Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
7b6bb8da | 5 | 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
a6d9a66e | 23 | #include "arch-utils.h" |
c906108c | 24 | #include <ctype.h> |
776592bf | 25 | #include "hashtab.h" |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
1042e4c0 | 29 | #include "tracepoint.h" |
c906108c SS |
30 | #include "gdbtypes.h" |
31 | #include "expression.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "value.h" | |
35 | #include "command.h" | |
36 | #include "inferior.h" | |
37 | #include "gdbthread.h" | |
38 | #include "target.h" | |
39 | #include "language.h" | |
40 | #include "gdb_string.h" | |
41 | #include "demangle.h" | |
0ba1096a | 42 | #include "filenames.h" |
c906108c SS |
43 | #include "annotate.h" |
44 | #include "symfile.h" | |
45 | #include "objfiles.h" | |
0378c332 | 46 | #include "source.h" |
c5f0f3d0 | 47 | #include "linespec.h" |
c94fdfd0 | 48 | #include "completer.h" |
5b7f31a4 | 49 | #include "gdb.h" |
8b93c638 | 50 | #include "ui-out.h" |
e1507482 | 51 | #include "cli/cli-script.h" |
0225421b | 52 | #include "gdb_assert.h" |
fe898f56 | 53 | #include "block.h" |
a77053c2 | 54 | #include "solib.h" |
84acb35a JJ |
55 | #include "solist.h" |
56 | #include "observer.h" | |
60250e8b | 57 | #include "exceptions.h" |
765dc015 | 58 | #include "memattr.h" |
f7f9143b | 59 | #include "ada-lang.h" |
d1aa2f50 | 60 | #include "top.h" |
fa4727a6 | 61 | #include "wrapper.h" |
79a45b7d | 62 | #include "valprint.h" |
4efc6507 | 63 | #include "jit.h" |
a96d9b2e | 64 | #include "xml-syscall.h" |
65d79d4b | 65 | #include "parser-defs.h" |
e9cafbcc | 66 | #include "cli/cli-utils.h" |
c906108c | 67 | |
1042e4c0 SS |
68 | /* readline include files */ |
69 | #include "readline/readline.h" | |
70 | #include "readline/history.h" | |
71 | ||
72 | /* readline defines this. */ | |
73 | #undef savestring | |
74 | ||
034dad6f | 75 | #include "mi/mi-common.h" |
7371cf6d | 76 | #include "python/python.h" |
104c1213 | 77 | |
44feb3ce TT |
78 | /* Arguments to pass as context to some catch command handlers. */ |
79 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
80 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 81 | |
4a64f543 | 82 | /* Prototypes for local functions. */ |
c906108c | 83 | |
a14ed312 | 84 | static void enable_delete_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void enable_once_command (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void disable_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void enable_command (char *, int); |
c906108c | 91 | |
95a42b64 TT |
92 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
93 | void *), | |
94 | void *); | |
c906108c | 95 | |
a14ed312 | 96 | static void ignore_command (char *, int); |
c906108c | 97 | |
4efb68b1 | 98 | static int breakpoint_re_set_one (void *); |
c906108c | 99 | |
a14ed312 | 100 | static void clear_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void catch_command (char *, int); |
c906108c | 103 | |
e09342b5 | 104 | static int can_use_hardware_watchpoint (struct value *, int); |
c906108c | 105 | |
98deb0da | 106 | static void break_command_1 (char *, int, int); |
c906108c | 107 | |
a14ed312 | 108 | static void mention (struct breakpoint *); |
c906108c | 109 | |
4a64f543 MS |
110 | /* This function is used in gdbtk sources and thus can not be made |
111 | static. */ | |
63c252f8 | 112 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
a6d9a66e UW |
113 | struct symtab_and_line, |
114 | enum bptype); | |
c906108c | 115 | |
76897487 KB |
116 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
117 | ||
a6d9a66e UW |
118 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
119 | CORE_ADDR bpaddr, | |
88f7da05 | 120 | enum bptype bptype); |
76897487 | 121 | |
6c95b8df PA |
122 | static void describe_other_breakpoints (struct gdbarch *, |
123 | struct program_space *, CORE_ADDR, | |
5af949e3 | 124 | struct obj_section *, int); |
c906108c | 125 | |
6c95b8df PA |
126 | static int breakpoint_address_match (struct address_space *aspace1, |
127 | CORE_ADDR addr1, | |
128 | struct address_space *aspace2, | |
129 | CORE_ADDR addr2); | |
130 | ||
85d721b8 PA |
131 | static int watchpoint_locations_match (struct bp_location *loc1, |
132 | struct bp_location *loc2); | |
133 | ||
a14ed312 | 134 | static void breakpoints_info (char *, int); |
c906108c | 135 | |
d77f58be SS |
136 | static void watchpoints_info (char *, int); |
137 | ||
e5a67952 MS |
138 | static int breakpoint_1 (char *, int, |
139 | int (*) (const struct breakpoint *)); | |
c906108c | 140 | |
4efb68b1 | 141 | static int breakpoint_cond_eval (void *); |
c906108c | 142 | |
4efb68b1 | 143 | static void cleanup_executing_breakpoints (void *); |
c906108c | 144 | |
a14ed312 | 145 | static void commands_command (char *, int); |
c906108c | 146 | |
a14ed312 | 147 | static void condition_command (char *, int); |
c906108c | 148 | |
c5aa993b JM |
149 | typedef enum |
150 | { | |
151 | mark_inserted, | |
152 | mark_uninserted | |
153 | } | |
154 | insertion_state_t; | |
c906108c | 155 | |
0bde7532 | 156 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 157 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 158 | |
a14ed312 | 159 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
160 | |
161 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 162 | |
4efb68b1 | 163 | static int watchpoint_check (void *); |
c906108c | 164 | |
a14ed312 | 165 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 166 | |
a14ed312 | 167 | static int hw_breakpoint_used_count (void); |
c906108c | 168 | |
a14ed312 | 169 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 170 | |
a14ed312 | 171 | static void hbreak_command (char *, int); |
c906108c | 172 | |
a14ed312 | 173 | static void thbreak_command (char *, int); |
c906108c | 174 | |
a14ed312 | 175 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 176 | |
a14ed312 | 177 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 178 | |
a14ed312 | 179 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 180 | |
a14ed312 | 181 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 182 | |
a14ed312 | 183 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 184 | |
d85310f7 MS |
185 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
186 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 187 | |
a14ed312 | 188 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 189 | |
d03285ec UW |
190 | static void detach_single_step_breakpoints (void); |
191 | ||
6c95b8df PA |
192 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
193 | CORE_ADDR pc); | |
1aafd4da | 194 | |
fe3f5fa8 | 195 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
196 | static void incref_bp_location (struct bp_location *loc); |
197 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 198 | |
39d61571 | 199 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 200 | |
b60e7edf | 201 | static void update_global_location_list (int); |
a5606eee | 202 | |
b60e7edf | 203 | static void update_global_location_list_nothrow (int); |
74960c60 | 204 | |
d77f58be | 205 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 | 206 | |
d77f58be | 207 | static int is_watchpoint (const struct breakpoint *bpt); |
60e1c644 | 208 | |
74960c60 | 209 | static void insert_breakpoint_locations (void); |
a5606eee | 210 | |
a96d9b2e SDJ |
211 | static int syscall_catchpoint_p (struct breakpoint *b); |
212 | ||
1042e4c0 SS |
213 | static void tracepoints_info (char *, int); |
214 | ||
215 | static void delete_trace_command (char *, int); | |
216 | ||
217 | static void enable_trace_command (char *, int); | |
218 | ||
219 | static void disable_trace_command (char *, int); | |
220 | ||
221 | static void trace_pass_command (char *, int); | |
222 | ||
0fb4aa4b PA |
223 | /* Assuming we're creating a static tracepoint, does S look like a |
224 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
225 | #define is_marker_spec(s) \ | |
f5a8e22b | 226 | (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) |
0fb4aa4b | 227 | |
5cea2a26 PA |
228 | /* A reference-counted struct command_line. This lets multiple |
229 | breakpoints share a single command list. */ | |
230 | struct counted_command_line | |
231 | { | |
232 | /* The reference count. */ | |
233 | int refc; | |
234 | ||
235 | /* The command list. */ | |
236 | struct command_line *commands; | |
237 | }; | |
238 | ||
239 | struct command_line * | |
240 | breakpoint_commands (struct breakpoint *b) | |
241 | { | |
242 | return b->commands ? b->commands->commands : NULL; | |
243 | } | |
3daf8fe5 | 244 | |
f3b1572e PA |
245 | /* Flag indicating that a command has proceeded the inferior past the |
246 | current breakpoint. */ | |
247 | ||
248 | static int breakpoint_proceeded; | |
249 | ||
2cec12e5 AR |
250 | static const char * |
251 | bpdisp_text (enum bpdisp disp) | |
252 | { | |
4a64f543 MS |
253 | /* NOTE: the following values are a part of MI protocol and |
254 | represent values of 'disp' field returned when inferior stops at | |
255 | a breakpoint. */ | |
bc043ef3 | 256 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 257 | |
2cec12e5 AR |
258 | return bpdisps[(int) disp]; |
259 | } | |
c906108c | 260 | |
4a64f543 | 261 | /* Prototypes for exported functions. */ |
c906108c | 262 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 263 | if such is available. */ |
c906108c SS |
264 | static int can_use_hw_watchpoints; |
265 | ||
920d2a44 AC |
266 | static void |
267 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
268 | struct cmd_list_element *c, | |
269 | const char *value) | |
270 | { | |
3e43a32a MS |
271 | fprintf_filtered (file, |
272 | _("Debugger's willingness to use " | |
273 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
274 | value); |
275 | } | |
276 | ||
fa8d40ab JJ |
277 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
278 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 279 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
280 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
281 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
282 | static void |
283 | show_pending_break_support (struct ui_file *file, int from_tty, | |
284 | struct cmd_list_element *c, | |
285 | const char *value) | |
286 | { | |
3e43a32a MS |
287 | fprintf_filtered (file, |
288 | _("Debugger's behavior regarding " | |
289 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
290 | value); |
291 | } | |
fa8d40ab | 292 | |
765dc015 | 293 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 294 | set with "break" but falling in read-only memory. |
765dc015 VP |
295 | If 0, gdb will warn about such breakpoints, but won't automatically |
296 | use hardware breakpoints. */ | |
297 | static int automatic_hardware_breakpoints; | |
298 | static void | |
299 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
300 | struct cmd_list_element *c, | |
301 | const char *value) | |
302 | { | |
3e43a32a MS |
303 | fprintf_filtered (file, |
304 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
305 | value); |
306 | } | |
307 | ||
33e5cbd6 PA |
308 | /* If on, gdb will keep breakpoints inserted even as inferior is |
309 | stopped, and immediately insert any new breakpoints. If off, gdb | |
310 | will insert breakpoints into inferior only when resuming it, and | |
311 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
312 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
313 | ||
314 | static const char always_inserted_auto[] = "auto"; | |
315 | static const char always_inserted_on[] = "on"; | |
316 | static const char always_inserted_off[] = "off"; | |
317 | static const char *always_inserted_enums[] = { | |
318 | always_inserted_auto, | |
319 | always_inserted_off, | |
320 | always_inserted_on, | |
321 | NULL | |
322 | }; | |
323 | static const char *always_inserted_mode = always_inserted_auto; | |
324 | static void | |
74960c60 | 325 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 326 | struct cmd_list_element *c, const char *value) |
74960c60 | 327 | { |
33e5cbd6 | 328 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
329 | fprintf_filtered (file, |
330 | _("Always inserted breakpoint " | |
331 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
332 | value, |
333 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
334 | else | |
3e43a32a MS |
335 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
336 | value); | |
74960c60 VP |
337 | } |
338 | ||
33e5cbd6 PA |
339 | int |
340 | breakpoints_always_inserted_mode (void) | |
341 | { | |
342 | return (always_inserted_mode == always_inserted_on | |
343 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
344 | } | |
765dc015 | 345 | |
a14ed312 | 346 | void _initialize_breakpoint (void); |
c906108c | 347 | |
c906108c SS |
348 | /* Are we executing breakpoint commands? */ |
349 | static int executing_breakpoint_commands; | |
350 | ||
c02f5703 MS |
351 | /* Are overlay event breakpoints enabled? */ |
352 | static int overlay_events_enabled; | |
353 | ||
e09342b5 TJB |
354 | /* See description in breakpoint.h. */ |
355 | int target_exact_watchpoints = 0; | |
356 | ||
c906108c | 357 | /* Walk the following statement or block through all breakpoints. |
4a64f543 MS |
358 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the |
359 | current breakpoint. */ | |
c906108c | 360 | |
5c44784c | 361 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 362 | |
5c44784c JM |
363 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
364 | for (B = breakpoint_chain; \ | |
365 | B ? (TMP=B->next, 1): 0; \ | |
366 | B = TMP) | |
c906108c | 367 | |
4a64f543 MS |
368 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
369 | not provided so update_global_location_list must not be called | |
370 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 371 | |
876fa593 JK |
372 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
373 | for (BP_TMP = bp_location; \ | |
374 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
375 | BP_TMP++) | |
7cc221ef | 376 | |
1042e4c0 SS |
377 | /* Iterator for tracepoints only. */ |
378 | ||
379 | #define ALL_TRACEPOINTS(B) \ | |
380 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 381 | if (is_tracepoint (B)) |
1042e4c0 | 382 | |
7cc221ef | 383 | /* Chains of all breakpoints defined. */ |
c906108c SS |
384 | |
385 | struct breakpoint *breakpoint_chain; | |
386 | ||
876fa593 JK |
387 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
388 | ||
389 | static struct bp_location **bp_location; | |
390 | ||
391 | /* Number of elements of BP_LOCATION. */ | |
392 | ||
393 | static unsigned bp_location_count; | |
394 | ||
4a64f543 MS |
395 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
396 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
397 | result from bp_location_has_shadow. You can use it for roughly | |
398 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
399 | an address you need to read. */ | |
876fa593 JK |
400 | |
401 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
402 | ||
4a64f543 MS |
403 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
404 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
405 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
406 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
407 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
408 | |
409 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 410 | |
4a64f543 MS |
411 | /* The locations that no longer correspond to any breakpoint, unlinked |
412 | from bp_location array, but for which a hit may still be reported | |
413 | by a target. */ | |
20874c92 VP |
414 | VEC(bp_location_p) *moribund_locations = NULL; |
415 | ||
c906108c SS |
416 | /* Number of last breakpoint made. */ |
417 | ||
95a42b64 TT |
418 | static int breakpoint_count; |
419 | ||
86b17b60 PA |
420 | /* The value of `breakpoint_count' before the last command that |
421 | created breakpoints. If the last (break-like) command created more | |
422 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
423 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
424 | static int prev_breakpoint_count; | |
c906108c | 425 | |
1042e4c0 SS |
426 | /* Number of last tracepoint made. */ |
427 | ||
95a42b64 | 428 | static int tracepoint_count; |
1042e4c0 | 429 | |
6149aea9 PA |
430 | static struct cmd_list_element *breakpoint_set_cmdlist; |
431 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 432 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 433 | |
468d015d JJ |
434 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
435 | static int | |
436 | breakpoint_enabled (struct breakpoint *b) | |
437 | { | |
0d381245 | 438 | return (b->enable_state == bp_enabled); |
468d015d JJ |
439 | } |
440 | ||
c906108c SS |
441 | /* Set breakpoint count to NUM. */ |
442 | ||
95a42b64 | 443 | static void |
fba45db2 | 444 | set_breakpoint_count (int num) |
c906108c | 445 | { |
86b17b60 | 446 | prev_breakpoint_count = breakpoint_count; |
c906108c | 447 | breakpoint_count = num; |
4fa62494 | 448 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
449 | } |
450 | ||
86b17b60 PA |
451 | /* Used by `start_rbreak_breakpoints' below, to record the current |
452 | breakpoint count before "rbreak" creates any breakpoint. */ | |
453 | static int rbreak_start_breakpoint_count; | |
454 | ||
95a42b64 TT |
455 | /* Called at the start an "rbreak" command to record the first |
456 | breakpoint made. */ | |
86b17b60 | 457 | |
95a42b64 TT |
458 | void |
459 | start_rbreak_breakpoints (void) | |
460 | { | |
86b17b60 | 461 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
462 | } |
463 | ||
464 | /* Called at the end of an "rbreak" command to record the last | |
465 | breakpoint made. */ | |
86b17b60 | 466 | |
95a42b64 TT |
467 | void |
468 | end_rbreak_breakpoints (void) | |
469 | { | |
86b17b60 | 470 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
471 | } |
472 | ||
4a64f543 | 473 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
474 | |
475 | void | |
fba45db2 | 476 | clear_breakpoint_hit_counts (void) |
c906108c SS |
477 | { |
478 | struct breakpoint *b; | |
479 | ||
480 | ALL_BREAKPOINTS (b) | |
481 | b->hit_count = 0; | |
482 | } | |
483 | ||
9add0f1b TT |
484 | /* Allocate a new counted_command_line with reference count of 1. |
485 | The new structure owns COMMANDS. */ | |
486 | ||
487 | static struct counted_command_line * | |
488 | alloc_counted_command_line (struct command_line *commands) | |
489 | { | |
490 | struct counted_command_line *result | |
491 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 492 | |
9add0f1b TT |
493 | result->refc = 1; |
494 | result->commands = commands; | |
495 | return result; | |
496 | } | |
497 | ||
498 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
499 | ||
500 | static void | |
501 | incref_counted_command_line (struct counted_command_line *cmd) | |
502 | { | |
503 | if (cmd) | |
504 | ++cmd->refc; | |
505 | } | |
506 | ||
507 | /* Decrement reference count. If the reference count reaches 0, | |
508 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
509 | nothing if *CMDP is NULL. */ | |
510 | ||
511 | static void | |
512 | decref_counted_command_line (struct counted_command_line **cmdp) | |
513 | { | |
514 | if (*cmdp) | |
515 | { | |
516 | if (--(*cmdp)->refc == 0) | |
517 | { | |
518 | free_command_lines (&(*cmdp)->commands); | |
519 | xfree (*cmdp); | |
520 | } | |
521 | *cmdp = NULL; | |
522 | } | |
523 | } | |
524 | ||
525 | /* A cleanup function that calls decref_counted_command_line. */ | |
526 | ||
527 | static void | |
528 | do_cleanup_counted_command_line (void *arg) | |
529 | { | |
530 | decref_counted_command_line (arg); | |
531 | } | |
532 | ||
533 | /* Create a cleanup that calls decref_counted_command_line on the | |
534 | argument. */ | |
535 | ||
536 | static struct cleanup * | |
537 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
538 | { | |
539 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
540 | } | |
541 | ||
c906108c SS |
542 | /* Default address, symtab and line to put a breakpoint at |
543 | for "break" command with no arg. | |
4a64f543 | 544 | If default_breakpoint_valid is zero, the other three are |
c906108c SS |
545 | not valid, and "break" with no arg is an error. |
546 | ||
547 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
548 | ||
549 | int default_breakpoint_valid; | |
550 | CORE_ADDR default_breakpoint_address; | |
551 | struct symtab *default_breakpoint_symtab; | |
552 | int default_breakpoint_line; | |
6c95b8df PA |
553 | struct program_space *default_breakpoint_pspace; |
554 | ||
c906108c | 555 | \f |
48cb2d85 VP |
556 | /* Return the breakpoint with the specified number, or NULL |
557 | if the number does not refer to an existing breakpoint. */ | |
558 | ||
559 | struct breakpoint * | |
560 | get_breakpoint (int num) | |
561 | { | |
562 | struct breakpoint *b; | |
563 | ||
564 | ALL_BREAKPOINTS (b) | |
565 | if (b->number == num) | |
566 | return b; | |
567 | ||
568 | return NULL; | |
569 | } | |
5c44784c | 570 | |
c906108c | 571 | \f |
adc36818 PM |
572 | |
573 | void | |
574 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
575 | int from_tty) | |
576 | { | |
577 | struct bp_location *loc = b->loc; | |
578 | ||
579 | for (; loc; loc = loc->next) | |
580 | { | |
581 | xfree (loc->cond); | |
582 | loc->cond = NULL; | |
583 | } | |
584 | xfree (b->cond_string); | |
585 | b->cond_string = NULL; | |
586 | xfree (b->cond_exp); | |
587 | b->cond_exp = NULL; | |
588 | ||
589 | if (*exp == 0) | |
590 | { | |
591 | if (from_tty) | |
592 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
593 | } | |
594 | else | |
595 | { | |
596 | char *arg = exp; | |
cc59ec59 | 597 | |
adc36818 PM |
598 | /* I don't know if it matters whether this is the string the user |
599 | typed in or the decompiled expression. */ | |
600 | b->cond_string = xstrdup (arg); | |
601 | b->condition_not_parsed = 0; | |
602 | ||
603 | if (is_watchpoint (b)) | |
604 | { | |
605 | innermost_block = NULL; | |
606 | arg = exp; | |
607 | b->cond_exp = parse_exp_1 (&arg, 0, 0); | |
608 | if (*arg) | |
609 | error (_("Junk at end of expression")); | |
610 | b->cond_exp_valid_block = innermost_block; | |
611 | } | |
612 | else | |
613 | { | |
614 | for (loc = b->loc; loc; loc = loc->next) | |
615 | { | |
616 | arg = exp; | |
617 | loc->cond = | |
618 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
619 | if (*arg) | |
620 | error (_("Junk at end of expression")); | |
621 | } | |
622 | } | |
623 | } | |
624 | breakpoints_changed (); | |
625 | observer_notify_breakpoint_modified (b->number); | |
626 | } | |
627 | ||
c906108c SS |
628 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
629 | ||
630 | static void | |
fba45db2 | 631 | condition_command (char *arg, int from_tty) |
c906108c | 632 | { |
52f0bd74 | 633 | struct breakpoint *b; |
c906108c | 634 | char *p; |
52f0bd74 | 635 | int bnum; |
c906108c SS |
636 | |
637 | if (arg == 0) | |
e2e0b3e5 | 638 | error_no_arg (_("breakpoint number")); |
c906108c SS |
639 | |
640 | p = arg; | |
641 | bnum = get_number (&p); | |
5c44784c | 642 | if (bnum == 0) |
8a3fe4f8 | 643 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
644 | |
645 | ALL_BREAKPOINTS (b) | |
646 | if (b->number == bnum) | |
2f069f6f | 647 | { |
7371cf6d PM |
648 | /* Check if this breakpoint has a Python object assigned to |
649 | it, and if it has a definition of the "stop" | |
650 | method. This method and conditions entered into GDB from | |
651 | the CLI are mutually exclusive. */ | |
652 | if (b->py_bp_object | |
653 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
654 | error (_("Cannot set a condition where a Python 'stop' " | |
655 | "method has been defined in the breakpoint.")); | |
2566ad2d | 656 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
657 | return; |
658 | } | |
c906108c | 659 | |
8a3fe4f8 | 660 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
661 | } |
662 | ||
a7bdde9e VP |
663 | /* Check that COMMAND do not contain commands that are suitable |
664 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
665 | Throw if any such commands is found. */ |
666 | ||
a7bdde9e VP |
667 | static void |
668 | check_no_tracepoint_commands (struct command_line *commands) | |
669 | { | |
670 | struct command_line *c; | |
cc59ec59 | 671 | |
a7bdde9e VP |
672 | for (c = commands; c; c = c->next) |
673 | { | |
674 | int i; | |
675 | ||
676 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
677 | error (_("The 'while-stepping' command can " |
678 | "only be used for tracepoints")); | |
a7bdde9e VP |
679 | |
680 | for (i = 0; i < c->body_count; ++i) | |
681 | check_no_tracepoint_commands ((c->body_list)[i]); | |
682 | ||
683 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 684 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
685 | command directly. */ |
686 | if (strstr (c->line, "collect ") == c->line) | |
687 | error (_("The 'collect' command can only be used for tracepoints")); | |
688 | ||
51661e93 VP |
689 | if (strstr (c->line, "teval ") == c->line) |
690 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
691 | } |
692 | } | |
693 | ||
d77f58be SS |
694 | /* Encapsulate tests for different types of tracepoints. */ |
695 | ||
a7bdde9e | 696 | int |
d77f58be | 697 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 698 | { |
0fb4aa4b PA |
699 | return (b->type == bp_tracepoint |
700 | || b->type == bp_fast_tracepoint | |
701 | || b->type == bp_static_tracepoint); | |
a7bdde9e | 702 | } |
d77f58be | 703 | |
95a42b64 TT |
704 | /* A helper function that validsates that COMMANDS are valid for a |
705 | breakpoint. This function will throw an exception if a problem is | |
706 | found. */ | |
48cb2d85 | 707 | |
95a42b64 TT |
708 | static void |
709 | validate_commands_for_breakpoint (struct breakpoint *b, | |
710 | struct command_line *commands) | |
48cb2d85 | 711 | { |
d77f58be | 712 | if (is_tracepoint (b)) |
a7bdde9e | 713 | { |
4a64f543 MS |
714 | /* We need to verify that each top-level element of commands is |
715 | valid for tracepoints, that there's at most one | |
716 | while-stepping element, and that while-stepping's body has | |
717 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
718 | struct command_line *c; |
719 | struct command_line *while_stepping = 0; | |
720 | for (c = commands; c; c = c->next) | |
721 | { | |
a7bdde9e VP |
722 | if (c->control_type == while_stepping_control) |
723 | { | |
724 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
725 | error (_("The 'while-stepping' command " |
726 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 727 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
728 | error (_("The 'while-stepping' command " |
729 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
730 | |
731 | if (while_stepping) | |
3e43a32a MS |
732 | error (_("The 'while-stepping' command " |
733 | "can be used only once")); | |
a7bdde9e VP |
734 | else |
735 | while_stepping = c; | |
736 | } | |
737 | } | |
738 | if (while_stepping) | |
739 | { | |
740 | struct command_line *c2; | |
741 | ||
742 | gdb_assert (while_stepping->body_count == 1); | |
743 | c2 = while_stepping->body_list[0]; | |
744 | for (; c2; c2 = c2->next) | |
745 | { | |
a7bdde9e VP |
746 | if (c2->control_type == while_stepping_control) |
747 | error (_("The 'while-stepping' command cannot be nested")); | |
748 | } | |
749 | } | |
750 | } | |
751 | else | |
752 | { | |
753 | check_no_tracepoint_commands (commands); | |
754 | } | |
95a42b64 TT |
755 | } |
756 | ||
0fb4aa4b PA |
757 | /* Return a vector of all the static tracepoints set at ADDR. The |
758 | caller is responsible for releasing the vector. */ | |
759 | ||
760 | VEC(breakpoint_p) * | |
761 | static_tracepoints_here (CORE_ADDR addr) | |
762 | { | |
763 | struct breakpoint *b; | |
764 | VEC(breakpoint_p) *found = 0; | |
765 | struct bp_location *loc; | |
766 | ||
767 | ALL_BREAKPOINTS (b) | |
768 | if (b->type == bp_static_tracepoint) | |
769 | { | |
770 | for (loc = b->loc; loc; loc = loc->next) | |
771 | if (loc->address == addr) | |
772 | VEC_safe_push(breakpoint_p, found, b); | |
773 | } | |
774 | ||
775 | return found; | |
776 | } | |
777 | ||
95a42b64 | 778 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 779 | validate that only allowed commands are included. */ |
95a42b64 TT |
780 | |
781 | void | |
4a64f543 MS |
782 | breakpoint_set_commands (struct breakpoint *b, |
783 | struct command_line *commands) | |
95a42b64 TT |
784 | { |
785 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 786 | |
9add0f1b TT |
787 | decref_counted_command_line (&b->commands); |
788 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
789 | breakpoints_changed (); |
790 | observer_notify_breakpoint_modified (b->number); | |
791 | } | |
792 | ||
45a43567 TT |
793 | /* Set the internal `silent' flag on the breakpoint. Note that this |
794 | is not the same as the "silent" that may appear in the breakpoint's | |
795 | commands. */ | |
796 | ||
797 | void | |
798 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
799 | { | |
800 | int old_silent = b->silent; | |
801 | ||
802 | b->silent = silent; | |
803 | if (old_silent != silent) | |
804 | observer_notify_breakpoint_modified (b->number); | |
805 | } | |
806 | ||
807 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
808 | breakpoint work for any thread. */ | |
809 | ||
810 | void | |
811 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
812 | { | |
813 | int old_thread = b->thread; | |
814 | ||
815 | b->thread = thread; | |
816 | if (old_thread != thread) | |
817 | observer_notify_breakpoint_modified (b->number); | |
818 | } | |
819 | ||
820 | /* Set the task for this breakpoint. If TASK is 0, make the | |
821 | breakpoint work for any task. */ | |
822 | ||
823 | void | |
824 | breakpoint_set_task (struct breakpoint *b, int task) | |
825 | { | |
826 | int old_task = b->task; | |
827 | ||
828 | b->task = task; | |
829 | if (old_task != task) | |
830 | observer_notify_breakpoint_modified (b->number); | |
831 | } | |
832 | ||
95a42b64 TT |
833 | void |
834 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
835 | { |
836 | struct breakpoint *b = closure; | |
cc59ec59 | 837 | |
a7bdde9e VP |
838 | validate_actionline (&line, b); |
839 | } | |
840 | ||
95a42b64 TT |
841 | /* A structure used to pass information through |
842 | map_breakpoint_numbers. */ | |
843 | ||
844 | struct commands_info | |
845 | { | |
846 | /* True if the command was typed at a tty. */ | |
847 | int from_tty; | |
86b17b60 PA |
848 | |
849 | /* The breakpoint range spec. */ | |
850 | char *arg; | |
851 | ||
95a42b64 TT |
852 | /* Non-NULL if the body of the commands are being read from this |
853 | already-parsed command. */ | |
854 | struct command_line *control; | |
86b17b60 | 855 | |
95a42b64 TT |
856 | /* The command lines read from the user, or NULL if they have not |
857 | yet been read. */ | |
858 | struct counted_command_line *cmd; | |
859 | }; | |
860 | ||
861 | /* A callback for map_breakpoint_numbers that sets the commands for | |
862 | commands_command. */ | |
863 | ||
c906108c | 864 | static void |
95a42b64 | 865 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 866 | { |
95a42b64 | 867 | struct commands_info *info = data; |
c906108c | 868 | |
95a42b64 TT |
869 | if (info->cmd == NULL) |
870 | { | |
871 | struct command_line *l; | |
5c44784c | 872 | |
95a42b64 TT |
873 | if (info->control != NULL) |
874 | l = copy_command_lines (info->control->body_list[0]); | |
875 | else | |
86b17b60 PA |
876 | { |
877 | struct cleanup *old_chain; | |
878 | char *str; | |
c5aa993b | 879 | |
3e43a32a MS |
880 | str = xstrprintf (_("Type commands for breakpoint(s) " |
881 | "%s, one per line."), | |
86b17b60 PA |
882 | info->arg); |
883 | ||
884 | old_chain = make_cleanup (xfree, str); | |
885 | ||
886 | l = read_command_lines (str, | |
887 | info->from_tty, 1, | |
d77f58be | 888 | (is_tracepoint (b) |
86b17b60 PA |
889 | ? check_tracepoint_command : 0), |
890 | b); | |
891 | ||
892 | do_cleanups (old_chain); | |
893 | } | |
a7bdde9e | 894 | |
95a42b64 TT |
895 | info->cmd = alloc_counted_command_line (l); |
896 | } | |
897 | ||
898 | /* If a breakpoint was on the list more than once, we don't need to | |
899 | do anything. */ | |
900 | if (b->commands != info->cmd) | |
901 | { | |
902 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
903 | incref_counted_command_line (info->cmd); | |
904 | decref_counted_command_line (&b->commands); | |
905 | b->commands = info->cmd; | |
906 | breakpoints_changed (); | |
907 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 908 | } |
95a42b64 TT |
909 | } |
910 | ||
911 | static void | |
4a64f543 MS |
912 | commands_command_1 (char *arg, int from_tty, |
913 | struct command_line *control) | |
95a42b64 TT |
914 | { |
915 | struct cleanup *cleanups; | |
916 | struct commands_info info; | |
917 | ||
918 | info.from_tty = from_tty; | |
919 | info.control = control; | |
920 | info.cmd = NULL; | |
921 | /* If we read command lines from the user, then `info' will hold an | |
922 | extra reference to the commands that we must clean up. */ | |
923 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
924 | ||
925 | if (arg == NULL || !*arg) | |
926 | { | |
86b17b60 | 927 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
928 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
929 | breakpoint_count); | |
95a42b64 TT |
930 | else if (breakpoint_count > 0) |
931 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
932 | else |
933 | { | |
934 | /* So that we don't try to free the incoming non-NULL | |
935 | argument in the cleanup below. Mapping breakpoint | |
936 | numbers will fail in this case. */ | |
937 | arg = NULL; | |
938 | } | |
95a42b64 | 939 | } |
9766ced4 SS |
940 | else |
941 | /* The command loop has some static state, so we need to preserve | |
942 | our argument. */ | |
943 | arg = xstrdup (arg); | |
86b17b60 PA |
944 | |
945 | if (arg != NULL) | |
946 | make_cleanup (xfree, arg); | |
947 | ||
948 | info.arg = arg; | |
95a42b64 TT |
949 | |
950 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
951 | ||
952 | if (info.cmd == NULL) | |
953 | error (_("No breakpoints specified.")); | |
954 | ||
955 | do_cleanups (cleanups); | |
956 | } | |
957 | ||
958 | static void | |
959 | commands_command (char *arg, int from_tty) | |
960 | { | |
961 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 962 | } |
40c03ae8 EZ |
963 | |
964 | /* Like commands_command, but instead of reading the commands from | |
965 | input stream, takes them from an already parsed command structure. | |
966 | ||
967 | This is used by cli-script.c to DTRT with breakpoint commands | |
968 | that are part of if and while bodies. */ | |
969 | enum command_control_type | |
970 | commands_from_control_command (char *arg, struct command_line *cmd) | |
971 | { | |
95a42b64 TT |
972 | commands_command_1 (arg, 0, cmd); |
973 | return simple_control; | |
40c03ae8 | 974 | } |
876fa593 JK |
975 | |
976 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
977 | ||
978 | static int | |
979 | bp_location_has_shadow (struct bp_location *bl) | |
980 | { | |
981 | if (bl->loc_type != bp_loc_software_breakpoint) | |
982 | return 0; | |
983 | if (!bl->inserted) | |
984 | return 0; | |
985 | if (bl->target_info.shadow_len == 0) | |
986 | /* bp isn't valid, or doesn't shadow memory. */ | |
987 | return 0; | |
988 | return 1; | |
989 | } | |
990 | ||
8defab1a | 991 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
992 | by replacing any memory breakpoints with their shadowed contents. |
993 | ||
994 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
995 | bl->address - bp_location_placed_address_before_address_max |
996 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
997 | The range we were requested to resolve shadows for is: |
998 | memaddr ... memaddr + len | |
999 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1000 | memaddr + len <= (bl->address |
1001 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1002 | and: |
35df4500 | 1003 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1004 | |
8defab1a DJ |
1005 | void |
1006 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1007 | { |
4a64f543 MS |
1008 | /* Left boundary, right boundary and median element of our binary |
1009 | search. */ | |
876fa593 JK |
1010 | unsigned bc_l, bc_r, bc; |
1011 | ||
4a64f543 MS |
1012 | /* Find BC_L which is a leftmost element which may affect BUF |
1013 | content. It is safe to report lower value but a failure to | |
1014 | report higher one. */ | |
876fa593 JK |
1015 | |
1016 | bc_l = 0; | |
1017 | bc_r = bp_location_count; | |
1018 | while (bc_l + 1 < bc_r) | |
1019 | { | |
35df4500 | 1020 | struct bp_location *bl; |
876fa593 JK |
1021 | |
1022 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1023 | bl = bp_location[bc]; |
876fa593 | 1024 | |
4a64f543 MS |
1025 | /* Check first BL->ADDRESS will not overflow due to the added |
1026 | constant. Then advance the left boundary only if we are sure | |
1027 | the BC element can in no way affect the BUF content (MEMADDR | |
1028 | to MEMADDR + LEN range). | |
876fa593 | 1029 | |
4a64f543 MS |
1030 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1031 | offset so that we cannot miss a breakpoint with its shadow | |
1032 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1033 | |
35df4500 TJB |
1034 | if ((bl->address + bp_location_shadow_len_after_address_max |
1035 | >= bl->address) | |
1036 | && (bl->address + bp_location_shadow_len_after_address_max | |
1037 | <= memaddr)) | |
876fa593 JK |
1038 | bc_l = bc; |
1039 | else | |
1040 | bc_r = bc; | |
1041 | } | |
1042 | ||
128070bb PA |
1043 | /* Due to the binary search above, we need to make sure we pick the |
1044 | first location that's at BC_L's address. E.g., if there are | |
1045 | multiple locations at the same address, BC_L may end up pointing | |
1046 | at a duplicate location, and miss the "master"/"inserted" | |
1047 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1048 | B: | |
1049 | ||
1050 | L1@A, L2@A, L3@B, ... | |
1051 | ||
1052 | BC_L could end up pointing at location L2, while the "master" | |
1053 | location could be L1. Since the `loc->inserted' flag is only set | |
1054 | on "master" locations, we'd forget to restore the shadow of L1 | |
1055 | and L2. */ | |
1056 | while (bc_l > 0 | |
1057 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1058 | bc_l--; | |
1059 | ||
876fa593 JK |
1060 | /* Now do full processing of the found relevant range of elements. */ |
1061 | ||
1062 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1063 | { |
35df4500 | 1064 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1065 | CORE_ADDR bp_addr = 0; |
1066 | int bp_size = 0; | |
1067 | int bptoffset = 0; | |
1068 | ||
35df4500 TJB |
1069 | /* bp_location array has BL->OWNER always non-NULL. */ |
1070 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1071 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1072 | bl->owner->number); |
ffce0d52 | 1073 | |
876fa593 JK |
1074 | /* Performance optimization: any futher element can no longer affect BUF |
1075 | content. */ | |
1076 | ||
35df4500 TJB |
1077 | if (bl->address >= bp_location_placed_address_before_address_max |
1078 | && memaddr + len <= (bl->address | |
1079 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1080 | break; |
1081 | ||
35df4500 | 1082 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1083 | continue; |
35df4500 | 1084 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1085 | current_program_space->aspace, 0)) |
1086 | continue; | |
1087 | ||
c5aa993b JM |
1088 | /* Addresses and length of the part of the breakpoint that |
1089 | we need to copy. */ | |
35df4500 TJB |
1090 | bp_addr = bl->target_info.placed_address; |
1091 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1092 | |
c5aa993b JM |
1093 | if (bp_addr + bp_size <= memaddr) |
1094 | /* The breakpoint is entirely before the chunk of memory we | |
1095 | are reading. */ | |
1096 | continue; | |
8defab1a | 1097 | |
c5aa993b JM |
1098 | if (bp_addr >= memaddr + len) |
1099 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1100 | reading. */ |
c5aa993b | 1101 | continue; |
c5aa993b | 1102 | |
8defab1a DJ |
1103 | /* Offset within shadow_contents. */ |
1104 | if (bp_addr < memaddr) | |
1105 | { | |
1106 | /* Only copy the second part of the breakpoint. */ | |
1107 | bp_size -= memaddr - bp_addr; | |
1108 | bptoffset = memaddr - bp_addr; | |
1109 | bp_addr = memaddr; | |
1110 | } | |
c5aa993b | 1111 | |
8defab1a DJ |
1112 | if (bp_addr + bp_size > memaddr + len) |
1113 | { | |
1114 | /* Only copy the first part of the breakpoint. */ | |
1115 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1116 | } | |
c5aa993b | 1117 | |
8defab1a | 1118 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1119 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1120 | } |
c906108c | 1121 | } |
c906108c | 1122 | \f |
c5aa993b | 1123 | |
60e1c644 PA |
1124 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1125 | ||
a5606eee | 1126 | static int |
d77f58be | 1127 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1128 | { |
1129 | return (bpt->type == bp_hardware_watchpoint | |
1130 | || bpt->type == bp_read_watchpoint | |
1131 | || bpt->type == bp_access_watchpoint); | |
1132 | } | |
7270d8f2 | 1133 | |
60e1c644 PA |
1134 | /* Return true if BPT is of any watchpoint kind, hardware or |
1135 | software. */ | |
1136 | ||
1137 | static int | |
d77f58be | 1138 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1139 | { |
1140 | return (is_hardware_watchpoint (bpt) | |
1141 | || bpt->type == bp_watchpoint); | |
1142 | } | |
1143 | ||
f6bc2008 PA |
1144 | /* Assuming that B is a watchpoint: returns true if the current thread |
1145 | and its running state are safe to evaluate or update watchpoint B. | |
1146 | Watchpoints on local expressions need to be evaluated in the | |
1147 | context of the thread that was current when the watchpoint was | |
1148 | created, and, that thread needs to be stopped to be able to select | |
1149 | the correct frame context. Watchpoints on global expressions can | |
1150 | be evaluated on any thread, and in any state. It is presently left | |
1151 | to the target allowing memory accesses when threads are | |
1152 | running. */ | |
1153 | ||
1154 | static int | |
1155 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1156 | { | |
1157 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1158 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1159 | && !is_executing (inferior_ptid))); | |
1160 | } | |
1161 | ||
d0fb5eae JK |
1162 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1163 | associated bp_watchpoint_scope breakpoint. */ | |
1164 | ||
1165 | static void | |
1166 | watchpoint_del_at_next_stop (struct breakpoint *b) | |
1167 | { | |
1168 | gdb_assert (is_watchpoint (b)); | |
1169 | ||
1170 | if (b->related_breakpoint != b) | |
1171 | { | |
1172 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1173 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1174 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1175 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1176 | b->related_breakpoint = b; | |
1177 | } | |
1178 | b->disposition = disp_del_at_next_stop; | |
1179 | } | |
1180 | ||
567e1b4e JB |
1181 | /* Assuming that B is a watchpoint: |
1182 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1183 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1184 | - Evaluate the condition if there is one, and store the result |
1185 | in b->loc->cond. | |
a5606eee VP |
1186 | - Update the list of values that must be watched in B->loc. |
1187 | ||
4a64f543 MS |
1188 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1189 | nothing. If this is local watchpoint that is out of scope, delete | |
1190 | it. | |
1191 | ||
1192 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1193 | removed + inserted on each stop here. Normal breakpoints must | |
1194 | never be removed because they might be missed by a running thread | |
1195 | when debugging in non-stop mode. On the other hand, hardware | |
1196 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1197 | to each LWP since they are stored in each LWP's hardware debug | |
1198 | registers. Therefore, such LWP must be stopped first in order to | |
1199 | be able to modify its hardware watchpoints. | |
1200 | ||
1201 | Hardware watchpoints must be reset exactly once after being | |
1202 | presented to the user. It cannot be done sooner, because it would | |
1203 | reset the data used to present the watchpoint hit to the user. And | |
1204 | it must not be done later because it could display the same single | |
1205 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1206 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1207 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1208 | not user-visible - its hit is suppressed if the memory content has | |
1209 | not changed. | |
1210 | ||
1211 | The following constraints influence the location where we can reset | |
1212 | hardware watchpoints: | |
1213 | ||
1214 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1215 | called several times when GDB stops. | |
1216 | ||
1217 | [linux] | |
1218 | * Multiple hardware watchpoints can be hit at the same time, | |
1219 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1220 | hit at a time as the reason for stopping, and all the other hits | |
1221 | are presented later, one after the other, each time the user | |
1222 | requests the execution to be resumed. Execution is not resumed | |
1223 | for the threads still having pending hit event stored in | |
1224 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1225 | the inferior on the first stop the thread hit event is kept being | |
1226 | reported from its cached value by linux_nat_stopped_data_address | |
1227 | until the real thread resume happens after the watchpoint gets | |
1228 | presented and thus its LWP_INFO->STATUS gets reset. | |
1229 | ||
1230 | Therefore the hardware watchpoint hit can get safely reset on the | |
1231 | watchpoint removal from inferior. */ | |
a79d3c27 | 1232 | |
b40ce68a | 1233 | static void |
a5606eee | 1234 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1235 | { |
a5606eee | 1236 | int within_current_scope; |
a5606eee | 1237 | struct frame_id saved_frame_id; |
66076460 | 1238 | int frame_saved; |
a5606eee | 1239 | |
d0fb5eae JK |
1240 | gdb_assert (is_watchpoint (b)); |
1241 | ||
f6bc2008 PA |
1242 | /* If this is a local watchpoint, we only want to check if the |
1243 | watchpoint frame is in scope if the current thread is the thread | |
1244 | that was used to create the watchpoint. */ | |
1245 | if (!watchpoint_in_thread_scope (b)) | |
1246 | return; | |
1247 | ||
a5606eee VP |
1248 | if (b->disposition == disp_del_at_next_stop) |
1249 | return; | |
1250 | ||
66076460 | 1251 | frame_saved = 0; |
a5606eee VP |
1252 | |
1253 | /* Determine if the watchpoint is within scope. */ | |
1254 | if (b->exp_valid_block == NULL) | |
1255 | within_current_scope = 1; | |
1256 | else | |
1257 | { | |
b5db5dfc UW |
1258 | struct frame_info *fi = get_current_frame (); |
1259 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1260 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1261 | ||
1262 | /* If we're in a function epilogue, unwinding may not work | |
1263 | properly, so do not attempt to recreate locations at this | |
1264 | point. See similar comments in watchpoint_check. */ | |
1265 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1266 | return; | |
66076460 DJ |
1267 | |
1268 | /* Save the current frame's ID so we can restore it after | |
1269 | evaluating the watchpoint expression on its own frame. */ | |
1270 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1271 | took a frame parameter, so that we didn't have to change the | |
1272 | selected frame. */ | |
1273 | frame_saved = 1; | |
1274 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1275 | ||
a5606eee VP |
1276 | fi = frame_find_by_id (b->watchpoint_frame); |
1277 | within_current_scope = (fi != NULL); | |
1278 | if (within_current_scope) | |
1279 | select_frame (fi); | |
1280 | } | |
1281 | ||
b5db5dfc UW |
1282 | /* We don't free locations. They are stored in the bp_location array |
1283 | and update_global_location_list will eventually delete them and | |
1284 | remove breakpoints if needed. */ | |
1285 | b->loc = NULL; | |
1286 | ||
a5606eee VP |
1287 | if (within_current_scope && reparse) |
1288 | { | |
1289 | char *s; | |
d63d0675 | 1290 | |
a5606eee VP |
1291 | if (b->exp) |
1292 | { | |
1293 | xfree (b->exp); | |
1294 | b->exp = NULL; | |
1295 | } | |
d63d0675 | 1296 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1297 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1298 | /* If the meaning of expression itself changed, the old value is | |
1299 | no longer relevant. We don't want to report a watchpoint hit | |
1300 | to the user when the old value and the new value may actually | |
1301 | be completely different objects. */ | |
1302 | value_free (b->val); | |
fa4727a6 DJ |
1303 | b->val = NULL; |
1304 | b->val_valid = 0; | |
60e1c644 PA |
1305 | |
1306 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1307 | expression is stored in the breakpoint object, not in the | |
1308 | locations (re)created below. */ | |
1309 | if (b->cond_string != NULL) | |
1310 | { | |
1311 | if (b->cond_exp != NULL) | |
1312 | { | |
1313 | xfree (b->cond_exp); | |
1314 | b->cond_exp = NULL; | |
1315 | } | |
1316 | ||
1317 | s = b->cond_string; | |
1318 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1319 | } | |
a5606eee | 1320 | } |
a5606eee VP |
1321 | |
1322 | /* If we failed to parse the expression, for example because | |
1323 | it refers to a global variable in a not-yet-loaded shared library, | |
1324 | don't try to insert watchpoint. We don't automatically delete | |
1325 | such watchpoint, though, since failure to parse expression | |
1326 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1327 | if ( !target_has_execution) |
1328 | { | |
1329 | /* Without execution, memory can't change. No use to try and | |
1330 | set watchpoint locations. The watchpoint will be reset when | |
1331 | the target gains execution, through breakpoint_re_set. */ | |
1332 | } | |
1333 | else if (within_current_scope && b->exp) | |
a5606eee | 1334 | { |
0cf6dd15 | 1335 | int pc = 0; |
fa4727a6 | 1336 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1337 | struct program_space *frame_pspace; |
a5606eee | 1338 | |
0cf6dd15 | 1339 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1340 | |
a5606eee VP |
1341 | /* Avoid setting b->val if it's already set. The meaning of |
1342 | b->val is 'the last value' user saw, and we should update | |
1343 | it only if we reported that last value to user. As it | |
1344 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1345 | if (!b->val_valid) |
1346 | { | |
1347 | b->val = v; | |
1348 | b->val_valid = 1; | |
1349 | } | |
a5606eee | 1350 | |
2d134ed3 PA |
1351 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1352 | ||
a5606eee | 1353 | /* Look at each value on the value chain. */ |
9fa40276 | 1354 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1355 | { |
1356 | /* If it's a memory location, and GDB actually needed | |
1357 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1358 | must watch it. If the first value returned is |
1359 | still lazy, that means an error occurred reading it; | |
1360 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1361 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1362 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1363 | { |
1364 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1365 | |
a5606eee VP |
1366 | /* We only watch structs and arrays if user asked |
1367 | for it explicitly, never if they just happen to | |
1368 | appear in the middle of some value chain. */ | |
fa4727a6 | 1369 | if (v == result |
a5606eee VP |
1370 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1371 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1372 | { | |
1373 | CORE_ADDR addr; | |
1374 | int len, type; | |
1375 | struct bp_location *loc, **tmp; | |
1376 | ||
42ae5230 | 1377 | addr = value_address (v); |
a5606eee VP |
1378 | len = TYPE_LENGTH (value_type (v)); |
1379 | type = hw_write; | |
1380 | if (b->type == bp_read_watchpoint) | |
1381 | type = hw_read; | |
1382 | else if (b->type == bp_access_watchpoint) | |
1383 | type = hw_access; | |
1384 | ||
39d61571 | 1385 | loc = allocate_bp_location (b); |
a5606eee VP |
1386 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1387 | ; | |
1388 | *tmp = loc; | |
a6d9a66e | 1389 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1390 | |
1391 | loc->pspace = frame_pspace; | |
a5606eee VP |
1392 | loc->address = addr; |
1393 | loc->length = len; | |
1394 | loc->watchpoint_type = type; | |
1395 | } | |
1396 | } | |
9fa40276 TJB |
1397 | } |
1398 | ||
1399 | /* Change the type of breakpoint between hardware assisted or | |
1400 | an ordinary watchpoint depending on the hardware support | |
1401 | and free hardware slots. REPARSE is set when the inferior | |
1402 | is started. */ | |
1403 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1404 | && reparse) | |
1405 | { | |
e09342b5 | 1406 | int reg_cnt; |
9fa40276 TJB |
1407 | enum bp_loc_type loc_type; |
1408 | struct bp_location *bl; | |
a5606eee | 1409 | |
e09342b5 TJB |
1410 | reg_cnt = can_use_hardware_watchpoint (val_chain, b->exact); |
1411 | ||
1412 | if (reg_cnt) | |
9fa40276 TJB |
1413 | { |
1414 | int i, target_resources_ok, other_type_used; | |
e09342b5 | 1415 | enum enable_state orig_enable_state; |
9fa40276 TJB |
1416 | |
1417 | /* We need to determine how many resources are already | |
e09342b5 TJB |
1418 | used for all other hardware watchpoints plus this one |
1419 | to see if we still have enough resources to also fit | |
1420 | this watchpoint in as well. To guarantee the | |
1421 | hw_watchpoint_used_count call below counts this | |
1422 | watchpoint, make sure that it is marked as a hardware | |
1423 | watchpoint. */ | |
1424 | b->type = bp_hardware_watchpoint; | |
1425 | ||
1426 | /* hw_watchpoint_used_count ignores disabled watchpoints, | |
1427 | and b might be disabled if we're being called from | |
1428 | do_enable_breakpoint. */ | |
1429 | orig_enable_state = b->enable_state; | |
1430 | b->enable_state = bp_enabled; | |
1431 | ||
9fa40276 TJB |
1432 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1433 | &other_type_used); | |
9fa40276 | 1434 | |
e09342b5 TJB |
1435 | b->enable_state = orig_enable_state; |
1436 | ||
1437 | target_resources_ok = target_can_use_hardware_watchpoint | |
1438 | (bp_hardware_watchpoint, i, other_type_used); | |
1439 | if (target_resources_ok <= 0) | |
1440 | b->type = bp_watchpoint; | |
9fa40276 TJB |
1441 | } |
1442 | else | |
1443 | b->type = bp_watchpoint; | |
1444 | ||
1445 | loc_type = (b->type == bp_watchpoint? bp_loc_other | |
1446 | : bp_loc_hardware_watchpoint); | |
1447 | for (bl = b->loc; bl; bl = bl->next) | |
1448 | bl->loc_type = loc_type; | |
1449 | } | |
1450 | ||
1451 | for (v = val_chain; v; v = next) | |
1452 | { | |
a5606eee VP |
1453 | next = value_next (v); |
1454 | if (v != b->val) | |
1455 | value_free (v); | |
1456 | } | |
1457 | ||
c7437ca6 PA |
1458 | /* If a software watchpoint is not watching any memory, then the |
1459 | above left it without any location set up. But, | |
1460 | bpstat_stop_status requires a location to be able to report | |
1461 | stops, so make sure there's at least a dummy one. */ | |
1462 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1463 | { | |
1464 | b->loc = allocate_bp_location (b); | |
1465 | b->loc->pspace = frame_pspace; | |
1466 | b->loc->address = -1; | |
1467 | b->loc->length = -1; | |
1468 | b->loc->watchpoint_type = -1; | |
1469 | } | |
a5606eee VP |
1470 | } |
1471 | else if (!within_current_scope) | |
7270d8f2 | 1472 | { |
ac74f770 MS |
1473 | printf_filtered (_("\ |
1474 | Watchpoint %d deleted because the program has left the block\n\ | |
1475 | in which its expression is valid.\n"), | |
a5606eee | 1476 | b->number); |
d0fb5eae | 1477 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1478 | } |
a5606eee VP |
1479 | |
1480 | /* Restore the selected frame. */ | |
66076460 DJ |
1481 | if (frame_saved) |
1482 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1483 | } |
1484 | ||
a5606eee | 1485 | |
74960c60 VP |
1486 | /* Returns 1 iff breakpoint location should be |
1487 | inserted in the inferior. */ | |
1488 | static int | |
35df4500 | 1489 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1490 | { |
35df4500 | 1491 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1492 | return 0; |
1493 | ||
35df4500 | 1494 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1495 | return 0; |
1496 | ||
35df4500 | 1497 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1498 | return 0; |
1499 | ||
56710373 PA |
1500 | /* This is set for example, when we're attached to the parent of a |
1501 | vfork, and have detached from the child. The child is running | |
1502 | free, and we expect it to do an exec or exit, at which point the | |
1503 | OS makes the parent schedulable again (and the target reports | |
1504 | that the vfork is done). Until the child is done with the shared | |
1505 | memory region, do not insert breakpoints in the parent, otherwise | |
1506 | the child could still trip on the parent's breakpoints. Since | |
1507 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1508 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1509 | return 0; |
1510 | ||
1042e4c0 SS |
1511 | /* Tracepoints are inserted by the target at a time of its choosing, |
1512 | not by us. */ | |
35df4500 | 1513 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1514 | return 0; |
1515 | ||
74960c60 VP |
1516 | return 1; |
1517 | } | |
1518 | ||
35df4500 TJB |
1519 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1520 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
1521 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. | |
879bfdc2 | 1522 | |
4a64f543 MS |
1523 | NOTE drow/2003-09-09: This routine could be broken down to an |
1524 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1525 | static int |
35df4500 | 1526 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1527 | struct ui_file *tmp_error_stream, |
fa3a767f | 1528 | int *disabled_breaks, |
26bb91f3 | 1529 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1530 | { |
1531 | int val = 0; | |
1532 | ||
35df4500 | 1533 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1534 | return 0; |
1535 | ||
8181d85f | 1536 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1537 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1538 | bl->target_info.placed_address = bl->address; | |
1539 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
8181d85f | 1540 | |
35df4500 TJB |
1541 | if (bl->loc_type == bp_loc_software_breakpoint |
1542 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1543 | { |
35df4500 | 1544 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1545 | { |
1546 | /* If the explicitly specified breakpoint type | |
1547 | is not hardware breakpoint, check the memory map to see | |
1548 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1549 | |
765dc015 VP |
1550 | Two important cases are: |
1551 | - location type is not hardware breakpoint, memory | |
1552 | is readonly. We change the type of the location to | |
1553 | hardware breakpoint. | |
4a64f543 MS |
1554 | - location type is hardware breakpoint, memory is |
1555 | read-write. This means we've previously made the | |
1556 | location hardware one, but then the memory map changed, | |
1557 | so we undo. | |
765dc015 | 1558 | |
4a64f543 MS |
1559 | When breakpoints are removed, remove_breakpoints will use |
1560 | location types we've just set here, the only possible | |
1561 | problem is that memory map has changed during running | |
1562 | program, but it's not going to work anyway with current | |
1563 | gdb. */ | |
765dc015 | 1564 | struct mem_region *mr |
35df4500 | 1565 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1566 | |
1567 | if (mr) | |
1568 | { | |
1569 | if (automatic_hardware_breakpoints) | |
1570 | { | |
765dc015 VP |
1571 | enum bp_loc_type new_type; |
1572 | ||
1573 | if (mr->attrib.mode != MEM_RW) | |
1574 | new_type = bp_loc_hardware_breakpoint; | |
1575 | else | |
1576 | new_type = bp_loc_software_breakpoint; | |
1577 | ||
35df4500 | 1578 | if (new_type != bl->loc_type) |
765dc015 VP |
1579 | { |
1580 | static int said = 0; | |
cc59ec59 | 1581 | |
35df4500 | 1582 | bl->loc_type = new_type; |
765dc015 VP |
1583 | if (!said) |
1584 | { | |
3e43a32a MS |
1585 | fprintf_filtered (gdb_stdout, |
1586 | _("Note: automatically using " | |
1587 | "hardware breakpoints for " | |
1588 | "read-only addresses.\n")); | |
765dc015 VP |
1589 | said = 1; |
1590 | } | |
1591 | } | |
1592 | } | |
35df4500 | 1593 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1594 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1595 | warning (_("cannot set software breakpoint " |
1596 | "at readonly address %s"), | |
35df4500 | 1597 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1598 | } |
1599 | } | |
1600 | ||
879bfdc2 DJ |
1601 | /* First check to see if we have to handle an overlay. */ |
1602 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1603 | || bl->section == NULL |
1604 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1605 | { |
1606 | /* No overlay handling: just set the breakpoint. */ | |
1607 | ||
35df4500 TJB |
1608 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1609 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1610 | &bl->target_info); | |
879bfdc2 | 1611 | else |
35df4500 TJB |
1612 | val = target_insert_breakpoint (bl->gdbarch, |
1613 | &bl->target_info); | |
879bfdc2 DJ |
1614 | } |
1615 | else | |
1616 | { | |
4a64f543 | 1617 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1618 | Shall we set a breakpoint at the LMA? */ |
1619 | if (!overlay_events_enabled) | |
1620 | { | |
1621 | /* Yes -- overlay event support is not active, | |
1622 | so we must try to set a breakpoint at the LMA. | |
1623 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1624 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1625 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1626 | bl->owner->number); |
879bfdc2 DJ |
1627 | else |
1628 | { | |
35df4500 TJB |
1629 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1630 | bl->section); | |
879bfdc2 | 1631 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1632 | bl->overlay_target_info = bl->target_info; |
1633 | bl->overlay_target_info.placed_address = addr; | |
1634 | val = target_insert_breakpoint (bl->gdbarch, | |
1635 | &bl->overlay_target_info); | |
879bfdc2 | 1636 | if (val != 0) |
99361f52 | 1637 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1638 | "Overlay breakpoint %d " |
1639 | "failed: in ROM?\n", | |
35df4500 | 1640 | bl->owner->number); |
879bfdc2 DJ |
1641 | } |
1642 | } | |
1643 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1644 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1645 | { |
1646 | /* Yes. This overlay section is mapped into memory. */ | |
35df4500 TJB |
1647 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1648 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1649 | &bl->target_info); | |
879bfdc2 | 1650 | else |
35df4500 TJB |
1651 | val = target_insert_breakpoint (bl->gdbarch, |
1652 | &bl->target_info); | |
879bfdc2 DJ |
1653 | } |
1654 | else | |
1655 | { | |
1656 | /* No. This breakpoint will not be inserted. | |
1657 | No error, but do not mark the bp as 'inserted'. */ | |
1658 | return 0; | |
1659 | } | |
1660 | } | |
1661 | ||
1662 | if (val) | |
1663 | { | |
1664 | /* Can't set the breakpoint. */ | |
35df4500 | 1665 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1666 | { |
4a64f543 | 1667 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1668 | val = 0; |
35df4500 | 1669 | bl->shlib_disabled = 1; |
879bfdc2 DJ |
1670 | if (!*disabled_breaks) |
1671 | { | |
1672 | fprintf_unfiltered (tmp_error_stream, | |
1673 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1674 | bl->owner->number); |
879bfdc2 | 1675 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1676 | "Temporarily disabling shared " |
1677 | "library breakpoints:\n"); | |
879bfdc2 DJ |
1678 | } |
1679 | *disabled_breaks = 1; | |
1680 | fprintf_unfiltered (tmp_error_stream, | |
35df4500 | 1681 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1682 | } |
1683 | else | |
879bfdc2 | 1684 | { |
35df4500 | 1685 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1686 | { |
1687 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1688 | fprintf_unfiltered (tmp_error_stream, |
1689 | "Cannot insert hardware " | |
1690 | "breakpoint %d.\n", | |
35df4500 | 1691 | bl->owner->number); |
879bfdc2 DJ |
1692 | } |
1693 | else | |
1694 | { | |
1695 | fprintf_unfiltered (tmp_error_stream, | |
1696 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1697 | bl->owner->number); |
879bfdc2 DJ |
1698 | fprintf_filtered (tmp_error_stream, |
1699 | "Error accessing memory address "); | |
35df4500 | 1700 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1701 | tmp_error_stream); |
879bfdc2 DJ |
1702 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1703 | safe_strerror (val)); | |
1704 | } | |
1705 | ||
1706 | } | |
1707 | } | |
1708 | else | |
35df4500 | 1709 | bl->inserted = 1; |
879bfdc2 DJ |
1710 | |
1711 | return val; | |
1712 | } | |
1713 | ||
35df4500 | 1714 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1715 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1716 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1717 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1718 | { |
77b06cd7 TJB |
1719 | gdb_assert (bl->owner->ops != NULL |
1720 | && bl->owner->ops->insert_location != NULL); | |
1721 | ||
1722 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1723 | |
1724 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1725 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1726 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1727 | { |
1728 | struct bp_location *loc, **loc_temp; | |
1729 | ||
1730 | /* But don't try to insert it, if there's already another | |
1731 | hw_access location that would be considered a duplicate | |
1732 | of this one. */ | |
1733 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1734 | if (loc != bl |
85d721b8 | 1735 | && loc->watchpoint_type == hw_access |
35df4500 | 1736 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1737 | { |
35df4500 TJB |
1738 | bl->duplicate = 1; |
1739 | bl->inserted = 1; | |
1740 | bl->target_info = loc->target_info; | |
1741 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1742 | val = 0; |
1743 | break; | |
1744 | } | |
1745 | ||
1746 | if (val == 1) | |
1747 | { | |
77b06cd7 TJB |
1748 | bl->watchpoint_type = hw_access; |
1749 | val = bl->owner->ops->insert_location (bl); | |
1750 | ||
1751 | if (val) | |
1752 | /* Back to the original value. */ | |
1753 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1754 | } |
1755 | } | |
1756 | ||
35df4500 | 1757 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1758 | } |
1759 | ||
35df4500 | 1760 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1761 | { |
77b06cd7 TJB |
1762 | gdb_assert (bl->owner->ops != NULL |
1763 | && bl->owner->ops->insert_location != NULL); | |
1764 | ||
1765 | val = bl->owner->ops->insert_location (bl); | |
1766 | if (val) | |
1767 | { | |
1768 | bl->owner->enable_state = bp_disabled; | |
1769 | ||
1770 | if (val == 1) | |
1771 | warning (_("\ | |
1772 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1773 | of catchpoint."), bl->owner->number); | |
1774 | else | |
1775 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1776 | } | |
1777 | ||
1778 | bl->inserted = (val == 0); | |
1640b821 DJ |
1779 | |
1780 | /* We've already printed an error message if there was a problem | |
1781 | inserting this catchpoint, and we've disabled the catchpoint, | |
1782 | so just return success. */ | |
1783 | return 0; | |
879bfdc2 DJ |
1784 | } |
1785 | ||
1786 | return 0; | |
1787 | } | |
1788 | ||
6c95b8df PA |
1789 | /* This function is called when program space PSPACE is about to be |
1790 | deleted. It takes care of updating breakpoints to not reference | |
1791 | PSPACE anymore. */ | |
1792 | ||
1793 | void | |
1794 | breakpoint_program_space_exit (struct program_space *pspace) | |
1795 | { | |
1796 | struct breakpoint *b, *b_temp; | |
876fa593 | 1797 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1798 | |
1799 | /* Remove any breakpoint that was set through this program space. */ | |
1800 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1801 | { | |
1802 | if (b->pspace == pspace) | |
1803 | delete_breakpoint (b); | |
1804 | } | |
1805 | ||
1806 | /* Breakpoints set through other program spaces could have locations | |
1807 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1808 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1809 | { |
1810 | struct bp_location *tmp; | |
1811 | ||
1812 | if (loc->pspace == pspace) | |
1813 | { | |
2bdf28a0 | 1814 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1815 | if (loc->owner->loc == loc) |
1816 | loc->owner->loc = loc->next; | |
1817 | else | |
1818 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1819 | if (tmp->next == loc) | |
1820 | { | |
1821 | tmp->next = loc->next; | |
1822 | break; | |
1823 | } | |
1824 | } | |
1825 | } | |
1826 | ||
1827 | /* Now update the global location list to permanently delete the | |
1828 | removed locations above. */ | |
1829 | update_global_location_list (0); | |
1830 | } | |
1831 | ||
74960c60 VP |
1832 | /* Make sure all breakpoints are inserted in inferior. |
1833 | Throws exception on any error. | |
1834 | A breakpoint that is already inserted won't be inserted | |
1835 | again, so calling this function twice is safe. */ | |
1836 | void | |
1837 | insert_breakpoints (void) | |
1838 | { | |
1839 | struct breakpoint *bpt; | |
1840 | ||
1841 | ALL_BREAKPOINTS (bpt) | |
1842 | if (is_hardware_watchpoint (bpt)) | |
4a64f543 | 1843 | update_watchpoint (bpt, 0 /* don't reparse. */); |
74960c60 | 1844 | |
b60e7edf | 1845 | update_global_location_list (1); |
74960c60 | 1846 | |
c35b1492 PA |
1847 | /* update_global_location_list does not insert breakpoints when |
1848 | always_inserted_mode is not enabled. Explicitly insert them | |
1849 | now. */ | |
1850 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1851 | insert_breakpoint_locations (); |
1852 | } | |
1853 | ||
c906108c SS |
1854 | /* insert_breakpoints is used when starting or continuing the program. |
1855 | remove_breakpoints is used when the program stops. | |
1856 | Both return zero if successful, | |
1857 | or an `errno' value if could not write the inferior. */ | |
1858 | ||
74960c60 VP |
1859 | static void |
1860 | insert_breakpoint_locations (void) | |
c906108c | 1861 | { |
a5606eee | 1862 | struct breakpoint *bpt; |
35df4500 | 1863 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1864 | int error = 0; |
c906108c SS |
1865 | int val = 0; |
1866 | int disabled_breaks = 0; | |
81d0cc19 | 1867 | int hw_breakpoint_error = 0; |
c906108c | 1868 | |
81d0cc19 | 1869 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1870 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1871 | |
81d0cc19 GS |
1872 | /* Explicitly mark the warning -- this will only be printed if |
1873 | there was an error. */ | |
1874 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1875 | |
1876 | save_current_space_and_thread (); | |
1877 | ||
35df4500 | 1878 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1879 | { |
35df4500 | 1880 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1881 | continue; |
1882 | ||
4a64f543 MS |
1883 | /* There is no point inserting thread-specific breakpoints if |
1884 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1885 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1886 | if (bl->owner->thread != -1 |
1887 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1888 | continue; |
1889 | ||
35df4500 | 1890 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1891 | |
1892 | /* For targets that support global breakpoints, there's no need | |
1893 | to select an inferior to insert breakpoint to. In fact, even | |
1894 | if we aren't attached to any process yet, we should still | |
1895 | insert breakpoints. */ | |
1896 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1897 | && ptid_equal (inferior_ptid, null_ptid)) | |
1898 | continue; | |
1899 | ||
35df4500 | 1900 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
879bfdc2 DJ |
1901 | &hw_breakpoint_error); |
1902 | if (val) | |
e236ba44 | 1903 | error = val; |
879bfdc2 | 1904 | } |
c906108c | 1905 | |
4a64f543 MS |
1906 | /* If we failed to insert all locations of a watchpoint, remove |
1907 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1908 | ALL_BREAKPOINTS (bpt) |
1909 | { | |
1910 | int some_failed = 0; | |
1911 | struct bp_location *loc; | |
1912 | ||
1913 | if (!is_hardware_watchpoint (bpt)) | |
1914 | continue; | |
1915 | ||
d6b74ac4 | 1916 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1917 | continue; |
74960c60 VP |
1918 | |
1919 | if (bpt->disposition == disp_del_at_next_stop) | |
1920 | continue; | |
a5606eee VP |
1921 | |
1922 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1923 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1924 | { |
1925 | some_failed = 1; | |
1926 | break; | |
1927 | } | |
1928 | if (some_failed) | |
1929 | { | |
1930 | for (loc = bpt->loc; loc; loc = loc->next) | |
1931 | if (loc->inserted) | |
1932 | remove_breakpoint (loc, mark_uninserted); | |
1933 | ||
1934 | hw_breakpoint_error = 1; | |
1935 | fprintf_unfiltered (tmp_error_stream, | |
1936 | "Could not insert hardware watchpoint %d.\n", | |
1937 | bpt->number); | |
1938 | error = -1; | |
1939 | } | |
1940 | } | |
1941 | ||
e236ba44 | 1942 | if (error) |
81d0cc19 GS |
1943 | { |
1944 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1945 | message about possibly exhausted resources. */ | |
879bfdc2 | 1946 | if (hw_breakpoint_error) |
81d0cc19 | 1947 | { |
c6510018 MS |
1948 | fprintf_unfiltered (tmp_error_stream, |
1949 | "Could not insert hardware breakpoints:\n\ | |
1950 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1951 | } |
81d0cc19 GS |
1952 | target_terminal_ours_for_output (); |
1953 | error_stream (tmp_error_stream); | |
1954 | } | |
f7545552 TT |
1955 | |
1956 | do_cleanups (cleanups); | |
c906108c SS |
1957 | } |
1958 | ||
c906108c | 1959 | int |
fba45db2 | 1960 | remove_breakpoints (void) |
c906108c | 1961 | { |
35df4500 | 1962 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 1963 | int val = 0; |
c906108c | 1964 | |
35df4500 | 1965 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 1966 | { |
35df4500 TJB |
1967 | if (bl->inserted) |
1968 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 1969 | } |
3a1bae8e | 1970 | return val; |
c906108c SS |
1971 | } |
1972 | ||
6c95b8df PA |
1973 | /* Remove breakpoints of process PID. */ |
1974 | ||
1975 | int | |
1976 | remove_breakpoints_pid (int pid) | |
1977 | { | |
35df4500 | 1978 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
1979 | int val; |
1980 | struct inferior *inf = find_inferior_pid (pid); | |
1981 | ||
35df4500 | 1982 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 1983 | { |
35df4500 | 1984 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
1985 | continue; |
1986 | ||
35df4500 | 1987 | if (bl->inserted) |
6c95b8df | 1988 | { |
35df4500 | 1989 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
1990 | if (val != 0) |
1991 | return val; | |
1992 | } | |
1993 | } | |
1994 | return 0; | |
1995 | } | |
1996 | ||
692590c1 | 1997 | int |
80ce1ecb | 1998 | remove_hw_watchpoints (void) |
692590c1 | 1999 | { |
35df4500 | 2000 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2001 | int val = 0; |
692590c1 | 2002 | |
35df4500 | 2003 | ALL_BP_LOCATIONS (bl, blp_tmp) |
692590c1 | 2004 | { |
35df4500 TJB |
2005 | if (bl->inserted && bl->loc_type == bp_loc_hardware_watchpoint) |
2006 | val |= remove_breakpoint (bl, mark_uninserted); | |
692590c1 | 2007 | } |
3a1bae8e | 2008 | return val; |
692590c1 MS |
2009 | } |
2010 | ||
c906108c | 2011 | int |
fba45db2 | 2012 | reattach_breakpoints (int pid) |
c906108c | 2013 | { |
6c95b8df | 2014 | struct cleanup *old_chain; |
35df4500 | 2015 | struct bp_location *bl, **blp_tmp; |
c906108c | 2016 | int val; |
86b887df | 2017 | struct ui_file *tmp_error_stream; |
fa3a767f | 2018 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2019 | struct inferior *inf; |
2020 | struct thread_info *tp; | |
2021 | ||
2022 | tp = any_live_thread_of_process (pid); | |
2023 | if (tp == NULL) | |
2024 | return 1; | |
2025 | ||
2026 | inf = find_inferior_pid (pid); | |
2027 | old_chain = save_inferior_ptid (); | |
2028 | ||
2029 | inferior_ptid = tp->ptid; | |
a4954f26 | 2030 | |
86b887df | 2031 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2032 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2033 | |
35df4500 | 2034 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2035 | { |
35df4500 | 2036 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2037 | continue; |
2038 | ||
35df4500 | 2039 | if (bl->inserted) |
c5aa993b | 2040 | { |
35df4500 TJB |
2041 | bl->inserted = 0; |
2042 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); | |
c5aa993b JM |
2043 | if (val != 0) |
2044 | { | |
ce696e05 | 2045 | do_cleanups (old_chain); |
c5aa993b JM |
2046 | return val; |
2047 | } | |
2048 | } | |
2049 | } | |
ce696e05 | 2050 | do_cleanups (old_chain); |
c906108c SS |
2051 | return 0; |
2052 | } | |
2053 | ||
e58b0e63 PA |
2054 | static int internal_breakpoint_number = -1; |
2055 | ||
84f4c1fe PM |
2056 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2057 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2058 | from internal_breakpoint_number and that variable decremented. | |
2059 | Otherwis the breakpoint number will be populated from | |
2060 | breakpoint_count and that value incremented. Internal breakpoints | |
2061 | do not set the internal var bpnum. */ | |
2062 | static void | |
2063 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2064 | { | |
2065 | if (internal) | |
2066 | b->number = internal_breakpoint_number--; | |
2067 | else | |
2068 | { | |
2069 | set_breakpoint_count (breakpoint_count + 1); | |
2070 | b->number = breakpoint_count; | |
2071 | } | |
2072 | } | |
2073 | ||
e62c965a | 2074 | static struct breakpoint * |
a6d9a66e UW |
2075 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2076 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2077 | { |
e62c965a PP |
2078 | struct symtab_and_line sal; |
2079 | struct breakpoint *b; | |
2080 | ||
4a64f543 | 2081 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2082 | |
2083 | sal.pc = address; | |
2084 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2085 | sal.pspace = current_program_space; |
e62c965a | 2086 | |
a6d9a66e | 2087 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2088 | b->number = internal_breakpoint_number--; |
2089 | b->disposition = disp_donttouch; | |
2090 | ||
2091 | return b; | |
2092 | } | |
2093 | ||
17450429 PP |
2094 | static const char *const longjmp_names[] = |
2095 | { | |
2096 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2097 | }; | |
2098 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2099 | ||
2100 | /* Per-objfile data private to breakpoint.c. */ | |
2101 | struct breakpoint_objfile_data | |
2102 | { | |
2103 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2104 | struct minimal_symbol *overlay_msym; | |
2105 | ||
2106 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2107 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2108 | ||
2109 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2110 | struct minimal_symbol *terminate_msym; | |
2111 | ||
2112 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2113 | struct minimal_symbol *exception_msym; | |
2114 | }; | |
2115 | ||
2116 | static const struct objfile_data *breakpoint_objfile_key; | |
2117 | ||
2118 | /* Minimal symbol not found sentinel. */ | |
2119 | static struct minimal_symbol msym_not_found; | |
2120 | ||
2121 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2122 | ||
2123 | static int | |
2124 | msym_not_found_p (const struct minimal_symbol *msym) | |
2125 | { | |
2126 | return msym == &msym_not_found; | |
2127 | } | |
2128 | ||
2129 | /* Return per-objfile data needed by breakpoint.c. | |
2130 | Allocate the data if necessary. */ | |
2131 | ||
2132 | static struct breakpoint_objfile_data * | |
2133 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2134 | { | |
2135 | struct breakpoint_objfile_data *bp_objfile_data; | |
2136 | ||
2137 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2138 | if (bp_objfile_data == NULL) | |
2139 | { | |
2140 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2141 | sizeof (*bp_objfile_data)); | |
2142 | ||
2143 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2144 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2145 | } | |
2146 | return bp_objfile_data; | |
2147 | } | |
2148 | ||
e62c965a | 2149 | static void |
af02033e | 2150 | create_overlay_event_breakpoint (void) |
e62c965a | 2151 | { |
69de3c6a | 2152 | struct objfile *objfile; |
af02033e | 2153 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2154 | |
69de3c6a PP |
2155 | ALL_OBJFILES (objfile) |
2156 | { | |
2157 | struct breakpoint *b; | |
17450429 PP |
2158 | struct breakpoint_objfile_data *bp_objfile_data; |
2159 | CORE_ADDR addr; | |
69de3c6a | 2160 | |
17450429 PP |
2161 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2162 | ||
2163 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2164 | continue; | |
2165 | ||
2166 | if (bp_objfile_data->overlay_msym == NULL) | |
2167 | { | |
2168 | struct minimal_symbol *m; | |
2169 | ||
2170 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2171 | if (m == NULL) | |
2172 | { | |
2173 | /* Avoid future lookups in this objfile. */ | |
2174 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2175 | continue; | |
2176 | } | |
2177 | bp_objfile_data->overlay_msym = m; | |
2178 | } | |
e62c965a | 2179 | |
17450429 PP |
2180 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2181 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
69de3c6a PP |
2182 | bp_overlay_event); |
2183 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2184 | |
69de3c6a PP |
2185 | if (overlay_debugging == ovly_auto) |
2186 | { | |
2187 | b->enable_state = bp_enabled; | |
2188 | overlay_events_enabled = 1; | |
2189 | } | |
2190 | else | |
2191 | { | |
2192 | b->enable_state = bp_disabled; | |
2193 | overlay_events_enabled = 0; | |
2194 | } | |
e62c965a PP |
2195 | } |
2196 | update_global_location_list (1); | |
2197 | } | |
2198 | ||
0fd8e87f | 2199 | static void |
af02033e | 2200 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2201 | { |
6c95b8df | 2202 | struct program_space *pspace; |
6c95b8df PA |
2203 | struct cleanup *old_chain; |
2204 | ||
2205 | old_chain = save_current_program_space (); | |
0fd8e87f | 2206 | |
6c95b8df | 2207 | ALL_PSPACES (pspace) |
af02033e PP |
2208 | { |
2209 | struct objfile *objfile; | |
2210 | ||
2211 | set_current_program_space (pspace); | |
2212 | ||
2213 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2214 | { |
af02033e PP |
2215 | int i; |
2216 | struct gdbarch *gdbarch; | |
17450429 | 2217 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2218 | |
af02033e PP |
2219 | gdbarch = get_objfile_arch (objfile); |
2220 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2221 | continue; |
2222 | ||
17450429 PP |
2223 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2224 | ||
2225 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2226 | { |
2227 | struct breakpoint *b; | |
af02033e | 2228 | const char *func_name; |
17450429 | 2229 | CORE_ADDR addr; |
6c95b8df | 2230 | |
17450429 | 2231 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2232 | continue; |
0fd8e87f | 2233 | |
17450429 PP |
2234 | func_name = longjmp_names[i]; |
2235 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2236 | { | |
2237 | struct minimal_symbol *m; | |
2238 | ||
2239 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2240 | if (m == NULL) | |
2241 | { | |
2242 | /* Prevent future lookups in this objfile. */ | |
2243 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2244 | continue; | |
2245 | } | |
2246 | bp_objfile_data->longjmp_msym[i] = m; | |
2247 | } | |
2248 | ||
2249 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
2250 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master); | |
af02033e PP |
2251 | b->addr_string = xstrdup (func_name); |
2252 | b->enable_state = bp_disabled; | |
2253 | } | |
0fd8e87f | 2254 | } |
af02033e | 2255 | } |
0fd8e87f | 2256 | update_global_location_list (1); |
6c95b8df PA |
2257 | |
2258 | do_cleanups (old_chain); | |
0fd8e87f UW |
2259 | } |
2260 | ||
af02033e | 2261 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2262 | static void |
af02033e | 2263 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2264 | { |
2265 | struct program_space *pspace; | |
aa7d318d | 2266 | struct cleanup *old_chain; |
af02033e | 2267 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2268 | |
2269 | old_chain = save_current_program_space (); | |
2270 | ||
2271 | ALL_PSPACES (pspace) | |
17450429 PP |
2272 | { |
2273 | struct objfile *objfile; | |
2274 | CORE_ADDR addr; | |
2275 | ||
2276 | set_current_program_space (pspace); | |
2277 | ||
aa7d318d TT |
2278 | ALL_OBJFILES (objfile) |
2279 | { | |
2280 | struct breakpoint *b; | |
17450429 | 2281 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2282 | |
17450429 | 2283 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2284 | |
17450429 PP |
2285 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2286 | continue; | |
2287 | ||
2288 | if (bp_objfile_data->terminate_msym == NULL) | |
2289 | { | |
2290 | struct minimal_symbol *m; | |
2291 | ||
2292 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2293 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2294 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2295 | { | |
2296 | /* Prevent future lookups in this objfile. */ | |
2297 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2298 | continue; | |
2299 | } | |
2300 | bp_objfile_data->terminate_msym = m; | |
2301 | } | |
aa7d318d | 2302 | |
17450429 PP |
2303 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2304 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
aa7d318d TT |
2305 | bp_std_terminate_master); |
2306 | b->addr_string = xstrdup (func_name); | |
2307 | b->enable_state = bp_disabled; | |
2308 | } | |
17450429 PP |
2309 | } |
2310 | ||
aa7d318d TT |
2311 | update_global_location_list (1); |
2312 | ||
2313 | do_cleanups (old_chain); | |
2314 | } | |
2315 | ||
186c406b TT |
2316 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2317 | ||
2318 | void | |
2319 | create_exception_master_breakpoint (void) | |
2320 | { | |
2321 | struct objfile *objfile; | |
17450429 | 2322 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2323 | |
2324 | ALL_OBJFILES (objfile) | |
2325 | { | |
17450429 PP |
2326 | struct breakpoint *b; |
2327 | struct gdbarch *gdbarch; | |
2328 | struct breakpoint_objfile_data *bp_objfile_data; | |
2329 | CORE_ADDR addr; | |
2330 | ||
2331 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2332 | ||
2333 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2334 | continue; | |
2335 | ||
2336 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2337 | |
17450429 | 2338 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2339 | { |
17450429 | 2340 | struct minimal_symbol *debug_hook; |
186c406b | 2341 | |
17450429 PP |
2342 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2343 | if (debug_hook == NULL) | |
2344 | { | |
2345 | bp_objfile_data->exception_msym = &msym_not_found; | |
2346 | continue; | |
2347 | } | |
2348 | ||
2349 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2350 | } |
17450429 PP |
2351 | |
2352 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2353 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2354 | ¤t_target); | |
2355 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); | |
2356 | b->addr_string = xstrdup (func_name); | |
2357 | b->enable_state = bp_disabled; | |
186c406b TT |
2358 | } |
2359 | ||
2360 | update_global_location_list (1); | |
2361 | } | |
2362 | ||
c906108c | 2363 | void |
fba45db2 | 2364 | update_breakpoints_after_exec (void) |
c906108c | 2365 | { |
35df4500 | 2366 | struct breakpoint *b, *b_tmp; |
876fa593 | 2367 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2368 | |
25b22b0a PA |
2369 | /* We're about to delete breakpoints from GDB's lists. If the |
2370 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2371 | writing the breakpoints' "shadow contents" back into memory. The | |
2372 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2373 | do that. Instead, the target is responsible from marking | |
2374 | breakpoints out as soon as it detects an exec. We don't do that | |
2375 | here instead, because there may be other attempts to delete | |
2376 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2377 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2378 | if (bploc->pspace == current_program_space) |
2379 | gdb_assert (!bploc->inserted); | |
c906108c | 2380 | |
35df4500 | 2381 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2382 | { |
6c95b8df PA |
2383 | if (b->pspace != current_program_space) |
2384 | continue; | |
2385 | ||
4a64f543 | 2386 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2387 | if (b->type == bp_shlib_event) |
2388 | { | |
2389 | delete_breakpoint (b); | |
2390 | continue; | |
2391 | } | |
c906108c | 2392 | |
4a64f543 | 2393 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2394 | if (b->type == bp_jit_event) |
2395 | { | |
2396 | delete_breakpoint (b); | |
2397 | continue; | |
2398 | } | |
2399 | ||
1900040c | 2400 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2401 | as must overlay event and longjmp master breakpoints. */ |
2402 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2403 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2404 | || b->type == bp_exception_master) | |
c4093a6a JM |
2405 | { |
2406 | delete_breakpoint (b); | |
2407 | continue; | |
2408 | } | |
2409 | ||
4a64f543 | 2410 | /* Step-resume breakpoints are meaningless after an exec(). */ |
c5aa993b JM |
2411 | if (b->type == bp_step_resume) |
2412 | { | |
2413 | delete_breakpoint (b); | |
2414 | continue; | |
2415 | } | |
2416 | ||
611c83ae PA |
2417 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2418 | after an exec. */ | |
186c406b TT |
2419 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2420 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2421 | { |
2422 | delete_breakpoint (b); | |
2423 | continue; | |
2424 | } | |
2425 | ||
ce78b96d JB |
2426 | if (b->type == bp_catchpoint) |
2427 | { | |
2428 | /* For now, none of the bp_catchpoint breakpoints need to | |
2429 | do anything at this point. In the future, if some of | |
2430 | the catchpoints need to something, we will need to add | |
2431 | a new method, and call this method from here. */ | |
2432 | continue; | |
2433 | } | |
2434 | ||
c5aa993b JM |
2435 | /* bp_finish is a special case. The only way we ought to be able |
2436 | to see one of these when an exec() has happened, is if the user | |
2437 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2438 | carries them to the call-site of the current callee, by setting | |
2439 | a temporary bp there and resuming. But in this case, the finish | |
2440 | will carry them entirely through the vfork & exec. | |
2441 | ||
2442 | We don't want to allow a bp_finish to remain inserted now. But | |
2443 | we can't safely delete it, 'cause finish_command has a handle to | |
2444 | the bp on a bpstat, and will later want to delete it. There's a | |
2445 | chance (and I've seen it happen) that if we delete the bp_finish | |
2446 | here, that its storage will get reused by the time finish_command | |
2447 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2448 | We really must allow finish_command to delete a bp_finish. | |
2449 | ||
53a5351d JM |
2450 | In the absense of a general solution for the "how do we know |
2451 | it's safe to delete something others may have handles to?" | |
2452 | problem, what we'll do here is just uninsert the bp_finish, and | |
2453 | let finish_command delete it. | |
2454 | ||
2455 | (We know the bp_finish is "doomed" in the sense that it's | |
2456 | momentary, and will be deleted as soon as finish_command sees | |
2457 | the inferior stopped. So it doesn't matter that the bp's | |
2458 | address is probably bogus in the new a.out, unlike e.g., the | |
2459 | solib breakpoints.) */ | |
c5aa993b | 2460 | |
c5aa993b JM |
2461 | if (b->type == bp_finish) |
2462 | { | |
2463 | continue; | |
2464 | } | |
2465 | ||
2466 | /* Without a symbolic address, we have little hope of the | |
2467 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2468 | a.out. */ |
c5aa993b JM |
2469 | if (b->addr_string == NULL) |
2470 | { | |
2471 | delete_breakpoint (b); | |
2472 | continue; | |
2473 | } | |
c5aa993b | 2474 | } |
1900040c | 2475 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2476 | create_overlay_event_breakpoint (); |
2477 | create_longjmp_master_breakpoint (); | |
2478 | create_std_terminate_master_breakpoint (); | |
186c406b | 2479 | create_exception_master_breakpoint (); |
c906108c SS |
2480 | } |
2481 | ||
2482 | int | |
fba45db2 | 2483 | detach_breakpoints (int pid) |
c906108c | 2484 | { |
35df4500 | 2485 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2486 | int val = 0; |
ce696e05 | 2487 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2488 | struct inferior *inf = current_inferior (); |
c5aa993b | 2489 | |
39f77062 | 2490 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2491 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2492 | |
6c95b8df | 2493 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2494 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2495 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2496 | { |
35df4500 | 2497 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2498 | continue; |
2499 | ||
35df4500 TJB |
2500 | if (bl->inserted) |
2501 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2502 | } |
d03285ec UW |
2503 | |
2504 | /* Detach single-step breakpoints as well. */ | |
2505 | detach_single_step_breakpoints (); | |
2506 | ||
ce696e05 | 2507 | do_cleanups (old_chain); |
3a1bae8e | 2508 | return val; |
c906108c SS |
2509 | } |
2510 | ||
35df4500 | 2511 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2512 | Note that this is used to detach breakpoints from a child fork. |
2513 | When we get here, the child isn't in the inferior list, and neither | |
2514 | do we have objects to represent its address space --- we should | |
35df4500 | 2515 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2516 | |
c906108c | 2517 | static int |
35df4500 | 2518 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2519 | { |
2520 | int val; | |
c5aa993b | 2521 | |
35df4500 TJB |
2522 | /* BL is never in moribund_locations by our callers. */ |
2523 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2524 | |
35df4500 | 2525 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2526 | /* Permanent breakpoints cannot be inserted or removed. */ |
2527 | return 0; | |
2528 | ||
74960c60 VP |
2529 | /* The type of none suggests that owner is actually deleted. |
2530 | This should not ever happen. */ | |
35df4500 | 2531 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2532 | |
35df4500 TJB |
2533 | if (bl->loc_type == bp_loc_software_breakpoint |
2534 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2535 | { |
c02f5703 MS |
2536 | /* "Normal" instruction breakpoint: either the standard |
2537 | trap-instruction bp (bp_breakpoint), or a | |
2538 | bp_hardware_breakpoint. */ | |
2539 | ||
2540 | /* First check to see if we have to handle an overlay. */ | |
2541 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2542 | || bl->section == NULL |
2543 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2544 | { |
2545 | /* No overlay handling: just remove the breakpoint. */ | |
2546 | ||
35df4500 TJB |
2547 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2548 | val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
c02f5703 | 2549 | else |
35df4500 | 2550 | val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
c02f5703 | 2551 | } |
c906108c SS |
2552 | else |
2553 | { | |
4a64f543 | 2554 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2555 | Did we set a breakpoint at the LMA? */ |
2556 | if (!overlay_events_enabled) | |
2557 | { | |
2558 | /* Yes -- overlay event support is not active, so we | |
2559 | should have set a breakpoint at the LMA. Remove it. | |
2560 | */ | |
c02f5703 MS |
2561 | /* Ignore any failures: if the LMA is in ROM, we will |
2562 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2563 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2564 | target_remove_hw_breakpoint (bl->gdbarch, | |
2565 | &bl->overlay_target_info); | |
c02f5703 | 2566 | else |
35df4500 TJB |
2567 | target_remove_breakpoint (bl->gdbarch, |
2568 | &bl->overlay_target_info); | |
c02f5703 MS |
2569 | } |
2570 | /* Did we set a breakpoint at the VMA? | |
2571 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2572 | if (bl->inserted) |
c906108c | 2573 | { |
c02f5703 MS |
2574 | /* Yes -- remove it. Previously we did not bother to |
2575 | remove the breakpoint if the section had been | |
2576 | unmapped, but let's not rely on that being safe. We | |
2577 | don't know what the overlay manager might do. */ | |
35df4500 TJB |
2578 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2579 | val = target_remove_hw_breakpoint (bl->gdbarch, | |
2580 | &bl->target_info); | |
aa67235e UW |
2581 | |
2582 | /* However, we should remove *software* breakpoints only | |
2583 | if the section is still mapped, or else we overwrite | |
2584 | wrong code with the saved shadow contents. */ | |
35df4500 TJB |
2585 | else if (section_is_mapped (bl->section)) |
2586 | val = target_remove_breakpoint (bl->gdbarch, | |
2587 | &bl->target_info); | |
aa67235e UW |
2588 | else |
2589 | val = 0; | |
c906108c | 2590 | } |
c02f5703 MS |
2591 | else |
2592 | { | |
2593 | /* No -- not inserted, so no need to remove. No error. */ | |
2594 | val = 0; | |
2595 | } | |
c906108c | 2596 | } |
879d1e6b UW |
2597 | |
2598 | /* In some cases, we might not be able to remove a breakpoint | |
2599 | in a shared library that has already been removed, but we | |
2600 | have not yet processed the shlib unload event. */ | |
35df4500 | 2601 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2602 | val = 0; |
2603 | ||
c906108c SS |
2604 | if (val) |
2605 | return val; | |
35df4500 | 2606 | bl->inserted = (is == mark_inserted); |
c906108c | 2607 | } |
35df4500 | 2608 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2609 | { |
77b06cd7 TJB |
2610 | gdb_assert (bl->owner->ops != NULL |
2611 | && bl->owner->ops->remove_location != NULL); | |
2612 | ||
35df4500 | 2613 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2614 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2615 | |
c906108c | 2616 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2617 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2618 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2619 | bl->owner->number); |
c906108c | 2620 | } |
35df4500 TJB |
2621 | else if (bl->owner->type == bp_catchpoint |
2622 | && breakpoint_enabled (bl->owner) | |
2623 | && !bl->duplicate) | |
ce78b96d | 2624 | { |
77b06cd7 TJB |
2625 | gdb_assert (bl->owner->ops != NULL |
2626 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2627 | |
77b06cd7 | 2628 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2629 | if (val) |
2630 | return val; | |
77b06cd7 | 2631 | |
35df4500 | 2632 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2633 | } |
c906108c SS |
2634 | |
2635 | return 0; | |
2636 | } | |
2637 | ||
6c95b8df | 2638 | static int |
35df4500 | 2639 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2640 | { |
2641 | int ret; | |
2642 | struct cleanup *old_chain; | |
2643 | ||
35df4500 TJB |
2644 | /* BL is never in moribund_locations by our callers. */ |
2645 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2646 | |
35df4500 | 2647 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2648 | /* Permanent breakpoints cannot be inserted or removed. */ |
2649 | return 0; | |
2650 | ||
2651 | /* The type of none suggests that owner is actually deleted. | |
2652 | This should not ever happen. */ | |
35df4500 | 2653 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2654 | |
2655 | old_chain = save_current_space_and_thread (); | |
2656 | ||
35df4500 | 2657 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2658 | |
35df4500 | 2659 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2660 | |
2661 | do_cleanups (old_chain); | |
2662 | return ret; | |
2663 | } | |
2664 | ||
c906108c SS |
2665 | /* Clear the "inserted" flag in all breakpoints. */ |
2666 | ||
25b22b0a | 2667 | void |
fba45db2 | 2668 | mark_breakpoints_out (void) |
c906108c | 2669 | { |
35df4500 | 2670 | struct bp_location *bl, **blp_tmp; |
c906108c | 2671 | |
35df4500 TJB |
2672 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2673 | if (bl->pspace == current_program_space) | |
2674 | bl->inserted = 0; | |
c906108c SS |
2675 | } |
2676 | ||
53a5351d JM |
2677 | /* Clear the "inserted" flag in all breakpoints and delete any |
2678 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2679 | |
2680 | Plus other such housekeeping that has to be done for breakpoints | |
2681 | between runs. | |
2682 | ||
53a5351d JM |
2683 | Note: this function gets called at the end of a run (by |
2684 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2685 | init_wait_for_inferior). */ |
c906108c SS |
2686 | |
2687 | ||
2688 | ||
2689 | void | |
fba45db2 | 2690 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2691 | { |
35df4500 TJB |
2692 | struct breakpoint *b, *b_tmp; |
2693 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2694 | int ix; |
6c95b8df | 2695 | struct program_space *pspace = current_program_space; |
c906108c | 2696 | |
50c71eaf PA |
2697 | /* If breakpoint locations are shared across processes, then there's |
2698 | nothing to do. */ | |
2567c7d9 | 2699 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2700 | return; |
2701 | ||
35df4500 | 2702 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2703 | { |
35df4500 TJB |
2704 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2705 | if (bl->pspace == pspace | |
2706 | && bl->owner->enable_state != bp_permanent) | |
2707 | bl->inserted = 0; | |
6c95b8df | 2708 | } |
075f6582 | 2709 | |
35df4500 | 2710 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2711 | { |
6c95b8df PA |
2712 | if (b->loc && b->loc->pspace != pspace) |
2713 | continue; | |
2714 | ||
c5aa993b JM |
2715 | switch (b->type) |
2716 | { | |
2717 | case bp_call_dummy: | |
c906108c | 2718 | |
c5aa993b | 2719 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2720 | cause problems when the inferior is rerun, so we better get |
2721 | rid of it. */ | |
2722 | ||
2723 | case bp_watchpoint_scope: | |
2724 | ||
2725 | /* Also get rid of scope breakpoints. */ | |
2726 | ||
2727 | case bp_shlib_event: | |
2728 | ||
2729 | /* Also remove solib event breakpoints. Their addresses may | |
2730 | have changed since the last time we ran the program. | |
2731 | Actually we may now be debugging against different target; | |
2732 | and so the solib backend that installed this breakpoint may | |
2733 | not be used in by the target. E.g., | |
2734 | ||
2735 | (gdb) file prog-linux | |
2736 | (gdb) run # native linux target | |
2737 | ... | |
2738 | (gdb) kill | |
2739 | (gdb) file prog-win.exe | |
2740 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2741 | */ | |
c906108c | 2742 | |
c5aa993b JM |
2743 | delete_breakpoint (b); |
2744 | break; | |
c906108c | 2745 | |
c5aa993b JM |
2746 | case bp_watchpoint: |
2747 | case bp_hardware_watchpoint: | |
2748 | case bp_read_watchpoint: | |
2749 | case bp_access_watchpoint: | |
c906108c | 2750 | |
c5aa993b JM |
2751 | /* Likewise for watchpoints on local expressions. */ |
2752 | if (b->exp_valid_block != NULL) | |
2753 | delete_breakpoint (b); | |
967af18d | 2754 | else if (context == inf_starting) |
c860120c | 2755 | { |
4a64f543 MS |
2756 | /* Reset val field to force reread of starting value in |
2757 | insert_breakpoints. */ | |
c860120c PM |
2758 | if (b->val) |
2759 | value_free (b->val); | |
2760 | b->val = NULL; | |
fa4727a6 | 2761 | b->val_valid = 0; |
c860120c | 2762 | } |
c5aa993b JM |
2763 | break; |
2764 | default: | |
c5aa993b JM |
2765 | break; |
2766 | } | |
2767 | } | |
1c5cfe86 PA |
2768 | |
2769 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2770 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2771 | decref_bp_location (&bl); | |
1c5cfe86 | 2772 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2773 | } |
2774 | ||
6c95b8df PA |
2775 | /* These functions concern about actual breakpoints inserted in the |
2776 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2777 | we need to hop over the bkpt --- so we check for address space | |
2778 | match, not program space. */ | |
2779 | ||
c2c6d25f JM |
2780 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2781 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2782 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2783 | permanent breakpoint. | |
2784 | - When continuing from a location with an ordinary breakpoint, we | |
2785 | actually single step once before calling insert_breakpoints. | |
2786 | - When continuing from a localion with a permanent breakpoint, we | |
2787 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2788 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2789 | |
c2c6d25f | 2790 | enum breakpoint_here |
6c95b8df | 2791 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2792 | { |
35df4500 | 2793 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2794 | int any_breakpoint_here = 0; |
c906108c | 2795 | |
35df4500 | 2796 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2797 | { |
35df4500 TJB |
2798 | if (bl->loc_type != bp_loc_software_breakpoint |
2799 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2800 | continue; |
2801 | ||
35df4500 TJB |
2802 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2803 | if ((breakpoint_enabled (bl->owner) | |
2804 | || bl->owner->enable_state == bp_permanent) | |
2805 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2806 | aspace, pc)) |
075f6582 DJ |
2807 | { |
2808 | if (overlay_debugging | |
35df4500 TJB |
2809 | && section_is_overlay (bl->section) |
2810 | && !section_is_mapped (bl->section)) | |
075f6582 | 2811 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2812 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2813 | return permanent_breakpoint_here; |
2814 | else | |
2815 | any_breakpoint_here = 1; | |
2816 | } | |
2817 | } | |
c906108c | 2818 | |
c2c6d25f | 2819 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2820 | } |
2821 | ||
1c5cfe86 PA |
2822 | /* Return true if there's a moribund breakpoint at PC. */ |
2823 | ||
2824 | int | |
6c95b8df | 2825 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2826 | { |
2827 | struct bp_location *loc; | |
2828 | int ix; | |
2829 | ||
2830 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2831 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2832 | aspace, pc)) | |
1c5cfe86 PA |
2833 | return 1; |
2834 | ||
2835 | return 0; | |
2836 | } | |
c2c6d25f | 2837 | |
c36b740a | 2838 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2839 | inserted using regular breakpoint_chain / bp_location array |
2840 | mechanism. This does not check for single-step breakpoints, which | |
2841 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2842 | |
2843 | int | |
4a64f543 MS |
2844 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2845 | CORE_ADDR pc) | |
c906108c | 2846 | { |
35df4500 | 2847 | struct bp_location *bl, **blp_tmp; |
c906108c | 2848 | |
35df4500 | 2849 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2850 | { |
35df4500 TJB |
2851 | if (bl->loc_type != bp_loc_software_breakpoint |
2852 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2853 | continue; |
2854 | ||
35df4500 TJB |
2855 | if (bl->inserted |
2856 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2857 | aspace, pc)) |
075f6582 DJ |
2858 | { |
2859 | if (overlay_debugging | |
35df4500 TJB |
2860 | && section_is_overlay (bl->section) |
2861 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2862 | continue; /* unmapped overlay -- can't be a match */ |
2863 | else | |
2864 | return 1; | |
2865 | } | |
c5aa993b | 2866 | } |
c36b740a VP |
2867 | return 0; |
2868 | } | |
2869 | ||
2870 | /* Returns non-zero iff there's either regular breakpoint | |
2871 | or a single step breakpoint inserted at PC. */ | |
2872 | ||
2873 | int | |
6c95b8df | 2874 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2875 | { |
6c95b8df | 2876 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2877 | return 1; |
c906108c | 2878 | |
6c95b8df | 2879 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2880 | return 1; |
2881 | ||
c906108c SS |
2882 | return 0; |
2883 | } | |
2884 | ||
4fa8626c DJ |
2885 | /* This function returns non-zero iff there is a software breakpoint |
2886 | inserted at PC. */ | |
2887 | ||
2888 | int | |
3e43a32a MS |
2889 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2890 | CORE_ADDR pc) | |
4fa8626c | 2891 | { |
35df4500 | 2892 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2893 | |
35df4500 | 2894 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2895 | { |
35df4500 | 2896 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2897 | continue; |
2898 | ||
35df4500 TJB |
2899 | if (bl->inserted |
2900 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2901 | aspace, pc)) |
4fa8626c DJ |
2902 | { |
2903 | if (overlay_debugging | |
35df4500 TJB |
2904 | && section_is_overlay (bl->section) |
2905 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2906 | continue; /* unmapped overlay -- can't be a match */ |
2907 | else | |
2908 | return 1; | |
2909 | } | |
2910 | } | |
2911 | ||
1aafd4da | 2912 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2913 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2914 | return 1; |
2915 | ||
4fa8626c DJ |
2916 | return 0; |
2917 | } | |
2918 | ||
9093389c PA |
2919 | int |
2920 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2921 | CORE_ADDR addr, ULONGEST len) | |
2922 | { | |
2923 | struct breakpoint *bpt; | |
2924 | ||
2925 | ALL_BREAKPOINTS (bpt) | |
2926 | { | |
2927 | struct bp_location *loc; | |
2928 | ||
2929 | if (bpt->type != bp_hardware_watchpoint | |
2930 | && bpt->type != bp_access_watchpoint) | |
2931 | continue; | |
2932 | ||
2933 | if (!breakpoint_enabled (bpt)) | |
2934 | continue; | |
2935 | ||
2936 | for (loc = bpt->loc; loc; loc = loc->next) | |
2937 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2938 | { | |
2939 | CORE_ADDR l, h; | |
2940 | ||
2941 | /* Check for intersection. */ | |
2942 | l = max (loc->address, addr); | |
2943 | h = min (loc->address + loc->length, addr + len); | |
2944 | if (l < h) | |
2945 | return 1; | |
2946 | } | |
2947 | } | |
2948 | return 0; | |
2949 | } | |
2950 | ||
075f6582 DJ |
2951 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2952 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2953 | |
2954 | int | |
6c95b8df PA |
2955 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2956 | ptid_t ptid) | |
c906108c | 2957 | { |
35df4500 | 2958 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 2959 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2960 | int thread = -1; |
4a306c9a | 2961 | int task = 0; |
a6f1cd96 | 2962 | |
35df4500 | 2963 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2964 | { |
35df4500 TJB |
2965 | if (bl->loc_type != bp_loc_software_breakpoint |
2966 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2967 | continue; |
2968 | ||
35df4500 TJB |
2969 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2970 | if (!breakpoint_enabled (bl->owner) | |
2971 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
2972 | continue; |
2973 | ||
35df4500 | 2974 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
6c95b8df | 2975 | aspace, pc)) |
a6f1cd96 JB |
2976 | continue; |
2977 | ||
35df4500 | 2978 | if (bl->owner->thread != -1) |
075f6582 | 2979 | { |
a6f1cd96 JB |
2980 | /* This is a thread-specific breakpoint. Check that ptid |
2981 | matches that thread. If thread hasn't been computed yet, | |
2982 | it is now time to do so. */ | |
2983 | if (thread == -1) | |
2984 | thread = pid_to_thread_id (ptid); | |
35df4500 | 2985 | if (bl->owner->thread != thread) |
a6f1cd96 | 2986 | continue; |
075f6582 | 2987 | } |
a6f1cd96 | 2988 | |
35df4500 | 2989 | if (bl->owner->task != 0) |
4a306c9a JB |
2990 | { |
2991 | /* This is a task-specific breakpoint. Check that ptid | |
2992 | matches that task. If task hasn't been computed yet, | |
2993 | it is now time to do so. */ | |
2994 | if (task == 0) | |
2995 | task = ada_get_task_number (ptid); | |
35df4500 | 2996 | if (bl->owner->task != task) |
4a306c9a JB |
2997 | continue; |
2998 | } | |
2999 | ||
a6f1cd96 | 3000 | if (overlay_debugging |
35df4500 TJB |
3001 | && section_is_overlay (bl->section) |
3002 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3003 | continue; /* unmapped overlay -- can't be a match */ |
3004 | ||
3005 | return 1; | |
c5aa993b | 3006 | } |
c906108c SS |
3007 | |
3008 | return 0; | |
3009 | } | |
c906108c | 3010 | \f |
c5aa993b | 3011 | |
c906108c SS |
3012 | /* bpstat stuff. External routines' interfaces are documented |
3013 | in breakpoint.h. */ | |
3014 | ||
3015 | int | |
fba45db2 | 3016 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3017 | { |
533be4dd | 3018 | return (ep->type == bp_catchpoint); |
c906108c SS |
3019 | } |
3020 | ||
f431efe5 PA |
3021 | /* Frees any storage that is part of a bpstat. Does not walk the |
3022 | 'next' chain. */ | |
3023 | ||
3024 | static void | |
198757a8 VP |
3025 | bpstat_free (bpstat bs) |
3026 | { | |
3027 | if (bs->old_val != NULL) | |
3028 | value_free (bs->old_val); | |
9add0f1b | 3029 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3030 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3031 | xfree (bs); |
3032 | } | |
3033 | ||
c906108c SS |
3034 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3035 | Also free any storage that is part of a bpstat. */ | |
3036 | ||
3037 | void | |
fba45db2 | 3038 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3039 | { |
3040 | bpstat p; | |
3041 | bpstat q; | |
3042 | ||
3043 | if (bsp == 0) | |
3044 | return; | |
3045 | p = *bsp; | |
3046 | while (p != NULL) | |
3047 | { | |
3048 | q = p->next; | |
198757a8 | 3049 | bpstat_free (p); |
c906108c SS |
3050 | p = q; |
3051 | } | |
3052 | *bsp = NULL; | |
3053 | } | |
3054 | ||
3055 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3056 | is part of the bpstat is copied as well. */ | |
3057 | ||
3058 | bpstat | |
fba45db2 | 3059 | bpstat_copy (bpstat bs) |
c906108c SS |
3060 | { |
3061 | bpstat p = NULL; | |
3062 | bpstat tmp; | |
3063 | bpstat retval = NULL; | |
3064 | ||
3065 | if (bs == NULL) | |
3066 | return bs; | |
3067 | ||
3068 | for (; bs != NULL; bs = bs->next) | |
3069 | { | |
3070 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3071 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3072 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3073 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3074 | if (bs->old_val != NULL) |
3c3185ac JK |
3075 | { |
3076 | tmp->old_val = value_copy (bs->old_val); | |
3077 | release_value (tmp->old_val); | |
3078 | } | |
31cc81e9 | 3079 | |
c906108c SS |
3080 | if (p == NULL) |
3081 | /* This is the first thing in the chain. */ | |
3082 | retval = tmp; | |
3083 | else | |
3084 | p->next = tmp; | |
3085 | p = tmp; | |
3086 | } | |
3087 | p->next = NULL; | |
3088 | return retval; | |
3089 | } | |
3090 | ||
4a64f543 | 3091 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3092 | |
3093 | bpstat | |
fba45db2 | 3094 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3095 | { |
c5aa993b JM |
3096 | if (bsp == NULL) |
3097 | return NULL; | |
c906108c | 3098 | |
c5aa993b JM |
3099 | for (; bsp != NULL; bsp = bsp->next) |
3100 | { | |
f431efe5 | 3101 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3102 | return bsp; |
3103 | } | |
c906108c SS |
3104 | return NULL; |
3105 | } | |
3106 | ||
4a64f543 MS |
3107 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3108 | stopped at. *BSP upon return is a bpstat which points to the | |
3109 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3110 | good for anything but further calls to bpstat_num). | |
3111 | ||
8671a17b PA |
3112 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3113 | Return -1 if stopped at a breakpoint that has been deleted since | |
3114 | we set it. | |
3115 | Return 1 otherwise. */ | |
c906108c SS |
3116 | |
3117 | int | |
8671a17b | 3118 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3119 | { |
3120 | struct breakpoint *b; | |
3121 | ||
3122 | if ((*bsp) == NULL) | |
3123 | return 0; /* No more breakpoint values */ | |
8671a17b | 3124 | |
4a64f543 MS |
3125 | /* We assume we'll never have several bpstats that correspond to a |
3126 | single breakpoint -- otherwise, this function might return the | |
3127 | same number more than once and this will look ugly. */ | |
f431efe5 | 3128 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3129 | *bsp = (*bsp)->next; |
3130 | if (b == NULL) | |
3131 | return -1; /* breakpoint that's been deleted since */ | |
3132 | ||
3133 | *num = b->number; /* We have its number */ | |
3134 | return 1; | |
c906108c SS |
3135 | } |
3136 | ||
3137 | /* Modify BS so that the actions will not be performed. */ | |
3138 | ||
3139 | void | |
fba45db2 | 3140 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3141 | { |
3142 | for (; bs != NULL; bs = bs->next) | |
3143 | { | |
9add0f1b | 3144 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3145 | bs->commands_left = NULL; |
c906108c SS |
3146 | if (bs->old_val != NULL) |
3147 | { | |
3148 | value_free (bs->old_val); | |
3149 | bs->old_val = NULL; | |
3150 | } | |
3151 | } | |
3152 | } | |
3153 | ||
f3b1572e PA |
3154 | /* Called when a command is about to proceed the inferior. */ |
3155 | ||
3156 | static void | |
3157 | breakpoint_about_to_proceed (void) | |
3158 | { | |
3159 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3160 | { | |
3161 | struct thread_info *tp = inferior_thread (); | |
3162 | ||
3163 | /* Allow inferior function calls in breakpoint commands to not | |
3164 | interrupt the command list. When the call finishes | |
3165 | successfully, the inferior will be standing at the same | |
3166 | breakpoint as if nothing happened. */ | |
16c381f0 | 3167 | if (tp->control.in_infcall) |
f3b1572e PA |
3168 | return; |
3169 | } | |
3170 | ||
3171 | breakpoint_proceeded = 1; | |
3172 | } | |
3173 | ||
4a64f543 MS |
3174 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3175 | command. */ | |
c906108c | 3176 | static void |
4efb68b1 | 3177 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3178 | { |
3179 | executing_breakpoint_commands = 0; | |
3180 | } | |
3181 | ||
4a64f543 MS |
3182 | /* Execute all the commands associated with all the breakpoints at |
3183 | this location. Any of these commands could cause the process to | |
3184 | proceed beyond this point, etc. We look out for such changes by | |
3185 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3186 | |
347bddb7 PA |
3187 | Returns true if a breakpoint command resumed the inferior. In that |
3188 | case, it is the caller's responsibility to recall it again with the | |
3189 | bpstat of the current thread. */ | |
3190 | ||
3191 | static int | |
3192 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3193 | { |
3194 | bpstat bs; | |
3195 | struct cleanup *old_chain; | |
347bddb7 | 3196 | int again = 0; |
c906108c SS |
3197 | |
3198 | /* Avoid endless recursion if a `source' command is contained | |
3199 | in bs->commands. */ | |
3200 | if (executing_breakpoint_commands) | |
347bddb7 | 3201 | return 0; |
c906108c SS |
3202 | |
3203 | executing_breakpoint_commands = 1; | |
3204 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3205 | ||
4a64f543 | 3206 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3207 | bs = *bsp; |
3208 | ||
3209 | breakpoint_proceeded = 0; | |
3210 | for (; bs != NULL; bs = bs->next) | |
3211 | { | |
9add0f1b | 3212 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3213 | struct command_line *cmd; |
3214 | struct cleanup *this_cmd_tree_chain; | |
3215 | ||
3216 | /* Take ownership of the BSP's command tree, if it has one. | |
3217 | ||
3218 | The command tree could legitimately contain commands like | |
3219 | 'step' and 'next', which call clear_proceed_status, which | |
3220 | frees stop_bpstat's command tree. To make sure this doesn't | |
3221 | free the tree we're executing out from under us, we need to | |
3222 | take ownership of the tree ourselves. Since a given bpstat's | |
3223 | commands are only executed once, we don't need to copy it; we | |
3224 | can clear the pointer in the bpstat, and make sure we free | |
3225 | the tree when we're done. */ | |
9add0f1b TT |
3226 | ccmd = bs->commands; |
3227 | bs->commands = NULL; | |
3228 | this_cmd_tree_chain | |
3229 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3230 | cmd = bs->commands_left; | |
3231 | bs->commands_left = NULL; | |
6c50ab1c | 3232 | |
c906108c SS |
3233 | while (cmd != NULL) |
3234 | { | |
3235 | execute_control_command (cmd); | |
3236 | ||
3237 | if (breakpoint_proceeded) | |
3238 | break; | |
3239 | else | |
3240 | cmd = cmd->next; | |
3241 | } | |
6c50ab1c JB |
3242 | |
3243 | /* We can free this command tree now. */ | |
3244 | do_cleanups (this_cmd_tree_chain); | |
3245 | ||
c906108c | 3246 | if (breakpoint_proceeded) |
32c1e744 VP |
3247 | { |
3248 | if (target_can_async_p ()) | |
347bddb7 PA |
3249 | /* If we are in async mode, then the target might be still |
3250 | running, not stopped at any breakpoint, so nothing for | |
3251 | us to do here -- just return to the event loop. */ | |
3252 | ; | |
32c1e744 VP |
3253 | else |
3254 | /* In sync mode, when execute_control_command returns | |
3255 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3256 | Breakpoint commands for that stop were not run, since |
3257 | execute_command does not run breakpoint commands -- | |
3258 | only command_line_handler does, but that one is not | |
3259 | involved in execution of breakpoint commands. So, we | |
3260 | can now execute breakpoint commands. It should be | |
3261 | noted that making execute_command do bpstat actions is | |
3262 | not an option -- in this case we'll have recursive | |
3263 | invocation of bpstat for each breakpoint with a | |
3264 | command, and can easily blow up GDB stack. Instead, we | |
3265 | return true, which will trigger the caller to recall us | |
3266 | with the new stop_bpstat. */ | |
3267 | again = 1; | |
3268 | break; | |
32c1e744 | 3269 | } |
c906108c | 3270 | } |
c2b8ed2c | 3271 | do_cleanups (old_chain); |
347bddb7 PA |
3272 | return again; |
3273 | } | |
3274 | ||
3275 | void | |
3276 | bpstat_do_actions (void) | |
3277 | { | |
3278 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3279 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3280 | && target_has_execution | |
3281 | && !is_exited (inferior_ptid) | |
3282 | && !is_executing (inferior_ptid)) | |
3283 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3284 | and only return when it is stopped at the next breakpoint, we | |
3285 | keep doing breakpoint actions until it returns false to | |
3286 | indicate the inferior was not resumed. */ | |
16c381f0 | 3287 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3288 | break; |
c906108c SS |
3289 | } |
3290 | ||
fa4727a6 DJ |
3291 | /* Print out the (old or new) value associated with a watchpoint. */ |
3292 | ||
3293 | static void | |
3294 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3295 | { | |
3296 | if (val == NULL) | |
3297 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3298 | else | |
79a45b7d TT |
3299 | { |
3300 | struct value_print_options opts; | |
3301 | get_user_print_options (&opts); | |
3302 | value_print (val, stream, &opts); | |
3303 | } | |
fa4727a6 DJ |
3304 | } |
3305 | ||
e514a9d6 | 3306 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3307 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3308 | by having it set different print_it values. |
3309 | ||
3310 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3311 | through the bpstat list of things causing this stop, calling the | |
4a64f543 | 3312 | print_bp_stop_message function on each one. The behavior of the |
e514a9d6 | 3313 | print_bp_stop_message function depends on the print_it field of |
4a64f543 | 3314 | bpstat. If such field so indicates, call this function here. |
e514a9d6 JM |
3315 | |
3316 | Return values from this routine (ultimately used by bpstat_print() | |
3317 | and normal_stop() to decide what to do): | |
3318 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3319 | don't print anything else. | |
3320 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3321 | that something to be followed by a location. | |
3322 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3323 | that something to be followed by a location. | |
3324 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3325 | analysis. */ | |
c906108c | 3326 | |
917317f4 | 3327 | static enum print_stop_action |
fba45db2 | 3328 | print_it_typical (bpstat bs) |
c906108c | 3329 | { |
f7545552 | 3330 | struct cleanup *old_chain; |
4f8d1dc6 | 3331 | struct breakpoint *b; |
89f9893c | 3332 | const struct bp_location *bl; |
8b93c638 | 3333 | struct ui_stream *stb; |
f7545552 TT |
3334 | int bp_temp = 0; |
3335 | enum print_stop_action result; | |
3336 | ||
f431efe5 PA |
3337 | gdb_assert (bs->bp_location_at != NULL); |
3338 | ||
3339 | bl = bs->bp_location_at; | |
3340 | b = bs->breakpoint_at; | |
c906108c | 3341 | |
f7545552 TT |
3342 | stb = ui_out_stream_new (uiout); |
3343 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3344 | ||
4f8d1dc6 | 3345 | switch (b->type) |
c906108c | 3346 | { |
e514a9d6 JM |
3347 | case bp_breakpoint: |
3348 | case bp_hardware_breakpoint: | |
f431efe5 | 3349 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3350 | if (bl->address != bl->requested_address) |
3351 | breakpoint_adjustment_warning (bl->requested_address, | |
3352 | bl->address, | |
4f8d1dc6 VP |
3353 | b->number, 1); |
3354 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3355 | if (bp_temp) |
3356 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3357 | else | |
3358 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3359 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3360 | { |
3361 | ui_out_field_string (uiout, "reason", | |
3362 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3363 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3364 | } | |
4f8d1dc6 | 3365 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3366 | ui_out_text (uiout, ", "); |
f7545552 | 3367 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3368 | break; |
3369 | ||
3370 | case bp_shlib_event: | |
917317f4 JM |
3371 | /* Did we stop because the user set the stop_on_solib_events |
3372 | variable? (If so, we report this as a generic, "Stopped due | |
3373 | to shlib event" message.) */ | |
a3f17187 | 3374 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3375 | result = PRINT_NOTHING; |
e514a9d6 JM |
3376 | break; |
3377 | ||
c4093a6a | 3378 | case bp_thread_event: |
4a64f543 | 3379 | /* Not sure how we will get here. |
c4093a6a | 3380 | GDB should not stop for these breakpoints. */ |
a3f17187 | 3381 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3382 | result = PRINT_NOTHING; |
c4093a6a JM |
3383 | break; |
3384 | ||
1900040c | 3385 | case bp_overlay_event: |
4a64f543 | 3386 | /* By analogy with the thread event, GDB should not stop for these. */ |
a3f17187 | 3387 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3388 | result = PRINT_NOTHING; |
1900040c MS |
3389 | break; |
3390 | ||
0fd8e87f UW |
3391 | case bp_longjmp_master: |
3392 | /* These should never be enabled. */ | |
3393 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3394 | result = PRINT_NOTHING; | |
3395 | break; | |
3396 | ||
aa7d318d TT |
3397 | case bp_std_terminate_master: |
3398 | /* These should never be enabled. */ | |
3e43a32a MS |
3399 | printf_filtered (_("std::terminate Master Breakpoint: " |
3400 | "gdb should not stop!\n")); | |
aa7d318d TT |
3401 | result = PRINT_NOTHING; |
3402 | break; | |
3403 | ||
186c406b TT |
3404 | case bp_exception_master: |
3405 | /* These should never be enabled. */ | |
3e43a32a MS |
3406 | printf_filtered (_("Exception Master Breakpoint: " |
3407 | "gdb should not stop!\n")); | |
186c406b TT |
3408 | result = PRINT_NOTHING; |
3409 | break; | |
3410 | ||
e514a9d6 JM |
3411 | case bp_watchpoint: |
3412 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3413 | annotate_watchpoint (b->number); |
3414 | if (ui_out_is_mi_like_p (uiout)) | |
3415 | ui_out_field_string | |
3416 | (uiout, "reason", | |
3417 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3418 | mention (b); | |
f7545552 | 3419 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3420 | ui_out_text (uiout, "\nOld value = "); |
3421 | watchpoint_value_print (bs->old_val, stb->stream); | |
3422 | ui_out_field_stream (uiout, "old", stb); | |
3423 | ui_out_text (uiout, "\nNew value = "); | |
3424 | watchpoint_value_print (b->val, stb->stream); | |
3425 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3426 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3427 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3428 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3429 | break; |
3430 | ||
3431 | case bp_read_watchpoint: | |
9dc5e2a9 | 3432 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3433 | ui_out_field_string |
3434 | (uiout, "reason", | |
3435 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3436 | mention (b); |
f7545552 | 3437 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3438 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3439 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3440 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3441 | ui_out_text (uiout, "\n"); |
f7545552 | 3442 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3443 | break; |
3444 | ||
3445 | case bp_access_watchpoint: | |
fa4727a6 | 3446 | if (bs->old_val != NULL) |
8b93c638 | 3447 | { |
4f8d1dc6 | 3448 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3449 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3450 | ui_out_field_string |
3451 | (uiout, "reason", | |
3452 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3453 | mention (b); |
f7545552 | 3454 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3455 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3456 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3457 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3458 | ui_out_text (uiout, "\nNew value = "); |
3459 | } | |
3460 | else | |
3461 | { | |
4f8d1dc6 | 3462 | mention (b); |
9dc5e2a9 | 3463 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3464 | ui_out_field_string |
3465 | (uiout, "reason", | |
3466 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3467 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3468 | ui_out_text (uiout, "\nValue = "); |
3469 | } | |
fa4727a6 | 3470 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3471 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3472 | ui_out_text (uiout, "\n"); |
f7545552 | 3473 | result = PRINT_UNKNOWN; |
e514a9d6 | 3474 | break; |
4ce44c66 | 3475 | |
e514a9d6 | 3476 | /* Fall through, we don't deal with these types of breakpoints |
4a64f543 | 3477 | here. */ |
e514a9d6 | 3478 | |
11cf8741 | 3479 | case bp_finish: |
9dc5e2a9 | 3480 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3481 | ui_out_field_string |
3482 | (uiout, "reason", | |
3483 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3484 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3485 | break; |
3486 | ||
e514a9d6 | 3487 | case bp_until: |
9dc5e2a9 | 3488 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3489 | ui_out_field_string |
3490 | (uiout, "reason", | |
3491 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3492 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3493 | break; |
3494 | ||
c2d11a7d | 3495 | case bp_none: |
e514a9d6 JM |
3496 | case bp_longjmp: |
3497 | case bp_longjmp_resume: | |
186c406b TT |
3498 | case bp_exception: |
3499 | case bp_exception_resume: | |
e514a9d6 | 3500 | case bp_step_resume: |
e514a9d6 JM |
3501 | case bp_watchpoint_scope: |
3502 | case bp_call_dummy: | |
aa7d318d | 3503 | case bp_std_terminate: |
1042e4c0 | 3504 | case bp_tracepoint: |
7a697b8d | 3505 | case bp_fast_tracepoint: |
4efc6507 | 3506 | case bp_jit_event: |
e514a9d6 | 3507 | default: |
f7545552 TT |
3508 | result = PRINT_UNKNOWN; |
3509 | break; | |
e514a9d6 | 3510 | } |
f7545552 TT |
3511 | |
3512 | do_cleanups (old_chain); | |
3513 | return result; | |
e514a9d6 JM |
3514 | } |
3515 | ||
3516 | /* Generic routine for printing messages indicating why we | |
4a64f543 | 3517 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3518 | 'print_it' in the bpstat structure. Under some circumstances we |
3519 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3520 | normal_stop(). */ |
e514a9d6 JM |
3521 | |
3522 | static enum print_stop_action | |
3523 | print_bp_stop_message (bpstat bs) | |
3524 | { | |
3525 | switch (bs->print_it) | |
3526 | { | |
3527 | case print_it_noop: | |
4a64f543 | 3528 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3529 | return PRINT_UNKNOWN; |
3530 | break; | |
3531 | ||
3532 | case print_it_done: | |
3533 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3534 | relevant messages. */ |
e514a9d6 JM |
3535 | return PRINT_SRC_AND_LOC; |
3536 | break; | |
3537 | ||
3538 | case print_it_normal: | |
4f8d1dc6 | 3539 | { |
f431efe5 PA |
3540 | struct breakpoint *b = bs->breakpoint_at; |
3541 | ||
1a6a67de TJB |
3542 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3543 | which has since been deleted. */ | |
3544 | if (b == NULL) | |
3545 | return PRINT_UNKNOWN; | |
3546 | ||
4f8d1dc6 VP |
3547 | /* Normal case. Call the breakpoint's print_it method, or |
3548 | print_it_typical. */ | |
1a6a67de | 3549 | if (b->ops != NULL && b->ops->print_it != NULL) |
4f8d1dc6 VP |
3550 | return b->ops->print_it (b); |
3551 | else | |
3552 | return print_it_typical (bs); | |
3553 | } | |
3554 | break; | |
3086aeae | 3555 | |
e514a9d6 | 3556 | default: |
8e65ff28 | 3557 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3558 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3559 | break; |
c906108c | 3560 | } |
c906108c SS |
3561 | } |
3562 | ||
e514a9d6 JM |
3563 | /* Print a message indicating what happened. This is called from |
3564 | normal_stop(). The input to this routine is the head of the bpstat | |
3565 | list - a list of the eventpoints that caused this stop. This | |
3566 | routine calls the generic print routine for printing a message | |
3567 | about reasons for stopping. This will print (for example) the | |
3568 | "Breakpoint n," part of the output. The return value of this | |
3569 | routine is one of: | |
c906108c | 3570 | |
4a64f543 | 3571 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3572 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3573 | code to print the location. An example is |
c5aa993b JM |
3574 | "Breakpoint 1, " which should be followed by |
3575 | the location. | |
917317f4 | 3576 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3577 | to also print the location part of the message. |
3578 | An example is the catch/throw messages, which | |
4a64f543 | 3579 | don't require a location appended to the end. |
917317f4 | 3580 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3581 | further info to be printed. */ |
c906108c | 3582 | |
917317f4 | 3583 | enum print_stop_action |
fba45db2 | 3584 | bpstat_print (bpstat bs) |
c906108c SS |
3585 | { |
3586 | int val; | |
c5aa993b | 3587 | |
c906108c | 3588 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3589 | (Currently all watchpoints go on the bpstat whether hit or not. |
3590 | That probably could (should) be changed, provided care is taken | |
c906108c | 3591 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3592 | for (; bs; bs = bs->next) |
3593 | { | |
3594 | val = print_bp_stop_message (bs); | |
3595 | if (val == PRINT_SRC_ONLY | |
3596 | || val == PRINT_SRC_AND_LOC | |
3597 | || val == PRINT_NOTHING) | |
3598 | return val; | |
3599 | } | |
c906108c | 3600 | |
e514a9d6 | 3601 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3602 | with and nothing was printed. */ |
917317f4 | 3603 | return PRINT_UNKNOWN; |
c906108c SS |
3604 | } |
3605 | ||
4a64f543 MS |
3606 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3607 | used inside a catch_errors to evaluate the breakpoint condition. | |
3608 | The argument is a "struct expression *" that has been cast to a | |
3609 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3610 | |
3611 | static int | |
4efb68b1 | 3612 | breakpoint_cond_eval (void *exp) |
c906108c | 3613 | { |
278cd55f | 3614 | struct value *mark = value_mark (); |
c5aa993b | 3615 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3616 | |
c906108c SS |
3617 | value_free_to_mark (mark); |
3618 | return i; | |
3619 | } | |
3620 | ||
5760d0ab | 3621 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3622 | |
3623 | static bpstat | |
5760d0ab | 3624 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3625 | { |
3626 | bpstat bs; | |
3627 | ||
3628 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3629 | bs->next = NULL; |
3630 | **bs_link_pointer = bs; | |
3631 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3632 | bs->breakpoint_at = bl->owner; |
3633 | bs->bp_location_at = bl; | |
3634 | incref_bp_location (bl); | |
c906108c SS |
3635 | /* If the condition is false, etc., don't do the commands. */ |
3636 | bs->commands = NULL; | |
9add0f1b | 3637 | bs->commands_left = NULL; |
c906108c SS |
3638 | bs->old_val = NULL; |
3639 | bs->print_it = print_it_normal; | |
3640 | return bs; | |
3641 | } | |
3642 | \f | |
d983da9c DJ |
3643 | /* The target has stopped with waitstatus WS. Check if any hardware |
3644 | watchpoints have triggered, according to the target. */ | |
3645 | ||
3646 | int | |
3647 | watchpoints_triggered (struct target_waitstatus *ws) | |
3648 | { | |
d92524f1 | 3649 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3650 | CORE_ADDR addr; |
3651 | struct breakpoint *b; | |
3652 | ||
3653 | if (!stopped_by_watchpoint) | |
3654 | { | |
3655 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3656 | as not triggered. */ | |
3657 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3658 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3659 | b->watchpoint_triggered = watch_triggered_no; |
3660 | ||
3661 | return 0; | |
3662 | } | |
3663 | ||
3664 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3665 | { | |
3666 | /* We were stopped by a watchpoint, but we don't know where. | |
3667 | Mark all watchpoints as unknown. */ | |
3668 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3669 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3670 | b->watchpoint_triggered = watch_triggered_unknown; |
3671 | ||
3672 | return stopped_by_watchpoint; | |
3673 | } | |
3674 | ||
3675 | /* The target could report the data address. Mark watchpoints | |
3676 | affected by this data address as triggered, and all others as not | |
3677 | triggered. */ | |
3678 | ||
3679 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3680 | if (is_hardware_watchpoint (b)) |
d983da9c | 3681 | { |
a5606eee | 3682 | struct bp_location *loc; |
d983da9c DJ |
3683 | |
3684 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3685 | for (loc = b->loc; loc; loc = loc->next) |
3686 | /* Exact match not required. Within range is | |
3687 | sufficient. */ | |
5009afc5 AS |
3688 | if (target_watchpoint_addr_within_range (¤t_target, |
3689 | addr, loc->address, | |
3690 | loc->length)) | |
a5606eee VP |
3691 | { |
3692 | b->watchpoint_triggered = watch_triggered_yes; | |
3693 | break; | |
3694 | } | |
d983da9c DJ |
3695 | } |
3696 | ||
3697 | return 1; | |
3698 | } | |
3699 | ||
c906108c SS |
3700 | /* Possible return values for watchpoint_check (this can't be an enum |
3701 | because of check_errors). */ | |
3702 | /* The watchpoint has been deleted. */ | |
3703 | #define WP_DELETED 1 | |
3704 | /* The value has changed. */ | |
3705 | #define WP_VALUE_CHANGED 2 | |
3706 | /* The value has not changed. */ | |
3707 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3708 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3709 | #define WP_IGNORE 4 | |
c906108c SS |
3710 | |
3711 | #define BP_TEMPFLAG 1 | |
3712 | #define BP_HARDWAREFLAG 2 | |
3713 | ||
4a64f543 MS |
3714 | /* Evaluate watchpoint condition expression and check if its value |
3715 | changed. | |
553e4c11 JB |
3716 | |
3717 | P should be a pointer to struct bpstat, but is defined as a void * | |
3718 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3719 | |
3720 | static int | |
4efb68b1 | 3721 | watchpoint_check (void *p) |
c906108c SS |
3722 | { |
3723 | bpstat bs = (bpstat) p; | |
3724 | struct breakpoint *b; | |
3725 | struct frame_info *fr; | |
3726 | int within_current_scope; | |
3727 | ||
f431efe5 | 3728 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3729 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3730 | b = bs->breakpoint_at; |
c906108c | 3731 | |
d0fb5eae JK |
3732 | gdb_assert (is_watchpoint (b)); |
3733 | ||
f6bc2008 PA |
3734 | /* If this is a local watchpoint, we only want to check if the |
3735 | watchpoint frame is in scope if the current thread is the thread | |
3736 | that was used to create the watchpoint. */ | |
3737 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3738 | return WP_IGNORE; |
f6bc2008 | 3739 | |
c906108c SS |
3740 | if (b->exp_valid_block == NULL) |
3741 | within_current_scope = 1; | |
3742 | else | |
3743 | { | |
edb3359d DJ |
3744 | struct frame_info *frame = get_current_frame (); |
3745 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3746 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3747 | ||
4a64f543 MS |
3748 | /* in_function_epilogue_p() returns a non-zero value if we're |
3749 | still in the function but the stack frame has already been | |
3750 | invalidated. Since we can't rely on the values of local | |
3751 | variables after the stack has been destroyed, we are treating | |
3752 | the watchpoint in that state as `not changed' without further | |
3753 | checking. Don't mark watchpoints as changed if the current | |
3754 | frame is in an epilogue - even if they are in some other | |
3755 | frame, our view of the stack is likely to be wrong and | |
3756 | frame_find_by_id could error out. */ | |
a0f49112 | 3757 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3758 | return WP_IGNORE; |
a0f49112 | 3759 | |
101dcfbe | 3760 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3761 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3762 | |
3763 | /* If we've gotten confused in the unwinder, we might have | |
3764 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3765 | if (within_current_scope) |
3766 | { | |
3767 | struct symbol *function; | |
3768 | ||
3769 | function = get_frame_function (fr); | |
3770 | if (function == NULL | |
3771 | || !contained_in (b->exp_valid_block, | |
3772 | SYMBOL_BLOCK_VALUE (function))) | |
3773 | within_current_scope = 0; | |
3774 | } | |
69fbadd5 | 3775 | |
edb3359d | 3776 | if (within_current_scope) |
c906108c SS |
3777 | /* If we end up stopping, the current frame will get selected |
3778 | in normal_stop. So this call to select_frame won't affect | |
3779 | the user. */ | |
0f7d239c | 3780 | select_frame (fr); |
c906108c | 3781 | } |
c5aa993b | 3782 | |
c906108c SS |
3783 | if (within_current_scope) |
3784 | { | |
4a64f543 MS |
3785 | /* We use value_{,free_to_}mark because it could be a *long* |
3786 | time before we return to the command level and call | |
3787 | free_all_values. We can't call free_all_values because we | |
3788 | might be in the middle of evaluating a function call. */ | |
c906108c | 3789 | |
0cf6dd15 | 3790 | int pc = 0; |
278cd55f | 3791 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3792 | struct value *new_val; |
3793 | ||
0cf6dd15 | 3794 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3795 | |
4a64f543 MS |
3796 | /* We use value_equal_contents instead of value_equal because |
3797 | the latter coerces an array to a pointer, thus comparing just | |
3798 | the address of the array instead of its contents. This is | |
3799 | not what we want. */ | |
fa4727a6 | 3800 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3801 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3802 | { |
fa4727a6 DJ |
3803 | if (new_val != NULL) |
3804 | { | |
3805 | release_value (new_val); | |
3806 | value_free_to_mark (mark); | |
3807 | } | |
c906108c SS |
3808 | bs->old_val = b->val; |
3809 | b->val = new_val; | |
fa4727a6 | 3810 | b->val_valid = 1; |
c906108c SS |
3811 | return WP_VALUE_CHANGED; |
3812 | } | |
3813 | else | |
3814 | { | |
60e1c644 | 3815 | /* Nothing changed. */ |
c906108c | 3816 | value_free_to_mark (mark); |
c906108c SS |
3817 | return WP_VALUE_NOT_CHANGED; |
3818 | } | |
3819 | } | |
3820 | else | |
3821 | { | |
3822 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3823 | if we temporarily ignored the watchpoint, then when |
3824 | we reenter the block in which it is valid it contains | |
3825 | garbage (in the case of a function, it may have two | |
3826 | garbage values, one before and one after the prologue). | |
3827 | So we can't even detect the first assignment to it and | |
3828 | watch after that (since the garbage may or may not equal | |
3829 | the first value assigned). */ | |
4ce44c66 JM |
3830 | /* We print all the stop information in print_it_typical(), but |
3831 | in this case, by the time we call print_it_typical() this bp | |
4a64f543 MS |
3832 | will be deleted already. So we have no choice but print the |
3833 | information here. */ | |
9dc5e2a9 | 3834 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3835 | ui_out_field_string |
3836 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3837 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3838 | ui_out_field_int (uiout, "wpnum", b->number); |
3e43a32a MS |
3839 | ui_out_text (uiout, |
3840 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3841 | which its expression is valid.\n"); |
4ce44c66 | 3842 | |
d0fb5eae | 3843 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3844 | |
3845 | return WP_DELETED; | |
3846 | } | |
3847 | } | |
3848 | ||
18a18393 VP |
3849 | /* Return true if it looks like target has stopped due to hitting |
3850 | breakpoint location BL. This function does not check if we | |
3851 | should stop, only if BL explains the stop. */ | |
3852 | static int | |
6c95b8df PA |
3853 | bpstat_check_location (const struct bp_location *bl, |
3854 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3855 | { |
3856 | struct breakpoint *b = bl->owner; | |
3857 | ||
2bdf28a0 JK |
3858 | /* BL is from existing struct breakpoint. */ |
3859 | gdb_assert (b != NULL); | |
3860 | ||
e8595ef6 SS |
3861 | /* By definition, the inferior does not report stops at |
3862 | tracepoints. */ | |
d77f58be | 3863 | if (is_tracepoint (b)) |
e8595ef6 SS |
3864 | return 0; |
3865 | ||
cc60f2e3 | 3866 | if (!is_watchpoint (b) |
18a18393 | 3867 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3868 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3869 | { |
6c95b8df PA |
3870 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3871 | aspace, bp_addr)) | |
18a18393 VP |
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 | } | |
cc60f2e3 | 3878 | |
18a18393 VP |
3879 | /* Continuable hardware watchpoints are treated as non-existent if the |
3880 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3881 | some data address). Otherwise gdb won't stop on a break instruction | |
3882 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3883 | been defined. Also skip watchpoints which we know did not trigger | |
3884 | (did not match the data address). */ | |
cc60f2e3 PA |
3885 | |
3886 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3887 | && b->watchpoint_triggered == watch_triggered_no) |
3888 | return 0; | |
3889 | ||
3890 | if (b->type == bp_hardware_breakpoint) | |
3891 | { | |
3892 | if (bl->address != bp_addr) | |
3893 | return 0; | |
3894 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3895 | && section_is_overlay (bl->section) |
18a18393 VP |
3896 | && !section_is_mapped (bl->section)) |
3897 | return 0; | |
3898 | } | |
ce78b96d | 3899 | |
ce78b96d JB |
3900 | if (b->type == bp_catchpoint) |
3901 | { | |
3902 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3903 | if (!b->ops->breakpoint_hit (b)) | |
3904 | return 0; | |
3905 | } | |
3906 | ||
18a18393 VP |
3907 | return 1; |
3908 | } | |
3909 | ||
3910 | /* If BS refers to a watchpoint, determine if the watched values | |
3911 | has actually changed, and we should stop. If not, set BS->stop | |
3912 | to 0. */ | |
3913 | static void | |
3914 | bpstat_check_watchpoint (bpstat bs) | |
3915 | { | |
2bdf28a0 JK |
3916 | const struct bp_location *bl; |
3917 | struct breakpoint *b; | |
3918 | ||
3919 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3920 | bl = bs->bp_location_at; |
2bdf28a0 | 3921 | gdb_assert (bl != NULL); |
f431efe5 | 3922 | b = bs->breakpoint_at; |
2bdf28a0 | 3923 | gdb_assert (b != NULL); |
18a18393 | 3924 | |
cc60f2e3 | 3925 | if (is_watchpoint (b)) |
18a18393 | 3926 | { |
18a18393 VP |
3927 | int must_check_value = 0; |
3928 | ||
3929 | if (b->type == bp_watchpoint) | |
3930 | /* For a software watchpoint, we must always check the | |
3931 | watched value. */ | |
3932 | must_check_value = 1; | |
3933 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3934 | /* We have a hardware watchpoint (read, write, or access) | |
3935 | and the target earlier reported an address watched by | |
3936 | this watchpoint. */ | |
3937 | must_check_value = 1; | |
3938 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3939 | && b->type == bp_hardware_watchpoint) | |
3940 | /* We were stopped by a hardware watchpoint, but the target could | |
3941 | not report the data address. We must check the watchpoint's | |
3942 | value. Access and read watchpoints are out of luck; without | |
3943 | a data address, we can't figure it out. */ | |
3944 | must_check_value = 1; | |
3945 | ||
3946 | if (must_check_value) | |
3947 | { | |
3e43a32a MS |
3948 | char *message |
3949 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3950 | b->number); | |
18a18393 VP |
3951 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3952 | int e = catch_errors (watchpoint_check, bs, message, | |
3953 | RETURN_MASK_ALL); | |
3954 | do_cleanups (cleanups); | |
3955 | switch (e) | |
3956 | { | |
3957 | case WP_DELETED: | |
3958 | /* We've already printed what needs to be printed. */ | |
3959 | bs->print_it = print_it_done; | |
3960 | /* Stop. */ | |
3961 | break; | |
60e1c644 PA |
3962 | case WP_IGNORE: |
3963 | bs->print_it = print_it_noop; | |
3964 | bs->stop = 0; | |
3965 | break; | |
18a18393 VP |
3966 | case WP_VALUE_CHANGED: |
3967 | if (b->type == bp_read_watchpoint) | |
3968 | { | |
85d721b8 PA |
3969 | /* There are two cases to consider here: |
3970 | ||
4a64f543 | 3971 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3972 | In that case, trust the target, and always report |
3973 | the watchpoint hit to the user. Even though | |
3974 | reads don't cause value changes, the value may | |
3975 | have changed since the last time it was read, and | |
3976 | since we're not trapping writes, we will not see | |
3977 | those, and as such we should ignore our notion of | |
3978 | old value. | |
3979 | ||
4a64f543 | 3980 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3981 | reads and writes. There are two ways this may |
3982 | happen: | |
3983 | ||
4a64f543 | 3984 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3985 | reads only, but can break on accesses (reads or |
3986 | writes), such as e.g., x86. We detect this case | |
3987 | at the time we try to insert read watchpoints. | |
3988 | ||
4a64f543 | 3989 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3990 | watchpoints, but, the user set an access or write |
3991 | watchpoint watching the same memory as this read | |
3992 | watchpoint. | |
3993 | ||
3994 | If we're watching memory writes as well as reads, | |
3995 | ignore watchpoint hits when we find that the | |
3996 | value hasn't changed, as reads don't cause | |
3997 | changes. This still gives false positives when | |
3998 | the program writes the same value to memory as | |
3999 | what there was already in memory (we will confuse | |
4000 | it for a read), but it's much better than | |
4001 | nothing. */ | |
4002 | ||
4003 | int other_write_watchpoint = 0; | |
4004 | ||
4005 | if (bl->watchpoint_type == hw_read) | |
4006 | { | |
4007 | struct breakpoint *other_b; | |
4008 | ||
4009 | ALL_BREAKPOINTS (other_b) | |
4010 | if ((other_b->type == bp_hardware_watchpoint | |
4011 | || other_b->type == bp_access_watchpoint) | |
4012 | && (other_b->watchpoint_triggered | |
4013 | == watch_triggered_yes)) | |
4014 | { | |
4015 | other_write_watchpoint = 1; | |
4016 | break; | |
4017 | } | |
4018 | } | |
4019 | ||
4020 | if (other_write_watchpoint | |
4021 | || bl->watchpoint_type == hw_access) | |
4022 | { | |
4023 | /* We're watching the same memory for writes, | |
4024 | and the value changed since the last time we | |
4025 | updated it, so this trap must be for a write. | |
4026 | Ignore it. */ | |
4027 | bs->print_it = print_it_noop; | |
4028 | bs->stop = 0; | |
4029 | } | |
18a18393 VP |
4030 | } |
4031 | break; | |
4032 | case WP_VALUE_NOT_CHANGED: | |
4033 | if (b->type == bp_hardware_watchpoint | |
4034 | || b->type == bp_watchpoint) | |
4035 | { | |
4036 | /* Don't stop: write watchpoints shouldn't fire if | |
4037 | the value hasn't changed. */ | |
4038 | bs->print_it = print_it_noop; | |
4039 | bs->stop = 0; | |
4040 | } | |
4041 | /* Stop. */ | |
4042 | break; | |
4043 | default: | |
4044 | /* Can't happen. */ | |
4045 | case 0: | |
4046 | /* Error from catch_errors. */ | |
4047 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
d0fb5eae | 4048 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
4049 | /* We've already printed what needs to be printed. */ |
4050 | bs->print_it = print_it_done; | |
4051 | break; | |
4052 | } | |
4053 | } | |
4054 | else /* must_check_value == 0 */ | |
4055 | { | |
4056 | /* This is a case where some watchpoint(s) triggered, but | |
4057 | not at the address of this watchpoint, or else no | |
4058 | watchpoint triggered after all. So don't print | |
4059 | anything for this watchpoint. */ | |
4060 | bs->print_it = print_it_noop; | |
4061 | bs->stop = 0; | |
4062 | } | |
4063 | } | |
4064 | } | |
4065 | ||
4066 | ||
4067 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4068 | of breakpoint referred to by BS. If we should not stop for this | |
4069 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4070 | |
18a18393 VP |
4071 | static void |
4072 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4073 | { | |
4074 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4075 | const struct bp_location *bl; |
4076 | struct breakpoint *b; | |
4077 | ||
4078 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4079 | bl = bs->bp_location_at; |
2bdf28a0 | 4080 | gdb_assert (bl != NULL); |
f431efe5 | 4081 | b = bs->breakpoint_at; |
2bdf28a0 | 4082 | gdb_assert (b != NULL); |
18a18393 VP |
4083 | |
4084 | if (frame_id_p (b->frame_id) | |
edb3359d | 4085 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4086 | bs->stop = 0; |
4087 | else if (bs->stop) | |
4088 | { | |
4089 | int value_is_zero = 0; | |
60e1c644 PA |
4090 | struct expression *cond; |
4091 | ||
7371cf6d PM |
4092 | /* Evaluate Python breakpoints that have a "stop" |
4093 | method implemented. */ | |
4094 | if (b->py_bp_object) | |
4095 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4096 | ||
60e1c644 PA |
4097 | if (is_watchpoint (b)) |
4098 | cond = b->cond_exp; | |
4099 | else | |
4100 | cond = bl->cond; | |
4101 | ||
f431efe5 | 4102 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4103 | { |
60e1c644 PA |
4104 | int within_current_scope = 1; |
4105 | ||
c5bc3a77 DJ |
4106 | /* We use value_mark and value_free_to_mark because it could |
4107 | be a long time before we return to the command level and | |
4108 | call free_all_values. We can't call free_all_values | |
4109 | because we might be in the middle of evaluating a | |
4110 | function call. */ | |
4111 | struct value *mark = value_mark (); | |
4112 | ||
edb3359d DJ |
4113 | /* Need to select the frame, with all that implies so that |
4114 | the conditions will have the right context. Because we | |
4115 | use the frame, we will not see an inlined function's | |
4116 | variables when we arrive at a breakpoint at the start | |
4117 | of the inlined function; the current frame will be the | |
4118 | call site. */ | |
60e1c644 PA |
4119 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
4120 | select_frame (get_current_frame ()); | |
4121 | else | |
4122 | { | |
4123 | struct frame_info *frame; | |
4124 | ||
4125 | /* For local watchpoint expressions, which particular | |
4126 | instance of a local is being watched matters, so we | |
4127 | keep track of the frame to evaluate the expression | |
4128 | in. To evaluate the condition however, it doesn't | |
4129 | really matter which instantiation of the function | |
4130 | where the condition makes sense triggers the | |
4131 | watchpoint. This allows an expression like "watch | |
4132 | global if q > 10" set in `func', catch writes to | |
4133 | global on all threads that call `func', or catch | |
4134 | writes on all recursive calls of `func' by a single | |
4135 | thread. We simply always evaluate the condition in | |
4136 | the innermost frame that's executing where it makes | |
4137 | sense to evaluate the condition. It seems | |
4138 | intuitive. */ | |
4139 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4140 | if (frame != NULL) | |
4141 | select_frame (frame); | |
4142 | else | |
4143 | within_current_scope = 0; | |
4144 | } | |
4145 | if (within_current_scope) | |
4146 | value_is_zero | |
4147 | = catch_errors (breakpoint_cond_eval, cond, | |
4148 | "Error in testing breakpoint condition:\n", | |
4149 | RETURN_MASK_ALL); | |
4150 | else | |
4151 | { | |
4152 | warning (_("Watchpoint condition cannot be tested " | |
4153 | "in the current scope")); | |
4154 | /* If we failed to set the right context for this | |
4155 | watchpoint, unconditionally report it. */ | |
4156 | value_is_zero = 0; | |
4157 | } | |
4a64f543 | 4158 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4159 | value_free_to_mark (mark); |
18a18393 | 4160 | } |
60e1c644 PA |
4161 | |
4162 | if (cond && value_is_zero) | |
18a18393 VP |
4163 | { |
4164 | bs->stop = 0; | |
4165 | } | |
4166 | else if (b->thread != -1 && b->thread != thread_id) | |
4167 | { | |
4168 | bs->stop = 0; | |
4169 | } | |
4170 | else if (b->ignore_count > 0) | |
4171 | { | |
4172 | b->ignore_count--; | |
4173 | annotate_ignore_count_change (); | |
4174 | bs->stop = 0; | |
4a64f543 | 4175 | /* Increase the hit count even though we don't stop. */ |
18a18393 VP |
4176 | ++(b->hit_count); |
4177 | } | |
4178 | } | |
4179 | } | |
4180 | ||
4181 | ||
9709f61c | 4182 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4183 | BP_ADDR in thread PTID. |
c906108c | 4184 | |
d983da9c | 4185 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4186 | don't understand this stop. Result is a chain of bpstat's such |
4187 | that: | |
c906108c | 4188 | |
c5aa993b | 4189 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4190 | |
c5aa993b | 4191 | if we understand why we stopped, the result is not null. |
c906108c | 4192 | |
c5aa993b JM |
4193 | Each element of the chain refers to a particular breakpoint or |
4194 | watchpoint at which we have stopped. (We may have stopped for | |
4195 | several reasons concurrently.) | |
c906108c | 4196 | |
c5aa993b JM |
4197 | Each element of the chain has valid next, breakpoint_at, |
4198 | commands, FIXME??? fields. */ | |
c906108c SS |
4199 | |
4200 | bpstat | |
6c95b8df PA |
4201 | bpstat_stop_status (struct address_space *aspace, |
4202 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4203 | { |
0d381245 | 4204 | struct breakpoint *b = NULL; |
afe38095 | 4205 | struct bp_location *bl; |
20874c92 | 4206 | struct bp_location *loc; |
5760d0ab JK |
4207 | /* First item of allocated bpstat's. */ |
4208 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4209 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4210 | bpstat bs; |
20874c92 | 4211 | int ix; |
429374b8 | 4212 | int need_remove_insert; |
f431efe5 | 4213 | int removed_any; |
c906108c | 4214 | |
f431efe5 PA |
4215 | /* First, build the bpstat chain with locations that explain a |
4216 | target stop, while being careful to not set the target running, | |
4217 | as that may invalidate locations (in particular watchpoint | |
4218 | locations are recreated). Resuming will happen here with | |
4219 | breakpoint conditions or watchpoint expressions that include | |
4220 | inferior function calls. */ | |
c5aa993b | 4221 | |
429374b8 JK |
4222 | ALL_BREAKPOINTS (b) |
4223 | { | |
4224 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4225 | continue; | |
a5606eee | 4226 | |
429374b8 JK |
4227 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4228 | { | |
4a64f543 MS |
4229 | /* For hardware watchpoints, we look only at the first |
4230 | location. The watchpoint_check function will work on the | |
4231 | entire expression, not the individual locations. For | |
4232 | read watchpoints, the watchpoints_triggered function has | |
4233 | checked all locations already. */ | |
429374b8 JK |
4234 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4235 | break; | |
18a18393 | 4236 | |
429374b8 JK |
4237 | if (bl->shlib_disabled) |
4238 | continue; | |
c5aa993b | 4239 | |
429374b8 JK |
4240 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4241 | continue; | |
c5aa993b | 4242 | |
4a64f543 MS |
4243 | /* Come here if it's a watchpoint, or if the break address |
4244 | matches. */ | |
c5aa993b | 4245 | |
4a64f543 MS |
4246 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4247 | explain stop. */ | |
c5aa993b | 4248 | |
f431efe5 PA |
4249 | /* Assume we stop. Should we find a watchpoint that is not |
4250 | actually triggered, or if the condition of the breakpoint | |
4251 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4252 | bs->stop = 1; |
4253 | bs->print = 1; | |
d983da9c | 4254 | |
f431efe5 PA |
4255 | /* If this is a scope breakpoint, mark the associated |
4256 | watchpoint as triggered so that we will handle the | |
4257 | out-of-scope event. We'll get to the watchpoint next | |
4258 | iteration. */ | |
d0fb5eae | 4259 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
f431efe5 PA |
4260 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; |
4261 | } | |
4262 | } | |
4263 | ||
4264 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4265 | { | |
4266 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, | |
4267 | aspace, bp_addr)) | |
4268 | { | |
5760d0ab | 4269 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4270 | /* For hits of moribund locations, we should just proceed. */ |
4271 | bs->stop = 0; | |
4272 | bs->print = 0; | |
4273 | bs->print_it = print_it_noop; | |
4274 | } | |
4275 | } | |
4276 | ||
f431efe5 PA |
4277 | /* Now go through the locations that caused the target to stop, and |
4278 | check whether we're interested in reporting this stop to higher | |
4279 | layers, or whether we should resume the target transparently. */ | |
4280 | ||
4281 | removed_any = 0; | |
4282 | ||
5760d0ab | 4283 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4284 | { |
4285 | if (!bs->stop) | |
4286 | continue; | |
4287 | ||
4288 | bpstat_check_watchpoint (bs); | |
4289 | if (!bs->stop) | |
4290 | continue; | |
4291 | ||
4292 | b = bs->breakpoint_at; | |
18a18393 | 4293 | |
429374b8 | 4294 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d | 4295 | || b->type == bp_longjmp_master |
186c406b TT |
4296 | || b->type == bp_std_terminate_master |
4297 | || b->type == bp_exception_master) | |
429374b8 JK |
4298 | /* We do not stop for these. */ |
4299 | bs->stop = 0; | |
4300 | else | |
4301 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4302 | |
429374b8 JK |
4303 | if (bs->stop) |
4304 | { | |
4305 | ++(b->hit_count); | |
c906108c | 4306 | |
4a64f543 | 4307 | /* We will stop here. */ |
429374b8 JK |
4308 | if (b->disposition == disp_disable) |
4309 | { | |
4310 | if (b->enable_state != bp_permanent) | |
4311 | b->enable_state = bp_disabled; | |
f431efe5 | 4312 | removed_any = 1; |
429374b8 JK |
4313 | } |
4314 | if (b->silent) | |
4315 | bs->print = 0; | |
4316 | bs->commands = b->commands; | |
9add0f1b TT |
4317 | incref_counted_command_line (bs->commands); |
4318 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4319 | if (bs->commands_left | |
4320 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4321 | || (xdb_commands | |
4322 | && strcmp ("Q", | |
4323 | bs->commands_left->line) == 0))) | |
429374b8 | 4324 | { |
9add0f1b | 4325 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4326 | bs->print = 0; |
4327 | } | |
429374b8 JK |
4328 | } |
4329 | ||
4330 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4331 | if (bs->stop == 0 || bs->print == 0) | |
4332 | bs->print_it = print_it_noop; | |
429374b8 | 4333 | } |
876fa593 | 4334 | |
d983da9c DJ |
4335 | /* If we aren't stopping, the value of some hardware watchpoint may |
4336 | not have changed, but the intermediate memory locations we are | |
4337 | watching may have. Don't bother if we're stopping; this will get | |
4338 | done later. */ | |
d832cb68 | 4339 | need_remove_insert = 0; |
5760d0ab JK |
4340 | if (! bpstat_causes_stop (bs_head)) |
4341 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4342 | if (!bs->stop |
f431efe5 PA |
4343 | && bs->breakpoint_at |
4344 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4345 | { |
4a64f543 | 4346 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4347 | need_remove_insert = 1; |
d983da9c DJ |
4348 | } |
4349 | ||
d832cb68 | 4350 | if (need_remove_insert) |
2d134ed3 | 4351 | update_global_location_list (1); |
f431efe5 PA |
4352 | else if (removed_any) |
4353 | update_global_location_list (0); | |
d832cb68 | 4354 | |
5760d0ab | 4355 | return bs_head; |
c906108c | 4356 | } |
628fe4e4 JK |
4357 | |
4358 | static void | |
4359 | handle_jit_event (void) | |
4360 | { | |
4361 | struct frame_info *frame; | |
4362 | struct gdbarch *gdbarch; | |
4363 | ||
4364 | /* Switch terminal for any messages produced by | |
4365 | breakpoint_re_set. */ | |
4366 | target_terminal_ours_for_output (); | |
4367 | ||
4368 | frame = get_current_frame (); | |
4369 | gdbarch = get_frame_arch (frame); | |
4370 | ||
4371 | jit_event_handler (gdbarch); | |
4372 | ||
4373 | target_terminal_inferior (); | |
4374 | } | |
4375 | ||
4376 | /* Prepare WHAT final decision for infrun. */ | |
4377 | ||
4378 | /* Decide what infrun needs to do with this bpstat. */ | |
4379 | ||
c906108c | 4380 | struct bpstat_what |
fba45db2 | 4381 | bpstat_what (bpstat bs) |
c906108c | 4382 | { |
c906108c | 4383 | struct bpstat_what retval; |
628fe4e4 JK |
4384 | /* We need to defer calling `solib_add', as adding new symbols |
4385 | resets breakpoints, which in turn deletes breakpoint locations, | |
4386 | and hence may clear unprocessed entries in the BS chain. */ | |
4387 | int shlib_event = 0; | |
4388 | int jit_event = 0; | |
c906108c | 4389 | |
628fe4e4 | 4390 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4391 | retval.call_dummy = STOP_NONE; |
186c406b | 4392 | retval.is_longjmp = 0; |
628fe4e4 | 4393 | |
c906108c SS |
4394 | for (; bs != NULL; bs = bs->next) |
4395 | { | |
628fe4e4 JK |
4396 | /* Extract this BS's action. After processing each BS, we check |
4397 | if its action overrides all we've seem so far. */ | |
4398 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4399 | enum bptype bptype; | |
4400 | ||
c906108c | 4401 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4402 | { |
4403 | /* I suspect this can happen if it was a momentary | |
4404 | breakpoint which has since been deleted. */ | |
4405 | bptype = bp_none; | |
4406 | } | |
f431efe5 | 4407 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4408 | bptype = bp_none; |
20874c92 | 4409 | else |
f431efe5 | 4410 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4411 | |
4412 | switch (bptype) | |
c906108c SS |
4413 | { |
4414 | case bp_none: | |
628fe4e4 | 4415 | break; |
c906108c SS |
4416 | case bp_breakpoint: |
4417 | case bp_hardware_breakpoint: | |
4418 | case bp_until: | |
4419 | case bp_finish: | |
4420 | if (bs->stop) | |
4421 | { | |
4422 | if (bs->print) | |
628fe4e4 | 4423 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4424 | else |
628fe4e4 | 4425 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4426 | } |
4427 | else | |
628fe4e4 | 4428 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4429 | break; |
4430 | case bp_watchpoint: | |
4431 | case bp_hardware_watchpoint: | |
4432 | case bp_read_watchpoint: | |
4433 | case bp_access_watchpoint: | |
4434 | if (bs->stop) | |
4435 | { | |
4436 | if (bs->print) | |
628fe4e4 | 4437 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4438 | else |
628fe4e4 | 4439 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4440 | } |
4441 | else | |
628fe4e4 JK |
4442 | { |
4443 | /* There was a watchpoint, but we're not stopping. | |
4444 | This requires no further action. */ | |
4445 | } | |
c906108c SS |
4446 | break; |
4447 | case bp_longjmp: | |
186c406b | 4448 | case bp_exception: |
628fe4e4 | 4449 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4450 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4451 | break; |
4452 | case bp_longjmp_resume: | |
186c406b | 4453 | case bp_exception_resume: |
628fe4e4 | 4454 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4455 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4456 | break; |
4457 | case bp_step_resume: | |
4458 | if (bs->stop) | |
628fe4e4 JK |
4459 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4460 | else | |
c906108c | 4461 | { |
628fe4e4 JK |
4462 | /* It is for the wrong frame. */ |
4463 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4464 | } |
c906108c | 4465 | break; |
c906108c | 4466 | case bp_watchpoint_scope: |
c4093a6a | 4467 | case bp_thread_event: |
1900040c | 4468 | case bp_overlay_event: |
0fd8e87f | 4469 | case bp_longjmp_master: |
aa7d318d | 4470 | case bp_std_terminate_master: |
186c406b | 4471 | case bp_exception_master: |
628fe4e4 | 4472 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4473 | break; |
ce78b96d | 4474 | case bp_catchpoint: |
c5aa993b JM |
4475 | if (bs->stop) |
4476 | { | |
4477 | if (bs->print) | |
628fe4e4 | 4478 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4479 | else |
628fe4e4 | 4480 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4481 | } |
4482 | else | |
628fe4e4 JK |
4483 | { |
4484 | /* There was a catchpoint, but we're not stopping. | |
4485 | This requires no further action. */ | |
4486 | } | |
4487 | break; | |
4488 | case bp_shlib_event: | |
4489 | shlib_event = 1; | |
4490 | ||
4491 | /* If requested, stop when the dynamic linker notifies GDB | |
4492 | of events. This allows the user to get control and place | |
4493 | breakpoints in initializer routines for dynamically | |
4494 | loaded objects (among other things). */ | |
4495 | if (stop_on_solib_events) | |
4496 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4497 | else | |
4498 | this_action = BPSTAT_WHAT_SINGLE; | |
4499 | break; | |
4500 | case bp_jit_event: | |
4501 | jit_event = 1; | |
4502 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4503 | break; |
c906108c | 4504 | case bp_call_dummy: |
53a5351d JM |
4505 | /* Make sure the action is stop (silent or noisy), |
4506 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4507 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4508 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4509 | break; |
4510 | case bp_std_terminate: | |
4511 | /* Make sure the action is stop (silent or noisy), | |
4512 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4513 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4514 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4515 | break; |
1042e4c0 | 4516 | case bp_tracepoint: |
7a697b8d | 4517 | case bp_fast_tracepoint: |
0fb4aa4b | 4518 | case bp_static_tracepoint: |
1042e4c0 SS |
4519 | /* Tracepoint hits should not be reported back to GDB, and |
4520 | if one got through somehow, it should have been filtered | |
4521 | out already. */ | |
4522 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4523 | _("bpstat_what: tracepoint encountered")); |
628fe4e4 JK |
4524 | default: |
4525 | internal_error (__FILE__, __LINE__, | |
4526 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4527 | } |
628fe4e4 JK |
4528 | |
4529 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4530 | } |
628fe4e4 JK |
4531 | |
4532 | if (shlib_event) | |
4533 | { | |
4534 | if (debug_infrun) | |
4535 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4536 | ||
4537 | /* Check for any newly added shared libraries if we're supposed | |
4538 | to be adding them automatically. */ | |
4539 | ||
4540 | /* Switch terminal for any messages produced by | |
4541 | breakpoint_re_set. */ | |
4542 | target_terminal_ours_for_output (); | |
4543 | ||
4544 | #ifdef SOLIB_ADD | |
4545 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4546 | #else | |
4547 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4548 | #endif | |
4549 | ||
4550 | target_terminal_inferior (); | |
4551 | } | |
4552 | ||
4553 | if (jit_event) | |
4554 | { | |
4555 | if (debug_infrun) | |
4556 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4557 | ||
4558 | handle_jit_event (); | |
4559 | } | |
4560 | ||
c906108c SS |
4561 | return retval; |
4562 | } | |
4563 | ||
4564 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4565 | without hardware support). This isn't related to a specific bpstat, | |
4566 | just to things like whether watchpoints are set. */ | |
4567 | ||
c5aa993b | 4568 | int |
fba45db2 | 4569 | bpstat_should_step (void) |
c906108c SS |
4570 | { |
4571 | struct breakpoint *b; | |
cc59ec59 | 4572 | |
c906108c | 4573 | ALL_BREAKPOINTS (b) |
717a8278 | 4574 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4575 | return 1; |
c906108c SS |
4576 | return 0; |
4577 | } | |
4578 | ||
67822962 PA |
4579 | int |
4580 | bpstat_causes_stop (bpstat bs) | |
4581 | { | |
4582 | for (; bs != NULL; bs = bs->next) | |
4583 | if (bs->stop) | |
4584 | return 1; | |
4585 | ||
4586 | return 0; | |
4587 | } | |
4588 | ||
c906108c | 4589 | \f |
c5aa993b | 4590 | |
170b53b2 UW |
4591 | /* Compute a string of spaces suitable to indent the next line |
4592 | so it starts at the position corresponding to the table column | |
4593 | named COL_NAME in the currently active table of UIOUT. */ | |
4594 | ||
4595 | static char * | |
4596 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4597 | { | |
4598 | static char wrap_indent[80]; | |
4599 | int i, total_width, width, align; | |
4600 | char *text; | |
4601 | ||
4602 | total_width = 0; | |
4603 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4604 | { | |
4605 | if (strcmp (text, col_name) == 0) | |
4606 | { | |
4607 | gdb_assert (total_width < sizeof wrap_indent); | |
4608 | memset (wrap_indent, ' ', total_width); | |
4609 | wrap_indent[total_width] = 0; | |
4610 | ||
4611 | return wrap_indent; | |
4612 | } | |
4613 | ||
4614 | total_width += width + 1; | |
4615 | } | |
4616 | ||
4617 | return NULL; | |
4618 | } | |
4619 | ||
859825b8 JK |
4620 | /* Print the LOC location out of the list of B->LOC locations. */ |
4621 | ||
170b53b2 UW |
4622 | static void |
4623 | print_breakpoint_location (struct breakpoint *b, | |
4624 | struct bp_location *loc) | |
0d381245 | 4625 | { |
6c95b8df PA |
4626 | struct cleanup *old_chain = save_current_program_space (); |
4627 | ||
859825b8 JK |
4628 | if (loc != NULL && loc->shlib_disabled) |
4629 | loc = NULL; | |
4630 | ||
6c95b8df PA |
4631 | if (loc != NULL) |
4632 | set_current_program_space (loc->pspace); | |
4633 | ||
56435ebe TT |
4634 | if (b->display_canonical) |
4635 | ui_out_field_string (uiout, "what", b->addr_string); | |
4636 | else if (b->source_file && loc) | |
0d381245 VP |
4637 | { |
4638 | struct symbol *sym | |
4639 | = find_pc_sect_function (loc->address, loc->section); | |
4640 | if (sym) | |
4641 | { | |
4642 | ui_out_text (uiout, "in "); | |
4643 | ui_out_field_string (uiout, "func", | |
4644 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4645 | ui_out_text (uiout, " "); |
4646 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4647 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4648 | } |
4649 | ui_out_field_string (uiout, "file", b->source_file); | |
4650 | ui_out_text (uiout, ":"); | |
4651 | ||
4652 | if (ui_out_is_mi_like_p (uiout)) | |
4653 | { | |
4654 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4655 | char *fullname = symtab_to_fullname (sal.symtab); | |
4656 | ||
4657 | if (fullname) | |
4658 | ui_out_field_string (uiout, "fullname", fullname); | |
4659 | } | |
4660 | ||
4661 | ui_out_field_int (uiout, "line", b->line_number); | |
4662 | } | |
859825b8 | 4663 | else if (loc) |
0d381245 | 4664 | { |
170b53b2 UW |
4665 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4666 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4667 | ||
22e722e1 DJ |
4668 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4669 | demangle, ""); | |
0d381245 | 4670 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4671 | |
4672 | do_cleanups (stb_chain); | |
0d381245 | 4673 | } |
859825b8 JK |
4674 | else |
4675 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4676 | |
4677 | do_cleanups (old_chain); | |
0d381245 VP |
4678 | } |
4679 | ||
269b11a2 PA |
4680 | static const char * |
4681 | bptype_string (enum bptype type) | |
c906108c | 4682 | { |
c4093a6a JM |
4683 | struct ep_type_description |
4684 | { | |
4685 | enum bptype type; | |
4686 | char *description; | |
4687 | }; | |
4688 | static struct ep_type_description bptypes[] = | |
c906108c | 4689 | { |
c5aa993b JM |
4690 | {bp_none, "?deleted?"}, |
4691 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4692 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4693 | {bp_until, "until"}, |
4694 | {bp_finish, "finish"}, | |
4695 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4696 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4697 | {bp_read_watchpoint, "read watchpoint"}, |
4698 | {bp_access_watchpoint, "acc watchpoint"}, | |
4699 | {bp_longjmp, "longjmp"}, | |
4700 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4701 | {bp_exception, "exception"}, |
4702 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4703 | {bp_step_resume, "step resume"}, |
c5aa993b JM |
4704 | {bp_watchpoint_scope, "watchpoint scope"}, |
4705 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4706 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4707 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4708 | {bp_thread_event, "thread events"}, |
1900040c | 4709 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4710 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4711 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4712 | {bp_exception_master, "exception master"}, |
ce78b96d | 4713 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4714 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4715 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4716 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4717 | {bp_jit_event, "jit events"}, |
c5aa993b | 4718 | }; |
269b11a2 PA |
4719 | |
4720 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4721 | || ((int) type != bptypes[(int) type].type)) | |
4722 | internal_error (__FILE__, __LINE__, | |
4723 | _("bptypes table does not describe type #%d."), | |
4724 | (int) type); | |
4725 | ||
4726 | return bptypes[(int) type].description; | |
4727 | } | |
4728 | ||
4729 | /* Print B to gdb_stdout. */ | |
4730 | ||
4731 | static void | |
4732 | print_one_breakpoint_location (struct breakpoint *b, | |
4733 | struct bp_location *loc, | |
4734 | int loc_number, | |
4735 | struct bp_location **last_loc, | |
269b11a2 PA |
4736 | int allflag) |
4737 | { | |
4738 | struct command_line *l; | |
c2c6d25f | 4739 | static char bpenables[] = "nynny"; |
3b31d625 | 4740 | struct cleanup *bkpt_chain; |
c906108c | 4741 | |
0d381245 VP |
4742 | int header_of_multiple = 0; |
4743 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4744 | struct value_print_options opts; |
4745 | ||
4746 | get_user_print_options (&opts); | |
0d381245 VP |
4747 | |
4748 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4749 | /* See comment in print_one_breakpoint concerning treatment of |
4750 | breakpoints with single disabled location. */ | |
0d381245 VP |
4751 | if (loc == NULL |
4752 | && (b->loc != NULL | |
4753 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4754 | header_of_multiple = 1; | |
4755 | if (loc == NULL) | |
4756 | loc = b->loc; | |
4757 | ||
c4093a6a | 4758 | annotate_record (); |
3b31d625 | 4759 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4760 | |
4761 | /* 1 */ | |
4762 | annotate_field (0); | |
0d381245 VP |
4763 | if (part_of_multiple) |
4764 | { | |
4765 | char *formatted; | |
0c6773c1 | 4766 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4767 | ui_out_field_string (uiout, "number", formatted); |
4768 | xfree (formatted); | |
4769 | } | |
4770 | else | |
4771 | { | |
4772 | ui_out_field_int (uiout, "number", b->number); | |
4773 | } | |
c4093a6a JM |
4774 | |
4775 | /* 2 */ | |
4776 | annotate_field (1); | |
0d381245 VP |
4777 | if (part_of_multiple) |
4778 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4779 | else |
4780 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4781 | |
4782 | /* 3 */ | |
4783 | annotate_field (2); | |
0d381245 VP |
4784 | if (part_of_multiple) |
4785 | ui_out_field_skip (uiout, "disp"); | |
4786 | else | |
2cec12e5 | 4787 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4788 | |
c4093a6a JM |
4789 | |
4790 | /* 4 */ | |
4791 | annotate_field (3); | |
0d381245 | 4792 | if (part_of_multiple) |
54e52265 | 4793 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4794 | else |
4a64f543 MS |
4795 | ui_out_field_fmt (uiout, "enabled", "%c", |
4796 | bpenables[(int) b->enable_state]); | |
54e52265 | 4797 | ui_out_spaces (uiout, 2); |
0d381245 | 4798 | |
c4093a6a JM |
4799 | |
4800 | /* 5 and 6 */ | |
3086aeae | 4801 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4802 | { |
4a64f543 MS |
4803 | /* Although the print_one can possibly print all locations, |
4804 | calling it here is not likely to get any nice result. So, | |
4805 | make sure there's just one location. */ | |
0d381245 | 4806 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4807 | b->ops->print_one (b, last_loc); |
0d381245 | 4808 | } |
3086aeae DJ |
4809 | else |
4810 | switch (b->type) | |
4811 | { | |
4812 | case bp_none: | |
4813 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4814 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4815 | break; |
c906108c | 4816 | |
3086aeae DJ |
4817 | case bp_watchpoint: |
4818 | case bp_hardware_watchpoint: | |
4819 | case bp_read_watchpoint: | |
4820 | case bp_access_watchpoint: | |
4821 | /* Field 4, the address, is omitted (which makes the columns | |
4822 | not line up too nicely with the headers, but the effect | |
4823 | is relatively readable). */ | |
79a45b7d | 4824 | if (opts.addressprint) |
3086aeae DJ |
4825 | ui_out_field_skip (uiout, "addr"); |
4826 | annotate_field (5); | |
fa8a61dc | 4827 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4828 | break; |
4829 | ||
3086aeae DJ |
4830 | case bp_breakpoint: |
4831 | case bp_hardware_breakpoint: | |
4832 | case bp_until: | |
4833 | case bp_finish: | |
4834 | case bp_longjmp: | |
4835 | case bp_longjmp_resume: | |
186c406b TT |
4836 | case bp_exception: |
4837 | case bp_exception_resume: | |
3086aeae | 4838 | case bp_step_resume: |
3086aeae DJ |
4839 | case bp_watchpoint_scope: |
4840 | case bp_call_dummy: | |
aa7d318d | 4841 | case bp_std_terminate: |
3086aeae DJ |
4842 | case bp_shlib_event: |
4843 | case bp_thread_event: | |
4844 | case bp_overlay_event: | |
0fd8e87f | 4845 | case bp_longjmp_master: |
aa7d318d | 4846 | case bp_std_terminate_master: |
186c406b | 4847 | case bp_exception_master: |
1042e4c0 | 4848 | case bp_tracepoint: |
7a697b8d | 4849 | case bp_fast_tracepoint: |
0fb4aa4b | 4850 | case bp_static_tracepoint: |
4efc6507 | 4851 | case bp_jit_event: |
79a45b7d | 4852 | if (opts.addressprint) |
3086aeae DJ |
4853 | { |
4854 | annotate_field (4); | |
54e52265 | 4855 | if (header_of_multiple) |
0d381245 | 4856 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4857 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4858 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4859 | else |
5af949e3 UW |
4860 | ui_out_field_core_addr (uiout, "addr", |
4861 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4862 | } |
4863 | annotate_field (5); | |
0d381245 | 4864 | if (!header_of_multiple) |
170b53b2 | 4865 | print_breakpoint_location (b, loc); |
0d381245 | 4866 | if (b->loc) |
a6d9a66e | 4867 | *last_loc = b->loc; |
3086aeae DJ |
4868 | break; |
4869 | } | |
c906108c | 4870 | |
6c95b8df PA |
4871 | |
4872 | /* For backward compatibility, don't display inferiors unless there | |
4873 | are several. */ | |
4874 | if (loc != NULL | |
4875 | && !header_of_multiple | |
4876 | && (allflag | |
4877 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4878 | && (number_of_program_spaces () > 1 | |
4879 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4880 | /* LOC is for existing B, it cannot be in |
4881 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4882 | && loc->owner->type != bp_catchpoint))) |
4883 | { | |
4884 | struct inferior *inf; | |
4885 | int first = 1; | |
4886 | ||
4887 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4888 | { | |
4889 | if (inf->pspace == loc->pspace) | |
4890 | { | |
4891 | if (first) | |
4892 | { | |
4893 | first = 0; | |
4894 | ui_out_text (uiout, " inf "); | |
4895 | } | |
4896 | else | |
4897 | ui_out_text (uiout, ", "); | |
4898 | ui_out_text (uiout, plongest (inf->num)); | |
4899 | } | |
4900 | } | |
4901 | } | |
4902 | ||
4a306c9a | 4903 | if (!part_of_multiple) |
c4093a6a | 4904 | { |
4a306c9a JB |
4905 | if (b->thread != -1) |
4906 | { | |
4907 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4908 | "stop only in" line a little further down. */ |
4a306c9a JB |
4909 | ui_out_text (uiout, " thread "); |
4910 | ui_out_field_int (uiout, "thread", b->thread); | |
4911 | } | |
4912 | else if (b->task != 0) | |
4913 | { | |
4914 | ui_out_text (uiout, " task "); | |
4915 | ui_out_field_int (uiout, "task", b->task); | |
4916 | } | |
c4093a6a JM |
4917 | } |
4918 | ||
8b93c638 | 4919 | ui_out_text (uiout, "\n"); |
c4093a6a | 4920 | |
0fb4aa4b PA |
4921 | if (!part_of_multiple && b->static_trace_marker_id) |
4922 | { | |
4923 | gdb_assert (b->type == bp_static_tracepoint); | |
4924 | ||
4925 | ui_out_text (uiout, "\tmarker id is "); | |
4926 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
4927 | b->static_trace_marker_id); | |
4928 | ui_out_text (uiout, "\n"); | |
4929 | } | |
4930 | ||
0d381245 | 4931 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4932 | { |
4933 | annotate_field (6); | |
8b93c638 | 4934 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4935 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4936 | the frame ID. */ | |
5af949e3 UW |
4937 | ui_out_field_core_addr (uiout, "frame", |
4938 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4939 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4940 | } |
4941 | ||
0d381245 | 4942 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4943 | { |
f7f9143b JB |
4944 | /* We do not print the condition for Ada exception catchpoints |
4945 | because the condition is an internal implementation detail | |
4946 | that we do not want to expose to the user. */ | |
c4093a6a | 4947 | annotate_field (7); |
d77f58be | 4948 | if (is_tracepoint (b)) |
1042e4c0 SS |
4949 | ui_out_text (uiout, "\ttrace only if "); |
4950 | else | |
4951 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4952 | ui_out_field_string (uiout, "cond", b->cond_string); |
4953 | ui_out_text (uiout, "\n"); | |
4954 | } | |
4955 | ||
0d381245 | 4956 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4957 | { |
4a64f543 | 4958 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4959 | ui_out_text (uiout, "\tstop only in thread "); |
4960 | ui_out_field_int (uiout, "thread", b->thread); | |
4961 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4962 | } |
4963 | ||
63c715c6 | 4964 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4965 | { |
4a64f543 | 4966 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4967 | if (ep_is_catchpoint (b)) |
4968 | ui_out_text (uiout, "\tcatchpoint"); | |
4969 | else | |
4970 | ui_out_text (uiout, "\tbreakpoint"); | |
4971 | ui_out_text (uiout, " already hit "); | |
4972 | ui_out_field_int (uiout, "times", b->hit_count); | |
4973 | if (b->hit_count == 1) | |
4974 | ui_out_text (uiout, " time\n"); | |
4975 | else | |
4976 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4977 | } |
4978 | ||
4a64f543 MS |
4979 | /* Output the count also if it is zero, but only if this is mi. |
4980 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4981 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4982 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4983 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4984 | |
0d381245 | 4985 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4986 | { |
4987 | annotate_field (8); | |
8b93c638 JM |
4988 | ui_out_text (uiout, "\tignore next "); |
4989 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4990 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4991 | } |
059fb39f | 4992 | |
9add0f1b | 4993 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4994 | if (!part_of_multiple && l) |
c4093a6a | 4995 | { |
3b31d625 EZ |
4996 | struct cleanup *script_chain; |
4997 | ||
c4093a6a | 4998 | annotate_field (9); |
3b31d625 | 4999 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 5000 | print_command_lines (uiout, l, 4); |
3b31d625 | 5001 | do_cleanups (script_chain); |
c4093a6a | 5002 | } |
d24317b4 | 5003 | |
1042e4c0 SS |
5004 | if (!part_of_multiple && b->pass_count) |
5005 | { | |
5006 | annotate_field (10); | |
5007 | ui_out_text (uiout, "\tpass count "); | |
5008 | ui_out_field_int (uiout, "pass", b->pass_count); | |
5009 | ui_out_text (uiout, " \n"); | |
5010 | } | |
5011 | ||
d24317b4 VP |
5012 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5013 | { | |
5014 | if (b->addr_string) | |
5015 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
5016 | else if (b->exp_string) | |
5017 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
5018 | } | |
5019 | ||
3b31d625 | 5020 | do_cleanups (bkpt_chain); |
c4093a6a | 5021 | } |
c5aa993b | 5022 | |
0d381245 VP |
5023 | static void |
5024 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5025 | struct bp_location **last_loc, |
6c95b8df | 5026 | int allflag) |
0d381245 | 5027 | { |
12c5a436 | 5028 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
0d381245 VP |
5029 | |
5030 | /* If this breakpoint has custom print function, | |
5031 | it's already printed. Otherwise, print individual | |
5032 | locations, if any. */ | |
5033 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5034 | { | |
4a64f543 MS |
5035 | /* If breakpoint has a single location that is disabled, we |
5036 | print it as if it had several locations, since otherwise it's | |
5037 | hard to represent "breakpoint enabled, location disabled" | |
5038 | situation. | |
5039 | ||
5040 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5041 | internally, that's not a property exposed to user. */ |
0d381245 | 5042 | if (b->loc |
a5606eee | 5043 | && !is_hardware_watchpoint (b) |
0d381245 | 5044 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 5045 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
5046 | { |
5047 | struct bp_location *loc; | |
5048 | int n = 1; | |
5049 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
12c5a436 | 5050 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
0d381245 VP |
5051 | } |
5052 | } | |
5053 | } | |
5054 | ||
a6d9a66e UW |
5055 | static int |
5056 | breakpoint_address_bits (struct breakpoint *b) | |
5057 | { | |
5058 | int print_address_bits = 0; | |
5059 | struct bp_location *loc; | |
5060 | ||
5061 | for (loc = b->loc; loc; loc = loc->next) | |
5062 | { | |
c7437ca6 PA |
5063 | int addr_bit; |
5064 | ||
5065 | /* Software watchpoints that aren't watching memory don't have | |
5066 | an address to print. */ | |
5067 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5068 | continue; | |
5069 | ||
5070 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5071 | if (addr_bit > print_address_bits) |
5072 | print_address_bits = addr_bit; | |
5073 | } | |
5074 | ||
5075 | return print_address_bits; | |
5076 | } | |
0d381245 | 5077 | |
c4093a6a JM |
5078 | struct captured_breakpoint_query_args |
5079 | { | |
5080 | int bnum; | |
5081 | }; | |
c5aa993b | 5082 | |
c4093a6a | 5083 | static int |
2b65245e | 5084 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5085 | { |
5086 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5087 | struct breakpoint *b; |
a6d9a66e | 5088 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5089 | |
c4093a6a JM |
5090 | ALL_BREAKPOINTS (b) |
5091 | { | |
5092 | if (args->bnum == b->number) | |
c5aa993b | 5093 | { |
12c5a436 | 5094 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5095 | return GDB_RC_OK; |
c5aa993b | 5096 | } |
c4093a6a JM |
5097 | } |
5098 | return GDB_RC_NONE; | |
5099 | } | |
c5aa993b | 5100 | |
c4093a6a | 5101 | enum gdb_rc |
4a64f543 MS |
5102 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5103 | char **error_message) | |
c4093a6a JM |
5104 | { |
5105 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5106 | |
c4093a6a JM |
5107 | args.bnum = bnum; |
5108 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5109 | an error. */ |
b0b13bb4 DJ |
5110 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5111 | error_message, RETURN_MASK_ALL) < 0) | |
5112 | return GDB_RC_FAIL; | |
5113 | else | |
5114 | return GDB_RC_OK; | |
c4093a6a | 5115 | } |
c5aa993b | 5116 | |
7f3b0473 | 5117 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4a64f543 | 5118 | catchpoints, et.al.). */ |
7f3b0473 AC |
5119 | |
5120 | static int | |
5121 | user_settable_breakpoint (const struct breakpoint *b) | |
5122 | { | |
5123 | return (b->type == bp_breakpoint | |
ce78b96d | 5124 | || b->type == bp_catchpoint |
7f3b0473 | 5125 | || b->type == bp_hardware_breakpoint |
d77f58be | 5126 | || is_tracepoint (b) |
cc60f2e3 | 5127 | || is_watchpoint (b)); |
7f3b0473 | 5128 | } |
4a64f543 | 5129 | |
09d682a4 TT |
5130 | /* Return true if this breakpoint was set by the user, false if it is |
5131 | internal or momentary. */ | |
5132 | ||
5133 | int | |
5134 | user_breakpoint_p (struct breakpoint *b) | |
5135 | { | |
5136 | return user_settable_breakpoint (b) && b->number > 0; | |
5137 | } | |
5138 | ||
7f3b0473 | 5139 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5140 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5141 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5142 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5143 | ones for which it returns non-zero. Return the total number of | |
5144 | breakpoints listed. */ | |
c906108c | 5145 | |
d77f58be | 5146 | static int |
e5a67952 | 5147 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5148 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5149 | { |
52f0bd74 | 5150 | struct breakpoint *b; |
a6d9a66e | 5151 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5152 | int nr_printable_breakpoints; |
3b31d625 | 5153 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5154 | struct value_print_options opts; |
a6d9a66e | 5155 | int print_address_bits = 0; |
269b11a2 PA |
5156 | int print_type_col_width = 14; |
5157 | ||
79a45b7d TT |
5158 | get_user_print_options (&opts); |
5159 | ||
4a64f543 MS |
5160 | /* Compute the number of rows in the table, as well as the size |
5161 | required for address fields. */ | |
7f3b0473 AC |
5162 | nr_printable_breakpoints = 0; |
5163 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5164 | { |
5165 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5166 | if (filter && !filter (b)) | |
5167 | continue; | |
5168 | ||
5169 | /* If we have an "args" string, it is a list of breakpoints to | |
5170 | accept. Skip the others. */ | |
5171 | if (args != NULL && *args != '\0') | |
5172 | { | |
5173 | if (allflag && parse_and_eval_long (args) != b->number) | |
5174 | continue; | |
5175 | if (!allflag && !number_is_in_list (args, b->number)) | |
5176 | continue; | |
5177 | } | |
269b11a2 | 5178 | |
e5a67952 MS |
5179 | if (allflag || user_breakpoint_p (b)) |
5180 | { | |
5181 | int addr_bit, type_len; | |
a6d9a66e | 5182 | |
e5a67952 MS |
5183 | addr_bit = breakpoint_address_bits (b); |
5184 | if (addr_bit > print_address_bits) | |
5185 | print_address_bits = addr_bit; | |
269b11a2 | 5186 | |
e5a67952 MS |
5187 | type_len = strlen (bptype_string (b->type)); |
5188 | if (type_len > print_type_col_width) | |
5189 | print_type_col_width = type_len; | |
5190 | ||
5191 | nr_printable_breakpoints++; | |
5192 | } | |
5193 | } | |
7f3b0473 | 5194 | |
79a45b7d | 5195 | if (opts.addressprint) |
3b31d625 | 5196 | bkpttbl_chain |
3e43a32a MS |
5197 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5198 | nr_printable_breakpoints, | |
3b31d625 | 5199 | "BreakpointTable"); |
8b93c638 | 5200 | else |
3b31d625 | 5201 | bkpttbl_chain |
3e43a32a MS |
5202 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5203 | nr_printable_breakpoints, | |
3b31d625 | 5204 | "BreakpointTable"); |
8b93c638 | 5205 | |
7f3b0473 | 5206 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5207 | annotate_breakpoints_headers (); |
5208 | if (nr_printable_breakpoints > 0) | |
5209 | annotate_field (0); | |
4a64f543 | 5210 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5211 | if (nr_printable_breakpoints > 0) |
5212 | annotate_field (1); | |
269b11a2 | 5213 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5214 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5215 | if (nr_printable_breakpoints > 0) |
5216 | annotate_field (2); | |
4a64f543 | 5217 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5218 | if (nr_printable_breakpoints > 0) |
5219 | annotate_field (3); | |
54e52265 | 5220 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5221 | if (opts.addressprint) |
e5a67952 MS |
5222 | { |
5223 | if (nr_printable_breakpoints > 0) | |
5224 | annotate_field (4); | |
5225 | if (print_address_bits <= 32) | |
5226 | ui_out_table_header (uiout, 10, ui_left, | |
5227 | "addr", "Address"); /* 5 */ | |
5228 | else | |
5229 | ui_out_table_header (uiout, 18, ui_left, | |
5230 | "addr", "Address"); /* 5 */ | |
5231 | } | |
d7faa9e7 AC |
5232 | if (nr_printable_breakpoints > 0) |
5233 | annotate_field (5); | |
5234 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5235 | ui_out_table_body (uiout); | |
5236 | if (nr_printable_breakpoints > 0) | |
5237 | annotate_breakpoints_table (); | |
7f3b0473 | 5238 | |
c4093a6a | 5239 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5240 | { |
5241 | QUIT; | |
5242 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5243 | if (filter && !filter (b)) | |
5244 | continue; | |
5245 | ||
5246 | /* If we have an "args" string, it is a list of breakpoints to | |
5247 | accept. Skip the others. */ | |
5248 | ||
5249 | if (args != NULL && *args != '\0') | |
5250 | { | |
5251 | if (allflag) /* maintenance info breakpoint */ | |
5252 | { | |
5253 | if (parse_and_eval_long (args) != b->number) | |
5254 | continue; | |
5255 | } | |
5256 | else /* all others */ | |
5257 | { | |
5258 | if (!number_is_in_list (args, b->number)) | |
5259 | continue; | |
5260 | } | |
5261 | } | |
5262 | /* We only print out user settable breakpoints unless the | |
5263 | allflag is set. */ | |
5264 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5265 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5266 | } |
5267 | ||
3b31d625 | 5268 | do_cleanups (bkpttbl_chain); |
698384cd | 5269 | |
7f3b0473 | 5270 | if (nr_printable_breakpoints == 0) |
c906108c | 5271 | { |
4a64f543 MS |
5272 | /* If there's a filter, let the caller decide how to report |
5273 | empty list. */ | |
d77f58be SS |
5274 | if (!filter) |
5275 | { | |
e5a67952 | 5276 | if (args == NULL || *args == '\0') |
d77f58be SS |
5277 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5278 | else | |
4a64f543 | 5279 | ui_out_message (uiout, 0, |
e5a67952 MS |
5280 | "No breakpoint or watchpoint matching '%s'.\n", |
5281 | args); | |
d77f58be | 5282 | } |
c906108c SS |
5283 | } |
5284 | else | |
c4093a6a | 5285 | { |
a6d9a66e UW |
5286 | if (last_loc && !server_command) |
5287 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5288 | } |
c906108c | 5289 | |
4a64f543 | 5290 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5291 | there have been breakpoints? */ |
c906108c | 5292 | annotate_breakpoints_table_end (); |
d77f58be SS |
5293 | |
5294 | return nr_printable_breakpoints; | |
c906108c SS |
5295 | } |
5296 | ||
ad443146 SS |
5297 | /* Display the value of default-collect in a way that is generally |
5298 | compatible with the breakpoint list. */ | |
5299 | ||
5300 | static void | |
5301 | default_collect_info (void) | |
5302 | { | |
5303 | /* If it has no value (which is frequently the case), say nothing; a | |
5304 | message like "No default-collect." gets in user's face when it's | |
5305 | not wanted. */ | |
5306 | if (!*default_collect) | |
5307 | return; | |
5308 | ||
5309 | /* The following phrase lines up nicely with per-tracepoint collect | |
5310 | actions. */ | |
5311 | ui_out_text (uiout, "default collect "); | |
5312 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5313 | ui_out_text (uiout, " \n"); | |
5314 | } | |
5315 | ||
c906108c | 5316 | static void |
e5a67952 | 5317 | breakpoints_info (char *args, int from_tty) |
c906108c | 5318 | { |
e5a67952 | 5319 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5320 | |
5321 | default_collect_info (); | |
d77f58be SS |
5322 | } |
5323 | ||
5324 | static void | |
e5a67952 | 5325 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5326 | { |
e5a67952 | 5327 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
d77f58be SS |
5328 | |
5329 | if (num_printed == 0) | |
5330 | { | |
e5a67952 | 5331 | if (args == NULL || *args == '\0') |
d77f58be SS |
5332 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5333 | else | |
e5a67952 | 5334 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5335 | } |
c906108c SS |
5336 | } |
5337 | ||
7a292a7a | 5338 | static void |
e5a67952 | 5339 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5340 | { |
e5a67952 | 5341 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5342 | |
5343 | default_collect_info (); | |
c906108c SS |
5344 | } |
5345 | ||
0d381245 | 5346 | static int |
714835d5 | 5347 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5348 | struct program_space *pspace, |
714835d5 | 5349 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5350 | { |
5351 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5352 | |
0d381245 VP |
5353 | for (; bl; bl = bl->next) |
5354 | { | |
6c95b8df PA |
5355 | if (bl->pspace == pspace |
5356 | && bl->address == pc | |
0d381245 VP |
5357 | && (!overlay_debugging || bl->section == section)) |
5358 | return 1; | |
5359 | } | |
5360 | return 0; | |
5361 | } | |
5362 | ||
6c95b8df PA |
5363 | /* Print a message describing any breakpoints set at PC. This |
5364 | concerns with logical breakpoints, so we match program spaces, not | |
5365 | address spaces. */ | |
c906108c SS |
5366 | |
5367 | static void | |
6c95b8df PA |
5368 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5369 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5370 | struct obj_section *section, int thread) |
c906108c | 5371 | { |
52f0bd74 AC |
5372 | int others = 0; |
5373 | struct breakpoint *b; | |
c906108c SS |
5374 | |
5375 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5376 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5377 | if (others > 0) |
5378 | { | |
a3f17187 AC |
5379 | if (others == 1) |
5380 | printf_filtered (_("Note: breakpoint ")); | |
5381 | else /* if (others == ???) */ | |
5382 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5383 | ALL_BREAKPOINTS (b) |
6c95b8df | 5384 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5385 | { |
5386 | others--; | |
5387 | printf_filtered ("%d", b->number); | |
5388 | if (b->thread == -1 && thread != -1) | |
5389 | printf_filtered (" (all threads)"); | |
5390 | else if (b->thread != -1) | |
5391 | printf_filtered (" (thread %d)", b->thread); | |
5392 | printf_filtered ("%s%s ", | |
059fb39f | 5393 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5394 | || b->enable_state == bp_call_disabled |
5395 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5396 | ? " (disabled)" |
5397 | : b->enable_state == bp_permanent | |
5398 | ? " (permanent)" | |
5399 | : ""), | |
5400 | (others > 1) ? "," | |
5401 | : ((others == 1) ? " and" : "")); | |
5402 | } | |
a3f17187 | 5403 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5404 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5405 | printf_filtered (".\n"); |
5406 | } | |
5407 | } | |
5408 | \f | |
5409 | /* Set the default place to put a breakpoint | |
5410 | for the `break' command with no arguments. */ | |
5411 | ||
5412 | void | |
6c95b8df PA |
5413 | set_default_breakpoint (int valid, struct program_space *pspace, |
5414 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5415 | int line) |
c906108c SS |
5416 | { |
5417 | default_breakpoint_valid = valid; | |
6c95b8df | 5418 | default_breakpoint_pspace = pspace; |
c906108c SS |
5419 | default_breakpoint_address = addr; |
5420 | default_breakpoint_symtab = symtab; | |
5421 | default_breakpoint_line = line; | |
5422 | } | |
5423 | ||
e4f237da KB |
5424 | /* Return true iff it is meaningful to use the address member of |
5425 | BPT. For some breakpoint types, the address member is irrelevant | |
5426 | and it makes no sense to attempt to compare it to other addresses | |
5427 | (or use it for any other purpose either). | |
5428 | ||
4a64f543 MS |
5429 | More specifically, each of the following breakpoint types will |
5430 | always have a zero valued address and we don't want to mark | |
5431 | breakpoints of any of these types to be a duplicate of an actual | |
5432 | breakpoint at address zero: | |
e4f237da KB |
5433 | |
5434 | bp_watchpoint | |
2d134ed3 PA |
5435 | bp_catchpoint |
5436 | ||
5437 | */ | |
e4f237da KB |
5438 | |
5439 | static int | |
5440 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5441 | { | |
5442 | enum bptype type = bpt->type; | |
5443 | ||
2d134ed3 PA |
5444 | return (type != bp_watchpoint && type != bp_catchpoint); |
5445 | } | |
5446 | ||
5447 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5448 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5449 | ||
5450 | static int | |
4a64f543 MS |
5451 | watchpoint_locations_match (struct bp_location *loc1, |
5452 | struct bp_location *loc2) | |
2d134ed3 | 5453 | { |
2bdf28a0 JK |
5454 | /* Both of them must not be in moribund_locations. */ |
5455 | gdb_assert (loc1->owner != NULL); | |
5456 | gdb_assert (loc2->owner != NULL); | |
5457 | ||
4a64f543 MS |
5458 | /* If the target can evaluate the condition expression in hardware, |
5459 | then we we need to insert both watchpoints even if they are at | |
5460 | the same place. Otherwise the watchpoint will only trigger when | |
5461 | the condition of whichever watchpoint was inserted evaluates to | |
5462 | true, not giving a chance for GDB to check the condition of the | |
5463 | other watchpoint. */ | |
0cf6dd15 | 5464 | if ((loc1->owner->cond_exp |
4a64f543 MS |
5465 | && target_can_accel_watchpoint_condition (loc1->address, |
5466 | loc1->length, | |
0cf6dd15 TJB |
5467 | loc1->watchpoint_type, |
5468 | loc1->owner->cond_exp)) | |
5469 | || (loc2->owner->cond_exp | |
4a64f543 MS |
5470 | && target_can_accel_watchpoint_condition (loc2->address, |
5471 | loc2->length, | |
0cf6dd15 TJB |
5472 | loc2->watchpoint_type, |
5473 | loc2->owner->cond_exp))) | |
5474 | return 0; | |
5475 | ||
85d721b8 PA |
5476 | /* Note that this checks the owner's type, not the location's. In |
5477 | case the target does not support read watchpoints, but does | |
5478 | support access watchpoints, we'll have bp_read_watchpoint | |
5479 | watchpoints with hw_access locations. Those should be considered | |
5480 | duplicates of hw_read locations. The hw_read locations will | |
5481 | become hw_access locations later. */ | |
2d134ed3 PA |
5482 | return (loc1->owner->type == loc2->owner->type |
5483 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5484 | && loc1->address == loc2->address | |
5485 | && loc1->length == loc2->length); | |
e4f237da KB |
5486 | } |
5487 | ||
6c95b8df PA |
5488 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5489 | same breakpoint location. In most targets, this can only be true | |
5490 | if ASPACE1 matches ASPACE2. On targets that have global | |
5491 | breakpoints, the address space doesn't really matter. */ | |
5492 | ||
5493 | static int | |
5494 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5495 | struct address_space *aspace2, CORE_ADDR addr2) | |
5496 | { | |
5497 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5498 | || aspace1 == aspace2) | |
5499 | && addr1 == addr2); | |
5500 | } | |
5501 | ||
2d134ed3 PA |
5502 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5503 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5504 | represent the same location. */ | |
5505 | ||
5506 | static int | |
4a64f543 MS |
5507 | breakpoint_locations_match (struct bp_location *loc1, |
5508 | struct bp_location *loc2) | |
2d134ed3 | 5509 | { |
2bdf28a0 JK |
5510 | int hw_point1, hw_point2; |
5511 | ||
5512 | /* Both of them must not be in moribund_locations. */ | |
5513 | gdb_assert (loc1->owner != NULL); | |
5514 | gdb_assert (loc2->owner != NULL); | |
5515 | ||
5516 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5517 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5518 | |
5519 | if (hw_point1 != hw_point2) | |
5520 | return 0; | |
5521 | else if (hw_point1) | |
5522 | return watchpoint_locations_match (loc1, loc2); | |
5523 | else | |
5524 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5525 | loc2->pspace->aspace, loc2->address); | |
5526 | } | |
5527 | ||
76897487 KB |
5528 | static void |
5529 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5530 | int bnum, int have_bnum) | |
5531 | { | |
f63fbe86 MS |
5532 | /* The longest string possibly returned by hex_string_custom |
5533 | is 50 chars. These must be at least that big for safety. */ | |
5534 | char astr1[64]; | |
5535 | char astr2[64]; | |
76897487 | 5536 | |
bb599908 PH |
5537 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5538 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5539 | if (have_bnum) |
8a3fe4f8 | 5540 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5541 | bnum, astr1, astr2); |
5542 | else | |
8a3fe4f8 | 5543 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5544 | } |
5545 | ||
4a64f543 MS |
5546 | /* Adjust a breakpoint's address to account for architectural |
5547 | constraints on breakpoint placement. Return the adjusted address. | |
5548 | Note: Very few targets require this kind of adjustment. For most | |
5549 | targets, this function is simply the identity function. */ | |
76897487 KB |
5550 | |
5551 | static CORE_ADDR | |
a6d9a66e UW |
5552 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5553 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5554 | { |
a6d9a66e | 5555 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5556 | { |
5557 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5558 | return bpaddr; | |
5559 | } | |
88f7da05 KB |
5560 | else if (bptype == bp_watchpoint |
5561 | || bptype == bp_hardware_watchpoint | |
5562 | || bptype == bp_read_watchpoint | |
5563 | || bptype == bp_access_watchpoint | |
fe798b75 | 5564 | || bptype == bp_catchpoint) |
88f7da05 KB |
5565 | { |
5566 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5567 | have their addresses modified. */ | |
5568 | return bpaddr; | |
5569 | } | |
76897487 KB |
5570 | else |
5571 | { | |
5572 | CORE_ADDR adjusted_bpaddr; | |
5573 | ||
5574 | /* Some targets have architectural constraints on the placement | |
5575 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5576 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5577 | |
5578 | /* An adjusted breakpoint address can significantly alter | |
5579 | a user's expectations. Print a warning if an adjustment | |
5580 | is required. */ | |
5581 | if (adjusted_bpaddr != bpaddr) | |
5582 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5583 | ||
5584 | return adjusted_bpaddr; | |
5585 | } | |
5586 | } | |
5587 | ||
7cc221ef DJ |
5588 | /* Allocate a struct bp_location. */ |
5589 | ||
26bb91f3 | 5590 | static struct bp_location * |
39d61571 | 5591 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5592 | { |
afe38095 | 5593 | struct bp_location *loc; |
7cc221ef DJ |
5594 | |
5595 | loc = xmalloc (sizeof (struct bp_location)); | |
5596 | memset (loc, 0, sizeof (*loc)); | |
5597 | ||
e049a4b5 | 5598 | loc->owner = bpt; |
511a6cd4 | 5599 | loc->cond = NULL; |
0d381245 VP |
5600 | loc->shlib_disabled = 0; |
5601 | loc->enabled = 1; | |
e049a4b5 | 5602 | |
39d61571 | 5603 | switch (bpt->type) |
e049a4b5 DJ |
5604 | { |
5605 | case bp_breakpoint: | |
5606 | case bp_until: | |
5607 | case bp_finish: | |
5608 | case bp_longjmp: | |
5609 | case bp_longjmp_resume: | |
186c406b TT |
5610 | case bp_exception: |
5611 | case bp_exception_resume: | |
e049a4b5 | 5612 | case bp_step_resume: |
e049a4b5 DJ |
5613 | case bp_watchpoint_scope: |
5614 | case bp_call_dummy: | |
aa7d318d | 5615 | case bp_std_terminate: |
e049a4b5 DJ |
5616 | case bp_shlib_event: |
5617 | case bp_thread_event: | |
5618 | case bp_overlay_event: | |
4efc6507 | 5619 | case bp_jit_event: |
0fd8e87f | 5620 | case bp_longjmp_master: |
aa7d318d | 5621 | case bp_std_terminate_master: |
186c406b | 5622 | case bp_exception_master: |
e049a4b5 DJ |
5623 | loc->loc_type = bp_loc_software_breakpoint; |
5624 | break; | |
5625 | case bp_hardware_breakpoint: | |
5626 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5627 | break; | |
5628 | case bp_hardware_watchpoint: | |
5629 | case bp_read_watchpoint: | |
5630 | case bp_access_watchpoint: | |
5631 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5632 | break; | |
5633 | case bp_watchpoint: | |
ce78b96d | 5634 | case bp_catchpoint: |
15c3d785 PA |
5635 | case bp_tracepoint: |
5636 | case bp_fast_tracepoint: | |
0fb4aa4b | 5637 | case bp_static_tracepoint: |
e049a4b5 DJ |
5638 | loc->loc_type = bp_loc_other; |
5639 | break; | |
5640 | default: | |
e2e0b3e5 | 5641 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5642 | } |
5643 | ||
f431efe5 | 5644 | loc->refc = 1; |
7cc221ef DJ |
5645 | return loc; |
5646 | } | |
5647 | ||
f431efe5 PA |
5648 | static void |
5649 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5650 | { |
5651 | if (loc->cond) | |
5652 | xfree (loc->cond); | |
74960c60 VP |
5653 | |
5654 | if (loc->function_name) | |
5655 | xfree (loc->function_name); | |
f431efe5 | 5656 | |
fe3f5fa8 VP |
5657 | xfree (loc); |
5658 | } | |
5659 | ||
f431efe5 PA |
5660 | /* Increment reference count. */ |
5661 | ||
5662 | static void | |
5663 | incref_bp_location (struct bp_location *bl) | |
5664 | { | |
5665 | ++bl->refc; | |
5666 | } | |
5667 | ||
5668 | /* Decrement reference count. If the reference count reaches 0, | |
5669 | destroy the bp_location. Sets *BLP to NULL. */ | |
5670 | ||
5671 | static void | |
5672 | decref_bp_location (struct bp_location **blp) | |
5673 | { | |
0807b50c PA |
5674 | gdb_assert ((*blp)->refc > 0); |
5675 | ||
f431efe5 PA |
5676 | if (--(*blp)->refc == 0) |
5677 | free_bp_location (*blp); | |
5678 | *blp = NULL; | |
5679 | } | |
5680 | ||
4a64f543 MS |
5681 | /* Helper to set_raw_breakpoint below. Creates a breakpoint that has |
5682 | type BPTYPE and has no locations as yet. */ | |
5683 | /* This function is used in gdbtk sources and thus can not be made | |
5684 | static. */ | |
c906108c | 5685 | |
c40e75cd | 5686 | static struct breakpoint * |
a6d9a66e UW |
5687 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5688 | enum bptype bptype) | |
c906108c | 5689 | { |
52f0bd74 | 5690 | struct breakpoint *b, *b1; |
c906108c SS |
5691 | |
5692 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5693 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5694 | |
4d28f7a8 | 5695 | b->type = bptype; |
a6d9a66e | 5696 | b->gdbarch = gdbarch; |
c906108c SS |
5697 | b->language = current_language->la_language; |
5698 | b->input_radix = input_radix; | |
5699 | b->thread = -1; | |
b5de0fa7 | 5700 | b->enable_state = bp_enabled; |
c906108c SS |
5701 | b->next = 0; |
5702 | b->silent = 0; | |
5703 | b->ignore_count = 0; | |
5704 | b->commands = NULL; | |
818dd999 | 5705 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5706 | b->forked_inferior_pid = null_ptid; |
c906108c | 5707 | b->exec_pathname = NULL; |
a96d9b2e | 5708 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5709 | b->ops = NULL; |
0d381245 | 5710 | b->condition_not_parsed = 0; |
84f4c1fe | 5711 | b->py_bp_object = NULL; |
d0fb5eae | 5712 | b->related_breakpoint = b; |
c906108c | 5713 | |
4a64f543 MS |
5714 | /* Add this breakpoint to the end of the chain so that a list of |
5715 | breakpoints will come out in order of increasing numbers. */ | |
c906108c SS |
5716 | |
5717 | b1 = breakpoint_chain; | |
5718 | if (b1 == 0) | |
5719 | breakpoint_chain = b; | |
5720 | else | |
5721 | { | |
5722 | while (b1->next) | |
5723 | b1 = b1->next; | |
5724 | b1->next = b; | |
5725 | } | |
0d381245 VP |
5726 | return b; |
5727 | } | |
5728 | ||
5729 | /* Initialize loc->function_name. */ | |
5730 | static void | |
5731 | set_breakpoint_location_function (struct bp_location *loc) | |
5732 | { | |
2bdf28a0 JK |
5733 | gdb_assert (loc->owner != NULL); |
5734 | ||
0d381245 | 5735 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5736 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5737 | || is_tracepoint (loc->owner)) |
0d381245 VP |
5738 | { |
5739 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5740 | NULL, NULL); | |
5741 | if (loc->function_name) | |
5742 | loc->function_name = xstrdup (loc->function_name); | |
5743 | } | |
5744 | } | |
5745 | ||
a6d9a66e UW |
5746 | /* Attempt to determine architecture of location identified by SAL. */ |
5747 | static struct gdbarch * | |
5748 | get_sal_arch (struct symtab_and_line sal) | |
5749 | { | |
5750 | if (sal.section) | |
5751 | return get_objfile_arch (sal.section->objfile); | |
5752 | if (sal.symtab) | |
5753 | return get_objfile_arch (sal.symtab->objfile); | |
5754 | ||
5755 | return NULL; | |
5756 | } | |
5757 | ||
0d381245 VP |
5758 | /* set_raw_breakpoint is a low level routine for allocating and |
5759 | partially initializing a breakpoint of type BPTYPE. The newly | |
5760 | created breakpoint's address, section, source file name, and line | |
5761 | number are provided by SAL. The newly created and partially | |
5762 | initialized breakpoint is added to the breakpoint chain and | |
5763 | is also returned as the value of this function. | |
5764 | ||
5765 | It is expected that the caller will complete the initialization of | |
5766 | the newly created breakpoint struct as well as output any status | |
5767 | information regarding the creation of a new breakpoint. In | |
5768 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5769 | number! Care should be taken to not allow an error to occur | |
5770 | prior to completing the initialization of the breakpoint. If this | |
5771 | should happen, a bogus breakpoint will be left on the chain. */ | |
5772 | ||
63c252f8 | 5773 | struct breakpoint * |
a6d9a66e UW |
5774 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5775 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5776 | { |
4a64f543 MS |
5777 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, |
5778 | bptype); | |
0d381245 | 5779 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5780 | struct gdbarch *loc_gdbarch; |
5781 | ||
5782 | loc_gdbarch = get_sal_arch (sal); | |
5783 | if (!loc_gdbarch) | |
5784 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5785 | |
6c95b8df PA |
5786 | if (bptype != bp_catchpoint) |
5787 | gdb_assert (sal.pspace != NULL); | |
5788 | ||
0d381245 VP |
5789 | /* Adjust the breakpoint's address prior to allocating a location. |
5790 | Once we call allocate_bp_location(), that mostly uninitialized | |
5791 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5792 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5793 | not want its scan of the location chain to find a breakpoint and |
5794 | location that's only been partially initialized. */ | |
4a64f543 MS |
5795 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5796 | sal.pc, b->type); | |
0d381245 | 5797 | |
39d61571 | 5798 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5799 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5800 | b->loc->requested_address = sal.pc; |
5801 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5802 | b->loc->pspace = sal.pspace; |
5803 | ||
5804 | /* Store the program space that was used to set the breakpoint, for | |
5805 | breakpoint resetting. */ | |
5806 | b->pspace = sal.pspace; | |
0d381245 VP |
5807 | |
5808 | if (sal.symtab == NULL) | |
5809 | b->source_file = NULL; | |
5810 | else | |
1b36a34b | 5811 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5812 | b->loc->section = sal.section; |
5813 | b->line_number = sal.line; | |
5814 | ||
5815 | set_breakpoint_location_function (b->loc); | |
c906108c | 5816 | |
c906108c SS |
5817 | breakpoints_changed (); |
5818 | ||
5819 | return b; | |
5820 | } | |
5821 | ||
c2c6d25f JM |
5822 | |
5823 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5824 | instruction, hard-wired into the inferior's code. */ | |
5825 | void | |
5826 | make_breakpoint_permanent (struct breakpoint *b) | |
5827 | { | |
0d381245 | 5828 | struct bp_location *bl; |
cc59ec59 | 5829 | |
b5de0fa7 | 5830 | b->enable_state = bp_permanent; |
c2c6d25f | 5831 | |
4a64f543 MS |
5832 | /* By definition, permanent breakpoints are already present in the |
5833 | code. Mark all locations as inserted. For now, | |
5834 | make_breakpoint_permanent is called in just one place, so it's | |
5835 | hard to say if it's reasonable to have permanent breakpoint with | |
5836 | multiple locations or not, but it's easy to implmement. */ | |
0d381245 VP |
5837 | for (bl = b->loc; bl; bl = bl->next) |
5838 | bl->inserted = 1; | |
c2c6d25f JM |
5839 | } |
5840 | ||
53a5351d | 5841 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5842 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5843 | initiated the operation. */ | |
c906108c SS |
5844 | |
5845 | void | |
186c406b | 5846 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5847 | { |
35df4500 | 5848 | struct breakpoint *b, *b_tmp; |
186c406b | 5849 | int thread = tp->num; |
0fd8e87f UW |
5850 | |
5851 | /* To avoid having to rescan all objfile symbols at every step, | |
5852 | we maintain a list of continually-inserted but always disabled | |
5853 | longjmp "master" breakpoints. Here, we simply create momentary | |
5854 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5855 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5856 | if (b->pspace == current_program_space |
186c406b TT |
5857 | && (b->type == bp_longjmp_master |
5858 | || b->type == bp_exception_master)) | |
0fd8e87f UW |
5859 | { |
5860 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5861 | |
186c406b | 5862 | clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
0fd8e87f UW |
5863 | clone->thread = thread; |
5864 | } | |
186c406b TT |
5865 | |
5866 | tp->initiating_frame = frame; | |
c906108c SS |
5867 | } |
5868 | ||
611c83ae | 5869 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5870 | void |
611c83ae | 5871 | delete_longjmp_breakpoint (int thread) |
c906108c | 5872 | { |
35df4500 | 5873 | struct breakpoint *b, *b_tmp; |
c906108c | 5874 | |
35df4500 | 5875 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5876 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5877 | { |
5878 | if (b->thread == thread) | |
5879 | delete_breakpoint (b); | |
5880 | } | |
c906108c SS |
5881 | } |
5882 | ||
1900040c MS |
5883 | void |
5884 | enable_overlay_breakpoints (void) | |
5885 | { | |
52f0bd74 | 5886 | struct breakpoint *b; |
1900040c MS |
5887 | |
5888 | ALL_BREAKPOINTS (b) | |
5889 | if (b->type == bp_overlay_event) | |
5890 | { | |
5891 | b->enable_state = bp_enabled; | |
b60e7edf | 5892 | update_global_location_list (1); |
c02f5703 | 5893 | overlay_events_enabled = 1; |
1900040c MS |
5894 | } |
5895 | } | |
5896 | ||
5897 | void | |
5898 | disable_overlay_breakpoints (void) | |
5899 | { | |
52f0bd74 | 5900 | struct breakpoint *b; |
1900040c MS |
5901 | |
5902 | ALL_BREAKPOINTS (b) | |
5903 | if (b->type == bp_overlay_event) | |
5904 | { | |
5905 | b->enable_state = bp_disabled; | |
b60e7edf | 5906 | update_global_location_list (0); |
c02f5703 | 5907 | overlay_events_enabled = 0; |
1900040c MS |
5908 | } |
5909 | } | |
5910 | ||
aa7d318d TT |
5911 | /* Set an active std::terminate breakpoint for each std::terminate |
5912 | master breakpoint. */ | |
5913 | void | |
5914 | set_std_terminate_breakpoint (void) | |
5915 | { | |
35df4500 | 5916 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5917 | |
35df4500 | 5918 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5919 | if (b->pspace == current_program_space |
5920 | && b->type == bp_std_terminate_master) | |
5921 | { | |
5922 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5923 | clone->type = bp_std_terminate; | |
5924 | } | |
5925 | } | |
5926 | ||
5927 | /* Delete all the std::terminate breakpoints. */ | |
5928 | void | |
5929 | delete_std_terminate_breakpoint (void) | |
5930 | { | |
35df4500 | 5931 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5932 | |
35df4500 | 5933 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5934 | if (b->type == bp_std_terminate) |
5935 | delete_breakpoint (b); | |
5936 | } | |
5937 | ||
c4093a6a | 5938 | struct breakpoint * |
a6d9a66e | 5939 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5940 | { |
5941 | struct breakpoint *b; | |
c4093a6a | 5942 | |
a6d9a66e | 5943 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5944 | |
b5de0fa7 | 5945 | b->enable_state = bp_enabled; |
c4093a6a | 5946 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5947 | b->addr_string |
5948 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5949 | |
b60e7edf | 5950 | update_global_location_list_nothrow (1); |
74960c60 | 5951 | |
c4093a6a JM |
5952 | return b; |
5953 | } | |
5954 | ||
5955 | void | |
5956 | remove_thread_event_breakpoints (void) | |
5957 | { | |
35df4500 | 5958 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5959 | |
35df4500 | 5960 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5961 | if (b->type == bp_thread_event |
5962 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5963 | delete_breakpoint (b); |
5964 | } | |
5965 | ||
0101ce28 JJ |
5966 | struct captured_parse_breakpoint_args |
5967 | { | |
5968 | char **arg_p; | |
5969 | struct symtabs_and_lines *sals_p; | |
7efd8fc2 | 5970 | struct linespec_result *canonical_p; |
0101ce28 JJ |
5971 | int *not_found_ptr; |
5972 | }; | |
5973 | ||
5974 | struct lang_and_radix | |
5975 | { | |
5976 | enum language lang; | |
5977 | int radix; | |
5978 | }; | |
5979 | ||
4efc6507 DE |
5980 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5981 | ||
5982 | struct breakpoint * | |
5983 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5984 | { | |
5985 | struct breakpoint *b; | |
5986 | ||
5987 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5988 | update_global_location_list_nothrow (1); | |
5989 | return b; | |
5990 | } | |
0101ce28 | 5991 | |
03673fc7 PP |
5992 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
5993 | ||
5994 | void | |
5995 | remove_jit_event_breakpoints (void) | |
5996 | { | |
5997 | struct breakpoint *b, *b_tmp; | |
5998 | ||
5999 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6000 | if (b->type == bp_jit_event | |
6001 | && b->loc->pspace == current_program_space) | |
6002 | delete_breakpoint (b); | |
6003 | } | |
6004 | ||
cae688ec JJ |
6005 | void |
6006 | remove_solib_event_breakpoints (void) | |
6007 | { | |
35df4500 | 6008 | struct breakpoint *b, *b_tmp; |
cae688ec | 6009 | |
35df4500 | 6010 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6011 | if (b->type == bp_shlib_event |
6012 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6013 | delete_breakpoint (b); |
6014 | } | |
6015 | ||
6016 | struct breakpoint * | |
a6d9a66e | 6017 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6018 | { |
6019 | struct breakpoint *b; | |
6020 | ||
a6d9a66e | 6021 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 6022 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6023 | return b; |
6024 | } | |
6025 | ||
6026 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6027 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6028 | ||
6029 | void | |
cb851954 | 6030 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6031 | { |
876fa593 | 6032 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6033 | |
876fa593 | 6034 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6035 | { |
2bdf28a0 | 6036 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6037 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6038 | |
4a64f543 MS |
6039 | /* We apply the check to all breakpoints, including disabled for |
6040 | those with loc->duplicate set. This is so that when breakpoint | |
6041 | becomes enabled, or the duplicate is removed, gdb will try to | |
6042 | insert all breakpoints. If we don't set shlib_disabled here, | |
6043 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6044 | if (((b->type == bp_breakpoint) |
508ccb1f | 6045 | || (b->type == bp_jit_event) |
1042e4c0 | 6046 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6047 | || (is_tracepoint (b))) |
6c95b8df | 6048 | && loc->pspace == current_program_space |
0d381245 | 6049 | && !loc->shlib_disabled |
a77053c2 | 6050 | #ifdef PC_SOLIB |
0d381245 | 6051 | && PC_SOLIB (loc->address) |
a77053c2 | 6052 | #else |
6c95b8df | 6053 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6054 | #endif |
6055 | ) | |
0d381245 VP |
6056 | { |
6057 | loc->shlib_disabled = 1; | |
6058 | } | |
cae688ec JJ |
6059 | } |
6060 | } | |
6061 | ||
4a64f543 MS |
6062 | /* Disable any breakpoints that are in in an unloaded shared library. |
6063 | Only apply to enabled breakpoints, disabled ones can just stay | |
6064 | disabled. */ | |
84acb35a | 6065 | |
75149521 | 6066 | static void |
84acb35a JJ |
6067 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6068 | { | |
876fa593 | 6069 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6070 | int disabled_shlib_breaks = 0; |
6071 | ||
c86cf029 VP |
6072 | /* SunOS a.out shared libraries are always mapped, so do not |
6073 | disable breakpoints; they will only be reported as unloaded | |
6074 | through clear_solib when GDB discards its shared library | |
6075 | list. See clear_solib for more information. */ | |
6076 | if (exec_bfd != NULL | |
6077 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6078 | return; | |
6079 | ||
876fa593 | 6080 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6081 | { |
2bdf28a0 | 6082 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6083 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6084 | |
0d381245 VP |
6085 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6086 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6087 | && solib->pspace == loc->pspace |
e2dd7057 | 6088 | && !loc->shlib_disabled |
508ccb1f TT |
6089 | && (b->type == bp_breakpoint |
6090 | || b->type == bp_jit_event | |
6091 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6092 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6093 | { |
e2dd7057 PP |
6094 | loc->shlib_disabled = 1; |
6095 | /* At this point, we cannot rely on remove_breakpoint | |
6096 | succeeding so we must mark the breakpoint as not inserted | |
6097 | to prevent future errors occurring in remove_breakpoints. */ | |
6098 | loc->inserted = 0; | |
6099 | if (!disabled_shlib_breaks) | |
6100 | { | |
6101 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6102 | warning (_("Temporarily disabling breakpoints " |
6103 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6104 | solib->so_name); |
84acb35a | 6105 | } |
e2dd7057 | 6106 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6107 | } |
6108 | } | |
84acb35a JJ |
6109 | } |
6110 | ||
ce78b96d JB |
6111 | /* FORK & VFORK catchpoints. */ |
6112 | ||
4a64f543 MS |
6113 | /* Implement the "insert" breakpoint_ops method for fork |
6114 | catchpoints. */ | |
ce78b96d | 6115 | |
77b06cd7 TJB |
6116 | static int |
6117 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6118 | { |
77b06cd7 | 6119 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6120 | } |
6121 | ||
4a64f543 MS |
6122 | /* Implement the "remove" breakpoint_ops method for fork |
6123 | catchpoints. */ | |
ce78b96d JB |
6124 | |
6125 | static int | |
77b06cd7 | 6126 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6127 | { |
6128 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6129 | } | |
6130 | ||
6131 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6132 | catchpoints. */ | |
6133 | ||
6134 | static int | |
6135 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
6136 | { | |
6137 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
6138 | } | |
6139 | ||
4a64f543 MS |
6140 | /* Implement the "print_it" breakpoint_ops method for fork |
6141 | catchpoints. */ | |
ce78b96d JB |
6142 | |
6143 | static enum print_stop_action | |
6144 | print_it_catch_fork (struct breakpoint *b) | |
6145 | { | |
6146 | annotate_catchpoint (b->number); | |
6147 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
6148 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6149 | return PRINT_SRC_AND_LOC; | |
6150 | } | |
6151 | ||
4a64f543 MS |
6152 | /* Implement the "print_one" breakpoint_ops method for fork |
6153 | catchpoints. */ | |
ce78b96d JB |
6154 | |
6155 | static void | |
a6d9a66e | 6156 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6157 | { |
79a45b7d TT |
6158 | struct value_print_options opts; |
6159 | ||
6160 | get_user_print_options (&opts); | |
6161 | ||
4a64f543 MS |
6162 | /* Field 4, the address, is omitted (which makes the columns not |
6163 | line up too nicely with the headers, but the effect is relatively | |
6164 | readable). */ | |
79a45b7d | 6165 | if (opts.addressprint) |
ce78b96d JB |
6166 | ui_out_field_skip (uiout, "addr"); |
6167 | annotate_field (5); | |
6168 | ui_out_text (uiout, "fork"); | |
6169 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6170 | { | |
6171 | ui_out_text (uiout, ", process "); | |
6172 | ui_out_field_int (uiout, "what", | |
6173 | ptid_get_pid (b->forked_inferior_pid)); | |
6174 | ui_out_spaces (uiout, 1); | |
6175 | } | |
6176 | } | |
6177 | ||
6178 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6179 | catchpoints. */ | |
6180 | ||
6181 | static void | |
6182 | print_mention_catch_fork (struct breakpoint *b) | |
6183 | { | |
6184 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6185 | } | |
6186 | ||
6149aea9 PA |
6187 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6188 | catchpoints. */ | |
6189 | ||
6190 | static void | |
6191 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6192 | { | |
6193 | fprintf_unfiltered (fp, "catch fork"); | |
6194 | } | |
6195 | ||
ce78b96d JB |
6196 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6197 | ||
6198 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
6199 | { | |
6200 | insert_catch_fork, | |
6201 | remove_catch_fork, | |
6202 | breakpoint_hit_catch_fork, | |
e09342b5 | 6203 | NULL, /* resources_needed */ |
ce78b96d JB |
6204 | print_it_catch_fork, |
6205 | print_one_catch_fork, | |
6149aea9 PA |
6206 | print_mention_catch_fork, |
6207 | print_recreate_catch_fork | |
ce78b96d JB |
6208 | }; |
6209 | ||
4a64f543 MS |
6210 | /* Implement the "insert" breakpoint_ops method for vfork |
6211 | catchpoints. */ | |
ce78b96d | 6212 | |
77b06cd7 TJB |
6213 | static int |
6214 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6215 | { |
77b06cd7 | 6216 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6217 | } |
6218 | ||
4a64f543 MS |
6219 | /* Implement the "remove" breakpoint_ops method for vfork |
6220 | catchpoints. */ | |
ce78b96d JB |
6221 | |
6222 | static int | |
77b06cd7 | 6223 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6224 | { |
6225 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6226 | } | |
6227 | ||
6228 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6229 | catchpoints. */ | |
6230 | ||
6231 | static int | |
6232 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
6233 | { | |
6234 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
6235 | } | |
6236 | ||
4a64f543 MS |
6237 | /* Implement the "print_it" breakpoint_ops method for vfork |
6238 | catchpoints. */ | |
ce78b96d JB |
6239 | |
6240 | static enum print_stop_action | |
6241 | print_it_catch_vfork (struct breakpoint *b) | |
6242 | { | |
6243 | annotate_catchpoint (b->number); | |
6244 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
6245 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6246 | return PRINT_SRC_AND_LOC; | |
6247 | } | |
6248 | ||
4a64f543 MS |
6249 | /* Implement the "print_one" breakpoint_ops method for vfork |
6250 | catchpoints. */ | |
ce78b96d JB |
6251 | |
6252 | static void | |
a6d9a66e | 6253 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6254 | { |
79a45b7d TT |
6255 | struct value_print_options opts; |
6256 | ||
6257 | get_user_print_options (&opts); | |
4a64f543 MS |
6258 | /* Field 4, the address, is omitted (which makes the columns not |
6259 | line up too nicely with the headers, but the effect is relatively | |
6260 | readable). */ | |
79a45b7d | 6261 | if (opts.addressprint) |
ce78b96d JB |
6262 | ui_out_field_skip (uiout, "addr"); |
6263 | annotate_field (5); | |
6264 | ui_out_text (uiout, "vfork"); | |
6265 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6266 | { | |
6267 | ui_out_text (uiout, ", process "); | |
6268 | ui_out_field_int (uiout, "what", | |
6269 | ptid_get_pid (b->forked_inferior_pid)); | |
6270 | ui_out_spaces (uiout, 1); | |
6271 | } | |
6272 | } | |
6273 | ||
6274 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6275 | catchpoints. */ | |
6276 | ||
6277 | static void | |
6278 | print_mention_catch_vfork (struct breakpoint *b) | |
6279 | { | |
6280 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6281 | } | |
6282 | ||
6149aea9 PA |
6283 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6284 | catchpoints. */ | |
6285 | ||
6286 | static void | |
6287 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6288 | { | |
6289 | fprintf_unfiltered (fp, "catch vfork"); | |
6290 | } | |
6291 | ||
ce78b96d JB |
6292 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6293 | ||
6294 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6295 | { | |
6296 | insert_catch_vfork, | |
6297 | remove_catch_vfork, | |
6298 | breakpoint_hit_catch_vfork, | |
e09342b5 | 6299 | NULL, /* resources_needed */ |
ce78b96d JB |
6300 | print_it_catch_vfork, |
6301 | print_one_catch_vfork, | |
6149aea9 PA |
6302 | print_mention_catch_vfork, |
6303 | print_recreate_catch_vfork | |
ce78b96d JB |
6304 | }; |
6305 | ||
a96d9b2e SDJ |
6306 | /* Implement the "insert" breakpoint_ops method for syscall |
6307 | catchpoints. */ | |
6308 | ||
77b06cd7 TJB |
6309 | static int |
6310 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e SDJ |
6311 | { |
6312 | struct inferior *inf = current_inferior (); | |
6313 | ||
6314 | ++inf->total_syscalls_count; | |
77b06cd7 | 6315 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6316 | ++inf->any_syscall_count; |
6317 | else | |
6318 | { | |
6319 | int i, iter; | |
cc59ec59 | 6320 | |
a96d9b2e | 6321 | for (i = 0; |
77b06cd7 | 6322 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6323 | i++) |
6324 | { | |
6325 | int elem; | |
cc59ec59 | 6326 | |
a96d9b2e SDJ |
6327 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6328 | { | |
6329 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6330 | uintptr_t vec_addr_offset |
6331 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6332 | uintptr_t vec_addr; |
6333 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6334 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6335 | vec_addr_offset; | |
6336 | memset ((void *) vec_addr, 0, | |
6337 | (iter + 1 - old_size) * sizeof (int)); | |
6338 | } | |
6339 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6340 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6341 | } | |
6342 | } | |
6343 | ||
77b06cd7 TJB |
6344 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6345 | inf->total_syscalls_count != 0, | |
6346 | inf->any_syscall_count, | |
6347 | VEC_length (int, inf->syscalls_counts), | |
6348 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6349 | } |
6350 | ||
6351 | /* Implement the "remove" breakpoint_ops method for syscall | |
6352 | catchpoints. */ | |
6353 | ||
6354 | static int | |
77b06cd7 | 6355 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e SDJ |
6356 | { |
6357 | struct inferior *inf = current_inferior (); | |
6358 | ||
6359 | --inf->total_syscalls_count; | |
77b06cd7 | 6360 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6361 | --inf->any_syscall_count; |
6362 | else | |
6363 | { | |
6364 | int i, iter; | |
cc59ec59 | 6365 | |
a96d9b2e | 6366 | for (i = 0; |
77b06cd7 | 6367 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6368 | i++) |
6369 | { | |
6370 | int elem; | |
6371 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6372 | /* Shouldn't happen. */ | |
6373 | continue; | |
6374 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6375 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6376 | } | |
6377 | } | |
6378 | ||
6379 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6380 | inf->total_syscalls_count != 0, | |
6381 | inf->any_syscall_count, | |
6382 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6383 | VEC_address (int, |
6384 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6385 | } |
6386 | ||
6387 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6388 | catchpoints. */ | |
6389 | ||
6390 | static int | |
6391 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6392 | { | |
4a64f543 MS |
6393 | /* We must check if we are catching specific syscalls in this |
6394 | breakpoint. If we are, then we must guarantee that the called | |
6395 | syscall is the same syscall we are catching. */ | |
a96d9b2e SDJ |
6396 | int syscall_number = 0; |
6397 | ||
6398 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6399 | return 0; | |
6400 | ||
6401 | /* Now, checking if the syscall is the same. */ | |
6402 | if (b->syscalls_to_be_caught) | |
6403 | { | |
6404 | int i, iter; | |
cc59ec59 | 6405 | |
a96d9b2e SDJ |
6406 | for (i = 0; |
6407 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6408 | i++) | |
6409 | if (syscall_number == iter) | |
6410 | break; | |
6411 | /* Not the same. */ | |
6412 | if (!iter) | |
6413 | return 0; | |
6414 | } | |
6415 | ||
6416 | return 1; | |
6417 | } | |
6418 | ||
6419 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6420 | catchpoints. */ | |
6421 | ||
6422 | static enum print_stop_action | |
6423 | print_it_catch_syscall (struct breakpoint *b) | |
6424 | { | |
6425 | /* These are needed because we want to know in which state a | |
6426 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6427 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6428 | must print "called syscall" or "returned from syscall". */ | |
6429 | ptid_t ptid; | |
6430 | struct target_waitstatus last; | |
6431 | struct syscall s; | |
6432 | struct cleanup *old_chain; | |
6433 | char *syscall_id; | |
6434 | ||
6435 | get_last_target_status (&ptid, &last); | |
6436 | ||
6437 | get_syscall_by_number (last.value.syscall_number, &s); | |
6438 | ||
6439 | annotate_catchpoint (b->number); | |
6440 | ||
6441 | if (s.name == NULL) | |
6442 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6443 | else | |
6444 | syscall_id = xstrprintf ("'%s'", s.name); | |
6445 | ||
6446 | old_chain = make_cleanup (xfree, syscall_id); | |
6447 | ||
6448 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6449 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6450 | b->number, syscall_id); | |
6451 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6452 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6453 | b->number, syscall_id); | |
6454 | ||
6455 | do_cleanups (old_chain); | |
6456 | ||
6457 | return PRINT_SRC_AND_LOC; | |
6458 | } | |
6459 | ||
6460 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6461 | catchpoints. */ | |
6462 | ||
6463 | static void | |
6464 | print_one_catch_syscall (struct breakpoint *b, | |
6465 | struct bp_location **last_loc) | |
6466 | { | |
6467 | struct value_print_options opts; | |
6468 | ||
6469 | get_user_print_options (&opts); | |
4a64f543 MS |
6470 | /* Field 4, the address, is omitted (which makes the columns not |
6471 | line up too nicely with the headers, but the effect is relatively | |
6472 | readable). */ | |
a96d9b2e SDJ |
6473 | if (opts.addressprint) |
6474 | ui_out_field_skip (uiout, "addr"); | |
6475 | annotate_field (5); | |
6476 | ||
6477 | if (b->syscalls_to_be_caught | |
6478 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6479 | ui_out_text (uiout, "syscalls \""); | |
6480 | else | |
6481 | ui_out_text (uiout, "syscall \""); | |
6482 | ||
6483 | if (b->syscalls_to_be_caught) | |
6484 | { | |
6485 | int i, iter; | |
6486 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6487 | |
a96d9b2e SDJ |
6488 | for (i = 0; |
6489 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6490 | i++) | |
6491 | { | |
6492 | char *x = text; | |
6493 | struct syscall s; | |
6494 | get_syscall_by_number (iter, &s); | |
6495 | ||
6496 | if (s.name != NULL) | |
6497 | text = xstrprintf ("%s%s, ", text, s.name); | |
6498 | else | |
6499 | text = xstrprintf ("%s%d, ", text, iter); | |
6500 | ||
6501 | /* We have to xfree the last 'text' (now stored at 'x') | |
6502 | because xstrprintf dinamically allocates new space for it | |
6503 | on every call. */ | |
6504 | xfree (x); | |
6505 | } | |
6506 | /* Remove the last comma. */ | |
6507 | text[strlen (text) - 2] = '\0'; | |
6508 | ui_out_field_string (uiout, "what", text); | |
6509 | } | |
6510 | else | |
6511 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6512 | ui_out_text (uiout, "\" "); | |
6513 | } | |
6514 | ||
6515 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6516 | catchpoints. */ | |
6517 | ||
6518 | static void | |
6519 | print_mention_catch_syscall (struct breakpoint *b) | |
6520 | { | |
6521 | if (b->syscalls_to_be_caught) | |
6522 | { | |
6523 | int i, iter; | |
6524 | ||
6525 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6526 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6527 | else | |
6528 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6529 | ||
6530 | for (i = 0; | |
6531 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6532 | i++) | |
6533 | { | |
6534 | struct syscall s; | |
6535 | get_syscall_by_number (iter, &s); | |
6536 | ||
6537 | if (s.name) | |
6538 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6539 | else | |
6540 | printf_filtered (" %d", s.number); | |
6541 | } | |
6542 | printf_filtered (")"); | |
6543 | } | |
6544 | else | |
6545 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6546 | b->number); | |
6547 | } | |
6548 | ||
6149aea9 PA |
6549 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6550 | catchpoints. */ | |
6551 | ||
6552 | static void | |
6553 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6554 | { | |
6555 | fprintf_unfiltered (fp, "catch syscall"); | |
6556 | ||
6557 | if (b->syscalls_to_be_caught) | |
6558 | { | |
6559 | int i, iter; | |
6560 | ||
6561 | for (i = 0; | |
6562 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6563 | i++) | |
6564 | { | |
6565 | struct syscall s; | |
6566 | ||
6567 | get_syscall_by_number (iter, &s); | |
6568 | if (s.name) | |
6569 | fprintf_unfiltered (fp, " %s", s.name); | |
6570 | else | |
6571 | fprintf_unfiltered (fp, " %d", s.number); | |
6572 | } | |
6573 | } | |
6574 | } | |
6575 | ||
a96d9b2e SDJ |
6576 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6577 | ||
6578 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6579 | { | |
6580 | insert_catch_syscall, | |
6581 | remove_catch_syscall, | |
6582 | breakpoint_hit_catch_syscall, | |
e09342b5 | 6583 | NULL, /* resources_needed */ |
a96d9b2e SDJ |
6584 | print_it_catch_syscall, |
6585 | print_one_catch_syscall, | |
6149aea9 PA |
6586 | print_mention_catch_syscall, |
6587 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6588 | }; |
6589 | ||
6590 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6591 | ||
6592 | static int | |
6593 | syscall_catchpoint_p (struct breakpoint *b) | |
6594 | { | |
6595 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6596 | } | |
6597 | ||
6598 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6599 | but does NOT mention it nor update the global location list. | |
6600 | This is useful if you need to fill more fields in the | |
6601 | struct breakpoint before calling mention. | |
ce78b96d JB |
6602 | |
6603 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6604 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6605 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6606 | to the catchpoint. */ | |
6607 | ||
6608 | static struct breakpoint * | |
a96d9b2e SDJ |
6609 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6610 | char *cond_string, | |
6611 | struct breakpoint_ops *ops) | |
c906108c | 6612 | { |
c5aa993b JM |
6613 | struct symtab_and_line sal; |
6614 | struct breakpoint *b; | |
c5aa993b | 6615 | |
fe39c653 | 6616 | init_sal (&sal); |
6c95b8df | 6617 | sal.pspace = current_program_space; |
c5aa993b | 6618 | |
a6d9a66e | 6619 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6620 | set_breakpoint_count (breakpoint_count + 1); |
6621 | b->number = breakpoint_count; | |
ce78b96d | 6622 | |
1b36a34b | 6623 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6624 | b->thread = -1; |
c906108c | 6625 | b->addr_string = NULL; |
b5de0fa7 EZ |
6626 | b->enable_state = bp_enabled; |
6627 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6628 | b->ops = ops; |
c5aa993b | 6629 | |
a96d9b2e SDJ |
6630 | return b; |
6631 | } | |
6632 | ||
6633 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6634 | ||
6635 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6636 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6637 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6638 | to the catchpoint. */ | |
6639 | ||
6640 | static struct breakpoint * | |
6641 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6642 | char *cond_string, struct breakpoint_ops *ops) | |
6643 | { | |
6644 | struct breakpoint *b = | |
6645 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6646 | ||
c906108c | 6647 | mention (b); |
ce78b96d | 6648 | update_global_location_list (1); |
c906108c | 6649 | |
ce78b96d | 6650 | return b; |
c906108c | 6651 | } |
c5aa993b | 6652 | |
9b70b993 | 6653 | static void |
a6d9a66e UW |
6654 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6655 | int tempflag, char *cond_string, | |
ce78b96d | 6656 | struct breakpoint_ops *ops) |
c906108c | 6657 | { |
a6d9a66e UW |
6658 | struct breakpoint *b |
6659 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6660 | |
6661 | /* FIXME: We should put this information in a breakpoint private data | |
6662 | area. */ | |
6663 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6664 | } |
6665 | ||
fe798b75 JB |
6666 | /* Exec catchpoints. */ |
6667 | ||
77b06cd7 TJB |
6668 | static int |
6669 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6670 | { |
77b06cd7 | 6671 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6672 | } |
c906108c | 6673 | |
fe798b75 | 6674 | static int |
77b06cd7 | 6675 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6676 | { |
6677 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6678 | } | |
c906108c | 6679 | |
fe798b75 JB |
6680 | static int |
6681 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6682 | { | |
6683 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6684 | } | |
c906108c | 6685 | |
fe798b75 JB |
6686 | static enum print_stop_action |
6687 | print_it_catch_exec (struct breakpoint *b) | |
6688 | { | |
6689 | annotate_catchpoint (b->number); | |
6690 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6691 | b->exec_pathname); | |
6692 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6693 | } |
6694 | ||
fe798b75 | 6695 | static void |
a6d9a66e | 6696 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6697 | { |
6698 | struct value_print_options opts; | |
6699 | ||
6700 | get_user_print_options (&opts); | |
6701 | ||
6702 | /* Field 4, the address, is omitted (which makes the columns | |
6703 | not line up too nicely with the headers, but the effect | |
6704 | is relatively readable). */ | |
6705 | if (opts.addressprint) | |
6706 | ui_out_field_skip (uiout, "addr"); | |
6707 | annotate_field (5); | |
6708 | ui_out_text (uiout, "exec"); | |
6709 | if (b->exec_pathname != NULL) | |
6710 | { | |
6711 | ui_out_text (uiout, ", program \""); | |
6712 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6713 | ui_out_text (uiout, "\" "); | |
6714 | } | |
6715 | } | |
6716 | ||
6717 | static void | |
6718 | print_mention_catch_exec (struct breakpoint *b) | |
6719 | { | |
6720 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6721 | } | |
6722 | ||
6149aea9 PA |
6723 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6724 | catchpoints. */ | |
6725 | ||
6726 | static void | |
6727 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6728 | { | |
6729 | fprintf_unfiltered (fp, "catch exec"); | |
6730 | } | |
6731 | ||
fe798b75 JB |
6732 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6733 | { | |
6734 | insert_catch_exec, | |
6735 | remove_catch_exec, | |
6736 | breakpoint_hit_catch_exec, | |
e09342b5 | 6737 | NULL, /* resources_needed */ |
fe798b75 JB |
6738 | print_it_catch_exec, |
6739 | print_one_catch_exec, | |
6149aea9 PA |
6740 | print_mention_catch_exec, |
6741 | print_recreate_catch_exec | |
fe798b75 JB |
6742 | }; |
6743 | ||
a96d9b2e SDJ |
6744 | static void |
6745 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6746 | struct breakpoint_ops *ops) | |
6747 | { | |
6748 | struct gdbarch *gdbarch = get_current_arch (); | |
6749 | struct breakpoint *b = | |
6750 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6751 | ||
6752 | b->syscalls_to_be_caught = filter; | |
6753 | ||
6754 | /* Now, we have to mention the breakpoint and update the global | |
6755 | location list. */ | |
6756 | mention (b); | |
6757 | update_global_location_list (1); | |
6758 | } | |
6759 | ||
c906108c | 6760 | static int |
fba45db2 | 6761 | hw_breakpoint_used_count (void) |
c906108c | 6762 | { |
52f0bd74 | 6763 | struct breakpoint *b; |
c906108c SS |
6764 | int i = 0; |
6765 | ||
6766 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6767 | { |
d6b74ac4 | 6768 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6769 | i++; |
6770 | } | |
c906108c SS |
6771 | |
6772 | return i; | |
6773 | } | |
6774 | ||
6775 | static int | |
fba45db2 | 6776 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6777 | { |
c906108c | 6778 | int i = 0; |
e09342b5 TJB |
6779 | struct breakpoint *b; |
6780 | struct bp_location *bl; | |
c906108c SS |
6781 | |
6782 | *other_type_used = 0; | |
6783 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6784 | { |
6785 | if (!breakpoint_enabled (b)) | |
6786 | continue; | |
6787 | ||
c5aa993b | 6788 | if (b->type == type) |
e09342b5 TJB |
6789 | for (bl = b->loc; bl; bl = bl->next) |
6790 | { | |
6791 | /* Special types of hardware watchpoints may use more than | |
6792 | one register. */ | |
6793 | if (b->ops && b->ops->resources_needed) | |
6794 | i += b->ops->resources_needed (bl); | |
6795 | else | |
6796 | i++; | |
6797 | } | |
cc60f2e3 | 6798 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6799 | *other_type_used = 1; |
e09342b5 TJB |
6800 | } |
6801 | ||
c906108c SS |
6802 | return i; |
6803 | } | |
6804 | ||
c906108c | 6805 | void |
fba45db2 | 6806 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6807 | { |
c5aa993b | 6808 | struct breakpoint *b; |
c906108c SS |
6809 | |
6810 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6811 | { |
cc60f2e3 | 6812 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6813 | { |
b5de0fa7 | 6814 | b->enable_state = bp_call_disabled; |
b60e7edf | 6815 | update_global_location_list (0); |
c5aa993b JM |
6816 | } |
6817 | } | |
c906108c SS |
6818 | } |
6819 | ||
6820 | void | |
fba45db2 | 6821 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6822 | { |
c5aa993b | 6823 | struct breakpoint *b; |
c906108c SS |
6824 | |
6825 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6826 | { |
cc60f2e3 | 6827 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6828 | { |
b5de0fa7 | 6829 | b->enable_state = bp_enabled; |
b60e7edf | 6830 | update_global_location_list (1); |
c5aa993b JM |
6831 | } |
6832 | } | |
c906108c SS |
6833 | } |
6834 | ||
8bea4e01 UW |
6835 | void |
6836 | disable_breakpoints_before_startup (void) | |
6837 | { | |
6838 | struct breakpoint *b; | |
6839 | int found = 0; | |
6840 | ||
6841 | ALL_BREAKPOINTS (b) | |
6842 | { | |
6c95b8df PA |
6843 | if (b->pspace != current_program_space) |
6844 | continue; | |
6845 | ||
8bea4e01 UW |
6846 | if ((b->type == bp_breakpoint |
6847 | || b->type == bp_hardware_breakpoint) | |
6848 | && breakpoint_enabled (b)) | |
6849 | { | |
6850 | b->enable_state = bp_startup_disabled; | |
6851 | found = 1; | |
6852 | } | |
6853 | } | |
6854 | ||
6855 | if (found) | |
6856 | update_global_location_list (0); | |
6857 | ||
6c95b8df | 6858 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6859 | } |
6860 | ||
6861 | void | |
6862 | enable_breakpoints_after_startup (void) | |
6863 | { | |
6864 | struct breakpoint *b; | |
6865 | int found = 0; | |
6866 | ||
6c95b8df | 6867 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6868 | |
6869 | ALL_BREAKPOINTS (b) | |
6870 | { | |
6c95b8df PA |
6871 | if (b->pspace != current_program_space) |
6872 | continue; | |
6873 | ||
8bea4e01 UW |
6874 | if ((b->type == bp_breakpoint |
6875 | || b->type == bp_hardware_breakpoint) | |
6876 | && b->enable_state == bp_startup_disabled) | |
6877 | { | |
6878 | b->enable_state = bp_enabled; | |
6879 | found = 1; | |
6880 | } | |
6881 | } | |
6882 | ||
6883 | if (found) | |
6884 | breakpoint_re_set (); | |
6885 | } | |
6886 | ||
c906108c SS |
6887 | |
6888 | /* Set a breakpoint that will evaporate an end of command | |
6889 | at address specified by SAL. | |
6890 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6891 | ||
6892 | struct breakpoint * | |
a6d9a66e UW |
6893 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6894 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6895 | { |
52f0bd74 | 6896 | struct breakpoint *b; |
edb3359d DJ |
6897 | |
6898 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6899 | one. */ | |
6900 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6901 | ||
a6d9a66e | 6902 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6903 | b->enable_state = bp_enabled; |
6904 | b->disposition = disp_donttouch; | |
818dd999 | 6905 | b->frame_id = frame_id; |
c906108c | 6906 | |
4a64f543 MS |
6907 | /* If we're debugging a multi-threaded program, then we want |
6908 | momentary breakpoints to be active in only a single thread of | |
6909 | control. */ | |
39f77062 KB |
6910 | if (in_thread_list (inferior_ptid)) |
6911 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6912 | |
b60e7edf | 6913 | update_global_location_list_nothrow (1); |
74960c60 | 6914 | |
c906108c SS |
6915 | return b; |
6916 | } | |
611c83ae | 6917 | |
e58b0e63 PA |
6918 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6919 | ORIG is NULL. */ | |
6920 | ||
6921 | struct breakpoint * | |
6922 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6923 | { | |
6924 | struct breakpoint *copy; | |
6925 | ||
6926 | /* If there's nothing to clone, then return nothing. */ | |
6927 | if (orig == NULL) | |
6928 | return NULL; | |
6929 | ||
a6d9a66e | 6930 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6931 | copy->loc = allocate_bp_location (copy); |
6932 | set_breakpoint_location_function (copy->loc); | |
6933 | ||
a6d9a66e | 6934 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6935 | copy->loc->requested_address = orig->loc->requested_address; |
6936 | copy->loc->address = orig->loc->address; | |
6937 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6938 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6939 | |
6940 | if (orig->source_file == NULL) | |
6941 | copy->source_file = NULL; | |
6942 | else | |
6943 | copy->source_file = xstrdup (orig->source_file); | |
6944 | ||
6945 | copy->line_number = orig->line_number; | |
6946 | copy->frame_id = orig->frame_id; | |
6947 | copy->thread = orig->thread; | |
6c95b8df | 6948 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6949 | |
6950 | copy->enable_state = bp_enabled; | |
6951 | copy->disposition = disp_donttouch; | |
6952 | copy->number = internal_breakpoint_number--; | |
6953 | ||
6954 | update_global_location_list_nothrow (0); | |
6955 | return copy; | |
6956 | } | |
6957 | ||
611c83ae | 6958 | struct breakpoint * |
a6d9a66e UW |
6959 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6960 | enum bptype type) | |
611c83ae PA |
6961 | { |
6962 | struct symtab_and_line sal; | |
6963 | ||
6964 | sal = find_pc_line (pc, 0); | |
6965 | sal.pc = pc; | |
6966 | sal.section = find_pc_overlay (pc); | |
6967 | sal.explicit_pc = 1; | |
6968 | ||
a6d9a66e | 6969 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6970 | } |
c906108c | 6971 | \f |
c5aa993b | 6972 | |
c906108c SS |
6973 | /* Tell the user we have just set a breakpoint B. */ |
6974 | ||
6975 | static void | |
fba45db2 | 6976 | mention (struct breakpoint *b) |
c906108c SS |
6977 | { |
6978 | int say_where = 0; | |
fa8a61dc | 6979 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6980 | struct value_print_options opts; |
6981 | ||
6982 | get_user_print_options (&opts); | |
8b93c638 | 6983 | |
9a4105ab AC |
6984 | /* FIXME: This is misplaced; mention() is called by things (like |
6985 | hitting a watchpoint) other than breakpoint creation. It should | |
6986 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6987 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6988 | observer_notify_breakpoint_created (b->number); |
c906108c | 6989 | |
3086aeae DJ |
6990 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6991 | b->ops->print_mention (b); | |
6992 | else | |
6993 | switch (b->type) | |
6994 | { | |
6995 | case bp_none: | |
3e43a32a MS |
6996 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), |
6997 | b->number); | |
3086aeae DJ |
6998 | break; |
6999 | case bp_watchpoint: | |
7000 | ui_out_text (uiout, "Watchpoint "); | |
7001 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
7002 | ui_out_field_int (uiout, "number", b->number); | |
7003 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7004 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7005 | do_cleanups (ui_out_chain); |
7006 | break; | |
7007 | case bp_hardware_watchpoint: | |
7008 | ui_out_text (uiout, "Hardware watchpoint "); | |
7009 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
7010 | ui_out_field_int (uiout, "number", b->number); | |
7011 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7012 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7013 | do_cleanups (ui_out_chain); |
7014 | break; | |
7015 | case bp_read_watchpoint: | |
7016 | ui_out_text (uiout, "Hardware read watchpoint "); | |
7017 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
7018 | ui_out_field_int (uiout, "number", b->number); | |
7019 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7020 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7021 | do_cleanups (ui_out_chain); |
7022 | break; | |
7023 | case bp_access_watchpoint: | |
7024 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
7025 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
7026 | ui_out_field_int (uiout, "number", b->number); | |
7027 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7028 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7029 | do_cleanups (ui_out_chain); |
7030 | break; | |
7031 | case bp_breakpoint: | |
7032 | if (ui_out_is_mi_like_p (uiout)) | |
7033 | { | |
7034 | say_where = 0; | |
7035 | break; | |
7036 | } | |
2cec12e5 AR |
7037 | if (b->disposition == disp_del) |
7038 | printf_filtered (_("Temporary breakpoint")); | |
7039 | else | |
7040 | printf_filtered (_("Breakpoint")); | |
7041 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
7042 | say_where = 1; |
7043 | break; | |
7044 | case bp_hardware_breakpoint: | |
7045 | if (ui_out_is_mi_like_p (uiout)) | |
7046 | { | |
7047 | say_where = 0; | |
7048 | break; | |
7049 | } | |
a3f17187 | 7050 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
7051 | say_where = 1; |
7052 | break; | |
1042e4c0 SS |
7053 | case bp_tracepoint: |
7054 | if (ui_out_is_mi_like_p (uiout)) | |
7055 | { | |
7056 | say_where = 0; | |
7057 | break; | |
7058 | } | |
7059 | printf_filtered (_("Tracepoint")); | |
7060 | printf_filtered (_(" %d"), b->number); | |
7061 | say_where = 1; | |
7062 | break; | |
7a697b8d SS |
7063 | case bp_fast_tracepoint: |
7064 | if (ui_out_is_mi_like_p (uiout)) | |
7065 | { | |
7066 | say_where = 0; | |
7067 | break; | |
7068 | } | |
7069 | printf_filtered (_("Fast tracepoint")); | |
7070 | printf_filtered (_(" %d"), b->number); | |
7071 | say_where = 1; | |
7072 | break; | |
0fb4aa4b PA |
7073 | case bp_static_tracepoint: |
7074 | if (ui_out_is_mi_like_p (uiout)) | |
7075 | { | |
7076 | say_where = 0; | |
7077 | break; | |
7078 | } | |
7079 | printf_filtered (_("Static tracepoint")); | |
7080 | printf_filtered (_(" %d"), b->number); | |
7081 | say_where = 1; | |
7082 | break; | |
3086aeae DJ |
7083 | |
7084 | case bp_until: | |
7085 | case bp_finish: | |
7086 | case bp_longjmp: | |
7087 | case bp_longjmp_resume: | |
186c406b TT |
7088 | case bp_exception: |
7089 | case bp_exception_resume: | |
3086aeae | 7090 | case bp_step_resume: |
3086aeae | 7091 | case bp_call_dummy: |
aa7d318d | 7092 | case bp_std_terminate: |
3086aeae DJ |
7093 | case bp_watchpoint_scope: |
7094 | case bp_shlib_event: | |
7095 | case bp_thread_event: | |
7096 | case bp_overlay_event: | |
4efc6507 | 7097 | case bp_jit_event: |
0fd8e87f | 7098 | case bp_longjmp_master: |
aa7d318d | 7099 | case bp_std_terminate_master: |
186c406b | 7100 | case bp_exception_master: |
3086aeae DJ |
7101 | break; |
7102 | } | |
c906108c | 7103 | |
c906108c SS |
7104 | if (say_where) |
7105 | { | |
a3f17187 AC |
7106 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
7107 | single string. */ | |
0d381245 | 7108 | if (b->loc == NULL) |
c906108c | 7109 | { |
a3f17187 | 7110 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
7111 | } |
7112 | else | |
7113 | { | |
79a45b7d | 7114 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
7115 | { |
7116 | printf_filtered (" at "); | |
5af949e3 UW |
7117 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
7118 | gdb_stdout); | |
0101ce28 JJ |
7119 | } |
7120 | if (b->source_file) | |
7121 | printf_filtered (": file %s, line %d.", | |
7122 | b->source_file, b->line_number); | |
0d381245 VP |
7123 | |
7124 | if (b->loc->next) | |
7125 | { | |
7126 | struct bp_location *loc = b->loc; | |
7127 | int n = 0; | |
7128 | for (; loc; loc = loc->next) | |
7129 | ++n; | |
7130 | printf_filtered (" (%d locations)", n); | |
7131 | } | |
7132 | ||
c906108c | 7133 | } |
c906108c | 7134 | } |
9dc5e2a9 | 7135 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7136 | return; |
c906108c SS |
7137 | printf_filtered ("\n"); |
7138 | } | |
c906108c | 7139 | \f |
c5aa993b | 7140 | |
0d381245 | 7141 | static struct bp_location * |
39d61571 | 7142 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7143 | const struct symtab_and_line *sal) |
7144 | { | |
7145 | struct bp_location *loc, **tmp; | |
7146 | ||
39d61571 | 7147 | loc = allocate_bp_location (b); |
0d381245 VP |
7148 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7149 | ; | |
7150 | *tmp = loc; | |
a6d9a66e UW |
7151 | loc->gdbarch = get_sal_arch (*sal); |
7152 | if (!loc->gdbarch) | |
7153 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7154 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7155 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7156 | loc->requested_address, b->type); | |
6c95b8df PA |
7157 | loc->pspace = sal->pspace; |
7158 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7159 | loc->section = sal->section; |
7160 | ||
7161 | set_breakpoint_location_function (loc); | |
7162 | return loc; | |
7163 | } | |
514f746b AR |
7164 | \f |
7165 | ||
7166 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7167 | return 0 otherwise. */ | |
7168 | ||
7169 | static int | |
7170 | bp_loc_is_permanent (struct bp_location *loc) | |
7171 | { | |
7172 | int len; | |
7173 | CORE_ADDR addr; | |
7174 | const gdb_byte *brk; | |
7175 | gdb_byte *target_mem; | |
939c61fa JK |
7176 | struct cleanup *cleanup; |
7177 | int retval = 0; | |
514f746b AR |
7178 | |
7179 | gdb_assert (loc != NULL); | |
7180 | ||
7181 | addr = loc->address; | |
a6d9a66e | 7182 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7183 | |
939c61fa JK |
7184 | /* Software breakpoints unsupported? */ |
7185 | if (brk == NULL) | |
7186 | return 0; | |
7187 | ||
514f746b AR |
7188 | target_mem = alloca (len); |
7189 | ||
939c61fa JK |
7190 | /* Enable the automatic memory restoration from breakpoints while |
7191 | we read the memory. Otherwise we could say about our temporary | |
7192 | breakpoints they are permanent. */ | |
6c95b8df PA |
7193 | cleanup = save_current_space_and_thread (); |
7194 | ||
7195 | switch_to_program_space_and_thread (loc->pspace); | |
7196 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7197 | |
514f746b AR |
7198 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7199 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7200 | retval = 1; |
514f746b | 7201 | |
939c61fa JK |
7202 | do_cleanups (cleanup); |
7203 | ||
7204 | return retval; | |
514f746b AR |
7205 | } |
7206 | ||
7207 | ||
c3f6f71d | 7208 | |
018d34a4 VP |
7209 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7210 | as textual description of the location, and COND_STRING | |
db107f19 | 7211 | as condition expression. */ |
018d34a4 VP |
7212 | |
7213 | static void | |
8cdf0e15 VP |
7214 | create_breakpoint_sal (struct gdbarch *gdbarch, |
7215 | struct symtabs_and_lines sals, char *addr_string, | |
7216 | char *cond_string, | |
7217 | enum bptype type, enum bpdisp disposition, | |
7218 | int thread, int task, int ignore_count, | |
84f4c1fe | 7219 | struct breakpoint_ops *ops, int from_tty, |
56435ebe | 7220 | int enabled, int internal, int display_canonical) |
018d34a4 | 7221 | { |
0d381245 VP |
7222 | struct breakpoint *b = NULL; |
7223 | int i; | |
018d34a4 VP |
7224 | |
7225 | if (type == bp_hardware_breakpoint) | |
7226 | { | |
7227 | int i = hw_breakpoint_used_count (); | |
7228 | int target_resources_ok = | |
d92524f1 | 7229 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7230 | i + 1, 0); |
7231 | if (target_resources_ok == 0) | |
7232 | error (_("No hardware breakpoint support in the target.")); | |
7233 | else if (target_resources_ok < 0) | |
7234 | error (_("Hardware breakpoints used exceeds limit.")); | |
7235 | } | |
7236 | ||
6c95b8df PA |
7237 | gdb_assert (sals.nelts > 0); |
7238 | ||
0d381245 VP |
7239 | for (i = 0; i < sals.nelts; ++i) |
7240 | { | |
7241 | struct symtab_and_line sal = sals.sals[i]; | |
7242 | struct bp_location *loc; | |
7243 | ||
7244 | if (from_tty) | |
5af949e3 UW |
7245 | { |
7246 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7247 | if (!loc_gdbarch) | |
7248 | loc_gdbarch = gdbarch; | |
7249 | ||
7250 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7251 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7252 | } |
0d381245 VP |
7253 | |
7254 | if (i == 0) | |
7255 | { | |
a6d9a66e | 7256 | b = set_raw_breakpoint (gdbarch, sal, type); |
84f4c1fe | 7257 | set_breakpoint_number (internal, b); |
0d381245 | 7258 | b->thread = thread; |
4a306c9a | 7259 | b->task = task; |
018d34a4 | 7260 | |
0d381245 VP |
7261 | b->cond_string = cond_string; |
7262 | b->ignore_count = ignore_count; | |
41447f92 | 7263 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7264 | b->disposition = disposition; |
6c95b8df PA |
7265 | b->pspace = sals.sals[0].pspace; |
7266 | ||
0fb4aa4b PA |
7267 | if (type == bp_static_tracepoint) |
7268 | { | |
7269 | struct static_tracepoint_marker marker; | |
7270 | ||
7271 | if (is_marker_spec (addr_string)) | |
7272 | { | |
7273 | /* We already know the marker exists, otherwise, we | |
7274 | wouldn't see a sal for it. */ | |
7275 | char *p = &addr_string[3]; | |
7276 | char *endp; | |
7277 | char *marker_str; | |
7278 | int i; | |
7279 | ||
e9cafbcc | 7280 | p = skip_spaces (p); |
0fb4aa4b | 7281 | |
e9cafbcc | 7282 | endp = skip_to_space (p); |
0fb4aa4b PA |
7283 | |
7284 | marker_str = savestring (p, endp - p); | |
7285 | b->static_trace_marker_id = marker_str; | |
7286 | ||
3e43a32a MS |
7287 | printf_filtered (_("Probed static tracepoint " |
7288 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7289 | b->static_trace_marker_id); |
7290 | } | |
7291 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7292 | { | |
7293 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
7294 | release_static_tracepoint_marker (&marker); | |
7295 | ||
3e43a32a MS |
7296 | printf_filtered (_("Probed static tracepoint " |
7297 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7298 | b->static_trace_marker_id); |
7299 | } | |
7300 | else | |
3e43a32a MS |
7301 | warning (_("Couldn't determine the static " |
7302 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7303 | } |
7304 | ||
6c95b8df | 7305 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7306 | && (b->type == bp_breakpoint |
7307 | || b->type == bp_hardware_breakpoint)) | |
7308 | b->enable_state = bp_startup_disabled; | |
7309 | ||
0d381245 VP |
7310 | loc = b->loc; |
7311 | } | |
7312 | else | |
018d34a4 | 7313 | { |
39d61571 | 7314 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7315 | } |
7316 | ||
514f746b AR |
7317 | if (bp_loc_is_permanent (loc)) |
7318 | make_breakpoint_permanent (b); | |
7319 | ||
0d381245 VP |
7320 | if (b->cond_string) |
7321 | { | |
7322 | char *arg = b->cond_string; | |
d32a6982 | 7323 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7324 | if (*arg) |
db107f19 | 7325 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7326 | } |
0d381245 | 7327 | } |
018d34a4 | 7328 | |
56435ebe | 7329 | b->display_canonical = display_canonical; |
018d34a4 VP |
7330 | if (addr_string) |
7331 | b->addr_string = addr_string; | |
7332 | else | |
7333 | /* addr_string has to be used or breakpoint_re_set will delete | |
7334 | me. */ | |
5af949e3 UW |
7335 | b->addr_string |
7336 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7337 | |
604133b5 | 7338 | b->ops = ops; |
84f4c1fe PM |
7339 | if (internal) |
7340 | /* Do not mention breakpoints with a negative number, but do | |
7341 | notify observers. */ | |
7342 | observer_notify_breakpoint_created (b->number); | |
7343 | else | |
7344 | mention (b); | |
018d34a4 VP |
7345 | } |
7346 | ||
ed0616c6 VP |
7347 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7348 | elements to fill the void space. */ | |
2c0b251b PA |
7349 | static void |
7350 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7351 | { |
7352 | int i = index_to_remove+1; | |
7353 | int last_index = sal->nelts-1; | |
7354 | ||
7355 | for (;i <= last_index; ++i) | |
7356 | sal->sals[i-1] = sal->sals[i]; | |
7357 | ||
7358 | --(sal->nelts); | |
7359 | } | |
7360 | ||
6c95b8df PA |
7361 | /* If appropriate, obtains all sals that correspond to the same file |
7362 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7363 | will want to set a breakpoint at foo.c:line, and not really care | |
7364 | about program spaces. This is done only if SAL does not have | |
7365 | explicit PC and has line and file information. If we got just a | |
7366 | single expanded sal, return the original. | |
ed0616c6 | 7367 | |
6c95b8df PA |
7368 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7369 | which the name of enclosing function is different from SAL. This | |
7370 | makes sure that if we have breakpoint originally set in template | |
7371 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7372 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7373 | |
2c0b251b | 7374 | static struct symtabs_and_lines |
ed0616c6 VP |
7375 | expand_line_sal_maybe (struct symtab_and_line sal) |
7376 | { | |
7377 | struct symtabs_and_lines expanded; | |
7378 | CORE_ADDR original_pc = sal.pc; | |
7379 | char *original_function = NULL; | |
7380 | int found; | |
7381 | int i; | |
6c95b8df | 7382 | struct cleanup *old_chain; |
ed0616c6 VP |
7383 | |
7384 | /* If we have explicit pc, don't expand. | |
7385 | If we have no line number, we can't expand. */ | |
7386 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7387 | { | |
7388 | expanded.nelts = 1; | |
7389 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7390 | expanded.sals[0] = sal; | |
7391 | return expanded; | |
7392 | } | |
7393 | ||
7394 | sal.pc = 0; | |
6c95b8df PA |
7395 | |
7396 | old_chain = save_current_space_and_thread (); | |
7397 | ||
7398 | switch_to_program_space_and_thread (sal.pspace); | |
7399 | ||
ed0616c6 | 7400 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7401 | |
7402 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7403 | expanded = expand_line_sal (sal); |
6c95b8df | 7404 | |
ed0616c6 VP |
7405 | if (expanded.nelts == 1) |
7406 | { | |
3dba1c98 JB |
7407 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7408 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7409 | xfree (expanded.sals); |
7410 | expanded.nelts = 1; | |
7411 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7412 | sal.pc = original_pc; | |
7413 | expanded.sals[0] = sal; | |
3dba1c98 | 7414 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7415 | do_cleanups (old_chain); |
ed0616c6 VP |
7416 | return expanded; |
7417 | } | |
7418 | ||
7419 | if (!sal.explicit_line) | |
7420 | { | |
7421 | CORE_ADDR func_addr, func_end; | |
7422 | for (i = 0; i < expanded.nelts; ++i) | |
7423 | { | |
7424 | CORE_ADDR pc = expanded.sals[i].pc; | |
7425 | char *this_function; | |
6c95b8df PA |
7426 | |
7427 | /* We need to switch threads as well since we're about to | |
7428 | read memory. */ | |
7429 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7430 | ||
ed0616c6 VP |
7431 | if (find_pc_partial_function (pc, &this_function, |
7432 | &func_addr, &func_end)) | |
7433 | { | |
059fb39f PM |
7434 | if (this_function |
7435 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7436 | { |
7437 | remove_sal (&expanded, i); | |
7438 | --i; | |
7439 | } | |
ed0616c6 VP |
7440 | } |
7441 | } | |
7442 | } | |
059acae7 UW |
7443 | |
7444 | /* Skip the function prologue if necessary. */ | |
7445 | for (i = 0; i < expanded.nelts; ++i) | |
7446 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7447 | |
6c95b8df PA |
7448 | do_cleanups (old_chain); |
7449 | ||
ed0616c6 VP |
7450 | if (expanded.nelts <= 1) |
7451 | { | |
4a64f543 MS |
7452 | /* This is un ugly workaround. If we get zero expanded sals |
7453 | then something is really wrong. Fix that by returning the | |
7454 | original sal. */ | |
7455 | ||
ed0616c6 VP |
7456 | xfree (expanded.sals); |
7457 | expanded.nelts = 1; | |
7458 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7459 | sal.pc = original_pc; | |
7460 | expanded.sals[0] = sal; | |
7461 | return expanded; | |
7462 | } | |
7463 | ||
7464 | if (original_pc) | |
7465 | { | |
7466 | found = 0; | |
7467 | for (i = 0; i < expanded.nelts; ++i) | |
7468 | if (expanded.sals[i].pc == original_pc) | |
7469 | { | |
7470 | found = 1; | |
7471 | break; | |
7472 | } | |
7473 | gdb_assert (found); | |
7474 | } | |
7475 | ||
7476 | return expanded; | |
7477 | } | |
7478 | ||
018d34a4 VP |
7479 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7480 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7481 | value. COND_STRING, if not NULL, specified the condition to be | |
7482 | used for all breakpoints. Essentially the only case where | |
7483 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7484 | function. In that case, it's still not possible to specify | |
7485 | separate conditions for different overloaded functions, so | |
7486 | we take just a single condition string. | |
7487 | ||
c3f6f71d | 7488 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7489 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7490 | array contents). If the function fails (error() is called), the |
7491 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7492 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7493 | |
7494 | static void | |
8cdf0e15 | 7495 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7496 | struct symtabs_and_lines sals, |
7497 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7498 | char *cond_string, |
7499 | enum bptype type, enum bpdisp disposition, | |
7500 | int thread, int task, int ignore_count, | |
7501 | struct breakpoint_ops *ops, int from_tty, | |
84f4c1fe | 7502 | int enabled, int internal) |
c906108c | 7503 | { |
018d34a4 | 7504 | int i; |
cc59ec59 | 7505 | |
018d34a4 | 7506 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7507 | { |
ed0616c6 VP |
7508 | struct symtabs_and_lines expanded = |
7509 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7510 | |
7efd8fc2 | 7511 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7512 | cond_string, type, disposition, |
84f4c1fe | 7513 | thread, task, ignore_count, ops, |
56435ebe TT |
7514 | from_tty, enabled, internal, |
7515 | canonical->special_display); | |
c3f6f71d | 7516 | } |
c3f6f71d | 7517 | } |
c906108c | 7518 | |
9998af43 | 7519 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7520 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7521 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7522 | address strings. ADDRESS points to the end of the SAL. |
7523 | ||
7524 | The array and the line spec strings are allocated on the heap, it is | |
7525 | the caller's responsibility to free them. */ | |
c906108c | 7526 | |
b9362cc7 | 7527 | static void |
c3f6f71d JM |
7528 | parse_breakpoint_sals (char **address, |
7529 | struct symtabs_and_lines *sals, | |
7efd8fc2 | 7530 | struct linespec_result *canonical, |
0101ce28 | 7531 | int *not_found_ptr) |
c3f6f71d JM |
7532 | { |
7533 | char *addr_start = *address; | |
cc59ec59 | 7534 | |
c3f6f71d | 7535 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7536 | breakpoint. */ |
c3f6f71d JM |
7537 | if ((*address) == NULL |
7538 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7539 | { |
7540 | if (default_breakpoint_valid) | |
7541 | { | |
c3f6f71d | 7542 | struct symtab_and_line sal; |
cc59ec59 | 7543 | |
4a64f543 | 7544 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7545 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7546 | xmalloc (sizeof (struct symtab_and_line)); |
7547 | sal.pc = default_breakpoint_address; | |
7548 | sal.line = default_breakpoint_line; | |
7549 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7550 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7551 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7552 | |
4a64f543 MS |
7553 | /* "break" without arguments is equivalent to "break *PC" |
7554 | where PC is the default_breakpoint_address. So make sure | |
7555 | to set sal.explicit_pc to prevent GDB from trying to | |
7556 | expand the list of sals to include all other instances | |
7557 | with the same symtab and line. */ | |
00903456 JK |
7558 | sal.explicit_pc = 1; |
7559 | ||
c3f6f71d JM |
7560 | sals->sals[0] = sal; |
7561 | sals->nelts = 1; | |
c906108c SS |
7562 | } |
7563 | else | |
8a3fe4f8 | 7564 | error (_("No default breakpoint address now.")); |
c906108c SS |
7565 | } |
7566 | else | |
7567 | { | |
c906108c | 7568 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7569 | current_source_symtab (which is decode_line_1's default). |
7570 | This should produce the results we want almost all of the | |
7571 | time while leaving default_breakpoint_* alone. | |
7572 | ||
1aeae86e AF |
7573 | ObjC: However, don't match an Objective-C method name which |
7574 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7575 | |
c214a6fd | 7576 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7577 | |
c906108c | 7578 | if (default_breakpoint_valid |
0378c332 | 7579 | && (!cursal.symtab |
1aeae86e AF |
7580 | || ((strchr ("+-", (*address)[0]) != NULL) |
7581 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7582 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
7efd8fc2 | 7583 | default_breakpoint_line, canonical, |
0101ce28 | 7584 | not_found_ptr); |
c906108c | 7585 | else |
0101ce28 | 7586 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7efd8fc2 | 7587 | canonical, not_found_ptr); |
c906108c | 7588 | } |
4a64f543 | 7589 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 TT |
7590 | if (sals->nelts > 0 && canonical->canonical == NULL) |
7591 | canonical->canonical = xcalloc (sals->nelts, sizeof (char **)); | |
c3f6f71d | 7592 | if (addr_start != (*address)) |
c906108c | 7593 | { |
c3f6f71d | 7594 | int i; |
cc59ec59 | 7595 | |
c3f6f71d | 7596 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7597 | { |
4a64f543 | 7598 | /* Add the string if not present. */ |
7efd8fc2 TT |
7599 | if (canonical->canonical[i] == NULL) |
7600 | canonical->canonical[i] = savestring (addr_start, | |
7601 | (*address) - addr_start); | |
c906108c SS |
7602 | } |
7603 | } | |
c3f6f71d | 7604 | } |
c906108c | 7605 | |
c906108c | 7606 | |
c3f6f71d | 7607 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7608 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7609 | |
b9362cc7 | 7610 | static void |
23e7acfb | 7611 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7612 | { |
7613 | int i; | |
cc59ec59 | 7614 | |
c3f6f71d | 7615 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7616 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7617 | } |
7618 | ||
7a697b8d SS |
7619 | /* Fast tracepoints may have restrictions on valid locations. For |
7620 | instance, a fast tracepoint using a jump instead of a trap will | |
7621 | likely have to overwrite more bytes than a trap would, and so can | |
7622 | only be placed where the instruction is longer than the jump, or a | |
7623 | multi-instruction sequence does not have a jump into the middle of | |
7624 | it, etc. */ | |
7625 | ||
7626 | static void | |
7627 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7628 | struct symtabs_and_lines *sals) | |
7629 | { | |
7630 | int i, rslt; | |
7631 | struct symtab_and_line *sal; | |
7632 | char *msg; | |
7633 | struct cleanup *old_chain; | |
7634 | ||
7635 | for (i = 0; i < sals->nelts; i++) | |
7636 | { | |
7637 | sal = &sals->sals[i]; | |
7638 | ||
7639 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7640 | NULL, &msg); | |
7641 | old_chain = make_cleanup (xfree, msg); | |
7642 | ||
7643 | if (!rslt) | |
7644 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7645 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7646 | ||
7647 | do_cleanups (old_chain); | |
7648 | } | |
7649 | } | |
7650 | ||
05ff989b | 7651 | static void |
0101ce28 JJ |
7652 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7653 | { | |
7654 | struct captured_parse_breakpoint_args *args = data; | |
7655 | ||
7efd8fc2 | 7656 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->canonical_p, |
0101ce28 | 7657 | args->not_found_ptr); |
0101ce28 JJ |
7658 | } |
7659 | ||
018d34a4 VP |
7660 | /* Given TOK, a string specification of condition and thread, as |
7661 | accepted by the 'break' command, extract the condition | |
7662 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7663 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7664 | If no condition is found, *COND_STRING is set to NULL. |
7665 | If no thread is found, *THREAD is set to -1. */ | |
7666 | static void | |
7667 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7668 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7669 | { |
7670 | *cond_string = NULL; | |
7671 | *thread = -1; | |
7672 | while (tok && *tok) | |
7673 | { | |
7674 | char *end_tok; | |
7675 | int toklen; | |
7676 | char *cond_start = NULL; | |
7677 | char *cond_end = NULL; | |
cc59ec59 | 7678 | |
e9cafbcc | 7679 | tok = skip_spaces (tok); |
018d34a4 | 7680 | |
e9cafbcc | 7681 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7682 | |
7683 | toklen = end_tok - tok; | |
7684 | ||
7685 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7686 | { | |
f7545552 TT |
7687 | struct expression *expr; |
7688 | ||
018d34a4 | 7689 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7690 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7691 | xfree (expr); | |
018d34a4 VP |
7692 | cond_end = tok; |
7693 | *cond_string = savestring (cond_start, | |
7694 | cond_end - cond_start); | |
7695 | } | |
7696 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7697 | { | |
7698 | char *tmptok; | |
7699 | ||
7700 | tok = end_tok + 1; | |
7701 | tmptok = tok; | |
7702 | *thread = strtol (tok, &tok, 0); | |
7703 | if (tok == tmptok) | |
7704 | error (_("Junk after thread keyword.")); | |
7705 | if (!valid_thread_id (*thread)) | |
7706 | error (_("Unknown thread %d."), *thread); | |
7707 | } | |
4a306c9a JB |
7708 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7709 | { | |
7710 | char *tmptok; | |
7711 | ||
7712 | tok = end_tok + 1; | |
7713 | tmptok = tok; | |
7714 | *task = strtol (tok, &tok, 0); | |
7715 | if (tok == tmptok) | |
7716 | error (_("Junk after task keyword.")); | |
7717 | if (!valid_task_id (*task)) | |
b6199126 | 7718 | error (_("Unknown task %d."), *task); |
4a306c9a | 7719 | } |
018d34a4 VP |
7720 | else |
7721 | error (_("Junk at end of arguments.")); | |
7722 | } | |
7723 | } | |
7724 | ||
0fb4aa4b PA |
7725 | /* Decode a static tracepoint marker spec. */ |
7726 | ||
7727 | static struct symtabs_and_lines | |
7728 | decode_static_tracepoint_spec (char **arg_p) | |
7729 | { | |
7730 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7731 | struct symtabs_and_lines sals; | |
7732 | struct symtab_and_line sal; | |
7733 | struct symbol *sym; | |
7734 | struct cleanup *old_chain; | |
7735 | char *p = &(*arg_p)[3]; | |
7736 | char *endp; | |
7737 | char *marker_str; | |
7738 | int i; | |
7739 | ||
e9cafbcc | 7740 | p = skip_spaces (p); |
0fb4aa4b | 7741 | |
e9cafbcc | 7742 | endp = skip_to_space (p); |
0fb4aa4b PA |
7743 | |
7744 | marker_str = savestring (p, endp - p); | |
7745 | old_chain = make_cleanup (xfree, marker_str); | |
7746 | ||
7747 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7748 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7749 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7750 | ||
7751 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7752 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7753 | ||
7754 | for (i = 0; i < sals.nelts; i++) | |
7755 | { | |
7756 | struct static_tracepoint_marker *marker; | |
7757 | ||
7758 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7759 | ||
7760 | init_sal (&sals.sals[i]); | |
7761 | ||
7762 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7763 | sals.sals[i].pc = marker->address; | |
7764 | ||
7765 | release_static_tracepoint_marker (marker); | |
7766 | } | |
7767 | ||
7768 | do_cleanups (old_chain); | |
7769 | ||
7770 | *arg_p = endp; | |
7771 | return sals; | |
7772 | } | |
7773 | ||
fd9b8c24 PA |
7774 | /* Set a breakpoint. This function is shared between CLI and MI |
7775 | functions for setting a breakpoint. This function has two major | |
7776 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7777 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7778 | breakpoint location, address and thread. Otherwise, ARG is just |
7779 | the location of breakpoint, with condition and thread specified by | |
7780 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7781 | the breakpoint number will be allocated from the internal | |
7782 | breakpoint count. Returns true if any breakpoint was created; | |
7783 | false otherwise. */ | |
0101ce28 | 7784 | |
8cdf0e15 VP |
7785 | int |
7786 | create_breakpoint (struct gdbarch *gdbarch, | |
7787 | char *arg, char *cond_string, int thread, | |
7788 | int parse_condition_and_thread, | |
0fb4aa4b | 7789 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7790 | int ignore_count, |
7791 | enum auto_boolean pending_break_support, | |
7792 | struct breakpoint_ops *ops, | |
84f4c1fe | 7793 | int from_tty, int enabled, int internal) |
c3f6f71d | 7794 | { |
71fff37b | 7795 | struct gdb_exception e; |
c3f6f71d | 7796 | struct symtabs_and_lines sals; |
0101ce28 | 7797 | struct symtab_and_line pending_sal; |
0101ce28 | 7798 | char *copy_arg; |
c3f6f71d | 7799 | char *addr_start = arg; |
7efd8fc2 | 7800 | struct linespec_result canonical; |
c3f6f71d | 7801 | struct cleanup *old_chain; |
80c99de1 | 7802 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7803 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7804 | int i; |
0101ce28 | 7805 | int pending = 0; |
0101ce28 | 7806 | int not_found = 0; |
4a306c9a | 7807 | int task = 0; |
86b17b60 | 7808 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7809 | |
c3f6f71d JM |
7810 | sals.sals = NULL; |
7811 | sals.nelts = 0; | |
7efd8fc2 | 7812 | init_linespec_result (&canonical); |
c3f6f71d | 7813 | |
0101ce28 JJ |
7814 | parse_args.arg_p = &arg; |
7815 | parse_args.sals_p = &sals; | |
7efd8fc2 | 7816 | parse_args.canonical_p = &canonical; |
0101ce28 JJ |
7817 | parse_args.not_found_ptr = ¬_found; |
7818 | ||
0fb4aa4b PA |
7819 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7820 | { | |
7821 | int i; | |
7822 | ||
7823 | sals = decode_static_tracepoint_spec (&arg); | |
7824 | ||
7825 | copy_arg = savestring (addr_start, arg - addr_start); | |
7efd8fc2 | 7826 | canonical.canonical = xcalloc (sals.nelts, sizeof (char **)); |
0fb4aa4b | 7827 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7828 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7829 | goto done; |
7830 | } | |
7831 | ||
05ff989b AC |
7832 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7833 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7834 | |
7835 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7836 | switch (e.reason) |
0101ce28 | 7837 | { |
05ff989b | 7838 | case RETURN_QUIT: |
98deb0da | 7839 | throw_exception (e); |
05ff989b AC |
7840 | case RETURN_ERROR: |
7841 | switch (e.error) | |
0101ce28 | 7842 | { |
05ff989b | 7843 | case NOT_FOUND_ERROR: |
0101ce28 | 7844 | |
05ff989b AC |
7845 | /* If pending breakpoint support is turned off, throw |
7846 | error. */ | |
fa8d40ab JJ |
7847 | |
7848 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7849 | throw_exception (e); |
7850 | ||
7851 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7852 | |
05ff989b AC |
7853 | /* If pending breakpoint support is auto query and the user |
7854 | selects no, then simply return the error code. */ | |
059fb39f | 7855 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7856 | && !nquery (_("Make breakpoint pending on " |
7857 | "future shared library load? "))) | |
fd9b8c24 | 7858 | return 0; |
fa8d40ab | 7859 | |
05ff989b AC |
7860 | /* At this point, either the user was queried about setting |
7861 | a pending breakpoint and selected yes, or pending | |
7862 | breakpoint behavior is on and thus a pending breakpoint | |
7863 | is defaulted on behalf of the user. */ | |
0101ce28 | 7864 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 7865 | canonical.canonical = ©_arg; |
0101ce28 JJ |
7866 | sals.nelts = 1; |
7867 | sals.sals = &pending_sal; | |
7868 | pending_sal.pc = 0; | |
7869 | pending = 1; | |
05ff989b AC |
7870 | break; |
7871 | default: | |
98deb0da | 7872 | throw_exception (e); |
0101ce28 | 7873 | } |
2abae994 | 7874 | break; |
05ff989b AC |
7875 | default: |
7876 | if (!sals.nelts) | |
fd9b8c24 | 7877 | return 0; |
0101ce28 | 7878 | } |
c3f6f71d | 7879 | |
0fb4aa4b PA |
7880 | done: |
7881 | ||
4a64f543 | 7882 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7883 | old_chain = make_cleanup (null_cleanup, 0); |
7884 | ||
0101ce28 JJ |
7885 | if (!pending) |
7886 | { | |
7887 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7888 | make_cleanup (xfree, sals.sals); | |
7889 | ||
7efd8fc2 TT |
7890 | /* Cleanup the canonical array but not its contents. */ |
7891 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 7892 | } |
c3f6f71d | 7893 | |
c3f6f71d JM |
7894 | /* ----------------------------- SNIP ----------------------------- |
7895 | Anything added to the cleanup chain beyond this point is assumed | |
7896 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7897 | then the memory is not reclaimed. */ |
7898 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 7899 | |
7efd8fc2 | 7900 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 7901 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7902 | for (i = 0; i < sals.nelts; i++) |
7903 | { | |
7efd8fc2 TT |
7904 | if (canonical.canonical[i] != NULL) |
7905 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
7906 | } |
7907 | ||
7908 | /* Resolve all line numbers to PC's and verify that the addresses | |
7909 | are ok for the target. */ | |
0101ce28 | 7910 | if (!pending) |
23e7acfb | 7911 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7912 | |
7a697b8d SS |
7913 | /* Fast tracepoints may have additional restrictions on location. */ |
7914 | if (type_wanted == bp_fast_tracepoint) | |
7915 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7916 | ||
c3f6f71d JM |
7917 | /* Verify that condition can be parsed, before setting any |
7918 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7919 | breakpoint. */ |
0101ce28 | 7920 | if (!pending) |
c3f6f71d | 7921 | { |
2f069f6f | 7922 | if (parse_condition_and_thread) |
72b2ff0e VP |
7923 | { |
7924 | /* Here we only parse 'arg' to separate condition | |
7925 | from thread number, so parsing in context of first | |
7926 | sal is OK. When setting the breakpoint we'll | |
7927 | re-parse it in context of each sal. */ | |
7928 | cond_string = NULL; | |
7929 | thread = -1; | |
4a306c9a JB |
7930 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7931 | &thread, &task); | |
72b2ff0e VP |
7932 | if (cond_string) |
7933 | make_cleanup (xfree, cond_string); | |
7934 | } | |
2f069f6f | 7935 | else |
72b2ff0e VP |
7936 | { |
7937 | /* Create a private copy of condition string. */ | |
7938 | if (cond_string) | |
7939 | { | |
7940 | cond_string = xstrdup (cond_string); | |
7941 | make_cleanup (xfree, cond_string); | |
7942 | } | |
7943 | } | |
0fb4aa4b PA |
7944 | |
7945 | /* If the user is creating a static tracepoint by marker id | |
7946 | (strace -m MARKER_ID), then store the sals index, so that | |
7947 | breakpoint_re_set can try to match up which of the newly | |
7948 | found markers corresponds to this one, and, don't try to | |
7949 | expand multiple locations for each sal, given than SALS | |
7950 | already should contain all sals for MARKER_ID. */ | |
7951 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 7952 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
7953 | { |
7954 | int i; | |
7955 | ||
7956 | for (i = 0; i < sals.nelts; ++i) | |
7957 | { | |
7958 | struct symtabs_and_lines expanded; | |
7959 | struct breakpoint *tp; | |
7960 | struct cleanup *old_chain; | |
7961 | ||
7962 | expanded.nelts = 1; | |
7963 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7964 | expanded.sals[0] = sals.sals[i]; | |
7965 | old_chain = make_cleanup (xfree, expanded.sals); | |
7966 | ||
7efd8fc2 | 7967 | create_breakpoint_sal (gdbarch, expanded, canonical.canonical[i], |
0fb4aa4b PA |
7968 | cond_string, type_wanted, |
7969 | tempflag ? disp_del : disp_donttouch, | |
7970 | thread, task, ignore_count, ops, | |
56435ebe TT |
7971 | from_tty, enabled, internal, |
7972 | canonical.special_display); | |
0fb4aa4b PA |
7973 | |
7974 | do_cleanups (old_chain); | |
7975 | ||
7976 | /* Get the tracepoint we just created. */ | |
84f4c1fe PM |
7977 | if (internal) |
7978 | tp = get_breakpoint (internal_breakpoint_number); | |
7979 | else | |
7980 | tp = get_breakpoint (breakpoint_count); | |
0fb4aa4b PA |
7981 | gdb_assert (tp != NULL); |
7982 | ||
7983 | /* Given that its possible to have multiple markers with | |
7984 | the same string id, if the user is creating a static | |
7985 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7986 | store the sals index, so that breakpoint_re_set can | |
7987 | try to match up which of the newly found markers | |
7988 | corresponds to this one */ | |
7989 | tp->static_trace_marker_id_idx = i; | |
7990 | } | |
7991 | } | |
7992 | else | |
7efd8fc2 | 7993 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
7994 | type_wanted, |
7995 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7996 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7997 | enabled, internal); |
c906108c | 7998 | } |
0101ce28 JJ |
7999 | else |
8000 | { | |
0101ce28 JJ |
8001 | struct breakpoint *b; |
8002 | ||
0101ce28 JJ |
8003 | make_cleanup (xfree, copy_arg); |
8004 | ||
a6d9a66e | 8005 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
84f4c1fe | 8006 | set_breakpoint_number (internal, b); |
72b2ff0e | 8007 | b->thread = -1; |
7efd8fc2 | 8008 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 8009 | b->cond_string = NULL; |
0101ce28 | 8010 | b->ignore_count = ignore_count; |
0101ce28 | 8011 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8012 | b->condition_not_parsed = 1; |
604133b5 | 8013 | b->ops = ops; |
41447f92 | 8014 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 8015 | b->pspace = current_program_space; |
84f4c1fe | 8016 | b->py_bp_object = NULL; |
74960c60 | 8017 | |
6c95b8df | 8018 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8019 | && (b->type == bp_breakpoint |
8020 | || b->type == bp_hardware_breakpoint)) | |
8021 | b->enable_state = bp_startup_disabled; | |
8022 | ||
84f4c1fe PM |
8023 | if (internal) |
8024 | /* Do not mention breakpoints with a negative number, | |
8025 | but do notify observers. */ | |
8026 | observer_notify_breakpoint_created (b->number); | |
8027 | else | |
8028 | mention (b); | |
0101ce28 JJ |
8029 | } |
8030 | ||
c3f6f71d | 8031 | if (sals.nelts > 1) |
95a42b64 | 8032 | { |
3e43a32a MS |
8033 | warning (_("Multiple breakpoints were set.\nUse the " |
8034 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8035 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8036 | } |
8037 | ||
80c99de1 PA |
8038 | /* That's it. Discard the cleanups for data inserted into the |
8039 | breakpoint. */ | |
8040 | discard_cleanups (bkpt_chain); | |
8041 | /* But cleanup everything else. */ | |
c3f6f71d | 8042 | do_cleanups (old_chain); |
217dc9e2 | 8043 | |
80c99de1 | 8044 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8045 | update_global_location_list (1); |
fd9b8c24 PA |
8046 | |
8047 | return 1; | |
c3f6f71d | 8048 | } |
c906108c | 8049 | |
72b2ff0e VP |
8050 | /* Set a breakpoint. |
8051 | ARG is a string describing breakpoint address, | |
8052 | condition, and thread. | |
8053 | FLAG specifies if a breakpoint is hardware on, | |
8054 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8055 | and BP_TEMPFLAG. */ | |
8056 | ||
98deb0da | 8057 | static void |
72b2ff0e | 8058 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8059 | { |
72b2ff0e | 8060 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8061 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8062 | ? bp_hardware_breakpoint | |
8063 | : bp_breakpoint); | |
c3f6f71d | 8064 | |
8cdf0e15 VP |
8065 | create_breakpoint (get_current_arch (), |
8066 | arg, | |
8067 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8068 | tempflag, type_wanted, |
8cdf0e15 VP |
8069 | 0 /* Ignore count */, |
8070 | pending_break_support, | |
8071 | NULL /* breakpoint_ops */, | |
8072 | from_tty, | |
84f4c1fe PM |
8073 | 1 /* enabled */, |
8074 | 0 /* internal */); | |
c906108c SS |
8075 | } |
8076 | ||
72b2ff0e | 8077 | |
c906108c SS |
8078 | /* Helper function for break_command_1 and disassemble_command. */ |
8079 | ||
8080 | void | |
fba45db2 | 8081 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8082 | { |
8083 | CORE_ADDR pc; | |
8084 | ||
8085 | if (sal->pc == 0 && sal->symtab != NULL) | |
8086 | { | |
8087 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8088 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8089 | sal->line, sal->symtab->filename); |
8090 | sal->pc = pc; | |
6a048695 | 8091 | |
4a64f543 MS |
8092 | /* If this SAL corresponds to a breakpoint inserted using a line |
8093 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8094 | if (sal->explicit_line) |
059acae7 | 8095 | skip_prologue_sal (sal); |
c906108c SS |
8096 | } |
8097 | ||
8098 | if (sal->section == 0 && sal->symtab != NULL) | |
8099 | { | |
8100 | struct blockvector *bv; | |
c5aa993b JM |
8101 | struct block *b; |
8102 | struct symbol *sym; | |
c906108c | 8103 | |
801e3a5b | 8104 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8105 | if (bv != NULL) |
8106 | { | |
7f0df278 | 8107 | sym = block_linkage_function (b); |
c906108c SS |
8108 | if (sym != NULL) |
8109 | { | |
8110 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8111 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8112 | } |
8113 | else | |
8114 | { | |
4a64f543 MS |
8115 | /* It really is worthwhile to have the section, so we'll |
8116 | just have to look harder. This case can be executed | |
8117 | if we have line numbers but no functions (as can | |
8118 | happen in assembly source). */ | |
c906108c | 8119 | |
c5aa993b | 8120 | struct minimal_symbol *msym; |
6c95b8df PA |
8121 | struct cleanup *old_chain = save_current_space_and_thread (); |
8122 | ||
8123 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8124 | |
8125 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8126 | if (msym) | |
714835d5 | 8127 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8128 | |
8129 | do_cleanups (old_chain); | |
c906108c SS |
8130 | } |
8131 | } | |
8132 | } | |
8133 | } | |
8134 | ||
8135 | void | |
fba45db2 | 8136 | break_command (char *arg, int from_tty) |
c906108c | 8137 | { |
db107f19 | 8138 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8139 | } |
8140 | ||
c906108c | 8141 | void |
fba45db2 | 8142 | tbreak_command (char *arg, int from_tty) |
c906108c | 8143 | { |
db107f19 | 8144 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8145 | } |
8146 | ||
c906108c | 8147 | static void |
fba45db2 | 8148 | hbreak_command (char *arg, int from_tty) |
c906108c | 8149 | { |
db107f19 | 8150 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8151 | } |
8152 | ||
8153 | static void | |
fba45db2 | 8154 | thbreak_command (char *arg, int from_tty) |
c906108c | 8155 | { |
db107f19 | 8156 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8157 | } |
8158 | ||
8159 | static void | |
fba45db2 | 8160 | stop_command (char *arg, int from_tty) |
c906108c | 8161 | { |
a3f17187 | 8162 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8163 | Usage: stop in <function | address>\n\ |
a3f17187 | 8164 | stop at <line>\n")); |
c906108c SS |
8165 | } |
8166 | ||
8167 | static void | |
fba45db2 | 8168 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8169 | { |
8170 | int badInput = 0; | |
8171 | ||
c5aa993b | 8172 | if (arg == (char *) NULL) |
c906108c SS |
8173 | badInput = 1; |
8174 | else if (*arg != '*') | |
8175 | { | |
8176 | char *argptr = arg; | |
8177 | int hasColon = 0; | |
8178 | ||
4a64f543 | 8179 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8180 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8181 | function/method name. */ |
c906108c | 8182 | while (*argptr && !hasColon) |
c5aa993b JM |
8183 | { |
8184 | hasColon = (*argptr == ':'); | |
8185 | argptr++; | |
8186 | } | |
c906108c SS |
8187 | |
8188 | if (hasColon) | |
c5aa993b | 8189 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8190 | else |
c5aa993b | 8191 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8192 | } |
8193 | ||
8194 | if (badInput) | |
a3f17187 | 8195 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8196 | else |
db107f19 | 8197 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8198 | } |
8199 | ||
8200 | static void | |
fba45db2 | 8201 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8202 | { |
8203 | int badInput = 0; | |
8204 | ||
c5aa993b | 8205 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8206 | badInput = 1; |
8207 | else | |
8208 | { | |
8209 | char *argptr = arg; | |
8210 | int hasColon = 0; | |
8211 | ||
4a64f543 MS |
8212 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8213 | it is probably a line number. */ | |
c906108c | 8214 | while (*argptr && !hasColon) |
c5aa993b JM |
8215 | { |
8216 | hasColon = (*argptr == ':'); | |
8217 | argptr++; | |
8218 | } | |
c906108c SS |
8219 | |
8220 | if (hasColon) | |
c5aa993b | 8221 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8222 | else |
c5aa993b | 8223 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8224 | } |
8225 | ||
8226 | if (badInput) | |
a3f17187 | 8227 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8228 | else |
db107f19 | 8229 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8230 | } |
8231 | ||
4a64f543 MS |
8232 | /* Return non-zero if EXP is verified as constant. Returned zero |
8233 | means EXP is variable. Also the constant detection may fail for | |
8234 | some constant expressions and in such case still falsely return | |
8235 | zero. */ | |
65d79d4b SDJ |
8236 | static int |
8237 | watchpoint_exp_is_const (const struct expression *exp) | |
8238 | { | |
8239 | int i = exp->nelts; | |
8240 | ||
8241 | while (i > 0) | |
8242 | { | |
8243 | int oplenp, argsp; | |
8244 | ||
8245 | /* We are only interested in the descriptor of each element. */ | |
8246 | operator_length (exp, i, &oplenp, &argsp); | |
8247 | i -= oplenp; | |
8248 | ||
8249 | switch (exp->elts[i].opcode) | |
8250 | { | |
8251 | case BINOP_ADD: | |
8252 | case BINOP_SUB: | |
8253 | case BINOP_MUL: | |
8254 | case BINOP_DIV: | |
8255 | case BINOP_REM: | |
8256 | case BINOP_MOD: | |
8257 | case BINOP_LSH: | |
8258 | case BINOP_RSH: | |
8259 | case BINOP_LOGICAL_AND: | |
8260 | case BINOP_LOGICAL_OR: | |
8261 | case BINOP_BITWISE_AND: | |
8262 | case BINOP_BITWISE_IOR: | |
8263 | case BINOP_BITWISE_XOR: | |
8264 | case BINOP_EQUAL: | |
8265 | case BINOP_NOTEQUAL: | |
8266 | case BINOP_LESS: | |
8267 | case BINOP_GTR: | |
8268 | case BINOP_LEQ: | |
8269 | case BINOP_GEQ: | |
8270 | case BINOP_REPEAT: | |
8271 | case BINOP_COMMA: | |
8272 | case BINOP_EXP: | |
8273 | case BINOP_MIN: | |
8274 | case BINOP_MAX: | |
8275 | case BINOP_INTDIV: | |
8276 | case BINOP_CONCAT: | |
8277 | case BINOP_IN: | |
8278 | case BINOP_RANGE: | |
8279 | case TERNOP_COND: | |
8280 | case TERNOP_SLICE: | |
8281 | case TERNOP_SLICE_COUNT: | |
8282 | ||
8283 | case OP_LONG: | |
8284 | case OP_DOUBLE: | |
8285 | case OP_DECFLOAT: | |
8286 | case OP_LAST: | |
8287 | case OP_COMPLEX: | |
8288 | case OP_STRING: | |
8289 | case OP_BITSTRING: | |
8290 | case OP_ARRAY: | |
8291 | case OP_TYPE: | |
8292 | case OP_NAME: | |
8293 | case OP_OBJC_NSSTRING: | |
8294 | ||
8295 | case UNOP_NEG: | |
8296 | case UNOP_LOGICAL_NOT: | |
8297 | case UNOP_COMPLEMENT: | |
8298 | case UNOP_ADDR: | |
8299 | case UNOP_HIGH: | |
4a64f543 MS |
8300 | /* Unary, binary and ternary operators: We have to check |
8301 | their operands. If they are constant, then so is the | |
8302 | result of that operation. For instance, if A and B are | |
8303 | determined to be constants, then so is "A + B". | |
8304 | ||
8305 | UNOP_IND is one exception to the rule above, because the | |
8306 | value of *ADDR is not necessarily a constant, even when | |
8307 | ADDR is. */ | |
65d79d4b SDJ |
8308 | break; |
8309 | ||
8310 | case OP_VAR_VALUE: | |
8311 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8312 | |
65d79d4b | 8313 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8314 | possible that a buggy compiler could mark a variable as |
8315 | constant even when it is not, and TYPE_CONST would return | |
8316 | true in this case, while SYMBOL_CLASS wouldn't. | |
8317 | ||
8318 | We also have to check for function symbols because they | |
8319 | are always constant. */ | |
65d79d4b SDJ |
8320 | { |
8321 | struct symbol *s = exp->elts[i + 2].symbol; | |
8322 | ||
8323 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8324 | && SYMBOL_CLASS (s) != LOC_CONST | |
8325 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8326 | return 0; | |
8327 | break; | |
8328 | } | |
8329 | ||
8330 | /* The default action is to return 0 because we are using | |
8331 | the optimistic approach here: If we don't know something, | |
8332 | then it is not a constant. */ | |
8333 | default: | |
8334 | return 0; | |
8335 | } | |
8336 | } | |
8337 | ||
8338 | return 1; | |
8339 | } | |
8340 | ||
77b06cd7 TJB |
8341 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8342 | ||
8343 | static int | |
8344 | insert_watchpoint (struct bp_location *bl) | |
8345 | { | |
e09342b5 TJB |
8346 | int length = bl->owner->exact? 1 : bl->length; |
8347 | ||
8348 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
8349 | bl->owner->cond_exp); | |
77b06cd7 TJB |
8350 | } |
8351 | ||
8352 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8353 | ||
8354 | static int | |
8355 | remove_watchpoint (struct bp_location *bl) | |
8356 | { | |
e09342b5 TJB |
8357 | int length = bl->owner->exact? 1 : bl->length; |
8358 | ||
8359 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
8360 | bl->owner->cond_exp); | |
8361 | } | |
8362 | ||
8363 | /* Implement the "resources_needed" breakpoint_ops method for | |
8364 | hardware watchpoints. */ | |
8365 | ||
8366 | static int | |
8367 | resources_needed_watchpoint (const struct bp_location *bl) | |
8368 | { | |
90e4670f | 8369 | int length = bl->owner->exact? 1 : bl->length; |
e09342b5 | 8370 | |
90e4670f | 8371 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
77b06cd7 TJB |
8372 | } |
8373 | ||
8374 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8375 | ||
8376 | static struct breakpoint_ops watchpoint_breakpoint_ops = | |
8377 | { | |
8378 | insert_watchpoint, | |
8379 | remove_watchpoint, | |
8380 | NULL, /* breakpoint_hit */ | |
e09342b5 | 8381 | resources_needed_watchpoint, |
77b06cd7 TJB |
8382 | NULL, /* print_it */ |
8383 | NULL, /* print_one */ | |
8384 | NULL, /* print_mention */ | |
8385 | NULL /* print_recreate */ | |
8386 | }; | |
8387 | ||
53a5351d JM |
8388 | /* accessflag: hw_write: watch write, |
8389 | hw_read: watch read, | |
8390 | hw_access: watch access (read or write) */ | |
c906108c | 8391 | static void |
84f4c1fe PM |
8392 | watch_command_1 (char *arg, int accessflag, int from_tty, |
8393 | int just_location, int internal) | |
c906108c | 8394 | { |
d983da9c | 8395 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 8396 | struct expression *exp; |
60e1c644 | 8397 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 8398 | struct value *val, *mark, *result; |
c906108c | 8399 | struct frame_info *frame; |
c906108c SS |
8400 | char *exp_start = NULL; |
8401 | char *exp_end = NULL; | |
37e4754d | 8402 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
8403 | int toklen; |
8404 | char *cond_start = NULL; | |
8405 | char *cond_end = NULL; | |
c906108c SS |
8406 | int i, other_type_used, target_resources_ok = 0; |
8407 | enum bptype bp_type; | |
e09342b5 | 8408 | int reg_cnt = 0; |
37e4754d | 8409 | int thread = -1; |
0cf6dd15 | 8410 | int pc = 0; |
c906108c | 8411 | |
37e4754d LM |
8412 | /* Make sure that we actually have parameters to parse. */ |
8413 | if (arg != NULL && arg[0] != '\0') | |
8414 | { | |
8415 | toklen = strlen (arg); /* Size of argument list. */ | |
8416 | ||
8417 | /* Points tok to the end of the argument list. */ | |
8418 | tok = arg + toklen - 1; | |
8419 | ||
4a64f543 MS |
8420 | /* Go backwards in the parameters list. Skip the last |
8421 | parameter. If we're expecting a 'thread <thread_num>' | |
8422 | parameter, this should be the thread identifier. */ | |
37e4754d LM |
8423 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8424 | tok--; | |
8425 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8426 | tok--; | |
8427 | ||
8428 | /* Points end_tok to the beginning of the last token. */ | |
8429 | id_tok_start = tok + 1; | |
8430 | ||
4a64f543 MS |
8431 | /* Go backwards in the parameters list. Skip one more |
8432 | parameter. If we're expecting a 'thread <thread_num>' | |
8433 | parameter, we should reach a "thread" token. */ | |
37e4754d LM |
8434 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8435 | tok--; | |
8436 | ||
8437 | end_tok = tok; | |
8438 | ||
8439 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8440 | tok--; | |
8441 | ||
8442 | /* Move the pointer forward to skip the whitespace and | |
8443 | calculate the length of the token. */ | |
8444 | tok++; | |
8445 | toklen = end_tok - tok; | |
8446 | ||
8447 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8448 | { | |
8449 | /* At this point we've found a "thread" token, which means | |
8450 | the user is trying to set a watchpoint that triggers | |
8451 | only in a specific thread. */ | |
8452 | char *endp; | |
8453 | ||
8454 | /* Extract the thread ID from the next token. */ | |
8455 | thread = strtol (id_tok_start, &endp, 0); | |
8456 | ||
8457 | /* Check if the user provided a valid numeric value for the | |
8458 | thread ID. */ | |
8459 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
8460 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
8461 | ||
8462 | /* Check if the thread actually exists. */ | |
8463 | if (!valid_thread_id (thread)) | |
8464 | error (_("Unknown thread %d."), thread); | |
8465 | ||
8466 | /* Truncate the string and get rid of the thread <thread_num> | |
8467 | parameter before the parameter list is parsed by the | |
8468 | evaluate_expression() function. */ | |
8469 | *tok = '\0'; | |
8470 | } | |
8471 | } | |
8472 | ||
8473 | /* Parse the rest of the arguments. */ | |
c906108c SS |
8474 | innermost_block = NULL; |
8475 | exp_start = arg; | |
8476 | exp = parse_exp_1 (&arg, 0, 0); | |
8477 | exp_end = arg; | |
fa8a61dc TT |
8478 | /* Remove trailing whitespace from the expression before saving it. |
8479 | This makes the eventual display of the expression string a bit | |
8480 | prettier. */ | |
8481 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
8482 | --exp_end; | |
8483 | ||
65d79d4b SDJ |
8484 | /* Checking if the expression is not constant. */ |
8485 | if (watchpoint_exp_is_const (exp)) | |
8486 | { | |
8487 | int len; | |
8488 | ||
8489 | len = exp_end - exp_start; | |
8490 | while (len > 0 && isspace (exp_start[len - 1])) | |
8491 | len--; | |
8492 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
8493 | } | |
8494 | ||
c906108c SS |
8495 | exp_valid_block = innermost_block; |
8496 | mark = value_mark (); | |
a1442452 | 8497 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
8498 | |
8499 | if (just_location) | |
8500 | { | |
8501 | exp_valid_block = NULL; | |
a1442452 | 8502 | val = value_addr (result); |
06a64a0b TT |
8503 | release_value (val); |
8504 | value_free_to_mark (mark); | |
8505 | } | |
8506 | else if (val != NULL) | |
fa4727a6 | 8507 | release_value (val); |
c906108c | 8508 | |
e9cafbcc TT |
8509 | tok = skip_spaces (arg); |
8510 | end_tok = skip_to_space (tok); | |
c906108c SS |
8511 | |
8512 | toklen = end_tok - tok; | |
8513 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8514 | { | |
2d134ed3 PA |
8515 | struct expression *cond; |
8516 | ||
60e1c644 | 8517 | innermost_block = NULL; |
c906108c SS |
8518 | tok = cond_start = end_tok + 1; |
8519 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
8520 | |
8521 | /* The watchpoint expression may not be local, but the condition | |
8522 | may still be. E.g.: `watch global if local > 0'. */ | |
8523 | cond_exp_valid_block = innermost_block; | |
8524 | ||
2d134ed3 | 8525 | xfree (cond); |
c906108c SS |
8526 | cond_end = tok; |
8527 | } | |
8528 | if (*tok) | |
8a3fe4f8 | 8529 | error (_("Junk at end of command.")); |
c906108c | 8530 | |
53a5351d | 8531 | if (accessflag == hw_read) |
c5aa993b | 8532 | bp_type = bp_read_watchpoint; |
53a5351d | 8533 | else if (accessflag == hw_access) |
c5aa993b JM |
8534 | bp_type = bp_access_watchpoint; |
8535 | else | |
8536 | bp_type = bp_hardware_watchpoint; | |
c906108c | 8537 | |
e09342b5 TJB |
8538 | reg_cnt = can_use_hardware_watchpoint (val, target_exact_watchpoints); |
8539 | if (reg_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 8540 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
e09342b5 | 8541 | if (reg_cnt != 0) |
c5aa993b JM |
8542 | { |
8543 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 8544 | target_resources_ok = |
e09342b5 | 8545 | target_can_use_hardware_watchpoint (bp_type, i + reg_cnt, |
53a5351d | 8546 | other_type_used); |
c5aa993b | 8547 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8548 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 8549 | |
c5aa993b | 8550 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
3e43a32a MS |
8551 | error (_("Target can only support one kind " |
8552 | "of HW watchpoint at a time.")); | |
c5aa993b | 8553 | } |
c906108c | 8554 | |
4a64f543 MS |
8555 | /* Change the type of breakpoint to an ordinary watchpoint if a |
8556 | hardware watchpoint could not be set. */ | |
e09342b5 | 8557 | if (!reg_cnt || target_resources_ok <= 0) |
4d28f7a8 KB |
8558 | bp_type = bp_watchpoint; |
8559 | ||
d983da9c | 8560 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
8561 | |
8562 | /* If the expression is "local", then set up a "watchpoint scope" | |
8563 | breakpoint at the point where we've left the scope of the watchpoint | |
8564 | expression. Create the scope breakpoint before the watchpoint, so | |
8565 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 8566 | if (exp_valid_block && frame) |
d983da9c | 8567 | { |
edb3359d DJ |
8568 | if (frame_id_p (frame_unwind_caller_id (frame))) |
8569 | { | |
8570 | scope_breakpoint | |
a6d9a66e UW |
8571 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
8572 | frame_unwind_caller_pc (frame), | |
edb3359d | 8573 | bp_watchpoint_scope); |
d983da9c | 8574 | |
edb3359d | 8575 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 8576 | |
edb3359d DJ |
8577 | /* Automatically delete the breakpoint when it hits. */ |
8578 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 8579 | |
edb3359d DJ |
8580 | /* Only break in the proper frame (help with recursion). */ |
8581 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 8582 | |
edb3359d | 8583 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
8584 | scope_breakpoint->loc->gdbarch |
8585 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
8586 | scope_breakpoint->loc->requested_address |
8587 | = frame_unwind_caller_pc (frame); | |
8588 | scope_breakpoint->loc->address | |
a6d9a66e UW |
8589 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
8590 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
8591 | scope_breakpoint->type); |
8592 | } | |
d983da9c DJ |
8593 | } |
8594 | ||
c906108c | 8595 | /* Now set up the breakpoint. */ |
2d134ed3 | 8596 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
84f4c1fe | 8597 | set_breakpoint_number (internal, b); |
37e4754d | 8598 | b->thread = thread; |
b5de0fa7 | 8599 | b->disposition = disp_donttouch; |
c906108c SS |
8600 | b->exp = exp; |
8601 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 8602 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
8603 | if (just_location) |
8604 | { | |
8605 | struct type *t = value_type (val); | |
8606 | CORE_ADDR addr = value_as_address (val); | |
8607 | char *name; | |
8608 | ||
8609 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
8610 | name = type_to_string (t); | |
8611 | ||
d63d0675 JK |
8612 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
8613 | core_addr_to_string (addr)); | |
06a64a0b TT |
8614 | xfree (name); |
8615 | ||
d63d0675 JK |
8616 | b->exp_string = xstrprintf ("-location: %.*s", |
8617 | (int) (exp_end - exp_start), exp_start); | |
8618 | ||
06a64a0b TT |
8619 | /* The above expression is in C. */ |
8620 | b->language = language_c; | |
8621 | } | |
8622 | else | |
8623 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
c906108c | 8624 | b->val = val; |
fa4727a6 | 8625 | b->val_valid = 1; |
77b06cd7 TJB |
8626 | b->ops = &watchpoint_breakpoint_ops; |
8627 | ||
e09342b5 TJB |
8628 | /* Use an exact watchpoint when there's only one memory region to be |
8629 | watched, and only one debug register is needed to watch it. */ | |
8630 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
8631 | ||
c906108c SS |
8632 | if (cond_start) |
8633 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
8634 | else | |
8635 | b->cond_string = 0; | |
c5aa993b | 8636 | |
c906108c | 8637 | if (frame) |
f6bc2008 PA |
8638 | { |
8639 | b->watchpoint_frame = get_frame_id (frame); | |
8640 | b->watchpoint_thread = inferior_ptid; | |
8641 | } | |
c906108c | 8642 | else |
f6bc2008 PA |
8643 | { |
8644 | b->watchpoint_frame = null_frame_id; | |
8645 | b->watchpoint_thread = null_ptid; | |
8646 | } | |
c906108c | 8647 | |
d983da9c | 8648 | if (scope_breakpoint != NULL) |
c906108c | 8649 | { |
d983da9c DJ |
8650 | /* The scope breakpoint is related to the watchpoint. We will |
8651 | need to act on them together. */ | |
8652 | b->related_breakpoint = scope_breakpoint; | |
8653 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 8654 | } |
d983da9c | 8655 | |
06a64a0b TT |
8656 | if (!just_location) |
8657 | value_free_to_mark (mark); | |
2d134ed3 PA |
8658 | |
8659 | /* Finally update the new watchpoint. This creates the locations | |
8660 | that should be inserted. */ | |
8661 | update_watchpoint (b, 1); | |
84f4c1fe PM |
8662 | if (internal) |
8663 | /* Do not mention breakpoints with a negative number, but do | |
8664 | notify observers. */ | |
8665 | observer_notify_breakpoint_created (b->number); | |
8666 | else | |
8667 | mention (b); | |
b60e7edf | 8668 | update_global_location_list (1); |
c906108c SS |
8669 | } |
8670 | ||
e09342b5 TJB |
8671 | /* Return count of debug registers needed to watch the given expression. |
8672 | If EXACT_WATCHPOINTS is 1, then consider that only the address of | |
8673 | the start of the watched region will be monitored (i.e., all accesses | |
8674 | will be aligned). This uses less debug registers on some targets. | |
8675 | ||
8676 | If the watchpoint cannot be handled in hardware return zero. */ | |
c906108c | 8677 | |
c906108c | 8678 | static int |
e09342b5 | 8679 | can_use_hardware_watchpoint (struct value *v, int exact_watchpoints) |
c906108c SS |
8680 | { |
8681 | int found_memory_cnt = 0; | |
2e70b7b9 | 8682 | struct value *head = v; |
c906108c SS |
8683 | |
8684 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 8685 | if (!can_use_hw_watchpoints) |
c906108c | 8686 | return 0; |
c5aa993b | 8687 | |
5c44784c JM |
8688 | /* Make sure that the value of the expression depends only upon |
8689 | memory contents, and values computed from them within GDB. If we | |
8690 | find any register references or function calls, we can't use a | |
8691 | hardware watchpoint. | |
8692 | ||
8693 | The idea here is that evaluating an expression generates a series | |
8694 | of values, one holding the value of every subexpression. (The | |
8695 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
8696 | a*b+c.) GDB's values hold almost enough information to establish | |
8697 | the criteria given above --- they identify memory lvalues, | |
8698 | register lvalues, computed values, etcetera. So we can evaluate | |
8699 | the expression, and then scan the chain of values that leaves | |
8700 | behind to decide whether we can detect any possible change to the | |
8701 | expression's final value using only hardware watchpoints. | |
8702 | ||
8703 | However, I don't think that the values returned by inferior | |
8704 | function calls are special in any way. So this function may not | |
8705 | notice that an expression involving an inferior function call | |
8706 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 8707 | for (; v; v = value_next (v)) |
c906108c | 8708 | { |
5c44784c | 8709 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 8710 | { |
8464be76 DJ |
8711 | if (v != head && value_lazy (v)) |
8712 | /* A lazy memory lvalue in the chain is one that GDB never | |
8713 | needed to fetch; we either just used its address (e.g., | |
8714 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
8715 | in `a,b'). This doesn't apply to HEAD; if that is | |
8716 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 8717 | ; |
53a5351d | 8718 | else |
5c44784c JM |
8719 | { |
8720 | /* Ahh, memory we actually used! Check if we can cover | |
8721 | it with hardware watchpoints. */ | |
df407dfe | 8722 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
8723 | |
8724 | /* We only watch structs and arrays if user asked for it | |
8725 | explicitly, never if they just happen to appear in a | |
8726 | middle of some value chain. */ | |
8727 | if (v == head | |
8728 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
8729 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
8730 | { | |
42ae5230 | 8731 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
8732 | int len; |
8733 | int num_regs; | |
8734 | ||
8735 | len = (exact_watchpoints | |
8736 | && is_scalar_type_recursive (vtype))? | |
8737 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 8738 | |
e09342b5 TJB |
8739 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
8740 | if (!num_regs) | |
2e70b7b9 MS |
8741 | return 0; |
8742 | else | |
e09342b5 | 8743 | found_memory_cnt += num_regs; |
2e70b7b9 | 8744 | } |
5c44784c | 8745 | } |
c5aa993b | 8746 | } |
5086187c AC |
8747 | else if (VALUE_LVAL (v) != not_lval |
8748 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 8749 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 8750 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 8751 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
8752 | } |
8753 | ||
8754 | /* The expression itself looks suitable for using a hardware | |
8755 | watchpoint, but give the target machine a chance to reject it. */ | |
8756 | return found_memory_cnt; | |
8757 | } | |
8758 | ||
8b93c638 | 8759 | void |
84f4c1fe | 8760 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8761 | { |
84f4c1fe | 8762 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
8763 | } |
8764 | ||
8765 | /* A helper function that looks for an argument at the start of a | |
8766 | string. The argument must also either be at the end of the string, | |
8767 | or be followed by whitespace. Returns 1 if it finds the argument, | |
8768 | 0 otherwise. If the argument is found, it updates *STR. */ | |
8769 | ||
8770 | static int | |
8771 | check_for_argument (char **str, char *arg, int arg_len) | |
8772 | { | |
8773 | if (strncmp (*str, arg, arg_len) == 0 | |
8774 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
8775 | { | |
8776 | *str += arg_len; | |
8777 | return 1; | |
8778 | } | |
8779 | return 0; | |
8780 | } | |
8781 | ||
8782 | /* A helper function that looks for the "-location" argument and then | |
8783 | calls watch_command_1. */ | |
8784 | ||
8785 | static void | |
8786 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
8787 | { | |
8788 | int just_location = 0; | |
8789 | ||
8790 | if (arg | |
8791 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
8792 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
8793 | { | |
e9cafbcc | 8794 | arg = skip_spaces (arg); |
06a64a0b TT |
8795 | just_location = 1; |
8796 | } | |
8797 | ||
84f4c1fe | 8798 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 8799 | } |
8926118c | 8800 | |
c5aa993b | 8801 | static void |
fba45db2 | 8802 | watch_command (char *arg, int from_tty) |
c906108c | 8803 | { |
06a64a0b | 8804 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
8805 | } |
8806 | ||
8b93c638 | 8807 | void |
84f4c1fe | 8808 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8809 | { |
84f4c1fe | 8810 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 8811 | } |
8926118c | 8812 | |
c5aa993b | 8813 | static void |
fba45db2 | 8814 | rwatch_command (char *arg, int from_tty) |
c906108c | 8815 | { |
06a64a0b | 8816 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
8817 | } |
8818 | ||
8b93c638 | 8819 | void |
84f4c1fe | 8820 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8821 | { |
84f4c1fe | 8822 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 8823 | } |
8926118c | 8824 | |
c5aa993b | 8825 | static void |
fba45db2 | 8826 | awatch_command (char *arg, int from_tty) |
c906108c | 8827 | { |
06a64a0b | 8828 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 8829 | } |
c906108c | 8830 | \f |
c5aa993b | 8831 | |
43ff13b4 | 8832 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8833 | because it uses the mechanisms of breakpoints. */ |
8834 | ||
bfec99b2 PA |
8835 | struct until_break_command_continuation_args |
8836 | { | |
8837 | struct breakpoint *breakpoint; | |
8838 | struct breakpoint *breakpoint2; | |
186c406b | 8839 | int thread_num; |
bfec99b2 PA |
8840 | }; |
8841 | ||
43ff13b4 | 8842 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 8843 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 8844 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 8845 | command. */ |
c2c6d25f | 8846 | static void |
604ead4a | 8847 | until_break_command_continuation (void *arg) |
43ff13b4 | 8848 | { |
bfec99b2 PA |
8849 | struct until_break_command_continuation_args *a = arg; |
8850 | ||
8851 | delete_breakpoint (a->breakpoint); | |
8852 | if (a->breakpoint2) | |
8853 | delete_breakpoint (a->breakpoint2); | |
186c406b | 8854 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
8855 | } |
8856 | ||
c906108c | 8857 | void |
ae66c1fc | 8858 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8859 | { |
8860 | struct symtabs_and_lines sals; | |
8861 | struct symtab_and_line sal; | |
206415a3 | 8862 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8863 | struct breakpoint *breakpoint; |
f107f563 | 8864 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 8865 | struct cleanup *old_chain; |
186c406b TT |
8866 | int thread; |
8867 | struct thread_info *tp; | |
c906108c SS |
8868 | |
8869 | clear_proceed_status (); | |
8870 | ||
8871 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 8872 | this function. */ |
c5aa993b | 8873 | |
c906108c SS |
8874 | if (default_breakpoint_valid) |
8875 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
7efd8fc2 | 8876 | default_breakpoint_line, NULL, NULL); |
c906108c | 8877 | else |
7efd8fc2 | 8878 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL, NULL); |
c5aa993b | 8879 | |
c906108c | 8880 | if (sals.nelts != 1) |
8a3fe4f8 | 8881 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8882 | |
c906108c | 8883 | sal = sals.sals[0]; |
4a64f543 | 8884 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 8885 | |
c906108c | 8886 | if (*arg) |
8a3fe4f8 | 8887 | error (_("Junk at end of arguments.")); |
c5aa993b | 8888 | |
c906108c | 8889 | resolve_sal_pc (&sal); |
c5aa993b | 8890 | |
ae66c1fc EZ |
8891 | if (anywhere) |
8892 | /* If the user told us to continue until a specified location, | |
8893 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8894 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8895 | null_frame_id, bp_until); | |
ae66c1fc | 8896 | else |
4a64f543 MS |
8897 | /* Otherwise, specify the selected frame, because we want to stop |
8898 | only at the very same frame. */ | |
a6d9a66e UW |
8899 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8900 | get_stack_frame_id (frame), | |
ae66c1fc | 8901 | bp_until); |
c5aa993b | 8902 | |
f107f563 | 8903 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8904 | |
186c406b TT |
8905 | tp = inferior_thread (); |
8906 | thread = tp->num; | |
8907 | ||
ae66c1fc EZ |
8908 | /* Keep within the current frame, or in frames called by the current |
8909 | one. */ | |
edb3359d DJ |
8910 | |
8911 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8912 | { |
edb3359d DJ |
8913 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8914 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8915 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8916 | sal, | |
edb3359d | 8917 | frame_unwind_caller_id (frame), |
f107f563 VP |
8918 | bp_until); |
8919 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
8920 | |
8921 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
8922 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 8923 | } |
c5aa993b | 8924 | |
c906108c | 8925 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 8926 | |
4a64f543 MS |
8927 | /* If we are running asynchronously, and proceed call above has |
8928 | actually managed to start the target, arrange for breakpoints to | |
8929 | be deleted when the target stops. Otherwise, we're already | |
8930 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 8931 | |
8ea051c5 | 8932 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8933 | { |
bfec99b2 PA |
8934 | struct until_break_command_continuation_args *args; |
8935 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8936 | |
bfec99b2 PA |
8937 | args->breakpoint = breakpoint; |
8938 | args->breakpoint2 = breakpoint2; | |
186c406b | 8939 | args->thread_num = thread; |
f107f563 VP |
8940 | |
8941 | discard_cleanups (old_chain); | |
95e54da7 PA |
8942 | add_continuation (inferior_thread (), |
8943 | until_break_command_continuation, args, | |
604ead4a | 8944 | xfree); |
f107f563 VP |
8945 | } |
8946 | else | |
c5aa993b | 8947 | do_cleanups (old_chain); |
c906108c | 8948 | } |
ae66c1fc | 8949 | |
c906108c SS |
8950 | /* This function attempts to parse an optional "if <cond>" clause |
8951 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8952 | |
c906108c SS |
8953 | Else, it returns a pointer to the condition string. (It does not |
8954 | attempt to evaluate the string against a particular block.) And, | |
8955 | it updates arg to point to the first character following the parsed | |
4a64f543 | 8956 | if clause in the arg string. */ |
53a5351d | 8957 | |
c906108c | 8958 | static char * |
fba45db2 | 8959 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8960 | { |
c5aa993b JM |
8961 | char *cond_string; |
8962 | ||
8963 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8964 | return NULL; |
c5aa993b | 8965 | |
4a64f543 | 8966 | /* Skip the "if" keyword. */ |
c906108c | 8967 | (*arg) += 2; |
c5aa993b | 8968 | |
c906108c | 8969 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 8970 | condition string. */ |
e9cafbcc | 8971 | *arg = skip_spaces (*arg); |
c906108c | 8972 | cond_string = *arg; |
c5aa993b | 8973 | |
4a64f543 MS |
8974 | /* Assume that the condition occupies the remainder of the arg |
8975 | string. */ | |
c906108c | 8976 | (*arg) += strlen (cond_string); |
c5aa993b | 8977 | |
c906108c SS |
8978 | return cond_string; |
8979 | } | |
c5aa993b | 8980 | |
c906108c SS |
8981 | /* Commands to deal with catching events, such as signals, exceptions, |
8982 | process start/exit, etc. */ | |
c5aa993b JM |
8983 | |
8984 | typedef enum | |
8985 | { | |
44feb3ce TT |
8986 | catch_fork_temporary, catch_vfork_temporary, |
8987 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8988 | } |
8989 | catch_fork_kind; | |
8990 | ||
c906108c | 8991 | static void |
cc59ec59 MS |
8992 | catch_fork_command_1 (char *arg, int from_tty, |
8993 | struct cmd_list_element *command) | |
c906108c | 8994 | { |
a6d9a66e | 8995 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8996 | char *cond_string = NULL; |
44feb3ce TT |
8997 | catch_fork_kind fork_kind; |
8998 | int tempflag; | |
8999 | ||
9000 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9001 | tempflag = (fork_kind == catch_fork_temporary | |
9002 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9003 | |
44feb3ce TT |
9004 | if (!arg) |
9005 | arg = ""; | |
e9cafbcc | 9006 | arg = skip_spaces (arg); |
c5aa993b | 9007 | |
c906108c | 9008 | /* The allowed syntax is: |
c5aa993b JM |
9009 | catch [v]fork |
9010 | catch [v]fork if <cond> | |
9011 | ||
4a64f543 | 9012 | First, check if there's an if clause. */ |
c906108c | 9013 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9014 | |
c906108c | 9015 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9016 | error (_("Junk at end of arguments.")); |
c5aa993b | 9017 | |
c906108c | 9018 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9019 | and enable reporting of such events. */ |
c5aa993b JM |
9020 | switch (fork_kind) |
9021 | { | |
44feb3ce TT |
9022 | case catch_fork_temporary: |
9023 | case catch_fork_permanent: | |
a6d9a66e | 9024 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9025 | &catch_fork_breakpoint_ops); |
c906108c | 9026 | break; |
44feb3ce TT |
9027 | case catch_vfork_temporary: |
9028 | case catch_vfork_permanent: | |
a6d9a66e | 9029 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9030 | &catch_vfork_breakpoint_ops); |
c906108c | 9031 | break; |
c5aa993b | 9032 | default: |
8a3fe4f8 | 9033 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9034 | break; |
c5aa993b | 9035 | } |
c906108c SS |
9036 | } |
9037 | ||
9038 | static void | |
cc59ec59 MS |
9039 | catch_exec_command_1 (char *arg, int from_tty, |
9040 | struct cmd_list_element *command) | |
c906108c | 9041 | { |
a6d9a66e | 9042 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9043 | int tempflag; |
c5aa993b | 9044 | char *cond_string = NULL; |
c906108c | 9045 | |
44feb3ce TT |
9046 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9047 | ||
9048 | if (!arg) | |
9049 | arg = ""; | |
e9cafbcc | 9050 | arg = skip_spaces (arg); |
c906108c SS |
9051 | |
9052 | /* The allowed syntax is: | |
c5aa993b JM |
9053 | catch exec |
9054 | catch exec if <cond> | |
c906108c | 9055 | |
4a64f543 | 9056 | First, check if there's an if clause. */ |
c906108c SS |
9057 | cond_string = ep_parse_optional_if_clause (&arg); |
9058 | ||
9059 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9060 | error (_("Junk at end of arguments.")); |
c906108c SS |
9061 | |
9062 | /* If this target supports it, create an exec catchpoint | |
4a64f543 | 9063 | and enable reporting of such events. */ |
a6d9a66e UW |
9064 | create_catchpoint (gdbarch, tempflag, cond_string, |
9065 | &catch_exec_breakpoint_ops); | |
c906108c | 9066 | } |
c5aa993b | 9067 | |
3086aeae DJ |
9068 | static enum print_stop_action |
9069 | print_exception_catchpoint (struct breakpoint *b) | |
9070 | { | |
ade92717 | 9071 | int bp_temp, bp_throw; |
3086aeae | 9072 | |
ade92717 | 9073 | annotate_catchpoint (b->number); |
3086aeae | 9074 | |
ade92717 AR |
9075 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9076 | if (b->loc->address != b->loc->requested_address) | |
9077 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9078 | b->loc->address, | |
9079 | b->number, 1); | |
df2b6d2d | 9080 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9081 | ui_out_text (uiout, |
9082 | bp_temp ? "Temporary catchpoint " | |
9083 | : "Catchpoint "); | |
9084 | if (!ui_out_is_mi_like_p (uiout)) | |
9085 | ui_out_field_int (uiout, "bkptno", b->number); | |
9086 | ui_out_text (uiout, | |
c0b37c48 AR |
9087 | bp_throw ? " (exception thrown), " |
9088 | : " (exception caught), "); | |
ade92717 AR |
9089 | if (ui_out_is_mi_like_p (uiout)) |
9090 | { | |
9091 | ui_out_field_string (uiout, "reason", | |
9092 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9093 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9094 | ui_out_field_int (uiout, "bkptno", b->number); | |
9095 | } | |
3086aeae DJ |
9096 | return PRINT_SRC_AND_LOC; |
9097 | } | |
9098 | ||
9099 | static void | |
cc59ec59 MS |
9100 | print_one_exception_catchpoint (struct breakpoint *b, |
9101 | struct bp_location **last_loc) | |
3086aeae | 9102 | { |
79a45b7d | 9103 | struct value_print_options opts; |
cc59ec59 | 9104 | |
79a45b7d TT |
9105 | get_user_print_options (&opts); |
9106 | if (opts.addressprint) | |
3086aeae DJ |
9107 | { |
9108 | annotate_field (4); | |
604133b5 AR |
9109 | if (b->loc == NULL || b->loc->shlib_disabled) |
9110 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9111 | else | |
5af949e3 UW |
9112 | ui_out_field_core_addr (uiout, "addr", |
9113 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9114 | } |
9115 | annotate_field (5); | |
604133b5 | 9116 | if (b->loc) |
a6d9a66e | 9117 | *last_loc = b->loc; |
3086aeae DJ |
9118 | if (strstr (b->addr_string, "throw") != NULL) |
9119 | ui_out_field_string (uiout, "what", "exception throw"); | |
9120 | else | |
9121 | ui_out_field_string (uiout, "what", "exception catch"); | |
9122 | } | |
9123 | ||
9124 | static void | |
9125 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9126 | { | |
ade92717 AR |
9127 | int bp_temp; |
9128 | int bp_throw; | |
9129 | ||
df2b6d2d | 9130 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9131 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9132 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9133 | : _("Catchpoint ")); | |
9134 | ui_out_field_int (uiout, "bkptno", b->number); | |
9135 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9136 | : _(" (catch)")); | |
3086aeae DJ |
9137 | } |
9138 | ||
6149aea9 PA |
9139 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9140 | catch catchpoints. */ | |
9141 | ||
9142 | static void | |
4a64f543 MS |
9143 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9144 | struct ui_file *fp) | |
6149aea9 PA |
9145 | { |
9146 | int bp_temp; | |
9147 | int bp_throw; | |
9148 | ||
9149 | bp_temp = b->disposition == disp_del; | |
9150 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9151 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9152 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
9153 | } | |
9154 | ||
3086aeae | 9155 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
9156 | NULL, /* insert */ |
9157 | NULL, /* remove */ | |
9158 | NULL, /* breakpoint_hit */ | |
e09342b5 | 9159 | NULL, /* resources_needed */ |
3086aeae DJ |
9160 | print_exception_catchpoint, |
9161 | print_one_exception_catchpoint, | |
6149aea9 PA |
9162 | print_mention_exception_catchpoint, |
9163 | print_recreate_exception_catchpoint | |
3086aeae DJ |
9164 | }; |
9165 | ||
9166 | static int | |
9167 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9168 | enum exception_event_kind ex_event, int from_tty) | |
9169 | { | |
604133b5 AR |
9170 | char *trigger_func_name; |
9171 | ||
3086aeae | 9172 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9173 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9174 | else |
604133b5 | 9175 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9176 | |
8cdf0e15 VP |
9177 | create_breakpoint (get_current_arch (), |
9178 | trigger_func_name, cond_string, -1, | |
9179 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9180 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9181 | 0, |
9182 | AUTO_BOOLEAN_TRUE /* pending */, | |
9183 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9184 | 1 /* enabled */, |
9185 | 0 /* internal */); | |
3086aeae | 9186 | |
3086aeae DJ |
9187 | return 1; |
9188 | } | |
9189 | ||
4a64f543 | 9190 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9191 | |
9192 | static void | |
fba45db2 KB |
9193 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9194 | int tempflag, int from_tty) | |
c906108c | 9195 | { |
c5aa993b | 9196 | char *cond_string = NULL; |
c5aa993b | 9197 | |
44feb3ce TT |
9198 | if (!arg) |
9199 | arg = ""; | |
e9cafbcc | 9200 | arg = skip_spaces (arg); |
c5aa993b | 9201 | |
c906108c SS |
9202 | cond_string = ep_parse_optional_if_clause (&arg); |
9203 | ||
9204 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9205 | error (_("Junk at end of arguments.")); |
c906108c | 9206 | |
059fb39f PM |
9207 | if (ex_event != EX_EVENT_THROW |
9208 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9209 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9210 | |
3086aeae DJ |
9211 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9212 | return; | |
9213 | ||
8a3fe4f8 | 9214 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9215 | } |
9216 | ||
44feb3ce TT |
9217 | /* Implementation of "catch catch" command. */ |
9218 | ||
9219 | static void | |
9220 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9221 | { | |
9222 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9223 | |
44feb3ce TT |
9224 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9225 | } | |
9226 | ||
9227 | /* Implementation of "catch throw" command. */ | |
9228 | ||
9229 | static void | |
9230 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9231 | { | |
9232 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9233 | |
44feb3ce TT |
9234 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9235 | } | |
9236 | ||
f7f9143b JB |
9237 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
9238 | ||
9239 | static void | |
a6d9a66e UW |
9240 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
9241 | struct symtab_and_line sal, | |
f7f9143b JB |
9242 | char *addr_string, |
9243 | char *exp_string, | |
9244 | char *cond_string, | |
9245 | struct expression *cond, | |
9246 | struct breakpoint_ops *ops, | |
9247 | int tempflag, | |
9248 | int from_tty) | |
9249 | { | |
9250 | struct breakpoint *b; | |
9251 | ||
9252 | if (from_tty) | |
9253 | { | |
5af949e3 UW |
9254 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9255 | if (!loc_gdbarch) | |
9256 | loc_gdbarch = gdbarch; | |
9257 | ||
6c95b8df PA |
9258 | describe_other_breakpoints (loc_gdbarch, |
9259 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9260 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9261 | version for exception catchpoints, because two catchpoints | |
9262 | used for different exception names will use the same address. | |
9263 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9264 | unproductive. Besides, the warning phrasing is also a bit |
f7f9143b JB |
9265 | inapropriate, we should use the word catchpoint, and tell |
9266 | the user what type of catchpoint it is. The above is good | |
9267 | enough for now, though. */ | |
9268 | } | |
9269 | ||
a6d9a66e | 9270 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
9271 | set_breakpoint_count (breakpoint_count + 1); |
9272 | ||
9273 | b->enable_state = bp_enabled; | |
9274 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
9275 | b->number = breakpoint_count; | |
9276 | b->ignore_count = 0; | |
511a6cd4 | 9277 | b->loc->cond = cond; |
f7f9143b JB |
9278 | b->addr_string = addr_string; |
9279 | b->language = language_ada; | |
9280 | b->cond_string = cond_string; | |
9281 | b->exp_string = exp_string; | |
9282 | b->thread = -1; | |
9283 | b->ops = ops; | |
f7f9143b JB |
9284 | |
9285 | mention (b); | |
b60e7edf | 9286 | update_global_location_list (1); |
f7f9143b JB |
9287 | } |
9288 | ||
9289 | /* Implement the "catch exception" command. */ | |
9290 | ||
9291 | static void | |
44feb3ce TT |
9292 | catch_ada_exception_command (char *arg, int from_tty, |
9293 | struct cmd_list_element *command) | |
f7f9143b | 9294 | { |
a6d9a66e | 9295 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9296 | int tempflag; |
f7f9143b | 9297 | struct symtab_and_line sal; |
f7f9143b JB |
9298 | char *addr_string = NULL; |
9299 | char *exp_string = NULL; | |
9300 | char *cond_string = NULL; | |
9301 | struct expression *cond = NULL; | |
9302 | struct breakpoint_ops *ops = NULL; | |
9303 | ||
44feb3ce TT |
9304 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9305 | ||
9306 | if (!arg) | |
9307 | arg = ""; | |
f7f9143b JB |
9308 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
9309 | &cond_string, &cond, &ops); | |
a6d9a66e | 9310 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
9311 | cond_string, cond, ops, tempflag, |
9312 | from_tty); | |
9313 | } | |
9314 | ||
a96d9b2e SDJ |
9315 | /* Cleanup function for a syscall filter list. */ |
9316 | static void | |
9317 | clean_up_filters (void *arg) | |
9318 | { | |
9319 | VEC(int) *iter = *(VEC(int) **) arg; | |
9320 | VEC_free (int, iter); | |
9321 | } | |
9322 | ||
9323 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
9324 | filter list, or NULL if no filtering is required. */ | |
9325 | static VEC(int) * | |
9326 | catch_syscall_split_args (char *arg) | |
9327 | { | |
9328 | VEC(int) *result = NULL; | |
9329 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
9330 | ||
9331 | while (*arg != '\0') | |
9332 | { | |
9333 | int i, syscall_number; | |
9334 | char *endptr; | |
9335 | char cur_name[128]; | |
9336 | struct syscall s; | |
9337 | ||
9338 | /* Skip whitespace. */ | |
9339 | while (isspace (*arg)) | |
9340 | arg++; | |
9341 | ||
9342 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9343 | cur_name[i] = arg[i]; | |
9344 | cur_name[i] = '\0'; | |
9345 | arg += i; | |
9346 | ||
9347 | /* Check if the user provided a syscall name or a number. */ | |
9348 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9349 | if (*endptr == '\0') | |
bccd0dd2 | 9350 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9351 | else |
9352 | { | |
9353 | /* We have a name. Let's check if it's valid and convert it | |
9354 | to a number. */ | |
9355 | get_syscall_by_name (cur_name, &s); | |
9356 | ||
9357 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9358 | /* Here we have to issue an error instead of a warning, |
9359 | because GDB cannot do anything useful if there's no | |
9360 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9361 | error (_("Unknown syscall name '%s'."), cur_name); |
9362 | } | |
9363 | ||
9364 | /* Ok, it's valid. */ | |
9365 | VEC_safe_push (int, result, s.number); | |
9366 | } | |
9367 | ||
9368 | discard_cleanups (cleanup); | |
9369 | return result; | |
9370 | } | |
9371 | ||
9372 | /* Implement the "catch syscall" command. */ | |
9373 | ||
9374 | static void | |
cc59ec59 MS |
9375 | catch_syscall_command_1 (char *arg, int from_tty, |
9376 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
9377 | { |
9378 | int tempflag; | |
9379 | VEC(int) *filter; | |
9380 | struct syscall s; | |
9381 | struct gdbarch *gdbarch = get_current_arch (); | |
9382 | ||
9383 | /* Checking if the feature if supported. */ | |
9384 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
9385 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 9386 | this architecture yet.")); |
a96d9b2e SDJ |
9387 | |
9388 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
9389 | ||
e9cafbcc | 9390 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
9391 | |
9392 | /* We need to do this first "dummy" translation in order | |
9393 | to get the syscall XML file loaded or, most important, | |
9394 | to display a warning to the user if there's no XML file | |
9395 | for his/her architecture. */ | |
9396 | get_syscall_by_number (0, &s); | |
9397 | ||
9398 | /* The allowed syntax is: | |
9399 | catch syscall | |
9400 | catch syscall <name | number> [<name | number> ... <name | number>] | |
9401 | ||
9402 | Let's check if there's a syscall name. */ | |
9403 | ||
9404 | if (arg != NULL) | |
9405 | filter = catch_syscall_split_args (arg); | |
9406 | else | |
9407 | filter = NULL; | |
9408 | ||
9409 | create_syscall_event_catchpoint (tempflag, filter, | |
9410 | &catch_syscall_breakpoint_ops); | |
9411 | } | |
9412 | ||
f7f9143b JB |
9413 | /* Implement the "catch assert" command. */ |
9414 | ||
9415 | static void | |
3e43a32a MS |
9416 | catch_assert_command (char *arg, int from_tty, |
9417 | struct cmd_list_element *command) | |
f7f9143b | 9418 | { |
a6d9a66e | 9419 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9420 | int tempflag; |
f7f9143b JB |
9421 | struct symtab_and_line sal; |
9422 | char *addr_string = NULL; | |
9423 | struct breakpoint_ops *ops = NULL; | |
9424 | ||
44feb3ce TT |
9425 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9426 | ||
9427 | if (!arg) | |
9428 | arg = ""; | |
f7f9143b | 9429 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
9430 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
9431 | ops, tempflag, from_tty); | |
f7f9143b JB |
9432 | } |
9433 | ||
c906108c | 9434 | static void |
fba45db2 | 9435 | catch_command (char *arg, int from_tty) |
c906108c | 9436 | { |
44feb3ce | 9437 | error (_("Catch requires an event name.")); |
c906108c SS |
9438 | } |
9439 | \f | |
9440 | ||
9441 | static void | |
fba45db2 | 9442 | tcatch_command (char *arg, int from_tty) |
c906108c | 9443 | { |
44feb3ce | 9444 | error (_("Catch requires an event name.")); |
c906108c SS |
9445 | } |
9446 | ||
80f8a6eb | 9447 | /* Delete breakpoints by address or line. */ |
c906108c SS |
9448 | |
9449 | static void | |
fba45db2 | 9450 | clear_command (char *arg, int from_tty) |
c906108c | 9451 | { |
d6e956e5 VP |
9452 | struct breakpoint *b; |
9453 | VEC(breakpoint_p) *found = 0; | |
9454 | int ix; | |
c906108c SS |
9455 | int default_match; |
9456 | struct symtabs_and_lines sals; | |
9457 | struct symtab_and_line sal; | |
c906108c SS |
9458 | int i; |
9459 | ||
9460 | if (arg) | |
9461 | { | |
9462 | sals = decode_line_spec (arg, 1); | |
9463 | default_match = 0; | |
9464 | } | |
9465 | else | |
9466 | { | |
c5aa993b | 9467 | sals.sals = (struct symtab_and_line *) |
c906108c | 9468 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 9469 | make_cleanup (xfree, sals.sals); |
4a64f543 | 9470 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
9471 | sal.line = default_breakpoint_line; |
9472 | sal.symtab = default_breakpoint_symtab; | |
9473 | sal.pc = default_breakpoint_address; | |
6c95b8df | 9474 | sal.pspace = default_breakpoint_pspace; |
c906108c | 9475 | if (sal.symtab == 0) |
8a3fe4f8 | 9476 | error (_("No source file specified.")); |
c906108c SS |
9477 | |
9478 | sals.sals[0] = sal; | |
9479 | sals.nelts = 1; | |
9480 | ||
9481 | default_match = 1; | |
9482 | } | |
9483 | ||
4a64f543 MS |
9484 | /* We don't call resolve_sal_pc here. That's not as bad as it |
9485 | seems, because all existing breakpoints typically have both | |
9486 | file/line and pc set. So, if clear is given file/line, we can | |
9487 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
9488 | |
9489 | We only support clearing given the address explicitly | |
9490 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 9491 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 9492 | due to optimization, all in one block. |
4a64f543 MS |
9493 | |
9494 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
9495 | PC corresponding to the same file:line, the breakpoint won't |
9496 | be cleared. We probably can still clear the breakpoint, but | |
9497 | since the other PC value is never presented to user, user | |
9498 | can only find it by guessing, and it does not seem important | |
9499 | to support that. */ | |
9500 | ||
4a64f543 MS |
9501 | /* For each line spec given, delete bps which correspond to it. Do |
9502 | it in two passes, solely to preserve the current behavior that | |
9503 | from_tty is forced true if we delete more than one | |
9504 | breakpoint. */ | |
c906108c | 9505 | |
80f8a6eb | 9506 | found = NULL; |
c906108c SS |
9507 | for (i = 0; i < sals.nelts; i++) |
9508 | { | |
9509 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
9510 | If line given (pc == 0), clear all bpts on specified line. |
9511 | If defaulting, clear all bpts on default line | |
c906108c | 9512 | or at default pc. |
c5aa993b JM |
9513 | |
9514 | defaulting sal.pc != 0 tests to do | |
9515 | ||
9516 | 0 1 pc | |
9517 | 1 1 pc _and_ line | |
9518 | 0 0 line | |
9519 | 1 0 <can't happen> */ | |
c906108c SS |
9520 | |
9521 | sal = sals.sals[i]; | |
c906108c | 9522 | |
4a64f543 | 9523 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 9524 | ALL_BREAKPOINTS (b) |
c5aa993b | 9525 | { |
0d381245 | 9526 | int match = 0; |
4a64f543 | 9527 | /* Are we going to delete b? */ |
cc60f2e3 | 9528 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
9529 | { |
9530 | struct bp_location *loc = b->loc; | |
9531 | for (; loc; loc = loc->next) | |
9532 | { | |
6c95b8df PA |
9533 | int pc_match = sal.pc |
9534 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
9535 | && (loc->address == sal.pc) |
9536 | && (!section_is_overlay (loc->section) | |
9537 | || loc->section == sal.section); | |
9538 | int line_match = ((default_match || (0 == sal.pc)) | |
9539 | && b->source_file != NULL | |
9540 | && sal.symtab != NULL | |
6c95b8df | 9541 | && sal.pspace == loc->pspace |
0ba1096a KT |
9542 | && filename_cmp (b->source_file, |
9543 | sal.symtab->filename) == 0 | |
0d381245 VP |
9544 | && b->line_number == sal.line); |
9545 | if (pc_match || line_match) | |
9546 | { | |
9547 | match = 1; | |
9548 | break; | |
9549 | } | |
9550 | } | |
9551 | } | |
9552 | ||
9553 | if (match) | |
d6e956e5 | 9554 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 9555 | } |
80f8a6eb MS |
9556 | } |
9557 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 9558 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
9559 | { |
9560 | if (arg) | |
8a3fe4f8 | 9561 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 9562 | else |
8a3fe4f8 | 9563 | error (_("No breakpoint at this line.")); |
80f8a6eb | 9564 | } |
c906108c | 9565 | |
d6e956e5 | 9566 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 9567 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 9568 | if (from_tty) |
a3f17187 | 9569 | { |
d6e956e5 | 9570 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
9571 | printf_unfiltered (_("Deleted breakpoint ")); |
9572 | else | |
9573 | printf_unfiltered (_("Deleted breakpoints ")); | |
9574 | } | |
80f8a6eb | 9575 | breakpoints_changed (); |
d6e956e5 VP |
9576 | |
9577 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 9578 | { |
c5aa993b | 9579 | if (from_tty) |
d6e956e5 VP |
9580 | printf_unfiltered ("%d ", b->number); |
9581 | delete_breakpoint (b); | |
c906108c | 9582 | } |
80f8a6eb MS |
9583 | if (from_tty) |
9584 | putchar_unfiltered ('\n'); | |
c906108c SS |
9585 | } |
9586 | \f | |
9587 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
9588 | all breakpoints that are marked for deletion, whether hit or not. | |
9589 | This is called after any breakpoint is hit, or after errors. */ | |
9590 | ||
9591 | void | |
fba45db2 | 9592 | breakpoint_auto_delete (bpstat bs) |
c906108c | 9593 | { |
35df4500 | 9594 | struct breakpoint *b, *b_tmp; |
c906108c SS |
9595 | |
9596 | for (; bs; bs = bs->next) | |
f431efe5 PA |
9597 | if (bs->breakpoint_at |
9598 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 9599 | && bs->stop) |
f431efe5 | 9600 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 9601 | |
35df4500 | 9602 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 9603 | { |
b5de0fa7 | 9604 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
9605 | delete_breakpoint (b); |
9606 | } | |
c906108c SS |
9607 | } |
9608 | ||
4a64f543 MS |
9609 | /* A comparison function for bp_location AP and BP being interfaced to |
9610 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
9611 | does breakpoint_address_is_meaningful say for its OWNER), | |
9612 | secondarily by ordering first bp_permanent OWNERed elements and | |
9613 | terciarily just ensuring the array is sorted stable way despite | |
9614 | qsort being an instable algorithm. */ | |
876fa593 JK |
9615 | |
9616 | static int | |
494cfb0f | 9617 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 9618 | { |
494cfb0f JK |
9619 | struct bp_location *a = *(void **) ap; |
9620 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 9621 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
9622 | int a_perm = a->owner->enable_state == bp_permanent; |
9623 | int b_perm = b->owner->enable_state == bp_permanent; | |
9624 | ||
9625 | if (a->address != b->address) | |
9626 | return (a->address > b->address) - (a->address < b->address); | |
9627 | ||
9628 | /* Sort permanent breakpoints first. */ | |
9629 | if (a_perm != b_perm) | |
9630 | return (a_perm < b_perm) - (a_perm > b_perm); | |
9631 | ||
4a64f543 MS |
9632 | /* Make the user-visible order stable across GDB runs. Locations of |
9633 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
9634 | |
9635 | if (a->owner->number != b->owner->number) | |
9636 | return (a->owner->number > b->owner->number) | |
9637 | - (a->owner->number < b->owner->number); | |
9638 | ||
9639 | return (a > b) - (a < b); | |
9640 | } | |
9641 | ||
876fa593 | 9642 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
9643 | bp_location_shadow_len_after_address_max according to the current |
9644 | content of the bp_location array. */ | |
f7545552 TT |
9645 | |
9646 | static void | |
876fa593 | 9647 | bp_location_target_extensions_update (void) |
f7545552 | 9648 | { |
876fa593 JK |
9649 | struct bp_location *bl, **blp_tmp; |
9650 | ||
9651 | bp_location_placed_address_before_address_max = 0; | |
9652 | bp_location_shadow_len_after_address_max = 0; | |
9653 | ||
9654 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
9655 | { | |
9656 | CORE_ADDR start, end, addr; | |
9657 | ||
9658 | if (!bp_location_has_shadow (bl)) | |
9659 | continue; | |
9660 | ||
9661 | start = bl->target_info.placed_address; | |
9662 | end = start + bl->target_info.shadow_len; | |
9663 | ||
9664 | gdb_assert (bl->address >= start); | |
9665 | addr = bl->address - start; | |
9666 | if (addr > bp_location_placed_address_before_address_max) | |
9667 | bp_location_placed_address_before_address_max = addr; | |
9668 | ||
9669 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
9670 | ||
9671 | gdb_assert (bl->address < end); | |
9672 | addr = end - bl->address; | |
9673 | if (addr > bp_location_shadow_len_after_address_max) | |
9674 | bp_location_shadow_len_after_address_max = addr; | |
9675 | } | |
f7545552 TT |
9676 | } |
9677 | ||
4cd9bd08 | 9678 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
9679 | into the inferior, only remove already-inserted locations that no |
9680 | longer should be inserted. Functions that delete a breakpoint or | |
9681 | breakpoints should pass false, so that deleting a breakpoint | |
9682 | doesn't have the side effect of inserting the locations of other | |
9683 | breakpoints that are marked not-inserted, but should_be_inserted | |
9684 | returns true on them. | |
9685 | ||
9686 | This behaviour is useful is situations close to tear-down -- e.g., | |
9687 | after an exec, while the target still has execution, but breakpoint | |
9688 | shadows of the previous executable image should *NOT* be restored | |
9689 | to the new image; or before detaching, where the target still has | |
9690 | execution and wants to delete breakpoints from GDB's lists, and all | |
9691 | breakpoints had already been removed from the inferior. */ | |
9692 | ||
0d381245 | 9693 | static void |
b60e7edf | 9694 | update_global_location_list (int should_insert) |
0d381245 | 9695 | { |
74960c60 | 9696 | struct breakpoint *b; |
876fa593 | 9697 | struct bp_location **locp, *loc; |
f7545552 TT |
9698 | struct cleanup *cleanups; |
9699 | ||
2d134ed3 PA |
9700 | /* Used in the duplicates detection below. When iterating over all |
9701 | bp_locations, points to the first bp_location of a given address. | |
9702 | Breakpoints and watchpoints of different types are never | |
9703 | duplicates of each other. Keep one pointer for each type of | |
9704 | breakpoint/watchpoint, so we only need to loop over all locations | |
9705 | once. */ | |
9706 | struct bp_location *bp_loc_first; /* breakpoint */ | |
9707 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
9708 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
9709 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 9710 | |
4a64f543 MS |
9711 | /* Saved former bp_location array which we compare against the newly |
9712 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
9713 | struct bp_location **old_location, **old_locp; |
9714 | unsigned old_location_count; | |
9715 | ||
9716 | old_location = bp_location; | |
9717 | old_location_count = bp_location_count; | |
9718 | bp_location = NULL; | |
9719 | bp_location_count = 0; | |
9720 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 9721 | |
74960c60 | 9722 | ALL_BREAKPOINTS (b) |
876fa593 JK |
9723 | for (loc = b->loc; loc; loc = loc->next) |
9724 | bp_location_count++; | |
9725 | ||
9726 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
9727 | locp = bp_location; | |
9728 | ALL_BREAKPOINTS (b) | |
9729 | for (loc = b->loc; loc; loc = loc->next) | |
9730 | *locp++ = loc; | |
9731 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 9732 | bp_location_compare); |
876fa593 JK |
9733 | |
9734 | bp_location_target_extensions_update (); | |
74960c60 | 9735 | |
4a64f543 MS |
9736 | /* Identify bp_location instances that are no longer present in the |
9737 | new list, and therefore should be freed. Note that it's not | |
9738 | necessary that those locations should be removed from inferior -- | |
9739 | if there's another location at the same address (previously | |
9740 | marked as duplicate), we don't need to remove/insert the | |
9741 | location. | |
876fa593 | 9742 | |
4a64f543 MS |
9743 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
9744 | and former bp_location array state respectively. */ | |
876fa593 JK |
9745 | |
9746 | locp = bp_location; | |
9747 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
9748 | old_locp++) | |
74960c60 | 9749 | { |
876fa593 | 9750 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 9751 | struct bp_location **loc2p; |
876fa593 | 9752 | |
4a64f543 MS |
9753 | /* Tells if 'old_loc' is found amoung the new locations. If |
9754 | not, we have to free it. */ | |
c7d46a38 | 9755 | int found_object = 0; |
20874c92 VP |
9756 | /* Tells if the location should remain inserted in the target. */ |
9757 | int keep_in_target = 0; | |
9758 | int removed = 0; | |
876fa593 | 9759 | |
4a64f543 MS |
9760 | /* Skip LOCP entries which will definitely never be needed. |
9761 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 9762 | while (locp < bp_location + bp_location_count |
c7d46a38 | 9763 | && (*locp)->address < old_loc->address) |
876fa593 | 9764 | locp++; |
c7d46a38 PA |
9765 | |
9766 | for (loc2p = locp; | |
9767 | (loc2p < bp_location + bp_location_count | |
9768 | && (*loc2p)->address == old_loc->address); | |
9769 | loc2p++) | |
9770 | { | |
9771 | if (*loc2p == old_loc) | |
9772 | { | |
9773 | found_object = 1; | |
9774 | break; | |
9775 | } | |
9776 | } | |
74960c60 | 9777 | |
4a64f543 MS |
9778 | /* If this location is no longer present, and inserted, look if |
9779 | there's maybe a new location at the same address. If so, | |
9780 | mark that one inserted, and don't remove this one. This is | |
9781 | needed so that we don't have a time window where a breakpoint | |
9782 | at certain location is not inserted. */ | |
74960c60 | 9783 | |
876fa593 | 9784 | if (old_loc->inserted) |
0d381245 | 9785 | { |
4a64f543 MS |
9786 | /* If the location is inserted now, we might have to remove |
9787 | it. */ | |
74960c60 | 9788 | |
876fa593 | 9789 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 9790 | { |
4a64f543 MS |
9791 | /* The location is still present in the location list, |
9792 | and still should be inserted. Don't do anything. */ | |
20874c92 | 9793 | keep_in_target = 1; |
74960c60 VP |
9794 | } |
9795 | else | |
9796 | { | |
4a64f543 MS |
9797 | /* The location is either no longer present, or got |
9798 | disabled. See if there's another location at the | |
9799 | same address, in which case we don't need to remove | |
9800 | this one from the target. */ | |
876fa593 | 9801 | |
2bdf28a0 | 9802 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
9803 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
9804 | { | |
876fa593 | 9805 | for (loc2p = locp; |
c7d46a38 PA |
9806 | (loc2p < bp_location + bp_location_count |
9807 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
9808 | loc2p++) |
9809 | { | |
9810 | struct bp_location *loc2 = *loc2p; | |
9811 | ||
2d134ed3 | 9812 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
9813 | { |
9814 | /* For the sake of should_be_inserted. | |
4a64f543 MS |
9815 | Duplicates check below will fix up this |
9816 | later. */ | |
c7d46a38 | 9817 | loc2->duplicate = 0; |
85d721b8 PA |
9818 | |
9819 | /* Read watchpoint locations are switched to | |
9820 | access watchpoints, if the former are not | |
9821 | supported, but the latter are. */ | |
9822 | if (is_hardware_watchpoint (old_loc->owner)) | |
9823 | { | |
9824 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
9825 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
9826 | } | |
9827 | ||
c7d46a38 PA |
9828 | if (loc2 != old_loc && should_be_inserted (loc2)) |
9829 | { | |
9830 | loc2->inserted = 1; | |
9831 | loc2->target_info = old_loc->target_info; | |
9832 | keep_in_target = 1; | |
9833 | break; | |
9834 | } | |
876fa593 JK |
9835 | } |
9836 | } | |
9837 | } | |
74960c60 VP |
9838 | } |
9839 | ||
20874c92 VP |
9840 | if (!keep_in_target) |
9841 | { | |
876fa593 | 9842 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 9843 | { |
4a64f543 MS |
9844 | /* This is just about all we can do. We could keep |
9845 | this location on the global list, and try to | |
9846 | remove it next time, but there's no particular | |
9847 | reason why we will succeed next time. | |
20874c92 | 9848 | |
4a64f543 MS |
9849 | Note that at this point, old_loc->owner is still |
9850 | valid, as delete_breakpoint frees the breakpoint | |
9851 | only after calling us. */ | |
3e43a32a MS |
9852 | printf_filtered (_("warning: Error removing " |
9853 | "breakpoint %d\n"), | |
876fa593 | 9854 | old_loc->owner->number); |
20874c92 VP |
9855 | } |
9856 | removed = 1; | |
9857 | } | |
0d381245 | 9858 | } |
74960c60 VP |
9859 | |
9860 | if (!found_object) | |
1c5cfe86 | 9861 | { |
db82e815 PA |
9862 | if (removed && non_stop |
9863 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9864 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9865 | { |
db82e815 PA |
9866 | /* This location was removed from the target. In |
9867 | non-stop mode, a race condition is possible where | |
9868 | we've removed a breakpoint, but stop events for that | |
9869 | breakpoint are already queued and will arrive later. | |
9870 | We apply an heuristic to be able to distinguish such | |
9871 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9872 | breakpoint location for a bit, and will retire it | |
9873 | after we see some number of events. The theory here | |
9874 | is that reporting of events should, "on the average", | |
9875 | be fair, so after a while we'll see events from all | |
9876 | threads that have anything of interest, and no longer | |
9877 | need to keep this breakpoint location around. We | |
9878 | don't hold locations forever so to reduce chances of | |
9879 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9880 | SIGTRAP. | |
9881 | ||
9882 | The heuristic failing can be disastrous on | |
9883 | decr_pc_after_break targets. | |
9884 | ||
9885 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9886 | if we fail to recognize a late breakpoint SIGTRAP, | |
9887 | because events_till_retirement has reached 0 too | |
9888 | soon, we'll fail to do the PC adjustment, and report | |
9889 | a random SIGTRAP to the user. When the user resumes | |
9890 | the inferior, it will most likely immediately crash | |
2dec564e | 9891 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
9892 | corrupted, because of being resumed e.g., in the |
9893 | middle of a multi-byte instruction, or skipped a | |
9894 | one-byte instruction. This was actually seen happen | |
9895 | on native x86-linux, and should be less rare on | |
9896 | targets that do not support new thread events, like | |
9897 | remote, due to the heuristic depending on | |
9898 | thread_count. | |
9899 | ||
9900 | Mistaking a random SIGTRAP for a breakpoint trap | |
9901 | causes similar symptoms (PC adjustment applied when | |
9902 | it shouldn't), but then again, playing with SIGTRAPs | |
9903 | behind the debugger's back is asking for trouble. | |
9904 | ||
9905 | Since hardware watchpoint traps are always | |
9906 | distinguishable from other traps, so we don't need to | |
9907 | apply keep hardware watchpoint moribund locations | |
9908 | around. We simply always ignore hardware watchpoint | |
9909 | traps we can no longer explain. */ | |
9910 | ||
876fa593 JK |
9911 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9912 | old_loc->owner = NULL; | |
20874c92 | 9913 | |
876fa593 | 9914 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9915 | } |
9916 | else | |
f431efe5 PA |
9917 | { |
9918 | old_loc->owner = NULL; | |
9919 | decref_bp_location (&old_loc); | |
9920 | } | |
20874c92 | 9921 | } |
74960c60 | 9922 | } |
1c5cfe86 | 9923 | |
2d134ed3 PA |
9924 | /* Rescan breakpoints at the same address and section, marking the |
9925 | first one as "first" and any others as "duplicates". This is so | |
9926 | that the bpt instruction is only inserted once. If we have a | |
9927 | permanent breakpoint at the same place as BPT, make that one the | |
9928 | official one, and the rest as duplicates. Permanent breakpoints | |
9929 | are sorted first for the same address. | |
9930 | ||
9931 | Do the same for hardware watchpoints, but also considering the | |
9932 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9933 | |
2d134ed3 PA |
9934 | bp_loc_first = NULL; |
9935 | wp_loc_first = NULL; | |
9936 | awp_loc_first = NULL; | |
9937 | rwp_loc_first = NULL; | |
876fa593 | 9938 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9939 | { |
4a64f543 MS |
9940 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
9941 | non-NULL. */ | |
876fa593 | 9942 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9943 | struct bp_location **loc_first_p; |
876fa593 JK |
9944 | |
9945 | if (b->enable_state == bp_disabled | |
9946 | || b->enable_state == bp_call_disabled | |
9947 | || b->enable_state == bp_startup_disabled | |
9948 | || !loc->enabled | |
9949 | || loc->shlib_disabled | |
15c3d785 | 9950 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 9951 | || is_tracepoint (b)) |
876fa593 JK |
9952 | continue; |
9953 | ||
9954 | /* Permanent breakpoint should always be inserted. */ | |
9955 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9956 | internal_error (__FILE__, __LINE__, | |
9957 | _("allegedly permanent breakpoint is not " | |
9958 | "actually inserted")); | |
9959 | ||
2d134ed3 PA |
9960 | if (b->type == bp_hardware_watchpoint) |
9961 | loc_first_p = &wp_loc_first; | |
9962 | else if (b->type == bp_read_watchpoint) | |
9963 | loc_first_p = &rwp_loc_first; | |
9964 | else if (b->type == bp_access_watchpoint) | |
9965 | loc_first_p = &awp_loc_first; | |
9966 | else | |
9967 | loc_first_p = &bp_loc_first; | |
9968 | ||
9969 | if (*loc_first_p == NULL | |
9970 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9971 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9972 | { |
2d134ed3 | 9973 | *loc_first_p = loc; |
876fa593 JK |
9974 | loc->duplicate = 0; |
9975 | continue; | |
9976 | } | |
9977 | ||
9978 | loc->duplicate = 1; | |
9979 | ||
2d134ed3 PA |
9980 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9981 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9982 | internal_error (__FILE__, __LINE__, |
9983 | _("another breakpoint was inserted on top of " | |
9984 | "a permanent breakpoint")); | |
0d381245 | 9985 | } |
74960c60 | 9986 | |
50c71eaf | 9987 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9988 | && (have_live_inferiors () |
2567c7d9 | 9989 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9990 | insert_breakpoint_locations (); |
f7545552 TT |
9991 | |
9992 | do_cleanups (cleanups); | |
74960c60 VP |
9993 | } |
9994 | ||
20874c92 VP |
9995 | void |
9996 | breakpoint_retire_moribund (void) | |
9997 | { | |
9998 | struct bp_location *loc; | |
9999 | int ix; | |
10000 | ||
10001 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10002 | if (--(loc->events_till_retirement) == 0) | |
10003 | { | |
f431efe5 | 10004 | decref_bp_location (&loc); |
20874c92 VP |
10005 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
10006 | --ix; | |
10007 | } | |
10008 | } | |
10009 | ||
74960c60 | 10010 | static void |
b60e7edf | 10011 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
10012 | { |
10013 | struct gdb_exception e; | |
cc59ec59 | 10014 | |
74960c60 | 10015 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 10016 | update_global_location_list (inserting); |
0d381245 VP |
10017 | } |
10018 | ||
f431efe5 PA |
10019 | /* Clear BKP from a BPS. */ |
10020 | ||
a474d7c2 | 10021 | static void |
f431efe5 | 10022 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
10023 | { |
10024 | bpstat bs; | |
cc59ec59 | 10025 | |
a474d7c2 | 10026 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 10027 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
10028 | { |
10029 | bs->breakpoint_at = NULL; | |
10030 | bs->old_val = NULL; | |
10031 | /* bs->commands will be freed later. */ | |
10032 | } | |
10033 | } | |
10034 | ||
10035 | /* Callback for iterate_over_threads. */ | |
10036 | static int | |
f431efe5 | 10037 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 10038 | { |
f431efe5 | 10039 | struct breakpoint *bpt = data; |
cc59ec59 | 10040 | |
16c381f0 | 10041 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
a474d7c2 PA |
10042 | return 0; |
10043 | } | |
10044 | ||
53a5351d | 10045 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 10046 | structures. */ |
c906108c SS |
10047 | |
10048 | void | |
fba45db2 | 10049 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 10050 | { |
52f0bd74 | 10051 | struct breakpoint *b; |
c906108c | 10052 | |
8a3fe4f8 | 10053 | gdb_assert (bpt != NULL); |
c906108c | 10054 | |
4a64f543 MS |
10055 | /* Has this bp already been deleted? This can happen because |
10056 | multiple lists can hold pointers to bp's. bpstat lists are | |
10057 | especial culprits. | |
10058 | ||
10059 | One example of this happening is a watchpoint's scope bp. When | |
10060 | the scope bp triggers, we notice that the watchpoint is out of | |
10061 | scope, and delete it. We also delete its scope bp. But the | |
10062 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
10063 | That bpstat is then checked for auto-deleting bp's, which are | |
10064 | deleted. | |
10065 | ||
10066 | A real solution to this problem might involve reference counts in | |
10067 | bp's, and/or giving them pointers back to their referencing | |
10068 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
10069 | storage when no more references were extent. A cheaper bandaid | |
10070 | was chosen. */ | |
c906108c SS |
10071 | if (bpt->type == bp_none) |
10072 | return; | |
10073 | ||
4a64f543 MS |
10074 | /* At least avoid this stale reference until the reference counting |
10075 | of breakpoints gets resolved. */ | |
d0fb5eae | 10076 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 10077 | { |
d0fb5eae JK |
10078 | struct breakpoint *related; |
10079 | ||
10080 | if (bpt->type == bp_watchpoint_scope) | |
10081 | watchpoint_del_at_next_stop (bpt->related_breakpoint); | |
10082 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) | |
10083 | watchpoint_del_at_next_stop (bpt); | |
10084 | ||
10085 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
10086 | for (related = bpt; related->related_breakpoint != bpt; | |
10087 | related = related->related_breakpoint); | |
10088 | related->related_breakpoint = bpt->related_breakpoint; | |
10089 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
10090 | } |
10091 | ||
383f836e | 10092 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 10093 | |
c906108c SS |
10094 | if (breakpoint_chain == bpt) |
10095 | breakpoint_chain = bpt->next; | |
10096 | ||
c906108c SS |
10097 | ALL_BREAKPOINTS (b) |
10098 | if (b->next == bpt) | |
c5aa993b JM |
10099 | { |
10100 | b->next = bpt->next; | |
10101 | break; | |
10102 | } | |
c906108c | 10103 | |
9add0f1b | 10104 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
10105 | xfree (bpt->cond_string); |
10106 | xfree (bpt->cond_exp); | |
10107 | xfree (bpt->addr_string); | |
10108 | xfree (bpt->exp); | |
10109 | xfree (bpt->exp_string); | |
d63d0675 | 10110 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
10111 | value_free (bpt->val); |
10112 | xfree (bpt->source_file); | |
10113 | xfree (bpt->exec_pathname); | |
a96d9b2e | 10114 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 10115 | |
f431efe5 PA |
10116 | |
10117 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
10118 | been freed. */ | |
10119 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
10120 | in all threeds for now. Note that we cannot just remove bpstats | |
10121 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
10122 | commands are associated with the bpstat; if we remove it here, | |
10123 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
10124 | event-top.c won't do anything, and temporary breakpoints with | |
10125 | commands won't work. */ | |
10126 | ||
10127 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
10128 | ||
4a64f543 MS |
10129 | /* Now that breakpoint is removed from breakpoint list, update the |
10130 | global location list. This will remove locations that used to | |
10131 | belong to this breakpoint. Do this before freeing the breakpoint | |
10132 | itself, since remove_breakpoint looks at location's owner. It | |
10133 | might be better design to have location completely | |
10134 | self-contained, but it's not the case now. */ | |
b60e7edf | 10135 | update_global_location_list (0); |
74960c60 VP |
10136 | |
10137 | ||
4a64f543 MS |
10138 | /* On the chance that someone will soon try again to delete this |
10139 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c SS |
10140 | bpt->type = bp_none; |
10141 | ||
b8c9b27d | 10142 | xfree (bpt); |
c906108c SS |
10143 | } |
10144 | ||
4d6140d9 AC |
10145 | static void |
10146 | do_delete_breakpoint_cleanup (void *b) | |
10147 | { | |
10148 | delete_breakpoint (b); | |
10149 | } | |
10150 | ||
10151 | struct cleanup * | |
10152 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
10153 | { | |
10154 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
10155 | } | |
10156 | ||
95a42b64 TT |
10157 | /* A callback for map_breakpoint_numbers that calls |
10158 | delete_breakpoint. */ | |
10159 | ||
10160 | static void | |
10161 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
10162 | { | |
10163 | delete_breakpoint (b); | |
10164 | } | |
10165 | ||
c906108c | 10166 | void |
fba45db2 | 10167 | delete_command (char *arg, int from_tty) |
c906108c | 10168 | { |
35df4500 | 10169 | struct breakpoint *b, *b_tmp; |
c906108c | 10170 | |
ea9365bb TT |
10171 | dont_repeat (); |
10172 | ||
c906108c SS |
10173 | if (arg == 0) |
10174 | { | |
10175 | int breaks_to_delete = 0; | |
10176 | ||
10177 | /* Delete all breakpoints if no argument. | |
4a64f543 MS |
10178 | Do not delete internal or call-dummy breakpoints, these have |
10179 | to be deleted with an explicit breakpoint number argument. */ | |
c5aa993b JM |
10180 | ALL_BREAKPOINTS (b) |
10181 | { | |
059fb39f | 10182 | if (b->type != bp_call_dummy |
aa7d318d | 10183 | && b->type != bp_std_terminate |
059fb39f | 10184 | && b->type != bp_shlib_event |
4efc6507 | 10185 | && b->type != bp_jit_event |
059fb39f PM |
10186 | && b->type != bp_thread_event |
10187 | && b->type != bp_overlay_event | |
0fd8e87f | 10188 | && b->type != bp_longjmp_master |
aa7d318d | 10189 | && b->type != bp_std_terminate_master |
186c406b | 10190 | && b->type != bp_exception_master |
059fb39f | 10191 | && b->number >= 0) |
973d738b DJ |
10192 | { |
10193 | breaks_to_delete = 1; | |
10194 | break; | |
10195 | } | |
c5aa993b | 10196 | } |
c906108c SS |
10197 | |
10198 | /* Ask user only if there are some breakpoints to delete. */ | |
10199 | if (!from_tty | |
e2e0b3e5 | 10200 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 10201 | { |
35df4500 | 10202 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10203 | { |
059fb39f | 10204 | if (b->type != bp_call_dummy |
aa7d318d | 10205 | && b->type != bp_std_terminate |
059fb39f PM |
10206 | && b->type != bp_shlib_event |
10207 | && b->type != bp_thread_event | |
4efc6507 | 10208 | && b->type != bp_jit_event |
059fb39f | 10209 | && b->type != bp_overlay_event |
0fd8e87f | 10210 | && b->type != bp_longjmp_master |
aa7d318d | 10211 | && b->type != bp_std_terminate_master |
186c406b | 10212 | && b->type != bp_exception_master |
059fb39f | 10213 | && b->number >= 0) |
c5aa993b JM |
10214 | delete_breakpoint (b); |
10215 | } | |
c906108c SS |
10216 | } |
10217 | } | |
10218 | else | |
95a42b64 | 10219 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
10220 | } |
10221 | ||
0d381245 VP |
10222 | static int |
10223 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 10224 | { |
0d381245 VP |
10225 | for (; loc; loc = loc->next) |
10226 | if (!loc->shlib_disabled) | |
10227 | return 0; | |
10228 | return 1; | |
fe3f5fa8 VP |
10229 | } |
10230 | ||
776592bf DE |
10231 | /* Subroutine of update_breakpoint_locations to simplify it. |
10232 | Return non-zero if multiple fns in list LOC have the same name. | |
10233 | Null names are ignored. */ | |
10234 | ||
10235 | static int | |
10236 | ambiguous_names_p (struct bp_location *loc) | |
10237 | { | |
10238 | struct bp_location *l; | |
10239 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
10240 | (int (*) (const void *, |
10241 | const void *)) streq, | |
776592bf DE |
10242 | NULL, xcalloc, xfree); |
10243 | ||
10244 | for (l = loc; l != NULL; l = l->next) | |
10245 | { | |
10246 | const char **slot; | |
10247 | const char *name = l->function_name; | |
10248 | ||
10249 | /* Allow for some names to be NULL, ignore them. */ | |
10250 | if (name == NULL) | |
10251 | continue; | |
10252 | ||
10253 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
10254 | INSERT); | |
4a64f543 MS |
10255 | /* NOTE: We can assume slot != NULL here because xcalloc never |
10256 | returns NULL. */ | |
776592bf DE |
10257 | if (*slot != NULL) |
10258 | { | |
10259 | htab_delete (htab); | |
10260 | return 1; | |
10261 | } | |
10262 | *slot = name; | |
10263 | } | |
10264 | ||
10265 | htab_delete (htab); | |
10266 | return 0; | |
10267 | } | |
10268 | ||
0fb4aa4b PA |
10269 | /* When symbols change, it probably means the sources changed as well, |
10270 | and it might mean the static tracepoint markers are no longer at | |
10271 | the same address or line numbers they used to be at last we | |
10272 | checked. Losing your static tracepoints whenever you rebuild is | |
10273 | undesirable. This function tries to resync/rematch gdb static | |
10274 | tracepoints with the markers on the target, for static tracepoints | |
10275 | that have not been set by marker id. Static tracepoint that have | |
10276 | been set by marker id are reset by marker id in breakpoint_re_set. | |
10277 | The heuristic is: | |
10278 | ||
10279 | 1) For a tracepoint set at a specific address, look for a marker at | |
10280 | the old PC. If one is found there, assume to be the same marker. | |
10281 | If the name / string id of the marker found is different from the | |
10282 | previous known name, assume that means the user renamed the marker | |
10283 | in the sources, and output a warning. | |
10284 | ||
10285 | 2) For a tracepoint set at a given line number, look for a marker | |
10286 | at the new address of the old line number. If one is found there, | |
10287 | assume to be the same marker. If the name / string id of the | |
10288 | marker found is different from the previous known name, assume that | |
10289 | means the user renamed the marker in the sources, and output a | |
10290 | warning. | |
10291 | ||
10292 | 3) If a marker is no longer found at the same address or line, it | |
10293 | may mean the marker no longer exists. But it may also just mean | |
10294 | the code changed a bit. Maybe the user added a few lines of code | |
10295 | that made the marker move up or down (in line number terms). Ask | |
10296 | the target for info about the marker with the string id as we knew | |
10297 | it. If found, update line number and address in the matching | |
10298 | static tracepoint. This will get confused if there's more than one | |
10299 | marker with the same ID (possible in UST, although unadvised | |
10300 | precisely because it confuses tools). */ | |
10301 | ||
10302 | static struct symtab_and_line | |
10303 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
10304 | { | |
10305 | struct static_tracepoint_marker marker; | |
10306 | CORE_ADDR pc; | |
10307 | int i; | |
10308 | ||
10309 | pc = sal.pc; | |
10310 | if (sal.line) | |
10311 | find_line_pc (sal.symtab, sal.line, &pc); | |
10312 | ||
10313 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
10314 | { | |
10315 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
10316 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
10317 | b->number, | |
10318 | b->static_trace_marker_id, marker.str_id); | |
10319 | ||
10320 | xfree (b->static_trace_marker_id); | |
10321 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
10322 | release_static_tracepoint_marker (&marker); | |
10323 | ||
10324 | return sal; | |
10325 | } | |
10326 | ||
10327 | /* Old marker wasn't found on target at lineno. Try looking it up | |
10328 | by string ID. */ | |
10329 | if (!sal.explicit_pc | |
10330 | && sal.line != 0 | |
10331 | && sal.symtab != NULL | |
10332 | && b->static_trace_marker_id != NULL) | |
10333 | { | |
10334 | VEC(static_tracepoint_marker_p) *markers; | |
10335 | ||
10336 | markers | |
10337 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
10338 | ||
10339 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
10340 | { | |
10341 | struct symtab_and_line sal; | |
10342 | struct symbol *sym; | |
10343 | struct static_tracepoint_marker *marker; | |
10344 | ||
10345 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
10346 | ||
10347 | xfree (b->static_trace_marker_id); | |
10348 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
10349 | ||
10350 | warning (_("marker for static tracepoint %d (%s) not " | |
10351 | "found at previous line number"), | |
10352 | b->number, b->static_trace_marker_id); | |
10353 | ||
10354 | init_sal (&sal); | |
10355 | ||
10356 | sal.pc = marker->address; | |
10357 | ||
10358 | sal = find_pc_line (marker->address, 0); | |
10359 | sym = find_pc_sect_function (marker->address, NULL); | |
10360 | ui_out_text (uiout, "Now in "); | |
10361 | if (sym) | |
10362 | { | |
10363 | ui_out_field_string (uiout, "func", | |
10364 | SYMBOL_PRINT_NAME (sym)); | |
10365 | ui_out_text (uiout, " at "); | |
10366 | } | |
10367 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
10368 | ui_out_text (uiout, ":"); | |
10369 | ||
10370 | if (ui_out_is_mi_like_p (uiout)) | |
10371 | { | |
10372 | char *fullname = symtab_to_fullname (sal.symtab); | |
10373 | ||
10374 | if (fullname) | |
10375 | ui_out_field_string (uiout, "fullname", fullname); | |
10376 | } | |
10377 | ||
10378 | ui_out_field_int (uiout, "line", sal.line); | |
10379 | ui_out_text (uiout, "\n"); | |
10380 | ||
10381 | b->line_number = sal.line; | |
10382 | ||
10383 | xfree (b->source_file); | |
10384 | if (sym) | |
10385 | b->source_file = xstrdup (sal.symtab->filename); | |
10386 | else | |
10387 | b->source_file = NULL; | |
10388 | ||
10389 | xfree (b->addr_string); | |
10390 | b->addr_string = xstrprintf ("%s:%d", | |
10391 | sal.symtab->filename, b->line_number); | |
10392 | ||
10393 | /* Might be nice to check if function changed, and warn if | |
10394 | so. */ | |
10395 | ||
10396 | release_static_tracepoint_marker (marker); | |
10397 | } | |
10398 | } | |
10399 | return sal; | |
10400 | } | |
10401 | ||
fe3f5fa8 | 10402 | static void |
0d381245 VP |
10403 | update_breakpoint_locations (struct breakpoint *b, |
10404 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
10405 | { |
10406 | int i; | |
10407 | char *s; | |
0d381245 VP |
10408 | struct bp_location *existing_locations = b->loc; |
10409 | ||
4a64f543 MS |
10410 | /* If there's no new locations, and all existing locations are |
10411 | pending, don't do anything. This optimizes the common case where | |
10412 | all locations are in the same shared library, that was unloaded. | |
10413 | We'd like to retain the location, so that when the library is | |
10414 | loaded again, we don't loose the enabled/disabled status of the | |
10415 | individual locations. */ | |
0d381245 | 10416 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
10417 | return; |
10418 | ||
fe3f5fa8 VP |
10419 | b->loc = NULL; |
10420 | ||
0d381245 | 10421 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 10422 | { |
0d381245 | 10423 | struct bp_location *new_loc = |
39d61571 | 10424 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 10425 | |
0d381245 VP |
10426 | /* Reparse conditions, they might contain references to the |
10427 | old symtab. */ | |
10428 | if (b->cond_string != NULL) | |
10429 | { | |
10430 | struct gdb_exception e; | |
fe3f5fa8 | 10431 | |
0d381245 VP |
10432 | s = b->cond_string; |
10433 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10434 | { | |
10435 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
10436 | 0); | |
10437 | } | |
10438 | if (e.reason < 0) | |
10439 | { | |
3e43a32a MS |
10440 | warning (_("failed to reevaluate condition " |
10441 | "for breakpoint %d: %s"), | |
0d381245 VP |
10442 | b->number, e.message); |
10443 | new_loc->enabled = 0; | |
10444 | } | |
10445 | } | |
fe3f5fa8 | 10446 | |
0d381245 VP |
10447 | if (b->source_file != NULL) |
10448 | xfree (b->source_file); | |
10449 | if (sals.sals[i].symtab == NULL) | |
10450 | b->source_file = NULL; | |
10451 | else | |
1b36a34b | 10452 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 10453 | |
0d381245 VP |
10454 | if (b->line_number == 0) |
10455 | b->line_number = sals.sals[i].line; | |
10456 | } | |
fe3f5fa8 | 10457 | |
514f746b AR |
10458 | /* Update locations of permanent breakpoints. */ |
10459 | if (b->enable_state == bp_permanent) | |
10460 | make_breakpoint_permanent (b); | |
10461 | ||
4a64f543 MS |
10462 | /* If possible, carry over 'disable' status from existing |
10463 | breakpoints. */ | |
0d381245 VP |
10464 | { |
10465 | struct bp_location *e = existing_locations; | |
776592bf DE |
10466 | /* If there are multiple breakpoints with the same function name, |
10467 | e.g. for inline functions, comparing function names won't work. | |
10468 | Instead compare pc addresses; this is just a heuristic as things | |
10469 | may have moved, but in practice it gives the correct answer | |
10470 | often enough until a better solution is found. */ | |
10471 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
10472 | ||
0d381245 VP |
10473 | for (; e; e = e->next) |
10474 | { | |
10475 | if (!e->enabled && e->function_name) | |
10476 | { | |
10477 | struct bp_location *l = b->loc; | |
776592bf DE |
10478 | if (have_ambiguous_names) |
10479 | { | |
10480 | for (; l; l = l->next) | |
6c95b8df PA |
10481 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
10482 | l->pspace->aspace, l->address)) | |
776592bf DE |
10483 | { |
10484 | l->enabled = 0; | |
10485 | break; | |
10486 | } | |
10487 | } | |
10488 | else | |
10489 | { | |
10490 | for (; l; l = l->next) | |
10491 | if (l->function_name | |
10492 | && strcmp (e->function_name, l->function_name) == 0) | |
10493 | { | |
10494 | l->enabled = 0; | |
10495 | break; | |
10496 | } | |
10497 | } | |
0d381245 VP |
10498 | } |
10499 | } | |
10500 | } | |
fe3f5fa8 | 10501 | |
b60e7edf | 10502 | update_global_location_list (1); |
fe3f5fa8 VP |
10503 | } |
10504 | ||
c906108c SS |
10505 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
10506 | The value we return ends up being the return value from catch_errors. | |
10507 | Unused in this case. */ | |
10508 | ||
10509 | static int | |
4efb68b1 | 10510 | breakpoint_re_set_one (void *bint) |
c906108c | 10511 | { |
4a64f543 | 10512 | /* Get past catch_errs. */ |
53a5351d | 10513 | struct breakpoint *b = (struct breakpoint *) bint; |
fe3f5fa8 VP |
10514 | int not_found = 0; |
10515 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
10516 | struct symtabs_and_lines sals = {0}; |
10517 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 10518 | char *s; |
fe3f5fa8 | 10519 | struct gdb_exception e; |
6c95b8df | 10520 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
0fb4aa4b | 10521 | int marker_spec = 0; |
c906108c SS |
10522 | |
10523 | switch (b->type) | |
10524 | { | |
10525 | case bp_none: | |
8a3fe4f8 | 10526 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 10527 | b->number); |
c906108c SS |
10528 | return 0; |
10529 | case bp_breakpoint: | |
10530 | case bp_hardware_breakpoint: | |
1042e4c0 | 10531 | case bp_tracepoint: |
7a697b8d | 10532 | case bp_fast_tracepoint: |
0fb4aa4b | 10533 | case bp_static_tracepoint: |
8bea4e01 UW |
10534 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10535 | if (b->enable_state == bp_startup_disabled) | |
10536 | return 0; | |
10537 | ||
c906108c SS |
10538 | if (b->addr_string == NULL) |
10539 | { | |
4a64f543 | 10540 | /* Anything without a string can't be re-set. */ |
c906108c SS |
10541 | delete_breakpoint (b); |
10542 | return 0; | |
10543 | } | |
c906108c | 10544 | |
c906108c SS |
10545 | input_radix = b->input_radix; |
10546 | s = b->addr_string; | |
6c95b8df PA |
10547 | |
10548 | save_current_space_and_thread (); | |
10549 | switch_to_program_space_and_thread (b->pspace); | |
10550 | ||
0fb4aa4b PA |
10551 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); |
10552 | ||
385d04dc | 10553 | set_language (b->language); |
fe3f5fa8 | 10554 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 10555 | { |
0fb4aa4b PA |
10556 | if (marker_spec) |
10557 | { | |
10558 | sals = decode_static_tracepoint_spec (&s); | |
10559 | if (sals.nelts > b->static_trace_marker_id_idx) | |
10560 | { | |
10561 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
10562 | sals.nelts = 1; | |
10563 | } | |
10564 | else | |
10565 | error (_("marker %s not found"), b->static_trace_marker_id); | |
10566 | } | |
10567 | else | |
3e43a32a | 10568 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, |
7efd8fc2 | 10569 | NULL, not_found_ptr); |
fe3f5fa8 VP |
10570 | } |
10571 | if (e.reason < 0) | |
10572 | { | |
10573 | int not_found_and_ok = 0; | |
4a64f543 MS |
10574 | /* For pending breakpoints, it's expected that parsing will |
10575 | fail until the right shared library is loaded. User has | |
10576 | already told to create pending breakpoints and don't need | |
10577 | extra messages. If breakpoint is in bp_shlib_disabled | |
10578 | state, then user already saw the message about that | |
10579 | breakpoint being disabled, and don't want to see more | |
10580 | errors. */ | |
0d381245 VP |
10581 | if (not_found |
10582 | && (b->condition_not_parsed | |
10583 | || (b->loc && b->loc->shlib_disabled) | |
10584 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
10585 | not_found_and_ok = 1; |
10586 | ||
10587 | if (!not_found_and_ok) | |
c906108c | 10588 | { |
fe3f5fa8 VP |
10589 | /* We surely don't want to warn about the same breakpoint |
10590 | 10 times. One solution, implemented here, is disable | |
10591 | the breakpoint on error. Another solution would be to | |
10592 | have separate 'warning emitted' flag. Since this | |
10593 | happens only when a binary has changed, I don't know | |
10594 | which approach is better. */ | |
10595 | b->enable_state = bp_disabled; | |
10596 | throw_exception (e); | |
c906108c | 10597 | } |
fe3f5fa8 | 10598 | } |
c906108c | 10599 | |
6c95b8df | 10600 | if (!not_found) |
fe3f5fa8 | 10601 | { |
6c95b8df PA |
10602 | gdb_assert (sals.nelts == 1); |
10603 | ||
10604 | resolve_sal_pc (&sals.sals[0]); | |
10605 | if (b->condition_not_parsed && s && s[0]) | |
10606 | { | |
10607 | char *cond_string = 0; | |
10608 | int thread = -1; | |
10609 | int task = 0; | |
10610 | ||
10611 | find_condition_and_thread (s, sals.sals[0].pc, | |
10612 | &cond_string, &thread, &task); | |
10613 | if (cond_string) | |
10614 | b->cond_string = cond_string; | |
10615 | b->thread = thread; | |
10616 | b->task = task; | |
10617 | b->condition_not_parsed = 0; | |
10618 | } | |
10619 | ||
0fb4aa4b PA |
10620 | if (b->type == bp_static_tracepoint && !marker_spec) |
10621 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
10622 | ||
6c95b8df | 10623 | expanded = expand_line_sal_maybe (sals.sals[0]); |
fe3f5fa8 | 10624 | } |
6c95b8df PA |
10625 | |
10626 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 10627 | update_breakpoint_locations (b, expanded); |
c906108c SS |
10628 | break; |
10629 | ||
10630 | case bp_watchpoint: | |
10631 | case bp_hardware_watchpoint: | |
10632 | case bp_read_watchpoint: | |
10633 | case bp_access_watchpoint: | |
4a64f543 MS |
10634 | /* Watchpoint can be either on expression using entirely global |
10635 | variables, or it can be on local variables. | |
10636 | ||
10637 | Watchpoints of the first kind are never auto-deleted, and | |
10638 | even persist across program restarts. Since they can use | |
10639 | variables from shared libraries, we need to reparse | |
10640 | expression as libraries are loaded and unloaded. | |
10641 | ||
10642 | Watchpoints on local variables can also change meaning as | |
10643 | result of solib event. For example, if a watchpoint uses | |
10644 | both a local and a global variables in expression, it's a | |
10645 | local watchpoint, but unloading of a shared library will make | |
10646 | the expression invalid. This is not a very common use case, | |
10647 | but we still re-evaluate expression, to avoid surprises to | |
10648 | the user. | |
0b3de036 VP |
10649 | |
10650 | Note that for local watchpoints, we re-evaluate it only if | |
10651 | watchpoints frame id is still valid. If it's not, it means | |
4a64f543 MS |
10652 | the watchpoint is out of scope and will be deleted soon. In |
10653 | fact, I'm not sure we'll ever be called in this case. | |
0b3de036 VP |
10654 | |
10655 | If a local watchpoint's frame id is still valid, then | |
4a64f543 | 10656 | b->exp_valid_block is likewise valid, and we can safely use it. |
0b3de036 VP |
10657 | |
10658 | Don't do anything about disabled watchpoints, since they will | |
10659 | be reevaluated again when enabled. */ | |
a5606eee | 10660 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 10661 | break; |
c5aa993b JM |
10662 | /* We needn't really do anything to reset these, since the mask |
10663 | that requests them is unaffected by e.g., new libraries being | |
4a64f543 | 10664 | loaded. */ |
ce78b96d | 10665 | case bp_catchpoint: |
c906108c | 10666 | break; |
c5aa993b | 10667 | |
c906108c | 10668 | default: |
a3f17187 | 10669 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 10670 | /* fall through */ |
0fd8e87f UW |
10671 | /* Delete overlay event and longjmp master breakpoints; they will be |
10672 | reset later by breakpoint_re_set. */ | |
1900040c | 10673 | case bp_overlay_event: |
0fd8e87f | 10674 | case bp_longjmp_master: |
aa7d318d | 10675 | case bp_std_terminate_master: |
186c406b | 10676 | case bp_exception_master: |
c906108c SS |
10677 | delete_breakpoint (b); |
10678 | break; | |
10679 | ||
c5aa993b JM |
10680 | /* This breakpoint is special, it's set up when the inferior |
10681 | starts and we really don't want to touch it. */ | |
c906108c SS |
10682 | case bp_shlib_event: |
10683 | ||
c4093a6a JM |
10684 | /* Like bp_shlib_event, this breakpoint type is special. |
10685 | Once it is set up, we do not want to touch it. */ | |
10686 | case bp_thread_event: | |
10687 | ||
4a64f543 MS |
10688 | /* Keep temporary breakpoints, which can be encountered when we |
10689 | step over a dlopen call and SOLIB_ADD is resetting the | |
10690 | breakpoints. Otherwise these should have been blown away via | |
10691 | the cleanup chain or by breakpoint_init_inferior when we | |
10692 | rerun the executable. */ | |
c906108c SS |
10693 | case bp_until: |
10694 | case bp_finish: | |
10695 | case bp_watchpoint_scope: | |
10696 | case bp_call_dummy: | |
aa7d318d | 10697 | case bp_std_terminate: |
c906108c | 10698 | case bp_step_resume: |
611c83ae PA |
10699 | case bp_longjmp: |
10700 | case bp_longjmp_resume: | |
186c406b TT |
10701 | case bp_exception: |
10702 | case bp_exception_resume: | |
4efc6507 | 10703 | case bp_jit_event: |
c906108c SS |
10704 | break; |
10705 | } | |
10706 | ||
6c95b8df | 10707 | do_cleanups (cleanups); |
c906108c SS |
10708 | return 0; |
10709 | } | |
10710 | ||
69de3c6a | 10711 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 10712 | void |
69de3c6a | 10713 | breakpoint_re_set (void) |
c906108c | 10714 | { |
35df4500 | 10715 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10716 | enum language save_language; |
10717 | int save_input_radix; | |
6c95b8df | 10718 | struct cleanup *old_chain; |
c5aa993b | 10719 | |
c906108c SS |
10720 | save_language = current_language->la_language; |
10721 | save_input_radix = input_radix; | |
6c95b8df PA |
10722 | old_chain = save_current_program_space (); |
10723 | ||
35df4500 | 10724 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10725 | { |
4a64f543 | 10726 | /* Format possible error msg. */ |
fe3f5fa8 | 10727 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
10728 | b->number); |
10729 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 10730 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 10731 | do_cleanups (cleanups); |
c5aa993b | 10732 | } |
c906108c SS |
10733 | set_language (save_language); |
10734 | input_radix = save_input_radix; | |
e62c965a | 10735 | |
0756c555 | 10736 | jit_breakpoint_re_set (); |
4efc6507 | 10737 | |
6c95b8df PA |
10738 | do_cleanups (old_chain); |
10739 | ||
af02033e PP |
10740 | create_overlay_event_breakpoint (); |
10741 | create_longjmp_master_breakpoint (); | |
10742 | create_std_terminate_master_breakpoint (); | |
186c406b | 10743 | create_exception_master_breakpoint (); |
c906108c SS |
10744 | } |
10745 | \f | |
c906108c SS |
10746 | /* Reset the thread number of this breakpoint: |
10747 | ||
10748 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 10749 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 10750 | void |
fba45db2 | 10751 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
10752 | { |
10753 | if (b->thread != -1) | |
10754 | { | |
39f77062 KB |
10755 | if (in_thread_list (inferior_ptid)) |
10756 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
10757 | |
10758 | /* We're being called after following a fork. The new fork is | |
10759 | selected as current, and unless this was a vfork will have a | |
10760 | different program space from the original thread. Reset that | |
10761 | as well. */ | |
10762 | b->loc->pspace = current_program_space; | |
c906108c SS |
10763 | } |
10764 | } | |
10765 | ||
03ac34d5 MS |
10766 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10767 | If from_tty is nonzero, it prints a message to that effect, | |
10768 | which ends with a period (no newline). */ | |
10769 | ||
c906108c | 10770 | void |
fba45db2 | 10771 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 10772 | { |
52f0bd74 | 10773 | struct breakpoint *b; |
c906108c SS |
10774 | |
10775 | if (count < 0) | |
10776 | count = 0; | |
10777 | ||
10778 | ALL_BREAKPOINTS (b) | |
10779 | if (b->number == bptnum) | |
c5aa993b | 10780 | { |
d77f58be SS |
10781 | if (is_tracepoint (b)) |
10782 | { | |
10783 | if (from_tty && count != 0) | |
10784 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
10785 | bptnum); | |
10786 | return; | |
10787 | } | |
10788 | ||
c5aa993b | 10789 | b->ignore_count = count; |
221ea385 KS |
10790 | if (from_tty) |
10791 | { | |
10792 | if (count == 0) | |
3e43a32a MS |
10793 | printf_filtered (_("Will stop next time " |
10794 | "breakpoint %d is reached."), | |
221ea385 KS |
10795 | bptnum); |
10796 | else if (count == 1) | |
a3f17187 | 10797 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
10798 | bptnum); |
10799 | else | |
3e43a32a MS |
10800 | printf_filtered (_("Will ignore next %d " |
10801 | "crossings of breakpoint %d."), | |
221ea385 KS |
10802 | count, bptnum); |
10803 | } | |
c5aa993b | 10804 | breakpoints_changed (); |
383f836e | 10805 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
10806 | return; |
10807 | } | |
c906108c | 10808 | |
8a3fe4f8 | 10809 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
10810 | } |
10811 | ||
c906108c SS |
10812 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
10813 | ||
10814 | static void | |
fba45db2 | 10815 | ignore_command (char *args, int from_tty) |
c906108c SS |
10816 | { |
10817 | char *p = args; | |
52f0bd74 | 10818 | int num; |
c906108c SS |
10819 | |
10820 | if (p == 0) | |
e2e0b3e5 | 10821 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 10822 | |
c906108c | 10823 | num = get_number (&p); |
5c44784c | 10824 | if (num == 0) |
8a3fe4f8 | 10825 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 10826 | if (*p == 0) |
8a3fe4f8 | 10827 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
10828 | |
10829 | set_ignore_count (num, | |
10830 | longest_to_int (value_as_long (parse_and_eval (p))), | |
10831 | from_tty); | |
221ea385 KS |
10832 | if (from_tty) |
10833 | printf_filtered ("\n"); | |
c906108c SS |
10834 | } |
10835 | \f | |
10836 | /* Call FUNCTION on each of the breakpoints | |
10837 | whose numbers are given in ARGS. */ | |
10838 | ||
10839 | static void | |
95a42b64 TT |
10840 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
10841 | void *), | |
10842 | void *data) | |
c906108c | 10843 | { |
52f0bd74 AC |
10844 | int num; |
10845 | struct breakpoint *b, *tmp; | |
11cf8741 | 10846 | int match; |
197f0a60 | 10847 | struct get_number_or_range_state state; |
c906108c | 10848 | |
197f0a60 | 10849 | if (args == 0) |
e2e0b3e5 | 10850 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 10851 | |
197f0a60 TT |
10852 | init_number_or_range (&state, args); |
10853 | ||
10854 | while (!state.finished) | |
c906108c | 10855 | { |
197f0a60 TT |
10856 | char *p = state.string; |
10857 | ||
11cf8741 | 10858 | match = 0; |
c5aa993b | 10859 | |
197f0a60 | 10860 | num = get_number_or_range (&state); |
5c44784c | 10861 | if (num == 0) |
c5aa993b | 10862 | { |
8a3fe4f8 | 10863 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
10864 | } |
10865 | else | |
10866 | { | |
10867 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
10868 | if (b->number == num) | |
10869 | { | |
d0fb5eae JK |
10870 | struct breakpoint *related_breakpoint; |
10871 | ||
11cf8741 | 10872 | match = 1; |
d0fb5eae JK |
10873 | related_breakpoint = b; |
10874 | do | |
10875 | { | |
10876 | struct breakpoint *next_related_b; | |
10877 | ||
10878 | /* FUNCTION can be also delete_breakpoint. */ | |
10879 | next_related_b = related_breakpoint->related_breakpoint; | |
10880 | function (related_breakpoint, data); | |
10881 | ||
10882 | /* For delete_breakpoint of the last entry of the ring we | |
10883 | were traversing we would never get back to B. */ | |
10884 | if (next_related_b == related_breakpoint) | |
10885 | break; | |
10886 | related_breakpoint = next_related_b; | |
10887 | } | |
10888 | while (related_breakpoint != b); | |
11cf8741 | 10889 | break; |
5c44784c | 10890 | } |
11cf8741 | 10891 | if (match == 0) |
a3f17187 | 10892 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 10893 | } |
c906108c SS |
10894 | } |
10895 | } | |
10896 | ||
0d381245 VP |
10897 | static struct bp_location * |
10898 | find_location_by_number (char *number) | |
10899 | { | |
10900 | char *dot = strchr (number, '.'); | |
10901 | char *p1; | |
10902 | int bp_num; | |
10903 | int loc_num; | |
10904 | struct breakpoint *b; | |
10905 | struct bp_location *loc; | |
10906 | ||
10907 | *dot = '\0'; | |
10908 | ||
10909 | p1 = number; | |
197f0a60 | 10910 | bp_num = get_number (&p1); |
0d381245 VP |
10911 | if (bp_num == 0) |
10912 | error (_("Bad breakpoint number '%s'"), number); | |
10913 | ||
10914 | ALL_BREAKPOINTS (b) | |
10915 | if (b->number == bp_num) | |
10916 | { | |
10917 | break; | |
10918 | } | |
10919 | ||
10920 | if (!b || b->number != bp_num) | |
10921 | error (_("Bad breakpoint number '%s'"), number); | |
10922 | ||
10923 | p1 = dot+1; | |
197f0a60 | 10924 | loc_num = get_number (&p1); |
0d381245 VP |
10925 | if (loc_num == 0) |
10926 | error (_("Bad breakpoint location number '%s'"), number); | |
10927 | ||
10928 | --loc_num; | |
10929 | loc = b->loc; | |
10930 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
10931 | ; | |
10932 | if (!loc) | |
10933 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
10934 | ||
10935 | return loc; | |
10936 | } | |
10937 | ||
10938 | ||
1900040c MS |
10939 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10940 | If from_tty is nonzero, it prints a message to that effect, | |
10941 | which ends with a period (no newline). */ | |
10942 | ||
c906108c | 10943 | void |
fba45db2 | 10944 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10945 | { |
10946 | /* Never disable a watchpoint scope breakpoint; we want to | |
10947 | hit them when we leave scope so we can delete both the | |
10948 | watchpoint and its scope breakpoint at that time. */ | |
10949 | if (bpt->type == bp_watchpoint_scope) | |
10950 | return; | |
10951 | ||
c2c6d25f | 10952 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 10953 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
10954 | return; |
10955 | ||
b5de0fa7 | 10956 | bpt->enable_state = bp_disabled; |
c906108c | 10957 | |
b60e7edf | 10958 | update_global_location_list (0); |
c906108c | 10959 | |
383f836e | 10960 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10961 | } |
10962 | ||
95a42b64 TT |
10963 | /* A callback for map_breakpoint_numbers that calls |
10964 | disable_breakpoint. */ | |
10965 | ||
10966 | static void | |
10967 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
10968 | { | |
10969 | disable_breakpoint (b); | |
10970 | } | |
10971 | ||
c906108c | 10972 | static void |
fba45db2 | 10973 | disable_command (char *args, int from_tty) |
c906108c | 10974 | { |
52f0bd74 | 10975 | struct breakpoint *bpt; |
cc59ec59 | 10976 | |
c906108c SS |
10977 | if (args == 0) |
10978 | ALL_BREAKPOINTS (bpt) | |
10979 | switch (bpt->type) | |
c5aa993b JM |
10980 | { |
10981 | case bp_none: | |
8a3fe4f8 | 10982 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 10983 | bpt->number); |
488919c4 | 10984 | break; |
c5aa993b | 10985 | case bp_breakpoint: |
1042e4c0 | 10986 | case bp_tracepoint: |
7a697b8d | 10987 | case bp_fast_tracepoint: |
0fb4aa4b | 10988 | case bp_static_tracepoint: |
ce78b96d | 10989 | case bp_catchpoint: |
c5aa993b JM |
10990 | case bp_hardware_breakpoint: |
10991 | case bp_watchpoint: | |
10992 | case bp_hardware_watchpoint: | |
10993 | case bp_read_watchpoint: | |
10994 | case bp_access_watchpoint: | |
10995 | disable_breakpoint (bpt); | |
488919c4 | 10996 | break; |
c5aa993b | 10997 | default: |
488919c4 | 10998 | break; |
c5aa993b | 10999 | } |
0d381245 VP |
11000 | else if (strchr (args, '.')) |
11001 | { | |
11002 | struct bp_location *loc = find_location_by_number (args); | |
11003 | if (loc) | |
11004 | loc->enabled = 0; | |
b60e7edf | 11005 | update_global_location_list (0); |
0d381245 | 11006 | } |
c906108c | 11007 | else |
95a42b64 | 11008 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
11009 | } |
11010 | ||
11011 | static void | |
fba45db2 | 11012 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 11013 | { |
afe38095 | 11014 | int target_resources_ok; |
c906108c SS |
11015 | |
11016 | if (bpt->type == bp_hardware_breakpoint) | |
11017 | { | |
11018 | int i; | |
c5aa993b | 11019 | i = hw_breakpoint_used_count (); |
53a5351d | 11020 | target_resources_ok = |
d92524f1 | 11021 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 11022 | i + 1, 0); |
c906108c | 11023 | if (target_resources_ok == 0) |
8a3fe4f8 | 11024 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 11025 | else if (target_resources_ok < 0) |
8a3fe4f8 | 11026 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
11027 | } |
11028 | ||
cc60f2e3 | 11029 | if (is_watchpoint (bpt)) |
c906108c | 11030 | { |
dde02812 ES |
11031 | struct gdb_exception e; |
11032 | ||
11033 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 11034 | { |
dde02812 | 11035 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 11036 | } |
dde02812 | 11037 | if (e.reason < 0) |
c5aa993b | 11038 | { |
dde02812 ES |
11039 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
11040 | bpt->number); | |
11041 | return; | |
c5aa993b | 11042 | } |
c906108c | 11043 | } |
0101ce28 | 11044 | |
b4c291bb KH |
11045 | if (bpt->enable_state != bp_permanent) |
11046 | bpt->enable_state = bp_enabled; | |
11047 | bpt->disposition = disposition; | |
b60e7edf | 11048 | update_global_location_list (1); |
b4c291bb KH |
11049 | breakpoints_changed (); |
11050 | ||
383f836e | 11051 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
11052 | } |
11053 | ||
fe3f5fa8 | 11054 | |
c906108c | 11055 | void |
fba45db2 | 11056 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
11057 | { |
11058 | do_enable_breakpoint (bpt, bpt->disposition); | |
11059 | } | |
11060 | ||
95a42b64 TT |
11061 | /* A callback for map_breakpoint_numbers that calls |
11062 | enable_breakpoint. */ | |
11063 | ||
11064 | static void | |
11065 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
11066 | { | |
11067 | enable_breakpoint (b); | |
11068 | } | |
11069 | ||
c906108c SS |
11070 | /* The enable command enables the specified breakpoints (or all defined |
11071 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 11072 | in stopping the inferior. */ |
c906108c | 11073 | |
c906108c | 11074 | static void |
fba45db2 | 11075 | enable_command (char *args, int from_tty) |
c906108c | 11076 | { |
52f0bd74 | 11077 | struct breakpoint *bpt; |
cc59ec59 | 11078 | |
c906108c SS |
11079 | if (args == 0) |
11080 | ALL_BREAKPOINTS (bpt) | |
11081 | switch (bpt->type) | |
c5aa993b JM |
11082 | { |
11083 | case bp_none: | |
8a3fe4f8 | 11084 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 11085 | bpt->number); |
488919c4 | 11086 | break; |
c5aa993b | 11087 | case bp_breakpoint: |
1042e4c0 | 11088 | case bp_tracepoint: |
7a697b8d | 11089 | case bp_fast_tracepoint: |
0fb4aa4b | 11090 | case bp_static_tracepoint: |
ce78b96d | 11091 | case bp_catchpoint: |
c5aa993b JM |
11092 | case bp_hardware_breakpoint: |
11093 | case bp_watchpoint: | |
11094 | case bp_hardware_watchpoint: | |
11095 | case bp_read_watchpoint: | |
11096 | case bp_access_watchpoint: | |
11097 | enable_breakpoint (bpt); | |
488919c4 | 11098 | break; |
c5aa993b | 11099 | default: |
488919c4 | 11100 | break; |
c5aa993b | 11101 | } |
0d381245 VP |
11102 | else if (strchr (args, '.')) |
11103 | { | |
11104 | struct bp_location *loc = find_location_by_number (args); | |
11105 | if (loc) | |
11106 | loc->enabled = 1; | |
b60e7edf | 11107 | update_global_location_list (1); |
0d381245 | 11108 | } |
c906108c | 11109 | else |
95a42b64 | 11110 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
11111 | } |
11112 | ||
11113 | static void | |
95a42b64 | 11114 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11115 | { |
b5de0fa7 | 11116 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
11117 | } |
11118 | ||
c906108c | 11119 | static void |
fba45db2 | 11120 | enable_once_command (char *args, int from_tty) |
c906108c | 11121 | { |
95a42b64 | 11122 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
11123 | } |
11124 | ||
11125 | static void | |
95a42b64 | 11126 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11127 | { |
b5de0fa7 | 11128 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
11129 | } |
11130 | ||
c906108c | 11131 | static void |
fba45db2 | 11132 | enable_delete_command (char *args, int from_tty) |
c906108c | 11133 | { |
95a42b64 | 11134 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
11135 | } |
11136 | \f | |
fa8d40ab JJ |
11137 | static void |
11138 | set_breakpoint_cmd (char *args, int from_tty) | |
11139 | { | |
11140 | } | |
11141 | ||
11142 | static void | |
11143 | show_breakpoint_cmd (char *args, int from_tty) | |
11144 | { | |
11145 | } | |
11146 | ||
1f3b5d1b PP |
11147 | /* Invalidate last known value of any hardware watchpoint if |
11148 | the memory which that value represents has been written to by | |
11149 | GDB itself. */ | |
11150 | ||
11151 | static void | |
11152 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
11153 | const bfd_byte *data) | |
11154 | { | |
11155 | struct breakpoint *bp; | |
11156 | ||
11157 | ALL_BREAKPOINTS (bp) | |
11158 | if (bp->enable_state == bp_enabled | |
11159 | && bp->type == bp_hardware_watchpoint | |
11160 | && bp->val_valid && bp->val) | |
11161 | { | |
11162 | struct bp_location *loc; | |
11163 | ||
11164 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
11165 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
11166 | && loc->address + loc->length > addr | |
11167 | && addr + len > loc->address) | |
11168 | { | |
11169 | value_free (bp->val); | |
11170 | bp->val = NULL; | |
11171 | bp->val_valid = 0; | |
11172 | } | |
11173 | } | |
11174 | } | |
11175 | ||
c906108c SS |
11176 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
11177 | ||
11178 | struct symtabs_and_lines | |
fba45db2 | 11179 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
11180 | { |
11181 | struct symtabs_and_lines sals; | |
cc59ec59 | 11182 | |
c906108c | 11183 | if (string == 0) |
8a3fe4f8 | 11184 | error (_("Empty line specification.")); |
c906108c SS |
11185 | if (default_breakpoint_valid) |
11186 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
11187 | default_breakpoint_symtab, |
11188 | default_breakpoint_line, | |
7efd8fc2 | 11189 | NULL, NULL); |
c906108c SS |
11190 | else |
11191 | sals = decode_line_1 (&string, funfirstline, | |
7efd8fc2 | 11192 | (struct symtab *) NULL, 0, NULL, NULL); |
c906108c | 11193 | if (*string) |
8a3fe4f8 | 11194 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
11195 | return sals; |
11196 | } | |
8181d85f DJ |
11197 | |
11198 | /* Create and insert a raw software breakpoint at PC. Return an | |
11199 | identifier, which should be used to remove the breakpoint later. | |
11200 | In general, places which call this should be using something on the | |
11201 | breakpoint chain instead; this function should be eliminated | |
11202 | someday. */ | |
11203 | ||
11204 | void * | |
6c95b8df PA |
11205 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
11206 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
11207 | { |
11208 | struct bp_target_info *bp_tgt; | |
11209 | ||
6c95b8df | 11210 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 11211 | |
6c95b8df | 11212 | bp_tgt->placed_address_space = aspace; |
8181d85f | 11213 | bp_tgt->placed_address = pc; |
6c95b8df | 11214 | |
a6d9a66e | 11215 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
11216 | { |
11217 | /* Could not insert the breakpoint. */ | |
11218 | xfree (bp_tgt); | |
11219 | return NULL; | |
11220 | } | |
11221 | ||
11222 | return bp_tgt; | |
11223 | } | |
11224 | ||
4a64f543 MS |
11225 | /* Remove a breakpoint BP inserted by |
11226 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
11227 | |
11228 | int | |
a6d9a66e | 11229 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
11230 | { |
11231 | struct bp_target_info *bp_tgt = bp; | |
11232 | int ret; | |
11233 | ||
a6d9a66e | 11234 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
11235 | xfree (bp_tgt); |
11236 | ||
11237 | return ret; | |
11238 | } | |
11239 | ||
4a64f543 MS |
11240 | /* One (or perhaps two) breakpoints used for software single |
11241 | stepping. */ | |
8181d85f DJ |
11242 | |
11243 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 11244 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
11245 | |
11246 | /* Create and insert a breakpoint for software single step. */ | |
11247 | ||
11248 | void | |
6c95b8df | 11249 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
11250 | struct address_space *aspace, |
11251 | CORE_ADDR next_pc) | |
8181d85f DJ |
11252 | { |
11253 | void **bpt_p; | |
11254 | ||
11255 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
11256 | { |
11257 | bpt_p = &single_step_breakpoints[0]; | |
11258 | single_step_gdbarch[0] = gdbarch; | |
11259 | } | |
8181d85f DJ |
11260 | else |
11261 | { | |
11262 | gdb_assert (single_step_breakpoints[1] == NULL); | |
11263 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 11264 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
11265 | } |
11266 | ||
4a64f543 MS |
11267 | /* NOTE drow/2006-04-11: A future improvement to this function would |
11268 | be to only create the breakpoints once, and actually put them on | |
11269 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
11270 | We could adjust the addresses each time they were needed. Doing | |
11271 | this requires corresponding changes elsewhere where single step | |
11272 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 11273 | |
6c95b8df | 11274 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 11275 | if (*bpt_p == NULL) |
5af949e3 UW |
11276 | error (_("Could not insert single-step breakpoint at %s"), |
11277 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
11278 | } |
11279 | ||
f02253f1 HZ |
11280 | /* Check if the breakpoints used for software single stepping |
11281 | were inserted or not. */ | |
11282 | ||
11283 | int | |
11284 | single_step_breakpoints_inserted (void) | |
11285 | { | |
11286 | return (single_step_breakpoints[0] != NULL | |
11287 | || single_step_breakpoints[1] != NULL); | |
11288 | } | |
11289 | ||
8181d85f DJ |
11290 | /* Remove and delete any breakpoints used for software single step. */ |
11291 | ||
11292 | void | |
11293 | remove_single_step_breakpoints (void) | |
11294 | { | |
11295 | gdb_assert (single_step_breakpoints[0] != NULL); | |
11296 | ||
11297 | /* See insert_single_step_breakpoint for more about this deprecated | |
11298 | call. */ | |
a6d9a66e UW |
11299 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
11300 | single_step_breakpoints[0]); | |
11301 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
11302 | single_step_breakpoints[0] = NULL; |
11303 | ||
11304 | if (single_step_breakpoints[1] != NULL) | |
11305 | { | |
a6d9a66e UW |
11306 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
11307 | single_step_breakpoints[1]); | |
11308 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
11309 | single_step_breakpoints[1] = NULL; |
11310 | } | |
11311 | } | |
11312 | ||
d03285ec UW |
11313 | /* Delete software single step breakpoints without removing them from |
11314 | the inferior. This is intended to be used if the inferior's address | |
11315 | space where they were inserted is already gone, e.g. after exit or | |
11316 | exec. */ | |
11317 | ||
11318 | void | |
11319 | cancel_single_step_breakpoints (void) | |
11320 | { | |
11321 | int i; | |
11322 | ||
11323 | for (i = 0; i < 2; i++) | |
11324 | if (single_step_breakpoints[i]) | |
11325 | { | |
11326 | xfree (single_step_breakpoints[i]); | |
11327 | single_step_breakpoints[i] = NULL; | |
11328 | single_step_gdbarch[i] = NULL; | |
11329 | } | |
11330 | } | |
11331 | ||
11332 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
11333 | removing them. */ | |
11334 | ||
11335 | static void | |
11336 | detach_single_step_breakpoints (void) | |
11337 | { | |
11338 | int i; | |
11339 | ||
11340 | for (i = 0; i < 2; i++) | |
11341 | if (single_step_breakpoints[i]) | |
11342 | target_remove_breakpoint (single_step_gdbarch[i], | |
11343 | single_step_breakpoints[i]); | |
11344 | } | |
11345 | ||
4a64f543 MS |
11346 | /* Check whether a software single-step breakpoint is inserted at |
11347 | PC. */ | |
1aafd4da UW |
11348 | |
11349 | static int | |
cc59ec59 MS |
11350 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
11351 | CORE_ADDR pc) | |
1aafd4da UW |
11352 | { |
11353 | int i; | |
11354 | ||
11355 | for (i = 0; i < 2; i++) | |
11356 | { | |
11357 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
11358 | if (bp_tgt |
11359 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
11360 | bp_tgt->placed_address, | |
11361 | aspace, pc)) | |
1aafd4da UW |
11362 | return 1; |
11363 | } | |
11364 | ||
11365 | return 0; | |
11366 | } | |
11367 | ||
a96d9b2e SDJ |
11368 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
11369 | non-zero otherwise. */ | |
11370 | static int | |
11371 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
11372 | { | |
11373 | if (syscall_catchpoint_p (bp) | |
11374 | && bp->enable_state != bp_disabled | |
11375 | && bp->enable_state != bp_call_disabled) | |
11376 | return 1; | |
11377 | else | |
11378 | return 0; | |
11379 | } | |
11380 | ||
11381 | int | |
11382 | catch_syscall_enabled (void) | |
11383 | { | |
11384 | struct inferior *inf = current_inferior (); | |
11385 | ||
11386 | return inf->total_syscalls_count != 0; | |
11387 | } | |
11388 | ||
11389 | int | |
11390 | catching_syscall_number (int syscall_number) | |
11391 | { | |
11392 | struct breakpoint *bp; | |
11393 | ||
11394 | ALL_BREAKPOINTS (bp) | |
11395 | if (is_syscall_catchpoint_enabled (bp)) | |
11396 | { | |
11397 | if (bp->syscalls_to_be_caught) | |
11398 | { | |
11399 | int i, iter; | |
11400 | for (i = 0; | |
11401 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
11402 | i++) | |
11403 | if (syscall_number == iter) | |
11404 | return 1; | |
11405 | } | |
11406 | else | |
11407 | return 1; | |
11408 | } | |
11409 | ||
11410 | return 0; | |
11411 | } | |
11412 | ||
11413 | /* Complete syscall names. Used by "catch syscall". */ | |
11414 | static char ** | |
11415 | catch_syscall_completer (struct cmd_list_element *cmd, | |
11416 | char *text, char *word) | |
11417 | { | |
11418 | const char **list = get_syscall_names (); | |
c38eea1a MS |
11419 | char **retlist |
11420 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 11421 | |
c38eea1a MS |
11422 | xfree (list); |
11423 | return retlist; | |
a96d9b2e SDJ |
11424 | } |
11425 | ||
1042e4c0 SS |
11426 | /* Tracepoint-specific operations. */ |
11427 | ||
11428 | /* Set tracepoint count to NUM. */ | |
11429 | static void | |
11430 | set_tracepoint_count (int num) | |
11431 | { | |
11432 | tracepoint_count = num; | |
4fa62494 | 11433 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
11434 | } |
11435 | ||
11436 | void | |
11437 | trace_command (char *arg, int from_tty) | |
11438 | { | |
8cdf0e15 VP |
11439 | if (create_breakpoint (get_current_arch (), |
11440 | arg, | |
11441 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11442 | 0 /* tempflag */, |
11443 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11444 | 0 /* Ignore count */, |
11445 | pending_break_support, | |
11446 | NULL, | |
11447 | from_tty, | |
84f4c1fe PM |
11448 | 1 /* enabled */, |
11449 | 0 /* internal */)) | |
fd9b8c24 | 11450 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
11451 | } |
11452 | ||
7a697b8d SS |
11453 | void |
11454 | ftrace_command (char *arg, int from_tty) | |
11455 | { | |
8cdf0e15 VP |
11456 | if (create_breakpoint (get_current_arch (), |
11457 | arg, | |
11458 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11459 | 0 /* tempflag */, |
11460 | bp_fast_tracepoint /* type_wanted */, | |
11461 | 0 /* Ignore count */, | |
11462 | pending_break_support, | |
11463 | NULL, | |
11464 | from_tty, | |
84f4c1fe PM |
11465 | 1 /* enabled */, |
11466 | 0 /* internal */)) | |
0fb4aa4b PA |
11467 | set_tracepoint_count (breakpoint_count); |
11468 | } | |
11469 | ||
11470 | /* strace command implementation. Creates a static tracepoint. */ | |
11471 | ||
11472 | void | |
11473 | strace_command (char *arg, int from_tty) | |
11474 | { | |
11475 | if (create_breakpoint (get_current_arch (), | |
11476 | arg, | |
11477 | NULL, 0, 1 /* parse arg */, | |
11478 | 0 /* tempflag */, | |
11479 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11480 | 0 /* Ignore count */, |
11481 | pending_break_support, | |
11482 | NULL, | |
11483 | from_tty, | |
84f4c1fe PM |
11484 | 1 /* enabled */, |
11485 | 0 /* internal */)) | |
fd9b8c24 | 11486 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
11487 | } |
11488 | ||
409873ef SS |
11489 | /* Set up a fake reader function that gets command lines from a linked |
11490 | list that was acquired during tracepoint uploading. */ | |
11491 | ||
11492 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 11493 | static int next_cmd; |
409873ef SS |
11494 | |
11495 | static char * | |
11496 | read_uploaded_action (void) | |
11497 | { | |
11498 | char *rslt; | |
11499 | ||
3149d8c1 | 11500 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 11501 | |
3149d8c1 | 11502 | next_cmd++; |
409873ef SS |
11503 | |
11504 | return rslt; | |
11505 | } | |
11506 | ||
00bf0b85 SS |
11507 | /* Given information about a tracepoint as recorded on a target (which |
11508 | can be either a live system or a trace file), attempt to create an | |
11509 | equivalent GDB tracepoint. This is not a reliable process, since | |
11510 | the target does not necessarily have all the information used when | |
11511 | the tracepoint was originally defined. */ | |
11512 | ||
11513 | struct breakpoint * | |
11514 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 11515 | { |
409873ef | 11516 | char *addr_str, small_buf[100]; |
d5551862 | 11517 | struct breakpoint *tp; |
fd9b8c24 | 11518 | |
409873ef SS |
11519 | if (utp->at_string) |
11520 | addr_str = utp->at_string; | |
11521 | else | |
11522 | { | |
11523 | /* In the absence of a source location, fall back to raw | |
11524 | address. Since there is no way to confirm that the address | |
11525 | means the same thing as when the trace was started, warn the | |
11526 | user. */ | |
3e43a32a MS |
11527 | warning (_("Uploaded tracepoint %d has no " |
11528 | "source location, using raw address"), | |
409873ef SS |
11529 | utp->number); |
11530 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
11531 | addr_str = small_buf; | |
11532 | } | |
11533 | ||
11534 | /* There's not much we can do with a sequence of bytecodes. */ | |
11535 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
11536 | warning (_("Uploaded tracepoint %d condition " |
11537 | "has no source form, ignoring it"), | |
409873ef | 11538 | utp->number); |
d5551862 | 11539 | |
8cdf0e15 | 11540 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
11541 | addr_str, |
11542 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 11543 | 0 /* tempflag */, |
0fb4aa4b | 11544 | utp->type /* type_wanted */, |
8cdf0e15 VP |
11545 | 0 /* Ignore count */, |
11546 | pending_break_support, | |
11547 | NULL, | |
11548 | 0 /* from_tty */, | |
84f4c1fe PM |
11549 | utp->enabled /* enabled */, |
11550 | 0 /* internal */)) | |
fd9b8c24 PA |
11551 | return NULL; |
11552 | ||
00bf0b85 SS |
11553 | set_tracepoint_count (breakpoint_count); |
11554 | ||
409873ef | 11555 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
11556 | tp = get_tracepoint (tracepoint_count); |
11557 | gdb_assert (tp != NULL); | |
d5551862 | 11558 | |
00bf0b85 SS |
11559 | if (utp->pass > 0) |
11560 | { | |
409873ef | 11561 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 11562 | |
409873ef | 11563 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
11564 | } |
11565 | ||
409873ef SS |
11566 | /* If we have uploaded versions of the original commands, set up a |
11567 | special-purpose "reader" function and call the usual command line | |
11568 | reader, then pass the result to the breakpoint command-setting | |
11569 | function. */ | |
3149d8c1 | 11570 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 11571 | { |
409873ef | 11572 | struct command_line *cmd_list; |
00bf0b85 | 11573 | |
409873ef | 11574 | this_utp = utp; |
3149d8c1 | 11575 | next_cmd = 0; |
d5551862 | 11576 | |
409873ef SS |
11577 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
11578 | ||
11579 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 11580 | } |
3149d8c1 SS |
11581 | else if (!VEC_empty (char_ptr, utp->actions) |
11582 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
11583 | warning (_("Uploaded tracepoint %d actions " |
11584 | "have no source form, ignoring them"), | |
409873ef | 11585 | utp->number); |
00bf0b85 SS |
11586 | |
11587 | return tp; | |
11588 | } | |
11589 | ||
1042e4c0 SS |
11590 | /* Print information on tracepoint number TPNUM_EXP, or all if |
11591 | omitted. */ | |
11592 | ||
11593 | static void | |
e5a67952 | 11594 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 11595 | { |
e5a67952 | 11596 | int num_printed; |
1042e4c0 | 11597 | |
e5a67952 | 11598 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
11599 | |
11600 | if (num_printed == 0) | |
1042e4c0 | 11601 | { |
e5a67952 | 11602 | if (args == NULL || *args == '\0') |
d77f58be SS |
11603 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
11604 | else | |
e5a67952 | 11605 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 11606 | } |
ad443146 SS |
11607 | |
11608 | default_collect_info (); | |
1042e4c0 SS |
11609 | } |
11610 | ||
4a64f543 | 11611 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
11612 | Not supported by all targets. */ |
11613 | static void | |
11614 | enable_trace_command (char *args, int from_tty) | |
11615 | { | |
11616 | enable_command (args, from_tty); | |
11617 | } | |
11618 | ||
4a64f543 | 11619 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
11620 | Not supported by all targets. */ |
11621 | static void | |
11622 | disable_trace_command (char *args, int from_tty) | |
11623 | { | |
11624 | disable_command (args, from_tty); | |
11625 | } | |
11626 | ||
4a64f543 | 11627 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
11628 | static void |
11629 | delete_trace_command (char *arg, int from_tty) | |
11630 | { | |
35df4500 | 11631 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
11632 | |
11633 | dont_repeat (); | |
11634 | ||
11635 | if (arg == 0) | |
11636 | { | |
11637 | int breaks_to_delete = 0; | |
11638 | ||
11639 | /* Delete all breakpoints if no argument. | |
11640 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
11641 | have to be deleted with an explicit breakpoint number |
11642 | argument. */ | |
1042e4c0 SS |
11643 | ALL_TRACEPOINTS (b) |
11644 | { | |
11645 | if (b->number >= 0) | |
11646 | { | |
11647 | breaks_to_delete = 1; | |
11648 | break; | |
11649 | } | |
11650 | } | |
11651 | ||
11652 | /* Ask user only if there are some breakpoints to delete. */ | |
11653 | if (!from_tty | |
11654 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
11655 | { | |
35df4500 | 11656 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
1042e4c0 | 11657 | { |
d77f58be | 11658 | if (is_tracepoint (b) |
059fb39f | 11659 | && b->number >= 0) |
1042e4c0 SS |
11660 | delete_breakpoint (b); |
11661 | } | |
11662 | } | |
11663 | } | |
11664 | else | |
95a42b64 | 11665 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
11666 | } |
11667 | ||
197f0a60 TT |
11668 | /* Helper function for trace_pass_command. */ |
11669 | ||
11670 | static void | |
11671 | trace_pass_set_count (struct breakpoint *bp, int count, int from_tty) | |
11672 | { | |
11673 | bp->pass_count = count; | |
11674 | observer_notify_tracepoint_modified (bp->number); | |
11675 | if (from_tty) | |
11676 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
11677 | bp->number, count); | |
11678 | } | |
11679 | ||
1042e4c0 SS |
11680 | /* Set passcount for tracepoint. |
11681 | ||
11682 | First command argument is passcount, second is tracepoint number. | |
11683 | If tracepoint number omitted, apply to most recently defined. | |
11684 | Also accepts special argument "all". */ | |
11685 | ||
11686 | static void | |
11687 | trace_pass_command (char *args, int from_tty) | |
11688 | { | |
197f0a60 | 11689 | struct breakpoint *t1; |
1042e4c0 | 11690 | unsigned int count; |
1042e4c0 SS |
11691 | |
11692 | if (args == 0 || *args == 0) | |
3e43a32a MS |
11693 | error (_("passcount command requires an " |
11694 | "argument (count + optional TP num)")); | |
1042e4c0 | 11695 | |
4a64f543 | 11696 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
11697 | |
11698 | while (*args && isspace ((int) *args)) | |
11699 | args++; | |
11700 | ||
11701 | if (*args && strncasecmp (args, "all", 3) == 0) | |
11702 | { | |
11703 | args += 3; /* Skip special argument "all". */ | |
1042e4c0 SS |
11704 | if (*args) |
11705 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 11706 | |
197f0a60 TT |
11707 | ALL_TRACEPOINTS (t1) |
11708 | { | |
11709 | trace_pass_set_count (t1, count, from_tty); | |
11710 | } | |
11711 | } | |
11712 | else if (*args == '\0') | |
1042e4c0 | 11713 | { |
197f0a60 | 11714 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 11715 | if (t1) |
197f0a60 TT |
11716 | trace_pass_set_count (t1, count, from_tty); |
11717 | } | |
11718 | else | |
11719 | { | |
11720 | struct get_number_or_range_state state; | |
11721 | ||
11722 | init_number_or_range (&state, args); | |
11723 | while (!state.finished) | |
1042e4c0 | 11724 | { |
197f0a60 TT |
11725 | t1 = get_tracepoint_by_number (&args, &state, 1); |
11726 | if (t1) | |
11727 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
11728 | } |
11729 | } | |
1042e4c0 SS |
11730 | } |
11731 | ||
11732 | struct breakpoint * | |
11733 | get_tracepoint (int num) | |
11734 | { | |
11735 | struct breakpoint *t; | |
11736 | ||
11737 | ALL_TRACEPOINTS (t) | |
11738 | if (t->number == num) | |
11739 | return t; | |
11740 | ||
11741 | return NULL; | |
11742 | } | |
11743 | ||
d5551862 SS |
11744 | /* Find the tracepoint with the given target-side number (which may be |
11745 | different from the tracepoint number after disconnecting and | |
11746 | reconnecting). */ | |
11747 | ||
11748 | struct breakpoint * | |
11749 | get_tracepoint_by_number_on_target (int num) | |
11750 | { | |
11751 | struct breakpoint *t; | |
11752 | ||
11753 | ALL_TRACEPOINTS (t) | |
11754 | if (t->number_on_target == num) | |
11755 | return t; | |
11756 | ||
11757 | return NULL; | |
11758 | } | |
11759 | ||
1042e4c0 | 11760 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
11761 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
11762 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 SS |
11763 | recent tracepoint (tracepoint_count) is returned. */ |
11764 | struct breakpoint * | |
197f0a60 TT |
11765 | get_tracepoint_by_number (char **arg, |
11766 | struct get_number_or_range_state *state, | |
11767 | int optional_p) | |
1042e4c0 SS |
11768 | { |
11769 | extern int tracepoint_count; | |
11770 | struct breakpoint *t; | |
11771 | int tpnum; | |
11772 | char *instring = arg == NULL ? NULL : *arg; | |
11773 | ||
197f0a60 TT |
11774 | if (state) |
11775 | { | |
11776 | gdb_assert (!state->finished); | |
11777 | tpnum = get_number_or_range (state); | |
11778 | } | |
11779 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
11780 | { |
11781 | if (optional_p) | |
11782 | tpnum = tracepoint_count; | |
11783 | else | |
11784 | error_no_arg (_("tracepoint number")); | |
11785 | } | |
11786 | else | |
197f0a60 | 11787 | tpnum = get_number (arg); |
1042e4c0 SS |
11788 | |
11789 | if (tpnum <= 0) | |
11790 | { | |
11791 | if (instring && *instring) | |
11792 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
11793 | instring); | |
11794 | else | |
3e43a32a MS |
11795 | printf_filtered (_("Tracepoint argument missing " |
11796 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
11797 | return NULL; |
11798 | } | |
11799 | ||
11800 | ALL_TRACEPOINTS (t) | |
11801 | if (t->number == tpnum) | |
11802 | { | |
11803 | return t; | |
11804 | } | |
11805 | ||
1042e4c0 SS |
11806 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
11807 | return NULL; | |
11808 | } | |
11809 | ||
6149aea9 PA |
11810 | /* Save information on user settable breakpoints (watchpoints, etc) to |
11811 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
11812 | on each breakpoint and only include the ones for which it returns | |
11813 | non-zero. */ | |
11814 | ||
1042e4c0 | 11815 | static void |
6149aea9 PA |
11816 | save_breakpoints (char *filename, int from_tty, |
11817 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
11818 | { |
11819 | struct breakpoint *tp; | |
6149aea9 | 11820 | int any = 0; |
a7bdde9e | 11821 | char *pathname; |
1042e4c0 | 11822 | struct cleanup *cleanup; |
a7bdde9e | 11823 | struct ui_file *fp; |
6149aea9 | 11824 | int extra_trace_bits = 0; |
1042e4c0 | 11825 | |
6149aea9 PA |
11826 | if (filename == 0 || *filename == 0) |
11827 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
11828 | |
11829 | /* See if we have anything to save. */ | |
6149aea9 | 11830 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11831 | { |
6149aea9 | 11832 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11833 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
11834 | continue; |
11835 | ||
11836 | /* If we have a filter, only save the breakpoints it accepts. */ | |
11837 | if (filter && !filter (tp)) | |
11838 | continue; | |
11839 | ||
11840 | any = 1; | |
11841 | ||
11842 | if (is_tracepoint (tp)) | |
11843 | { | |
11844 | extra_trace_bits = 1; | |
11845 | ||
11846 | /* We can stop searching. */ | |
11847 | break; | |
11848 | } | |
1042e4c0 | 11849 | } |
6149aea9 PA |
11850 | |
11851 | if (!any) | |
1042e4c0 | 11852 | { |
6149aea9 | 11853 | warning (_("Nothing to save.")); |
1042e4c0 SS |
11854 | return; |
11855 | } | |
11856 | ||
6149aea9 | 11857 | pathname = tilde_expand (filename); |
1042e4c0 | 11858 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 11859 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 11860 | if (!fp) |
6149aea9 PA |
11861 | error (_("Unable to open file '%s' for saving (%s)"), |
11862 | filename, safe_strerror (errno)); | |
a7bdde9e | 11863 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 11864 | |
6149aea9 PA |
11865 | if (extra_trace_bits) |
11866 | save_trace_state_variables (fp); | |
8bf6485c | 11867 | |
6149aea9 | 11868 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11869 | { |
6149aea9 | 11870 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11871 | if (!user_breakpoint_p (tp)) |
6149aea9 | 11872 | continue; |
8bf6485c | 11873 | |
6149aea9 PA |
11874 | /* If we have a filter, only save the breakpoints it accepts. */ |
11875 | if (filter && !filter (tp)) | |
11876 | continue; | |
11877 | ||
11878 | if (tp->ops != NULL) | |
11879 | (tp->ops->print_recreate) (tp, fp); | |
1042e4c0 SS |
11880 | else |
11881 | { | |
6149aea9 PA |
11882 | if (tp->type == bp_fast_tracepoint) |
11883 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
11884 | if (tp->type == bp_static_tracepoint) |
11885 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
11886 | else if (tp->type == bp_tracepoint) |
11887 | fprintf_unfiltered (fp, "trace"); | |
11888 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11889 | fprintf_unfiltered (fp, "tbreak"); | |
11890 | else if (tp->type == bp_breakpoint) | |
11891 | fprintf_unfiltered (fp, "break"); | |
11892 | else if (tp->type == bp_hardware_breakpoint | |
11893 | && tp->disposition == disp_del) | |
11894 | fprintf_unfiltered (fp, "thbreak"); | |
11895 | else if (tp->type == bp_hardware_breakpoint) | |
11896 | fprintf_unfiltered (fp, "hbreak"); | |
11897 | else if (tp->type == bp_watchpoint) | |
11898 | fprintf_unfiltered (fp, "watch"); | |
11899 | else if (tp->type == bp_hardware_watchpoint) | |
11900 | fprintf_unfiltered (fp, "watch"); | |
11901 | else if (tp->type == bp_read_watchpoint) | |
11902 | fprintf_unfiltered (fp, "rwatch"); | |
11903 | else if (tp->type == bp_access_watchpoint) | |
11904 | fprintf_unfiltered (fp, "awatch"); | |
11905 | else | |
11906 | internal_error (__FILE__, __LINE__, | |
11907 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11908 | ||
11909 | if (tp->exp_string) | |
11910 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
11911 | else if (tp->addr_string) | |
11912 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
11913 | else | |
11914 | { | |
11915 | char tmp[40]; | |
11916 | ||
11917 | sprintf_vma (tmp, tp->loc->address); | |
11918 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
11919 | } | |
1042e4c0 SS |
11920 | } |
11921 | ||
6149aea9 PA |
11922 | if (tp->thread != -1) |
11923 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
11924 | ||
11925 | if (tp->task != 0) | |
11926 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
11927 | |
11928 | fprintf_unfiltered (fp, "\n"); | |
11929 | ||
6149aea9 PA |
11930 | /* Note, we can't rely on tp->number for anything, as we can't |
11931 | assume the recreated breakpoint numbers will match. Use $bpnum | |
11932 | instead. */ | |
11933 | ||
11934 | if (tp->cond_string) | |
11935 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
11936 | ||
11937 | if (tp->ignore_count) | |
11938 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
11939 | ||
1042e4c0 | 11940 | if (tp->pass_count) |
a7bdde9e | 11941 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 11942 | |
a7bdde9e | 11943 | if (tp->commands) |
1042e4c0 | 11944 | { |
a7bdde9e VP |
11945 | volatile struct gdb_exception ex; |
11946 | ||
6149aea9 | 11947 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
11948 | |
11949 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 11950 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 11951 | { |
9add0f1b | 11952 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
11953 | } |
11954 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 11955 | |
a7bdde9e VP |
11956 | if (ex.reason < 0) |
11957 | throw_exception (ex); | |
1042e4c0 | 11958 | |
a7bdde9e | 11959 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 11960 | } |
6149aea9 PA |
11961 | |
11962 | if (tp->enable_state == bp_disabled) | |
11963 | fprintf_unfiltered (fp, "disable\n"); | |
11964 | ||
11965 | /* If this is a multi-location breakpoint, check if the locations | |
11966 | should be individually disabled. Watchpoint locations are | |
11967 | special, and not user visible. */ | |
11968 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
11969 | { | |
11970 | struct bp_location *loc; | |
11971 | int n = 1; | |
11972 | ||
11973 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
11974 | if (!loc->enabled) | |
11975 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
11976 | } | |
1042e4c0 | 11977 | } |
8bf6485c | 11978 | |
6149aea9 | 11979 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
11980 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
11981 | ||
1042e4c0 SS |
11982 | do_cleanups (cleanup); |
11983 | if (from_tty) | |
6149aea9 PA |
11984 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
11985 | } | |
11986 | ||
11987 | /* The `save breakpoints' command. */ | |
11988 | ||
11989 | static void | |
11990 | save_breakpoints_command (char *args, int from_tty) | |
11991 | { | |
11992 | save_breakpoints (args, from_tty, NULL); | |
11993 | } | |
11994 | ||
11995 | /* The `save tracepoints' command. */ | |
11996 | ||
11997 | static void | |
11998 | save_tracepoints_command (char *args, int from_tty) | |
11999 | { | |
12000 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
12001 | } |
12002 | ||
12003 | /* Create a vector of all tracepoints. */ | |
12004 | ||
12005 | VEC(breakpoint_p) * | |
eeae04df | 12006 | all_tracepoints (void) |
1042e4c0 SS |
12007 | { |
12008 | VEC(breakpoint_p) *tp_vec = 0; | |
12009 | struct breakpoint *tp; | |
12010 | ||
12011 | ALL_TRACEPOINTS (tp) | |
12012 | { | |
12013 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
12014 | } | |
12015 | ||
12016 | return tp_vec; | |
12017 | } | |
12018 | ||
c906108c | 12019 | \f |
4a64f543 MS |
12020 | /* This help string is used for the break, hbreak, tbreak and thbreak |
12021 | commands. It is defined as a macro to prevent duplication. | |
12022 | COMMAND should be a string constant containing the name of the | |
12023 | command. */ | |
31e2b00f AS |
12024 | #define BREAK_ARGS_HELP(command) \ |
12025 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
12026 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
12027 | If a line number is specified, break at start of code for that line.\n\ | |
12028 | If a function is specified, break at start of code for that function.\n\ | |
12029 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
12030 | With no LOCATION, uses current execution address of the selected\n\ |
12031 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
12032 | \n\ |
12033 | THREADNUM is the number from \"info threads\".\n\ | |
12034 | CONDITION is a boolean expression.\n\ | |
12035 | \n\ | |
d41c0fc8 PA |
12036 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
12037 | conditions are different.\n\ | |
31e2b00f AS |
12038 | \n\ |
12039 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
12040 | ||
44feb3ce TT |
12041 | /* List of subcommands for "catch". */ |
12042 | static struct cmd_list_element *catch_cmdlist; | |
12043 | ||
12044 | /* List of subcommands for "tcatch". */ | |
12045 | static struct cmd_list_element *tcatch_cmdlist; | |
12046 | ||
12047 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
12048 | lists, and pass some additional user data to the command function. */ | |
12049 | static void | |
12050 | add_catch_command (char *name, char *docstring, | |
12051 | void (*sfunc) (char *args, int from_tty, | |
12052 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
12053 | char **(*completer) (struct cmd_list_element *cmd, |
12054 | char *text, char *word), | |
44feb3ce TT |
12055 | void *user_data_catch, |
12056 | void *user_data_tcatch) | |
12057 | { | |
12058 | struct cmd_list_element *command; | |
12059 | ||
12060 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12061 | &catch_cmdlist); | |
12062 | set_cmd_sfunc (command, sfunc); | |
12063 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 12064 | set_cmd_completer (command, completer); |
44feb3ce TT |
12065 | |
12066 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12067 | &tcatch_cmdlist); | |
12068 | set_cmd_sfunc (command, sfunc); | |
12069 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 12070 | set_cmd_completer (command, completer); |
44feb3ce TT |
12071 | } |
12072 | ||
6c95b8df | 12073 | static void |
a79b8f6e | 12074 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 12075 | { |
6c95b8df PA |
12076 | inf->total_syscalls_count = 0; |
12077 | inf->any_syscall_count = 0; | |
12078 | VEC_free (int, inf->syscalls_counts); | |
12079 | } | |
12080 | ||
6149aea9 PA |
12081 | static void |
12082 | save_command (char *arg, int from_tty) | |
12083 | { | |
3e43a32a MS |
12084 | printf_unfiltered (_("\"save\" must be followed by " |
12085 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
12086 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
12087 | } | |
12088 | ||
84f4c1fe PM |
12089 | struct breakpoint * |
12090 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
12091 | void *data) | |
12092 | { | |
35df4500 | 12093 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 12094 | |
35df4500 | 12095 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
12096 | { |
12097 | if ((*callback) (b, data)) | |
12098 | return b; | |
12099 | } | |
12100 | ||
12101 | return NULL; | |
12102 | } | |
12103 | ||
c906108c | 12104 | void |
fba45db2 | 12105 | _initialize_breakpoint (void) |
c906108c SS |
12106 | { |
12107 | struct cmd_list_element *c; | |
12108 | ||
84acb35a | 12109 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 12110 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 12111 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 12112 | |
17450429 PP |
12113 | breakpoint_objfile_key = register_objfile_data (); |
12114 | ||
c906108c SS |
12115 | breakpoint_chain = 0; |
12116 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
12117 | before a breakpoint is set. */ | |
12118 | breakpoint_count = 0; | |
12119 | ||
1042e4c0 SS |
12120 | tracepoint_count = 0; |
12121 | ||
1bedd215 AC |
12122 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
12123 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
12124 | Usage is `ignore N COUNT'.")); | |
c906108c | 12125 | if (xdb_commands) |
c5aa993b | 12126 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 12127 | |
1bedd215 AC |
12128 | add_com ("commands", class_breakpoint, commands_command, _("\ |
12129 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
12130 | Give breakpoint number as argument after \"commands\".\n\ |
12131 | With no argument, the targeted breakpoint is the last one set.\n\ | |
12132 | The commands themselves follow starting on the next line.\n\ | |
12133 | Type a line containing \"end\" to indicate the end of them.\n\ | |
12134 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 12135 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 12136 | |
1bedd215 AC |
12137 | add_com ("condition", class_breakpoint, condition_command, _("\ |
12138 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 12139 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 12140 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 12141 | |
1bedd215 | 12142 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 12143 | Set a temporary breakpoint.\n\ |
c906108c SS |
12144 | Like \"break\" except the breakpoint is only temporary,\n\ |
12145 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
12146 | by using \"enable delete\" on the breakpoint number.\n\ |
12147 | \n" | |
12148 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 12149 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12150 | |
1bedd215 | 12151 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 12152 | Set a hardware assisted breakpoint.\n\ |
c906108c | 12153 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
12154 | some target hardware may not have this support.\n\ |
12155 | \n" | |
12156 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 12157 | set_cmd_completer (c, location_completer); |
c906108c | 12158 | |
1bedd215 | 12159 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 12160 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 12161 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
12162 | so it will be deleted when hit.\n\ |
12163 | \n" | |
12164 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 12165 | set_cmd_completer (c, location_completer); |
c906108c | 12166 | |
1bedd215 AC |
12167 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
12168 | Enable some breakpoints.\n\ | |
c906108c SS |
12169 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12170 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12171 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12172 | With a subcommand you can enable temporarily."), |
c906108c SS |
12173 | &enablelist, "enable ", 1, &cmdlist); |
12174 | if (xdb_commands) | |
1bedd215 AC |
12175 | add_com ("ab", class_breakpoint, enable_command, _("\ |
12176 | Enable some breakpoints.\n\ | |
c906108c SS |
12177 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12178 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12179 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12180 | With a subcommand you can enable temporarily.")); |
c906108c SS |
12181 | |
12182 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
12183 | ||
84951ab5 | 12184 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 12185 | Enable some breakpoints.\n\ |
c906108c SS |
12186 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12187 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12188 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 12189 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 12190 | |
1a966eab AC |
12191 | add_cmd ("once", no_class, enable_once_command, _("\ |
12192 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12193 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12194 | &enablebreaklist); |
12195 | ||
1a966eab AC |
12196 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12197 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12198 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12199 | &enablebreaklist); |
12200 | ||
1a966eab AC |
12201 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12202 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12203 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12204 | &enablelist); |
12205 | ||
1a966eab AC |
12206 | add_cmd ("once", no_class, enable_once_command, _("\ |
12207 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12208 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12209 | &enablelist); |
12210 | ||
1bedd215 AC |
12211 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
12212 | Disable some breakpoints.\n\ | |
c906108c SS |
12213 | Arguments are breakpoint numbers with spaces in between.\n\ |
12214 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12215 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
12216 | &disablelist, "disable ", 1, &cmdlist); |
12217 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
12218 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
12219 | if (xdb_commands) | |
1bedd215 AC |
12220 | add_com ("sb", class_breakpoint, disable_command, _("\ |
12221 | Disable some breakpoints.\n\ | |
c906108c SS |
12222 | Arguments are breakpoint numbers with spaces in between.\n\ |
12223 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12224 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 12225 | |
1a966eab AC |
12226 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
12227 | Disable some breakpoints.\n\ | |
c906108c SS |
12228 | Arguments are breakpoint numbers with spaces in between.\n\ |
12229 | To disable all breakpoints, give no argument.\n\ | |
12230 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 12231 | This command may be abbreviated \"disable\"."), |
c906108c SS |
12232 | &disablelist); |
12233 | ||
1bedd215 AC |
12234 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
12235 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12236 | Arguments are breakpoint numbers with spaces in between.\n\ |
12237 | To delete all breakpoints, give no argument.\n\ | |
12238 | \n\ | |
12239 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 12240 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
12241 | &deletelist, "delete ", 1, &cmdlist); |
12242 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 12243 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 12244 | if (xdb_commands) |
1bedd215 AC |
12245 | add_com ("db", class_breakpoint, delete_command, _("\ |
12246 | Delete some breakpoints.\n\ | |
c906108c | 12247 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 12248 | To delete all breakpoints, give no argument.\n")); |
c906108c | 12249 | |
1a966eab AC |
12250 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
12251 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12252 | Arguments are breakpoint numbers with spaces in between.\n\ |
12253 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 12254 | This command may be abbreviated \"delete\"."), |
c906108c SS |
12255 | &deletelist); |
12256 | ||
1bedd215 AC |
12257 | add_com ("clear", class_breakpoint, clear_command, _("\ |
12258 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
12259 | Argument may be line number, function name, or \"*\" and an address.\n\ |
12260 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
12261 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
12262 | If an address is specified, breakpoints at that address are cleared.\n\ |
12263 | \n\ | |
12264 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
12265 | is executing in.\n\ |
12266 | \n\ | |
1bedd215 | 12267 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 12268 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 12269 | |
1bedd215 | 12270 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
12271 | Set breakpoint at specified line or function.\n" |
12272 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 12273 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12274 | |
c906108c SS |
12275 | add_com_alias ("b", "break", class_run, 1); |
12276 | add_com_alias ("br", "break", class_run, 1); | |
12277 | add_com_alias ("bre", "break", class_run, 1); | |
12278 | add_com_alias ("brea", "break", class_run, 1); | |
12279 | ||
7681d515 PM |
12280 | if (xdb_commands) |
12281 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
12282 | |
12283 | if (dbx_commands) | |
12284 | { | |
1bedd215 AC |
12285 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
12286 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
12287 | &stoplist, "stop ", 1, &cmdlist); |
12288 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 12289 | _("Break in function or address."), &stoplist); |
c5aa993b | 12290 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 12291 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
12292 | add_com ("status", class_info, breakpoints_info, _("\ |
12293 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12294 | The \"Type\" column indicates one of:\n\ |
12295 | \tbreakpoint - normal breakpoint\n\ | |
12296 | \twatchpoint - watchpoint\n\ | |
12297 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12298 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12299 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12300 | address and file/line number respectively.\n\ |
12301 | \n\ | |
12302 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12303 | are set to the address of the last breakpoint listed unless the command\n\ |
12304 | is prefixed with \"server \".\n\n\ | |
c906108c | 12305 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12306 | breakpoint set.")); |
c906108c SS |
12307 | } |
12308 | ||
1bedd215 | 12309 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 12310 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
12311 | The \"Type\" column indicates one of:\n\ |
12312 | \tbreakpoint - normal breakpoint\n\ | |
12313 | \twatchpoint - watchpoint\n\ | |
12314 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12315 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12316 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12317 | address and file/line number respectively.\n\ |
12318 | \n\ | |
12319 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12320 | are set to the address of the last breakpoint listed unless the command\n\ |
12321 | is prefixed with \"server \".\n\n\ | |
c906108c | 12322 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12323 | breakpoint set.")); |
c906108c | 12324 | |
6b04bdb7 MS |
12325 | add_info_alias ("b", "breakpoints", 1); |
12326 | ||
c906108c | 12327 | if (xdb_commands) |
1bedd215 AC |
12328 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
12329 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12330 | The \"Type\" column indicates one of:\n\ |
12331 | \tbreakpoint - normal breakpoint\n\ | |
12332 | \twatchpoint - watchpoint\n\ | |
12333 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12334 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12335 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12336 | address and file/line number respectively.\n\ |
12337 | \n\ | |
12338 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12339 | are set to the address of the last breakpoint listed unless the command\n\ |
12340 | is prefixed with \"server \".\n\n\ | |
c906108c | 12341 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12342 | breakpoint set.")); |
c906108c | 12343 | |
1a966eab AC |
12344 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
12345 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12346 | The \"Type\" column indicates one of:\n\ |
12347 | \tbreakpoint - normal breakpoint\n\ | |
12348 | \twatchpoint - watchpoint\n\ | |
12349 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
12350 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
12351 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
12352 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
12353 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
12354 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
12355 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
12356 | address and file/line number respectively.\n\ |
12357 | \n\ | |
12358 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12359 | are set to the address of the last breakpoint listed unless the command\n\ |
12360 | is prefixed with \"server \".\n\n\ | |
c906108c | 12361 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 12362 | breakpoint set."), |
c906108c SS |
12363 | &maintenanceinfolist); |
12364 | ||
44feb3ce TT |
12365 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
12366 | Set catchpoints to catch events."), | |
12367 | &catch_cmdlist, "catch ", | |
12368 | 0/*allow-unknown*/, &cmdlist); | |
12369 | ||
12370 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
12371 | Set temporary catchpoints to catch events."), | |
12372 | &tcatch_cmdlist, "tcatch ", | |
12373 | 0/*allow-unknown*/, &cmdlist); | |
12374 | ||
12375 | /* Add catch and tcatch sub-commands. */ | |
12376 | add_catch_command ("catch", _("\ | |
12377 | Catch an exception, when caught.\n\ | |
12378 | With an argument, catch only exceptions with the given name."), | |
12379 | catch_catch_command, | |
a96d9b2e | 12380 | NULL, |
44feb3ce TT |
12381 | CATCH_PERMANENT, |
12382 | CATCH_TEMPORARY); | |
12383 | add_catch_command ("throw", _("\ | |
12384 | Catch an exception, when thrown.\n\ | |
12385 | With an argument, catch only exceptions with the given name."), | |
12386 | catch_throw_command, | |
a96d9b2e | 12387 | NULL, |
44feb3ce TT |
12388 | CATCH_PERMANENT, |
12389 | CATCH_TEMPORARY); | |
12390 | add_catch_command ("fork", _("Catch calls to fork."), | |
12391 | catch_fork_command_1, | |
a96d9b2e | 12392 | NULL, |
44feb3ce TT |
12393 | (void *) (uintptr_t) catch_fork_permanent, |
12394 | (void *) (uintptr_t) catch_fork_temporary); | |
12395 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
12396 | catch_fork_command_1, | |
a96d9b2e | 12397 | NULL, |
44feb3ce TT |
12398 | (void *) (uintptr_t) catch_vfork_permanent, |
12399 | (void *) (uintptr_t) catch_vfork_temporary); | |
12400 | add_catch_command ("exec", _("Catch calls to exec."), | |
12401 | catch_exec_command_1, | |
a96d9b2e SDJ |
12402 | NULL, |
12403 | CATCH_PERMANENT, | |
12404 | CATCH_TEMPORARY); | |
12405 | add_catch_command ("syscall", _("\ | |
12406 | Catch system calls by their names and/or numbers.\n\ | |
12407 | Arguments say which system calls to catch. If no arguments\n\ | |
12408 | are given, every system call will be caught.\n\ | |
12409 | Arguments, if given, should be one or more system call names\n\ | |
12410 | (if your system supports that), or system call numbers."), | |
12411 | catch_syscall_command_1, | |
12412 | catch_syscall_completer, | |
44feb3ce TT |
12413 | CATCH_PERMANENT, |
12414 | CATCH_TEMPORARY); | |
44feb3ce TT |
12415 | add_catch_command ("exception", _("\ |
12416 | Catch Ada exceptions, when raised.\n\ | |
12417 | With an argument, catch only exceptions with the given name."), | |
12418 | catch_ada_exception_command, | |
a96d9b2e | 12419 | NULL, |
44feb3ce TT |
12420 | CATCH_PERMANENT, |
12421 | CATCH_TEMPORARY); | |
12422 | add_catch_command ("assert", _("\ | |
12423 | Catch failed Ada assertions, when raised.\n\ | |
12424 | With an argument, catch only exceptions with the given name."), | |
12425 | catch_assert_command, | |
a96d9b2e | 12426 | NULL, |
44feb3ce TT |
12427 | CATCH_PERMANENT, |
12428 | CATCH_TEMPORARY); | |
c5aa993b | 12429 | |
1bedd215 AC |
12430 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
12431 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12432 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 12433 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12434 | an expression changes.\n\ |
12435 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12436 | the memory to which it refers.")); | |
65d12d83 | 12437 | set_cmd_completer (c, expression_completer); |
c906108c | 12438 | |
1bedd215 AC |
12439 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
12440 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 12441 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 12442 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12443 | an expression is read.\n\ |
12444 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12445 | the memory to which it refers.")); | |
65d12d83 | 12446 | set_cmd_completer (c, expression_completer); |
c906108c | 12447 | |
1bedd215 AC |
12448 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
12449 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12450 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 12451 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12452 | an expression is either read or written.\n\ |
12453 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12454 | the memory to which it refers.")); | |
65d12d83 | 12455 | set_cmd_completer (c, expression_completer); |
c906108c | 12456 | |
d77f58be | 12457 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 12458 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 12459 | |
920d2a44 AC |
12460 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
12461 | respond to changes - contrary to the description. */ | |
85c07804 AC |
12462 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
12463 | &can_use_hw_watchpoints, _("\ | |
12464 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
12465 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
12466 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
12467 | such is available. (However, any hardware watchpoints that were\n\ | |
12468 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
12469 | hardware.)"), |
12470 | NULL, | |
920d2a44 | 12471 | show_can_use_hw_watchpoints, |
85c07804 | 12472 | &setlist, &showlist); |
c906108c SS |
12473 | |
12474 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 12475 | |
1042e4c0 SS |
12476 | /* Tracepoint manipulation commands. */ |
12477 | ||
12478 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
12479 | Set a tracepoint at specified line or function.\n\ | |
12480 | \n" | |
12481 | BREAK_ARGS_HELP ("trace") "\n\ | |
12482 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12483 | set_cmd_completer (c, location_completer); | |
12484 | ||
12485 | add_com_alias ("tp", "trace", class_alias, 0); | |
12486 | add_com_alias ("tr", "trace", class_alias, 1); | |
12487 | add_com_alias ("tra", "trace", class_alias, 1); | |
12488 | add_com_alias ("trac", "trace", class_alias, 1); | |
12489 | ||
7a697b8d SS |
12490 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
12491 | Set a fast tracepoint at specified line or function.\n\ | |
12492 | \n" | |
12493 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
12494 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12495 | set_cmd_completer (c, location_completer); | |
12496 | ||
0fb4aa4b PA |
12497 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
12498 | Set a static tracepoint at specified line, function or marker.\n\ | |
12499 | \n\ | |
12500 | strace [LOCATION] [if CONDITION]\n\ | |
12501 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
12502 | or -m MARKER_ID.\n\ | |
12503 | If a line number is specified, probe the marker at start of code\n\ | |
12504 | for that line. If a function is specified, probe the marker at start\n\ | |
12505 | of code for that function. If an address is specified, probe the marker\n\ | |
12506 | at that exact address. If a marker id is specified, probe the marker\n\ | |
12507 | with that name. With no LOCATION, uses current execution address of\n\ | |
12508 | the selected stack frame.\n\ | |
12509 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
12510 | This collects arbitrary user data passed in the probe point call to the\n\ | |
12511 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
12512 | by printing the $_sdata variable like any other convenience variable.\n\ | |
12513 | \n\ | |
12514 | CONDITION is a boolean expression.\n\ | |
12515 | \n\ | |
d41c0fc8 PA |
12516 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
12517 | conditions are different.\n\ | |
0fb4aa4b PA |
12518 | \n\ |
12519 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
12520 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12521 | set_cmd_completer (c, location_completer); | |
12522 | ||
1042e4c0 | 12523 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 12524 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
12525 | Convenience variable \"$tpnum\" contains the number of the\n\ |
12526 | last tracepoint set.")); | |
12527 | ||
12528 | add_info_alias ("tp", "tracepoints", 1); | |
12529 | ||
12530 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
12531 | Delete specified tracepoints.\n\ | |
12532 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12533 | No argument means delete all tracepoints."), | |
12534 | &deletelist); | |
12535 | ||
12536 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
12537 | Disable specified tracepoints.\n\ | |
12538 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12539 | No argument means disable all tracepoints."), | |
12540 | &disablelist); | |
12541 | deprecate_cmd (c, "disable"); | |
12542 | ||
12543 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
12544 | Enable specified tracepoints.\n\ | |
12545 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12546 | No argument means enable all tracepoints."), | |
12547 | &enablelist); | |
12548 | deprecate_cmd (c, "enable"); | |
12549 | ||
12550 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
12551 | Set the passcount for a tracepoint.\n\ | |
12552 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
12553 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
12554 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
12555 | ||
6149aea9 PA |
12556 | add_prefix_cmd ("save", class_breakpoint, save_command, |
12557 | _("Save breakpoint definitions as a script."), | |
12558 | &save_cmdlist, "save ", | |
12559 | 0/*allow-unknown*/, &cmdlist); | |
12560 | ||
12561 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
12562 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 12563 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
12564 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
12565 | session to restore them."), | |
12566 | &save_cmdlist); | |
12567 | set_cmd_completer (c, filename_completer); | |
12568 | ||
12569 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 12570 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
12571 | Use the 'source' command in another debug session to restore them."), |
12572 | &save_cmdlist); | |
1042e4c0 SS |
12573 | set_cmd_completer (c, filename_completer); |
12574 | ||
6149aea9 PA |
12575 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
12576 | deprecate_cmd (c, "save tracepoints"); | |
12577 | ||
1bedd215 | 12578 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12579 | Breakpoint specific settings\n\ |
12580 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12581 | pending breakpoint behavior"), |
fa8d40ab JJ |
12582 | &breakpoint_set_cmdlist, "set breakpoint ", |
12583 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 12584 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12585 | Breakpoint specific settings\n\ |
12586 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12587 | pending breakpoint behavior"), |
fa8d40ab JJ |
12588 | &breakpoint_show_cmdlist, "show breakpoint ", |
12589 | 0/*allow-unknown*/, &showlist); | |
12590 | ||
7915a72c AC |
12591 | add_setshow_auto_boolean_cmd ("pending", no_class, |
12592 | &pending_break_support, _("\ | |
12593 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
12594 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
12595 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
12596 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
12597 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 12598 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 12599 | NULL, |
920d2a44 | 12600 | show_pending_break_support, |
6e1d7d6c AC |
12601 | &breakpoint_set_cmdlist, |
12602 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
12603 | |
12604 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
12605 | |
12606 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
12607 | &automatic_hardware_breakpoints, _("\ | |
12608 | Set automatic usage of hardware breakpoints."), _("\ | |
12609 | Show automatic usage of hardware breakpoints."), _("\ | |
12610 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
12611 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
12612 | a warning will be emitted for such breakpoints."), | |
12613 | NULL, | |
12614 | show_automatic_hardware_breakpoints, | |
12615 | &breakpoint_set_cmdlist, | |
12616 | &breakpoint_show_cmdlist); | |
74960c60 | 12617 | |
33e5cbd6 PA |
12618 | add_setshow_enum_cmd ("always-inserted", class_support, |
12619 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
12620 | Set mode for inserting breakpoints."), _("\ |
12621 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
12622 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
12623 | resumed, and removed when execution stops. When this mode is on,\n\ | |
12624 | breakpoints are inserted immediately and removed only when the user\n\ | |
12625 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
12626 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
12627 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
12628 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
12629 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
12630 | NULL, |
12631 | &show_always_inserted_mode, | |
12632 | &breakpoint_set_cmdlist, | |
12633 | &breakpoint_show_cmdlist); | |
765dc015 VP |
12634 | |
12635 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
12636 | |
12637 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 12638 | } |