]>
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 | ||
e93ca019 | 3189 | /* See breakpoint.h. */ |
c906108c SS |
3190 | |
3191 | void | |
e93ca019 | 3192 | bpstat_clear_actions (void) |
c906108c | 3193 | { |
e93ca019 JK |
3194 | struct thread_info *tp; |
3195 | bpstat bs; | |
3196 | ||
3197 | if (ptid_equal (inferior_ptid, null_ptid)) | |
3198 | return; | |
3199 | ||
3200 | tp = find_thread_ptid (inferior_ptid); | |
3201 | if (tp == NULL) | |
3202 | return; | |
3203 | ||
3204 | for (bs = tp->control.stop_bpstat; bs != NULL; bs = bs->next) | |
c906108c | 3205 | { |
9add0f1b | 3206 | decref_counted_command_line (&bs->commands); |
abf85f46 | 3207 | |
c906108c SS |
3208 | if (bs->old_val != NULL) |
3209 | { | |
3210 | value_free (bs->old_val); | |
3211 | bs->old_val = NULL; | |
3212 | } | |
3213 | } | |
3214 | } | |
3215 | ||
f3b1572e PA |
3216 | /* Called when a command is about to proceed the inferior. */ |
3217 | ||
3218 | static void | |
3219 | breakpoint_about_to_proceed (void) | |
3220 | { | |
3221 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3222 | { | |
3223 | struct thread_info *tp = inferior_thread (); | |
3224 | ||
3225 | /* Allow inferior function calls in breakpoint commands to not | |
3226 | interrupt the command list. When the call finishes | |
3227 | successfully, the inferior will be standing at the same | |
3228 | breakpoint as if nothing happened. */ | |
16c381f0 | 3229 | if (tp->control.in_infcall) |
f3b1572e PA |
3230 | return; |
3231 | } | |
3232 | ||
3233 | breakpoint_proceeded = 1; | |
3234 | } | |
3235 | ||
4a64f543 MS |
3236 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3237 | command. */ | |
c906108c | 3238 | static void |
4efb68b1 | 3239 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3240 | { |
3241 | executing_breakpoint_commands = 0; | |
3242 | } | |
3243 | ||
abf85f46 JK |
3244 | /* Return non-zero iff CMD as the first line of a command sequence is `silent' |
3245 | or its equivalent. */ | |
3246 | ||
3247 | static int | |
3248 | command_line_is_silent (struct command_line *cmd) | |
3249 | { | |
3250 | return cmd && (strcmp ("silent", cmd->line) == 0 | |
3251 | || (xdb_commands && strcmp ("Q", cmd->line) == 0)); | |
3252 | } | |
3253 | ||
4a64f543 MS |
3254 | /* Execute all the commands associated with all the breakpoints at |
3255 | this location. Any of these commands could cause the process to | |
3256 | proceed beyond this point, etc. We look out for such changes by | |
3257 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3258 | |
347bddb7 PA |
3259 | Returns true if a breakpoint command resumed the inferior. In that |
3260 | case, it is the caller's responsibility to recall it again with the | |
3261 | bpstat of the current thread. */ | |
3262 | ||
3263 | static int | |
3264 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3265 | { |
3266 | bpstat bs; | |
3267 | struct cleanup *old_chain; | |
347bddb7 | 3268 | int again = 0; |
c906108c SS |
3269 | |
3270 | /* Avoid endless recursion if a `source' command is contained | |
3271 | in bs->commands. */ | |
3272 | if (executing_breakpoint_commands) | |
347bddb7 | 3273 | return 0; |
c906108c SS |
3274 | |
3275 | executing_breakpoint_commands = 1; | |
3276 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3277 | ||
cf6c5ffb TT |
3278 | prevent_dont_repeat (); |
3279 | ||
4a64f543 | 3280 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3281 | bs = *bsp; |
3282 | ||
3283 | breakpoint_proceeded = 0; | |
3284 | for (; bs != NULL; bs = bs->next) | |
3285 | { | |
9add0f1b | 3286 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3287 | struct command_line *cmd; |
3288 | struct cleanup *this_cmd_tree_chain; | |
3289 | ||
3290 | /* Take ownership of the BSP's command tree, if it has one. | |
3291 | ||
3292 | The command tree could legitimately contain commands like | |
3293 | 'step' and 'next', which call clear_proceed_status, which | |
3294 | frees stop_bpstat's command tree. To make sure this doesn't | |
3295 | free the tree we're executing out from under us, we need to | |
3296 | take ownership of the tree ourselves. Since a given bpstat's | |
3297 | commands are only executed once, we don't need to copy it; we | |
3298 | can clear the pointer in the bpstat, and make sure we free | |
3299 | the tree when we're done. */ | |
9add0f1b TT |
3300 | ccmd = bs->commands; |
3301 | bs->commands = NULL; | |
abf85f46 JK |
3302 | this_cmd_tree_chain = make_cleanup_decref_counted_command_line (&ccmd); |
3303 | cmd = ccmd ? ccmd->commands : NULL; | |
3304 | if (command_line_is_silent (cmd)) | |
3305 | { | |
3306 | /* The action has been already done by bpstat_stop_status. */ | |
3307 | cmd = cmd->next; | |
3308 | } | |
6c50ab1c | 3309 | |
c906108c SS |
3310 | while (cmd != NULL) |
3311 | { | |
3312 | execute_control_command (cmd); | |
3313 | ||
3314 | if (breakpoint_proceeded) | |
3315 | break; | |
3316 | else | |
3317 | cmd = cmd->next; | |
3318 | } | |
6c50ab1c JB |
3319 | |
3320 | /* We can free this command tree now. */ | |
3321 | do_cleanups (this_cmd_tree_chain); | |
3322 | ||
c906108c | 3323 | if (breakpoint_proceeded) |
32c1e744 VP |
3324 | { |
3325 | if (target_can_async_p ()) | |
347bddb7 PA |
3326 | /* If we are in async mode, then the target might be still |
3327 | running, not stopped at any breakpoint, so nothing for | |
3328 | us to do here -- just return to the event loop. */ | |
3329 | ; | |
32c1e744 VP |
3330 | else |
3331 | /* In sync mode, when execute_control_command returns | |
3332 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3333 | Breakpoint commands for that stop were not run, since |
3334 | execute_command does not run breakpoint commands -- | |
3335 | only command_line_handler does, but that one is not | |
3336 | involved in execution of breakpoint commands. So, we | |
3337 | can now execute breakpoint commands. It should be | |
3338 | noted that making execute_command do bpstat actions is | |
3339 | not an option -- in this case we'll have recursive | |
3340 | invocation of bpstat for each breakpoint with a | |
3341 | command, and can easily blow up GDB stack. Instead, we | |
3342 | return true, which will trigger the caller to recall us | |
3343 | with the new stop_bpstat. */ | |
3344 | again = 1; | |
3345 | break; | |
32c1e744 | 3346 | } |
c906108c | 3347 | } |
c2b8ed2c | 3348 | do_cleanups (old_chain); |
347bddb7 PA |
3349 | return again; |
3350 | } | |
3351 | ||
3352 | void | |
3353 | bpstat_do_actions (void) | |
3354 | { | |
353d1d73 JK |
3355 | struct cleanup *cleanup_if_error = make_bpstat_clear_actions_cleanup (); |
3356 | ||
347bddb7 PA |
3357 | /* Do any commands attached to breakpoint we are stopped at. */ |
3358 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3359 | && target_has_execution | |
3360 | && !is_exited (inferior_ptid) | |
3361 | && !is_executing (inferior_ptid)) | |
3362 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3363 | and only return when it is stopped at the next breakpoint, we | |
3364 | keep doing breakpoint actions until it returns false to | |
3365 | indicate the inferior was not resumed. */ | |
16c381f0 | 3366 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3367 | break; |
353d1d73 JK |
3368 | |
3369 | discard_cleanups (cleanup_if_error); | |
c906108c SS |
3370 | } |
3371 | ||
fa4727a6 DJ |
3372 | /* Print out the (old or new) value associated with a watchpoint. */ |
3373 | ||
3374 | static void | |
3375 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3376 | { | |
3377 | if (val == NULL) | |
3378 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3379 | else | |
79a45b7d TT |
3380 | { |
3381 | struct value_print_options opts; | |
3382 | get_user_print_options (&opts); | |
3383 | value_print (val, stream, &opts); | |
3384 | } | |
fa4727a6 DJ |
3385 | } |
3386 | ||
e514a9d6 | 3387 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3388 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3389 | 'print_it' in the bpstat structure. Under some circumstances we |
3390 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3391 | normal_stop(). */ |
e514a9d6 JM |
3392 | |
3393 | static enum print_stop_action | |
3394 | print_bp_stop_message (bpstat bs) | |
3395 | { | |
3396 | switch (bs->print_it) | |
3397 | { | |
3398 | case print_it_noop: | |
4a64f543 | 3399 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3400 | return PRINT_UNKNOWN; |
3401 | break; | |
3402 | ||
3403 | case print_it_done: | |
3404 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3405 | relevant messages. */ |
e514a9d6 JM |
3406 | return PRINT_SRC_AND_LOC; |
3407 | break; | |
3408 | ||
3409 | case print_it_normal: | |
4f8d1dc6 | 3410 | { |
f431efe5 PA |
3411 | struct breakpoint *b = bs->breakpoint_at; |
3412 | ||
1a6a67de TJB |
3413 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3414 | which has since been deleted. */ | |
3415 | if (b == NULL) | |
3416 | return PRINT_UNKNOWN; | |
3417 | ||
348d480f PA |
3418 | /* Normal case. Call the breakpoint's print_it method. */ |
3419 | return b->ops->print_it (bs); | |
4f8d1dc6 | 3420 | } |
348d480f | 3421 | break; |
3086aeae | 3422 | |
e514a9d6 | 3423 | default: |
8e65ff28 | 3424 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3425 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3426 | break; |
c906108c | 3427 | } |
c906108c SS |
3428 | } |
3429 | ||
e514a9d6 JM |
3430 | /* Print a message indicating what happened. This is called from |
3431 | normal_stop(). The input to this routine is the head of the bpstat | |
3432 | list - a list of the eventpoints that caused this stop. This | |
3433 | routine calls the generic print routine for printing a message | |
3434 | about reasons for stopping. This will print (for example) the | |
3435 | "Breakpoint n," part of the output. The return value of this | |
3436 | routine is one of: | |
c906108c | 3437 | |
4a64f543 | 3438 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3439 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3440 | code to print the location. An example is |
c5aa993b JM |
3441 | "Breakpoint 1, " which should be followed by |
3442 | the location. | |
917317f4 | 3443 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3444 | to also print the location part of the message. |
3445 | An example is the catch/throw messages, which | |
4a64f543 | 3446 | don't require a location appended to the end. |
917317f4 | 3447 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3448 | further info to be printed. */ |
c906108c | 3449 | |
917317f4 | 3450 | enum print_stop_action |
fba45db2 | 3451 | bpstat_print (bpstat bs) |
c906108c SS |
3452 | { |
3453 | int val; | |
c5aa993b | 3454 | |
c906108c | 3455 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3456 | (Currently all watchpoints go on the bpstat whether hit or not. |
3457 | That probably could (should) be changed, provided care is taken | |
c906108c | 3458 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3459 | for (; bs; bs = bs->next) |
3460 | { | |
3461 | val = print_bp_stop_message (bs); | |
3462 | if (val == PRINT_SRC_ONLY | |
3463 | || val == PRINT_SRC_AND_LOC | |
3464 | || val == PRINT_NOTHING) | |
3465 | return val; | |
3466 | } | |
c906108c | 3467 | |
e514a9d6 | 3468 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3469 | with and nothing was printed. */ |
917317f4 | 3470 | return PRINT_UNKNOWN; |
c906108c SS |
3471 | } |
3472 | ||
4a64f543 MS |
3473 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3474 | used inside a catch_errors to evaluate the breakpoint condition. | |
3475 | The argument is a "struct expression *" that has been cast to a | |
3476 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3477 | |
3478 | static int | |
4efb68b1 | 3479 | breakpoint_cond_eval (void *exp) |
c906108c | 3480 | { |
278cd55f | 3481 | struct value *mark = value_mark (); |
c5aa993b | 3482 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3483 | |
c906108c SS |
3484 | value_free_to_mark (mark); |
3485 | return i; | |
3486 | } | |
3487 | ||
5760d0ab | 3488 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3489 | |
3490 | static bpstat | |
5760d0ab | 3491 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3492 | { |
3493 | bpstat bs; | |
3494 | ||
3495 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3496 | bs->next = NULL; |
3497 | **bs_link_pointer = bs; | |
3498 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3499 | bs->breakpoint_at = bl->owner; |
3500 | bs->bp_location_at = bl; | |
3501 | incref_bp_location (bl); | |
c906108c SS |
3502 | /* If the condition is false, etc., don't do the commands. */ |
3503 | bs->commands = NULL; | |
3504 | bs->old_val = NULL; | |
3505 | bs->print_it = print_it_normal; | |
3506 | return bs; | |
3507 | } | |
3508 | \f | |
d983da9c DJ |
3509 | /* The target has stopped with waitstatus WS. Check if any hardware |
3510 | watchpoints have triggered, according to the target. */ | |
3511 | ||
3512 | int | |
3513 | watchpoints_triggered (struct target_waitstatus *ws) | |
3514 | { | |
d92524f1 | 3515 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3516 | CORE_ADDR addr; |
3517 | struct breakpoint *b; | |
3518 | ||
3519 | if (!stopped_by_watchpoint) | |
3520 | { | |
3521 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3522 | as not triggered. */ | |
3523 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3524 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3525 | { |
3526 | struct watchpoint *w = (struct watchpoint *) b; | |
3527 | ||
3528 | w->watchpoint_triggered = watch_triggered_no; | |
3529 | } | |
d983da9c DJ |
3530 | |
3531 | return 0; | |
3532 | } | |
3533 | ||
3534 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3535 | { | |
3536 | /* We were stopped by a watchpoint, but we don't know where. | |
3537 | Mark all watchpoints as unknown. */ | |
3538 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3539 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3540 | { |
3541 | struct watchpoint *w = (struct watchpoint *) b; | |
3542 | ||
3543 | w->watchpoint_triggered = watch_triggered_unknown; | |
3544 | } | |
d983da9c DJ |
3545 | |
3546 | return stopped_by_watchpoint; | |
3547 | } | |
3548 | ||
3549 | /* The target could report the data address. Mark watchpoints | |
3550 | affected by this data address as triggered, and all others as not | |
3551 | triggered. */ | |
3552 | ||
3553 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3554 | if (is_hardware_watchpoint (b)) |
d983da9c | 3555 | { |
3a5c3e22 | 3556 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 3557 | struct bp_location *loc; |
d983da9c | 3558 | |
3a5c3e22 | 3559 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 3560 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 3561 | { |
3a5c3e22 | 3562 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 3563 | { |
3a5c3e22 PA |
3564 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
3565 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
3566 | |
3567 | if (newaddr == start) | |
3568 | { | |
3a5c3e22 | 3569 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3570 | break; |
3571 | } | |
3572 | } | |
3573 | /* Exact match not required. Within range is sufficient. */ | |
3574 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3575 | addr, loc->address, | |
3576 | loc->length)) | |
3577 | { | |
3a5c3e22 | 3578 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3579 | break; |
3580 | } | |
3581 | } | |
d983da9c DJ |
3582 | } |
3583 | ||
3584 | return 1; | |
3585 | } | |
3586 | ||
c906108c SS |
3587 | /* Possible return values for watchpoint_check (this can't be an enum |
3588 | because of check_errors). */ | |
3589 | /* The watchpoint has been deleted. */ | |
3590 | #define WP_DELETED 1 | |
3591 | /* The value has changed. */ | |
3592 | #define WP_VALUE_CHANGED 2 | |
3593 | /* The value has not changed. */ | |
3594 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3595 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3596 | #define WP_IGNORE 4 | |
c906108c SS |
3597 | |
3598 | #define BP_TEMPFLAG 1 | |
3599 | #define BP_HARDWAREFLAG 2 | |
3600 | ||
4a64f543 MS |
3601 | /* Evaluate watchpoint condition expression and check if its value |
3602 | changed. | |
553e4c11 JB |
3603 | |
3604 | P should be a pointer to struct bpstat, but is defined as a void * | |
3605 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3606 | |
3607 | static int | |
4efb68b1 | 3608 | watchpoint_check (void *p) |
c906108c SS |
3609 | { |
3610 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 3611 | struct watchpoint *b; |
c906108c SS |
3612 | struct frame_info *fr; |
3613 | int within_current_scope; | |
3614 | ||
f431efe5 | 3615 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3616 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 3617 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 3618 | |
f6bc2008 PA |
3619 | /* If this is a local watchpoint, we only want to check if the |
3620 | watchpoint frame is in scope if the current thread is the thread | |
3621 | that was used to create the watchpoint. */ | |
3622 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3623 | return WP_IGNORE; |
f6bc2008 | 3624 | |
c906108c SS |
3625 | if (b->exp_valid_block == NULL) |
3626 | within_current_scope = 1; | |
3627 | else | |
3628 | { | |
edb3359d DJ |
3629 | struct frame_info *frame = get_current_frame (); |
3630 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3631 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3632 | ||
4a64f543 MS |
3633 | /* in_function_epilogue_p() returns a non-zero value if we're |
3634 | still in the function but the stack frame has already been | |
3635 | invalidated. Since we can't rely on the values of local | |
3636 | variables after the stack has been destroyed, we are treating | |
3637 | the watchpoint in that state as `not changed' without further | |
3638 | checking. Don't mark watchpoints as changed if the current | |
3639 | frame is in an epilogue - even if they are in some other | |
3640 | frame, our view of the stack is likely to be wrong and | |
3641 | frame_find_by_id could error out. */ | |
a0f49112 | 3642 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3643 | return WP_IGNORE; |
a0f49112 | 3644 | |
101dcfbe | 3645 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3646 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3647 | |
3648 | /* If we've gotten confused in the unwinder, we might have | |
3649 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3650 | if (within_current_scope) |
3651 | { | |
3652 | struct symbol *function; | |
3653 | ||
3654 | function = get_frame_function (fr); | |
3655 | if (function == NULL | |
3656 | || !contained_in (b->exp_valid_block, | |
3657 | SYMBOL_BLOCK_VALUE (function))) | |
3658 | within_current_scope = 0; | |
3659 | } | |
69fbadd5 | 3660 | |
edb3359d | 3661 | if (within_current_scope) |
c906108c SS |
3662 | /* If we end up stopping, the current frame will get selected |
3663 | in normal_stop. So this call to select_frame won't affect | |
3664 | the user. */ | |
0f7d239c | 3665 | select_frame (fr); |
c906108c | 3666 | } |
c5aa993b | 3667 | |
c906108c SS |
3668 | if (within_current_scope) |
3669 | { | |
4a64f543 MS |
3670 | /* We use value_{,free_to_}mark because it could be a *long* |
3671 | time before we return to the command level and call | |
3672 | free_all_values. We can't call free_all_values because we | |
3673 | might be in the middle of evaluating a function call. */ | |
c906108c | 3674 | |
0cf6dd15 | 3675 | int pc = 0; |
9c06b0b4 | 3676 | struct value *mark; |
fa4727a6 DJ |
3677 | struct value *new_val; |
3678 | ||
3a5c3e22 | 3679 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
3680 | /* Since we don't know the exact trigger address (from |
3681 | stopped_data_address), just tell the user we've triggered | |
3682 | a mask watchpoint. */ | |
3683 | return WP_VALUE_CHANGED; | |
3684 | ||
3685 | mark = value_mark (); | |
0cf6dd15 | 3686 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3687 | |
4a64f543 MS |
3688 | /* We use value_equal_contents instead of value_equal because |
3689 | the latter coerces an array to a pointer, thus comparing just | |
3690 | the address of the array instead of its contents. This is | |
3691 | not what we want. */ | |
fa4727a6 | 3692 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3693 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3694 | { |
fa4727a6 DJ |
3695 | if (new_val != NULL) |
3696 | { | |
3697 | release_value (new_val); | |
3698 | value_free_to_mark (mark); | |
3699 | } | |
c906108c SS |
3700 | bs->old_val = b->val; |
3701 | b->val = new_val; | |
fa4727a6 | 3702 | b->val_valid = 1; |
c906108c SS |
3703 | return WP_VALUE_CHANGED; |
3704 | } | |
3705 | else | |
3706 | { | |
60e1c644 | 3707 | /* Nothing changed. */ |
c906108c | 3708 | value_free_to_mark (mark); |
c906108c SS |
3709 | return WP_VALUE_NOT_CHANGED; |
3710 | } | |
3711 | } | |
3712 | else | |
3713 | { | |
79a45e25 PA |
3714 | struct ui_out *uiout = current_uiout; |
3715 | ||
c906108c | 3716 | /* This seems like the only logical thing to do because |
c5aa993b JM |
3717 | if we temporarily ignored the watchpoint, then when |
3718 | we reenter the block in which it is valid it contains | |
3719 | garbage (in the case of a function, it may have two | |
3720 | garbage values, one before and one after the prologue). | |
3721 | So we can't even detect the first assignment to it and | |
3722 | watch after that (since the garbage may or may not equal | |
3723 | the first value assigned). */ | |
348d480f PA |
3724 | /* We print all the stop information in |
3725 | breakpoint_ops->print_it, but in this case, by the time we | |
3726 | call breakpoint_ops->print_it this bp will be deleted | |
3727 | already. So we have no choice but print the information | |
3728 | here. */ | |
9dc5e2a9 | 3729 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3730 | ui_out_field_string |
3731 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3732 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 3733 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
3734 | ui_out_text (uiout, |
3735 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3736 | which its expression is valid.\n"); |
4ce44c66 | 3737 | |
cdac0397 | 3738 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 3739 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 3740 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3741 | |
3742 | return WP_DELETED; | |
3743 | } | |
3744 | } | |
3745 | ||
18a18393 | 3746 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
3747 | breakpoint location BL. This function does not check if we should |
3748 | stop, only if BL explains the stop. */ | |
3749 | ||
18a18393 | 3750 | static int |
6c95b8df PA |
3751 | bpstat_check_location (const struct bp_location *bl, |
3752 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3753 | { |
3754 | struct breakpoint *b = bl->owner; | |
3755 | ||
348d480f | 3756 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
3757 | gdb_assert (b != NULL); |
3758 | ||
348d480f | 3759 | return b->ops->breakpoint_hit (bl, aspace, bp_addr); |
18a18393 VP |
3760 | } |
3761 | ||
3a5c3e22 PA |
3762 | /* Determine if the watched values have actually changed, and we |
3763 | should stop. If not, set BS->stop to 0. */ | |
3764 | ||
18a18393 VP |
3765 | static void |
3766 | bpstat_check_watchpoint (bpstat bs) | |
3767 | { | |
2bdf28a0 | 3768 | const struct bp_location *bl; |
3a5c3e22 | 3769 | struct watchpoint *b; |
2bdf28a0 JK |
3770 | |
3771 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3772 | bl = bs->bp_location_at; |
2bdf28a0 | 3773 | gdb_assert (bl != NULL); |
3a5c3e22 | 3774 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 3775 | gdb_assert (b != NULL); |
18a18393 | 3776 | |
18a18393 | 3777 | { |
18a18393 VP |
3778 | int must_check_value = 0; |
3779 | ||
3a5c3e22 | 3780 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
3781 | /* For a software watchpoint, we must always check the |
3782 | watched value. */ | |
3783 | must_check_value = 1; | |
3784 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3785 | /* We have a hardware watchpoint (read, write, or access) | |
3786 | and the target earlier reported an address watched by | |
3787 | this watchpoint. */ | |
3788 | must_check_value = 1; | |
3789 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 3790 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
3791 | /* We were stopped by a hardware watchpoint, but the target could |
3792 | not report the data address. We must check the watchpoint's | |
3793 | value. Access and read watchpoints are out of luck; without | |
3794 | a data address, we can't figure it out. */ | |
3795 | must_check_value = 1; | |
3a5c3e22 | 3796 | |
18a18393 VP |
3797 | if (must_check_value) |
3798 | { | |
3e43a32a MS |
3799 | char *message |
3800 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 3801 | b->base.number); |
18a18393 VP |
3802 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3803 | int e = catch_errors (watchpoint_check, bs, message, | |
3804 | RETURN_MASK_ALL); | |
3805 | do_cleanups (cleanups); | |
3806 | switch (e) | |
3807 | { | |
3808 | case WP_DELETED: | |
3809 | /* We've already printed what needs to be printed. */ | |
3810 | bs->print_it = print_it_done; | |
3811 | /* Stop. */ | |
3812 | break; | |
60e1c644 PA |
3813 | case WP_IGNORE: |
3814 | bs->print_it = print_it_noop; | |
3815 | bs->stop = 0; | |
3816 | break; | |
18a18393 | 3817 | case WP_VALUE_CHANGED: |
3a5c3e22 | 3818 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 3819 | { |
85d721b8 PA |
3820 | /* There are two cases to consider here: |
3821 | ||
4a64f543 | 3822 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3823 | In that case, trust the target, and always report |
3824 | the watchpoint hit to the user. Even though | |
3825 | reads don't cause value changes, the value may | |
3826 | have changed since the last time it was read, and | |
3827 | since we're not trapping writes, we will not see | |
3828 | those, and as such we should ignore our notion of | |
3829 | old value. | |
3830 | ||
4a64f543 | 3831 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3832 | reads and writes. There are two ways this may |
3833 | happen: | |
3834 | ||
4a64f543 | 3835 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3836 | reads only, but can break on accesses (reads or |
3837 | writes), such as e.g., x86. We detect this case | |
3838 | at the time we try to insert read watchpoints. | |
3839 | ||
4a64f543 | 3840 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3841 | watchpoints, but, the user set an access or write |
3842 | watchpoint watching the same memory as this read | |
3843 | watchpoint. | |
3844 | ||
3845 | If we're watching memory writes as well as reads, | |
3846 | ignore watchpoint hits when we find that the | |
3847 | value hasn't changed, as reads don't cause | |
3848 | changes. This still gives false positives when | |
3849 | the program writes the same value to memory as | |
3850 | what there was already in memory (we will confuse | |
3851 | it for a read), but it's much better than | |
3852 | nothing. */ | |
3853 | ||
3854 | int other_write_watchpoint = 0; | |
3855 | ||
3856 | if (bl->watchpoint_type == hw_read) | |
3857 | { | |
3858 | struct breakpoint *other_b; | |
3859 | ||
3860 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
3861 | if (other_b->type == bp_hardware_watchpoint |
3862 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 3863 | { |
3a5c3e22 PA |
3864 | struct watchpoint *other_w = |
3865 | (struct watchpoint *) other_b; | |
3866 | ||
3867 | if (other_w->watchpoint_triggered | |
3868 | == watch_triggered_yes) | |
3869 | { | |
3870 | other_write_watchpoint = 1; | |
3871 | break; | |
3872 | } | |
85d721b8 PA |
3873 | } |
3874 | } | |
3875 | ||
3876 | if (other_write_watchpoint | |
3877 | || bl->watchpoint_type == hw_access) | |
3878 | { | |
3879 | /* We're watching the same memory for writes, | |
3880 | and the value changed since the last time we | |
3881 | updated it, so this trap must be for a write. | |
3882 | Ignore it. */ | |
3883 | bs->print_it = print_it_noop; | |
3884 | bs->stop = 0; | |
3885 | } | |
18a18393 VP |
3886 | } |
3887 | break; | |
3888 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
3889 | if (b->base.type == bp_hardware_watchpoint |
3890 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
3891 | { |
3892 | /* Don't stop: write watchpoints shouldn't fire if | |
3893 | the value hasn't changed. */ | |
3894 | bs->print_it = print_it_noop; | |
3895 | bs->stop = 0; | |
3896 | } | |
3897 | /* Stop. */ | |
3898 | break; | |
3899 | default: | |
3900 | /* Can't happen. */ | |
3901 | case 0: | |
3902 | /* Error from catch_errors. */ | |
3a5c3e22 | 3903 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 3904 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
3905 | /* We've already printed what needs to be printed. */ |
3906 | bs->print_it = print_it_done; | |
3907 | break; | |
3908 | } | |
3909 | } | |
3910 | else /* must_check_value == 0 */ | |
3911 | { | |
3912 | /* This is a case where some watchpoint(s) triggered, but | |
3913 | not at the address of this watchpoint, or else no | |
3914 | watchpoint triggered after all. So don't print | |
3915 | anything for this watchpoint. */ | |
3916 | bs->print_it = print_it_noop; | |
3917 | bs->stop = 0; | |
3918 | } | |
3919 | } | |
3920 | } | |
3921 | ||
3922 | ||
3923 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3924 | of breakpoint referred to by BS. If we should not stop for this | |
3925 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 3926 | |
18a18393 VP |
3927 | static void |
3928 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3929 | { | |
3930 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
3931 | const struct bp_location *bl; |
3932 | struct breakpoint *b; | |
3933 | ||
3934 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3935 | bl = bs->bp_location_at; |
2bdf28a0 | 3936 | gdb_assert (bl != NULL); |
f431efe5 | 3937 | b = bs->breakpoint_at; |
2bdf28a0 | 3938 | gdb_assert (b != NULL); |
18a18393 VP |
3939 | |
3940 | if (frame_id_p (b->frame_id) | |
edb3359d | 3941 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3942 | bs->stop = 0; |
3943 | else if (bs->stop) | |
3944 | { | |
3945 | int value_is_zero = 0; | |
60e1c644 PA |
3946 | struct expression *cond; |
3947 | ||
7371cf6d PM |
3948 | /* Evaluate Python breakpoints that have a "stop" |
3949 | method implemented. */ | |
3950 | if (b->py_bp_object) | |
3951 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
3952 | ||
60e1c644 | 3953 | if (is_watchpoint (b)) |
3a5c3e22 PA |
3954 | { |
3955 | struct watchpoint *w = (struct watchpoint *) b; | |
3956 | ||
3957 | cond = w->cond_exp; | |
3958 | } | |
60e1c644 PA |
3959 | else |
3960 | cond = bl->cond; | |
3961 | ||
f431efe5 | 3962 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 3963 | { |
60e1c644 | 3964 | int within_current_scope = 1; |
3a5c3e22 | 3965 | struct watchpoint * w; |
60e1c644 | 3966 | |
c5bc3a77 DJ |
3967 | /* We use value_mark and value_free_to_mark because it could |
3968 | be a long time before we return to the command level and | |
3969 | call free_all_values. We can't call free_all_values | |
3970 | because we might be in the middle of evaluating a | |
3971 | function call. */ | |
3972 | struct value *mark = value_mark (); | |
3973 | ||
3a5c3e22 PA |
3974 | if (is_watchpoint (b)) |
3975 | w = (struct watchpoint *) b; | |
3976 | else | |
3977 | w = NULL; | |
3978 | ||
edb3359d DJ |
3979 | /* Need to select the frame, with all that implies so that |
3980 | the conditions will have the right context. Because we | |
3981 | use the frame, we will not see an inlined function's | |
3982 | variables when we arrive at a breakpoint at the start | |
3983 | of the inlined function; the current frame will be the | |
3984 | call site. */ | |
3a5c3e22 | 3985 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
3986 | select_frame (get_current_frame ()); |
3987 | else | |
3988 | { | |
3989 | struct frame_info *frame; | |
3990 | ||
3991 | /* For local watchpoint expressions, which particular | |
3992 | instance of a local is being watched matters, so we | |
3993 | keep track of the frame to evaluate the expression | |
3994 | in. To evaluate the condition however, it doesn't | |
3995 | really matter which instantiation of the function | |
3996 | where the condition makes sense triggers the | |
3997 | watchpoint. This allows an expression like "watch | |
3998 | global if q > 10" set in `func', catch writes to | |
3999 | global on all threads that call `func', or catch | |
4000 | writes on all recursive calls of `func' by a single | |
4001 | thread. We simply always evaluate the condition in | |
4002 | the innermost frame that's executing where it makes | |
4003 | sense to evaluate the condition. It seems | |
4004 | intuitive. */ | |
3a5c3e22 | 4005 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
4006 | if (frame != NULL) |
4007 | select_frame (frame); | |
4008 | else | |
4009 | within_current_scope = 0; | |
4010 | } | |
4011 | if (within_current_scope) | |
4012 | value_is_zero | |
4013 | = catch_errors (breakpoint_cond_eval, cond, | |
4014 | "Error in testing breakpoint condition:\n", | |
4015 | RETURN_MASK_ALL); | |
4016 | else | |
4017 | { | |
4018 | warning (_("Watchpoint condition cannot be tested " | |
4019 | "in the current scope")); | |
4020 | /* If we failed to set the right context for this | |
4021 | watchpoint, unconditionally report it. */ | |
4022 | value_is_zero = 0; | |
4023 | } | |
4a64f543 | 4024 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4025 | value_free_to_mark (mark); |
18a18393 | 4026 | } |
60e1c644 PA |
4027 | |
4028 | if (cond && value_is_zero) | |
18a18393 VP |
4029 | { |
4030 | bs->stop = 0; | |
4031 | } | |
4032 | else if (b->thread != -1 && b->thread != thread_id) | |
4033 | { | |
4034 | bs->stop = 0; | |
4035 | } | |
4036 | else if (b->ignore_count > 0) | |
4037 | { | |
4038 | b->ignore_count--; | |
4039 | annotate_ignore_count_change (); | |
4040 | bs->stop = 0; | |
4a64f543 | 4041 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4042 | ++(b->hit_count); |
8d3788bd | 4043 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4044 | } |
4045 | } | |
4046 | } | |
4047 | ||
4048 | ||
9709f61c | 4049 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4050 | BP_ADDR in thread PTID. |
c906108c | 4051 | |
d983da9c | 4052 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4053 | don't understand this stop. Result is a chain of bpstat's such |
4054 | that: | |
c906108c | 4055 | |
c5aa993b | 4056 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4057 | |
c5aa993b | 4058 | if we understand why we stopped, the result is not null. |
c906108c | 4059 | |
c5aa993b JM |
4060 | Each element of the chain refers to a particular breakpoint or |
4061 | watchpoint at which we have stopped. (We may have stopped for | |
4062 | several reasons concurrently.) | |
c906108c | 4063 | |
c5aa993b JM |
4064 | Each element of the chain has valid next, breakpoint_at, |
4065 | commands, FIXME??? fields. */ | |
c906108c SS |
4066 | |
4067 | bpstat | |
6c95b8df PA |
4068 | bpstat_stop_status (struct address_space *aspace, |
4069 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4070 | { |
0d381245 | 4071 | struct breakpoint *b = NULL; |
afe38095 | 4072 | struct bp_location *bl; |
20874c92 | 4073 | struct bp_location *loc; |
5760d0ab JK |
4074 | /* First item of allocated bpstat's. */ |
4075 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4076 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4077 | bpstat bs; |
20874c92 | 4078 | int ix; |
429374b8 | 4079 | int need_remove_insert; |
f431efe5 | 4080 | int removed_any; |
c906108c | 4081 | |
f431efe5 PA |
4082 | /* First, build the bpstat chain with locations that explain a |
4083 | target stop, while being careful to not set the target running, | |
4084 | as that may invalidate locations (in particular watchpoint | |
4085 | locations are recreated). Resuming will happen here with | |
4086 | breakpoint conditions or watchpoint expressions that include | |
4087 | inferior function calls. */ | |
c5aa993b | 4088 | |
429374b8 JK |
4089 | ALL_BREAKPOINTS (b) |
4090 | { | |
4091 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4092 | continue; | |
a5606eee | 4093 | |
429374b8 JK |
4094 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4095 | { | |
4a64f543 MS |
4096 | /* For hardware watchpoints, we look only at the first |
4097 | location. The watchpoint_check function will work on the | |
4098 | entire expression, not the individual locations. For | |
4099 | read watchpoints, the watchpoints_triggered function has | |
4100 | checked all locations already. */ | |
429374b8 JK |
4101 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4102 | break; | |
18a18393 | 4103 | |
429374b8 JK |
4104 | if (bl->shlib_disabled) |
4105 | continue; | |
c5aa993b | 4106 | |
429374b8 JK |
4107 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4108 | continue; | |
c5aa993b | 4109 | |
4a64f543 MS |
4110 | /* Come here if it's a watchpoint, or if the break address |
4111 | matches. */ | |
c5aa993b | 4112 | |
4a64f543 MS |
4113 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4114 | explain stop. */ | |
c5aa993b | 4115 | |
f431efe5 PA |
4116 | /* Assume we stop. Should we find a watchpoint that is not |
4117 | actually triggered, or if the condition of the breakpoint | |
4118 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4119 | bs->stop = 1; |
4120 | bs->print = 1; | |
d983da9c | 4121 | |
f431efe5 PA |
4122 | /* If this is a scope breakpoint, mark the associated |
4123 | watchpoint as triggered so that we will handle the | |
4124 | out-of-scope event. We'll get to the watchpoint next | |
4125 | iteration. */ | |
d0fb5eae | 4126 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4127 | { |
4128 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4129 | ||
4130 | w->watchpoint_triggered = watch_triggered_yes; | |
4131 | } | |
f431efe5 PA |
4132 | } |
4133 | } | |
4134 | ||
4135 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4136 | { | |
f1310107 | 4137 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4138 | { |
5760d0ab | 4139 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4140 | /* For hits of moribund locations, we should just proceed. */ |
4141 | bs->stop = 0; | |
4142 | bs->print = 0; | |
4143 | bs->print_it = print_it_noop; | |
4144 | } | |
4145 | } | |
4146 | ||
f431efe5 PA |
4147 | /* Now go through the locations that caused the target to stop, and |
4148 | check whether we're interested in reporting this stop to higher | |
4149 | layers, or whether we should resume the target transparently. */ | |
4150 | ||
4151 | removed_any = 0; | |
4152 | ||
5760d0ab | 4153 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4154 | { |
4155 | if (!bs->stop) | |
4156 | continue; | |
4157 | ||
f431efe5 | 4158 | b = bs->breakpoint_at; |
348d480f PA |
4159 | b->ops->check_status (bs); |
4160 | if (bs->stop) | |
28010a5d | 4161 | { |
348d480f | 4162 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4163 | |
429374b8 JK |
4164 | if (bs->stop) |
4165 | { | |
4166 | ++(b->hit_count); | |
8d3788bd | 4167 | observer_notify_breakpoint_modified (b); |
c906108c | 4168 | |
4a64f543 | 4169 | /* We will stop here. */ |
429374b8 JK |
4170 | if (b->disposition == disp_disable) |
4171 | { | |
4172 | if (b->enable_state != bp_permanent) | |
4173 | b->enable_state = bp_disabled; | |
f431efe5 | 4174 | removed_any = 1; |
429374b8 JK |
4175 | } |
4176 | if (b->silent) | |
4177 | bs->print = 0; | |
4178 | bs->commands = b->commands; | |
9add0f1b | 4179 | incref_counted_command_line (bs->commands); |
abf85f46 JK |
4180 | if (command_line_is_silent (bs->commands |
4181 | ? bs->commands->commands : NULL)) | |
4182 | bs->print = 0; | |
429374b8 JK |
4183 | } |
4184 | ||
e5dd4106 | 4185 | /* Print nothing for this entry if we don't stop or don't print. */ |
429374b8 JK |
4186 | if (bs->stop == 0 || bs->print == 0) |
4187 | bs->print_it = print_it_noop; | |
348d480f | 4188 | } |
429374b8 | 4189 | } |
876fa593 | 4190 | |
d983da9c DJ |
4191 | /* If we aren't stopping, the value of some hardware watchpoint may |
4192 | not have changed, but the intermediate memory locations we are | |
4193 | watching may have. Don't bother if we're stopping; this will get | |
4194 | done later. */ | |
d832cb68 | 4195 | need_remove_insert = 0; |
5760d0ab JK |
4196 | if (! bpstat_causes_stop (bs_head)) |
4197 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4198 | if (!bs->stop |
f431efe5 PA |
4199 | && bs->breakpoint_at |
4200 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4201 | { |
3a5c3e22 PA |
4202 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4203 | ||
4204 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4205 | need_remove_insert = 1; |
d983da9c DJ |
4206 | } |
4207 | ||
d832cb68 | 4208 | if (need_remove_insert) |
2d134ed3 | 4209 | update_global_location_list (1); |
f431efe5 PA |
4210 | else if (removed_any) |
4211 | update_global_location_list (0); | |
d832cb68 | 4212 | |
5760d0ab | 4213 | return bs_head; |
c906108c | 4214 | } |
628fe4e4 JK |
4215 | |
4216 | static void | |
4217 | handle_jit_event (void) | |
4218 | { | |
4219 | struct frame_info *frame; | |
4220 | struct gdbarch *gdbarch; | |
4221 | ||
4222 | /* Switch terminal for any messages produced by | |
4223 | breakpoint_re_set. */ | |
4224 | target_terminal_ours_for_output (); | |
4225 | ||
4226 | frame = get_current_frame (); | |
4227 | gdbarch = get_frame_arch (frame); | |
4228 | ||
4229 | jit_event_handler (gdbarch); | |
4230 | ||
4231 | target_terminal_inferior (); | |
4232 | } | |
4233 | ||
4234 | /* Prepare WHAT final decision for infrun. */ | |
4235 | ||
4236 | /* Decide what infrun needs to do with this bpstat. */ | |
4237 | ||
c906108c | 4238 | struct bpstat_what |
0e30163f | 4239 | bpstat_what (bpstat bs_head) |
c906108c | 4240 | { |
c906108c | 4241 | struct bpstat_what retval; |
628fe4e4 JK |
4242 | /* We need to defer calling `solib_add', as adding new symbols |
4243 | resets breakpoints, which in turn deletes breakpoint locations, | |
4244 | and hence may clear unprocessed entries in the BS chain. */ | |
4245 | int shlib_event = 0; | |
4246 | int jit_event = 0; | |
0e30163f | 4247 | bpstat bs; |
c906108c | 4248 | |
628fe4e4 | 4249 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4250 | retval.call_dummy = STOP_NONE; |
186c406b | 4251 | retval.is_longjmp = 0; |
628fe4e4 | 4252 | |
0e30163f | 4253 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4254 | { |
628fe4e4 JK |
4255 | /* Extract this BS's action. After processing each BS, we check |
4256 | if its action overrides all we've seem so far. */ | |
4257 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4258 | enum bptype bptype; | |
4259 | ||
c906108c | 4260 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4261 | { |
4262 | /* I suspect this can happen if it was a momentary | |
4263 | breakpoint which has since been deleted. */ | |
4264 | bptype = bp_none; | |
4265 | } | |
20874c92 | 4266 | else |
f431efe5 | 4267 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4268 | |
4269 | switch (bptype) | |
c906108c SS |
4270 | { |
4271 | case bp_none: | |
628fe4e4 | 4272 | break; |
c906108c SS |
4273 | case bp_breakpoint: |
4274 | case bp_hardware_breakpoint: | |
4275 | case bp_until: | |
4276 | case bp_finish: | |
4277 | if (bs->stop) | |
4278 | { | |
4279 | if (bs->print) | |
628fe4e4 | 4280 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4281 | else |
628fe4e4 | 4282 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4283 | } |
4284 | else | |
628fe4e4 | 4285 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4286 | break; |
4287 | case bp_watchpoint: | |
4288 | case bp_hardware_watchpoint: | |
4289 | case bp_read_watchpoint: | |
4290 | case bp_access_watchpoint: | |
4291 | if (bs->stop) | |
4292 | { | |
4293 | if (bs->print) | |
628fe4e4 | 4294 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4295 | else |
628fe4e4 | 4296 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4297 | } |
4298 | else | |
628fe4e4 JK |
4299 | { |
4300 | /* There was a watchpoint, but we're not stopping. | |
4301 | This requires no further action. */ | |
4302 | } | |
c906108c SS |
4303 | break; |
4304 | case bp_longjmp: | |
186c406b | 4305 | case bp_exception: |
628fe4e4 | 4306 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4307 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4308 | break; |
4309 | case bp_longjmp_resume: | |
186c406b | 4310 | case bp_exception_resume: |
628fe4e4 | 4311 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4312 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4313 | break; |
4314 | case bp_step_resume: | |
4315 | if (bs->stop) | |
628fe4e4 JK |
4316 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4317 | else | |
c906108c | 4318 | { |
628fe4e4 JK |
4319 | /* It is for the wrong frame. */ |
4320 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4321 | } |
c906108c | 4322 | break; |
2c03e5be PA |
4323 | case bp_hp_step_resume: |
4324 | if (bs->stop) | |
4325 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4326 | else | |
4327 | { | |
4328 | /* It is for the wrong frame. */ | |
4329 | this_action = BPSTAT_WHAT_SINGLE; | |
4330 | } | |
4331 | break; | |
c906108c | 4332 | case bp_watchpoint_scope: |
c4093a6a | 4333 | case bp_thread_event: |
1900040c | 4334 | case bp_overlay_event: |
0fd8e87f | 4335 | case bp_longjmp_master: |
aa7d318d | 4336 | case bp_std_terminate_master: |
186c406b | 4337 | case bp_exception_master: |
628fe4e4 | 4338 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4339 | break; |
ce78b96d | 4340 | case bp_catchpoint: |
c5aa993b JM |
4341 | if (bs->stop) |
4342 | { | |
4343 | if (bs->print) | |
628fe4e4 | 4344 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4345 | else |
628fe4e4 | 4346 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4347 | } |
4348 | else | |
628fe4e4 JK |
4349 | { |
4350 | /* There was a catchpoint, but we're not stopping. | |
4351 | This requires no further action. */ | |
4352 | } | |
4353 | break; | |
4354 | case bp_shlib_event: | |
4355 | shlib_event = 1; | |
4356 | ||
4357 | /* If requested, stop when the dynamic linker notifies GDB | |
4358 | of events. This allows the user to get control and place | |
4359 | breakpoints in initializer routines for dynamically | |
4360 | loaded objects (among other things). */ | |
4361 | if (stop_on_solib_events) | |
4362 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4363 | else | |
4364 | this_action = BPSTAT_WHAT_SINGLE; | |
4365 | break; | |
4366 | case bp_jit_event: | |
4367 | jit_event = 1; | |
4368 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4369 | break; |
c906108c | 4370 | case bp_call_dummy: |
53a5351d JM |
4371 | /* Make sure the action is stop (silent or noisy), |
4372 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4373 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4374 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4375 | break; |
4376 | case bp_std_terminate: | |
4377 | /* Make sure the action is stop (silent or noisy), | |
4378 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4379 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4380 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4381 | break; |
1042e4c0 | 4382 | case bp_tracepoint: |
7a697b8d | 4383 | case bp_fast_tracepoint: |
0fb4aa4b | 4384 | case bp_static_tracepoint: |
1042e4c0 SS |
4385 | /* Tracepoint hits should not be reported back to GDB, and |
4386 | if one got through somehow, it should have been filtered | |
4387 | out already. */ | |
4388 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4389 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4390 | break; |
4391 | case bp_gnu_ifunc_resolver: | |
4392 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4393 | this_action = BPSTAT_WHAT_SINGLE; | |
4394 | break; | |
4395 | case bp_gnu_ifunc_resolver_return: | |
4396 | /* The breakpoint will be removed, execution will restart from the | |
4397 | PC of the former breakpoint. */ | |
4398 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4399 | break; | |
628fe4e4 JK |
4400 | default: |
4401 | internal_error (__FILE__, __LINE__, | |
4402 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4403 | } |
628fe4e4 JK |
4404 | |
4405 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4406 | } |
628fe4e4 | 4407 | |
0e30163f JK |
4408 | /* These operations may affect the bs->breakpoint_at state so they are |
4409 | delayed after MAIN_ACTION is decided above. */ | |
4410 | ||
628fe4e4 JK |
4411 | if (shlib_event) |
4412 | { | |
4413 | if (debug_infrun) | |
4414 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4415 | ||
4416 | /* Check for any newly added shared libraries if we're supposed | |
4417 | to be adding them automatically. */ | |
4418 | ||
4419 | /* Switch terminal for any messages produced by | |
4420 | breakpoint_re_set. */ | |
4421 | target_terminal_ours_for_output (); | |
4422 | ||
4423 | #ifdef SOLIB_ADD | |
4424 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4425 | #else | |
4426 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4427 | #endif | |
4428 | ||
4429 | target_terminal_inferior (); | |
4430 | } | |
4431 | ||
4432 | if (jit_event) | |
4433 | { | |
4434 | if (debug_infrun) | |
4435 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4436 | ||
4437 | handle_jit_event (); | |
4438 | } | |
4439 | ||
0e30163f JK |
4440 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4441 | { | |
4442 | struct breakpoint *b = bs->breakpoint_at; | |
4443 | ||
4444 | if (b == NULL) | |
4445 | continue; | |
4446 | switch (b->type) | |
4447 | { | |
4448 | case bp_gnu_ifunc_resolver: | |
4449 | gnu_ifunc_resolver_stop (b); | |
4450 | break; | |
4451 | case bp_gnu_ifunc_resolver_return: | |
4452 | gnu_ifunc_resolver_return_stop (b); | |
4453 | break; | |
4454 | } | |
4455 | } | |
4456 | ||
c906108c SS |
4457 | return retval; |
4458 | } | |
4459 | ||
4460 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4461 | without hardware support). This isn't related to a specific bpstat, | |
4462 | just to things like whether watchpoints are set. */ | |
4463 | ||
c5aa993b | 4464 | int |
fba45db2 | 4465 | bpstat_should_step (void) |
c906108c SS |
4466 | { |
4467 | struct breakpoint *b; | |
cc59ec59 | 4468 | |
c906108c | 4469 | ALL_BREAKPOINTS (b) |
717a8278 | 4470 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4471 | return 1; |
c906108c SS |
4472 | return 0; |
4473 | } | |
4474 | ||
67822962 PA |
4475 | int |
4476 | bpstat_causes_stop (bpstat bs) | |
4477 | { | |
4478 | for (; bs != NULL; bs = bs->next) | |
4479 | if (bs->stop) | |
4480 | return 1; | |
4481 | ||
4482 | return 0; | |
4483 | } | |
4484 | ||
c906108c | 4485 | \f |
c5aa993b | 4486 | |
170b53b2 UW |
4487 | /* Compute a string of spaces suitable to indent the next line |
4488 | so it starts at the position corresponding to the table column | |
4489 | named COL_NAME in the currently active table of UIOUT. */ | |
4490 | ||
4491 | static char * | |
4492 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4493 | { | |
4494 | static char wrap_indent[80]; | |
4495 | int i, total_width, width, align; | |
4496 | char *text; | |
4497 | ||
4498 | total_width = 0; | |
4499 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4500 | { | |
4501 | if (strcmp (text, col_name) == 0) | |
4502 | { | |
4503 | gdb_assert (total_width < sizeof wrap_indent); | |
4504 | memset (wrap_indent, ' ', total_width); | |
4505 | wrap_indent[total_width] = 0; | |
4506 | ||
4507 | return wrap_indent; | |
4508 | } | |
4509 | ||
4510 | total_width += width + 1; | |
4511 | } | |
4512 | ||
4513 | return NULL; | |
4514 | } | |
4515 | ||
859825b8 JK |
4516 | /* Print the LOC location out of the list of B->LOC locations. */ |
4517 | ||
170b53b2 UW |
4518 | static void |
4519 | print_breakpoint_location (struct breakpoint *b, | |
4520 | struct bp_location *loc) | |
0d381245 | 4521 | { |
79a45e25 | 4522 | struct ui_out *uiout = current_uiout; |
6c95b8df PA |
4523 | struct cleanup *old_chain = save_current_program_space (); |
4524 | ||
859825b8 JK |
4525 | if (loc != NULL && loc->shlib_disabled) |
4526 | loc = NULL; | |
4527 | ||
6c95b8df PA |
4528 | if (loc != NULL) |
4529 | set_current_program_space (loc->pspace); | |
4530 | ||
56435ebe TT |
4531 | if (b->display_canonical) |
4532 | ui_out_field_string (uiout, "what", b->addr_string); | |
4533 | else if (b->source_file && loc) | |
0d381245 VP |
4534 | { |
4535 | struct symbol *sym | |
4536 | = find_pc_sect_function (loc->address, loc->section); | |
4537 | if (sym) | |
4538 | { | |
4539 | ui_out_text (uiout, "in "); | |
4540 | ui_out_field_string (uiout, "func", | |
4541 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4542 | ui_out_text (uiout, " "); |
4543 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4544 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4545 | } |
4546 | ui_out_field_string (uiout, "file", b->source_file); | |
4547 | ui_out_text (uiout, ":"); | |
4548 | ||
4549 | if (ui_out_is_mi_like_p (uiout)) | |
4550 | { | |
4551 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4552 | char *fullname = symtab_to_fullname (sal.symtab); | |
4553 | ||
4554 | if (fullname) | |
4555 | ui_out_field_string (uiout, "fullname", fullname); | |
4556 | } | |
4557 | ||
4558 | ui_out_field_int (uiout, "line", b->line_number); | |
4559 | } | |
859825b8 | 4560 | else if (loc) |
0d381245 | 4561 | { |
170b53b2 UW |
4562 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4563 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4564 | ||
22e722e1 DJ |
4565 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4566 | demangle, ""); | |
0d381245 | 4567 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4568 | |
4569 | do_cleanups (stb_chain); | |
0d381245 | 4570 | } |
859825b8 JK |
4571 | else |
4572 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4573 | |
4574 | do_cleanups (old_chain); | |
0d381245 VP |
4575 | } |
4576 | ||
269b11a2 PA |
4577 | static const char * |
4578 | bptype_string (enum bptype type) | |
c906108c | 4579 | { |
c4093a6a JM |
4580 | struct ep_type_description |
4581 | { | |
4582 | enum bptype type; | |
4583 | char *description; | |
4584 | }; | |
4585 | static struct ep_type_description bptypes[] = | |
c906108c | 4586 | { |
c5aa993b JM |
4587 | {bp_none, "?deleted?"}, |
4588 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4589 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4590 | {bp_until, "until"}, |
4591 | {bp_finish, "finish"}, | |
4592 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4593 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4594 | {bp_read_watchpoint, "read watchpoint"}, |
4595 | {bp_access_watchpoint, "acc watchpoint"}, | |
4596 | {bp_longjmp, "longjmp"}, | |
4597 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4598 | {bp_exception, "exception"}, |
4599 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4600 | {bp_step_resume, "step resume"}, |
2c03e5be | 4601 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4602 | {bp_watchpoint_scope, "watchpoint scope"}, |
4603 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4604 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4605 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4606 | {bp_thread_event, "thread events"}, |
1900040c | 4607 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4608 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4609 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4610 | {bp_exception_master, "exception master"}, |
ce78b96d | 4611 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4612 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4613 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4614 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4615 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4616 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4617 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4618 | }; |
269b11a2 PA |
4619 | |
4620 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4621 | || ((int) type != bptypes[(int) type].type)) | |
4622 | internal_error (__FILE__, __LINE__, | |
4623 | _("bptypes table does not describe type #%d."), | |
4624 | (int) type); | |
4625 | ||
4626 | return bptypes[(int) type].description; | |
4627 | } | |
4628 | ||
4629 | /* Print B to gdb_stdout. */ | |
4630 | ||
4631 | static void | |
4632 | print_one_breakpoint_location (struct breakpoint *b, | |
4633 | struct bp_location *loc, | |
4634 | int loc_number, | |
4635 | struct bp_location **last_loc, | |
269b11a2 PA |
4636 | int allflag) |
4637 | { | |
4638 | struct command_line *l; | |
c2c6d25f | 4639 | static char bpenables[] = "nynny"; |
c906108c | 4640 | |
79a45e25 | 4641 | struct ui_out *uiout = current_uiout; |
0d381245 VP |
4642 | int header_of_multiple = 0; |
4643 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4644 | struct value_print_options opts; |
4645 | ||
4646 | get_user_print_options (&opts); | |
0d381245 VP |
4647 | |
4648 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4649 | /* See comment in print_one_breakpoint concerning treatment of |
4650 | breakpoints with single disabled location. */ | |
0d381245 VP |
4651 | if (loc == NULL |
4652 | && (b->loc != NULL | |
4653 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4654 | header_of_multiple = 1; | |
4655 | if (loc == NULL) | |
4656 | loc = b->loc; | |
4657 | ||
c4093a6a JM |
4658 | annotate_record (); |
4659 | ||
4660 | /* 1 */ | |
4661 | annotate_field (0); | |
0d381245 VP |
4662 | if (part_of_multiple) |
4663 | { | |
4664 | char *formatted; | |
0c6773c1 | 4665 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4666 | ui_out_field_string (uiout, "number", formatted); |
4667 | xfree (formatted); | |
4668 | } | |
4669 | else | |
4670 | { | |
4671 | ui_out_field_int (uiout, "number", b->number); | |
4672 | } | |
c4093a6a JM |
4673 | |
4674 | /* 2 */ | |
4675 | annotate_field (1); | |
0d381245 VP |
4676 | if (part_of_multiple) |
4677 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4678 | else |
4679 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4680 | |
4681 | /* 3 */ | |
4682 | annotate_field (2); | |
0d381245 VP |
4683 | if (part_of_multiple) |
4684 | ui_out_field_skip (uiout, "disp"); | |
4685 | else | |
2cec12e5 | 4686 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4687 | |
c4093a6a JM |
4688 | |
4689 | /* 4 */ | |
4690 | annotate_field (3); | |
0d381245 | 4691 | if (part_of_multiple) |
54e52265 | 4692 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4693 | else |
4a64f543 MS |
4694 | ui_out_field_fmt (uiout, "enabled", "%c", |
4695 | bpenables[(int) b->enable_state]); | |
54e52265 | 4696 | ui_out_spaces (uiout, 2); |
0d381245 | 4697 | |
c4093a6a JM |
4698 | |
4699 | /* 5 and 6 */ | |
3086aeae | 4700 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4701 | { |
4a64f543 MS |
4702 | /* Although the print_one can possibly print all locations, |
4703 | calling it here is not likely to get any nice result. So, | |
4704 | make sure there's just one location. */ | |
0d381245 | 4705 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4706 | b->ops->print_one (b, last_loc); |
0d381245 | 4707 | } |
3086aeae DJ |
4708 | else |
4709 | switch (b->type) | |
4710 | { | |
4711 | case bp_none: | |
4712 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4713 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4714 | break; |
c906108c | 4715 | |
3086aeae DJ |
4716 | case bp_watchpoint: |
4717 | case bp_hardware_watchpoint: | |
4718 | case bp_read_watchpoint: | |
4719 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4720 | { |
4721 | struct watchpoint *w = (struct watchpoint *) b; | |
4722 | ||
4723 | /* Field 4, the address, is omitted (which makes the columns | |
4724 | not line up too nicely with the headers, but the effect | |
4725 | is relatively readable). */ | |
4726 | if (opts.addressprint) | |
4727 | ui_out_field_skip (uiout, "addr"); | |
4728 | annotate_field (5); | |
4729 | ui_out_field_string (uiout, "what", w->exp_string); | |
4730 | } | |
3086aeae DJ |
4731 | break; |
4732 | ||
3086aeae DJ |
4733 | case bp_breakpoint: |
4734 | case bp_hardware_breakpoint: | |
4735 | case bp_until: | |
4736 | case bp_finish: | |
4737 | case bp_longjmp: | |
4738 | case bp_longjmp_resume: | |
186c406b TT |
4739 | case bp_exception: |
4740 | case bp_exception_resume: | |
3086aeae | 4741 | case bp_step_resume: |
2c03e5be | 4742 | case bp_hp_step_resume: |
3086aeae DJ |
4743 | case bp_watchpoint_scope: |
4744 | case bp_call_dummy: | |
aa7d318d | 4745 | case bp_std_terminate: |
3086aeae DJ |
4746 | case bp_shlib_event: |
4747 | case bp_thread_event: | |
4748 | case bp_overlay_event: | |
0fd8e87f | 4749 | case bp_longjmp_master: |
aa7d318d | 4750 | case bp_std_terminate_master: |
186c406b | 4751 | case bp_exception_master: |
1042e4c0 | 4752 | case bp_tracepoint: |
7a697b8d | 4753 | case bp_fast_tracepoint: |
0fb4aa4b | 4754 | case bp_static_tracepoint: |
4efc6507 | 4755 | case bp_jit_event: |
0e30163f JK |
4756 | case bp_gnu_ifunc_resolver: |
4757 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4758 | if (opts.addressprint) |
3086aeae DJ |
4759 | { |
4760 | annotate_field (4); | |
54e52265 | 4761 | if (header_of_multiple) |
0d381245 | 4762 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4763 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4764 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4765 | else |
5af949e3 UW |
4766 | ui_out_field_core_addr (uiout, "addr", |
4767 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4768 | } |
4769 | annotate_field (5); | |
0d381245 | 4770 | if (!header_of_multiple) |
170b53b2 | 4771 | print_breakpoint_location (b, loc); |
0d381245 | 4772 | if (b->loc) |
a6d9a66e | 4773 | *last_loc = b->loc; |
3086aeae DJ |
4774 | break; |
4775 | } | |
c906108c | 4776 | |
6c95b8df PA |
4777 | |
4778 | /* For backward compatibility, don't display inferiors unless there | |
4779 | are several. */ | |
4780 | if (loc != NULL | |
4781 | && !header_of_multiple | |
4782 | && (allflag | |
4783 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4784 | && (number_of_program_spaces () > 1 | |
4785 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4786 | /* LOC is for existing B, it cannot be in |
4787 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4788 | && loc->owner->type != bp_catchpoint))) |
4789 | { | |
4790 | struct inferior *inf; | |
4791 | int first = 1; | |
4792 | ||
4793 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4794 | { | |
4795 | if (inf->pspace == loc->pspace) | |
4796 | { | |
4797 | if (first) | |
4798 | { | |
4799 | first = 0; | |
4800 | ui_out_text (uiout, " inf "); | |
4801 | } | |
4802 | else | |
4803 | ui_out_text (uiout, ", "); | |
4804 | ui_out_text (uiout, plongest (inf->num)); | |
4805 | } | |
4806 | } | |
4807 | } | |
4808 | ||
4a306c9a | 4809 | if (!part_of_multiple) |
c4093a6a | 4810 | { |
4a306c9a JB |
4811 | if (b->thread != -1) |
4812 | { | |
4813 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4814 | "stop only in" line a little further down. */ |
4a306c9a JB |
4815 | ui_out_text (uiout, " thread "); |
4816 | ui_out_field_int (uiout, "thread", b->thread); | |
4817 | } | |
4818 | else if (b->task != 0) | |
4819 | { | |
4820 | ui_out_text (uiout, " task "); | |
4821 | ui_out_field_int (uiout, "task", b->task); | |
4822 | } | |
c4093a6a | 4823 | } |
f1310107 | 4824 | |
8b93c638 | 4825 | ui_out_text (uiout, "\n"); |
f1310107 | 4826 | |
348d480f | 4827 | if (!part_of_multiple) |
f1310107 TJB |
4828 | b->ops->print_one_detail (b, uiout); |
4829 | ||
0d381245 | 4830 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4831 | { |
4832 | annotate_field (6); | |
8b93c638 | 4833 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 4834 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 4835 | the frame ID. */ |
5af949e3 UW |
4836 | ui_out_field_core_addr (uiout, "frame", |
4837 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4838 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4839 | } |
4840 | ||
28010a5d | 4841 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
4842 | { |
4843 | annotate_field (7); | |
d77f58be | 4844 | if (is_tracepoint (b)) |
1042e4c0 SS |
4845 | ui_out_text (uiout, "\ttrace only if "); |
4846 | else | |
4847 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4848 | ui_out_field_string (uiout, "cond", b->cond_string); |
4849 | ui_out_text (uiout, "\n"); | |
4850 | } | |
4851 | ||
0d381245 | 4852 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4853 | { |
4a64f543 | 4854 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4855 | ui_out_text (uiout, "\tstop only in thread "); |
4856 | ui_out_field_int (uiout, "thread", b->thread); | |
4857 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4858 | } |
4859 | ||
63c715c6 | 4860 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4861 | { |
4a64f543 | 4862 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4863 | if (ep_is_catchpoint (b)) |
4864 | ui_out_text (uiout, "\tcatchpoint"); | |
4865 | else | |
4866 | ui_out_text (uiout, "\tbreakpoint"); | |
4867 | ui_out_text (uiout, " already hit "); | |
4868 | ui_out_field_int (uiout, "times", b->hit_count); | |
4869 | if (b->hit_count == 1) | |
4870 | ui_out_text (uiout, " time\n"); | |
4871 | else | |
4872 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4873 | } |
4874 | ||
4a64f543 MS |
4875 | /* Output the count also if it is zero, but only if this is mi. |
4876 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4877 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4878 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4879 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4880 | |
0d381245 | 4881 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4882 | { |
4883 | annotate_field (8); | |
8b93c638 JM |
4884 | ui_out_text (uiout, "\tignore next "); |
4885 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4886 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4887 | } |
059fb39f | 4888 | |
9add0f1b | 4889 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4890 | if (!part_of_multiple && l) |
c4093a6a | 4891 | { |
3b31d625 EZ |
4892 | struct cleanup *script_chain; |
4893 | ||
c4093a6a | 4894 | annotate_field (9); |
3b31d625 | 4895 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4896 | print_command_lines (uiout, l, 4); |
3b31d625 | 4897 | do_cleanups (script_chain); |
c4093a6a | 4898 | } |
d24317b4 | 4899 | |
d9b3f62e | 4900 | if (is_tracepoint (b)) |
1042e4c0 | 4901 | { |
d9b3f62e PA |
4902 | struct tracepoint *t = (struct tracepoint *) b; |
4903 | ||
4904 | if (!part_of_multiple && t->pass_count) | |
4905 | { | |
4906 | annotate_field (10); | |
4907 | ui_out_text (uiout, "\tpass count "); | |
4908 | ui_out_field_int (uiout, "pass", t->pass_count); | |
4909 | ui_out_text (uiout, " \n"); | |
4910 | } | |
1042e4c0 SS |
4911 | } |
4912 | ||
d24317b4 VP |
4913 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4914 | { | |
3a5c3e22 PA |
4915 | if (is_watchpoint (b)) |
4916 | { | |
4917 | struct watchpoint *w = (struct watchpoint *) b; | |
4918 | ||
4919 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
4920 | } | |
4921 | else if (b->addr_string) | |
d24317b4 | 4922 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 4923 | } |
c4093a6a | 4924 | } |
c5aa993b | 4925 | |
0d381245 VP |
4926 | static void |
4927 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 4928 | struct bp_location **last_loc, |
6c95b8df | 4929 | int allflag) |
0d381245 | 4930 | { |
8d3788bd | 4931 | struct cleanup *bkpt_chain; |
79a45e25 | 4932 | struct ui_out *uiout = current_uiout; |
8d3788bd VP |
4933 | |
4934 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
4935 | ||
12c5a436 | 4936 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 4937 | do_cleanups (bkpt_chain); |
0d381245 VP |
4938 | |
4939 | /* If this breakpoint has custom print function, | |
4940 | it's already printed. Otherwise, print individual | |
4941 | locations, if any. */ | |
4942 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4943 | { | |
4a64f543 MS |
4944 | /* If breakpoint has a single location that is disabled, we |
4945 | print it as if it had several locations, since otherwise it's | |
4946 | hard to represent "breakpoint enabled, location disabled" | |
4947 | situation. | |
4948 | ||
4949 | Note that while hardware watchpoints have several locations | |
a3be7890 | 4950 | internally, that's not a property exposed to user. */ |
0d381245 | 4951 | if (b->loc |
a5606eee | 4952 | && !is_hardware_watchpoint (b) |
8d3788bd | 4953 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
4954 | { |
4955 | struct bp_location *loc; | |
4956 | int n = 1; | |
8d3788bd | 4957 | |
0d381245 | 4958 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
4959 | { |
4960 | struct cleanup *inner2 = | |
4961 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
4962 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
4963 | do_cleanups (inner2); | |
4964 | } | |
0d381245 VP |
4965 | } |
4966 | } | |
4967 | } | |
4968 | ||
a6d9a66e UW |
4969 | static int |
4970 | breakpoint_address_bits (struct breakpoint *b) | |
4971 | { | |
4972 | int print_address_bits = 0; | |
4973 | struct bp_location *loc; | |
4974 | ||
4975 | for (loc = b->loc; loc; loc = loc->next) | |
4976 | { | |
c7437ca6 PA |
4977 | int addr_bit; |
4978 | ||
4979 | /* Software watchpoints that aren't watching memory don't have | |
4980 | an address to print. */ | |
4981 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4982 | continue; | |
4983 | ||
4984 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4985 | if (addr_bit > print_address_bits) |
4986 | print_address_bits = addr_bit; | |
4987 | } | |
4988 | ||
4989 | return print_address_bits; | |
4990 | } | |
0d381245 | 4991 | |
c4093a6a JM |
4992 | struct captured_breakpoint_query_args |
4993 | { | |
4994 | int bnum; | |
4995 | }; | |
c5aa993b | 4996 | |
c4093a6a | 4997 | static int |
2b65245e | 4998 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4999 | { |
5000 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5001 | struct breakpoint *b; |
a6d9a66e | 5002 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5003 | |
c4093a6a JM |
5004 | ALL_BREAKPOINTS (b) |
5005 | { | |
5006 | if (args->bnum == b->number) | |
c5aa993b | 5007 | { |
12c5a436 | 5008 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5009 | return GDB_RC_OK; |
c5aa993b | 5010 | } |
c4093a6a JM |
5011 | } |
5012 | return GDB_RC_NONE; | |
5013 | } | |
c5aa993b | 5014 | |
c4093a6a | 5015 | enum gdb_rc |
4a64f543 MS |
5016 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5017 | char **error_message) | |
c4093a6a JM |
5018 | { |
5019 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5020 | |
c4093a6a JM |
5021 | args.bnum = bnum; |
5022 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5023 | an error. */ |
b0b13bb4 DJ |
5024 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5025 | error_message, RETURN_MASK_ALL) < 0) | |
5026 | return GDB_RC_FAIL; | |
5027 | else | |
5028 | return GDB_RC_OK; | |
c4093a6a | 5029 | } |
c5aa993b | 5030 | |
09d682a4 TT |
5031 | /* Return true if this breakpoint was set by the user, false if it is |
5032 | internal or momentary. */ | |
5033 | ||
5034 | int | |
5035 | user_breakpoint_p (struct breakpoint *b) | |
5036 | { | |
46c6471b | 5037 | return b->number > 0; |
09d682a4 TT |
5038 | } |
5039 | ||
7f3b0473 | 5040 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5041 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5042 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5043 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5044 | ones for which it returns non-zero. Return the total number of | |
5045 | breakpoints listed. */ | |
c906108c | 5046 | |
d77f58be | 5047 | static int |
e5a67952 | 5048 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5049 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5050 | { |
52f0bd74 | 5051 | struct breakpoint *b; |
a6d9a66e | 5052 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5053 | int nr_printable_breakpoints; |
3b31d625 | 5054 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5055 | struct value_print_options opts; |
a6d9a66e | 5056 | int print_address_bits = 0; |
269b11a2 | 5057 | int print_type_col_width = 14; |
79a45e25 | 5058 | struct ui_out *uiout = current_uiout; |
269b11a2 | 5059 | |
79a45b7d TT |
5060 | get_user_print_options (&opts); |
5061 | ||
4a64f543 MS |
5062 | /* Compute the number of rows in the table, as well as the size |
5063 | required for address fields. */ | |
7f3b0473 AC |
5064 | nr_printable_breakpoints = 0; |
5065 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5066 | { |
5067 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5068 | if (filter && !filter (b)) | |
5069 | continue; | |
5070 | ||
5071 | /* If we have an "args" string, it is a list of breakpoints to | |
5072 | accept. Skip the others. */ | |
5073 | if (args != NULL && *args != '\0') | |
5074 | { | |
5075 | if (allflag && parse_and_eval_long (args) != b->number) | |
5076 | continue; | |
5077 | if (!allflag && !number_is_in_list (args, b->number)) | |
5078 | continue; | |
5079 | } | |
269b11a2 | 5080 | |
e5a67952 MS |
5081 | if (allflag || user_breakpoint_p (b)) |
5082 | { | |
5083 | int addr_bit, type_len; | |
a6d9a66e | 5084 | |
e5a67952 MS |
5085 | addr_bit = breakpoint_address_bits (b); |
5086 | if (addr_bit > print_address_bits) | |
5087 | print_address_bits = addr_bit; | |
269b11a2 | 5088 | |
e5a67952 MS |
5089 | type_len = strlen (bptype_string (b->type)); |
5090 | if (type_len > print_type_col_width) | |
5091 | print_type_col_width = type_len; | |
5092 | ||
5093 | nr_printable_breakpoints++; | |
5094 | } | |
5095 | } | |
7f3b0473 | 5096 | |
79a45b7d | 5097 | if (opts.addressprint) |
3b31d625 | 5098 | bkpttbl_chain |
3e43a32a MS |
5099 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5100 | nr_printable_breakpoints, | |
3b31d625 | 5101 | "BreakpointTable"); |
8b93c638 | 5102 | else |
3b31d625 | 5103 | bkpttbl_chain |
3e43a32a MS |
5104 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5105 | nr_printable_breakpoints, | |
3b31d625 | 5106 | "BreakpointTable"); |
8b93c638 | 5107 | |
7f3b0473 | 5108 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5109 | annotate_breakpoints_headers (); |
5110 | if (nr_printable_breakpoints > 0) | |
5111 | annotate_field (0); | |
4a64f543 | 5112 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5113 | if (nr_printable_breakpoints > 0) |
5114 | annotate_field (1); | |
269b11a2 | 5115 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5116 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5117 | if (nr_printable_breakpoints > 0) |
5118 | annotate_field (2); | |
4a64f543 | 5119 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5120 | if (nr_printable_breakpoints > 0) |
5121 | annotate_field (3); | |
54e52265 | 5122 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5123 | if (opts.addressprint) |
e5a67952 MS |
5124 | { |
5125 | if (nr_printable_breakpoints > 0) | |
5126 | annotate_field (4); | |
5127 | if (print_address_bits <= 32) | |
5128 | ui_out_table_header (uiout, 10, ui_left, | |
5129 | "addr", "Address"); /* 5 */ | |
5130 | else | |
5131 | ui_out_table_header (uiout, 18, ui_left, | |
5132 | "addr", "Address"); /* 5 */ | |
5133 | } | |
d7faa9e7 AC |
5134 | if (nr_printable_breakpoints > 0) |
5135 | annotate_field (5); | |
5136 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5137 | ui_out_table_body (uiout); | |
5138 | if (nr_printable_breakpoints > 0) | |
5139 | annotate_breakpoints_table (); | |
7f3b0473 | 5140 | |
c4093a6a | 5141 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5142 | { |
5143 | QUIT; | |
5144 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5145 | if (filter && !filter (b)) | |
5146 | continue; | |
5147 | ||
5148 | /* If we have an "args" string, it is a list of breakpoints to | |
5149 | accept. Skip the others. */ | |
5150 | ||
5151 | if (args != NULL && *args != '\0') | |
5152 | { | |
5153 | if (allflag) /* maintenance info breakpoint */ | |
5154 | { | |
5155 | if (parse_and_eval_long (args) != b->number) | |
5156 | continue; | |
5157 | } | |
5158 | else /* all others */ | |
5159 | { | |
5160 | if (!number_is_in_list (args, b->number)) | |
5161 | continue; | |
5162 | } | |
5163 | } | |
5164 | /* We only print out user settable breakpoints unless the | |
5165 | allflag is set. */ | |
5166 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5167 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5168 | } |
5169 | ||
3b31d625 | 5170 | do_cleanups (bkpttbl_chain); |
698384cd | 5171 | |
7f3b0473 | 5172 | if (nr_printable_breakpoints == 0) |
c906108c | 5173 | { |
4a64f543 MS |
5174 | /* If there's a filter, let the caller decide how to report |
5175 | empty list. */ | |
d77f58be SS |
5176 | if (!filter) |
5177 | { | |
e5a67952 | 5178 | if (args == NULL || *args == '\0') |
d77f58be SS |
5179 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5180 | else | |
4a64f543 | 5181 | ui_out_message (uiout, 0, |
e5a67952 MS |
5182 | "No breakpoint or watchpoint matching '%s'.\n", |
5183 | args); | |
d77f58be | 5184 | } |
c906108c SS |
5185 | } |
5186 | else | |
c4093a6a | 5187 | { |
a6d9a66e UW |
5188 | if (last_loc && !server_command) |
5189 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5190 | } |
c906108c | 5191 | |
4a64f543 | 5192 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5193 | there have been breakpoints? */ |
c906108c | 5194 | annotate_breakpoints_table_end (); |
d77f58be SS |
5195 | |
5196 | return nr_printable_breakpoints; | |
c906108c SS |
5197 | } |
5198 | ||
ad443146 SS |
5199 | /* Display the value of default-collect in a way that is generally |
5200 | compatible with the breakpoint list. */ | |
5201 | ||
5202 | static void | |
5203 | default_collect_info (void) | |
5204 | { | |
79a45e25 PA |
5205 | struct ui_out *uiout = current_uiout; |
5206 | ||
ad443146 SS |
5207 | /* If it has no value (which is frequently the case), say nothing; a |
5208 | message like "No default-collect." gets in user's face when it's | |
5209 | not wanted. */ | |
5210 | if (!*default_collect) | |
5211 | return; | |
5212 | ||
5213 | /* The following phrase lines up nicely with per-tracepoint collect | |
5214 | actions. */ | |
5215 | ui_out_text (uiout, "default collect "); | |
5216 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5217 | ui_out_text (uiout, " \n"); | |
5218 | } | |
5219 | ||
c906108c | 5220 | static void |
e5a67952 | 5221 | breakpoints_info (char *args, int from_tty) |
c906108c | 5222 | { |
e5a67952 | 5223 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5224 | |
5225 | default_collect_info (); | |
d77f58be SS |
5226 | } |
5227 | ||
5228 | static void | |
e5a67952 | 5229 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5230 | { |
e5a67952 | 5231 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
79a45e25 | 5232 | struct ui_out *uiout = current_uiout; |
d77f58be SS |
5233 | |
5234 | if (num_printed == 0) | |
5235 | { | |
e5a67952 | 5236 | if (args == NULL || *args == '\0') |
d77f58be SS |
5237 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5238 | else | |
e5a67952 | 5239 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5240 | } |
c906108c SS |
5241 | } |
5242 | ||
7a292a7a | 5243 | static void |
e5a67952 | 5244 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5245 | { |
e5a67952 | 5246 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5247 | |
5248 | default_collect_info (); | |
c906108c SS |
5249 | } |
5250 | ||
0d381245 | 5251 | static int |
714835d5 | 5252 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5253 | struct program_space *pspace, |
714835d5 | 5254 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5255 | { |
5256 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5257 | |
0d381245 VP |
5258 | for (; bl; bl = bl->next) |
5259 | { | |
6c95b8df PA |
5260 | if (bl->pspace == pspace |
5261 | && bl->address == pc | |
0d381245 VP |
5262 | && (!overlay_debugging || bl->section == section)) |
5263 | return 1; | |
5264 | } | |
5265 | return 0; | |
5266 | } | |
5267 | ||
6c95b8df PA |
5268 | /* Print a message describing any breakpoints set at PC. This |
5269 | concerns with logical breakpoints, so we match program spaces, not | |
5270 | address spaces. */ | |
c906108c SS |
5271 | |
5272 | static void | |
6c95b8df PA |
5273 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5274 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5275 | struct obj_section *section, int thread) |
c906108c | 5276 | { |
52f0bd74 AC |
5277 | int others = 0; |
5278 | struct breakpoint *b; | |
c906108c SS |
5279 | |
5280 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5281 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5282 | if (others > 0) |
5283 | { | |
a3f17187 AC |
5284 | if (others == 1) |
5285 | printf_filtered (_("Note: breakpoint ")); | |
5286 | else /* if (others == ???) */ | |
5287 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5288 | ALL_BREAKPOINTS (b) |
6c95b8df | 5289 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5290 | { |
5291 | others--; | |
5292 | printf_filtered ("%d", b->number); | |
5293 | if (b->thread == -1 && thread != -1) | |
5294 | printf_filtered (" (all threads)"); | |
5295 | else if (b->thread != -1) | |
5296 | printf_filtered (" (thread %d)", b->thread); | |
5297 | printf_filtered ("%s%s ", | |
059fb39f | 5298 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5299 | || b->enable_state == bp_call_disabled |
5300 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5301 | ? " (disabled)" |
5302 | : b->enable_state == bp_permanent | |
5303 | ? " (permanent)" | |
5304 | : ""), | |
5305 | (others > 1) ? "," | |
5306 | : ((others == 1) ? " and" : "")); | |
5307 | } | |
a3f17187 | 5308 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5309 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5310 | printf_filtered (".\n"); |
5311 | } | |
5312 | } | |
5313 | \f | |
5314 | /* Set the default place to put a breakpoint | |
5315 | for the `break' command with no arguments. */ | |
5316 | ||
5317 | void | |
6c95b8df PA |
5318 | set_default_breakpoint (int valid, struct program_space *pspace, |
5319 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5320 | int line) |
c906108c SS |
5321 | { |
5322 | default_breakpoint_valid = valid; | |
6c95b8df | 5323 | default_breakpoint_pspace = pspace; |
c906108c SS |
5324 | default_breakpoint_address = addr; |
5325 | default_breakpoint_symtab = symtab; | |
5326 | default_breakpoint_line = line; | |
5327 | } | |
5328 | ||
e4f237da KB |
5329 | /* Return true iff it is meaningful to use the address member of |
5330 | BPT. For some breakpoint types, the address member is irrelevant | |
5331 | and it makes no sense to attempt to compare it to other addresses | |
5332 | (or use it for any other purpose either). | |
5333 | ||
4a64f543 MS |
5334 | More specifically, each of the following breakpoint types will |
5335 | always have a zero valued address and we don't want to mark | |
5336 | breakpoints of any of these types to be a duplicate of an actual | |
5337 | breakpoint at address zero: | |
e4f237da KB |
5338 | |
5339 | bp_watchpoint | |
2d134ed3 PA |
5340 | bp_catchpoint |
5341 | ||
5342 | */ | |
e4f237da KB |
5343 | |
5344 | static int | |
5345 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5346 | { | |
5347 | enum bptype type = bpt->type; | |
5348 | ||
2d134ed3 PA |
5349 | return (type != bp_watchpoint && type != bp_catchpoint); |
5350 | } | |
5351 | ||
5352 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5353 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5354 | ||
5355 | static int | |
4a64f543 MS |
5356 | watchpoint_locations_match (struct bp_location *loc1, |
5357 | struct bp_location *loc2) | |
2d134ed3 | 5358 | { |
3a5c3e22 PA |
5359 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
5360 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
5361 | ||
5362 | /* Both of them must exist. */ | |
5363 | gdb_assert (w1 != NULL); | |
5364 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 5365 | |
4a64f543 MS |
5366 | /* If the target can evaluate the condition expression in hardware, |
5367 | then we we need to insert both watchpoints even if they are at | |
5368 | the same place. Otherwise the watchpoint will only trigger when | |
5369 | the condition of whichever watchpoint was inserted evaluates to | |
5370 | true, not giving a chance for GDB to check the condition of the | |
5371 | other watchpoint. */ | |
3a5c3e22 | 5372 | if ((w1->cond_exp |
4a64f543 MS |
5373 | && target_can_accel_watchpoint_condition (loc1->address, |
5374 | loc1->length, | |
0cf6dd15 | 5375 | loc1->watchpoint_type, |
3a5c3e22 PA |
5376 | w1->cond_exp)) |
5377 | || (w2->cond_exp | |
4a64f543 MS |
5378 | && target_can_accel_watchpoint_condition (loc2->address, |
5379 | loc2->length, | |
0cf6dd15 | 5380 | loc2->watchpoint_type, |
3a5c3e22 | 5381 | w2->cond_exp))) |
0cf6dd15 TJB |
5382 | return 0; |
5383 | ||
85d721b8 PA |
5384 | /* Note that this checks the owner's type, not the location's. In |
5385 | case the target does not support read watchpoints, but does | |
5386 | support access watchpoints, we'll have bp_read_watchpoint | |
5387 | watchpoints with hw_access locations. Those should be considered | |
5388 | duplicates of hw_read locations. The hw_read locations will | |
5389 | become hw_access locations later. */ | |
2d134ed3 PA |
5390 | return (loc1->owner->type == loc2->owner->type |
5391 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5392 | && loc1->address == loc2->address | |
5393 | && loc1->length == loc2->length); | |
e4f237da KB |
5394 | } |
5395 | ||
6c95b8df PA |
5396 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5397 | same breakpoint location. In most targets, this can only be true | |
5398 | if ASPACE1 matches ASPACE2. On targets that have global | |
5399 | breakpoints, the address space doesn't really matter. */ | |
5400 | ||
5401 | static int | |
5402 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5403 | struct address_space *aspace2, CORE_ADDR addr2) | |
5404 | { | |
5405 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5406 | || aspace1 == aspace2) | |
5407 | && addr1 == addr2); | |
5408 | } | |
5409 | ||
f1310107 TJB |
5410 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5411 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5412 | matches ASPACE2. On targets that have global breakpoints, the address | |
5413 | space doesn't really matter. */ | |
5414 | ||
5415 | static int | |
5416 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5417 | int len1, struct address_space *aspace2, | |
5418 | CORE_ADDR addr2) | |
5419 | { | |
5420 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5421 | || aspace1 == aspace2) | |
5422 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5423 | } | |
5424 | ||
5425 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5426 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5427 | matches the breakpoint's address space. On targets that have global | |
5428 | breakpoints, the address space doesn't really matter. */ | |
5429 | ||
5430 | static int | |
5431 | breakpoint_location_address_match (struct bp_location *bl, | |
5432 | struct address_space *aspace, | |
5433 | CORE_ADDR addr) | |
5434 | { | |
5435 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5436 | aspace, addr) | |
5437 | || (bl->length | |
5438 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5439 | bl->address, bl->length, | |
5440 | aspace, addr))); | |
5441 | } | |
5442 | ||
2d134ed3 PA |
5443 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5444 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5445 | represent the same location. */ | |
5446 | ||
5447 | static int | |
4a64f543 MS |
5448 | breakpoint_locations_match (struct bp_location *loc1, |
5449 | struct bp_location *loc2) | |
2d134ed3 | 5450 | { |
2bdf28a0 JK |
5451 | int hw_point1, hw_point2; |
5452 | ||
5453 | /* Both of them must not be in moribund_locations. */ | |
5454 | gdb_assert (loc1->owner != NULL); | |
5455 | gdb_assert (loc2->owner != NULL); | |
5456 | ||
5457 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5458 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5459 | |
5460 | if (hw_point1 != hw_point2) | |
5461 | return 0; | |
5462 | else if (hw_point1) | |
5463 | return watchpoint_locations_match (loc1, loc2); | |
5464 | else | |
f1310107 TJB |
5465 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5466 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5467 | loc2->pspace->aspace, loc2->address) | |
5468 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5469 | } |
5470 | ||
76897487 KB |
5471 | static void |
5472 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5473 | int bnum, int have_bnum) | |
5474 | { | |
f63fbe86 MS |
5475 | /* The longest string possibly returned by hex_string_custom |
5476 | is 50 chars. These must be at least that big for safety. */ | |
5477 | char astr1[64]; | |
5478 | char astr2[64]; | |
76897487 | 5479 | |
bb599908 PH |
5480 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5481 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5482 | if (have_bnum) |
8a3fe4f8 | 5483 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5484 | bnum, astr1, astr2); |
5485 | else | |
8a3fe4f8 | 5486 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5487 | } |
5488 | ||
4a64f543 MS |
5489 | /* Adjust a breakpoint's address to account for architectural |
5490 | constraints on breakpoint placement. Return the adjusted address. | |
5491 | Note: Very few targets require this kind of adjustment. For most | |
5492 | targets, this function is simply the identity function. */ | |
76897487 KB |
5493 | |
5494 | static CORE_ADDR | |
a6d9a66e UW |
5495 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5496 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5497 | { |
a6d9a66e | 5498 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5499 | { |
5500 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5501 | return bpaddr; | |
5502 | } | |
88f7da05 KB |
5503 | else if (bptype == bp_watchpoint |
5504 | || bptype == bp_hardware_watchpoint | |
5505 | || bptype == bp_read_watchpoint | |
5506 | || bptype == bp_access_watchpoint | |
fe798b75 | 5507 | || bptype == bp_catchpoint) |
88f7da05 KB |
5508 | { |
5509 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5510 | have their addresses modified. */ | |
5511 | return bpaddr; | |
5512 | } | |
76897487 KB |
5513 | else |
5514 | { | |
5515 | CORE_ADDR adjusted_bpaddr; | |
5516 | ||
5517 | /* Some targets have architectural constraints on the placement | |
5518 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5519 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5520 | |
5521 | /* An adjusted breakpoint address can significantly alter | |
5522 | a user's expectations. Print a warning if an adjustment | |
5523 | is required. */ | |
5524 | if (adjusted_bpaddr != bpaddr) | |
5525 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5526 | ||
5527 | return adjusted_bpaddr; | |
5528 | } | |
5529 | } | |
5530 | ||
28010a5d PA |
5531 | void |
5532 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
5533 | struct breakpoint *owner) | |
7cc221ef | 5534 | { |
7cc221ef DJ |
5535 | memset (loc, 0, sizeof (*loc)); |
5536 | ||
348d480f PA |
5537 | gdb_assert (ops != NULL); |
5538 | ||
28010a5d PA |
5539 | loc->ops = ops; |
5540 | loc->owner = owner; | |
511a6cd4 | 5541 | loc->cond = NULL; |
0d381245 VP |
5542 | loc->shlib_disabled = 0; |
5543 | loc->enabled = 1; | |
e049a4b5 | 5544 | |
28010a5d | 5545 | switch (owner->type) |
e049a4b5 DJ |
5546 | { |
5547 | case bp_breakpoint: | |
5548 | case bp_until: | |
5549 | case bp_finish: | |
5550 | case bp_longjmp: | |
5551 | case bp_longjmp_resume: | |
186c406b TT |
5552 | case bp_exception: |
5553 | case bp_exception_resume: | |
e049a4b5 | 5554 | case bp_step_resume: |
2c03e5be | 5555 | case bp_hp_step_resume: |
e049a4b5 DJ |
5556 | case bp_watchpoint_scope: |
5557 | case bp_call_dummy: | |
aa7d318d | 5558 | case bp_std_terminate: |
e049a4b5 DJ |
5559 | case bp_shlib_event: |
5560 | case bp_thread_event: | |
5561 | case bp_overlay_event: | |
4efc6507 | 5562 | case bp_jit_event: |
0fd8e87f | 5563 | case bp_longjmp_master: |
aa7d318d | 5564 | case bp_std_terminate_master: |
186c406b | 5565 | case bp_exception_master: |
0e30163f JK |
5566 | case bp_gnu_ifunc_resolver: |
5567 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5568 | loc->loc_type = bp_loc_software_breakpoint; |
5569 | break; | |
5570 | case bp_hardware_breakpoint: | |
5571 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5572 | break; | |
5573 | case bp_hardware_watchpoint: | |
5574 | case bp_read_watchpoint: | |
5575 | case bp_access_watchpoint: | |
5576 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5577 | break; | |
5578 | case bp_watchpoint: | |
ce78b96d | 5579 | case bp_catchpoint: |
15c3d785 PA |
5580 | case bp_tracepoint: |
5581 | case bp_fast_tracepoint: | |
0fb4aa4b | 5582 | case bp_static_tracepoint: |
e049a4b5 DJ |
5583 | loc->loc_type = bp_loc_other; |
5584 | break; | |
5585 | default: | |
e2e0b3e5 | 5586 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5587 | } |
5588 | ||
f431efe5 | 5589 | loc->refc = 1; |
28010a5d PA |
5590 | } |
5591 | ||
5592 | /* Allocate a struct bp_location. */ | |
5593 | ||
5594 | static struct bp_location * | |
5595 | allocate_bp_location (struct breakpoint *bpt) | |
5596 | { | |
348d480f PA |
5597 | return bpt->ops->allocate_location (bpt); |
5598 | } | |
7cc221ef | 5599 | |
f431efe5 PA |
5600 | static void |
5601 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 5602 | { |
348d480f | 5603 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
5604 | xfree (loc); |
5605 | } | |
5606 | ||
f431efe5 PA |
5607 | /* Increment reference count. */ |
5608 | ||
5609 | static void | |
5610 | incref_bp_location (struct bp_location *bl) | |
5611 | { | |
5612 | ++bl->refc; | |
5613 | } | |
5614 | ||
5615 | /* Decrement reference count. If the reference count reaches 0, | |
5616 | destroy the bp_location. Sets *BLP to NULL. */ | |
5617 | ||
5618 | static void | |
5619 | decref_bp_location (struct bp_location **blp) | |
5620 | { | |
0807b50c PA |
5621 | gdb_assert ((*blp)->refc > 0); |
5622 | ||
f431efe5 PA |
5623 | if (--(*blp)->refc == 0) |
5624 | free_bp_location (*blp); | |
5625 | *blp = NULL; | |
5626 | } | |
5627 | ||
346774a9 | 5628 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 5629 | |
346774a9 PA |
5630 | static void |
5631 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 5632 | { |
346774a9 | 5633 | struct breakpoint *b1; |
c906108c | 5634 | |
346774a9 PA |
5635 | /* Add this breakpoint to the end of the chain so that a list of |
5636 | breakpoints will come out in order of increasing numbers. */ | |
5637 | ||
5638 | b1 = breakpoint_chain; | |
5639 | if (b1 == 0) | |
5640 | breakpoint_chain = b; | |
5641 | else | |
5642 | { | |
5643 | while (b1->next) | |
5644 | b1 = b1->next; | |
5645 | b1->next = b; | |
5646 | } | |
5647 | } | |
5648 | ||
5649 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
5650 | ||
5651 | static void | |
5652 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
5653 | struct gdbarch *gdbarch, | |
28010a5d | 5654 | enum bptype bptype, |
c0a91b2b | 5655 | const struct breakpoint_ops *ops) |
346774a9 | 5656 | { |
c906108c | 5657 | memset (b, 0, sizeof (*b)); |
2219d63c | 5658 | |
348d480f PA |
5659 | gdb_assert (ops != NULL); |
5660 | ||
28010a5d | 5661 | b->ops = ops; |
4d28f7a8 | 5662 | b->type = bptype; |
a6d9a66e | 5663 | b->gdbarch = gdbarch; |
c906108c SS |
5664 | b->language = current_language->la_language; |
5665 | b->input_radix = input_radix; | |
5666 | b->thread = -1; | |
b5de0fa7 | 5667 | b->enable_state = bp_enabled; |
c906108c SS |
5668 | b->next = 0; |
5669 | b->silent = 0; | |
5670 | b->ignore_count = 0; | |
5671 | b->commands = NULL; | |
818dd999 | 5672 | b->frame_id = null_frame_id; |
0d381245 | 5673 | b->condition_not_parsed = 0; |
84f4c1fe | 5674 | b->py_bp_object = NULL; |
d0fb5eae | 5675 | b->related_breakpoint = b; |
346774a9 PA |
5676 | } |
5677 | ||
5678 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
5679 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
5680 | |
5681 | static struct breakpoint * | |
5682 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 5683 | enum bptype bptype, |
c0a91b2b | 5684 | const struct breakpoint_ops *ops) |
346774a9 PA |
5685 | { |
5686 | struct breakpoint *b = XNEW (struct breakpoint); | |
5687 | ||
348d480f | 5688 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 5689 | add_to_breakpoint_chain (b); |
0d381245 VP |
5690 | return b; |
5691 | } | |
5692 | ||
0e30163f JK |
5693 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5694 | resolutions should be made as the user specified the location explicitly | |
5695 | enough. */ | |
5696 | ||
0d381245 | 5697 | static void |
0e30163f | 5698 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5699 | { |
2bdf28a0 JK |
5700 | gdb_assert (loc->owner != NULL); |
5701 | ||
0d381245 | 5702 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5703 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5704 | || is_tracepoint (loc->owner)) |
0d381245 | 5705 | { |
0e30163f JK |
5706 | int is_gnu_ifunc; |
5707 | ||
5708 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5709 | NULL, NULL, &is_gnu_ifunc); | |
5710 | ||
5711 | if (is_gnu_ifunc && !explicit_loc) | |
5712 | { | |
5713 | struct breakpoint *b = loc->owner; | |
5714 | ||
5715 | gdb_assert (loc->pspace == current_program_space); | |
5716 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5717 | &loc->requested_address)) | |
5718 | { | |
5719 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5720 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5721 | loc->requested_address, | |
5722 | b->type); | |
5723 | } | |
5724 | else if (b->type == bp_breakpoint && b->loc == loc | |
5725 | && loc->next == NULL && b->related_breakpoint == b) | |
5726 | { | |
5727 | /* Create only the whole new breakpoint of this type but do not | |
5728 | mess more complicated breakpoints with multiple locations. */ | |
5729 | b->type = bp_gnu_ifunc_resolver; | |
5730 | } | |
5731 | } | |
5732 | ||
0d381245 VP |
5733 | if (loc->function_name) |
5734 | loc->function_name = xstrdup (loc->function_name); | |
5735 | } | |
5736 | } | |
5737 | ||
a6d9a66e UW |
5738 | /* Attempt to determine architecture of location identified by SAL. */ |
5739 | static struct gdbarch * | |
5740 | get_sal_arch (struct symtab_and_line sal) | |
5741 | { | |
5742 | if (sal.section) | |
5743 | return get_objfile_arch (sal.section->objfile); | |
5744 | if (sal.symtab) | |
5745 | return get_objfile_arch (sal.symtab->objfile); | |
5746 | ||
5747 | return NULL; | |
5748 | } | |
5749 | ||
346774a9 PA |
5750 | /* Low level routine for partially initializing a breakpoint of type |
5751 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 5752 | file name, and line number are provided by SAL. |
0d381245 VP |
5753 | |
5754 | It is expected that the caller will complete the initialization of | |
5755 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 5756 | information regarding the creation of a new breakpoint. */ |
0d381245 | 5757 | |
346774a9 PA |
5758 | static void |
5759 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 5760 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5761 | const struct breakpoint_ops *ops) |
0d381245 | 5762 | { |
0d381245 | 5763 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5764 | struct gdbarch *loc_gdbarch; |
5765 | ||
28010a5d | 5766 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 5767 | |
a6d9a66e UW |
5768 | loc_gdbarch = get_sal_arch (sal); |
5769 | if (!loc_gdbarch) | |
5770 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5771 | |
6c95b8df PA |
5772 | if (bptype != bp_catchpoint) |
5773 | gdb_assert (sal.pspace != NULL); | |
5774 | ||
0d381245 VP |
5775 | /* Adjust the breakpoint's address prior to allocating a location. |
5776 | Once we call allocate_bp_location(), that mostly uninitialized | |
5777 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5778 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5779 | not want its scan of the location chain to find a breakpoint and |
5780 | location that's only been partially initialized. */ | |
4a64f543 MS |
5781 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5782 | sal.pc, b->type); | |
0d381245 | 5783 | |
39d61571 | 5784 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5785 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5786 | b->loc->requested_address = sal.pc; |
5787 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5788 | b->loc->pspace = sal.pspace; |
5789 | ||
5790 | /* Store the program space that was used to set the breakpoint, for | |
5791 | breakpoint resetting. */ | |
5792 | b->pspace = sal.pspace; | |
0d381245 VP |
5793 | |
5794 | if (sal.symtab == NULL) | |
5795 | b->source_file = NULL; | |
5796 | else | |
1b36a34b | 5797 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5798 | b->loc->section = sal.section; |
5799 | b->line_number = sal.line; | |
5800 | ||
0e30163f JK |
5801 | set_breakpoint_location_function (b->loc, |
5802 | sal.explicit_pc || sal.explicit_line); | |
c906108c | 5803 | |
c906108c | 5804 | breakpoints_changed (); |
346774a9 | 5805 | } |
c906108c | 5806 | |
346774a9 PA |
5807 | /* set_raw_breakpoint is a low level routine for allocating and |
5808 | partially initializing a breakpoint of type BPTYPE. The newly | |
5809 | created breakpoint's address, section, source file name, and line | |
5810 | number are provided by SAL. The newly created and partially | |
5811 | initialized breakpoint is added to the breakpoint chain and | |
5812 | is also returned as the value of this function. | |
5813 | ||
5814 | It is expected that the caller will complete the initialization of | |
5815 | the newly created breakpoint struct as well as output any status | |
5816 | information regarding the creation of a new breakpoint. In | |
5817 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5818 | number! Care should be taken to not allow an error to occur | |
5819 | prior to completing the initialization of the breakpoint. If this | |
5820 | should happen, a bogus breakpoint will be left on the chain. */ | |
5821 | ||
5822 | struct breakpoint * | |
5823 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 5824 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5825 | const struct breakpoint_ops *ops) |
346774a9 PA |
5826 | { |
5827 | struct breakpoint *b = XNEW (struct breakpoint); | |
5828 | ||
348d480f | 5829 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 5830 | add_to_breakpoint_chain (b); |
c906108c SS |
5831 | return b; |
5832 | } | |
5833 | ||
c2c6d25f JM |
5834 | |
5835 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5836 | instruction, hard-wired into the inferior's code. */ | |
5837 | void | |
5838 | make_breakpoint_permanent (struct breakpoint *b) | |
5839 | { | |
0d381245 | 5840 | struct bp_location *bl; |
cc59ec59 | 5841 | |
b5de0fa7 | 5842 | b->enable_state = bp_permanent; |
c2c6d25f | 5843 | |
4a64f543 MS |
5844 | /* By definition, permanent breakpoints are already present in the |
5845 | code. Mark all locations as inserted. For now, | |
5846 | make_breakpoint_permanent is called in just one place, so it's | |
5847 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 5848 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
5849 | for (bl = b->loc; bl; bl = bl->next) |
5850 | bl->inserted = 1; | |
c2c6d25f JM |
5851 | } |
5852 | ||
53a5351d | 5853 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5854 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5855 | initiated the operation. */ | |
c906108c SS |
5856 | |
5857 | void | |
186c406b | 5858 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5859 | { |
35df4500 | 5860 | struct breakpoint *b, *b_tmp; |
186c406b | 5861 | int thread = tp->num; |
0fd8e87f UW |
5862 | |
5863 | /* To avoid having to rescan all objfile symbols at every step, | |
5864 | we maintain a list of continually-inserted but always disabled | |
5865 | longjmp "master" breakpoints. Here, we simply create momentary | |
5866 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5867 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5868 | if (b->pspace == current_program_space |
186c406b TT |
5869 | && (b->type == bp_longjmp_master |
5870 | || b->type == bp_exception_master)) | |
0fd8e87f | 5871 | { |
06edf0c0 PA |
5872 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
5873 | struct breakpoint *clone; | |
cc59ec59 | 5874 | |
06edf0c0 PA |
5875 | clone = momentary_breakpoint_from_master (b, type, |
5876 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
5877 | clone->thread = thread; |
5878 | } | |
186c406b TT |
5879 | |
5880 | tp->initiating_frame = frame; | |
c906108c SS |
5881 | } |
5882 | ||
611c83ae | 5883 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5884 | void |
611c83ae | 5885 | delete_longjmp_breakpoint (int thread) |
c906108c | 5886 | { |
35df4500 | 5887 | struct breakpoint *b, *b_tmp; |
c906108c | 5888 | |
35df4500 | 5889 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5890 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5891 | { |
5892 | if (b->thread == thread) | |
5893 | delete_breakpoint (b); | |
5894 | } | |
c906108c SS |
5895 | } |
5896 | ||
1900040c MS |
5897 | void |
5898 | enable_overlay_breakpoints (void) | |
5899 | { | |
52f0bd74 | 5900 | struct breakpoint *b; |
1900040c MS |
5901 | |
5902 | ALL_BREAKPOINTS (b) | |
5903 | if (b->type == bp_overlay_event) | |
5904 | { | |
5905 | b->enable_state = bp_enabled; | |
b60e7edf | 5906 | update_global_location_list (1); |
c02f5703 | 5907 | overlay_events_enabled = 1; |
1900040c MS |
5908 | } |
5909 | } | |
5910 | ||
5911 | void | |
5912 | disable_overlay_breakpoints (void) | |
5913 | { | |
52f0bd74 | 5914 | struct breakpoint *b; |
1900040c MS |
5915 | |
5916 | ALL_BREAKPOINTS (b) | |
5917 | if (b->type == bp_overlay_event) | |
5918 | { | |
5919 | b->enable_state = bp_disabled; | |
b60e7edf | 5920 | update_global_location_list (0); |
c02f5703 | 5921 | overlay_events_enabled = 0; |
1900040c MS |
5922 | } |
5923 | } | |
5924 | ||
aa7d318d TT |
5925 | /* Set an active std::terminate breakpoint for each std::terminate |
5926 | master breakpoint. */ | |
5927 | void | |
5928 | set_std_terminate_breakpoint (void) | |
5929 | { | |
35df4500 | 5930 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5931 | |
35df4500 | 5932 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5933 | if (b->pspace == current_program_space |
5934 | && b->type == bp_std_terminate_master) | |
5935 | { | |
06edf0c0 PA |
5936 | momentary_breakpoint_from_master (b, bp_std_terminate, |
5937 | &momentary_breakpoint_ops); | |
aa7d318d TT |
5938 | } |
5939 | } | |
5940 | ||
5941 | /* Delete all the std::terminate breakpoints. */ | |
5942 | void | |
5943 | delete_std_terminate_breakpoint (void) | |
5944 | { | |
35df4500 | 5945 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5946 | |
35df4500 | 5947 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5948 | if (b->type == bp_std_terminate) |
5949 | delete_breakpoint (b); | |
5950 | } | |
5951 | ||
c4093a6a | 5952 | struct breakpoint * |
a6d9a66e | 5953 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5954 | { |
5955 | struct breakpoint *b; | |
c4093a6a | 5956 | |
06edf0c0 PA |
5957 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
5958 | &internal_breakpoint_ops); | |
5959 | ||
b5de0fa7 | 5960 | b->enable_state = bp_enabled; |
c4093a6a | 5961 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5962 | b->addr_string |
5963 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5964 | |
b60e7edf | 5965 | update_global_location_list_nothrow (1); |
74960c60 | 5966 | |
c4093a6a JM |
5967 | return b; |
5968 | } | |
5969 | ||
5970 | void | |
5971 | remove_thread_event_breakpoints (void) | |
5972 | { | |
35df4500 | 5973 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5974 | |
35df4500 | 5975 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5976 | if (b->type == bp_thread_event |
5977 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5978 | delete_breakpoint (b); |
5979 | } | |
5980 | ||
0101ce28 JJ |
5981 | struct lang_and_radix |
5982 | { | |
5983 | enum language lang; | |
5984 | int radix; | |
5985 | }; | |
5986 | ||
4efc6507 DE |
5987 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5988 | ||
5989 | struct breakpoint * | |
5990 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5991 | { | |
5992 | struct breakpoint *b; | |
5993 | ||
06edf0c0 PA |
5994 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
5995 | &internal_breakpoint_ops); | |
4efc6507 DE |
5996 | update_global_location_list_nothrow (1); |
5997 | return b; | |
5998 | } | |
0101ce28 | 5999 | |
03673fc7 PP |
6000 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6001 | ||
6002 | void | |
6003 | remove_jit_event_breakpoints (void) | |
6004 | { | |
6005 | struct breakpoint *b, *b_tmp; | |
6006 | ||
6007 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6008 | if (b->type == bp_jit_event | |
6009 | && b->loc->pspace == current_program_space) | |
6010 | delete_breakpoint (b); | |
6011 | } | |
6012 | ||
cae688ec JJ |
6013 | void |
6014 | remove_solib_event_breakpoints (void) | |
6015 | { | |
35df4500 | 6016 | struct breakpoint *b, *b_tmp; |
cae688ec | 6017 | |
35df4500 | 6018 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6019 | if (b->type == bp_shlib_event |
6020 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6021 | delete_breakpoint (b); |
6022 | } | |
6023 | ||
6024 | struct breakpoint * | |
a6d9a66e | 6025 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6026 | { |
6027 | struct breakpoint *b; | |
6028 | ||
06edf0c0 PA |
6029 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6030 | &internal_breakpoint_ops); | |
b60e7edf | 6031 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6032 | return b; |
6033 | } | |
6034 | ||
6035 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6036 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6037 | ||
6038 | void | |
cb851954 | 6039 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6040 | { |
876fa593 | 6041 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6042 | |
876fa593 | 6043 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6044 | { |
2bdf28a0 | 6045 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6046 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6047 | |
4a64f543 MS |
6048 | /* We apply the check to all breakpoints, including disabled for |
6049 | those with loc->duplicate set. This is so that when breakpoint | |
6050 | becomes enabled, or the duplicate is removed, gdb will try to | |
6051 | insert all breakpoints. If we don't set shlib_disabled here, | |
6052 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6053 | if (((b->type == bp_breakpoint) |
508ccb1f | 6054 | || (b->type == bp_jit_event) |
1042e4c0 | 6055 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6056 | || (is_tracepoint (b))) |
6c95b8df | 6057 | && loc->pspace == current_program_space |
0d381245 | 6058 | && !loc->shlib_disabled |
a77053c2 | 6059 | #ifdef PC_SOLIB |
0d381245 | 6060 | && PC_SOLIB (loc->address) |
a77053c2 | 6061 | #else |
6c95b8df | 6062 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6063 | #endif |
6064 | ) | |
0d381245 VP |
6065 | { |
6066 | loc->shlib_disabled = 1; | |
6067 | } | |
cae688ec JJ |
6068 | } |
6069 | } | |
6070 | ||
7a9dd1b2 | 6071 | /* Disable any breakpoints that are in an unloaded shared library. |
4a64f543 MS |
6072 | Only apply to enabled breakpoints, disabled ones can just stay |
6073 | disabled. */ | |
84acb35a | 6074 | |
75149521 | 6075 | static void |
84acb35a JJ |
6076 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6077 | { | |
876fa593 | 6078 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6079 | int disabled_shlib_breaks = 0; |
6080 | ||
c86cf029 VP |
6081 | /* SunOS a.out shared libraries are always mapped, so do not |
6082 | disable breakpoints; they will only be reported as unloaded | |
6083 | through clear_solib when GDB discards its shared library | |
6084 | list. See clear_solib for more information. */ | |
6085 | if (exec_bfd != NULL | |
6086 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6087 | return; | |
6088 | ||
876fa593 | 6089 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6090 | { |
2bdf28a0 | 6091 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6092 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6093 | |
0d381245 VP |
6094 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6095 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6096 | && solib->pspace == loc->pspace |
e2dd7057 | 6097 | && !loc->shlib_disabled |
508ccb1f TT |
6098 | && (b->type == bp_breakpoint |
6099 | || b->type == bp_jit_event | |
6100 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6101 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6102 | { |
e2dd7057 PP |
6103 | loc->shlib_disabled = 1; |
6104 | /* At this point, we cannot rely on remove_breakpoint | |
6105 | succeeding so we must mark the breakpoint as not inserted | |
6106 | to prevent future errors occurring in remove_breakpoints. */ | |
6107 | loc->inserted = 0; | |
8d3788bd VP |
6108 | |
6109 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6110 | observer_notify_breakpoint_modified (b); | |
6111 | ||
e2dd7057 PP |
6112 | if (!disabled_shlib_breaks) |
6113 | { | |
6114 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6115 | warning (_("Temporarily disabling breakpoints " |
6116 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6117 | solib->so_name); |
84acb35a | 6118 | } |
e2dd7057 | 6119 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6120 | } |
6121 | } | |
84acb35a JJ |
6122 | } |
6123 | ||
ce78b96d JB |
6124 | /* FORK & VFORK catchpoints. */ |
6125 | ||
e29a4733 PA |
6126 | /* An instance of this type is used to represent a fork or vfork |
6127 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6128 | class; users downcast to "struct breakpoint *" when needed. A | |
6129 | breakpoint is really of this type iff its ops pointer points to | |
6130 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6131 | ||
6132 | struct fork_catchpoint | |
6133 | { | |
6134 | /* The base class. */ | |
6135 | struct breakpoint base; | |
6136 | ||
6137 | /* Process id of a child process whose forking triggered this | |
6138 | catchpoint. This field is only valid immediately after this | |
6139 | catchpoint has triggered. */ | |
6140 | ptid_t forked_inferior_pid; | |
6141 | }; | |
6142 | ||
4a64f543 MS |
6143 | /* Implement the "insert" breakpoint_ops method for fork |
6144 | catchpoints. */ | |
ce78b96d | 6145 | |
77b06cd7 TJB |
6146 | static int |
6147 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6148 | { |
77b06cd7 | 6149 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6150 | } |
6151 | ||
4a64f543 MS |
6152 | /* Implement the "remove" breakpoint_ops method for fork |
6153 | catchpoints. */ | |
ce78b96d JB |
6154 | |
6155 | static int | |
77b06cd7 | 6156 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6157 | { |
6158 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6159 | } | |
6160 | ||
6161 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6162 | catchpoints. */ | |
6163 | ||
6164 | static int | |
f1310107 TJB |
6165 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
6166 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6167 | { |
e29a4733 PA |
6168 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6169 | ||
6170 | return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6171 | } |
6172 | ||
4a64f543 MS |
6173 | /* Implement the "print_it" breakpoint_ops method for fork |
6174 | catchpoints. */ | |
ce78b96d JB |
6175 | |
6176 | static enum print_stop_action | |
348d480f | 6177 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6178 | { |
348d480f PA |
6179 | struct breakpoint *b = bs->breakpoint_at; |
6180 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6181 | |
ce78b96d JB |
6182 | annotate_catchpoint (b->number); |
6183 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
e29a4733 | 6184 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6185 | return PRINT_SRC_AND_LOC; |
6186 | } | |
6187 | ||
4a64f543 MS |
6188 | /* Implement the "print_one" breakpoint_ops method for fork |
6189 | catchpoints. */ | |
ce78b96d JB |
6190 | |
6191 | static void | |
a6d9a66e | 6192 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6193 | { |
e29a4733 | 6194 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6195 | struct value_print_options opts; |
79a45e25 | 6196 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6197 | |
6198 | get_user_print_options (&opts); | |
6199 | ||
4a64f543 MS |
6200 | /* Field 4, the address, is omitted (which makes the columns not |
6201 | line up too nicely with the headers, but the effect is relatively | |
6202 | readable). */ | |
79a45b7d | 6203 | if (opts.addressprint) |
ce78b96d JB |
6204 | ui_out_field_skip (uiout, "addr"); |
6205 | annotate_field (5); | |
6206 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6207 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6208 | { |
6209 | ui_out_text (uiout, ", process "); | |
6210 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6211 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6212 | ui_out_spaces (uiout, 1); |
6213 | } | |
6214 | } | |
6215 | ||
6216 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6217 | catchpoints. */ | |
6218 | ||
6219 | static void | |
6220 | print_mention_catch_fork (struct breakpoint *b) | |
6221 | { | |
6222 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6223 | } | |
6224 | ||
6149aea9 PA |
6225 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6226 | catchpoints. */ | |
6227 | ||
6228 | static void | |
6229 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6230 | { | |
6231 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6232 | print_recreate_thread (b, fp); |
6149aea9 PA |
6233 | } |
6234 | ||
ce78b96d JB |
6235 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6236 | ||
2060206e | 6237 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 6238 | |
4a64f543 MS |
6239 | /* Implement the "insert" breakpoint_ops method for vfork |
6240 | catchpoints. */ | |
ce78b96d | 6241 | |
77b06cd7 TJB |
6242 | static int |
6243 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6244 | { |
77b06cd7 | 6245 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6246 | } |
6247 | ||
4a64f543 MS |
6248 | /* Implement the "remove" breakpoint_ops method for vfork |
6249 | catchpoints. */ | |
ce78b96d JB |
6250 | |
6251 | static int | |
77b06cd7 | 6252 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6253 | { |
6254 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6255 | } | |
6256 | ||
6257 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6258 | catchpoints. */ | |
6259 | ||
6260 | static int | |
f1310107 TJB |
6261 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
6262 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6263 | { |
e29a4733 PA |
6264 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6265 | ||
6266 | return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6267 | } |
6268 | ||
4a64f543 MS |
6269 | /* Implement the "print_it" breakpoint_ops method for vfork |
6270 | catchpoints. */ | |
ce78b96d JB |
6271 | |
6272 | static enum print_stop_action | |
348d480f | 6273 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 6274 | { |
348d480f | 6275 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
6276 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6277 | ||
ce78b96d JB |
6278 | annotate_catchpoint (b->number); |
6279 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
e29a4733 | 6280 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6281 | return PRINT_SRC_AND_LOC; |
6282 | } | |
6283 | ||
4a64f543 MS |
6284 | /* Implement the "print_one" breakpoint_ops method for vfork |
6285 | catchpoints. */ | |
ce78b96d JB |
6286 | |
6287 | static void | |
a6d9a66e | 6288 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6289 | { |
e29a4733 | 6290 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d | 6291 | struct value_print_options opts; |
79a45e25 | 6292 | struct ui_out *uiout = current_uiout; |
79a45b7d TT |
6293 | |
6294 | get_user_print_options (&opts); | |
4a64f543 MS |
6295 | /* Field 4, the address, is omitted (which makes the columns not |
6296 | line up too nicely with the headers, but the effect is relatively | |
6297 | readable). */ | |
79a45b7d | 6298 | if (opts.addressprint) |
ce78b96d JB |
6299 | ui_out_field_skip (uiout, "addr"); |
6300 | annotate_field (5); | |
6301 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 6302 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6303 | { |
6304 | ui_out_text (uiout, ", process "); | |
6305 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6306 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6307 | ui_out_spaces (uiout, 1); |
6308 | } | |
6309 | } | |
6310 | ||
6311 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6312 | catchpoints. */ | |
6313 | ||
6314 | static void | |
6315 | print_mention_catch_vfork (struct breakpoint *b) | |
6316 | { | |
6317 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6318 | } | |
6319 | ||
6149aea9 PA |
6320 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6321 | catchpoints. */ | |
6322 | ||
6323 | static void | |
6324 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6325 | { | |
6326 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 6327 | print_recreate_thread (b, fp); |
6149aea9 PA |
6328 | } |
6329 | ||
ce78b96d JB |
6330 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6331 | ||
2060206e | 6332 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 6333 | |
be5c67c1 PA |
6334 | /* An instance of this type is used to represent a syscall catchpoint. |
6335 | It includes a "struct breakpoint" as a kind of base class; users | |
6336 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6337 | really of this type iff its ops pointer points to | |
6338 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
6339 | ||
6340 | struct syscall_catchpoint | |
6341 | { | |
6342 | /* The base class. */ | |
6343 | struct breakpoint base; | |
6344 | ||
6345 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
6346 | syscall has been specified for filtering, its value is NULL. | |
6347 | Otherwise, it holds a list of all syscalls to be caught. The | |
6348 | list elements are allocated with xmalloc. */ | |
6349 | VEC(int) *syscalls_to_be_caught; | |
6350 | }; | |
6351 | ||
6352 | /* Implement the "dtor" breakpoint_ops method for syscall | |
6353 | catchpoints. */ | |
6354 | ||
6355 | static void | |
6356 | dtor_catch_syscall (struct breakpoint *b) | |
6357 | { | |
6358 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
6359 | ||
6360 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 6361 | |
2060206e | 6362 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
6363 | } |
6364 | ||
a96d9b2e SDJ |
6365 | /* Implement the "insert" breakpoint_ops method for syscall |
6366 | catchpoints. */ | |
6367 | ||
77b06cd7 TJB |
6368 | static int |
6369 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 6370 | { |
be5c67c1 | 6371 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6372 | struct inferior *inf = current_inferior (); |
6373 | ||
6374 | ++inf->total_syscalls_count; | |
be5c67c1 | 6375 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6376 | ++inf->any_syscall_count; |
6377 | else | |
6378 | { | |
6379 | int i, iter; | |
cc59ec59 | 6380 | |
a96d9b2e | 6381 | for (i = 0; |
be5c67c1 | 6382 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6383 | i++) |
6384 | { | |
6385 | int elem; | |
cc59ec59 | 6386 | |
a96d9b2e SDJ |
6387 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6388 | { | |
6389 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6390 | uintptr_t vec_addr_offset |
6391 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6392 | uintptr_t vec_addr; |
6393 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6394 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6395 | vec_addr_offset; | |
6396 | memset ((void *) vec_addr, 0, | |
6397 | (iter + 1 - old_size) * sizeof (int)); | |
6398 | } | |
6399 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6400 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6401 | } | |
6402 | } | |
6403 | ||
77b06cd7 TJB |
6404 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6405 | inf->total_syscalls_count != 0, | |
6406 | inf->any_syscall_count, | |
6407 | VEC_length (int, inf->syscalls_counts), | |
6408 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6409 | } |
6410 | ||
6411 | /* Implement the "remove" breakpoint_ops method for syscall | |
6412 | catchpoints. */ | |
6413 | ||
6414 | static int | |
77b06cd7 | 6415 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 6416 | { |
be5c67c1 | 6417 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6418 | struct inferior *inf = current_inferior (); |
6419 | ||
6420 | --inf->total_syscalls_count; | |
be5c67c1 | 6421 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6422 | --inf->any_syscall_count; |
6423 | else | |
6424 | { | |
6425 | int i, iter; | |
cc59ec59 | 6426 | |
a96d9b2e | 6427 | for (i = 0; |
be5c67c1 | 6428 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6429 | i++) |
6430 | { | |
6431 | int elem; | |
6432 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6433 | /* Shouldn't happen. */ | |
6434 | continue; | |
6435 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6436 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6437 | } | |
6438 | } | |
6439 | ||
6440 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6441 | inf->total_syscalls_count != 0, | |
6442 | inf->any_syscall_count, | |
6443 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6444 | VEC_address (int, |
6445 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6446 | } |
6447 | ||
6448 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6449 | catchpoints. */ | |
6450 | ||
6451 | static int | |
f1310107 TJB |
6452 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
6453 | struct address_space *aspace, CORE_ADDR bp_addr) | |
a96d9b2e | 6454 | { |
4a64f543 MS |
6455 | /* We must check if we are catching specific syscalls in this |
6456 | breakpoint. If we are, then we must guarantee that the called | |
6457 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6458 | int syscall_number = 0; |
be5c67c1 PA |
6459 | const struct syscall_catchpoint *c |
6460 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e SDJ |
6461 | |
6462 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6463 | return 0; | |
6464 | ||
6465 | /* Now, checking if the syscall is the same. */ | |
be5c67c1 | 6466 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6467 | { |
6468 | int i, iter; | |
cc59ec59 | 6469 | |
a96d9b2e | 6470 | for (i = 0; |
be5c67c1 | 6471 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6472 | i++) |
6473 | if (syscall_number == iter) | |
6474 | break; | |
6475 | /* Not the same. */ | |
6476 | if (!iter) | |
6477 | return 0; | |
6478 | } | |
6479 | ||
6480 | return 1; | |
6481 | } | |
6482 | ||
6483 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6484 | catchpoints. */ | |
6485 | ||
6486 | static enum print_stop_action | |
348d480f | 6487 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 6488 | { |
348d480f | 6489 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
6490 | /* These are needed because we want to know in which state a |
6491 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6492 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6493 | must print "called syscall" or "returned from syscall". */ | |
6494 | ptid_t ptid; | |
6495 | struct target_waitstatus last; | |
6496 | struct syscall s; | |
6497 | struct cleanup *old_chain; | |
6498 | char *syscall_id; | |
6499 | ||
6500 | get_last_target_status (&ptid, &last); | |
6501 | ||
6502 | get_syscall_by_number (last.value.syscall_number, &s); | |
6503 | ||
6504 | annotate_catchpoint (b->number); | |
6505 | ||
6506 | if (s.name == NULL) | |
6507 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6508 | else | |
6509 | syscall_id = xstrprintf ("'%s'", s.name); | |
6510 | ||
6511 | old_chain = make_cleanup (xfree, syscall_id); | |
6512 | ||
6513 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6514 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6515 | b->number, syscall_id); | |
6516 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6517 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6518 | b->number, syscall_id); | |
6519 | ||
6520 | do_cleanups (old_chain); | |
6521 | ||
6522 | return PRINT_SRC_AND_LOC; | |
6523 | } | |
6524 | ||
6525 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6526 | catchpoints. */ | |
6527 | ||
6528 | static void | |
6529 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6530 | struct bp_location **last_loc) |
a96d9b2e | 6531 | { |
be5c67c1 | 6532 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e | 6533 | struct value_print_options opts; |
79a45e25 | 6534 | struct ui_out *uiout = current_uiout; |
a96d9b2e SDJ |
6535 | |
6536 | get_user_print_options (&opts); | |
4a64f543 MS |
6537 | /* Field 4, the address, is omitted (which makes the columns not |
6538 | line up too nicely with the headers, but the effect is relatively | |
6539 | readable). */ | |
a96d9b2e SDJ |
6540 | if (opts.addressprint) |
6541 | ui_out_field_skip (uiout, "addr"); | |
6542 | annotate_field (5); | |
6543 | ||
be5c67c1 PA |
6544 | if (c->syscalls_to_be_caught |
6545 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
6546 | ui_out_text (uiout, "syscalls \""); |
6547 | else | |
6548 | ui_out_text (uiout, "syscall \""); | |
6549 | ||
be5c67c1 | 6550 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6551 | { |
6552 | int i, iter; | |
6553 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6554 | |
a96d9b2e | 6555 | for (i = 0; |
be5c67c1 | 6556 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6557 | i++) |
6558 | { | |
6559 | char *x = text; | |
6560 | struct syscall s; | |
6561 | get_syscall_by_number (iter, &s); | |
6562 | ||
6563 | if (s.name != NULL) | |
6564 | text = xstrprintf ("%s%s, ", text, s.name); | |
6565 | else | |
6566 | text = xstrprintf ("%s%d, ", text, iter); | |
6567 | ||
6568 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 6569 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
6570 | on every call. */ |
6571 | xfree (x); | |
6572 | } | |
6573 | /* Remove the last comma. */ | |
6574 | text[strlen (text) - 2] = '\0'; | |
6575 | ui_out_field_string (uiout, "what", text); | |
6576 | } | |
6577 | else | |
6578 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6579 | ui_out_text (uiout, "\" "); | |
6580 | } | |
6581 | ||
6582 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6583 | catchpoints. */ | |
6584 | ||
6585 | static void | |
6586 | print_mention_catch_syscall (struct breakpoint *b) | |
6587 | { | |
be5c67c1 PA |
6588 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6589 | ||
6590 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
6591 | { |
6592 | int i, iter; | |
6593 | ||
be5c67c1 | 6594 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
6595 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
6596 | else | |
6597 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6598 | ||
6599 | for (i = 0; | |
be5c67c1 | 6600 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6601 | i++) |
6602 | { | |
6603 | struct syscall s; | |
6604 | get_syscall_by_number (iter, &s); | |
6605 | ||
6606 | if (s.name) | |
6607 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6608 | else | |
6609 | printf_filtered (" %d", s.number); | |
6610 | } | |
6611 | printf_filtered (")"); | |
6612 | } | |
6613 | else | |
6614 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6615 | b->number); | |
6616 | } | |
6617 | ||
6149aea9 PA |
6618 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6619 | catchpoints. */ | |
6620 | ||
6621 | static void | |
6622 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6623 | { | |
be5c67c1 PA |
6624 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6625 | ||
6149aea9 PA |
6626 | fprintf_unfiltered (fp, "catch syscall"); |
6627 | ||
be5c67c1 | 6628 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
6629 | { |
6630 | int i, iter; | |
6631 | ||
6632 | for (i = 0; | |
be5c67c1 | 6633 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
6634 | i++) |
6635 | { | |
6636 | struct syscall s; | |
6637 | ||
6638 | get_syscall_by_number (iter, &s); | |
6639 | if (s.name) | |
6640 | fprintf_unfiltered (fp, " %s", s.name); | |
6641 | else | |
6642 | fprintf_unfiltered (fp, " %d", s.number); | |
6643 | } | |
6644 | } | |
d9b3f62e | 6645 | print_recreate_thread (b, fp); |
6149aea9 PA |
6646 | } |
6647 | ||
a96d9b2e SDJ |
6648 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6649 | ||
2060206e | 6650 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
6651 | |
6652 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6653 | ||
6654 | static int | |
6655 | syscall_catchpoint_p (struct breakpoint *b) | |
6656 | { | |
6657 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6658 | } | |
6659 | ||
346774a9 PA |
6660 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
6661 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
6662 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
6663 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 6664 | |
346774a9 PA |
6665 | static void |
6666 | init_catchpoint (struct breakpoint *b, | |
6667 | struct gdbarch *gdbarch, int tempflag, | |
6668 | char *cond_string, | |
c0a91b2b | 6669 | const struct breakpoint_ops *ops) |
c906108c | 6670 | { |
c5aa993b | 6671 | struct symtab_and_line sal; |
346774a9 | 6672 | |
fe39c653 | 6673 | init_sal (&sal); |
6c95b8df | 6674 | sal.pspace = current_program_space; |
c5aa993b | 6675 | |
28010a5d | 6676 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 6677 | |
1b36a34b | 6678 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 6679 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
6680 | } |
6681 | ||
28010a5d | 6682 | void |
3a5c3e22 | 6683 | install_breakpoint (int internal, struct breakpoint *b) |
c56053d2 PA |
6684 | { |
6685 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
6686 | set_breakpoint_number (internal, b); |
6687 | if (!internal) | |
6688 | mention (b); | |
c56053d2 PA |
6689 | observer_notify_breakpoint_created (b); |
6690 | update_global_location_list (1); | |
6691 | } | |
6692 | ||
9b70b993 | 6693 | static void |
a6d9a66e UW |
6694 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6695 | int tempflag, char *cond_string, | |
c0a91b2b | 6696 | const struct breakpoint_ops *ops) |
c906108c | 6697 | { |
e29a4733 | 6698 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 6699 | |
e29a4733 PA |
6700 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
6701 | ||
6702 | c->forked_inferior_pid = null_ptid; | |
6703 | ||
3a5c3e22 | 6704 | install_breakpoint (0, &c->base); |
c906108c SS |
6705 | } |
6706 | ||
fe798b75 JB |
6707 | /* Exec catchpoints. */ |
6708 | ||
b4d90040 PA |
6709 | /* An instance of this type is used to represent an exec catchpoint. |
6710 | It includes a "struct breakpoint" as a kind of base class; users | |
6711 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6712 | really of this type iff its ops pointer points to | |
6713 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
6714 | ||
6715 | struct exec_catchpoint | |
6716 | { | |
6717 | /* The base class. */ | |
6718 | struct breakpoint base; | |
6719 | ||
6720 | /* Filename of a program whose exec triggered this catchpoint. | |
6721 | This field is only valid immediately after this catchpoint has | |
6722 | triggered. */ | |
6723 | char *exec_pathname; | |
6724 | }; | |
6725 | ||
6726 | /* Implement the "dtor" breakpoint_ops method for exec | |
6727 | catchpoints. */ | |
6728 | ||
6729 | static void | |
6730 | dtor_catch_exec (struct breakpoint *b) | |
6731 | { | |
6732 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
6733 | ||
6734 | xfree (c->exec_pathname); | |
348d480f | 6735 | |
2060206e | 6736 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
6737 | } |
6738 | ||
77b06cd7 TJB |
6739 | static int |
6740 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6741 | { |
77b06cd7 | 6742 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6743 | } |
c906108c | 6744 | |
fe798b75 | 6745 | static int |
77b06cd7 | 6746 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6747 | { |
6748 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6749 | } | |
c906108c | 6750 | |
fe798b75 | 6751 | static int |
f1310107 TJB |
6752 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
6753 | struct address_space *aspace, CORE_ADDR bp_addr) | |
fe798b75 | 6754 | { |
b4d90040 PA |
6755 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
6756 | ||
6757 | return inferior_has_execd (inferior_ptid, &c->exec_pathname); | |
fe798b75 | 6758 | } |
c906108c | 6759 | |
fe798b75 | 6760 | static enum print_stop_action |
348d480f | 6761 | print_it_catch_exec (bpstat bs) |
fe798b75 | 6762 | { |
348d480f | 6763 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
6764 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
6765 | ||
fe798b75 JB |
6766 | annotate_catchpoint (b->number); |
6767 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
b4d90040 | 6768 | c->exec_pathname); |
fe798b75 | 6769 | return PRINT_SRC_AND_LOC; |
c906108c SS |
6770 | } |
6771 | ||
fe798b75 | 6772 | static void |
a6d9a66e | 6773 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 6774 | { |
b4d90040 | 6775 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 | 6776 | struct value_print_options opts; |
79a45e25 | 6777 | struct ui_out *uiout = current_uiout; |
fe798b75 JB |
6778 | |
6779 | get_user_print_options (&opts); | |
6780 | ||
6781 | /* Field 4, the address, is omitted (which makes the columns | |
6782 | not line up too nicely with the headers, but the effect | |
6783 | is relatively readable). */ | |
6784 | if (opts.addressprint) | |
6785 | ui_out_field_skip (uiout, "addr"); | |
6786 | annotate_field (5); | |
6787 | ui_out_text (uiout, "exec"); | |
b4d90040 | 6788 | if (c->exec_pathname != NULL) |
fe798b75 JB |
6789 | { |
6790 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 6791 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
6792 | ui_out_text (uiout, "\" "); |
6793 | } | |
6794 | } | |
6795 | ||
6796 | static void | |
6797 | print_mention_catch_exec (struct breakpoint *b) | |
6798 | { | |
6799 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6800 | } | |
6801 | ||
6149aea9 PA |
6802 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6803 | catchpoints. */ | |
6804 | ||
6805 | static void | |
6806 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6807 | { | |
6808 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 6809 | print_recreate_thread (b, fp); |
6149aea9 PA |
6810 | } |
6811 | ||
2060206e | 6812 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 6813 | |
a96d9b2e SDJ |
6814 | static void |
6815 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 6816 | const struct breakpoint_ops *ops) |
a96d9b2e | 6817 | { |
be5c67c1 | 6818 | struct syscall_catchpoint *c; |
a96d9b2e | 6819 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 6820 | |
be5c67c1 PA |
6821 | c = XNEW (struct syscall_catchpoint); |
6822 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
6823 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 6824 | |
3a5c3e22 | 6825 | install_breakpoint (0, &c->base); |
a96d9b2e SDJ |
6826 | } |
6827 | ||
c906108c | 6828 | static int |
fba45db2 | 6829 | hw_breakpoint_used_count (void) |
c906108c | 6830 | { |
c906108c | 6831 | int i = 0; |
f1310107 TJB |
6832 | struct breakpoint *b; |
6833 | struct bp_location *bl; | |
c906108c SS |
6834 | |
6835 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6836 | { |
d6b74ac4 | 6837 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
6838 | for (bl = b->loc; bl; bl = bl->next) |
6839 | { | |
6840 | /* Special types of hardware breakpoints may use more than | |
6841 | one register. */ | |
348d480f | 6842 | i += b->ops->resources_needed (bl); |
f1310107 | 6843 | } |
c5aa993b | 6844 | } |
c906108c SS |
6845 | |
6846 | return i; | |
6847 | } | |
6848 | ||
6849 | static int | |
fba45db2 | 6850 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6851 | { |
c906108c | 6852 | int i = 0; |
e09342b5 TJB |
6853 | struct breakpoint *b; |
6854 | struct bp_location *bl; | |
c906108c SS |
6855 | |
6856 | *other_type_used = 0; | |
6857 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6858 | { |
6859 | if (!breakpoint_enabled (b)) | |
6860 | continue; | |
6861 | ||
c5aa993b | 6862 | if (b->type == type) |
e09342b5 TJB |
6863 | for (bl = b->loc; bl; bl = bl->next) |
6864 | { | |
6865 | /* Special types of hardware watchpoints may use more than | |
6866 | one register. */ | |
348d480f | 6867 | i += b->ops->resources_needed (bl); |
e09342b5 | 6868 | } |
cc60f2e3 | 6869 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6870 | *other_type_used = 1; |
e09342b5 TJB |
6871 | } |
6872 | ||
c906108c SS |
6873 | return i; |
6874 | } | |
6875 | ||
c906108c | 6876 | void |
fba45db2 | 6877 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6878 | { |
c5aa993b | 6879 | struct breakpoint *b; |
c906108c SS |
6880 | |
6881 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6882 | { |
cc60f2e3 | 6883 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6884 | { |
b5de0fa7 | 6885 | b->enable_state = bp_call_disabled; |
b60e7edf | 6886 | update_global_location_list (0); |
c5aa993b JM |
6887 | } |
6888 | } | |
c906108c SS |
6889 | } |
6890 | ||
6891 | void | |
fba45db2 | 6892 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6893 | { |
c5aa993b | 6894 | struct breakpoint *b; |
c906108c SS |
6895 | |
6896 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6897 | { |
cc60f2e3 | 6898 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6899 | { |
b5de0fa7 | 6900 | b->enable_state = bp_enabled; |
b60e7edf | 6901 | update_global_location_list (1); |
c5aa993b JM |
6902 | } |
6903 | } | |
c906108c SS |
6904 | } |
6905 | ||
8bea4e01 UW |
6906 | void |
6907 | disable_breakpoints_before_startup (void) | |
6908 | { | |
6909 | struct breakpoint *b; | |
6910 | int found = 0; | |
6911 | ||
6912 | ALL_BREAKPOINTS (b) | |
6913 | { | |
6c95b8df PA |
6914 | if (b->pspace != current_program_space) |
6915 | continue; | |
6916 | ||
8bea4e01 UW |
6917 | if ((b->type == bp_breakpoint |
6918 | || b->type == bp_hardware_breakpoint) | |
6919 | && breakpoint_enabled (b)) | |
6920 | { | |
6921 | b->enable_state = bp_startup_disabled; | |
6922 | found = 1; | |
6923 | } | |
6924 | } | |
6925 | ||
6926 | if (found) | |
6927 | update_global_location_list (0); | |
6928 | ||
6c95b8df | 6929 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6930 | } |
6931 | ||
6932 | void | |
6933 | enable_breakpoints_after_startup (void) | |
6934 | { | |
6935 | struct breakpoint *b; | |
6936 | int found = 0; | |
6937 | ||
6c95b8df | 6938 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6939 | |
6940 | ALL_BREAKPOINTS (b) | |
6941 | { | |
6c95b8df PA |
6942 | if (b->pspace != current_program_space) |
6943 | continue; | |
6944 | ||
8bea4e01 UW |
6945 | if ((b->type == bp_breakpoint |
6946 | || b->type == bp_hardware_breakpoint) | |
6947 | && b->enable_state == bp_startup_disabled) | |
6948 | { | |
6949 | b->enable_state = bp_enabled; | |
6950 | found = 1; | |
6951 | } | |
6952 | } | |
6953 | ||
6954 | if (found) | |
6955 | breakpoint_re_set (); | |
6956 | } | |
6957 | ||
c906108c SS |
6958 | |
6959 | /* Set a breakpoint that will evaporate an end of command | |
6960 | at address specified by SAL. | |
6961 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6962 | ||
6963 | struct breakpoint * | |
a6d9a66e UW |
6964 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6965 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6966 | { |
52f0bd74 | 6967 | struct breakpoint *b; |
edb3359d DJ |
6968 | |
6969 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6970 | one. */ | |
6971 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6972 | ||
06edf0c0 | 6973 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
6974 | b->enable_state = bp_enabled; |
6975 | b->disposition = disp_donttouch; | |
818dd999 | 6976 | b->frame_id = frame_id; |
c906108c | 6977 | |
4a64f543 MS |
6978 | /* If we're debugging a multi-threaded program, then we want |
6979 | momentary breakpoints to be active in only a single thread of | |
6980 | control. */ | |
39f77062 KB |
6981 | if (in_thread_list (inferior_ptid)) |
6982 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6983 | |
b60e7edf | 6984 | update_global_location_list_nothrow (1); |
74960c60 | 6985 | |
c906108c SS |
6986 | return b; |
6987 | } | |
611c83ae | 6988 | |
06edf0c0 PA |
6989 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
6990 | The new breakpoint will have type TYPE, and use OPS as it | |
6991 | breakpoint_ops. */ | |
e58b0e63 | 6992 | |
06edf0c0 PA |
6993 | static struct breakpoint * |
6994 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
6995 | enum bptype type, | |
c0a91b2b | 6996 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
6997 | { |
6998 | struct breakpoint *copy; | |
6999 | ||
06edf0c0 | 7000 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 7001 | copy->loc = allocate_bp_location (copy); |
0e30163f | 7002 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 7003 | |
a6d9a66e | 7004 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
7005 | copy->loc->requested_address = orig->loc->requested_address; |
7006 | copy->loc->address = orig->loc->address; | |
7007 | copy->loc->section = orig->loc->section; | |
6c95b8df | 7008 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
7009 | |
7010 | if (orig->source_file == NULL) | |
7011 | copy->source_file = NULL; | |
7012 | else | |
7013 | copy->source_file = xstrdup (orig->source_file); | |
7014 | ||
7015 | copy->line_number = orig->line_number; | |
7016 | copy->frame_id = orig->frame_id; | |
7017 | copy->thread = orig->thread; | |
6c95b8df | 7018 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7019 | |
7020 | copy->enable_state = bp_enabled; | |
7021 | copy->disposition = disp_donttouch; | |
7022 | copy->number = internal_breakpoint_number--; | |
7023 | ||
7024 | update_global_location_list_nothrow (0); | |
7025 | return copy; | |
7026 | } | |
7027 | ||
06edf0c0 PA |
7028 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7029 | ORIG is NULL. */ | |
7030 | ||
7031 | struct breakpoint * | |
7032 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7033 | { | |
7034 | /* If there's nothing to clone, then return nothing. */ | |
7035 | if (orig == NULL) | |
7036 | return NULL; | |
7037 | ||
7038 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
7039 | } | |
7040 | ||
611c83ae | 7041 | struct breakpoint * |
a6d9a66e UW |
7042 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7043 | enum bptype type) | |
611c83ae PA |
7044 | { |
7045 | struct symtab_and_line sal; | |
7046 | ||
7047 | sal = find_pc_line (pc, 0); | |
7048 | sal.pc = pc; | |
7049 | sal.section = find_pc_overlay (pc); | |
7050 | sal.explicit_pc = 1; | |
7051 | ||
a6d9a66e | 7052 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7053 | } |
c906108c | 7054 | \f |
c5aa993b | 7055 | |
c906108c SS |
7056 | /* Tell the user we have just set a breakpoint B. */ |
7057 | ||
7058 | static void | |
fba45db2 | 7059 | mention (struct breakpoint *b) |
c906108c | 7060 | { |
348d480f | 7061 | b->ops->print_mention (b); |
79a45e25 | 7062 | if (ui_out_is_mi_like_p (current_uiout)) |
fb40c209 | 7063 | return; |
c906108c SS |
7064 | printf_filtered ("\n"); |
7065 | } | |
c906108c | 7066 | \f |
c5aa993b | 7067 | |
0d381245 | 7068 | static struct bp_location * |
39d61571 | 7069 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7070 | const struct symtab_and_line *sal) |
7071 | { | |
7072 | struct bp_location *loc, **tmp; | |
7073 | ||
39d61571 | 7074 | loc = allocate_bp_location (b); |
0d381245 VP |
7075 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7076 | ; | |
7077 | *tmp = loc; | |
a6d9a66e UW |
7078 | loc->gdbarch = get_sal_arch (*sal); |
7079 | if (!loc->gdbarch) | |
7080 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7081 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7082 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7083 | loc->requested_address, b->type); | |
6c95b8df PA |
7084 | loc->pspace = sal->pspace; |
7085 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7086 | loc->section = sal->section; |
7087 | ||
0e30163f JK |
7088 | set_breakpoint_location_function (loc, |
7089 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7090 | return loc; |
7091 | } | |
514f746b AR |
7092 | \f |
7093 | ||
7094 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7095 | return 0 otherwise. */ | |
7096 | ||
7097 | static int | |
7098 | bp_loc_is_permanent (struct bp_location *loc) | |
7099 | { | |
7100 | int len; | |
7101 | CORE_ADDR addr; | |
7102 | const gdb_byte *brk; | |
7103 | gdb_byte *target_mem; | |
939c61fa JK |
7104 | struct cleanup *cleanup; |
7105 | int retval = 0; | |
514f746b AR |
7106 | |
7107 | gdb_assert (loc != NULL); | |
7108 | ||
7109 | addr = loc->address; | |
a6d9a66e | 7110 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7111 | |
939c61fa JK |
7112 | /* Software breakpoints unsupported? */ |
7113 | if (brk == NULL) | |
7114 | return 0; | |
7115 | ||
514f746b AR |
7116 | target_mem = alloca (len); |
7117 | ||
939c61fa JK |
7118 | /* Enable the automatic memory restoration from breakpoints while |
7119 | we read the memory. Otherwise we could say about our temporary | |
7120 | breakpoints they are permanent. */ | |
6c95b8df PA |
7121 | cleanup = save_current_space_and_thread (); |
7122 | ||
7123 | switch_to_program_space_and_thread (loc->pspace); | |
7124 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7125 | |
514f746b AR |
7126 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7127 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7128 | retval = 1; |
514f746b | 7129 | |
939c61fa JK |
7130 | do_cleanups (cleanup); |
7131 | ||
7132 | return retval; | |
514f746b AR |
7133 | } |
7134 | ||
7135 | ||
c3f6f71d | 7136 | |
018d34a4 VP |
7137 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7138 | as textual description of the location, and COND_STRING | |
db107f19 | 7139 | as condition expression. */ |
018d34a4 VP |
7140 | |
7141 | static void | |
d9b3f62e PA |
7142 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
7143 | struct symtabs_and_lines sals, char *addr_string, | |
7144 | char *cond_string, | |
7145 | enum bptype type, enum bpdisp disposition, | |
7146 | int thread, int task, int ignore_count, | |
c0a91b2b | 7147 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e | 7148 | int enabled, int internal, int display_canonical) |
018d34a4 | 7149 | { |
0d381245 | 7150 | int i; |
018d34a4 VP |
7151 | |
7152 | if (type == bp_hardware_breakpoint) | |
7153 | { | |
7154 | int i = hw_breakpoint_used_count (); | |
7155 | int target_resources_ok = | |
d92524f1 | 7156 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7157 | i + 1, 0); |
7158 | if (target_resources_ok == 0) | |
7159 | error (_("No hardware breakpoint support in the target.")); | |
7160 | else if (target_resources_ok < 0) | |
7161 | error (_("Hardware breakpoints used exceeds limit.")); | |
7162 | } | |
7163 | ||
6c95b8df PA |
7164 | gdb_assert (sals.nelts > 0); |
7165 | ||
0d381245 VP |
7166 | for (i = 0; i < sals.nelts; ++i) |
7167 | { | |
7168 | struct symtab_and_line sal = sals.sals[i]; | |
7169 | struct bp_location *loc; | |
7170 | ||
7171 | if (from_tty) | |
5af949e3 UW |
7172 | { |
7173 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7174 | if (!loc_gdbarch) | |
7175 | loc_gdbarch = gdbarch; | |
7176 | ||
7177 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7178 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7179 | } |
0d381245 VP |
7180 | |
7181 | if (i == 0) | |
7182 | { | |
d9b3f62e | 7183 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 7184 | b->thread = thread; |
4a306c9a | 7185 | b->task = task; |
018d34a4 | 7186 | |
0d381245 VP |
7187 | b->cond_string = cond_string; |
7188 | b->ignore_count = ignore_count; | |
41447f92 | 7189 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7190 | b->disposition = disposition; |
6c95b8df PA |
7191 | b->pspace = sals.sals[0].pspace; |
7192 | ||
0fb4aa4b PA |
7193 | if (type == bp_static_tracepoint) |
7194 | { | |
d9b3f62e | 7195 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
7196 | struct static_tracepoint_marker marker; |
7197 | ||
7198 | if (is_marker_spec (addr_string)) | |
7199 | { | |
7200 | /* We already know the marker exists, otherwise, we | |
7201 | wouldn't see a sal for it. */ | |
7202 | char *p = &addr_string[3]; | |
7203 | char *endp; | |
7204 | char *marker_str; | |
7205 | int i; | |
7206 | ||
e9cafbcc | 7207 | p = skip_spaces (p); |
0fb4aa4b | 7208 | |
e9cafbcc | 7209 | endp = skip_to_space (p); |
0fb4aa4b PA |
7210 | |
7211 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 7212 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 7213 | |
3e43a32a MS |
7214 | printf_filtered (_("Probed static tracepoint " |
7215 | "marker \"%s\"\n"), | |
d9b3f62e | 7216 | t->static_trace_marker_id); |
0fb4aa4b PA |
7217 | } |
7218 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7219 | { | |
d9b3f62e | 7220 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
7221 | release_static_tracepoint_marker (&marker); |
7222 | ||
3e43a32a MS |
7223 | printf_filtered (_("Probed static tracepoint " |
7224 | "marker \"%s\"\n"), | |
d9b3f62e | 7225 | t->static_trace_marker_id); |
0fb4aa4b PA |
7226 | } |
7227 | else | |
3e43a32a MS |
7228 | warning (_("Couldn't determine the static " |
7229 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7230 | } |
7231 | ||
6c95b8df | 7232 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7233 | && (b->type == bp_breakpoint |
7234 | || b->type == bp_hardware_breakpoint)) | |
7235 | b->enable_state = bp_startup_disabled; | |
7236 | ||
0d381245 VP |
7237 | loc = b->loc; |
7238 | } | |
7239 | else | |
018d34a4 | 7240 | { |
39d61571 | 7241 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7242 | } |
7243 | ||
514f746b AR |
7244 | if (bp_loc_is_permanent (loc)) |
7245 | make_breakpoint_permanent (b); | |
7246 | ||
0d381245 VP |
7247 | if (b->cond_string) |
7248 | { | |
7249 | char *arg = b->cond_string; | |
d32a6982 | 7250 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7251 | if (*arg) |
db107f19 | 7252 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7253 | } |
0d381245 | 7254 | } |
018d34a4 | 7255 | |
56435ebe | 7256 | b->display_canonical = display_canonical; |
018d34a4 VP |
7257 | if (addr_string) |
7258 | b->addr_string = addr_string; | |
7259 | else | |
7260 | /* addr_string has to be used or breakpoint_re_set will delete | |
7261 | me. */ | |
5af949e3 UW |
7262 | b->addr_string |
7263 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
d9b3f62e | 7264 | } |
018d34a4 | 7265 | |
d9b3f62e PA |
7266 | static void |
7267 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
7268 | struct symtabs_and_lines sals, char *addr_string, | |
7269 | char *cond_string, | |
7270 | enum bptype type, enum bpdisp disposition, | |
7271 | int thread, int task, int ignore_count, | |
c0a91b2b | 7272 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e PA |
7273 | int enabled, int internal, int display_canonical) |
7274 | { | |
7275 | struct breakpoint *b; | |
7276 | struct cleanup *old_chain; | |
7277 | ||
7278 | if (is_tracepoint_type (type)) | |
7279 | { | |
7280 | struct tracepoint *t; | |
7281 | ||
7282 | t = XCNEW (struct tracepoint); | |
7283 | b = &t->base; | |
7284 | } | |
7285 | else | |
7286 | b = XNEW (struct breakpoint); | |
7287 | ||
7288 | old_chain = make_cleanup (xfree, b); | |
7289 | ||
7290 | init_breakpoint_sal (b, gdbarch, | |
7291 | sals, addr_string, | |
7292 | cond_string, | |
7293 | type, disposition, | |
7294 | thread, task, ignore_count, | |
7295 | ops, from_tty, | |
7296 | enabled, internal, display_canonical); | |
7297 | discard_cleanups (old_chain); | |
7298 | ||
7299 | install_breakpoint (internal, b); | |
018d34a4 VP |
7300 | } |
7301 | ||
ed0616c6 VP |
7302 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7303 | elements to fill the void space. */ | |
2c0b251b PA |
7304 | static void |
7305 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7306 | { |
7307 | int i = index_to_remove+1; | |
7308 | int last_index = sal->nelts-1; | |
7309 | ||
7310 | for (;i <= last_index; ++i) | |
7311 | sal->sals[i-1] = sal->sals[i]; | |
7312 | ||
7313 | --(sal->nelts); | |
7314 | } | |
7315 | ||
6c95b8df PA |
7316 | /* If appropriate, obtains all sals that correspond to the same file |
7317 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7318 | will want to set a breakpoint at foo.c:line, and not really care | |
7319 | about program spaces. This is done only if SAL does not have | |
7320 | explicit PC and has line and file information. If we got just a | |
7321 | single expanded sal, return the original. | |
ed0616c6 | 7322 | |
6c95b8df PA |
7323 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7324 | which the name of enclosing function is different from SAL. This | |
7325 | makes sure that if we have breakpoint originally set in template | |
7326 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7327 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7328 | |
2c0b251b | 7329 | static struct symtabs_and_lines |
ed0616c6 VP |
7330 | expand_line_sal_maybe (struct symtab_and_line sal) |
7331 | { | |
7332 | struct symtabs_and_lines expanded; | |
7333 | CORE_ADDR original_pc = sal.pc; | |
7334 | char *original_function = NULL; | |
7335 | int found; | |
7336 | int i; | |
6c95b8df | 7337 | struct cleanup *old_chain; |
ed0616c6 VP |
7338 | |
7339 | /* If we have explicit pc, don't expand. | |
7340 | If we have no line number, we can't expand. */ | |
7341 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7342 | { | |
7343 | expanded.nelts = 1; | |
7344 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7345 | expanded.sals[0] = sal; | |
7346 | return expanded; | |
7347 | } | |
7348 | ||
7349 | sal.pc = 0; | |
6c95b8df PA |
7350 | |
7351 | old_chain = save_current_space_and_thread (); | |
7352 | ||
7353 | switch_to_program_space_and_thread (sal.pspace); | |
7354 | ||
ed0616c6 | 7355 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7356 | |
7357 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7358 | expanded = expand_line_sal (sal); |
6c95b8df | 7359 | |
ed0616c6 VP |
7360 | if (expanded.nelts == 1) |
7361 | { | |
3dba1c98 JB |
7362 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7363 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7364 | xfree (expanded.sals); |
7365 | expanded.nelts = 1; | |
7366 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7367 | sal.pc = original_pc; | |
7368 | expanded.sals[0] = sal; | |
3dba1c98 | 7369 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7370 | do_cleanups (old_chain); |
ed0616c6 VP |
7371 | return expanded; |
7372 | } | |
7373 | ||
7374 | if (!sal.explicit_line) | |
7375 | { | |
7376 | CORE_ADDR func_addr, func_end; | |
7377 | for (i = 0; i < expanded.nelts; ++i) | |
7378 | { | |
7379 | CORE_ADDR pc = expanded.sals[i].pc; | |
7380 | char *this_function; | |
6c95b8df PA |
7381 | |
7382 | /* We need to switch threads as well since we're about to | |
7383 | read memory. */ | |
7384 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7385 | ||
ed0616c6 VP |
7386 | if (find_pc_partial_function (pc, &this_function, |
7387 | &func_addr, &func_end)) | |
7388 | { | |
059fb39f PM |
7389 | if (this_function |
7390 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7391 | { |
7392 | remove_sal (&expanded, i); | |
7393 | --i; | |
7394 | } | |
ed0616c6 VP |
7395 | } |
7396 | } | |
7397 | } | |
059acae7 UW |
7398 | |
7399 | /* Skip the function prologue if necessary. */ | |
7400 | for (i = 0; i < expanded.nelts; ++i) | |
7401 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7402 | |
6c95b8df PA |
7403 | do_cleanups (old_chain); |
7404 | ||
ed0616c6 VP |
7405 | if (expanded.nelts <= 1) |
7406 | { | |
e5dd4106 | 7407 | /* This is an ugly workaround. If we get zero expanded sals |
4a64f543 MS |
7408 | then something is really wrong. Fix that by returning the |
7409 | original sal. */ | |
7410 | ||
ed0616c6 VP |
7411 | xfree (expanded.sals); |
7412 | expanded.nelts = 1; | |
7413 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7414 | sal.pc = original_pc; | |
7415 | expanded.sals[0] = sal; | |
7416 | return expanded; | |
7417 | } | |
7418 | ||
7419 | if (original_pc) | |
7420 | { | |
7421 | found = 0; | |
7422 | for (i = 0; i < expanded.nelts; ++i) | |
7423 | if (expanded.sals[i].pc == original_pc) | |
7424 | { | |
7425 | found = 1; | |
7426 | break; | |
7427 | } | |
7428 | gdb_assert (found); | |
7429 | } | |
7430 | ||
7431 | return expanded; | |
7432 | } | |
7433 | ||
018d34a4 VP |
7434 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7435 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7436 | value. COND_STRING, if not NULL, specified the condition to be | |
7437 | used for all breakpoints. Essentially the only case where | |
7438 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7439 | function. In that case, it's still not possible to specify | |
7440 | separate conditions for different overloaded functions, so | |
7441 | we take just a single condition string. | |
7442 | ||
c3f6f71d | 7443 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7444 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7445 | array contents). If the function fails (error() is called), the |
7446 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7447 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7448 | |
7449 | static void | |
8cdf0e15 | 7450 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7451 | struct symtabs_and_lines sals, |
7452 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7453 | char *cond_string, |
7454 | enum bptype type, enum bpdisp disposition, | |
7455 | int thread, int task, int ignore_count, | |
c0a91b2b | 7456 | const struct breakpoint_ops *ops, int from_tty, |
84f4c1fe | 7457 | int enabled, int internal) |
c906108c | 7458 | { |
018d34a4 | 7459 | int i; |
cc59ec59 | 7460 | |
018d34a4 | 7461 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7462 | { |
ed0616c6 VP |
7463 | struct symtabs_and_lines expanded = |
7464 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7465 | |
7efd8fc2 | 7466 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7467 | cond_string, type, disposition, |
84f4c1fe | 7468 | thread, task, ignore_count, ops, |
56435ebe TT |
7469 | from_tty, enabled, internal, |
7470 | canonical->special_display); | |
c3f6f71d | 7471 | } |
c3f6f71d | 7472 | } |
c906108c | 7473 | |
9998af43 | 7474 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7475 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7476 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7477 | address strings. ADDRESS points to the end of the SAL. |
7478 | ||
7479 | The array and the line spec strings are allocated on the heap, it is | |
7480 | the caller's responsibility to free them. */ | |
c906108c | 7481 | |
b9362cc7 | 7482 | static void |
c3f6f71d JM |
7483 | parse_breakpoint_sals (char **address, |
7484 | struct symtabs_and_lines *sals, | |
58438ac1 | 7485 | struct linespec_result *canonical) |
c3f6f71d JM |
7486 | { |
7487 | char *addr_start = *address; | |
cc59ec59 | 7488 | |
c3f6f71d | 7489 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7490 | breakpoint. */ |
c3f6f71d JM |
7491 | if ((*address) == NULL |
7492 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7493 | { |
7494 | if (default_breakpoint_valid) | |
7495 | { | |
c3f6f71d | 7496 | struct symtab_and_line sal; |
cc59ec59 | 7497 | |
4a64f543 | 7498 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7499 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7500 | xmalloc (sizeof (struct symtab_and_line)); |
7501 | sal.pc = default_breakpoint_address; | |
7502 | sal.line = default_breakpoint_line; | |
7503 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7504 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7505 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7506 | |
4a64f543 MS |
7507 | /* "break" without arguments is equivalent to "break *PC" |
7508 | where PC is the default_breakpoint_address. So make sure | |
7509 | to set sal.explicit_pc to prevent GDB from trying to | |
7510 | expand the list of sals to include all other instances | |
7511 | with the same symtab and line. */ | |
00903456 JK |
7512 | sal.explicit_pc = 1; |
7513 | ||
c3f6f71d JM |
7514 | sals->sals[0] = sal; |
7515 | sals->nelts = 1; | |
c906108c SS |
7516 | } |
7517 | else | |
8a3fe4f8 | 7518 | error (_("No default breakpoint address now.")); |
c906108c SS |
7519 | } |
7520 | else | |
7521 | { | |
c906108c | 7522 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7523 | current_source_symtab (which is decode_line_1's default). |
7524 | This should produce the results we want almost all of the | |
7525 | time while leaving default_breakpoint_* alone. | |
7526 | ||
1aeae86e AF |
7527 | ObjC: However, don't match an Objective-C method name which |
7528 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7529 | |
c214a6fd | 7530 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7531 | |
c906108c | 7532 | if (default_breakpoint_valid |
0378c332 | 7533 | && (!cursal.symtab |
1aeae86e AF |
7534 | || ((strchr ("+-", (*address)[0]) != NULL) |
7535 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7536 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
58438ac1 | 7537 | default_breakpoint_line, canonical); |
c906108c | 7538 | else |
0101ce28 | 7539 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
58438ac1 | 7540 | canonical); |
c906108c | 7541 | } |
4a64f543 | 7542 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 | 7543 | if (sals->nelts > 0 && canonical->canonical == NULL) |
38a714bb | 7544 | canonical->canonical = xcalloc (sals->nelts, sizeof (char *)); |
c3f6f71d | 7545 | if (addr_start != (*address)) |
c906108c | 7546 | { |
c3f6f71d | 7547 | int i; |
cc59ec59 | 7548 | |
c3f6f71d | 7549 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7550 | { |
4a64f543 | 7551 | /* Add the string if not present. */ |
7efd8fc2 TT |
7552 | if (canonical->canonical[i] == NULL) |
7553 | canonical->canonical[i] = savestring (addr_start, | |
7554 | (*address) - addr_start); | |
c906108c SS |
7555 | } |
7556 | } | |
c3f6f71d | 7557 | } |
c906108c | 7558 | |
c906108c | 7559 | |
c3f6f71d | 7560 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7561 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7562 | |
b9362cc7 | 7563 | static void |
23e7acfb | 7564 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7565 | { |
7566 | int i; | |
cc59ec59 | 7567 | |
c3f6f71d | 7568 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7569 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7570 | } |
7571 | ||
7a697b8d SS |
7572 | /* Fast tracepoints may have restrictions on valid locations. For |
7573 | instance, a fast tracepoint using a jump instead of a trap will | |
7574 | likely have to overwrite more bytes than a trap would, and so can | |
7575 | only be placed where the instruction is longer than the jump, or a | |
7576 | multi-instruction sequence does not have a jump into the middle of | |
7577 | it, etc. */ | |
7578 | ||
7579 | static void | |
7580 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7581 | struct symtabs_and_lines *sals) | |
7582 | { | |
7583 | int i, rslt; | |
7584 | struct symtab_and_line *sal; | |
7585 | char *msg; | |
7586 | struct cleanup *old_chain; | |
7587 | ||
7588 | for (i = 0; i < sals->nelts; i++) | |
7589 | { | |
7590 | sal = &sals->sals[i]; | |
7591 | ||
7592 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7593 | NULL, &msg); | |
7594 | old_chain = make_cleanup (xfree, msg); | |
7595 | ||
7596 | if (!rslt) | |
7597 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7598 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7599 | ||
7600 | do_cleanups (old_chain); | |
7601 | } | |
7602 | } | |
7603 | ||
018d34a4 VP |
7604 | /* Given TOK, a string specification of condition and thread, as |
7605 | accepted by the 'break' command, extract the condition | |
7606 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7607 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7608 | If no condition is found, *COND_STRING is set to NULL. |
7609 | If no thread is found, *THREAD is set to -1. */ | |
7610 | static void | |
7611 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7612 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7613 | { |
7614 | *cond_string = NULL; | |
7615 | *thread = -1; | |
7616 | while (tok && *tok) | |
7617 | { | |
7618 | char *end_tok; | |
7619 | int toklen; | |
7620 | char *cond_start = NULL; | |
7621 | char *cond_end = NULL; | |
cc59ec59 | 7622 | |
e9cafbcc | 7623 | tok = skip_spaces (tok); |
018d34a4 | 7624 | |
e9cafbcc | 7625 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7626 | |
7627 | toklen = end_tok - tok; | |
7628 | ||
7629 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7630 | { | |
f7545552 TT |
7631 | struct expression *expr; |
7632 | ||
018d34a4 | 7633 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7634 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7635 | xfree (expr); | |
018d34a4 VP |
7636 | cond_end = tok; |
7637 | *cond_string = savestring (cond_start, | |
7638 | cond_end - cond_start); | |
7639 | } | |
7640 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7641 | { | |
7642 | char *tmptok; | |
7643 | ||
7644 | tok = end_tok + 1; | |
7645 | tmptok = tok; | |
7646 | *thread = strtol (tok, &tok, 0); | |
7647 | if (tok == tmptok) | |
7648 | error (_("Junk after thread keyword.")); | |
7649 | if (!valid_thread_id (*thread)) | |
7650 | error (_("Unknown thread %d."), *thread); | |
7651 | } | |
4a306c9a JB |
7652 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7653 | { | |
7654 | char *tmptok; | |
7655 | ||
7656 | tok = end_tok + 1; | |
7657 | tmptok = tok; | |
7658 | *task = strtol (tok, &tok, 0); | |
7659 | if (tok == tmptok) | |
7660 | error (_("Junk after task keyword.")); | |
7661 | if (!valid_task_id (*task)) | |
b6199126 | 7662 | error (_("Unknown task %d."), *task); |
4a306c9a | 7663 | } |
018d34a4 VP |
7664 | else |
7665 | error (_("Junk at end of arguments.")); | |
7666 | } | |
7667 | } | |
7668 | ||
0fb4aa4b PA |
7669 | /* Decode a static tracepoint marker spec. */ |
7670 | ||
7671 | static struct symtabs_and_lines | |
7672 | decode_static_tracepoint_spec (char **arg_p) | |
7673 | { | |
7674 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7675 | struct symtabs_and_lines sals; | |
7676 | struct symtab_and_line sal; | |
7677 | struct symbol *sym; | |
7678 | struct cleanup *old_chain; | |
7679 | char *p = &(*arg_p)[3]; | |
7680 | char *endp; | |
7681 | char *marker_str; | |
7682 | int i; | |
7683 | ||
e9cafbcc | 7684 | p = skip_spaces (p); |
0fb4aa4b | 7685 | |
e9cafbcc | 7686 | endp = skip_to_space (p); |
0fb4aa4b PA |
7687 | |
7688 | marker_str = savestring (p, endp - p); | |
7689 | old_chain = make_cleanup (xfree, marker_str); | |
7690 | ||
7691 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7692 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7693 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7694 | ||
7695 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7696 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7697 | ||
7698 | for (i = 0; i < sals.nelts; i++) | |
7699 | { | |
7700 | struct static_tracepoint_marker *marker; | |
7701 | ||
7702 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7703 | ||
7704 | init_sal (&sals.sals[i]); | |
7705 | ||
7706 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7707 | sals.sals[i].pc = marker->address; | |
7708 | ||
7709 | release_static_tracepoint_marker (marker); | |
7710 | } | |
7711 | ||
7712 | do_cleanups (old_chain); | |
7713 | ||
7714 | *arg_p = endp; | |
7715 | return sals; | |
7716 | } | |
7717 | ||
fd9b8c24 PA |
7718 | /* Set a breakpoint. This function is shared between CLI and MI |
7719 | functions for setting a breakpoint. This function has two major | |
7720 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7721 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7722 | breakpoint location, address and thread. Otherwise, ARG is just |
7723 | the location of breakpoint, with condition and thread specified by | |
7724 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7725 | the breakpoint number will be allocated from the internal | |
7726 | breakpoint count. Returns true if any breakpoint was created; | |
7727 | false otherwise. */ | |
0101ce28 | 7728 | |
8cdf0e15 VP |
7729 | int |
7730 | create_breakpoint (struct gdbarch *gdbarch, | |
7731 | char *arg, char *cond_string, int thread, | |
7732 | int parse_condition_and_thread, | |
0fb4aa4b | 7733 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7734 | int ignore_count, |
7735 | enum auto_boolean pending_break_support, | |
c0a91b2b | 7736 | const struct breakpoint_ops *ops, |
84f4c1fe | 7737 | int from_tty, int enabled, int internal) |
c3f6f71d | 7738 | { |
b78a6381 | 7739 | volatile struct gdb_exception e; |
c3f6f71d | 7740 | struct symtabs_and_lines sals; |
0101ce28 | 7741 | struct symtab_and_line pending_sal; |
0101ce28 | 7742 | char *copy_arg; |
c3f6f71d | 7743 | char *addr_start = arg; |
7efd8fc2 | 7744 | struct linespec_result canonical; |
c3f6f71d | 7745 | struct cleanup *old_chain; |
80c99de1 | 7746 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 7747 | int i; |
0101ce28 | 7748 | int pending = 0; |
4a306c9a | 7749 | int task = 0; |
86b17b60 | 7750 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7751 | |
348d480f PA |
7752 | gdb_assert (ops != NULL); |
7753 | ||
c3f6f71d JM |
7754 | sals.sals = NULL; |
7755 | sals.nelts = 0; | |
7efd8fc2 | 7756 | init_linespec_result (&canonical); |
c3f6f71d | 7757 | |
0fb4aa4b PA |
7758 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7759 | { | |
7760 | int i; | |
7761 | ||
7762 | sals = decode_static_tracepoint_spec (&arg); | |
7763 | ||
7764 | copy_arg = savestring (addr_start, arg - addr_start); | |
38a714bb | 7765 | canonical.canonical = xcalloc (sals.nelts, sizeof (char *)); |
0fb4aa4b | 7766 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7767 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7768 | goto done; |
7769 | } | |
7770 | ||
b78a6381 TT |
7771 | TRY_CATCH (e, RETURN_MASK_ALL) |
7772 | { | |
58438ac1 | 7773 | parse_breakpoint_sals (&arg, &sals, &canonical); |
b78a6381 | 7774 | } |
0101ce28 JJ |
7775 | |
7776 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7777 | switch (e.reason) |
0101ce28 | 7778 | { |
05ff989b | 7779 | case RETURN_QUIT: |
98deb0da | 7780 | throw_exception (e); |
05ff989b AC |
7781 | case RETURN_ERROR: |
7782 | switch (e.error) | |
0101ce28 | 7783 | { |
05ff989b | 7784 | case NOT_FOUND_ERROR: |
0101ce28 | 7785 | |
05ff989b AC |
7786 | /* If pending breakpoint support is turned off, throw |
7787 | error. */ | |
fa8d40ab JJ |
7788 | |
7789 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7790 | throw_exception (e); |
7791 | ||
7792 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7793 | |
05ff989b AC |
7794 | /* If pending breakpoint support is auto query and the user |
7795 | selects no, then simply return the error code. */ | |
059fb39f | 7796 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7797 | && !nquery (_("Make breakpoint pending on " |
7798 | "future shared library load? "))) | |
fd9b8c24 | 7799 | return 0; |
fa8d40ab | 7800 | |
05ff989b AC |
7801 | /* At this point, either the user was queried about setting |
7802 | a pending breakpoint and selected yes, or pending | |
7803 | breakpoint behavior is on and thus a pending breakpoint | |
7804 | is defaulted on behalf of the user. */ | |
0101ce28 | 7805 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 7806 | canonical.canonical = ©_arg; |
0101ce28 JJ |
7807 | sals.nelts = 1; |
7808 | sals.sals = &pending_sal; | |
7809 | pending_sal.pc = 0; | |
7810 | pending = 1; | |
05ff989b AC |
7811 | break; |
7812 | default: | |
98deb0da | 7813 | throw_exception (e); |
0101ce28 | 7814 | } |
2abae994 | 7815 | break; |
05ff989b AC |
7816 | default: |
7817 | if (!sals.nelts) | |
fd9b8c24 | 7818 | return 0; |
0101ce28 | 7819 | } |
c3f6f71d | 7820 | |
0fb4aa4b PA |
7821 | done: |
7822 | ||
4a64f543 | 7823 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7824 | old_chain = make_cleanup (null_cleanup, 0); |
7825 | ||
0101ce28 JJ |
7826 | if (!pending) |
7827 | { | |
7828 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7829 | make_cleanup (xfree, sals.sals); | |
7830 | ||
7efd8fc2 TT |
7831 | /* Cleanup the canonical array but not its contents. */ |
7832 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 7833 | } |
c3f6f71d | 7834 | |
c3f6f71d JM |
7835 | /* ----------------------------- SNIP ----------------------------- |
7836 | Anything added to the cleanup chain beyond this point is assumed | |
7837 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7838 | then the memory is not reclaimed. */ |
7839 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 7840 | |
7efd8fc2 | 7841 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 7842 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7843 | for (i = 0; i < sals.nelts; i++) |
7844 | { | |
7efd8fc2 TT |
7845 | if (canonical.canonical[i] != NULL) |
7846 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
7847 | } |
7848 | ||
7849 | /* Resolve all line numbers to PC's and verify that the addresses | |
7850 | are ok for the target. */ | |
0101ce28 | 7851 | if (!pending) |
23e7acfb | 7852 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7853 | |
7a697b8d SS |
7854 | /* Fast tracepoints may have additional restrictions on location. */ |
7855 | if (type_wanted == bp_fast_tracepoint) | |
7856 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7857 | ||
c3f6f71d JM |
7858 | /* Verify that condition can be parsed, before setting any |
7859 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7860 | breakpoint. */ |
0101ce28 | 7861 | if (!pending) |
c3f6f71d | 7862 | { |
2f069f6f | 7863 | if (parse_condition_and_thread) |
72b2ff0e VP |
7864 | { |
7865 | /* Here we only parse 'arg' to separate condition | |
7866 | from thread number, so parsing in context of first | |
7867 | sal is OK. When setting the breakpoint we'll | |
7868 | re-parse it in context of each sal. */ | |
7869 | cond_string = NULL; | |
7870 | thread = -1; | |
4a306c9a JB |
7871 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7872 | &thread, &task); | |
72b2ff0e VP |
7873 | if (cond_string) |
7874 | make_cleanup (xfree, cond_string); | |
7875 | } | |
2f069f6f | 7876 | else |
72b2ff0e VP |
7877 | { |
7878 | /* Create a private copy of condition string. */ | |
7879 | if (cond_string) | |
7880 | { | |
7881 | cond_string = xstrdup (cond_string); | |
7882 | make_cleanup (xfree, cond_string); | |
7883 | } | |
7884 | } | |
0fb4aa4b PA |
7885 | |
7886 | /* If the user is creating a static tracepoint by marker id | |
7887 | (strace -m MARKER_ID), then store the sals index, so that | |
7888 | breakpoint_re_set can try to match up which of the newly | |
7889 | found markers corresponds to this one, and, don't try to | |
7890 | expand multiple locations for each sal, given than SALS | |
7891 | already should contain all sals for MARKER_ID. */ | |
7892 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 7893 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
7894 | { |
7895 | int i; | |
7896 | ||
7897 | for (i = 0; i < sals.nelts; ++i) | |
7898 | { | |
7899 | struct symtabs_and_lines expanded; | |
d9b3f62e | 7900 | struct tracepoint *tp; |
0fb4aa4b PA |
7901 | struct cleanup *old_chain; |
7902 | ||
7903 | expanded.nelts = 1; | |
7904 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7905 | expanded.sals[0] = sals.sals[i]; | |
7906 | old_chain = make_cleanup (xfree, expanded.sals); | |
7907 | ||
d9b3f62e PA |
7908 | tp = XCNEW (struct tracepoint); |
7909 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
7910 | canonical.canonical[i], | |
7911 | cond_string, type_wanted, | |
7912 | tempflag ? disp_del : disp_donttouch, | |
7913 | thread, task, ignore_count, ops, | |
7914 | from_tty, enabled, internal, | |
7915 | canonical.special_display); | |
0fb4aa4b PA |
7916 | /* Given that its possible to have multiple markers with |
7917 | the same string id, if the user is creating a static | |
7918 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7919 | store the sals index, so that breakpoint_re_set can | |
7920 | try to match up which of the newly found markers | |
7921 | corresponds to this one */ | |
7922 | tp->static_trace_marker_id_idx = i; | |
d9b3f62e PA |
7923 | |
7924 | install_breakpoint (internal, &tp->base); | |
7925 | ||
7926 | do_cleanups (old_chain); | |
0fb4aa4b PA |
7927 | } |
7928 | } | |
7929 | else | |
7efd8fc2 | 7930 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
7931 | type_wanted, |
7932 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7933 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7934 | enabled, internal); |
c906108c | 7935 | } |
0101ce28 JJ |
7936 | else |
7937 | { | |
0101ce28 JJ |
7938 | struct breakpoint *b; |
7939 | ||
0101ce28 JJ |
7940 | make_cleanup (xfree, copy_arg); |
7941 | ||
348d480f | 7942 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted, ops); |
84f4c1fe | 7943 | set_breakpoint_number (internal, b); |
72b2ff0e | 7944 | b->thread = -1; |
7efd8fc2 | 7945 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 7946 | b->cond_string = NULL; |
0101ce28 | 7947 | b->ignore_count = ignore_count; |
0101ce28 | 7948 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7949 | b->condition_not_parsed = 1; |
41447f92 | 7950 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7951 | b->pspace = current_program_space; |
84f4c1fe | 7952 | b->py_bp_object = NULL; |
74960c60 | 7953 | |
6c95b8df | 7954 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7955 | && (b->type == bp_breakpoint |
7956 | || b->type == bp_hardware_breakpoint)) | |
7957 | b->enable_state = bp_startup_disabled; | |
7958 | ||
8d3788bd | 7959 | if (!internal) |
84f4c1fe PM |
7960 | /* Do not mention breakpoints with a negative number, |
7961 | but do notify observers. */ | |
8d3788bd VP |
7962 | mention (b); |
7963 | observer_notify_breakpoint_created (b); | |
0101ce28 JJ |
7964 | } |
7965 | ||
c3f6f71d | 7966 | if (sals.nelts > 1) |
95a42b64 | 7967 | { |
3e43a32a MS |
7968 | warning (_("Multiple breakpoints were set.\nUse the " |
7969 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7970 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7971 | } |
7972 | ||
80c99de1 PA |
7973 | /* That's it. Discard the cleanups for data inserted into the |
7974 | breakpoint. */ | |
7975 | discard_cleanups (bkpt_chain); | |
7976 | /* But cleanup everything else. */ | |
c3f6f71d | 7977 | do_cleanups (old_chain); |
217dc9e2 | 7978 | |
80c99de1 | 7979 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7980 | update_global_location_list (1); |
fd9b8c24 PA |
7981 | |
7982 | return 1; | |
c3f6f71d | 7983 | } |
c906108c | 7984 | |
348d480f | 7985 | /* Set a breakpoint. |
72b2ff0e VP |
7986 | ARG is a string describing breakpoint address, |
7987 | condition, and thread. | |
7988 | FLAG specifies if a breakpoint is hardware on, | |
7989 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7990 | and BP_TEMPFLAG. */ | |
348d480f | 7991 | |
98deb0da | 7992 | static void |
72b2ff0e | 7993 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7994 | { |
72b2ff0e | 7995 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
7996 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
7997 | ? bp_hardware_breakpoint | |
7998 | : bp_breakpoint); | |
c3f6f71d | 7999 | |
8cdf0e15 VP |
8000 | create_breakpoint (get_current_arch (), |
8001 | arg, | |
8002 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8003 | tempflag, type_wanted, |
8cdf0e15 VP |
8004 | 0 /* Ignore count */, |
8005 | pending_break_support, | |
348d480f | 8006 | &bkpt_breakpoint_ops, |
8cdf0e15 | 8007 | from_tty, |
84f4c1fe PM |
8008 | 1 /* enabled */, |
8009 | 0 /* internal */); | |
c906108c SS |
8010 | } |
8011 | ||
c906108c SS |
8012 | /* Helper function for break_command_1 and disassemble_command. */ |
8013 | ||
8014 | void | |
fba45db2 | 8015 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8016 | { |
8017 | CORE_ADDR pc; | |
8018 | ||
8019 | if (sal->pc == 0 && sal->symtab != NULL) | |
8020 | { | |
8021 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8022 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8023 | sal->line, sal->symtab->filename); |
8024 | sal->pc = pc; | |
6a048695 | 8025 | |
4a64f543 MS |
8026 | /* If this SAL corresponds to a breakpoint inserted using a line |
8027 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8028 | if (sal->explicit_line) |
059acae7 | 8029 | skip_prologue_sal (sal); |
c906108c SS |
8030 | } |
8031 | ||
8032 | if (sal->section == 0 && sal->symtab != NULL) | |
8033 | { | |
8034 | struct blockvector *bv; | |
c5aa993b JM |
8035 | struct block *b; |
8036 | struct symbol *sym; | |
c906108c | 8037 | |
801e3a5b | 8038 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8039 | if (bv != NULL) |
8040 | { | |
7f0df278 | 8041 | sym = block_linkage_function (b); |
c906108c SS |
8042 | if (sym != NULL) |
8043 | { | |
8044 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8045 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8046 | } |
8047 | else | |
8048 | { | |
4a64f543 MS |
8049 | /* It really is worthwhile to have the section, so we'll |
8050 | just have to look harder. This case can be executed | |
8051 | if we have line numbers but no functions (as can | |
8052 | happen in assembly source). */ | |
c906108c | 8053 | |
c5aa993b | 8054 | struct minimal_symbol *msym; |
6c95b8df PA |
8055 | struct cleanup *old_chain = save_current_space_and_thread (); |
8056 | ||
8057 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8058 | |
8059 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8060 | if (msym) | |
714835d5 | 8061 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8062 | |
8063 | do_cleanups (old_chain); | |
c906108c SS |
8064 | } |
8065 | } | |
8066 | } | |
8067 | } | |
8068 | ||
8069 | void | |
fba45db2 | 8070 | break_command (char *arg, int from_tty) |
c906108c | 8071 | { |
db107f19 | 8072 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8073 | } |
8074 | ||
c906108c | 8075 | void |
fba45db2 | 8076 | tbreak_command (char *arg, int from_tty) |
c906108c | 8077 | { |
db107f19 | 8078 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8079 | } |
8080 | ||
c906108c | 8081 | static void |
fba45db2 | 8082 | hbreak_command (char *arg, int from_tty) |
c906108c | 8083 | { |
db107f19 | 8084 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8085 | } |
8086 | ||
8087 | static void | |
fba45db2 | 8088 | thbreak_command (char *arg, int from_tty) |
c906108c | 8089 | { |
db107f19 | 8090 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8091 | } |
8092 | ||
8093 | static void | |
fba45db2 | 8094 | stop_command (char *arg, int from_tty) |
c906108c | 8095 | { |
a3f17187 | 8096 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8097 | Usage: stop in <function | address>\n\ |
a3f17187 | 8098 | stop at <line>\n")); |
c906108c SS |
8099 | } |
8100 | ||
8101 | static void | |
fba45db2 | 8102 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8103 | { |
8104 | int badInput = 0; | |
8105 | ||
c5aa993b | 8106 | if (arg == (char *) NULL) |
c906108c SS |
8107 | badInput = 1; |
8108 | else if (*arg != '*') | |
8109 | { | |
8110 | char *argptr = arg; | |
8111 | int hasColon = 0; | |
8112 | ||
4a64f543 | 8113 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8114 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8115 | function/method name. */ |
c906108c | 8116 | while (*argptr && !hasColon) |
c5aa993b JM |
8117 | { |
8118 | hasColon = (*argptr == ':'); | |
8119 | argptr++; | |
8120 | } | |
c906108c SS |
8121 | |
8122 | if (hasColon) | |
c5aa993b | 8123 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8124 | else |
c5aa993b | 8125 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8126 | } |
8127 | ||
8128 | if (badInput) | |
a3f17187 | 8129 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8130 | else |
db107f19 | 8131 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8132 | } |
8133 | ||
8134 | static void | |
fba45db2 | 8135 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8136 | { |
8137 | int badInput = 0; | |
8138 | ||
c5aa993b | 8139 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8140 | badInput = 1; |
8141 | else | |
8142 | { | |
8143 | char *argptr = arg; | |
8144 | int hasColon = 0; | |
8145 | ||
4a64f543 MS |
8146 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8147 | it is probably a line number. */ | |
c906108c | 8148 | while (*argptr && !hasColon) |
c5aa993b JM |
8149 | { |
8150 | hasColon = (*argptr == ':'); | |
8151 | argptr++; | |
8152 | } | |
c906108c SS |
8153 | |
8154 | if (hasColon) | |
c5aa993b | 8155 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8156 | else |
c5aa993b | 8157 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8158 | } |
8159 | ||
8160 | if (badInput) | |
a3f17187 | 8161 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8162 | else |
db107f19 | 8163 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8164 | } |
8165 | ||
f1310107 TJB |
8166 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8167 | ranged breakpoints. */ | |
8168 | ||
8169 | static int | |
8170 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8171 | struct address_space *aspace, | |
8172 | CORE_ADDR bp_addr) | |
8173 | { | |
8174 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, | |
8175 | bl->length, aspace, bp_addr); | |
8176 | } | |
8177 | ||
8178 | /* Implement the "resources_needed" breakpoint_ops method for | |
8179 | ranged breakpoints. */ | |
8180 | ||
8181 | static int | |
8182 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8183 | { | |
8184 | return target_ranged_break_num_registers (); | |
8185 | } | |
8186 | ||
8187 | /* Implement the "print_it" breakpoint_ops method for | |
8188 | ranged breakpoints. */ | |
8189 | ||
8190 | static enum print_stop_action | |
348d480f | 8191 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 8192 | { |
348d480f | 8193 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 | 8194 | struct bp_location *bl = b->loc; |
79a45e25 | 8195 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8196 | |
8197 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8198 | ||
8199 | /* Ranged breakpoints have only one location. */ | |
8200 | gdb_assert (bl && bl->next == NULL); | |
8201 | ||
8202 | annotate_breakpoint (b->number); | |
8203 | if (b->disposition == disp_del) | |
8204 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8205 | else | |
8206 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8207 | if (ui_out_is_mi_like_p (uiout)) | |
8208 | { | |
8209 | ui_out_field_string (uiout, "reason", | |
8210 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8211 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8212 | } | |
8213 | ui_out_field_int (uiout, "bkptno", b->number); | |
8214 | ui_out_text (uiout, ", "); | |
8215 | ||
8216 | return PRINT_SRC_AND_LOC; | |
8217 | } | |
8218 | ||
8219 | /* Implement the "print_one" breakpoint_ops method for | |
8220 | ranged breakpoints. */ | |
8221 | ||
8222 | static void | |
8223 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8224 | struct bp_location **last_loc) | |
8225 | { | |
8226 | struct bp_location *bl = b->loc; | |
8227 | struct value_print_options opts; | |
79a45e25 | 8228 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8229 | |
8230 | /* Ranged breakpoints have only one location. */ | |
8231 | gdb_assert (bl && bl->next == NULL); | |
8232 | ||
8233 | get_user_print_options (&opts); | |
8234 | ||
8235 | if (opts.addressprint) | |
8236 | /* We don't print the address range here, it will be printed later | |
8237 | by print_one_detail_ranged_breakpoint. */ | |
8238 | ui_out_field_skip (uiout, "addr"); | |
8239 | annotate_field (5); | |
8240 | print_breakpoint_location (b, bl); | |
8241 | *last_loc = bl; | |
8242 | } | |
8243 | ||
8244 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8245 | ranged breakpoints. */ | |
8246 | ||
8247 | static void | |
8248 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8249 | struct ui_out *uiout) | |
8250 | { | |
8251 | CORE_ADDR address_start, address_end; | |
8252 | struct bp_location *bl = b->loc; | |
8253 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8254 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8255 | ||
8256 | gdb_assert (bl); | |
8257 | ||
8258 | address_start = bl->address; | |
8259 | address_end = address_start + bl->length - 1; | |
8260 | ||
8261 | ui_out_text (uiout, "\taddress range: "); | |
8262 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8263 | print_core_address (bl->gdbarch, address_start), | |
8264 | print_core_address (bl->gdbarch, address_end)); | |
8265 | ui_out_field_stream (uiout, "addr", stb); | |
8266 | ui_out_text (uiout, "\n"); | |
8267 | ||
8268 | do_cleanups (cleanup); | |
8269 | } | |
8270 | ||
8271 | /* Implement the "print_mention" breakpoint_ops method for | |
8272 | ranged breakpoints. */ | |
8273 | ||
8274 | static void | |
8275 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8276 | { | |
8277 | struct bp_location *bl = b->loc; | |
79a45e25 | 8278 | struct ui_out *uiout = current_uiout; |
f1310107 TJB |
8279 | |
8280 | gdb_assert (bl); | |
8281 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8282 | ||
8283 | if (ui_out_is_mi_like_p (uiout)) | |
8284 | return; | |
8285 | ||
8286 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8287 | b->number, paddress (bl->gdbarch, bl->address), | |
8288 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8289 | } | |
8290 | ||
8291 | /* Implement the "print_recreate" breakpoint_ops method for | |
8292 | ranged breakpoints. */ | |
8293 | ||
8294 | static void | |
8295 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8296 | { | |
8297 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8298 | b->addr_string_range_end); | |
d9b3f62e | 8299 | print_recreate_thread (b, fp); |
f1310107 TJB |
8300 | } |
8301 | ||
8302 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8303 | ||
2060206e | 8304 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
8305 | |
8306 | /* Find the address where the end of the breakpoint range should be | |
8307 | placed, given the SAL of the end of the range. This is so that if | |
8308 | the user provides a line number, the end of the range is set to the | |
8309 | last instruction of the given line. */ | |
8310 | ||
8311 | static CORE_ADDR | |
8312 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8313 | { | |
8314 | CORE_ADDR end; | |
8315 | ||
8316 | /* If the user provided a PC value, use it. Otherwise, | |
8317 | find the address of the end of the given location. */ | |
8318 | if (sal.explicit_pc) | |
8319 | end = sal.pc; | |
8320 | else | |
8321 | { | |
8322 | int ret; | |
8323 | CORE_ADDR start; | |
8324 | ||
8325 | ret = find_line_pc_range (sal, &start, &end); | |
8326 | if (!ret) | |
8327 | error (_("Could not find location of the end of the range.")); | |
8328 | ||
8329 | /* find_line_pc_range returns the start of the next line. */ | |
8330 | end--; | |
8331 | } | |
8332 | ||
8333 | return end; | |
8334 | } | |
8335 | ||
8336 | /* Implement the "break-range" CLI command. */ | |
8337 | ||
8338 | static void | |
8339 | break_range_command (char *arg, int from_tty) | |
8340 | { | |
8341 | char *arg_start, *addr_string_start, *addr_string_end; | |
8342 | struct linespec_result canonical_start, canonical_end; | |
8343 | int bp_count, can_use_bp, length; | |
8344 | CORE_ADDR end; | |
8345 | struct breakpoint *b; | |
8346 | struct symtab_and_line sal_start, sal_end; | |
8347 | struct symtabs_and_lines sals_start, sals_end; | |
8348 | struct cleanup *cleanup_bkpt; | |
8349 | ||
8350 | /* We don't support software ranged breakpoints. */ | |
8351 | if (target_ranged_break_num_registers () < 0) | |
8352 | error (_("This target does not support hardware ranged breakpoints.")); | |
8353 | ||
8354 | bp_count = hw_breakpoint_used_count (); | |
8355 | bp_count += target_ranged_break_num_registers (); | |
8356 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8357 | bp_count, 0); | |
8358 | if (can_use_bp < 0) | |
8359 | error (_("Hardware breakpoints used exceeds limit.")); | |
8360 | ||
8361 | if (arg == NULL || arg[0] == '\0') | |
8362 | error(_("No address range specified.")); | |
8363 | ||
8364 | sals_start.sals = NULL; | |
8365 | sals_start.nelts = 0; | |
8366 | init_linespec_result (&canonical_start); | |
8367 | ||
8368 | while (*arg == ' ' || *arg == '\t') | |
8369 | arg++; | |
8370 | ||
58438ac1 | 8371 | parse_breakpoint_sals (&arg, &sals_start, &canonical_start); |
f1310107 TJB |
8372 | |
8373 | sal_start = sals_start.sals[0]; | |
8374 | addr_string_start = canonical_start.canonical[0]; | |
8375 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); | |
8376 | xfree (sals_start.sals); | |
8377 | xfree (canonical_start.canonical); | |
8378 | ||
8379 | if (arg[0] != ',') | |
8380 | error (_("Too few arguments.")); | |
8381 | else if (sals_start.nelts == 0) | |
8382 | error (_("Could not find location of the beginning of the range.")); | |
8383 | else if (sals_start.nelts != 1) | |
8384 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8385 | ||
8386 | resolve_sal_pc (&sal_start); | |
8387 | ||
8388 | arg++; /* Skip the comma. */ | |
8389 | while (*arg == ' ' || *arg == '\t') | |
8390 | arg++; | |
8391 | ||
8392 | /* Parse the end location. */ | |
8393 | ||
8394 | sals_end.sals = NULL; | |
8395 | sals_end.nelts = 0; | |
8396 | init_linespec_result (&canonical_end); | |
8397 | arg_start = arg; | |
8398 | ||
423f41a5 | 8399 | /* We call decode_line_1 directly here instead of using |
f1310107 TJB |
8400 | parse_breakpoint_sals because we need to specify the start location's |
8401 | symtab and line as the default symtab and line for the end of the | |
8402 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8403 | where +14 means 14 lines from the start location. */ | |
8404 | sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line, | |
58438ac1 | 8405 | &canonical_end); |
f1310107 TJB |
8406 | |
8407 | /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */ | |
8408 | if (canonical_end.canonical == NULL) | |
38a714bb | 8409 | canonical_end.canonical = xcalloc (1, sizeof (char *)); |
f1310107 TJB |
8410 | /* Add the string if not present. */ |
8411 | if (arg_start != arg && canonical_end.canonical[0] == NULL) | |
8412 | canonical_end.canonical[0] = savestring (arg_start, arg - arg_start); | |
8413 | ||
8414 | sal_end = sals_end.sals[0]; | |
8415 | addr_string_end = canonical_end.canonical[0]; | |
8416 | make_cleanup (xfree, addr_string_end); | |
8417 | xfree (sals_end.sals); | |
8418 | xfree (canonical_end.canonical); | |
8419 | ||
8420 | if (sals_end.nelts == 0) | |
8421 | error (_("Could not find location of the end of the range.")); | |
8422 | else if (sals_end.nelts != 1) | |
8423 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8424 | ||
8425 | resolve_sal_pc (&sal_end); | |
8426 | ||
8427 | end = find_breakpoint_range_end (sal_end); | |
8428 | if (sal_start.pc > end) | |
177b42fe | 8429 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
8430 | |
8431 | length = end - sal_start.pc + 1; | |
8432 | if (length < 0) | |
8433 | /* Length overflowed. */ | |
8434 | error (_("Address range too large.")); | |
8435 | else if (length == 1) | |
8436 | { | |
8437 | /* This range is simple enough to be handled by | |
8438 | the `hbreak' command. */ | |
8439 | hbreak_command (addr_string_start, 1); | |
8440 | ||
8441 | do_cleanups (cleanup_bkpt); | |
8442 | ||
8443 | return; | |
8444 | } | |
8445 | ||
8446 | /* Now set up the breakpoint. */ | |
8447 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 8448 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
8449 | set_breakpoint_count (breakpoint_count + 1); |
8450 | b->number = breakpoint_count; | |
8451 | b->disposition = disp_donttouch; | |
8452 | b->addr_string = addr_string_start; | |
8453 | b->addr_string_range_end = addr_string_end; | |
f1310107 TJB |
8454 | b->loc->length = length; |
8455 | ||
8456 | discard_cleanups (cleanup_bkpt); | |
8457 | ||
8458 | mention (b); | |
8d3788bd | 8459 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8460 | update_global_location_list (1); |
8461 | } | |
8462 | ||
4a64f543 MS |
8463 | /* Return non-zero if EXP is verified as constant. Returned zero |
8464 | means EXP is variable. Also the constant detection may fail for | |
8465 | some constant expressions and in such case still falsely return | |
8466 | zero. */ | |
65d79d4b SDJ |
8467 | static int |
8468 | watchpoint_exp_is_const (const struct expression *exp) | |
8469 | { | |
8470 | int i = exp->nelts; | |
8471 | ||
8472 | while (i > 0) | |
8473 | { | |
8474 | int oplenp, argsp; | |
8475 | ||
8476 | /* We are only interested in the descriptor of each element. */ | |
8477 | operator_length (exp, i, &oplenp, &argsp); | |
8478 | i -= oplenp; | |
8479 | ||
8480 | switch (exp->elts[i].opcode) | |
8481 | { | |
8482 | case BINOP_ADD: | |
8483 | case BINOP_SUB: | |
8484 | case BINOP_MUL: | |
8485 | case BINOP_DIV: | |
8486 | case BINOP_REM: | |
8487 | case BINOP_MOD: | |
8488 | case BINOP_LSH: | |
8489 | case BINOP_RSH: | |
8490 | case BINOP_LOGICAL_AND: | |
8491 | case BINOP_LOGICAL_OR: | |
8492 | case BINOP_BITWISE_AND: | |
8493 | case BINOP_BITWISE_IOR: | |
8494 | case BINOP_BITWISE_XOR: | |
8495 | case BINOP_EQUAL: | |
8496 | case BINOP_NOTEQUAL: | |
8497 | case BINOP_LESS: | |
8498 | case BINOP_GTR: | |
8499 | case BINOP_LEQ: | |
8500 | case BINOP_GEQ: | |
8501 | case BINOP_REPEAT: | |
8502 | case BINOP_COMMA: | |
8503 | case BINOP_EXP: | |
8504 | case BINOP_MIN: | |
8505 | case BINOP_MAX: | |
8506 | case BINOP_INTDIV: | |
8507 | case BINOP_CONCAT: | |
8508 | case BINOP_IN: | |
8509 | case BINOP_RANGE: | |
8510 | case TERNOP_COND: | |
8511 | case TERNOP_SLICE: | |
8512 | case TERNOP_SLICE_COUNT: | |
8513 | ||
8514 | case OP_LONG: | |
8515 | case OP_DOUBLE: | |
8516 | case OP_DECFLOAT: | |
8517 | case OP_LAST: | |
8518 | case OP_COMPLEX: | |
8519 | case OP_STRING: | |
8520 | case OP_BITSTRING: | |
8521 | case OP_ARRAY: | |
8522 | case OP_TYPE: | |
8523 | case OP_NAME: | |
8524 | case OP_OBJC_NSSTRING: | |
8525 | ||
8526 | case UNOP_NEG: | |
8527 | case UNOP_LOGICAL_NOT: | |
8528 | case UNOP_COMPLEMENT: | |
8529 | case UNOP_ADDR: | |
8530 | case UNOP_HIGH: | |
4a64f543 MS |
8531 | /* Unary, binary and ternary operators: We have to check |
8532 | their operands. If they are constant, then so is the | |
8533 | result of that operation. For instance, if A and B are | |
8534 | determined to be constants, then so is "A + B". | |
8535 | ||
8536 | UNOP_IND is one exception to the rule above, because the | |
8537 | value of *ADDR is not necessarily a constant, even when | |
8538 | ADDR is. */ | |
65d79d4b SDJ |
8539 | break; |
8540 | ||
8541 | case OP_VAR_VALUE: | |
8542 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8543 | |
65d79d4b | 8544 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8545 | possible that a buggy compiler could mark a variable as |
8546 | constant even when it is not, and TYPE_CONST would return | |
8547 | true in this case, while SYMBOL_CLASS wouldn't. | |
8548 | ||
8549 | We also have to check for function symbols because they | |
8550 | are always constant. */ | |
65d79d4b SDJ |
8551 | { |
8552 | struct symbol *s = exp->elts[i + 2].symbol; | |
8553 | ||
8554 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8555 | && SYMBOL_CLASS (s) != LOC_CONST | |
8556 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8557 | return 0; | |
8558 | break; | |
8559 | } | |
8560 | ||
8561 | /* The default action is to return 0 because we are using | |
8562 | the optimistic approach here: If we don't know something, | |
8563 | then it is not a constant. */ | |
8564 | default: | |
8565 | return 0; | |
8566 | } | |
8567 | } | |
8568 | ||
8569 | return 1; | |
8570 | } | |
8571 | ||
3a5c3e22 PA |
8572 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
8573 | ||
8574 | static void | |
8575 | dtor_watchpoint (struct breakpoint *self) | |
8576 | { | |
8577 | struct watchpoint *w = (struct watchpoint *) self; | |
8578 | ||
8579 | xfree (w->cond_exp); | |
8580 | xfree (w->exp); | |
8581 | xfree (w->exp_string); | |
8582 | xfree (w->exp_string_reparse); | |
8583 | value_free (w->val); | |
8584 | ||
8585 | base_breakpoint_ops.dtor (self); | |
8586 | } | |
8587 | ||
348d480f PA |
8588 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
8589 | ||
8590 | static void | |
8591 | re_set_watchpoint (struct breakpoint *b) | |
8592 | { | |
3a5c3e22 PA |
8593 | struct watchpoint *w = (struct watchpoint *) b; |
8594 | ||
348d480f PA |
8595 | /* Watchpoint can be either on expression using entirely global |
8596 | variables, or it can be on local variables. | |
8597 | ||
8598 | Watchpoints of the first kind are never auto-deleted, and even | |
8599 | persist across program restarts. Since they can use variables | |
8600 | from shared libraries, we need to reparse expression as libraries | |
8601 | are loaded and unloaded. | |
8602 | ||
8603 | Watchpoints on local variables can also change meaning as result | |
8604 | of solib event. For example, if a watchpoint uses both a local | |
8605 | and a global variables in expression, it's a local watchpoint, | |
8606 | but unloading of a shared library will make the expression | |
8607 | invalid. This is not a very common use case, but we still | |
8608 | re-evaluate expression, to avoid surprises to the user. | |
8609 | ||
8610 | Note that for local watchpoints, we re-evaluate it only if | |
8611 | watchpoints frame id is still valid. If it's not, it means the | |
8612 | watchpoint is out of scope and will be deleted soon. In fact, | |
8613 | I'm not sure we'll ever be called in this case. | |
8614 | ||
8615 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 8616 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 8617 | |
3a5c3e22 PA |
8618 | Don't do anything about disabled watchpoints, since they will be |
8619 | reevaluated again when enabled. */ | |
8620 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
8621 | } |
8622 | ||
77b06cd7 TJB |
8623 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8624 | ||
8625 | static int | |
8626 | insert_watchpoint (struct bp_location *bl) | |
8627 | { | |
3a5c3e22 PA |
8628 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8629 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8630 | |
8631 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8632 | w->cond_exp); |
77b06cd7 TJB |
8633 | } |
8634 | ||
8635 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8636 | ||
8637 | static int | |
8638 | remove_watchpoint (struct bp_location *bl) | |
8639 | { | |
3a5c3e22 PA |
8640 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8641 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8642 | |
8643 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8644 | w->cond_exp); |
e09342b5 TJB |
8645 | } |
8646 | ||
e09342b5 | 8647 | static int |
348d480f PA |
8648 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
8649 | struct address_space *aspace, CORE_ADDR bp_addr) | |
e09342b5 | 8650 | { |
348d480f | 8651 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 8652 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 8653 | |
348d480f PA |
8654 | /* Continuable hardware watchpoints are treated as non-existent if the |
8655 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
8656 | some data address). Otherwise gdb won't stop on a break instruction | |
8657 | in the code (not from a breakpoint) when a hardware watchpoint has | |
8658 | been defined. Also skip watchpoints which we know did not trigger | |
8659 | (did not match the data address). */ | |
8660 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 8661 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 8662 | return 0; |
9c06b0b4 | 8663 | |
348d480f | 8664 | return 1; |
9c06b0b4 TJB |
8665 | } |
8666 | ||
348d480f PA |
8667 | static void |
8668 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 8669 | { |
348d480f | 8670 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 8671 | |
348d480f | 8672 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
8673 | } |
8674 | ||
8675 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 8676 | hardware watchpoints. */ |
9c06b0b4 TJB |
8677 | |
8678 | static int | |
348d480f | 8679 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 8680 | { |
3a5c3e22 PA |
8681 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8682 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
8683 | |
8684 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
8685 | } |
8686 | ||
8687 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 8688 | hardware watchpoints. */ |
9c06b0b4 TJB |
8689 | |
8690 | static int | |
348d480f | 8691 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 8692 | { |
efa80663 PA |
8693 | /* Read and access watchpoints only work with hardware support. */ |
8694 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
8695 | } |
8696 | ||
9c06b0b4 | 8697 | static enum print_stop_action |
348d480f | 8698 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 8699 | { |
348d480f PA |
8700 | struct cleanup *old_chain; |
8701 | struct breakpoint *b; | |
8702 | const struct bp_location *bl; | |
8703 | struct ui_stream *stb; | |
8704 | enum print_stop_action result; | |
3a5c3e22 | 8705 | struct watchpoint *w; |
79a45e25 | 8706 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8707 | |
8708 | gdb_assert (bs->bp_location_at != NULL); | |
8709 | ||
8710 | bl = bs->bp_location_at; | |
8711 | b = bs->breakpoint_at; | |
3a5c3e22 | 8712 | w = (struct watchpoint *) b; |
348d480f PA |
8713 | |
8714 | stb = ui_out_stream_new (uiout); | |
8715 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
8716 | |
8717 | switch (b->type) | |
8718 | { | |
348d480f | 8719 | case bp_watchpoint: |
9c06b0b4 TJB |
8720 | case bp_hardware_watchpoint: |
8721 | annotate_watchpoint (b->number); | |
8722 | if (ui_out_is_mi_like_p (uiout)) | |
8723 | ui_out_field_string | |
8724 | (uiout, "reason", | |
8725 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8726 | mention (b); |
8727 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8728 | ui_out_text (uiout, "\nOld value = "); | |
8729 | watchpoint_value_print (bs->old_val, stb->stream); | |
8730 | ui_out_field_stream (uiout, "old", stb); | |
8731 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 8732 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8733 | ui_out_field_stream (uiout, "new", stb); |
8734 | ui_out_text (uiout, "\n"); | |
8735 | /* More than one watchpoint may have been triggered. */ | |
8736 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8737 | break; |
8738 | ||
8739 | case bp_read_watchpoint: | |
8740 | if (ui_out_is_mi_like_p (uiout)) | |
8741 | ui_out_field_string | |
8742 | (uiout, "reason", | |
8743 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8744 | mention (b); |
8745 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8746 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 8747 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8748 | ui_out_field_stream (uiout, "value", stb); |
8749 | ui_out_text (uiout, "\n"); | |
8750 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8751 | break; |
8752 | ||
8753 | case bp_access_watchpoint: | |
348d480f PA |
8754 | if (bs->old_val != NULL) |
8755 | { | |
8756 | annotate_watchpoint (b->number); | |
8757 | if (ui_out_is_mi_like_p (uiout)) | |
8758 | ui_out_field_string | |
8759 | (uiout, "reason", | |
8760 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8761 | mention (b); | |
8762 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8763 | ui_out_text (uiout, "\nOld value = "); | |
8764 | watchpoint_value_print (bs->old_val, stb->stream); | |
8765 | ui_out_field_stream (uiout, "old", stb); | |
8766 | ui_out_text (uiout, "\nNew value = "); | |
8767 | } | |
8768 | else | |
8769 | { | |
8770 | mention (b); | |
8771 | if (ui_out_is_mi_like_p (uiout)) | |
8772 | ui_out_field_string | |
8773 | (uiout, "reason", | |
8774 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8775 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8776 | ui_out_text (uiout, "\nValue = "); | |
8777 | } | |
3a5c3e22 | 8778 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8779 | ui_out_field_stream (uiout, "new", stb); |
8780 | ui_out_text (uiout, "\n"); | |
8781 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8782 | break; |
8783 | default: | |
348d480f | 8784 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
8785 | } |
8786 | ||
348d480f PA |
8787 | do_cleanups (old_chain); |
8788 | return result; | |
8789 | } | |
8790 | ||
8791 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
8792 | watchpoints. */ | |
8793 | ||
8794 | static void | |
8795 | print_mention_watchpoint (struct breakpoint *b) | |
8796 | { | |
8797 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 8798 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 8799 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8800 | |
8801 | switch (b->type) | |
8802 | { | |
8803 | case bp_watchpoint: | |
8804 | ui_out_text (uiout, "Watchpoint "); | |
8805 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8806 | break; | |
8807 | case bp_hardware_watchpoint: | |
8808 | ui_out_text (uiout, "Hardware watchpoint "); | |
8809 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8810 | break; | |
8811 | case bp_read_watchpoint: | |
8812 | ui_out_text (uiout, "Hardware read watchpoint "); | |
8813 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8814 | break; | |
8815 | case bp_access_watchpoint: | |
8816 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
8817 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8818 | break; | |
8819 | default: | |
8820 | internal_error (__FILE__, __LINE__, | |
8821 | _("Invalid hardware watchpoint type.")); | |
8822 | } | |
8823 | ||
8824 | ui_out_field_int (uiout, "number", b->number); | |
8825 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8826 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
8827 | do_cleanups (ui_out_chain); |
8828 | } | |
8829 | ||
8830 | /* Implement the "print_recreate" breakpoint_ops method for | |
8831 | watchpoints. */ | |
8832 | ||
8833 | static void | |
8834 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8835 | { | |
3a5c3e22 PA |
8836 | struct watchpoint *w = (struct watchpoint *) b; |
8837 | ||
348d480f PA |
8838 | switch (b->type) |
8839 | { | |
8840 | case bp_watchpoint: | |
8841 | case bp_hardware_watchpoint: | |
8842 | fprintf_unfiltered (fp, "watch"); | |
8843 | break; | |
8844 | case bp_read_watchpoint: | |
8845 | fprintf_unfiltered (fp, "rwatch"); | |
8846 | break; | |
8847 | case bp_access_watchpoint: | |
8848 | fprintf_unfiltered (fp, "awatch"); | |
8849 | break; | |
8850 | default: | |
8851 | internal_error (__FILE__, __LINE__, | |
8852 | _("Invalid watchpoint type.")); | |
8853 | } | |
8854 | ||
3a5c3e22 | 8855 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 8856 | print_recreate_thread (b, fp); |
348d480f PA |
8857 | } |
8858 | ||
8859 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8860 | ||
2060206e | 8861 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
8862 | |
8863 | /* Implement the "insert" breakpoint_ops method for | |
8864 | masked hardware watchpoints. */ | |
8865 | ||
8866 | static int | |
8867 | insert_masked_watchpoint (struct bp_location *bl) | |
8868 | { | |
3a5c3e22 PA |
8869 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8870 | ||
8871 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8872 | bl->watchpoint_type); |
8873 | } | |
8874 | ||
8875 | /* Implement the "remove" breakpoint_ops method for | |
8876 | masked hardware watchpoints. */ | |
8877 | ||
8878 | static int | |
8879 | remove_masked_watchpoint (struct bp_location *bl) | |
8880 | { | |
3a5c3e22 PA |
8881 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8882 | ||
8883 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8884 | bl->watchpoint_type); |
8885 | } | |
8886 | ||
8887 | /* Implement the "resources_needed" breakpoint_ops method for | |
8888 | masked hardware watchpoints. */ | |
8889 | ||
8890 | static int | |
8891 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
8892 | { | |
3a5c3e22 PA |
8893 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8894 | ||
8895 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
8896 | } |
8897 | ||
8898 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
8899 | masked hardware watchpoints. */ | |
8900 | ||
8901 | static int | |
8902 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
8903 | { | |
8904 | return 0; | |
8905 | } | |
8906 | ||
8907 | /* Implement the "print_it" breakpoint_ops method for | |
8908 | masked hardware watchpoints. */ | |
8909 | ||
8910 | static enum print_stop_action | |
8911 | print_it_masked_watchpoint (bpstat bs) | |
8912 | { | |
8913 | struct breakpoint *b = bs->breakpoint_at; | |
79a45e25 | 8914 | struct ui_out *uiout = current_uiout; |
348d480f PA |
8915 | |
8916 | /* Masked watchpoints have only one location. */ | |
8917 | gdb_assert (b->loc && b->loc->next == NULL); | |
8918 | ||
8919 | switch (b->type) | |
8920 | { | |
8921 | case bp_hardware_watchpoint: | |
8922 | annotate_watchpoint (b->number); | |
8923 | if (ui_out_is_mi_like_p (uiout)) | |
8924 | ui_out_field_string | |
8925 | (uiout, "reason", | |
8926 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
8927 | break; | |
8928 | ||
8929 | case bp_read_watchpoint: | |
8930 | if (ui_out_is_mi_like_p (uiout)) | |
8931 | ui_out_field_string | |
8932 | (uiout, "reason", | |
8933 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
8934 | break; | |
8935 | ||
8936 | case bp_access_watchpoint: | |
8937 | if (ui_out_is_mi_like_p (uiout)) | |
8938 | ui_out_field_string | |
8939 | (uiout, "reason", | |
8940 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8941 | break; | |
8942 | default: | |
8943 | internal_error (__FILE__, __LINE__, | |
8944 | _("Invalid hardware watchpoint type.")); | |
8945 | } | |
8946 | ||
8947 | mention (b); | |
9c06b0b4 TJB |
8948 | ui_out_text (uiout, _("\n\ |
8949 | Check the underlying instruction at PC for the memory\n\ | |
8950 | address and value which triggered this watchpoint.\n")); | |
8951 | ui_out_text (uiout, "\n"); | |
8952 | ||
8953 | /* More than one watchpoint may have been triggered. */ | |
8954 | return PRINT_UNKNOWN; | |
8955 | } | |
8956 | ||
8957 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8958 | masked hardware watchpoints. */ | |
8959 | ||
8960 | static void | |
8961 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
8962 | struct ui_out *uiout) | |
8963 | { | |
3a5c3e22 PA |
8964 | struct watchpoint *w = (struct watchpoint *) b; |
8965 | ||
9c06b0b4 TJB |
8966 | /* Masked watchpoints have only one location. */ |
8967 | gdb_assert (b->loc && b->loc->next == NULL); | |
8968 | ||
8969 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 8970 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
8971 | ui_out_text (uiout, "\n"); |
8972 | } | |
8973 | ||
8974 | /* Implement the "print_mention" breakpoint_ops method for | |
8975 | masked hardware watchpoints. */ | |
8976 | ||
8977 | static void | |
8978 | print_mention_masked_watchpoint (struct breakpoint *b) | |
8979 | { | |
3a5c3e22 | 8980 | struct watchpoint *w = (struct watchpoint *) b; |
79a45e25 | 8981 | struct ui_out *uiout = current_uiout; |
9c06b0b4 TJB |
8982 | struct cleanup *ui_out_chain; |
8983 | ||
8984 | switch (b->type) | |
8985 | { | |
8986 | case bp_hardware_watchpoint: | |
8987 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
8988 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8989 | break; | |
8990 | case bp_read_watchpoint: | |
8991 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
8992 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8993 | break; | |
8994 | case bp_access_watchpoint: | |
8995 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
8996 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8997 | break; | |
8998 | default: | |
8999 | internal_error (__FILE__, __LINE__, | |
9000 | _("Invalid hardware watchpoint type.")); | |
9001 | } | |
9002 | ||
9003 | ui_out_field_int (uiout, "number", b->number); | |
9004 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 9005 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
9006 | do_cleanups (ui_out_chain); |
9007 | } | |
9008 | ||
9009 | /* Implement the "print_recreate" breakpoint_ops method for | |
9010 | masked hardware watchpoints. */ | |
9011 | ||
9012 | static void | |
9013 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
9014 | { | |
3a5c3e22 | 9015 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
9016 | char tmp[40]; |
9017 | ||
9018 | switch (b->type) | |
9019 | { | |
9020 | case bp_hardware_watchpoint: | |
9021 | fprintf_unfiltered (fp, "watch"); | |
9022 | break; | |
9023 | case bp_read_watchpoint: | |
9024 | fprintf_unfiltered (fp, "rwatch"); | |
9025 | break; | |
9026 | case bp_access_watchpoint: | |
9027 | fprintf_unfiltered (fp, "awatch"); | |
9028 | break; | |
9029 | default: | |
9030 | internal_error (__FILE__, __LINE__, | |
9031 | _("Invalid hardware watchpoint type.")); | |
9032 | } | |
9033 | ||
3a5c3e22 PA |
9034 | sprintf_vma (tmp, w->hw_wp_mask); |
9035 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 9036 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
9037 | } |
9038 | ||
9039 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9040 | ||
2060206e | 9041 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
9042 | |
9043 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9044 | ||
9045 | static int | |
9046 | is_masked_watchpoint (const struct breakpoint *b) | |
9047 | { | |
9048 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9049 | } | |
9050 | ||
53a5351d JM |
9051 | /* accessflag: hw_write: watch write, |
9052 | hw_read: watch read, | |
9053 | hw_access: watch access (read or write) */ | |
c906108c | 9054 | static void |
84f4c1fe PM |
9055 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9056 | int just_location, int internal) | |
c906108c | 9057 | { |
a9634178 | 9058 | volatile struct gdb_exception e; |
d983da9c | 9059 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9060 | struct expression *exp; |
60e1c644 | 9061 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9062 | struct value *val, *mark, *result; |
c906108c | 9063 | struct frame_info *frame; |
c906108c SS |
9064 | char *exp_start = NULL; |
9065 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9066 | char *tok, *end_tok; |
9067 | int toklen = -1; | |
c906108c SS |
9068 | char *cond_start = NULL; |
9069 | char *cond_end = NULL; | |
c906108c | 9070 | enum bptype bp_type; |
37e4754d | 9071 | int thread = -1; |
0cf6dd15 | 9072 | int pc = 0; |
9c06b0b4 TJB |
9073 | /* Flag to indicate whether we are going to use masks for |
9074 | the hardware watchpoint. */ | |
9075 | int use_mask = 0; | |
9076 | CORE_ADDR mask = 0; | |
3a5c3e22 | 9077 | struct watchpoint *w; |
c906108c | 9078 | |
37e4754d LM |
9079 | /* Make sure that we actually have parameters to parse. */ |
9080 | if (arg != NULL && arg[0] != '\0') | |
9081 | { | |
9c06b0b4 | 9082 | char *value_start; |
37e4754d | 9083 | |
9c06b0b4 TJB |
9084 | /* Look for "parameter value" pairs at the end |
9085 | of the arguments string. */ | |
9086 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9087 | { | |
9088 | /* Skip whitespace at the end of the argument list. */ | |
9089 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9090 | tok--; | |
9091 | ||
9092 | /* Find the beginning of the last token. | |
9093 | This is the value of the parameter. */ | |
9094 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9095 | tok--; | |
9096 | value_start = tok + 1; | |
9097 | ||
9098 | /* Skip whitespace. */ | |
9099 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9100 | tok--; | |
9101 | ||
9102 | end_tok = tok; | |
9103 | ||
9104 | /* Find the beginning of the second to last token. | |
9105 | This is the parameter itself. */ | |
9106 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9107 | tok--; | |
9108 | tok++; | |
9109 | toklen = end_tok - tok + 1; | |
9110 | ||
9111 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9112 | { | |
9113 | /* At this point we've found a "thread" token, which means | |
9114 | the user is trying to set a watchpoint that triggers | |
9115 | only in a specific thread. */ | |
9116 | char *endp; | |
37e4754d | 9117 | |
9c06b0b4 TJB |
9118 | if (thread != -1) |
9119 | error(_("You can specify only one thread.")); | |
37e4754d | 9120 | |
9c06b0b4 TJB |
9121 | /* Extract the thread ID from the next token. */ |
9122 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9123 | |
9c06b0b4 TJB |
9124 | /* Check if the user provided a valid numeric value for the |
9125 | thread ID. */ | |
9126 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9127 | error (_("Invalid thread ID specification %s."), value_start); | |
9128 | ||
9129 | /* Check if the thread actually exists. */ | |
9130 | if (!valid_thread_id (thread)) | |
9131 | error (_("Unknown thread %d."), thread); | |
9132 | } | |
9133 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9134 | { | |
9135 | /* We've found a "mask" token, which means the user wants to | |
9136 | create a hardware watchpoint that is going to have the mask | |
9137 | facility. */ | |
9138 | struct value *mask_value, *mark; | |
37e4754d | 9139 | |
9c06b0b4 TJB |
9140 | if (use_mask) |
9141 | error(_("You can specify only one mask.")); | |
37e4754d | 9142 | |
9c06b0b4 | 9143 | use_mask = just_location = 1; |
37e4754d | 9144 | |
9c06b0b4 TJB |
9145 | mark = value_mark (); |
9146 | mask_value = parse_to_comma_and_eval (&value_start); | |
9147 | mask = value_as_address (mask_value); | |
9148 | value_free_to_mark (mark); | |
9149 | } | |
9150 | else | |
9151 | /* We didn't recognize what we found. We should stop here. */ | |
9152 | break; | |
37e4754d | 9153 | |
9c06b0b4 TJB |
9154 | /* Truncate the string and get rid of the "parameter value" pair before |
9155 | the arguments string is parsed by the parse_exp_1 function. */ | |
9156 | *tok = '\0'; | |
9157 | } | |
37e4754d LM |
9158 | } |
9159 | ||
9160 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9161 | innermost_block = NULL; |
9162 | exp_start = arg; | |
9163 | exp = parse_exp_1 (&arg, 0, 0); | |
9164 | exp_end = arg; | |
fa8a61dc TT |
9165 | /* Remove trailing whitespace from the expression before saving it. |
9166 | This makes the eventual display of the expression string a bit | |
9167 | prettier. */ | |
9168 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9169 | --exp_end; | |
9170 | ||
65d79d4b SDJ |
9171 | /* Checking if the expression is not constant. */ |
9172 | if (watchpoint_exp_is_const (exp)) | |
9173 | { | |
9174 | int len; | |
9175 | ||
9176 | len = exp_end - exp_start; | |
9177 | while (len > 0 && isspace (exp_start[len - 1])) | |
9178 | len--; | |
9179 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9180 | } | |
9181 | ||
c906108c SS |
9182 | exp_valid_block = innermost_block; |
9183 | mark = value_mark (); | |
a1442452 | 9184 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9185 | |
9186 | if (just_location) | |
9187 | { | |
9c06b0b4 TJB |
9188 | int ret; |
9189 | ||
06a64a0b | 9190 | exp_valid_block = NULL; |
a1442452 | 9191 | val = value_addr (result); |
06a64a0b TT |
9192 | release_value (val); |
9193 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9194 | |
9195 | if (use_mask) | |
9196 | { | |
9197 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9198 | mask); | |
9199 | if (ret == -1) | |
9200 | error (_("This target does not support masked watchpoints.")); | |
9201 | else if (ret == -2) | |
9202 | error (_("Invalid mask or memory region.")); | |
9203 | } | |
06a64a0b TT |
9204 | } |
9205 | else if (val != NULL) | |
fa4727a6 | 9206 | release_value (val); |
c906108c | 9207 | |
e9cafbcc TT |
9208 | tok = skip_spaces (arg); |
9209 | end_tok = skip_to_space (tok); | |
c906108c SS |
9210 | |
9211 | toklen = end_tok - tok; | |
9212 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9213 | { | |
2d134ed3 PA |
9214 | struct expression *cond; |
9215 | ||
60e1c644 | 9216 | innermost_block = NULL; |
c906108c SS |
9217 | tok = cond_start = end_tok + 1; |
9218 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9219 | |
9220 | /* The watchpoint expression may not be local, but the condition | |
9221 | may still be. E.g.: `watch global if local > 0'. */ | |
9222 | cond_exp_valid_block = innermost_block; | |
9223 | ||
2d134ed3 | 9224 | xfree (cond); |
c906108c SS |
9225 | cond_end = tok; |
9226 | } | |
9227 | if (*tok) | |
8a3fe4f8 | 9228 | error (_("Junk at end of command.")); |
c906108c | 9229 | |
53a5351d | 9230 | if (accessflag == hw_read) |
c5aa993b | 9231 | bp_type = bp_read_watchpoint; |
53a5351d | 9232 | else if (accessflag == hw_access) |
c5aa993b JM |
9233 | bp_type = bp_access_watchpoint; |
9234 | else | |
9235 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9236 | |
d983da9c | 9237 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9238 | |
9239 | /* If the expression is "local", then set up a "watchpoint scope" | |
9240 | breakpoint at the point where we've left the scope of the watchpoint | |
9241 | expression. Create the scope breakpoint before the watchpoint, so | |
9242 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9243 | if (exp_valid_block && frame) |
d983da9c | 9244 | { |
edb3359d DJ |
9245 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9246 | { | |
9247 | scope_breakpoint | |
a6d9a66e UW |
9248 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9249 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
9250 | bp_watchpoint_scope, |
9251 | &momentary_breakpoint_ops); | |
d983da9c | 9252 | |
edb3359d | 9253 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9254 | |
edb3359d DJ |
9255 | /* Automatically delete the breakpoint when it hits. */ |
9256 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9257 | |
edb3359d DJ |
9258 | /* Only break in the proper frame (help with recursion). */ |
9259 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9260 | |
edb3359d | 9261 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9262 | scope_breakpoint->loc->gdbarch |
9263 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9264 | scope_breakpoint->loc->requested_address |
9265 | = frame_unwind_caller_pc (frame); | |
9266 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9267 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9268 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9269 | scope_breakpoint->type); |
9270 | } | |
d983da9c DJ |
9271 | } |
9272 | ||
c906108c | 9273 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
9274 | |
9275 | w = XCNEW (struct watchpoint); | |
9276 | b = &w->base; | |
348d480f | 9277 | if (use_mask) |
3a5c3e22 PA |
9278 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9279 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 9280 | else |
3a5c3e22 PA |
9281 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9282 | &watchpoint_breakpoint_ops); | |
37e4754d | 9283 | b->thread = thread; |
b5de0fa7 | 9284 | b->disposition = disp_donttouch; |
348d480f | 9285 | b->pspace = current_program_space; |
3a5c3e22 PA |
9286 | w->exp = exp; |
9287 | w->exp_valid_block = exp_valid_block; | |
9288 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
9289 | if (just_location) |
9290 | { | |
9291 | struct type *t = value_type (val); | |
9292 | CORE_ADDR addr = value_as_address (val); | |
9293 | char *name; | |
9294 | ||
9295 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9296 | name = type_to_string (t); | |
9297 | ||
3a5c3e22 | 9298 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 9299 | core_addr_to_string (addr)); |
06a64a0b TT |
9300 | xfree (name); |
9301 | ||
3a5c3e22 | 9302 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9303 | (int) (exp_end - exp_start), exp_start); |
9304 | ||
06a64a0b TT |
9305 | /* The above expression is in C. */ |
9306 | b->language = language_c; | |
9307 | } | |
9308 | else | |
3a5c3e22 | 9309 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
9310 | |
9311 | if (use_mask) | |
9312 | { | |
3a5c3e22 | 9313 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
9314 | } |
9315 | else | |
9316 | { | |
3a5c3e22 PA |
9317 | w->val = val; |
9318 | w->val_valid = 1; | |
9c06b0b4 | 9319 | } |
77b06cd7 | 9320 | |
c906108c SS |
9321 | if (cond_start) |
9322 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9323 | else | |
9324 | b->cond_string = 0; | |
c5aa993b | 9325 | |
c906108c | 9326 | if (frame) |
f6bc2008 | 9327 | { |
3a5c3e22 PA |
9328 | w->watchpoint_frame = get_frame_id (frame); |
9329 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 9330 | } |
c906108c | 9331 | else |
f6bc2008 | 9332 | { |
3a5c3e22 PA |
9333 | w->watchpoint_frame = null_frame_id; |
9334 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 9335 | } |
c906108c | 9336 | |
d983da9c | 9337 | if (scope_breakpoint != NULL) |
c906108c | 9338 | { |
d983da9c DJ |
9339 | /* The scope breakpoint is related to the watchpoint. We will |
9340 | need to act on them together. */ | |
9341 | b->related_breakpoint = scope_breakpoint; | |
9342 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9343 | } |
d983da9c | 9344 | |
06a64a0b TT |
9345 | if (!just_location) |
9346 | value_free_to_mark (mark); | |
2d134ed3 | 9347 | |
a9634178 TJB |
9348 | TRY_CATCH (e, RETURN_MASK_ALL) |
9349 | { | |
9350 | /* Finally update the new watchpoint. This creates the locations | |
9351 | that should be inserted. */ | |
3a5c3e22 | 9352 | update_watchpoint (w, 1); |
a9634178 TJB |
9353 | } |
9354 | if (e.reason < 0) | |
9355 | { | |
9356 | delete_breakpoint (b); | |
9357 | throw_exception (e); | |
9358 | } | |
9359 | ||
3a5c3e22 | 9360 | install_breakpoint (internal, b); |
c906108c SS |
9361 | } |
9362 | ||
e09342b5 | 9363 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9364 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9365 | |
c906108c | 9366 | static int |
a9634178 | 9367 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9368 | { |
9369 | int found_memory_cnt = 0; | |
2e70b7b9 | 9370 | struct value *head = v; |
c906108c SS |
9371 | |
9372 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9373 | if (!can_use_hw_watchpoints) |
c906108c | 9374 | return 0; |
c5aa993b | 9375 | |
5c44784c JM |
9376 | /* Make sure that the value of the expression depends only upon |
9377 | memory contents, and values computed from them within GDB. If we | |
9378 | find any register references or function calls, we can't use a | |
9379 | hardware watchpoint. | |
9380 | ||
9381 | The idea here is that evaluating an expression generates a series | |
9382 | of values, one holding the value of every subexpression. (The | |
9383 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9384 | a*b+c.) GDB's values hold almost enough information to establish | |
9385 | the criteria given above --- they identify memory lvalues, | |
9386 | register lvalues, computed values, etcetera. So we can evaluate | |
9387 | the expression, and then scan the chain of values that leaves | |
9388 | behind to decide whether we can detect any possible change to the | |
9389 | expression's final value using only hardware watchpoints. | |
9390 | ||
9391 | However, I don't think that the values returned by inferior | |
9392 | function calls are special in any way. So this function may not | |
9393 | notice that an expression involving an inferior function call | |
9394 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9395 | for (; v; v = value_next (v)) |
c906108c | 9396 | { |
5c44784c | 9397 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9398 | { |
8464be76 DJ |
9399 | if (v != head && value_lazy (v)) |
9400 | /* A lazy memory lvalue in the chain is one that GDB never | |
9401 | needed to fetch; we either just used its address (e.g., | |
9402 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9403 | in `a,b'). This doesn't apply to HEAD; if that is | |
9404 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9405 | ; |
53a5351d | 9406 | else |
5c44784c JM |
9407 | { |
9408 | /* Ahh, memory we actually used! Check if we can cover | |
9409 | it with hardware watchpoints. */ | |
df407dfe | 9410 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9411 | |
9412 | /* We only watch structs and arrays if user asked for it | |
9413 | explicitly, never if they just happen to appear in a | |
9414 | middle of some value chain. */ | |
9415 | if (v == head | |
9416 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9417 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9418 | { | |
42ae5230 | 9419 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9420 | int len; |
9421 | int num_regs; | |
9422 | ||
a9634178 | 9423 | len = (target_exact_watchpoints |
e09342b5 TJB |
9424 | && is_scalar_type_recursive (vtype))? |
9425 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9426 | |
e09342b5 TJB |
9427 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9428 | if (!num_regs) | |
2e70b7b9 MS |
9429 | return 0; |
9430 | else | |
e09342b5 | 9431 | found_memory_cnt += num_regs; |
2e70b7b9 | 9432 | } |
5c44784c | 9433 | } |
c5aa993b | 9434 | } |
5086187c AC |
9435 | else if (VALUE_LVAL (v) != not_lval |
9436 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9437 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9438 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9439 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9440 | } |
9441 | ||
9442 | /* The expression itself looks suitable for using a hardware | |
9443 | watchpoint, but give the target machine a chance to reject it. */ | |
9444 | return found_memory_cnt; | |
9445 | } | |
9446 | ||
8b93c638 | 9447 | void |
84f4c1fe | 9448 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9449 | { |
84f4c1fe | 9450 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9451 | } |
9452 | ||
9453 | /* A helper function that looks for an argument at the start of a | |
9454 | string. The argument must also either be at the end of the string, | |
9455 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9456 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9457 | ||
9458 | static int | |
9459 | check_for_argument (char **str, char *arg, int arg_len) | |
9460 | { | |
9461 | if (strncmp (*str, arg, arg_len) == 0 | |
9462 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9463 | { | |
9464 | *str += arg_len; | |
9465 | return 1; | |
9466 | } | |
9467 | return 0; | |
9468 | } | |
9469 | ||
9470 | /* A helper function that looks for the "-location" argument and then | |
9471 | calls watch_command_1. */ | |
9472 | ||
9473 | static void | |
9474 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9475 | { | |
9476 | int just_location = 0; | |
9477 | ||
9478 | if (arg | |
9479 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9480 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9481 | { | |
e9cafbcc | 9482 | arg = skip_spaces (arg); |
06a64a0b TT |
9483 | just_location = 1; |
9484 | } | |
9485 | ||
84f4c1fe | 9486 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9487 | } |
8926118c | 9488 | |
c5aa993b | 9489 | static void |
fba45db2 | 9490 | watch_command (char *arg, int from_tty) |
c906108c | 9491 | { |
06a64a0b | 9492 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9493 | } |
9494 | ||
8b93c638 | 9495 | void |
84f4c1fe | 9496 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9497 | { |
84f4c1fe | 9498 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9499 | } |
8926118c | 9500 | |
c5aa993b | 9501 | static void |
fba45db2 | 9502 | rwatch_command (char *arg, int from_tty) |
c906108c | 9503 | { |
06a64a0b | 9504 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9505 | } |
9506 | ||
8b93c638 | 9507 | void |
84f4c1fe | 9508 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9509 | { |
84f4c1fe | 9510 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9511 | } |
8926118c | 9512 | |
c5aa993b | 9513 | static void |
fba45db2 | 9514 | awatch_command (char *arg, int from_tty) |
c906108c | 9515 | { |
06a64a0b | 9516 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9517 | } |
c906108c | 9518 | \f |
c5aa993b | 9519 | |
43ff13b4 | 9520 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9521 | because it uses the mechanisms of breakpoints. */ |
9522 | ||
bfec99b2 PA |
9523 | struct until_break_command_continuation_args |
9524 | { | |
9525 | struct breakpoint *breakpoint; | |
9526 | struct breakpoint *breakpoint2; | |
186c406b | 9527 | int thread_num; |
bfec99b2 PA |
9528 | }; |
9529 | ||
43ff13b4 | 9530 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9531 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9532 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9533 | command. */ |
c2c6d25f | 9534 | static void |
fa4cd53f | 9535 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 9536 | { |
bfec99b2 PA |
9537 | struct until_break_command_continuation_args *a = arg; |
9538 | ||
9539 | delete_breakpoint (a->breakpoint); | |
9540 | if (a->breakpoint2) | |
9541 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9542 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9543 | } |
9544 | ||
c906108c | 9545 | void |
ae66c1fc | 9546 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9547 | { |
9548 | struct symtabs_and_lines sals; | |
9549 | struct symtab_and_line sal; | |
206415a3 | 9550 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9551 | struct breakpoint *breakpoint; |
f107f563 | 9552 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9553 | struct cleanup *old_chain; |
186c406b TT |
9554 | int thread; |
9555 | struct thread_info *tp; | |
c906108c SS |
9556 | |
9557 | clear_proceed_status (); | |
9558 | ||
9559 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9560 | this function. */ |
c5aa993b | 9561 | |
c906108c SS |
9562 | if (default_breakpoint_valid) |
9563 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
58438ac1 | 9564 | default_breakpoint_line, NULL); |
c906108c | 9565 | else |
58438ac1 | 9566 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL); |
c5aa993b | 9567 | |
c906108c | 9568 | if (sals.nelts != 1) |
8a3fe4f8 | 9569 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9570 | |
c906108c | 9571 | sal = sals.sals[0]; |
4a64f543 | 9572 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9573 | |
c906108c | 9574 | if (*arg) |
8a3fe4f8 | 9575 | error (_("Junk at end of arguments.")); |
c5aa993b | 9576 | |
c906108c | 9577 | resolve_sal_pc (&sal); |
c5aa993b | 9578 | |
ae66c1fc EZ |
9579 | if (anywhere) |
9580 | /* If the user told us to continue until a specified location, | |
9581 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9582 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9583 | null_frame_id, bp_until); | |
ae66c1fc | 9584 | else |
4a64f543 MS |
9585 | /* Otherwise, specify the selected frame, because we want to stop |
9586 | only at the very same frame. */ | |
a6d9a66e UW |
9587 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9588 | get_stack_frame_id (frame), | |
ae66c1fc | 9589 | bp_until); |
c5aa993b | 9590 | |
f107f563 | 9591 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9592 | |
186c406b TT |
9593 | tp = inferior_thread (); |
9594 | thread = tp->num; | |
9595 | ||
ae66c1fc EZ |
9596 | /* Keep within the current frame, or in frames called by the current |
9597 | one. */ | |
edb3359d DJ |
9598 | |
9599 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9600 | { |
edb3359d DJ |
9601 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9602 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9603 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9604 | sal, | |
edb3359d | 9605 | frame_unwind_caller_id (frame), |
f107f563 VP |
9606 | bp_until); |
9607 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9608 | |
9609 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9610 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9611 | } |
c5aa993b | 9612 | |
c906108c | 9613 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9614 | |
4a64f543 MS |
9615 | /* If we are running asynchronously, and proceed call above has |
9616 | actually managed to start the target, arrange for breakpoints to | |
9617 | be deleted when the target stops. Otherwise, we're already | |
9618 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9619 | |
8ea051c5 | 9620 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9621 | { |
bfec99b2 PA |
9622 | struct until_break_command_continuation_args *args; |
9623 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9624 | |
bfec99b2 PA |
9625 | args->breakpoint = breakpoint; |
9626 | args->breakpoint2 = breakpoint2; | |
186c406b | 9627 | args->thread_num = thread; |
f107f563 VP |
9628 | |
9629 | discard_cleanups (old_chain); | |
95e54da7 PA |
9630 | add_continuation (inferior_thread (), |
9631 | until_break_command_continuation, args, | |
604ead4a | 9632 | xfree); |
f107f563 VP |
9633 | } |
9634 | else | |
c5aa993b | 9635 | do_cleanups (old_chain); |
c906108c | 9636 | } |
ae66c1fc | 9637 | |
c906108c SS |
9638 | /* This function attempts to parse an optional "if <cond>" clause |
9639 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9640 | |
c906108c SS |
9641 | Else, it returns a pointer to the condition string. (It does not |
9642 | attempt to evaluate the string against a particular block.) And, | |
9643 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9644 | if clause in the arg string. */ |
53a5351d | 9645 | |
c906108c | 9646 | static char * |
fba45db2 | 9647 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9648 | { |
c5aa993b JM |
9649 | char *cond_string; |
9650 | ||
9651 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9652 | return NULL; |
c5aa993b | 9653 | |
4a64f543 | 9654 | /* Skip the "if" keyword. */ |
c906108c | 9655 | (*arg) += 2; |
c5aa993b | 9656 | |
c906108c | 9657 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9658 | condition string. */ |
e9cafbcc | 9659 | *arg = skip_spaces (*arg); |
c906108c | 9660 | cond_string = *arg; |
c5aa993b | 9661 | |
4a64f543 MS |
9662 | /* Assume that the condition occupies the remainder of the arg |
9663 | string. */ | |
c906108c | 9664 | (*arg) += strlen (cond_string); |
c5aa993b | 9665 | |
c906108c SS |
9666 | return cond_string; |
9667 | } | |
c5aa993b | 9668 | |
c906108c SS |
9669 | /* Commands to deal with catching events, such as signals, exceptions, |
9670 | process start/exit, etc. */ | |
c5aa993b JM |
9671 | |
9672 | typedef enum | |
9673 | { | |
44feb3ce TT |
9674 | catch_fork_temporary, catch_vfork_temporary, |
9675 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9676 | } |
9677 | catch_fork_kind; | |
9678 | ||
c906108c | 9679 | static void |
cc59ec59 MS |
9680 | catch_fork_command_1 (char *arg, int from_tty, |
9681 | struct cmd_list_element *command) | |
c906108c | 9682 | { |
a6d9a66e | 9683 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9684 | char *cond_string = NULL; |
44feb3ce TT |
9685 | catch_fork_kind fork_kind; |
9686 | int tempflag; | |
9687 | ||
9688 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9689 | tempflag = (fork_kind == catch_fork_temporary | |
9690 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9691 | |
44feb3ce TT |
9692 | if (!arg) |
9693 | arg = ""; | |
e9cafbcc | 9694 | arg = skip_spaces (arg); |
c5aa993b | 9695 | |
c906108c | 9696 | /* The allowed syntax is: |
c5aa993b JM |
9697 | catch [v]fork |
9698 | catch [v]fork if <cond> | |
9699 | ||
4a64f543 | 9700 | First, check if there's an if clause. */ |
c906108c | 9701 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9702 | |
c906108c | 9703 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9704 | error (_("Junk at end of arguments.")); |
c5aa993b | 9705 | |
c906108c | 9706 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9707 | and enable reporting of such events. */ |
c5aa993b JM |
9708 | switch (fork_kind) |
9709 | { | |
44feb3ce TT |
9710 | case catch_fork_temporary: |
9711 | case catch_fork_permanent: | |
a6d9a66e | 9712 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9713 | &catch_fork_breakpoint_ops); |
c906108c | 9714 | break; |
44feb3ce TT |
9715 | case catch_vfork_temporary: |
9716 | case catch_vfork_permanent: | |
a6d9a66e | 9717 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9718 | &catch_vfork_breakpoint_ops); |
c906108c | 9719 | break; |
c5aa993b | 9720 | default: |
8a3fe4f8 | 9721 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9722 | break; |
c5aa993b | 9723 | } |
c906108c SS |
9724 | } |
9725 | ||
9726 | static void | |
cc59ec59 MS |
9727 | catch_exec_command_1 (char *arg, int from_tty, |
9728 | struct cmd_list_element *command) | |
c906108c | 9729 | { |
b4d90040 | 9730 | struct exec_catchpoint *c; |
a6d9a66e | 9731 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9732 | int tempflag; |
c5aa993b | 9733 | char *cond_string = NULL; |
c906108c | 9734 | |
44feb3ce TT |
9735 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9736 | ||
9737 | if (!arg) | |
9738 | arg = ""; | |
e9cafbcc | 9739 | arg = skip_spaces (arg); |
c906108c SS |
9740 | |
9741 | /* The allowed syntax is: | |
c5aa993b JM |
9742 | catch exec |
9743 | catch exec if <cond> | |
c906108c | 9744 | |
4a64f543 | 9745 | First, check if there's an if clause. */ |
c906108c SS |
9746 | cond_string = ep_parse_optional_if_clause (&arg); |
9747 | ||
9748 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9749 | error (_("Junk at end of arguments.")); |
c906108c | 9750 | |
b4d90040 PA |
9751 | c = XNEW (struct exec_catchpoint); |
9752 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
9753 | &catch_exec_breakpoint_ops); | |
9754 | c->exec_pathname = NULL; | |
9755 | ||
3a5c3e22 | 9756 | install_breakpoint (0, &c->base); |
c906108c | 9757 | } |
c5aa993b | 9758 | |
3086aeae | 9759 | static enum print_stop_action |
348d480f | 9760 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 9761 | { |
79a45e25 | 9762 | struct ui_out *uiout = current_uiout; |
348d480f | 9763 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 9764 | int bp_temp, bp_throw; |
3086aeae | 9765 | |
ade92717 | 9766 | annotate_catchpoint (b->number); |
3086aeae | 9767 | |
ade92717 AR |
9768 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9769 | if (b->loc->address != b->loc->requested_address) | |
9770 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9771 | b->loc->address, | |
9772 | b->number, 1); | |
df2b6d2d | 9773 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9774 | ui_out_text (uiout, |
9775 | bp_temp ? "Temporary catchpoint " | |
9776 | : "Catchpoint "); | |
9777 | if (!ui_out_is_mi_like_p (uiout)) | |
9778 | ui_out_field_int (uiout, "bkptno", b->number); | |
9779 | ui_out_text (uiout, | |
c0b37c48 AR |
9780 | bp_throw ? " (exception thrown), " |
9781 | : " (exception caught), "); | |
ade92717 AR |
9782 | if (ui_out_is_mi_like_p (uiout)) |
9783 | { | |
9784 | ui_out_field_string (uiout, "reason", | |
9785 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9786 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9787 | ui_out_field_int (uiout, "bkptno", b->number); | |
9788 | } | |
3086aeae DJ |
9789 | return PRINT_SRC_AND_LOC; |
9790 | } | |
9791 | ||
9792 | static void | |
cc59ec59 MS |
9793 | print_one_exception_catchpoint (struct breakpoint *b, |
9794 | struct bp_location **last_loc) | |
3086aeae | 9795 | { |
79a45b7d | 9796 | struct value_print_options opts; |
79a45e25 | 9797 | struct ui_out *uiout = current_uiout; |
cc59ec59 | 9798 | |
79a45b7d TT |
9799 | get_user_print_options (&opts); |
9800 | if (opts.addressprint) | |
3086aeae DJ |
9801 | { |
9802 | annotate_field (4); | |
604133b5 AR |
9803 | if (b->loc == NULL || b->loc->shlib_disabled) |
9804 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9805 | else | |
5af949e3 UW |
9806 | ui_out_field_core_addr (uiout, "addr", |
9807 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9808 | } |
9809 | annotate_field (5); | |
604133b5 | 9810 | if (b->loc) |
a6d9a66e | 9811 | *last_loc = b->loc; |
3086aeae DJ |
9812 | if (strstr (b->addr_string, "throw") != NULL) |
9813 | ui_out_field_string (uiout, "what", "exception throw"); | |
9814 | else | |
9815 | ui_out_field_string (uiout, "what", "exception catch"); | |
9816 | } | |
9817 | ||
9818 | static void | |
9819 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9820 | { | |
79a45e25 | 9821 | struct ui_out *uiout = current_uiout; |
ade92717 AR |
9822 | int bp_temp; |
9823 | int bp_throw; | |
9824 | ||
df2b6d2d | 9825 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9826 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9827 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9828 | : _("Catchpoint ")); | |
9829 | ui_out_field_int (uiout, "bkptno", b->number); | |
9830 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9831 | : _(" (catch)")); | |
3086aeae DJ |
9832 | } |
9833 | ||
6149aea9 PA |
9834 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9835 | catch catchpoints. */ | |
9836 | ||
9837 | static void | |
4a64f543 MS |
9838 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9839 | struct ui_file *fp) | |
6149aea9 PA |
9840 | { |
9841 | int bp_temp; | |
9842 | int bp_throw; | |
9843 | ||
9844 | bp_temp = b->disposition == disp_del; | |
9845 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9846 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9847 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 9848 | print_recreate_thread (b, fp); |
6149aea9 PA |
9849 | } |
9850 | ||
2060206e | 9851 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
9852 | |
9853 | static int | |
9854 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9855 | enum exception_event_kind ex_event, int from_tty) | |
9856 | { | |
604133b5 AR |
9857 | char *trigger_func_name; |
9858 | ||
3086aeae | 9859 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9860 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9861 | else |
604133b5 | 9862 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9863 | |
8cdf0e15 VP |
9864 | create_breakpoint (get_current_arch (), |
9865 | trigger_func_name, cond_string, -1, | |
9866 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9867 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9868 | 0, |
9869 | AUTO_BOOLEAN_TRUE /* pending */, | |
9870 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9871 | 1 /* enabled */, |
9872 | 0 /* internal */); | |
3086aeae | 9873 | |
3086aeae DJ |
9874 | return 1; |
9875 | } | |
9876 | ||
4a64f543 | 9877 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9878 | |
9879 | static void | |
fba45db2 KB |
9880 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9881 | int tempflag, int from_tty) | |
c906108c | 9882 | { |
c5aa993b | 9883 | char *cond_string = NULL; |
c5aa993b | 9884 | |
44feb3ce TT |
9885 | if (!arg) |
9886 | arg = ""; | |
e9cafbcc | 9887 | arg = skip_spaces (arg); |
c5aa993b | 9888 | |
c906108c SS |
9889 | cond_string = ep_parse_optional_if_clause (&arg); |
9890 | ||
9891 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9892 | error (_("Junk at end of arguments.")); |
c906108c | 9893 | |
059fb39f PM |
9894 | if (ex_event != EX_EVENT_THROW |
9895 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9896 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9897 | |
3086aeae DJ |
9898 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9899 | return; | |
9900 | ||
8a3fe4f8 | 9901 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9902 | } |
9903 | ||
44feb3ce TT |
9904 | /* Implementation of "catch catch" command. */ |
9905 | ||
9906 | static void | |
9907 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9908 | { | |
9909 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9910 | |
44feb3ce TT |
9911 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9912 | } | |
9913 | ||
9914 | /* Implementation of "catch throw" command. */ | |
9915 | ||
9916 | static void | |
9917 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9918 | { | |
9919 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9920 | |
44feb3ce TT |
9921 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9922 | } | |
9923 | ||
9ac4176b | 9924 | void |
28010a5d PA |
9925 | init_ada_exception_breakpoint (struct breakpoint *b, |
9926 | struct gdbarch *gdbarch, | |
9927 | struct symtab_and_line sal, | |
9928 | char *addr_string, | |
c0a91b2b | 9929 | const struct breakpoint_ops *ops, |
28010a5d PA |
9930 | int tempflag, |
9931 | int from_tty) | |
f7f9143b | 9932 | { |
f7f9143b JB |
9933 | if (from_tty) |
9934 | { | |
5af949e3 UW |
9935 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9936 | if (!loc_gdbarch) | |
9937 | loc_gdbarch = gdbarch; | |
9938 | ||
6c95b8df PA |
9939 | describe_other_breakpoints (loc_gdbarch, |
9940 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9941 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9942 | version for exception catchpoints, because two catchpoints | |
9943 | used for different exception names will use the same address. | |
9944 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9945 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 9946 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
9947 | the user what type of catchpoint it is. The above is good |
9948 | enough for now, though. */ | |
9949 | } | |
9950 | ||
28010a5d | 9951 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
9952 | |
9953 | b->enable_state = bp_enabled; | |
9954 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
9955 | b->addr_string = addr_string; |
9956 | b->language = language_ada; | |
f7f9143b JB |
9957 | } |
9958 | ||
a96d9b2e SDJ |
9959 | /* Splits the argument using space as delimiter. Returns an xmalloc'd |
9960 | filter list, or NULL if no filtering is required. */ | |
9961 | static VEC(int) * | |
9962 | catch_syscall_split_args (char *arg) | |
9963 | { | |
9964 | VEC(int) *result = NULL; | |
29d0bb3d | 9965 | struct cleanup *cleanup = make_cleanup (VEC_cleanup (int), &result); |
a96d9b2e SDJ |
9966 | |
9967 | while (*arg != '\0') | |
9968 | { | |
9969 | int i, syscall_number; | |
9970 | char *endptr; | |
9971 | char cur_name[128]; | |
9972 | struct syscall s; | |
9973 | ||
9974 | /* Skip whitespace. */ | |
9975 | while (isspace (*arg)) | |
9976 | arg++; | |
9977 | ||
9978 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9979 | cur_name[i] = arg[i]; | |
9980 | cur_name[i] = '\0'; | |
9981 | arg += i; | |
9982 | ||
9983 | /* Check if the user provided a syscall name or a number. */ | |
9984 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9985 | if (*endptr == '\0') | |
bccd0dd2 | 9986 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9987 | else |
9988 | { | |
9989 | /* We have a name. Let's check if it's valid and convert it | |
9990 | to a number. */ | |
9991 | get_syscall_by_name (cur_name, &s); | |
9992 | ||
9993 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9994 | /* Here we have to issue an error instead of a warning, |
9995 | because GDB cannot do anything useful if there's no | |
9996 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9997 | error (_("Unknown syscall name '%s'."), cur_name); |
9998 | } | |
9999 | ||
10000 | /* Ok, it's valid. */ | |
10001 | VEC_safe_push (int, result, s.number); | |
10002 | } | |
10003 | ||
10004 | discard_cleanups (cleanup); | |
10005 | return result; | |
10006 | } | |
10007 | ||
10008 | /* Implement the "catch syscall" command. */ | |
10009 | ||
10010 | static void | |
cc59ec59 MS |
10011 | catch_syscall_command_1 (char *arg, int from_tty, |
10012 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10013 | { |
10014 | int tempflag; | |
10015 | VEC(int) *filter; | |
10016 | struct syscall s; | |
10017 | struct gdbarch *gdbarch = get_current_arch (); | |
10018 | ||
10019 | /* Checking if the feature if supported. */ | |
10020 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10021 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10022 | this architecture yet.")); |
a96d9b2e SDJ |
10023 | |
10024 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10025 | ||
e9cafbcc | 10026 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10027 | |
10028 | /* We need to do this first "dummy" translation in order | |
10029 | to get the syscall XML file loaded or, most important, | |
10030 | to display a warning to the user if there's no XML file | |
10031 | for his/her architecture. */ | |
10032 | get_syscall_by_number (0, &s); | |
10033 | ||
10034 | /* The allowed syntax is: | |
10035 | catch syscall | |
10036 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10037 | ||
10038 | Let's check if there's a syscall name. */ | |
10039 | ||
10040 | if (arg != NULL) | |
10041 | filter = catch_syscall_split_args (arg); | |
10042 | else | |
10043 | filter = NULL; | |
10044 | ||
10045 | create_syscall_event_catchpoint (tempflag, filter, | |
10046 | &catch_syscall_breakpoint_ops); | |
10047 | } | |
10048 | ||
c906108c | 10049 | static void |
fba45db2 | 10050 | catch_command (char *arg, int from_tty) |
c906108c | 10051 | { |
44feb3ce | 10052 | error (_("Catch requires an event name.")); |
c906108c SS |
10053 | } |
10054 | \f | |
10055 | ||
10056 | static void | |
fba45db2 | 10057 | tcatch_command (char *arg, int from_tty) |
c906108c | 10058 | { |
44feb3ce | 10059 | error (_("Catch requires an event name.")); |
c906108c SS |
10060 | } |
10061 | ||
80f8a6eb | 10062 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10063 | |
10064 | static void | |
fba45db2 | 10065 | clear_command (char *arg, int from_tty) |
c906108c | 10066 | { |
d6e956e5 VP |
10067 | struct breakpoint *b; |
10068 | VEC(breakpoint_p) *found = 0; | |
10069 | int ix; | |
c906108c SS |
10070 | int default_match; |
10071 | struct symtabs_and_lines sals; | |
10072 | struct symtab_and_line sal; | |
c906108c SS |
10073 | int i; |
10074 | ||
10075 | if (arg) | |
10076 | { | |
10077 | sals = decode_line_spec (arg, 1); | |
10078 | default_match = 0; | |
10079 | } | |
10080 | else | |
10081 | { | |
c5aa993b | 10082 | sals.sals = (struct symtab_and_line *) |
c906108c | 10083 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10084 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10085 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
10086 | sal.line = default_breakpoint_line; |
10087 | sal.symtab = default_breakpoint_symtab; | |
10088 | sal.pc = default_breakpoint_address; | |
6c95b8df | 10089 | sal.pspace = default_breakpoint_pspace; |
c906108c | 10090 | if (sal.symtab == 0) |
8a3fe4f8 | 10091 | error (_("No source file specified.")); |
c906108c SS |
10092 | |
10093 | sals.sals[0] = sal; | |
10094 | sals.nelts = 1; | |
10095 | ||
10096 | default_match = 1; | |
10097 | } | |
10098 | ||
4a64f543 MS |
10099 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10100 | seems, because all existing breakpoints typically have both | |
10101 | file/line and pc set. So, if clear is given file/line, we can | |
10102 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10103 | |
10104 | We only support clearing given the address explicitly | |
10105 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10106 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10107 | due to optimization, all in one block. |
4a64f543 MS |
10108 | |
10109 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10110 | PC corresponding to the same file:line, the breakpoint won't |
10111 | be cleared. We probably can still clear the breakpoint, but | |
10112 | since the other PC value is never presented to user, user | |
10113 | can only find it by guessing, and it does not seem important | |
10114 | to support that. */ | |
10115 | ||
4a64f543 MS |
10116 | /* For each line spec given, delete bps which correspond to it. Do |
10117 | it in two passes, solely to preserve the current behavior that | |
10118 | from_tty is forced true if we delete more than one | |
10119 | breakpoint. */ | |
c906108c | 10120 | |
80f8a6eb | 10121 | found = NULL; |
c906108c SS |
10122 | for (i = 0; i < sals.nelts; i++) |
10123 | { | |
10124 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
10125 | If line given (pc == 0), clear all bpts on specified line. |
10126 | If defaulting, clear all bpts on default line | |
c906108c | 10127 | or at default pc. |
c5aa993b JM |
10128 | |
10129 | defaulting sal.pc != 0 tests to do | |
10130 | ||
10131 | 0 1 pc | |
10132 | 1 1 pc _and_ line | |
10133 | 0 0 line | |
10134 | 1 0 <can't happen> */ | |
c906108c SS |
10135 | |
10136 | sal = sals.sals[i]; | |
c906108c | 10137 | |
4a64f543 | 10138 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10139 | ALL_BREAKPOINTS (b) |
c5aa993b | 10140 | { |
0d381245 | 10141 | int match = 0; |
4a64f543 | 10142 | /* Are we going to delete b? */ |
cc60f2e3 | 10143 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10144 | { |
10145 | struct bp_location *loc = b->loc; | |
10146 | for (; loc; loc = loc->next) | |
10147 | { | |
6c95b8df PA |
10148 | int pc_match = sal.pc |
10149 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
10150 | && (loc->address == sal.pc) |
10151 | && (!section_is_overlay (loc->section) | |
10152 | || loc->section == sal.section); | |
10153 | int line_match = ((default_match || (0 == sal.pc)) | |
10154 | && b->source_file != NULL | |
10155 | && sal.symtab != NULL | |
6c95b8df | 10156 | && sal.pspace == loc->pspace |
0ba1096a KT |
10157 | && filename_cmp (b->source_file, |
10158 | sal.symtab->filename) == 0 | |
0d381245 VP |
10159 | && b->line_number == sal.line); |
10160 | if (pc_match || line_match) | |
10161 | { | |
10162 | match = 1; | |
10163 | break; | |
10164 | } | |
10165 | } | |
10166 | } | |
10167 | ||
10168 | if (match) | |
d6e956e5 | 10169 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10170 | } |
80f8a6eb MS |
10171 | } |
10172 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 10173 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10174 | { |
10175 | if (arg) | |
8a3fe4f8 | 10176 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10177 | else |
8a3fe4f8 | 10178 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10179 | } |
c906108c | 10180 | |
d6e956e5 | 10181 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10182 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10183 | if (from_tty) |
a3f17187 | 10184 | { |
d6e956e5 | 10185 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10186 | printf_unfiltered (_("Deleted breakpoint ")); |
10187 | else | |
10188 | printf_unfiltered (_("Deleted breakpoints ")); | |
10189 | } | |
80f8a6eb | 10190 | breakpoints_changed (); |
d6e956e5 VP |
10191 | |
10192 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10193 | { |
c5aa993b | 10194 | if (from_tty) |
d6e956e5 VP |
10195 | printf_unfiltered ("%d ", b->number); |
10196 | delete_breakpoint (b); | |
c906108c | 10197 | } |
80f8a6eb MS |
10198 | if (from_tty) |
10199 | putchar_unfiltered ('\n'); | |
c906108c SS |
10200 | } |
10201 | \f | |
10202 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10203 | all breakpoints that are marked for deletion, whether hit or not. | |
10204 | This is called after any breakpoint is hit, or after errors. */ | |
10205 | ||
10206 | void | |
fba45db2 | 10207 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10208 | { |
35df4500 | 10209 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10210 | |
10211 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10212 | if (bs->breakpoint_at |
10213 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10214 | && bs->stop) |
f431efe5 | 10215 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10216 | |
35df4500 | 10217 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10218 | { |
b5de0fa7 | 10219 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10220 | delete_breakpoint (b); |
10221 | } | |
c906108c SS |
10222 | } |
10223 | ||
4a64f543 MS |
10224 | /* A comparison function for bp_location AP and BP being interfaced to |
10225 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10226 | does breakpoint_address_is_meaningful say for its OWNER), | |
10227 | secondarily by ordering first bp_permanent OWNERed elements and | |
10228 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 10229 | qsort being an unstable algorithm. */ |
876fa593 JK |
10230 | |
10231 | static int | |
494cfb0f | 10232 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10233 | { |
494cfb0f JK |
10234 | struct bp_location *a = *(void **) ap; |
10235 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10236 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10237 | int a_perm = a->owner->enable_state == bp_permanent; |
10238 | int b_perm = b->owner->enable_state == bp_permanent; | |
10239 | ||
10240 | if (a->address != b->address) | |
10241 | return (a->address > b->address) - (a->address < b->address); | |
10242 | ||
10243 | /* Sort permanent breakpoints first. */ | |
10244 | if (a_perm != b_perm) | |
10245 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10246 | ||
4a64f543 MS |
10247 | /* Make the user-visible order stable across GDB runs. Locations of |
10248 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10249 | |
10250 | if (a->owner->number != b->owner->number) | |
10251 | return (a->owner->number > b->owner->number) | |
10252 | - (a->owner->number < b->owner->number); | |
10253 | ||
10254 | return (a > b) - (a < b); | |
10255 | } | |
10256 | ||
876fa593 | 10257 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10258 | bp_location_shadow_len_after_address_max according to the current |
10259 | content of the bp_location array. */ | |
f7545552 TT |
10260 | |
10261 | static void | |
876fa593 | 10262 | bp_location_target_extensions_update (void) |
f7545552 | 10263 | { |
876fa593 JK |
10264 | struct bp_location *bl, **blp_tmp; |
10265 | ||
10266 | bp_location_placed_address_before_address_max = 0; | |
10267 | bp_location_shadow_len_after_address_max = 0; | |
10268 | ||
10269 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10270 | { | |
10271 | CORE_ADDR start, end, addr; | |
10272 | ||
10273 | if (!bp_location_has_shadow (bl)) | |
10274 | continue; | |
10275 | ||
10276 | start = bl->target_info.placed_address; | |
10277 | end = start + bl->target_info.shadow_len; | |
10278 | ||
10279 | gdb_assert (bl->address >= start); | |
10280 | addr = bl->address - start; | |
10281 | if (addr > bp_location_placed_address_before_address_max) | |
10282 | bp_location_placed_address_before_address_max = addr; | |
10283 | ||
10284 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10285 | ||
10286 | gdb_assert (bl->address < end); | |
10287 | addr = end - bl->address; | |
10288 | if (addr > bp_location_shadow_len_after_address_max) | |
10289 | bp_location_shadow_len_after_address_max = addr; | |
10290 | } | |
f7545552 TT |
10291 | } |
10292 | ||
934709f0 PW |
10293 | /* Swap the insertion/duplication state between two locations. */ |
10294 | ||
10295 | static void | |
10296 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
10297 | { | |
10298 | const int left_inserted = left->inserted; | |
10299 | const int left_duplicate = left->duplicate; | |
10300 | const struct bp_target_info left_target_info = left->target_info; | |
10301 | ||
10302 | left->inserted = right->inserted; | |
10303 | left->duplicate = right->duplicate; | |
10304 | left->target_info = right->target_info; | |
10305 | right->inserted = left_inserted; | |
10306 | right->duplicate = left_duplicate; | |
10307 | right->target_info = left_target_info; | |
10308 | } | |
10309 | ||
4cd9bd08 | 10310 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10311 | into the inferior, only remove already-inserted locations that no |
10312 | longer should be inserted. Functions that delete a breakpoint or | |
10313 | breakpoints should pass false, so that deleting a breakpoint | |
10314 | doesn't have the side effect of inserting the locations of other | |
10315 | breakpoints that are marked not-inserted, but should_be_inserted | |
10316 | returns true on them. | |
10317 | ||
10318 | This behaviour is useful is situations close to tear-down -- e.g., | |
10319 | after an exec, while the target still has execution, but breakpoint | |
10320 | shadows of the previous executable image should *NOT* be restored | |
10321 | to the new image; or before detaching, where the target still has | |
10322 | execution and wants to delete breakpoints from GDB's lists, and all | |
10323 | breakpoints had already been removed from the inferior. */ | |
10324 | ||
0d381245 | 10325 | static void |
b60e7edf | 10326 | update_global_location_list (int should_insert) |
0d381245 | 10327 | { |
74960c60 | 10328 | struct breakpoint *b; |
876fa593 | 10329 | struct bp_location **locp, *loc; |
f7545552 TT |
10330 | struct cleanup *cleanups; |
10331 | ||
2d134ed3 PA |
10332 | /* Used in the duplicates detection below. When iterating over all |
10333 | bp_locations, points to the first bp_location of a given address. | |
10334 | Breakpoints and watchpoints of different types are never | |
10335 | duplicates of each other. Keep one pointer for each type of | |
10336 | breakpoint/watchpoint, so we only need to loop over all locations | |
10337 | once. */ | |
10338 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10339 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10340 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10341 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10342 | |
4a64f543 MS |
10343 | /* Saved former bp_location array which we compare against the newly |
10344 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10345 | struct bp_location **old_location, **old_locp; |
10346 | unsigned old_location_count; | |
10347 | ||
10348 | old_location = bp_location; | |
10349 | old_location_count = bp_location_count; | |
10350 | bp_location = NULL; | |
10351 | bp_location_count = 0; | |
10352 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10353 | |
74960c60 | 10354 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10355 | for (loc = b->loc; loc; loc = loc->next) |
10356 | bp_location_count++; | |
10357 | ||
10358 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10359 | locp = bp_location; | |
10360 | ALL_BREAKPOINTS (b) | |
10361 | for (loc = b->loc; loc; loc = loc->next) | |
10362 | *locp++ = loc; | |
10363 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10364 | bp_location_compare); |
876fa593 JK |
10365 | |
10366 | bp_location_target_extensions_update (); | |
74960c60 | 10367 | |
4a64f543 MS |
10368 | /* Identify bp_location instances that are no longer present in the |
10369 | new list, and therefore should be freed. Note that it's not | |
10370 | necessary that those locations should be removed from inferior -- | |
10371 | if there's another location at the same address (previously | |
10372 | marked as duplicate), we don't need to remove/insert the | |
10373 | location. | |
876fa593 | 10374 | |
4a64f543 MS |
10375 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10376 | and former bp_location array state respectively. */ | |
876fa593 JK |
10377 | |
10378 | locp = bp_location; | |
10379 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10380 | old_locp++) | |
74960c60 | 10381 | { |
876fa593 | 10382 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10383 | struct bp_location **loc2p; |
876fa593 | 10384 | |
e5dd4106 | 10385 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 10386 | not, we have to free it. */ |
c7d46a38 | 10387 | int found_object = 0; |
20874c92 VP |
10388 | /* Tells if the location should remain inserted in the target. */ |
10389 | int keep_in_target = 0; | |
10390 | int removed = 0; | |
876fa593 | 10391 | |
4a64f543 MS |
10392 | /* Skip LOCP entries which will definitely never be needed. |
10393 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10394 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10395 | && (*locp)->address < old_loc->address) |
876fa593 | 10396 | locp++; |
c7d46a38 PA |
10397 | |
10398 | for (loc2p = locp; | |
10399 | (loc2p < bp_location + bp_location_count | |
10400 | && (*loc2p)->address == old_loc->address); | |
10401 | loc2p++) | |
10402 | { | |
10403 | if (*loc2p == old_loc) | |
10404 | { | |
10405 | found_object = 1; | |
10406 | break; | |
10407 | } | |
10408 | } | |
74960c60 | 10409 | |
4a64f543 MS |
10410 | /* If this location is no longer present, and inserted, look if |
10411 | there's maybe a new location at the same address. If so, | |
10412 | mark that one inserted, and don't remove this one. This is | |
10413 | needed so that we don't have a time window where a breakpoint | |
10414 | at certain location is not inserted. */ | |
74960c60 | 10415 | |
876fa593 | 10416 | if (old_loc->inserted) |
0d381245 | 10417 | { |
4a64f543 MS |
10418 | /* If the location is inserted now, we might have to remove |
10419 | it. */ | |
74960c60 | 10420 | |
876fa593 | 10421 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10422 | { |
4a64f543 MS |
10423 | /* The location is still present in the location list, |
10424 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10425 | keep_in_target = 1; |
74960c60 VP |
10426 | } |
10427 | else | |
10428 | { | |
4a64f543 MS |
10429 | /* The location is either no longer present, or got |
10430 | disabled. See if there's another location at the | |
10431 | same address, in which case we don't need to remove | |
10432 | this one from the target. */ | |
876fa593 | 10433 | |
2bdf28a0 | 10434 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10435 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10436 | { | |
876fa593 | 10437 | for (loc2p = locp; |
c7d46a38 PA |
10438 | (loc2p < bp_location + bp_location_count |
10439 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10440 | loc2p++) |
10441 | { | |
10442 | struct bp_location *loc2 = *loc2p; | |
10443 | ||
2d134ed3 | 10444 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 10445 | { |
85d721b8 PA |
10446 | /* Read watchpoint locations are switched to |
10447 | access watchpoints, if the former are not | |
10448 | supported, but the latter are. */ | |
10449 | if (is_hardware_watchpoint (old_loc->owner)) | |
10450 | { | |
10451 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10452 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10453 | } | |
10454 | ||
934709f0 PW |
10455 | /* loc2 is a duplicated location. We need to check |
10456 | if it should be inserted in case it will be | |
10457 | unduplicated. */ | |
10458 | if (loc2 != old_loc | |
10459 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 10460 | { |
934709f0 | 10461 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
10462 | keep_in_target = 1; |
10463 | break; | |
10464 | } | |
876fa593 JK |
10465 | } |
10466 | } | |
10467 | } | |
74960c60 VP |
10468 | } |
10469 | ||
20874c92 VP |
10470 | if (!keep_in_target) |
10471 | { | |
876fa593 | 10472 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10473 | { |
4a64f543 MS |
10474 | /* This is just about all we can do. We could keep |
10475 | this location on the global list, and try to | |
10476 | remove it next time, but there's no particular | |
10477 | reason why we will succeed next time. | |
20874c92 | 10478 | |
4a64f543 MS |
10479 | Note that at this point, old_loc->owner is still |
10480 | valid, as delete_breakpoint frees the breakpoint | |
10481 | only after calling us. */ | |
3e43a32a MS |
10482 | printf_filtered (_("warning: Error removing " |
10483 | "breakpoint %d\n"), | |
876fa593 | 10484 | old_loc->owner->number); |
20874c92 VP |
10485 | } |
10486 | removed = 1; | |
10487 | } | |
0d381245 | 10488 | } |
74960c60 VP |
10489 | |
10490 | if (!found_object) | |
1c5cfe86 | 10491 | { |
db82e815 PA |
10492 | if (removed && non_stop |
10493 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10494 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10495 | { |
db82e815 PA |
10496 | /* This location was removed from the target. In |
10497 | non-stop mode, a race condition is possible where | |
10498 | we've removed a breakpoint, but stop events for that | |
10499 | breakpoint are already queued and will arrive later. | |
10500 | We apply an heuristic to be able to distinguish such | |
10501 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10502 | breakpoint location for a bit, and will retire it | |
10503 | after we see some number of events. The theory here | |
10504 | is that reporting of events should, "on the average", | |
10505 | be fair, so after a while we'll see events from all | |
10506 | threads that have anything of interest, and no longer | |
10507 | need to keep this breakpoint location around. We | |
10508 | don't hold locations forever so to reduce chances of | |
10509 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10510 | SIGTRAP. | |
10511 | ||
10512 | The heuristic failing can be disastrous on | |
10513 | decr_pc_after_break targets. | |
10514 | ||
10515 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10516 | if we fail to recognize a late breakpoint SIGTRAP, | |
10517 | because events_till_retirement has reached 0 too | |
10518 | soon, we'll fail to do the PC adjustment, and report | |
10519 | a random SIGTRAP to the user. When the user resumes | |
10520 | the inferior, it will most likely immediately crash | |
2dec564e | 10521 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10522 | corrupted, because of being resumed e.g., in the |
10523 | middle of a multi-byte instruction, or skipped a | |
10524 | one-byte instruction. This was actually seen happen | |
10525 | on native x86-linux, and should be less rare on | |
10526 | targets that do not support new thread events, like | |
10527 | remote, due to the heuristic depending on | |
10528 | thread_count. | |
10529 | ||
10530 | Mistaking a random SIGTRAP for a breakpoint trap | |
10531 | causes similar symptoms (PC adjustment applied when | |
10532 | it shouldn't), but then again, playing with SIGTRAPs | |
10533 | behind the debugger's back is asking for trouble. | |
10534 | ||
10535 | Since hardware watchpoint traps are always | |
10536 | distinguishable from other traps, so we don't need to | |
10537 | apply keep hardware watchpoint moribund locations | |
10538 | around. We simply always ignore hardware watchpoint | |
10539 | traps we can no longer explain. */ | |
10540 | ||
876fa593 JK |
10541 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10542 | old_loc->owner = NULL; | |
20874c92 | 10543 | |
876fa593 | 10544 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10545 | } |
10546 | else | |
f431efe5 PA |
10547 | { |
10548 | old_loc->owner = NULL; | |
10549 | decref_bp_location (&old_loc); | |
10550 | } | |
20874c92 | 10551 | } |
74960c60 | 10552 | } |
1c5cfe86 | 10553 | |
348d480f PA |
10554 | /* Rescan breakpoints at the same address and section, marking the |
10555 | first one as "first" and any others as "duplicates". This is so | |
10556 | that the bpt instruction is only inserted once. If we have a | |
10557 | permanent breakpoint at the same place as BPT, make that one the | |
10558 | official one, and the rest as duplicates. Permanent breakpoints | |
10559 | are sorted first for the same address. | |
10560 | ||
10561 | Do the same for hardware watchpoints, but also considering the | |
10562 | watchpoint's type (regular/access/read) and length. */ | |
10563 | ||
10564 | bp_loc_first = NULL; | |
10565 | wp_loc_first = NULL; | |
10566 | awp_loc_first = NULL; | |
10567 | rwp_loc_first = NULL; | |
10568 | ALL_BP_LOCATIONS (loc, locp) | |
10569 | { | |
10570 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
10571 | non-NULL. */ | |
10572 | struct breakpoint *b = loc->owner; | |
10573 | struct bp_location **loc_first_p; | |
10574 | ||
10575 | if (b->enable_state == bp_disabled | |
10576 | || b->enable_state == bp_call_disabled | |
10577 | || b->enable_state == bp_startup_disabled | |
10578 | || !loc->enabled | |
10579 | || loc->shlib_disabled | |
10580 | || !breakpoint_address_is_meaningful (b) | |
10581 | || is_tracepoint (b)) | |
10582 | continue; | |
10583 | ||
10584 | /* Permanent breakpoint should always be inserted. */ | |
10585 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10586 | internal_error (__FILE__, __LINE__, | |
10587 | _("allegedly permanent breakpoint is not " | |
10588 | "actually inserted")); | |
10589 | ||
10590 | if (b->type == bp_hardware_watchpoint) | |
10591 | loc_first_p = &wp_loc_first; | |
10592 | else if (b->type == bp_read_watchpoint) | |
10593 | loc_first_p = &rwp_loc_first; | |
10594 | else if (b->type == bp_access_watchpoint) | |
10595 | loc_first_p = &awp_loc_first; | |
10596 | else | |
10597 | loc_first_p = &bp_loc_first; | |
10598 | ||
10599 | if (*loc_first_p == NULL | |
10600 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10601 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
10602 | { | |
10603 | *loc_first_p = loc; | |
10604 | loc->duplicate = 0; | |
10605 | continue; | |
10606 | } | |
10607 | ||
934709f0 PW |
10608 | |
10609 | /* This and the above ensure the invariant that the first location | |
10610 | is not duplicated, and is the inserted one. | |
10611 | All following are marked as duplicated, and are not inserted. */ | |
10612 | if (loc->inserted) | |
10613 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
10614 | loc->duplicate = 1; |
10615 | ||
10616 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted | |
10617 | && b->enable_state != bp_permanent) | |
10618 | internal_error (__FILE__, __LINE__, | |
10619 | _("another breakpoint was inserted on top of " | |
10620 | "a permanent breakpoint")); | |
10621 | } | |
10622 | ||
10623 | if (breakpoints_always_inserted_mode () && should_insert | |
10624 | && (have_live_inferiors () | |
10625 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
10626 | insert_breakpoint_locations (); | |
10627 | ||
10628 | do_cleanups (cleanups); | |
10629 | } | |
10630 | ||
10631 | void | |
10632 | breakpoint_retire_moribund (void) | |
10633 | { | |
10634 | struct bp_location *loc; | |
10635 | int ix; | |
10636 | ||
10637 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10638 | if (--(loc->events_till_retirement) == 0) | |
10639 | { | |
10640 | decref_bp_location (&loc); | |
10641 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
10642 | --ix; | |
10643 | } | |
10644 | } | |
10645 | ||
10646 | static void | |
10647 | update_global_location_list_nothrow (int inserting) | |
10648 | { | |
10649 | struct gdb_exception e; | |
10650 | ||
10651 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10652 | update_global_location_list (inserting); | |
10653 | } | |
10654 | ||
10655 | /* Clear BKP from a BPS. */ | |
10656 | ||
10657 | static void | |
10658 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
10659 | { | |
10660 | bpstat bs; | |
10661 | ||
10662 | for (bs = bps; bs; bs = bs->next) | |
10663 | if (bs->breakpoint_at == bpt) | |
10664 | { | |
10665 | bs->breakpoint_at = NULL; | |
10666 | bs->old_val = NULL; | |
10667 | /* bs->commands will be freed later. */ | |
10668 | } | |
10669 | } | |
10670 | ||
10671 | /* Callback for iterate_over_threads. */ | |
10672 | static int | |
10673 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
10674 | { | |
10675 | struct breakpoint *bpt = data; | |
10676 | ||
10677 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
10678 | return 0; | |
10679 | } | |
10680 | ||
10681 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
10682 | callbacks. */ | |
10683 | ||
10684 | static void | |
10685 | say_where (struct breakpoint *b) | |
10686 | { | |
79a45e25 | 10687 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10688 | struct value_print_options opts; |
10689 | ||
10690 | get_user_print_options (&opts); | |
10691 | ||
10692 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
10693 | single string. */ | |
10694 | if (b->loc == NULL) | |
10695 | { | |
10696 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
10697 | } | |
10698 | else | |
10699 | { | |
10700 | if (opts.addressprint || b->source_file == NULL) | |
10701 | { | |
10702 | printf_filtered (" at "); | |
10703 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
10704 | gdb_stdout); | |
10705 | } | |
10706 | if (b->source_file) | |
10707 | printf_filtered (": file %s, line %d.", | |
10708 | b->source_file, b->line_number); | |
10709 | ||
10710 | if (b->loc->next) | |
10711 | { | |
10712 | struct bp_location *loc = b->loc; | |
10713 | int n = 0; | |
10714 | for (; loc; loc = loc->next) | |
10715 | ++n; | |
10716 | printf_filtered (" (%d locations)", n); | |
10717 | } | |
10718 | } | |
10719 | } | |
10720 | ||
348d480f PA |
10721 | /* Default bp_location_ops methods. */ |
10722 | ||
10723 | static void | |
10724 | bp_location_dtor (struct bp_location *self) | |
10725 | { | |
10726 | xfree (self->cond); | |
10727 | xfree (self->function_name); | |
10728 | } | |
10729 | ||
10730 | static const struct bp_location_ops bp_location_ops = | |
10731 | { | |
10732 | bp_location_dtor | |
10733 | }; | |
10734 | ||
2060206e PA |
10735 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
10736 | inherit from. */ | |
348d480f | 10737 | |
2060206e PA |
10738 | static void |
10739 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
10740 | { |
10741 | decref_counted_command_line (&self->commands); | |
10742 | xfree (self->cond_string); | |
348d480f PA |
10743 | xfree (self->addr_string); |
10744 | xfree (self->addr_string_range_end); | |
348d480f PA |
10745 | xfree (self->source_file); |
10746 | } | |
10747 | ||
2060206e PA |
10748 | static struct bp_location * |
10749 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
10750 | { |
10751 | struct bp_location *loc; | |
10752 | ||
10753 | loc = XNEW (struct bp_location); | |
10754 | init_bp_location (loc, &bp_location_ops, self); | |
10755 | return loc; | |
10756 | } | |
10757 | ||
2060206e PA |
10758 | static void |
10759 | base_breakpoint_re_set (struct breakpoint *b) | |
10760 | { | |
10761 | /* Nothing to re-set. */ | |
10762 | } | |
10763 | ||
10764 | #define internal_error_pure_virtual_called() \ | |
10765 | gdb_assert_not_reached ("pure virtual function called") | |
10766 | ||
10767 | static int | |
10768 | base_breakpoint_insert_location (struct bp_location *bl) | |
10769 | { | |
10770 | internal_error_pure_virtual_called (); | |
10771 | } | |
10772 | ||
10773 | static int | |
10774 | base_breakpoint_remove_location (struct bp_location *bl) | |
10775 | { | |
10776 | internal_error_pure_virtual_called (); | |
10777 | } | |
10778 | ||
10779 | static int | |
10780 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
10781 | struct address_space *aspace, | |
10782 | CORE_ADDR bp_addr) | |
10783 | { | |
10784 | internal_error_pure_virtual_called (); | |
10785 | } | |
10786 | ||
10787 | static void | |
10788 | base_breakpoint_check_status (bpstat bs) | |
10789 | { | |
10790 | /* Always stop. */ | |
10791 | } | |
10792 | ||
10793 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
10794 | errors. */ | |
10795 | ||
10796 | static int | |
10797 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
10798 | { | |
10799 | internal_error_pure_virtual_called (); | |
10800 | } | |
10801 | ||
10802 | /* A "resources_needed" breakpoint_ops method that just internal | |
10803 | errors. */ | |
10804 | ||
10805 | static int | |
10806 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
10807 | { | |
10808 | internal_error_pure_virtual_called (); | |
10809 | } | |
10810 | ||
10811 | static enum print_stop_action | |
10812 | base_breakpoint_print_it (bpstat bs) | |
10813 | { | |
10814 | internal_error_pure_virtual_called (); | |
10815 | } | |
10816 | ||
10817 | static void | |
10818 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
10819 | struct ui_out *uiout) | |
10820 | { | |
10821 | /* nothing */ | |
10822 | } | |
10823 | ||
10824 | static void | |
10825 | base_breakpoint_print_mention (struct breakpoint *b) | |
10826 | { | |
10827 | internal_error_pure_virtual_called (); | |
10828 | } | |
10829 | ||
10830 | static void | |
10831 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
10832 | { | |
10833 | internal_error_pure_virtual_called (); | |
10834 | } | |
10835 | ||
10836 | static struct breakpoint_ops base_breakpoint_ops = | |
10837 | { | |
10838 | base_breakpoint_dtor, | |
10839 | base_breakpoint_allocate_location, | |
10840 | base_breakpoint_re_set, | |
10841 | base_breakpoint_insert_location, | |
10842 | base_breakpoint_remove_location, | |
10843 | base_breakpoint_breakpoint_hit, | |
10844 | base_breakpoint_check_status, | |
10845 | base_breakpoint_resources_needed, | |
10846 | base_breakpoint_works_in_software_mode, | |
10847 | base_breakpoint_print_it, | |
10848 | NULL, | |
10849 | base_breakpoint_print_one_detail, | |
10850 | base_breakpoint_print_mention, | |
10851 | base_breakpoint_print_recreate | |
10852 | }; | |
10853 | ||
10854 | /* Default breakpoint_ops methods. */ | |
10855 | ||
10856 | static void | |
348d480f PA |
10857 | bkpt_re_set (struct breakpoint *b) |
10858 | { | |
06edf0c0 PA |
10859 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10860 | if (b->enable_state == bp_startup_disabled) | |
10861 | return; | |
348d480f | 10862 | |
06edf0c0 PA |
10863 | /* FIXME: is this still reachable? */ |
10864 | if (b->addr_string == NULL) | |
10865 | { | |
10866 | /* Anything without a string can't be re-set. */ | |
348d480f | 10867 | delete_breakpoint (b); |
06edf0c0 | 10868 | return; |
348d480f | 10869 | } |
06edf0c0 PA |
10870 | |
10871 | breakpoint_re_set_default (b); | |
348d480f PA |
10872 | } |
10873 | ||
2060206e | 10874 | static int |
348d480f PA |
10875 | bkpt_insert_location (struct bp_location *bl) |
10876 | { | |
10877 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10878 | return target_insert_hw_breakpoint (bl->gdbarch, | |
10879 | &bl->target_info); | |
10880 | else | |
10881 | return target_insert_breakpoint (bl->gdbarch, | |
10882 | &bl->target_info); | |
10883 | } | |
10884 | ||
2060206e | 10885 | static int |
348d480f PA |
10886 | bkpt_remove_location (struct bp_location *bl) |
10887 | { | |
10888 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10889 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
10890 | else | |
10891 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
10892 | } | |
10893 | ||
2060206e | 10894 | static int |
348d480f PA |
10895 | bkpt_breakpoint_hit (const struct bp_location *bl, |
10896 | struct address_space *aspace, CORE_ADDR bp_addr) | |
10897 | { | |
10898 | struct breakpoint *b = bl->owner; | |
10899 | ||
10900 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, | |
10901 | aspace, bp_addr)) | |
10902 | return 0; | |
10903 | ||
10904 | if (overlay_debugging /* unmapped overlay section */ | |
10905 | && section_is_overlay (bl->section) | |
10906 | && !section_is_mapped (bl->section)) | |
10907 | return 0; | |
10908 | ||
10909 | return 1; | |
10910 | } | |
10911 | ||
2060206e | 10912 | static int |
348d480f PA |
10913 | bkpt_resources_needed (const struct bp_location *bl) |
10914 | { | |
10915 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
10916 | ||
10917 | return 1; | |
10918 | } | |
10919 | ||
2060206e | 10920 | static enum print_stop_action |
348d480f PA |
10921 | bkpt_print_it (bpstat bs) |
10922 | { | |
348d480f PA |
10923 | struct breakpoint *b; |
10924 | const struct bp_location *bl; | |
001c8c33 | 10925 | int bp_temp; |
79a45e25 | 10926 | struct ui_out *uiout = current_uiout; |
348d480f PA |
10927 | |
10928 | gdb_assert (bs->bp_location_at != NULL); | |
10929 | ||
10930 | bl = bs->bp_location_at; | |
10931 | b = bs->breakpoint_at; | |
10932 | ||
001c8c33 PA |
10933 | bp_temp = b->disposition == disp_del; |
10934 | if (bl->address != bl->requested_address) | |
10935 | breakpoint_adjustment_warning (bl->requested_address, | |
10936 | bl->address, | |
10937 | b->number, 1); | |
10938 | annotate_breakpoint (b->number); | |
10939 | if (bp_temp) | |
10940 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
10941 | else | |
10942 | ui_out_text (uiout, "\nBreakpoint "); | |
10943 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 10944 | { |
001c8c33 PA |
10945 | ui_out_field_string (uiout, "reason", |
10946 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10947 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 10948 | } |
001c8c33 PA |
10949 | ui_out_field_int (uiout, "bkptno", b->number); |
10950 | ui_out_text (uiout, ", "); | |
06edf0c0 | 10951 | |
001c8c33 | 10952 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
10953 | } |
10954 | ||
2060206e | 10955 | static void |
06edf0c0 PA |
10956 | bkpt_print_mention (struct breakpoint *b) |
10957 | { | |
79a45e25 | 10958 | if (ui_out_is_mi_like_p (current_uiout)) |
06edf0c0 PA |
10959 | return; |
10960 | ||
10961 | switch (b->type) | |
10962 | { | |
10963 | case bp_breakpoint: | |
10964 | case bp_gnu_ifunc_resolver: | |
10965 | if (b->disposition == disp_del) | |
10966 | printf_filtered (_("Temporary breakpoint")); | |
10967 | else | |
10968 | printf_filtered (_("Breakpoint")); | |
10969 | printf_filtered (_(" %d"), b->number); | |
10970 | if (b->type == bp_gnu_ifunc_resolver) | |
10971 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
10972 | break; | |
10973 | case bp_hardware_breakpoint: | |
10974 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
10975 | break; | |
10976 | } | |
10977 | ||
10978 | say_where (b); | |
10979 | } | |
10980 | ||
2060206e | 10981 | static void |
06edf0c0 PA |
10982 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
10983 | { | |
10984 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
10985 | fprintf_unfiltered (fp, "tbreak"); | |
10986 | else if (tp->type == bp_breakpoint) | |
10987 | fprintf_unfiltered (fp, "break"); | |
10988 | else if (tp->type == bp_hardware_breakpoint | |
10989 | && tp->disposition == disp_del) | |
10990 | fprintf_unfiltered (fp, "thbreak"); | |
10991 | else if (tp->type == bp_hardware_breakpoint) | |
10992 | fprintf_unfiltered (fp, "hbreak"); | |
10993 | else | |
10994 | internal_error (__FILE__, __LINE__, | |
10995 | _("unhandled breakpoint type %d"), (int) tp->type); | |
10996 | ||
2060206e | 10997 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
06edf0c0 PA |
10998 | } |
10999 | ||
06edf0c0 PA |
11000 | /* Virtual table for internal breakpoints. */ |
11001 | ||
11002 | static void | |
11003 | internal_bkpt_re_set (struct breakpoint *b) | |
11004 | { | |
11005 | switch (b->type) | |
11006 | { | |
11007 | /* Delete overlay event and longjmp master breakpoints; they | |
11008 | will be reset later by breakpoint_re_set. */ | |
11009 | case bp_overlay_event: | |
11010 | case bp_longjmp_master: | |
11011 | case bp_std_terminate_master: | |
11012 | case bp_exception_master: | |
11013 | delete_breakpoint (b); | |
11014 | break; | |
11015 | ||
11016 | /* This breakpoint is special, it's set up when the inferior | |
11017 | starts and we really don't want to touch it. */ | |
11018 | case bp_shlib_event: | |
11019 | ||
11020 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
11021 | it is set up, we do not want to touch it. */ | |
11022 | case bp_thread_event: | |
11023 | break; | |
11024 | } | |
11025 | } | |
11026 | ||
11027 | static void | |
11028 | internal_bkpt_check_status (bpstat bs) | |
11029 | { | |
11030 | /* We do not stop for these. */ | |
11031 | bs->stop = 0; | |
11032 | } | |
11033 | ||
11034 | static enum print_stop_action | |
11035 | internal_bkpt_print_it (bpstat bs) | |
11036 | { | |
06edf0c0 | 11037 | struct breakpoint *b; |
06edf0c0 | 11038 | |
06edf0c0 PA |
11039 | b = bs->breakpoint_at; |
11040 | ||
06edf0c0 PA |
11041 | switch (b->type) |
11042 | { | |
348d480f PA |
11043 | case bp_shlib_event: |
11044 | /* Did we stop because the user set the stop_on_solib_events | |
11045 | variable? (If so, we report this as a generic, "Stopped due | |
11046 | to shlib event" message.) */ | |
11047 | printf_filtered (_("Stopped due to shared library event\n")); | |
348d480f PA |
11048 | break; |
11049 | ||
11050 | case bp_thread_event: | |
11051 | /* Not sure how we will get here. | |
11052 | GDB should not stop for these breakpoints. */ | |
11053 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11054 | break; |
11055 | ||
11056 | case bp_overlay_event: | |
11057 | /* By analogy with the thread event, GDB should not stop for these. */ | |
11058 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11059 | break; |
11060 | ||
11061 | case bp_longjmp_master: | |
11062 | /* These should never be enabled. */ | |
11063 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11064 | break; |
11065 | ||
11066 | case bp_std_terminate_master: | |
11067 | /* These should never be enabled. */ | |
11068 | printf_filtered (_("std::terminate Master Breakpoint: " | |
11069 | "gdb should not stop!\n")); | |
348d480f PA |
11070 | break; |
11071 | ||
11072 | case bp_exception_master: | |
11073 | /* These should never be enabled. */ | |
11074 | printf_filtered (_("Exception Master Breakpoint: " | |
11075 | "gdb should not stop!\n")); | |
06edf0c0 PA |
11076 | break; |
11077 | } | |
11078 | ||
001c8c33 | 11079 | return PRINT_NOTHING; |
06edf0c0 PA |
11080 | } |
11081 | ||
11082 | static void | |
11083 | internal_bkpt_print_mention (struct breakpoint *b) | |
11084 | { | |
11085 | /* Nothing to mention. These breakpoints are internal. */ | |
11086 | } | |
11087 | ||
06edf0c0 PA |
11088 | /* Virtual table for momentary breakpoints */ |
11089 | ||
11090 | static void | |
11091 | momentary_bkpt_re_set (struct breakpoint *b) | |
11092 | { | |
11093 | /* Keep temporary breakpoints, which can be encountered when we step | |
11094 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
11095 | Otherwise these should have been blown away via the cleanup chain | |
11096 | or by breakpoint_init_inferior when we rerun the executable. */ | |
11097 | } | |
11098 | ||
11099 | static void | |
11100 | momentary_bkpt_check_status (bpstat bs) | |
11101 | { | |
11102 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
11103 | } | |
11104 | ||
11105 | static enum print_stop_action | |
11106 | momentary_bkpt_print_it (bpstat bs) | |
11107 | { | |
79a45e25 PA |
11108 | struct ui_out *uiout = current_uiout; |
11109 | ||
001c8c33 | 11110 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 11111 | { |
001c8c33 | 11112 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 11113 | |
001c8c33 PA |
11114 | switch (b->type) |
11115 | { | |
11116 | case bp_finish: | |
11117 | ui_out_field_string | |
11118 | (uiout, "reason", | |
11119 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
11120 | break; | |
348d480f | 11121 | |
001c8c33 PA |
11122 | case bp_until: |
11123 | ui_out_field_string | |
11124 | (uiout, "reason", | |
11125 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
11126 | break; | |
11127 | } | |
348d480f PA |
11128 | } |
11129 | ||
001c8c33 | 11130 | return PRINT_UNKNOWN; |
348d480f PA |
11131 | } |
11132 | ||
06edf0c0 PA |
11133 | static void |
11134 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 11135 | { |
06edf0c0 | 11136 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
11137 | } |
11138 | ||
348d480f | 11139 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 11140 | |
348d480f PA |
11141 | static void |
11142 | tracepoint_re_set (struct breakpoint *b) | |
11143 | { | |
11144 | breakpoint_re_set_default (b); | |
11145 | } | |
876fa593 | 11146 | |
348d480f PA |
11147 | static int |
11148 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
11149 | struct address_space *aspace, CORE_ADDR bp_addr) | |
11150 | { | |
11151 | /* By definition, the inferior does not report stops at | |
11152 | tracepoints. */ | |
11153 | return 0; | |
74960c60 VP |
11154 | } |
11155 | ||
11156 | static void | |
348d480f PA |
11157 | tracepoint_print_one_detail (const struct breakpoint *self, |
11158 | struct ui_out *uiout) | |
74960c60 | 11159 | { |
d9b3f62e PA |
11160 | struct tracepoint *tp = (struct tracepoint *) self; |
11161 | if (tp->static_trace_marker_id) | |
348d480f PA |
11162 | { |
11163 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 11164 | |
348d480f PA |
11165 | ui_out_text (uiout, "\tmarker id is "); |
11166 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 11167 | tp->static_trace_marker_id); |
348d480f PA |
11168 | ui_out_text (uiout, "\n"); |
11169 | } | |
0d381245 VP |
11170 | } |
11171 | ||
a474d7c2 | 11172 | static void |
348d480f | 11173 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 11174 | { |
79a45e25 | 11175 | if (ui_out_is_mi_like_p (current_uiout)) |
348d480f | 11176 | return; |
cc59ec59 | 11177 | |
348d480f PA |
11178 | switch (b->type) |
11179 | { | |
11180 | case bp_tracepoint: | |
11181 | printf_filtered (_("Tracepoint")); | |
11182 | printf_filtered (_(" %d"), b->number); | |
11183 | break; | |
11184 | case bp_fast_tracepoint: | |
11185 | printf_filtered (_("Fast tracepoint")); | |
11186 | printf_filtered (_(" %d"), b->number); | |
11187 | break; | |
11188 | case bp_static_tracepoint: | |
11189 | printf_filtered (_("Static tracepoint")); | |
11190 | printf_filtered (_(" %d"), b->number); | |
11191 | break; | |
11192 | default: | |
11193 | internal_error (__FILE__, __LINE__, | |
11194 | _("unhandled tracepoint type %d"), (int) b->type); | |
11195 | } | |
11196 | ||
11197 | say_where (b); | |
a474d7c2 PA |
11198 | } |
11199 | ||
348d480f | 11200 | static void |
d9b3f62e | 11201 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 11202 | { |
d9b3f62e PA |
11203 | struct tracepoint *tp = (struct tracepoint *) self; |
11204 | ||
11205 | if (self->type == bp_fast_tracepoint) | |
348d480f | 11206 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 11207 | if (self->type == bp_static_tracepoint) |
348d480f | 11208 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 11209 | else if (self->type == bp_tracepoint) |
348d480f PA |
11210 | fprintf_unfiltered (fp, "trace"); |
11211 | else | |
11212 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 11213 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 11214 | |
d9b3f62e PA |
11215 | fprintf_unfiltered (fp, " %s", self->addr_string); |
11216 | print_recreate_thread (self, fp); | |
11217 | ||
11218 | if (tp->pass_count) | |
11219 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
11220 | } |
11221 | ||
2060206e | 11222 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 11223 | |
53a5351d | 11224 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 11225 | structures. */ |
c906108c SS |
11226 | |
11227 | void | |
fba45db2 | 11228 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 11229 | { |
52f0bd74 | 11230 | struct breakpoint *b; |
c906108c | 11231 | |
8a3fe4f8 | 11232 | gdb_assert (bpt != NULL); |
c906108c | 11233 | |
4a64f543 MS |
11234 | /* Has this bp already been deleted? This can happen because |
11235 | multiple lists can hold pointers to bp's. bpstat lists are | |
11236 | especial culprits. | |
11237 | ||
11238 | One example of this happening is a watchpoint's scope bp. When | |
11239 | the scope bp triggers, we notice that the watchpoint is out of | |
11240 | scope, and delete it. We also delete its scope bp. But the | |
11241 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
11242 | That bpstat is then checked for auto-deleting bp's, which are | |
11243 | deleted. | |
11244 | ||
11245 | A real solution to this problem might involve reference counts in | |
11246 | bp's, and/or giving them pointers back to their referencing | |
11247 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
11248 | storage when no more references were extent. A cheaper bandaid | |
11249 | was chosen. */ | |
c906108c SS |
11250 | if (bpt->type == bp_none) |
11251 | return; | |
11252 | ||
4a64f543 MS |
11253 | /* At least avoid this stale reference until the reference counting |
11254 | of breakpoints gets resolved. */ | |
d0fb5eae | 11255 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 11256 | { |
d0fb5eae | 11257 | struct breakpoint *related; |
3a5c3e22 | 11258 | struct watchpoint *w; |
d0fb5eae JK |
11259 | |
11260 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 11261 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 11262 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
11263 | w = (struct watchpoint *) bpt; |
11264 | else | |
11265 | w = NULL; | |
11266 | if (w != NULL) | |
11267 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
11268 | |
11269 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
11270 | for (related = bpt; related->related_breakpoint != bpt; | |
11271 | related = related->related_breakpoint); | |
11272 | related->related_breakpoint = bpt->related_breakpoint; | |
11273 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
11274 | } |
11275 | ||
a9634178 TJB |
11276 | /* watch_command_1 creates a watchpoint but only sets its number if |
11277 | update_watchpoint succeeds in creating its bp_locations. If there's | |
11278 | a problem in that process, we'll be asked to delete the half-created | |
11279 | watchpoint. In that case, don't announce the deletion. */ | |
11280 | if (bpt->number) | |
11281 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 11282 | |
c906108c SS |
11283 | if (breakpoint_chain == bpt) |
11284 | breakpoint_chain = bpt->next; | |
11285 | ||
c906108c SS |
11286 | ALL_BREAKPOINTS (b) |
11287 | if (b->next == bpt) | |
c5aa993b JM |
11288 | { |
11289 | b->next = bpt->next; | |
11290 | break; | |
11291 | } | |
c906108c | 11292 | |
f431efe5 PA |
11293 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
11294 | been freed. */ | |
11295 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 11296 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
11297 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
11298 | commands are associated with the bpstat; if we remove it here, | |
11299 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
11300 | event-top.c won't do anything, and temporary breakpoints with | |
11301 | commands won't work. */ | |
11302 | ||
11303 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
11304 | ||
4a64f543 MS |
11305 | /* Now that breakpoint is removed from breakpoint list, update the |
11306 | global location list. This will remove locations that used to | |
11307 | belong to this breakpoint. Do this before freeing the breakpoint | |
11308 | itself, since remove_breakpoint looks at location's owner. It | |
11309 | might be better design to have location completely | |
11310 | self-contained, but it's not the case now. */ | |
b60e7edf | 11311 | update_global_location_list (0); |
74960c60 | 11312 | |
348d480f | 11313 | bpt->ops->dtor (bpt); |
4a64f543 MS |
11314 | /* On the chance that someone will soon try again to delete this |
11315 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 11316 | bpt->type = bp_none; |
b8c9b27d | 11317 | xfree (bpt); |
c906108c SS |
11318 | } |
11319 | ||
4d6140d9 AC |
11320 | static void |
11321 | do_delete_breakpoint_cleanup (void *b) | |
11322 | { | |
11323 | delete_breakpoint (b); | |
11324 | } | |
11325 | ||
11326 | struct cleanup * | |
11327 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
11328 | { | |
11329 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
11330 | } | |
11331 | ||
51be5b68 PA |
11332 | /* Iterator function to call a user-provided callback function once |
11333 | for each of B and its related breakpoints. */ | |
11334 | ||
11335 | static void | |
11336 | iterate_over_related_breakpoints (struct breakpoint *b, | |
11337 | void (*function) (struct breakpoint *, | |
11338 | void *), | |
11339 | void *data) | |
11340 | { | |
11341 | struct breakpoint *related; | |
11342 | ||
11343 | related = b; | |
11344 | do | |
11345 | { | |
11346 | struct breakpoint *next; | |
11347 | ||
11348 | /* FUNCTION may delete RELATED. */ | |
11349 | next = related->related_breakpoint; | |
11350 | ||
11351 | if (next == related) | |
11352 | { | |
11353 | /* RELATED is the last ring entry. */ | |
11354 | function (related, data); | |
11355 | ||
11356 | /* FUNCTION may have deleted it, so we'd never reach back to | |
11357 | B. There's nothing left to do anyway, so just break | |
11358 | out. */ | |
11359 | break; | |
11360 | } | |
11361 | else | |
11362 | function (related, data); | |
11363 | ||
11364 | related = next; | |
11365 | } | |
11366 | while (related != b); | |
11367 | } | |
95a42b64 TT |
11368 | |
11369 | static void | |
11370 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11371 | { | |
11372 | delete_breakpoint (b); | |
11373 | } | |
11374 | ||
51be5b68 PA |
11375 | /* A callback for map_breakpoint_numbers that calls |
11376 | delete_breakpoint. */ | |
11377 | ||
11378 | static void | |
11379 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11380 | { | |
11381 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
11382 | } | |
11383 | ||
c906108c | 11384 | void |
fba45db2 | 11385 | delete_command (char *arg, int from_tty) |
c906108c | 11386 | { |
35df4500 | 11387 | struct breakpoint *b, *b_tmp; |
c906108c | 11388 | |
ea9365bb TT |
11389 | dont_repeat (); |
11390 | ||
c906108c SS |
11391 | if (arg == 0) |
11392 | { | |
11393 | int breaks_to_delete = 0; | |
11394 | ||
46c6471b PA |
11395 | /* Delete all breakpoints if no argument. Do not delete |
11396 | internal breakpoints, these have to be deleted with an | |
11397 | explicit breakpoint number argument. */ | |
c5aa993b | 11398 | ALL_BREAKPOINTS (b) |
46c6471b | 11399 | if (user_breakpoint_p (b)) |
973d738b DJ |
11400 | { |
11401 | breaks_to_delete = 1; | |
11402 | break; | |
11403 | } | |
c906108c SS |
11404 | |
11405 | /* Ask user only if there are some breakpoints to delete. */ | |
11406 | if (!from_tty | |
e2e0b3e5 | 11407 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 11408 | { |
35df4500 | 11409 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 11410 | if (user_breakpoint_p (b)) |
c5aa993b | 11411 | delete_breakpoint (b); |
c906108c SS |
11412 | } |
11413 | } | |
11414 | else | |
51be5b68 | 11415 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
11416 | } |
11417 | ||
0d381245 VP |
11418 | static int |
11419 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 11420 | { |
0d381245 VP |
11421 | for (; loc; loc = loc->next) |
11422 | if (!loc->shlib_disabled) | |
11423 | return 0; | |
11424 | return 1; | |
fe3f5fa8 VP |
11425 | } |
11426 | ||
776592bf DE |
11427 | /* Subroutine of update_breakpoint_locations to simplify it. |
11428 | Return non-zero if multiple fns in list LOC have the same name. | |
11429 | Null names are ignored. */ | |
11430 | ||
11431 | static int | |
11432 | ambiguous_names_p (struct bp_location *loc) | |
11433 | { | |
11434 | struct bp_location *l; | |
11435 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
11436 | (int (*) (const void *, |
11437 | const void *)) streq, | |
776592bf DE |
11438 | NULL, xcalloc, xfree); |
11439 | ||
11440 | for (l = loc; l != NULL; l = l->next) | |
11441 | { | |
11442 | const char **slot; | |
11443 | const char *name = l->function_name; | |
11444 | ||
11445 | /* Allow for some names to be NULL, ignore them. */ | |
11446 | if (name == NULL) | |
11447 | continue; | |
11448 | ||
11449 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
11450 | INSERT); | |
4a64f543 MS |
11451 | /* NOTE: We can assume slot != NULL here because xcalloc never |
11452 | returns NULL. */ | |
776592bf DE |
11453 | if (*slot != NULL) |
11454 | { | |
11455 | htab_delete (htab); | |
11456 | return 1; | |
11457 | } | |
11458 | *slot = name; | |
11459 | } | |
11460 | ||
11461 | htab_delete (htab); | |
11462 | return 0; | |
11463 | } | |
11464 | ||
0fb4aa4b PA |
11465 | /* When symbols change, it probably means the sources changed as well, |
11466 | and it might mean the static tracepoint markers are no longer at | |
11467 | the same address or line numbers they used to be at last we | |
11468 | checked. Losing your static tracepoints whenever you rebuild is | |
11469 | undesirable. This function tries to resync/rematch gdb static | |
11470 | tracepoints with the markers on the target, for static tracepoints | |
11471 | that have not been set by marker id. Static tracepoint that have | |
11472 | been set by marker id are reset by marker id in breakpoint_re_set. | |
11473 | The heuristic is: | |
11474 | ||
11475 | 1) For a tracepoint set at a specific address, look for a marker at | |
11476 | the old PC. If one is found there, assume to be the same marker. | |
11477 | If the name / string id of the marker found is different from the | |
11478 | previous known name, assume that means the user renamed the marker | |
11479 | in the sources, and output a warning. | |
11480 | ||
11481 | 2) For a tracepoint set at a given line number, look for a marker | |
11482 | at the new address of the old line number. If one is found there, | |
11483 | assume to be the same marker. If the name / string id of the | |
11484 | marker found is different from the previous known name, assume that | |
11485 | means the user renamed the marker in the sources, and output a | |
11486 | warning. | |
11487 | ||
11488 | 3) If a marker is no longer found at the same address or line, it | |
11489 | may mean the marker no longer exists. But it may also just mean | |
11490 | the code changed a bit. Maybe the user added a few lines of code | |
11491 | that made the marker move up or down (in line number terms). Ask | |
11492 | the target for info about the marker with the string id as we knew | |
11493 | it. If found, update line number and address in the matching | |
11494 | static tracepoint. This will get confused if there's more than one | |
11495 | marker with the same ID (possible in UST, although unadvised | |
11496 | precisely because it confuses tools). */ | |
11497 | ||
11498 | static struct symtab_and_line | |
11499 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
11500 | { | |
d9b3f62e | 11501 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
11502 | struct static_tracepoint_marker marker; |
11503 | CORE_ADDR pc; | |
11504 | int i; | |
11505 | ||
11506 | pc = sal.pc; | |
11507 | if (sal.line) | |
11508 | find_line_pc (sal.symtab, sal.line, &pc); | |
11509 | ||
11510 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
11511 | { | |
d9b3f62e | 11512 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
11513 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
11514 | b->number, | |
d9b3f62e | 11515 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 11516 | |
d9b3f62e PA |
11517 | xfree (tp->static_trace_marker_id); |
11518 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
11519 | release_static_tracepoint_marker (&marker); |
11520 | ||
11521 | return sal; | |
11522 | } | |
11523 | ||
11524 | /* Old marker wasn't found on target at lineno. Try looking it up | |
11525 | by string ID. */ | |
11526 | if (!sal.explicit_pc | |
11527 | && sal.line != 0 | |
11528 | && sal.symtab != NULL | |
d9b3f62e | 11529 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
11530 | { |
11531 | VEC(static_tracepoint_marker_p) *markers; | |
11532 | ||
11533 | markers | |
d9b3f62e | 11534 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
11535 | |
11536 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
11537 | { | |
11538 | struct symtab_and_line sal; | |
11539 | struct symbol *sym; | |
11540 | struct static_tracepoint_marker *marker; | |
79a45e25 | 11541 | struct ui_out *uiout = current_uiout; |
0fb4aa4b PA |
11542 | |
11543 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
11544 | ||
d9b3f62e PA |
11545 | xfree (tp->static_trace_marker_id); |
11546 | tp->static_trace_marker_id = xstrdup (marker->str_id); | |
0fb4aa4b PA |
11547 | |
11548 | warning (_("marker for static tracepoint %d (%s) not " | |
11549 | "found at previous line number"), | |
d9b3f62e | 11550 | b->number, tp->static_trace_marker_id); |
0fb4aa4b PA |
11551 | |
11552 | init_sal (&sal); | |
11553 | ||
11554 | sal.pc = marker->address; | |
11555 | ||
11556 | sal = find_pc_line (marker->address, 0); | |
11557 | sym = find_pc_sect_function (marker->address, NULL); | |
11558 | ui_out_text (uiout, "Now in "); | |
11559 | if (sym) | |
11560 | { | |
11561 | ui_out_field_string (uiout, "func", | |
11562 | SYMBOL_PRINT_NAME (sym)); | |
11563 | ui_out_text (uiout, " at "); | |
11564 | } | |
11565 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
11566 | ui_out_text (uiout, ":"); | |
11567 | ||
11568 | if (ui_out_is_mi_like_p (uiout)) | |
11569 | { | |
11570 | char *fullname = symtab_to_fullname (sal.symtab); | |
11571 | ||
11572 | if (fullname) | |
11573 | ui_out_field_string (uiout, "fullname", fullname); | |
11574 | } | |
11575 | ||
11576 | ui_out_field_int (uiout, "line", sal.line); | |
11577 | ui_out_text (uiout, "\n"); | |
11578 | ||
11579 | b->line_number = sal.line; | |
11580 | ||
11581 | xfree (b->source_file); | |
11582 | if (sym) | |
11583 | b->source_file = xstrdup (sal.symtab->filename); | |
11584 | else | |
11585 | b->source_file = NULL; | |
11586 | ||
11587 | xfree (b->addr_string); | |
11588 | b->addr_string = xstrprintf ("%s:%d", | |
11589 | sal.symtab->filename, b->line_number); | |
11590 | ||
11591 | /* Might be nice to check if function changed, and warn if | |
11592 | so. */ | |
11593 | ||
11594 | release_static_tracepoint_marker (marker); | |
11595 | } | |
11596 | } | |
11597 | return sal; | |
11598 | } | |
11599 | ||
8d3788bd VP |
11600 | /* Returns 1 iff locations A and B are sufficiently same that |
11601 | we don't need to report breakpoint as changed. */ | |
11602 | ||
11603 | static int | |
11604 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11605 | { | |
11606 | while (a && b) | |
11607 | { | |
11608 | if (a->address != b->address) | |
11609 | return 0; | |
11610 | ||
11611 | if (a->shlib_disabled != b->shlib_disabled) | |
11612 | return 0; | |
11613 | ||
11614 | if (a->enabled != b->enabled) | |
11615 | return 0; | |
11616 | ||
11617 | a = a->next; | |
11618 | b = b->next; | |
11619 | } | |
11620 | ||
11621 | if ((a == NULL) != (b == NULL)) | |
11622 | return 0; | |
11623 | ||
11624 | return 1; | |
11625 | } | |
11626 | ||
f1310107 TJB |
11627 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11628 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11629 | a ranged breakpoint. */ | |
11630 | ||
0e30163f | 11631 | void |
0d381245 | 11632 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11633 | struct symtabs_and_lines sals, |
11634 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11635 | { |
11636 | int i; | |
0d381245 VP |
11637 | struct bp_location *existing_locations = b->loc; |
11638 | ||
f1310107 TJB |
11639 | /* Ranged breakpoints have only one start location and one end location. */ |
11640 | gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1)); | |
11641 | ||
4a64f543 MS |
11642 | /* If there's no new locations, and all existing locations are |
11643 | pending, don't do anything. This optimizes the common case where | |
11644 | all locations are in the same shared library, that was unloaded. | |
11645 | We'd like to retain the location, so that when the library is | |
11646 | loaded again, we don't loose the enabled/disabled status of the | |
11647 | individual locations. */ | |
0d381245 | 11648 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11649 | return; |
11650 | ||
fe3f5fa8 VP |
11651 | b->loc = NULL; |
11652 | ||
0d381245 | 11653 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11654 | { |
0d381245 | 11655 | struct bp_location *new_loc = |
39d61571 | 11656 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 11657 | |
0d381245 VP |
11658 | /* Reparse conditions, they might contain references to the |
11659 | old symtab. */ | |
11660 | if (b->cond_string != NULL) | |
11661 | { | |
f1310107 | 11662 | char *s; |
0d381245 | 11663 | struct gdb_exception e; |
fe3f5fa8 | 11664 | |
0d381245 VP |
11665 | s = b->cond_string; |
11666 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11667 | { | |
11668 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11669 | 0); | |
11670 | } | |
11671 | if (e.reason < 0) | |
11672 | { | |
3e43a32a MS |
11673 | warning (_("failed to reevaluate condition " |
11674 | "for breakpoint %d: %s"), | |
0d381245 VP |
11675 | b->number, e.message); |
11676 | new_loc->enabled = 0; | |
11677 | } | |
11678 | } | |
fe3f5fa8 | 11679 | |
0d381245 VP |
11680 | if (b->source_file != NULL) |
11681 | xfree (b->source_file); | |
11682 | if (sals.sals[i].symtab == NULL) | |
11683 | b->source_file = NULL; | |
11684 | else | |
1b36a34b | 11685 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 11686 | |
0d381245 VP |
11687 | if (b->line_number == 0) |
11688 | b->line_number = sals.sals[i].line; | |
f1310107 TJB |
11689 | |
11690 | if (sals_end.nelts) | |
11691 | { | |
11692 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11693 | ||
11694 | new_loc->length = end - sals.sals[0].pc + 1; | |
11695 | } | |
0d381245 | 11696 | } |
fe3f5fa8 | 11697 | |
514f746b AR |
11698 | /* Update locations of permanent breakpoints. */ |
11699 | if (b->enable_state == bp_permanent) | |
11700 | make_breakpoint_permanent (b); | |
11701 | ||
4a64f543 MS |
11702 | /* If possible, carry over 'disable' status from existing |
11703 | breakpoints. */ | |
0d381245 VP |
11704 | { |
11705 | struct bp_location *e = existing_locations; | |
776592bf DE |
11706 | /* If there are multiple breakpoints with the same function name, |
11707 | e.g. for inline functions, comparing function names won't work. | |
11708 | Instead compare pc addresses; this is just a heuristic as things | |
11709 | may have moved, but in practice it gives the correct answer | |
11710 | often enough until a better solution is found. */ | |
11711 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
11712 | ||
0d381245 VP |
11713 | for (; e; e = e->next) |
11714 | { | |
11715 | if (!e->enabled && e->function_name) | |
11716 | { | |
11717 | struct bp_location *l = b->loc; | |
776592bf DE |
11718 | if (have_ambiguous_names) |
11719 | { | |
11720 | for (; l; l = l->next) | |
f1310107 | 11721 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
11722 | { |
11723 | l->enabled = 0; | |
11724 | break; | |
11725 | } | |
11726 | } | |
11727 | else | |
11728 | { | |
11729 | for (; l; l = l->next) | |
11730 | if (l->function_name | |
11731 | && strcmp (e->function_name, l->function_name) == 0) | |
11732 | { | |
11733 | l->enabled = 0; | |
11734 | break; | |
11735 | } | |
11736 | } | |
0d381245 VP |
11737 | } |
11738 | } | |
11739 | } | |
fe3f5fa8 | 11740 | |
8d3788bd VP |
11741 | if (!locations_are_equal (existing_locations, b->loc)) |
11742 | observer_notify_breakpoint_modified (b); | |
11743 | ||
b60e7edf | 11744 | update_global_location_list (1); |
fe3f5fa8 VP |
11745 | } |
11746 | ||
ef23e705 TJB |
11747 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
11748 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
11749 | ||
11750 | static struct symtabs_and_lines | |
11751 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
11752 | { | |
11753 | char *s; | |
58438ac1 | 11754 | int marker_spec; |
02d20e4a | 11755 | struct symtabs_and_lines sals = {0}; |
ef23e705 TJB |
11756 | struct gdb_exception e; |
11757 | ||
11758 | s = addr_string; | |
11759 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); | |
11760 | ||
11761 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11762 | { | |
11763 | if (marker_spec) | |
11764 | { | |
d9b3f62e PA |
11765 | struct tracepoint *tp = (struct tracepoint *) b; |
11766 | ||
ef23e705 | 11767 | sals = decode_static_tracepoint_spec (&s); |
d9b3f62e | 11768 | if (sals.nelts > tp->static_trace_marker_id_idx) |
ef23e705 | 11769 | { |
d9b3f62e | 11770 | sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx]; |
ef23e705 TJB |
11771 | sals.nelts = 1; |
11772 | } | |
11773 | else | |
d9b3f62e | 11774 | error (_("marker %s not found"), tp->static_trace_marker_id); |
ef23e705 TJB |
11775 | } |
11776 | else | |
58438ac1 | 11777 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL); |
ef23e705 TJB |
11778 | } |
11779 | if (e.reason < 0) | |
11780 | { | |
11781 | int not_found_and_ok = 0; | |
11782 | /* For pending breakpoints, it's expected that parsing will | |
11783 | fail until the right shared library is loaded. User has | |
11784 | already told to create pending breakpoints and don't need | |
11785 | extra messages. If breakpoint is in bp_shlib_disabled | |
11786 | state, then user already saw the message about that | |
11787 | breakpoint being disabled, and don't want to see more | |
11788 | errors. */ | |
58438ac1 | 11789 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
11790 | && (b->condition_not_parsed |
11791 | || (b->loc && b->loc->shlib_disabled) | |
11792 | || b->enable_state == bp_disabled)) | |
11793 | not_found_and_ok = 1; | |
11794 | ||
11795 | if (!not_found_and_ok) | |
11796 | { | |
11797 | /* We surely don't want to warn about the same breakpoint | |
11798 | 10 times. One solution, implemented here, is disable | |
11799 | the breakpoint on error. Another solution would be to | |
11800 | have separate 'warning emitted' flag. Since this | |
11801 | happens only when a binary has changed, I don't know | |
11802 | which approach is better. */ | |
11803 | b->enable_state = bp_disabled; | |
11804 | throw_exception (e); | |
11805 | } | |
11806 | } | |
11807 | ||
58438ac1 | 11808 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 TJB |
11809 | { |
11810 | gdb_assert (sals.nelts == 1); | |
11811 | ||
11812 | resolve_sal_pc (&sals.sals[0]); | |
11813 | if (b->condition_not_parsed && s && s[0]) | |
11814 | { | |
11815 | char *cond_string = 0; | |
11816 | int thread = -1; | |
11817 | int task = 0; | |
11818 | ||
11819 | find_condition_and_thread (s, sals.sals[0].pc, | |
11820 | &cond_string, &thread, &task); | |
11821 | if (cond_string) | |
11822 | b->cond_string = cond_string; | |
11823 | b->thread = thread; | |
11824 | b->task = task; | |
11825 | b->condition_not_parsed = 0; | |
11826 | } | |
11827 | ||
11828 | if (b->type == bp_static_tracepoint && !marker_spec) | |
11829 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
ef23e705 | 11830 | |
58438ac1 TT |
11831 | *found = 1; |
11832 | } | |
11833 | else | |
11834 | *found = 0; | |
ef23e705 TJB |
11835 | |
11836 | return sals; | |
11837 | } | |
11838 | ||
348d480f PA |
11839 | /* The default re_set method, for typical hardware or software |
11840 | breakpoints. Reevaluate the breakpoint and recreate its | |
11841 | locations. */ | |
11842 | ||
11843 | static void | |
28010a5d | 11844 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
11845 | { |
11846 | int found; | |
f1310107 | 11847 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 11848 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 11849 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
11850 | |
11851 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
11852 | if (found) | |
11853 | { | |
11854 | make_cleanup (xfree, sals.sals); | |
11855 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
11856 | } | |
11857 | ||
f1310107 TJB |
11858 | if (b->addr_string_range_end) |
11859 | { | |
11860 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
11861 | if (found) | |
11862 | { | |
11863 | make_cleanup (xfree, sals_end.sals); | |
11864 | expanded_end = expand_line_sal_maybe (sals_end.sals[0]); | |
11865 | } | |
11866 | } | |
11867 | ||
11868 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
11869 | } |
11870 | ||
11871 | /* Prepare the global context for a re-set of breakpoint B. */ | |
11872 | ||
11873 | static struct cleanup * | |
11874 | prepare_re_set_context (struct breakpoint *b) | |
11875 | { | |
11876 | struct cleanup *cleanups; | |
11877 | ||
11878 | input_radix = b->input_radix; | |
11879 | cleanups = save_current_space_and_thread (); | |
11880 | switch_to_program_space_and_thread (b->pspace); | |
11881 | set_language (b->language); | |
11882 | ||
11883 | return cleanups; | |
ef23e705 TJB |
11884 | } |
11885 | ||
c906108c SS |
11886 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
11887 | The value we return ends up being the return value from catch_errors. | |
11888 | Unused in this case. */ | |
11889 | ||
11890 | static int | |
4efb68b1 | 11891 | breakpoint_re_set_one (void *bint) |
c906108c | 11892 | { |
4a64f543 | 11893 | /* Get past catch_errs. */ |
53a5351d | 11894 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 11895 | struct cleanup *cleanups; |
c906108c | 11896 | |
348d480f PA |
11897 | cleanups = prepare_re_set_context (b); |
11898 | b->ops->re_set (b); | |
11899 | do_cleanups (cleanups); | |
c906108c SS |
11900 | return 0; |
11901 | } | |
11902 | ||
69de3c6a | 11903 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 11904 | void |
69de3c6a | 11905 | breakpoint_re_set (void) |
c906108c | 11906 | { |
35df4500 | 11907 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11908 | enum language save_language; |
11909 | int save_input_radix; | |
6c95b8df | 11910 | struct cleanup *old_chain; |
c5aa993b | 11911 | |
c906108c SS |
11912 | save_language = current_language->la_language; |
11913 | save_input_radix = input_radix; | |
6c95b8df PA |
11914 | old_chain = save_current_program_space (); |
11915 | ||
35df4500 | 11916 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11917 | { |
4a64f543 | 11918 | /* Format possible error msg. */ |
fe3f5fa8 | 11919 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
11920 | b->number); |
11921 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 11922 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 11923 | do_cleanups (cleanups); |
c5aa993b | 11924 | } |
c906108c SS |
11925 | set_language (save_language); |
11926 | input_radix = save_input_radix; | |
e62c965a | 11927 | |
0756c555 | 11928 | jit_breakpoint_re_set (); |
4efc6507 | 11929 | |
6c95b8df PA |
11930 | do_cleanups (old_chain); |
11931 | ||
af02033e PP |
11932 | create_overlay_event_breakpoint (); |
11933 | create_longjmp_master_breakpoint (); | |
11934 | create_std_terminate_master_breakpoint (); | |
186c406b | 11935 | create_exception_master_breakpoint (); |
c906108c SS |
11936 | } |
11937 | \f | |
c906108c SS |
11938 | /* Reset the thread number of this breakpoint: |
11939 | ||
11940 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 11941 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 11942 | void |
fba45db2 | 11943 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
11944 | { |
11945 | if (b->thread != -1) | |
11946 | { | |
39f77062 KB |
11947 | if (in_thread_list (inferior_ptid)) |
11948 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
11949 | |
11950 | /* We're being called after following a fork. The new fork is | |
11951 | selected as current, and unless this was a vfork will have a | |
11952 | different program space from the original thread. Reset that | |
11953 | as well. */ | |
11954 | b->loc->pspace = current_program_space; | |
c906108c SS |
11955 | } |
11956 | } | |
11957 | ||
03ac34d5 MS |
11958 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
11959 | If from_tty is nonzero, it prints a message to that effect, | |
11960 | which ends with a period (no newline). */ | |
11961 | ||
c906108c | 11962 | void |
fba45db2 | 11963 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 11964 | { |
52f0bd74 | 11965 | struct breakpoint *b; |
c906108c SS |
11966 | |
11967 | if (count < 0) | |
11968 | count = 0; | |
11969 | ||
11970 | ALL_BREAKPOINTS (b) | |
11971 | if (b->number == bptnum) | |
c5aa993b | 11972 | { |
d77f58be SS |
11973 | if (is_tracepoint (b)) |
11974 | { | |
11975 | if (from_tty && count != 0) | |
11976 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
11977 | bptnum); | |
11978 | return; | |
11979 | } | |
11980 | ||
c5aa993b | 11981 | b->ignore_count = count; |
221ea385 KS |
11982 | if (from_tty) |
11983 | { | |
11984 | if (count == 0) | |
3e43a32a MS |
11985 | printf_filtered (_("Will stop next time " |
11986 | "breakpoint %d is reached."), | |
221ea385 KS |
11987 | bptnum); |
11988 | else if (count == 1) | |
a3f17187 | 11989 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
11990 | bptnum); |
11991 | else | |
3e43a32a MS |
11992 | printf_filtered (_("Will ignore next %d " |
11993 | "crossings of breakpoint %d."), | |
221ea385 KS |
11994 | count, bptnum); |
11995 | } | |
c5aa993b | 11996 | breakpoints_changed (); |
8d3788bd | 11997 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
11998 | return; |
11999 | } | |
c906108c | 12000 | |
8a3fe4f8 | 12001 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
12002 | } |
12003 | ||
c906108c SS |
12004 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
12005 | ||
12006 | static void | |
fba45db2 | 12007 | ignore_command (char *args, int from_tty) |
c906108c SS |
12008 | { |
12009 | char *p = args; | |
52f0bd74 | 12010 | int num; |
c906108c SS |
12011 | |
12012 | if (p == 0) | |
e2e0b3e5 | 12013 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 12014 | |
c906108c | 12015 | num = get_number (&p); |
5c44784c | 12016 | if (num == 0) |
8a3fe4f8 | 12017 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 12018 | if (*p == 0) |
8a3fe4f8 | 12019 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
12020 | |
12021 | set_ignore_count (num, | |
12022 | longest_to_int (value_as_long (parse_and_eval (p))), | |
12023 | from_tty); | |
221ea385 KS |
12024 | if (from_tty) |
12025 | printf_filtered ("\n"); | |
c906108c SS |
12026 | } |
12027 | \f | |
12028 | /* Call FUNCTION on each of the breakpoints | |
12029 | whose numbers are given in ARGS. */ | |
12030 | ||
12031 | static void | |
95a42b64 TT |
12032 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
12033 | void *), | |
12034 | void *data) | |
c906108c | 12035 | { |
52f0bd74 AC |
12036 | int num; |
12037 | struct breakpoint *b, *tmp; | |
11cf8741 | 12038 | int match; |
197f0a60 | 12039 | struct get_number_or_range_state state; |
c906108c | 12040 | |
197f0a60 | 12041 | if (args == 0) |
e2e0b3e5 | 12042 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 12043 | |
197f0a60 TT |
12044 | init_number_or_range (&state, args); |
12045 | ||
12046 | while (!state.finished) | |
c906108c | 12047 | { |
197f0a60 TT |
12048 | char *p = state.string; |
12049 | ||
11cf8741 | 12050 | match = 0; |
c5aa993b | 12051 | |
197f0a60 | 12052 | num = get_number_or_range (&state); |
5c44784c | 12053 | if (num == 0) |
c5aa993b | 12054 | { |
8a3fe4f8 | 12055 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
12056 | } |
12057 | else | |
12058 | { | |
12059 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
12060 | if (b->number == num) | |
12061 | { | |
11cf8741 | 12062 | match = 1; |
cdac0397 | 12063 | function (b, data); |
11cf8741 | 12064 | break; |
5c44784c | 12065 | } |
11cf8741 | 12066 | if (match == 0) |
a3f17187 | 12067 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 12068 | } |
c906108c SS |
12069 | } |
12070 | } | |
12071 | ||
0d381245 VP |
12072 | static struct bp_location * |
12073 | find_location_by_number (char *number) | |
12074 | { | |
12075 | char *dot = strchr (number, '.'); | |
12076 | char *p1; | |
12077 | int bp_num; | |
12078 | int loc_num; | |
12079 | struct breakpoint *b; | |
12080 | struct bp_location *loc; | |
12081 | ||
12082 | *dot = '\0'; | |
12083 | ||
12084 | p1 = number; | |
197f0a60 | 12085 | bp_num = get_number (&p1); |
0d381245 VP |
12086 | if (bp_num == 0) |
12087 | error (_("Bad breakpoint number '%s'"), number); | |
12088 | ||
12089 | ALL_BREAKPOINTS (b) | |
12090 | if (b->number == bp_num) | |
12091 | { | |
12092 | break; | |
12093 | } | |
12094 | ||
12095 | if (!b || b->number != bp_num) | |
12096 | error (_("Bad breakpoint number '%s'"), number); | |
12097 | ||
12098 | p1 = dot+1; | |
197f0a60 | 12099 | loc_num = get_number (&p1); |
0d381245 VP |
12100 | if (loc_num == 0) |
12101 | error (_("Bad breakpoint location number '%s'"), number); | |
12102 | ||
12103 | --loc_num; | |
12104 | loc = b->loc; | |
12105 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
12106 | ; | |
12107 | if (!loc) | |
12108 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
12109 | ||
12110 | return loc; | |
12111 | } | |
12112 | ||
12113 | ||
1900040c MS |
12114 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12115 | If from_tty is nonzero, it prints a message to that effect, | |
12116 | which ends with a period (no newline). */ | |
12117 | ||
c906108c | 12118 | void |
fba45db2 | 12119 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
12120 | { |
12121 | /* Never disable a watchpoint scope breakpoint; we want to | |
12122 | hit them when we leave scope so we can delete both the | |
12123 | watchpoint and its scope breakpoint at that time. */ | |
12124 | if (bpt->type == bp_watchpoint_scope) | |
12125 | return; | |
12126 | ||
c2c6d25f | 12127 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 12128 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
12129 | return; |
12130 | ||
b5de0fa7 | 12131 | bpt->enable_state = bp_disabled; |
c906108c | 12132 | |
d248b706 KY |
12133 | if (target_supports_enable_disable_tracepoint () |
12134 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12135 | { | |
12136 | struct bp_location *location; | |
12137 | ||
12138 | for (location = bpt->loc; location; location = location->next) | |
12139 | target_disable_tracepoint (location); | |
12140 | } | |
12141 | ||
b60e7edf | 12142 | update_global_location_list (0); |
c906108c | 12143 | |
8d3788bd | 12144 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12145 | } |
12146 | ||
51be5b68 PA |
12147 | /* A callback for iterate_over_related_breakpoints. */ |
12148 | ||
12149 | static void | |
12150 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12151 | { | |
12152 | disable_breakpoint (b); | |
12153 | } | |
12154 | ||
95a42b64 TT |
12155 | /* A callback for map_breakpoint_numbers that calls |
12156 | disable_breakpoint. */ | |
12157 | ||
12158 | static void | |
12159 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12160 | { | |
51be5b68 | 12161 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
12162 | } |
12163 | ||
c906108c | 12164 | static void |
fba45db2 | 12165 | disable_command (char *args, int from_tty) |
c906108c | 12166 | { |
c906108c | 12167 | if (args == 0) |
46c6471b PA |
12168 | { |
12169 | struct breakpoint *bpt; | |
12170 | ||
12171 | ALL_BREAKPOINTS (bpt) | |
12172 | if (user_breakpoint_p (bpt)) | |
12173 | disable_breakpoint (bpt); | |
12174 | } | |
0d381245 VP |
12175 | else if (strchr (args, '.')) |
12176 | { | |
12177 | struct bp_location *loc = find_location_by_number (args); | |
12178 | if (loc) | |
d248b706 KY |
12179 | { |
12180 | loc->enabled = 0; | |
12181 | if (target_supports_enable_disable_tracepoint () | |
12182 | && current_trace_status ()->running && loc->owner | |
12183 | && is_tracepoint (loc->owner)) | |
12184 | target_disable_tracepoint (loc); | |
12185 | } | |
b60e7edf | 12186 | update_global_location_list (0); |
0d381245 | 12187 | } |
c906108c | 12188 | else |
95a42b64 | 12189 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
12190 | } |
12191 | ||
12192 | static void | |
51be5b68 | 12193 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 12194 | { |
afe38095 | 12195 | int target_resources_ok; |
c906108c SS |
12196 | |
12197 | if (bpt->type == bp_hardware_breakpoint) | |
12198 | { | |
12199 | int i; | |
c5aa993b | 12200 | i = hw_breakpoint_used_count (); |
53a5351d | 12201 | target_resources_ok = |
d92524f1 | 12202 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 12203 | i + 1, 0); |
c906108c | 12204 | if (target_resources_ok == 0) |
8a3fe4f8 | 12205 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 12206 | else if (target_resources_ok < 0) |
8a3fe4f8 | 12207 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
12208 | } |
12209 | ||
cc60f2e3 | 12210 | if (is_watchpoint (bpt)) |
c906108c | 12211 | { |
d07205c2 JK |
12212 | /* Initialize it just to avoid a GCC false warning. */ |
12213 | enum enable_state orig_enable_state = 0; | |
dde02812 ES |
12214 | struct gdb_exception e; |
12215 | ||
12216 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 12217 | { |
3a5c3e22 PA |
12218 | struct watchpoint *w = (struct watchpoint *) bpt; |
12219 | ||
1e718ff1 TJB |
12220 | orig_enable_state = bpt->enable_state; |
12221 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 12222 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 12223 | } |
dde02812 | 12224 | if (e.reason < 0) |
c5aa993b | 12225 | { |
1e718ff1 | 12226 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
12227 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
12228 | bpt->number); | |
12229 | return; | |
c5aa993b | 12230 | } |
c906108c | 12231 | } |
0101ce28 | 12232 | |
b4c291bb KH |
12233 | if (bpt->enable_state != bp_permanent) |
12234 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
12235 | |
12236 | if (target_supports_enable_disable_tracepoint () | |
12237 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12238 | { | |
12239 | struct bp_location *location; | |
12240 | ||
12241 | for (location = bpt->loc; location; location = location->next) | |
12242 | target_enable_tracepoint (location); | |
12243 | } | |
12244 | ||
b4c291bb | 12245 | bpt->disposition = disposition; |
b60e7edf | 12246 | update_global_location_list (1); |
b4c291bb KH |
12247 | breakpoints_changed (); |
12248 | ||
8d3788bd | 12249 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12250 | } |
12251 | ||
fe3f5fa8 | 12252 | |
c906108c | 12253 | void |
fba45db2 | 12254 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 12255 | { |
51be5b68 PA |
12256 | enable_breakpoint_disp (bpt, bpt->disposition); |
12257 | } | |
12258 | ||
12259 | static void | |
12260 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
12261 | { | |
12262 | enable_breakpoint (bpt); | |
c906108c SS |
12263 | } |
12264 | ||
95a42b64 TT |
12265 | /* A callback for map_breakpoint_numbers that calls |
12266 | enable_breakpoint. */ | |
12267 | ||
12268 | static void | |
12269 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
12270 | { | |
51be5b68 | 12271 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
12272 | } |
12273 | ||
c906108c SS |
12274 | /* The enable command enables the specified breakpoints (or all defined |
12275 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 12276 | in stopping the inferior. */ |
c906108c | 12277 | |
c906108c | 12278 | static void |
fba45db2 | 12279 | enable_command (char *args, int from_tty) |
c906108c | 12280 | { |
c906108c | 12281 | if (args == 0) |
46c6471b PA |
12282 | { |
12283 | struct breakpoint *bpt; | |
12284 | ||
12285 | ALL_BREAKPOINTS (bpt) | |
12286 | if (user_breakpoint_p (bpt)) | |
12287 | enable_breakpoint (bpt); | |
12288 | } | |
0d381245 VP |
12289 | else if (strchr (args, '.')) |
12290 | { | |
12291 | struct bp_location *loc = find_location_by_number (args); | |
12292 | if (loc) | |
d248b706 KY |
12293 | { |
12294 | loc->enabled = 1; | |
12295 | if (target_supports_enable_disable_tracepoint () | |
12296 | && current_trace_status ()->running && loc->owner | |
12297 | && is_tracepoint (loc->owner)) | |
12298 | target_enable_tracepoint (loc); | |
12299 | } | |
b60e7edf | 12300 | update_global_location_list (1); |
0d381245 | 12301 | } |
c906108c | 12302 | else |
95a42b64 | 12303 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
12304 | } |
12305 | ||
12306 | static void | |
51be5b68 PA |
12307 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
12308 | { | |
12309 | enum bpdisp disp = *(enum bpdisp *) arg; | |
12310 | ||
12311 | enable_breakpoint_disp (bpt, disp); | |
12312 | } | |
12313 | ||
12314 | static void | |
12315 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 12316 | { |
51be5b68 PA |
12317 | enum bpdisp disp = disp_disable; |
12318 | ||
12319 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12320 | } |
12321 | ||
c906108c | 12322 | static void |
fba45db2 | 12323 | enable_once_command (char *args, int from_tty) |
c906108c | 12324 | { |
51be5b68 | 12325 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
12326 | } |
12327 | ||
12328 | static void | |
51be5b68 | 12329 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 12330 | { |
51be5b68 PA |
12331 | enum bpdisp disp = disp_del; |
12332 | ||
12333 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12334 | } |
12335 | ||
c906108c | 12336 | static void |
fba45db2 | 12337 | enable_delete_command (char *args, int from_tty) |
c906108c | 12338 | { |
51be5b68 | 12339 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
12340 | } |
12341 | \f | |
fa8d40ab JJ |
12342 | static void |
12343 | set_breakpoint_cmd (char *args, int from_tty) | |
12344 | { | |
12345 | } | |
12346 | ||
12347 | static void | |
12348 | show_breakpoint_cmd (char *args, int from_tty) | |
12349 | { | |
12350 | } | |
12351 | ||
1f3b5d1b PP |
12352 | /* Invalidate last known value of any hardware watchpoint if |
12353 | the memory which that value represents has been written to by | |
12354 | GDB itself. */ | |
12355 | ||
12356 | static void | |
12357 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
12358 | const bfd_byte *data) | |
12359 | { | |
12360 | struct breakpoint *bp; | |
12361 | ||
12362 | ALL_BREAKPOINTS (bp) | |
12363 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 12364 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 12365 | { |
3a5c3e22 | 12366 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 12367 | |
3a5c3e22 PA |
12368 | if (wp->val_valid && wp->val) |
12369 | { | |
12370 | struct bp_location *loc; | |
12371 | ||
12372 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
12373 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
12374 | && loc->address + loc->length > addr | |
12375 | && addr + len > loc->address) | |
12376 | { | |
12377 | value_free (wp->val); | |
12378 | wp->val = NULL; | |
12379 | wp->val_valid = 0; | |
12380 | } | |
12381 | } | |
1f3b5d1b PP |
12382 | } |
12383 | } | |
12384 | ||
c906108c SS |
12385 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
12386 | ||
12387 | struct symtabs_and_lines | |
fba45db2 | 12388 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
12389 | { |
12390 | struct symtabs_and_lines sals; | |
cc59ec59 | 12391 | |
c906108c | 12392 | if (string == 0) |
8a3fe4f8 | 12393 | error (_("Empty line specification.")); |
c906108c SS |
12394 | if (default_breakpoint_valid) |
12395 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
12396 | default_breakpoint_symtab, |
12397 | default_breakpoint_line, | |
58438ac1 | 12398 | NULL); |
c906108c SS |
12399 | else |
12400 | sals = decode_line_1 (&string, funfirstline, | |
58438ac1 | 12401 | (struct symtab *) NULL, 0, NULL); |
c906108c | 12402 | if (*string) |
8a3fe4f8 | 12403 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
12404 | return sals; |
12405 | } | |
8181d85f DJ |
12406 | |
12407 | /* Create and insert a raw software breakpoint at PC. Return an | |
12408 | identifier, which should be used to remove the breakpoint later. | |
12409 | In general, places which call this should be using something on the | |
12410 | breakpoint chain instead; this function should be eliminated | |
12411 | someday. */ | |
12412 | ||
12413 | void * | |
6c95b8df PA |
12414 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
12415 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
12416 | { |
12417 | struct bp_target_info *bp_tgt; | |
12418 | ||
6c95b8df | 12419 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 12420 | |
6c95b8df | 12421 | bp_tgt->placed_address_space = aspace; |
8181d85f | 12422 | bp_tgt->placed_address = pc; |
6c95b8df | 12423 | |
a6d9a66e | 12424 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
12425 | { |
12426 | /* Could not insert the breakpoint. */ | |
12427 | xfree (bp_tgt); | |
12428 | return NULL; | |
12429 | } | |
12430 | ||
12431 | return bp_tgt; | |
12432 | } | |
12433 | ||
4a64f543 MS |
12434 | /* Remove a breakpoint BP inserted by |
12435 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
12436 | |
12437 | int | |
a6d9a66e | 12438 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
12439 | { |
12440 | struct bp_target_info *bp_tgt = bp; | |
12441 | int ret; | |
12442 | ||
a6d9a66e | 12443 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
12444 | xfree (bp_tgt); |
12445 | ||
12446 | return ret; | |
12447 | } | |
12448 | ||
4a64f543 MS |
12449 | /* One (or perhaps two) breakpoints used for software single |
12450 | stepping. */ | |
8181d85f DJ |
12451 | |
12452 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 12453 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
12454 | |
12455 | /* Create and insert a breakpoint for software single step. */ | |
12456 | ||
12457 | void | |
6c95b8df | 12458 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
12459 | struct address_space *aspace, |
12460 | CORE_ADDR next_pc) | |
8181d85f DJ |
12461 | { |
12462 | void **bpt_p; | |
12463 | ||
12464 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
12465 | { |
12466 | bpt_p = &single_step_breakpoints[0]; | |
12467 | single_step_gdbarch[0] = gdbarch; | |
12468 | } | |
8181d85f DJ |
12469 | else |
12470 | { | |
12471 | gdb_assert (single_step_breakpoints[1] == NULL); | |
12472 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 12473 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
12474 | } |
12475 | ||
4a64f543 MS |
12476 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12477 | be to only create the breakpoints once, and actually put them on | |
12478 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12479 | We could adjust the addresses each time they were needed. Doing | |
12480 | this requires corresponding changes elsewhere where single step | |
12481 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12482 | |
6c95b8df | 12483 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12484 | if (*bpt_p == NULL) |
5af949e3 UW |
12485 | error (_("Could not insert single-step breakpoint at %s"), |
12486 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12487 | } |
12488 | ||
f02253f1 HZ |
12489 | /* Check if the breakpoints used for software single stepping |
12490 | were inserted or not. */ | |
12491 | ||
12492 | int | |
12493 | single_step_breakpoints_inserted (void) | |
12494 | { | |
12495 | return (single_step_breakpoints[0] != NULL | |
12496 | || single_step_breakpoints[1] != NULL); | |
12497 | } | |
12498 | ||
8181d85f DJ |
12499 | /* Remove and delete any breakpoints used for software single step. */ |
12500 | ||
12501 | void | |
12502 | remove_single_step_breakpoints (void) | |
12503 | { | |
12504 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12505 | ||
12506 | /* See insert_single_step_breakpoint for more about this deprecated | |
12507 | call. */ | |
a6d9a66e UW |
12508 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12509 | single_step_breakpoints[0]); | |
12510 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12511 | single_step_breakpoints[0] = NULL; |
12512 | ||
12513 | if (single_step_breakpoints[1] != NULL) | |
12514 | { | |
a6d9a66e UW |
12515 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12516 | single_step_breakpoints[1]); | |
12517 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12518 | single_step_breakpoints[1] = NULL; |
12519 | } | |
12520 | } | |
12521 | ||
d03285ec UW |
12522 | /* Delete software single step breakpoints without removing them from |
12523 | the inferior. This is intended to be used if the inferior's address | |
12524 | space where they were inserted is already gone, e.g. after exit or | |
12525 | exec. */ | |
12526 | ||
12527 | void | |
12528 | cancel_single_step_breakpoints (void) | |
12529 | { | |
12530 | int i; | |
12531 | ||
12532 | for (i = 0; i < 2; i++) | |
12533 | if (single_step_breakpoints[i]) | |
12534 | { | |
12535 | xfree (single_step_breakpoints[i]); | |
12536 | single_step_breakpoints[i] = NULL; | |
12537 | single_step_gdbarch[i] = NULL; | |
12538 | } | |
12539 | } | |
12540 | ||
12541 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12542 | removing them. */ | |
12543 | ||
12544 | static void | |
12545 | detach_single_step_breakpoints (void) | |
12546 | { | |
12547 | int i; | |
12548 | ||
12549 | for (i = 0; i < 2; i++) | |
12550 | if (single_step_breakpoints[i]) | |
12551 | target_remove_breakpoint (single_step_gdbarch[i], | |
12552 | single_step_breakpoints[i]); | |
12553 | } | |
12554 | ||
4a64f543 MS |
12555 | /* Check whether a software single-step breakpoint is inserted at |
12556 | PC. */ | |
1aafd4da UW |
12557 | |
12558 | static int | |
cc59ec59 MS |
12559 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12560 | CORE_ADDR pc) | |
1aafd4da UW |
12561 | { |
12562 | int i; | |
12563 | ||
12564 | for (i = 0; i < 2; i++) | |
12565 | { | |
12566 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12567 | if (bp_tgt |
12568 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12569 | bp_tgt->placed_address, | |
12570 | aspace, pc)) | |
1aafd4da UW |
12571 | return 1; |
12572 | } | |
12573 | ||
12574 | return 0; | |
12575 | } | |
12576 | ||
a96d9b2e SDJ |
12577 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12578 | non-zero otherwise. */ | |
12579 | static int | |
12580 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12581 | { | |
12582 | if (syscall_catchpoint_p (bp) | |
12583 | && bp->enable_state != bp_disabled | |
12584 | && bp->enable_state != bp_call_disabled) | |
12585 | return 1; | |
12586 | else | |
12587 | return 0; | |
12588 | } | |
12589 | ||
12590 | int | |
12591 | catch_syscall_enabled (void) | |
12592 | { | |
12593 | struct inferior *inf = current_inferior (); | |
12594 | ||
12595 | return inf->total_syscalls_count != 0; | |
12596 | } | |
12597 | ||
12598 | int | |
12599 | catching_syscall_number (int syscall_number) | |
12600 | { | |
12601 | struct breakpoint *bp; | |
12602 | ||
12603 | ALL_BREAKPOINTS (bp) | |
12604 | if (is_syscall_catchpoint_enabled (bp)) | |
12605 | { | |
be5c67c1 PA |
12606 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
12607 | ||
12608 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
12609 | { |
12610 | int i, iter; | |
12611 | for (i = 0; | |
be5c67c1 | 12612 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
12613 | i++) |
12614 | if (syscall_number == iter) | |
12615 | return 1; | |
12616 | } | |
12617 | else | |
12618 | return 1; | |
12619 | } | |
12620 | ||
12621 | return 0; | |
12622 | } | |
12623 | ||
12624 | /* Complete syscall names. Used by "catch syscall". */ | |
12625 | static char ** | |
12626 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12627 | char *text, char *word) | |
12628 | { | |
12629 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12630 | char **retlist |
12631 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12632 | |
c38eea1a MS |
12633 | xfree (list); |
12634 | return retlist; | |
a96d9b2e SDJ |
12635 | } |
12636 | ||
1042e4c0 SS |
12637 | /* Tracepoint-specific operations. */ |
12638 | ||
12639 | /* Set tracepoint count to NUM. */ | |
12640 | static void | |
12641 | set_tracepoint_count (int num) | |
12642 | { | |
12643 | tracepoint_count = num; | |
4fa62494 | 12644 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
12645 | } |
12646 | ||
12647 | void | |
12648 | trace_command (char *arg, int from_tty) | |
12649 | { | |
8cdf0e15 VP |
12650 | if (create_breakpoint (get_current_arch (), |
12651 | arg, | |
12652 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12653 | 0 /* tempflag */, |
12654 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12655 | 0 /* Ignore count */, |
12656 | pending_break_support, | |
348d480f | 12657 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12658 | from_tty, |
84f4c1fe PM |
12659 | 1 /* enabled */, |
12660 | 0 /* internal */)) | |
fd9b8c24 | 12661 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
12662 | } |
12663 | ||
7a697b8d SS |
12664 | void |
12665 | ftrace_command (char *arg, int from_tty) | |
12666 | { | |
8cdf0e15 VP |
12667 | if (create_breakpoint (get_current_arch (), |
12668 | arg, | |
12669 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12670 | 0 /* tempflag */, |
12671 | bp_fast_tracepoint /* type_wanted */, | |
12672 | 0 /* Ignore count */, | |
12673 | pending_break_support, | |
348d480f | 12674 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 12675 | from_tty, |
84f4c1fe PM |
12676 | 1 /* enabled */, |
12677 | 0 /* internal */)) | |
0fb4aa4b PA |
12678 | set_tracepoint_count (breakpoint_count); |
12679 | } | |
12680 | ||
12681 | /* strace command implementation. Creates a static tracepoint. */ | |
12682 | ||
12683 | void | |
12684 | strace_command (char *arg, int from_tty) | |
12685 | { | |
12686 | if (create_breakpoint (get_current_arch (), | |
12687 | arg, | |
12688 | NULL, 0, 1 /* parse arg */, | |
12689 | 0 /* tempflag */, | |
12690 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12691 | 0 /* Ignore count */, |
12692 | pending_break_support, | |
348d480f | 12693 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12694 | from_tty, |
84f4c1fe PM |
12695 | 1 /* enabled */, |
12696 | 0 /* internal */)) | |
fd9b8c24 | 12697 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
12698 | } |
12699 | ||
409873ef SS |
12700 | /* Set up a fake reader function that gets command lines from a linked |
12701 | list that was acquired during tracepoint uploading. */ | |
12702 | ||
12703 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 12704 | static int next_cmd; |
409873ef SS |
12705 | |
12706 | static char * | |
12707 | read_uploaded_action (void) | |
12708 | { | |
12709 | char *rslt; | |
12710 | ||
3149d8c1 | 12711 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 12712 | |
3149d8c1 | 12713 | next_cmd++; |
409873ef SS |
12714 | |
12715 | return rslt; | |
12716 | } | |
12717 | ||
00bf0b85 SS |
12718 | /* Given information about a tracepoint as recorded on a target (which |
12719 | can be either a live system or a trace file), attempt to create an | |
12720 | equivalent GDB tracepoint. This is not a reliable process, since | |
12721 | the target does not necessarily have all the information used when | |
12722 | the tracepoint was originally defined. */ | |
12723 | ||
d9b3f62e | 12724 | struct tracepoint * |
00bf0b85 | 12725 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 12726 | { |
409873ef | 12727 | char *addr_str, small_buf[100]; |
d9b3f62e | 12728 | struct tracepoint *tp; |
fd9b8c24 | 12729 | |
409873ef SS |
12730 | if (utp->at_string) |
12731 | addr_str = utp->at_string; | |
12732 | else | |
12733 | { | |
12734 | /* In the absence of a source location, fall back to raw | |
12735 | address. Since there is no way to confirm that the address | |
12736 | means the same thing as when the trace was started, warn the | |
12737 | user. */ | |
3e43a32a MS |
12738 | warning (_("Uploaded tracepoint %d has no " |
12739 | "source location, using raw address"), | |
409873ef SS |
12740 | utp->number); |
12741 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
12742 | addr_str = small_buf; | |
12743 | } | |
12744 | ||
12745 | /* There's not much we can do with a sequence of bytecodes. */ | |
12746 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
12747 | warning (_("Uploaded tracepoint %d condition " |
12748 | "has no source form, ignoring it"), | |
409873ef | 12749 | utp->number); |
d5551862 | 12750 | |
8cdf0e15 | 12751 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
12752 | addr_str, |
12753 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 12754 | 0 /* tempflag */, |
0fb4aa4b | 12755 | utp->type /* type_wanted */, |
8cdf0e15 VP |
12756 | 0 /* Ignore count */, |
12757 | pending_break_support, | |
348d480f | 12758 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12759 | 0 /* from_tty */, |
84f4c1fe PM |
12760 | utp->enabled /* enabled */, |
12761 | 0 /* internal */)) | |
fd9b8c24 PA |
12762 | return NULL; |
12763 | ||
00bf0b85 SS |
12764 | set_tracepoint_count (breakpoint_count); |
12765 | ||
409873ef | 12766 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
12767 | tp = get_tracepoint (tracepoint_count); |
12768 | gdb_assert (tp != NULL); | |
d5551862 | 12769 | |
00bf0b85 SS |
12770 | if (utp->pass > 0) |
12771 | { | |
d9b3f62e | 12772 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 12773 | |
409873ef | 12774 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
12775 | } |
12776 | ||
409873ef SS |
12777 | /* If we have uploaded versions of the original commands, set up a |
12778 | special-purpose "reader" function and call the usual command line | |
12779 | reader, then pass the result to the breakpoint command-setting | |
12780 | function. */ | |
3149d8c1 | 12781 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 12782 | { |
409873ef | 12783 | struct command_line *cmd_list; |
00bf0b85 | 12784 | |
409873ef | 12785 | this_utp = utp; |
3149d8c1 | 12786 | next_cmd = 0; |
d5551862 | 12787 | |
409873ef SS |
12788 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
12789 | ||
d9b3f62e | 12790 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 12791 | } |
3149d8c1 SS |
12792 | else if (!VEC_empty (char_ptr, utp->actions) |
12793 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
12794 | warning (_("Uploaded tracepoint %d actions " |
12795 | "have no source form, ignoring them"), | |
409873ef | 12796 | utp->number); |
00bf0b85 SS |
12797 | |
12798 | return tp; | |
d9b3f62e | 12799 | } |
00bf0b85 | 12800 | |
1042e4c0 SS |
12801 | /* Print information on tracepoint number TPNUM_EXP, or all if |
12802 | omitted. */ | |
12803 | ||
12804 | static void | |
e5a67952 | 12805 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 12806 | { |
79a45e25 | 12807 | struct ui_out *uiout = current_uiout; |
e5a67952 | 12808 | int num_printed; |
1042e4c0 | 12809 | |
e5a67952 | 12810 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
12811 | |
12812 | if (num_printed == 0) | |
1042e4c0 | 12813 | { |
e5a67952 | 12814 | if (args == NULL || *args == '\0') |
d77f58be SS |
12815 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
12816 | else | |
e5a67952 | 12817 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 12818 | } |
ad443146 SS |
12819 | |
12820 | default_collect_info (); | |
1042e4c0 SS |
12821 | } |
12822 | ||
4a64f543 | 12823 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
12824 | Not supported by all targets. */ |
12825 | static void | |
12826 | enable_trace_command (char *args, int from_tty) | |
12827 | { | |
12828 | enable_command (args, from_tty); | |
12829 | } | |
12830 | ||
4a64f543 | 12831 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
12832 | Not supported by all targets. */ |
12833 | static void | |
12834 | disable_trace_command (char *args, int from_tty) | |
12835 | { | |
12836 | disable_command (args, from_tty); | |
12837 | } | |
12838 | ||
4a64f543 | 12839 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
12840 | static void |
12841 | delete_trace_command (char *arg, int from_tty) | |
12842 | { | |
35df4500 | 12843 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
12844 | |
12845 | dont_repeat (); | |
12846 | ||
12847 | if (arg == 0) | |
12848 | { | |
12849 | int breaks_to_delete = 0; | |
12850 | ||
12851 | /* Delete all breakpoints if no argument. | |
12852 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
12853 | have to be deleted with an explicit breakpoint number |
12854 | argument. */ | |
1042e4c0 | 12855 | ALL_TRACEPOINTS (b) |
46c6471b | 12856 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
12857 | { |
12858 | breaks_to_delete = 1; | |
12859 | break; | |
12860 | } | |
1042e4c0 SS |
12861 | |
12862 | /* Ask user only if there are some breakpoints to delete. */ | |
12863 | if (!from_tty | |
12864 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
12865 | { | |
35df4500 | 12866 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12867 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 12868 | delete_breakpoint (b); |
1042e4c0 SS |
12869 | } |
12870 | } | |
12871 | else | |
51be5b68 | 12872 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
12873 | } |
12874 | ||
197f0a60 TT |
12875 | /* Helper function for trace_pass_command. */ |
12876 | ||
12877 | static void | |
d9b3f62e | 12878 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 12879 | { |
d9b3f62e PA |
12880 | tp->pass_count = count; |
12881 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
12882 | if (from_tty) |
12883 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 12884 | tp->base.number, count); |
197f0a60 TT |
12885 | } |
12886 | ||
1042e4c0 SS |
12887 | /* Set passcount for tracepoint. |
12888 | ||
12889 | First command argument is passcount, second is tracepoint number. | |
12890 | If tracepoint number omitted, apply to most recently defined. | |
12891 | Also accepts special argument "all". */ | |
12892 | ||
12893 | static void | |
12894 | trace_pass_command (char *args, int from_tty) | |
12895 | { | |
d9b3f62e | 12896 | struct tracepoint *t1; |
1042e4c0 | 12897 | unsigned int count; |
1042e4c0 SS |
12898 | |
12899 | if (args == 0 || *args == 0) | |
3e43a32a MS |
12900 | error (_("passcount command requires an " |
12901 | "argument (count + optional TP num)")); | |
1042e4c0 | 12902 | |
4a64f543 | 12903 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
12904 | |
12905 | while (*args && isspace ((int) *args)) | |
12906 | args++; | |
12907 | ||
12908 | if (*args && strncasecmp (args, "all", 3) == 0) | |
12909 | { | |
d9b3f62e PA |
12910 | struct breakpoint *b; |
12911 | ||
1042e4c0 | 12912 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
12913 | if (*args) |
12914 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 12915 | |
d9b3f62e | 12916 | ALL_TRACEPOINTS (b) |
197f0a60 | 12917 | { |
d9b3f62e | 12918 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
12919 | trace_pass_set_count (t1, count, from_tty); |
12920 | } | |
12921 | } | |
12922 | else if (*args == '\0') | |
1042e4c0 | 12923 | { |
197f0a60 | 12924 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 12925 | if (t1) |
197f0a60 TT |
12926 | trace_pass_set_count (t1, count, from_tty); |
12927 | } | |
12928 | else | |
12929 | { | |
12930 | struct get_number_or_range_state state; | |
12931 | ||
12932 | init_number_or_range (&state, args); | |
12933 | while (!state.finished) | |
1042e4c0 | 12934 | { |
197f0a60 TT |
12935 | t1 = get_tracepoint_by_number (&args, &state, 1); |
12936 | if (t1) | |
12937 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
12938 | } |
12939 | } | |
1042e4c0 SS |
12940 | } |
12941 | ||
d9b3f62e | 12942 | struct tracepoint * |
1042e4c0 SS |
12943 | get_tracepoint (int num) |
12944 | { | |
12945 | struct breakpoint *t; | |
12946 | ||
12947 | ALL_TRACEPOINTS (t) | |
12948 | if (t->number == num) | |
d9b3f62e | 12949 | return (struct tracepoint *) t; |
1042e4c0 SS |
12950 | |
12951 | return NULL; | |
12952 | } | |
12953 | ||
d5551862 SS |
12954 | /* Find the tracepoint with the given target-side number (which may be |
12955 | different from the tracepoint number after disconnecting and | |
12956 | reconnecting). */ | |
12957 | ||
d9b3f62e | 12958 | struct tracepoint * |
d5551862 SS |
12959 | get_tracepoint_by_number_on_target (int num) |
12960 | { | |
d9b3f62e | 12961 | struct breakpoint *b; |
d5551862 | 12962 | |
d9b3f62e PA |
12963 | ALL_TRACEPOINTS (b) |
12964 | { | |
12965 | struct tracepoint *t = (struct tracepoint *) b; | |
12966 | ||
12967 | if (t->number_on_target == num) | |
12968 | return t; | |
12969 | } | |
d5551862 SS |
12970 | |
12971 | return NULL; | |
12972 | } | |
12973 | ||
1042e4c0 | 12974 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
12975 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
12976 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 12977 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 12978 | struct tracepoint * |
197f0a60 TT |
12979 | get_tracepoint_by_number (char **arg, |
12980 | struct get_number_or_range_state *state, | |
12981 | int optional_p) | |
1042e4c0 SS |
12982 | { |
12983 | extern int tracepoint_count; | |
12984 | struct breakpoint *t; | |
12985 | int tpnum; | |
12986 | char *instring = arg == NULL ? NULL : *arg; | |
12987 | ||
197f0a60 TT |
12988 | if (state) |
12989 | { | |
12990 | gdb_assert (!state->finished); | |
12991 | tpnum = get_number_or_range (state); | |
12992 | } | |
12993 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
12994 | { |
12995 | if (optional_p) | |
12996 | tpnum = tracepoint_count; | |
12997 | else | |
12998 | error_no_arg (_("tracepoint number")); | |
12999 | } | |
13000 | else | |
197f0a60 | 13001 | tpnum = get_number (arg); |
1042e4c0 SS |
13002 | |
13003 | if (tpnum <= 0) | |
13004 | { | |
13005 | if (instring && *instring) | |
13006 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
13007 | instring); | |
13008 | else | |
3e43a32a MS |
13009 | printf_filtered (_("Tracepoint argument missing " |
13010 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
13011 | return NULL; |
13012 | } | |
13013 | ||
13014 | ALL_TRACEPOINTS (t) | |
13015 | if (t->number == tpnum) | |
13016 | { | |
d9b3f62e | 13017 | return (struct tracepoint *) t; |
1042e4c0 SS |
13018 | } |
13019 | ||
1042e4c0 SS |
13020 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
13021 | return NULL; | |
13022 | } | |
13023 | ||
d9b3f62e PA |
13024 | void |
13025 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
13026 | { | |
13027 | if (b->thread != -1) | |
13028 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
13029 | ||
13030 | if (b->task != 0) | |
13031 | fprintf_unfiltered (fp, " task %d", b->task); | |
13032 | ||
13033 | fprintf_unfiltered (fp, "\n"); | |
13034 | } | |
13035 | ||
6149aea9 PA |
13036 | /* Save information on user settable breakpoints (watchpoints, etc) to |
13037 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
13038 | on each breakpoint and only include the ones for which it returns | |
13039 | non-zero. */ | |
13040 | ||
1042e4c0 | 13041 | static void |
6149aea9 PA |
13042 | save_breakpoints (char *filename, int from_tty, |
13043 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
13044 | { |
13045 | struct breakpoint *tp; | |
6149aea9 | 13046 | int any = 0; |
a7bdde9e | 13047 | char *pathname; |
1042e4c0 | 13048 | struct cleanup *cleanup; |
a7bdde9e | 13049 | struct ui_file *fp; |
6149aea9 | 13050 | int extra_trace_bits = 0; |
1042e4c0 | 13051 | |
6149aea9 PA |
13052 | if (filename == 0 || *filename == 0) |
13053 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
13054 | |
13055 | /* See if we have anything to save. */ | |
6149aea9 | 13056 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13057 | { |
6149aea9 | 13058 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13059 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
13060 | continue; |
13061 | ||
13062 | /* If we have a filter, only save the breakpoints it accepts. */ | |
13063 | if (filter && !filter (tp)) | |
13064 | continue; | |
13065 | ||
13066 | any = 1; | |
13067 | ||
13068 | if (is_tracepoint (tp)) | |
13069 | { | |
13070 | extra_trace_bits = 1; | |
13071 | ||
13072 | /* We can stop searching. */ | |
13073 | break; | |
13074 | } | |
1042e4c0 | 13075 | } |
6149aea9 PA |
13076 | |
13077 | if (!any) | |
1042e4c0 | 13078 | { |
6149aea9 | 13079 | warning (_("Nothing to save.")); |
1042e4c0 SS |
13080 | return; |
13081 | } | |
13082 | ||
6149aea9 | 13083 | pathname = tilde_expand (filename); |
1042e4c0 | 13084 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 13085 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 13086 | if (!fp) |
6149aea9 PA |
13087 | error (_("Unable to open file '%s' for saving (%s)"), |
13088 | filename, safe_strerror (errno)); | |
a7bdde9e | 13089 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 13090 | |
6149aea9 PA |
13091 | if (extra_trace_bits) |
13092 | save_trace_state_variables (fp); | |
8bf6485c | 13093 | |
6149aea9 | 13094 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13095 | { |
6149aea9 | 13096 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13097 | if (!user_breakpoint_p (tp)) |
6149aea9 | 13098 | continue; |
8bf6485c | 13099 | |
6149aea9 PA |
13100 | /* If we have a filter, only save the breakpoints it accepts. */ |
13101 | if (filter && !filter (tp)) | |
13102 | continue; | |
13103 | ||
348d480f | 13104 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 13105 | |
6149aea9 PA |
13106 | /* Note, we can't rely on tp->number for anything, as we can't |
13107 | assume the recreated breakpoint numbers will match. Use $bpnum | |
13108 | instead. */ | |
13109 | ||
13110 | if (tp->cond_string) | |
13111 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
13112 | ||
13113 | if (tp->ignore_count) | |
13114 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
13115 | ||
a7bdde9e | 13116 | if (tp->commands) |
1042e4c0 | 13117 | { |
a7bdde9e VP |
13118 | volatile struct gdb_exception ex; |
13119 | ||
6149aea9 | 13120 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e | 13121 | |
79a45e25 | 13122 | ui_out_redirect (current_uiout, fp); |
14dba4b4 | 13123 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 13124 | { |
79a45e25 | 13125 | print_command_lines (current_uiout, tp->commands->commands, 2); |
a7bdde9e | 13126 | } |
79a45e25 | 13127 | ui_out_redirect (current_uiout, NULL); |
1042e4c0 | 13128 | |
a7bdde9e VP |
13129 | if (ex.reason < 0) |
13130 | throw_exception (ex); | |
1042e4c0 | 13131 | |
a7bdde9e | 13132 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 13133 | } |
6149aea9 PA |
13134 | |
13135 | if (tp->enable_state == bp_disabled) | |
13136 | fprintf_unfiltered (fp, "disable\n"); | |
13137 | ||
13138 | /* If this is a multi-location breakpoint, check if the locations | |
13139 | should be individually disabled. Watchpoint locations are | |
13140 | special, and not user visible. */ | |
13141 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
13142 | { | |
13143 | struct bp_location *loc; | |
13144 | int n = 1; | |
13145 | ||
13146 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
13147 | if (!loc->enabled) | |
13148 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
13149 | } | |
1042e4c0 | 13150 | } |
8bf6485c | 13151 | |
6149aea9 | 13152 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
13153 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
13154 | ||
1042e4c0 SS |
13155 | do_cleanups (cleanup); |
13156 | if (from_tty) | |
6149aea9 PA |
13157 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
13158 | } | |
13159 | ||
13160 | /* The `save breakpoints' command. */ | |
13161 | ||
13162 | static void | |
13163 | save_breakpoints_command (char *args, int from_tty) | |
13164 | { | |
13165 | save_breakpoints (args, from_tty, NULL); | |
13166 | } | |
13167 | ||
13168 | /* The `save tracepoints' command. */ | |
13169 | ||
13170 | static void | |
13171 | save_tracepoints_command (char *args, int from_tty) | |
13172 | { | |
13173 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
13174 | } |
13175 | ||
13176 | /* Create a vector of all tracepoints. */ | |
13177 | ||
13178 | VEC(breakpoint_p) * | |
eeae04df | 13179 | all_tracepoints (void) |
1042e4c0 SS |
13180 | { |
13181 | VEC(breakpoint_p) *tp_vec = 0; | |
13182 | struct breakpoint *tp; | |
13183 | ||
13184 | ALL_TRACEPOINTS (tp) | |
13185 | { | |
13186 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
13187 | } | |
13188 | ||
13189 | return tp_vec; | |
13190 | } | |
13191 | ||
c906108c | 13192 | \f |
4a64f543 MS |
13193 | /* This help string is used for the break, hbreak, tbreak and thbreak |
13194 | commands. It is defined as a macro to prevent duplication. | |
13195 | COMMAND should be a string constant containing the name of the | |
13196 | command. */ | |
31e2b00f AS |
13197 | #define BREAK_ARGS_HELP(command) \ |
13198 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
13199 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
13200 | If a line number is specified, break at start of code for that line.\n\ | |
13201 | If a function is specified, break at start of code for that function.\n\ | |
13202 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
13203 | With no LOCATION, uses current execution address of the selected\n\ |
13204 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
13205 | \n\ |
13206 | THREADNUM is the number from \"info threads\".\n\ | |
13207 | CONDITION is a boolean expression.\n\ | |
13208 | \n\ | |
d41c0fc8 PA |
13209 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
13210 | conditions are different.\n\ | |
31e2b00f AS |
13211 | \n\ |
13212 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
13213 | ||
44feb3ce TT |
13214 | /* List of subcommands for "catch". */ |
13215 | static struct cmd_list_element *catch_cmdlist; | |
13216 | ||
13217 | /* List of subcommands for "tcatch". */ | |
13218 | static struct cmd_list_element *tcatch_cmdlist; | |
13219 | ||
9ac4176b | 13220 | void |
44feb3ce TT |
13221 | add_catch_command (char *name, char *docstring, |
13222 | void (*sfunc) (char *args, int from_tty, | |
13223 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
13224 | char **(*completer) (struct cmd_list_element *cmd, |
13225 | char *text, char *word), | |
44feb3ce TT |
13226 | void *user_data_catch, |
13227 | void *user_data_tcatch) | |
13228 | { | |
13229 | struct cmd_list_element *command; | |
13230 | ||
13231 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13232 | &catch_cmdlist); | |
13233 | set_cmd_sfunc (command, sfunc); | |
13234 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 13235 | set_cmd_completer (command, completer); |
44feb3ce TT |
13236 | |
13237 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13238 | &tcatch_cmdlist); | |
13239 | set_cmd_sfunc (command, sfunc); | |
13240 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 13241 | set_cmd_completer (command, completer); |
44feb3ce TT |
13242 | } |
13243 | ||
6c95b8df | 13244 | static void |
a79b8f6e | 13245 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 13246 | { |
6c95b8df PA |
13247 | inf->total_syscalls_count = 0; |
13248 | inf->any_syscall_count = 0; | |
13249 | VEC_free (int, inf->syscalls_counts); | |
13250 | } | |
13251 | ||
6149aea9 PA |
13252 | static void |
13253 | save_command (char *arg, int from_tty) | |
13254 | { | |
3e43a32a MS |
13255 | printf_unfiltered (_("\"save\" must be followed by " |
13256 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
13257 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
13258 | } | |
13259 | ||
84f4c1fe PM |
13260 | struct breakpoint * |
13261 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
13262 | void *data) | |
13263 | { | |
35df4500 | 13264 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 13265 | |
35df4500 | 13266 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
13267 | { |
13268 | if ((*callback) (b, data)) | |
13269 | return b; | |
13270 | } | |
13271 | ||
13272 | return NULL; | |
13273 | } | |
13274 | ||
2060206e PA |
13275 | void |
13276 | initialize_breakpoint_ops (void) | |
13277 | { | |
13278 | static int initialized = 0; | |
13279 | ||
13280 | struct breakpoint_ops *ops; | |
13281 | ||
13282 | if (initialized) | |
13283 | return; | |
13284 | initialized = 1; | |
13285 | ||
13286 | /* The breakpoint_ops structure to be inherit by all kinds of | |
13287 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
13288 | internal and momentary breakpoints, etc.). */ | |
13289 | ops = &bkpt_base_breakpoint_ops; | |
13290 | *ops = base_breakpoint_ops; | |
13291 | ops->re_set = bkpt_re_set; | |
13292 | ops->insert_location = bkpt_insert_location; | |
13293 | ops->remove_location = bkpt_remove_location; | |
13294 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
13295 | ||
13296 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
13297 | ops = &bkpt_breakpoint_ops; | |
13298 | *ops = bkpt_base_breakpoint_ops; | |
13299 | ops->re_set = bkpt_re_set; | |
13300 | ops->resources_needed = bkpt_resources_needed; | |
13301 | ops->print_it = bkpt_print_it; | |
13302 | ops->print_mention = bkpt_print_mention; | |
13303 | ops->print_recreate = bkpt_print_recreate; | |
13304 | ||
13305 | /* Ranged breakpoints. */ | |
13306 | ops = &ranged_breakpoint_ops; | |
13307 | *ops = bkpt_breakpoint_ops; | |
13308 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
13309 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
13310 | ops->print_it = print_it_ranged_breakpoint; | |
13311 | ops->print_one = print_one_ranged_breakpoint; | |
13312 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
13313 | ops->print_mention = print_mention_ranged_breakpoint; | |
13314 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
13315 | ||
13316 | /* Internal breakpoints. */ | |
13317 | ops = &internal_breakpoint_ops; | |
13318 | *ops = bkpt_base_breakpoint_ops; | |
13319 | ops->re_set = internal_bkpt_re_set; | |
13320 | ops->check_status = internal_bkpt_check_status; | |
13321 | ops->print_it = internal_bkpt_print_it; | |
13322 | ops->print_mention = internal_bkpt_print_mention; | |
13323 | ||
13324 | /* Momentary breakpoints. */ | |
13325 | ops = &momentary_breakpoint_ops; | |
13326 | *ops = bkpt_base_breakpoint_ops; | |
13327 | ops->re_set = momentary_bkpt_re_set; | |
13328 | ops->check_status = momentary_bkpt_check_status; | |
13329 | ops->print_it = momentary_bkpt_print_it; | |
13330 | ops->print_mention = momentary_bkpt_print_mention; | |
13331 | ||
13332 | /* GNU v3 exception catchpoints. */ | |
13333 | ops = &gnu_v3_exception_catchpoint_ops; | |
13334 | *ops = bkpt_breakpoint_ops; | |
13335 | ops->print_it = print_it_exception_catchpoint; | |
13336 | ops->print_one = print_one_exception_catchpoint; | |
13337 | ops->print_mention = print_mention_exception_catchpoint; | |
13338 | ops->print_recreate = print_recreate_exception_catchpoint; | |
13339 | ||
13340 | /* Watchpoints. */ | |
13341 | ops = &watchpoint_breakpoint_ops; | |
13342 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 13343 | ops->dtor = dtor_watchpoint; |
2060206e PA |
13344 | ops->re_set = re_set_watchpoint; |
13345 | ops->insert_location = insert_watchpoint; | |
13346 | ops->remove_location = remove_watchpoint; | |
13347 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
13348 | ops->check_status = check_status_watchpoint; | |
13349 | ops->resources_needed = resources_needed_watchpoint; | |
13350 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
13351 | ops->print_it = print_it_watchpoint; | |
13352 | ops->print_mention = print_mention_watchpoint; | |
13353 | ops->print_recreate = print_recreate_watchpoint; | |
13354 | ||
13355 | /* Masked watchpoints. */ | |
13356 | ops = &masked_watchpoint_breakpoint_ops; | |
13357 | *ops = watchpoint_breakpoint_ops; | |
13358 | ops->insert_location = insert_masked_watchpoint; | |
13359 | ops->remove_location = remove_masked_watchpoint; | |
13360 | ops->resources_needed = resources_needed_masked_watchpoint; | |
13361 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
13362 | ops->print_it = print_it_masked_watchpoint; | |
13363 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
13364 | ops->print_mention = print_mention_masked_watchpoint; | |
13365 | ops->print_recreate = print_recreate_masked_watchpoint; | |
13366 | ||
13367 | /* Tracepoints. */ | |
13368 | ops = &tracepoint_breakpoint_ops; | |
13369 | *ops = base_breakpoint_ops; | |
13370 | ops->re_set = tracepoint_re_set; | |
13371 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
13372 | ops->print_one_detail = tracepoint_print_one_detail; | |
13373 | ops->print_mention = tracepoint_print_mention; | |
13374 | ops->print_recreate = tracepoint_print_recreate; | |
13375 | ||
13376 | /* Fork catchpoints. */ | |
13377 | ops = &catch_fork_breakpoint_ops; | |
13378 | *ops = base_breakpoint_ops; | |
13379 | ops->insert_location = insert_catch_fork; | |
13380 | ops->remove_location = remove_catch_fork; | |
13381 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
13382 | ops->print_it = print_it_catch_fork; | |
13383 | ops->print_one = print_one_catch_fork; | |
13384 | ops->print_mention = print_mention_catch_fork; | |
13385 | ops->print_recreate = print_recreate_catch_fork; | |
13386 | ||
13387 | /* Vfork catchpoints. */ | |
13388 | ops = &catch_vfork_breakpoint_ops; | |
13389 | *ops = base_breakpoint_ops; | |
13390 | ops->insert_location = insert_catch_vfork; | |
13391 | ops->remove_location = remove_catch_vfork; | |
13392 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
13393 | ops->print_it = print_it_catch_vfork; | |
13394 | ops->print_one = print_one_catch_vfork; | |
13395 | ops->print_mention = print_mention_catch_vfork; | |
13396 | ops->print_recreate = print_recreate_catch_vfork; | |
13397 | ||
13398 | /* Exec catchpoints. */ | |
13399 | ops = &catch_exec_breakpoint_ops; | |
13400 | *ops = base_breakpoint_ops; | |
13401 | ops->dtor = dtor_catch_exec; | |
13402 | ops->insert_location = insert_catch_exec; | |
13403 | ops->remove_location = remove_catch_exec; | |
13404 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
13405 | ops->print_it = print_it_catch_exec; | |
13406 | ops->print_one = print_one_catch_exec; | |
13407 | ops->print_mention = print_mention_catch_exec; | |
13408 | ops->print_recreate = print_recreate_catch_exec; | |
13409 | ||
13410 | /* Syscall catchpoints. */ | |
13411 | ops = &catch_syscall_breakpoint_ops; | |
13412 | *ops = base_breakpoint_ops; | |
13413 | ops->dtor = dtor_catch_syscall; | |
13414 | ops->insert_location = insert_catch_syscall; | |
13415 | ops->remove_location = remove_catch_syscall; | |
13416 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
13417 | ops->print_it = print_it_catch_syscall; | |
13418 | ops->print_one = print_one_catch_syscall; | |
13419 | ops->print_mention = print_mention_catch_syscall; | |
13420 | ops->print_recreate = print_recreate_catch_syscall; | |
13421 | } | |
13422 | ||
c906108c | 13423 | void |
fba45db2 | 13424 | _initialize_breakpoint (void) |
c906108c SS |
13425 | { |
13426 | struct cmd_list_element *c; | |
13427 | ||
2060206e PA |
13428 | initialize_breakpoint_ops (); |
13429 | ||
84acb35a | 13430 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 13431 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 13432 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 13433 | |
17450429 PP |
13434 | breakpoint_objfile_key = register_objfile_data (); |
13435 | ||
c906108c SS |
13436 | breakpoint_chain = 0; |
13437 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
13438 | before a breakpoint is set. */ | |
13439 | breakpoint_count = 0; | |
13440 | ||
1042e4c0 SS |
13441 | tracepoint_count = 0; |
13442 | ||
1bedd215 AC |
13443 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
13444 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
13445 | Usage is `ignore N COUNT'.")); | |
c906108c | 13446 | if (xdb_commands) |
c5aa993b | 13447 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 13448 | |
1bedd215 AC |
13449 | add_com ("commands", class_breakpoint, commands_command, _("\ |
13450 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
13451 | Give breakpoint number as argument after \"commands\".\n\ |
13452 | With no argument, the targeted breakpoint is the last one set.\n\ | |
13453 | The commands themselves follow starting on the next line.\n\ | |
13454 | Type a line containing \"end\" to indicate the end of them.\n\ | |
13455 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 13456 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 13457 | |
1bedd215 AC |
13458 | add_com ("condition", class_breakpoint, condition_command, _("\ |
13459 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 13460 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 13461 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 13462 | |
1bedd215 | 13463 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 13464 | Set a temporary breakpoint.\n\ |
c906108c SS |
13465 | Like \"break\" except the breakpoint is only temporary,\n\ |
13466 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
13467 | by using \"enable delete\" on the breakpoint number.\n\ |
13468 | \n" | |
13469 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 13470 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13471 | |
1bedd215 | 13472 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 13473 | Set a hardware assisted breakpoint.\n\ |
c906108c | 13474 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
13475 | some target hardware may not have this support.\n\ |
13476 | \n" | |
13477 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 13478 | set_cmd_completer (c, location_completer); |
c906108c | 13479 | |
1bedd215 | 13480 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 13481 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 13482 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
13483 | so it will be deleted when hit.\n\ |
13484 | \n" | |
13485 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 13486 | set_cmd_completer (c, location_completer); |
c906108c | 13487 | |
1bedd215 AC |
13488 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
13489 | Enable some breakpoints.\n\ | |
c906108c SS |
13490 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13491 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13492 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13493 | With a subcommand you can enable temporarily."), |
c906108c SS |
13494 | &enablelist, "enable ", 1, &cmdlist); |
13495 | if (xdb_commands) | |
1bedd215 AC |
13496 | add_com ("ab", class_breakpoint, enable_command, _("\ |
13497 | Enable some breakpoints.\n\ | |
c906108c SS |
13498 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13499 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13500 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13501 | With a subcommand you can enable temporarily.")); |
c906108c SS |
13502 | |
13503 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
13504 | ||
84951ab5 | 13505 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 13506 | Enable some breakpoints.\n\ |
c906108c SS |
13507 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13508 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13509 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 13510 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 13511 | |
1a966eab AC |
13512 | add_cmd ("once", no_class, enable_once_command, _("\ |
13513 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13514 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13515 | &enablebreaklist); |
13516 | ||
1a966eab AC |
13517 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13518 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13519 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13520 | &enablebreaklist); |
13521 | ||
1a966eab AC |
13522 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13523 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13524 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13525 | &enablelist); |
13526 | ||
1a966eab AC |
13527 | add_cmd ("once", no_class, enable_once_command, _("\ |
13528 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13529 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13530 | &enablelist); |
13531 | ||
1bedd215 AC |
13532 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
13533 | Disable some breakpoints.\n\ | |
c906108c SS |
13534 | Arguments are breakpoint numbers with spaces in between.\n\ |
13535 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13536 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
13537 | &disablelist, "disable ", 1, &cmdlist); |
13538 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
13539 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
13540 | if (xdb_commands) | |
1bedd215 AC |
13541 | add_com ("sb", class_breakpoint, disable_command, _("\ |
13542 | Disable some breakpoints.\n\ | |
c906108c SS |
13543 | Arguments are breakpoint numbers with spaces in between.\n\ |
13544 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13545 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 13546 | |
1a966eab AC |
13547 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
13548 | Disable some breakpoints.\n\ | |
c906108c SS |
13549 | Arguments are breakpoint numbers with spaces in between.\n\ |
13550 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13551 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 13552 | This command may be abbreviated \"disable\"."), |
c906108c SS |
13553 | &disablelist); |
13554 | ||
1bedd215 AC |
13555 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
13556 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13557 | Arguments are breakpoint numbers with spaces in between.\n\ |
13558 | To delete all breakpoints, give no argument.\n\ | |
13559 | \n\ | |
13560 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 13561 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
13562 | &deletelist, "delete ", 1, &cmdlist); |
13563 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 13564 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 13565 | if (xdb_commands) |
1bedd215 AC |
13566 | add_com ("db", class_breakpoint, delete_command, _("\ |
13567 | Delete some breakpoints.\n\ | |
c906108c | 13568 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 13569 | To delete all breakpoints, give no argument.\n")); |
c906108c | 13570 | |
1a966eab AC |
13571 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
13572 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13573 | Arguments are breakpoint numbers with spaces in between.\n\ |
13574 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 13575 | This command may be abbreviated \"delete\"."), |
c906108c SS |
13576 | &deletelist); |
13577 | ||
1bedd215 AC |
13578 | add_com ("clear", class_breakpoint, clear_command, _("\ |
13579 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
13580 | Argument may be line number, function name, or \"*\" and an address.\n\ |
13581 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
13582 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
13583 | If an address is specified, breakpoints at that address are cleared.\n\ |
13584 | \n\ | |
13585 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
13586 | is executing in.\n\ |
13587 | \n\ | |
1bedd215 | 13588 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 13589 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 13590 | |
1bedd215 | 13591 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
13592 | Set breakpoint at specified line or function.\n" |
13593 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 13594 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13595 | |
c906108c SS |
13596 | add_com_alias ("b", "break", class_run, 1); |
13597 | add_com_alias ("br", "break", class_run, 1); | |
13598 | add_com_alias ("bre", "break", class_run, 1); | |
13599 | add_com_alias ("brea", "break", class_run, 1); | |
13600 | ||
7681d515 PM |
13601 | if (xdb_commands) |
13602 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
13603 | |
13604 | if (dbx_commands) | |
13605 | { | |
1bedd215 AC |
13606 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
13607 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
13608 | &stoplist, "stop ", 1, &cmdlist); |
13609 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 13610 | _("Break in function or address."), &stoplist); |
c5aa993b | 13611 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 13612 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
13613 | add_com ("status", class_info, breakpoints_info, _("\ |
13614 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13615 | The \"Type\" column indicates one of:\n\ |
13616 | \tbreakpoint - normal breakpoint\n\ | |
13617 | \twatchpoint - watchpoint\n\ | |
13618 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13619 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13620 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13621 | address and file/line number respectively.\n\ |
13622 | \n\ | |
13623 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13624 | are set to the address of the last breakpoint listed unless the command\n\ |
13625 | is prefixed with \"server \".\n\n\ | |
c906108c | 13626 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13627 | breakpoint set.")); |
c906108c SS |
13628 | } |
13629 | ||
1bedd215 | 13630 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 13631 | Status of specified breakpoints (all user-settable breakpoints if no argument).\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 | |
6b04bdb7 MS |
13646 | add_info_alias ("b", "breakpoints", 1); |
13647 | ||
c906108c | 13648 | if (xdb_commands) |
1bedd215 AC |
13649 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
13650 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13651 | The \"Type\" column indicates one of:\n\ |
13652 | \tbreakpoint - normal breakpoint\n\ | |
13653 | \twatchpoint - watchpoint\n\ | |
13654 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13655 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13656 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13657 | address and file/line number respectively.\n\ |
13658 | \n\ | |
13659 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13660 | are set to the address of the last breakpoint listed unless the command\n\ |
13661 | is prefixed with \"server \".\n\n\ | |
c906108c | 13662 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13663 | breakpoint set.")); |
c906108c | 13664 | |
1a966eab AC |
13665 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
13666 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13667 | The \"Type\" column indicates one of:\n\ |
13668 | \tbreakpoint - normal breakpoint\n\ | |
13669 | \twatchpoint - watchpoint\n\ | |
13670 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
13671 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
13672 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
13673 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
13674 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
13675 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
13676 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
13677 | address and file/line number respectively.\n\ |
13678 | \n\ | |
13679 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13680 | are set to the address of the last breakpoint listed unless the command\n\ |
13681 | is prefixed with \"server \".\n\n\ | |
c906108c | 13682 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 13683 | breakpoint set."), |
c906108c SS |
13684 | &maintenanceinfolist); |
13685 | ||
44feb3ce TT |
13686 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
13687 | Set catchpoints to catch events."), | |
13688 | &catch_cmdlist, "catch ", | |
13689 | 0/*allow-unknown*/, &cmdlist); | |
13690 | ||
13691 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
13692 | Set temporary catchpoints to catch events."), | |
13693 | &tcatch_cmdlist, "tcatch ", | |
13694 | 0/*allow-unknown*/, &cmdlist); | |
13695 | ||
13696 | /* Add catch and tcatch sub-commands. */ | |
13697 | add_catch_command ("catch", _("\ | |
13698 | Catch an exception, when caught.\n\ | |
13699 | With an argument, catch only exceptions with the given name."), | |
13700 | catch_catch_command, | |
a96d9b2e | 13701 | NULL, |
44feb3ce TT |
13702 | CATCH_PERMANENT, |
13703 | CATCH_TEMPORARY); | |
13704 | add_catch_command ("throw", _("\ | |
13705 | Catch an exception, when thrown.\n\ | |
13706 | With an argument, catch only exceptions with the given name."), | |
13707 | catch_throw_command, | |
a96d9b2e | 13708 | NULL, |
44feb3ce TT |
13709 | CATCH_PERMANENT, |
13710 | CATCH_TEMPORARY); | |
13711 | add_catch_command ("fork", _("Catch calls to fork."), | |
13712 | catch_fork_command_1, | |
a96d9b2e | 13713 | NULL, |
44feb3ce TT |
13714 | (void *) (uintptr_t) catch_fork_permanent, |
13715 | (void *) (uintptr_t) catch_fork_temporary); | |
13716 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
13717 | catch_fork_command_1, | |
a96d9b2e | 13718 | NULL, |
44feb3ce TT |
13719 | (void *) (uintptr_t) catch_vfork_permanent, |
13720 | (void *) (uintptr_t) catch_vfork_temporary); | |
13721 | add_catch_command ("exec", _("Catch calls to exec."), | |
13722 | catch_exec_command_1, | |
a96d9b2e SDJ |
13723 | NULL, |
13724 | CATCH_PERMANENT, | |
13725 | CATCH_TEMPORARY); | |
13726 | add_catch_command ("syscall", _("\ | |
13727 | Catch system calls by their names and/or numbers.\n\ | |
13728 | Arguments say which system calls to catch. If no arguments\n\ | |
13729 | are given, every system call will be caught.\n\ | |
13730 | Arguments, if given, should be one or more system call names\n\ | |
13731 | (if your system supports that), or system call numbers."), | |
13732 | catch_syscall_command_1, | |
13733 | catch_syscall_completer, | |
44feb3ce TT |
13734 | CATCH_PERMANENT, |
13735 | CATCH_TEMPORARY); | |
c5aa993b | 13736 | |
1bedd215 AC |
13737 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
13738 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13739 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 13740 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13741 | an expression changes.\n\ |
13742 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13743 | the memory to which it refers.")); | |
65d12d83 | 13744 | set_cmd_completer (c, expression_completer); |
c906108c | 13745 | |
1bedd215 AC |
13746 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
13747 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 13748 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 13749 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13750 | an expression is read.\n\ |
13751 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13752 | the memory to which it refers.")); | |
65d12d83 | 13753 | set_cmd_completer (c, expression_completer); |
c906108c | 13754 | |
1bedd215 AC |
13755 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
13756 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13757 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 13758 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13759 | an expression is either read or written.\n\ |
13760 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13761 | the memory to which it refers.")); | |
65d12d83 | 13762 | set_cmd_completer (c, expression_completer); |
c906108c | 13763 | |
d77f58be | 13764 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 13765 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 13766 | |
920d2a44 AC |
13767 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
13768 | respond to changes - contrary to the description. */ | |
85c07804 AC |
13769 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
13770 | &can_use_hw_watchpoints, _("\ | |
13771 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
13772 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
13773 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
13774 | such is available. (However, any hardware watchpoints that were\n\ | |
13775 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
13776 | hardware.)"), |
13777 | NULL, | |
920d2a44 | 13778 | show_can_use_hw_watchpoints, |
85c07804 | 13779 | &setlist, &showlist); |
c906108c SS |
13780 | |
13781 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 13782 | |
1042e4c0 SS |
13783 | /* Tracepoint manipulation commands. */ |
13784 | ||
13785 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
13786 | Set a tracepoint at specified line or function.\n\ | |
13787 | \n" | |
13788 | BREAK_ARGS_HELP ("trace") "\n\ | |
13789 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13790 | set_cmd_completer (c, location_completer); | |
13791 | ||
13792 | add_com_alias ("tp", "trace", class_alias, 0); | |
13793 | add_com_alias ("tr", "trace", class_alias, 1); | |
13794 | add_com_alias ("tra", "trace", class_alias, 1); | |
13795 | add_com_alias ("trac", "trace", class_alias, 1); | |
13796 | ||
7a697b8d SS |
13797 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
13798 | Set a fast tracepoint at specified line or function.\n\ | |
13799 | \n" | |
13800 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
13801 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13802 | set_cmd_completer (c, location_completer); | |
13803 | ||
0fb4aa4b PA |
13804 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
13805 | Set a static tracepoint at specified line, function or marker.\n\ | |
13806 | \n\ | |
13807 | strace [LOCATION] [if CONDITION]\n\ | |
13808 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
13809 | or -m MARKER_ID.\n\ | |
13810 | If a line number is specified, probe the marker at start of code\n\ | |
13811 | for that line. If a function is specified, probe the marker at start\n\ | |
13812 | of code for that function. If an address is specified, probe the marker\n\ | |
13813 | at that exact address. If a marker id is specified, probe the marker\n\ | |
13814 | with that name. With no LOCATION, uses current execution address of\n\ | |
13815 | the selected stack frame.\n\ | |
13816 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
13817 | This collects arbitrary user data passed in the probe point call to the\n\ | |
13818 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
13819 | by printing the $_sdata variable like any other convenience variable.\n\ | |
13820 | \n\ | |
13821 | CONDITION is a boolean expression.\n\ | |
13822 | \n\ | |
d41c0fc8 PA |
13823 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
13824 | conditions are different.\n\ | |
0fb4aa4b PA |
13825 | \n\ |
13826 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
13827 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13828 | set_cmd_completer (c, location_completer); | |
13829 | ||
1042e4c0 | 13830 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 13831 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
13832 | Convenience variable \"$tpnum\" contains the number of the\n\ |
13833 | last tracepoint set.")); | |
13834 | ||
13835 | add_info_alias ("tp", "tracepoints", 1); | |
13836 | ||
13837 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
13838 | Delete specified tracepoints.\n\ | |
13839 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13840 | No argument means delete all tracepoints."), | |
13841 | &deletelist); | |
13842 | ||
13843 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
13844 | Disable specified tracepoints.\n\ | |
13845 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13846 | No argument means disable all tracepoints."), | |
13847 | &disablelist); | |
13848 | deprecate_cmd (c, "disable"); | |
13849 | ||
13850 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
13851 | Enable specified tracepoints.\n\ | |
13852 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13853 | No argument means enable all tracepoints."), | |
13854 | &enablelist); | |
13855 | deprecate_cmd (c, "enable"); | |
13856 | ||
13857 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
13858 | Set the passcount for a tracepoint.\n\ | |
13859 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
13860 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
13861 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
13862 | ||
6149aea9 PA |
13863 | add_prefix_cmd ("save", class_breakpoint, save_command, |
13864 | _("Save breakpoint definitions as a script."), | |
13865 | &save_cmdlist, "save ", | |
13866 | 0/*allow-unknown*/, &cmdlist); | |
13867 | ||
13868 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
13869 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 13870 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
13871 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
13872 | session to restore them."), | |
13873 | &save_cmdlist); | |
13874 | set_cmd_completer (c, filename_completer); | |
13875 | ||
13876 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 13877 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
13878 | Use the 'source' command in another debug session to restore them."), |
13879 | &save_cmdlist); | |
1042e4c0 SS |
13880 | set_cmd_completer (c, filename_completer); |
13881 | ||
6149aea9 PA |
13882 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
13883 | deprecate_cmd (c, "save tracepoints"); | |
13884 | ||
1bedd215 | 13885 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13886 | Breakpoint specific settings\n\ |
13887 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13888 | pending breakpoint behavior"), |
fa8d40ab JJ |
13889 | &breakpoint_set_cmdlist, "set breakpoint ", |
13890 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 13891 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13892 | Breakpoint specific settings\n\ |
13893 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13894 | pending breakpoint behavior"), |
fa8d40ab JJ |
13895 | &breakpoint_show_cmdlist, "show breakpoint ", |
13896 | 0/*allow-unknown*/, &showlist); | |
13897 | ||
7915a72c AC |
13898 | add_setshow_auto_boolean_cmd ("pending", no_class, |
13899 | &pending_break_support, _("\ | |
13900 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
13901 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
13902 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
13903 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
13904 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 13905 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 13906 | NULL, |
920d2a44 | 13907 | show_pending_break_support, |
6e1d7d6c AC |
13908 | &breakpoint_set_cmdlist, |
13909 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
13910 | |
13911 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
13912 | |
13913 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
13914 | &automatic_hardware_breakpoints, _("\ | |
13915 | Set automatic usage of hardware breakpoints."), _("\ | |
13916 | Show automatic usage of hardware breakpoints."), _("\ | |
13917 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
13918 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
13919 | a warning will be emitted for such breakpoints."), | |
13920 | NULL, | |
13921 | show_automatic_hardware_breakpoints, | |
13922 | &breakpoint_set_cmdlist, | |
13923 | &breakpoint_show_cmdlist); | |
74960c60 | 13924 | |
33e5cbd6 PA |
13925 | add_setshow_enum_cmd ("always-inserted", class_support, |
13926 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
13927 | Set mode for inserting breakpoints."), _("\ |
13928 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
13929 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
13930 | resumed, and removed when execution stops. When this mode is on,\n\ | |
13931 | breakpoints are inserted immediately and removed only when the user\n\ | |
13932 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
13933 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
13934 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
13935 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
13936 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
13937 | NULL, |
13938 | &show_always_inserted_mode, | |
13939 | &breakpoint_set_cmdlist, | |
13940 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
13941 | |
13942 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
13943 | Set a breakpoint for an address range.\n\ | |
13944 | break-range START-LOCATION, END-LOCATION\n\ | |
13945 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
13946 | LINENUM, for that line in the current file,\n\ | |
13947 | FILE:LINENUM, for that line in that file,\n\ | |
13948 | +OFFSET, for that number of lines after the current line\n\ | |
13949 | or the start of the range\n\ | |
13950 | FUNCTION, for the first line in that function,\n\ | |
13951 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
13952 | *ADDRESS, for the instruction at that address.\n\ | |
13953 | \n\ | |
13954 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
13955 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
13956 | range (including START-LOCATION and END-LOCATION).")); | |
13957 | ||
765dc015 | 13958 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
13959 | |
13960 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 13961 | } |