Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
7b6bb8da | 5 | 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
a6d9a66e | 23 | #include "arch-utils.h" |
c906108c | 24 | #include <ctype.h> |
776592bf | 25 | #include "hashtab.h" |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
1042e4c0 | 29 | #include "tracepoint.h" |
c906108c SS |
30 | #include "gdbtypes.h" |
31 | #include "expression.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "value.h" | |
35 | #include "command.h" | |
36 | #include "inferior.h" | |
37 | #include "gdbthread.h" | |
38 | #include "target.h" | |
39 | #include "language.h" | |
40 | #include "gdb_string.h" | |
41 | #include "demangle.h" | |
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" |
e9cafbcc | 65 | #include "cli/cli-utils.h" |
c906108c | 66 | |
1042e4c0 SS |
67 | /* readline include files */ |
68 | #include "readline/readline.h" | |
69 | #include "readline/history.h" | |
70 | ||
71 | /* readline defines this. */ | |
72 | #undef savestring | |
73 | ||
034dad6f | 74 | #include "mi/mi-common.h" |
104c1213 | 75 | |
44feb3ce TT |
76 | /* Arguments to pass as context to some catch command handlers. */ |
77 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
78 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 79 | |
4a64f543 | 80 | /* Prototypes for local functions. */ |
c906108c | 81 | |
a14ed312 | 82 | static void enable_delete_command (char *, int); |
c906108c | 83 | |
a14ed312 | 84 | static void enable_once_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void disable_command (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void enable_command (char *, int); |
c906108c | 89 | |
95a42b64 TT |
90 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
91 | void *), | |
92 | void *); | |
c906108c | 93 | |
a14ed312 | 94 | static void ignore_command (char *, int); |
c906108c | 95 | |
4efb68b1 | 96 | static int breakpoint_re_set_one (void *); |
c906108c | 97 | |
a14ed312 | 98 | static void clear_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void catch_command (char *, int); |
c906108c | 101 | |
e09342b5 | 102 | static int can_use_hardware_watchpoint (struct value *, int); |
c906108c | 103 | |
98deb0da | 104 | static void break_command_1 (char *, int, int); |
c906108c | 105 | |
a14ed312 | 106 | static void mention (struct breakpoint *); |
c906108c | 107 | |
4a64f543 MS |
108 | /* This function is used in gdbtk sources and thus can not be made |
109 | static. */ | |
63c252f8 | 110 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
a6d9a66e UW |
111 | struct symtab_and_line, |
112 | enum bptype); | |
c906108c | 113 | |
76897487 KB |
114 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
115 | ||
a6d9a66e UW |
116 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
117 | CORE_ADDR bpaddr, | |
88f7da05 | 118 | enum bptype bptype); |
76897487 | 119 | |
6c95b8df PA |
120 | static void describe_other_breakpoints (struct gdbarch *, |
121 | struct program_space *, CORE_ADDR, | |
5af949e3 | 122 | struct obj_section *, int); |
c906108c | 123 | |
6c95b8df PA |
124 | static int breakpoint_address_match (struct address_space *aspace1, |
125 | CORE_ADDR addr1, | |
126 | struct address_space *aspace2, | |
127 | CORE_ADDR addr2); | |
128 | ||
85d721b8 PA |
129 | static int watchpoint_locations_match (struct bp_location *loc1, |
130 | struct bp_location *loc2); | |
131 | ||
a14ed312 | 132 | static void breakpoints_info (char *, int); |
c906108c | 133 | |
d77f58be SS |
134 | static void watchpoints_info (char *, int); |
135 | ||
e5a67952 MS |
136 | static int breakpoint_1 (char *, int, |
137 | int (*) (const struct breakpoint *)); | |
c906108c | 138 | |
4efb68b1 | 139 | static int breakpoint_cond_eval (void *); |
c906108c | 140 | |
4efb68b1 | 141 | static void cleanup_executing_breakpoints (void *); |
c906108c | 142 | |
a14ed312 | 143 | static void commands_command (char *, int); |
c906108c | 144 | |
a14ed312 | 145 | static void condition_command (char *, int); |
c906108c | 146 | |
c5aa993b JM |
147 | typedef enum |
148 | { | |
149 | mark_inserted, | |
150 | mark_uninserted | |
151 | } | |
152 | insertion_state_t; | |
c906108c | 153 | |
0bde7532 | 154 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 155 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 156 | |
a14ed312 | 157 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
158 | |
159 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 160 | |
4efb68b1 | 161 | static int watchpoint_check (void *); |
c906108c | 162 | |
a14ed312 | 163 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 164 | |
a14ed312 | 165 | static int hw_breakpoint_used_count (void); |
c906108c | 166 | |
a14ed312 | 167 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 168 | |
a14ed312 | 169 | static void hbreak_command (char *, int); |
c906108c | 170 | |
a14ed312 | 171 | static void thbreak_command (char *, int); |
c906108c | 172 | |
a14ed312 | 173 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 174 | |
a14ed312 | 175 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 176 | |
a14ed312 | 177 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 178 | |
a14ed312 | 179 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 180 | |
a14ed312 | 181 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 182 | |
d85310f7 MS |
183 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
184 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 185 | |
a14ed312 | 186 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 187 | |
d03285ec UW |
188 | static void detach_single_step_breakpoints (void); |
189 | ||
6c95b8df PA |
190 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
191 | CORE_ADDR pc); | |
1aafd4da | 192 | |
fe3f5fa8 | 193 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
194 | static void incref_bp_location (struct bp_location *loc); |
195 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 196 | |
39d61571 | 197 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 198 | |
b60e7edf | 199 | static void update_global_location_list (int); |
a5606eee | 200 | |
b60e7edf | 201 | static void update_global_location_list_nothrow (int); |
74960c60 | 202 | |
d77f58be | 203 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 | 204 | |
d77f58be | 205 | static int is_watchpoint (const struct breakpoint *bpt); |
60e1c644 | 206 | |
74960c60 | 207 | static void insert_breakpoint_locations (void); |
a5606eee | 208 | |
a96d9b2e SDJ |
209 | static int syscall_catchpoint_p (struct breakpoint *b); |
210 | ||
1042e4c0 SS |
211 | static void tracepoints_info (char *, int); |
212 | ||
213 | static void delete_trace_command (char *, int); | |
214 | ||
215 | static void enable_trace_command (char *, int); | |
216 | ||
217 | static void disable_trace_command (char *, int); | |
218 | ||
219 | static void trace_pass_command (char *, int); | |
220 | ||
0fb4aa4b PA |
221 | /* Assuming we're creating a static tracepoint, does S look like a |
222 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
223 | #define is_marker_spec(s) \ | |
f5a8e22b | 224 | (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) |
0fb4aa4b | 225 | |
5cea2a26 PA |
226 | /* A reference-counted struct command_line. This lets multiple |
227 | breakpoints share a single command list. */ | |
228 | struct counted_command_line | |
229 | { | |
230 | /* The reference count. */ | |
231 | int refc; | |
232 | ||
233 | /* The command list. */ | |
234 | struct command_line *commands; | |
235 | }; | |
236 | ||
237 | struct command_line * | |
238 | breakpoint_commands (struct breakpoint *b) | |
239 | { | |
240 | return b->commands ? b->commands->commands : NULL; | |
241 | } | |
3daf8fe5 | 242 | |
f3b1572e PA |
243 | /* Flag indicating that a command has proceeded the inferior past the |
244 | current breakpoint. */ | |
245 | ||
246 | static int breakpoint_proceeded; | |
247 | ||
2cec12e5 AR |
248 | static const char * |
249 | bpdisp_text (enum bpdisp disp) | |
250 | { | |
4a64f543 MS |
251 | /* NOTE: the following values are a part of MI protocol and |
252 | represent values of 'disp' field returned when inferior stops at | |
253 | a breakpoint. */ | |
bc043ef3 | 254 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 255 | |
2cec12e5 AR |
256 | return bpdisps[(int) disp]; |
257 | } | |
c906108c | 258 | |
4a64f543 | 259 | /* Prototypes for exported functions. */ |
c906108c | 260 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 261 | if such is available. */ |
c906108c SS |
262 | static int can_use_hw_watchpoints; |
263 | ||
920d2a44 AC |
264 | static void |
265 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
266 | struct cmd_list_element *c, | |
267 | const char *value) | |
268 | { | |
3e43a32a MS |
269 | fprintf_filtered (file, |
270 | _("Debugger's willingness to use " | |
271 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
272 | value); |
273 | } | |
274 | ||
fa8d40ab JJ |
275 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
276 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 277 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
278 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
279 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
280 | static void |
281 | show_pending_break_support (struct ui_file *file, int from_tty, | |
282 | struct cmd_list_element *c, | |
283 | const char *value) | |
284 | { | |
3e43a32a MS |
285 | fprintf_filtered (file, |
286 | _("Debugger's behavior regarding " | |
287 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
288 | value); |
289 | } | |
fa8d40ab | 290 | |
765dc015 | 291 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 292 | set with "break" but falling in read-only memory. |
765dc015 VP |
293 | If 0, gdb will warn about such breakpoints, but won't automatically |
294 | use hardware breakpoints. */ | |
295 | static int automatic_hardware_breakpoints; | |
296 | static void | |
297 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
298 | struct cmd_list_element *c, | |
299 | const char *value) | |
300 | { | |
3e43a32a MS |
301 | fprintf_filtered (file, |
302 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
303 | value); |
304 | } | |
305 | ||
33e5cbd6 PA |
306 | /* If on, gdb will keep breakpoints inserted even as inferior is |
307 | stopped, and immediately insert any new breakpoints. If off, gdb | |
308 | will insert breakpoints into inferior only when resuming it, and | |
309 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
310 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
311 | ||
312 | static const char always_inserted_auto[] = "auto"; | |
313 | static const char always_inserted_on[] = "on"; | |
314 | static const char always_inserted_off[] = "off"; | |
315 | static const char *always_inserted_enums[] = { | |
316 | always_inserted_auto, | |
317 | always_inserted_off, | |
318 | always_inserted_on, | |
319 | NULL | |
320 | }; | |
321 | static const char *always_inserted_mode = always_inserted_auto; | |
322 | static void | |
74960c60 | 323 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 324 | struct cmd_list_element *c, const char *value) |
74960c60 | 325 | { |
33e5cbd6 | 326 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
327 | fprintf_filtered (file, |
328 | _("Always inserted breakpoint " | |
329 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
330 | value, |
331 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
332 | else | |
3e43a32a MS |
333 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
334 | value); | |
74960c60 VP |
335 | } |
336 | ||
33e5cbd6 PA |
337 | int |
338 | breakpoints_always_inserted_mode (void) | |
339 | { | |
340 | return (always_inserted_mode == always_inserted_on | |
341 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
342 | } | |
765dc015 | 343 | |
a14ed312 | 344 | void _initialize_breakpoint (void); |
c906108c | 345 | |
c906108c SS |
346 | /* Are we executing breakpoint commands? */ |
347 | static int executing_breakpoint_commands; | |
348 | ||
c02f5703 MS |
349 | /* Are overlay event breakpoints enabled? */ |
350 | static int overlay_events_enabled; | |
351 | ||
e09342b5 TJB |
352 | /* See description in breakpoint.h. */ |
353 | int target_exact_watchpoints = 0; | |
354 | ||
c906108c | 355 | /* Walk the following statement or block through all breakpoints. |
4a64f543 MS |
356 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the |
357 | current breakpoint. */ | |
c906108c | 358 | |
5c44784c | 359 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 360 | |
5c44784c JM |
361 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
362 | for (B = breakpoint_chain; \ | |
363 | B ? (TMP=B->next, 1): 0; \ | |
364 | B = TMP) | |
c906108c | 365 | |
4a64f543 MS |
366 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
367 | not provided so update_global_location_list must not be called | |
368 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 369 | |
876fa593 JK |
370 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
371 | for (BP_TMP = bp_location; \ | |
372 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
373 | BP_TMP++) | |
7cc221ef | 374 | |
1042e4c0 SS |
375 | /* Iterator for tracepoints only. */ |
376 | ||
377 | #define ALL_TRACEPOINTS(B) \ | |
378 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 379 | if (is_tracepoint (B)) |
1042e4c0 | 380 | |
7cc221ef | 381 | /* Chains of all breakpoints defined. */ |
c906108c SS |
382 | |
383 | struct breakpoint *breakpoint_chain; | |
384 | ||
876fa593 JK |
385 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
386 | ||
387 | static struct bp_location **bp_location; | |
388 | ||
389 | /* Number of elements of BP_LOCATION. */ | |
390 | ||
391 | static unsigned bp_location_count; | |
392 | ||
4a64f543 MS |
393 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
394 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
395 | result from bp_location_has_shadow. You can use it for roughly | |
396 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
397 | an address you need to read. */ | |
876fa593 JK |
398 | |
399 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
400 | ||
4a64f543 MS |
401 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
402 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
403 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
404 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
405 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
406 | |
407 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 408 | |
4a64f543 MS |
409 | /* The locations that no longer correspond to any breakpoint, unlinked |
410 | from bp_location array, but for which a hit may still be reported | |
411 | by a target. */ | |
20874c92 VP |
412 | VEC(bp_location_p) *moribund_locations = NULL; |
413 | ||
c906108c SS |
414 | /* Number of last breakpoint made. */ |
415 | ||
95a42b64 TT |
416 | static int breakpoint_count; |
417 | ||
86b17b60 PA |
418 | /* The value of `breakpoint_count' before the last command that |
419 | created breakpoints. If the last (break-like) command created more | |
420 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
421 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
422 | static int prev_breakpoint_count; | |
c906108c | 423 | |
1042e4c0 SS |
424 | /* Number of last tracepoint made. */ |
425 | ||
95a42b64 | 426 | static int tracepoint_count; |
1042e4c0 | 427 | |
6149aea9 PA |
428 | static struct cmd_list_element *breakpoint_set_cmdlist; |
429 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 430 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 431 | |
468d015d JJ |
432 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
433 | static int | |
434 | breakpoint_enabled (struct breakpoint *b) | |
435 | { | |
0d381245 | 436 | return (b->enable_state == bp_enabled); |
468d015d JJ |
437 | } |
438 | ||
c906108c SS |
439 | /* Set breakpoint count to NUM. */ |
440 | ||
95a42b64 | 441 | static void |
fba45db2 | 442 | set_breakpoint_count (int num) |
c906108c | 443 | { |
86b17b60 | 444 | prev_breakpoint_count = breakpoint_count; |
c906108c | 445 | breakpoint_count = num; |
4fa62494 | 446 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
447 | } |
448 | ||
86b17b60 PA |
449 | /* Used by `start_rbreak_breakpoints' below, to record the current |
450 | breakpoint count before "rbreak" creates any breakpoint. */ | |
451 | static int rbreak_start_breakpoint_count; | |
452 | ||
95a42b64 TT |
453 | /* Called at the start an "rbreak" command to record the first |
454 | breakpoint made. */ | |
86b17b60 | 455 | |
95a42b64 TT |
456 | void |
457 | start_rbreak_breakpoints (void) | |
458 | { | |
86b17b60 | 459 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
460 | } |
461 | ||
462 | /* Called at the end of an "rbreak" command to record the last | |
463 | breakpoint made. */ | |
86b17b60 | 464 | |
95a42b64 TT |
465 | void |
466 | end_rbreak_breakpoints (void) | |
467 | { | |
86b17b60 | 468 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
469 | } |
470 | ||
4a64f543 | 471 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
472 | |
473 | void | |
fba45db2 | 474 | clear_breakpoint_hit_counts (void) |
c906108c SS |
475 | { |
476 | struct breakpoint *b; | |
477 | ||
478 | ALL_BREAKPOINTS (b) | |
479 | b->hit_count = 0; | |
480 | } | |
481 | ||
9add0f1b TT |
482 | /* Allocate a new counted_command_line with reference count of 1. |
483 | The new structure owns COMMANDS. */ | |
484 | ||
485 | static struct counted_command_line * | |
486 | alloc_counted_command_line (struct command_line *commands) | |
487 | { | |
488 | struct counted_command_line *result | |
489 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 490 | |
9add0f1b TT |
491 | result->refc = 1; |
492 | result->commands = commands; | |
493 | return result; | |
494 | } | |
495 | ||
496 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
497 | ||
498 | static void | |
499 | incref_counted_command_line (struct counted_command_line *cmd) | |
500 | { | |
501 | if (cmd) | |
502 | ++cmd->refc; | |
503 | } | |
504 | ||
505 | /* Decrement reference count. If the reference count reaches 0, | |
506 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
507 | nothing if *CMDP is NULL. */ | |
508 | ||
509 | static void | |
510 | decref_counted_command_line (struct counted_command_line **cmdp) | |
511 | { | |
512 | if (*cmdp) | |
513 | { | |
514 | if (--(*cmdp)->refc == 0) | |
515 | { | |
516 | free_command_lines (&(*cmdp)->commands); | |
517 | xfree (*cmdp); | |
518 | } | |
519 | *cmdp = NULL; | |
520 | } | |
521 | } | |
522 | ||
523 | /* A cleanup function that calls decref_counted_command_line. */ | |
524 | ||
525 | static void | |
526 | do_cleanup_counted_command_line (void *arg) | |
527 | { | |
528 | decref_counted_command_line (arg); | |
529 | } | |
530 | ||
531 | /* Create a cleanup that calls decref_counted_command_line on the | |
532 | argument. */ | |
533 | ||
534 | static struct cleanup * | |
535 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
536 | { | |
537 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
538 | } | |
539 | ||
c906108c SS |
540 | /* Default address, symtab and line to put a breakpoint at |
541 | for "break" command with no arg. | |
4a64f543 | 542 | If default_breakpoint_valid is zero, the other three are |
c906108c SS |
543 | not valid, and "break" with no arg is an error. |
544 | ||
545 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
546 | ||
547 | int default_breakpoint_valid; | |
548 | CORE_ADDR default_breakpoint_address; | |
549 | struct symtab *default_breakpoint_symtab; | |
550 | int default_breakpoint_line; | |
6c95b8df PA |
551 | struct program_space *default_breakpoint_pspace; |
552 | ||
c906108c | 553 | \f |
48cb2d85 VP |
554 | /* Return the breakpoint with the specified number, or NULL |
555 | if the number does not refer to an existing breakpoint. */ | |
556 | ||
557 | struct breakpoint * | |
558 | get_breakpoint (int num) | |
559 | { | |
560 | struct breakpoint *b; | |
561 | ||
562 | ALL_BREAKPOINTS (b) | |
563 | if (b->number == num) | |
564 | return b; | |
565 | ||
566 | return NULL; | |
567 | } | |
5c44784c | 568 | |
c906108c | 569 | \f |
adc36818 PM |
570 | |
571 | void | |
572 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
573 | int from_tty) | |
574 | { | |
575 | struct bp_location *loc = b->loc; | |
576 | ||
577 | for (; loc; loc = loc->next) | |
578 | { | |
579 | xfree (loc->cond); | |
580 | loc->cond = NULL; | |
581 | } | |
582 | xfree (b->cond_string); | |
583 | b->cond_string = NULL; | |
584 | xfree (b->cond_exp); | |
585 | b->cond_exp = NULL; | |
586 | ||
587 | if (*exp == 0) | |
588 | { | |
589 | if (from_tty) | |
590 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
591 | } | |
592 | else | |
593 | { | |
594 | char *arg = exp; | |
cc59ec59 | 595 | |
adc36818 PM |
596 | /* I don't know if it matters whether this is the string the user |
597 | typed in or the decompiled expression. */ | |
598 | b->cond_string = xstrdup (arg); | |
599 | b->condition_not_parsed = 0; | |
600 | ||
601 | if (is_watchpoint (b)) | |
602 | { | |
603 | innermost_block = NULL; | |
604 | arg = exp; | |
605 | b->cond_exp = parse_exp_1 (&arg, 0, 0); | |
606 | if (*arg) | |
607 | error (_("Junk at end of expression")); | |
608 | b->cond_exp_valid_block = innermost_block; | |
609 | } | |
610 | else | |
611 | { | |
612 | for (loc = b->loc; loc; loc = loc->next) | |
613 | { | |
614 | arg = exp; | |
615 | loc->cond = | |
616 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
617 | if (*arg) | |
618 | error (_("Junk at end of expression")); | |
619 | } | |
620 | } | |
621 | } | |
622 | breakpoints_changed (); | |
623 | observer_notify_breakpoint_modified (b->number); | |
624 | } | |
625 | ||
c906108c SS |
626 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
627 | ||
628 | static void | |
fba45db2 | 629 | condition_command (char *arg, int from_tty) |
c906108c | 630 | { |
52f0bd74 | 631 | struct breakpoint *b; |
c906108c | 632 | char *p; |
52f0bd74 | 633 | int bnum; |
c906108c SS |
634 | |
635 | if (arg == 0) | |
e2e0b3e5 | 636 | error_no_arg (_("breakpoint number")); |
c906108c SS |
637 | |
638 | p = arg; | |
639 | bnum = get_number (&p); | |
5c44784c | 640 | if (bnum == 0) |
8a3fe4f8 | 641 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
642 | |
643 | ALL_BREAKPOINTS (b) | |
644 | if (b->number == bnum) | |
2f069f6f | 645 | { |
2566ad2d | 646 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
647 | return; |
648 | } | |
c906108c | 649 | |
8a3fe4f8 | 650 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
651 | } |
652 | ||
a7bdde9e VP |
653 | /* Check that COMMAND do not contain commands that are suitable |
654 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
655 | Throw if any such commands is found. */ |
656 | ||
a7bdde9e VP |
657 | static void |
658 | check_no_tracepoint_commands (struct command_line *commands) | |
659 | { | |
660 | struct command_line *c; | |
cc59ec59 | 661 | |
a7bdde9e VP |
662 | for (c = commands; c; c = c->next) |
663 | { | |
664 | int i; | |
665 | ||
666 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
667 | error (_("The 'while-stepping' command can " |
668 | "only be used for tracepoints")); | |
a7bdde9e VP |
669 | |
670 | for (i = 0; i < c->body_count; ++i) | |
671 | check_no_tracepoint_commands ((c->body_list)[i]); | |
672 | ||
673 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 674 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
675 | command directly. */ |
676 | if (strstr (c->line, "collect ") == c->line) | |
677 | error (_("The 'collect' command can only be used for tracepoints")); | |
678 | ||
51661e93 VP |
679 | if (strstr (c->line, "teval ") == c->line) |
680 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
681 | } |
682 | } | |
683 | ||
d77f58be SS |
684 | /* Encapsulate tests for different types of tracepoints. */ |
685 | ||
a7bdde9e | 686 | int |
d77f58be | 687 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 688 | { |
0fb4aa4b PA |
689 | return (b->type == bp_tracepoint |
690 | || b->type == bp_fast_tracepoint | |
691 | || b->type == bp_static_tracepoint); | |
a7bdde9e | 692 | } |
d77f58be | 693 | |
95a42b64 TT |
694 | /* A helper function that validsates that COMMANDS are valid for a |
695 | breakpoint. This function will throw an exception if a problem is | |
696 | found. */ | |
48cb2d85 | 697 | |
95a42b64 TT |
698 | static void |
699 | validate_commands_for_breakpoint (struct breakpoint *b, | |
700 | struct command_line *commands) | |
48cb2d85 | 701 | { |
d77f58be | 702 | if (is_tracepoint (b)) |
a7bdde9e | 703 | { |
4a64f543 MS |
704 | /* We need to verify that each top-level element of commands is |
705 | valid for tracepoints, that there's at most one | |
706 | while-stepping element, and that while-stepping's body has | |
707 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
708 | struct command_line *c; |
709 | struct command_line *while_stepping = 0; | |
710 | for (c = commands; c; c = c->next) | |
711 | { | |
a7bdde9e VP |
712 | if (c->control_type == while_stepping_control) |
713 | { | |
714 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
715 | error (_("The 'while-stepping' command " |
716 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 717 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
718 | error (_("The 'while-stepping' command " |
719 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
720 | |
721 | if (while_stepping) | |
3e43a32a MS |
722 | error (_("The 'while-stepping' command " |
723 | "can be used only once")); | |
a7bdde9e VP |
724 | else |
725 | while_stepping = c; | |
726 | } | |
727 | } | |
728 | if (while_stepping) | |
729 | { | |
730 | struct command_line *c2; | |
731 | ||
732 | gdb_assert (while_stepping->body_count == 1); | |
733 | c2 = while_stepping->body_list[0]; | |
734 | for (; c2; c2 = c2->next) | |
735 | { | |
a7bdde9e VP |
736 | if (c2->control_type == while_stepping_control) |
737 | error (_("The 'while-stepping' command cannot be nested")); | |
738 | } | |
739 | } | |
740 | } | |
741 | else | |
742 | { | |
743 | check_no_tracepoint_commands (commands); | |
744 | } | |
95a42b64 TT |
745 | } |
746 | ||
0fb4aa4b PA |
747 | /* Return a vector of all the static tracepoints set at ADDR. The |
748 | caller is responsible for releasing the vector. */ | |
749 | ||
750 | VEC(breakpoint_p) * | |
751 | static_tracepoints_here (CORE_ADDR addr) | |
752 | { | |
753 | struct breakpoint *b; | |
754 | VEC(breakpoint_p) *found = 0; | |
755 | struct bp_location *loc; | |
756 | ||
757 | ALL_BREAKPOINTS (b) | |
758 | if (b->type == bp_static_tracepoint) | |
759 | { | |
760 | for (loc = b->loc; loc; loc = loc->next) | |
761 | if (loc->address == addr) | |
762 | VEC_safe_push(breakpoint_p, found, b); | |
763 | } | |
764 | ||
765 | return found; | |
766 | } | |
767 | ||
95a42b64 | 768 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 769 | validate that only allowed commands are included. */ |
95a42b64 TT |
770 | |
771 | void | |
4a64f543 MS |
772 | breakpoint_set_commands (struct breakpoint *b, |
773 | struct command_line *commands) | |
95a42b64 TT |
774 | { |
775 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 776 | |
9add0f1b TT |
777 | decref_counted_command_line (&b->commands); |
778 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
779 | breakpoints_changed (); |
780 | observer_notify_breakpoint_modified (b->number); | |
781 | } | |
782 | ||
45a43567 TT |
783 | /* Set the internal `silent' flag on the breakpoint. Note that this |
784 | is not the same as the "silent" that may appear in the breakpoint's | |
785 | commands. */ | |
786 | ||
787 | void | |
788 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
789 | { | |
790 | int old_silent = b->silent; | |
791 | ||
792 | b->silent = silent; | |
793 | if (old_silent != silent) | |
794 | observer_notify_breakpoint_modified (b->number); | |
795 | } | |
796 | ||
797 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
798 | breakpoint work for any thread. */ | |
799 | ||
800 | void | |
801 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
802 | { | |
803 | int old_thread = b->thread; | |
804 | ||
805 | b->thread = thread; | |
806 | if (old_thread != thread) | |
807 | observer_notify_breakpoint_modified (b->number); | |
808 | } | |
809 | ||
810 | /* Set the task for this breakpoint. If TASK is 0, make the | |
811 | breakpoint work for any task. */ | |
812 | ||
813 | void | |
814 | breakpoint_set_task (struct breakpoint *b, int task) | |
815 | { | |
816 | int old_task = b->task; | |
817 | ||
818 | b->task = task; | |
819 | if (old_task != task) | |
820 | observer_notify_breakpoint_modified (b->number); | |
821 | } | |
822 | ||
95a42b64 TT |
823 | void |
824 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
825 | { |
826 | struct breakpoint *b = closure; | |
cc59ec59 | 827 | |
a7bdde9e VP |
828 | validate_actionline (&line, b); |
829 | } | |
830 | ||
95a42b64 TT |
831 | /* A structure used to pass information through |
832 | map_breakpoint_numbers. */ | |
833 | ||
834 | struct commands_info | |
835 | { | |
836 | /* True if the command was typed at a tty. */ | |
837 | int from_tty; | |
86b17b60 PA |
838 | |
839 | /* The breakpoint range spec. */ | |
840 | char *arg; | |
841 | ||
95a42b64 TT |
842 | /* Non-NULL if the body of the commands are being read from this |
843 | already-parsed command. */ | |
844 | struct command_line *control; | |
86b17b60 | 845 | |
95a42b64 TT |
846 | /* The command lines read from the user, or NULL if they have not |
847 | yet been read. */ | |
848 | struct counted_command_line *cmd; | |
849 | }; | |
850 | ||
851 | /* A callback for map_breakpoint_numbers that sets the commands for | |
852 | commands_command. */ | |
853 | ||
c906108c | 854 | static void |
95a42b64 | 855 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 856 | { |
95a42b64 | 857 | struct commands_info *info = data; |
c906108c | 858 | |
95a42b64 TT |
859 | if (info->cmd == NULL) |
860 | { | |
861 | struct command_line *l; | |
5c44784c | 862 | |
95a42b64 TT |
863 | if (info->control != NULL) |
864 | l = copy_command_lines (info->control->body_list[0]); | |
865 | else | |
86b17b60 PA |
866 | { |
867 | struct cleanup *old_chain; | |
868 | char *str; | |
c5aa993b | 869 | |
3e43a32a MS |
870 | str = xstrprintf (_("Type commands for breakpoint(s) " |
871 | "%s, one per line."), | |
86b17b60 PA |
872 | info->arg); |
873 | ||
874 | old_chain = make_cleanup (xfree, str); | |
875 | ||
876 | l = read_command_lines (str, | |
877 | info->from_tty, 1, | |
d77f58be | 878 | (is_tracepoint (b) |
86b17b60 PA |
879 | ? check_tracepoint_command : 0), |
880 | b); | |
881 | ||
882 | do_cleanups (old_chain); | |
883 | } | |
a7bdde9e | 884 | |
95a42b64 TT |
885 | info->cmd = alloc_counted_command_line (l); |
886 | } | |
887 | ||
888 | /* If a breakpoint was on the list more than once, we don't need to | |
889 | do anything. */ | |
890 | if (b->commands != info->cmd) | |
891 | { | |
892 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
893 | incref_counted_command_line (info->cmd); | |
894 | decref_counted_command_line (&b->commands); | |
895 | b->commands = info->cmd; | |
896 | breakpoints_changed (); | |
897 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 898 | } |
95a42b64 TT |
899 | } |
900 | ||
901 | static void | |
4a64f543 MS |
902 | commands_command_1 (char *arg, int from_tty, |
903 | struct command_line *control) | |
95a42b64 TT |
904 | { |
905 | struct cleanup *cleanups; | |
906 | struct commands_info info; | |
907 | ||
908 | info.from_tty = from_tty; | |
909 | info.control = control; | |
910 | info.cmd = NULL; | |
911 | /* If we read command lines from the user, then `info' will hold an | |
912 | extra reference to the commands that we must clean up. */ | |
913 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
914 | ||
915 | if (arg == NULL || !*arg) | |
916 | { | |
86b17b60 | 917 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
918 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
919 | breakpoint_count); | |
95a42b64 TT |
920 | else if (breakpoint_count > 0) |
921 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
922 | else |
923 | { | |
924 | /* So that we don't try to free the incoming non-NULL | |
925 | argument in the cleanup below. Mapping breakpoint | |
926 | numbers will fail in this case. */ | |
927 | arg = NULL; | |
928 | } | |
95a42b64 | 929 | } |
9766ced4 SS |
930 | else |
931 | /* The command loop has some static state, so we need to preserve | |
932 | our argument. */ | |
933 | arg = xstrdup (arg); | |
86b17b60 PA |
934 | |
935 | if (arg != NULL) | |
936 | make_cleanup (xfree, arg); | |
937 | ||
938 | info.arg = arg; | |
95a42b64 TT |
939 | |
940 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
941 | ||
942 | if (info.cmd == NULL) | |
943 | error (_("No breakpoints specified.")); | |
944 | ||
945 | do_cleanups (cleanups); | |
946 | } | |
947 | ||
948 | static void | |
949 | commands_command (char *arg, int from_tty) | |
950 | { | |
951 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 952 | } |
40c03ae8 EZ |
953 | |
954 | /* Like commands_command, but instead of reading the commands from | |
955 | input stream, takes them from an already parsed command structure. | |
956 | ||
957 | This is used by cli-script.c to DTRT with breakpoint commands | |
958 | that are part of if and while bodies. */ | |
959 | enum command_control_type | |
960 | commands_from_control_command (char *arg, struct command_line *cmd) | |
961 | { | |
95a42b64 TT |
962 | commands_command_1 (arg, 0, cmd); |
963 | return simple_control; | |
40c03ae8 | 964 | } |
876fa593 JK |
965 | |
966 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
967 | ||
968 | static int | |
969 | bp_location_has_shadow (struct bp_location *bl) | |
970 | { | |
971 | if (bl->loc_type != bp_loc_software_breakpoint) | |
972 | return 0; | |
973 | if (!bl->inserted) | |
974 | return 0; | |
975 | if (bl->target_info.shadow_len == 0) | |
976 | /* bp isn't valid, or doesn't shadow memory. */ | |
977 | return 0; | |
978 | return 1; | |
979 | } | |
980 | ||
8defab1a | 981 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
982 | by replacing any memory breakpoints with their shadowed contents. |
983 | ||
984 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
985 | bl->address - bp_location_placed_address_before_address_max |
986 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
987 | The range we were requested to resolve shadows for is: |
988 | memaddr ... memaddr + len | |
989 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
990 | memaddr + len <= (bl->address |
991 | - bp_location_placed_address_before_address_max) | |
876fa593 | 992 | and: |
35df4500 | 993 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 994 | |
8defab1a DJ |
995 | void |
996 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 997 | { |
4a64f543 MS |
998 | /* Left boundary, right boundary and median element of our binary |
999 | search. */ | |
876fa593 JK |
1000 | unsigned bc_l, bc_r, bc; |
1001 | ||
4a64f543 MS |
1002 | /* Find BC_L which is a leftmost element which may affect BUF |
1003 | content. It is safe to report lower value but a failure to | |
1004 | report higher one. */ | |
876fa593 JK |
1005 | |
1006 | bc_l = 0; | |
1007 | bc_r = bp_location_count; | |
1008 | while (bc_l + 1 < bc_r) | |
1009 | { | |
35df4500 | 1010 | struct bp_location *bl; |
876fa593 JK |
1011 | |
1012 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1013 | bl = bp_location[bc]; |
876fa593 | 1014 | |
4a64f543 MS |
1015 | /* Check first BL->ADDRESS will not overflow due to the added |
1016 | constant. Then advance the left boundary only if we are sure | |
1017 | the BC element can in no way affect the BUF content (MEMADDR | |
1018 | to MEMADDR + LEN range). | |
876fa593 | 1019 | |
4a64f543 MS |
1020 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1021 | offset so that we cannot miss a breakpoint with its shadow | |
1022 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1023 | |
35df4500 TJB |
1024 | if ((bl->address + bp_location_shadow_len_after_address_max |
1025 | >= bl->address) | |
1026 | && (bl->address + bp_location_shadow_len_after_address_max | |
1027 | <= memaddr)) | |
876fa593 JK |
1028 | bc_l = bc; |
1029 | else | |
1030 | bc_r = bc; | |
1031 | } | |
1032 | ||
128070bb PA |
1033 | /* Due to the binary search above, we need to make sure we pick the |
1034 | first location that's at BC_L's address. E.g., if there are | |
1035 | multiple locations at the same address, BC_L may end up pointing | |
1036 | at a duplicate location, and miss the "master"/"inserted" | |
1037 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1038 | B: | |
1039 | ||
1040 | L1@A, L2@A, L3@B, ... | |
1041 | ||
1042 | BC_L could end up pointing at location L2, while the "master" | |
1043 | location could be L1. Since the `loc->inserted' flag is only set | |
1044 | on "master" locations, we'd forget to restore the shadow of L1 | |
1045 | and L2. */ | |
1046 | while (bc_l > 0 | |
1047 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1048 | bc_l--; | |
1049 | ||
876fa593 JK |
1050 | /* Now do full processing of the found relevant range of elements. */ |
1051 | ||
1052 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1053 | { |
35df4500 | 1054 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1055 | CORE_ADDR bp_addr = 0; |
1056 | int bp_size = 0; | |
1057 | int bptoffset = 0; | |
1058 | ||
35df4500 TJB |
1059 | /* bp_location array has BL->OWNER always non-NULL. */ |
1060 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1061 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1062 | bl->owner->number); |
ffce0d52 | 1063 | |
876fa593 JK |
1064 | /* Performance optimization: any futher element can no longer affect BUF |
1065 | content. */ | |
1066 | ||
35df4500 TJB |
1067 | if (bl->address >= bp_location_placed_address_before_address_max |
1068 | && memaddr + len <= (bl->address | |
1069 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1070 | break; |
1071 | ||
35df4500 | 1072 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1073 | continue; |
35df4500 | 1074 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1075 | current_program_space->aspace, 0)) |
1076 | continue; | |
1077 | ||
c5aa993b JM |
1078 | /* Addresses and length of the part of the breakpoint that |
1079 | we need to copy. */ | |
35df4500 TJB |
1080 | bp_addr = bl->target_info.placed_address; |
1081 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1082 | |
c5aa993b JM |
1083 | if (bp_addr + bp_size <= memaddr) |
1084 | /* The breakpoint is entirely before the chunk of memory we | |
1085 | are reading. */ | |
1086 | continue; | |
8defab1a | 1087 | |
c5aa993b JM |
1088 | if (bp_addr >= memaddr + len) |
1089 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1090 | reading. */ |
c5aa993b | 1091 | continue; |
c5aa993b | 1092 | |
8defab1a DJ |
1093 | /* Offset within shadow_contents. */ |
1094 | if (bp_addr < memaddr) | |
1095 | { | |
1096 | /* Only copy the second part of the breakpoint. */ | |
1097 | bp_size -= memaddr - bp_addr; | |
1098 | bptoffset = memaddr - bp_addr; | |
1099 | bp_addr = memaddr; | |
1100 | } | |
c5aa993b | 1101 | |
8defab1a DJ |
1102 | if (bp_addr + bp_size > memaddr + len) |
1103 | { | |
1104 | /* Only copy the first part of the breakpoint. */ | |
1105 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1106 | } | |
c5aa993b | 1107 | |
8defab1a | 1108 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1109 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1110 | } |
c906108c | 1111 | } |
c906108c | 1112 | \f |
c5aa993b | 1113 | |
60e1c644 PA |
1114 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1115 | ||
a5606eee | 1116 | static int |
d77f58be | 1117 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1118 | { |
1119 | return (bpt->type == bp_hardware_watchpoint | |
1120 | || bpt->type == bp_read_watchpoint | |
1121 | || bpt->type == bp_access_watchpoint); | |
1122 | } | |
7270d8f2 | 1123 | |
60e1c644 PA |
1124 | /* Return true if BPT is of any watchpoint kind, hardware or |
1125 | software. */ | |
1126 | ||
1127 | static int | |
d77f58be | 1128 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1129 | { |
1130 | return (is_hardware_watchpoint (bpt) | |
1131 | || bpt->type == bp_watchpoint); | |
1132 | } | |
1133 | ||
f6bc2008 PA |
1134 | /* Assuming that B is a watchpoint: returns true if the current thread |
1135 | and its running state are safe to evaluate or update watchpoint B. | |
1136 | Watchpoints on local expressions need to be evaluated in the | |
1137 | context of the thread that was current when the watchpoint was | |
1138 | created, and, that thread needs to be stopped to be able to select | |
1139 | the correct frame context. Watchpoints on global expressions can | |
1140 | be evaluated on any thread, and in any state. It is presently left | |
1141 | to the target allowing memory accesses when threads are | |
1142 | running. */ | |
1143 | ||
1144 | static int | |
1145 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1146 | { | |
1147 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1148 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1149 | && !is_executing (inferior_ptid))); | |
1150 | } | |
1151 | ||
567e1b4e JB |
1152 | /* Assuming that B is a watchpoint: |
1153 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1154 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1155 | - Evaluate the condition if there is one, and store the result |
1156 | in b->loc->cond. | |
a5606eee VP |
1157 | - Update the list of values that must be watched in B->loc. |
1158 | ||
4a64f543 MS |
1159 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1160 | nothing. If this is local watchpoint that is out of scope, delete | |
1161 | it. | |
1162 | ||
1163 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1164 | removed + inserted on each stop here. Normal breakpoints must | |
1165 | never be removed because they might be missed by a running thread | |
1166 | when debugging in non-stop mode. On the other hand, hardware | |
1167 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1168 | to each LWP since they are stored in each LWP's hardware debug | |
1169 | registers. Therefore, such LWP must be stopped first in order to | |
1170 | be able to modify its hardware watchpoints. | |
1171 | ||
1172 | Hardware watchpoints must be reset exactly once after being | |
1173 | presented to the user. It cannot be done sooner, because it would | |
1174 | reset the data used to present the watchpoint hit to the user. And | |
1175 | it must not be done later because it could display the same single | |
1176 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1177 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1178 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1179 | not user-visible - its hit is suppressed if the memory content has | |
1180 | not changed. | |
1181 | ||
1182 | The following constraints influence the location where we can reset | |
1183 | hardware watchpoints: | |
1184 | ||
1185 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1186 | called several times when GDB stops. | |
1187 | ||
1188 | [linux] | |
1189 | * Multiple hardware watchpoints can be hit at the same time, | |
1190 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1191 | hit at a time as the reason for stopping, and all the other hits | |
1192 | are presented later, one after the other, each time the user | |
1193 | requests the execution to be resumed. Execution is not resumed | |
1194 | for the threads still having pending hit event stored in | |
1195 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1196 | the inferior on the first stop the thread hit event is kept being | |
1197 | reported from its cached value by linux_nat_stopped_data_address | |
1198 | until the real thread resume happens after the watchpoint gets | |
1199 | presented and thus its LWP_INFO->STATUS gets reset. | |
1200 | ||
1201 | Therefore the hardware watchpoint hit can get safely reset on the | |
1202 | watchpoint removal from inferior. */ | |
a79d3c27 | 1203 | |
b40ce68a | 1204 | static void |
a5606eee | 1205 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1206 | { |
a5606eee | 1207 | int within_current_scope; |
a5606eee | 1208 | struct frame_id saved_frame_id; |
66076460 | 1209 | int frame_saved; |
a5606eee | 1210 | |
f6bc2008 PA |
1211 | /* If this is a local watchpoint, we only want to check if the |
1212 | watchpoint frame is in scope if the current thread is the thread | |
1213 | that was used to create the watchpoint. */ | |
1214 | if (!watchpoint_in_thread_scope (b)) | |
1215 | return; | |
1216 | ||
a5606eee VP |
1217 | if (b->disposition == disp_del_at_next_stop) |
1218 | return; | |
1219 | ||
66076460 | 1220 | frame_saved = 0; |
a5606eee VP |
1221 | |
1222 | /* Determine if the watchpoint is within scope. */ | |
1223 | if (b->exp_valid_block == NULL) | |
1224 | within_current_scope = 1; | |
1225 | else | |
1226 | { | |
b5db5dfc UW |
1227 | struct frame_info *fi = get_current_frame (); |
1228 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1229 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1230 | ||
1231 | /* If we're in a function epilogue, unwinding may not work | |
1232 | properly, so do not attempt to recreate locations at this | |
1233 | point. See similar comments in watchpoint_check. */ | |
1234 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1235 | return; | |
66076460 DJ |
1236 | |
1237 | /* Save the current frame's ID so we can restore it after | |
1238 | evaluating the watchpoint expression on its own frame. */ | |
1239 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1240 | took a frame parameter, so that we didn't have to change the | |
1241 | selected frame. */ | |
1242 | frame_saved = 1; | |
1243 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1244 | ||
a5606eee VP |
1245 | fi = frame_find_by_id (b->watchpoint_frame); |
1246 | within_current_scope = (fi != NULL); | |
1247 | if (within_current_scope) | |
1248 | select_frame (fi); | |
1249 | } | |
1250 | ||
b5db5dfc UW |
1251 | /* We don't free locations. They are stored in the bp_location array |
1252 | and update_global_location_list will eventually delete them and | |
1253 | remove breakpoints if needed. */ | |
1254 | b->loc = NULL; | |
1255 | ||
a5606eee VP |
1256 | if (within_current_scope && reparse) |
1257 | { | |
1258 | char *s; | |
d63d0675 | 1259 | |
a5606eee VP |
1260 | if (b->exp) |
1261 | { | |
1262 | xfree (b->exp); | |
1263 | b->exp = NULL; | |
1264 | } | |
d63d0675 | 1265 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1266 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1267 | /* If the meaning of expression itself changed, the old value is | |
1268 | no longer relevant. We don't want to report a watchpoint hit | |
1269 | to the user when the old value and the new value may actually | |
1270 | be completely different objects. */ | |
1271 | value_free (b->val); | |
fa4727a6 DJ |
1272 | b->val = NULL; |
1273 | b->val_valid = 0; | |
60e1c644 PA |
1274 | |
1275 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1276 | expression is stored in the breakpoint object, not in the | |
1277 | locations (re)created below. */ | |
1278 | if (b->cond_string != NULL) | |
1279 | { | |
1280 | if (b->cond_exp != NULL) | |
1281 | { | |
1282 | xfree (b->cond_exp); | |
1283 | b->cond_exp = NULL; | |
1284 | } | |
1285 | ||
1286 | s = b->cond_string; | |
1287 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1288 | } | |
a5606eee | 1289 | } |
a5606eee VP |
1290 | |
1291 | /* If we failed to parse the expression, for example because | |
1292 | it refers to a global variable in a not-yet-loaded shared library, | |
1293 | don't try to insert watchpoint. We don't automatically delete | |
1294 | such watchpoint, though, since failure to parse expression | |
1295 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1296 | if ( !target_has_execution) |
1297 | { | |
1298 | /* Without execution, memory can't change. No use to try and | |
1299 | set watchpoint locations. The watchpoint will be reset when | |
1300 | the target gains execution, through breakpoint_re_set. */ | |
1301 | } | |
1302 | else if (within_current_scope && b->exp) | |
a5606eee | 1303 | { |
0cf6dd15 | 1304 | int pc = 0; |
fa4727a6 | 1305 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1306 | struct program_space *frame_pspace; |
a5606eee | 1307 | |
0cf6dd15 | 1308 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1309 | |
a5606eee VP |
1310 | /* Avoid setting b->val if it's already set. The meaning of |
1311 | b->val is 'the last value' user saw, and we should update | |
1312 | it only if we reported that last value to user. As it | |
1313 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1314 | if (!b->val_valid) |
1315 | { | |
1316 | b->val = v; | |
1317 | b->val_valid = 1; | |
1318 | } | |
a5606eee | 1319 | |
2d134ed3 PA |
1320 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1321 | ||
a5606eee | 1322 | /* Look at each value on the value chain. */ |
9fa40276 | 1323 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1324 | { |
1325 | /* If it's a memory location, and GDB actually needed | |
1326 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1327 | must watch it. If the first value returned is |
1328 | still lazy, that means an error occurred reading it; | |
1329 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1330 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1331 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1332 | { |
1333 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1334 | |
a5606eee VP |
1335 | /* We only watch structs and arrays if user asked |
1336 | for it explicitly, never if they just happen to | |
1337 | appear in the middle of some value chain. */ | |
fa4727a6 | 1338 | if (v == result |
a5606eee VP |
1339 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1340 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1341 | { | |
1342 | CORE_ADDR addr; | |
1343 | int len, type; | |
1344 | struct bp_location *loc, **tmp; | |
1345 | ||
42ae5230 | 1346 | addr = value_address (v); |
a5606eee VP |
1347 | len = TYPE_LENGTH (value_type (v)); |
1348 | type = hw_write; | |
1349 | if (b->type == bp_read_watchpoint) | |
1350 | type = hw_read; | |
1351 | else if (b->type == bp_access_watchpoint) | |
1352 | type = hw_access; | |
1353 | ||
39d61571 | 1354 | loc = allocate_bp_location (b); |
a5606eee VP |
1355 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1356 | ; | |
1357 | *tmp = loc; | |
a6d9a66e | 1358 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1359 | |
1360 | loc->pspace = frame_pspace; | |
a5606eee VP |
1361 | loc->address = addr; |
1362 | loc->length = len; | |
1363 | loc->watchpoint_type = type; | |
1364 | } | |
1365 | } | |
9fa40276 TJB |
1366 | } |
1367 | ||
1368 | /* Change the type of breakpoint between hardware assisted or | |
1369 | an ordinary watchpoint depending on the hardware support | |
1370 | and free hardware slots. REPARSE is set when the inferior | |
1371 | is started. */ | |
1372 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1373 | && reparse) | |
1374 | { | |
e09342b5 | 1375 | int reg_cnt; |
9fa40276 TJB |
1376 | enum bp_loc_type loc_type; |
1377 | struct bp_location *bl; | |
a5606eee | 1378 | |
e09342b5 TJB |
1379 | reg_cnt = can_use_hardware_watchpoint (val_chain, b->exact); |
1380 | ||
1381 | if (reg_cnt) | |
9fa40276 TJB |
1382 | { |
1383 | int i, target_resources_ok, other_type_used; | |
e09342b5 | 1384 | enum enable_state orig_enable_state; |
9fa40276 TJB |
1385 | |
1386 | /* We need to determine how many resources are already | |
e09342b5 TJB |
1387 | used for all other hardware watchpoints plus this one |
1388 | to see if we still have enough resources to also fit | |
1389 | this watchpoint in as well. To guarantee the | |
1390 | hw_watchpoint_used_count call below counts this | |
1391 | watchpoint, make sure that it is marked as a hardware | |
1392 | watchpoint. */ | |
1393 | b->type = bp_hardware_watchpoint; | |
1394 | ||
1395 | /* hw_watchpoint_used_count ignores disabled watchpoints, | |
1396 | and b might be disabled if we're being called from | |
1397 | do_enable_breakpoint. */ | |
1398 | orig_enable_state = b->enable_state; | |
1399 | b->enable_state = bp_enabled; | |
1400 | ||
9fa40276 TJB |
1401 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1402 | &other_type_used); | |
9fa40276 | 1403 | |
e09342b5 TJB |
1404 | b->enable_state = orig_enable_state; |
1405 | ||
1406 | target_resources_ok = target_can_use_hardware_watchpoint | |
1407 | (bp_hardware_watchpoint, i, other_type_used); | |
1408 | if (target_resources_ok <= 0) | |
1409 | b->type = bp_watchpoint; | |
9fa40276 TJB |
1410 | } |
1411 | else | |
1412 | b->type = bp_watchpoint; | |
1413 | ||
1414 | loc_type = (b->type == bp_watchpoint? bp_loc_other | |
1415 | : bp_loc_hardware_watchpoint); | |
1416 | for (bl = b->loc; bl; bl = bl->next) | |
1417 | bl->loc_type = loc_type; | |
1418 | } | |
1419 | ||
1420 | for (v = val_chain; v; v = next) | |
1421 | { | |
a5606eee VP |
1422 | next = value_next (v); |
1423 | if (v != b->val) | |
1424 | value_free (v); | |
1425 | } | |
1426 | ||
c7437ca6 PA |
1427 | /* If a software watchpoint is not watching any memory, then the |
1428 | above left it without any location set up. But, | |
1429 | bpstat_stop_status requires a location to be able to report | |
1430 | stops, so make sure there's at least a dummy one. */ | |
1431 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1432 | { | |
1433 | b->loc = allocate_bp_location (b); | |
1434 | b->loc->pspace = frame_pspace; | |
1435 | b->loc->address = -1; | |
1436 | b->loc->length = -1; | |
1437 | b->loc->watchpoint_type = -1; | |
1438 | } | |
a5606eee VP |
1439 | } |
1440 | else if (!within_current_scope) | |
7270d8f2 | 1441 | { |
ac74f770 MS |
1442 | printf_filtered (_("\ |
1443 | Watchpoint %d deleted because the program has left the block\n\ | |
1444 | in which its expression is valid.\n"), | |
a5606eee VP |
1445 | b->number); |
1446 | if (b->related_breakpoint) | |
60e1c644 PA |
1447 | { |
1448 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1449 | b->related_breakpoint->related_breakpoint = NULL; | |
1450 | b->related_breakpoint= NULL; | |
1451 | } | |
a5606eee | 1452 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1453 | } |
a5606eee VP |
1454 | |
1455 | /* Restore the selected frame. */ | |
66076460 DJ |
1456 | if (frame_saved) |
1457 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1458 | } |
1459 | ||
a5606eee | 1460 | |
74960c60 VP |
1461 | /* Returns 1 iff breakpoint location should be |
1462 | inserted in the inferior. */ | |
1463 | static int | |
35df4500 | 1464 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1465 | { |
35df4500 | 1466 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1467 | return 0; |
1468 | ||
35df4500 | 1469 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1470 | return 0; |
1471 | ||
35df4500 | 1472 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1473 | return 0; |
1474 | ||
56710373 PA |
1475 | /* This is set for example, when we're attached to the parent of a |
1476 | vfork, and have detached from the child. The child is running | |
1477 | free, and we expect it to do an exec or exit, at which point the | |
1478 | OS makes the parent schedulable again (and the target reports | |
1479 | that the vfork is done). Until the child is done with the shared | |
1480 | memory region, do not insert breakpoints in the parent, otherwise | |
1481 | the child could still trip on the parent's breakpoints. Since | |
1482 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1483 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1484 | return 0; |
1485 | ||
1042e4c0 SS |
1486 | /* Tracepoints are inserted by the target at a time of its choosing, |
1487 | not by us. */ | |
35df4500 | 1488 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1489 | return 0; |
1490 | ||
74960c60 VP |
1491 | return 1; |
1492 | } | |
1493 | ||
35df4500 TJB |
1494 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1495 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
1496 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. | |
879bfdc2 | 1497 | |
4a64f543 MS |
1498 | NOTE drow/2003-09-09: This routine could be broken down to an |
1499 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1500 | static int |
35df4500 | 1501 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1502 | struct ui_file *tmp_error_stream, |
fa3a767f | 1503 | int *disabled_breaks, |
26bb91f3 | 1504 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1505 | { |
1506 | int val = 0; | |
1507 | ||
35df4500 | 1508 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1509 | return 0; |
1510 | ||
8181d85f | 1511 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1512 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1513 | bl->target_info.placed_address = bl->address; | |
1514 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
8181d85f | 1515 | |
35df4500 TJB |
1516 | if (bl->loc_type == bp_loc_software_breakpoint |
1517 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1518 | { |
35df4500 | 1519 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1520 | { |
1521 | /* If the explicitly specified breakpoint type | |
1522 | is not hardware breakpoint, check the memory map to see | |
1523 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1524 | |
765dc015 VP |
1525 | Two important cases are: |
1526 | - location type is not hardware breakpoint, memory | |
1527 | is readonly. We change the type of the location to | |
1528 | hardware breakpoint. | |
4a64f543 MS |
1529 | - location type is hardware breakpoint, memory is |
1530 | read-write. This means we've previously made the | |
1531 | location hardware one, but then the memory map changed, | |
1532 | so we undo. | |
765dc015 | 1533 | |
4a64f543 MS |
1534 | When breakpoints are removed, remove_breakpoints will use |
1535 | location types we've just set here, the only possible | |
1536 | problem is that memory map has changed during running | |
1537 | program, but it's not going to work anyway with current | |
1538 | gdb. */ | |
765dc015 | 1539 | struct mem_region *mr |
35df4500 | 1540 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1541 | |
1542 | if (mr) | |
1543 | { | |
1544 | if (automatic_hardware_breakpoints) | |
1545 | { | |
765dc015 VP |
1546 | enum bp_loc_type new_type; |
1547 | ||
1548 | if (mr->attrib.mode != MEM_RW) | |
1549 | new_type = bp_loc_hardware_breakpoint; | |
1550 | else | |
1551 | new_type = bp_loc_software_breakpoint; | |
1552 | ||
35df4500 | 1553 | if (new_type != bl->loc_type) |
765dc015 VP |
1554 | { |
1555 | static int said = 0; | |
cc59ec59 | 1556 | |
35df4500 | 1557 | bl->loc_type = new_type; |
765dc015 VP |
1558 | if (!said) |
1559 | { | |
3e43a32a MS |
1560 | fprintf_filtered (gdb_stdout, |
1561 | _("Note: automatically using " | |
1562 | "hardware breakpoints for " | |
1563 | "read-only addresses.\n")); | |
765dc015 VP |
1564 | said = 1; |
1565 | } | |
1566 | } | |
1567 | } | |
35df4500 | 1568 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1569 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1570 | warning (_("cannot set software breakpoint " |
1571 | "at readonly address %s"), | |
35df4500 | 1572 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1573 | } |
1574 | } | |
1575 | ||
879bfdc2 DJ |
1576 | /* First check to see if we have to handle an overlay. */ |
1577 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1578 | || bl->section == NULL |
1579 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1580 | { |
1581 | /* No overlay handling: just set the breakpoint. */ | |
1582 | ||
35df4500 TJB |
1583 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1584 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1585 | &bl->target_info); | |
879bfdc2 | 1586 | else |
35df4500 TJB |
1587 | val = target_insert_breakpoint (bl->gdbarch, |
1588 | &bl->target_info); | |
879bfdc2 DJ |
1589 | } |
1590 | else | |
1591 | { | |
4a64f543 | 1592 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1593 | Shall we set a breakpoint at the LMA? */ |
1594 | if (!overlay_events_enabled) | |
1595 | { | |
1596 | /* Yes -- overlay event support is not active, | |
1597 | so we must try to set a breakpoint at the LMA. | |
1598 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1599 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1600 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1601 | bl->owner->number); |
879bfdc2 DJ |
1602 | else |
1603 | { | |
35df4500 TJB |
1604 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1605 | bl->section); | |
879bfdc2 | 1606 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1607 | bl->overlay_target_info = bl->target_info; |
1608 | bl->overlay_target_info.placed_address = addr; | |
1609 | val = target_insert_breakpoint (bl->gdbarch, | |
1610 | &bl->overlay_target_info); | |
879bfdc2 | 1611 | if (val != 0) |
99361f52 | 1612 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1613 | "Overlay breakpoint %d " |
1614 | "failed: in ROM?\n", | |
35df4500 | 1615 | bl->owner->number); |
879bfdc2 DJ |
1616 | } |
1617 | } | |
1618 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1619 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1620 | { |
1621 | /* Yes. This overlay section is mapped into memory. */ | |
35df4500 TJB |
1622 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1623 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1624 | &bl->target_info); | |
879bfdc2 | 1625 | else |
35df4500 TJB |
1626 | val = target_insert_breakpoint (bl->gdbarch, |
1627 | &bl->target_info); | |
879bfdc2 DJ |
1628 | } |
1629 | else | |
1630 | { | |
1631 | /* No. This breakpoint will not be inserted. | |
1632 | No error, but do not mark the bp as 'inserted'. */ | |
1633 | return 0; | |
1634 | } | |
1635 | } | |
1636 | ||
1637 | if (val) | |
1638 | { | |
1639 | /* Can't set the breakpoint. */ | |
35df4500 | 1640 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1641 | { |
4a64f543 | 1642 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1643 | val = 0; |
35df4500 | 1644 | bl->shlib_disabled = 1; |
879bfdc2 DJ |
1645 | if (!*disabled_breaks) |
1646 | { | |
1647 | fprintf_unfiltered (tmp_error_stream, | |
1648 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1649 | bl->owner->number); |
879bfdc2 | 1650 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1651 | "Temporarily disabling shared " |
1652 | "library breakpoints:\n"); | |
879bfdc2 DJ |
1653 | } |
1654 | *disabled_breaks = 1; | |
1655 | fprintf_unfiltered (tmp_error_stream, | |
35df4500 | 1656 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1657 | } |
1658 | else | |
879bfdc2 | 1659 | { |
35df4500 | 1660 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1661 | { |
1662 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1663 | fprintf_unfiltered (tmp_error_stream, |
1664 | "Cannot insert hardware " | |
1665 | "breakpoint %d.\n", | |
35df4500 | 1666 | bl->owner->number); |
879bfdc2 DJ |
1667 | } |
1668 | else | |
1669 | { | |
1670 | fprintf_unfiltered (tmp_error_stream, | |
1671 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1672 | bl->owner->number); |
879bfdc2 DJ |
1673 | fprintf_filtered (tmp_error_stream, |
1674 | "Error accessing memory address "); | |
35df4500 | 1675 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1676 | tmp_error_stream); |
879bfdc2 DJ |
1677 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1678 | safe_strerror (val)); | |
1679 | } | |
1680 | ||
1681 | } | |
1682 | } | |
1683 | else | |
35df4500 | 1684 | bl->inserted = 1; |
879bfdc2 DJ |
1685 | |
1686 | return val; | |
1687 | } | |
1688 | ||
35df4500 | 1689 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1690 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1691 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1692 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1693 | { |
77b06cd7 TJB |
1694 | gdb_assert (bl->owner->ops != NULL |
1695 | && bl->owner->ops->insert_location != NULL); | |
1696 | ||
1697 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1698 | |
1699 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1700 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1701 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1702 | { |
1703 | struct bp_location *loc, **loc_temp; | |
1704 | ||
1705 | /* But don't try to insert it, if there's already another | |
1706 | hw_access location that would be considered a duplicate | |
1707 | of this one. */ | |
1708 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1709 | if (loc != bl |
85d721b8 | 1710 | && loc->watchpoint_type == hw_access |
35df4500 | 1711 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1712 | { |
35df4500 TJB |
1713 | bl->duplicate = 1; |
1714 | bl->inserted = 1; | |
1715 | bl->target_info = loc->target_info; | |
1716 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1717 | val = 0; |
1718 | break; | |
1719 | } | |
1720 | ||
1721 | if (val == 1) | |
1722 | { | |
77b06cd7 TJB |
1723 | bl->watchpoint_type = hw_access; |
1724 | val = bl->owner->ops->insert_location (bl); | |
1725 | ||
1726 | if (val) | |
1727 | /* Back to the original value. */ | |
1728 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1729 | } |
1730 | } | |
1731 | ||
35df4500 | 1732 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1733 | } |
1734 | ||
35df4500 | 1735 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1736 | { |
77b06cd7 TJB |
1737 | gdb_assert (bl->owner->ops != NULL |
1738 | && bl->owner->ops->insert_location != NULL); | |
1739 | ||
1740 | val = bl->owner->ops->insert_location (bl); | |
1741 | if (val) | |
1742 | { | |
1743 | bl->owner->enable_state = bp_disabled; | |
1744 | ||
1745 | if (val == 1) | |
1746 | warning (_("\ | |
1747 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1748 | of catchpoint."), bl->owner->number); | |
1749 | else | |
1750 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1751 | } | |
1752 | ||
1753 | bl->inserted = (val == 0); | |
1640b821 DJ |
1754 | |
1755 | /* We've already printed an error message if there was a problem | |
1756 | inserting this catchpoint, and we've disabled the catchpoint, | |
1757 | so just return success. */ | |
1758 | return 0; | |
879bfdc2 DJ |
1759 | } |
1760 | ||
1761 | return 0; | |
1762 | } | |
1763 | ||
6c95b8df PA |
1764 | /* This function is called when program space PSPACE is about to be |
1765 | deleted. It takes care of updating breakpoints to not reference | |
1766 | PSPACE anymore. */ | |
1767 | ||
1768 | void | |
1769 | breakpoint_program_space_exit (struct program_space *pspace) | |
1770 | { | |
1771 | struct breakpoint *b, *b_temp; | |
876fa593 | 1772 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1773 | |
1774 | /* Remove any breakpoint that was set through this program space. */ | |
1775 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1776 | { | |
1777 | if (b->pspace == pspace) | |
1778 | delete_breakpoint (b); | |
1779 | } | |
1780 | ||
1781 | /* Breakpoints set through other program spaces could have locations | |
1782 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1783 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1784 | { |
1785 | struct bp_location *tmp; | |
1786 | ||
1787 | if (loc->pspace == pspace) | |
1788 | { | |
2bdf28a0 | 1789 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1790 | if (loc->owner->loc == loc) |
1791 | loc->owner->loc = loc->next; | |
1792 | else | |
1793 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1794 | if (tmp->next == loc) | |
1795 | { | |
1796 | tmp->next = loc->next; | |
1797 | break; | |
1798 | } | |
1799 | } | |
1800 | } | |
1801 | ||
1802 | /* Now update the global location list to permanently delete the | |
1803 | removed locations above. */ | |
1804 | update_global_location_list (0); | |
1805 | } | |
1806 | ||
74960c60 VP |
1807 | /* Make sure all breakpoints are inserted in inferior. |
1808 | Throws exception on any error. | |
1809 | A breakpoint that is already inserted won't be inserted | |
1810 | again, so calling this function twice is safe. */ | |
1811 | void | |
1812 | insert_breakpoints (void) | |
1813 | { | |
1814 | struct breakpoint *bpt; | |
1815 | ||
1816 | ALL_BREAKPOINTS (bpt) | |
1817 | if (is_hardware_watchpoint (bpt)) | |
4a64f543 | 1818 | update_watchpoint (bpt, 0 /* don't reparse. */); |
74960c60 | 1819 | |
b60e7edf | 1820 | update_global_location_list (1); |
74960c60 | 1821 | |
c35b1492 PA |
1822 | /* update_global_location_list does not insert breakpoints when |
1823 | always_inserted_mode is not enabled. Explicitly insert them | |
1824 | now. */ | |
1825 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1826 | insert_breakpoint_locations (); |
1827 | } | |
1828 | ||
c906108c SS |
1829 | /* insert_breakpoints is used when starting or continuing the program. |
1830 | remove_breakpoints is used when the program stops. | |
1831 | Both return zero if successful, | |
1832 | or an `errno' value if could not write the inferior. */ | |
1833 | ||
74960c60 VP |
1834 | static void |
1835 | insert_breakpoint_locations (void) | |
c906108c | 1836 | { |
a5606eee | 1837 | struct breakpoint *bpt; |
35df4500 | 1838 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1839 | int error = 0; |
c906108c SS |
1840 | int val = 0; |
1841 | int disabled_breaks = 0; | |
81d0cc19 | 1842 | int hw_breakpoint_error = 0; |
c906108c | 1843 | |
81d0cc19 | 1844 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1845 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1846 | |
81d0cc19 GS |
1847 | /* Explicitly mark the warning -- this will only be printed if |
1848 | there was an error. */ | |
1849 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1850 | |
1851 | save_current_space_and_thread (); | |
1852 | ||
35df4500 | 1853 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1854 | { |
35df4500 | 1855 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1856 | continue; |
1857 | ||
4a64f543 MS |
1858 | /* There is no point inserting thread-specific breakpoints if |
1859 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1860 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1861 | if (bl->owner->thread != -1 |
1862 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1863 | continue; |
1864 | ||
35df4500 | 1865 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1866 | |
1867 | /* For targets that support global breakpoints, there's no need | |
1868 | to select an inferior to insert breakpoint to. In fact, even | |
1869 | if we aren't attached to any process yet, we should still | |
1870 | insert breakpoints. */ | |
1871 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1872 | && ptid_equal (inferior_ptid, null_ptid)) | |
1873 | continue; | |
1874 | ||
35df4500 | 1875 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
879bfdc2 DJ |
1876 | &hw_breakpoint_error); |
1877 | if (val) | |
e236ba44 | 1878 | error = val; |
879bfdc2 | 1879 | } |
c906108c | 1880 | |
4a64f543 MS |
1881 | /* If we failed to insert all locations of a watchpoint, remove |
1882 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1883 | ALL_BREAKPOINTS (bpt) |
1884 | { | |
1885 | int some_failed = 0; | |
1886 | struct bp_location *loc; | |
1887 | ||
1888 | if (!is_hardware_watchpoint (bpt)) | |
1889 | continue; | |
1890 | ||
d6b74ac4 | 1891 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1892 | continue; |
74960c60 VP |
1893 | |
1894 | if (bpt->disposition == disp_del_at_next_stop) | |
1895 | continue; | |
a5606eee VP |
1896 | |
1897 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1898 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1899 | { |
1900 | some_failed = 1; | |
1901 | break; | |
1902 | } | |
1903 | if (some_failed) | |
1904 | { | |
1905 | for (loc = bpt->loc; loc; loc = loc->next) | |
1906 | if (loc->inserted) | |
1907 | remove_breakpoint (loc, mark_uninserted); | |
1908 | ||
1909 | hw_breakpoint_error = 1; | |
1910 | fprintf_unfiltered (tmp_error_stream, | |
1911 | "Could not insert hardware watchpoint %d.\n", | |
1912 | bpt->number); | |
1913 | error = -1; | |
1914 | } | |
1915 | } | |
1916 | ||
e236ba44 | 1917 | if (error) |
81d0cc19 GS |
1918 | { |
1919 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1920 | message about possibly exhausted resources. */ | |
879bfdc2 | 1921 | if (hw_breakpoint_error) |
81d0cc19 | 1922 | { |
c6510018 MS |
1923 | fprintf_unfiltered (tmp_error_stream, |
1924 | "Could not insert hardware breakpoints:\n\ | |
1925 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1926 | } |
81d0cc19 GS |
1927 | target_terminal_ours_for_output (); |
1928 | error_stream (tmp_error_stream); | |
1929 | } | |
f7545552 TT |
1930 | |
1931 | do_cleanups (cleanups); | |
c906108c SS |
1932 | } |
1933 | ||
c906108c | 1934 | int |
fba45db2 | 1935 | remove_breakpoints (void) |
c906108c | 1936 | { |
35df4500 | 1937 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 1938 | int val = 0; |
c906108c | 1939 | |
35df4500 | 1940 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 1941 | { |
35df4500 TJB |
1942 | if (bl->inserted) |
1943 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 1944 | } |
3a1bae8e | 1945 | return val; |
c906108c SS |
1946 | } |
1947 | ||
6c95b8df PA |
1948 | /* Remove breakpoints of process PID. */ |
1949 | ||
1950 | int | |
1951 | remove_breakpoints_pid (int pid) | |
1952 | { | |
35df4500 | 1953 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
1954 | int val; |
1955 | struct inferior *inf = find_inferior_pid (pid); | |
1956 | ||
35df4500 | 1957 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 1958 | { |
35df4500 | 1959 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
1960 | continue; |
1961 | ||
35df4500 | 1962 | if (bl->inserted) |
6c95b8df | 1963 | { |
35df4500 | 1964 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
1965 | if (val != 0) |
1966 | return val; | |
1967 | } | |
1968 | } | |
1969 | return 0; | |
1970 | } | |
1971 | ||
692590c1 | 1972 | int |
80ce1ecb | 1973 | remove_hw_watchpoints (void) |
692590c1 | 1974 | { |
35df4500 | 1975 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 1976 | int val = 0; |
692590c1 | 1977 | |
35df4500 | 1978 | ALL_BP_LOCATIONS (bl, blp_tmp) |
692590c1 | 1979 | { |
35df4500 TJB |
1980 | if (bl->inserted && bl->loc_type == bp_loc_hardware_watchpoint) |
1981 | val |= remove_breakpoint (bl, mark_uninserted); | |
692590c1 | 1982 | } |
3a1bae8e | 1983 | return val; |
692590c1 MS |
1984 | } |
1985 | ||
c906108c | 1986 | int |
fba45db2 | 1987 | reattach_breakpoints (int pid) |
c906108c | 1988 | { |
6c95b8df | 1989 | struct cleanup *old_chain; |
35df4500 | 1990 | struct bp_location *bl, **blp_tmp; |
c906108c | 1991 | int val; |
a4954f26 | 1992 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1993 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
1994 | struct inferior *inf; |
1995 | struct thread_info *tp; | |
1996 | ||
1997 | tp = any_live_thread_of_process (pid); | |
1998 | if (tp == NULL) | |
1999 | return 1; | |
2000 | ||
2001 | inf = find_inferior_pid (pid); | |
2002 | old_chain = save_inferior_ptid (); | |
2003 | ||
2004 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2005 | |
2006 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2007 | |
35df4500 | 2008 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2009 | { |
35df4500 | 2010 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2011 | continue; |
2012 | ||
35df4500 | 2013 | if (bl->inserted) |
c5aa993b | 2014 | { |
35df4500 TJB |
2015 | bl->inserted = 0; |
2016 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); | |
c5aa993b JM |
2017 | if (val != 0) |
2018 | { | |
ce696e05 | 2019 | do_cleanups (old_chain); |
c5aa993b JM |
2020 | return val; |
2021 | } | |
2022 | } | |
2023 | } | |
ce696e05 | 2024 | do_cleanups (old_chain); |
c906108c SS |
2025 | return 0; |
2026 | } | |
2027 | ||
e58b0e63 PA |
2028 | static int internal_breakpoint_number = -1; |
2029 | ||
84f4c1fe PM |
2030 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2031 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2032 | from internal_breakpoint_number and that variable decremented. | |
2033 | Otherwis the breakpoint number will be populated from | |
2034 | breakpoint_count and that value incremented. Internal breakpoints | |
2035 | do not set the internal var bpnum. */ | |
2036 | static void | |
2037 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2038 | { | |
2039 | if (internal) | |
2040 | b->number = internal_breakpoint_number--; | |
2041 | else | |
2042 | { | |
2043 | set_breakpoint_count (breakpoint_count + 1); | |
2044 | b->number = breakpoint_count; | |
2045 | } | |
2046 | } | |
2047 | ||
e62c965a | 2048 | static struct breakpoint * |
a6d9a66e UW |
2049 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2050 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2051 | { |
e62c965a PP |
2052 | struct symtab_and_line sal; |
2053 | struct breakpoint *b; | |
2054 | ||
4a64f543 | 2055 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2056 | |
2057 | sal.pc = address; | |
2058 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2059 | sal.pspace = current_program_space; |
e62c965a | 2060 | |
a6d9a66e | 2061 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2062 | b->number = internal_breakpoint_number--; |
2063 | b->disposition = disp_donttouch; | |
2064 | ||
2065 | return b; | |
2066 | } | |
2067 | ||
17450429 PP |
2068 | static const char *const longjmp_names[] = |
2069 | { | |
2070 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2071 | }; | |
2072 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2073 | ||
2074 | /* Per-objfile data private to breakpoint.c. */ | |
2075 | struct breakpoint_objfile_data | |
2076 | { | |
2077 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2078 | struct minimal_symbol *overlay_msym; | |
2079 | ||
2080 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2081 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2082 | ||
2083 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2084 | struct minimal_symbol *terminate_msym; | |
2085 | ||
2086 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2087 | struct minimal_symbol *exception_msym; | |
2088 | }; | |
2089 | ||
2090 | static const struct objfile_data *breakpoint_objfile_key; | |
2091 | ||
2092 | /* Minimal symbol not found sentinel. */ | |
2093 | static struct minimal_symbol msym_not_found; | |
2094 | ||
2095 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2096 | ||
2097 | static int | |
2098 | msym_not_found_p (const struct minimal_symbol *msym) | |
2099 | { | |
2100 | return msym == &msym_not_found; | |
2101 | } | |
2102 | ||
2103 | /* Return per-objfile data needed by breakpoint.c. | |
2104 | Allocate the data if necessary. */ | |
2105 | ||
2106 | static struct breakpoint_objfile_data * | |
2107 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2108 | { | |
2109 | struct breakpoint_objfile_data *bp_objfile_data; | |
2110 | ||
2111 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2112 | if (bp_objfile_data == NULL) | |
2113 | { | |
2114 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2115 | sizeof (*bp_objfile_data)); | |
2116 | ||
2117 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2118 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2119 | } | |
2120 | return bp_objfile_data; | |
2121 | } | |
2122 | ||
e62c965a | 2123 | static void |
af02033e | 2124 | create_overlay_event_breakpoint (void) |
e62c965a | 2125 | { |
69de3c6a | 2126 | struct objfile *objfile; |
af02033e | 2127 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2128 | |
69de3c6a PP |
2129 | ALL_OBJFILES (objfile) |
2130 | { | |
2131 | struct breakpoint *b; | |
17450429 PP |
2132 | struct breakpoint_objfile_data *bp_objfile_data; |
2133 | CORE_ADDR addr; | |
69de3c6a | 2134 | |
17450429 PP |
2135 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2136 | ||
2137 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2138 | continue; | |
2139 | ||
2140 | if (bp_objfile_data->overlay_msym == NULL) | |
2141 | { | |
2142 | struct minimal_symbol *m; | |
2143 | ||
2144 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2145 | if (m == NULL) | |
2146 | { | |
2147 | /* Avoid future lookups in this objfile. */ | |
2148 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2149 | continue; | |
2150 | } | |
2151 | bp_objfile_data->overlay_msym = m; | |
2152 | } | |
e62c965a | 2153 | |
17450429 PP |
2154 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2155 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
69de3c6a PP |
2156 | bp_overlay_event); |
2157 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2158 | |
69de3c6a PP |
2159 | if (overlay_debugging == ovly_auto) |
2160 | { | |
2161 | b->enable_state = bp_enabled; | |
2162 | overlay_events_enabled = 1; | |
2163 | } | |
2164 | else | |
2165 | { | |
2166 | b->enable_state = bp_disabled; | |
2167 | overlay_events_enabled = 0; | |
2168 | } | |
e62c965a PP |
2169 | } |
2170 | update_global_location_list (1); | |
2171 | } | |
2172 | ||
0fd8e87f | 2173 | static void |
af02033e | 2174 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2175 | { |
6c95b8df | 2176 | struct program_space *pspace; |
6c95b8df PA |
2177 | struct cleanup *old_chain; |
2178 | ||
2179 | old_chain = save_current_program_space (); | |
0fd8e87f | 2180 | |
6c95b8df | 2181 | ALL_PSPACES (pspace) |
af02033e PP |
2182 | { |
2183 | struct objfile *objfile; | |
2184 | ||
2185 | set_current_program_space (pspace); | |
2186 | ||
2187 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2188 | { |
af02033e PP |
2189 | int i; |
2190 | struct gdbarch *gdbarch; | |
17450429 | 2191 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2192 | |
af02033e PP |
2193 | gdbarch = get_objfile_arch (objfile); |
2194 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2195 | continue; |
2196 | ||
17450429 PP |
2197 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2198 | ||
2199 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2200 | { |
2201 | struct breakpoint *b; | |
af02033e | 2202 | const char *func_name; |
17450429 | 2203 | CORE_ADDR addr; |
6c95b8df | 2204 | |
17450429 | 2205 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2206 | continue; |
0fd8e87f | 2207 | |
17450429 PP |
2208 | func_name = longjmp_names[i]; |
2209 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2210 | { | |
2211 | struct minimal_symbol *m; | |
2212 | ||
2213 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2214 | if (m == NULL) | |
2215 | { | |
2216 | /* Prevent future lookups in this objfile. */ | |
2217 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2218 | continue; | |
2219 | } | |
2220 | bp_objfile_data->longjmp_msym[i] = m; | |
2221 | } | |
2222 | ||
2223 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
2224 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master); | |
af02033e PP |
2225 | b->addr_string = xstrdup (func_name); |
2226 | b->enable_state = bp_disabled; | |
2227 | } | |
0fd8e87f | 2228 | } |
af02033e | 2229 | } |
0fd8e87f | 2230 | update_global_location_list (1); |
6c95b8df PA |
2231 | |
2232 | do_cleanups (old_chain); | |
0fd8e87f UW |
2233 | } |
2234 | ||
af02033e | 2235 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2236 | static void |
af02033e | 2237 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2238 | { |
2239 | struct program_space *pspace; | |
aa7d318d | 2240 | struct cleanup *old_chain; |
af02033e | 2241 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2242 | |
2243 | old_chain = save_current_program_space (); | |
2244 | ||
2245 | ALL_PSPACES (pspace) | |
17450429 PP |
2246 | { |
2247 | struct objfile *objfile; | |
2248 | CORE_ADDR addr; | |
2249 | ||
2250 | set_current_program_space (pspace); | |
2251 | ||
aa7d318d TT |
2252 | ALL_OBJFILES (objfile) |
2253 | { | |
2254 | struct breakpoint *b; | |
17450429 | 2255 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2256 | |
17450429 | 2257 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2258 | |
17450429 PP |
2259 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2260 | continue; | |
2261 | ||
2262 | if (bp_objfile_data->terminate_msym == NULL) | |
2263 | { | |
2264 | struct minimal_symbol *m; | |
2265 | ||
2266 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2267 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2268 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2269 | { | |
2270 | /* Prevent future lookups in this objfile. */ | |
2271 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2272 | continue; | |
2273 | } | |
2274 | bp_objfile_data->terminate_msym = m; | |
2275 | } | |
aa7d318d | 2276 | |
17450429 PP |
2277 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2278 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
aa7d318d TT |
2279 | bp_std_terminate_master); |
2280 | b->addr_string = xstrdup (func_name); | |
2281 | b->enable_state = bp_disabled; | |
2282 | } | |
17450429 PP |
2283 | } |
2284 | ||
aa7d318d TT |
2285 | update_global_location_list (1); |
2286 | ||
2287 | do_cleanups (old_chain); | |
2288 | } | |
2289 | ||
186c406b TT |
2290 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2291 | ||
2292 | void | |
2293 | create_exception_master_breakpoint (void) | |
2294 | { | |
2295 | struct objfile *objfile; | |
17450429 | 2296 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2297 | |
2298 | ALL_OBJFILES (objfile) | |
2299 | { | |
17450429 PP |
2300 | struct breakpoint *b; |
2301 | struct gdbarch *gdbarch; | |
2302 | struct breakpoint_objfile_data *bp_objfile_data; | |
2303 | CORE_ADDR addr; | |
2304 | ||
2305 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2306 | ||
2307 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2308 | continue; | |
2309 | ||
2310 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2311 | |
17450429 | 2312 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2313 | { |
17450429 | 2314 | struct minimal_symbol *debug_hook; |
186c406b | 2315 | |
17450429 PP |
2316 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2317 | if (debug_hook == NULL) | |
2318 | { | |
2319 | bp_objfile_data->exception_msym = &msym_not_found; | |
2320 | continue; | |
2321 | } | |
2322 | ||
2323 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2324 | } |
17450429 PP |
2325 | |
2326 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2327 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2328 | ¤t_target); | |
2329 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); | |
2330 | b->addr_string = xstrdup (func_name); | |
2331 | b->enable_state = bp_disabled; | |
186c406b TT |
2332 | } |
2333 | ||
2334 | update_global_location_list (1); | |
2335 | } | |
2336 | ||
c906108c | 2337 | void |
fba45db2 | 2338 | update_breakpoints_after_exec (void) |
c906108c | 2339 | { |
35df4500 | 2340 | struct breakpoint *b, *b_tmp; |
876fa593 | 2341 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2342 | |
25b22b0a PA |
2343 | /* We're about to delete breakpoints from GDB's lists. If the |
2344 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2345 | writing the breakpoints' "shadow contents" back into memory. The | |
2346 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2347 | do that. Instead, the target is responsible from marking | |
2348 | breakpoints out as soon as it detects an exec. We don't do that | |
2349 | here instead, because there may be other attempts to delete | |
2350 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2351 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2352 | if (bploc->pspace == current_program_space) |
2353 | gdb_assert (!bploc->inserted); | |
c906108c | 2354 | |
35df4500 | 2355 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2356 | { |
6c95b8df PA |
2357 | if (b->pspace != current_program_space) |
2358 | continue; | |
2359 | ||
4a64f543 | 2360 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2361 | if (b->type == bp_shlib_event) |
2362 | { | |
2363 | delete_breakpoint (b); | |
2364 | continue; | |
2365 | } | |
c906108c | 2366 | |
4a64f543 | 2367 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2368 | if (b->type == bp_jit_event) |
2369 | { | |
2370 | delete_breakpoint (b); | |
2371 | continue; | |
2372 | } | |
2373 | ||
1900040c | 2374 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2375 | as must overlay event and longjmp master breakpoints. */ |
2376 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2377 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2378 | || b->type == bp_exception_master) | |
c4093a6a JM |
2379 | { |
2380 | delete_breakpoint (b); | |
2381 | continue; | |
2382 | } | |
2383 | ||
4a64f543 | 2384 | /* Step-resume breakpoints are meaningless after an exec(). */ |
c5aa993b JM |
2385 | if (b->type == bp_step_resume) |
2386 | { | |
2387 | delete_breakpoint (b); | |
2388 | continue; | |
2389 | } | |
2390 | ||
611c83ae PA |
2391 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2392 | after an exec. */ | |
186c406b TT |
2393 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2394 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2395 | { |
2396 | delete_breakpoint (b); | |
2397 | continue; | |
2398 | } | |
2399 | ||
ce78b96d JB |
2400 | if (b->type == bp_catchpoint) |
2401 | { | |
2402 | /* For now, none of the bp_catchpoint breakpoints need to | |
2403 | do anything at this point. In the future, if some of | |
2404 | the catchpoints need to something, we will need to add | |
2405 | a new method, and call this method from here. */ | |
2406 | continue; | |
2407 | } | |
2408 | ||
c5aa993b JM |
2409 | /* bp_finish is a special case. The only way we ought to be able |
2410 | to see one of these when an exec() has happened, is if the user | |
2411 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2412 | carries them to the call-site of the current callee, by setting | |
2413 | a temporary bp there and resuming. But in this case, the finish | |
2414 | will carry them entirely through the vfork & exec. | |
2415 | ||
2416 | We don't want to allow a bp_finish to remain inserted now. But | |
2417 | we can't safely delete it, 'cause finish_command has a handle to | |
2418 | the bp on a bpstat, and will later want to delete it. There's a | |
2419 | chance (and I've seen it happen) that if we delete the bp_finish | |
2420 | here, that its storage will get reused by the time finish_command | |
2421 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2422 | We really must allow finish_command to delete a bp_finish. | |
2423 | ||
53a5351d JM |
2424 | In the absense of a general solution for the "how do we know |
2425 | it's safe to delete something others may have handles to?" | |
2426 | problem, what we'll do here is just uninsert the bp_finish, and | |
2427 | let finish_command delete it. | |
2428 | ||
2429 | (We know the bp_finish is "doomed" in the sense that it's | |
2430 | momentary, and will be deleted as soon as finish_command sees | |
2431 | the inferior stopped. So it doesn't matter that the bp's | |
2432 | address is probably bogus in the new a.out, unlike e.g., the | |
2433 | solib breakpoints.) */ | |
c5aa993b | 2434 | |
c5aa993b JM |
2435 | if (b->type == bp_finish) |
2436 | { | |
2437 | continue; | |
2438 | } | |
2439 | ||
2440 | /* Without a symbolic address, we have little hope of the | |
2441 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2442 | a.out. */ |
c5aa993b JM |
2443 | if (b->addr_string == NULL) |
2444 | { | |
2445 | delete_breakpoint (b); | |
2446 | continue; | |
2447 | } | |
c5aa993b | 2448 | } |
1900040c | 2449 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2450 | create_overlay_event_breakpoint (); |
2451 | create_longjmp_master_breakpoint (); | |
2452 | create_std_terminate_master_breakpoint (); | |
186c406b | 2453 | create_exception_master_breakpoint (); |
c906108c SS |
2454 | } |
2455 | ||
2456 | int | |
fba45db2 | 2457 | detach_breakpoints (int pid) |
c906108c | 2458 | { |
35df4500 | 2459 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2460 | int val = 0; |
ce696e05 | 2461 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2462 | struct inferior *inf = current_inferior (); |
c5aa993b | 2463 | |
39f77062 | 2464 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2465 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2466 | |
6c95b8df | 2467 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2468 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2469 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2470 | { |
35df4500 | 2471 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2472 | continue; |
2473 | ||
35df4500 TJB |
2474 | if (bl->inserted) |
2475 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2476 | } |
d03285ec UW |
2477 | |
2478 | /* Detach single-step breakpoints as well. */ | |
2479 | detach_single_step_breakpoints (); | |
2480 | ||
ce696e05 | 2481 | do_cleanups (old_chain); |
3a1bae8e | 2482 | return val; |
c906108c SS |
2483 | } |
2484 | ||
35df4500 | 2485 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2486 | Note that this is used to detach breakpoints from a child fork. |
2487 | When we get here, the child isn't in the inferior list, and neither | |
2488 | do we have objects to represent its address space --- we should | |
35df4500 | 2489 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2490 | |
c906108c | 2491 | static int |
35df4500 | 2492 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2493 | { |
2494 | int val; | |
c5aa993b | 2495 | |
35df4500 TJB |
2496 | /* BL is never in moribund_locations by our callers. */ |
2497 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2498 | |
35df4500 | 2499 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2500 | /* Permanent breakpoints cannot be inserted or removed. */ |
2501 | return 0; | |
2502 | ||
74960c60 VP |
2503 | /* The type of none suggests that owner is actually deleted. |
2504 | This should not ever happen. */ | |
35df4500 | 2505 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2506 | |
35df4500 TJB |
2507 | if (bl->loc_type == bp_loc_software_breakpoint |
2508 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2509 | { |
c02f5703 MS |
2510 | /* "Normal" instruction breakpoint: either the standard |
2511 | trap-instruction bp (bp_breakpoint), or a | |
2512 | bp_hardware_breakpoint. */ | |
2513 | ||
2514 | /* First check to see if we have to handle an overlay. */ | |
2515 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2516 | || bl->section == NULL |
2517 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2518 | { |
2519 | /* No overlay handling: just remove the breakpoint. */ | |
2520 | ||
35df4500 TJB |
2521 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2522 | val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
c02f5703 | 2523 | else |
35df4500 | 2524 | val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
c02f5703 | 2525 | } |
c906108c SS |
2526 | else |
2527 | { | |
4a64f543 | 2528 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2529 | Did we set a breakpoint at the LMA? */ |
2530 | if (!overlay_events_enabled) | |
2531 | { | |
2532 | /* Yes -- overlay event support is not active, so we | |
2533 | should have set a breakpoint at the LMA. Remove it. | |
2534 | */ | |
c02f5703 MS |
2535 | /* Ignore any failures: if the LMA is in ROM, we will |
2536 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2537 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2538 | target_remove_hw_breakpoint (bl->gdbarch, | |
2539 | &bl->overlay_target_info); | |
c02f5703 | 2540 | else |
35df4500 TJB |
2541 | target_remove_breakpoint (bl->gdbarch, |
2542 | &bl->overlay_target_info); | |
c02f5703 MS |
2543 | } |
2544 | /* Did we set a breakpoint at the VMA? | |
2545 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2546 | if (bl->inserted) |
c906108c | 2547 | { |
c02f5703 MS |
2548 | /* Yes -- remove it. Previously we did not bother to |
2549 | remove the breakpoint if the section had been | |
2550 | unmapped, but let's not rely on that being safe. We | |
2551 | don't know what the overlay manager might do. */ | |
35df4500 TJB |
2552 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2553 | val = target_remove_hw_breakpoint (bl->gdbarch, | |
2554 | &bl->target_info); | |
aa67235e UW |
2555 | |
2556 | /* However, we should remove *software* breakpoints only | |
2557 | if the section is still mapped, or else we overwrite | |
2558 | wrong code with the saved shadow contents. */ | |
35df4500 TJB |
2559 | else if (section_is_mapped (bl->section)) |
2560 | val = target_remove_breakpoint (bl->gdbarch, | |
2561 | &bl->target_info); | |
aa67235e UW |
2562 | else |
2563 | val = 0; | |
c906108c | 2564 | } |
c02f5703 MS |
2565 | else |
2566 | { | |
2567 | /* No -- not inserted, so no need to remove. No error. */ | |
2568 | val = 0; | |
2569 | } | |
c906108c | 2570 | } |
879d1e6b UW |
2571 | |
2572 | /* In some cases, we might not be able to remove a breakpoint | |
2573 | in a shared library that has already been removed, but we | |
2574 | have not yet processed the shlib unload event. */ | |
35df4500 | 2575 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2576 | val = 0; |
2577 | ||
c906108c SS |
2578 | if (val) |
2579 | return val; | |
35df4500 | 2580 | bl->inserted = (is == mark_inserted); |
c906108c | 2581 | } |
35df4500 | 2582 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2583 | { |
77b06cd7 TJB |
2584 | gdb_assert (bl->owner->ops != NULL |
2585 | && bl->owner->ops->remove_location != NULL); | |
2586 | ||
35df4500 | 2587 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2588 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2589 | |
c906108c | 2590 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2591 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2592 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2593 | bl->owner->number); |
c906108c | 2594 | } |
35df4500 TJB |
2595 | else if (bl->owner->type == bp_catchpoint |
2596 | && breakpoint_enabled (bl->owner) | |
2597 | && !bl->duplicate) | |
ce78b96d | 2598 | { |
77b06cd7 TJB |
2599 | gdb_assert (bl->owner->ops != NULL |
2600 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2601 | |
77b06cd7 | 2602 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2603 | if (val) |
2604 | return val; | |
77b06cd7 | 2605 | |
35df4500 | 2606 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2607 | } |
c906108c SS |
2608 | |
2609 | return 0; | |
2610 | } | |
2611 | ||
6c95b8df | 2612 | static int |
35df4500 | 2613 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2614 | { |
2615 | int ret; | |
2616 | struct cleanup *old_chain; | |
2617 | ||
35df4500 TJB |
2618 | /* BL is never in moribund_locations by our callers. */ |
2619 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2620 | |
35df4500 | 2621 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2622 | /* Permanent breakpoints cannot be inserted or removed. */ |
2623 | return 0; | |
2624 | ||
2625 | /* The type of none suggests that owner is actually deleted. | |
2626 | This should not ever happen. */ | |
35df4500 | 2627 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2628 | |
2629 | old_chain = save_current_space_and_thread (); | |
2630 | ||
35df4500 | 2631 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2632 | |
35df4500 | 2633 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2634 | |
2635 | do_cleanups (old_chain); | |
2636 | return ret; | |
2637 | } | |
2638 | ||
c906108c SS |
2639 | /* Clear the "inserted" flag in all breakpoints. */ |
2640 | ||
25b22b0a | 2641 | void |
fba45db2 | 2642 | mark_breakpoints_out (void) |
c906108c | 2643 | { |
35df4500 | 2644 | struct bp_location *bl, **blp_tmp; |
c906108c | 2645 | |
35df4500 TJB |
2646 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2647 | if (bl->pspace == current_program_space) | |
2648 | bl->inserted = 0; | |
c906108c SS |
2649 | } |
2650 | ||
53a5351d JM |
2651 | /* Clear the "inserted" flag in all breakpoints and delete any |
2652 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2653 | |
2654 | Plus other such housekeeping that has to be done for breakpoints | |
2655 | between runs. | |
2656 | ||
53a5351d JM |
2657 | Note: this function gets called at the end of a run (by |
2658 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2659 | init_wait_for_inferior). */ |
c906108c SS |
2660 | |
2661 | ||
2662 | ||
2663 | void | |
fba45db2 | 2664 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2665 | { |
35df4500 TJB |
2666 | struct breakpoint *b, *b_tmp; |
2667 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2668 | int ix; |
6c95b8df | 2669 | struct program_space *pspace = current_program_space; |
c906108c | 2670 | |
50c71eaf PA |
2671 | /* If breakpoint locations are shared across processes, then there's |
2672 | nothing to do. */ | |
2567c7d9 | 2673 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2674 | return; |
2675 | ||
35df4500 | 2676 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2677 | { |
35df4500 TJB |
2678 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2679 | if (bl->pspace == pspace | |
2680 | && bl->owner->enable_state != bp_permanent) | |
2681 | bl->inserted = 0; | |
6c95b8df | 2682 | } |
075f6582 | 2683 | |
35df4500 | 2684 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2685 | { |
6c95b8df PA |
2686 | if (b->loc && b->loc->pspace != pspace) |
2687 | continue; | |
2688 | ||
c5aa993b JM |
2689 | switch (b->type) |
2690 | { | |
2691 | case bp_call_dummy: | |
c906108c | 2692 | |
c5aa993b | 2693 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2694 | cause problems when the inferior is rerun, so we better get |
2695 | rid of it. */ | |
2696 | ||
2697 | case bp_watchpoint_scope: | |
2698 | ||
2699 | /* Also get rid of scope breakpoints. */ | |
2700 | ||
2701 | case bp_shlib_event: | |
2702 | ||
2703 | /* Also remove solib event breakpoints. Their addresses may | |
2704 | have changed since the last time we ran the program. | |
2705 | Actually we may now be debugging against different target; | |
2706 | and so the solib backend that installed this breakpoint may | |
2707 | not be used in by the target. E.g., | |
2708 | ||
2709 | (gdb) file prog-linux | |
2710 | (gdb) run # native linux target | |
2711 | ... | |
2712 | (gdb) kill | |
2713 | (gdb) file prog-win.exe | |
2714 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2715 | */ | |
c906108c | 2716 | |
c5aa993b JM |
2717 | delete_breakpoint (b); |
2718 | break; | |
c906108c | 2719 | |
c5aa993b JM |
2720 | case bp_watchpoint: |
2721 | case bp_hardware_watchpoint: | |
2722 | case bp_read_watchpoint: | |
2723 | case bp_access_watchpoint: | |
c906108c | 2724 | |
c5aa993b JM |
2725 | /* Likewise for watchpoints on local expressions. */ |
2726 | if (b->exp_valid_block != NULL) | |
2727 | delete_breakpoint (b); | |
967af18d | 2728 | else if (context == inf_starting) |
c860120c | 2729 | { |
4a64f543 MS |
2730 | /* Reset val field to force reread of starting value in |
2731 | insert_breakpoints. */ | |
c860120c PM |
2732 | if (b->val) |
2733 | value_free (b->val); | |
2734 | b->val = NULL; | |
fa4727a6 | 2735 | b->val_valid = 0; |
c860120c | 2736 | } |
c5aa993b JM |
2737 | break; |
2738 | default: | |
c5aa993b JM |
2739 | break; |
2740 | } | |
2741 | } | |
1c5cfe86 PA |
2742 | |
2743 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2744 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2745 | decref_bp_location (&bl); | |
1c5cfe86 | 2746 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2747 | } |
2748 | ||
6c95b8df PA |
2749 | /* These functions concern about actual breakpoints inserted in the |
2750 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2751 | we need to hop over the bkpt --- so we check for address space | |
2752 | match, not program space. */ | |
2753 | ||
c2c6d25f JM |
2754 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2755 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2756 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2757 | permanent breakpoint. | |
2758 | - When continuing from a location with an ordinary breakpoint, we | |
2759 | actually single step once before calling insert_breakpoints. | |
2760 | - When continuing from a localion with a permanent breakpoint, we | |
2761 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2762 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2763 | |
c2c6d25f | 2764 | enum breakpoint_here |
6c95b8df | 2765 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2766 | { |
35df4500 | 2767 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2768 | int any_breakpoint_here = 0; |
c906108c | 2769 | |
35df4500 | 2770 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2771 | { |
35df4500 TJB |
2772 | if (bl->loc_type != bp_loc_software_breakpoint |
2773 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2774 | continue; |
2775 | ||
35df4500 TJB |
2776 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2777 | if ((breakpoint_enabled (bl->owner) | |
2778 | || bl->owner->enable_state == bp_permanent) | |
2779 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2780 | aspace, pc)) |
075f6582 DJ |
2781 | { |
2782 | if (overlay_debugging | |
35df4500 TJB |
2783 | && section_is_overlay (bl->section) |
2784 | && !section_is_mapped (bl->section)) | |
075f6582 | 2785 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2786 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2787 | return permanent_breakpoint_here; |
2788 | else | |
2789 | any_breakpoint_here = 1; | |
2790 | } | |
2791 | } | |
c906108c | 2792 | |
c2c6d25f | 2793 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2794 | } |
2795 | ||
1c5cfe86 PA |
2796 | /* Return true if there's a moribund breakpoint at PC. */ |
2797 | ||
2798 | int | |
6c95b8df | 2799 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2800 | { |
2801 | struct bp_location *loc; | |
2802 | int ix; | |
2803 | ||
2804 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2805 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2806 | aspace, pc)) | |
1c5cfe86 PA |
2807 | return 1; |
2808 | ||
2809 | return 0; | |
2810 | } | |
c2c6d25f | 2811 | |
c36b740a | 2812 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2813 | inserted using regular breakpoint_chain / bp_location array |
2814 | mechanism. This does not check for single-step breakpoints, which | |
2815 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2816 | |
2817 | int | |
4a64f543 MS |
2818 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2819 | CORE_ADDR pc) | |
c906108c | 2820 | { |
35df4500 | 2821 | struct bp_location *bl, **blp_tmp; |
c906108c | 2822 | |
35df4500 | 2823 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2824 | { |
35df4500 TJB |
2825 | if (bl->loc_type != bp_loc_software_breakpoint |
2826 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2827 | continue; |
2828 | ||
35df4500 TJB |
2829 | if (bl->inserted |
2830 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2831 | aspace, pc)) |
075f6582 DJ |
2832 | { |
2833 | if (overlay_debugging | |
35df4500 TJB |
2834 | && section_is_overlay (bl->section) |
2835 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2836 | continue; /* unmapped overlay -- can't be a match */ |
2837 | else | |
2838 | return 1; | |
2839 | } | |
c5aa993b | 2840 | } |
c36b740a VP |
2841 | return 0; |
2842 | } | |
2843 | ||
2844 | /* Returns non-zero iff there's either regular breakpoint | |
2845 | or a single step breakpoint inserted at PC. */ | |
2846 | ||
2847 | int | |
6c95b8df | 2848 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2849 | { |
6c95b8df | 2850 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2851 | return 1; |
c906108c | 2852 | |
6c95b8df | 2853 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2854 | return 1; |
2855 | ||
c906108c SS |
2856 | return 0; |
2857 | } | |
2858 | ||
4fa8626c DJ |
2859 | /* This function returns non-zero iff there is a software breakpoint |
2860 | inserted at PC. */ | |
2861 | ||
2862 | int | |
3e43a32a MS |
2863 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2864 | CORE_ADDR pc) | |
4fa8626c | 2865 | { |
35df4500 | 2866 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2867 | |
35df4500 | 2868 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2869 | { |
35df4500 | 2870 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2871 | continue; |
2872 | ||
35df4500 TJB |
2873 | if (bl->inserted |
2874 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2875 | aspace, pc)) |
4fa8626c DJ |
2876 | { |
2877 | if (overlay_debugging | |
35df4500 TJB |
2878 | && section_is_overlay (bl->section) |
2879 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2880 | continue; /* unmapped overlay -- can't be a match */ |
2881 | else | |
2882 | return 1; | |
2883 | } | |
2884 | } | |
2885 | ||
1aafd4da | 2886 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2887 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2888 | return 1; |
2889 | ||
4fa8626c DJ |
2890 | return 0; |
2891 | } | |
2892 | ||
9093389c PA |
2893 | int |
2894 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2895 | CORE_ADDR addr, ULONGEST len) | |
2896 | { | |
2897 | struct breakpoint *bpt; | |
2898 | ||
2899 | ALL_BREAKPOINTS (bpt) | |
2900 | { | |
2901 | struct bp_location *loc; | |
2902 | ||
2903 | if (bpt->type != bp_hardware_watchpoint | |
2904 | && bpt->type != bp_access_watchpoint) | |
2905 | continue; | |
2906 | ||
2907 | if (!breakpoint_enabled (bpt)) | |
2908 | continue; | |
2909 | ||
2910 | for (loc = bpt->loc; loc; loc = loc->next) | |
2911 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2912 | { | |
2913 | CORE_ADDR l, h; | |
2914 | ||
2915 | /* Check for intersection. */ | |
2916 | l = max (loc->address, addr); | |
2917 | h = min (loc->address + loc->length, addr + len); | |
2918 | if (l < h) | |
2919 | return 1; | |
2920 | } | |
2921 | } | |
2922 | return 0; | |
2923 | } | |
2924 | ||
075f6582 DJ |
2925 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2926 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2927 | |
2928 | int | |
6c95b8df PA |
2929 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2930 | ptid_t ptid) | |
c906108c | 2931 | { |
35df4500 | 2932 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 2933 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2934 | int thread = -1; |
4a306c9a | 2935 | int task = 0; |
a6f1cd96 | 2936 | |
35df4500 | 2937 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2938 | { |
35df4500 TJB |
2939 | if (bl->loc_type != bp_loc_software_breakpoint |
2940 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2941 | continue; |
2942 | ||
35df4500 TJB |
2943 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2944 | if (!breakpoint_enabled (bl->owner) | |
2945 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
2946 | continue; |
2947 | ||
35df4500 | 2948 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
6c95b8df | 2949 | aspace, pc)) |
a6f1cd96 JB |
2950 | continue; |
2951 | ||
35df4500 | 2952 | if (bl->owner->thread != -1) |
075f6582 | 2953 | { |
a6f1cd96 JB |
2954 | /* This is a thread-specific breakpoint. Check that ptid |
2955 | matches that thread. If thread hasn't been computed yet, | |
2956 | it is now time to do so. */ | |
2957 | if (thread == -1) | |
2958 | thread = pid_to_thread_id (ptid); | |
35df4500 | 2959 | if (bl->owner->thread != thread) |
a6f1cd96 | 2960 | continue; |
075f6582 | 2961 | } |
a6f1cd96 | 2962 | |
35df4500 | 2963 | if (bl->owner->task != 0) |
4a306c9a JB |
2964 | { |
2965 | /* This is a task-specific breakpoint. Check that ptid | |
2966 | matches that task. If task hasn't been computed yet, | |
2967 | it is now time to do so. */ | |
2968 | if (task == 0) | |
2969 | task = ada_get_task_number (ptid); | |
35df4500 | 2970 | if (bl->owner->task != task) |
4a306c9a JB |
2971 | continue; |
2972 | } | |
2973 | ||
a6f1cd96 | 2974 | if (overlay_debugging |
35df4500 TJB |
2975 | && section_is_overlay (bl->section) |
2976 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
2977 | continue; /* unmapped overlay -- can't be a match */ |
2978 | ||
2979 | return 1; | |
c5aa993b | 2980 | } |
c906108c SS |
2981 | |
2982 | return 0; | |
2983 | } | |
c906108c | 2984 | \f |
c5aa993b | 2985 | |
c906108c SS |
2986 | /* bpstat stuff. External routines' interfaces are documented |
2987 | in breakpoint.h. */ | |
2988 | ||
2989 | int | |
fba45db2 | 2990 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2991 | { |
533be4dd | 2992 | return (ep->type == bp_catchpoint); |
c906108c SS |
2993 | } |
2994 | ||
f431efe5 PA |
2995 | /* Frees any storage that is part of a bpstat. Does not walk the |
2996 | 'next' chain. */ | |
2997 | ||
2998 | static void | |
198757a8 VP |
2999 | bpstat_free (bpstat bs) |
3000 | { | |
3001 | if (bs->old_val != NULL) | |
3002 | value_free (bs->old_val); | |
9add0f1b | 3003 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3004 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3005 | xfree (bs); |
3006 | } | |
3007 | ||
c906108c SS |
3008 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3009 | Also free any storage that is part of a bpstat. */ | |
3010 | ||
3011 | void | |
fba45db2 | 3012 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3013 | { |
3014 | bpstat p; | |
3015 | bpstat q; | |
3016 | ||
3017 | if (bsp == 0) | |
3018 | return; | |
3019 | p = *bsp; | |
3020 | while (p != NULL) | |
3021 | { | |
3022 | q = p->next; | |
198757a8 | 3023 | bpstat_free (p); |
c906108c SS |
3024 | p = q; |
3025 | } | |
3026 | *bsp = NULL; | |
3027 | } | |
3028 | ||
3029 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3030 | is part of the bpstat is copied as well. */ | |
3031 | ||
3032 | bpstat | |
fba45db2 | 3033 | bpstat_copy (bpstat bs) |
c906108c SS |
3034 | { |
3035 | bpstat p = NULL; | |
3036 | bpstat tmp; | |
3037 | bpstat retval = NULL; | |
3038 | ||
3039 | if (bs == NULL) | |
3040 | return bs; | |
3041 | ||
3042 | for (; bs != NULL; bs = bs->next) | |
3043 | { | |
3044 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3045 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3046 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3047 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3048 | if (bs->old_val != NULL) |
3c3185ac JK |
3049 | { |
3050 | tmp->old_val = value_copy (bs->old_val); | |
3051 | release_value (tmp->old_val); | |
3052 | } | |
31cc81e9 | 3053 | |
c906108c SS |
3054 | if (p == NULL) |
3055 | /* This is the first thing in the chain. */ | |
3056 | retval = tmp; | |
3057 | else | |
3058 | p->next = tmp; | |
3059 | p = tmp; | |
3060 | } | |
3061 | p->next = NULL; | |
3062 | return retval; | |
3063 | } | |
3064 | ||
4a64f543 | 3065 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3066 | |
3067 | bpstat | |
fba45db2 | 3068 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3069 | { |
c5aa993b JM |
3070 | if (bsp == NULL) |
3071 | return NULL; | |
c906108c | 3072 | |
c5aa993b JM |
3073 | for (; bsp != NULL; bsp = bsp->next) |
3074 | { | |
f431efe5 | 3075 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3076 | return bsp; |
3077 | } | |
c906108c SS |
3078 | return NULL; |
3079 | } | |
3080 | ||
4a64f543 MS |
3081 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3082 | stopped at. *BSP upon return is a bpstat which points to the | |
3083 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3084 | good for anything but further calls to bpstat_num). | |
3085 | ||
8671a17b PA |
3086 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3087 | Return -1 if stopped at a breakpoint that has been deleted since | |
3088 | we set it. | |
3089 | Return 1 otherwise. */ | |
c906108c SS |
3090 | |
3091 | int | |
8671a17b | 3092 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3093 | { |
3094 | struct breakpoint *b; | |
3095 | ||
3096 | if ((*bsp) == NULL) | |
3097 | return 0; /* No more breakpoint values */ | |
8671a17b | 3098 | |
4a64f543 MS |
3099 | /* We assume we'll never have several bpstats that correspond to a |
3100 | single breakpoint -- otherwise, this function might return the | |
3101 | same number more than once and this will look ugly. */ | |
f431efe5 | 3102 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3103 | *bsp = (*bsp)->next; |
3104 | if (b == NULL) | |
3105 | return -1; /* breakpoint that's been deleted since */ | |
3106 | ||
3107 | *num = b->number; /* We have its number */ | |
3108 | return 1; | |
c906108c SS |
3109 | } |
3110 | ||
3111 | /* Modify BS so that the actions will not be performed. */ | |
3112 | ||
3113 | void | |
fba45db2 | 3114 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3115 | { |
3116 | for (; bs != NULL; bs = bs->next) | |
3117 | { | |
9add0f1b | 3118 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3119 | bs->commands_left = NULL; |
c906108c SS |
3120 | if (bs->old_val != NULL) |
3121 | { | |
3122 | value_free (bs->old_val); | |
3123 | bs->old_val = NULL; | |
3124 | } | |
3125 | } | |
3126 | } | |
3127 | ||
f3b1572e PA |
3128 | /* Called when a command is about to proceed the inferior. */ |
3129 | ||
3130 | static void | |
3131 | breakpoint_about_to_proceed (void) | |
3132 | { | |
3133 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3134 | { | |
3135 | struct thread_info *tp = inferior_thread (); | |
3136 | ||
3137 | /* Allow inferior function calls in breakpoint commands to not | |
3138 | interrupt the command list. When the call finishes | |
3139 | successfully, the inferior will be standing at the same | |
3140 | breakpoint as if nothing happened. */ | |
16c381f0 | 3141 | if (tp->control.in_infcall) |
f3b1572e PA |
3142 | return; |
3143 | } | |
3144 | ||
3145 | breakpoint_proceeded = 1; | |
3146 | } | |
3147 | ||
4a64f543 MS |
3148 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3149 | command. */ | |
c906108c | 3150 | static void |
4efb68b1 | 3151 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3152 | { |
3153 | executing_breakpoint_commands = 0; | |
3154 | } | |
3155 | ||
4a64f543 MS |
3156 | /* Execute all the commands associated with all the breakpoints at |
3157 | this location. Any of these commands could cause the process to | |
3158 | proceed beyond this point, etc. We look out for such changes by | |
3159 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3160 | |
347bddb7 PA |
3161 | Returns true if a breakpoint command resumed the inferior. In that |
3162 | case, it is the caller's responsibility to recall it again with the | |
3163 | bpstat of the current thread. */ | |
3164 | ||
3165 | static int | |
3166 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3167 | { |
3168 | bpstat bs; | |
3169 | struct cleanup *old_chain; | |
347bddb7 | 3170 | int again = 0; |
c906108c SS |
3171 | |
3172 | /* Avoid endless recursion if a `source' command is contained | |
3173 | in bs->commands. */ | |
3174 | if (executing_breakpoint_commands) | |
347bddb7 | 3175 | return 0; |
c906108c SS |
3176 | |
3177 | executing_breakpoint_commands = 1; | |
3178 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3179 | ||
4a64f543 | 3180 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3181 | bs = *bsp; |
3182 | ||
3183 | breakpoint_proceeded = 0; | |
3184 | for (; bs != NULL; bs = bs->next) | |
3185 | { | |
9add0f1b | 3186 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3187 | struct command_line *cmd; |
3188 | struct cleanup *this_cmd_tree_chain; | |
3189 | ||
3190 | /* Take ownership of the BSP's command tree, if it has one. | |
3191 | ||
3192 | The command tree could legitimately contain commands like | |
3193 | 'step' and 'next', which call clear_proceed_status, which | |
3194 | frees stop_bpstat's command tree. To make sure this doesn't | |
3195 | free the tree we're executing out from under us, we need to | |
3196 | take ownership of the tree ourselves. Since a given bpstat's | |
3197 | commands are only executed once, we don't need to copy it; we | |
3198 | can clear the pointer in the bpstat, and make sure we free | |
3199 | the tree when we're done. */ | |
9add0f1b TT |
3200 | ccmd = bs->commands; |
3201 | bs->commands = NULL; | |
3202 | this_cmd_tree_chain | |
3203 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3204 | cmd = bs->commands_left; | |
3205 | bs->commands_left = NULL; | |
6c50ab1c | 3206 | |
c906108c SS |
3207 | while (cmd != NULL) |
3208 | { | |
3209 | execute_control_command (cmd); | |
3210 | ||
3211 | if (breakpoint_proceeded) | |
3212 | break; | |
3213 | else | |
3214 | cmd = cmd->next; | |
3215 | } | |
6c50ab1c JB |
3216 | |
3217 | /* We can free this command tree now. */ | |
3218 | do_cleanups (this_cmd_tree_chain); | |
3219 | ||
c906108c | 3220 | if (breakpoint_proceeded) |
32c1e744 VP |
3221 | { |
3222 | if (target_can_async_p ()) | |
347bddb7 PA |
3223 | /* If we are in async mode, then the target might be still |
3224 | running, not stopped at any breakpoint, so nothing for | |
3225 | us to do here -- just return to the event loop. */ | |
3226 | ; | |
32c1e744 VP |
3227 | else |
3228 | /* In sync mode, when execute_control_command returns | |
3229 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3230 | Breakpoint commands for that stop were not run, since |
3231 | execute_command does not run breakpoint commands -- | |
3232 | only command_line_handler does, but that one is not | |
3233 | involved in execution of breakpoint commands. So, we | |
3234 | can now execute breakpoint commands. It should be | |
3235 | noted that making execute_command do bpstat actions is | |
3236 | not an option -- in this case we'll have recursive | |
3237 | invocation of bpstat for each breakpoint with a | |
3238 | command, and can easily blow up GDB stack. Instead, we | |
3239 | return true, which will trigger the caller to recall us | |
3240 | with the new stop_bpstat. */ | |
3241 | again = 1; | |
3242 | break; | |
32c1e744 | 3243 | } |
c906108c | 3244 | } |
c2b8ed2c | 3245 | do_cleanups (old_chain); |
347bddb7 PA |
3246 | return again; |
3247 | } | |
3248 | ||
3249 | void | |
3250 | bpstat_do_actions (void) | |
3251 | { | |
3252 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3253 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3254 | && target_has_execution | |
3255 | && !is_exited (inferior_ptid) | |
3256 | && !is_executing (inferior_ptid)) | |
3257 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3258 | and only return when it is stopped at the next breakpoint, we | |
3259 | keep doing breakpoint actions until it returns false to | |
3260 | indicate the inferior was not resumed. */ | |
16c381f0 | 3261 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3262 | break; |
c906108c SS |
3263 | } |
3264 | ||
fa4727a6 DJ |
3265 | /* Print out the (old or new) value associated with a watchpoint. */ |
3266 | ||
3267 | static void | |
3268 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3269 | { | |
3270 | if (val == NULL) | |
3271 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3272 | else | |
79a45b7d TT |
3273 | { |
3274 | struct value_print_options opts; | |
3275 | get_user_print_options (&opts); | |
3276 | value_print (val, stream, &opts); | |
3277 | } | |
fa4727a6 DJ |
3278 | } |
3279 | ||
e514a9d6 | 3280 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3281 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3282 | by having it set different print_it values. |
3283 | ||
3284 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3285 | through the bpstat list of things causing this stop, calling the | |
4a64f543 | 3286 | print_bp_stop_message function on each one. The behavior of the |
e514a9d6 | 3287 | print_bp_stop_message function depends on the print_it field of |
4a64f543 | 3288 | bpstat. If such field so indicates, call this function here. |
e514a9d6 JM |
3289 | |
3290 | Return values from this routine (ultimately used by bpstat_print() | |
3291 | and normal_stop() to decide what to do): | |
3292 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3293 | don't print anything else. | |
3294 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3295 | that something to be followed by a location. | |
3296 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3297 | that something to be followed by a location. | |
3298 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3299 | analysis. */ | |
c906108c | 3300 | |
917317f4 | 3301 | static enum print_stop_action |
fba45db2 | 3302 | print_it_typical (bpstat bs) |
c906108c | 3303 | { |
f7545552 | 3304 | struct cleanup *old_chain; |
4f8d1dc6 | 3305 | struct breakpoint *b; |
89f9893c | 3306 | const struct bp_location *bl; |
8b93c638 | 3307 | struct ui_stream *stb; |
f7545552 TT |
3308 | int bp_temp = 0; |
3309 | enum print_stop_action result; | |
3310 | ||
c906108c SS |
3311 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3312 | which has since been deleted. */ | |
e514a9d6 | 3313 | if (bs->breakpoint_at == NULL) |
917317f4 | 3314 | return PRINT_UNKNOWN; |
2bdf28a0 | 3315 | |
f431efe5 PA |
3316 | gdb_assert (bs->bp_location_at != NULL); |
3317 | ||
3318 | bl = bs->bp_location_at; | |
3319 | b = bs->breakpoint_at; | |
c906108c | 3320 | |
f7545552 TT |
3321 | stb = ui_out_stream_new (uiout); |
3322 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3323 | ||
4f8d1dc6 | 3324 | switch (b->type) |
c906108c | 3325 | { |
e514a9d6 JM |
3326 | case bp_breakpoint: |
3327 | case bp_hardware_breakpoint: | |
f431efe5 | 3328 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3329 | if (bl->address != bl->requested_address) |
3330 | breakpoint_adjustment_warning (bl->requested_address, | |
3331 | bl->address, | |
4f8d1dc6 VP |
3332 | b->number, 1); |
3333 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3334 | if (bp_temp) |
3335 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3336 | else | |
3337 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3338 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3339 | { |
3340 | ui_out_field_string (uiout, "reason", | |
3341 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3342 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3343 | } | |
4f8d1dc6 | 3344 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3345 | ui_out_text (uiout, ", "); |
f7545552 | 3346 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3347 | break; |
3348 | ||
3349 | case bp_shlib_event: | |
917317f4 JM |
3350 | /* Did we stop because the user set the stop_on_solib_events |
3351 | variable? (If so, we report this as a generic, "Stopped due | |
3352 | to shlib event" message.) */ | |
a3f17187 | 3353 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3354 | result = PRINT_NOTHING; |
e514a9d6 JM |
3355 | break; |
3356 | ||
c4093a6a | 3357 | case bp_thread_event: |
4a64f543 | 3358 | /* Not sure how we will get here. |
c4093a6a | 3359 | GDB should not stop for these breakpoints. */ |
a3f17187 | 3360 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3361 | result = PRINT_NOTHING; |
c4093a6a JM |
3362 | break; |
3363 | ||
1900040c | 3364 | case bp_overlay_event: |
4a64f543 | 3365 | /* By analogy with the thread event, GDB should not stop for these. */ |
a3f17187 | 3366 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3367 | result = PRINT_NOTHING; |
1900040c MS |
3368 | break; |
3369 | ||
0fd8e87f UW |
3370 | case bp_longjmp_master: |
3371 | /* These should never be enabled. */ | |
3372 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3373 | result = PRINT_NOTHING; | |
3374 | break; | |
3375 | ||
aa7d318d TT |
3376 | case bp_std_terminate_master: |
3377 | /* These should never be enabled. */ | |
3e43a32a MS |
3378 | printf_filtered (_("std::terminate Master Breakpoint: " |
3379 | "gdb should not stop!\n")); | |
aa7d318d TT |
3380 | result = PRINT_NOTHING; |
3381 | break; | |
3382 | ||
186c406b TT |
3383 | case bp_exception_master: |
3384 | /* These should never be enabled. */ | |
3e43a32a MS |
3385 | printf_filtered (_("Exception Master Breakpoint: " |
3386 | "gdb should not stop!\n")); | |
186c406b TT |
3387 | result = PRINT_NOTHING; |
3388 | break; | |
3389 | ||
e514a9d6 JM |
3390 | case bp_watchpoint: |
3391 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3392 | annotate_watchpoint (b->number); |
3393 | if (ui_out_is_mi_like_p (uiout)) | |
3394 | ui_out_field_string | |
3395 | (uiout, "reason", | |
3396 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3397 | mention (b); | |
f7545552 | 3398 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3399 | ui_out_text (uiout, "\nOld value = "); |
3400 | watchpoint_value_print (bs->old_val, stb->stream); | |
3401 | ui_out_field_stream (uiout, "old", stb); | |
3402 | ui_out_text (uiout, "\nNew value = "); | |
3403 | watchpoint_value_print (b->val, stb->stream); | |
3404 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3405 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3406 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3407 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3408 | break; |
3409 | ||
3410 | case bp_read_watchpoint: | |
9dc5e2a9 | 3411 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3412 | ui_out_field_string |
3413 | (uiout, "reason", | |
3414 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3415 | mention (b); |
f7545552 | 3416 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3417 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3418 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3419 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3420 | ui_out_text (uiout, "\n"); |
f7545552 | 3421 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3422 | break; |
3423 | ||
3424 | case bp_access_watchpoint: | |
fa4727a6 | 3425 | if (bs->old_val != NULL) |
8b93c638 | 3426 | { |
4f8d1dc6 | 3427 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3428 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3429 | ui_out_field_string |
3430 | (uiout, "reason", | |
3431 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3432 | mention (b); |
f7545552 | 3433 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3434 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3435 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3436 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3437 | ui_out_text (uiout, "\nNew value = "); |
3438 | } | |
3439 | else | |
3440 | { | |
4f8d1dc6 | 3441 | mention (b); |
9dc5e2a9 | 3442 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3443 | ui_out_field_string |
3444 | (uiout, "reason", | |
3445 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3446 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3447 | ui_out_text (uiout, "\nValue = "); |
3448 | } | |
fa4727a6 | 3449 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3450 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3451 | ui_out_text (uiout, "\n"); |
f7545552 | 3452 | result = PRINT_UNKNOWN; |
e514a9d6 | 3453 | break; |
4ce44c66 | 3454 | |
e514a9d6 | 3455 | /* Fall through, we don't deal with these types of breakpoints |
4a64f543 | 3456 | here. */ |
e514a9d6 | 3457 | |
11cf8741 | 3458 | case bp_finish: |
9dc5e2a9 | 3459 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3460 | ui_out_field_string |
3461 | (uiout, "reason", | |
3462 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3463 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3464 | break; |
3465 | ||
e514a9d6 | 3466 | case bp_until: |
9dc5e2a9 | 3467 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3468 | ui_out_field_string |
3469 | (uiout, "reason", | |
3470 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3471 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3472 | break; |
3473 | ||
c2d11a7d | 3474 | case bp_none: |
e514a9d6 JM |
3475 | case bp_longjmp: |
3476 | case bp_longjmp_resume: | |
186c406b TT |
3477 | case bp_exception: |
3478 | case bp_exception_resume: | |
e514a9d6 | 3479 | case bp_step_resume: |
e514a9d6 JM |
3480 | case bp_watchpoint_scope: |
3481 | case bp_call_dummy: | |
aa7d318d | 3482 | case bp_std_terminate: |
1042e4c0 | 3483 | case bp_tracepoint: |
7a697b8d | 3484 | case bp_fast_tracepoint: |
4efc6507 | 3485 | case bp_jit_event: |
e514a9d6 | 3486 | default: |
f7545552 TT |
3487 | result = PRINT_UNKNOWN; |
3488 | break; | |
e514a9d6 | 3489 | } |
f7545552 TT |
3490 | |
3491 | do_cleanups (old_chain); | |
3492 | return result; | |
e514a9d6 JM |
3493 | } |
3494 | ||
3495 | /* Generic routine for printing messages indicating why we | |
4a64f543 | 3496 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3497 | 'print_it' in the bpstat structure. Under some circumstances we |
3498 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3499 | normal_stop(). */ |
e514a9d6 JM |
3500 | |
3501 | static enum print_stop_action | |
3502 | print_bp_stop_message (bpstat bs) | |
3503 | { | |
3504 | switch (bs->print_it) | |
3505 | { | |
3506 | case print_it_noop: | |
4a64f543 | 3507 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3508 | return PRINT_UNKNOWN; |
3509 | break; | |
3510 | ||
3511 | case print_it_done: | |
3512 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3513 | relevant messages. */ |
e514a9d6 JM |
3514 | return PRINT_SRC_AND_LOC; |
3515 | break; | |
3516 | ||
3517 | case print_it_normal: | |
4f8d1dc6 | 3518 | { |
f431efe5 PA |
3519 | struct breakpoint *b = bs->breakpoint_at; |
3520 | ||
4f8d1dc6 VP |
3521 | /* Normal case. Call the breakpoint's print_it method, or |
3522 | print_it_typical. */ | |
3523 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3524 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3525 | return b->ops->print_it (b); | |
3526 | else | |
3527 | return print_it_typical (bs); | |
3528 | } | |
3529 | break; | |
3086aeae | 3530 | |
e514a9d6 | 3531 | default: |
8e65ff28 | 3532 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3533 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3534 | break; |
c906108c | 3535 | } |
c906108c SS |
3536 | } |
3537 | ||
e514a9d6 JM |
3538 | /* Print a message indicating what happened. This is called from |
3539 | normal_stop(). The input to this routine is the head of the bpstat | |
3540 | list - a list of the eventpoints that caused this stop. This | |
3541 | routine calls the generic print routine for printing a message | |
3542 | about reasons for stopping. This will print (for example) the | |
3543 | "Breakpoint n," part of the output. The return value of this | |
3544 | routine is one of: | |
c906108c | 3545 | |
4a64f543 | 3546 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3547 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3548 | code to print the location. An example is |
c5aa993b JM |
3549 | "Breakpoint 1, " which should be followed by |
3550 | the location. | |
917317f4 | 3551 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3552 | to also print the location part of the message. |
3553 | An example is the catch/throw messages, which | |
4a64f543 | 3554 | don't require a location appended to the end. |
917317f4 | 3555 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3556 | further info to be printed. */ |
c906108c | 3557 | |
917317f4 | 3558 | enum print_stop_action |
fba45db2 | 3559 | bpstat_print (bpstat bs) |
c906108c SS |
3560 | { |
3561 | int val; | |
c5aa993b | 3562 | |
c906108c | 3563 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3564 | (Currently all watchpoints go on the bpstat whether hit or not. |
3565 | That probably could (should) be changed, provided care is taken | |
c906108c | 3566 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3567 | for (; bs; bs = bs->next) |
3568 | { | |
3569 | val = print_bp_stop_message (bs); | |
3570 | if (val == PRINT_SRC_ONLY | |
3571 | || val == PRINT_SRC_AND_LOC | |
3572 | || val == PRINT_NOTHING) | |
3573 | return val; | |
3574 | } | |
c906108c | 3575 | |
e514a9d6 | 3576 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3577 | with and nothing was printed. */ |
917317f4 | 3578 | return PRINT_UNKNOWN; |
c906108c SS |
3579 | } |
3580 | ||
4a64f543 MS |
3581 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3582 | used inside a catch_errors to evaluate the breakpoint condition. | |
3583 | The argument is a "struct expression *" that has been cast to a | |
3584 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3585 | |
3586 | static int | |
4efb68b1 | 3587 | breakpoint_cond_eval (void *exp) |
c906108c | 3588 | { |
278cd55f | 3589 | struct value *mark = value_mark (); |
c5aa993b | 3590 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3591 | |
c906108c SS |
3592 | value_free_to_mark (mark); |
3593 | return i; | |
3594 | } | |
3595 | ||
5760d0ab | 3596 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3597 | |
3598 | static bpstat | |
5760d0ab | 3599 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3600 | { |
3601 | bpstat bs; | |
3602 | ||
3603 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3604 | bs->next = NULL; |
3605 | **bs_link_pointer = bs; | |
3606 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3607 | bs->breakpoint_at = bl->owner; |
3608 | bs->bp_location_at = bl; | |
3609 | incref_bp_location (bl); | |
c906108c SS |
3610 | /* If the condition is false, etc., don't do the commands. */ |
3611 | bs->commands = NULL; | |
9add0f1b | 3612 | bs->commands_left = NULL; |
c906108c SS |
3613 | bs->old_val = NULL; |
3614 | bs->print_it = print_it_normal; | |
3615 | return bs; | |
3616 | } | |
3617 | \f | |
d983da9c DJ |
3618 | /* The target has stopped with waitstatus WS. Check if any hardware |
3619 | watchpoints have triggered, according to the target. */ | |
3620 | ||
3621 | int | |
3622 | watchpoints_triggered (struct target_waitstatus *ws) | |
3623 | { | |
d92524f1 | 3624 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3625 | CORE_ADDR addr; |
3626 | struct breakpoint *b; | |
3627 | ||
3628 | if (!stopped_by_watchpoint) | |
3629 | { | |
3630 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3631 | as not triggered. */ | |
3632 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3633 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3634 | b->watchpoint_triggered = watch_triggered_no; |
3635 | ||
3636 | return 0; | |
3637 | } | |
3638 | ||
3639 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3640 | { | |
3641 | /* We were stopped by a watchpoint, but we don't know where. | |
3642 | Mark all watchpoints as unknown. */ | |
3643 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3644 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3645 | b->watchpoint_triggered = watch_triggered_unknown; |
3646 | ||
3647 | return stopped_by_watchpoint; | |
3648 | } | |
3649 | ||
3650 | /* The target could report the data address. Mark watchpoints | |
3651 | affected by this data address as triggered, and all others as not | |
3652 | triggered. */ | |
3653 | ||
3654 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3655 | if (is_hardware_watchpoint (b)) |
d983da9c | 3656 | { |
a5606eee | 3657 | struct bp_location *loc; |
d983da9c DJ |
3658 | |
3659 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3660 | for (loc = b->loc; loc; loc = loc->next) |
3661 | /* Exact match not required. Within range is | |
3662 | sufficient. */ | |
5009afc5 AS |
3663 | if (target_watchpoint_addr_within_range (¤t_target, |
3664 | addr, loc->address, | |
3665 | loc->length)) | |
a5606eee VP |
3666 | { |
3667 | b->watchpoint_triggered = watch_triggered_yes; | |
3668 | break; | |
3669 | } | |
d983da9c DJ |
3670 | } |
3671 | ||
3672 | return 1; | |
3673 | } | |
3674 | ||
c906108c SS |
3675 | /* Possible return values for watchpoint_check (this can't be an enum |
3676 | because of check_errors). */ | |
3677 | /* The watchpoint has been deleted. */ | |
3678 | #define WP_DELETED 1 | |
3679 | /* The value has changed. */ | |
3680 | #define WP_VALUE_CHANGED 2 | |
3681 | /* The value has not changed. */ | |
3682 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3683 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3684 | #define WP_IGNORE 4 | |
c906108c SS |
3685 | |
3686 | #define BP_TEMPFLAG 1 | |
3687 | #define BP_HARDWAREFLAG 2 | |
3688 | ||
4a64f543 MS |
3689 | /* Evaluate watchpoint condition expression and check if its value |
3690 | changed. | |
553e4c11 JB |
3691 | |
3692 | P should be a pointer to struct bpstat, but is defined as a void * | |
3693 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3694 | |
3695 | static int | |
4efb68b1 | 3696 | watchpoint_check (void *p) |
c906108c SS |
3697 | { |
3698 | bpstat bs = (bpstat) p; | |
3699 | struct breakpoint *b; | |
3700 | struct frame_info *fr; | |
3701 | int within_current_scope; | |
3702 | ||
f431efe5 | 3703 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3704 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3705 | b = bs->breakpoint_at; |
c906108c | 3706 | |
f6bc2008 PA |
3707 | /* If this is a local watchpoint, we only want to check if the |
3708 | watchpoint frame is in scope if the current thread is the thread | |
3709 | that was used to create the watchpoint. */ | |
3710 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3711 | return WP_IGNORE; |
f6bc2008 | 3712 | |
c906108c SS |
3713 | if (b->exp_valid_block == NULL) |
3714 | within_current_scope = 1; | |
3715 | else | |
3716 | { | |
edb3359d DJ |
3717 | struct frame_info *frame = get_current_frame (); |
3718 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3719 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3720 | ||
4a64f543 MS |
3721 | /* in_function_epilogue_p() returns a non-zero value if we're |
3722 | still in the function but the stack frame has already been | |
3723 | invalidated. Since we can't rely on the values of local | |
3724 | variables after the stack has been destroyed, we are treating | |
3725 | the watchpoint in that state as `not changed' without further | |
3726 | checking. Don't mark watchpoints as changed if the current | |
3727 | frame is in an epilogue - even if they are in some other | |
3728 | frame, our view of the stack is likely to be wrong and | |
3729 | frame_find_by_id could error out. */ | |
a0f49112 | 3730 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3731 | return WP_IGNORE; |
a0f49112 | 3732 | |
101dcfbe | 3733 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3734 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3735 | |
3736 | /* If we've gotten confused in the unwinder, we might have | |
3737 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3738 | if (within_current_scope) |
3739 | { | |
3740 | struct symbol *function; | |
3741 | ||
3742 | function = get_frame_function (fr); | |
3743 | if (function == NULL | |
3744 | || !contained_in (b->exp_valid_block, | |
3745 | SYMBOL_BLOCK_VALUE (function))) | |
3746 | within_current_scope = 0; | |
3747 | } | |
69fbadd5 | 3748 | |
edb3359d | 3749 | if (within_current_scope) |
c906108c SS |
3750 | /* If we end up stopping, the current frame will get selected |
3751 | in normal_stop. So this call to select_frame won't affect | |
3752 | the user. */ | |
0f7d239c | 3753 | select_frame (fr); |
c906108c | 3754 | } |
c5aa993b | 3755 | |
c906108c SS |
3756 | if (within_current_scope) |
3757 | { | |
4a64f543 MS |
3758 | /* We use value_{,free_to_}mark because it could be a *long* |
3759 | time before we return to the command level and call | |
3760 | free_all_values. We can't call free_all_values because we | |
3761 | might be in the middle of evaluating a function call. */ | |
c906108c | 3762 | |
0cf6dd15 | 3763 | int pc = 0; |
278cd55f | 3764 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3765 | struct value *new_val; |
3766 | ||
0cf6dd15 | 3767 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3768 | |
4a64f543 MS |
3769 | /* We use value_equal_contents instead of value_equal because |
3770 | the latter coerces an array to a pointer, thus comparing just | |
3771 | the address of the array instead of its contents. This is | |
3772 | not what we want. */ | |
fa4727a6 | 3773 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3774 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3775 | { |
fa4727a6 DJ |
3776 | if (new_val != NULL) |
3777 | { | |
3778 | release_value (new_val); | |
3779 | value_free_to_mark (mark); | |
3780 | } | |
c906108c SS |
3781 | bs->old_val = b->val; |
3782 | b->val = new_val; | |
fa4727a6 | 3783 | b->val_valid = 1; |
c906108c SS |
3784 | return WP_VALUE_CHANGED; |
3785 | } | |
3786 | else | |
3787 | { | |
60e1c644 | 3788 | /* Nothing changed. */ |
c906108c | 3789 | value_free_to_mark (mark); |
c906108c SS |
3790 | return WP_VALUE_NOT_CHANGED; |
3791 | } | |
3792 | } | |
3793 | else | |
3794 | { | |
3795 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3796 | if we temporarily ignored the watchpoint, then when |
3797 | we reenter the block in which it is valid it contains | |
3798 | garbage (in the case of a function, it may have two | |
3799 | garbage values, one before and one after the prologue). | |
3800 | So we can't even detect the first assignment to it and | |
3801 | watch after that (since the garbage may or may not equal | |
3802 | the first value assigned). */ | |
4ce44c66 JM |
3803 | /* We print all the stop information in print_it_typical(), but |
3804 | in this case, by the time we call print_it_typical() this bp | |
4a64f543 MS |
3805 | will be deleted already. So we have no choice but print the |
3806 | information here. */ | |
9dc5e2a9 | 3807 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3808 | ui_out_field_string |
3809 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3810 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3811 | ui_out_field_int (uiout, "wpnum", b->number); |
3e43a32a MS |
3812 | ui_out_text (uiout, |
3813 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3814 | which its expression is valid.\n"); |
4ce44c66 | 3815 | |
c906108c | 3816 | if (b->related_breakpoint) |
60e1c644 PA |
3817 | { |
3818 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3819 | b->related_breakpoint->related_breakpoint = NULL; | |
3820 | b->related_breakpoint = NULL; | |
3821 | } | |
b5de0fa7 | 3822 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3823 | |
3824 | return WP_DELETED; | |
3825 | } | |
3826 | } | |
3827 | ||
18a18393 VP |
3828 | /* Return true if it looks like target has stopped due to hitting |
3829 | breakpoint location BL. This function does not check if we | |
3830 | should stop, only if BL explains the stop. */ | |
3831 | static int | |
6c95b8df PA |
3832 | bpstat_check_location (const struct bp_location *bl, |
3833 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3834 | { |
3835 | struct breakpoint *b = bl->owner; | |
3836 | ||
2bdf28a0 JK |
3837 | /* BL is from existing struct breakpoint. */ |
3838 | gdb_assert (b != NULL); | |
3839 | ||
e8595ef6 SS |
3840 | /* By definition, the inferior does not report stops at |
3841 | tracepoints. */ | |
d77f58be | 3842 | if (is_tracepoint (b)) |
e8595ef6 SS |
3843 | return 0; |
3844 | ||
cc60f2e3 | 3845 | if (!is_watchpoint (b) |
18a18393 | 3846 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3847 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3848 | { |
6c95b8df PA |
3849 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3850 | aspace, bp_addr)) | |
18a18393 VP |
3851 | return 0; |
3852 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3853 | && section_is_overlay (bl->section) |
18a18393 VP |
3854 | && !section_is_mapped (bl->section)) |
3855 | return 0; | |
3856 | } | |
cc60f2e3 | 3857 | |
18a18393 VP |
3858 | /* Continuable hardware watchpoints are treated as non-existent if the |
3859 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3860 | some data address). Otherwise gdb won't stop on a break instruction | |
3861 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3862 | been defined. Also skip watchpoints which we know did not trigger | |
3863 | (did not match the data address). */ | |
cc60f2e3 PA |
3864 | |
3865 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3866 | && b->watchpoint_triggered == watch_triggered_no) |
3867 | return 0; | |
3868 | ||
3869 | if (b->type == bp_hardware_breakpoint) | |
3870 | { | |
3871 | if (bl->address != bp_addr) | |
3872 | return 0; | |
3873 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3874 | && section_is_overlay (bl->section) |
18a18393 VP |
3875 | && !section_is_mapped (bl->section)) |
3876 | return 0; | |
3877 | } | |
ce78b96d | 3878 | |
ce78b96d JB |
3879 | if (b->type == bp_catchpoint) |
3880 | { | |
3881 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3882 | if (!b->ops->breakpoint_hit (b)) | |
3883 | return 0; | |
3884 | } | |
3885 | ||
18a18393 VP |
3886 | return 1; |
3887 | } | |
3888 | ||
3889 | /* If BS refers to a watchpoint, determine if the watched values | |
3890 | has actually changed, and we should stop. If not, set BS->stop | |
3891 | to 0. */ | |
3892 | static void | |
3893 | bpstat_check_watchpoint (bpstat bs) | |
3894 | { | |
2bdf28a0 JK |
3895 | const struct bp_location *bl; |
3896 | struct breakpoint *b; | |
3897 | ||
3898 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3899 | bl = bs->bp_location_at; |
2bdf28a0 | 3900 | gdb_assert (bl != NULL); |
f431efe5 | 3901 | b = bs->breakpoint_at; |
2bdf28a0 | 3902 | gdb_assert (b != NULL); |
18a18393 | 3903 | |
cc60f2e3 | 3904 | if (is_watchpoint (b)) |
18a18393 | 3905 | { |
18a18393 VP |
3906 | int must_check_value = 0; |
3907 | ||
3908 | if (b->type == bp_watchpoint) | |
3909 | /* For a software watchpoint, we must always check the | |
3910 | watched value. */ | |
3911 | must_check_value = 1; | |
3912 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3913 | /* We have a hardware watchpoint (read, write, or access) | |
3914 | and the target earlier reported an address watched by | |
3915 | this watchpoint. */ | |
3916 | must_check_value = 1; | |
3917 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3918 | && b->type == bp_hardware_watchpoint) | |
3919 | /* We were stopped by a hardware watchpoint, but the target could | |
3920 | not report the data address. We must check the watchpoint's | |
3921 | value. Access and read watchpoints are out of luck; without | |
3922 | a data address, we can't figure it out. */ | |
3923 | must_check_value = 1; | |
3924 | ||
3925 | if (must_check_value) | |
3926 | { | |
3e43a32a MS |
3927 | char *message |
3928 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3929 | b->number); | |
18a18393 VP |
3930 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3931 | int e = catch_errors (watchpoint_check, bs, message, | |
3932 | RETURN_MASK_ALL); | |
3933 | do_cleanups (cleanups); | |
3934 | switch (e) | |
3935 | { | |
3936 | case WP_DELETED: | |
3937 | /* We've already printed what needs to be printed. */ | |
3938 | bs->print_it = print_it_done; | |
3939 | /* Stop. */ | |
3940 | break; | |
60e1c644 PA |
3941 | case WP_IGNORE: |
3942 | bs->print_it = print_it_noop; | |
3943 | bs->stop = 0; | |
3944 | break; | |
18a18393 VP |
3945 | case WP_VALUE_CHANGED: |
3946 | if (b->type == bp_read_watchpoint) | |
3947 | { | |
85d721b8 PA |
3948 | /* There are two cases to consider here: |
3949 | ||
4a64f543 | 3950 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3951 | In that case, trust the target, and always report |
3952 | the watchpoint hit to the user. Even though | |
3953 | reads don't cause value changes, the value may | |
3954 | have changed since the last time it was read, and | |
3955 | since we're not trapping writes, we will not see | |
3956 | those, and as such we should ignore our notion of | |
3957 | old value. | |
3958 | ||
4a64f543 | 3959 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3960 | reads and writes. There are two ways this may |
3961 | happen: | |
3962 | ||
4a64f543 | 3963 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3964 | reads only, but can break on accesses (reads or |
3965 | writes), such as e.g., x86. We detect this case | |
3966 | at the time we try to insert read watchpoints. | |
3967 | ||
4a64f543 | 3968 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3969 | watchpoints, but, the user set an access or write |
3970 | watchpoint watching the same memory as this read | |
3971 | watchpoint. | |
3972 | ||
3973 | If we're watching memory writes as well as reads, | |
3974 | ignore watchpoint hits when we find that the | |
3975 | value hasn't changed, as reads don't cause | |
3976 | changes. This still gives false positives when | |
3977 | the program writes the same value to memory as | |
3978 | what there was already in memory (we will confuse | |
3979 | it for a read), but it's much better than | |
3980 | nothing. */ | |
3981 | ||
3982 | int other_write_watchpoint = 0; | |
3983 | ||
3984 | if (bl->watchpoint_type == hw_read) | |
3985 | { | |
3986 | struct breakpoint *other_b; | |
3987 | ||
3988 | ALL_BREAKPOINTS (other_b) | |
3989 | if ((other_b->type == bp_hardware_watchpoint | |
3990 | || other_b->type == bp_access_watchpoint) | |
3991 | && (other_b->watchpoint_triggered | |
3992 | == watch_triggered_yes)) | |
3993 | { | |
3994 | other_write_watchpoint = 1; | |
3995 | break; | |
3996 | } | |
3997 | } | |
3998 | ||
3999 | if (other_write_watchpoint | |
4000 | || bl->watchpoint_type == hw_access) | |
4001 | { | |
4002 | /* We're watching the same memory for writes, | |
4003 | and the value changed since the last time we | |
4004 | updated it, so this trap must be for a write. | |
4005 | Ignore it. */ | |
4006 | bs->print_it = print_it_noop; | |
4007 | bs->stop = 0; | |
4008 | } | |
18a18393 VP |
4009 | } |
4010 | break; | |
4011 | case WP_VALUE_NOT_CHANGED: | |
4012 | if (b->type == bp_hardware_watchpoint | |
4013 | || b->type == bp_watchpoint) | |
4014 | { | |
4015 | /* Don't stop: write watchpoints shouldn't fire if | |
4016 | the value hasn't changed. */ | |
4017 | bs->print_it = print_it_noop; | |
4018 | bs->stop = 0; | |
4019 | } | |
4020 | /* Stop. */ | |
4021 | break; | |
4022 | default: | |
4023 | /* Can't happen. */ | |
4024 | case 0: | |
4025 | /* Error from catch_errors. */ | |
4026 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
4027 | if (b->related_breakpoint) | |
4028 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
4029 | b->disposition = disp_del_at_next_stop; | |
4030 | /* We've already printed what needs to be printed. */ | |
4031 | bs->print_it = print_it_done; | |
4032 | break; | |
4033 | } | |
4034 | } | |
4035 | else /* must_check_value == 0 */ | |
4036 | { | |
4037 | /* This is a case where some watchpoint(s) triggered, but | |
4038 | not at the address of this watchpoint, or else no | |
4039 | watchpoint triggered after all. So don't print | |
4040 | anything for this watchpoint. */ | |
4041 | bs->print_it = print_it_noop; | |
4042 | bs->stop = 0; | |
4043 | } | |
4044 | } | |
4045 | } | |
4046 | ||
4047 | ||
4048 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4049 | of breakpoint referred to by BS. If we should not stop for this | |
4050 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4051 | |
18a18393 VP |
4052 | static void |
4053 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4054 | { | |
4055 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4056 | const struct bp_location *bl; |
4057 | struct breakpoint *b; | |
4058 | ||
4059 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4060 | bl = bs->bp_location_at; |
2bdf28a0 | 4061 | gdb_assert (bl != NULL); |
f431efe5 | 4062 | b = bs->breakpoint_at; |
2bdf28a0 | 4063 | gdb_assert (b != NULL); |
18a18393 VP |
4064 | |
4065 | if (frame_id_p (b->frame_id) | |
edb3359d | 4066 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4067 | bs->stop = 0; |
4068 | else if (bs->stop) | |
4069 | { | |
4070 | int value_is_zero = 0; | |
60e1c644 PA |
4071 | struct expression *cond; |
4072 | ||
60e1c644 PA |
4073 | if (is_watchpoint (b)) |
4074 | cond = b->cond_exp; | |
4075 | else | |
4076 | cond = bl->cond; | |
4077 | ||
f431efe5 | 4078 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4079 | { |
60e1c644 PA |
4080 | int within_current_scope = 1; |
4081 | ||
c5bc3a77 DJ |
4082 | /* We use value_mark and value_free_to_mark because it could |
4083 | be a long time before we return to the command level and | |
4084 | call free_all_values. We can't call free_all_values | |
4085 | because we might be in the middle of evaluating a | |
4086 | function call. */ | |
4087 | struct value *mark = value_mark (); | |
4088 | ||
edb3359d DJ |
4089 | /* Need to select the frame, with all that implies so that |
4090 | the conditions will have the right context. Because we | |
4091 | use the frame, we will not see an inlined function's | |
4092 | variables when we arrive at a breakpoint at the start | |
4093 | of the inlined function; the current frame will be the | |
4094 | call site. */ | |
60e1c644 PA |
4095 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
4096 | select_frame (get_current_frame ()); | |
4097 | else | |
4098 | { | |
4099 | struct frame_info *frame; | |
4100 | ||
4101 | /* For local watchpoint expressions, which particular | |
4102 | instance of a local is being watched matters, so we | |
4103 | keep track of the frame to evaluate the expression | |
4104 | in. To evaluate the condition however, it doesn't | |
4105 | really matter which instantiation of the function | |
4106 | where the condition makes sense triggers the | |
4107 | watchpoint. This allows an expression like "watch | |
4108 | global if q > 10" set in `func', catch writes to | |
4109 | global on all threads that call `func', or catch | |
4110 | writes on all recursive calls of `func' by a single | |
4111 | thread. We simply always evaluate the condition in | |
4112 | the innermost frame that's executing where it makes | |
4113 | sense to evaluate the condition. It seems | |
4114 | intuitive. */ | |
4115 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4116 | if (frame != NULL) | |
4117 | select_frame (frame); | |
4118 | else | |
4119 | within_current_scope = 0; | |
4120 | } | |
4121 | if (within_current_scope) | |
4122 | value_is_zero | |
4123 | = catch_errors (breakpoint_cond_eval, cond, | |
4124 | "Error in testing breakpoint condition:\n", | |
4125 | RETURN_MASK_ALL); | |
4126 | else | |
4127 | { | |
4128 | warning (_("Watchpoint condition cannot be tested " | |
4129 | "in the current scope")); | |
4130 | /* If we failed to set the right context for this | |
4131 | watchpoint, unconditionally report it. */ | |
4132 | value_is_zero = 0; | |
4133 | } | |
4a64f543 | 4134 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4135 | value_free_to_mark (mark); |
18a18393 | 4136 | } |
60e1c644 PA |
4137 | |
4138 | if (cond && value_is_zero) | |
18a18393 VP |
4139 | { |
4140 | bs->stop = 0; | |
4141 | } | |
4142 | else if (b->thread != -1 && b->thread != thread_id) | |
4143 | { | |
4144 | bs->stop = 0; | |
4145 | } | |
4146 | else if (b->ignore_count > 0) | |
4147 | { | |
4148 | b->ignore_count--; | |
4149 | annotate_ignore_count_change (); | |
4150 | bs->stop = 0; | |
4a64f543 | 4151 | /* Increase the hit count even though we don't stop. */ |
18a18393 VP |
4152 | ++(b->hit_count); |
4153 | } | |
4154 | } | |
4155 | } | |
4156 | ||
4157 | ||
9709f61c | 4158 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4159 | BP_ADDR in thread PTID. |
c906108c | 4160 | |
d983da9c | 4161 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4162 | don't understand this stop. Result is a chain of bpstat's such |
4163 | that: | |
c906108c | 4164 | |
c5aa993b | 4165 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4166 | |
c5aa993b | 4167 | if we understand why we stopped, the result is not null. |
c906108c | 4168 | |
c5aa993b JM |
4169 | Each element of the chain refers to a particular breakpoint or |
4170 | watchpoint at which we have stopped. (We may have stopped for | |
4171 | several reasons concurrently.) | |
c906108c | 4172 | |
c5aa993b JM |
4173 | Each element of the chain has valid next, breakpoint_at, |
4174 | commands, FIXME??? fields. */ | |
c906108c SS |
4175 | |
4176 | bpstat | |
6c95b8df PA |
4177 | bpstat_stop_status (struct address_space *aspace, |
4178 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4179 | { |
0d381245 | 4180 | struct breakpoint *b = NULL; |
afe38095 | 4181 | struct bp_location *bl; |
20874c92 | 4182 | struct bp_location *loc; |
5760d0ab JK |
4183 | /* First item of allocated bpstat's. */ |
4184 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4185 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4186 | bpstat bs; |
20874c92 | 4187 | int ix; |
429374b8 | 4188 | int need_remove_insert; |
f431efe5 | 4189 | int removed_any; |
c906108c | 4190 | |
f431efe5 PA |
4191 | /* First, build the bpstat chain with locations that explain a |
4192 | target stop, while being careful to not set the target running, | |
4193 | as that may invalidate locations (in particular watchpoint | |
4194 | locations are recreated). Resuming will happen here with | |
4195 | breakpoint conditions or watchpoint expressions that include | |
4196 | inferior function calls. */ | |
c5aa993b | 4197 | |
429374b8 JK |
4198 | ALL_BREAKPOINTS (b) |
4199 | { | |
4200 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4201 | continue; | |
a5606eee | 4202 | |
429374b8 JK |
4203 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4204 | { | |
4a64f543 MS |
4205 | /* For hardware watchpoints, we look only at the first |
4206 | location. The watchpoint_check function will work on the | |
4207 | entire expression, not the individual locations. For | |
4208 | read watchpoints, the watchpoints_triggered function has | |
4209 | checked all locations already. */ | |
429374b8 JK |
4210 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4211 | break; | |
18a18393 | 4212 | |
429374b8 JK |
4213 | if (bl->shlib_disabled) |
4214 | continue; | |
c5aa993b | 4215 | |
429374b8 JK |
4216 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4217 | continue; | |
c5aa993b | 4218 | |
4a64f543 MS |
4219 | /* Come here if it's a watchpoint, or if the break address |
4220 | matches. */ | |
c5aa993b | 4221 | |
4a64f543 MS |
4222 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4223 | explain stop. */ | |
c5aa993b | 4224 | |
f431efe5 PA |
4225 | /* Assume we stop. Should we find a watchpoint that is not |
4226 | actually triggered, or if the condition of the breakpoint | |
4227 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4228 | bs->stop = 1; |
4229 | bs->print = 1; | |
d983da9c | 4230 | |
f431efe5 PA |
4231 | /* If this is a scope breakpoint, mark the associated |
4232 | watchpoint as triggered so that we will handle the | |
4233 | out-of-scope event. We'll get to the watchpoint next | |
4234 | iteration. */ | |
4235 | if (b->type == bp_watchpoint_scope) | |
4236 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
4237 | } | |
4238 | } | |
4239 | ||
4240 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4241 | { | |
4242 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, | |
4243 | aspace, bp_addr)) | |
4244 | { | |
5760d0ab | 4245 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4246 | /* For hits of moribund locations, we should just proceed. */ |
4247 | bs->stop = 0; | |
4248 | bs->print = 0; | |
4249 | bs->print_it = print_it_noop; | |
4250 | } | |
4251 | } | |
4252 | ||
f431efe5 PA |
4253 | /* Now go through the locations that caused the target to stop, and |
4254 | check whether we're interested in reporting this stop to higher | |
4255 | layers, or whether we should resume the target transparently. */ | |
4256 | ||
4257 | removed_any = 0; | |
4258 | ||
5760d0ab | 4259 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4260 | { |
4261 | if (!bs->stop) | |
4262 | continue; | |
4263 | ||
4264 | bpstat_check_watchpoint (bs); | |
4265 | if (!bs->stop) | |
4266 | continue; | |
4267 | ||
4268 | b = bs->breakpoint_at; | |
18a18393 | 4269 | |
429374b8 | 4270 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d | 4271 | || b->type == bp_longjmp_master |
186c406b TT |
4272 | || b->type == bp_std_terminate_master |
4273 | || b->type == bp_exception_master) | |
429374b8 JK |
4274 | /* We do not stop for these. */ |
4275 | bs->stop = 0; | |
4276 | else | |
4277 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4278 | |
429374b8 JK |
4279 | if (bs->stop) |
4280 | { | |
4281 | ++(b->hit_count); | |
c906108c | 4282 | |
4a64f543 | 4283 | /* We will stop here. */ |
429374b8 JK |
4284 | if (b->disposition == disp_disable) |
4285 | { | |
4286 | if (b->enable_state != bp_permanent) | |
4287 | b->enable_state = bp_disabled; | |
f431efe5 | 4288 | removed_any = 1; |
429374b8 JK |
4289 | } |
4290 | if (b->silent) | |
4291 | bs->print = 0; | |
4292 | bs->commands = b->commands; | |
9add0f1b TT |
4293 | incref_counted_command_line (bs->commands); |
4294 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4295 | if (bs->commands_left | |
4296 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4297 | || (xdb_commands | |
4298 | && strcmp ("Q", | |
4299 | bs->commands_left->line) == 0))) | |
429374b8 | 4300 | { |
9add0f1b | 4301 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4302 | bs->print = 0; |
4303 | } | |
429374b8 JK |
4304 | } |
4305 | ||
4306 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4307 | if (bs->stop == 0 || bs->print == 0) | |
4308 | bs->print_it = print_it_noop; | |
429374b8 | 4309 | } |
876fa593 | 4310 | |
d983da9c DJ |
4311 | /* If we aren't stopping, the value of some hardware watchpoint may |
4312 | not have changed, but the intermediate memory locations we are | |
4313 | watching may have. Don't bother if we're stopping; this will get | |
4314 | done later. */ | |
d832cb68 | 4315 | need_remove_insert = 0; |
5760d0ab JK |
4316 | if (! bpstat_causes_stop (bs_head)) |
4317 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4318 | if (!bs->stop |
f431efe5 PA |
4319 | && bs->breakpoint_at |
4320 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4321 | { |
4a64f543 | 4322 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4323 | need_remove_insert = 1; |
d983da9c DJ |
4324 | } |
4325 | ||
d832cb68 | 4326 | if (need_remove_insert) |
2d134ed3 | 4327 | update_global_location_list (1); |
f431efe5 PA |
4328 | else if (removed_any) |
4329 | update_global_location_list (0); | |
d832cb68 | 4330 | |
5760d0ab | 4331 | return bs_head; |
c906108c | 4332 | } |
628fe4e4 JK |
4333 | |
4334 | static void | |
4335 | handle_jit_event (void) | |
4336 | { | |
4337 | struct frame_info *frame; | |
4338 | struct gdbarch *gdbarch; | |
4339 | ||
4340 | /* Switch terminal for any messages produced by | |
4341 | breakpoint_re_set. */ | |
4342 | target_terminal_ours_for_output (); | |
4343 | ||
4344 | frame = get_current_frame (); | |
4345 | gdbarch = get_frame_arch (frame); | |
4346 | ||
4347 | jit_event_handler (gdbarch); | |
4348 | ||
4349 | target_terminal_inferior (); | |
4350 | } | |
4351 | ||
4352 | /* Prepare WHAT final decision for infrun. */ | |
4353 | ||
4354 | /* Decide what infrun needs to do with this bpstat. */ | |
4355 | ||
c906108c | 4356 | struct bpstat_what |
fba45db2 | 4357 | bpstat_what (bpstat bs) |
c906108c | 4358 | { |
c906108c | 4359 | struct bpstat_what retval; |
628fe4e4 JK |
4360 | /* We need to defer calling `solib_add', as adding new symbols |
4361 | resets breakpoints, which in turn deletes breakpoint locations, | |
4362 | and hence may clear unprocessed entries in the BS chain. */ | |
4363 | int shlib_event = 0; | |
4364 | int jit_event = 0; | |
c906108c | 4365 | |
628fe4e4 | 4366 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4367 | retval.call_dummy = STOP_NONE; |
186c406b | 4368 | retval.is_longjmp = 0; |
628fe4e4 | 4369 | |
c906108c SS |
4370 | for (; bs != NULL; bs = bs->next) |
4371 | { | |
628fe4e4 JK |
4372 | /* Extract this BS's action. After processing each BS, we check |
4373 | if its action overrides all we've seem so far. */ | |
4374 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4375 | enum bptype bptype; | |
4376 | ||
c906108c | 4377 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4378 | { |
4379 | /* I suspect this can happen if it was a momentary | |
4380 | breakpoint which has since been deleted. */ | |
4381 | bptype = bp_none; | |
4382 | } | |
f431efe5 | 4383 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4384 | bptype = bp_none; |
20874c92 | 4385 | else |
f431efe5 | 4386 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4387 | |
4388 | switch (bptype) | |
c906108c SS |
4389 | { |
4390 | case bp_none: | |
628fe4e4 | 4391 | break; |
c906108c SS |
4392 | case bp_breakpoint: |
4393 | case bp_hardware_breakpoint: | |
4394 | case bp_until: | |
4395 | case bp_finish: | |
4396 | if (bs->stop) | |
4397 | { | |
4398 | if (bs->print) | |
628fe4e4 | 4399 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4400 | else |
628fe4e4 | 4401 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4402 | } |
4403 | else | |
628fe4e4 | 4404 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4405 | break; |
4406 | case bp_watchpoint: | |
4407 | case bp_hardware_watchpoint: | |
4408 | case bp_read_watchpoint: | |
4409 | case bp_access_watchpoint: | |
4410 | if (bs->stop) | |
4411 | { | |
4412 | if (bs->print) | |
628fe4e4 | 4413 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4414 | else |
628fe4e4 | 4415 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4416 | } |
4417 | else | |
628fe4e4 JK |
4418 | { |
4419 | /* There was a watchpoint, but we're not stopping. | |
4420 | This requires no further action. */ | |
4421 | } | |
c906108c SS |
4422 | break; |
4423 | case bp_longjmp: | |
186c406b | 4424 | case bp_exception: |
628fe4e4 | 4425 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4426 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4427 | break; |
4428 | case bp_longjmp_resume: | |
186c406b | 4429 | case bp_exception_resume: |
628fe4e4 | 4430 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4431 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4432 | break; |
4433 | case bp_step_resume: | |
4434 | if (bs->stop) | |
628fe4e4 JK |
4435 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4436 | else | |
c906108c | 4437 | { |
628fe4e4 JK |
4438 | /* It is for the wrong frame. */ |
4439 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4440 | } |
c906108c | 4441 | break; |
c906108c | 4442 | case bp_watchpoint_scope: |
c4093a6a | 4443 | case bp_thread_event: |
1900040c | 4444 | case bp_overlay_event: |
0fd8e87f | 4445 | case bp_longjmp_master: |
aa7d318d | 4446 | case bp_std_terminate_master: |
186c406b | 4447 | case bp_exception_master: |
628fe4e4 | 4448 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4449 | break; |
ce78b96d | 4450 | case bp_catchpoint: |
c5aa993b JM |
4451 | if (bs->stop) |
4452 | { | |
4453 | if (bs->print) | |
628fe4e4 | 4454 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4455 | else |
628fe4e4 | 4456 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4457 | } |
4458 | else | |
628fe4e4 JK |
4459 | { |
4460 | /* There was a catchpoint, but we're not stopping. | |
4461 | This requires no further action. */ | |
4462 | } | |
4463 | break; | |
4464 | case bp_shlib_event: | |
4465 | shlib_event = 1; | |
4466 | ||
4467 | /* If requested, stop when the dynamic linker notifies GDB | |
4468 | of events. This allows the user to get control and place | |
4469 | breakpoints in initializer routines for dynamically | |
4470 | loaded objects (among other things). */ | |
4471 | if (stop_on_solib_events) | |
4472 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4473 | else | |
4474 | this_action = BPSTAT_WHAT_SINGLE; | |
4475 | break; | |
4476 | case bp_jit_event: | |
4477 | jit_event = 1; | |
4478 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4479 | break; |
c906108c | 4480 | case bp_call_dummy: |
53a5351d JM |
4481 | /* Make sure the action is stop (silent or noisy), |
4482 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4483 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4484 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4485 | break; |
4486 | case bp_std_terminate: | |
4487 | /* Make sure the action is stop (silent or noisy), | |
4488 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4489 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4490 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4491 | break; |
1042e4c0 | 4492 | case bp_tracepoint: |
7a697b8d | 4493 | case bp_fast_tracepoint: |
0fb4aa4b | 4494 | case bp_static_tracepoint: |
1042e4c0 SS |
4495 | /* Tracepoint hits should not be reported back to GDB, and |
4496 | if one got through somehow, it should have been filtered | |
4497 | out already. */ | |
4498 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4499 | _("bpstat_what: tracepoint encountered")); |
628fe4e4 JK |
4500 | default: |
4501 | internal_error (__FILE__, __LINE__, | |
4502 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4503 | } |
628fe4e4 JK |
4504 | |
4505 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4506 | } |
628fe4e4 JK |
4507 | |
4508 | if (shlib_event) | |
4509 | { | |
4510 | if (debug_infrun) | |
4511 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4512 | ||
4513 | /* Check for any newly added shared libraries if we're supposed | |
4514 | to be adding them automatically. */ | |
4515 | ||
4516 | /* Switch terminal for any messages produced by | |
4517 | breakpoint_re_set. */ | |
4518 | target_terminal_ours_for_output (); | |
4519 | ||
4520 | #ifdef SOLIB_ADD | |
4521 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4522 | #else | |
4523 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4524 | #endif | |
4525 | ||
4526 | target_terminal_inferior (); | |
4527 | } | |
4528 | ||
4529 | if (jit_event) | |
4530 | { | |
4531 | if (debug_infrun) | |
4532 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4533 | ||
4534 | handle_jit_event (); | |
4535 | } | |
4536 | ||
c906108c SS |
4537 | return retval; |
4538 | } | |
4539 | ||
4540 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4541 | without hardware support). This isn't related to a specific bpstat, | |
4542 | just to things like whether watchpoints are set. */ | |
4543 | ||
c5aa993b | 4544 | int |
fba45db2 | 4545 | bpstat_should_step (void) |
c906108c SS |
4546 | { |
4547 | struct breakpoint *b; | |
cc59ec59 | 4548 | |
c906108c | 4549 | ALL_BREAKPOINTS (b) |
717a8278 | 4550 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4551 | return 1; |
c906108c SS |
4552 | return 0; |
4553 | } | |
4554 | ||
67822962 PA |
4555 | int |
4556 | bpstat_causes_stop (bpstat bs) | |
4557 | { | |
4558 | for (; bs != NULL; bs = bs->next) | |
4559 | if (bs->stop) | |
4560 | return 1; | |
4561 | ||
4562 | return 0; | |
4563 | } | |
4564 | ||
c906108c | 4565 | \f |
c5aa993b | 4566 | |
859825b8 JK |
4567 | /* Print the LOC location out of the list of B->LOC locations. */ |
4568 | ||
0d381245 VP |
4569 | static void print_breakpoint_location (struct breakpoint *b, |
4570 | struct bp_location *loc, | |
4571 | char *wrap_indent, | |
4572 | struct ui_stream *stb) | |
4573 | { | |
6c95b8df PA |
4574 | struct cleanup *old_chain = save_current_program_space (); |
4575 | ||
859825b8 JK |
4576 | if (loc != NULL && loc->shlib_disabled) |
4577 | loc = NULL; | |
4578 | ||
6c95b8df PA |
4579 | if (loc != NULL) |
4580 | set_current_program_space (loc->pspace); | |
4581 | ||
859825b8 | 4582 | if (b->source_file && loc) |
0d381245 VP |
4583 | { |
4584 | struct symbol *sym | |
4585 | = find_pc_sect_function (loc->address, loc->section); | |
4586 | if (sym) | |
4587 | { | |
4588 | ui_out_text (uiout, "in "); | |
4589 | ui_out_field_string (uiout, "func", | |
4590 | SYMBOL_PRINT_NAME (sym)); | |
4591 | ui_out_wrap_hint (uiout, wrap_indent); | |
4592 | ui_out_text (uiout, " at "); | |
4593 | } | |
4594 | ui_out_field_string (uiout, "file", b->source_file); | |
4595 | ui_out_text (uiout, ":"); | |
4596 | ||
4597 | if (ui_out_is_mi_like_p (uiout)) | |
4598 | { | |
4599 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4600 | char *fullname = symtab_to_fullname (sal.symtab); | |
4601 | ||
4602 | if (fullname) | |
4603 | ui_out_field_string (uiout, "fullname", fullname); | |
4604 | } | |
4605 | ||
4606 | ui_out_field_int (uiout, "line", b->line_number); | |
4607 | } | |
859825b8 | 4608 | else if (loc) |
0d381245 | 4609 | { |
22e722e1 DJ |
4610 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4611 | demangle, ""); | |
0d381245 VP |
4612 | ui_out_field_stream (uiout, "at", stb); |
4613 | } | |
859825b8 JK |
4614 | else |
4615 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4616 | |
4617 | do_cleanups (old_chain); | |
0d381245 VP |
4618 | } |
4619 | ||
269b11a2 PA |
4620 | static const char * |
4621 | bptype_string (enum bptype type) | |
c906108c | 4622 | { |
c4093a6a JM |
4623 | struct ep_type_description |
4624 | { | |
4625 | enum bptype type; | |
4626 | char *description; | |
4627 | }; | |
4628 | static struct ep_type_description bptypes[] = | |
c906108c | 4629 | { |
c5aa993b JM |
4630 | {bp_none, "?deleted?"}, |
4631 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4632 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4633 | {bp_until, "until"}, |
4634 | {bp_finish, "finish"}, | |
4635 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4636 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4637 | {bp_read_watchpoint, "read watchpoint"}, |
4638 | {bp_access_watchpoint, "acc watchpoint"}, | |
4639 | {bp_longjmp, "longjmp"}, | |
4640 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4641 | {bp_exception, "exception"}, |
4642 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4643 | {bp_step_resume, "step resume"}, |
c5aa993b JM |
4644 | {bp_watchpoint_scope, "watchpoint scope"}, |
4645 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4646 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4647 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4648 | {bp_thread_event, "thread events"}, |
1900040c | 4649 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4650 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4651 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4652 | {bp_exception_master, "exception master"}, |
ce78b96d | 4653 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4654 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4655 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4656 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4657 | {bp_jit_event, "jit events"}, |
c5aa993b | 4658 | }; |
269b11a2 PA |
4659 | |
4660 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4661 | || ((int) type != bptypes[(int) type].type)) | |
4662 | internal_error (__FILE__, __LINE__, | |
4663 | _("bptypes table does not describe type #%d."), | |
4664 | (int) type); | |
4665 | ||
4666 | return bptypes[(int) type].description; | |
4667 | } | |
4668 | ||
4669 | /* Print B to gdb_stdout. */ | |
4670 | ||
4671 | static void | |
4672 | print_one_breakpoint_location (struct breakpoint *b, | |
4673 | struct bp_location *loc, | |
4674 | int loc_number, | |
4675 | struct bp_location **last_loc, | |
4676 | int print_address_bits, | |
4677 | int allflag) | |
4678 | { | |
4679 | struct command_line *l; | |
c2c6d25f | 4680 | static char bpenables[] = "nynny"; |
c906108c | 4681 | char wrap_indent[80]; |
8b93c638 JM |
4682 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4683 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4684 | struct cleanup *bkpt_chain; |
c906108c | 4685 | |
0d381245 VP |
4686 | int header_of_multiple = 0; |
4687 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4688 | struct value_print_options opts; |
4689 | ||
4690 | get_user_print_options (&opts); | |
0d381245 VP |
4691 | |
4692 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4693 | /* See comment in print_one_breakpoint concerning treatment of |
4694 | breakpoints with single disabled location. */ | |
0d381245 VP |
4695 | if (loc == NULL |
4696 | && (b->loc != NULL | |
4697 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4698 | header_of_multiple = 1; | |
4699 | if (loc == NULL) | |
4700 | loc = b->loc; | |
4701 | ||
c4093a6a | 4702 | annotate_record (); |
3b31d625 | 4703 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4704 | |
4705 | /* 1 */ | |
4706 | annotate_field (0); | |
0d381245 VP |
4707 | if (part_of_multiple) |
4708 | { | |
4709 | char *formatted; | |
0c6773c1 | 4710 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4711 | ui_out_field_string (uiout, "number", formatted); |
4712 | xfree (formatted); | |
4713 | } | |
4714 | else | |
4715 | { | |
4716 | ui_out_field_int (uiout, "number", b->number); | |
4717 | } | |
c4093a6a JM |
4718 | |
4719 | /* 2 */ | |
4720 | annotate_field (1); | |
0d381245 VP |
4721 | if (part_of_multiple) |
4722 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4723 | else |
4724 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4725 | |
4726 | /* 3 */ | |
4727 | annotate_field (2); | |
0d381245 VP |
4728 | if (part_of_multiple) |
4729 | ui_out_field_skip (uiout, "disp"); | |
4730 | else | |
2cec12e5 | 4731 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4732 | |
c4093a6a JM |
4733 | |
4734 | /* 4 */ | |
4735 | annotate_field (3); | |
0d381245 | 4736 | if (part_of_multiple) |
54e52265 | 4737 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4738 | else |
4a64f543 MS |
4739 | ui_out_field_fmt (uiout, "enabled", "%c", |
4740 | bpenables[(int) b->enable_state]); | |
54e52265 | 4741 | ui_out_spaces (uiout, 2); |
0d381245 | 4742 | |
c4093a6a JM |
4743 | |
4744 | /* 5 and 6 */ | |
4745 | strcpy (wrap_indent, " "); | |
79a45b7d | 4746 | if (opts.addressprint) |
75ac9d7b | 4747 | { |
a6d9a66e | 4748 | if (print_address_bits <= 32) |
75ac9d7b MS |
4749 | strcat (wrap_indent, " "); |
4750 | else | |
4751 | strcat (wrap_indent, " "); | |
4752 | } | |
c906108c | 4753 | |
3086aeae | 4754 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4755 | { |
4a64f543 MS |
4756 | /* Although the print_one can possibly print all locations, |
4757 | calling it here is not likely to get any nice result. So, | |
4758 | make sure there's just one location. */ | |
0d381245 | 4759 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4760 | b->ops->print_one (b, last_loc); |
0d381245 | 4761 | } |
3086aeae DJ |
4762 | else |
4763 | switch (b->type) | |
4764 | { | |
4765 | case bp_none: | |
4766 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4767 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4768 | break; |
c906108c | 4769 | |
3086aeae DJ |
4770 | case bp_watchpoint: |
4771 | case bp_hardware_watchpoint: | |
4772 | case bp_read_watchpoint: | |
4773 | case bp_access_watchpoint: | |
4774 | /* Field 4, the address, is omitted (which makes the columns | |
4775 | not line up too nicely with the headers, but the effect | |
4776 | is relatively readable). */ | |
79a45b7d | 4777 | if (opts.addressprint) |
3086aeae DJ |
4778 | ui_out_field_skip (uiout, "addr"); |
4779 | annotate_field (5); | |
fa8a61dc | 4780 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4781 | break; |
4782 | ||
3086aeae DJ |
4783 | case bp_breakpoint: |
4784 | case bp_hardware_breakpoint: | |
4785 | case bp_until: | |
4786 | case bp_finish: | |
4787 | case bp_longjmp: | |
4788 | case bp_longjmp_resume: | |
186c406b TT |
4789 | case bp_exception: |
4790 | case bp_exception_resume: | |
3086aeae | 4791 | case bp_step_resume: |
3086aeae DJ |
4792 | case bp_watchpoint_scope: |
4793 | case bp_call_dummy: | |
aa7d318d | 4794 | case bp_std_terminate: |
3086aeae DJ |
4795 | case bp_shlib_event: |
4796 | case bp_thread_event: | |
4797 | case bp_overlay_event: | |
0fd8e87f | 4798 | case bp_longjmp_master: |
aa7d318d | 4799 | case bp_std_terminate_master: |
186c406b | 4800 | case bp_exception_master: |
1042e4c0 | 4801 | case bp_tracepoint: |
7a697b8d | 4802 | case bp_fast_tracepoint: |
0fb4aa4b | 4803 | case bp_static_tracepoint: |
4efc6507 | 4804 | case bp_jit_event: |
79a45b7d | 4805 | if (opts.addressprint) |
3086aeae DJ |
4806 | { |
4807 | annotate_field (4); | |
54e52265 | 4808 | if (header_of_multiple) |
0d381245 | 4809 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4810 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4811 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4812 | else |
5af949e3 UW |
4813 | ui_out_field_core_addr (uiout, "addr", |
4814 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4815 | } |
4816 | annotate_field (5); | |
0d381245 VP |
4817 | if (!header_of_multiple) |
4818 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4819 | if (b->loc) | |
a6d9a66e | 4820 | *last_loc = b->loc; |
3086aeae DJ |
4821 | break; |
4822 | } | |
c906108c | 4823 | |
6c95b8df PA |
4824 | |
4825 | /* For backward compatibility, don't display inferiors unless there | |
4826 | are several. */ | |
4827 | if (loc != NULL | |
4828 | && !header_of_multiple | |
4829 | && (allflag | |
4830 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4831 | && (number_of_program_spaces () > 1 | |
4832 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4833 | /* LOC is for existing B, it cannot be in |
4834 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4835 | && loc->owner->type != bp_catchpoint))) |
4836 | { | |
4837 | struct inferior *inf; | |
4838 | int first = 1; | |
4839 | ||
4840 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4841 | { | |
4842 | if (inf->pspace == loc->pspace) | |
4843 | { | |
4844 | if (first) | |
4845 | { | |
4846 | first = 0; | |
4847 | ui_out_text (uiout, " inf "); | |
4848 | } | |
4849 | else | |
4850 | ui_out_text (uiout, ", "); | |
4851 | ui_out_text (uiout, plongest (inf->num)); | |
4852 | } | |
4853 | } | |
4854 | } | |
4855 | ||
4a306c9a | 4856 | if (!part_of_multiple) |
c4093a6a | 4857 | { |
4a306c9a JB |
4858 | if (b->thread != -1) |
4859 | { | |
4860 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4861 | "stop only in" line a little further down. */ |
4a306c9a JB |
4862 | ui_out_text (uiout, " thread "); |
4863 | ui_out_field_int (uiout, "thread", b->thread); | |
4864 | } | |
4865 | else if (b->task != 0) | |
4866 | { | |
4867 | ui_out_text (uiout, " task "); | |
4868 | ui_out_field_int (uiout, "task", b->task); | |
4869 | } | |
c4093a6a JM |
4870 | } |
4871 | ||
8b93c638 | 4872 | ui_out_text (uiout, "\n"); |
c4093a6a | 4873 | |
0fb4aa4b PA |
4874 | if (!part_of_multiple && b->static_trace_marker_id) |
4875 | { | |
4876 | gdb_assert (b->type == bp_static_tracepoint); | |
4877 | ||
4878 | ui_out_text (uiout, "\tmarker id is "); | |
4879 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
4880 | b->static_trace_marker_id); | |
4881 | ui_out_text (uiout, "\n"); | |
4882 | } | |
4883 | ||
0d381245 | 4884 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4885 | { |
4886 | annotate_field (6); | |
8b93c638 | 4887 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4888 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4889 | the frame ID. */ | |
5af949e3 UW |
4890 | ui_out_field_core_addr (uiout, "frame", |
4891 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4892 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4893 | } |
4894 | ||
0d381245 | 4895 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4896 | { |
f7f9143b JB |
4897 | /* We do not print the condition for Ada exception catchpoints |
4898 | because the condition is an internal implementation detail | |
4899 | that we do not want to expose to the user. */ | |
c4093a6a | 4900 | annotate_field (7); |
d77f58be | 4901 | if (is_tracepoint (b)) |
1042e4c0 SS |
4902 | ui_out_text (uiout, "\ttrace only if "); |
4903 | else | |
4904 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4905 | ui_out_field_string (uiout, "cond", b->cond_string); |
4906 | ui_out_text (uiout, "\n"); | |
4907 | } | |
4908 | ||
0d381245 | 4909 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4910 | { |
4a64f543 | 4911 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4912 | ui_out_text (uiout, "\tstop only in thread "); |
4913 | ui_out_field_int (uiout, "thread", b->thread); | |
4914 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4915 | } |
4916 | ||
63c715c6 | 4917 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4918 | { |
4a64f543 | 4919 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4920 | if (ep_is_catchpoint (b)) |
4921 | ui_out_text (uiout, "\tcatchpoint"); | |
4922 | else | |
4923 | ui_out_text (uiout, "\tbreakpoint"); | |
4924 | ui_out_text (uiout, " already hit "); | |
4925 | ui_out_field_int (uiout, "times", b->hit_count); | |
4926 | if (b->hit_count == 1) | |
4927 | ui_out_text (uiout, " time\n"); | |
4928 | else | |
4929 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4930 | } |
4931 | ||
4a64f543 MS |
4932 | /* Output the count also if it is zero, but only if this is mi. |
4933 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4934 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4935 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4936 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4937 | |
0d381245 | 4938 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4939 | { |
4940 | annotate_field (8); | |
8b93c638 JM |
4941 | ui_out_text (uiout, "\tignore next "); |
4942 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4943 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4944 | } |
059fb39f | 4945 | |
9add0f1b | 4946 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4947 | if (!part_of_multiple && l) |
c4093a6a | 4948 | { |
3b31d625 EZ |
4949 | struct cleanup *script_chain; |
4950 | ||
c4093a6a | 4951 | annotate_field (9); |
3b31d625 | 4952 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4953 | print_command_lines (uiout, l, 4); |
3b31d625 | 4954 | do_cleanups (script_chain); |
c4093a6a | 4955 | } |
d24317b4 | 4956 | |
1042e4c0 SS |
4957 | if (!part_of_multiple && b->pass_count) |
4958 | { | |
4959 | annotate_field (10); | |
4960 | ui_out_text (uiout, "\tpass count "); | |
4961 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4962 | ui_out_text (uiout, " \n"); | |
4963 | } | |
4964 | ||
d24317b4 VP |
4965 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4966 | { | |
4967 | if (b->addr_string) | |
4968 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4969 | else if (b->exp_string) | |
4970 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4971 | } | |
4972 | ||
3b31d625 | 4973 | do_cleanups (bkpt_chain); |
8b93c638 | 4974 | do_cleanups (old_chain); |
c4093a6a | 4975 | } |
c5aa993b | 4976 | |
0d381245 VP |
4977 | static void |
4978 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 MS |
4979 | struct bp_location **last_loc, |
4980 | int print_address_bits, | |
6c95b8df | 4981 | int allflag) |
0d381245 | 4982 | { |
6c95b8df PA |
4983 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4984 | print_address_bits, allflag); | |
0d381245 VP |
4985 | |
4986 | /* If this breakpoint has custom print function, | |
4987 | it's already printed. Otherwise, print individual | |
4988 | locations, if any. */ | |
4989 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4990 | { | |
4a64f543 MS |
4991 | /* If breakpoint has a single location that is disabled, we |
4992 | print it as if it had several locations, since otherwise it's | |
4993 | hard to represent "breakpoint enabled, location disabled" | |
4994 | situation. | |
4995 | ||
4996 | Note that while hardware watchpoints have several locations | |
a3be7890 | 4997 | internally, that's not a property exposed to user. */ |
0d381245 | 4998 | if (b->loc |
a5606eee | 4999 | && !is_hardware_watchpoint (b) |
0d381245 | 5000 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 5001 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
5002 | { |
5003 | struct bp_location *loc; | |
5004 | int n = 1; | |
5005 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 5006 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 5007 | print_address_bits, allflag); |
0d381245 VP |
5008 | } |
5009 | } | |
5010 | } | |
5011 | ||
a6d9a66e UW |
5012 | static int |
5013 | breakpoint_address_bits (struct breakpoint *b) | |
5014 | { | |
5015 | int print_address_bits = 0; | |
5016 | struct bp_location *loc; | |
5017 | ||
5018 | for (loc = b->loc; loc; loc = loc->next) | |
5019 | { | |
c7437ca6 PA |
5020 | int addr_bit; |
5021 | ||
5022 | /* Software watchpoints that aren't watching memory don't have | |
5023 | an address to print. */ | |
5024 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5025 | continue; | |
5026 | ||
5027 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5028 | if (addr_bit > print_address_bits) |
5029 | print_address_bits = addr_bit; | |
5030 | } | |
5031 | ||
5032 | return print_address_bits; | |
5033 | } | |
0d381245 | 5034 | |
c4093a6a JM |
5035 | struct captured_breakpoint_query_args |
5036 | { | |
5037 | int bnum; | |
5038 | }; | |
c5aa993b | 5039 | |
c4093a6a | 5040 | static int |
2b65245e | 5041 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5042 | { |
5043 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5044 | struct breakpoint *b; |
a6d9a66e | 5045 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5046 | |
c4093a6a JM |
5047 | ALL_BREAKPOINTS (b) |
5048 | { | |
5049 | if (args->bnum == b->number) | |
c5aa993b | 5050 | { |
a6d9a66e | 5051 | int print_address_bits = breakpoint_address_bits (b); |
cc59ec59 | 5052 | |
6c95b8df | 5053 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 5054 | return GDB_RC_OK; |
c5aa993b | 5055 | } |
c4093a6a JM |
5056 | } |
5057 | return GDB_RC_NONE; | |
5058 | } | |
c5aa993b | 5059 | |
c4093a6a | 5060 | enum gdb_rc |
4a64f543 MS |
5061 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5062 | char **error_message) | |
c4093a6a JM |
5063 | { |
5064 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5065 | |
c4093a6a JM |
5066 | args.bnum = bnum; |
5067 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5068 | an error. */ |
b0b13bb4 DJ |
5069 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5070 | error_message, RETURN_MASK_ALL) < 0) | |
5071 | return GDB_RC_FAIL; | |
5072 | else | |
5073 | return GDB_RC_OK; | |
c4093a6a | 5074 | } |
c5aa993b | 5075 | |
7f3b0473 | 5076 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4a64f543 | 5077 | catchpoints, et.al.). */ |
7f3b0473 AC |
5078 | |
5079 | static int | |
5080 | user_settable_breakpoint (const struct breakpoint *b) | |
5081 | { | |
5082 | return (b->type == bp_breakpoint | |
ce78b96d | 5083 | || b->type == bp_catchpoint |
7f3b0473 | 5084 | || b->type == bp_hardware_breakpoint |
d77f58be | 5085 | || is_tracepoint (b) |
cc60f2e3 | 5086 | || is_watchpoint (b)); |
7f3b0473 | 5087 | } |
4a64f543 | 5088 | |
09d682a4 TT |
5089 | /* Return true if this breakpoint was set by the user, false if it is |
5090 | internal or momentary. */ | |
5091 | ||
5092 | int | |
5093 | user_breakpoint_p (struct breakpoint *b) | |
5094 | { | |
5095 | return user_settable_breakpoint (b) && b->number > 0; | |
5096 | } | |
5097 | ||
7f3b0473 | 5098 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5099 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5100 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5101 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5102 | ones for which it returns non-zero. Return the total number of | |
5103 | breakpoints listed. */ | |
c906108c | 5104 | |
d77f58be | 5105 | static int |
e5a67952 | 5106 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5107 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5108 | { |
52f0bd74 | 5109 | struct breakpoint *b; |
a6d9a66e | 5110 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5111 | int nr_printable_breakpoints; |
3b31d625 | 5112 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5113 | struct value_print_options opts; |
a6d9a66e | 5114 | int print_address_bits = 0; |
269b11a2 PA |
5115 | int print_type_col_width = 14; |
5116 | ||
79a45b7d TT |
5117 | get_user_print_options (&opts); |
5118 | ||
4a64f543 MS |
5119 | /* Compute the number of rows in the table, as well as the size |
5120 | required for address fields. */ | |
7f3b0473 AC |
5121 | nr_printable_breakpoints = 0; |
5122 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5123 | { |
5124 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5125 | if (filter && !filter (b)) | |
5126 | continue; | |
5127 | ||
5128 | /* If we have an "args" string, it is a list of breakpoints to | |
5129 | accept. Skip the others. */ | |
5130 | if (args != NULL && *args != '\0') | |
5131 | { | |
5132 | if (allflag && parse_and_eval_long (args) != b->number) | |
5133 | continue; | |
5134 | if (!allflag && !number_is_in_list (args, b->number)) | |
5135 | continue; | |
5136 | } | |
269b11a2 | 5137 | |
e5a67952 MS |
5138 | if (allflag || user_breakpoint_p (b)) |
5139 | { | |
5140 | int addr_bit, type_len; | |
a6d9a66e | 5141 | |
e5a67952 MS |
5142 | addr_bit = breakpoint_address_bits (b); |
5143 | if (addr_bit > print_address_bits) | |
5144 | print_address_bits = addr_bit; | |
269b11a2 | 5145 | |
e5a67952 MS |
5146 | type_len = strlen (bptype_string (b->type)); |
5147 | if (type_len > print_type_col_width) | |
5148 | print_type_col_width = type_len; | |
5149 | ||
5150 | nr_printable_breakpoints++; | |
5151 | } | |
5152 | } | |
7f3b0473 | 5153 | |
79a45b7d | 5154 | if (opts.addressprint) |
3b31d625 | 5155 | bkpttbl_chain |
3e43a32a MS |
5156 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5157 | nr_printable_breakpoints, | |
3b31d625 | 5158 | "BreakpointTable"); |
8b93c638 | 5159 | else |
3b31d625 | 5160 | bkpttbl_chain |
3e43a32a MS |
5161 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5162 | nr_printable_breakpoints, | |
3b31d625 | 5163 | "BreakpointTable"); |
8b93c638 | 5164 | |
7f3b0473 | 5165 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5166 | annotate_breakpoints_headers (); |
5167 | if (nr_printable_breakpoints > 0) | |
5168 | annotate_field (0); | |
4a64f543 | 5169 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5170 | if (nr_printable_breakpoints > 0) |
5171 | annotate_field (1); | |
269b11a2 | 5172 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5173 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5174 | if (nr_printable_breakpoints > 0) |
5175 | annotate_field (2); | |
4a64f543 | 5176 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5177 | if (nr_printable_breakpoints > 0) |
5178 | annotate_field (3); | |
54e52265 | 5179 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5180 | if (opts.addressprint) |
e5a67952 MS |
5181 | { |
5182 | if (nr_printable_breakpoints > 0) | |
5183 | annotate_field (4); | |
5184 | if (print_address_bits <= 32) | |
5185 | ui_out_table_header (uiout, 10, ui_left, | |
5186 | "addr", "Address"); /* 5 */ | |
5187 | else | |
5188 | ui_out_table_header (uiout, 18, ui_left, | |
5189 | "addr", "Address"); /* 5 */ | |
5190 | } | |
d7faa9e7 AC |
5191 | if (nr_printable_breakpoints > 0) |
5192 | annotate_field (5); | |
5193 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5194 | ui_out_table_body (uiout); | |
5195 | if (nr_printable_breakpoints > 0) | |
5196 | annotate_breakpoints_table (); | |
7f3b0473 | 5197 | |
c4093a6a | 5198 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5199 | { |
5200 | QUIT; | |
5201 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5202 | if (filter && !filter (b)) | |
5203 | continue; | |
5204 | ||
5205 | /* If we have an "args" string, it is a list of breakpoints to | |
5206 | accept. Skip the others. */ | |
5207 | ||
5208 | if (args != NULL && *args != '\0') | |
5209 | { | |
5210 | if (allflag) /* maintenance info breakpoint */ | |
5211 | { | |
5212 | if (parse_and_eval_long (args) != b->number) | |
5213 | continue; | |
5214 | } | |
5215 | else /* all others */ | |
5216 | { | |
5217 | if (!number_is_in_list (args, b->number)) | |
5218 | continue; | |
5219 | } | |
5220 | } | |
5221 | /* We only print out user settable breakpoints unless the | |
5222 | allflag is set. */ | |
5223 | if (allflag || user_breakpoint_p (b)) | |
5224 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); | |
5225 | } | |
5226 | ||
3b31d625 | 5227 | do_cleanups (bkpttbl_chain); |
698384cd | 5228 | |
7f3b0473 | 5229 | if (nr_printable_breakpoints == 0) |
c906108c | 5230 | { |
4a64f543 MS |
5231 | /* If there's a filter, let the caller decide how to report |
5232 | empty list. */ | |
d77f58be SS |
5233 | if (!filter) |
5234 | { | |
e5a67952 | 5235 | if (args == NULL || *args == '\0') |
d77f58be SS |
5236 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5237 | else | |
4a64f543 | 5238 | ui_out_message (uiout, 0, |
e5a67952 MS |
5239 | "No breakpoint or watchpoint matching '%s'.\n", |
5240 | args); | |
d77f58be | 5241 | } |
c906108c SS |
5242 | } |
5243 | else | |
c4093a6a | 5244 | { |
a6d9a66e UW |
5245 | if (last_loc && !server_command) |
5246 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5247 | } |
c906108c | 5248 | |
4a64f543 | 5249 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5250 | there have been breakpoints? */ |
c906108c | 5251 | annotate_breakpoints_table_end (); |
d77f58be SS |
5252 | |
5253 | return nr_printable_breakpoints; | |
c906108c SS |
5254 | } |
5255 | ||
ad443146 SS |
5256 | /* Display the value of default-collect in a way that is generally |
5257 | compatible with the breakpoint list. */ | |
5258 | ||
5259 | static void | |
5260 | default_collect_info (void) | |
5261 | { | |
5262 | /* If it has no value (which is frequently the case), say nothing; a | |
5263 | message like "No default-collect." gets in user's face when it's | |
5264 | not wanted. */ | |
5265 | if (!*default_collect) | |
5266 | return; | |
5267 | ||
5268 | /* The following phrase lines up nicely with per-tracepoint collect | |
5269 | actions. */ | |
5270 | ui_out_text (uiout, "default collect "); | |
5271 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5272 | ui_out_text (uiout, " \n"); | |
5273 | } | |
5274 | ||
c906108c | 5275 | static void |
e5a67952 | 5276 | breakpoints_info (char *args, int from_tty) |
c906108c | 5277 | { |
e5a67952 | 5278 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5279 | |
5280 | default_collect_info (); | |
d77f58be SS |
5281 | } |
5282 | ||
5283 | static void | |
e5a67952 | 5284 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5285 | { |
e5a67952 | 5286 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
d77f58be SS |
5287 | |
5288 | if (num_printed == 0) | |
5289 | { | |
e5a67952 | 5290 | if (args == NULL || *args == '\0') |
d77f58be SS |
5291 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5292 | else | |
e5a67952 | 5293 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5294 | } |
c906108c SS |
5295 | } |
5296 | ||
7a292a7a | 5297 | static void |
e5a67952 | 5298 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5299 | { |
e5a67952 | 5300 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5301 | |
5302 | default_collect_info (); | |
c906108c SS |
5303 | } |
5304 | ||
0d381245 | 5305 | static int |
714835d5 | 5306 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5307 | struct program_space *pspace, |
714835d5 | 5308 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5309 | { |
5310 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5311 | |
0d381245 VP |
5312 | for (; bl; bl = bl->next) |
5313 | { | |
6c95b8df PA |
5314 | if (bl->pspace == pspace |
5315 | && bl->address == pc | |
0d381245 VP |
5316 | && (!overlay_debugging || bl->section == section)) |
5317 | return 1; | |
5318 | } | |
5319 | return 0; | |
5320 | } | |
5321 | ||
6c95b8df PA |
5322 | /* Print a message describing any breakpoints set at PC. This |
5323 | concerns with logical breakpoints, so we match program spaces, not | |
5324 | address spaces. */ | |
c906108c SS |
5325 | |
5326 | static void | |
6c95b8df PA |
5327 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5328 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5329 | struct obj_section *section, int thread) |
c906108c | 5330 | { |
52f0bd74 AC |
5331 | int others = 0; |
5332 | struct breakpoint *b; | |
c906108c SS |
5333 | |
5334 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5335 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5336 | if (others > 0) |
5337 | { | |
a3f17187 AC |
5338 | if (others == 1) |
5339 | printf_filtered (_("Note: breakpoint ")); | |
5340 | else /* if (others == ???) */ | |
5341 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5342 | ALL_BREAKPOINTS (b) |
6c95b8df | 5343 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5344 | { |
5345 | others--; | |
5346 | printf_filtered ("%d", b->number); | |
5347 | if (b->thread == -1 && thread != -1) | |
5348 | printf_filtered (" (all threads)"); | |
5349 | else if (b->thread != -1) | |
5350 | printf_filtered (" (thread %d)", b->thread); | |
5351 | printf_filtered ("%s%s ", | |
059fb39f | 5352 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5353 | || b->enable_state == bp_call_disabled |
5354 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5355 | ? " (disabled)" |
5356 | : b->enable_state == bp_permanent | |
5357 | ? " (permanent)" | |
5358 | : ""), | |
5359 | (others > 1) ? "," | |
5360 | : ((others == 1) ? " and" : "")); | |
5361 | } | |
a3f17187 | 5362 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5363 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5364 | printf_filtered (".\n"); |
5365 | } | |
5366 | } | |
5367 | \f | |
5368 | /* Set the default place to put a breakpoint | |
5369 | for the `break' command with no arguments. */ | |
5370 | ||
5371 | void | |
6c95b8df PA |
5372 | set_default_breakpoint (int valid, struct program_space *pspace, |
5373 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5374 | int line) |
c906108c SS |
5375 | { |
5376 | default_breakpoint_valid = valid; | |
6c95b8df | 5377 | default_breakpoint_pspace = pspace; |
c906108c SS |
5378 | default_breakpoint_address = addr; |
5379 | default_breakpoint_symtab = symtab; | |
5380 | default_breakpoint_line = line; | |
5381 | } | |
5382 | ||
e4f237da KB |
5383 | /* Return true iff it is meaningful to use the address member of |
5384 | BPT. For some breakpoint types, the address member is irrelevant | |
5385 | and it makes no sense to attempt to compare it to other addresses | |
5386 | (or use it for any other purpose either). | |
5387 | ||
4a64f543 MS |
5388 | More specifically, each of the following breakpoint types will |
5389 | always have a zero valued address and we don't want to mark | |
5390 | breakpoints of any of these types to be a duplicate of an actual | |
5391 | breakpoint at address zero: | |
e4f237da KB |
5392 | |
5393 | bp_watchpoint | |
2d134ed3 PA |
5394 | bp_catchpoint |
5395 | ||
5396 | */ | |
e4f237da KB |
5397 | |
5398 | static int | |
5399 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5400 | { | |
5401 | enum bptype type = bpt->type; | |
5402 | ||
2d134ed3 PA |
5403 | return (type != bp_watchpoint && type != bp_catchpoint); |
5404 | } | |
5405 | ||
5406 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5407 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5408 | ||
5409 | static int | |
4a64f543 MS |
5410 | watchpoint_locations_match (struct bp_location *loc1, |
5411 | struct bp_location *loc2) | |
2d134ed3 | 5412 | { |
2bdf28a0 JK |
5413 | /* Both of them must not be in moribund_locations. */ |
5414 | gdb_assert (loc1->owner != NULL); | |
5415 | gdb_assert (loc2->owner != NULL); | |
5416 | ||
4a64f543 MS |
5417 | /* If the target can evaluate the condition expression in hardware, |
5418 | then we we need to insert both watchpoints even if they are at | |
5419 | the same place. Otherwise the watchpoint will only trigger when | |
5420 | the condition of whichever watchpoint was inserted evaluates to | |
5421 | true, not giving a chance for GDB to check the condition of the | |
5422 | other watchpoint. */ | |
0cf6dd15 | 5423 | if ((loc1->owner->cond_exp |
4a64f543 MS |
5424 | && target_can_accel_watchpoint_condition (loc1->address, |
5425 | loc1->length, | |
0cf6dd15 TJB |
5426 | loc1->watchpoint_type, |
5427 | loc1->owner->cond_exp)) | |
5428 | || (loc2->owner->cond_exp | |
4a64f543 MS |
5429 | && target_can_accel_watchpoint_condition (loc2->address, |
5430 | loc2->length, | |
0cf6dd15 TJB |
5431 | loc2->watchpoint_type, |
5432 | loc2->owner->cond_exp))) | |
5433 | return 0; | |
5434 | ||
85d721b8 PA |
5435 | /* Note that this checks the owner's type, not the location's. In |
5436 | case the target does not support read watchpoints, but does | |
5437 | support access watchpoints, we'll have bp_read_watchpoint | |
5438 | watchpoints with hw_access locations. Those should be considered | |
5439 | duplicates of hw_read locations. The hw_read locations will | |
5440 | become hw_access locations later. */ | |
2d134ed3 PA |
5441 | return (loc1->owner->type == loc2->owner->type |
5442 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5443 | && loc1->address == loc2->address | |
5444 | && loc1->length == loc2->length); | |
e4f237da KB |
5445 | } |
5446 | ||
6c95b8df PA |
5447 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5448 | same breakpoint location. In most targets, this can only be true | |
5449 | if ASPACE1 matches ASPACE2. On targets that have global | |
5450 | breakpoints, the address space doesn't really matter. */ | |
5451 | ||
5452 | static int | |
5453 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5454 | struct address_space *aspace2, CORE_ADDR addr2) | |
5455 | { | |
5456 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5457 | || aspace1 == aspace2) | |
5458 | && addr1 == addr2); | |
5459 | } | |
5460 | ||
2d134ed3 PA |
5461 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5462 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5463 | represent the same location. */ | |
5464 | ||
5465 | static int | |
4a64f543 MS |
5466 | breakpoint_locations_match (struct bp_location *loc1, |
5467 | struct bp_location *loc2) | |
2d134ed3 | 5468 | { |
2bdf28a0 JK |
5469 | int hw_point1, hw_point2; |
5470 | ||
5471 | /* Both of them must not be in moribund_locations. */ | |
5472 | gdb_assert (loc1->owner != NULL); | |
5473 | gdb_assert (loc2->owner != NULL); | |
5474 | ||
5475 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5476 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5477 | |
5478 | if (hw_point1 != hw_point2) | |
5479 | return 0; | |
5480 | else if (hw_point1) | |
5481 | return watchpoint_locations_match (loc1, loc2); | |
5482 | else | |
5483 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5484 | loc2->pspace->aspace, loc2->address); | |
5485 | } | |
5486 | ||
76897487 KB |
5487 | static void |
5488 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5489 | int bnum, int have_bnum) | |
5490 | { | |
5491 | char astr1[40]; | |
5492 | char astr2[40]; | |
5493 | ||
bb599908 PH |
5494 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5495 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5496 | if (have_bnum) |
8a3fe4f8 | 5497 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5498 | bnum, astr1, astr2); |
5499 | else | |
8a3fe4f8 | 5500 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5501 | } |
5502 | ||
4a64f543 MS |
5503 | /* Adjust a breakpoint's address to account for architectural |
5504 | constraints on breakpoint placement. Return the adjusted address. | |
5505 | Note: Very few targets require this kind of adjustment. For most | |
5506 | targets, this function is simply the identity function. */ | |
76897487 KB |
5507 | |
5508 | static CORE_ADDR | |
a6d9a66e UW |
5509 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5510 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5511 | { |
a6d9a66e | 5512 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5513 | { |
5514 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5515 | return bpaddr; | |
5516 | } | |
88f7da05 KB |
5517 | else if (bptype == bp_watchpoint |
5518 | || bptype == bp_hardware_watchpoint | |
5519 | || bptype == bp_read_watchpoint | |
5520 | || bptype == bp_access_watchpoint | |
fe798b75 | 5521 | || bptype == bp_catchpoint) |
88f7da05 KB |
5522 | { |
5523 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5524 | have their addresses modified. */ | |
5525 | return bpaddr; | |
5526 | } | |
76897487 KB |
5527 | else |
5528 | { | |
5529 | CORE_ADDR adjusted_bpaddr; | |
5530 | ||
5531 | /* Some targets have architectural constraints on the placement | |
5532 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5533 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5534 | |
5535 | /* An adjusted breakpoint address can significantly alter | |
5536 | a user's expectations. Print a warning if an adjustment | |
5537 | is required. */ | |
5538 | if (adjusted_bpaddr != bpaddr) | |
5539 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5540 | ||
5541 | return adjusted_bpaddr; | |
5542 | } | |
5543 | } | |
5544 | ||
7cc221ef DJ |
5545 | /* Allocate a struct bp_location. */ |
5546 | ||
26bb91f3 | 5547 | static struct bp_location * |
39d61571 | 5548 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5549 | { |
afe38095 | 5550 | struct bp_location *loc; |
7cc221ef DJ |
5551 | |
5552 | loc = xmalloc (sizeof (struct bp_location)); | |
5553 | memset (loc, 0, sizeof (*loc)); | |
5554 | ||
e049a4b5 | 5555 | loc->owner = bpt; |
511a6cd4 | 5556 | loc->cond = NULL; |
0d381245 VP |
5557 | loc->shlib_disabled = 0; |
5558 | loc->enabled = 1; | |
e049a4b5 | 5559 | |
39d61571 | 5560 | switch (bpt->type) |
e049a4b5 DJ |
5561 | { |
5562 | case bp_breakpoint: | |
5563 | case bp_until: | |
5564 | case bp_finish: | |
5565 | case bp_longjmp: | |
5566 | case bp_longjmp_resume: | |
186c406b TT |
5567 | case bp_exception: |
5568 | case bp_exception_resume: | |
e049a4b5 | 5569 | case bp_step_resume: |
e049a4b5 DJ |
5570 | case bp_watchpoint_scope: |
5571 | case bp_call_dummy: | |
aa7d318d | 5572 | case bp_std_terminate: |
e049a4b5 DJ |
5573 | case bp_shlib_event: |
5574 | case bp_thread_event: | |
5575 | case bp_overlay_event: | |
4efc6507 | 5576 | case bp_jit_event: |
0fd8e87f | 5577 | case bp_longjmp_master: |
aa7d318d | 5578 | case bp_std_terminate_master: |
186c406b | 5579 | case bp_exception_master: |
e049a4b5 DJ |
5580 | loc->loc_type = bp_loc_software_breakpoint; |
5581 | break; | |
5582 | case bp_hardware_breakpoint: | |
5583 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5584 | break; | |
5585 | case bp_hardware_watchpoint: | |
5586 | case bp_read_watchpoint: | |
5587 | case bp_access_watchpoint: | |
5588 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5589 | break; | |
5590 | case bp_watchpoint: | |
ce78b96d | 5591 | case bp_catchpoint: |
15c3d785 PA |
5592 | case bp_tracepoint: |
5593 | case bp_fast_tracepoint: | |
0fb4aa4b | 5594 | case bp_static_tracepoint: |
e049a4b5 DJ |
5595 | loc->loc_type = bp_loc_other; |
5596 | break; | |
5597 | default: | |
e2e0b3e5 | 5598 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5599 | } |
5600 | ||
f431efe5 | 5601 | loc->refc = 1; |
7cc221ef DJ |
5602 | return loc; |
5603 | } | |
5604 | ||
f431efe5 PA |
5605 | static void |
5606 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5607 | { |
5608 | if (loc->cond) | |
5609 | xfree (loc->cond); | |
74960c60 VP |
5610 | |
5611 | if (loc->function_name) | |
5612 | xfree (loc->function_name); | |
f431efe5 | 5613 | |
fe3f5fa8 VP |
5614 | xfree (loc); |
5615 | } | |
5616 | ||
f431efe5 PA |
5617 | /* Increment reference count. */ |
5618 | ||
5619 | static void | |
5620 | incref_bp_location (struct bp_location *bl) | |
5621 | { | |
5622 | ++bl->refc; | |
5623 | } | |
5624 | ||
5625 | /* Decrement reference count. If the reference count reaches 0, | |
5626 | destroy the bp_location. Sets *BLP to NULL. */ | |
5627 | ||
5628 | static void | |
5629 | decref_bp_location (struct bp_location **blp) | |
5630 | { | |
0807b50c PA |
5631 | gdb_assert ((*blp)->refc > 0); |
5632 | ||
f431efe5 PA |
5633 | if (--(*blp)->refc == 0) |
5634 | free_bp_location (*blp); | |
5635 | *blp = NULL; | |
5636 | } | |
5637 | ||
4a64f543 MS |
5638 | /* Helper to set_raw_breakpoint below. Creates a breakpoint that has |
5639 | type BPTYPE and has no locations as yet. */ | |
5640 | /* This function is used in gdbtk sources and thus can not be made | |
5641 | static. */ | |
c906108c | 5642 | |
c40e75cd | 5643 | static struct breakpoint * |
a6d9a66e UW |
5644 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5645 | enum bptype bptype) | |
c906108c | 5646 | { |
52f0bd74 | 5647 | struct breakpoint *b, *b1; |
c906108c SS |
5648 | |
5649 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5650 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5651 | |
4d28f7a8 | 5652 | b->type = bptype; |
a6d9a66e | 5653 | b->gdbarch = gdbarch; |
c906108c SS |
5654 | b->language = current_language->la_language; |
5655 | b->input_radix = input_radix; | |
5656 | b->thread = -1; | |
b5de0fa7 | 5657 | b->enable_state = bp_enabled; |
c906108c SS |
5658 | b->next = 0; |
5659 | b->silent = 0; | |
5660 | b->ignore_count = 0; | |
5661 | b->commands = NULL; | |
818dd999 | 5662 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5663 | b->forked_inferior_pid = null_ptid; |
c906108c | 5664 | b->exec_pathname = NULL; |
a96d9b2e | 5665 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5666 | b->ops = NULL; |
0d381245 | 5667 | b->condition_not_parsed = 0; |
84f4c1fe | 5668 | b->py_bp_object = NULL; |
c906108c | 5669 | |
4a64f543 MS |
5670 | /* Add this breakpoint to the end of the chain so that a list of |
5671 | breakpoints will come out in order of increasing numbers. */ | |
c906108c SS |
5672 | |
5673 | b1 = breakpoint_chain; | |
5674 | if (b1 == 0) | |
5675 | breakpoint_chain = b; | |
5676 | else | |
5677 | { | |
5678 | while (b1->next) | |
5679 | b1 = b1->next; | |
5680 | b1->next = b; | |
5681 | } | |
0d381245 VP |
5682 | return b; |
5683 | } | |
5684 | ||
5685 | /* Initialize loc->function_name. */ | |
5686 | static void | |
5687 | set_breakpoint_location_function (struct bp_location *loc) | |
5688 | { | |
2bdf28a0 JK |
5689 | gdb_assert (loc->owner != NULL); |
5690 | ||
0d381245 | 5691 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5692 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5693 | || is_tracepoint (loc->owner)) |
0d381245 VP |
5694 | { |
5695 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5696 | NULL, NULL); | |
5697 | if (loc->function_name) | |
5698 | loc->function_name = xstrdup (loc->function_name); | |
5699 | } | |
5700 | } | |
5701 | ||
a6d9a66e UW |
5702 | /* Attempt to determine architecture of location identified by SAL. */ |
5703 | static struct gdbarch * | |
5704 | get_sal_arch (struct symtab_and_line sal) | |
5705 | { | |
5706 | if (sal.section) | |
5707 | return get_objfile_arch (sal.section->objfile); | |
5708 | if (sal.symtab) | |
5709 | return get_objfile_arch (sal.symtab->objfile); | |
5710 | ||
5711 | return NULL; | |
5712 | } | |
5713 | ||
0d381245 VP |
5714 | /* set_raw_breakpoint is a low level routine for allocating and |
5715 | partially initializing a breakpoint of type BPTYPE. The newly | |
5716 | created breakpoint's address, section, source file name, and line | |
5717 | number are provided by SAL. The newly created and partially | |
5718 | initialized breakpoint is added to the breakpoint chain and | |
5719 | is also returned as the value of this function. | |
5720 | ||
5721 | It is expected that the caller will complete the initialization of | |
5722 | the newly created breakpoint struct as well as output any status | |
5723 | information regarding the creation of a new breakpoint. In | |
5724 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5725 | number! Care should be taken to not allow an error to occur | |
5726 | prior to completing the initialization of the breakpoint. If this | |
5727 | should happen, a bogus breakpoint will be left on the chain. */ | |
5728 | ||
63c252f8 | 5729 | struct breakpoint * |
a6d9a66e UW |
5730 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5731 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5732 | { |
4a64f543 MS |
5733 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, |
5734 | bptype); | |
0d381245 | 5735 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5736 | struct gdbarch *loc_gdbarch; |
5737 | ||
5738 | loc_gdbarch = get_sal_arch (sal); | |
5739 | if (!loc_gdbarch) | |
5740 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5741 | |
6c95b8df PA |
5742 | if (bptype != bp_catchpoint) |
5743 | gdb_assert (sal.pspace != NULL); | |
5744 | ||
0d381245 VP |
5745 | /* Adjust the breakpoint's address prior to allocating a location. |
5746 | Once we call allocate_bp_location(), that mostly uninitialized | |
5747 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5748 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5749 | not want its scan of the location chain to find a breakpoint and |
5750 | location that's only been partially initialized. */ | |
4a64f543 MS |
5751 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5752 | sal.pc, b->type); | |
0d381245 | 5753 | |
39d61571 | 5754 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5755 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5756 | b->loc->requested_address = sal.pc; |
5757 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5758 | b->loc->pspace = sal.pspace; |
5759 | ||
5760 | /* Store the program space that was used to set the breakpoint, for | |
5761 | breakpoint resetting. */ | |
5762 | b->pspace = sal.pspace; | |
0d381245 VP |
5763 | |
5764 | if (sal.symtab == NULL) | |
5765 | b->source_file = NULL; | |
5766 | else | |
1b36a34b | 5767 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5768 | b->loc->section = sal.section; |
5769 | b->line_number = sal.line; | |
5770 | ||
5771 | set_breakpoint_location_function (b->loc); | |
c906108c | 5772 | |
c906108c SS |
5773 | breakpoints_changed (); |
5774 | ||
5775 | return b; | |
5776 | } | |
5777 | ||
c2c6d25f JM |
5778 | |
5779 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5780 | instruction, hard-wired into the inferior's code. */ | |
5781 | void | |
5782 | make_breakpoint_permanent (struct breakpoint *b) | |
5783 | { | |
0d381245 | 5784 | struct bp_location *bl; |
cc59ec59 | 5785 | |
b5de0fa7 | 5786 | b->enable_state = bp_permanent; |
c2c6d25f | 5787 | |
4a64f543 MS |
5788 | /* By definition, permanent breakpoints are already present in the |
5789 | code. Mark all locations as inserted. For now, | |
5790 | make_breakpoint_permanent is called in just one place, so it's | |
5791 | hard to say if it's reasonable to have permanent breakpoint with | |
5792 | multiple locations or not, but it's easy to implmement. */ | |
0d381245 VP |
5793 | for (bl = b->loc; bl; bl = bl->next) |
5794 | bl->inserted = 1; | |
c2c6d25f JM |
5795 | } |
5796 | ||
53a5351d | 5797 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5798 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5799 | initiated the operation. */ | |
c906108c SS |
5800 | |
5801 | void | |
186c406b | 5802 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5803 | { |
35df4500 | 5804 | struct breakpoint *b, *b_tmp; |
186c406b | 5805 | int thread = tp->num; |
0fd8e87f UW |
5806 | |
5807 | /* To avoid having to rescan all objfile symbols at every step, | |
5808 | we maintain a list of continually-inserted but always disabled | |
5809 | longjmp "master" breakpoints. Here, we simply create momentary | |
5810 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5811 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5812 | if (b->pspace == current_program_space |
186c406b TT |
5813 | && (b->type == bp_longjmp_master |
5814 | || b->type == bp_exception_master)) | |
0fd8e87f UW |
5815 | { |
5816 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5817 | |
186c406b | 5818 | clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
0fd8e87f UW |
5819 | clone->thread = thread; |
5820 | } | |
186c406b TT |
5821 | |
5822 | tp->initiating_frame = frame; | |
c906108c SS |
5823 | } |
5824 | ||
611c83ae | 5825 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5826 | void |
611c83ae | 5827 | delete_longjmp_breakpoint (int thread) |
c906108c | 5828 | { |
35df4500 | 5829 | struct breakpoint *b, *b_tmp; |
c906108c | 5830 | |
35df4500 | 5831 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5832 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5833 | { |
5834 | if (b->thread == thread) | |
5835 | delete_breakpoint (b); | |
5836 | } | |
c906108c SS |
5837 | } |
5838 | ||
1900040c MS |
5839 | void |
5840 | enable_overlay_breakpoints (void) | |
5841 | { | |
52f0bd74 | 5842 | struct breakpoint *b; |
1900040c MS |
5843 | |
5844 | ALL_BREAKPOINTS (b) | |
5845 | if (b->type == bp_overlay_event) | |
5846 | { | |
5847 | b->enable_state = bp_enabled; | |
b60e7edf | 5848 | update_global_location_list (1); |
c02f5703 | 5849 | overlay_events_enabled = 1; |
1900040c MS |
5850 | } |
5851 | } | |
5852 | ||
5853 | void | |
5854 | disable_overlay_breakpoints (void) | |
5855 | { | |
52f0bd74 | 5856 | struct breakpoint *b; |
1900040c MS |
5857 | |
5858 | ALL_BREAKPOINTS (b) | |
5859 | if (b->type == bp_overlay_event) | |
5860 | { | |
5861 | b->enable_state = bp_disabled; | |
b60e7edf | 5862 | update_global_location_list (0); |
c02f5703 | 5863 | overlay_events_enabled = 0; |
1900040c MS |
5864 | } |
5865 | } | |
5866 | ||
aa7d318d TT |
5867 | /* Set an active std::terminate breakpoint for each std::terminate |
5868 | master breakpoint. */ | |
5869 | void | |
5870 | set_std_terminate_breakpoint (void) | |
5871 | { | |
35df4500 | 5872 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5873 | |
35df4500 | 5874 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5875 | if (b->pspace == current_program_space |
5876 | && b->type == bp_std_terminate_master) | |
5877 | { | |
5878 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5879 | clone->type = bp_std_terminate; | |
5880 | } | |
5881 | } | |
5882 | ||
5883 | /* Delete all the std::terminate breakpoints. */ | |
5884 | void | |
5885 | delete_std_terminate_breakpoint (void) | |
5886 | { | |
35df4500 | 5887 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5888 | |
35df4500 | 5889 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5890 | if (b->type == bp_std_terminate) |
5891 | delete_breakpoint (b); | |
5892 | } | |
5893 | ||
c4093a6a | 5894 | struct breakpoint * |
a6d9a66e | 5895 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5896 | { |
5897 | struct breakpoint *b; | |
c4093a6a | 5898 | |
a6d9a66e | 5899 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5900 | |
b5de0fa7 | 5901 | b->enable_state = bp_enabled; |
c4093a6a | 5902 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5903 | b->addr_string |
5904 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5905 | |
b60e7edf | 5906 | update_global_location_list_nothrow (1); |
74960c60 | 5907 | |
c4093a6a JM |
5908 | return b; |
5909 | } | |
5910 | ||
5911 | void | |
5912 | remove_thread_event_breakpoints (void) | |
5913 | { | |
35df4500 | 5914 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5915 | |
35df4500 | 5916 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5917 | if (b->type == bp_thread_event |
5918 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5919 | delete_breakpoint (b); |
5920 | } | |
5921 | ||
0101ce28 JJ |
5922 | struct captured_parse_breakpoint_args |
5923 | { | |
5924 | char **arg_p; | |
5925 | struct symtabs_and_lines *sals_p; | |
5926 | char ***addr_string_p; | |
5927 | int *not_found_ptr; | |
5928 | }; | |
5929 | ||
5930 | struct lang_and_radix | |
5931 | { | |
5932 | enum language lang; | |
5933 | int radix; | |
5934 | }; | |
5935 | ||
4efc6507 DE |
5936 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5937 | ||
5938 | struct breakpoint * | |
5939 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5940 | { | |
5941 | struct breakpoint *b; | |
5942 | ||
5943 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5944 | update_global_location_list_nothrow (1); | |
5945 | return b; | |
5946 | } | |
0101ce28 | 5947 | |
03673fc7 PP |
5948 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
5949 | ||
5950 | void | |
5951 | remove_jit_event_breakpoints (void) | |
5952 | { | |
5953 | struct breakpoint *b, *b_tmp; | |
5954 | ||
5955 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5956 | if (b->type == bp_jit_event | |
5957 | && b->loc->pspace == current_program_space) | |
5958 | delete_breakpoint (b); | |
5959 | } | |
5960 | ||
cae688ec JJ |
5961 | void |
5962 | remove_solib_event_breakpoints (void) | |
5963 | { | |
35df4500 | 5964 | struct breakpoint *b, *b_tmp; |
cae688ec | 5965 | |
35df4500 | 5966 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5967 | if (b->type == bp_shlib_event |
5968 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5969 | delete_breakpoint (b); |
5970 | } | |
5971 | ||
5972 | struct breakpoint * | |
a6d9a66e | 5973 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5974 | { |
5975 | struct breakpoint *b; | |
5976 | ||
a6d9a66e | 5977 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5978 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5979 | return b; |
5980 | } | |
5981 | ||
5982 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5983 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5984 | ||
5985 | void | |
cb851954 | 5986 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5987 | { |
876fa593 | 5988 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5989 | |
876fa593 | 5990 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5991 | { |
2bdf28a0 | 5992 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 5993 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 5994 | |
4a64f543 MS |
5995 | /* We apply the check to all breakpoints, including disabled for |
5996 | those with loc->duplicate set. This is so that when breakpoint | |
5997 | becomes enabled, or the duplicate is removed, gdb will try to | |
5998 | insert all breakpoints. If we don't set shlib_disabled here, | |
5999 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6000 | if (((b->type == bp_breakpoint) |
508ccb1f | 6001 | || (b->type == bp_jit_event) |
1042e4c0 | 6002 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6003 | || (is_tracepoint (b))) |
6c95b8df | 6004 | && loc->pspace == current_program_space |
0d381245 | 6005 | && !loc->shlib_disabled |
a77053c2 | 6006 | #ifdef PC_SOLIB |
0d381245 | 6007 | && PC_SOLIB (loc->address) |
a77053c2 | 6008 | #else |
6c95b8df | 6009 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6010 | #endif |
6011 | ) | |
0d381245 VP |
6012 | { |
6013 | loc->shlib_disabled = 1; | |
6014 | } | |
cae688ec JJ |
6015 | } |
6016 | } | |
6017 | ||
4a64f543 MS |
6018 | /* Disable any breakpoints that are in in an unloaded shared library. |
6019 | Only apply to enabled breakpoints, disabled ones can just stay | |
6020 | disabled. */ | |
84acb35a | 6021 | |
75149521 | 6022 | static void |
84acb35a JJ |
6023 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6024 | { | |
876fa593 | 6025 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6026 | int disabled_shlib_breaks = 0; |
6027 | ||
c86cf029 VP |
6028 | /* SunOS a.out shared libraries are always mapped, so do not |
6029 | disable breakpoints; they will only be reported as unloaded | |
6030 | through clear_solib when GDB discards its shared library | |
6031 | list. See clear_solib for more information. */ | |
6032 | if (exec_bfd != NULL | |
6033 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6034 | return; | |
6035 | ||
876fa593 | 6036 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6037 | { |
2bdf28a0 | 6038 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6039 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6040 | |
0d381245 VP |
6041 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6042 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6043 | && solib->pspace == loc->pspace |
e2dd7057 | 6044 | && !loc->shlib_disabled |
508ccb1f TT |
6045 | && (b->type == bp_breakpoint |
6046 | || b->type == bp_jit_event | |
6047 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6048 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6049 | { |
e2dd7057 PP |
6050 | loc->shlib_disabled = 1; |
6051 | /* At this point, we cannot rely on remove_breakpoint | |
6052 | succeeding so we must mark the breakpoint as not inserted | |
6053 | to prevent future errors occurring in remove_breakpoints. */ | |
6054 | loc->inserted = 0; | |
6055 | if (!disabled_shlib_breaks) | |
6056 | { | |
6057 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6058 | warning (_("Temporarily disabling breakpoints " |
6059 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6060 | solib->so_name); |
84acb35a | 6061 | } |
e2dd7057 | 6062 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6063 | } |
6064 | } | |
84acb35a JJ |
6065 | } |
6066 | ||
ce78b96d JB |
6067 | /* FORK & VFORK catchpoints. */ |
6068 | ||
4a64f543 MS |
6069 | /* Implement the "insert" breakpoint_ops method for fork |
6070 | catchpoints. */ | |
ce78b96d | 6071 | |
77b06cd7 TJB |
6072 | static int |
6073 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6074 | { |
77b06cd7 | 6075 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6076 | } |
6077 | ||
4a64f543 MS |
6078 | /* Implement the "remove" breakpoint_ops method for fork |
6079 | catchpoints. */ | |
ce78b96d JB |
6080 | |
6081 | static int | |
77b06cd7 | 6082 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6083 | { |
6084 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6085 | } | |
6086 | ||
6087 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6088 | catchpoints. */ | |
6089 | ||
6090 | static int | |
6091 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
6092 | { | |
6093 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
6094 | } | |
6095 | ||
4a64f543 MS |
6096 | /* Implement the "print_it" breakpoint_ops method for fork |
6097 | catchpoints. */ | |
ce78b96d JB |
6098 | |
6099 | static enum print_stop_action | |
6100 | print_it_catch_fork (struct breakpoint *b) | |
6101 | { | |
6102 | annotate_catchpoint (b->number); | |
6103 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
6104 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6105 | return PRINT_SRC_AND_LOC; | |
6106 | } | |
6107 | ||
4a64f543 MS |
6108 | /* Implement the "print_one" breakpoint_ops method for fork |
6109 | catchpoints. */ | |
ce78b96d JB |
6110 | |
6111 | static void | |
a6d9a66e | 6112 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6113 | { |
79a45b7d TT |
6114 | struct value_print_options opts; |
6115 | ||
6116 | get_user_print_options (&opts); | |
6117 | ||
4a64f543 MS |
6118 | /* Field 4, the address, is omitted (which makes the columns not |
6119 | line up too nicely with the headers, but the effect is relatively | |
6120 | readable). */ | |
79a45b7d | 6121 | if (opts.addressprint) |
ce78b96d JB |
6122 | ui_out_field_skip (uiout, "addr"); |
6123 | annotate_field (5); | |
6124 | ui_out_text (uiout, "fork"); | |
6125 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6126 | { | |
6127 | ui_out_text (uiout, ", process "); | |
6128 | ui_out_field_int (uiout, "what", | |
6129 | ptid_get_pid (b->forked_inferior_pid)); | |
6130 | ui_out_spaces (uiout, 1); | |
6131 | } | |
6132 | } | |
6133 | ||
6134 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6135 | catchpoints. */ | |
6136 | ||
6137 | static void | |
6138 | print_mention_catch_fork (struct breakpoint *b) | |
6139 | { | |
6140 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6141 | } | |
6142 | ||
6149aea9 PA |
6143 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6144 | catchpoints. */ | |
6145 | ||
6146 | static void | |
6147 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6148 | { | |
6149 | fprintf_unfiltered (fp, "catch fork"); | |
6150 | } | |
6151 | ||
ce78b96d JB |
6152 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6153 | ||
6154 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
6155 | { | |
6156 | insert_catch_fork, | |
6157 | remove_catch_fork, | |
6158 | breakpoint_hit_catch_fork, | |
e09342b5 | 6159 | NULL, /* resources_needed */ |
ce78b96d JB |
6160 | print_it_catch_fork, |
6161 | print_one_catch_fork, | |
6149aea9 PA |
6162 | print_mention_catch_fork, |
6163 | print_recreate_catch_fork | |
ce78b96d JB |
6164 | }; |
6165 | ||
4a64f543 MS |
6166 | /* Implement the "insert" breakpoint_ops method for vfork |
6167 | catchpoints. */ | |
ce78b96d | 6168 | |
77b06cd7 TJB |
6169 | static int |
6170 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6171 | { |
77b06cd7 | 6172 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6173 | } |
6174 | ||
4a64f543 MS |
6175 | /* Implement the "remove" breakpoint_ops method for vfork |
6176 | catchpoints. */ | |
ce78b96d JB |
6177 | |
6178 | static int | |
77b06cd7 | 6179 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6180 | { |
6181 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6182 | } | |
6183 | ||
6184 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6185 | catchpoints. */ | |
6186 | ||
6187 | static int | |
6188 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
6189 | { | |
6190 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
6191 | } | |
6192 | ||
4a64f543 MS |
6193 | /* Implement the "print_it" breakpoint_ops method for vfork |
6194 | catchpoints. */ | |
ce78b96d JB |
6195 | |
6196 | static enum print_stop_action | |
6197 | print_it_catch_vfork (struct breakpoint *b) | |
6198 | { | |
6199 | annotate_catchpoint (b->number); | |
6200 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
6201 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6202 | return PRINT_SRC_AND_LOC; | |
6203 | } | |
6204 | ||
4a64f543 MS |
6205 | /* Implement the "print_one" breakpoint_ops method for vfork |
6206 | catchpoints. */ | |
ce78b96d JB |
6207 | |
6208 | static void | |
a6d9a66e | 6209 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6210 | { |
79a45b7d TT |
6211 | struct value_print_options opts; |
6212 | ||
6213 | get_user_print_options (&opts); | |
4a64f543 MS |
6214 | /* Field 4, the address, is omitted (which makes the columns not |
6215 | line up too nicely with the headers, but the effect is relatively | |
6216 | readable). */ | |
79a45b7d | 6217 | if (opts.addressprint) |
ce78b96d JB |
6218 | ui_out_field_skip (uiout, "addr"); |
6219 | annotate_field (5); | |
6220 | ui_out_text (uiout, "vfork"); | |
6221 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6222 | { | |
6223 | ui_out_text (uiout, ", process "); | |
6224 | ui_out_field_int (uiout, "what", | |
6225 | ptid_get_pid (b->forked_inferior_pid)); | |
6226 | ui_out_spaces (uiout, 1); | |
6227 | } | |
6228 | } | |
6229 | ||
6230 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6231 | catchpoints. */ | |
6232 | ||
6233 | static void | |
6234 | print_mention_catch_vfork (struct breakpoint *b) | |
6235 | { | |
6236 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6237 | } | |
6238 | ||
6149aea9 PA |
6239 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6240 | catchpoints. */ | |
6241 | ||
6242 | static void | |
6243 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6244 | { | |
6245 | fprintf_unfiltered (fp, "catch vfork"); | |
6246 | } | |
6247 | ||
ce78b96d JB |
6248 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6249 | ||
6250 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6251 | { | |
6252 | insert_catch_vfork, | |
6253 | remove_catch_vfork, | |
6254 | breakpoint_hit_catch_vfork, | |
e09342b5 | 6255 | NULL, /* resources_needed */ |
ce78b96d JB |
6256 | print_it_catch_vfork, |
6257 | print_one_catch_vfork, | |
6149aea9 PA |
6258 | print_mention_catch_vfork, |
6259 | print_recreate_catch_vfork | |
ce78b96d JB |
6260 | }; |
6261 | ||
a96d9b2e SDJ |
6262 | /* Implement the "insert" breakpoint_ops method for syscall |
6263 | catchpoints. */ | |
6264 | ||
77b06cd7 TJB |
6265 | static int |
6266 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e SDJ |
6267 | { |
6268 | struct inferior *inf = current_inferior (); | |
6269 | ||
6270 | ++inf->total_syscalls_count; | |
77b06cd7 | 6271 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6272 | ++inf->any_syscall_count; |
6273 | else | |
6274 | { | |
6275 | int i, iter; | |
cc59ec59 | 6276 | |
a96d9b2e | 6277 | for (i = 0; |
77b06cd7 | 6278 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6279 | i++) |
6280 | { | |
6281 | int elem; | |
cc59ec59 | 6282 | |
a96d9b2e SDJ |
6283 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6284 | { | |
6285 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6286 | uintptr_t vec_addr_offset |
6287 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6288 | uintptr_t vec_addr; |
6289 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6290 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6291 | vec_addr_offset; | |
6292 | memset ((void *) vec_addr, 0, | |
6293 | (iter + 1 - old_size) * sizeof (int)); | |
6294 | } | |
6295 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6296 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6297 | } | |
6298 | } | |
6299 | ||
77b06cd7 TJB |
6300 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6301 | inf->total_syscalls_count != 0, | |
6302 | inf->any_syscall_count, | |
6303 | VEC_length (int, inf->syscalls_counts), | |
6304 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6305 | } |
6306 | ||
6307 | /* Implement the "remove" breakpoint_ops method for syscall | |
6308 | catchpoints. */ | |
6309 | ||
6310 | static int | |
77b06cd7 | 6311 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e SDJ |
6312 | { |
6313 | struct inferior *inf = current_inferior (); | |
6314 | ||
6315 | --inf->total_syscalls_count; | |
77b06cd7 | 6316 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6317 | --inf->any_syscall_count; |
6318 | else | |
6319 | { | |
6320 | int i, iter; | |
cc59ec59 | 6321 | |
a96d9b2e | 6322 | for (i = 0; |
77b06cd7 | 6323 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6324 | i++) |
6325 | { | |
6326 | int elem; | |
6327 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6328 | /* Shouldn't happen. */ | |
6329 | continue; | |
6330 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6331 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6332 | } | |
6333 | } | |
6334 | ||
6335 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6336 | inf->total_syscalls_count != 0, | |
6337 | inf->any_syscall_count, | |
6338 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6339 | VEC_address (int, |
6340 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6341 | } |
6342 | ||
6343 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6344 | catchpoints. */ | |
6345 | ||
6346 | static int | |
6347 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6348 | { | |
4a64f543 MS |
6349 | /* We must check if we are catching specific syscalls in this |
6350 | breakpoint. If we are, then we must guarantee that the called | |
6351 | syscall is the same syscall we are catching. */ | |
a96d9b2e SDJ |
6352 | int syscall_number = 0; |
6353 | ||
6354 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6355 | return 0; | |
6356 | ||
6357 | /* Now, checking if the syscall is the same. */ | |
6358 | if (b->syscalls_to_be_caught) | |
6359 | { | |
6360 | int i, iter; | |
cc59ec59 | 6361 | |
a96d9b2e SDJ |
6362 | for (i = 0; |
6363 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6364 | i++) | |
6365 | if (syscall_number == iter) | |
6366 | break; | |
6367 | /* Not the same. */ | |
6368 | if (!iter) | |
6369 | return 0; | |
6370 | } | |
6371 | ||
6372 | return 1; | |
6373 | } | |
6374 | ||
6375 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6376 | catchpoints. */ | |
6377 | ||
6378 | static enum print_stop_action | |
6379 | print_it_catch_syscall (struct breakpoint *b) | |
6380 | { | |
6381 | /* These are needed because we want to know in which state a | |
6382 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6383 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6384 | must print "called syscall" or "returned from syscall". */ | |
6385 | ptid_t ptid; | |
6386 | struct target_waitstatus last; | |
6387 | struct syscall s; | |
6388 | struct cleanup *old_chain; | |
6389 | char *syscall_id; | |
6390 | ||
6391 | get_last_target_status (&ptid, &last); | |
6392 | ||
6393 | get_syscall_by_number (last.value.syscall_number, &s); | |
6394 | ||
6395 | annotate_catchpoint (b->number); | |
6396 | ||
6397 | if (s.name == NULL) | |
6398 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6399 | else | |
6400 | syscall_id = xstrprintf ("'%s'", s.name); | |
6401 | ||
6402 | old_chain = make_cleanup (xfree, syscall_id); | |
6403 | ||
6404 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6405 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6406 | b->number, syscall_id); | |
6407 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6408 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6409 | b->number, syscall_id); | |
6410 | ||
6411 | do_cleanups (old_chain); | |
6412 | ||
6413 | return PRINT_SRC_AND_LOC; | |
6414 | } | |
6415 | ||
6416 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6417 | catchpoints. */ | |
6418 | ||
6419 | static void | |
6420 | print_one_catch_syscall (struct breakpoint *b, | |
6421 | struct bp_location **last_loc) | |
6422 | { | |
6423 | struct value_print_options opts; | |
6424 | ||
6425 | get_user_print_options (&opts); | |
4a64f543 MS |
6426 | /* Field 4, the address, is omitted (which makes the columns not |
6427 | line up too nicely with the headers, but the effect is relatively | |
6428 | readable). */ | |
a96d9b2e SDJ |
6429 | if (opts.addressprint) |
6430 | ui_out_field_skip (uiout, "addr"); | |
6431 | annotate_field (5); | |
6432 | ||
6433 | if (b->syscalls_to_be_caught | |
6434 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6435 | ui_out_text (uiout, "syscalls \""); | |
6436 | else | |
6437 | ui_out_text (uiout, "syscall \""); | |
6438 | ||
6439 | if (b->syscalls_to_be_caught) | |
6440 | { | |
6441 | int i, iter; | |
6442 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6443 | |
a96d9b2e SDJ |
6444 | for (i = 0; |
6445 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6446 | i++) | |
6447 | { | |
6448 | char *x = text; | |
6449 | struct syscall s; | |
6450 | get_syscall_by_number (iter, &s); | |
6451 | ||
6452 | if (s.name != NULL) | |
6453 | text = xstrprintf ("%s%s, ", text, s.name); | |
6454 | else | |
6455 | text = xstrprintf ("%s%d, ", text, iter); | |
6456 | ||
6457 | /* We have to xfree the last 'text' (now stored at 'x') | |
6458 | because xstrprintf dinamically allocates new space for it | |
6459 | on every call. */ | |
6460 | xfree (x); | |
6461 | } | |
6462 | /* Remove the last comma. */ | |
6463 | text[strlen (text) - 2] = '\0'; | |
6464 | ui_out_field_string (uiout, "what", text); | |
6465 | } | |
6466 | else | |
6467 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6468 | ui_out_text (uiout, "\" "); | |
6469 | } | |
6470 | ||
6471 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6472 | catchpoints. */ | |
6473 | ||
6474 | static void | |
6475 | print_mention_catch_syscall (struct breakpoint *b) | |
6476 | { | |
6477 | if (b->syscalls_to_be_caught) | |
6478 | { | |
6479 | int i, iter; | |
6480 | ||
6481 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6482 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6483 | else | |
6484 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6485 | ||
6486 | for (i = 0; | |
6487 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6488 | i++) | |
6489 | { | |
6490 | struct syscall s; | |
6491 | get_syscall_by_number (iter, &s); | |
6492 | ||
6493 | if (s.name) | |
6494 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6495 | else | |
6496 | printf_filtered (" %d", s.number); | |
6497 | } | |
6498 | printf_filtered (")"); | |
6499 | } | |
6500 | else | |
6501 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6502 | b->number); | |
6503 | } | |
6504 | ||
6149aea9 PA |
6505 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6506 | catchpoints. */ | |
6507 | ||
6508 | static void | |
6509 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6510 | { | |
6511 | fprintf_unfiltered (fp, "catch syscall"); | |
6512 | ||
6513 | if (b->syscalls_to_be_caught) | |
6514 | { | |
6515 | int i, iter; | |
6516 | ||
6517 | for (i = 0; | |
6518 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6519 | i++) | |
6520 | { | |
6521 | struct syscall s; | |
6522 | ||
6523 | get_syscall_by_number (iter, &s); | |
6524 | if (s.name) | |
6525 | fprintf_unfiltered (fp, " %s", s.name); | |
6526 | else | |
6527 | fprintf_unfiltered (fp, " %d", s.number); | |
6528 | } | |
6529 | } | |
6530 | } | |
6531 | ||
a96d9b2e SDJ |
6532 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6533 | ||
6534 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6535 | { | |
6536 | insert_catch_syscall, | |
6537 | remove_catch_syscall, | |
6538 | breakpoint_hit_catch_syscall, | |
e09342b5 | 6539 | NULL, /* resources_needed */ |
a96d9b2e SDJ |
6540 | print_it_catch_syscall, |
6541 | print_one_catch_syscall, | |
6149aea9 PA |
6542 | print_mention_catch_syscall, |
6543 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6544 | }; |
6545 | ||
6546 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6547 | ||
6548 | static int | |
6549 | syscall_catchpoint_p (struct breakpoint *b) | |
6550 | { | |
6551 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6552 | } | |
6553 | ||
6554 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6555 | but does NOT mention it nor update the global location list. | |
6556 | This is useful if you need to fill more fields in the | |
6557 | struct breakpoint before calling mention. | |
ce78b96d JB |
6558 | |
6559 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6560 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6561 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6562 | to the catchpoint. */ | |
6563 | ||
6564 | static struct breakpoint * | |
a96d9b2e SDJ |
6565 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6566 | char *cond_string, | |
6567 | struct breakpoint_ops *ops) | |
c906108c | 6568 | { |
c5aa993b JM |
6569 | struct symtab_and_line sal; |
6570 | struct breakpoint *b; | |
c5aa993b | 6571 | |
fe39c653 | 6572 | init_sal (&sal); |
6c95b8df | 6573 | sal.pspace = current_program_space; |
c5aa993b | 6574 | |
a6d9a66e | 6575 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6576 | set_breakpoint_count (breakpoint_count + 1); |
6577 | b->number = breakpoint_count; | |
ce78b96d | 6578 | |
1b36a34b | 6579 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6580 | b->thread = -1; |
c906108c | 6581 | b->addr_string = NULL; |
b5de0fa7 EZ |
6582 | b->enable_state = bp_enabled; |
6583 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6584 | b->ops = ops; |
c5aa993b | 6585 | |
a96d9b2e SDJ |
6586 | return b; |
6587 | } | |
6588 | ||
6589 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6590 | ||
6591 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6592 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6593 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6594 | to the catchpoint. */ | |
6595 | ||
6596 | static struct breakpoint * | |
6597 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6598 | char *cond_string, struct breakpoint_ops *ops) | |
6599 | { | |
6600 | struct breakpoint *b = | |
6601 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6602 | ||
c906108c | 6603 | mention (b); |
ce78b96d | 6604 | update_global_location_list (1); |
c906108c | 6605 | |
ce78b96d | 6606 | return b; |
c906108c | 6607 | } |
c5aa993b | 6608 | |
9b70b993 | 6609 | static void |
a6d9a66e UW |
6610 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6611 | int tempflag, char *cond_string, | |
ce78b96d | 6612 | struct breakpoint_ops *ops) |
c906108c | 6613 | { |
a6d9a66e UW |
6614 | struct breakpoint *b |
6615 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6616 | |
6617 | /* FIXME: We should put this information in a breakpoint private data | |
6618 | area. */ | |
6619 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6620 | } |
6621 | ||
fe798b75 JB |
6622 | /* Exec catchpoints. */ |
6623 | ||
77b06cd7 TJB |
6624 | static int |
6625 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6626 | { |
77b06cd7 | 6627 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6628 | } |
c906108c | 6629 | |
fe798b75 | 6630 | static int |
77b06cd7 | 6631 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6632 | { |
6633 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6634 | } | |
c906108c | 6635 | |
fe798b75 JB |
6636 | static int |
6637 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6638 | { | |
6639 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6640 | } | |
c906108c | 6641 | |
fe798b75 JB |
6642 | static enum print_stop_action |
6643 | print_it_catch_exec (struct breakpoint *b) | |
6644 | { | |
6645 | annotate_catchpoint (b->number); | |
6646 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6647 | b->exec_pathname); | |
6648 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6649 | } |
6650 | ||
fe798b75 | 6651 | static void |
a6d9a66e | 6652 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6653 | { |
6654 | struct value_print_options opts; | |
6655 | ||
6656 | get_user_print_options (&opts); | |
6657 | ||
6658 | /* Field 4, the address, is omitted (which makes the columns | |
6659 | not line up too nicely with the headers, but the effect | |
6660 | is relatively readable). */ | |
6661 | if (opts.addressprint) | |
6662 | ui_out_field_skip (uiout, "addr"); | |
6663 | annotate_field (5); | |
6664 | ui_out_text (uiout, "exec"); | |
6665 | if (b->exec_pathname != NULL) | |
6666 | { | |
6667 | ui_out_text (uiout, ", program \""); | |
6668 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6669 | ui_out_text (uiout, "\" "); | |
6670 | } | |
6671 | } | |
6672 | ||
6673 | static void | |
6674 | print_mention_catch_exec (struct breakpoint *b) | |
6675 | { | |
6676 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6677 | } | |
6678 | ||
6149aea9 PA |
6679 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6680 | catchpoints. */ | |
6681 | ||
6682 | static void | |
6683 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6684 | { | |
6685 | fprintf_unfiltered (fp, "catch exec"); | |
6686 | } | |
6687 | ||
fe798b75 JB |
6688 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6689 | { | |
6690 | insert_catch_exec, | |
6691 | remove_catch_exec, | |
6692 | breakpoint_hit_catch_exec, | |
e09342b5 | 6693 | NULL, /* resources_needed */ |
fe798b75 JB |
6694 | print_it_catch_exec, |
6695 | print_one_catch_exec, | |
6149aea9 PA |
6696 | print_mention_catch_exec, |
6697 | print_recreate_catch_exec | |
fe798b75 JB |
6698 | }; |
6699 | ||
a96d9b2e SDJ |
6700 | static void |
6701 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6702 | struct breakpoint_ops *ops) | |
6703 | { | |
6704 | struct gdbarch *gdbarch = get_current_arch (); | |
6705 | struct breakpoint *b = | |
6706 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6707 | ||
6708 | b->syscalls_to_be_caught = filter; | |
6709 | ||
6710 | /* Now, we have to mention the breakpoint and update the global | |
6711 | location list. */ | |
6712 | mention (b); | |
6713 | update_global_location_list (1); | |
6714 | } | |
6715 | ||
c906108c | 6716 | static int |
fba45db2 | 6717 | hw_breakpoint_used_count (void) |
c906108c | 6718 | { |
52f0bd74 | 6719 | struct breakpoint *b; |
c906108c SS |
6720 | int i = 0; |
6721 | ||
6722 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6723 | { |
d6b74ac4 | 6724 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6725 | i++; |
6726 | } | |
c906108c SS |
6727 | |
6728 | return i; | |
6729 | } | |
6730 | ||
6731 | static int | |
fba45db2 | 6732 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6733 | { |
c906108c | 6734 | int i = 0; |
e09342b5 TJB |
6735 | struct breakpoint *b; |
6736 | struct bp_location *bl; | |
c906108c SS |
6737 | |
6738 | *other_type_used = 0; | |
6739 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6740 | { |
6741 | if (!breakpoint_enabled (b)) | |
6742 | continue; | |
6743 | ||
c5aa993b | 6744 | if (b->type == type) |
e09342b5 TJB |
6745 | for (bl = b->loc; bl; bl = bl->next) |
6746 | { | |
6747 | /* Special types of hardware watchpoints may use more than | |
6748 | one register. */ | |
6749 | if (b->ops && b->ops->resources_needed) | |
6750 | i += b->ops->resources_needed (bl); | |
6751 | else | |
6752 | i++; | |
6753 | } | |
cc60f2e3 | 6754 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6755 | *other_type_used = 1; |
e09342b5 TJB |
6756 | } |
6757 | ||
c906108c SS |
6758 | return i; |
6759 | } | |
6760 | ||
c906108c | 6761 | void |
fba45db2 | 6762 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6763 | { |
c5aa993b | 6764 | struct breakpoint *b; |
c906108c SS |
6765 | |
6766 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6767 | { |
cc60f2e3 | 6768 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6769 | { |
b5de0fa7 | 6770 | b->enable_state = bp_call_disabled; |
b60e7edf | 6771 | update_global_location_list (0); |
c5aa993b JM |
6772 | } |
6773 | } | |
c906108c SS |
6774 | } |
6775 | ||
6776 | void | |
fba45db2 | 6777 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6778 | { |
c5aa993b | 6779 | struct breakpoint *b; |
c906108c SS |
6780 | |
6781 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6782 | { |
cc60f2e3 | 6783 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6784 | { |
b5de0fa7 | 6785 | b->enable_state = bp_enabled; |
b60e7edf | 6786 | update_global_location_list (1); |
c5aa993b JM |
6787 | } |
6788 | } | |
c906108c SS |
6789 | } |
6790 | ||
8bea4e01 UW |
6791 | void |
6792 | disable_breakpoints_before_startup (void) | |
6793 | { | |
6794 | struct breakpoint *b; | |
6795 | int found = 0; | |
6796 | ||
6797 | ALL_BREAKPOINTS (b) | |
6798 | { | |
6c95b8df PA |
6799 | if (b->pspace != current_program_space) |
6800 | continue; | |
6801 | ||
8bea4e01 UW |
6802 | if ((b->type == bp_breakpoint |
6803 | || b->type == bp_hardware_breakpoint) | |
6804 | && breakpoint_enabled (b)) | |
6805 | { | |
6806 | b->enable_state = bp_startup_disabled; | |
6807 | found = 1; | |
6808 | } | |
6809 | } | |
6810 | ||
6811 | if (found) | |
6812 | update_global_location_list (0); | |
6813 | ||
6c95b8df | 6814 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6815 | } |
6816 | ||
6817 | void | |
6818 | enable_breakpoints_after_startup (void) | |
6819 | { | |
6820 | struct breakpoint *b; | |
6821 | int found = 0; | |
6822 | ||
6c95b8df | 6823 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6824 | |
6825 | ALL_BREAKPOINTS (b) | |
6826 | { | |
6c95b8df PA |
6827 | if (b->pspace != current_program_space) |
6828 | continue; | |
6829 | ||
8bea4e01 UW |
6830 | if ((b->type == bp_breakpoint |
6831 | || b->type == bp_hardware_breakpoint) | |
6832 | && b->enable_state == bp_startup_disabled) | |
6833 | { | |
6834 | b->enable_state = bp_enabled; | |
6835 | found = 1; | |
6836 | } | |
6837 | } | |
6838 | ||
6839 | if (found) | |
6840 | breakpoint_re_set (); | |
6841 | } | |
6842 | ||
c906108c SS |
6843 | |
6844 | /* Set a breakpoint that will evaporate an end of command | |
6845 | at address specified by SAL. | |
6846 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6847 | ||
6848 | struct breakpoint * | |
a6d9a66e UW |
6849 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6850 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6851 | { |
52f0bd74 | 6852 | struct breakpoint *b; |
edb3359d DJ |
6853 | |
6854 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6855 | one. */ | |
6856 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6857 | ||
a6d9a66e | 6858 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6859 | b->enable_state = bp_enabled; |
6860 | b->disposition = disp_donttouch; | |
818dd999 | 6861 | b->frame_id = frame_id; |
c906108c | 6862 | |
4a64f543 MS |
6863 | /* If we're debugging a multi-threaded program, then we want |
6864 | momentary breakpoints to be active in only a single thread of | |
6865 | control. */ | |
39f77062 KB |
6866 | if (in_thread_list (inferior_ptid)) |
6867 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6868 | |
b60e7edf | 6869 | update_global_location_list_nothrow (1); |
74960c60 | 6870 | |
c906108c SS |
6871 | return b; |
6872 | } | |
611c83ae | 6873 | |
e58b0e63 PA |
6874 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6875 | ORIG is NULL. */ | |
6876 | ||
6877 | struct breakpoint * | |
6878 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6879 | { | |
6880 | struct breakpoint *copy; | |
6881 | ||
6882 | /* If there's nothing to clone, then return nothing. */ | |
6883 | if (orig == NULL) | |
6884 | return NULL; | |
6885 | ||
a6d9a66e | 6886 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6887 | copy->loc = allocate_bp_location (copy); |
6888 | set_breakpoint_location_function (copy->loc); | |
6889 | ||
a6d9a66e | 6890 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6891 | copy->loc->requested_address = orig->loc->requested_address; |
6892 | copy->loc->address = orig->loc->address; | |
6893 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6894 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6895 | |
6896 | if (orig->source_file == NULL) | |
6897 | copy->source_file = NULL; | |
6898 | else | |
6899 | copy->source_file = xstrdup (orig->source_file); | |
6900 | ||
6901 | copy->line_number = orig->line_number; | |
6902 | copy->frame_id = orig->frame_id; | |
6903 | copy->thread = orig->thread; | |
6c95b8df | 6904 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6905 | |
6906 | copy->enable_state = bp_enabled; | |
6907 | copy->disposition = disp_donttouch; | |
6908 | copy->number = internal_breakpoint_number--; | |
6909 | ||
6910 | update_global_location_list_nothrow (0); | |
6911 | return copy; | |
6912 | } | |
6913 | ||
611c83ae | 6914 | struct breakpoint * |
a6d9a66e UW |
6915 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6916 | enum bptype type) | |
611c83ae PA |
6917 | { |
6918 | struct symtab_and_line sal; | |
6919 | ||
6920 | sal = find_pc_line (pc, 0); | |
6921 | sal.pc = pc; | |
6922 | sal.section = find_pc_overlay (pc); | |
6923 | sal.explicit_pc = 1; | |
6924 | ||
a6d9a66e | 6925 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6926 | } |
c906108c | 6927 | \f |
c5aa993b | 6928 | |
c906108c SS |
6929 | /* Tell the user we have just set a breakpoint B. */ |
6930 | ||
6931 | static void | |
fba45db2 | 6932 | mention (struct breakpoint *b) |
c906108c SS |
6933 | { |
6934 | int say_where = 0; | |
fa8a61dc | 6935 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6936 | struct value_print_options opts; |
6937 | ||
6938 | get_user_print_options (&opts); | |
8b93c638 | 6939 | |
9a4105ab AC |
6940 | /* FIXME: This is misplaced; mention() is called by things (like |
6941 | hitting a watchpoint) other than breakpoint creation. It should | |
6942 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6943 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6944 | observer_notify_breakpoint_created (b->number); |
c906108c | 6945 | |
3086aeae DJ |
6946 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6947 | b->ops->print_mention (b); | |
6948 | else | |
6949 | switch (b->type) | |
6950 | { | |
6951 | case bp_none: | |
3e43a32a MS |
6952 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), |
6953 | b->number); | |
3086aeae DJ |
6954 | break; |
6955 | case bp_watchpoint: | |
6956 | ui_out_text (uiout, "Watchpoint "); | |
6957 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6958 | ui_out_field_int (uiout, "number", b->number); | |
6959 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6960 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6961 | do_cleanups (ui_out_chain); |
6962 | break; | |
6963 | case bp_hardware_watchpoint: | |
6964 | ui_out_text (uiout, "Hardware watchpoint "); | |
6965 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6966 | ui_out_field_int (uiout, "number", b->number); | |
6967 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6968 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6969 | do_cleanups (ui_out_chain); |
6970 | break; | |
6971 | case bp_read_watchpoint: | |
6972 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6973 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6974 | ui_out_field_int (uiout, "number", b->number); | |
6975 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6976 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6977 | do_cleanups (ui_out_chain); |
6978 | break; | |
6979 | case bp_access_watchpoint: | |
6980 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6981 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6982 | ui_out_field_int (uiout, "number", b->number); | |
6983 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6984 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6985 | do_cleanups (ui_out_chain); |
6986 | break; | |
6987 | case bp_breakpoint: | |
6988 | if (ui_out_is_mi_like_p (uiout)) | |
6989 | { | |
6990 | say_where = 0; | |
6991 | break; | |
6992 | } | |
2cec12e5 AR |
6993 | if (b->disposition == disp_del) |
6994 | printf_filtered (_("Temporary breakpoint")); | |
6995 | else | |
6996 | printf_filtered (_("Breakpoint")); | |
6997 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6998 | say_where = 1; |
6999 | break; | |
7000 | case bp_hardware_breakpoint: | |
7001 | if (ui_out_is_mi_like_p (uiout)) | |
7002 | { | |
7003 | say_where = 0; | |
7004 | break; | |
7005 | } | |
a3f17187 | 7006 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
7007 | say_where = 1; |
7008 | break; | |
1042e4c0 SS |
7009 | case bp_tracepoint: |
7010 | if (ui_out_is_mi_like_p (uiout)) | |
7011 | { | |
7012 | say_where = 0; | |
7013 | break; | |
7014 | } | |
7015 | printf_filtered (_("Tracepoint")); | |
7016 | printf_filtered (_(" %d"), b->number); | |
7017 | say_where = 1; | |
7018 | break; | |
7a697b8d SS |
7019 | case bp_fast_tracepoint: |
7020 | if (ui_out_is_mi_like_p (uiout)) | |
7021 | { | |
7022 | say_where = 0; | |
7023 | break; | |
7024 | } | |
7025 | printf_filtered (_("Fast tracepoint")); | |
7026 | printf_filtered (_(" %d"), b->number); | |
7027 | say_where = 1; | |
7028 | break; | |
0fb4aa4b PA |
7029 | case bp_static_tracepoint: |
7030 | if (ui_out_is_mi_like_p (uiout)) | |
7031 | { | |
7032 | say_where = 0; | |
7033 | break; | |
7034 | } | |
7035 | printf_filtered (_("Static tracepoint")); | |
7036 | printf_filtered (_(" %d"), b->number); | |
7037 | say_where = 1; | |
7038 | break; | |
3086aeae DJ |
7039 | |
7040 | case bp_until: | |
7041 | case bp_finish: | |
7042 | case bp_longjmp: | |
7043 | case bp_longjmp_resume: | |
186c406b TT |
7044 | case bp_exception: |
7045 | case bp_exception_resume: | |
3086aeae | 7046 | case bp_step_resume: |
3086aeae | 7047 | case bp_call_dummy: |
aa7d318d | 7048 | case bp_std_terminate: |
3086aeae DJ |
7049 | case bp_watchpoint_scope: |
7050 | case bp_shlib_event: | |
7051 | case bp_thread_event: | |
7052 | case bp_overlay_event: | |
4efc6507 | 7053 | case bp_jit_event: |
0fd8e87f | 7054 | case bp_longjmp_master: |
aa7d318d | 7055 | case bp_std_terminate_master: |
186c406b | 7056 | case bp_exception_master: |
3086aeae DJ |
7057 | break; |
7058 | } | |
c906108c | 7059 | |
c906108c SS |
7060 | if (say_where) |
7061 | { | |
a3f17187 AC |
7062 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
7063 | single string. */ | |
0d381245 | 7064 | if (b->loc == NULL) |
c906108c | 7065 | { |
a3f17187 | 7066 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
7067 | } |
7068 | else | |
7069 | { | |
79a45b7d | 7070 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
7071 | { |
7072 | printf_filtered (" at "); | |
5af949e3 UW |
7073 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
7074 | gdb_stdout); | |
0101ce28 JJ |
7075 | } |
7076 | if (b->source_file) | |
7077 | printf_filtered (": file %s, line %d.", | |
7078 | b->source_file, b->line_number); | |
0d381245 VP |
7079 | |
7080 | if (b->loc->next) | |
7081 | { | |
7082 | struct bp_location *loc = b->loc; | |
7083 | int n = 0; | |
7084 | for (; loc; loc = loc->next) | |
7085 | ++n; | |
7086 | printf_filtered (" (%d locations)", n); | |
7087 | } | |
7088 | ||
c906108c | 7089 | } |
c906108c | 7090 | } |
9dc5e2a9 | 7091 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7092 | return; |
c906108c SS |
7093 | printf_filtered ("\n"); |
7094 | } | |
c906108c | 7095 | \f |
c5aa993b | 7096 | |
0d381245 | 7097 | static struct bp_location * |
39d61571 | 7098 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7099 | const struct symtab_and_line *sal) |
7100 | { | |
7101 | struct bp_location *loc, **tmp; | |
7102 | ||
39d61571 | 7103 | loc = allocate_bp_location (b); |
0d381245 VP |
7104 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7105 | ; | |
7106 | *tmp = loc; | |
a6d9a66e UW |
7107 | loc->gdbarch = get_sal_arch (*sal); |
7108 | if (!loc->gdbarch) | |
7109 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7110 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7111 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7112 | loc->requested_address, b->type); | |
6c95b8df PA |
7113 | loc->pspace = sal->pspace; |
7114 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7115 | loc->section = sal->section; |
7116 | ||
7117 | set_breakpoint_location_function (loc); | |
7118 | return loc; | |
7119 | } | |
514f746b AR |
7120 | \f |
7121 | ||
7122 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7123 | return 0 otherwise. */ | |
7124 | ||
7125 | static int | |
7126 | bp_loc_is_permanent (struct bp_location *loc) | |
7127 | { | |
7128 | int len; | |
7129 | CORE_ADDR addr; | |
7130 | const gdb_byte *brk; | |
7131 | gdb_byte *target_mem; | |
939c61fa JK |
7132 | struct cleanup *cleanup; |
7133 | int retval = 0; | |
514f746b AR |
7134 | |
7135 | gdb_assert (loc != NULL); | |
7136 | ||
7137 | addr = loc->address; | |
a6d9a66e | 7138 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7139 | |
939c61fa JK |
7140 | /* Software breakpoints unsupported? */ |
7141 | if (brk == NULL) | |
7142 | return 0; | |
7143 | ||
514f746b AR |
7144 | target_mem = alloca (len); |
7145 | ||
939c61fa JK |
7146 | /* Enable the automatic memory restoration from breakpoints while |
7147 | we read the memory. Otherwise we could say about our temporary | |
7148 | breakpoints they are permanent. */ | |
6c95b8df PA |
7149 | cleanup = save_current_space_and_thread (); |
7150 | ||
7151 | switch_to_program_space_and_thread (loc->pspace); | |
7152 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7153 | |
514f746b AR |
7154 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7155 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7156 | retval = 1; |
514f746b | 7157 | |
939c61fa JK |
7158 | do_cleanups (cleanup); |
7159 | ||
7160 | return retval; | |
514f746b AR |
7161 | } |
7162 | ||
7163 | ||
c3f6f71d | 7164 | |
018d34a4 VP |
7165 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7166 | as textual description of the location, and COND_STRING | |
db107f19 | 7167 | as condition expression. */ |
018d34a4 VP |
7168 | |
7169 | static void | |
8cdf0e15 VP |
7170 | create_breakpoint_sal (struct gdbarch *gdbarch, |
7171 | struct symtabs_and_lines sals, char *addr_string, | |
7172 | char *cond_string, | |
7173 | enum bptype type, enum bpdisp disposition, | |
7174 | int thread, int task, int ignore_count, | |
84f4c1fe PM |
7175 | struct breakpoint_ops *ops, int from_tty, |
7176 | int enabled, int internal) | |
018d34a4 | 7177 | { |
0d381245 VP |
7178 | struct breakpoint *b = NULL; |
7179 | int i; | |
018d34a4 VP |
7180 | |
7181 | if (type == bp_hardware_breakpoint) | |
7182 | { | |
7183 | int i = hw_breakpoint_used_count (); | |
7184 | int target_resources_ok = | |
d92524f1 | 7185 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7186 | i + 1, 0); |
7187 | if (target_resources_ok == 0) | |
7188 | error (_("No hardware breakpoint support in the target.")); | |
7189 | else if (target_resources_ok < 0) | |
7190 | error (_("Hardware breakpoints used exceeds limit.")); | |
7191 | } | |
7192 | ||
6c95b8df PA |
7193 | gdb_assert (sals.nelts > 0); |
7194 | ||
0d381245 VP |
7195 | for (i = 0; i < sals.nelts; ++i) |
7196 | { | |
7197 | struct symtab_and_line sal = sals.sals[i]; | |
7198 | struct bp_location *loc; | |
7199 | ||
7200 | if (from_tty) | |
5af949e3 UW |
7201 | { |
7202 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7203 | if (!loc_gdbarch) | |
7204 | loc_gdbarch = gdbarch; | |
7205 | ||
7206 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7207 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7208 | } |
0d381245 VP |
7209 | |
7210 | if (i == 0) | |
7211 | { | |
a6d9a66e | 7212 | b = set_raw_breakpoint (gdbarch, sal, type); |
84f4c1fe | 7213 | set_breakpoint_number (internal, b); |
0d381245 | 7214 | b->thread = thread; |
4a306c9a | 7215 | b->task = task; |
018d34a4 | 7216 | |
0d381245 VP |
7217 | b->cond_string = cond_string; |
7218 | b->ignore_count = ignore_count; | |
41447f92 | 7219 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7220 | b->disposition = disposition; |
6c95b8df PA |
7221 | b->pspace = sals.sals[0].pspace; |
7222 | ||
0fb4aa4b PA |
7223 | if (type == bp_static_tracepoint) |
7224 | { | |
7225 | struct static_tracepoint_marker marker; | |
7226 | ||
7227 | if (is_marker_spec (addr_string)) | |
7228 | { | |
7229 | /* We already know the marker exists, otherwise, we | |
7230 | wouldn't see a sal for it. */ | |
7231 | char *p = &addr_string[3]; | |
7232 | char *endp; | |
7233 | char *marker_str; | |
7234 | int i; | |
7235 | ||
e9cafbcc | 7236 | p = skip_spaces (p); |
0fb4aa4b | 7237 | |
e9cafbcc | 7238 | endp = skip_to_space (p); |
0fb4aa4b PA |
7239 | |
7240 | marker_str = savestring (p, endp - p); | |
7241 | b->static_trace_marker_id = marker_str; | |
7242 | ||
3e43a32a MS |
7243 | printf_filtered (_("Probed static tracepoint " |
7244 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7245 | b->static_trace_marker_id); |
7246 | } | |
7247 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7248 | { | |
7249 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
7250 | release_static_tracepoint_marker (&marker); | |
7251 | ||
3e43a32a MS |
7252 | printf_filtered (_("Probed static tracepoint " |
7253 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7254 | b->static_trace_marker_id); |
7255 | } | |
7256 | else | |
3e43a32a MS |
7257 | warning (_("Couldn't determine the static " |
7258 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7259 | } |
7260 | ||
6c95b8df | 7261 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7262 | && (b->type == bp_breakpoint |
7263 | || b->type == bp_hardware_breakpoint)) | |
7264 | b->enable_state = bp_startup_disabled; | |
7265 | ||
0d381245 VP |
7266 | loc = b->loc; |
7267 | } | |
7268 | else | |
018d34a4 | 7269 | { |
39d61571 | 7270 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7271 | } |
7272 | ||
514f746b AR |
7273 | if (bp_loc_is_permanent (loc)) |
7274 | make_breakpoint_permanent (b); | |
7275 | ||
0d381245 VP |
7276 | if (b->cond_string) |
7277 | { | |
7278 | char *arg = b->cond_string; | |
d32a6982 | 7279 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7280 | if (*arg) |
db107f19 | 7281 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7282 | } |
0d381245 | 7283 | } |
018d34a4 VP |
7284 | |
7285 | if (addr_string) | |
7286 | b->addr_string = addr_string; | |
7287 | else | |
7288 | /* addr_string has to be used or breakpoint_re_set will delete | |
7289 | me. */ | |
5af949e3 UW |
7290 | b->addr_string |
7291 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7292 | |
604133b5 | 7293 | b->ops = ops; |
84f4c1fe PM |
7294 | if (internal) |
7295 | /* Do not mention breakpoints with a negative number, but do | |
7296 | notify observers. */ | |
7297 | observer_notify_breakpoint_created (b->number); | |
7298 | else | |
7299 | mention (b); | |
018d34a4 VP |
7300 | } |
7301 | ||
ed0616c6 VP |
7302 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7303 | elements to fill the void space. */ | |
2c0b251b PA |
7304 | static void |
7305 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7306 | { |
7307 | int i = index_to_remove+1; | |
7308 | int last_index = sal->nelts-1; | |
7309 | ||
7310 | for (;i <= last_index; ++i) | |
7311 | sal->sals[i-1] = sal->sals[i]; | |
7312 | ||
7313 | --(sal->nelts); | |
7314 | } | |
7315 | ||
6c95b8df PA |
7316 | /* If appropriate, obtains all sals that correspond to the same file |
7317 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7318 | will want to set a breakpoint at foo.c:line, and not really care | |
7319 | about program spaces. This is done only if SAL does not have | |
7320 | explicit PC and has line and file information. If we got just a | |
7321 | single expanded sal, return the original. | |
ed0616c6 | 7322 | |
6c95b8df PA |
7323 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7324 | which the name of enclosing function is different from SAL. This | |
7325 | makes sure that if we have breakpoint originally set in template | |
7326 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7327 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7328 | |
2c0b251b | 7329 | static struct symtabs_and_lines |
ed0616c6 VP |
7330 | expand_line_sal_maybe (struct symtab_and_line sal) |
7331 | { | |
7332 | struct symtabs_and_lines expanded; | |
7333 | CORE_ADDR original_pc = sal.pc; | |
7334 | char *original_function = NULL; | |
7335 | int found; | |
7336 | int i; | |
6c95b8df | 7337 | struct cleanup *old_chain; |
ed0616c6 VP |
7338 | |
7339 | /* If we have explicit pc, don't expand. | |
7340 | If we have no line number, we can't expand. */ | |
7341 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7342 | { | |
7343 | expanded.nelts = 1; | |
7344 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7345 | expanded.sals[0] = sal; | |
7346 | return expanded; | |
7347 | } | |
7348 | ||
7349 | sal.pc = 0; | |
6c95b8df PA |
7350 | |
7351 | old_chain = save_current_space_and_thread (); | |
7352 | ||
7353 | switch_to_program_space_and_thread (sal.pspace); | |
7354 | ||
ed0616c6 | 7355 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7356 | |
7357 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7358 | expanded = expand_line_sal (sal); |
6c95b8df | 7359 | |
ed0616c6 VP |
7360 | if (expanded.nelts == 1) |
7361 | { | |
3dba1c98 JB |
7362 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7363 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7364 | xfree (expanded.sals); |
7365 | expanded.nelts = 1; | |
7366 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7367 | sal.pc = original_pc; | |
7368 | expanded.sals[0] = sal; | |
3dba1c98 | 7369 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7370 | do_cleanups (old_chain); |
ed0616c6 VP |
7371 | return expanded; |
7372 | } | |
7373 | ||
7374 | if (!sal.explicit_line) | |
7375 | { | |
7376 | CORE_ADDR func_addr, func_end; | |
7377 | for (i = 0; i < expanded.nelts; ++i) | |
7378 | { | |
7379 | CORE_ADDR pc = expanded.sals[i].pc; | |
7380 | char *this_function; | |
6c95b8df PA |
7381 | |
7382 | /* We need to switch threads as well since we're about to | |
7383 | read memory. */ | |
7384 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7385 | ||
ed0616c6 VP |
7386 | if (find_pc_partial_function (pc, &this_function, |
7387 | &func_addr, &func_end)) | |
7388 | { | |
059fb39f PM |
7389 | if (this_function |
7390 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7391 | { |
7392 | remove_sal (&expanded, i); | |
7393 | --i; | |
7394 | } | |
ed0616c6 VP |
7395 | } |
7396 | } | |
7397 | } | |
059acae7 UW |
7398 | |
7399 | /* Skip the function prologue if necessary. */ | |
7400 | for (i = 0; i < expanded.nelts; ++i) | |
7401 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7402 | |
6c95b8df PA |
7403 | do_cleanups (old_chain); |
7404 | ||
ed0616c6 VP |
7405 | if (expanded.nelts <= 1) |
7406 | { | |
4a64f543 MS |
7407 | /* This is un ugly workaround. If we get zero expanded sals |
7408 | then something is really wrong. Fix that by returning the | |
7409 | original sal. */ | |
7410 | ||
ed0616c6 VP |
7411 | xfree (expanded.sals); |
7412 | expanded.nelts = 1; | |
7413 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7414 | sal.pc = original_pc; | |
7415 | expanded.sals[0] = sal; | |
7416 | return expanded; | |
7417 | } | |
7418 | ||
7419 | if (original_pc) | |
7420 | { | |
7421 | found = 0; | |
7422 | for (i = 0; i < expanded.nelts; ++i) | |
7423 | if (expanded.sals[i].pc == original_pc) | |
7424 | { | |
7425 | found = 1; | |
7426 | break; | |
7427 | } | |
7428 | gdb_assert (found); | |
7429 | } | |
7430 | ||
7431 | return expanded; | |
7432 | } | |
7433 | ||
018d34a4 VP |
7434 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7435 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7436 | value. COND_STRING, if not NULL, specified the condition to be | |
7437 | used for all breakpoints. Essentially the only case where | |
7438 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7439 | function. In that case, it's still not possible to specify | |
7440 | separate conditions for different overloaded functions, so | |
7441 | we take just a single condition string. | |
7442 | ||
c3f6f71d | 7443 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7444 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7445 | array contents). If the function fails (error() is called), the |
7446 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7447 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7448 | |
7449 | static void | |
8cdf0e15 VP |
7450 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7451 | struct symtabs_and_lines sals, char **addr_string, | |
7452 | char *cond_string, | |
7453 | enum bptype type, enum bpdisp disposition, | |
7454 | int thread, int task, int ignore_count, | |
7455 | struct breakpoint_ops *ops, int from_tty, | |
84f4c1fe | 7456 | int enabled, int internal) |
c906108c | 7457 | { |
018d34a4 | 7458 | int i; |
cc59ec59 | 7459 | |
018d34a4 | 7460 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7461 | { |
ed0616c6 VP |
7462 | struct symtabs_and_lines expanded = |
7463 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7464 | |
8cdf0e15 VP |
7465 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7466 | cond_string, type, disposition, | |
84f4c1fe PM |
7467 | thread, task, ignore_count, ops, |
7468 | from_tty, enabled, internal); | |
c3f6f71d | 7469 | } |
c3f6f71d | 7470 | } |
c906108c | 7471 | |
9998af43 | 7472 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7473 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7474 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7475 | address strings. ADDRESS points to the end of the SAL. |
7476 | ||
7477 | The array and the line spec strings are allocated on the heap, it is | |
7478 | the caller's responsibility to free them. */ | |
c906108c | 7479 | |
b9362cc7 | 7480 | static void |
c3f6f71d JM |
7481 | parse_breakpoint_sals (char **address, |
7482 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7483 | char ***addr_string, |
7484 | int *not_found_ptr) | |
c3f6f71d JM |
7485 | { |
7486 | char *addr_start = *address; | |
cc59ec59 | 7487 | |
c3f6f71d JM |
7488 | *addr_string = NULL; |
7489 | /* If no arg given, or if first arg is 'if ', use the default | |
4a64f543 | 7490 | breakpoint. */ |
c3f6f71d JM |
7491 | if ((*address) == NULL |
7492 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7493 | { |
7494 | if (default_breakpoint_valid) | |
7495 | { | |
c3f6f71d | 7496 | struct symtab_and_line sal; |
cc59ec59 | 7497 | |
4a64f543 | 7498 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7499 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7500 | xmalloc (sizeof (struct symtab_and_line)); |
7501 | sal.pc = default_breakpoint_address; | |
7502 | sal.line = default_breakpoint_line; | |
7503 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7504 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7505 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7506 | |
4a64f543 MS |
7507 | /* "break" without arguments is equivalent to "break *PC" |
7508 | where PC is the default_breakpoint_address. So make sure | |
7509 | to set sal.explicit_pc to prevent GDB from trying to | |
7510 | expand the list of sals to include all other instances | |
7511 | with the same symtab and line. */ | |
00903456 JK |
7512 | sal.explicit_pc = 1; |
7513 | ||
c3f6f71d JM |
7514 | sals->sals[0] = sal; |
7515 | sals->nelts = 1; | |
c906108c SS |
7516 | } |
7517 | else | |
8a3fe4f8 | 7518 | error (_("No default breakpoint address now.")); |
c906108c SS |
7519 | } |
7520 | else | |
7521 | { | |
c906108c | 7522 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7523 | current_source_symtab (which is decode_line_1's default). |
7524 | This should produce the results we want almost all of the | |
7525 | time while leaving default_breakpoint_* alone. | |
7526 | ||
1aeae86e AF |
7527 | ObjC: However, don't match an Objective-C method name which |
7528 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7529 | |
c214a6fd | 7530 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7531 | |
c906108c | 7532 | if (default_breakpoint_valid |
0378c332 | 7533 | && (!cursal.symtab |
1aeae86e AF |
7534 | || ((strchr ("+-", (*address)[0]) != NULL) |
7535 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7536 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7537 | default_breakpoint_line, addr_string, |
7538 | not_found_ptr); | |
c906108c | 7539 | else |
0101ce28 JJ |
7540 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7541 | addr_string, not_found_ptr); | |
c906108c | 7542 | } |
4a64f543 | 7543 | /* For any SAL that didn't have a canonical string, fill one in. */ |
c3f6f71d JM |
7544 | if (sals->nelts > 0 && *addr_string == NULL) |
7545 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7546 | if (addr_start != (*address)) | |
c906108c | 7547 | { |
c3f6f71d | 7548 | int i; |
cc59ec59 | 7549 | |
c3f6f71d | 7550 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7551 | { |
4a64f543 | 7552 | /* Add the string if not present. */ |
c3f6f71d | 7553 | if ((*addr_string)[i] == NULL) |
cc59ec59 MS |
7554 | (*addr_string)[i] = savestring (addr_start, |
7555 | (*address) - addr_start); | |
c906108c SS |
7556 | } |
7557 | } | |
c3f6f71d | 7558 | } |
c906108c | 7559 | |
c906108c | 7560 | |
c3f6f71d | 7561 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7562 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7563 | |
b9362cc7 | 7564 | static void |
23e7acfb | 7565 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7566 | { |
7567 | int i; | |
cc59ec59 | 7568 | |
c3f6f71d | 7569 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7570 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7571 | } |
7572 | ||
7a697b8d SS |
7573 | /* Fast tracepoints may have restrictions on valid locations. For |
7574 | instance, a fast tracepoint using a jump instead of a trap will | |
7575 | likely have to overwrite more bytes than a trap would, and so can | |
7576 | only be placed where the instruction is longer than the jump, or a | |
7577 | multi-instruction sequence does not have a jump into the middle of | |
7578 | it, etc. */ | |
7579 | ||
7580 | static void | |
7581 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7582 | struct symtabs_and_lines *sals) | |
7583 | { | |
7584 | int i, rslt; | |
7585 | struct symtab_and_line *sal; | |
7586 | char *msg; | |
7587 | struct cleanup *old_chain; | |
7588 | ||
7589 | for (i = 0; i < sals->nelts; i++) | |
7590 | { | |
7591 | sal = &sals->sals[i]; | |
7592 | ||
7593 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7594 | NULL, &msg); | |
7595 | old_chain = make_cleanup (xfree, msg); | |
7596 | ||
7597 | if (!rslt) | |
7598 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7599 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7600 | ||
7601 | do_cleanups (old_chain); | |
7602 | } | |
7603 | } | |
7604 | ||
05ff989b | 7605 | static void |
0101ce28 JJ |
7606 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7607 | { | |
7608 | struct captured_parse_breakpoint_args *args = data; | |
7609 | ||
7610 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7611 | args->not_found_ptr); | |
0101ce28 JJ |
7612 | } |
7613 | ||
018d34a4 VP |
7614 | /* Given TOK, a string specification of condition and thread, as |
7615 | accepted by the 'break' command, extract the condition | |
7616 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7617 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7618 | If no condition is found, *COND_STRING is set to NULL. |
7619 | If no thread is found, *THREAD is set to -1. */ | |
7620 | static void | |
7621 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7622 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7623 | { |
7624 | *cond_string = NULL; | |
7625 | *thread = -1; | |
7626 | while (tok && *tok) | |
7627 | { | |
7628 | char *end_tok; | |
7629 | int toklen; | |
7630 | char *cond_start = NULL; | |
7631 | char *cond_end = NULL; | |
cc59ec59 | 7632 | |
e9cafbcc | 7633 | tok = skip_spaces (tok); |
018d34a4 | 7634 | |
e9cafbcc | 7635 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7636 | |
7637 | toklen = end_tok - tok; | |
7638 | ||
7639 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7640 | { | |
f7545552 TT |
7641 | struct expression *expr; |
7642 | ||
018d34a4 | 7643 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7644 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7645 | xfree (expr); | |
018d34a4 VP |
7646 | cond_end = tok; |
7647 | *cond_string = savestring (cond_start, | |
7648 | cond_end - cond_start); | |
7649 | } | |
7650 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7651 | { | |
7652 | char *tmptok; | |
7653 | ||
7654 | tok = end_tok + 1; | |
7655 | tmptok = tok; | |
7656 | *thread = strtol (tok, &tok, 0); | |
7657 | if (tok == tmptok) | |
7658 | error (_("Junk after thread keyword.")); | |
7659 | if (!valid_thread_id (*thread)) | |
7660 | error (_("Unknown thread %d."), *thread); | |
7661 | } | |
4a306c9a JB |
7662 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7663 | { | |
7664 | char *tmptok; | |
7665 | ||
7666 | tok = end_tok + 1; | |
7667 | tmptok = tok; | |
7668 | *task = strtol (tok, &tok, 0); | |
7669 | if (tok == tmptok) | |
7670 | error (_("Junk after task keyword.")); | |
7671 | if (!valid_task_id (*task)) | |
b6199126 | 7672 | error (_("Unknown task %d."), *task); |
4a306c9a | 7673 | } |
018d34a4 VP |
7674 | else |
7675 | error (_("Junk at end of arguments.")); | |
7676 | } | |
7677 | } | |
7678 | ||
0fb4aa4b PA |
7679 | /* Decode a static tracepoint marker spec. */ |
7680 | ||
7681 | static struct symtabs_and_lines | |
7682 | decode_static_tracepoint_spec (char **arg_p) | |
7683 | { | |
7684 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7685 | struct symtabs_and_lines sals; | |
7686 | struct symtab_and_line sal; | |
7687 | struct symbol *sym; | |
7688 | struct cleanup *old_chain; | |
7689 | char *p = &(*arg_p)[3]; | |
7690 | char *endp; | |
7691 | char *marker_str; | |
7692 | int i; | |
7693 | ||
e9cafbcc | 7694 | p = skip_spaces (p); |
0fb4aa4b | 7695 | |
e9cafbcc | 7696 | endp = skip_to_space (p); |
0fb4aa4b PA |
7697 | |
7698 | marker_str = savestring (p, endp - p); | |
7699 | old_chain = make_cleanup (xfree, marker_str); | |
7700 | ||
7701 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7702 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7703 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7704 | ||
7705 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7706 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7707 | ||
7708 | for (i = 0; i < sals.nelts; i++) | |
7709 | { | |
7710 | struct static_tracepoint_marker *marker; | |
7711 | ||
7712 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7713 | ||
7714 | init_sal (&sals.sals[i]); | |
7715 | ||
7716 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7717 | sals.sals[i].pc = marker->address; | |
7718 | ||
7719 | release_static_tracepoint_marker (marker); | |
7720 | } | |
7721 | ||
7722 | do_cleanups (old_chain); | |
7723 | ||
7724 | *arg_p = endp; | |
7725 | return sals; | |
7726 | } | |
7727 | ||
fd9b8c24 PA |
7728 | /* Set a breakpoint. This function is shared between CLI and MI |
7729 | functions for setting a breakpoint. This function has two major | |
7730 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7731 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7732 | breakpoint location, address and thread. Otherwise, ARG is just |
7733 | the location of breakpoint, with condition and thread specified by | |
7734 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7735 | the breakpoint number will be allocated from the internal | |
7736 | breakpoint count. Returns true if any breakpoint was created; | |
7737 | false otherwise. */ | |
0101ce28 | 7738 | |
8cdf0e15 VP |
7739 | int |
7740 | create_breakpoint (struct gdbarch *gdbarch, | |
7741 | char *arg, char *cond_string, int thread, | |
7742 | int parse_condition_and_thread, | |
0fb4aa4b | 7743 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7744 | int ignore_count, |
7745 | enum auto_boolean pending_break_support, | |
7746 | struct breakpoint_ops *ops, | |
84f4c1fe | 7747 | int from_tty, int enabled, int internal) |
c3f6f71d | 7748 | { |
71fff37b | 7749 | struct gdb_exception e; |
c3f6f71d | 7750 | struct symtabs_and_lines sals; |
0101ce28 | 7751 | struct symtab_and_line pending_sal; |
0101ce28 | 7752 | char *copy_arg; |
c3f6f71d JM |
7753 | char *addr_start = arg; |
7754 | char **addr_string; | |
7755 | struct cleanup *old_chain; | |
80c99de1 | 7756 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7757 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7758 | int i; |
0101ce28 | 7759 | int pending = 0; |
0101ce28 | 7760 | int not_found = 0; |
4a306c9a | 7761 | int task = 0; |
86b17b60 | 7762 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7763 | |
c3f6f71d JM |
7764 | sals.sals = NULL; |
7765 | sals.nelts = 0; | |
7766 | addr_string = NULL; | |
c3f6f71d | 7767 | |
0101ce28 JJ |
7768 | parse_args.arg_p = &arg; |
7769 | parse_args.sals_p = &sals; | |
7770 | parse_args.addr_string_p = &addr_string; | |
7771 | parse_args.not_found_ptr = ¬_found; | |
7772 | ||
0fb4aa4b PA |
7773 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7774 | { | |
7775 | int i; | |
7776 | ||
7777 | sals = decode_static_tracepoint_spec (&arg); | |
7778 | ||
7779 | copy_arg = savestring (addr_start, arg - addr_start); | |
7780 | addr_string = xcalloc (sals.nelts, sizeof (char **)); | |
7781 | for (i = 0; i < sals.nelts; i++) | |
7782 | addr_string[i] = xstrdup (copy_arg); | |
7783 | goto done; | |
7784 | } | |
7785 | ||
05ff989b AC |
7786 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7787 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7788 | |
7789 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7790 | switch (e.reason) |
0101ce28 | 7791 | { |
05ff989b | 7792 | case RETURN_QUIT: |
98deb0da | 7793 | throw_exception (e); |
05ff989b AC |
7794 | case RETURN_ERROR: |
7795 | switch (e.error) | |
0101ce28 | 7796 | { |
05ff989b | 7797 | case NOT_FOUND_ERROR: |
0101ce28 | 7798 | |
05ff989b AC |
7799 | /* If pending breakpoint support is turned off, throw |
7800 | error. */ | |
fa8d40ab JJ |
7801 | |
7802 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7803 | throw_exception (e); |
7804 | ||
7805 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7806 | |
05ff989b AC |
7807 | /* If pending breakpoint support is auto query and the user |
7808 | selects no, then simply return the error code. */ | |
059fb39f | 7809 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7810 | && !nquery (_("Make breakpoint pending on " |
7811 | "future shared library load? "))) | |
fd9b8c24 | 7812 | return 0; |
fa8d40ab | 7813 | |
05ff989b AC |
7814 | /* At this point, either the user was queried about setting |
7815 | a pending breakpoint and selected yes, or pending | |
7816 | breakpoint behavior is on and thus a pending breakpoint | |
7817 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7818 | copy_arg = xstrdup (addr_start); |
7819 | addr_string = ©_arg; | |
7820 | sals.nelts = 1; | |
7821 | sals.sals = &pending_sal; | |
7822 | pending_sal.pc = 0; | |
7823 | pending = 1; | |
05ff989b AC |
7824 | break; |
7825 | default: | |
98deb0da | 7826 | throw_exception (e); |
0101ce28 | 7827 | } |
05ff989b AC |
7828 | default: |
7829 | if (!sals.nelts) | |
fd9b8c24 | 7830 | return 0; |
0101ce28 | 7831 | } |
c3f6f71d | 7832 | |
0fb4aa4b PA |
7833 | done: |
7834 | ||
4a64f543 | 7835 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7836 | old_chain = make_cleanup (null_cleanup, 0); |
7837 | ||
0101ce28 JJ |
7838 | if (!pending) |
7839 | { | |
7840 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7841 | make_cleanup (xfree, sals.sals); | |
7842 | ||
4a64f543 | 7843 | /* Cleanup the addr_string array but not its contents. */ |
0101ce28 JJ |
7844 | make_cleanup (xfree, addr_string); |
7845 | } | |
c3f6f71d | 7846 | |
c3f6f71d JM |
7847 | /* ----------------------------- SNIP ----------------------------- |
7848 | Anything added to the cleanup chain beyond this point is assumed | |
7849 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7850 | then the memory is not reclaimed. */ |
7851 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7852 | |
7853 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7854 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7855 | for (i = 0; i < sals.nelts; i++) |
7856 | { | |
7857 | if (addr_string[i] != NULL) | |
b8c9b27d | 7858 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7859 | } |
7860 | ||
7861 | /* Resolve all line numbers to PC's and verify that the addresses | |
7862 | are ok for the target. */ | |
0101ce28 | 7863 | if (!pending) |
23e7acfb | 7864 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7865 | |
7a697b8d SS |
7866 | /* Fast tracepoints may have additional restrictions on location. */ |
7867 | if (type_wanted == bp_fast_tracepoint) | |
7868 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7869 | ||
c3f6f71d JM |
7870 | /* Verify that condition can be parsed, before setting any |
7871 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7872 | breakpoint. */ |
0101ce28 | 7873 | if (!pending) |
c3f6f71d | 7874 | { |
2f069f6f | 7875 | if (parse_condition_and_thread) |
72b2ff0e VP |
7876 | { |
7877 | /* Here we only parse 'arg' to separate condition | |
7878 | from thread number, so parsing in context of first | |
7879 | sal is OK. When setting the breakpoint we'll | |
7880 | re-parse it in context of each sal. */ | |
7881 | cond_string = NULL; | |
7882 | thread = -1; | |
4a306c9a JB |
7883 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7884 | &thread, &task); | |
72b2ff0e VP |
7885 | if (cond_string) |
7886 | make_cleanup (xfree, cond_string); | |
7887 | } | |
2f069f6f | 7888 | else |
72b2ff0e VP |
7889 | { |
7890 | /* Create a private copy of condition string. */ | |
7891 | if (cond_string) | |
7892 | { | |
7893 | cond_string = xstrdup (cond_string); | |
7894 | make_cleanup (xfree, cond_string); | |
7895 | } | |
7896 | } | |
0fb4aa4b PA |
7897 | |
7898 | /* If the user is creating a static tracepoint by marker id | |
7899 | (strace -m MARKER_ID), then store the sals index, so that | |
7900 | breakpoint_re_set can try to match up which of the newly | |
7901 | found markers corresponds to this one, and, don't try to | |
7902 | expand multiple locations for each sal, given than SALS | |
7903 | already should contain all sals for MARKER_ID. */ | |
7904 | if (type_wanted == bp_static_tracepoint | |
7905 | && is_marker_spec (addr_string[0])) | |
7906 | { | |
7907 | int i; | |
7908 | ||
7909 | for (i = 0; i < sals.nelts; ++i) | |
7910 | { | |
7911 | struct symtabs_and_lines expanded; | |
7912 | struct breakpoint *tp; | |
7913 | struct cleanup *old_chain; | |
7914 | ||
7915 | expanded.nelts = 1; | |
7916 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7917 | expanded.sals[0] = sals.sals[i]; | |
7918 | old_chain = make_cleanup (xfree, expanded.sals); | |
7919 | ||
7920 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], | |
7921 | cond_string, type_wanted, | |
7922 | tempflag ? disp_del : disp_donttouch, | |
7923 | thread, task, ignore_count, ops, | |
84f4c1fe | 7924 | from_tty, enabled, internal); |
0fb4aa4b PA |
7925 | |
7926 | do_cleanups (old_chain); | |
7927 | ||
7928 | /* Get the tracepoint we just created. */ | |
84f4c1fe PM |
7929 | if (internal) |
7930 | tp = get_breakpoint (internal_breakpoint_number); | |
7931 | else | |
7932 | tp = get_breakpoint (breakpoint_count); | |
0fb4aa4b PA |
7933 | gdb_assert (tp != NULL); |
7934 | ||
7935 | /* Given that its possible to have multiple markers with | |
7936 | the same string id, if the user is creating a static | |
7937 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7938 | store the sals index, so that breakpoint_re_set can | |
7939 | try to match up which of the newly found markers | |
7940 | corresponds to this one */ | |
7941 | tp->static_trace_marker_id_idx = i; | |
7942 | } | |
7943 | } | |
7944 | else | |
7945 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, | |
3e43a32a MS |
7946 | type_wanted, |
7947 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7948 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7949 | enabled, internal); |
c906108c | 7950 | } |
0101ce28 JJ |
7951 | else |
7952 | { | |
0101ce28 JJ |
7953 | struct breakpoint *b; |
7954 | ||
0101ce28 JJ |
7955 | make_cleanup (xfree, copy_arg); |
7956 | ||
a6d9a66e | 7957 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
84f4c1fe | 7958 | set_breakpoint_number (internal, b); |
72b2ff0e | 7959 | b->thread = -1; |
018d34a4 | 7960 | b->addr_string = addr_string[0]; |
72b2ff0e | 7961 | b->cond_string = NULL; |
0101ce28 | 7962 | b->ignore_count = ignore_count; |
0101ce28 | 7963 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7964 | b->condition_not_parsed = 1; |
604133b5 | 7965 | b->ops = ops; |
41447f92 | 7966 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7967 | b->pspace = current_program_space; |
84f4c1fe | 7968 | b->py_bp_object = NULL; |
74960c60 | 7969 | |
6c95b8df | 7970 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7971 | && (b->type == bp_breakpoint |
7972 | || b->type == bp_hardware_breakpoint)) | |
7973 | b->enable_state = bp_startup_disabled; | |
7974 | ||
84f4c1fe PM |
7975 | if (internal) |
7976 | /* Do not mention breakpoints with a negative number, | |
7977 | but do notify observers. */ | |
7978 | observer_notify_breakpoint_created (b->number); | |
7979 | else | |
7980 | mention (b); | |
0101ce28 JJ |
7981 | } |
7982 | ||
c3f6f71d | 7983 | if (sals.nelts > 1) |
95a42b64 | 7984 | { |
3e43a32a MS |
7985 | warning (_("Multiple breakpoints were set.\nUse the " |
7986 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7987 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7988 | } |
7989 | ||
80c99de1 PA |
7990 | /* That's it. Discard the cleanups for data inserted into the |
7991 | breakpoint. */ | |
7992 | discard_cleanups (bkpt_chain); | |
7993 | /* But cleanup everything else. */ | |
c3f6f71d | 7994 | do_cleanups (old_chain); |
217dc9e2 | 7995 | |
80c99de1 | 7996 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7997 | update_global_location_list (1); |
fd9b8c24 PA |
7998 | |
7999 | return 1; | |
c3f6f71d | 8000 | } |
c906108c | 8001 | |
72b2ff0e VP |
8002 | /* Set a breakpoint. |
8003 | ARG is a string describing breakpoint address, | |
8004 | condition, and thread. | |
8005 | FLAG specifies if a breakpoint is hardware on, | |
8006 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8007 | and BP_TEMPFLAG. */ | |
8008 | ||
98deb0da | 8009 | static void |
72b2ff0e | 8010 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8011 | { |
72b2ff0e | 8012 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8013 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8014 | ? bp_hardware_breakpoint | |
8015 | : bp_breakpoint); | |
c3f6f71d | 8016 | |
8cdf0e15 VP |
8017 | create_breakpoint (get_current_arch (), |
8018 | arg, | |
8019 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8020 | tempflag, type_wanted, |
8cdf0e15 VP |
8021 | 0 /* Ignore count */, |
8022 | pending_break_support, | |
8023 | NULL /* breakpoint_ops */, | |
8024 | from_tty, | |
84f4c1fe PM |
8025 | 1 /* enabled */, |
8026 | 0 /* internal */); | |
c906108c SS |
8027 | } |
8028 | ||
72b2ff0e | 8029 | |
c906108c SS |
8030 | /* Helper function for break_command_1 and disassemble_command. */ |
8031 | ||
8032 | void | |
fba45db2 | 8033 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8034 | { |
8035 | CORE_ADDR pc; | |
8036 | ||
8037 | if (sal->pc == 0 && sal->symtab != NULL) | |
8038 | { | |
8039 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8040 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8041 | sal->line, sal->symtab->filename); |
8042 | sal->pc = pc; | |
6a048695 | 8043 | |
4a64f543 MS |
8044 | /* If this SAL corresponds to a breakpoint inserted using a line |
8045 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8046 | if (sal->explicit_line) |
059acae7 | 8047 | skip_prologue_sal (sal); |
c906108c SS |
8048 | } |
8049 | ||
8050 | if (sal->section == 0 && sal->symtab != NULL) | |
8051 | { | |
8052 | struct blockvector *bv; | |
c5aa993b JM |
8053 | struct block *b; |
8054 | struct symbol *sym; | |
c906108c | 8055 | |
801e3a5b | 8056 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8057 | if (bv != NULL) |
8058 | { | |
7f0df278 | 8059 | sym = block_linkage_function (b); |
c906108c SS |
8060 | if (sym != NULL) |
8061 | { | |
8062 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8063 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8064 | } |
8065 | else | |
8066 | { | |
4a64f543 MS |
8067 | /* It really is worthwhile to have the section, so we'll |
8068 | just have to look harder. This case can be executed | |
8069 | if we have line numbers but no functions (as can | |
8070 | happen in assembly source). */ | |
c906108c | 8071 | |
c5aa993b | 8072 | struct minimal_symbol *msym; |
6c95b8df PA |
8073 | struct cleanup *old_chain = save_current_space_and_thread (); |
8074 | ||
8075 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8076 | |
8077 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8078 | if (msym) | |
714835d5 | 8079 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8080 | |
8081 | do_cleanups (old_chain); | |
c906108c SS |
8082 | } |
8083 | } | |
8084 | } | |
8085 | } | |
8086 | ||
8087 | void | |
fba45db2 | 8088 | break_command (char *arg, int from_tty) |
c906108c | 8089 | { |
db107f19 | 8090 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8091 | } |
8092 | ||
c906108c | 8093 | void |
fba45db2 | 8094 | tbreak_command (char *arg, int from_tty) |
c906108c | 8095 | { |
db107f19 | 8096 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8097 | } |
8098 | ||
c906108c | 8099 | static void |
fba45db2 | 8100 | hbreak_command (char *arg, int from_tty) |
c906108c | 8101 | { |
db107f19 | 8102 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8103 | } |
8104 | ||
8105 | static void | |
fba45db2 | 8106 | thbreak_command (char *arg, int from_tty) |
c906108c | 8107 | { |
db107f19 | 8108 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8109 | } |
8110 | ||
8111 | static void | |
fba45db2 | 8112 | stop_command (char *arg, int from_tty) |
c906108c | 8113 | { |
a3f17187 | 8114 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8115 | Usage: stop in <function | address>\n\ |
a3f17187 | 8116 | stop at <line>\n")); |
c906108c SS |
8117 | } |
8118 | ||
8119 | static void | |
fba45db2 | 8120 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8121 | { |
8122 | int badInput = 0; | |
8123 | ||
c5aa993b | 8124 | if (arg == (char *) NULL) |
c906108c SS |
8125 | badInput = 1; |
8126 | else if (*arg != '*') | |
8127 | { | |
8128 | char *argptr = arg; | |
8129 | int hasColon = 0; | |
8130 | ||
4a64f543 | 8131 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8132 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8133 | function/method name. */ |
c906108c | 8134 | while (*argptr && !hasColon) |
c5aa993b JM |
8135 | { |
8136 | hasColon = (*argptr == ':'); | |
8137 | argptr++; | |
8138 | } | |
c906108c SS |
8139 | |
8140 | if (hasColon) | |
c5aa993b | 8141 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8142 | else |
c5aa993b | 8143 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8144 | } |
8145 | ||
8146 | if (badInput) | |
a3f17187 | 8147 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8148 | else |
db107f19 | 8149 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8150 | } |
8151 | ||
8152 | static void | |
fba45db2 | 8153 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8154 | { |
8155 | int badInput = 0; | |
8156 | ||
c5aa993b | 8157 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8158 | badInput = 1; |
8159 | else | |
8160 | { | |
8161 | char *argptr = arg; | |
8162 | int hasColon = 0; | |
8163 | ||
4a64f543 MS |
8164 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8165 | it is probably a line number. */ | |
c906108c | 8166 | while (*argptr && !hasColon) |
c5aa993b JM |
8167 | { |
8168 | hasColon = (*argptr == ':'); | |
8169 | argptr++; | |
8170 | } | |
c906108c SS |
8171 | |
8172 | if (hasColon) | |
c5aa993b | 8173 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8174 | else |
c5aa993b | 8175 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8176 | } |
8177 | ||
8178 | if (badInput) | |
a3f17187 | 8179 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8180 | else |
db107f19 | 8181 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8182 | } |
8183 | ||
4a64f543 MS |
8184 | /* Return non-zero if EXP is verified as constant. Returned zero |
8185 | means EXP is variable. Also the constant detection may fail for | |
8186 | some constant expressions and in such case still falsely return | |
8187 | zero. */ | |
65d79d4b SDJ |
8188 | static int |
8189 | watchpoint_exp_is_const (const struct expression *exp) | |
8190 | { | |
8191 | int i = exp->nelts; | |
8192 | ||
8193 | while (i > 0) | |
8194 | { | |
8195 | int oplenp, argsp; | |
8196 | ||
8197 | /* We are only interested in the descriptor of each element. */ | |
8198 | operator_length (exp, i, &oplenp, &argsp); | |
8199 | i -= oplenp; | |
8200 | ||
8201 | switch (exp->elts[i].opcode) | |
8202 | { | |
8203 | case BINOP_ADD: | |
8204 | case BINOP_SUB: | |
8205 | case BINOP_MUL: | |
8206 | case BINOP_DIV: | |
8207 | case BINOP_REM: | |
8208 | case BINOP_MOD: | |
8209 | case BINOP_LSH: | |
8210 | case BINOP_RSH: | |
8211 | case BINOP_LOGICAL_AND: | |
8212 | case BINOP_LOGICAL_OR: | |
8213 | case BINOP_BITWISE_AND: | |
8214 | case BINOP_BITWISE_IOR: | |
8215 | case BINOP_BITWISE_XOR: | |
8216 | case BINOP_EQUAL: | |
8217 | case BINOP_NOTEQUAL: | |
8218 | case BINOP_LESS: | |
8219 | case BINOP_GTR: | |
8220 | case BINOP_LEQ: | |
8221 | case BINOP_GEQ: | |
8222 | case BINOP_REPEAT: | |
8223 | case BINOP_COMMA: | |
8224 | case BINOP_EXP: | |
8225 | case BINOP_MIN: | |
8226 | case BINOP_MAX: | |
8227 | case BINOP_INTDIV: | |
8228 | case BINOP_CONCAT: | |
8229 | case BINOP_IN: | |
8230 | case BINOP_RANGE: | |
8231 | case TERNOP_COND: | |
8232 | case TERNOP_SLICE: | |
8233 | case TERNOP_SLICE_COUNT: | |
8234 | ||
8235 | case OP_LONG: | |
8236 | case OP_DOUBLE: | |
8237 | case OP_DECFLOAT: | |
8238 | case OP_LAST: | |
8239 | case OP_COMPLEX: | |
8240 | case OP_STRING: | |
8241 | case OP_BITSTRING: | |
8242 | case OP_ARRAY: | |
8243 | case OP_TYPE: | |
8244 | case OP_NAME: | |
8245 | case OP_OBJC_NSSTRING: | |
8246 | ||
8247 | case UNOP_NEG: | |
8248 | case UNOP_LOGICAL_NOT: | |
8249 | case UNOP_COMPLEMENT: | |
8250 | case UNOP_ADDR: | |
8251 | case UNOP_HIGH: | |
4a64f543 MS |
8252 | /* Unary, binary and ternary operators: We have to check |
8253 | their operands. If they are constant, then so is the | |
8254 | result of that operation. For instance, if A and B are | |
8255 | determined to be constants, then so is "A + B". | |
8256 | ||
8257 | UNOP_IND is one exception to the rule above, because the | |
8258 | value of *ADDR is not necessarily a constant, even when | |
8259 | ADDR is. */ | |
65d79d4b SDJ |
8260 | break; |
8261 | ||
8262 | case OP_VAR_VALUE: | |
8263 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8264 | |
65d79d4b | 8265 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8266 | possible that a buggy compiler could mark a variable as |
8267 | constant even when it is not, and TYPE_CONST would return | |
8268 | true in this case, while SYMBOL_CLASS wouldn't. | |
8269 | ||
8270 | We also have to check for function symbols because they | |
8271 | are always constant. */ | |
65d79d4b SDJ |
8272 | { |
8273 | struct symbol *s = exp->elts[i + 2].symbol; | |
8274 | ||
8275 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8276 | && SYMBOL_CLASS (s) != LOC_CONST | |
8277 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8278 | return 0; | |
8279 | break; | |
8280 | } | |
8281 | ||
8282 | /* The default action is to return 0 because we are using | |
8283 | the optimistic approach here: If we don't know something, | |
8284 | then it is not a constant. */ | |
8285 | default: | |
8286 | return 0; | |
8287 | } | |
8288 | } | |
8289 | ||
8290 | return 1; | |
8291 | } | |
8292 | ||
77b06cd7 TJB |
8293 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8294 | ||
8295 | static int | |
8296 | insert_watchpoint (struct bp_location *bl) | |
8297 | { | |
e09342b5 TJB |
8298 | int length = bl->owner->exact? 1 : bl->length; |
8299 | ||
8300 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
8301 | bl->owner->cond_exp); | |
77b06cd7 TJB |
8302 | } |
8303 | ||
8304 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8305 | ||
8306 | static int | |
8307 | remove_watchpoint (struct bp_location *bl) | |
8308 | { | |
e09342b5 TJB |
8309 | int length = bl->owner->exact? 1 : bl->length; |
8310 | ||
8311 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
8312 | bl->owner->cond_exp); | |
8313 | } | |
8314 | ||
8315 | /* Implement the "resources_needed" breakpoint_ops method for | |
8316 | hardware watchpoints. */ | |
8317 | ||
8318 | static int | |
8319 | resources_needed_watchpoint (const struct bp_location *bl) | |
8320 | { | |
90e4670f | 8321 | int length = bl->owner->exact? 1 : bl->length; |
e09342b5 | 8322 | |
90e4670f | 8323 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
77b06cd7 TJB |
8324 | } |
8325 | ||
8326 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8327 | ||
8328 | static struct breakpoint_ops watchpoint_breakpoint_ops = | |
8329 | { | |
8330 | insert_watchpoint, | |
8331 | remove_watchpoint, | |
8332 | NULL, /* breakpoint_hit */ | |
e09342b5 | 8333 | resources_needed_watchpoint, |
77b06cd7 TJB |
8334 | NULL, /* print_it */ |
8335 | NULL, /* print_one */ | |
8336 | NULL, /* print_mention */ | |
8337 | NULL /* print_recreate */ | |
8338 | }; | |
8339 | ||
53a5351d JM |
8340 | /* accessflag: hw_write: watch write, |
8341 | hw_read: watch read, | |
8342 | hw_access: watch access (read or write) */ | |
c906108c | 8343 | static void |
84f4c1fe PM |
8344 | watch_command_1 (char *arg, int accessflag, int from_tty, |
8345 | int just_location, int internal) | |
c906108c | 8346 | { |
d983da9c | 8347 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 8348 | struct expression *exp; |
60e1c644 | 8349 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 8350 | struct value *val, *mark, *result; |
c906108c | 8351 | struct frame_info *frame; |
c906108c SS |
8352 | char *exp_start = NULL; |
8353 | char *exp_end = NULL; | |
37e4754d | 8354 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
8355 | int toklen; |
8356 | char *cond_start = NULL; | |
8357 | char *cond_end = NULL; | |
c906108c SS |
8358 | int i, other_type_used, target_resources_ok = 0; |
8359 | enum bptype bp_type; | |
e09342b5 | 8360 | int reg_cnt = 0; |
37e4754d | 8361 | int thread = -1; |
0cf6dd15 | 8362 | int pc = 0; |
c906108c | 8363 | |
37e4754d LM |
8364 | /* Make sure that we actually have parameters to parse. */ |
8365 | if (arg != NULL && arg[0] != '\0') | |
8366 | { | |
8367 | toklen = strlen (arg); /* Size of argument list. */ | |
8368 | ||
8369 | /* Points tok to the end of the argument list. */ | |
8370 | tok = arg + toklen - 1; | |
8371 | ||
4a64f543 MS |
8372 | /* Go backwards in the parameters list. Skip the last |
8373 | parameter. If we're expecting a 'thread <thread_num>' | |
8374 | parameter, this should be the thread identifier. */ | |
37e4754d LM |
8375 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8376 | tok--; | |
8377 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8378 | tok--; | |
8379 | ||
8380 | /* Points end_tok to the beginning of the last token. */ | |
8381 | id_tok_start = tok + 1; | |
8382 | ||
4a64f543 MS |
8383 | /* Go backwards in the parameters list. Skip one more |
8384 | parameter. If we're expecting a 'thread <thread_num>' | |
8385 | parameter, we should reach a "thread" token. */ | |
37e4754d LM |
8386 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8387 | tok--; | |
8388 | ||
8389 | end_tok = tok; | |
8390 | ||
8391 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8392 | tok--; | |
8393 | ||
8394 | /* Move the pointer forward to skip the whitespace and | |
8395 | calculate the length of the token. */ | |
8396 | tok++; | |
8397 | toklen = end_tok - tok; | |
8398 | ||
8399 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8400 | { | |
8401 | /* At this point we've found a "thread" token, which means | |
8402 | the user is trying to set a watchpoint that triggers | |
8403 | only in a specific thread. */ | |
8404 | char *endp; | |
8405 | ||
8406 | /* Extract the thread ID from the next token. */ | |
8407 | thread = strtol (id_tok_start, &endp, 0); | |
8408 | ||
8409 | /* Check if the user provided a valid numeric value for the | |
8410 | thread ID. */ | |
8411 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
8412 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
8413 | ||
8414 | /* Check if the thread actually exists. */ | |
8415 | if (!valid_thread_id (thread)) | |
8416 | error (_("Unknown thread %d."), thread); | |
8417 | ||
8418 | /* Truncate the string and get rid of the thread <thread_num> | |
8419 | parameter before the parameter list is parsed by the | |
8420 | evaluate_expression() function. */ | |
8421 | *tok = '\0'; | |
8422 | } | |
8423 | } | |
8424 | ||
8425 | /* Parse the rest of the arguments. */ | |
c906108c SS |
8426 | innermost_block = NULL; |
8427 | exp_start = arg; | |
8428 | exp = parse_exp_1 (&arg, 0, 0); | |
8429 | exp_end = arg; | |
fa8a61dc TT |
8430 | /* Remove trailing whitespace from the expression before saving it. |
8431 | This makes the eventual display of the expression string a bit | |
8432 | prettier. */ | |
8433 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
8434 | --exp_end; | |
8435 | ||
65d79d4b SDJ |
8436 | /* Checking if the expression is not constant. */ |
8437 | if (watchpoint_exp_is_const (exp)) | |
8438 | { | |
8439 | int len; | |
8440 | ||
8441 | len = exp_end - exp_start; | |
8442 | while (len > 0 && isspace (exp_start[len - 1])) | |
8443 | len--; | |
8444 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
8445 | } | |
8446 | ||
c906108c SS |
8447 | exp_valid_block = innermost_block; |
8448 | mark = value_mark (); | |
a1442452 | 8449 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
8450 | |
8451 | if (just_location) | |
8452 | { | |
8453 | exp_valid_block = NULL; | |
a1442452 | 8454 | val = value_addr (result); |
06a64a0b TT |
8455 | release_value (val); |
8456 | value_free_to_mark (mark); | |
8457 | } | |
8458 | else if (val != NULL) | |
fa4727a6 | 8459 | release_value (val); |
c906108c | 8460 | |
e9cafbcc TT |
8461 | tok = skip_spaces (arg); |
8462 | end_tok = skip_to_space (tok); | |
c906108c SS |
8463 | |
8464 | toklen = end_tok - tok; | |
8465 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8466 | { | |
2d134ed3 PA |
8467 | struct expression *cond; |
8468 | ||
60e1c644 | 8469 | innermost_block = NULL; |
c906108c SS |
8470 | tok = cond_start = end_tok + 1; |
8471 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
8472 | |
8473 | /* The watchpoint expression may not be local, but the condition | |
8474 | may still be. E.g.: `watch global if local > 0'. */ | |
8475 | cond_exp_valid_block = innermost_block; | |
8476 | ||
2d134ed3 | 8477 | xfree (cond); |
c906108c SS |
8478 | cond_end = tok; |
8479 | } | |
8480 | if (*tok) | |
8a3fe4f8 | 8481 | error (_("Junk at end of command.")); |
c906108c | 8482 | |
53a5351d | 8483 | if (accessflag == hw_read) |
c5aa993b | 8484 | bp_type = bp_read_watchpoint; |
53a5351d | 8485 | else if (accessflag == hw_access) |
c5aa993b JM |
8486 | bp_type = bp_access_watchpoint; |
8487 | else | |
8488 | bp_type = bp_hardware_watchpoint; | |
c906108c | 8489 | |
e09342b5 TJB |
8490 | reg_cnt = can_use_hardware_watchpoint (val, target_exact_watchpoints); |
8491 | if (reg_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 8492 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
e09342b5 | 8493 | if (reg_cnt != 0) |
c5aa993b JM |
8494 | { |
8495 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 8496 | target_resources_ok = |
e09342b5 | 8497 | target_can_use_hardware_watchpoint (bp_type, i + reg_cnt, |
53a5351d | 8498 | other_type_used); |
c5aa993b | 8499 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8500 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 8501 | |
c5aa993b | 8502 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
3e43a32a MS |
8503 | error (_("Target can only support one kind " |
8504 | "of HW watchpoint at a time.")); | |
c5aa993b | 8505 | } |
c906108c | 8506 | |
4a64f543 MS |
8507 | /* Change the type of breakpoint to an ordinary watchpoint if a |
8508 | hardware watchpoint could not be set. */ | |
e09342b5 | 8509 | if (!reg_cnt || target_resources_ok <= 0) |
4d28f7a8 KB |
8510 | bp_type = bp_watchpoint; |
8511 | ||
d983da9c | 8512 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
8513 | |
8514 | /* If the expression is "local", then set up a "watchpoint scope" | |
8515 | breakpoint at the point where we've left the scope of the watchpoint | |
8516 | expression. Create the scope breakpoint before the watchpoint, so | |
8517 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 8518 | if (exp_valid_block && frame) |
d983da9c | 8519 | { |
edb3359d DJ |
8520 | if (frame_id_p (frame_unwind_caller_id (frame))) |
8521 | { | |
8522 | scope_breakpoint | |
a6d9a66e UW |
8523 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
8524 | frame_unwind_caller_pc (frame), | |
edb3359d | 8525 | bp_watchpoint_scope); |
d983da9c | 8526 | |
edb3359d | 8527 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 8528 | |
edb3359d DJ |
8529 | /* Automatically delete the breakpoint when it hits. */ |
8530 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 8531 | |
edb3359d DJ |
8532 | /* Only break in the proper frame (help with recursion). */ |
8533 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 8534 | |
edb3359d | 8535 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
8536 | scope_breakpoint->loc->gdbarch |
8537 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
8538 | scope_breakpoint->loc->requested_address |
8539 | = frame_unwind_caller_pc (frame); | |
8540 | scope_breakpoint->loc->address | |
a6d9a66e UW |
8541 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
8542 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
8543 | scope_breakpoint->type); |
8544 | } | |
d983da9c DJ |
8545 | } |
8546 | ||
c906108c | 8547 | /* Now set up the breakpoint. */ |
2d134ed3 | 8548 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
84f4c1fe | 8549 | set_breakpoint_number (internal, b); |
37e4754d | 8550 | b->thread = thread; |
b5de0fa7 | 8551 | b->disposition = disp_donttouch; |
c906108c SS |
8552 | b->exp = exp; |
8553 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 8554 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
8555 | if (just_location) |
8556 | { | |
8557 | struct type *t = value_type (val); | |
8558 | CORE_ADDR addr = value_as_address (val); | |
8559 | char *name; | |
8560 | ||
8561 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
8562 | name = type_to_string (t); | |
8563 | ||
d63d0675 JK |
8564 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
8565 | core_addr_to_string (addr)); | |
06a64a0b TT |
8566 | xfree (name); |
8567 | ||
d63d0675 JK |
8568 | b->exp_string = xstrprintf ("-location: %.*s", |
8569 | (int) (exp_end - exp_start), exp_start); | |
8570 | ||
06a64a0b TT |
8571 | /* The above expression is in C. */ |
8572 | b->language = language_c; | |
8573 | } | |
8574 | else | |
8575 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
c906108c | 8576 | b->val = val; |
fa4727a6 | 8577 | b->val_valid = 1; |
77b06cd7 TJB |
8578 | b->ops = &watchpoint_breakpoint_ops; |
8579 | ||
e09342b5 TJB |
8580 | /* Use an exact watchpoint when there's only one memory region to be |
8581 | watched, and only one debug register is needed to watch it. */ | |
8582 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
8583 | ||
c906108c SS |
8584 | if (cond_start) |
8585 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
8586 | else | |
8587 | b->cond_string = 0; | |
c5aa993b | 8588 | |
c906108c | 8589 | if (frame) |
f6bc2008 PA |
8590 | { |
8591 | b->watchpoint_frame = get_frame_id (frame); | |
8592 | b->watchpoint_thread = inferior_ptid; | |
8593 | } | |
c906108c | 8594 | else |
f6bc2008 PA |
8595 | { |
8596 | b->watchpoint_frame = null_frame_id; | |
8597 | b->watchpoint_thread = null_ptid; | |
8598 | } | |
c906108c | 8599 | |
d983da9c | 8600 | if (scope_breakpoint != NULL) |
c906108c | 8601 | { |
d983da9c DJ |
8602 | /* The scope breakpoint is related to the watchpoint. We will |
8603 | need to act on them together. */ | |
8604 | b->related_breakpoint = scope_breakpoint; | |
8605 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 8606 | } |
d983da9c | 8607 | |
06a64a0b TT |
8608 | if (!just_location) |
8609 | value_free_to_mark (mark); | |
2d134ed3 PA |
8610 | |
8611 | /* Finally update the new watchpoint. This creates the locations | |
8612 | that should be inserted. */ | |
8613 | update_watchpoint (b, 1); | |
84f4c1fe PM |
8614 | if (internal) |
8615 | /* Do not mention breakpoints with a negative number, but do | |
8616 | notify observers. */ | |
8617 | observer_notify_breakpoint_created (b->number); | |
8618 | else | |
8619 | mention (b); | |
b60e7edf | 8620 | update_global_location_list (1); |
c906108c SS |
8621 | } |
8622 | ||
e09342b5 TJB |
8623 | /* Return count of debug registers needed to watch the given expression. |
8624 | If EXACT_WATCHPOINTS is 1, then consider that only the address of | |
8625 | the start of the watched region will be monitored (i.e., all accesses | |
8626 | will be aligned). This uses less debug registers on some targets. | |
8627 | ||
8628 | If the watchpoint cannot be handled in hardware return zero. */ | |
c906108c | 8629 | |
c906108c | 8630 | static int |
e09342b5 | 8631 | can_use_hardware_watchpoint (struct value *v, int exact_watchpoints) |
c906108c SS |
8632 | { |
8633 | int found_memory_cnt = 0; | |
2e70b7b9 | 8634 | struct value *head = v; |
c906108c SS |
8635 | |
8636 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 8637 | if (!can_use_hw_watchpoints) |
c906108c | 8638 | return 0; |
c5aa993b | 8639 | |
5c44784c JM |
8640 | /* Make sure that the value of the expression depends only upon |
8641 | memory contents, and values computed from them within GDB. If we | |
8642 | find any register references or function calls, we can't use a | |
8643 | hardware watchpoint. | |
8644 | ||
8645 | The idea here is that evaluating an expression generates a series | |
8646 | of values, one holding the value of every subexpression. (The | |
8647 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
8648 | a*b+c.) GDB's values hold almost enough information to establish | |
8649 | the criteria given above --- they identify memory lvalues, | |
8650 | register lvalues, computed values, etcetera. So we can evaluate | |
8651 | the expression, and then scan the chain of values that leaves | |
8652 | behind to decide whether we can detect any possible change to the | |
8653 | expression's final value using only hardware watchpoints. | |
8654 | ||
8655 | However, I don't think that the values returned by inferior | |
8656 | function calls are special in any way. So this function may not | |
8657 | notice that an expression involving an inferior function call | |
8658 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 8659 | for (; v; v = value_next (v)) |
c906108c | 8660 | { |
5c44784c | 8661 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 8662 | { |
8464be76 DJ |
8663 | if (v != head && value_lazy (v)) |
8664 | /* A lazy memory lvalue in the chain is one that GDB never | |
8665 | needed to fetch; we either just used its address (e.g., | |
8666 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
8667 | in `a,b'). This doesn't apply to HEAD; if that is | |
8668 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 8669 | ; |
53a5351d | 8670 | else |
5c44784c JM |
8671 | { |
8672 | /* Ahh, memory we actually used! Check if we can cover | |
8673 | it with hardware watchpoints. */ | |
df407dfe | 8674 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
8675 | |
8676 | /* We only watch structs and arrays if user asked for it | |
8677 | explicitly, never if they just happen to appear in a | |
8678 | middle of some value chain. */ | |
8679 | if (v == head | |
8680 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
8681 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
8682 | { | |
42ae5230 | 8683 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
8684 | int len; |
8685 | int num_regs; | |
8686 | ||
8687 | len = (exact_watchpoints | |
8688 | && is_scalar_type_recursive (vtype))? | |
8689 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 8690 | |
e09342b5 TJB |
8691 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
8692 | if (!num_regs) | |
2e70b7b9 MS |
8693 | return 0; |
8694 | else | |
e09342b5 | 8695 | found_memory_cnt += num_regs; |
2e70b7b9 | 8696 | } |
5c44784c | 8697 | } |
c5aa993b | 8698 | } |
5086187c AC |
8699 | else if (VALUE_LVAL (v) != not_lval |
8700 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 8701 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 8702 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 8703 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
8704 | } |
8705 | ||
8706 | /* The expression itself looks suitable for using a hardware | |
8707 | watchpoint, but give the target machine a chance to reject it. */ | |
8708 | return found_memory_cnt; | |
8709 | } | |
8710 | ||
8b93c638 | 8711 | void |
84f4c1fe | 8712 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8713 | { |
84f4c1fe | 8714 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
8715 | } |
8716 | ||
8717 | /* A helper function that looks for an argument at the start of a | |
8718 | string. The argument must also either be at the end of the string, | |
8719 | or be followed by whitespace. Returns 1 if it finds the argument, | |
8720 | 0 otherwise. If the argument is found, it updates *STR. */ | |
8721 | ||
8722 | static int | |
8723 | check_for_argument (char **str, char *arg, int arg_len) | |
8724 | { | |
8725 | if (strncmp (*str, arg, arg_len) == 0 | |
8726 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
8727 | { | |
8728 | *str += arg_len; | |
8729 | return 1; | |
8730 | } | |
8731 | return 0; | |
8732 | } | |
8733 | ||
8734 | /* A helper function that looks for the "-location" argument and then | |
8735 | calls watch_command_1. */ | |
8736 | ||
8737 | static void | |
8738 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
8739 | { | |
8740 | int just_location = 0; | |
8741 | ||
8742 | if (arg | |
8743 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
8744 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
8745 | { | |
e9cafbcc | 8746 | arg = skip_spaces (arg); |
06a64a0b TT |
8747 | just_location = 1; |
8748 | } | |
8749 | ||
84f4c1fe | 8750 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 8751 | } |
8926118c | 8752 | |
c5aa993b | 8753 | static void |
fba45db2 | 8754 | watch_command (char *arg, int from_tty) |
c906108c | 8755 | { |
06a64a0b | 8756 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
8757 | } |
8758 | ||
8b93c638 | 8759 | void |
84f4c1fe | 8760 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8761 | { |
84f4c1fe | 8762 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 8763 | } |
8926118c | 8764 | |
c5aa993b | 8765 | static void |
fba45db2 | 8766 | rwatch_command (char *arg, int from_tty) |
c906108c | 8767 | { |
06a64a0b | 8768 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
8769 | } |
8770 | ||
8b93c638 | 8771 | void |
84f4c1fe | 8772 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8773 | { |
84f4c1fe | 8774 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 8775 | } |
8926118c | 8776 | |
c5aa993b | 8777 | static void |
fba45db2 | 8778 | awatch_command (char *arg, int from_tty) |
c906108c | 8779 | { |
06a64a0b | 8780 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 8781 | } |
c906108c | 8782 | \f |
c5aa993b | 8783 | |
43ff13b4 | 8784 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8785 | because it uses the mechanisms of breakpoints. */ |
8786 | ||
bfec99b2 PA |
8787 | struct until_break_command_continuation_args |
8788 | { | |
8789 | struct breakpoint *breakpoint; | |
8790 | struct breakpoint *breakpoint2; | |
186c406b | 8791 | int thread_num; |
bfec99b2 PA |
8792 | }; |
8793 | ||
43ff13b4 | 8794 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 8795 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 8796 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 8797 | command. */ |
c2c6d25f | 8798 | static void |
604ead4a | 8799 | until_break_command_continuation (void *arg) |
43ff13b4 | 8800 | { |
bfec99b2 PA |
8801 | struct until_break_command_continuation_args *a = arg; |
8802 | ||
8803 | delete_breakpoint (a->breakpoint); | |
8804 | if (a->breakpoint2) | |
8805 | delete_breakpoint (a->breakpoint2); | |
186c406b | 8806 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
8807 | } |
8808 | ||
c906108c | 8809 | void |
ae66c1fc | 8810 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8811 | { |
8812 | struct symtabs_and_lines sals; | |
8813 | struct symtab_and_line sal; | |
206415a3 | 8814 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8815 | struct breakpoint *breakpoint; |
f107f563 | 8816 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 8817 | struct cleanup *old_chain; |
186c406b TT |
8818 | int thread; |
8819 | struct thread_info *tp; | |
c906108c SS |
8820 | |
8821 | clear_proceed_status (); | |
8822 | ||
8823 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 8824 | this function. */ |
c5aa993b | 8825 | |
c906108c SS |
8826 | if (default_breakpoint_valid) |
8827 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 8828 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 8829 | else |
53a5351d | 8830 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 8831 | 0, (char ***) NULL, NULL); |
c5aa993b | 8832 | |
c906108c | 8833 | if (sals.nelts != 1) |
8a3fe4f8 | 8834 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8835 | |
c906108c | 8836 | sal = sals.sals[0]; |
4a64f543 | 8837 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 8838 | |
c906108c | 8839 | if (*arg) |
8a3fe4f8 | 8840 | error (_("Junk at end of arguments.")); |
c5aa993b | 8841 | |
c906108c | 8842 | resolve_sal_pc (&sal); |
c5aa993b | 8843 | |
ae66c1fc EZ |
8844 | if (anywhere) |
8845 | /* If the user told us to continue until a specified location, | |
8846 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8847 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8848 | null_frame_id, bp_until); | |
ae66c1fc | 8849 | else |
4a64f543 MS |
8850 | /* Otherwise, specify the selected frame, because we want to stop |
8851 | only at the very same frame. */ | |
a6d9a66e UW |
8852 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8853 | get_stack_frame_id (frame), | |
ae66c1fc | 8854 | bp_until); |
c5aa993b | 8855 | |
f107f563 | 8856 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8857 | |
186c406b TT |
8858 | tp = inferior_thread (); |
8859 | thread = tp->num; | |
8860 | ||
ae66c1fc EZ |
8861 | /* Keep within the current frame, or in frames called by the current |
8862 | one. */ | |
edb3359d DJ |
8863 | |
8864 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8865 | { |
edb3359d DJ |
8866 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8867 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8868 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8869 | sal, | |
edb3359d | 8870 | frame_unwind_caller_id (frame), |
f107f563 VP |
8871 | bp_until); |
8872 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
8873 | |
8874 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
8875 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 8876 | } |
c5aa993b | 8877 | |
c906108c | 8878 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 8879 | |
4a64f543 MS |
8880 | /* If we are running asynchronously, and proceed call above has |
8881 | actually managed to start the target, arrange for breakpoints to | |
8882 | be deleted when the target stops. Otherwise, we're already | |
8883 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 8884 | |
8ea051c5 | 8885 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8886 | { |
bfec99b2 PA |
8887 | struct until_break_command_continuation_args *args; |
8888 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8889 | |
bfec99b2 PA |
8890 | args->breakpoint = breakpoint; |
8891 | args->breakpoint2 = breakpoint2; | |
186c406b | 8892 | args->thread_num = thread; |
f107f563 VP |
8893 | |
8894 | discard_cleanups (old_chain); | |
95e54da7 PA |
8895 | add_continuation (inferior_thread (), |
8896 | until_break_command_continuation, args, | |
604ead4a | 8897 | xfree); |
f107f563 VP |
8898 | } |
8899 | else | |
c5aa993b | 8900 | do_cleanups (old_chain); |
c906108c | 8901 | } |
ae66c1fc | 8902 | |
c906108c SS |
8903 | /* This function attempts to parse an optional "if <cond>" clause |
8904 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8905 | |
c906108c SS |
8906 | Else, it returns a pointer to the condition string. (It does not |
8907 | attempt to evaluate the string against a particular block.) And, | |
8908 | it updates arg to point to the first character following the parsed | |
4a64f543 | 8909 | if clause in the arg string. */ |
53a5351d | 8910 | |
c906108c | 8911 | static char * |
fba45db2 | 8912 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8913 | { |
c5aa993b JM |
8914 | char *cond_string; |
8915 | ||
8916 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8917 | return NULL; |
c5aa993b | 8918 | |
4a64f543 | 8919 | /* Skip the "if" keyword. */ |
c906108c | 8920 | (*arg) += 2; |
c5aa993b | 8921 | |
c906108c | 8922 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 8923 | condition string. */ |
e9cafbcc | 8924 | *arg = skip_spaces (*arg); |
c906108c | 8925 | cond_string = *arg; |
c5aa993b | 8926 | |
4a64f543 MS |
8927 | /* Assume that the condition occupies the remainder of the arg |
8928 | string. */ | |
c906108c | 8929 | (*arg) += strlen (cond_string); |
c5aa993b | 8930 | |
c906108c SS |
8931 | return cond_string; |
8932 | } | |
c5aa993b | 8933 | |
c906108c SS |
8934 | /* Commands to deal with catching events, such as signals, exceptions, |
8935 | process start/exit, etc. */ | |
c5aa993b JM |
8936 | |
8937 | typedef enum | |
8938 | { | |
44feb3ce TT |
8939 | catch_fork_temporary, catch_vfork_temporary, |
8940 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8941 | } |
8942 | catch_fork_kind; | |
8943 | ||
c906108c | 8944 | static void |
cc59ec59 MS |
8945 | catch_fork_command_1 (char *arg, int from_tty, |
8946 | struct cmd_list_element *command) | |
c906108c | 8947 | { |
a6d9a66e | 8948 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8949 | char *cond_string = NULL; |
44feb3ce TT |
8950 | catch_fork_kind fork_kind; |
8951 | int tempflag; | |
8952 | ||
8953 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8954 | tempflag = (fork_kind == catch_fork_temporary | |
8955 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8956 | |
44feb3ce TT |
8957 | if (!arg) |
8958 | arg = ""; | |
e9cafbcc | 8959 | arg = skip_spaces (arg); |
c5aa993b | 8960 | |
c906108c | 8961 | /* The allowed syntax is: |
c5aa993b JM |
8962 | catch [v]fork |
8963 | catch [v]fork if <cond> | |
8964 | ||
4a64f543 | 8965 | First, check if there's an if clause. */ |
c906108c | 8966 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 8967 | |
c906108c | 8968 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 8969 | error (_("Junk at end of arguments.")); |
c5aa993b | 8970 | |
c906108c | 8971 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 8972 | and enable reporting of such events. */ |
c5aa993b JM |
8973 | switch (fork_kind) |
8974 | { | |
44feb3ce TT |
8975 | case catch_fork_temporary: |
8976 | case catch_fork_permanent: | |
a6d9a66e | 8977 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8978 | &catch_fork_breakpoint_ops); |
c906108c | 8979 | break; |
44feb3ce TT |
8980 | case catch_vfork_temporary: |
8981 | case catch_vfork_permanent: | |
a6d9a66e | 8982 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8983 | &catch_vfork_breakpoint_ops); |
c906108c | 8984 | break; |
c5aa993b | 8985 | default: |
8a3fe4f8 | 8986 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 8987 | break; |
c5aa993b | 8988 | } |
c906108c SS |
8989 | } |
8990 | ||
8991 | static void | |
cc59ec59 MS |
8992 | catch_exec_command_1 (char *arg, int from_tty, |
8993 | struct cmd_list_element *command) | |
c906108c | 8994 | { |
a6d9a66e | 8995 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8996 | int tempflag; |
c5aa993b | 8997 | char *cond_string = NULL; |
c906108c | 8998 | |
44feb3ce TT |
8999 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9000 | ||
9001 | if (!arg) | |
9002 | arg = ""; | |
e9cafbcc | 9003 | arg = skip_spaces (arg); |
c906108c SS |
9004 | |
9005 | /* The allowed syntax is: | |
c5aa993b JM |
9006 | catch exec |
9007 | catch exec if <cond> | |
c906108c | 9008 | |
4a64f543 | 9009 | First, check if there's an if clause. */ |
c906108c SS |
9010 | cond_string = ep_parse_optional_if_clause (&arg); |
9011 | ||
9012 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9013 | error (_("Junk at end of arguments.")); |
c906108c SS |
9014 | |
9015 | /* If this target supports it, create an exec catchpoint | |
4a64f543 | 9016 | and enable reporting of such events. */ |
a6d9a66e UW |
9017 | create_catchpoint (gdbarch, tempflag, cond_string, |
9018 | &catch_exec_breakpoint_ops); | |
c906108c | 9019 | } |
c5aa993b | 9020 | |
3086aeae DJ |
9021 | static enum print_stop_action |
9022 | print_exception_catchpoint (struct breakpoint *b) | |
9023 | { | |
ade92717 | 9024 | int bp_temp, bp_throw; |
3086aeae | 9025 | |
ade92717 | 9026 | annotate_catchpoint (b->number); |
3086aeae | 9027 | |
ade92717 AR |
9028 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9029 | if (b->loc->address != b->loc->requested_address) | |
9030 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9031 | b->loc->address, | |
9032 | b->number, 1); | |
df2b6d2d | 9033 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9034 | ui_out_text (uiout, |
9035 | bp_temp ? "Temporary catchpoint " | |
9036 | : "Catchpoint "); | |
9037 | if (!ui_out_is_mi_like_p (uiout)) | |
9038 | ui_out_field_int (uiout, "bkptno", b->number); | |
9039 | ui_out_text (uiout, | |
c0b37c48 AR |
9040 | bp_throw ? " (exception thrown), " |
9041 | : " (exception caught), "); | |
ade92717 AR |
9042 | if (ui_out_is_mi_like_p (uiout)) |
9043 | { | |
9044 | ui_out_field_string (uiout, "reason", | |
9045 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9046 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9047 | ui_out_field_int (uiout, "bkptno", b->number); | |
9048 | } | |
3086aeae DJ |
9049 | return PRINT_SRC_AND_LOC; |
9050 | } | |
9051 | ||
9052 | static void | |
cc59ec59 MS |
9053 | print_one_exception_catchpoint (struct breakpoint *b, |
9054 | struct bp_location **last_loc) | |
3086aeae | 9055 | { |
79a45b7d | 9056 | struct value_print_options opts; |
cc59ec59 | 9057 | |
79a45b7d TT |
9058 | get_user_print_options (&opts); |
9059 | if (opts.addressprint) | |
3086aeae DJ |
9060 | { |
9061 | annotate_field (4); | |
604133b5 AR |
9062 | if (b->loc == NULL || b->loc->shlib_disabled) |
9063 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9064 | else | |
5af949e3 UW |
9065 | ui_out_field_core_addr (uiout, "addr", |
9066 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9067 | } |
9068 | annotate_field (5); | |
604133b5 | 9069 | if (b->loc) |
a6d9a66e | 9070 | *last_loc = b->loc; |
3086aeae DJ |
9071 | if (strstr (b->addr_string, "throw") != NULL) |
9072 | ui_out_field_string (uiout, "what", "exception throw"); | |
9073 | else | |
9074 | ui_out_field_string (uiout, "what", "exception catch"); | |
9075 | } | |
9076 | ||
9077 | static void | |
9078 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9079 | { | |
ade92717 AR |
9080 | int bp_temp; |
9081 | int bp_throw; | |
9082 | ||
df2b6d2d | 9083 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9084 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9085 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9086 | : _("Catchpoint ")); | |
9087 | ui_out_field_int (uiout, "bkptno", b->number); | |
9088 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9089 | : _(" (catch)")); | |
3086aeae DJ |
9090 | } |
9091 | ||
6149aea9 PA |
9092 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9093 | catch catchpoints. */ | |
9094 | ||
9095 | static void | |
4a64f543 MS |
9096 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9097 | struct ui_file *fp) | |
6149aea9 PA |
9098 | { |
9099 | int bp_temp; | |
9100 | int bp_throw; | |
9101 | ||
9102 | bp_temp = b->disposition == disp_del; | |
9103 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9104 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9105 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
9106 | } | |
9107 | ||
3086aeae | 9108 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
9109 | NULL, /* insert */ |
9110 | NULL, /* remove */ | |
9111 | NULL, /* breakpoint_hit */ | |
e09342b5 | 9112 | NULL, /* resources_needed */ |
3086aeae DJ |
9113 | print_exception_catchpoint, |
9114 | print_one_exception_catchpoint, | |
6149aea9 PA |
9115 | print_mention_exception_catchpoint, |
9116 | print_recreate_exception_catchpoint | |
3086aeae DJ |
9117 | }; |
9118 | ||
9119 | static int | |
9120 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9121 | enum exception_event_kind ex_event, int from_tty) | |
9122 | { | |
604133b5 AR |
9123 | char *trigger_func_name; |
9124 | ||
3086aeae | 9125 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9126 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9127 | else |
604133b5 | 9128 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9129 | |
8cdf0e15 VP |
9130 | create_breakpoint (get_current_arch (), |
9131 | trigger_func_name, cond_string, -1, | |
9132 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9133 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9134 | 0, |
9135 | AUTO_BOOLEAN_TRUE /* pending */, | |
9136 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9137 | 1 /* enabled */, |
9138 | 0 /* internal */); | |
3086aeae | 9139 | |
3086aeae DJ |
9140 | return 1; |
9141 | } | |
9142 | ||
4a64f543 | 9143 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9144 | |
9145 | static void | |
fba45db2 KB |
9146 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9147 | int tempflag, int from_tty) | |
c906108c | 9148 | { |
c5aa993b | 9149 | char *cond_string = NULL; |
c5aa993b | 9150 | |
44feb3ce TT |
9151 | if (!arg) |
9152 | arg = ""; | |
e9cafbcc | 9153 | arg = skip_spaces (arg); |
c5aa993b | 9154 | |
c906108c SS |
9155 | cond_string = ep_parse_optional_if_clause (&arg); |
9156 | ||
9157 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9158 | error (_("Junk at end of arguments.")); |
c906108c | 9159 | |
059fb39f PM |
9160 | if (ex_event != EX_EVENT_THROW |
9161 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9162 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9163 | |
3086aeae DJ |
9164 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9165 | return; | |
9166 | ||
8a3fe4f8 | 9167 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9168 | } |
9169 | ||
44feb3ce TT |
9170 | /* Implementation of "catch catch" command. */ |
9171 | ||
9172 | static void | |
9173 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9174 | { | |
9175 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9176 | |
44feb3ce TT |
9177 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9178 | } | |
9179 | ||
9180 | /* Implementation of "catch throw" command. */ | |
9181 | ||
9182 | static void | |
9183 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9184 | { | |
9185 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9186 | |
44feb3ce TT |
9187 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9188 | } | |
9189 | ||
f7f9143b JB |
9190 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
9191 | ||
9192 | static void | |
a6d9a66e UW |
9193 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
9194 | struct symtab_and_line sal, | |
f7f9143b JB |
9195 | char *addr_string, |
9196 | char *exp_string, | |
9197 | char *cond_string, | |
9198 | struct expression *cond, | |
9199 | struct breakpoint_ops *ops, | |
9200 | int tempflag, | |
9201 | int from_tty) | |
9202 | { | |
9203 | struct breakpoint *b; | |
9204 | ||
9205 | if (from_tty) | |
9206 | { | |
5af949e3 UW |
9207 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9208 | if (!loc_gdbarch) | |
9209 | loc_gdbarch = gdbarch; | |
9210 | ||
6c95b8df PA |
9211 | describe_other_breakpoints (loc_gdbarch, |
9212 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9213 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9214 | version for exception catchpoints, because two catchpoints | |
9215 | used for different exception names will use the same address. | |
9216 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9217 | unproductive. Besides, the warning phrasing is also a bit |
f7f9143b JB |
9218 | inapropriate, we should use the word catchpoint, and tell |
9219 | the user what type of catchpoint it is. The above is good | |
9220 | enough for now, though. */ | |
9221 | } | |
9222 | ||
a6d9a66e | 9223 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
9224 | set_breakpoint_count (breakpoint_count + 1); |
9225 | ||
9226 | b->enable_state = bp_enabled; | |
9227 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
9228 | b->number = breakpoint_count; | |
9229 | b->ignore_count = 0; | |
511a6cd4 | 9230 | b->loc->cond = cond; |
f7f9143b JB |
9231 | b->addr_string = addr_string; |
9232 | b->language = language_ada; | |
9233 | b->cond_string = cond_string; | |
9234 | b->exp_string = exp_string; | |
9235 | b->thread = -1; | |
9236 | b->ops = ops; | |
f7f9143b JB |
9237 | |
9238 | mention (b); | |
b60e7edf | 9239 | update_global_location_list (1); |
f7f9143b JB |
9240 | } |
9241 | ||
9242 | /* Implement the "catch exception" command. */ | |
9243 | ||
9244 | static void | |
44feb3ce TT |
9245 | catch_ada_exception_command (char *arg, int from_tty, |
9246 | struct cmd_list_element *command) | |
f7f9143b | 9247 | { |
a6d9a66e | 9248 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9249 | int tempflag; |
f7f9143b | 9250 | struct symtab_and_line sal; |
f7f9143b JB |
9251 | char *addr_string = NULL; |
9252 | char *exp_string = NULL; | |
9253 | char *cond_string = NULL; | |
9254 | struct expression *cond = NULL; | |
9255 | struct breakpoint_ops *ops = NULL; | |
9256 | ||
44feb3ce TT |
9257 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9258 | ||
9259 | if (!arg) | |
9260 | arg = ""; | |
f7f9143b JB |
9261 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
9262 | &cond_string, &cond, &ops); | |
a6d9a66e | 9263 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
9264 | cond_string, cond, ops, tempflag, |
9265 | from_tty); | |
9266 | } | |
9267 | ||
a96d9b2e SDJ |
9268 | /* Cleanup function for a syscall filter list. */ |
9269 | static void | |
9270 | clean_up_filters (void *arg) | |
9271 | { | |
9272 | VEC(int) *iter = *(VEC(int) **) arg; | |
9273 | VEC_free (int, iter); | |
9274 | } | |
9275 | ||
9276 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
9277 | filter list, or NULL if no filtering is required. */ | |
9278 | static VEC(int) * | |
9279 | catch_syscall_split_args (char *arg) | |
9280 | { | |
9281 | VEC(int) *result = NULL; | |
9282 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
9283 | ||
9284 | while (*arg != '\0') | |
9285 | { | |
9286 | int i, syscall_number; | |
9287 | char *endptr; | |
9288 | char cur_name[128]; | |
9289 | struct syscall s; | |
9290 | ||
9291 | /* Skip whitespace. */ | |
9292 | while (isspace (*arg)) | |
9293 | arg++; | |
9294 | ||
9295 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9296 | cur_name[i] = arg[i]; | |
9297 | cur_name[i] = '\0'; | |
9298 | arg += i; | |
9299 | ||
9300 | /* Check if the user provided a syscall name or a number. */ | |
9301 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9302 | if (*endptr == '\0') | |
bccd0dd2 | 9303 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9304 | else |
9305 | { | |
9306 | /* We have a name. Let's check if it's valid and convert it | |
9307 | to a number. */ | |
9308 | get_syscall_by_name (cur_name, &s); | |
9309 | ||
9310 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9311 | /* Here we have to issue an error instead of a warning, |
9312 | because GDB cannot do anything useful if there's no | |
9313 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9314 | error (_("Unknown syscall name '%s'."), cur_name); |
9315 | } | |
9316 | ||
9317 | /* Ok, it's valid. */ | |
9318 | VEC_safe_push (int, result, s.number); | |
9319 | } | |
9320 | ||
9321 | discard_cleanups (cleanup); | |
9322 | return result; | |
9323 | } | |
9324 | ||
9325 | /* Implement the "catch syscall" command. */ | |
9326 | ||
9327 | static void | |
cc59ec59 MS |
9328 | catch_syscall_command_1 (char *arg, int from_tty, |
9329 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
9330 | { |
9331 | int tempflag; | |
9332 | VEC(int) *filter; | |
9333 | struct syscall s; | |
9334 | struct gdbarch *gdbarch = get_current_arch (); | |
9335 | ||
9336 | /* Checking if the feature if supported. */ | |
9337 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
9338 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 9339 | this architecture yet.")); |
a96d9b2e SDJ |
9340 | |
9341 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
9342 | ||
e9cafbcc | 9343 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
9344 | |
9345 | /* We need to do this first "dummy" translation in order | |
9346 | to get the syscall XML file loaded or, most important, | |
9347 | to display a warning to the user if there's no XML file | |
9348 | for his/her architecture. */ | |
9349 | get_syscall_by_number (0, &s); | |
9350 | ||
9351 | /* The allowed syntax is: | |
9352 | catch syscall | |
9353 | catch syscall <name | number> [<name | number> ... <name | number>] | |
9354 | ||
9355 | Let's check if there's a syscall name. */ | |
9356 | ||
9357 | if (arg != NULL) | |
9358 | filter = catch_syscall_split_args (arg); | |
9359 | else | |
9360 | filter = NULL; | |
9361 | ||
9362 | create_syscall_event_catchpoint (tempflag, filter, | |
9363 | &catch_syscall_breakpoint_ops); | |
9364 | } | |
9365 | ||
f7f9143b JB |
9366 | /* Implement the "catch assert" command. */ |
9367 | ||
9368 | static void | |
3e43a32a MS |
9369 | catch_assert_command (char *arg, int from_tty, |
9370 | struct cmd_list_element *command) | |
f7f9143b | 9371 | { |
a6d9a66e | 9372 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9373 | int tempflag; |
f7f9143b JB |
9374 | struct symtab_and_line sal; |
9375 | char *addr_string = NULL; | |
9376 | struct breakpoint_ops *ops = NULL; | |
9377 | ||
44feb3ce TT |
9378 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9379 | ||
9380 | if (!arg) | |
9381 | arg = ""; | |
f7f9143b | 9382 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
9383 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
9384 | ops, tempflag, from_tty); | |
f7f9143b JB |
9385 | } |
9386 | ||
c906108c | 9387 | static void |
fba45db2 | 9388 | catch_command (char *arg, int from_tty) |
c906108c | 9389 | { |
44feb3ce | 9390 | error (_("Catch requires an event name.")); |
c906108c SS |
9391 | } |
9392 | \f | |
9393 | ||
9394 | static void | |
fba45db2 | 9395 | tcatch_command (char *arg, int from_tty) |
c906108c | 9396 | { |
44feb3ce | 9397 | error (_("Catch requires an event name.")); |
c906108c SS |
9398 | } |
9399 | ||
80f8a6eb | 9400 | /* Delete breakpoints by address or line. */ |
c906108c SS |
9401 | |
9402 | static void | |
fba45db2 | 9403 | clear_command (char *arg, int from_tty) |
c906108c | 9404 | { |
d6e956e5 VP |
9405 | struct breakpoint *b; |
9406 | VEC(breakpoint_p) *found = 0; | |
9407 | int ix; | |
c906108c SS |
9408 | int default_match; |
9409 | struct symtabs_and_lines sals; | |
9410 | struct symtab_and_line sal; | |
c906108c SS |
9411 | int i; |
9412 | ||
9413 | if (arg) | |
9414 | { | |
9415 | sals = decode_line_spec (arg, 1); | |
9416 | default_match = 0; | |
9417 | } | |
9418 | else | |
9419 | { | |
c5aa993b | 9420 | sals.sals = (struct symtab_and_line *) |
c906108c | 9421 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 9422 | make_cleanup (xfree, sals.sals); |
4a64f543 | 9423 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
9424 | sal.line = default_breakpoint_line; |
9425 | sal.symtab = default_breakpoint_symtab; | |
9426 | sal.pc = default_breakpoint_address; | |
6c95b8df | 9427 | sal.pspace = default_breakpoint_pspace; |
c906108c | 9428 | if (sal.symtab == 0) |
8a3fe4f8 | 9429 | error (_("No source file specified.")); |
c906108c SS |
9430 | |
9431 | sals.sals[0] = sal; | |
9432 | sals.nelts = 1; | |
9433 | ||
9434 | default_match = 1; | |
9435 | } | |
9436 | ||
4a64f543 MS |
9437 | /* We don't call resolve_sal_pc here. That's not as bad as it |
9438 | seems, because all existing breakpoints typically have both | |
9439 | file/line and pc set. So, if clear is given file/line, we can | |
9440 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
9441 | |
9442 | We only support clearing given the address explicitly | |
9443 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 9444 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 9445 | due to optimization, all in one block. |
4a64f543 MS |
9446 | |
9447 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
9448 | PC corresponding to the same file:line, the breakpoint won't |
9449 | be cleared. We probably can still clear the breakpoint, but | |
9450 | since the other PC value is never presented to user, user | |
9451 | can only find it by guessing, and it does not seem important | |
9452 | to support that. */ | |
9453 | ||
4a64f543 MS |
9454 | /* For each line spec given, delete bps which correspond to it. Do |
9455 | it in two passes, solely to preserve the current behavior that | |
9456 | from_tty is forced true if we delete more than one | |
9457 | breakpoint. */ | |
c906108c | 9458 | |
80f8a6eb | 9459 | found = NULL; |
c906108c SS |
9460 | for (i = 0; i < sals.nelts; i++) |
9461 | { | |
9462 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
9463 | If line given (pc == 0), clear all bpts on specified line. |
9464 | If defaulting, clear all bpts on default line | |
c906108c | 9465 | or at default pc. |
c5aa993b JM |
9466 | |
9467 | defaulting sal.pc != 0 tests to do | |
9468 | ||
9469 | 0 1 pc | |
9470 | 1 1 pc _and_ line | |
9471 | 0 0 line | |
9472 | 1 0 <can't happen> */ | |
c906108c SS |
9473 | |
9474 | sal = sals.sals[i]; | |
c906108c | 9475 | |
4a64f543 | 9476 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 9477 | ALL_BREAKPOINTS (b) |
c5aa993b | 9478 | { |
0d381245 | 9479 | int match = 0; |
4a64f543 | 9480 | /* Are we going to delete b? */ |
cc60f2e3 | 9481 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
9482 | { |
9483 | struct bp_location *loc = b->loc; | |
9484 | for (; loc; loc = loc->next) | |
9485 | { | |
6c95b8df PA |
9486 | int pc_match = sal.pc |
9487 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
9488 | && (loc->address == sal.pc) |
9489 | && (!section_is_overlay (loc->section) | |
9490 | || loc->section == sal.section); | |
9491 | int line_match = ((default_match || (0 == sal.pc)) | |
9492 | && b->source_file != NULL | |
9493 | && sal.symtab != NULL | |
6c95b8df | 9494 | && sal.pspace == loc->pspace |
3e43a32a MS |
9495 | && strcmp (b->source_file, |
9496 | sal.symtab->filename) == 0 | |
0d381245 VP |
9497 | && b->line_number == sal.line); |
9498 | if (pc_match || line_match) | |
9499 | { | |
9500 | match = 1; | |
9501 | break; | |
9502 | } | |
9503 | } | |
9504 | } | |
9505 | ||
9506 | if (match) | |
d6e956e5 | 9507 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 9508 | } |
80f8a6eb MS |
9509 | } |
9510 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 9511 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
9512 | { |
9513 | if (arg) | |
8a3fe4f8 | 9514 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 9515 | else |
8a3fe4f8 | 9516 | error (_("No breakpoint at this line.")); |
80f8a6eb | 9517 | } |
c906108c | 9518 | |
d6e956e5 | 9519 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 9520 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 9521 | if (from_tty) |
a3f17187 | 9522 | { |
d6e956e5 | 9523 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
9524 | printf_unfiltered (_("Deleted breakpoint ")); |
9525 | else | |
9526 | printf_unfiltered (_("Deleted breakpoints ")); | |
9527 | } | |
80f8a6eb | 9528 | breakpoints_changed (); |
d6e956e5 VP |
9529 | |
9530 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 9531 | { |
c5aa993b | 9532 | if (from_tty) |
d6e956e5 VP |
9533 | printf_unfiltered ("%d ", b->number); |
9534 | delete_breakpoint (b); | |
c906108c | 9535 | } |
80f8a6eb MS |
9536 | if (from_tty) |
9537 | putchar_unfiltered ('\n'); | |
c906108c SS |
9538 | } |
9539 | \f | |
9540 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
9541 | all breakpoints that are marked for deletion, whether hit or not. | |
9542 | This is called after any breakpoint is hit, or after errors. */ | |
9543 | ||
9544 | void | |
fba45db2 | 9545 | breakpoint_auto_delete (bpstat bs) |
c906108c | 9546 | { |
35df4500 | 9547 | struct breakpoint *b, *b_tmp; |
c906108c SS |
9548 | |
9549 | for (; bs; bs = bs->next) | |
f431efe5 PA |
9550 | if (bs->breakpoint_at |
9551 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 9552 | && bs->stop) |
f431efe5 | 9553 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 9554 | |
35df4500 | 9555 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 9556 | { |
b5de0fa7 | 9557 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
9558 | delete_breakpoint (b); |
9559 | } | |
c906108c SS |
9560 | } |
9561 | ||
4a64f543 MS |
9562 | /* A comparison function for bp_location AP and BP being interfaced to |
9563 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
9564 | does breakpoint_address_is_meaningful say for its OWNER), | |
9565 | secondarily by ordering first bp_permanent OWNERed elements and | |
9566 | terciarily just ensuring the array is sorted stable way despite | |
9567 | qsort being an instable algorithm. */ | |
876fa593 JK |
9568 | |
9569 | static int | |
494cfb0f | 9570 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 9571 | { |
494cfb0f JK |
9572 | struct bp_location *a = *(void **) ap; |
9573 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 9574 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
9575 | int a_perm = a->owner->enable_state == bp_permanent; |
9576 | int b_perm = b->owner->enable_state == bp_permanent; | |
9577 | ||
9578 | if (a->address != b->address) | |
9579 | return (a->address > b->address) - (a->address < b->address); | |
9580 | ||
9581 | /* Sort permanent breakpoints first. */ | |
9582 | if (a_perm != b_perm) | |
9583 | return (a_perm < b_perm) - (a_perm > b_perm); | |
9584 | ||
4a64f543 MS |
9585 | /* Make the user-visible order stable across GDB runs. Locations of |
9586 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
9587 | |
9588 | if (a->owner->number != b->owner->number) | |
9589 | return (a->owner->number > b->owner->number) | |
9590 | - (a->owner->number < b->owner->number); | |
9591 | ||
9592 | return (a > b) - (a < b); | |
9593 | } | |
9594 | ||
876fa593 | 9595 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
9596 | bp_location_shadow_len_after_address_max according to the current |
9597 | content of the bp_location array. */ | |
f7545552 TT |
9598 | |
9599 | static void | |
876fa593 | 9600 | bp_location_target_extensions_update (void) |
f7545552 | 9601 | { |
876fa593 JK |
9602 | struct bp_location *bl, **blp_tmp; |
9603 | ||
9604 | bp_location_placed_address_before_address_max = 0; | |
9605 | bp_location_shadow_len_after_address_max = 0; | |
9606 | ||
9607 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
9608 | { | |
9609 | CORE_ADDR start, end, addr; | |
9610 | ||
9611 | if (!bp_location_has_shadow (bl)) | |
9612 | continue; | |
9613 | ||
9614 | start = bl->target_info.placed_address; | |
9615 | end = start + bl->target_info.shadow_len; | |
9616 | ||
9617 | gdb_assert (bl->address >= start); | |
9618 | addr = bl->address - start; | |
9619 | if (addr > bp_location_placed_address_before_address_max) | |
9620 | bp_location_placed_address_before_address_max = addr; | |
9621 | ||
9622 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
9623 | ||
9624 | gdb_assert (bl->address < end); | |
9625 | addr = end - bl->address; | |
9626 | if (addr > bp_location_shadow_len_after_address_max) | |
9627 | bp_location_shadow_len_after_address_max = addr; | |
9628 | } | |
f7545552 TT |
9629 | } |
9630 | ||
4cd9bd08 | 9631 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
9632 | into the inferior, only remove already-inserted locations that no |
9633 | longer should be inserted. Functions that delete a breakpoint or | |
9634 | breakpoints should pass false, so that deleting a breakpoint | |
9635 | doesn't have the side effect of inserting the locations of other | |
9636 | breakpoints that are marked not-inserted, but should_be_inserted | |
9637 | returns true on them. | |
9638 | ||
9639 | This behaviour is useful is situations close to tear-down -- e.g., | |
9640 | after an exec, while the target still has execution, but breakpoint | |
9641 | shadows of the previous executable image should *NOT* be restored | |
9642 | to the new image; or before detaching, where the target still has | |
9643 | execution and wants to delete breakpoints from GDB's lists, and all | |
9644 | breakpoints had already been removed from the inferior. */ | |
9645 | ||
0d381245 | 9646 | static void |
b60e7edf | 9647 | update_global_location_list (int should_insert) |
0d381245 | 9648 | { |
74960c60 | 9649 | struct breakpoint *b; |
876fa593 | 9650 | struct bp_location **locp, *loc; |
f7545552 TT |
9651 | struct cleanup *cleanups; |
9652 | ||
2d134ed3 PA |
9653 | /* Used in the duplicates detection below. When iterating over all |
9654 | bp_locations, points to the first bp_location of a given address. | |
9655 | Breakpoints and watchpoints of different types are never | |
9656 | duplicates of each other. Keep one pointer for each type of | |
9657 | breakpoint/watchpoint, so we only need to loop over all locations | |
9658 | once. */ | |
9659 | struct bp_location *bp_loc_first; /* breakpoint */ | |
9660 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
9661 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
9662 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 9663 | |
4a64f543 MS |
9664 | /* Saved former bp_location array which we compare against the newly |
9665 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
9666 | struct bp_location **old_location, **old_locp; |
9667 | unsigned old_location_count; | |
9668 | ||
9669 | old_location = bp_location; | |
9670 | old_location_count = bp_location_count; | |
9671 | bp_location = NULL; | |
9672 | bp_location_count = 0; | |
9673 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 9674 | |
74960c60 | 9675 | ALL_BREAKPOINTS (b) |
876fa593 JK |
9676 | for (loc = b->loc; loc; loc = loc->next) |
9677 | bp_location_count++; | |
9678 | ||
9679 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
9680 | locp = bp_location; | |
9681 | ALL_BREAKPOINTS (b) | |
9682 | for (loc = b->loc; loc; loc = loc->next) | |
9683 | *locp++ = loc; | |
9684 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 9685 | bp_location_compare); |
876fa593 JK |
9686 | |
9687 | bp_location_target_extensions_update (); | |
74960c60 | 9688 | |
4a64f543 MS |
9689 | /* Identify bp_location instances that are no longer present in the |
9690 | new list, and therefore should be freed. Note that it's not | |
9691 | necessary that those locations should be removed from inferior -- | |
9692 | if there's another location at the same address (previously | |
9693 | marked as duplicate), we don't need to remove/insert the | |
9694 | location. | |
876fa593 | 9695 | |
4a64f543 MS |
9696 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
9697 | and former bp_location array state respectively. */ | |
876fa593 JK |
9698 | |
9699 | locp = bp_location; | |
9700 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
9701 | old_locp++) | |
74960c60 | 9702 | { |
876fa593 | 9703 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 9704 | struct bp_location **loc2p; |
876fa593 | 9705 | |
4a64f543 MS |
9706 | /* Tells if 'old_loc' is found amoung the new locations. If |
9707 | not, we have to free it. */ | |
c7d46a38 | 9708 | int found_object = 0; |
20874c92 VP |
9709 | /* Tells if the location should remain inserted in the target. */ |
9710 | int keep_in_target = 0; | |
9711 | int removed = 0; | |
876fa593 | 9712 | |
4a64f543 MS |
9713 | /* Skip LOCP entries which will definitely never be needed. |
9714 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 9715 | while (locp < bp_location + bp_location_count |
c7d46a38 | 9716 | && (*locp)->address < old_loc->address) |
876fa593 | 9717 | locp++; |
c7d46a38 PA |
9718 | |
9719 | for (loc2p = locp; | |
9720 | (loc2p < bp_location + bp_location_count | |
9721 | && (*loc2p)->address == old_loc->address); | |
9722 | loc2p++) | |
9723 | { | |
9724 | if (*loc2p == old_loc) | |
9725 | { | |
9726 | found_object = 1; | |
9727 | break; | |
9728 | } | |
9729 | } | |
74960c60 | 9730 | |
4a64f543 MS |
9731 | /* If this location is no longer present, and inserted, look if |
9732 | there's maybe a new location at the same address. If so, | |
9733 | mark that one inserted, and don't remove this one. This is | |
9734 | needed so that we don't have a time window where a breakpoint | |
9735 | at certain location is not inserted. */ | |
74960c60 | 9736 | |
876fa593 | 9737 | if (old_loc->inserted) |
0d381245 | 9738 | { |
4a64f543 MS |
9739 | /* If the location is inserted now, we might have to remove |
9740 | it. */ | |
74960c60 | 9741 | |
876fa593 | 9742 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 9743 | { |
4a64f543 MS |
9744 | /* The location is still present in the location list, |
9745 | and still should be inserted. Don't do anything. */ | |
20874c92 | 9746 | keep_in_target = 1; |
74960c60 VP |
9747 | } |
9748 | else | |
9749 | { | |
4a64f543 MS |
9750 | /* The location is either no longer present, or got |
9751 | disabled. See if there's another location at the | |
9752 | same address, in which case we don't need to remove | |
9753 | this one from the target. */ | |
876fa593 | 9754 | |
2bdf28a0 | 9755 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
9756 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
9757 | { | |
876fa593 | 9758 | for (loc2p = locp; |
c7d46a38 PA |
9759 | (loc2p < bp_location + bp_location_count |
9760 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
9761 | loc2p++) |
9762 | { | |
9763 | struct bp_location *loc2 = *loc2p; | |
9764 | ||
2d134ed3 | 9765 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
9766 | { |
9767 | /* For the sake of should_be_inserted. | |
4a64f543 MS |
9768 | Duplicates check below will fix up this |
9769 | later. */ | |
c7d46a38 | 9770 | loc2->duplicate = 0; |
85d721b8 PA |
9771 | |
9772 | /* Read watchpoint locations are switched to | |
9773 | access watchpoints, if the former are not | |
9774 | supported, but the latter are. */ | |
9775 | if (is_hardware_watchpoint (old_loc->owner)) | |
9776 | { | |
9777 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
9778 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
9779 | } | |
9780 | ||
c7d46a38 PA |
9781 | if (loc2 != old_loc && should_be_inserted (loc2)) |
9782 | { | |
9783 | loc2->inserted = 1; | |
9784 | loc2->target_info = old_loc->target_info; | |
9785 | keep_in_target = 1; | |
9786 | break; | |
9787 | } | |
876fa593 JK |
9788 | } |
9789 | } | |
9790 | } | |
74960c60 VP |
9791 | } |
9792 | ||
20874c92 VP |
9793 | if (!keep_in_target) |
9794 | { | |
876fa593 | 9795 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 9796 | { |
4a64f543 MS |
9797 | /* This is just about all we can do. We could keep |
9798 | this location on the global list, and try to | |
9799 | remove it next time, but there's no particular | |
9800 | reason why we will succeed next time. | |
20874c92 | 9801 | |
4a64f543 MS |
9802 | Note that at this point, old_loc->owner is still |
9803 | valid, as delete_breakpoint frees the breakpoint | |
9804 | only after calling us. */ | |
3e43a32a MS |
9805 | printf_filtered (_("warning: Error removing " |
9806 | "breakpoint %d\n"), | |
876fa593 | 9807 | old_loc->owner->number); |
20874c92 VP |
9808 | } |
9809 | removed = 1; | |
9810 | } | |
0d381245 | 9811 | } |
74960c60 VP |
9812 | |
9813 | if (!found_object) | |
1c5cfe86 | 9814 | { |
db82e815 PA |
9815 | if (removed && non_stop |
9816 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9817 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9818 | { |
db82e815 PA |
9819 | /* This location was removed from the target. In |
9820 | non-stop mode, a race condition is possible where | |
9821 | we've removed a breakpoint, but stop events for that | |
9822 | breakpoint are already queued and will arrive later. | |
9823 | We apply an heuristic to be able to distinguish such | |
9824 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9825 | breakpoint location for a bit, and will retire it | |
9826 | after we see some number of events. The theory here | |
9827 | is that reporting of events should, "on the average", | |
9828 | be fair, so after a while we'll see events from all | |
9829 | threads that have anything of interest, and no longer | |
9830 | need to keep this breakpoint location around. We | |
9831 | don't hold locations forever so to reduce chances of | |
9832 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9833 | SIGTRAP. | |
9834 | ||
9835 | The heuristic failing can be disastrous on | |
9836 | decr_pc_after_break targets. | |
9837 | ||
9838 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9839 | if we fail to recognize a late breakpoint SIGTRAP, | |
9840 | because events_till_retirement has reached 0 too | |
9841 | soon, we'll fail to do the PC adjustment, and report | |
9842 | a random SIGTRAP to the user. When the user resumes | |
9843 | the inferior, it will most likely immediately crash | |
2dec564e | 9844 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
9845 | corrupted, because of being resumed e.g., in the |
9846 | middle of a multi-byte instruction, or skipped a | |
9847 | one-byte instruction. This was actually seen happen | |
9848 | on native x86-linux, and should be less rare on | |
9849 | targets that do not support new thread events, like | |
9850 | remote, due to the heuristic depending on | |
9851 | thread_count. | |
9852 | ||
9853 | Mistaking a random SIGTRAP for a breakpoint trap | |
9854 | causes similar symptoms (PC adjustment applied when | |
9855 | it shouldn't), but then again, playing with SIGTRAPs | |
9856 | behind the debugger's back is asking for trouble. | |
9857 | ||
9858 | Since hardware watchpoint traps are always | |
9859 | distinguishable from other traps, so we don't need to | |
9860 | apply keep hardware watchpoint moribund locations | |
9861 | around. We simply always ignore hardware watchpoint | |
9862 | traps we can no longer explain. */ | |
9863 | ||
876fa593 JK |
9864 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9865 | old_loc->owner = NULL; | |
20874c92 | 9866 | |
876fa593 | 9867 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9868 | } |
9869 | else | |
f431efe5 PA |
9870 | { |
9871 | old_loc->owner = NULL; | |
9872 | decref_bp_location (&old_loc); | |
9873 | } | |
20874c92 | 9874 | } |
74960c60 | 9875 | } |
1c5cfe86 | 9876 | |
2d134ed3 PA |
9877 | /* Rescan breakpoints at the same address and section, marking the |
9878 | first one as "first" and any others as "duplicates". This is so | |
9879 | that the bpt instruction is only inserted once. If we have a | |
9880 | permanent breakpoint at the same place as BPT, make that one the | |
9881 | official one, and the rest as duplicates. Permanent breakpoints | |
9882 | are sorted first for the same address. | |
9883 | ||
9884 | Do the same for hardware watchpoints, but also considering the | |
9885 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9886 | |
2d134ed3 PA |
9887 | bp_loc_first = NULL; |
9888 | wp_loc_first = NULL; | |
9889 | awp_loc_first = NULL; | |
9890 | rwp_loc_first = NULL; | |
876fa593 | 9891 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9892 | { |
4a64f543 MS |
9893 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
9894 | non-NULL. */ | |
876fa593 | 9895 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9896 | struct bp_location **loc_first_p; |
876fa593 JK |
9897 | |
9898 | if (b->enable_state == bp_disabled | |
9899 | || b->enable_state == bp_call_disabled | |
9900 | || b->enable_state == bp_startup_disabled | |
9901 | || !loc->enabled | |
9902 | || loc->shlib_disabled | |
15c3d785 | 9903 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 9904 | || is_tracepoint (b)) |
876fa593 JK |
9905 | continue; |
9906 | ||
9907 | /* Permanent breakpoint should always be inserted. */ | |
9908 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9909 | internal_error (__FILE__, __LINE__, | |
9910 | _("allegedly permanent breakpoint is not " | |
9911 | "actually inserted")); | |
9912 | ||
2d134ed3 PA |
9913 | if (b->type == bp_hardware_watchpoint) |
9914 | loc_first_p = &wp_loc_first; | |
9915 | else if (b->type == bp_read_watchpoint) | |
9916 | loc_first_p = &rwp_loc_first; | |
9917 | else if (b->type == bp_access_watchpoint) | |
9918 | loc_first_p = &awp_loc_first; | |
9919 | else | |
9920 | loc_first_p = &bp_loc_first; | |
9921 | ||
9922 | if (*loc_first_p == NULL | |
9923 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9924 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9925 | { |
2d134ed3 | 9926 | *loc_first_p = loc; |
876fa593 JK |
9927 | loc->duplicate = 0; |
9928 | continue; | |
9929 | } | |
9930 | ||
9931 | loc->duplicate = 1; | |
9932 | ||
2d134ed3 PA |
9933 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9934 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9935 | internal_error (__FILE__, __LINE__, |
9936 | _("another breakpoint was inserted on top of " | |
9937 | "a permanent breakpoint")); | |
0d381245 | 9938 | } |
74960c60 | 9939 | |
50c71eaf | 9940 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9941 | && (have_live_inferiors () |
2567c7d9 | 9942 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9943 | insert_breakpoint_locations (); |
f7545552 TT |
9944 | |
9945 | do_cleanups (cleanups); | |
74960c60 VP |
9946 | } |
9947 | ||
20874c92 VP |
9948 | void |
9949 | breakpoint_retire_moribund (void) | |
9950 | { | |
9951 | struct bp_location *loc; | |
9952 | int ix; | |
9953 | ||
9954 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9955 | if (--(loc->events_till_retirement) == 0) | |
9956 | { | |
f431efe5 | 9957 | decref_bp_location (&loc); |
20874c92 VP |
9958 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
9959 | --ix; | |
9960 | } | |
9961 | } | |
9962 | ||
74960c60 | 9963 | static void |
b60e7edf | 9964 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9965 | { |
9966 | struct gdb_exception e; | |
cc59ec59 | 9967 | |
74960c60 | 9968 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 9969 | update_global_location_list (inserting); |
0d381245 VP |
9970 | } |
9971 | ||
f431efe5 PA |
9972 | /* Clear BKP from a BPS. */ |
9973 | ||
a474d7c2 | 9974 | static void |
f431efe5 | 9975 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
9976 | { |
9977 | bpstat bs; | |
cc59ec59 | 9978 | |
a474d7c2 | 9979 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 9980 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
9981 | { |
9982 | bs->breakpoint_at = NULL; | |
9983 | bs->old_val = NULL; | |
9984 | /* bs->commands will be freed later. */ | |
9985 | } | |
9986 | } | |
9987 | ||
9988 | /* Callback for iterate_over_threads. */ | |
9989 | static int | |
f431efe5 | 9990 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 9991 | { |
f431efe5 | 9992 | struct breakpoint *bpt = data; |
cc59ec59 | 9993 | |
16c381f0 | 9994 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
a474d7c2 PA |
9995 | return 0; |
9996 | } | |
9997 | ||
53a5351d | 9998 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 9999 | structures. */ |
c906108c SS |
10000 | |
10001 | void | |
fba45db2 | 10002 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 10003 | { |
52f0bd74 | 10004 | struct breakpoint *b; |
c906108c | 10005 | |
8a3fe4f8 | 10006 | gdb_assert (bpt != NULL); |
c906108c | 10007 | |
4a64f543 MS |
10008 | /* Has this bp already been deleted? This can happen because |
10009 | multiple lists can hold pointers to bp's. bpstat lists are | |
10010 | especial culprits. | |
10011 | ||
10012 | One example of this happening is a watchpoint's scope bp. When | |
10013 | the scope bp triggers, we notice that the watchpoint is out of | |
10014 | scope, and delete it. We also delete its scope bp. But the | |
10015 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
10016 | That bpstat is then checked for auto-deleting bp's, which are | |
10017 | deleted. | |
10018 | ||
10019 | A real solution to this problem might involve reference counts in | |
10020 | bp's, and/or giving them pointers back to their referencing | |
10021 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
10022 | storage when no more references were extent. A cheaper bandaid | |
10023 | was chosen. */ | |
c906108c SS |
10024 | if (bpt->type == bp_none) |
10025 | return; | |
10026 | ||
4a64f543 MS |
10027 | /* At least avoid this stale reference until the reference counting |
10028 | of breakpoints gets resolved. */ | |
e5a0a904 JK |
10029 | if (bpt->related_breakpoint != NULL) |
10030 | { | |
10031 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
10032 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
10033 | bpt->related_breakpoint->related_breakpoint = NULL; | |
10034 | bpt->related_breakpoint = NULL; | |
10035 | } | |
10036 | ||
383f836e | 10037 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 10038 | |
c906108c SS |
10039 | if (breakpoint_chain == bpt) |
10040 | breakpoint_chain = bpt->next; | |
10041 | ||
c906108c SS |
10042 | ALL_BREAKPOINTS (b) |
10043 | if (b->next == bpt) | |
c5aa993b JM |
10044 | { |
10045 | b->next = bpt->next; | |
10046 | break; | |
10047 | } | |
c906108c | 10048 | |
9add0f1b | 10049 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
10050 | xfree (bpt->cond_string); |
10051 | xfree (bpt->cond_exp); | |
10052 | xfree (bpt->addr_string); | |
10053 | xfree (bpt->exp); | |
10054 | xfree (bpt->exp_string); | |
d63d0675 | 10055 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
10056 | value_free (bpt->val); |
10057 | xfree (bpt->source_file); | |
10058 | xfree (bpt->exec_pathname); | |
a96d9b2e | 10059 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 10060 | |
f431efe5 PA |
10061 | |
10062 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
10063 | been freed. */ | |
10064 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
10065 | in all threeds for now. Note that we cannot just remove bpstats | |
10066 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
10067 | commands are associated with the bpstat; if we remove it here, | |
10068 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
10069 | event-top.c won't do anything, and temporary breakpoints with | |
10070 | commands won't work. */ | |
10071 | ||
10072 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
10073 | ||
4a64f543 MS |
10074 | /* Now that breakpoint is removed from breakpoint list, update the |
10075 | global location list. This will remove locations that used to | |
10076 | belong to this breakpoint. Do this before freeing the breakpoint | |
10077 | itself, since remove_breakpoint looks at location's owner. It | |
10078 | might be better design to have location completely | |
10079 | self-contained, but it's not the case now. */ | |
b60e7edf | 10080 | update_global_location_list (0); |
74960c60 VP |
10081 | |
10082 | ||
4a64f543 MS |
10083 | /* On the chance that someone will soon try again to delete this |
10084 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c SS |
10085 | bpt->type = bp_none; |
10086 | ||
b8c9b27d | 10087 | xfree (bpt); |
c906108c SS |
10088 | } |
10089 | ||
4d6140d9 AC |
10090 | static void |
10091 | do_delete_breakpoint_cleanup (void *b) | |
10092 | { | |
10093 | delete_breakpoint (b); | |
10094 | } | |
10095 | ||
10096 | struct cleanup * | |
10097 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
10098 | { | |
10099 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
10100 | } | |
10101 | ||
95a42b64 TT |
10102 | /* A callback for map_breakpoint_numbers that calls |
10103 | delete_breakpoint. */ | |
10104 | ||
10105 | static void | |
10106 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
10107 | { | |
10108 | delete_breakpoint (b); | |
10109 | } | |
10110 | ||
c906108c | 10111 | void |
fba45db2 | 10112 | delete_command (char *arg, int from_tty) |
c906108c | 10113 | { |
35df4500 | 10114 | struct breakpoint *b, *b_tmp; |
c906108c | 10115 | |
ea9365bb TT |
10116 | dont_repeat (); |
10117 | ||
c906108c SS |
10118 | if (arg == 0) |
10119 | { | |
10120 | int breaks_to_delete = 0; | |
10121 | ||
10122 | /* Delete all breakpoints if no argument. | |
4a64f543 MS |
10123 | Do not delete internal or call-dummy breakpoints, these have |
10124 | to be deleted with an explicit breakpoint number argument. */ | |
c5aa993b JM |
10125 | ALL_BREAKPOINTS (b) |
10126 | { | |
059fb39f | 10127 | if (b->type != bp_call_dummy |
aa7d318d | 10128 | && b->type != bp_std_terminate |
059fb39f | 10129 | && b->type != bp_shlib_event |
4efc6507 | 10130 | && b->type != bp_jit_event |
059fb39f PM |
10131 | && b->type != bp_thread_event |
10132 | && b->type != bp_overlay_event | |
0fd8e87f | 10133 | && b->type != bp_longjmp_master |
aa7d318d | 10134 | && b->type != bp_std_terminate_master |
186c406b | 10135 | && b->type != bp_exception_master |
059fb39f | 10136 | && b->number >= 0) |
973d738b DJ |
10137 | { |
10138 | breaks_to_delete = 1; | |
10139 | break; | |
10140 | } | |
c5aa993b | 10141 | } |
c906108c SS |
10142 | |
10143 | /* Ask user only if there are some breakpoints to delete. */ | |
10144 | if (!from_tty | |
e2e0b3e5 | 10145 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 10146 | { |
35df4500 | 10147 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10148 | { |
059fb39f | 10149 | if (b->type != bp_call_dummy |
aa7d318d | 10150 | && b->type != bp_std_terminate |
059fb39f PM |
10151 | && b->type != bp_shlib_event |
10152 | && b->type != bp_thread_event | |
4efc6507 | 10153 | && b->type != bp_jit_event |
059fb39f | 10154 | && b->type != bp_overlay_event |
0fd8e87f | 10155 | && b->type != bp_longjmp_master |
aa7d318d | 10156 | && b->type != bp_std_terminate_master |
186c406b | 10157 | && b->type != bp_exception_master |
059fb39f | 10158 | && b->number >= 0) |
c5aa993b JM |
10159 | delete_breakpoint (b); |
10160 | } | |
c906108c SS |
10161 | } |
10162 | } | |
10163 | else | |
95a42b64 | 10164 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
10165 | } |
10166 | ||
0d381245 VP |
10167 | static int |
10168 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 10169 | { |
0d381245 VP |
10170 | for (; loc; loc = loc->next) |
10171 | if (!loc->shlib_disabled) | |
10172 | return 0; | |
10173 | return 1; | |
fe3f5fa8 VP |
10174 | } |
10175 | ||
776592bf DE |
10176 | /* Subroutine of update_breakpoint_locations to simplify it. |
10177 | Return non-zero if multiple fns in list LOC have the same name. | |
10178 | Null names are ignored. */ | |
10179 | ||
10180 | static int | |
10181 | ambiguous_names_p (struct bp_location *loc) | |
10182 | { | |
10183 | struct bp_location *l; | |
10184 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
10185 | (int (*) (const void *, |
10186 | const void *)) streq, | |
776592bf DE |
10187 | NULL, xcalloc, xfree); |
10188 | ||
10189 | for (l = loc; l != NULL; l = l->next) | |
10190 | { | |
10191 | const char **slot; | |
10192 | const char *name = l->function_name; | |
10193 | ||
10194 | /* Allow for some names to be NULL, ignore them. */ | |
10195 | if (name == NULL) | |
10196 | continue; | |
10197 | ||
10198 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
10199 | INSERT); | |
4a64f543 MS |
10200 | /* NOTE: We can assume slot != NULL here because xcalloc never |
10201 | returns NULL. */ | |
776592bf DE |
10202 | if (*slot != NULL) |
10203 | { | |
10204 | htab_delete (htab); | |
10205 | return 1; | |
10206 | } | |
10207 | *slot = name; | |
10208 | } | |
10209 | ||
10210 | htab_delete (htab); | |
10211 | return 0; | |
10212 | } | |
10213 | ||
0fb4aa4b PA |
10214 | /* When symbols change, it probably means the sources changed as well, |
10215 | and it might mean the static tracepoint markers are no longer at | |
10216 | the same address or line numbers they used to be at last we | |
10217 | checked. Losing your static tracepoints whenever you rebuild is | |
10218 | undesirable. This function tries to resync/rematch gdb static | |
10219 | tracepoints with the markers on the target, for static tracepoints | |
10220 | that have not been set by marker id. Static tracepoint that have | |
10221 | been set by marker id are reset by marker id in breakpoint_re_set. | |
10222 | The heuristic is: | |
10223 | ||
10224 | 1) For a tracepoint set at a specific address, look for a marker at | |
10225 | the old PC. If one is found there, assume to be the same marker. | |
10226 | If the name / string id of the marker found is different from the | |
10227 | previous known name, assume that means the user renamed the marker | |
10228 | in the sources, and output a warning. | |
10229 | ||
10230 | 2) For a tracepoint set at a given line number, look for a marker | |
10231 | at the new address of the old line number. If one is found there, | |
10232 | assume to be the same marker. If the name / string id of the | |
10233 | marker found is different from the previous known name, assume that | |
10234 | means the user renamed the marker in the sources, and output a | |
10235 | warning. | |
10236 | ||
10237 | 3) If a marker is no longer found at the same address or line, it | |
10238 | may mean the marker no longer exists. But it may also just mean | |
10239 | the code changed a bit. Maybe the user added a few lines of code | |
10240 | that made the marker move up or down (in line number terms). Ask | |
10241 | the target for info about the marker with the string id as we knew | |
10242 | it. If found, update line number and address in the matching | |
10243 | static tracepoint. This will get confused if there's more than one | |
10244 | marker with the same ID (possible in UST, although unadvised | |
10245 | precisely because it confuses tools). */ | |
10246 | ||
10247 | static struct symtab_and_line | |
10248 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
10249 | { | |
10250 | struct static_tracepoint_marker marker; | |
10251 | CORE_ADDR pc; | |
10252 | int i; | |
10253 | ||
10254 | pc = sal.pc; | |
10255 | if (sal.line) | |
10256 | find_line_pc (sal.symtab, sal.line, &pc); | |
10257 | ||
10258 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
10259 | { | |
10260 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
10261 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
10262 | b->number, | |
10263 | b->static_trace_marker_id, marker.str_id); | |
10264 | ||
10265 | xfree (b->static_trace_marker_id); | |
10266 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
10267 | release_static_tracepoint_marker (&marker); | |
10268 | ||
10269 | return sal; | |
10270 | } | |
10271 | ||
10272 | /* Old marker wasn't found on target at lineno. Try looking it up | |
10273 | by string ID. */ | |
10274 | if (!sal.explicit_pc | |
10275 | && sal.line != 0 | |
10276 | && sal.symtab != NULL | |
10277 | && b->static_trace_marker_id != NULL) | |
10278 | { | |
10279 | VEC(static_tracepoint_marker_p) *markers; | |
10280 | ||
10281 | markers | |
10282 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
10283 | ||
10284 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
10285 | { | |
10286 | struct symtab_and_line sal; | |
10287 | struct symbol *sym; | |
10288 | struct static_tracepoint_marker *marker; | |
10289 | ||
10290 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
10291 | ||
10292 | xfree (b->static_trace_marker_id); | |
10293 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
10294 | ||
10295 | warning (_("marker for static tracepoint %d (%s) not " | |
10296 | "found at previous line number"), | |
10297 | b->number, b->static_trace_marker_id); | |
10298 | ||
10299 | init_sal (&sal); | |
10300 | ||
10301 | sal.pc = marker->address; | |
10302 | ||
10303 | sal = find_pc_line (marker->address, 0); | |
10304 | sym = find_pc_sect_function (marker->address, NULL); | |
10305 | ui_out_text (uiout, "Now in "); | |
10306 | if (sym) | |
10307 | { | |
10308 | ui_out_field_string (uiout, "func", | |
10309 | SYMBOL_PRINT_NAME (sym)); | |
10310 | ui_out_text (uiout, " at "); | |
10311 | } | |
10312 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
10313 | ui_out_text (uiout, ":"); | |
10314 | ||
10315 | if (ui_out_is_mi_like_p (uiout)) | |
10316 | { | |
10317 | char *fullname = symtab_to_fullname (sal.symtab); | |
10318 | ||
10319 | if (fullname) | |
10320 | ui_out_field_string (uiout, "fullname", fullname); | |
10321 | } | |
10322 | ||
10323 | ui_out_field_int (uiout, "line", sal.line); | |
10324 | ui_out_text (uiout, "\n"); | |
10325 | ||
10326 | b->line_number = sal.line; | |
10327 | ||
10328 | xfree (b->source_file); | |
10329 | if (sym) | |
10330 | b->source_file = xstrdup (sal.symtab->filename); | |
10331 | else | |
10332 | b->source_file = NULL; | |
10333 | ||
10334 | xfree (b->addr_string); | |
10335 | b->addr_string = xstrprintf ("%s:%d", | |
10336 | sal.symtab->filename, b->line_number); | |
10337 | ||
10338 | /* Might be nice to check if function changed, and warn if | |
10339 | so. */ | |
10340 | ||
10341 | release_static_tracepoint_marker (marker); | |
10342 | } | |
10343 | } | |
10344 | return sal; | |
10345 | } | |
10346 | ||
fe3f5fa8 | 10347 | static void |
0d381245 VP |
10348 | update_breakpoint_locations (struct breakpoint *b, |
10349 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
10350 | { |
10351 | int i; | |
10352 | char *s; | |
0d381245 VP |
10353 | struct bp_location *existing_locations = b->loc; |
10354 | ||
4a64f543 MS |
10355 | /* If there's no new locations, and all existing locations are |
10356 | pending, don't do anything. This optimizes the common case where | |
10357 | all locations are in the same shared library, that was unloaded. | |
10358 | We'd like to retain the location, so that when the library is | |
10359 | loaded again, we don't loose the enabled/disabled status of the | |
10360 | individual locations. */ | |
0d381245 | 10361 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
10362 | return; |
10363 | ||
fe3f5fa8 VP |
10364 | b->loc = NULL; |
10365 | ||
0d381245 | 10366 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 10367 | { |
0d381245 | 10368 | struct bp_location *new_loc = |
39d61571 | 10369 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 10370 | |
0d381245 VP |
10371 | /* Reparse conditions, they might contain references to the |
10372 | old symtab. */ | |
10373 | if (b->cond_string != NULL) | |
10374 | { | |
10375 | struct gdb_exception e; | |
fe3f5fa8 | 10376 | |
0d381245 VP |
10377 | s = b->cond_string; |
10378 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10379 | { | |
10380 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
10381 | 0); | |
10382 | } | |
10383 | if (e.reason < 0) | |
10384 | { | |
3e43a32a MS |
10385 | warning (_("failed to reevaluate condition " |
10386 | "for breakpoint %d: %s"), | |
0d381245 VP |
10387 | b->number, e.message); |
10388 | new_loc->enabled = 0; | |
10389 | } | |
10390 | } | |
fe3f5fa8 | 10391 | |
0d381245 VP |
10392 | if (b->source_file != NULL) |
10393 | xfree (b->source_file); | |
10394 | if (sals.sals[i].symtab == NULL) | |
10395 | b->source_file = NULL; | |
10396 | else | |
1b36a34b | 10397 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 10398 | |
0d381245 VP |
10399 | if (b->line_number == 0) |
10400 | b->line_number = sals.sals[i].line; | |
10401 | } | |
fe3f5fa8 | 10402 | |
514f746b AR |
10403 | /* Update locations of permanent breakpoints. */ |
10404 | if (b->enable_state == bp_permanent) | |
10405 | make_breakpoint_permanent (b); | |
10406 | ||
4a64f543 MS |
10407 | /* If possible, carry over 'disable' status from existing |
10408 | breakpoints. */ | |
0d381245 VP |
10409 | { |
10410 | struct bp_location *e = existing_locations; | |
776592bf DE |
10411 | /* If there are multiple breakpoints with the same function name, |
10412 | e.g. for inline functions, comparing function names won't work. | |
10413 | Instead compare pc addresses; this is just a heuristic as things | |
10414 | may have moved, but in practice it gives the correct answer | |
10415 | often enough until a better solution is found. */ | |
10416 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
10417 | ||
0d381245 VP |
10418 | for (; e; e = e->next) |
10419 | { | |
10420 | if (!e->enabled && e->function_name) | |
10421 | { | |
10422 | struct bp_location *l = b->loc; | |
776592bf DE |
10423 | if (have_ambiguous_names) |
10424 | { | |
10425 | for (; l; l = l->next) | |
6c95b8df PA |
10426 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
10427 | l->pspace->aspace, l->address)) | |
776592bf DE |
10428 | { |
10429 | l->enabled = 0; | |
10430 | break; | |
10431 | } | |
10432 | } | |
10433 | else | |
10434 | { | |
10435 | for (; l; l = l->next) | |
10436 | if (l->function_name | |
10437 | && strcmp (e->function_name, l->function_name) == 0) | |
10438 | { | |
10439 | l->enabled = 0; | |
10440 | break; | |
10441 | } | |
10442 | } | |
0d381245 VP |
10443 | } |
10444 | } | |
10445 | } | |
fe3f5fa8 | 10446 | |
b60e7edf | 10447 | update_global_location_list (1); |
fe3f5fa8 VP |
10448 | } |
10449 | ||
c906108c SS |
10450 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
10451 | The value we return ends up being the return value from catch_errors. | |
10452 | Unused in this case. */ | |
10453 | ||
10454 | static int | |
4efb68b1 | 10455 | breakpoint_re_set_one (void *bint) |
c906108c | 10456 | { |
4a64f543 | 10457 | /* Get past catch_errs. */ |
53a5351d | 10458 | struct breakpoint *b = (struct breakpoint *) bint; |
fe3f5fa8 VP |
10459 | int not_found = 0; |
10460 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
10461 | struct symtabs_and_lines sals = {0}; |
10462 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 10463 | char *s; |
fe3f5fa8 | 10464 | struct gdb_exception e; |
6c95b8df | 10465 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
0fb4aa4b | 10466 | int marker_spec = 0; |
c906108c SS |
10467 | |
10468 | switch (b->type) | |
10469 | { | |
10470 | case bp_none: | |
8a3fe4f8 | 10471 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 10472 | b->number); |
c906108c SS |
10473 | return 0; |
10474 | case bp_breakpoint: | |
10475 | case bp_hardware_breakpoint: | |
1042e4c0 | 10476 | case bp_tracepoint: |
7a697b8d | 10477 | case bp_fast_tracepoint: |
0fb4aa4b | 10478 | case bp_static_tracepoint: |
8bea4e01 UW |
10479 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10480 | if (b->enable_state == bp_startup_disabled) | |
10481 | return 0; | |
10482 | ||
c906108c SS |
10483 | if (b->addr_string == NULL) |
10484 | { | |
4a64f543 | 10485 | /* Anything without a string can't be re-set. */ |
c906108c SS |
10486 | delete_breakpoint (b); |
10487 | return 0; | |
10488 | } | |
c906108c | 10489 | |
c906108c SS |
10490 | input_radix = b->input_radix; |
10491 | s = b->addr_string; | |
6c95b8df PA |
10492 | |
10493 | save_current_space_and_thread (); | |
10494 | switch_to_program_space_and_thread (b->pspace); | |
10495 | ||
0fb4aa4b PA |
10496 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); |
10497 | ||
385d04dc | 10498 | set_language (b->language); |
fe3f5fa8 | 10499 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 10500 | { |
0fb4aa4b PA |
10501 | if (marker_spec) |
10502 | { | |
10503 | sals = decode_static_tracepoint_spec (&s); | |
10504 | if (sals.nelts > b->static_trace_marker_id_idx) | |
10505 | { | |
10506 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
10507 | sals.nelts = 1; | |
10508 | } | |
10509 | else | |
10510 | error (_("marker %s not found"), b->static_trace_marker_id); | |
10511 | } | |
10512 | else | |
3e43a32a MS |
10513 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, |
10514 | (char ***) NULL, not_found_ptr); | |
fe3f5fa8 VP |
10515 | } |
10516 | if (e.reason < 0) | |
10517 | { | |
10518 | int not_found_and_ok = 0; | |
4a64f543 MS |
10519 | /* For pending breakpoints, it's expected that parsing will |
10520 | fail until the right shared library is loaded. User has | |
10521 | already told to create pending breakpoints and don't need | |
10522 | extra messages. If breakpoint is in bp_shlib_disabled | |
10523 | state, then user already saw the message about that | |
10524 | breakpoint being disabled, and don't want to see more | |
10525 | errors. */ | |
0d381245 VP |
10526 | if (not_found |
10527 | && (b->condition_not_parsed | |
10528 | || (b->loc && b->loc->shlib_disabled) | |
10529 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
10530 | not_found_and_ok = 1; |
10531 | ||
10532 | if (!not_found_and_ok) | |
c906108c | 10533 | { |
fe3f5fa8 VP |
10534 | /* We surely don't want to warn about the same breakpoint |
10535 | 10 times. One solution, implemented here, is disable | |
10536 | the breakpoint on error. Another solution would be to | |
10537 | have separate 'warning emitted' flag. Since this | |
10538 | happens only when a binary has changed, I don't know | |
10539 | which approach is better. */ | |
10540 | b->enable_state = bp_disabled; | |
10541 | throw_exception (e); | |
c906108c | 10542 | } |
fe3f5fa8 | 10543 | } |
c906108c | 10544 | |
6c95b8df | 10545 | if (!not_found) |
fe3f5fa8 | 10546 | { |
6c95b8df PA |
10547 | gdb_assert (sals.nelts == 1); |
10548 | ||
10549 | resolve_sal_pc (&sals.sals[0]); | |
10550 | if (b->condition_not_parsed && s && s[0]) | |
10551 | { | |
10552 | char *cond_string = 0; | |
10553 | int thread = -1; | |
10554 | int task = 0; | |
10555 | ||
10556 | find_condition_and_thread (s, sals.sals[0].pc, | |
10557 | &cond_string, &thread, &task); | |
10558 | if (cond_string) | |
10559 | b->cond_string = cond_string; | |
10560 | b->thread = thread; | |
10561 | b->task = task; | |
10562 | b->condition_not_parsed = 0; | |
10563 | } | |
10564 | ||
0fb4aa4b PA |
10565 | if (b->type == bp_static_tracepoint && !marker_spec) |
10566 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
10567 | ||
6c95b8df | 10568 | expanded = expand_line_sal_maybe (sals.sals[0]); |
fe3f5fa8 | 10569 | } |
6c95b8df PA |
10570 | |
10571 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 10572 | update_breakpoint_locations (b, expanded); |
c906108c SS |
10573 | break; |
10574 | ||
10575 | case bp_watchpoint: | |
10576 | case bp_hardware_watchpoint: | |
10577 | case bp_read_watchpoint: | |
10578 | case bp_access_watchpoint: | |
4a64f543 MS |
10579 | /* Watchpoint can be either on expression using entirely global |
10580 | variables, or it can be on local variables. | |
10581 | ||
10582 | Watchpoints of the first kind are never auto-deleted, and | |
10583 | even persist across program restarts. Since they can use | |
10584 | variables from shared libraries, we need to reparse | |
10585 | expression as libraries are loaded and unloaded. | |
10586 | ||
10587 | Watchpoints on local variables can also change meaning as | |
10588 | result of solib event. For example, if a watchpoint uses | |
10589 | both a local and a global variables in expression, it's a | |
10590 | local watchpoint, but unloading of a shared library will make | |
10591 | the expression invalid. This is not a very common use case, | |
10592 | but we still re-evaluate expression, to avoid surprises to | |
10593 | the user. | |
0b3de036 VP |
10594 | |
10595 | Note that for local watchpoints, we re-evaluate it only if | |
10596 | watchpoints frame id is still valid. If it's not, it means | |
4a64f543 MS |
10597 | the watchpoint is out of scope and will be deleted soon. In |
10598 | fact, I'm not sure we'll ever be called in this case. | |
0b3de036 VP |
10599 | |
10600 | If a local watchpoint's frame id is still valid, then | |
4a64f543 | 10601 | b->exp_valid_block is likewise valid, and we can safely use it. |
0b3de036 VP |
10602 | |
10603 | Don't do anything about disabled watchpoints, since they will | |
10604 | be reevaluated again when enabled. */ | |
a5606eee | 10605 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 10606 | break; |
c5aa993b JM |
10607 | /* We needn't really do anything to reset these, since the mask |
10608 | that requests them is unaffected by e.g., new libraries being | |
4a64f543 | 10609 | loaded. */ |
ce78b96d | 10610 | case bp_catchpoint: |
c906108c | 10611 | break; |
c5aa993b | 10612 | |
c906108c | 10613 | default: |
a3f17187 | 10614 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 10615 | /* fall through */ |
0fd8e87f UW |
10616 | /* Delete overlay event and longjmp master breakpoints; they will be |
10617 | reset later by breakpoint_re_set. */ | |
1900040c | 10618 | case bp_overlay_event: |
0fd8e87f | 10619 | case bp_longjmp_master: |
aa7d318d | 10620 | case bp_std_terminate_master: |
186c406b | 10621 | case bp_exception_master: |
c906108c SS |
10622 | delete_breakpoint (b); |
10623 | break; | |
10624 | ||
c5aa993b JM |
10625 | /* This breakpoint is special, it's set up when the inferior |
10626 | starts and we really don't want to touch it. */ | |
c906108c SS |
10627 | case bp_shlib_event: |
10628 | ||
c4093a6a JM |
10629 | /* Like bp_shlib_event, this breakpoint type is special. |
10630 | Once it is set up, we do not want to touch it. */ | |
10631 | case bp_thread_event: | |
10632 | ||
4a64f543 MS |
10633 | /* Keep temporary breakpoints, which can be encountered when we |
10634 | step over a dlopen call and SOLIB_ADD is resetting the | |
10635 | breakpoints. Otherwise these should have been blown away via | |
10636 | the cleanup chain or by breakpoint_init_inferior when we | |
10637 | rerun the executable. */ | |
c906108c SS |
10638 | case bp_until: |
10639 | case bp_finish: | |
10640 | case bp_watchpoint_scope: | |
10641 | case bp_call_dummy: | |
aa7d318d | 10642 | case bp_std_terminate: |
c906108c | 10643 | case bp_step_resume: |
611c83ae PA |
10644 | case bp_longjmp: |
10645 | case bp_longjmp_resume: | |
186c406b TT |
10646 | case bp_exception: |
10647 | case bp_exception_resume: | |
4efc6507 | 10648 | case bp_jit_event: |
c906108c SS |
10649 | break; |
10650 | } | |
10651 | ||
6c95b8df | 10652 | do_cleanups (cleanups); |
c906108c SS |
10653 | return 0; |
10654 | } | |
10655 | ||
69de3c6a | 10656 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 10657 | void |
69de3c6a | 10658 | breakpoint_re_set (void) |
c906108c | 10659 | { |
35df4500 | 10660 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10661 | enum language save_language; |
10662 | int save_input_radix; | |
6c95b8df | 10663 | struct cleanup *old_chain; |
c5aa993b | 10664 | |
c906108c SS |
10665 | save_language = current_language->la_language; |
10666 | save_input_radix = input_radix; | |
6c95b8df PA |
10667 | old_chain = save_current_program_space (); |
10668 | ||
35df4500 | 10669 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10670 | { |
4a64f543 | 10671 | /* Format possible error msg. */ |
fe3f5fa8 | 10672 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
10673 | b->number); |
10674 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 10675 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 10676 | do_cleanups (cleanups); |
c5aa993b | 10677 | } |
c906108c SS |
10678 | set_language (save_language); |
10679 | input_radix = save_input_radix; | |
e62c965a | 10680 | |
0756c555 | 10681 | jit_breakpoint_re_set (); |
4efc6507 | 10682 | |
6c95b8df PA |
10683 | do_cleanups (old_chain); |
10684 | ||
af02033e PP |
10685 | create_overlay_event_breakpoint (); |
10686 | create_longjmp_master_breakpoint (); | |
10687 | create_std_terminate_master_breakpoint (); | |
186c406b | 10688 | create_exception_master_breakpoint (); |
c906108c SS |
10689 | } |
10690 | \f | |
c906108c SS |
10691 | /* Reset the thread number of this breakpoint: |
10692 | ||
10693 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 10694 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 10695 | void |
fba45db2 | 10696 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
10697 | { |
10698 | if (b->thread != -1) | |
10699 | { | |
39f77062 KB |
10700 | if (in_thread_list (inferior_ptid)) |
10701 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
10702 | |
10703 | /* We're being called after following a fork. The new fork is | |
10704 | selected as current, and unless this was a vfork will have a | |
10705 | different program space from the original thread. Reset that | |
10706 | as well. */ | |
10707 | b->loc->pspace = current_program_space; | |
c906108c SS |
10708 | } |
10709 | } | |
10710 | ||
03ac34d5 MS |
10711 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10712 | If from_tty is nonzero, it prints a message to that effect, | |
10713 | which ends with a period (no newline). */ | |
10714 | ||
c906108c | 10715 | void |
fba45db2 | 10716 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 10717 | { |
52f0bd74 | 10718 | struct breakpoint *b; |
c906108c SS |
10719 | |
10720 | if (count < 0) | |
10721 | count = 0; | |
10722 | ||
10723 | ALL_BREAKPOINTS (b) | |
10724 | if (b->number == bptnum) | |
c5aa993b | 10725 | { |
d77f58be SS |
10726 | if (is_tracepoint (b)) |
10727 | { | |
10728 | if (from_tty && count != 0) | |
10729 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
10730 | bptnum); | |
10731 | return; | |
10732 | } | |
10733 | ||
c5aa993b | 10734 | b->ignore_count = count; |
221ea385 KS |
10735 | if (from_tty) |
10736 | { | |
10737 | if (count == 0) | |
3e43a32a MS |
10738 | printf_filtered (_("Will stop next time " |
10739 | "breakpoint %d is reached."), | |
221ea385 KS |
10740 | bptnum); |
10741 | else if (count == 1) | |
a3f17187 | 10742 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
10743 | bptnum); |
10744 | else | |
3e43a32a MS |
10745 | printf_filtered (_("Will ignore next %d " |
10746 | "crossings of breakpoint %d."), | |
221ea385 KS |
10747 | count, bptnum); |
10748 | } | |
c5aa993b | 10749 | breakpoints_changed (); |
383f836e | 10750 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
10751 | return; |
10752 | } | |
c906108c | 10753 | |
8a3fe4f8 | 10754 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
10755 | } |
10756 | ||
c906108c SS |
10757 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
10758 | ||
10759 | static void | |
fba45db2 | 10760 | ignore_command (char *args, int from_tty) |
c906108c SS |
10761 | { |
10762 | char *p = args; | |
52f0bd74 | 10763 | int num; |
c906108c SS |
10764 | |
10765 | if (p == 0) | |
e2e0b3e5 | 10766 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 10767 | |
c906108c | 10768 | num = get_number (&p); |
5c44784c | 10769 | if (num == 0) |
8a3fe4f8 | 10770 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 10771 | if (*p == 0) |
8a3fe4f8 | 10772 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
10773 | |
10774 | set_ignore_count (num, | |
10775 | longest_to_int (value_as_long (parse_and_eval (p))), | |
10776 | from_tty); | |
221ea385 KS |
10777 | if (from_tty) |
10778 | printf_filtered ("\n"); | |
c906108c SS |
10779 | } |
10780 | \f | |
10781 | /* Call FUNCTION on each of the breakpoints | |
10782 | whose numbers are given in ARGS. */ | |
10783 | ||
10784 | static void | |
95a42b64 TT |
10785 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
10786 | void *), | |
10787 | void *data) | |
c906108c | 10788 | { |
52f0bd74 | 10789 | char *p = args; |
c906108c | 10790 | char *p1; |
52f0bd74 AC |
10791 | int num; |
10792 | struct breakpoint *b, *tmp; | |
11cf8741 | 10793 | int match; |
c906108c SS |
10794 | |
10795 | if (p == 0) | |
e2e0b3e5 | 10796 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
10797 | |
10798 | while (*p) | |
10799 | { | |
11cf8741 | 10800 | match = 0; |
c906108c | 10801 | p1 = p; |
c5aa993b | 10802 | |
5c44784c JM |
10803 | num = get_number_or_range (&p1); |
10804 | if (num == 0) | |
c5aa993b | 10805 | { |
8a3fe4f8 | 10806 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
10807 | } |
10808 | else | |
10809 | { | |
10810 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
10811 | if (b->number == num) | |
10812 | { | |
10813 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 10814 | match = 1; |
95a42b64 | 10815 | function (b, data); |
5c44784c | 10816 | if (related_breakpoint) |
95a42b64 | 10817 | function (related_breakpoint, data); |
11cf8741 | 10818 | break; |
5c44784c | 10819 | } |
11cf8741 | 10820 | if (match == 0) |
a3f17187 | 10821 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 10822 | } |
c906108c SS |
10823 | p = p1; |
10824 | } | |
10825 | } | |
10826 | ||
0d381245 VP |
10827 | static struct bp_location * |
10828 | find_location_by_number (char *number) | |
10829 | { | |
10830 | char *dot = strchr (number, '.'); | |
10831 | char *p1; | |
10832 | int bp_num; | |
10833 | int loc_num; | |
10834 | struct breakpoint *b; | |
10835 | struct bp_location *loc; | |
10836 | ||
10837 | *dot = '\0'; | |
10838 | ||
10839 | p1 = number; | |
10840 | bp_num = get_number_or_range (&p1); | |
10841 | if (bp_num == 0) | |
10842 | error (_("Bad breakpoint number '%s'"), number); | |
10843 | ||
10844 | ALL_BREAKPOINTS (b) | |
10845 | if (b->number == bp_num) | |
10846 | { | |
10847 | break; | |
10848 | } | |
10849 | ||
10850 | if (!b || b->number != bp_num) | |
10851 | error (_("Bad breakpoint number '%s'"), number); | |
10852 | ||
10853 | p1 = dot+1; | |
10854 | loc_num = get_number_or_range (&p1); | |
10855 | if (loc_num == 0) | |
10856 | error (_("Bad breakpoint location number '%s'"), number); | |
10857 | ||
10858 | --loc_num; | |
10859 | loc = b->loc; | |
10860 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
10861 | ; | |
10862 | if (!loc) | |
10863 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
10864 | ||
10865 | return loc; | |
10866 | } | |
10867 | ||
10868 | ||
1900040c MS |
10869 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10870 | If from_tty is nonzero, it prints a message to that effect, | |
10871 | which ends with a period (no newline). */ | |
10872 | ||
c906108c | 10873 | void |
fba45db2 | 10874 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10875 | { |
10876 | /* Never disable a watchpoint scope breakpoint; we want to | |
10877 | hit them when we leave scope so we can delete both the | |
10878 | watchpoint and its scope breakpoint at that time. */ | |
10879 | if (bpt->type == bp_watchpoint_scope) | |
10880 | return; | |
10881 | ||
c2c6d25f | 10882 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 10883 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
10884 | return; |
10885 | ||
b5de0fa7 | 10886 | bpt->enable_state = bp_disabled; |
c906108c | 10887 | |
b60e7edf | 10888 | update_global_location_list (0); |
c906108c | 10889 | |
383f836e | 10890 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10891 | } |
10892 | ||
95a42b64 TT |
10893 | /* A callback for map_breakpoint_numbers that calls |
10894 | disable_breakpoint. */ | |
10895 | ||
10896 | static void | |
10897 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
10898 | { | |
10899 | disable_breakpoint (b); | |
10900 | } | |
10901 | ||
c906108c | 10902 | static void |
fba45db2 | 10903 | disable_command (char *args, int from_tty) |
c906108c | 10904 | { |
52f0bd74 | 10905 | struct breakpoint *bpt; |
cc59ec59 | 10906 | |
c906108c SS |
10907 | if (args == 0) |
10908 | ALL_BREAKPOINTS (bpt) | |
10909 | switch (bpt->type) | |
c5aa993b JM |
10910 | { |
10911 | case bp_none: | |
8a3fe4f8 | 10912 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 10913 | bpt->number); |
c5aa993b JM |
10914 | continue; |
10915 | case bp_breakpoint: | |
1042e4c0 | 10916 | case bp_tracepoint: |
7a697b8d | 10917 | case bp_fast_tracepoint: |
0fb4aa4b | 10918 | case bp_static_tracepoint: |
ce78b96d | 10919 | case bp_catchpoint: |
c5aa993b JM |
10920 | case bp_hardware_breakpoint: |
10921 | case bp_watchpoint: | |
10922 | case bp_hardware_watchpoint: | |
10923 | case bp_read_watchpoint: | |
10924 | case bp_access_watchpoint: | |
10925 | disable_breakpoint (bpt); | |
10926 | default: | |
10927 | continue; | |
10928 | } | |
0d381245 VP |
10929 | else if (strchr (args, '.')) |
10930 | { | |
10931 | struct bp_location *loc = find_location_by_number (args); | |
10932 | if (loc) | |
10933 | loc->enabled = 0; | |
b60e7edf | 10934 | update_global_location_list (0); |
0d381245 | 10935 | } |
c906108c | 10936 | else |
95a42b64 | 10937 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
10938 | } |
10939 | ||
10940 | static void | |
fba45db2 | 10941 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 10942 | { |
afe38095 | 10943 | int target_resources_ok; |
c906108c SS |
10944 | |
10945 | if (bpt->type == bp_hardware_breakpoint) | |
10946 | { | |
10947 | int i; | |
c5aa993b | 10948 | i = hw_breakpoint_used_count (); |
53a5351d | 10949 | target_resources_ok = |
d92524f1 | 10950 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 10951 | i + 1, 0); |
c906108c | 10952 | if (target_resources_ok == 0) |
8a3fe4f8 | 10953 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 10954 | else if (target_resources_ok < 0) |
8a3fe4f8 | 10955 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
10956 | } |
10957 | ||
cc60f2e3 | 10958 | if (is_watchpoint (bpt)) |
c906108c | 10959 | { |
dde02812 ES |
10960 | struct gdb_exception e; |
10961 | ||
10962 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 10963 | { |
dde02812 | 10964 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 10965 | } |
dde02812 | 10966 | if (e.reason < 0) |
c5aa993b | 10967 | { |
dde02812 ES |
10968 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
10969 | bpt->number); | |
10970 | return; | |
c5aa993b | 10971 | } |
c906108c | 10972 | } |
0101ce28 | 10973 | |
b4c291bb KH |
10974 | if (bpt->enable_state != bp_permanent) |
10975 | bpt->enable_state = bp_enabled; | |
10976 | bpt->disposition = disposition; | |
b60e7edf | 10977 | update_global_location_list (1); |
b4c291bb KH |
10978 | breakpoints_changed (); |
10979 | ||
383f836e | 10980 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10981 | } |
10982 | ||
fe3f5fa8 | 10983 | |
c906108c | 10984 | void |
fba45db2 | 10985 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10986 | { |
10987 | do_enable_breakpoint (bpt, bpt->disposition); | |
10988 | } | |
10989 | ||
95a42b64 TT |
10990 | /* A callback for map_breakpoint_numbers that calls |
10991 | enable_breakpoint. */ | |
10992 | ||
10993 | static void | |
10994 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
10995 | { | |
10996 | enable_breakpoint (b); | |
10997 | } | |
10998 | ||
c906108c SS |
10999 | /* The enable command enables the specified breakpoints (or all defined |
11000 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 11001 | in stopping the inferior. */ |
c906108c | 11002 | |
c906108c | 11003 | static void |
fba45db2 | 11004 | enable_command (char *args, int from_tty) |
c906108c | 11005 | { |
52f0bd74 | 11006 | struct breakpoint *bpt; |
cc59ec59 | 11007 | |
c906108c SS |
11008 | if (args == 0) |
11009 | ALL_BREAKPOINTS (bpt) | |
11010 | switch (bpt->type) | |
c5aa993b JM |
11011 | { |
11012 | case bp_none: | |
8a3fe4f8 | 11013 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 11014 | bpt->number); |
c5aa993b JM |
11015 | continue; |
11016 | case bp_breakpoint: | |
1042e4c0 | 11017 | case bp_tracepoint: |
7a697b8d | 11018 | case bp_fast_tracepoint: |
0fb4aa4b | 11019 | case bp_static_tracepoint: |
ce78b96d | 11020 | case bp_catchpoint: |
c5aa993b JM |
11021 | case bp_hardware_breakpoint: |
11022 | case bp_watchpoint: | |
11023 | case bp_hardware_watchpoint: | |
11024 | case bp_read_watchpoint: | |
11025 | case bp_access_watchpoint: | |
11026 | enable_breakpoint (bpt); | |
11027 | default: | |
11028 | continue; | |
11029 | } | |
0d381245 VP |
11030 | else if (strchr (args, '.')) |
11031 | { | |
11032 | struct bp_location *loc = find_location_by_number (args); | |
11033 | if (loc) | |
11034 | loc->enabled = 1; | |
b60e7edf | 11035 | update_global_location_list (1); |
0d381245 | 11036 | } |
c906108c | 11037 | else |
95a42b64 | 11038 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
11039 | } |
11040 | ||
11041 | static void | |
95a42b64 | 11042 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11043 | { |
b5de0fa7 | 11044 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
11045 | } |
11046 | ||
c906108c | 11047 | static void |
fba45db2 | 11048 | enable_once_command (char *args, int from_tty) |
c906108c | 11049 | { |
95a42b64 | 11050 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
11051 | } |
11052 | ||
11053 | static void | |
95a42b64 | 11054 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11055 | { |
b5de0fa7 | 11056 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
11057 | } |
11058 | ||
c906108c | 11059 | static void |
fba45db2 | 11060 | enable_delete_command (char *args, int from_tty) |
c906108c | 11061 | { |
95a42b64 | 11062 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
11063 | } |
11064 | \f | |
fa8d40ab JJ |
11065 | static void |
11066 | set_breakpoint_cmd (char *args, int from_tty) | |
11067 | { | |
11068 | } | |
11069 | ||
11070 | static void | |
11071 | show_breakpoint_cmd (char *args, int from_tty) | |
11072 | { | |
11073 | } | |
11074 | ||
1f3b5d1b PP |
11075 | /* Invalidate last known value of any hardware watchpoint if |
11076 | the memory which that value represents has been written to by | |
11077 | GDB itself. */ | |
11078 | ||
11079 | static void | |
11080 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
11081 | const bfd_byte *data) | |
11082 | { | |
11083 | struct breakpoint *bp; | |
11084 | ||
11085 | ALL_BREAKPOINTS (bp) | |
11086 | if (bp->enable_state == bp_enabled | |
11087 | && bp->type == bp_hardware_watchpoint | |
11088 | && bp->val_valid && bp->val) | |
11089 | { | |
11090 | struct bp_location *loc; | |
11091 | ||
11092 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
11093 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
11094 | && loc->address + loc->length > addr | |
11095 | && addr + len > loc->address) | |
11096 | { | |
11097 | value_free (bp->val); | |
11098 | bp->val = NULL; | |
11099 | bp->val_valid = 0; | |
11100 | } | |
11101 | } | |
11102 | } | |
11103 | ||
c906108c SS |
11104 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
11105 | ||
11106 | struct symtabs_and_lines | |
fba45db2 | 11107 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
11108 | { |
11109 | struct symtabs_and_lines sals; | |
cc59ec59 | 11110 | |
c906108c | 11111 | if (string == 0) |
8a3fe4f8 | 11112 | error (_("Empty line specification.")); |
c906108c SS |
11113 | if (default_breakpoint_valid) |
11114 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
11115 | default_breakpoint_symtab, |
11116 | default_breakpoint_line, | |
68219205 | 11117 | (char ***) NULL, NULL); |
c906108c SS |
11118 | else |
11119 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 11120 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 11121 | if (*string) |
8a3fe4f8 | 11122 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
11123 | return sals; |
11124 | } | |
8181d85f DJ |
11125 | |
11126 | /* Create and insert a raw software breakpoint at PC. Return an | |
11127 | identifier, which should be used to remove the breakpoint later. | |
11128 | In general, places which call this should be using something on the | |
11129 | breakpoint chain instead; this function should be eliminated | |
11130 | someday. */ | |
11131 | ||
11132 | void * | |
6c95b8df PA |
11133 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
11134 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
11135 | { |
11136 | struct bp_target_info *bp_tgt; | |
11137 | ||
6c95b8df | 11138 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 11139 | |
6c95b8df | 11140 | bp_tgt->placed_address_space = aspace; |
8181d85f | 11141 | bp_tgt->placed_address = pc; |
6c95b8df | 11142 | |
a6d9a66e | 11143 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
11144 | { |
11145 | /* Could not insert the breakpoint. */ | |
11146 | xfree (bp_tgt); | |
11147 | return NULL; | |
11148 | } | |
11149 | ||
11150 | return bp_tgt; | |
11151 | } | |
11152 | ||
4a64f543 MS |
11153 | /* Remove a breakpoint BP inserted by |
11154 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
11155 | |
11156 | int | |
a6d9a66e | 11157 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
11158 | { |
11159 | struct bp_target_info *bp_tgt = bp; | |
11160 | int ret; | |
11161 | ||
a6d9a66e | 11162 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
11163 | xfree (bp_tgt); |
11164 | ||
11165 | return ret; | |
11166 | } | |
11167 | ||
4a64f543 MS |
11168 | /* One (or perhaps two) breakpoints used for software single |
11169 | stepping. */ | |
8181d85f DJ |
11170 | |
11171 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 11172 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
11173 | |
11174 | /* Create and insert a breakpoint for software single step. */ | |
11175 | ||
11176 | void | |
6c95b8df | 11177 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
11178 | struct address_space *aspace, |
11179 | CORE_ADDR next_pc) | |
8181d85f DJ |
11180 | { |
11181 | void **bpt_p; | |
11182 | ||
11183 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
11184 | { |
11185 | bpt_p = &single_step_breakpoints[0]; | |
11186 | single_step_gdbarch[0] = gdbarch; | |
11187 | } | |
8181d85f DJ |
11188 | else |
11189 | { | |
11190 | gdb_assert (single_step_breakpoints[1] == NULL); | |
11191 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 11192 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
11193 | } |
11194 | ||
4a64f543 MS |
11195 | /* NOTE drow/2006-04-11: A future improvement to this function would |
11196 | be to only create the breakpoints once, and actually put them on | |
11197 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
11198 | We could adjust the addresses each time they were needed. Doing | |
11199 | this requires corresponding changes elsewhere where single step | |
11200 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 11201 | |
6c95b8df | 11202 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 11203 | if (*bpt_p == NULL) |
5af949e3 UW |
11204 | error (_("Could not insert single-step breakpoint at %s"), |
11205 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
11206 | } |
11207 | ||
f02253f1 HZ |
11208 | /* Check if the breakpoints used for software single stepping |
11209 | were inserted or not. */ | |
11210 | ||
11211 | int | |
11212 | single_step_breakpoints_inserted (void) | |
11213 | { | |
11214 | return (single_step_breakpoints[0] != NULL | |
11215 | || single_step_breakpoints[1] != NULL); | |
11216 | } | |
11217 | ||
8181d85f DJ |
11218 | /* Remove and delete any breakpoints used for software single step. */ |
11219 | ||
11220 | void | |
11221 | remove_single_step_breakpoints (void) | |
11222 | { | |
11223 | gdb_assert (single_step_breakpoints[0] != NULL); | |
11224 | ||
11225 | /* See insert_single_step_breakpoint for more about this deprecated | |
11226 | call. */ | |
a6d9a66e UW |
11227 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
11228 | single_step_breakpoints[0]); | |
11229 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
11230 | single_step_breakpoints[0] = NULL; |
11231 | ||
11232 | if (single_step_breakpoints[1] != NULL) | |
11233 | { | |
a6d9a66e UW |
11234 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
11235 | single_step_breakpoints[1]); | |
11236 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
11237 | single_step_breakpoints[1] = NULL; |
11238 | } | |
11239 | } | |
11240 | ||
d03285ec UW |
11241 | /* Delete software single step breakpoints without removing them from |
11242 | the inferior. This is intended to be used if the inferior's address | |
11243 | space where they were inserted is already gone, e.g. after exit or | |
11244 | exec. */ | |
11245 | ||
11246 | void | |
11247 | cancel_single_step_breakpoints (void) | |
11248 | { | |
11249 | int i; | |
11250 | ||
11251 | for (i = 0; i < 2; i++) | |
11252 | if (single_step_breakpoints[i]) | |
11253 | { | |
11254 | xfree (single_step_breakpoints[i]); | |
11255 | single_step_breakpoints[i] = NULL; | |
11256 | single_step_gdbarch[i] = NULL; | |
11257 | } | |
11258 | } | |
11259 | ||
11260 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
11261 | removing them. */ | |
11262 | ||
11263 | static void | |
11264 | detach_single_step_breakpoints (void) | |
11265 | { | |
11266 | int i; | |
11267 | ||
11268 | for (i = 0; i < 2; i++) | |
11269 | if (single_step_breakpoints[i]) | |
11270 | target_remove_breakpoint (single_step_gdbarch[i], | |
11271 | single_step_breakpoints[i]); | |
11272 | } | |
11273 | ||
4a64f543 MS |
11274 | /* Check whether a software single-step breakpoint is inserted at |
11275 | PC. */ | |
1aafd4da UW |
11276 | |
11277 | static int | |
cc59ec59 MS |
11278 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
11279 | CORE_ADDR pc) | |
1aafd4da UW |
11280 | { |
11281 | int i; | |
11282 | ||
11283 | for (i = 0; i < 2; i++) | |
11284 | { | |
11285 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
11286 | if (bp_tgt |
11287 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
11288 | bp_tgt->placed_address, | |
11289 | aspace, pc)) | |
1aafd4da UW |
11290 | return 1; |
11291 | } | |
11292 | ||
11293 | return 0; | |
11294 | } | |
11295 | ||
a96d9b2e SDJ |
11296 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
11297 | non-zero otherwise. */ | |
11298 | static int | |
11299 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
11300 | { | |
11301 | if (syscall_catchpoint_p (bp) | |
11302 | && bp->enable_state != bp_disabled | |
11303 | && bp->enable_state != bp_call_disabled) | |
11304 | return 1; | |
11305 | else | |
11306 | return 0; | |
11307 | } | |
11308 | ||
11309 | int | |
11310 | catch_syscall_enabled (void) | |
11311 | { | |
11312 | struct inferior *inf = current_inferior (); | |
11313 | ||
11314 | return inf->total_syscalls_count != 0; | |
11315 | } | |
11316 | ||
11317 | int | |
11318 | catching_syscall_number (int syscall_number) | |
11319 | { | |
11320 | struct breakpoint *bp; | |
11321 | ||
11322 | ALL_BREAKPOINTS (bp) | |
11323 | if (is_syscall_catchpoint_enabled (bp)) | |
11324 | { | |
11325 | if (bp->syscalls_to_be_caught) | |
11326 | { | |
11327 | int i, iter; | |
11328 | for (i = 0; | |
11329 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
11330 | i++) | |
11331 | if (syscall_number == iter) | |
11332 | return 1; | |
11333 | } | |
11334 | else | |
11335 | return 1; | |
11336 | } | |
11337 | ||
11338 | return 0; | |
11339 | } | |
11340 | ||
11341 | /* Complete syscall names. Used by "catch syscall". */ | |
11342 | static char ** | |
11343 | catch_syscall_completer (struct cmd_list_element *cmd, | |
11344 | char *text, char *word) | |
11345 | { | |
11346 | const char **list = get_syscall_names (); | |
cc59ec59 | 11347 | |
a96d9b2e SDJ |
11348 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); |
11349 | } | |
11350 | ||
1042e4c0 SS |
11351 | /* Tracepoint-specific operations. */ |
11352 | ||
11353 | /* Set tracepoint count to NUM. */ | |
11354 | static void | |
11355 | set_tracepoint_count (int num) | |
11356 | { | |
11357 | tracepoint_count = num; | |
4fa62494 | 11358 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
11359 | } |
11360 | ||
11361 | void | |
11362 | trace_command (char *arg, int from_tty) | |
11363 | { | |
8cdf0e15 VP |
11364 | if (create_breakpoint (get_current_arch (), |
11365 | arg, | |
11366 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11367 | 0 /* tempflag */, |
11368 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11369 | 0 /* Ignore count */, |
11370 | pending_break_support, | |
11371 | NULL, | |
11372 | from_tty, | |
84f4c1fe PM |
11373 | 1 /* enabled */, |
11374 | 0 /* internal */)) | |
fd9b8c24 | 11375 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
11376 | } |
11377 | ||
7a697b8d SS |
11378 | void |
11379 | ftrace_command (char *arg, int from_tty) | |
11380 | { | |
8cdf0e15 VP |
11381 | if (create_breakpoint (get_current_arch (), |
11382 | arg, | |
11383 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11384 | 0 /* tempflag */, |
11385 | bp_fast_tracepoint /* type_wanted */, | |
11386 | 0 /* Ignore count */, | |
11387 | pending_break_support, | |
11388 | NULL, | |
11389 | from_tty, | |
84f4c1fe PM |
11390 | 1 /* enabled */, |
11391 | 0 /* internal */)) | |
0fb4aa4b PA |
11392 | set_tracepoint_count (breakpoint_count); |
11393 | } | |
11394 | ||
11395 | /* strace command implementation. Creates a static tracepoint. */ | |
11396 | ||
11397 | void | |
11398 | strace_command (char *arg, int from_tty) | |
11399 | { | |
11400 | if (create_breakpoint (get_current_arch (), | |
11401 | arg, | |
11402 | NULL, 0, 1 /* parse arg */, | |
11403 | 0 /* tempflag */, | |
11404 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11405 | 0 /* Ignore count */, |
11406 | pending_break_support, | |
11407 | NULL, | |
11408 | from_tty, | |
84f4c1fe PM |
11409 | 1 /* enabled */, |
11410 | 0 /* internal */)) | |
fd9b8c24 | 11411 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
11412 | } |
11413 | ||
409873ef SS |
11414 | /* Set up a fake reader function that gets command lines from a linked |
11415 | list that was acquired during tracepoint uploading. */ | |
11416 | ||
11417 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 11418 | static int next_cmd; |
409873ef SS |
11419 | |
11420 | static char * | |
11421 | read_uploaded_action (void) | |
11422 | { | |
11423 | char *rslt; | |
11424 | ||
3149d8c1 | 11425 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 11426 | |
3149d8c1 | 11427 | next_cmd++; |
409873ef SS |
11428 | |
11429 | return rslt; | |
11430 | } | |
11431 | ||
00bf0b85 SS |
11432 | /* Given information about a tracepoint as recorded on a target (which |
11433 | can be either a live system or a trace file), attempt to create an | |
11434 | equivalent GDB tracepoint. This is not a reliable process, since | |
11435 | the target does not necessarily have all the information used when | |
11436 | the tracepoint was originally defined. */ | |
11437 | ||
11438 | struct breakpoint * | |
11439 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 11440 | { |
409873ef | 11441 | char *addr_str, small_buf[100]; |
d5551862 | 11442 | struct breakpoint *tp; |
fd9b8c24 | 11443 | |
409873ef SS |
11444 | if (utp->at_string) |
11445 | addr_str = utp->at_string; | |
11446 | else | |
11447 | { | |
11448 | /* In the absence of a source location, fall back to raw | |
11449 | address. Since there is no way to confirm that the address | |
11450 | means the same thing as when the trace was started, warn the | |
11451 | user. */ | |
3e43a32a MS |
11452 | warning (_("Uploaded tracepoint %d has no " |
11453 | "source location, using raw address"), | |
409873ef SS |
11454 | utp->number); |
11455 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
11456 | addr_str = small_buf; | |
11457 | } | |
11458 | ||
11459 | /* There's not much we can do with a sequence of bytecodes. */ | |
11460 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
11461 | warning (_("Uploaded tracepoint %d condition " |
11462 | "has no source form, ignoring it"), | |
409873ef | 11463 | utp->number); |
d5551862 | 11464 | |
8cdf0e15 | 11465 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
11466 | addr_str, |
11467 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 11468 | 0 /* tempflag */, |
0fb4aa4b | 11469 | utp->type /* type_wanted */, |
8cdf0e15 VP |
11470 | 0 /* Ignore count */, |
11471 | pending_break_support, | |
11472 | NULL, | |
11473 | 0 /* from_tty */, | |
84f4c1fe PM |
11474 | utp->enabled /* enabled */, |
11475 | 0 /* internal */)) | |
fd9b8c24 PA |
11476 | return NULL; |
11477 | ||
00bf0b85 SS |
11478 | set_tracepoint_count (breakpoint_count); |
11479 | ||
409873ef | 11480 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
11481 | tp = get_tracepoint (tracepoint_count); |
11482 | gdb_assert (tp != NULL); | |
d5551862 | 11483 | |
00bf0b85 SS |
11484 | if (utp->pass > 0) |
11485 | { | |
409873ef | 11486 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 11487 | |
409873ef | 11488 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
11489 | } |
11490 | ||
409873ef SS |
11491 | /* If we have uploaded versions of the original commands, set up a |
11492 | special-purpose "reader" function and call the usual command line | |
11493 | reader, then pass the result to the breakpoint command-setting | |
11494 | function. */ | |
3149d8c1 | 11495 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 11496 | { |
409873ef | 11497 | struct command_line *cmd_list; |
00bf0b85 | 11498 | |
409873ef | 11499 | this_utp = utp; |
3149d8c1 | 11500 | next_cmd = 0; |
d5551862 | 11501 | |
409873ef SS |
11502 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
11503 | ||
11504 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 11505 | } |
3149d8c1 SS |
11506 | else if (!VEC_empty (char_ptr, utp->actions) |
11507 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
11508 | warning (_("Uploaded tracepoint %d actions " |
11509 | "have no source form, ignoring them"), | |
409873ef | 11510 | utp->number); |
00bf0b85 SS |
11511 | |
11512 | return tp; | |
11513 | } | |
11514 | ||
1042e4c0 SS |
11515 | /* Print information on tracepoint number TPNUM_EXP, or all if |
11516 | omitted. */ | |
11517 | ||
11518 | static void | |
e5a67952 | 11519 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 11520 | { |
e5a67952 | 11521 | int num_printed; |
1042e4c0 | 11522 | |
e5a67952 | 11523 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
11524 | |
11525 | if (num_printed == 0) | |
1042e4c0 | 11526 | { |
e5a67952 | 11527 | if (args == NULL || *args == '\0') |
d77f58be SS |
11528 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
11529 | else | |
e5a67952 | 11530 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 11531 | } |
ad443146 SS |
11532 | |
11533 | default_collect_info (); | |
1042e4c0 SS |
11534 | } |
11535 | ||
4a64f543 | 11536 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
11537 | Not supported by all targets. */ |
11538 | static void | |
11539 | enable_trace_command (char *args, int from_tty) | |
11540 | { | |
11541 | enable_command (args, from_tty); | |
11542 | } | |
11543 | ||
4a64f543 | 11544 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
11545 | Not supported by all targets. */ |
11546 | static void | |
11547 | disable_trace_command (char *args, int from_tty) | |
11548 | { | |
11549 | disable_command (args, from_tty); | |
11550 | } | |
11551 | ||
4a64f543 | 11552 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
11553 | static void |
11554 | delete_trace_command (char *arg, int from_tty) | |
11555 | { | |
35df4500 | 11556 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
11557 | |
11558 | dont_repeat (); | |
11559 | ||
11560 | if (arg == 0) | |
11561 | { | |
11562 | int breaks_to_delete = 0; | |
11563 | ||
11564 | /* Delete all breakpoints if no argument. | |
11565 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
11566 | have to be deleted with an explicit breakpoint number |
11567 | argument. */ | |
1042e4c0 SS |
11568 | ALL_TRACEPOINTS (b) |
11569 | { | |
11570 | if (b->number >= 0) | |
11571 | { | |
11572 | breaks_to_delete = 1; | |
11573 | break; | |
11574 | } | |
11575 | } | |
11576 | ||
11577 | /* Ask user only if there are some breakpoints to delete. */ | |
11578 | if (!from_tty | |
11579 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
11580 | { | |
35df4500 | 11581 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
1042e4c0 | 11582 | { |
d77f58be | 11583 | if (is_tracepoint (b) |
059fb39f | 11584 | && b->number >= 0) |
1042e4c0 SS |
11585 | delete_breakpoint (b); |
11586 | } | |
11587 | } | |
11588 | } | |
11589 | else | |
95a42b64 | 11590 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
11591 | } |
11592 | ||
11593 | /* Set passcount for tracepoint. | |
11594 | ||
11595 | First command argument is passcount, second is tracepoint number. | |
11596 | If tracepoint number omitted, apply to most recently defined. | |
11597 | Also accepts special argument "all". */ | |
11598 | ||
11599 | static void | |
11600 | trace_pass_command (char *args, int from_tty) | |
11601 | { | |
11602 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
11603 | unsigned int count; | |
11604 | int all = 0; | |
11605 | ||
11606 | if (args == 0 || *args == 0) | |
3e43a32a MS |
11607 | error (_("passcount command requires an " |
11608 | "argument (count + optional TP num)")); | |
1042e4c0 | 11609 | |
4a64f543 | 11610 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
11611 | |
11612 | while (*args && isspace ((int) *args)) | |
11613 | args++; | |
11614 | ||
11615 | if (*args && strncasecmp (args, "all", 3) == 0) | |
11616 | { | |
11617 | args += 3; /* Skip special argument "all". */ | |
11618 | all = 1; | |
11619 | if (*args) | |
11620 | error (_("Junk at end of arguments.")); | |
11621 | } | |
11622 | else | |
11623 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
11624 | ||
11625 | do | |
11626 | { | |
11627 | if (t1) | |
11628 | { | |
11629 | ALL_TRACEPOINTS (t2) | |
11630 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
11631 | { | |
11632 | t2->pass_count = count; | |
11633 | observer_notify_tracepoint_modified (t2->number); | |
11634 | if (from_tty) | |
3e43a32a MS |
11635 | printf_filtered (_("Setting tracepoint %d's " |
11636 | "passcount to %d\n"), | |
1042e4c0 SS |
11637 | t2->number, count); |
11638 | } | |
11639 | if (! all && *args) | |
11640 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
11641 | } | |
11642 | } | |
11643 | while (*args); | |
11644 | } | |
11645 | ||
11646 | struct breakpoint * | |
11647 | get_tracepoint (int num) | |
11648 | { | |
11649 | struct breakpoint *t; | |
11650 | ||
11651 | ALL_TRACEPOINTS (t) | |
11652 | if (t->number == num) | |
11653 | return t; | |
11654 | ||
11655 | return NULL; | |
11656 | } | |
11657 | ||
d5551862 SS |
11658 | /* Find the tracepoint with the given target-side number (which may be |
11659 | different from the tracepoint number after disconnecting and | |
11660 | reconnecting). */ | |
11661 | ||
11662 | struct breakpoint * | |
11663 | get_tracepoint_by_number_on_target (int num) | |
11664 | { | |
11665 | struct breakpoint *t; | |
11666 | ||
11667 | ALL_TRACEPOINTS (t) | |
11668 | if (t->number_on_target == num) | |
11669 | return t; | |
11670 | ||
11671 | return NULL; | |
11672 | } | |
11673 | ||
1042e4c0 SS |
11674 | /* Utility: parse a tracepoint number and look it up in the list. |
11675 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
11676 | if OPTIONAL_P is true, then if the argument is missing, the most | |
11677 | recent tracepoint (tracepoint_count) is returned. */ | |
11678 | struct breakpoint * | |
11679 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
11680 | { | |
11681 | extern int tracepoint_count; | |
11682 | struct breakpoint *t; | |
11683 | int tpnum; | |
11684 | char *instring = arg == NULL ? NULL : *arg; | |
11685 | ||
11686 | if (arg == NULL || *arg == NULL || ! **arg) | |
11687 | { | |
11688 | if (optional_p) | |
11689 | tpnum = tracepoint_count; | |
11690 | else | |
11691 | error_no_arg (_("tracepoint number")); | |
11692 | } | |
11693 | else | |
11694 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
11695 | ||
11696 | if (tpnum <= 0) | |
11697 | { | |
11698 | if (instring && *instring) | |
11699 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
11700 | instring); | |
11701 | else | |
3e43a32a MS |
11702 | printf_filtered (_("Tracepoint argument missing " |
11703 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
11704 | return NULL; |
11705 | } | |
11706 | ||
11707 | ALL_TRACEPOINTS (t) | |
11708 | if (t->number == tpnum) | |
11709 | { | |
11710 | return t; | |
11711 | } | |
11712 | ||
11713 | /* FIXME: if we are in the middle of a range we don't want to give | |
11714 | a message. The current interface to get_number_or_range doesn't | |
11715 | allow us to discover this. */ | |
11716 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
11717 | return NULL; | |
11718 | } | |
11719 | ||
6149aea9 PA |
11720 | /* Save information on user settable breakpoints (watchpoints, etc) to |
11721 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
11722 | on each breakpoint and only include the ones for which it returns | |
11723 | non-zero. */ | |
11724 | ||
1042e4c0 | 11725 | static void |
6149aea9 PA |
11726 | save_breakpoints (char *filename, int from_tty, |
11727 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
11728 | { |
11729 | struct breakpoint *tp; | |
6149aea9 | 11730 | int any = 0; |
a7bdde9e | 11731 | char *pathname; |
1042e4c0 | 11732 | struct cleanup *cleanup; |
a7bdde9e | 11733 | struct ui_file *fp; |
6149aea9 | 11734 | int extra_trace_bits = 0; |
1042e4c0 | 11735 | |
6149aea9 PA |
11736 | if (filename == 0 || *filename == 0) |
11737 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
11738 | |
11739 | /* See if we have anything to save. */ | |
6149aea9 | 11740 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11741 | { |
6149aea9 | 11742 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11743 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
11744 | continue; |
11745 | ||
11746 | /* If we have a filter, only save the breakpoints it accepts. */ | |
11747 | if (filter && !filter (tp)) | |
11748 | continue; | |
11749 | ||
11750 | any = 1; | |
11751 | ||
11752 | if (is_tracepoint (tp)) | |
11753 | { | |
11754 | extra_trace_bits = 1; | |
11755 | ||
11756 | /* We can stop searching. */ | |
11757 | break; | |
11758 | } | |
1042e4c0 | 11759 | } |
6149aea9 PA |
11760 | |
11761 | if (!any) | |
1042e4c0 | 11762 | { |
6149aea9 | 11763 | warning (_("Nothing to save.")); |
1042e4c0 SS |
11764 | return; |
11765 | } | |
11766 | ||
6149aea9 | 11767 | pathname = tilde_expand (filename); |
1042e4c0 | 11768 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 11769 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 11770 | if (!fp) |
6149aea9 PA |
11771 | error (_("Unable to open file '%s' for saving (%s)"), |
11772 | filename, safe_strerror (errno)); | |
a7bdde9e | 11773 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 11774 | |
6149aea9 PA |
11775 | if (extra_trace_bits) |
11776 | save_trace_state_variables (fp); | |
8bf6485c | 11777 | |
6149aea9 | 11778 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11779 | { |
6149aea9 | 11780 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11781 | if (!user_breakpoint_p (tp)) |
6149aea9 | 11782 | continue; |
8bf6485c | 11783 | |
6149aea9 PA |
11784 | /* If we have a filter, only save the breakpoints it accepts. */ |
11785 | if (filter && !filter (tp)) | |
11786 | continue; | |
11787 | ||
11788 | if (tp->ops != NULL) | |
11789 | (tp->ops->print_recreate) (tp, fp); | |
1042e4c0 SS |
11790 | else |
11791 | { | |
6149aea9 PA |
11792 | if (tp->type == bp_fast_tracepoint) |
11793 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
11794 | if (tp->type == bp_static_tracepoint) |
11795 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
11796 | else if (tp->type == bp_tracepoint) |
11797 | fprintf_unfiltered (fp, "trace"); | |
11798 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11799 | fprintf_unfiltered (fp, "tbreak"); | |
11800 | else if (tp->type == bp_breakpoint) | |
11801 | fprintf_unfiltered (fp, "break"); | |
11802 | else if (tp->type == bp_hardware_breakpoint | |
11803 | && tp->disposition == disp_del) | |
11804 | fprintf_unfiltered (fp, "thbreak"); | |
11805 | else if (tp->type == bp_hardware_breakpoint) | |
11806 | fprintf_unfiltered (fp, "hbreak"); | |
11807 | else if (tp->type == bp_watchpoint) | |
11808 | fprintf_unfiltered (fp, "watch"); | |
11809 | else if (tp->type == bp_hardware_watchpoint) | |
11810 | fprintf_unfiltered (fp, "watch"); | |
11811 | else if (tp->type == bp_read_watchpoint) | |
11812 | fprintf_unfiltered (fp, "rwatch"); | |
11813 | else if (tp->type == bp_access_watchpoint) | |
11814 | fprintf_unfiltered (fp, "awatch"); | |
11815 | else | |
11816 | internal_error (__FILE__, __LINE__, | |
11817 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11818 | ||
11819 | if (tp->exp_string) | |
11820 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
11821 | else if (tp->addr_string) | |
11822 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
11823 | else | |
11824 | { | |
11825 | char tmp[40]; | |
11826 | ||
11827 | sprintf_vma (tmp, tp->loc->address); | |
11828 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
11829 | } | |
1042e4c0 SS |
11830 | } |
11831 | ||
6149aea9 PA |
11832 | if (tp->thread != -1) |
11833 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
11834 | ||
11835 | if (tp->task != 0) | |
11836 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
11837 | |
11838 | fprintf_unfiltered (fp, "\n"); | |
11839 | ||
6149aea9 PA |
11840 | /* Note, we can't rely on tp->number for anything, as we can't |
11841 | assume the recreated breakpoint numbers will match. Use $bpnum | |
11842 | instead. */ | |
11843 | ||
11844 | if (tp->cond_string) | |
11845 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
11846 | ||
11847 | if (tp->ignore_count) | |
11848 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
11849 | ||
1042e4c0 | 11850 | if (tp->pass_count) |
a7bdde9e | 11851 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 11852 | |
a7bdde9e | 11853 | if (tp->commands) |
1042e4c0 | 11854 | { |
a7bdde9e VP |
11855 | volatile struct gdb_exception ex; |
11856 | ||
6149aea9 | 11857 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
11858 | |
11859 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 11860 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 11861 | { |
9add0f1b | 11862 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
11863 | } |
11864 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 11865 | |
a7bdde9e VP |
11866 | if (ex.reason < 0) |
11867 | throw_exception (ex); | |
1042e4c0 | 11868 | |
a7bdde9e | 11869 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 11870 | } |
6149aea9 PA |
11871 | |
11872 | if (tp->enable_state == bp_disabled) | |
11873 | fprintf_unfiltered (fp, "disable\n"); | |
11874 | ||
11875 | /* If this is a multi-location breakpoint, check if the locations | |
11876 | should be individually disabled. Watchpoint locations are | |
11877 | special, and not user visible. */ | |
11878 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
11879 | { | |
11880 | struct bp_location *loc; | |
11881 | int n = 1; | |
11882 | ||
11883 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
11884 | if (!loc->enabled) | |
11885 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
11886 | } | |
1042e4c0 | 11887 | } |
8bf6485c | 11888 | |
6149aea9 | 11889 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
11890 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
11891 | ||
1042e4c0 SS |
11892 | do_cleanups (cleanup); |
11893 | if (from_tty) | |
6149aea9 PA |
11894 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
11895 | } | |
11896 | ||
11897 | /* The `save breakpoints' command. */ | |
11898 | ||
11899 | static void | |
11900 | save_breakpoints_command (char *args, int from_tty) | |
11901 | { | |
11902 | save_breakpoints (args, from_tty, NULL); | |
11903 | } | |
11904 | ||
11905 | /* The `save tracepoints' command. */ | |
11906 | ||
11907 | static void | |
11908 | save_tracepoints_command (char *args, int from_tty) | |
11909 | { | |
11910 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
11911 | } |
11912 | ||
11913 | /* Create a vector of all tracepoints. */ | |
11914 | ||
11915 | VEC(breakpoint_p) * | |
11916 | all_tracepoints () | |
11917 | { | |
11918 | VEC(breakpoint_p) *tp_vec = 0; | |
11919 | struct breakpoint *tp; | |
11920 | ||
11921 | ALL_TRACEPOINTS (tp) | |
11922 | { | |
11923 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
11924 | } | |
11925 | ||
11926 | return tp_vec; | |
11927 | } | |
11928 | ||
c906108c | 11929 | \f |
4a64f543 MS |
11930 | /* This help string is used for the break, hbreak, tbreak and thbreak |
11931 | commands. It is defined as a macro to prevent duplication. | |
11932 | COMMAND should be a string constant containing the name of the | |
11933 | command. */ | |
31e2b00f AS |
11934 | #define BREAK_ARGS_HELP(command) \ |
11935 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
11936 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
11937 | If a line number is specified, break at start of code for that line.\n\ | |
11938 | If a function is specified, break at start of code for that function.\n\ | |
11939 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
11940 | With no LOCATION, uses current execution address of the selected\n\ |
11941 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
11942 | \n\ |
11943 | THREADNUM is the number from \"info threads\".\n\ | |
11944 | CONDITION is a boolean expression.\n\ | |
11945 | \n\ | |
d41c0fc8 PA |
11946 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
11947 | conditions are different.\n\ | |
31e2b00f AS |
11948 | \n\ |
11949 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
11950 | ||
44feb3ce TT |
11951 | /* List of subcommands for "catch". */ |
11952 | static struct cmd_list_element *catch_cmdlist; | |
11953 | ||
11954 | /* List of subcommands for "tcatch". */ | |
11955 | static struct cmd_list_element *tcatch_cmdlist; | |
11956 | ||
11957 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
11958 | lists, and pass some additional user data to the command function. */ | |
11959 | static void | |
11960 | add_catch_command (char *name, char *docstring, | |
11961 | void (*sfunc) (char *args, int from_tty, | |
11962 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
11963 | char **(*completer) (struct cmd_list_element *cmd, |
11964 | char *text, char *word), | |
44feb3ce TT |
11965 | void *user_data_catch, |
11966 | void *user_data_tcatch) | |
11967 | { | |
11968 | struct cmd_list_element *command; | |
11969 | ||
11970 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
11971 | &catch_cmdlist); | |
11972 | set_cmd_sfunc (command, sfunc); | |
11973 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 11974 | set_cmd_completer (command, completer); |
44feb3ce TT |
11975 | |
11976 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
11977 | &tcatch_cmdlist); | |
11978 | set_cmd_sfunc (command, sfunc); | |
11979 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 11980 | set_cmd_completer (command, completer); |
44feb3ce TT |
11981 | } |
11982 | ||
6c95b8df | 11983 | static void |
a79b8f6e | 11984 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 11985 | { |
6c95b8df PA |
11986 | inf->total_syscalls_count = 0; |
11987 | inf->any_syscall_count = 0; | |
11988 | VEC_free (int, inf->syscalls_counts); | |
11989 | } | |
11990 | ||
6149aea9 PA |
11991 | static void |
11992 | save_command (char *arg, int from_tty) | |
11993 | { | |
3e43a32a MS |
11994 | printf_unfiltered (_("\"save\" must be followed by " |
11995 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
11996 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
11997 | } | |
11998 | ||
84f4c1fe PM |
11999 | struct breakpoint * |
12000 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
12001 | void *data) | |
12002 | { | |
35df4500 | 12003 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 12004 | |
35df4500 | 12005 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
12006 | { |
12007 | if ((*callback) (b, data)) | |
12008 | return b; | |
12009 | } | |
12010 | ||
12011 | return NULL; | |
12012 | } | |
12013 | ||
c906108c | 12014 | void |
fba45db2 | 12015 | _initialize_breakpoint (void) |
c906108c SS |
12016 | { |
12017 | struct cmd_list_element *c; | |
12018 | ||
84acb35a | 12019 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 12020 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 12021 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 12022 | |
17450429 PP |
12023 | breakpoint_objfile_key = register_objfile_data (); |
12024 | ||
c906108c SS |
12025 | breakpoint_chain = 0; |
12026 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
12027 | before a breakpoint is set. */ | |
12028 | breakpoint_count = 0; | |
12029 | ||
1042e4c0 SS |
12030 | tracepoint_count = 0; |
12031 | ||
1bedd215 AC |
12032 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
12033 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
12034 | Usage is `ignore N COUNT'.")); | |
c906108c | 12035 | if (xdb_commands) |
c5aa993b | 12036 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 12037 | |
1bedd215 AC |
12038 | add_com ("commands", class_breakpoint, commands_command, _("\ |
12039 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
12040 | Give breakpoint number as argument after \"commands\".\n\ |
12041 | With no argument, the targeted breakpoint is the last one set.\n\ | |
12042 | The commands themselves follow starting on the next line.\n\ | |
12043 | Type a line containing \"end\" to indicate the end of them.\n\ | |
12044 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 12045 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 12046 | |
1bedd215 AC |
12047 | add_com ("condition", class_breakpoint, condition_command, _("\ |
12048 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 12049 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 12050 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 12051 | |
1bedd215 | 12052 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 12053 | Set a temporary breakpoint.\n\ |
c906108c SS |
12054 | Like \"break\" except the breakpoint is only temporary,\n\ |
12055 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
12056 | by using \"enable delete\" on the breakpoint number.\n\ |
12057 | \n" | |
12058 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 12059 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12060 | |
1bedd215 | 12061 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 12062 | Set a hardware assisted breakpoint.\n\ |
c906108c | 12063 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
12064 | some target hardware may not have this support.\n\ |
12065 | \n" | |
12066 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 12067 | set_cmd_completer (c, location_completer); |
c906108c | 12068 | |
1bedd215 | 12069 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 12070 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 12071 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
12072 | so it will be deleted when hit.\n\ |
12073 | \n" | |
12074 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 12075 | set_cmd_completer (c, location_completer); |
c906108c | 12076 | |
1bedd215 AC |
12077 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
12078 | Enable some breakpoints.\n\ | |
c906108c SS |
12079 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12080 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12081 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12082 | With a subcommand you can enable temporarily."), |
c906108c SS |
12083 | &enablelist, "enable ", 1, &cmdlist); |
12084 | if (xdb_commands) | |
1bedd215 AC |
12085 | add_com ("ab", class_breakpoint, enable_command, _("\ |
12086 | Enable some breakpoints.\n\ | |
c906108c SS |
12087 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12088 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12089 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12090 | With a subcommand you can enable temporarily.")); |
c906108c SS |
12091 | |
12092 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
12093 | ||
84951ab5 | 12094 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 12095 | Enable some breakpoints.\n\ |
c906108c SS |
12096 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12097 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12098 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 12099 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 12100 | |
1a966eab AC |
12101 | add_cmd ("once", no_class, enable_once_command, _("\ |
12102 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12103 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12104 | &enablebreaklist); |
12105 | ||
1a966eab AC |
12106 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12107 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12108 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12109 | &enablebreaklist); |
12110 | ||
1a966eab AC |
12111 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12112 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12113 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12114 | &enablelist); |
12115 | ||
1a966eab AC |
12116 | add_cmd ("once", no_class, enable_once_command, _("\ |
12117 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12118 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12119 | &enablelist); |
12120 | ||
1bedd215 AC |
12121 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
12122 | Disable some breakpoints.\n\ | |
c906108c SS |
12123 | Arguments are breakpoint numbers with spaces in between.\n\ |
12124 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12125 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
12126 | &disablelist, "disable ", 1, &cmdlist); |
12127 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
12128 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
12129 | if (xdb_commands) | |
1bedd215 AC |
12130 | add_com ("sb", class_breakpoint, disable_command, _("\ |
12131 | Disable some breakpoints.\n\ | |
c906108c SS |
12132 | Arguments are breakpoint numbers with spaces in between.\n\ |
12133 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12134 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 12135 | |
1a966eab AC |
12136 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
12137 | Disable some breakpoints.\n\ | |
c906108c SS |
12138 | Arguments are breakpoint numbers with spaces in between.\n\ |
12139 | To disable all breakpoints, give no argument.\n\ | |
12140 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 12141 | This command may be abbreviated \"disable\"."), |
c906108c SS |
12142 | &disablelist); |
12143 | ||
1bedd215 AC |
12144 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
12145 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12146 | Arguments are breakpoint numbers with spaces in between.\n\ |
12147 | To delete all breakpoints, give no argument.\n\ | |
12148 | \n\ | |
12149 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 12150 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
12151 | &deletelist, "delete ", 1, &cmdlist); |
12152 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 12153 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 12154 | if (xdb_commands) |
1bedd215 AC |
12155 | add_com ("db", class_breakpoint, delete_command, _("\ |
12156 | Delete some breakpoints.\n\ | |
c906108c | 12157 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 12158 | To delete all breakpoints, give no argument.\n")); |
c906108c | 12159 | |
1a966eab AC |
12160 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
12161 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12162 | Arguments are breakpoint numbers with spaces in between.\n\ |
12163 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 12164 | This command may be abbreviated \"delete\"."), |
c906108c SS |
12165 | &deletelist); |
12166 | ||
1bedd215 AC |
12167 | add_com ("clear", class_breakpoint, clear_command, _("\ |
12168 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
12169 | Argument may be line number, function name, or \"*\" and an address.\n\ |
12170 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
12171 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
12172 | If an address is specified, breakpoints at that address are cleared.\n\ |
12173 | \n\ | |
12174 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
12175 | is executing in.\n\ |
12176 | \n\ | |
1bedd215 | 12177 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 12178 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 12179 | |
1bedd215 | 12180 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
12181 | Set breakpoint at specified line or function.\n" |
12182 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 12183 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12184 | |
c906108c SS |
12185 | add_com_alias ("b", "break", class_run, 1); |
12186 | add_com_alias ("br", "break", class_run, 1); | |
12187 | add_com_alias ("bre", "break", class_run, 1); | |
12188 | add_com_alias ("brea", "break", class_run, 1); | |
12189 | ||
7681d515 PM |
12190 | if (xdb_commands) |
12191 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
12192 | |
12193 | if (dbx_commands) | |
12194 | { | |
1bedd215 AC |
12195 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
12196 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
12197 | &stoplist, "stop ", 1, &cmdlist); |
12198 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 12199 | _("Break in function or address."), &stoplist); |
c5aa993b | 12200 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 12201 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
12202 | add_com ("status", class_info, breakpoints_info, _("\ |
12203 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12204 | The \"Type\" column indicates one of:\n\ |
12205 | \tbreakpoint - normal breakpoint\n\ | |
12206 | \twatchpoint - watchpoint\n\ | |
12207 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12208 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12209 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12210 | address and file/line number respectively.\n\ |
12211 | \n\ | |
12212 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12213 | are set to the address of the last breakpoint listed unless the command\n\ |
12214 | is prefixed with \"server \".\n\n\ | |
c906108c | 12215 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12216 | breakpoint set.")); |
c906108c SS |
12217 | } |
12218 | ||
1bedd215 | 12219 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 12220 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
12221 | The \"Type\" column indicates one of:\n\ |
12222 | \tbreakpoint - normal breakpoint\n\ | |
12223 | \twatchpoint - watchpoint\n\ | |
12224 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12225 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12226 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12227 | address and file/line number respectively.\n\ |
12228 | \n\ | |
12229 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12230 | are set to the address of the last breakpoint listed unless the command\n\ |
12231 | is prefixed with \"server \".\n\n\ | |
c906108c | 12232 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12233 | breakpoint set.")); |
c906108c | 12234 | |
6b04bdb7 MS |
12235 | add_info_alias ("b", "breakpoints", 1); |
12236 | ||
c906108c | 12237 | if (xdb_commands) |
1bedd215 AC |
12238 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
12239 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12240 | The \"Type\" column indicates one of:\n\ |
12241 | \tbreakpoint - normal breakpoint\n\ | |
12242 | \twatchpoint - watchpoint\n\ | |
12243 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12244 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12245 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12246 | address and file/line number respectively.\n\ |
12247 | \n\ | |
12248 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12249 | are set to the address of the last breakpoint listed unless the command\n\ |
12250 | is prefixed with \"server \".\n\n\ | |
c906108c | 12251 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12252 | breakpoint set.")); |
c906108c | 12253 | |
1a966eab AC |
12254 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
12255 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12256 | The \"Type\" column indicates one of:\n\ |
12257 | \tbreakpoint - normal breakpoint\n\ | |
12258 | \twatchpoint - watchpoint\n\ | |
12259 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
12260 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
12261 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
12262 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
12263 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
12264 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
12265 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
12266 | address and file/line number respectively.\n\ |
12267 | \n\ | |
12268 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12269 | are set to the address of the last breakpoint listed unless the command\n\ |
12270 | is prefixed with \"server \".\n\n\ | |
c906108c | 12271 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 12272 | breakpoint set."), |
c906108c SS |
12273 | &maintenanceinfolist); |
12274 | ||
44feb3ce TT |
12275 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
12276 | Set catchpoints to catch events."), | |
12277 | &catch_cmdlist, "catch ", | |
12278 | 0/*allow-unknown*/, &cmdlist); | |
12279 | ||
12280 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
12281 | Set temporary catchpoints to catch events."), | |
12282 | &tcatch_cmdlist, "tcatch ", | |
12283 | 0/*allow-unknown*/, &cmdlist); | |
12284 | ||
12285 | /* Add catch and tcatch sub-commands. */ | |
12286 | add_catch_command ("catch", _("\ | |
12287 | Catch an exception, when caught.\n\ | |
12288 | With an argument, catch only exceptions with the given name."), | |
12289 | catch_catch_command, | |
a96d9b2e | 12290 | NULL, |
44feb3ce TT |
12291 | CATCH_PERMANENT, |
12292 | CATCH_TEMPORARY); | |
12293 | add_catch_command ("throw", _("\ | |
12294 | Catch an exception, when thrown.\n\ | |
12295 | With an argument, catch only exceptions with the given name."), | |
12296 | catch_throw_command, | |
a96d9b2e | 12297 | NULL, |
44feb3ce TT |
12298 | CATCH_PERMANENT, |
12299 | CATCH_TEMPORARY); | |
12300 | add_catch_command ("fork", _("Catch calls to fork."), | |
12301 | catch_fork_command_1, | |
a96d9b2e | 12302 | NULL, |
44feb3ce TT |
12303 | (void *) (uintptr_t) catch_fork_permanent, |
12304 | (void *) (uintptr_t) catch_fork_temporary); | |
12305 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
12306 | catch_fork_command_1, | |
a96d9b2e | 12307 | NULL, |
44feb3ce TT |
12308 | (void *) (uintptr_t) catch_vfork_permanent, |
12309 | (void *) (uintptr_t) catch_vfork_temporary); | |
12310 | add_catch_command ("exec", _("Catch calls to exec."), | |
12311 | catch_exec_command_1, | |
a96d9b2e SDJ |
12312 | NULL, |
12313 | CATCH_PERMANENT, | |
12314 | CATCH_TEMPORARY); | |
12315 | add_catch_command ("syscall", _("\ | |
12316 | Catch system calls by their names and/or numbers.\n\ | |
12317 | Arguments say which system calls to catch. If no arguments\n\ | |
12318 | are given, every system call will be caught.\n\ | |
12319 | Arguments, if given, should be one or more system call names\n\ | |
12320 | (if your system supports that), or system call numbers."), | |
12321 | catch_syscall_command_1, | |
12322 | catch_syscall_completer, | |
44feb3ce TT |
12323 | CATCH_PERMANENT, |
12324 | CATCH_TEMPORARY); | |
44feb3ce TT |
12325 | add_catch_command ("exception", _("\ |
12326 | Catch Ada exceptions, when raised.\n\ | |
12327 | With an argument, catch only exceptions with the given name."), | |
12328 | catch_ada_exception_command, | |
a96d9b2e | 12329 | NULL, |
44feb3ce TT |
12330 | CATCH_PERMANENT, |
12331 | CATCH_TEMPORARY); | |
12332 | add_catch_command ("assert", _("\ | |
12333 | Catch failed Ada assertions, when raised.\n\ | |
12334 | With an argument, catch only exceptions with the given name."), | |
12335 | catch_assert_command, | |
a96d9b2e | 12336 | NULL, |
44feb3ce TT |
12337 | CATCH_PERMANENT, |
12338 | CATCH_TEMPORARY); | |
c5aa993b | 12339 | |
1bedd215 AC |
12340 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
12341 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12342 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 12343 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12344 | an expression changes.\n\ |
12345 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12346 | the memory to which it refers.")); | |
65d12d83 | 12347 | set_cmd_completer (c, expression_completer); |
c906108c | 12348 | |
1bedd215 AC |
12349 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
12350 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 12351 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 12352 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12353 | an expression is read.\n\ |
12354 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12355 | the memory to which it refers.")); | |
65d12d83 | 12356 | set_cmd_completer (c, expression_completer); |
c906108c | 12357 | |
1bedd215 AC |
12358 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
12359 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12360 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 12361 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12362 | an expression is either read or written.\n\ |
12363 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12364 | the memory to which it refers.")); | |
65d12d83 | 12365 | set_cmd_completer (c, expression_completer); |
c906108c | 12366 | |
d77f58be | 12367 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 12368 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 12369 | |
920d2a44 AC |
12370 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
12371 | respond to changes - contrary to the description. */ | |
85c07804 AC |
12372 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
12373 | &can_use_hw_watchpoints, _("\ | |
12374 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
12375 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
12376 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
12377 | such is available. (However, any hardware watchpoints that were\n\ | |
12378 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
12379 | hardware.)"), |
12380 | NULL, | |
920d2a44 | 12381 | show_can_use_hw_watchpoints, |
85c07804 | 12382 | &setlist, &showlist); |
c906108c SS |
12383 | |
12384 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 12385 | |
1042e4c0 SS |
12386 | /* Tracepoint manipulation commands. */ |
12387 | ||
12388 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
12389 | Set a tracepoint at specified line or function.\n\ | |
12390 | \n" | |
12391 | BREAK_ARGS_HELP ("trace") "\n\ | |
12392 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12393 | set_cmd_completer (c, location_completer); | |
12394 | ||
12395 | add_com_alias ("tp", "trace", class_alias, 0); | |
12396 | add_com_alias ("tr", "trace", class_alias, 1); | |
12397 | add_com_alias ("tra", "trace", class_alias, 1); | |
12398 | add_com_alias ("trac", "trace", class_alias, 1); | |
12399 | ||
7a697b8d SS |
12400 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
12401 | Set a fast tracepoint at specified line or function.\n\ | |
12402 | \n" | |
12403 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
12404 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12405 | set_cmd_completer (c, location_completer); | |
12406 | ||
0fb4aa4b PA |
12407 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
12408 | Set a static tracepoint at specified line, function or marker.\n\ | |
12409 | \n\ | |
12410 | strace [LOCATION] [if CONDITION]\n\ | |
12411 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
12412 | or -m MARKER_ID.\n\ | |
12413 | If a line number is specified, probe the marker at start of code\n\ | |
12414 | for that line. If a function is specified, probe the marker at start\n\ | |
12415 | of code for that function. If an address is specified, probe the marker\n\ | |
12416 | at that exact address. If a marker id is specified, probe the marker\n\ | |
12417 | with that name. With no LOCATION, uses current execution address of\n\ | |
12418 | the selected stack frame.\n\ | |
12419 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
12420 | This collects arbitrary user data passed in the probe point call to the\n\ | |
12421 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
12422 | by printing the $_sdata variable like any other convenience variable.\n\ | |
12423 | \n\ | |
12424 | CONDITION is a boolean expression.\n\ | |
12425 | \n\ | |
d41c0fc8 PA |
12426 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
12427 | conditions are different.\n\ | |
0fb4aa4b PA |
12428 | \n\ |
12429 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
12430 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12431 | set_cmd_completer (c, location_completer); | |
12432 | ||
1042e4c0 | 12433 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 12434 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
12435 | Convenience variable \"$tpnum\" contains the number of the\n\ |
12436 | last tracepoint set.")); | |
12437 | ||
12438 | add_info_alias ("tp", "tracepoints", 1); | |
12439 | ||
12440 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
12441 | Delete specified tracepoints.\n\ | |
12442 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12443 | No argument means delete all tracepoints."), | |
12444 | &deletelist); | |
12445 | ||
12446 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
12447 | Disable specified tracepoints.\n\ | |
12448 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12449 | No argument means disable all tracepoints."), | |
12450 | &disablelist); | |
12451 | deprecate_cmd (c, "disable"); | |
12452 | ||
12453 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
12454 | Enable specified tracepoints.\n\ | |
12455 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12456 | No argument means enable all tracepoints."), | |
12457 | &enablelist); | |
12458 | deprecate_cmd (c, "enable"); | |
12459 | ||
12460 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
12461 | Set the passcount for a tracepoint.\n\ | |
12462 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
12463 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
12464 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
12465 | ||
6149aea9 PA |
12466 | add_prefix_cmd ("save", class_breakpoint, save_command, |
12467 | _("Save breakpoint definitions as a script."), | |
12468 | &save_cmdlist, "save ", | |
12469 | 0/*allow-unknown*/, &cmdlist); | |
12470 | ||
12471 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
12472 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 12473 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
12474 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
12475 | session to restore them."), | |
12476 | &save_cmdlist); | |
12477 | set_cmd_completer (c, filename_completer); | |
12478 | ||
12479 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 12480 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
12481 | Use the 'source' command in another debug session to restore them."), |
12482 | &save_cmdlist); | |
1042e4c0 SS |
12483 | set_cmd_completer (c, filename_completer); |
12484 | ||
6149aea9 PA |
12485 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
12486 | deprecate_cmd (c, "save tracepoints"); | |
12487 | ||
1bedd215 | 12488 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12489 | Breakpoint specific settings\n\ |
12490 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12491 | pending breakpoint behavior"), |
fa8d40ab JJ |
12492 | &breakpoint_set_cmdlist, "set breakpoint ", |
12493 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 12494 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12495 | Breakpoint specific settings\n\ |
12496 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12497 | pending breakpoint behavior"), |
fa8d40ab JJ |
12498 | &breakpoint_show_cmdlist, "show breakpoint ", |
12499 | 0/*allow-unknown*/, &showlist); | |
12500 | ||
7915a72c AC |
12501 | add_setshow_auto_boolean_cmd ("pending", no_class, |
12502 | &pending_break_support, _("\ | |
12503 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
12504 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
12505 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
12506 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
12507 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 12508 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 12509 | NULL, |
920d2a44 | 12510 | show_pending_break_support, |
6e1d7d6c AC |
12511 | &breakpoint_set_cmdlist, |
12512 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
12513 | |
12514 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
12515 | |
12516 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
12517 | &automatic_hardware_breakpoints, _("\ | |
12518 | Set automatic usage of hardware breakpoints."), _("\ | |
12519 | Show automatic usage of hardware breakpoints."), _("\ | |
12520 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
12521 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
12522 | a warning will be emitted for such breakpoints."), | |
12523 | NULL, | |
12524 | show_automatic_hardware_breakpoints, | |
12525 | &breakpoint_set_cmdlist, | |
12526 | &breakpoint_show_cmdlist); | |
74960c60 | 12527 | |
33e5cbd6 PA |
12528 | add_setshow_enum_cmd ("always-inserted", class_support, |
12529 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
12530 | Set mode for inserting breakpoints."), _("\ |
12531 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
12532 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
12533 | resumed, and removed when execution stops. When this mode is on,\n\ | |
12534 | breakpoints are inserted immediately and removed only when the user\n\ | |
12535 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
12536 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
12537 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
12538 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
12539 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
12540 | NULL, |
12541 | &show_always_inserted_mode, | |
12542 | &breakpoint_set_cmdlist, | |
12543 | &breakpoint_show_cmdlist); | |
765dc015 VP |
12544 | |
12545 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
12546 | |
12547 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 12548 | } |