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, |
4c38e0a4 | 5 | 2008, 2009, 2010 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" | |
42 | #include "annotate.h" | |
43 | #include "symfile.h" | |
44 | #include "objfiles.h" | |
0378c332 | 45 | #include "source.h" |
c5f0f3d0 | 46 | #include "linespec.h" |
c94fdfd0 | 47 | #include "completer.h" |
5b7f31a4 | 48 | #include "gdb.h" |
8b93c638 | 49 | #include "ui-out.h" |
e1507482 | 50 | #include "cli/cli-script.h" |
0225421b | 51 | #include "gdb_assert.h" |
fe898f56 | 52 | #include "block.h" |
a77053c2 | 53 | #include "solib.h" |
84acb35a JJ |
54 | #include "solist.h" |
55 | #include "observer.h" | |
60250e8b | 56 | #include "exceptions.h" |
765dc015 | 57 | #include "memattr.h" |
f7f9143b | 58 | #include "ada-lang.h" |
d1aa2f50 | 59 | #include "top.h" |
fa4727a6 | 60 | #include "wrapper.h" |
79a45b7d | 61 | #include "valprint.h" |
4efc6507 | 62 | #include "jit.h" |
a96d9b2e | 63 | #include "xml-syscall.h" |
65d79d4b | 64 | #include "parser-defs.h" |
c906108c | 65 | |
1042e4c0 SS |
66 | /* readline include files */ |
67 | #include "readline/readline.h" | |
68 | #include "readline/history.h" | |
69 | ||
70 | /* readline defines this. */ | |
71 | #undef savestring | |
72 | ||
034dad6f | 73 | #include "mi/mi-common.h" |
104c1213 | 74 | |
44feb3ce TT |
75 | /* Arguments to pass as context to some catch command handlers. */ |
76 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
77 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 78 | |
44feb3ce | 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 | |
a14ed312 | 97 | static void clear_command (char *, int); |
c906108c | 98 | |
a14ed312 | 99 | static void catch_command (char *, int); |
c906108c | 100 | |
a14ed312 | 101 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 102 | |
98deb0da | 103 | static void break_command_1 (char *, int, int); |
c906108c | 104 | |
a14ed312 | 105 | static void mention (struct breakpoint *); |
c906108c | 106 | |
63c252f8 PM |
107 | /* This function is used in gdbtk sources and thus can not be made static. */ |
108 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, | |
a6d9a66e UW |
109 | struct symtab_and_line, |
110 | enum bptype); | |
c906108c | 111 | |
76897487 KB |
112 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
113 | ||
a6d9a66e UW |
114 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
115 | CORE_ADDR bpaddr, | |
88f7da05 | 116 | enum bptype bptype); |
76897487 | 117 | |
6c95b8df PA |
118 | static void describe_other_breakpoints (struct gdbarch *, |
119 | struct program_space *, CORE_ADDR, | |
5af949e3 | 120 | struct obj_section *, int); |
c906108c | 121 | |
6c95b8df PA |
122 | static int breakpoint_address_match (struct address_space *aspace1, |
123 | CORE_ADDR addr1, | |
124 | struct address_space *aspace2, | |
125 | CORE_ADDR addr2); | |
126 | ||
85d721b8 PA |
127 | static int watchpoint_locations_match (struct bp_location *loc1, |
128 | struct bp_location *loc2); | |
129 | ||
a14ed312 | 130 | static void breakpoints_info (char *, int); |
c906108c | 131 | |
d77f58be SS |
132 | static void watchpoints_info (char *, int); |
133 | ||
134 | static int breakpoint_1 (int, int, int (*) (const struct breakpoint *)); | |
c906108c | 135 | |
89f9893c | 136 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 137 | |
4efb68b1 | 138 | static int breakpoint_cond_eval (void *); |
c906108c | 139 | |
4efb68b1 | 140 | static void cleanup_executing_breakpoints (void *); |
c906108c | 141 | |
a14ed312 | 142 | static void commands_command (char *, int); |
c906108c | 143 | |
a14ed312 | 144 | static void condition_command (char *, int); |
c906108c | 145 | |
a14ed312 | 146 | static int get_number_trailer (char **, int); |
c906108c | 147 | |
c5aa993b JM |
148 | typedef enum |
149 | { | |
150 | mark_inserted, | |
151 | mark_uninserted | |
152 | } | |
153 | insertion_state_t; | |
c906108c | 154 | |
0bde7532 | 155 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 156 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 157 | |
a14ed312 | 158 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
159 | |
160 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 161 | |
4efb68b1 | 162 | static int watchpoint_check (void *); |
c906108c | 163 | |
a14ed312 | 164 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 165 | |
a14ed312 | 166 | static int hw_breakpoint_used_count (void); |
c906108c | 167 | |
a14ed312 | 168 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 169 | |
a14ed312 | 170 | static void hbreak_command (char *, int); |
c906108c | 171 | |
a14ed312 | 172 | static void thbreak_command (char *, int); |
c906108c | 173 | |
a14ed312 | 174 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 175 | |
a14ed312 | 176 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 177 | |
a14ed312 | 178 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 179 | |
a14ed312 | 180 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 181 | |
a14ed312 | 182 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 183 | |
d85310f7 MS |
184 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
185 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 186 | |
a14ed312 | 187 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 188 | |
a14ed312 | 189 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 190 | |
d03285ec UW |
191 | static void detach_single_step_breakpoints (void); |
192 | ||
6c95b8df PA |
193 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
194 | CORE_ADDR pc); | |
1aafd4da | 195 | |
fe3f5fa8 VP |
196 | static void free_bp_location (struct bp_location *loc); |
197 | ||
39d61571 | 198 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 199 | |
b60e7edf | 200 | static void update_global_location_list (int); |
a5606eee | 201 | |
b60e7edf | 202 | static void update_global_location_list_nothrow (int); |
74960c60 | 203 | |
1a2ab13a JK |
204 | static int bpstat_remove_bp_location_callback (struct thread_info *th, |
205 | void *data); | |
206 | ||
d77f58be | 207 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 | 208 | |
d77f58be | 209 | static int is_watchpoint (const struct breakpoint *bpt); |
60e1c644 | 210 | |
74960c60 | 211 | static void insert_breakpoint_locations (void); |
a5606eee | 212 | |
a96d9b2e SDJ |
213 | static int syscall_catchpoint_p (struct breakpoint *b); |
214 | ||
1042e4c0 SS |
215 | static void tracepoints_info (char *, int); |
216 | ||
217 | static void delete_trace_command (char *, int); | |
218 | ||
219 | static void enable_trace_command (char *, int); | |
220 | ||
221 | static void disable_trace_command (char *, int); | |
222 | ||
223 | static void trace_pass_command (char *, int); | |
224 | ||
0fb4aa4b PA |
225 | /* Assuming we're creating a static tracepoint, does S look like a |
226 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
227 | #define is_marker_spec(s) \ | |
228 | (strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) | |
229 | ||
5cea2a26 PA |
230 | /* A reference-counted struct command_line. This lets multiple |
231 | breakpoints share a single command list. */ | |
232 | struct counted_command_line | |
233 | { | |
234 | /* The reference count. */ | |
235 | int refc; | |
236 | ||
237 | /* The command list. */ | |
238 | struct command_line *commands; | |
239 | }; | |
240 | ||
241 | struct command_line * | |
242 | breakpoint_commands (struct breakpoint *b) | |
243 | { | |
244 | return b->commands ? b->commands->commands : NULL; | |
245 | } | |
3daf8fe5 | 246 | |
f3b1572e PA |
247 | /* Flag indicating that a command has proceeded the inferior past the |
248 | current breakpoint. */ | |
249 | ||
250 | static int breakpoint_proceeded; | |
251 | ||
2cec12e5 AR |
252 | static const char * |
253 | bpdisp_text (enum bpdisp disp) | |
254 | { | |
255 | /* NOTE: the following values are a part of MI protocol and represent | |
256 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
bc043ef3 | 257 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 258 | |
2cec12e5 AR |
259 | return bpdisps[(int) disp]; |
260 | } | |
c906108c | 261 | |
2cec12e5 | 262 | /* Prototypes for exported functions. */ |
c906108c SS |
263 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
264 | if such is available. */ | |
265 | static int can_use_hw_watchpoints; | |
266 | ||
920d2a44 AC |
267 | static void |
268 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
269 | struct cmd_list_element *c, | |
270 | const char *value) | |
271 | { | |
272 | fprintf_filtered (file, _("\ | |
273 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
274 | value); | |
275 | } | |
276 | ||
fa8d40ab JJ |
277 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
278 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
279 | for unrecognized breakpoint locations. | |
280 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
281 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
282 | static void |
283 | show_pending_break_support (struct ui_file *file, int from_tty, | |
284 | struct cmd_list_element *c, | |
285 | const char *value) | |
286 | { | |
287 | fprintf_filtered (file, _("\ | |
288 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
289 | value); | |
290 | } | |
fa8d40ab | 291 | |
765dc015 VP |
292 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
293 | set with "break" but falling in read-only memory. | |
294 | If 0, gdb will warn about such breakpoints, but won't automatically | |
295 | use hardware breakpoints. */ | |
296 | static int automatic_hardware_breakpoints; | |
297 | static void | |
298 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
299 | struct cmd_list_element *c, | |
300 | const char *value) | |
301 | { | |
302 | fprintf_filtered (file, _("\ | |
303 | Automatic usage of hardware breakpoints is %s.\n"), | |
304 | value); | |
305 | } | |
306 | ||
33e5cbd6 PA |
307 | /* If on, gdb will keep breakpoints inserted even as inferior is |
308 | stopped, and immediately insert any new breakpoints. If off, gdb | |
309 | will insert breakpoints into inferior only when resuming it, and | |
310 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
311 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
312 | ||
313 | static const char always_inserted_auto[] = "auto"; | |
314 | static const char always_inserted_on[] = "on"; | |
315 | static const char always_inserted_off[] = "off"; | |
316 | static const char *always_inserted_enums[] = { | |
317 | always_inserted_auto, | |
318 | always_inserted_off, | |
319 | always_inserted_on, | |
320 | NULL | |
321 | }; | |
322 | static const char *always_inserted_mode = always_inserted_auto; | |
323 | static void | |
74960c60 | 324 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 325 | struct cmd_list_element *c, const char *value) |
74960c60 | 326 | { |
33e5cbd6 PA |
327 | if (always_inserted_mode == always_inserted_auto) |
328 | fprintf_filtered (file, _("\ | |
329 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
330 | value, | |
331 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
332 | else | |
333 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
334 | } |
335 | ||
33e5cbd6 PA |
336 | int |
337 | breakpoints_always_inserted_mode (void) | |
338 | { | |
339 | return (always_inserted_mode == always_inserted_on | |
340 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
341 | } | |
765dc015 | 342 | |
a14ed312 | 343 | void _initialize_breakpoint (void); |
c906108c | 344 | |
c906108c SS |
345 | /* Are we executing breakpoint commands? */ |
346 | static int executing_breakpoint_commands; | |
347 | ||
c02f5703 MS |
348 | /* Are overlay event breakpoints enabled? */ |
349 | static int overlay_events_enabled; | |
350 | ||
c906108c SS |
351 | /* Walk the following statement or block through all breakpoints. |
352 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
353 | breakpoint. */ | |
354 | ||
5c44784c | 355 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 356 | |
5c44784c JM |
357 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
358 | for (B = breakpoint_chain; \ | |
359 | B ? (TMP=B->next, 1): 0; \ | |
360 | B = TMP) | |
c906108c | 361 | |
876fa593 JK |
362 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
363 | provided so update_global_location_list must not be called while executing | |
364 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 365 | |
876fa593 JK |
366 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
367 | for (BP_TMP = bp_location; \ | |
368 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
369 | BP_TMP++) | |
7cc221ef | 370 | |
1042e4c0 SS |
371 | /* Iterator for tracepoints only. */ |
372 | ||
373 | #define ALL_TRACEPOINTS(B) \ | |
374 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 375 | if (is_tracepoint (B)) |
1042e4c0 | 376 | |
7cc221ef | 377 | /* Chains of all breakpoints defined. */ |
c906108c SS |
378 | |
379 | struct breakpoint *breakpoint_chain; | |
380 | ||
876fa593 JK |
381 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
382 | ||
383 | static struct bp_location **bp_location; | |
384 | ||
385 | /* Number of elements of BP_LOCATION. */ | |
386 | ||
387 | static unsigned bp_location_count; | |
388 | ||
389 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
390 | for the current elements of BP_LOCATION which get a valid result from | |
391 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
392 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
393 | ||
394 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
395 | ||
396 | /* Maximum offset plus alignment between | |
397 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
398 | the current elements of BP_LOCATION which get a valid result from | |
399 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
400 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
401 | ||
402 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 403 | |
20874c92 | 404 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 405 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
406 | may still be reported by a target. */ |
407 | VEC(bp_location_p) *moribund_locations = NULL; | |
408 | ||
c906108c SS |
409 | /* Number of last breakpoint made. */ |
410 | ||
95a42b64 TT |
411 | static int breakpoint_count; |
412 | ||
86b17b60 PA |
413 | /* The value of `breakpoint_count' before the last command that |
414 | created breakpoints. If the last (break-like) command created more | |
415 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
416 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
417 | static int prev_breakpoint_count; | |
c906108c | 418 | |
1042e4c0 SS |
419 | /* Number of last tracepoint made. */ |
420 | ||
95a42b64 | 421 | static int tracepoint_count; |
1042e4c0 | 422 | |
6149aea9 PA |
423 | static struct cmd_list_element *breakpoint_set_cmdlist; |
424 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 425 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 426 | |
468d015d JJ |
427 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
428 | static int | |
429 | breakpoint_enabled (struct breakpoint *b) | |
430 | { | |
0d381245 | 431 | return (b->enable_state == bp_enabled); |
468d015d JJ |
432 | } |
433 | ||
c906108c SS |
434 | /* Set breakpoint count to NUM. */ |
435 | ||
95a42b64 | 436 | static void |
fba45db2 | 437 | set_breakpoint_count (int num) |
c906108c | 438 | { |
86b17b60 | 439 | prev_breakpoint_count = breakpoint_count; |
c906108c | 440 | breakpoint_count = num; |
4fa62494 | 441 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
442 | } |
443 | ||
86b17b60 PA |
444 | /* Used by `start_rbreak_breakpoints' below, to record the current |
445 | breakpoint count before "rbreak" creates any breakpoint. */ | |
446 | static int rbreak_start_breakpoint_count; | |
447 | ||
95a42b64 TT |
448 | /* Called at the start an "rbreak" command to record the first |
449 | breakpoint made. */ | |
86b17b60 | 450 | |
95a42b64 TT |
451 | void |
452 | start_rbreak_breakpoints (void) | |
453 | { | |
86b17b60 | 454 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
455 | } |
456 | ||
457 | /* Called at the end of an "rbreak" command to record the last | |
458 | breakpoint made. */ | |
86b17b60 | 459 | |
95a42b64 TT |
460 | void |
461 | end_rbreak_breakpoints (void) | |
462 | { | |
86b17b60 | 463 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
464 | } |
465 | ||
c906108c SS |
466 | /* Used in run_command to zero the hit count when a new run starts. */ |
467 | ||
468 | void | |
fba45db2 | 469 | clear_breakpoint_hit_counts (void) |
c906108c SS |
470 | { |
471 | struct breakpoint *b; | |
472 | ||
473 | ALL_BREAKPOINTS (b) | |
474 | b->hit_count = 0; | |
475 | } | |
476 | ||
9add0f1b TT |
477 | /* Allocate a new counted_command_line with reference count of 1. |
478 | The new structure owns COMMANDS. */ | |
479 | ||
480 | static struct counted_command_line * | |
481 | alloc_counted_command_line (struct command_line *commands) | |
482 | { | |
483 | struct counted_command_line *result | |
484 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 485 | |
9add0f1b TT |
486 | result->refc = 1; |
487 | result->commands = commands; | |
488 | return result; | |
489 | } | |
490 | ||
491 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
492 | ||
493 | static void | |
494 | incref_counted_command_line (struct counted_command_line *cmd) | |
495 | { | |
496 | if (cmd) | |
497 | ++cmd->refc; | |
498 | } | |
499 | ||
500 | /* Decrement reference count. If the reference count reaches 0, | |
501 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
502 | nothing if *CMDP is NULL. */ | |
503 | ||
504 | static void | |
505 | decref_counted_command_line (struct counted_command_line **cmdp) | |
506 | { | |
507 | if (*cmdp) | |
508 | { | |
509 | if (--(*cmdp)->refc == 0) | |
510 | { | |
511 | free_command_lines (&(*cmdp)->commands); | |
512 | xfree (*cmdp); | |
513 | } | |
514 | *cmdp = NULL; | |
515 | } | |
516 | } | |
517 | ||
518 | /* A cleanup function that calls decref_counted_command_line. */ | |
519 | ||
520 | static void | |
521 | do_cleanup_counted_command_line (void *arg) | |
522 | { | |
523 | decref_counted_command_line (arg); | |
524 | } | |
525 | ||
526 | /* Create a cleanup that calls decref_counted_command_line on the | |
527 | argument. */ | |
528 | ||
529 | static struct cleanup * | |
530 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
531 | { | |
532 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
533 | } | |
534 | ||
c906108c SS |
535 | /* Default address, symtab and line to put a breakpoint at |
536 | for "break" command with no arg. | |
537 | if default_breakpoint_valid is zero, the other three are | |
538 | not valid, and "break" with no arg is an error. | |
539 | ||
540 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
541 | ||
542 | int default_breakpoint_valid; | |
543 | CORE_ADDR default_breakpoint_address; | |
544 | struct symtab *default_breakpoint_symtab; | |
545 | int default_breakpoint_line; | |
6c95b8df PA |
546 | struct program_space *default_breakpoint_pspace; |
547 | ||
c906108c SS |
548 | \f |
549 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
550 | Advance *PP after the string and any trailing whitespace. | |
551 | ||
552 | Currently the string can either be a number or "$" followed by the name | |
553 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 554 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
555 | |
556 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
557 | |
558 | TRAILER is a character which can be found after the number; most | |
559 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 560 | static int |
fba45db2 | 561 | get_number_trailer (char **pp, int trailer) |
c906108c | 562 | { |
5c44784c | 563 | int retval = 0; /* default */ |
c906108c SS |
564 | char *p = *pp; |
565 | ||
566 | if (p == NULL) | |
567 | /* Empty line means refer to the last breakpoint. */ | |
568 | return breakpoint_count; | |
569 | else if (*p == '$') | |
570 | { | |
571 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 572 | to pass to lookup_internalvar(). */ |
c906108c SS |
573 | char *varname; |
574 | char *start = ++p; | |
4fa62494 | 575 | LONGEST val; |
c906108c SS |
576 | |
577 | while (isalnum (*p) || *p == '_') | |
578 | p++; | |
579 | varname = (char *) alloca (p - start + 1); | |
580 | strncpy (varname, start, p - start); | |
581 | varname[p - start] = '\0'; | |
4fa62494 UW |
582 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
583 | retval = (int) val; | |
5c44784c JM |
584 | else |
585 | { | |
a3f17187 | 586 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
587 | retval = 0; |
588 | } | |
c906108c SS |
589 | } |
590 | else | |
591 | { | |
592 | if (*p == '-') | |
593 | ++p; | |
594 | while (*p >= '0' && *p <= '9') | |
595 | ++p; | |
596 | if (p == *pp) | |
597 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
598 | { |
599 | /* Skip non-numeric token */ | |
600 | while (*p && !isspace((int) *p)) | |
601 | ++p; | |
602 | /* Return zero, which caller must interpret as error. */ | |
603 | retval = 0; | |
604 | } | |
605 | else | |
606 | retval = atoi (*pp); | |
607 | } | |
608 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
609 | { | |
610 | /* Trailing junk: return 0 and let caller print error msg. */ | |
611 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
612 | ++p; | |
613 | retval = 0; | |
c906108c | 614 | } |
c906108c SS |
615 | while (isspace (*p)) |
616 | p++; | |
617 | *pp = p; | |
618 | return retval; | |
619 | } | |
5c44784c | 620 | |
11cf8741 | 621 | |
5c44784c JM |
622 | /* Like get_number_trailer, but don't allow a trailer. */ |
623 | int | |
fba45db2 | 624 | get_number (char **pp) |
5c44784c JM |
625 | { |
626 | return get_number_trailer (pp, '\0'); | |
627 | } | |
628 | ||
629 | /* Parse a number or a range. | |
630 | * A number will be of the form handled by get_number. | |
631 | * A range will be of the form <number1> - <number2>, and | |
632 | * will represent all the integers between number1 and number2, | |
633 | * inclusive. | |
634 | * | |
635 | * While processing a range, this fuction is called iteratively; | |
636 | * At each call it will return the next value in the range. | |
637 | * | |
638 | * At the beginning of parsing a range, the char pointer PP will | |
639 | * be advanced past <number1> and left pointing at the '-' token. | |
640 | * Subsequent calls will not advance the pointer until the range | |
641 | * is completed. The call that completes the range will advance | |
642 | * pointer PP past <number2>. | |
643 | */ | |
644 | ||
645 | int | |
fba45db2 | 646 | get_number_or_range (char **pp) |
5c44784c JM |
647 | { |
648 | static int last_retval, end_value; | |
649 | static char *end_ptr; | |
650 | static int in_range = 0; | |
651 | ||
652 | if (**pp != '-') | |
653 | { | |
654 | /* Default case: pp is pointing either to a solo number, | |
655 | or to the first number of a range. */ | |
656 | last_retval = get_number_trailer (pp, '-'); | |
657 | if (**pp == '-') | |
658 | { | |
659 | char **temp; | |
660 | ||
661 | /* This is the start of a range (<number1> - <number2>). | |
662 | Skip the '-', parse and remember the second number, | |
663 | and also remember the end of the final token. */ | |
664 | ||
665 | temp = &end_ptr; | |
666 | end_ptr = *pp + 1; | |
667 | while (isspace ((int) *end_ptr)) | |
668 | end_ptr++; /* skip white space */ | |
669 | end_value = get_number (temp); | |
670 | if (end_value < last_retval) | |
671 | { | |
8a3fe4f8 | 672 | error (_("inverted range")); |
5c44784c JM |
673 | } |
674 | else if (end_value == last_retval) | |
675 | { | |
676 | /* degenerate range (number1 == number2). Advance the | |
677 | token pointer so that the range will be treated as a | |
678 | single number. */ | |
679 | *pp = end_ptr; | |
680 | } | |
681 | else | |
682 | in_range = 1; | |
683 | } | |
684 | } | |
685 | else if (! in_range) | |
8a3fe4f8 | 686 | error (_("negative value")); |
5c44784c JM |
687 | else |
688 | { | |
689 | /* pp points to the '-' that betokens a range. All | |
690 | number-parsing has already been done. Return the next | |
691 | integer value (one greater than the saved previous value). | |
692 | Do not advance the token pointer 'pp' until the end of range | |
693 | is reached. */ | |
694 | ||
695 | if (++last_retval == end_value) | |
696 | { | |
697 | /* End of range reached; advance token pointer. */ | |
698 | *pp = end_ptr; | |
699 | in_range = 0; | |
700 | } | |
701 | } | |
702 | return last_retval; | |
703 | } | |
704 | ||
48cb2d85 VP |
705 | /* Return the breakpoint with the specified number, or NULL |
706 | if the number does not refer to an existing breakpoint. */ | |
707 | ||
708 | struct breakpoint * | |
709 | get_breakpoint (int num) | |
710 | { | |
711 | struct breakpoint *b; | |
712 | ||
713 | ALL_BREAKPOINTS (b) | |
714 | if (b->number == num) | |
715 | return b; | |
716 | ||
717 | return NULL; | |
718 | } | |
5c44784c | 719 | |
c906108c | 720 | \f |
adc36818 PM |
721 | |
722 | void | |
723 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
724 | int from_tty) | |
725 | { | |
726 | struct bp_location *loc = b->loc; | |
727 | ||
728 | for (; loc; loc = loc->next) | |
729 | { | |
730 | xfree (loc->cond); | |
731 | loc->cond = NULL; | |
732 | } | |
733 | xfree (b->cond_string); | |
734 | b->cond_string = NULL; | |
735 | xfree (b->cond_exp); | |
736 | b->cond_exp = NULL; | |
737 | ||
738 | if (*exp == 0) | |
739 | { | |
740 | if (from_tty) | |
741 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
742 | } | |
743 | else | |
744 | { | |
745 | char *arg = exp; | |
cc59ec59 | 746 | |
adc36818 PM |
747 | /* I don't know if it matters whether this is the string the user |
748 | typed in or the decompiled expression. */ | |
749 | b->cond_string = xstrdup (arg); | |
750 | b->condition_not_parsed = 0; | |
751 | ||
752 | if (is_watchpoint (b)) | |
753 | { | |
754 | innermost_block = NULL; | |
755 | arg = exp; | |
756 | b->cond_exp = parse_exp_1 (&arg, 0, 0); | |
757 | if (*arg) | |
758 | error (_("Junk at end of expression")); | |
759 | b->cond_exp_valid_block = innermost_block; | |
760 | } | |
761 | else | |
762 | { | |
763 | for (loc = b->loc; loc; loc = loc->next) | |
764 | { | |
765 | arg = exp; | |
766 | loc->cond = | |
767 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
768 | if (*arg) | |
769 | error (_("Junk at end of expression")); | |
770 | } | |
771 | } | |
772 | } | |
773 | breakpoints_changed (); | |
774 | observer_notify_breakpoint_modified (b->number); | |
775 | } | |
776 | ||
c906108c SS |
777 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
778 | ||
779 | static void | |
fba45db2 | 780 | condition_command (char *arg, int from_tty) |
c906108c | 781 | { |
52f0bd74 | 782 | struct breakpoint *b; |
c906108c | 783 | char *p; |
52f0bd74 | 784 | int bnum; |
c906108c SS |
785 | |
786 | if (arg == 0) | |
e2e0b3e5 | 787 | error_no_arg (_("breakpoint number")); |
c906108c SS |
788 | |
789 | p = arg; | |
790 | bnum = get_number (&p); | |
5c44784c | 791 | if (bnum == 0) |
8a3fe4f8 | 792 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
793 | |
794 | ALL_BREAKPOINTS (b) | |
795 | if (b->number == bnum) | |
2f069f6f | 796 | { |
2566ad2d | 797 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
798 | return; |
799 | } | |
c906108c | 800 | |
8a3fe4f8 | 801 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
802 | } |
803 | ||
a7bdde9e VP |
804 | /* Check that COMMAND do not contain commands that are suitable |
805 | only for tracepoints and not suitable for ordinary breakpoints. | |
806 | Throw if any such commands is found. | |
807 | */ | |
808 | static void | |
809 | check_no_tracepoint_commands (struct command_line *commands) | |
810 | { | |
811 | struct command_line *c; | |
cc59ec59 | 812 | |
a7bdde9e VP |
813 | for (c = commands; c; c = c->next) |
814 | { | |
815 | int i; | |
816 | ||
817 | if (c->control_type == while_stepping_control) | |
818 | error (_("The 'while-stepping' command can only be used for tracepoints")); | |
819 | ||
820 | for (i = 0; i < c->body_count; ++i) | |
821 | check_no_tracepoint_commands ((c->body_list)[i]); | |
822 | ||
823 | /* Not that command parsing removes leading whitespace and comment | |
824 | lines and also empty lines. So, we only need to check for | |
825 | command directly. */ | |
826 | if (strstr (c->line, "collect ") == c->line) | |
827 | error (_("The 'collect' command can only be used for tracepoints")); | |
828 | ||
51661e93 VP |
829 | if (strstr (c->line, "teval ") == c->line) |
830 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
831 | } |
832 | } | |
833 | ||
d77f58be SS |
834 | /* Encapsulate tests for different types of tracepoints. */ |
835 | ||
a7bdde9e | 836 | int |
d77f58be | 837 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 838 | { |
0fb4aa4b PA |
839 | return (b->type == bp_tracepoint |
840 | || b->type == bp_fast_tracepoint | |
841 | || b->type == bp_static_tracepoint); | |
a7bdde9e | 842 | } |
d77f58be | 843 | |
95a42b64 TT |
844 | /* A helper function that validsates that COMMANDS are valid for a |
845 | breakpoint. This function will throw an exception if a problem is | |
846 | found. */ | |
48cb2d85 | 847 | |
95a42b64 TT |
848 | static void |
849 | validate_commands_for_breakpoint (struct breakpoint *b, | |
850 | struct command_line *commands) | |
48cb2d85 | 851 | { |
d77f58be | 852 | if (is_tracepoint (b)) |
a7bdde9e VP |
853 | { |
854 | /* We need to verify that each top-level element of commands | |
855 | is valid for tracepoints, that there's at most one while-stepping | |
856 | element, and that while-stepping's body has valid tracing commands | |
857 | excluding nested while-stepping. */ | |
858 | struct command_line *c; | |
859 | struct command_line *while_stepping = 0; | |
860 | for (c = commands; c; c = c->next) | |
861 | { | |
a7bdde9e VP |
862 | if (c->control_type == while_stepping_control) |
863 | { | |
864 | if (b->type == bp_fast_tracepoint) | |
0fb4aa4b PA |
865 | error (_("\ |
866 | The 'while-stepping' command cannot be used for fast tracepoint")); | |
867 | else if (b->type == bp_static_tracepoint) | |
868 | error (_("\ | |
869 | The 'while-stepping' command cannot be used for static tracepoint")); | |
a7bdde9e VP |
870 | |
871 | if (while_stepping) | |
872 | error (_("The 'while-stepping' command can be used only once")); | |
873 | else | |
874 | while_stepping = c; | |
875 | } | |
876 | } | |
877 | if (while_stepping) | |
878 | { | |
879 | struct command_line *c2; | |
880 | ||
881 | gdb_assert (while_stepping->body_count == 1); | |
882 | c2 = while_stepping->body_list[0]; | |
883 | for (; c2; c2 = c2->next) | |
884 | { | |
a7bdde9e VP |
885 | if (c2->control_type == while_stepping_control) |
886 | error (_("The 'while-stepping' command cannot be nested")); | |
887 | } | |
888 | } | |
889 | } | |
890 | else | |
891 | { | |
892 | check_no_tracepoint_commands (commands); | |
893 | } | |
95a42b64 TT |
894 | } |
895 | ||
0fb4aa4b PA |
896 | /* Return a vector of all the static tracepoints set at ADDR. The |
897 | caller is responsible for releasing the vector. */ | |
898 | ||
899 | VEC(breakpoint_p) * | |
900 | static_tracepoints_here (CORE_ADDR addr) | |
901 | { | |
902 | struct breakpoint *b; | |
903 | VEC(breakpoint_p) *found = 0; | |
904 | struct bp_location *loc; | |
905 | ||
906 | ALL_BREAKPOINTS (b) | |
907 | if (b->type == bp_static_tracepoint) | |
908 | { | |
909 | for (loc = b->loc; loc; loc = loc->next) | |
910 | if (loc->address == addr) | |
911 | VEC_safe_push(breakpoint_p, found, b); | |
912 | } | |
913 | ||
914 | return found; | |
915 | } | |
916 | ||
95a42b64 TT |
917 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
918 | validate that only allowed commands are included. | |
919 | */ | |
920 | ||
921 | void | |
922 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
923 | { | |
924 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 925 | |
9add0f1b TT |
926 | decref_counted_command_line (&b->commands); |
927 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
928 | breakpoints_changed (); |
929 | observer_notify_breakpoint_modified (b->number); | |
930 | } | |
931 | ||
95a42b64 TT |
932 | void |
933 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
934 | { |
935 | struct breakpoint *b = closure; | |
cc59ec59 | 936 | |
a7bdde9e VP |
937 | validate_actionline (&line, b); |
938 | } | |
939 | ||
95a42b64 TT |
940 | /* A structure used to pass information through |
941 | map_breakpoint_numbers. */ | |
942 | ||
943 | struct commands_info | |
944 | { | |
945 | /* True if the command was typed at a tty. */ | |
946 | int from_tty; | |
86b17b60 PA |
947 | |
948 | /* The breakpoint range spec. */ | |
949 | char *arg; | |
950 | ||
95a42b64 TT |
951 | /* Non-NULL if the body of the commands are being read from this |
952 | already-parsed command. */ | |
953 | struct command_line *control; | |
86b17b60 | 954 | |
95a42b64 TT |
955 | /* The command lines read from the user, or NULL if they have not |
956 | yet been read. */ | |
957 | struct counted_command_line *cmd; | |
958 | }; | |
959 | ||
960 | /* A callback for map_breakpoint_numbers that sets the commands for | |
961 | commands_command. */ | |
962 | ||
c906108c | 963 | static void |
95a42b64 | 964 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 965 | { |
95a42b64 | 966 | struct commands_info *info = data; |
c906108c | 967 | |
95a42b64 TT |
968 | if (info->cmd == NULL) |
969 | { | |
970 | struct command_line *l; | |
5c44784c | 971 | |
95a42b64 TT |
972 | if (info->control != NULL) |
973 | l = copy_command_lines (info->control->body_list[0]); | |
974 | else | |
86b17b60 PA |
975 | { |
976 | struct cleanup *old_chain; | |
977 | char *str; | |
c5aa993b | 978 | |
86b17b60 PA |
979 | str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."), |
980 | info->arg); | |
981 | ||
982 | old_chain = make_cleanup (xfree, str); | |
983 | ||
984 | l = read_command_lines (str, | |
985 | info->from_tty, 1, | |
d77f58be | 986 | (is_tracepoint (b) |
86b17b60 PA |
987 | ? check_tracepoint_command : 0), |
988 | b); | |
989 | ||
990 | do_cleanups (old_chain); | |
991 | } | |
a7bdde9e | 992 | |
95a42b64 TT |
993 | info->cmd = alloc_counted_command_line (l); |
994 | } | |
995 | ||
996 | /* If a breakpoint was on the list more than once, we don't need to | |
997 | do anything. */ | |
998 | if (b->commands != info->cmd) | |
999 | { | |
1000 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1001 | incref_counted_command_line (info->cmd); | |
1002 | decref_counted_command_line (&b->commands); | |
1003 | b->commands = info->cmd; | |
1004 | breakpoints_changed (); | |
1005 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 1006 | } |
95a42b64 TT |
1007 | } |
1008 | ||
1009 | static void | |
1010 | commands_command_1 (char *arg, int from_tty, struct command_line *control) | |
1011 | { | |
1012 | struct cleanup *cleanups; | |
1013 | struct commands_info info; | |
1014 | ||
1015 | info.from_tty = from_tty; | |
1016 | info.control = control; | |
1017 | info.cmd = NULL; | |
1018 | /* If we read command lines from the user, then `info' will hold an | |
1019 | extra reference to the commands that we must clean up. */ | |
1020 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1021 | ||
1022 | if (arg == NULL || !*arg) | |
1023 | { | |
86b17b60 PA |
1024 | if (breakpoint_count - prev_breakpoint_count > 1) |
1025 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count); | |
95a42b64 TT |
1026 | else if (breakpoint_count > 0) |
1027 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1028 | else |
1029 | { | |
1030 | /* So that we don't try to free the incoming non-NULL | |
1031 | argument in the cleanup below. Mapping breakpoint | |
1032 | numbers will fail in this case. */ | |
1033 | arg = NULL; | |
1034 | } | |
95a42b64 | 1035 | } |
9766ced4 SS |
1036 | else |
1037 | /* The command loop has some static state, so we need to preserve | |
1038 | our argument. */ | |
1039 | arg = xstrdup (arg); | |
86b17b60 PA |
1040 | |
1041 | if (arg != NULL) | |
1042 | make_cleanup (xfree, arg); | |
1043 | ||
1044 | info.arg = arg; | |
95a42b64 TT |
1045 | |
1046 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1047 | ||
1048 | if (info.cmd == NULL) | |
1049 | error (_("No breakpoints specified.")); | |
1050 | ||
1051 | do_cleanups (cleanups); | |
1052 | } | |
1053 | ||
1054 | static void | |
1055 | commands_command (char *arg, int from_tty) | |
1056 | { | |
1057 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1058 | } |
40c03ae8 EZ |
1059 | |
1060 | /* Like commands_command, but instead of reading the commands from | |
1061 | input stream, takes them from an already parsed command structure. | |
1062 | ||
1063 | This is used by cli-script.c to DTRT with breakpoint commands | |
1064 | that are part of if and while bodies. */ | |
1065 | enum command_control_type | |
1066 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1067 | { | |
95a42b64 TT |
1068 | commands_command_1 (arg, 0, cmd); |
1069 | return simple_control; | |
40c03ae8 | 1070 | } |
876fa593 JK |
1071 | |
1072 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1073 | ||
1074 | static int | |
1075 | bp_location_has_shadow (struct bp_location *bl) | |
1076 | { | |
1077 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1078 | return 0; | |
1079 | if (!bl->inserted) | |
1080 | return 0; | |
1081 | if (bl->target_info.shadow_len == 0) | |
1082 | /* bp isn't valid, or doesn't shadow memory. */ | |
1083 | return 0; | |
1084 | return 1; | |
1085 | } | |
1086 | ||
8defab1a | 1087 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1088 | by replacing any memory breakpoints with their shadowed contents. |
1089 | ||
1090 | The range of shadowed area by each bp_location is: | |
1091 | b->address - bp_location_placed_address_before_address_max | |
1092 | up to b->address + bp_location_shadow_len_after_address_max | |
1093 | The range we were requested to resolve shadows for is: | |
1094 | memaddr ... memaddr + len | |
1095 | Thus the safe cutoff boundaries for performance optimization are | |
1096 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
1097 | and: | |
1098 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 1099 | |
8defab1a DJ |
1100 | void |
1101 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1102 | { |
876fa593 JK |
1103 | /* Left boundary, right boundary and median element of our binary search. */ |
1104 | unsigned bc_l, bc_r, bc; | |
1105 | ||
1106 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
1107 | safe to report lower value but a failure to report higher one. */ | |
1108 | ||
1109 | bc_l = 0; | |
1110 | bc_r = bp_location_count; | |
1111 | while (bc_l + 1 < bc_r) | |
1112 | { | |
1113 | struct bp_location *b; | |
1114 | ||
1115 | bc = (bc_l + bc_r) / 2; | |
1116 | b = bp_location[bc]; | |
1117 | ||
1118 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
1119 | Then advance the left boundary only if we are sure the BC element can | |
1120 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
1121 | ||
1122 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
1123 | we cannot miss a breakpoint with its shadow range tail still reaching | |
1124 | MEMADDR. */ | |
c5aa993b | 1125 | |
876fa593 JK |
1126 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
1127 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
1128 | bc_l = bc; | |
1129 | else | |
1130 | bc_r = bc; | |
1131 | } | |
1132 | ||
1133 | /* Now do full processing of the found relevant range of elements. */ | |
1134 | ||
1135 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1136 | { |
876fa593 JK |
1137 | struct bp_location *b = bp_location[bc]; |
1138 | CORE_ADDR bp_addr = 0; | |
1139 | int bp_size = 0; | |
1140 | int bptoffset = 0; | |
1141 | ||
2bdf28a0 | 1142 | /* bp_location array has B->OWNER always non-NULL. */ |
ffce0d52 | 1143 | if (b->owner->type == bp_none) |
8a3fe4f8 | 1144 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
1145 | b->owner->number); |
1146 | ||
876fa593 JK |
1147 | /* Performance optimization: any futher element can no longer affect BUF |
1148 | content. */ | |
1149 | ||
1150 | if (b->address >= bp_location_placed_address_before_address_max | |
1151 | && memaddr + len <= b->address | |
1152 | - bp_location_placed_address_before_address_max) | |
1153 | break; | |
1154 | ||
1155 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 1156 | continue; |
6c95b8df PA |
1157 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
1158 | current_program_space->aspace, 0)) | |
1159 | continue; | |
1160 | ||
c5aa993b JM |
1161 | /* Addresses and length of the part of the breakpoint that |
1162 | we need to copy. */ | |
8181d85f DJ |
1163 | bp_addr = b->target_info.placed_address; |
1164 | bp_size = b->target_info.shadow_len; | |
8defab1a | 1165 | |
c5aa993b JM |
1166 | if (bp_addr + bp_size <= memaddr) |
1167 | /* The breakpoint is entirely before the chunk of memory we | |
1168 | are reading. */ | |
1169 | continue; | |
8defab1a | 1170 | |
c5aa993b JM |
1171 | if (bp_addr >= memaddr + len) |
1172 | /* The breakpoint is entirely after the chunk of memory we are | |
1173 | reading. */ | |
1174 | continue; | |
c5aa993b | 1175 | |
8defab1a DJ |
1176 | /* Offset within shadow_contents. */ |
1177 | if (bp_addr < memaddr) | |
1178 | { | |
1179 | /* Only copy the second part of the breakpoint. */ | |
1180 | bp_size -= memaddr - bp_addr; | |
1181 | bptoffset = memaddr - bp_addr; | |
1182 | bp_addr = memaddr; | |
1183 | } | |
c5aa993b | 1184 | |
8defab1a DJ |
1185 | if (bp_addr + bp_size > memaddr + len) |
1186 | { | |
1187 | /* Only copy the first part of the breakpoint. */ | |
1188 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1189 | } | |
c5aa993b | 1190 | |
8defab1a DJ |
1191 | memcpy (buf + bp_addr - memaddr, |
1192 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 1193 | } |
c906108c | 1194 | } |
c906108c | 1195 | \f |
c5aa993b | 1196 | |
687595f9 | 1197 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 1198 | static void |
687595f9 DJ |
1199 | insert_catchpoint (struct ui_out *uo, void *args) |
1200 | { | |
1201 | struct breakpoint *b = (struct breakpoint *) args; | |
687595f9 | 1202 | |
fe798b75 JB |
1203 | gdb_assert (b->type == bp_catchpoint); |
1204 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
1205 | ||
1206 | b->ops->insert (b); | |
687595f9 DJ |
1207 | } |
1208 | ||
60e1c644 PA |
1209 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1210 | ||
a5606eee | 1211 | static int |
d77f58be | 1212 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1213 | { |
1214 | return (bpt->type == bp_hardware_watchpoint | |
1215 | || bpt->type == bp_read_watchpoint | |
1216 | || bpt->type == bp_access_watchpoint); | |
1217 | } | |
7270d8f2 | 1218 | |
60e1c644 PA |
1219 | /* Return true if BPT is of any watchpoint kind, hardware or |
1220 | software. */ | |
1221 | ||
1222 | static int | |
d77f58be | 1223 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1224 | { |
1225 | return (is_hardware_watchpoint (bpt) | |
1226 | || bpt->type == bp_watchpoint); | |
1227 | } | |
1228 | ||
f6bc2008 PA |
1229 | /* Assuming that B is a watchpoint: returns true if the current thread |
1230 | and its running state are safe to evaluate or update watchpoint B. | |
1231 | Watchpoints on local expressions need to be evaluated in the | |
1232 | context of the thread that was current when the watchpoint was | |
1233 | created, and, that thread needs to be stopped to be able to select | |
1234 | the correct frame context. Watchpoints on global expressions can | |
1235 | be evaluated on any thread, and in any state. It is presently left | |
1236 | to the target allowing memory accesses when threads are | |
1237 | running. */ | |
1238 | ||
1239 | static int | |
1240 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1241 | { | |
1242 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1243 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1244 | && !is_executing (inferior_ptid))); | |
1245 | } | |
1246 | ||
567e1b4e JB |
1247 | /* Assuming that B is a watchpoint: |
1248 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1249 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1250 | - Evaluate the condition if there is one, and store the result |
1251 | in b->loc->cond. | |
a5606eee VP |
1252 | - Update the list of values that must be watched in B->loc. |
1253 | ||
bfa149ac | 1254 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1255 | If this is local watchpoint that is out of scope, delete it. |
1256 | ||
1257 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1258 | + inserted on each stop here. Normal breakpoints must never be removed | |
1259 | because they might be missed by a running thread when debugging in non-stop | |
1260 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1261 | processed here) are specific to each LWP since they are stored in each LWP's | |
1262 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1263 | order to be able to modify its hardware watchpoints. | |
1264 | ||
1265 | Hardware watchpoints must be reset exactly once after being presented to the | |
1266 | user. It cannot be done sooner, because it would reset the data used to | |
1267 | present the watchpoint hit to the user. And it must not be done later | |
1268 | because it could display the same single watchpoint hit during multiple GDB | |
1269 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1270 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1271 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1272 | memory content has not changed. | |
1273 | ||
1274 | The following constraints influence the location where we can reset hardware | |
1275 | watchpoints: | |
1276 | ||
1277 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1278 | several times when GDB stops. | |
1279 | ||
1280 | [linux] | |
1281 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1282 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1283 | reason for stopping, and all the other hits are presented later, one after | |
1284 | the other, each time the user requests the execution to be resumed. | |
1285 | Execution is not resumed for the threads still having pending hit event | |
1286 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1287 | the inferior on the first stop the thread hit event is kept being reported | |
1288 | from its cached value by linux_nat_stopped_data_address until the real | |
1289 | thread resume happens after the watchpoint gets presented and thus its | |
1290 | LWP_INFO->STATUS gets reset. | |
1291 | ||
1292 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1293 | removal from inferior. */ | |
1294 | ||
b40ce68a | 1295 | static void |
a5606eee | 1296 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1297 | { |
a5606eee | 1298 | int within_current_scope; |
a5606eee | 1299 | struct frame_id saved_frame_id; |
66076460 | 1300 | int frame_saved; |
a5606eee | 1301 | |
f6bc2008 PA |
1302 | /* If this is a local watchpoint, we only want to check if the |
1303 | watchpoint frame is in scope if the current thread is the thread | |
1304 | that was used to create the watchpoint. */ | |
1305 | if (!watchpoint_in_thread_scope (b)) | |
1306 | return; | |
1307 | ||
876fa593 | 1308 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1309 | update_global_locations will eventually delete them and remove |
1310 | breakpoints if needed. */ | |
a5606eee VP |
1311 | b->loc = NULL; |
1312 | ||
1313 | if (b->disposition == disp_del_at_next_stop) | |
1314 | return; | |
1315 | ||
66076460 | 1316 | frame_saved = 0; |
a5606eee VP |
1317 | |
1318 | /* Determine if the watchpoint is within scope. */ | |
1319 | if (b->exp_valid_block == NULL) | |
1320 | within_current_scope = 1; | |
1321 | else | |
1322 | { | |
1323 | struct frame_info *fi; | |
66076460 DJ |
1324 | |
1325 | /* Save the current frame's ID so we can restore it after | |
1326 | evaluating the watchpoint expression on its own frame. */ | |
1327 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1328 | took a frame parameter, so that we didn't have to change the | |
1329 | selected frame. */ | |
1330 | frame_saved = 1; | |
1331 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1332 | ||
a5606eee VP |
1333 | fi = frame_find_by_id (b->watchpoint_frame); |
1334 | within_current_scope = (fi != NULL); | |
1335 | if (within_current_scope) | |
1336 | select_frame (fi); | |
1337 | } | |
1338 | ||
1339 | if (within_current_scope && reparse) | |
1340 | { | |
1341 | char *s; | |
d63d0675 | 1342 | |
a5606eee VP |
1343 | if (b->exp) |
1344 | { | |
1345 | xfree (b->exp); | |
1346 | b->exp = NULL; | |
1347 | } | |
d63d0675 | 1348 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1349 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1350 | /* If the meaning of expression itself changed, the old value is | |
1351 | no longer relevant. We don't want to report a watchpoint hit | |
1352 | to the user when the old value and the new value may actually | |
1353 | be completely different objects. */ | |
1354 | value_free (b->val); | |
fa4727a6 DJ |
1355 | b->val = NULL; |
1356 | b->val_valid = 0; | |
60e1c644 PA |
1357 | |
1358 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1359 | expression is stored in the breakpoint object, not in the | |
1360 | locations (re)created below. */ | |
1361 | if (b->cond_string != NULL) | |
1362 | { | |
1363 | if (b->cond_exp != NULL) | |
1364 | { | |
1365 | xfree (b->cond_exp); | |
1366 | b->cond_exp = NULL; | |
1367 | } | |
1368 | ||
1369 | s = b->cond_string; | |
1370 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1371 | } | |
a5606eee | 1372 | } |
a5606eee VP |
1373 | |
1374 | /* If we failed to parse the expression, for example because | |
1375 | it refers to a global variable in a not-yet-loaded shared library, | |
1376 | don't try to insert watchpoint. We don't automatically delete | |
1377 | such watchpoint, though, since failure to parse expression | |
1378 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1379 | if ( !target_has_execution) |
1380 | { | |
1381 | /* Without execution, memory can't change. No use to try and | |
1382 | set watchpoint locations. The watchpoint will be reset when | |
1383 | the target gains execution, through breakpoint_re_set. */ | |
1384 | } | |
1385 | else if (within_current_scope && b->exp) | |
a5606eee | 1386 | { |
0cf6dd15 | 1387 | int pc = 0; |
fa4727a6 | 1388 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1389 | struct program_space *frame_pspace; |
a5606eee | 1390 | |
0cf6dd15 | 1391 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1392 | |
a5606eee VP |
1393 | /* Avoid setting b->val if it's already set. The meaning of |
1394 | b->val is 'the last value' user saw, and we should update | |
1395 | it only if we reported that last value to user. As it | |
1396 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1397 | if (!b->val_valid) |
1398 | { | |
1399 | b->val = v; | |
1400 | b->val_valid = 1; | |
1401 | } | |
a5606eee | 1402 | |
db2ad4c3 JK |
1403 | /* Change the type of breakpoint between hardware assisted or an |
1404 | ordinary watchpoint depending on the hardware support and free | |
1405 | hardware slots. REPARSE is set when the inferior is started. */ | |
1406 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1407 | && reparse) | |
1408 | { | |
ca2d49e8 | 1409 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1410 | |
7b838ca2 TJB |
1411 | /* We need to determine how many resources are already used |
1412 | for all other hardware watchpoints to see if we still have | |
1413 | enough resources to also fit this watchpoint in as well. | |
1414 | To avoid the hw_watchpoint_used_count call below from counting | |
1415 | this watchpoint, make sure that it is marked as a software | |
1416 | watchpoint. */ | |
1417 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1418 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1419 | &other_type_used); | |
1420 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1421 | ||
ca2d49e8 | 1422 | if (!mem_cnt) |
db2ad4c3 JK |
1423 | b->type = bp_watchpoint; |
1424 | else | |
ca2d49e8 | 1425 | { |
d92524f1 | 1426 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1427 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1428 | if (target_resources_ok <= 0) | |
1429 | b->type = bp_watchpoint; | |
1430 | else | |
1431 | b->type = bp_hardware_watchpoint; | |
1432 | } | |
db2ad4c3 JK |
1433 | } |
1434 | ||
2d134ed3 PA |
1435 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1436 | ||
a5606eee | 1437 | /* Look at each value on the value chain. */ |
fa4727a6 | 1438 | for (v = val_chain; v; v = next) |
a5606eee VP |
1439 | { |
1440 | /* If it's a memory location, and GDB actually needed | |
1441 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1442 | must watch it. If the first value returned is |
1443 | still lazy, that means an error occurred reading it; | |
1444 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1445 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1446 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1447 | { |
1448 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1449 | |
a5606eee VP |
1450 | /* We only watch structs and arrays if user asked |
1451 | for it explicitly, never if they just happen to | |
1452 | appear in the middle of some value chain. */ | |
fa4727a6 | 1453 | if (v == result |
a5606eee VP |
1454 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1455 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1456 | { | |
1457 | CORE_ADDR addr; | |
1458 | int len, type; | |
1459 | struct bp_location *loc, **tmp; | |
1460 | ||
42ae5230 | 1461 | addr = value_address (v); |
a5606eee VP |
1462 | len = TYPE_LENGTH (value_type (v)); |
1463 | type = hw_write; | |
1464 | if (b->type == bp_read_watchpoint) | |
1465 | type = hw_read; | |
1466 | else if (b->type == bp_access_watchpoint) | |
1467 | type = hw_access; | |
1468 | ||
39d61571 | 1469 | loc = allocate_bp_location (b); |
a5606eee VP |
1470 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1471 | ; | |
1472 | *tmp = loc; | |
a6d9a66e | 1473 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1474 | |
1475 | loc->pspace = frame_pspace; | |
a5606eee VP |
1476 | loc->address = addr; |
1477 | loc->length = len; | |
1478 | loc->watchpoint_type = type; | |
1479 | } | |
1480 | } | |
1481 | ||
1482 | next = value_next (v); | |
1483 | if (v != b->val) | |
1484 | value_free (v); | |
1485 | } | |
1486 | ||
c7437ca6 PA |
1487 | /* If a software watchpoint is not watching any memory, then the |
1488 | above left it without any location set up. But, | |
1489 | bpstat_stop_status requires a location to be able to report | |
1490 | stops, so make sure there's at least a dummy one. */ | |
1491 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1492 | { | |
1493 | b->loc = allocate_bp_location (b); | |
1494 | b->loc->pspace = frame_pspace; | |
1495 | b->loc->address = -1; | |
1496 | b->loc->length = -1; | |
1497 | b->loc->watchpoint_type = -1; | |
1498 | } | |
a5606eee VP |
1499 | } |
1500 | else if (!within_current_scope) | |
7270d8f2 | 1501 | { |
a5606eee | 1502 | printf_filtered (_("\ |
cce7e648 | 1503 | Watchpoint %d deleted because the program has left the block\n\ |
a5606eee VP |
1504 | in which its expression is valid.\n"), |
1505 | b->number); | |
1506 | if (b->related_breakpoint) | |
60e1c644 PA |
1507 | { |
1508 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1509 | b->related_breakpoint->related_breakpoint = NULL; | |
1510 | b->related_breakpoint= NULL; | |
1511 | } | |
a5606eee | 1512 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1513 | } |
a5606eee VP |
1514 | |
1515 | /* Restore the selected frame. */ | |
66076460 DJ |
1516 | if (frame_saved) |
1517 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1518 | } |
1519 | ||
a5606eee | 1520 | |
74960c60 VP |
1521 | /* Returns 1 iff breakpoint location should be |
1522 | inserted in the inferior. */ | |
1523 | static int | |
1524 | should_be_inserted (struct bp_location *bpt) | |
1525 | { | |
2bdf28a0 | 1526 | if (bpt->owner == NULL || !breakpoint_enabled (bpt->owner)) |
74960c60 VP |
1527 | return 0; |
1528 | ||
1529 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1530 | return 0; | |
1531 | ||
1532 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1533 | return 0; | |
1534 | ||
56710373 PA |
1535 | /* This is set for example, when we're attached to the parent of a |
1536 | vfork, and have detached from the child. The child is running | |
1537 | free, and we expect it to do an exec or exit, at which point the | |
1538 | OS makes the parent schedulable again (and the target reports | |
1539 | that the vfork is done). Until the child is done with the shared | |
1540 | memory region, do not insert breakpoints in the parent, otherwise | |
1541 | the child could still trip on the parent's breakpoints. Since | |
1542 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1543 | if (bpt->pspace->breakpoints_not_allowed) | |
1544 | return 0; | |
1545 | ||
1042e4c0 SS |
1546 | /* Tracepoints are inserted by the target at a time of its choosing, |
1547 | not by us. */ | |
d77f58be | 1548 | if (is_tracepoint (bpt->owner)) |
1042e4c0 SS |
1549 | return 0; |
1550 | ||
74960c60 VP |
1551 | return 1; |
1552 | } | |
1553 | ||
879bfdc2 DJ |
1554 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1555 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1556 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1557 | |
1558 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1559 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1560 | static int |
879bfdc2 | 1561 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1562 | struct ui_file *tmp_error_stream, |
fa3a767f | 1563 | int *disabled_breaks, |
26bb91f3 | 1564 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1565 | { |
1566 | int val = 0; | |
1567 | ||
74960c60 | 1568 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1569 | return 0; |
1570 | ||
8181d85f DJ |
1571 | /* Initialize the target-specific information. */ |
1572 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1573 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1574 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1575 | |
879bfdc2 DJ |
1576 | if (bpt->loc_type == bp_loc_software_breakpoint |
1577 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1578 | { | |
765dc015 VP |
1579 | if (bpt->owner->type != bp_hardware_breakpoint) |
1580 | { | |
1581 | /* If the explicitly specified breakpoint type | |
1582 | is not hardware breakpoint, check the memory map to see | |
1583 | if the breakpoint address is in read only memory or not. | |
1584 | Two important cases are: | |
1585 | - location type is not hardware breakpoint, memory | |
1586 | is readonly. We change the type of the location to | |
1587 | hardware breakpoint. | |
1588 | - location type is hardware breakpoint, memory is read-write. | |
1589 | This means we've previously made the location hardware one, but | |
1590 | then the memory map changed, so we undo. | |
1591 | ||
1592 | When breakpoints are removed, remove_breakpoints will | |
1593 | use location types we've just set here, the only possible | |
1594 | problem is that memory map has changed during running program, | |
1595 | but it's not going to work anyway with current gdb. */ | |
1596 | struct mem_region *mr | |
1597 | = lookup_mem_region (bpt->target_info.placed_address); | |
1598 | ||
1599 | if (mr) | |
1600 | { | |
1601 | if (automatic_hardware_breakpoints) | |
1602 | { | |
765dc015 VP |
1603 | enum bp_loc_type new_type; |
1604 | ||
1605 | if (mr->attrib.mode != MEM_RW) | |
1606 | new_type = bp_loc_hardware_breakpoint; | |
1607 | else | |
1608 | new_type = bp_loc_software_breakpoint; | |
1609 | ||
1610 | if (new_type != bpt->loc_type) | |
1611 | { | |
1612 | static int said = 0; | |
cc59ec59 | 1613 | |
765dc015 VP |
1614 | bpt->loc_type = new_type; |
1615 | if (!said) | |
1616 | { | |
1617 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1618 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1619 | said = 1; |
1620 | } | |
1621 | } | |
1622 | } | |
1623 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1624 | && mr->attrib.mode != MEM_RW) | |
1625 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1626 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1627 | } |
1628 | } | |
1629 | ||
879bfdc2 DJ |
1630 | /* First check to see if we have to handle an overlay. */ |
1631 | if (overlay_debugging == ovly_off | |
1632 | || bpt->section == NULL | |
1633 | || !(section_is_overlay (bpt->section))) | |
1634 | { | |
1635 | /* No overlay handling: just set the breakpoint. */ | |
1636 | ||
1637 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1638 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1639 | &bpt->target_info); | |
879bfdc2 | 1640 | else |
a6d9a66e UW |
1641 | val = target_insert_breakpoint (bpt->gdbarch, |
1642 | &bpt->target_info); | |
879bfdc2 DJ |
1643 | } |
1644 | else | |
1645 | { | |
1646 | /* This breakpoint is in an overlay section. | |
1647 | Shall we set a breakpoint at the LMA? */ | |
1648 | if (!overlay_events_enabled) | |
1649 | { | |
1650 | /* Yes -- overlay event support is not active, | |
1651 | so we must try to set a breakpoint at the LMA. | |
1652 | This will not work for a hardware breakpoint. */ | |
1653 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1654 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1655 | bpt->owner->number); |
1656 | else | |
1657 | { | |
1658 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1659 | bpt->section); | |
1660 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1661 | bpt->overlay_target_info = bpt->target_info; |
1662 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1663 | val = target_insert_breakpoint (bpt->gdbarch, |
1664 | &bpt->overlay_target_info); | |
879bfdc2 | 1665 | if (val != 0) |
99361f52 DE |
1666 | fprintf_unfiltered (tmp_error_stream, |
1667 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1668 | bpt->owner->number); |
1669 | } | |
1670 | } | |
1671 | /* Shall we set a breakpoint at the VMA? */ | |
1672 | if (section_is_mapped (bpt->section)) | |
1673 | { | |
1674 | /* Yes. This overlay section is mapped into memory. */ | |
1675 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1676 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1677 | &bpt->target_info); | |
879bfdc2 | 1678 | else |
a6d9a66e UW |
1679 | val = target_insert_breakpoint (bpt->gdbarch, |
1680 | &bpt->target_info); | |
879bfdc2 DJ |
1681 | } |
1682 | else | |
1683 | { | |
1684 | /* No. This breakpoint will not be inserted. | |
1685 | No error, but do not mark the bp as 'inserted'. */ | |
1686 | return 0; | |
1687 | } | |
1688 | } | |
1689 | ||
1690 | if (val) | |
1691 | { | |
1692 | /* Can't set the breakpoint. */ | |
6c95b8df | 1693 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1694 | { |
1695 | /* See also: disable_breakpoints_in_shlibs. */ | |
1696 | val = 0; | |
0d381245 | 1697 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1698 | if (!*disabled_breaks) |
1699 | { | |
1700 | fprintf_unfiltered (tmp_error_stream, | |
1701 | "Cannot insert breakpoint %d.\n", | |
1702 | bpt->owner->number); | |
1703 | fprintf_unfiltered (tmp_error_stream, | |
1704 | "Temporarily disabling shared library breakpoints:\n"); | |
1705 | } | |
1706 | *disabled_breaks = 1; | |
1707 | fprintf_unfiltered (tmp_error_stream, | |
1708 | "breakpoint #%d\n", bpt->owner->number); | |
1709 | } | |
1710 | else | |
879bfdc2 | 1711 | { |
879bfdc2 DJ |
1712 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1713 | { | |
1714 | *hw_breakpoint_error = 1; | |
1715 | fprintf_unfiltered (tmp_error_stream, | |
1716 | "Cannot insert hardware breakpoint %d.\n", | |
1717 | bpt->owner->number); | |
1718 | } | |
1719 | else | |
1720 | { | |
1721 | fprintf_unfiltered (tmp_error_stream, | |
1722 | "Cannot insert breakpoint %d.\n", | |
1723 | bpt->owner->number); | |
1724 | fprintf_filtered (tmp_error_stream, | |
1725 | "Error accessing memory address "); | |
5af949e3 UW |
1726 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1727 | tmp_error_stream); | |
879bfdc2 DJ |
1728 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1729 | safe_strerror (val)); | |
1730 | } | |
1731 | ||
1732 | } | |
1733 | } | |
1734 | else | |
1735 | bpt->inserted = 1; | |
1736 | ||
1737 | return val; | |
1738 | } | |
1739 | ||
1740 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1741 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1742 | watchpoints. It's not clear that it's necessary... */ | |
1743 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1744 | { | |
85d721b8 | 1745 | val = target_insert_watchpoint (bpt->address, |
a5606eee | 1746 | bpt->length, |
0cf6dd15 TJB |
1747 | bpt->watchpoint_type, |
1748 | bpt->owner->cond_exp); | |
85d721b8 PA |
1749 | |
1750 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1751 | supported, try emulating one with an access watchpoint. */ | |
1752 | if (val == 1 && bpt->watchpoint_type == hw_read) | |
1753 | { | |
1754 | struct bp_location *loc, **loc_temp; | |
1755 | ||
1756 | /* But don't try to insert it, if there's already another | |
1757 | hw_access location that would be considered a duplicate | |
1758 | of this one. */ | |
1759 | ALL_BP_LOCATIONS (loc, loc_temp) | |
1760 | if (loc != bpt | |
1761 | && loc->watchpoint_type == hw_access | |
1762 | && watchpoint_locations_match (bpt, loc)) | |
1763 | { | |
1764 | bpt->duplicate = 1; | |
1765 | bpt->inserted = 1; | |
1766 | bpt->target_info = loc->target_info; | |
1767 | bpt->watchpoint_type = hw_access; | |
1768 | val = 0; | |
1769 | break; | |
1770 | } | |
1771 | ||
1772 | if (val == 1) | |
1773 | { | |
1774 | val = target_insert_watchpoint (bpt->address, | |
1775 | bpt->length, | |
0cf6dd15 TJB |
1776 | hw_access, |
1777 | bpt->owner->cond_exp); | |
85d721b8 PA |
1778 | if (val == 0) |
1779 | bpt->watchpoint_type = hw_access; | |
1780 | } | |
1781 | } | |
1782 | ||
1783 | bpt->inserted = (val == 0); | |
879bfdc2 DJ |
1784 | } |
1785 | ||
fe798b75 | 1786 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1787 | { |
71fff37b AC |
1788 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1789 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1790 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1791 | bpt->owner->number); | |
1792 | if (e.reason < 0) | |
879bfdc2 DJ |
1793 | bpt->owner->enable_state = bp_disabled; |
1794 | else | |
1795 | bpt->inserted = 1; | |
1640b821 DJ |
1796 | |
1797 | /* We've already printed an error message if there was a problem | |
1798 | inserting this catchpoint, and we've disabled the catchpoint, | |
1799 | so just return success. */ | |
1800 | return 0; | |
879bfdc2 DJ |
1801 | } |
1802 | ||
1803 | return 0; | |
1804 | } | |
1805 | ||
6c95b8df PA |
1806 | /* This function is called when program space PSPACE is about to be |
1807 | deleted. It takes care of updating breakpoints to not reference | |
1808 | PSPACE anymore. */ | |
1809 | ||
1810 | void | |
1811 | breakpoint_program_space_exit (struct program_space *pspace) | |
1812 | { | |
1813 | struct breakpoint *b, *b_temp; | |
876fa593 | 1814 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1815 | |
1816 | /* Remove any breakpoint that was set through this program space. */ | |
1817 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1818 | { | |
1819 | if (b->pspace == pspace) | |
1820 | delete_breakpoint (b); | |
1821 | } | |
1822 | ||
1823 | /* Breakpoints set through other program spaces could have locations | |
1824 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1825 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1826 | { |
1827 | struct bp_location *tmp; | |
1828 | ||
1829 | if (loc->pspace == pspace) | |
1830 | { | |
2bdf28a0 | 1831 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1832 | if (loc->owner->loc == loc) |
1833 | loc->owner->loc = loc->next; | |
1834 | else | |
1835 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1836 | if (tmp->next == loc) | |
1837 | { | |
1838 | tmp->next = loc->next; | |
1839 | break; | |
1840 | } | |
1841 | } | |
1842 | } | |
1843 | ||
1844 | /* Now update the global location list to permanently delete the | |
1845 | removed locations above. */ | |
1846 | update_global_location_list (0); | |
1847 | } | |
1848 | ||
74960c60 VP |
1849 | /* Make sure all breakpoints are inserted in inferior. |
1850 | Throws exception on any error. | |
1851 | A breakpoint that is already inserted won't be inserted | |
1852 | again, so calling this function twice is safe. */ | |
1853 | void | |
1854 | insert_breakpoints (void) | |
1855 | { | |
1856 | struct breakpoint *bpt; | |
1857 | ||
1858 | ALL_BREAKPOINTS (bpt) | |
1859 | if (is_hardware_watchpoint (bpt)) | |
1860 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1861 | ||
b60e7edf | 1862 | update_global_location_list (1); |
74960c60 | 1863 | |
c35b1492 PA |
1864 | /* update_global_location_list does not insert breakpoints when |
1865 | always_inserted_mode is not enabled. Explicitly insert them | |
1866 | now. */ | |
1867 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1868 | insert_breakpoint_locations (); |
1869 | } | |
1870 | ||
c906108c SS |
1871 | /* insert_breakpoints is used when starting or continuing the program. |
1872 | remove_breakpoints is used when the program stops. | |
1873 | Both return zero if successful, | |
1874 | or an `errno' value if could not write the inferior. */ | |
1875 | ||
74960c60 VP |
1876 | static void |
1877 | insert_breakpoint_locations (void) | |
c906108c | 1878 | { |
a5606eee | 1879 | struct breakpoint *bpt; |
876fa593 | 1880 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1881 | int error = 0; |
c906108c SS |
1882 | int val = 0; |
1883 | int disabled_breaks = 0; | |
81d0cc19 | 1884 | int hw_breakpoint_error = 0; |
c906108c | 1885 | |
81d0cc19 | 1886 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1887 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1888 | |
81d0cc19 GS |
1889 | /* Explicitly mark the warning -- this will only be printed if |
1890 | there was an error. */ | |
1891 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1892 | |
1893 | save_current_space_and_thread (); | |
1894 | ||
876fa593 | 1895 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1896 | { |
74960c60 | 1897 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1898 | continue; |
1899 | ||
f365de73 | 1900 | /* There is no point inserting thread-specific breakpoints if the |
2bdf28a0 JK |
1901 | thread no longer exists. ALL_BP_LOCATIONS bp_location has B->OWNER |
1902 | always non-NULL. */ | |
f365de73 AS |
1903 | if (b->owner->thread != -1 |
1904 | && !valid_thread_id (b->owner->thread)) | |
1905 | continue; | |
1906 | ||
6c95b8df PA |
1907 | switch_to_program_space_and_thread (b->pspace); |
1908 | ||
1909 | /* For targets that support global breakpoints, there's no need | |
1910 | to select an inferior to insert breakpoint to. In fact, even | |
1911 | if we aren't attached to any process yet, we should still | |
1912 | insert breakpoints. */ | |
1913 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1914 | && ptid_equal (inferior_ptid, null_ptid)) | |
1915 | continue; | |
1916 | ||
879bfdc2 | 1917 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1918 | &disabled_breaks, |
879bfdc2 DJ |
1919 | &hw_breakpoint_error); |
1920 | if (val) | |
e236ba44 | 1921 | error = val; |
879bfdc2 | 1922 | } |
c906108c | 1923 | |
a5606eee VP |
1924 | /* If we failed to insert all locations of a watchpoint, |
1925 | remove them, as half-inserted watchpoint is of limited use. */ | |
1926 | ALL_BREAKPOINTS (bpt) | |
1927 | { | |
1928 | int some_failed = 0; | |
1929 | struct bp_location *loc; | |
1930 | ||
1931 | if (!is_hardware_watchpoint (bpt)) | |
1932 | continue; | |
1933 | ||
d6b74ac4 | 1934 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1935 | continue; |
74960c60 VP |
1936 | |
1937 | if (bpt->disposition == disp_del_at_next_stop) | |
1938 | continue; | |
a5606eee VP |
1939 | |
1940 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1941 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1942 | { |
1943 | some_failed = 1; | |
1944 | break; | |
1945 | } | |
1946 | if (some_failed) | |
1947 | { | |
1948 | for (loc = bpt->loc; loc; loc = loc->next) | |
1949 | if (loc->inserted) | |
1950 | remove_breakpoint (loc, mark_uninserted); | |
1951 | ||
1952 | hw_breakpoint_error = 1; | |
1953 | fprintf_unfiltered (tmp_error_stream, | |
1954 | "Could not insert hardware watchpoint %d.\n", | |
1955 | bpt->number); | |
1956 | error = -1; | |
1957 | } | |
1958 | } | |
1959 | ||
e236ba44 | 1960 | if (error) |
81d0cc19 GS |
1961 | { |
1962 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1963 | message about possibly exhausted resources. */ | |
879bfdc2 | 1964 | if (hw_breakpoint_error) |
81d0cc19 | 1965 | { |
c6510018 MS |
1966 | fprintf_unfiltered (tmp_error_stream, |
1967 | "Could not insert hardware breakpoints:\n\ | |
1968 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1969 | } |
81d0cc19 GS |
1970 | target_terminal_ours_for_output (); |
1971 | error_stream (tmp_error_stream); | |
1972 | } | |
f7545552 TT |
1973 | |
1974 | do_cleanups (cleanups); | |
c906108c SS |
1975 | } |
1976 | ||
c906108c | 1977 | int |
fba45db2 | 1978 | remove_breakpoints (void) |
c906108c | 1979 | { |
876fa593 | 1980 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1981 | int val = 0; |
c906108c | 1982 | |
876fa593 | 1983 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1984 | { |
0bde7532 | 1985 | if (b->inserted) |
3a1bae8e | 1986 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1987 | } |
3a1bae8e | 1988 | return val; |
c906108c SS |
1989 | } |
1990 | ||
6c95b8df PA |
1991 | /* Remove breakpoints of process PID. */ |
1992 | ||
1993 | int | |
1994 | remove_breakpoints_pid (int pid) | |
1995 | { | |
876fa593 | 1996 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1997 | int val; |
1998 | struct inferior *inf = find_inferior_pid (pid); | |
1999 | ||
876fa593 | 2000 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
2001 | { |
2002 | if (b->pspace != inf->pspace) | |
2003 | continue; | |
2004 | ||
2005 | if (b->inserted) | |
2006 | { | |
2007 | val = remove_breakpoint (b, mark_uninserted); | |
2008 | if (val != 0) | |
2009 | return val; | |
2010 | } | |
2011 | } | |
2012 | return 0; | |
2013 | } | |
2014 | ||
692590c1 | 2015 | int |
80ce1ecb | 2016 | remove_hw_watchpoints (void) |
692590c1 | 2017 | { |
876fa593 | 2018 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2019 | int val = 0; |
692590c1 | 2020 | |
876fa593 | 2021 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 2022 | { |
0bde7532 | 2023 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 2024 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 2025 | } |
3a1bae8e | 2026 | return val; |
692590c1 MS |
2027 | } |
2028 | ||
c906108c | 2029 | int |
fba45db2 | 2030 | reattach_breakpoints (int pid) |
c906108c | 2031 | { |
6c95b8df | 2032 | struct cleanup *old_chain; |
876fa593 | 2033 | struct bp_location *b, **bp_tmp; |
c906108c | 2034 | int val; |
a4954f26 | 2035 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 2036 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2037 | struct inferior *inf; |
2038 | struct thread_info *tp; | |
2039 | ||
2040 | tp = any_live_thread_of_process (pid); | |
2041 | if (tp == NULL) | |
2042 | return 1; | |
2043 | ||
2044 | inf = find_inferior_pid (pid); | |
2045 | old_chain = save_inferior_ptid (); | |
2046 | ||
2047 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2048 | |
2049 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2050 | |
876fa593 | 2051 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2052 | { |
6c95b8df PA |
2053 | if (b->pspace != inf->pspace) |
2054 | continue; | |
2055 | ||
0bde7532 | 2056 | if (b->inserted) |
c5aa993b | 2057 | { |
a4954f26 DJ |
2058 | b->inserted = 0; |
2059 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 2060 | &dummy1, &dummy2); |
c5aa993b JM |
2061 | if (val != 0) |
2062 | { | |
ce696e05 | 2063 | do_cleanups (old_chain); |
c5aa993b JM |
2064 | return val; |
2065 | } | |
2066 | } | |
2067 | } | |
ce696e05 | 2068 | do_cleanups (old_chain); |
c906108c SS |
2069 | return 0; |
2070 | } | |
2071 | ||
e58b0e63 PA |
2072 | static int internal_breakpoint_number = -1; |
2073 | ||
e62c965a | 2074 | static struct breakpoint * |
a6d9a66e UW |
2075 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2076 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2077 | { |
e62c965a PP |
2078 | struct symtab_and_line sal; |
2079 | struct breakpoint *b; | |
2080 | ||
2081 | init_sal (&sal); /* initialize to zeroes */ | |
2082 | ||
2083 | sal.pc = address; | |
2084 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2085 | sal.pspace = current_program_space; |
e62c965a | 2086 | |
a6d9a66e | 2087 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2088 | b->number = internal_breakpoint_number--; |
2089 | b->disposition = disp_donttouch; | |
2090 | ||
2091 | return b; | |
2092 | } | |
2093 | ||
2094 | static void | |
69de3c6a | 2095 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 2096 | { |
69de3c6a | 2097 | struct objfile *objfile; |
e62c965a | 2098 | |
69de3c6a PP |
2099 | ALL_OBJFILES (objfile) |
2100 | { | |
2101 | struct breakpoint *b; | |
2102 | struct minimal_symbol *m; | |
2103 | ||
2104 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2105 | if (m == NULL) | |
2106 | continue; | |
e62c965a | 2107 | |
a6d9a66e UW |
2108 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2109 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
2110 | bp_overlay_event); |
2111 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2112 | |
69de3c6a PP |
2113 | if (overlay_debugging == ovly_auto) |
2114 | { | |
2115 | b->enable_state = bp_enabled; | |
2116 | overlay_events_enabled = 1; | |
2117 | } | |
2118 | else | |
2119 | { | |
2120 | b->enable_state = bp_disabled; | |
2121 | overlay_events_enabled = 0; | |
2122 | } | |
e62c965a PP |
2123 | } |
2124 | update_global_location_list (1); | |
2125 | } | |
2126 | ||
0fd8e87f UW |
2127 | static void |
2128 | create_longjmp_master_breakpoint (char *func_name) | |
2129 | { | |
6c95b8df | 2130 | struct program_space *pspace; |
0fd8e87f | 2131 | struct objfile *objfile; |
6c95b8df PA |
2132 | struct cleanup *old_chain; |
2133 | ||
2134 | old_chain = save_current_program_space (); | |
0fd8e87f | 2135 | |
6c95b8df | 2136 | ALL_PSPACES (pspace) |
0fd8e87f UW |
2137 | ALL_OBJFILES (objfile) |
2138 | { | |
2139 | struct breakpoint *b; | |
2140 | struct minimal_symbol *m; | |
2141 | ||
2142 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
2143 | continue; | |
2144 | ||
6c95b8df PA |
2145 | set_current_program_space (pspace); |
2146 | ||
0fd8e87f UW |
2147 | m = lookup_minimal_symbol_text (func_name, objfile); |
2148 | if (m == NULL) | |
2149 | continue; | |
2150 | ||
a6d9a66e UW |
2151 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2152 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
2153 | bp_longjmp_master); |
2154 | b->addr_string = xstrdup (func_name); | |
2155 | b->enable_state = bp_disabled; | |
2156 | } | |
2157 | update_global_location_list (1); | |
6c95b8df PA |
2158 | |
2159 | do_cleanups (old_chain); | |
0fd8e87f UW |
2160 | } |
2161 | ||
aa7d318d TT |
2162 | /* Create a master std::terminate breakpoint. The actual function |
2163 | looked for is named FUNC_NAME. */ | |
2164 | static void | |
2165 | create_std_terminate_master_breakpoint (const char *func_name) | |
2166 | { | |
2167 | struct program_space *pspace; | |
2168 | struct objfile *objfile; | |
2169 | struct cleanup *old_chain; | |
2170 | ||
2171 | old_chain = save_current_program_space (); | |
2172 | ||
2173 | ALL_PSPACES (pspace) | |
2174 | ALL_OBJFILES (objfile) | |
2175 | { | |
2176 | struct breakpoint *b; | |
2177 | struct minimal_symbol *m; | |
2178 | ||
2179 | set_current_program_space (pspace); | |
2180 | ||
2181 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2182 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2183 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2184 | continue; | |
2185 | ||
2186 | b = create_internal_breakpoint (get_objfile_arch (objfile), | |
2187 | SYMBOL_VALUE_ADDRESS (m), | |
2188 | bp_std_terminate_master); | |
2189 | b->addr_string = xstrdup (func_name); | |
2190 | b->enable_state = bp_disabled; | |
2191 | } | |
2192 | update_global_location_list (1); | |
2193 | ||
2194 | do_cleanups (old_chain); | |
2195 | } | |
2196 | ||
c906108c | 2197 | void |
fba45db2 | 2198 | update_breakpoints_after_exec (void) |
c906108c | 2199 | { |
c5aa993b JM |
2200 | struct breakpoint *b; |
2201 | struct breakpoint *temp; | |
876fa593 | 2202 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2203 | |
25b22b0a PA |
2204 | /* We're about to delete breakpoints from GDB's lists. If the |
2205 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2206 | writing the breakpoints' "shadow contents" back into memory. The | |
2207 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2208 | do that. Instead, the target is responsible from marking | |
2209 | breakpoints out as soon as it detects an exec. We don't do that | |
2210 | here instead, because there may be other attempts to delete | |
2211 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2212 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2213 | if (bploc->pspace == current_program_space) |
2214 | gdb_assert (!bploc->inserted); | |
c906108c SS |
2215 | |
2216 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 2217 | { |
6c95b8df PA |
2218 | if (b->pspace != current_program_space) |
2219 | continue; | |
2220 | ||
c5aa993b JM |
2221 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
2222 | if (b->type == bp_shlib_event) | |
2223 | { | |
2224 | delete_breakpoint (b); | |
2225 | continue; | |
2226 | } | |
c906108c | 2227 | |
4efc6507 DE |
2228 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
2229 | if (b->type == bp_jit_event) | |
2230 | { | |
2231 | delete_breakpoint (b); | |
2232 | continue; | |
2233 | } | |
2234 | ||
1900040c | 2235 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2236 | as must overlay event and longjmp master breakpoints. */ |
2237 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
aa7d318d | 2238 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master) |
c4093a6a JM |
2239 | { |
2240 | delete_breakpoint (b); | |
2241 | continue; | |
2242 | } | |
2243 | ||
c5aa993b JM |
2244 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2245 | if (b->type == bp_step_resume) | |
2246 | { | |
2247 | delete_breakpoint (b); | |
2248 | continue; | |
2249 | } | |
2250 | ||
611c83ae PA |
2251 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2252 | after an exec. */ | |
2253 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
2254 | { | |
2255 | delete_breakpoint (b); | |
2256 | continue; | |
2257 | } | |
2258 | ||
ce78b96d JB |
2259 | if (b->type == bp_catchpoint) |
2260 | { | |
2261 | /* For now, none of the bp_catchpoint breakpoints need to | |
2262 | do anything at this point. In the future, if some of | |
2263 | the catchpoints need to something, we will need to add | |
2264 | a new method, and call this method from here. */ | |
2265 | continue; | |
2266 | } | |
2267 | ||
c5aa993b JM |
2268 | /* bp_finish is a special case. The only way we ought to be able |
2269 | to see one of these when an exec() has happened, is if the user | |
2270 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2271 | carries them to the call-site of the current callee, by setting | |
2272 | a temporary bp there and resuming. But in this case, the finish | |
2273 | will carry them entirely through the vfork & exec. | |
2274 | ||
2275 | We don't want to allow a bp_finish to remain inserted now. But | |
2276 | we can't safely delete it, 'cause finish_command has a handle to | |
2277 | the bp on a bpstat, and will later want to delete it. There's a | |
2278 | chance (and I've seen it happen) that if we delete the bp_finish | |
2279 | here, that its storage will get reused by the time finish_command | |
2280 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2281 | We really must allow finish_command to delete a bp_finish. | |
2282 | ||
53a5351d JM |
2283 | In the absense of a general solution for the "how do we know |
2284 | it's safe to delete something others may have handles to?" | |
2285 | problem, what we'll do here is just uninsert the bp_finish, and | |
2286 | let finish_command delete it. | |
2287 | ||
2288 | (We know the bp_finish is "doomed" in the sense that it's | |
2289 | momentary, and will be deleted as soon as finish_command sees | |
2290 | the inferior stopped. So it doesn't matter that the bp's | |
2291 | address is probably bogus in the new a.out, unlike e.g., the | |
2292 | solib breakpoints.) */ | |
c5aa993b | 2293 | |
c5aa993b JM |
2294 | if (b->type == bp_finish) |
2295 | { | |
2296 | continue; | |
2297 | } | |
2298 | ||
2299 | /* Without a symbolic address, we have little hope of the | |
2300 | pre-exec() address meaning the same thing in the post-exec() | |
2301 | a.out. */ | |
2302 | if (b->addr_string == NULL) | |
2303 | { | |
2304 | delete_breakpoint (b); | |
2305 | continue; | |
2306 | } | |
c5aa993b | 2307 | } |
1900040c | 2308 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 2309 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
2310 | create_longjmp_master_breakpoint ("longjmp"); |
2311 | create_longjmp_master_breakpoint ("_longjmp"); | |
2312 | create_longjmp_master_breakpoint ("siglongjmp"); | |
2313 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 2314 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
2315 | } |
2316 | ||
2317 | int | |
fba45db2 | 2318 | detach_breakpoints (int pid) |
c906108c | 2319 | { |
876fa593 | 2320 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2321 | int val = 0; |
ce696e05 | 2322 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2323 | struct inferior *inf = current_inferior (); |
c5aa993b | 2324 | |
39f77062 | 2325 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2326 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2327 | |
6c95b8df | 2328 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2329 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 2330 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2331 | { |
6c95b8df PA |
2332 | if (b->pspace != inf->pspace) |
2333 | continue; | |
2334 | ||
0bde7532 | 2335 | if (b->inserted) |
6c95b8df | 2336 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2337 | } |
d03285ec UW |
2338 | |
2339 | /* Detach single-step breakpoints as well. */ | |
2340 | detach_single_step_breakpoints (); | |
2341 | ||
ce696e05 | 2342 | do_cleanups (old_chain); |
3a1bae8e | 2343 | return val; |
c906108c SS |
2344 | } |
2345 | ||
6c95b8df PA |
2346 | /* Remove the breakpoint location B from the current address space. |
2347 | Note that this is used to detach breakpoints from a child fork. | |
2348 | When we get here, the child isn't in the inferior list, and neither | |
2349 | do we have objects to represent its address space --- we should | |
2350 | *not* look at b->pspace->aspace here. */ | |
2351 | ||
c906108c | 2352 | static int |
6c95b8df | 2353 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2354 | { |
2355 | int val; | |
c5aa993b | 2356 | |
2bdf28a0 JK |
2357 | /* B is never in moribund_locations by our callers. */ |
2358 | gdb_assert (b->owner != NULL); | |
2359 | ||
0bde7532 | 2360 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2361 | /* Permanent breakpoints cannot be inserted or removed. */ |
2362 | return 0; | |
2363 | ||
74960c60 VP |
2364 | /* The type of none suggests that owner is actually deleted. |
2365 | This should not ever happen. */ | |
2366 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2367 | |
2368 | if (b->loc_type == bp_loc_software_breakpoint | |
2369 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2370 | { |
c02f5703 MS |
2371 | /* "Normal" instruction breakpoint: either the standard |
2372 | trap-instruction bp (bp_breakpoint), or a | |
2373 | bp_hardware_breakpoint. */ | |
2374 | ||
2375 | /* First check to see if we have to handle an overlay. */ | |
2376 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2377 | || b->section == NULL |
2378 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2379 | { |
2380 | /* No overlay handling: just remove the breakpoint. */ | |
2381 | ||
0bde7532 | 2382 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2383 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2384 | else |
a6d9a66e | 2385 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2386 | } |
c906108c SS |
2387 | else |
2388 | { | |
c02f5703 MS |
2389 | /* This breakpoint is in an overlay section. |
2390 | Did we set a breakpoint at the LMA? */ | |
2391 | if (!overlay_events_enabled) | |
2392 | { | |
2393 | /* Yes -- overlay event support is not active, so we | |
2394 | should have set a breakpoint at the LMA. Remove it. | |
2395 | */ | |
c02f5703 MS |
2396 | /* Ignore any failures: if the LMA is in ROM, we will |
2397 | have already warned when we failed to insert it. */ | |
0bde7532 | 2398 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2399 | target_remove_hw_breakpoint (b->gdbarch, |
2400 | &b->overlay_target_info); | |
c02f5703 | 2401 | else |
a6d9a66e UW |
2402 | target_remove_breakpoint (b->gdbarch, |
2403 | &b->overlay_target_info); | |
c02f5703 MS |
2404 | } |
2405 | /* Did we set a breakpoint at the VMA? | |
2406 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2407 | if (b->inserted) |
c906108c | 2408 | { |
c02f5703 MS |
2409 | /* Yes -- remove it. Previously we did not bother to |
2410 | remove the breakpoint if the section had been | |
2411 | unmapped, but let's not rely on that being safe. We | |
2412 | don't know what the overlay manager might do. */ | |
0bde7532 | 2413 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2414 | val = target_remove_hw_breakpoint (b->gdbarch, |
2415 | &b->target_info); | |
aa67235e UW |
2416 | |
2417 | /* However, we should remove *software* breakpoints only | |
2418 | if the section is still mapped, or else we overwrite | |
2419 | wrong code with the saved shadow contents. */ | |
2420 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2421 | val = target_remove_breakpoint (b->gdbarch, |
2422 | &b->target_info); | |
aa67235e UW |
2423 | else |
2424 | val = 0; | |
c906108c | 2425 | } |
c02f5703 MS |
2426 | else |
2427 | { | |
2428 | /* No -- not inserted, so no need to remove. No error. */ | |
2429 | val = 0; | |
2430 | } | |
c906108c | 2431 | } |
879d1e6b UW |
2432 | |
2433 | /* In some cases, we might not be able to remove a breakpoint | |
2434 | in a shared library that has already been removed, but we | |
2435 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2436 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2437 | val = 0; |
2438 | ||
c906108c SS |
2439 | if (val) |
2440 | return val; | |
0bde7532 | 2441 | b->inserted = (is == mark_inserted); |
c906108c | 2442 | } |
a5606eee | 2443 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2444 | { |
0bde7532 | 2445 | b->inserted = (is == mark_inserted); |
0cf6dd15 TJB |
2446 | val = target_remove_watchpoint (b->address, b->length, |
2447 | b->watchpoint_type, b->owner->cond_exp); | |
2e70b7b9 | 2448 | |
c906108c | 2449 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2450 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2451 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2452 | b->owner->number); |
c906108c | 2453 | } |
ce78b96d JB |
2454 | else if (b->owner->type == bp_catchpoint |
2455 | && breakpoint_enabled (b->owner) | |
2456 | && !b->duplicate) | |
2457 | { | |
2458 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2459 | ||
2460 | val = b->owner->ops->remove (b->owner); | |
2461 | if (val) | |
2462 | return val; | |
2463 | b->inserted = (is == mark_inserted); | |
2464 | } | |
c906108c SS |
2465 | |
2466 | return 0; | |
2467 | } | |
2468 | ||
6c95b8df PA |
2469 | static int |
2470 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2471 | { | |
2472 | int ret; | |
2473 | struct cleanup *old_chain; | |
2474 | ||
2bdf28a0 JK |
2475 | /* B is never in moribund_locations by our callers. */ |
2476 | gdb_assert (b->owner != NULL); | |
2477 | ||
6c95b8df PA |
2478 | if (b->owner->enable_state == bp_permanent) |
2479 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2480 | return 0; | |
2481 | ||
2482 | /* The type of none suggests that owner is actually deleted. | |
2483 | This should not ever happen. */ | |
2484 | gdb_assert (b->owner->type != bp_none); | |
2485 | ||
2486 | old_chain = save_current_space_and_thread (); | |
2487 | ||
2488 | switch_to_program_space_and_thread (b->pspace); | |
2489 | ||
2490 | ret = remove_breakpoint_1 (b, is); | |
2491 | ||
2492 | do_cleanups (old_chain); | |
2493 | return ret; | |
2494 | } | |
2495 | ||
c906108c SS |
2496 | /* Clear the "inserted" flag in all breakpoints. */ |
2497 | ||
25b22b0a | 2498 | void |
fba45db2 | 2499 | mark_breakpoints_out (void) |
c906108c | 2500 | { |
876fa593 | 2501 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2502 | |
876fa593 | 2503 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2504 | if (bpt->pspace == current_program_space) |
2505 | bpt->inserted = 0; | |
c906108c SS |
2506 | } |
2507 | ||
53a5351d JM |
2508 | /* Clear the "inserted" flag in all breakpoints and delete any |
2509 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2510 | |
2511 | Plus other such housekeeping that has to be done for breakpoints | |
2512 | between runs. | |
2513 | ||
53a5351d JM |
2514 | Note: this function gets called at the end of a run (by |
2515 | generic_mourn_inferior) and when a run begins (by | |
2516 | init_wait_for_inferior). */ | |
c906108c SS |
2517 | |
2518 | ||
2519 | ||
2520 | void | |
fba45db2 | 2521 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2522 | { |
52f0bd74 | 2523 | struct breakpoint *b, *temp; |
876fa593 | 2524 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2525 | int ix; |
6c95b8df | 2526 | struct program_space *pspace = current_program_space; |
c906108c | 2527 | |
50c71eaf PA |
2528 | /* If breakpoint locations are shared across processes, then there's |
2529 | nothing to do. */ | |
2567c7d9 | 2530 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2531 | return; |
2532 | ||
876fa593 | 2533 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df | 2534 | { |
2bdf28a0 | 2535 | /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */ |
6c95b8df PA |
2536 | if (bpt->pspace == pspace |
2537 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2538 | bpt->inserted = 0; |
6c95b8df | 2539 | } |
075f6582 | 2540 | |
c906108c | 2541 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2542 | { |
6c95b8df PA |
2543 | if (b->loc && b->loc->pspace != pspace) |
2544 | continue; | |
2545 | ||
c5aa993b JM |
2546 | switch (b->type) |
2547 | { | |
2548 | case bp_call_dummy: | |
c906108c | 2549 | |
c5aa993b | 2550 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2551 | cause problems when the inferior is rerun, so we better get |
2552 | rid of it. */ | |
2553 | ||
2554 | case bp_watchpoint_scope: | |
2555 | ||
2556 | /* Also get rid of scope breakpoints. */ | |
2557 | ||
2558 | case bp_shlib_event: | |
2559 | ||
2560 | /* Also remove solib event breakpoints. Their addresses may | |
2561 | have changed since the last time we ran the program. | |
2562 | Actually we may now be debugging against different target; | |
2563 | and so the solib backend that installed this breakpoint may | |
2564 | not be used in by the target. E.g., | |
2565 | ||
2566 | (gdb) file prog-linux | |
2567 | (gdb) run # native linux target | |
2568 | ... | |
2569 | (gdb) kill | |
2570 | (gdb) file prog-win.exe | |
2571 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2572 | */ | |
c906108c | 2573 | |
c5aa993b JM |
2574 | delete_breakpoint (b); |
2575 | break; | |
c906108c | 2576 | |
c5aa993b JM |
2577 | case bp_watchpoint: |
2578 | case bp_hardware_watchpoint: | |
2579 | case bp_read_watchpoint: | |
2580 | case bp_access_watchpoint: | |
c906108c | 2581 | |
c5aa993b JM |
2582 | /* Likewise for watchpoints on local expressions. */ |
2583 | if (b->exp_valid_block != NULL) | |
2584 | delete_breakpoint (b); | |
967af18d | 2585 | else if (context == inf_starting) |
c860120c PM |
2586 | { |
2587 | /* Reset val field to force reread of starting value | |
2588 | in insert_breakpoints. */ | |
2589 | if (b->val) | |
2590 | value_free (b->val); | |
2591 | b->val = NULL; | |
fa4727a6 | 2592 | b->val_valid = 0; |
c860120c | 2593 | } |
c5aa993b JM |
2594 | break; |
2595 | default: | |
c5aa993b JM |
2596 | break; |
2597 | } | |
2598 | } | |
1c5cfe86 PA |
2599 | |
2600 | /* Get rid of the moribund locations. */ | |
2601 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2602 | free_bp_location (bpt); | |
2603 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2604 | } |
2605 | ||
6c95b8df PA |
2606 | /* These functions concern about actual breakpoints inserted in the |
2607 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2608 | we need to hop over the bkpt --- so we check for address space | |
2609 | match, not program space. */ | |
2610 | ||
c2c6d25f JM |
2611 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2612 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2613 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2614 | permanent breakpoint. | |
2615 | - When continuing from a location with an ordinary breakpoint, we | |
2616 | actually single step once before calling insert_breakpoints. | |
2617 | - When continuing from a localion with a permanent breakpoint, we | |
2618 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2619 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2620 | |
c2c6d25f | 2621 | enum breakpoint_here |
6c95b8df | 2622 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2623 | { |
876fa593 | 2624 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2625 | int any_breakpoint_here = 0; |
c906108c | 2626 | |
876fa593 | 2627 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2628 | { |
2629 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2630 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2631 | continue; | |
2632 | ||
2bdf28a0 | 2633 | /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */ |
468d015d | 2634 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2635 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2636 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2637 | aspace, pc)) | |
075f6582 DJ |
2638 | { |
2639 | if (overlay_debugging | |
2640 | && section_is_overlay (bpt->section) | |
2641 | && !section_is_mapped (bpt->section)) | |
2642 | continue; /* unmapped overlay -- can't be a match */ | |
2643 | else if (bpt->owner->enable_state == bp_permanent) | |
2644 | return permanent_breakpoint_here; | |
2645 | else | |
2646 | any_breakpoint_here = 1; | |
2647 | } | |
2648 | } | |
c906108c | 2649 | |
c2c6d25f | 2650 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2651 | } |
2652 | ||
1c5cfe86 PA |
2653 | /* Return true if there's a moribund breakpoint at PC. */ |
2654 | ||
2655 | int | |
6c95b8df | 2656 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2657 | { |
2658 | struct bp_location *loc; | |
2659 | int ix; | |
2660 | ||
2661 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2662 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2663 | aspace, pc)) | |
1c5cfe86 PA |
2664 | return 1; |
2665 | ||
2666 | return 0; | |
2667 | } | |
c2c6d25f | 2668 | |
c36b740a | 2669 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2670 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2671 | This does not check for single-step breakpoints, which are |
2672 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2673 | |
2674 | int | |
6c95b8df | 2675 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2676 | { |
876fa593 | 2677 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2678 | |
876fa593 | 2679 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2680 | { |
075f6582 DJ |
2681 | if (bpt->loc_type != bp_loc_software_breakpoint |
2682 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2683 | continue; | |
2684 | ||
2685 | if (bpt->inserted | |
6c95b8df PA |
2686 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2687 | aspace, pc)) | |
075f6582 DJ |
2688 | { |
2689 | if (overlay_debugging | |
2690 | && section_is_overlay (bpt->section) | |
2691 | && !section_is_mapped (bpt->section)) | |
2692 | continue; /* unmapped overlay -- can't be a match */ | |
2693 | else | |
2694 | return 1; | |
2695 | } | |
c5aa993b | 2696 | } |
c36b740a VP |
2697 | return 0; |
2698 | } | |
2699 | ||
2700 | /* Returns non-zero iff there's either regular breakpoint | |
2701 | or a single step breakpoint inserted at PC. */ | |
2702 | ||
2703 | int | |
6c95b8df | 2704 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2705 | { |
6c95b8df | 2706 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2707 | return 1; |
c906108c | 2708 | |
6c95b8df | 2709 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2710 | return 1; |
2711 | ||
c906108c SS |
2712 | return 0; |
2713 | } | |
2714 | ||
4fa8626c DJ |
2715 | /* This function returns non-zero iff there is a software breakpoint |
2716 | inserted at PC. */ | |
2717 | ||
2718 | int | |
6c95b8df | 2719 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2720 | { |
876fa593 | 2721 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c | 2722 | |
876fa593 | 2723 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2724 | { |
2725 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2726 | continue; | |
2727 | ||
0d381245 | 2728 | if (bpt->inserted |
6c95b8df PA |
2729 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2730 | aspace, pc)) | |
4fa8626c DJ |
2731 | { |
2732 | if (overlay_debugging | |
2733 | && section_is_overlay (bpt->section) | |
2734 | && !section_is_mapped (bpt->section)) | |
2735 | continue; /* unmapped overlay -- can't be a match */ | |
2736 | else | |
2737 | return 1; | |
2738 | } | |
2739 | } | |
2740 | ||
1aafd4da | 2741 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2742 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2743 | return 1; |
2744 | ||
4fa8626c DJ |
2745 | return 0; |
2746 | } | |
2747 | ||
9093389c PA |
2748 | int |
2749 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2750 | CORE_ADDR addr, ULONGEST len) | |
2751 | { | |
2752 | struct breakpoint *bpt; | |
2753 | ||
2754 | ALL_BREAKPOINTS (bpt) | |
2755 | { | |
2756 | struct bp_location *loc; | |
2757 | ||
2758 | if (bpt->type != bp_hardware_watchpoint | |
2759 | && bpt->type != bp_access_watchpoint) | |
2760 | continue; | |
2761 | ||
2762 | if (!breakpoint_enabled (bpt)) | |
2763 | continue; | |
2764 | ||
2765 | for (loc = bpt->loc; loc; loc = loc->next) | |
2766 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2767 | { | |
2768 | CORE_ADDR l, h; | |
2769 | ||
2770 | /* Check for intersection. */ | |
2771 | l = max (loc->address, addr); | |
2772 | h = min (loc->address + loc->length, addr + len); | |
2773 | if (l < h) | |
2774 | return 1; | |
2775 | } | |
2776 | } | |
2777 | return 0; | |
2778 | } | |
2779 | ||
075f6582 DJ |
2780 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2781 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2782 | |
2783 | int | |
6c95b8df PA |
2784 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2785 | ptid_t ptid) | |
c906108c | 2786 | { |
876fa593 | 2787 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2788 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2789 | int thread = -1; |
4a306c9a | 2790 | int task = 0; |
a6f1cd96 | 2791 | |
876fa593 | 2792 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2793 | { |
075f6582 DJ |
2794 | if (bpt->loc_type != bp_loc_software_breakpoint |
2795 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2796 | continue; | |
2797 | ||
2bdf28a0 | 2798 | /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */ |
a6f1cd96 JB |
2799 | if (!breakpoint_enabled (bpt->owner) |
2800 | && bpt->owner->enable_state != bp_permanent) | |
2801 | continue; | |
2802 | ||
6c95b8df PA |
2803 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2804 | aspace, pc)) | |
a6f1cd96 JB |
2805 | continue; |
2806 | ||
2807 | if (bpt->owner->thread != -1) | |
075f6582 | 2808 | { |
a6f1cd96 JB |
2809 | /* This is a thread-specific breakpoint. Check that ptid |
2810 | matches that thread. If thread hasn't been computed yet, | |
2811 | it is now time to do so. */ | |
2812 | if (thread == -1) | |
2813 | thread = pid_to_thread_id (ptid); | |
2814 | if (bpt->owner->thread != thread) | |
2815 | continue; | |
075f6582 | 2816 | } |
a6f1cd96 | 2817 | |
4a306c9a JB |
2818 | if (bpt->owner->task != 0) |
2819 | { | |
2820 | /* This is a task-specific breakpoint. Check that ptid | |
2821 | matches that task. If task hasn't been computed yet, | |
2822 | it is now time to do so. */ | |
2823 | if (task == 0) | |
2824 | task = ada_get_task_number (ptid); | |
2825 | if (bpt->owner->task != task) | |
2826 | continue; | |
2827 | } | |
2828 | ||
a6f1cd96 JB |
2829 | if (overlay_debugging |
2830 | && section_is_overlay (bpt->section) | |
2831 | && !section_is_mapped (bpt->section)) | |
2832 | continue; /* unmapped overlay -- can't be a match */ | |
2833 | ||
2834 | return 1; | |
c5aa993b | 2835 | } |
c906108c SS |
2836 | |
2837 | return 0; | |
2838 | } | |
c906108c | 2839 | \f |
c5aa993b | 2840 | |
c906108c SS |
2841 | /* bpstat stuff. External routines' interfaces are documented |
2842 | in breakpoint.h. */ | |
2843 | ||
2844 | int | |
fba45db2 | 2845 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2846 | { |
533be4dd | 2847 | return (ep->type == bp_catchpoint); |
c906108c SS |
2848 | } |
2849 | ||
198757a8 VP |
2850 | void |
2851 | bpstat_free (bpstat bs) | |
2852 | { | |
2853 | if (bs->old_val != NULL) | |
2854 | value_free (bs->old_val); | |
9add0f1b | 2855 | decref_counted_command_line (&bs->commands); |
198757a8 VP |
2856 | xfree (bs); |
2857 | } | |
2858 | ||
c906108c SS |
2859 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2860 | Also free any storage that is part of a bpstat. */ | |
2861 | ||
2862 | void | |
fba45db2 | 2863 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2864 | { |
2865 | bpstat p; | |
2866 | bpstat q; | |
2867 | ||
2868 | if (bsp == 0) | |
2869 | return; | |
2870 | p = *bsp; | |
2871 | while (p != NULL) | |
2872 | { | |
2873 | q = p->next; | |
198757a8 | 2874 | bpstat_free (p); |
c906108c SS |
2875 | p = q; |
2876 | } | |
2877 | *bsp = NULL; | |
2878 | } | |
2879 | ||
2880 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2881 | is part of the bpstat is copied as well. */ | |
2882 | ||
2883 | bpstat | |
fba45db2 | 2884 | bpstat_copy (bpstat bs) |
c906108c SS |
2885 | { |
2886 | bpstat p = NULL; | |
2887 | bpstat tmp; | |
2888 | bpstat retval = NULL; | |
2889 | ||
2890 | if (bs == NULL) | |
2891 | return bs; | |
2892 | ||
2893 | for (; bs != NULL; bs = bs->next) | |
2894 | { | |
2895 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2896 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 2897 | incref_counted_command_line (tmp->commands); |
31cc81e9 | 2898 | if (bs->old_val != NULL) |
3c3185ac JK |
2899 | { |
2900 | tmp->old_val = value_copy (bs->old_val); | |
2901 | release_value (tmp->old_val); | |
2902 | } | |
31cc81e9 | 2903 | |
c906108c SS |
2904 | if (p == NULL) |
2905 | /* This is the first thing in the chain. */ | |
2906 | retval = tmp; | |
2907 | else | |
2908 | p->next = tmp; | |
2909 | p = tmp; | |
2910 | } | |
2911 | p->next = NULL; | |
2912 | return retval; | |
2913 | } | |
2914 | ||
2915 | /* Find the bpstat associated with this breakpoint */ | |
2916 | ||
2917 | bpstat | |
fba45db2 | 2918 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2919 | { |
c5aa993b JM |
2920 | if (bsp == NULL) |
2921 | return NULL; | |
c906108c | 2922 | |
c5aa993b JM |
2923 | for (; bsp != NULL; bsp = bsp->next) |
2924 | { | |
4f8d1dc6 | 2925 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2926 | return bsp; |
2927 | } | |
c906108c SS |
2928 | return NULL; |
2929 | } | |
2930 | ||
8671a17b | 2931 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2932 | at. *BSP upon return is a bpstat which points to the remaining |
2933 | breakpoints stopped at (but which is not guaranteed to be good for | |
2934 | anything but further calls to bpstat_num). | |
8671a17b PA |
2935 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2936 | Return -1 if stopped at a breakpoint that has been deleted since | |
2937 | we set it. | |
2938 | Return 1 otherwise. */ | |
c906108c SS |
2939 | |
2940 | int | |
8671a17b | 2941 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2942 | { |
2943 | struct breakpoint *b; | |
2944 | ||
2945 | if ((*bsp) == NULL) | |
2946 | return 0; /* No more breakpoint values */ | |
8671a17b | 2947 | |
4f8d1dc6 VP |
2948 | /* We assume we'll never have several bpstats that |
2949 | correspond to a single breakpoint -- otherwise, | |
2950 | this function might return the same number more | |
2951 | than once and this will look ugly. */ | |
2952 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2953 | *bsp = (*bsp)->next; |
2954 | if (b == NULL) | |
2955 | return -1; /* breakpoint that's been deleted since */ | |
2956 | ||
2957 | *num = b->number; /* We have its number */ | |
2958 | return 1; | |
c906108c SS |
2959 | } |
2960 | ||
2961 | /* Modify BS so that the actions will not be performed. */ | |
2962 | ||
2963 | void | |
fba45db2 | 2964 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2965 | { |
2966 | for (; bs != NULL; bs = bs->next) | |
2967 | { | |
9add0f1b | 2968 | decref_counted_command_line (&bs->commands); |
dde2d684 | 2969 | bs->commands_left = NULL; |
c906108c SS |
2970 | if (bs->old_val != NULL) |
2971 | { | |
2972 | value_free (bs->old_val); | |
2973 | bs->old_val = NULL; | |
2974 | } | |
2975 | } | |
2976 | } | |
2977 | ||
f3b1572e PA |
2978 | /* Called when a command is about to proceed the inferior. */ |
2979 | ||
2980 | static void | |
2981 | breakpoint_about_to_proceed (void) | |
2982 | { | |
2983 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2984 | { | |
2985 | struct thread_info *tp = inferior_thread (); | |
2986 | ||
2987 | /* Allow inferior function calls in breakpoint commands to not | |
2988 | interrupt the command list. When the call finishes | |
2989 | successfully, the inferior will be standing at the same | |
2990 | breakpoint as if nothing happened. */ | |
2991 | if (tp->in_infcall) | |
2992 | return; | |
2993 | } | |
2994 | ||
2995 | breakpoint_proceeded = 1; | |
2996 | } | |
2997 | ||
c906108c | 2998 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2999 | static void |
4efb68b1 | 3000 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3001 | { |
3002 | executing_breakpoint_commands = 0; | |
3003 | } | |
3004 | ||
3005 | /* Execute all the commands associated with all the breakpoints at this | |
3006 | location. Any of these commands could cause the process to proceed | |
3007 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 3008 | the global "breakpoint_proceeded" after each command. |
c906108c | 3009 | |
347bddb7 PA |
3010 | Returns true if a breakpoint command resumed the inferior. In that |
3011 | case, it is the caller's responsibility to recall it again with the | |
3012 | bpstat of the current thread. */ | |
3013 | ||
3014 | static int | |
3015 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3016 | { |
3017 | bpstat bs; | |
3018 | struct cleanup *old_chain; | |
347bddb7 | 3019 | int again = 0; |
c906108c SS |
3020 | |
3021 | /* Avoid endless recursion if a `source' command is contained | |
3022 | in bs->commands. */ | |
3023 | if (executing_breakpoint_commands) | |
347bddb7 | 3024 | return 0; |
c906108c SS |
3025 | |
3026 | executing_breakpoint_commands = 1; | |
3027 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3028 | ||
c906108c SS |
3029 | /* This pointer will iterate over the list of bpstat's. */ |
3030 | bs = *bsp; | |
3031 | ||
3032 | breakpoint_proceeded = 0; | |
3033 | for (; bs != NULL; bs = bs->next) | |
3034 | { | |
9add0f1b | 3035 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3036 | struct command_line *cmd; |
3037 | struct cleanup *this_cmd_tree_chain; | |
3038 | ||
3039 | /* Take ownership of the BSP's command tree, if it has one. | |
3040 | ||
3041 | The command tree could legitimately contain commands like | |
3042 | 'step' and 'next', which call clear_proceed_status, which | |
3043 | frees stop_bpstat's command tree. To make sure this doesn't | |
3044 | free the tree we're executing out from under us, we need to | |
3045 | take ownership of the tree ourselves. Since a given bpstat's | |
3046 | commands are only executed once, we don't need to copy it; we | |
3047 | can clear the pointer in the bpstat, and make sure we free | |
3048 | the tree when we're done. */ | |
9add0f1b TT |
3049 | ccmd = bs->commands; |
3050 | bs->commands = NULL; | |
3051 | this_cmd_tree_chain | |
3052 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3053 | cmd = bs->commands_left; | |
3054 | bs->commands_left = NULL; | |
6c50ab1c | 3055 | |
c906108c SS |
3056 | while (cmd != NULL) |
3057 | { | |
3058 | execute_control_command (cmd); | |
3059 | ||
3060 | if (breakpoint_proceeded) | |
3061 | break; | |
3062 | else | |
3063 | cmd = cmd->next; | |
3064 | } | |
6c50ab1c JB |
3065 | |
3066 | /* We can free this command tree now. */ | |
3067 | do_cleanups (this_cmd_tree_chain); | |
3068 | ||
c906108c | 3069 | if (breakpoint_proceeded) |
32c1e744 VP |
3070 | { |
3071 | if (target_can_async_p ()) | |
347bddb7 PA |
3072 | /* If we are in async mode, then the target might be still |
3073 | running, not stopped at any breakpoint, so nothing for | |
3074 | us to do here -- just return to the event loop. */ | |
3075 | ; | |
32c1e744 VP |
3076 | else |
3077 | /* In sync mode, when execute_control_command returns | |
3078 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3079 | Breakpoint commands for that stop were not run, since |
3080 | execute_command does not run breakpoint commands -- | |
3081 | only command_line_handler does, but that one is not | |
3082 | involved in execution of breakpoint commands. So, we | |
3083 | can now execute breakpoint commands. It should be | |
3084 | noted that making execute_command do bpstat actions is | |
3085 | not an option -- in this case we'll have recursive | |
3086 | invocation of bpstat for each breakpoint with a | |
3087 | command, and can easily blow up GDB stack. Instead, we | |
3088 | return true, which will trigger the caller to recall us | |
3089 | with the new stop_bpstat. */ | |
3090 | again = 1; | |
3091 | break; | |
32c1e744 | 3092 | } |
c906108c | 3093 | } |
c2b8ed2c | 3094 | do_cleanups (old_chain); |
347bddb7 PA |
3095 | return again; |
3096 | } | |
3097 | ||
3098 | void | |
3099 | bpstat_do_actions (void) | |
3100 | { | |
3101 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3102 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3103 | && target_has_execution | |
3104 | && !is_exited (inferior_ptid) | |
3105 | && !is_executing (inferior_ptid)) | |
3106 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3107 | and only return when it is stopped at the next breakpoint, we | |
3108 | keep doing breakpoint actions until it returns false to | |
3109 | indicate the inferior was not resumed. */ | |
3110 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
3111 | break; | |
c906108c SS |
3112 | } |
3113 | ||
fa4727a6 DJ |
3114 | /* Print out the (old or new) value associated with a watchpoint. */ |
3115 | ||
3116 | static void | |
3117 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3118 | { | |
3119 | if (val == NULL) | |
3120 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3121 | else | |
79a45b7d TT |
3122 | { |
3123 | struct value_print_options opts; | |
3124 | get_user_print_options (&opts); | |
3125 | value_print (val, stream, &opts); | |
3126 | } | |
fa4727a6 DJ |
3127 | } |
3128 | ||
e514a9d6 | 3129 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3130 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3131 | by having it set different print_it values. |
3132 | ||
3133 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3134 | through the bpstat list of things causing this stop, calling the | |
3135 | print_bp_stop_message function on each one. The behavior of the | |
3136 | print_bp_stop_message function depends on the print_it field of | |
3137 | bpstat. If such field so indicates, call this function here. | |
3138 | ||
3139 | Return values from this routine (ultimately used by bpstat_print() | |
3140 | and normal_stop() to decide what to do): | |
3141 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3142 | don't print anything else. | |
3143 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3144 | that something to be followed by a location. | |
3145 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3146 | that something to be followed by a location. | |
3147 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3148 | analysis. */ | |
c906108c | 3149 | |
917317f4 | 3150 | static enum print_stop_action |
fba45db2 | 3151 | print_it_typical (bpstat bs) |
c906108c | 3152 | { |
f7545552 | 3153 | struct cleanup *old_chain; |
4f8d1dc6 | 3154 | struct breakpoint *b; |
89f9893c | 3155 | const struct bp_location *bl; |
8b93c638 | 3156 | struct ui_stream *stb; |
f7545552 TT |
3157 | int bp_temp = 0; |
3158 | enum print_stop_action result; | |
3159 | ||
c906108c SS |
3160 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3161 | which has since been deleted. */ | |
e514a9d6 | 3162 | if (bs->breakpoint_at == NULL) |
917317f4 | 3163 | return PRINT_UNKNOWN; |
0d381245 | 3164 | bl = bs->breakpoint_at; |
2bdf28a0 JK |
3165 | |
3166 | /* bl->owner can be NULL if it was a momentary breakpoint | |
3167 | which has since been placed into moribund_locations. */ | |
3168 | if (bl->owner == NULL) | |
3169 | return PRINT_UNKNOWN; | |
0d381245 | 3170 | b = bl->owner; |
c906108c | 3171 | |
f7545552 TT |
3172 | stb = ui_out_stream_new (uiout); |
3173 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3174 | ||
4f8d1dc6 | 3175 | switch (b->type) |
c906108c | 3176 | { |
e514a9d6 JM |
3177 | case bp_breakpoint: |
3178 | case bp_hardware_breakpoint: | |
2cec12e5 | 3179 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
3180 | if (bl->address != bl->requested_address) |
3181 | breakpoint_adjustment_warning (bl->requested_address, | |
3182 | bl->address, | |
4f8d1dc6 VP |
3183 | b->number, 1); |
3184 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3185 | if (bp_temp) |
3186 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3187 | else | |
3188 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3189 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3190 | { |
3191 | ui_out_field_string (uiout, "reason", | |
3192 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3193 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3194 | } | |
4f8d1dc6 | 3195 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3196 | ui_out_text (uiout, ", "); |
f7545552 | 3197 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3198 | break; |
3199 | ||
3200 | case bp_shlib_event: | |
917317f4 JM |
3201 | /* Did we stop because the user set the stop_on_solib_events |
3202 | variable? (If so, we report this as a generic, "Stopped due | |
3203 | to shlib event" message.) */ | |
a3f17187 | 3204 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3205 | result = PRINT_NOTHING; |
e514a9d6 JM |
3206 | break; |
3207 | ||
c4093a6a JM |
3208 | case bp_thread_event: |
3209 | /* Not sure how we will get here. | |
3210 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 3211 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3212 | result = PRINT_NOTHING; |
c4093a6a JM |
3213 | break; |
3214 | ||
1900040c MS |
3215 | case bp_overlay_event: |
3216 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 3217 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3218 | result = PRINT_NOTHING; |
1900040c MS |
3219 | break; |
3220 | ||
0fd8e87f UW |
3221 | case bp_longjmp_master: |
3222 | /* These should never be enabled. */ | |
3223 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3224 | result = PRINT_NOTHING; | |
3225 | break; | |
3226 | ||
aa7d318d TT |
3227 | case bp_std_terminate_master: |
3228 | /* These should never be enabled. */ | |
3229 | printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n")); | |
3230 | result = PRINT_NOTHING; | |
3231 | break; | |
3232 | ||
e514a9d6 JM |
3233 | case bp_watchpoint: |
3234 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3235 | annotate_watchpoint (b->number); |
3236 | if (ui_out_is_mi_like_p (uiout)) | |
3237 | ui_out_field_string | |
3238 | (uiout, "reason", | |
3239 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3240 | mention (b); | |
f7545552 | 3241 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3242 | ui_out_text (uiout, "\nOld value = "); |
3243 | watchpoint_value_print (bs->old_val, stb->stream); | |
3244 | ui_out_field_stream (uiout, "old", stb); | |
3245 | ui_out_text (uiout, "\nNew value = "); | |
3246 | watchpoint_value_print (b->val, stb->stream); | |
3247 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3248 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3249 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3250 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3251 | break; |
3252 | ||
3253 | case bp_read_watchpoint: | |
9dc5e2a9 | 3254 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3255 | ui_out_field_string |
3256 | (uiout, "reason", | |
3257 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3258 | mention (b); |
f7545552 | 3259 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3260 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3261 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3262 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3263 | ui_out_text (uiout, "\n"); |
f7545552 | 3264 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3265 | break; |
3266 | ||
3267 | case bp_access_watchpoint: | |
fa4727a6 | 3268 | if (bs->old_val != NULL) |
8b93c638 | 3269 | { |
4f8d1dc6 | 3270 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3271 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3272 | ui_out_field_string |
3273 | (uiout, "reason", | |
3274 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3275 | mention (b); |
f7545552 | 3276 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3277 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3278 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3279 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3280 | ui_out_text (uiout, "\nNew value = "); |
3281 | } | |
3282 | else | |
3283 | { | |
4f8d1dc6 | 3284 | mention (b); |
9dc5e2a9 | 3285 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3286 | ui_out_field_string |
3287 | (uiout, "reason", | |
3288 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3289 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3290 | ui_out_text (uiout, "\nValue = "); |
3291 | } | |
fa4727a6 | 3292 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3293 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3294 | ui_out_text (uiout, "\n"); |
f7545552 | 3295 | result = PRINT_UNKNOWN; |
e514a9d6 | 3296 | break; |
4ce44c66 | 3297 | |
e514a9d6 JM |
3298 | /* Fall through, we don't deal with these types of breakpoints |
3299 | here. */ | |
3300 | ||
11cf8741 | 3301 | case bp_finish: |
9dc5e2a9 | 3302 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3303 | ui_out_field_string |
3304 | (uiout, "reason", | |
3305 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3306 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3307 | break; |
3308 | ||
e514a9d6 | 3309 | case bp_until: |
9dc5e2a9 | 3310 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3311 | ui_out_field_string |
3312 | (uiout, "reason", | |
3313 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3314 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3315 | break; |
3316 | ||
c2d11a7d | 3317 | case bp_none: |
e514a9d6 JM |
3318 | case bp_longjmp: |
3319 | case bp_longjmp_resume: | |
3320 | case bp_step_resume: | |
e514a9d6 JM |
3321 | case bp_watchpoint_scope: |
3322 | case bp_call_dummy: | |
aa7d318d | 3323 | case bp_std_terminate: |
1042e4c0 | 3324 | case bp_tracepoint: |
7a697b8d | 3325 | case bp_fast_tracepoint: |
4efc6507 | 3326 | case bp_jit_event: |
e514a9d6 | 3327 | default: |
f7545552 TT |
3328 | result = PRINT_UNKNOWN; |
3329 | break; | |
e514a9d6 | 3330 | } |
f7545552 TT |
3331 | |
3332 | do_cleanups (old_chain); | |
3333 | return result; | |
e514a9d6 JM |
3334 | } |
3335 | ||
3336 | /* Generic routine for printing messages indicating why we | |
3337 | stopped. The behavior of this function depends on the value | |
3338 | 'print_it' in the bpstat structure. Under some circumstances we | |
3339 | may decide not to print anything here and delegate the task to | |
3340 | normal_stop(). */ | |
3341 | ||
3342 | static enum print_stop_action | |
3343 | print_bp_stop_message (bpstat bs) | |
3344 | { | |
3345 | switch (bs->print_it) | |
3346 | { | |
3347 | case print_it_noop: | |
3348 | /* Nothing should be printed for this bpstat entry. */ | |
3349 | return PRINT_UNKNOWN; | |
3350 | break; | |
3351 | ||
3352 | case print_it_done: | |
3353 | /* We still want to print the frame, but we already printed the | |
3354 | relevant messages. */ | |
3355 | return PRINT_SRC_AND_LOC; | |
3356 | break; | |
3357 | ||
3358 | case print_it_normal: | |
4f8d1dc6 | 3359 | { |
89f9893c | 3360 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3361 | struct breakpoint *b = bl ? bl->owner : NULL; |
3362 | ||
3363 | /* Normal case. Call the breakpoint's print_it method, or | |
3364 | print_it_typical. */ | |
3365 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3366 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3367 | return b->ops->print_it (b); | |
3368 | else | |
3369 | return print_it_typical (bs); | |
3370 | } | |
3371 | break; | |
3086aeae | 3372 | |
e514a9d6 | 3373 | default: |
8e65ff28 | 3374 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3375 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3376 | break; |
c906108c | 3377 | } |
c906108c SS |
3378 | } |
3379 | ||
e514a9d6 JM |
3380 | /* Print a message indicating what happened. This is called from |
3381 | normal_stop(). The input to this routine is the head of the bpstat | |
3382 | list - a list of the eventpoints that caused this stop. This | |
3383 | routine calls the generic print routine for printing a message | |
3384 | about reasons for stopping. This will print (for example) the | |
3385 | "Breakpoint n," part of the output. The return value of this | |
3386 | routine is one of: | |
c906108c | 3387 | |
917317f4 JM |
3388 | PRINT_UNKNOWN: Means we printed nothing |
3389 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3390 | code to print the location. An example is |
3391 | "Breakpoint 1, " which should be followed by | |
3392 | the location. | |
917317f4 | 3393 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3394 | to also print the location part of the message. |
3395 | An example is the catch/throw messages, which | |
917317f4 JM |
3396 | don't require a location appended to the end. |
3397 | PRINT_NOTHING: We have done some printing and we don't need any | |
3398 | further info to be printed.*/ | |
c906108c | 3399 | |
917317f4 | 3400 | enum print_stop_action |
fba45db2 | 3401 | bpstat_print (bpstat bs) |
c906108c SS |
3402 | { |
3403 | int val; | |
c5aa993b | 3404 | |
c906108c | 3405 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3406 | (Currently all watchpoints go on the bpstat whether hit or not. |
3407 | That probably could (should) be changed, provided care is taken | |
c906108c | 3408 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3409 | for (; bs; bs = bs->next) |
3410 | { | |
3411 | val = print_bp_stop_message (bs); | |
3412 | if (val == PRINT_SRC_ONLY | |
3413 | || val == PRINT_SRC_AND_LOC | |
3414 | || val == PRINT_NOTHING) | |
3415 | return val; | |
3416 | } | |
c906108c | 3417 | |
e514a9d6 JM |
3418 | /* We reached the end of the chain, or we got a null BS to start |
3419 | with and nothing was printed. */ | |
917317f4 | 3420 | return PRINT_UNKNOWN; |
c906108c SS |
3421 | } |
3422 | ||
3423 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3424 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3425 | The argument is a "struct expression *" that has been cast to char * to | |
3426 | make it pass through catch_errors. */ | |
3427 | ||
3428 | static int | |
4efb68b1 | 3429 | breakpoint_cond_eval (void *exp) |
c906108c | 3430 | { |
278cd55f | 3431 | struct value *mark = value_mark (); |
c5aa993b | 3432 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3433 | |
c906108c SS |
3434 | value_free_to_mark (mark); |
3435 | return i; | |
3436 | } | |
3437 | ||
3438 | /* Allocate a new bpstat and chain it to the current one. */ | |
3439 | ||
3440 | static bpstat | |
89f9893c | 3441 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3442 | { |
3443 | bpstat bs; | |
3444 | ||
3445 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3446 | cbs->next = bs; | |
4f8d1dc6 | 3447 | bs->breakpoint_at = bl; |
c906108c SS |
3448 | /* If the condition is false, etc., don't do the commands. */ |
3449 | bs->commands = NULL; | |
9add0f1b | 3450 | bs->commands_left = NULL; |
c906108c SS |
3451 | bs->old_val = NULL; |
3452 | bs->print_it = print_it_normal; | |
3453 | return bs; | |
3454 | } | |
3455 | \f | |
d983da9c DJ |
3456 | /* The target has stopped with waitstatus WS. Check if any hardware |
3457 | watchpoints have triggered, according to the target. */ | |
3458 | ||
3459 | int | |
3460 | watchpoints_triggered (struct target_waitstatus *ws) | |
3461 | { | |
d92524f1 | 3462 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3463 | CORE_ADDR addr; |
3464 | struct breakpoint *b; | |
3465 | ||
3466 | if (!stopped_by_watchpoint) | |
3467 | { | |
3468 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3469 | as not triggered. */ | |
3470 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3471 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3472 | b->watchpoint_triggered = watch_triggered_no; |
3473 | ||
3474 | return 0; | |
3475 | } | |
3476 | ||
3477 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3478 | { | |
3479 | /* We were stopped by a watchpoint, but we don't know where. | |
3480 | Mark all watchpoints as unknown. */ | |
3481 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3482 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3483 | b->watchpoint_triggered = watch_triggered_unknown; |
3484 | ||
3485 | return stopped_by_watchpoint; | |
3486 | } | |
3487 | ||
3488 | /* The target could report the data address. Mark watchpoints | |
3489 | affected by this data address as triggered, and all others as not | |
3490 | triggered. */ | |
3491 | ||
3492 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3493 | if (is_hardware_watchpoint (b)) |
d983da9c | 3494 | { |
a5606eee | 3495 | struct bp_location *loc; |
d983da9c DJ |
3496 | |
3497 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3498 | for (loc = b->loc; loc; loc = loc->next) |
3499 | /* Exact match not required. Within range is | |
3500 | sufficient. */ | |
5009afc5 AS |
3501 | if (target_watchpoint_addr_within_range (¤t_target, |
3502 | addr, loc->address, | |
3503 | loc->length)) | |
a5606eee VP |
3504 | { |
3505 | b->watchpoint_triggered = watch_triggered_yes; | |
3506 | break; | |
3507 | } | |
d983da9c DJ |
3508 | } |
3509 | ||
3510 | return 1; | |
3511 | } | |
3512 | ||
c906108c SS |
3513 | /* Possible return values for watchpoint_check (this can't be an enum |
3514 | because of check_errors). */ | |
3515 | /* The watchpoint has been deleted. */ | |
3516 | #define WP_DELETED 1 | |
3517 | /* The value has changed. */ | |
3518 | #define WP_VALUE_CHANGED 2 | |
3519 | /* The value has not changed. */ | |
3520 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3521 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3522 | #define WP_IGNORE 4 | |
c906108c SS |
3523 | |
3524 | #define BP_TEMPFLAG 1 | |
3525 | #define BP_HARDWAREFLAG 2 | |
3526 | ||
553e4c11 JB |
3527 | /* Evaluate watchpoint condition expression and check if its value changed. |
3528 | ||
3529 | P should be a pointer to struct bpstat, but is defined as a void * | |
3530 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3531 | |
3532 | static int | |
4efb68b1 | 3533 | watchpoint_check (void *p) |
c906108c SS |
3534 | { |
3535 | bpstat bs = (bpstat) p; | |
3536 | struct breakpoint *b; | |
3537 | struct frame_info *fr; | |
3538 | int within_current_scope; | |
3539 | ||
2bdf28a0 JK |
3540 | /* BS is built for existing struct breakpoint. */ |
3541 | gdb_assert (bs->breakpoint_at != NULL); | |
3542 | gdb_assert (bs->breakpoint_at->owner != NULL); | |
4f8d1dc6 | 3543 | b = bs->breakpoint_at->owner; |
c906108c | 3544 | |
f6bc2008 PA |
3545 | /* If this is a local watchpoint, we only want to check if the |
3546 | watchpoint frame is in scope if the current thread is the thread | |
3547 | that was used to create the watchpoint. */ | |
3548 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3549 | return WP_IGNORE; |
f6bc2008 | 3550 | |
c906108c SS |
3551 | if (b->exp_valid_block == NULL) |
3552 | within_current_scope = 1; | |
3553 | else | |
3554 | { | |
edb3359d DJ |
3555 | struct frame_info *frame = get_current_frame (); |
3556 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3557 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3558 | ||
a0f49112 JK |
3559 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3560 | in the function but the stack frame has already been invalidated. | |
3561 | Since we can't rely on the values of local variables after the | |
3562 | stack has been destroyed, we are treating the watchpoint in that | |
3563 | state as `not changed' without further checking. Don't mark | |
3564 | watchpoints as changed if the current frame is in an epilogue - | |
3565 | even if they are in some other frame, our view of the stack | |
3566 | is likely to be wrong and frame_find_by_id could error out. */ | |
3567 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
60e1c644 | 3568 | return WP_IGNORE; |
a0f49112 | 3569 | |
101dcfbe | 3570 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3571 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3572 | |
3573 | /* If we've gotten confused in the unwinder, we might have | |
3574 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3575 | if (within_current_scope) |
3576 | { | |
3577 | struct symbol *function; | |
3578 | ||
3579 | function = get_frame_function (fr); | |
3580 | if (function == NULL | |
3581 | || !contained_in (b->exp_valid_block, | |
3582 | SYMBOL_BLOCK_VALUE (function))) | |
3583 | within_current_scope = 0; | |
3584 | } | |
69fbadd5 | 3585 | |
edb3359d | 3586 | if (within_current_scope) |
c906108c SS |
3587 | /* If we end up stopping, the current frame will get selected |
3588 | in normal_stop. So this call to select_frame won't affect | |
3589 | the user. */ | |
0f7d239c | 3590 | select_frame (fr); |
c906108c | 3591 | } |
c5aa993b | 3592 | |
c906108c SS |
3593 | if (within_current_scope) |
3594 | { | |
3595 | /* We use value_{,free_to_}mark because it could be a | |
3596 | *long* time before we return to the command level and | |
c5aa993b JM |
3597 | call free_all_values. We can't call free_all_values because |
3598 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3599 | |
0cf6dd15 | 3600 | int pc = 0; |
278cd55f | 3601 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3602 | struct value *new_val; |
3603 | ||
0cf6dd15 | 3604 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 TJB |
3605 | |
3606 | /* We use value_equal_contents instead of value_equal because the latter | |
3607 | coerces an array to a pointer, thus comparing just the address of the | |
3608 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3609 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3610 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3611 | { |
fa4727a6 DJ |
3612 | if (new_val != NULL) |
3613 | { | |
3614 | release_value (new_val); | |
3615 | value_free_to_mark (mark); | |
3616 | } | |
c906108c SS |
3617 | bs->old_val = b->val; |
3618 | b->val = new_val; | |
fa4727a6 | 3619 | b->val_valid = 1; |
c906108c SS |
3620 | return WP_VALUE_CHANGED; |
3621 | } | |
3622 | else | |
3623 | { | |
60e1c644 | 3624 | /* Nothing changed. */ |
c906108c | 3625 | value_free_to_mark (mark); |
c906108c SS |
3626 | return WP_VALUE_NOT_CHANGED; |
3627 | } | |
3628 | } | |
3629 | else | |
3630 | { | |
3631 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3632 | if we temporarily ignored the watchpoint, then when |
3633 | we reenter the block in which it is valid it contains | |
3634 | garbage (in the case of a function, it may have two | |
3635 | garbage values, one before and one after the prologue). | |
3636 | So we can't even detect the first assignment to it and | |
3637 | watch after that (since the garbage may or may not equal | |
3638 | the first value assigned). */ | |
4ce44c66 JM |
3639 | /* We print all the stop information in print_it_typical(), but |
3640 | in this case, by the time we call print_it_typical() this bp | |
3641 | will be deleted already. So we have no choice but print the | |
3642 | information here. */ | |
9dc5e2a9 | 3643 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3644 | ui_out_field_string |
3645 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3646 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3647 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3648 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3649 | which its expression is valid.\n"); | |
4ce44c66 | 3650 | |
c906108c | 3651 | if (b->related_breakpoint) |
60e1c644 PA |
3652 | { |
3653 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3654 | b->related_breakpoint->related_breakpoint = NULL; | |
3655 | b->related_breakpoint = NULL; | |
3656 | } | |
b5de0fa7 | 3657 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3658 | |
3659 | return WP_DELETED; | |
3660 | } | |
3661 | } | |
3662 | ||
18a18393 VP |
3663 | /* Return true if it looks like target has stopped due to hitting |
3664 | breakpoint location BL. This function does not check if we | |
3665 | should stop, only if BL explains the stop. */ | |
3666 | static int | |
6c95b8df PA |
3667 | bpstat_check_location (const struct bp_location *bl, |
3668 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3669 | { |
3670 | struct breakpoint *b = bl->owner; | |
3671 | ||
2bdf28a0 JK |
3672 | /* BL is from existing struct breakpoint. */ |
3673 | gdb_assert (b != NULL); | |
3674 | ||
e8595ef6 SS |
3675 | /* By definition, the inferior does not report stops at |
3676 | tracepoints. */ | |
d77f58be | 3677 | if (is_tracepoint (b)) |
e8595ef6 SS |
3678 | return 0; |
3679 | ||
cc60f2e3 | 3680 | if (!is_watchpoint (b) |
18a18393 | 3681 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3682 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3683 | { |
6c95b8df PA |
3684 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3685 | aspace, bp_addr)) | |
18a18393 VP |
3686 | return 0; |
3687 | if (overlay_debugging /* unmapped overlay section */ | |
3688 | && section_is_overlay (bl->section) | |
3689 | && !section_is_mapped (bl->section)) | |
3690 | return 0; | |
3691 | } | |
cc60f2e3 | 3692 | |
18a18393 VP |
3693 | /* Continuable hardware watchpoints are treated as non-existent if the |
3694 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3695 | some data address). Otherwise gdb won't stop on a break instruction | |
3696 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3697 | been defined. Also skip watchpoints which we know did not trigger | |
3698 | (did not match the data address). */ | |
cc60f2e3 PA |
3699 | |
3700 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3701 | && b->watchpoint_triggered == watch_triggered_no) |
3702 | return 0; | |
3703 | ||
3704 | if (b->type == bp_hardware_breakpoint) | |
3705 | { | |
3706 | if (bl->address != bp_addr) | |
3707 | return 0; | |
3708 | if (overlay_debugging /* unmapped overlay section */ | |
3709 | && section_is_overlay (bl->section) | |
3710 | && !section_is_mapped (bl->section)) | |
3711 | return 0; | |
3712 | } | |
ce78b96d | 3713 | |
ce78b96d JB |
3714 | if (b->type == bp_catchpoint) |
3715 | { | |
3716 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3717 | if (!b->ops->breakpoint_hit (b)) | |
3718 | return 0; | |
3719 | } | |
3720 | ||
18a18393 VP |
3721 | return 1; |
3722 | } | |
3723 | ||
3724 | /* If BS refers to a watchpoint, determine if the watched values | |
3725 | has actually changed, and we should stop. If not, set BS->stop | |
3726 | to 0. */ | |
3727 | static void | |
3728 | bpstat_check_watchpoint (bpstat bs) | |
3729 | { | |
2bdf28a0 JK |
3730 | const struct bp_location *bl; |
3731 | struct breakpoint *b; | |
3732 | ||
3733 | /* BS is built for existing struct breakpoint. */ | |
3734 | bl = bs->breakpoint_at; | |
3735 | gdb_assert (bl != NULL); | |
3736 | b = bl->owner; | |
3737 | gdb_assert (b != NULL); | |
18a18393 | 3738 | |
cc60f2e3 | 3739 | if (is_watchpoint (b)) |
18a18393 | 3740 | { |
18a18393 VP |
3741 | int must_check_value = 0; |
3742 | ||
3743 | if (b->type == bp_watchpoint) | |
3744 | /* For a software watchpoint, we must always check the | |
3745 | watched value. */ | |
3746 | must_check_value = 1; | |
3747 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3748 | /* We have a hardware watchpoint (read, write, or access) | |
3749 | and the target earlier reported an address watched by | |
3750 | this watchpoint. */ | |
3751 | must_check_value = 1; | |
3752 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3753 | && b->type == bp_hardware_watchpoint) | |
3754 | /* We were stopped by a hardware watchpoint, but the target could | |
3755 | not report the data address. We must check the watchpoint's | |
3756 | value. Access and read watchpoints are out of luck; without | |
3757 | a data address, we can't figure it out. */ | |
3758 | must_check_value = 1; | |
3759 | ||
3760 | if (must_check_value) | |
3761 | { | |
3762 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3763 | b->number); | |
3764 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3765 | int e = catch_errors (watchpoint_check, bs, message, | |
3766 | RETURN_MASK_ALL); | |
3767 | do_cleanups (cleanups); | |
3768 | switch (e) | |
3769 | { | |
3770 | case WP_DELETED: | |
3771 | /* We've already printed what needs to be printed. */ | |
3772 | bs->print_it = print_it_done; | |
3773 | /* Stop. */ | |
3774 | break; | |
60e1c644 PA |
3775 | case WP_IGNORE: |
3776 | bs->print_it = print_it_noop; | |
3777 | bs->stop = 0; | |
3778 | break; | |
18a18393 VP |
3779 | case WP_VALUE_CHANGED: |
3780 | if (b->type == bp_read_watchpoint) | |
3781 | { | |
85d721b8 PA |
3782 | /* There are two cases to consider here: |
3783 | ||
3784 | 1. we're watching the triggered memory for reads. | |
3785 | In that case, trust the target, and always report | |
3786 | the watchpoint hit to the user. Even though | |
3787 | reads don't cause value changes, the value may | |
3788 | have changed since the last time it was read, and | |
3789 | since we're not trapping writes, we will not see | |
3790 | those, and as such we should ignore our notion of | |
3791 | old value. | |
3792 | ||
3793 | 2. we're watching the triggered memory for both | |
3794 | reads and writes. There are two ways this may | |
3795 | happen: | |
3796 | ||
3797 | 2.1. this is a target that can't break on data | |
3798 | reads only, but can break on accesses (reads or | |
3799 | writes), such as e.g., x86. We detect this case | |
3800 | at the time we try to insert read watchpoints. | |
3801 | ||
3802 | 2.2. otherwise, the target supports read | |
3803 | watchpoints, but, the user set an access or write | |
3804 | watchpoint watching the same memory as this read | |
3805 | watchpoint. | |
3806 | ||
3807 | If we're watching memory writes as well as reads, | |
3808 | ignore watchpoint hits when we find that the | |
3809 | value hasn't changed, as reads don't cause | |
3810 | changes. This still gives false positives when | |
3811 | the program writes the same value to memory as | |
3812 | what there was already in memory (we will confuse | |
3813 | it for a read), but it's much better than | |
3814 | nothing. */ | |
3815 | ||
3816 | int other_write_watchpoint = 0; | |
3817 | ||
3818 | if (bl->watchpoint_type == hw_read) | |
3819 | { | |
3820 | struct breakpoint *other_b; | |
3821 | ||
3822 | ALL_BREAKPOINTS (other_b) | |
3823 | if ((other_b->type == bp_hardware_watchpoint | |
3824 | || other_b->type == bp_access_watchpoint) | |
3825 | && (other_b->watchpoint_triggered | |
3826 | == watch_triggered_yes)) | |
3827 | { | |
3828 | other_write_watchpoint = 1; | |
3829 | break; | |
3830 | } | |
3831 | } | |
3832 | ||
3833 | if (other_write_watchpoint | |
3834 | || bl->watchpoint_type == hw_access) | |
3835 | { | |
3836 | /* We're watching the same memory for writes, | |
3837 | and the value changed since the last time we | |
3838 | updated it, so this trap must be for a write. | |
3839 | Ignore it. */ | |
3840 | bs->print_it = print_it_noop; | |
3841 | bs->stop = 0; | |
3842 | } | |
18a18393 VP |
3843 | } |
3844 | break; | |
3845 | case WP_VALUE_NOT_CHANGED: | |
3846 | if (b->type == bp_hardware_watchpoint | |
3847 | || b->type == bp_watchpoint) | |
3848 | { | |
3849 | /* Don't stop: write watchpoints shouldn't fire if | |
3850 | the value hasn't changed. */ | |
3851 | bs->print_it = print_it_noop; | |
3852 | bs->stop = 0; | |
3853 | } | |
3854 | /* Stop. */ | |
3855 | break; | |
3856 | default: | |
3857 | /* Can't happen. */ | |
3858 | case 0: | |
3859 | /* Error from catch_errors. */ | |
3860 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3861 | if (b->related_breakpoint) | |
3862 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3863 | b->disposition = disp_del_at_next_stop; | |
3864 | /* We've already printed what needs to be printed. */ | |
3865 | bs->print_it = print_it_done; | |
3866 | break; | |
3867 | } | |
3868 | } | |
3869 | else /* must_check_value == 0 */ | |
3870 | { | |
3871 | /* This is a case where some watchpoint(s) triggered, but | |
3872 | not at the address of this watchpoint, or else no | |
3873 | watchpoint triggered after all. So don't print | |
3874 | anything for this watchpoint. */ | |
3875 | bs->print_it = print_it_noop; | |
3876 | bs->stop = 0; | |
3877 | } | |
3878 | } | |
3879 | } | |
3880 | ||
3881 | ||
3882 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3883 | of breakpoint referred to by BS. If we should not stop for this | |
3884 | breakpoint, set BS->stop to 0. */ | |
3885 | static void | |
3886 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3887 | { | |
3888 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
3889 | const struct bp_location *bl; |
3890 | struct breakpoint *b; | |
3891 | ||
3892 | /* BS is built for existing struct breakpoint. */ | |
3893 | bl = bs->breakpoint_at; | |
3894 | gdb_assert (bl != NULL); | |
3895 | b = bl->owner; | |
3896 | gdb_assert (b != NULL); | |
18a18393 VP |
3897 | |
3898 | if (frame_id_p (b->frame_id) | |
edb3359d | 3899 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3900 | bs->stop = 0; |
3901 | else if (bs->stop) | |
3902 | { | |
3903 | int value_is_zero = 0; | |
60e1c644 PA |
3904 | struct expression *cond; |
3905 | ||
18a18393 VP |
3906 | /* If this is a scope breakpoint, mark the associated |
3907 | watchpoint as triggered so that we will handle the | |
3908 | out-of-scope event. We'll get to the watchpoint next | |
3909 | iteration. */ | |
3910 | if (b->type == bp_watchpoint_scope) | |
3911 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
60e1c644 PA |
3912 | |
3913 | if (is_watchpoint (b)) | |
3914 | cond = b->cond_exp; | |
3915 | else | |
3916 | cond = bl->cond; | |
3917 | ||
3918 | if (cond && bl->owner->disposition != disp_del_at_next_stop) | |
18a18393 | 3919 | { |
60e1c644 PA |
3920 | int within_current_scope = 1; |
3921 | ||
c5bc3a77 DJ |
3922 | /* We use value_mark and value_free_to_mark because it could |
3923 | be a long time before we return to the command level and | |
3924 | call free_all_values. We can't call free_all_values | |
3925 | because we might be in the middle of evaluating a | |
3926 | function call. */ | |
3927 | struct value *mark = value_mark (); | |
3928 | ||
edb3359d DJ |
3929 | /* Need to select the frame, with all that implies so that |
3930 | the conditions will have the right context. Because we | |
3931 | use the frame, we will not see an inlined function's | |
3932 | variables when we arrive at a breakpoint at the start | |
3933 | of the inlined function; the current frame will be the | |
3934 | call site. */ | |
60e1c644 PA |
3935 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
3936 | select_frame (get_current_frame ()); | |
3937 | else | |
3938 | { | |
3939 | struct frame_info *frame; | |
3940 | ||
3941 | /* For local watchpoint expressions, which particular | |
3942 | instance of a local is being watched matters, so we | |
3943 | keep track of the frame to evaluate the expression | |
3944 | in. To evaluate the condition however, it doesn't | |
3945 | really matter which instantiation of the function | |
3946 | where the condition makes sense triggers the | |
3947 | watchpoint. This allows an expression like "watch | |
3948 | global if q > 10" set in `func', catch writes to | |
3949 | global on all threads that call `func', or catch | |
3950 | writes on all recursive calls of `func' by a single | |
3951 | thread. We simply always evaluate the condition in | |
3952 | the innermost frame that's executing where it makes | |
3953 | sense to evaluate the condition. It seems | |
3954 | intuitive. */ | |
3955 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
3956 | if (frame != NULL) | |
3957 | select_frame (frame); | |
3958 | else | |
3959 | within_current_scope = 0; | |
3960 | } | |
3961 | if (within_current_scope) | |
3962 | value_is_zero | |
3963 | = catch_errors (breakpoint_cond_eval, cond, | |
3964 | "Error in testing breakpoint condition:\n", | |
3965 | RETURN_MASK_ALL); | |
3966 | else | |
3967 | { | |
3968 | warning (_("Watchpoint condition cannot be tested " | |
3969 | "in the current scope")); | |
3970 | /* If we failed to set the right context for this | |
3971 | watchpoint, unconditionally report it. */ | |
3972 | value_is_zero = 0; | |
3973 | } | |
18a18393 | 3974 | /* FIXME-someday, should give breakpoint # */ |
c5bc3a77 | 3975 | value_free_to_mark (mark); |
18a18393 | 3976 | } |
60e1c644 PA |
3977 | |
3978 | if (cond && value_is_zero) | |
18a18393 VP |
3979 | { |
3980 | bs->stop = 0; | |
3981 | } | |
3982 | else if (b->thread != -1 && b->thread != thread_id) | |
3983 | { | |
3984 | bs->stop = 0; | |
3985 | } | |
3986 | else if (b->ignore_count > 0) | |
3987 | { | |
3988 | b->ignore_count--; | |
3989 | annotate_ignore_count_change (); | |
3990 | bs->stop = 0; | |
3991 | /* Increase the hit count even though we don't | |
3992 | stop. */ | |
3993 | ++(b->hit_count); | |
3994 | } | |
3995 | } | |
3996 | } | |
3997 | ||
3998 | ||
9709f61c | 3999 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4000 | BP_ADDR in thread PTID. |
c906108c | 4001 | |
d983da9c | 4002 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
4003 | don't understand this stop. Result is a chain of bpstat's such that: |
4004 | ||
c5aa993b | 4005 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4006 | |
c5aa993b | 4007 | if we understand why we stopped, the result is not null. |
c906108c | 4008 | |
c5aa993b JM |
4009 | Each element of the chain refers to a particular breakpoint or |
4010 | watchpoint at which we have stopped. (We may have stopped for | |
4011 | several reasons concurrently.) | |
c906108c | 4012 | |
c5aa993b JM |
4013 | Each element of the chain has valid next, breakpoint_at, |
4014 | commands, FIXME??? fields. */ | |
c906108c SS |
4015 | |
4016 | bpstat | |
6c95b8df PA |
4017 | bpstat_stop_status (struct address_space *aspace, |
4018 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4019 | { |
0d381245 | 4020 | struct breakpoint *b = NULL; |
afe38095 | 4021 | struct bp_location *bl; |
20874c92 | 4022 | struct bp_location *loc; |
c906108c SS |
4023 | /* Root of the chain of bpstat's */ |
4024 | struct bpstats root_bs[1]; | |
4025 | /* Pointer to the last thing in the chain currently. */ | |
4026 | bpstat bs = root_bs; | |
20874c92 | 4027 | int ix; |
429374b8 | 4028 | int need_remove_insert; |
c906108c | 4029 | |
429374b8 JK |
4030 | /* ALL_BP_LOCATIONS iteration would break across |
4031 | update_global_location_list possibly executed by | |
4032 | bpstat_check_breakpoint_conditions's inferior call. */ | |
c5aa993b | 4033 | |
429374b8 JK |
4034 | ALL_BREAKPOINTS (b) |
4035 | { | |
4036 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4037 | continue; | |
a5606eee | 4038 | |
429374b8 JK |
4039 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4040 | { | |
4041 | /* For hardware watchpoints, we look only at the first location. | |
cc60f2e3 PA |
4042 | The watchpoint_check function will work on the entire expression, |
4043 | not the individual locations. For read watchpoints, the | |
4044 | watchpoints_triggered function has checked all locations | |
429374b8 JK |
4045 | already. */ |
4046 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
4047 | break; | |
18a18393 | 4048 | |
429374b8 JK |
4049 | if (bl->shlib_disabled) |
4050 | continue; | |
c5aa993b | 4051 | |
429374b8 JK |
4052 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4053 | continue; | |
c5aa993b | 4054 | |
429374b8 | 4055 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 4056 | |
429374b8 | 4057 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 4058 | |
429374b8 JK |
4059 | /* Assume we stop. Should we find watchpoint that is not actually |
4060 | triggered, or if condition of breakpoint is false, we'll reset | |
4061 | 'stop' to 0. */ | |
4062 | bs->stop = 1; | |
4063 | bs->print = 1; | |
d983da9c | 4064 | |
429374b8 JK |
4065 | bpstat_check_watchpoint (bs); |
4066 | if (!bs->stop) | |
4067 | continue; | |
18a18393 | 4068 | |
429374b8 | 4069 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d TT |
4070 | || b->type == bp_longjmp_master |
4071 | || b->type == bp_std_terminate_master) | |
429374b8 JK |
4072 | /* We do not stop for these. */ |
4073 | bs->stop = 0; | |
4074 | else | |
4075 | bpstat_check_breakpoint_conditions (bs, ptid); | |
4076 | ||
4077 | if (bs->stop) | |
4078 | { | |
4079 | ++(b->hit_count); | |
c906108c | 4080 | |
429374b8 JK |
4081 | /* We will stop here */ |
4082 | if (b->disposition == disp_disable) | |
4083 | { | |
4084 | if (b->enable_state != bp_permanent) | |
4085 | b->enable_state = bp_disabled; | |
4086 | update_global_location_list (0); | |
4087 | } | |
4088 | if (b->silent) | |
4089 | bs->print = 0; | |
4090 | bs->commands = b->commands; | |
9add0f1b TT |
4091 | incref_counted_command_line (bs->commands); |
4092 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4093 | if (bs->commands_left | |
4094 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4095 | || (xdb_commands | |
4096 | && strcmp ("Q", | |
4097 | bs->commands_left->line) == 0))) | |
429374b8 | 4098 | { |
9add0f1b | 4099 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4100 | bs->print = 0; |
4101 | } | |
429374b8 JK |
4102 | } |
4103 | ||
4104 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4105 | if (bs->stop == 0 || bs->print == 0) | |
4106 | bs->print_it = print_it_noop; | |
4107 | } | |
4108 | } | |
876fa593 | 4109 | |
20874c92 VP |
4110 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
4111 | { | |
6c95b8df PA |
4112 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
4113 | aspace, bp_addr)) | |
20874c92 VP |
4114 | { |
4115 | bs = bpstat_alloc (loc, bs); | |
4116 | /* For hits of moribund locations, we should just proceed. */ | |
4117 | bs->stop = 0; | |
4118 | bs->print = 0; | |
4119 | bs->print_it = print_it_noop; | |
4120 | } | |
4121 | } | |
4122 | ||
c906108c | 4123 | bs->next = NULL; /* Terminate the chain */ |
c906108c | 4124 | |
d983da9c DJ |
4125 | /* If we aren't stopping, the value of some hardware watchpoint may |
4126 | not have changed, but the intermediate memory locations we are | |
4127 | watching may have. Don't bother if we're stopping; this will get | |
4128 | done later. */ | |
d832cb68 | 4129 | need_remove_insert = 0; |
1f7ccab2 | 4130 | if (! bpstat_causes_stop (root_bs->next)) |
d983da9c DJ |
4131 | for (bs = root_bs->next; bs != NULL; bs = bs->next) |
4132 | if (!bs->stop | |
20874c92 | 4133 | && bs->breakpoint_at->owner |
2d134ed3 | 4134 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 4135 | { |
2d134ed3 PA |
4136 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
4137 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
4138 | Prevent further code from trying to use it. */ | |
a5606eee | 4139 | bs->breakpoint_at = NULL; |
d832cb68 | 4140 | need_remove_insert = 1; |
d983da9c DJ |
4141 | } |
4142 | ||
d832cb68 | 4143 | if (need_remove_insert) |
2d134ed3 | 4144 | update_global_location_list (1); |
d832cb68 | 4145 | |
d983da9c | 4146 | return root_bs->next; |
c906108c | 4147 | } |
628fe4e4 JK |
4148 | |
4149 | static void | |
4150 | handle_jit_event (void) | |
4151 | { | |
4152 | struct frame_info *frame; | |
4153 | struct gdbarch *gdbarch; | |
4154 | ||
4155 | /* Switch terminal for any messages produced by | |
4156 | breakpoint_re_set. */ | |
4157 | target_terminal_ours_for_output (); | |
4158 | ||
4159 | frame = get_current_frame (); | |
4160 | gdbarch = get_frame_arch (frame); | |
4161 | ||
4162 | jit_event_handler (gdbarch); | |
4163 | ||
4164 | target_terminal_inferior (); | |
4165 | } | |
4166 | ||
4167 | /* Prepare WHAT final decision for infrun. */ | |
4168 | ||
4169 | /* Decide what infrun needs to do with this bpstat. */ | |
4170 | ||
c906108c | 4171 | struct bpstat_what |
fba45db2 | 4172 | bpstat_what (bpstat bs) |
c906108c | 4173 | { |
c906108c | 4174 | struct bpstat_what retval; |
628fe4e4 JK |
4175 | /* We need to defer calling `solib_add', as adding new symbols |
4176 | resets breakpoints, which in turn deletes breakpoint locations, | |
4177 | and hence may clear unprocessed entries in the BS chain. */ | |
4178 | int shlib_event = 0; | |
4179 | int jit_event = 0; | |
c906108c | 4180 | |
628fe4e4 | 4181 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4182 | retval.call_dummy = STOP_NONE; |
628fe4e4 | 4183 | |
c906108c SS |
4184 | for (; bs != NULL; bs = bs->next) |
4185 | { | |
628fe4e4 JK |
4186 | /* Extract this BS's action. After processing each BS, we check |
4187 | if its action overrides all we've seem so far. */ | |
4188 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4189 | enum bptype bptype; | |
4190 | ||
c906108c | 4191 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4192 | { |
4193 | /* I suspect this can happen if it was a momentary | |
4194 | breakpoint which has since been deleted. */ | |
4195 | bptype = bp_none; | |
4196 | } | |
4197 | else if (bs->breakpoint_at->owner == NULL) | |
4198 | bptype = bp_none; | |
20874c92 | 4199 | else |
628fe4e4 JK |
4200 | bptype = bs->breakpoint_at->owner->type; |
4201 | ||
4202 | switch (bptype) | |
c906108c SS |
4203 | { |
4204 | case bp_none: | |
628fe4e4 | 4205 | break; |
c906108c SS |
4206 | case bp_breakpoint: |
4207 | case bp_hardware_breakpoint: | |
4208 | case bp_until: | |
4209 | case bp_finish: | |
4210 | if (bs->stop) | |
4211 | { | |
4212 | if (bs->print) | |
628fe4e4 | 4213 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4214 | else |
628fe4e4 | 4215 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4216 | } |
4217 | else | |
628fe4e4 | 4218 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4219 | break; |
4220 | case bp_watchpoint: | |
4221 | case bp_hardware_watchpoint: | |
4222 | case bp_read_watchpoint: | |
4223 | case bp_access_watchpoint: | |
4224 | if (bs->stop) | |
4225 | { | |
4226 | if (bs->print) | |
628fe4e4 | 4227 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4228 | else |
628fe4e4 | 4229 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4230 | } |
4231 | else | |
628fe4e4 JK |
4232 | { |
4233 | /* There was a watchpoint, but we're not stopping. | |
4234 | This requires no further action. */ | |
4235 | } | |
c906108c SS |
4236 | break; |
4237 | case bp_longjmp: | |
628fe4e4 | 4238 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
c906108c SS |
4239 | break; |
4240 | case bp_longjmp_resume: | |
628fe4e4 | 4241 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
c906108c SS |
4242 | break; |
4243 | case bp_step_resume: | |
4244 | if (bs->stop) | |
628fe4e4 JK |
4245 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4246 | else | |
c906108c | 4247 | { |
628fe4e4 JK |
4248 | /* It is for the wrong frame. */ |
4249 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4250 | } |
c906108c | 4251 | break; |
c906108c | 4252 | case bp_watchpoint_scope: |
c4093a6a | 4253 | case bp_thread_event: |
1900040c | 4254 | case bp_overlay_event: |
0fd8e87f | 4255 | case bp_longjmp_master: |
aa7d318d | 4256 | case bp_std_terminate_master: |
628fe4e4 | 4257 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4258 | break; |
ce78b96d | 4259 | case bp_catchpoint: |
c5aa993b JM |
4260 | if (bs->stop) |
4261 | { | |
4262 | if (bs->print) | |
628fe4e4 | 4263 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4264 | else |
628fe4e4 | 4265 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4266 | } |
4267 | else | |
628fe4e4 JK |
4268 | { |
4269 | /* There was a catchpoint, but we're not stopping. | |
4270 | This requires no further action. */ | |
4271 | } | |
4272 | break; | |
4273 | case bp_shlib_event: | |
4274 | shlib_event = 1; | |
4275 | ||
4276 | /* If requested, stop when the dynamic linker notifies GDB | |
4277 | of events. This allows the user to get control and place | |
4278 | breakpoints in initializer routines for dynamically | |
4279 | loaded objects (among other things). */ | |
4280 | if (stop_on_solib_events) | |
4281 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4282 | else | |
4283 | this_action = BPSTAT_WHAT_SINGLE; | |
4284 | break; | |
4285 | case bp_jit_event: | |
4286 | jit_event = 1; | |
4287 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4288 | break; |
c906108c | 4289 | case bp_call_dummy: |
53a5351d JM |
4290 | /* Make sure the action is stop (silent or noisy), |
4291 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4292 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4293 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4294 | break; |
4295 | case bp_std_terminate: | |
4296 | /* Make sure the action is stop (silent or noisy), | |
4297 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4298 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4299 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4300 | break; |
1042e4c0 | 4301 | case bp_tracepoint: |
7a697b8d | 4302 | case bp_fast_tracepoint: |
0fb4aa4b | 4303 | case bp_static_tracepoint: |
1042e4c0 SS |
4304 | /* Tracepoint hits should not be reported back to GDB, and |
4305 | if one got through somehow, it should have been filtered | |
4306 | out already. */ | |
4307 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4308 | _("bpstat_what: tracepoint encountered")); |
628fe4e4 JK |
4309 | default: |
4310 | internal_error (__FILE__, __LINE__, | |
4311 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4312 | } |
628fe4e4 JK |
4313 | |
4314 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4315 | } |
628fe4e4 JK |
4316 | |
4317 | if (shlib_event) | |
4318 | { | |
4319 | if (debug_infrun) | |
4320 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4321 | ||
4322 | /* Check for any newly added shared libraries if we're supposed | |
4323 | to be adding them automatically. */ | |
4324 | ||
4325 | /* Switch terminal for any messages produced by | |
4326 | breakpoint_re_set. */ | |
4327 | target_terminal_ours_for_output (); | |
4328 | ||
4329 | #ifdef SOLIB_ADD | |
4330 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4331 | #else | |
4332 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4333 | #endif | |
4334 | ||
4335 | target_terminal_inferior (); | |
4336 | } | |
4337 | ||
4338 | if (jit_event) | |
4339 | { | |
4340 | if (debug_infrun) | |
4341 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4342 | ||
4343 | handle_jit_event (); | |
4344 | } | |
4345 | ||
c906108c SS |
4346 | return retval; |
4347 | } | |
4348 | ||
4349 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4350 | without hardware support). This isn't related to a specific bpstat, | |
4351 | just to things like whether watchpoints are set. */ | |
4352 | ||
c5aa993b | 4353 | int |
fba45db2 | 4354 | bpstat_should_step (void) |
c906108c SS |
4355 | { |
4356 | struct breakpoint *b; | |
cc59ec59 | 4357 | |
c906108c | 4358 | ALL_BREAKPOINTS (b) |
717a8278 | 4359 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4360 | return 1; |
c906108c SS |
4361 | return 0; |
4362 | } | |
4363 | ||
67822962 PA |
4364 | int |
4365 | bpstat_causes_stop (bpstat bs) | |
4366 | { | |
4367 | for (; bs != NULL; bs = bs->next) | |
4368 | if (bs->stop) | |
4369 | return 1; | |
4370 | ||
4371 | return 0; | |
4372 | } | |
4373 | ||
c906108c | 4374 | \f |
c5aa993b | 4375 | |
859825b8 JK |
4376 | /* Print the LOC location out of the list of B->LOC locations. */ |
4377 | ||
0d381245 VP |
4378 | static void print_breakpoint_location (struct breakpoint *b, |
4379 | struct bp_location *loc, | |
4380 | char *wrap_indent, | |
4381 | struct ui_stream *stb) | |
4382 | { | |
6c95b8df PA |
4383 | struct cleanup *old_chain = save_current_program_space (); |
4384 | ||
859825b8 JK |
4385 | if (loc != NULL && loc->shlib_disabled) |
4386 | loc = NULL; | |
4387 | ||
6c95b8df PA |
4388 | if (loc != NULL) |
4389 | set_current_program_space (loc->pspace); | |
4390 | ||
859825b8 | 4391 | if (b->source_file && loc) |
0d381245 VP |
4392 | { |
4393 | struct symbol *sym | |
4394 | = find_pc_sect_function (loc->address, loc->section); | |
4395 | if (sym) | |
4396 | { | |
4397 | ui_out_text (uiout, "in "); | |
4398 | ui_out_field_string (uiout, "func", | |
4399 | SYMBOL_PRINT_NAME (sym)); | |
4400 | ui_out_wrap_hint (uiout, wrap_indent); | |
4401 | ui_out_text (uiout, " at "); | |
4402 | } | |
4403 | ui_out_field_string (uiout, "file", b->source_file); | |
4404 | ui_out_text (uiout, ":"); | |
4405 | ||
4406 | if (ui_out_is_mi_like_p (uiout)) | |
4407 | { | |
4408 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4409 | char *fullname = symtab_to_fullname (sal.symtab); | |
4410 | ||
4411 | if (fullname) | |
4412 | ui_out_field_string (uiout, "fullname", fullname); | |
4413 | } | |
4414 | ||
4415 | ui_out_field_int (uiout, "line", b->line_number); | |
4416 | } | |
859825b8 | 4417 | else if (loc) |
0d381245 | 4418 | { |
22e722e1 DJ |
4419 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4420 | demangle, ""); | |
0d381245 VP |
4421 | ui_out_field_stream (uiout, "at", stb); |
4422 | } | |
859825b8 JK |
4423 | else |
4424 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4425 | |
4426 | do_cleanups (old_chain); | |
0d381245 VP |
4427 | } |
4428 | ||
269b11a2 PA |
4429 | static const char * |
4430 | bptype_string (enum bptype type) | |
c906108c | 4431 | { |
c4093a6a JM |
4432 | struct ep_type_description |
4433 | { | |
4434 | enum bptype type; | |
4435 | char *description; | |
4436 | }; | |
4437 | static struct ep_type_description bptypes[] = | |
c906108c | 4438 | { |
c5aa993b JM |
4439 | {bp_none, "?deleted?"}, |
4440 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4441 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4442 | {bp_until, "until"}, |
4443 | {bp_finish, "finish"}, | |
4444 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4445 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4446 | {bp_read_watchpoint, "read watchpoint"}, |
4447 | {bp_access_watchpoint, "acc watchpoint"}, | |
4448 | {bp_longjmp, "longjmp"}, | |
4449 | {bp_longjmp_resume, "longjmp resume"}, | |
4450 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4451 | {bp_watchpoint_scope, "watchpoint scope"}, |
4452 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4453 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4454 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4455 | {bp_thread_event, "thread events"}, |
1900040c | 4456 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4457 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4458 | {bp_std_terminate_master, "std::terminate master"}, |
ce78b96d | 4459 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4460 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4461 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4462 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4463 | {bp_jit_event, "jit events"}, |
c5aa993b | 4464 | }; |
269b11a2 PA |
4465 | |
4466 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4467 | || ((int) type != bptypes[(int) type].type)) | |
4468 | internal_error (__FILE__, __LINE__, | |
4469 | _("bptypes table does not describe type #%d."), | |
4470 | (int) type); | |
4471 | ||
4472 | return bptypes[(int) type].description; | |
4473 | } | |
4474 | ||
4475 | /* Print B to gdb_stdout. */ | |
4476 | ||
4477 | static void | |
4478 | print_one_breakpoint_location (struct breakpoint *b, | |
4479 | struct bp_location *loc, | |
4480 | int loc_number, | |
4481 | struct bp_location **last_loc, | |
4482 | int print_address_bits, | |
4483 | int allflag) | |
4484 | { | |
4485 | struct command_line *l; | |
c2c6d25f | 4486 | static char bpenables[] = "nynny"; |
c906108c | 4487 | char wrap_indent[80]; |
8b93c638 JM |
4488 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4489 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4490 | struct cleanup *bkpt_chain; |
c906108c | 4491 | |
0d381245 VP |
4492 | int header_of_multiple = 0; |
4493 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4494 | struct value_print_options opts; |
4495 | ||
4496 | get_user_print_options (&opts); | |
0d381245 VP |
4497 | |
4498 | gdb_assert (!loc || loc_number != 0); | |
4499 | /* See comment in print_one_breakpoint concerning | |
4500 | treatment of breakpoints with single disabled | |
4501 | location. */ | |
4502 | if (loc == NULL | |
4503 | && (b->loc != NULL | |
4504 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4505 | header_of_multiple = 1; | |
4506 | if (loc == NULL) | |
4507 | loc = b->loc; | |
4508 | ||
c4093a6a | 4509 | annotate_record (); |
3b31d625 | 4510 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4511 | |
4512 | /* 1 */ | |
4513 | annotate_field (0); | |
0d381245 VP |
4514 | if (part_of_multiple) |
4515 | { | |
4516 | char *formatted; | |
0c6773c1 | 4517 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4518 | ui_out_field_string (uiout, "number", formatted); |
4519 | xfree (formatted); | |
4520 | } | |
4521 | else | |
4522 | { | |
4523 | ui_out_field_int (uiout, "number", b->number); | |
4524 | } | |
c4093a6a JM |
4525 | |
4526 | /* 2 */ | |
4527 | annotate_field (1); | |
0d381245 VP |
4528 | if (part_of_multiple) |
4529 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4530 | else |
4531 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4532 | |
4533 | /* 3 */ | |
4534 | annotate_field (2); | |
0d381245 VP |
4535 | if (part_of_multiple) |
4536 | ui_out_field_skip (uiout, "disp"); | |
4537 | else | |
2cec12e5 | 4538 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4539 | |
c4093a6a JM |
4540 | |
4541 | /* 4 */ | |
4542 | annotate_field (3); | |
0d381245 | 4543 | if (part_of_multiple) |
54e52265 | 4544 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4545 | else |
54e52265 VP |
4546 | ui_out_field_fmt (uiout, "enabled", "%c", |
4547 | bpenables[(int) b->enable_state]); | |
4548 | ui_out_spaces (uiout, 2); | |
0d381245 | 4549 | |
c4093a6a JM |
4550 | |
4551 | /* 5 and 6 */ | |
4552 | strcpy (wrap_indent, " "); | |
79a45b7d | 4553 | if (opts.addressprint) |
75ac9d7b | 4554 | { |
a6d9a66e | 4555 | if (print_address_bits <= 32) |
75ac9d7b MS |
4556 | strcat (wrap_indent, " "); |
4557 | else | |
4558 | strcat (wrap_indent, " "); | |
4559 | } | |
c906108c | 4560 | |
3086aeae | 4561 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4562 | { |
4563 | /* Although the print_one can possibly print | |
4564 | all locations, calling it here is not likely | |
4565 | to get any nice result. So, make sure there's | |
4566 | just one location. */ | |
4567 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4568 | b->ops->print_one (b, last_loc); |
0d381245 | 4569 | } |
3086aeae DJ |
4570 | else |
4571 | switch (b->type) | |
4572 | { | |
4573 | case bp_none: | |
4574 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4575 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4576 | break; |
c906108c | 4577 | |
3086aeae DJ |
4578 | case bp_watchpoint: |
4579 | case bp_hardware_watchpoint: | |
4580 | case bp_read_watchpoint: | |
4581 | case bp_access_watchpoint: | |
4582 | /* Field 4, the address, is omitted (which makes the columns | |
4583 | not line up too nicely with the headers, but the effect | |
4584 | is relatively readable). */ | |
79a45b7d | 4585 | if (opts.addressprint) |
3086aeae DJ |
4586 | ui_out_field_skip (uiout, "addr"); |
4587 | annotate_field (5); | |
fa8a61dc | 4588 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4589 | break; |
4590 | ||
3086aeae DJ |
4591 | case bp_breakpoint: |
4592 | case bp_hardware_breakpoint: | |
4593 | case bp_until: | |
4594 | case bp_finish: | |
4595 | case bp_longjmp: | |
4596 | case bp_longjmp_resume: | |
4597 | case bp_step_resume: | |
3086aeae DJ |
4598 | case bp_watchpoint_scope: |
4599 | case bp_call_dummy: | |
aa7d318d | 4600 | case bp_std_terminate: |
3086aeae DJ |
4601 | case bp_shlib_event: |
4602 | case bp_thread_event: | |
4603 | case bp_overlay_event: | |
0fd8e87f | 4604 | case bp_longjmp_master: |
aa7d318d | 4605 | case bp_std_terminate_master: |
1042e4c0 | 4606 | case bp_tracepoint: |
7a697b8d | 4607 | case bp_fast_tracepoint: |
0fb4aa4b | 4608 | case bp_static_tracepoint: |
4efc6507 | 4609 | case bp_jit_event: |
79a45b7d | 4610 | if (opts.addressprint) |
3086aeae DJ |
4611 | { |
4612 | annotate_field (4); | |
54e52265 | 4613 | if (header_of_multiple) |
0d381245 | 4614 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4615 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4616 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4617 | else |
5af949e3 UW |
4618 | ui_out_field_core_addr (uiout, "addr", |
4619 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4620 | } |
4621 | annotate_field (5); | |
0d381245 VP |
4622 | if (!header_of_multiple) |
4623 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4624 | if (b->loc) | |
a6d9a66e | 4625 | *last_loc = b->loc; |
3086aeae DJ |
4626 | break; |
4627 | } | |
c906108c | 4628 | |
6c95b8df PA |
4629 | |
4630 | /* For backward compatibility, don't display inferiors unless there | |
4631 | are several. */ | |
4632 | if (loc != NULL | |
4633 | && !header_of_multiple | |
4634 | && (allflag | |
4635 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4636 | && (number_of_program_spaces () > 1 | |
4637 | || number_of_inferiors () > 1) | |
2bdf28a0 JK |
4638 | /* LOC is for existing B, it cannot be in moribund_locations and |
4639 | thus having NULL OWNER. */ | |
6c95b8df PA |
4640 | && loc->owner->type != bp_catchpoint))) |
4641 | { | |
4642 | struct inferior *inf; | |
4643 | int first = 1; | |
4644 | ||
4645 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4646 | { | |
4647 | if (inf->pspace == loc->pspace) | |
4648 | { | |
4649 | if (first) | |
4650 | { | |
4651 | first = 0; | |
4652 | ui_out_text (uiout, " inf "); | |
4653 | } | |
4654 | else | |
4655 | ui_out_text (uiout, ", "); | |
4656 | ui_out_text (uiout, plongest (inf->num)); | |
4657 | } | |
4658 | } | |
4659 | } | |
4660 | ||
4a306c9a | 4661 | if (!part_of_multiple) |
c4093a6a | 4662 | { |
4a306c9a JB |
4663 | if (b->thread != -1) |
4664 | { | |
4665 | /* FIXME: This seems to be redundant and lost here; see the | |
4666 | "stop only in" line a little further down. */ | |
4667 | ui_out_text (uiout, " thread "); | |
4668 | ui_out_field_int (uiout, "thread", b->thread); | |
4669 | } | |
4670 | else if (b->task != 0) | |
4671 | { | |
4672 | ui_out_text (uiout, " task "); | |
4673 | ui_out_field_int (uiout, "task", b->task); | |
4674 | } | |
c4093a6a JM |
4675 | } |
4676 | ||
8b93c638 | 4677 | ui_out_text (uiout, "\n"); |
c4093a6a | 4678 | |
0fb4aa4b PA |
4679 | if (!part_of_multiple && b->static_trace_marker_id) |
4680 | { | |
4681 | gdb_assert (b->type == bp_static_tracepoint); | |
4682 | ||
4683 | ui_out_text (uiout, "\tmarker id is "); | |
4684 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
4685 | b->static_trace_marker_id); | |
4686 | ui_out_text (uiout, "\n"); | |
4687 | } | |
4688 | ||
0d381245 | 4689 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4690 | { |
4691 | annotate_field (6); | |
8b93c638 | 4692 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4693 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4694 | the frame ID. */ | |
5af949e3 UW |
4695 | ui_out_field_core_addr (uiout, "frame", |
4696 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4697 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4698 | } |
4699 | ||
0d381245 | 4700 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4701 | { |
f7f9143b JB |
4702 | /* We do not print the condition for Ada exception catchpoints |
4703 | because the condition is an internal implementation detail | |
4704 | that we do not want to expose to the user. */ | |
c4093a6a | 4705 | annotate_field (7); |
d77f58be | 4706 | if (is_tracepoint (b)) |
1042e4c0 SS |
4707 | ui_out_text (uiout, "\ttrace only if "); |
4708 | else | |
4709 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4710 | ui_out_field_string (uiout, "cond", b->cond_string); |
4711 | ui_out_text (uiout, "\n"); | |
4712 | } | |
4713 | ||
0d381245 | 4714 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4715 | { |
4716 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4717 | ui_out_text (uiout, "\tstop only in thread "); |
4718 | ui_out_field_int (uiout, "thread", b->thread); | |
4719 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4720 | } |
4721 | ||
63c715c6 | 4722 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4723 | { |
4724 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4725 | if (ep_is_catchpoint (b)) |
4726 | ui_out_text (uiout, "\tcatchpoint"); | |
4727 | else | |
4728 | ui_out_text (uiout, "\tbreakpoint"); | |
4729 | ui_out_text (uiout, " already hit "); | |
4730 | ui_out_field_int (uiout, "times", b->hit_count); | |
4731 | if (b->hit_count == 1) | |
4732 | ui_out_text (uiout, " time\n"); | |
4733 | else | |
4734 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4735 | } |
4736 | ||
fb40c209 AC |
4737 | /* Output the count also if it is zero, but only if this is |
4738 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4739 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4740 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4741 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4742 | |
0d381245 | 4743 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4744 | { |
4745 | annotate_field (8); | |
8b93c638 JM |
4746 | ui_out_text (uiout, "\tignore next "); |
4747 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4748 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4749 | } |
059fb39f | 4750 | |
9add0f1b | 4751 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4752 | if (!part_of_multiple && l) |
c4093a6a | 4753 | { |
3b31d625 EZ |
4754 | struct cleanup *script_chain; |
4755 | ||
c4093a6a | 4756 | annotate_field (9); |
3b31d625 | 4757 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4758 | print_command_lines (uiout, l, 4); |
3b31d625 | 4759 | do_cleanups (script_chain); |
c4093a6a | 4760 | } |
d24317b4 | 4761 | |
1042e4c0 SS |
4762 | if (!part_of_multiple && b->pass_count) |
4763 | { | |
4764 | annotate_field (10); | |
4765 | ui_out_text (uiout, "\tpass count "); | |
4766 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4767 | ui_out_text (uiout, " \n"); | |
4768 | } | |
4769 | ||
d24317b4 VP |
4770 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4771 | { | |
4772 | if (b->addr_string) | |
4773 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4774 | else if (b->exp_string) | |
4775 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4776 | } | |
4777 | ||
3b31d625 | 4778 | do_cleanups (bkpt_chain); |
8b93c638 | 4779 | do_cleanups (old_chain); |
c4093a6a | 4780 | } |
c5aa993b | 4781 | |
0d381245 VP |
4782 | static void |
4783 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4784 | struct bp_location **last_loc, int print_address_bits, |
4785 | int allflag) | |
0d381245 | 4786 | { |
6c95b8df PA |
4787 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4788 | print_address_bits, allflag); | |
0d381245 VP |
4789 | |
4790 | /* If this breakpoint has custom print function, | |
4791 | it's already printed. Otherwise, print individual | |
4792 | locations, if any. */ | |
4793 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4794 | { | |
4795 | /* If breakpoint has a single location that is | |
4796 | disabled, we print it as if it had | |
4797 | several locations, since otherwise it's hard to | |
4798 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4799 | situation. |
4800 | Note that while hardware watchpoints have | |
4801 | several locations internally, that's no a property | |
4802 | exposed to user. */ | |
0d381245 | 4803 | if (b->loc |
a5606eee | 4804 | && !is_hardware_watchpoint (b) |
0d381245 | 4805 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4806 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4807 | { |
4808 | struct bp_location *loc; | |
4809 | int n = 1; | |
4810 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4811 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4812 | print_address_bits, allflag); |
0d381245 VP |
4813 | } |
4814 | } | |
4815 | } | |
4816 | ||
a6d9a66e UW |
4817 | static int |
4818 | breakpoint_address_bits (struct breakpoint *b) | |
4819 | { | |
4820 | int print_address_bits = 0; | |
4821 | struct bp_location *loc; | |
4822 | ||
4823 | for (loc = b->loc; loc; loc = loc->next) | |
4824 | { | |
c7437ca6 PA |
4825 | int addr_bit; |
4826 | ||
4827 | /* Software watchpoints that aren't watching memory don't have | |
4828 | an address to print. */ | |
4829 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4830 | continue; | |
4831 | ||
4832 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4833 | if (addr_bit > print_address_bits) |
4834 | print_address_bits = addr_bit; | |
4835 | } | |
4836 | ||
4837 | return print_address_bits; | |
4838 | } | |
0d381245 | 4839 | |
c4093a6a JM |
4840 | struct captured_breakpoint_query_args |
4841 | { | |
4842 | int bnum; | |
4843 | }; | |
c5aa993b | 4844 | |
c4093a6a | 4845 | static int |
2b65245e | 4846 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4847 | { |
4848 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4849 | struct breakpoint *b; |
a6d9a66e | 4850 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 4851 | |
c4093a6a JM |
4852 | ALL_BREAKPOINTS (b) |
4853 | { | |
4854 | if (args->bnum == b->number) | |
c5aa993b | 4855 | { |
a6d9a66e | 4856 | int print_address_bits = breakpoint_address_bits (b); |
cc59ec59 | 4857 | |
6c95b8df | 4858 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4859 | return GDB_RC_OK; |
c5aa993b | 4860 | } |
c4093a6a JM |
4861 | } |
4862 | return GDB_RC_NONE; | |
4863 | } | |
c5aa993b | 4864 | |
c4093a6a | 4865 | enum gdb_rc |
ce43223b | 4866 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4867 | { |
4868 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 4869 | |
c4093a6a JM |
4870 | args.bnum = bnum; |
4871 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4872 | an error. */ | |
b0b13bb4 DJ |
4873 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4874 | error_message, RETURN_MASK_ALL) < 0) | |
4875 | return GDB_RC_FAIL; | |
4876 | else | |
4877 | return GDB_RC_OK; | |
c4093a6a | 4878 | } |
c5aa993b | 4879 | |
7f3b0473 AC |
4880 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4881 | catchpoints, et.al.). */ | |
4882 | ||
4883 | static int | |
4884 | user_settable_breakpoint (const struct breakpoint *b) | |
4885 | { | |
4886 | return (b->type == bp_breakpoint | |
ce78b96d | 4887 | || b->type == bp_catchpoint |
7f3b0473 | 4888 | || b->type == bp_hardware_breakpoint |
d77f58be | 4889 | || is_tracepoint (b) |
cc60f2e3 | 4890 | || is_watchpoint (b)); |
7f3b0473 AC |
4891 | } |
4892 | ||
4893 | /* Print information on user settable breakpoint (watchpoint, etc) | |
d77f58be SS |
4894 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
4895 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
4896 | FILTER is non-NULL, call it on each breakpoint and only include the | |
4897 | ones for which it returns non-zero. Return the total number of | |
4898 | breakpoints listed. */ | |
c906108c | 4899 | |
d77f58be SS |
4900 | static int |
4901 | breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *)) | |
c4093a6a | 4902 | { |
52f0bd74 | 4903 | struct breakpoint *b; |
a6d9a66e | 4904 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4905 | int nr_printable_breakpoints; |
3b31d625 | 4906 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4907 | struct value_print_options opts; |
a6d9a66e | 4908 | int print_address_bits = 0; |
269b11a2 PA |
4909 | int print_type_col_width = 14; |
4910 | ||
79a45b7d TT |
4911 | get_user_print_options (&opts); |
4912 | ||
a6d9a66e UW |
4913 | /* Compute the number of rows in the table, as well as the |
4914 | size required for address fields. */ | |
7f3b0473 AC |
4915 | nr_printable_breakpoints = 0; |
4916 | ALL_BREAKPOINTS (b) | |
4917 | if (bnum == -1 | |
4918 | || bnum == b->number) | |
4919 | { | |
d77f58be SS |
4920 | /* If we have a filter, only list the breakpoints it accepts. */ |
4921 | if (filter && !filter (b)) | |
4922 | continue; | |
4923 | ||
7f3b0473 | 4924 | if (allflag || user_settable_breakpoint (b)) |
a6d9a66e | 4925 | { |
269b11a2 PA |
4926 | int addr_bit, type_len; |
4927 | ||
4928 | addr_bit = breakpoint_address_bits (b); | |
a6d9a66e UW |
4929 | if (addr_bit > print_address_bits) |
4930 | print_address_bits = addr_bit; | |
4931 | ||
269b11a2 PA |
4932 | type_len = strlen (bptype_string (b->type)); |
4933 | if (type_len > print_type_col_width) | |
4934 | print_type_col_width = type_len; | |
4935 | ||
a6d9a66e UW |
4936 | nr_printable_breakpoints++; |
4937 | } | |
7f3b0473 AC |
4938 | } |
4939 | ||
79a45b7d | 4940 | if (opts.addressprint) |
3b31d625 EZ |
4941 | bkpttbl_chain |
4942 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4943 | "BreakpointTable"); | |
8b93c638 | 4944 | else |
3b31d625 EZ |
4945 | bkpttbl_chain |
4946 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4947 | "BreakpointTable"); | |
8b93c638 | 4948 | |
7f3b0473 | 4949 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4950 | annotate_breakpoints_headers (); |
4951 | if (nr_printable_breakpoints > 0) | |
4952 | annotate_field (0); | |
0d381245 | 4953 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4954 | if (nr_printable_breakpoints > 0) |
4955 | annotate_field (1); | |
269b11a2 PA |
4956 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4957 | "type", "Type"); /* 2 */ | |
d7faa9e7 AC |
4958 | if (nr_printable_breakpoints > 0) |
4959 | annotate_field (2); | |
4960 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4961 | if (nr_printable_breakpoints > 0) | |
4962 | annotate_field (3); | |
54e52265 | 4963 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4964 | if (opts.addressprint) |
7f3b0473 | 4965 | { |
d7faa9e7 AC |
4966 | if (nr_printable_breakpoints > 0) |
4967 | annotate_field (4); | |
a6d9a66e | 4968 | if (print_address_bits <= 32) |
b25959ec | 4969 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4970 | else |
b25959ec | 4971 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4972 | } |
d7faa9e7 AC |
4973 | if (nr_printable_breakpoints > 0) |
4974 | annotate_field (5); | |
4975 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4976 | ui_out_table_body (uiout); | |
4977 | if (nr_printable_breakpoints > 0) | |
4978 | annotate_breakpoints_table (); | |
7f3b0473 | 4979 | |
c4093a6a | 4980 | ALL_BREAKPOINTS (b) |
bad56014 TT |
4981 | { |
4982 | QUIT; | |
c4093a6a JM |
4983 | if (bnum == -1 |
4984 | || bnum == b->number) | |
4985 | { | |
d77f58be SS |
4986 | /* If we have a filter, only list the breakpoints it accepts. */ |
4987 | if (filter && !filter (b)) | |
4988 | continue; | |
4989 | ||
c4093a6a JM |
4990 | /* We only print out user settable breakpoints unless the |
4991 | allflag is set. */ | |
7f3b0473 | 4992 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 4993 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a | 4994 | } |
bad56014 | 4995 | } |
c4093a6a | 4996 | |
3b31d625 | 4997 | do_cleanups (bkpttbl_chain); |
698384cd | 4998 | |
7f3b0473 | 4999 | if (nr_printable_breakpoints == 0) |
c906108c | 5000 | { |
d77f58be SS |
5001 | /* If there's a filter, let the caller decide how to report empty list. */ |
5002 | if (!filter) | |
5003 | { | |
5004 | if (bnum == -1) | |
5005 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
5006 | else | |
5007 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
5008 | bnum); | |
5009 | } | |
c906108c SS |
5010 | } |
5011 | else | |
c4093a6a | 5012 | { |
a6d9a66e UW |
5013 | if (last_loc && !server_command) |
5014 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5015 | } |
c906108c | 5016 | |
c4093a6a JM |
5017 | /* FIXME? Should this be moved up so that it is only called when |
5018 | there have been breakpoints? */ | |
c906108c | 5019 | annotate_breakpoints_table_end (); |
d77f58be SS |
5020 | |
5021 | return nr_printable_breakpoints; | |
c906108c SS |
5022 | } |
5023 | ||
ad443146 SS |
5024 | /* Display the value of default-collect in a way that is generally |
5025 | compatible with the breakpoint list. */ | |
5026 | ||
5027 | static void | |
5028 | default_collect_info (void) | |
5029 | { | |
5030 | /* If it has no value (which is frequently the case), say nothing; a | |
5031 | message like "No default-collect." gets in user's face when it's | |
5032 | not wanted. */ | |
5033 | if (!*default_collect) | |
5034 | return; | |
5035 | ||
5036 | /* The following phrase lines up nicely with per-tracepoint collect | |
5037 | actions. */ | |
5038 | ui_out_text (uiout, "default collect "); | |
5039 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5040 | ui_out_text (uiout, " \n"); | |
5041 | } | |
5042 | ||
c906108c | 5043 | static void |
fba45db2 | 5044 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
5045 | { |
5046 | int bnum = -1; | |
5047 | ||
5048 | if (bnum_exp) | |
bb518678 | 5049 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5050 | |
d77f58be | 5051 | breakpoint_1 (bnum, 0, NULL); |
ad443146 SS |
5052 | |
5053 | default_collect_info (); | |
d77f58be SS |
5054 | } |
5055 | ||
5056 | static void | |
5057 | watchpoints_info (char *wpnum_exp, int from_tty) | |
5058 | { | |
5059 | int wpnum = -1, num_printed; | |
5060 | ||
5061 | if (wpnum_exp) | |
5062 | wpnum = parse_and_eval_long (wpnum_exp); | |
5063 | ||
5064 | num_printed = breakpoint_1 (wpnum, 0, is_watchpoint); | |
5065 | ||
5066 | if (num_printed == 0) | |
5067 | { | |
5068 | if (wpnum == -1) | |
5069 | ui_out_message (uiout, 0, "No watchpoints.\n"); | |
5070 | else | |
5071 | ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum); | |
5072 | } | |
c906108c SS |
5073 | } |
5074 | ||
7a292a7a | 5075 | static void |
fba45db2 | 5076 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
5077 | { |
5078 | int bnum = -1; | |
5079 | ||
5080 | if (bnum_exp) | |
bb518678 | 5081 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5082 | |
d77f58be | 5083 | breakpoint_1 (bnum, 1, NULL); |
ad443146 SS |
5084 | |
5085 | default_collect_info (); | |
c906108c SS |
5086 | } |
5087 | ||
0d381245 | 5088 | static int |
714835d5 | 5089 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5090 | struct program_space *pspace, |
714835d5 | 5091 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5092 | { |
5093 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5094 | |
0d381245 VP |
5095 | for (; bl; bl = bl->next) |
5096 | { | |
6c95b8df PA |
5097 | if (bl->pspace == pspace |
5098 | && bl->address == pc | |
0d381245 VP |
5099 | && (!overlay_debugging || bl->section == section)) |
5100 | return 1; | |
5101 | } | |
5102 | return 0; | |
5103 | } | |
5104 | ||
6c95b8df PA |
5105 | /* Print a message describing any breakpoints set at PC. This |
5106 | concerns with logical breakpoints, so we match program spaces, not | |
5107 | address spaces. */ | |
c906108c SS |
5108 | |
5109 | static void | |
6c95b8df PA |
5110 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5111 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5112 | struct obj_section *section, int thread) |
c906108c | 5113 | { |
52f0bd74 AC |
5114 | int others = 0; |
5115 | struct breakpoint *b; | |
c906108c SS |
5116 | |
5117 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5118 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5119 | if (others > 0) |
5120 | { | |
a3f17187 AC |
5121 | if (others == 1) |
5122 | printf_filtered (_("Note: breakpoint ")); | |
5123 | else /* if (others == ???) */ | |
5124 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5125 | ALL_BREAKPOINTS (b) |
6c95b8df | 5126 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5127 | { |
5128 | others--; | |
5129 | printf_filtered ("%d", b->number); | |
5130 | if (b->thread == -1 && thread != -1) | |
5131 | printf_filtered (" (all threads)"); | |
5132 | else if (b->thread != -1) | |
5133 | printf_filtered (" (thread %d)", b->thread); | |
5134 | printf_filtered ("%s%s ", | |
059fb39f | 5135 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5136 | || b->enable_state == bp_call_disabled |
5137 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5138 | ? " (disabled)" |
5139 | : b->enable_state == bp_permanent | |
5140 | ? " (permanent)" | |
5141 | : ""), | |
5142 | (others > 1) ? "," | |
5143 | : ((others == 1) ? " and" : "")); | |
5144 | } | |
a3f17187 | 5145 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5146 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5147 | printf_filtered (".\n"); |
5148 | } | |
5149 | } | |
5150 | \f | |
5151 | /* Set the default place to put a breakpoint | |
5152 | for the `break' command with no arguments. */ | |
5153 | ||
5154 | void | |
6c95b8df PA |
5155 | set_default_breakpoint (int valid, struct program_space *pspace, |
5156 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5157 | int line) |
c906108c SS |
5158 | { |
5159 | default_breakpoint_valid = valid; | |
6c95b8df | 5160 | default_breakpoint_pspace = pspace; |
c906108c SS |
5161 | default_breakpoint_address = addr; |
5162 | default_breakpoint_symtab = symtab; | |
5163 | default_breakpoint_line = line; | |
5164 | } | |
5165 | ||
e4f237da KB |
5166 | /* Return true iff it is meaningful to use the address member of |
5167 | BPT. For some breakpoint types, the address member is irrelevant | |
5168 | and it makes no sense to attempt to compare it to other addresses | |
5169 | (or use it for any other purpose either). | |
5170 | ||
5171 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
5172 | have a zero valued address and we don't want to mark breakpoints of any of |
5173 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
5174 | |
5175 | bp_watchpoint | |
2d134ed3 PA |
5176 | bp_catchpoint |
5177 | ||
5178 | */ | |
e4f237da KB |
5179 | |
5180 | static int | |
5181 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5182 | { | |
5183 | enum bptype type = bpt->type; | |
5184 | ||
2d134ed3 PA |
5185 | return (type != bp_watchpoint && type != bp_catchpoint); |
5186 | } | |
5187 | ||
5188 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5189 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5190 | ||
5191 | static int | |
5192 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5193 | { | |
2bdf28a0 JK |
5194 | /* Both of them must not be in moribund_locations. */ |
5195 | gdb_assert (loc1->owner != NULL); | |
5196 | gdb_assert (loc2->owner != NULL); | |
5197 | ||
0cf6dd15 TJB |
5198 | /* If the target can evaluate the condition expression in hardware, then we |
5199 | we need to insert both watchpoints even if they are at the same place. | |
5200 | Otherwise the watchpoint will only trigger when the condition of whichever | |
5201 | watchpoint was inserted evaluates to true, not giving a chance for GDB to | |
5202 | check the condition of the other watchpoint. */ | |
5203 | if ((loc1->owner->cond_exp | |
5204 | && target_can_accel_watchpoint_condition (loc1->address, loc1->length, | |
5205 | loc1->watchpoint_type, | |
5206 | loc1->owner->cond_exp)) | |
5207 | || (loc2->owner->cond_exp | |
5208 | && target_can_accel_watchpoint_condition (loc2->address, loc2->length, | |
5209 | loc2->watchpoint_type, | |
5210 | loc2->owner->cond_exp))) | |
5211 | return 0; | |
5212 | ||
85d721b8 PA |
5213 | /* Note that this checks the owner's type, not the location's. In |
5214 | case the target does not support read watchpoints, but does | |
5215 | support access watchpoints, we'll have bp_read_watchpoint | |
5216 | watchpoints with hw_access locations. Those should be considered | |
5217 | duplicates of hw_read locations. The hw_read locations will | |
5218 | become hw_access locations later. */ | |
2d134ed3 PA |
5219 | return (loc1->owner->type == loc2->owner->type |
5220 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5221 | && loc1->address == loc2->address | |
5222 | && loc1->length == loc2->length); | |
e4f237da KB |
5223 | } |
5224 | ||
6c95b8df PA |
5225 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5226 | same breakpoint location. In most targets, this can only be true | |
5227 | if ASPACE1 matches ASPACE2. On targets that have global | |
5228 | breakpoints, the address space doesn't really matter. */ | |
5229 | ||
5230 | static int | |
5231 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5232 | struct address_space *aspace2, CORE_ADDR addr2) | |
5233 | { | |
5234 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5235 | || aspace1 == aspace2) | |
5236 | && addr1 == addr2); | |
5237 | } | |
5238 | ||
2d134ed3 PA |
5239 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5240 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5241 | represent the same location. */ | |
5242 | ||
5243 | static int | |
5244 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5245 | { | |
2bdf28a0 JK |
5246 | int hw_point1, hw_point2; |
5247 | ||
5248 | /* Both of them must not be in moribund_locations. */ | |
5249 | gdb_assert (loc1->owner != NULL); | |
5250 | gdb_assert (loc2->owner != NULL); | |
5251 | ||
5252 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5253 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5254 | |
5255 | if (hw_point1 != hw_point2) | |
5256 | return 0; | |
5257 | else if (hw_point1) | |
5258 | return watchpoint_locations_match (loc1, loc2); | |
5259 | else | |
5260 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5261 | loc2->pspace->aspace, loc2->address); | |
5262 | } | |
5263 | ||
76897487 KB |
5264 | static void |
5265 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5266 | int bnum, int have_bnum) | |
5267 | { | |
5268 | char astr1[40]; | |
5269 | char astr2[40]; | |
5270 | ||
bb599908 PH |
5271 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5272 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5273 | if (have_bnum) |
8a3fe4f8 | 5274 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5275 | bnum, astr1, astr2); |
5276 | else | |
8a3fe4f8 | 5277 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5278 | } |
5279 | ||
5280 | /* Adjust a breakpoint's address to account for architectural constraints | |
5281 | on breakpoint placement. Return the adjusted address. Note: Very | |
5282 | few targets require this kind of adjustment. For most targets, | |
5283 | this function is simply the identity function. */ | |
5284 | ||
5285 | static CORE_ADDR | |
a6d9a66e UW |
5286 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5287 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5288 | { |
a6d9a66e | 5289 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5290 | { |
5291 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5292 | return bpaddr; | |
5293 | } | |
88f7da05 KB |
5294 | else if (bptype == bp_watchpoint |
5295 | || bptype == bp_hardware_watchpoint | |
5296 | || bptype == bp_read_watchpoint | |
5297 | || bptype == bp_access_watchpoint | |
fe798b75 | 5298 | || bptype == bp_catchpoint) |
88f7da05 KB |
5299 | { |
5300 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5301 | have their addresses modified. */ | |
5302 | return bpaddr; | |
5303 | } | |
76897487 KB |
5304 | else |
5305 | { | |
5306 | CORE_ADDR adjusted_bpaddr; | |
5307 | ||
5308 | /* Some targets have architectural constraints on the placement | |
5309 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5310 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5311 | |
5312 | /* An adjusted breakpoint address can significantly alter | |
5313 | a user's expectations. Print a warning if an adjustment | |
5314 | is required. */ | |
5315 | if (adjusted_bpaddr != bpaddr) | |
5316 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5317 | ||
5318 | return adjusted_bpaddr; | |
5319 | } | |
5320 | } | |
5321 | ||
7cc221ef DJ |
5322 | /* Allocate a struct bp_location. */ |
5323 | ||
26bb91f3 | 5324 | static struct bp_location * |
39d61571 | 5325 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5326 | { |
afe38095 | 5327 | struct bp_location *loc; |
7cc221ef DJ |
5328 | |
5329 | loc = xmalloc (sizeof (struct bp_location)); | |
5330 | memset (loc, 0, sizeof (*loc)); | |
5331 | ||
e049a4b5 | 5332 | loc->owner = bpt; |
511a6cd4 | 5333 | loc->cond = NULL; |
0d381245 VP |
5334 | loc->shlib_disabled = 0; |
5335 | loc->enabled = 1; | |
e049a4b5 | 5336 | |
39d61571 | 5337 | switch (bpt->type) |
e049a4b5 DJ |
5338 | { |
5339 | case bp_breakpoint: | |
5340 | case bp_until: | |
5341 | case bp_finish: | |
5342 | case bp_longjmp: | |
5343 | case bp_longjmp_resume: | |
5344 | case bp_step_resume: | |
e049a4b5 DJ |
5345 | case bp_watchpoint_scope: |
5346 | case bp_call_dummy: | |
aa7d318d | 5347 | case bp_std_terminate: |
e049a4b5 DJ |
5348 | case bp_shlib_event: |
5349 | case bp_thread_event: | |
5350 | case bp_overlay_event: | |
4efc6507 | 5351 | case bp_jit_event: |
0fd8e87f | 5352 | case bp_longjmp_master: |
aa7d318d | 5353 | case bp_std_terminate_master: |
e049a4b5 DJ |
5354 | loc->loc_type = bp_loc_software_breakpoint; |
5355 | break; | |
5356 | case bp_hardware_breakpoint: | |
5357 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5358 | break; | |
5359 | case bp_hardware_watchpoint: | |
5360 | case bp_read_watchpoint: | |
5361 | case bp_access_watchpoint: | |
5362 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5363 | break; | |
5364 | case bp_watchpoint: | |
ce78b96d | 5365 | case bp_catchpoint: |
15c3d785 PA |
5366 | case bp_tracepoint: |
5367 | case bp_fast_tracepoint: | |
0fb4aa4b | 5368 | case bp_static_tracepoint: |
e049a4b5 DJ |
5369 | loc->loc_type = bp_loc_other; |
5370 | break; | |
5371 | default: | |
e2e0b3e5 | 5372 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5373 | } |
5374 | ||
7cc221ef DJ |
5375 | return loc; |
5376 | } | |
5377 | ||
fe3f5fa8 VP |
5378 | static void free_bp_location (struct bp_location *loc) |
5379 | { | |
1a2ab13a JK |
5380 | /* Be sure no bpstat's are pointing at it after it's been freed. */ |
5381 | /* FIXME, how can we find all bpstat's? | |
5382 | We just check stop_bpstat for now. Note that we cannot just | |
5383 | remove bpstats pointing at bpt from the stop_bpstat list | |
5384 | entirely, as breakpoint commands are associated with the bpstat; | |
5385 | if we remove it here, then the later call to | |
5386 | bpstat_do_actions (&stop_bpstat); | |
5387 | in event-top.c won't do anything, and temporary breakpoints | |
5388 | with commands won't work. */ | |
5389 | ||
5390 | iterate_over_threads (bpstat_remove_bp_location_callback, loc); | |
5391 | ||
fe3f5fa8 VP |
5392 | if (loc->cond) |
5393 | xfree (loc->cond); | |
74960c60 VP |
5394 | |
5395 | if (loc->function_name) | |
5396 | xfree (loc->function_name); | |
5397 | ||
fe3f5fa8 VP |
5398 | xfree (loc); |
5399 | } | |
5400 | ||
0d381245 VP |
5401 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
5402 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 5403 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 5404 | |
c40e75cd | 5405 | static struct breakpoint * |
a6d9a66e UW |
5406 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5407 | enum bptype bptype) | |
c906108c | 5408 | { |
52f0bd74 | 5409 | struct breakpoint *b, *b1; |
c906108c SS |
5410 | |
5411 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5412 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5413 | |
4d28f7a8 | 5414 | b->type = bptype; |
a6d9a66e | 5415 | b->gdbarch = gdbarch; |
c906108c SS |
5416 | b->language = current_language->la_language; |
5417 | b->input_radix = input_radix; | |
5418 | b->thread = -1; | |
b5de0fa7 | 5419 | b->enable_state = bp_enabled; |
c906108c SS |
5420 | b->next = 0; |
5421 | b->silent = 0; | |
5422 | b->ignore_count = 0; | |
5423 | b->commands = NULL; | |
818dd999 | 5424 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5425 | b->forked_inferior_pid = null_ptid; |
c906108c | 5426 | b->exec_pathname = NULL; |
a96d9b2e | 5427 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5428 | b->ops = NULL; |
0d381245 | 5429 | b->condition_not_parsed = 0; |
c906108c SS |
5430 | |
5431 | /* Add this breakpoint to the end of the chain | |
5432 | so that a list of breakpoints will come out in order | |
5433 | of increasing numbers. */ | |
5434 | ||
5435 | b1 = breakpoint_chain; | |
5436 | if (b1 == 0) | |
5437 | breakpoint_chain = b; | |
5438 | else | |
5439 | { | |
5440 | while (b1->next) | |
5441 | b1 = b1->next; | |
5442 | b1->next = b; | |
5443 | } | |
0d381245 VP |
5444 | return b; |
5445 | } | |
5446 | ||
5447 | /* Initialize loc->function_name. */ | |
5448 | static void | |
5449 | set_breakpoint_location_function (struct bp_location *loc) | |
5450 | { | |
2bdf28a0 JK |
5451 | gdb_assert (loc->owner != NULL); |
5452 | ||
0d381245 | 5453 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5454 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5455 | || is_tracepoint (loc->owner)) |
0d381245 VP |
5456 | { |
5457 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5458 | NULL, NULL); | |
5459 | if (loc->function_name) | |
5460 | loc->function_name = xstrdup (loc->function_name); | |
5461 | } | |
5462 | } | |
5463 | ||
a6d9a66e UW |
5464 | /* Attempt to determine architecture of location identified by SAL. */ |
5465 | static struct gdbarch * | |
5466 | get_sal_arch (struct symtab_and_line sal) | |
5467 | { | |
5468 | if (sal.section) | |
5469 | return get_objfile_arch (sal.section->objfile); | |
5470 | if (sal.symtab) | |
5471 | return get_objfile_arch (sal.symtab->objfile); | |
5472 | ||
5473 | return NULL; | |
5474 | } | |
5475 | ||
0d381245 VP |
5476 | /* set_raw_breakpoint is a low level routine for allocating and |
5477 | partially initializing a breakpoint of type BPTYPE. The newly | |
5478 | created breakpoint's address, section, source file name, and line | |
5479 | number are provided by SAL. The newly created and partially | |
5480 | initialized breakpoint is added to the breakpoint chain and | |
5481 | is also returned as the value of this function. | |
5482 | ||
5483 | It is expected that the caller will complete the initialization of | |
5484 | the newly created breakpoint struct as well as output any status | |
5485 | information regarding the creation of a new breakpoint. In | |
5486 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5487 | number! Care should be taken to not allow an error to occur | |
5488 | prior to completing the initialization of the breakpoint. If this | |
5489 | should happen, a bogus breakpoint will be left on the chain. */ | |
5490 | ||
63c252f8 | 5491 | struct breakpoint * |
a6d9a66e UW |
5492 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5493 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5494 | { |
a6d9a66e | 5495 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 5496 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5497 | struct gdbarch *loc_gdbarch; |
5498 | ||
5499 | loc_gdbarch = get_sal_arch (sal); | |
5500 | if (!loc_gdbarch) | |
5501 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5502 | |
6c95b8df PA |
5503 | if (bptype != bp_catchpoint) |
5504 | gdb_assert (sal.pspace != NULL); | |
5505 | ||
0d381245 VP |
5506 | /* Adjust the breakpoint's address prior to allocating a location. |
5507 | Once we call allocate_bp_location(), that mostly uninitialized | |
5508 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5509 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5510 | not want its scan of the location chain to find a breakpoint and |
5511 | location that's only been partially initialized. */ | |
a6d9a66e | 5512 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 5513 | |
39d61571 | 5514 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5515 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5516 | b->loc->requested_address = sal.pc; |
5517 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5518 | b->loc->pspace = sal.pspace; |
5519 | ||
5520 | /* Store the program space that was used to set the breakpoint, for | |
5521 | breakpoint resetting. */ | |
5522 | b->pspace = sal.pspace; | |
0d381245 VP |
5523 | |
5524 | if (sal.symtab == NULL) | |
5525 | b->source_file = NULL; | |
5526 | else | |
1b36a34b | 5527 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5528 | b->loc->section = sal.section; |
5529 | b->line_number = sal.line; | |
5530 | ||
5531 | set_breakpoint_location_function (b->loc); | |
c906108c | 5532 | |
c906108c SS |
5533 | breakpoints_changed (); |
5534 | ||
5535 | return b; | |
5536 | } | |
5537 | ||
c2c6d25f JM |
5538 | |
5539 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5540 | instruction, hard-wired into the inferior's code. */ | |
5541 | void | |
5542 | make_breakpoint_permanent (struct breakpoint *b) | |
5543 | { | |
0d381245 | 5544 | struct bp_location *bl; |
cc59ec59 | 5545 | |
b5de0fa7 | 5546 | b->enable_state = bp_permanent; |
c2c6d25f | 5547 | |
0d381245 VP |
5548 | /* By definition, permanent breakpoints are already present in the code. |
5549 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
5550 | is called in just one place, so it's hard to say if it's reasonable | |
5551 | to have permanent breakpoint with multiple locations or not, | |
5552 | but it's easy to implmement. */ | |
5553 | for (bl = b->loc; bl; bl = bl->next) | |
5554 | bl->inserted = 1; | |
c2c6d25f JM |
5555 | } |
5556 | ||
53a5351d | 5557 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5558 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5559 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5560 | ||
5561 | void | |
0fd8e87f | 5562 | set_longjmp_breakpoint (int thread) |
c906108c | 5563 | { |
0fd8e87f UW |
5564 | struct breakpoint *b, *temp; |
5565 | ||
5566 | /* To avoid having to rescan all objfile symbols at every step, | |
5567 | we maintain a list of continually-inserted but always disabled | |
5568 | longjmp "master" breakpoints. Here, we simply create momentary | |
5569 | clones of those and enable them for the requested thread. */ | |
5570 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5571 | if (b->pspace == current_program_space |
5572 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5573 | { |
5574 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5575 | |
0fd8e87f UW |
5576 | clone->type = bp_longjmp; |
5577 | clone->thread = thread; | |
5578 | } | |
c906108c SS |
5579 | } |
5580 | ||
611c83ae | 5581 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5582 | void |
611c83ae | 5583 | delete_longjmp_breakpoint (int thread) |
c906108c | 5584 | { |
611c83ae | 5585 | struct breakpoint *b, *temp; |
c906108c | 5586 | |
611c83ae PA |
5587 | ALL_BREAKPOINTS_SAFE (b, temp) |
5588 | if (b->type == bp_longjmp) | |
5589 | { | |
5590 | if (b->thread == thread) | |
5591 | delete_breakpoint (b); | |
5592 | } | |
c906108c SS |
5593 | } |
5594 | ||
1900040c MS |
5595 | void |
5596 | enable_overlay_breakpoints (void) | |
5597 | { | |
52f0bd74 | 5598 | struct breakpoint *b; |
1900040c MS |
5599 | |
5600 | ALL_BREAKPOINTS (b) | |
5601 | if (b->type == bp_overlay_event) | |
5602 | { | |
5603 | b->enable_state = bp_enabled; | |
b60e7edf | 5604 | update_global_location_list (1); |
c02f5703 | 5605 | overlay_events_enabled = 1; |
1900040c MS |
5606 | } |
5607 | } | |
5608 | ||
5609 | void | |
5610 | disable_overlay_breakpoints (void) | |
5611 | { | |
52f0bd74 | 5612 | struct breakpoint *b; |
1900040c MS |
5613 | |
5614 | ALL_BREAKPOINTS (b) | |
5615 | if (b->type == bp_overlay_event) | |
5616 | { | |
5617 | b->enable_state = bp_disabled; | |
b60e7edf | 5618 | update_global_location_list (0); |
c02f5703 | 5619 | overlay_events_enabled = 0; |
1900040c MS |
5620 | } |
5621 | } | |
5622 | ||
aa7d318d TT |
5623 | /* Set an active std::terminate breakpoint for each std::terminate |
5624 | master breakpoint. */ | |
5625 | void | |
5626 | set_std_terminate_breakpoint (void) | |
5627 | { | |
5628 | struct breakpoint *b, *temp; | |
5629 | ||
5630 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5631 | if (b->pspace == current_program_space | |
5632 | && b->type == bp_std_terminate_master) | |
5633 | { | |
5634 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5635 | clone->type = bp_std_terminate; | |
5636 | } | |
5637 | } | |
5638 | ||
5639 | /* Delete all the std::terminate breakpoints. */ | |
5640 | void | |
5641 | delete_std_terminate_breakpoint (void) | |
5642 | { | |
5643 | struct breakpoint *b, *temp; | |
5644 | ||
5645 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5646 | if (b->type == bp_std_terminate) | |
5647 | delete_breakpoint (b); | |
5648 | } | |
5649 | ||
c4093a6a | 5650 | struct breakpoint * |
a6d9a66e | 5651 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5652 | { |
5653 | struct breakpoint *b; | |
c4093a6a | 5654 | |
a6d9a66e | 5655 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5656 | |
b5de0fa7 | 5657 | b->enable_state = bp_enabled; |
c4093a6a | 5658 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5659 | b->addr_string |
5660 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5661 | |
b60e7edf | 5662 | update_global_location_list_nothrow (1); |
74960c60 | 5663 | |
c4093a6a JM |
5664 | return b; |
5665 | } | |
5666 | ||
5667 | void | |
5668 | remove_thread_event_breakpoints (void) | |
5669 | { | |
5670 | struct breakpoint *b, *temp; | |
5671 | ||
5672 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5673 | if (b->type == bp_thread_event |
5674 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5675 | delete_breakpoint (b); |
5676 | } | |
5677 | ||
0101ce28 JJ |
5678 | struct captured_parse_breakpoint_args |
5679 | { | |
5680 | char **arg_p; | |
5681 | struct symtabs_and_lines *sals_p; | |
5682 | char ***addr_string_p; | |
5683 | int *not_found_ptr; | |
5684 | }; | |
5685 | ||
5686 | struct lang_and_radix | |
5687 | { | |
5688 | enum language lang; | |
5689 | int radix; | |
5690 | }; | |
5691 | ||
4efc6507 DE |
5692 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5693 | ||
5694 | struct breakpoint * | |
5695 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5696 | { | |
5697 | struct breakpoint *b; | |
5698 | ||
5699 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5700 | update_global_location_list_nothrow (1); | |
5701 | return b; | |
5702 | } | |
0101ce28 | 5703 | |
cae688ec JJ |
5704 | void |
5705 | remove_solib_event_breakpoints (void) | |
5706 | { | |
5707 | struct breakpoint *b, *temp; | |
5708 | ||
5709 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5710 | if (b->type == bp_shlib_event |
5711 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5712 | delete_breakpoint (b); |
5713 | } | |
5714 | ||
5715 | struct breakpoint * | |
a6d9a66e | 5716 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5717 | { |
5718 | struct breakpoint *b; | |
5719 | ||
a6d9a66e | 5720 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5721 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5722 | return b; |
5723 | } | |
5724 | ||
5725 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5726 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5727 | ||
5728 | void | |
cb851954 | 5729 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5730 | { |
876fa593 | 5731 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5732 | |
876fa593 | 5733 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5734 | { |
2bdf28a0 | 5735 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 5736 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 5737 | |
0d381245 VP |
5738 | /* We apply the check to all breakpoints, including disabled |
5739 | for those with loc->duplicate set. This is so that when breakpoint | |
5740 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5741 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5742 | to insert those breakpoints and fail. */ | |
1042e4c0 | 5743 | if (((b->type == bp_breakpoint) |
508ccb1f | 5744 | || (b->type == bp_jit_event) |
1042e4c0 | 5745 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 5746 | || (is_tracepoint (b))) |
6c95b8df | 5747 | && loc->pspace == current_program_space |
0d381245 | 5748 | && !loc->shlib_disabled |
a77053c2 | 5749 | #ifdef PC_SOLIB |
0d381245 | 5750 | && PC_SOLIB (loc->address) |
a77053c2 | 5751 | #else |
6c95b8df | 5752 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5753 | #endif |
5754 | ) | |
0d381245 VP |
5755 | { |
5756 | loc->shlib_disabled = 1; | |
5757 | } | |
cae688ec JJ |
5758 | } |
5759 | } | |
5760 | ||
84acb35a JJ |
5761 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5762 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5763 | ||
75149521 | 5764 | static void |
84acb35a JJ |
5765 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5766 | { | |
876fa593 | 5767 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5768 | int disabled_shlib_breaks = 0; |
5769 | ||
c86cf029 VP |
5770 | /* SunOS a.out shared libraries are always mapped, so do not |
5771 | disable breakpoints; they will only be reported as unloaded | |
5772 | through clear_solib when GDB discards its shared library | |
5773 | list. See clear_solib for more information. */ | |
5774 | if (exec_bfd != NULL | |
5775 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5776 | return; | |
5777 | ||
876fa593 | 5778 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5779 | { |
2bdf28a0 | 5780 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 5781 | struct breakpoint *b = loc->owner; |
cc59ec59 | 5782 | |
0d381245 VP |
5783 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
5784 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5785 | && solib->pspace == loc->pspace |
e2dd7057 | 5786 | && !loc->shlib_disabled |
508ccb1f TT |
5787 | && (b->type == bp_breakpoint |
5788 | || b->type == bp_jit_event | |
5789 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 5790 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 5791 | { |
e2dd7057 PP |
5792 | loc->shlib_disabled = 1; |
5793 | /* At this point, we cannot rely on remove_breakpoint | |
5794 | succeeding so we must mark the breakpoint as not inserted | |
5795 | to prevent future errors occurring in remove_breakpoints. */ | |
5796 | loc->inserted = 0; | |
5797 | if (!disabled_shlib_breaks) | |
5798 | { | |
5799 | target_terminal_ours_for_output (); | |
5800 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5801 | solib->so_name); | |
84acb35a | 5802 | } |
e2dd7057 | 5803 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5804 | } |
5805 | } | |
84acb35a JJ |
5806 | } |
5807 | ||
ce78b96d JB |
5808 | /* FORK & VFORK catchpoints. */ |
5809 | ||
5810 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5811 | ||
c906108c | 5812 | static void |
ce78b96d JB |
5813 | insert_catch_fork (struct breakpoint *b) |
5814 | { | |
5815 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5816 | } | |
5817 | ||
5818 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5819 | ||
5820 | static int | |
5821 | remove_catch_fork (struct breakpoint *b) | |
5822 | { | |
5823 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5824 | } | |
5825 | ||
5826 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5827 | catchpoints. */ | |
5828 | ||
5829 | static int | |
5830 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5831 | { | |
5832 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5833 | } | |
5834 | ||
5835 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5836 | ||
5837 | static enum print_stop_action | |
5838 | print_it_catch_fork (struct breakpoint *b) | |
5839 | { | |
5840 | annotate_catchpoint (b->number); | |
5841 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5842 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5843 | return PRINT_SRC_AND_LOC; | |
5844 | } | |
5845 | ||
5846 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5847 | ||
5848 | static void | |
a6d9a66e | 5849 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5850 | { |
79a45b7d TT |
5851 | struct value_print_options opts; |
5852 | ||
5853 | get_user_print_options (&opts); | |
5854 | ||
ce78b96d JB |
5855 | /* Field 4, the address, is omitted (which makes the columns |
5856 | not line up too nicely with the headers, but the effect | |
5857 | is relatively readable). */ | |
79a45b7d | 5858 | if (opts.addressprint) |
ce78b96d JB |
5859 | ui_out_field_skip (uiout, "addr"); |
5860 | annotate_field (5); | |
5861 | ui_out_text (uiout, "fork"); | |
5862 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5863 | { | |
5864 | ui_out_text (uiout, ", process "); | |
5865 | ui_out_field_int (uiout, "what", | |
5866 | ptid_get_pid (b->forked_inferior_pid)); | |
5867 | ui_out_spaces (uiout, 1); | |
5868 | } | |
5869 | } | |
5870 | ||
5871 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5872 | catchpoints. */ | |
5873 | ||
5874 | static void | |
5875 | print_mention_catch_fork (struct breakpoint *b) | |
5876 | { | |
5877 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5878 | } | |
5879 | ||
6149aea9 PA |
5880 | /* Implement the "print_recreate" breakpoint_ops method for fork |
5881 | catchpoints. */ | |
5882 | ||
5883 | static void | |
5884 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
5885 | { | |
5886 | fprintf_unfiltered (fp, "catch fork"); | |
5887 | } | |
5888 | ||
ce78b96d JB |
5889 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
5890 | ||
5891 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5892 | { | |
5893 | insert_catch_fork, | |
5894 | remove_catch_fork, | |
5895 | breakpoint_hit_catch_fork, | |
5896 | print_it_catch_fork, | |
5897 | print_one_catch_fork, | |
6149aea9 PA |
5898 | print_mention_catch_fork, |
5899 | print_recreate_catch_fork | |
ce78b96d JB |
5900 | }; |
5901 | ||
5902 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5903 | ||
5904 | static void | |
5905 | insert_catch_vfork (struct breakpoint *b) | |
5906 | { | |
5907 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5908 | } | |
5909 | ||
5910 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5911 | ||
5912 | static int | |
5913 | remove_catch_vfork (struct breakpoint *b) | |
5914 | { | |
5915 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5916 | } | |
5917 | ||
5918 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5919 | catchpoints. */ | |
5920 | ||
5921 | static int | |
5922 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5923 | { | |
5924 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5925 | } | |
5926 | ||
5927 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5928 | ||
5929 | static enum print_stop_action | |
5930 | print_it_catch_vfork (struct breakpoint *b) | |
5931 | { | |
5932 | annotate_catchpoint (b->number); | |
5933 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5934 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5935 | return PRINT_SRC_AND_LOC; | |
5936 | } | |
5937 | ||
5938 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5939 | ||
5940 | static void | |
a6d9a66e | 5941 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5942 | { |
79a45b7d TT |
5943 | struct value_print_options opts; |
5944 | ||
5945 | get_user_print_options (&opts); | |
ce78b96d JB |
5946 | /* Field 4, the address, is omitted (which makes the columns |
5947 | not line up too nicely with the headers, but the effect | |
5948 | is relatively readable). */ | |
79a45b7d | 5949 | if (opts.addressprint) |
ce78b96d JB |
5950 | ui_out_field_skip (uiout, "addr"); |
5951 | annotate_field (5); | |
5952 | ui_out_text (uiout, "vfork"); | |
5953 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5954 | { | |
5955 | ui_out_text (uiout, ", process "); | |
5956 | ui_out_field_int (uiout, "what", | |
5957 | ptid_get_pid (b->forked_inferior_pid)); | |
5958 | ui_out_spaces (uiout, 1); | |
5959 | } | |
5960 | } | |
5961 | ||
5962 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5963 | catchpoints. */ | |
5964 | ||
5965 | static void | |
5966 | print_mention_catch_vfork (struct breakpoint *b) | |
5967 | { | |
5968 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5969 | } | |
5970 | ||
6149aea9 PA |
5971 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
5972 | catchpoints. */ | |
5973 | ||
5974 | static void | |
5975 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
5976 | { | |
5977 | fprintf_unfiltered (fp, "catch vfork"); | |
5978 | } | |
5979 | ||
ce78b96d JB |
5980 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
5981 | ||
5982 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5983 | { | |
5984 | insert_catch_vfork, | |
5985 | remove_catch_vfork, | |
5986 | breakpoint_hit_catch_vfork, | |
5987 | print_it_catch_vfork, | |
5988 | print_one_catch_vfork, | |
6149aea9 PA |
5989 | print_mention_catch_vfork, |
5990 | print_recreate_catch_vfork | |
ce78b96d JB |
5991 | }; |
5992 | ||
a96d9b2e SDJ |
5993 | /* Implement the "insert" breakpoint_ops method for syscall |
5994 | catchpoints. */ | |
5995 | ||
5996 | static void | |
5997 | insert_catch_syscall (struct breakpoint *b) | |
5998 | { | |
5999 | struct inferior *inf = current_inferior (); | |
6000 | ||
6001 | ++inf->total_syscalls_count; | |
6002 | if (!b->syscalls_to_be_caught) | |
6003 | ++inf->any_syscall_count; | |
6004 | else | |
6005 | { | |
6006 | int i, iter; | |
cc59ec59 | 6007 | |
a96d9b2e SDJ |
6008 | for (i = 0; |
6009 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6010 | i++) | |
6011 | { | |
6012 | int elem; | |
cc59ec59 | 6013 | |
a96d9b2e SDJ |
6014 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6015 | { | |
6016 | int old_size = VEC_length (int, inf->syscalls_counts); | |
6017 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
6018 | uintptr_t vec_addr; | |
6019 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6020 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6021 | vec_addr_offset; | |
6022 | memset ((void *) vec_addr, 0, | |
6023 | (iter + 1 - old_size) * sizeof (int)); | |
6024 | } | |
6025 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6026 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6027 | } | |
6028 | } | |
6029 | ||
6030 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6031 | inf->total_syscalls_count != 0, | |
6032 | inf->any_syscall_count, | |
6033 | VEC_length (int, inf->syscalls_counts), | |
6034 | VEC_address (int, inf->syscalls_counts)); | |
6035 | } | |
6036 | ||
6037 | /* Implement the "remove" breakpoint_ops method for syscall | |
6038 | catchpoints. */ | |
6039 | ||
6040 | static int | |
6041 | remove_catch_syscall (struct breakpoint *b) | |
6042 | { | |
6043 | struct inferior *inf = current_inferior (); | |
6044 | ||
6045 | --inf->total_syscalls_count; | |
6046 | if (!b->syscalls_to_be_caught) | |
6047 | --inf->any_syscall_count; | |
6048 | else | |
6049 | { | |
6050 | int i, iter; | |
cc59ec59 | 6051 | |
a96d9b2e SDJ |
6052 | for (i = 0; |
6053 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6054 | i++) | |
6055 | { | |
6056 | int elem; | |
6057 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6058 | /* Shouldn't happen. */ | |
6059 | continue; | |
6060 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6061 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6062 | } | |
6063 | } | |
6064 | ||
6065 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6066 | inf->total_syscalls_count != 0, | |
6067 | inf->any_syscall_count, | |
6068 | VEC_length (int, inf->syscalls_counts), | |
6069 | VEC_address (int, inf->syscalls_counts)); | |
6070 | } | |
6071 | ||
6072 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6073 | catchpoints. */ | |
6074 | ||
6075 | static int | |
6076 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6077 | { | |
6078 | /* We must check if we are catching specific syscalls in this breakpoint. | |
6079 | If we are, then we must guarantee that the called syscall is the same | |
6080 | syscall we are catching. */ | |
6081 | int syscall_number = 0; | |
6082 | ||
6083 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6084 | return 0; | |
6085 | ||
6086 | /* Now, checking if the syscall is the same. */ | |
6087 | if (b->syscalls_to_be_caught) | |
6088 | { | |
6089 | int i, iter; | |
cc59ec59 | 6090 | |
a96d9b2e SDJ |
6091 | for (i = 0; |
6092 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6093 | i++) | |
6094 | if (syscall_number == iter) | |
6095 | break; | |
6096 | /* Not the same. */ | |
6097 | if (!iter) | |
6098 | return 0; | |
6099 | } | |
6100 | ||
6101 | return 1; | |
6102 | } | |
6103 | ||
6104 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6105 | catchpoints. */ | |
6106 | ||
6107 | static enum print_stop_action | |
6108 | print_it_catch_syscall (struct breakpoint *b) | |
6109 | { | |
6110 | /* These are needed because we want to know in which state a | |
6111 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6112 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6113 | must print "called syscall" or "returned from syscall". */ | |
6114 | ptid_t ptid; | |
6115 | struct target_waitstatus last; | |
6116 | struct syscall s; | |
6117 | struct cleanup *old_chain; | |
6118 | char *syscall_id; | |
6119 | ||
6120 | get_last_target_status (&ptid, &last); | |
6121 | ||
6122 | get_syscall_by_number (last.value.syscall_number, &s); | |
6123 | ||
6124 | annotate_catchpoint (b->number); | |
6125 | ||
6126 | if (s.name == NULL) | |
6127 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6128 | else | |
6129 | syscall_id = xstrprintf ("'%s'", s.name); | |
6130 | ||
6131 | old_chain = make_cleanup (xfree, syscall_id); | |
6132 | ||
6133 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6134 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6135 | b->number, syscall_id); | |
6136 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6137 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6138 | b->number, syscall_id); | |
6139 | ||
6140 | do_cleanups (old_chain); | |
6141 | ||
6142 | return PRINT_SRC_AND_LOC; | |
6143 | } | |
6144 | ||
6145 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6146 | catchpoints. */ | |
6147 | ||
6148 | static void | |
6149 | print_one_catch_syscall (struct breakpoint *b, | |
6150 | struct bp_location **last_loc) | |
6151 | { | |
6152 | struct value_print_options opts; | |
6153 | ||
6154 | get_user_print_options (&opts); | |
6155 | /* Field 4, the address, is omitted (which makes the columns | |
6156 | not line up too nicely with the headers, but the effect | |
6157 | is relatively readable). */ | |
6158 | if (opts.addressprint) | |
6159 | ui_out_field_skip (uiout, "addr"); | |
6160 | annotate_field (5); | |
6161 | ||
6162 | if (b->syscalls_to_be_caught | |
6163 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6164 | ui_out_text (uiout, "syscalls \""); | |
6165 | else | |
6166 | ui_out_text (uiout, "syscall \""); | |
6167 | ||
6168 | if (b->syscalls_to_be_caught) | |
6169 | { | |
6170 | int i, iter; | |
6171 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6172 | |
a96d9b2e SDJ |
6173 | for (i = 0; |
6174 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6175 | i++) | |
6176 | { | |
6177 | char *x = text; | |
6178 | struct syscall s; | |
6179 | get_syscall_by_number (iter, &s); | |
6180 | ||
6181 | if (s.name != NULL) | |
6182 | text = xstrprintf ("%s%s, ", text, s.name); | |
6183 | else | |
6184 | text = xstrprintf ("%s%d, ", text, iter); | |
6185 | ||
6186 | /* We have to xfree the last 'text' (now stored at 'x') | |
6187 | because xstrprintf dinamically allocates new space for it | |
6188 | on every call. */ | |
6189 | xfree (x); | |
6190 | } | |
6191 | /* Remove the last comma. */ | |
6192 | text[strlen (text) - 2] = '\0'; | |
6193 | ui_out_field_string (uiout, "what", text); | |
6194 | } | |
6195 | else | |
6196 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6197 | ui_out_text (uiout, "\" "); | |
6198 | } | |
6199 | ||
6200 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6201 | catchpoints. */ | |
6202 | ||
6203 | static void | |
6204 | print_mention_catch_syscall (struct breakpoint *b) | |
6205 | { | |
6206 | if (b->syscalls_to_be_caught) | |
6207 | { | |
6208 | int i, iter; | |
6209 | ||
6210 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6211 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6212 | else | |
6213 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6214 | ||
6215 | for (i = 0; | |
6216 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6217 | i++) | |
6218 | { | |
6219 | struct syscall s; | |
6220 | get_syscall_by_number (iter, &s); | |
6221 | ||
6222 | if (s.name) | |
6223 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6224 | else | |
6225 | printf_filtered (" %d", s.number); | |
6226 | } | |
6227 | printf_filtered (")"); | |
6228 | } | |
6229 | else | |
6230 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6231 | b->number); | |
6232 | } | |
6233 | ||
6149aea9 PA |
6234 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6235 | catchpoints. */ | |
6236 | ||
6237 | static void | |
6238 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6239 | { | |
6240 | fprintf_unfiltered (fp, "catch syscall"); | |
6241 | ||
6242 | if (b->syscalls_to_be_caught) | |
6243 | { | |
6244 | int i, iter; | |
6245 | ||
6246 | for (i = 0; | |
6247 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6248 | i++) | |
6249 | { | |
6250 | struct syscall s; | |
6251 | ||
6252 | get_syscall_by_number (iter, &s); | |
6253 | if (s.name) | |
6254 | fprintf_unfiltered (fp, " %s", s.name); | |
6255 | else | |
6256 | fprintf_unfiltered (fp, " %d", s.number); | |
6257 | } | |
6258 | } | |
6259 | } | |
6260 | ||
a96d9b2e SDJ |
6261 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6262 | ||
6263 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6264 | { | |
6265 | insert_catch_syscall, | |
6266 | remove_catch_syscall, | |
6267 | breakpoint_hit_catch_syscall, | |
6268 | print_it_catch_syscall, | |
6269 | print_one_catch_syscall, | |
6149aea9 PA |
6270 | print_mention_catch_syscall, |
6271 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6272 | }; |
6273 | ||
6274 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6275 | ||
6276 | static int | |
6277 | syscall_catchpoint_p (struct breakpoint *b) | |
6278 | { | |
6279 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6280 | } | |
6281 | ||
6282 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6283 | but does NOT mention it nor update the global location list. | |
6284 | This is useful if you need to fill more fields in the | |
6285 | struct breakpoint before calling mention. | |
ce78b96d JB |
6286 | |
6287 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6288 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6289 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6290 | to the catchpoint. */ | |
6291 | ||
6292 | static struct breakpoint * | |
a96d9b2e SDJ |
6293 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6294 | char *cond_string, | |
6295 | struct breakpoint_ops *ops) | |
c906108c | 6296 | { |
c5aa993b JM |
6297 | struct symtab_and_line sal; |
6298 | struct breakpoint *b; | |
c5aa993b | 6299 | |
fe39c653 | 6300 | init_sal (&sal); |
6c95b8df | 6301 | sal.pspace = current_program_space; |
c5aa993b | 6302 | |
a6d9a66e | 6303 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6304 | set_breakpoint_count (breakpoint_count + 1); |
6305 | b->number = breakpoint_count; | |
ce78b96d | 6306 | |
1b36a34b | 6307 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6308 | b->thread = -1; |
c906108c | 6309 | b->addr_string = NULL; |
b5de0fa7 EZ |
6310 | b->enable_state = bp_enabled; |
6311 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6312 | b->ops = ops; |
c5aa993b | 6313 | |
a96d9b2e SDJ |
6314 | return b; |
6315 | } | |
6316 | ||
6317 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6318 | ||
6319 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6320 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6321 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6322 | to the catchpoint. */ | |
6323 | ||
6324 | static struct breakpoint * | |
6325 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6326 | char *cond_string, struct breakpoint_ops *ops) | |
6327 | { | |
6328 | struct breakpoint *b = | |
6329 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6330 | ||
c906108c | 6331 | mention (b); |
ce78b96d | 6332 | update_global_location_list (1); |
c906108c | 6333 | |
ce78b96d | 6334 | return b; |
c906108c | 6335 | } |
c5aa993b | 6336 | |
9b70b993 | 6337 | static void |
a6d9a66e UW |
6338 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6339 | int tempflag, char *cond_string, | |
ce78b96d | 6340 | struct breakpoint_ops *ops) |
c906108c | 6341 | { |
a6d9a66e UW |
6342 | struct breakpoint *b |
6343 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6344 | |
6345 | /* FIXME: We should put this information in a breakpoint private data | |
6346 | area. */ | |
6347 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6348 | } |
6349 | ||
fe798b75 JB |
6350 | /* Exec catchpoints. */ |
6351 | ||
9b70b993 | 6352 | static void |
fe798b75 | 6353 | insert_catch_exec (struct breakpoint *b) |
c906108c | 6354 | { |
fe798b75 JB |
6355 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
6356 | } | |
c906108c | 6357 | |
fe798b75 JB |
6358 | static int |
6359 | remove_catch_exec (struct breakpoint *b) | |
6360 | { | |
6361 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6362 | } | |
c906108c | 6363 | |
fe798b75 JB |
6364 | static int |
6365 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6366 | { | |
6367 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6368 | } | |
c906108c | 6369 | |
fe798b75 JB |
6370 | static enum print_stop_action |
6371 | print_it_catch_exec (struct breakpoint *b) | |
6372 | { | |
6373 | annotate_catchpoint (b->number); | |
6374 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6375 | b->exec_pathname); | |
6376 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6377 | } |
6378 | ||
fe798b75 | 6379 | static void |
a6d9a66e | 6380 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6381 | { |
6382 | struct value_print_options opts; | |
6383 | ||
6384 | get_user_print_options (&opts); | |
6385 | ||
6386 | /* Field 4, the address, is omitted (which makes the columns | |
6387 | not line up too nicely with the headers, but the effect | |
6388 | is relatively readable). */ | |
6389 | if (opts.addressprint) | |
6390 | ui_out_field_skip (uiout, "addr"); | |
6391 | annotate_field (5); | |
6392 | ui_out_text (uiout, "exec"); | |
6393 | if (b->exec_pathname != NULL) | |
6394 | { | |
6395 | ui_out_text (uiout, ", program \""); | |
6396 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6397 | ui_out_text (uiout, "\" "); | |
6398 | } | |
6399 | } | |
6400 | ||
6401 | static void | |
6402 | print_mention_catch_exec (struct breakpoint *b) | |
6403 | { | |
6404 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6405 | } | |
6406 | ||
6149aea9 PA |
6407 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6408 | catchpoints. */ | |
6409 | ||
6410 | static void | |
6411 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6412 | { | |
6413 | fprintf_unfiltered (fp, "catch exec"); | |
6414 | } | |
6415 | ||
fe798b75 JB |
6416 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6417 | { | |
6418 | insert_catch_exec, | |
6419 | remove_catch_exec, | |
6420 | breakpoint_hit_catch_exec, | |
6421 | print_it_catch_exec, | |
6422 | print_one_catch_exec, | |
6149aea9 PA |
6423 | print_mention_catch_exec, |
6424 | print_recreate_catch_exec | |
fe798b75 JB |
6425 | }; |
6426 | ||
a96d9b2e SDJ |
6427 | static void |
6428 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6429 | struct breakpoint_ops *ops) | |
6430 | { | |
6431 | struct gdbarch *gdbarch = get_current_arch (); | |
6432 | struct breakpoint *b = | |
6433 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6434 | ||
6435 | b->syscalls_to_be_caught = filter; | |
6436 | ||
6437 | /* Now, we have to mention the breakpoint and update the global | |
6438 | location list. */ | |
6439 | mention (b); | |
6440 | update_global_location_list (1); | |
6441 | } | |
6442 | ||
c906108c | 6443 | static int |
fba45db2 | 6444 | hw_breakpoint_used_count (void) |
c906108c | 6445 | { |
52f0bd74 | 6446 | struct breakpoint *b; |
c906108c SS |
6447 | int i = 0; |
6448 | ||
6449 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6450 | { |
d6b74ac4 | 6451 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6452 | i++; |
6453 | } | |
c906108c SS |
6454 | |
6455 | return i; | |
6456 | } | |
6457 | ||
6458 | static int | |
fba45db2 | 6459 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6460 | { |
52f0bd74 | 6461 | struct breakpoint *b; |
c906108c SS |
6462 | int i = 0; |
6463 | ||
6464 | *other_type_used = 0; | |
6465 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6466 | { |
468d015d | 6467 | if (breakpoint_enabled (b)) |
c5aa993b JM |
6468 | { |
6469 | if (b->type == type) | |
6470 | i++; | |
cc60f2e3 | 6471 | else if (is_hardware_watchpoint (b)) |
c5aa993b JM |
6472 | *other_type_used = 1; |
6473 | } | |
6474 | } | |
c906108c SS |
6475 | return i; |
6476 | } | |
6477 | ||
c906108c | 6478 | void |
fba45db2 | 6479 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6480 | { |
c5aa993b | 6481 | struct breakpoint *b; |
c906108c SS |
6482 | |
6483 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6484 | { |
cc60f2e3 | 6485 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6486 | { |
b5de0fa7 | 6487 | b->enable_state = bp_call_disabled; |
b60e7edf | 6488 | update_global_location_list (0); |
c5aa993b JM |
6489 | } |
6490 | } | |
c906108c SS |
6491 | } |
6492 | ||
6493 | void | |
fba45db2 | 6494 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6495 | { |
c5aa993b | 6496 | struct breakpoint *b; |
c906108c SS |
6497 | |
6498 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6499 | { |
cc60f2e3 | 6500 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6501 | { |
b5de0fa7 | 6502 | b->enable_state = bp_enabled; |
b60e7edf | 6503 | update_global_location_list (1); |
c5aa993b JM |
6504 | } |
6505 | } | |
c906108c SS |
6506 | } |
6507 | ||
8bea4e01 UW |
6508 | void |
6509 | disable_breakpoints_before_startup (void) | |
6510 | { | |
6511 | struct breakpoint *b; | |
6512 | int found = 0; | |
6513 | ||
6514 | ALL_BREAKPOINTS (b) | |
6515 | { | |
6c95b8df PA |
6516 | if (b->pspace != current_program_space) |
6517 | continue; | |
6518 | ||
8bea4e01 UW |
6519 | if ((b->type == bp_breakpoint |
6520 | || b->type == bp_hardware_breakpoint) | |
6521 | && breakpoint_enabled (b)) | |
6522 | { | |
6523 | b->enable_state = bp_startup_disabled; | |
6524 | found = 1; | |
6525 | } | |
6526 | } | |
6527 | ||
6528 | if (found) | |
6529 | update_global_location_list (0); | |
6530 | ||
6c95b8df | 6531 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6532 | } |
6533 | ||
6534 | void | |
6535 | enable_breakpoints_after_startup (void) | |
6536 | { | |
6537 | struct breakpoint *b; | |
6538 | int found = 0; | |
6539 | ||
6c95b8df | 6540 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6541 | |
6542 | ALL_BREAKPOINTS (b) | |
6543 | { | |
6c95b8df PA |
6544 | if (b->pspace != current_program_space) |
6545 | continue; | |
6546 | ||
8bea4e01 UW |
6547 | if ((b->type == bp_breakpoint |
6548 | || b->type == bp_hardware_breakpoint) | |
6549 | && b->enable_state == bp_startup_disabled) | |
6550 | { | |
6551 | b->enable_state = bp_enabled; | |
6552 | found = 1; | |
6553 | } | |
6554 | } | |
6555 | ||
6556 | if (found) | |
6557 | breakpoint_re_set (); | |
6558 | } | |
6559 | ||
c906108c SS |
6560 | |
6561 | /* Set a breakpoint that will evaporate an end of command | |
6562 | at address specified by SAL. | |
6563 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6564 | ||
6565 | struct breakpoint * | |
a6d9a66e UW |
6566 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6567 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6568 | { |
52f0bd74 | 6569 | struct breakpoint *b; |
edb3359d DJ |
6570 | |
6571 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6572 | one. */ | |
6573 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6574 | ||
a6d9a66e | 6575 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6576 | b->enable_state = bp_enabled; |
6577 | b->disposition = disp_donttouch; | |
818dd999 | 6578 | b->frame_id = frame_id; |
c906108c SS |
6579 | |
6580 | /* If we're debugging a multi-threaded program, then we | |
6581 | want momentary breakpoints to be active in only a | |
6582 | single thread of control. */ | |
39f77062 KB |
6583 | if (in_thread_list (inferior_ptid)) |
6584 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6585 | |
b60e7edf | 6586 | update_global_location_list_nothrow (1); |
74960c60 | 6587 | |
c906108c SS |
6588 | return b; |
6589 | } | |
611c83ae | 6590 | |
e58b0e63 PA |
6591 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6592 | ORIG is NULL. */ | |
6593 | ||
6594 | struct breakpoint * | |
6595 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6596 | { | |
6597 | struct breakpoint *copy; | |
6598 | ||
6599 | /* If there's nothing to clone, then return nothing. */ | |
6600 | if (orig == NULL) | |
6601 | return NULL; | |
6602 | ||
a6d9a66e | 6603 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6604 | copy->loc = allocate_bp_location (copy); |
6605 | set_breakpoint_location_function (copy->loc); | |
6606 | ||
a6d9a66e | 6607 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6608 | copy->loc->requested_address = orig->loc->requested_address; |
6609 | copy->loc->address = orig->loc->address; | |
6610 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6611 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6612 | |
6613 | if (orig->source_file == NULL) | |
6614 | copy->source_file = NULL; | |
6615 | else | |
6616 | copy->source_file = xstrdup (orig->source_file); | |
6617 | ||
6618 | copy->line_number = orig->line_number; | |
6619 | copy->frame_id = orig->frame_id; | |
6620 | copy->thread = orig->thread; | |
6c95b8df | 6621 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6622 | |
6623 | copy->enable_state = bp_enabled; | |
6624 | copy->disposition = disp_donttouch; | |
6625 | copy->number = internal_breakpoint_number--; | |
6626 | ||
6627 | update_global_location_list_nothrow (0); | |
6628 | return copy; | |
6629 | } | |
6630 | ||
611c83ae | 6631 | struct breakpoint * |
a6d9a66e UW |
6632 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6633 | enum bptype type) | |
611c83ae PA |
6634 | { |
6635 | struct symtab_and_line sal; | |
6636 | ||
6637 | sal = find_pc_line (pc, 0); | |
6638 | sal.pc = pc; | |
6639 | sal.section = find_pc_overlay (pc); | |
6640 | sal.explicit_pc = 1; | |
6641 | ||
a6d9a66e | 6642 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6643 | } |
c906108c | 6644 | \f |
c5aa993b | 6645 | |
c906108c SS |
6646 | /* Tell the user we have just set a breakpoint B. */ |
6647 | ||
6648 | static void | |
fba45db2 | 6649 | mention (struct breakpoint *b) |
c906108c SS |
6650 | { |
6651 | int say_where = 0; | |
fa8a61dc | 6652 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6653 | struct value_print_options opts; |
6654 | ||
6655 | get_user_print_options (&opts); | |
8b93c638 | 6656 | |
9a4105ab AC |
6657 | /* FIXME: This is misplaced; mention() is called by things (like |
6658 | hitting a watchpoint) other than breakpoint creation. It should | |
6659 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6660 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6661 | observer_notify_breakpoint_created (b->number); |
c906108c | 6662 | |
3086aeae DJ |
6663 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6664 | b->ops->print_mention (b); | |
6665 | else | |
6666 | switch (b->type) | |
6667 | { | |
6668 | case bp_none: | |
a3f17187 | 6669 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6670 | break; |
6671 | case bp_watchpoint: | |
6672 | ui_out_text (uiout, "Watchpoint "); | |
6673 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6674 | ui_out_field_int (uiout, "number", b->number); | |
6675 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6676 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6677 | do_cleanups (ui_out_chain); |
6678 | break; | |
6679 | case bp_hardware_watchpoint: | |
6680 | ui_out_text (uiout, "Hardware watchpoint "); | |
6681 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6682 | ui_out_field_int (uiout, "number", b->number); | |
6683 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6684 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6685 | do_cleanups (ui_out_chain); |
6686 | break; | |
6687 | case bp_read_watchpoint: | |
6688 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6689 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6690 | ui_out_field_int (uiout, "number", b->number); | |
6691 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6692 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6693 | do_cleanups (ui_out_chain); |
6694 | break; | |
6695 | case bp_access_watchpoint: | |
6696 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6697 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6698 | ui_out_field_int (uiout, "number", b->number); | |
6699 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6700 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6701 | do_cleanups (ui_out_chain); |
6702 | break; | |
6703 | case bp_breakpoint: | |
6704 | if (ui_out_is_mi_like_p (uiout)) | |
6705 | { | |
6706 | say_where = 0; | |
6707 | break; | |
6708 | } | |
2cec12e5 AR |
6709 | if (b->disposition == disp_del) |
6710 | printf_filtered (_("Temporary breakpoint")); | |
6711 | else | |
6712 | printf_filtered (_("Breakpoint")); | |
6713 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6714 | say_where = 1; |
6715 | break; | |
6716 | case bp_hardware_breakpoint: | |
6717 | if (ui_out_is_mi_like_p (uiout)) | |
6718 | { | |
6719 | say_where = 0; | |
6720 | break; | |
6721 | } | |
a3f17187 | 6722 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6723 | say_where = 1; |
6724 | break; | |
1042e4c0 SS |
6725 | case bp_tracepoint: |
6726 | if (ui_out_is_mi_like_p (uiout)) | |
6727 | { | |
6728 | say_where = 0; | |
6729 | break; | |
6730 | } | |
6731 | printf_filtered (_("Tracepoint")); | |
6732 | printf_filtered (_(" %d"), b->number); | |
6733 | say_where = 1; | |
6734 | break; | |
7a697b8d SS |
6735 | case bp_fast_tracepoint: |
6736 | if (ui_out_is_mi_like_p (uiout)) | |
6737 | { | |
6738 | say_where = 0; | |
6739 | break; | |
6740 | } | |
6741 | printf_filtered (_("Fast tracepoint")); | |
6742 | printf_filtered (_(" %d"), b->number); | |
6743 | say_where = 1; | |
6744 | break; | |
0fb4aa4b PA |
6745 | case bp_static_tracepoint: |
6746 | if (ui_out_is_mi_like_p (uiout)) | |
6747 | { | |
6748 | say_where = 0; | |
6749 | break; | |
6750 | } | |
6751 | printf_filtered (_("Static tracepoint")); | |
6752 | printf_filtered (_(" %d"), b->number); | |
6753 | say_where = 1; | |
6754 | break; | |
3086aeae DJ |
6755 | |
6756 | case bp_until: | |
6757 | case bp_finish: | |
6758 | case bp_longjmp: | |
6759 | case bp_longjmp_resume: | |
6760 | case bp_step_resume: | |
3086aeae | 6761 | case bp_call_dummy: |
aa7d318d | 6762 | case bp_std_terminate: |
3086aeae DJ |
6763 | case bp_watchpoint_scope: |
6764 | case bp_shlib_event: | |
6765 | case bp_thread_event: | |
6766 | case bp_overlay_event: | |
4efc6507 | 6767 | case bp_jit_event: |
0fd8e87f | 6768 | case bp_longjmp_master: |
aa7d318d | 6769 | case bp_std_terminate_master: |
3086aeae DJ |
6770 | break; |
6771 | } | |
c906108c | 6772 | |
c906108c SS |
6773 | if (say_where) |
6774 | { | |
a3f17187 AC |
6775 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6776 | single string. */ | |
0d381245 | 6777 | if (b->loc == NULL) |
c906108c | 6778 | { |
a3f17187 | 6779 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6780 | } |
6781 | else | |
6782 | { | |
79a45b7d | 6783 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6784 | { |
6785 | printf_filtered (" at "); | |
5af949e3 UW |
6786 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6787 | gdb_stdout); | |
0101ce28 JJ |
6788 | } |
6789 | if (b->source_file) | |
6790 | printf_filtered (": file %s, line %d.", | |
6791 | b->source_file, b->line_number); | |
0d381245 VP |
6792 | |
6793 | if (b->loc->next) | |
6794 | { | |
6795 | struct bp_location *loc = b->loc; | |
6796 | int n = 0; | |
6797 | for (; loc; loc = loc->next) | |
6798 | ++n; | |
6799 | printf_filtered (" (%d locations)", n); | |
6800 | } | |
6801 | ||
c906108c | 6802 | } |
c906108c | 6803 | } |
9dc5e2a9 | 6804 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6805 | return; |
c906108c SS |
6806 | printf_filtered ("\n"); |
6807 | } | |
c906108c | 6808 | \f |
c5aa993b | 6809 | |
0d381245 | 6810 | static struct bp_location * |
39d61571 | 6811 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6812 | const struct symtab_and_line *sal) |
6813 | { | |
6814 | struct bp_location *loc, **tmp; | |
6815 | ||
39d61571 | 6816 | loc = allocate_bp_location (b); |
0d381245 VP |
6817 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6818 | ; | |
6819 | *tmp = loc; | |
a6d9a66e UW |
6820 | loc->gdbarch = get_sal_arch (*sal); |
6821 | if (!loc->gdbarch) | |
6822 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6823 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6824 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6825 | loc->requested_address, b->type); | |
6c95b8df PA |
6826 | loc->pspace = sal->pspace; |
6827 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6828 | loc->section = sal->section; |
6829 | ||
6830 | set_breakpoint_location_function (loc); | |
6831 | return loc; | |
6832 | } | |
514f746b AR |
6833 | \f |
6834 | ||
6835 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6836 | return 0 otherwise. */ | |
6837 | ||
6838 | static int | |
6839 | bp_loc_is_permanent (struct bp_location *loc) | |
6840 | { | |
6841 | int len; | |
6842 | CORE_ADDR addr; | |
6843 | const gdb_byte *brk; | |
6844 | gdb_byte *target_mem; | |
939c61fa JK |
6845 | struct cleanup *cleanup; |
6846 | int retval = 0; | |
514f746b AR |
6847 | |
6848 | gdb_assert (loc != NULL); | |
6849 | ||
6850 | addr = loc->address; | |
a6d9a66e | 6851 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6852 | |
939c61fa JK |
6853 | /* Software breakpoints unsupported? */ |
6854 | if (brk == NULL) | |
6855 | return 0; | |
6856 | ||
514f746b AR |
6857 | target_mem = alloca (len); |
6858 | ||
939c61fa JK |
6859 | /* Enable the automatic memory restoration from breakpoints while |
6860 | we read the memory. Otherwise we could say about our temporary | |
6861 | breakpoints they are permanent. */ | |
6c95b8df PA |
6862 | cleanup = save_current_space_and_thread (); |
6863 | ||
6864 | switch_to_program_space_and_thread (loc->pspace); | |
6865 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6866 | |
514f746b AR |
6867 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6868 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6869 | retval = 1; |
514f746b | 6870 | |
939c61fa JK |
6871 | do_cleanups (cleanup); |
6872 | ||
6873 | return retval; | |
514f746b AR |
6874 | } |
6875 | ||
6876 | ||
c3f6f71d | 6877 | |
018d34a4 VP |
6878 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6879 | as textual description of the location, and COND_STRING | |
db107f19 | 6880 | as condition expression. */ |
018d34a4 VP |
6881 | |
6882 | static void | |
8cdf0e15 VP |
6883 | create_breakpoint_sal (struct gdbarch *gdbarch, |
6884 | struct symtabs_and_lines sals, char *addr_string, | |
6885 | char *cond_string, | |
6886 | enum bptype type, enum bpdisp disposition, | |
6887 | int thread, int task, int ignore_count, | |
6888 | struct breakpoint_ops *ops, int from_tty, int enabled) | |
018d34a4 | 6889 | { |
0d381245 VP |
6890 | struct breakpoint *b = NULL; |
6891 | int i; | |
018d34a4 VP |
6892 | |
6893 | if (type == bp_hardware_breakpoint) | |
6894 | { | |
6895 | int i = hw_breakpoint_used_count (); | |
6896 | int target_resources_ok = | |
d92524f1 | 6897 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6898 | i + 1, 0); |
6899 | if (target_resources_ok == 0) | |
6900 | error (_("No hardware breakpoint support in the target.")); | |
6901 | else if (target_resources_ok < 0) | |
6902 | error (_("Hardware breakpoints used exceeds limit.")); | |
6903 | } | |
6904 | ||
6c95b8df PA |
6905 | gdb_assert (sals.nelts > 0); |
6906 | ||
0d381245 VP |
6907 | for (i = 0; i < sals.nelts; ++i) |
6908 | { | |
6909 | struct symtab_and_line sal = sals.sals[i]; | |
6910 | struct bp_location *loc; | |
6911 | ||
6912 | if (from_tty) | |
5af949e3 UW |
6913 | { |
6914 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6915 | if (!loc_gdbarch) | |
6916 | loc_gdbarch = gdbarch; | |
6917 | ||
6918 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6919 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6920 | } |
0d381245 VP |
6921 | |
6922 | if (i == 0) | |
6923 | { | |
a6d9a66e | 6924 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6925 | set_breakpoint_count (breakpoint_count + 1); |
6926 | b->number = breakpoint_count; | |
6927 | b->thread = thread; | |
4a306c9a | 6928 | b->task = task; |
018d34a4 | 6929 | |
0d381245 VP |
6930 | b->cond_string = cond_string; |
6931 | b->ignore_count = ignore_count; | |
41447f92 | 6932 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6933 | b->disposition = disposition; |
6c95b8df PA |
6934 | b->pspace = sals.sals[0].pspace; |
6935 | ||
0fb4aa4b PA |
6936 | if (type == bp_static_tracepoint) |
6937 | { | |
6938 | struct static_tracepoint_marker marker; | |
6939 | ||
6940 | if (is_marker_spec (addr_string)) | |
6941 | { | |
6942 | /* We already know the marker exists, otherwise, we | |
6943 | wouldn't see a sal for it. */ | |
6944 | char *p = &addr_string[3]; | |
6945 | char *endp; | |
6946 | char *marker_str; | |
6947 | int i; | |
6948 | ||
6949 | while (*p == ' ' || *p == '\t') | |
6950 | p++; | |
6951 | ||
6952 | endp = p; | |
6953 | while (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
6954 | endp++; | |
6955 | ||
6956 | marker_str = savestring (p, endp - p); | |
6957 | b->static_trace_marker_id = marker_str; | |
6958 | ||
6959 | printf_filtered (_("Probed static tracepoint marker \"%s\"\n"), | |
6960 | b->static_trace_marker_id); | |
6961 | } | |
6962 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
6963 | { | |
6964 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
6965 | release_static_tracepoint_marker (&marker); | |
6966 | ||
6967 | printf_filtered (_("Probed static tracepoint marker \"%s\"\n"), | |
6968 | b->static_trace_marker_id); | |
6969 | } | |
6970 | else | |
6971 | warning (_("\ | |
6972 | Couldn't determine the static tracepoint marker to probe")); | |
6973 | } | |
6974 | ||
6c95b8df | 6975 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
6976 | && (b->type == bp_breakpoint |
6977 | || b->type == bp_hardware_breakpoint)) | |
6978 | b->enable_state = bp_startup_disabled; | |
6979 | ||
0d381245 VP |
6980 | loc = b->loc; |
6981 | } | |
6982 | else | |
018d34a4 | 6983 | { |
39d61571 | 6984 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6985 | } |
6986 | ||
514f746b AR |
6987 | if (bp_loc_is_permanent (loc)) |
6988 | make_breakpoint_permanent (b); | |
6989 | ||
0d381245 VP |
6990 | if (b->cond_string) |
6991 | { | |
6992 | char *arg = b->cond_string; | |
d32a6982 | 6993 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6994 | if (*arg) |
db107f19 | 6995 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6996 | } |
0d381245 | 6997 | } |
018d34a4 VP |
6998 | |
6999 | if (addr_string) | |
7000 | b->addr_string = addr_string; | |
7001 | else | |
7002 | /* addr_string has to be used or breakpoint_re_set will delete | |
7003 | me. */ | |
5af949e3 UW |
7004 | b->addr_string |
7005 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7006 | |
604133b5 | 7007 | b->ops = ops; |
018d34a4 VP |
7008 | mention (b); |
7009 | } | |
7010 | ||
ed0616c6 VP |
7011 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7012 | elements to fill the void space. */ | |
2c0b251b PA |
7013 | static void |
7014 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7015 | { |
7016 | int i = index_to_remove+1; | |
7017 | int last_index = sal->nelts-1; | |
7018 | ||
7019 | for (;i <= last_index; ++i) | |
7020 | sal->sals[i-1] = sal->sals[i]; | |
7021 | ||
7022 | --(sal->nelts); | |
7023 | } | |
7024 | ||
6c95b8df PA |
7025 | /* If appropriate, obtains all sals that correspond to the same file |
7026 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7027 | will want to set a breakpoint at foo.c:line, and not really care | |
7028 | about program spaces. This is done only if SAL does not have | |
7029 | explicit PC and has line and file information. If we got just a | |
7030 | single expanded sal, return the original. | |
ed0616c6 | 7031 | |
6c95b8df PA |
7032 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7033 | which the name of enclosing function is different from SAL. This | |
7034 | makes sure that if we have breakpoint originally set in template | |
7035 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7036 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7037 | |
2c0b251b | 7038 | static struct symtabs_and_lines |
ed0616c6 VP |
7039 | expand_line_sal_maybe (struct symtab_and_line sal) |
7040 | { | |
7041 | struct symtabs_and_lines expanded; | |
7042 | CORE_ADDR original_pc = sal.pc; | |
7043 | char *original_function = NULL; | |
7044 | int found; | |
7045 | int i; | |
6c95b8df | 7046 | struct cleanup *old_chain; |
ed0616c6 VP |
7047 | |
7048 | /* If we have explicit pc, don't expand. | |
7049 | If we have no line number, we can't expand. */ | |
7050 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7051 | { | |
7052 | expanded.nelts = 1; | |
7053 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7054 | expanded.sals[0] = sal; | |
7055 | return expanded; | |
7056 | } | |
7057 | ||
7058 | sal.pc = 0; | |
6c95b8df PA |
7059 | |
7060 | old_chain = save_current_space_and_thread (); | |
7061 | ||
7062 | switch_to_program_space_and_thread (sal.pspace); | |
7063 | ||
ed0616c6 | 7064 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7065 | |
7066 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7067 | expanded = expand_line_sal (sal); |
6c95b8df | 7068 | |
ed0616c6 VP |
7069 | if (expanded.nelts == 1) |
7070 | { | |
3dba1c98 JB |
7071 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7072 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7073 | xfree (expanded.sals); |
7074 | expanded.nelts = 1; | |
7075 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7076 | sal.pc = original_pc; | |
7077 | expanded.sals[0] = sal; | |
3dba1c98 | 7078 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7079 | do_cleanups (old_chain); |
ed0616c6 VP |
7080 | return expanded; |
7081 | } | |
7082 | ||
7083 | if (!sal.explicit_line) | |
7084 | { | |
7085 | CORE_ADDR func_addr, func_end; | |
7086 | for (i = 0; i < expanded.nelts; ++i) | |
7087 | { | |
7088 | CORE_ADDR pc = expanded.sals[i].pc; | |
7089 | char *this_function; | |
6c95b8df PA |
7090 | |
7091 | /* We need to switch threads as well since we're about to | |
7092 | read memory. */ | |
7093 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7094 | ||
ed0616c6 VP |
7095 | if (find_pc_partial_function (pc, &this_function, |
7096 | &func_addr, &func_end)) | |
7097 | { | |
059fb39f PM |
7098 | if (this_function |
7099 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7100 | { |
7101 | remove_sal (&expanded, i); | |
7102 | --i; | |
7103 | } | |
ed0616c6 VP |
7104 | } |
7105 | } | |
7106 | } | |
059acae7 UW |
7107 | |
7108 | /* Skip the function prologue if necessary. */ | |
7109 | for (i = 0; i < expanded.nelts; ++i) | |
7110 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7111 | |
6c95b8df PA |
7112 | do_cleanups (old_chain); |
7113 | ||
ed0616c6 VP |
7114 | if (expanded.nelts <= 1) |
7115 | { | |
7116 | /* This is un ugly workaround. If we get zero | |
7117 | expanded sals then something is really wrong. | |
7118 | Fix that by returnign the original sal. */ | |
7119 | xfree (expanded.sals); | |
7120 | expanded.nelts = 1; | |
7121 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7122 | sal.pc = original_pc; | |
7123 | expanded.sals[0] = sal; | |
7124 | return expanded; | |
7125 | } | |
7126 | ||
7127 | if (original_pc) | |
7128 | { | |
7129 | found = 0; | |
7130 | for (i = 0; i < expanded.nelts; ++i) | |
7131 | if (expanded.sals[i].pc == original_pc) | |
7132 | { | |
7133 | found = 1; | |
7134 | break; | |
7135 | } | |
7136 | gdb_assert (found); | |
7137 | } | |
7138 | ||
7139 | return expanded; | |
7140 | } | |
7141 | ||
018d34a4 VP |
7142 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7143 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7144 | value. COND_STRING, if not NULL, specified the condition to be | |
7145 | used for all breakpoints. Essentially the only case where | |
7146 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7147 | function. In that case, it's still not possible to specify | |
7148 | separate conditions for different overloaded functions, so | |
7149 | we take just a single condition string. | |
7150 | ||
c3f6f71d | 7151 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7152 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7153 | array contents). If the function fails (error() is called), the |
7154 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
7155 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
7156 | |
7157 | static void | |
8cdf0e15 VP |
7158 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7159 | struct symtabs_and_lines sals, char **addr_string, | |
7160 | char *cond_string, | |
7161 | enum bptype type, enum bpdisp disposition, | |
7162 | int thread, int task, int ignore_count, | |
7163 | struct breakpoint_ops *ops, int from_tty, | |
7164 | int enabled) | |
c906108c | 7165 | { |
018d34a4 | 7166 | int i; |
cc59ec59 | 7167 | |
018d34a4 | 7168 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7169 | { |
ed0616c6 VP |
7170 | struct symtabs_and_lines expanded = |
7171 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7172 | |
8cdf0e15 VP |
7173 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7174 | cond_string, type, disposition, | |
7175 | thread, task, ignore_count, ops, from_tty, enabled); | |
c3f6f71d | 7176 | } |
c3f6f71d | 7177 | } |
c906108c | 7178 | |
c3f6f71d JM |
7179 | /* Parse ARG which is assumed to be a SAL specification possibly |
7180 | followed by conditionals. On return, SALS contains an array of SAL | |
7181 | addresses found. ADDR_STRING contains a vector of (canonical) | |
7182 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 7183 | |
b9362cc7 | 7184 | static void |
c3f6f71d JM |
7185 | parse_breakpoint_sals (char **address, |
7186 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7187 | char ***addr_string, |
7188 | int *not_found_ptr) | |
c3f6f71d JM |
7189 | { |
7190 | char *addr_start = *address; | |
cc59ec59 | 7191 | |
c3f6f71d JM |
7192 | *addr_string = NULL; |
7193 | /* If no arg given, or if first arg is 'if ', use the default | |
7194 | breakpoint. */ | |
7195 | if ((*address) == NULL | |
7196 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7197 | { |
7198 | if (default_breakpoint_valid) | |
7199 | { | |
c3f6f71d | 7200 | struct symtab_and_line sal; |
cc59ec59 | 7201 | |
fe39c653 | 7202 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 7203 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7204 | xmalloc (sizeof (struct symtab_and_line)); |
7205 | sal.pc = default_breakpoint_address; | |
7206 | sal.line = default_breakpoint_line; | |
7207 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7208 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7209 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
7210 | |
7211 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
7212 | the default_breakpoint_address. So make sure to set | |
7213 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
7214 | sals to include all other instances with the same symtab and line. | |
7215 | */ | |
7216 | sal.explicit_pc = 1; | |
7217 | ||
c3f6f71d JM |
7218 | sals->sals[0] = sal; |
7219 | sals->nelts = 1; | |
c906108c SS |
7220 | } |
7221 | else | |
8a3fe4f8 | 7222 | error (_("No default breakpoint address now.")); |
c906108c SS |
7223 | } |
7224 | else | |
7225 | { | |
c906108c | 7226 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
7227 | current_source_symtab (which is decode_line_1's default). This |
7228 | should produce the results we want almost all of the time while | |
1aeae86e AF |
7229 | leaving default_breakpoint_* alone. |
7230 | ObjC: However, don't match an Objective-C method name which | |
7231 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7232 | |
c214a6fd | 7233 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7234 | |
c906108c | 7235 | if (default_breakpoint_valid |
0378c332 | 7236 | && (!cursal.symtab |
1aeae86e AF |
7237 | || ((strchr ("+-", (*address)[0]) != NULL) |
7238 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7239 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7240 | default_breakpoint_line, addr_string, |
7241 | not_found_ptr); | |
c906108c | 7242 | else |
0101ce28 JJ |
7243 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7244 | addr_string, not_found_ptr); | |
c906108c | 7245 | } |
c3f6f71d JM |
7246 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7247 | if (sals->nelts > 0 && *addr_string == NULL) | |
7248 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7249 | if (addr_start != (*address)) | |
c906108c | 7250 | { |
c3f6f71d | 7251 | int i; |
cc59ec59 | 7252 | |
c3f6f71d | 7253 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7254 | { |
c3f6f71d JM |
7255 | /* Add the string if not present. */ |
7256 | if ((*addr_string)[i] == NULL) | |
cc59ec59 MS |
7257 | (*addr_string)[i] = savestring (addr_start, |
7258 | (*address) - addr_start); | |
c906108c SS |
7259 | } |
7260 | } | |
c3f6f71d | 7261 | } |
c906108c | 7262 | |
c906108c | 7263 | |
c3f6f71d JM |
7264 | /* Convert each SAL into a real PC. Verify that the PC can be |
7265 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 7266 | |
b9362cc7 | 7267 | static void |
23e7acfb | 7268 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7269 | { |
7270 | int i; | |
cc59ec59 | 7271 | |
c3f6f71d | 7272 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7273 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7274 | } |
7275 | ||
7a697b8d SS |
7276 | /* Fast tracepoints may have restrictions on valid locations. For |
7277 | instance, a fast tracepoint using a jump instead of a trap will | |
7278 | likely have to overwrite more bytes than a trap would, and so can | |
7279 | only be placed where the instruction is longer than the jump, or a | |
7280 | multi-instruction sequence does not have a jump into the middle of | |
7281 | it, etc. */ | |
7282 | ||
7283 | static void | |
7284 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7285 | struct symtabs_and_lines *sals) | |
7286 | { | |
7287 | int i, rslt; | |
7288 | struct symtab_and_line *sal; | |
7289 | char *msg; | |
7290 | struct cleanup *old_chain; | |
7291 | ||
7292 | for (i = 0; i < sals->nelts; i++) | |
7293 | { | |
7294 | sal = &sals->sals[i]; | |
7295 | ||
7296 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7297 | NULL, &msg); | |
7298 | old_chain = make_cleanup (xfree, msg); | |
7299 | ||
7300 | if (!rslt) | |
7301 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7302 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7303 | ||
7304 | do_cleanups (old_chain); | |
7305 | } | |
7306 | } | |
7307 | ||
05ff989b | 7308 | static void |
0101ce28 JJ |
7309 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7310 | { | |
7311 | struct captured_parse_breakpoint_args *args = data; | |
7312 | ||
7313 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7314 | args->not_found_ptr); | |
0101ce28 JJ |
7315 | } |
7316 | ||
018d34a4 VP |
7317 | /* Given TOK, a string specification of condition and thread, as |
7318 | accepted by the 'break' command, extract the condition | |
7319 | string and thread number and set *COND_STRING and *THREAD. | |
7320 | PC identifies the context at which the condition should be parsed. | |
7321 | If no condition is found, *COND_STRING is set to NULL. | |
7322 | If no thread is found, *THREAD is set to -1. */ | |
7323 | static void | |
7324 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7325 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7326 | { |
7327 | *cond_string = NULL; | |
7328 | *thread = -1; | |
7329 | while (tok && *tok) | |
7330 | { | |
7331 | char *end_tok; | |
7332 | int toklen; | |
7333 | char *cond_start = NULL; | |
7334 | char *cond_end = NULL; | |
cc59ec59 | 7335 | |
018d34a4 VP |
7336 | while (*tok == ' ' || *tok == '\t') |
7337 | tok++; | |
7338 | ||
7339 | end_tok = tok; | |
7340 | ||
7341 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7342 | end_tok++; | |
7343 | ||
7344 | toklen = end_tok - tok; | |
7345 | ||
7346 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7347 | { | |
f7545552 TT |
7348 | struct expression *expr; |
7349 | ||
018d34a4 | 7350 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7351 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7352 | xfree (expr); | |
018d34a4 VP |
7353 | cond_end = tok; |
7354 | *cond_string = savestring (cond_start, | |
7355 | cond_end - cond_start); | |
7356 | } | |
7357 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7358 | { | |
7359 | char *tmptok; | |
7360 | ||
7361 | tok = end_tok + 1; | |
7362 | tmptok = tok; | |
7363 | *thread = strtol (tok, &tok, 0); | |
7364 | if (tok == tmptok) | |
7365 | error (_("Junk after thread keyword.")); | |
7366 | if (!valid_thread_id (*thread)) | |
7367 | error (_("Unknown thread %d."), *thread); | |
7368 | } | |
4a306c9a JB |
7369 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7370 | { | |
7371 | char *tmptok; | |
7372 | ||
7373 | tok = end_tok + 1; | |
7374 | tmptok = tok; | |
7375 | *task = strtol (tok, &tok, 0); | |
7376 | if (tok == tmptok) | |
7377 | error (_("Junk after task keyword.")); | |
7378 | if (!valid_task_id (*task)) | |
b6199126 | 7379 | error (_("Unknown task %d."), *task); |
4a306c9a | 7380 | } |
018d34a4 VP |
7381 | else |
7382 | error (_("Junk at end of arguments.")); | |
7383 | } | |
7384 | } | |
7385 | ||
0fb4aa4b PA |
7386 | /* Decode a static tracepoint marker spec. */ |
7387 | ||
7388 | static struct symtabs_and_lines | |
7389 | decode_static_tracepoint_spec (char **arg_p) | |
7390 | { | |
7391 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7392 | struct symtabs_and_lines sals; | |
7393 | struct symtab_and_line sal; | |
7394 | struct symbol *sym; | |
7395 | struct cleanup *old_chain; | |
7396 | char *p = &(*arg_p)[3]; | |
7397 | char *endp; | |
7398 | char *marker_str; | |
7399 | int i; | |
7400 | ||
7401 | while (*p == ' ' || *p == '\t') | |
7402 | p++; | |
7403 | ||
7404 | endp = p; | |
7405 | while (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7406 | endp++; | |
7407 | ||
7408 | marker_str = savestring (p, endp - p); | |
7409 | old_chain = make_cleanup (xfree, marker_str); | |
7410 | ||
7411 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7412 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7413 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7414 | ||
7415 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7416 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7417 | ||
7418 | for (i = 0; i < sals.nelts; i++) | |
7419 | { | |
7420 | struct static_tracepoint_marker *marker; | |
7421 | ||
7422 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7423 | ||
7424 | init_sal (&sals.sals[i]); | |
7425 | ||
7426 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7427 | sals.sals[i].pc = marker->address; | |
7428 | ||
7429 | release_static_tracepoint_marker (marker); | |
7430 | } | |
7431 | ||
7432 | do_cleanups (old_chain); | |
7433 | ||
7434 | *arg_p = endp; | |
7435 | return sals; | |
7436 | } | |
7437 | ||
fd9b8c24 PA |
7438 | /* Set a breakpoint. This function is shared between CLI and MI |
7439 | functions for setting a breakpoint. This function has two major | |
7440 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7441 | parameter. If non-zero, the function will parse arg, extracting | |
7442 | breakpoint location, address and thread. Otherwise, ARG is just the | |
7443 | location of breakpoint, with condition and thread specified by the | |
7444 | COND_STRING and THREAD parameters. Returns true if any breakpoint | |
7445 | was created; false otherwise. */ | |
0101ce28 | 7446 | |
8cdf0e15 VP |
7447 | int |
7448 | create_breakpoint (struct gdbarch *gdbarch, | |
7449 | char *arg, char *cond_string, int thread, | |
7450 | int parse_condition_and_thread, | |
0fb4aa4b | 7451 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7452 | int ignore_count, |
7453 | enum auto_boolean pending_break_support, | |
7454 | struct breakpoint_ops *ops, | |
7455 | int from_tty, | |
7456 | int enabled) | |
c3f6f71d | 7457 | { |
71fff37b | 7458 | struct gdb_exception e; |
c3f6f71d | 7459 | struct symtabs_and_lines sals; |
0101ce28 | 7460 | struct symtab_and_line pending_sal; |
0101ce28 | 7461 | char *copy_arg; |
c3f6f71d JM |
7462 | char *addr_start = arg; |
7463 | char **addr_string; | |
7464 | struct cleanup *old_chain; | |
80c99de1 | 7465 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7466 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7467 | int i; |
0101ce28 | 7468 | int pending = 0; |
0101ce28 | 7469 | int not_found = 0; |
4a306c9a | 7470 | int task = 0; |
86b17b60 | 7471 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7472 | |
c3f6f71d JM |
7473 | sals.sals = NULL; |
7474 | sals.nelts = 0; | |
7475 | addr_string = NULL; | |
c3f6f71d | 7476 | |
0101ce28 JJ |
7477 | parse_args.arg_p = &arg; |
7478 | parse_args.sals_p = &sals; | |
7479 | parse_args.addr_string_p = &addr_string; | |
7480 | parse_args.not_found_ptr = ¬_found; | |
7481 | ||
0fb4aa4b PA |
7482 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7483 | { | |
7484 | int i; | |
7485 | ||
7486 | sals = decode_static_tracepoint_spec (&arg); | |
7487 | ||
7488 | copy_arg = savestring (addr_start, arg - addr_start); | |
7489 | addr_string = xcalloc (sals.nelts, sizeof (char **)); | |
7490 | for (i = 0; i < sals.nelts; i++) | |
7491 | addr_string[i] = xstrdup (copy_arg); | |
7492 | goto done; | |
7493 | } | |
7494 | ||
05ff989b AC |
7495 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7496 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7497 | |
7498 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7499 | switch (e.reason) |
0101ce28 | 7500 | { |
05ff989b | 7501 | case RETURN_QUIT: |
98deb0da | 7502 | throw_exception (e); |
05ff989b AC |
7503 | case RETURN_ERROR: |
7504 | switch (e.error) | |
0101ce28 | 7505 | { |
05ff989b | 7506 | case NOT_FOUND_ERROR: |
0101ce28 | 7507 | |
05ff989b AC |
7508 | /* If pending breakpoint support is turned off, throw |
7509 | error. */ | |
fa8d40ab JJ |
7510 | |
7511 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7512 | throw_exception (e); |
7513 | ||
7514 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7515 | |
05ff989b AC |
7516 | /* If pending breakpoint support is auto query and the user |
7517 | selects no, then simply return the error code. */ | |
059fb39f PM |
7518 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
7519 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
fd9b8c24 | 7520 | return 0; |
fa8d40ab | 7521 | |
05ff989b AC |
7522 | /* At this point, either the user was queried about setting |
7523 | a pending breakpoint and selected yes, or pending | |
7524 | breakpoint behavior is on and thus a pending breakpoint | |
7525 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7526 | copy_arg = xstrdup (addr_start); |
7527 | addr_string = ©_arg; | |
7528 | sals.nelts = 1; | |
7529 | sals.sals = &pending_sal; | |
7530 | pending_sal.pc = 0; | |
7531 | pending = 1; | |
05ff989b AC |
7532 | break; |
7533 | default: | |
98deb0da | 7534 | throw_exception (e); |
0101ce28 | 7535 | } |
05ff989b AC |
7536 | default: |
7537 | if (!sals.nelts) | |
fd9b8c24 | 7538 | return 0; |
0101ce28 | 7539 | } |
c3f6f71d | 7540 | |
0fb4aa4b PA |
7541 | done: |
7542 | ||
c3f6f71d JM |
7543 | /* Create a chain of things that always need to be cleaned up. */ |
7544 | old_chain = make_cleanup (null_cleanup, 0); | |
7545 | ||
0101ce28 JJ |
7546 | if (!pending) |
7547 | { | |
7548 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7549 | make_cleanup (xfree, sals.sals); | |
7550 | ||
7551 | /* Cleanup the addr_string array but not its contents. */ | |
7552 | make_cleanup (xfree, addr_string); | |
7553 | } | |
c3f6f71d | 7554 | |
c3f6f71d JM |
7555 | /* ----------------------------- SNIP ----------------------------- |
7556 | Anything added to the cleanup chain beyond this point is assumed | |
7557 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7558 | then the memory is not reclaimed. */ |
7559 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7560 | |
7561 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7562 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7563 | for (i = 0; i < sals.nelts; i++) |
7564 | { | |
7565 | if (addr_string[i] != NULL) | |
b8c9b27d | 7566 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7567 | } |
7568 | ||
7569 | /* Resolve all line numbers to PC's and verify that the addresses | |
7570 | are ok for the target. */ | |
0101ce28 | 7571 | if (!pending) |
23e7acfb | 7572 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7573 | |
7a697b8d SS |
7574 | /* Fast tracepoints may have additional restrictions on location. */ |
7575 | if (type_wanted == bp_fast_tracepoint) | |
7576 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7577 | ||
c3f6f71d JM |
7578 | /* Verify that condition can be parsed, before setting any |
7579 | breakpoints. Allocate a separate condition expression for each | |
7580 | breakpoint. */ | |
0101ce28 | 7581 | if (!pending) |
c3f6f71d | 7582 | { |
2f069f6f | 7583 | if (parse_condition_and_thread) |
72b2ff0e VP |
7584 | { |
7585 | /* Here we only parse 'arg' to separate condition | |
7586 | from thread number, so parsing in context of first | |
7587 | sal is OK. When setting the breakpoint we'll | |
7588 | re-parse it in context of each sal. */ | |
7589 | cond_string = NULL; | |
7590 | thread = -1; | |
4a306c9a JB |
7591 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7592 | &thread, &task); | |
72b2ff0e VP |
7593 | if (cond_string) |
7594 | make_cleanup (xfree, cond_string); | |
7595 | } | |
2f069f6f | 7596 | else |
72b2ff0e VP |
7597 | { |
7598 | /* Create a private copy of condition string. */ | |
7599 | if (cond_string) | |
7600 | { | |
7601 | cond_string = xstrdup (cond_string); | |
7602 | make_cleanup (xfree, cond_string); | |
7603 | } | |
7604 | } | |
0fb4aa4b PA |
7605 | |
7606 | /* If the user is creating a static tracepoint by marker id | |
7607 | (strace -m MARKER_ID), then store the sals index, so that | |
7608 | breakpoint_re_set can try to match up which of the newly | |
7609 | found markers corresponds to this one, and, don't try to | |
7610 | expand multiple locations for each sal, given than SALS | |
7611 | already should contain all sals for MARKER_ID. */ | |
7612 | if (type_wanted == bp_static_tracepoint | |
7613 | && is_marker_spec (addr_string[0])) | |
7614 | { | |
7615 | int i; | |
7616 | ||
7617 | for (i = 0; i < sals.nelts; ++i) | |
7618 | { | |
7619 | struct symtabs_and_lines expanded; | |
7620 | struct breakpoint *tp; | |
7621 | struct cleanup *old_chain; | |
7622 | ||
7623 | expanded.nelts = 1; | |
7624 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7625 | expanded.sals[0] = sals.sals[i]; | |
7626 | old_chain = make_cleanup (xfree, expanded.sals); | |
7627 | ||
7628 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], | |
7629 | cond_string, type_wanted, | |
7630 | tempflag ? disp_del : disp_donttouch, | |
7631 | thread, task, ignore_count, ops, | |
7632 | from_tty, enabled); | |
7633 | ||
7634 | do_cleanups (old_chain); | |
7635 | ||
7636 | /* Get the tracepoint we just created. */ | |
7637 | tp = get_breakpoint (breakpoint_count); | |
7638 | gdb_assert (tp != NULL); | |
7639 | ||
7640 | /* Given that its possible to have multiple markers with | |
7641 | the same string id, if the user is creating a static | |
7642 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7643 | store the sals index, so that breakpoint_re_set can | |
7644 | try to match up which of the newly found markers | |
7645 | corresponds to this one */ | |
7646 | tp->static_trace_marker_id_idx = i; | |
7647 | } | |
7648 | } | |
7649 | else | |
7650 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, | |
7651 | type_wanted, tempflag ? disp_del : disp_donttouch, | |
7652 | thread, task, ignore_count, ops, from_tty, | |
7653 | enabled); | |
c906108c | 7654 | } |
0101ce28 JJ |
7655 | else |
7656 | { | |
0101ce28 JJ |
7657 | struct breakpoint *b; |
7658 | ||
0101ce28 JJ |
7659 | make_cleanup (xfree, copy_arg); |
7660 | ||
a6d9a66e | 7661 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
7662 | set_breakpoint_count (breakpoint_count + 1); |
7663 | b->number = breakpoint_count; | |
72b2ff0e | 7664 | b->thread = -1; |
018d34a4 | 7665 | b->addr_string = addr_string[0]; |
72b2ff0e | 7666 | b->cond_string = NULL; |
0101ce28 | 7667 | b->ignore_count = ignore_count; |
0101ce28 | 7668 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7669 | b->condition_not_parsed = 1; |
604133b5 | 7670 | b->ops = ops; |
41447f92 | 7671 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7672 | b->pspace = current_program_space; |
74960c60 | 7673 | |
6c95b8df | 7674 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7675 | && (b->type == bp_breakpoint |
7676 | || b->type == bp_hardware_breakpoint)) | |
7677 | b->enable_state = bp_startup_disabled; | |
7678 | ||
0101ce28 JJ |
7679 | mention (b); |
7680 | } | |
7681 | ||
c3f6f71d | 7682 | if (sals.nelts > 1) |
95a42b64 TT |
7683 | { |
7684 | warning (_("Multiple breakpoints were set.\n" | |
7685 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7686 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7687 | } |
7688 | ||
80c99de1 PA |
7689 | /* That's it. Discard the cleanups for data inserted into the |
7690 | breakpoint. */ | |
7691 | discard_cleanups (bkpt_chain); | |
7692 | /* But cleanup everything else. */ | |
c3f6f71d | 7693 | do_cleanups (old_chain); |
217dc9e2 | 7694 | |
80c99de1 | 7695 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7696 | update_global_location_list (1); |
fd9b8c24 PA |
7697 | |
7698 | return 1; | |
c3f6f71d | 7699 | } |
c906108c | 7700 | |
72b2ff0e VP |
7701 | /* Set a breakpoint. |
7702 | ARG is a string describing breakpoint address, | |
7703 | condition, and thread. | |
7704 | FLAG specifies if a breakpoint is hardware on, | |
7705 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7706 | and BP_TEMPFLAG. */ | |
7707 | ||
98deb0da | 7708 | static void |
72b2ff0e | 7709 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7710 | { |
72b2ff0e | 7711 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
7712 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
7713 | ? bp_hardware_breakpoint | |
7714 | : bp_breakpoint); | |
c3f6f71d | 7715 | |
8cdf0e15 VP |
7716 | create_breakpoint (get_current_arch (), |
7717 | arg, | |
7718 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 7719 | tempflag, type_wanted, |
8cdf0e15 VP |
7720 | 0 /* Ignore count */, |
7721 | pending_break_support, | |
7722 | NULL /* breakpoint_ops */, | |
7723 | from_tty, | |
7724 | 1 /* enabled */); | |
c906108c SS |
7725 | } |
7726 | ||
72b2ff0e | 7727 | |
c906108c SS |
7728 | /* Helper function for break_command_1 and disassemble_command. */ |
7729 | ||
7730 | void | |
fba45db2 | 7731 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7732 | { |
7733 | CORE_ADDR pc; | |
7734 | ||
7735 | if (sal->pc == 0 && sal->symtab != NULL) | |
7736 | { | |
7737 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7738 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7739 | sal->line, sal->symtab->filename); |
7740 | sal->pc = pc; | |
6a048695 JB |
7741 | |
7742 | /* If this SAL corresponds to a breakpoint inserted using | |
7743 | a line number, then skip the function prologue if necessary. */ | |
7744 | if (sal->explicit_line) | |
059acae7 | 7745 | skip_prologue_sal (sal); |
c906108c SS |
7746 | } |
7747 | ||
7748 | if (sal->section == 0 && sal->symtab != NULL) | |
7749 | { | |
7750 | struct blockvector *bv; | |
c5aa993b JM |
7751 | struct block *b; |
7752 | struct symbol *sym; | |
c906108c | 7753 | |
801e3a5b | 7754 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7755 | if (bv != NULL) |
7756 | { | |
7f0df278 | 7757 | sym = block_linkage_function (b); |
c906108c SS |
7758 | if (sym != NULL) |
7759 | { | |
7760 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7761 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7762 | } |
7763 | else | |
7764 | { | |
7765 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
7766 | have to look harder. This case can be executed if we have |
7767 | line numbers but no functions (as can happen in assembly | |
7768 | source). */ | |
c906108c | 7769 | |
c5aa993b | 7770 | struct minimal_symbol *msym; |
6c95b8df PA |
7771 | struct cleanup *old_chain = save_current_space_and_thread (); |
7772 | ||
7773 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
7774 | |
7775 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7776 | if (msym) | |
714835d5 | 7777 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7778 | |
7779 | do_cleanups (old_chain); | |
c906108c SS |
7780 | } |
7781 | } | |
7782 | } | |
7783 | } | |
7784 | ||
7785 | void | |
fba45db2 | 7786 | break_command (char *arg, int from_tty) |
c906108c | 7787 | { |
db107f19 | 7788 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7789 | } |
7790 | ||
c906108c | 7791 | void |
fba45db2 | 7792 | tbreak_command (char *arg, int from_tty) |
c906108c | 7793 | { |
db107f19 | 7794 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7795 | } |
7796 | ||
c906108c | 7797 | static void |
fba45db2 | 7798 | hbreak_command (char *arg, int from_tty) |
c906108c | 7799 | { |
db107f19 | 7800 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7801 | } |
7802 | ||
7803 | static void | |
fba45db2 | 7804 | thbreak_command (char *arg, int from_tty) |
c906108c | 7805 | { |
db107f19 | 7806 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7807 | } |
7808 | ||
7809 | static void | |
fba45db2 | 7810 | stop_command (char *arg, int from_tty) |
c906108c | 7811 | { |
a3f17187 | 7812 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7813 | Usage: stop in <function | address>\n\ |
a3f17187 | 7814 | stop at <line>\n")); |
c906108c SS |
7815 | } |
7816 | ||
7817 | static void | |
fba45db2 | 7818 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7819 | { |
7820 | int badInput = 0; | |
7821 | ||
c5aa993b | 7822 | if (arg == (char *) NULL) |
c906108c SS |
7823 | badInput = 1; |
7824 | else if (*arg != '*') | |
7825 | { | |
7826 | char *argptr = arg; | |
7827 | int hasColon = 0; | |
7828 | ||
53a5351d JM |
7829 | /* look for a ':'. If this is a line number specification, then |
7830 | say it is bad, otherwise, it should be an address or | |
7831 | function/method name */ | |
c906108c | 7832 | while (*argptr && !hasColon) |
c5aa993b JM |
7833 | { |
7834 | hasColon = (*argptr == ':'); | |
7835 | argptr++; | |
7836 | } | |
c906108c SS |
7837 | |
7838 | if (hasColon) | |
c5aa993b | 7839 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7840 | else |
c5aa993b | 7841 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7842 | } |
7843 | ||
7844 | if (badInput) | |
a3f17187 | 7845 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7846 | else |
db107f19 | 7847 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7848 | } |
7849 | ||
7850 | static void | |
fba45db2 | 7851 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7852 | { |
7853 | int badInput = 0; | |
7854 | ||
c5aa993b | 7855 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7856 | badInput = 1; |
7857 | else | |
7858 | { | |
7859 | char *argptr = arg; | |
7860 | int hasColon = 0; | |
7861 | ||
7862 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7863 | it is probably a line number. */ |
c906108c | 7864 | while (*argptr && !hasColon) |
c5aa993b JM |
7865 | { |
7866 | hasColon = (*argptr == ':'); | |
7867 | argptr++; | |
7868 | } | |
c906108c SS |
7869 | |
7870 | if (hasColon) | |
c5aa993b | 7871 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7872 | else |
c5aa993b | 7873 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7874 | } |
7875 | ||
7876 | if (badInput) | |
a3f17187 | 7877 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7878 | else |
db107f19 | 7879 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7880 | } |
7881 | ||
65d79d4b SDJ |
7882 | /* Return non-zero if EXP is verified as constant. Returned zero means EXP is |
7883 | variable. Also the constant detection may fail for some constant | |
7884 | expressions and in such case still falsely return zero. */ | |
7885 | static int | |
7886 | watchpoint_exp_is_const (const struct expression *exp) | |
7887 | { | |
7888 | int i = exp->nelts; | |
7889 | ||
7890 | while (i > 0) | |
7891 | { | |
7892 | int oplenp, argsp; | |
7893 | ||
7894 | /* We are only interested in the descriptor of each element. */ | |
7895 | operator_length (exp, i, &oplenp, &argsp); | |
7896 | i -= oplenp; | |
7897 | ||
7898 | switch (exp->elts[i].opcode) | |
7899 | { | |
7900 | case BINOP_ADD: | |
7901 | case BINOP_SUB: | |
7902 | case BINOP_MUL: | |
7903 | case BINOP_DIV: | |
7904 | case BINOP_REM: | |
7905 | case BINOP_MOD: | |
7906 | case BINOP_LSH: | |
7907 | case BINOP_RSH: | |
7908 | case BINOP_LOGICAL_AND: | |
7909 | case BINOP_LOGICAL_OR: | |
7910 | case BINOP_BITWISE_AND: | |
7911 | case BINOP_BITWISE_IOR: | |
7912 | case BINOP_BITWISE_XOR: | |
7913 | case BINOP_EQUAL: | |
7914 | case BINOP_NOTEQUAL: | |
7915 | case BINOP_LESS: | |
7916 | case BINOP_GTR: | |
7917 | case BINOP_LEQ: | |
7918 | case BINOP_GEQ: | |
7919 | case BINOP_REPEAT: | |
7920 | case BINOP_COMMA: | |
7921 | case BINOP_EXP: | |
7922 | case BINOP_MIN: | |
7923 | case BINOP_MAX: | |
7924 | case BINOP_INTDIV: | |
7925 | case BINOP_CONCAT: | |
7926 | case BINOP_IN: | |
7927 | case BINOP_RANGE: | |
7928 | case TERNOP_COND: | |
7929 | case TERNOP_SLICE: | |
7930 | case TERNOP_SLICE_COUNT: | |
7931 | ||
7932 | case OP_LONG: | |
7933 | case OP_DOUBLE: | |
7934 | case OP_DECFLOAT: | |
7935 | case OP_LAST: | |
7936 | case OP_COMPLEX: | |
7937 | case OP_STRING: | |
7938 | case OP_BITSTRING: | |
7939 | case OP_ARRAY: | |
7940 | case OP_TYPE: | |
7941 | case OP_NAME: | |
7942 | case OP_OBJC_NSSTRING: | |
7943 | ||
7944 | case UNOP_NEG: | |
7945 | case UNOP_LOGICAL_NOT: | |
7946 | case UNOP_COMPLEMENT: | |
7947 | case UNOP_ADDR: | |
7948 | case UNOP_HIGH: | |
7949 | /* Unary, binary and ternary operators: We have to check their | |
7950 | operands. If they are constant, then so is the result of | |
7951 | that operation. For instance, if A and B are determined to be | |
7952 | constants, then so is "A + B". | |
7953 | ||
7954 | UNOP_IND is one exception to the rule above, because the value | |
7955 | of *ADDR is not necessarily a constant, even when ADDR is. */ | |
7956 | break; | |
7957 | ||
7958 | case OP_VAR_VALUE: | |
7959 | /* Check whether the associated symbol is a constant. | |
7960 | We use SYMBOL_CLASS rather than TYPE_CONST because it's | |
7961 | possible that a buggy compiler could mark a variable as constant | |
7962 | even when it is not, and TYPE_CONST would return true in this | |
7963 | case, while SYMBOL_CLASS wouldn't. | |
7964 | We also have to check for function symbols because they are | |
7965 | always constant. */ | |
7966 | { | |
7967 | struct symbol *s = exp->elts[i + 2].symbol; | |
7968 | ||
7969 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
7970 | && SYMBOL_CLASS (s) != LOC_CONST | |
7971 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
7972 | return 0; | |
7973 | break; | |
7974 | } | |
7975 | ||
7976 | /* The default action is to return 0 because we are using | |
7977 | the optimistic approach here: If we don't know something, | |
7978 | then it is not a constant. */ | |
7979 | default: | |
7980 | return 0; | |
7981 | } | |
7982 | } | |
7983 | ||
7984 | return 1; | |
7985 | } | |
7986 | ||
53a5351d JM |
7987 | /* accessflag: hw_write: watch write, |
7988 | hw_read: watch read, | |
7989 | hw_access: watch access (read or write) */ | |
c906108c | 7990 | static void |
06a64a0b | 7991 | watch_command_1 (char *arg, int accessflag, int from_tty, int just_location) |
c906108c | 7992 | { |
d983da9c | 7993 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 7994 | struct expression *exp; |
60e1c644 | 7995 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
c906108c SS |
7996 | struct value *val, *mark; |
7997 | struct frame_info *frame; | |
c906108c SS |
7998 | char *exp_start = NULL; |
7999 | char *exp_end = NULL; | |
37e4754d | 8000 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
8001 | int toklen; |
8002 | char *cond_start = NULL; | |
8003 | char *cond_end = NULL; | |
c906108c SS |
8004 | int i, other_type_used, target_resources_ok = 0; |
8005 | enum bptype bp_type; | |
8006 | int mem_cnt = 0; | |
37e4754d | 8007 | int thread = -1; |
0cf6dd15 | 8008 | int pc = 0; |
c906108c | 8009 | |
37e4754d LM |
8010 | /* Make sure that we actually have parameters to parse. */ |
8011 | if (arg != NULL && arg[0] != '\0') | |
8012 | { | |
8013 | toklen = strlen (arg); /* Size of argument list. */ | |
8014 | ||
8015 | /* Points tok to the end of the argument list. */ | |
8016 | tok = arg + toklen - 1; | |
8017 | ||
8018 | /* Go backwards in the parameters list. Skip the last parameter. | |
8019 | If we're expecting a 'thread <thread_num>' parameter, this should | |
8020 | be the thread identifier. */ | |
8021 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
8022 | tok--; | |
8023 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8024 | tok--; | |
8025 | ||
8026 | /* Points end_tok to the beginning of the last token. */ | |
8027 | id_tok_start = tok + 1; | |
8028 | ||
8029 | /* Go backwards in the parameters list. Skip one more parameter. | |
8030 | If we're expecting a 'thread <thread_num>' parameter, we should | |
8031 | reach a "thread" token. */ | |
8032 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
8033 | tok--; | |
8034 | ||
8035 | end_tok = tok; | |
8036 | ||
8037 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8038 | tok--; | |
8039 | ||
8040 | /* Move the pointer forward to skip the whitespace and | |
8041 | calculate the length of the token. */ | |
8042 | tok++; | |
8043 | toklen = end_tok - tok; | |
8044 | ||
8045 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8046 | { | |
8047 | /* At this point we've found a "thread" token, which means | |
8048 | the user is trying to set a watchpoint that triggers | |
8049 | only in a specific thread. */ | |
8050 | char *endp; | |
8051 | ||
8052 | /* Extract the thread ID from the next token. */ | |
8053 | thread = strtol (id_tok_start, &endp, 0); | |
8054 | ||
8055 | /* Check if the user provided a valid numeric value for the | |
8056 | thread ID. */ | |
8057 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
8058 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
8059 | ||
8060 | /* Check if the thread actually exists. */ | |
8061 | if (!valid_thread_id (thread)) | |
8062 | error (_("Unknown thread %d."), thread); | |
8063 | ||
8064 | /* Truncate the string and get rid of the thread <thread_num> | |
8065 | parameter before the parameter list is parsed by the | |
8066 | evaluate_expression() function. */ | |
8067 | *tok = '\0'; | |
8068 | } | |
8069 | } | |
8070 | ||
8071 | /* Parse the rest of the arguments. */ | |
c906108c SS |
8072 | innermost_block = NULL; |
8073 | exp_start = arg; | |
8074 | exp = parse_exp_1 (&arg, 0, 0); | |
8075 | exp_end = arg; | |
fa8a61dc TT |
8076 | /* Remove trailing whitespace from the expression before saving it. |
8077 | This makes the eventual display of the expression string a bit | |
8078 | prettier. */ | |
8079 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
8080 | --exp_end; | |
8081 | ||
65d79d4b SDJ |
8082 | /* Checking if the expression is not constant. */ |
8083 | if (watchpoint_exp_is_const (exp)) | |
8084 | { | |
8085 | int len; | |
8086 | ||
8087 | len = exp_end - exp_start; | |
8088 | while (len > 0 && isspace (exp_start[len - 1])) | |
8089 | len--; | |
8090 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
8091 | } | |
8092 | ||
c906108c SS |
8093 | exp_valid_block = innermost_block; |
8094 | mark = value_mark (); | |
0cf6dd15 | 8095 | fetch_subexp_value (exp, &pc, &val, NULL, NULL); |
06a64a0b TT |
8096 | |
8097 | if (just_location) | |
8098 | { | |
8099 | exp_valid_block = NULL; | |
8100 | val = value_addr (val); | |
8101 | release_value (val); | |
8102 | value_free_to_mark (mark); | |
8103 | } | |
8104 | else if (val != NULL) | |
fa4727a6 | 8105 | release_value (val); |
c906108c SS |
8106 | |
8107 | tok = arg; | |
8108 | while (*tok == ' ' || *tok == '\t') | |
8109 | tok++; | |
8110 | end_tok = tok; | |
8111 | ||
8112 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
8113 | end_tok++; | |
8114 | ||
8115 | toklen = end_tok - tok; | |
8116 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8117 | { | |
2d134ed3 PA |
8118 | struct expression *cond; |
8119 | ||
60e1c644 | 8120 | innermost_block = NULL; |
c906108c SS |
8121 | tok = cond_start = end_tok + 1; |
8122 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
8123 | |
8124 | /* The watchpoint expression may not be local, but the condition | |
8125 | may still be. E.g.: `watch global if local > 0'. */ | |
8126 | cond_exp_valid_block = innermost_block; | |
8127 | ||
2d134ed3 | 8128 | xfree (cond); |
c906108c SS |
8129 | cond_end = tok; |
8130 | } | |
8131 | if (*tok) | |
8a3fe4f8 | 8132 | error (_("Junk at end of command.")); |
c906108c | 8133 | |
53a5351d | 8134 | if (accessflag == hw_read) |
c5aa993b | 8135 | bp_type = bp_read_watchpoint; |
53a5351d | 8136 | else if (accessflag == hw_access) |
c5aa993b JM |
8137 | bp_type = bp_access_watchpoint; |
8138 | else | |
8139 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
8140 | |
8141 | mem_cnt = can_use_hardware_watchpoint (val); | |
8142 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 8143 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
8144 | if (mem_cnt != 0) |
8145 | { | |
8146 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 8147 | target_resources_ok = |
d92524f1 | 8148 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 8149 | other_type_used); |
c5aa993b | 8150 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8151 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 8152 | |
c5aa993b | 8153 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8154 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 8155 | } |
c906108c | 8156 | |
4d28f7a8 KB |
8157 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
8158 | watchpoint could not be set. */ | |
8159 | if (!mem_cnt || target_resources_ok <= 0) | |
8160 | bp_type = bp_watchpoint; | |
8161 | ||
d983da9c | 8162 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
8163 | |
8164 | /* If the expression is "local", then set up a "watchpoint scope" | |
8165 | breakpoint at the point where we've left the scope of the watchpoint | |
8166 | expression. Create the scope breakpoint before the watchpoint, so | |
8167 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 8168 | if (exp_valid_block && frame) |
d983da9c | 8169 | { |
edb3359d DJ |
8170 | if (frame_id_p (frame_unwind_caller_id (frame))) |
8171 | { | |
8172 | scope_breakpoint | |
a6d9a66e UW |
8173 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
8174 | frame_unwind_caller_pc (frame), | |
edb3359d | 8175 | bp_watchpoint_scope); |
d983da9c | 8176 | |
edb3359d | 8177 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 8178 | |
edb3359d DJ |
8179 | /* Automatically delete the breakpoint when it hits. */ |
8180 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 8181 | |
edb3359d DJ |
8182 | /* Only break in the proper frame (help with recursion). */ |
8183 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 8184 | |
edb3359d | 8185 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
8186 | scope_breakpoint->loc->gdbarch |
8187 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
8188 | scope_breakpoint->loc->requested_address |
8189 | = frame_unwind_caller_pc (frame); | |
8190 | scope_breakpoint->loc->address | |
a6d9a66e UW |
8191 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
8192 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
8193 | scope_breakpoint->type); |
8194 | } | |
d983da9c DJ |
8195 | } |
8196 | ||
c906108c | 8197 | /* Now set up the breakpoint. */ |
2d134ed3 | 8198 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
8199 | set_breakpoint_count (breakpoint_count + 1); |
8200 | b->number = breakpoint_count; | |
37e4754d | 8201 | b->thread = thread; |
b5de0fa7 | 8202 | b->disposition = disp_donttouch; |
c906108c SS |
8203 | b->exp = exp; |
8204 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 8205 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
8206 | if (just_location) |
8207 | { | |
8208 | struct type *t = value_type (val); | |
8209 | CORE_ADDR addr = value_as_address (val); | |
8210 | char *name; | |
8211 | ||
8212 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
8213 | name = type_to_string (t); | |
8214 | ||
d63d0675 JK |
8215 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
8216 | core_addr_to_string (addr)); | |
06a64a0b TT |
8217 | xfree (name); |
8218 | ||
d63d0675 JK |
8219 | b->exp_string = xstrprintf ("-location: %.*s", |
8220 | (int) (exp_end - exp_start), exp_start); | |
8221 | ||
06a64a0b TT |
8222 | /* The above expression is in C. */ |
8223 | b->language = language_c; | |
8224 | } | |
8225 | else | |
8226 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
c906108c | 8227 | b->val = val; |
fa4727a6 | 8228 | b->val_valid = 1; |
c906108c SS |
8229 | if (cond_start) |
8230 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
8231 | else | |
8232 | b->cond_string = 0; | |
c5aa993b | 8233 | |
c906108c | 8234 | if (frame) |
f6bc2008 PA |
8235 | { |
8236 | b->watchpoint_frame = get_frame_id (frame); | |
8237 | b->watchpoint_thread = inferior_ptid; | |
8238 | } | |
c906108c | 8239 | else |
f6bc2008 PA |
8240 | { |
8241 | b->watchpoint_frame = null_frame_id; | |
8242 | b->watchpoint_thread = null_ptid; | |
8243 | } | |
c906108c | 8244 | |
d983da9c | 8245 | if (scope_breakpoint != NULL) |
c906108c | 8246 | { |
d983da9c DJ |
8247 | /* The scope breakpoint is related to the watchpoint. We will |
8248 | need to act on them together. */ | |
8249 | b->related_breakpoint = scope_breakpoint; | |
8250 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 8251 | } |
d983da9c | 8252 | |
06a64a0b TT |
8253 | if (!just_location) |
8254 | value_free_to_mark (mark); | |
2d134ed3 PA |
8255 | |
8256 | /* Finally update the new watchpoint. This creates the locations | |
8257 | that should be inserted. */ | |
8258 | update_watchpoint (b, 1); | |
8259 | ||
c906108c | 8260 | mention (b); |
b60e7edf | 8261 | update_global_location_list (1); |
c906108c SS |
8262 | } |
8263 | ||
8264 | /* Return count of locations need to be watched and can be handled | |
8265 | in hardware. If the watchpoint can not be handled | |
8266 | in hardware return zero. */ | |
8267 | ||
c906108c | 8268 | static int |
fba45db2 | 8269 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
8270 | { |
8271 | int found_memory_cnt = 0; | |
2e70b7b9 | 8272 | struct value *head = v; |
c906108c SS |
8273 | |
8274 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 8275 | if (!can_use_hw_watchpoints) |
c906108c | 8276 | return 0; |
c5aa993b | 8277 | |
5c44784c JM |
8278 | /* Make sure that the value of the expression depends only upon |
8279 | memory contents, and values computed from them within GDB. If we | |
8280 | find any register references or function calls, we can't use a | |
8281 | hardware watchpoint. | |
8282 | ||
8283 | The idea here is that evaluating an expression generates a series | |
8284 | of values, one holding the value of every subexpression. (The | |
8285 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
8286 | a*b+c.) GDB's values hold almost enough information to establish | |
8287 | the criteria given above --- they identify memory lvalues, | |
8288 | register lvalues, computed values, etcetera. So we can evaluate | |
8289 | the expression, and then scan the chain of values that leaves | |
8290 | behind to decide whether we can detect any possible change to the | |
8291 | expression's final value using only hardware watchpoints. | |
8292 | ||
8293 | However, I don't think that the values returned by inferior | |
8294 | function calls are special in any way. So this function may not | |
8295 | notice that an expression involving an inferior function call | |
8296 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 8297 | for (; v; v = value_next (v)) |
c906108c | 8298 | { |
5c44784c | 8299 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 8300 | { |
d69fe07e | 8301 | if (value_lazy (v)) |
5c44784c JM |
8302 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
8303 | we either just used its address (e.g., `a' in `a.b') or | |
8304 | we never needed it at all (e.g., `a' in `a,b'). */ | |
8305 | ; | |
53a5351d | 8306 | else |
5c44784c JM |
8307 | { |
8308 | /* Ahh, memory we actually used! Check if we can cover | |
8309 | it with hardware watchpoints. */ | |
df407dfe | 8310 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
8311 | |
8312 | /* We only watch structs and arrays if user asked for it | |
8313 | explicitly, never if they just happen to appear in a | |
8314 | middle of some value chain. */ | |
8315 | if (v == head | |
8316 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
8317 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
8318 | { | |
42ae5230 | 8319 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 8320 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 8321 | |
d92524f1 | 8322 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
8323 | return 0; |
8324 | else | |
8325 | found_memory_cnt++; | |
8326 | } | |
5c44784c | 8327 | } |
c5aa993b | 8328 | } |
5086187c AC |
8329 | else if (VALUE_LVAL (v) != not_lval |
8330 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 8331 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 8332 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 8333 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
8334 | } |
8335 | ||
8336 | /* The expression itself looks suitable for using a hardware | |
8337 | watchpoint, but give the target machine a chance to reject it. */ | |
8338 | return found_memory_cnt; | |
8339 | } | |
8340 | ||
8b93c638 | 8341 | void |
fba45db2 | 8342 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 | 8343 | { |
06a64a0b TT |
8344 | watch_command_1 (arg, hw_write, from_tty, 0); |
8345 | } | |
8346 | ||
8347 | /* A helper function that looks for an argument at the start of a | |
8348 | string. The argument must also either be at the end of the string, | |
8349 | or be followed by whitespace. Returns 1 if it finds the argument, | |
8350 | 0 otherwise. If the argument is found, it updates *STR. */ | |
8351 | ||
8352 | static int | |
8353 | check_for_argument (char **str, char *arg, int arg_len) | |
8354 | { | |
8355 | if (strncmp (*str, arg, arg_len) == 0 | |
8356 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
8357 | { | |
8358 | *str += arg_len; | |
8359 | return 1; | |
8360 | } | |
8361 | return 0; | |
8362 | } | |
8363 | ||
8364 | /* A helper function that looks for the "-location" argument and then | |
8365 | calls watch_command_1. */ | |
8366 | ||
8367 | static void | |
8368 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
8369 | { | |
8370 | int just_location = 0; | |
8371 | ||
8372 | if (arg | |
8373 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
8374 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
8375 | { | |
8376 | ep_skip_leading_whitespace (&arg); | |
8377 | just_location = 1; | |
8378 | } | |
8379 | ||
8380 | watch_command_1 (arg, accessflag, from_tty, just_location); | |
8b93c638 | 8381 | } |
8926118c | 8382 | |
c5aa993b | 8383 | static void |
fba45db2 | 8384 | watch_command (char *arg, int from_tty) |
c906108c | 8385 | { |
06a64a0b | 8386 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
8387 | } |
8388 | ||
8b93c638 | 8389 | void |
fba45db2 | 8390 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 | 8391 | { |
06a64a0b | 8392 | watch_command_1 (arg, hw_read, from_tty, 0); |
8b93c638 | 8393 | } |
8926118c | 8394 | |
c5aa993b | 8395 | static void |
fba45db2 | 8396 | rwatch_command (char *arg, int from_tty) |
c906108c | 8397 | { |
06a64a0b | 8398 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
8399 | } |
8400 | ||
8b93c638 | 8401 | void |
fba45db2 | 8402 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 | 8403 | { |
06a64a0b | 8404 | watch_command_1 (arg, hw_access, from_tty, 0); |
8b93c638 | 8405 | } |
8926118c | 8406 | |
c5aa993b | 8407 | static void |
fba45db2 | 8408 | awatch_command (char *arg, int from_tty) |
c906108c | 8409 | { |
06a64a0b | 8410 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 8411 | } |
c906108c | 8412 | \f |
c5aa993b | 8413 | |
43ff13b4 | 8414 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8415 | because it uses the mechanisms of breakpoints. */ |
8416 | ||
bfec99b2 PA |
8417 | struct until_break_command_continuation_args |
8418 | { | |
8419 | struct breakpoint *breakpoint; | |
8420 | struct breakpoint *breakpoint2; | |
8421 | }; | |
8422 | ||
43ff13b4 JM |
8423 | /* This function is called by fetch_inferior_event via the |
8424 | cmd_continuation pointer, to complete the until command. It takes | |
8425 | care of cleaning up the temporary breakpoints set up by the until | |
8426 | command. */ | |
c2c6d25f | 8427 | static void |
604ead4a | 8428 | until_break_command_continuation (void *arg) |
43ff13b4 | 8429 | { |
bfec99b2 PA |
8430 | struct until_break_command_continuation_args *a = arg; |
8431 | ||
8432 | delete_breakpoint (a->breakpoint); | |
8433 | if (a->breakpoint2) | |
8434 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
8435 | } |
8436 | ||
c906108c | 8437 | void |
ae66c1fc | 8438 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8439 | { |
8440 | struct symtabs_and_lines sals; | |
8441 | struct symtab_and_line sal; | |
206415a3 | 8442 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8443 | struct breakpoint *breakpoint; |
f107f563 | 8444 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
8445 | struct cleanup *old_chain; |
8446 | ||
8447 | clear_proceed_status (); | |
8448 | ||
8449 | /* Set a breakpoint where the user wants it and at return from | |
8450 | this function */ | |
c5aa993b | 8451 | |
c906108c SS |
8452 | if (default_breakpoint_valid) |
8453 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 8454 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 8455 | else |
53a5351d | 8456 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 8457 | 0, (char ***) NULL, NULL); |
c5aa993b | 8458 | |
c906108c | 8459 | if (sals.nelts != 1) |
8a3fe4f8 | 8460 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8461 | |
c906108c | 8462 | sal = sals.sals[0]; |
b8c9b27d | 8463 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 8464 | |
c906108c | 8465 | if (*arg) |
8a3fe4f8 | 8466 | error (_("Junk at end of arguments.")); |
c5aa993b | 8467 | |
c906108c | 8468 | resolve_sal_pc (&sal); |
c5aa993b | 8469 | |
ae66c1fc EZ |
8470 | if (anywhere) |
8471 | /* If the user told us to continue until a specified location, | |
8472 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8473 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8474 | null_frame_id, bp_until); | |
ae66c1fc | 8475 | else |
edb3359d | 8476 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 8477 | at the very same frame. */ |
a6d9a66e UW |
8478 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8479 | get_stack_frame_id (frame), | |
ae66c1fc | 8480 | bp_until); |
c5aa993b | 8481 | |
f107f563 | 8482 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8483 | |
ae66c1fc EZ |
8484 | /* Keep within the current frame, or in frames called by the current |
8485 | one. */ | |
edb3359d DJ |
8486 | |
8487 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8488 | { |
edb3359d DJ |
8489 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8490 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8491 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8492 | sal, | |
edb3359d | 8493 | frame_unwind_caller_id (frame), |
f107f563 VP |
8494 | bp_until); |
8495 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 8496 | } |
c5aa993b | 8497 | |
c906108c | 8498 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
8499 | |
8500 | /* If we are running asynchronously, and proceed call above has actually | |
8501 | managed to start the target, arrange for breakpoints to be | |
8502 | deleted when the target stops. Otherwise, we're already stopped and | |
8503 | delete breakpoints via cleanup chain. */ | |
8504 | ||
8ea051c5 | 8505 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8506 | { |
bfec99b2 PA |
8507 | struct until_break_command_continuation_args *args; |
8508 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8509 | |
bfec99b2 PA |
8510 | args->breakpoint = breakpoint; |
8511 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
8512 | |
8513 | discard_cleanups (old_chain); | |
95e54da7 PA |
8514 | add_continuation (inferior_thread (), |
8515 | until_break_command_continuation, args, | |
604ead4a | 8516 | xfree); |
f107f563 VP |
8517 | } |
8518 | else | |
c5aa993b | 8519 | do_cleanups (old_chain); |
c906108c | 8520 | } |
ae66c1fc | 8521 | |
c906108c | 8522 | static void |
fba45db2 | 8523 | ep_skip_leading_whitespace (char **s) |
c906108c | 8524 | { |
c5aa993b JM |
8525 | if ((s == NULL) || (*s == NULL)) |
8526 | return; | |
8527 | while (isspace (**s)) | |
8528 | *s += 1; | |
c906108c | 8529 | } |
c5aa993b | 8530 | |
c906108c SS |
8531 | /* This function attempts to parse an optional "if <cond>" clause |
8532 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8533 | |
c906108c SS |
8534 | Else, it returns a pointer to the condition string. (It does not |
8535 | attempt to evaluate the string against a particular block.) And, | |
8536 | it updates arg to point to the first character following the parsed | |
8537 | if clause in the arg string. */ | |
53a5351d | 8538 | |
c906108c | 8539 | static char * |
fba45db2 | 8540 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8541 | { |
c5aa993b JM |
8542 | char *cond_string; |
8543 | ||
8544 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8545 | return NULL; |
c5aa993b | 8546 | |
c906108c SS |
8547 | /* Skip the "if" keyword. */ |
8548 | (*arg) += 2; | |
c5aa993b | 8549 | |
c906108c SS |
8550 | /* Skip any extra leading whitespace, and record the start of the |
8551 | condition string. */ | |
8552 | ep_skip_leading_whitespace (arg); | |
8553 | cond_string = *arg; | |
c5aa993b | 8554 | |
c906108c SS |
8555 | /* Assume that the condition occupies the remainder of the arg string. */ |
8556 | (*arg) += strlen (cond_string); | |
c5aa993b | 8557 | |
c906108c SS |
8558 | return cond_string; |
8559 | } | |
c5aa993b | 8560 | |
c906108c SS |
8561 | /* Commands to deal with catching events, such as signals, exceptions, |
8562 | process start/exit, etc. */ | |
c5aa993b JM |
8563 | |
8564 | typedef enum | |
8565 | { | |
44feb3ce TT |
8566 | catch_fork_temporary, catch_vfork_temporary, |
8567 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8568 | } |
8569 | catch_fork_kind; | |
8570 | ||
c906108c | 8571 | static void |
cc59ec59 MS |
8572 | catch_fork_command_1 (char *arg, int from_tty, |
8573 | struct cmd_list_element *command) | |
c906108c | 8574 | { |
a6d9a66e | 8575 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8576 | char *cond_string = NULL; |
44feb3ce TT |
8577 | catch_fork_kind fork_kind; |
8578 | int tempflag; | |
8579 | ||
8580 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8581 | tempflag = (fork_kind == catch_fork_temporary | |
8582 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8583 | |
44feb3ce TT |
8584 | if (!arg) |
8585 | arg = ""; | |
c906108c | 8586 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8587 | |
c906108c | 8588 | /* The allowed syntax is: |
c5aa993b JM |
8589 | catch [v]fork |
8590 | catch [v]fork if <cond> | |
8591 | ||
c906108c SS |
8592 | First, check if there's an if clause. */ |
8593 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 8594 | |
c906108c | 8595 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 8596 | error (_("Junk at end of arguments.")); |
c5aa993b | 8597 | |
c906108c SS |
8598 | /* If this target supports it, create a fork or vfork catchpoint |
8599 | and enable reporting of such events. */ | |
c5aa993b JM |
8600 | switch (fork_kind) |
8601 | { | |
44feb3ce TT |
8602 | case catch_fork_temporary: |
8603 | case catch_fork_permanent: | |
a6d9a66e | 8604 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8605 | &catch_fork_breakpoint_ops); |
c906108c | 8606 | break; |
44feb3ce TT |
8607 | case catch_vfork_temporary: |
8608 | case catch_vfork_permanent: | |
a6d9a66e | 8609 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8610 | &catch_vfork_breakpoint_ops); |
c906108c | 8611 | break; |
c5aa993b | 8612 | default: |
8a3fe4f8 | 8613 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 8614 | break; |
c5aa993b | 8615 | } |
c906108c SS |
8616 | } |
8617 | ||
8618 | static void | |
cc59ec59 MS |
8619 | catch_exec_command_1 (char *arg, int from_tty, |
8620 | struct cmd_list_element *command) | |
c906108c | 8621 | { |
a6d9a66e | 8622 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8623 | int tempflag; |
c5aa993b | 8624 | char *cond_string = NULL; |
c906108c | 8625 | |
44feb3ce TT |
8626 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8627 | ||
8628 | if (!arg) | |
8629 | arg = ""; | |
c906108c SS |
8630 | ep_skip_leading_whitespace (&arg); |
8631 | ||
8632 | /* The allowed syntax is: | |
c5aa993b JM |
8633 | catch exec |
8634 | catch exec if <cond> | |
c906108c SS |
8635 | |
8636 | First, check if there's an if clause. */ | |
8637 | cond_string = ep_parse_optional_if_clause (&arg); | |
8638 | ||
8639 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8640 | error (_("Junk at end of arguments.")); |
c906108c SS |
8641 | |
8642 | /* If this target supports it, create an exec catchpoint | |
8643 | and enable reporting of such events. */ | |
a6d9a66e UW |
8644 | create_catchpoint (gdbarch, tempflag, cond_string, |
8645 | &catch_exec_breakpoint_ops); | |
c906108c | 8646 | } |
c5aa993b | 8647 | |
3086aeae DJ |
8648 | static enum print_stop_action |
8649 | print_exception_catchpoint (struct breakpoint *b) | |
8650 | { | |
ade92717 | 8651 | int bp_temp, bp_throw; |
3086aeae | 8652 | |
ade92717 | 8653 | annotate_catchpoint (b->number); |
3086aeae | 8654 | |
ade92717 AR |
8655 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8656 | if (b->loc->address != b->loc->requested_address) | |
8657 | breakpoint_adjustment_warning (b->loc->requested_address, | |
8658 | b->loc->address, | |
8659 | b->number, 1); | |
df2b6d2d | 8660 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8661 | ui_out_text (uiout, |
8662 | bp_temp ? "Temporary catchpoint " | |
8663 | : "Catchpoint "); | |
8664 | if (!ui_out_is_mi_like_p (uiout)) | |
8665 | ui_out_field_int (uiout, "bkptno", b->number); | |
8666 | ui_out_text (uiout, | |
c0b37c48 AR |
8667 | bp_throw ? " (exception thrown), " |
8668 | : " (exception caught), "); | |
ade92717 AR |
8669 | if (ui_out_is_mi_like_p (uiout)) |
8670 | { | |
8671 | ui_out_field_string (uiout, "reason", | |
8672 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8673 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8674 | ui_out_field_int (uiout, "bkptno", b->number); | |
8675 | } | |
3086aeae DJ |
8676 | return PRINT_SRC_AND_LOC; |
8677 | } | |
8678 | ||
8679 | static void | |
cc59ec59 MS |
8680 | print_one_exception_catchpoint (struct breakpoint *b, |
8681 | struct bp_location **last_loc) | |
3086aeae | 8682 | { |
79a45b7d | 8683 | struct value_print_options opts; |
cc59ec59 | 8684 | |
79a45b7d TT |
8685 | get_user_print_options (&opts); |
8686 | if (opts.addressprint) | |
3086aeae DJ |
8687 | { |
8688 | annotate_field (4); | |
604133b5 AR |
8689 | if (b->loc == NULL || b->loc->shlib_disabled) |
8690 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
8691 | else | |
5af949e3 UW |
8692 | ui_out_field_core_addr (uiout, "addr", |
8693 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
8694 | } |
8695 | annotate_field (5); | |
604133b5 | 8696 | if (b->loc) |
a6d9a66e | 8697 | *last_loc = b->loc; |
3086aeae DJ |
8698 | if (strstr (b->addr_string, "throw") != NULL) |
8699 | ui_out_field_string (uiout, "what", "exception throw"); | |
8700 | else | |
8701 | ui_out_field_string (uiout, "what", "exception catch"); | |
8702 | } | |
8703 | ||
8704 | static void | |
8705 | print_mention_exception_catchpoint (struct breakpoint *b) | |
8706 | { | |
ade92717 AR |
8707 | int bp_temp; |
8708 | int bp_throw; | |
8709 | ||
df2b6d2d | 8710 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8711 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8712 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
8713 | : _("Catchpoint ")); | |
8714 | ui_out_field_int (uiout, "bkptno", b->number); | |
8715 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
8716 | : _(" (catch)")); | |
3086aeae DJ |
8717 | } |
8718 | ||
6149aea9 PA |
8719 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
8720 | catch catchpoints. */ | |
8721 | ||
8722 | static void | |
8723 | print_recreate_exception_catchpoint (struct breakpoint *b, struct ui_file *fp) | |
8724 | { | |
8725 | int bp_temp; | |
8726 | int bp_throw; | |
8727 | ||
8728 | bp_temp = b->disposition == disp_del; | |
8729 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
8730 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
8731 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
8732 | } | |
8733 | ||
3086aeae | 8734 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
8735 | NULL, /* insert */ |
8736 | NULL, /* remove */ | |
8737 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
8738 | print_exception_catchpoint, |
8739 | print_one_exception_catchpoint, | |
6149aea9 PA |
8740 | print_mention_exception_catchpoint, |
8741 | print_recreate_exception_catchpoint | |
3086aeae DJ |
8742 | }; |
8743 | ||
8744 | static int | |
8745 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
8746 | enum exception_event_kind ex_event, int from_tty) | |
8747 | { | |
604133b5 AR |
8748 | char *trigger_func_name; |
8749 | ||
3086aeae | 8750 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 8751 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 8752 | else |
604133b5 | 8753 | trigger_func_name = "__cxa_throw"; |
3086aeae | 8754 | |
8cdf0e15 VP |
8755 | create_breakpoint (get_current_arch (), |
8756 | trigger_func_name, cond_string, -1, | |
8757 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 8758 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
8759 | 0, |
8760 | AUTO_BOOLEAN_TRUE /* pending */, | |
8761 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
8762 | 1 /* enabled */); | |
3086aeae | 8763 | |
3086aeae DJ |
8764 | return 1; |
8765 | } | |
8766 | ||
c5aa993b | 8767 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
8768 | |
8769 | static void | |
fba45db2 KB |
8770 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
8771 | int tempflag, int from_tty) | |
c906108c | 8772 | { |
c5aa993b | 8773 | char *cond_string = NULL; |
c5aa993b | 8774 | |
44feb3ce TT |
8775 | if (!arg) |
8776 | arg = ""; | |
c906108c | 8777 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8778 | |
c906108c SS |
8779 | cond_string = ep_parse_optional_if_clause (&arg); |
8780 | ||
8781 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8782 | error (_("Junk at end of arguments.")); |
c906108c | 8783 | |
059fb39f PM |
8784 | if (ex_event != EX_EVENT_THROW |
8785 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 8786 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 8787 | |
3086aeae DJ |
8788 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
8789 | return; | |
8790 | ||
8a3fe4f8 | 8791 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
8792 | } |
8793 | ||
44feb3ce TT |
8794 | /* Implementation of "catch catch" command. */ |
8795 | ||
8796 | static void | |
8797 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8798 | { | |
8799 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 8800 | |
44feb3ce TT |
8801 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
8802 | } | |
8803 | ||
8804 | /* Implementation of "catch throw" command. */ | |
8805 | ||
8806 | static void | |
8807 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8808 | { | |
8809 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 8810 | |
44feb3ce TT |
8811 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
8812 | } | |
8813 | ||
f7f9143b JB |
8814 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
8815 | ||
8816 | static void | |
a6d9a66e UW |
8817 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
8818 | struct symtab_and_line sal, | |
f7f9143b JB |
8819 | char *addr_string, |
8820 | char *exp_string, | |
8821 | char *cond_string, | |
8822 | struct expression *cond, | |
8823 | struct breakpoint_ops *ops, | |
8824 | int tempflag, | |
8825 | int from_tty) | |
8826 | { | |
8827 | struct breakpoint *b; | |
8828 | ||
8829 | if (from_tty) | |
8830 | { | |
5af949e3 UW |
8831 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
8832 | if (!loc_gdbarch) | |
8833 | loc_gdbarch = gdbarch; | |
8834 | ||
6c95b8df PA |
8835 | describe_other_breakpoints (loc_gdbarch, |
8836 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
8837 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
8838 | version for exception catchpoints, because two catchpoints | |
8839 | used for different exception names will use the same address. | |
8840 | In this case, a "breakpoint ... also set at..." warning is | |
8841 | unproductive. Besides. the warning phrasing is also a bit | |
8842 | inapropriate, we should use the word catchpoint, and tell | |
8843 | the user what type of catchpoint it is. The above is good | |
8844 | enough for now, though. */ | |
8845 | } | |
8846 | ||
a6d9a66e | 8847 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
8848 | set_breakpoint_count (breakpoint_count + 1); |
8849 | ||
8850 | b->enable_state = bp_enabled; | |
8851 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
8852 | b->number = breakpoint_count; | |
8853 | b->ignore_count = 0; | |
511a6cd4 | 8854 | b->loc->cond = cond; |
f7f9143b JB |
8855 | b->addr_string = addr_string; |
8856 | b->language = language_ada; | |
8857 | b->cond_string = cond_string; | |
8858 | b->exp_string = exp_string; | |
8859 | b->thread = -1; | |
8860 | b->ops = ops; | |
f7f9143b JB |
8861 | |
8862 | mention (b); | |
b60e7edf | 8863 | update_global_location_list (1); |
f7f9143b JB |
8864 | } |
8865 | ||
8866 | /* Implement the "catch exception" command. */ | |
8867 | ||
8868 | static void | |
44feb3ce TT |
8869 | catch_ada_exception_command (char *arg, int from_tty, |
8870 | struct cmd_list_element *command) | |
f7f9143b | 8871 | { |
a6d9a66e | 8872 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8873 | int tempflag; |
f7f9143b | 8874 | struct symtab_and_line sal; |
f7f9143b JB |
8875 | char *addr_string = NULL; |
8876 | char *exp_string = NULL; | |
8877 | char *cond_string = NULL; | |
8878 | struct expression *cond = NULL; | |
8879 | struct breakpoint_ops *ops = NULL; | |
8880 | ||
44feb3ce TT |
8881 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8882 | ||
8883 | if (!arg) | |
8884 | arg = ""; | |
f7f9143b JB |
8885 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
8886 | &cond_string, &cond, &ops); | |
a6d9a66e | 8887 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
8888 | cond_string, cond, ops, tempflag, |
8889 | from_tty); | |
8890 | } | |
8891 | ||
a96d9b2e SDJ |
8892 | /* Cleanup function for a syscall filter list. */ |
8893 | static void | |
8894 | clean_up_filters (void *arg) | |
8895 | { | |
8896 | VEC(int) *iter = *(VEC(int) **) arg; | |
8897 | VEC_free (int, iter); | |
8898 | } | |
8899 | ||
8900 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
8901 | filter list, or NULL if no filtering is required. */ | |
8902 | static VEC(int) * | |
8903 | catch_syscall_split_args (char *arg) | |
8904 | { | |
8905 | VEC(int) *result = NULL; | |
8906 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
8907 | ||
8908 | while (*arg != '\0') | |
8909 | { | |
8910 | int i, syscall_number; | |
8911 | char *endptr; | |
8912 | char cur_name[128]; | |
8913 | struct syscall s; | |
8914 | ||
8915 | /* Skip whitespace. */ | |
8916 | while (isspace (*arg)) | |
8917 | arg++; | |
8918 | ||
8919 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
8920 | cur_name[i] = arg[i]; | |
8921 | cur_name[i] = '\0'; | |
8922 | arg += i; | |
8923 | ||
8924 | /* Check if the user provided a syscall name or a number. */ | |
8925 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
8926 | if (*endptr == '\0') | |
bccd0dd2 | 8927 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
8928 | else |
8929 | { | |
8930 | /* We have a name. Let's check if it's valid and convert it | |
8931 | to a number. */ | |
8932 | get_syscall_by_name (cur_name, &s); | |
8933 | ||
8934 | if (s.number == UNKNOWN_SYSCALL) | |
8935 | /* Here we have to issue an error instead of a warning, because | |
8936 | GDB cannot do anything useful if there's no syscall number to | |
8937 | be caught. */ | |
8938 | error (_("Unknown syscall name '%s'."), cur_name); | |
8939 | } | |
8940 | ||
8941 | /* Ok, it's valid. */ | |
8942 | VEC_safe_push (int, result, s.number); | |
8943 | } | |
8944 | ||
8945 | discard_cleanups (cleanup); | |
8946 | return result; | |
8947 | } | |
8948 | ||
8949 | /* Implement the "catch syscall" command. */ | |
8950 | ||
8951 | static void | |
cc59ec59 MS |
8952 | catch_syscall_command_1 (char *arg, int from_tty, |
8953 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
8954 | { |
8955 | int tempflag; | |
8956 | VEC(int) *filter; | |
8957 | struct syscall s; | |
8958 | struct gdbarch *gdbarch = get_current_arch (); | |
8959 | ||
8960 | /* Checking if the feature if supported. */ | |
8961 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8962 | error (_("The feature 'catch syscall' is not supported on \ | |
8963 | this architeture yet.")); | |
8964 | ||
8965 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8966 | ||
8967 | ep_skip_leading_whitespace (&arg); | |
8968 | ||
8969 | /* We need to do this first "dummy" translation in order | |
8970 | to get the syscall XML file loaded or, most important, | |
8971 | to display a warning to the user if there's no XML file | |
8972 | for his/her architecture. */ | |
8973 | get_syscall_by_number (0, &s); | |
8974 | ||
8975 | /* The allowed syntax is: | |
8976 | catch syscall | |
8977 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8978 | ||
8979 | Let's check if there's a syscall name. */ | |
8980 | ||
8981 | if (arg != NULL) | |
8982 | filter = catch_syscall_split_args (arg); | |
8983 | else | |
8984 | filter = NULL; | |
8985 | ||
8986 | create_syscall_event_catchpoint (tempflag, filter, | |
8987 | &catch_syscall_breakpoint_ops); | |
8988 | } | |
8989 | ||
f7f9143b JB |
8990 | /* Implement the "catch assert" command. */ |
8991 | ||
8992 | static void | |
44feb3ce | 8993 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8994 | { |
a6d9a66e | 8995 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8996 | int tempflag; |
f7f9143b JB |
8997 | struct symtab_and_line sal; |
8998 | char *addr_string = NULL; | |
8999 | struct breakpoint_ops *ops = NULL; | |
9000 | ||
44feb3ce TT |
9001 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9002 | ||
9003 | if (!arg) | |
9004 | arg = ""; | |
f7f9143b | 9005 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
9006 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
9007 | ops, tempflag, from_tty); | |
f7f9143b JB |
9008 | } |
9009 | ||
c906108c | 9010 | static void |
fba45db2 | 9011 | catch_command (char *arg, int from_tty) |
c906108c | 9012 | { |
44feb3ce | 9013 | error (_("Catch requires an event name.")); |
c906108c SS |
9014 | } |
9015 | \f | |
9016 | ||
9017 | static void | |
fba45db2 | 9018 | tcatch_command (char *arg, int from_tty) |
c906108c | 9019 | { |
44feb3ce | 9020 | error (_("Catch requires an event name.")); |
c906108c SS |
9021 | } |
9022 | ||
80f8a6eb | 9023 | /* Delete breakpoints by address or line. */ |
c906108c SS |
9024 | |
9025 | static void | |
fba45db2 | 9026 | clear_command (char *arg, int from_tty) |
c906108c | 9027 | { |
d6e956e5 VP |
9028 | struct breakpoint *b; |
9029 | VEC(breakpoint_p) *found = 0; | |
9030 | int ix; | |
c906108c SS |
9031 | int default_match; |
9032 | struct symtabs_and_lines sals; | |
9033 | struct symtab_and_line sal; | |
c906108c SS |
9034 | int i; |
9035 | ||
9036 | if (arg) | |
9037 | { | |
9038 | sals = decode_line_spec (arg, 1); | |
9039 | default_match = 0; | |
9040 | } | |
9041 | else | |
9042 | { | |
c5aa993b | 9043 | sals.sals = (struct symtab_and_line *) |
c906108c | 9044 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 9045 | make_cleanup (xfree, sals.sals); |
fe39c653 | 9046 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
9047 | sal.line = default_breakpoint_line; |
9048 | sal.symtab = default_breakpoint_symtab; | |
9049 | sal.pc = default_breakpoint_address; | |
6c95b8df | 9050 | sal.pspace = default_breakpoint_pspace; |
c906108c | 9051 | if (sal.symtab == 0) |
8a3fe4f8 | 9052 | error (_("No source file specified.")); |
c906108c SS |
9053 | |
9054 | sals.sals[0] = sal; | |
9055 | sals.nelts = 1; | |
9056 | ||
9057 | default_match = 1; | |
9058 | } | |
9059 | ||
ed0616c6 VP |
9060 | /* We don't call resolve_sal_pc here. That's not |
9061 | as bad as it seems, because all existing breakpoints | |
9062 | typically have both file/line and pc set. So, if | |
9063 | clear is given file/line, we can match this to existing | |
9064 | breakpoint without obtaining pc at all. | |
9065 | ||
9066 | We only support clearing given the address explicitly | |
9067 | present in breakpoint table. Say, we've set breakpoint | |
9068 | at file:line. There were several PC values for that file:line, | |
9069 | due to optimization, all in one block. | |
9070 | We've picked one PC value. If "clear" is issued with another | |
9071 | PC corresponding to the same file:line, the breakpoint won't | |
9072 | be cleared. We probably can still clear the breakpoint, but | |
9073 | since the other PC value is never presented to user, user | |
9074 | can only find it by guessing, and it does not seem important | |
9075 | to support that. */ | |
9076 | ||
c906108c | 9077 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
9078 | to it. Do it in two passes, solely to preserve the current |
9079 | behavior that from_tty is forced true if we delete more than | |
9080 | one breakpoint. */ | |
c906108c | 9081 | |
80f8a6eb | 9082 | found = NULL; |
c906108c SS |
9083 | for (i = 0; i < sals.nelts; i++) |
9084 | { | |
9085 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
9086 | If line given (pc == 0), clear all bpts on specified line. |
9087 | If defaulting, clear all bpts on default line | |
c906108c | 9088 | or at default pc. |
c5aa993b JM |
9089 | |
9090 | defaulting sal.pc != 0 tests to do | |
9091 | ||
9092 | 0 1 pc | |
9093 | 1 1 pc _and_ line | |
9094 | 0 0 line | |
9095 | 1 0 <can't happen> */ | |
c906108c SS |
9096 | |
9097 | sal = sals.sals[i]; | |
c906108c | 9098 | |
d6e956e5 VP |
9099 | /* Find all matching breakpoints and add them to |
9100 | 'found'. */ | |
9101 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9102 | { |
0d381245 | 9103 | int match = 0; |
80f8a6eb | 9104 | /* Are we going to delete b? */ |
cc60f2e3 | 9105 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
9106 | { |
9107 | struct bp_location *loc = b->loc; | |
9108 | for (; loc; loc = loc->next) | |
9109 | { | |
6c95b8df PA |
9110 | int pc_match = sal.pc |
9111 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
9112 | && (loc->address == sal.pc) |
9113 | && (!section_is_overlay (loc->section) | |
9114 | || loc->section == sal.section); | |
9115 | int line_match = ((default_match || (0 == sal.pc)) | |
9116 | && b->source_file != NULL | |
9117 | && sal.symtab != NULL | |
6c95b8df | 9118 | && sal.pspace == loc->pspace |
0d381245 VP |
9119 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
9120 | && b->line_number == sal.line); | |
9121 | if (pc_match || line_match) | |
9122 | { | |
9123 | match = 1; | |
9124 | break; | |
9125 | } | |
9126 | } | |
9127 | } | |
9128 | ||
9129 | if (match) | |
d6e956e5 | 9130 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 9131 | } |
80f8a6eb MS |
9132 | } |
9133 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 9134 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
9135 | { |
9136 | if (arg) | |
8a3fe4f8 | 9137 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 9138 | else |
8a3fe4f8 | 9139 | error (_("No breakpoint at this line.")); |
80f8a6eb | 9140 | } |
c906108c | 9141 | |
d6e956e5 | 9142 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
9143 | from_tty = 1; /* Always report if deleted more than one */ |
9144 | if (from_tty) | |
a3f17187 | 9145 | { |
d6e956e5 | 9146 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
9147 | printf_unfiltered (_("Deleted breakpoint ")); |
9148 | else | |
9149 | printf_unfiltered (_("Deleted breakpoints ")); | |
9150 | } | |
80f8a6eb | 9151 | breakpoints_changed (); |
d6e956e5 VP |
9152 | |
9153 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 9154 | { |
c5aa993b | 9155 | if (from_tty) |
d6e956e5 VP |
9156 | printf_unfiltered ("%d ", b->number); |
9157 | delete_breakpoint (b); | |
c906108c | 9158 | } |
80f8a6eb MS |
9159 | if (from_tty) |
9160 | putchar_unfiltered ('\n'); | |
c906108c SS |
9161 | } |
9162 | \f | |
9163 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
9164 | all breakpoints that are marked for deletion, whether hit or not. | |
9165 | This is called after any breakpoint is hit, or after errors. */ | |
9166 | ||
9167 | void | |
fba45db2 | 9168 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
9169 | { |
9170 | struct breakpoint *b, *temp; | |
9171 | ||
9172 | for (; bs; bs = bs->next) | |
20874c92 VP |
9173 | if (bs->breakpoint_at |
9174 | && bs->breakpoint_at->owner | |
9175 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 9176 | && bs->stop) |
4f8d1dc6 | 9177 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
9178 | |
9179 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 9180 | { |
b5de0fa7 | 9181 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
9182 | delete_breakpoint (b); |
9183 | } | |
c906108c SS |
9184 | } |
9185 | ||
494cfb0f | 9186 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
9187 | Sort elements primarily by their ADDRESS (no matter what does |
9188 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
9189 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
9190 | is sorted stable way despite qsort being an instable algorithm. */ | |
9191 | ||
9192 | static int | |
494cfb0f | 9193 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 9194 | { |
494cfb0f JK |
9195 | struct bp_location *a = *(void **) ap; |
9196 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 9197 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
9198 | int a_perm = a->owner->enable_state == bp_permanent; |
9199 | int b_perm = b->owner->enable_state == bp_permanent; | |
9200 | ||
9201 | if (a->address != b->address) | |
9202 | return (a->address > b->address) - (a->address < b->address); | |
9203 | ||
9204 | /* Sort permanent breakpoints first. */ | |
9205 | if (a_perm != b_perm) | |
9206 | return (a_perm < b_perm) - (a_perm > b_perm); | |
9207 | ||
9208 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
9209 | breakpoint can be sorted in arbitrary order. */ | |
9210 | ||
9211 | if (a->owner->number != b->owner->number) | |
9212 | return (a->owner->number > b->owner->number) | |
9213 | - (a->owner->number < b->owner->number); | |
9214 | ||
9215 | return (a > b) - (a < b); | |
9216 | } | |
9217 | ||
876fa593 JK |
9218 | /* Set bp_location_placed_address_before_address_max and |
9219 | bp_location_shadow_len_after_address_max according to the current content of | |
9220 | the bp_location array. */ | |
f7545552 TT |
9221 | |
9222 | static void | |
876fa593 | 9223 | bp_location_target_extensions_update (void) |
f7545552 | 9224 | { |
876fa593 JK |
9225 | struct bp_location *bl, **blp_tmp; |
9226 | ||
9227 | bp_location_placed_address_before_address_max = 0; | |
9228 | bp_location_shadow_len_after_address_max = 0; | |
9229 | ||
9230 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
9231 | { | |
9232 | CORE_ADDR start, end, addr; | |
9233 | ||
9234 | if (!bp_location_has_shadow (bl)) | |
9235 | continue; | |
9236 | ||
9237 | start = bl->target_info.placed_address; | |
9238 | end = start + bl->target_info.shadow_len; | |
9239 | ||
9240 | gdb_assert (bl->address >= start); | |
9241 | addr = bl->address - start; | |
9242 | if (addr > bp_location_placed_address_before_address_max) | |
9243 | bp_location_placed_address_before_address_max = addr; | |
9244 | ||
9245 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
9246 | ||
9247 | gdb_assert (bl->address < end); | |
9248 | addr = end - bl->address; | |
9249 | if (addr > bp_location_shadow_len_after_address_max) | |
9250 | bp_location_shadow_len_after_address_max = addr; | |
9251 | } | |
f7545552 TT |
9252 | } |
9253 | ||
4cd9bd08 | 9254 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
9255 | into the inferior, only remove already-inserted locations that no |
9256 | longer should be inserted. Functions that delete a breakpoint or | |
9257 | breakpoints should pass false, so that deleting a breakpoint | |
9258 | doesn't have the side effect of inserting the locations of other | |
9259 | breakpoints that are marked not-inserted, but should_be_inserted | |
9260 | returns true on them. | |
9261 | ||
9262 | This behaviour is useful is situations close to tear-down -- e.g., | |
9263 | after an exec, while the target still has execution, but breakpoint | |
9264 | shadows of the previous executable image should *NOT* be restored | |
9265 | to the new image; or before detaching, where the target still has | |
9266 | execution and wants to delete breakpoints from GDB's lists, and all | |
9267 | breakpoints had already been removed from the inferior. */ | |
9268 | ||
0d381245 | 9269 | static void |
b60e7edf | 9270 | update_global_location_list (int should_insert) |
0d381245 | 9271 | { |
74960c60 | 9272 | struct breakpoint *b; |
876fa593 | 9273 | struct bp_location **locp, *loc; |
f7545552 TT |
9274 | struct cleanup *cleanups; |
9275 | ||
2d134ed3 PA |
9276 | /* Used in the duplicates detection below. When iterating over all |
9277 | bp_locations, points to the first bp_location of a given address. | |
9278 | Breakpoints and watchpoints of different types are never | |
9279 | duplicates of each other. Keep one pointer for each type of | |
9280 | breakpoint/watchpoint, so we only need to loop over all locations | |
9281 | once. */ | |
9282 | struct bp_location *bp_loc_first; /* breakpoint */ | |
9283 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
9284 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
9285 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
9286 | |
9287 | /* Saved former bp_location array which we compare against the newly built | |
9288 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
9289 | struct bp_location **old_location, **old_locp; | |
9290 | unsigned old_location_count; | |
9291 | ||
9292 | old_location = bp_location; | |
9293 | old_location_count = bp_location_count; | |
9294 | bp_location = NULL; | |
9295 | bp_location_count = 0; | |
9296 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 9297 | |
74960c60 | 9298 | ALL_BREAKPOINTS (b) |
876fa593 JK |
9299 | for (loc = b->loc; loc; loc = loc->next) |
9300 | bp_location_count++; | |
9301 | ||
9302 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
9303 | locp = bp_location; | |
9304 | ALL_BREAKPOINTS (b) | |
9305 | for (loc = b->loc; loc; loc = loc->next) | |
9306 | *locp++ = loc; | |
9307 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 9308 | bp_location_compare); |
876fa593 JK |
9309 | |
9310 | bp_location_target_extensions_update (); | |
74960c60 VP |
9311 | |
9312 | /* Identify bp_location instances that are no longer present in the new | |
9313 | list, and therefore should be freed. Note that it's not necessary that | |
9314 | those locations should be removed from inferior -- if there's another | |
9315 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
9316 | we don't need to remove/insert the location. |
9317 | ||
9318 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
9319 | former bp_location array state respectively. */ | |
9320 | ||
9321 | locp = bp_location; | |
9322 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
9323 | old_locp++) | |
74960c60 | 9324 | { |
876fa593 | 9325 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 9326 | struct bp_location **loc2p; |
876fa593 JK |
9327 | |
9328 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 9329 | have to free it. */ |
c7d46a38 | 9330 | int found_object = 0; |
20874c92 VP |
9331 | /* Tells if the location should remain inserted in the target. */ |
9332 | int keep_in_target = 0; | |
9333 | int removed = 0; | |
876fa593 JK |
9334 | |
9335 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
9336 | at or being the one matching OLD_LOC. */ | |
9337 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 9338 | && (*locp)->address < old_loc->address) |
876fa593 | 9339 | locp++; |
c7d46a38 PA |
9340 | |
9341 | for (loc2p = locp; | |
9342 | (loc2p < bp_location + bp_location_count | |
9343 | && (*loc2p)->address == old_loc->address); | |
9344 | loc2p++) | |
9345 | { | |
9346 | if (*loc2p == old_loc) | |
9347 | { | |
9348 | found_object = 1; | |
9349 | break; | |
9350 | } | |
9351 | } | |
74960c60 VP |
9352 | |
9353 | /* If this location is no longer present, and inserted, look if there's | |
9354 | maybe a new location at the same address. If so, mark that one | |
9355 | inserted, and don't remove this one. This is needed so that we | |
9356 | don't have a time window where a breakpoint at certain location is not | |
9357 | inserted. */ | |
9358 | ||
876fa593 | 9359 | if (old_loc->inserted) |
0d381245 | 9360 | { |
74960c60 | 9361 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 9362 | |
876fa593 | 9363 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
9364 | { |
9365 | /* The location is still present in the location list, and still | |
9366 | should be inserted. Don't do anything. */ | |
20874c92 | 9367 | keep_in_target = 1; |
74960c60 VP |
9368 | } |
9369 | else | |
9370 | { | |
9371 | /* The location is either no longer present, or got disabled. | |
9372 | See if there's another location at the same address, in which | |
9373 | case we don't need to remove this one from the target. */ | |
876fa593 | 9374 | |
2bdf28a0 | 9375 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
9376 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
9377 | { | |
876fa593 | 9378 | for (loc2p = locp; |
c7d46a38 PA |
9379 | (loc2p < bp_location + bp_location_count |
9380 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
9381 | loc2p++) |
9382 | { | |
9383 | struct bp_location *loc2 = *loc2p; | |
9384 | ||
2d134ed3 | 9385 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
9386 | { |
9387 | /* For the sake of should_be_inserted. | |
9388 | Duplicates check below will fix up this later. */ | |
9389 | loc2->duplicate = 0; | |
85d721b8 PA |
9390 | |
9391 | /* Read watchpoint locations are switched to | |
9392 | access watchpoints, if the former are not | |
9393 | supported, but the latter are. */ | |
9394 | if (is_hardware_watchpoint (old_loc->owner)) | |
9395 | { | |
9396 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
9397 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
9398 | } | |
9399 | ||
c7d46a38 PA |
9400 | if (loc2 != old_loc && should_be_inserted (loc2)) |
9401 | { | |
9402 | loc2->inserted = 1; | |
9403 | loc2->target_info = old_loc->target_info; | |
9404 | keep_in_target = 1; | |
9405 | break; | |
9406 | } | |
876fa593 JK |
9407 | } |
9408 | } | |
9409 | } | |
74960c60 VP |
9410 | } |
9411 | ||
20874c92 VP |
9412 | if (!keep_in_target) |
9413 | { | |
876fa593 | 9414 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
9415 | { |
9416 | /* This is just about all we can do. We could keep this | |
9417 | location on the global list, and try to remove it next | |
9418 | time, but there's no particular reason why we will | |
9419 | succeed next time. | |
9420 | ||
876fa593 | 9421 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
9422 | as delete_breakpoint frees the breakpoint only |
9423 | after calling us. */ | |
9424 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 9425 | old_loc->owner->number); |
20874c92 VP |
9426 | } |
9427 | removed = 1; | |
9428 | } | |
0d381245 | 9429 | } |
74960c60 VP |
9430 | |
9431 | if (!found_object) | |
1c5cfe86 | 9432 | { |
db82e815 PA |
9433 | if (removed && non_stop |
9434 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9435 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9436 | { |
db82e815 PA |
9437 | /* This location was removed from the target. In |
9438 | non-stop mode, a race condition is possible where | |
9439 | we've removed a breakpoint, but stop events for that | |
9440 | breakpoint are already queued and will arrive later. | |
9441 | We apply an heuristic to be able to distinguish such | |
9442 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9443 | breakpoint location for a bit, and will retire it | |
9444 | after we see some number of events. The theory here | |
9445 | is that reporting of events should, "on the average", | |
9446 | be fair, so after a while we'll see events from all | |
9447 | threads that have anything of interest, and no longer | |
9448 | need to keep this breakpoint location around. We | |
9449 | don't hold locations forever so to reduce chances of | |
9450 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9451 | SIGTRAP. | |
9452 | ||
9453 | The heuristic failing can be disastrous on | |
9454 | decr_pc_after_break targets. | |
9455 | ||
9456 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9457 | if we fail to recognize a late breakpoint SIGTRAP, | |
9458 | because events_till_retirement has reached 0 too | |
9459 | soon, we'll fail to do the PC adjustment, and report | |
9460 | a random SIGTRAP to the user. When the user resumes | |
9461 | the inferior, it will most likely immediately crash | |
2dec564e | 9462 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
9463 | corrupted, because of being resumed e.g., in the |
9464 | middle of a multi-byte instruction, or skipped a | |
9465 | one-byte instruction. This was actually seen happen | |
9466 | on native x86-linux, and should be less rare on | |
9467 | targets that do not support new thread events, like | |
9468 | remote, due to the heuristic depending on | |
9469 | thread_count. | |
9470 | ||
9471 | Mistaking a random SIGTRAP for a breakpoint trap | |
9472 | causes similar symptoms (PC adjustment applied when | |
9473 | it shouldn't), but then again, playing with SIGTRAPs | |
9474 | behind the debugger's back is asking for trouble. | |
9475 | ||
9476 | Since hardware watchpoint traps are always | |
9477 | distinguishable from other traps, so we don't need to | |
9478 | apply keep hardware watchpoint moribund locations | |
9479 | around. We simply always ignore hardware watchpoint | |
9480 | traps we can no longer explain. */ | |
9481 | ||
876fa593 JK |
9482 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9483 | old_loc->owner = NULL; | |
20874c92 | 9484 | |
876fa593 | 9485 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9486 | } |
9487 | else | |
876fa593 | 9488 | free_bp_location (old_loc); |
20874c92 | 9489 | } |
74960c60 | 9490 | } |
1c5cfe86 | 9491 | |
2d134ed3 PA |
9492 | /* Rescan breakpoints at the same address and section, marking the |
9493 | first one as "first" and any others as "duplicates". This is so | |
9494 | that the bpt instruction is only inserted once. If we have a | |
9495 | permanent breakpoint at the same place as BPT, make that one the | |
9496 | official one, and the rest as duplicates. Permanent breakpoints | |
9497 | are sorted first for the same address. | |
9498 | ||
9499 | Do the same for hardware watchpoints, but also considering the | |
9500 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9501 | |
2d134ed3 PA |
9502 | bp_loc_first = NULL; |
9503 | wp_loc_first = NULL; | |
9504 | awp_loc_first = NULL; | |
9505 | rwp_loc_first = NULL; | |
876fa593 | 9506 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9507 | { |
2bdf28a0 | 9508 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
876fa593 | 9509 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9510 | struct bp_location **loc_first_p; |
876fa593 JK |
9511 | |
9512 | if (b->enable_state == bp_disabled | |
9513 | || b->enable_state == bp_call_disabled | |
9514 | || b->enable_state == bp_startup_disabled | |
9515 | || !loc->enabled | |
9516 | || loc->shlib_disabled | |
15c3d785 | 9517 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 9518 | || is_tracepoint (b)) |
876fa593 JK |
9519 | continue; |
9520 | ||
9521 | /* Permanent breakpoint should always be inserted. */ | |
9522 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9523 | internal_error (__FILE__, __LINE__, | |
9524 | _("allegedly permanent breakpoint is not " | |
9525 | "actually inserted")); | |
9526 | ||
2d134ed3 PA |
9527 | if (b->type == bp_hardware_watchpoint) |
9528 | loc_first_p = &wp_loc_first; | |
9529 | else if (b->type == bp_read_watchpoint) | |
9530 | loc_first_p = &rwp_loc_first; | |
9531 | else if (b->type == bp_access_watchpoint) | |
9532 | loc_first_p = &awp_loc_first; | |
9533 | else | |
9534 | loc_first_p = &bp_loc_first; | |
9535 | ||
9536 | if (*loc_first_p == NULL | |
9537 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9538 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9539 | { |
2d134ed3 | 9540 | *loc_first_p = loc; |
876fa593 JK |
9541 | loc->duplicate = 0; |
9542 | continue; | |
9543 | } | |
9544 | ||
9545 | loc->duplicate = 1; | |
9546 | ||
2d134ed3 PA |
9547 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9548 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9549 | internal_error (__FILE__, __LINE__, |
9550 | _("another breakpoint was inserted on top of " | |
9551 | "a permanent breakpoint")); | |
0d381245 | 9552 | } |
74960c60 | 9553 | |
50c71eaf | 9554 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9555 | && (have_live_inferiors () |
2567c7d9 | 9556 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9557 | insert_breakpoint_locations (); |
f7545552 TT |
9558 | |
9559 | do_cleanups (cleanups); | |
74960c60 VP |
9560 | } |
9561 | ||
20874c92 VP |
9562 | void |
9563 | breakpoint_retire_moribund (void) | |
9564 | { | |
9565 | struct bp_location *loc; | |
9566 | int ix; | |
9567 | ||
9568 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9569 | if (--(loc->events_till_retirement) == 0) | |
9570 | { | |
9571 | free_bp_location (loc); | |
9572 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
9573 | --ix; | |
9574 | } | |
9575 | } | |
9576 | ||
74960c60 | 9577 | static void |
b60e7edf | 9578 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9579 | { |
9580 | struct gdb_exception e; | |
cc59ec59 | 9581 | |
74960c60 | 9582 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 9583 | update_global_location_list (inserting); |
0d381245 VP |
9584 | } |
9585 | ||
1a2ab13a | 9586 | /* Clear LOC from a BPS. */ |
a474d7c2 | 9587 | static void |
1a2ab13a | 9588 | bpstat_remove_bp_location (bpstat bps, struct bp_location *loc) |
a474d7c2 PA |
9589 | { |
9590 | bpstat bs; | |
cc59ec59 | 9591 | |
a474d7c2 | 9592 | for (bs = bps; bs; bs = bs->next) |
1a2ab13a | 9593 | if (bs->breakpoint_at == loc) |
a474d7c2 PA |
9594 | { |
9595 | bs->breakpoint_at = NULL; | |
9596 | bs->old_val = NULL; | |
9597 | /* bs->commands will be freed later. */ | |
9598 | } | |
9599 | } | |
9600 | ||
9601 | /* Callback for iterate_over_threads. */ | |
9602 | static int | |
1a2ab13a | 9603 | bpstat_remove_bp_location_callback (struct thread_info *th, void *data) |
a474d7c2 | 9604 | { |
1a2ab13a | 9605 | struct bp_location *loc = data; |
cc59ec59 | 9606 | |
1a2ab13a | 9607 | bpstat_remove_bp_location (th->stop_bpstat, loc); |
a474d7c2 PA |
9608 | return 0; |
9609 | } | |
9610 | ||
53a5351d JM |
9611 | /* Delete a breakpoint and clean up all traces of it in the data |
9612 | structures. */ | |
c906108c SS |
9613 | |
9614 | void | |
fba45db2 | 9615 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9616 | { |
52f0bd74 | 9617 | struct breakpoint *b; |
c906108c | 9618 | |
8a3fe4f8 | 9619 | gdb_assert (bpt != NULL); |
c906108c SS |
9620 | |
9621 | /* Has this bp already been deleted? This can happen because multiple | |
9622 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
9623 | ||
9624 | One example of this happening is a watchpoint's scope bp. When the | |
9625 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
9626 | delete it. We also delete its scope bp. But the scope bp is marked | |
9627 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
9628 | checked for auto-deleting bp's, which are deleted. | |
9629 | ||
9630 | A real solution to this problem might involve reference counts in bp's, | |
9631 | and/or giving them pointers back to their referencing bpstat's, and | |
9632 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 9633 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
9634 | if (bpt->type == bp_none) |
9635 | return; | |
9636 | ||
e5a0a904 JK |
9637 | /* At least avoid this stale reference until the reference counting of |
9638 | breakpoints gets resolved. */ | |
9639 | if (bpt->related_breakpoint != NULL) | |
9640 | { | |
9641 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
9642 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
9643 | bpt->related_breakpoint->related_breakpoint = NULL; | |
9644 | bpt->related_breakpoint = NULL; | |
9645 | } | |
9646 | ||
383f836e | 9647 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 9648 | |
c906108c SS |
9649 | if (breakpoint_chain == bpt) |
9650 | breakpoint_chain = bpt->next; | |
9651 | ||
c906108c SS |
9652 | ALL_BREAKPOINTS (b) |
9653 | if (b->next == bpt) | |
c5aa993b JM |
9654 | { |
9655 | b->next = bpt->next; | |
9656 | break; | |
9657 | } | |
c906108c | 9658 | |
9add0f1b | 9659 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
9660 | xfree (bpt->cond_string); |
9661 | xfree (bpt->cond_exp); | |
9662 | xfree (bpt->addr_string); | |
9663 | xfree (bpt->exp); | |
9664 | xfree (bpt->exp_string); | |
d63d0675 | 9665 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
9666 | value_free (bpt->val); |
9667 | xfree (bpt->source_file); | |
9668 | xfree (bpt->exec_pathname); | |
a96d9b2e | 9669 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 9670 | |
74960c60 VP |
9671 | /* Now that breakpoint is removed from breakpoint |
9672 | list, update the global location list. This | |
9673 | will remove locations that used to belong to | |
9674 | this breakpoint. Do this before freeing | |
9675 | the breakpoint itself, since remove_breakpoint | |
9676 | looks at location's owner. It might be better | |
9677 | design to have location completely self-contained, | |
9678 | but it's not the case now. */ | |
b60e7edf | 9679 | update_global_location_list (0); |
74960c60 VP |
9680 | |
9681 | ||
c906108c SS |
9682 | /* On the chance that someone will soon try again to delete this same |
9683 | bp, we mark it as deleted before freeing its storage. */ | |
9684 | bpt->type = bp_none; | |
9685 | ||
b8c9b27d | 9686 | xfree (bpt); |
c906108c SS |
9687 | } |
9688 | ||
4d6140d9 AC |
9689 | static void |
9690 | do_delete_breakpoint_cleanup (void *b) | |
9691 | { | |
9692 | delete_breakpoint (b); | |
9693 | } | |
9694 | ||
9695 | struct cleanup * | |
9696 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
9697 | { | |
9698 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
9699 | } | |
9700 | ||
95a42b64 TT |
9701 | /* A callback for map_breakpoint_numbers that calls |
9702 | delete_breakpoint. */ | |
9703 | ||
9704 | static void | |
9705 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
9706 | { | |
9707 | delete_breakpoint (b); | |
9708 | } | |
9709 | ||
c906108c | 9710 | void |
fba45db2 | 9711 | delete_command (char *arg, int from_tty) |
c906108c SS |
9712 | { |
9713 | struct breakpoint *b, *temp; | |
9714 | ||
ea9365bb TT |
9715 | dont_repeat (); |
9716 | ||
c906108c SS |
9717 | if (arg == 0) |
9718 | { | |
9719 | int breaks_to_delete = 0; | |
9720 | ||
9721 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
9722 | Do not delete internal or call-dummy breakpoints, these |
9723 | have to be deleted with an explicit breakpoint number argument. */ | |
9724 | ALL_BREAKPOINTS (b) | |
9725 | { | |
059fb39f | 9726 | if (b->type != bp_call_dummy |
aa7d318d | 9727 | && b->type != bp_std_terminate |
059fb39f | 9728 | && b->type != bp_shlib_event |
4efc6507 | 9729 | && b->type != bp_jit_event |
059fb39f PM |
9730 | && b->type != bp_thread_event |
9731 | && b->type != bp_overlay_event | |
0fd8e87f | 9732 | && b->type != bp_longjmp_master |
aa7d318d | 9733 | && b->type != bp_std_terminate_master |
059fb39f | 9734 | && b->number >= 0) |
973d738b DJ |
9735 | { |
9736 | breaks_to_delete = 1; | |
9737 | break; | |
9738 | } | |
c5aa993b | 9739 | } |
c906108c SS |
9740 | |
9741 | /* Ask user only if there are some breakpoints to delete. */ | |
9742 | if (!from_tty | |
e2e0b3e5 | 9743 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 9744 | { |
c5aa993b JM |
9745 | ALL_BREAKPOINTS_SAFE (b, temp) |
9746 | { | |
059fb39f | 9747 | if (b->type != bp_call_dummy |
aa7d318d | 9748 | && b->type != bp_std_terminate |
059fb39f PM |
9749 | && b->type != bp_shlib_event |
9750 | && b->type != bp_thread_event | |
4efc6507 | 9751 | && b->type != bp_jit_event |
059fb39f | 9752 | && b->type != bp_overlay_event |
0fd8e87f | 9753 | && b->type != bp_longjmp_master |
aa7d318d | 9754 | && b->type != bp_std_terminate_master |
059fb39f | 9755 | && b->number >= 0) |
c5aa993b JM |
9756 | delete_breakpoint (b); |
9757 | } | |
c906108c SS |
9758 | } |
9759 | } | |
9760 | else | |
95a42b64 | 9761 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
9762 | } |
9763 | ||
0d381245 VP |
9764 | static int |
9765 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 9766 | { |
0d381245 VP |
9767 | for (; loc; loc = loc->next) |
9768 | if (!loc->shlib_disabled) | |
9769 | return 0; | |
9770 | return 1; | |
fe3f5fa8 VP |
9771 | } |
9772 | ||
776592bf DE |
9773 | /* Subroutine of update_breakpoint_locations to simplify it. |
9774 | Return non-zero if multiple fns in list LOC have the same name. | |
9775 | Null names are ignored. */ | |
9776 | ||
9777 | static int | |
9778 | ambiguous_names_p (struct bp_location *loc) | |
9779 | { | |
9780 | struct bp_location *l; | |
9781 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
9782 | (int (*) (const void *, |
9783 | const void *)) streq, | |
776592bf DE |
9784 | NULL, xcalloc, xfree); |
9785 | ||
9786 | for (l = loc; l != NULL; l = l->next) | |
9787 | { | |
9788 | const char **slot; | |
9789 | const char *name = l->function_name; | |
9790 | ||
9791 | /* Allow for some names to be NULL, ignore them. */ | |
9792 | if (name == NULL) | |
9793 | continue; | |
9794 | ||
9795 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
9796 | INSERT); | |
9797 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
9798 | NULL. */ | |
9799 | if (*slot != NULL) | |
9800 | { | |
9801 | htab_delete (htab); | |
9802 | return 1; | |
9803 | } | |
9804 | *slot = name; | |
9805 | } | |
9806 | ||
9807 | htab_delete (htab); | |
9808 | return 0; | |
9809 | } | |
9810 | ||
0fb4aa4b PA |
9811 | /* When symbols change, it probably means the sources changed as well, |
9812 | and it might mean the static tracepoint markers are no longer at | |
9813 | the same address or line numbers they used to be at last we | |
9814 | checked. Losing your static tracepoints whenever you rebuild is | |
9815 | undesirable. This function tries to resync/rematch gdb static | |
9816 | tracepoints with the markers on the target, for static tracepoints | |
9817 | that have not been set by marker id. Static tracepoint that have | |
9818 | been set by marker id are reset by marker id in breakpoint_re_set. | |
9819 | The heuristic is: | |
9820 | ||
9821 | 1) For a tracepoint set at a specific address, look for a marker at | |
9822 | the old PC. If one is found there, assume to be the same marker. | |
9823 | If the name / string id of the marker found is different from the | |
9824 | previous known name, assume that means the user renamed the marker | |
9825 | in the sources, and output a warning. | |
9826 | ||
9827 | 2) For a tracepoint set at a given line number, look for a marker | |
9828 | at the new address of the old line number. If one is found there, | |
9829 | assume to be the same marker. If the name / string id of the | |
9830 | marker found is different from the previous known name, assume that | |
9831 | means the user renamed the marker in the sources, and output a | |
9832 | warning. | |
9833 | ||
9834 | 3) If a marker is no longer found at the same address or line, it | |
9835 | may mean the marker no longer exists. But it may also just mean | |
9836 | the code changed a bit. Maybe the user added a few lines of code | |
9837 | that made the marker move up or down (in line number terms). Ask | |
9838 | the target for info about the marker with the string id as we knew | |
9839 | it. If found, update line number and address in the matching | |
9840 | static tracepoint. This will get confused if there's more than one | |
9841 | marker with the same ID (possible in UST, although unadvised | |
9842 | precisely because it confuses tools). */ | |
9843 | ||
9844 | static struct symtab_and_line | |
9845 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
9846 | { | |
9847 | struct static_tracepoint_marker marker; | |
9848 | CORE_ADDR pc; | |
9849 | int i; | |
9850 | ||
9851 | pc = sal.pc; | |
9852 | if (sal.line) | |
9853 | find_line_pc (sal.symtab, sal.line, &pc); | |
9854 | ||
9855 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
9856 | { | |
9857 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
9858 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
9859 | b->number, | |
9860 | b->static_trace_marker_id, marker.str_id); | |
9861 | ||
9862 | xfree (b->static_trace_marker_id); | |
9863 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
9864 | release_static_tracepoint_marker (&marker); | |
9865 | ||
9866 | return sal; | |
9867 | } | |
9868 | ||
9869 | /* Old marker wasn't found on target at lineno. Try looking it up | |
9870 | by string ID. */ | |
9871 | if (!sal.explicit_pc | |
9872 | && sal.line != 0 | |
9873 | && sal.symtab != NULL | |
9874 | && b->static_trace_marker_id != NULL) | |
9875 | { | |
9876 | VEC(static_tracepoint_marker_p) *markers; | |
9877 | ||
9878 | markers | |
9879 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
9880 | ||
9881 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
9882 | { | |
9883 | struct symtab_and_line sal; | |
9884 | struct symbol *sym; | |
9885 | struct static_tracepoint_marker *marker; | |
9886 | ||
9887 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
9888 | ||
9889 | xfree (b->static_trace_marker_id); | |
9890 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
9891 | ||
9892 | warning (_("marker for static tracepoint %d (%s) not " | |
9893 | "found at previous line number"), | |
9894 | b->number, b->static_trace_marker_id); | |
9895 | ||
9896 | init_sal (&sal); | |
9897 | ||
9898 | sal.pc = marker->address; | |
9899 | ||
9900 | sal = find_pc_line (marker->address, 0); | |
9901 | sym = find_pc_sect_function (marker->address, NULL); | |
9902 | ui_out_text (uiout, "Now in "); | |
9903 | if (sym) | |
9904 | { | |
9905 | ui_out_field_string (uiout, "func", | |
9906 | SYMBOL_PRINT_NAME (sym)); | |
9907 | ui_out_text (uiout, " at "); | |
9908 | } | |
9909 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
9910 | ui_out_text (uiout, ":"); | |
9911 | ||
9912 | if (ui_out_is_mi_like_p (uiout)) | |
9913 | { | |
9914 | char *fullname = symtab_to_fullname (sal.symtab); | |
9915 | ||
9916 | if (fullname) | |
9917 | ui_out_field_string (uiout, "fullname", fullname); | |
9918 | } | |
9919 | ||
9920 | ui_out_field_int (uiout, "line", sal.line); | |
9921 | ui_out_text (uiout, "\n"); | |
9922 | ||
9923 | b->line_number = sal.line; | |
9924 | ||
9925 | xfree (b->source_file); | |
9926 | if (sym) | |
9927 | b->source_file = xstrdup (sal.symtab->filename); | |
9928 | else | |
9929 | b->source_file = NULL; | |
9930 | ||
9931 | xfree (b->addr_string); | |
9932 | b->addr_string = xstrprintf ("%s:%d", | |
9933 | sal.symtab->filename, b->line_number); | |
9934 | ||
9935 | /* Might be nice to check if function changed, and warn if | |
9936 | so. */ | |
9937 | ||
9938 | release_static_tracepoint_marker (marker); | |
9939 | } | |
9940 | } | |
9941 | return sal; | |
9942 | } | |
9943 | ||
fe3f5fa8 | 9944 | static void |
0d381245 VP |
9945 | update_breakpoint_locations (struct breakpoint *b, |
9946 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
9947 | { |
9948 | int i; | |
9949 | char *s; | |
0d381245 VP |
9950 | struct bp_location *existing_locations = b->loc; |
9951 | ||
9952 | /* If there's no new locations, and all existing locations | |
9953 | are pending, don't do anything. This optimizes | |
9954 | the common case where all locations are in the same | |
9955 | shared library, that was unloaded. We'd like to | |
9956 | retain the location, so that when the library | |
9957 | is loaded again, we don't loose the enabled/disabled | |
9958 | status of the individual locations. */ | |
9959 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
9960 | return; |
9961 | ||
fe3f5fa8 VP |
9962 | b->loc = NULL; |
9963 | ||
0d381245 | 9964 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 9965 | { |
0d381245 | 9966 | struct bp_location *new_loc = |
39d61571 | 9967 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 9968 | |
0d381245 VP |
9969 | /* Reparse conditions, they might contain references to the |
9970 | old symtab. */ | |
9971 | if (b->cond_string != NULL) | |
9972 | { | |
9973 | struct gdb_exception e; | |
fe3f5fa8 | 9974 | |
0d381245 VP |
9975 | s = b->cond_string; |
9976 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
9977 | { | |
9978 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
9979 | 0); | |
9980 | } | |
9981 | if (e.reason < 0) | |
9982 | { | |
9983 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
9984 | b->number, e.message); | |
9985 | new_loc->enabled = 0; | |
9986 | } | |
9987 | } | |
fe3f5fa8 | 9988 | |
0d381245 VP |
9989 | if (b->source_file != NULL) |
9990 | xfree (b->source_file); | |
9991 | if (sals.sals[i].symtab == NULL) | |
9992 | b->source_file = NULL; | |
9993 | else | |
1b36a34b | 9994 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 9995 | |
0d381245 VP |
9996 | if (b->line_number == 0) |
9997 | b->line_number = sals.sals[i].line; | |
9998 | } | |
fe3f5fa8 | 9999 | |
514f746b AR |
10000 | /* Update locations of permanent breakpoints. */ |
10001 | if (b->enable_state == bp_permanent) | |
10002 | make_breakpoint_permanent (b); | |
10003 | ||
0d381245 VP |
10004 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
10005 | { | |
10006 | struct bp_location *e = existing_locations; | |
776592bf DE |
10007 | /* If there are multiple breakpoints with the same function name, |
10008 | e.g. for inline functions, comparing function names won't work. | |
10009 | Instead compare pc addresses; this is just a heuristic as things | |
10010 | may have moved, but in practice it gives the correct answer | |
10011 | often enough until a better solution is found. */ | |
10012 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
10013 | ||
0d381245 VP |
10014 | for (; e; e = e->next) |
10015 | { | |
10016 | if (!e->enabled && e->function_name) | |
10017 | { | |
10018 | struct bp_location *l = b->loc; | |
776592bf DE |
10019 | if (have_ambiguous_names) |
10020 | { | |
10021 | for (; l; l = l->next) | |
6c95b8df PA |
10022 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
10023 | l->pspace->aspace, l->address)) | |
776592bf DE |
10024 | { |
10025 | l->enabled = 0; | |
10026 | break; | |
10027 | } | |
10028 | } | |
10029 | else | |
10030 | { | |
10031 | for (; l; l = l->next) | |
10032 | if (l->function_name | |
10033 | && strcmp (e->function_name, l->function_name) == 0) | |
10034 | { | |
10035 | l->enabled = 0; | |
10036 | break; | |
10037 | } | |
10038 | } | |
0d381245 VP |
10039 | } |
10040 | } | |
10041 | } | |
fe3f5fa8 | 10042 | |
b60e7edf | 10043 | update_global_location_list (1); |
fe3f5fa8 VP |
10044 | } |
10045 | ||
c906108c SS |
10046 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
10047 | The value we return ends up being the return value from catch_errors. | |
10048 | Unused in this case. */ | |
10049 | ||
10050 | static int | |
4efb68b1 | 10051 | breakpoint_re_set_one (void *bint) |
c906108c | 10052 | { |
53a5351d JM |
10053 | /* get past catch_errs */ |
10054 | struct breakpoint *b = (struct breakpoint *) bint; | |
fe3f5fa8 VP |
10055 | int not_found = 0; |
10056 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
10057 | struct symtabs_and_lines sals = {0}; |
10058 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 10059 | char *s; |
fe3f5fa8 | 10060 | struct gdb_exception e; |
6c95b8df | 10061 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
0fb4aa4b | 10062 | int marker_spec = 0; |
c906108c SS |
10063 | |
10064 | switch (b->type) | |
10065 | { | |
10066 | case bp_none: | |
8a3fe4f8 | 10067 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 10068 | b->number); |
c906108c SS |
10069 | return 0; |
10070 | case bp_breakpoint: | |
10071 | case bp_hardware_breakpoint: | |
1042e4c0 | 10072 | case bp_tracepoint: |
7a697b8d | 10073 | case bp_fast_tracepoint: |
0fb4aa4b | 10074 | case bp_static_tracepoint: |
8bea4e01 UW |
10075 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10076 | if (b->enable_state == bp_startup_disabled) | |
10077 | return 0; | |
10078 | ||
c906108c SS |
10079 | if (b->addr_string == NULL) |
10080 | { | |
10081 | /* Anything without a string can't be re-set. */ | |
10082 | delete_breakpoint (b); | |
10083 | return 0; | |
10084 | } | |
c906108c | 10085 | |
c906108c SS |
10086 | input_radix = b->input_radix; |
10087 | s = b->addr_string; | |
6c95b8df PA |
10088 | |
10089 | save_current_space_and_thread (); | |
10090 | switch_to_program_space_and_thread (b->pspace); | |
10091 | ||
0fb4aa4b PA |
10092 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); |
10093 | ||
385d04dc | 10094 | set_language (b->language); |
fe3f5fa8 | 10095 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 10096 | { |
0fb4aa4b PA |
10097 | if (marker_spec) |
10098 | { | |
10099 | sals = decode_static_tracepoint_spec (&s); | |
10100 | if (sals.nelts > b->static_trace_marker_id_idx) | |
10101 | { | |
10102 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
10103 | sals.nelts = 1; | |
10104 | } | |
10105 | else | |
10106 | error (_("marker %s not found"), b->static_trace_marker_id); | |
10107 | } | |
10108 | else | |
10109 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, | |
10110 | not_found_ptr); | |
fe3f5fa8 VP |
10111 | } |
10112 | if (e.reason < 0) | |
10113 | { | |
10114 | int not_found_and_ok = 0; | |
10115 | /* For pending breakpoints, it's expected that parsing | |
10116 | will fail until the right shared library is loaded. | |
10117 | User has already told to create pending breakpoints and | |
10118 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
10119 | state, then user already saw the message about that breakpoint | |
10120 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
10121 | if (not_found |
10122 | && (b->condition_not_parsed | |
10123 | || (b->loc && b->loc->shlib_disabled) | |
10124 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
10125 | not_found_and_ok = 1; |
10126 | ||
10127 | if (!not_found_and_ok) | |
c906108c | 10128 | { |
fe3f5fa8 VP |
10129 | /* We surely don't want to warn about the same breakpoint |
10130 | 10 times. One solution, implemented here, is disable | |
10131 | the breakpoint on error. Another solution would be to | |
10132 | have separate 'warning emitted' flag. Since this | |
10133 | happens only when a binary has changed, I don't know | |
10134 | which approach is better. */ | |
10135 | b->enable_state = bp_disabled; | |
10136 | throw_exception (e); | |
c906108c | 10137 | } |
fe3f5fa8 | 10138 | } |
c906108c | 10139 | |
6c95b8df | 10140 | if (!not_found) |
fe3f5fa8 | 10141 | { |
6c95b8df PA |
10142 | gdb_assert (sals.nelts == 1); |
10143 | ||
10144 | resolve_sal_pc (&sals.sals[0]); | |
10145 | if (b->condition_not_parsed && s && s[0]) | |
10146 | { | |
10147 | char *cond_string = 0; | |
10148 | int thread = -1; | |
10149 | int task = 0; | |
10150 | ||
10151 | find_condition_and_thread (s, sals.sals[0].pc, | |
10152 | &cond_string, &thread, &task); | |
10153 | if (cond_string) | |
10154 | b->cond_string = cond_string; | |
10155 | b->thread = thread; | |
10156 | b->task = task; | |
10157 | b->condition_not_parsed = 0; | |
10158 | } | |
10159 | ||
0fb4aa4b PA |
10160 | if (b->type == bp_static_tracepoint && !marker_spec) |
10161 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
10162 | ||
6c95b8df | 10163 | expanded = expand_line_sal_maybe (sals.sals[0]); |
fe3f5fa8 | 10164 | } |
6c95b8df PA |
10165 | |
10166 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 10167 | update_breakpoint_locations (b, expanded); |
c906108c SS |
10168 | break; |
10169 | ||
10170 | case bp_watchpoint: | |
10171 | case bp_hardware_watchpoint: | |
10172 | case bp_read_watchpoint: | |
10173 | case bp_access_watchpoint: | |
0b3de036 VP |
10174 | /* Watchpoint can be either on expression using entirely global variables, |
10175 | or it can be on local variables. | |
10176 | ||
10177 | Watchpoints of the first kind are never auto-deleted, and even persist | |
10178 | across program restarts. Since they can use variables from shared | |
10179 | libraries, we need to reparse expression as libraries are loaded | |
10180 | and unloaded. | |
10181 | ||
10182 | Watchpoints on local variables can also change meaning as result | |
10183 | of solib event. For example, if a watchpoint uses both a local and | |
10184 | a global variables in expression, it's a local watchpoint, but | |
10185 | unloading of a shared library will make the expression invalid. | |
10186 | This is not a very common use case, but we still re-evaluate | |
10187 | expression, to avoid surprises to the user. | |
10188 | ||
10189 | Note that for local watchpoints, we re-evaluate it only if | |
10190 | watchpoints frame id is still valid. If it's not, it means | |
10191 | the watchpoint is out of scope and will be deleted soon. In fact, | |
10192 | I'm not sure we'll ever be called in this case. | |
10193 | ||
10194 | If a local watchpoint's frame id is still valid, then | |
10195 | b->exp_valid_block is likewise valid, and we can safely use it. | |
10196 | ||
10197 | Don't do anything about disabled watchpoints, since they will | |
10198 | be reevaluated again when enabled. */ | |
a5606eee | 10199 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 10200 | break; |
c5aa993b JM |
10201 | /* We needn't really do anything to reset these, since the mask |
10202 | that requests them is unaffected by e.g., new libraries being | |
10203 | loaded. */ | |
ce78b96d | 10204 | case bp_catchpoint: |
c906108c | 10205 | break; |
c5aa993b | 10206 | |
c906108c | 10207 | default: |
a3f17187 | 10208 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 10209 | /* fall through */ |
0fd8e87f UW |
10210 | /* Delete overlay event and longjmp master breakpoints; they will be |
10211 | reset later by breakpoint_re_set. */ | |
1900040c | 10212 | case bp_overlay_event: |
0fd8e87f | 10213 | case bp_longjmp_master: |
aa7d318d | 10214 | case bp_std_terminate_master: |
c906108c SS |
10215 | delete_breakpoint (b); |
10216 | break; | |
10217 | ||
c5aa993b JM |
10218 | /* This breakpoint is special, it's set up when the inferior |
10219 | starts and we really don't want to touch it. */ | |
c906108c SS |
10220 | case bp_shlib_event: |
10221 | ||
c4093a6a JM |
10222 | /* Like bp_shlib_event, this breakpoint type is special. |
10223 | Once it is set up, we do not want to touch it. */ | |
10224 | case bp_thread_event: | |
10225 | ||
c5aa993b JM |
10226 | /* Keep temporary breakpoints, which can be encountered when we step |
10227 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
10228 | Otherwise these should have been blown away via the cleanup chain | |
10229 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
10230 | case bp_until: |
10231 | case bp_finish: | |
10232 | case bp_watchpoint_scope: | |
10233 | case bp_call_dummy: | |
aa7d318d | 10234 | case bp_std_terminate: |
c906108c | 10235 | case bp_step_resume: |
611c83ae PA |
10236 | case bp_longjmp: |
10237 | case bp_longjmp_resume: | |
4efc6507 | 10238 | case bp_jit_event: |
c906108c SS |
10239 | break; |
10240 | } | |
10241 | ||
6c95b8df | 10242 | do_cleanups (cleanups); |
c906108c SS |
10243 | return 0; |
10244 | } | |
10245 | ||
69de3c6a | 10246 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 10247 | void |
69de3c6a | 10248 | breakpoint_re_set (void) |
c906108c SS |
10249 | { |
10250 | struct breakpoint *b, *temp; | |
10251 | enum language save_language; | |
10252 | int save_input_radix; | |
6c95b8df | 10253 | struct cleanup *old_chain; |
c5aa993b | 10254 | |
c906108c SS |
10255 | save_language = current_language->la_language; |
10256 | save_input_radix = input_radix; | |
6c95b8df PA |
10257 | old_chain = save_current_program_space (); |
10258 | ||
c906108c | 10259 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 10260 | { |
53a5351d | 10261 | /* Format possible error msg */ |
fe3f5fa8 | 10262 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
10263 | b->number); |
10264 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 10265 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 10266 | do_cleanups (cleanups); |
c5aa993b | 10267 | } |
c906108c SS |
10268 | set_language (save_language); |
10269 | input_radix = save_input_radix; | |
e62c965a | 10270 | |
0756c555 | 10271 | jit_breakpoint_re_set (); |
4efc6507 | 10272 | |
6c95b8df PA |
10273 | do_cleanups (old_chain); |
10274 | ||
69de3c6a | 10275 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
10276 | create_longjmp_master_breakpoint ("longjmp"); |
10277 | create_longjmp_master_breakpoint ("_longjmp"); | |
10278 | create_longjmp_master_breakpoint ("siglongjmp"); | |
10279 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 10280 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
10281 | } |
10282 | \f | |
c906108c SS |
10283 | /* Reset the thread number of this breakpoint: |
10284 | ||
10285 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 10286 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 10287 | void |
fba45db2 | 10288 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
10289 | { |
10290 | if (b->thread != -1) | |
10291 | { | |
39f77062 KB |
10292 | if (in_thread_list (inferior_ptid)) |
10293 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
10294 | |
10295 | /* We're being called after following a fork. The new fork is | |
10296 | selected as current, and unless this was a vfork will have a | |
10297 | different program space from the original thread. Reset that | |
10298 | as well. */ | |
10299 | b->loc->pspace = current_program_space; | |
c906108c SS |
10300 | } |
10301 | } | |
10302 | ||
03ac34d5 MS |
10303 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10304 | If from_tty is nonzero, it prints a message to that effect, | |
10305 | which ends with a period (no newline). */ | |
10306 | ||
c906108c | 10307 | void |
fba45db2 | 10308 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 10309 | { |
52f0bd74 | 10310 | struct breakpoint *b; |
c906108c SS |
10311 | |
10312 | if (count < 0) | |
10313 | count = 0; | |
10314 | ||
10315 | ALL_BREAKPOINTS (b) | |
10316 | if (b->number == bptnum) | |
c5aa993b | 10317 | { |
d77f58be SS |
10318 | if (is_tracepoint (b)) |
10319 | { | |
10320 | if (from_tty && count != 0) | |
10321 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
10322 | bptnum); | |
10323 | return; | |
10324 | } | |
10325 | ||
c5aa993b | 10326 | b->ignore_count = count; |
221ea385 KS |
10327 | if (from_tty) |
10328 | { | |
10329 | if (count == 0) | |
a3f17187 | 10330 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
10331 | bptnum); |
10332 | else if (count == 1) | |
a3f17187 | 10333 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
10334 | bptnum); |
10335 | else | |
a3f17187 | 10336 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
10337 | count, bptnum); |
10338 | } | |
c5aa993b | 10339 | breakpoints_changed (); |
383f836e | 10340 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
10341 | return; |
10342 | } | |
c906108c | 10343 | |
8a3fe4f8 | 10344 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
10345 | } |
10346 | ||
b2175913 MS |
10347 | void |
10348 | make_breakpoint_silent (struct breakpoint *b) | |
10349 | { | |
10350 | /* Silence the breakpoint. */ | |
10351 | b->silent = 1; | |
10352 | } | |
10353 | ||
c906108c SS |
10354 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
10355 | ||
10356 | static void | |
fba45db2 | 10357 | ignore_command (char *args, int from_tty) |
c906108c SS |
10358 | { |
10359 | char *p = args; | |
52f0bd74 | 10360 | int num; |
c906108c SS |
10361 | |
10362 | if (p == 0) | |
e2e0b3e5 | 10363 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 10364 | |
c906108c | 10365 | num = get_number (&p); |
5c44784c | 10366 | if (num == 0) |
8a3fe4f8 | 10367 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 10368 | if (*p == 0) |
8a3fe4f8 | 10369 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
10370 | |
10371 | set_ignore_count (num, | |
10372 | longest_to_int (value_as_long (parse_and_eval (p))), | |
10373 | from_tty); | |
221ea385 KS |
10374 | if (from_tty) |
10375 | printf_filtered ("\n"); | |
c906108c SS |
10376 | } |
10377 | \f | |
10378 | /* Call FUNCTION on each of the breakpoints | |
10379 | whose numbers are given in ARGS. */ | |
10380 | ||
10381 | static void | |
95a42b64 TT |
10382 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
10383 | void *), | |
10384 | void *data) | |
c906108c | 10385 | { |
52f0bd74 | 10386 | char *p = args; |
c906108c | 10387 | char *p1; |
52f0bd74 AC |
10388 | int num; |
10389 | struct breakpoint *b, *tmp; | |
11cf8741 | 10390 | int match; |
c906108c SS |
10391 | |
10392 | if (p == 0) | |
e2e0b3e5 | 10393 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
10394 | |
10395 | while (*p) | |
10396 | { | |
11cf8741 | 10397 | match = 0; |
c906108c | 10398 | p1 = p; |
c5aa993b | 10399 | |
5c44784c JM |
10400 | num = get_number_or_range (&p1); |
10401 | if (num == 0) | |
c5aa993b | 10402 | { |
8a3fe4f8 | 10403 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
10404 | } |
10405 | else | |
10406 | { | |
10407 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
10408 | if (b->number == num) | |
10409 | { | |
10410 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 10411 | match = 1; |
95a42b64 | 10412 | function (b, data); |
5c44784c | 10413 | if (related_breakpoint) |
95a42b64 | 10414 | function (related_breakpoint, data); |
11cf8741 | 10415 | break; |
5c44784c | 10416 | } |
11cf8741 | 10417 | if (match == 0) |
a3f17187 | 10418 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 10419 | } |
c906108c SS |
10420 | p = p1; |
10421 | } | |
10422 | } | |
10423 | ||
0d381245 VP |
10424 | static struct bp_location * |
10425 | find_location_by_number (char *number) | |
10426 | { | |
10427 | char *dot = strchr (number, '.'); | |
10428 | char *p1; | |
10429 | int bp_num; | |
10430 | int loc_num; | |
10431 | struct breakpoint *b; | |
10432 | struct bp_location *loc; | |
10433 | ||
10434 | *dot = '\0'; | |
10435 | ||
10436 | p1 = number; | |
10437 | bp_num = get_number_or_range (&p1); | |
10438 | if (bp_num == 0) | |
10439 | error (_("Bad breakpoint number '%s'"), number); | |
10440 | ||
10441 | ALL_BREAKPOINTS (b) | |
10442 | if (b->number == bp_num) | |
10443 | { | |
10444 | break; | |
10445 | } | |
10446 | ||
10447 | if (!b || b->number != bp_num) | |
10448 | error (_("Bad breakpoint number '%s'"), number); | |
10449 | ||
10450 | p1 = dot+1; | |
10451 | loc_num = get_number_or_range (&p1); | |
10452 | if (loc_num == 0) | |
10453 | error (_("Bad breakpoint location number '%s'"), number); | |
10454 | ||
10455 | --loc_num; | |
10456 | loc = b->loc; | |
10457 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
10458 | ; | |
10459 | if (!loc) | |
10460 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
10461 | ||
10462 | return loc; | |
10463 | } | |
10464 | ||
10465 | ||
1900040c MS |
10466 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10467 | If from_tty is nonzero, it prints a message to that effect, | |
10468 | which ends with a period (no newline). */ | |
10469 | ||
c906108c | 10470 | void |
fba45db2 | 10471 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10472 | { |
10473 | /* Never disable a watchpoint scope breakpoint; we want to | |
10474 | hit them when we leave scope so we can delete both the | |
10475 | watchpoint and its scope breakpoint at that time. */ | |
10476 | if (bpt->type == bp_watchpoint_scope) | |
10477 | return; | |
10478 | ||
c2c6d25f | 10479 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 10480 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
10481 | return; |
10482 | ||
b5de0fa7 | 10483 | bpt->enable_state = bp_disabled; |
c906108c | 10484 | |
b60e7edf | 10485 | update_global_location_list (0); |
c906108c | 10486 | |
383f836e | 10487 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10488 | } |
10489 | ||
95a42b64 TT |
10490 | /* A callback for map_breakpoint_numbers that calls |
10491 | disable_breakpoint. */ | |
10492 | ||
10493 | static void | |
10494 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
10495 | { | |
10496 | disable_breakpoint (b); | |
10497 | } | |
10498 | ||
c906108c | 10499 | static void |
fba45db2 | 10500 | disable_command (char *args, int from_tty) |
c906108c | 10501 | { |
52f0bd74 | 10502 | struct breakpoint *bpt; |
cc59ec59 | 10503 | |
c906108c SS |
10504 | if (args == 0) |
10505 | ALL_BREAKPOINTS (bpt) | |
10506 | switch (bpt->type) | |
c5aa993b JM |
10507 | { |
10508 | case bp_none: | |
8a3fe4f8 | 10509 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 10510 | bpt->number); |
c5aa993b JM |
10511 | continue; |
10512 | case bp_breakpoint: | |
1042e4c0 | 10513 | case bp_tracepoint: |
7a697b8d | 10514 | case bp_fast_tracepoint: |
0fb4aa4b | 10515 | case bp_static_tracepoint: |
ce78b96d | 10516 | case bp_catchpoint: |
c5aa993b JM |
10517 | case bp_hardware_breakpoint: |
10518 | case bp_watchpoint: | |
10519 | case bp_hardware_watchpoint: | |
10520 | case bp_read_watchpoint: | |
10521 | case bp_access_watchpoint: | |
10522 | disable_breakpoint (bpt); | |
10523 | default: | |
10524 | continue; | |
10525 | } | |
0d381245 VP |
10526 | else if (strchr (args, '.')) |
10527 | { | |
10528 | struct bp_location *loc = find_location_by_number (args); | |
10529 | if (loc) | |
10530 | loc->enabled = 0; | |
b60e7edf | 10531 | update_global_location_list (0); |
0d381245 | 10532 | } |
c906108c | 10533 | else |
95a42b64 | 10534 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
10535 | } |
10536 | ||
10537 | static void | |
fba45db2 | 10538 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 10539 | { |
afe38095 | 10540 | int target_resources_ok; |
c906108c SS |
10541 | |
10542 | if (bpt->type == bp_hardware_breakpoint) | |
10543 | { | |
10544 | int i; | |
c5aa993b | 10545 | i = hw_breakpoint_used_count (); |
53a5351d | 10546 | target_resources_ok = |
d92524f1 | 10547 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 10548 | i + 1, 0); |
c906108c | 10549 | if (target_resources_ok == 0) |
8a3fe4f8 | 10550 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 10551 | else if (target_resources_ok < 0) |
8a3fe4f8 | 10552 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
10553 | } |
10554 | ||
cc60f2e3 | 10555 | if (is_watchpoint (bpt)) |
c906108c | 10556 | { |
dde02812 ES |
10557 | struct gdb_exception e; |
10558 | ||
10559 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 10560 | { |
dde02812 | 10561 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 10562 | } |
dde02812 | 10563 | if (e.reason < 0) |
c5aa993b | 10564 | { |
dde02812 ES |
10565 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
10566 | bpt->number); | |
10567 | return; | |
c5aa993b | 10568 | } |
c906108c | 10569 | } |
0101ce28 | 10570 | |
b4c291bb KH |
10571 | if (bpt->enable_state != bp_permanent) |
10572 | bpt->enable_state = bp_enabled; | |
10573 | bpt->disposition = disposition; | |
b60e7edf | 10574 | update_global_location_list (1); |
b4c291bb KH |
10575 | breakpoints_changed (); |
10576 | ||
383f836e | 10577 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10578 | } |
10579 | ||
fe3f5fa8 | 10580 | |
c906108c | 10581 | void |
fba45db2 | 10582 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10583 | { |
10584 | do_enable_breakpoint (bpt, bpt->disposition); | |
10585 | } | |
10586 | ||
95a42b64 TT |
10587 | /* A callback for map_breakpoint_numbers that calls |
10588 | enable_breakpoint. */ | |
10589 | ||
10590 | static void | |
10591 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
10592 | { | |
10593 | enable_breakpoint (b); | |
10594 | } | |
10595 | ||
c906108c SS |
10596 | /* The enable command enables the specified breakpoints (or all defined |
10597 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 10598 | in stopping the inferior. */ |
c906108c | 10599 | |
c906108c | 10600 | static void |
fba45db2 | 10601 | enable_command (char *args, int from_tty) |
c906108c | 10602 | { |
52f0bd74 | 10603 | struct breakpoint *bpt; |
cc59ec59 | 10604 | |
c906108c SS |
10605 | if (args == 0) |
10606 | ALL_BREAKPOINTS (bpt) | |
10607 | switch (bpt->type) | |
c5aa993b JM |
10608 | { |
10609 | case bp_none: | |
8a3fe4f8 | 10610 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 10611 | bpt->number); |
c5aa993b JM |
10612 | continue; |
10613 | case bp_breakpoint: | |
1042e4c0 | 10614 | case bp_tracepoint: |
7a697b8d | 10615 | case bp_fast_tracepoint: |
0fb4aa4b | 10616 | case bp_static_tracepoint: |
ce78b96d | 10617 | case bp_catchpoint: |
c5aa993b JM |
10618 | case bp_hardware_breakpoint: |
10619 | case bp_watchpoint: | |
10620 | case bp_hardware_watchpoint: | |
10621 | case bp_read_watchpoint: | |
10622 | case bp_access_watchpoint: | |
10623 | enable_breakpoint (bpt); | |
10624 | default: | |
10625 | continue; | |
10626 | } | |
0d381245 VP |
10627 | else if (strchr (args, '.')) |
10628 | { | |
10629 | struct bp_location *loc = find_location_by_number (args); | |
10630 | if (loc) | |
10631 | loc->enabled = 1; | |
b60e7edf | 10632 | update_global_location_list (1); |
0d381245 | 10633 | } |
c906108c | 10634 | else |
95a42b64 | 10635 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
10636 | } |
10637 | ||
10638 | static void | |
95a42b64 | 10639 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10640 | { |
b5de0fa7 | 10641 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
10642 | } |
10643 | ||
c906108c | 10644 | static void |
fba45db2 | 10645 | enable_once_command (char *args, int from_tty) |
c906108c | 10646 | { |
95a42b64 | 10647 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
10648 | } |
10649 | ||
10650 | static void | |
95a42b64 | 10651 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10652 | { |
b5de0fa7 | 10653 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
10654 | } |
10655 | ||
c906108c | 10656 | static void |
fba45db2 | 10657 | enable_delete_command (char *args, int from_tty) |
c906108c | 10658 | { |
95a42b64 | 10659 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
10660 | } |
10661 | \f | |
fa8d40ab JJ |
10662 | static void |
10663 | set_breakpoint_cmd (char *args, int from_tty) | |
10664 | { | |
10665 | } | |
10666 | ||
10667 | static void | |
10668 | show_breakpoint_cmd (char *args, int from_tty) | |
10669 | { | |
10670 | } | |
10671 | ||
1f3b5d1b PP |
10672 | /* Invalidate last known value of any hardware watchpoint if |
10673 | the memory which that value represents has been written to by | |
10674 | GDB itself. */ | |
10675 | ||
10676 | static void | |
10677 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
10678 | const bfd_byte *data) | |
10679 | { | |
10680 | struct breakpoint *bp; | |
10681 | ||
10682 | ALL_BREAKPOINTS (bp) | |
10683 | if (bp->enable_state == bp_enabled | |
10684 | && bp->type == bp_hardware_watchpoint | |
10685 | && bp->val_valid && bp->val) | |
10686 | { | |
10687 | struct bp_location *loc; | |
10688 | ||
10689 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
10690 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
10691 | && loc->address + loc->length > addr | |
10692 | && addr + len > loc->address) | |
10693 | { | |
10694 | value_free (bp->val); | |
10695 | bp->val = NULL; | |
10696 | bp->val_valid = 0; | |
10697 | } | |
10698 | } | |
10699 | } | |
10700 | ||
c906108c SS |
10701 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
10702 | ||
10703 | struct symtabs_and_lines | |
fba45db2 | 10704 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
10705 | { |
10706 | struct symtabs_and_lines sals; | |
cc59ec59 | 10707 | |
c906108c | 10708 | if (string == 0) |
8a3fe4f8 | 10709 | error (_("Empty line specification.")); |
c906108c SS |
10710 | if (default_breakpoint_valid) |
10711 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
10712 | default_breakpoint_symtab, |
10713 | default_breakpoint_line, | |
68219205 | 10714 | (char ***) NULL, NULL); |
c906108c SS |
10715 | else |
10716 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 10717 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 10718 | if (*string) |
8a3fe4f8 | 10719 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
10720 | return sals; |
10721 | } | |
8181d85f DJ |
10722 | |
10723 | /* Create and insert a raw software breakpoint at PC. Return an | |
10724 | identifier, which should be used to remove the breakpoint later. | |
10725 | In general, places which call this should be using something on the | |
10726 | breakpoint chain instead; this function should be eliminated | |
10727 | someday. */ | |
10728 | ||
10729 | void * | |
6c95b8df PA |
10730 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
10731 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
10732 | { |
10733 | struct bp_target_info *bp_tgt; | |
10734 | ||
6c95b8df | 10735 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 10736 | |
6c95b8df | 10737 | bp_tgt->placed_address_space = aspace; |
8181d85f | 10738 | bp_tgt->placed_address = pc; |
6c95b8df | 10739 | |
a6d9a66e | 10740 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
10741 | { |
10742 | /* Could not insert the breakpoint. */ | |
10743 | xfree (bp_tgt); | |
10744 | return NULL; | |
10745 | } | |
10746 | ||
10747 | return bp_tgt; | |
10748 | } | |
10749 | ||
10750 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
10751 | ||
10752 | int | |
a6d9a66e | 10753 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
10754 | { |
10755 | struct bp_target_info *bp_tgt = bp; | |
10756 | int ret; | |
10757 | ||
a6d9a66e | 10758 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
10759 | xfree (bp_tgt); |
10760 | ||
10761 | return ret; | |
10762 | } | |
10763 | ||
10764 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
10765 | ||
10766 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 10767 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
10768 | |
10769 | /* Create and insert a breakpoint for software single step. */ | |
10770 | ||
10771 | void | |
6c95b8df PA |
10772 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
10773 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
10774 | { |
10775 | void **bpt_p; | |
10776 | ||
10777 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
10778 | { |
10779 | bpt_p = &single_step_breakpoints[0]; | |
10780 | single_step_gdbarch[0] = gdbarch; | |
10781 | } | |
8181d85f DJ |
10782 | else |
10783 | { | |
10784 | gdb_assert (single_step_breakpoints[1] == NULL); | |
10785 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 10786 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
10787 | } |
10788 | ||
10789 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
10790 | to only create the breakpoints once, and actually put them on the | |
10791 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
10792 | adjust the addresses each time they were needed. Doing this requires | |
10793 | corresponding changes elsewhere where single step breakpoints are | |
10794 | handled, however. So, for now, we use this. */ | |
10795 | ||
6c95b8df | 10796 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 10797 | if (*bpt_p == NULL) |
5af949e3 UW |
10798 | error (_("Could not insert single-step breakpoint at %s"), |
10799 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
10800 | } |
10801 | ||
f02253f1 HZ |
10802 | /* Check if the breakpoints used for software single stepping |
10803 | were inserted or not. */ | |
10804 | ||
10805 | int | |
10806 | single_step_breakpoints_inserted (void) | |
10807 | { | |
10808 | return (single_step_breakpoints[0] != NULL | |
10809 | || single_step_breakpoints[1] != NULL); | |
10810 | } | |
10811 | ||
8181d85f DJ |
10812 | /* Remove and delete any breakpoints used for software single step. */ |
10813 | ||
10814 | void | |
10815 | remove_single_step_breakpoints (void) | |
10816 | { | |
10817 | gdb_assert (single_step_breakpoints[0] != NULL); | |
10818 | ||
10819 | /* See insert_single_step_breakpoint for more about this deprecated | |
10820 | call. */ | |
a6d9a66e UW |
10821 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
10822 | single_step_breakpoints[0]); | |
10823 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
10824 | single_step_breakpoints[0] = NULL; |
10825 | ||
10826 | if (single_step_breakpoints[1] != NULL) | |
10827 | { | |
a6d9a66e UW |
10828 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
10829 | single_step_breakpoints[1]); | |
10830 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
10831 | single_step_breakpoints[1] = NULL; |
10832 | } | |
10833 | } | |
10834 | ||
d03285ec UW |
10835 | /* Delete software single step breakpoints without removing them from |
10836 | the inferior. This is intended to be used if the inferior's address | |
10837 | space where they were inserted is already gone, e.g. after exit or | |
10838 | exec. */ | |
10839 | ||
10840 | void | |
10841 | cancel_single_step_breakpoints (void) | |
10842 | { | |
10843 | int i; | |
10844 | ||
10845 | for (i = 0; i < 2; i++) | |
10846 | if (single_step_breakpoints[i]) | |
10847 | { | |
10848 | xfree (single_step_breakpoints[i]); | |
10849 | single_step_breakpoints[i] = NULL; | |
10850 | single_step_gdbarch[i] = NULL; | |
10851 | } | |
10852 | } | |
10853 | ||
10854 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
10855 | removing them. */ | |
10856 | ||
10857 | static void | |
10858 | detach_single_step_breakpoints (void) | |
10859 | { | |
10860 | int i; | |
10861 | ||
10862 | for (i = 0; i < 2; i++) | |
10863 | if (single_step_breakpoints[i]) | |
10864 | target_remove_breakpoint (single_step_gdbarch[i], | |
10865 | single_step_breakpoints[i]); | |
10866 | } | |
10867 | ||
1aafd4da UW |
10868 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
10869 | ||
10870 | static int | |
cc59ec59 MS |
10871 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
10872 | CORE_ADDR pc) | |
1aafd4da UW |
10873 | { |
10874 | int i; | |
10875 | ||
10876 | for (i = 0; i < 2; i++) | |
10877 | { | |
10878 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
10879 | if (bp_tgt |
10880 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
10881 | bp_tgt->placed_address, | |
10882 | aspace, pc)) | |
1aafd4da UW |
10883 | return 1; |
10884 | } | |
10885 | ||
10886 | return 0; | |
10887 | } | |
10888 | ||
a96d9b2e SDJ |
10889 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
10890 | non-zero otherwise. */ | |
10891 | static int | |
10892 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
10893 | { | |
10894 | if (syscall_catchpoint_p (bp) | |
10895 | && bp->enable_state != bp_disabled | |
10896 | && bp->enable_state != bp_call_disabled) | |
10897 | return 1; | |
10898 | else | |
10899 | return 0; | |
10900 | } | |
10901 | ||
10902 | int | |
10903 | catch_syscall_enabled (void) | |
10904 | { | |
10905 | struct inferior *inf = current_inferior (); | |
10906 | ||
10907 | return inf->total_syscalls_count != 0; | |
10908 | } | |
10909 | ||
10910 | int | |
10911 | catching_syscall_number (int syscall_number) | |
10912 | { | |
10913 | struct breakpoint *bp; | |
10914 | ||
10915 | ALL_BREAKPOINTS (bp) | |
10916 | if (is_syscall_catchpoint_enabled (bp)) | |
10917 | { | |
10918 | if (bp->syscalls_to_be_caught) | |
10919 | { | |
10920 | int i, iter; | |
10921 | for (i = 0; | |
10922 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
10923 | i++) | |
10924 | if (syscall_number == iter) | |
10925 | return 1; | |
10926 | } | |
10927 | else | |
10928 | return 1; | |
10929 | } | |
10930 | ||
10931 | return 0; | |
10932 | } | |
10933 | ||
10934 | /* Complete syscall names. Used by "catch syscall". */ | |
10935 | static char ** | |
10936 | catch_syscall_completer (struct cmd_list_element *cmd, | |
10937 | char *text, char *word) | |
10938 | { | |
10939 | const char **list = get_syscall_names (); | |
cc59ec59 | 10940 | |
a96d9b2e SDJ |
10941 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); |
10942 | } | |
10943 | ||
1042e4c0 SS |
10944 | /* Tracepoint-specific operations. */ |
10945 | ||
10946 | /* Set tracepoint count to NUM. */ | |
10947 | static void | |
10948 | set_tracepoint_count (int num) | |
10949 | { | |
10950 | tracepoint_count = num; | |
4fa62494 | 10951 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
10952 | } |
10953 | ||
10954 | void | |
10955 | trace_command (char *arg, int from_tty) | |
10956 | { | |
8cdf0e15 VP |
10957 | if (create_breakpoint (get_current_arch (), |
10958 | arg, | |
10959 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
10960 | 0 /* tempflag */, |
10961 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
10962 | 0 /* Ignore count */, |
10963 | pending_break_support, | |
10964 | NULL, | |
10965 | from_tty, | |
10966 | 1 /* enabled */)) | |
fd9b8c24 | 10967 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
10968 | } |
10969 | ||
7a697b8d SS |
10970 | void |
10971 | ftrace_command (char *arg, int from_tty) | |
10972 | { | |
8cdf0e15 VP |
10973 | if (create_breakpoint (get_current_arch (), |
10974 | arg, | |
10975 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
10976 | 0 /* tempflag */, |
10977 | bp_fast_tracepoint /* type_wanted */, | |
10978 | 0 /* Ignore count */, | |
10979 | pending_break_support, | |
10980 | NULL, | |
10981 | from_tty, | |
10982 | 1 /* enabled */)) | |
10983 | set_tracepoint_count (breakpoint_count); | |
10984 | } | |
10985 | ||
10986 | /* strace command implementation. Creates a static tracepoint. */ | |
10987 | ||
10988 | void | |
10989 | strace_command (char *arg, int from_tty) | |
10990 | { | |
10991 | if (create_breakpoint (get_current_arch (), | |
10992 | arg, | |
10993 | NULL, 0, 1 /* parse arg */, | |
10994 | 0 /* tempflag */, | |
10995 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
10996 | 0 /* Ignore count */, |
10997 | pending_break_support, | |
10998 | NULL, | |
10999 | from_tty, | |
11000 | 1 /* enabled */)) | |
fd9b8c24 | 11001 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
11002 | } |
11003 | ||
409873ef SS |
11004 | /* Set up a fake reader function that gets command lines from a linked |
11005 | list that was acquired during tracepoint uploading. */ | |
11006 | ||
11007 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 11008 | static int next_cmd; |
409873ef SS |
11009 | |
11010 | static char * | |
11011 | read_uploaded_action (void) | |
11012 | { | |
11013 | char *rslt; | |
11014 | ||
3149d8c1 | 11015 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 11016 | |
3149d8c1 | 11017 | next_cmd++; |
409873ef SS |
11018 | |
11019 | return rslt; | |
11020 | } | |
11021 | ||
00bf0b85 SS |
11022 | /* Given information about a tracepoint as recorded on a target (which |
11023 | can be either a live system or a trace file), attempt to create an | |
11024 | equivalent GDB tracepoint. This is not a reliable process, since | |
11025 | the target does not necessarily have all the information used when | |
11026 | the tracepoint was originally defined. */ | |
11027 | ||
11028 | struct breakpoint * | |
11029 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 11030 | { |
409873ef | 11031 | char *addr_str, small_buf[100]; |
d5551862 | 11032 | struct breakpoint *tp; |
fd9b8c24 | 11033 | |
409873ef SS |
11034 | if (utp->at_string) |
11035 | addr_str = utp->at_string; | |
11036 | else | |
11037 | { | |
11038 | /* In the absence of a source location, fall back to raw | |
11039 | address. Since there is no way to confirm that the address | |
11040 | means the same thing as when the trace was started, warn the | |
11041 | user. */ | |
11042 | warning (_("Uploaded tracepoint %d has no source location, using raw address"), | |
11043 | utp->number); | |
11044 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
11045 | addr_str = small_buf; | |
11046 | } | |
11047 | ||
11048 | /* There's not much we can do with a sequence of bytecodes. */ | |
11049 | if (utp->cond && !utp->cond_string) | |
11050 | warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"), | |
11051 | utp->number); | |
d5551862 | 11052 | |
8cdf0e15 | 11053 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
11054 | addr_str, |
11055 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 11056 | 0 /* tempflag */, |
0fb4aa4b | 11057 | utp->type /* type_wanted */, |
8cdf0e15 VP |
11058 | 0 /* Ignore count */, |
11059 | pending_break_support, | |
11060 | NULL, | |
11061 | 0 /* from_tty */, | |
11062 | utp->enabled /* enabled */)) | |
fd9b8c24 PA |
11063 | return NULL; |
11064 | ||
00bf0b85 SS |
11065 | set_tracepoint_count (breakpoint_count); |
11066 | ||
409873ef | 11067 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
11068 | tp = get_tracepoint (tracepoint_count); |
11069 | gdb_assert (tp != NULL); | |
d5551862 | 11070 | |
00bf0b85 SS |
11071 | if (utp->pass > 0) |
11072 | { | |
409873ef | 11073 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 11074 | |
409873ef | 11075 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
11076 | } |
11077 | ||
409873ef SS |
11078 | /* If we have uploaded versions of the original commands, set up a |
11079 | special-purpose "reader" function and call the usual command line | |
11080 | reader, then pass the result to the breakpoint command-setting | |
11081 | function. */ | |
3149d8c1 | 11082 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 11083 | { |
409873ef | 11084 | struct command_line *cmd_list; |
00bf0b85 | 11085 | |
409873ef | 11086 | this_utp = utp; |
3149d8c1 | 11087 | next_cmd = 0; |
d5551862 | 11088 | |
409873ef SS |
11089 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
11090 | ||
11091 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 11092 | } |
3149d8c1 SS |
11093 | else if (!VEC_empty (char_ptr, utp->actions) |
11094 | || !VEC_empty (char_ptr, utp->step_actions)) | |
409873ef SS |
11095 | warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"), |
11096 | utp->number); | |
00bf0b85 SS |
11097 | |
11098 | return tp; | |
11099 | } | |
11100 | ||
1042e4c0 SS |
11101 | /* Print information on tracepoint number TPNUM_EXP, or all if |
11102 | omitted. */ | |
11103 | ||
11104 | static void | |
11105 | tracepoints_info (char *tpnum_exp, int from_tty) | |
11106 | { | |
d77f58be SS |
11107 | int tpnum = -1, num_printed; |
11108 | ||
11109 | if (tpnum_exp) | |
11110 | tpnum = parse_and_eval_long (tpnum_exp); | |
1042e4c0 | 11111 | |
d77f58be SS |
11112 | num_printed = breakpoint_1 (tpnum, 0, is_tracepoint); |
11113 | ||
11114 | if (num_printed == 0) | |
1042e4c0 | 11115 | { |
d77f58be SS |
11116 | if (tpnum == -1) |
11117 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
11118 | else | |
11119 | ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum); | |
1042e4c0 | 11120 | } |
ad443146 SS |
11121 | |
11122 | default_collect_info (); | |
1042e4c0 SS |
11123 | } |
11124 | ||
11125 | /* The 'enable trace' command enables tracepoints. | |
11126 | Not supported by all targets. */ | |
11127 | static void | |
11128 | enable_trace_command (char *args, int from_tty) | |
11129 | { | |
11130 | enable_command (args, from_tty); | |
11131 | } | |
11132 | ||
11133 | /* The 'disable trace' command disables tracepoints. | |
11134 | Not supported by all targets. */ | |
11135 | static void | |
11136 | disable_trace_command (char *args, int from_tty) | |
11137 | { | |
11138 | disable_command (args, from_tty); | |
11139 | } | |
11140 | ||
11141 | /* Remove a tracepoint (or all if no argument) */ | |
11142 | static void | |
11143 | delete_trace_command (char *arg, int from_tty) | |
11144 | { | |
11145 | struct breakpoint *b, *temp; | |
11146 | ||
11147 | dont_repeat (); | |
11148 | ||
11149 | if (arg == 0) | |
11150 | { | |
11151 | int breaks_to_delete = 0; | |
11152 | ||
11153 | /* Delete all breakpoints if no argument. | |
11154 | Do not delete internal or call-dummy breakpoints, these | |
11155 | have to be deleted with an explicit breakpoint number argument. */ | |
11156 | ALL_TRACEPOINTS (b) | |
11157 | { | |
11158 | if (b->number >= 0) | |
11159 | { | |
11160 | breaks_to_delete = 1; | |
11161 | break; | |
11162 | } | |
11163 | } | |
11164 | ||
11165 | /* Ask user only if there are some breakpoints to delete. */ | |
11166 | if (!from_tty | |
11167 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
11168 | { | |
11169 | ALL_BREAKPOINTS_SAFE (b, temp) | |
11170 | { | |
d77f58be | 11171 | if (is_tracepoint (b) |
059fb39f | 11172 | && b->number >= 0) |
1042e4c0 SS |
11173 | delete_breakpoint (b); |
11174 | } | |
11175 | } | |
11176 | } | |
11177 | else | |
95a42b64 | 11178 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
11179 | } |
11180 | ||
11181 | /* Set passcount for tracepoint. | |
11182 | ||
11183 | First command argument is passcount, second is tracepoint number. | |
11184 | If tracepoint number omitted, apply to most recently defined. | |
11185 | Also accepts special argument "all". */ | |
11186 | ||
11187 | static void | |
11188 | trace_pass_command (char *args, int from_tty) | |
11189 | { | |
11190 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
11191 | unsigned int count; | |
11192 | int all = 0; | |
11193 | ||
11194 | if (args == 0 || *args == 0) | |
11195 | error (_("passcount command requires an argument (count + optional TP num)")); | |
11196 | ||
11197 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
11198 | ||
11199 | while (*args && isspace ((int) *args)) | |
11200 | args++; | |
11201 | ||
11202 | if (*args && strncasecmp (args, "all", 3) == 0) | |
11203 | { | |
11204 | args += 3; /* Skip special argument "all". */ | |
11205 | all = 1; | |
11206 | if (*args) | |
11207 | error (_("Junk at end of arguments.")); | |
11208 | } | |
11209 | else | |
11210 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
11211 | ||
11212 | do | |
11213 | { | |
11214 | if (t1) | |
11215 | { | |
11216 | ALL_TRACEPOINTS (t2) | |
11217 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
11218 | { | |
11219 | t2->pass_count = count; | |
11220 | observer_notify_tracepoint_modified (t2->number); | |
11221 | if (from_tty) | |
11222 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
11223 | t2->number, count); | |
11224 | } | |
11225 | if (! all && *args) | |
11226 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
11227 | } | |
11228 | } | |
11229 | while (*args); | |
11230 | } | |
11231 | ||
11232 | struct breakpoint * | |
11233 | get_tracepoint (int num) | |
11234 | { | |
11235 | struct breakpoint *t; | |
11236 | ||
11237 | ALL_TRACEPOINTS (t) | |
11238 | if (t->number == num) | |
11239 | return t; | |
11240 | ||
11241 | return NULL; | |
11242 | } | |
11243 | ||
d5551862 SS |
11244 | /* Find the tracepoint with the given target-side number (which may be |
11245 | different from the tracepoint number after disconnecting and | |
11246 | reconnecting). */ | |
11247 | ||
11248 | struct breakpoint * | |
11249 | get_tracepoint_by_number_on_target (int num) | |
11250 | { | |
11251 | struct breakpoint *t; | |
11252 | ||
11253 | ALL_TRACEPOINTS (t) | |
11254 | if (t->number_on_target == num) | |
11255 | return t; | |
11256 | ||
11257 | return NULL; | |
11258 | } | |
11259 | ||
1042e4c0 SS |
11260 | /* Utility: parse a tracepoint number and look it up in the list. |
11261 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
11262 | if OPTIONAL_P is true, then if the argument is missing, the most | |
11263 | recent tracepoint (tracepoint_count) is returned. */ | |
11264 | struct breakpoint * | |
11265 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
11266 | { | |
11267 | extern int tracepoint_count; | |
11268 | struct breakpoint *t; | |
11269 | int tpnum; | |
11270 | char *instring = arg == NULL ? NULL : *arg; | |
11271 | ||
11272 | if (arg == NULL || *arg == NULL || ! **arg) | |
11273 | { | |
11274 | if (optional_p) | |
11275 | tpnum = tracepoint_count; | |
11276 | else | |
11277 | error_no_arg (_("tracepoint number")); | |
11278 | } | |
11279 | else | |
11280 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
11281 | ||
11282 | if (tpnum <= 0) | |
11283 | { | |
11284 | if (instring && *instring) | |
11285 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
11286 | instring); | |
11287 | else | |
11288 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
11289 | return NULL; | |
11290 | } | |
11291 | ||
11292 | ALL_TRACEPOINTS (t) | |
11293 | if (t->number == tpnum) | |
11294 | { | |
11295 | return t; | |
11296 | } | |
11297 | ||
11298 | /* FIXME: if we are in the middle of a range we don't want to give | |
11299 | a message. The current interface to get_number_or_range doesn't | |
11300 | allow us to discover this. */ | |
11301 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
11302 | return NULL; | |
11303 | } | |
11304 | ||
6149aea9 PA |
11305 | /* Save information on user settable breakpoints (watchpoints, etc) to |
11306 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
11307 | on each breakpoint and only include the ones for which it returns | |
11308 | non-zero. */ | |
11309 | ||
1042e4c0 | 11310 | static void |
6149aea9 PA |
11311 | save_breakpoints (char *filename, int from_tty, |
11312 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
11313 | { |
11314 | struct breakpoint *tp; | |
6149aea9 | 11315 | int any = 0; |
a7bdde9e | 11316 | char *pathname; |
1042e4c0 | 11317 | struct cleanup *cleanup; |
a7bdde9e | 11318 | struct ui_file *fp; |
6149aea9 | 11319 | int extra_trace_bits = 0; |
1042e4c0 | 11320 | |
6149aea9 PA |
11321 | if (filename == 0 || *filename == 0) |
11322 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
11323 | |
11324 | /* See if we have anything to save. */ | |
6149aea9 | 11325 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11326 | { |
6149aea9 PA |
11327 | /* Skip internal and momentary breakpoints. */ |
11328 | if (!user_settable_breakpoint (tp)) | |
11329 | continue; | |
11330 | ||
11331 | /* If we have a filter, only save the breakpoints it accepts. */ | |
11332 | if (filter && !filter (tp)) | |
11333 | continue; | |
11334 | ||
11335 | any = 1; | |
11336 | ||
11337 | if (is_tracepoint (tp)) | |
11338 | { | |
11339 | extra_trace_bits = 1; | |
11340 | ||
11341 | /* We can stop searching. */ | |
11342 | break; | |
11343 | } | |
1042e4c0 | 11344 | } |
6149aea9 PA |
11345 | |
11346 | if (!any) | |
1042e4c0 | 11347 | { |
6149aea9 | 11348 | warning (_("Nothing to save.")); |
1042e4c0 SS |
11349 | return; |
11350 | } | |
11351 | ||
6149aea9 | 11352 | pathname = tilde_expand (filename); |
1042e4c0 | 11353 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 11354 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 11355 | if (!fp) |
6149aea9 PA |
11356 | error (_("Unable to open file '%s' for saving (%s)"), |
11357 | filename, safe_strerror (errno)); | |
a7bdde9e | 11358 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 11359 | |
6149aea9 PA |
11360 | if (extra_trace_bits) |
11361 | save_trace_state_variables (fp); | |
8bf6485c | 11362 | |
6149aea9 | 11363 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11364 | { |
6149aea9 PA |
11365 | /* Skip internal and momentary breakpoints. */ |
11366 | if (!user_settable_breakpoint (tp)) | |
11367 | continue; | |
8bf6485c | 11368 | |
6149aea9 PA |
11369 | /* If we have a filter, only save the breakpoints it accepts. */ |
11370 | if (filter && !filter (tp)) | |
11371 | continue; | |
11372 | ||
11373 | if (tp->ops != NULL) | |
11374 | (tp->ops->print_recreate) (tp, fp); | |
1042e4c0 SS |
11375 | else |
11376 | { | |
6149aea9 PA |
11377 | if (tp->type == bp_fast_tracepoint) |
11378 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
11379 | if (tp->type == bp_static_tracepoint) |
11380 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
11381 | else if (tp->type == bp_tracepoint) |
11382 | fprintf_unfiltered (fp, "trace"); | |
11383 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11384 | fprintf_unfiltered (fp, "tbreak"); | |
11385 | else if (tp->type == bp_breakpoint) | |
11386 | fprintf_unfiltered (fp, "break"); | |
11387 | else if (tp->type == bp_hardware_breakpoint | |
11388 | && tp->disposition == disp_del) | |
11389 | fprintf_unfiltered (fp, "thbreak"); | |
11390 | else if (tp->type == bp_hardware_breakpoint) | |
11391 | fprintf_unfiltered (fp, "hbreak"); | |
11392 | else if (tp->type == bp_watchpoint) | |
11393 | fprintf_unfiltered (fp, "watch"); | |
11394 | else if (tp->type == bp_hardware_watchpoint) | |
11395 | fprintf_unfiltered (fp, "watch"); | |
11396 | else if (tp->type == bp_read_watchpoint) | |
11397 | fprintf_unfiltered (fp, "rwatch"); | |
11398 | else if (tp->type == bp_access_watchpoint) | |
11399 | fprintf_unfiltered (fp, "awatch"); | |
11400 | else | |
11401 | internal_error (__FILE__, __LINE__, | |
11402 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11403 | ||
11404 | if (tp->exp_string) | |
11405 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
11406 | else if (tp->addr_string) | |
11407 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
11408 | else | |
11409 | { | |
11410 | char tmp[40]; | |
11411 | ||
11412 | sprintf_vma (tmp, tp->loc->address); | |
11413 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
11414 | } | |
1042e4c0 SS |
11415 | } |
11416 | ||
6149aea9 PA |
11417 | if (tp->thread != -1) |
11418 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
11419 | ||
11420 | if (tp->task != 0) | |
11421 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
11422 | |
11423 | fprintf_unfiltered (fp, "\n"); | |
11424 | ||
6149aea9 PA |
11425 | /* Note, we can't rely on tp->number for anything, as we can't |
11426 | assume the recreated breakpoint numbers will match. Use $bpnum | |
11427 | instead. */ | |
11428 | ||
11429 | if (tp->cond_string) | |
11430 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
11431 | ||
11432 | if (tp->ignore_count) | |
11433 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
11434 | ||
1042e4c0 | 11435 | if (tp->pass_count) |
a7bdde9e | 11436 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 11437 | |
a7bdde9e | 11438 | if (tp->commands) |
1042e4c0 | 11439 | { |
a7bdde9e VP |
11440 | volatile struct gdb_exception ex; |
11441 | ||
6149aea9 | 11442 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
11443 | |
11444 | ui_out_redirect (uiout, fp); | |
11445 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1042e4c0 | 11446 | { |
9add0f1b | 11447 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
11448 | } |
11449 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 11450 | |
a7bdde9e VP |
11451 | if (ex.reason < 0) |
11452 | throw_exception (ex); | |
1042e4c0 | 11453 | |
a7bdde9e | 11454 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 11455 | } |
6149aea9 PA |
11456 | |
11457 | if (tp->enable_state == bp_disabled) | |
11458 | fprintf_unfiltered (fp, "disable\n"); | |
11459 | ||
11460 | /* If this is a multi-location breakpoint, check if the locations | |
11461 | should be individually disabled. Watchpoint locations are | |
11462 | special, and not user visible. */ | |
11463 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
11464 | { | |
11465 | struct bp_location *loc; | |
11466 | int n = 1; | |
11467 | ||
11468 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
11469 | if (!loc->enabled) | |
11470 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
11471 | } | |
1042e4c0 | 11472 | } |
8bf6485c | 11473 | |
6149aea9 | 11474 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
11475 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
11476 | ||
1042e4c0 SS |
11477 | do_cleanups (cleanup); |
11478 | if (from_tty) | |
6149aea9 PA |
11479 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
11480 | } | |
11481 | ||
11482 | /* The `save breakpoints' command. */ | |
11483 | ||
11484 | static void | |
11485 | save_breakpoints_command (char *args, int from_tty) | |
11486 | { | |
11487 | save_breakpoints (args, from_tty, NULL); | |
11488 | } | |
11489 | ||
11490 | /* The `save tracepoints' command. */ | |
11491 | ||
11492 | static void | |
11493 | save_tracepoints_command (char *args, int from_tty) | |
11494 | { | |
11495 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
11496 | } |
11497 | ||
11498 | /* Create a vector of all tracepoints. */ | |
11499 | ||
11500 | VEC(breakpoint_p) * | |
11501 | all_tracepoints () | |
11502 | { | |
11503 | VEC(breakpoint_p) *tp_vec = 0; | |
11504 | struct breakpoint *tp; | |
11505 | ||
11506 | ALL_TRACEPOINTS (tp) | |
11507 | { | |
11508 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
11509 | } | |
11510 | ||
11511 | return tp_vec; | |
11512 | } | |
11513 | ||
c906108c | 11514 | \f |
31e2b00f AS |
11515 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
11516 | It is defined as a macro to prevent duplication. | |
11517 | COMMAND should be a string constant containing the name of the command. */ | |
11518 | #define BREAK_ARGS_HELP(command) \ | |
11519 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
11520 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
11521 | If a line number is specified, break at start of code for that line.\n\ | |
11522 | If a function is specified, break at start of code for that function.\n\ | |
11523 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
11524 | With no LOCATION, uses current execution address of the selected\n\ |
11525 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
11526 | \n\ |
11527 | THREADNUM is the number from \"info threads\".\n\ | |
11528 | CONDITION is a boolean expression.\n\ | |
11529 | \n\ | |
d41c0fc8 PA |
11530 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
11531 | conditions are different.\n\ | |
31e2b00f AS |
11532 | \n\ |
11533 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
11534 | ||
44feb3ce TT |
11535 | /* List of subcommands for "catch". */ |
11536 | static struct cmd_list_element *catch_cmdlist; | |
11537 | ||
11538 | /* List of subcommands for "tcatch". */ | |
11539 | static struct cmd_list_element *tcatch_cmdlist; | |
11540 | ||
11541 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
11542 | lists, and pass some additional user data to the command function. */ | |
11543 | static void | |
11544 | add_catch_command (char *name, char *docstring, | |
11545 | void (*sfunc) (char *args, int from_tty, | |
11546 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
11547 | char **(*completer) (struct cmd_list_element *cmd, |
11548 | char *text, char *word), | |
44feb3ce TT |
11549 | void *user_data_catch, |
11550 | void *user_data_tcatch) | |
11551 | { | |
11552 | struct cmd_list_element *command; | |
11553 | ||
11554 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
11555 | &catch_cmdlist); | |
11556 | set_cmd_sfunc (command, sfunc); | |
11557 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 11558 | set_cmd_completer (command, completer); |
44feb3ce TT |
11559 | |
11560 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
11561 | &tcatch_cmdlist); | |
11562 | set_cmd_sfunc (command, sfunc); | |
11563 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 11564 | set_cmd_completer (command, completer); |
44feb3ce TT |
11565 | } |
11566 | ||
6c95b8df | 11567 | static void |
a79b8f6e | 11568 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 11569 | { |
6c95b8df PA |
11570 | inf->total_syscalls_count = 0; |
11571 | inf->any_syscall_count = 0; | |
11572 | VEC_free (int, inf->syscalls_counts); | |
11573 | } | |
11574 | ||
6149aea9 PA |
11575 | static void |
11576 | save_command (char *arg, int from_tty) | |
11577 | { | |
11578 | printf_unfiltered (_("\ | |
11579 | \"save\" must be followed by the name of a save subcommand.\n")); | |
11580 | help_list (save_cmdlist, "save ", -1, gdb_stdout); | |
11581 | } | |
11582 | ||
c906108c | 11583 | void |
fba45db2 | 11584 | _initialize_breakpoint (void) |
c906108c SS |
11585 | { |
11586 | struct cmd_list_element *c; | |
11587 | ||
84acb35a | 11588 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 11589 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 11590 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 11591 | |
c906108c SS |
11592 | breakpoint_chain = 0; |
11593 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
11594 | before a breakpoint is set. */ | |
11595 | breakpoint_count = 0; | |
11596 | ||
1042e4c0 SS |
11597 | tracepoint_count = 0; |
11598 | ||
1bedd215 AC |
11599 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
11600 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
11601 | Usage is `ignore N COUNT'.")); | |
c906108c | 11602 | if (xdb_commands) |
c5aa993b | 11603 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 11604 | |
1bedd215 AC |
11605 | add_com ("commands", class_breakpoint, commands_command, _("\ |
11606 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
11607 | Give breakpoint number as argument after \"commands\".\n\ |
11608 | With no argument, the targeted breakpoint is the last one set.\n\ | |
11609 | The commands themselves follow starting on the next line.\n\ | |
11610 | Type a line containing \"end\" to indicate the end of them.\n\ | |
11611 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 11612 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 11613 | |
1bedd215 AC |
11614 | add_com ("condition", class_breakpoint, condition_command, _("\ |
11615 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 11616 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 11617 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 11618 | |
1bedd215 | 11619 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 11620 | Set a temporary breakpoint.\n\ |
c906108c SS |
11621 | Like \"break\" except the breakpoint is only temporary,\n\ |
11622 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
11623 | by using \"enable delete\" on the breakpoint number.\n\ |
11624 | \n" | |
11625 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 11626 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 11627 | |
1bedd215 | 11628 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 11629 | Set a hardware assisted breakpoint.\n\ |
c906108c | 11630 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
11631 | some target hardware may not have this support.\n\ |
11632 | \n" | |
11633 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 11634 | set_cmd_completer (c, location_completer); |
c906108c | 11635 | |
1bedd215 | 11636 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 11637 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 11638 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
11639 | so it will be deleted when hit.\n\ |
11640 | \n" | |
11641 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 11642 | set_cmd_completer (c, location_completer); |
c906108c | 11643 | |
1bedd215 AC |
11644 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
11645 | Enable some breakpoints.\n\ | |
c906108c SS |
11646 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
11647 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
11648 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 11649 | With a subcommand you can enable temporarily."), |
c906108c SS |
11650 | &enablelist, "enable ", 1, &cmdlist); |
11651 | if (xdb_commands) | |
1bedd215 AC |
11652 | add_com ("ab", class_breakpoint, enable_command, _("\ |
11653 | Enable some breakpoints.\n\ | |
c906108c SS |
11654 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
11655 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
11656 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 11657 | With a subcommand you can enable temporarily.")); |
c906108c SS |
11658 | |
11659 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
11660 | ||
84951ab5 | 11661 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 11662 | Enable some breakpoints.\n\ |
c906108c SS |
11663 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
11664 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 11665 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 11666 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 11667 | |
1a966eab AC |
11668 | add_cmd ("once", no_class, enable_once_command, _("\ |
11669 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
11670 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
11671 | &enablebreaklist); |
11672 | ||
1a966eab AC |
11673 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
11674 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
11675 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
11676 | &enablebreaklist); |
11677 | ||
1a966eab AC |
11678 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
11679 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
11680 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
11681 | &enablelist); |
11682 | ||
1a966eab AC |
11683 | add_cmd ("once", no_class, enable_once_command, _("\ |
11684 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
11685 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
11686 | &enablelist); |
11687 | ||
1bedd215 AC |
11688 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
11689 | Disable some breakpoints.\n\ | |
c906108c SS |
11690 | Arguments are breakpoint numbers with spaces in between.\n\ |
11691 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 11692 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
11693 | &disablelist, "disable ", 1, &cmdlist); |
11694 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
11695 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
11696 | if (xdb_commands) | |
1bedd215 AC |
11697 | add_com ("sb", class_breakpoint, disable_command, _("\ |
11698 | Disable some breakpoints.\n\ | |
c906108c SS |
11699 | Arguments are breakpoint numbers with spaces in between.\n\ |
11700 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 11701 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 11702 | |
1a966eab AC |
11703 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
11704 | Disable some breakpoints.\n\ | |
c906108c SS |
11705 | Arguments are breakpoint numbers with spaces in between.\n\ |
11706 | To disable all breakpoints, give no argument.\n\ | |
11707 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 11708 | This command may be abbreviated \"disable\"."), |
c906108c SS |
11709 | &disablelist); |
11710 | ||
1bedd215 AC |
11711 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
11712 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
11713 | Arguments are breakpoint numbers with spaces in between.\n\ |
11714 | To delete all breakpoints, give no argument.\n\ | |
11715 | \n\ | |
11716 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 11717 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
11718 | &deletelist, "delete ", 1, &cmdlist); |
11719 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 11720 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 11721 | if (xdb_commands) |
1bedd215 AC |
11722 | add_com ("db", class_breakpoint, delete_command, _("\ |
11723 | Delete some breakpoints.\n\ | |
c906108c | 11724 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 11725 | To delete all breakpoints, give no argument.\n")); |
c906108c | 11726 | |
1a966eab AC |
11727 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
11728 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
11729 | Arguments are breakpoint numbers with spaces in between.\n\ |
11730 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 11731 | This command may be abbreviated \"delete\"."), |
c906108c SS |
11732 | &deletelist); |
11733 | ||
1bedd215 AC |
11734 | add_com ("clear", class_breakpoint, clear_command, _("\ |
11735 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
11736 | Argument may be line number, function name, or \"*\" and an address.\n\ |
11737 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
11738 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
11739 | If an address is specified, breakpoints at that address are cleared.\n\ |
11740 | \n\ | |
11741 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
11742 | is executing in.\n\ |
11743 | \n\ | |
1bedd215 | 11744 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 11745 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 11746 | |
1bedd215 | 11747 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
11748 | Set breakpoint at specified line or function.\n" |
11749 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 11750 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 11751 | |
c906108c SS |
11752 | add_com_alias ("b", "break", class_run, 1); |
11753 | add_com_alias ("br", "break", class_run, 1); | |
11754 | add_com_alias ("bre", "break", class_run, 1); | |
11755 | add_com_alias ("brea", "break", class_run, 1); | |
11756 | ||
7681d515 PM |
11757 | if (xdb_commands) |
11758 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
11759 | |
11760 | if (dbx_commands) | |
11761 | { | |
1bedd215 AC |
11762 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
11763 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
11764 | &stoplist, "stop ", 1, &cmdlist); |
11765 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 11766 | _("Break in function or address."), &stoplist); |
c5aa993b | 11767 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 11768 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
11769 | add_com ("status", class_info, breakpoints_info, _("\ |
11770 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11771 | The \"Type\" column indicates one of:\n\ |
11772 | \tbreakpoint - normal breakpoint\n\ | |
11773 | \twatchpoint - watchpoint\n\ | |
11774 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11775 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11776 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11777 | address and file/line number respectively.\n\ |
11778 | \n\ | |
11779 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11780 | are set to the address of the last breakpoint listed unless the command\n\ |
11781 | is prefixed with \"server \".\n\n\ | |
c906108c | 11782 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11783 | breakpoint set.")); |
c906108c SS |
11784 | } |
11785 | ||
1bedd215 AC |
11786 | add_info ("breakpoints", breakpoints_info, _("\ |
11787 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11788 | The \"Type\" column indicates one of:\n\ |
11789 | \tbreakpoint - normal breakpoint\n\ | |
11790 | \twatchpoint - watchpoint\n\ | |
11791 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11792 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11793 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11794 | address and file/line number respectively.\n\ |
11795 | \n\ | |
11796 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11797 | are set to the address of the last breakpoint listed unless the command\n\ |
11798 | is prefixed with \"server \".\n\n\ | |
c906108c | 11799 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11800 | breakpoint set.")); |
c906108c | 11801 | |
6b04bdb7 MS |
11802 | add_info_alias ("b", "breakpoints", 1); |
11803 | ||
c906108c | 11804 | if (xdb_commands) |
1bedd215 AC |
11805 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
11806 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11807 | The \"Type\" column indicates one of:\n\ |
11808 | \tbreakpoint - normal breakpoint\n\ | |
11809 | \twatchpoint - watchpoint\n\ | |
11810 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11811 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11812 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11813 | address and file/line number respectively.\n\ |
11814 | \n\ | |
11815 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11816 | are set to the address of the last breakpoint listed unless the command\n\ |
11817 | is prefixed with \"server \".\n\n\ | |
c906108c | 11818 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11819 | breakpoint set.")); |
c906108c | 11820 | |
1a966eab AC |
11821 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
11822 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11823 | The \"Type\" column indicates one of:\n\ |
11824 | \tbreakpoint - normal breakpoint\n\ | |
11825 | \twatchpoint - watchpoint\n\ | |
11826 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
11827 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
11828 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
11829 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
11830 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
11831 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
11832 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
11833 | address and file/line number respectively.\n\ |
11834 | \n\ | |
11835 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11836 | are set to the address of the last breakpoint listed unless the command\n\ |
11837 | is prefixed with \"server \".\n\n\ | |
c906108c | 11838 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 11839 | breakpoint set."), |
c906108c SS |
11840 | &maintenanceinfolist); |
11841 | ||
44feb3ce TT |
11842 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
11843 | Set catchpoints to catch events."), | |
11844 | &catch_cmdlist, "catch ", | |
11845 | 0/*allow-unknown*/, &cmdlist); | |
11846 | ||
11847 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
11848 | Set temporary catchpoints to catch events."), | |
11849 | &tcatch_cmdlist, "tcatch ", | |
11850 | 0/*allow-unknown*/, &cmdlist); | |
11851 | ||
11852 | /* Add catch and tcatch sub-commands. */ | |
11853 | add_catch_command ("catch", _("\ | |
11854 | Catch an exception, when caught.\n\ | |
11855 | With an argument, catch only exceptions with the given name."), | |
11856 | catch_catch_command, | |
a96d9b2e | 11857 | NULL, |
44feb3ce TT |
11858 | CATCH_PERMANENT, |
11859 | CATCH_TEMPORARY); | |
11860 | add_catch_command ("throw", _("\ | |
11861 | Catch an exception, when thrown.\n\ | |
11862 | With an argument, catch only exceptions with the given name."), | |
11863 | catch_throw_command, | |
a96d9b2e | 11864 | NULL, |
44feb3ce TT |
11865 | CATCH_PERMANENT, |
11866 | CATCH_TEMPORARY); | |
11867 | add_catch_command ("fork", _("Catch calls to fork."), | |
11868 | catch_fork_command_1, | |
a96d9b2e | 11869 | NULL, |
44feb3ce TT |
11870 | (void *) (uintptr_t) catch_fork_permanent, |
11871 | (void *) (uintptr_t) catch_fork_temporary); | |
11872 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
11873 | catch_fork_command_1, | |
a96d9b2e | 11874 | NULL, |
44feb3ce TT |
11875 | (void *) (uintptr_t) catch_vfork_permanent, |
11876 | (void *) (uintptr_t) catch_vfork_temporary); | |
11877 | add_catch_command ("exec", _("Catch calls to exec."), | |
11878 | catch_exec_command_1, | |
a96d9b2e SDJ |
11879 | NULL, |
11880 | CATCH_PERMANENT, | |
11881 | CATCH_TEMPORARY); | |
11882 | add_catch_command ("syscall", _("\ | |
11883 | Catch system calls by their names and/or numbers.\n\ | |
11884 | Arguments say which system calls to catch. If no arguments\n\ | |
11885 | are given, every system call will be caught.\n\ | |
11886 | Arguments, if given, should be one or more system call names\n\ | |
11887 | (if your system supports that), or system call numbers."), | |
11888 | catch_syscall_command_1, | |
11889 | catch_syscall_completer, | |
44feb3ce TT |
11890 | CATCH_PERMANENT, |
11891 | CATCH_TEMPORARY); | |
44feb3ce TT |
11892 | add_catch_command ("exception", _("\ |
11893 | Catch Ada exceptions, when raised.\n\ | |
11894 | With an argument, catch only exceptions with the given name."), | |
11895 | catch_ada_exception_command, | |
a96d9b2e | 11896 | NULL, |
44feb3ce TT |
11897 | CATCH_PERMANENT, |
11898 | CATCH_TEMPORARY); | |
11899 | add_catch_command ("assert", _("\ | |
11900 | Catch failed Ada assertions, when raised.\n\ | |
11901 | With an argument, catch only exceptions with the given name."), | |
11902 | catch_assert_command, | |
a96d9b2e | 11903 | NULL, |
44feb3ce TT |
11904 | CATCH_PERMANENT, |
11905 | CATCH_TEMPORARY); | |
c5aa993b | 11906 | |
1bedd215 AC |
11907 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
11908 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 11909 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 11910 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
11911 | an expression changes.\n\ |
11912 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
11913 | the memory to which it refers.")); | |
65d12d83 | 11914 | set_cmd_completer (c, expression_completer); |
c906108c | 11915 | |
1bedd215 AC |
11916 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
11917 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 11918 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 11919 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
11920 | an expression is read.\n\ |
11921 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
11922 | the memory to which it refers.")); | |
65d12d83 | 11923 | set_cmd_completer (c, expression_completer); |
c906108c | 11924 | |
1bedd215 AC |
11925 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
11926 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 11927 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 11928 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
11929 | an expression is either read or written.\n\ |
11930 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
11931 | the memory to which it refers.")); | |
65d12d83 | 11932 | set_cmd_completer (c, expression_completer); |
c906108c | 11933 | |
d77f58be SS |
11934 | add_info ("watchpoints", watchpoints_info, _("\ |
11935 | Status of watchpoints, or watchpoint number NUMBER.")); | |
11936 | ||
c906108c SS |
11937 | |
11938 | ||
920d2a44 AC |
11939 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
11940 | respond to changes - contrary to the description. */ | |
85c07804 AC |
11941 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
11942 | &can_use_hw_watchpoints, _("\ | |
11943 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
11944 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
11945 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
11946 | such is available. (However, any hardware watchpoints that were\n\ | |
11947 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
11948 | hardware.)"), |
11949 | NULL, | |
920d2a44 | 11950 | show_can_use_hw_watchpoints, |
85c07804 | 11951 | &setlist, &showlist); |
c906108c SS |
11952 | |
11953 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 11954 | |
1042e4c0 SS |
11955 | /* Tracepoint manipulation commands. */ |
11956 | ||
11957 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
11958 | Set a tracepoint at specified line or function.\n\ | |
11959 | \n" | |
11960 | BREAK_ARGS_HELP ("trace") "\n\ | |
11961 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11962 | set_cmd_completer (c, location_completer); | |
11963 | ||
11964 | add_com_alias ("tp", "trace", class_alias, 0); | |
11965 | add_com_alias ("tr", "trace", class_alias, 1); | |
11966 | add_com_alias ("tra", "trace", class_alias, 1); | |
11967 | add_com_alias ("trac", "trace", class_alias, 1); | |
11968 | ||
7a697b8d SS |
11969 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
11970 | Set a fast tracepoint at specified line or function.\n\ | |
11971 | \n" | |
11972 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
11973 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
11974 | set_cmd_completer (c, location_completer); | |
11975 | ||
0fb4aa4b PA |
11976 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
11977 | Set a static tracepoint at specified line, function or marker.\n\ | |
11978 | \n\ | |
11979 | strace [LOCATION] [if CONDITION]\n\ | |
11980 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
11981 | or -m MARKER_ID.\n\ | |
11982 | If a line number is specified, probe the marker at start of code\n\ | |
11983 | for that line. If a function is specified, probe the marker at start\n\ | |
11984 | of code for that function. If an address is specified, probe the marker\n\ | |
11985 | at that exact address. If a marker id is specified, probe the marker\n\ | |
11986 | with that name. With no LOCATION, uses current execution address of\n\ | |
11987 | the selected stack frame.\n\ | |
11988 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
11989 | This collects arbitrary user data passed in the probe point call to the\n\ | |
11990 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
11991 | by printing the $_sdata variable like any other convenience variable.\n\ | |
11992 | \n\ | |
11993 | CONDITION is a boolean expression.\n\ | |
11994 | \n\ | |
d41c0fc8 PA |
11995 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
11996 | conditions are different.\n\ | |
0fb4aa4b PA |
11997 | \n\ |
11998 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
11999 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12000 | set_cmd_completer (c, location_completer); | |
12001 | ||
1042e4c0 SS |
12002 | add_info ("tracepoints", tracepoints_info, _("\ |
12003 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
12004 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
12005 | last tracepoint set.")); | |
12006 | ||
12007 | add_info_alias ("tp", "tracepoints", 1); | |
12008 | ||
12009 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
12010 | Delete specified tracepoints.\n\ | |
12011 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12012 | No argument means delete all tracepoints."), | |
12013 | &deletelist); | |
12014 | ||
12015 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
12016 | Disable specified tracepoints.\n\ | |
12017 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12018 | No argument means disable all tracepoints."), | |
12019 | &disablelist); | |
12020 | deprecate_cmd (c, "disable"); | |
12021 | ||
12022 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
12023 | Enable specified tracepoints.\n\ | |
12024 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12025 | No argument means enable all tracepoints."), | |
12026 | &enablelist); | |
12027 | deprecate_cmd (c, "enable"); | |
12028 | ||
12029 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
12030 | Set the passcount for a tracepoint.\n\ | |
12031 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
12032 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
12033 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
12034 | ||
6149aea9 PA |
12035 | add_prefix_cmd ("save", class_breakpoint, save_command, |
12036 | _("Save breakpoint definitions as a script."), | |
12037 | &save_cmdlist, "save ", | |
12038 | 0/*allow-unknown*/, &cmdlist); | |
12039 | ||
12040 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
12041 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 12042 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
12043 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
12044 | session to restore them."), | |
12045 | &save_cmdlist); | |
12046 | set_cmd_completer (c, filename_completer); | |
12047 | ||
12048 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 12049 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
12050 | Use the 'source' command in another debug session to restore them."), |
12051 | &save_cmdlist); | |
1042e4c0 SS |
12052 | set_cmd_completer (c, filename_completer); |
12053 | ||
6149aea9 PA |
12054 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
12055 | deprecate_cmd (c, "save tracepoints"); | |
12056 | ||
1bedd215 | 12057 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12058 | Breakpoint specific settings\n\ |
12059 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12060 | pending breakpoint behavior"), |
fa8d40ab JJ |
12061 | &breakpoint_set_cmdlist, "set breakpoint ", |
12062 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 12063 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12064 | Breakpoint specific settings\n\ |
12065 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12066 | pending breakpoint behavior"), |
fa8d40ab JJ |
12067 | &breakpoint_show_cmdlist, "show breakpoint ", |
12068 | 0/*allow-unknown*/, &showlist); | |
12069 | ||
7915a72c AC |
12070 | add_setshow_auto_boolean_cmd ("pending", no_class, |
12071 | &pending_break_support, _("\ | |
12072 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
12073 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
12074 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
12075 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
12076 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 12077 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 12078 | NULL, |
920d2a44 | 12079 | show_pending_break_support, |
6e1d7d6c AC |
12080 | &breakpoint_set_cmdlist, |
12081 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
12082 | |
12083 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
12084 | |
12085 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
12086 | &automatic_hardware_breakpoints, _("\ | |
12087 | Set automatic usage of hardware breakpoints."), _("\ | |
12088 | Show automatic usage of hardware breakpoints."), _("\ | |
12089 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
12090 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
12091 | a warning will be emitted for such breakpoints."), | |
12092 | NULL, | |
12093 | show_automatic_hardware_breakpoints, | |
12094 | &breakpoint_set_cmdlist, | |
12095 | &breakpoint_show_cmdlist); | |
74960c60 | 12096 | |
33e5cbd6 PA |
12097 | add_setshow_enum_cmd ("always-inserted", class_support, |
12098 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
12099 | Set mode for inserting breakpoints."), _("\ |
12100 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
12101 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
12102 | resumed, and removed when execution stops. When this mode is on,\n\ | |
12103 | breakpoints are inserted immediately and removed only when the user\n\ | |
12104 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
12105 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
12106 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
12107 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
12108 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
12109 | NULL, |
12110 | &show_always_inserted_mode, | |
12111 | &breakpoint_set_cmdlist, | |
12112 | &breakpoint_show_cmdlist); | |
765dc015 VP |
12113 | |
12114 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
12115 | |
12116 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 12117 | } |