Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
7b6bb8da | 5 | 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
a6d9a66e | 23 | #include "arch-utils.h" |
c906108c | 24 | #include <ctype.h> |
776592bf | 25 | #include "hashtab.h" |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
1042e4c0 | 29 | #include "tracepoint.h" |
c906108c SS |
30 | #include "gdbtypes.h" |
31 | #include "expression.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "value.h" | |
35 | #include "command.h" | |
36 | #include "inferior.h" | |
37 | #include "gdbthread.h" | |
38 | #include "target.h" | |
39 | #include "language.h" | |
40 | #include "gdb_string.h" | |
41 | #include "demangle.h" | |
0ba1096a | 42 | #include "filenames.h" |
c906108c SS |
43 | #include "annotate.h" |
44 | #include "symfile.h" | |
45 | #include "objfiles.h" | |
0378c332 | 46 | #include "source.h" |
c5f0f3d0 | 47 | #include "linespec.h" |
c94fdfd0 | 48 | #include "completer.h" |
5b7f31a4 | 49 | #include "gdb.h" |
8b93c638 | 50 | #include "ui-out.h" |
e1507482 | 51 | #include "cli/cli-script.h" |
0225421b | 52 | #include "gdb_assert.h" |
fe898f56 | 53 | #include "block.h" |
a77053c2 | 54 | #include "solib.h" |
84acb35a JJ |
55 | #include "solist.h" |
56 | #include "observer.h" | |
60250e8b | 57 | #include "exceptions.h" |
765dc015 | 58 | #include "memattr.h" |
f7f9143b | 59 | #include "ada-lang.h" |
d1aa2f50 | 60 | #include "top.h" |
fa4727a6 | 61 | #include "wrapper.h" |
79a45b7d | 62 | #include "valprint.h" |
4efc6507 | 63 | #include "jit.h" |
a96d9b2e | 64 | #include "xml-syscall.h" |
65d79d4b | 65 | #include "parser-defs.h" |
e9cafbcc | 66 | #include "cli/cli-utils.h" |
be34f849 | 67 | #include "continuations.h" |
c906108c | 68 | |
1042e4c0 SS |
69 | /* readline include files */ |
70 | #include "readline/readline.h" | |
71 | #include "readline/history.h" | |
72 | ||
73 | /* readline defines this. */ | |
74 | #undef savestring | |
75 | ||
034dad6f | 76 | #include "mi/mi-common.h" |
7371cf6d | 77 | #include "python/python.h" |
104c1213 | 78 | |
4a64f543 | 79 | /* Prototypes for local functions. */ |
c906108c | 80 | |
a14ed312 | 81 | static void enable_delete_command (char *, int); |
c906108c | 82 | |
a14ed312 | 83 | static void enable_once_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static void disable_command (char *, int); |
c906108c | 86 | |
a14ed312 | 87 | static void enable_command (char *, int); |
c906108c | 88 | |
95a42b64 TT |
89 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
90 | void *), | |
91 | void *); | |
c906108c | 92 | |
a14ed312 | 93 | static void ignore_command (char *, int); |
c906108c | 94 | |
4efb68b1 | 95 | static int breakpoint_re_set_one (void *); |
c906108c | 96 | |
348d480f PA |
97 | static void breakpoint_re_set_default (struct breakpoint *); |
98 | ||
a14ed312 | 99 | static void clear_command (char *, int); |
c906108c | 100 | |
a14ed312 | 101 | static void catch_command (char *, int); |
c906108c | 102 | |
a9634178 | 103 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 104 | |
98deb0da | 105 | static void break_command_1 (char *, int, int); |
c906108c | 106 | |
a14ed312 | 107 | static void mention (struct breakpoint *); |
c906108c | 108 | |
348d480f PA |
109 | static struct breakpoint *set_raw_breakpoint_without_location (struct gdbarch *, |
110 | enum bptype, | |
c0a91b2b | 111 | const struct breakpoint_ops *); |
4a64f543 MS |
112 | /* This function is used in gdbtk sources and thus can not be made |
113 | static. */ | |
63c252f8 | 114 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
348d480f | 115 | struct symtab_and_line, |
c0a91b2b TT |
116 | enum bptype, |
117 | const struct breakpoint_ops *); | |
c906108c | 118 | |
06edf0c0 PA |
119 | static struct breakpoint * |
120 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
121 | enum bptype type, | |
c0a91b2b | 122 | const struct breakpoint_ops *ops); |
06edf0c0 | 123 | |
76897487 KB |
124 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
125 | ||
a6d9a66e UW |
126 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
127 | CORE_ADDR bpaddr, | |
88f7da05 | 128 | enum bptype bptype); |
76897487 | 129 | |
6c95b8df PA |
130 | static void describe_other_breakpoints (struct gdbarch *, |
131 | struct program_space *, CORE_ADDR, | |
5af949e3 | 132 | struct obj_section *, int); |
c906108c | 133 | |
6c95b8df PA |
134 | static int breakpoint_address_match (struct address_space *aspace1, |
135 | CORE_ADDR addr1, | |
136 | struct address_space *aspace2, | |
137 | CORE_ADDR addr2); | |
138 | ||
85d721b8 PA |
139 | static int watchpoint_locations_match (struct bp_location *loc1, |
140 | struct bp_location *loc2); | |
141 | ||
f1310107 TJB |
142 | static int breakpoint_location_address_match (struct bp_location *bl, |
143 | struct address_space *aspace, | |
144 | CORE_ADDR addr); | |
145 | ||
a14ed312 | 146 | static void breakpoints_info (char *, int); |
c906108c | 147 | |
d77f58be SS |
148 | static void watchpoints_info (char *, int); |
149 | ||
e5a67952 MS |
150 | static int breakpoint_1 (char *, int, |
151 | int (*) (const struct breakpoint *)); | |
c906108c | 152 | |
4efb68b1 | 153 | static int breakpoint_cond_eval (void *); |
c906108c | 154 | |
4efb68b1 | 155 | static void cleanup_executing_breakpoints (void *); |
c906108c | 156 | |
a14ed312 | 157 | static void commands_command (char *, int); |
c906108c | 158 | |
a14ed312 | 159 | static void condition_command (char *, int); |
c906108c | 160 | |
c5aa993b JM |
161 | typedef enum |
162 | { | |
163 | mark_inserted, | |
164 | mark_uninserted | |
165 | } | |
166 | insertion_state_t; | |
c906108c | 167 | |
0bde7532 | 168 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 169 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 170 | |
e514a9d6 | 171 | static enum print_stop_action print_bp_stop_message (bpstat bs); |
c906108c | 172 | |
4efb68b1 | 173 | static int watchpoint_check (void *); |
c906108c | 174 | |
a14ed312 | 175 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 176 | |
a14ed312 | 177 | static int hw_breakpoint_used_count (void); |
c906108c | 178 | |
a14ed312 | 179 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 180 | |
a14ed312 | 181 | static void hbreak_command (char *, int); |
c906108c | 182 | |
a14ed312 | 183 | static void thbreak_command (char *, int); |
c906108c | 184 | |
51be5b68 | 185 | static void enable_breakpoint_disp (struct breakpoint *, enum bpdisp); |
c906108c | 186 | |
a14ed312 | 187 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 188 | |
a14ed312 | 189 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 190 | |
a14ed312 | 191 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 192 | |
a14ed312 | 193 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 194 | |
d85310f7 MS |
195 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
196 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 197 | |
a14ed312 | 198 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 199 | |
d03285ec UW |
200 | static void detach_single_step_breakpoints (void); |
201 | ||
6c95b8df PA |
202 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
203 | CORE_ADDR pc); | |
1aafd4da | 204 | |
fe3f5fa8 | 205 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
206 | static void incref_bp_location (struct bp_location *loc); |
207 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 208 | |
39d61571 | 209 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 210 | |
b60e7edf | 211 | static void update_global_location_list (int); |
a5606eee | 212 | |
b60e7edf | 213 | static void update_global_location_list_nothrow (int); |
74960c60 | 214 | |
d77f58be | 215 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 VP |
216 | |
217 | static void insert_breakpoint_locations (void); | |
a5606eee | 218 | |
a96d9b2e SDJ |
219 | static int syscall_catchpoint_p (struct breakpoint *b); |
220 | ||
1042e4c0 SS |
221 | static void tracepoints_info (char *, int); |
222 | ||
223 | static void delete_trace_command (char *, int); | |
224 | ||
225 | static void enable_trace_command (char *, int); | |
226 | ||
227 | static void disable_trace_command (char *, int); | |
228 | ||
229 | static void trace_pass_command (char *, int); | |
230 | ||
9c06b0b4 TJB |
231 | static int is_masked_watchpoint (const struct breakpoint *b); |
232 | ||
0fb4aa4b PA |
233 | /* Assuming we're creating a static tracepoint, does S look like a |
234 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
235 | #define is_marker_spec(s) \ | |
f5a8e22b | 236 | (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) |
0fb4aa4b | 237 | |
2060206e PA |
238 | /* The abstract base class all breakpoint_ops structures inherit |
239 | from. */ | |
240 | static struct breakpoint_ops base_breakpoint_ops; | |
241 | ||
242 | /* The breakpoint_ops structure to be inherited by all breakpoint_ops | |
243 | that are implemented on top of software or hardware breakpoints | |
244 | (user breakpoints, internal and momentary breakpoints, etc.). */ | |
245 | static struct breakpoint_ops bkpt_base_breakpoint_ops; | |
246 | ||
247 | /* Internal breakpoints class type. */ | |
06edf0c0 | 248 | static struct breakpoint_ops internal_breakpoint_ops; |
2060206e PA |
249 | |
250 | /* Momentary breakpoints class type. */ | |
06edf0c0 PA |
251 | static struct breakpoint_ops momentary_breakpoint_ops; |
252 | ||
2060206e PA |
253 | /* The breakpoint_ops structure to be used in regular user created |
254 | breakpoints. */ | |
255 | struct breakpoint_ops bkpt_breakpoint_ops; | |
256 | ||
5cea2a26 PA |
257 | /* A reference-counted struct command_line. This lets multiple |
258 | breakpoints share a single command list. */ | |
259 | struct counted_command_line | |
260 | { | |
261 | /* The reference count. */ | |
262 | int refc; | |
263 | ||
264 | /* The command list. */ | |
265 | struct command_line *commands; | |
266 | }; | |
267 | ||
268 | struct command_line * | |
269 | breakpoint_commands (struct breakpoint *b) | |
270 | { | |
271 | return b->commands ? b->commands->commands : NULL; | |
272 | } | |
3daf8fe5 | 273 | |
f3b1572e PA |
274 | /* Flag indicating that a command has proceeded the inferior past the |
275 | current breakpoint. */ | |
276 | ||
277 | static int breakpoint_proceeded; | |
278 | ||
956a9fb9 | 279 | const char * |
2cec12e5 AR |
280 | bpdisp_text (enum bpdisp disp) |
281 | { | |
4a64f543 MS |
282 | /* NOTE: the following values are a part of MI protocol and |
283 | represent values of 'disp' field returned when inferior stops at | |
284 | a breakpoint. */ | |
bc043ef3 | 285 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 286 | |
2cec12e5 AR |
287 | return bpdisps[(int) disp]; |
288 | } | |
c906108c | 289 | |
4a64f543 | 290 | /* Prototypes for exported functions. */ |
c906108c | 291 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 292 | if such is available. */ |
c906108c SS |
293 | static int can_use_hw_watchpoints; |
294 | ||
920d2a44 AC |
295 | static void |
296 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
297 | struct cmd_list_element *c, | |
298 | const char *value) | |
299 | { | |
3e43a32a MS |
300 | fprintf_filtered (file, |
301 | _("Debugger's willingness to use " | |
302 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
303 | value); |
304 | } | |
305 | ||
fa8d40ab JJ |
306 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
307 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 308 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
309 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
310 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
311 | static void |
312 | show_pending_break_support (struct ui_file *file, int from_tty, | |
313 | struct cmd_list_element *c, | |
314 | const char *value) | |
315 | { | |
3e43a32a MS |
316 | fprintf_filtered (file, |
317 | _("Debugger's behavior regarding " | |
318 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
319 | value); |
320 | } | |
fa8d40ab | 321 | |
765dc015 | 322 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 323 | set with "break" but falling in read-only memory. |
765dc015 VP |
324 | If 0, gdb will warn about such breakpoints, but won't automatically |
325 | use hardware breakpoints. */ | |
326 | static int automatic_hardware_breakpoints; | |
327 | static void | |
328 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
329 | struct cmd_list_element *c, | |
330 | const char *value) | |
331 | { | |
3e43a32a MS |
332 | fprintf_filtered (file, |
333 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
334 | value); |
335 | } | |
336 | ||
33e5cbd6 PA |
337 | /* If on, gdb will keep breakpoints inserted even as inferior is |
338 | stopped, and immediately insert any new breakpoints. If off, gdb | |
339 | will insert breakpoints into inferior only when resuming it, and | |
340 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
341 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
342 | ||
343 | static const char always_inserted_auto[] = "auto"; | |
344 | static const char always_inserted_on[] = "on"; | |
345 | static const char always_inserted_off[] = "off"; | |
346 | static const char *always_inserted_enums[] = { | |
347 | always_inserted_auto, | |
348 | always_inserted_off, | |
349 | always_inserted_on, | |
350 | NULL | |
351 | }; | |
352 | static const char *always_inserted_mode = always_inserted_auto; | |
353 | static void | |
74960c60 | 354 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 355 | struct cmd_list_element *c, const char *value) |
74960c60 | 356 | { |
33e5cbd6 | 357 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
358 | fprintf_filtered (file, |
359 | _("Always inserted breakpoint " | |
360 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
361 | value, |
362 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
363 | else | |
3e43a32a MS |
364 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
365 | value); | |
74960c60 VP |
366 | } |
367 | ||
33e5cbd6 PA |
368 | int |
369 | breakpoints_always_inserted_mode (void) | |
370 | { | |
371 | return (always_inserted_mode == always_inserted_on | |
372 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
373 | } | |
765dc015 | 374 | |
a14ed312 | 375 | void _initialize_breakpoint (void); |
c906108c | 376 | |
c906108c SS |
377 | /* Are we executing breakpoint commands? */ |
378 | static int executing_breakpoint_commands; | |
379 | ||
c02f5703 MS |
380 | /* Are overlay event breakpoints enabled? */ |
381 | static int overlay_events_enabled; | |
382 | ||
e09342b5 TJB |
383 | /* See description in breakpoint.h. */ |
384 | int target_exact_watchpoints = 0; | |
385 | ||
c906108c | 386 | /* Walk the following statement or block through all breakpoints. |
e5dd4106 | 387 | ALL_BREAKPOINTS_SAFE does so even if the statement deletes the |
4a64f543 | 388 | current breakpoint. */ |
c906108c | 389 | |
5c44784c | 390 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 391 | |
5c44784c JM |
392 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
393 | for (B = breakpoint_chain; \ | |
394 | B ? (TMP=B->next, 1): 0; \ | |
395 | B = TMP) | |
c906108c | 396 | |
4a64f543 MS |
397 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
398 | not provided so update_global_location_list must not be called | |
399 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 400 | |
876fa593 JK |
401 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
402 | for (BP_TMP = bp_location; \ | |
403 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
404 | BP_TMP++) | |
7cc221ef | 405 | |
1042e4c0 SS |
406 | /* Iterator for tracepoints only. */ |
407 | ||
408 | #define ALL_TRACEPOINTS(B) \ | |
409 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 410 | if (is_tracepoint (B)) |
1042e4c0 | 411 | |
7cc221ef | 412 | /* Chains of all breakpoints defined. */ |
c906108c SS |
413 | |
414 | struct breakpoint *breakpoint_chain; | |
415 | ||
876fa593 JK |
416 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
417 | ||
418 | static struct bp_location **bp_location; | |
419 | ||
420 | /* Number of elements of BP_LOCATION. */ | |
421 | ||
422 | static unsigned bp_location_count; | |
423 | ||
4a64f543 MS |
424 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
425 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
426 | result from bp_location_has_shadow. You can use it for roughly | |
427 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
428 | an address you need to read. */ | |
876fa593 JK |
429 | |
430 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
431 | ||
4a64f543 MS |
432 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
433 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
434 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
435 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
436 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
437 | |
438 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 439 | |
4a64f543 MS |
440 | /* The locations that no longer correspond to any breakpoint, unlinked |
441 | from bp_location array, but for which a hit may still be reported | |
442 | by a target. */ | |
20874c92 VP |
443 | VEC(bp_location_p) *moribund_locations = NULL; |
444 | ||
c906108c SS |
445 | /* Number of last breakpoint made. */ |
446 | ||
95a42b64 TT |
447 | static int breakpoint_count; |
448 | ||
86b17b60 PA |
449 | /* The value of `breakpoint_count' before the last command that |
450 | created breakpoints. If the last (break-like) command created more | |
451 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
452 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
453 | static int prev_breakpoint_count; | |
c906108c | 454 | |
1042e4c0 SS |
455 | /* Number of last tracepoint made. */ |
456 | ||
95a42b64 | 457 | static int tracepoint_count; |
1042e4c0 | 458 | |
6149aea9 PA |
459 | static struct cmd_list_element *breakpoint_set_cmdlist; |
460 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 461 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 462 | |
468d015d JJ |
463 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
464 | static int | |
465 | breakpoint_enabled (struct breakpoint *b) | |
466 | { | |
0d381245 | 467 | return (b->enable_state == bp_enabled); |
468d015d JJ |
468 | } |
469 | ||
c906108c SS |
470 | /* Set breakpoint count to NUM. */ |
471 | ||
95a42b64 | 472 | static void |
fba45db2 | 473 | set_breakpoint_count (int num) |
c906108c | 474 | { |
86b17b60 | 475 | prev_breakpoint_count = breakpoint_count; |
c906108c | 476 | breakpoint_count = num; |
4fa62494 | 477 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
478 | } |
479 | ||
86b17b60 PA |
480 | /* Used by `start_rbreak_breakpoints' below, to record the current |
481 | breakpoint count before "rbreak" creates any breakpoint. */ | |
482 | static int rbreak_start_breakpoint_count; | |
483 | ||
95a42b64 TT |
484 | /* Called at the start an "rbreak" command to record the first |
485 | breakpoint made. */ | |
86b17b60 | 486 | |
95a42b64 TT |
487 | void |
488 | start_rbreak_breakpoints (void) | |
489 | { | |
86b17b60 | 490 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
491 | } |
492 | ||
493 | /* Called at the end of an "rbreak" command to record the last | |
494 | breakpoint made. */ | |
86b17b60 | 495 | |
95a42b64 TT |
496 | void |
497 | end_rbreak_breakpoints (void) | |
498 | { | |
86b17b60 | 499 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
500 | } |
501 | ||
4a64f543 | 502 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
503 | |
504 | void | |
fba45db2 | 505 | clear_breakpoint_hit_counts (void) |
c906108c SS |
506 | { |
507 | struct breakpoint *b; | |
508 | ||
509 | ALL_BREAKPOINTS (b) | |
510 | b->hit_count = 0; | |
511 | } | |
512 | ||
9add0f1b TT |
513 | /* Allocate a new counted_command_line with reference count of 1. |
514 | The new structure owns COMMANDS. */ | |
515 | ||
516 | static struct counted_command_line * | |
517 | alloc_counted_command_line (struct command_line *commands) | |
518 | { | |
519 | struct counted_command_line *result | |
520 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 521 | |
9add0f1b TT |
522 | result->refc = 1; |
523 | result->commands = commands; | |
524 | return result; | |
525 | } | |
526 | ||
527 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
528 | ||
529 | static void | |
530 | incref_counted_command_line (struct counted_command_line *cmd) | |
531 | { | |
532 | if (cmd) | |
533 | ++cmd->refc; | |
534 | } | |
535 | ||
536 | /* Decrement reference count. If the reference count reaches 0, | |
537 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
538 | nothing if *CMDP is NULL. */ | |
539 | ||
540 | static void | |
541 | decref_counted_command_line (struct counted_command_line **cmdp) | |
542 | { | |
543 | if (*cmdp) | |
544 | { | |
545 | if (--(*cmdp)->refc == 0) | |
546 | { | |
547 | free_command_lines (&(*cmdp)->commands); | |
548 | xfree (*cmdp); | |
549 | } | |
550 | *cmdp = NULL; | |
551 | } | |
552 | } | |
553 | ||
554 | /* A cleanup function that calls decref_counted_command_line. */ | |
555 | ||
556 | static void | |
557 | do_cleanup_counted_command_line (void *arg) | |
558 | { | |
559 | decref_counted_command_line (arg); | |
560 | } | |
561 | ||
562 | /* Create a cleanup that calls decref_counted_command_line on the | |
563 | argument. */ | |
564 | ||
565 | static struct cleanup * | |
566 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
567 | { | |
568 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
569 | } | |
570 | ||
c906108c SS |
571 | /* Default address, symtab and line to put a breakpoint at |
572 | for "break" command with no arg. | |
4a64f543 | 573 | If default_breakpoint_valid is zero, the other three are |
c906108c SS |
574 | not valid, and "break" with no arg is an error. |
575 | ||
576 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
577 | ||
578 | int default_breakpoint_valid; | |
579 | CORE_ADDR default_breakpoint_address; | |
580 | struct symtab *default_breakpoint_symtab; | |
581 | int default_breakpoint_line; | |
6c95b8df PA |
582 | struct program_space *default_breakpoint_pspace; |
583 | ||
c906108c | 584 | \f |
48cb2d85 VP |
585 | /* Return the breakpoint with the specified number, or NULL |
586 | if the number does not refer to an existing breakpoint. */ | |
587 | ||
588 | struct breakpoint * | |
589 | get_breakpoint (int num) | |
590 | { | |
591 | struct breakpoint *b; | |
592 | ||
593 | ALL_BREAKPOINTS (b) | |
594 | if (b->number == num) | |
595 | return b; | |
596 | ||
597 | return NULL; | |
598 | } | |
5c44784c | 599 | |
c906108c | 600 | \f |
adc36818 PM |
601 | |
602 | void | |
603 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
604 | int from_tty) | |
605 | { | |
3a5c3e22 PA |
606 | xfree (b->cond_string); |
607 | b->cond_string = NULL; | |
adc36818 | 608 | |
3a5c3e22 | 609 | if (is_watchpoint (b)) |
adc36818 | 610 | { |
3a5c3e22 PA |
611 | struct watchpoint *w = (struct watchpoint *) b; |
612 | ||
613 | xfree (w->cond_exp); | |
614 | w->cond_exp = NULL; | |
615 | } | |
616 | else | |
617 | { | |
618 | struct bp_location *loc; | |
619 | ||
620 | for (loc = b->loc; loc; loc = loc->next) | |
621 | { | |
622 | xfree (loc->cond); | |
623 | loc->cond = NULL; | |
624 | } | |
adc36818 | 625 | } |
adc36818 PM |
626 | |
627 | if (*exp == 0) | |
628 | { | |
629 | if (from_tty) | |
630 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
631 | } | |
632 | else | |
633 | { | |
634 | char *arg = exp; | |
cc59ec59 | 635 | |
adc36818 PM |
636 | /* I don't know if it matters whether this is the string the user |
637 | typed in or the decompiled expression. */ | |
638 | b->cond_string = xstrdup (arg); | |
639 | b->condition_not_parsed = 0; | |
640 | ||
641 | if (is_watchpoint (b)) | |
642 | { | |
3a5c3e22 PA |
643 | struct watchpoint *w = (struct watchpoint *) b; |
644 | ||
adc36818 PM |
645 | innermost_block = NULL; |
646 | arg = exp; | |
3a5c3e22 | 647 | w->cond_exp = parse_exp_1 (&arg, 0, 0); |
adc36818 PM |
648 | if (*arg) |
649 | error (_("Junk at end of expression")); | |
3a5c3e22 | 650 | w->cond_exp_valid_block = innermost_block; |
adc36818 PM |
651 | } |
652 | else | |
653 | { | |
3a5c3e22 PA |
654 | struct bp_location *loc; |
655 | ||
adc36818 PM |
656 | for (loc = b->loc; loc; loc = loc->next) |
657 | { | |
658 | arg = exp; | |
659 | loc->cond = | |
660 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
661 | if (*arg) | |
662 | error (_("Junk at end of expression")); | |
663 | } | |
664 | } | |
665 | } | |
666 | breakpoints_changed (); | |
8d3788bd | 667 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
668 | } |
669 | ||
c906108c SS |
670 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
671 | ||
672 | static void | |
fba45db2 | 673 | condition_command (char *arg, int from_tty) |
c906108c | 674 | { |
52f0bd74 | 675 | struct breakpoint *b; |
c906108c | 676 | char *p; |
52f0bd74 | 677 | int bnum; |
c906108c SS |
678 | |
679 | if (arg == 0) | |
e2e0b3e5 | 680 | error_no_arg (_("breakpoint number")); |
c906108c SS |
681 | |
682 | p = arg; | |
683 | bnum = get_number (&p); | |
5c44784c | 684 | if (bnum == 0) |
8a3fe4f8 | 685 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
686 | |
687 | ALL_BREAKPOINTS (b) | |
688 | if (b->number == bnum) | |
2f069f6f | 689 | { |
7371cf6d PM |
690 | /* Check if this breakpoint has a Python object assigned to |
691 | it, and if it has a definition of the "stop" | |
692 | method. This method and conditions entered into GDB from | |
693 | the CLI are mutually exclusive. */ | |
694 | if (b->py_bp_object | |
695 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
696 | error (_("Cannot set a condition where a Python 'stop' " | |
697 | "method has been defined in the breakpoint.")); | |
2566ad2d | 698 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
699 | return; |
700 | } | |
c906108c | 701 | |
8a3fe4f8 | 702 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
703 | } |
704 | ||
a7bdde9e VP |
705 | /* Check that COMMAND do not contain commands that are suitable |
706 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
707 | Throw if any such commands is found. */ |
708 | ||
a7bdde9e VP |
709 | static void |
710 | check_no_tracepoint_commands (struct command_line *commands) | |
711 | { | |
712 | struct command_line *c; | |
cc59ec59 | 713 | |
a7bdde9e VP |
714 | for (c = commands; c; c = c->next) |
715 | { | |
716 | int i; | |
717 | ||
718 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
719 | error (_("The 'while-stepping' command can " |
720 | "only be used for tracepoints")); | |
a7bdde9e VP |
721 | |
722 | for (i = 0; i < c->body_count; ++i) | |
723 | check_no_tracepoint_commands ((c->body_list)[i]); | |
724 | ||
725 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 726 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
727 | command directly. */ |
728 | if (strstr (c->line, "collect ") == c->line) | |
729 | error (_("The 'collect' command can only be used for tracepoints")); | |
730 | ||
51661e93 VP |
731 | if (strstr (c->line, "teval ") == c->line) |
732 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
733 | } |
734 | } | |
735 | ||
d77f58be SS |
736 | /* Encapsulate tests for different types of tracepoints. */ |
737 | ||
d9b3f62e PA |
738 | static int |
739 | is_tracepoint_type (enum bptype type) | |
740 | { | |
741 | return (type == bp_tracepoint | |
742 | || type == bp_fast_tracepoint | |
743 | || type == bp_static_tracepoint); | |
744 | } | |
745 | ||
a7bdde9e | 746 | int |
d77f58be | 747 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 748 | { |
d9b3f62e | 749 | return is_tracepoint_type (b->type); |
a7bdde9e | 750 | } |
d9b3f62e | 751 | |
e5dd4106 | 752 | /* A helper function that validates that COMMANDS are valid for a |
95a42b64 TT |
753 | breakpoint. This function will throw an exception if a problem is |
754 | found. */ | |
48cb2d85 | 755 | |
95a42b64 TT |
756 | static void |
757 | validate_commands_for_breakpoint (struct breakpoint *b, | |
758 | struct command_line *commands) | |
48cb2d85 | 759 | { |
d77f58be | 760 | if (is_tracepoint (b)) |
a7bdde9e | 761 | { |
4a64f543 MS |
762 | /* We need to verify that each top-level element of commands is |
763 | valid for tracepoints, that there's at most one | |
764 | while-stepping element, and that while-stepping's body has | |
765 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
766 | struct command_line *c; |
767 | struct command_line *while_stepping = 0; | |
768 | for (c = commands; c; c = c->next) | |
769 | { | |
a7bdde9e VP |
770 | if (c->control_type == while_stepping_control) |
771 | { | |
772 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
773 | error (_("The 'while-stepping' command " |
774 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 775 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
776 | error (_("The 'while-stepping' command " |
777 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
778 | |
779 | if (while_stepping) | |
3e43a32a MS |
780 | error (_("The 'while-stepping' command " |
781 | "can be used only once")); | |
a7bdde9e VP |
782 | else |
783 | while_stepping = c; | |
784 | } | |
785 | } | |
786 | if (while_stepping) | |
787 | { | |
788 | struct command_line *c2; | |
789 | ||
790 | gdb_assert (while_stepping->body_count == 1); | |
791 | c2 = while_stepping->body_list[0]; | |
792 | for (; c2; c2 = c2->next) | |
793 | { | |
a7bdde9e VP |
794 | if (c2->control_type == while_stepping_control) |
795 | error (_("The 'while-stepping' command cannot be nested")); | |
796 | } | |
797 | } | |
798 | } | |
799 | else | |
800 | { | |
801 | check_no_tracepoint_commands (commands); | |
802 | } | |
95a42b64 TT |
803 | } |
804 | ||
0fb4aa4b PA |
805 | /* Return a vector of all the static tracepoints set at ADDR. The |
806 | caller is responsible for releasing the vector. */ | |
807 | ||
808 | VEC(breakpoint_p) * | |
809 | static_tracepoints_here (CORE_ADDR addr) | |
810 | { | |
811 | struct breakpoint *b; | |
812 | VEC(breakpoint_p) *found = 0; | |
813 | struct bp_location *loc; | |
814 | ||
815 | ALL_BREAKPOINTS (b) | |
816 | if (b->type == bp_static_tracepoint) | |
817 | { | |
818 | for (loc = b->loc; loc; loc = loc->next) | |
819 | if (loc->address == addr) | |
820 | VEC_safe_push(breakpoint_p, found, b); | |
821 | } | |
822 | ||
823 | return found; | |
824 | } | |
825 | ||
95a42b64 | 826 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 827 | validate that only allowed commands are included. */ |
95a42b64 TT |
828 | |
829 | void | |
4a64f543 MS |
830 | breakpoint_set_commands (struct breakpoint *b, |
831 | struct command_line *commands) | |
95a42b64 TT |
832 | { |
833 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 834 | |
9add0f1b TT |
835 | decref_counted_command_line (&b->commands); |
836 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 837 | breakpoints_changed (); |
8d3788bd | 838 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
839 | } |
840 | ||
45a43567 TT |
841 | /* Set the internal `silent' flag on the breakpoint. Note that this |
842 | is not the same as the "silent" that may appear in the breakpoint's | |
843 | commands. */ | |
844 | ||
845 | void | |
846 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
847 | { | |
848 | int old_silent = b->silent; | |
849 | ||
850 | b->silent = silent; | |
851 | if (old_silent != silent) | |
8d3788bd | 852 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
853 | } |
854 | ||
855 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
856 | breakpoint work for any thread. */ | |
857 | ||
858 | void | |
859 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
860 | { | |
861 | int old_thread = b->thread; | |
862 | ||
863 | b->thread = thread; | |
864 | if (old_thread != thread) | |
8d3788bd | 865 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
866 | } |
867 | ||
868 | /* Set the task for this breakpoint. If TASK is 0, make the | |
869 | breakpoint work for any task. */ | |
870 | ||
871 | void | |
872 | breakpoint_set_task (struct breakpoint *b, int task) | |
873 | { | |
874 | int old_task = b->task; | |
875 | ||
876 | b->task = task; | |
877 | if (old_task != task) | |
8d3788bd | 878 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
879 | } |
880 | ||
95a42b64 TT |
881 | void |
882 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
883 | { |
884 | struct breakpoint *b = closure; | |
cc59ec59 | 885 | |
a7bdde9e VP |
886 | validate_actionline (&line, b); |
887 | } | |
888 | ||
95a42b64 TT |
889 | /* A structure used to pass information through |
890 | map_breakpoint_numbers. */ | |
891 | ||
892 | struct commands_info | |
893 | { | |
894 | /* True if the command was typed at a tty. */ | |
895 | int from_tty; | |
86b17b60 PA |
896 | |
897 | /* The breakpoint range spec. */ | |
898 | char *arg; | |
899 | ||
95a42b64 TT |
900 | /* Non-NULL if the body of the commands are being read from this |
901 | already-parsed command. */ | |
902 | struct command_line *control; | |
86b17b60 | 903 | |
95a42b64 TT |
904 | /* The command lines read from the user, or NULL if they have not |
905 | yet been read. */ | |
906 | struct counted_command_line *cmd; | |
907 | }; | |
908 | ||
909 | /* A callback for map_breakpoint_numbers that sets the commands for | |
910 | commands_command. */ | |
911 | ||
c906108c | 912 | static void |
95a42b64 | 913 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 914 | { |
95a42b64 | 915 | struct commands_info *info = data; |
c906108c | 916 | |
95a42b64 TT |
917 | if (info->cmd == NULL) |
918 | { | |
919 | struct command_line *l; | |
5c44784c | 920 | |
95a42b64 TT |
921 | if (info->control != NULL) |
922 | l = copy_command_lines (info->control->body_list[0]); | |
923 | else | |
86b17b60 PA |
924 | { |
925 | struct cleanup *old_chain; | |
926 | char *str; | |
c5aa993b | 927 | |
3e43a32a MS |
928 | str = xstrprintf (_("Type commands for breakpoint(s) " |
929 | "%s, one per line."), | |
86b17b60 PA |
930 | info->arg); |
931 | ||
932 | old_chain = make_cleanup (xfree, str); | |
933 | ||
934 | l = read_command_lines (str, | |
935 | info->from_tty, 1, | |
d77f58be | 936 | (is_tracepoint (b) |
86b17b60 PA |
937 | ? check_tracepoint_command : 0), |
938 | b); | |
939 | ||
940 | do_cleanups (old_chain); | |
941 | } | |
a7bdde9e | 942 | |
95a42b64 TT |
943 | info->cmd = alloc_counted_command_line (l); |
944 | } | |
945 | ||
946 | /* If a breakpoint was on the list more than once, we don't need to | |
947 | do anything. */ | |
948 | if (b->commands != info->cmd) | |
949 | { | |
950 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
951 | incref_counted_command_line (info->cmd); | |
952 | decref_counted_command_line (&b->commands); | |
953 | b->commands = info->cmd; | |
954 | breakpoints_changed (); | |
8d3788bd | 955 | observer_notify_breakpoint_modified (b); |
c5aa993b | 956 | } |
95a42b64 TT |
957 | } |
958 | ||
959 | static void | |
4a64f543 MS |
960 | commands_command_1 (char *arg, int from_tty, |
961 | struct command_line *control) | |
95a42b64 TT |
962 | { |
963 | struct cleanup *cleanups; | |
964 | struct commands_info info; | |
965 | ||
966 | info.from_tty = from_tty; | |
967 | info.control = control; | |
968 | info.cmd = NULL; | |
969 | /* If we read command lines from the user, then `info' will hold an | |
970 | extra reference to the commands that we must clean up. */ | |
971 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
972 | ||
973 | if (arg == NULL || !*arg) | |
974 | { | |
86b17b60 | 975 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
976 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
977 | breakpoint_count); | |
95a42b64 TT |
978 | else if (breakpoint_count > 0) |
979 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
980 | else |
981 | { | |
982 | /* So that we don't try to free the incoming non-NULL | |
983 | argument in the cleanup below. Mapping breakpoint | |
984 | numbers will fail in this case. */ | |
985 | arg = NULL; | |
986 | } | |
95a42b64 | 987 | } |
9766ced4 SS |
988 | else |
989 | /* The command loop has some static state, so we need to preserve | |
990 | our argument. */ | |
991 | arg = xstrdup (arg); | |
86b17b60 PA |
992 | |
993 | if (arg != NULL) | |
994 | make_cleanup (xfree, arg); | |
995 | ||
996 | info.arg = arg; | |
95a42b64 TT |
997 | |
998 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
999 | ||
1000 | if (info.cmd == NULL) | |
1001 | error (_("No breakpoints specified.")); | |
1002 | ||
1003 | do_cleanups (cleanups); | |
1004 | } | |
1005 | ||
1006 | static void | |
1007 | commands_command (char *arg, int from_tty) | |
1008 | { | |
1009 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1010 | } |
40c03ae8 EZ |
1011 | |
1012 | /* Like commands_command, but instead of reading the commands from | |
1013 | input stream, takes them from an already parsed command structure. | |
1014 | ||
1015 | This is used by cli-script.c to DTRT with breakpoint commands | |
1016 | that are part of if and while bodies. */ | |
1017 | enum command_control_type | |
1018 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1019 | { | |
95a42b64 TT |
1020 | commands_command_1 (arg, 0, cmd); |
1021 | return simple_control; | |
40c03ae8 | 1022 | } |
876fa593 JK |
1023 | |
1024 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1025 | ||
1026 | static int | |
1027 | bp_location_has_shadow (struct bp_location *bl) | |
1028 | { | |
1029 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1030 | return 0; | |
1031 | if (!bl->inserted) | |
1032 | return 0; | |
1033 | if (bl->target_info.shadow_len == 0) | |
e5dd4106 | 1034 | /* BL isn't valid, or doesn't shadow memory. */ |
876fa593 JK |
1035 | return 0; |
1036 | return 1; | |
1037 | } | |
1038 | ||
8defab1a | 1039 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1040 | by replacing any memory breakpoints with their shadowed contents. |
1041 | ||
1042 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1043 | bl->address - bp_location_placed_address_before_address_max |
1044 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1045 | The range we were requested to resolve shadows for is: |
1046 | memaddr ... memaddr + len | |
1047 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1048 | memaddr + len <= (bl->address |
1049 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1050 | and: |
35df4500 | 1051 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1052 | |
8defab1a DJ |
1053 | void |
1054 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1055 | { |
4a64f543 MS |
1056 | /* Left boundary, right boundary and median element of our binary |
1057 | search. */ | |
876fa593 JK |
1058 | unsigned bc_l, bc_r, bc; |
1059 | ||
4a64f543 MS |
1060 | /* Find BC_L which is a leftmost element which may affect BUF |
1061 | content. It is safe to report lower value but a failure to | |
1062 | report higher one. */ | |
876fa593 JK |
1063 | |
1064 | bc_l = 0; | |
1065 | bc_r = bp_location_count; | |
1066 | while (bc_l + 1 < bc_r) | |
1067 | { | |
35df4500 | 1068 | struct bp_location *bl; |
876fa593 JK |
1069 | |
1070 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1071 | bl = bp_location[bc]; |
876fa593 | 1072 | |
4a64f543 MS |
1073 | /* Check first BL->ADDRESS will not overflow due to the added |
1074 | constant. Then advance the left boundary only if we are sure | |
1075 | the BC element can in no way affect the BUF content (MEMADDR | |
1076 | to MEMADDR + LEN range). | |
876fa593 | 1077 | |
4a64f543 MS |
1078 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1079 | offset so that we cannot miss a breakpoint with its shadow | |
1080 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1081 | |
35df4500 TJB |
1082 | if ((bl->address + bp_location_shadow_len_after_address_max |
1083 | >= bl->address) | |
1084 | && (bl->address + bp_location_shadow_len_after_address_max | |
1085 | <= memaddr)) | |
876fa593 JK |
1086 | bc_l = bc; |
1087 | else | |
1088 | bc_r = bc; | |
1089 | } | |
1090 | ||
128070bb PA |
1091 | /* Due to the binary search above, we need to make sure we pick the |
1092 | first location that's at BC_L's address. E.g., if there are | |
1093 | multiple locations at the same address, BC_L may end up pointing | |
1094 | at a duplicate location, and miss the "master"/"inserted" | |
1095 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1096 | B: | |
1097 | ||
1098 | L1@A, L2@A, L3@B, ... | |
1099 | ||
1100 | BC_L could end up pointing at location L2, while the "master" | |
1101 | location could be L1. Since the `loc->inserted' flag is only set | |
1102 | on "master" locations, we'd forget to restore the shadow of L1 | |
1103 | and L2. */ | |
1104 | while (bc_l > 0 | |
1105 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1106 | bc_l--; | |
1107 | ||
876fa593 JK |
1108 | /* Now do full processing of the found relevant range of elements. */ |
1109 | ||
1110 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1111 | { |
35df4500 | 1112 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1113 | CORE_ADDR bp_addr = 0; |
1114 | int bp_size = 0; | |
1115 | int bptoffset = 0; | |
1116 | ||
35df4500 TJB |
1117 | /* bp_location array has BL->OWNER always non-NULL. */ |
1118 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1119 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1120 | bl->owner->number); |
ffce0d52 | 1121 | |
e5dd4106 | 1122 | /* Performance optimization: any further element can no longer affect BUF |
876fa593 JK |
1123 | content. */ |
1124 | ||
35df4500 TJB |
1125 | if (bl->address >= bp_location_placed_address_before_address_max |
1126 | && memaddr + len <= (bl->address | |
1127 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1128 | break; |
1129 | ||
35df4500 | 1130 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1131 | continue; |
35df4500 | 1132 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1133 | current_program_space->aspace, 0)) |
1134 | continue; | |
1135 | ||
c5aa993b JM |
1136 | /* Addresses and length of the part of the breakpoint that |
1137 | we need to copy. */ | |
35df4500 TJB |
1138 | bp_addr = bl->target_info.placed_address; |
1139 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1140 | |
c5aa993b JM |
1141 | if (bp_addr + bp_size <= memaddr) |
1142 | /* The breakpoint is entirely before the chunk of memory we | |
1143 | are reading. */ | |
1144 | continue; | |
8defab1a | 1145 | |
c5aa993b JM |
1146 | if (bp_addr >= memaddr + len) |
1147 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1148 | reading. */ |
c5aa993b | 1149 | continue; |
c5aa993b | 1150 | |
8defab1a DJ |
1151 | /* Offset within shadow_contents. */ |
1152 | if (bp_addr < memaddr) | |
1153 | { | |
1154 | /* Only copy the second part of the breakpoint. */ | |
1155 | bp_size -= memaddr - bp_addr; | |
1156 | bptoffset = memaddr - bp_addr; | |
1157 | bp_addr = memaddr; | |
1158 | } | |
c5aa993b | 1159 | |
8defab1a DJ |
1160 | if (bp_addr + bp_size > memaddr + len) |
1161 | { | |
1162 | /* Only copy the first part of the breakpoint. */ | |
1163 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1164 | } | |
c5aa993b | 1165 | |
8defab1a | 1166 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1167 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1168 | } |
c906108c | 1169 | } |
c906108c | 1170 | \f |
c5aa993b | 1171 | |
60e1c644 PA |
1172 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1173 | ||
a5606eee | 1174 | static int |
d77f58be | 1175 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1176 | { |
1177 | return (bpt->type == bp_hardware_watchpoint | |
1178 | || bpt->type == bp_read_watchpoint | |
1179 | || bpt->type == bp_access_watchpoint); | |
1180 | } | |
7270d8f2 | 1181 | |
60e1c644 PA |
1182 | /* Return true if BPT is of any watchpoint kind, hardware or |
1183 | software. */ | |
1184 | ||
3a5c3e22 | 1185 | int |
d77f58be | 1186 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1187 | { |
1188 | return (is_hardware_watchpoint (bpt) | |
1189 | || bpt->type == bp_watchpoint); | |
1190 | } | |
1191 | ||
3a5c3e22 PA |
1192 | /* Returns true if the current thread and its running state are safe |
1193 | to evaluate or update watchpoint B. Watchpoints on local | |
1194 | expressions need to be evaluated in the context of the thread that | |
1195 | was current when the watchpoint was created, and, that thread needs | |
1196 | to be stopped to be able to select the correct frame context. | |
1197 | Watchpoints on global expressions can be evaluated on any thread, | |
1198 | and in any state. It is presently left to the target allowing | |
1199 | memory accesses when threads are running. */ | |
f6bc2008 PA |
1200 | |
1201 | static int | |
3a5c3e22 | 1202 | watchpoint_in_thread_scope (struct watchpoint *b) |
f6bc2008 PA |
1203 | { |
1204 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1205 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1206 | && !is_executing (inferior_ptid))); | |
1207 | } | |
1208 | ||
d0fb5eae JK |
1209 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1210 | associated bp_watchpoint_scope breakpoint. */ | |
1211 | ||
1212 | static void | |
3a5c3e22 | 1213 | watchpoint_del_at_next_stop (struct watchpoint *w) |
d0fb5eae | 1214 | { |
3a5c3e22 | 1215 | struct breakpoint *b = &w->base; |
d0fb5eae JK |
1216 | |
1217 | if (b->related_breakpoint != b) | |
1218 | { | |
1219 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1220 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1221 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1222 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1223 | b->related_breakpoint = b; | |
1224 | } | |
1225 | b->disposition = disp_del_at_next_stop; | |
1226 | } | |
1227 | ||
567e1b4e JB |
1228 | /* Assuming that B is a watchpoint: |
1229 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1230 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1231 | - Evaluate the condition if there is one, and store the result |
1232 | in b->loc->cond. | |
a5606eee VP |
1233 | - Update the list of values that must be watched in B->loc. |
1234 | ||
4a64f543 MS |
1235 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1236 | nothing. If this is local watchpoint that is out of scope, delete | |
1237 | it. | |
1238 | ||
1239 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1240 | removed + inserted on each stop here. Normal breakpoints must | |
1241 | never be removed because they might be missed by a running thread | |
1242 | when debugging in non-stop mode. On the other hand, hardware | |
1243 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1244 | to each LWP since they are stored in each LWP's hardware debug | |
1245 | registers. Therefore, such LWP must be stopped first in order to | |
1246 | be able to modify its hardware watchpoints. | |
1247 | ||
1248 | Hardware watchpoints must be reset exactly once after being | |
1249 | presented to the user. It cannot be done sooner, because it would | |
1250 | reset the data used to present the watchpoint hit to the user. And | |
1251 | it must not be done later because it could display the same single | |
1252 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1253 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1254 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1255 | not user-visible - its hit is suppressed if the memory content has | |
1256 | not changed. | |
1257 | ||
1258 | The following constraints influence the location where we can reset | |
1259 | hardware watchpoints: | |
1260 | ||
1261 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1262 | called several times when GDB stops. | |
1263 | ||
1264 | [linux] | |
1265 | * Multiple hardware watchpoints can be hit at the same time, | |
1266 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1267 | hit at a time as the reason for stopping, and all the other hits | |
1268 | are presented later, one after the other, each time the user | |
1269 | requests the execution to be resumed. Execution is not resumed | |
1270 | for the threads still having pending hit event stored in | |
1271 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1272 | the inferior on the first stop the thread hit event is kept being | |
1273 | reported from its cached value by linux_nat_stopped_data_address | |
1274 | until the real thread resume happens after the watchpoint gets | |
1275 | presented and thus its LWP_INFO->STATUS gets reset. | |
1276 | ||
1277 | Therefore the hardware watchpoint hit can get safely reset on the | |
1278 | watchpoint removal from inferior. */ | |
a79d3c27 | 1279 | |
b40ce68a | 1280 | static void |
3a5c3e22 | 1281 | update_watchpoint (struct watchpoint *b, int reparse) |
7270d8f2 | 1282 | { |
a5606eee | 1283 | int within_current_scope; |
a5606eee | 1284 | struct frame_id saved_frame_id; |
66076460 | 1285 | int frame_saved; |
a5606eee | 1286 | |
f6bc2008 PA |
1287 | /* If this is a local watchpoint, we only want to check if the |
1288 | watchpoint frame is in scope if the current thread is the thread | |
1289 | that was used to create the watchpoint. */ | |
1290 | if (!watchpoint_in_thread_scope (b)) | |
1291 | return; | |
1292 | ||
3a5c3e22 | 1293 | if (b->base.disposition == disp_del_at_next_stop) |
a5606eee VP |
1294 | return; |
1295 | ||
66076460 | 1296 | frame_saved = 0; |
a5606eee VP |
1297 | |
1298 | /* Determine if the watchpoint is within scope. */ | |
1299 | if (b->exp_valid_block == NULL) | |
1300 | within_current_scope = 1; | |
1301 | else | |
1302 | { | |
b5db5dfc UW |
1303 | struct frame_info *fi = get_current_frame (); |
1304 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1305 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1306 | ||
1307 | /* If we're in a function epilogue, unwinding may not work | |
1308 | properly, so do not attempt to recreate locations at this | |
1309 | point. See similar comments in watchpoint_check. */ | |
1310 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1311 | return; | |
66076460 DJ |
1312 | |
1313 | /* Save the current frame's ID so we can restore it after | |
1314 | evaluating the watchpoint expression on its own frame. */ | |
1315 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1316 | took a frame parameter, so that we didn't have to change the | |
1317 | selected frame. */ | |
1318 | frame_saved = 1; | |
1319 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1320 | ||
a5606eee VP |
1321 | fi = frame_find_by_id (b->watchpoint_frame); |
1322 | within_current_scope = (fi != NULL); | |
1323 | if (within_current_scope) | |
1324 | select_frame (fi); | |
1325 | } | |
1326 | ||
b5db5dfc UW |
1327 | /* We don't free locations. They are stored in the bp_location array |
1328 | and update_global_location_list will eventually delete them and | |
1329 | remove breakpoints if needed. */ | |
3a5c3e22 | 1330 | b->base.loc = NULL; |
b5db5dfc | 1331 | |
a5606eee VP |
1332 | if (within_current_scope && reparse) |
1333 | { | |
1334 | char *s; | |
d63d0675 | 1335 | |
a5606eee VP |
1336 | if (b->exp) |
1337 | { | |
1338 | xfree (b->exp); | |
1339 | b->exp = NULL; | |
1340 | } | |
d63d0675 | 1341 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1342 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1343 | /* If the meaning of expression itself changed, the old value is | |
1344 | no longer relevant. We don't want to report a watchpoint hit | |
1345 | to the user when the old value and the new value may actually | |
1346 | be completely different objects. */ | |
1347 | value_free (b->val); | |
fa4727a6 DJ |
1348 | b->val = NULL; |
1349 | b->val_valid = 0; | |
60e1c644 PA |
1350 | |
1351 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1352 | expression is stored in the breakpoint object, not in the | |
1353 | locations (re)created below. */ | |
3a5c3e22 | 1354 | if (b->base.cond_string != NULL) |
60e1c644 PA |
1355 | { |
1356 | if (b->cond_exp != NULL) | |
1357 | { | |
1358 | xfree (b->cond_exp); | |
1359 | b->cond_exp = NULL; | |
1360 | } | |
1361 | ||
3a5c3e22 | 1362 | s = b->base.cond_string; |
60e1c644 PA |
1363 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); |
1364 | } | |
a5606eee | 1365 | } |
a5606eee VP |
1366 | |
1367 | /* If we failed to parse the expression, for example because | |
1368 | it refers to a global variable in a not-yet-loaded shared library, | |
1369 | don't try to insert watchpoint. We don't automatically delete | |
1370 | such watchpoint, though, since failure to parse expression | |
1371 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1372 | if ( !target_has_execution) |
1373 | { | |
1374 | /* Without execution, memory can't change. No use to try and | |
1375 | set watchpoint locations. The watchpoint will be reset when | |
1376 | the target gains execution, through breakpoint_re_set. */ | |
1377 | } | |
1378 | else if (within_current_scope && b->exp) | |
a5606eee | 1379 | { |
0cf6dd15 | 1380 | int pc = 0; |
fa4727a6 | 1381 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1382 | struct program_space *frame_pspace; |
a5606eee | 1383 | |
0cf6dd15 | 1384 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1385 | |
a5606eee VP |
1386 | /* Avoid setting b->val if it's already set. The meaning of |
1387 | b->val is 'the last value' user saw, and we should update | |
1388 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1389 | happens, the code that reports it updates b->val directly. |
1390 | We don't keep track of the memory value for masked | |
1391 | watchpoints. */ | |
3a5c3e22 | 1392 | if (!b->val_valid && !is_masked_watchpoint (&b->base)) |
fa4727a6 DJ |
1393 | { |
1394 | b->val = v; | |
1395 | b->val_valid = 1; | |
1396 | } | |
a5606eee | 1397 | |
2d134ed3 PA |
1398 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1399 | ||
a5606eee | 1400 | /* Look at each value on the value chain. */ |
9fa40276 | 1401 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1402 | { |
1403 | /* If it's a memory location, and GDB actually needed | |
1404 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1405 | must watch it. If the first value returned is |
1406 | still lazy, that means an error occurred reading it; | |
1407 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1408 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1409 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1410 | { |
1411 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1412 | |
a5606eee VP |
1413 | /* We only watch structs and arrays if user asked |
1414 | for it explicitly, never if they just happen to | |
1415 | appear in the middle of some value chain. */ | |
fa4727a6 | 1416 | if (v == result |
a5606eee VP |
1417 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1418 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1419 | { | |
1420 | CORE_ADDR addr; | |
1421 | int len, type; | |
1422 | struct bp_location *loc, **tmp; | |
1423 | ||
42ae5230 | 1424 | addr = value_address (v); |
a5606eee VP |
1425 | len = TYPE_LENGTH (value_type (v)); |
1426 | type = hw_write; | |
3a5c3e22 | 1427 | if (b->base.type == bp_read_watchpoint) |
a5606eee | 1428 | type = hw_read; |
3a5c3e22 | 1429 | else if (b->base.type == bp_access_watchpoint) |
a5606eee | 1430 | type = hw_access; |
3a5c3e22 PA |
1431 | |
1432 | loc = allocate_bp_location (&b->base); | |
1433 | for (tmp = &(b->base.loc); *tmp != NULL; tmp = &((*tmp)->next)) | |
a5606eee VP |
1434 | ; |
1435 | *tmp = loc; | |
a6d9a66e | 1436 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1437 | |
1438 | loc->pspace = frame_pspace; | |
a5606eee VP |
1439 | loc->address = addr; |
1440 | loc->length = len; | |
1441 | loc->watchpoint_type = type; | |
1442 | } | |
1443 | } | |
9fa40276 TJB |
1444 | } |
1445 | ||
1446 | /* Change the type of breakpoint between hardware assisted or | |
1447 | an ordinary watchpoint depending on the hardware support | |
1448 | and free hardware slots. REPARSE is set when the inferior | |
1449 | is started. */ | |
a9634178 | 1450 | if (reparse) |
9fa40276 | 1451 | { |
e09342b5 | 1452 | int reg_cnt; |
9fa40276 TJB |
1453 | enum bp_loc_type loc_type; |
1454 | struct bp_location *bl; | |
a5606eee | 1455 | |
a9634178 | 1456 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1457 | |
1458 | if (reg_cnt) | |
9fa40276 TJB |
1459 | { |
1460 | int i, target_resources_ok, other_type_used; | |
1461 | ||
a9634178 TJB |
1462 | /* Use an exact watchpoint when there's only one memory region to be |
1463 | watched, and only one debug register is needed to watch it. */ | |
1464 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1465 | ||
9fa40276 | 1466 | /* We need to determine how many resources are already |
e09342b5 TJB |
1467 | used for all other hardware watchpoints plus this one |
1468 | to see if we still have enough resources to also fit | |
1469 | this watchpoint in as well. To guarantee the | |
1470 | hw_watchpoint_used_count call below counts this | |
1471 | watchpoint, make sure that it is marked as a hardware | |
1472 | watchpoint. */ | |
3a5c3e22 PA |
1473 | if (b->base.type == bp_watchpoint) |
1474 | b->base.type = bp_hardware_watchpoint; | |
9fa40276 | 1475 | |
3a5c3e22 | 1476 | i = hw_watchpoint_used_count (b->base.type, &other_type_used); |
e09342b5 | 1477 | target_resources_ok = target_can_use_hardware_watchpoint |
3a5c3e22 | 1478 | (b->base.type, i, other_type_used); |
e09342b5 | 1479 | if (target_resources_ok <= 0) |
a9634178 | 1480 | { |
3a5c3e22 | 1481 | int sw_mode = b->base.ops->works_in_software_mode (&b->base); |
9c06b0b4 TJB |
1482 | |
1483 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1484 | error (_("Target does not support this type of " |
1485 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1486 | else if (target_resources_ok < 0 && !sw_mode) |
1487 | error (_("There are not enough available hardware " | |
1488 | "resources for this watchpoint.")); | |
a9634178 | 1489 | else |
3a5c3e22 | 1490 | b->base.type = bp_watchpoint; |
a9634178 | 1491 | } |
9fa40276 | 1492 | } |
3a5c3e22 | 1493 | else if (!b->base.ops->works_in_software_mode (&b->base)) |
a9634178 TJB |
1494 | error (_("Expression cannot be implemented with " |
1495 | "read/access watchpoint.")); | |
9fa40276 | 1496 | else |
3a5c3e22 | 1497 | b->base.type = bp_watchpoint; |
9fa40276 | 1498 | |
3a5c3e22 | 1499 | loc_type = (b->base.type == bp_watchpoint? bp_loc_other |
9fa40276 | 1500 | : bp_loc_hardware_watchpoint); |
3a5c3e22 | 1501 | for (bl = b->base.loc; bl; bl = bl->next) |
9fa40276 TJB |
1502 | bl->loc_type = loc_type; |
1503 | } | |
1504 | ||
1505 | for (v = val_chain; v; v = next) | |
1506 | { | |
a5606eee VP |
1507 | next = value_next (v); |
1508 | if (v != b->val) | |
1509 | value_free (v); | |
1510 | } | |
1511 | ||
c7437ca6 PA |
1512 | /* If a software watchpoint is not watching any memory, then the |
1513 | above left it without any location set up. But, | |
1514 | bpstat_stop_status requires a location to be able to report | |
1515 | stops, so make sure there's at least a dummy one. */ | |
3a5c3e22 | 1516 | if (b->base.type == bp_watchpoint && b->base.loc == NULL) |
c7437ca6 | 1517 | { |
3a5c3e22 PA |
1518 | struct breakpoint *base = &b->base; |
1519 | base->loc = allocate_bp_location (base); | |
1520 | base->loc->pspace = frame_pspace; | |
1521 | base->loc->address = -1; | |
1522 | base->loc->length = -1; | |
1523 | base->loc->watchpoint_type = -1; | |
c7437ca6 | 1524 | } |
a5606eee VP |
1525 | } |
1526 | else if (!within_current_scope) | |
7270d8f2 | 1527 | { |
ac74f770 MS |
1528 | printf_filtered (_("\ |
1529 | Watchpoint %d deleted because the program has left the block\n\ | |
1530 | in which its expression is valid.\n"), | |
3a5c3e22 | 1531 | b->base.number); |
d0fb5eae | 1532 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1533 | } |
a5606eee VP |
1534 | |
1535 | /* Restore the selected frame. */ | |
66076460 DJ |
1536 | if (frame_saved) |
1537 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1538 | } |
1539 | ||
a5606eee | 1540 | |
74960c60 VP |
1541 | /* Returns 1 iff breakpoint location should be |
1542 | inserted in the inferior. */ | |
1543 | static int | |
35df4500 | 1544 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1545 | { |
35df4500 | 1546 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1547 | return 0; |
1548 | ||
35df4500 | 1549 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1550 | return 0; |
1551 | ||
35df4500 | 1552 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1553 | return 0; |
1554 | ||
56710373 PA |
1555 | /* This is set for example, when we're attached to the parent of a |
1556 | vfork, and have detached from the child. The child is running | |
1557 | free, and we expect it to do an exec or exit, at which point the | |
1558 | OS makes the parent schedulable again (and the target reports | |
1559 | that the vfork is done). Until the child is done with the shared | |
1560 | memory region, do not insert breakpoints in the parent, otherwise | |
1561 | the child could still trip on the parent's breakpoints. Since | |
1562 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1563 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1564 | return 0; |
1565 | ||
1042e4c0 SS |
1566 | /* Tracepoints are inserted by the target at a time of its choosing, |
1567 | not by us. */ | |
35df4500 | 1568 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1569 | return 0; |
1570 | ||
74960c60 VP |
1571 | return 1; |
1572 | } | |
1573 | ||
934709f0 PW |
1574 | /* Same as should_be_inserted but does the check assuming |
1575 | that the location is not duplicated. */ | |
1576 | ||
1577 | static int | |
1578 | unduplicated_should_be_inserted (struct bp_location *bl) | |
1579 | { | |
1580 | int result; | |
1581 | const int save_duplicate = bl->duplicate; | |
1582 | ||
1583 | bl->duplicate = 0; | |
1584 | result = should_be_inserted (bl); | |
1585 | bl->duplicate = save_duplicate; | |
1586 | return result; | |
1587 | } | |
1588 | ||
35df4500 TJB |
1589 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1590 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
3fbb6ffa | 1591 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. |
c30eee59 TJB |
1592 | Returns 0 for success, 1 if the bp_location type is not supported or |
1593 | -1 for failure. | |
879bfdc2 | 1594 | |
4a64f543 MS |
1595 | NOTE drow/2003-09-09: This routine could be broken down to an |
1596 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1597 | static int |
35df4500 | 1598 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1599 | struct ui_file *tmp_error_stream, |
3fbb6ffa | 1600 | int *disabled_breaks, |
26bb91f3 | 1601 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1602 | { |
1603 | int val = 0; | |
1604 | ||
35df4500 | 1605 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1606 | return 0; |
1607 | ||
8181d85f | 1608 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1609 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1610 | bl->target_info.placed_address = bl->address; | |
1611 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 1612 | bl->target_info.length = bl->length; |
8181d85f | 1613 | |
35df4500 TJB |
1614 | if (bl->loc_type == bp_loc_software_breakpoint |
1615 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1616 | { |
35df4500 | 1617 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1618 | { |
1619 | /* If the explicitly specified breakpoint type | |
1620 | is not hardware breakpoint, check the memory map to see | |
1621 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1622 | |
765dc015 VP |
1623 | Two important cases are: |
1624 | - location type is not hardware breakpoint, memory | |
1625 | is readonly. We change the type of the location to | |
1626 | hardware breakpoint. | |
4a64f543 MS |
1627 | - location type is hardware breakpoint, memory is |
1628 | read-write. This means we've previously made the | |
1629 | location hardware one, but then the memory map changed, | |
1630 | so we undo. | |
765dc015 | 1631 | |
4a64f543 MS |
1632 | When breakpoints are removed, remove_breakpoints will use |
1633 | location types we've just set here, the only possible | |
1634 | problem is that memory map has changed during running | |
1635 | program, but it's not going to work anyway with current | |
1636 | gdb. */ | |
765dc015 | 1637 | struct mem_region *mr |
35df4500 | 1638 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1639 | |
1640 | if (mr) | |
1641 | { | |
1642 | if (automatic_hardware_breakpoints) | |
1643 | { | |
765dc015 VP |
1644 | enum bp_loc_type new_type; |
1645 | ||
1646 | if (mr->attrib.mode != MEM_RW) | |
1647 | new_type = bp_loc_hardware_breakpoint; | |
1648 | else | |
1649 | new_type = bp_loc_software_breakpoint; | |
1650 | ||
35df4500 | 1651 | if (new_type != bl->loc_type) |
765dc015 VP |
1652 | { |
1653 | static int said = 0; | |
cc59ec59 | 1654 | |
35df4500 | 1655 | bl->loc_type = new_type; |
765dc015 VP |
1656 | if (!said) |
1657 | { | |
3e43a32a MS |
1658 | fprintf_filtered (gdb_stdout, |
1659 | _("Note: automatically using " | |
1660 | "hardware breakpoints for " | |
1661 | "read-only addresses.\n")); | |
765dc015 VP |
1662 | said = 1; |
1663 | } | |
1664 | } | |
1665 | } | |
35df4500 | 1666 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1667 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1668 | warning (_("cannot set software breakpoint " |
1669 | "at readonly address %s"), | |
35df4500 | 1670 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1671 | } |
1672 | } | |
1673 | ||
879bfdc2 DJ |
1674 | /* First check to see if we have to handle an overlay. */ |
1675 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1676 | || bl->section == NULL |
1677 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1678 | { |
1679 | /* No overlay handling: just set the breakpoint. */ | |
1680 | ||
348d480f | 1681 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1682 | } |
1683 | else | |
1684 | { | |
4a64f543 | 1685 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1686 | Shall we set a breakpoint at the LMA? */ |
1687 | if (!overlay_events_enabled) | |
1688 | { | |
1689 | /* Yes -- overlay event support is not active, | |
1690 | so we must try to set a breakpoint at the LMA. | |
1691 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1692 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1693 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1694 | bl->owner->number); |
879bfdc2 DJ |
1695 | else |
1696 | { | |
35df4500 TJB |
1697 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1698 | bl->section); | |
879bfdc2 | 1699 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1700 | bl->overlay_target_info = bl->target_info; |
1701 | bl->overlay_target_info.placed_address = addr; | |
1702 | val = target_insert_breakpoint (bl->gdbarch, | |
1703 | &bl->overlay_target_info); | |
879bfdc2 | 1704 | if (val != 0) |
99361f52 | 1705 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1706 | "Overlay breakpoint %d " |
1707 | "failed: in ROM?\n", | |
35df4500 | 1708 | bl->owner->number); |
879bfdc2 DJ |
1709 | } |
1710 | } | |
1711 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1712 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1713 | { |
1714 | /* Yes. This overlay section is mapped into memory. */ | |
348d480f | 1715 | val = bl->owner->ops->insert_location (bl); |
879bfdc2 DJ |
1716 | } |
1717 | else | |
1718 | { | |
1719 | /* No. This breakpoint will not be inserted. | |
1720 | No error, but do not mark the bp as 'inserted'. */ | |
1721 | return 0; | |
1722 | } | |
1723 | } | |
1724 | ||
1725 | if (val) | |
1726 | { | |
1727 | /* Can't set the breakpoint. */ | |
35df4500 | 1728 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1729 | { |
4a64f543 | 1730 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1731 | val = 0; |
35df4500 | 1732 | bl->shlib_disabled = 1; |
8d3788bd | 1733 | observer_notify_breakpoint_modified (bl->owner); |
3fbb6ffa TJB |
1734 | if (!*disabled_breaks) |
1735 | { | |
1736 | fprintf_unfiltered (tmp_error_stream, | |
1737 | "Cannot insert breakpoint %d.\n", | |
1738 | bl->owner->number); | |
1739 | fprintf_unfiltered (tmp_error_stream, | |
1740 | "Temporarily disabling shared " | |
1741 | "library breakpoints:\n"); | |
1742 | } | |
1743 | *disabled_breaks = 1; | |
879bfdc2 | 1744 | fprintf_unfiltered (tmp_error_stream, |
35df4500 | 1745 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1746 | } |
1747 | else | |
879bfdc2 | 1748 | { |
35df4500 | 1749 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1750 | { |
1751 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1752 | fprintf_unfiltered (tmp_error_stream, |
1753 | "Cannot insert hardware " | |
1754 | "breakpoint %d.\n", | |
35df4500 | 1755 | bl->owner->number); |
879bfdc2 DJ |
1756 | } |
1757 | else | |
1758 | { | |
1759 | fprintf_unfiltered (tmp_error_stream, | |
1760 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1761 | bl->owner->number); |
879bfdc2 DJ |
1762 | fprintf_filtered (tmp_error_stream, |
1763 | "Error accessing memory address "); | |
35df4500 | 1764 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1765 | tmp_error_stream); |
879bfdc2 DJ |
1766 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1767 | safe_strerror (val)); | |
1768 | } | |
1769 | ||
1770 | } | |
1771 | } | |
1772 | else | |
35df4500 | 1773 | bl->inserted = 1; |
879bfdc2 DJ |
1774 | |
1775 | return val; | |
1776 | } | |
1777 | ||
35df4500 | 1778 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1779 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1780 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1781 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1782 | { |
77b06cd7 TJB |
1783 | gdb_assert (bl->owner->ops != NULL |
1784 | && bl->owner->ops->insert_location != NULL); | |
1785 | ||
1786 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1787 | |
1788 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1789 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1790 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1791 | { |
1792 | struct bp_location *loc, **loc_temp; | |
1793 | ||
1794 | /* But don't try to insert it, if there's already another | |
1795 | hw_access location that would be considered a duplicate | |
1796 | of this one. */ | |
1797 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1798 | if (loc != bl |
85d721b8 | 1799 | && loc->watchpoint_type == hw_access |
35df4500 | 1800 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1801 | { |
35df4500 TJB |
1802 | bl->duplicate = 1; |
1803 | bl->inserted = 1; | |
1804 | bl->target_info = loc->target_info; | |
1805 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1806 | val = 0; |
1807 | break; | |
1808 | } | |
1809 | ||
1810 | if (val == 1) | |
1811 | { | |
77b06cd7 TJB |
1812 | bl->watchpoint_type = hw_access; |
1813 | val = bl->owner->ops->insert_location (bl); | |
1814 | ||
1815 | if (val) | |
1816 | /* Back to the original value. */ | |
1817 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1818 | } |
1819 | } | |
1820 | ||
35df4500 | 1821 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1822 | } |
1823 | ||
35df4500 | 1824 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1825 | { |
77b06cd7 TJB |
1826 | gdb_assert (bl->owner->ops != NULL |
1827 | && bl->owner->ops->insert_location != NULL); | |
1828 | ||
1829 | val = bl->owner->ops->insert_location (bl); | |
1830 | if (val) | |
1831 | { | |
1832 | bl->owner->enable_state = bp_disabled; | |
1833 | ||
1834 | if (val == 1) | |
1835 | warning (_("\ | |
1836 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1837 | of catchpoint."), bl->owner->number); | |
1838 | else | |
1839 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1840 | } | |
1841 | ||
1842 | bl->inserted = (val == 0); | |
1640b821 DJ |
1843 | |
1844 | /* We've already printed an error message if there was a problem | |
1845 | inserting this catchpoint, and we've disabled the catchpoint, | |
1846 | so just return success. */ | |
1847 | return 0; | |
879bfdc2 DJ |
1848 | } |
1849 | ||
1850 | return 0; | |
1851 | } | |
1852 | ||
6c95b8df PA |
1853 | /* This function is called when program space PSPACE is about to be |
1854 | deleted. It takes care of updating breakpoints to not reference | |
1855 | PSPACE anymore. */ | |
1856 | ||
1857 | void | |
1858 | breakpoint_program_space_exit (struct program_space *pspace) | |
1859 | { | |
1860 | struct breakpoint *b, *b_temp; | |
876fa593 | 1861 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1862 | |
1863 | /* Remove any breakpoint that was set through this program space. */ | |
1864 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1865 | { | |
1866 | if (b->pspace == pspace) | |
1867 | delete_breakpoint (b); | |
1868 | } | |
1869 | ||
1870 | /* Breakpoints set through other program spaces could have locations | |
1871 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1872 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1873 | { |
1874 | struct bp_location *tmp; | |
1875 | ||
1876 | if (loc->pspace == pspace) | |
1877 | { | |
2bdf28a0 | 1878 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1879 | if (loc->owner->loc == loc) |
1880 | loc->owner->loc = loc->next; | |
1881 | else | |
1882 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1883 | if (tmp->next == loc) | |
1884 | { | |
1885 | tmp->next = loc->next; | |
1886 | break; | |
1887 | } | |
1888 | } | |
1889 | } | |
1890 | ||
1891 | /* Now update the global location list to permanently delete the | |
1892 | removed locations above. */ | |
1893 | update_global_location_list (0); | |
1894 | } | |
1895 | ||
74960c60 VP |
1896 | /* Make sure all breakpoints are inserted in inferior. |
1897 | Throws exception on any error. | |
1898 | A breakpoint that is already inserted won't be inserted | |
1899 | again, so calling this function twice is safe. */ | |
1900 | void | |
1901 | insert_breakpoints (void) | |
1902 | { | |
1903 | struct breakpoint *bpt; | |
1904 | ||
1905 | ALL_BREAKPOINTS (bpt) | |
1906 | if (is_hardware_watchpoint (bpt)) | |
3a5c3e22 PA |
1907 | { |
1908 | struct watchpoint *w = (struct watchpoint *) bpt; | |
1909 | ||
1910 | update_watchpoint (w, 0 /* don't reparse. */); | |
1911 | } | |
74960c60 | 1912 | |
b60e7edf | 1913 | update_global_location_list (1); |
74960c60 | 1914 | |
c35b1492 PA |
1915 | /* update_global_location_list does not insert breakpoints when |
1916 | always_inserted_mode is not enabled. Explicitly insert them | |
1917 | now. */ | |
1918 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1919 | insert_breakpoint_locations (); |
1920 | } | |
1921 | ||
c30eee59 | 1922 | /* Used when starting or continuing the program. */ |
c906108c | 1923 | |
74960c60 VP |
1924 | static void |
1925 | insert_breakpoint_locations (void) | |
c906108c | 1926 | { |
a5606eee | 1927 | struct breakpoint *bpt; |
35df4500 | 1928 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1929 | int error = 0; |
c906108c | 1930 | int val = 0; |
3fbb6ffa | 1931 | int disabled_breaks = 0; |
81d0cc19 | 1932 | int hw_breakpoint_error = 0; |
c906108c | 1933 | |
81d0cc19 | 1934 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1935 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1936 | |
81d0cc19 GS |
1937 | /* Explicitly mark the warning -- this will only be printed if |
1938 | there was an error. */ | |
1939 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1940 | |
1941 | save_current_space_and_thread (); | |
1942 | ||
35df4500 | 1943 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1944 | { |
35df4500 | 1945 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1946 | continue; |
1947 | ||
4a64f543 MS |
1948 | /* There is no point inserting thread-specific breakpoints if |
1949 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1950 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1951 | if (bl->owner->thread != -1 |
1952 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1953 | continue; |
1954 | ||
35df4500 | 1955 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1956 | |
1957 | /* For targets that support global breakpoints, there's no need | |
1958 | to select an inferior to insert breakpoint to. In fact, even | |
1959 | if we aren't attached to any process yet, we should still | |
1960 | insert breakpoints. */ | |
1961 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1962 | && ptid_equal (inferior_ptid, null_ptid)) | |
1963 | continue; | |
1964 | ||
3fbb6ffa TJB |
1965 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
1966 | &hw_breakpoint_error); | |
879bfdc2 | 1967 | if (val) |
e236ba44 | 1968 | error = val; |
879bfdc2 | 1969 | } |
c906108c | 1970 | |
4a64f543 MS |
1971 | /* If we failed to insert all locations of a watchpoint, remove |
1972 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1973 | ALL_BREAKPOINTS (bpt) |
1974 | { | |
1975 | int some_failed = 0; | |
1976 | struct bp_location *loc; | |
1977 | ||
1978 | if (!is_hardware_watchpoint (bpt)) | |
1979 | continue; | |
1980 | ||
d6b74ac4 | 1981 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1982 | continue; |
74960c60 VP |
1983 | |
1984 | if (bpt->disposition == disp_del_at_next_stop) | |
1985 | continue; | |
a5606eee VP |
1986 | |
1987 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1988 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1989 | { |
1990 | some_failed = 1; | |
1991 | break; | |
1992 | } | |
1993 | if (some_failed) | |
1994 | { | |
1995 | for (loc = bpt->loc; loc; loc = loc->next) | |
1996 | if (loc->inserted) | |
1997 | remove_breakpoint (loc, mark_uninserted); | |
1998 | ||
1999 | hw_breakpoint_error = 1; | |
2000 | fprintf_unfiltered (tmp_error_stream, | |
2001 | "Could not insert hardware watchpoint %d.\n", | |
2002 | bpt->number); | |
2003 | error = -1; | |
2004 | } | |
2005 | } | |
2006 | ||
e236ba44 | 2007 | if (error) |
81d0cc19 GS |
2008 | { |
2009 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2010 | message about possibly exhausted resources. */ | |
879bfdc2 | 2011 | if (hw_breakpoint_error) |
81d0cc19 | 2012 | { |
c6510018 MS |
2013 | fprintf_unfiltered (tmp_error_stream, |
2014 | "Could not insert hardware breakpoints:\n\ | |
2015 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2016 | } |
81d0cc19 GS |
2017 | target_terminal_ours_for_output (); |
2018 | error_stream (tmp_error_stream); | |
2019 | } | |
f7545552 TT |
2020 | |
2021 | do_cleanups (cleanups); | |
c906108c SS |
2022 | } |
2023 | ||
c30eee59 TJB |
2024 | /* Used when the program stops. |
2025 | Returns zero if successful, or non-zero if there was a problem | |
2026 | removing a breakpoint location. */ | |
2027 | ||
c906108c | 2028 | int |
fba45db2 | 2029 | remove_breakpoints (void) |
c906108c | 2030 | { |
35df4500 | 2031 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2032 | int val = 0; |
c906108c | 2033 | |
35df4500 | 2034 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2035 | { |
35df4500 TJB |
2036 | if (bl->inserted) |
2037 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 2038 | } |
3a1bae8e | 2039 | return val; |
c906108c SS |
2040 | } |
2041 | ||
6c95b8df PA |
2042 | /* Remove breakpoints of process PID. */ |
2043 | ||
2044 | int | |
2045 | remove_breakpoints_pid (int pid) | |
2046 | { | |
35df4500 | 2047 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2048 | int val; |
2049 | struct inferior *inf = find_inferior_pid (pid); | |
2050 | ||
35df4500 | 2051 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2052 | { |
35df4500 | 2053 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2054 | continue; |
2055 | ||
35df4500 | 2056 | if (bl->inserted) |
6c95b8df | 2057 | { |
35df4500 | 2058 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2059 | if (val != 0) |
2060 | return val; | |
2061 | } | |
2062 | } | |
2063 | return 0; | |
2064 | } | |
2065 | ||
c906108c | 2066 | int |
fba45db2 | 2067 | reattach_breakpoints (int pid) |
c906108c | 2068 | { |
6c95b8df | 2069 | struct cleanup *old_chain; |
35df4500 | 2070 | struct bp_location *bl, **blp_tmp; |
c906108c | 2071 | int val; |
86b887df | 2072 | struct ui_file *tmp_error_stream; |
3fbb6ffa | 2073 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2074 | struct inferior *inf; |
2075 | struct thread_info *tp; | |
2076 | ||
2077 | tp = any_live_thread_of_process (pid); | |
2078 | if (tp == NULL) | |
2079 | return 1; | |
2080 | ||
2081 | inf = find_inferior_pid (pid); | |
2082 | old_chain = save_inferior_ptid (); | |
2083 | ||
2084 | inferior_ptid = tp->ptid; | |
a4954f26 | 2085 | |
86b887df | 2086 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2087 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2088 | |
35df4500 | 2089 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2090 | { |
35df4500 | 2091 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2092 | continue; |
2093 | ||
35df4500 | 2094 | if (bl->inserted) |
c5aa993b | 2095 | { |
35df4500 | 2096 | bl->inserted = 0; |
3fbb6ffa | 2097 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); |
c5aa993b JM |
2098 | if (val != 0) |
2099 | { | |
ce696e05 | 2100 | do_cleanups (old_chain); |
c5aa993b JM |
2101 | return val; |
2102 | } | |
2103 | } | |
2104 | } | |
ce696e05 | 2105 | do_cleanups (old_chain); |
c906108c SS |
2106 | return 0; |
2107 | } | |
2108 | ||
e58b0e63 PA |
2109 | static int internal_breakpoint_number = -1; |
2110 | ||
84f4c1fe PM |
2111 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2112 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2113 | from internal_breakpoint_number and that variable decremented. | |
e5dd4106 | 2114 | Otherwise the breakpoint number will be populated from |
84f4c1fe PM |
2115 | breakpoint_count and that value incremented. Internal breakpoints |
2116 | do not set the internal var bpnum. */ | |
2117 | static void | |
2118 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2119 | { | |
2120 | if (internal) | |
2121 | b->number = internal_breakpoint_number--; | |
2122 | else | |
2123 | { | |
2124 | set_breakpoint_count (breakpoint_count + 1); | |
2125 | b->number = breakpoint_count; | |
2126 | } | |
2127 | } | |
2128 | ||
e62c965a | 2129 | static struct breakpoint * |
a6d9a66e | 2130 | create_internal_breakpoint (struct gdbarch *gdbarch, |
06edf0c0 | 2131 | CORE_ADDR address, enum bptype type, |
c0a91b2b | 2132 | const struct breakpoint_ops *ops) |
e62c965a | 2133 | { |
e62c965a PP |
2134 | struct symtab_and_line sal; |
2135 | struct breakpoint *b; | |
2136 | ||
4a64f543 | 2137 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2138 | |
2139 | sal.pc = address; | |
2140 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2141 | sal.pspace = current_program_space; |
e62c965a | 2142 | |
06edf0c0 | 2143 | b = set_raw_breakpoint (gdbarch, sal, type, ops); |
e62c965a PP |
2144 | b->number = internal_breakpoint_number--; |
2145 | b->disposition = disp_donttouch; | |
2146 | ||
2147 | return b; | |
2148 | } | |
2149 | ||
17450429 PP |
2150 | static const char *const longjmp_names[] = |
2151 | { | |
2152 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2153 | }; | |
2154 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2155 | ||
2156 | /* Per-objfile data private to breakpoint.c. */ | |
2157 | struct breakpoint_objfile_data | |
2158 | { | |
2159 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2160 | struct minimal_symbol *overlay_msym; | |
2161 | ||
2162 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2163 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2164 | ||
2165 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2166 | struct minimal_symbol *terminate_msym; | |
2167 | ||
2168 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2169 | struct minimal_symbol *exception_msym; | |
2170 | }; | |
2171 | ||
2172 | static const struct objfile_data *breakpoint_objfile_key; | |
2173 | ||
2174 | /* Minimal symbol not found sentinel. */ | |
2175 | static struct minimal_symbol msym_not_found; | |
2176 | ||
2177 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2178 | ||
2179 | static int | |
2180 | msym_not_found_p (const struct minimal_symbol *msym) | |
2181 | { | |
2182 | return msym == &msym_not_found; | |
2183 | } | |
2184 | ||
2185 | /* Return per-objfile data needed by breakpoint.c. | |
2186 | Allocate the data if necessary. */ | |
2187 | ||
2188 | static struct breakpoint_objfile_data * | |
2189 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2190 | { | |
2191 | struct breakpoint_objfile_data *bp_objfile_data; | |
2192 | ||
2193 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2194 | if (bp_objfile_data == NULL) | |
2195 | { | |
2196 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2197 | sizeof (*bp_objfile_data)); | |
2198 | ||
2199 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2200 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2201 | } | |
2202 | return bp_objfile_data; | |
2203 | } | |
2204 | ||
e62c965a | 2205 | static void |
af02033e | 2206 | create_overlay_event_breakpoint (void) |
e62c965a | 2207 | { |
69de3c6a | 2208 | struct objfile *objfile; |
af02033e | 2209 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2210 | |
69de3c6a PP |
2211 | ALL_OBJFILES (objfile) |
2212 | { | |
2213 | struct breakpoint *b; | |
17450429 PP |
2214 | struct breakpoint_objfile_data *bp_objfile_data; |
2215 | CORE_ADDR addr; | |
69de3c6a | 2216 | |
17450429 PP |
2217 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2218 | ||
2219 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2220 | continue; | |
2221 | ||
2222 | if (bp_objfile_data->overlay_msym == NULL) | |
2223 | { | |
2224 | struct minimal_symbol *m; | |
2225 | ||
2226 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2227 | if (m == NULL) | |
2228 | { | |
2229 | /* Avoid future lookups in this objfile. */ | |
2230 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2231 | continue; | |
2232 | } | |
2233 | bp_objfile_data->overlay_msym = m; | |
2234 | } | |
e62c965a | 2235 | |
17450429 PP |
2236 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2237 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2238 | bp_overlay_event, |
2239 | &internal_breakpoint_ops); | |
69de3c6a | 2240 | b->addr_string = xstrdup (func_name); |
e62c965a | 2241 | |
69de3c6a PP |
2242 | if (overlay_debugging == ovly_auto) |
2243 | { | |
2244 | b->enable_state = bp_enabled; | |
2245 | overlay_events_enabled = 1; | |
2246 | } | |
2247 | else | |
2248 | { | |
2249 | b->enable_state = bp_disabled; | |
2250 | overlay_events_enabled = 0; | |
2251 | } | |
e62c965a PP |
2252 | } |
2253 | update_global_location_list (1); | |
2254 | } | |
2255 | ||
0fd8e87f | 2256 | static void |
af02033e | 2257 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2258 | { |
6c95b8df | 2259 | struct program_space *pspace; |
6c95b8df PA |
2260 | struct cleanup *old_chain; |
2261 | ||
2262 | old_chain = save_current_program_space (); | |
0fd8e87f | 2263 | |
6c95b8df | 2264 | ALL_PSPACES (pspace) |
af02033e PP |
2265 | { |
2266 | struct objfile *objfile; | |
2267 | ||
2268 | set_current_program_space (pspace); | |
2269 | ||
2270 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2271 | { |
af02033e PP |
2272 | int i; |
2273 | struct gdbarch *gdbarch; | |
17450429 | 2274 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2275 | |
af02033e PP |
2276 | gdbarch = get_objfile_arch (objfile); |
2277 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2278 | continue; |
2279 | ||
17450429 PP |
2280 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2281 | ||
2282 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2283 | { |
2284 | struct breakpoint *b; | |
af02033e | 2285 | const char *func_name; |
17450429 | 2286 | CORE_ADDR addr; |
6c95b8df | 2287 | |
17450429 | 2288 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2289 | continue; |
0fd8e87f | 2290 | |
17450429 PP |
2291 | func_name = longjmp_names[i]; |
2292 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2293 | { | |
2294 | struct minimal_symbol *m; | |
2295 | ||
2296 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2297 | if (m == NULL) | |
2298 | { | |
2299 | /* Prevent future lookups in this objfile. */ | |
2300 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2301 | continue; | |
2302 | } | |
2303 | bp_objfile_data->longjmp_msym[i] = m; | |
2304 | } | |
2305 | ||
2306 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
06edf0c0 PA |
2307 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master, |
2308 | &internal_breakpoint_ops); | |
af02033e PP |
2309 | b->addr_string = xstrdup (func_name); |
2310 | b->enable_state = bp_disabled; | |
2311 | } | |
0fd8e87f | 2312 | } |
af02033e | 2313 | } |
0fd8e87f | 2314 | update_global_location_list (1); |
6c95b8df PA |
2315 | |
2316 | do_cleanups (old_chain); | |
0fd8e87f UW |
2317 | } |
2318 | ||
af02033e | 2319 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2320 | static void |
af02033e | 2321 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2322 | { |
2323 | struct program_space *pspace; | |
aa7d318d | 2324 | struct cleanup *old_chain; |
af02033e | 2325 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2326 | |
2327 | old_chain = save_current_program_space (); | |
2328 | ||
2329 | ALL_PSPACES (pspace) | |
17450429 PP |
2330 | { |
2331 | struct objfile *objfile; | |
2332 | CORE_ADDR addr; | |
2333 | ||
2334 | set_current_program_space (pspace); | |
2335 | ||
aa7d318d TT |
2336 | ALL_OBJFILES (objfile) |
2337 | { | |
2338 | struct breakpoint *b; | |
17450429 | 2339 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2340 | |
17450429 | 2341 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2342 | |
17450429 PP |
2343 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2344 | continue; | |
2345 | ||
2346 | if (bp_objfile_data->terminate_msym == NULL) | |
2347 | { | |
2348 | struct minimal_symbol *m; | |
2349 | ||
2350 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2351 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2352 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2353 | { | |
2354 | /* Prevent future lookups in this objfile. */ | |
2355 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2356 | continue; | |
2357 | } | |
2358 | bp_objfile_data->terminate_msym = m; | |
2359 | } | |
aa7d318d | 2360 | |
17450429 PP |
2361 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2362 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
06edf0c0 PA |
2363 | bp_std_terminate_master, |
2364 | &internal_breakpoint_ops); | |
aa7d318d TT |
2365 | b->addr_string = xstrdup (func_name); |
2366 | b->enable_state = bp_disabled; | |
2367 | } | |
17450429 PP |
2368 | } |
2369 | ||
aa7d318d TT |
2370 | update_global_location_list (1); |
2371 | ||
2372 | do_cleanups (old_chain); | |
2373 | } | |
2374 | ||
186c406b TT |
2375 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2376 | ||
2377 | void | |
2378 | create_exception_master_breakpoint (void) | |
2379 | { | |
2380 | struct objfile *objfile; | |
17450429 | 2381 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2382 | |
2383 | ALL_OBJFILES (objfile) | |
2384 | { | |
17450429 PP |
2385 | struct breakpoint *b; |
2386 | struct gdbarch *gdbarch; | |
2387 | struct breakpoint_objfile_data *bp_objfile_data; | |
2388 | CORE_ADDR addr; | |
2389 | ||
2390 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2391 | ||
2392 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2393 | continue; | |
2394 | ||
2395 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2396 | |
17450429 | 2397 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2398 | { |
17450429 | 2399 | struct minimal_symbol *debug_hook; |
186c406b | 2400 | |
17450429 PP |
2401 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2402 | if (debug_hook == NULL) | |
2403 | { | |
2404 | bp_objfile_data->exception_msym = &msym_not_found; | |
2405 | continue; | |
2406 | } | |
2407 | ||
2408 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2409 | } |
17450429 PP |
2410 | |
2411 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2412 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2413 | ¤t_target); | |
06edf0c0 PA |
2414 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master, |
2415 | &internal_breakpoint_ops); | |
17450429 PP |
2416 | b->addr_string = xstrdup (func_name); |
2417 | b->enable_state = bp_disabled; | |
186c406b TT |
2418 | } |
2419 | ||
2420 | update_global_location_list (1); | |
2421 | } | |
2422 | ||
c906108c | 2423 | void |
fba45db2 | 2424 | update_breakpoints_after_exec (void) |
c906108c | 2425 | { |
35df4500 | 2426 | struct breakpoint *b, *b_tmp; |
876fa593 | 2427 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2428 | |
25b22b0a PA |
2429 | /* We're about to delete breakpoints from GDB's lists. If the |
2430 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2431 | writing the breakpoints' "shadow contents" back into memory. The | |
2432 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2433 | do that. Instead, the target is responsible from marking | |
2434 | breakpoints out as soon as it detects an exec. We don't do that | |
2435 | here instead, because there may be other attempts to delete | |
2436 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2437 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2438 | if (bploc->pspace == current_program_space) |
2439 | gdb_assert (!bploc->inserted); | |
c906108c | 2440 | |
35df4500 | 2441 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2442 | { |
6c95b8df PA |
2443 | if (b->pspace != current_program_space) |
2444 | continue; | |
2445 | ||
4a64f543 | 2446 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2447 | if (b->type == bp_shlib_event) |
2448 | { | |
2449 | delete_breakpoint (b); | |
2450 | continue; | |
2451 | } | |
c906108c | 2452 | |
4a64f543 | 2453 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2454 | if (b->type == bp_jit_event) |
2455 | { | |
2456 | delete_breakpoint (b); | |
2457 | continue; | |
2458 | } | |
2459 | ||
1900040c | 2460 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2461 | as must overlay event and longjmp master breakpoints. */ |
2462 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2463 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2464 | || b->type == bp_exception_master) | |
c4093a6a JM |
2465 | { |
2466 | delete_breakpoint (b); | |
2467 | continue; | |
2468 | } | |
2469 | ||
4a64f543 | 2470 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 2471 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
2472 | { |
2473 | delete_breakpoint (b); | |
2474 | continue; | |
2475 | } | |
2476 | ||
611c83ae PA |
2477 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2478 | after an exec. */ | |
186c406b TT |
2479 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2480 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2481 | { |
2482 | delete_breakpoint (b); | |
2483 | continue; | |
2484 | } | |
2485 | ||
ce78b96d JB |
2486 | if (b->type == bp_catchpoint) |
2487 | { | |
2488 | /* For now, none of the bp_catchpoint breakpoints need to | |
2489 | do anything at this point. In the future, if some of | |
2490 | the catchpoints need to something, we will need to add | |
2491 | a new method, and call this method from here. */ | |
2492 | continue; | |
2493 | } | |
2494 | ||
c5aa993b JM |
2495 | /* bp_finish is a special case. The only way we ought to be able |
2496 | to see one of these when an exec() has happened, is if the user | |
2497 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2498 | carries them to the call-site of the current callee, by setting | |
2499 | a temporary bp there and resuming. But in this case, the finish | |
2500 | will carry them entirely through the vfork & exec. | |
2501 | ||
2502 | We don't want to allow a bp_finish to remain inserted now. But | |
2503 | we can't safely delete it, 'cause finish_command has a handle to | |
2504 | the bp on a bpstat, and will later want to delete it. There's a | |
2505 | chance (and I've seen it happen) that if we delete the bp_finish | |
2506 | here, that its storage will get reused by the time finish_command | |
2507 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2508 | We really must allow finish_command to delete a bp_finish. | |
2509 | ||
e5dd4106 | 2510 | In the absence of a general solution for the "how do we know |
53a5351d JM |
2511 | it's safe to delete something others may have handles to?" |
2512 | problem, what we'll do here is just uninsert the bp_finish, and | |
2513 | let finish_command delete it. | |
2514 | ||
2515 | (We know the bp_finish is "doomed" in the sense that it's | |
2516 | momentary, and will be deleted as soon as finish_command sees | |
2517 | the inferior stopped. So it doesn't matter that the bp's | |
2518 | address is probably bogus in the new a.out, unlike e.g., the | |
2519 | solib breakpoints.) */ | |
c5aa993b | 2520 | |
c5aa993b JM |
2521 | if (b->type == bp_finish) |
2522 | { | |
2523 | continue; | |
2524 | } | |
2525 | ||
2526 | /* Without a symbolic address, we have little hope of the | |
2527 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2528 | a.out. */ |
c5aa993b JM |
2529 | if (b->addr_string == NULL) |
2530 | { | |
2531 | delete_breakpoint (b); | |
2532 | continue; | |
2533 | } | |
c5aa993b | 2534 | } |
1900040c | 2535 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2536 | create_overlay_event_breakpoint (); |
2537 | create_longjmp_master_breakpoint (); | |
2538 | create_std_terminate_master_breakpoint (); | |
186c406b | 2539 | create_exception_master_breakpoint (); |
c906108c SS |
2540 | } |
2541 | ||
2542 | int | |
fba45db2 | 2543 | detach_breakpoints (int pid) |
c906108c | 2544 | { |
35df4500 | 2545 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2546 | int val = 0; |
ce696e05 | 2547 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2548 | struct inferior *inf = current_inferior (); |
c5aa993b | 2549 | |
39f77062 | 2550 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2551 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2552 | |
6c95b8df | 2553 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2554 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2555 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2556 | { |
35df4500 | 2557 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2558 | continue; |
2559 | ||
35df4500 TJB |
2560 | if (bl->inserted) |
2561 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2562 | } |
d03285ec UW |
2563 | |
2564 | /* Detach single-step breakpoints as well. */ | |
2565 | detach_single_step_breakpoints (); | |
2566 | ||
ce696e05 | 2567 | do_cleanups (old_chain); |
3a1bae8e | 2568 | return val; |
c906108c SS |
2569 | } |
2570 | ||
35df4500 | 2571 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2572 | Note that this is used to detach breakpoints from a child fork. |
2573 | When we get here, the child isn't in the inferior list, and neither | |
2574 | do we have objects to represent its address space --- we should | |
35df4500 | 2575 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2576 | |
c906108c | 2577 | static int |
35df4500 | 2578 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2579 | { |
2580 | int val; | |
c5aa993b | 2581 | |
35df4500 TJB |
2582 | /* BL is never in moribund_locations by our callers. */ |
2583 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2584 | |
35df4500 | 2585 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2586 | /* Permanent breakpoints cannot be inserted or removed. */ |
2587 | return 0; | |
2588 | ||
74960c60 VP |
2589 | /* The type of none suggests that owner is actually deleted. |
2590 | This should not ever happen. */ | |
35df4500 | 2591 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2592 | |
35df4500 TJB |
2593 | if (bl->loc_type == bp_loc_software_breakpoint |
2594 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2595 | { |
c02f5703 MS |
2596 | /* "Normal" instruction breakpoint: either the standard |
2597 | trap-instruction bp (bp_breakpoint), or a | |
2598 | bp_hardware_breakpoint. */ | |
2599 | ||
2600 | /* First check to see if we have to handle an overlay. */ | |
2601 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2602 | || bl->section == NULL |
2603 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2604 | { |
2605 | /* No overlay handling: just remove the breakpoint. */ | |
348d480f | 2606 | val = bl->owner->ops->remove_location (bl); |
c02f5703 | 2607 | } |
c906108c SS |
2608 | else |
2609 | { | |
4a64f543 | 2610 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2611 | Did we set a breakpoint at the LMA? */ |
2612 | if (!overlay_events_enabled) | |
2613 | { | |
2614 | /* Yes -- overlay event support is not active, so we | |
2615 | should have set a breakpoint at the LMA. Remove it. | |
2616 | */ | |
c02f5703 MS |
2617 | /* Ignore any failures: if the LMA is in ROM, we will |
2618 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2619 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2620 | target_remove_hw_breakpoint (bl->gdbarch, | |
2621 | &bl->overlay_target_info); | |
c02f5703 | 2622 | else |
35df4500 TJB |
2623 | target_remove_breakpoint (bl->gdbarch, |
2624 | &bl->overlay_target_info); | |
c02f5703 MS |
2625 | } |
2626 | /* Did we set a breakpoint at the VMA? | |
2627 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2628 | if (bl->inserted) |
c906108c | 2629 | { |
c02f5703 MS |
2630 | /* Yes -- remove it. Previously we did not bother to |
2631 | remove the breakpoint if the section had been | |
2632 | unmapped, but let's not rely on that being safe. We | |
2633 | don't know what the overlay manager might do. */ | |
aa67235e UW |
2634 | |
2635 | /* However, we should remove *software* breakpoints only | |
2636 | if the section is still mapped, or else we overwrite | |
2637 | wrong code with the saved shadow contents. */ | |
348d480f PA |
2638 | if (bl->loc_type == bp_loc_hardware_breakpoint |
2639 | || section_is_mapped (bl->section)) | |
2640 | val = bl->owner->ops->remove_location (bl); | |
aa67235e UW |
2641 | else |
2642 | val = 0; | |
c906108c | 2643 | } |
c02f5703 MS |
2644 | else |
2645 | { | |
2646 | /* No -- not inserted, so no need to remove. No error. */ | |
2647 | val = 0; | |
2648 | } | |
c906108c | 2649 | } |
879d1e6b UW |
2650 | |
2651 | /* In some cases, we might not be able to remove a breakpoint | |
2652 | in a shared library that has already been removed, but we | |
2653 | have not yet processed the shlib unload event. */ | |
35df4500 | 2654 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2655 | val = 0; |
2656 | ||
c906108c SS |
2657 | if (val) |
2658 | return val; | |
35df4500 | 2659 | bl->inserted = (is == mark_inserted); |
c906108c | 2660 | } |
35df4500 | 2661 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2662 | { |
77b06cd7 TJB |
2663 | gdb_assert (bl->owner->ops != NULL |
2664 | && bl->owner->ops->remove_location != NULL); | |
2665 | ||
35df4500 | 2666 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2667 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2668 | |
c906108c | 2669 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2670 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2671 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2672 | bl->owner->number); |
c906108c | 2673 | } |
35df4500 TJB |
2674 | else if (bl->owner->type == bp_catchpoint |
2675 | && breakpoint_enabled (bl->owner) | |
2676 | && !bl->duplicate) | |
ce78b96d | 2677 | { |
77b06cd7 TJB |
2678 | gdb_assert (bl->owner->ops != NULL |
2679 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2680 | |
77b06cd7 | 2681 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2682 | if (val) |
2683 | return val; | |
77b06cd7 | 2684 | |
35df4500 | 2685 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2686 | } |
c906108c SS |
2687 | |
2688 | return 0; | |
2689 | } | |
2690 | ||
6c95b8df | 2691 | static int |
35df4500 | 2692 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2693 | { |
2694 | int ret; | |
2695 | struct cleanup *old_chain; | |
2696 | ||
35df4500 TJB |
2697 | /* BL is never in moribund_locations by our callers. */ |
2698 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2699 | |
35df4500 | 2700 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2701 | /* Permanent breakpoints cannot be inserted or removed. */ |
2702 | return 0; | |
2703 | ||
2704 | /* The type of none suggests that owner is actually deleted. | |
2705 | This should not ever happen. */ | |
35df4500 | 2706 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2707 | |
2708 | old_chain = save_current_space_and_thread (); | |
2709 | ||
35df4500 | 2710 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2711 | |
35df4500 | 2712 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2713 | |
2714 | do_cleanups (old_chain); | |
2715 | return ret; | |
2716 | } | |
2717 | ||
c906108c SS |
2718 | /* Clear the "inserted" flag in all breakpoints. */ |
2719 | ||
25b22b0a | 2720 | void |
fba45db2 | 2721 | mark_breakpoints_out (void) |
c906108c | 2722 | { |
35df4500 | 2723 | struct bp_location *bl, **blp_tmp; |
c906108c | 2724 | |
35df4500 TJB |
2725 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2726 | if (bl->pspace == current_program_space) | |
2727 | bl->inserted = 0; | |
c906108c SS |
2728 | } |
2729 | ||
53a5351d JM |
2730 | /* Clear the "inserted" flag in all breakpoints and delete any |
2731 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2732 | |
2733 | Plus other such housekeeping that has to be done for breakpoints | |
2734 | between runs. | |
2735 | ||
53a5351d JM |
2736 | Note: this function gets called at the end of a run (by |
2737 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2738 | init_wait_for_inferior). */ |
c906108c SS |
2739 | |
2740 | ||
2741 | ||
2742 | void | |
fba45db2 | 2743 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2744 | { |
35df4500 TJB |
2745 | struct breakpoint *b, *b_tmp; |
2746 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2747 | int ix; |
6c95b8df | 2748 | struct program_space *pspace = current_program_space; |
c906108c | 2749 | |
50c71eaf PA |
2750 | /* If breakpoint locations are shared across processes, then there's |
2751 | nothing to do. */ | |
2567c7d9 | 2752 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2753 | return; |
2754 | ||
35df4500 | 2755 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2756 | { |
35df4500 TJB |
2757 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2758 | if (bl->pspace == pspace | |
2759 | && bl->owner->enable_state != bp_permanent) | |
2760 | bl->inserted = 0; | |
6c95b8df | 2761 | } |
075f6582 | 2762 | |
35df4500 | 2763 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2764 | { |
6c95b8df PA |
2765 | if (b->loc && b->loc->pspace != pspace) |
2766 | continue; | |
2767 | ||
c5aa993b JM |
2768 | switch (b->type) |
2769 | { | |
2770 | case bp_call_dummy: | |
c906108c | 2771 | |
c5aa993b | 2772 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2773 | cause problems when the inferior is rerun, so we better get |
2774 | rid of it. */ | |
2775 | ||
2776 | case bp_watchpoint_scope: | |
2777 | ||
2778 | /* Also get rid of scope breakpoints. */ | |
2779 | ||
2780 | case bp_shlib_event: | |
2781 | ||
2782 | /* Also remove solib event breakpoints. Their addresses may | |
2783 | have changed since the last time we ran the program. | |
2784 | Actually we may now be debugging against different target; | |
2785 | and so the solib backend that installed this breakpoint may | |
2786 | not be used in by the target. E.g., | |
2787 | ||
2788 | (gdb) file prog-linux | |
2789 | (gdb) run # native linux target | |
2790 | ... | |
2791 | (gdb) kill | |
2792 | (gdb) file prog-win.exe | |
2793 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2794 | */ | |
c906108c | 2795 | |
c5aa993b JM |
2796 | delete_breakpoint (b); |
2797 | break; | |
c906108c | 2798 | |
c5aa993b JM |
2799 | case bp_watchpoint: |
2800 | case bp_hardware_watchpoint: | |
2801 | case bp_read_watchpoint: | |
2802 | case bp_access_watchpoint: | |
3a5c3e22 PA |
2803 | { |
2804 | struct watchpoint *w = (struct watchpoint *) b; | |
c906108c | 2805 | |
3a5c3e22 PA |
2806 | /* Likewise for watchpoints on local expressions. */ |
2807 | if (w->exp_valid_block != NULL) | |
2808 | delete_breakpoint (b); | |
2809 | else if (context == inf_starting) | |
2810 | { | |
2811 | /* Reset val field to force reread of starting value in | |
2812 | insert_breakpoints. */ | |
2813 | if (w->val) | |
2814 | value_free (w->val); | |
2815 | w->val = NULL; | |
2816 | w->val_valid = 0; | |
c860120c | 2817 | } |
3a5c3e22 | 2818 | } |
c5aa993b JM |
2819 | break; |
2820 | default: | |
c5aa993b JM |
2821 | break; |
2822 | } | |
2823 | } | |
1c5cfe86 PA |
2824 | |
2825 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2826 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2827 | decref_bp_location (&bl); | |
1c5cfe86 | 2828 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2829 | } |
2830 | ||
6c95b8df PA |
2831 | /* These functions concern about actual breakpoints inserted in the |
2832 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2833 | we need to hop over the bkpt --- so we check for address space | |
2834 | match, not program space. */ | |
2835 | ||
c2c6d25f JM |
2836 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2837 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2838 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2839 | permanent breakpoint. | |
2840 | - When continuing from a location with an ordinary breakpoint, we | |
2841 | actually single step once before calling insert_breakpoints. | |
e5dd4106 | 2842 | - When continuing from a location with a permanent breakpoint, we |
c2c6d25f JM |
2843 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by |
2844 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2845 | |
c2c6d25f | 2846 | enum breakpoint_here |
6c95b8df | 2847 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2848 | { |
35df4500 | 2849 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2850 | int any_breakpoint_here = 0; |
c906108c | 2851 | |
35df4500 | 2852 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2853 | { |
35df4500 TJB |
2854 | if (bl->loc_type != bp_loc_software_breakpoint |
2855 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2856 | continue; |
2857 | ||
f1310107 | 2858 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
2859 | if ((breakpoint_enabled (bl->owner) |
2860 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 2861 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2862 | { |
2863 | if (overlay_debugging | |
35df4500 TJB |
2864 | && section_is_overlay (bl->section) |
2865 | && !section_is_mapped (bl->section)) | |
075f6582 | 2866 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2867 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2868 | return permanent_breakpoint_here; |
2869 | else | |
2870 | any_breakpoint_here = 1; | |
2871 | } | |
2872 | } | |
c906108c | 2873 | |
c2c6d25f | 2874 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2875 | } |
2876 | ||
1c5cfe86 PA |
2877 | /* Return true if there's a moribund breakpoint at PC. */ |
2878 | ||
2879 | int | |
6c95b8df | 2880 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2881 | { |
2882 | struct bp_location *loc; | |
2883 | int ix; | |
2884 | ||
2885 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 2886 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
2887 | return 1; |
2888 | ||
2889 | return 0; | |
2890 | } | |
c2c6d25f | 2891 | |
c36b740a | 2892 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2893 | inserted using regular breakpoint_chain / bp_location array |
2894 | mechanism. This does not check for single-step breakpoints, which | |
2895 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2896 | |
2897 | int | |
4a64f543 MS |
2898 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2899 | CORE_ADDR pc) | |
c906108c | 2900 | { |
35df4500 | 2901 | struct bp_location *bl, **blp_tmp; |
c906108c | 2902 | |
35df4500 | 2903 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2904 | { |
35df4500 TJB |
2905 | if (bl->loc_type != bp_loc_software_breakpoint |
2906 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2907 | continue; |
2908 | ||
35df4500 | 2909 | if (bl->inserted |
f1310107 | 2910 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2911 | { |
2912 | if (overlay_debugging | |
35df4500 TJB |
2913 | && section_is_overlay (bl->section) |
2914 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2915 | continue; /* unmapped overlay -- can't be a match */ |
2916 | else | |
2917 | return 1; | |
2918 | } | |
c5aa993b | 2919 | } |
c36b740a VP |
2920 | return 0; |
2921 | } | |
2922 | ||
2923 | /* Returns non-zero iff there's either regular breakpoint | |
2924 | or a single step breakpoint inserted at PC. */ | |
2925 | ||
2926 | int | |
6c95b8df | 2927 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2928 | { |
6c95b8df | 2929 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2930 | return 1; |
c906108c | 2931 | |
6c95b8df | 2932 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2933 | return 1; |
2934 | ||
c906108c SS |
2935 | return 0; |
2936 | } | |
2937 | ||
4fa8626c DJ |
2938 | /* This function returns non-zero iff there is a software breakpoint |
2939 | inserted at PC. */ | |
2940 | ||
2941 | int | |
3e43a32a MS |
2942 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2943 | CORE_ADDR pc) | |
4fa8626c | 2944 | { |
35df4500 | 2945 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2946 | |
35df4500 | 2947 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2948 | { |
35df4500 | 2949 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2950 | continue; |
2951 | ||
35df4500 TJB |
2952 | if (bl->inserted |
2953 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2954 | aspace, pc)) |
4fa8626c DJ |
2955 | { |
2956 | if (overlay_debugging | |
35df4500 TJB |
2957 | && section_is_overlay (bl->section) |
2958 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2959 | continue; /* unmapped overlay -- can't be a match */ |
2960 | else | |
2961 | return 1; | |
2962 | } | |
2963 | } | |
2964 | ||
1aafd4da | 2965 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2966 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2967 | return 1; |
2968 | ||
4fa8626c DJ |
2969 | return 0; |
2970 | } | |
2971 | ||
9093389c PA |
2972 | int |
2973 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2974 | CORE_ADDR addr, ULONGEST len) | |
2975 | { | |
2976 | struct breakpoint *bpt; | |
2977 | ||
2978 | ALL_BREAKPOINTS (bpt) | |
2979 | { | |
2980 | struct bp_location *loc; | |
2981 | ||
2982 | if (bpt->type != bp_hardware_watchpoint | |
2983 | && bpt->type != bp_access_watchpoint) | |
2984 | continue; | |
2985 | ||
2986 | if (!breakpoint_enabled (bpt)) | |
2987 | continue; | |
2988 | ||
2989 | for (loc = bpt->loc; loc; loc = loc->next) | |
2990 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2991 | { | |
2992 | CORE_ADDR l, h; | |
2993 | ||
2994 | /* Check for intersection. */ | |
2995 | l = max (loc->address, addr); | |
2996 | h = min (loc->address + loc->length, addr + len); | |
2997 | if (l < h) | |
2998 | return 1; | |
2999 | } | |
3000 | } | |
3001 | return 0; | |
3002 | } | |
3003 | ||
075f6582 DJ |
3004 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
3005 | PC is valid for process/thread PTID. */ | |
c906108c SS |
3006 | |
3007 | int | |
6c95b8df PA |
3008 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
3009 | ptid_t ptid) | |
c906108c | 3010 | { |
35df4500 | 3011 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 3012 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 3013 | int thread = -1; |
4a306c9a | 3014 | int task = 0; |
a6f1cd96 | 3015 | |
35df4500 | 3016 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3017 | { |
35df4500 TJB |
3018 | if (bl->loc_type != bp_loc_software_breakpoint |
3019 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
3020 | continue; |
3021 | ||
35df4500 TJB |
3022 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
3023 | if (!breakpoint_enabled (bl->owner) | |
3024 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
3025 | continue; |
3026 | ||
f1310107 | 3027 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
3028 | continue; |
3029 | ||
35df4500 | 3030 | if (bl->owner->thread != -1) |
075f6582 | 3031 | { |
a6f1cd96 JB |
3032 | /* This is a thread-specific breakpoint. Check that ptid |
3033 | matches that thread. If thread hasn't been computed yet, | |
3034 | it is now time to do so. */ | |
3035 | if (thread == -1) | |
3036 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3037 | if (bl->owner->thread != thread) |
a6f1cd96 | 3038 | continue; |
075f6582 | 3039 | } |
a6f1cd96 | 3040 | |
35df4500 | 3041 | if (bl->owner->task != 0) |
4a306c9a JB |
3042 | { |
3043 | /* This is a task-specific breakpoint. Check that ptid | |
3044 | matches that task. If task hasn't been computed yet, | |
3045 | it is now time to do so. */ | |
3046 | if (task == 0) | |
3047 | task = ada_get_task_number (ptid); | |
35df4500 | 3048 | if (bl->owner->task != task) |
4a306c9a JB |
3049 | continue; |
3050 | } | |
3051 | ||
a6f1cd96 | 3052 | if (overlay_debugging |
35df4500 TJB |
3053 | && section_is_overlay (bl->section) |
3054 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3055 | continue; /* unmapped overlay -- can't be a match */ |
3056 | ||
3057 | return 1; | |
c5aa993b | 3058 | } |
c906108c SS |
3059 | |
3060 | return 0; | |
3061 | } | |
c906108c | 3062 | \f |
c5aa993b | 3063 | |
c906108c SS |
3064 | /* bpstat stuff. External routines' interfaces are documented |
3065 | in breakpoint.h. */ | |
3066 | ||
3067 | int | |
fba45db2 | 3068 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3069 | { |
533be4dd | 3070 | return (ep->type == bp_catchpoint); |
c906108c SS |
3071 | } |
3072 | ||
f431efe5 PA |
3073 | /* Frees any storage that is part of a bpstat. Does not walk the |
3074 | 'next' chain. */ | |
3075 | ||
3076 | static void | |
198757a8 VP |
3077 | bpstat_free (bpstat bs) |
3078 | { | |
3079 | if (bs->old_val != NULL) | |
3080 | value_free (bs->old_val); | |
9add0f1b | 3081 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3082 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3083 | xfree (bs); |
3084 | } | |
3085 | ||
c906108c SS |
3086 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3087 | Also free any storage that is part of a bpstat. */ | |
3088 | ||
3089 | void | |
fba45db2 | 3090 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3091 | { |
3092 | bpstat p; | |
3093 | bpstat q; | |
3094 | ||
3095 | if (bsp == 0) | |
3096 | return; | |
3097 | p = *bsp; | |
3098 | while (p != NULL) | |
3099 | { | |
3100 | q = p->next; | |
198757a8 | 3101 | bpstat_free (p); |
c906108c SS |
3102 | p = q; |
3103 | } | |
3104 | *bsp = NULL; | |
3105 | } | |
3106 | ||
3107 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3108 | is part of the bpstat is copied as well. */ | |
3109 | ||
3110 | bpstat | |
fba45db2 | 3111 | bpstat_copy (bpstat bs) |
c906108c SS |
3112 | { |
3113 | bpstat p = NULL; | |
3114 | bpstat tmp; | |
3115 | bpstat retval = NULL; | |
3116 | ||
3117 | if (bs == NULL) | |
3118 | return bs; | |
3119 | ||
3120 | for (; bs != NULL; bs = bs->next) | |
3121 | { | |
3122 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3123 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3124 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3125 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3126 | if (bs->old_val != NULL) |
3c3185ac JK |
3127 | { |
3128 | tmp->old_val = value_copy (bs->old_val); | |
3129 | release_value (tmp->old_val); | |
3130 | } | |
31cc81e9 | 3131 | |
c906108c SS |
3132 | if (p == NULL) |
3133 | /* This is the first thing in the chain. */ | |
3134 | retval = tmp; | |
3135 | else | |
3136 | p->next = tmp; | |
3137 | p = tmp; | |
3138 | } | |
3139 | p->next = NULL; | |
3140 | return retval; | |
3141 | } | |
3142 | ||
4a64f543 | 3143 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3144 | |
3145 | bpstat | |
fba45db2 | 3146 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3147 | { |
c5aa993b JM |
3148 | if (bsp == NULL) |
3149 | return NULL; | |
c906108c | 3150 | |
c5aa993b JM |
3151 | for (; bsp != NULL; bsp = bsp->next) |
3152 | { | |
f431efe5 | 3153 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3154 | return bsp; |
3155 | } | |
c906108c SS |
3156 | return NULL; |
3157 | } | |
3158 | ||
4a64f543 MS |
3159 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3160 | stopped at. *BSP upon return is a bpstat which points to the | |
3161 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3162 | good for anything but further calls to bpstat_num). | |
3163 | ||
8671a17b PA |
3164 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3165 | Return -1 if stopped at a breakpoint that has been deleted since | |
3166 | we set it. | |
3167 | Return 1 otherwise. */ | |
c906108c SS |
3168 | |
3169 | int | |
8671a17b | 3170 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3171 | { |
3172 | struct breakpoint *b; | |
3173 | ||
3174 | if ((*bsp) == NULL) | |
3175 | return 0; /* No more breakpoint values */ | |
8671a17b | 3176 | |
4a64f543 MS |
3177 | /* We assume we'll never have several bpstats that correspond to a |
3178 | single breakpoint -- otherwise, this function might return the | |
3179 | same number more than once and this will look ugly. */ | |
f431efe5 | 3180 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3181 | *bsp = (*bsp)->next; |
3182 | if (b == NULL) | |
3183 | return -1; /* breakpoint that's been deleted since */ | |
3184 | ||
3185 | *num = b->number; /* We have its number */ | |
3186 | return 1; | |
c906108c SS |
3187 | } |
3188 | ||
3189 | /* Modify BS so that the actions will not be performed. */ | |
3190 | ||
3191 | void | |
fba45db2 | 3192 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3193 | { |
3194 | for (; bs != NULL; bs = bs->next) | |
3195 | { | |
9add0f1b | 3196 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3197 | bs->commands_left = NULL; |
c906108c SS |
3198 | if (bs->old_val != NULL) |
3199 | { | |
3200 | value_free (bs->old_val); | |
3201 | bs->old_val = NULL; | |
3202 | } | |
3203 | } | |
3204 | } | |
3205 | ||
f3b1572e PA |
3206 | /* Called when a command is about to proceed the inferior. */ |
3207 | ||
3208 | static void | |
3209 | breakpoint_about_to_proceed (void) | |
3210 | { | |
3211 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3212 | { | |
3213 | struct thread_info *tp = inferior_thread (); | |
3214 | ||
3215 | /* Allow inferior function calls in breakpoint commands to not | |
3216 | interrupt the command list. When the call finishes | |
3217 | successfully, the inferior will be standing at the same | |
3218 | breakpoint as if nothing happened. */ | |
16c381f0 | 3219 | if (tp->control.in_infcall) |
f3b1572e PA |
3220 | return; |
3221 | } | |
3222 | ||
3223 | breakpoint_proceeded = 1; | |
3224 | } | |
3225 | ||
4a64f543 MS |
3226 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3227 | command. */ | |
c906108c | 3228 | static void |
4efb68b1 | 3229 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3230 | { |
3231 | executing_breakpoint_commands = 0; | |
3232 | } | |
3233 | ||
4a64f543 MS |
3234 | /* Execute all the commands associated with all the breakpoints at |
3235 | this location. Any of these commands could cause the process to | |
3236 | proceed beyond this point, etc. We look out for such changes by | |
3237 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3238 | |
347bddb7 PA |
3239 | Returns true if a breakpoint command resumed the inferior. In that |
3240 | case, it is the caller's responsibility to recall it again with the | |
3241 | bpstat of the current thread. */ | |
3242 | ||
3243 | static int | |
3244 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3245 | { |
3246 | bpstat bs; | |
3247 | struct cleanup *old_chain; | |
347bddb7 | 3248 | int again = 0; |
c906108c SS |
3249 | |
3250 | /* Avoid endless recursion if a `source' command is contained | |
3251 | in bs->commands. */ | |
3252 | if (executing_breakpoint_commands) | |
347bddb7 | 3253 | return 0; |
c906108c SS |
3254 | |
3255 | executing_breakpoint_commands = 1; | |
3256 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3257 | ||
cf6c5ffb TT |
3258 | prevent_dont_repeat (); |
3259 | ||
4a64f543 | 3260 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3261 | bs = *bsp; |
3262 | ||
3263 | breakpoint_proceeded = 0; | |
3264 | for (; bs != NULL; bs = bs->next) | |
3265 | { | |
9add0f1b | 3266 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3267 | struct command_line *cmd; |
3268 | struct cleanup *this_cmd_tree_chain; | |
3269 | ||
3270 | /* Take ownership of the BSP's command tree, if it has one. | |
3271 | ||
3272 | The command tree could legitimately contain commands like | |
3273 | 'step' and 'next', which call clear_proceed_status, which | |
3274 | frees stop_bpstat's command tree. To make sure this doesn't | |
3275 | free the tree we're executing out from under us, we need to | |
3276 | take ownership of the tree ourselves. Since a given bpstat's | |
3277 | commands are only executed once, we don't need to copy it; we | |
3278 | can clear the pointer in the bpstat, and make sure we free | |
3279 | the tree when we're done. */ | |
9add0f1b TT |
3280 | ccmd = bs->commands; |
3281 | bs->commands = NULL; | |
3282 | this_cmd_tree_chain | |
3283 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3284 | cmd = bs->commands_left; | |
3285 | bs->commands_left = NULL; | |
6c50ab1c | 3286 | |
c906108c SS |
3287 | while (cmd != NULL) |
3288 | { | |
3289 | execute_control_command (cmd); | |
3290 | ||
3291 | if (breakpoint_proceeded) | |
3292 | break; | |
3293 | else | |
3294 | cmd = cmd->next; | |
3295 | } | |
6c50ab1c JB |
3296 | |
3297 | /* We can free this command tree now. */ | |
3298 | do_cleanups (this_cmd_tree_chain); | |
3299 | ||
c906108c | 3300 | if (breakpoint_proceeded) |
32c1e744 VP |
3301 | { |
3302 | if (target_can_async_p ()) | |
347bddb7 PA |
3303 | /* If we are in async mode, then the target might be still |
3304 | running, not stopped at any breakpoint, so nothing for | |
3305 | us to do here -- just return to the event loop. */ | |
3306 | ; | |
32c1e744 VP |
3307 | else |
3308 | /* In sync mode, when execute_control_command returns | |
3309 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3310 | Breakpoint commands for that stop were not run, since |
3311 | execute_command does not run breakpoint commands -- | |
3312 | only command_line_handler does, but that one is not | |
3313 | involved in execution of breakpoint commands. So, we | |
3314 | can now execute breakpoint commands. It should be | |
3315 | noted that making execute_command do bpstat actions is | |
3316 | not an option -- in this case we'll have recursive | |
3317 | invocation of bpstat for each breakpoint with a | |
3318 | command, and can easily blow up GDB stack. Instead, we | |
3319 | return true, which will trigger the caller to recall us | |
3320 | with the new stop_bpstat. */ | |
3321 | again = 1; | |
3322 | break; | |
32c1e744 | 3323 | } |
c906108c | 3324 | } |
c2b8ed2c | 3325 | do_cleanups (old_chain); |
347bddb7 PA |
3326 | return again; |
3327 | } | |
3328 | ||
3329 | void | |
3330 | bpstat_do_actions (void) | |
3331 | { | |
3332 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3333 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3334 | && target_has_execution | |
3335 | && !is_exited (inferior_ptid) | |
3336 | && !is_executing (inferior_ptid)) | |
3337 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3338 | and only return when it is stopped at the next breakpoint, we | |
3339 | keep doing breakpoint actions until it returns false to | |
3340 | indicate the inferior was not resumed. */ | |
16c381f0 | 3341 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3342 | break; |
c906108c SS |
3343 | } |
3344 | ||
fa4727a6 DJ |
3345 | /* Print out the (old or new) value associated with a watchpoint. */ |
3346 | ||
3347 | static void | |
3348 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3349 | { | |
3350 | if (val == NULL) | |
3351 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3352 | else | |
79a45b7d TT |
3353 | { |
3354 | struct value_print_options opts; | |
3355 | get_user_print_options (&opts); | |
3356 | value_print (val, stream, &opts); | |
3357 | } | |
fa4727a6 DJ |
3358 | } |
3359 | ||
e514a9d6 | 3360 | /* Generic routine for printing messages indicating why we |
4a64f543 | 3361 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3362 | 'print_it' in the bpstat structure. Under some circumstances we |
3363 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3364 | normal_stop(). */ |
e514a9d6 JM |
3365 | |
3366 | static enum print_stop_action | |
3367 | print_bp_stop_message (bpstat bs) | |
3368 | { | |
3369 | switch (bs->print_it) | |
3370 | { | |
3371 | case print_it_noop: | |
4a64f543 | 3372 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3373 | return PRINT_UNKNOWN; |
3374 | break; | |
3375 | ||
3376 | case print_it_done: | |
3377 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3378 | relevant messages. */ |
e514a9d6 JM |
3379 | return PRINT_SRC_AND_LOC; |
3380 | break; | |
3381 | ||
3382 | case print_it_normal: | |
4f8d1dc6 | 3383 | { |
f431efe5 PA |
3384 | struct breakpoint *b = bs->breakpoint_at; |
3385 | ||
1a6a67de TJB |
3386 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3387 | which has since been deleted. */ | |
3388 | if (b == NULL) | |
3389 | return PRINT_UNKNOWN; | |
3390 | ||
348d480f PA |
3391 | /* Normal case. Call the breakpoint's print_it method. */ |
3392 | return b->ops->print_it (bs); | |
4f8d1dc6 | 3393 | } |
348d480f | 3394 | break; |
3086aeae | 3395 | |
e514a9d6 | 3396 | default: |
8e65ff28 | 3397 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3398 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3399 | break; |
c906108c | 3400 | } |
c906108c SS |
3401 | } |
3402 | ||
e514a9d6 JM |
3403 | /* Print a message indicating what happened. This is called from |
3404 | normal_stop(). The input to this routine is the head of the bpstat | |
3405 | list - a list of the eventpoints that caused this stop. This | |
3406 | routine calls the generic print routine for printing a message | |
3407 | about reasons for stopping. This will print (for example) the | |
3408 | "Breakpoint n," part of the output. The return value of this | |
3409 | routine is one of: | |
c906108c | 3410 | |
4a64f543 | 3411 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3412 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3413 | code to print the location. An example is |
c5aa993b JM |
3414 | "Breakpoint 1, " which should be followed by |
3415 | the location. | |
917317f4 | 3416 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3417 | to also print the location part of the message. |
3418 | An example is the catch/throw messages, which | |
4a64f543 | 3419 | don't require a location appended to the end. |
917317f4 | 3420 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3421 | further info to be printed. */ |
c906108c | 3422 | |
917317f4 | 3423 | enum print_stop_action |
fba45db2 | 3424 | bpstat_print (bpstat bs) |
c906108c SS |
3425 | { |
3426 | int val; | |
c5aa993b | 3427 | |
c906108c | 3428 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3429 | (Currently all watchpoints go on the bpstat whether hit or not. |
3430 | That probably could (should) be changed, provided care is taken | |
c906108c | 3431 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3432 | for (; bs; bs = bs->next) |
3433 | { | |
3434 | val = print_bp_stop_message (bs); | |
3435 | if (val == PRINT_SRC_ONLY | |
3436 | || val == PRINT_SRC_AND_LOC | |
3437 | || val == PRINT_NOTHING) | |
3438 | return val; | |
3439 | } | |
c906108c | 3440 | |
e514a9d6 | 3441 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3442 | with and nothing was printed. */ |
917317f4 | 3443 | return PRINT_UNKNOWN; |
c906108c SS |
3444 | } |
3445 | ||
4a64f543 MS |
3446 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3447 | used inside a catch_errors to evaluate the breakpoint condition. | |
3448 | The argument is a "struct expression *" that has been cast to a | |
3449 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3450 | |
3451 | static int | |
4efb68b1 | 3452 | breakpoint_cond_eval (void *exp) |
c906108c | 3453 | { |
278cd55f | 3454 | struct value *mark = value_mark (); |
c5aa993b | 3455 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3456 | |
c906108c SS |
3457 | value_free_to_mark (mark); |
3458 | return i; | |
3459 | } | |
3460 | ||
5760d0ab | 3461 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3462 | |
3463 | static bpstat | |
5760d0ab | 3464 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3465 | { |
3466 | bpstat bs; | |
3467 | ||
3468 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3469 | bs->next = NULL; |
3470 | **bs_link_pointer = bs; | |
3471 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3472 | bs->breakpoint_at = bl->owner; |
3473 | bs->bp_location_at = bl; | |
3474 | incref_bp_location (bl); | |
c906108c SS |
3475 | /* If the condition is false, etc., don't do the commands. */ |
3476 | bs->commands = NULL; | |
9add0f1b | 3477 | bs->commands_left = NULL; |
c906108c SS |
3478 | bs->old_val = NULL; |
3479 | bs->print_it = print_it_normal; | |
3480 | return bs; | |
3481 | } | |
3482 | \f | |
d983da9c DJ |
3483 | /* The target has stopped with waitstatus WS. Check if any hardware |
3484 | watchpoints have triggered, according to the target. */ | |
3485 | ||
3486 | int | |
3487 | watchpoints_triggered (struct target_waitstatus *ws) | |
3488 | { | |
d92524f1 | 3489 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3490 | CORE_ADDR addr; |
3491 | struct breakpoint *b; | |
3492 | ||
3493 | if (!stopped_by_watchpoint) | |
3494 | { | |
3495 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3496 | as not triggered. */ | |
3497 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3498 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3499 | { |
3500 | struct watchpoint *w = (struct watchpoint *) b; | |
3501 | ||
3502 | w->watchpoint_triggered = watch_triggered_no; | |
3503 | } | |
d983da9c DJ |
3504 | |
3505 | return 0; | |
3506 | } | |
3507 | ||
3508 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3509 | { | |
3510 | /* We were stopped by a watchpoint, but we don't know where. | |
3511 | Mark all watchpoints as unknown. */ | |
3512 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3513 | if (is_hardware_watchpoint (b)) |
3a5c3e22 PA |
3514 | { |
3515 | struct watchpoint *w = (struct watchpoint *) b; | |
3516 | ||
3517 | w->watchpoint_triggered = watch_triggered_unknown; | |
3518 | } | |
d983da9c DJ |
3519 | |
3520 | return stopped_by_watchpoint; | |
3521 | } | |
3522 | ||
3523 | /* The target could report the data address. Mark watchpoints | |
3524 | affected by this data address as triggered, and all others as not | |
3525 | triggered. */ | |
3526 | ||
3527 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3528 | if (is_hardware_watchpoint (b)) |
d983da9c | 3529 | { |
3a5c3e22 | 3530 | struct watchpoint *w = (struct watchpoint *) b; |
a5606eee | 3531 | struct bp_location *loc; |
d983da9c | 3532 | |
3a5c3e22 | 3533 | w->watchpoint_triggered = watch_triggered_no; |
a5606eee | 3534 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 | 3535 | { |
3a5c3e22 | 3536 | if (is_masked_watchpoint (b)) |
9c06b0b4 | 3537 | { |
3a5c3e22 PA |
3538 | CORE_ADDR newaddr = addr & w->hw_wp_mask; |
3539 | CORE_ADDR start = loc->address & w->hw_wp_mask; | |
9c06b0b4 TJB |
3540 | |
3541 | if (newaddr == start) | |
3542 | { | |
3a5c3e22 | 3543 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3544 | break; |
3545 | } | |
3546 | } | |
3547 | /* Exact match not required. Within range is sufficient. */ | |
3548 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3549 | addr, loc->address, | |
3550 | loc->length)) | |
3551 | { | |
3a5c3e22 | 3552 | w->watchpoint_triggered = watch_triggered_yes; |
9c06b0b4 TJB |
3553 | break; |
3554 | } | |
3555 | } | |
d983da9c DJ |
3556 | } |
3557 | ||
3558 | return 1; | |
3559 | } | |
3560 | ||
c906108c SS |
3561 | /* Possible return values for watchpoint_check (this can't be an enum |
3562 | because of check_errors). */ | |
3563 | /* The watchpoint has been deleted. */ | |
3564 | #define WP_DELETED 1 | |
3565 | /* The value has changed. */ | |
3566 | #define WP_VALUE_CHANGED 2 | |
3567 | /* The value has not changed. */ | |
3568 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3569 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3570 | #define WP_IGNORE 4 | |
c906108c SS |
3571 | |
3572 | #define BP_TEMPFLAG 1 | |
3573 | #define BP_HARDWAREFLAG 2 | |
3574 | ||
4a64f543 MS |
3575 | /* Evaluate watchpoint condition expression and check if its value |
3576 | changed. | |
553e4c11 JB |
3577 | |
3578 | P should be a pointer to struct bpstat, but is defined as a void * | |
3579 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3580 | |
3581 | static int | |
4efb68b1 | 3582 | watchpoint_check (void *p) |
c906108c SS |
3583 | { |
3584 | bpstat bs = (bpstat) p; | |
3a5c3e22 | 3585 | struct watchpoint *b; |
c906108c SS |
3586 | struct frame_info *fr; |
3587 | int within_current_scope; | |
3588 | ||
f431efe5 | 3589 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3590 | gdb_assert (bs->breakpoint_at != NULL); |
3a5c3e22 | 3591 | b = (struct watchpoint *) bs->breakpoint_at; |
d0fb5eae | 3592 | |
f6bc2008 PA |
3593 | /* If this is a local watchpoint, we only want to check if the |
3594 | watchpoint frame is in scope if the current thread is the thread | |
3595 | that was used to create the watchpoint. */ | |
3596 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3597 | return WP_IGNORE; |
f6bc2008 | 3598 | |
c906108c SS |
3599 | if (b->exp_valid_block == NULL) |
3600 | within_current_scope = 1; | |
3601 | else | |
3602 | { | |
edb3359d DJ |
3603 | struct frame_info *frame = get_current_frame (); |
3604 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3605 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3606 | ||
4a64f543 MS |
3607 | /* in_function_epilogue_p() returns a non-zero value if we're |
3608 | still in the function but the stack frame has already been | |
3609 | invalidated. Since we can't rely on the values of local | |
3610 | variables after the stack has been destroyed, we are treating | |
3611 | the watchpoint in that state as `not changed' without further | |
3612 | checking. Don't mark watchpoints as changed if the current | |
3613 | frame is in an epilogue - even if they are in some other | |
3614 | frame, our view of the stack is likely to be wrong and | |
3615 | frame_find_by_id could error out. */ | |
a0f49112 | 3616 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3617 | return WP_IGNORE; |
a0f49112 | 3618 | |
101dcfbe | 3619 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3620 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3621 | |
3622 | /* If we've gotten confused in the unwinder, we might have | |
3623 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3624 | if (within_current_scope) |
3625 | { | |
3626 | struct symbol *function; | |
3627 | ||
3628 | function = get_frame_function (fr); | |
3629 | if (function == NULL | |
3630 | || !contained_in (b->exp_valid_block, | |
3631 | SYMBOL_BLOCK_VALUE (function))) | |
3632 | within_current_scope = 0; | |
3633 | } | |
69fbadd5 | 3634 | |
edb3359d | 3635 | if (within_current_scope) |
c906108c SS |
3636 | /* If we end up stopping, the current frame will get selected |
3637 | in normal_stop. So this call to select_frame won't affect | |
3638 | the user. */ | |
0f7d239c | 3639 | select_frame (fr); |
c906108c | 3640 | } |
c5aa993b | 3641 | |
c906108c SS |
3642 | if (within_current_scope) |
3643 | { | |
4a64f543 MS |
3644 | /* We use value_{,free_to_}mark because it could be a *long* |
3645 | time before we return to the command level and call | |
3646 | free_all_values. We can't call free_all_values because we | |
3647 | might be in the middle of evaluating a function call. */ | |
c906108c | 3648 | |
0cf6dd15 | 3649 | int pc = 0; |
9c06b0b4 | 3650 | struct value *mark; |
fa4727a6 DJ |
3651 | struct value *new_val; |
3652 | ||
3a5c3e22 | 3653 | if (is_masked_watchpoint (&b->base)) |
9c06b0b4 TJB |
3654 | /* Since we don't know the exact trigger address (from |
3655 | stopped_data_address), just tell the user we've triggered | |
3656 | a mask watchpoint. */ | |
3657 | return WP_VALUE_CHANGED; | |
3658 | ||
3659 | mark = value_mark (); | |
0cf6dd15 | 3660 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3661 | |
4a64f543 MS |
3662 | /* We use value_equal_contents instead of value_equal because |
3663 | the latter coerces an array to a pointer, thus comparing just | |
3664 | the address of the array instead of its contents. This is | |
3665 | not what we want. */ | |
fa4727a6 | 3666 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3667 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3668 | { |
fa4727a6 DJ |
3669 | if (new_val != NULL) |
3670 | { | |
3671 | release_value (new_val); | |
3672 | value_free_to_mark (mark); | |
3673 | } | |
c906108c SS |
3674 | bs->old_val = b->val; |
3675 | b->val = new_val; | |
fa4727a6 | 3676 | b->val_valid = 1; |
c906108c SS |
3677 | return WP_VALUE_CHANGED; |
3678 | } | |
3679 | else | |
3680 | { | |
60e1c644 | 3681 | /* Nothing changed. */ |
c906108c | 3682 | value_free_to_mark (mark); |
c906108c SS |
3683 | return WP_VALUE_NOT_CHANGED; |
3684 | } | |
3685 | } | |
3686 | else | |
3687 | { | |
3688 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3689 | if we temporarily ignored the watchpoint, then when |
3690 | we reenter the block in which it is valid it contains | |
3691 | garbage (in the case of a function, it may have two | |
3692 | garbage values, one before and one after the prologue). | |
3693 | So we can't even detect the first assignment to it and | |
3694 | watch after that (since the garbage may or may not equal | |
3695 | the first value assigned). */ | |
348d480f PA |
3696 | /* We print all the stop information in |
3697 | breakpoint_ops->print_it, but in this case, by the time we | |
3698 | call breakpoint_ops->print_it this bp will be deleted | |
3699 | already. So we have no choice but print the information | |
3700 | here. */ | |
9dc5e2a9 | 3701 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3702 | ui_out_field_string |
3703 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3704 | ui_out_text (uiout, "\nWatchpoint "); |
3a5c3e22 | 3705 | ui_out_field_int (uiout, "wpnum", b->base.number); |
3e43a32a MS |
3706 | ui_out_text (uiout, |
3707 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3708 | which its expression is valid.\n"); |
4ce44c66 | 3709 | |
cdac0397 | 3710 | /* Make sure the watchpoint's commands aren't executed. */ |
3a5c3e22 | 3711 | decref_counted_command_line (&b->base.commands); |
d0fb5eae | 3712 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3713 | |
3714 | return WP_DELETED; | |
3715 | } | |
3716 | } | |
3717 | ||
18a18393 | 3718 | /* Return true if it looks like target has stopped due to hitting |
348d480f PA |
3719 | breakpoint location BL. This function does not check if we should |
3720 | stop, only if BL explains the stop. */ | |
3721 | ||
18a18393 | 3722 | static int |
6c95b8df PA |
3723 | bpstat_check_location (const struct bp_location *bl, |
3724 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3725 | { |
3726 | struct breakpoint *b = bl->owner; | |
3727 | ||
348d480f | 3728 | /* BL is from an existing breakpoint. */ |
2bdf28a0 JK |
3729 | gdb_assert (b != NULL); |
3730 | ||
348d480f | 3731 | return b->ops->breakpoint_hit (bl, aspace, bp_addr); |
18a18393 VP |
3732 | } |
3733 | ||
3a5c3e22 PA |
3734 | /* Determine if the watched values have actually changed, and we |
3735 | should stop. If not, set BS->stop to 0. */ | |
3736 | ||
18a18393 VP |
3737 | static void |
3738 | bpstat_check_watchpoint (bpstat bs) | |
3739 | { | |
2bdf28a0 | 3740 | const struct bp_location *bl; |
3a5c3e22 | 3741 | struct watchpoint *b; |
2bdf28a0 JK |
3742 | |
3743 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3744 | bl = bs->bp_location_at; |
2bdf28a0 | 3745 | gdb_assert (bl != NULL); |
3a5c3e22 | 3746 | b = (struct watchpoint *) bs->breakpoint_at; |
2bdf28a0 | 3747 | gdb_assert (b != NULL); |
18a18393 | 3748 | |
18a18393 | 3749 | { |
18a18393 VP |
3750 | int must_check_value = 0; |
3751 | ||
3a5c3e22 | 3752 | if (b->base.type == bp_watchpoint) |
18a18393 VP |
3753 | /* For a software watchpoint, we must always check the |
3754 | watched value. */ | |
3755 | must_check_value = 1; | |
3756 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3757 | /* We have a hardware watchpoint (read, write, or access) | |
3758 | and the target earlier reported an address watched by | |
3759 | this watchpoint. */ | |
3760 | must_check_value = 1; | |
3761 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3a5c3e22 | 3762 | && b->base.type == bp_hardware_watchpoint) |
18a18393 VP |
3763 | /* We were stopped by a hardware watchpoint, but the target could |
3764 | not report the data address. We must check the watchpoint's | |
3765 | value. Access and read watchpoints are out of luck; without | |
3766 | a data address, we can't figure it out. */ | |
3767 | must_check_value = 1; | |
3a5c3e22 | 3768 | |
18a18393 VP |
3769 | if (must_check_value) |
3770 | { | |
3e43a32a MS |
3771 | char *message |
3772 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3a5c3e22 | 3773 | b->base.number); |
18a18393 VP |
3774 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3775 | int e = catch_errors (watchpoint_check, bs, message, | |
3776 | RETURN_MASK_ALL); | |
3777 | do_cleanups (cleanups); | |
3778 | switch (e) | |
3779 | { | |
3780 | case WP_DELETED: | |
3781 | /* We've already printed what needs to be printed. */ | |
3782 | bs->print_it = print_it_done; | |
3783 | /* Stop. */ | |
3784 | break; | |
60e1c644 PA |
3785 | case WP_IGNORE: |
3786 | bs->print_it = print_it_noop; | |
3787 | bs->stop = 0; | |
3788 | break; | |
18a18393 | 3789 | case WP_VALUE_CHANGED: |
3a5c3e22 | 3790 | if (b->base.type == bp_read_watchpoint) |
18a18393 | 3791 | { |
85d721b8 PA |
3792 | /* There are two cases to consider here: |
3793 | ||
4a64f543 | 3794 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3795 | In that case, trust the target, and always report |
3796 | the watchpoint hit to the user. Even though | |
3797 | reads don't cause value changes, the value may | |
3798 | have changed since the last time it was read, and | |
3799 | since we're not trapping writes, we will not see | |
3800 | those, and as such we should ignore our notion of | |
3801 | old value. | |
3802 | ||
4a64f543 | 3803 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3804 | reads and writes. There are two ways this may |
3805 | happen: | |
3806 | ||
4a64f543 | 3807 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3808 | reads only, but can break on accesses (reads or |
3809 | writes), such as e.g., x86. We detect this case | |
3810 | at the time we try to insert read watchpoints. | |
3811 | ||
4a64f543 | 3812 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3813 | watchpoints, but, the user set an access or write |
3814 | watchpoint watching the same memory as this read | |
3815 | watchpoint. | |
3816 | ||
3817 | If we're watching memory writes as well as reads, | |
3818 | ignore watchpoint hits when we find that the | |
3819 | value hasn't changed, as reads don't cause | |
3820 | changes. This still gives false positives when | |
3821 | the program writes the same value to memory as | |
3822 | what there was already in memory (we will confuse | |
3823 | it for a read), but it's much better than | |
3824 | nothing. */ | |
3825 | ||
3826 | int other_write_watchpoint = 0; | |
3827 | ||
3828 | if (bl->watchpoint_type == hw_read) | |
3829 | { | |
3830 | struct breakpoint *other_b; | |
3831 | ||
3832 | ALL_BREAKPOINTS (other_b) | |
3a5c3e22 PA |
3833 | if (other_b->type == bp_hardware_watchpoint |
3834 | || other_b->type == bp_access_watchpoint) | |
85d721b8 | 3835 | { |
3a5c3e22 PA |
3836 | struct watchpoint *other_w = |
3837 | (struct watchpoint *) other_b; | |
3838 | ||
3839 | if (other_w->watchpoint_triggered | |
3840 | == watch_triggered_yes) | |
3841 | { | |
3842 | other_write_watchpoint = 1; | |
3843 | break; | |
3844 | } | |
85d721b8 PA |
3845 | } |
3846 | } | |
3847 | ||
3848 | if (other_write_watchpoint | |
3849 | || bl->watchpoint_type == hw_access) | |
3850 | { | |
3851 | /* We're watching the same memory for writes, | |
3852 | and the value changed since the last time we | |
3853 | updated it, so this trap must be for a write. | |
3854 | Ignore it. */ | |
3855 | bs->print_it = print_it_noop; | |
3856 | bs->stop = 0; | |
3857 | } | |
18a18393 VP |
3858 | } |
3859 | break; | |
3860 | case WP_VALUE_NOT_CHANGED: | |
3a5c3e22 PA |
3861 | if (b->base.type == bp_hardware_watchpoint |
3862 | || b->base.type == bp_watchpoint) | |
18a18393 VP |
3863 | { |
3864 | /* Don't stop: write watchpoints shouldn't fire if | |
3865 | the value hasn't changed. */ | |
3866 | bs->print_it = print_it_noop; | |
3867 | bs->stop = 0; | |
3868 | } | |
3869 | /* Stop. */ | |
3870 | break; | |
3871 | default: | |
3872 | /* Can't happen. */ | |
3873 | case 0: | |
3874 | /* Error from catch_errors. */ | |
3a5c3e22 | 3875 | printf_filtered (_("Watchpoint %d deleted.\n"), b->base.number); |
d0fb5eae | 3876 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
3877 | /* We've already printed what needs to be printed. */ |
3878 | bs->print_it = print_it_done; | |
3879 | break; | |
3880 | } | |
3881 | } | |
3882 | else /* must_check_value == 0 */ | |
3883 | { | |
3884 | /* This is a case where some watchpoint(s) triggered, but | |
3885 | not at the address of this watchpoint, or else no | |
3886 | watchpoint triggered after all. So don't print | |
3887 | anything for this watchpoint. */ | |
3888 | bs->print_it = print_it_noop; | |
3889 | bs->stop = 0; | |
3890 | } | |
3891 | } | |
3892 | } | |
3893 | ||
3894 | ||
3895 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3896 | of breakpoint referred to by BS. If we should not stop for this | |
3897 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 3898 | |
18a18393 VP |
3899 | static void |
3900 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3901 | { | |
3902 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
3903 | const struct bp_location *bl; |
3904 | struct breakpoint *b; | |
3905 | ||
3906 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3907 | bl = bs->bp_location_at; |
2bdf28a0 | 3908 | gdb_assert (bl != NULL); |
f431efe5 | 3909 | b = bs->breakpoint_at; |
2bdf28a0 | 3910 | gdb_assert (b != NULL); |
18a18393 VP |
3911 | |
3912 | if (frame_id_p (b->frame_id) | |
edb3359d | 3913 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3914 | bs->stop = 0; |
3915 | else if (bs->stop) | |
3916 | { | |
3917 | int value_is_zero = 0; | |
60e1c644 PA |
3918 | struct expression *cond; |
3919 | ||
7371cf6d PM |
3920 | /* Evaluate Python breakpoints that have a "stop" |
3921 | method implemented. */ | |
3922 | if (b->py_bp_object) | |
3923 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
3924 | ||
60e1c644 | 3925 | if (is_watchpoint (b)) |
3a5c3e22 PA |
3926 | { |
3927 | struct watchpoint *w = (struct watchpoint *) b; | |
3928 | ||
3929 | cond = w->cond_exp; | |
3930 | } | |
60e1c644 PA |
3931 | else |
3932 | cond = bl->cond; | |
3933 | ||
f431efe5 | 3934 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 3935 | { |
60e1c644 | 3936 | int within_current_scope = 1; |
3a5c3e22 | 3937 | struct watchpoint * w; |
60e1c644 | 3938 | |
c5bc3a77 DJ |
3939 | /* We use value_mark and value_free_to_mark because it could |
3940 | be a long time before we return to the command level and | |
3941 | call free_all_values. We can't call free_all_values | |
3942 | because we might be in the middle of evaluating a | |
3943 | function call. */ | |
3944 | struct value *mark = value_mark (); | |
3945 | ||
3a5c3e22 PA |
3946 | if (is_watchpoint (b)) |
3947 | w = (struct watchpoint *) b; | |
3948 | else | |
3949 | w = NULL; | |
3950 | ||
edb3359d DJ |
3951 | /* Need to select the frame, with all that implies so that |
3952 | the conditions will have the right context. Because we | |
3953 | use the frame, we will not see an inlined function's | |
3954 | variables when we arrive at a breakpoint at the start | |
3955 | of the inlined function; the current frame will be the | |
3956 | call site. */ | |
3a5c3e22 | 3957 | if (w == NULL || w->cond_exp_valid_block == NULL) |
60e1c644 PA |
3958 | select_frame (get_current_frame ()); |
3959 | else | |
3960 | { | |
3961 | struct frame_info *frame; | |
3962 | ||
3963 | /* For local watchpoint expressions, which particular | |
3964 | instance of a local is being watched matters, so we | |
3965 | keep track of the frame to evaluate the expression | |
3966 | in. To evaluate the condition however, it doesn't | |
3967 | really matter which instantiation of the function | |
3968 | where the condition makes sense triggers the | |
3969 | watchpoint. This allows an expression like "watch | |
3970 | global if q > 10" set in `func', catch writes to | |
3971 | global on all threads that call `func', or catch | |
3972 | writes on all recursive calls of `func' by a single | |
3973 | thread. We simply always evaluate the condition in | |
3974 | the innermost frame that's executing where it makes | |
3975 | sense to evaluate the condition. It seems | |
3976 | intuitive. */ | |
3a5c3e22 | 3977 | frame = block_innermost_frame (w->cond_exp_valid_block); |
60e1c644 PA |
3978 | if (frame != NULL) |
3979 | select_frame (frame); | |
3980 | else | |
3981 | within_current_scope = 0; | |
3982 | } | |
3983 | if (within_current_scope) | |
3984 | value_is_zero | |
3985 | = catch_errors (breakpoint_cond_eval, cond, | |
3986 | "Error in testing breakpoint condition:\n", | |
3987 | RETURN_MASK_ALL); | |
3988 | else | |
3989 | { | |
3990 | warning (_("Watchpoint condition cannot be tested " | |
3991 | "in the current scope")); | |
3992 | /* If we failed to set the right context for this | |
3993 | watchpoint, unconditionally report it. */ | |
3994 | value_is_zero = 0; | |
3995 | } | |
4a64f543 | 3996 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 3997 | value_free_to_mark (mark); |
18a18393 | 3998 | } |
60e1c644 PA |
3999 | |
4000 | if (cond && value_is_zero) | |
18a18393 VP |
4001 | { |
4002 | bs->stop = 0; | |
4003 | } | |
4004 | else if (b->thread != -1 && b->thread != thread_id) | |
4005 | { | |
4006 | bs->stop = 0; | |
4007 | } | |
4008 | else if (b->ignore_count > 0) | |
4009 | { | |
4010 | b->ignore_count--; | |
4011 | annotate_ignore_count_change (); | |
4012 | bs->stop = 0; | |
4a64f543 | 4013 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4014 | ++(b->hit_count); |
8d3788bd | 4015 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4016 | } |
4017 | } | |
4018 | } | |
4019 | ||
4020 | ||
9709f61c | 4021 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4022 | BP_ADDR in thread PTID. |
c906108c | 4023 | |
d983da9c | 4024 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4025 | don't understand this stop. Result is a chain of bpstat's such |
4026 | that: | |
c906108c | 4027 | |
c5aa993b | 4028 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4029 | |
c5aa993b | 4030 | if we understand why we stopped, the result is not null. |
c906108c | 4031 | |
c5aa993b JM |
4032 | Each element of the chain refers to a particular breakpoint or |
4033 | watchpoint at which we have stopped. (We may have stopped for | |
4034 | several reasons concurrently.) | |
c906108c | 4035 | |
c5aa993b JM |
4036 | Each element of the chain has valid next, breakpoint_at, |
4037 | commands, FIXME??? fields. */ | |
c906108c SS |
4038 | |
4039 | bpstat | |
6c95b8df PA |
4040 | bpstat_stop_status (struct address_space *aspace, |
4041 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4042 | { |
0d381245 | 4043 | struct breakpoint *b = NULL; |
afe38095 | 4044 | struct bp_location *bl; |
20874c92 | 4045 | struct bp_location *loc; |
5760d0ab JK |
4046 | /* First item of allocated bpstat's. */ |
4047 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4048 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4049 | bpstat bs; |
20874c92 | 4050 | int ix; |
429374b8 | 4051 | int need_remove_insert; |
f431efe5 | 4052 | int removed_any; |
c906108c | 4053 | |
f431efe5 PA |
4054 | /* First, build the bpstat chain with locations that explain a |
4055 | target stop, while being careful to not set the target running, | |
4056 | as that may invalidate locations (in particular watchpoint | |
4057 | locations are recreated). Resuming will happen here with | |
4058 | breakpoint conditions or watchpoint expressions that include | |
4059 | inferior function calls. */ | |
c5aa993b | 4060 | |
429374b8 JK |
4061 | ALL_BREAKPOINTS (b) |
4062 | { | |
4063 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4064 | continue; | |
a5606eee | 4065 | |
429374b8 JK |
4066 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4067 | { | |
4a64f543 MS |
4068 | /* For hardware watchpoints, we look only at the first |
4069 | location. The watchpoint_check function will work on the | |
4070 | entire expression, not the individual locations. For | |
4071 | read watchpoints, the watchpoints_triggered function has | |
4072 | checked all locations already. */ | |
429374b8 JK |
4073 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4074 | break; | |
18a18393 | 4075 | |
429374b8 JK |
4076 | if (bl->shlib_disabled) |
4077 | continue; | |
c5aa993b | 4078 | |
429374b8 JK |
4079 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4080 | continue; | |
c5aa993b | 4081 | |
4a64f543 MS |
4082 | /* Come here if it's a watchpoint, or if the break address |
4083 | matches. */ | |
c5aa993b | 4084 | |
4a64f543 MS |
4085 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4086 | explain stop. */ | |
c5aa993b | 4087 | |
f431efe5 PA |
4088 | /* Assume we stop. Should we find a watchpoint that is not |
4089 | actually triggered, or if the condition of the breakpoint | |
4090 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4091 | bs->stop = 1; |
4092 | bs->print = 1; | |
d983da9c | 4093 | |
f431efe5 PA |
4094 | /* If this is a scope breakpoint, mark the associated |
4095 | watchpoint as triggered so that we will handle the | |
4096 | out-of-scope event. We'll get to the watchpoint next | |
4097 | iteration. */ | |
d0fb5eae | 4098 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
3a5c3e22 PA |
4099 | { |
4100 | struct watchpoint *w = (struct watchpoint *) b->related_breakpoint; | |
4101 | ||
4102 | w->watchpoint_triggered = watch_triggered_yes; | |
4103 | } | |
f431efe5 PA |
4104 | } |
4105 | } | |
4106 | ||
4107 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4108 | { | |
f1310107 | 4109 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4110 | { |
5760d0ab | 4111 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4112 | /* For hits of moribund locations, we should just proceed. */ |
4113 | bs->stop = 0; | |
4114 | bs->print = 0; | |
4115 | bs->print_it = print_it_noop; | |
4116 | } | |
4117 | } | |
4118 | ||
f431efe5 PA |
4119 | /* Now go through the locations that caused the target to stop, and |
4120 | check whether we're interested in reporting this stop to higher | |
4121 | layers, or whether we should resume the target transparently. */ | |
4122 | ||
4123 | removed_any = 0; | |
4124 | ||
5760d0ab | 4125 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4126 | { |
4127 | if (!bs->stop) | |
4128 | continue; | |
4129 | ||
f431efe5 | 4130 | b = bs->breakpoint_at; |
348d480f PA |
4131 | b->ops->check_status (bs); |
4132 | if (bs->stop) | |
28010a5d | 4133 | { |
348d480f | 4134 | bpstat_check_breakpoint_conditions (bs, ptid); |
f431efe5 | 4135 | |
429374b8 JK |
4136 | if (bs->stop) |
4137 | { | |
4138 | ++(b->hit_count); | |
8d3788bd | 4139 | observer_notify_breakpoint_modified (b); |
c906108c | 4140 | |
4a64f543 | 4141 | /* We will stop here. */ |
429374b8 JK |
4142 | if (b->disposition == disp_disable) |
4143 | { | |
4144 | if (b->enable_state != bp_permanent) | |
4145 | b->enable_state = bp_disabled; | |
f431efe5 | 4146 | removed_any = 1; |
429374b8 JK |
4147 | } |
4148 | if (b->silent) | |
4149 | bs->print = 0; | |
4150 | bs->commands = b->commands; | |
9add0f1b TT |
4151 | incref_counted_command_line (bs->commands); |
4152 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4153 | if (bs->commands_left | |
4154 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4155 | || (xdb_commands | |
4156 | && strcmp ("Q", | |
4157 | bs->commands_left->line) == 0))) | |
429374b8 | 4158 | { |
9add0f1b | 4159 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4160 | bs->print = 0; |
4161 | } | |
429374b8 JK |
4162 | } |
4163 | ||
e5dd4106 | 4164 | /* Print nothing for this entry if we don't stop or don't print. */ |
429374b8 JK |
4165 | if (bs->stop == 0 || bs->print == 0) |
4166 | bs->print_it = print_it_noop; | |
348d480f | 4167 | } |
429374b8 | 4168 | } |
876fa593 | 4169 | |
d983da9c DJ |
4170 | /* If we aren't stopping, the value of some hardware watchpoint may |
4171 | not have changed, but the intermediate memory locations we are | |
4172 | watching may have. Don't bother if we're stopping; this will get | |
4173 | done later. */ | |
d832cb68 | 4174 | need_remove_insert = 0; |
5760d0ab JK |
4175 | if (! bpstat_causes_stop (bs_head)) |
4176 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4177 | if (!bs->stop |
f431efe5 PA |
4178 | && bs->breakpoint_at |
4179 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4180 | { |
3a5c3e22 PA |
4181 | struct watchpoint *w = (struct watchpoint *) bs->breakpoint_at; |
4182 | ||
4183 | update_watchpoint (w, 0 /* don't reparse. */); | |
d832cb68 | 4184 | need_remove_insert = 1; |
d983da9c DJ |
4185 | } |
4186 | ||
d832cb68 | 4187 | if (need_remove_insert) |
2d134ed3 | 4188 | update_global_location_list (1); |
f431efe5 PA |
4189 | else if (removed_any) |
4190 | update_global_location_list (0); | |
d832cb68 | 4191 | |
5760d0ab | 4192 | return bs_head; |
c906108c | 4193 | } |
628fe4e4 JK |
4194 | |
4195 | static void | |
4196 | handle_jit_event (void) | |
4197 | { | |
4198 | struct frame_info *frame; | |
4199 | struct gdbarch *gdbarch; | |
4200 | ||
4201 | /* Switch terminal for any messages produced by | |
4202 | breakpoint_re_set. */ | |
4203 | target_terminal_ours_for_output (); | |
4204 | ||
4205 | frame = get_current_frame (); | |
4206 | gdbarch = get_frame_arch (frame); | |
4207 | ||
4208 | jit_event_handler (gdbarch); | |
4209 | ||
4210 | target_terminal_inferior (); | |
4211 | } | |
4212 | ||
4213 | /* Prepare WHAT final decision for infrun. */ | |
4214 | ||
4215 | /* Decide what infrun needs to do with this bpstat. */ | |
4216 | ||
c906108c | 4217 | struct bpstat_what |
0e30163f | 4218 | bpstat_what (bpstat bs_head) |
c906108c | 4219 | { |
c906108c | 4220 | struct bpstat_what retval; |
628fe4e4 JK |
4221 | /* We need to defer calling `solib_add', as adding new symbols |
4222 | resets breakpoints, which in turn deletes breakpoint locations, | |
4223 | and hence may clear unprocessed entries in the BS chain. */ | |
4224 | int shlib_event = 0; | |
4225 | int jit_event = 0; | |
0e30163f | 4226 | bpstat bs; |
c906108c | 4227 | |
628fe4e4 | 4228 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4229 | retval.call_dummy = STOP_NONE; |
186c406b | 4230 | retval.is_longjmp = 0; |
628fe4e4 | 4231 | |
0e30163f | 4232 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4233 | { |
628fe4e4 JK |
4234 | /* Extract this BS's action. After processing each BS, we check |
4235 | if its action overrides all we've seem so far. */ | |
4236 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4237 | enum bptype bptype; | |
4238 | ||
c906108c | 4239 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4240 | { |
4241 | /* I suspect this can happen if it was a momentary | |
4242 | breakpoint which has since been deleted. */ | |
4243 | bptype = bp_none; | |
4244 | } | |
20874c92 | 4245 | else |
f431efe5 | 4246 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4247 | |
4248 | switch (bptype) | |
c906108c SS |
4249 | { |
4250 | case bp_none: | |
628fe4e4 | 4251 | break; |
c906108c SS |
4252 | case bp_breakpoint: |
4253 | case bp_hardware_breakpoint: | |
4254 | case bp_until: | |
4255 | case bp_finish: | |
4256 | if (bs->stop) | |
4257 | { | |
4258 | if (bs->print) | |
628fe4e4 | 4259 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4260 | else |
628fe4e4 | 4261 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4262 | } |
4263 | else | |
628fe4e4 | 4264 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4265 | break; |
4266 | case bp_watchpoint: | |
4267 | case bp_hardware_watchpoint: | |
4268 | case bp_read_watchpoint: | |
4269 | case bp_access_watchpoint: | |
4270 | if (bs->stop) | |
4271 | { | |
4272 | if (bs->print) | |
628fe4e4 | 4273 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4274 | else |
628fe4e4 | 4275 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4276 | } |
4277 | else | |
628fe4e4 JK |
4278 | { |
4279 | /* There was a watchpoint, but we're not stopping. | |
4280 | This requires no further action. */ | |
4281 | } | |
c906108c SS |
4282 | break; |
4283 | case bp_longjmp: | |
186c406b | 4284 | case bp_exception: |
628fe4e4 | 4285 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4286 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4287 | break; |
4288 | case bp_longjmp_resume: | |
186c406b | 4289 | case bp_exception_resume: |
628fe4e4 | 4290 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4291 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4292 | break; |
4293 | case bp_step_resume: | |
4294 | if (bs->stop) | |
628fe4e4 JK |
4295 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4296 | else | |
c906108c | 4297 | { |
628fe4e4 JK |
4298 | /* It is for the wrong frame. */ |
4299 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4300 | } |
c906108c | 4301 | break; |
2c03e5be PA |
4302 | case bp_hp_step_resume: |
4303 | if (bs->stop) | |
4304 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4305 | else | |
4306 | { | |
4307 | /* It is for the wrong frame. */ | |
4308 | this_action = BPSTAT_WHAT_SINGLE; | |
4309 | } | |
4310 | break; | |
c906108c | 4311 | case bp_watchpoint_scope: |
c4093a6a | 4312 | case bp_thread_event: |
1900040c | 4313 | case bp_overlay_event: |
0fd8e87f | 4314 | case bp_longjmp_master: |
aa7d318d | 4315 | case bp_std_terminate_master: |
186c406b | 4316 | case bp_exception_master: |
628fe4e4 | 4317 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4318 | break; |
ce78b96d | 4319 | case bp_catchpoint: |
c5aa993b JM |
4320 | if (bs->stop) |
4321 | { | |
4322 | if (bs->print) | |
628fe4e4 | 4323 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4324 | else |
628fe4e4 | 4325 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4326 | } |
4327 | else | |
628fe4e4 JK |
4328 | { |
4329 | /* There was a catchpoint, but we're not stopping. | |
4330 | This requires no further action. */ | |
4331 | } | |
4332 | break; | |
4333 | case bp_shlib_event: | |
4334 | shlib_event = 1; | |
4335 | ||
4336 | /* If requested, stop when the dynamic linker notifies GDB | |
4337 | of events. This allows the user to get control and place | |
4338 | breakpoints in initializer routines for dynamically | |
4339 | loaded objects (among other things). */ | |
4340 | if (stop_on_solib_events) | |
4341 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4342 | else | |
4343 | this_action = BPSTAT_WHAT_SINGLE; | |
4344 | break; | |
4345 | case bp_jit_event: | |
4346 | jit_event = 1; | |
4347 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4348 | break; |
c906108c | 4349 | case bp_call_dummy: |
53a5351d JM |
4350 | /* Make sure the action is stop (silent or noisy), |
4351 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4352 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4353 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4354 | break; |
4355 | case bp_std_terminate: | |
4356 | /* Make sure the action is stop (silent or noisy), | |
4357 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4358 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4359 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4360 | break; |
1042e4c0 | 4361 | case bp_tracepoint: |
7a697b8d | 4362 | case bp_fast_tracepoint: |
0fb4aa4b | 4363 | case bp_static_tracepoint: |
1042e4c0 SS |
4364 | /* Tracepoint hits should not be reported back to GDB, and |
4365 | if one got through somehow, it should have been filtered | |
4366 | out already. */ | |
4367 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4368 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4369 | break; |
4370 | case bp_gnu_ifunc_resolver: | |
4371 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4372 | this_action = BPSTAT_WHAT_SINGLE; | |
4373 | break; | |
4374 | case bp_gnu_ifunc_resolver_return: | |
4375 | /* The breakpoint will be removed, execution will restart from the | |
4376 | PC of the former breakpoint. */ | |
4377 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4378 | break; | |
628fe4e4 JK |
4379 | default: |
4380 | internal_error (__FILE__, __LINE__, | |
4381 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4382 | } |
628fe4e4 JK |
4383 | |
4384 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4385 | } |
628fe4e4 | 4386 | |
0e30163f JK |
4387 | /* These operations may affect the bs->breakpoint_at state so they are |
4388 | delayed after MAIN_ACTION is decided above. */ | |
4389 | ||
628fe4e4 JK |
4390 | if (shlib_event) |
4391 | { | |
4392 | if (debug_infrun) | |
4393 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4394 | ||
4395 | /* Check for any newly added shared libraries if we're supposed | |
4396 | to be adding them automatically. */ | |
4397 | ||
4398 | /* Switch terminal for any messages produced by | |
4399 | breakpoint_re_set. */ | |
4400 | target_terminal_ours_for_output (); | |
4401 | ||
4402 | #ifdef SOLIB_ADD | |
4403 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4404 | #else | |
4405 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4406 | #endif | |
4407 | ||
4408 | target_terminal_inferior (); | |
4409 | } | |
4410 | ||
4411 | if (jit_event) | |
4412 | { | |
4413 | if (debug_infrun) | |
4414 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4415 | ||
4416 | handle_jit_event (); | |
4417 | } | |
4418 | ||
0e30163f JK |
4419 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4420 | { | |
4421 | struct breakpoint *b = bs->breakpoint_at; | |
4422 | ||
4423 | if (b == NULL) | |
4424 | continue; | |
4425 | switch (b->type) | |
4426 | { | |
4427 | case bp_gnu_ifunc_resolver: | |
4428 | gnu_ifunc_resolver_stop (b); | |
4429 | break; | |
4430 | case bp_gnu_ifunc_resolver_return: | |
4431 | gnu_ifunc_resolver_return_stop (b); | |
4432 | break; | |
4433 | } | |
4434 | } | |
4435 | ||
c906108c SS |
4436 | return retval; |
4437 | } | |
4438 | ||
4439 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4440 | without hardware support). This isn't related to a specific bpstat, | |
4441 | just to things like whether watchpoints are set. */ | |
4442 | ||
c5aa993b | 4443 | int |
fba45db2 | 4444 | bpstat_should_step (void) |
c906108c SS |
4445 | { |
4446 | struct breakpoint *b; | |
cc59ec59 | 4447 | |
c906108c | 4448 | ALL_BREAKPOINTS (b) |
717a8278 | 4449 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4450 | return 1; |
c906108c SS |
4451 | return 0; |
4452 | } | |
4453 | ||
67822962 PA |
4454 | int |
4455 | bpstat_causes_stop (bpstat bs) | |
4456 | { | |
4457 | for (; bs != NULL; bs = bs->next) | |
4458 | if (bs->stop) | |
4459 | return 1; | |
4460 | ||
4461 | return 0; | |
4462 | } | |
4463 | ||
c906108c | 4464 | \f |
c5aa993b | 4465 | |
170b53b2 UW |
4466 | /* Compute a string of spaces suitable to indent the next line |
4467 | so it starts at the position corresponding to the table column | |
4468 | named COL_NAME in the currently active table of UIOUT. */ | |
4469 | ||
4470 | static char * | |
4471 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4472 | { | |
4473 | static char wrap_indent[80]; | |
4474 | int i, total_width, width, align; | |
4475 | char *text; | |
4476 | ||
4477 | total_width = 0; | |
4478 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4479 | { | |
4480 | if (strcmp (text, col_name) == 0) | |
4481 | { | |
4482 | gdb_assert (total_width < sizeof wrap_indent); | |
4483 | memset (wrap_indent, ' ', total_width); | |
4484 | wrap_indent[total_width] = 0; | |
4485 | ||
4486 | return wrap_indent; | |
4487 | } | |
4488 | ||
4489 | total_width += width + 1; | |
4490 | } | |
4491 | ||
4492 | return NULL; | |
4493 | } | |
4494 | ||
859825b8 JK |
4495 | /* Print the LOC location out of the list of B->LOC locations. */ |
4496 | ||
170b53b2 UW |
4497 | static void |
4498 | print_breakpoint_location (struct breakpoint *b, | |
4499 | struct bp_location *loc) | |
0d381245 | 4500 | { |
6c95b8df PA |
4501 | struct cleanup *old_chain = save_current_program_space (); |
4502 | ||
859825b8 JK |
4503 | if (loc != NULL && loc->shlib_disabled) |
4504 | loc = NULL; | |
4505 | ||
6c95b8df PA |
4506 | if (loc != NULL) |
4507 | set_current_program_space (loc->pspace); | |
4508 | ||
56435ebe TT |
4509 | if (b->display_canonical) |
4510 | ui_out_field_string (uiout, "what", b->addr_string); | |
4511 | else if (b->source_file && loc) | |
0d381245 VP |
4512 | { |
4513 | struct symbol *sym | |
4514 | = find_pc_sect_function (loc->address, loc->section); | |
4515 | if (sym) | |
4516 | { | |
4517 | ui_out_text (uiout, "in "); | |
4518 | ui_out_field_string (uiout, "func", | |
4519 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4520 | ui_out_text (uiout, " "); |
4521 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4522 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4523 | } |
4524 | ui_out_field_string (uiout, "file", b->source_file); | |
4525 | ui_out_text (uiout, ":"); | |
4526 | ||
4527 | if (ui_out_is_mi_like_p (uiout)) | |
4528 | { | |
4529 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4530 | char *fullname = symtab_to_fullname (sal.symtab); | |
4531 | ||
4532 | if (fullname) | |
4533 | ui_out_field_string (uiout, "fullname", fullname); | |
4534 | } | |
4535 | ||
4536 | ui_out_field_int (uiout, "line", b->line_number); | |
4537 | } | |
859825b8 | 4538 | else if (loc) |
0d381245 | 4539 | { |
170b53b2 UW |
4540 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4541 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4542 | ||
22e722e1 DJ |
4543 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4544 | demangle, ""); | |
0d381245 | 4545 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4546 | |
4547 | do_cleanups (stb_chain); | |
0d381245 | 4548 | } |
859825b8 JK |
4549 | else |
4550 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4551 | |
4552 | do_cleanups (old_chain); | |
0d381245 VP |
4553 | } |
4554 | ||
269b11a2 PA |
4555 | static const char * |
4556 | bptype_string (enum bptype type) | |
c906108c | 4557 | { |
c4093a6a JM |
4558 | struct ep_type_description |
4559 | { | |
4560 | enum bptype type; | |
4561 | char *description; | |
4562 | }; | |
4563 | static struct ep_type_description bptypes[] = | |
c906108c | 4564 | { |
c5aa993b JM |
4565 | {bp_none, "?deleted?"}, |
4566 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4567 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4568 | {bp_until, "until"}, |
4569 | {bp_finish, "finish"}, | |
4570 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4571 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4572 | {bp_read_watchpoint, "read watchpoint"}, |
4573 | {bp_access_watchpoint, "acc watchpoint"}, | |
4574 | {bp_longjmp, "longjmp"}, | |
4575 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4576 | {bp_exception, "exception"}, |
4577 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4578 | {bp_step_resume, "step resume"}, |
2c03e5be | 4579 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4580 | {bp_watchpoint_scope, "watchpoint scope"}, |
4581 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4582 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4583 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4584 | {bp_thread_event, "thread events"}, |
1900040c | 4585 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4586 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4587 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4588 | {bp_exception_master, "exception master"}, |
ce78b96d | 4589 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4590 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4591 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4592 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4593 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4594 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4595 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4596 | }; |
269b11a2 PA |
4597 | |
4598 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4599 | || ((int) type != bptypes[(int) type].type)) | |
4600 | internal_error (__FILE__, __LINE__, | |
4601 | _("bptypes table does not describe type #%d."), | |
4602 | (int) type); | |
4603 | ||
4604 | return bptypes[(int) type].description; | |
4605 | } | |
4606 | ||
4607 | /* Print B to gdb_stdout. */ | |
4608 | ||
4609 | static void | |
4610 | print_one_breakpoint_location (struct breakpoint *b, | |
4611 | struct bp_location *loc, | |
4612 | int loc_number, | |
4613 | struct bp_location **last_loc, | |
269b11a2 PA |
4614 | int allflag) |
4615 | { | |
4616 | struct command_line *l; | |
c2c6d25f | 4617 | static char bpenables[] = "nynny"; |
c906108c | 4618 | |
0d381245 VP |
4619 | int header_of_multiple = 0; |
4620 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4621 | struct value_print_options opts; |
4622 | ||
4623 | get_user_print_options (&opts); | |
0d381245 VP |
4624 | |
4625 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4626 | /* See comment in print_one_breakpoint concerning treatment of |
4627 | breakpoints with single disabled location. */ | |
0d381245 VP |
4628 | if (loc == NULL |
4629 | && (b->loc != NULL | |
4630 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4631 | header_of_multiple = 1; | |
4632 | if (loc == NULL) | |
4633 | loc = b->loc; | |
4634 | ||
c4093a6a JM |
4635 | annotate_record (); |
4636 | ||
4637 | /* 1 */ | |
4638 | annotate_field (0); | |
0d381245 VP |
4639 | if (part_of_multiple) |
4640 | { | |
4641 | char *formatted; | |
0c6773c1 | 4642 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4643 | ui_out_field_string (uiout, "number", formatted); |
4644 | xfree (formatted); | |
4645 | } | |
4646 | else | |
4647 | { | |
4648 | ui_out_field_int (uiout, "number", b->number); | |
4649 | } | |
c4093a6a JM |
4650 | |
4651 | /* 2 */ | |
4652 | annotate_field (1); | |
0d381245 VP |
4653 | if (part_of_multiple) |
4654 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4655 | else |
4656 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4657 | |
4658 | /* 3 */ | |
4659 | annotate_field (2); | |
0d381245 VP |
4660 | if (part_of_multiple) |
4661 | ui_out_field_skip (uiout, "disp"); | |
4662 | else | |
2cec12e5 | 4663 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4664 | |
c4093a6a JM |
4665 | |
4666 | /* 4 */ | |
4667 | annotate_field (3); | |
0d381245 | 4668 | if (part_of_multiple) |
54e52265 | 4669 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4670 | else |
4a64f543 MS |
4671 | ui_out_field_fmt (uiout, "enabled", "%c", |
4672 | bpenables[(int) b->enable_state]); | |
54e52265 | 4673 | ui_out_spaces (uiout, 2); |
0d381245 | 4674 | |
c4093a6a JM |
4675 | |
4676 | /* 5 and 6 */ | |
3086aeae | 4677 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4678 | { |
4a64f543 MS |
4679 | /* Although the print_one can possibly print all locations, |
4680 | calling it here is not likely to get any nice result. So, | |
4681 | make sure there's just one location. */ | |
0d381245 | 4682 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4683 | b->ops->print_one (b, last_loc); |
0d381245 | 4684 | } |
3086aeae DJ |
4685 | else |
4686 | switch (b->type) | |
4687 | { | |
4688 | case bp_none: | |
4689 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4690 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4691 | break; |
c906108c | 4692 | |
3086aeae DJ |
4693 | case bp_watchpoint: |
4694 | case bp_hardware_watchpoint: | |
4695 | case bp_read_watchpoint: | |
4696 | case bp_access_watchpoint: | |
3a5c3e22 PA |
4697 | { |
4698 | struct watchpoint *w = (struct watchpoint *) b; | |
4699 | ||
4700 | /* Field 4, the address, is omitted (which makes the columns | |
4701 | not line up too nicely with the headers, but the effect | |
4702 | is relatively readable). */ | |
4703 | if (opts.addressprint) | |
4704 | ui_out_field_skip (uiout, "addr"); | |
4705 | annotate_field (5); | |
4706 | ui_out_field_string (uiout, "what", w->exp_string); | |
4707 | } | |
3086aeae DJ |
4708 | break; |
4709 | ||
3086aeae DJ |
4710 | case bp_breakpoint: |
4711 | case bp_hardware_breakpoint: | |
4712 | case bp_until: | |
4713 | case bp_finish: | |
4714 | case bp_longjmp: | |
4715 | case bp_longjmp_resume: | |
186c406b TT |
4716 | case bp_exception: |
4717 | case bp_exception_resume: | |
3086aeae | 4718 | case bp_step_resume: |
2c03e5be | 4719 | case bp_hp_step_resume: |
3086aeae DJ |
4720 | case bp_watchpoint_scope: |
4721 | case bp_call_dummy: | |
aa7d318d | 4722 | case bp_std_terminate: |
3086aeae DJ |
4723 | case bp_shlib_event: |
4724 | case bp_thread_event: | |
4725 | case bp_overlay_event: | |
0fd8e87f | 4726 | case bp_longjmp_master: |
aa7d318d | 4727 | case bp_std_terminate_master: |
186c406b | 4728 | case bp_exception_master: |
1042e4c0 | 4729 | case bp_tracepoint: |
7a697b8d | 4730 | case bp_fast_tracepoint: |
0fb4aa4b | 4731 | case bp_static_tracepoint: |
4efc6507 | 4732 | case bp_jit_event: |
0e30163f JK |
4733 | case bp_gnu_ifunc_resolver: |
4734 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4735 | if (opts.addressprint) |
3086aeae DJ |
4736 | { |
4737 | annotate_field (4); | |
54e52265 | 4738 | if (header_of_multiple) |
0d381245 | 4739 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4740 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4741 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4742 | else |
5af949e3 UW |
4743 | ui_out_field_core_addr (uiout, "addr", |
4744 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4745 | } |
4746 | annotate_field (5); | |
0d381245 | 4747 | if (!header_of_multiple) |
170b53b2 | 4748 | print_breakpoint_location (b, loc); |
0d381245 | 4749 | if (b->loc) |
a6d9a66e | 4750 | *last_loc = b->loc; |
3086aeae DJ |
4751 | break; |
4752 | } | |
c906108c | 4753 | |
6c95b8df PA |
4754 | |
4755 | /* For backward compatibility, don't display inferiors unless there | |
4756 | are several. */ | |
4757 | if (loc != NULL | |
4758 | && !header_of_multiple | |
4759 | && (allflag | |
4760 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4761 | && (number_of_program_spaces () > 1 | |
4762 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4763 | /* LOC is for existing B, it cannot be in |
4764 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4765 | && loc->owner->type != bp_catchpoint))) |
4766 | { | |
4767 | struct inferior *inf; | |
4768 | int first = 1; | |
4769 | ||
4770 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4771 | { | |
4772 | if (inf->pspace == loc->pspace) | |
4773 | { | |
4774 | if (first) | |
4775 | { | |
4776 | first = 0; | |
4777 | ui_out_text (uiout, " inf "); | |
4778 | } | |
4779 | else | |
4780 | ui_out_text (uiout, ", "); | |
4781 | ui_out_text (uiout, plongest (inf->num)); | |
4782 | } | |
4783 | } | |
4784 | } | |
4785 | ||
4a306c9a | 4786 | if (!part_of_multiple) |
c4093a6a | 4787 | { |
4a306c9a JB |
4788 | if (b->thread != -1) |
4789 | { | |
4790 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4791 | "stop only in" line a little further down. */ |
4a306c9a JB |
4792 | ui_out_text (uiout, " thread "); |
4793 | ui_out_field_int (uiout, "thread", b->thread); | |
4794 | } | |
4795 | else if (b->task != 0) | |
4796 | { | |
4797 | ui_out_text (uiout, " task "); | |
4798 | ui_out_field_int (uiout, "task", b->task); | |
4799 | } | |
c4093a6a | 4800 | } |
f1310107 | 4801 | |
8b93c638 | 4802 | ui_out_text (uiout, "\n"); |
f1310107 | 4803 | |
348d480f | 4804 | if (!part_of_multiple) |
f1310107 TJB |
4805 | b->ops->print_one_detail (b, uiout); |
4806 | ||
0d381245 | 4807 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4808 | { |
4809 | annotate_field (6); | |
8b93c638 | 4810 | ui_out_text (uiout, "\tstop only in stack frame at "); |
e5dd4106 | 4811 | /* FIXME: cagney/2002-12-01: Shouldn't be poking around inside |
818dd999 | 4812 | the frame ID. */ |
5af949e3 UW |
4813 | ui_out_field_core_addr (uiout, "frame", |
4814 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4815 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4816 | } |
4817 | ||
28010a5d | 4818 | if (!part_of_multiple && b->cond_string) |
c4093a6a JM |
4819 | { |
4820 | annotate_field (7); | |
d77f58be | 4821 | if (is_tracepoint (b)) |
1042e4c0 SS |
4822 | ui_out_text (uiout, "\ttrace only if "); |
4823 | else | |
4824 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4825 | ui_out_field_string (uiout, "cond", b->cond_string); |
4826 | ui_out_text (uiout, "\n"); | |
4827 | } | |
4828 | ||
0d381245 | 4829 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4830 | { |
4a64f543 | 4831 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4832 | ui_out_text (uiout, "\tstop only in thread "); |
4833 | ui_out_field_int (uiout, "thread", b->thread); | |
4834 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4835 | } |
4836 | ||
63c715c6 | 4837 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4838 | { |
4a64f543 | 4839 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4840 | if (ep_is_catchpoint (b)) |
4841 | ui_out_text (uiout, "\tcatchpoint"); | |
4842 | else | |
4843 | ui_out_text (uiout, "\tbreakpoint"); | |
4844 | ui_out_text (uiout, " already hit "); | |
4845 | ui_out_field_int (uiout, "times", b->hit_count); | |
4846 | if (b->hit_count == 1) | |
4847 | ui_out_text (uiout, " time\n"); | |
4848 | else | |
4849 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4850 | } |
4851 | ||
4a64f543 MS |
4852 | /* Output the count also if it is zero, but only if this is mi. |
4853 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4854 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4855 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4856 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4857 | |
0d381245 | 4858 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4859 | { |
4860 | annotate_field (8); | |
8b93c638 JM |
4861 | ui_out_text (uiout, "\tignore next "); |
4862 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4863 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4864 | } |
059fb39f | 4865 | |
9add0f1b | 4866 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4867 | if (!part_of_multiple && l) |
c4093a6a | 4868 | { |
3b31d625 EZ |
4869 | struct cleanup *script_chain; |
4870 | ||
c4093a6a | 4871 | annotate_field (9); |
3b31d625 | 4872 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4873 | print_command_lines (uiout, l, 4); |
3b31d625 | 4874 | do_cleanups (script_chain); |
c4093a6a | 4875 | } |
d24317b4 | 4876 | |
d9b3f62e | 4877 | if (is_tracepoint (b)) |
1042e4c0 | 4878 | { |
d9b3f62e PA |
4879 | struct tracepoint *t = (struct tracepoint *) b; |
4880 | ||
4881 | if (!part_of_multiple && t->pass_count) | |
4882 | { | |
4883 | annotate_field (10); | |
4884 | ui_out_text (uiout, "\tpass count "); | |
4885 | ui_out_field_int (uiout, "pass", t->pass_count); | |
4886 | ui_out_text (uiout, " \n"); | |
4887 | } | |
1042e4c0 SS |
4888 | } |
4889 | ||
d24317b4 VP |
4890 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4891 | { | |
3a5c3e22 PA |
4892 | if (is_watchpoint (b)) |
4893 | { | |
4894 | struct watchpoint *w = (struct watchpoint *) b; | |
4895 | ||
4896 | ui_out_field_string (uiout, "original-location", w->exp_string); | |
4897 | } | |
4898 | else if (b->addr_string) | |
d24317b4 | 4899 | ui_out_field_string (uiout, "original-location", b->addr_string); |
d24317b4 | 4900 | } |
c4093a6a | 4901 | } |
c5aa993b | 4902 | |
0d381245 VP |
4903 | static void |
4904 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 4905 | struct bp_location **last_loc, |
6c95b8df | 4906 | int allflag) |
0d381245 | 4907 | { |
8d3788bd VP |
4908 | struct cleanup *bkpt_chain; |
4909 | ||
4910 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
4911 | ||
12c5a436 | 4912 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 4913 | do_cleanups (bkpt_chain); |
0d381245 VP |
4914 | |
4915 | /* If this breakpoint has custom print function, | |
4916 | it's already printed. Otherwise, print individual | |
4917 | locations, if any. */ | |
4918 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4919 | { | |
4a64f543 MS |
4920 | /* If breakpoint has a single location that is disabled, we |
4921 | print it as if it had several locations, since otherwise it's | |
4922 | hard to represent "breakpoint enabled, location disabled" | |
4923 | situation. | |
4924 | ||
4925 | Note that while hardware watchpoints have several locations | |
a3be7890 | 4926 | internally, that's not a property exposed to user. */ |
0d381245 | 4927 | if (b->loc |
a5606eee | 4928 | && !is_hardware_watchpoint (b) |
8d3788bd | 4929 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
4930 | { |
4931 | struct bp_location *loc; | |
4932 | int n = 1; | |
8d3788bd | 4933 | |
0d381245 | 4934 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
4935 | { |
4936 | struct cleanup *inner2 = | |
4937 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
4938 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
4939 | do_cleanups (inner2); | |
4940 | } | |
0d381245 VP |
4941 | } |
4942 | } | |
4943 | } | |
4944 | ||
a6d9a66e UW |
4945 | static int |
4946 | breakpoint_address_bits (struct breakpoint *b) | |
4947 | { | |
4948 | int print_address_bits = 0; | |
4949 | struct bp_location *loc; | |
4950 | ||
4951 | for (loc = b->loc; loc; loc = loc->next) | |
4952 | { | |
c7437ca6 PA |
4953 | int addr_bit; |
4954 | ||
4955 | /* Software watchpoints that aren't watching memory don't have | |
4956 | an address to print. */ | |
4957 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4958 | continue; | |
4959 | ||
4960 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4961 | if (addr_bit > print_address_bits) |
4962 | print_address_bits = addr_bit; | |
4963 | } | |
4964 | ||
4965 | return print_address_bits; | |
4966 | } | |
0d381245 | 4967 | |
c4093a6a JM |
4968 | struct captured_breakpoint_query_args |
4969 | { | |
4970 | int bnum; | |
4971 | }; | |
c5aa993b | 4972 | |
c4093a6a | 4973 | static int |
2b65245e | 4974 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4975 | { |
4976 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4977 | struct breakpoint *b; |
a6d9a66e | 4978 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 4979 | |
c4093a6a JM |
4980 | ALL_BREAKPOINTS (b) |
4981 | { | |
4982 | if (args->bnum == b->number) | |
c5aa993b | 4983 | { |
12c5a436 | 4984 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 4985 | return GDB_RC_OK; |
c5aa993b | 4986 | } |
c4093a6a JM |
4987 | } |
4988 | return GDB_RC_NONE; | |
4989 | } | |
c5aa993b | 4990 | |
c4093a6a | 4991 | enum gdb_rc |
4a64f543 MS |
4992 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
4993 | char **error_message) | |
c4093a6a JM |
4994 | { |
4995 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 4996 | |
c4093a6a JM |
4997 | args.bnum = bnum; |
4998 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 4999 | an error. */ |
b0b13bb4 DJ |
5000 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5001 | error_message, RETURN_MASK_ALL) < 0) | |
5002 | return GDB_RC_FAIL; | |
5003 | else | |
5004 | return GDB_RC_OK; | |
c4093a6a | 5005 | } |
c5aa993b | 5006 | |
09d682a4 TT |
5007 | /* Return true if this breakpoint was set by the user, false if it is |
5008 | internal or momentary. */ | |
5009 | ||
5010 | int | |
5011 | user_breakpoint_p (struct breakpoint *b) | |
5012 | { | |
46c6471b | 5013 | return b->number > 0; |
09d682a4 TT |
5014 | } |
5015 | ||
7f3b0473 | 5016 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5017 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5018 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5019 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5020 | ones for which it returns non-zero. Return the total number of | |
5021 | breakpoints listed. */ | |
c906108c | 5022 | |
d77f58be | 5023 | static int |
e5a67952 | 5024 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5025 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5026 | { |
52f0bd74 | 5027 | struct breakpoint *b; |
a6d9a66e | 5028 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5029 | int nr_printable_breakpoints; |
3b31d625 | 5030 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5031 | struct value_print_options opts; |
a6d9a66e | 5032 | int print_address_bits = 0; |
269b11a2 PA |
5033 | int print_type_col_width = 14; |
5034 | ||
79a45b7d TT |
5035 | get_user_print_options (&opts); |
5036 | ||
4a64f543 MS |
5037 | /* Compute the number of rows in the table, as well as the size |
5038 | required for address fields. */ | |
7f3b0473 AC |
5039 | nr_printable_breakpoints = 0; |
5040 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5041 | { |
5042 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5043 | if (filter && !filter (b)) | |
5044 | continue; | |
5045 | ||
5046 | /* If we have an "args" string, it is a list of breakpoints to | |
5047 | accept. Skip the others. */ | |
5048 | if (args != NULL && *args != '\0') | |
5049 | { | |
5050 | if (allflag && parse_and_eval_long (args) != b->number) | |
5051 | continue; | |
5052 | if (!allflag && !number_is_in_list (args, b->number)) | |
5053 | continue; | |
5054 | } | |
269b11a2 | 5055 | |
e5a67952 MS |
5056 | if (allflag || user_breakpoint_p (b)) |
5057 | { | |
5058 | int addr_bit, type_len; | |
a6d9a66e | 5059 | |
e5a67952 MS |
5060 | addr_bit = breakpoint_address_bits (b); |
5061 | if (addr_bit > print_address_bits) | |
5062 | print_address_bits = addr_bit; | |
269b11a2 | 5063 | |
e5a67952 MS |
5064 | type_len = strlen (bptype_string (b->type)); |
5065 | if (type_len > print_type_col_width) | |
5066 | print_type_col_width = type_len; | |
5067 | ||
5068 | nr_printable_breakpoints++; | |
5069 | } | |
5070 | } | |
7f3b0473 | 5071 | |
79a45b7d | 5072 | if (opts.addressprint) |
3b31d625 | 5073 | bkpttbl_chain |
3e43a32a MS |
5074 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5075 | nr_printable_breakpoints, | |
3b31d625 | 5076 | "BreakpointTable"); |
8b93c638 | 5077 | else |
3b31d625 | 5078 | bkpttbl_chain |
3e43a32a MS |
5079 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5080 | nr_printable_breakpoints, | |
3b31d625 | 5081 | "BreakpointTable"); |
8b93c638 | 5082 | |
7f3b0473 | 5083 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5084 | annotate_breakpoints_headers (); |
5085 | if (nr_printable_breakpoints > 0) | |
5086 | annotate_field (0); | |
4a64f543 | 5087 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5088 | if (nr_printable_breakpoints > 0) |
5089 | annotate_field (1); | |
269b11a2 | 5090 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5091 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5092 | if (nr_printable_breakpoints > 0) |
5093 | annotate_field (2); | |
4a64f543 | 5094 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5095 | if (nr_printable_breakpoints > 0) |
5096 | annotate_field (3); | |
54e52265 | 5097 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5098 | if (opts.addressprint) |
e5a67952 MS |
5099 | { |
5100 | if (nr_printable_breakpoints > 0) | |
5101 | annotate_field (4); | |
5102 | if (print_address_bits <= 32) | |
5103 | ui_out_table_header (uiout, 10, ui_left, | |
5104 | "addr", "Address"); /* 5 */ | |
5105 | else | |
5106 | ui_out_table_header (uiout, 18, ui_left, | |
5107 | "addr", "Address"); /* 5 */ | |
5108 | } | |
d7faa9e7 AC |
5109 | if (nr_printable_breakpoints > 0) |
5110 | annotate_field (5); | |
5111 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5112 | ui_out_table_body (uiout); | |
5113 | if (nr_printable_breakpoints > 0) | |
5114 | annotate_breakpoints_table (); | |
7f3b0473 | 5115 | |
c4093a6a | 5116 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5117 | { |
5118 | QUIT; | |
5119 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5120 | if (filter && !filter (b)) | |
5121 | continue; | |
5122 | ||
5123 | /* If we have an "args" string, it is a list of breakpoints to | |
5124 | accept. Skip the others. */ | |
5125 | ||
5126 | if (args != NULL && *args != '\0') | |
5127 | { | |
5128 | if (allflag) /* maintenance info breakpoint */ | |
5129 | { | |
5130 | if (parse_and_eval_long (args) != b->number) | |
5131 | continue; | |
5132 | } | |
5133 | else /* all others */ | |
5134 | { | |
5135 | if (!number_is_in_list (args, b->number)) | |
5136 | continue; | |
5137 | } | |
5138 | } | |
5139 | /* We only print out user settable breakpoints unless the | |
5140 | allflag is set. */ | |
5141 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5142 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5143 | } |
5144 | ||
3b31d625 | 5145 | do_cleanups (bkpttbl_chain); |
698384cd | 5146 | |
7f3b0473 | 5147 | if (nr_printable_breakpoints == 0) |
c906108c | 5148 | { |
4a64f543 MS |
5149 | /* If there's a filter, let the caller decide how to report |
5150 | empty list. */ | |
d77f58be SS |
5151 | if (!filter) |
5152 | { | |
e5a67952 | 5153 | if (args == NULL || *args == '\0') |
d77f58be SS |
5154 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5155 | else | |
4a64f543 | 5156 | ui_out_message (uiout, 0, |
e5a67952 MS |
5157 | "No breakpoint or watchpoint matching '%s'.\n", |
5158 | args); | |
d77f58be | 5159 | } |
c906108c SS |
5160 | } |
5161 | else | |
c4093a6a | 5162 | { |
a6d9a66e UW |
5163 | if (last_loc && !server_command) |
5164 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5165 | } |
c906108c | 5166 | |
4a64f543 | 5167 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5168 | there have been breakpoints? */ |
c906108c | 5169 | annotate_breakpoints_table_end (); |
d77f58be SS |
5170 | |
5171 | return nr_printable_breakpoints; | |
c906108c SS |
5172 | } |
5173 | ||
ad443146 SS |
5174 | /* Display the value of default-collect in a way that is generally |
5175 | compatible with the breakpoint list. */ | |
5176 | ||
5177 | static void | |
5178 | default_collect_info (void) | |
5179 | { | |
5180 | /* If it has no value (which is frequently the case), say nothing; a | |
5181 | message like "No default-collect." gets in user's face when it's | |
5182 | not wanted. */ | |
5183 | if (!*default_collect) | |
5184 | return; | |
5185 | ||
5186 | /* The following phrase lines up nicely with per-tracepoint collect | |
5187 | actions. */ | |
5188 | ui_out_text (uiout, "default collect "); | |
5189 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5190 | ui_out_text (uiout, " \n"); | |
5191 | } | |
5192 | ||
c906108c | 5193 | static void |
e5a67952 | 5194 | breakpoints_info (char *args, int from_tty) |
c906108c | 5195 | { |
e5a67952 | 5196 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5197 | |
5198 | default_collect_info (); | |
d77f58be SS |
5199 | } |
5200 | ||
5201 | static void | |
e5a67952 | 5202 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5203 | { |
e5a67952 | 5204 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
d77f58be SS |
5205 | |
5206 | if (num_printed == 0) | |
5207 | { | |
e5a67952 | 5208 | if (args == NULL || *args == '\0') |
d77f58be SS |
5209 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5210 | else | |
e5a67952 | 5211 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5212 | } |
c906108c SS |
5213 | } |
5214 | ||
7a292a7a | 5215 | static void |
e5a67952 | 5216 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5217 | { |
e5a67952 | 5218 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5219 | |
5220 | default_collect_info (); | |
c906108c SS |
5221 | } |
5222 | ||
0d381245 | 5223 | static int |
714835d5 | 5224 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5225 | struct program_space *pspace, |
714835d5 | 5226 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5227 | { |
5228 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5229 | |
0d381245 VP |
5230 | for (; bl; bl = bl->next) |
5231 | { | |
6c95b8df PA |
5232 | if (bl->pspace == pspace |
5233 | && bl->address == pc | |
0d381245 VP |
5234 | && (!overlay_debugging || bl->section == section)) |
5235 | return 1; | |
5236 | } | |
5237 | return 0; | |
5238 | } | |
5239 | ||
6c95b8df PA |
5240 | /* Print a message describing any breakpoints set at PC. This |
5241 | concerns with logical breakpoints, so we match program spaces, not | |
5242 | address spaces. */ | |
c906108c SS |
5243 | |
5244 | static void | |
6c95b8df PA |
5245 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5246 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5247 | struct obj_section *section, int thread) |
c906108c | 5248 | { |
52f0bd74 AC |
5249 | int others = 0; |
5250 | struct breakpoint *b; | |
c906108c SS |
5251 | |
5252 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5253 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5254 | if (others > 0) |
5255 | { | |
a3f17187 AC |
5256 | if (others == 1) |
5257 | printf_filtered (_("Note: breakpoint ")); | |
5258 | else /* if (others == ???) */ | |
5259 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5260 | ALL_BREAKPOINTS (b) |
6c95b8df | 5261 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5262 | { |
5263 | others--; | |
5264 | printf_filtered ("%d", b->number); | |
5265 | if (b->thread == -1 && thread != -1) | |
5266 | printf_filtered (" (all threads)"); | |
5267 | else if (b->thread != -1) | |
5268 | printf_filtered (" (thread %d)", b->thread); | |
5269 | printf_filtered ("%s%s ", | |
059fb39f | 5270 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5271 | || b->enable_state == bp_call_disabled |
5272 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5273 | ? " (disabled)" |
5274 | : b->enable_state == bp_permanent | |
5275 | ? " (permanent)" | |
5276 | : ""), | |
5277 | (others > 1) ? "," | |
5278 | : ((others == 1) ? " and" : "")); | |
5279 | } | |
a3f17187 | 5280 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5281 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5282 | printf_filtered (".\n"); |
5283 | } | |
5284 | } | |
5285 | \f | |
5286 | /* Set the default place to put a breakpoint | |
5287 | for the `break' command with no arguments. */ | |
5288 | ||
5289 | void | |
6c95b8df PA |
5290 | set_default_breakpoint (int valid, struct program_space *pspace, |
5291 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5292 | int line) |
c906108c SS |
5293 | { |
5294 | default_breakpoint_valid = valid; | |
6c95b8df | 5295 | default_breakpoint_pspace = pspace; |
c906108c SS |
5296 | default_breakpoint_address = addr; |
5297 | default_breakpoint_symtab = symtab; | |
5298 | default_breakpoint_line = line; | |
5299 | } | |
5300 | ||
e4f237da KB |
5301 | /* Return true iff it is meaningful to use the address member of |
5302 | BPT. For some breakpoint types, the address member is irrelevant | |
5303 | and it makes no sense to attempt to compare it to other addresses | |
5304 | (or use it for any other purpose either). | |
5305 | ||
4a64f543 MS |
5306 | More specifically, each of the following breakpoint types will |
5307 | always have a zero valued address and we don't want to mark | |
5308 | breakpoints of any of these types to be a duplicate of an actual | |
5309 | breakpoint at address zero: | |
e4f237da KB |
5310 | |
5311 | bp_watchpoint | |
2d134ed3 PA |
5312 | bp_catchpoint |
5313 | ||
5314 | */ | |
e4f237da KB |
5315 | |
5316 | static int | |
5317 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5318 | { | |
5319 | enum bptype type = bpt->type; | |
5320 | ||
2d134ed3 PA |
5321 | return (type != bp_watchpoint && type != bp_catchpoint); |
5322 | } | |
5323 | ||
5324 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5325 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5326 | ||
5327 | static int | |
4a64f543 MS |
5328 | watchpoint_locations_match (struct bp_location *loc1, |
5329 | struct bp_location *loc2) | |
2d134ed3 | 5330 | { |
3a5c3e22 PA |
5331 | struct watchpoint *w1 = (struct watchpoint *) loc1->owner; |
5332 | struct watchpoint *w2 = (struct watchpoint *) loc2->owner; | |
5333 | ||
5334 | /* Both of them must exist. */ | |
5335 | gdb_assert (w1 != NULL); | |
5336 | gdb_assert (w2 != NULL); | |
2bdf28a0 | 5337 | |
4a64f543 MS |
5338 | /* If the target can evaluate the condition expression in hardware, |
5339 | then we we need to insert both watchpoints even if they are at | |
5340 | the same place. Otherwise the watchpoint will only trigger when | |
5341 | the condition of whichever watchpoint was inserted evaluates to | |
5342 | true, not giving a chance for GDB to check the condition of the | |
5343 | other watchpoint. */ | |
3a5c3e22 | 5344 | if ((w1->cond_exp |
4a64f543 MS |
5345 | && target_can_accel_watchpoint_condition (loc1->address, |
5346 | loc1->length, | |
0cf6dd15 | 5347 | loc1->watchpoint_type, |
3a5c3e22 PA |
5348 | w1->cond_exp)) |
5349 | || (w2->cond_exp | |
4a64f543 MS |
5350 | && target_can_accel_watchpoint_condition (loc2->address, |
5351 | loc2->length, | |
0cf6dd15 | 5352 | loc2->watchpoint_type, |
3a5c3e22 | 5353 | w2->cond_exp))) |
0cf6dd15 TJB |
5354 | return 0; |
5355 | ||
85d721b8 PA |
5356 | /* Note that this checks the owner's type, not the location's. In |
5357 | case the target does not support read watchpoints, but does | |
5358 | support access watchpoints, we'll have bp_read_watchpoint | |
5359 | watchpoints with hw_access locations. Those should be considered | |
5360 | duplicates of hw_read locations. The hw_read locations will | |
5361 | become hw_access locations later. */ | |
2d134ed3 PA |
5362 | return (loc1->owner->type == loc2->owner->type |
5363 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5364 | && loc1->address == loc2->address | |
5365 | && loc1->length == loc2->length); | |
e4f237da KB |
5366 | } |
5367 | ||
6c95b8df PA |
5368 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5369 | same breakpoint location. In most targets, this can only be true | |
5370 | if ASPACE1 matches ASPACE2. On targets that have global | |
5371 | breakpoints, the address space doesn't really matter. */ | |
5372 | ||
5373 | static int | |
5374 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5375 | struct address_space *aspace2, CORE_ADDR addr2) | |
5376 | { | |
5377 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5378 | || aspace1 == aspace2) | |
5379 | && addr1 == addr2); | |
5380 | } | |
5381 | ||
f1310107 TJB |
5382 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5383 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5384 | matches ASPACE2. On targets that have global breakpoints, the address | |
5385 | space doesn't really matter. */ | |
5386 | ||
5387 | static int | |
5388 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5389 | int len1, struct address_space *aspace2, | |
5390 | CORE_ADDR addr2) | |
5391 | { | |
5392 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5393 | || aspace1 == aspace2) | |
5394 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5395 | } | |
5396 | ||
5397 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5398 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5399 | matches the breakpoint's address space. On targets that have global | |
5400 | breakpoints, the address space doesn't really matter. */ | |
5401 | ||
5402 | static int | |
5403 | breakpoint_location_address_match (struct bp_location *bl, | |
5404 | struct address_space *aspace, | |
5405 | CORE_ADDR addr) | |
5406 | { | |
5407 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5408 | aspace, addr) | |
5409 | || (bl->length | |
5410 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5411 | bl->address, bl->length, | |
5412 | aspace, addr))); | |
5413 | } | |
5414 | ||
2d134ed3 PA |
5415 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5416 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5417 | represent the same location. */ | |
5418 | ||
5419 | static int | |
4a64f543 MS |
5420 | breakpoint_locations_match (struct bp_location *loc1, |
5421 | struct bp_location *loc2) | |
2d134ed3 | 5422 | { |
2bdf28a0 JK |
5423 | int hw_point1, hw_point2; |
5424 | ||
5425 | /* Both of them must not be in moribund_locations. */ | |
5426 | gdb_assert (loc1->owner != NULL); | |
5427 | gdb_assert (loc2->owner != NULL); | |
5428 | ||
5429 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5430 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5431 | |
5432 | if (hw_point1 != hw_point2) | |
5433 | return 0; | |
5434 | else if (hw_point1) | |
5435 | return watchpoint_locations_match (loc1, loc2); | |
5436 | else | |
f1310107 TJB |
5437 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5438 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5439 | loc2->pspace->aspace, loc2->address) | |
5440 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5441 | } |
5442 | ||
76897487 KB |
5443 | static void |
5444 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5445 | int bnum, int have_bnum) | |
5446 | { | |
f63fbe86 MS |
5447 | /* The longest string possibly returned by hex_string_custom |
5448 | is 50 chars. These must be at least that big for safety. */ | |
5449 | char astr1[64]; | |
5450 | char astr2[64]; | |
76897487 | 5451 | |
bb599908 PH |
5452 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5453 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5454 | if (have_bnum) |
8a3fe4f8 | 5455 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5456 | bnum, astr1, astr2); |
5457 | else | |
8a3fe4f8 | 5458 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5459 | } |
5460 | ||
4a64f543 MS |
5461 | /* Adjust a breakpoint's address to account for architectural |
5462 | constraints on breakpoint placement. Return the adjusted address. | |
5463 | Note: Very few targets require this kind of adjustment. For most | |
5464 | targets, this function is simply the identity function. */ | |
76897487 KB |
5465 | |
5466 | static CORE_ADDR | |
a6d9a66e UW |
5467 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5468 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5469 | { |
a6d9a66e | 5470 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5471 | { |
5472 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5473 | return bpaddr; | |
5474 | } | |
88f7da05 KB |
5475 | else if (bptype == bp_watchpoint |
5476 | || bptype == bp_hardware_watchpoint | |
5477 | || bptype == bp_read_watchpoint | |
5478 | || bptype == bp_access_watchpoint | |
fe798b75 | 5479 | || bptype == bp_catchpoint) |
88f7da05 KB |
5480 | { |
5481 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5482 | have their addresses modified. */ | |
5483 | return bpaddr; | |
5484 | } | |
76897487 KB |
5485 | else |
5486 | { | |
5487 | CORE_ADDR adjusted_bpaddr; | |
5488 | ||
5489 | /* Some targets have architectural constraints on the placement | |
5490 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5491 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5492 | |
5493 | /* An adjusted breakpoint address can significantly alter | |
5494 | a user's expectations. Print a warning if an adjustment | |
5495 | is required. */ | |
5496 | if (adjusted_bpaddr != bpaddr) | |
5497 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5498 | ||
5499 | return adjusted_bpaddr; | |
5500 | } | |
5501 | } | |
5502 | ||
28010a5d PA |
5503 | void |
5504 | init_bp_location (struct bp_location *loc, const struct bp_location_ops *ops, | |
5505 | struct breakpoint *owner) | |
7cc221ef | 5506 | { |
7cc221ef DJ |
5507 | memset (loc, 0, sizeof (*loc)); |
5508 | ||
348d480f PA |
5509 | gdb_assert (ops != NULL); |
5510 | ||
28010a5d PA |
5511 | loc->ops = ops; |
5512 | loc->owner = owner; | |
511a6cd4 | 5513 | loc->cond = NULL; |
0d381245 VP |
5514 | loc->shlib_disabled = 0; |
5515 | loc->enabled = 1; | |
e049a4b5 | 5516 | |
28010a5d | 5517 | switch (owner->type) |
e049a4b5 DJ |
5518 | { |
5519 | case bp_breakpoint: | |
5520 | case bp_until: | |
5521 | case bp_finish: | |
5522 | case bp_longjmp: | |
5523 | case bp_longjmp_resume: | |
186c406b TT |
5524 | case bp_exception: |
5525 | case bp_exception_resume: | |
e049a4b5 | 5526 | case bp_step_resume: |
2c03e5be | 5527 | case bp_hp_step_resume: |
e049a4b5 DJ |
5528 | case bp_watchpoint_scope: |
5529 | case bp_call_dummy: | |
aa7d318d | 5530 | case bp_std_terminate: |
e049a4b5 DJ |
5531 | case bp_shlib_event: |
5532 | case bp_thread_event: | |
5533 | case bp_overlay_event: | |
4efc6507 | 5534 | case bp_jit_event: |
0fd8e87f | 5535 | case bp_longjmp_master: |
aa7d318d | 5536 | case bp_std_terminate_master: |
186c406b | 5537 | case bp_exception_master: |
0e30163f JK |
5538 | case bp_gnu_ifunc_resolver: |
5539 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5540 | loc->loc_type = bp_loc_software_breakpoint; |
5541 | break; | |
5542 | case bp_hardware_breakpoint: | |
5543 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5544 | break; | |
5545 | case bp_hardware_watchpoint: | |
5546 | case bp_read_watchpoint: | |
5547 | case bp_access_watchpoint: | |
5548 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5549 | break; | |
5550 | case bp_watchpoint: | |
ce78b96d | 5551 | case bp_catchpoint: |
15c3d785 PA |
5552 | case bp_tracepoint: |
5553 | case bp_fast_tracepoint: | |
0fb4aa4b | 5554 | case bp_static_tracepoint: |
e049a4b5 DJ |
5555 | loc->loc_type = bp_loc_other; |
5556 | break; | |
5557 | default: | |
e2e0b3e5 | 5558 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5559 | } |
5560 | ||
f431efe5 | 5561 | loc->refc = 1; |
28010a5d PA |
5562 | } |
5563 | ||
5564 | /* Allocate a struct bp_location. */ | |
5565 | ||
5566 | static struct bp_location * | |
5567 | allocate_bp_location (struct breakpoint *bpt) | |
5568 | { | |
348d480f PA |
5569 | return bpt->ops->allocate_location (bpt); |
5570 | } | |
7cc221ef | 5571 | |
f431efe5 PA |
5572 | static void |
5573 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 | 5574 | { |
348d480f | 5575 | loc->ops->dtor (loc); |
fe3f5fa8 VP |
5576 | xfree (loc); |
5577 | } | |
5578 | ||
f431efe5 PA |
5579 | /* Increment reference count. */ |
5580 | ||
5581 | static void | |
5582 | incref_bp_location (struct bp_location *bl) | |
5583 | { | |
5584 | ++bl->refc; | |
5585 | } | |
5586 | ||
5587 | /* Decrement reference count. If the reference count reaches 0, | |
5588 | destroy the bp_location. Sets *BLP to NULL. */ | |
5589 | ||
5590 | static void | |
5591 | decref_bp_location (struct bp_location **blp) | |
5592 | { | |
0807b50c PA |
5593 | gdb_assert ((*blp)->refc > 0); |
5594 | ||
f431efe5 PA |
5595 | if (--(*blp)->refc == 0) |
5596 | free_bp_location (*blp); | |
5597 | *blp = NULL; | |
5598 | } | |
5599 | ||
346774a9 | 5600 | /* Add breakpoint B at the end of the global breakpoint chain. */ |
c906108c | 5601 | |
346774a9 PA |
5602 | static void |
5603 | add_to_breakpoint_chain (struct breakpoint *b) | |
c906108c | 5604 | { |
346774a9 | 5605 | struct breakpoint *b1; |
c906108c | 5606 | |
346774a9 PA |
5607 | /* Add this breakpoint to the end of the chain so that a list of |
5608 | breakpoints will come out in order of increasing numbers. */ | |
5609 | ||
5610 | b1 = breakpoint_chain; | |
5611 | if (b1 == 0) | |
5612 | breakpoint_chain = b; | |
5613 | else | |
5614 | { | |
5615 | while (b1->next) | |
5616 | b1 = b1->next; | |
5617 | b1->next = b; | |
5618 | } | |
5619 | } | |
5620 | ||
5621 | /* Initializes breakpoint B with type BPTYPE and no locations yet. */ | |
5622 | ||
5623 | static void | |
5624 | init_raw_breakpoint_without_location (struct breakpoint *b, | |
5625 | struct gdbarch *gdbarch, | |
28010a5d | 5626 | enum bptype bptype, |
c0a91b2b | 5627 | const struct breakpoint_ops *ops) |
346774a9 | 5628 | { |
c906108c | 5629 | memset (b, 0, sizeof (*b)); |
2219d63c | 5630 | |
348d480f PA |
5631 | gdb_assert (ops != NULL); |
5632 | ||
28010a5d | 5633 | b->ops = ops; |
4d28f7a8 | 5634 | b->type = bptype; |
a6d9a66e | 5635 | b->gdbarch = gdbarch; |
c906108c SS |
5636 | b->language = current_language->la_language; |
5637 | b->input_radix = input_radix; | |
5638 | b->thread = -1; | |
b5de0fa7 | 5639 | b->enable_state = bp_enabled; |
c906108c SS |
5640 | b->next = 0; |
5641 | b->silent = 0; | |
5642 | b->ignore_count = 0; | |
5643 | b->commands = NULL; | |
818dd999 | 5644 | b->frame_id = null_frame_id; |
0d381245 | 5645 | b->condition_not_parsed = 0; |
84f4c1fe | 5646 | b->py_bp_object = NULL; |
d0fb5eae | 5647 | b->related_breakpoint = b; |
346774a9 PA |
5648 | } |
5649 | ||
5650 | /* Helper to set_raw_breakpoint below. Creates a breakpoint | |
5651 | that has type BPTYPE and has no locations as yet. */ | |
346774a9 PA |
5652 | |
5653 | static struct breakpoint * | |
5654 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, | |
348d480f | 5655 | enum bptype bptype, |
c0a91b2b | 5656 | const struct breakpoint_ops *ops) |
346774a9 PA |
5657 | { |
5658 | struct breakpoint *b = XNEW (struct breakpoint); | |
5659 | ||
348d480f | 5660 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
c56053d2 | 5661 | add_to_breakpoint_chain (b); |
0d381245 VP |
5662 | return b; |
5663 | } | |
5664 | ||
0e30163f JK |
5665 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5666 | resolutions should be made as the user specified the location explicitly | |
5667 | enough. */ | |
5668 | ||
0d381245 | 5669 | static void |
0e30163f | 5670 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5671 | { |
2bdf28a0 JK |
5672 | gdb_assert (loc->owner != NULL); |
5673 | ||
0d381245 | 5674 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5675 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5676 | || is_tracepoint (loc->owner)) |
0d381245 | 5677 | { |
0e30163f JK |
5678 | int is_gnu_ifunc; |
5679 | ||
5680 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5681 | NULL, NULL, &is_gnu_ifunc); | |
5682 | ||
5683 | if (is_gnu_ifunc && !explicit_loc) | |
5684 | { | |
5685 | struct breakpoint *b = loc->owner; | |
5686 | ||
5687 | gdb_assert (loc->pspace == current_program_space); | |
5688 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5689 | &loc->requested_address)) | |
5690 | { | |
5691 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5692 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5693 | loc->requested_address, | |
5694 | b->type); | |
5695 | } | |
5696 | else if (b->type == bp_breakpoint && b->loc == loc | |
5697 | && loc->next == NULL && b->related_breakpoint == b) | |
5698 | { | |
5699 | /* Create only the whole new breakpoint of this type but do not | |
5700 | mess more complicated breakpoints with multiple locations. */ | |
5701 | b->type = bp_gnu_ifunc_resolver; | |
5702 | } | |
5703 | } | |
5704 | ||
0d381245 VP |
5705 | if (loc->function_name) |
5706 | loc->function_name = xstrdup (loc->function_name); | |
5707 | } | |
5708 | } | |
5709 | ||
a6d9a66e UW |
5710 | /* Attempt to determine architecture of location identified by SAL. */ |
5711 | static struct gdbarch * | |
5712 | get_sal_arch (struct symtab_and_line sal) | |
5713 | { | |
5714 | if (sal.section) | |
5715 | return get_objfile_arch (sal.section->objfile); | |
5716 | if (sal.symtab) | |
5717 | return get_objfile_arch (sal.symtab->objfile); | |
5718 | ||
5719 | return NULL; | |
5720 | } | |
5721 | ||
346774a9 PA |
5722 | /* Low level routine for partially initializing a breakpoint of type |
5723 | BPTYPE. The newly created breakpoint's address, section, source | |
c56053d2 | 5724 | file name, and line number are provided by SAL. |
0d381245 VP |
5725 | |
5726 | It is expected that the caller will complete the initialization of | |
5727 | the newly created breakpoint struct as well as output any status | |
c56053d2 | 5728 | information regarding the creation of a new breakpoint. */ |
0d381245 | 5729 | |
346774a9 PA |
5730 | static void |
5731 | init_raw_breakpoint (struct breakpoint *b, struct gdbarch *gdbarch, | |
28010a5d | 5732 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5733 | const struct breakpoint_ops *ops) |
0d381245 | 5734 | { |
0d381245 | 5735 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5736 | struct gdbarch *loc_gdbarch; |
5737 | ||
28010a5d | 5738 | init_raw_breakpoint_without_location (b, gdbarch, bptype, ops); |
346774a9 | 5739 | |
a6d9a66e UW |
5740 | loc_gdbarch = get_sal_arch (sal); |
5741 | if (!loc_gdbarch) | |
5742 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5743 | |
6c95b8df PA |
5744 | if (bptype != bp_catchpoint) |
5745 | gdb_assert (sal.pspace != NULL); | |
5746 | ||
0d381245 VP |
5747 | /* Adjust the breakpoint's address prior to allocating a location. |
5748 | Once we call allocate_bp_location(), that mostly uninitialized | |
5749 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5750 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5751 | not want its scan of the location chain to find a breakpoint and |
5752 | location that's only been partially initialized. */ | |
4a64f543 MS |
5753 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5754 | sal.pc, b->type); | |
0d381245 | 5755 | |
39d61571 | 5756 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5757 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5758 | b->loc->requested_address = sal.pc; |
5759 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5760 | b->loc->pspace = sal.pspace; |
5761 | ||
5762 | /* Store the program space that was used to set the breakpoint, for | |
5763 | breakpoint resetting. */ | |
5764 | b->pspace = sal.pspace; | |
0d381245 VP |
5765 | |
5766 | if (sal.symtab == NULL) | |
5767 | b->source_file = NULL; | |
5768 | else | |
1b36a34b | 5769 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5770 | b->loc->section = sal.section; |
5771 | b->line_number = sal.line; | |
5772 | ||
0e30163f JK |
5773 | set_breakpoint_location_function (b->loc, |
5774 | sal.explicit_pc || sal.explicit_line); | |
c906108c | 5775 | |
c906108c | 5776 | breakpoints_changed (); |
346774a9 | 5777 | } |
c906108c | 5778 | |
346774a9 PA |
5779 | /* set_raw_breakpoint is a low level routine for allocating and |
5780 | partially initializing a breakpoint of type BPTYPE. The newly | |
5781 | created breakpoint's address, section, source file name, and line | |
5782 | number are provided by SAL. The newly created and partially | |
5783 | initialized breakpoint is added to the breakpoint chain and | |
5784 | is also returned as the value of this function. | |
5785 | ||
5786 | It is expected that the caller will complete the initialization of | |
5787 | the newly created breakpoint struct as well as output any status | |
5788 | information regarding the creation of a new breakpoint. In | |
5789 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5790 | number! Care should be taken to not allow an error to occur | |
5791 | prior to completing the initialization of the breakpoint. If this | |
5792 | should happen, a bogus breakpoint will be left on the chain. */ | |
5793 | ||
5794 | struct breakpoint * | |
5795 | set_raw_breakpoint (struct gdbarch *gdbarch, | |
348d480f | 5796 | struct symtab_and_line sal, enum bptype bptype, |
c0a91b2b | 5797 | const struct breakpoint_ops *ops) |
346774a9 PA |
5798 | { |
5799 | struct breakpoint *b = XNEW (struct breakpoint); | |
5800 | ||
348d480f | 5801 | init_raw_breakpoint (b, gdbarch, sal, bptype, ops); |
c56053d2 | 5802 | add_to_breakpoint_chain (b); |
c906108c SS |
5803 | return b; |
5804 | } | |
5805 | ||
c2c6d25f JM |
5806 | |
5807 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5808 | instruction, hard-wired into the inferior's code. */ | |
5809 | void | |
5810 | make_breakpoint_permanent (struct breakpoint *b) | |
5811 | { | |
0d381245 | 5812 | struct bp_location *bl; |
cc59ec59 | 5813 | |
b5de0fa7 | 5814 | b->enable_state = bp_permanent; |
c2c6d25f | 5815 | |
4a64f543 MS |
5816 | /* By definition, permanent breakpoints are already present in the |
5817 | code. Mark all locations as inserted. For now, | |
5818 | make_breakpoint_permanent is called in just one place, so it's | |
5819 | hard to say if it's reasonable to have permanent breakpoint with | |
e5dd4106 | 5820 | multiple locations or not, but it's easy to implement. */ |
0d381245 VP |
5821 | for (bl = b->loc; bl; bl = bl->next) |
5822 | bl->inserted = 1; | |
c2c6d25f JM |
5823 | } |
5824 | ||
53a5351d | 5825 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5826 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5827 | initiated the operation. */ | |
c906108c SS |
5828 | |
5829 | void | |
186c406b | 5830 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5831 | { |
35df4500 | 5832 | struct breakpoint *b, *b_tmp; |
186c406b | 5833 | int thread = tp->num; |
0fd8e87f UW |
5834 | |
5835 | /* To avoid having to rescan all objfile symbols at every step, | |
5836 | we maintain a list of continually-inserted but always disabled | |
5837 | longjmp "master" breakpoints. Here, we simply create momentary | |
5838 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5839 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5840 | if (b->pspace == current_program_space |
186c406b TT |
5841 | && (b->type == bp_longjmp_master |
5842 | || b->type == bp_exception_master)) | |
0fd8e87f | 5843 | { |
06edf0c0 PA |
5844 | enum bptype type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
5845 | struct breakpoint *clone; | |
cc59ec59 | 5846 | |
06edf0c0 PA |
5847 | clone = momentary_breakpoint_from_master (b, type, |
5848 | &momentary_breakpoint_ops); | |
0fd8e87f UW |
5849 | clone->thread = thread; |
5850 | } | |
186c406b TT |
5851 | |
5852 | tp->initiating_frame = frame; | |
c906108c SS |
5853 | } |
5854 | ||
611c83ae | 5855 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5856 | void |
611c83ae | 5857 | delete_longjmp_breakpoint (int thread) |
c906108c | 5858 | { |
35df4500 | 5859 | struct breakpoint *b, *b_tmp; |
c906108c | 5860 | |
35df4500 | 5861 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5862 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5863 | { |
5864 | if (b->thread == thread) | |
5865 | delete_breakpoint (b); | |
5866 | } | |
c906108c SS |
5867 | } |
5868 | ||
1900040c MS |
5869 | void |
5870 | enable_overlay_breakpoints (void) | |
5871 | { | |
52f0bd74 | 5872 | struct breakpoint *b; |
1900040c MS |
5873 | |
5874 | ALL_BREAKPOINTS (b) | |
5875 | if (b->type == bp_overlay_event) | |
5876 | { | |
5877 | b->enable_state = bp_enabled; | |
b60e7edf | 5878 | update_global_location_list (1); |
c02f5703 | 5879 | overlay_events_enabled = 1; |
1900040c MS |
5880 | } |
5881 | } | |
5882 | ||
5883 | void | |
5884 | disable_overlay_breakpoints (void) | |
5885 | { | |
52f0bd74 | 5886 | struct breakpoint *b; |
1900040c MS |
5887 | |
5888 | ALL_BREAKPOINTS (b) | |
5889 | if (b->type == bp_overlay_event) | |
5890 | { | |
5891 | b->enable_state = bp_disabled; | |
b60e7edf | 5892 | update_global_location_list (0); |
c02f5703 | 5893 | overlay_events_enabled = 0; |
1900040c MS |
5894 | } |
5895 | } | |
5896 | ||
aa7d318d TT |
5897 | /* Set an active std::terminate breakpoint for each std::terminate |
5898 | master breakpoint. */ | |
5899 | void | |
5900 | set_std_terminate_breakpoint (void) | |
5901 | { | |
35df4500 | 5902 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5903 | |
35df4500 | 5904 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5905 | if (b->pspace == current_program_space |
5906 | && b->type == bp_std_terminate_master) | |
5907 | { | |
06edf0c0 PA |
5908 | momentary_breakpoint_from_master (b, bp_std_terminate, |
5909 | &momentary_breakpoint_ops); | |
aa7d318d TT |
5910 | } |
5911 | } | |
5912 | ||
5913 | /* Delete all the std::terminate breakpoints. */ | |
5914 | void | |
5915 | delete_std_terminate_breakpoint (void) | |
5916 | { | |
35df4500 | 5917 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5918 | |
35df4500 | 5919 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5920 | if (b->type == bp_std_terminate) |
5921 | delete_breakpoint (b); | |
5922 | } | |
5923 | ||
c4093a6a | 5924 | struct breakpoint * |
a6d9a66e | 5925 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5926 | { |
5927 | struct breakpoint *b; | |
c4093a6a | 5928 | |
06edf0c0 PA |
5929 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event, |
5930 | &internal_breakpoint_ops); | |
5931 | ||
b5de0fa7 | 5932 | b->enable_state = bp_enabled; |
c4093a6a | 5933 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5934 | b->addr_string |
5935 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5936 | |
b60e7edf | 5937 | update_global_location_list_nothrow (1); |
74960c60 | 5938 | |
c4093a6a JM |
5939 | return b; |
5940 | } | |
5941 | ||
5942 | void | |
5943 | remove_thread_event_breakpoints (void) | |
5944 | { | |
35df4500 | 5945 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5946 | |
35df4500 | 5947 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5948 | if (b->type == bp_thread_event |
5949 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5950 | delete_breakpoint (b); |
5951 | } | |
5952 | ||
0101ce28 JJ |
5953 | struct lang_and_radix |
5954 | { | |
5955 | enum language lang; | |
5956 | int radix; | |
5957 | }; | |
5958 | ||
4efc6507 DE |
5959 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5960 | ||
5961 | struct breakpoint * | |
5962 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5963 | { | |
5964 | struct breakpoint *b; | |
5965 | ||
06edf0c0 PA |
5966 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event, |
5967 | &internal_breakpoint_ops); | |
4efc6507 DE |
5968 | update_global_location_list_nothrow (1); |
5969 | return b; | |
5970 | } | |
0101ce28 | 5971 | |
03673fc7 PP |
5972 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
5973 | ||
5974 | void | |
5975 | remove_jit_event_breakpoints (void) | |
5976 | { | |
5977 | struct breakpoint *b, *b_tmp; | |
5978 | ||
5979 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5980 | if (b->type == bp_jit_event | |
5981 | && b->loc->pspace == current_program_space) | |
5982 | delete_breakpoint (b); | |
5983 | } | |
5984 | ||
cae688ec JJ |
5985 | void |
5986 | remove_solib_event_breakpoints (void) | |
5987 | { | |
35df4500 | 5988 | struct breakpoint *b, *b_tmp; |
cae688ec | 5989 | |
35df4500 | 5990 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5991 | if (b->type == bp_shlib_event |
5992 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5993 | delete_breakpoint (b); |
5994 | } | |
5995 | ||
5996 | struct breakpoint * | |
a6d9a66e | 5997 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5998 | { |
5999 | struct breakpoint *b; | |
6000 | ||
06edf0c0 PA |
6001 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event, |
6002 | &internal_breakpoint_ops); | |
b60e7edf | 6003 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6004 | return b; |
6005 | } | |
6006 | ||
6007 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6008 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6009 | ||
6010 | void | |
cb851954 | 6011 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6012 | { |
876fa593 | 6013 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6014 | |
876fa593 | 6015 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6016 | { |
2bdf28a0 | 6017 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6018 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6019 | |
4a64f543 MS |
6020 | /* We apply the check to all breakpoints, including disabled for |
6021 | those with loc->duplicate set. This is so that when breakpoint | |
6022 | becomes enabled, or the duplicate is removed, gdb will try to | |
6023 | insert all breakpoints. If we don't set shlib_disabled here, | |
6024 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6025 | if (((b->type == bp_breakpoint) |
508ccb1f | 6026 | || (b->type == bp_jit_event) |
1042e4c0 | 6027 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6028 | || (is_tracepoint (b))) |
6c95b8df | 6029 | && loc->pspace == current_program_space |
0d381245 | 6030 | && !loc->shlib_disabled |
a77053c2 | 6031 | #ifdef PC_SOLIB |
0d381245 | 6032 | && PC_SOLIB (loc->address) |
a77053c2 | 6033 | #else |
6c95b8df | 6034 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6035 | #endif |
6036 | ) | |
0d381245 VP |
6037 | { |
6038 | loc->shlib_disabled = 1; | |
6039 | } | |
cae688ec JJ |
6040 | } |
6041 | } | |
6042 | ||
7a9dd1b2 | 6043 | /* Disable any breakpoints that are in an unloaded shared library. |
4a64f543 MS |
6044 | Only apply to enabled breakpoints, disabled ones can just stay |
6045 | disabled. */ | |
84acb35a | 6046 | |
75149521 | 6047 | static void |
84acb35a JJ |
6048 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6049 | { | |
876fa593 | 6050 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6051 | int disabled_shlib_breaks = 0; |
6052 | ||
c86cf029 VP |
6053 | /* SunOS a.out shared libraries are always mapped, so do not |
6054 | disable breakpoints; they will only be reported as unloaded | |
6055 | through clear_solib when GDB discards its shared library | |
6056 | list. See clear_solib for more information. */ | |
6057 | if (exec_bfd != NULL | |
6058 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6059 | return; | |
6060 | ||
876fa593 | 6061 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6062 | { |
2bdf28a0 | 6063 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6064 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6065 | |
0d381245 VP |
6066 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6067 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6068 | && solib->pspace == loc->pspace |
e2dd7057 | 6069 | && !loc->shlib_disabled |
508ccb1f TT |
6070 | && (b->type == bp_breakpoint |
6071 | || b->type == bp_jit_event | |
6072 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6073 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6074 | { |
e2dd7057 PP |
6075 | loc->shlib_disabled = 1; |
6076 | /* At this point, we cannot rely on remove_breakpoint | |
6077 | succeeding so we must mark the breakpoint as not inserted | |
6078 | to prevent future errors occurring in remove_breakpoints. */ | |
6079 | loc->inserted = 0; | |
8d3788bd VP |
6080 | |
6081 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6082 | observer_notify_breakpoint_modified (b); | |
6083 | ||
e2dd7057 PP |
6084 | if (!disabled_shlib_breaks) |
6085 | { | |
6086 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6087 | warning (_("Temporarily disabling breakpoints " |
6088 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6089 | solib->so_name); |
84acb35a | 6090 | } |
e2dd7057 | 6091 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6092 | } |
6093 | } | |
84acb35a JJ |
6094 | } |
6095 | ||
ce78b96d JB |
6096 | /* FORK & VFORK catchpoints. */ |
6097 | ||
e29a4733 PA |
6098 | /* An instance of this type is used to represent a fork or vfork |
6099 | catchpoint. It includes a "struct breakpoint" as a kind of base | |
6100 | class; users downcast to "struct breakpoint *" when needed. A | |
6101 | breakpoint is really of this type iff its ops pointer points to | |
6102 | CATCH_FORK_BREAKPOINT_OPS. */ | |
6103 | ||
6104 | struct fork_catchpoint | |
6105 | { | |
6106 | /* The base class. */ | |
6107 | struct breakpoint base; | |
6108 | ||
6109 | /* Process id of a child process whose forking triggered this | |
6110 | catchpoint. This field is only valid immediately after this | |
6111 | catchpoint has triggered. */ | |
6112 | ptid_t forked_inferior_pid; | |
6113 | }; | |
6114 | ||
4a64f543 MS |
6115 | /* Implement the "insert" breakpoint_ops method for fork |
6116 | catchpoints. */ | |
ce78b96d | 6117 | |
77b06cd7 TJB |
6118 | static int |
6119 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6120 | { |
77b06cd7 | 6121 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6122 | } |
6123 | ||
4a64f543 MS |
6124 | /* Implement the "remove" breakpoint_ops method for fork |
6125 | catchpoints. */ | |
ce78b96d JB |
6126 | |
6127 | static int | |
77b06cd7 | 6128 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6129 | { |
6130 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6131 | } | |
6132 | ||
6133 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6134 | catchpoints. */ | |
6135 | ||
6136 | static int | |
f1310107 TJB |
6137 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
6138 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6139 | { |
e29a4733 PA |
6140 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6141 | ||
6142 | return inferior_has_forked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6143 | } |
6144 | ||
4a64f543 MS |
6145 | /* Implement the "print_it" breakpoint_ops method for fork |
6146 | catchpoints. */ | |
ce78b96d JB |
6147 | |
6148 | static enum print_stop_action | |
348d480f | 6149 | print_it_catch_fork (bpstat bs) |
ce78b96d | 6150 | { |
348d480f PA |
6151 | struct breakpoint *b = bs->breakpoint_at; |
6152 | struct fork_catchpoint *c = (struct fork_catchpoint *) bs->breakpoint_at; | |
e29a4733 | 6153 | |
ce78b96d JB |
6154 | annotate_catchpoint (b->number); |
6155 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
e29a4733 | 6156 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6157 | return PRINT_SRC_AND_LOC; |
6158 | } | |
6159 | ||
4a64f543 MS |
6160 | /* Implement the "print_one" breakpoint_ops method for fork |
6161 | catchpoints. */ | |
ce78b96d JB |
6162 | |
6163 | static void | |
a6d9a66e | 6164 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6165 | { |
e29a4733 | 6166 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d TT |
6167 | struct value_print_options opts; |
6168 | ||
6169 | get_user_print_options (&opts); | |
6170 | ||
4a64f543 MS |
6171 | /* Field 4, the address, is omitted (which makes the columns not |
6172 | line up too nicely with the headers, but the effect is relatively | |
6173 | readable). */ | |
79a45b7d | 6174 | if (opts.addressprint) |
ce78b96d JB |
6175 | ui_out_field_skip (uiout, "addr"); |
6176 | annotate_field (5); | |
6177 | ui_out_text (uiout, "fork"); | |
e29a4733 | 6178 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6179 | { |
6180 | ui_out_text (uiout, ", process "); | |
6181 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6182 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6183 | ui_out_spaces (uiout, 1); |
6184 | } | |
6185 | } | |
6186 | ||
6187 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6188 | catchpoints. */ | |
6189 | ||
6190 | static void | |
6191 | print_mention_catch_fork (struct breakpoint *b) | |
6192 | { | |
6193 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6194 | } | |
6195 | ||
6149aea9 PA |
6196 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6197 | catchpoints. */ | |
6198 | ||
6199 | static void | |
6200 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6201 | { | |
6202 | fprintf_unfiltered (fp, "catch fork"); | |
d9b3f62e | 6203 | print_recreate_thread (b, fp); |
6149aea9 PA |
6204 | } |
6205 | ||
ce78b96d JB |
6206 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6207 | ||
2060206e | 6208 | static struct breakpoint_ops catch_fork_breakpoint_ops; |
ce78b96d | 6209 | |
4a64f543 MS |
6210 | /* Implement the "insert" breakpoint_ops method for vfork |
6211 | catchpoints. */ | |
ce78b96d | 6212 | |
77b06cd7 TJB |
6213 | static int |
6214 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6215 | { |
77b06cd7 | 6216 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6217 | } |
6218 | ||
4a64f543 MS |
6219 | /* Implement the "remove" breakpoint_ops method for vfork |
6220 | catchpoints. */ | |
ce78b96d JB |
6221 | |
6222 | static int | |
77b06cd7 | 6223 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6224 | { |
6225 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6226 | } | |
6227 | ||
6228 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6229 | catchpoints. */ | |
6230 | ||
6231 | static int | |
f1310107 TJB |
6232 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
6233 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6234 | { |
e29a4733 PA |
6235 | struct fork_catchpoint *c = (struct fork_catchpoint *) bl->owner; |
6236 | ||
6237 | return inferior_has_vforked (inferior_ptid, &c->forked_inferior_pid); | |
ce78b96d JB |
6238 | } |
6239 | ||
4a64f543 MS |
6240 | /* Implement the "print_it" breakpoint_ops method for vfork |
6241 | catchpoints. */ | |
ce78b96d JB |
6242 | |
6243 | static enum print_stop_action | |
348d480f | 6244 | print_it_catch_vfork (bpstat bs) |
ce78b96d | 6245 | { |
348d480f | 6246 | struct breakpoint *b = bs->breakpoint_at; |
e29a4733 PA |
6247 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
6248 | ||
ce78b96d JB |
6249 | annotate_catchpoint (b->number); |
6250 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
e29a4733 | 6251 | b->number, ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6252 | return PRINT_SRC_AND_LOC; |
6253 | } | |
6254 | ||
4a64f543 MS |
6255 | /* Implement the "print_one" breakpoint_ops method for vfork |
6256 | catchpoints. */ | |
ce78b96d JB |
6257 | |
6258 | static void | |
a6d9a66e | 6259 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6260 | { |
e29a4733 | 6261 | struct fork_catchpoint *c = (struct fork_catchpoint *) b; |
79a45b7d TT |
6262 | struct value_print_options opts; |
6263 | ||
6264 | get_user_print_options (&opts); | |
4a64f543 MS |
6265 | /* Field 4, the address, is omitted (which makes the columns not |
6266 | line up too nicely with the headers, but the effect is relatively | |
6267 | readable). */ | |
79a45b7d | 6268 | if (opts.addressprint) |
ce78b96d JB |
6269 | ui_out_field_skip (uiout, "addr"); |
6270 | annotate_field (5); | |
6271 | ui_out_text (uiout, "vfork"); | |
e29a4733 | 6272 | if (!ptid_equal (c->forked_inferior_pid, null_ptid)) |
ce78b96d JB |
6273 | { |
6274 | ui_out_text (uiout, ", process "); | |
6275 | ui_out_field_int (uiout, "what", | |
e29a4733 | 6276 | ptid_get_pid (c->forked_inferior_pid)); |
ce78b96d JB |
6277 | ui_out_spaces (uiout, 1); |
6278 | } | |
6279 | } | |
6280 | ||
6281 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6282 | catchpoints. */ | |
6283 | ||
6284 | static void | |
6285 | print_mention_catch_vfork (struct breakpoint *b) | |
6286 | { | |
6287 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6288 | } | |
6289 | ||
6149aea9 PA |
6290 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6291 | catchpoints. */ | |
6292 | ||
6293 | static void | |
6294 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6295 | { | |
6296 | fprintf_unfiltered (fp, "catch vfork"); | |
d9b3f62e | 6297 | print_recreate_thread (b, fp); |
6149aea9 PA |
6298 | } |
6299 | ||
ce78b96d JB |
6300 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6301 | ||
2060206e | 6302 | static struct breakpoint_ops catch_vfork_breakpoint_ops; |
ce78b96d | 6303 | |
be5c67c1 PA |
6304 | /* An instance of this type is used to represent a syscall catchpoint. |
6305 | It includes a "struct breakpoint" as a kind of base class; users | |
6306 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6307 | really of this type iff its ops pointer points to | |
6308 | CATCH_SYSCALL_BREAKPOINT_OPS. */ | |
6309 | ||
6310 | struct syscall_catchpoint | |
6311 | { | |
6312 | /* The base class. */ | |
6313 | struct breakpoint base; | |
6314 | ||
6315 | /* Syscall numbers used for the 'catch syscall' feature. If no | |
6316 | syscall has been specified for filtering, its value is NULL. | |
6317 | Otherwise, it holds a list of all syscalls to be caught. The | |
6318 | list elements are allocated with xmalloc. */ | |
6319 | VEC(int) *syscalls_to_be_caught; | |
6320 | }; | |
6321 | ||
6322 | /* Implement the "dtor" breakpoint_ops method for syscall | |
6323 | catchpoints. */ | |
6324 | ||
6325 | static void | |
6326 | dtor_catch_syscall (struct breakpoint *b) | |
6327 | { | |
6328 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; | |
6329 | ||
6330 | VEC_free (int, c->syscalls_to_be_caught); | |
348d480f | 6331 | |
2060206e | 6332 | base_breakpoint_ops.dtor (b); |
be5c67c1 PA |
6333 | } |
6334 | ||
a96d9b2e SDJ |
6335 | /* Implement the "insert" breakpoint_ops method for syscall |
6336 | catchpoints. */ | |
6337 | ||
77b06cd7 TJB |
6338 | static int |
6339 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e | 6340 | { |
be5c67c1 | 6341 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6342 | struct inferior *inf = current_inferior (); |
6343 | ||
6344 | ++inf->total_syscalls_count; | |
be5c67c1 | 6345 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6346 | ++inf->any_syscall_count; |
6347 | else | |
6348 | { | |
6349 | int i, iter; | |
cc59ec59 | 6350 | |
a96d9b2e | 6351 | for (i = 0; |
be5c67c1 | 6352 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6353 | i++) |
6354 | { | |
6355 | int elem; | |
cc59ec59 | 6356 | |
a96d9b2e SDJ |
6357 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6358 | { | |
6359 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6360 | uintptr_t vec_addr_offset |
6361 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6362 | uintptr_t vec_addr; |
6363 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6364 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6365 | vec_addr_offset; | |
6366 | memset ((void *) vec_addr, 0, | |
6367 | (iter + 1 - old_size) * sizeof (int)); | |
6368 | } | |
6369 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6370 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6371 | } | |
6372 | } | |
6373 | ||
77b06cd7 TJB |
6374 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6375 | inf->total_syscalls_count != 0, | |
6376 | inf->any_syscall_count, | |
6377 | VEC_length (int, inf->syscalls_counts), | |
6378 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6379 | } |
6380 | ||
6381 | /* Implement the "remove" breakpoint_ops method for syscall | |
6382 | catchpoints. */ | |
6383 | ||
6384 | static int | |
77b06cd7 | 6385 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e | 6386 | { |
be5c67c1 | 6387 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bl->owner; |
a96d9b2e SDJ |
6388 | struct inferior *inf = current_inferior (); |
6389 | ||
6390 | --inf->total_syscalls_count; | |
be5c67c1 | 6391 | if (!c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6392 | --inf->any_syscall_count; |
6393 | else | |
6394 | { | |
6395 | int i, iter; | |
cc59ec59 | 6396 | |
a96d9b2e | 6397 | for (i = 0; |
be5c67c1 | 6398 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6399 | i++) |
6400 | { | |
6401 | int elem; | |
6402 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6403 | /* Shouldn't happen. */ | |
6404 | continue; | |
6405 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6406 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6407 | } | |
6408 | } | |
6409 | ||
6410 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6411 | inf->total_syscalls_count != 0, | |
6412 | inf->any_syscall_count, | |
6413 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6414 | VEC_address (int, |
6415 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6416 | } |
6417 | ||
6418 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6419 | catchpoints. */ | |
6420 | ||
6421 | static int | |
f1310107 TJB |
6422 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
6423 | struct address_space *aspace, CORE_ADDR bp_addr) | |
a96d9b2e | 6424 | { |
4a64f543 MS |
6425 | /* We must check if we are catching specific syscalls in this |
6426 | breakpoint. If we are, then we must guarantee that the called | |
6427 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6428 | int syscall_number = 0; |
be5c67c1 PA |
6429 | const struct syscall_catchpoint *c |
6430 | = (const struct syscall_catchpoint *) bl->owner; | |
a96d9b2e SDJ |
6431 | |
6432 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6433 | return 0; | |
6434 | ||
6435 | /* Now, checking if the syscall is the same. */ | |
be5c67c1 | 6436 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6437 | { |
6438 | int i, iter; | |
cc59ec59 | 6439 | |
a96d9b2e | 6440 | for (i = 0; |
be5c67c1 | 6441 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6442 | i++) |
6443 | if (syscall_number == iter) | |
6444 | break; | |
6445 | /* Not the same. */ | |
6446 | if (!iter) | |
6447 | return 0; | |
6448 | } | |
6449 | ||
6450 | return 1; | |
6451 | } | |
6452 | ||
6453 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6454 | catchpoints. */ | |
6455 | ||
6456 | static enum print_stop_action | |
348d480f | 6457 | print_it_catch_syscall (bpstat bs) |
a96d9b2e | 6458 | { |
348d480f | 6459 | struct breakpoint *b = bs->breakpoint_at; |
a96d9b2e SDJ |
6460 | /* These are needed because we want to know in which state a |
6461 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6462 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6463 | must print "called syscall" or "returned from syscall". */ | |
6464 | ptid_t ptid; | |
6465 | struct target_waitstatus last; | |
6466 | struct syscall s; | |
6467 | struct cleanup *old_chain; | |
6468 | char *syscall_id; | |
6469 | ||
6470 | get_last_target_status (&ptid, &last); | |
6471 | ||
6472 | get_syscall_by_number (last.value.syscall_number, &s); | |
6473 | ||
6474 | annotate_catchpoint (b->number); | |
6475 | ||
6476 | if (s.name == NULL) | |
6477 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6478 | else | |
6479 | syscall_id = xstrprintf ("'%s'", s.name); | |
6480 | ||
6481 | old_chain = make_cleanup (xfree, syscall_id); | |
6482 | ||
6483 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6484 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6485 | b->number, syscall_id); | |
6486 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6487 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6488 | b->number, syscall_id); | |
6489 | ||
6490 | do_cleanups (old_chain); | |
6491 | ||
6492 | return PRINT_SRC_AND_LOC; | |
6493 | } | |
6494 | ||
6495 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6496 | catchpoints. */ | |
6497 | ||
6498 | static void | |
6499 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6500 | struct bp_location **last_loc) |
a96d9b2e | 6501 | { |
be5c67c1 | 6502 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
a96d9b2e SDJ |
6503 | struct value_print_options opts; |
6504 | ||
6505 | get_user_print_options (&opts); | |
4a64f543 MS |
6506 | /* Field 4, the address, is omitted (which makes the columns not |
6507 | line up too nicely with the headers, but the effect is relatively | |
6508 | readable). */ | |
a96d9b2e SDJ |
6509 | if (opts.addressprint) |
6510 | ui_out_field_skip (uiout, "addr"); | |
6511 | annotate_field (5); | |
6512 | ||
be5c67c1 PA |
6513 | if (c->syscalls_to_be_caught |
6514 | && VEC_length (int, c->syscalls_to_be_caught) > 1) | |
a96d9b2e SDJ |
6515 | ui_out_text (uiout, "syscalls \""); |
6516 | else | |
6517 | ui_out_text (uiout, "syscall \""); | |
6518 | ||
be5c67c1 | 6519 | if (c->syscalls_to_be_caught) |
a96d9b2e SDJ |
6520 | { |
6521 | int i, iter; | |
6522 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6523 | |
a96d9b2e | 6524 | for (i = 0; |
be5c67c1 | 6525 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6526 | i++) |
6527 | { | |
6528 | char *x = text; | |
6529 | struct syscall s; | |
6530 | get_syscall_by_number (iter, &s); | |
6531 | ||
6532 | if (s.name != NULL) | |
6533 | text = xstrprintf ("%s%s, ", text, s.name); | |
6534 | else | |
6535 | text = xstrprintf ("%s%d, ", text, iter); | |
6536 | ||
6537 | /* We have to xfree the last 'text' (now stored at 'x') | |
e5dd4106 | 6538 | because xstrprintf dynamically allocates new space for it |
a96d9b2e SDJ |
6539 | on every call. */ |
6540 | xfree (x); | |
6541 | } | |
6542 | /* Remove the last comma. */ | |
6543 | text[strlen (text) - 2] = '\0'; | |
6544 | ui_out_field_string (uiout, "what", text); | |
6545 | } | |
6546 | else | |
6547 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6548 | ui_out_text (uiout, "\" "); | |
6549 | } | |
6550 | ||
6551 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6552 | catchpoints. */ | |
6553 | ||
6554 | static void | |
6555 | print_mention_catch_syscall (struct breakpoint *b) | |
6556 | { | |
be5c67c1 PA |
6557 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6558 | ||
6559 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
6560 | { |
6561 | int i, iter; | |
6562 | ||
be5c67c1 | 6563 | if (VEC_length (int, c->syscalls_to_be_caught) > 1) |
a96d9b2e SDJ |
6564 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); |
6565 | else | |
6566 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6567 | ||
6568 | for (i = 0; | |
be5c67c1 | 6569 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6570 | i++) |
6571 | { | |
6572 | struct syscall s; | |
6573 | get_syscall_by_number (iter, &s); | |
6574 | ||
6575 | if (s.name) | |
6576 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6577 | else | |
6578 | printf_filtered (" %d", s.number); | |
6579 | } | |
6580 | printf_filtered (")"); | |
6581 | } | |
6582 | else | |
6583 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6584 | b->number); | |
6585 | } | |
6586 | ||
6149aea9 PA |
6587 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6588 | catchpoints. */ | |
6589 | ||
6590 | static void | |
6591 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6592 | { | |
be5c67c1 PA |
6593 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) b; |
6594 | ||
6149aea9 PA |
6595 | fprintf_unfiltered (fp, "catch syscall"); |
6596 | ||
be5c67c1 | 6597 | if (c->syscalls_to_be_caught) |
6149aea9 PA |
6598 | { |
6599 | int i, iter; | |
6600 | ||
6601 | for (i = 0; | |
be5c67c1 | 6602 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
6149aea9 PA |
6603 | i++) |
6604 | { | |
6605 | struct syscall s; | |
6606 | ||
6607 | get_syscall_by_number (iter, &s); | |
6608 | if (s.name) | |
6609 | fprintf_unfiltered (fp, " %s", s.name); | |
6610 | else | |
6611 | fprintf_unfiltered (fp, " %d", s.number); | |
6612 | } | |
6613 | } | |
d9b3f62e | 6614 | print_recreate_thread (b, fp); |
6149aea9 PA |
6615 | } |
6616 | ||
a96d9b2e SDJ |
6617 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6618 | ||
2060206e | 6619 | static struct breakpoint_ops catch_syscall_breakpoint_ops; |
a96d9b2e SDJ |
6620 | |
6621 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6622 | ||
6623 | static int | |
6624 | syscall_catchpoint_p (struct breakpoint *b) | |
6625 | { | |
6626 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6627 | } | |
6628 | ||
346774a9 PA |
6629 | /* Initialize a new breakpoint of the bp_catchpoint kind. If TEMPFLAG |
6630 | is non-zero, then make the breakpoint temporary. If COND_STRING is | |
6631 | not NULL, then store it in the breakpoint. OPS, if not NULL, is | |
6632 | the breakpoint_ops structure associated to the catchpoint. */ | |
ce78b96d | 6633 | |
346774a9 PA |
6634 | static void |
6635 | init_catchpoint (struct breakpoint *b, | |
6636 | struct gdbarch *gdbarch, int tempflag, | |
6637 | char *cond_string, | |
c0a91b2b | 6638 | const struct breakpoint_ops *ops) |
c906108c | 6639 | { |
c5aa993b | 6640 | struct symtab_and_line sal; |
346774a9 | 6641 | |
fe39c653 | 6642 | init_sal (&sal); |
6c95b8df | 6643 | sal.pspace = current_program_space; |
c5aa993b | 6644 | |
28010a5d | 6645 | init_raw_breakpoint (b, gdbarch, sal, bp_catchpoint, ops); |
ce78b96d | 6646 | |
1b36a34b | 6647 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
b5de0fa7 | 6648 | b->disposition = tempflag ? disp_del : disp_donttouch; |
346774a9 PA |
6649 | } |
6650 | ||
28010a5d | 6651 | void |
3a5c3e22 | 6652 | install_breakpoint (int internal, struct breakpoint *b) |
c56053d2 PA |
6653 | { |
6654 | add_to_breakpoint_chain (b); | |
3a5c3e22 PA |
6655 | set_breakpoint_number (internal, b); |
6656 | if (!internal) | |
6657 | mention (b); | |
c56053d2 PA |
6658 | observer_notify_breakpoint_created (b); |
6659 | update_global_location_list (1); | |
6660 | } | |
6661 | ||
9b70b993 | 6662 | static void |
a6d9a66e UW |
6663 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6664 | int tempflag, char *cond_string, | |
c0a91b2b | 6665 | const struct breakpoint_ops *ops) |
c906108c | 6666 | { |
e29a4733 | 6667 | struct fork_catchpoint *c = XNEW (struct fork_catchpoint); |
ce78b96d | 6668 | |
e29a4733 PA |
6669 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, ops); |
6670 | ||
6671 | c->forked_inferior_pid = null_ptid; | |
6672 | ||
3a5c3e22 | 6673 | install_breakpoint (0, &c->base); |
c906108c SS |
6674 | } |
6675 | ||
fe798b75 JB |
6676 | /* Exec catchpoints. */ |
6677 | ||
b4d90040 PA |
6678 | /* An instance of this type is used to represent an exec catchpoint. |
6679 | It includes a "struct breakpoint" as a kind of base class; users | |
6680 | downcast to "struct breakpoint *" when needed. A breakpoint is | |
6681 | really of this type iff its ops pointer points to | |
6682 | CATCH_EXEC_BREAKPOINT_OPS. */ | |
6683 | ||
6684 | struct exec_catchpoint | |
6685 | { | |
6686 | /* The base class. */ | |
6687 | struct breakpoint base; | |
6688 | ||
6689 | /* Filename of a program whose exec triggered this catchpoint. | |
6690 | This field is only valid immediately after this catchpoint has | |
6691 | triggered. */ | |
6692 | char *exec_pathname; | |
6693 | }; | |
6694 | ||
6695 | /* Implement the "dtor" breakpoint_ops method for exec | |
6696 | catchpoints. */ | |
6697 | ||
6698 | static void | |
6699 | dtor_catch_exec (struct breakpoint *b) | |
6700 | { | |
6701 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; | |
6702 | ||
6703 | xfree (c->exec_pathname); | |
348d480f | 6704 | |
2060206e | 6705 | base_breakpoint_ops.dtor (b); |
b4d90040 PA |
6706 | } |
6707 | ||
77b06cd7 TJB |
6708 | static int |
6709 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6710 | { |
77b06cd7 | 6711 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6712 | } |
c906108c | 6713 | |
fe798b75 | 6714 | static int |
77b06cd7 | 6715 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6716 | { |
6717 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6718 | } | |
c906108c | 6719 | |
fe798b75 | 6720 | static int |
f1310107 TJB |
6721 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
6722 | struct address_space *aspace, CORE_ADDR bp_addr) | |
fe798b75 | 6723 | { |
b4d90040 PA |
6724 | struct exec_catchpoint *c = (struct exec_catchpoint *) bl->owner; |
6725 | ||
6726 | return inferior_has_execd (inferior_ptid, &c->exec_pathname); | |
fe798b75 | 6727 | } |
c906108c | 6728 | |
fe798b75 | 6729 | static enum print_stop_action |
348d480f | 6730 | print_it_catch_exec (bpstat bs) |
fe798b75 | 6731 | { |
348d480f | 6732 | struct breakpoint *b = bs->breakpoint_at; |
b4d90040 PA |
6733 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
6734 | ||
fe798b75 JB |
6735 | annotate_catchpoint (b->number); |
6736 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
b4d90040 | 6737 | c->exec_pathname); |
fe798b75 | 6738 | return PRINT_SRC_AND_LOC; |
c906108c SS |
6739 | } |
6740 | ||
fe798b75 | 6741 | static void |
a6d9a66e | 6742 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 | 6743 | { |
b4d90040 | 6744 | struct exec_catchpoint *c = (struct exec_catchpoint *) b; |
fe798b75 JB |
6745 | struct value_print_options opts; |
6746 | ||
6747 | get_user_print_options (&opts); | |
6748 | ||
6749 | /* Field 4, the address, is omitted (which makes the columns | |
6750 | not line up too nicely with the headers, but the effect | |
6751 | is relatively readable). */ | |
6752 | if (opts.addressprint) | |
6753 | ui_out_field_skip (uiout, "addr"); | |
6754 | annotate_field (5); | |
6755 | ui_out_text (uiout, "exec"); | |
b4d90040 | 6756 | if (c->exec_pathname != NULL) |
fe798b75 JB |
6757 | { |
6758 | ui_out_text (uiout, ", program \""); | |
b4d90040 | 6759 | ui_out_field_string (uiout, "what", c->exec_pathname); |
fe798b75 JB |
6760 | ui_out_text (uiout, "\" "); |
6761 | } | |
6762 | } | |
6763 | ||
6764 | static void | |
6765 | print_mention_catch_exec (struct breakpoint *b) | |
6766 | { | |
6767 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6768 | } | |
6769 | ||
6149aea9 PA |
6770 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6771 | catchpoints. */ | |
6772 | ||
6773 | static void | |
6774 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6775 | { | |
6776 | fprintf_unfiltered (fp, "catch exec"); | |
d9b3f62e | 6777 | print_recreate_thread (b, fp); |
6149aea9 PA |
6778 | } |
6779 | ||
2060206e | 6780 | static struct breakpoint_ops catch_exec_breakpoint_ops; |
fe798b75 | 6781 | |
a96d9b2e SDJ |
6782 | static void |
6783 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
c0a91b2b | 6784 | const struct breakpoint_ops *ops) |
a96d9b2e | 6785 | { |
be5c67c1 | 6786 | struct syscall_catchpoint *c; |
a96d9b2e | 6787 | struct gdbarch *gdbarch = get_current_arch (); |
a96d9b2e | 6788 | |
be5c67c1 PA |
6789 | c = XNEW (struct syscall_catchpoint); |
6790 | init_catchpoint (&c->base, gdbarch, tempflag, NULL, ops); | |
6791 | c->syscalls_to_be_caught = filter; | |
a96d9b2e | 6792 | |
3a5c3e22 | 6793 | install_breakpoint (0, &c->base); |
a96d9b2e SDJ |
6794 | } |
6795 | ||
c906108c | 6796 | static int |
fba45db2 | 6797 | hw_breakpoint_used_count (void) |
c906108c | 6798 | { |
c906108c | 6799 | int i = 0; |
f1310107 TJB |
6800 | struct breakpoint *b; |
6801 | struct bp_location *bl; | |
c906108c SS |
6802 | |
6803 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6804 | { |
d6b74ac4 | 6805 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
6806 | for (bl = b->loc; bl; bl = bl->next) |
6807 | { | |
6808 | /* Special types of hardware breakpoints may use more than | |
6809 | one register. */ | |
348d480f | 6810 | i += b->ops->resources_needed (bl); |
f1310107 | 6811 | } |
c5aa993b | 6812 | } |
c906108c SS |
6813 | |
6814 | return i; | |
6815 | } | |
6816 | ||
6817 | static int | |
fba45db2 | 6818 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6819 | { |
c906108c | 6820 | int i = 0; |
e09342b5 TJB |
6821 | struct breakpoint *b; |
6822 | struct bp_location *bl; | |
c906108c SS |
6823 | |
6824 | *other_type_used = 0; | |
6825 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6826 | { |
6827 | if (!breakpoint_enabled (b)) | |
6828 | continue; | |
6829 | ||
c5aa993b | 6830 | if (b->type == type) |
e09342b5 TJB |
6831 | for (bl = b->loc; bl; bl = bl->next) |
6832 | { | |
6833 | /* Special types of hardware watchpoints may use more than | |
6834 | one register. */ | |
348d480f | 6835 | i += b->ops->resources_needed (bl); |
e09342b5 | 6836 | } |
cc60f2e3 | 6837 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6838 | *other_type_used = 1; |
e09342b5 TJB |
6839 | } |
6840 | ||
c906108c SS |
6841 | return i; |
6842 | } | |
6843 | ||
c906108c | 6844 | void |
fba45db2 | 6845 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6846 | { |
c5aa993b | 6847 | struct breakpoint *b; |
c906108c SS |
6848 | |
6849 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6850 | { |
cc60f2e3 | 6851 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6852 | { |
b5de0fa7 | 6853 | b->enable_state = bp_call_disabled; |
b60e7edf | 6854 | update_global_location_list (0); |
c5aa993b JM |
6855 | } |
6856 | } | |
c906108c SS |
6857 | } |
6858 | ||
6859 | void | |
fba45db2 | 6860 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6861 | { |
c5aa993b | 6862 | struct breakpoint *b; |
c906108c SS |
6863 | |
6864 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6865 | { |
cc60f2e3 | 6866 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6867 | { |
b5de0fa7 | 6868 | b->enable_state = bp_enabled; |
b60e7edf | 6869 | update_global_location_list (1); |
c5aa993b JM |
6870 | } |
6871 | } | |
c906108c SS |
6872 | } |
6873 | ||
8bea4e01 UW |
6874 | void |
6875 | disable_breakpoints_before_startup (void) | |
6876 | { | |
6877 | struct breakpoint *b; | |
6878 | int found = 0; | |
6879 | ||
6880 | ALL_BREAKPOINTS (b) | |
6881 | { | |
6c95b8df PA |
6882 | if (b->pspace != current_program_space) |
6883 | continue; | |
6884 | ||
8bea4e01 UW |
6885 | if ((b->type == bp_breakpoint |
6886 | || b->type == bp_hardware_breakpoint) | |
6887 | && breakpoint_enabled (b)) | |
6888 | { | |
6889 | b->enable_state = bp_startup_disabled; | |
6890 | found = 1; | |
6891 | } | |
6892 | } | |
6893 | ||
6894 | if (found) | |
6895 | update_global_location_list (0); | |
6896 | ||
6c95b8df | 6897 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6898 | } |
6899 | ||
6900 | void | |
6901 | enable_breakpoints_after_startup (void) | |
6902 | { | |
6903 | struct breakpoint *b; | |
6904 | int found = 0; | |
6905 | ||
6c95b8df | 6906 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6907 | |
6908 | ALL_BREAKPOINTS (b) | |
6909 | { | |
6c95b8df PA |
6910 | if (b->pspace != current_program_space) |
6911 | continue; | |
6912 | ||
8bea4e01 UW |
6913 | if ((b->type == bp_breakpoint |
6914 | || b->type == bp_hardware_breakpoint) | |
6915 | && b->enable_state == bp_startup_disabled) | |
6916 | { | |
6917 | b->enable_state = bp_enabled; | |
6918 | found = 1; | |
6919 | } | |
6920 | } | |
6921 | ||
6922 | if (found) | |
6923 | breakpoint_re_set (); | |
6924 | } | |
6925 | ||
c906108c SS |
6926 | |
6927 | /* Set a breakpoint that will evaporate an end of command | |
6928 | at address specified by SAL. | |
6929 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6930 | ||
6931 | struct breakpoint * | |
a6d9a66e UW |
6932 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6933 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6934 | { |
52f0bd74 | 6935 | struct breakpoint *b; |
edb3359d DJ |
6936 | |
6937 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6938 | one. */ | |
6939 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6940 | ||
06edf0c0 | 6941 | b = set_raw_breakpoint (gdbarch, sal, type, &momentary_breakpoint_ops); |
b5de0fa7 EZ |
6942 | b->enable_state = bp_enabled; |
6943 | b->disposition = disp_donttouch; | |
818dd999 | 6944 | b->frame_id = frame_id; |
c906108c | 6945 | |
4a64f543 MS |
6946 | /* If we're debugging a multi-threaded program, then we want |
6947 | momentary breakpoints to be active in only a single thread of | |
6948 | control. */ | |
39f77062 KB |
6949 | if (in_thread_list (inferior_ptid)) |
6950 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6951 | |
b60e7edf | 6952 | update_global_location_list_nothrow (1); |
74960c60 | 6953 | |
c906108c SS |
6954 | return b; |
6955 | } | |
611c83ae | 6956 | |
06edf0c0 PA |
6957 | /* Make a momentary breakpoint based on the master breakpoint ORIG. |
6958 | The new breakpoint will have type TYPE, and use OPS as it | |
6959 | breakpoint_ops. */ | |
e58b0e63 | 6960 | |
06edf0c0 PA |
6961 | static struct breakpoint * |
6962 | momentary_breakpoint_from_master (struct breakpoint *orig, | |
6963 | enum bptype type, | |
c0a91b2b | 6964 | const struct breakpoint_ops *ops) |
e58b0e63 PA |
6965 | { |
6966 | struct breakpoint *copy; | |
6967 | ||
06edf0c0 | 6968 | copy = set_raw_breakpoint_without_location (orig->gdbarch, type, ops); |
e58b0e63 | 6969 | copy->loc = allocate_bp_location (copy); |
0e30163f | 6970 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 6971 | |
a6d9a66e | 6972 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6973 | copy->loc->requested_address = orig->loc->requested_address; |
6974 | copy->loc->address = orig->loc->address; | |
6975 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6976 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6977 | |
6978 | if (orig->source_file == NULL) | |
6979 | copy->source_file = NULL; | |
6980 | else | |
6981 | copy->source_file = xstrdup (orig->source_file); | |
6982 | ||
6983 | copy->line_number = orig->line_number; | |
6984 | copy->frame_id = orig->frame_id; | |
6985 | copy->thread = orig->thread; | |
6c95b8df | 6986 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6987 | |
6988 | copy->enable_state = bp_enabled; | |
6989 | copy->disposition = disp_donttouch; | |
6990 | copy->number = internal_breakpoint_number--; | |
6991 | ||
6992 | update_global_location_list_nothrow (0); | |
6993 | return copy; | |
6994 | } | |
6995 | ||
06edf0c0 PA |
6996 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6997 | ORIG is NULL. */ | |
6998 | ||
6999 | struct breakpoint * | |
7000 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7001 | { | |
7002 | /* If there's nothing to clone, then return nothing. */ | |
7003 | if (orig == NULL) | |
7004 | return NULL; | |
7005 | ||
7006 | return momentary_breakpoint_from_master (orig, orig->type, orig->ops); | |
7007 | } | |
7008 | ||
611c83ae | 7009 | struct breakpoint * |
a6d9a66e UW |
7010 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7011 | enum bptype type) | |
611c83ae PA |
7012 | { |
7013 | struct symtab_and_line sal; | |
7014 | ||
7015 | sal = find_pc_line (pc, 0); | |
7016 | sal.pc = pc; | |
7017 | sal.section = find_pc_overlay (pc); | |
7018 | sal.explicit_pc = 1; | |
7019 | ||
a6d9a66e | 7020 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7021 | } |
c906108c | 7022 | \f |
c5aa993b | 7023 | |
c906108c SS |
7024 | /* Tell the user we have just set a breakpoint B. */ |
7025 | ||
7026 | static void | |
fba45db2 | 7027 | mention (struct breakpoint *b) |
c906108c | 7028 | { |
348d480f | 7029 | b->ops->print_mention (b); |
9dc5e2a9 | 7030 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7031 | return; |
c906108c SS |
7032 | printf_filtered ("\n"); |
7033 | } | |
c906108c | 7034 | \f |
c5aa993b | 7035 | |
0d381245 | 7036 | static struct bp_location * |
39d61571 | 7037 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7038 | const struct symtab_and_line *sal) |
7039 | { | |
7040 | struct bp_location *loc, **tmp; | |
7041 | ||
39d61571 | 7042 | loc = allocate_bp_location (b); |
0d381245 VP |
7043 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7044 | ; | |
7045 | *tmp = loc; | |
a6d9a66e UW |
7046 | loc->gdbarch = get_sal_arch (*sal); |
7047 | if (!loc->gdbarch) | |
7048 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7049 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7050 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7051 | loc->requested_address, b->type); | |
6c95b8df PA |
7052 | loc->pspace = sal->pspace; |
7053 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7054 | loc->section = sal->section; |
7055 | ||
0e30163f JK |
7056 | set_breakpoint_location_function (loc, |
7057 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7058 | return loc; |
7059 | } | |
514f746b AR |
7060 | \f |
7061 | ||
7062 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7063 | return 0 otherwise. */ | |
7064 | ||
7065 | static int | |
7066 | bp_loc_is_permanent (struct bp_location *loc) | |
7067 | { | |
7068 | int len; | |
7069 | CORE_ADDR addr; | |
7070 | const gdb_byte *brk; | |
7071 | gdb_byte *target_mem; | |
939c61fa JK |
7072 | struct cleanup *cleanup; |
7073 | int retval = 0; | |
514f746b AR |
7074 | |
7075 | gdb_assert (loc != NULL); | |
7076 | ||
7077 | addr = loc->address; | |
a6d9a66e | 7078 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7079 | |
939c61fa JK |
7080 | /* Software breakpoints unsupported? */ |
7081 | if (brk == NULL) | |
7082 | return 0; | |
7083 | ||
514f746b AR |
7084 | target_mem = alloca (len); |
7085 | ||
939c61fa JK |
7086 | /* Enable the automatic memory restoration from breakpoints while |
7087 | we read the memory. Otherwise we could say about our temporary | |
7088 | breakpoints they are permanent. */ | |
6c95b8df PA |
7089 | cleanup = save_current_space_and_thread (); |
7090 | ||
7091 | switch_to_program_space_and_thread (loc->pspace); | |
7092 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7093 | |
514f746b AR |
7094 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7095 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7096 | retval = 1; |
514f746b | 7097 | |
939c61fa JK |
7098 | do_cleanups (cleanup); |
7099 | ||
7100 | return retval; | |
514f746b AR |
7101 | } |
7102 | ||
7103 | ||
c3f6f71d | 7104 | |
018d34a4 VP |
7105 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7106 | as textual description of the location, and COND_STRING | |
db107f19 | 7107 | as condition expression. */ |
018d34a4 VP |
7108 | |
7109 | static void | |
d9b3f62e PA |
7110 | init_breakpoint_sal (struct breakpoint *b, struct gdbarch *gdbarch, |
7111 | struct symtabs_and_lines sals, char *addr_string, | |
7112 | char *cond_string, | |
7113 | enum bptype type, enum bpdisp disposition, | |
7114 | int thread, int task, int ignore_count, | |
c0a91b2b | 7115 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e | 7116 | int enabled, int internal, int display_canonical) |
018d34a4 | 7117 | { |
0d381245 | 7118 | int i; |
018d34a4 VP |
7119 | |
7120 | if (type == bp_hardware_breakpoint) | |
7121 | { | |
7122 | int i = hw_breakpoint_used_count (); | |
7123 | int target_resources_ok = | |
d92524f1 | 7124 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7125 | i + 1, 0); |
7126 | if (target_resources_ok == 0) | |
7127 | error (_("No hardware breakpoint support in the target.")); | |
7128 | else if (target_resources_ok < 0) | |
7129 | error (_("Hardware breakpoints used exceeds limit.")); | |
7130 | } | |
7131 | ||
6c95b8df PA |
7132 | gdb_assert (sals.nelts > 0); |
7133 | ||
0d381245 VP |
7134 | for (i = 0; i < sals.nelts; ++i) |
7135 | { | |
7136 | struct symtab_and_line sal = sals.sals[i]; | |
7137 | struct bp_location *loc; | |
7138 | ||
7139 | if (from_tty) | |
5af949e3 UW |
7140 | { |
7141 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7142 | if (!loc_gdbarch) | |
7143 | loc_gdbarch = gdbarch; | |
7144 | ||
7145 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7146 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7147 | } |
0d381245 VP |
7148 | |
7149 | if (i == 0) | |
7150 | { | |
d9b3f62e | 7151 | init_raw_breakpoint (b, gdbarch, sal, type, ops); |
0d381245 | 7152 | b->thread = thread; |
4a306c9a | 7153 | b->task = task; |
018d34a4 | 7154 | |
0d381245 VP |
7155 | b->cond_string = cond_string; |
7156 | b->ignore_count = ignore_count; | |
41447f92 | 7157 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7158 | b->disposition = disposition; |
6c95b8df PA |
7159 | b->pspace = sals.sals[0].pspace; |
7160 | ||
0fb4aa4b PA |
7161 | if (type == bp_static_tracepoint) |
7162 | { | |
d9b3f62e | 7163 | struct tracepoint *t = (struct tracepoint *) b; |
0fb4aa4b PA |
7164 | struct static_tracepoint_marker marker; |
7165 | ||
7166 | if (is_marker_spec (addr_string)) | |
7167 | { | |
7168 | /* We already know the marker exists, otherwise, we | |
7169 | wouldn't see a sal for it. */ | |
7170 | char *p = &addr_string[3]; | |
7171 | char *endp; | |
7172 | char *marker_str; | |
7173 | int i; | |
7174 | ||
e9cafbcc | 7175 | p = skip_spaces (p); |
0fb4aa4b | 7176 | |
e9cafbcc | 7177 | endp = skip_to_space (p); |
0fb4aa4b PA |
7178 | |
7179 | marker_str = savestring (p, endp - p); | |
d9b3f62e | 7180 | t->static_trace_marker_id = marker_str; |
0fb4aa4b | 7181 | |
3e43a32a MS |
7182 | printf_filtered (_("Probed static tracepoint " |
7183 | "marker \"%s\"\n"), | |
d9b3f62e | 7184 | t->static_trace_marker_id); |
0fb4aa4b PA |
7185 | } |
7186 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7187 | { | |
d9b3f62e | 7188 | t->static_trace_marker_id = xstrdup (marker.str_id); |
0fb4aa4b PA |
7189 | release_static_tracepoint_marker (&marker); |
7190 | ||
3e43a32a MS |
7191 | printf_filtered (_("Probed static tracepoint " |
7192 | "marker \"%s\"\n"), | |
d9b3f62e | 7193 | t->static_trace_marker_id); |
0fb4aa4b PA |
7194 | } |
7195 | else | |
3e43a32a MS |
7196 | warning (_("Couldn't determine the static " |
7197 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7198 | } |
7199 | ||
6c95b8df | 7200 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7201 | && (b->type == bp_breakpoint |
7202 | || b->type == bp_hardware_breakpoint)) | |
7203 | b->enable_state = bp_startup_disabled; | |
7204 | ||
0d381245 VP |
7205 | loc = b->loc; |
7206 | } | |
7207 | else | |
018d34a4 | 7208 | { |
39d61571 | 7209 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7210 | } |
7211 | ||
514f746b AR |
7212 | if (bp_loc_is_permanent (loc)) |
7213 | make_breakpoint_permanent (b); | |
7214 | ||
0d381245 VP |
7215 | if (b->cond_string) |
7216 | { | |
7217 | char *arg = b->cond_string; | |
d32a6982 | 7218 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7219 | if (*arg) |
db107f19 | 7220 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7221 | } |
0d381245 | 7222 | } |
018d34a4 | 7223 | |
56435ebe | 7224 | b->display_canonical = display_canonical; |
018d34a4 VP |
7225 | if (addr_string) |
7226 | b->addr_string = addr_string; | |
7227 | else | |
7228 | /* addr_string has to be used or breakpoint_re_set will delete | |
7229 | me. */ | |
5af949e3 UW |
7230 | b->addr_string |
7231 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
d9b3f62e | 7232 | } |
018d34a4 | 7233 | |
d9b3f62e PA |
7234 | static void |
7235 | create_breakpoint_sal (struct gdbarch *gdbarch, | |
7236 | struct symtabs_and_lines sals, char *addr_string, | |
7237 | char *cond_string, | |
7238 | enum bptype type, enum bpdisp disposition, | |
7239 | int thread, int task, int ignore_count, | |
c0a91b2b | 7240 | const struct breakpoint_ops *ops, int from_tty, |
d9b3f62e PA |
7241 | int enabled, int internal, int display_canonical) |
7242 | { | |
7243 | struct breakpoint *b; | |
7244 | struct cleanup *old_chain; | |
7245 | ||
7246 | if (is_tracepoint_type (type)) | |
7247 | { | |
7248 | struct tracepoint *t; | |
7249 | ||
7250 | t = XCNEW (struct tracepoint); | |
7251 | b = &t->base; | |
7252 | } | |
7253 | else | |
7254 | b = XNEW (struct breakpoint); | |
7255 | ||
7256 | old_chain = make_cleanup (xfree, b); | |
7257 | ||
7258 | init_breakpoint_sal (b, gdbarch, | |
7259 | sals, addr_string, | |
7260 | cond_string, | |
7261 | type, disposition, | |
7262 | thread, task, ignore_count, | |
7263 | ops, from_tty, | |
7264 | enabled, internal, display_canonical); | |
7265 | discard_cleanups (old_chain); | |
7266 | ||
7267 | install_breakpoint (internal, b); | |
018d34a4 VP |
7268 | } |
7269 | ||
ed0616c6 VP |
7270 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7271 | elements to fill the void space. */ | |
2c0b251b PA |
7272 | static void |
7273 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7274 | { |
7275 | int i = index_to_remove+1; | |
7276 | int last_index = sal->nelts-1; | |
7277 | ||
7278 | for (;i <= last_index; ++i) | |
7279 | sal->sals[i-1] = sal->sals[i]; | |
7280 | ||
7281 | --(sal->nelts); | |
7282 | } | |
7283 | ||
6c95b8df PA |
7284 | /* If appropriate, obtains all sals that correspond to the same file |
7285 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7286 | will want to set a breakpoint at foo.c:line, and not really care | |
7287 | about program spaces. This is done only if SAL does not have | |
7288 | explicit PC and has line and file information. If we got just a | |
7289 | single expanded sal, return the original. | |
ed0616c6 | 7290 | |
6c95b8df PA |
7291 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7292 | which the name of enclosing function is different from SAL. This | |
7293 | makes sure that if we have breakpoint originally set in template | |
7294 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7295 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7296 | |
2c0b251b | 7297 | static struct symtabs_and_lines |
ed0616c6 VP |
7298 | expand_line_sal_maybe (struct symtab_and_line sal) |
7299 | { | |
7300 | struct symtabs_and_lines expanded; | |
7301 | CORE_ADDR original_pc = sal.pc; | |
7302 | char *original_function = NULL; | |
7303 | int found; | |
7304 | int i; | |
6c95b8df | 7305 | struct cleanup *old_chain; |
ed0616c6 VP |
7306 | |
7307 | /* If we have explicit pc, don't expand. | |
7308 | If we have no line number, we can't expand. */ | |
7309 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7310 | { | |
7311 | expanded.nelts = 1; | |
7312 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7313 | expanded.sals[0] = sal; | |
7314 | return expanded; | |
7315 | } | |
7316 | ||
7317 | sal.pc = 0; | |
6c95b8df PA |
7318 | |
7319 | old_chain = save_current_space_and_thread (); | |
7320 | ||
7321 | switch_to_program_space_and_thread (sal.pspace); | |
7322 | ||
ed0616c6 | 7323 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7324 | |
7325 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7326 | expanded = expand_line_sal (sal); |
6c95b8df | 7327 | |
ed0616c6 VP |
7328 | if (expanded.nelts == 1) |
7329 | { | |
3dba1c98 JB |
7330 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7331 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7332 | xfree (expanded.sals); |
7333 | expanded.nelts = 1; | |
7334 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7335 | sal.pc = original_pc; | |
7336 | expanded.sals[0] = sal; | |
3dba1c98 | 7337 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7338 | do_cleanups (old_chain); |
ed0616c6 VP |
7339 | return expanded; |
7340 | } | |
7341 | ||
7342 | if (!sal.explicit_line) | |
7343 | { | |
7344 | CORE_ADDR func_addr, func_end; | |
7345 | for (i = 0; i < expanded.nelts; ++i) | |
7346 | { | |
7347 | CORE_ADDR pc = expanded.sals[i].pc; | |
7348 | char *this_function; | |
6c95b8df PA |
7349 | |
7350 | /* We need to switch threads as well since we're about to | |
7351 | read memory. */ | |
7352 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7353 | ||
ed0616c6 VP |
7354 | if (find_pc_partial_function (pc, &this_function, |
7355 | &func_addr, &func_end)) | |
7356 | { | |
059fb39f PM |
7357 | if (this_function |
7358 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7359 | { |
7360 | remove_sal (&expanded, i); | |
7361 | --i; | |
7362 | } | |
ed0616c6 VP |
7363 | } |
7364 | } | |
7365 | } | |
059acae7 UW |
7366 | |
7367 | /* Skip the function prologue if necessary. */ | |
7368 | for (i = 0; i < expanded.nelts; ++i) | |
7369 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7370 | |
6c95b8df PA |
7371 | do_cleanups (old_chain); |
7372 | ||
ed0616c6 VP |
7373 | if (expanded.nelts <= 1) |
7374 | { | |
e5dd4106 | 7375 | /* This is an ugly workaround. If we get zero expanded sals |
4a64f543 MS |
7376 | then something is really wrong. Fix that by returning the |
7377 | original sal. */ | |
7378 | ||
ed0616c6 VP |
7379 | xfree (expanded.sals); |
7380 | expanded.nelts = 1; | |
7381 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7382 | sal.pc = original_pc; | |
7383 | expanded.sals[0] = sal; | |
7384 | return expanded; | |
7385 | } | |
7386 | ||
7387 | if (original_pc) | |
7388 | { | |
7389 | found = 0; | |
7390 | for (i = 0; i < expanded.nelts; ++i) | |
7391 | if (expanded.sals[i].pc == original_pc) | |
7392 | { | |
7393 | found = 1; | |
7394 | break; | |
7395 | } | |
7396 | gdb_assert (found); | |
7397 | } | |
7398 | ||
7399 | return expanded; | |
7400 | } | |
7401 | ||
018d34a4 VP |
7402 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7403 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7404 | value. COND_STRING, if not NULL, specified the condition to be | |
7405 | used for all breakpoints. Essentially the only case where | |
7406 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7407 | function. In that case, it's still not possible to specify | |
7408 | separate conditions for different overloaded functions, so | |
7409 | we take just a single condition string. | |
7410 | ||
c3f6f71d | 7411 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7412 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7413 | array contents). If the function fails (error() is called), the |
7414 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7415 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7416 | |
7417 | static void | |
8cdf0e15 | 7418 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7419 | struct symtabs_and_lines sals, |
7420 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7421 | char *cond_string, |
7422 | enum bptype type, enum bpdisp disposition, | |
7423 | int thread, int task, int ignore_count, | |
c0a91b2b | 7424 | const struct breakpoint_ops *ops, int from_tty, |
84f4c1fe | 7425 | int enabled, int internal) |
c906108c | 7426 | { |
018d34a4 | 7427 | int i; |
cc59ec59 | 7428 | |
018d34a4 | 7429 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7430 | { |
ed0616c6 VP |
7431 | struct symtabs_and_lines expanded = |
7432 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7433 | |
7efd8fc2 | 7434 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7435 | cond_string, type, disposition, |
84f4c1fe | 7436 | thread, task, ignore_count, ops, |
56435ebe TT |
7437 | from_tty, enabled, internal, |
7438 | canonical->special_display); | |
c3f6f71d | 7439 | } |
c3f6f71d | 7440 | } |
c906108c | 7441 | |
9998af43 | 7442 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7443 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7444 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7445 | address strings. ADDRESS points to the end of the SAL. |
7446 | ||
7447 | The array and the line spec strings are allocated on the heap, it is | |
7448 | the caller's responsibility to free them. */ | |
c906108c | 7449 | |
b9362cc7 | 7450 | static void |
c3f6f71d JM |
7451 | parse_breakpoint_sals (char **address, |
7452 | struct symtabs_and_lines *sals, | |
58438ac1 | 7453 | struct linespec_result *canonical) |
c3f6f71d JM |
7454 | { |
7455 | char *addr_start = *address; | |
cc59ec59 | 7456 | |
c3f6f71d | 7457 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7458 | breakpoint. */ |
c3f6f71d JM |
7459 | if ((*address) == NULL |
7460 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7461 | { |
7462 | if (default_breakpoint_valid) | |
7463 | { | |
c3f6f71d | 7464 | struct symtab_and_line sal; |
cc59ec59 | 7465 | |
4a64f543 | 7466 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7467 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7468 | xmalloc (sizeof (struct symtab_and_line)); |
7469 | sal.pc = default_breakpoint_address; | |
7470 | sal.line = default_breakpoint_line; | |
7471 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7472 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7473 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7474 | |
4a64f543 MS |
7475 | /* "break" without arguments is equivalent to "break *PC" |
7476 | where PC is the default_breakpoint_address. So make sure | |
7477 | to set sal.explicit_pc to prevent GDB from trying to | |
7478 | expand the list of sals to include all other instances | |
7479 | with the same symtab and line. */ | |
00903456 JK |
7480 | sal.explicit_pc = 1; |
7481 | ||
c3f6f71d JM |
7482 | sals->sals[0] = sal; |
7483 | sals->nelts = 1; | |
c906108c SS |
7484 | } |
7485 | else | |
8a3fe4f8 | 7486 | error (_("No default breakpoint address now.")); |
c906108c SS |
7487 | } |
7488 | else | |
7489 | { | |
c906108c | 7490 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7491 | current_source_symtab (which is decode_line_1's default). |
7492 | This should produce the results we want almost all of the | |
7493 | time while leaving default_breakpoint_* alone. | |
7494 | ||
1aeae86e AF |
7495 | ObjC: However, don't match an Objective-C method name which |
7496 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7497 | |
c214a6fd | 7498 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7499 | |
c906108c | 7500 | if (default_breakpoint_valid |
0378c332 | 7501 | && (!cursal.symtab |
1aeae86e AF |
7502 | || ((strchr ("+-", (*address)[0]) != NULL) |
7503 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7504 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
58438ac1 | 7505 | default_breakpoint_line, canonical); |
c906108c | 7506 | else |
0101ce28 | 7507 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
58438ac1 | 7508 | canonical); |
c906108c | 7509 | } |
4a64f543 | 7510 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 | 7511 | if (sals->nelts > 0 && canonical->canonical == NULL) |
38a714bb | 7512 | canonical->canonical = xcalloc (sals->nelts, sizeof (char *)); |
c3f6f71d | 7513 | if (addr_start != (*address)) |
c906108c | 7514 | { |
c3f6f71d | 7515 | int i; |
cc59ec59 | 7516 | |
c3f6f71d | 7517 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7518 | { |
4a64f543 | 7519 | /* Add the string if not present. */ |
7efd8fc2 TT |
7520 | if (canonical->canonical[i] == NULL) |
7521 | canonical->canonical[i] = savestring (addr_start, | |
7522 | (*address) - addr_start); | |
c906108c SS |
7523 | } |
7524 | } | |
c3f6f71d | 7525 | } |
c906108c | 7526 | |
c906108c | 7527 | |
c3f6f71d | 7528 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7529 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7530 | |
b9362cc7 | 7531 | static void |
23e7acfb | 7532 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7533 | { |
7534 | int i; | |
cc59ec59 | 7535 | |
c3f6f71d | 7536 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7537 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7538 | } |
7539 | ||
7a697b8d SS |
7540 | /* Fast tracepoints may have restrictions on valid locations. For |
7541 | instance, a fast tracepoint using a jump instead of a trap will | |
7542 | likely have to overwrite more bytes than a trap would, and so can | |
7543 | only be placed where the instruction is longer than the jump, or a | |
7544 | multi-instruction sequence does not have a jump into the middle of | |
7545 | it, etc. */ | |
7546 | ||
7547 | static void | |
7548 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7549 | struct symtabs_and_lines *sals) | |
7550 | { | |
7551 | int i, rslt; | |
7552 | struct symtab_and_line *sal; | |
7553 | char *msg; | |
7554 | struct cleanup *old_chain; | |
7555 | ||
7556 | for (i = 0; i < sals->nelts; i++) | |
7557 | { | |
7558 | sal = &sals->sals[i]; | |
7559 | ||
7560 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7561 | NULL, &msg); | |
7562 | old_chain = make_cleanup (xfree, msg); | |
7563 | ||
7564 | if (!rslt) | |
7565 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7566 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7567 | ||
7568 | do_cleanups (old_chain); | |
7569 | } | |
7570 | } | |
7571 | ||
018d34a4 VP |
7572 | /* Given TOK, a string specification of condition and thread, as |
7573 | accepted by the 'break' command, extract the condition | |
7574 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7575 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7576 | If no condition is found, *COND_STRING is set to NULL. |
7577 | If no thread is found, *THREAD is set to -1. */ | |
7578 | static void | |
7579 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7580 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7581 | { |
7582 | *cond_string = NULL; | |
7583 | *thread = -1; | |
7584 | while (tok && *tok) | |
7585 | { | |
7586 | char *end_tok; | |
7587 | int toklen; | |
7588 | char *cond_start = NULL; | |
7589 | char *cond_end = NULL; | |
cc59ec59 | 7590 | |
e9cafbcc | 7591 | tok = skip_spaces (tok); |
018d34a4 | 7592 | |
e9cafbcc | 7593 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7594 | |
7595 | toklen = end_tok - tok; | |
7596 | ||
7597 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7598 | { | |
f7545552 TT |
7599 | struct expression *expr; |
7600 | ||
018d34a4 | 7601 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7602 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7603 | xfree (expr); | |
018d34a4 VP |
7604 | cond_end = tok; |
7605 | *cond_string = savestring (cond_start, | |
7606 | cond_end - cond_start); | |
7607 | } | |
7608 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7609 | { | |
7610 | char *tmptok; | |
7611 | ||
7612 | tok = end_tok + 1; | |
7613 | tmptok = tok; | |
7614 | *thread = strtol (tok, &tok, 0); | |
7615 | if (tok == tmptok) | |
7616 | error (_("Junk after thread keyword.")); | |
7617 | if (!valid_thread_id (*thread)) | |
7618 | error (_("Unknown thread %d."), *thread); | |
7619 | } | |
4a306c9a JB |
7620 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7621 | { | |
7622 | char *tmptok; | |
7623 | ||
7624 | tok = end_tok + 1; | |
7625 | tmptok = tok; | |
7626 | *task = strtol (tok, &tok, 0); | |
7627 | if (tok == tmptok) | |
7628 | error (_("Junk after task keyword.")); | |
7629 | if (!valid_task_id (*task)) | |
b6199126 | 7630 | error (_("Unknown task %d."), *task); |
4a306c9a | 7631 | } |
018d34a4 VP |
7632 | else |
7633 | error (_("Junk at end of arguments.")); | |
7634 | } | |
7635 | } | |
7636 | ||
0fb4aa4b PA |
7637 | /* Decode a static tracepoint marker spec. */ |
7638 | ||
7639 | static struct symtabs_and_lines | |
7640 | decode_static_tracepoint_spec (char **arg_p) | |
7641 | { | |
7642 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7643 | struct symtabs_and_lines sals; | |
7644 | struct symtab_and_line sal; | |
7645 | struct symbol *sym; | |
7646 | struct cleanup *old_chain; | |
7647 | char *p = &(*arg_p)[3]; | |
7648 | char *endp; | |
7649 | char *marker_str; | |
7650 | int i; | |
7651 | ||
e9cafbcc | 7652 | p = skip_spaces (p); |
0fb4aa4b | 7653 | |
e9cafbcc | 7654 | endp = skip_to_space (p); |
0fb4aa4b PA |
7655 | |
7656 | marker_str = savestring (p, endp - p); | |
7657 | old_chain = make_cleanup (xfree, marker_str); | |
7658 | ||
7659 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7660 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7661 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7662 | ||
7663 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7664 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7665 | ||
7666 | for (i = 0; i < sals.nelts; i++) | |
7667 | { | |
7668 | struct static_tracepoint_marker *marker; | |
7669 | ||
7670 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7671 | ||
7672 | init_sal (&sals.sals[i]); | |
7673 | ||
7674 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7675 | sals.sals[i].pc = marker->address; | |
7676 | ||
7677 | release_static_tracepoint_marker (marker); | |
7678 | } | |
7679 | ||
7680 | do_cleanups (old_chain); | |
7681 | ||
7682 | *arg_p = endp; | |
7683 | return sals; | |
7684 | } | |
7685 | ||
fd9b8c24 PA |
7686 | /* Set a breakpoint. This function is shared between CLI and MI |
7687 | functions for setting a breakpoint. This function has two major | |
7688 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7689 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7690 | breakpoint location, address and thread. Otherwise, ARG is just |
7691 | the location of breakpoint, with condition and thread specified by | |
7692 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7693 | the breakpoint number will be allocated from the internal | |
7694 | breakpoint count. Returns true if any breakpoint was created; | |
7695 | false otherwise. */ | |
0101ce28 | 7696 | |
8cdf0e15 VP |
7697 | int |
7698 | create_breakpoint (struct gdbarch *gdbarch, | |
7699 | char *arg, char *cond_string, int thread, | |
7700 | int parse_condition_and_thread, | |
0fb4aa4b | 7701 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7702 | int ignore_count, |
7703 | enum auto_boolean pending_break_support, | |
c0a91b2b | 7704 | const struct breakpoint_ops *ops, |
84f4c1fe | 7705 | int from_tty, int enabled, int internal) |
c3f6f71d | 7706 | { |
b78a6381 | 7707 | volatile struct gdb_exception e; |
c3f6f71d | 7708 | struct symtabs_and_lines sals; |
0101ce28 | 7709 | struct symtab_and_line pending_sal; |
0101ce28 | 7710 | char *copy_arg; |
c3f6f71d | 7711 | char *addr_start = arg; |
7efd8fc2 | 7712 | struct linespec_result canonical; |
c3f6f71d | 7713 | struct cleanup *old_chain; |
80c99de1 | 7714 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 7715 | int i; |
0101ce28 | 7716 | int pending = 0; |
4a306c9a | 7717 | int task = 0; |
86b17b60 | 7718 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7719 | |
348d480f PA |
7720 | gdb_assert (ops != NULL); |
7721 | ||
c3f6f71d JM |
7722 | sals.sals = NULL; |
7723 | sals.nelts = 0; | |
7efd8fc2 | 7724 | init_linespec_result (&canonical); |
c3f6f71d | 7725 | |
0fb4aa4b PA |
7726 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7727 | { | |
7728 | int i; | |
7729 | ||
7730 | sals = decode_static_tracepoint_spec (&arg); | |
7731 | ||
7732 | copy_arg = savestring (addr_start, arg - addr_start); | |
38a714bb | 7733 | canonical.canonical = xcalloc (sals.nelts, sizeof (char *)); |
0fb4aa4b | 7734 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7735 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7736 | goto done; |
7737 | } | |
7738 | ||
b78a6381 TT |
7739 | TRY_CATCH (e, RETURN_MASK_ALL) |
7740 | { | |
58438ac1 | 7741 | parse_breakpoint_sals (&arg, &sals, &canonical); |
b78a6381 | 7742 | } |
0101ce28 JJ |
7743 | |
7744 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7745 | switch (e.reason) |
0101ce28 | 7746 | { |
05ff989b | 7747 | case RETURN_QUIT: |
98deb0da | 7748 | throw_exception (e); |
05ff989b AC |
7749 | case RETURN_ERROR: |
7750 | switch (e.error) | |
0101ce28 | 7751 | { |
05ff989b | 7752 | case NOT_FOUND_ERROR: |
0101ce28 | 7753 | |
05ff989b AC |
7754 | /* If pending breakpoint support is turned off, throw |
7755 | error. */ | |
fa8d40ab JJ |
7756 | |
7757 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7758 | throw_exception (e); |
7759 | ||
7760 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7761 | |
05ff989b AC |
7762 | /* If pending breakpoint support is auto query and the user |
7763 | selects no, then simply return the error code. */ | |
059fb39f | 7764 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7765 | && !nquery (_("Make breakpoint pending on " |
7766 | "future shared library load? "))) | |
fd9b8c24 | 7767 | return 0; |
fa8d40ab | 7768 | |
05ff989b AC |
7769 | /* At this point, either the user was queried about setting |
7770 | a pending breakpoint and selected yes, or pending | |
7771 | breakpoint behavior is on and thus a pending breakpoint | |
7772 | is defaulted on behalf of the user. */ | |
0101ce28 | 7773 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 7774 | canonical.canonical = ©_arg; |
0101ce28 JJ |
7775 | sals.nelts = 1; |
7776 | sals.sals = &pending_sal; | |
7777 | pending_sal.pc = 0; | |
7778 | pending = 1; | |
05ff989b AC |
7779 | break; |
7780 | default: | |
98deb0da | 7781 | throw_exception (e); |
0101ce28 | 7782 | } |
2abae994 | 7783 | break; |
05ff989b AC |
7784 | default: |
7785 | if (!sals.nelts) | |
fd9b8c24 | 7786 | return 0; |
0101ce28 | 7787 | } |
c3f6f71d | 7788 | |
0fb4aa4b PA |
7789 | done: |
7790 | ||
4a64f543 | 7791 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7792 | old_chain = make_cleanup (null_cleanup, 0); |
7793 | ||
0101ce28 JJ |
7794 | if (!pending) |
7795 | { | |
7796 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7797 | make_cleanup (xfree, sals.sals); | |
7798 | ||
7efd8fc2 TT |
7799 | /* Cleanup the canonical array but not its contents. */ |
7800 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 7801 | } |
c3f6f71d | 7802 | |
c3f6f71d JM |
7803 | /* ----------------------------- SNIP ----------------------------- |
7804 | Anything added to the cleanup chain beyond this point is assumed | |
7805 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7806 | then the memory is not reclaimed. */ |
7807 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 7808 | |
7efd8fc2 | 7809 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 7810 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7811 | for (i = 0; i < sals.nelts; i++) |
7812 | { | |
7efd8fc2 TT |
7813 | if (canonical.canonical[i] != NULL) |
7814 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
7815 | } |
7816 | ||
7817 | /* Resolve all line numbers to PC's and verify that the addresses | |
7818 | are ok for the target. */ | |
0101ce28 | 7819 | if (!pending) |
23e7acfb | 7820 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7821 | |
7a697b8d SS |
7822 | /* Fast tracepoints may have additional restrictions on location. */ |
7823 | if (type_wanted == bp_fast_tracepoint) | |
7824 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7825 | ||
c3f6f71d JM |
7826 | /* Verify that condition can be parsed, before setting any |
7827 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7828 | breakpoint. */ |
0101ce28 | 7829 | if (!pending) |
c3f6f71d | 7830 | { |
2f069f6f | 7831 | if (parse_condition_and_thread) |
72b2ff0e VP |
7832 | { |
7833 | /* Here we only parse 'arg' to separate condition | |
7834 | from thread number, so parsing in context of first | |
7835 | sal is OK. When setting the breakpoint we'll | |
7836 | re-parse it in context of each sal. */ | |
7837 | cond_string = NULL; | |
7838 | thread = -1; | |
4a306c9a JB |
7839 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7840 | &thread, &task); | |
72b2ff0e VP |
7841 | if (cond_string) |
7842 | make_cleanup (xfree, cond_string); | |
7843 | } | |
2f069f6f | 7844 | else |
72b2ff0e VP |
7845 | { |
7846 | /* Create a private copy of condition string. */ | |
7847 | if (cond_string) | |
7848 | { | |
7849 | cond_string = xstrdup (cond_string); | |
7850 | make_cleanup (xfree, cond_string); | |
7851 | } | |
7852 | } | |
0fb4aa4b PA |
7853 | |
7854 | /* If the user is creating a static tracepoint by marker id | |
7855 | (strace -m MARKER_ID), then store the sals index, so that | |
7856 | breakpoint_re_set can try to match up which of the newly | |
7857 | found markers corresponds to this one, and, don't try to | |
7858 | expand multiple locations for each sal, given than SALS | |
7859 | already should contain all sals for MARKER_ID. */ | |
7860 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 7861 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
7862 | { |
7863 | int i; | |
7864 | ||
7865 | for (i = 0; i < sals.nelts; ++i) | |
7866 | { | |
7867 | struct symtabs_and_lines expanded; | |
d9b3f62e | 7868 | struct tracepoint *tp; |
0fb4aa4b PA |
7869 | struct cleanup *old_chain; |
7870 | ||
7871 | expanded.nelts = 1; | |
7872 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7873 | expanded.sals[0] = sals.sals[i]; | |
7874 | old_chain = make_cleanup (xfree, expanded.sals); | |
7875 | ||
d9b3f62e PA |
7876 | tp = XCNEW (struct tracepoint); |
7877 | init_breakpoint_sal (&tp->base, gdbarch, expanded, | |
7878 | canonical.canonical[i], | |
7879 | cond_string, type_wanted, | |
7880 | tempflag ? disp_del : disp_donttouch, | |
7881 | thread, task, ignore_count, ops, | |
7882 | from_tty, enabled, internal, | |
7883 | canonical.special_display); | |
0fb4aa4b PA |
7884 | /* Given that its possible to have multiple markers with |
7885 | the same string id, if the user is creating a static | |
7886 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7887 | store the sals index, so that breakpoint_re_set can | |
7888 | try to match up which of the newly found markers | |
7889 | corresponds to this one */ | |
7890 | tp->static_trace_marker_id_idx = i; | |
d9b3f62e PA |
7891 | |
7892 | install_breakpoint (internal, &tp->base); | |
7893 | ||
7894 | do_cleanups (old_chain); | |
0fb4aa4b PA |
7895 | } |
7896 | } | |
7897 | else | |
7efd8fc2 | 7898 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
7899 | type_wanted, |
7900 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7901 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7902 | enabled, internal); |
c906108c | 7903 | } |
0101ce28 JJ |
7904 | else |
7905 | { | |
0101ce28 JJ |
7906 | struct breakpoint *b; |
7907 | ||
0101ce28 JJ |
7908 | make_cleanup (xfree, copy_arg); |
7909 | ||
348d480f | 7910 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted, ops); |
84f4c1fe | 7911 | set_breakpoint_number (internal, b); |
72b2ff0e | 7912 | b->thread = -1; |
7efd8fc2 | 7913 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 7914 | b->cond_string = NULL; |
0101ce28 | 7915 | b->ignore_count = ignore_count; |
0101ce28 | 7916 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7917 | b->condition_not_parsed = 1; |
41447f92 | 7918 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7919 | b->pspace = current_program_space; |
84f4c1fe | 7920 | b->py_bp_object = NULL; |
74960c60 | 7921 | |
6c95b8df | 7922 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7923 | && (b->type == bp_breakpoint |
7924 | || b->type == bp_hardware_breakpoint)) | |
7925 | b->enable_state = bp_startup_disabled; | |
7926 | ||
8d3788bd | 7927 | if (!internal) |
84f4c1fe PM |
7928 | /* Do not mention breakpoints with a negative number, |
7929 | but do notify observers. */ | |
8d3788bd VP |
7930 | mention (b); |
7931 | observer_notify_breakpoint_created (b); | |
0101ce28 JJ |
7932 | } |
7933 | ||
c3f6f71d | 7934 | if (sals.nelts > 1) |
95a42b64 | 7935 | { |
3e43a32a MS |
7936 | warning (_("Multiple breakpoints were set.\nUse the " |
7937 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7938 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7939 | } |
7940 | ||
80c99de1 PA |
7941 | /* That's it. Discard the cleanups for data inserted into the |
7942 | breakpoint. */ | |
7943 | discard_cleanups (bkpt_chain); | |
7944 | /* But cleanup everything else. */ | |
c3f6f71d | 7945 | do_cleanups (old_chain); |
217dc9e2 | 7946 | |
80c99de1 | 7947 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7948 | update_global_location_list (1); |
fd9b8c24 PA |
7949 | |
7950 | return 1; | |
c3f6f71d | 7951 | } |
c906108c | 7952 | |
348d480f | 7953 | /* Set a breakpoint. |
72b2ff0e VP |
7954 | ARG is a string describing breakpoint address, |
7955 | condition, and thread. | |
7956 | FLAG specifies if a breakpoint is hardware on, | |
7957 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7958 | and BP_TEMPFLAG. */ | |
348d480f | 7959 | |
98deb0da | 7960 | static void |
72b2ff0e | 7961 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7962 | { |
72b2ff0e | 7963 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
7964 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
7965 | ? bp_hardware_breakpoint | |
7966 | : bp_breakpoint); | |
c3f6f71d | 7967 | |
8cdf0e15 VP |
7968 | create_breakpoint (get_current_arch (), |
7969 | arg, | |
7970 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 7971 | tempflag, type_wanted, |
8cdf0e15 VP |
7972 | 0 /* Ignore count */, |
7973 | pending_break_support, | |
348d480f | 7974 | &bkpt_breakpoint_ops, |
8cdf0e15 | 7975 | from_tty, |
84f4c1fe PM |
7976 | 1 /* enabled */, |
7977 | 0 /* internal */); | |
c906108c SS |
7978 | } |
7979 | ||
c906108c SS |
7980 | /* Helper function for break_command_1 and disassemble_command. */ |
7981 | ||
7982 | void | |
fba45db2 | 7983 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7984 | { |
7985 | CORE_ADDR pc; | |
7986 | ||
7987 | if (sal->pc == 0 && sal->symtab != NULL) | |
7988 | { | |
7989 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7990 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7991 | sal->line, sal->symtab->filename); |
7992 | sal->pc = pc; | |
6a048695 | 7993 | |
4a64f543 MS |
7994 | /* If this SAL corresponds to a breakpoint inserted using a line |
7995 | number, then skip the function prologue if necessary. */ | |
6a048695 | 7996 | if (sal->explicit_line) |
059acae7 | 7997 | skip_prologue_sal (sal); |
c906108c SS |
7998 | } |
7999 | ||
8000 | if (sal->section == 0 && sal->symtab != NULL) | |
8001 | { | |
8002 | struct blockvector *bv; | |
c5aa993b JM |
8003 | struct block *b; |
8004 | struct symbol *sym; | |
c906108c | 8005 | |
801e3a5b | 8006 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8007 | if (bv != NULL) |
8008 | { | |
7f0df278 | 8009 | sym = block_linkage_function (b); |
c906108c SS |
8010 | if (sym != NULL) |
8011 | { | |
8012 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8013 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8014 | } |
8015 | else | |
8016 | { | |
4a64f543 MS |
8017 | /* It really is worthwhile to have the section, so we'll |
8018 | just have to look harder. This case can be executed | |
8019 | if we have line numbers but no functions (as can | |
8020 | happen in assembly source). */ | |
c906108c | 8021 | |
c5aa993b | 8022 | struct minimal_symbol *msym; |
6c95b8df PA |
8023 | struct cleanup *old_chain = save_current_space_and_thread (); |
8024 | ||
8025 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8026 | |
8027 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8028 | if (msym) | |
714835d5 | 8029 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8030 | |
8031 | do_cleanups (old_chain); | |
c906108c SS |
8032 | } |
8033 | } | |
8034 | } | |
8035 | } | |
8036 | ||
8037 | void | |
fba45db2 | 8038 | break_command (char *arg, int from_tty) |
c906108c | 8039 | { |
db107f19 | 8040 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8041 | } |
8042 | ||
c906108c | 8043 | void |
fba45db2 | 8044 | tbreak_command (char *arg, int from_tty) |
c906108c | 8045 | { |
db107f19 | 8046 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8047 | } |
8048 | ||
c906108c | 8049 | static void |
fba45db2 | 8050 | hbreak_command (char *arg, int from_tty) |
c906108c | 8051 | { |
db107f19 | 8052 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8053 | } |
8054 | ||
8055 | static void | |
fba45db2 | 8056 | thbreak_command (char *arg, int from_tty) |
c906108c | 8057 | { |
db107f19 | 8058 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8059 | } |
8060 | ||
8061 | static void | |
fba45db2 | 8062 | stop_command (char *arg, int from_tty) |
c906108c | 8063 | { |
a3f17187 | 8064 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8065 | Usage: stop in <function | address>\n\ |
a3f17187 | 8066 | stop at <line>\n")); |
c906108c SS |
8067 | } |
8068 | ||
8069 | static void | |
fba45db2 | 8070 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8071 | { |
8072 | int badInput = 0; | |
8073 | ||
c5aa993b | 8074 | if (arg == (char *) NULL) |
c906108c SS |
8075 | badInput = 1; |
8076 | else if (*arg != '*') | |
8077 | { | |
8078 | char *argptr = arg; | |
8079 | int hasColon = 0; | |
8080 | ||
4a64f543 | 8081 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8082 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8083 | function/method name. */ |
c906108c | 8084 | while (*argptr && !hasColon) |
c5aa993b JM |
8085 | { |
8086 | hasColon = (*argptr == ':'); | |
8087 | argptr++; | |
8088 | } | |
c906108c SS |
8089 | |
8090 | if (hasColon) | |
c5aa993b | 8091 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8092 | else |
c5aa993b | 8093 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8094 | } |
8095 | ||
8096 | if (badInput) | |
a3f17187 | 8097 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8098 | else |
db107f19 | 8099 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8100 | } |
8101 | ||
8102 | static void | |
fba45db2 | 8103 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8104 | { |
8105 | int badInput = 0; | |
8106 | ||
c5aa993b | 8107 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8108 | badInput = 1; |
8109 | else | |
8110 | { | |
8111 | char *argptr = arg; | |
8112 | int hasColon = 0; | |
8113 | ||
4a64f543 MS |
8114 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8115 | it is probably a line number. */ | |
c906108c | 8116 | while (*argptr && !hasColon) |
c5aa993b JM |
8117 | { |
8118 | hasColon = (*argptr == ':'); | |
8119 | argptr++; | |
8120 | } | |
c906108c SS |
8121 | |
8122 | if (hasColon) | |
c5aa993b | 8123 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8124 | else |
c5aa993b | 8125 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8126 | } |
8127 | ||
8128 | if (badInput) | |
a3f17187 | 8129 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8130 | else |
db107f19 | 8131 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8132 | } |
8133 | ||
f1310107 TJB |
8134 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8135 | ranged breakpoints. */ | |
8136 | ||
8137 | static int | |
8138 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8139 | struct address_space *aspace, | |
8140 | CORE_ADDR bp_addr) | |
8141 | { | |
8142 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, | |
8143 | bl->length, aspace, bp_addr); | |
8144 | } | |
8145 | ||
8146 | /* Implement the "resources_needed" breakpoint_ops method for | |
8147 | ranged breakpoints. */ | |
8148 | ||
8149 | static int | |
8150 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8151 | { | |
8152 | return target_ranged_break_num_registers (); | |
8153 | } | |
8154 | ||
8155 | /* Implement the "print_it" breakpoint_ops method for | |
8156 | ranged breakpoints. */ | |
8157 | ||
8158 | static enum print_stop_action | |
348d480f | 8159 | print_it_ranged_breakpoint (bpstat bs) |
f1310107 | 8160 | { |
348d480f | 8161 | struct breakpoint *b = bs->breakpoint_at; |
f1310107 TJB |
8162 | struct bp_location *bl = b->loc; |
8163 | ||
8164 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8165 | ||
8166 | /* Ranged breakpoints have only one location. */ | |
8167 | gdb_assert (bl && bl->next == NULL); | |
8168 | ||
8169 | annotate_breakpoint (b->number); | |
8170 | if (b->disposition == disp_del) | |
8171 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8172 | else | |
8173 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8174 | if (ui_out_is_mi_like_p (uiout)) | |
8175 | { | |
8176 | ui_out_field_string (uiout, "reason", | |
8177 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8178 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8179 | } | |
8180 | ui_out_field_int (uiout, "bkptno", b->number); | |
8181 | ui_out_text (uiout, ", "); | |
8182 | ||
8183 | return PRINT_SRC_AND_LOC; | |
8184 | } | |
8185 | ||
8186 | /* Implement the "print_one" breakpoint_ops method for | |
8187 | ranged breakpoints. */ | |
8188 | ||
8189 | static void | |
8190 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8191 | struct bp_location **last_loc) | |
8192 | { | |
8193 | struct bp_location *bl = b->loc; | |
8194 | struct value_print_options opts; | |
8195 | ||
8196 | /* Ranged breakpoints have only one location. */ | |
8197 | gdb_assert (bl && bl->next == NULL); | |
8198 | ||
8199 | get_user_print_options (&opts); | |
8200 | ||
8201 | if (opts.addressprint) | |
8202 | /* We don't print the address range here, it will be printed later | |
8203 | by print_one_detail_ranged_breakpoint. */ | |
8204 | ui_out_field_skip (uiout, "addr"); | |
8205 | annotate_field (5); | |
8206 | print_breakpoint_location (b, bl); | |
8207 | *last_loc = bl; | |
8208 | } | |
8209 | ||
8210 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8211 | ranged breakpoints. */ | |
8212 | ||
8213 | static void | |
8214 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8215 | struct ui_out *uiout) | |
8216 | { | |
8217 | CORE_ADDR address_start, address_end; | |
8218 | struct bp_location *bl = b->loc; | |
8219 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8220 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8221 | ||
8222 | gdb_assert (bl); | |
8223 | ||
8224 | address_start = bl->address; | |
8225 | address_end = address_start + bl->length - 1; | |
8226 | ||
8227 | ui_out_text (uiout, "\taddress range: "); | |
8228 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8229 | print_core_address (bl->gdbarch, address_start), | |
8230 | print_core_address (bl->gdbarch, address_end)); | |
8231 | ui_out_field_stream (uiout, "addr", stb); | |
8232 | ui_out_text (uiout, "\n"); | |
8233 | ||
8234 | do_cleanups (cleanup); | |
8235 | } | |
8236 | ||
8237 | /* Implement the "print_mention" breakpoint_ops method for | |
8238 | ranged breakpoints. */ | |
8239 | ||
8240 | static void | |
8241 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8242 | { | |
8243 | struct bp_location *bl = b->loc; | |
8244 | ||
8245 | gdb_assert (bl); | |
8246 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8247 | ||
8248 | if (ui_out_is_mi_like_p (uiout)) | |
8249 | return; | |
8250 | ||
8251 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8252 | b->number, paddress (bl->gdbarch, bl->address), | |
8253 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8254 | } | |
8255 | ||
8256 | /* Implement the "print_recreate" breakpoint_ops method for | |
8257 | ranged breakpoints. */ | |
8258 | ||
8259 | static void | |
8260 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8261 | { | |
8262 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8263 | b->addr_string_range_end); | |
d9b3f62e | 8264 | print_recreate_thread (b, fp); |
f1310107 TJB |
8265 | } |
8266 | ||
8267 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8268 | ||
2060206e | 8269 | static struct breakpoint_ops ranged_breakpoint_ops; |
f1310107 TJB |
8270 | |
8271 | /* Find the address where the end of the breakpoint range should be | |
8272 | placed, given the SAL of the end of the range. This is so that if | |
8273 | the user provides a line number, the end of the range is set to the | |
8274 | last instruction of the given line. */ | |
8275 | ||
8276 | static CORE_ADDR | |
8277 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8278 | { | |
8279 | CORE_ADDR end; | |
8280 | ||
8281 | /* If the user provided a PC value, use it. Otherwise, | |
8282 | find the address of the end of the given location. */ | |
8283 | if (sal.explicit_pc) | |
8284 | end = sal.pc; | |
8285 | else | |
8286 | { | |
8287 | int ret; | |
8288 | CORE_ADDR start; | |
8289 | ||
8290 | ret = find_line_pc_range (sal, &start, &end); | |
8291 | if (!ret) | |
8292 | error (_("Could not find location of the end of the range.")); | |
8293 | ||
8294 | /* find_line_pc_range returns the start of the next line. */ | |
8295 | end--; | |
8296 | } | |
8297 | ||
8298 | return end; | |
8299 | } | |
8300 | ||
8301 | /* Implement the "break-range" CLI command. */ | |
8302 | ||
8303 | static void | |
8304 | break_range_command (char *arg, int from_tty) | |
8305 | { | |
8306 | char *arg_start, *addr_string_start, *addr_string_end; | |
8307 | struct linespec_result canonical_start, canonical_end; | |
8308 | int bp_count, can_use_bp, length; | |
8309 | CORE_ADDR end; | |
8310 | struct breakpoint *b; | |
8311 | struct symtab_and_line sal_start, sal_end; | |
8312 | struct symtabs_and_lines sals_start, sals_end; | |
8313 | struct cleanup *cleanup_bkpt; | |
8314 | ||
8315 | /* We don't support software ranged breakpoints. */ | |
8316 | if (target_ranged_break_num_registers () < 0) | |
8317 | error (_("This target does not support hardware ranged breakpoints.")); | |
8318 | ||
8319 | bp_count = hw_breakpoint_used_count (); | |
8320 | bp_count += target_ranged_break_num_registers (); | |
8321 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8322 | bp_count, 0); | |
8323 | if (can_use_bp < 0) | |
8324 | error (_("Hardware breakpoints used exceeds limit.")); | |
8325 | ||
8326 | if (arg == NULL || arg[0] == '\0') | |
8327 | error(_("No address range specified.")); | |
8328 | ||
8329 | sals_start.sals = NULL; | |
8330 | sals_start.nelts = 0; | |
8331 | init_linespec_result (&canonical_start); | |
8332 | ||
8333 | while (*arg == ' ' || *arg == '\t') | |
8334 | arg++; | |
8335 | ||
58438ac1 | 8336 | parse_breakpoint_sals (&arg, &sals_start, &canonical_start); |
f1310107 TJB |
8337 | |
8338 | sal_start = sals_start.sals[0]; | |
8339 | addr_string_start = canonical_start.canonical[0]; | |
8340 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); | |
8341 | xfree (sals_start.sals); | |
8342 | xfree (canonical_start.canonical); | |
8343 | ||
8344 | if (arg[0] != ',') | |
8345 | error (_("Too few arguments.")); | |
8346 | else if (sals_start.nelts == 0) | |
8347 | error (_("Could not find location of the beginning of the range.")); | |
8348 | else if (sals_start.nelts != 1) | |
8349 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8350 | ||
8351 | resolve_sal_pc (&sal_start); | |
8352 | ||
8353 | arg++; /* Skip the comma. */ | |
8354 | while (*arg == ' ' || *arg == '\t') | |
8355 | arg++; | |
8356 | ||
8357 | /* Parse the end location. */ | |
8358 | ||
8359 | sals_end.sals = NULL; | |
8360 | sals_end.nelts = 0; | |
8361 | init_linespec_result (&canonical_end); | |
8362 | arg_start = arg; | |
8363 | ||
423f41a5 | 8364 | /* We call decode_line_1 directly here instead of using |
f1310107 TJB |
8365 | parse_breakpoint_sals because we need to specify the start location's |
8366 | symtab and line as the default symtab and line for the end of the | |
8367 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8368 | where +14 means 14 lines from the start location. */ | |
8369 | sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line, | |
58438ac1 | 8370 | &canonical_end); |
f1310107 TJB |
8371 | |
8372 | /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */ | |
8373 | if (canonical_end.canonical == NULL) | |
38a714bb | 8374 | canonical_end.canonical = xcalloc (1, sizeof (char *)); |
f1310107 TJB |
8375 | /* Add the string if not present. */ |
8376 | if (arg_start != arg && canonical_end.canonical[0] == NULL) | |
8377 | canonical_end.canonical[0] = savestring (arg_start, arg - arg_start); | |
8378 | ||
8379 | sal_end = sals_end.sals[0]; | |
8380 | addr_string_end = canonical_end.canonical[0]; | |
8381 | make_cleanup (xfree, addr_string_end); | |
8382 | xfree (sals_end.sals); | |
8383 | xfree (canonical_end.canonical); | |
8384 | ||
8385 | if (sals_end.nelts == 0) | |
8386 | error (_("Could not find location of the end of the range.")); | |
8387 | else if (sals_end.nelts != 1) | |
8388 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8389 | ||
8390 | resolve_sal_pc (&sal_end); | |
8391 | ||
8392 | end = find_breakpoint_range_end (sal_end); | |
8393 | if (sal_start.pc > end) | |
177b42fe | 8394 | error (_("Invalid address range, end precedes start.")); |
f1310107 TJB |
8395 | |
8396 | length = end - sal_start.pc + 1; | |
8397 | if (length < 0) | |
8398 | /* Length overflowed. */ | |
8399 | error (_("Address range too large.")); | |
8400 | else if (length == 1) | |
8401 | { | |
8402 | /* This range is simple enough to be handled by | |
8403 | the `hbreak' command. */ | |
8404 | hbreak_command (addr_string_start, 1); | |
8405 | ||
8406 | do_cleanups (cleanup_bkpt); | |
8407 | ||
8408 | return; | |
8409 | } | |
8410 | ||
8411 | /* Now set up the breakpoint. */ | |
8412 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
348d480f | 8413 | bp_hardware_breakpoint, &ranged_breakpoint_ops); |
f1310107 TJB |
8414 | set_breakpoint_count (breakpoint_count + 1); |
8415 | b->number = breakpoint_count; | |
8416 | b->disposition = disp_donttouch; | |
8417 | b->addr_string = addr_string_start; | |
8418 | b->addr_string_range_end = addr_string_end; | |
f1310107 TJB |
8419 | b->loc->length = length; |
8420 | ||
8421 | discard_cleanups (cleanup_bkpt); | |
8422 | ||
8423 | mention (b); | |
8d3788bd | 8424 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8425 | update_global_location_list (1); |
8426 | } | |
8427 | ||
4a64f543 MS |
8428 | /* Return non-zero if EXP is verified as constant. Returned zero |
8429 | means EXP is variable. Also the constant detection may fail for | |
8430 | some constant expressions and in such case still falsely return | |
8431 | zero. */ | |
65d79d4b SDJ |
8432 | static int |
8433 | watchpoint_exp_is_const (const struct expression *exp) | |
8434 | { | |
8435 | int i = exp->nelts; | |
8436 | ||
8437 | while (i > 0) | |
8438 | { | |
8439 | int oplenp, argsp; | |
8440 | ||
8441 | /* We are only interested in the descriptor of each element. */ | |
8442 | operator_length (exp, i, &oplenp, &argsp); | |
8443 | i -= oplenp; | |
8444 | ||
8445 | switch (exp->elts[i].opcode) | |
8446 | { | |
8447 | case BINOP_ADD: | |
8448 | case BINOP_SUB: | |
8449 | case BINOP_MUL: | |
8450 | case BINOP_DIV: | |
8451 | case BINOP_REM: | |
8452 | case BINOP_MOD: | |
8453 | case BINOP_LSH: | |
8454 | case BINOP_RSH: | |
8455 | case BINOP_LOGICAL_AND: | |
8456 | case BINOP_LOGICAL_OR: | |
8457 | case BINOP_BITWISE_AND: | |
8458 | case BINOP_BITWISE_IOR: | |
8459 | case BINOP_BITWISE_XOR: | |
8460 | case BINOP_EQUAL: | |
8461 | case BINOP_NOTEQUAL: | |
8462 | case BINOP_LESS: | |
8463 | case BINOP_GTR: | |
8464 | case BINOP_LEQ: | |
8465 | case BINOP_GEQ: | |
8466 | case BINOP_REPEAT: | |
8467 | case BINOP_COMMA: | |
8468 | case BINOP_EXP: | |
8469 | case BINOP_MIN: | |
8470 | case BINOP_MAX: | |
8471 | case BINOP_INTDIV: | |
8472 | case BINOP_CONCAT: | |
8473 | case BINOP_IN: | |
8474 | case BINOP_RANGE: | |
8475 | case TERNOP_COND: | |
8476 | case TERNOP_SLICE: | |
8477 | case TERNOP_SLICE_COUNT: | |
8478 | ||
8479 | case OP_LONG: | |
8480 | case OP_DOUBLE: | |
8481 | case OP_DECFLOAT: | |
8482 | case OP_LAST: | |
8483 | case OP_COMPLEX: | |
8484 | case OP_STRING: | |
8485 | case OP_BITSTRING: | |
8486 | case OP_ARRAY: | |
8487 | case OP_TYPE: | |
8488 | case OP_NAME: | |
8489 | case OP_OBJC_NSSTRING: | |
8490 | ||
8491 | case UNOP_NEG: | |
8492 | case UNOP_LOGICAL_NOT: | |
8493 | case UNOP_COMPLEMENT: | |
8494 | case UNOP_ADDR: | |
8495 | case UNOP_HIGH: | |
4a64f543 MS |
8496 | /* Unary, binary and ternary operators: We have to check |
8497 | their operands. If they are constant, then so is the | |
8498 | result of that operation. For instance, if A and B are | |
8499 | determined to be constants, then so is "A + B". | |
8500 | ||
8501 | UNOP_IND is one exception to the rule above, because the | |
8502 | value of *ADDR is not necessarily a constant, even when | |
8503 | ADDR is. */ | |
65d79d4b SDJ |
8504 | break; |
8505 | ||
8506 | case OP_VAR_VALUE: | |
8507 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8508 | |
65d79d4b | 8509 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8510 | possible that a buggy compiler could mark a variable as |
8511 | constant even when it is not, and TYPE_CONST would return | |
8512 | true in this case, while SYMBOL_CLASS wouldn't. | |
8513 | ||
8514 | We also have to check for function symbols because they | |
8515 | are always constant. */ | |
65d79d4b SDJ |
8516 | { |
8517 | struct symbol *s = exp->elts[i + 2].symbol; | |
8518 | ||
8519 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8520 | && SYMBOL_CLASS (s) != LOC_CONST | |
8521 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8522 | return 0; | |
8523 | break; | |
8524 | } | |
8525 | ||
8526 | /* The default action is to return 0 because we are using | |
8527 | the optimistic approach here: If we don't know something, | |
8528 | then it is not a constant. */ | |
8529 | default: | |
8530 | return 0; | |
8531 | } | |
8532 | } | |
8533 | ||
8534 | return 1; | |
8535 | } | |
8536 | ||
3a5c3e22 PA |
8537 | /* Implement the "dtor" breakpoint_ops method for watchpoints. */ |
8538 | ||
8539 | static void | |
8540 | dtor_watchpoint (struct breakpoint *self) | |
8541 | { | |
8542 | struct watchpoint *w = (struct watchpoint *) self; | |
8543 | ||
8544 | xfree (w->cond_exp); | |
8545 | xfree (w->exp); | |
8546 | xfree (w->exp_string); | |
8547 | xfree (w->exp_string_reparse); | |
8548 | value_free (w->val); | |
8549 | ||
8550 | base_breakpoint_ops.dtor (self); | |
8551 | } | |
8552 | ||
348d480f PA |
8553 | /* Implement the "re_set" breakpoint_ops method for watchpoints. */ |
8554 | ||
8555 | static void | |
8556 | re_set_watchpoint (struct breakpoint *b) | |
8557 | { | |
3a5c3e22 PA |
8558 | struct watchpoint *w = (struct watchpoint *) b; |
8559 | ||
348d480f PA |
8560 | /* Watchpoint can be either on expression using entirely global |
8561 | variables, or it can be on local variables. | |
8562 | ||
8563 | Watchpoints of the first kind are never auto-deleted, and even | |
8564 | persist across program restarts. Since they can use variables | |
8565 | from shared libraries, we need to reparse expression as libraries | |
8566 | are loaded and unloaded. | |
8567 | ||
8568 | Watchpoints on local variables can also change meaning as result | |
8569 | of solib event. For example, if a watchpoint uses both a local | |
8570 | and a global variables in expression, it's a local watchpoint, | |
8571 | but unloading of a shared library will make the expression | |
8572 | invalid. This is not a very common use case, but we still | |
8573 | re-evaluate expression, to avoid surprises to the user. | |
8574 | ||
8575 | Note that for local watchpoints, we re-evaluate it only if | |
8576 | watchpoints frame id is still valid. If it's not, it means the | |
8577 | watchpoint is out of scope and will be deleted soon. In fact, | |
8578 | I'm not sure we'll ever be called in this case. | |
8579 | ||
8580 | If a local watchpoint's frame id is still valid, then | |
3a5c3e22 | 8581 | w->exp_valid_block is likewise valid, and we can safely use it. |
348d480f | 8582 | |
3a5c3e22 PA |
8583 | Don't do anything about disabled watchpoints, since they will be |
8584 | reevaluated again when enabled. */ | |
8585 | update_watchpoint (w, 1 /* reparse */); | |
348d480f PA |
8586 | } |
8587 | ||
77b06cd7 TJB |
8588 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8589 | ||
8590 | static int | |
8591 | insert_watchpoint (struct bp_location *bl) | |
8592 | { | |
3a5c3e22 PA |
8593 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8594 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8595 | |
8596 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8597 | w->cond_exp); |
77b06cd7 TJB |
8598 | } |
8599 | ||
8600 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8601 | ||
8602 | static int | |
8603 | remove_watchpoint (struct bp_location *bl) | |
8604 | { | |
3a5c3e22 PA |
8605 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8606 | int length = w->exact ? 1 : bl->length; | |
e09342b5 TJB |
8607 | |
8608 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
3a5c3e22 | 8609 | w->cond_exp); |
e09342b5 TJB |
8610 | } |
8611 | ||
e09342b5 | 8612 | static int |
348d480f PA |
8613 | breakpoint_hit_watchpoint (const struct bp_location *bl, |
8614 | struct address_space *aspace, CORE_ADDR bp_addr) | |
e09342b5 | 8615 | { |
348d480f | 8616 | struct breakpoint *b = bl->owner; |
3a5c3e22 | 8617 | struct watchpoint *w = (struct watchpoint *) b; |
77b06cd7 | 8618 | |
348d480f PA |
8619 | /* Continuable hardware watchpoints are treated as non-existent if the |
8620 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
8621 | some data address). Otherwise gdb won't stop on a break instruction | |
8622 | in the code (not from a breakpoint) when a hardware watchpoint has | |
8623 | been defined. Also skip watchpoints which we know did not trigger | |
8624 | (did not match the data address). */ | |
8625 | if (is_hardware_watchpoint (b) | |
3a5c3e22 | 8626 | && w->watchpoint_triggered == watch_triggered_no) |
348d480f | 8627 | return 0; |
9c06b0b4 | 8628 | |
348d480f | 8629 | return 1; |
9c06b0b4 TJB |
8630 | } |
8631 | ||
348d480f PA |
8632 | static void |
8633 | check_status_watchpoint (bpstat bs) | |
9c06b0b4 | 8634 | { |
348d480f | 8635 | gdb_assert (is_watchpoint (bs->breakpoint_at)); |
9c06b0b4 | 8636 | |
348d480f | 8637 | bpstat_check_watchpoint (bs); |
9c06b0b4 TJB |
8638 | } |
8639 | ||
8640 | /* Implement the "resources_needed" breakpoint_ops method for | |
348d480f | 8641 | hardware watchpoints. */ |
9c06b0b4 TJB |
8642 | |
8643 | static int | |
348d480f | 8644 | resources_needed_watchpoint (const struct bp_location *bl) |
9c06b0b4 | 8645 | { |
3a5c3e22 PA |
8646 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8647 | int length = w->exact? 1 : bl->length; | |
348d480f PA |
8648 | |
8649 | return target_region_ok_for_hw_watchpoint (bl->address, length); | |
9c06b0b4 TJB |
8650 | } |
8651 | ||
8652 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
348d480f | 8653 | hardware watchpoints. */ |
9c06b0b4 TJB |
8654 | |
8655 | static int | |
348d480f | 8656 | works_in_software_mode_watchpoint (const struct breakpoint *b) |
9c06b0b4 | 8657 | { |
efa80663 PA |
8658 | /* Read and access watchpoints only work with hardware support. */ |
8659 | return b->type == bp_watchpoint || b->type == bp_hardware_watchpoint; | |
9c06b0b4 TJB |
8660 | } |
8661 | ||
9c06b0b4 | 8662 | static enum print_stop_action |
348d480f | 8663 | print_it_watchpoint (bpstat bs) |
9c06b0b4 | 8664 | { |
348d480f PA |
8665 | struct cleanup *old_chain; |
8666 | struct breakpoint *b; | |
8667 | const struct bp_location *bl; | |
8668 | struct ui_stream *stb; | |
8669 | enum print_stop_action result; | |
3a5c3e22 | 8670 | struct watchpoint *w; |
348d480f PA |
8671 | |
8672 | gdb_assert (bs->bp_location_at != NULL); | |
8673 | ||
8674 | bl = bs->bp_location_at; | |
8675 | b = bs->breakpoint_at; | |
3a5c3e22 | 8676 | w = (struct watchpoint *) b; |
348d480f PA |
8677 | |
8678 | stb = ui_out_stream_new (uiout); | |
8679 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
9c06b0b4 TJB |
8680 | |
8681 | switch (b->type) | |
8682 | { | |
348d480f | 8683 | case bp_watchpoint: |
9c06b0b4 TJB |
8684 | case bp_hardware_watchpoint: |
8685 | annotate_watchpoint (b->number); | |
8686 | if (ui_out_is_mi_like_p (uiout)) | |
8687 | ui_out_field_string | |
8688 | (uiout, "reason", | |
8689 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8690 | mention (b); |
8691 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8692 | ui_out_text (uiout, "\nOld value = "); | |
8693 | watchpoint_value_print (bs->old_val, stb->stream); | |
8694 | ui_out_field_stream (uiout, "old", stb); | |
8695 | ui_out_text (uiout, "\nNew value = "); | |
3a5c3e22 | 8696 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8697 | ui_out_field_stream (uiout, "new", stb); |
8698 | ui_out_text (uiout, "\n"); | |
8699 | /* More than one watchpoint may have been triggered. */ | |
8700 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8701 | break; |
8702 | ||
8703 | case bp_read_watchpoint: | |
8704 | if (ui_out_is_mi_like_p (uiout)) | |
8705 | ui_out_field_string | |
8706 | (uiout, "reason", | |
8707 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
348d480f PA |
8708 | mention (b); |
8709 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8710 | ui_out_text (uiout, "\nValue = "); | |
3a5c3e22 | 8711 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8712 | ui_out_field_stream (uiout, "value", stb); |
8713 | ui_out_text (uiout, "\n"); | |
8714 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8715 | break; |
8716 | ||
8717 | case bp_access_watchpoint: | |
348d480f PA |
8718 | if (bs->old_val != NULL) |
8719 | { | |
8720 | annotate_watchpoint (b->number); | |
8721 | if (ui_out_is_mi_like_p (uiout)) | |
8722 | ui_out_field_string | |
8723 | (uiout, "reason", | |
8724 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8725 | mention (b); | |
8726 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8727 | ui_out_text (uiout, "\nOld value = "); | |
8728 | watchpoint_value_print (bs->old_val, stb->stream); | |
8729 | ui_out_field_stream (uiout, "old", stb); | |
8730 | ui_out_text (uiout, "\nNew value = "); | |
8731 | } | |
8732 | else | |
8733 | { | |
8734 | mention (b); | |
8735 | if (ui_out_is_mi_like_p (uiout)) | |
8736 | ui_out_field_string | |
8737 | (uiout, "reason", | |
8738 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8739 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); | |
8740 | ui_out_text (uiout, "\nValue = "); | |
8741 | } | |
3a5c3e22 | 8742 | watchpoint_value_print (w->val, stb->stream); |
348d480f PA |
8743 | ui_out_field_stream (uiout, "new", stb); |
8744 | ui_out_text (uiout, "\n"); | |
8745 | result = PRINT_UNKNOWN; | |
9c06b0b4 TJB |
8746 | break; |
8747 | default: | |
348d480f | 8748 | result = PRINT_UNKNOWN; |
9c06b0b4 TJB |
8749 | } |
8750 | ||
348d480f PA |
8751 | do_cleanups (old_chain); |
8752 | return result; | |
8753 | } | |
8754 | ||
8755 | /* Implement the "print_mention" breakpoint_ops method for hardware | |
8756 | watchpoints. */ | |
8757 | ||
8758 | static void | |
8759 | print_mention_watchpoint (struct breakpoint *b) | |
8760 | { | |
8761 | struct cleanup *ui_out_chain; | |
3a5c3e22 | 8762 | struct watchpoint *w = (struct watchpoint *) b; |
348d480f PA |
8763 | |
8764 | switch (b->type) | |
8765 | { | |
8766 | case bp_watchpoint: | |
8767 | ui_out_text (uiout, "Watchpoint "); | |
8768 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8769 | break; | |
8770 | case bp_hardware_watchpoint: | |
8771 | ui_out_text (uiout, "Hardware watchpoint "); | |
8772 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8773 | break; | |
8774 | case bp_read_watchpoint: | |
8775 | ui_out_text (uiout, "Hardware read watchpoint "); | |
8776 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8777 | break; | |
8778 | case bp_access_watchpoint: | |
8779 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
8780 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8781 | break; | |
8782 | default: | |
8783 | internal_error (__FILE__, __LINE__, | |
8784 | _("Invalid hardware watchpoint type.")); | |
8785 | } | |
8786 | ||
8787 | ui_out_field_int (uiout, "number", b->number); | |
8788 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8789 | ui_out_field_string (uiout, "exp", w->exp_string); |
348d480f PA |
8790 | do_cleanups (ui_out_chain); |
8791 | } | |
8792 | ||
8793 | /* Implement the "print_recreate" breakpoint_ops method for | |
8794 | watchpoints. */ | |
8795 | ||
8796 | static void | |
8797 | print_recreate_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8798 | { | |
3a5c3e22 PA |
8799 | struct watchpoint *w = (struct watchpoint *) b; |
8800 | ||
348d480f PA |
8801 | switch (b->type) |
8802 | { | |
8803 | case bp_watchpoint: | |
8804 | case bp_hardware_watchpoint: | |
8805 | fprintf_unfiltered (fp, "watch"); | |
8806 | break; | |
8807 | case bp_read_watchpoint: | |
8808 | fprintf_unfiltered (fp, "rwatch"); | |
8809 | break; | |
8810 | case bp_access_watchpoint: | |
8811 | fprintf_unfiltered (fp, "awatch"); | |
8812 | break; | |
8813 | default: | |
8814 | internal_error (__FILE__, __LINE__, | |
8815 | _("Invalid watchpoint type.")); | |
8816 | } | |
8817 | ||
3a5c3e22 | 8818 | fprintf_unfiltered (fp, " %s", w->exp_string); |
d9b3f62e | 8819 | print_recreate_thread (b, fp); |
348d480f PA |
8820 | } |
8821 | ||
8822 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8823 | ||
2060206e | 8824 | static struct breakpoint_ops watchpoint_breakpoint_ops; |
348d480f PA |
8825 | |
8826 | /* Implement the "insert" breakpoint_ops method for | |
8827 | masked hardware watchpoints. */ | |
8828 | ||
8829 | static int | |
8830 | insert_masked_watchpoint (struct bp_location *bl) | |
8831 | { | |
3a5c3e22 PA |
8832 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8833 | ||
8834 | return target_insert_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8835 | bl->watchpoint_type); |
8836 | } | |
8837 | ||
8838 | /* Implement the "remove" breakpoint_ops method for | |
8839 | masked hardware watchpoints. */ | |
8840 | ||
8841 | static int | |
8842 | remove_masked_watchpoint (struct bp_location *bl) | |
8843 | { | |
3a5c3e22 PA |
8844 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8845 | ||
8846 | return target_remove_mask_watchpoint (bl->address, w->hw_wp_mask, | |
348d480f PA |
8847 | bl->watchpoint_type); |
8848 | } | |
8849 | ||
8850 | /* Implement the "resources_needed" breakpoint_ops method for | |
8851 | masked hardware watchpoints. */ | |
8852 | ||
8853 | static int | |
8854 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
8855 | { | |
3a5c3e22 PA |
8856 | struct watchpoint *w = (struct watchpoint *) bl->owner; |
8857 | ||
8858 | return target_masked_watch_num_registers (bl->address, w->hw_wp_mask); | |
348d480f PA |
8859 | } |
8860 | ||
8861 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
8862 | masked hardware watchpoints. */ | |
8863 | ||
8864 | static int | |
8865 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
8866 | { | |
8867 | return 0; | |
8868 | } | |
8869 | ||
8870 | /* Implement the "print_it" breakpoint_ops method for | |
8871 | masked hardware watchpoints. */ | |
8872 | ||
8873 | static enum print_stop_action | |
8874 | print_it_masked_watchpoint (bpstat bs) | |
8875 | { | |
8876 | struct breakpoint *b = bs->breakpoint_at; | |
8877 | ||
8878 | /* Masked watchpoints have only one location. */ | |
8879 | gdb_assert (b->loc && b->loc->next == NULL); | |
8880 | ||
8881 | switch (b->type) | |
8882 | { | |
8883 | case bp_hardware_watchpoint: | |
8884 | annotate_watchpoint (b->number); | |
8885 | if (ui_out_is_mi_like_p (uiout)) | |
8886 | ui_out_field_string | |
8887 | (uiout, "reason", | |
8888 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
8889 | break; | |
8890 | ||
8891 | case bp_read_watchpoint: | |
8892 | if (ui_out_is_mi_like_p (uiout)) | |
8893 | ui_out_field_string | |
8894 | (uiout, "reason", | |
8895 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
8896 | break; | |
8897 | ||
8898 | case bp_access_watchpoint: | |
8899 | if (ui_out_is_mi_like_p (uiout)) | |
8900 | ui_out_field_string | |
8901 | (uiout, "reason", | |
8902 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8903 | break; | |
8904 | default: | |
8905 | internal_error (__FILE__, __LINE__, | |
8906 | _("Invalid hardware watchpoint type.")); | |
8907 | } | |
8908 | ||
8909 | mention (b); | |
9c06b0b4 TJB |
8910 | ui_out_text (uiout, _("\n\ |
8911 | Check the underlying instruction at PC for the memory\n\ | |
8912 | address and value which triggered this watchpoint.\n")); | |
8913 | ui_out_text (uiout, "\n"); | |
8914 | ||
8915 | /* More than one watchpoint may have been triggered. */ | |
8916 | return PRINT_UNKNOWN; | |
8917 | } | |
8918 | ||
8919 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8920 | masked hardware watchpoints. */ | |
8921 | ||
8922 | static void | |
8923 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
8924 | struct ui_out *uiout) | |
8925 | { | |
3a5c3e22 PA |
8926 | struct watchpoint *w = (struct watchpoint *) b; |
8927 | ||
9c06b0b4 TJB |
8928 | /* Masked watchpoints have only one location. */ |
8929 | gdb_assert (b->loc && b->loc->next == NULL); | |
8930 | ||
8931 | ui_out_text (uiout, "\tmask "); | |
3a5c3e22 | 8932 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, w->hw_wp_mask); |
9c06b0b4 TJB |
8933 | ui_out_text (uiout, "\n"); |
8934 | } | |
8935 | ||
8936 | /* Implement the "print_mention" breakpoint_ops method for | |
8937 | masked hardware watchpoints. */ | |
8938 | ||
8939 | static void | |
8940 | print_mention_masked_watchpoint (struct breakpoint *b) | |
8941 | { | |
3a5c3e22 | 8942 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
8943 | struct cleanup *ui_out_chain; |
8944 | ||
8945 | switch (b->type) | |
8946 | { | |
8947 | case bp_hardware_watchpoint: | |
8948 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
8949 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8950 | break; | |
8951 | case bp_read_watchpoint: | |
8952 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
8953 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8954 | break; | |
8955 | case bp_access_watchpoint: | |
8956 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
8957 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8958 | break; | |
8959 | default: | |
8960 | internal_error (__FILE__, __LINE__, | |
8961 | _("Invalid hardware watchpoint type.")); | |
8962 | } | |
8963 | ||
8964 | ui_out_field_int (uiout, "number", b->number); | |
8965 | ui_out_text (uiout, ": "); | |
3a5c3e22 | 8966 | ui_out_field_string (uiout, "exp", w->exp_string); |
9c06b0b4 TJB |
8967 | do_cleanups (ui_out_chain); |
8968 | } | |
8969 | ||
8970 | /* Implement the "print_recreate" breakpoint_ops method for | |
8971 | masked hardware watchpoints. */ | |
8972 | ||
8973 | static void | |
8974 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8975 | { | |
3a5c3e22 | 8976 | struct watchpoint *w = (struct watchpoint *) b; |
9c06b0b4 TJB |
8977 | char tmp[40]; |
8978 | ||
8979 | switch (b->type) | |
8980 | { | |
8981 | case bp_hardware_watchpoint: | |
8982 | fprintf_unfiltered (fp, "watch"); | |
8983 | break; | |
8984 | case bp_read_watchpoint: | |
8985 | fprintf_unfiltered (fp, "rwatch"); | |
8986 | break; | |
8987 | case bp_access_watchpoint: | |
8988 | fprintf_unfiltered (fp, "awatch"); | |
8989 | break; | |
8990 | default: | |
8991 | internal_error (__FILE__, __LINE__, | |
8992 | _("Invalid hardware watchpoint type.")); | |
8993 | } | |
8994 | ||
3a5c3e22 PA |
8995 | sprintf_vma (tmp, w->hw_wp_mask); |
8996 | fprintf_unfiltered (fp, " %s mask 0x%s", w->exp_string, tmp); | |
d9b3f62e | 8997 | print_recreate_thread (b, fp); |
9c06b0b4 TJB |
8998 | } |
8999 | ||
9000 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9001 | ||
2060206e | 9002 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops; |
9c06b0b4 TJB |
9003 | |
9004 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9005 | ||
9006 | static int | |
9007 | is_masked_watchpoint (const struct breakpoint *b) | |
9008 | { | |
9009 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9010 | } | |
9011 | ||
53a5351d JM |
9012 | /* accessflag: hw_write: watch write, |
9013 | hw_read: watch read, | |
9014 | hw_access: watch access (read or write) */ | |
c906108c | 9015 | static void |
84f4c1fe PM |
9016 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9017 | int just_location, int internal) | |
c906108c | 9018 | { |
a9634178 | 9019 | volatile struct gdb_exception e; |
d983da9c | 9020 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9021 | struct expression *exp; |
60e1c644 | 9022 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9023 | struct value *val, *mark, *result; |
c906108c | 9024 | struct frame_info *frame; |
c906108c SS |
9025 | char *exp_start = NULL; |
9026 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9027 | char *tok, *end_tok; |
9028 | int toklen = -1; | |
c906108c SS |
9029 | char *cond_start = NULL; |
9030 | char *cond_end = NULL; | |
c906108c | 9031 | enum bptype bp_type; |
37e4754d | 9032 | int thread = -1; |
0cf6dd15 | 9033 | int pc = 0; |
9c06b0b4 TJB |
9034 | /* Flag to indicate whether we are going to use masks for |
9035 | the hardware watchpoint. */ | |
9036 | int use_mask = 0; | |
9037 | CORE_ADDR mask = 0; | |
3a5c3e22 | 9038 | struct watchpoint *w; |
c906108c | 9039 | |
37e4754d LM |
9040 | /* Make sure that we actually have parameters to parse. */ |
9041 | if (arg != NULL && arg[0] != '\0') | |
9042 | { | |
9c06b0b4 | 9043 | char *value_start; |
37e4754d | 9044 | |
9c06b0b4 TJB |
9045 | /* Look for "parameter value" pairs at the end |
9046 | of the arguments string. */ | |
9047 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9048 | { | |
9049 | /* Skip whitespace at the end of the argument list. */ | |
9050 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9051 | tok--; | |
9052 | ||
9053 | /* Find the beginning of the last token. | |
9054 | This is the value of the parameter. */ | |
9055 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9056 | tok--; | |
9057 | value_start = tok + 1; | |
9058 | ||
9059 | /* Skip whitespace. */ | |
9060 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9061 | tok--; | |
9062 | ||
9063 | end_tok = tok; | |
9064 | ||
9065 | /* Find the beginning of the second to last token. | |
9066 | This is the parameter itself. */ | |
9067 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9068 | tok--; | |
9069 | tok++; | |
9070 | toklen = end_tok - tok + 1; | |
9071 | ||
9072 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9073 | { | |
9074 | /* At this point we've found a "thread" token, which means | |
9075 | the user is trying to set a watchpoint that triggers | |
9076 | only in a specific thread. */ | |
9077 | char *endp; | |
37e4754d | 9078 | |
9c06b0b4 TJB |
9079 | if (thread != -1) |
9080 | error(_("You can specify only one thread.")); | |
37e4754d | 9081 | |
9c06b0b4 TJB |
9082 | /* Extract the thread ID from the next token. */ |
9083 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9084 | |
9c06b0b4 TJB |
9085 | /* Check if the user provided a valid numeric value for the |
9086 | thread ID. */ | |
9087 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9088 | error (_("Invalid thread ID specification %s."), value_start); | |
9089 | ||
9090 | /* Check if the thread actually exists. */ | |
9091 | if (!valid_thread_id (thread)) | |
9092 | error (_("Unknown thread %d."), thread); | |
9093 | } | |
9094 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9095 | { | |
9096 | /* We've found a "mask" token, which means the user wants to | |
9097 | create a hardware watchpoint that is going to have the mask | |
9098 | facility. */ | |
9099 | struct value *mask_value, *mark; | |
37e4754d | 9100 | |
9c06b0b4 TJB |
9101 | if (use_mask) |
9102 | error(_("You can specify only one mask.")); | |
37e4754d | 9103 | |
9c06b0b4 | 9104 | use_mask = just_location = 1; |
37e4754d | 9105 | |
9c06b0b4 TJB |
9106 | mark = value_mark (); |
9107 | mask_value = parse_to_comma_and_eval (&value_start); | |
9108 | mask = value_as_address (mask_value); | |
9109 | value_free_to_mark (mark); | |
9110 | } | |
9111 | else | |
9112 | /* We didn't recognize what we found. We should stop here. */ | |
9113 | break; | |
37e4754d | 9114 | |
9c06b0b4 TJB |
9115 | /* Truncate the string and get rid of the "parameter value" pair before |
9116 | the arguments string is parsed by the parse_exp_1 function. */ | |
9117 | *tok = '\0'; | |
9118 | } | |
37e4754d LM |
9119 | } |
9120 | ||
9121 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9122 | innermost_block = NULL; |
9123 | exp_start = arg; | |
9124 | exp = parse_exp_1 (&arg, 0, 0); | |
9125 | exp_end = arg; | |
fa8a61dc TT |
9126 | /* Remove trailing whitespace from the expression before saving it. |
9127 | This makes the eventual display of the expression string a bit | |
9128 | prettier. */ | |
9129 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9130 | --exp_end; | |
9131 | ||
65d79d4b SDJ |
9132 | /* Checking if the expression is not constant. */ |
9133 | if (watchpoint_exp_is_const (exp)) | |
9134 | { | |
9135 | int len; | |
9136 | ||
9137 | len = exp_end - exp_start; | |
9138 | while (len > 0 && isspace (exp_start[len - 1])) | |
9139 | len--; | |
9140 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9141 | } | |
9142 | ||
c906108c SS |
9143 | exp_valid_block = innermost_block; |
9144 | mark = value_mark (); | |
a1442452 | 9145 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9146 | |
9147 | if (just_location) | |
9148 | { | |
9c06b0b4 TJB |
9149 | int ret; |
9150 | ||
06a64a0b | 9151 | exp_valid_block = NULL; |
a1442452 | 9152 | val = value_addr (result); |
06a64a0b TT |
9153 | release_value (val); |
9154 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9155 | |
9156 | if (use_mask) | |
9157 | { | |
9158 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9159 | mask); | |
9160 | if (ret == -1) | |
9161 | error (_("This target does not support masked watchpoints.")); | |
9162 | else if (ret == -2) | |
9163 | error (_("Invalid mask or memory region.")); | |
9164 | } | |
06a64a0b TT |
9165 | } |
9166 | else if (val != NULL) | |
fa4727a6 | 9167 | release_value (val); |
c906108c | 9168 | |
e9cafbcc TT |
9169 | tok = skip_spaces (arg); |
9170 | end_tok = skip_to_space (tok); | |
c906108c SS |
9171 | |
9172 | toklen = end_tok - tok; | |
9173 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9174 | { | |
2d134ed3 PA |
9175 | struct expression *cond; |
9176 | ||
60e1c644 | 9177 | innermost_block = NULL; |
c906108c SS |
9178 | tok = cond_start = end_tok + 1; |
9179 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9180 | |
9181 | /* The watchpoint expression may not be local, but the condition | |
9182 | may still be. E.g.: `watch global if local > 0'. */ | |
9183 | cond_exp_valid_block = innermost_block; | |
9184 | ||
2d134ed3 | 9185 | xfree (cond); |
c906108c SS |
9186 | cond_end = tok; |
9187 | } | |
9188 | if (*tok) | |
8a3fe4f8 | 9189 | error (_("Junk at end of command.")); |
c906108c | 9190 | |
53a5351d | 9191 | if (accessflag == hw_read) |
c5aa993b | 9192 | bp_type = bp_read_watchpoint; |
53a5351d | 9193 | else if (accessflag == hw_access) |
c5aa993b JM |
9194 | bp_type = bp_access_watchpoint; |
9195 | else | |
9196 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9197 | |
d983da9c | 9198 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9199 | |
9200 | /* If the expression is "local", then set up a "watchpoint scope" | |
9201 | breakpoint at the point where we've left the scope of the watchpoint | |
9202 | expression. Create the scope breakpoint before the watchpoint, so | |
9203 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9204 | if (exp_valid_block && frame) |
d983da9c | 9205 | { |
edb3359d DJ |
9206 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9207 | { | |
9208 | scope_breakpoint | |
a6d9a66e UW |
9209 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9210 | frame_unwind_caller_pc (frame), | |
06edf0c0 PA |
9211 | bp_watchpoint_scope, |
9212 | &momentary_breakpoint_ops); | |
d983da9c | 9213 | |
edb3359d | 9214 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9215 | |
edb3359d DJ |
9216 | /* Automatically delete the breakpoint when it hits. */ |
9217 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9218 | |
edb3359d DJ |
9219 | /* Only break in the proper frame (help with recursion). */ |
9220 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9221 | |
edb3359d | 9222 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9223 | scope_breakpoint->loc->gdbarch |
9224 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9225 | scope_breakpoint->loc->requested_address |
9226 | = frame_unwind_caller_pc (frame); | |
9227 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9228 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9229 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9230 | scope_breakpoint->type); |
9231 | } | |
d983da9c DJ |
9232 | } |
9233 | ||
c906108c | 9234 | /* Now set up the breakpoint. */ |
3a5c3e22 PA |
9235 | |
9236 | w = XCNEW (struct watchpoint); | |
9237 | b = &w->base; | |
348d480f | 9238 | if (use_mask) |
3a5c3e22 PA |
9239 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9240 | &masked_watchpoint_breakpoint_ops); | |
348d480f | 9241 | else |
3a5c3e22 PA |
9242 | init_raw_breakpoint_without_location (b, NULL, bp_type, |
9243 | &watchpoint_breakpoint_ops); | |
37e4754d | 9244 | b->thread = thread; |
b5de0fa7 | 9245 | b->disposition = disp_donttouch; |
348d480f | 9246 | b->pspace = current_program_space; |
3a5c3e22 PA |
9247 | w->exp = exp; |
9248 | w->exp_valid_block = exp_valid_block; | |
9249 | w->cond_exp_valid_block = cond_exp_valid_block; | |
06a64a0b TT |
9250 | if (just_location) |
9251 | { | |
9252 | struct type *t = value_type (val); | |
9253 | CORE_ADDR addr = value_as_address (val); | |
9254 | char *name; | |
9255 | ||
9256 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9257 | name = type_to_string (t); | |
9258 | ||
3a5c3e22 | 9259 | w->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
d63d0675 | 9260 | core_addr_to_string (addr)); |
06a64a0b TT |
9261 | xfree (name); |
9262 | ||
3a5c3e22 | 9263 | w->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9264 | (int) (exp_end - exp_start), exp_start); |
9265 | ||
06a64a0b TT |
9266 | /* The above expression is in C. */ |
9267 | b->language = language_c; | |
9268 | } | |
9269 | else | |
3a5c3e22 | 9270 | w->exp_string = savestring (exp_start, exp_end - exp_start); |
9c06b0b4 TJB |
9271 | |
9272 | if (use_mask) | |
9273 | { | |
3a5c3e22 | 9274 | w->hw_wp_mask = mask; |
9c06b0b4 TJB |
9275 | } |
9276 | else | |
9277 | { | |
3a5c3e22 PA |
9278 | w->val = val; |
9279 | w->val_valid = 1; | |
9c06b0b4 | 9280 | } |
77b06cd7 | 9281 | |
c906108c SS |
9282 | if (cond_start) |
9283 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9284 | else | |
9285 | b->cond_string = 0; | |
c5aa993b | 9286 | |
c906108c | 9287 | if (frame) |
f6bc2008 | 9288 | { |
3a5c3e22 PA |
9289 | w->watchpoint_frame = get_frame_id (frame); |
9290 | w->watchpoint_thread = inferior_ptid; | |
f6bc2008 | 9291 | } |
c906108c | 9292 | else |
f6bc2008 | 9293 | { |
3a5c3e22 PA |
9294 | w->watchpoint_frame = null_frame_id; |
9295 | w->watchpoint_thread = null_ptid; | |
f6bc2008 | 9296 | } |
c906108c | 9297 | |
d983da9c | 9298 | if (scope_breakpoint != NULL) |
c906108c | 9299 | { |
d983da9c DJ |
9300 | /* The scope breakpoint is related to the watchpoint. We will |
9301 | need to act on them together. */ | |
9302 | b->related_breakpoint = scope_breakpoint; | |
9303 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9304 | } |
d983da9c | 9305 | |
06a64a0b TT |
9306 | if (!just_location) |
9307 | value_free_to_mark (mark); | |
2d134ed3 | 9308 | |
a9634178 TJB |
9309 | TRY_CATCH (e, RETURN_MASK_ALL) |
9310 | { | |
9311 | /* Finally update the new watchpoint. This creates the locations | |
9312 | that should be inserted. */ | |
3a5c3e22 | 9313 | update_watchpoint (w, 1); |
a9634178 TJB |
9314 | } |
9315 | if (e.reason < 0) | |
9316 | { | |
9317 | delete_breakpoint (b); | |
9318 | throw_exception (e); | |
9319 | } | |
9320 | ||
3a5c3e22 | 9321 | install_breakpoint (internal, b); |
c906108c SS |
9322 | } |
9323 | ||
e09342b5 | 9324 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9325 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9326 | |
c906108c | 9327 | static int |
a9634178 | 9328 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9329 | { |
9330 | int found_memory_cnt = 0; | |
2e70b7b9 | 9331 | struct value *head = v; |
c906108c SS |
9332 | |
9333 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9334 | if (!can_use_hw_watchpoints) |
c906108c | 9335 | return 0; |
c5aa993b | 9336 | |
5c44784c JM |
9337 | /* Make sure that the value of the expression depends only upon |
9338 | memory contents, and values computed from them within GDB. If we | |
9339 | find any register references or function calls, we can't use a | |
9340 | hardware watchpoint. | |
9341 | ||
9342 | The idea here is that evaluating an expression generates a series | |
9343 | of values, one holding the value of every subexpression. (The | |
9344 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9345 | a*b+c.) GDB's values hold almost enough information to establish | |
9346 | the criteria given above --- they identify memory lvalues, | |
9347 | register lvalues, computed values, etcetera. So we can evaluate | |
9348 | the expression, and then scan the chain of values that leaves | |
9349 | behind to decide whether we can detect any possible change to the | |
9350 | expression's final value using only hardware watchpoints. | |
9351 | ||
9352 | However, I don't think that the values returned by inferior | |
9353 | function calls are special in any way. So this function may not | |
9354 | notice that an expression involving an inferior function call | |
9355 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9356 | for (; v; v = value_next (v)) |
c906108c | 9357 | { |
5c44784c | 9358 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9359 | { |
8464be76 DJ |
9360 | if (v != head && value_lazy (v)) |
9361 | /* A lazy memory lvalue in the chain is one that GDB never | |
9362 | needed to fetch; we either just used its address (e.g., | |
9363 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9364 | in `a,b'). This doesn't apply to HEAD; if that is | |
9365 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9366 | ; |
53a5351d | 9367 | else |
5c44784c JM |
9368 | { |
9369 | /* Ahh, memory we actually used! Check if we can cover | |
9370 | it with hardware watchpoints. */ | |
df407dfe | 9371 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9372 | |
9373 | /* We only watch structs and arrays if user asked for it | |
9374 | explicitly, never if they just happen to appear in a | |
9375 | middle of some value chain. */ | |
9376 | if (v == head | |
9377 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9378 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9379 | { | |
42ae5230 | 9380 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9381 | int len; |
9382 | int num_regs; | |
9383 | ||
a9634178 | 9384 | len = (target_exact_watchpoints |
e09342b5 TJB |
9385 | && is_scalar_type_recursive (vtype))? |
9386 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9387 | |
e09342b5 TJB |
9388 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9389 | if (!num_regs) | |
2e70b7b9 MS |
9390 | return 0; |
9391 | else | |
e09342b5 | 9392 | found_memory_cnt += num_regs; |
2e70b7b9 | 9393 | } |
5c44784c | 9394 | } |
c5aa993b | 9395 | } |
5086187c AC |
9396 | else if (VALUE_LVAL (v) != not_lval |
9397 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9398 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9399 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9400 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9401 | } |
9402 | ||
9403 | /* The expression itself looks suitable for using a hardware | |
9404 | watchpoint, but give the target machine a chance to reject it. */ | |
9405 | return found_memory_cnt; | |
9406 | } | |
9407 | ||
8b93c638 | 9408 | void |
84f4c1fe | 9409 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9410 | { |
84f4c1fe | 9411 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9412 | } |
9413 | ||
9414 | /* A helper function that looks for an argument at the start of a | |
9415 | string. The argument must also either be at the end of the string, | |
9416 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9417 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9418 | ||
9419 | static int | |
9420 | check_for_argument (char **str, char *arg, int arg_len) | |
9421 | { | |
9422 | if (strncmp (*str, arg, arg_len) == 0 | |
9423 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9424 | { | |
9425 | *str += arg_len; | |
9426 | return 1; | |
9427 | } | |
9428 | return 0; | |
9429 | } | |
9430 | ||
9431 | /* A helper function that looks for the "-location" argument and then | |
9432 | calls watch_command_1. */ | |
9433 | ||
9434 | static void | |
9435 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9436 | { | |
9437 | int just_location = 0; | |
9438 | ||
9439 | if (arg | |
9440 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9441 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9442 | { | |
e9cafbcc | 9443 | arg = skip_spaces (arg); |
06a64a0b TT |
9444 | just_location = 1; |
9445 | } | |
9446 | ||
84f4c1fe | 9447 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9448 | } |
8926118c | 9449 | |
c5aa993b | 9450 | static void |
fba45db2 | 9451 | watch_command (char *arg, int from_tty) |
c906108c | 9452 | { |
06a64a0b | 9453 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9454 | } |
9455 | ||
8b93c638 | 9456 | void |
84f4c1fe | 9457 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9458 | { |
84f4c1fe | 9459 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9460 | } |
8926118c | 9461 | |
c5aa993b | 9462 | static void |
fba45db2 | 9463 | rwatch_command (char *arg, int from_tty) |
c906108c | 9464 | { |
06a64a0b | 9465 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9466 | } |
9467 | ||
8b93c638 | 9468 | void |
84f4c1fe | 9469 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9470 | { |
84f4c1fe | 9471 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9472 | } |
8926118c | 9473 | |
c5aa993b | 9474 | static void |
fba45db2 | 9475 | awatch_command (char *arg, int from_tty) |
c906108c | 9476 | { |
06a64a0b | 9477 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9478 | } |
c906108c | 9479 | \f |
c5aa993b | 9480 | |
43ff13b4 | 9481 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9482 | because it uses the mechanisms of breakpoints. */ |
9483 | ||
bfec99b2 PA |
9484 | struct until_break_command_continuation_args |
9485 | { | |
9486 | struct breakpoint *breakpoint; | |
9487 | struct breakpoint *breakpoint2; | |
186c406b | 9488 | int thread_num; |
bfec99b2 PA |
9489 | }; |
9490 | ||
43ff13b4 | 9491 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9492 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9493 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9494 | command. */ |
c2c6d25f | 9495 | static void |
fa4cd53f | 9496 | until_break_command_continuation (void *arg, int err) |
43ff13b4 | 9497 | { |
bfec99b2 PA |
9498 | struct until_break_command_continuation_args *a = arg; |
9499 | ||
9500 | delete_breakpoint (a->breakpoint); | |
9501 | if (a->breakpoint2) | |
9502 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9503 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9504 | } |
9505 | ||
c906108c | 9506 | void |
ae66c1fc | 9507 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9508 | { |
9509 | struct symtabs_and_lines sals; | |
9510 | struct symtab_and_line sal; | |
206415a3 | 9511 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9512 | struct breakpoint *breakpoint; |
f107f563 | 9513 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9514 | struct cleanup *old_chain; |
186c406b TT |
9515 | int thread; |
9516 | struct thread_info *tp; | |
c906108c SS |
9517 | |
9518 | clear_proceed_status (); | |
9519 | ||
9520 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9521 | this function. */ |
c5aa993b | 9522 | |
c906108c SS |
9523 | if (default_breakpoint_valid) |
9524 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
58438ac1 | 9525 | default_breakpoint_line, NULL); |
c906108c | 9526 | else |
58438ac1 | 9527 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL); |
c5aa993b | 9528 | |
c906108c | 9529 | if (sals.nelts != 1) |
8a3fe4f8 | 9530 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9531 | |
c906108c | 9532 | sal = sals.sals[0]; |
4a64f543 | 9533 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9534 | |
c906108c | 9535 | if (*arg) |
8a3fe4f8 | 9536 | error (_("Junk at end of arguments.")); |
c5aa993b | 9537 | |
c906108c | 9538 | resolve_sal_pc (&sal); |
c5aa993b | 9539 | |
ae66c1fc EZ |
9540 | if (anywhere) |
9541 | /* If the user told us to continue until a specified location, | |
9542 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9543 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9544 | null_frame_id, bp_until); | |
ae66c1fc | 9545 | else |
4a64f543 MS |
9546 | /* Otherwise, specify the selected frame, because we want to stop |
9547 | only at the very same frame. */ | |
a6d9a66e UW |
9548 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9549 | get_stack_frame_id (frame), | |
ae66c1fc | 9550 | bp_until); |
c5aa993b | 9551 | |
f107f563 | 9552 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9553 | |
186c406b TT |
9554 | tp = inferior_thread (); |
9555 | thread = tp->num; | |
9556 | ||
ae66c1fc EZ |
9557 | /* Keep within the current frame, or in frames called by the current |
9558 | one. */ | |
edb3359d DJ |
9559 | |
9560 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9561 | { |
edb3359d DJ |
9562 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9563 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9564 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9565 | sal, | |
edb3359d | 9566 | frame_unwind_caller_id (frame), |
f107f563 VP |
9567 | bp_until); |
9568 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9569 | |
9570 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9571 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9572 | } |
c5aa993b | 9573 | |
c906108c | 9574 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9575 | |
4a64f543 MS |
9576 | /* If we are running asynchronously, and proceed call above has |
9577 | actually managed to start the target, arrange for breakpoints to | |
9578 | be deleted when the target stops. Otherwise, we're already | |
9579 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9580 | |
8ea051c5 | 9581 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9582 | { |
bfec99b2 PA |
9583 | struct until_break_command_continuation_args *args; |
9584 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9585 | |
bfec99b2 PA |
9586 | args->breakpoint = breakpoint; |
9587 | args->breakpoint2 = breakpoint2; | |
186c406b | 9588 | args->thread_num = thread; |
f107f563 VP |
9589 | |
9590 | discard_cleanups (old_chain); | |
95e54da7 PA |
9591 | add_continuation (inferior_thread (), |
9592 | until_break_command_continuation, args, | |
604ead4a | 9593 | xfree); |
f107f563 VP |
9594 | } |
9595 | else | |
c5aa993b | 9596 | do_cleanups (old_chain); |
c906108c | 9597 | } |
ae66c1fc | 9598 | |
c906108c SS |
9599 | /* This function attempts to parse an optional "if <cond>" clause |
9600 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9601 | |
c906108c SS |
9602 | Else, it returns a pointer to the condition string. (It does not |
9603 | attempt to evaluate the string against a particular block.) And, | |
9604 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9605 | if clause in the arg string. */ |
53a5351d | 9606 | |
c906108c | 9607 | static char * |
fba45db2 | 9608 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9609 | { |
c5aa993b JM |
9610 | char *cond_string; |
9611 | ||
9612 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9613 | return NULL; |
c5aa993b | 9614 | |
4a64f543 | 9615 | /* Skip the "if" keyword. */ |
c906108c | 9616 | (*arg) += 2; |
c5aa993b | 9617 | |
c906108c | 9618 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9619 | condition string. */ |
e9cafbcc | 9620 | *arg = skip_spaces (*arg); |
c906108c | 9621 | cond_string = *arg; |
c5aa993b | 9622 | |
4a64f543 MS |
9623 | /* Assume that the condition occupies the remainder of the arg |
9624 | string. */ | |
c906108c | 9625 | (*arg) += strlen (cond_string); |
c5aa993b | 9626 | |
c906108c SS |
9627 | return cond_string; |
9628 | } | |
c5aa993b | 9629 | |
c906108c SS |
9630 | /* Commands to deal with catching events, such as signals, exceptions, |
9631 | process start/exit, etc. */ | |
c5aa993b JM |
9632 | |
9633 | typedef enum | |
9634 | { | |
44feb3ce TT |
9635 | catch_fork_temporary, catch_vfork_temporary, |
9636 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9637 | } |
9638 | catch_fork_kind; | |
9639 | ||
c906108c | 9640 | static void |
cc59ec59 MS |
9641 | catch_fork_command_1 (char *arg, int from_tty, |
9642 | struct cmd_list_element *command) | |
c906108c | 9643 | { |
a6d9a66e | 9644 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9645 | char *cond_string = NULL; |
44feb3ce TT |
9646 | catch_fork_kind fork_kind; |
9647 | int tempflag; | |
9648 | ||
9649 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9650 | tempflag = (fork_kind == catch_fork_temporary | |
9651 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9652 | |
44feb3ce TT |
9653 | if (!arg) |
9654 | arg = ""; | |
e9cafbcc | 9655 | arg = skip_spaces (arg); |
c5aa993b | 9656 | |
c906108c | 9657 | /* The allowed syntax is: |
c5aa993b JM |
9658 | catch [v]fork |
9659 | catch [v]fork if <cond> | |
9660 | ||
4a64f543 | 9661 | First, check if there's an if clause. */ |
c906108c | 9662 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9663 | |
c906108c | 9664 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9665 | error (_("Junk at end of arguments.")); |
c5aa993b | 9666 | |
c906108c | 9667 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9668 | and enable reporting of such events. */ |
c5aa993b JM |
9669 | switch (fork_kind) |
9670 | { | |
44feb3ce TT |
9671 | case catch_fork_temporary: |
9672 | case catch_fork_permanent: | |
a6d9a66e | 9673 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9674 | &catch_fork_breakpoint_ops); |
c906108c | 9675 | break; |
44feb3ce TT |
9676 | case catch_vfork_temporary: |
9677 | case catch_vfork_permanent: | |
a6d9a66e | 9678 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9679 | &catch_vfork_breakpoint_ops); |
c906108c | 9680 | break; |
c5aa993b | 9681 | default: |
8a3fe4f8 | 9682 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9683 | break; |
c5aa993b | 9684 | } |
c906108c SS |
9685 | } |
9686 | ||
9687 | static void | |
cc59ec59 MS |
9688 | catch_exec_command_1 (char *arg, int from_tty, |
9689 | struct cmd_list_element *command) | |
c906108c | 9690 | { |
b4d90040 | 9691 | struct exec_catchpoint *c; |
a6d9a66e | 9692 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9693 | int tempflag; |
c5aa993b | 9694 | char *cond_string = NULL; |
c906108c | 9695 | |
44feb3ce TT |
9696 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9697 | ||
9698 | if (!arg) | |
9699 | arg = ""; | |
e9cafbcc | 9700 | arg = skip_spaces (arg); |
c906108c SS |
9701 | |
9702 | /* The allowed syntax is: | |
c5aa993b JM |
9703 | catch exec |
9704 | catch exec if <cond> | |
c906108c | 9705 | |
4a64f543 | 9706 | First, check if there's an if clause. */ |
c906108c SS |
9707 | cond_string = ep_parse_optional_if_clause (&arg); |
9708 | ||
9709 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9710 | error (_("Junk at end of arguments.")); |
c906108c | 9711 | |
b4d90040 PA |
9712 | c = XNEW (struct exec_catchpoint); |
9713 | init_catchpoint (&c->base, gdbarch, tempflag, cond_string, | |
9714 | &catch_exec_breakpoint_ops); | |
9715 | c->exec_pathname = NULL; | |
9716 | ||
3a5c3e22 | 9717 | install_breakpoint (0, &c->base); |
c906108c | 9718 | } |
c5aa993b | 9719 | |
3086aeae | 9720 | static enum print_stop_action |
348d480f | 9721 | print_it_exception_catchpoint (bpstat bs) |
3086aeae | 9722 | { |
348d480f | 9723 | struct breakpoint *b = bs->breakpoint_at; |
ade92717 | 9724 | int bp_temp, bp_throw; |
3086aeae | 9725 | |
ade92717 | 9726 | annotate_catchpoint (b->number); |
3086aeae | 9727 | |
ade92717 AR |
9728 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9729 | if (b->loc->address != b->loc->requested_address) | |
9730 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9731 | b->loc->address, | |
9732 | b->number, 1); | |
df2b6d2d | 9733 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9734 | ui_out_text (uiout, |
9735 | bp_temp ? "Temporary catchpoint " | |
9736 | : "Catchpoint "); | |
9737 | if (!ui_out_is_mi_like_p (uiout)) | |
9738 | ui_out_field_int (uiout, "bkptno", b->number); | |
9739 | ui_out_text (uiout, | |
c0b37c48 AR |
9740 | bp_throw ? " (exception thrown), " |
9741 | : " (exception caught), "); | |
ade92717 AR |
9742 | if (ui_out_is_mi_like_p (uiout)) |
9743 | { | |
9744 | ui_out_field_string (uiout, "reason", | |
9745 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9746 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9747 | ui_out_field_int (uiout, "bkptno", b->number); | |
9748 | } | |
3086aeae DJ |
9749 | return PRINT_SRC_AND_LOC; |
9750 | } | |
9751 | ||
9752 | static void | |
cc59ec59 MS |
9753 | print_one_exception_catchpoint (struct breakpoint *b, |
9754 | struct bp_location **last_loc) | |
3086aeae | 9755 | { |
79a45b7d | 9756 | struct value_print_options opts; |
cc59ec59 | 9757 | |
79a45b7d TT |
9758 | get_user_print_options (&opts); |
9759 | if (opts.addressprint) | |
3086aeae DJ |
9760 | { |
9761 | annotate_field (4); | |
604133b5 AR |
9762 | if (b->loc == NULL || b->loc->shlib_disabled) |
9763 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9764 | else | |
5af949e3 UW |
9765 | ui_out_field_core_addr (uiout, "addr", |
9766 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9767 | } |
9768 | annotate_field (5); | |
604133b5 | 9769 | if (b->loc) |
a6d9a66e | 9770 | *last_loc = b->loc; |
3086aeae DJ |
9771 | if (strstr (b->addr_string, "throw") != NULL) |
9772 | ui_out_field_string (uiout, "what", "exception throw"); | |
9773 | else | |
9774 | ui_out_field_string (uiout, "what", "exception catch"); | |
9775 | } | |
9776 | ||
9777 | static void | |
9778 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9779 | { | |
ade92717 AR |
9780 | int bp_temp; |
9781 | int bp_throw; | |
9782 | ||
df2b6d2d | 9783 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9784 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9785 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9786 | : _("Catchpoint ")); | |
9787 | ui_out_field_int (uiout, "bkptno", b->number); | |
9788 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9789 | : _(" (catch)")); | |
3086aeae DJ |
9790 | } |
9791 | ||
6149aea9 PA |
9792 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9793 | catch catchpoints. */ | |
9794 | ||
9795 | static void | |
4a64f543 MS |
9796 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9797 | struct ui_file *fp) | |
6149aea9 PA |
9798 | { |
9799 | int bp_temp; | |
9800 | int bp_throw; | |
9801 | ||
9802 | bp_temp = b->disposition == disp_del; | |
9803 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9804 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9805 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
d9b3f62e | 9806 | print_recreate_thread (b, fp); |
6149aea9 PA |
9807 | } |
9808 | ||
2060206e | 9809 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops; |
3086aeae DJ |
9810 | |
9811 | static int | |
9812 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9813 | enum exception_event_kind ex_event, int from_tty) | |
9814 | { | |
604133b5 AR |
9815 | char *trigger_func_name; |
9816 | ||
3086aeae | 9817 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9818 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9819 | else |
604133b5 | 9820 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9821 | |
8cdf0e15 VP |
9822 | create_breakpoint (get_current_arch (), |
9823 | trigger_func_name, cond_string, -1, | |
9824 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9825 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9826 | 0, |
9827 | AUTO_BOOLEAN_TRUE /* pending */, | |
9828 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9829 | 1 /* enabled */, |
9830 | 0 /* internal */); | |
3086aeae | 9831 | |
3086aeae DJ |
9832 | return 1; |
9833 | } | |
9834 | ||
4a64f543 | 9835 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9836 | |
9837 | static void | |
fba45db2 KB |
9838 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9839 | int tempflag, int from_tty) | |
c906108c | 9840 | { |
c5aa993b | 9841 | char *cond_string = NULL; |
c5aa993b | 9842 | |
44feb3ce TT |
9843 | if (!arg) |
9844 | arg = ""; | |
e9cafbcc | 9845 | arg = skip_spaces (arg); |
c5aa993b | 9846 | |
c906108c SS |
9847 | cond_string = ep_parse_optional_if_clause (&arg); |
9848 | ||
9849 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9850 | error (_("Junk at end of arguments.")); |
c906108c | 9851 | |
059fb39f PM |
9852 | if (ex_event != EX_EVENT_THROW |
9853 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9854 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9855 | |
3086aeae DJ |
9856 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9857 | return; | |
9858 | ||
8a3fe4f8 | 9859 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9860 | } |
9861 | ||
44feb3ce TT |
9862 | /* Implementation of "catch catch" command. */ |
9863 | ||
9864 | static void | |
9865 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9866 | { | |
9867 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9868 | |
44feb3ce TT |
9869 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9870 | } | |
9871 | ||
9872 | /* Implementation of "catch throw" command. */ | |
9873 | ||
9874 | static void | |
9875 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9876 | { | |
9877 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9878 | |
44feb3ce TT |
9879 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9880 | } | |
9881 | ||
9ac4176b | 9882 | void |
28010a5d PA |
9883 | init_ada_exception_breakpoint (struct breakpoint *b, |
9884 | struct gdbarch *gdbarch, | |
9885 | struct symtab_and_line sal, | |
9886 | char *addr_string, | |
c0a91b2b | 9887 | const struct breakpoint_ops *ops, |
28010a5d PA |
9888 | int tempflag, |
9889 | int from_tty) | |
f7f9143b | 9890 | { |
f7f9143b JB |
9891 | if (from_tty) |
9892 | { | |
5af949e3 UW |
9893 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9894 | if (!loc_gdbarch) | |
9895 | loc_gdbarch = gdbarch; | |
9896 | ||
6c95b8df PA |
9897 | describe_other_breakpoints (loc_gdbarch, |
9898 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9899 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9900 | version for exception catchpoints, because two catchpoints | |
9901 | used for different exception names will use the same address. | |
9902 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9903 | unproductive. Besides, the warning phrasing is also a bit |
e5dd4106 | 9904 | inappropriate, we should use the word catchpoint, and tell |
f7f9143b JB |
9905 | the user what type of catchpoint it is. The above is good |
9906 | enough for now, though. */ | |
9907 | } | |
9908 | ||
28010a5d | 9909 | init_raw_breakpoint (b, gdbarch, sal, bp_breakpoint, ops); |
f7f9143b JB |
9910 | |
9911 | b->enable_state = bp_enabled; | |
9912 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
f7f9143b JB |
9913 | b->addr_string = addr_string; |
9914 | b->language = language_ada; | |
f7f9143b JB |
9915 | } |
9916 | ||
a96d9b2e SDJ |
9917 | /* Cleanup function for a syscall filter list. */ |
9918 | static void | |
9919 | clean_up_filters (void *arg) | |
9920 | { | |
9921 | VEC(int) *iter = *(VEC(int) **) arg; | |
9922 | VEC_free (int, iter); | |
9923 | } | |
9924 | ||
9925 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
9926 | filter list, or NULL if no filtering is required. */ | |
9927 | static VEC(int) * | |
9928 | catch_syscall_split_args (char *arg) | |
9929 | { | |
9930 | VEC(int) *result = NULL; | |
9931 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
9932 | ||
9933 | while (*arg != '\0') | |
9934 | { | |
9935 | int i, syscall_number; | |
9936 | char *endptr; | |
9937 | char cur_name[128]; | |
9938 | struct syscall s; | |
9939 | ||
9940 | /* Skip whitespace. */ | |
9941 | while (isspace (*arg)) | |
9942 | arg++; | |
9943 | ||
9944 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9945 | cur_name[i] = arg[i]; | |
9946 | cur_name[i] = '\0'; | |
9947 | arg += i; | |
9948 | ||
9949 | /* Check if the user provided a syscall name or a number. */ | |
9950 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9951 | if (*endptr == '\0') | |
bccd0dd2 | 9952 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9953 | else |
9954 | { | |
9955 | /* We have a name. Let's check if it's valid and convert it | |
9956 | to a number. */ | |
9957 | get_syscall_by_name (cur_name, &s); | |
9958 | ||
9959 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9960 | /* Here we have to issue an error instead of a warning, |
9961 | because GDB cannot do anything useful if there's no | |
9962 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9963 | error (_("Unknown syscall name '%s'."), cur_name); |
9964 | } | |
9965 | ||
9966 | /* Ok, it's valid. */ | |
9967 | VEC_safe_push (int, result, s.number); | |
9968 | } | |
9969 | ||
9970 | discard_cleanups (cleanup); | |
9971 | return result; | |
9972 | } | |
9973 | ||
9974 | /* Implement the "catch syscall" command. */ | |
9975 | ||
9976 | static void | |
cc59ec59 MS |
9977 | catch_syscall_command_1 (char *arg, int from_tty, |
9978 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
9979 | { |
9980 | int tempflag; | |
9981 | VEC(int) *filter; | |
9982 | struct syscall s; | |
9983 | struct gdbarch *gdbarch = get_current_arch (); | |
9984 | ||
9985 | /* Checking if the feature if supported. */ | |
9986 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
9987 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 9988 | this architecture yet.")); |
a96d9b2e SDJ |
9989 | |
9990 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
9991 | ||
e9cafbcc | 9992 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
9993 | |
9994 | /* We need to do this first "dummy" translation in order | |
9995 | to get the syscall XML file loaded or, most important, | |
9996 | to display a warning to the user if there's no XML file | |
9997 | for his/her architecture. */ | |
9998 | get_syscall_by_number (0, &s); | |
9999 | ||
10000 | /* The allowed syntax is: | |
10001 | catch syscall | |
10002 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10003 | ||
10004 | Let's check if there's a syscall name. */ | |
10005 | ||
10006 | if (arg != NULL) | |
10007 | filter = catch_syscall_split_args (arg); | |
10008 | else | |
10009 | filter = NULL; | |
10010 | ||
10011 | create_syscall_event_catchpoint (tempflag, filter, | |
10012 | &catch_syscall_breakpoint_ops); | |
10013 | } | |
10014 | ||
c906108c | 10015 | static void |
fba45db2 | 10016 | catch_command (char *arg, int from_tty) |
c906108c | 10017 | { |
44feb3ce | 10018 | error (_("Catch requires an event name.")); |
c906108c SS |
10019 | } |
10020 | \f | |
10021 | ||
10022 | static void | |
fba45db2 | 10023 | tcatch_command (char *arg, int from_tty) |
c906108c | 10024 | { |
44feb3ce | 10025 | error (_("Catch requires an event name.")); |
c906108c SS |
10026 | } |
10027 | ||
80f8a6eb | 10028 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10029 | |
10030 | static void | |
fba45db2 | 10031 | clear_command (char *arg, int from_tty) |
c906108c | 10032 | { |
d6e956e5 VP |
10033 | struct breakpoint *b; |
10034 | VEC(breakpoint_p) *found = 0; | |
10035 | int ix; | |
c906108c SS |
10036 | int default_match; |
10037 | struct symtabs_and_lines sals; | |
10038 | struct symtab_and_line sal; | |
c906108c SS |
10039 | int i; |
10040 | ||
10041 | if (arg) | |
10042 | { | |
10043 | sals = decode_line_spec (arg, 1); | |
10044 | default_match = 0; | |
10045 | } | |
10046 | else | |
10047 | { | |
c5aa993b | 10048 | sals.sals = (struct symtab_and_line *) |
c906108c | 10049 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10050 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10051 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
10052 | sal.line = default_breakpoint_line; |
10053 | sal.symtab = default_breakpoint_symtab; | |
10054 | sal.pc = default_breakpoint_address; | |
6c95b8df | 10055 | sal.pspace = default_breakpoint_pspace; |
c906108c | 10056 | if (sal.symtab == 0) |
8a3fe4f8 | 10057 | error (_("No source file specified.")); |
c906108c SS |
10058 | |
10059 | sals.sals[0] = sal; | |
10060 | sals.nelts = 1; | |
10061 | ||
10062 | default_match = 1; | |
10063 | } | |
10064 | ||
4a64f543 MS |
10065 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10066 | seems, because all existing breakpoints typically have both | |
10067 | file/line and pc set. So, if clear is given file/line, we can | |
10068 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10069 | |
10070 | We only support clearing given the address explicitly | |
10071 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10072 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10073 | due to optimization, all in one block. |
4a64f543 MS |
10074 | |
10075 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10076 | PC corresponding to the same file:line, the breakpoint won't |
10077 | be cleared. We probably can still clear the breakpoint, but | |
10078 | since the other PC value is never presented to user, user | |
10079 | can only find it by guessing, and it does not seem important | |
10080 | to support that. */ | |
10081 | ||
4a64f543 MS |
10082 | /* For each line spec given, delete bps which correspond to it. Do |
10083 | it in two passes, solely to preserve the current behavior that | |
10084 | from_tty is forced true if we delete more than one | |
10085 | breakpoint. */ | |
c906108c | 10086 | |
80f8a6eb | 10087 | found = NULL; |
c906108c SS |
10088 | for (i = 0; i < sals.nelts; i++) |
10089 | { | |
10090 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
10091 | If line given (pc == 0), clear all bpts on specified line. |
10092 | If defaulting, clear all bpts on default line | |
c906108c | 10093 | or at default pc. |
c5aa993b JM |
10094 | |
10095 | defaulting sal.pc != 0 tests to do | |
10096 | ||
10097 | 0 1 pc | |
10098 | 1 1 pc _and_ line | |
10099 | 0 0 line | |
10100 | 1 0 <can't happen> */ | |
c906108c SS |
10101 | |
10102 | sal = sals.sals[i]; | |
c906108c | 10103 | |
4a64f543 | 10104 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10105 | ALL_BREAKPOINTS (b) |
c5aa993b | 10106 | { |
0d381245 | 10107 | int match = 0; |
4a64f543 | 10108 | /* Are we going to delete b? */ |
cc60f2e3 | 10109 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10110 | { |
10111 | struct bp_location *loc = b->loc; | |
10112 | for (; loc; loc = loc->next) | |
10113 | { | |
6c95b8df PA |
10114 | int pc_match = sal.pc |
10115 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
10116 | && (loc->address == sal.pc) |
10117 | && (!section_is_overlay (loc->section) | |
10118 | || loc->section == sal.section); | |
10119 | int line_match = ((default_match || (0 == sal.pc)) | |
10120 | && b->source_file != NULL | |
10121 | && sal.symtab != NULL | |
6c95b8df | 10122 | && sal.pspace == loc->pspace |
0ba1096a KT |
10123 | && filename_cmp (b->source_file, |
10124 | sal.symtab->filename) == 0 | |
0d381245 VP |
10125 | && b->line_number == sal.line); |
10126 | if (pc_match || line_match) | |
10127 | { | |
10128 | match = 1; | |
10129 | break; | |
10130 | } | |
10131 | } | |
10132 | } | |
10133 | ||
10134 | if (match) | |
d6e956e5 | 10135 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10136 | } |
80f8a6eb MS |
10137 | } |
10138 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 10139 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10140 | { |
10141 | if (arg) | |
8a3fe4f8 | 10142 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10143 | else |
8a3fe4f8 | 10144 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10145 | } |
c906108c | 10146 | |
d6e956e5 | 10147 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10148 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10149 | if (from_tty) |
a3f17187 | 10150 | { |
d6e956e5 | 10151 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10152 | printf_unfiltered (_("Deleted breakpoint ")); |
10153 | else | |
10154 | printf_unfiltered (_("Deleted breakpoints ")); | |
10155 | } | |
80f8a6eb | 10156 | breakpoints_changed (); |
d6e956e5 VP |
10157 | |
10158 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10159 | { |
c5aa993b | 10160 | if (from_tty) |
d6e956e5 VP |
10161 | printf_unfiltered ("%d ", b->number); |
10162 | delete_breakpoint (b); | |
c906108c | 10163 | } |
80f8a6eb MS |
10164 | if (from_tty) |
10165 | putchar_unfiltered ('\n'); | |
c906108c SS |
10166 | } |
10167 | \f | |
10168 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10169 | all breakpoints that are marked for deletion, whether hit or not. | |
10170 | This is called after any breakpoint is hit, or after errors. */ | |
10171 | ||
10172 | void | |
fba45db2 | 10173 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10174 | { |
35df4500 | 10175 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10176 | |
10177 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10178 | if (bs->breakpoint_at |
10179 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10180 | && bs->stop) |
f431efe5 | 10181 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10182 | |
35df4500 | 10183 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10184 | { |
b5de0fa7 | 10185 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10186 | delete_breakpoint (b); |
10187 | } | |
c906108c SS |
10188 | } |
10189 | ||
4a64f543 MS |
10190 | /* A comparison function for bp_location AP and BP being interfaced to |
10191 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10192 | does breakpoint_address_is_meaningful say for its OWNER), | |
10193 | secondarily by ordering first bp_permanent OWNERed elements and | |
10194 | terciarily just ensuring the array is sorted stable way despite | |
e5dd4106 | 10195 | qsort being an unstable algorithm. */ |
876fa593 JK |
10196 | |
10197 | static int | |
494cfb0f | 10198 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10199 | { |
494cfb0f JK |
10200 | struct bp_location *a = *(void **) ap; |
10201 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10202 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10203 | int a_perm = a->owner->enable_state == bp_permanent; |
10204 | int b_perm = b->owner->enable_state == bp_permanent; | |
10205 | ||
10206 | if (a->address != b->address) | |
10207 | return (a->address > b->address) - (a->address < b->address); | |
10208 | ||
10209 | /* Sort permanent breakpoints first. */ | |
10210 | if (a_perm != b_perm) | |
10211 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10212 | ||
4a64f543 MS |
10213 | /* Make the user-visible order stable across GDB runs. Locations of |
10214 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10215 | |
10216 | if (a->owner->number != b->owner->number) | |
10217 | return (a->owner->number > b->owner->number) | |
10218 | - (a->owner->number < b->owner->number); | |
10219 | ||
10220 | return (a > b) - (a < b); | |
10221 | } | |
10222 | ||
876fa593 | 10223 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10224 | bp_location_shadow_len_after_address_max according to the current |
10225 | content of the bp_location array. */ | |
f7545552 TT |
10226 | |
10227 | static void | |
876fa593 | 10228 | bp_location_target_extensions_update (void) |
f7545552 | 10229 | { |
876fa593 JK |
10230 | struct bp_location *bl, **blp_tmp; |
10231 | ||
10232 | bp_location_placed_address_before_address_max = 0; | |
10233 | bp_location_shadow_len_after_address_max = 0; | |
10234 | ||
10235 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10236 | { | |
10237 | CORE_ADDR start, end, addr; | |
10238 | ||
10239 | if (!bp_location_has_shadow (bl)) | |
10240 | continue; | |
10241 | ||
10242 | start = bl->target_info.placed_address; | |
10243 | end = start + bl->target_info.shadow_len; | |
10244 | ||
10245 | gdb_assert (bl->address >= start); | |
10246 | addr = bl->address - start; | |
10247 | if (addr > bp_location_placed_address_before_address_max) | |
10248 | bp_location_placed_address_before_address_max = addr; | |
10249 | ||
10250 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10251 | ||
10252 | gdb_assert (bl->address < end); | |
10253 | addr = end - bl->address; | |
10254 | if (addr > bp_location_shadow_len_after_address_max) | |
10255 | bp_location_shadow_len_after_address_max = addr; | |
10256 | } | |
f7545552 TT |
10257 | } |
10258 | ||
934709f0 PW |
10259 | /* Swap the insertion/duplication state between two locations. */ |
10260 | ||
10261 | static void | |
10262 | swap_insertion (struct bp_location *left, struct bp_location *right) | |
10263 | { | |
10264 | const int left_inserted = left->inserted; | |
10265 | const int left_duplicate = left->duplicate; | |
10266 | const struct bp_target_info left_target_info = left->target_info; | |
10267 | ||
10268 | left->inserted = right->inserted; | |
10269 | left->duplicate = right->duplicate; | |
10270 | left->target_info = right->target_info; | |
10271 | right->inserted = left_inserted; | |
10272 | right->duplicate = left_duplicate; | |
10273 | right->target_info = left_target_info; | |
10274 | } | |
10275 | ||
4cd9bd08 | 10276 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10277 | into the inferior, only remove already-inserted locations that no |
10278 | longer should be inserted. Functions that delete a breakpoint or | |
10279 | breakpoints should pass false, so that deleting a breakpoint | |
10280 | doesn't have the side effect of inserting the locations of other | |
10281 | breakpoints that are marked not-inserted, but should_be_inserted | |
10282 | returns true on them. | |
10283 | ||
10284 | This behaviour is useful is situations close to tear-down -- e.g., | |
10285 | after an exec, while the target still has execution, but breakpoint | |
10286 | shadows of the previous executable image should *NOT* be restored | |
10287 | to the new image; or before detaching, where the target still has | |
10288 | execution and wants to delete breakpoints from GDB's lists, and all | |
10289 | breakpoints had already been removed from the inferior. */ | |
10290 | ||
0d381245 | 10291 | static void |
b60e7edf | 10292 | update_global_location_list (int should_insert) |
0d381245 | 10293 | { |
74960c60 | 10294 | struct breakpoint *b; |
876fa593 | 10295 | struct bp_location **locp, *loc; |
f7545552 TT |
10296 | struct cleanup *cleanups; |
10297 | ||
2d134ed3 PA |
10298 | /* Used in the duplicates detection below. When iterating over all |
10299 | bp_locations, points to the first bp_location of a given address. | |
10300 | Breakpoints and watchpoints of different types are never | |
10301 | duplicates of each other. Keep one pointer for each type of | |
10302 | breakpoint/watchpoint, so we only need to loop over all locations | |
10303 | once. */ | |
10304 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10305 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10306 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10307 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10308 | |
4a64f543 MS |
10309 | /* Saved former bp_location array which we compare against the newly |
10310 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10311 | struct bp_location **old_location, **old_locp; |
10312 | unsigned old_location_count; | |
10313 | ||
10314 | old_location = bp_location; | |
10315 | old_location_count = bp_location_count; | |
10316 | bp_location = NULL; | |
10317 | bp_location_count = 0; | |
10318 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10319 | |
74960c60 | 10320 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10321 | for (loc = b->loc; loc; loc = loc->next) |
10322 | bp_location_count++; | |
10323 | ||
10324 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10325 | locp = bp_location; | |
10326 | ALL_BREAKPOINTS (b) | |
10327 | for (loc = b->loc; loc; loc = loc->next) | |
10328 | *locp++ = loc; | |
10329 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10330 | bp_location_compare); |
876fa593 JK |
10331 | |
10332 | bp_location_target_extensions_update (); | |
74960c60 | 10333 | |
4a64f543 MS |
10334 | /* Identify bp_location instances that are no longer present in the |
10335 | new list, and therefore should be freed. Note that it's not | |
10336 | necessary that those locations should be removed from inferior -- | |
10337 | if there's another location at the same address (previously | |
10338 | marked as duplicate), we don't need to remove/insert the | |
10339 | location. | |
876fa593 | 10340 | |
4a64f543 MS |
10341 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10342 | and former bp_location array state respectively. */ | |
876fa593 JK |
10343 | |
10344 | locp = bp_location; | |
10345 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10346 | old_locp++) | |
74960c60 | 10347 | { |
876fa593 | 10348 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10349 | struct bp_location **loc2p; |
876fa593 | 10350 | |
e5dd4106 | 10351 | /* Tells if 'old_loc' is found among the new locations. If |
4a64f543 | 10352 | not, we have to free it. */ |
c7d46a38 | 10353 | int found_object = 0; |
20874c92 VP |
10354 | /* Tells if the location should remain inserted in the target. */ |
10355 | int keep_in_target = 0; | |
10356 | int removed = 0; | |
876fa593 | 10357 | |
4a64f543 MS |
10358 | /* Skip LOCP entries which will definitely never be needed. |
10359 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10360 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10361 | && (*locp)->address < old_loc->address) |
876fa593 | 10362 | locp++; |
c7d46a38 PA |
10363 | |
10364 | for (loc2p = locp; | |
10365 | (loc2p < bp_location + bp_location_count | |
10366 | && (*loc2p)->address == old_loc->address); | |
10367 | loc2p++) | |
10368 | { | |
10369 | if (*loc2p == old_loc) | |
10370 | { | |
10371 | found_object = 1; | |
10372 | break; | |
10373 | } | |
10374 | } | |
74960c60 | 10375 | |
4a64f543 MS |
10376 | /* If this location is no longer present, and inserted, look if |
10377 | there's maybe a new location at the same address. If so, | |
10378 | mark that one inserted, and don't remove this one. This is | |
10379 | needed so that we don't have a time window where a breakpoint | |
10380 | at certain location is not inserted. */ | |
74960c60 | 10381 | |
876fa593 | 10382 | if (old_loc->inserted) |
0d381245 | 10383 | { |
4a64f543 MS |
10384 | /* If the location is inserted now, we might have to remove |
10385 | it. */ | |
74960c60 | 10386 | |
876fa593 | 10387 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10388 | { |
4a64f543 MS |
10389 | /* The location is still present in the location list, |
10390 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10391 | keep_in_target = 1; |
74960c60 VP |
10392 | } |
10393 | else | |
10394 | { | |
4a64f543 MS |
10395 | /* The location is either no longer present, or got |
10396 | disabled. See if there's another location at the | |
10397 | same address, in which case we don't need to remove | |
10398 | this one from the target. */ | |
876fa593 | 10399 | |
2bdf28a0 | 10400 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10401 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10402 | { | |
876fa593 | 10403 | for (loc2p = locp; |
c7d46a38 PA |
10404 | (loc2p < bp_location + bp_location_count |
10405 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10406 | loc2p++) |
10407 | { | |
10408 | struct bp_location *loc2 = *loc2p; | |
10409 | ||
2d134ed3 | 10410 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 | 10411 | { |
85d721b8 PA |
10412 | /* Read watchpoint locations are switched to |
10413 | access watchpoints, if the former are not | |
10414 | supported, but the latter are. */ | |
10415 | if (is_hardware_watchpoint (old_loc->owner)) | |
10416 | { | |
10417 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10418 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10419 | } | |
10420 | ||
934709f0 PW |
10421 | /* loc2 is a duplicated location. We need to check |
10422 | if it should be inserted in case it will be | |
10423 | unduplicated. */ | |
10424 | if (loc2 != old_loc | |
10425 | && unduplicated_should_be_inserted (loc2)) | |
c7d46a38 | 10426 | { |
934709f0 | 10427 | swap_insertion (old_loc, loc2); |
c7d46a38 PA |
10428 | keep_in_target = 1; |
10429 | break; | |
10430 | } | |
876fa593 JK |
10431 | } |
10432 | } | |
10433 | } | |
74960c60 VP |
10434 | } |
10435 | ||
20874c92 VP |
10436 | if (!keep_in_target) |
10437 | { | |
876fa593 | 10438 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10439 | { |
4a64f543 MS |
10440 | /* This is just about all we can do. We could keep |
10441 | this location on the global list, and try to | |
10442 | remove it next time, but there's no particular | |
10443 | reason why we will succeed next time. | |
20874c92 | 10444 | |
4a64f543 MS |
10445 | Note that at this point, old_loc->owner is still |
10446 | valid, as delete_breakpoint frees the breakpoint | |
10447 | only after calling us. */ | |
3e43a32a MS |
10448 | printf_filtered (_("warning: Error removing " |
10449 | "breakpoint %d\n"), | |
876fa593 | 10450 | old_loc->owner->number); |
20874c92 VP |
10451 | } |
10452 | removed = 1; | |
10453 | } | |
0d381245 | 10454 | } |
74960c60 VP |
10455 | |
10456 | if (!found_object) | |
1c5cfe86 | 10457 | { |
db82e815 PA |
10458 | if (removed && non_stop |
10459 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10460 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10461 | { |
db82e815 PA |
10462 | /* This location was removed from the target. In |
10463 | non-stop mode, a race condition is possible where | |
10464 | we've removed a breakpoint, but stop events for that | |
10465 | breakpoint are already queued and will arrive later. | |
10466 | We apply an heuristic to be able to distinguish such | |
10467 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10468 | breakpoint location for a bit, and will retire it | |
10469 | after we see some number of events. The theory here | |
10470 | is that reporting of events should, "on the average", | |
10471 | be fair, so after a while we'll see events from all | |
10472 | threads that have anything of interest, and no longer | |
10473 | need to keep this breakpoint location around. We | |
10474 | don't hold locations forever so to reduce chances of | |
10475 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10476 | SIGTRAP. | |
10477 | ||
10478 | The heuristic failing can be disastrous on | |
10479 | decr_pc_after_break targets. | |
10480 | ||
10481 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10482 | if we fail to recognize a late breakpoint SIGTRAP, | |
10483 | because events_till_retirement has reached 0 too | |
10484 | soon, we'll fail to do the PC adjustment, and report | |
10485 | a random SIGTRAP to the user. When the user resumes | |
10486 | the inferior, it will most likely immediately crash | |
2dec564e | 10487 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10488 | corrupted, because of being resumed e.g., in the |
10489 | middle of a multi-byte instruction, or skipped a | |
10490 | one-byte instruction. This was actually seen happen | |
10491 | on native x86-linux, and should be less rare on | |
10492 | targets that do not support new thread events, like | |
10493 | remote, due to the heuristic depending on | |
10494 | thread_count. | |
10495 | ||
10496 | Mistaking a random SIGTRAP for a breakpoint trap | |
10497 | causes similar symptoms (PC adjustment applied when | |
10498 | it shouldn't), but then again, playing with SIGTRAPs | |
10499 | behind the debugger's back is asking for trouble. | |
10500 | ||
10501 | Since hardware watchpoint traps are always | |
10502 | distinguishable from other traps, so we don't need to | |
10503 | apply keep hardware watchpoint moribund locations | |
10504 | around. We simply always ignore hardware watchpoint | |
10505 | traps we can no longer explain. */ | |
10506 | ||
876fa593 JK |
10507 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10508 | old_loc->owner = NULL; | |
20874c92 | 10509 | |
876fa593 | 10510 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10511 | } |
10512 | else | |
f431efe5 PA |
10513 | { |
10514 | old_loc->owner = NULL; | |
10515 | decref_bp_location (&old_loc); | |
10516 | } | |
20874c92 | 10517 | } |
74960c60 | 10518 | } |
1c5cfe86 | 10519 | |
348d480f PA |
10520 | /* Rescan breakpoints at the same address and section, marking the |
10521 | first one as "first" and any others as "duplicates". This is so | |
10522 | that the bpt instruction is only inserted once. If we have a | |
10523 | permanent breakpoint at the same place as BPT, make that one the | |
10524 | official one, and the rest as duplicates. Permanent breakpoints | |
10525 | are sorted first for the same address. | |
10526 | ||
10527 | Do the same for hardware watchpoints, but also considering the | |
10528 | watchpoint's type (regular/access/read) and length. */ | |
10529 | ||
10530 | bp_loc_first = NULL; | |
10531 | wp_loc_first = NULL; | |
10532 | awp_loc_first = NULL; | |
10533 | rwp_loc_first = NULL; | |
10534 | ALL_BP_LOCATIONS (loc, locp) | |
10535 | { | |
10536 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always | |
10537 | non-NULL. */ | |
10538 | struct breakpoint *b = loc->owner; | |
10539 | struct bp_location **loc_first_p; | |
10540 | ||
10541 | if (b->enable_state == bp_disabled | |
10542 | || b->enable_state == bp_call_disabled | |
10543 | || b->enable_state == bp_startup_disabled | |
10544 | || !loc->enabled | |
10545 | || loc->shlib_disabled | |
10546 | || !breakpoint_address_is_meaningful (b) | |
10547 | || is_tracepoint (b)) | |
10548 | continue; | |
10549 | ||
10550 | /* Permanent breakpoint should always be inserted. */ | |
10551 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10552 | internal_error (__FILE__, __LINE__, | |
10553 | _("allegedly permanent breakpoint is not " | |
10554 | "actually inserted")); | |
10555 | ||
10556 | if (b->type == bp_hardware_watchpoint) | |
10557 | loc_first_p = &wp_loc_first; | |
10558 | else if (b->type == bp_read_watchpoint) | |
10559 | loc_first_p = &rwp_loc_first; | |
10560 | else if (b->type == bp_access_watchpoint) | |
10561 | loc_first_p = &awp_loc_first; | |
10562 | else | |
10563 | loc_first_p = &bp_loc_first; | |
10564 | ||
10565 | if (*loc_first_p == NULL | |
10566 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10567 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
10568 | { | |
10569 | *loc_first_p = loc; | |
10570 | loc->duplicate = 0; | |
10571 | continue; | |
10572 | } | |
10573 | ||
934709f0 PW |
10574 | |
10575 | /* This and the above ensure the invariant that the first location | |
10576 | is not duplicated, and is the inserted one. | |
10577 | All following are marked as duplicated, and are not inserted. */ | |
10578 | if (loc->inserted) | |
10579 | swap_insertion (loc, *loc_first_p); | |
348d480f PA |
10580 | loc->duplicate = 1; |
10581 | ||
10582 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted | |
10583 | && b->enable_state != bp_permanent) | |
10584 | internal_error (__FILE__, __LINE__, | |
10585 | _("another breakpoint was inserted on top of " | |
10586 | "a permanent breakpoint")); | |
10587 | } | |
10588 | ||
10589 | if (breakpoints_always_inserted_mode () && should_insert | |
10590 | && (have_live_inferiors () | |
10591 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) | |
10592 | insert_breakpoint_locations (); | |
10593 | ||
10594 | do_cleanups (cleanups); | |
10595 | } | |
10596 | ||
10597 | void | |
10598 | breakpoint_retire_moribund (void) | |
10599 | { | |
10600 | struct bp_location *loc; | |
10601 | int ix; | |
10602 | ||
10603 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10604 | if (--(loc->events_till_retirement) == 0) | |
10605 | { | |
10606 | decref_bp_location (&loc); | |
10607 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
10608 | --ix; | |
10609 | } | |
10610 | } | |
10611 | ||
10612 | static void | |
10613 | update_global_location_list_nothrow (int inserting) | |
10614 | { | |
10615 | struct gdb_exception e; | |
10616 | ||
10617 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10618 | update_global_location_list (inserting); | |
10619 | } | |
10620 | ||
10621 | /* Clear BKP from a BPS. */ | |
10622 | ||
10623 | static void | |
10624 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) | |
10625 | { | |
10626 | bpstat bs; | |
10627 | ||
10628 | for (bs = bps; bs; bs = bs->next) | |
10629 | if (bs->breakpoint_at == bpt) | |
10630 | { | |
10631 | bs->breakpoint_at = NULL; | |
10632 | bs->old_val = NULL; | |
10633 | /* bs->commands will be freed later. */ | |
10634 | } | |
10635 | } | |
10636 | ||
10637 | /* Callback for iterate_over_threads. */ | |
10638 | static int | |
10639 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
10640 | { | |
10641 | struct breakpoint *bpt = data; | |
10642 | ||
10643 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); | |
10644 | return 0; | |
10645 | } | |
10646 | ||
10647 | /* Helper for breakpoint and tracepoint breakpoint_ops->mention | |
10648 | callbacks. */ | |
10649 | ||
10650 | static void | |
10651 | say_where (struct breakpoint *b) | |
10652 | { | |
10653 | struct value_print_options opts; | |
10654 | ||
10655 | get_user_print_options (&opts); | |
10656 | ||
10657 | /* i18n: cagney/2005-02-11: Below needs to be merged into a | |
10658 | single string. */ | |
10659 | if (b->loc == NULL) | |
10660 | { | |
10661 | printf_filtered (_(" (%s) pending."), b->addr_string); | |
10662 | } | |
10663 | else | |
10664 | { | |
10665 | if (opts.addressprint || b->source_file == NULL) | |
10666 | { | |
10667 | printf_filtered (" at "); | |
10668 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), | |
10669 | gdb_stdout); | |
10670 | } | |
10671 | if (b->source_file) | |
10672 | printf_filtered (": file %s, line %d.", | |
10673 | b->source_file, b->line_number); | |
10674 | ||
10675 | if (b->loc->next) | |
10676 | { | |
10677 | struct bp_location *loc = b->loc; | |
10678 | int n = 0; | |
10679 | for (; loc; loc = loc->next) | |
10680 | ++n; | |
10681 | printf_filtered (" (%d locations)", n); | |
10682 | } | |
10683 | } | |
10684 | } | |
10685 | ||
348d480f PA |
10686 | /* Default bp_location_ops methods. */ |
10687 | ||
10688 | static void | |
10689 | bp_location_dtor (struct bp_location *self) | |
10690 | { | |
10691 | xfree (self->cond); | |
10692 | xfree (self->function_name); | |
10693 | } | |
10694 | ||
10695 | static const struct bp_location_ops bp_location_ops = | |
10696 | { | |
10697 | bp_location_dtor | |
10698 | }; | |
10699 | ||
2060206e PA |
10700 | /* Default breakpoint_ops methods all breakpoint_ops ultimately |
10701 | inherit from. */ | |
348d480f | 10702 | |
2060206e PA |
10703 | static void |
10704 | base_breakpoint_dtor (struct breakpoint *self) | |
348d480f PA |
10705 | { |
10706 | decref_counted_command_line (&self->commands); | |
10707 | xfree (self->cond_string); | |
348d480f PA |
10708 | xfree (self->addr_string); |
10709 | xfree (self->addr_string_range_end); | |
348d480f PA |
10710 | xfree (self->source_file); |
10711 | } | |
10712 | ||
2060206e PA |
10713 | static struct bp_location * |
10714 | base_breakpoint_allocate_location (struct breakpoint *self) | |
348d480f PA |
10715 | { |
10716 | struct bp_location *loc; | |
10717 | ||
10718 | loc = XNEW (struct bp_location); | |
10719 | init_bp_location (loc, &bp_location_ops, self); | |
10720 | return loc; | |
10721 | } | |
10722 | ||
2060206e PA |
10723 | static void |
10724 | base_breakpoint_re_set (struct breakpoint *b) | |
10725 | { | |
10726 | /* Nothing to re-set. */ | |
10727 | } | |
10728 | ||
10729 | #define internal_error_pure_virtual_called() \ | |
10730 | gdb_assert_not_reached ("pure virtual function called") | |
10731 | ||
10732 | static int | |
10733 | base_breakpoint_insert_location (struct bp_location *bl) | |
10734 | { | |
10735 | internal_error_pure_virtual_called (); | |
10736 | } | |
10737 | ||
10738 | static int | |
10739 | base_breakpoint_remove_location (struct bp_location *bl) | |
10740 | { | |
10741 | internal_error_pure_virtual_called (); | |
10742 | } | |
10743 | ||
10744 | static int | |
10745 | base_breakpoint_breakpoint_hit (const struct bp_location *bl, | |
10746 | struct address_space *aspace, | |
10747 | CORE_ADDR bp_addr) | |
10748 | { | |
10749 | internal_error_pure_virtual_called (); | |
10750 | } | |
10751 | ||
10752 | static void | |
10753 | base_breakpoint_check_status (bpstat bs) | |
10754 | { | |
10755 | /* Always stop. */ | |
10756 | } | |
10757 | ||
10758 | /* A "works_in_software_mode" breakpoint_ops method that just internal | |
10759 | errors. */ | |
10760 | ||
10761 | static int | |
10762 | base_breakpoint_works_in_software_mode (const struct breakpoint *b) | |
10763 | { | |
10764 | internal_error_pure_virtual_called (); | |
10765 | } | |
10766 | ||
10767 | /* A "resources_needed" breakpoint_ops method that just internal | |
10768 | errors. */ | |
10769 | ||
10770 | static int | |
10771 | base_breakpoint_resources_needed (const struct bp_location *bl) | |
10772 | { | |
10773 | internal_error_pure_virtual_called (); | |
10774 | } | |
10775 | ||
10776 | static enum print_stop_action | |
10777 | base_breakpoint_print_it (bpstat bs) | |
10778 | { | |
10779 | internal_error_pure_virtual_called (); | |
10780 | } | |
10781 | ||
10782 | static void | |
10783 | base_breakpoint_print_one_detail (const struct breakpoint *self, | |
10784 | struct ui_out *uiout) | |
10785 | { | |
10786 | /* nothing */ | |
10787 | } | |
10788 | ||
10789 | static void | |
10790 | base_breakpoint_print_mention (struct breakpoint *b) | |
10791 | { | |
10792 | internal_error_pure_virtual_called (); | |
10793 | } | |
10794 | ||
10795 | static void | |
10796 | base_breakpoint_print_recreate (struct breakpoint *b, struct ui_file *fp) | |
10797 | { | |
10798 | internal_error_pure_virtual_called (); | |
10799 | } | |
10800 | ||
10801 | static struct breakpoint_ops base_breakpoint_ops = | |
10802 | { | |
10803 | base_breakpoint_dtor, | |
10804 | base_breakpoint_allocate_location, | |
10805 | base_breakpoint_re_set, | |
10806 | base_breakpoint_insert_location, | |
10807 | base_breakpoint_remove_location, | |
10808 | base_breakpoint_breakpoint_hit, | |
10809 | base_breakpoint_check_status, | |
10810 | base_breakpoint_resources_needed, | |
10811 | base_breakpoint_works_in_software_mode, | |
10812 | base_breakpoint_print_it, | |
10813 | NULL, | |
10814 | base_breakpoint_print_one_detail, | |
10815 | base_breakpoint_print_mention, | |
10816 | base_breakpoint_print_recreate | |
10817 | }; | |
10818 | ||
10819 | /* Default breakpoint_ops methods. */ | |
10820 | ||
10821 | static void | |
348d480f PA |
10822 | bkpt_re_set (struct breakpoint *b) |
10823 | { | |
06edf0c0 PA |
10824 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10825 | if (b->enable_state == bp_startup_disabled) | |
10826 | return; | |
348d480f | 10827 | |
06edf0c0 PA |
10828 | /* FIXME: is this still reachable? */ |
10829 | if (b->addr_string == NULL) | |
10830 | { | |
10831 | /* Anything without a string can't be re-set. */ | |
348d480f | 10832 | delete_breakpoint (b); |
06edf0c0 | 10833 | return; |
348d480f | 10834 | } |
06edf0c0 PA |
10835 | |
10836 | breakpoint_re_set_default (b); | |
348d480f PA |
10837 | } |
10838 | ||
2060206e | 10839 | static int |
348d480f PA |
10840 | bkpt_insert_location (struct bp_location *bl) |
10841 | { | |
10842 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10843 | return target_insert_hw_breakpoint (bl->gdbarch, | |
10844 | &bl->target_info); | |
10845 | else | |
10846 | return target_insert_breakpoint (bl->gdbarch, | |
10847 | &bl->target_info); | |
10848 | } | |
10849 | ||
2060206e | 10850 | static int |
348d480f PA |
10851 | bkpt_remove_location (struct bp_location *bl) |
10852 | { | |
10853 | if (bl->loc_type == bp_loc_hardware_breakpoint) | |
10854 | return target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
10855 | else | |
10856 | return target_remove_breakpoint (bl->gdbarch, &bl->target_info); | |
10857 | } | |
10858 | ||
2060206e | 10859 | static int |
348d480f PA |
10860 | bkpt_breakpoint_hit (const struct bp_location *bl, |
10861 | struct address_space *aspace, CORE_ADDR bp_addr) | |
10862 | { | |
10863 | struct breakpoint *b = bl->owner; | |
10864 | ||
10865 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, | |
10866 | aspace, bp_addr)) | |
10867 | return 0; | |
10868 | ||
10869 | if (overlay_debugging /* unmapped overlay section */ | |
10870 | && section_is_overlay (bl->section) | |
10871 | && !section_is_mapped (bl->section)) | |
10872 | return 0; | |
10873 | ||
10874 | return 1; | |
10875 | } | |
10876 | ||
2060206e | 10877 | static int |
348d480f PA |
10878 | bkpt_resources_needed (const struct bp_location *bl) |
10879 | { | |
10880 | gdb_assert (bl->owner->type == bp_hardware_breakpoint); | |
10881 | ||
10882 | return 1; | |
10883 | } | |
10884 | ||
2060206e | 10885 | static enum print_stop_action |
348d480f PA |
10886 | bkpt_print_it (bpstat bs) |
10887 | { | |
348d480f PA |
10888 | struct breakpoint *b; |
10889 | const struct bp_location *bl; | |
001c8c33 | 10890 | int bp_temp; |
348d480f PA |
10891 | |
10892 | gdb_assert (bs->bp_location_at != NULL); | |
10893 | ||
10894 | bl = bs->bp_location_at; | |
10895 | b = bs->breakpoint_at; | |
10896 | ||
001c8c33 PA |
10897 | bp_temp = b->disposition == disp_del; |
10898 | if (bl->address != bl->requested_address) | |
10899 | breakpoint_adjustment_warning (bl->requested_address, | |
10900 | bl->address, | |
10901 | b->number, 1); | |
10902 | annotate_breakpoint (b->number); | |
10903 | if (bp_temp) | |
10904 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
10905 | else | |
10906 | ui_out_text (uiout, "\nBreakpoint "); | |
10907 | if (ui_out_is_mi_like_p (uiout)) | |
348d480f | 10908 | { |
001c8c33 PA |
10909 | ui_out_field_string (uiout, "reason", |
10910 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
10911 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
06edf0c0 | 10912 | } |
001c8c33 PA |
10913 | ui_out_field_int (uiout, "bkptno", b->number); |
10914 | ui_out_text (uiout, ", "); | |
06edf0c0 | 10915 | |
001c8c33 | 10916 | return PRINT_SRC_AND_LOC; |
06edf0c0 PA |
10917 | } |
10918 | ||
2060206e | 10919 | static void |
06edf0c0 PA |
10920 | bkpt_print_mention (struct breakpoint *b) |
10921 | { | |
10922 | if (ui_out_is_mi_like_p (uiout)) | |
10923 | return; | |
10924 | ||
10925 | switch (b->type) | |
10926 | { | |
10927 | case bp_breakpoint: | |
10928 | case bp_gnu_ifunc_resolver: | |
10929 | if (b->disposition == disp_del) | |
10930 | printf_filtered (_("Temporary breakpoint")); | |
10931 | else | |
10932 | printf_filtered (_("Breakpoint")); | |
10933 | printf_filtered (_(" %d"), b->number); | |
10934 | if (b->type == bp_gnu_ifunc_resolver) | |
10935 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
10936 | break; | |
10937 | case bp_hardware_breakpoint: | |
10938 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); | |
10939 | break; | |
10940 | } | |
10941 | ||
10942 | say_where (b); | |
10943 | } | |
10944 | ||
2060206e | 10945 | static void |
06edf0c0 PA |
10946 | bkpt_print_recreate (struct breakpoint *tp, struct ui_file *fp) |
10947 | { | |
10948 | if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
10949 | fprintf_unfiltered (fp, "tbreak"); | |
10950 | else if (tp->type == bp_breakpoint) | |
10951 | fprintf_unfiltered (fp, "break"); | |
10952 | else if (tp->type == bp_hardware_breakpoint | |
10953 | && tp->disposition == disp_del) | |
10954 | fprintf_unfiltered (fp, "thbreak"); | |
10955 | else if (tp->type == bp_hardware_breakpoint) | |
10956 | fprintf_unfiltered (fp, "hbreak"); | |
10957 | else | |
10958 | internal_error (__FILE__, __LINE__, | |
10959 | _("unhandled breakpoint type %d"), (int) tp->type); | |
10960 | ||
2060206e | 10961 | fprintf_unfiltered (fp, " %s", tp->addr_string); |
06edf0c0 PA |
10962 | } |
10963 | ||
06edf0c0 PA |
10964 | /* Virtual table for internal breakpoints. */ |
10965 | ||
10966 | static void | |
10967 | internal_bkpt_re_set (struct breakpoint *b) | |
10968 | { | |
10969 | switch (b->type) | |
10970 | { | |
10971 | /* Delete overlay event and longjmp master breakpoints; they | |
10972 | will be reset later by breakpoint_re_set. */ | |
10973 | case bp_overlay_event: | |
10974 | case bp_longjmp_master: | |
10975 | case bp_std_terminate_master: | |
10976 | case bp_exception_master: | |
10977 | delete_breakpoint (b); | |
10978 | break; | |
10979 | ||
10980 | /* This breakpoint is special, it's set up when the inferior | |
10981 | starts and we really don't want to touch it. */ | |
10982 | case bp_shlib_event: | |
10983 | ||
10984 | /* Like bp_shlib_event, this breakpoint type is special. Once | |
10985 | it is set up, we do not want to touch it. */ | |
10986 | case bp_thread_event: | |
10987 | break; | |
10988 | } | |
10989 | } | |
10990 | ||
10991 | static void | |
10992 | internal_bkpt_check_status (bpstat bs) | |
10993 | { | |
10994 | /* We do not stop for these. */ | |
10995 | bs->stop = 0; | |
10996 | } | |
10997 | ||
10998 | static enum print_stop_action | |
10999 | internal_bkpt_print_it (bpstat bs) | |
11000 | { | |
06edf0c0 | 11001 | struct breakpoint *b; |
06edf0c0 | 11002 | |
06edf0c0 PA |
11003 | b = bs->breakpoint_at; |
11004 | ||
06edf0c0 PA |
11005 | switch (b->type) |
11006 | { | |
348d480f PA |
11007 | case bp_shlib_event: |
11008 | /* Did we stop because the user set the stop_on_solib_events | |
11009 | variable? (If so, we report this as a generic, "Stopped due | |
11010 | to shlib event" message.) */ | |
11011 | printf_filtered (_("Stopped due to shared library event\n")); | |
348d480f PA |
11012 | break; |
11013 | ||
11014 | case bp_thread_event: | |
11015 | /* Not sure how we will get here. | |
11016 | GDB should not stop for these breakpoints. */ | |
11017 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11018 | break; |
11019 | ||
11020 | case bp_overlay_event: | |
11021 | /* By analogy with the thread event, GDB should not stop for these. */ | |
11022 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11023 | break; |
11024 | ||
11025 | case bp_longjmp_master: | |
11026 | /* These should never be enabled. */ | |
11027 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
348d480f PA |
11028 | break; |
11029 | ||
11030 | case bp_std_terminate_master: | |
11031 | /* These should never be enabled. */ | |
11032 | printf_filtered (_("std::terminate Master Breakpoint: " | |
11033 | "gdb should not stop!\n")); | |
348d480f PA |
11034 | break; |
11035 | ||
11036 | case bp_exception_master: | |
11037 | /* These should never be enabled. */ | |
11038 | printf_filtered (_("Exception Master Breakpoint: " | |
11039 | "gdb should not stop!\n")); | |
06edf0c0 PA |
11040 | break; |
11041 | } | |
11042 | ||
001c8c33 | 11043 | return PRINT_NOTHING; |
06edf0c0 PA |
11044 | } |
11045 | ||
11046 | static void | |
11047 | internal_bkpt_print_mention (struct breakpoint *b) | |
11048 | { | |
11049 | /* Nothing to mention. These breakpoints are internal. */ | |
11050 | } | |
11051 | ||
06edf0c0 PA |
11052 | /* Virtual table for momentary breakpoints */ |
11053 | ||
11054 | static void | |
11055 | momentary_bkpt_re_set (struct breakpoint *b) | |
11056 | { | |
11057 | /* Keep temporary breakpoints, which can be encountered when we step | |
11058 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
11059 | Otherwise these should have been blown away via the cleanup chain | |
11060 | or by breakpoint_init_inferior when we rerun the executable. */ | |
11061 | } | |
11062 | ||
11063 | static void | |
11064 | momentary_bkpt_check_status (bpstat bs) | |
11065 | { | |
11066 | /* Nothing. The point of these breakpoints is causing a stop. */ | |
11067 | } | |
11068 | ||
11069 | static enum print_stop_action | |
11070 | momentary_bkpt_print_it (bpstat bs) | |
11071 | { | |
001c8c33 | 11072 | if (ui_out_is_mi_like_p (uiout)) |
06edf0c0 | 11073 | { |
001c8c33 | 11074 | struct breakpoint *b = bs->breakpoint_at; |
348d480f | 11075 | |
001c8c33 PA |
11076 | switch (b->type) |
11077 | { | |
11078 | case bp_finish: | |
11079 | ui_out_field_string | |
11080 | (uiout, "reason", | |
11081 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
11082 | break; | |
348d480f | 11083 | |
001c8c33 PA |
11084 | case bp_until: |
11085 | ui_out_field_string | |
11086 | (uiout, "reason", | |
11087 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
11088 | break; | |
11089 | } | |
348d480f PA |
11090 | } |
11091 | ||
001c8c33 | 11092 | return PRINT_UNKNOWN; |
348d480f PA |
11093 | } |
11094 | ||
06edf0c0 PA |
11095 | static void |
11096 | momentary_bkpt_print_mention (struct breakpoint *b) | |
348d480f | 11097 | { |
06edf0c0 | 11098 | /* Nothing to mention. These breakpoints are internal. */ |
348d480f PA |
11099 | } |
11100 | ||
348d480f | 11101 | /* The breakpoint_ops structure to be used in tracepoints. */ |
876fa593 | 11102 | |
348d480f PA |
11103 | static void |
11104 | tracepoint_re_set (struct breakpoint *b) | |
11105 | { | |
11106 | breakpoint_re_set_default (b); | |
11107 | } | |
876fa593 | 11108 | |
348d480f PA |
11109 | static int |
11110 | tracepoint_breakpoint_hit (const struct bp_location *bl, | |
11111 | struct address_space *aspace, CORE_ADDR bp_addr) | |
11112 | { | |
11113 | /* By definition, the inferior does not report stops at | |
11114 | tracepoints. */ | |
11115 | return 0; | |
74960c60 VP |
11116 | } |
11117 | ||
11118 | static void | |
348d480f PA |
11119 | tracepoint_print_one_detail (const struct breakpoint *self, |
11120 | struct ui_out *uiout) | |
74960c60 | 11121 | { |
d9b3f62e PA |
11122 | struct tracepoint *tp = (struct tracepoint *) self; |
11123 | if (tp->static_trace_marker_id) | |
348d480f PA |
11124 | { |
11125 | gdb_assert (self->type == bp_static_tracepoint); | |
cc59ec59 | 11126 | |
348d480f PA |
11127 | ui_out_text (uiout, "\tmarker id is "); |
11128 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
d9b3f62e | 11129 | tp->static_trace_marker_id); |
348d480f PA |
11130 | ui_out_text (uiout, "\n"); |
11131 | } | |
0d381245 VP |
11132 | } |
11133 | ||
a474d7c2 | 11134 | static void |
348d480f | 11135 | tracepoint_print_mention (struct breakpoint *b) |
a474d7c2 | 11136 | { |
348d480f PA |
11137 | if (ui_out_is_mi_like_p (uiout)) |
11138 | return; | |
cc59ec59 | 11139 | |
348d480f PA |
11140 | switch (b->type) |
11141 | { | |
11142 | case bp_tracepoint: | |
11143 | printf_filtered (_("Tracepoint")); | |
11144 | printf_filtered (_(" %d"), b->number); | |
11145 | break; | |
11146 | case bp_fast_tracepoint: | |
11147 | printf_filtered (_("Fast tracepoint")); | |
11148 | printf_filtered (_(" %d"), b->number); | |
11149 | break; | |
11150 | case bp_static_tracepoint: | |
11151 | printf_filtered (_("Static tracepoint")); | |
11152 | printf_filtered (_(" %d"), b->number); | |
11153 | break; | |
11154 | default: | |
11155 | internal_error (__FILE__, __LINE__, | |
11156 | _("unhandled tracepoint type %d"), (int) b->type); | |
11157 | } | |
11158 | ||
11159 | say_where (b); | |
a474d7c2 PA |
11160 | } |
11161 | ||
348d480f | 11162 | static void |
d9b3f62e | 11163 | tracepoint_print_recreate (struct breakpoint *self, struct ui_file *fp) |
a474d7c2 | 11164 | { |
d9b3f62e PA |
11165 | struct tracepoint *tp = (struct tracepoint *) self; |
11166 | ||
11167 | if (self->type == bp_fast_tracepoint) | |
348d480f | 11168 | fprintf_unfiltered (fp, "ftrace"); |
d9b3f62e | 11169 | if (self->type == bp_static_tracepoint) |
348d480f | 11170 | fprintf_unfiltered (fp, "strace"); |
d9b3f62e | 11171 | else if (self->type == bp_tracepoint) |
348d480f PA |
11172 | fprintf_unfiltered (fp, "trace"); |
11173 | else | |
11174 | internal_error (__FILE__, __LINE__, | |
d9b3f62e | 11175 | _("unhandled tracepoint type %d"), (int) self->type); |
cc59ec59 | 11176 | |
d9b3f62e PA |
11177 | fprintf_unfiltered (fp, " %s", self->addr_string); |
11178 | print_recreate_thread (self, fp); | |
11179 | ||
11180 | if (tp->pass_count) | |
11181 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); | |
a474d7c2 PA |
11182 | } |
11183 | ||
2060206e | 11184 | struct breakpoint_ops tracepoint_breakpoint_ops; |
348d480f | 11185 | |
53a5351d | 11186 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 11187 | structures. */ |
c906108c SS |
11188 | |
11189 | void | |
fba45db2 | 11190 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 11191 | { |
52f0bd74 | 11192 | struct breakpoint *b; |
c906108c | 11193 | |
8a3fe4f8 | 11194 | gdb_assert (bpt != NULL); |
c906108c | 11195 | |
4a64f543 MS |
11196 | /* Has this bp already been deleted? This can happen because |
11197 | multiple lists can hold pointers to bp's. bpstat lists are | |
11198 | especial culprits. | |
11199 | ||
11200 | One example of this happening is a watchpoint's scope bp. When | |
11201 | the scope bp triggers, we notice that the watchpoint is out of | |
11202 | scope, and delete it. We also delete its scope bp. But the | |
11203 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
11204 | That bpstat is then checked for auto-deleting bp's, which are | |
11205 | deleted. | |
11206 | ||
11207 | A real solution to this problem might involve reference counts in | |
11208 | bp's, and/or giving them pointers back to their referencing | |
11209 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
11210 | storage when no more references were extent. A cheaper bandaid | |
11211 | was chosen. */ | |
c906108c SS |
11212 | if (bpt->type == bp_none) |
11213 | return; | |
11214 | ||
4a64f543 MS |
11215 | /* At least avoid this stale reference until the reference counting |
11216 | of breakpoints gets resolved. */ | |
d0fb5eae | 11217 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 11218 | { |
d0fb5eae | 11219 | struct breakpoint *related; |
3a5c3e22 | 11220 | struct watchpoint *w; |
d0fb5eae JK |
11221 | |
11222 | if (bpt->type == bp_watchpoint_scope) | |
3a5c3e22 | 11223 | w = (struct watchpoint *) bpt->related_breakpoint; |
d0fb5eae | 11224 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) |
3a5c3e22 PA |
11225 | w = (struct watchpoint *) bpt; |
11226 | else | |
11227 | w = NULL; | |
11228 | if (w != NULL) | |
11229 | watchpoint_del_at_next_stop (w); | |
d0fb5eae JK |
11230 | |
11231 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
11232 | for (related = bpt; related->related_breakpoint != bpt; | |
11233 | related = related->related_breakpoint); | |
11234 | related->related_breakpoint = bpt->related_breakpoint; | |
11235 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
11236 | } |
11237 | ||
a9634178 TJB |
11238 | /* watch_command_1 creates a watchpoint but only sets its number if |
11239 | update_watchpoint succeeds in creating its bp_locations. If there's | |
11240 | a problem in that process, we'll be asked to delete the half-created | |
11241 | watchpoint. In that case, don't announce the deletion. */ | |
11242 | if (bpt->number) | |
11243 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 11244 | |
c906108c SS |
11245 | if (breakpoint_chain == bpt) |
11246 | breakpoint_chain = bpt->next; | |
11247 | ||
c906108c SS |
11248 | ALL_BREAKPOINTS (b) |
11249 | if (b->next == bpt) | |
c5aa993b JM |
11250 | { |
11251 | b->next = bpt->next; | |
11252 | break; | |
11253 | } | |
c906108c | 11254 | |
f431efe5 PA |
11255 | /* Be sure no bpstat's are pointing at the breakpoint after it's |
11256 | been freed. */ | |
11257 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
e5dd4106 | 11258 | in all threads for now. Note that we cannot just remove bpstats |
f431efe5 PA |
11259 | pointing at bpt from the stop_bpstat list entirely, as breakpoint |
11260 | commands are associated with the bpstat; if we remove it here, | |
11261 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
11262 | event-top.c won't do anything, and temporary breakpoints with | |
11263 | commands won't work. */ | |
11264 | ||
11265 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
11266 | ||
4a64f543 MS |
11267 | /* Now that breakpoint is removed from breakpoint list, update the |
11268 | global location list. This will remove locations that used to | |
11269 | belong to this breakpoint. Do this before freeing the breakpoint | |
11270 | itself, since remove_breakpoint looks at location's owner. It | |
11271 | might be better design to have location completely | |
11272 | self-contained, but it's not the case now. */ | |
b60e7edf | 11273 | update_global_location_list (0); |
74960c60 | 11274 | |
348d480f | 11275 | bpt->ops->dtor (bpt); |
4a64f543 MS |
11276 | /* On the chance that someone will soon try again to delete this |
11277 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c | 11278 | bpt->type = bp_none; |
b8c9b27d | 11279 | xfree (bpt); |
c906108c SS |
11280 | } |
11281 | ||
4d6140d9 AC |
11282 | static void |
11283 | do_delete_breakpoint_cleanup (void *b) | |
11284 | { | |
11285 | delete_breakpoint (b); | |
11286 | } | |
11287 | ||
11288 | struct cleanup * | |
11289 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
11290 | { | |
11291 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
11292 | } | |
11293 | ||
51be5b68 PA |
11294 | /* Iterator function to call a user-provided callback function once |
11295 | for each of B and its related breakpoints. */ | |
11296 | ||
11297 | static void | |
11298 | iterate_over_related_breakpoints (struct breakpoint *b, | |
11299 | void (*function) (struct breakpoint *, | |
11300 | void *), | |
11301 | void *data) | |
11302 | { | |
11303 | struct breakpoint *related; | |
11304 | ||
11305 | related = b; | |
11306 | do | |
11307 | { | |
11308 | struct breakpoint *next; | |
11309 | ||
11310 | /* FUNCTION may delete RELATED. */ | |
11311 | next = related->related_breakpoint; | |
11312 | ||
11313 | if (next == related) | |
11314 | { | |
11315 | /* RELATED is the last ring entry. */ | |
11316 | function (related, data); | |
11317 | ||
11318 | /* FUNCTION may have deleted it, so we'd never reach back to | |
11319 | B. There's nothing left to do anyway, so just break | |
11320 | out. */ | |
11321 | break; | |
11322 | } | |
11323 | else | |
11324 | function (related, data); | |
11325 | ||
11326 | related = next; | |
11327 | } | |
11328 | while (related != b); | |
11329 | } | |
95a42b64 TT |
11330 | |
11331 | static void | |
11332 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11333 | { | |
11334 | delete_breakpoint (b); | |
11335 | } | |
11336 | ||
51be5b68 PA |
11337 | /* A callback for map_breakpoint_numbers that calls |
11338 | delete_breakpoint. */ | |
11339 | ||
11340 | static void | |
11341 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
11342 | { | |
11343 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
11344 | } | |
11345 | ||
c906108c | 11346 | void |
fba45db2 | 11347 | delete_command (char *arg, int from_tty) |
c906108c | 11348 | { |
35df4500 | 11349 | struct breakpoint *b, *b_tmp; |
c906108c | 11350 | |
ea9365bb TT |
11351 | dont_repeat (); |
11352 | ||
c906108c SS |
11353 | if (arg == 0) |
11354 | { | |
11355 | int breaks_to_delete = 0; | |
11356 | ||
46c6471b PA |
11357 | /* Delete all breakpoints if no argument. Do not delete |
11358 | internal breakpoints, these have to be deleted with an | |
11359 | explicit breakpoint number argument. */ | |
c5aa993b | 11360 | ALL_BREAKPOINTS (b) |
46c6471b | 11361 | if (user_breakpoint_p (b)) |
973d738b DJ |
11362 | { |
11363 | breaks_to_delete = 1; | |
11364 | break; | |
11365 | } | |
c906108c SS |
11366 | |
11367 | /* Ask user only if there are some breakpoints to delete. */ | |
11368 | if (!from_tty | |
e2e0b3e5 | 11369 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 11370 | { |
35df4500 | 11371 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 11372 | if (user_breakpoint_p (b)) |
c5aa993b | 11373 | delete_breakpoint (b); |
c906108c SS |
11374 | } |
11375 | } | |
11376 | else | |
51be5b68 | 11377 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
11378 | } |
11379 | ||
0d381245 VP |
11380 | static int |
11381 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 11382 | { |
0d381245 VP |
11383 | for (; loc; loc = loc->next) |
11384 | if (!loc->shlib_disabled) | |
11385 | return 0; | |
11386 | return 1; | |
fe3f5fa8 VP |
11387 | } |
11388 | ||
776592bf DE |
11389 | /* Subroutine of update_breakpoint_locations to simplify it. |
11390 | Return non-zero if multiple fns in list LOC have the same name. | |
11391 | Null names are ignored. */ | |
11392 | ||
11393 | static int | |
11394 | ambiguous_names_p (struct bp_location *loc) | |
11395 | { | |
11396 | struct bp_location *l; | |
11397 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
11398 | (int (*) (const void *, |
11399 | const void *)) streq, | |
776592bf DE |
11400 | NULL, xcalloc, xfree); |
11401 | ||
11402 | for (l = loc; l != NULL; l = l->next) | |
11403 | { | |
11404 | const char **slot; | |
11405 | const char *name = l->function_name; | |
11406 | ||
11407 | /* Allow for some names to be NULL, ignore them. */ | |
11408 | if (name == NULL) | |
11409 | continue; | |
11410 | ||
11411 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
11412 | INSERT); | |
4a64f543 MS |
11413 | /* NOTE: We can assume slot != NULL here because xcalloc never |
11414 | returns NULL. */ | |
776592bf DE |
11415 | if (*slot != NULL) |
11416 | { | |
11417 | htab_delete (htab); | |
11418 | return 1; | |
11419 | } | |
11420 | *slot = name; | |
11421 | } | |
11422 | ||
11423 | htab_delete (htab); | |
11424 | return 0; | |
11425 | } | |
11426 | ||
0fb4aa4b PA |
11427 | /* When symbols change, it probably means the sources changed as well, |
11428 | and it might mean the static tracepoint markers are no longer at | |
11429 | the same address or line numbers they used to be at last we | |
11430 | checked. Losing your static tracepoints whenever you rebuild is | |
11431 | undesirable. This function tries to resync/rematch gdb static | |
11432 | tracepoints with the markers on the target, for static tracepoints | |
11433 | that have not been set by marker id. Static tracepoint that have | |
11434 | been set by marker id are reset by marker id in breakpoint_re_set. | |
11435 | The heuristic is: | |
11436 | ||
11437 | 1) For a tracepoint set at a specific address, look for a marker at | |
11438 | the old PC. If one is found there, assume to be the same marker. | |
11439 | If the name / string id of the marker found is different from the | |
11440 | previous known name, assume that means the user renamed the marker | |
11441 | in the sources, and output a warning. | |
11442 | ||
11443 | 2) For a tracepoint set at a given line number, look for a marker | |
11444 | at the new address of the old line number. If one is found there, | |
11445 | assume to be the same marker. If the name / string id of the | |
11446 | marker found is different from the previous known name, assume that | |
11447 | means the user renamed the marker in the sources, and output a | |
11448 | warning. | |
11449 | ||
11450 | 3) If a marker is no longer found at the same address or line, it | |
11451 | may mean the marker no longer exists. But it may also just mean | |
11452 | the code changed a bit. Maybe the user added a few lines of code | |
11453 | that made the marker move up or down (in line number terms). Ask | |
11454 | the target for info about the marker with the string id as we knew | |
11455 | it. If found, update line number and address in the matching | |
11456 | static tracepoint. This will get confused if there's more than one | |
11457 | marker with the same ID (possible in UST, although unadvised | |
11458 | precisely because it confuses tools). */ | |
11459 | ||
11460 | static struct symtab_and_line | |
11461 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
11462 | { | |
d9b3f62e | 11463 | struct tracepoint *tp = (struct tracepoint *) b; |
0fb4aa4b PA |
11464 | struct static_tracepoint_marker marker; |
11465 | CORE_ADDR pc; | |
11466 | int i; | |
11467 | ||
11468 | pc = sal.pc; | |
11469 | if (sal.line) | |
11470 | find_line_pc (sal.symtab, sal.line, &pc); | |
11471 | ||
11472 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
11473 | { | |
d9b3f62e | 11474 | if (strcmp (tp->static_trace_marker_id, marker.str_id) != 0) |
0fb4aa4b PA |
11475 | warning (_("static tracepoint %d changed probed marker from %s to %s"), |
11476 | b->number, | |
d9b3f62e | 11477 | tp->static_trace_marker_id, marker.str_id); |
0fb4aa4b | 11478 | |
d9b3f62e PA |
11479 | xfree (tp->static_trace_marker_id); |
11480 | tp->static_trace_marker_id = xstrdup (marker.str_id); | |
0fb4aa4b PA |
11481 | release_static_tracepoint_marker (&marker); |
11482 | ||
11483 | return sal; | |
11484 | } | |
11485 | ||
11486 | /* Old marker wasn't found on target at lineno. Try looking it up | |
11487 | by string ID. */ | |
11488 | if (!sal.explicit_pc | |
11489 | && sal.line != 0 | |
11490 | && sal.symtab != NULL | |
d9b3f62e | 11491 | && tp->static_trace_marker_id != NULL) |
0fb4aa4b PA |
11492 | { |
11493 | VEC(static_tracepoint_marker_p) *markers; | |
11494 | ||
11495 | markers | |
d9b3f62e | 11496 | = target_static_tracepoint_markers_by_strid (tp->static_trace_marker_id); |
0fb4aa4b PA |
11497 | |
11498 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
11499 | { | |
11500 | struct symtab_and_line sal; | |
11501 | struct symbol *sym; | |
11502 | struct static_tracepoint_marker *marker; | |
11503 | ||
11504 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
11505 | ||
d9b3f62e PA |
11506 | xfree (tp->static_trace_marker_id); |
11507 | tp->static_trace_marker_id = xstrdup (marker->str_id); | |
0fb4aa4b PA |
11508 | |
11509 | warning (_("marker for static tracepoint %d (%s) not " | |
11510 | "found at previous line number"), | |
d9b3f62e | 11511 | b->number, tp->static_trace_marker_id); |
0fb4aa4b PA |
11512 | |
11513 | init_sal (&sal); | |
11514 | ||
11515 | sal.pc = marker->address; | |
11516 | ||
11517 | sal = find_pc_line (marker->address, 0); | |
11518 | sym = find_pc_sect_function (marker->address, NULL); | |
11519 | ui_out_text (uiout, "Now in "); | |
11520 | if (sym) | |
11521 | { | |
11522 | ui_out_field_string (uiout, "func", | |
11523 | SYMBOL_PRINT_NAME (sym)); | |
11524 | ui_out_text (uiout, " at "); | |
11525 | } | |
11526 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
11527 | ui_out_text (uiout, ":"); | |
11528 | ||
11529 | if (ui_out_is_mi_like_p (uiout)) | |
11530 | { | |
11531 | char *fullname = symtab_to_fullname (sal.symtab); | |
11532 | ||
11533 | if (fullname) | |
11534 | ui_out_field_string (uiout, "fullname", fullname); | |
11535 | } | |
11536 | ||
11537 | ui_out_field_int (uiout, "line", sal.line); | |
11538 | ui_out_text (uiout, "\n"); | |
11539 | ||
11540 | b->line_number = sal.line; | |
11541 | ||
11542 | xfree (b->source_file); | |
11543 | if (sym) | |
11544 | b->source_file = xstrdup (sal.symtab->filename); | |
11545 | else | |
11546 | b->source_file = NULL; | |
11547 | ||
11548 | xfree (b->addr_string); | |
11549 | b->addr_string = xstrprintf ("%s:%d", | |
11550 | sal.symtab->filename, b->line_number); | |
11551 | ||
11552 | /* Might be nice to check if function changed, and warn if | |
11553 | so. */ | |
11554 | ||
11555 | release_static_tracepoint_marker (marker); | |
11556 | } | |
11557 | } | |
11558 | return sal; | |
11559 | } | |
11560 | ||
8d3788bd VP |
11561 | /* Returns 1 iff locations A and B are sufficiently same that |
11562 | we don't need to report breakpoint as changed. */ | |
11563 | ||
11564 | static int | |
11565 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11566 | { | |
11567 | while (a && b) | |
11568 | { | |
11569 | if (a->address != b->address) | |
11570 | return 0; | |
11571 | ||
11572 | if (a->shlib_disabled != b->shlib_disabled) | |
11573 | return 0; | |
11574 | ||
11575 | if (a->enabled != b->enabled) | |
11576 | return 0; | |
11577 | ||
11578 | a = a->next; | |
11579 | b = b->next; | |
11580 | } | |
11581 | ||
11582 | if ((a == NULL) != (b == NULL)) | |
11583 | return 0; | |
11584 | ||
11585 | return 1; | |
11586 | } | |
11587 | ||
f1310107 TJB |
11588 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11589 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11590 | a ranged breakpoint. */ | |
11591 | ||
0e30163f | 11592 | void |
0d381245 | 11593 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11594 | struct symtabs_and_lines sals, |
11595 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11596 | { |
11597 | int i; | |
0d381245 VP |
11598 | struct bp_location *existing_locations = b->loc; |
11599 | ||
f1310107 TJB |
11600 | /* Ranged breakpoints have only one start location and one end location. */ |
11601 | gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1)); | |
11602 | ||
4a64f543 MS |
11603 | /* If there's no new locations, and all existing locations are |
11604 | pending, don't do anything. This optimizes the common case where | |
11605 | all locations are in the same shared library, that was unloaded. | |
11606 | We'd like to retain the location, so that when the library is | |
11607 | loaded again, we don't loose the enabled/disabled status of the | |
11608 | individual locations. */ | |
0d381245 | 11609 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11610 | return; |
11611 | ||
fe3f5fa8 VP |
11612 | b->loc = NULL; |
11613 | ||
0d381245 | 11614 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11615 | { |
0d381245 | 11616 | struct bp_location *new_loc = |
39d61571 | 11617 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 11618 | |
0d381245 VP |
11619 | /* Reparse conditions, they might contain references to the |
11620 | old symtab. */ | |
11621 | if (b->cond_string != NULL) | |
11622 | { | |
f1310107 | 11623 | char *s; |
0d381245 | 11624 | struct gdb_exception e; |
fe3f5fa8 | 11625 | |
0d381245 VP |
11626 | s = b->cond_string; |
11627 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11628 | { | |
11629 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11630 | 0); | |
11631 | } | |
11632 | if (e.reason < 0) | |
11633 | { | |
3e43a32a MS |
11634 | warning (_("failed to reevaluate condition " |
11635 | "for breakpoint %d: %s"), | |
0d381245 VP |
11636 | b->number, e.message); |
11637 | new_loc->enabled = 0; | |
11638 | } | |
11639 | } | |
fe3f5fa8 | 11640 | |
0d381245 VP |
11641 | if (b->source_file != NULL) |
11642 | xfree (b->source_file); | |
11643 | if (sals.sals[i].symtab == NULL) | |
11644 | b->source_file = NULL; | |
11645 | else | |
1b36a34b | 11646 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 11647 | |
0d381245 VP |
11648 | if (b->line_number == 0) |
11649 | b->line_number = sals.sals[i].line; | |
f1310107 TJB |
11650 | |
11651 | if (sals_end.nelts) | |
11652 | { | |
11653 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11654 | ||
11655 | new_loc->length = end - sals.sals[0].pc + 1; | |
11656 | } | |
0d381245 | 11657 | } |
fe3f5fa8 | 11658 | |
514f746b AR |
11659 | /* Update locations of permanent breakpoints. */ |
11660 | if (b->enable_state == bp_permanent) | |
11661 | make_breakpoint_permanent (b); | |
11662 | ||
4a64f543 MS |
11663 | /* If possible, carry over 'disable' status from existing |
11664 | breakpoints. */ | |
0d381245 VP |
11665 | { |
11666 | struct bp_location *e = existing_locations; | |
776592bf DE |
11667 | /* If there are multiple breakpoints with the same function name, |
11668 | e.g. for inline functions, comparing function names won't work. | |
11669 | Instead compare pc addresses; this is just a heuristic as things | |
11670 | may have moved, but in practice it gives the correct answer | |
11671 | often enough until a better solution is found. */ | |
11672 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
11673 | ||
0d381245 VP |
11674 | for (; e; e = e->next) |
11675 | { | |
11676 | if (!e->enabled && e->function_name) | |
11677 | { | |
11678 | struct bp_location *l = b->loc; | |
776592bf DE |
11679 | if (have_ambiguous_names) |
11680 | { | |
11681 | for (; l; l = l->next) | |
f1310107 | 11682 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
11683 | { |
11684 | l->enabled = 0; | |
11685 | break; | |
11686 | } | |
11687 | } | |
11688 | else | |
11689 | { | |
11690 | for (; l; l = l->next) | |
11691 | if (l->function_name | |
11692 | && strcmp (e->function_name, l->function_name) == 0) | |
11693 | { | |
11694 | l->enabled = 0; | |
11695 | break; | |
11696 | } | |
11697 | } | |
0d381245 VP |
11698 | } |
11699 | } | |
11700 | } | |
fe3f5fa8 | 11701 | |
8d3788bd VP |
11702 | if (!locations_are_equal (existing_locations, b->loc)) |
11703 | observer_notify_breakpoint_modified (b); | |
11704 | ||
b60e7edf | 11705 | update_global_location_list (1); |
fe3f5fa8 VP |
11706 | } |
11707 | ||
ef23e705 TJB |
11708 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
11709 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
11710 | ||
11711 | static struct symtabs_and_lines | |
11712 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
11713 | { | |
11714 | char *s; | |
58438ac1 | 11715 | int marker_spec; |
02d20e4a | 11716 | struct symtabs_and_lines sals = {0}; |
ef23e705 TJB |
11717 | struct gdb_exception e; |
11718 | ||
11719 | s = addr_string; | |
11720 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); | |
11721 | ||
11722 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11723 | { | |
11724 | if (marker_spec) | |
11725 | { | |
d9b3f62e PA |
11726 | struct tracepoint *tp = (struct tracepoint *) b; |
11727 | ||
ef23e705 | 11728 | sals = decode_static_tracepoint_spec (&s); |
d9b3f62e | 11729 | if (sals.nelts > tp->static_trace_marker_id_idx) |
ef23e705 | 11730 | { |
d9b3f62e | 11731 | sals.sals[0] = sals.sals[tp->static_trace_marker_id_idx]; |
ef23e705 TJB |
11732 | sals.nelts = 1; |
11733 | } | |
11734 | else | |
d9b3f62e | 11735 | error (_("marker %s not found"), tp->static_trace_marker_id); |
ef23e705 TJB |
11736 | } |
11737 | else | |
58438ac1 | 11738 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL); |
ef23e705 TJB |
11739 | } |
11740 | if (e.reason < 0) | |
11741 | { | |
11742 | int not_found_and_ok = 0; | |
11743 | /* For pending breakpoints, it's expected that parsing will | |
11744 | fail until the right shared library is loaded. User has | |
11745 | already told to create pending breakpoints and don't need | |
11746 | extra messages. If breakpoint is in bp_shlib_disabled | |
11747 | state, then user already saw the message about that | |
11748 | breakpoint being disabled, and don't want to see more | |
11749 | errors. */ | |
58438ac1 | 11750 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
11751 | && (b->condition_not_parsed |
11752 | || (b->loc && b->loc->shlib_disabled) | |
11753 | || b->enable_state == bp_disabled)) | |
11754 | not_found_and_ok = 1; | |
11755 | ||
11756 | if (!not_found_and_ok) | |
11757 | { | |
11758 | /* We surely don't want to warn about the same breakpoint | |
11759 | 10 times. One solution, implemented here, is disable | |
11760 | the breakpoint on error. Another solution would be to | |
11761 | have separate 'warning emitted' flag. Since this | |
11762 | happens only when a binary has changed, I don't know | |
11763 | which approach is better. */ | |
11764 | b->enable_state = bp_disabled; | |
11765 | throw_exception (e); | |
11766 | } | |
11767 | } | |
11768 | ||
58438ac1 | 11769 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 TJB |
11770 | { |
11771 | gdb_assert (sals.nelts == 1); | |
11772 | ||
11773 | resolve_sal_pc (&sals.sals[0]); | |
11774 | if (b->condition_not_parsed && s && s[0]) | |
11775 | { | |
11776 | char *cond_string = 0; | |
11777 | int thread = -1; | |
11778 | int task = 0; | |
11779 | ||
11780 | find_condition_and_thread (s, sals.sals[0].pc, | |
11781 | &cond_string, &thread, &task); | |
11782 | if (cond_string) | |
11783 | b->cond_string = cond_string; | |
11784 | b->thread = thread; | |
11785 | b->task = task; | |
11786 | b->condition_not_parsed = 0; | |
11787 | } | |
11788 | ||
11789 | if (b->type == bp_static_tracepoint && !marker_spec) | |
11790 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
ef23e705 | 11791 | |
58438ac1 TT |
11792 | *found = 1; |
11793 | } | |
11794 | else | |
11795 | *found = 0; | |
ef23e705 TJB |
11796 | |
11797 | return sals; | |
11798 | } | |
11799 | ||
348d480f PA |
11800 | /* The default re_set method, for typical hardware or software |
11801 | breakpoints. Reevaluate the breakpoint and recreate its | |
11802 | locations. */ | |
11803 | ||
11804 | static void | |
28010a5d | 11805 | breakpoint_re_set_default (struct breakpoint *b) |
ef23e705 TJB |
11806 | { |
11807 | int found; | |
f1310107 | 11808 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 11809 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 11810 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
11811 | |
11812 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
11813 | if (found) | |
11814 | { | |
11815 | make_cleanup (xfree, sals.sals); | |
11816 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
11817 | } | |
11818 | ||
f1310107 TJB |
11819 | if (b->addr_string_range_end) |
11820 | { | |
11821 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
11822 | if (found) | |
11823 | { | |
11824 | make_cleanup (xfree, sals_end.sals); | |
11825 | expanded_end = expand_line_sal_maybe (sals_end.sals[0]); | |
11826 | } | |
11827 | } | |
11828 | ||
11829 | update_breakpoint_locations (b, expanded, expanded_end); | |
28010a5d PA |
11830 | } |
11831 | ||
11832 | /* Prepare the global context for a re-set of breakpoint B. */ | |
11833 | ||
11834 | static struct cleanup * | |
11835 | prepare_re_set_context (struct breakpoint *b) | |
11836 | { | |
11837 | struct cleanup *cleanups; | |
11838 | ||
11839 | input_radix = b->input_radix; | |
11840 | cleanups = save_current_space_and_thread (); | |
11841 | switch_to_program_space_and_thread (b->pspace); | |
11842 | set_language (b->language); | |
11843 | ||
11844 | return cleanups; | |
ef23e705 TJB |
11845 | } |
11846 | ||
c906108c SS |
11847 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
11848 | The value we return ends up being the return value from catch_errors. | |
11849 | Unused in this case. */ | |
11850 | ||
11851 | static int | |
4efb68b1 | 11852 | breakpoint_re_set_one (void *bint) |
c906108c | 11853 | { |
4a64f543 | 11854 | /* Get past catch_errs. */ |
53a5351d | 11855 | struct breakpoint *b = (struct breakpoint *) bint; |
348d480f | 11856 | struct cleanup *cleanups; |
c906108c | 11857 | |
348d480f PA |
11858 | cleanups = prepare_re_set_context (b); |
11859 | b->ops->re_set (b); | |
11860 | do_cleanups (cleanups); | |
c906108c SS |
11861 | return 0; |
11862 | } | |
11863 | ||
69de3c6a | 11864 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 11865 | void |
69de3c6a | 11866 | breakpoint_re_set (void) |
c906108c | 11867 | { |
35df4500 | 11868 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11869 | enum language save_language; |
11870 | int save_input_radix; | |
6c95b8df | 11871 | struct cleanup *old_chain; |
c5aa993b | 11872 | |
c906108c SS |
11873 | save_language = current_language->la_language; |
11874 | save_input_radix = input_radix; | |
6c95b8df PA |
11875 | old_chain = save_current_program_space (); |
11876 | ||
35df4500 | 11877 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11878 | { |
4a64f543 | 11879 | /* Format possible error msg. */ |
fe3f5fa8 | 11880 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
11881 | b->number); |
11882 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 11883 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 11884 | do_cleanups (cleanups); |
c5aa993b | 11885 | } |
c906108c SS |
11886 | set_language (save_language); |
11887 | input_radix = save_input_radix; | |
e62c965a | 11888 | |
0756c555 | 11889 | jit_breakpoint_re_set (); |
4efc6507 | 11890 | |
6c95b8df PA |
11891 | do_cleanups (old_chain); |
11892 | ||
af02033e PP |
11893 | create_overlay_event_breakpoint (); |
11894 | create_longjmp_master_breakpoint (); | |
11895 | create_std_terminate_master_breakpoint (); | |
186c406b | 11896 | create_exception_master_breakpoint (); |
c906108c SS |
11897 | } |
11898 | \f | |
c906108c SS |
11899 | /* Reset the thread number of this breakpoint: |
11900 | ||
11901 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 11902 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 11903 | void |
fba45db2 | 11904 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
11905 | { |
11906 | if (b->thread != -1) | |
11907 | { | |
39f77062 KB |
11908 | if (in_thread_list (inferior_ptid)) |
11909 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
11910 | |
11911 | /* We're being called after following a fork. The new fork is | |
11912 | selected as current, and unless this was a vfork will have a | |
11913 | different program space from the original thread. Reset that | |
11914 | as well. */ | |
11915 | b->loc->pspace = current_program_space; | |
c906108c SS |
11916 | } |
11917 | } | |
11918 | ||
03ac34d5 MS |
11919 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
11920 | If from_tty is nonzero, it prints a message to that effect, | |
11921 | which ends with a period (no newline). */ | |
11922 | ||
c906108c | 11923 | void |
fba45db2 | 11924 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 11925 | { |
52f0bd74 | 11926 | struct breakpoint *b; |
c906108c SS |
11927 | |
11928 | if (count < 0) | |
11929 | count = 0; | |
11930 | ||
11931 | ALL_BREAKPOINTS (b) | |
11932 | if (b->number == bptnum) | |
c5aa993b | 11933 | { |
d77f58be SS |
11934 | if (is_tracepoint (b)) |
11935 | { | |
11936 | if (from_tty && count != 0) | |
11937 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
11938 | bptnum); | |
11939 | return; | |
11940 | } | |
11941 | ||
c5aa993b | 11942 | b->ignore_count = count; |
221ea385 KS |
11943 | if (from_tty) |
11944 | { | |
11945 | if (count == 0) | |
3e43a32a MS |
11946 | printf_filtered (_("Will stop next time " |
11947 | "breakpoint %d is reached."), | |
221ea385 KS |
11948 | bptnum); |
11949 | else if (count == 1) | |
a3f17187 | 11950 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
11951 | bptnum); |
11952 | else | |
3e43a32a MS |
11953 | printf_filtered (_("Will ignore next %d " |
11954 | "crossings of breakpoint %d."), | |
221ea385 KS |
11955 | count, bptnum); |
11956 | } | |
c5aa993b | 11957 | breakpoints_changed (); |
8d3788bd | 11958 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
11959 | return; |
11960 | } | |
c906108c | 11961 | |
8a3fe4f8 | 11962 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
11963 | } |
11964 | ||
c906108c SS |
11965 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
11966 | ||
11967 | static void | |
fba45db2 | 11968 | ignore_command (char *args, int from_tty) |
c906108c SS |
11969 | { |
11970 | char *p = args; | |
52f0bd74 | 11971 | int num; |
c906108c SS |
11972 | |
11973 | if (p == 0) | |
e2e0b3e5 | 11974 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 11975 | |
c906108c | 11976 | num = get_number (&p); |
5c44784c | 11977 | if (num == 0) |
8a3fe4f8 | 11978 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 11979 | if (*p == 0) |
8a3fe4f8 | 11980 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
11981 | |
11982 | set_ignore_count (num, | |
11983 | longest_to_int (value_as_long (parse_and_eval (p))), | |
11984 | from_tty); | |
221ea385 KS |
11985 | if (from_tty) |
11986 | printf_filtered ("\n"); | |
c906108c SS |
11987 | } |
11988 | \f | |
11989 | /* Call FUNCTION on each of the breakpoints | |
11990 | whose numbers are given in ARGS. */ | |
11991 | ||
11992 | static void | |
95a42b64 TT |
11993 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
11994 | void *), | |
11995 | void *data) | |
c906108c | 11996 | { |
52f0bd74 AC |
11997 | int num; |
11998 | struct breakpoint *b, *tmp; | |
11cf8741 | 11999 | int match; |
197f0a60 | 12000 | struct get_number_or_range_state state; |
c906108c | 12001 | |
197f0a60 | 12002 | if (args == 0) |
e2e0b3e5 | 12003 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 12004 | |
197f0a60 TT |
12005 | init_number_or_range (&state, args); |
12006 | ||
12007 | while (!state.finished) | |
c906108c | 12008 | { |
197f0a60 TT |
12009 | char *p = state.string; |
12010 | ||
11cf8741 | 12011 | match = 0; |
c5aa993b | 12012 | |
197f0a60 | 12013 | num = get_number_or_range (&state); |
5c44784c | 12014 | if (num == 0) |
c5aa993b | 12015 | { |
8a3fe4f8 | 12016 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
12017 | } |
12018 | else | |
12019 | { | |
12020 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
12021 | if (b->number == num) | |
12022 | { | |
11cf8741 | 12023 | match = 1; |
cdac0397 | 12024 | function (b, data); |
11cf8741 | 12025 | break; |
5c44784c | 12026 | } |
11cf8741 | 12027 | if (match == 0) |
a3f17187 | 12028 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 12029 | } |
c906108c SS |
12030 | } |
12031 | } | |
12032 | ||
0d381245 VP |
12033 | static struct bp_location * |
12034 | find_location_by_number (char *number) | |
12035 | { | |
12036 | char *dot = strchr (number, '.'); | |
12037 | char *p1; | |
12038 | int bp_num; | |
12039 | int loc_num; | |
12040 | struct breakpoint *b; | |
12041 | struct bp_location *loc; | |
12042 | ||
12043 | *dot = '\0'; | |
12044 | ||
12045 | p1 = number; | |
197f0a60 | 12046 | bp_num = get_number (&p1); |
0d381245 VP |
12047 | if (bp_num == 0) |
12048 | error (_("Bad breakpoint number '%s'"), number); | |
12049 | ||
12050 | ALL_BREAKPOINTS (b) | |
12051 | if (b->number == bp_num) | |
12052 | { | |
12053 | break; | |
12054 | } | |
12055 | ||
12056 | if (!b || b->number != bp_num) | |
12057 | error (_("Bad breakpoint number '%s'"), number); | |
12058 | ||
12059 | p1 = dot+1; | |
197f0a60 | 12060 | loc_num = get_number (&p1); |
0d381245 VP |
12061 | if (loc_num == 0) |
12062 | error (_("Bad breakpoint location number '%s'"), number); | |
12063 | ||
12064 | --loc_num; | |
12065 | loc = b->loc; | |
12066 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
12067 | ; | |
12068 | if (!loc) | |
12069 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
12070 | ||
12071 | return loc; | |
12072 | } | |
12073 | ||
12074 | ||
1900040c MS |
12075 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
12076 | If from_tty is nonzero, it prints a message to that effect, | |
12077 | which ends with a period (no newline). */ | |
12078 | ||
c906108c | 12079 | void |
fba45db2 | 12080 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
12081 | { |
12082 | /* Never disable a watchpoint scope breakpoint; we want to | |
12083 | hit them when we leave scope so we can delete both the | |
12084 | watchpoint and its scope breakpoint at that time. */ | |
12085 | if (bpt->type == bp_watchpoint_scope) | |
12086 | return; | |
12087 | ||
c2c6d25f | 12088 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 12089 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
12090 | return; |
12091 | ||
b5de0fa7 | 12092 | bpt->enable_state = bp_disabled; |
c906108c | 12093 | |
d248b706 KY |
12094 | if (target_supports_enable_disable_tracepoint () |
12095 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12096 | { | |
12097 | struct bp_location *location; | |
12098 | ||
12099 | for (location = bpt->loc; location; location = location->next) | |
12100 | target_disable_tracepoint (location); | |
12101 | } | |
12102 | ||
b60e7edf | 12103 | update_global_location_list (0); |
c906108c | 12104 | |
8d3788bd | 12105 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12106 | } |
12107 | ||
51be5b68 PA |
12108 | /* A callback for iterate_over_related_breakpoints. */ |
12109 | ||
12110 | static void | |
12111 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12112 | { | |
12113 | disable_breakpoint (b); | |
12114 | } | |
12115 | ||
95a42b64 TT |
12116 | /* A callback for map_breakpoint_numbers that calls |
12117 | disable_breakpoint. */ | |
12118 | ||
12119 | static void | |
12120 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
12121 | { | |
51be5b68 | 12122 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
12123 | } |
12124 | ||
c906108c | 12125 | static void |
fba45db2 | 12126 | disable_command (char *args, int from_tty) |
c906108c | 12127 | { |
c906108c | 12128 | if (args == 0) |
46c6471b PA |
12129 | { |
12130 | struct breakpoint *bpt; | |
12131 | ||
12132 | ALL_BREAKPOINTS (bpt) | |
12133 | if (user_breakpoint_p (bpt)) | |
12134 | disable_breakpoint (bpt); | |
12135 | } | |
0d381245 VP |
12136 | else if (strchr (args, '.')) |
12137 | { | |
12138 | struct bp_location *loc = find_location_by_number (args); | |
12139 | if (loc) | |
d248b706 KY |
12140 | { |
12141 | loc->enabled = 0; | |
12142 | if (target_supports_enable_disable_tracepoint () | |
12143 | && current_trace_status ()->running && loc->owner | |
12144 | && is_tracepoint (loc->owner)) | |
12145 | target_disable_tracepoint (loc); | |
12146 | } | |
b60e7edf | 12147 | update_global_location_list (0); |
0d381245 | 12148 | } |
c906108c | 12149 | else |
95a42b64 | 12150 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
12151 | } |
12152 | ||
12153 | static void | |
51be5b68 | 12154 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 12155 | { |
afe38095 | 12156 | int target_resources_ok; |
c906108c SS |
12157 | |
12158 | if (bpt->type == bp_hardware_breakpoint) | |
12159 | { | |
12160 | int i; | |
c5aa993b | 12161 | i = hw_breakpoint_used_count (); |
53a5351d | 12162 | target_resources_ok = |
d92524f1 | 12163 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 12164 | i + 1, 0); |
c906108c | 12165 | if (target_resources_ok == 0) |
8a3fe4f8 | 12166 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 12167 | else if (target_resources_ok < 0) |
8a3fe4f8 | 12168 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
12169 | } |
12170 | ||
cc60f2e3 | 12171 | if (is_watchpoint (bpt)) |
c906108c | 12172 | { |
d07205c2 JK |
12173 | /* Initialize it just to avoid a GCC false warning. */ |
12174 | enum enable_state orig_enable_state = 0; | |
dde02812 ES |
12175 | struct gdb_exception e; |
12176 | ||
12177 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 12178 | { |
3a5c3e22 PA |
12179 | struct watchpoint *w = (struct watchpoint *) bpt; |
12180 | ||
1e718ff1 TJB |
12181 | orig_enable_state = bpt->enable_state; |
12182 | bpt->enable_state = bp_enabled; | |
3a5c3e22 | 12183 | update_watchpoint (w, 1 /* reparse */); |
c906108c | 12184 | } |
dde02812 | 12185 | if (e.reason < 0) |
c5aa993b | 12186 | { |
1e718ff1 | 12187 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
12188 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
12189 | bpt->number); | |
12190 | return; | |
c5aa993b | 12191 | } |
c906108c | 12192 | } |
0101ce28 | 12193 | |
b4c291bb KH |
12194 | if (bpt->enable_state != bp_permanent) |
12195 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
12196 | |
12197 | if (target_supports_enable_disable_tracepoint () | |
12198 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
12199 | { | |
12200 | struct bp_location *location; | |
12201 | ||
12202 | for (location = bpt->loc; location; location = location->next) | |
12203 | target_enable_tracepoint (location); | |
12204 | } | |
12205 | ||
b4c291bb | 12206 | bpt->disposition = disposition; |
b60e7edf | 12207 | update_global_location_list (1); |
b4c291bb KH |
12208 | breakpoints_changed (); |
12209 | ||
8d3788bd | 12210 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
12211 | } |
12212 | ||
fe3f5fa8 | 12213 | |
c906108c | 12214 | void |
fba45db2 | 12215 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 12216 | { |
51be5b68 PA |
12217 | enable_breakpoint_disp (bpt, bpt->disposition); |
12218 | } | |
12219 | ||
12220 | static void | |
12221 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
12222 | { | |
12223 | enable_breakpoint (bpt); | |
c906108c SS |
12224 | } |
12225 | ||
95a42b64 TT |
12226 | /* A callback for map_breakpoint_numbers that calls |
12227 | enable_breakpoint. */ | |
12228 | ||
12229 | static void | |
12230 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
12231 | { | |
51be5b68 | 12232 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
12233 | } |
12234 | ||
c906108c SS |
12235 | /* The enable command enables the specified breakpoints (or all defined |
12236 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 12237 | in stopping the inferior. */ |
c906108c | 12238 | |
c906108c | 12239 | static void |
fba45db2 | 12240 | enable_command (char *args, int from_tty) |
c906108c | 12241 | { |
c906108c | 12242 | if (args == 0) |
46c6471b PA |
12243 | { |
12244 | struct breakpoint *bpt; | |
12245 | ||
12246 | ALL_BREAKPOINTS (bpt) | |
12247 | if (user_breakpoint_p (bpt)) | |
12248 | enable_breakpoint (bpt); | |
12249 | } | |
0d381245 VP |
12250 | else if (strchr (args, '.')) |
12251 | { | |
12252 | struct bp_location *loc = find_location_by_number (args); | |
12253 | if (loc) | |
d248b706 KY |
12254 | { |
12255 | loc->enabled = 1; | |
12256 | if (target_supports_enable_disable_tracepoint () | |
12257 | && current_trace_status ()->running && loc->owner | |
12258 | && is_tracepoint (loc->owner)) | |
12259 | target_enable_tracepoint (loc); | |
12260 | } | |
b60e7edf | 12261 | update_global_location_list (1); |
0d381245 | 12262 | } |
c906108c | 12263 | else |
95a42b64 | 12264 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
12265 | } |
12266 | ||
12267 | static void | |
51be5b68 PA |
12268 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
12269 | { | |
12270 | enum bpdisp disp = *(enum bpdisp *) arg; | |
12271 | ||
12272 | enable_breakpoint_disp (bpt, disp); | |
12273 | } | |
12274 | ||
12275 | static void | |
12276 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 12277 | { |
51be5b68 PA |
12278 | enum bpdisp disp = disp_disable; |
12279 | ||
12280 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12281 | } |
12282 | ||
c906108c | 12283 | static void |
fba45db2 | 12284 | enable_once_command (char *args, int from_tty) |
c906108c | 12285 | { |
51be5b68 | 12286 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
12287 | } |
12288 | ||
12289 | static void | |
51be5b68 | 12290 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 12291 | { |
51be5b68 PA |
12292 | enum bpdisp disp = disp_del; |
12293 | ||
12294 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
12295 | } |
12296 | ||
c906108c | 12297 | static void |
fba45db2 | 12298 | enable_delete_command (char *args, int from_tty) |
c906108c | 12299 | { |
51be5b68 | 12300 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
12301 | } |
12302 | \f | |
fa8d40ab JJ |
12303 | static void |
12304 | set_breakpoint_cmd (char *args, int from_tty) | |
12305 | { | |
12306 | } | |
12307 | ||
12308 | static void | |
12309 | show_breakpoint_cmd (char *args, int from_tty) | |
12310 | { | |
12311 | } | |
12312 | ||
1f3b5d1b PP |
12313 | /* Invalidate last known value of any hardware watchpoint if |
12314 | the memory which that value represents has been written to by | |
12315 | GDB itself. */ | |
12316 | ||
12317 | static void | |
12318 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
12319 | const bfd_byte *data) | |
12320 | { | |
12321 | struct breakpoint *bp; | |
12322 | ||
12323 | ALL_BREAKPOINTS (bp) | |
12324 | if (bp->enable_state == bp_enabled | |
3a5c3e22 | 12325 | && bp->type == bp_hardware_watchpoint) |
1f3b5d1b | 12326 | { |
3a5c3e22 | 12327 | struct watchpoint *wp = (struct watchpoint *) bp; |
1f3b5d1b | 12328 | |
3a5c3e22 PA |
12329 | if (wp->val_valid && wp->val) |
12330 | { | |
12331 | struct bp_location *loc; | |
12332 | ||
12333 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
12334 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
12335 | && loc->address + loc->length > addr | |
12336 | && addr + len > loc->address) | |
12337 | { | |
12338 | value_free (wp->val); | |
12339 | wp->val = NULL; | |
12340 | wp->val_valid = 0; | |
12341 | } | |
12342 | } | |
1f3b5d1b PP |
12343 | } |
12344 | } | |
12345 | ||
c906108c SS |
12346 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
12347 | ||
12348 | struct symtabs_and_lines | |
fba45db2 | 12349 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
12350 | { |
12351 | struct symtabs_and_lines sals; | |
cc59ec59 | 12352 | |
c906108c | 12353 | if (string == 0) |
8a3fe4f8 | 12354 | error (_("Empty line specification.")); |
c906108c SS |
12355 | if (default_breakpoint_valid) |
12356 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
12357 | default_breakpoint_symtab, |
12358 | default_breakpoint_line, | |
58438ac1 | 12359 | NULL); |
c906108c SS |
12360 | else |
12361 | sals = decode_line_1 (&string, funfirstline, | |
58438ac1 | 12362 | (struct symtab *) NULL, 0, NULL); |
c906108c | 12363 | if (*string) |
8a3fe4f8 | 12364 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
12365 | return sals; |
12366 | } | |
8181d85f DJ |
12367 | |
12368 | /* Create and insert a raw software breakpoint at PC. Return an | |
12369 | identifier, which should be used to remove the breakpoint later. | |
12370 | In general, places which call this should be using something on the | |
12371 | breakpoint chain instead; this function should be eliminated | |
12372 | someday. */ | |
12373 | ||
12374 | void * | |
6c95b8df PA |
12375 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
12376 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
12377 | { |
12378 | struct bp_target_info *bp_tgt; | |
12379 | ||
6c95b8df | 12380 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 12381 | |
6c95b8df | 12382 | bp_tgt->placed_address_space = aspace; |
8181d85f | 12383 | bp_tgt->placed_address = pc; |
6c95b8df | 12384 | |
a6d9a66e | 12385 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
12386 | { |
12387 | /* Could not insert the breakpoint. */ | |
12388 | xfree (bp_tgt); | |
12389 | return NULL; | |
12390 | } | |
12391 | ||
12392 | return bp_tgt; | |
12393 | } | |
12394 | ||
4a64f543 MS |
12395 | /* Remove a breakpoint BP inserted by |
12396 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
12397 | |
12398 | int | |
a6d9a66e | 12399 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
12400 | { |
12401 | struct bp_target_info *bp_tgt = bp; | |
12402 | int ret; | |
12403 | ||
a6d9a66e | 12404 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
12405 | xfree (bp_tgt); |
12406 | ||
12407 | return ret; | |
12408 | } | |
12409 | ||
4a64f543 MS |
12410 | /* One (or perhaps two) breakpoints used for software single |
12411 | stepping. */ | |
8181d85f DJ |
12412 | |
12413 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 12414 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
12415 | |
12416 | /* Create and insert a breakpoint for software single step. */ | |
12417 | ||
12418 | void | |
6c95b8df | 12419 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
12420 | struct address_space *aspace, |
12421 | CORE_ADDR next_pc) | |
8181d85f DJ |
12422 | { |
12423 | void **bpt_p; | |
12424 | ||
12425 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
12426 | { |
12427 | bpt_p = &single_step_breakpoints[0]; | |
12428 | single_step_gdbarch[0] = gdbarch; | |
12429 | } | |
8181d85f DJ |
12430 | else |
12431 | { | |
12432 | gdb_assert (single_step_breakpoints[1] == NULL); | |
12433 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 12434 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
12435 | } |
12436 | ||
4a64f543 MS |
12437 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12438 | be to only create the breakpoints once, and actually put them on | |
12439 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12440 | We could adjust the addresses each time they were needed. Doing | |
12441 | this requires corresponding changes elsewhere where single step | |
12442 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12443 | |
6c95b8df | 12444 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12445 | if (*bpt_p == NULL) |
5af949e3 UW |
12446 | error (_("Could not insert single-step breakpoint at %s"), |
12447 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12448 | } |
12449 | ||
f02253f1 HZ |
12450 | /* Check if the breakpoints used for software single stepping |
12451 | were inserted or not. */ | |
12452 | ||
12453 | int | |
12454 | single_step_breakpoints_inserted (void) | |
12455 | { | |
12456 | return (single_step_breakpoints[0] != NULL | |
12457 | || single_step_breakpoints[1] != NULL); | |
12458 | } | |
12459 | ||
8181d85f DJ |
12460 | /* Remove and delete any breakpoints used for software single step. */ |
12461 | ||
12462 | void | |
12463 | remove_single_step_breakpoints (void) | |
12464 | { | |
12465 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12466 | ||
12467 | /* See insert_single_step_breakpoint for more about this deprecated | |
12468 | call. */ | |
a6d9a66e UW |
12469 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12470 | single_step_breakpoints[0]); | |
12471 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12472 | single_step_breakpoints[0] = NULL; |
12473 | ||
12474 | if (single_step_breakpoints[1] != NULL) | |
12475 | { | |
a6d9a66e UW |
12476 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12477 | single_step_breakpoints[1]); | |
12478 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12479 | single_step_breakpoints[1] = NULL; |
12480 | } | |
12481 | } | |
12482 | ||
d03285ec UW |
12483 | /* Delete software single step breakpoints without removing them from |
12484 | the inferior. This is intended to be used if the inferior's address | |
12485 | space where they were inserted is already gone, e.g. after exit or | |
12486 | exec. */ | |
12487 | ||
12488 | void | |
12489 | cancel_single_step_breakpoints (void) | |
12490 | { | |
12491 | int i; | |
12492 | ||
12493 | for (i = 0; i < 2; i++) | |
12494 | if (single_step_breakpoints[i]) | |
12495 | { | |
12496 | xfree (single_step_breakpoints[i]); | |
12497 | single_step_breakpoints[i] = NULL; | |
12498 | single_step_gdbarch[i] = NULL; | |
12499 | } | |
12500 | } | |
12501 | ||
12502 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12503 | removing them. */ | |
12504 | ||
12505 | static void | |
12506 | detach_single_step_breakpoints (void) | |
12507 | { | |
12508 | int i; | |
12509 | ||
12510 | for (i = 0; i < 2; i++) | |
12511 | if (single_step_breakpoints[i]) | |
12512 | target_remove_breakpoint (single_step_gdbarch[i], | |
12513 | single_step_breakpoints[i]); | |
12514 | } | |
12515 | ||
4a64f543 MS |
12516 | /* Check whether a software single-step breakpoint is inserted at |
12517 | PC. */ | |
1aafd4da UW |
12518 | |
12519 | static int | |
cc59ec59 MS |
12520 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12521 | CORE_ADDR pc) | |
1aafd4da UW |
12522 | { |
12523 | int i; | |
12524 | ||
12525 | for (i = 0; i < 2; i++) | |
12526 | { | |
12527 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12528 | if (bp_tgt |
12529 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12530 | bp_tgt->placed_address, | |
12531 | aspace, pc)) | |
1aafd4da UW |
12532 | return 1; |
12533 | } | |
12534 | ||
12535 | return 0; | |
12536 | } | |
12537 | ||
a96d9b2e SDJ |
12538 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12539 | non-zero otherwise. */ | |
12540 | static int | |
12541 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12542 | { | |
12543 | if (syscall_catchpoint_p (bp) | |
12544 | && bp->enable_state != bp_disabled | |
12545 | && bp->enable_state != bp_call_disabled) | |
12546 | return 1; | |
12547 | else | |
12548 | return 0; | |
12549 | } | |
12550 | ||
12551 | int | |
12552 | catch_syscall_enabled (void) | |
12553 | { | |
12554 | struct inferior *inf = current_inferior (); | |
12555 | ||
12556 | return inf->total_syscalls_count != 0; | |
12557 | } | |
12558 | ||
12559 | int | |
12560 | catching_syscall_number (int syscall_number) | |
12561 | { | |
12562 | struct breakpoint *bp; | |
12563 | ||
12564 | ALL_BREAKPOINTS (bp) | |
12565 | if (is_syscall_catchpoint_enabled (bp)) | |
12566 | { | |
be5c67c1 PA |
12567 | struct syscall_catchpoint *c = (struct syscall_catchpoint *) bp; |
12568 | ||
12569 | if (c->syscalls_to_be_caught) | |
a96d9b2e SDJ |
12570 | { |
12571 | int i, iter; | |
12572 | for (i = 0; | |
be5c67c1 | 12573 | VEC_iterate (int, c->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
12574 | i++) |
12575 | if (syscall_number == iter) | |
12576 | return 1; | |
12577 | } | |
12578 | else | |
12579 | return 1; | |
12580 | } | |
12581 | ||
12582 | return 0; | |
12583 | } | |
12584 | ||
12585 | /* Complete syscall names. Used by "catch syscall". */ | |
12586 | static char ** | |
12587 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12588 | char *text, char *word) | |
12589 | { | |
12590 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12591 | char **retlist |
12592 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12593 | |
c38eea1a MS |
12594 | xfree (list); |
12595 | return retlist; | |
a96d9b2e SDJ |
12596 | } |
12597 | ||
1042e4c0 SS |
12598 | /* Tracepoint-specific operations. */ |
12599 | ||
12600 | /* Set tracepoint count to NUM. */ | |
12601 | static void | |
12602 | set_tracepoint_count (int num) | |
12603 | { | |
12604 | tracepoint_count = num; | |
4fa62494 | 12605 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
12606 | } |
12607 | ||
12608 | void | |
12609 | trace_command (char *arg, int from_tty) | |
12610 | { | |
8cdf0e15 VP |
12611 | if (create_breakpoint (get_current_arch (), |
12612 | arg, | |
12613 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12614 | 0 /* tempflag */, |
12615 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12616 | 0 /* Ignore count */, |
12617 | pending_break_support, | |
348d480f | 12618 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12619 | from_tty, |
84f4c1fe PM |
12620 | 1 /* enabled */, |
12621 | 0 /* internal */)) | |
fd9b8c24 | 12622 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
12623 | } |
12624 | ||
7a697b8d SS |
12625 | void |
12626 | ftrace_command (char *arg, int from_tty) | |
12627 | { | |
8cdf0e15 VP |
12628 | if (create_breakpoint (get_current_arch (), |
12629 | arg, | |
12630 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12631 | 0 /* tempflag */, |
12632 | bp_fast_tracepoint /* type_wanted */, | |
12633 | 0 /* Ignore count */, | |
12634 | pending_break_support, | |
348d480f | 12635 | &tracepoint_breakpoint_ops, |
0fb4aa4b | 12636 | from_tty, |
84f4c1fe PM |
12637 | 1 /* enabled */, |
12638 | 0 /* internal */)) | |
0fb4aa4b PA |
12639 | set_tracepoint_count (breakpoint_count); |
12640 | } | |
12641 | ||
12642 | /* strace command implementation. Creates a static tracepoint. */ | |
12643 | ||
12644 | void | |
12645 | strace_command (char *arg, int from_tty) | |
12646 | { | |
12647 | if (create_breakpoint (get_current_arch (), | |
12648 | arg, | |
12649 | NULL, 0, 1 /* parse arg */, | |
12650 | 0 /* tempflag */, | |
12651 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12652 | 0 /* Ignore count */, |
12653 | pending_break_support, | |
348d480f | 12654 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12655 | from_tty, |
84f4c1fe PM |
12656 | 1 /* enabled */, |
12657 | 0 /* internal */)) | |
fd9b8c24 | 12658 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
12659 | } |
12660 | ||
409873ef SS |
12661 | /* Set up a fake reader function that gets command lines from a linked |
12662 | list that was acquired during tracepoint uploading. */ | |
12663 | ||
12664 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 12665 | static int next_cmd; |
409873ef SS |
12666 | |
12667 | static char * | |
12668 | read_uploaded_action (void) | |
12669 | { | |
12670 | char *rslt; | |
12671 | ||
3149d8c1 | 12672 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 12673 | |
3149d8c1 | 12674 | next_cmd++; |
409873ef SS |
12675 | |
12676 | return rslt; | |
12677 | } | |
12678 | ||
00bf0b85 SS |
12679 | /* Given information about a tracepoint as recorded on a target (which |
12680 | can be either a live system or a trace file), attempt to create an | |
12681 | equivalent GDB tracepoint. This is not a reliable process, since | |
12682 | the target does not necessarily have all the information used when | |
12683 | the tracepoint was originally defined. */ | |
12684 | ||
d9b3f62e | 12685 | struct tracepoint * |
00bf0b85 | 12686 | create_tracepoint_from_upload (struct uploaded_tp *utp) |
d5551862 | 12687 | { |
409873ef | 12688 | char *addr_str, small_buf[100]; |
d9b3f62e | 12689 | struct tracepoint *tp; |
fd9b8c24 | 12690 | |
409873ef SS |
12691 | if (utp->at_string) |
12692 | addr_str = utp->at_string; | |
12693 | else | |
12694 | { | |
12695 | /* In the absence of a source location, fall back to raw | |
12696 | address. Since there is no way to confirm that the address | |
12697 | means the same thing as when the trace was started, warn the | |
12698 | user. */ | |
3e43a32a MS |
12699 | warning (_("Uploaded tracepoint %d has no " |
12700 | "source location, using raw address"), | |
409873ef SS |
12701 | utp->number); |
12702 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
12703 | addr_str = small_buf; | |
12704 | } | |
12705 | ||
12706 | /* There's not much we can do with a sequence of bytecodes. */ | |
12707 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
12708 | warning (_("Uploaded tracepoint %d condition " |
12709 | "has no source form, ignoring it"), | |
409873ef | 12710 | utp->number); |
d5551862 | 12711 | |
8cdf0e15 | 12712 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
12713 | addr_str, |
12714 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 12715 | 0 /* tempflag */, |
0fb4aa4b | 12716 | utp->type /* type_wanted */, |
8cdf0e15 VP |
12717 | 0 /* Ignore count */, |
12718 | pending_break_support, | |
348d480f | 12719 | &tracepoint_breakpoint_ops, |
8cdf0e15 | 12720 | 0 /* from_tty */, |
84f4c1fe PM |
12721 | utp->enabled /* enabled */, |
12722 | 0 /* internal */)) | |
fd9b8c24 PA |
12723 | return NULL; |
12724 | ||
00bf0b85 SS |
12725 | set_tracepoint_count (breakpoint_count); |
12726 | ||
409873ef | 12727 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
12728 | tp = get_tracepoint (tracepoint_count); |
12729 | gdb_assert (tp != NULL); | |
d5551862 | 12730 | |
00bf0b85 SS |
12731 | if (utp->pass > 0) |
12732 | { | |
d9b3f62e | 12733 | sprintf (small_buf, "%d %d", utp->pass, tp->base.number); |
00bf0b85 | 12734 | |
409873ef | 12735 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
12736 | } |
12737 | ||
409873ef SS |
12738 | /* If we have uploaded versions of the original commands, set up a |
12739 | special-purpose "reader" function and call the usual command line | |
12740 | reader, then pass the result to the breakpoint command-setting | |
12741 | function. */ | |
3149d8c1 | 12742 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 12743 | { |
409873ef | 12744 | struct command_line *cmd_list; |
00bf0b85 | 12745 | |
409873ef | 12746 | this_utp = utp; |
3149d8c1 | 12747 | next_cmd = 0; |
d5551862 | 12748 | |
409873ef SS |
12749 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
12750 | ||
d9b3f62e | 12751 | breakpoint_set_commands (&tp->base, cmd_list); |
00bf0b85 | 12752 | } |
3149d8c1 SS |
12753 | else if (!VEC_empty (char_ptr, utp->actions) |
12754 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
12755 | warning (_("Uploaded tracepoint %d actions " |
12756 | "have no source form, ignoring them"), | |
409873ef | 12757 | utp->number); |
00bf0b85 SS |
12758 | |
12759 | return tp; | |
d9b3f62e | 12760 | } |
00bf0b85 | 12761 | |
1042e4c0 SS |
12762 | /* Print information on tracepoint number TPNUM_EXP, or all if |
12763 | omitted. */ | |
12764 | ||
12765 | static void | |
e5a67952 | 12766 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 12767 | { |
e5a67952 | 12768 | int num_printed; |
1042e4c0 | 12769 | |
e5a67952 | 12770 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
12771 | |
12772 | if (num_printed == 0) | |
1042e4c0 | 12773 | { |
e5a67952 | 12774 | if (args == NULL || *args == '\0') |
d77f58be SS |
12775 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
12776 | else | |
e5a67952 | 12777 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 12778 | } |
ad443146 SS |
12779 | |
12780 | default_collect_info (); | |
1042e4c0 SS |
12781 | } |
12782 | ||
4a64f543 | 12783 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
12784 | Not supported by all targets. */ |
12785 | static void | |
12786 | enable_trace_command (char *args, int from_tty) | |
12787 | { | |
12788 | enable_command (args, from_tty); | |
12789 | } | |
12790 | ||
4a64f543 | 12791 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
12792 | Not supported by all targets. */ |
12793 | static void | |
12794 | disable_trace_command (char *args, int from_tty) | |
12795 | { | |
12796 | disable_command (args, from_tty); | |
12797 | } | |
12798 | ||
4a64f543 | 12799 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
12800 | static void |
12801 | delete_trace_command (char *arg, int from_tty) | |
12802 | { | |
35df4500 | 12803 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
12804 | |
12805 | dont_repeat (); | |
12806 | ||
12807 | if (arg == 0) | |
12808 | { | |
12809 | int breaks_to_delete = 0; | |
12810 | ||
12811 | /* Delete all breakpoints if no argument. | |
12812 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
12813 | have to be deleted with an explicit breakpoint number |
12814 | argument. */ | |
1042e4c0 | 12815 | ALL_TRACEPOINTS (b) |
46c6471b | 12816 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
12817 | { |
12818 | breaks_to_delete = 1; | |
12819 | break; | |
12820 | } | |
1042e4c0 SS |
12821 | |
12822 | /* Ask user only if there are some breakpoints to delete. */ | |
12823 | if (!from_tty | |
12824 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
12825 | { | |
35df4500 | 12826 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12827 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 12828 | delete_breakpoint (b); |
1042e4c0 SS |
12829 | } |
12830 | } | |
12831 | else | |
51be5b68 | 12832 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
12833 | } |
12834 | ||
197f0a60 TT |
12835 | /* Helper function for trace_pass_command. */ |
12836 | ||
12837 | static void | |
d9b3f62e | 12838 | trace_pass_set_count (struct tracepoint *tp, int count, int from_tty) |
197f0a60 | 12839 | { |
d9b3f62e PA |
12840 | tp->pass_count = count; |
12841 | observer_notify_tracepoint_modified (tp->base.number); | |
197f0a60 TT |
12842 | if (from_tty) |
12843 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
d9b3f62e | 12844 | tp->base.number, count); |
197f0a60 TT |
12845 | } |
12846 | ||
1042e4c0 SS |
12847 | /* Set passcount for tracepoint. |
12848 | ||
12849 | First command argument is passcount, second is tracepoint number. | |
12850 | If tracepoint number omitted, apply to most recently defined. | |
12851 | Also accepts special argument "all". */ | |
12852 | ||
12853 | static void | |
12854 | trace_pass_command (char *args, int from_tty) | |
12855 | { | |
d9b3f62e | 12856 | struct tracepoint *t1; |
1042e4c0 | 12857 | unsigned int count; |
1042e4c0 SS |
12858 | |
12859 | if (args == 0 || *args == 0) | |
3e43a32a MS |
12860 | error (_("passcount command requires an " |
12861 | "argument (count + optional TP num)")); | |
1042e4c0 | 12862 | |
4a64f543 | 12863 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
12864 | |
12865 | while (*args && isspace ((int) *args)) | |
12866 | args++; | |
12867 | ||
12868 | if (*args && strncasecmp (args, "all", 3) == 0) | |
12869 | { | |
d9b3f62e PA |
12870 | struct breakpoint *b; |
12871 | ||
1042e4c0 | 12872 | args += 3; /* Skip special argument "all". */ |
1042e4c0 SS |
12873 | if (*args) |
12874 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 12875 | |
d9b3f62e | 12876 | ALL_TRACEPOINTS (b) |
197f0a60 | 12877 | { |
d9b3f62e | 12878 | t1 = (struct tracepoint *) b; |
197f0a60 TT |
12879 | trace_pass_set_count (t1, count, from_tty); |
12880 | } | |
12881 | } | |
12882 | else if (*args == '\0') | |
1042e4c0 | 12883 | { |
197f0a60 | 12884 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 12885 | if (t1) |
197f0a60 TT |
12886 | trace_pass_set_count (t1, count, from_tty); |
12887 | } | |
12888 | else | |
12889 | { | |
12890 | struct get_number_or_range_state state; | |
12891 | ||
12892 | init_number_or_range (&state, args); | |
12893 | while (!state.finished) | |
1042e4c0 | 12894 | { |
197f0a60 TT |
12895 | t1 = get_tracepoint_by_number (&args, &state, 1); |
12896 | if (t1) | |
12897 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
12898 | } |
12899 | } | |
1042e4c0 SS |
12900 | } |
12901 | ||
d9b3f62e | 12902 | struct tracepoint * |
1042e4c0 SS |
12903 | get_tracepoint (int num) |
12904 | { | |
12905 | struct breakpoint *t; | |
12906 | ||
12907 | ALL_TRACEPOINTS (t) | |
12908 | if (t->number == num) | |
d9b3f62e | 12909 | return (struct tracepoint *) t; |
1042e4c0 SS |
12910 | |
12911 | return NULL; | |
12912 | } | |
12913 | ||
d5551862 SS |
12914 | /* Find the tracepoint with the given target-side number (which may be |
12915 | different from the tracepoint number after disconnecting and | |
12916 | reconnecting). */ | |
12917 | ||
d9b3f62e | 12918 | struct tracepoint * |
d5551862 SS |
12919 | get_tracepoint_by_number_on_target (int num) |
12920 | { | |
d9b3f62e | 12921 | struct breakpoint *b; |
d5551862 | 12922 | |
d9b3f62e PA |
12923 | ALL_TRACEPOINTS (b) |
12924 | { | |
12925 | struct tracepoint *t = (struct tracepoint *) b; | |
12926 | ||
12927 | if (t->number_on_target == num) | |
12928 | return t; | |
12929 | } | |
d5551862 SS |
12930 | |
12931 | return NULL; | |
12932 | } | |
12933 | ||
1042e4c0 | 12934 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
12935 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
12936 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 | 12937 | recent tracepoint (tracepoint_count) is returned. */ |
d9b3f62e | 12938 | struct tracepoint * |
197f0a60 TT |
12939 | get_tracepoint_by_number (char **arg, |
12940 | struct get_number_or_range_state *state, | |
12941 | int optional_p) | |
1042e4c0 SS |
12942 | { |
12943 | extern int tracepoint_count; | |
12944 | struct breakpoint *t; | |
12945 | int tpnum; | |
12946 | char *instring = arg == NULL ? NULL : *arg; | |
12947 | ||
197f0a60 TT |
12948 | if (state) |
12949 | { | |
12950 | gdb_assert (!state->finished); | |
12951 | tpnum = get_number_or_range (state); | |
12952 | } | |
12953 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
12954 | { |
12955 | if (optional_p) | |
12956 | tpnum = tracepoint_count; | |
12957 | else | |
12958 | error_no_arg (_("tracepoint number")); | |
12959 | } | |
12960 | else | |
197f0a60 | 12961 | tpnum = get_number (arg); |
1042e4c0 SS |
12962 | |
12963 | if (tpnum <= 0) | |
12964 | { | |
12965 | if (instring && *instring) | |
12966 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
12967 | instring); | |
12968 | else | |
3e43a32a MS |
12969 | printf_filtered (_("Tracepoint argument missing " |
12970 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
12971 | return NULL; |
12972 | } | |
12973 | ||
12974 | ALL_TRACEPOINTS (t) | |
12975 | if (t->number == tpnum) | |
12976 | { | |
d9b3f62e | 12977 | return (struct tracepoint *) t; |
1042e4c0 SS |
12978 | } |
12979 | ||
1042e4c0 SS |
12980 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
12981 | return NULL; | |
12982 | } | |
12983 | ||
d9b3f62e PA |
12984 | void |
12985 | print_recreate_thread (struct breakpoint *b, struct ui_file *fp) | |
12986 | { | |
12987 | if (b->thread != -1) | |
12988 | fprintf_unfiltered (fp, " thread %d", b->thread); | |
12989 | ||
12990 | if (b->task != 0) | |
12991 | fprintf_unfiltered (fp, " task %d", b->task); | |
12992 | ||
12993 | fprintf_unfiltered (fp, "\n"); | |
12994 | } | |
12995 | ||
6149aea9 PA |
12996 | /* Save information on user settable breakpoints (watchpoints, etc) to |
12997 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
12998 | on each breakpoint and only include the ones for which it returns | |
12999 | non-zero. */ | |
13000 | ||
1042e4c0 | 13001 | static void |
6149aea9 PA |
13002 | save_breakpoints (char *filename, int from_tty, |
13003 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
13004 | { |
13005 | struct breakpoint *tp; | |
6149aea9 | 13006 | int any = 0; |
a7bdde9e | 13007 | char *pathname; |
1042e4c0 | 13008 | struct cleanup *cleanup; |
a7bdde9e | 13009 | struct ui_file *fp; |
6149aea9 | 13010 | int extra_trace_bits = 0; |
1042e4c0 | 13011 | |
6149aea9 PA |
13012 | if (filename == 0 || *filename == 0) |
13013 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
13014 | |
13015 | /* See if we have anything to save. */ | |
6149aea9 | 13016 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13017 | { |
6149aea9 | 13018 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13019 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
13020 | continue; |
13021 | ||
13022 | /* If we have a filter, only save the breakpoints it accepts. */ | |
13023 | if (filter && !filter (tp)) | |
13024 | continue; | |
13025 | ||
13026 | any = 1; | |
13027 | ||
13028 | if (is_tracepoint (tp)) | |
13029 | { | |
13030 | extra_trace_bits = 1; | |
13031 | ||
13032 | /* We can stop searching. */ | |
13033 | break; | |
13034 | } | |
1042e4c0 | 13035 | } |
6149aea9 PA |
13036 | |
13037 | if (!any) | |
1042e4c0 | 13038 | { |
6149aea9 | 13039 | warning (_("Nothing to save.")); |
1042e4c0 SS |
13040 | return; |
13041 | } | |
13042 | ||
6149aea9 | 13043 | pathname = tilde_expand (filename); |
1042e4c0 | 13044 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 13045 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 13046 | if (!fp) |
6149aea9 PA |
13047 | error (_("Unable to open file '%s' for saving (%s)"), |
13048 | filename, safe_strerror (errno)); | |
a7bdde9e | 13049 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 13050 | |
6149aea9 PA |
13051 | if (extra_trace_bits) |
13052 | save_trace_state_variables (fp); | |
8bf6485c | 13053 | |
6149aea9 | 13054 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 13055 | { |
6149aea9 | 13056 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 13057 | if (!user_breakpoint_p (tp)) |
6149aea9 | 13058 | continue; |
8bf6485c | 13059 | |
6149aea9 PA |
13060 | /* If we have a filter, only save the breakpoints it accepts. */ |
13061 | if (filter && !filter (tp)) | |
13062 | continue; | |
13063 | ||
348d480f | 13064 | tp->ops->print_recreate (tp, fp); |
1042e4c0 | 13065 | |
6149aea9 PA |
13066 | /* Note, we can't rely on tp->number for anything, as we can't |
13067 | assume the recreated breakpoint numbers will match. Use $bpnum | |
13068 | instead. */ | |
13069 | ||
13070 | if (tp->cond_string) | |
13071 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
13072 | ||
13073 | if (tp->ignore_count) | |
13074 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
13075 | ||
a7bdde9e | 13076 | if (tp->commands) |
1042e4c0 | 13077 | { |
a7bdde9e VP |
13078 | volatile struct gdb_exception ex; |
13079 | ||
6149aea9 | 13080 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
13081 | |
13082 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 13083 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 13084 | { |
9add0f1b | 13085 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
13086 | } |
13087 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 13088 | |
a7bdde9e VP |
13089 | if (ex.reason < 0) |
13090 | throw_exception (ex); | |
1042e4c0 | 13091 | |
a7bdde9e | 13092 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 13093 | } |
6149aea9 PA |
13094 | |
13095 | if (tp->enable_state == bp_disabled) | |
13096 | fprintf_unfiltered (fp, "disable\n"); | |
13097 | ||
13098 | /* If this is a multi-location breakpoint, check if the locations | |
13099 | should be individually disabled. Watchpoint locations are | |
13100 | special, and not user visible. */ | |
13101 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
13102 | { | |
13103 | struct bp_location *loc; | |
13104 | int n = 1; | |
13105 | ||
13106 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
13107 | if (!loc->enabled) | |
13108 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
13109 | } | |
1042e4c0 | 13110 | } |
8bf6485c | 13111 | |
6149aea9 | 13112 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
13113 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
13114 | ||
1042e4c0 SS |
13115 | do_cleanups (cleanup); |
13116 | if (from_tty) | |
6149aea9 PA |
13117 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
13118 | } | |
13119 | ||
13120 | /* The `save breakpoints' command. */ | |
13121 | ||
13122 | static void | |
13123 | save_breakpoints_command (char *args, int from_tty) | |
13124 | { | |
13125 | save_breakpoints (args, from_tty, NULL); | |
13126 | } | |
13127 | ||
13128 | /* The `save tracepoints' command. */ | |
13129 | ||
13130 | static void | |
13131 | save_tracepoints_command (char *args, int from_tty) | |
13132 | { | |
13133 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
13134 | } |
13135 | ||
13136 | /* Create a vector of all tracepoints. */ | |
13137 | ||
13138 | VEC(breakpoint_p) * | |
eeae04df | 13139 | all_tracepoints (void) |
1042e4c0 SS |
13140 | { |
13141 | VEC(breakpoint_p) *tp_vec = 0; | |
13142 | struct breakpoint *tp; | |
13143 | ||
13144 | ALL_TRACEPOINTS (tp) | |
13145 | { | |
13146 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
13147 | } | |
13148 | ||
13149 | return tp_vec; | |
13150 | } | |
13151 | ||
c906108c | 13152 | \f |
4a64f543 MS |
13153 | /* This help string is used for the break, hbreak, tbreak and thbreak |
13154 | commands. It is defined as a macro to prevent duplication. | |
13155 | COMMAND should be a string constant containing the name of the | |
13156 | command. */ | |
31e2b00f AS |
13157 | #define BREAK_ARGS_HELP(command) \ |
13158 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
13159 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
13160 | If a line number is specified, break at start of code for that line.\n\ | |
13161 | If a function is specified, break at start of code for that function.\n\ | |
13162 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
13163 | With no LOCATION, uses current execution address of the selected\n\ |
13164 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
13165 | \n\ |
13166 | THREADNUM is the number from \"info threads\".\n\ | |
13167 | CONDITION is a boolean expression.\n\ | |
13168 | \n\ | |
d41c0fc8 PA |
13169 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
13170 | conditions are different.\n\ | |
31e2b00f AS |
13171 | \n\ |
13172 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
13173 | ||
44feb3ce TT |
13174 | /* List of subcommands for "catch". */ |
13175 | static struct cmd_list_element *catch_cmdlist; | |
13176 | ||
13177 | /* List of subcommands for "tcatch". */ | |
13178 | static struct cmd_list_element *tcatch_cmdlist; | |
13179 | ||
9ac4176b | 13180 | void |
44feb3ce TT |
13181 | add_catch_command (char *name, char *docstring, |
13182 | void (*sfunc) (char *args, int from_tty, | |
13183 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
13184 | char **(*completer) (struct cmd_list_element *cmd, |
13185 | char *text, char *word), | |
44feb3ce TT |
13186 | void *user_data_catch, |
13187 | void *user_data_tcatch) | |
13188 | { | |
13189 | struct cmd_list_element *command; | |
13190 | ||
13191 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13192 | &catch_cmdlist); | |
13193 | set_cmd_sfunc (command, sfunc); | |
13194 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 13195 | set_cmd_completer (command, completer); |
44feb3ce TT |
13196 | |
13197 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
13198 | &tcatch_cmdlist); | |
13199 | set_cmd_sfunc (command, sfunc); | |
13200 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 13201 | set_cmd_completer (command, completer); |
44feb3ce TT |
13202 | } |
13203 | ||
6c95b8df | 13204 | static void |
a79b8f6e | 13205 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 13206 | { |
6c95b8df PA |
13207 | inf->total_syscalls_count = 0; |
13208 | inf->any_syscall_count = 0; | |
13209 | VEC_free (int, inf->syscalls_counts); | |
13210 | } | |
13211 | ||
6149aea9 PA |
13212 | static void |
13213 | save_command (char *arg, int from_tty) | |
13214 | { | |
3e43a32a MS |
13215 | printf_unfiltered (_("\"save\" must be followed by " |
13216 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
13217 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
13218 | } | |
13219 | ||
84f4c1fe PM |
13220 | struct breakpoint * |
13221 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
13222 | void *data) | |
13223 | { | |
35df4500 | 13224 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 13225 | |
35df4500 | 13226 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
13227 | { |
13228 | if ((*callback) (b, data)) | |
13229 | return b; | |
13230 | } | |
13231 | ||
13232 | return NULL; | |
13233 | } | |
13234 | ||
2060206e PA |
13235 | void |
13236 | initialize_breakpoint_ops (void) | |
13237 | { | |
13238 | static int initialized = 0; | |
13239 | ||
13240 | struct breakpoint_ops *ops; | |
13241 | ||
13242 | if (initialized) | |
13243 | return; | |
13244 | initialized = 1; | |
13245 | ||
13246 | /* The breakpoint_ops structure to be inherit by all kinds of | |
13247 | breakpoints (real breakpoints, i.e., user "break" breakpoints, | |
13248 | internal and momentary breakpoints, etc.). */ | |
13249 | ops = &bkpt_base_breakpoint_ops; | |
13250 | *ops = base_breakpoint_ops; | |
13251 | ops->re_set = bkpt_re_set; | |
13252 | ops->insert_location = bkpt_insert_location; | |
13253 | ops->remove_location = bkpt_remove_location; | |
13254 | ops->breakpoint_hit = bkpt_breakpoint_hit; | |
13255 | ||
13256 | /* The breakpoint_ops structure to be used in regular breakpoints. */ | |
13257 | ops = &bkpt_breakpoint_ops; | |
13258 | *ops = bkpt_base_breakpoint_ops; | |
13259 | ops->re_set = bkpt_re_set; | |
13260 | ops->resources_needed = bkpt_resources_needed; | |
13261 | ops->print_it = bkpt_print_it; | |
13262 | ops->print_mention = bkpt_print_mention; | |
13263 | ops->print_recreate = bkpt_print_recreate; | |
13264 | ||
13265 | /* Ranged breakpoints. */ | |
13266 | ops = &ranged_breakpoint_ops; | |
13267 | *ops = bkpt_breakpoint_ops; | |
13268 | ops->breakpoint_hit = breakpoint_hit_ranged_breakpoint; | |
13269 | ops->resources_needed = resources_needed_ranged_breakpoint; | |
13270 | ops->print_it = print_it_ranged_breakpoint; | |
13271 | ops->print_one = print_one_ranged_breakpoint; | |
13272 | ops->print_one_detail = print_one_detail_ranged_breakpoint; | |
13273 | ops->print_mention = print_mention_ranged_breakpoint; | |
13274 | ops->print_recreate = print_recreate_ranged_breakpoint; | |
13275 | ||
13276 | /* Internal breakpoints. */ | |
13277 | ops = &internal_breakpoint_ops; | |
13278 | *ops = bkpt_base_breakpoint_ops; | |
13279 | ops->re_set = internal_bkpt_re_set; | |
13280 | ops->check_status = internal_bkpt_check_status; | |
13281 | ops->print_it = internal_bkpt_print_it; | |
13282 | ops->print_mention = internal_bkpt_print_mention; | |
13283 | ||
13284 | /* Momentary breakpoints. */ | |
13285 | ops = &momentary_breakpoint_ops; | |
13286 | *ops = bkpt_base_breakpoint_ops; | |
13287 | ops->re_set = momentary_bkpt_re_set; | |
13288 | ops->check_status = momentary_bkpt_check_status; | |
13289 | ops->print_it = momentary_bkpt_print_it; | |
13290 | ops->print_mention = momentary_bkpt_print_mention; | |
13291 | ||
13292 | /* GNU v3 exception catchpoints. */ | |
13293 | ops = &gnu_v3_exception_catchpoint_ops; | |
13294 | *ops = bkpt_breakpoint_ops; | |
13295 | ops->print_it = print_it_exception_catchpoint; | |
13296 | ops->print_one = print_one_exception_catchpoint; | |
13297 | ops->print_mention = print_mention_exception_catchpoint; | |
13298 | ops->print_recreate = print_recreate_exception_catchpoint; | |
13299 | ||
13300 | /* Watchpoints. */ | |
13301 | ops = &watchpoint_breakpoint_ops; | |
13302 | *ops = base_breakpoint_ops; | |
3a5c3e22 | 13303 | ops->dtor = dtor_watchpoint; |
2060206e PA |
13304 | ops->re_set = re_set_watchpoint; |
13305 | ops->insert_location = insert_watchpoint; | |
13306 | ops->remove_location = remove_watchpoint; | |
13307 | ops->breakpoint_hit = breakpoint_hit_watchpoint; | |
13308 | ops->check_status = check_status_watchpoint; | |
13309 | ops->resources_needed = resources_needed_watchpoint; | |
13310 | ops->works_in_software_mode = works_in_software_mode_watchpoint; | |
13311 | ops->print_it = print_it_watchpoint; | |
13312 | ops->print_mention = print_mention_watchpoint; | |
13313 | ops->print_recreate = print_recreate_watchpoint; | |
13314 | ||
13315 | /* Masked watchpoints. */ | |
13316 | ops = &masked_watchpoint_breakpoint_ops; | |
13317 | *ops = watchpoint_breakpoint_ops; | |
13318 | ops->insert_location = insert_masked_watchpoint; | |
13319 | ops->remove_location = remove_masked_watchpoint; | |
13320 | ops->resources_needed = resources_needed_masked_watchpoint; | |
13321 | ops->works_in_software_mode = works_in_software_mode_masked_watchpoint; | |
13322 | ops->print_it = print_it_masked_watchpoint; | |
13323 | ops->print_one_detail = print_one_detail_masked_watchpoint; | |
13324 | ops->print_mention = print_mention_masked_watchpoint; | |
13325 | ops->print_recreate = print_recreate_masked_watchpoint; | |
13326 | ||
13327 | /* Tracepoints. */ | |
13328 | ops = &tracepoint_breakpoint_ops; | |
13329 | *ops = base_breakpoint_ops; | |
13330 | ops->re_set = tracepoint_re_set; | |
13331 | ops->breakpoint_hit = tracepoint_breakpoint_hit; | |
13332 | ops->print_one_detail = tracepoint_print_one_detail; | |
13333 | ops->print_mention = tracepoint_print_mention; | |
13334 | ops->print_recreate = tracepoint_print_recreate; | |
13335 | ||
13336 | /* Fork catchpoints. */ | |
13337 | ops = &catch_fork_breakpoint_ops; | |
13338 | *ops = base_breakpoint_ops; | |
13339 | ops->insert_location = insert_catch_fork; | |
13340 | ops->remove_location = remove_catch_fork; | |
13341 | ops->breakpoint_hit = breakpoint_hit_catch_fork; | |
13342 | ops->print_it = print_it_catch_fork; | |
13343 | ops->print_one = print_one_catch_fork; | |
13344 | ops->print_mention = print_mention_catch_fork; | |
13345 | ops->print_recreate = print_recreate_catch_fork; | |
13346 | ||
13347 | /* Vfork catchpoints. */ | |
13348 | ops = &catch_vfork_breakpoint_ops; | |
13349 | *ops = base_breakpoint_ops; | |
13350 | ops->insert_location = insert_catch_vfork; | |
13351 | ops->remove_location = remove_catch_vfork; | |
13352 | ops->breakpoint_hit = breakpoint_hit_catch_vfork; | |
13353 | ops->print_it = print_it_catch_vfork; | |
13354 | ops->print_one = print_one_catch_vfork; | |
13355 | ops->print_mention = print_mention_catch_vfork; | |
13356 | ops->print_recreate = print_recreate_catch_vfork; | |
13357 | ||
13358 | /* Exec catchpoints. */ | |
13359 | ops = &catch_exec_breakpoint_ops; | |
13360 | *ops = base_breakpoint_ops; | |
13361 | ops->dtor = dtor_catch_exec; | |
13362 | ops->insert_location = insert_catch_exec; | |
13363 | ops->remove_location = remove_catch_exec; | |
13364 | ops->breakpoint_hit = breakpoint_hit_catch_exec; | |
13365 | ops->print_it = print_it_catch_exec; | |
13366 | ops->print_one = print_one_catch_exec; | |
13367 | ops->print_mention = print_mention_catch_exec; | |
13368 | ops->print_recreate = print_recreate_catch_exec; | |
13369 | ||
13370 | /* Syscall catchpoints. */ | |
13371 | ops = &catch_syscall_breakpoint_ops; | |
13372 | *ops = base_breakpoint_ops; | |
13373 | ops->dtor = dtor_catch_syscall; | |
13374 | ops->insert_location = insert_catch_syscall; | |
13375 | ops->remove_location = remove_catch_syscall; | |
13376 | ops->breakpoint_hit = breakpoint_hit_catch_syscall; | |
13377 | ops->print_it = print_it_catch_syscall; | |
13378 | ops->print_one = print_one_catch_syscall; | |
13379 | ops->print_mention = print_mention_catch_syscall; | |
13380 | ops->print_recreate = print_recreate_catch_syscall; | |
13381 | } | |
13382 | ||
c906108c | 13383 | void |
fba45db2 | 13384 | _initialize_breakpoint (void) |
c906108c SS |
13385 | { |
13386 | struct cmd_list_element *c; | |
13387 | ||
2060206e PA |
13388 | initialize_breakpoint_ops (); |
13389 | ||
84acb35a | 13390 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 13391 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 13392 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 13393 | |
17450429 PP |
13394 | breakpoint_objfile_key = register_objfile_data (); |
13395 | ||
c906108c SS |
13396 | breakpoint_chain = 0; |
13397 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
13398 | before a breakpoint is set. */ | |
13399 | breakpoint_count = 0; | |
13400 | ||
1042e4c0 SS |
13401 | tracepoint_count = 0; |
13402 | ||
1bedd215 AC |
13403 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
13404 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
13405 | Usage is `ignore N COUNT'.")); | |
c906108c | 13406 | if (xdb_commands) |
c5aa993b | 13407 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 13408 | |
1bedd215 AC |
13409 | add_com ("commands", class_breakpoint, commands_command, _("\ |
13410 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
13411 | Give breakpoint number as argument after \"commands\".\n\ |
13412 | With no argument, the targeted breakpoint is the last one set.\n\ | |
13413 | The commands themselves follow starting on the next line.\n\ | |
13414 | Type a line containing \"end\" to indicate the end of them.\n\ | |
13415 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 13416 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 13417 | |
1bedd215 AC |
13418 | add_com ("condition", class_breakpoint, condition_command, _("\ |
13419 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 13420 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 13421 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 13422 | |
1bedd215 | 13423 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 13424 | Set a temporary breakpoint.\n\ |
c906108c SS |
13425 | Like \"break\" except the breakpoint is only temporary,\n\ |
13426 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
13427 | by using \"enable delete\" on the breakpoint number.\n\ |
13428 | \n" | |
13429 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 13430 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13431 | |
1bedd215 | 13432 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 13433 | Set a hardware assisted breakpoint.\n\ |
c906108c | 13434 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
13435 | some target hardware may not have this support.\n\ |
13436 | \n" | |
13437 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 13438 | set_cmd_completer (c, location_completer); |
c906108c | 13439 | |
1bedd215 | 13440 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 13441 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 13442 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
13443 | so it will be deleted when hit.\n\ |
13444 | \n" | |
13445 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 13446 | set_cmd_completer (c, location_completer); |
c906108c | 13447 | |
1bedd215 AC |
13448 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
13449 | Enable some breakpoints.\n\ | |
c906108c SS |
13450 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13451 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13452 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13453 | With a subcommand you can enable temporarily."), |
c906108c SS |
13454 | &enablelist, "enable ", 1, &cmdlist); |
13455 | if (xdb_commands) | |
1bedd215 AC |
13456 | add_com ("ab", class_breakpoint, enable_command, _("\ |
13457 | Enable some breakpoints.\n\ | |
c906108c SS |
13458 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13459 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
13460 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13461 | With a subcommand you can enable temporarily.")); |
c906108c SS |
13462 | |
13463 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
13464 | ||
84951ab5 | 13465 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 13466 | Enable some breakpoints.\n\ |
c906108c SS |
13467 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
13468 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 13469 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 13470 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 13471 | |
1a966eab AC |
13472 | add_cmd ("once", no_class, enable_once_command, _("\ |
13473 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13474 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13475 | &enablebreaklist); |
13476 | ||
1a966eab AC |
13477 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13478 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13479 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13480 | &enablebreaklist); |
13481 | ||
1a966eab AC |
13482 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
13483 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
13484 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
13485 | &enablelist); |
13486 | ||
1a966eab AC |
13487 | add_cmd ("once", no_class, enable_once_command, _("\ |
13488 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
13489 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
13490 | &enablelist); |
13491 | ||
1bedd215 AC |
13492 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
13493 | Disable some breakpoints.\n\ | |
c906108c SS |
13494 | Arguments are breakpoint numbers with spaces in between.\n\ |
13495 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13496 | A disabled breakpoint is not forgotten, but has no effect until re-enabled."), |
c906108c SS |
13497 | &disablelist, "disable ", 1, &cmdlist); |
13498 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
13499 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
13500 | if (xdb_commands) | |
1bedd215 AC |
13501 | add_com ("sb", class_breakpoint, disable_command, _("\ |
13502 | Disable some breakpoints.\n\ | |
c906108c SS |
13503 | Arguments are breakpoint numbers with spaces in between.\n\ |
13504 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13505 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.")); |
c906108c | 13506 | |
1a966eab AC |
13507 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
13508 | Disable some breakpoints.\n\ | |
c906108c SS |
13509 | Arguments are breakpoint numbers with spaces in between.\n\ |
13510 | To disable all breakpoints, give no argument.\n\ | |
64b9b334 | 13511 | A disabled breakpoint is not forgotten, but has no effect until re-enabled.\n\ |
1a966eab | 13512 | This command may be abbreviated \"disable\"."), |
c906108c SS |
13513 | &disablelist); |
13514 | ||
1bedd215 AC |
13515 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
13516 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13517 | Arguments are breakpoint numbers with spaces in between.\n\ |
13518 | To delete all breakpoints, give no argument.\n\ | |
13519 | \n\ | |
13520 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 13521 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
13522 | &deletelist, "delete ", 1, &cmdlist); |
13523 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 13524 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 13525 | if (xdb_commands) |
1bedd215 AC |
13526 | add_com ("db", class_breakpoint, delete_command, _("\ |
13527 | Delete some breakpoints.\n\ | |
c906108c | 13528 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 13529 | To delete all breakpoints, give no argument.\n")); |
c906108c | 13530 | |
1a966eab AC |
13531 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
13532 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13533 | Arguments are breakpoint numbers with spaces in between.\n\ |
13534 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 13535 | This command may be abbreviated \"delete\"."), |
c906108c SS |
13536 | &deletelist); |
13537 | ||
1bedd215 AC |
13538 | add_com ("clear", class_breakpoint, clear_command, _("\ |
13539 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
13540 | Argument may be line number, function name, or \"*\" and an address.\n\ |
13541 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
13542 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
13543 | If an address is specified, breakpoints at that address are cleared.\n\ |
13544 | \n\ | |
13545 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
13546 | is executing in.\n\ |
13547 | \n\ | |
1bedd215 | 13548 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 13549 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 13550 | |
1bedd215 | 13551 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
13552 | Set breakpoint at specified line or function.\n" |
13553 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 13554 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13555 | |
c906108c SS |
13556 | add_com_alias ("b", "break", class_run, 1); |
13557 | add_com_alias ("br", "break", class_run, 1); | |
13558 | add_com_alias ("bre", "break", class_run, 1); | |
13559 | add_com_alias ("brea", "break", class_run, 1); | |
13560 | ||
7681d515 PM |
13561 | if (xdb_commands) |
13562 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
13563 | |
13564 | if (dbx_commands) | |
13565 | { | |
1bedd215 AC |
13566 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
13567 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
13568 | &stoplist, "stop ", 1, &cmdlist); |
13569 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 13570 | _("Break in function or address."), &stoplist); |
c5aa993b | 13571 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 13572 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
13573 | add_com ("status", class_info, breakpoints_info, _("\ |
13574 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13575 | The \"Type\" column indicates one of:\n\ |
13576 | \tbreakpoint - normal breakpoint\n\ | |
13577 | \twatchpoint - watchpoint\n\ | |
13578 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13579 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13580 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13581 | address and file/line number respectively.\n\ |
13582 | \n\ | |
13583 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13584 | are set to the address of the last breakpoint listed unless the command\n\ |
13585 | is prefixed with \"server \".\n\n\ | |
c906108c | 13586 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13587 | breakpoint set.")); |
c906108c SS |
13588 | } |
13589 | ||
1bedd215 | 13590 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 13591 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
13592 | The \"Type\" column indicates one of:\n\ |
13593 | \tbreakpoint - normal breakpoint\n\ | |
13594 | \twatchpoint - watchpoint\n\ | |
13595 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13596 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13597 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13598 | address and file/line number respectively.\n\ |
13599 | \n\ | |
13600 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13601 | are set to the address of the last breakpoint listed unless the command\n\ |
13602 | is prefixed with \"server \".\n\n\ | |
c906108c | 13603 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13604 | breakpoint set.")); |
c906108c | 13605 | |
6b04bdb7 MS |
13606 | add_info_alias ("b", "breakpoints", 1); |
13607 | ||
c906108c | 13608 | if (xdb_commands) |
1bedd215 AC |
13609 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
13610 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13611 | The \"Type\" column indicates one of:\n\ |
13612 | \tbreakpoint - normal breakpoint\n\ | |
13613 | \twatchpoint - watchpoint\n\ | |
13614 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13615 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13616 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13617 | address and file/line number respectively.\n\ |
13618 | \n\ | |
13619 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13620 | are set to the address of the last breakpoint listed unless the command\n\ |
13621 | is prefixed with \"server \".\n\n\ | |
c906108c | 13622 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13623 | breakpoint set.")); |
c906108c | 13624 | |
1a966eab AC |
13625 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
13626 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13627 | The \"Type\" column indicates one of:\n\ |
13628 | \tbreakpoint - normal breakpoint\n\ | |
13629 | \twatchpoint - watchpoint\n\ | |
13630 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
13631 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
13632 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
13633 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
13634 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
13635 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
13636 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
13637 | address and file/line number respectively.\n\ |
13638 | \n\ | |
13639 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13640 | are set to the address of the last breakpoint listed unless the command\n\ |
13641 | is prefixed with \"server \".\n\n\ | |
c906108c | 13642 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 13643 | breakpoint set."), |
c906108c SS |
13644 | &maintenanceinfolist); |
13645 | ||
44feb3ce TT |
13646 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
13647 | Set catchpoints to catch events."), | |
13648 | &catch_cmdlist, "catch ", | |
13649 | 0/*allow-unknown*/, &cmdlist); | |
13650 | ||
13651 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
13652 | Set temporary catchpoints to catch events."), | |
13653 | &tcatch_cmdlist, "tcatch ", | |
13654 | 0/*allow-unknown*/, &cmdlist); | |
13655 | ||
13656 | /* Add catch and tcatch sub-commands. */ | |
13657 | add_catch_command ("catch", _("\ | |
13658 | Catch an exception, when caught.\n\ | |
13659 | With an argument, catch only exceptions with the given name."), | |
13660 | catch_catch_command, | |
a96d9b2e | 13661 | NULL, |
44feb3ce TT |
13662 | CATCH_PERMANENT, |
13663 | CATCH_TEMPORARY); | |
13664 | add_catch_command ("throw", _("\ | |
13665 | Catch an exception, when thrown.\n\ | |
13666 | With an argument, catch only exceptions with the given name."), | |
13667 | catch_throw_command, | |
a96d9b2e | 13668 | NULL, |
44feb3ce TT |
13669 | CATCH_PERMANENT, |
13670 | CATCH_TEMPORARY); | |
13671 | add_catch_command ("fork", _("Catch calls to fork."), | |
13672 | catch_fork_command_1, | |
a96d9b2e | 13673 | NULL, |
44feb3ce TT |
13674 | (void *) (uintptr_t) catch_fork_permanent, |
13675 | (void *) (uintptr_t) catch_fork_temporary); | |
13676 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
13677 | catch_fork_command_1, | |
a96d9b2e | 13678 | NULL, |
44feb3ce TT |
13679 | (void *) (uintptr_t) catch_vfork_permanent, |
13680 | (void *) (uintptr_t) catch_vfork_temporary); | |
13681 | add_catch_command ("exec", _("Catch calls to exec."), | |
13682 | catch_exec_command_1, | |
a96d9b2e SDJ |
13683 | NULL, |
13684 | CATCH_PERMANENT, | |
13685 | CATCH_TEMPORARY); | |
13686 | add_catch_command ("syscall", _("\ | |
13687 | Catch system calls by their names and/or numbers.\n\ | |
13688 | Arguments say which system calls to catch. If no arguments\n\ | |
13689 | are given, every system call will be caught.\n\ | |
13690 | Arguments, if given, should be one or more system call names\n\ | |
13691 | (if your system supports that), or system call numbers."), | |
13692 | catch_syscall_command_1, | |
13693 | catch_syscall_completer, | |
44feb3ce TT |
13694 | CATCH_PERMANENT, |
13695 | CATCH_TEMPORARY); | |
c5aa993b | 13696 | |
1bedd215 AC |
13697 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
13698 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13699 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 13700 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13701 | an expression changes.\n\ |
13702 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13703 | the memory to which it refers.")); | |
65d12d83 | 13704 | set_cmd_completer (c, expression_completer); |
c906108c | 13705 | |
1bedd215 AC |
13706 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
13707 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 13708 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 13709 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13710 | an expression is read.\n\ |
13711 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13712 | the memory to which it refers.")); | |
65d12d83 | 13713 | set_cmd_completer (c, expression_completer); |
c906108c | 13714 | |
1bedd215 AC |
13715 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
13716 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13717 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 13718 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13719 | an expression is either read or written.\n\ |
13720 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13721 | the memory to which it refers.")); | |
65d12d83 | 13722 | set_cmd_completer (c, expression_completer); |
c906108c | 13723 | |
d77f58be | 13724 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 13725 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 13726 | |
920d2a44 AC |
13727 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
13728 | respond to changes - contrary to the description. */ | |
85c07804 AC |
13729 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
13730 | &can_use_hw_watchpoints, _("\ | |
13731 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
13732 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
13733 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
13734 | such is available. (However, any hardware watchpoints that were\n\ | |
13735 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
13736 | hardware.)"), |
13737 | NULL, | |
920d2a44 | 13738 | show_can_use_hw_watchpoints, |
85c07804 | 13739 | &setlist, &showlist); |
c906108c SS |
13740 | |
13741 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 13742 | |
1042e4c0 SS |
13743 | /* Tracepoint manipulation commands. */ |
13744 | ||
13745 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
13746 | Set a tracepoint at specified line or function.\n\ | |
13747 | \n" | |
13748 | BREAK_ARGS_HELP ("trace") "\n\ | |
13749 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13750 | set_cmd_completer (c, location_completer); | |
13751 | ||
13752 | add_com_alias ("tp", "trace", class_alias, 0); | |
13753 | add_com_alias ("tr", "trace", class_alias, 1); | |
13754 | add_com_alias ("tra", "trace", class_alias, 1); | |
13755 | add_com_alias ("trac", "trace", class_alias, 1); | |
13756 | ||
7a697b8d SS |
13757 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
13758 | Set a fast tracepoint at specified line or function.\n\ | |
13759 | \n" | |
13760 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
13761 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13762 | set_cmd_completer (c, location_completer); | |
13763 | ||
0fb4aa4b PA |
13764 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
13765 | Set a static tracepoint at specified line, function or marker.\n\ | |
13766 | \n\ | |
13767 | strace [LOCATION] [if CONDITION]\n\ | |
13768 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
13769 | or -m MARKER_ID.\n\ | |
13770 | If a line number is specified, probe the marker at start of code\n\ | |
13771 | for that line. If a function is specified, probe the marker at start\n\ | |
13772 | of code for that function. If an address is specified, probe the marker\n\ | |
13773 | at that exact address. If a marker id is specified, probe the marker\n\ | |
13774 | with that name. With no LOCATION, uses current execution address of\n\ | |
13775 | the selected stack frame.\n\ | |
13776 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
13777 | This collects arbitrary user data passed in the probe point call to the\n\ | |
13778 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
13779 | by printing the $_sdata variable like any other convenience variable.\n\ | |
13780 | \n\ | |
13781 | CONDITION is a boolean expression.\n\ | |
13782 | \n\ | |
d41c0fc8 PA |
13783 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
13784 | conditions are different.\n\ | |
0fb4aa4b PA |
13785 | \n\ |
13786 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
13787 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13788 | set_cmd_completer (c, location_completer); | |
13789 | ||
1042e4c0 | 13790 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 13791 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
13792 | Convenience variable \"$tpnum\" contains the number of the\n\ |
13793 | last tracepoint set.")); | |
13794 | ||
13795 | add_info_alias ("tp", "tracepoints", 1); | |
13796 | ||
13797 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
13798 | Delete specified tracepoints.\n\ | |
13799 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13800 | No argument means delete all tracepoints."), | |
13801 | &deletelist); | |
13802 | ||
13803 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
13804 | Disable specified tracepoints.\n\ | |
13805 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13806 | No argument means disable all tracepoints."), | |
13807 | &disablelist); | |
13808 | deprecate_cmd (c, "disable"); | |
13809 | ||
13810 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
13811 | Enable specified tracepoints.\n\ | |
13812 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13813 | No argument means enable all tracepoints."), | |
13814 | &enablelist); | |
13815 | deprecate_cmd (c, "enable"); | |
13816 | ||
13817 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
13818 | Set the passcount for a tracepoint.\n\ | |
13819 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
13820 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
13821 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
13822 | ||
6149aea9 PA |
13823 | add_prefix_cmd ("save", class_breakpoint, save_command, |
13824 | _("Save breakpoint definitions as a script."), | |
13825 | &save_cmdlist, "save ", | |
13826 | 0/*allow-unknown*/, &cmdlist); | |
13827 | ||
13828 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
13829 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 13830 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
13831 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
13832 | session to restore them."), | |
13833 | &save_cmdlist); | |
13834 | set_cmd_completer (c, filename_completer); | |
13835 | ||
13836 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 13837 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
13838 | Use the 'source' command in another debug session to restore them."), |
13839 | &save_cmdlist); | |
1042e4c0 SS |
13840 | set_cmd_completer (c, filename_completer); |
13841 | ||
6149aea9 PA |
13842 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
13843 | deprecate_cmd (c, "save tracepoints"); | |
13844 | ||
1bedd215 | 13845 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13846 | Breakpoint specific settings\n\ |
13847 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13848 | pending breakpoint behavior"), |
fa8d40ab JJ |
13849 | &breakpoint_set_cmdlist, "set breakpoint ", |
13850 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 13851 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13852 | Breakpoint specific settings\n\ |
13853 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13854 | pending breakpoint behavior"), |
fa8d40ab JJ |
13855 | &breakpoint_show_cmdlist, "show breakpoint ", |
13856 | 0/*allow-unknown*/, &showlist); | |
13857 | ||
7915a72c AC |
13858 | add_setshow_auto_boolean_cmd ("pending", no_class, |
13859 | &pending_break_support, _("\ | |
13860 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
13861 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
13862 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
13863 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
13864 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 13865 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 13866 | NULL, |
920d2a44 | 13867 | show_pending_break_support, |
6e1d7d6c AC |
13868 | &breakpoint_set_cmdlist, |
13869 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
13870 | |
13871 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
13872 | |
13873 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
13874 | &automatic_hardware_breakpoints, _("\ | |
13875 | Set automatic usage of hardware breakpoints."), _("\ | |
13876 | Show automatic usage of hardware breakpoints."), _("\ | |
13877 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
13878 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
13879 | a warning will be emitted for such breakpoints."), | |
13880 | NULL, | |
13881 | show_automatic_hardware_breakpoints, | |
13882 | &breakpoint_set_cmdlist, | |
13883 | &breakpoint_show_cmdlist); | |
74960c60 | 13884 | |
33e5cbd6 PA |
13885 | add_setshow_enum_cmd ("always-inserted", class_support, |
13886 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
13887 | Set mode for inserting breakpoints."), _("\ |
13888 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
13889 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
13890 | resumed, and removed when execution stops. When this mode is on,\n\ | |
13891 | breakpoints are inserted immediately and removed only when the user\n\ | |
13892 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
13893 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
13894 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
13895 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
13896 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
13897 | NULL, |
13898 | &show_always_inserted_mode, | |
13899 | &breakpoint_set_cmdlist, | |
13900 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
13901 | |
13902 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
13903 | Set a breakpoint for an address range.\n\ | |
13904 | break-range START-LOCATION, END-LOCATION\n\ | |
13905 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
13906 | LINENUM, for that line in the current file,\n\ | |
13907 | FILE:LINENUM, for that line in that file,\n\ | |
13908 | +OFFSET, for that number of lines after the current line\n\ | |
13909 | or the start of the range\n\ | |
13910 | FUNCTION, for the first line in that function,\n\ | |
13911 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
13912 | *ADDRESS, for the instruction at that address.\n\ | |
13913 | \n\ | |
13914 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
13915 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
13916 | range (including START-LOCATION and END-LOCATION).")); | |
13917 | ||
765dc015 | 13918 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
13919 | |
13920 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 13921 | } |