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 | ||
567e1b4e JB |
1162 | /* Assuming that B is a watchpoint: |
1163 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1164 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1165 | - Evaluate the condition if there is one, and store the result |
1166 | in b->loc->cond. | |
a5606eee VP |
1167 | - Update the list of values that must be watched in B->loc. |
1168 | ||
4a64f543 MS |
1169 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1170 | nothing. If this is local watchpoint that is out of scope, delete | |
1171 | it. | |
1172 | ||
1173 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1174 | removed + inserted on each stop here. Normal breakpoints must | |
1175 | never be removed because they might be missed by a running thread | |
1176 | when debugging in non-stop mode. On the other hand, hardware | |
1177 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1178 | to each LWP since they are stored in each LWP's hardware debug | |
1179 | registers. Therefore, such LWP must be stopped first in order to | |
1180 | be able to modify its hardware watchpoints. | |
1181 | ||
1182 | Hardware watchpoints must be reset exactly once after being | |
1183 | presented to the user. It cannot be done sooner, because it would | |
1184 | reset the data used to present the watchpoint hit to the user. And | |
1185 | it must not be done later because it could display the same single | |
1186 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1187 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1188 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1189 | not user-visible - its hit is suppressed if the memory content has | |
1190 | not changed. | |
1191 | ||
1192 | The following constraints influence the location where we can reset | |
1193 | hardware watchpoints: | |
1194 | ||
1195 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1196 | called several times when GDB stops. | |
1197 | ||
1198 | [linux] | |
1199 | * Multiple hardware watchpoints can be hit at the same time, | |
1200 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1201 | hit at a time as the reason for stopping, and all the other hits | |
1202 | are presented later, one after the other, each time the user | |
1203 | requests the execution to be resumed. Execution is not resumed | |
1204 | for the threads still having pending hit event stored in | |
1205 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1206 | the inferior on the first stop the thread hit event is kept being | |
1207 | reported from its cached value by linux_nat_stopped_data_address | |
1208 | until the real thread resume happens after the watchpoint gets | |
1209 | presented and thus its LWP_INFO->STATUS gets reset. | |
1210 | ||
1211 | Therefore the hardware watchpoint hit can get safely reset on the | |
1212 | watchpoint removal from inferior. */ | |
a79d3c27 | 1213 | |
b40ce68a | 1214 | static void |
a5606eee | 1215 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1216 | { |
a5606eee | 1217 | int within_current_scope; |
a5606eee | 1218 | struct frame_id saved_frame_id; |
66076460 | 1219 | int frame_saved; |
a5606eee | 1220 | |
f6bc2008 PA |
1221 | /* If this is a local watchpoint, we only want to check if the |
1222 | watchpoint frame is in scope if the current thread is the thread | |
1223 | that was used to create the watchpoint. */ | |
1224 | if (!watchpoint_in_thread_scope (b)) | |
1225 | return; | |
1226 | ||
a5606eee VP |
1227 | if (b->disposition == disp_del_at_next_stop) |
1228 | return; | |
1229 | ||
66076460 | 1230 | frame_saved = 0; |
a5606eee VP |
1231 | |
1232 | /* Determine if the watchpoint is within scope. */ | |
1233 | if (b->exp_valid_block == NULL) | |
1234 | within_current_scope = 1; | |
1235 | else | |
1236 | { | |
b5db5dfc UW |
1237 | struct frame_info *fi = get_current_frame (); |
1238 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1239 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1240 | ||
1241 | /* If we're in a function epilogue, unwinding may not work | |
1242 | properly, so do not attempt to recreate locations at this | |
1243 | point. See similar comments in watchpoint_check. */ | |
1244 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1245 | return; | |
66076460 DJ |
1246 | |
1247 | /* Save the current frame's ID so we can restore it after | |
1248 | evaluating the watchpoint expression on its own frame. */ | |
1249 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1250 | took a frame parameter, so that we didn't have to change the | |
1251 | selected frame. */ | |
1252 | frame_saved = 1; | |
1253 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1254 | ||
a5606eee VP |
1255 | fi = frame_find_by_id (b->watchpoint_frame); |
1256 | within_current_scope = (fi != NULL); | |
1257 | if (within_current_scope) | |
1258 | select_frame (fi); | |
1259 | } | |
1260 | ||
b5db5dfc UW |
1261 | /* We don't free locations. They are stored in the bp_location array |
1262 | and update_global_location_list will eventually delete them and | |
1263 | remove breakpoints if needed. */ | |
1264 | b->loc = NULL; | |
1265 | ||
a5606eee VP |
1266 | if (within_current_scope && reparse) |
1267 | { | |
1268 | char *s; | |
d63d0675 | 1269 | |
a5606eee VP |
1270 | if (b->exp) |
1271 | { | |
1272 | xfree (b->exp); | |
1273 | b->exp = NULL; | |
1274 | } | |
d63d0675 | 1275 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1276 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1277 | /* If the meaning of expression itself changed, the old value is | |
1278 | no longer relevant. We don't want to report a watchpoint hit | |
1279 | to the user when the old value and the new value may actually | |
1280 | be completely different objects. */ | |
1281 | value_free (b->val); | |
fa4727a6 DJ |
1282 | b->val = NULL; |
1283 | b->val_valid = 0; | |
60e1c644 PA |
1284 | |
1285 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1286 | expression is stored in the breakpoint object, not in the | |
1287 | locations (re)created below. */ | |
1288 | if (b->cond_string != NULL) | |
1289 | { | |
1290 | if (b->cond_exp != NULL) | |
1291 | { | |
1292 | xfree (b->cond_exp); | |
1293 | b->cond_exp = NULL; | |
1294 | } | |
1295 | ||
1296 | s = b->cond_string; | |
1297 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1298 | } | |
a5606eee | 1299 | } |
a5606eee VP |
1300 | |
1301 | /* If we failed to parse the expression, for example because | |
1302 | it refers to a global variable in a not-yet-loaded shared library, | |
1303 | don't try to insert watchpoint. We don't automatically delete | |
1304 | such watchpoint, though, since failure to parse expression | |
1305 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1306 | if ( !target_has_execution) |
1307 | { | |
1308 | /* Without execution, memory can't change. No use to try and | |
1309 | set watchpoint locations. The watchpoint will be reset when | |
1310 | the target gains execution, through breakpoint_re_set. */ | |
1311 | } | |
1312 | else if (within_current_scope && b->exp) | |
a5606eee | 1313 | { |
0cf6dd15 | 1314 | int pc = 0; |
fa4727a6 | 1315 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1316 | struct program_space *frame_pspace; |
a5606eee | 1317 | |
0cf6dd15 | 1318 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1319 | |
a5606eee VP |
1320 | /* Avoid setting b->val if it's already set. The meaning of |
1321 | b->val is 'the last value' user saw, and we should update | |
1322 | it only if we reported that last value to user. As it | |
1323 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1324 | if (!b->val_valid) |
1325 | { | |
1326 | b->val = v; | |
1327 | b->val_valid = 1; | |
1328 | } | |
a5606eee | 1329 | |
2d134ed3 PA |
1330 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1331 | ||
a5606eee | 1332 | /* Look at each value on the value chain. */ |
9fa40276 | 1333 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1334 | { |
1335 | /* If it's a memory location, and GDB actually needed | |
1336 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1337 | must watch it. If the first value returned is |
1338 | still lazy, that means an error occurred reading it; | |
1339 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1340 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1341 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1342 | { |
1343 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1344 | |
a5606eee VP |
1345 | /* We only watch structs and arrays if user asked |
1346 | for it explicitly, never if they just happen to | |
1347 | appear in the middle of some value chain. */ | |
fa4727a6 | 1348 | if (v == result |
a5606eee VP |
1349 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1350 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1351 | { | |
1352 | CORE_ADDR addr; | |
1353 | int len, type; | |
1354 | struct bp_location *loc, **tmp; | |
1355 | ||
42ae5230 | 1356 | addr = value_address (v); |
a5606eee VP |
1357 | len = TYPE_LENGTH (value_type (v)); |
1358 | type = hw_write; | |
1359 | if (b->type == bp_read_watchpoint) | |
1360 | type = hw_read; | |
1361 | else if (b->type == bp_access_watchpoint) | |
1362 | type = hw_access; | |
1363 | ||
39d61571 | 1364 | loc = allocate_bp_location (b); |
a5606eee VP |
1365 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1366 | ; | |
1367 | *tmp = loc; | |
a6d9a66e | 1368 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1369 | |
1370 | loc->pspace = frame_pspace; | |
a5606eee VP |
1371 | loc->address = addr; |
1372 | loc->length = len; | |
1373 | loc->watchpoint_type = type; | |
1374 | } | |
1375 | } | |
9fa40276 TJB |
1376 | } |
1377 | ||
1378 | /* Change the type of breakpoint between hardware assisted or | |
1379 | an ordinary watchpoint depending on the hardware support | |
1380 | and free hardware slots. REPARSE is set when the inferior | |
1381 | is started. */ | |
1382 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1383 | && reparse) | |
1384 | { | |
e09342b5 | 1385 | int reg_cnt; |
9fa40276 TJB |
1386 | enum bp_loc_type loc_type; |
1387 | struct bp_location *bl; | |
a5606eee | 1388 | |
e09342b5 TJB |
1389 | reg_cnt = can_use_hardware_watchpoint (val_chain, b->exact); |
1390 | ||
1391 | if (reg_cnt) | |
9fa40276 TJB |
1392 | { |
1393 | int i, target_resources_ok, other_type_used; | |
e09342b5 | 1394 | enum enable_state orig_enable_state; |
9fa40276 TJB |
1395 | |
1396 | /* We need to determine how many resources are already | |
e09342b5 TJB |
1397 | used for all other hardware watchpoints plus this one |
1398 | to see if we still have enough resources to also fit | |
1399 | this watchpoint in as well. To guarantee the | |
1400 | hw_watchpoint_used_count call below counts this | |
1401 | watchpoint, make sure that it is marked as a hardware | |
1402 | watchpoint. */ | |
1403 | b->type = bp_hardware_watchpoint; | |
1404 | ||
1405 | /* hw_watchpoint_used_count ignores disabled watchpoints, | |
1406 | and b might be disabled if we're being called from | |
1407 | do_enable_breakpoint. */ | |
1408 | orig_enable_state = b->enable_state; | |
1409 | b->enable_state = bp_enabled; | |
1410 | ||
9fa40276 TJB |
1411 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1412 | &other_type_used); | |
9fa40276 | 1413 | |
e09342b5 TJB |
1414 | b->enable_state = orig_enable_state; |
1415 | ||
1416 | target_resources_ok = target_can_use_hardware_watchpoint | |
1417 | (bp_hardware_watchpoint, i, other_type_used); | |
1418 | if (target_resources_ok <= 0) | |
1419 | b->type = bp_watchpoint; | |
9fa40276 TJB |
1420 | } |
1421 | else | |
1422 | b->type = bp_watchpoint; | |
1423 | ||
1424 | loc_type = (b->type == bp_watchpoint? bp_loc_other | |
1425 | : bp_loc_hardware_watchpoint); | |
1426 | for (bl = b->loc; bl; bl = bl->next) | |
1427 | bl->loc_type = loc_type; | |
1428 | } | |
1429 | ||
1430 | for (v = val_chain; v; v = next) | |
1431 | { | |
a5606eee VP |
1432 | next = value_next (v); |
1433 | if (v != b->val) | |
1434 | value_free (v); | |
1435 | } | |
1436 | ||
c7437ca6 PA |
1437 | /* If a software watchpoint is not watching any memory, then the |
1438 | above left it without any location set up. But, | |
1439 | bpstat_stop_status requires a location to be able to report | |
1440 | stops, so make sure there's at least a dummy one. */ | |
1441 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1442 | { | |
1443 | b->loc = allocate_bp_location (b); | |
1444 | b->loc->pspace = frame_pspace; | |
1445 | b->loc->address = -1; | |
1446 | b->loc->length = -1; | |
1447 | b->loc->watchpoint_type = -1; | |
1448 | } | |
a5606eee VP |
1449 | } |
1450 | else if (!within_current_scope) | |
7270d8f2 | 1451 | { |
ac74f770 MS |
1452 | printf_filtered (_("\ |
1453 | Watchpoint %d deleted because the program has left the block\n\ | |
1454 | in which its expression is valid.\n"), | |
a5606eee VP |
1455 | b->number); |
1456 | if (b->related_breakpoint) | |
60e1c644 PA |
1457 | { |
1458 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1459 | b->related_breakpoint->related_breakpoint = NULL; | |
1460 | b->related_breakpoint= NULL; | |
1461 | } | |
a5606eee | 1462 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1463 | } |
a5606eee VP |
1464 | |
1465 | /* Restore the selected frame. */ | |
66076460 DJ |
1466 | if (frame_saved) |
1467 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1468 | } |
1469 | ||
a5606eee | 1470 | |
74960c60 VP |
1471 | /* Returns 1 iff breakpoint location should be |
1472 | inserted in the inferior. */ | |
1473 | static int | |
35df4500 | 1474 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1475 | { |
35df4500 | 1476 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1477 | return 0; |
1478 | ||
35df4500 | 1479 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1480 | return 0; |
1481 | ||
35df4500 | 1482 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1483 | return 0; |
1484 | ||
56710373 PA |
1485 | /* This is set for example, when we're attached to the parent of a |
1486 | vfork, and have detached from the child. The child is running | |
1487 | free, and we expect it to do an exec or exit, at which point the | |
1488 | OS makes the parent schedulable again (and the target reports | |
1489 | that the vfork is done). Until the child is done with the shared | |
1490 | memory region, do not insert breakpoints in the parent, otherwise | |
1491 | the child could still trip on the parent's breakpoints. Since | |
1492 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1493 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1494 | return 0; |
1495 | ||
1042e4c0 SS |
1496 | /* Tracepoints are inserted by the target at a time of its choosing, |
1497 | not by us. */ | |
35df4500 | 1498 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1499 | return 0; |
1500 | ||
74960c60 VP |
1501 | return 1; |
1502 | } | |
1503 | ||
35df4500 TJB |
1504 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1505 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
1506 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. | |
879bfdc2 | 1507 | |
4a64f543 MS |
1508 | NOTE drow/2003-09-09: This routine could be broken down to an |
1509 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1510 | static int |
35df4500 | 1511 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1512 | struct ui_file *tmp_error_stream, |
fa3a767f | 1513 | int *disabled_breaks, |
26bb91f3 | 1514 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1515 | { |
1516 | int val = 0; | |
1517 | ||
35df4500 | 1518 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1519 | return 0; |
1520 | ||
8181d85f | 1521 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1522 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1523 | bl->target_info.placed_address = bl->address; | |
1524 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
8181d85f | 1525 | |
35df4500 TJB |
1526 | if (bl->loc_type == bp_loc_software_breakpoint |
1527 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1528 | { |
35df4500 | 1529 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1530 | { |
1531 | /* If the explicitly specified breakpoint type | |
1532 | is not hardware breakpoint, check the memory map to see | |
1533 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1534 | |
765dc015 VP |
1535 | Two important cases are: |
1536 | - location type is not hardware breakpoint, memory | |
1537 | is readonly. We change the type of the location to | |
1538 | hardware breakpoint. | |
4a64f543 MS |
1539 | - location type is hardware breakpoint, memory is |
1540 | read-write. This means we've previously made the | |
1541 | location hardware one, but then the memory map changed, | |
1542 | so we undo. | |
765dc015 | 1543 | |
4a64f543 MS |
1544 | When breakpoints are removed, remove_breakpoints will use |
1545 | location types we've just set here, the only possible | |
1546 | problem is that memory map has changed during running | |
1547 | program, but it's not going to work anyway with current | |
1548 | gdb. */ | |
765dc015 | 1549 | struct mem_region *mr |
35df4500 | 1550 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1551 | |
1552 | if (mr) | |
1553 | { | |
1554 | if (automatic_hardware_breakpoints) | |
1555 | { | |
765dc015 VP |
1556 | enum bp_loc_type new_type; |
1557 | ||
1558 | if (mr->attrib.mode != MEM_RW) | |
1559 | new_type = bp_loc_hardware_breakpoint; | |
1560 | else | |
1561 | new_type = bp_loc_software_breakpoint; | |
1562 | ||
35df4500 | 1563 | if (new_type != bl->loc_type) |
765dc015 VP |
1564 | { |
1565 | static int said = 0; | |
cc59ec59 | 1566 | |
35df4500 | 1567 | bl->loc_type = new_type; |
765dc015 VP |
1568 | if (!said) |
1569 | { | |
3e43a32a MS |
1570 | fprintf_filtered (gdb_stdout, |
1571 | _("Note: automatically using " | |
1572 | "hardware breakpoints for " | |
1573 | "read-only addresses.\n")); | |
765dc015 VP |
1574 | said = 1; |
1575 | } | |
1576 | } | |
1577 | } | |
35df4500 | 1578 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1579 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1580 | warning (_("cannot set software breakpoint " |
1581 | "at readonly address %s"), | |
35df4500 | 1582 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1583 | } |
1584 | } | |
1585 | ||
879bfdc2 DJ |
1586 | /* First check to see if we have to handle an overlay. */ |
1587 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1588 | || bl->section == NULL |
1589 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1590 | { |
1591 | /* No overlay handling: just set the breakpoint. */ | |
1592 | ||
35df4500 TJB |
1593 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1594 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1595 | &bl->target_info); | |
879bfdc2 | 1596 | else |
35df4500 TJB |
1597 | val = target_insert_breakpoint (bl->gdbarch, |
1598 | &bl->target_info); | |
879bfdc2 DJ |
1599 | } |
1600 | else | |
1601 | { | |
4a64f543 | 1602 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1603 | Shall we set a breakpoint at the LMA? */ |
1604 | if (!overlay_events_enabled) | |
1605 | { | |
1606 | /* Yes -- overlay event support is not active, | |
1607 | so we must try to set a breakpoint at the LMA. | |
1608 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1609 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1610 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1611 | bl->owner->number); |
879bfdc2 DJ |
1612 | else |
1613 | { | |
35df4500 TJB |
1614 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1615 | bl->section); | |
879bfdc2 | 1616 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1617 | bl->overlay_target_info = bl->target_info; |
1618 | bl->overlay_target_info.placed_address = addr; | |
1619 | val = target_insert_breakpoint (bl->gdbarch, | |
1620 | &bl->overlay_target_info); | |
879bfdc2 | 1621 | if (val != 0) |
99361f52 | 1622 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1623 | "Overlay breakpoint %d " |
1624 | "failed: in ROM?\n", | |
35df4500 | 1625 | bl->owner->number); |
879bfdc2 DJ |
1626 | } |
1627 | } | |
1628 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1629 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1630 | { |
1631 | /* Yes. This overlay section is mapped into memory. */ | |
35df4500 TJB |
1632 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1633 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1634 | &bl->target_info); | |
879bfdc2 | 1635 | else |
35df4500 TJB |
1636 | val = target_insert_breakpoint (bl->gdbarch, |
1637 | &bl->target_info); | |
879bfdc2 DJ |
1638 | } |
1639 | else | |
1640 | { | |
1641 | /* No. This breakpoint will not be inserted. | |
1642 | No error, but do not mark the bp as 'inserted'. */ | |
1643 | return 0; | |
1644 | } | |
1645 | } | |
1646 | ||
1647 | if (val) | |
1648 | { | |
1649 | /* Can't set the breakpoint. */ | |
35df4500 | 1650 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1651 | { |
4a64f543 | 1652 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1653 | val = 0; |
35df4500 | 1654 | bl->shlib_disabled = 1; |
879bfdc2 DJ |
1655 | if (!*disabled_breaks) |
1656 | { | |
1657 | fprintf_unfiltered (tmp_error_stream, | |
1658 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1659 | bl->owner->number); |
879bfdc2 | 1660 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1661 | "Temporarily disabling shared " |
1662 | "library breakpoints:\n"); | |
879bfdc2 DJ |
1663 | } |
1664 | *disabled_breaks = 1; | |
1665 | fprintf_unfiltered (tmp_error_stream, | |
35df4500 | 1666 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1667 | } |
1668 | else | |
879bfdc2 | 1669 | { |
35df4500 | 1670 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1671 | { |
1672 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1673 | fprintf_unfiltered (tmp_error_stream, |
1674 | "Cannot insert hardware " | |
1675 | "breakpoint %d.\n", | |
35df4500 | 1676 | bl->owner->number); |
879bfdc2 DJ |
1677 | } |
1678 | else | |
1679 | { | |
1680 | fprintf_unfiltered (tmp_error_stream, | |
1681 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1682 | bl->owner->number); |
879bfdc2 DJ |
1683 | fprintf_filtered (tmp_error_stream, |
1684 | "Error accessing memory address "); | |
35df4500 | 1685 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1686 | tmp_error_stream); |
879bfdc2 DJ |
1687 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1688 | safe_strerror (val)); | |
1689 | } | |
1690 | ||
1691 | } | |
1692 | } | |
1693 | else | |
35df4500 | 1694 | bl->inserted = 1; |
879bfdc2 DJ |
1695 | |
1696 | return val; | |
1697 | } | |
1698 | ||
35df4500 | 1699 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1700 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1701 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1702 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1703 | { |
77b06cd7 TJB |
1704 | gdb_assert (bl->owner->ops != NULL |
1705 | && bl->owner->ops->insert_location != NULL); | |
1706 | ||
1707 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1708 | |
1709 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1710 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1711 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1712 | { |
1713 | struct bp_location *loc, **loc_temp; | |
1714 | ||
1715 | /* But don't try to insert it, if there's already another | |
1716 | hw_access location that would be considered a duplicate | |
1717 | of this one. */ | |
1718 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1719 | if (loc != bl |
85d721b8 | 1720 | && loc->watchpoint_type == hw_access |
35df4500 | 1721 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1722 | { |
35df4500 TJB |
1723 | bl->duplicate = 1; |
1724 | bl->inserted = 1; | |
1725 | bl->target_info = loc->target_info; | |
1726 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1727 | val = 0; |
1728 | break; | |
1729 | } | |
1730 | ||
1731 | if (val == 1) | |
1732 | { | |
77b06cd7 TJB |
1733 | bl->watchpoint_type = hw_access; |
1734 | val = bl->owner->ops->insert_location (bl); | |
1735 | ||
1736 | if (val) | |
1737 | /* Back to the original value. */ | |
1738 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1739 | } |
1740 | } | |
1741 | ||
35df4500 | 1742 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1743 | } |
1744 | ||
35df4500 | 1745 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1746 | { |
77b06cd7 TJB |
1747 | gdb_assert (bl->owner->ops != NULL |
1748 | && bl->owner->ops->insert_location != NULL); | |
1749 | ||
1750 | val = bl->owner->ops->insert_location (bl); | |
1751 | if (val) | |
1752 | { | |
1753 | bl->owner->enable_state = bp_disabled; | |
1754 | ||
1755 | if (val == 1) | |
1756 | warning (_("\ | |
1757 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1758 | of catchpoint."), bl->owner->number); | |
1759 | else | |
1760 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1761 | } | |
1762 | ||
1763 | bl->inserted = (val == 0); | |
1640b821 DJ |
1764 | |
1765 | /* We've already printed an error message if there was a problem | |
1766 | inserting this catchpoint, and we've disabled the catchpoint, | |
1767 | so just return success. */ | |
1768 | return 0; | |
879bfdc2 DJ |
1769 | } |
1770 | ||
1771 | return 0; | |
1772 | } | |
1773 | ||
6c95b8df PA |
1774 | /* This function is called when program space PSPACE is about to be |
1775 | deleted. It takes care of updating breakpoints to not reference | |
1776 | PSPACE anymore. */ | |
1777 | ||
1778 | void | |
1779 | breakpoint_program_space_exit (struct program_space *pspace) | |
1780 | { | |
1781 | struct breakpoint *b, *b_temp; | |
876fa593 | 1782 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1783 | |
1784 | /* Remove any breakpoint that was set through this program space. */ | |
1785 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1786 | { | |
1787 | if (b->pspace == pspace) | |
1788 | delete_breakpoint (b); | |
1789 | } | |
1790 | ||
1791 | /* Breakpoints set through other program spaces could have locations | |
1792 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1793 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1794 | { |
1795 | struct bp_location *tmp; | |
1796 | ||
1797 | if (loc->pspace == pspace) | |
1798 | { | |
2bdf28a0 | 1799 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1800 | if (loc->owner->loc == loc) |
1801 | loc->owner->loc = loc->next; | |
1802 | else | |
1803 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1804 | if (tmp->next == loc) | |
1805 | { | |
1806 | tmp->next = loc->next; | |
1807 | break; | |
1808 | } | |
1809 | } | |
1810 | } | |
1811 | ||
1812 | /* Now update the global location list to permanently delete the | |
1813 | removed locations above. */ | |
1814 | update_global_location_list (0); | |
1815 | } | |
1816 | ||
74960c60 VP |
1817 | /* Make sure all breakpoints are inserted in inferior. |
1818 | Throws exception on any error. | |
1819 | A breakpoint that is already inserted won't be inserted | |
1820 | again, so calling this function twice is safe. */ | |
1821 | void | |
1822 | insert_breakpoints (void) | |
1823 | { | |
1824 | struct breakpoint *bpt; | |
1825 | ||
1826 | ALL_BREAKPOINTS (bpt) | |
1827 | if (is_hardware_watchpoint (bpt)) | |
4a64f543 | 1828 | update_watchpoint (bpt, 0 /* don't reparse. */); |
74960c60 | 1829 | |
b60e7edf | 1830 | update_global_location_list (1); |
74960c60 | 1831 | |
c35b1492 PA |
1832 | /* update_global_location_list does not insert breakpoints when |
1833 | always_inserted_mode is not enabled. Explicitly insert them | |
1834 | now. */ | |
1835 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1836 | insert_breakpoint_locations (); |
1837 | } | |
1838 | ||
c906108c SS |
1839 | /* insert_breakpoints is used when starting or continuing the program. |
1840 | remove_breakpoints is used when the program stops. | |
1841 | Both return zero if successful, | |
1842 | or an `errno' value if could not write the inferior. */ | |
1843 | ||
74960c60 VP |
1844 | static void |
1845 | insert_breakpoint_locations (void) | |
c906108c | 1846 | { |
a5606eee | 1847 | struct breakpoint *bpt; |
35df4500 | 1848 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1849 | int error = 0; |
c906108c SS |
1850 | int val = 0; |
1851 | int disabled_breaks = 0; | |
81d0cc19 | 1852 | int hw_breakpoint_error = 0; |
c906108c | 1853 | |
81d0cc19 | 1854 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1855 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1856 | |
81d0cc19 GS |
1857 | /* Explicitly mark the warning -- this will only be printed if |
1858 | there was an error. */ | |
1859 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1860 | |
1861 | save_current_space_and_thread (); | |
1862 | ||
35df4500 | 1863 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1864 | { |
35df4500 | 1865 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1866 | continue; |
1867 | ||
4a64f543 MS |
1868 | /* There is no point inserting thread-specific breakpoints if |
1869 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1870 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1871 | if (bl->owner->thread != -1 |
1872 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1873 | continue; |
1874 | ||
35df4500 | 1875 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1876 | |
1877 | /* For targets that support global breakpoints, there's no need | |
1878 | to select an inferior to insert breakpoint to. In fact, even | |
1879 | if we aren't attached to any process yet, we should still | |
1880 | insert breakpoints. */ | |
1881 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1882 | && ptid_equal (inferior_ptid, null_ptid)) | |
1883 | continue; | |
1884 | ||
35df4500 | 1885 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
879bfdc2 DJ |
1886 | &hw_breakpoint_error); |
1887 | if (val) | |
e236ba44 | 1888 | error = val; |
879bfdc2 | 1889 | } |
c906108c | 1890 | |
4a64f543 MS |
1891 | /* If we failed to insert all locations of a watchpoint, remove |
1892 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1893 | ALL_BREAKPOINTS (bpt) |
1894 | { | |
1895 | int some_failed = 0; | |
1896 | struct bp_location *loc; | |
1897 | ||
1898 | if (!is_hardware_watchpoint (bpt)) | |
1899 | continue; | |
1900 | ||
d6b74ac4 | 1901 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1902 | continue; |
74960c60 VP |
1903 | |
1904 | if (bpt->disposition == disp_del_at_next_stop) | |
1905 | continue; | |
a5606eee VP |
1906 | |
1907 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1908 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1909 | { |
1910 | some_failed = 1; | |
1911 | break; | |
1912 | } | |
1913 | if (some_failed) | |
1914 | { | |
1915 | for (loc = bpt->loc; loc; loc = loc->next) | |
1916 | if (loc->inserted) | |
1917 | remove_breakpoint (loc, mark_uninserted); | |
1918 | ||
1919 | hw_breakpoint_error = 1; | |
1920 | fprintf_unfiltered (tmp_error_stream, | |
1921 | "Could not insert hardware watchpoint %d.\n", | |
1922 | bpt->number); | |
1923 | error = -1; | |
1924 | } | |
1925 | } | |
1926 | ||
e236ba44 | 1927 | if (error) |
81d0cc19 GS |
1928 | { |
1929 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1930 | message about possibly exhausted resources. */ | |
879bfdc2 | 1931 | if (hw_breakpoint_error) |
81d0cc19 | 1932 | { |
c6510018 MS |
1933 | fprintf_unfiltered (tmp_error_stream, |
1934 | "Could not insert hardware breakpoints:\n\ | |
1935 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1936 | } |
81d0cc19 GS |
1937 | target_terminal_ours_for_output (); |
1938 | error_stream (tmp_error_stream); | |
1939 | } | |
f7545552 TT |
1940 | |
1941 | do_cleanups (cleanups); | |
c906108c SS |
1942 | } |
1943 | ||
c906108c | 1944 | int |
fba45db2 | 1945 | remove_breakpoints (void) |
c906108c | 1946 | { |
35df4500 | 1947 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 1948 | int val = 0; |
c906108c | 1949 | |
35df4500 | 1950 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 1951 | { |
35df4500 TJB |
1952 | if (bl->inserted) |
1953 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 1954 | } |
3a1bae8e | 1955 | return val; |
c906108c SS |
1956 | } |
1957 | ||
6c95b8df PA |
1958 | /* Remove breakpoints of process PID. */ |
1959 | ||
1960 | int | |
1961 | remove_breakpoints_pid (int pid) | |
1962 | { | |
35df4500 | 1963 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
1964 | int val; |
1965 | struct inferior *inf = find_inferior_pid (pid); | |
1966 | ||
35df4500 | 1967 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 1968 | { |
35df4500 | 1969 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
1970 | continue; |
1971 | ||
35df4500 | 1972 | if (bl->inserted) |
6c95b8df | 1973 | { |
35df4500 | 1974 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
1975 | if (val != 0) |
1976 | return val; | |
1977 | } | |
1978 | } | |
1979 | return 0; | |
1980 | } | |
1981 | ||
692590c1 | 1982 | int |
80ce1ecb | 1983 | remove_hw_watchpoints (void) |
692590c1 | 1984 | { |
35df4500 | 1985 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 1986 | int val = 0; |
692590c1 | 1987 | |
35df4500 | 1988 | ALL_BP_LOCATIONS (bl, blp_tmp) |
692590c1 | 1989 | { |
35df4500 TJB |
1990 | if (bl->inserted && bl->loc_type == bp_loc_hardware_watchpoint) |
1991 | val |= remove_breakpoint (bl, mark_uninserted); | |
692590c1 | 1992 | } |
3a1bae8e | 1993 | return val; |
692590c1 MS |
1994 | } |
1995 | ||
c906108c | 1996 | int |
fba45db2 | 1997 | reattach_breakpoints (int pid) |
c906108c | 1998 | { |
6c95b8df | 1999 | struct cleanup *old_chain; |
35df4500 | 2000 | struct bp_location *bl, **blp_tmp; |
c906108c | 2001 | int val; |
86b887df | 2002 | struct ui_file *tmp_error_stream; |
fa3a767f | 2003 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2004 | struct inferior *inf; |
2005 | struct thread_info *tp; | |
2006 | ||
2007 | tp = any_live_thread_of_process (pid); | |
2008 | if (tp == NULL) | |
2009 | return 1; | |
2010 | ||
2011 | inf = find_inferior_pid (pid); | |
2012 | old_chain = save_inferior_ptid (); | |
2013 | ||
2014 | inferior_ptid = tp->ptid; | |
a4954f26 | 2015 | |
86b887df | 2016 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2017 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2018 | |
35df4500 | 2019 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2020 | { |
35df4500 | 2021 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2022 | continue; |
2023 | ||
35df4500 | 2024 | if (bl->inserted) |
c5aa993b | 2025 | { |
35df4500 TJB |
2026 | bl->inserted = 0; |
2027 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); | |
c5aa993b JM |
2028 | if (val != 0) |
2029 | { | |
ce696e05 | 2030 | do_cleanups (old_chain); |
c5aa993b JM |
2031 | return val; |
2032 | } | |
2033 | } | |
2034 | } | |
ce696e05 | 2035 | do_cleanups (old_chain); |
c906108c SS |
2036 | return 0; |
2037 | } | |
2038 | ||
e58b0e63 PA |
2039 | static int internal_breakpoint_number = -1; |
2040 | ||
84f4c1fe PM |
2041 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2042 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2043 | from internal_breakpoint_number and that variable decremented. | |
2044 | Otherwis the breakpoint number will be populated from | |
2045 | breakpoint_count and that value incremented. Internal breakpoints | |
2046 | do not set the internal var bpnum. */ | |
2047 | static void | |
2048 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2049 | { | |
2050 | if (internal) | |
2051 | b->number = internal_breakpoint_number--; | |
2052 | else | |
2053 | { | |
2054 | set_breakpoint_count (breakpoint_count + 1); | |
2055 | b->number = breakpoint_count; | |
2056 | } | |
2057 | } | |
2058 | ||
e62c965a | 2059 | static struct breakpoint * |
a6d9a66e UW |
2060 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2061 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2062 | { |
e62c965a PP |
2063 | struct symtab_and_line sal; |
2064 | struct breakpoint *b; | |
2065 | ||
4a64f543 | 2066 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2067 | |
2068 | sal.pc = address; | |
2069 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2070 | sal.pspace = current_program_space; |
e62c965a | 2071 | |
a6d9a66e | 2072 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2073 | b->number = internal_breakpoint_number--; |
2074 | b->disposition = disp_donttouch; | |
2075 | ||
2076 | return b; | |
2077 | } | |
2078 | ||
17450429 PP |
2079 | static const char *const longjmp_names[] = |
2080 | { | |
2081 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2082 | }; | |
2083 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2084 | ||
2085 | /* Per-objfile data private to breakpoint.c. */ | |
2086 | struct breakpoint_objfile_data | |
2087 | { | |
2088 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2089 | struct minimal_symbol *overlay_msym; | |
2090 | ||
2091 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2092 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2093 | ||
2094 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2095 | struct minimal_symbol *terminate_msym; | |
2096 | ||
2097 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2098 | struct minimal_symbol *exception_msym; | |
2099 | }; | |
2100 | ||
2101 | static const struct objfile_data *breakpoint_objfile_key; | |
2102 | ||
2103 | /* Minimal symbol not found sentinel. */ | |
2104 | static struct minimal_symbol msym_not_found; | |
2105 | ||
2106 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2107 | ||
2108 | static int | |
2109 | msym_not_found_p (const struct minimal_symbol *msym) | |
2110 | { | |
2111 | return msym == &msym_not_found; | |
2112 | } | |
2113 | ||
2114 | /* Return per-objfile data needed by breakpoint.c. | |
2115 | Allocate the data if necessary. */ | |
2116 | ||
2117 | static struct breakpoint_objfile_data * | |
2118 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2119 | { | |
2120 | struct breakpoint_objfile_data *bp_objfile_data; | |
2121 | ||
2122 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2123 | if (bp_objfile_data == NULL) | |
2124 | { | |
2125 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2126 | sizeof (*bp_objfile_data)); | |
2127 | ||
2128 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2129 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2130 | } | |
2131 | return bp_objfile_data; | |
2132 | } | |
2133 | ||
e62c965a | 2134 | static void |
af02033e | 2135 | create_overlay_event_breakpoint (void) |
e62c965a | 2136 | { |
69de3c6a | 2137 | struct objfile *objfile; |
af02033e | 2138 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2139 | |
69de3c6a PP |
2140 | ALL_OBJFILES (objfile) |
2141 | { | |
2142 | struct breakpoint *b; | |
17450429 PP |
2143 | struct breakpoint_objfile_data *bp_objfile_data; |
2144 | CORE_ADDR addr; | |
69de3c6a | 2145 | |
17450429 PP |
2146 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2147 | ||
2148 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2149 | continue; | |
2150 | ||
2151 | if (bp_objfile_data->overlay_msym == NULL) | |
2152 | { | |
2153 | struct minimal_symbol *m; | |
2154 | ||
2155 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2156 | if (m == NULL) | |
2157 | { | |
2158 | /* Avoid future lookups in this objfile. */ | |
2159 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2160 | continue; | |
2161 | } | |
2162 | bp_objfile_data->overlay_msym = m; | |
2163 | } | |
e62c965a | 2164 | |
17450429 PP |
2165 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2166 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
69de3c6a PP |
2167 | bp_overlay_event); |
2168 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2169 | |
69de3c6a PP |
2170 | if (overlay_debugging == ovly_auto) |
2171 | { | |
2172 | b->enable_state = bp_enabled; | |
2173 | overlay_events_enabled = 1; | |
2174 | } | |
2175 | else | |
2176 | { | |
2177 | b->enable_state = bp_disabled; | |
2178 | overlay_events_enabled = 0; | |
2179 | } | |
e62c965a PP |
2180 | } |
2181 | update_global_location_list (1); | |
2182 | } | |
2183 | ||
0fd8e87f | 2184 | static void |
af02033e | 2185 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2186 | { |
6c95b8df | 2187 | struct program_space *pspace; |
6c95b8df PA |
2188 | struct cleanup *old_chain; |
2189 | ||
2190 | old_chain = save_current_program_space (); | |
0fd8e87f | 2191 | |
6c95b8df | 2192 | ALL_PSPACES (pspace) |
af02033e PP |
2193 | { |
2194 | struct objfile *objfile; | |
2195 | ||
2196 | set_current_program_space (pspace); | |
2197 | ||
2198 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2199 | { |
af02033e PP |
2200 | int i; |
2201 | struct gdbarch *gdbarch; | |
17450429 | 2202 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2203 | |
af02033e PP |
2204 | gdbarch = get_objfile_arch (objfile); |
2205 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2206 | continue; |
2207 | ||
17450429 PP |
2208 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2209 | ||
2210 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2211 | { |
2212 | struct breakpoint *b; | |
af02033e | 2213 | const char *func_name; |
17450429 | 2214 | CORE_ADDR addr; |
6c95b8df | 2215 | |
17450429 | 2216 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2217 | continue; |
0fd8e87f | 2218 | |
17450429 PP |
2219 | func_name = longjmp_names[i]; |
2220 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2221 | { | |
2222 | struct minimal_symbol *m; | |
2223 | ||
2224 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2225 | if (m == NULL) | |
2226 | { | |
2227 | /* Prevent future lookups in this objfile. */ | |
2228 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2229 | continue; | |
2230 | } | |
2231 | bp_objfile_data->longjmp_msym[i] = m; | |
2232 | } | |
2233 | ||
2234 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
2235 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master); | |
af02033e PP |
2236 | b->addr_string = xstrdup (func_name); |
2237 | b->enable_state = bp_disabled; | |
2238 | } | |
0fd8e87f | 2239 | } |
af02033e | 2240 | } |
0fd8e87f | 2241 | update_global_location_list (1); |
6c95b8df PA |
2242 | |
2243 | do_cleanups (old_chain); | |
0fd8e87f UW |
2244 | } |
2245 | ||
af02033e | 2246 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2247 | static void |
af02033e | 2248 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2249 | { |
2250 | struct program_space *pspace; | |
aa7d318d | 2251 | struct cleanup *old_chain; |
af02033e | 2252 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2253 | |
2254 | old_chain = save_current_program_space (); | |
2255 | ||
2256 | ALL_PSPACES (pspace) | |
17450429 PP |
2257 | { |
2258 | struct objfile *objfile; | |
2259 | CORE_ADDR addr; | |
2260 | ||
2261 | set_current_program_space (pspace); | |
2262 | ||
aa7d318d TT |
2263 | ALL_OBJFILES (objfile) |
2264 | { | |
2265 | struct breakpoint *b; | |
17450429 | 2266 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2267 | |
17450429 | 2268 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2269 | |
17450429 PP |
2270 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2271 | continue; | |
2272 | ||
2273 | if (bp_objfile_data->terminate_msym == NULL) | |
2274 | { | |
2275 | struct minimal_symbol *m; | |
2276 | ||
2277 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2278 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2279 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2280 | { | |
2281 | /* Prevent future lookups in this objfile. */ | |
2282 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2283 | continue; | |
2284 | } | |
2285 | bp_objfile_data->terminate_msym = m; | |
2286 | } | |
aa7d318d | 2287 | |
17450429 PP |
2288 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2289 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
aa7d318d TT |
2290 | bp_std_terminate_master); |
2291 | b->addr_string = xstrdup (func_name); | |
2292 | b->enable_state = bp_disabled; | |
2293 | } | |
17450429 PP |
2294 | } |
2295 | ||
aa7d318d TT |
2296 | update_global_location_list (1); |
2297 | ||
2298 | do_cleanups (old_chain); | |
2299 | } | |
2300 | ||
186c406b TT |
2301 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2302 | ||
2303 | void | |
2304 | create_exception_master_breakpoint (void) | |
2305 | { | |
2306 | struct objfile *objfile; | |
17450429 | 2307 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2308 | |
2309 | ALL_OBJFILES (objfile) | |
2310 | { | |
17450429 PP |
2311 | struct breakpoint *b; |
2312 | struct gdbarch *gdbarch; | |
2313 | struct breakpoint_objfile_data *bp_objfile_data; | |
2314 | CORE_ADDR addr; | |
2315 | ||
2316 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2317 | ||
2318 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2319 | continue; | |
2320 | ||
2321 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2322 | |
17450429 | 2323 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2324 | { |
17450429 | 2325 | struct minimal_symbol *debug_hook; |
186c406b | 2326 | |
17450429 PP |
2327 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2328 | if (debug_hook == NULL) | |
2329 | { | |
2330 | bp_objfile_data->exception_msym = &msym_not_found; | |
2331 | continue; | |
2332 | } | |
2333 | ||
2334 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2335 | } |
17450429 PP |
2336 | |
2337 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2338 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2339 | ¤t_target); | |
2340 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); | |
2341 | b->addr_string = xstrdup (func_name); | |
2342 | b->enable_state = bp_disabled; | |
186c406b TT |
2343 | } |
2344 | ||
2345 | update_global_location_list (1); | |
2346 | } | |
2347 | ||
c906108c | 2348 | void |
fba45db2 | 2349 | update_breakpoints_after_exec (void) |
c906108c | 2350 | { |
35df4500 | 2351 | struct breakpoint *b, *b_tmp; |
876fa593 | 2352 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2353 | |
25b22b0a PA |
2354 | /* We're about to delete breakpoints from GDB's lists. If the |
2355 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2356 | writing the breakpoints' "shadow contents" back into memory. The | |
2357 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2358 | do that. Instead, the target is responsible from marking | |
2359 | breakpoints out as soon as it detects an exec. We don't do that | |
2360 | here instead, because there may be other attempts to delete | |
2361 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2362 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2363 | if (bploc->pspace == current_program_space) |
2364 | gdb_assert (!bploc->inserted); | |
c906108c | 2365 | |
35df4500 | 2366 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2367 | { |
6c95b8df PA |
2368 | if (b->pspace != current_program_space) |
2369 | continue; | |
2370 | ||
4a64f543 | 2371 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2372 | if (b->type == bp_shlib_event) |
2373 | { | |
2374 | delete_breakpoint (b); | |
2375 | continue; | |
2376 | } | |
c906108c | 2377 | |
4a64f543 | 2378 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2379 | if (b->type == bp_jit_event) |
2380 | { | |
2381 | delete_breakpoint (b); | |
2382 | continue; | |
2383 | } | |
2384 | ||
1900040c | 2385 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2386 | as must overlay event and longjmp master breakpoints. */ |
2387 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2388 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2389 | || b->type == bp_exception_master) | |
c4093a6a JM |
2390 | { |
2391 | delete_breakpoint (b); | |
2392 | continue; | |
2393 | } | |
2394 | ||
4a64f543 | 2395 | /* Step-resume breakpoints are meaningless after an exec(). */ |
c5aa993b JM |
2396 | if (b->type == bp_step_resume) |
2397 | { | |
2398 | delete_breakpoint (b); | |
2399 | continue; | |
2400 | } | |
2401 | ||
611c83ae PA |
2402 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2403 | after an exec. */ | |
186c406b TT |
2404 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2405 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2406 | { |
2407 | delete_breakpoint (b); | |
2408 | continue; | |
2409 | } | |
2410 | ||
ce78b96d JB |
2411 | if (b->type == bp_catchpoint) |
2412 | { | |
2413 | /* For now, none of the bp_catchpoint breakpoints need to | |
2414 | do anything at this point. In the future, if some of | |
2415 | the catchpoints need to something, we will need to add | |
2416 | a new method, and call this method from here. */ | |
2417 | continue; | |
2418 | } | |
2419 | ||
c5aa993b JM |
2420 | /* bp_finish is a special case. The only way we ought to be able |
2421 | to see one of these when an exec() has happened, is if the user | |
2422 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2423 | carries them to the call-site of the current callee, by setting | |
2424 | a temporary bp there and resuming. But in this case, the finish | |
2425 | will carry them entirely through the vfork & exec. | |
2426 | ||
2427 | We don't want to allow a bp_finish to remain inserted now. But | |
2428 | we can't safely delete it, 'cause finish_command has a handle to | |
2429 | the bp on a bpstat, and will later want to delete it. There's a | |
2430 | chance (and I've seen it happen) that if we delete the bp_finish | |
2431 | here, that its storage will get reused by the time finish_command | |
2432 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2433 | We really must allow finish_command to delete a bp_finish. | |
2434 | ||
53a5351d JM |
2435 | In the absense of a general solution for the "how do we know |
2436 | it's safe to delete something others may have handles to?" | |
2437 | problem, what we'll do here is just uninsert the bp_finish, and | |
2438 | let finish_command delete it. | |
2439 | ||
2440 | (We know the bp_finish is "doomed" in the sense that it's | |
2441 | momentary, and will be deleted as soon as finish_command sees | |
2442 | the inferior stopped. So it doesn't matter that the bp's | |
2443 | address is probably bogus in the new a.out, unlike e.g., the | |
2444 | solib breakpoints.) */ | |
c5aa993b | 2445 | |
c5aa993b JM |
2446 | if (b->type == bp_finish) |
2447 | { | |
2448 | continue; | |
2449 | } | |
2450 | ||
2451 | /* Without a symbolic address, we have little hope of the | |
2452 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2453 | a.out. */ |
c5aa993b JM |
2454 | if (b->addr_string == NULL) |
2455 | { | |
2456 | delete_breakpoint (b); | |
2457 | continue; | |
2458 | } | |
c5aa993b | 2459 | } |
1900040c | 2460 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2461 | create_overlay_event_breakpoint (); |
2462 | create_longjmp_master_breakpoint (); | |
2463 | create_std_terminate_master_breakpoint (); | |
186c406b | 2464 | create_exception_master_breakpoint (); |
c906108c SS |
2465 | } |
2466 | ||
2467 | int | |
fba45db2 | 2468 | detach_breakpoints (int pid) |
c906108c | 2469 | { |
35df4500 | 2470 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2471 | int val = 0; |
ce696e05 | 2472 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2473 | struct inferior *inf = current_inferior (); |
c5aa993b | 2474 | |
39f77062 | 2475 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2476 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2477 | |
6c95b8df | 2478 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2479 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2480 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2481 | { |
35df4500 | 2482 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2483 | continue; |
2484 | ||
35df4500 TJB |
2485 | if (bl->inserted) |
2486 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2487 | } |
d03285ec UW |
2488 | |
2489 | /* Detach single-step breakpoints as well. */ | |
2490 | detach_single_step_breakpoints (); | |
2491 | ||
ce696e05 | 2492 | do_cleanups (old_chain); |
3a1bae8e | 2493 | return val; |
c906108c SS |
2494 | } |
2495 | ||
35df4500 | 2496 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2497 | Note that this is used to detach breakpoints from a child fork. |
2498 | When we get here, the child isn't in the inferior list, and neither | |
2499 | do we have objects to represent its address space --- we should | |
35df4500 | 2500 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2501 | |
c906108c | 2502 | static int |
35df4500 | 2503 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2504 | { |
2505 | int val; | |
c5aa993b | 2506 | |
35df4500 TJB |
2507 | /* BL is never in moribund_locations by our callers. */ |
2508 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2509 | |
35df4500 | 2510 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2511 | /* Permanent breakpoints cannot be inserted or removed. */ |
2512 | return 0; | |
2513 | ||
74960c60 VP |
2514 | /* The type of none suggests that owner is actually deleted. |
2515 | This should not ever happen. */ | |
35df4500 | 2516 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2517 | |
35df4500 TJB |
2518 | if (bl->loc_type == bp_loc_software_breakpoint |
2519 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2520 | { |
c02f5703 MS |
2521 | /* "Normal" instruction breakpoint: either the standard |
2522 | trap-instruction bp (bp_breakpoint), or a | |
2523 | bp_hardware_breakpoint. */ | |
2524 | ||
2525 | /* First check to see if we have to handle an overlay. */ | |
2526 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2527 | || bl->section == NULL |
2528 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2529 | { |
2530 | /* No overlay handling: just remove the breakpoint. */ | |
2531 | ||
35df4500 TJB |
2532 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2533 | val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
c02f5703 | 2534 | else |
35df4500 | 2535 | val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
c02f5703 | 2536 | } |
c906108c SS |
2537 | else |
2538 | { | |
4a64f543 | 2539 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2540 | Did we set a breakpoint at the LMA? */ |
2541 | if (!overlay_events_enabled) | |
2542 | { | |
2543 | /* Yes -- overlay event support is not active, so we | |
2544 | should have set a breakpoint at the LMA. Remove it. | |
2545 | */ | |
c02f5703 MS |
2546 | /* Ignore any failures: if the LMA is in ROM, we will |
2547 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2548 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2549 | target_remove_hw_breakpoint (bl->gdbarch, | |
2550 | &bl->overlay_target_info); | |
c02f5703 | 2551 | else |
35df4500 TJB |
2552 | target_remove_breakpoint (bl->gdbarch, |
2553 | &bl->overlay_target_info); | |
c02f5703 MS |
2554 | } |
2555 | /* Did we set a breakpoint at the VMA? | |
2556 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2557 | if (bl->inserted) |
c906108c | 2558 | { |
c02f5703 MS |
2559 | /* Yes -- remove it. Previously we did not bother to |
2560 | remove the breakpoint if the section had been | |
2561 | unmapped, but let's not rely on that being safe. We | |
2562 | don't know what the overlay manager might do. */ | |
35df4500 TJB |
2563 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2564 | val = target_remove_hw_breakpoint (bl->gdbarch, | |
2565 | &bl->target_info); | |
aa67235e UW |
2566 | |
2567 | /* However, we should remove *software* breakpoints only | |
2568 | if the section is still mapped, or else we overwrite | |
2569 | wrong code with the saved shadow contents. */ | |
35df4500 TJB |
2570 | else if (section_is_mapped (bl->section)) |
2571 | val = target_remove_breakpoint (bl->gdbarch, | |
2572 | &bl->target_info); | |
aa67235e UW |
2573 | else |
2574 | val = 0; | |
c906108c | 2575 | } |
c02f5703 MS |
2576 | else |
2577 | { | |
2578 | /* No -- not inserted, so no need to remove. No error. */ | |
2579 | val = 0; | |
2580 | } | |
c906108c | 2581 | } |
879d1e6b UW |
2582 | |
2583 | /* In some cases, we might not be able to remove a breakpoint | |
2584 | in a shared library that has already been removed, but we | |
2585 | have not yet processed the shlib unload event. */ | |
35df4500 | 2586 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2587 | val = 0; |
2588 | ||
c906108c SS |
2589 | if (val) |
2590 | return val; | |
35df4500 | 2591 | bl->inserted = (is == mark_inserted); |
c906108c | 2592 | } |
35df4500 | 2593 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2594 | { |
77b06cd7 TJB |
2595 | gdb_assert (bl->owner->ops != NULL |
2596 | && bl->owner->ops->remove_location != NULL); | |
2597 | ||
35df4500 | 2598 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2599 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2600 | |
c906108c | 2601 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2602 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2603 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2604 | bl->owner->number); |
c906108c | 2605 | } |
35df4500 TJB |
2606 | else if (bl->owner->type == bp_catchpoint |
2607 | && breakpoint_enabled (bl->owner) | |
2608 | && !bl->duplicate) | |
ce78b96d | 2609 | { |
77b06cd7 TJB |
2610 | gdb_assert (bl->owner->ops != NULL |
2611 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2612 | |
77b06cd7 | 2613 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2614 | if (val) |
2615 | return val; | |
77b06cd7 | 2616 | |
35df4500 | 2617 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2618 | } |
c906108c SS |
2619 | |
2620 | return 0; | |
2621 | } | |
2622 | ||
6c95b8df | 2623 | static int |
35df4500 | 2624 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2625 | { |
2626 | int ret; | |
2627 | struct cleanup *old_chain; | |
2628 | ||
35df4500 TJB |
2629 | /* BL is never in moribund_locations by our callers. */ |
2630 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2631 | |
35df4500 | 2632 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2633 | /* Permanent breakpoints cannot be inserted or removed. */ |
2634 | return 0; | |
2635 | ||
2636 | /* The type of none suggests that owner is actually deleted. | |
2637 | This should not ever happen. */ | |
35df4500 | 2638 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2639 | |
2640 | old_chain = save_current_space_and_thread (); | |
2641 | ||
35df4500 | 2642 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2643 | |
35df4500 | 2644 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2645 | |
2646 | do_cleanups (old_chain); | |
2647 | return ret; | |
2648 | } | |
2649 | ||
c906108c SS |
2650 | /* Clear the "inserted" flag in all breakpoints. */ |
2651 | ||
25b22b0a | 2652 | void |
fba45db2 | 2653 | mark_breakpoints_out (void) |
c906108c | 2654 | { |
35df4500 | 2655 | struct bp_location *bl, **blp_tmp; |
c906108c | 2656 | |
35df4500 TJB |
2657 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2658 | if (bl->pspace == current_program_space) | |
2659 | bl->inserted = 0; | |
c906108c SS |
2660 | } |
2661 | ||
53a5351d JM |
2662 | /* Clear the "inserted" flag in all breakpoints and delete any |
2663 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2664 | |
2665 | Plus other such housekeeping that has to be done for breakpoints | |
2666 | between runs. | |
2667 | ||
53a5351d JM |
2668 | Note: this function gets called at the end of a run (by |
2669 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2670 | init_wait_for_inferior). */ |
c906108c SS |
2671 | |
2672 | ||
2673 | ||
2674 | void | |
fba45db2 | 2675 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2676 | { |
35df4500 TJB |
2677 | struct breakpoint *b, *b_tmp; |
2678 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2679 | int ix; |
6c95b8df | 2680 | struct program_space *pspace = current_program_space; |
c906108c | 2681 | |
50c71eaf PA |
2682 | /* If breakpoint locations are shared across processes, then there's |
2683 | nothing to do. */ | |
2567c7d9 | 2684 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2685 | return; |
2686 | ||
35df4500 | 2687 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2688 | { |
35df4500 TJB |
2689 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2690 | if (bl->pspace == pspace | |
2691 | && bl->owner->enable_state != bp_permanent) | |
2692 | bl->inserted = 0; | |
6c95b8df | 2693 | } |
075f6582 | 2694 | |
35df4500 | 2695 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2696 | { |
6c95b8df PA |
2697 | if (b->loc && b->loc->pspace != pspace) |
2698 | continue; | |
2699 | ||
c5aa993b JM |
2700 | switch (b->type) |
2701 | { | |
2702 | case bp_call_dummy: | |
c906108c | 2703 | |
c5aa993b | 2704 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2705 | cause problems when the inferior is rerun, so we better get |
2706 | rid of it. */ | |
2707 | ||
2708 | case bp_watchpoint_scope: | |
2709 | ||
2710 | /* Also get rid of scope breakpoints. */ | |
2711 | ||
2712 | case bp_shlib_event: | |
2713 | ||
2714 | /* Also remove solib event breakpoints. Their addresses may | |
2715 | have changed since the last time we ran the program. | |
2716 | Actually we may now be debugging against different target; | |
2717 | and so the solib backend that installed this breakpoint may | |
2718 | not be used in by the target. E.g., | |
2719 | ||
2720 | (gdb) file prog-linux | |
2721 | (gdb) run # native linux target | |
2722 | ... | |
2723 | (gdb) kill | |
2724 | (gdb) file prog-win.exe | |
2725 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2726 | */ | |
c906108c | 2727 | |
c5aa993b JM |
2728 | delete_breakpoint (b); |
2729 | break; | |
c906108c | 2730 | |
c5aa993b JM |
2731 | case bp_watchpoint: |
2732 | case bp_hardware_watchpoint: | |
2733 | case bp_read_watchpoint: | |
2734 | case bp_access_watchpoint: | |
c906108c | 2735 | |
c5aa993b JM |
2736 | /* Likewise for watchpoints on local expressions. */ |
2737 | if (b->exp_valid_block != NULL) | |
2738 | delete_breakpoint (b); | |
967af18d | 2739 | else if (context == inf_starting) |
c860120c | 2740 | { |
4a64f543 MS |
2741 | /* Reset val field to force reread of starting value in |
2742 | insert_breakpoints. */ | |
c860120c PM |
2743 | if (b->val) |
2744 | value_free (b->val); | |
2745 | b->val = NULL; | |
fa4727a6 | 2746 | b->val_valid = 0; |
c860120c | 2747 | } |
c5aa993b JM |
2748 | break; |
2749 | default: | |
c5aa993b JM |
2750 | break; |
2751 | } | |
2752 | } | |
1c5cfe86 PA |
2753 | |
2754 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2755 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2756 | decref_bp_location (&bl); | |
1c5cfe86 | 2757 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2758 | } |
2759 | ||
6c95b8df PA |
2760 | /* These functions concern about actual breakpoints inserted in the |
2761 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2762 | we need to hop over the bkpt --- so we check for address space | |
2763 | match, not program space. */ | |
2764 | ||
c2c6d25f JM |
2765 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2766 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2767 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2768 | permanent breakpoint. | |
2769 | - When continuing from a location with an ordinary breakpoint, we | |
2770 | actually single step once before calling insert_breakpoints. | |
2771 | - When continuing from a localion with a permanent breakpoint, we | |
2772 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2773 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2774 | |
c2c6d25f | 2775 | enum breakpoint_here |
6c95b8df | 2776 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2777 | { |
35df4500 | 2778 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2779 | int any_breakpoint_here = 0; |
c906108c | 2780 | |
35df4500 | 2781 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2782 | { |
35df4500 TJB |
2783 | if (bl->loc_type != bp_loc_software_breakpoint |
2784 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2785 | continue; |
2786 | ||
35df4500 TJB |
2787 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2788 | if ((breakpoint_enabled (bl->owner) | |
2789 | || bl->owner->enable_state == bp_permanent) | |
2790 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2791 | aspace, pc)) |
075f6582 DJ |
2792 | { |
2793 | if (overlay_debugging | |
35df4500 TJB |
2794 | && section_is_overlay (bl->section) |
2795 | && !section_is_mapped (bl->section)) | |
075f6582 | 2796 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2797 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2798 | return permanent_breakpoint_here; |
2799 | else | |
2800 | any_breakpoint_here = 1; | |
2801 | } | |
2802 | } | |
c906108c | 2803 | |
c2c6d25f | 2804 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2805 | } |
2806 | ||
1c5cfe86 PA |
2807 | /* Return true if there's a moribund breakpoint at PC. */ |
2808 | ||
2809 | int | |
6c95b8df | 2810 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2811 | { |
2812 | struct bp_location *loc; | |
2813 | int ix; | |
2814 | ||
2815 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2816 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2817 | aspace, pc)) | |
1c5cfe86 PA |
2818 | return 1; |
2819 | ||
2820 | return 0; | |
2821 | } | |
c2c6d25f | 2822 | |
c36b740a | 2823 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2824 | inserted using regular breakpoint_chain / bp_location array |
2825 | mechanism. This does not check for single-step breakpoints, which | |
2826 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2827 | |
2828 | int | |
4a64f543 MS |
2829 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2830 | CORE_ADDR pc) | |
c906108c | 2831 | { |
35df4500 | 2832 | struct bp_location *bl, **blp_tmp; |
c906108c | 2833 | |
35df4500 | 2834 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2835 | { |
35df4500 TJB |
2836 | if (bl->loc_type != bp_loc_software_breakpoint |
2837 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2838 | continue; |
2839 | ||
35df4500 TJB |
2840 | if (bl->inserted |
2841 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2842 | aspace, pc)) |
075f6582 DJ |
2843 | { |
2844 | if (overlay_debugging | |
35df4500 TJB |
2845 | && section_is_overlay (bl->section) |
2846 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2847 | continue; /* unmapped overlay -- can't be a match */ |
2848 | else | |
2849 | return 1; | |
2850 | } | |
c5aa993b | 2851 | } |
c36b740a VP |
2852 | return 0; |
2853 | } | |
2854 | ||
2855 | /* Returns non-zero iff there's either regular breakpoint | |
2856 | or a single step breakpoint inserted at PC. */ | |
2857 | ||
2858 | int | |
6c95b8df | 2859 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2860 | { |
6c95b8df | 2861 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2862 | return 1; |
c906108c | 2863 | |
6c95b8df | 2864 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2865 | return 1; |
2866 | ||
c906108c SS |
2867 | return 0; |
2868 | } | |
2869 | ||
4fa8626c DJ |
2870 | /* This function returns non-zero iff there is a software breakpoint |
2871 | inserted at PC. */ | |
2872 | ||
2873 | int | |
3e43a32a MS |
2874 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2875 | CORE_ADDR pc) | |
4fa8626c | 2876 | { |
35df4500 | 2877 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2878 | |
35df4500 | 2879 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2880 | { |
35df4500 | 2881 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2882 | continue; |
2883 | ||
35df4500 TJB |
2884 | if (bl->inserted |
2885 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2886 | aspace, pc)) |
4fa8626c DJ |
2887 | { |
2888 | if (overlay_debugging | |
35df4500 TJB |
2889 | && section_is_overlay (bl->section) |
2890 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2891 | continue; /* unmapped overlay -- can't be a match */ |
2892 | else | |
2893 | return 1; | |
2894 | } | |
2895 | } | |
2896 | ||
1aafd4da | 2897 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2898 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2899 | return 1; |
2900 | ||
4fa8626c DJ |
2901 | return 0; |
2902 | } | |
2903 | ||
9093389c PA |
2904 | int |
2905 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2906 | CORE_ADDR addr, ULONGEST len) | |
2907 | { | |
2908 | struct breakpoint *bpt; | |
2909 | ||
2910 | ALL_BREAKPOINTS (bpt) | |
2911 | { | |
2912 | struct bp_location *loc; | |
2913 | ||
2914 | if (bpt->type != bp_hardware_watchpoint | |
2915 | && bpt->type != bp_access_watchpoint) | |
2916 | continue; | |
2917 | ||
2918 | if (!breakpoint_enabled (bpt)) | |
2919 | continue; | |
2920 | ||
2921 | for (loc = bpt->loc; loc; loc = loc->next) | |
2922 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2923 | { | |
2924 | CORE_ADDR l, h; | |
2925 | ||
2926 | /* Check for intersection. */ | |
2927 | l = max (loc->address, addr); | |
2928 | h = min (loc->address + loc->length, addr + len); | |
2929 | if (l < h) | |
2930 | return 1; | |
2931 | } | |
2932 | } | |
2933 | return 0; | |
2934 | } | |
2935 | ||
075f6582 DJ |
2936 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2937 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2938 | |
2939 | int | |
6c95b8df PA |
2940 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2941 | ptid_t ptid) | |
c906108c | 2942 | { |
35df4500 | 2943 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 2944 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2945 | int thread = -1; |
4a306c9a | 2946 | int task = 0; |
a6f1cd96 | 2947 | |
35df4500 | 2948 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2949 | { |
35df4500 TJB |
2950 | if (bl->loc_type != bp_loc_software_breakpoint |
2951 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2952 | continue; |
2953 | ||
35df4500 TJB |
2954 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2955 | if (!breakpoint_enabled (bl->owner) | |
2956 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
2957 | continue; |
2958 | ||
35df4500 | 2959 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
6c95b8df | 2960 | aspace, pc)) |
a6f1cd96 JB |
2961 | continue; |
2962 | ||
35df4500 | 2963 | if (bl->owner->thread != -1) |
075f6582 | 2964 | { |
a6f1cd96 JB |
2965 | /* This is a thread-specific breakpoint. Check that ptid |
2966 | matches that thread. If thread hasn't been computed yet, | |
2967 | it is now time to do so. */ | |
2968 | if (thread == -1) | |
2969 | thread = pid_to_thread_id (ptid); | |
35df4500 | 2970 | if (bl->owner->thread != thread) |
a6f1cd96 | 2971 | continue; |
075f6582 | 2972 | } |
a6f1cd96 | 2973 | |
35df4500 | 2974 | if (bl->owner->task != 0) |
4a306c9a JB |
2975 | { |
2976 | /* This is a task-specific breakpoint. Check that ptid | |
2977 | matches that task. If task hasn't been computed yet, | |
2978 | it is now time to do so. */ | |
2979 | if (task == 0) | |
2980 | task = ada_get_task_number (ptid); | |
35df4500 | 2981 | if (bl->owner->task != task) |
4a306c9a JB |
2982 | continue; |
2983 | } | |
2984 | ||
a6f1cd96 | 2985 | if (overlay_debugging |
35df4500 TJB |
2986 | && section_is_overlay (bl->section) |
2987 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
2988 | continue; /* unmapped overlay -- can't be a match */ |
2989 | ||
2990 | return 1; | |
c5aa993b | 2991 | } |
c906108c SS |
2992 | |
2993 | return 0; | |
2994 | } | |
c906108c | 2995 | \f |
c5aa993b | 2996 | |
c906108c SS |
2997 | /* bpstat stuff. External routines' interfaces are documented |
2998 | in breakpoint.h. */ | |
2999 | ||
3000 | int | |
fba45db2 | 3001 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3002 | { |
533be4dd | 3003 | return (ep->type == bp_catchpoint); |
c906108c SS |
3004 | } |
3005 | ||
f431efe5 PA |
3006 | /* Frees any storage that is part of a bpstat. Does not walk the |
3007 | 'next' chain. */ | |
3008 | ||
3009 | static void | |
198757a8 VP |
3010 | bpstat_free (bpstat bs) |
3011 | { | |
3012 | if (bs->old_val != NULL) | |
3013 | value_free (bs->old_val); | |
9add0f1b | 3014 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3015 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3016 | xfree (bs); |
3017 | } | |
3018 | ||
c906108c SS |
3019 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3020 | Also free any storage that is part of a bpstat. */ | |
3021 | ||
3022 | void | |
fba45db2 | 3023 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3024 | { |
3025 | bpstat p; | |
3026 | bpstat q; | |
3027 | ||
3028 | if (bsp == 0) | |
3029 | return; | |
3030 | p = *bsp; | |
3031 | while (p != NULL) | |
3032 | { | |
3033 | q = p->next; | |
198757a8 | 3034 | bpstat_free (p); |
c906108c SS |
3035 | p = q; |
3036 | } | |
3037 | *bsp = NULL; | |
3038 | } | |
3039 | ||
3040 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3041 | is part of the bpstat is copied as well. */ | |
3042 | ||
3043 | bpstat | |
fba45db2 | 3044 | bpstat_copy (bpstat bs) |
c906108c SS |
3045 | { |
3046 | bpstat p = NULL; | |
3047 | bpstat tmp; | |
3048 | bpstat retval = NULL; | |
3049 | ||
3050 | if (bs == NULL) | |
3051 | return bs; | |
3052 | ||
3053 | for (; bs != NULL; bs = bs->next) | |
3054 | { | |
3055 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3056 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3057 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3058 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3059 | if (bs->old_val != NULL) |
3c3185ac JK |
3060 | { |
3061 | tmp->old_val = value_copy (bs->old_val); | |
3062 | release_value (tmp->old_val); | |
3063 | } | |
31cc81e9 | 3064 | |
c906108c SS |
3065 | if (p == NULL) |
3066 | /* This is the first thing in the chain. */ | |
3067 | retval = tmp; | |
3068 | else | |
3069 | p->next = tmp; | |
3070 | p = tmp; | |
3071 | } | |
3072 | p->next = NULL; | |
3073 | return retval; | |
3074 | } | |
3075 | ||
4a64f543 | 3076 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3077 | |
3078 | bpstat | |
fba45db2 | 3079 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3080 | { |
c5aa993b JM |
3081 | if (bsp == NULL) |
3082 | return NULL; | |
c906108c | 3083 | |
c5aa993b JM |
3084 | for (; bsp != NULL; bsp = bsp->next) |
3085 | { | |
f431efe5 | 3086 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3087 | return bsp; |
3088 | } | |
c906108c SS |
3089 | return NULL; |
3090 | } | |
3091 | ||
4a64f543 MS |
3092 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3093 | stopped at. *BSP upon return is a bpstat which points to the | |
3094 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3095 | good for anything but further calls to bpstat_num). | |
3096 | ||
8671a17b PA |
3097 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3098 | Return -1 if stopped at a breakpoint that has been deleted since | |
3099 | we set it. | |
3100 | Return 1 otherwise. */ | |
c906108c SS |
3101 | |
3102 | int | |
8671a17b | 3103 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3104 | { |
3105 | struct breakpoint *b; | |
3106 | ||
3107 | if ((*bsp) == NULL) | |
3108 | return 0; /* No more breakpoint values */ | |
8671a17b | 3109 | |
4a64f543 MS |
3110 | /* We assume we'll never have several bpstats that correspond to a |
3111 | single breakpoint -- otherwise, this function might return the | |
3112 | same number more than once and this will look ugly. */ | |
f431efe5 | 3113 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3114 | *bsp = (*bsp)->next; |
3115 | if (b == NULL) | |
3116 | return -1; /* breakpoint that's been deleted since */ | |
3117 | ||
3118 | *num = b->number; /* We have its number */ | |
3119 | return 1; | |
c906108c SS |
3120 | } |
3121 | ||
3122 | /* Modify BS so that the actions will not be performed. */ | |
3123 | ||
3124 | void | |
fba45db2 | 3125 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3126 | { |
3127 | for (; bs != NULL; bs = bs->next) | |
3128 | { | |
9add0f1b | 3129 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3130 | bs->commands_left = NULL; |
c906108c SS |
3131 | if (bs->old_val != NULL) |
3132 | { | |
3133 | value_free (bs->old_val); | |
3134 | bs->old_val = NULL; | |
3135 | } | |
3136 | } | |
3137 | } | |
3138 | ||
f3b1572e PA |
3139 | /* Called when a command is about to proceed the inferior. */ |
3140 | ||
3141 | static void | |
3142 | breakpoint_about_to_proceed (void) | |
3143 | { | |
3144 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3145 | { | |
3146 | struct thread_info *tp = inferior_thread (); | |
3147 | ||
3148 | /* Allow inferior function calls in breakpoint commands to not | |
3149 | interrupt the command list. When the call finishes | |
3150 | successfully, the inferior will be standing at the same | |
3151 | breakpoint as if nothing happened. */ | |
16c381f0 | 3152 | if (tp->control.in_infcall) |
f3b1572e PA |
3153 | return; |
3154 | } | |
3155 | ||
3156 | breakpoint_proceeded = 1; | |
3157 | } | |
3158 | ||
4a64f543 MS |
3159 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3160 | command. */ | |
c906108c | 3161 | static void |
4efb68b1 | 3162 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3163 | { |
3164 | executing_breakpoint_commands = 0; | |
3165 | } | |
3166 | ||
4a64f543 MS |
3167 | /* Execute all the commands associated with all the breakpoints at |
3168 | this location. Any of these commands could cause the process to | |
3169 | proceed beyond this point, etc. We look out for such changes by | |
3170 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3171 | |
347bddb7 PA |
3172 | Returns true if a breakpoint command resumed the inferior. In that |
3173 | case, it is the caller's responsibility to recall it again with the | |
3174 | bpstat of the current thread. */ | |
3175 | ||
3176 | static int | |
3177 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3178 | { |
3179 | bpstat bs; | |
3180 | struct cleanup *old_chain; | |
347bddb7 | 3181 | int again = 0; |
c906108c SS |
3182 | |
3183 | /* Avoid endless recursion if a `source' command is contained | |
3184 | in bs->commands. */ | |
3185 | if (executing_breakpoint_commands) | |
347bddb7 | 3186 | return 0; |
c906108c SS |
3187 | |
3188 | executing_breakpoint_commands = 1; | |
3189 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3190 | ||
4a64f543 | 3191 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3192 | bs = *bsp; |
3193 | ||
3194 | breakpoint_proceeded = 0; | |
3195 | for (; bs != NULL; bs = bs->next) | |
3196 | { | |
9add0f1b | 3197 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3198 | struct command_line *cmd; |
3199 | struct cleanup *this_cmd_tree_chain; | |
3200 | ||
3201 | /* Take ownership of the BSP's command tree, if it has one. | |
3202 | ||
3203 | The command tree could legitimately contain commands like | |
3204 | 'step' and 'next', which call clear_proceed_status, which | |
3205 | frees stop_bpstat's command tree. To make sure this doesn't | |
3206 | free the tree we're executing out from under us, we need to | |
3207 | take ownership of the tree ourselves. Since a given bpstat's | |
3208 | commands are only executed once, we don't need to copy it; we | |
3209 | can clear the pointer in the bpstat, and make sure we free | |
3210 | the tree when we're done. */ | |
9add0f1b TT |
3211 | ccmd = bs->commands; |
3212 | bs->commands = NULL; | |
3213 | this_cmd_tree_chain | |
3214 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3215 | cmd = bs->commands_left; | |
3216 | bs->commands_left = NULL; | |
6c50ab1c | 3217 | |
c906108c SS |
3218 | while (cmd != NULL) |
3219 | { | |
3220 | execute_control_command (cmd); | |
3221 | ||
3222 | if (breakpoint_proceeded) | |
3223 | break; | |
3224 | else | |
3225 | cmd = cmd->next; | |
3226 | } | |
6c50ab1c JB |
3227 | |
3228 | /* We can free this command tree now. */ | |
3229 | do_cleanups (this_cmd_tree_chain); | |
3230 | ||
c906108c | 3231 | if (breakpoint_proceeded) |
32c1e744 VP |
3232 | { |
3233 | if (target_can_async_p ()) | |
347bddb7 PA |
3234 | /* If we are in async mode, then the target might be still |
3235 | running, not stopped at any breakpoint, so nothing for | |
3236 | us to do here -- just return to the event loop. */ | |
3237 | ; | |
32c1e744 VP |
3238 | else |
3239 | /* In sync mode, when execute_control_command returns | |
3240 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3241 | Breakpoint commands for that stop were not run, since |
3242 | execute_command does not run breakpoint commands -- | |
3243 | only command_line_handler does, but that one is not | |
3244 | involved in execution of breakpoint commands. So, we | |
3245 | can now execute breakpoint commands. It should be | |
3246 | noted that making execute_command do bpstat actions is | |
3247 | not an option -- in this case we'll have recursive | |
3248 | invocation of bpstat for each breakpoint with a | |
3249 | command, and can easily blow up GDB stack. Instead, we | |
3250 | return true, which will trigger the caller to recall us | |
3251 | with the new stop_bpstat. */ | |
3252 | again = 1; | |
3253 | break; | |
32c1e744 | 3254 | } |
c906108c | 3255 | } |
c2b8ed2c | 3256 | do_cleanups (old_chain); |
347bddb7 PA |
3257 | return again; |
3258 | } | |
3259 | ||
3260 | void | |
3261 | bpstat_do_actions (void) | |
3262 | { | |
3263 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3264 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3265 | && target_has_execution | |
3266 | && !is_exited (inferior_ptid) | |
3267 | && !is_executing (inferior_ptid)) | |
3268 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3269 | and only return when it is stopped at the next breakpoint, we | |
3270 | keep doing breakpoint actions until it returns false to | |
3271 | indicate the inferior was not resumed. */ | |
16c381f0 | 3272 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3273 | break; |
c906108c SS |
3274 | } |
3275 | ||
fa4727a6 DJ |
3276 | /* Print out the (old or new) value associated with a watchpoint. */ |
3277 | ||
3278 | static void | |
3279 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3280 | { | |
3281 | if (val == NULL) | |
3282 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3283 | else | |
79a45b7d TT |
3284 | { |
3285 | struct value_print_options opts; | |
3286 | get_user_print_options (&opts); | |
3287 | value_print (val, stream, &opts); | |
3288 | } | |
fa4727a6 DJ |
3289 | } |
3290 | ||
e514a9d6 | 3291 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3292 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3293 | by having it set different print_it values. |
3294 | ||
3295 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3296 | through the bpstat list of things causing this stop, calling the | |
4a64f543 | 3297 | print_bp_stop_message function on each one. The behavior of the |
e514a9d6 | 3298 | print_bp_stop_message function depends on the print_it field of |
4a64f543 | 3299 | bpstat. If such field so indicates, call this function here. |
e514a9d6 JM |
3300 | |
3301 | Return values from this routine (ultimately used by bpstat_print() | |
3302 | and normal_stop() to decide what to do): | |
3303 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3304 | don't print anything else. | |
3305 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3306 | that something to be followed by a location. | |
3307 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3308 | that something to be followed by a location. | |
3309 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3310 | analysis. */ | |
c906108c | 3311 | |
917317f4 | 3312 | static enum print_stop_action |
fba45db2 | 3313 | print_it_typical (bpstat bs) |
c906108c | 3314 | { |
f7545552 | 3315 | struct cleanup *old_chain; |
4f8d1dc6 | 3316 | struct breakpoint *b; |
89f9893c | 3317 | const struct bp_location *bl; |
8b93c638 | 3318 | struct ui_stream *stb; |
f7545552 TT |
3319 | int bp_temp = 0; |
3320 | enum print_stop_action result; | |
3321 | ||
f431efe5 PA |
3322 | gdb_assert (bs->bp_location_at != NULL); |
3323 | ||
3324 | bl = bs->bp_location_at; | |
3325 | b = bs->breakpoint_at; | |
c906108c | 3326 | |
f7545552 TT |
3327 | stb = ui_out_stream_new (uiout); |
3328 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3329 | ||
4f8d1dc6 | 3330 | switch (b->type) |
c906108c | 3331 | { |
e514a9d6 JM |
3332 | case bp_breakpoint: |
3333 | case bp_hardware_breakpoint: | |
f431efe5 | 3334 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3335 | if (bl->address != bl->requested_address) |
3336 | breakpoint_adjustment_warning (bl->requested_address, | |
3337 | bl->address, | |
4f8d1dc6 VP |
3338 | b->number, 1); |
3339 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3340 | if (bp_temp) |
3341 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3342 | else | |
3343 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3344 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3345 | { |
3346 | ui_out_field_string (uiout, "reason", | |
3347 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3348 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3349 | } | |
4f8d1dc6 | 3350 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3351 | ui_out_text (uiout, ", "); |
f7545552 | 3352 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3353 | break; |
3354 | ||
3355 | case bp_shlib_event: | |
917317f4 JM |
3356 | /* Did we stop because the user set the stop_on_solib_events |
3357 | variable? (If so, we report this as a generic, "Stopped due | |
3358 | to shlib event" message.) */ | |
a3f17187 | 3359 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3360 | result = PRINT_NOTHING; |
e514a9d6 JM |
3361 | break; |
3362 | ||
c4093a6a | 3363 | case bp_thread_event: |
4a64f543 | 3364 | /* Not sure how we will get here. |
c4093a6a | 3365 | GDB should not stop for these breakpoints. */ |
a3f17187 | 3366 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3367 | result = PRINT_NOTHING; |
c4093a6a JM |
3368 | break; |
3369 | ||
1900040c | 3370 | case bp_overlay_event: |
4a64f543 | 3371 | /* By analogy with the thread event, GDB should not stop for these. */ |
a3f17187 | 3372 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3373 | result = PRINT_NOTHING; |
1900040c MS |
3374 | break; |
3375 | ||
0fd8e87f UW |
3376 | case bp_longjmp_master: |
3377 | /* These should never be enabled. */ | |
3378 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3379 | result = PRINT_NOTHING; | |
3380 | break; | |
3381 | ||
aa7d318d TT |
3382 | case bp_std_terminate_master: |
3383 | /* These should never be enabled. */ | |
3e43a32a MS |
3384 | printf_filtered (_("std::terminate Master Breakpoint: " |
3385 | "gdb should not stop!\n")); | |
aa7d318d TT |
3386 | result = PRINT_NOTHING; |
3387 | break; | |
3388 | ||
186c406b TT |
3389 | case bp_exception_master: |
3390 | /* These should never be enabled. */ | |
3e43a32a MS |
3391 | printf_filtered (_("Exception Master Breakpoint: " |
3392 | "gdb should not stop!\n")); | |
186c406b TT |
3393 | result = PRINT_NOTHING; |
3394 | break; | |
3395 | ||
e514a9d6 JM |
3396 | case bp_watchpoint: |
3397 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3398 | annotate_watchpoint (b->number); |
3399 | if (ui_out_is_mi_like_p (uiout)) | |
3400 | ui_out_field_string | |
3401 | (uiout, "reason", | |
3402 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3403 | mention (b); | |
f7545552 | 3404 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3405 | ui_out_text (uiout, "\nOld value = "); |
3406 | watchpoint_value_print (bs->old_val, stb->stream); | |
3407 | ui_out_field_stream (uiout, "old", stb); | |
3408 | ui_out_text (uiout, "\nNew value = "); | |
3409 | watchpoint_value_print (b->val, stb->stream); | |
3410 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3411 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3412 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3413 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3414 | break; |
3415 | ||
3416 | case bp_read_watchpoint: | |
9dc5e2a9 | 3417 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3418 | ui_out_field_string |
3419 | (uiout, "reason", | |
3420 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3421 | mention (b); |
f7545552 | 3422 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3423 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3424 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3425 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3426 | ui_out_text (uiout, "\n"); |
f7545552 | 3427 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3428 | break; |
3429 | ||
3430 | case bp_access_watchpoint: | |
fa4727a6 | 3431 | if (bs->old_val != NULL) |
8b93c638 | 3432 | { |
4f8d1dc6 | 3433 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3434 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3435 | ui_out_field_string |
3436 | (uiout, "reason", | |
3437 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3438 | mention (b); |
f7545552 | 3439 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3440 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3441 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3442 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3443 | ui_out_text (uiout, "\nNew value = "); |
3444 | } | |
3445 | else | |
3446 | { | |
4f8d1dc6 | 3447 | mention (b); |
9dc5e2a9 | 3448 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3449 | ui_out_field_string |
3450 | (uiout, "reason", | |
3451 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3452 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3453 | ui_out_text (uiout, "\nValue = "); |
3454 | } | |
fa4727a6 | 3455 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3456 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3457 | ui_out_text (uiout, "\n"); |
f7545552 | 3458 | result = PRINT_UNKNOWN; |
e514a9d6 | 3459 | break; |
4ce44c66 | 3460 | |
e514a9d6 | 3461 | /* Fall through, we don't deal with these types of breakpoints |
4a64f543 | 3462 | here. */ |
e514a9d6 | 3463 | |
11cf8741 | 3464 | case bp_finish: |
9dc5e2a9 | 3465 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3466 | ui_out_field_string |
3467 | (uiout, "reason", | |
3468 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3469 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3470 | break; |
3471 | ||
e514a9d6 | 3472 | case bp_until: |
9dc5e2a9 | 3473 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3474 | ui_out_field_string |
3475 | (uiout, "reason", | |
3476 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3477 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3478 | break; |
3479 | ||
c2d11a7d | 3480 | case bp_none: |
e514a9d6 JM |
3481 | case bp_longjmp: |
3482 | case bp_longjmp_resume: | |
186c406b TT |
3483 | case bp_exception: |
3484 | case bp_exception_resume: | |
e514a9d6 | 3485 | case bp_step_resume: |
e514a9d6 JM |
3486 | case bp_watchpoint_scope: |
3487 | case bp_call_dummy: | |
aa7d318d | 3488 | case bp_std_terminate: |
1042e4c0 | 3489 | case bp_tracepoint: |
7a697b8d | 3490 | case bp_fast_tracepoint: |
4efc6507 | 3491 | case bp_jit_event: |
e514a9d6 | 3492 | default: |
f7545552 TT |
3493 | result = PRINT_UNKNOWN; |
3494 | break; | |
e514a9d6 | 3495 | } |
f7545552 TT |
3496 | |
3497 | do_cleanups (old_chain); | |
3498 | return result; | |
e514a9d6 JM |
3499 | } |
3500 | ||
3501 | /* Generic routine for printing messages indicating why we | |
4a64f543 | 3502 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3503 | 'print_it' in the bpstat structure. Under some circumstances we |
3504 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3505 | normal_stop(). */ |
e514a9d6 JM |
3506 | |
3507 | static enum print_stop_action | |
3508 | print_bp_stop_message (bpstat bs) | |
3509 | { | |
3510 | switch (bs->print_it) | |
3511 | { | |
3512 | case print_it_noop: | |
4a64f543 | 3513 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3514 | return PRINT_UNKNOWN; |
3515 | break; | |
3516 | ||
3517 | case print_it_done: | |
3518 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3519 | relevant messages. */ |
e514a9d6 JM |
3520 | return PRINT_SRC_AND_LOC; |
3521 | break; | |
3522 | ||
3523 | case print_it_normal: | |
4f8d1dc6 | 3524 | { |
f431efe5 PA |
3525 | struct breakpoint *b = bs->breakpoint_at; |
3526 | ||
1a6a67de TJB |
3527 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3528 | which has since been deleted. */ | |
3529 | if (b == NULL) | |
3530 | return PRINT_UNKNOWN; | |
3531 | ||
4f8d1dc6 VP |
3532 | /* Normal case. Call the breakpoint's print_it method, or |
3533 | print_it_typical. */ | |
1a6a67de | 3534 | if (b->ops != NULL && b->ops->print_it != NULL) |
4f8d1dc6 VP |
3535 | return b->ops->print_it (b); |
3536 | else | |
3537 | return print_it_typical (bs); | |
3538 | } | |
3539 | break; | |
3086aeae | 3540 | |
e514a9d6 | 3541 | default: |
8e65ff28 | 3542 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3543 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3544 | break; |
c906108c | 3545 | } |
c906108c SS |
3546 | } |
3547 | ||
e514a9d6 JM |
3548 | /* Print a message indicating what happened. This is called from |
3549 | normal_stop(). The input to this routine is the head of the bpstat | |
3550 | list - a list of the eventpoints that caused this stop. This | |
3551 | routine calls the generic print routine for printing a message | |
3552 | about reasons for stopping. This will print (for example) the | |
3553 | "Breakpoint n," part of the output. The return value of this | |
3554 | routine is one of: | |
c906108c | 3555 | |
4a64f543 | 3556 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3557 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3558 | code to print the location. An example is |
c5aa993b JM |
3559 | "Breakpoint 1, " which should be followed by |
3560 | the location. | |
917317f4 | 3561 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3562 | to also print the location part of the message. |
3563 | An example is the catch/throw messages, which | |
4a64f543 | 3564 | don't require a location appended to the end. |
917317f4 | 3565 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3566 | further info to be printed. */ |
c906108c | 3567 | |
917317f4 | 3568 | enum print_stop_action |
fba45db2 | 3569 | bpstat_print (bpstat bs) |
c906108c SS |
3570 | { |
3571 | int val; | |
c5aa993b | 3572 | |
c906108c | 3573 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3574 | (Currently all watchpoints go on the bpstat whether hit or not. |
3575 | That probably could (should) be changed, provided care is taken | |
c906108c | 3576 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3577 | for (; bs; bs = bs->next) |
3578 | { | |
3579 | val = print_bp_stop_message (bs); | |
3580 | if (val == PRINT_SRC_ONLY | |
3581 | || val == PRINT_SRC_AND_LOC | |
3582 | || val == PRINT_NOTHING) | |
3583 | return val; | |
3584 | } | |
c906108c | 3585 | |
e514a9d6 | 3586 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3587 | with and nothing was printed. */ |
917317f4 | 3588 | return PRINT_UNKNOWN; |
c906108c SS |
3589 | } |
3590 | ||
4a64f543 MS |
3591 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3592 | used inside a catch_errors to evaluate the breakpoint condition. | |
3593 | The argument is a "struct expression *" that has been cast to a | |
3594 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3595 | |
3596 | static int | |
4efb68b1 | 3597 | breakpoint_cond_eval (void *exp) |
c906108c | 3598 | { |
278cd55f | 3599 | struct value *mark = value_mark (); |
c5aa993b | 3600 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3601 | |
c906108c SS |
3602 | value_free_to_mark (mark); |
3603 | return i; | |
3604 | } | |
3605 | ||
5760d0ab | 3606 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3607 | |
3608 | static bpstat | |
5760d0ab | 3609 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3610 | { |
3611 | bpstat bs; | |
3612 | ||
3613 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3614 | bs->next = NULL; |
3615 | **bs_link_pointer = bs; | |
3616 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3617 | bs->breakpoint_at = bl->owner; |
3618 | bs->bp_location_at = bl; | |
3619 | incref_bp_location (bl); | |
c906108c SS |
3620 | /* If the condition is false, etc., don't do the commands. */ |
3621 | bs->commands = NULL; | |
9add0f1b | 3622 | bs->commands_left = NULL; |
c906108c SS |
3623 | bs->old_val = NULL; |
3624 | bs->print_it = print_it_normal; | |
3625 | return bs; | |
3626 | } | |
3627 | \f | |
d983da9c DJ |
3628 | /* The target has stopped with waitstatus WS. Check if any hardware |
3629 | watchpoints have triggered, according to the target. */ | |
3630 | ||
3631 | int | |
3632 | watchpoints_triggered (struct target_waitstatus *ws) | |
3633 | { | |
d92524f1 | 3634 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3635 | CORE_ADDR addr; |
3636 | struct breakpoint *b; | |
3637 | ||
3638 | if (!stopped_by_watchpoint) | |
3639 | { | |
3640 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3641 | as not triggered. */ | |
3642 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3643 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3644 | b->watchpoint_triggered = watch_triggered_no; |
3645 | ||
3646 | return 0; | |
3647 | } | |
3648 | ||
3649 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3650 | { | |
3651 | /* We were stopped by a watchpoint, but we don't know where. | |
3652 | Mark all watchpoints as unknown. */ | |
3653 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3654 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3655 | b->watchpoint_triggered = watch_triggered_unknown; |
3656 | ||
3657 | return stopped_by_watchpoint; | |
3658 | } | |
3659 | ||
3660 | /* The target could report the data address. Mark watchpoints | |
3661 | affected by this data address as triggered, and all others as not | |
3662 | triggered. */ | |
3663 | ||
3664 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3665 | if (is_hardware_watchpoint (b)) |
d983da9c | 3666 | { |
a5606eee | 3667 | struct bp_location *loc; |
d983da9c DJ |
3668 | |
3669 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3670 | for (loc = b->loc; loc; loc = loc->next) |
3671 | /* Exact match not required. Within range is | |
3672 | sufficient. */ | |
5009afc5 AS |
3673 | if (target_watchpoint_addr_within_range (¤t_target, |
3674 | addr, loc->address, | |
3675 | loc->length)) | |
a5606eee VP |
3676 | { |
3677 | b->watchpoint_triggered = watch_triggered_yes; | |
3678 | break; | |
3679 | } | |
d983da9c DJ |
3680 | } |
3681 | ||
3682 | return 1; | |
3683 | } | |
3684 | ||
c906108c SS |
3685 | /* Possible return values for watchpoint_check (this can't be an enum |
3686 | because of check_errors). */ | |
3687 | /* The watchpoint has been deleted. */ | |
3688 | #define WP_DELETED 1 | |
3689 | /* The value has changed. */ | |
3690 | #define WP_VALUE_CHANGED 2 | |
3691 | /* The value has not changed. */ | |
3692 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3693 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3694 | #define WP_IGNORE 4 | |
c906108c SS |
3695 | |
3696 | #define BP_TEMPFLAG 1 | |
3697 | #define BP_HARDWAREFLAG 2 | |
3698 | ||
4a64f543 MS |
3699 | /* Evaluate watchpoint condition expression and check if its value |
3700 | changed. | |
553e4c11 JB |
3701 | |
3702 | P should be a pointer to struct bpstat, but is defined as a void * | |
3703 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3704 | |
3705 | static int | |
4efb68b1 | 3706 | watchpoint_check (void *p) |
c906108c SS |
3707 | { |
3708 | bpstat bs = (bpstat) p; | |
3709 | struct breakpoint *b; | |
3710 | struct frame_info *fr; | |
3711 | int within_current_scope; | |
3712 | ||
f431efe5 | 3713 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3714 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3715 | b = bs->breakpoint_at; |
c906108c | 3716 | |
f6bc2008 PA |
3717 | /* If this is a local watchpoint, we only want to check if the |
3718 | watchpoint frame is in scope if the current thread is the thread | |
3719 | that was used to create the watchpoint. */ | |
3720 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3721 | return WP_IGNORE; |
f6bc2008 | 3722 | |
c906108c SS |
3723 | if (b->exp_valid_block == NULL) |
3724 | within_current_scope = 1; | |
3725 | else | |
3726 | { | |
edb3359d DJ |
3727 | struct frame_info *frame = get_current_frame (); |
3728 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3729 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3730 | ||
4a64f543 MS |
3731 | /* in_function_epilogue_p() returns a non-zero value if we're |
3732 | still in the function but the stack frame has already been | |
3733 | invalidated. Since we can't rely on the values of local | |
3734 | variables after the stack has been destroyed, we are treating | |
3735 | the watchpoint in that state as `not changed' without further | |
3736 | checking. Don't mark watchpoints as changed if the current | |
3737 | frame is in an epilogue - even if they are in some other | |
3738 | frame, our view of the stack is likely to be wrong and | |
3739 | frame_find_by_id could error out. */ | |
a0f49112 | 3740 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3741 | return WP_IGNORE; |
a0f49112 | 3742 | |
101dcfbe | 3743 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3744 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3745 | |
3746 | /* If we've gotten confused in the unwinder, we might have | |
3747 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3748 | if (within_current_scope) |
3749 | { | |
3750 | struct symbol *function; | |
3751 | ||
3752 | function = get_frame_function (fr); | |
3753 | if (function == NULL | |
3754 | || !contained_in (b->exp_valid_block, | |
3755 | SYMBOL_BLOCK_VALUE (function))) | |
3756 | within_current_scope = 0; | |
3757 | } | |
69fbadd5 | 3758 | |
edb3359d | 3759 | if (within_current_scope) |
c906108c SS |
3760 | /* If we end up stopping, the current frame will get selected |
3761 | in normal_stop. So this call to select_frame won't affect | |
3762 | the user. */ | |
0f7d239c | 3763 | select_frame (fr); |
c906108c | 3764 | } |
c5aa993b | 3765 | |
c906108c SS |
3766 | if (within_current_scope) |
3767 | { | |
4a64f543 MS |
3768 | /* We use value_{,free_to_}mark because it could be a *long* |
3769 | time before we return to the command level and call | |
3770 | free_all_values. We can't call free_all_values because we | |
3771 | might be in the middle of evaluating a function call. */ | |
c906108c | 3772 | |
0cf6dd15 | 3773 | int pc = 0; |
278cd55f | 3774 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3775 | struct value *new_val; |
3776 | ||
0cf6dd15 | 3777 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3778 | |
4a64f543 MS |
3779 | /* We use value_equal_contents instead of value_equal because |
3780 | the latter coerces an array to a pointer, thus comparing just | |
3781 | the address of the array instead of its contents. This is | |
3782 | not what we want. */ | |
fa4727a6 | 3783 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3784 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3785 | { |
fa4727a6 DJ |
3786 | if (new_val != NULL) |
3787 | { | |
3788 | release_value (new_val); | |
3789 | value_free_to_mark (mark); | |
3790 | } | |
c906108c SS |
3791 | bs->old_val = b->val; |
3792 | b->val = new_val; | |
fa4727a6 | 3793 | b->val_valid = 1; |
c906108c SS |
3794 | return WP_VALUE_CHANGED; |
3795 | } | |
3796 | else | |
3797 | { | |
60e1c644 | 3798 | /* Nothing changed. */ |
c906108c | 3799 | value_free_to_mark (mark); |
c906108c SS |
3800 | return WP_VALUE_NOT_CHANGED; |
3801 | } | |
3802 | } | |
3803 | else | |
3804 | { | |
3805 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3806 | if we temporarily ignored the watchpoint, then when |
3807 | we reenter the block in which it is valid it contains | |
3808 | garbage (in the case of a function, it may have two | |
3809 | garbage values, one before and one after the prologue). | |
3810 | So we can't even detect the first assignment to it and | |
3811 | watch after that (since the garbage may or may not equal | |
3812 | the first value assigned). */ | |
4ce44c66 JM |
3813 | /* We print all the stop information in print_it_typical(), but |
3814 | in this case, by the time we call print_it_typical() this bp | |
4a64f543 MS |
3815 | will be deleted already. So we have no choice but print the |
3816 | information here. */ | |
9dc5e2a9 | 3817 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3818 | ui_out_field_string |
3819 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3820 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3821 | ui_out_field_int (uiout, "wpnum", b->number); |
3e43a32a MS |
3822 | ui_out_text (uiout, |
3823 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3824 | which its expression is valid.\n"); |
4ce44c66 | 3825 | |
c906108c | 3826 | if (b->related_breakpoint) |
60e1c644 PA |
3827 | { |
3828 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3829 | b->related_breakpoint->related_breakpoint = NULL; | |
3830 | b->related_breakpoint = NULL; | |
3831 | } | |
b5de0fa7 | 3832 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3833 | |
3834 | return WP_DELETED; | |
3835 | } | |
3836 | } | |
3837 | ||
18a18393 VP |
3838 | /* Return true if it looks like target has stopped due to hitting |
3839 | breakpoint location BL. This function does not check if we | |
3840 | should stop, only if BL explains the stop. */ | |
3841 | static int | |
6c95b8df PA |
3842 | bpstat_check_location (const struct bp_location *bl, |
3843 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3844 | { |
3845 | struct breakpoint *b = bl->owner; | |
3846 | ||
2bdf28a0 JK |
3847 | /* BL is from existing struct breakpoint. */ |
3848 | gdb_assert (b != NULL); | |
3849 | ||
e8595ef6 SS |
3850 | /* By definition, the inferior does not report stops at |
3851 | tracepoints. */ | |
d77f58be | 3852 | if (is_tracepoint (b)) |
e8595ef6 SS |
3853 | return 0; |
3854 | ||
cc60f2e3 | 3855 | if (!is_watchpoint (b) |
18a18393 | 3856 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3857 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3858 | { |
6c95b8df PA |
3859 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3860 | aspace, bp_addr)) | |
18a18393 VP |
3861 | return 0; |
3862 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3863 | && section_is_overlay (bl->section) |
18a18393 VP |
3864 | && !section_is_mapped (bl->section)) |
3865 | return 0; | |
3866 | } | |
cc60f2e3 | 3867 | |
18a18393 VP |
3868 | /* Continuable hardware watchpoints are treated as non-existent if the |
3869 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3870 | some data address). Otherwise gdb won't stop on a break instruction | |
3871 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3872 | been defined. Also skip watchpoints which we know did not trigger | |
3873 | (did not match the data address). */ | |
cc60f2e3 PA |
3874 | |
3875 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3876 | && b->watchpoint_triggered == watch_triggered_no) |
3877 | return 0; | |
3878 | ||
3879 | if (b->type == bp_hardware_breakpoint) | |
3880 | { | |
3881 | if (bl->address != bp_addr) | |
3882 | return 0; | |
3883 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3884 | && section_is_overlay (bl->section) |
18a18393 VP |
3885 | && !section_is_mapped (bl->section)) |
3886 | return 0; | |
3887 | } | |
ce78b96d | 3888 | |
ce78b96d JB |
3889 | if (b->type == bp_catchpoint) |
3890 | { | |
3891 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3892 | if (!b->ops->breakpoint_hit (b)) | |
3893 | return 0; | |
3894 | } | |
3895 | ||
18a18393 VP |
3896 | return 1; |
3897 | } | |
3898 | ||
3899 | /* If BS refers to a watchpoint, determine if the watched values | |
3900 | has actually changed, and we should stop. If not, set BS->stop | |
3901 | to 0. */ | |
3902 | static void | |
3903 | bpstat_check_watchpoint (bpstat bs) | |
3904 | { | |
2bdf28a0 JK |
3905 | const struct bp_location *bl; |
3906 | struct breakpoint *b; | |
3907 | ||
3908 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3909 | bl = bs->bp_location_at; |
2bdf28a0 | 3910 | gdb_assert (bl != NULL); |
f431efe5 | 3911 | b = bs->breakpoint_at; |
2bdf28a0 | 3912 | gdb_assert (b != NULL); |
18a18393 | 3913 | |
cc60f2e3 | 3914 | if (is_watchpoint (b)) |
18a18393 | 3915 | { |
18a18393 VP |
3916 | int must_check_value = 0; |
3917 | ||
3918 | if (b->type == bp_watchpoint) | |
3919 | /* For a software watchpoint, we must always check the | |
3920 | watched value. */ | |
3921 | must_check_value = 1; | |
3922 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3923 | /* We have a hardware watchpoint (read, write, or access) | |
3924 | and the target earlier reported an address watched by | |
3925 | this watchpoint. */ | |
3926 | must_check_value = 1; | |
3927 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3928 | && b->type == bp_hardware_watchpoint) | |
3929 | /* We were stopped by a hardware watchpoint, but the target could | |
3930 | not report the data address. We must check the watchpoint's | |
3931 | value. Access and read watchpoints are out of luck; without | |
3932 | a data address, we can't figure it out. */ | |
3933 | must_check_value = 1; | |
3934 | ||
3935 | if (must_check_value) | |
3936 | { | |
3e43a32a MS |
3937 | char *message |
3938 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3939 | b->number); | |
18a18393 VP |
3940 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3941 | int e = catch_errors (watchpoint_check, bs, message, | |
3942 | RETURN_MASK_ALL); | |
3943 | do_cleanups (cleanups); | |
3944 | switch (e) | |
3945 | { | |
3946 | case WP_DELETED: | |
3947 | /* We've already printed what needs to be printed. */ | |
3948 | bs->print_it = print_it_done; | |
3949 | /* Stop. */ | |
3950 | break; | |
60e1c644 PA |
3951 | case WP_IGNORE: |
3952 | bs->print_it = print_it_noop; | |
3953 | bs->stop = 0; | |
3954 | break; | |
18a18393 VP |
3955 | case WP_VALUE_CHANGED: |
3956 | if (b->type == bp_read_watchpoint) | |
3957 | { | |
85d721b8 PA |
3958 | /* There are two cases to consider here: |
3959 | ||
4a64f543 | 3960 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3961 | In that case, trust the target, and always report |
3962 | the watchpoint hit to the user. Even though | |
3963 | reads don't cause value changes, the value may | |
3964 | have changed since the last time it was read, and | |
3965 | since we're not trapping writes, we will not see | |
3966 | those, and as such we should ignore our notion of | |
3967 | old value. | |
3968 | ||
4a64f543 | 3969 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3970 | reads and writes. There are two ways this may |
3971 | happen: | |
3972 | ||
4a64f543 | 3973 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3974 | reads only, but can break on accesses (reads or |
3975 | writes), such as e.g., x86. We detect this case | |
3976 | at the time we try to insert read watchpoints. | |
3977 | ||
4a64f543 | 3978 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3979 | watchpoints, but, the user set an access or write |
3980 | watchpoint watching the same memory as this read | |
3981 | watchpoint. | |
3982 | ||
3983 | If we're watching memory writes as well as reads, | |
3984 | ignore watchpoint hits when we find that the | |
3985 | value hasn't changed, as reads don't cause | |
3986 | changes. This still gives false positives when | |
3987 | the program writes the same value to memory as | |
3988 | what there was already in memory (we will confuse | |
3989 | it for a read), but it's much better than | |
3990 | nothing. */ | |
3991 | ||
3992 | int other_write_watchpoint = 0; | |
3993 | ||
3994 | if (bl->watchpoint_type == hw_read) | |
3995 | { | |
3996 | struct breakpoint *other_b; | |
3997 | ||
3998 | ALL_BREAKPOINTS (other_b) | |
3999 | if ((other_b->type == bp_hardware_watchpoint | |
4000 | || other_b->type == bp_access_watchpoint) | |
4001 | && (other_b->watchpoint_triggered | |
4002 | == watch_triggered_yes)) | |
4003 | { | |
4004 | other_write_watchpoint = 1; | |
4005 | break; | |
4006 | } | |
4007 | } | |
4008 | ||
4009 | if (other_write_watchpoint | |
4010 | || bl->watchpoint_type == hw_access) | |
4011 | { | |
4012 | /* We're watching the same memory for writes, | |
4013 | and the value changed since the last time we | |
4014 | updated it, so this trap must be for a write. | |
4015 | Ignore it. */ | |
4016 | bs->print_it = print_it_noop; | |
4017 | bs->stop = 0; | |
4018 | } | |
18a18393 VP |
4019 | } |
4020 | break; | |
4021 | case WP_VALUE_NOT_CHANGED: | |
4022 | if (b->type == bp_hardware_watchpoint | |
4023 | || b->type == bp_watchpoint) | |
4024 | { | |
4025 | /* Don't stop: write watchpoints shouldn't fire if | |
4026 | the value hasn't changed. */ | |
4027 | bs->print_it = print_it_noop; | |
4028 | bs->stop = 0; | |
4029 | } | |
4030 | /* Stop. */ | |
4031 | break; | |
4032 | default: | |
4033 | /* Can't happen. */ | |
4034 | case 0: | |
4035 | /* Error from catch_errors. */ | |
4036 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
4037 | if (b->related_breakpoint) | |
4038 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
4039 | b->disposition = disp_del_at_next_stop; | |
4040 | /* We've already printed what needs to be printed. */ | |
4041 | bs->print_it = print_it_done; | |
4042 | break; | |
4043 | } | |
4044 | } | |
4045 | else /* must_check_value == 0 */ | |
4046 | { | |
4047 | /* This is a case where some watchpoint(s) triggered, but | |
4048 | not at the address of this watchpoint, or else no | |
4049 | watchpoint triggered after all. So don't print | |
4050 | anything for this watchpoint. */ | |
4051 | bs->print_it = print_it_noop; | |
4052 | bs->stop = 0; | |
4053 | } | |
4054 | } | |
4055 | } | |
4056 | ||
4057 | ||
4058 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4059 | of breakpoint referred to by BS. If we should not stop for this | |
4060 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4061 | |
18a18393 VP |
4062 | static void |
4063 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4064 | { | |
4065 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4066 | const struct bp_location *bl; |
4067 | struct breakpoint *b; | |
4068 | ||
4069 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4070 | bl = bs->bp_location_at; |
2bdf28a0 | 4071 | gdb_assert (bl != NULL); |
f431efe5 | 4072 | b = bs->breakpoint_at; |
2bdf28a0 | 4073 | gdb_assert (b != NULL); |
18a18393 VP |
4074 | |
4075 | if (frame_id_p (b->frame_id) | |
edb3359d | 4076 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4077 | bs->stop = 0; |
4078 | else if (bs->stop) | |
4079 | { | |
4080 | int value_is_zero = 0; | |
60e1c644 PA |
4081 | struct expression *cond; |
4082 | ||
7371cf6d PM |
4083 | /* Evaluate Python breakpoints that have a "stop" |
4084 | method implemented. */ | |
4085 | if (b->py_bp_object) | |
4086 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4087 | ||
60e1c644 PA |
4088 | if (is_watchpoint (b)) |
4089 | cond = b->cond_exp; | |
4090 | else | |
4091 | cond = bl->cond; | |
4092 | ||
f431efe5 | 4093 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4094 | { |
60e1c644 PA |
4095 | int within_current_scope = 1; |
4096 | ||
c5bc3a77 DJ |
4097 | /* We use value_mark and value_free_to_mark because it could |
4098 | be a long time before we return to the command level and | |
4099 | call free_all_values. We can't call free_all_values | |
4100 | because we might be in the middle of evaluating a | |
4101 | function call. */ | |
4102 | struct value *mark = value_mark (); | |
4103 | ||
edb3359d DJ |
4104 | /* Need to select the frame, with all that implies so that |
4105 | the conditions will have the right context. Because we | |
4106 | use the frame, we will not see an inlined function's | |
4107 | variables when we arrive at a breakpoint at the start | |
4108 | of the inlined function; the current frame will be the | |
4109 | call site. */ | |
60e1c644 PA |
4110 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
4111 | select_frame (get_current_frame ()); | |
4112 | else | |
4113 | { | |
4114 | struct frame_info *frame; | |
4115 | ||
4116 | /* For local watchpoint expressions, which particular | |
4117 | instance of a local is being watched matters, so we | |
4118 | keep track of the frame to evaluate the expression | |
4119 | in. To evaluate the condition however, it doesn't | |
4120 | really matter which instantiation of the function | |
4121 | where the condition makes sense triggers the | |
4122 | watchpoint. This allows an expression like "watch | |
4123 | global if q > 10" set in `func', catch writes to | |
4124 | global on all threads that call `func', or catch | |
4125 | writes on all recursive calls of `func' by a single | |
4126 | thread. We simply always evaluate the condition in | |
4127 | the innermost frame that's executing where it makes | |
4128 | sense to evaluate the condition. It seems | |
4129 | intuitive. */ | |
4130 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4131 | if (frame != NULL) | |
4132 | select_frame (frame); | |
4133 | else | |
4134 | within_current_scope = 0; | |
4135 | } | |
4136 | if (within_current_scope) | |
4137 | value_is_zero | |
4138 | = catch_errors (breakpoint_cond_eval, cond, | |
4139 | "Error in testing breakpoint condition:\n", | |
4140 | RETURN_MASK_ALL); | |
4141 | else | |
4142 | { | |
4143 | warning (_("Watchpoint condition cannot be tested " | |
4144 | "in the current scope")); | |
4145 | /* If we failed to set the right context for this | |
4146 | watchpoint, unconditionally report it. */ | |
4147 | value_is_zero = 0; | |
4148 | } | |
4a64f543 | 4149 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4150 | value_free_to_mark (mark); |
18a18393 | 4151 | } |
60e1c644 PA |
4152 | |
4153 | if (cond && value_is_zero) | |
18a18393 VP |
4154 | { |
4155 | bs->stop = 0; | |
4156 | } | |
4157 | else if (b->thread != -1 && b->thread != thread_id) | |
4158 | { | |
4159 | bs->stop = 0; | |
4160 | } | |
4161 | else if (b->ignore_count > 0) | |
4162 | { | |
4163 | b->ignore_count--; | |
4164 | annotate_ignore_count_change (); | |
4165 | bs->stop = 0; | |
4a64f543 | 4166 | /* Increase the hit count even though we don't stop. */ |
18a18393 VP |
4167 | ++(b->hit_count); |
4168 | } | |
4169 | } | |
4170 | } | |
4171 | ||
4172 | ||
9709f61c | 4173 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4174 | BP_ADDR in thread PTID. |
c906108c | 4175 | |
d983da9c | 4176 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4177 | don't understand this stop. Result is a chain of bpstat's such |
4178 | that: | |
c906108c | 4179 | |
c5aa993b | 4180 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4181 | |
c5aa993b | 4182 | if we understand why we stopped, the result is not null. |
c906108c | 4183 | |
c5aa993b JM |
4184 | Each element of the chain refers to a particular breakpoint or |
4185 | watchpoint at which we have stopped. (We may have stopped for | |
4186 | several reasons concurrently.) | |
c906108c | 4187 | |
c5aa993b JM |
4188 | Each element of the chain has valid next, breakpoint_at, |
4189 | commands, FIXME??? fields. */ | |
c906108c SS |
4190 | |
4191 | bpstat | |
6c95b8df PA |
4192 | bpstat_stop_status (struct address_space *aspace, |
4193 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4194 | { |
0d381245 | 4195 | struct breakpoint *b = NULL; |
afe38095 | 4196 | struct bp_location *bl; |
20874c92 | 4197 | struct bp_location *loc; |
5760d0ab JK |
4198 | /* First item of allocated bpstat's. */ |
4199 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4200 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4201 | bpstat bs; |
20874c92 | 4202 | int ix; |
429374b8 | 4203 | int need_remove_insert; |
f431efe5 | 4204 | int removed_any; |
c906108c | 4205 | |
f431efe5 PA |
4206 | /* First, build the bpstat chain with locations that explain a |
4207 | target stop, while being careful to not set the target running, | |
4208 | as that may invalidate locations (in particular watchpoint | |
4209 | locations are recreated). Resuming will happen here with | |
4210 | breakpoint conditions or watchpoint expressions that include | |
4211 | inferior function calls. */ | |
c5aa993b | 4212 | |
429374b8 JK |
4213 | ALL_BREAKPOINTS (b) |
4214 | { | |
4215 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4216 | continue; | |
a5606eee | 4217 | |
429374b8 JK |
4218 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4219 | { | |
4a64f543 MS |
4220 | /* For hardware watchpoints, we look only at the first |
4221 | location. The watchpoint_check function will work on the | |
4222 | entire expression, not the individual locations. For | |
4223 | read watchpoints, the watchpoints_triggered function has | |
4224 | checked all locations already. */ | |
429374b8 JK |
4225 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4226 | break; | |
18a18393 | 4227 | |
429374b8 JK |
4228 | if (bl->shlib_disabled) |
4229 | continue; | |
c5aa993b | 4230 | |
429374b8 JK |
4231 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4232 | continue; | |
c5aa993b | 4233 | |
4a64f543 MS |
4234 | /* Come here if it's a watchpoint, or if the break address |
4235 | matches. */ | |
c5aa993b | 4236 | |
4a64f543 MS |
4237 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4238 | explain stop. */ | |
c5aa993b | 4239 | |
f431efe5 PA |
4240 | /* Assume we stop. Should we find a watchpoint that is not |
4241 | actually triggered, or if the condition of the breakpoint | |
4242 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4243 | bs->stop = 1; |
4244 | bs->print = 1; | |
d983da9c | 4245 | |
f431efe5 PA |
4246 | /* If this is a scope breakpoint, mark the associated |
4247 | watchpoint as triggered so that we will handle the | |
4248 | out-of-scope event. We'll get to the watchpoint next | |
4249 | iteration. */ | |
4250 | if (b->type == bp_watchpoint_scope) | |
4251 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
4252 | } | |
4253 | } | |
4254 | ||
4255 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4256 | { | |
4257 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, | |
4258 | aspace, bp_addr)) | |
4259 | { | |
5760d0ab | 4260 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4261 | /* For hits of moribund locations, we should just proceed. */ |
4262 | bs->stop = 0; | |
4263 | bs->print = 0; | |
4264 | bs->print_it = print_it_noop; | |
4265 | } | |
4266 | } | |
4267 | ||
f431efe5 PA |
4268 | /* Now go through the locations that caused the target to stop, and |
4269 | check whether we're interested in reporting this stop to higher | |
4270 | layers, or whether we should resume the target transparently. */ | |
4271 | ||
4272 | removed_any = 0; | |
4273 | ||
5760d0ab | 4274 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4275 | { |
4276 | if (!bs->stop) | |
4277 | continue; | |
4278 | ||
4279 | bpstat_check_watchpoint (bs); | |
4280 | if (!bs->stop) | |
4281 | continue; | |
4282 | ||
4283 | b = bs->breakpoint_at; | |
18a18393 | 4284 | |
429374b8 | 4285 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d | 4286 | || b->type == bp_longjmp_master |
186c406b TT |
4287 | || b->type == bp_std_terminate_master |
4288 | || b->type == bp_exception_master) | |
429374b8 JK |
4289 | /* We do not stop for these. */ |
4290 | bs->stop = 0; | |
4291 | else | |
4292 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4293 | |
429374b8 JK |
4294 | if (bs->stop) |
4295 | { | |
4296 | ++(b->hit_count); | |
c906108c | 4297 | |
4a64f543 | 4298 | /* We will stop here. */ |
429374b8 JK |
4299 | if (b->disposition == disp_disable) |
4300 | { | |
4301 | if (b->enable_state != bp_permanent) | |
4302 | b->enable_state = bp_disabled; | |
f431efe5 | 4303 | removed_any = 1; |
429374b8 JK |
4304 | } |
4305 | if (b->silent) | |
4306 | bs->print = 0; | |
4307 | bs->commands = b->commands; | |
9add0f1b TT |
4308 | incref_counted_command_line (bs->commands); |
4309 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4310 | if (bs->commands_left | |
4311 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4312 | || (xdb_commands | |
4313 | && strcmp ("Q", | |
4314 | bs->commands_left->line) == 0))) | |
429374b8 | 4315 | { |
9add0f1b | 4316 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4317 | bs->print = 0; |
4318 | } | |
429374b8 JK |
4319 | } |
4320 | ||
4321 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4322 | if (bs->stop == 0 || bs->print == 0) | |
4323 | bs->print_it = print_it_noop; | |
429374b8 | 4324 | } |
876fa593 | 4325 | |
d983da9c DJ |
4326 | /* If we aren't stopping, the value of some hardware watchpoint may |
4327 | not have changed, but the intermediate memory locations we are | |
4328 | watching may have. Don't bother if we're stopping; this will get | |
4329 | done later. */ | |
d832cb68 | 4330 | need_remove_insert = 0; |
5760d0ab JK |
4331 | if (! bpstat_causes_stop (bs_head)) |
4332 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4333 | if (!bs->stop |
f431efe5 PA |
4334 | && bs->breakpoint_at |
4335 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4336 | { |
4a64f543 | 4337 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4338 | need_remove_insert = 1; |
d983da9c DJ |
4339 | } |
4340 | ||
d832cb68 | 4341 | if (need_remove_insert) |
2d134ed3 | 4342 | update_global_location_list (1); |
f431efe5 PA |
4343 | else if (removed_any) |
4344 | update_global_location_list (0); | |
d832cb68 | 4345 | |
5760d0ab | 4346 | return bs_head; |
c906108c | 4347 | } |
628fe4e4 JK |
4348 | |
4349 | static void | |
4350 | handle_jit_event (void) | |
4351 | { | |
4352 | struct frame_info *frame; | |
4353 | struct gdbarch *gdbarch; | |
4354 | ||
4355 | /* Switch terminal for any messages produced by | |
4356 | breakpoint_re_set. */ | |
4357 | target_terminal_ours_for_output (); | |
4358 | ||
4359 | frame = get_current_frame (); | |
4360 | gdbarch = get_frame_arch (frame); | |
4361 | ||
4362 | jit_event_handler (gdbarch); | |
4363 | ||
4364 | target_terminal_inferior (); | |
4365 | } | |
4366 | ||
4367 | /* Prepare WHAT final decision for infrun. */ | |
4368 | ||
4369 | /* Decide what infrun needs to do with this bpstat. */ | |
4370 | ||
c906108c | 4371 | struct bpstat_what |
fba45db2 | 4372 | bpstat_what (bpstat bs) |
c906108c | 4373 | { |
c906108c | 4374 | struct bpstat_what retval; |
628fe4e4 JK |
4375 | /* We need to defer calling `solib_add', as adding new symbols |
4376 | resets breakpoints, which in turn deletes breakpoint locations, | |
4377 | and hence may clear unprocessed entries in the BS chain. */ | |
4378 | int shlib_event = 0; | |
4379 | int jit_event = 0; | |
c906108c | 4380 | |
628fe4e4 | 4381 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4382 | retval.call_dummy = STOP_NONE; |
186c406b | 4383 | retval.is_longjmp = 0; |
628fe4e4 | 4384 | |
c906108c SS |
4385 | for (; bs != NULL; bs = bs->next) |
4386 | { | |
628fe4e4 JK |
4387 | /* Extract this BS's action. After processing each BS, we check |
4388 | if its action overrides all we've seem so far. */ | |
4389 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4390 | enum bptype bptype; | |
4391 | ||
c906108c | 4392 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4393 | { |
4394 | /* I suspect this can happen if it was a momentary | |
4395 | breakpoint which has since been deleted. */ | |
4396 | bptype = bp_none; | |
4397 | } | |
f431efe5 | 4398 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4399 | bptype = bp_none; |
20874c92 | 4400 | else |
f431efe5 | 4401 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4402 | |
4403 | switch (bptype) | |
c906108c SS |
4404 | { |
4405 | case bp_none: | |
628fe4e4 | 4406 | break; |
c906108c SS |
4407 | case bp_breakpoint: |
4408 | case bp_hardware_breakpoint: | |
4409 | case bp_until: | |
4410 | case bp_finish: | |
4411 | if (bs->stop) | |
4412 | { | |
4413 | if (bs->print) | |
628fe4e4 | 4414 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4415 | else |
628fe4e4 | 4416 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4417 | } |
4418 | else | |
628fe4e4 | 4419 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4420 | break; |
4421 | case bp_watchpoint: | |
4422 | case bp_hardware_watchpoint: | |
4423 | case bp_read_watchpoint: | |
4424 | case bp_access_watchpoint: | |
4425 | if (bs->stop) | |
4426 | { | |
4427 | if (bs->print) | |
628fe4e4 | 4428 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4429 | else |
628fe4e4 | 4430 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4431 | } |
4432 | else | |
628fe4e4 JK |
4433 | { |
4434 | /* There was a watchpoint, but we're not stopping. | |
4435 | This requires no further action. */ | |
4436 | } | |
c906108c SS |
4437 | break; |
4438 | case bp_longjmp: | |
186c406b | 4439 | case bp_exception: |
628fe4e4 | 4440 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4441 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4442 | break; |
4443 | case bp_longjmp_resume: | |
186c406b | 4444 | case bp_exception_resume: |
628fe4e4 | 4445 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4446 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4447 | break; |
4448 | case bp_step_resume: | |
4449 | if (bs->stop) | |
628fe4e4 JK |
4450 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4451 | else | |
c906108c | 4452 | { |
628fe4e4 JK |
4453 | /* It is for the wrong frame. */ |
4454 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4455 | } |
c906108c | 4456 | break; |
c906108c | 4457 | case bp_watchpoint_scope: |
c4093a6a | 4458 | case bp_thread_event: |
1900040c | 4459 | case bp_overlay_event: |
0fd8e87f | 4460 | case bp_longjmp_master: |
aa7d318d | 4461 | case bp_std_terminate_master: |
186c406b | 4462 | case bp_exception_master: |
628fe4e4 | 4463 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4464 | break; |
ce78b96d | 4465 | case bp_catchpoint: |
c5aa993b JM |
4466 | if (bs->stop) |
4467 | { | |
4468 | if (bs->print) | |
628fe4e4 | 4469 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4470 | else |
628fe4e4 | 4471 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4472 | } |
4473 | else | |
628fe4e4 JK |
4474 | { |
4475 | /* There was a catchpoint, but we're not stopping. | |
4476 | This requires no further action. */ | |
4477 | } | |
4478 | break; | |
4479 | case bp_shlib_event: | |
4480 | shlib_event = 1; | |
4481 | ||
4482 | /* If requested, stop when the dynamic linker notifies GDB | |
4483 | of events. This allows the user to get control and place | |
4484 | breakpoints in initializer routines for dynamically | |
4485 | loaded objects (among other things). */ | |
4486 | if (stop_on_solib_events) | |
4487 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4488 | else | |
4489 | this_action = BPSTAT_WHAT_SINGLE; | |
4490 | break; | |
4491 | case bp_jit_event: | |
4492 | jit_event = 1; | |
4493 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4494 | break; |
c906108c | 4495 | case bp_call_dummy: |
53a5351d JM |
4496 | /* Make sure the action is stop (silent or noisy), |
4497 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4498 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4499 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4500 | break; |
4501 | case bp_std_terminate: | |
4502 | /* Make sure the action is stop (silent or noisy), | |
4503 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4504 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4505 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4506 | break; |
1042e4c0 | 4507 | case bp_tracepoint: |
7a697b8d | 4508 | case bp_fast_tracepoint: |
0fb4aa4b | 4509 | case bp_static_tracepoint: |
1042e4c0 SS |
4510 | /* Tracepoint hits should not be reported back to GDB, and |
4511 | if one got through somehow, it should have been filtered | |
4512 | out already. */ | |
4513 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4514 | _("bpstat_what: tracepoint encountered")); |
628fe4e4 JK |
4515 | default: |
4516 | internal_error (__FILE__, __LINE__, | |
4517 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4518 | } |
628fe4e4 JK |
4519 | |
4520 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4521 | } |
628fe4e4 JK |
4522 | |
4523 | if (shlib_event) | |
4524 | { | |
4525 | if (debug_infrun) | |
4526 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4527 | ||
4528 | /* Check for any newly added shared libraries if we're supposed | |
4529 | to be adding them automatically. */ | |
4530 | ||
4531 | /* Switch terminal for any messages produced by | |
4532 | breakpoint_re_set. */ | |
4533 | target_terminal_ours_for_output (); | |
4534 | ||
4535 | #ifdef SOLIB_ADD | |
4536 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4537 | #else | |
4538 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4539 | #endif | |
4540 | ||
4541 | target_terminal_inferior (); | |
4542 | } | |
4543 | ||
4544 | if (jit_event) | |
4545 | { | |
4546 | if (debug_infrun) | |
4547 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4548 | ||
4549 | handle_jit_event (); | |
4550 | } | |
4551 | ||
c906108c SS |
4552 | return retval; |
4553 | } | |
4554 | ||
4555 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4556 | without hardware support). This isn't related to a specific bpstat, | |
4557 | just to things like whether watchpoints are set. */ | |
4558 | ||
c5aa993b | 4559 | int |
fba45db2 | 4560 | bpstat_should_step (void) |
c906108c SS |
4561 | { |
4562 | struct breakpoint *b; | |
cc59ec59 | 4563 | |
c906108c | 4564 | ALL_BREAKPOINTS (b) |
717a8278 | 4565 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4566 | return 1; |
c906108c SS |
4567 | return 0; |
4568 | } | |
4569 | ||
67822962 PA |
4570 | int |
4571 | bpstat_causes_stop (bpstat bs) | |
4572 | { | |
4573 | for (; bs != NULL; bs = bs->next) | |
4574 | if (bs->stop) | |
4575 | return 1; | |
4576 | ||
4577 | return 0; | |
4578 | } | |
4579 | ||
c906108c | 4580 | \f |
c5aa993b | 4581 | |
170b53b2 UW |
4582 | /* Compute a string of spaces suitable to indent the next line |
4583 | so it starts at the position corresponding to the table column | |
4584 | named COL_NAME in the currently active table of UIOUT. */ | |
4585 | ||
4586 | static char * | |
4587 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4588 | { | |
4589 | static char wrap_indent[80]; | |
4590 | int i, total_width, width, align; | |
4591 | char *text; | |
4592 | ||
4593 | total_width = 0; | |
4594 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4595 | { | |
4596 | if (strcmp (text, col_name) == 0) | |
4597 | { | |
4598 | gdb_assert (total_width < sizeof wrap_indent); | |
4599 | memset (wrap_indent, ' ', total_width); | |
4600 | wrap_indent[total_width] = 0; | |
4601 | ||
4602 | return wrap_indent; | |
4603 | } | |
4604 | ||
4605 | total_width += width + 1; | |
4606 | } | |
4607 | ||
4608 | return NULL; | |
4609 | } | |
4610 | ||
859825b8 JK |
4611 | /* Print the LOC location out of the list of B->LOC locations. */ |
4612 | ||
170b53b2 UW |
4613 | static void |
4614 | print_breakpoint_location (struct breakpoint *b, | |
4615 | struct bp_location *loc) | |
0d381245 | 4616 | { |
6c95b8df PA |
4617 | struct cleanup *old_chain = save_current_program_space (); |
4618 | ||
859825b8 JK |
4619 | if (loc != NULL && loc->shlib_disabled) |
4620 | loc = NULL; | |
4621 | ||
6c95b8df PA |
4622 | if (loc != NULL) |
4623 | set_current_program_space (loc->pspace); | |
4624 | ||
56435ebe TT |
4625 | if (b->display_canonical) |
4626 | ui_out_field_string (uiout, "what", b->addr_string); | |
4627 | else if (b->source_file && loc) | |
0d381245 VP |
4628 | { |
4629 | struct symbol *sym | |
4630 | = find_pc_sect_function (loc->address, loc->section); | |
4631 | if (sym) | |
4632 | { | |
4633 | ui_out_text (uiout, "in "); | |
4634 | ui_out_field_string (uiout, "func", | |
4635 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4636 | ui_out_text (uiout, " "); |
4637 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4638 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4639 | } |
4640 | ui_out_field_string (uiout, "file", b->source_file); | |
4641 | ui_out_text (uiout, ":"); | |
4642 | ||
4643 | if (ui_out_is_mi_like_p (uiout)) | |
4644 | { | |
4645 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4646 | char *fullname = symtab_to_fullname (sal.symtab); | |
4647 | ||
4648 | if (fullname) | |
4649 | ui_out_field_string (uiout, "fullname", fullname); | |
4650 | } | |
4651 | ||
4652 | ui_out_field_int (uiout, "line", b->line_number); | |
4653 | } | |
859825b8 | 4654 | else if (loc) |
0d381245 | 4655 | { |
170b53b2 UW |
4656 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4657 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4658 | ||
22e722e1 DJ |
4659 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4660 | demangle, ""); | |
0d381245 | 4661 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4662 | |
4663 | do_cleanups (stb_chain); | |
0d381245 | 4664 | } |
859825b8 JK |
4665 | else |
4666 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4667 | |
4668 | do_cleanups (old_chain); | |
0d381245 VP |
4669 | } |
4670 | ||
269b11a2 PA |
4671 | static const char * |
4672 | bptype_string (enum bptype type) | |
c906108c | 4673 | { |
c4093a6a JM |
4674 | struct ep_type_description |
4675 | { | |
4676 | enum bptype type; | |
4677 | char *description; | |
4678 | }; | |
4679 | static struct ep_type_description bptypes[] = | |
c906108c | 4680 | { |
c5aa993b JM |
4681 | {bp_none, "?deleted?"}, |
4682 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4683 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4684 | {bp_until, "until"}, |
4685 | {bp_finish, "finish"}, | |
4686 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4687 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4688 | {bp_read_watchpoint, "read watchpoint"}, |
4689 | {bp_access_watchpoint, "acc watchpoint"}, | |
4690 | {bp_longjmp, "longjmp"}, | |
4691 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4692 | {bp_exception, "exception"}, |
4693 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4694 | {bp_step_resume, "step resume"}, |
c5aa993b JM |
4695 | {bp_watchpoint_scope, "watchpoint scope"}, |
4696 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4697 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4698 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4699 | {bp_thread_event, "thread events"}, |
1900040c | 4700 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4701 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4702 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4703 | {bp_exception_master, "exception master"}, |
ce78b96d | 4704 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4705 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4706 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4707 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4708 | {bp_jit_event, "jit events"}, |
c5aa993b | 4709 | }; |
269b11a2 PA |
4710 | |
4711 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4712 | || ((int) type != bptypes[(int) type].type)) | |
4713 | internal_error (__FILE__, __LINE__, | |
4714 | _("bptypes table does not describe type #%d."), | |
4715 | (int) type); | |
4716 | ||
4717 | return bptypes[(int) type].description; | |
4718 | } | |
4719 | ||
4720 | /* Print B to gdb_stdout. */ | |
4721 | ||
4722 | static void | |
4723 | print_one_breakpoint_location (struct breakpoint *b, | |
4724 | struct bp_location *loc, | |
4725 | int loc_number, | |
4726 | struct bp_location **last_loc, | |
269b11a2 PA |
4727 | int allflag) |
4728 | { | |
4729 | struct command_line *l; | |
c2c6d25f | 4730 | static char bpenables[] = "nynny"; |
3b31d625 | 4731 | struct cleanup *bkpt_chain; |
c906108c | 4732 | |
0d381245 VP |
4733 | int header_of_multiple = 0; |
4734 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4735 | struct value_print_options opts; |
4736 | ||
4737 | get_user_print_options (&opts); | |
0d381245 VP |
4738 | |
4739 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4740 | /* See comment in print_one_breakpoint concerning treatment of |
4741 | breakpoints with single disabled location. */ | |
0d381245 VP |
4742 | if (loc == NULL |
4743 | && (b->loc != NULL | |
4744 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4745 | header_of_multiple = 1; | |
4746 | if (loc == NULL) | |
4747 | loc = b->loc; | |
4748 | ||
c4093a6a | 4749 | annotate_record (); |
3b31d625 | 4750 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4751 | |
4752 | /* 1 */ | |
4753 | annotate_field (0); | |
0d381245 VP |
4754 | if (part_of_multiple) |
4755 | { | |
4756 | char *formatted; | |
0c6773c1 | 4757 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4758 | ui_out_field_string (uiout, "number", formatted); |
4759 | xfree (formatted); | |
4760 | } | |
4761 | else | |
4762 | { | |
4763 | ui_out_field_int (uiout, "number", b->number); | |
4764 | } | |
c4093a6a JM |
4765 | |
4766 | /* 2 */ | |
4767 | annotate_field (1); | |
0d381245 VP |
4768 | if (part_of_multiple) |
4769 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4770 | else |
4771 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4772 | |
4773 | /* 3 */ | |
4774 | annotate_field (2); | |
0d381245 VP |
4775 | if (part_of_multiple) |
4776 | ui_out_field_skip (uiout, "disp"); | |
4777 | else | |
2cec12e5 | 4778 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4779 | |
c4093a6a JM |
4780 | |
4781 | /* 4 */ | |
4782 | annotate_field (3); | |
0d381245 | 4783 | if (part_of_multiple) |
54e52265 | 4784 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4785 | else |
4a64f543 MS |
4786 | ui_out_field_fmt (uiout, "enabled", "%c", |
4787 | bpenables[(int) b->enable_state]); | |
54e52265 | 4788 | ui_out_spaces (uiout, 2); |
0d381245 | 4789 | |
c4093a6a JM |
4790 | |
4791 | /* 5 and 6 */ | |
3086aeae | 4792 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4793 | { |
4a64f543 MS |
4794 | /* Although the print_one can possibly print all locations, |
4795 | calling it here is not likely to get any nice result. So, | |
4796 | make sure there's just one location. */ | |
0d381245 | 4797 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4798 | b->ops->print_one (b, last_loc); |
0d381245 | 4799 | } |
3086aeae DJ |
4800 | else |
4801 | switch (b->type) | |
4802 | { | |
4803 | case bp_none: | |
4804 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4805 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4806 | break; |
c906108c | 4807 | |
3086aeae DJ |
4808 | case bp_watchpoint: |
4809 | case bp_hardware_watchpoint: | |
4810 | case bp_read_watchpoint: | |
4811 | case bp_access_watchpoint: | |
4812 | /* Field 4, the address, is omitted (which makes the columns | |
4813 | not line up too nicely with the headers, but the effect | |
4814 | is relatively readable). */ | |
79a45b7d | 4815 | if (opts.addressprint) |
3086aeae DJ |
4816 | ui_out_field_skip (uiout, "addr"); |
4817 | annotate_field (5); | |
fa8a61dc | 4818 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4819 | break; |
4820 | ||
3086aeae DJ |
4821 | case bp_breakpoint: |
4822 | case bp_hardware_breakpoint: | |
4823 | case bp_until: | |
4824 | case bp_finish: | |
4825 | case bp_longjmp: | |
4826 | case bp_longjmp_resume: | |
186c406b TT |
4827 | case bp_exception: |
4828 | case bp_exception_resume: | |
3086aeae | 4829 | case bp_step_resume: |
3086aeae DJ |
4830 | case bp_watchpoint_scope: |
4831 | case bp_call_dummy: | |
aa7d318d | 4832 | case bp_std_terminate: |
3086aeae DJ |
4833 | case bp_shlib_event: |
4834 | case bp_thread_event: | |
4835 | case bp_overlay_event: | |
0fd8e87f | 4836 | case bp_longjmp_master: |
aa7d318d | 4837 | case bp_std_terminate_master: |
186c406b | 4838 | case bp_exception_master: |
1042e4c0 | 4839 | case bp_tracepoint: |
7a697b8d | 4840 | case bp_fast_tracepoint: |
0fb4aa4b | 4841 | case bp_static_tracepoint: |
4efc6507 | 4842 | case bp_jit_event: |
79a45b7d | 4843 | if (opts.addressprint) |
3086aeae DJ |
4844 | { |
4845 | annotate_field (4); | |
54e52265 | 4846 | if (header_of_multiple) |
0d381245 | 4847 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4848 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4849 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4850 | else |
5af949e3 UW |
4851 | ui_out_field_core_addr (uiout, "addr", |
4852 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4853 | } |
4854 | annotate_field (5); | |
0d381245 | 4855 | if (!header_of_multiple) |
170b53b2 | 4856 | print_breakpoint_location (b, loc); |
0d381245 | 4857 | if (b->loc) |
a6d9a66e | 4858 | *last_loc = b->loc; |
3086aeae DJ |
4859 | break; |
4860 | } | |
c906108c | 4861 | |
6c95b8df PA |
4862 | |
4863 | /* For backward compatibility, don't display inferiors unless there | |
4864 | are several. */ | |
4865 | if (loc != NULL | |
4866 | && !header_of_multiple | |
4867 | && (allflag | |
4868 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4869 | && (number_of_program_spaces () > 1 | |
4870 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4871 | /* LOC is for existing B, it cannot be in |
4872 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4873 | && loc->owner->type != bp_catchpoint))) |
4874 | { | |
4875 | struct inferior *inf; | |
4876 | int first = 1; | |
4877 | ||
4878 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4879 | { | |
4880 | if (inf->pspace == loc->pspace) | |
4881 | { | |
4882 | if (first) | |
4883 | { | |
4884 | first = 0; | |
4885 | ui_out_text (uiout, " inf "); | |
4886 | } | |
4887 | else | |
4888 | ui_out_text (uiout, ", "); | |
4889 | ui_out_text (uiout, plongest (inf->num)); | |
4890 | } | |
4891 | } | |
4892 | } | |
4893 | ||
4a306c9a | 4894 | if (!part_of_multiple) |
c4093a6a | 4895 | { |
4a306c9a JB |
4896 | if (b->thread != -1) |
4897 | { | |
4898 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4899 | "stop only in" line a little further down. */ |
4a306c9a JB |
4900 | ui_out_text (uiout, " thread "); |
4901 | ui_out_field_int (uiout, "thread", b->thread); | |
4902 | } | |
4903 | else if (b->task != 0) | |
4904 | { | |
4905 | ui_out_text (uiout, " task "); | |
4906 | ui_out_field_int (uiout, "task", b->task); | |
4907 | } | |
c4093a6a JM |
4908 | } |
4909 | ||
8b93c638 | 4910 | ui_out_text (uiout, "\n"); |
c4093a6a | 4911 | |
0fb4aa4b PA |
4912 | if (!part_of_multiple && b->static_trace_marker_id) |
4913 | { | |
4914 | gdb_assert (b->type == bp_static_tracepoint); | |
4915 | ||
4916 | ui_out_text (uiout, "\tmarker id is "); | |
4917 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
4918 | b->static_trace_marker_id); | |
4919 | ui_out_text (uiout, "\n"); | |
4920 | } | |
4921 | ||
0d381245 | 4922 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4923 | { |
4924 | annotate_field (6); | |
8b93c638 | 4925 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4926 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4927 | the frame ID. */ | |
5af949e3 UW |
4928 | ui_out_field_core_addr (uiout, "frame", |
4929 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4930 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4931 | } |
4932 | ||
0d381245 | 4933 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4934 | { |
f7f9143b JB |
4935 | /* We do not print the condition for Ada exception catchpoints |
4936 | because the condition is an internal implementation detail | |
4937 | that we do not want to expose to the user. */ | |
c4093a6a | 4938 | annotate_field (7); |
d77f58be | 4939 | if (is_tracepoint (b)) |
1042e4c0 SS |
4940 | ui_out_text (uiout, "\ttrace only if "); |
4941 | else | |
4942 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4943 | ui_out_field_string (uiout, "cond", b->cond_string); |
4944 | ui_out_text (uiout, "\n"); | |
4945 | } | |
4946 | ||
0d381245 | 4947 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4948 | { |
4a64f543 | 4949 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4950 | ui_out_text (uiout, "\tstop only in thread "); |
4951 | ui_out_field_int (uiout, "thread", b->thread); | |
4952 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4953 | } |
4954 | ||
63c715c6 | 4955 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4956 | { |
4a64f543 | 4957 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4958 | if (ep_is_catchpoint (b)) |
4959 | ui_out_text (uiout, "\tcatchpoint"); | |
4960 | else | |
4961 | ui_out_text (uiout, "\tbreakpoint"); | |
4962 | ui_out_text (uiout, " already hit "); | |
4963 | ui_out_field_int (uiout, "times", b->hit_count); | |
4964 | if (b->hit_count == 1) | |
4965 | ui_out_text (uiout, " time\n"); | |
4966 | else | |
4967 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4968 | } |
4969 | ||
4a64f543 MS |
4970 | /* Output the count also if it is zero, but only if this is mi. |
4971 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4972 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4973 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4974 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4975 | |
0d381245 | 4976 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4977 | { |
4978 | annotate_field (8); | |
8b93c638 JM |
4979 | ui_out_text (uiout, "\tignore next "); |
4980 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4981 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4982 | } |
059fb39f | 4983 | |
9add0f1b | 4984 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4985 | if (!part_of_multiple && l) |
c4093a6a | 4986 | { |
3b31d625 EZ |
4987 | struct cleanup *script_chain; |
4988 | ||
c4093a6a | 4989 | annotate_field (9); |
3b31d625 | 4990 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4991 | print_command_lines (uiout, l, 4); |
3b31d625 | 4992 | do_cleanups (script_chain); |
c4093a6a | 4993 | } |
d24317b4 | 4994 | |
1042e4c0 SS |
4995 | if (!part_of_multiple && b->pass_count) |
4996 | { | |
4997 | annotate_field (10); | |
4998 | ui_out_text (uiout, "\tpass count "); | |
4999 | ui_out_field_int (uiout, "pass", b->pass_count); | |
5000 | ui_out_text (uiout, " \n"); | |
5001 | } | |
5002 | ||
d24317b4 VP |
5003 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5004 | { | |
5005 | if (b->addr_string) | |
5006 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
5007 | else if (b->exp_string) | |
5008 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
5009 | } | |
5010 | ||
3b31d625 | 5011 | do_cleanups (bkpt_chain); |
c4093a6a | 5012 | } |
c5aa993b | 5013 | |
0d381245 VP |
5014 | static void |
5015 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5016 | struct bp_location **last_loc, |
6c95b8df | 5017 | int allflag) |
0d381245 | 5018 | { |
12c5a436 | 5019 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
0d381245 VP |
5020 | |
5021 | /* If this breakpoint has custom print function, | |
5022 | it's already printed. Otherwise, print individual | |
5023 | locations, if any. */ | |
5024 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5025 | { | |
4a64f543 MS |
5026 | /* If breakpoint has a single location that is disabled, we |
5027 | print it as if it had several locations, since otherwise it's | |
5028 | hard to represent "breakpoint enabled, location disabled" | |
5029 | situation. | |
5030 | ||
5031 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5032 | internally, that's not a property exposed to user. */ |
0d381245 | 5033 | if (b->loc |
a5606eee | 5034 | && !is_hardware_watchpoint (b) |
0d381245 | 5035 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 5036 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
5037 | { |
5038 | struct bp_location *loc; | |
5039 | int n = 1; | |
5040 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
12c5a436 | 5041 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); |
0d381245 VP |
5042 | } |
5043 | } | |
5044 | } | |
5045 | ||
a6d9a66e UW |
5046 | static int |
5047 | breakpoint_address_bits (struct breakpoint *b) | |
5048 | { | |
5049 | int print_address_bits = 0; | |
5050 | struct bp_location *loc; | |
5051 | ||
5052 | for (loc = b->loc; loc; loc = loc->next) | |
5053 | { | |
c7437ca6 PA |
5054 | int addr_bit; |
5055 | ||
5056 | /* Software watchpoints that aren't watching memory don't have | |
5057 | an address to print. */ | |
5058 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5059 | continue; | |
5060 | ||
5061 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5062 | if (addr_bit > print_address_bits) |
5063 | print_address_bits = addr_bit; | |
5064 | } | |
5065 | ||
5066 | return print_address_bits; | |
5067 | } | |
0d381245 | 5068 | |
c4093a6a JM |
5069 | struct captured_breakpoint_query_args |
5070 | { | |
5071 | int bnum; | |
5072 | }; | |
c5aa993b | 5073 | |
c4093a6a | 5074 | static int |
2b65245e | 5075 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5076 | { |
5077 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5078 | struct breakpoint *b; |
a6d9a66e | 5079 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5080 | |
c4093a6a JM |
5081 | ALL_BREAKPOINTS (b) |
5082 | { | |
5083 | if (args->bnum == b->number) | |
c5aa993b | 5084 | { |
12c5a436 | 5085 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5086 | return GDB_RC_OK; |
c5aa993b | 5087 | } |
c4093a6a JM |
5088 | } |
5089 | return GDB_RC_NONE; | |
5090 | } | |
c5aa993b | 5091 | |
c4093a6a | 5092 | enum gdb_rc |
4a64f543 MS |
5093 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5094 | char **error_message) | |
c4093a6a JM |
5095 | { |
5096 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5097 | |
c4093a6a JM |
5098 | args.bnum = bnum; |
5099 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5100 | an error. */ |
b0b13bb4 DJ |
5101 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5102 | error_message, RETURN_MASK_ALL) < 0) | |
5103 | return GDB_RC_FAIL; | |
5104 | else | |
5105 | return GDB_RC_OK; | |
c4093a6a | 5106 | } |
c5aa993b | 5107 | |
7f3b0473 | 5108 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4a64f543 | 5109 | catchpoints, et.al.). */ |
7f3b0473 AC |
5110 | |
5111 | static int | |
5112 | user_settable_breakpoint (const struct breakpoint *b) | |
5113 | { | |
5114 | return (b->type == bp_breakpoint | |
ce78b96d | 5115 | || b->type == bp_catchpoint |
7f3b0473 | 5116 | || b->type == bp_hardware_breakpoint |
d77f58be | 5117 | || is_tracepoint (b) |
cc60f2e3 | 5118 | || is_watchpoint (b)); |
7f3b0473 | 5119 | } |
4a64f543 | 5120 | |
09d682a4 TT |
5121 | /* Return true if this breakpoint was set by the user, false if it is |
5122 | internal or momentary. */ | |
5123 | ||
5124 | int | |
5125 | user_breakpoint_p (struct breakpoint *b) | |
5126 | { | |
5127 | return user_settable_breakpoint (b) && b->number > 0; | |
5128 | } | |
5129 | ||
7f3b0473 | 5130 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5131 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5132 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5133 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5134 | ones for which it returns non-zero. Return the total number of | |
5135 | breakpoints listed. */ | |
c906108c | 5136 | |
d77f58be | 5137 | static int |
e5a67952 | 5138 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5139 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5140 | { |
52f0bd74 | 5141 | struct breakpoint *b; |
a6d9a66e | 5142 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5143 | int nr_printable_breakpoints; |
3b31d625 | 5144 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5145 | struct value_print_options opts; |
a6d9a66e | 5146 | int print_address_bits = 0; |
269b11a2 PA |
5147 | int print_type_col_width = 14; |
5148 | ||
79a45b7d TT |
5149 | get_user_print_options (&opts); |
5150 | ||
4a64f543 MS |
5151 | /* Compute the number of rows in the table, as well as the size |
5152 | required for address fields. */ | |
7f3b0473 AC |
5153 | nr_printable_breakpoints = 0; |
5154 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5155 | { |
5156 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5157 | if (filter && !filter (b)) | |
5158 | continue; | |
5159 | ||
5160 | /* If we have an "args" string, it is a list of breakpoints to | |
5161 | accept. Skip the others. */ | |
5162 | if (args != NULL && *args != '\0') | |
5163 | { | |
5164 | if (allflag && parse_and_eval_long (args) != b->number) | |
5165 | continue; | |
5166 | if (!allflag && !number_is_in_list (args, b->number)) | |
5167 | continue; | |
5168 | } | |
269b11a2 | 5169 | |
e5a67952 MS |
5170 | if (allflag || user_breakpoint_p (b)) |
5171 | { | |
5172 | int addr_bit, type_len; | |
a6d9a66e | 5173 | |
e5a67952 MS |
5174 | addr_bit = breakpoint_address_bits (b); |
5175 | if (addr_bit > print_address_bits) | |
5176 | print_address_bits = addr_bit; | |
269b11a2 | 5177 | |
e5a67952 MS |
5178 | type_len = strlen (bptype_string (b->type)); |
5179 | if (type_len > print_type_col_width) | |
5180 | print_type_col_width = type_len; | |
5181 | ||
5182 | nr_printable_breakpoints++; | |
5183 | } | |
5184 | } | |
7f3b0473 | 5185 | |
79a45b7d | 5186 | if (opts.addressprint) |
3b31d625 | 5187 | bkpttbl_chain |
3e43a32a MS |
5188 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5189 | nr_printable_breakpoints, | |
3b31d625 | 5190 | "BreakpointTable"); |
8b93c638 | 5191 | else |
3b31d625 | 5192 | bkpttbl_chain |
3e43a32a MS |
5193 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5194 | nr_printable_breakpoints, | |
3b31d625 | 5195 | "BreakpointTable"); |
8b93c638 | 5196 | |
7f3b0473 | 5197 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5198 | annotate_breakpoints_headers (); |
5199 | if (nr_printable_breakpoints > 0) | |
5200 | annotate_field (0); | |
4a64f543 | 5201 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5202 | if (nr_printable_breakpoints > 0) |
5203 | annotate_field (1); | |
269b11a2 | 5204 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5205 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5206 | if (nr_printable_breakpoints > 0) |
5207 | annotate_field (2); | |
4a64f543 | 5208 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5209 | if (nr_printable_breakpoints > 0) |
5210 | annotate_field (3); | |
54e52265 | 5211 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5212 | if (opts.addressprint) |
e5a67952 MS |
5213 | { |
5214 | if (nr_printable_breakpoints > 0) | |
5215 | annotate_field (4); | |
5216 | if (print_address_bits <= 32) | |
5217 | ui_out_table_header (uiout, 10, ui_left, | |
5218 | "addr", "Address"); /* 5 */ | |
5219 | else | |
5220 | ui_out_table_header (uiout, 18, ui_left, | |
5221 | "addr", "Address"); /* 5 */ | |
5222 | } | |
d7faa9e7 AC |
5223 | if (nr_printable_breakpoints > 0) |
5224 | annotate_field (5); | |
5225 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5226 | ui_out_table_body (uiout); | |
5227 | if (nr_printable_breakpoints > 0) | |
5228 | annotate_breakpoints_table (); | |
7f3b0473 | 5229 | |
c4093a6a | 5230 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5231 | { |
5232 | QUIT; | |
5233 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5234 | if (filter && !filter (b)) | |
5235 | continue; | |
5236 | ||
5237 | /* If we have an "args" string, it is a list of breakpoints to | |
5238 | accept. Skip the others. */ | |
5239 | ||
5240 | if (args != NULL && *args != '\0') | |
5241 | { | |
5242 | if (allflag) /* maintenance info breakpoint */ | |
5243 | { | |
5244 | if (parse_and_eval_long (args) != b->number) | |
5245 | continue; | |
5246 | } | |
5247 | else /* all others */ | |
5248 | { | |
5249 | if (!number_is_in_list (args, b->number)) | |
5250 | continue; | |
5251 | } | |
5252 | } | |
5253 | /* We only print out user settable breakpoints unless the | |
5254 | allflag is set. */ | |
5255 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5256 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5257 | } |
5258 | ||
3b31d625 | 5259 | do_cleanups (bkpttbl_chain); |
698384cd | 5260 | |
7f3b0473 | 5261 | if (nr_printable_breakpoints == 0) |
c906108c | 5262 | { |
4a64f543 MS |
5263 | /* If there's a filter, let the caller decide how to report |
5264 | empty list. */ | |
d77f58be SS |
5265 | if (!filter) |
5266 | { | |
e5a67952 | 5267 | if (args == NULL || *args == '\0') |
d77f58be SS |
5268 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5269 | else | |
4a64f543 | 5270 | ui_out_message (uiout, 0, |
e5a67952 MS |
5271 | "No breakpoint or watchpoint matching '%s'.\n", |
5272 | args); | |
d77f58be | 5273 | } |
c906108c SS |
5274 | } |
5275 | else | |
c4093a6a | 5276 | { |
a6d9a66e UW |
5277 | if (last_loc && !server_command) |
5278 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5279 | } |
c906108c | 5280 | |
4a64f543 | 5281 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5282 | there have been breakpoints? */ |
c906108c | 5283 | annotate_breakpoints_table_end (); |
d77f58be SS |
5284 | |
5285 | return nr_printable_breakpoints; | |
c906108c SS |
5286 | } |
5287 | ||
ad443146 SS |
5288 | /* Display the value of default-collect in a way that is generally |
5289 | compatible with the breakpoint list. */ | |
5290 | ||
5291 | static void | |
5292 | default_collect_info (void) | |
5293 | { | |
5294 | /* If it has no value (which is frequently the case), say nothing; a | |
5295 | message like "No default-collect." gets in user's face when it's | |
5296 | not wanted. */ | |
5297 | if (!*default_collect) | |
5298 | return; | |
5299 | ||
5300 | /* The following phrase lines up nicely with per-tracepoint collect | |
5301 | actions. */ | |
5302 | ui_out_text (uiout, "default collect "); | |
5303 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5304 | ui_out_text (uiout, " \n"); | |
5305 | } | |
5306 | ||
c906108c | 5307 | static void |
e5a67952 | 5308 | breakpoints_info (char *args, int from_tty) |
c906108c | 5309 | { |
e5a67952 | 5310 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5311 | |
5312 | default_collect_info (); | |
d77f58be SS |
5313 | } |
5314 | ||
5315 | static void | |
e5a67952 | 5316 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5317 | { |
e5a67952 | 5318 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
d77f58be SS |
5319 | |
5320 | if (num_printed == 0) | |
5321 | { | |
e5a67952 | 5322 | if (args == NULL || *args == '\0') |
d77f58be SS |
5323 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5324 | else | |
e5a67952 | 5325 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5326 | } |
c906108c SS |
5327 | } |
5328 | ||
7a292a7a | 5329 | static void |
e5a67952 | 5330 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5331 | { |
e5a67952 | 5332 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5333 | |
5334 | default_collect_info (); | |
c906108c SS |
5335 | } |
5336 | ||
0d381245 | 5337 | static int |
714835d5 | 5338 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5339 | struct program_space *pspace, |
714835d5 | 5340 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5341 | { |
5342 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5343 | |
0d381245 VP |
5344 | for (; bl; bl = bl->next) |
5345 | { | |
6c95b8df PA |
5346 | if (bl->pspace == pspace |
5347 | && bl->address == pc | |
0d381245 VP |
5348 | && (!overlay_debugging || bl->section == section)) |
5349 | return 1; | |
5350 | } | |
5351 | return 0; | |
5352 | } | |
5353 | ||
6c95b8df PA |
5354 | /* Print a message describing any breakpoints set at PC. This |
5355 | concerns with logical breakpoints, so we match program spaces, not | |
5356 | address spaces. */ | |
c906108c SS |
5357 | |
5358 | static void | |
6c95b8df PA |
5359 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5360 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5361 | struct obj_section *section, int thread) |
c906108c | 5362 | { |
52f0bd74 AC |
5363 | int others = 0; |
5364 | struct breakpoint *b; | |
c906108c SS |
5365 | |
5366 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5367 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5368 | if (others > 0) |
5369 | { | |
a3f17187 AC |
5370 | if (others == 1) |
5371 | printf_filtered (_("Note: breakpoint ")); | |
5372 | else /* if (others == ???) */ | |
5373 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5374 | ALL_BREAKPOINTS (b) |
6c95b8df | 5375 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5376 | { |
5377 | others--; | |
5378 | printf_filtered ("%d", b->number); | |
5379 | if (b->thread == -1 && thread != -1) | |
5380 | printf_filtered (" (all threads)"); | |
5381 | else if (b->thread != -1) | |
5382 | printf_filtered (" (thread %d)", b->thread); | |
5383 | printf_filtered ("%s%s ", | |
059fb39f | 5384 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5385 | || b->enable_state == bp_call_disabled |
5386 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5387 | ? " (disabled)" |
5388 | : b->enable_state == bp_permanent | |
5389 | ? " (permanent)" | |
5390 | : ""), | |
5391 | (others > 1) ? "," | |
5392 | : ((others == 1) ? " and" : "")); | |
5393 | } | |
a3f17187 | 5394 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5395 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5396 | printf_filtered (".\n"); |
5397 | } | |
5398 | } | |
5399 | \f | |
5400 | /* Set the default place to put a breakpoint | |
5401 | for the `break' command with no arguments. */ | |
5402 | ||
5403 | void | |
6c95b8df PA |
5404 | set_default_breakpoint (int valid, struct program_space *pspace, |
5405 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5406 | int line) |
c906108c SS |
5407 | { |
5408 | default_breakpoint_valid = valid; | |
6c95b8df | 5409 | default_breakpoint_pspace = pspace; |
c906108c SS |
5410 | default_breakpoint_address = addr; |
5411 | default_breakpoint_symtab = symtab; | |
5412 | default_breakpoint_line = line; | |
5413 | } | |
5414 | ||
e4f237da KB |
5415 | /* Return true iff it is meaningful to use the address member of |
5416 | BPT. For some breakpoint types, the address member is irrelevant | |
5417 | and it makes no sense to attempt to compare it to other addresses | |
5418 | (or use it for any other purpose either). | |
5419 | ||
4a64f543 MS |
5420 | More specifically, each of the following breakpoint types will |
5421 | always have a zero valued address and we don't want to mark | |
5422 | breakpoints of any of these types to be a duplicate of an actual | |
5423 | breakpoint at address zero: | |
e4f237da KB |
5424 | |
5425 | bp_watchpoint | |
2d134ed3 PA |
5426 | bp_catchpoint |
5427 | ||
5428 | */ | |
e4f237da KB |
5429 | |
5430 | static int | |
5431 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5432 | { | |
5433 | enum bptype type = bpt->type; | |
5434 | ||
2d134ed3 PA |
5435 | return (type != bp_watchpoint && type != bp_catchpoint); |
5436 | } | |
5437 | ||
5438 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5439 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5440 | ||
5441 | static int | |
4a64f543 MS |
5442 | watchpoint_locations_match (struct bp_location *loc1, |
5443 | struct bp_location *loc2) | |
2d134ed3 | 5444 | { |
2bdf28a0 JK |
5445 | /* Both of them must not be in moribund_locations. */ |
5446 | gdb_assert (loc1->owner != NULL); | |
5447 | gdb_assert (loc2->owner != NULL); | |
5448 | ||
4a64f543 MS |
5449 | /* If the target can evaluate the condition expression in hardware, |
5450 | then we we need to insert both watchpoints even if they are at | |
5451 | the same place. Otherwise the watchpoint will only trigger when | |
5452 | the condition of whichever watchpoint was inserted evaluates to | |
5453 | true, not giving a chance for GDB to check the condition of the | |
5454 | other watchpoint. */ | |
0cf6dd15 | 5455 | if ((loc1->owner->cond_exp |
4a64f543 MS |
5456 | && target_can_accel_watchpoint_condition (loc1->address, |
5457 | loc1->length, | |
0cf6dd15 TJB |
5458 | loc1->watchpoint_type, |
5459 | loc1->owner->cond_exp)) | |
5460 | || (loc2->owner->cond_exp | |
4a64f543 MS |
5461 | && target_can_accel_watchpoint_condition (loc2->address, |
5462 | loc2->length, | |
0cf6dd15 TJB |
5463 | loc2->watchpoint_type, |
5464 | loc2->owner->cond_exp))) | |
5465 | return 0; | |
5466 | ||
85d721b8 PA |
5467 | /* Note that this checks the owner's type, not the location's. In |
5468 | case the target does not support read watchpoints, but does | |
5469 | support access watchpoints, we'll have bp_read_watchpoint | |
5470 | watchpoints with hw_access locations. Those should be considered | |
5471 | duplicates of hw_read locations. The hw_read locations will | |
5472 | become hw_access locations later. */ | |
2d134ed3 PA |
5473 | return (loc1->owner->type == loc2->owner->type |
5474 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5475 | && loc1->address == loc2->address | |
5476 | && loc1->length == loc2->length); | |
e4f237da KB |
5477 | } |
5478 | ||
6c95b8df PA |
5479 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5480 | same breakpoint location. In most targets, this can only be true | |
5481 | if ASPACE1 matches ASPACE2. On targets that have global | |
5482 | breakpoints, the address space doesn't really matter. */ | |
5483 | ||
5484 | static int | |
5485 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5486 | struct address_space *aspace2, CORE_ADDR addr2) | |
5487 | { | |
5488 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5489 | || aspace1 == aspace2) | |
5490 | && addr1 == addr2); | |
5491 | } | |
5492 | ||
2d134ed3 PA |
5493 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5494 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5495 | represent the same location. */ | |
5496 | ||
5497 | static int | |
4a64f543 MS |
5498 | breakpoint_locations_match (struct bp_location *loc1, |
5499 | struct bp_location *loc2) | |
2d134ed3 | 5500 | { |
2bdf28a0 JK |
5501 | int hw_point1, hw_point2; |
5502 | ||
5503 | /* Both of them must not be in moribund_locations. */ | |
5504 | gdb_assert (loc1->owner != NULL); | |
5505 | gdb_assert (loc2->owner != NULL); | |
5506 | ||
5507 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5508 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5509 | |
5510 | if (hw_point1 != hw_point2) | |
5511 | return 0; | |
5512 | else if (hw_point1) | |
5513 | return watchpoint_locations_match (loc1, loc2); | |
5514 | else | |
5515 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5516 | loc2->pspace->aspace, loc2->address); | |
5517 | } | |
5518 | ||
76897487 KB |
5519 | static void |
5520 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5521 | int bnum, int have_bnum) | |
5522 | { | |
f63fbe86 MS |
5523 | /* The longest string possibly returned by hex_string_custom |
5524 | is 50 chars. These must be at least that big for safety. */ | |
5525 | char astr1[64]; | |
5526 | char astr2[64]; | |
76897487 | 5527 | |
bb599908 PH |
5528 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5529 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5530 | if (have_bnum) |
8a3fe4f8 | 5531 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5532 | bnum, astr1, astr2); |
5533 | else | |
8a3fe4f8 | 5534 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5535 | } |
5536 | ||
4a64f543 MS |
5537 | /* Adjust a breakpoint's address to account for architectural |
5538 | constraints on breakpoint placement. Return the adjusted address. | |
5539 | Note: Very few targets require this kind of adjustment. For most | |
5540 | targets, this function is simply the identity function. */ | |
76897487 KB |
5541 | |
5542 | static CORE_ADDR | |
a6d9a66e UW |
5543 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5544 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5545 | { |
a6d9a66e | 5546 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5547 | { |
5548 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5549 | return bpaddr; | |
5550 | } | |
88f7da05 KB |
5551 | else if (bptype == bp_watchpoint |
5552 | || bptype == bp_hardware_watchpoint | |
5553 | || bptype == bp_read_watchpoint | |
5554 | || bptype == bp_access_watchpoint | |
fe798b75 | 5555 | || bptype == bp_catchpoint) |
88f7da05 KB |
5556 | { |
5557 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5558 | have their addresses modified. */ | |
5559 | return bpaddr; | |
5560 | } | |
76897487 KB |
5561 | else |
5562 | { | |
5563 | CORE_ADDR adjusted_bpaddr; | |
5564 | ||
5565 | /* Some targets have architectural constraints on the placement | |
5566 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5567 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5568 | |
5569 | /* An adjusted breakpoint address can significantly alter | |
5570 | a user's expectations. Print a warning if an adjustment | |
5571 | is required. */ | |
5572 | if (adjusted_bpaddr != bpaddr) | |
5573 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5574 | ||
5575 | return adjusted_bpaddr; | |
5576 | } | |
5577 | } | |
5578 | ||
7cc221ef DJ |
5579 | /* Allocate a struct bp_location. */ |
5580 | ||
26bb91f3 | 5581 | static struct bp_location * |
39d61571 | 5582 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5583 | { |
afe38095 | 5584 | struct bp_location *loc; |
7cc221ef DJ |
5585 | |
5586 | loc = xmalloc (sizeof (struct bp_location)); | |
5587 | memset (loc, 0, sizeof (*loc)); | |
5588 | ||
e049a4b5 | 5589 | loc->owner = bpt; |
511a6cd4 | 5590 | loc->cond = NULL; |
0d381245 VP |
5591 | loc->shlib_disabled = 0; |
5592 | loc->enabled = 1; | |
e049a4b5 | 5593 | |
39d61571 | 5594 | switch (bpt->type) |
e049a4b5 DJ |
5595 | { |
5596 | case bp_breakpoint: | |
5597 | case bp_until: | |
5598 | case bp_finish: | |
5599 | case bp_longjmp: | |
5600 | case bp_longjmp_resume: | |
186c406b TT |
5601 | case bp_exception: |
5602 | case bp_exception_resume: | |
e049a4b5 | 5603 | case bp_step_resume: |
e049a4b5 DJ |
5604 | case bp_watchpoint_scope: |
5605 | case bp_call_dummy: | |
aa7d318d | 5606 | case bp_std_terminate: |
e049a4b5 DJ |
5607 | case bp_shlib_event: |
5608 | case bp_thread_event: | |
5609 | case bp_overlay_event: | |
4efc6507 | 5610 | case bp_jit_event: |
0fd8e87f | 5611 | case bp_longjmp_master: |
aa7d318d | 5612 | case bp_std_terminate_master: |
186c406b | 5613 | case bp_exception_master: |
e049a4b5 DJ |
5614 | loc->loc_type = bp_loc_software_breakpoint; |
5615 | break; | |
5616 | case bp_hardware_breakpoint: | |
5617 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5618 | break; | |
5619 | case bp_hardware_watchpoint: | |
5620 | case bp_read_watchpoint: | |
5621 | case bp_access_watchpoint: | |
5622 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5623 | break; | |
5624 | case bp_watchpoint: | |
ce78b96d | 5625 | case bp_catchpoint: |
15c3d785 PA |
5626 | case bp_tracepoint: |
5627 | case bp_fast_tracepoint: | |
0fb4aa4b | 5628 | case bp_static_tracepoint: |
e049a4b5 DJ |
5629 | loc->loc_type = bp_loc_other; |
5630 | break; | |
5631 | default: | |
e2e0b3e5 | 5632 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5633 | } |
5634 | ||
f431efe5 | 5635 | loc->refc = 1; |
7cc221ef DJ |
5636 | return loc; |
5637 | } | |
5638 | ||
f431efe5 PA |
5639 | static void |
5640 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5641 | { |
5642 | if (loc->cond) | |
5643 | xfree (loc->cond); | |
74960c60 VP |
5644 | |
5645 | if (loc->function_name) | |
5646 | xfree (loc->function_name); | |
f431efe5 | 5647 | |
fe3f5fa8 VP |
5648 | xfree (loc); |
5649 | } | |
5650 | ||
f431efe5 PA |
5651 | /* Increment reference count. */ |
5652 | ||
5653 | static void | |
5654 | incref_bp_location (struct bp_location *bl) | |
5655 | { | |
5656 | ++bl->refc; | |
5657 | } | |
5658 | ||
5659 | /* Decrement reference count. If the reference count reaches 0, | |
5660 | destroy the bp_location. Sets *BLP to NULL. */ | |
5661 | ||
5662 | static void | |
5663 | decref_bp_location (struct bp_location **blp) | |
5664 | { | |
0807b50c PA |
5665 | gdb_assert ((*blp)->refc > 0); |
5666 | ||
f431efe5 PA |
5667 | if (--(*blp)->refc == 0) |
5668 | free_bp_location (*blp); | |
5669 | *blp = NULL; | |
5670 | } | |
5671 | ||
4a64f543 MS |
5672 | /* Helper to set_raw_breakpoint below. Creates a breakpoint that has |
5673 | type BPTYPE and has no locations as yet. */ | |
5674 | /* This function is used in gdbtk sources and thus can not be made | |
5675 | static. */ | |
c906108c | 5676 | |
c40e75cd | 5677 | static struct breakpoint * |
a6d9a66e UW |
5678 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5679 | enum bptype bptype) | |
c906108c | 5680 | { |
52f0bd74 | 5681 | struct breakpoint *b, *b1; |
c906108c SS |
5682 | |
5683 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5684 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5685 | |
4d28f7a8 | 5686 | b->type = bptype; |
a6d9a66e | 5687 | b->gdbarch = gdbarch; |
c906108c SS |
5688 | b->language = current_language->la_language; |
5689 | b->input_radix = input_radix; | |
5690 | b->thread = -1; | |
b5de0fa7 | 5691 | b->enable_state = bp_enabled; |
c906108c SS |
5692 | b->next = 0; |
5693 | b->silent = 0; | |
5694 | b->ignore_count = 0; | |
5695 | b->commands = NULL; | |
818dd999 | 5696 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5697 | b->forked_inferior_pid = null_ptid; |
c906108c | 5698 | b->exec_pathname = NULL; |
a96d9b2e | 5699 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5700 | b->ops = NULL; |
0d381245 | 5701 | b->condition_not_parsed = 0; |
84f4c1fe | 5702 | b->py_bp_object = NULL; |
c906108c | 5703 | |
4a64f543 MS |
5704 | /* Add this breakpoint to the end of the chain so that a list of |
5705 | breakpoints will come out in order of increasing numbers. */ | |
c906108c SS |
5706 | |
5707 | b1 = breakpoint_chain; | |
5708 | if (b1 == 0) | |
5709 | breakpoint_chain = b; | |
5710 | else | |
5711 | { | |
5712 | while (b1->next) | |
5713 | b1 = b1->next; | |
5714 | b1->next = b; | |
5715 | } | |
0d381245 VP |
5716 | return b; |
5717 | } | |
5718 | ||
5719 | /* Initialize loc->function_name. */ | |
5720 | static void | |
5721 | set_breakpoint_location_function (struct bp_location *loc) | |
5722 | { | |
2bdf28a0 JK |
5723 | gdb_assert (loc->owner != NULL); |
5724 | ||
0d381245 | 5725 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5726 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5727 | || is_tracepoint (loc->owner)) |
0d381245 VP |
5728 | { |
5729 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5730 | NULL, NULL); | |
5731 | if (loc->function_name) | |
5732 | loc->function_name = xstrdup (loc->function_name); | |
5733 | } | |
5734 | } | |
5735 | ||
a6d9a66e UW |
5736 | /* Attempt to determine architecture of location identified by SAL. */ |
5737 | static struct gdbarch * | |
5738 | get_sal_arch (struct symtab_and_line sal) | |
5739 | { | |
5740 | if (sal.section) | |
5741 | return get_objfile_arch (sal.section->objfile); | |
5742 | if (sal.symtab) | |
5743 | return get_objfile_arch (sal.symtab->objfile); | |
5744 | ||
5745 | return NULL; | |
5746 | } | |
5747 | ||
0d381245 VP |
5748 | /* set_raw_breakpoint is a low level routine for allocating and |
5749 | partially initializing a breakpoint of type BPTYPE. The newly | |
5750 | created breakpoint's address, section, source file name, and line | |
5751 | number are provided by SAL. The newly created and partially | |
5752 | initialized breakpoint is added to the breakpoint chain and | |
5753 | is also returned as the value of this function. | |
5754 | ||
5755 | It is expected that the caller will complete the initialization of | |
5756 | the newly created breakpoint struct as well as output any status | |
5757 | information regarding the creation of a new breakpoint. In | |
5758 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5759 | number! Care should be taken to not allow an error to occur | |
5760 | prior to completing the initialization of the breakpoint. If this | |
5761 | should happen, a bogus breakpoint will be left on the chain. */ | |
5762 | ||
63c252f8 | 5763 | struct breakpoint * |
a6d9a66e UW |
5764 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5765 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5766 | { |
4a64f543 MS |
5767 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, |
5768 | bptype); | |
0d381245 | 5769 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5770 | struct gdbarch *loc_gdbarch; |
5771 | ||
5772 | loc_gdbarch = get_sal_arch (sal); | |
5773 | if (!loc_gdbarch) | |
5774 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5775 | |
6c95b8df PA |
5776 | if (bptype != bp_catchpoint) |
5777 | gdb_assert (sal.pspace != NULL); | |
5778 | ||
0d381245 VP |
5779 | /* Adjust the breakpoint's address prior to allocating a location. |
5780 | Once we call allocate_bp_location(), that mostly uninitialized | |
5781 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5782 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5783 | not want its scan of the location chain to find a breakpoint and |
5784 | location that's only been partially initialized. */ | |
4a64f543 MS |
5785 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5786 | sal.pc, b->type); | |
0d381245 | 5787 | |
39d61571 | 5788 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5789 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5790 | b->loc->requested_address = sal.pc; |
5791 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5792 | b->loc->pspace = sal.pspace; |
5793 | ||
5794 | /* Store the program space that was used to set the breakpoint, for | |
5795 | breakpoint resetting. */ | |
5796 | b->pspace = sal.pspace; | |
0d381245 VP |
5797 | |
5798 | if (sal.symtab == NULL) | |
5799 | b->source_file = NULL; | |
5800 | else | |
1b36a34b | 5801 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5802 | b->loc->section = sal.section; |
5803 | b->line_number = sal.line; | |
5804 | ||
5805 | set_breakpoint_location_function (b->loc); | |
c906108c | 5806 | |
c906108c SS |
5807 | breakpoints_changed (); |
5808 | ||
5809 | return b; | |
5810 | } | |
5811 | ||
c2c6d25f JM |
5812 | |
5813 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5814 | instruction, hard-wired into the inferior's code. */ | |
5815 | void | |
5816 | make_breakpoint_permanent (struct breakpoint *b) | |
5817 | { | |
0d381245 | 5818 | struct bp_location *bl; |
cc59ec59 | 5819 | |
b5de0fa7 | 5820 | b->enable_state = bp_permanent; |
c2c6d25f | 5821 | |
4a64f543 MS |
5822 | /* By definition, permanent breakpoints are already present in the |
5823 | code. Mark all locations as inserted. For now, | |
5824 | make_breakpoint_permanent is called in just one place, so it's | |
5825 | hard to say if it's reasonable to have permanent breakpoint with | |
5826 | multiple locations or not, but it's easy to implmement. */ | |
0d381245 VP |
5827 | for (bl = b->loc; bl; bl = bl->next) |
5828 | bl->inserted = 1; | |
c2c6d25f JM |
5829 | } |
5830 | ||
53a5351d | 5831 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5832 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5833 | initiated the operation. */ | |
c906108c SS |
5834 | |
5835 | void | |
186c406b | 5836 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5837 | { |
35df4500 | 5838 | struct breakpoint *b, *b_tmp; |
186c406b | 5839 | int thread = tp->num; |
0fd8e87f UW |
5840 | |
5841 | /* To avoid having to rescan all objfile symbols at every step, | |
5842 | we maintain a list of continually-inserted but always disabled | |
5843 | longjmp "master" breakpoints. Here, we simply create momentary | |
5844 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5845 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5846 | if (b->pspace == current_program_space |
186c406b TT |
5847 | && (b->type == bp_longjmp_master |
5848 | || b->type == bp_exception_master)) | |
0fd8e87f UW |
5849 | { |
5850 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5851 | |
186c406b | 5852 | clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
0fd8e87f UW |
5853 | clone->thread = thread; |
5854 | } | |
186c406b TT |
5855 | |
5856 | tp->initiating_frame = frame; | |
c906108c SS |
5857 | } |
5858 | ||
611c83ae | 5859 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5860 | void |
611c83ae | 5861 | delete_longjmp_breakpoint (int thread) |
c906108c | 5862 | { |
35df4500 | 5863 | struct breakpoint *b, *b_tmp; |
c906108c | 5864 | |
35df4500 | 5865 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5866 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5867 | { |
5868 | if (b->thread == thread) | |
5869 | delete_breakpoint (b); | |
5870 | } | |
c906108c SS |
5871 | } |
5872 | ||
1900040c MS |
5873 | void |
5874 | enable_overlay_breakpoints (void) | |
5875 | { | |
52f0bd74 | 5876 | struct breakpoint *b; |
1900040c MS |
5877 | |
5878 | ALL_BREAKPOINTS (b) | |
5879 | if (b->type == bp_overlay_event) | |
5880 | { | |
5881 | b->enable_state = bp_enabled; | |
b60e7edf | 5882 | update_global_location_list (1); |
c02f5703 | 5883 | overlay_events_enabled = 1; |
1900040c MS |
5884 | } |
5885 | } | |
5886 | ||
5887 | void | |
5888 | disable_overlay_breakpoints (void) | |
5889 | { | |
52f0bd74 | 5890 | struct breakpoint *b; |
1900040c MS |
5891 | |
5892 | ALL_BREAKPOINTS (b) | |
5893 | if (b->type == bp_overlay_event) | |
5894 | { | |
5895 | b->enable_state = bp_disabled; | |
b60e7edf | 5896 | update_global_location_list (0); |
c02f5703 | 5897 | overlay_events_enabled = 0; |
1900040c MS |
5898 | } |
5899 | } | |
5900 | ||
aa7d318d TT |
5901 | /* Set an active std::terminate breakpoint for each std::terminate |
5902 | master breakpoint. */ | |
5903 | void | |
5904 | set_std_terminate_breakpoint (void) | |
5905 | { | |
35df4500 | 5906 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5907 | |
35df4500 | 5908 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5909 | if (b->pspace == current_program_space |
5910 | && b->type == bp_std_terminate_master) | |
5911 | { | |
5912 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5913 | clone->type = bp_std_terminate; | |
5914 | } | |
5915 | } | |
5916 | ||
5917 | /* Delete all the std::terminate breakpoints. */ | |
5918 | void | |
5919 | delete_std_terminate_breakpoint (void) | |
5920 | { | |
35df4500 | 5921 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5922 | |
35df4500 | 5923 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5924 | if (b->type == bp_std_terminate) |
5925 | delete_breakpoint (b); | |
5926 | } | |
5927 | ||
c4093a6a | 5928 | struct breakpoint * |
a6d9a66e | 5929 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5930 | { |
5931 | struct breakpoint *b; | |
c4093a6a | 5932 | |
a6d9a66e | 5933 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5934 | |
b5de0fa7 | 5935 | b->enable_state = bp_enabled; |
c4093a6a | 5936 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5937 | b->addr_string |
5938 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5939 | |
b60e7edf | 5940 | update_global_location_list_nothrow (1); |
74960c60 | 5941 | |
c4093a6a JM |
5942 | return b; |
5943 | } | |
5944 | ||
5945 | void | |
5946 | remove_thread_event_breakpoints (void) | |
5947 | { | |
35df4500 | 5948 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5949 | |
35df4500 | 5950 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5951 | if (b->type == bp_thread_event |
5952 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5953 | delete_breakpoint (b); |
5954 | } | |
5955 | ||
0101ce28 JJ |
5956 | struct captured_parse_breakpoint_args |
5957 | { | |
5958 | char **arg_p; | |
5959 | struct symtabs_and_lines *sals_p; | |
7efd8fc2 | 5960 | struct linespec_result *canonical_p; |
0101ce28 JJ |
5961 | int *not_found_ptr; |
5962 | }; | |
5963 | ||
5964 | struct lang_and_radix | |
5965 | { | |
5966 | enum language lang; | |
5967 | int radix; | |
5968 | }; | |
5969 | ||
4efc6507 DE |
5970 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5971 | ||
5972 | struct breakpoint * | |
5973 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5974 | { | |
5975 | struct breakpoint *b; | |
5976 | ||
5977 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5978 | update_global_location_list_nothrow (1); | |
5979 | return b; | |
5980 | } | |
0101ce28 | 5981 | |
03673fc7 PP |
5982 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
5983 | ||
5984 | void | |
5985 | remove_jit_event_breakpoints (void) | |
5986 | { | |
5987 | struct breakpoint *b, *b_tmp; | |
5988 | ||
5989 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5990 | if (b->type == bp_jit_event | |
5991 | && b->loc->pspace == current_program_space) | |
5992 | delete_breakpoint (b); | |
5993 | } | |
5994 | ||
cae688ec JJ |
5995 | void |
5996 | remove_solib_event_breakpoints (void) | |
5997 | { | |
35df4500 | 5998 | struct breakpoint *b, *b_tmp; |
cae688ec | 5999 | |
35df4500 | 6000 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6001 | if (b->type == bp_shlib_event |
6002 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6003 | delete_breakpoint (b); |
6004 | } | |
6005 | ||
6006 | struct breakpoint * | |
a6d9a66e | 6007 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6008 | { |
6009 | struct breakpoint *b; | |
6010 | ||
a6d9a66e | 6011 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 6012 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6013 | return b; |
6014 | } | |
6015 | ||
6016 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6017 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6018 | ||
6019 | void | |
cb851954 | 6020 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6021 | { |
876fa593 | 6022 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6023 | |
876fa593 | 6024 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6025 | { |
2bdf28a0 | 6026 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6027 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6028 | |
4a64f543 MS |
6029 | /* We apply the check to all breakpoints, including disabled for |
6030 | those with loc->duplicate set. This is so that when breakpoint | |
6031 | becomes enabled, or the duplicate is removed, gdb will try to | |
6032 | insert all breakpoints. If we don't set shlib_disabled here, | |
6033 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6034 | if (((b->type == bp_breakpoint) |
508ccb1f | 6035 | || (b->type == bp_jit_event) |
1042e4c0 | 6036 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6037 | || (is_tracepoint (b))) |
6c95b8df | 6038 | && loc->pspace == current_program_space |
0d381245 | 6039 | && !loc->shlib_disabled |
a77053c2 | 6040 | #ifdef PC_SOLIB |
0d381245 | 6041 | && PC_SOLIB (loc->address) |
a77053c2 | 6042 | #else |
6c95b8df | 6043 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6044 | #endif |
6045 | ) | |
0d381245 VP |
6046 | { |
6047 | loc->shlib_disabled = 1; | |
6048 | } | |
cae688ec JJ |
6049 | } |
6050 | } | |
6051 | ||
4a64f543 MS |
6052 | /* Disable any breakpoints that are in in an unloaded shared library. |
6053 | Only apply to enabled breakpoints, disabled ones can just stay | |
6054 | disabled. */ | |
84acb35a | 6055 | |
75149521 | 6056 | static void |
84acb35a JJ |
6057 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6058 | { | |
876fa593 | 6059 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6060 | int disabled_shlib_breaks = 0; |
6061 | ||
c86cf029 VP |
6062 | /* SunOS a.out shared libraries are always mapped, so do not |
6063 | disable breakpoints; they will only be reported as unloaded | |
6064 | through clear_solib when GDB discards its shared library | |
6065 | list. See clear_solib for more information. */ | |
6066 | if (exec_bfd != NULL | |
6067 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6068 | return; | |
6069 | ||
876fa593 | 6070 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6071 | { |
2bdf28a0 | 6072 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6073 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6074 | |
0d381245 VP |
6075 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6076 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6077 | && solib->pspace == loc->pspace |
e2dd7057 | 6078 | && !loc->shlib_disabled |
508ccb1f TT |
6079 | && (b->type == bp_breakpoint |
6080 | || b->type == bp_jit_event | |
6081 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6082 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6083 | { |
e2dd7057 PP |
6084 | loc->shlib_disabled = 1; |
6085 | /* At this point, we cannot rely on remove_breakpoint | |
6086 | succeeding so we must mark the breakpoint as not inserted | |
6087 | to prevent future errors occurring in remove_breakpoints. */ | |
6088 | loc->inserted = 0; | |
6089 | if (!disabled_shlib_breaks) | |
6090 | { | |
6091 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6092 | warning (_("Temporarily disabling breakpoints " |
6093 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6094 | solib->so_name); |
84acb35a | 6095 | } |
e2dd7057 | 6096 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6097 | } |
6098 | } | |
84acb35a JJ |
6099 | } |
6100 | ||
ce78b96d JB |
6101 | /* FORK & VFORK catchpoints. */ |
6102 | ||
4a64f543 MS |
6103 | /* Implement the "insert" breakpoint_ops method for fork |
6104 | catchpoints. */ | |
ce78b96d | 6105 | |
77b06cd7 TJB |
6106 | static int |
6107 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6108 | { |
77b06cd7 | 6109 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6110 | } |
6111 | ||
4a64f543 MS |
6112 | /* Implement the "remove" breakpoint_ops method for fork |
6113 | catchpoints. */ | |
ce78b96d JB |
6114 | |
6115 | static int | |
77b06cd7 | 6116 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6117 | { |
6118 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6119 | } | |
6120 | ||
6121 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6122 | catchpoints. */ | |
6123 | ||
6124 | static int | |
6125 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
6126 | { | |
6127 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
6128 | } | |
6129 | ||
4a64f543 MS |
6130 | /* Implement the "print_it" breakpoint_ops method for fork |
6131 | catchpoints. */ | |
ce78b96d JB |
6132 | |
6133 | static enum print_stop_action | |
6134 | print_it_catch_fork (struct breakpoint *b) | |
6135 | { | |
6136 | annotate_catchpoint (b->number); | |
6137 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
6138 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6139 | return PRINT_SRC_AND_LOC; | |
6140 | } | |
6141 | ||
4a64f543 MS |
6142 | /* Implement the "print_one" breakpoint_ops method for fork |
6143 | catchpoints. */ | |
ce78b96d JB |
6144 | |
6145 | static void | |
a6d9a66e | 6146 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6147 | { |
79a45b7d TT |
6148 | struct value_print_options opts; |
6149 | ||
6150 | get_user_print_options (&opts); | |
6151 | ||
4a64f543 MS |
6152 | /* Field 4, the address, is omitted (which makes the columns not |
6153 | line up too nicely with the headers, but the effect is relatively | |
6154 | readable). */ | |
79a45b7d | 6155 | if (opts.addressprint) |
ce78b96d JB |
6156 | ui_out_field_skip (uiout, "addr"); |
6157 | annotate_field (5); | |
6158 | ui_out_text (uiout, "fork"); | |
6159 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6160 | { | |
6161 | ui_out_text (uiout, ", process "); | |
6162 | ui_out_field_int (uiout, "what", | |
6163 | ptid_get_pid (b->forked_inferior_pid)); | |
6164 | ui_out_spaces (uiout, 1); | |
6165 | } | |
6166 | } | |
6167 | ||
6168 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6169 | catchpoints. */ | |
6170 | ||
6171 | static void | |
6172 | print_mention_catch_fork (struct breakpoint *b) | |
6173 | { | |
6174 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6175 | } | |
6176 | ||
6149aea9 PA |
6177 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6178 | catchpoints. */ | |
6179 | ||
6180 | static void | |
6181 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6182 | { | |
6183 | fprintf_unfiltered (fp, "catch fork"); | |
6184 | } | |
6185 | ||
ce78b96d JB |
6186 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6187 | ||
6188 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
6189 | { | |
6190 | insert_catch_fork, | |
6191 | remove_catch_fork, | |
6192 | breakpoint_hit_catch_fork, | |
e09342b5 | 6193 | NULL, /* resources_needed */ |
ce78b96d JB |
6194 | print_it_catch_fork, |
6195 | print_one_catch_fork, | |
6149aea9 PA |
6196 | print_mention_catch_fork, |
6197 | print_recreate_catch_fork | |
ce78b96d JB |
6198 | }; |
6199 | ||
4a64f543 MS |
6200 | /* Implement the "insert" breakpoint_ops method for vfork |
6201 | catchpoints. */ | |
ce78b96d | 6202 | |
77b06cd7 TJB |
6203 | static int |
6204 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6205 | { |
77b06cd7 | 6206 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6207 | } |
6208 | ||
4a64f543 MS |
6209 | /* Implement the "remove" breakpoint_ops method for vfork |
6210 | catchpoints. */ | |
ce78b96d JB |
6211 | |
6212 | static int | |
77b06cd7 | 6213 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6214 | { |
6215 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6216 | } | |
6217 | ||
6218 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6219 | catchpoints. */ | |
6220 | ||
6221 | static int | |
6222 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
6223 | { | |
6224 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
6225 | } | |
6226 | ||
4a64f543 MS |
6227 | /* Implement the "print_it" breakpoint_ops method for vfork |
6228 | catchpoints. */ | |
ce78b96d JB |
6229 | |
6230 | static enum print_stop_action | |
6231 | print_it_catch_vfork (struct breakpoint *b) | |
6232 | { | |
6233 | annotate_catchpoint (b->number); | |
6234 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
6235 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6236 | return PRINT_SRC_AND_LOC; | |
6237 | } | |
6238 | ||
4a64f543 MS |
6239 | /* Implement the "print_one" breakpoint_ops method for vfork |
6240 | catchpoints. */ | |
ce78b96d JB |
6241 | |
6242 | static void | |
a6d9a66e | 6243 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6244 | { |
79a45b7d TT |
6245 | struct value_print_options opts; |
6246 | ||
6247 | get_user_print_options (&opts); | |
4a64f543 MS |
6248 | /* Field 4, the address, is omitted (which makes the columns not |
6249 | line up too nicely with the headers, but the effect is relatively | |
6250 | readable). */ | |
79a45b7d | 6251 | if (opts.addressprint) |
ce78b96d JB |
6252 | ui_out_field_skip (uiout, "addr"); |
6253 | annotate_field (5); | |
6254 | ui_out_text (uiout, "vfork"); | |
6255 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6256 | { | |
6257 | ui_out_text (uiout, ", process "); | |
6258 | ui_out_field_int (uiout, "what", | |
6259 | ptid_get_pid (b->forked_inferior_pid)); | |
6260 | ui_out_spaces (uiout, 1); | |
6261 | } | |
6262 | } | |
6263 | ||
6264 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6265 | catchpoints. */ | |
6266 | ||
6267 | static void | |
6268 | print_mention_catch_vfork (struct breakpoint *b) | |
6269 | { | |
6270 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6271 | } | |
6272 | ||
6149aea9 PA |
6273 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6274 | catchpoints. */ | |
6275 | ||
6276 | static void | |
6277 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6278 | { | |
6279 | fprintf_unfiltered (fp, "catch vfork"); | |
6280 | } | |
6281 | ||
ce78b96d JB |
6282 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6283 | ||
6284 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6285 | { | |
6286 | insert_catch_vfork, | |
6287 | remove_catch_vfork, | |
6288 | breakpoint_hit_catch_vfork, | |
e09342b5 | 6289 | NULL, /* resources_needed */ |
ce78b96d JB |
6290 | print_it_catch_vfork, |
6291 | print_one_catch_vfork, | |
6149aea9 PA |
6292 | print_mention_catch_vfork, |
6293 | print_recreate_catch_vfork | |
ce78b96d JB |
6294 | }; |
6295 | ||
a96d9b2e SDJ |
6296 | /* Implement the "insert" breakpoint_ops method for syscall |
6297 | catchpoints. */ | |
6298 | ||
77b06cd7 TJB |
6299 | static int |
6300 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e SDJ |
6301 | { |
6302 | struct inferior *inf = current_inferior (); | |
6303 | ||
6304 | ++inf->total_syscalls_count; | |
77b06cd7 | 6305 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6306 | ++inf->any_syscall_count; |
6307 | else | |
6308 | { | |
6309 | int i, iter; | |
cc59ec59 | 6310 | |
a96d9b2e | 6311 | for (i = 0; |
77b06cd7 | 6312 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6313 | i++) |
6314 | { | |
6315 | int elem; | |
cc59ec59 | 6316 | |
a96d9b2e SDJ |
6317 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6318 | { | |
6319 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6320 | uintptr_t vec_addr_offset |
6321 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6322 | uintptr_t vec_addr; |
6323 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6324 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6325 | vec_addr_offset; | |
6326 | memset ((void *) vec_addr, 0, | |
6327 | (iter + 1 - old_size) * sizeof (int)); | |
6328 | } | |
6329 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6330 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6331 | } | |
6332 | } | |
6333 | ||
77b06cd7 TJB |
6334 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6335 | inf->total_syscalls_count != 0, | |
6336 | inf->any_syscall_count, | |
6337 | VEC_length (int, inf->syscalls_counts), | |
6338 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6339 | } |
6340 | ||
6341 | /* Implement the "remove" breakpoint_ops method for syscall | |
6342 | catchpoints. */ | |
6343 | ||
6344 | static int | |
77b06cd7 | 6345 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e SDJ |
6346 | { |
6347 | struct inferior *inf = current_inferior (); | |
6348 | ||
6349 | --inf->total_syscalls_count; | |
77b06cd7 | 6350 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6351 | --inf->any_syscall_count; |
6352 | else | |
6353 | { | |
6354 | int i, iter; | |
cc59ec59 | 6355 | |
a96d9b2e | 6356 | for (i = 0; |
77b06cd7 | 6357 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6358 | i++) |
6359 | { | |
6360 | int elem; | |
6361 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6362 | /* Shouldn't happen. */ | |
6363 | continue; | |
6364 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6365 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6366 | } | |
6367 | } | |
6368 | ||
6369 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6370 | inf->total_syscalls_count != 0, | |
6371 | inf->any_syscall_count, | |
6372 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6373 | VEC_address (int, |
6374 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6375 | } |
6376 | ||
6377 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6378 | catchpoints. */ | |
6379 | ||
6380 | static int | |
6381 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6382 | { | |
4a64f543 MS |
6383 | /* We must check if we are catching specific syscalls in this |
6384 | breakpoint. If we are, then we must guarantee that the called | |
6385 | syscall is the same syscall we are catching. */ | |
a96d9b2e SDJ |
6386 | int syscall_number = 0; |
6387 | ||
6388 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6389 | return 0; | |
6390 | ||
6391 | /* Now, checking if the syscall is the same. */ | |
6392 | if (b->syscalls_to_be_caught) | |
6393 | { | |
6394 | int i, iter; | |
cc59ec59 | 6395 | |
a96d9b2e SDJ |
6396 | for (i = 0; |
6397 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6398 | i++) | |
6399 | if (syscall_number == iter) | |
6400 | break; | |
6401 | /* Not the same. */ | |
6402 | if (!iter) | |
6403 | return 0; | |
6404 | } | |
6405 | ||
6406 | return 1; | |
6407 | } | |
6408 | ||
6409 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6410 | catchpoints. */ | |
6411 | ||
6412 | static enum print_stop_action | |
6413 | print_it_catch_syscall (struct breakpoint *b) | |
6414 | { | |
6415 | /* These are needed because we want to know in which state a | |
6416 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6417 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6418 | must print "called syscall" or "returned from syscall". */ | |
6419 | ptid_t ptid; | |
6420 | struct target_waitstatus last; | |
6421 | struct syscall s; | |
6422 | struct cleanup *old_chain; | |
6423 | char *syscall_id; | |
6424 | ||
6425 | get_last_target_status (&ptid, &last); | |
6426 | ||
6427 | get_syscall_by_number (last.value.syscall_number, &s); | |
6428 | ||
6429 | annotate_catchpoint (b->number); | |
6430 | ||
6431 | if (s.name == NULL) | |
6432 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6433 | else | |
6434 | syscall_id = xstrprintf ("'%s'", s.name); | |
6435 | ||
6436 | old_chain = make_cleanup (xfree, syscall_id); | |
6437 | ||
6438 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6439 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6440 | b->number, syscall_id); | |
6441 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6442 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6443 | b->number, syscall_id); | |
6444 | ||
6445 | do_cleanups (old_chain); | |
6446 | ||
6447 | return PRINT_SRC_AND_LOC; | |
6448 | } | |
6449 | ||
6450 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6451 | catchpoints. */ | |
6452 | ||
6453 | static void | |
6454 | print_one_catch_syscall (struct breakpoint *b, | |
6455 | struct bp_location **last_loc) | |
6456 | { | |
6457 | struct value_print_options opts; | |
6458 | ||
6459 | get_user_print_options (&opts); | |
4a64f543 MS |
6460 | /* Field 4, the address, is omitted (which makes the columns not |
6461 | line up too nicely with the headers, but the effect is relatively | |
6462 | readable). */ | |
a96d9b2e SDJ |
6463 | if (opts.addressprint) |
6464 | ui_out_field_skip (uiout, "addr"); | |
6465 | annotate_field (5); | |
6466 | ||
6467 | if (b->syscalls_to_be_caught | |
6468 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6469 | ui_out_text (uiout, "syscalls \""); | |
6470 | else | |
6471 | ui_out_text (uiout, "syscall \""); | |
6472 | ||
6473 | if (b->syscalls_to_be_caught) | |
6474 | { | |
6475 | int i, iter; | |
6476 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6477 | |
a96d9b2e SDJ |
6478 | for (i = 0; |
6479 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6480 | i++) | |
6481 | { | |
6482 | char *x = text; | |
6483 | struct syscall s; | |
6484 | get_syscall_by_number (iter, &s); | |
6485 | ||
6486 | if (s.name != NULL) | |
6487 | text = xstrprintf ("%s%s, ", text, s.name); | |
6488 | else | |
6489 | text = xstrprintf ("%s%d, ", text, iter); | |
6490 | ||
6491 | /* We have to xfree the last 'text' (now stored at 'x') | |
6492 | because xstrprintf dinamically allocates new space for it | |
6493 | on every call. */ | |
6494 | xfree (x); | |
6495 | } | |
6496 | /* Remove the last comma. */ | |
6497 | text[strlen (text) - 2] = '\0'; | |
6498 | ui_out_field_string (uiout, "what", text); | |
6499 | } | |
6500 | else | |
6501 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6502 | ui_out_text (uiout, "\" "); | |
6503 | } | |
6504 | ||
6505 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6506 | catchpoints. */ | |
6507 | ||
6508 | static void | |
6509 | print_mention_catch_syscall (struct breakpoint *b) | |
6510 | { | |
6511 | if (b->syscalls_to_be_caught) | |
6512 | { | |
6513 | int i, iter; | |
6514 | ||
6515 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6516 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6517 | else | |
6518 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6519 | ||
6520 | for (i = 0; | |
6521 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6522 | i++) | |
6523 | { | |
6524 | struct syscall s; | |
6525 | get_syscall_by_number (iter, &s); | |
6526 | ||
6527 | if (s.name) | |
6528 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6529 | else | |
6530 | printf_filtered (" %d", s.number); | |
6531 | } | |
6532 | printf_filtered (")"); | |
6533 | } | |
6534 | else | |
6535 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6536 | b->number); | |
6537 | } | |
6538 | ||
6149aea9 PA |
6539 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6540 | catchpoints. */ | |
6541 | ||
6542 | static void | |
6543 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6544 | { | |
6545 | fprintf_unfiltered (fp, "catch syscall"); | |
6546 | ||
6547 | if (b->syscalls_to_be_caught) | |
6548 | { | |
6549 | int i, iter; | |
6550 | ||
6551 | for (i = 0; | |
6552 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6553 | i++) | |
6554 | { | |
6555 | struct syscall s; | |
6556 | ||
6557 | get_syscall_by_number (iter, &s); | |
6558 | if (s.name) | |
6559 | fprintf_unfiltered (fp, " %s", s.name); | |
6560 | else | |
6561 | fprintf_unfiltered (fp, " %d", s.number); | |
6562 | } | |
6563 | } | |
6564 | } | |
6565 | ||
a96d9b2e SDJ |
6566 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6567 | ||
6568 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6569 | { | |
6570 | insert_catch_syscall, | |
6571 | remove_catch_syscall, | |
6572 | breakpoint_hit_catch_syscall, | |
e09342b5 | 6573 | NULL, /* resources_needed */ |
a96d9b2e SDJ |
6574 | print_it_catch_syscall, |
6575 | print_one_catch_syscall, | |
6149aea9 PA |
6576 | print_mention_catch_syscall, |
6577 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6578 | }; |
6579 | ||
6580 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6581 | ||
6582 | static int | |
6583 | syscall_catchpoint_p (struct breakpoint *b) | |
6584 | { | |
6585 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6586 | } | |
6587 | ||
6588 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6589 | but does NOT mention it nor update the global location list. | |
6590 | This is useful if you need to fill more fields in the | |
6591 | struct breakpoint before calling mention. | |
ce78b96d JB |
6592 | |
6593 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6594 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6595 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6596 | to the catchpoint. */ | |
6597 | ||
6598 | static struct breakpoint * | |
a96d9b2e SDJ |
6599 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6600 | char *cond_string, | |
6601 | struct breakpoint_ops *ops) | |
c906108c | 6602 | { |
c5aa993b JM |
6603 | struct symtab_and_line sal; |
6604 | struct breakpoint *b; | |
c5aa993b | 6605 | |
fe39c653 | 6606 | init_sal (&sal); |
6c95b8df | 6607 | sal.pspace = current_program_space; |
c5aa993b | 6608 | |
a6d9a66e | 6609 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6610 | set_breakpoint_count (breakpoint_count + 1); |
6611 | b->number = breakpoint_count; | |
ce78b96d | 6612 | |
1b36a34b | 6613 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6614 | b->thread = -1; |
c906108c | 6615 | b->addr_string = NULL; |
b5de0fa7 EZ |
6616 | b->enable_state = bp_enabled; |
6617 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6618 | b->ops = ops; |
c5aa993b | 6619 | |
a96d9b2e SDJ |
6620 | return b; |
6621 | } | |
6622 | ||
6623 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6624 | ||
6625 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6626 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6627 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6628 | to the catchpoint. */ | |
6629 | ||
6630 | static struct breakpoint * | |
6631 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6632 | char *cond_string, struct breakpoint_ops *ops) | |
6633 | { | |
6634 | struct breakpoint *b = | |
6635 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6636 | ||
c906108c | 6637 | mention (b); |
ce78b96d | 6638 | update_global_location_list (1); |
c906108c | 6639 | |
ce78b96d | 6640 | return b; |
c906108c | 6641 | } |
c5aa993b | 6642 | |
9b70b993 | 6643 | static void |
a6d9a66e UW |
6644 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6645 | int tempflag, char *cond_string, | |
ce78b96d | 6646 | struct breakpoint_ops *ops) |
c906108c | 6647 | { |
a6d9a66e UW |
6648 | struct breakpoint *b |
6649 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6650 | |
6651 | /* FIXME: We should put this information in a breakpoint private data | |
6652 | area. */ | |
6653 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6654 | } |
6655 | ||
fe798b75 JB |
6656 | /* Exec catchpoints. */ |
6657 | ||
77b06cd7 TJB |
6658 | static int |
6659 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6660 | { |
77b06cd7 | 6661 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6662 | } |
c906108c | 6663 | |
fe798b75 | 6664 | static int |
77b06cd7 | 6665 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6666 | { |
6667 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6668 | } | |
c906108c | 6669 | |
fe798b75 JB |
6670 | static int |
6671 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6672 | { | |
6673 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6674 | } | |
c906108c | 6675 | |
fe798b75 JB |
6676 | static enum print_stop_action |
6677 | print_it_catch_exec (struct breakpoint *b) | |
6678 | { | |
6679 | annotate_catchpoint (b->number); | |
6680 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6681 | b->exec_pathname); | |
6682 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6683 | } |
6684 | ||
fe798b75 | 6685 | static void |
a6d9a66e | 6686 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6687 | { |
6688 | struct value_print_options opts; | |
6689 | ||
6690 | get_user_print_options (&opts); | |
6691 | ||
6692 | /* Field 4, the address, is omitted (which makes the columns | |
6693 | not line up too nicely with the headers, but the effect | |
6694 | is relatively readable). */ | |
6695 | if (opts.addressprint) | |
6696 | ui_out_field_skip (uiout, "addr"); | |
6697 | annotate_field (5); | |
6698 | ui_out_text (uiout, "exec"); | |
6699 | if (b->exec_pathname != NULL) | |
6700 | { | |
6701 | ui_out_text (uiout, ", program \""); | |
6702 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6703 | ui_out_text (uiout, "\" "); | |
6704 | } | |
6705 | } | |
6706 | ||
6707 | static void | |
6708 | print_mention_catch_exec (struct breakpoint *b) | |
6709 | { | |
6710 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6711 | } | |
6712 | ||
6149aea9 PA |
6713 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6714 | catchpoints. */ | |
6715 | ||
6716 | static void | |
6717 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6718 | { | |
6719 | fprintf_unfiltered (fp, "catch exec"); | |
6720 | } | |
6721 | ||
fe798b75 JB |
6722 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6723 | { | |
6724 | insert_catch_exec, | |
6725 | remove_catch_exec, | |
6726 | breakpoint_hit_catch_exec, | |
e09342b5 | 6727 | NULL, /* resources_needed */ |
fe798b75 JB |
6728 | print_it_catch_exec, |
6729 | print_one_catch_exec, | |
6149aea9 PA |
6730 | print_mention_catch_exec, |
6731 | print_recreate_catch_exec | |
fe798b75 JB |
6732 | }; |
6733 | ||
a96d9b2e SDJ |
6734 | static void |
6735 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6736 | struct breakpoint_ops *ops) | |
6737 | { | |
6738 | struct gdbarch *gdbarch = get_current_arch (); | |
6739 | struct breakpoint *b = | |
6740 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6741 | ||
6742 | b->syscalls_to_be_caught = filter; | |
6743 | ||
6744 | /* Now, we have to mention the breakpoint and update the global | |
6745 | location list. */ | |
6746 | mention (b); | |
6747 | update_global_location_list (1); | |
6748 | } | |
6749 | ||
c906108c | 6750 | static int |
fba45db2 | 6751 | hw_breakpoint_used_count (void) |
c906108c | 6752 | { |
52f0bd74 | 6753 | struct breakpoint *b; |
c906108c SS |
6754 | int i = 0; |
6755 | ||
6756 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6757 | { |
d6b74ac4 | 6758 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6759 | i++; |
6760 | } | |
c906108c SS |
6761 | |
6762 | return i; | |
6763 | } | |
6764 | ||
6765 | static int | |
fba45db2 | 6766 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6767 | { |
c906108c | 6768 | int i = 0; |
e09342b5 TJB |
6769 | struct breakpoint *b; |
6770 | struct bp_location *bl; | |
c906108c SS |
6771 | |
6772 | *other_type_used = 0; | |
6773 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6774 | { |
6775 | if (!breakpoint_enabled (b)) | |
6776 | continue; | |
6777 | ||
c5aa993b | 6778 | if (b->type == type) |
e09342b5 TJB |
6779 | for (bl = b->loc; bl; bl = bl->next) |
6780 | { | |
6781 | /* Special types of hardware watchpoints may use more than | |
6782 | one register. */ | |
6783 | if (b->ops && b->ops->resources_needed) | |
6784 | i += b->ops->resources_needed (bl); | |
6785 | else | |
6786 | i++; | |
6787 | } | |
cc60f2e3 | 6788 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6789 | *other_type_used = 1; |
e09342b5 TJB |
6790 | } |
6791 | ||
c906108c SS |
6792 | return i; |
6793 | } | |
6794 | ||
c906108c | 6795 | void |
fba45db2 | 6796 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6797 | { |
c5aa993b | 6798 | struct breakpoint *b; |
c906108c SS |
6799 | |
6800 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6801 | { |
cc60f2e3 | 6802 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6803 | { |
b5de0fa7 | 6804 | b->enable_state = bp_call_disabled; |
b60e7edf | 6805 | update_global_location_list (0); |
c5aa993b JM |
6806 | } |
6807 | } | |
c906108c SS |
6808 | } |
6809 | ||
6810 | void | |
fba45db2 | 6811 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6812 | { |
c5aa993b | 6813 | struct breakpoint *b; |
c906108c SS |
6814 | |
6815 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6816 | { |
cc60f2e3 | 6817 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6818 | { |
b5de0fa7 | 6819 | b->enable_state = bp_enabled; |
b60e7edf | 6820 | update_global_location_list (1); |
c5aa993b JM |
6821 | } |
6822 | } | |
c906108c SS |
6823 | } |
6824 | ||
8bea4e01 UW |
6825 | void |
6826 | disable_breakpoints_before_startup (void) | |
6827 | { | |
6828 | struct breakpoint *b; | |
6829 | int found = 0; | |
6830 | ||
6831 | ALL_BREAKPOINTS (b) | |
6832 | { | |
6c95b8df PA |
6833 | if (b->pspace != current_program_space) |
6834 | continue; | |
6835 | ||
8bea4e01 UW |
6836 | if ((b->type == bp_breakpoint |
6837 | || b->type == bp_hardware_breakpoint) | |
6838 | && breakpoint_enabled (b)) | |
6839 | { | |
6840 | b->enable_state = bp_startup_disabled; | |
6841 | found = 1; | |
6842 | } | |
6843 | } | |
6844 | ||
6845 | if (found) | |
6846 | update_global_location_list (0); | |
6847 | ||
6c95b8df | 6848 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6849 | } |
6850 | ||
6851 | void | |
6852 | enable_breakpoints_after_startup (void) | |
6853 | { | |
6854 | struct breakpoint *b; | |
6855 | int found = 0; | |
6856 | ||
6c95b8df | 6857 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6858 | |
6859 | ALL_BREAKPOINTS (b) | |
6860 | { | |
6c95b8df PA |
6861 | if (b->pspace != current_program_space) |
6862 | continue; | |
6863 | ||
8bea4e01 UW |
6864 | if ((b->type == bp_breakpoint |
6865 | || b->type == bp_hardware_breakpoint) | |
6866 | && b->enable_state == bp_startup_disabled) | |
6867 | { | |
6868 | b->enable_state = bp_enabled; | |
6869 | found = 1; | |
6870 | } | |
6871 | } | |
6872 | ||
6873 | if (found) | |
6874 | breakpoint_re_set (); | |
6875 | } | |
6876 | ||
c906108c SS |
6877 | |
6878 | /* Set a breakpoint that will evaporate an end of command | |
6879 | at address specified by SAL. | |
6880 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6881 | ||
6882 | struct breakpoint * | |
a6d9a66e UW |
6883 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6884 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6885 | { |
52f0bd74 | 6886 | struct breakpoint *b; |
edb3359d DJ |
6887 | |
6888 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6889 | one. */ | |
6890 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6891 | ||
a6d9a66e | 6892 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6893 | b->enable_state = bp_enabled; |
6894 | b->disposition = disp_donttouch; | |
818dd999 | 6895 | b->frame_id = frame_id; |
c906108c | 6896 | |
4a64f543 MS |
6897 | /* If we're debugging a multi-threaded program, then we want |
6898 | momentary breakpoints to be active in only a single thread of | |
6899 | control. */ | |
39f77062 KB |
6900 | if (in_thread_list (inferior_ptid)) |
6901 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6902 | |
b60e7edf | 6903 | update_global_location_list_nothrow (1); |
74960c60 | 6904 | |
c906108c SS |
6905 | return b; |
6906 | } | |
611c83ae | 6907 | |
e58b0e63 PA |
6908 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6909 | ORIG is NULL. */ | |
6910 | ||
6911 | struct breakpoint * | |
6912 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6913 | { | |
6914 | struct breakpoint *copy; | |
6915 | ||
6916 | /* If there's nothing to clone, then return nothing. */ | |
6917 | if (orig == NULL) | |
6918 | return NULL; | |
6919 | ||
a6d9a66e | 6920 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6921 | copy->loc = allocate_bp_location (copy); |
6922 | set_breakpoint_location_function (copy->loc); | |
6923 | ||
a6d9a66e | 6924 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6925 | copy->loc->requested_address = orig->loc->requested_address; |
6926 | copy->loc->address = orig->loc->address; | |
6927 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6928 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6929 | |
6930 | if (orig->source_file == NULL) | |
6931 | copy->source_file = NULL; | |
6932 | else | |
6933 | copy->source_file = xstrdup (orig->source_file); | |
6934 | ||
6935 | copy->line_number = orig->line_number; | |
6936 | copy->frame_id = orig->frame_id; | |
6937 | copy->thread = orig->thread; | |
6c95b8df | 6938 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6939 | |
6940 | copy->enable_state = bp_enabled; | |
6941 | copy->disposition = disp_donttouch; | |
6942 | copy->number = internal_breakpoint_number--; | |
6943 | ||
6944 | update_global_location_list_nothrow (0); | |
6945 | return copy; | |
6946 | } | |
6947 | ||
611c83ae | 6948 | struct breakpoint * |
a6d9a66e UW |
6949 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6950 | enum bptype type) | |
611c83ae PA |
6951 | { |
6952 | struct symtab_and_line sal; | |
6953 | ||
6954 | sal = find_pc_line (pc, 0); | |
6955 | sal.pc = pc; | |
6956 | sal.section = find_pc_overlay (pc); | |
6957 | sal.explicit_pc = 1; | |
6958 | ||
a6d9a66e | 6959 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6960 | } |
c906108c | 6961 | \f |
c5aa993b | 6962 | |
c906108c SS |
6963 | /* Tell the user we have just set a breakpoint B. */ |
6964 | ||
6965 | static void | |
fba45db2 | 6966 | mention (struct breakpoint *b) |
c906108c SS |
6967 | { |
6968 | int say_where = 0; | |
fa8a61dc | 6969 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6970 | struct value_print_options opts; |
6971 | ||
6972 | get_user_print_options (&opts); | |
8b93c638 | 6973 | |
9a4105ab AC |
6974 | /* FIXME: This is misplaced; mention() is called by things (like |
6975 | hitting a watchpoint) other than breakpoint creation. It should | |
6976 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6977 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6978 | observer_notify_breakpoint_created (b->number); |
c906108c | 6979 | |
3086aeae DJ |
6980 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6981 | b->ops->print_mention (b); | |
6982 | else | |
6983 | switch (b->type) | |
6984 | { | |
6985 | case bp_none: | |
3e43a32a MS |
6986 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), |
6987 | b->number); | |
3086aeae DJ |
6988 | break; |
6989 | case bp_watchpoint: | |
6990 | ui_out_text (uiout, "Watchpoint "); | |
6991 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6992 | ui_out_field_int (uiout, "number", b->number); | |
6993 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6994 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6995 | do_cleanups (ui_out_chain); |
6996 | break; | |
6997 | case bp_hardware_watchpoint: | |
6998 | ui_out_text (uiout, "Hardware watchpoint "); | |
6999 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
7000 | ui_out_field_int (uiout, "number", b->number); | |
7001 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7002 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7003 | do_cleanups (ui_out_chain); |
7004 | break; | |
7005 | case bp_read_watchpoint: | |
7006 | ui_out_text (uiout, "Hardware read watchpoint "); | |
7007 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
7008 | ui_out_field_int (uiout, "number", b->number); | |
7009 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7010 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7011 | do_cleanups (ui_out_chain); |
7012 | break; | |
7013 | case bp_access_watchpoint: | |
7014 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
7015 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
7016 | ui_out_field_int (uiout, "number", b->number); | |
7017 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7018 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7019 | do_cleanups (ui_out_chain); |
7020 | break; | |
7021 | case bp_breakpoint: | |
7022 | if (ui_out_is_mi_like_p (uiout)) | |
7023 | { | |
7024 | say_where = 0; | |
7025 | break; | |
7026 | } | |
2cec12e5 AR |
7027 | if (b->disposition == disp_del) |
7028 | printf_filtered (_("Temporary breakpoint")); | |
7029 | else | |
7030 | printf_filtered (_("Breakpoint")); | |
7031 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
7032 | say_where = 1; |
7033 | break; | |
7034 | case bp_hardware_breakpoint: | |
7035 | if (ui_out_is_mi_like_p (uiout)) | |
7036 | { | |
7037 | say_where = 0; | |
7038 | break; | |
7039 | } | |
a3f17187 | 7040 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
7041 | say_where = 1; |
7042 | break; | |
1042e4c0 SS |
7043 | case bp_tracepoint: |
7044 | if (ui_out_is_mi_like_p (uiout)) | |
7045 | { | |
7046 | say_where = 0; | |
7047 | break; | |
7048 | } | |
7049 | printf_filtered (_("Tracepoint")); | |
7050 | printf_filtered (_(" %d"), b->number); | |
7051 | say_where = 1; | |
7052 | break; | |
7a697b8d SS |
7053 | case bp_fast_tracepoint: |
7054 | if (ui_out_is_mi_like_p (uiout)) | |
7055 | { | |
7056 | say_where = 0; | |
7057 | break; | |
7058 | } | |
7059 | printf_filtered (_("Fast tracepoint")); | |
7060 | printf_filtered (_(" %d"), b->number); | |
7061 | say_where = 1; | |
7062 | break; | |
0fb4aa4b PA |
7063 | case bp_static_tracepoint: |
7064 | if (ui_out_is_mi_like_p (uiout)) | |
7065 | { | |
7066 | say_where = 0; | |
7067 | break; | |
7068 | } | |
7069 | printf_filtered (_("Static tracepoint")); | |
7070 | printf_filtered (_(" %d"), b->number); | |
7071 | say_where = 1; | |
7072 | break; | |
3086aeae DJ |
7073 | |
7074 | case bp_until: | |
7075 | case bp_finish: | |
7076 | case bp_longjmp: | |
7077 | case bp_longjmp_resume: | |
186c406b TT |
7078 | case bp_exception: |
7079 | case bp_exception_resume: | |
3086aeae | 7080 | case bp_step_resume: |
3086aeae | 7081 | case bp_call_dummy: |
aa7d318d | 7082 | case bp_std_terminate: |
3086aeae DJ |
7083 | case bp_watchpoint_scope: |
7084 | case bp_shlib_event: | |
7085 | case bp_thread_event: | |
7086 | case bp_overlay_event: | |
4efc6507 | 7087 | case bp_jit_event: |
0fd8e87f | 7088 | case bp_longjmp_master: |
aa7d318d | 7089 | case bp_std_terminate_master: |
186c406b | 7090 | case bp_exception_master: |
3086aeae DJ |
7091 | break; |
7092 | } | |
c906108c | 7093 | |
c906108c SS |
7094 | if (say_where) |
7095 | { | |
a3f17187 AC |
7096 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
7097 | single string. */ | |
0d381245 | 7098 | if (b->loc == NULL) |
c906108c | 7099 | { |
a3f17187 | 7100 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
7101 | } |
7102 | else | |
7103 | { | |
79a45b7d | 7104 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
7105 | { |
7106 | printf_filtered (" at "); | |
5af949e3 UW |
7107 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
7108 | gdb_stdout); | |
0101ce28 JJ |
7109 | } |
7110 | if (b->source_file) | |
7111 | printf_filtered (": file %s, line %d.", | |
7112 | b->source_file, b->line_number); | |
0d381245 VP |
7113 | |
7114 | if (b->loc->next) | |
7115 | { | |
7116 | struct bp_location *loc = b->loc; | |
7117 | int n = 0; | |
7118 | for (; loc; loc = loc->next) | |
7119 | ++n; | |
7120 | printf_filtered (" (%d locations)", n); | |
7121 | } | |
7122 | ||
c906108c | 7123 | } |
c906108c | 7124 | } |
9dc5e2a9 | 7125 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7126 | return; |
c906108c SS |
7127 | printf_filtered ("\n"); |
7128 | } | |
c906108c | 7129 | \f |
c5aa993b | 7130 | |
0d381245 | 7131 | static struct bp_location * |
39d61571 | 7132 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7133 | const struct symtab_and_line *sal) |
7134 | { | |
7135 | struct bp_location *loc, **tmp; | |
7136 | ||
39d61571 | 7137 | loc = allocate_bp_location (b); |
0d381245 VP |
7138 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7139 | ; | |
7140 | *tmp = loc; | |
a6d9a66e UW |
7141 | loc->gdbarch = get_sal_arch (*sal); |
7142 | if (!loc->gdbarch) | |
7143 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7144 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7145 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7146 | loc->requested_address, b->type); | |
6c95b8df PA |
7147 | loc->pspace = sal->pspace; |
7148 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7149 | loc->section = sal->section; |
7150 | ||
7151 | set_breakpoint_location_function (loc); | |
7152 | return loc; | |
7153 | } | |
514f746b AR |
7154 | \f |
7155 | ||
7156 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7157 | return 0 otherwise. */ | |
7158 | ||
7159 | static int | |
7160 | bp_loc_is_permanent (struct bp_location *loc) | |
7161 | { | |
7162 | int len; | |
7163 | CORE_ADDR addr; | |
7164 | const gdb_byte *brk; | |
7165 | gdb_byte *target_mem; | |
939c61fa JK |
7166 | struct cleanup *cleanup; |
7167 | int retval = 0; | |
514f746b AR |
7168 | |
7169 | gdb_assert (loc != NULL); | |
7170 | ||
7171 | addr = loc->address; | |
a6d9a66e | 7172 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7173 | |
939c61fa JK |
7174 | /* Software breakpoints unsupported? */ |
7175 | if (brk == NULL) | |
7176 | return 0; | |
7177 | ||
514f746b AR |
7178 | target_mem = alloca (len); |
7179 | ||
939c61fa JK |
7180 | /* Enable the automatic memory restoration from breakpoints while |
7181 | we read the memory. Otherwise we could say about our temporary | |
7182 | breakpoints they are permanent. */ | |
6c95b8df PA |
7183 | cleanup = save_current_space_and_thread (); |
7184 | ||
7185 | switch_to_program_space_and_thread (loc->pspace); | |
7186 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7187 | |
514f746b AR |
7188 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7189 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7190 | retval = 1; |
514f746b | 7191 | |
939c61fa JK |
7192 | do_cleanups (cleanup); |
7193 | ||
7194 | return retval; | |
514f746b AR |
7195 | } |
7196 | ||
7197 | ||
c3f6f71d | 7198 | |
018d34a4 VP |
7199 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7200 | as textual description of the location, and COND_STRING | |
db107f19 | 7201 | as condition expression. */ |
018d34a4 VP |
7202 | |
7203 | static void | |
8cdf0e15 VP |
7204 | create_breakpoint_sal (struct gdbarch *gdbarch, |
7205 | struct symtabs_and_lines sals, char *addr_string, | |
7206 | char *cond_string, | |
7207 | enum bptype type, enum bpdisp disposition, | |
7208 | int thread, int task, int ignore_count, | |
84f4c1fe | 7209 | struct breakpoint_ops *ops, int from_tty, |
56435ebe | 7210 | int enabled, int internal, int display_canonical) |
018d34a4 | 7211 | { |
0d381245 VP |
7212 | struct breakpoint *b = NULL; |
7213 | int i; | |
018d34a4 VP |
7214 | |
7215 | if (type == bp_hardware_breakpoint) | |
7216 | { | |
7217 | int i = hw_breakpoint_used_count (); | |
7218 | int target_resources_ok = | |
d92524f1 | 7219 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7220 | i + 1, 0); |
7221 | if (target_resources_ok == 0) | |
7222 | error (_("No hardware breakpoint support in the target.")); | |
7223 | else if (target_resources_ok < 0) | |
7224 | error (_("Hardware breakpoints used exceeds limit.")); | |
7225 | } | |
7226 | ||
6c95b8df PA |
7227 | gdb_assert (sals.nelts > 0); |
7228 | ||
0d381245 VP |
7229 | for (i = 0; i < sals.nelts; ++i) |
7230 | { | |
7231 | struct symtab_and_line sal = sals.sals[i]; | |
7232 | struct bp_location *loc; | |
7233 | ||
7234 | if (from_tty) | |
5af949e3 UW |
7235 | { |
7236 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7237 | if (!loc_gdbarch) | |
7238 | loc_gdbarch = gdbarch; | |
7239 | ||
7240 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7241 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7242 | } |
0d381245 VP |
7243 | |
7244 | if (i == 0) | |
7245 | { | |
a6d9a66e | 7246 | b = set_raw_breakpoint (gdbarch, sal, type); |
84f4c1fe | 7247 | set_breakpoint_number (internal, b); |
0d381245 | 7248 | b->thread = thread; |
4a306c9a | 7249 | b->task = task; |
018d34a4 | 7250 | |
0d381245 VP |
7251 | b->cond_string = cond_string; |
7252 | b->ignore_count = ignore_count; | |
41447f92 | 7253 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7254 | b->disposition = disposition; |
6c95b8df PA |
7255 | b->pspace = sals.sals[0].pspace; |
7256 | ||
0fb4aa4b PA |
7257 | if (type == bp_static_tracepoint) |
7258 | { | |
7259 | struct static_tracepoint_marker marker; | |
7260 | ||
7261 | if (is_marker_spec (addr_string)) | |
7262 | { | |
7263 | /* We already know the marker exists, otherwise, we | |
7264 | wouldn't see a sal for it. */ | |
7265 | char *p = &addr_string[3]; | |
7266 | char *endp; | |
7267 | char *marker_str; | |
7268 | int i; | |
7269 | ||
e9cafbcc | 7270 | p = skip_spaces (p); |
0fb4aa4b | 7271 | |
e9cafbcc | 7272 | endp = skip_to_space (p); |
0fb4aa4b PA |
7273 | |
7274 | marker_str = savestring (p, endp - p); | |
7275 | b->static_trace_marker_id = marker_str; | |
7276 | ||
3e43a32a MS |
7277 | printf_filtered (_("Probed static tracepoint " |
7278 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7279 | b->static_trace_marker_id); |
7280 | } | |
7281 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7282 | { | |
7283 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
7284 | release_static_tracepoint_marker (&marker); | |
7285 | ||
3e43a32a MS |
7286 | printf_filtered (_("Probed static tracepoint " |
7287 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7288 | b->static_trace_marker_id); |
7289 | } | |
7290 | else | |
3e43a32a MS |
7291 | warning (_("Couldn't determine the static " |
7292 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7293 | } |
7294 | ||
6c95b8df | 7295 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7296 | && (b->type == bp_breakpoint |
7297 | || b->type == bp_hardware_breakpoint)) | |
7298 | b->enable_state = bp_startup_disabled; | |
7299 | ||
0d381245 VP |
7300 | loc = b->loc; |
7301 | } | |
7302 | else | |
018d34a4 | 7303 | { |
39d61571 | 7304 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7305 | } |
7306 | ||
514f746b AR |
7307 | if (bp_loc_is_permanent (loc)) |
7308 | make_breakpoint_permanent (b); | |
7309 | ||
0d381245 VP |
7310 | if (b->cond_string) |
7311 | { | |
7312 | char *arg = b->cond_string; | |
d32a6982 | 7313 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7314 | if (*arg) |
db107f19 | 7315 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7316 | } |
0d381245 | 7317 | } |
018d34a4 | 7318 | |
56435ebe | 7319 | b->display_canonical = display_canonical; |
018d34a4 VP |
7320 | if (addr_string) |
7321 | b->addr_string = addr_string; | |
7322 | else | |
7323 | /* addr_string has to be used or breakpoint_re_set will delete | |
7324 | me. */ | |
5af949e3 UW |
7325 | b->addr_string |
7326 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7327 | |
604133b5 | 7328 | b->ops = ops; |
84f4c1fe PM |
7329 | if (internal) |
7330 | /* Do not mention breakpoints with a negative number, but do | |
7331 | notify observers. */ | |
7332 | observer_notify_breakpoint_created (b->number); | |
7333 | else | |
7334 | mention (b); | |
018d34a4 VP |
7335 | } |
7336 | ||
ed0616c6 VP |
7337 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7338 | elements to fill the void space. */ | |
2c0b251b PA |
7339 | static void |
7340 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7341 | { |
7342 | int i = index_to_remove+1; | |
7343 | int last_index = sal->nelts-1; | |
7344 | ||
7345 | for (;i <= last_index; ++i) | |
7346 | sal->sals[i-1] = sal->sals[i]; | |
7347 | ||
7348 | --(sal->nelts); | |
7349 | } | |
7350 | ||
6c95b8df PA |
7351 | /* If appropriate, obtains all sals that correspond to the same file |
7352 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7353 | will want to set a breakpoint at foo.c:line, and not really care | |
7354 | about program spaces. This is done only if SAL does not have | |
7355 | explicit PC and has line and file information. If we got just a | |
7356 | single expanded sal, return the original. | |
ed0616c6 | 7357 | |
6c95b8df PA |
7358 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7359 | which the name of enclosing function is different from SAL. This | |
7360 | makes sure that if we have breakpoint originally set in template | |
7361 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7362 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7363 | |
2c0b251b | 7364 | static struct symtabs_and_lines |
ed0616c6 VP |
7365 | expand_line_sal_maybe (struct symtab_and_line sal) |
7366 | { | |
7367 | struct symtabs_and_lines expanded; | |
7368 | CORE_ADDR original_pc = sal.pc; | |
7369 | char *original_function = NULL; | |
7370 | int found; | |
7371 | int i; | |
6c95b8df | 7372 | struct cleanup *old_chain; |
ed0616c6 VP |
7373 | |
7374 | /* If we have explicit pc, don't expand. | |
7375 | If we have no line number, we can't expand. */ | |
7376 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7377 | { | |
7378 | expanded.nelts = 1; | |
7379 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7380 | expanded.sals[0] = sal; | |
7381 | return expanded; | |
7382 | } | |
7383 | ||
7384 | sal.pc = 0; | |
6c95b8df PA |
7385 | |
7386 | old_chain = save_current_space_and_thread (); | |
7387 | ||
7388 | switch_to_program_space_and_thread (sal.pspace); | |
7389 | ||
ed0616c6 | 7390 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7391 | |
7392 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7393 | expanded = expand_line_sal (sal); |
6c95b8df | 7394 | |
ed0616c6 VP |
7395 | if (expanded.nelts == 1) |
7396 | { | |
3dba1c98 JB |
7397 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7398 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7399 | xfree (expanded.sals); |
7400 | expanded.nelts = 1; | |
7401 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7402 | sal.pc = original_pc; | |
7403 | expanded.sals[0] = sal; | |
3dba1c98 | 7404 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7405 | do_cleanups (old_chain); |
ed0616c6 VP |
7406 | return expanded; |
7407 | } | |
7408 | ||
7409 | if (!sal.explicit_line) | |
7410 | { | |
7411 | CORE_ADDR func_addr, func_end; | |
7412 | for (i = 0; i < expanded.nelts; ++i) | |
7413 | { | |
7414 | CORE_ADDR pc = expanded.sals[i].pc; | |
7415 | char *this_function; | |
6c95b8df PA |
7416 | |
7417 | /* We need to switch threads as well since we're about to | |
7418 | read memory. */ | |
7419 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7420 | ||
ed0616c6 VP |
7421 | if (find_pc_partial_function (pc, &this_function, |
7422 | &func_addr, &func_end)) | |
7423 | { | |
059fb39f PM |
7424 | if (this_function |
7425 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7426 | { |
7427 | remove_sal (&expanded, i); | |
7428 | --i; | |
7429 | } | |
ed0616c6 VP |
7430 | } |
7431 | } | |
7432 | } | |
059acae7 UW |
7433 | |
7434 | /* Skip the function prologue if necessary. */ | |
7435 | for (i = 0; i < expanded.nelts; ++i) | |
7436 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7437 | |
6c95b8df PA |
7438 | do_cleanups (old_chain); |
7439 | ||
ed0616c6 VP |
7440 | if (expanded.nelts <= 1) |
7441 | { | |
4a64f543 MS |
7442 | /* This is un ugly workaround. If we get zero expanded sals |
7443 | then something is really wrong. Fix that by returning the | |
7444 | original sal. */ | |
7445 | ||
ed0616c6 VP |
7446 | xfree (expanded.sals); |
7447 | expanded.nelts = 1; | |
7448 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7449 | sal.pc = original_pc; | |
7450 | expanded.sals[0] = sal; | |
7451 | return expanded; | |
7452 | } | |
7453 | ||
7454 | if (original_pc) | |
7455 | { | |
7456 | found = 0; | |
7457 | for (i = 0; i < expanded.nelts; ++i) | |
7458 | if (expanded.sals[i].pc == original_pc) | |
7459 | { | |
7460 | found = 1; | |
7461 | break; | |
7462 | } | |
7463 | gdb_assert (found); | |
7464 | } | |
7465 | ||
7466 | return expanded; | |
7467 | } | |
7468 | ||
018d34a4 VP |
7469 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7470 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7471 | value. COND_STRING, if not NULL, specified the condition to be | |
7472 | used for all breakpoints. Essentially the only case where | |
7473 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7474 | function. In that case, it's still not possible to specify | |
7475 | separate conditions for different overloaded functions, so | |
7476 | we take just a single condition string. | |
7477 | ||
c3f6f71d | 7478 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7479 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7480 | array contents). If the function fails (error() is called), the |
7481 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7482 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7483 | |
7484 | static void | |
8cdf0e15 | 7485 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7486 | struct symtabs_and_lines sals, |
7487 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7488 | char *cond_string, |
7489 | enum bptype type, enum bpdisp disposition, | |
7490 | int thread, int task, int ignore_count, | |
7491 | struct breakpoint_ops *ops, int from_tty, | |
84f4c1fe | 7492 | int enabled, int internal) |
c906108c | 7493 | { |
018d34a4 | 7494 | int i; |
cc59ec59 | 7495 | |
018d34a4 | 7496 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7497 | { |
ed0616c6 VP |
7498 | struct symtabs_and_lines expanded = |
7499 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7500 | |
7efd8fc2 | 7501 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7502 | cond_string, type, disposition, |
84f4c1fe | 7503 | thread, task, ignore_count, ops, |
56435ebe TT |
7504 | from_tty, enabled, internal, |
7505 | canonical->special_display); | |
c3f6f71d | 7506 | } |
c3f6f71d | 7507 | } |
c906108c | 7508 | |
9998af43 | 7509 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7510 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7511 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7512 | address strings. ADDRESS points to the end of the SAL. |
7513 | ||
7514 | The array and the line spec strings are allocated on the heap, it is | |
7515 | the caller's responsibility to free them. */ | |
c906108c | 7516 | |
b9362cc7 | 7517 | static void |
c3f6f71d JM |
7518 | parse_breakpoint_sals (char **address, |
7519 | struct symtabs_and_lines *sals, | |
7efd8fc2 | 7520 | struct linespec_result *canonical, |
0101ce28 | 7521 | int *not_found_ptr) |
c3f6f71d JM |
7522 | { |
7523 | char *addr_start = *address; | |
cc59ec59 | 7524 | |
c3f6f71d | 7525 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7526 | breakpoint. */ |
c3f6f71d JM |
7527 | if ((*address) == NULL |
7528 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7529 | { |
7530 | if (default_breakpoint_valid) | |
7531 | { | |
c3f6f71d | 7532 | struct symtab_and_line sal; |
cc59ec59 | 7533 | |
4a64f543 | 7534 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7535 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7536 | xmalloc (sizeof (struct symtab_and_line)); |
7537 | sal.pc = default_breakpoint_address; | |
7538 | sal.line = default_breakpoint_line; | |
7539 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7540 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7541 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7542 | |
4a64f543 MS |
7543 | /* "break" without arguments is equivalent to "break *PC" |
7544 | where PC is the default_breakpoint_address. So make sure | |
7545 | to set sal.explicit_pc to prevent GDB from trying to | |
7546 | expand the list of sals to include all other instances | |
7547 | with the same symtab and line. */ | |
00903456 JK |
7548 | sal.explicit_pc = 1; |
7549 | ||
c3f6f71d JM |
7550 | sals->sals[0] = sal; |
7551 | sals->nelts = 1; | |
c906108c SS |
7552 | } |
7553 | else | |
8a3fe4f8 | 7554 | error (_("No default breakpoint address now.")); |
c906108c SS |
7555 | } |
7556 | else | |
7557 | { | |
c906108c | 7558 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7559 | current_source_symtab (which is decode_line_1's default). |
7560 | This should produce the results we want almost all of the | |
7561 | time while leaving default_breakpoint_* alone. | |
7562 | ||
1aeae86e AF |
7563 | ObjC: However, don't match an Objective-C method name which |
7564 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7565 | |
c214a6fd | 7566 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7567 | |
c906108c | 7568 | if (default_breakpoint_valid |
0378c332 | 7569 | && (!cursal.symtab |
1aeae86e AF |
7570 | || ((strchr ("+-", (*address)[0]) != NULL) |
7571 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7572 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
7efd8fc2 | 7573 | default_breakpoint_line, canonical, |
0101ce28 | 7574 | not_found_ptr); |
c906108c | 7575 | else |
0101ce28 | 7576 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7efd8fc2 | 7577 | canonical, not_found_ptr); |
c906108c | 7578 | } |
4a64f543 | 7579 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 TT |
7580 | if (sals->nelts > 0 && canonical->canonical == NULL) |
7581 | canonical->canonical = xcalloc (sals->nelts, sizeof (char **)); | |
c3f6f71d | 7582 | if (addr_start != (*address)) |
c906108c | 7583 | { |
c3f6f71d | 7584 | int i; |
cc59ec59 | 7585 | |
c3f6f71d | 7586 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7587 | { |
4a64f543 | 7588 | /* Add the string if not present. */ |
7efd8fc2 TT |
7589 | if (canonical->canonical[i] == NULL) |
7590 | canonical->canonical[i] = savestring (addr_start, | |
7591 | (*address) - addr_start); | |
c906108c SS |
7592 | } |
7593 | } | |
c3f6f71d | 7594 | } |
c906108c | 7595 | |
c906108c | 7596 | |
c3f6f71d | 7597 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7598 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7599 | |
b9362cc7 | 7600 | static void |
23e7acfb | 7601 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7602 | { |
7603 | int i; | |
cc59ec59 | 7604 | |
c3f6f71d | 7605 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7606 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7607 | } |
7608 | ||
7a697b8d SS |
7609 | /* Fast tracepoints may have restrictions on valid locations. For |
7610 | instance, a fast tracepoint using a jump instead of a trap will | |
7611 | likely have to overwrite more bytes than a trap would, and so can | |
7612 | only be placed where the instruction is longer than the jump, or a | |
7613 | multi-instruction sequence does not have a jump into the middle of | |
7614 | it, etc. */ | |
7615 | ||
7616 | static void | |
7617 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7618 | struct symtabs_and_lines *sals) | |
7619 | { | |
7620 | int i, rslt; | |
7621 | struct symtab_and_line *sal; | |
7622 | char *msg; | |
7623 | struct cleanup *old_chain; | |
7624 | ||
7625 | for (i = 0; i < sals->nelts; i++) | |
7626 | { | |
7627 | sal = &sals->sals[i]; | |
7628 | ||
7629 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7630 | NULL, &msg); | |
7631 | old_chain = make_cleanup (xfree, msg); | |
7632 | ||
7633 | if (!rslt) | |
7634 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7635 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7636 | ||
7637 | do_cleanups (old_chain); | |
7638 | } | |
7639 | } | |
7640 | ||
05ff989b | 7641 | static void |
0101ce28 JJ |
7642 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7643 | { | |
7644 | struct captured_parse_breakpoint_args *args = data; | |
7645 | ||
7efd8fc2 | 7646 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->canonical_p, |
0101ce28 | 7647 | args->not_found_ptr); |
0101ce28 JJ |
7648 | } |
7649 | ||
018d34a4 VP |
7650 | /* Given TOK, a string specification of condition and thread, as |
7651 | accepted by the 'break' command, extract the condition | |
7652 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7653 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7654 | If no condition is found, *COND_STRING is set to NULL. |
7655 | If no thread is found, *THREAD is set to -1. */ | |
7656 | static void | |
7657 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7658 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7659 | { |
7660 | *cond_string = NULL; | |
7661 | *thread = -1; | |
7662 | while (tok && *tok) | |
7663 | { | |
7664 | char *end_tok; | |
7665 | int toklen; | |
7666 | char *cond_start = NULL; | |
7667 | char *cond_end = NULL; | |
cc59ec59 | 7668 | |
e9cafbcc | 7669 | tok = skip_spaces (tok); |
018d34a4 | 7670 | |
e9cafbcc | 7671 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7672 | |
7673 | toklen = end_tok - tok; | |
7674 | ||
7675 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7676 | { | |
f7545552 TT |
7677 | struct expression *expr; |
7678 | ||
018d34a4 | 7679 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7680 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7681 | xfree (expr); | |
018d34a4 VP |
7682 | cond_end = tok; |
7683 | *cond_string = savestring (cond_start, | |
7684 | cond_end - cond_start); | |
7685 | } | |
7686 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7687 | { | |
7688 | char *tmptok; | |
7689 | ||
7690 | tok = end_tok + 1; | |
7691 | tmptok = tok; | |
7692 | *thread = strtol (tok, &tok, 0); | |
7693 | if (tok == tmptok) | |
7694 | error (_("Junk after thread keyword.")); | |
7695 | if (!valid_thread_id (*thread)) | |
7696 | error (_("Unknown thread %d."), *thread); | |
7697 | } | |
4a306c9a JB |
7698 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7699 | { | |
7700 | char *tmptok; | |
7701 | ||
7702 | tok = end_tok + 1; | |
7703 | tmptok = tok; | |
7704 | *task = strtol (tok, &tok, 0); | |
7705 | if (tok == tmptok) | |
7706 | error (_("Junk after task keyword.")); | |
7707 | if (!valid_task_id (*task)) | |
b6199126 | 7708 | error (_("Unknown task %d."), *task); |
4a306c9a | 7709 | } |
018d34a4 VP |
7710 | else |
7711 | error (_("Junk at end of arguments.")); | |
7712 | } | |
7713 | } | |
7714 | ||
0fb4aa4b PA |
7715 | /* Decode a static tracepoint marker spec. */ |
7716 | ||
7717 | static struct symtabs_and_lines | |
7718 | decode_static_tracepoint_spec (char **arg_p) | |
7719 | { | |
7720 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7721 | struct symtabs_and_lines sals; | |
7722 | struct symtab_and_line sal; | |
7723 | struct symbol *sym; | |
7724 | struct cleanup *old_chain; | |
7725 | char *p = &(*arg_p)[3]; | |
7726 | char *endp; | |
7727 | char *marker_str; | |
7728 | int i; | |
7729 | ||
e9cafbcc | 7730 | p = skip_spaces (p); |
0fb4aa4b | 7731 | |
e9cafbcc | 7732 | endp = skip_to_space (p); |
0fb4aa4b PA |
7733 | |
7734 | marker_str = savestring (p, endp - p); | |
7735 | old_chain = make_cleanup (xfree, marker_str); | |
7736 | ||
7737 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7738 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7739 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7740 | ||
7741 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7742 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7743 | ||
7744 | for (i = 0; i < sals.nelts; i++) | |
7745 | { | |
7746 | struct static_tracepoint_marker *marker; | |
7747 | ||
7748 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7749 | ||
7750 | init_sal (&sals.sals[i]); | |
7751 | ||
7752 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7753 | sals.sals[i].pc = marker->address; | |
7754 | ||
7755 | release_static_tracepoint_marker (marker); | |
7756 | } | |
7757 | ||
7758 | do_cleanups (old_chain); | |
7759 | ||
7760 | *arg_p = endp; | |
7761 | return sals; | |
7762 | } | |
7763 | ||
fd9b8c24 PA |
7764 | /* Set a breakpoint. This function is shared between CLI and MI |
7765 | functions for setting a breakpoint. This function has two major | |
7766 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7767 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7768 | breakpoint location, address and thread. Otherwise, ARG is just |
7769 | the location of breakpoint, with condition and thread specified by | |
7770 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7771 | the breakpoint number will be allocated from the internal | |
7772 | breakpoint count. Returns true if any breakpoint was created; | |
7773 | false otherwise. */ | |
0101ce28 | 7774 | |
8cdf0e15 VP |
7775 | int |
7776 | create_breakpoint (struct gdbarch *gdbarch, | |
7777 | char *arg, char *cond_string, int thread, | |
7778 | int parse_condition_and_thread, | |
0fb4aa4b | 7779 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7780 | int ignore_count, |
7781 | enum auto_boolean pending_break_support, | |
7782 | struct breakpoint_ops *ops, | |
84f4c1fe | 7783 | int from_tty, int enabled, int internal) |
c3f6f71d | 7784 | { |
71fff37b | 7785 | struct gdb_exception e; |
c3f6f71d | 7786 | struct symtabs_and_lines sals; |
0101ce28 | 7787 | struct symtab_and_line pending_sal; |
0101ce28 | 7788 | char *copy_arg; |
c3f6f71d | 7789 | char *addr_start = arg; |
7efd8fc2 | 7790 | struct linespec_result canonical; |
c3f6f71d | 7791 | struct cleanup *old_chain; |
80c99de1 | 7792 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7793 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7794 | int i; |
0101ce28 | 7795 | int pending = 0; |
0101ce28 | 7796 | int not_found = 0; |
4a306c9a | 7797 | int task = 0; |
86b17b60 | 7798 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7799 | |
c3f6f71d JM |
7800 | sals.sals = NULL; |
7801 | sals.nelts = 0; | |
7efd8fc2 | 7802 | init_linespec_result (&canonical); |
c3f6f71d | 7803 | |
0101ce28 JJ |
7804 | parse_args.arg_p = &arg; |
7805 | parse_args.sals_p = &sals; | |
7efd8fc2 | 7806 | parse_args.canonical_p = &canonical; |
0101ce28 JJ |
7807 | parse_args.not_found_ptr = ¬_found; |
7808 | ||
0fb4aa4b PA |
7809 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7810 | { | |
7811 | int i; | |
7812 | ||
7813 | sals = decode_static_tracepoint_spec (&arg); | |
7814 | ||
7815 | copy_arg = savestring (addr_start, arg - addr_start); | |
7efd8fc2 | 7816 | canonical.canonical = xcalloc (sals.nelts, sizeof (char **)); |
0fb4aa4b | 7817 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7818 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7819 | goto done; |
7820 | } | |
7821 | ||
05ff989b AC |
7822 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7823 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7824 | |
7825 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7826 | switch (e.reason) |
0101ce28 | 7827 | { |
05ff989b | 7828 | case RETURN_QUIT: |
98deb0da | 7829 | throw_exception (e); |
05ff989b AC |
7830 | case RETURN_ERROR: |
7831 | switch (e.error) | |
0101ce28 | 7832 | { |
05ff989b | 7833 | case NOT_FOUND_ERROR: |
0101ce28 | 7834 | |
05ff989b AC |
7835 | /* If pending breakpoint support is turned off, throw |
7836 | error. */ | |
fa8d40ab JJ |
7837 | |
7838 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7839 | throw_exception (e); |
7840 | ||
7841 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7842 | |
05ff989b AC |
7843 | /* If pending breakpoint support is auto query and the user |
7844 | selects no, then simply return the error code. */ | |
059fb39f | 7845 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7846 | && !nquery (_("Make breakpoint pending on " |
7847 | "future shared library load? "))) | |
fd9b8c24 | 7848 | return 0; |
fa8d40ab | 7849 | |
05ff989b AC |
7850 | /* At this point, either the user was queried about setting |
7851 | a pending breakpoint and selected yes, or pending | |
7852 | breakpoint behavior is on and thus a pending breakpoint | |
7853 | is defaulted on behalf of the user. */ | |
0101ce28 | 7854 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 7855 | canonical.canonical = ©_arg; |
0101ce28 JJ |
7856 | sals.nelts = 1; |
7857 | sals.sals = &pending_sal; | |
7858 | pending_sal.pc = 0; | |
7859 | pending = 1; | |
05ff989b AC |
7860 | break; |
7861 | default: | |
98deb0da | 7862 | throw_exception (e); |
0101ce28 | 7863 | } |
2abae994 | 7864 | break; |
05ff989b AC |
7865 | default: |
7866 | if (!sals.nelts) | |
fd9b8c24 | 7867 | return 0; |
0101ce28 | 7868 | } |
c3f6f71d | 7869 | |
0fb4aa4b PA |
7870 | done: |
7871 | ||
4a64f543 | 7872 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7873 | old_chain = make_cleanup (null_cleanup, 0); |
7874 | ||
0101ce28 JJ |
7875 | if (!pending) |
7876 | { | |
7877 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7878 | make_cleanup (xfree, sals.sals); | |
7879 | ||
7efd8fc2 TT |
7880 | /* Cleanup the canonical array but not its contents. */ |
7881 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 7882 | } |
c3f6f71d | 7883 | |
c3f6f71d JM |
7884 | /* ----------------------------- SNIP ----------------------------- |
7885 | Anything added to the cleanup chain beyond this point is assumed | |
7886 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7887 | then the memory is not reclaimed. */ |
7888 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 7889 | |
7efd8fc2 | 7890 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 7891 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7892 | for (i = 0; i < sals.nelts; i++) |
7893 | { | |
7efd8fc2 TT |
7894 | if (canonical.canonical[i] != NULL) |
7895 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
7896 | } |
7897 | ||
7898 | /* Resolve all line numbers to PC's and verify that the addresses | |
7899 | are ok for the target. */ | |
0101ce28 | 7900 | if (!pending) |
23e7acfb | 7901 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7902 | |
7a697b8d SS |
7903 | /* Fast tracepoints may have additional restrictions on location. */ |
7904 | if (type_wanted == bp_fast_tracepoint) | |
7905 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7906 | ||
c3f6f71d JM |
7907 | /* Verify that condition can be parsed, before setting any |
7908 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7909 | breakpoint. */ |
0101ce28 | 7910 | if (!pending) |
c3f6f71d | 7911 | { |
2f069f6f | 7912 | if (parse_condition_and_thread) |
72b2ff0e VP |
7913 | { |
7914 | /* Here we only parse 'arg' to separate condition | |
7915 | from thread number, so parsing in context of first | |
7916 | sal is OK. When setting the breakpoint we'll | |
7917 | re-parse it in context of each sal. */ | |
7918 | cond_string = NULL; | |
7919 | thread = -1; | |
4a306c9a JB |
7920 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7921 | &thread, &task); | |
72b2ff0e VP |
7922 | if (cond_string) |
7923 | make_cleanup (xfree, cond_string); | |
7924 | } | |
2f069f6f | 7925 | else |
72b2ff0e VP |
7926 | { |
7927 | /* Create a private copy of condition string. */ | |
7928 | if (cond_string) | |
7929 | { | |
7930 | cond_string = xstrdup (cond_string); | |
7931 | make_cleanup (xfree, cond_string); | |
7932 | } | |
7933 | } | |
0fb4aa4b PA |
7934 | |
7935 | /* If the user is creating a static tracepoint by marker id | |
7936 | (strace -m MARKER_ID), then store the sals index, so that | |
7937 | breakpoint_re_set can try to match up which of the newly | |
7938 | found markers corresponds to this one, and, don't try to | |
7939 | expand multiple locations for each sal, given than SALS | |
7940 | already should contain all sals for MARKER_ID. */ | |
7941 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 7942 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
7943 | { |
7944 | int i; | |
7945 | ||
7946 | for (i = 0; i < sals.nelts; ++i) | |
7947 | { | |
7948 | struct symtabs_and_lines expanded; | |
7949 | struct breakpoint *tp; | |
7950 | struct cleanup *old_chain; | |
7951 | ||
7952 | expanded.nelts = 1; | |
7953 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7954 | expanded.sals[0] = sals.sals[i]; | |
7955 | old_chain = make_cleanup (xfree, expanded.sals); | |
7956 | ||
7efd8fc2 | 7957 | create_breakpoint_sal (gdbarch, expanded, canonical.canonical[i], |
0fb4aa4b PA |
7958 | cond_string, type_wanted, |
7959 | tempflag ? disp_del : disp_donttouch, | |
7960 | thread, task, ignore_count, ops, | |
56435ebe TT |
7961 | from_tty, enabled, internal, |
7962 | canonical.special_display); | |
0fb4aa4b PA |
7963 | |
7964 | do_cleanups (old_chain); | |
7965 | ||
7966 | /* Get the tracepoint we just created. */ | |
84f4c1fe PM |
7967 | if (internal) |
7968 | tp = get_breakpoint (internal_breakpoint_number); | |
7969 | else | |
7970 | tp = get_breakpoint (breakpoint_count); | |
0fb4aa4b PA |
7971 | gdb_assert (tp != NULL); |
7972 | ||
7973 | /* Given that its possible to have multiple markers with | |
7974 | the same string id, if the user is creating a static | |
7975 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7976 | store the sals index, so that breakpoint_re_set can | |
7977 | try to match up which of the newly found markers | |
7978 | corresponds to this one */ | |
7979 | tp->static_trace_marker_id_idx = i; | |
7980 | } | |
7981 | } | |
7982 | else | |
7efd8fc2 | 7983 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
7984 | type_wanted, |
7985 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7986 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7987 | enabled, internal); |
c906108c | 7988 | } |
0101ce28 JJ |
7989 | else |
7990 | { | |
0101ce28 JJ |
7991 | struct breakpoint *b; |
7992 | ||
0101ce28 JJ |
7993 | make_cleanup (xfree, copy_arg); |
7994 | ||
a6d9a66e | 7995 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
84f4c1fe | 7996 | set_breakpoint_number (internal, b); |
72b2ff0e | 7997 | b->thread = -1; |
7efd8fc2 | 7998 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 7999 | b->cond_string = NULL; |
0101ce28 | 8000 | b->ignore_count = ignore_count; |
0101ce28 | 8001 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8002 | b->condition_not_parsed = 1; |
604133b5 | 8003 | b->ops = ops; |
41447f92 | 8004 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 8005 | b->pspace = current_program_space; |
84f4c1fe | 8006 | b->py_bp_object = NULL; |
74960c60 | 8007 | |
6c95b8df | 8008 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8009 | && (b->type == bp_breakpoint |
8010 | || b->type == bp_hardware_breakpoint)) | |
8011 | b->enable_state = bp_startup_disabled; | |
8012 | ||
84f4c1fe PM |
8013 | if (internal) |
8014 | /* Do not mention breakpoints with a negative number, | |
8015 | but do notify observers. */ | |
8016 | observer_notify_breakpoint_created (b->number); | |
8017 | else | |
8018 | mention (b); | |
0101ce28 JJ |
8019 | } |
8020 | ||
c3f6f71d | 8021 | if (sals.nelts > 1) |
95a42b64 | 8022 | { |
3e43a32a MS |
8023 | warning (_("Multiple breakpoints were set.\nUse the " |
8024 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8025 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8026 | } |
8027 | ||
80c99de1 PA |
8028 | /* That's it. Discard the cleanups for data inserted into the |
8029 | breakpoint. */ | |
8030 | discard_cleanups (bkpt_chain); | |
8031 | /* But cleanup everything else. */ | |
c3f6f71d | 8032 | do_cleanups (old_chain); |
217dc9e2 | 8033 | |
80c99de1 | 8034 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8035 | update_global_location_list (1); |
fd9b8c24 PA |
8036 | |
8037 | return 1; | |
c3f6f71d | 8038 | } |
c906108c | 8039 | |
72b2ff0e VP |
8040 | /* Set a breakpoint. |
8041 | ARG is a string describing breakpoint address, | |
8042 | condition, and thread. | |
8043 | FLAG specifies if a breakpoint is hardware on, | |
8044 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8045 | and BP_TEMPFLAG. */ | |
8046 | ||
98deb0da | 8047 | static void |
72b2ff0e | 8048 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8049 | { |
72b2ff0e | 8050 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8051 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8052 | ? bp_hardware_breakpoint | |
8053 | : bp_breakpoint); | |
c3f6f71d | 8054 | |
8cdf0e15 VP |
8055 | create_breakpoint (get_current_arch (), |
8056 | arg, | |
8057 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8058 | tempflag, type_wanted, |
8cdf0e15 VP |
8059 | 0 /* Ignore count */, |
8060 | pending_break_support, | |
8061 | NULL /* breakpoint_ops */, | |
8062 | from_tty, | |
84f4c1fe PM |
8063 | 1 /* enabled */, |
8064 | 0 /* internal */); | |
c906108c SS |
8065 | } |
8066 | ||
72b2ff0e | 8067 | |
c906108c SS |
8068 | /* Helper function for break_command_1 and disassemble_command. */ |
8069 | ||
8070 | void | |
fba45db2 | 8071 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8072 | { |
8073 | CORE_ADDR pc; | |
8074 | ||
8075 | if (sal->pc == 0 && sal->symtab != NULL) | |
8076 | { | |
8077 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8078 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8079 | sal->line, sal->symtab->filename); |
8080 | sal->pc = pc; | |
6a048695 | 8081 | |
4a64f543 MS |
8082 | /* If this SAL corresponds to a breakpoint inserted using a line |
8083 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8084 | if (sal->explicit_line) |
059acae7 | 8085 | skip_prologue_sal (sal); |
c906108c SS |
8086 | } |
8087 | ||
8088 | if (sal->section == 0 && sal->symtab != NULL) | |
8089 | { | |
8090 | struct blockvector *bv; | |
c5aa993b JM |
8091 | struct block *b; |
8092 | struct symbol *sym; | |
c906108c | 8093 | |
801e3a5b | 8094 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8095 | if (bv != NULL) |
8096 | { | |
7f0df278 | 8097 | sym = block_linkage_function (b); |
c906108c SS |
8098 | if (sym != NULL) |
8099 | { | |
8100 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8101 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8102 | } |
8103 | else | |
8104 | { | |
4a64f543 MS |
8105 | /* It really is worthwhile to have the section, so we'll |
8106 | just have to look harder. This case can be executed | |
8107 | if we have line numbers but no functions (as can | |
8108 | happen in assembly source). */ | |
c906108c | 8109 | |
c5aa993b | 8110 | struct minimal_symbol *msym; |
6c95b8df PA |
8111 | struct cleanup *old_chain = save_current_space_and_thread (); |
8112 | ||
8113 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8114 | |
8115 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8116 | if (msym) | |
714835d5 | 8117 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8118 | |
8119 | do_cleanups (old_chain); | |
c906108c SS |
8120 | } |
8121 | } | |
8122 | } | |
8123 | } | |
8124 | ||
8125 | void | |
fba45db2 | 8126 | break_command (char *arg, int from_tty) |
c906108c | 8127 | { |
db107f19 | 8128 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8129 | } |
8130 | ||
c906108c | 8131 | void |
fba45db2 | 8132 | tbreak_command (char *arg, int from_tty) |
c906108c | 8133 | { |
db107f19 | 8134 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8135 | } |
8136 | ||
c906108c | 8137 | static void |
fba45db2 | 8138 | hbreak_command (char *arg, int from_tty) |
c906108c | 8139 | { |
db107f19 | 8140 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8141 | } |
8142 | ||
8143 | static void | |
fba45db2 | 8144 | thbreak_command (char *arg, int from_tty) |
c906108c | 8145 | { |
db107f19 | 8146 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8147 | } |
8148 | ||
8149 | static void | |
fba45db2 | 8150 | stop_command (char *arg, int from_tty) |
c906108c | 8151 | { |
a3f17187 | 8152 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8153 | Usage: stop in <function | address>\n\ |
a3f17187 | 8154 | stop at <line>\n")); |
c906108c SS |
8155 | } |
8156 | ||
8157 | static void | |
fba45db2 | 8158 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8159 | { |
8160 | int badInput = 0; | |
8161 | ||
c5aa993b | 8162 | if (arg == (char *) NULL) |
c906108c SS |
8163 | badInput = 1; |
8164 | else if (*arg != '*') | |
8165 | { | |
8166 | char *argptr = arg; | |
8167 | int hasColon = 0; | |
8168 | ||
4a64f543 | 8169 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8170 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8171 | function/method name. */ |
c906108c | 8172 | while (*argptr && !hasColon) |
c5aa993b JM |
8173 | { |
8174 | hasColon = (*argptr == ':'); | |
8175 | argptr++; | |
8176 | } | |
c906108c SS |
8177 | |
8178 | if (hasColon) | |
c5aa993b | 8179 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8180 | else |
c5aa993b | 8181 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8182 | } |
8183 | ||
8184 | if (badInput) | |
a3f17187 | 8185 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8186 | else |
db107f19 | 8187 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8188 | } |
8189 | ||
8190 | static void | |
fba45db2 | 8191 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8192 | { |
8193 | int badInput = 0; | |
8194 | ||
c5aa993b | 8195 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8196 | badInput = 1; |
8197 | else | |
8198 | { | |
8199 | char *argptr = arg; | |
8200 | int hasColon = 0; | |
8201 | ||
4a64f543 MS |
8202 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8203 | it is probably a line number. */ | |
c906108c | 8204 | while (*argptr && !hasColon) |
c5aa993b JM |
8205 | { |
8206 | hasColon = (*argptr == ':'); | |
8207 | argptr++; | |
8208 | } | |
c906108c SS |
8209 | |
8210 | if (hasColon) | |
c5aa993b | 8211 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8212 | else |
c5aa993b | 8213 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8214 | } |
8215 | ||
8216 | if (badInput) | |
a3f17187 | 8217 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8218 | else |
db107f19 | 8219 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8220 | } |
8221 | ||
4a64f543 MS |
8222 | /* Return non-zero if EXP is verified as constant. Returned zero |
8223 | means EXP is variable. Also the constant detection may fail for | |
8224 | some constant expressions and in such case still falsely return | |
8225 | zero. */ | |
65d79d4b SDJ |
8226 | static int |
8227 | watchpoint_exp_is_const (const struct expression *exp) | |
8228 | { | |
8229 | int i = exp->nelts; | |
8230 | ||
8231 | while (i > 0) | |
8232 | { | |
8233 | int oplenp, argsp; | |
8234 | ||
8235 | /* We are only interested in the descriptor of each element. */ | |
8236 | operator_length (exp, i, &oplenp, &argsp); | |
8237 | i -= oplenp; | |
8238 | ||
8239 | switch (exp->elts[i].opcode) | |
8240 | { | |
8241 | case BINOP_ADD: | |
8242 | case BINOP_SUB: | |
8243 | case BINOP_MUL: | |
8244 | case BINOP_DIV: | |
8245 | case BINOP_REM: | |
8246 | case BINOP_MOD: | |
8247 | case BINOP_LSH: | |
8248 | case BINOP_RSH: | |
8249 | case BINOP_LOGICAL_AND: | |
8250 | case BINOP_LOGICAL_OR: | |
8251 | case BINOP_BITWISE_AND: | |
8252 | case BINOP_BITWISE_IOR: | |
8253 | case BINOP_BITWISE_XOR: | |
8254 | case BINOP_EQUAL: | |
8255 | case BINOP_NOTEQUAL: | |
8256 | case BINOP_LESS: | |
8257 | case BINOP_GTR: | |
8258 | case BINOP_LEQ: | |
8259 | case BINOP_GEQ: | |
8260 | case BINOP_REPEAT: | |
8261 | case BINOP_COMMA: | |
8262 | case BINOP_EXP: | |
8263 | case BINOP_MIN: | |
8264 | case BINOP_MAX: | |
8265 | case BINOP_INTDIV: | |
8266 | case BINOP_CONCAT: | |
8267 | case BINOP_IN: | |
8268 | case BINOP_RANGE: | |
8269 | case TERNOP_COND: | |
8270 | case TERNOP_SLICE: | |
8271 | case TERNOP_SLICE_COUNT: | |
8272 | ||
8273 | case OP_LONG: | |
8274 | case OP_DOUBLE: | |
8275 | case OP_DECFLOAT: | |
8276 | case OP_LAST: | |
8277 | case OP_COMPLEX: | |
8278 | case OP_STRING: | |
8279 | case OP_BITSTRING: | |
8280 | case OP_ARRAY: | |
8281 | case OP_TYPE: | |
8282 | case OP_NAME: | |
8283 | case OP_OBJC_NSSTRING: | |
8284 | ||
8285 | case UNOP_NEG: | |
8286 | case UNOP_LOGICAL_NOT: | |
8287 | case UNOP_COMPLEMENT: | |
8288 | case UNOP_ADDR: | |
8289 | case UNOP_HIGH: | |
4a64f543 MS |
8290 | /* Unary, binary and ternary operators: We have to check |
8291 | their operands. If they are constant, then so is the | |
8292 | result of that operation. For instance, if A and B are | |
8293 | determined to be constants, then so is "A + B". | |
8294 | ||
8295 | UNOP_IND is one exception to the rule above, because the | |
8296 | value of *ADDR is not necessarily a constant, even when | |
8297 | ADDR is. */ | |
65d79d4b SDJ |
8298 | break; |
8299 | ||
8300 | case OP_VAR_VALUE: | |
8301 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8302 | |
65d79d4b | 8303 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8304 | possible that a buggy compiler could mark a variable as |
8305 | constant even when it is not, and TYPE_CONST would return | |
8306 | true in this case, while SYMBOL_CLASS wouldn't. | |
8307 | ||
8308 | We also have to check for function symbols because they | |
8309 | are always constant. */ | |
65d79d4b SDJ |
8310 | { |
8311 | struct symbol *s = exp->elts[i + 2].symbol; | |
8312 | ||
8313 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8314 | && SYMBOL_CLASS (s) != LOC_CONST | |
8315 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8316 | return 0; | |
8317 | break; | |
8318 | } | |
8319 | ||
8320 | /* The default action is to return 0 because we are using | |
8321 | the optimistic approach here: If we don't know something, | |
8322 | then it is not a constant. */ | |
8323 | default: | |
8324 | return 0; | |
8325 | } | |
8326 | } | |
8327 | ||
8328 | return 1; | |
8329 | } | |
8330 | ||
77b06cd7 TJB |
8331 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8332 | ||
8333 | static int | |
8334 | insert_watchpoint (struct bp_location *bl) | |
8335 | { | |
e09342b5 TJB |
8336 | int length = bl->owner->exact? 1 : bl->length; |
8337 | ||
8338 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
8339 | bl->owner->cond_exp); | |
77b06cd7 TJB |
8340 | } |
8341 | ||
8342 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8343 | ||
8344 | static int | |
8345 | remove_watchpoint (struct bp_location *bl) | |
8346 | { | |
e09342b5 TJB |
8347 | int length = bl->owner->exact? 1 : bl->length; |
8348 | ||
8349 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
8350 | bl->owner->cond_exp); | |
8351 | } | |
8352 | ||
8353 | /* Implement the "resources_needed" breakpoint_ops method for | |
8354 | hardware watchpoints. */ | |
8355 | ||
8356 | static int | |
8357 | resources_needed_watchpoint (const struct bp_location *bl) | |
8358 | { | |
90e4670f | 8359 | int length = bl->owner->exact? 1 : bl->length; |
e09342b5 | 8360 | |
90e4670f | 8361 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
77b06cd7 TJB |
8362 | } |
8363 | ||
8364 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8365 | ||
8366 | static struct breakpoint_ops watchpoint_breakpoint_ops = | |
8367 | { | |
8368 | insert_watchpoint, | |
8369 | remove_watchpoint, | |
8370 | NULL, /* breakpoint_hit */ | |
e09342b5 | 8371 | resources_needed_watchpoint, |
77b06cd7 TJB |
8372 | NULL, /* print_it */ |
8373 | NULL, /* print_one */ | |
8374 | NULL, /* print_mention */ | |
8375 | NULL /* print_recreate */ | |
8376 | }; | |
8377 | ||
53a5351d JM |
8378 | /* accessflag: hw_write: watch write, |
8379 | hw_read: watch read, | |
8380 | hw_access: watch access (read or write) */ | |
c906108c | 8381 | static void |
84f4c1fe PM |
8382 | watch_command_1 (char *arg, int accessflag, int from_tty, |
8383 | int just_location, int internal) | |
c906108c | 8384 | { |
d983da9c | 8385 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 8386 | struct expression *exp; |
60e1c644 | 8387 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 8388 | struct value *val, *mark, *result; |
c906108c | 8389 | struct frame_info *frame; |
c906108c SS |
8390 | char *exp_start = NULL; |
8391 | char *exp_end = NULL; | |
37e4754d | 8392 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
8393 | int toklen; |
8394 | char *cond_start = NULL; | |
8395 | char *cond_end = NULL; | |
c906108c SS |
8396 | int i, other_type_used, target_resources_ok = 0; |
8397 | enum bptype bp_type; | |
e09342b5 | 8398 | int reg_cnt = 0; |
37e4754d | 8399 | int thread = -1; |
0cf6dd15 | 8400 | int pc = 0; |
c906108c | 8401 | |
37e4754d LM |
8402 | /* Make sure that we actually have parameters to parse. */ |
8403 | if (arg != NULL && arg[0] != '\0') | |
8404 | { | |
8405 | toklen = strlen (arg); /* Size of argument list. */ | |
8406 | ||
8407 | /* Points tok to the end of the argument list. */ | |
8408 | tok = arg + toklen - 1; | |
8409 | ||
4a64f543 MS |
8410 | /* Go backwards in the parameters list. Skip the last |
8411 | parameter. If we're expecting a 'thread <thread_num>' | |
8412 | parameter, this should be the thread identifier. */ | |
37e4754d LM |
8413 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8414 | tok--; | |
8415 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8416 | tok--; | |
8417 | ||
8418 | /* Points end_tok to the beginning of the last token. */ | |
8419 | id_tok_start = tok + 1; | |
8420 | ||
4a64f543 MS |
8421 | /* Go backwards in the parameters list. Skip one more |
8422 | parameter. If we're expecting a 'thread <thread_num>' | |
8423 | parameter, we should reach a "thread" token. */ | |
37e4754d LM |
8424 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8425 | tok--; | |
8426 | ||
8427 | end_tok = tok; | |
8428 | ||
8429 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8430 | tok--; | |
8431 | ||
8432 | /* Move the pointer forward to skip the whitespace and | |
8433 | calculate the length of the token. */ | |
8434 | tok++; | |
8435 | toklen = end_tok - tok; | |
8436 | ||
8437 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8438 | { | |
8439 | /* At this point we've found a "thread" token, which means | |
8440 | the user is trying to set a watchpoint that triggers | |
8441 | only in a specific thread. */ | |
8442 | char *endp; | |
8443 | ||
8444 | /* Extract the thread ID from the next token. */ | |
8445 | thread = strtol (id_tok_start, &endp, 0); | |
8446 | ||
8447 | /* Check if the user provided a valid numeric value for the | |
8448 | thread ID. */ | |
8449 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
8450 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
8451 | ||
8452 | /* Check if the thread actually exists. */ | |
8453 | if (!valid_thread_id (thread)) | |
8454 | error (_("Unknown thread %d."), thread); | |
8455 | ||
8456 | /* Truncate the string and get rid of the thread <thread_num> | |
8457 | parameter before the parameter list is parsed by the | |
8458 | evaluate_expression() function. */ | |
8459 | *tok = '\0'; | |
8460 | } | |
8461 | } | |
8462 | ||
8463 | /* Parse the rest of the arguments. */ | |
c906108c SS |
8464 | innermost_block = NULL; |
8465 | exp_start = arg; | |
8466 | exp = parse_exp_1 (&arg, 0, 0); | |
8467 | exp_end = arg; | |
fa8a61dc TT |
8468 | /* Remove trailing whitespace from the expression before saving it. |
8469 | This makes the eventual display of the expression string a bit | |
8470 | prettier. */ | |
8471 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
8472 | --exp_end; | |
8473 | ||
65d79d4b SDJ |
8474 | /* Checking if the expression is not constant. */ |
8475 | if (watchpoint_exp_is_const (exp)) | |
8476 | { | |
8477 | int len; | |
8478 | ||
8479 | len = exp_end - exp_start; | |
8480 | while (len > 0 && isspace (exp_start[len - 1])) | |
8481 | len--; | |
8482 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
8483 | } | |
8484 | ||
c906108c SS |
8485 | exp_valid_block = innermost_block; |
8486 | mark = value_mark (); | |
a1442452 | 8487 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
8488 | |
8489 | if (just_location) | |
8490 | { | |
8491 | exp_valid_block = NULL; | |
a1442452 | 8492 | val = value_addr (result); |
06a64a0b TT |
8493 | release_value (val); |
8494 | value_free_to_mark (mark); | |
8495 | } | |
8496 | else if (val != NULL) | |
fa4727a6 | 8497 | release_value (val); |
c906108c | 8498 | |
e9cafbcc TT |
8499 | tok = skip_spaces (arg); |
8500 | end_tok = skip_to_space (tok); | |
c906108c SS |
8501 | |
8502 | toklen = end_tok - tok; | |
8503 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8504 | { | |
2d134ed3 PA |
8505 | struct expression *cond; |
8506 | ||
60e1c644 | 8507 | innermost_block = NULL; |
c906108c SS |
8508 | tok = cond_start = end_tok + 1; |
8509 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
8510 | |
8511 | /* The watchpoint expression may not be local, but the condition | |
8512 | may still be. E.g.: `watch global if local > 0'. */ | |
8513 | cond_exp_valid_block = innermost_block; | |
8514 | ||
2d134ed3 | 8515 | xfree (cond); |
c906108c SS |
8516 | cond_end = tok; |
8517 | } | |
8518 | if (*tok) | |
8a3fe4f8 | 8519 | error (_("Junk at end of command.")); |
c906108c | 8520 | |
53a5351d | 8521 | if (accessflag == hw_read) |
c5aa993b | 8522 | bp_type = bp_read_watchpoint; |
53a5351d | 8523 | else if (accessflag == hw_access) |
c5aa993b JM |
8524 | bp_type = bp_access_watchpoint; |
8525 | else | |
8526 | bp_type = bp_hardware_watchpoint; | |
c906108c | 8527 | |
e09342b5 TJB |
8528 | reg_cnt = can_use_hardware_watchpoint (val, target_exact_watchpoints); |
8529 | if (reg_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 8530 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
e09342b5 | 8531 | if (reg_cnt != 0) |
c5aa993b JM |
8532 | { |
8533 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 8534 | target_resources_ok = |
e09342b5 | 8535 | target_can_use_hardware_watchpoint (bp_type, i + reg_cnt, |
53a5351d | 8536 | other_type_used); |
c5aa993b | 8537 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8538 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 8539 | |
c5aa993b | 8540 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
3e43a32a MS |
8541 | error (_("Target can only support one kind " |
8542 | "of HW watchpoint at a time.")); | |
c5aa993b | 8543 | } |
c906108c | 8544 | |
4a64f543 MS |
8545 | /* Change the type of breakpoint to an ordinary watchpoint if a |
8546 | hardware watchpoint could not be set. */ | |
e09342b5 | 8547 | if (!reg_cnt || target_resources_ok <= 0) |
4d28f7a8 KB |
8548 | bp_type = bp_watchpoint; |
8549 | ||
d983da9c | 8550 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
8551 | |
8552 | /* If the expression is "local", then set up a "watchpoint scope" | |
8553 | breakpoint at the point where we've left the scope of the watchpoint | |
8554 | expression. Create the scope breakpoint before the watchpoint, so | |
8555 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 8556 | if (exp_valid_block && frame) |
d983da9c | 8557 | { |
edb3359d DJ |
8558 | if (frame_id_p (frame_unwind_caller_id (frame))) |
8559 | { | |
8560 | scope_breakpoint | |
a6d9a66e UW |
8561 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
8562 | frame_unwind_caller_pc (frame), | |
edb3359d | 8563 | bp_watchpoint_scope); |
d983da9c | 8564 | |
edb3359d | 8565 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 8566 | |
edb3359d DJ |
8567 | /* Automatically delete the breakpoint when it hits. */ |
8568 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 8569 | |
edb3359d DJ |
8570 | /* Only break in the proper frame (help with recursion). */ |
8571 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 8572 | |
edb3359d | 8573 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
8574 | scope_breakpoint->loc->gdbarch |
8575 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
8576 | scope_breakpoint->loc->requested_address |
8577 | = frame_unwind_caller_pc (frame); | |
8578 | scope_breakpoint->loc->address | |
a6d9a66e UW |
8579 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
8580 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
8581 | scope_breakpoint->type); |
8582 | } | |
d983da9c DJ |
8583 | } |
8584 | ||
c906108c | 8585 | /* Now set up the breakpoint. */ |
2d134ed3 | 8586 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
84f4c1fe | 8587 | set_breakpoint_number (internal, b); |
37e4754d | 8588 | b->thread = thread; |
b5de0fa7 | 8589 | b->disposition = disp_donttouch; |
c906108c SS |
8590 | b->exp = exp; |
8591 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 8592 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
8593 | if (just_location) |
8594 | { | |
8595 | struct type *t = value_type (val); | |
8596 | CORE_ADDR addr = value_as_address (val); | |
8597 | char *name; | |
8598 | ||
8599 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
8600 | name = type_to_string (t); | |
8601 | ||
d63d0675 JK |
8602 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
8603 | core_addr_to_string (addr)); | |
06a64a0b TT |
8604 | xfree (name); |
8605 | ||
d63d0675 JK |
8606 | b->exp_string = xstrprintf ("-location: %.*s", |
8607 | (int) (exp_end - exp_start), exp_start); | |
8608 | ||
06a64a0b TT |
8609 | /* The above expression is in C. */ |
8610 | b->language = language_c; | |
8611 | } | |
8612 | else | |
8613 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
c906108c | 8614 | b->val = val; |
fa4727a6 | 8615 | b->val_valid = 1; |
77b06cd7 TJB |
8616 | b->ops = &watchpoint_breakpoint_ops; |
8617 | ||
e09342b5 TJB |
8618 | /* Use an exact watchpoint when there's only one memory region to be |
8619 | watched, and only one debug register is needed to watch it. */ | |
8620 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
8621 | ||
c906108c SS |
8622 | if (cond_start) |
8623 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
8624 | else | |
8625 | b->cond_string = 0; | |
c5aa993b | 8626 | |
c906108c | 8627 | if (frame) |
f6bc2008 PA |
8628 | { |
8629 | b->watchpoint_frame = get_frame_id (frame); | |
8630 | b->watchpoint_thread = inferior_ptid; | |
8631 | } | |
c906108c | 8632 | else |
f6bc2008 PA |
8633 | { |
8634 | b->watchpoint_frame = null_frame_id; | |
8635 | b->watchpoint_thread = null_ptid; | |
8636 | } | |
c906108c | 8637 | |
d983da9c | 8638 | if (scope_breakpoint != NULL) |
c906108c | 8639 | { |
d983da9c DJ |
8640 | /* The scope breakpoint is related to the watchpoint. We will |
8641 | need to act on them together. */ | |
8642 | b->related_breakpoint = scope_breakpoint; | |
8643 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 8644 | } |
d983da9c | 8645 | |
06a64a0b TT |
8646 | if (!just_location) |
8647 | value_free_to_mark (mark); | |
2d134ed3 PA |
8648 | |
8649 | /* Finally update the new watchpoint. This creates the locations | |
8650 | that should be inserted. */ | |
8651 | update_watchpoint (b, 1); | |
84f4c1fe PM |
8652 | if (internal) |
8653 | /* Do not mention breakpoints with a negative number, but do | |
8654 | notify observers. */ | |
8655 | observer_notify_breakpoint_created (b->number); | |
8656 | else | |
8657 | mention (b); | |
b60e7edf | 8658 | update_global_location_list (1); |
c906108c SS |
8659 | } |
8660 | ||
e09342b5 TJB |
8661 | /* Return count of debug registers needed to watch the given expression. |
8662 | If EXACT_WATCHPOINTS is 1, then consider that only the address of | |
8663 | the start of the watched region will be monitored (i.e., all accesses | |
8664 | will be aligned). This uses less debug registers on some targets. | |
8665 | ||
8666 | If the watchpoint cannot be handled in hardware return zero. */ | |
c906108c | 8667 | |
c906108c | 8668 | static int |
e09342b5 | 8669 | can_use_hardware_watchpoint (struct value *v, int exact_watchpoints) |
c906108c SS |
8670 | { |
8671 | int found_memory_cnt = 0; | |
2e70b7b9 | 8672 | struct value *head = v; |
c906108c SS |
8673 | |
8674 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 8675 | if (!can_use_hw_watchpoints) |
c906108c | 8676 | return 0; |
c5aa993b | 8677 | |
5c44784c JM |
8678 | /* Make sure that the value of the expression depends only upon |
8679 | memory contents, and values computed from them within GDB. If we | |
8680 | find any register references or function calls, we can't use a | |
8681 | hardware watchpoint. | |
8682 | ||
8683 | The idea here is that evaluating an expression generates a series | |
8684 | of values, one holding the value of every subexpression. (The | |
8685 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
8686 | a*b+c.) GDB's values hold almost enough information to establish | |
8687 | the criteria given above --- they identify memory lvalues, | |
8688 | register lvalues, computed values, etcetera. So we can evaluate | |
8689 | the expression, and then scan the chain of values that leaves | |
8690 | behind to decide whether we can detect any possible change to the | |
8691 | expression's final value using only hardware watchpoints. | |
8692 | ||
8693 | However, I don't think that the values returned by inferior | |
8694 | function calls are special in any way. So this function may not | |
8695 | notice that an expression involving an inferior function call | |
8696 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 8697 | for (; v; v = value_next (v)) |
c906108c | 8698 | { |
5c44784c | 8699 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 8700 | { |
8464be76 DJ |
8701 | if (v != head && value_lazy (v)) |
8702 | /* A lazy memory lvalue in the chain is one that GDB never | |
8703 | needed to fetch; we either just used its address (e.g., | |
8704 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
8705 | in `a,b'). This doesn't apply to HEAD; if that is | |
8706 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 8707 | ; |
53a5351d | 8708 | else |
5c44784c JM |
8709 | { |
8710 | /* Ahh, memory we actually used! Check if we can cover | |
8711 | it with hardware watchpoints. */ | |
df407dfe | 8712 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
8713 | |
8714 | /* We only watch structs and arrays if user asked for it | |
8715 | explicitly, never if they just happen to appear in a | |
8716 | middle of some value chain. */ | |
8717 | if (v == head | |
8718 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
8719 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
8720 | { | |
42ae5230 | 8721 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
8722 | int len; |
8723 | int num_regs; | |
8724 | ||
8725 | len = (exact_watchpoints | |
8726 | && is_scalar_type_recursive (vtype))? | |
8727 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 8728 | |
e09342b5 TJB |
8729 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
8730 | if (!num_regs) | |
2e70b7b9 MS |
8731 | return 0; |
8732 | else | |
e09342b5 | 8733 | found_memory_cnt += num_regs; |
2e70b7b9 | 8734 | } |
5c44784c | 8735 | } |
c5aa993b | 8736 | } |
5086187c AC |
8737 | else if (VALUE_LVAL (v) != not_lval |
8738 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 8739 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 8740 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 8741 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
8742 | } |
8743 | ||
8744 | /* The expression itself looks suitable for using a hardware | |
8745 | watchpoint, but give the target machine a chance to reject it. */ | |
8746 | return found_memory_cnt; | |
8747 | } | |
8748 | ||
8b93c638 | 8749 | void |
84f4c1fe | 8750 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8751 | { |
84f4c1fe | 8752 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
8753 | } |
8754 | ||
8755 | /* A helper function that looks for an argument at the start of a | |
8756 | string. The argument must also either be at the end of the string, | |
8757 | or be followed by whitespace. Returns 1 if it finds the argument, | |
8758 | 0 otherwise. If the argument is found, it updates *STR. */ | |
8759 | ||
8760 | static int | |
8761 | check_for_argument (char **str, char *arg, int arg_len) | |
8762 | { | |
8763 | if (strncmp (*str, arg, arg_len) == 0 | |
8764 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
8765 | { | |
8766 | *str += arg_len; | |
8767 | return 1; | |
8768 | } | |
8769 | return 0; | |
8770 | } | |
8771 | ||
8772 | /* A helper function that looks for the "-location" argument and then | |
8773 | calls watch_command_1. */ | |
8774 | ||
8775 | static void | |
8776 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
8777 | { | |
8778 | int just_location = 0; | |
8779 | ||
8780 | if (arg | |
8781 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
8782 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
8783 | { | |
e9cafbcc | 8784 | arg = skip_spaces (arg); |
06a64a0b TT |
8785 | just_location = 1; |
8786 | } | |
8787 | ||
84f4c1fe | 8788 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 8789 | } |
8926118c | 8790 | |
c5aa993b | 8791 | static void |
fba45db2 | 8792 | watch_command (char *arg, int from_tty) |
c906108c | 8793 | { |
06a64a0b | 8794 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
8795 | } |
8796 | ||
8b93c638 | 8797 | void |
84f4c1fe | 8798 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8799 | { |
84f4c1fe | 8800 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 8801 | } |
8926118c | 8802 | |
c5aa993b | 8803 | static void |
fba45db2 | 8804 | rwatch_command (char *arg, int from_tty) |
c906108c | 8805 | { |
06a64a0b | 8806 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
8807 | } |
8808 | ||
8b93c638 | 8809 | void |
84f4c1fe | 8810 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8811 | { |
84f4c1fe | 8812 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 8813 | } |
8926118c | 8814 | |
c5aa993b | 8815 | static void |
fba45db2 | 8816 | awatch_command (char *arg, int from_tty) |
c906108c | 8817 | { |
06a64a0b | 8818 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 8819 | } |
c906108c | 8820 | \f |
c5aa993b | 8821 | |
43ff13b4 | 8822 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8823 | because it uses the mechanisms of breakpoints. */ |
8824 | ||
bfec99b2 PA |
8825 | struct until_break_command_continuation_args |
8826 | { | |
8827 | struct breakpoint *breakpoint; | |
8828 | struct breakpoint *breakpoint2; | |
186c406b | 8829 | int thread_num; |
bfec99b2 PA |
8830 | }; |
8831 | ||
43ff13b4 | 8832 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 8833 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 8834 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 8835 | command. */ |
c2c6d25f | 8836 | static void |
604ead4a | 8837 | until_break_command_continuation (void *arg) |
43ff13b4 | 8838 | { |
bfec99b2 PA |
8839 | struct until_break_command_continuation_args *a = arg; |
8840 | ||
8841 | delete_breakpoint (a->breakpoint); | |
8842 | if (a->breakpoint2) | |
8843 | delete_breakpoint (a->breakpoint2); | |
186c406b | 8844 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
8845 | } |
8846 | ||
c906108c | 8847 | void |
ae66c1fc | 8848 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8849 | { |
8850 | struct symtabs_and_lines sals; | |
8851 | struct symtab_and_line sal; | |
206415a3 | 8852 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8853 | struct breakpoint *breakpoint; |
f107f563 | 8854 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 8855 | struct cleanup *old_chain; |
186c406b TT |
8856 | int thread; |
8857 | struct thread_info *tp; | |
c906108c SS |
8858 | |
8859 | clear_proceed_status (); | |
8860 | ||
8861 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 8862 | this function. */ |
c5aa993b | 8863 | |
c906108c SS |
8864 | if (default_breakpoint_valid) |
8865 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
7efd8fc2 | 8866 | default_breakpoint_line, NULL, NULL); |
c906108c | 8867 | else |
7efd8fc2 | 8868 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL, NULL); |
c5aa993b | 8869 | |
c906108c | 8870 | if (sals.nelts != 1) |
8a3fe4f8 | 8871 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8872 | |
c906108c | 8873 | sal = sals.sals[0]; |
4a64f543 | 8874 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 8875 | |
c906108c | 8876 | if (*arg) |
8a3fe4f8 | 8877 | error (_("Junk at end of arguments.")); |
c5aa993b | 8878 | |
c906108c | 8879 | resolve_sal_pc (&sal); |
c5aa993b | 8880 | |
ae66c1fc EZ |
8881 | if (anywhere) |
8882 | /* If the user told us to continue until a specified location, | |
8883 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8884 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8885 | null_frame_id, bp_until); | |
ae66c1fc | 8886 | else |
4a64f543 MS |
8887 | /* Otherwise, specify the selected frame, because we want to stop |
8888 | only at the very same frame. */ | |
a6d9a66e UW |
8889 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8890 | get_stack_frame_id (frame), | |
ae66c1fc | 8891 | bp_until); |
c5aa993b | 8892 | |
f107f563 | 8893 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8894 | |
186c406b TT |
8895 | tp = inferior_thread (); |
8896 | thread = tp->num; | |
8897 | ||
ae66c1fc EZ |
8898 | /* Keep within the current frame, or in frames called by the current |
8899 | one. */ | |
edb3359d DJ |
8900 | |
8901 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8902 | { |
edb3359d DJ |
8903 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8904 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8905 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8906 | sal, | |
edb3359d | 8907 | frame_unwind_caller_id (frame), |
f107f563 VP |
8908 | bp_until); |
8909 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
8910 | |
8911 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
8912 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 8913 | } |
c5aa993b | 8914 | |
c906108c | 8915 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 8916 | |
4a64f543 MS |
8917 | /* If we are running asynchronously, and proceed call above has |
8918 | actually managed to start the target, arrange for breakpoints to | |
8919 | be deleted when the target stops. Otherwise, we're already | |
8920 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 8921 | |
8ea051c5 | 8922 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8923 | { |
bfec99b2 PA |
8924 | struct until_break_command_continuation_args *args; |
8925 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8926 | |
bfec99b2 PA |
8927 | args->breakpoint = breakpoint; |
8928 | args->breakpoint2 = breakpoint2; | |
186c406b | 8929 | args->thread_num = thread; |
f107f563 VP |
8930 | |
8931 | discard_cleanups (old_chain); | |
95e54da7 PA |
8932 | add_continuation (inferior_thread (), |
8933 | until_break_command_continuation, args, | |
604ead4a | 8934 | xfree); |
f107f563 VP |
8935 | } |
8936 | else | |
c5aa993b | 8937 | do_cleanups (old_chain); |
c906108c | 8938 | } |
ae66c1fc | 8939 | |
c906108c SS |
8940 | /* This function attempts to parse an optional "if <cond>" clause |
8941 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8942 | |
c906108c SS |
8943 | Else, it returns a pointer to the condition string. (It does not |
8944 | attempt to evaluate the string against a particular block.) And, | |
8945 | it updates arg to point to the first character following the parsed | |
4a64f543 | 8946 | if clause in the arg string. */ |
53a5351d | 8947 | |
c906108c | 8948 | static char * |
fba45db2 | 8949 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8950 | { |
c5aa993b JM |
8951 | char *cond_string; |
8952 | ||
8953 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8954 | return NULL; |
c5aa993b | 8955 | |
4a64f543 | 8956 | /* Skip the "if" keyword. */ |
c906108c | 8957 | (*arg) += 2; |
c5aa993b | 8958 | |
c906108c | 8959 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 8960 | condition string. */ |
e9cafbcc | 8961 | *arg = skip_spaces (*arg); |
c906108c | 8962 | cond_string = *arg; |
c5aa993b | 8963 | |
4a64f543 MS |
8964 | /* Assume that the condition occupies the remainder of the arg |
8965 | string. */ | |
c906108c | 8966 | (*arg) += strlen (cond_string); |
c5aa993b | 8967 | |
c906108c SS |
8968 | return cond_string; |
8969 | } | |
c5aa993b | 8970 | |
c906108c SS |
8971 | /* Commands to deal with catching events, such as signals, exceptions, |
8972 | process start/exit, etc. */ | |
c5aa993b JM |
8973 | |
8974 | typedef enum | |
8975 | { | |
44feb3ce TT |
8976 | catch_fork_temporary, catch_vfork_temporary, |
8977 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8978 | } |
8979 | catch_fork_kind; | |
8980 | ||
c906108c | 8981 | static void |
cc59ec59 MS |
8982 | catch_fork_command_1 (char *arg, int from_tty, |
8983 | struct cmd_list_element *command) | |
c906108c | 8984 | { |
a6d9a66e | 8985 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8986 | char *cond_string = NULL; |
44feb3ce TT |
8987 | catch_fork_kind fork_kind; |
8988 | int tempflag; | |
8989 | ||
8990 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8991 | tempflag = (fork_kind == catch_fork_temporary | |
8992 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8993 | |
44feb3ce TT |
8994 | if (!arg) |
8995 | arg = ""; | |
e9cafbcc | 8996 | arg = skip_spaces (arg); |
c5aa993b | 8997 | |
c906108c | 8998 | /* The allowed syntax is: |
c5aa993b JM |
8999 | catch [v]fork |
9000 | catch [v]fork if <cond> | |
9001 | ||
4a64f543 | 9002 | First, check if there's an if clause. */ |
c906108c | 9003 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9004 | |
c906108c | 9005 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9006 | error (_("Junk at end of arguments.")); |
c5aa993b | 9007 | |
c906108c | 9008 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9009 | and enable reporting of such events. */ |
c5aa993b JM |
9010 | switch (fork_kind) |
9011 | { | |
44feb3ce TT |
9012 | case catch_fork_temporary: |
9013 | case catch_fork_permanent: | |
a6d9a66e | 9014 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9015 | &catch_fork_breakpoint_ops); |
c906108c | 9016 | break; |
44feb3ce TT |
9017 | case catch_vfork_temporary: |
9018 | case catch_vfork_permanent: | |
a6d9a66e | 9019 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9020 | &catch_vfork_breakpoint_ops); |
c906108c | 9021 | break; |
c5aa993b | 9022 | default: |
8a3fe4f8 | 9023 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9024 | break; |
c5aa993b | 9025 | } |
c906108c SS |
9026 | } |
9027 | ||
9028 | static void | |
cc59ec59 MS |
9029 | catch_exec_command_1 (char *arg, int from_tty, |
9030 | struct cmd_list_element *command) | |
c906108c | 9031 | { |
a6d9a66e | 9032 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9033 | int tempflag; |
c5aa993b | 9034 | char *cond_string = NULL; |
c906108c | 9035 | |
44feb3ce TT |
9036 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9037 | ||
9038 | if (!arg) | |
9039 | arg = ""; | |
e9cafbcc | 9040 | arg = skip_spaces (arg); |
c906108c SS |
9041 | |
9042 | /* The allowed syntax is: | |
c5aa993b JM |
9043 | catch exec |
9044 | catch exec if <cond> | |
c906108c | 9045 | |
4a64f543 | 9046 | First, check if there's an if clause. */ |
c906108c SS |
9047 | cond_string = ep_parse_optional_if_clause (&arg); |
9048 | ||
9049 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9050 | error (_("Junk at end of arguments.")); |
c906108c SS |
9051 | |
9052 | /* If this target supports it, create an exec catchpoint | |
4a64f543 | 9053 | and enable reporting of such events. */ |
a6d9a66e UW |
9054 | create_catchpoint (gdbarch, tempflag, cond_string, |
9055 | &catch_exec_breakpoint_ops); | |
c906108c | 9056 | } |
c5aa993b | 9057 | |
3086aeae DJ |
9058 | static enum print_stop_action |
9059 | print_exception_catchpoint (struct breakpoint *b) | |
9060 | { | |
ade92717 | 9061 | int bp_temp, bp_throw; |
3086aeae | 9062 | |
ade92717 | 9063 | annotate_catchpoint (b->number); |
3086aeae | 9064 | |
ade92717 AR |
9065 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9066 | if (b->loc->address != b->loc->requested_address) | |
9067 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9068 | b->loc->address, | |
9069 | b->number, 1); | |
df2b6d2d | 9070 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9071 | ui_out_text (uiout, |
9072 | bp_temp ? "Temporary catchpoint " | |
9073 | : "Catchpoint "); | |
9074 | if (!ui_out_is_mi_like_p (uiout)) | |
9075 | ui_out_field_int (uiout, "bkptno", b->number); | |
9076 | ui_out_text (uiout, | |
c0b37c48 AR |
9077 | bp_throw ? " (exception thrown), " |
9078 | : " (exception caught), "); | |
ade92717 AR |
9079 | if (ui_out_is_mi_like_p (uiout)) |
9080 | { | |
9081 | ui_out_field_string (uiout, "reason", | |
9082 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9083 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9084 | ui_out_field_int (uiout, "bkptno", b->number); | |
9085 | } | |
3086aeae DJ |
9086 | return PRINT_SRC_AND_LOC; |
9087 | } | |
9088 | ||
9089 | static void | |
cc59ec59 MS |
9090 | print_one_exception_catchpoint (struct breakpoint *b, |
9091 | struct bp_location **last_loc) | |
3086aeae | 9092 | { |
79a45b7d | 9093 | struct value_print_options opts; |
cc59ec59 | 9094 | |
79a45b7d TT |
9095 | get_user_print_options (&opts); |
9096 | if (opts.addressprint) | |
3086aeae DJ |
9097 | { |
9098 | annotate_field (4); | |
604133b5 AR |
9099 | if (b->loc == NULL || b->loc->shlib_disabled) |
9100 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9101 | else | |
5af949e3 UW |
9102 | ui_out_field_core_addr (uiout, "addr", |
9103 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9104 | } |
9105 | annotate_field (5); | |
604133b5 | 9106 | if (b->loc) |
a6d9a66e | 9107 | *last_loc = b->loc; |
3086aeae DJ |
9108 | if (strstr (b->addr_string, "throw") != NULL) |
9109 | ui_out_field_string (uiout, "what", "exception throw"); | |
9110 | else | |
9111 | ui_out_field_string (uiout, "what", "exception catch"); | |
9112 | } | |
9113 | ||
9114 | static void | |
9115 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9116 | { | |
ade92717 AR |
9117 | int bp_temp; |
9118 | int bp_throw; | |
9119 | ||
df2b6d2d | 9120 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9121 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9122 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9123 | : _("Catchpoint ")); | |
9124 | ui_out_field_int (uiout, "bkptno", b->number); | |
9125 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9126 | : _(" (catch)")); | |
3086aeae DJ |
9127 | } |
9128 | ||
6149aea9 PA |
9129 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9130 | catch catchpoints. */ | |
9131 | ||
9132 | static void | |
4a64f543 MS |
9133 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9134 | struct ui_file *fp) | |
6149aea9 PA |
9135 | { |
9136 | int bp_temp; | |
9137 | int bp_throw; | |
9138 | ||
9139 | bp_temp = b->disposition == disp_del; | |
9140 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9141 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9142 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
9143 | } | |
9144 | ||
3086aeae | 9145 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
9146 | NULL, /* insert */ |
9147 | NULL, /* remove */ | |
9148 | NULL, /* breakpoint_hit */ | |
e09342b5 | 9149 | NULL, /* resources_needed */ |
3086aeae DJ |
9150 | print_exception_catchpoint, |
9151 | print_one_exception_catchpoint, | |
6149aea9 PA |
9152 | print_mention_exception_catchpoint, |
9153 | print_recreate_exception_catchpoint | |
3086aeae DJ |
9154 | }; |
9155 | ||
9156 | static int | |
9157 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9158 | enum exception_event_kind ex_event, int from_tty) | |
9159 | { | |
604133b5 AR |
9160 | char *trigger_func_name; |
9161 | ||
3086aeae | 9162 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9163 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9164 | else |
604133b5 | 9165 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9166 | |
8cdf0e15 VP |
9167 | create_breakpoint (get_current_arch (), |
9168 | trigger_func_name, cond_string, -1, | |
9169 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9170 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9171 | 0, |
9172 | AUTO_BOOLEAN_TRUE /* pending */, | |
9173 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9174 | 1 /* enabled */, |
9175 | 0 /* internal */); | |
3086aeae | 9176 | |
3086aeae DJ |
9177 | return 1; |
9178 | } | |
9179 | ||
4a64f543 | 9180 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9181 | |
9182 | static void | |
fba45db2 KB |
9183 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9184 | int tempflag, int from_tty) | |
c906108c | 9185 | { |
c5aa993b | 9186 | char *cond_string = NULL; |
c5aa993b | 9187 | |
44feb3ce TT |
9188 | if (!arg) |
9189 | arg = ""; | |
e9cafbcc | 9190 | arg = skip_spaces (arg); |
c5aa993b | 9191 | |
c906108c SS |
9192 | cond_string = ep_parse_optional_if_clause (&arg); |
9193 | ||
9194 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9195 | error (_("Junk at end of arguments.")); |
c906108c | 9196 | |
059fb39f PM |
9197 | if (ex_event != EX_EVENT_THROW |
9198 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9199 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9200 | |
3086aeae DJ |
9201 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9202 | return; | |
9203 | ||
8a3fe4f8 | 9204 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9205 | } |
9206 | ||
44feb3ce TT |
9207 | /* Implementation of "catch catch" command. */ |
9208 | ||
9209 | static void | |
9210 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9211 | { | |
9212 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9213 | |
44feb3ce TT |
9214 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9215 | } | |
9216 | ||
9217 | /* Implementation of "catch throw" command. */ | |
9218 | ||
9219 | static void | |
9220 | catch_throw_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_THROW, arg, tempflag, from_tty); |
9225 | } | |
9226 | ||
f7f9143b JB |
9227 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
9228 | ||
9229 | static void | |
a6d9a66e UW |
9230 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
9231 | struct symtab_and_line sal, | |
f7f9143b JB |
9232 | char *addr_string, |
9233 | char *exp_string, | |
9234 | char *cond_string, | |
9235 | struct expression *cond, | |
9236 | struct breakpoint_ops *ops, | |
9237 | int tempflag, | |
9238 | int from_tty) | |
9239 | { | |
9240 | struct breakpoint *b; | |
9241 | ||
9242 | if (from_tty) | |
9243 | { | |
5af949e3 UW |
9244 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9245 | if (!loc_gdbarch) | |
9246 | loc_gdbarch = gdbarch; | |
9247 | ||
6c95b8df PA |
9248 | describe_other_breakpoints (loc_gdbarch, |
9249 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9250 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9251 | version for exception catchpoints, because two catchpoints | |
9252 | used for different exception names will use the same address. | |
9253 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9254 | unproductive. Besides, the warning phrasing is also a bit |
f7f9143b JB |
9255 | inapropriate, we should use the word catchpoint, and tell |
9256 | the user what type of catchpoint it is. The above is good | |
9257 | enough for now, though. */ | |
9258 | } | |
9259 | ||
a6d9a66e | 9260 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
9261 | set_breakpoint_count (breakpoint_count + 1); |
9262 | ||
9263 | b->enable_state = bp_enabled; | |
9264 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
9265 | b->number = breakpoint_count; | |
9266 | b->ignore_count = 0; | |
511a6cd4 | 9267 | b->loc->cond = cond; |
f7f9143b JB |
9268 | b->addr_string = addr_string; |
9269 | b->language = language_ada; | |
9270 | b->cond_string = cond_string; | |
9271 | b->exp_string = exp_string; | |
9272 | b->thread = -1; | |
9273 | b->ops = ops; | |
f7f9143b JB |
9274 | |
9275 | mention (b); | |
b60e7edf | 9276 | update_global_location_list (1); |
f7f9143b JB |
9277 | } |
9278 | ||
9279 | /* Implement the "catch exception" command. */ | |
9280 | ||
9281 | static void | |
44feb3ce TT |
9282 | catch_ada_exception_command (char *arg, int from_tty, |
9283 | struct cmd_list_element *command) | |
f7f9143b | 9284 | { |
a6d9a66e | 9285 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9286 | int tempflag; |
f7f9143b | 9287 | struct symtab_and_line sal; |
f7f9143b JB |
9288 | char *addr_string = NULL; |
9289 | char *exp_string = NULL; | |
9290 | char *cond_string = NULL; | |
9291 | struct expression *cond = NULL; | |
9292 | struct breakpoint_ops *ops = NULL; | |
9293 | ||
44feb3ce TT |
9294 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9295 | ||
9296 | if (!arg) | |
9297 | arg = ""; | |
f7f9143b JB |
9298 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
9299 | &cond_string, &cond, &ops); | |
a6d9a66e | 9300 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
9301 | cond_string, cond, ops, tempflag, |
9302 | from_tty); | |
9303 | } | |
9304 | ||
a96d9b2e SDJ |
9305 | /* Cleanup function for a syscall filter list. */ |
9306 | static void | |
9307 | clean_up_filters (void *arg) | |
9308 | { | |
9309 | VEC(int) *iter = *(VEC(int) **) arg; | |
9310 | VEC_free (int, iter); | |
9311 | } | |
9312 | ||
9313 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
9314 | filter list, or NULL if no filtering is required. */ | |
9315 | static VEC(int) * | |
9316 | catch_syscall_split_args (char *arg) | |
9317 | { | |
9318 | VEC(int) *result = NULL; | |
9319 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
9320 | ||
9321 | while (*arg != '\0') | |
9322 | { | |
9323 | int i, syscall_number; | |
9324 | char *endptr; | |
9325 | char cur_name[128]; | |
9326 | struct syscall s; | |
9327 | ||
9328 | /* Skip whitespace. */ | |
9329 | while (isspace (*arg)) | |
9330 | arg++; | |
9331 | ||
9332 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9333 | cur_name[i] = arg[i]; | |
9334 | cur_name[i] = '\0'; | |
9335 | arg += i; | |
9336 | ||
9337 | /* Check if the user provided a syscall name or a number. */ | |
9338 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9339 | if (*endptr == '\0') | |
bccd0dd2 | 9340 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9341 | else |
9342 | { | |
9343 | /* We have a name. Let's check if it's valid and convert it | |
9344 | to a number. */ | |
9345 | get_syscall_by_name (cur_name, &s); | |
9346 | ||
9347 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9348 | /* Here we have to issue an error instead of a warning, |
9349 | because GDB cannot do anything useful if there's no | |
9350 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9351 | error (_("Unknown syscall name '%s'."), cur_name); |
9352 | } | |
9353 | ||
9354 | /* Ok, it's valid. */ | |
9355 | VEC_safe_push (int, result, s.number); | |
9356 | } | |
9357 | ||
9358 | discard_cleanups (cleanup); | |
9359 | return result; | |
9360 | } | |
9361 | ||
9362 | /* Implement the "catch syscall" command. */ | |
9363 | ||
9364 | static void | |
cc59ec59 MS |
9365 | catch_syscall_command_1 (char *arg, int from_tty, |
9366 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
9367 | { |
9368 | int tempflag; | |
9369 | VEC(int) *filter; | |
9370 | struct syscall s; | |
9371 | struct gdbarch *gdbarch = get_current_arch (); | |
9372 | ||
9373 | /* Checking if the feature if supported. */ | |
9374 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
9375 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 9376 | this architecture yet.")); |
a96d9b2e SDJ |
9377 | |
9378 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
9379 | ||
e9cafbcc | 9380 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
9381 | |
9382 | /* We need to do this first "dummy" translation in order | |
9383 | to get the syscall XML file loaded or, most important, | |
9384 | to display a warning to the user if there's no XML file | |
9385 | for his/her architecture. */ | |
9386 | get_syscall_by_number (0, &s); | |
9387 | ||
9388 | /* The allowed syntax is: | |
9389 | catch syscall | |
9390 | catch syscall <name | number> [<name | number> ... <name | number>] | |
9391 | ||
9392 | Let's check if there's a syscall name. */ | |
9393 | ||
9394 | if (arg != NULL) | |
9395 | filter = catch_syscall_split_args (arg); | |
9396 | else | |
9397 | filter = NULL; | |
9398 | ||
9399 | create_syscall_event_catchpoint (tempflag, filter, | |
9400 | &catch_syscall_breakpoint_ops); | |
9401 | } | |
9402 | ||
f7f9143b JB |
9403 | /* Implement the "catch assert" command. */ |
9404 | ||
9405 | static void | |
3e43a32a MS |
9406 | catch_assert_command (char *arg, int from_tty, |
9407 | struct cmd_list_element *command) | |
f7f9143b | 9408 | { |
a6d9a66e | 9409 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9410 | int tempflag; |
f7f9143b JB |
9411 | struct symtab_and_line sal; |
9412 | char *addr_string = NULL; | |
9413 | struct breakpoint_ops *ops = NULL; | |
9414 | ||
44feb3ce TT |
9415 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9416 | ||
9417 | if (!arg) | |
9418 | arg = ""; | |
f7f9143b | 9419 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
9420 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
9421 | ops, tempflag, from_tty); | |
f7f9143b JB |
9422 | } |
9423 | ||
c906108c | 9424 | static void |
fba45db2 | 9425 | catch_command (char *arg, int from_tty) |
c906108c | 9426 | { |
44feb3ce | 9427 | error (_("Catch requires an event name.")); |
c906108c SS |
9428 | } |
9429 | \f | |
9430 | ||
9431 | static void | |
fba45db2 | 9432 | tcatch_command (char *arg, int from_tty) |
c906108c | 9433 | { |
44feb3ce | 9434 | error (_("Catch requires an event name.")); |
c906108c SS |
9435 | } |
9436 | ||
80f8a6eb | 9437 | /* Delete breakpoints by address or line. */ |
c906108c SS |
9438 | |
9439 | static void | |
fba45db2 | 9440 | clear_command (char *arg, int from_tty) |
c906108c | 9441 | { |
d6e956e5 VP |
9442 | struct breakpoint *b; |
9443 | VEC(breakpoint_p) *found = 0; | |
9444 | int ix; | |
c906108c SS |
9445 | int default_match; |
9446 | struct symtabs_and_lines sals; | |
9447 | struct symtab_and_line sal; | |
c906108c SS |
9448 | int i; |
9449 | ||
9450 | if (arg) | |
9451 | { | |
9452 | sals = decode_line_spec (arg, 1); | |
9453 | default_match = 0; | |
9454 | } | |
9455 | else | |
9456 | { | |
c5aa993b | 9457 | sals.sals = (struct symtab_and_line *) |
c906108c | 9458 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 9459 | make_cleanup (xfree, sals.sals); |
4a64f543 | 9460 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
9461 | sal.line = default_breakpoint_line; |
9462 | sal.symtab = default_breakpoint_symtab; | |
9463 | sal.pc = default_breakpoint_address; | |
6c95b8df | 9464 | sal.pspace = default_breakpoint_pspace; |
c906108c | 9465 | if (sal.symtab == 0) |
8a3fe4f8 | 9466 | error (_("No source file specified.")); |
c906108c SS |
9467 | |
9468 | sals.sals[0] = sal; | |
9469 | sals.nelts = 1; | |
9470 | ||
9471 | default_match = 1; | |
9472 | } | |
9473 | ||
4a64f543 MS |
9474 | /* We don't call resolve_sal_pc here. That's not as bad as it |
9475 | seems, because all existing breakpoints typically have both | |
9476 | file/line and pc set. So, if clear is given file/line, we can | |
9477 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
9478 | |
9479 | We only support clearing given the address explicitly | |
9480 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 9481 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 9482 | due to optimization, all in one block. |
4a64f543 MS |
9483 | |
9484 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
9485 | PC corresponding to the same file:line, the breakpoint won't |
9486 | be cleared. We probably can still clear the breakpoint, but | |
9487 | since the other PC value is never presented to user, user | |
9488 | can only find it by guessing, and it does not seem important | |
9489 | to support that. */ | |
9490 | ||
4a64f543 MS |
9491 | /* For each line spec given, delete bps which correspond to it. Do |
9492 | it in two passes, solely to preserve the current behavior that | |
9493 | from_tty is forced true if we delete more than one | |
9494 | breakpoint. */ | |
c906108c | 9495 | |
80f8a6eb | 9496 | found = NULL; |
c906108c SS |
9497 | for (i = 0; i < sals.nelts; i++) |
9498 | { | |
9499 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
9500 | If line given (pc == 0), clear all bpts on specified line. |
9501 | If defaulting, clear all bpts on default line | |
c906108c | 9502 | or at default pc. |
c5aa993b JM |
9503 | |
9504 | defaulting sal.pc != 0 tests to do | |
9505 | ||
9506 | 0 1 pc | |
9507 | 1 1 pc _and_ line | |
9508 | 0 0 line | |
9509 | 1 0 <can't happen> */ | |
c906108c SS |
9510 | |
9511 | sal = sals.sals[i]; | |
c906108c | 9512 | |
4a64f543 | 9513 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 9514 | ALL_BREAKPOINTS (b) |
c5aa993b | 9515 | { |
0d381245 | 9516 | int match = 0; |
4a64f543 | 9517 | /* Are we going to delete b? */ |
cc60f2e3 | 9518 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
9519 | { |
9520 | struct bp_location *loc = b->loc; | |
9521 | for (; loc; loc = loc->next) | |
9522 | { | |
6c95b8df PA |
9523 | int pc_match = sal.pc |
9524 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
9525 | && (loc->address == sal.pc) |
9526 | && (!section_is_overlay (loc->section) | |
9527 | || loc->section == sal.section); | |
9528 | int line_match = ((default_match || (0 == sal.pc)) | |
9529 | && b->source_file != NULL | |
9530 | && sal.symtab != NULL | |
6c95b8df | 9531 | && sal.pspace == loc->pspace |
0ba1096a KT |
9532 | && filename_cmp (b->source_file, |
9533 | sal.symtab->filename) == 0 | |
0d381245 VP |
9534 | && b->line_number == sal.line); |
9535 | if (pc_match || line_match) | |
9536 | { | |
9537 | match = 1; | |
9538 | break; | |
9539 | } | |
9540 | } | |
9541 | } | |
9542 | ||
9543 | if (match) | |
d6e956e5 | 9544 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 9545 | } |
80f8a6eb MS |
9546 | } |
9547 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 9548 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
9549 | { |
9550 | if (arg) | |
8a3fe4f8 | 9551 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 9552 | else |
8a3fe4f8 | 9553 | error (_("No breakpoint at this line.")); |
80f8a6eb | 9554 | } |
c906108c | 9555 | |
d6e956e5 | 9556 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 9557 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 9558 | if (from_tty) |
a3f17187 | 9559 | { |
d6e956e5 | 9560 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
9561 | printf_unfiltered (_("Deleted breakpoint ")); |
9562 | else | |
9563 | printf_unfiltered (_("Deleted breakpoints ")); | |
9564 | } | |
80f8a6eb | 9565 | breakpoints_changed (); |
d6e956e5 VP |
9566 | |
9567 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 9568 | { |
c5aa993b | 9569 | if (from_tty) |
d6e956e5 VP |
9570 | printf_unfiltered ("%d ", b->number); |
9571 | delete_breakpoint (b); | |
c906108c | 9572 | } |
80f8a6eb MS |
9573 | if (from_tty) |
9574 | putchar_unfiltered ('\n'); | |
c906108c SS |
9575 | } |
9576 | \f | |
9577 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
9578 | all breakpoints that are marked for deletion, whether hit or not. | |
9579 | This is called after any breakpoint is hit, or after errors. */ | |
9580 | ||
9581 | void | |
fba45db2 | 9582 | breakpoint_auto_delete (bpstat bs) |
c906108c | 9583 | { |
35df4500 | 9584 | struct breakpoint *b, *b_tmp; |
c906108c SS |
9585 | |
9586 | for (; bs; bs = bs->next) | |
f431efe5 PA |
9587 | if (bs->breakpoint_at |
9588 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 9589 | && bs->stop) |
f431efe5 | 9590 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 9591 | |
35df4500 | 9592 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 9593 | { |
b5de0fa7 | 9594 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
9595 | delete_breakpoint (b); |
9596 | } | |
c906108c SS |
9597 | } |
9598 | ||
4a64f543 MS |
9599 | /* A comparison function for bp_location AP and BP being interfaced to |
9600 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
9601 | does breakpoint_address_is_meaningful say for its OWNER), | |
9602 | secondarily by ordering first bp_permanent OWNERed elements and | |
9603 | terciarily just ensuring the array is sorted stable way despite | |
9604 | qsort being an instable algorithm. */ | |
876fa593 JK |
9605 | |
9606 | static int | |
494cfb0f | 9607 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 9608 | { |
494cfb0f JK |
9609 | struct bp_location *a = *(void **) ap; |
9610 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 9611 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
9612 | int a_perm = a->owner->enable_state == bp_permanent; |
9613 | int b_perm = b->owner->enable_state == bp_permanent; | |
9614 | ||
9615 | if (a->address != b->address) | |
9616 | return (a->address > b->address) - (a->address < b->address); | |
9617 | ||
9618 | /* Sort permanent breakpoints first. */ | |
9619 | if (a_perm != b_perm) | |
9620 | return (a_perm < b_perm) - (a_perm > b_perm); | |
9621 | ||
4a64f543 MS |
9622 | /* Make the user-visible order stable across GDB runs. Locations of |
9623 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
9624 | |
9625 | if (a->owner->number != b->owner->number) | |
9626 | return (a->owner->number > b->owner->number) | |
9627 | - (a->owner->number < b->owner->number); | |
9628 | ||
9629 | return (a > b) - (a < b); | |
9630 | } | |
9631 | ||
876fa593 | 9632 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
9633 | bp_location_shadow_len_after_address_max according to the current |
9634 | content of the bp_location array. */ | |
f7545552 TT |
9635 | |
9636 | static void | |
876fa593 | 9637 | bp_location_target_extensions_update (void) |
f7545552 | 9638 | { |
876fa593 JK |
9639 | struct bp_location *bl, **blp_tmp; |
9640 | ||
9641 | bp_location_placed_address_before_address_max = 0; | |
9642 | bp_location_shadow_len_after_address_max = 0; | |
9643 | ||
9644 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
9645 | { | |
9646 | CORE_ADDR start, end, addr; | |
9647 | ||
9648 | if (!bp_location_has_shadow (bl)) | |
9649 | continue; | |
9650 | ||
9651 | start = bl->target_info.placed_address; | |
9652 | end = start + bl->target_info.shadow_len; | |
9653 | ||
9654 | gdb_assert (bl->address >= start); | |
9655 | addr = bl->address - start; | |
9656 | if (addr > bp_location_placed_address_before_address_max) | |
9657 | bp_location_placed_address_before_address_max = addr; | |
9658 | ||
9659 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
9660 | ||
9661 | gdb_assert (bl->address < end); | |
9662 | addr = end - bl->address; | |
9663 | if (addr > bp_location_shadow_len_after_address_max) | |
9664 | bp_location_shadow_len_after_address_max = addr; | |
9665 | } | |
f7545552 TT |
9666 | } |
9667 | ||
4cd9bd08 | 9668 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
9669 | into the inferior, only remove already-inserted locations that no |
9670 | longer should be inserted. Functions that delete a breakpoint or | |
9671 | breakpoints should pass false, so that deleting a breakpoint | |
9672 | doesn't have the side effect of inserting the locations of other | |
9673 | breakpoints that are marked not-inserted, but should_be_inserted | |
9674 | returns true on them. | |
9675 | ||
9676 | This behaviour is useful is situations close to tear-down -- e.g., | |
9677 | after an exec, while the target still has execution, but breakpoint | |
9678 | shadows of the previous executable image should *NOT* be restored | |
9679 | to the new image; or before detaching, where the target still has | |
9680 | execution and wants to delete breakpoints from GDB's lists, and all | |
9681 | breakpoints had already been removed from the inferior. */ | |
9682 | ||
0d381245 | 9683 | static void |
b60e7edf | 9684 | update_global_location_list (int should_insert) |
0d381245 | 9685 | { |
74960c60 | 9686 | struct breakpoint *b; |
876fa593 | 9687 | struct bp_location **locp, *loc; |
f7545552 TT |
9688 | struct cleanup *cleanups; |
9689 | ||
2d134ed3 PA |
9690 | /* Used in the duplicates detection below. When iterating over all |
9691 | bp_locations, points to the first bp_location of a given address. | |
9692 | Breakpoints and watchpoints of different types are never | |
9693 | duplicates of each other. Keep one pointer for each type of | |
9694 | breakpoint/watchpoint, so we only need to loop over all locations | |
9695 | once. */ | |
9696 | struct bp_location *bp_loc_first; /* breakpoint */ | |
9697 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
9698 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
9699 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 9700 | |
4a64f543 MS |
9701 | /* Saved former bp_location array which we compare against the newly |
9702 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
9703 | struct bp_location **old_location, **old_locp; |
9704 | unsigned old_location_count; | |
9705 | ||
9706 | old_location = bp_location; | |
9707 | old_location_count = bp_location_count; | |
9708 | bp_location = NULL; | |
9709 | bp_location_count = 0; | |
9710 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 9711 | |
74960c60 | 9712 | ALL_BREAKPOINTS (b) |
876fa593 JK |
9713 | for (loc = b->loc; loc; loc = loc->next) |
9714 | bp_location_count++; | |
9715 | ||
9716 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
9717 | locp = bp_location; | |
9718 | ALL_BREAKPOINTS (b) | |
9719 | for (loc = b->loc; loc; loc = loc->next) | |
9720 | *locp++ = loc; | |
9721 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 9722 | bp_location_compare); |
876fa593 JK |
9723 | |
9724 | bp_location_target_extensions_update (); | |
74960c60 | 9725 | |
4a64f543 MS |
9726 | /* Identify bp_location instances that are no longer present in the |
9727 | new list, and therefore should be freed. Note that it's not | |
9728 | necessary that those locations should be removed from inferior -- | |
9729 | if there's another location at the same address (previously | |
9730 | marked as duplicate), we don't need to remove/insert the | |
9731 | location. | |
876fa593 | 9732 | |
4a64f543 MS |
9733 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
9734 | and former bp_location array state respectively. */ | |
876fa593 JK |
9735 | |
9736 | locp = bp_location; | |
9737 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
9738 | old_locp++) | |
74960c60 | 9739 | { |
876fa593 | 9740 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 9741 | struct bp_location **loc2p; |
876fa593 | 9742 | |
4a64f543 MS |
9743 | /* Tells if 'old_loc' is found amoung the new locations. If |
9744 | not, we have to free it. */ | |
c7d46a38 | 9745 | int found_object = 0; |
20874c92 VP |
9746 | /* Tells if the location should remain inserted in the target. */ |
9747 | int keep_in_target = 0; | |
9748 | int removed = 0; | |
876fa593 | 9749 | |
4a64f543 MS |
9750 | /* Skip LOCP entries which will definitely never be needed. |
9751 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 9752 | while (locp < bp_location + bp_location_count |
c7d46a38 | 9753 | && (*locp)->address < old_loc->address) |
876fa593 | 9754 | locp++; |
c7d46a38 PA |
9755 | |
9756 | for (loc2p = locp; | |
9757 | (loc2p < bp_location + bp_location_count | |
9758 | && (*loc2p)->address == old_loc->address); | |
9759 | loc2p++) | |
9760 | { | |
9761 | if (*loc2p == old_loc) | |
9762 | { | |
9763 | found_object = 1; | |
9764 | break; | |
9765 | } | |
9766 | } | |
74960c60 | 9767 | |
4a64f543 MS |
9768 | /* If this location is no longer present, and inserted, look if |
9769 | there's maybe a new location at the same address. If so, | |
9770 | mark that one inserted, and don't remove this one. This is | |
9771 | needed so that we don't have a time window where a breakpoint | |
9772 | at certain location is not inserted. */ | |
74960c60 | 9773 | |
876fa593 | 9774 | if (old_loc->inserted) |
0d381245 | 9775 | { |
4a64f543 MS |
9776 | /* If the location is inserted now, we might have to remove |
9777 | it. */ | |
74960c60 | 9778 | |
876fa593 | 9779 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 9780 | { |
4a64f543 MS |
9781 | /* The location is still present in the location list, |
9782 | and still should be inserted. Don't do anything. */ | |
20874c92 | 9783 | keep_in_target = 1; |
74960c60 VP |
9784 | } |
9785 | else | |
9786 | { | |
4a64f543 MS |
9787 | /* The location is either no longer present, or got |
9788 | disabled. See if there's another location at the | |
9789 | same address, in which case we don't need to remove | |
9790 | this one from the target. */ | |
876fa593 | 9791 | |
2bdf28a0 | 9792 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
9793 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
9794 | { | |
876fa593 | 9795 | for (loc2p = locp; |
c7d46a38 PA |
9796 | (loc2p < bp_location + bp_location_count |
9797 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
9798 | loc2p++) |
9799 | { | |
9800 | struct bp_location *loc2 = *loc2p; | |
9801 | ||
2d134ed3 | 9802 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
9803 | { |
9804 | /* For the sake of should_be_inserted. | |
4a64f543 MS |
9805 | Duplicates check below will fix up this |
9806 | later. */ | |
c7d46a38 | 9807 | loc2->duplicate = 0; |
85d721b8 PA |
9808 | |
9809 | /* Read watchpoint locations are switched to | |
9810 | access watchpoints, if the former are not | |
9811 | supported, but the latter are. */ | |
9812 | if (is_hardware_watchpoint (old_loc->owner)) | |
9813 | { | |
9814 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
9815 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
9816 | } | |
9817 | ||
c7d46a38 PA |
9818 | if (loc2 != old_loc && should_be_inserted (loc2)) |
9819 | { | |
9820 | loc2->inserted = 1; | |
9821 | loc2->target_info = old_loc->target_info; | |
9822 | keep_in_target = 1; | |
9823 | break; | |
9824 | } | |
876fa593 JK |
9825 | } |
9826 | } | |
9827 | } | |
74960c60 VP |
9828 | } |
9829 | ||
20874c92 VP |
9830 | if (!keep_in_target) |
9831 | { | |
876fa593 | 9832 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 9833 | { |
4a64f543 MS |
9834 | /* This is just about all we can do. We could keep |
9835 | this location on the global list, and try to | |
9836 | remove it next time, but there's no particular | |
9837 | reason why we will succeed next time. | |
20874c92 | 9838 | |
4a64f543 MS |
9839 | Note that at this point, old_loc->owner is still |
9840 | valid, as delete_breakpoint frees the breakpoint | |
9841 | only after calling us. */ | |
3e43a32a MS |
9842 | printf_filtered (_("warning: Error removing " |
9843 | "breakpoint %d\n"), | |
876fa593 | 9844 | old_loc->owner->number); |
20874c92 VP |
9845 | } |
9846 | removed = 1; | |
9847 | } | |
0d381245 | 9848 | } |
74960c60 VP |
9849 | |
9850 | if (!found_object) | |
1c5cfe86 | 9851 | { |
db82e815 PA |
9852 | if (removed && non_stop |
9853 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9854 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9855 | { |
db82e815 PA |
9856 | /* This location was removed from the target. In |
9857 | non-stop mode, a race condition is possible where | |
9858 | we've removed a breakpoint, but stop events for that | |
9859 | breakpoint are already queued and will arrive later. | |
9860 | We apply an heuristic to be able to distinguish such | |
9861 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9862 | breakpoint location for a bit, and will retire it | |
9863 | after we see some number of events. The theory here | |
9864 | is that reporting of events should, "on the average", | |
9865 | be fair, so after a while we'll see events from all | |
9866 | threads that have anything of interest, and no longer | |
9867 | need to keep this breakpoint location around. We | |
9868 | don't hold locations forever so to reduce chances of | |
9869 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9870 | SIGTRAP. | |
9871 | ||
9872 | The heuristic failing can be disastrous on | |
9873 | decr_pc_after_break targets. | |
9874 | ||
9875 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9876 | if we fail to recognize a late breakpoint SIGTRAP, | |
9877 | because events_till_retirement has reached 0 too | |
9878 | soon, we'll fail to do the PC adjustment, and report | |
9879 | a random SIGTRAP to the user. When the user resumes | |
9880 | the inferior, it will most likely immediately crash | |
2dec564e | 9881 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
9882 | corrupted, because of being resumed e.g., in the |
9883 | middle of a multi-byte instruction, or skipped a | |
9884 | one-byte instruction. This was actually seen happen | |
9885 | on native x86-linux, and should be less rare on | |
9886 | targets that do not support new thread events, like | |
9887 | remote, due to the heuristic depending on | |
9888 | thread_count. | |
9889 | ||
9890 | Mistaking a random SIGTRAP for a breakpoint trap | |
9891 | causes similar symptoms (PC adjustment applied when | |
9892 | it shouldn't), but then again, playing with SIGTRAPs | |
9893 | behind the debugger's back is asking for trouble. | |
9894 | ||
9895 | Since hardware watchpoint traps are always | |
9896 | distinguishable from other traps, so we don't need to | |
9897 | apply keep hardware watchpoint moribund locations | |
9898 | around. We simply always ignore hardware watchpoint | |
9899 | traps we can no longer explain. */ | |
9900 | ||
876fa593 JK |
9901 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9902 | old_loc->owner = NULL; | |
20874c92 | 9903 | |
876fa593 | 9904 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9905 | } |
9906 | else | |
f431efe5 PA |
9907 | { |
9908 | old_loc->owner = NULL; | |
9909 | decref_bp_location (&old_loc); | |
9910 | } | |
20874c92 | 9911 | } |
74960c60 | 9912 | } |
1c5cfe86 | 9913 | |
2d134ed3 PA |
9914 | /* Rescan breakpoints at the same address and section, marking the |
9915 | first one as "first" and any others as "duplicates". This is so | |
9916 | that the bpt instruction is only inserted once. If we have a | |
9917 | permanent breakpoint at the same place as BPT, make that one the | |
9918 | official one, and the rest as duplicates. Permanent breakpoints | |
9919 | are sorted first for the same address. | |
9920 | ||
9921 | Do the same for hardware watchpoints, but also considering the | |
9922 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9923 | |
2d134ed3 PA |
9924 | bp_loc_first = NULL; |
9925 | wp_loc_first = NULL; | |
9926 | awp_loc_first = NULL; | |
9927 | rwp_loc_first = NULL; | |
876fa593 | 9928 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9929 | { |
4a64f543 MS |
9930 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
9931 | non-NULL. */ | |
876fa593 | 9932 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9933 | struct bp_location **loc_first_p; |
876fa593 JK |
9934 | |
9935 | if (b->enable_state == bp_disabled | |
9936 | || b->enable_state == bp_call_disabled | |
9937 | || b->enable_state == bp_startup_disabled | |
9938 | || !loc->enabled | |
9939 | || loc->shlib_disabled | |
15c3d785 | 9940 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 9941 | || is_tracepoint (b)) |
876fa593 JK |
9942 | continue; |
9943 | ||
9944 | /* Permanent breakpoint should always be inserted. */ | |
9945 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9946 | internal_error (__FILE__, __LINE__, | |
9947 | _("allegedly permanent breakpoint is not " | |
9948 | "actually inserted")); | |
9949 | ||
2d134ed3 PA |
9950 | if (b->type == bp_hardware_watchpoint) |
9951 | loc_first_p = &wp_loc_first; | |
9952 | else if (b->type == bp_read_watchpoint) | |
9953 | loc_first_p = &rwp_loc_first; | |
9954 | else if (b->type == bp_access_watchpoint) | |
9955 | loc_first_p = &awp_loc_first; | |
9956 | else | |
9957 | loc_first_p = &bp_loc_first; | |
9958 | ||
9959 | if (*loc_first_p == NULL | |
9960 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9961 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9962 | { |
2d134ed3 | 9963 | *loc_first_p = loc; |
876fa593 JK |
9964 | loc->duplicate = 0; |
9965 | continue; | |
9966 | } | |
9967 | ||
9968 | loc->duplicate = 1; | |
9969 | ||
2d134ed3 PA |
9970 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9971 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9972 | internal_error (__FILE__, __LINE__, |
9973 | _("another breakpoint was inserted on top of " | |
9974 | "a permanent breakpoint")); | |
0d381245 | 9975 | } |
74960c60 | 9976 | |
50c71eaf | 9977 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9978 | && (have_live_inferiors () |
2567c7d9 | 9979 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9980 | insert_breakpoint_locations (); |
f7545552 TT |
9981 | |
9982 | do_cleanups (cleanups); | |
74960c60 VP |
9983 | } |
9984 | ||
20874c92 VP |
9985 | void |
9986 | breakpoint_retire_moribund (void) | |
9987 | { | |
9988 | struct bp_location *loc; | |
9989 | int ix; | |
9990 | ||
9991 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9992 | if (--(loc->events_till_retirement) == 0) | |
9993 | { | |
f431efe5 | 9994 | decref_bp_location (&loc); |
20874c92 VP |
9995 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
9996 | --ix; | |
9997 | } | |
9998 | } | |
9999 | ||
74960c60 | 10000 | static void |
b60e7edf | 10001 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
10002 | { |
10003 | struct gdb_exception e; | |
cc59ec59 | 10004 | |
74960c60 | 10005 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 10006 | update_global_location_list (inserting); |
0d381245 VP |
10007 | } |
10008 | ||
f431efe5 PA |
10009 | /* Clear BKP from a BPS. */ |
10010 | ||
a474d7c2 | 10011 | static void |
f431efe5 | 10012 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
10013 | { |
10014 | bpstat bs; | |
cc59ec59 | 10015 | |
a474d7c2 | 10016 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 10017 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
10018 | { |
10019 | bs->breakpoint_at = NULL; | |
10020 | bs->old_val = NULL; | |
10021 | /* bs->commands will be freed later. */ | |
10022 | } | |
10023 | } | |
10024 | ||
10025 | /* Callback for iterate_over_threads. */ | |
10026 | static int | |
f431efe5 | 10027 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 10028 | { |
f431efe5 | 10029 | struct breakpoint *bpt = data; |
cc59ec59 | 10030 | |
16c381f0 | 10031 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
a474d7c2 PA |
10032 | return 0; |
10033 | } | |
10034 | ||
53a5351d | 10035 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 10036 | structures. */ |
c906108c SS |
10037 | |
10038 | void | |
fba45db2 | 10039 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 10040 | { |
52f0bd74 | 10041 | struct breakpoint *b; |
c906108c | 10042 | |
8a3fe4f8 | 10043 | gdb_assert (bpt != NULL); |
c906108c | 10044 | |
4a64f543 MS |
10045 | /* Has this bp already been deleted? This can happen because |
10046 | multiple lists can hold pointers to bp's. bpstat lists are | |
10047 | especial culprits. | |
10048 | ||
10049 | One example of this happening is a watchpoint's scope bp. When | |
10050 | the scope bp triggers, we notice that the watchpoint is out of | |
10051 | scope, and delete it. We also delete its scope bp. But the | |
10052 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
10053 | That bpstat is then checked for auto-deleting bp's, which are | |
10054 | deleted. | |
10055 | ||
10056 | A real solution to this problem might involve reference counts in | |
10057 | bp's, and/or giving them pointers back to their referencing | |
10058 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
10059 | storage when no more references were extent. A cheaper bandaid | |
10060 | was chosen. */ | |
c906108c SS |
10061 | if (bpt->type == bp_none) |
10062 | return; | |
10063 | ||
4a64f543 MS |
10064 | /* At least avoid this stale reference until the reference counting |
10065 | of breakpoints gets resolved. */ | |
e5a0a904 JK |
10066 | if (bpt->related_breakpoint != NULL) |
10067 | { | |
10068 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
10069 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
10070 | bpt->related_breakpoint->related_breakpoint = NULL; | |
10071 | bpt->related_breakpoint = NULL; | |
10072 | } | |
10073 | ||
383f836e | 10074 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 10075 | |
c906108c SS |
10076 | if (breakpoint_chain == bpt) |
10077 | breakpoint_chain = bpt->next; | |
10078 | ||
c906108c SS |
10079 | ALL_BREAKPOINTS (b) |
10080 | if (b->next == bpt) | |
c5aa993b JM |
10081 | { |
10082 | b->next = bpt->next; | |
10083 | break; | |
10084 | } | |
c906108c | 10085 | |
9add0f1b | 10086 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
10087 | xfree (bpt->cond_string); |
10088 | xfree (bpt->cond_exp); | |
10089 | xfree (bpt->addr_string); | |
10090 | xfree (bpt->exp); | |
10091 | xfree (bpt->exp_string); | |
d63d0675 | 10092 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
10093 | value_free (bpt->val); |
10094 | xfree (bpt->source_file); | |
10095 | xfree (bpt->exec_pathname); | |
a96d9b2e | 10096 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 10097 | |
f431efe5 PA |
10098 | |
10099 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
10100 | been freed. */ | |
10101 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
10102 | in all threeds for now. Note that we cannot just remove bpstats | |
10103 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
10104 | commands are associated with the bpstat; if we remove it here, | |
10105 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
10106 | event-top.c won't do anything, and temporary breakpoints with | |
10107 | commands won't work. */ | |
10108 | ||
10109 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
10110 | ||
4a64f543 MS |
10111 | /* Now that breakpoint is removed from breakpoint list, update the |
10112 | global location list. This will remove locations that used to | |
10113 | belong to this breakpoint. Do this before freeing the breakpoint | |
10114 | itself, since remove_breakpoint looks at location's owner. It | |
10115 | might be better design to have location completely | |
10116 | self-contained, but it's not the case now. */ | |
b60e7edf | 10117 | update_global_location_list (0); |
74960c60 VP |
10118 | |
10119 | ||
4a64f543 MS |
10120 | /* On the chance that someone will soon try again to delete this |
10121 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c SS |
10122 | bpt->type = bp_none; |
10123 | ||
b8c9b27d | 10124 | xfree (bpt); |
c906108c SS |
10125 | } |
10126 | ||
4d6140d9 AC |
10127 | static void |
10128 | do_delete_breakpoint_cleanup (void *b) | |
10129 | { | |
10130 | delete_breakpoint (b); | |
10131 | } | |
10132 | ||
10133 | struct cleanup * | |
10134 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
10135 | { | |
10136 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
10137 | } | |
10138 | ||
95a42b64 TT |
10139 | /* A callback for map_breakpoint_numbers that calls |
10140 | delete_breakpoint. */ | |
10141 | ||
10142 | static void | |
10143 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
10144 | { | |
10145 | delete_breakpoint (b); | |
10146 | } | |
10147 | ||
c906108c | 10148 | void |
fba45db2 | 10149 | delete_command (char *arg, int from_tty) |
c906108c | 10150 | { |
35df4500 | 10151 | struct breakpoint *b, *b_tmp; |
c906108c | 10152 | |
ea9365bb TT |
10153 | dont_repeat (); |
10154 | ||
c906108c SS |
10155 | if (arg == 0) |
10156 | { | |
10157 | int breaks_to_delete = 0; | |
10158 | ||
10159 | /* Delete all breakpoints if no argument. | |
4a64f543 MS |
10160 | Do not delete internal or call-dummy breakpoints, these have |
10161 | to be deleted with an explicit breakpoint number argument. */ | |
c5aa993b JM |
10162 | ALL_BREAKPOINTS (b) |
10163 | { | |
059fb39f | 10164 | if (b->type != bp_call_dummy |
aa7d318d | 10165 | && b->type != bp_std_terminate |
059fb39f | 10166 | && b->type != bp_shlib_event |
4efc6507 | 10167 | && b->type != bp_jit_event |
059fb39f PM |
10168 | && b->type != bp_thread_event |
10169 | && b->type != bp_overlay_event | |
0fd8e87f | 10170 | && b->type != bp_longjmp_master |
aa7d318d | 10171 | && b->type != bp_std_terminate_master |
186c406b | 10172 | && b->type != bp_exception_master |
059fb39f | 10173 | && b->number >= 0) |
973d738b DJ |
10174 | { |
10175 | breaks_to_delete = 1; | |
10176 | break; | |
10177 | } | |
c5aa993b | 10178 | } |
c906108c SS |
10179 | |
10180 | /* Ask user only if there are some breakpoints to delete. */ | |
10181 | if (!from_tty | |
e2e0b3e5 | 10182 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 10183 | { |
35df4500 | 10184 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10185 | { |
059fb39f | 10186 | if (b->type != bp_call_dummy |
aa7d318d | 10187 | && b->type != bp_std_terminate |
059fb39f PM |
10188 | && b->type != bp_shlib_event |
10189 | && b->type != bp_thread_event | |
4efc6507 | 10190 | && b->type != bp_jit_event |
059fb39f | 10191 | && b->type != bp_overlay_event |
0fd8e87f | 10192 | && b->type != bp_longjmp_master |
aa7d318d | 10193 | && b->type != bp_std_terminate_master |
186c406b | 10194 | && b->type != bp_exception_master |
059fb39f | 10195 | && b->number >= 0) |
c5aa993b JM |
10196 | delete_breakpoint (b); |
10197 | } | |
c906108c SS |
10198 | } |
10199 | } | |
10200 | else | |
95a42b64 | 10201 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
10202 | } |
10203 | ||
0d381245 VP |
10204 | static int |
10205 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 10206 | { |
0d381245 VP |
10207 | for (; loc; loc = loc->next) |
10208 | if (!loc->shlib_disabled) | |
10209 | return 0; | |
10210 | return 1; | |
fe3f5fa8 VP |
10211 | } |
10212 | ||
776592bf DE |
10213 | /* Subroutine of update_breakpoint_locations to simplify it. |
10214 | Return non-zero if multiple fns in list LOC have the same name. | |
10215 | Null names are ignored. */ | |
10216 | ||
10217 | static int | |
10218 | ambiguous_names_p (struct bp_location *loc) | |
10219 | { | |
10220 | struct bp_location *l; | |
10221 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
10222 | (int (*) (const void *, |
10223 | const void *)) streq, | |
776592bf DE |
10224 | NULL, xcalloc, xfree); |
10225 | ||
10226 | for (l = loc; l != NULL; l = l->next) | |
10227 | { | |
10228 | const char **slot; | |
10229 | const char *name = l->function_name; | |
10230 | ||
10231 | /* Allow for some names to be NULL, ignore them. */ | |
10232 | if (name == NULL) | |
10233 | continue; | |
10234 | ||
10235 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
10236 | INSERT); | |
4a64f543 MS |
10237 | /* NOTE: We can assume slot != NULL here because xcalloc never |
10238 | returns NULL. */ | |
776592bf DE |
10239 | if (*slot != NULL) |
10240 | { | |
10241 | htab_delete (htab); | |
10242 | return 1; | |
10243 | } | |
10244 | *slot = name; | |
10245 | } | |
10246 | ||
10247 | htab_delete (htab); | |
10248 | return 0; | |
10249 | } | |
10250 | ||
0fb4aa4b PA |
10251 | /* When symbols change, it probably means the sources changed as well, |
10252 | and it might mean the static tracepoint markers are no longer at | |
10253 | the same address or line numbers they used to be at last we | |
10254 | checked. Losing your static tracepoints whenever you rebuild is | |
10255 | undesirable. This function tries to resync/rematch gdb static | |
10256 | tracepoints with the markers on the target, for static tracepoints | |
10257 | that have not been set by marker id. Static tracepoint that have | |
10258 | been set by marker id are reset by marker id in breakpoint_re_set. | |
10259 | The heuristic is: | |
10260 | ||
10261 | 1) For a tracepoint set at a specific address, look for a marker at | |
10262 | the old PC. If one is found there, assume to be the same marker. | |
10263 | If the name / string id of the marker found is different from the | |
10264 | previous known name, assume that means the user renamed the marker | |
10265 | in the sources, and output a warning. | |
10266 | ||
10267 | 2) For a tracepoint set at a given line number, look for a marker | |
10268 | at the new address of the old line number. If one is found there, | |
10269 | assume to be the same marker. If the name / string id of the | |
10270 | marker found is different from the previous known name, assume that | |
10271 | means the user renamed the marker in the sources, and output a | |
10272 | warning. | |
10273 | ||
10274 | 3) If a marker is no longer found at the same address or line, it | |
10275 | may mean the marker no longer exists. But it may also just mean | |
10276 | the code changed a bit. Maybe the user added a few lines of code | |
10277 | that made the marker move up or down (in line number terms). Ask | |
10278 | the target for info about the marker with the string id as we knew | |
10279 | it. If found, update line number and address in the matching | |
10280 | static tracepoint. This will get confused if there's more than one | |
10281 | marker with the same ID (possible in UST, although unadvised | |
10282 | precisely because it confuses tools). */ | |
10283 | ||
10284 | static struct symtab_and_line | |
10285 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
10286 | { | |
10287 | struct static_tracepoint_marker marker; | |
10288 | CORE_ADDR pc; | |
10289 | int i; | |
10290 | ||
10291 | pc = sal.pc; | |
10292 | if (sal.line) | |
10293 | find_line_pc (sal.symtab, sal.line, &pc); | |
10294 | ||
10295 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
10296 | { | |
10297 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
10298 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
10299 | b->number, | |
10300 | b->static_trace_marker_id, marker.str_id); | |
10301 | ||
10302 | xfree (b->static_trace_marker_id); | |
10303 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
10304 | release_static_tracepoint_marker (&marker); | |
10305 | ||
10306 | return sal; | |
10307 | } | |
10308 | ||
10309 | /* Old marker wasn't found on target at lineno. Try looking it up | |
10310 | by string ID. */ | |
10311 | if (!sal.explicit_pc | |
10312 | && sal.line != 0 | |
10313 | && sal.symtab != NULL | |
10314 | && b->static_trace_marker_id != NULL) | |
10315 | { | |
10316 | VEC(static_tracepoint_marker_p) *markers; | |
10317 | ||
10318 | markers | |
10319 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
10320 | ||
10321 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
10322 | { | |
10323 | struct symtab_and_line sal; | |
10324 | struct symbol *sym; | |
10325 | struct static_tracepoint_marker *marker; | |
10326 | ||
10327 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
10328 | ||
10329 | xfree (b->static_trace_marker_id); | |
10330 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
10331 | ||
10332 | warning (_("marker for static tracepoint %d (%s) not " | |
10333 | "found at previous line number"), | |
10334 | b->number, b->static_trace_marker_id); | |
10335 | ||
10336 | init_sal (&sal); | |
10337 | ||
10338 | sal.pc = marker->address; | |
10339 | ||
10340 | sal = find_pc_line (marker->address, 0); | |
10341 | sym = find_pc_sect_function (marker->address, NULL); | |
10342 | ui_out_text (uiout, "Now in "); | |
10343 | if (sym) | |
10344 | { | |
10345 | ui_out_field_string (uiout, "func", | |
10346 | SYMBOL_PRINT_NAME (sym)); | |
10347 | ui_out_text (uiout, " at "); | |
10348 | } | |
10349 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
10350 | ui_out_text (uiout, ":"); | |
10351 | ||
10352 | if (ui_out_is_mi_like_p (uiout)) | |
10353 | { | |
10354 | char *fullname = symtab_to_fullname (sal.symtab); | |
10355 | ||
10356 | if (fullname) | |
10357 | ui_out_field_string (uiout, "fullname", fullname); | |
10358 | } | |
10359 | ||
10360 | ui_out_field_int (uiout, "line", sal.line); | |
10361 | ui_out_text (uiout, "\n"); | |
10362 | ||
10363 | b->line_number = sal.line; | |
10364 | ||
10365 | xfree (b->source_file); | |
10366 | if (sym) | |
10367 | b->source_file = xstrdup (sal.symtab->filename); | |
10368 | else | |
10369 | b->source_file = NULL; | |
10370 | ||
10371 | xfree (b->addr_string); | |
10372 | b->addr_string = xstrprintf ("%s:%d", | |
10373 | sal.symtab->filename, b->line_number); | |
10374 | ||
10375 | /* Might be nice to check if function changed, and warn if | |
10376 | so. */ | |
10377 | ||
10378 | release_static_tracepoint_marker (marker); | |
10379 | } | |
10380 | } | |
10381 | return sal; | |
10382 | } | |
10383 | ||
fe3f5fa8 | 10384 | static void |
0d381245 VP |
10385 | update_breakpoint_locations (struct breakpoint *b, |
10386 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
10387 | { |
10388 | int i; | |
10389 | char *s; | |
0d381245 VP |
10390 | struct bp_location *existing_locations = b->loc; |
10391 | ||
4a64f543 MS |
10392 | /* If there's no new locations, and all existing locations are |
10393 | pending, don't do anything. This optimizes the common case where | |
10394 | all locations are in the same shared library, that was unloaded. | |
10395 | We'd like to retain the location, so that when the library is | |
10396 | loaded again, we don't loose the enabled/disabled status of the | |
10397 | individual locations. */ | |
0d381245 | 10398 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
10399 | return; |
10400 | ||
fe3f5fa8 VP |
10401 | b->loc = NULL; |
10402 | ||
0d381245 | 10403 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 10404 | { |
0d381245 | 10405 | struct bp_location *new_loc = |
39d61571 | 10406 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 10407 | |
0d381245 VP |
10408 | /* Reparse conditions, they might contain references to the |
10409 | old symtab. */ | |
10410 | if (b->cond_string != NULL) | |
10411 | { | |
10412 | struct gdb_exception e; | |
fe3f5fa8 | 10413 | |
0d381245 VP |
10414 | s = b->cond_string; |
10415 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10416 | { | |
10417 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
10418 | 0); | |
10419 | } | |
10420 | if (e.reason < 0) | |
10421 | { | |
3e43a32a MS |
10422 | warning (_("failed to reevaluate condition " |
10423 | "for breakpoint %d: %s"), | |
0d381245 VP |
10424 | b->number, e.message); |
10425 | new_loc->enabled = 0; | |
10426 | } | |
10427 | } | |
fe3f5fa8 | 10428 | |
0d381245 VP |
10429 | if (b->source_file != NULL) |
10430 | xfree (b->source_file); | |
10431 | if (sals.sals[i].symtab == NULL) | |
10432 | b->source_file = NULL; | |
10433 | else | |
1b36a34b | 10434 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 10435 | |
0d381245 VP |
10436 | if (b->line_number == 0) |
10437 | b->line_number = sals.sals[i].line; | |
10438 | } | |
fe3f5fa8 | 10439 | |
514f746b AR |
10440 | /* Update locations of permanent breakpoints. */ |
10441 | if (b->enable_state == bp_permanent) | |
10442 | make_breakpoint_permanent (b); | |
10443 | ||
4a64f543 MS |
10444 | /* If possible, carry over 'disable' status from existing |
10445 | breakpoints. */ | |
0d381245 VP |
10446 | { |
10447 | struct bp_location *e = existing_locations; | |
776592bf DE |
10448 | /* If there are multiple breakpoints with the same function name, |
10449 | e.g. for inline functions, comparing function names won't work. | |
10450 | Instead compare pc addresses; this is just a heuristic as things | |
10451 | may have moved, but in practice it gives the correct answer | |
10452 | often enough until a better solution is found. */ | |
10453 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
10454 | ||
0d381245 VP |
10455 | for (; e; e = e->next) |
10456 | { | |
10457 | if (!e->enabled && e->function_name) | |
10458 | { | |
10459 | struct bp_location *l = b->loc; | |
776592bf DE |
10460 | if (have_ambiguous_names) |
10461 | { | |
10462 | for (; l; l = l->next) | |
6c95b8df PA |
10463 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
10464 | l->pspace->aspace, l->address)) | |
776592bf DE |
10465 | { |
10466 | l->enabled = 0; | |
10467 | break; | |
10468 | } | |
10469 | } | |
10470 | else | |
10471 | { | |
10472 | for (; l; l = l->next) | |
10473 | if (l->function_name | |
10474 | && strcmp (e->function_name, l->function_name) == 0) | |
10475 | { | |
10476 | l->enabled = 0; | |
10477 | break; | |
10478 | } | |
10479 | } | |
0d381245 VP |
10480 | } |
10481 | } | |
10482 | } | |
fe3f5fa8 | 10483 | |
b60e7edf | 10484 | update_global_location_list (1); |
fe3f5fa8 VP |
10485 | } |
10486 | ||
c906108c SS |
10487 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
10488 | The value we return ends up being the return value from catch_errors. | |
10489 | Unused in this case. */ | |
10490 | ||
10491 | static int | |
4efb68b1 | 10492 | breakpoint_re_set_one (void *bint) |
c906108c | 10493 | { |
4a64f543 | 10494 | /* Get past catch_errs. */ |
53a5351d | 10495 | struct breakpoint *b = (struct breakpoint *) bint; |
fe3f5fa8 VP |
10496 | int not_found = 0; |
10497 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
10498 | struct symtabs_and_lines sals = {0}; |
10499 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 10500 | char *s; |
fe3f5fa8 | 10501 | struct gdb_exception e; |
6c95b8df | 10502 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
0fb4aa4b | 10503 | int marker_spec = 0; |
c906108c SS |
10504 | |
10505 | switch (b->type) | |
10506 | { | |
10507 | case bp_none: | |
8a3fe4f8 | 10508 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 10509 | b->number); |
c906108c SS |
10510 | return 0; |
10511 | case bp_breakpoint: | |
10512 | case bp_hardware_breakpoint: | |
1042e4c0 | 10513 | case bp_tracepoint: |
7a697b8d | 10514 | case bp_fast_tracepoint: |
0fb4aa4b | 10515 | case bp_static_tracepoint: |
8bea4e01 UW |
10516 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10517 | if (b->enable_state == bp_startup_disabled) | |
10518 | return 0; | |
10519 | ||
c906108c SS |
10520 | if (b->addr_string == NULL) |
10521 | { | |
4a64f543 | 10522 | /* Anything without a string can't be re-set. */ |
c906108c SS |
10523 | delete_breakpoint (b); |
10524 | return 0; | |
10525 | } | |
c906108c | 10526 | |
c906108c SS |
10527 | input_radix = b->input_radix; |
10528 | s = b->addr_string; | |
6c95b8df PA |
10529 | |
10530 | save_current_space_and_thread (); | |
10531 | switch_to_program_space_and_thread (b->pspace); | |
10532 | ||
0fb4aa4b PA |
10533 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); |
10534 | ||
385d04dc | 10535 | set_language (b->language); |
fe3f5fa8 | 10536 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 10537 | { |
0fb4aa4b PA |
10538 | if (marker_spec) |
10539 | { | |
10540 | sals = decode_static_tracepoint_spec (&s); | |
10541 | if (sals.nelts > b->static_trace_marker_id_idx) | |
10542 | { | |
10543 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
10544 | sals.nelts = 1; | |
10545 | } | |
10546 | else | |
10547 | error (_("marker %s not found"), b->static_trace_marker_id); | |
10548 | } | |
10549 | else | |
3e43a32a | 10550 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, |
7efd8fc2 | 10551 | NULL, not_found_ptr); |
fe3f5fa8 VP |
10552 | } |
10553 | if (e.reason < 0) | |
10554 | { | |
10555 | int not_found_and_ok = 0; | |
4a64f543 MS |
10556 | /* For pending breakpoints, it's expected that parsing will |
10557 | fail until the right shared library is loaded. User has | |
10558 | already told to create pending breakpoints and don't need | |
10559 | extra messages. If breakpoint is in bp_shlib_disabled | |
10560 | state, then user already saw the message about that | |
10561 | breakpoint being disabled, and don't want to see more | |
10562 | errors. */ | |
0d381245 VP |
10563 | if (not_found |
10564 | && (b->condition_not_parsed | |
10565 | || (b->loc && b->loc->shlib_disabled) | |
10566 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
10567 | not_found_and_ok = 1; |
10568 | ||
10569 | if (!not_found_and_ok) | |
c906108c | 10570 | { |
fe3f5fa8 VP |
10571 | /* We surely don't want to warn about the same breakpoint |
10572 | 10 times. One solution, implemented here, is disable | |
10573 | the breakpoint on error. Another solution would be to | |
10574 | have separate 'warning emitted' flag. Since this | |
10575 | happens only when a binary has changed, I don't know | |
10576 | which approach is better. */ | |
10577 | b->enable_state = bp_disabled; | |
10578 | throw_exception (e); | |
c906108c | 10579 | } |
fe3f5fa8 | 10580 | } |
c906108c | 10581 | |
6c95b8df | 10582 | if (!not_found) |
fe3f5fa8 | 10583 | { |
6c95b8df PA |
10584 | gdb_assert (sals.nelts == 1); |
10585 | ||
10586 | resolve_sal_pc (&sals.sals[0]); | |
10587 | if (b->condition_not_parsed && s && s[0]) | |
10588 | { | |
10589 | char *cond_string = 0; | |
10590 | int thread = -1; | |
10591 | int task = 0; | |
10592 | ||
10593 | find_condition_and_thread (s, sals.sals[0].pc, | |
10594 | &cond_string, &thread, &task); | |
10595 | if (cond_string) | |
10596 | b->cond_string = cond_string; | |
10597 | b->thread = thread; | |
10598 | b->task = task; | |
10599 | b->condition_not_parsed = 0; | |
10600 | } | |
10601 | ||
0fb4aa4b PA |
10602 | if (b->type == bp_static_tracepoint && !marker_spec) |
10603 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
10604 | ||
6c95b8df | 10605 | expanded = expand_line_sal_maybe (sals.sals[0]); |
fe3f5fa8 | 10606 | } |
6c95b8df PA |
10607 | |
10608 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 10609 | update_breakpoint_locations (b, expanded); |
c906108c SS |
10610 | break; |
10611 | ||
10612 | case bp_watchpoint: | |
10613 | case bp_hardware_watchpoint: | |
10614 | case bp_read_watchpoint: | |
10615 | case bp_access_watchpoint: | |
4a64f543 MS |
10616 | /* Watchpoint can be either on expression using entirely global |
10617 | variables, or it can be on local variables. | |
10618 | ||
10619 | Watchpoints of the first kind are never auto-deleted, and | |
10620 | even persist across program restarts. Since they can use | |
10621 | variables from shared libraries, we need to reparse | |
10622 | expression as libraries are loaded and unloaded. | |
10623 | ||
10624 | Watchpoints on local variables can also change meaning as | |
10625 | result of solib event. For example, if a watchpoint uses | |
10626 | both a local and a global variables in expression, it's a | |
10627 | local watchpoint, but unloading of a shared library will make | |
10628 | the expression invalid. This is not a very common use case, | |
10629 | but we still re-evaluate expression, to avoid surprises to | |
10630 | the user. | |
0b3de036 VP |
10631 | |
10632 | Note that for local watchpoints, we re-evaluate it only if | |
10633 | watchpoints frame id is still valid. If it's not, it means | |
4a64f543 MS |
10634 | the watchpoint is out of scope and will be deleted soon. In |
10635 | fact, I'm not sure we'll ever be called in this case. | |
0b3de036 VP |
10636 | |
10637 | If a local watchpoint's frame id is still valid, then | |
4a64f543 | 10638 | b->exp_valid_block is likewise valid, and we can safely use it. |
0b3de036 VP |
10639 | |
10640 | Don't do anything about disabled watchpoints, since they will | |
10641 | be reevaluated again when enabled. */ | |
a5606eee | 10642 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 10643 | break; |
c5aa993b JM |
10644 | /* We needn't really do anything to reset these, since the mask |
10645 | that requests them is unaffected by e.g., new libraries being | |
4a64f543 | 10646 | loaded. */ |
ce78b96d | 10647 | case bp_catchpoint: |
c906108c | 10648 | break; |
c5aa993b | 10649 | |
c906108c | 10650 | default: |
a3f17187 | 10651 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 10652 | /* fall through */ |
0fd8e87f UW |
10653 | /* Delete overlay event and longjmp master breakpoints; they will be |
10654 | reset later by breakpoint_re_set. */ | |
1900040c | 10655 | case bp_overlay_event: |
0fd8e87f | 10656 | case bp_longjmp_master: |
aa7d318d | 10657 | case bp_std_terminate_master: |
186c406b | 10658 | case bp_exception_master: |
c906108c SS |
10659 | delete_breakpoint (b); |
10660 | break; | |
10661 | ||
c5aa993b JM |
10662 | /* This breakpoint is special, it's set up when the inferior |
10663 | starts and we really don't want to touch it. */ | |
c906108c SS |
10664 | case bp_shlib_event: |
10665 | ||
c4093a6a JM |
10666 | /* Like bp_shlib_event, this breakpoint type is special. |
10667 | Once it is set up, we do not want to touch it. */ | |
10668 | case bp_thread_event: | |
10669 | ||
4a64f543 MS |
10670 | /* Keep temporary breakpoints, which can be encountered when we |
10671 | step over a dlopen call and SOLIB_ADD is resetting the | |
10672 | breakpoints. Otherwise these should have been blown away via | |
10673 | the cleanup chain or by breakpoint_init_inferior when we | |
10674 | rerun the executable. */ | |
c906108c SS |
10675 | case bp_until: |
10676 | case bp_finish: | |
10677 | case bp_watchpoint_scope: | |
10678 | case bp_call_dummy: | |
aa7d318d | 10679 | case bp_std_terminate: |
c906108c | 10680 | case bp_step_resume: |
611c83ae PA |
10681 | case bp_longjmp: |
10682 | case bp_longjmp_resume: | |
186c406b TT |
10683 | case bp_exception: |
10684 | case bp_exception_resume: | |
4efc6507 | 10685 | case bp_jit_event: |
c906108c SS |
10686 | break; |
10687 | } | |
10688 | ||
6c95b8df | 10689 | do_cleanups (cleanups); |
c906108c SS |
10690 | return 0; |
10691 | } | |
10692 | ||
69de3c6a | 10693 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 10694 | void |
69de3c6a | 10695 | breakpoint_re_set (void) |
c906108c | 10696 | { |
35df4500 | 10697 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10698 | enum language save_language; |
10699 | int save_input_radix; | |
6c95b8df | 10700 | struct cleanup *old_chain; |
c5aa993b | 10701 | |
c906108c SS |
10702 | save_language = current_language->la_language; |
10703 | save_input_radix = input_radix; | |
6c95b8df PA |
10704 | old_chain = save_current_program_space (); |
10705 | ||
35df4500 | 10706 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10707 | { |
4a64f543 | 10708 | /* Format possible error msg. */ |
fe3f5fa8 | 10709 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
10710 | b->number); |
10711 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 10712 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 10713 | do_cleanups (cleanups); |
c5aa993b | 10714 | } |
c906108c SS |
10715 | set_language (save_language); |
10716 | input_radix = save_input_radix; | |
e62c965a | 10717 | |
0756c555 | 10718 | jit_breakpoint_re_set (); |
4efc6507 | 10719 | |
6c95b8df PA |
10720 | do_cleanups (old_chain); |
10721 | ||
af02033e PP |
10722 | create_overlay_event_breakpoint (); |
10723 | create_longjmp_master_breakpoint (); | |
10724 | create_std_terminate_master_breakpoint (); | |
186c406b | 10725 | create_exception_master_breakpoint (); |
c906108c SS |
10726 | } |
10727 | \f | |
c906108c SS |
10728 | /* Reset the thread number of this breakpoint: |
10729 | ||
10730 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 10731 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 10732 | void |
fba45db2 | 10733 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
10734 | { |
10735 | if (b->thread != -1) | |
10736 | { | |
39f77062 KB |
10737 | if (in_thread_list (inferior_ptid)) |
10738 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
10739 | |
10740 | /* We're being called after following a fork. The new fork is | |
10741 | selected as current, and unless this was a vfork will have a | |
10742 | different program space from the original thread. Reset that | |
10743 | as well. */ | |
10744 | b->loc->pspace = current_program_space; | |
c906108c SS |
10745 | } |
10746 | } | |
10747 | ||
03ac34d5 MS |
10748 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10749 | If from_tty is nonzero, it prints a message to that effect, | |
10750 | which ends with a period (no newline). */ | |
10751 | ||
c906108c | 10752 | void |
fba45db2 | 10753 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 10754 | { |
52f0bd74 | 10755 | struct breakpoint *b; |
c906108c SS |
10756 | |
10757 | if (count < 0) | |
10758 | count = 0; | |
10759 | ||
10760 | ALL_BREAKPOINTS (b) | |
10761 | if (b->number == bptnum) | |
c5aa993b | 10762 | { |
d77f58be SS |
10763 | if (is_tracepoint (b)) |
10764 | { | |
10765 | if (from_tty && count != 0) | |
10766 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
10767 | bptnum); | |
10768 | return; | |
10769 | } | |
10770 | ||
c5aa993b | 10771 | b->ignore_count = count; |
221ea385 KS |
10772 | if (from_tty) |
10773 | { | |
10774 | if (count == 0) | |
3e43a32a MS |
10775 | printf_filtered (_("Will stop next time " |
10776 | "breakpoint %d is reached."), | |
221ea385 KS |
10777 | bptnum); |
10778 | else if (count == 1) | |
a3f17187 | 10779 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
10780 | bptnum); |
10781 | else | |
3e43a32a MS |
10782 | printf_filtered (_("Will ignore next %d " |
10783 | "crossings of breakpoint %d."), | |
221ea385 KS |
10784 | count, bptnum); |
10785 | } | |
c5aa993b | 10786 | breakpoints_changed (); |
383f836e | 10787 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
10788 | return; |
10789 | } | |
c906108c | 10790 | |
8a3fe4f8 | 10791 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
10792 | } |
10793 | ||
c906108c SS |
10794 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
10795 | ||
10796 | static void | |
fba45db2 | 10797 | ignore_command (char *args, int from_tty) |
c906108c SS |
10798 | { |
10799 | char *p = args; | |
52f0bd74 | 10800 | int num; |
c906108c SS |
10801 | |
10802 | if (p == 0) | |
e2e0b3e5 | 10803 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 10804 | |
c906108c | 10805 | num = get_number (&p); |
5c44784c | 10806 | if (num == 0) |
8a3fe4f8 | 10807 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 10808 | if (*p == 0) |
8a3fe4f8 | 10809 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
10810 | |
10811 | set_ignore_count (num, | |
10812 | longest_to_int (value_as_long (parse_and_eval (p))), | |
10813 | from_tty); | |
221ea385 KS |
10814 | if (from_tty) |
10815 | printf_filtered ("\n"); | |
c906108c SS |
10816 | } |
10817 | \f | |
10818 | /* Call FUNCTION on each of the breakpoints | |
10819 | whose numbers are given in ARGS. */ | |
10820 | ||
10821 | static void | |
95a42b64 TT |
10822 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
10823 | void *), | |
10824 | void *data) | |
c906108c | 10825 | { |
52f0bd74 AC |
10826 | int num; |
10827 | struct breakpoint *b, *tmp; | |
11cf8741 | 10828 | int match; |
197f0a60 | 10829 | struct get_number_or_range_state state; |
c906108c | 10830 | |
197f0a60 | 10831 | if (args == 0) |
e2e0b3e5 | 10832 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 10833 | |
197f0a60 TT |
10834 | init_number_or_range (&state, args); |
10835 | ||
10836 | while (!state.finished) | |
c906108c | 10837 | { |
197f0a60 TT |
10838 | char *p = state.string; |
10839 | ||
11cf8741 | 10840 | match = 0; |
c5aa993b | 10841 | |
197f0a60 | 10842 | num = get_number_or_range (&state); |
5c44784c | 10843 | if (num == 0) |
c5aa993b | 10844 | { |
8a3fe4f8 | 10845 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
10846 | } |
10847 | else | |
10848 | { | |
10849 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
10850 | if (b->number == num) | |
10851 | { | |
10852 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 10853 | match = 1; |
95a42b64 | 10854 | function (b, data); |
5c44784c | 10855 | if (related_breakpoint) |
95a42b64 | 10856 | function (related_breakpoint, data); |
11cf8741 | 10857 | break; |
5c44784c | 10858 | } |
11cf8741 | 10859 | if (match == 0) |
a3f17187 | 10860 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 10861 | } |
c906108c SS |
10862 | } |
10863 | } | |
10864 | ||
0d381245 VP |
10865 | static struct bp_location * |
10866 | find_location_by_number (char *number) | |
10867 | { | |
10868 | char *dot = strchr (number, '.'); | |
10869 | char *p1; | |
10870 | int bp_num; | |
10871 | int loc_num; | |
10872 | struct breakpoint *b; | |
10873 | struct bp_location *loc; | |
10874 | ||
10875 | *dot = '\0'; | |
10876 | ||
10877 | p1 = number; | |
197f0a60 | 10878 | bp_num = get_number (&p1); |
0d381245 VP |
10879 | if (bp_num == 0) |
10880 | error (_("Bad breakpoint number '%s'"), number); | |
10881 | ||
10882 | ALL_BREAKPOINTS (b) | |
10883 | if (b->number == bp_num) | |
10884 | { | |
10885 | break; | |
10886 | } | |
10887 | ||
10888 | if (!b || b->number != bp_num) | |
10889 | error (_("Bad breakpoint number '%s'"), number); | |
10890 | ||
10891 | p1 = dot+1; | |
197f0a60 | 10892 | loc_num = get_number (&p1); |
0d381245 VP |
10893 | if (loc_num == 0) |
10894 | error (_("Bad breakpoint location number '%s'"), number); | |
10895 | ||
10896 | --loc_num; | |
10897 | loc = b->loc; | |
10898 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
10899 | ; | |
10900 | if (!loc) | |
10901 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
10902 | ||
10903 | return loc; | |
10904 | } | |
10905 | ||
10906 | ||
1900040c MS |
10907 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10908 | If from_tty is nonzero, it prints a message to that effect, | |
10909 | which ends with a period (no newline). */ | |
10910 | ||
c906108c | 10911 | void |
fba45db2 | 10912 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10913 | { |
10914 | /* Never disable a watchpoint scope breakpoint; we want to | |
10915 | hit them when we leave scope so we can delete both the | |
10916 | watchpoint and its scope breakpoint at that time. */ | |
10917 | if (bpt->type == bp_watchpoint_scope) | |
10918 | return; | |
10919 | ||
c2c6d25f | 10920 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 10921 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
10922 | return; |
10923 | ||
b5de0fa7 | 10924 | bpt->enable_state = bp_disabled; |
c906108c | 10925 | |
b60e7edf | 10926 | update_global_location_list (0); |
c906108c | 10927 | |
383f836e | 10928 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10929 | } |
10930 | ||
95a42b64 TT |
10931 | /* A callback for map_breakpoint_numbers that calls |
10932 | disable_breakpoint. */ | |
10933 | ||
10934 | static void | |
10935 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
10936 | { | |
10937 | disable_breakpoint (b); | |
10938 | } | |
10939 | ||
c906108c | 10940 | static void |
fba45db2 | 10941 | disable_command (char *args, int from_tty) |
c906108c | 10942 | { |
52f0bd74 | 10943 | struct breakpoint *bpt; |
cc59ec59 | 10944 | |
c906108c SS |
10945 | if (args == 0) |
10946 | ALL_BREAKPOINTS (bpt) | |
10947 | switch (bpt->type) | |
c5aa993b JM |
10948 | { |
10949 | case bp_none: | |
8a3fe4f8 | 10950 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 10951 | bpt->number); |
488919c4 | 10952 | break; |
c5aa993b | 10953 | case bp_breakpoint: |
1042e4c0 | 10954 | case bp_tracepoint: |
7a697b8d | 10955 | case bp_fast_tracepoint: |
0fb4aa4b | 10956 | case bp_static_tracepoint: |
ce78b96d | 10957 | case bp_catchpoint: |
c5aa993b JM |
10958 | case bp_hardware_breakpoint: |
10959 | case bp_watchpoint: | |
10960 | case bp_hardware_watchpoint: | |
10961 | case bp_read_watchpoint: | |
10962 | case bp_access_watchpoint: | |
10963 | disable_breakpoint (bpt); | |
488919c4 | 10964 | break; |
c5aa993b | 10965 | default: |
488919c4 | 10966 | break; |
c5aa993b | 10967 | } |
0d381245 VP |
10968 | else if (strchr (args, '.')) |
10969 | { | |
10970 | struct bp_location *loc = find_location_by_number (args); | |
10971 | if (loc) | |
10972 | loc->enabled = 0; | |
b60e7edf | 10973 | update_global_location_list (0); |
0d381245 | 10974 | } |
c906108c | 10975 | else |
95a42b64 | 10976 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
10977 | } |
10978 | ||
10979 | static void | |
fba45db2 | 10980 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 10981 | { |
afe38095 | 10982 | int target_resources_ok; |
c906108c SS |
10983 | |
10984 | if (bpt->type == bp_hardware_breakpoint) | |
10985 | { | |
10986 | int i; | |
c5aa993b | 10987 | i = hw_breakpoint_used_count (); |
53a5351d | 10988 | target_resources_ok = |
d92524f1 | 10989 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 10990 | i + 1, 0); |
c906108c | 10991 | if (target_resources_ok == 0) |
8a3fe4f8 | 10992 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 10993 | else if (target_resources_ok < 0) |
8a3fe4f8 | 10994 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
10995 | } |
10996 | ||
cc60f2e3 | 10997 | if (is_watchpoint (bpt)) |
c906108c | 10998 | { |
dde02812 ES |
10999 | struct gdb_exception e; |
11000 | ||
11001 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 11002 | { |
dde02812 | 11003 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 11004 | } |
dde02812 | 11005 | if (e.reason < 0) |
c5aa993b | 11006 | { |
dde02812 ES |
11007 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
11008 | bpt->number); | |
11009 | return; | |
c5aa993b | 11010 | } |
c906108c | 11011 | } |
0101ce28 | 11012 | |
b4c291bb KH |
11013 | if (bpt->enable_state != bp_permanent) |
11014 | bpt->enable_state = bp_enabled; | |
11015 | bpt->disposition = disposition; | |
b60e7edf | 11016 | update_global_location_list (1); |
b4c291bb KH |
11017 | breakpoints_changed (); |
11018 | ||
383f836e | 11019 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
11020 | } |
11021 | ||
fe3f5fa8 | 11022 | |
c906108c | 11023 | void |
fba45db2 | 11024 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
11025 | { |
11026 | do_enable_breakpoint (bpt, bpt->disposition); | |
11027 | } | |
11028 | ||
95a42b64 TT |
11029 | /* A callback for map_breakpoint_numbers that calls |
11030 | enable_breakpoint. */ | |
11031 | ||
11032 | static void | |
11033 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
11034 | { | |
11035 | enable_breakpoint (b); | |
11036 | } | |
11037 | ||
c906108c SS |
11038 | /* The enable command enables the specified breakpoints (or all defined |
11039 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 11040 | in stopping the inferior. */ |
c906108c | 11041 | |
c906108c | 11042 | static void |
fba45db2 | 11043 | enable_command (char *args, int from_tty) |
c906108c | 11044 | { |
52f0bd74 | 11045 | struct breakpoint *bpt; |
cc59ec59 | 11046 | |
c906108c SS |
11047 | if (args == 0) |
11048 | ALL_BREAKPOINTS (bpt) | |
11049 | switch (bpt->type) | |
c5aa993b JM |
11050 | { |
11051 | case bp_none: | |
8a3fe4f8 | 11052 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 11053 | bpt->number); |
488919c4 | 11054 | break; |
c5aa993b | 11055 | case bp_breakpoint: |
1042e4c0 | 11056 | case bp_tracepoint: |
7a697b8d | 11057 | case bp_fast_tracepoint: |
0fb4aa4b | 11058 | case bp_static_tracepoint: |
ce78b96d | 11059 | case bp_catchpoint: |
c5aa993b JM |
11060 | case bp_hardware_breakpoint: |
11061 | case bp_watchpoint: | |
11062 | case bp_hardware_watchpoint: | |
11063 | case bp_read_watchpoint: | |
11064 | case bp_access_watchpoint: | |
11065 | enable_breakpoint (bpt); | |
488919c4 | 11066 | break; |
c5aa993b | 11067 | default: |
488919c4 | 11068 | break; |
c5aa993b | 11069 | } |
0d381245 VP |
11070 | else if (strchr (args, '.')) |
11071 | { | |
11072 | struct bp_location *loc = find_location_by_number (args); | |
11073 | if (loc) | |
11074 | loc->enabled = 1; | |
b60e7edf | 11075 | update_global_location_list (1); |
0d381245 | 11076 | } |
c906108c | 11077 | else |
95a42b64 | 11078 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
11079 | } |
11080 | ||
11081 | static void | |
95a42b64 | 11082 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11083 | { |
b5de0fa7 | 11084 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
11085 | } |
11086 | ||
c906108c | 11087 | static void |
fba45db2 | 11088 | enable_once_command (char *args, int from_tty) |
c906108c | 11089 | { |
95a42b64 | 11090 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
11091 | } |
11092 | ||
11093 | static void | |
95a42b64 | 11094 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11095 | { |
b5de0fa7 | 11096 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
11097 | } |
11098 | ||
c906108c | 11099 | static void |
fba45db2 | 11100 | enable_delete_command (char *args, int from_tty) |
c906108c | 11101 | { |
95a42b64 | 11102 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
11103 | } |
11104 | \f | |
fa8d40ab JJ |
11105 | static void |
11106 | set_breakpoint_cmd (char *args, int from_tty) | |
11107 | { | |
11108 | } | |
11109 | ||
11110 | static void | |
11111 | show_breakpoint_cmd (char *args, int from_tty) | |
11112 | { | |
11113 | } | |
11114 | ||
1f3b5d1b PP |
11115 | /* Invalidate last known value of any hardware watchpoint if |
11116 | the memory which that value represents has been written to by | |
11117 | GDB itself. */ | |
11118 | ||
11119 | static void | |
11120 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
11121 | const bfd_byte *data) | |
11122 | { | |
11123 | struct breakpoint *bp; | |
11124 | ||
11125 | ALL_BREAKPOINTS (bp) | |
11126 | if (bp->enable_state == bp_enabled | |
11127 | && bp->type == bp_hardware_watchpoint | |
11128 | && bp->val_valid && bp->val) | |
11129 | { | |
11130 | struct bp_location *loc; | |
11131 | ||
11132 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
11133 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
11134 | && loc->address + loc->length > addr | |
11135 | && addr + len > loc->address) | |
11136 | { | |
11137 | value_free (bp->val); | |
11138 | bp->val = NULL; | |
11139 | bp->val_valid = 0; | |
11140 | } | |
11141 | } | |
11142 | } | |
11143 | ||
c906108c SS |
11144 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
11145 | ||
11146 | struct symtabs_and_lines | |
fba45db2 | 11147 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
11148 | { |
11149 | struct symtabs_and_lines sals; | |
cc59ec59 | 11150 | |
c906108c | 11151 | if (string == 0) |
8a3fe4f8 | 11152 | error (_("Empty line specification.")); |
c906108c SS |
11153 | if (default_breakpoint_valid) |
11154 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
11155 | default_breakpoint_symtab, |
11156 | default_breakpoint_line, | |
7efd8fc2 | 11157 | NULL, NULL); |
c906108c SS |
11158 | else |
11159 | sals = decode_line_1 (&string, funfirstline, | |
7efd8fc2 | 11160 | (struct symtab *) NULL, 0, NULL, NULL); |
c906108c | 11161 | if (*string) |
8a3fe4f8 | 11162 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
11163 | return sals; |
11164 | } | |
8181d85f DJ |
11165 | |
11166 | /* Create and insert a raw software breakpoint at PC. Return an | |
11167 | identifier, which should be used to remove the breakpoint later. | |
11168 | In general, places which call this should be using something on the | |
11169 | breakpoint chain instead; this function should be eliminated | |
11170 | someday. */ | |
11171 | ||
11172 | void * | |
6c95b8df PA |
11173 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
11174 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
11175 | { |
11176 | struct bp_target_info *bp_tgt; | |
11177 | ||
6c95b8df | 11178 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 11179 | |
6c95b8df | 11180 | bp_tgt->placed_address_space = aspace; |
8181d85f | 11181 | bp_tgt->placed_address = pc; |
6c95b8df | 11182 | |
a6d9a66e | 11183 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
11184 | { |
11185 | /* Could not insert the breakpoint. */ | |
11186 | xfree (bp_tgt); | |
11187 | return NULL; | |
11188 | } | |
11189 | ||
11190 | return bp_tgt; | |
11191 | } | |
11192 | ||
4a64f543 MS |
11193 | /* Remove a breakpoint BP inserted by |
11194 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
11195 | |
11196 | int | |
a6d9a66e | 11197 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
11198 | { |
11199 | struct bp_target_info *bp_tgt = bp; | |
11200 | int ret; | |
11201 | ||
a6d9a66e | 11202 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
11203 | xfree (bp_tgt); |
11204 | ||
11205 | return ret; | |
11206 | } | |
11207 | ||
4a64f543 MS |
11208 | /* One (or perhaps two) breakpoints used for software single |
11209 | stepping. */ | |
8181d85f DJ |
11210 | |
11211 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 11212 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
11213 | |
11214 | /* Create and insert a breakpoint for software single step. */ | |
11215 | ||
11216 | void | |
6c95b8df | 11217 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
11218 | struct address_space *aspace, |
11219 | CORE_ADDR next_pc) | |
8181d85f DJ |
11220 | { |
11221 | void **bpt_p; | |
11222 | ||
11223 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
11224 | { |
11225 | bpt_p = &single_step_breakpoints[0]; | |
11226 | single_step_gdbarch[0] = gdbarch; | |
11227 | } | |
8181d85f DJ |
11228 | else |
11229 | { | |
11230 | gdb_assert (single_step_breakpoints[1] == NULL); | |
11231 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 11232 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
11233 | } |
11234 | ||
4a64f543 MS |
11235 | /* NOTE drow/2006-04-11: A future improvement to this function would |
11236 | be to only create the breakpoints once, and actually put them on | |
11237 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
11238 | We could adjust the addresses each time they were needed. Doing | |
11239 | this requires corresponding changes elsewhere where single step | |
11240 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 11241 | |
6c95b8df | 11242 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 11243 | if (*bpt_p == NULL) |
5af949e3 UW |
11244 | error (_("Could not insert single-step breakpoint at %s"), |
11245 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
11246 | } |
11247 | ||
f02253f1 HZ |
11248 | /* Check if the breakpoints used for software single stepping |
11249 | were inserted or not. */ | |
11250 | ||
11251 | int | |
11252 | single_step_breakpoints_inserted (void) | |
11253 | { | |
11254 | return (single_step_breakpoints[0] != NULL | |
11255 | || single_step_breakpoints[1] != NULL); | |
11256 | } | |
11257 | ||
8181d85f DJ |
11258 | /* Remove and delete any breakpoints used for software single step. */ |
11259 | ||
11260 | void | |
11261 | remove_single_step_breakpoints (void) | |
11262 | { | |
11263 | gdb_assert (single_step_breakpoints[0] != NULL); | |
11264 | ||
11265 | /* See insert_single_step_breakpoint for more about this deprecated | |
11266 | call. */ | |
a6d9a66e UW |
11267 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
11268 | single_step_breakpoints[0]); | |
11269 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
11270 | single_step_breakpoints[0] = NULL; |
11271 | ||
11272 | if (single_step_breakpoints[1] != NULL) | |
11273 | { | |
a6d9a66e UW |
11274 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
11275 | single_step_breakpoints[1]); | |
11276 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
11277 | single_step_breakpoints[1] = NULL; |
11278 | } | |
11279 | } | |
11280 | ||
d03285ec UW |
11281 | /* Delete software single step breakpoints without removing them from |
11282 | the inferior. This is intended to be used if the inferior's address | |
11283 | space where they were inserted is already gone, e.g. after exit or | |
11284 | exec. */ | |
11285 | ||
11286 | void | |
11287 | cancel_single_step_breakpoints (void) | |
11288 | { | |
11289 | int i; | |
11290 | ||
11291 | for (i = 0; i < 2; i++) | |
11292 | if (single_step_breakpoints[i]) | |
11293 | { | |
11294 | xfree (single_step_breakpoints[i]); | |
11295 | single_step_breakpoints[i] = NULL; | |
11296 | single_step_gdbarch[i] = NULL; | |
11297 | } | |
11298 | } | |
11299 | ||
11300 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
11301 | removing them. */ | |
11302 | ||
11303 | static void | |
11304 | detach_single_step_breakpoints (void) | |
11305 | { | |
11306 | int i; | |
11307 | ||
11308 | for (i = 0; i < 2; i++) | |
11309 | if (single_step_breakpoints[i]) | |
11310 | target_remove_breakpoint (single_step_gdbarch[i], | |
11311 | single_step_breakpoints[i]); | |
11312 | } | |
11313 | ||
4a64f543 MS |
11314 | /* Check whether a software single-step breakpoint is inserted at |
11315 | PC. */ | |
1aafd4da UW |
11316 | |
11317 | static int | |
cc59ec59 MS |
11318 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
11319 | CORE_ADDR pc) | |
1aafd4da UW |
11320 | { |
11321 | int i; | |
11322 | ||
11323 | for (i = 0; i < 2; i++) | |
11324 | { | |
11325 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
11326 | if (bp_tgt |
11327 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
11328 | bp_tgt->placed_address, | |
11329 | aspace, pc)) | |
1aafd4da UW |
11330 | return 1; |
11331 | } | |
11332 | ||
11333 | return 0; | |
11334 | } | |
11335 | ||
a96d9b2e SDJ |
11336 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
11337 | non-zero otherwise. */ | |
11338 | static int | |
11339 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
11340 | { | |
11341 | if (syscall_catchpoint_p (bp) | |
11342 | && bp->enable_state != bp_disabled | |
11343 | && bp->enable_state != bp_call_disabled) | |
11344 | return 1; | |
11345 | else | |
11346 | return 0; | |
11347 | } | |
11348 | ||
11349 | int | |
11350 | catch_syscall_enabled (void) | |
11351 | { | |
11352 | struct inferior *inf = current_inferior (); | |
11353 | ||
11354 | return inf->total_syscalls_count != 0; | |
11355 | } | |
11356 | ||
11357 | int | |
11358 | catching_syscall_number (int syscall_number) | |
11359 | { | |
11360 | struct breakpoint *bp; | |
11361 | ||
11362 | ALL_BREAKPOINTS (bp) | |
11363 | if (is_syscall_catchpoint_enabled (bp)) | |
11364 | { | |
11365 | if (bp->syscalls_to_be_caught) | |
11366 | { | |
11367 | int i, iter; | |
11368 | for (i = 0; | |
11369 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
11370 | i++) | |
11371 | if (syscall_number == iter) | |
11372 | return 1; | |
11373 | } | |
11374 | else | |
11375 | return 1; | |
11376 | } | |
11377 | ||
11378 | return 0; | |
11379 | } | |
11380 | ||
11381 | /* Complete syscall names. Used by "catch syscall". */ | |
11382 | static char ** | |
11383 | catch_syscall_completer (struct cmd_list_element *cmd, | |
11384 | char *text, char *word) | |
11385 | { | |
11386 | const char **list = get_syscall_names (); | |
c38eea1a MS |
11387 | char **retlist |
11388 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 11389 | |
c38eea1a MS |
11390 | xfree (list); |
11391 | return retlist; | |
a96d9b2e SDJ |
11392 | } |
11393 | ||
1042e4c0 SS |
11394 | /* Tracepoint-specific operations. */ |
11395 | ||
11396 | /* Set tracepoint count to NUM. */ | |
11397 | static void | |
11398 | set_tracepoint_count (int num) | |
11399 | { | |
11400 | tracepoint_count = num; | |
4fa62494 | 11401 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
11402 | } |
11403 | ||
11404 | void | |
11405 | trace_command (char *arg, int from_tty) | |
11406 | { | |
8cdf0e15 VP |
11407 | if (create_breakpoint (get_current_arch (), |
11408 | arg, | |
11409 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11410 | 0 /* tempflag */, |
11411 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11412 | 0 /* Ignore count */, |
11413 | pending_break_support, | |
11414 | NULL, | |
11415 | from_tty, | |
84f4c1fe PM |
11416 | 1 /* enabled */, |
11417 | 0 /* internal */)) | |
fd9b8c24 | 11418 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
11419 | } |
11420 | ||
7a697b8d SS |
11421 | void |
11422 | ftrace_command (char *arg, int from_tty) | |
11423 | { | |
8cdf0e15 VP |
11424 | if (create_breakpoint (get_current_arch (), |
11425 | arg, | |
11426 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11427 | 0 /* tempflag */, |
11428 | bp_fast_tracepoint /* type_wanted */, | |
11429 | 0 /* Ignore count */, | |
11430 | pending_break_support, | |
11431 | NULL, | |
11432 | from_tty, | |
84f4c1fe PM |
11433 | 1 /* enabled */, |
11434 | 0 /* internal */)) | |
0fb4aa4b PA |
11435 | set_tracepoint_count (breakpoint_count); |
11436 | } | |
11437 | ||
11438 | /* strace command implementation. Creates a static tracepoint. */ | |
11439 | ||
11440 | void | |
11441 | strace_command (char *arg, int from_tty) | |
11442 | { | |
11443 | if (create_breakpoint (get_current_arch (), | |
11444 | arg, | |
11445 | NULL, 0, 1 /* parse arg */, | |
11446 | 0 /* tempflag */, | |
11447 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11448 | 0 /* Ignore count */, |
11449 | pending_break_support, | |
11450 | NULL, | |
11451 | from_tty, | |
84f4c1fe PM |
11452 | 1 /* enabled */, |
11453 | 0 /* internal */)) | |
fd9b8c24 | 11454 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
11455 | } |
11456 | ||
409873ef SS |
11457 | /* Set up a fake reader function that gets command lines from a linked |
11458 | list that was acquired during tracepoint uploading. */ | |
11459 | ||
11460 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 11461 | static int next_cmd; |
409873ef SS |
11462 | |
11463 | static char * | |
11464 | read_uploaded_action (void) | |
11465 | { | |
11466 | char *rslt; | |
11467 | ||
3149d8c1 | 11468 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 11469 | |
3149d8c1 | 11470 | next_cmd++; |
409873ef SS |
11471 | |
11472 | return rslt; | |
11473 | } | |
11474 | ||
00bf0b85 SS |
11475 | /* Given information about a tracepoint as recorded on a target (which |
11476 | can be either a live system or a trace file), attempt to create an | |
11477 | equivalent GDB tracepoint. This is not a reliable process, since | |
11478 | the target does not necessarily have all the information used when | |
11479 | the tracepoint was originally defined. */ | |
11480 | ||
11481 | struct breakpoint * | |
11482 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 11483 | { |
409873ef | 11484 | char *addr_str, small_buf[100]; |
d5551862 | 11485 | struct breakpoint *tp; |
fd9b8c24 | 11486 | |
409873ef SS |
11487 | if (utp->at_string) |
11488 | addr_str = utp->at_string; | |
11489 | else | |
11490 | { | |
11491 | /* In the absence of a source location, fall back to raw | |
11492 | address. Since there is no way to confirm that the address | |
11493 | means the same thing as when the trace was started, warn the | |
11494 | user. */ | |
3e43a32a MS |
11495 | warning (_("Uploaded tracepoint %d has no " |
11496 | "source location, using raw address"), | |
409873ef SS |
11497 | utp->number); |
11498 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
11499 | addr_str = small_buf; | |
11500 | } | |
11501 | ||
11502 | /* There's not much we can do with a sequence of bytecodes. */ | |
11503 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
11504 | warning (_("Uploaded tracepoint %d condition " |
11505 | "has no source form, ignoring it"), | |
409873ef | 11506 | utp->number); |
d5551862 | 11507 | |
8cdf0e15 | 11508 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
11509 | addr_str, |
11510 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 11511 | 0 /* tempflag */, |
0fb4aa4b | 11512 | utp->type /* type_wanted */, |
8cdf0e15 VP |
11513 | 0 /* Ignore count */, |
11514 | pending_break_support, | |
11515 | NULL, | |
11516 | 0 /* from_tty */, | |
84f4c1fe PM |
11517 | utp->enabled /* enabled */, |
11518 | 0 /* internal */)) | |
fd9b8c24 PA |
11519 | return NULL; |
11520 | ||
00bf0b85 SS |
11521 | set_tracepoint_count (breakpoint_count); |
11522 | ||
409873ef | 11523 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
11524 | tp = get_tracepoint (tracepoint_count); |
11525 | gdb_assert (tp != NULL); | |
d5551862 | 11526 | |
00bf0b85 SS |
11527 | if (utp->pass > 0) |
11528 | { | |
409873ef | 11529 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 11530 | |
409873ef | 11531 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
11532 | } |
11533 | ||
409873ef SS |
11534 | /* If we have uploaded versions of the original commands, set up a |
11535 | special-purpose "reader" function and call the usual command line | |
11536 | reader, then pass the result to the breakpoint command-setting | |
11537 | function. */ | |
3149d8c1 | 11538 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 11539 | { |
409873ef | 11540 | struct command_line *cmd_list; |
00bf0b85 | 11541 | |
409873ef | 11542 | this_utp = utp; |
3149d8c1 | 11543 | next_cmd = 0; |
d5551862 | 11544 | |
409873ef SS |
11545 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
11546 | ||
11547 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 11548 | } |
3149d8c1 SS |
11549 | else if (!VEC_empty (char_ptr, utp->actions) |
11550 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
11551 | warning (_("Uploaded tracepoint %d actions " |
11552 | "have no source form, ignoring them"), | |
409873ef | 11553 | utp->number); |
00bf0b85 SS |
11554 | |
11555 | return tp; | |
11556 | } | |
11557 | ||
1042e4c0 SS |
11558 | /* Print information on tracepoint number TPNUM_EXP, or all if |
11559 | omitted. */ | |
11560 | ||
11561 | static void | |
e5a67952 | 11562 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 11563 | { |
e5a67952 | 11564 | int num_printed; |
1042e4c0 | 11565 | |
e5a67952 | 11566 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
11567 | |
11568 | if (num_printed == 0) | |
1042e4c0 | 11569 | { |
e5a67952 | 11570 | if (args == NULL || *args == '\0') |
d77f58be SS |
11571 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
11572 | else | |
e5a67952 | 11573 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 11574 | } |
ad443146 SS |
11575 | |
11576 | default_collect_info (); | |
1042e4c0 SS |
11577 | } |
11578 | ||
4a64f543 | 11579 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
11580 | Not supported by all targets. */ |
11581 | static void | |
11582 | enable_trace_command (char *args, int from_tty) | |
11583 | { | |
11584 | enable_command (args, from_tty); | |
11585 | } | |
11586 | ||
4a64f543 | 11587 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
11588 | Not supported by all targets. */ |
11589 | static void | |
11590 | disable_trace_command (char *args, int from_tty) | |
11591 | { | |
11592 | disable_command (args, from_tty); | |
11593 | } | |
11594 | ||
4a64f543 | 11595 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
11596 | static void |
11597 | delete_trace_command (char *arg, int from_tty) | |
11598 | { | |
35df4500 | 11599 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
11600 | |
11601 | dont_repeat (); | |
11602 | ||
11603 | if (arg == 0) | |
11604 | { | |
11605 | int breaks_to_delete = 0; | |
11606 | ||
11607 | /* Delete all breakpoints if no argument. | |
11608 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
11609 | have to be deleted with an explicit breakpoint number |
11610 | argument. */ | |
1042e4c0 SS |
11611 | ALL_TRACEPOINTS (b) |
11612 | { | |
11613 | if (b->number >= 0) | |
11614 | { | |
11615 | breaks_to_delete = 1; | |
11616 | break; | |
11617 | } | |
11618 | } | |
11619 | ||
11620 | /* Ask user only if there are some breakpoints to delete. */ | |
11621 | if (!from_tty | |
11622 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
11623 | { | |
35df4500 | 11624 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
1042e4c0 | 11625 | { |
d77f58be | 11626 | if (is_tracepoint (b) |
059fb39f | 11627 | && b->number >= 0) |
1042e4c0 SS |
11628 | delete_breakpoint (b); |
11629 | } | |
11630 | } | |
11631 | } | |
11632 | else | |
95a42b64 | 11633 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
11634 | } |
11635 | ||
197f0a60 TT |
11636 | /* Helper function for trace_pass_command. */ |
11637 | ||
11638 | static void | |
11639 | trace_pass_set_count (struct breakpoint *bp, int count, int from_tty) | |
11640 | { | |
11641 | bp->pass_count = count; | |
11642 | observer_notify_tracepoint_modified (bp->number); | |
11643 | if (from_tty) | |
11644 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
11645 | bp->number, count); | |
11646 | } | |
11647 | ||
1042e4c0 SS |
11648 | /* Set passcount for tracepoint. |
11649 | ||
11650 | First command argument is passcount, second is tracepoint number. | |
11651 | If tracepoint number omitted, apply to most recently defined. | |
11652 | Also accepts special argument "all". */ | |
11653 | ||
11654 | static void | |
11655 | trace_pass_command (char *args, int from_tty) | |
11656 | { | |
197f0a60 | 11657 | struct breakpoint *t1; |
1042e4c0 | 11658 | unsigned int count; |
1042e4c0 SS |
11659 | |
11660 | if (args == 0 || *args == 0) | |
3e43a32a MS |
11661 | error (_("passcount command requires an " |
11662 | "argument (count + optional TP num)")); | |
1042e4c0 | 11663 | |
4a64f543 | 11664 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
11665 | |
11666 | while (*args && isspace ((int) *args)) | |
11667 | args++; | |
11668 | ||
11669 | if (*args && strncasecmp (args, "all", 3) == 0) | |
11670 | { | |
11671 | args += 3; /* Skip special argument "all". */ | |
1042e4c0 SS |
11672 | if (*args) |
11673 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 11674 | |
197f0a60 TT |
11675 | ALL_TRACEPOINTS (t1) |
11676 | { | |
11677 | trace_pass_set_count (t1, count, from_tty); | |
11678 | } | |
11679 | } | |
11680 | else if (*args == '\0') | |
1042e4c0 | 11681 | { |
197f0a60 | 11682 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 11683 | if (t1) |
197f0a60 TT |
11684 | trace_pass_set_count (t1, count, from_tty); |
11685 | } | |
11686 | else | |
11687 | { | |
11688 | struct get_number_or_range_state state; | |
11689 | ||
11690 | init_number_or_range (&state, args); | |
11691 | while (!state.finished) | |
1042e4c0 | 11692 | { |
197f0a60 TT |
11693 | t1 = get_tracepoint_by_number (&args, &state, 1); |
11694 | if (t1) | |
11695 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
11696 | } |
11697 | } | |
1042e4c0 SS |
11698 | } |
11699 | ||
11700 | struct breakpoint * | |
11701 | get_tracepoint (int num) | |
11702 | { | |
11703 | struct breakpoint *t; | |
11704 | ||
11705 | ALL_TRACEPOINTS (t) | |
11706 | if (t->number == num) | |
11707 | return t; | |
11708 | ||
11709 | return NULL; | |
11710 | } | |
11711 | ||
d5551862 SS |
11712 | /* Find the tracepoint with the given target-side number (which may be |
11713 | different from the tracepoint number after disconnecting and | |
11714 | reconnecting). */ | |
11715 | ||
11716 | struct breakpoint * | |
11717 | get_tracepoint_by_number_on_target (int num) | |
11718 | { | |
11719 | struct breakpoint *t; | |
11720 | ||
11721 | ALL_TRACEPOINTS (t) | |
11722 | if (t->number_on_target == num) | |
11723 | return t; | |
11724 | ||
11725 | return NULL; | |
11726 | } | |
11727 | ||
1042e4c0 | 11728 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
11729 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
11730 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 SS |
11731 | recent tracepoint (tracepoint_count) is returned. */ |
11732 | struct breakpoint * | |
197f0a60 TT |
11733 | get_tracepoint_by_number (char **arg, |
11734 | struct get_number_or_range_state *state, | |
11735 | int optional_p) | |
1042e4c0 SS |
11736 | { |
11737 | extern int tracepoint_count; | |
11738 | struct breakpoint *t; | |
11739 | int tpnum; | |
11740 | char *instring = arg == NULL ? NULL : *arg; | |
11741 | ||
197f0a60 TT |
11742 | if (state) |
11743 | { | |
11744 | gdb_assert (!state->finished); | |
11745 | tpnum = get_number_or_range (state); | |
11746 | } | |
11747 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
11748 | { |
11749 | if (optional_p) | |
11750 | tpnum = tracepoint_count; | |
11751 | else | |
11752 | error_no_arg (_("tracepoint number")); | |
11753 | } | |
11754 | else | |
197f0a60 | 11755 | tpnum = get_number (arg); |
1042e4c0 SS |
11756 | |
11757 | if (tpnum <= 0) | |
11758 | { | |
11759 | if (instring && *instring) | |
11760 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
11761 | instring); | |
11762 | else | |
3e43a32a MS |
11763 | printf_filtered (_("Tracepoint argument missing " |
11764 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
11765 | return NULL; |
11766 | } | |
11767 | ||
11768 | ALL_TRACEPOINTS (t) | |
11769 | if (t->number == tpnum) | |
11770 | { | |
11771 | return t; | |
11772 | } | |
11773 | ||
1042e4c0 SS |
11774 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
11775 | return NULL; | |
11776 | } | |
11777 | ||
6149aea9 PA |
11778 | /* Save information on user settable breakpoints (watchpoints, etc) to |
11779 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
11780 | on each breakpoint and only include the ones for which it returns | |
11781 | non-zero. */ | |
11782 | ||
1042e4c0 | 11783 | static void |
6149aea9 PA |
11784 | save_breakpoints (char *filename, int from_tty, |
11785 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
11786 | { |
11787 | struct breakpoint *tp; | |
6149aea9 | 11788 | int any = 0; |
a7bdde9e | 11789 | char *pathname; |
1042e4c0 | 11790 | struct cleanup *cleanup; |
a7bdde9e | 11791 | struct ui_file *fp; |
6149aea9 | 11792 | int extra_trace_bits = 0; |
1042e4c0 | 11793 | |
6149aea9 PA |
11794 | if (filename == 0 || *filename == 0) |
11795 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
11796 | |
11797 | /* See if we have anything to save. */ | |
6149aea9 | 11798 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11799 | { |
6149aea9 | 11800 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11801 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
11802 | continue; |
11803 | ||
11804 | /* If we have a filter, only save the breakpoints it accepts. */ | |
11805 | if (filter && !filter (tp)) | |
11806 | continue; | |
11807 | ||
11808 | any = 1; | |
11809 | ||
11810 | if (is_tracepoint (tp)) | |
11811 | { | |
11812 | extra_trace_bits = 1; | |
11813 | ||
11814 | /* We can stop searching. */ | |
11815 | break; | |
11816 | } | |
1042e4c0 | 11817 | } |
6149aea9 PA |
11818 | |
11819 | if (!any) | |
1042e4c0 | 11820 | { |
6149aea9 | 11821 | warning (_("Nothing to save.")); |
1042e4c0 SS |
11822 | return; |
11823 | } | |
11824 | ||
6149aea9 | 11825 | pathname = tilde_expand (filename); |
1042e4c0 | 11826 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 11827 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 11828 | if (!fp) |
6149aea9 PA |
11829 | error (_("Unable to open file '%s' for saving (%s)"), |
11830 | filename, safe_strerror (errno)); | |
a7bdde9e | 11831 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 11832 | |
6149aea9 PA |
11833 | if (extra_trace_bits) |
11834 | save_trace_state_variables (fp); | |
8bf6485c | 11835 | |
6149aea9 | 11836 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11837 | { |
6149aea9 | 11838 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11839 | if (!user_breakpoint_p (tp)) |
6149aea9 | 11840 | continue; |
8bf6485c | 11841 | |
6149aea9 PA |
11842 | /* If we have a filter, only save the breakpoints it accepts. */ |
11843 | if (filter && !filter (tp)) | |
11844 | continue; | |
11845 | ||
11846 | if (tp->ops != NULL) | |
11847 | (tp->ops->print_recreate) (tp, fp); | |
1042e4c0 SS |
11848 | else |
11849 | { | |
6149aea9 PA |
11850 | if (tp->type == bp_fast_tracepoint) |
11851 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
11852 | if (tp->type == bp_static_tracepoint) |
11853 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
11854 | else if (tp->type == bp_tracepoint) |
11855 | fprintf_unfiltered (fp, "trace"); | |
11856 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11857 | fprintf_unfiltered (fp, "tbreak"); | |
11858 | else if (tp->type == bp_breakpoint) | |
11859 | fprintf_unfiltered (fp, "break"); | |
11860 | else if (tp->type == bp_hardware_breakpoint | |
11861 | && tp->disposition == disp_del) | |
11862 | fprintf_unfiltered (fp, "thbreak"); | |
11863 | else if (tp->type == bp_hardware_breakpoint) | |
11864 | fprintf_unfiltered (fp, "hbreak"); | |
11865 | else if (tp->type == bp_watchpoint) | |
11866 | fprintf_unfiltered (fp, "watch"); | |
11867 | else if (tp->type == bp_hardware_watchpoint) | |
11868 | fprintf_unfiltered (fp, "watch"); | |
11869 | else if (tp->type == bp_read_watchpoint) | |
11870 | fprintf_unfiltered (fp, "rwatch"); | |
11871 | else if (tp->type == bp_access_watchpoint) | |
11872 | fprintf_unfiltered (fp, "awatch"); | |
11873 | else | |
11874 | internal_error (__FILE__, __LINE__, | |
11875 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11876 | ||
11877 | if (tp->exp_string) | |
11878 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
11879 | else if (tp->addr_string) | |
11880 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
11881 | else | |
11882 | { | |
11883 | char tmp[40]; | |
11884 | ||
11885 | sprintf_vma (tmp, tp->loc->address); | |
11886 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
11887 | } | |
1042e4c0 SS |
11888 | } |
11889 | ||
6149aea9 PA |
11890 | if (tp->thread != -1) |
11891 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
11892 | ||
11893 | if (tp->task != 0) | |
11894 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
11895 | |
11896 | fprintf_unfiltered (fp, "\n"); | |
11897 | ||
6149aea9 PA |
11898 | /* Note, we can't rely on tp->number for anything, as we can't |
11899 | assume the recreated breakpoint numbers will match. Use $bpnum | |
11900 | instead. */ | |
11901 | ||
11902 | if (tp->cond_string) | |
11903 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
11904 | ||
11905 | if (tp->ignore_count) | |
11906 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
11907 | ||
1042e4c0 | 11908 | if (tp->pass_count) |
a7bdde9e | 11909 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 11910 | |
a7bdde9e | 11911 | if (tp->commands) |
1042e4c0 | 11912 | { |
a7bdde9e VP |
11913 | volatile struct gdb_exception ex; |
11914 | ||
6149aea9 | 11915 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
11916 | |
11917 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 11918 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 11919 | { |
9add0f1b | 11920 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
11921 | } |
11922 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 11923 | |
a7bdde9e VP |
11924 | if (ex.reason < 0) |
11925 | throw_exception (ex); | |
1042e4c0 | 11926 | |
a7bdde9e | 11927 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 11928 | } |
6149aea9 PA |
11929 | |
11930 | if (tp->enable_state == bp_disabled) | |
11931 | fprintf_unfiltered (fp, "disable\n"); | |
11932 | ||
11933 | /* If this is a multi-location breakpoint, check if the locations | |
11934 | should be individually disabled. Watchpoint locations are | |
11935 | special, and not user visible. */ | |
11936 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
11937 | { | |
11938 | struct bp_location *loc; | |
11939 | int n = 1; | |
11940 | ||
11941 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
11942 | if (!loc->enabled) | |
11943 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
11944 | } | |
1042e4c0 | 11945 | } |
8bf6485c | 11946 | |
6149aea9 | 11947 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
11948 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
11949 | ||
1042e4c0 SS |
11950 | do_cleanups (cleanup); |
11951 | if (from_tty) | |
6149aea9 PA |
11952 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
11953 | } | |
11954 | ||
11955 | /* The `save breakpoints' command. */ | |
11956 | ||
11957 | static void | |
11958 | save_breakpoints_command (char *args, int from_tty) | |
11959 | { | |
11960 | save_breakpoints (args, from_tty, NULL); | |
11961 | } | |
11962 | ||
11963 | /* The `save tracepoints' command. */ | |
11964 | ||
11965 | static void | |
11966 | save_tracepoints_command (char *args, int from_tty) | |
11967 | { | |
11968 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
11969 | } |
11970 | ||
11971 | /* Create a vector of all tracepoints. */ | |
11972 | ||
11973 | VEC(breakpoint_p) * | |
eeae04df | 11974 | all_tracepoints (void) |
1042e4c0 SS |
11975 | { |
11976 | VEC(breakpoint_p) *tp_vec = 0; | |
11977 | struct breakpoint *tp; | |
11978 | ||
11979 | ALL_TRACEPOINTS (tp) | |
11980 | { | |
11981 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
11982 | } | |
11983 | ||
11984 | return tp_vec; | |
11985 | } | |
11986 | ||
c906108c | 11987 | \f |
4a64f543 MS |
11988 | /* This help string is used for the break, hbreak, tbreak and thbreak |
11989 | commands. It is defined as a macro to prevent duplication. | |
11990 | COMMAND should be a string constant containing the name of the | |
11991 | command. */ | |
31e2b00f AS |
11992 | #define BREAK_ARGS_HELP(command) \ |
11993 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
11994 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
11995 | If a line number is specified, break at start of code for that line.\n\ | |
11996 | If a function is specified, break at start of code for that function.\n\ | |
11997 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
11998 | With no LOCATION, uses current execution address of the selected\n\ |
11999 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
12000 | \n\ |
12001 | THREADNUM is the number from \"info threads\".\n\ | |
12002 | CONDITION is a boolean expression.\n\ | |
12003 | \n\ | |
d41c0fc8 PA |
12004 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
12005 | conditions are different.\n\ | |
31e2b00f AS |
12006 | \n\ |
12007 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
12008 | ||
44feb3ce TT |
12009 | /* List of subcommands for "catch". */ |
12010 | static struct cmd_list_element *catch_cmdlist; | |
12011 | ||
12012 | /* List of subcommands for "tcatch". */ | |
12013 | static struct cmd_list_element *tcatch_cmdlist; | |
12014 | ||
12015 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
12016 | lists, and pass some additional user data to the command function. */ | |
12017 | static void | |
12018 | add_catch_command (char *name, char *docstring, | |
12019 | void (*sfunc) (char *args, int from_tty, | |
12020 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
12021 | char **(*completer) (struct cmd_list_element *cmd, |
12022 | char *text, char *word), | |
44feb3ce TT |
12023 | void *user_data_catch, |
12024 | void *user_data_tcatch) | |
12025 | { | |
12026 | struct cmd_list_element *command; | |
12027 | ||
12028 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12029 | &catch_cmdlist); | |
12030 | set_cmd_sfunc (command, sfunc); | |
12031 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 12032 | set_cmd_completer (command, completer); |
44feb3ce TT |
12033 | |
12034 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12035 | &tcatch_cmdlist); | |
12036 | set_cmd_sfunc (command, sfunc); | |
12037 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 12038 | set_cmd_completer (command, completer); |
44feb3ce TT |
12039 | } |
12040 | ||
6c95b8df | 12041 | static void |
a79b8f6e | 12042 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 12043 | { |
6c95b8df PA |
12044 | inf->total_syscalls_count = 0; |
12045 | inf->any_syscall_count = 0; | |
12046 | VEC_free (int, inf->syscalls_counts); | |
12047 | } | |
12048 | ||
6149aea9 PA |
12049 | static void |
12050 | save_command (char *arg, int from_tty) | |
12051 | { | |
3e43a32a MS |
12052 | printf_unfiltered (_("\"save\" must be followed by " |
12053 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
12054 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
12055 | } | |
12056 | ||
84f4c1fe PM |
12057 | struct breakpoint * |
12058 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
12059 | void *data) | |
12060 | { | |
35df4500 | 12061 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 12062 | |
35df4500 | 12063 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
12064 | { |
12065 | if ((*callback) (b, data)) | |
12066 | return b; | |
12067 | } | |
12068 | ||
12069 | return NULL; | |
12070 | } | |
12071 | ||
c906108c | 12072 | void |
fba45db2 | 12073 | _initialize_breakpoint (void) |
c906108c SS |
12074 | { |
12075 | struct cmd_list_element *c; | |
12076 | ||
84acb35a | 12077 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 12078 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 12079 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 12080 | |
17450429 PP |
12081 | breakpoint_objfile_key = register_objfile_data (); |
12082 | ||
c906108c SS |
12083 | breakpoint_chain = 0; |
12084 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
12085 | before a breakpoint is set. */ | |
12086 | breakpoint_count = 0; | |
12087 | ||
1042e4c0 SS |
12088 | tracepoint_count = 0; |
12089 | ||
1bedd215 AC |
12090 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
12091 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
12092 | Usage is `ignore N COUNT'.")); | |
c906108c | 12093 | if (xdb_commands) |
c5aa993b | 12094 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 12095 | |
1bedd215 AC |
12096 | add_com ("commands", class_breakpoint, commands_command, _("\ |
12097 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
12098 | Give breakpoint number as argument after \"commands\".\n\ |
12099 | With no argument, the targeted breakpoint is the last one set.\n\ | |
12100 | The commands themselves follow starting on the next line.\n\ | |
12101 | Type a line containing \"end\" to indicate the end of them.\n\ | |
12102 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 12103 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 12104 | |
1bedd215 AC |
12105 | add_com ("condition", class_breakpoint, condition_command, _("\ |
12106 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 12107 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 12108 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 12109 | |
1bedd215 | 12110 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 12111 | Set a temporary breakpoint.\n\ |
c906108c SS |
12112 | Like \"break\" except the breakpoint is only temporary,\n\ |
12113 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
12114 | by using \"enable delete\" on the breakpoint number.\n\ |
12115 | \n" | |
12116 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 12117 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12118 | |
1bedd215 | 12119 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 12120 | Set a hardware assisted breakpoint.\n\ |
c906108c | 12121 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
12122 | some target hardware may not have this support.\n\ |
12123 | \n" | |
12124 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 12125 | set_cmd_completer (c, location_completer); |
c906108c | 12126 | |
1bedd215 | 12127 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 12128 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 12129 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
12130 | so it will be deleted when hit.\n\ |
12131 | \n" | |
12132 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 12133 | set_cmd_completer (c, location_completer); |
c906108c | 12134 | |
1bedd215 AC |
12135 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
12136 | Enable some breakpoints.\n\ | |
c906108c SS |
12137 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12138 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12139 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12140 | With a subcommand you can enable temporarily."), |
c906108c SS |
12141 | &enablelist, "enable ", 1, &cmdlist); |
12142 | if (xdb_commands) | |
1bedd215 AC |
12143 | add_com ("ab", class_breakpoint, enable_command, _("\ |
12144 | Enable some breakpoints.\n\ | |
c906108c SS |
12145 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12146 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12147 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12148 | With a subcommand you can enable temporarily.")); |
c906108c SS |
12149 | |
12150 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
12151 | ||
84951ab5 | 12152 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 12153 | Enable some breakpoints.\n\ |
c906108c SS |
12154 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12155 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12156 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 12157 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 12158 | |
1a966eab AC |
12159 | add_cmd ("once", no_class, enable_once_command, _("\ |
12160 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12161 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12162 | &enablebreaklist); |
12163 | ||
1a966eab AC |
12164 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12165 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12166 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12167 | &enablebreaklist); |
12168 | ||
1a966eab AC |
12169 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12170 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12171 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12172 | &enablelist); |
12173 | ||
1a966eab AC |
12174 | add_cmd ("once", no_class, enable_once_command, _("\ |
12175 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12176 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12177 | &enablelist); |
12178 | ||
1bedd215 AC |
12179 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
12180 | Disable some breakpoints.\n\ | |
c906108c SS |
12181 | Arguments are breakpoint numbers with spaces in between.\n\ |
12182 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12183 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
12184 | &disablelist, "disable ", 1, &cmdlist); |
12185 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
12186 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
12187 | if (xdb_commands) | |
1bedd215 AC |
12188 | add_com ("sb", class_breakpoint, disable_command, _("\ |
12189 | Disable some breakpoints.\n\ | |
c906108c SS |
12190 | Arguments are breakpoint numbers with spaces in between.\n\ |
12191 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12192 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 12193 | |
1a966eab AC |
12194 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
12195 | Disable some breakpoints.\n\ | |
c906108c SS |
12196 | Arguments are breakpoint numbers with spaces in between.\n\ |
12197 | To disable all breakpoints, give no argument.\n\ | |
12198 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 12199 | This command may be abbreviated \"disable\"."), |
c906108c SS |
12200 | &disablelist); |
12201 | ||
1bedd215 AC |
12202 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
12203 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12204 | Arguments are breakpoint numbers with spaces in between.\n\ |
12205 | To delete all breakpoints, give no argument.\n\ | |
12206 | \n\ | |
12207 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 12208 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
12209 | &deletelist, "delete ", 1, &cmdlist); |
12210 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 12211 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 12212 | if (xdb_commands) |
1bedd215 AC |
12213 | add_com ("db", class_breakpoint, delete_command, _("\ |
12214 | Delete some breakpoints.\n\ | |
c906108c | 12215 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 12216 | To delete all breakpoints, give no argument.\n")); |
c906108c | 12217 | |
1a966eab AC |
12218 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
12219 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12220 | Arguments are breakpoint numbers with spaces in between.\n\ |
12221 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 12222 | This command may be abbreviated \"delete\"."), |
c906108c SS |
12223 | &deletelist); |
12224 | ||
1bedd215 AC |
12225 | add_com ("clear", class_breakpoint, clear_command, _("\ |
12226 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
12227 | Argument may be line number, function name, or \"*\" and an address.\n\ |
12228 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
12229 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
12230 | If an address is specified, breakpoints at that address are cleared.\n\ |
12231 | \n\ | |
12232 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
12233 | is executing in.\n\ |
12234 | \n\ | |
1bedd215 | 12235 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 12236 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 12237 | |
1bedd215 | 12238 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
12239 | Set breakpoint at specified line or function.\n" |
12240 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 12241 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12242 | |
c906108c SS |
12243 | add_com_alias ("b", "break", class_run, 1); |
12244 | add_com_alias ("br", "break", class_run, 1); | |
12245 | add_com_alias ("bre", "break", class_run, 1); | |
12246 | add_com_alias ("brea", "break", class_run, 1); | |
12247 | ||
7681d515 PM |
12248 | if (xdb_commands) |
12249 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
12250 | |
12251 | if (dbx_commands) | |
12252 | { | |
1bedd215 AC |
12253 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
12254 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
12255 | &stoplist, "stop ", 1, &cmdlist); |
12256 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 12257 | _("Break in function or address."), &stoplist); |
c5aa993b | 12258 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 12259 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
12260 | add_com ("status", class_info, breakpoints_info, _("\ |
12261 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12262 | The \"Type\" column indicates one of:\n\ |
12263 | \tbreakpoint - normal breakpoint\n\ | |
12264 | \twatchpoint - watchpoint\n\ | |
12265 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12266 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12267 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12268 | address and file/line number respectively.\n\ |
12269 | \n\ | |
12270 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12271 | are set to the address of the last breakpoint listed unless the command\n\ |
12272 | is prefixed with \"server \".\n\n\ | |
c906108c | 12273 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12274 | breakpoint set.")); |
c906108c SS |
12275 | } |
12276 | ||
1bedd215 | 12277 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 12278 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
12279 | The \"Type\" column indicates one of:\n\ |
12280 | \tbreakpoint - normal breakpoint\n\ | |
12281 | \twatchpoint - watchpoint\n\ | |
12282 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12283 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12284 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12285 | address and file/line number respectively.\n\ |
12286 | \n\ | |
12287 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12288 | are set to the address of the last breakpoint listed unless the command\n\ |
12289 | is prefixed with \"server \".\n\n\ | |
c906108c | 12290 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12291 | breakpoint set.")); |
c906108c | 12292 | |
6b04bdb7 MS |
12293 | add_info_alias ("b", "breakpoints", 1); |
12294 | ||
c906108c | 12295 | if (xdb_commands) |
1bedd215 AC |
12296 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
12297 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12298 | The \"Type\" column indicates one of:\n\ |
12299 | \tbreakpoint - normal breakpoint\n\ | |
12300 | \twatchpoint - watchpoint\n\ | |
12301 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12302 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12303 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12304 | address and file/line number respectively.\n\ |
12305 | \n\ | |
12306 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12307 | are set to the address of the last breakpoint listed unless the command\n\ |
12308 | is prefixed with \"server \".\n\n\ | |
c906108c | 12309 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12310 | breakpoint set.")); |
c906108c | 12311 | |
1a966eab AC |
12312 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
12313 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12314 | The \"Type\" column indicates one of:\n\ |
12315 | \tbreakpoint - normal breakpoint\n\ | |
12316 | \twatchpoint - watchpoint\n\ | |
12317 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
12318 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
12319 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
12320 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
12321 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
12322 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
12323 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
12324 | address and file/line number respectively.\n\ |
12325 | \n\ | |
12326 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12327 | are set to the address of the last breakpoint listed unless the command\n\ |
12328 | is prefixed with \"server \".\n\n\ | |
c906108c | 12329 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 12330 | breakpoint set."), |
c906108c SS |
12331 | &maintenanceinfolist); |
12332 | ||
44feb3ce TT |
12333 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
12334 | Set catchpoints to catch events."), | |
12335 | &catch_cmdlist, "catch ", | |
12336 | 0/*allow-unknown*/, &cmdlist); | |
12337 | ||
12338 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
12339 | Set temporary catchpoints to catch events."), | |
12340 | &tcatch_cmdlist, "tcatch ", | |
12341 | 0/*allow-unknown*/, &cmdlist); | |
12342 | ||
12343 | /* Add catch and tcatch sub-commands. */ | |
12344 | add_catch_command ("catch", _("\ | |
12345 | Catch an exception, when caught.\n\ | |
12346 | With an argument, catch only exceptions with the given name."), | |
12347 | catch_catch_command, | |
a96d9b2e | 12348 | NULL, |
44feb3ce TT |
12349 | CATCH_PERMANENT, |
12350 | CATCH_TEMPORARY); | |
12351 | add_catch_command ("throw", _("\ | |
12352 | Catch an exception, when thrown.\n\ | |
12353 | With an argument, catch only exceptions with the given name."), | |
12354 | catch_throw_command, | |
a96d9b2e | 12355 | NULL, |
44feb3ce TT |
12356 | CATCH_PERMANENT, |
12357 | CATCH_TEMPORARY); | |
12358 | add_catch_command ("fork", _("Catch calls to fork."), | |
12359 | catch_fork_command_1, | |
a96d9b2e | 12360 | NULL, |
44feb3ce TT |
12361 | (void *) (uintptr_t) catch_fork_permanent, |
12362 | (void *) (uintptr_t) catch_fork_temporary); | |
12363 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
12364 | catch_fork_command_1, | |
a96d9b2e | 12365 | NULL, |
44feb3ce TT |
12366 | (void *) (uintptr_t) catch_vfork_permanent, |
12367 | (void *) (uintptr_t) catch_vfork_temporary); | |
12368 | add_catch_command ("exec", _("Catch calls to exec."), | |
12369 | catch_exec_command_1, | |
a96d9b2e SDJ |
12370 | NULL, |
12371 | CATCH_PERMANENT, | |
12372 | CATCH_TEMPORARY); | |
12373 | add_catch_command ("syscall", _("\ | |
12374 | Catch system calls by their names and/or numbers.\n\ | |
12375 | Arguments say which system calls to catch. If no arguments\n\ | |
12376 | are given, every system call will be caught.\n\ | |
12377 | Arguments, if given, should be one or more system call names\n\ | |
12378 | (if your system supports that), or system call numbers."), | |
12379 | catch_syscall_command_1, | |
12380 | catch_syscall_completer, | |
44feb3ce TT |
12381 | CATCH_PERMANENT, |
12382 | CATCH_TEMPORARY); | |
44feb3ce TT |
12383 | add_catch_command ("exception", _("\ |
12384 | Catch Ada exceptions, when raised.\n\ | |
12385 | With an argument, catch only exceptions with the given name."), | |
12386 | catch_ada_exception_command, | |
a96d9b2e | 12387 | NULL, |
44feb3ce TT |
12388 | CATCH_PERMANENT, |
12389 | CATCH_TEMPORARY); | |
12390 | add_catch_command ("assert", _("\ | |
12391 | Catch failed Ada assertions, when raised.\n\ | |
12392 | With an argument, catch only exceptions with the given name."), | |
12393 | catch_assert_command, | |
a96d9b2e | 12394 | NULL, |
44feb3ce TT |
12395 | CATCH_PERMANENT, |
12396 | CATCH_TEMPORARY); | |
c5aa993b | 12397 | |
1bedd215 AC |
12398 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
12399 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12400 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 12401 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12402 | an expression changes.\n\ |
12403 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12404 | the memory to which it refers.")); | |
65d12d83 | 12405 | set_cmd_completer (c, expression_completer); |
c906108c | 12406 | |
1bedd215 AC |
12407 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
12408 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 12409 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 12410 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12411 | an expression is read.\n\ |
12412 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12413 | the memory to which it refers.")); | |
65d12d83 | 12414 | set_cmd_completer (c, expression_completer); |
c906108c | 12415 | |
1bedd215 AC |
12416 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
12417 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12418 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 12419 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12420 | an expression is either read or written.\n\ |
12421 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12422 | the memory to which it refers.")); | |
65d12d83 | 12423 | set_cmd_completer (c, expression_completer); |
c906108c | 12424 | |
d77f58be | 12425 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 12426 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 12427 | |
920d2a44 AC |
12428 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
12429 | respond to changes - contrary to the description. */ | |
85c07804 AC |
12430 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
12431 | &can_use_hw_watchpoints, _("\ | |
12432 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
12433 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
12434 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
12435 | such is available. (However, any hardware watchpoints that were\n\ | |
12436 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
12437 | hardware.)"), |
12438 | NULL, | |
920d2a44 | 12439 | show_can_use_hw_watchpoints, |
85c07804 | 12440 | &setlist, &showlist); |
c906108c SS |
12441 | |
12442 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 12443 | |
1042e4c0 SS |
12444 | /* Tracepoint manipulation commands. */ |
12445 | ||
12446 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
12447 | Set a tracepoint at specified line or function.\n\ | |
12448 | \n" | |
12449 | BREAK_ARGS_HELP ("trace") "\n\ | |
12450 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12451 | set_cmd_completer (c, location_completer); | |
12452 | ||
12453 | add_com_alias ("tp", "trace", class_alias, 0); | |
12454 | add_com_alias ("tr", "trace", class_alias, 1); | |
12455 | add_com_alias ("tra", "trace", class_alias, 1); | |
12456 | add_com_alias ("trac", "trace", class_alias, 1); | |
12457 | ||
7a697b8d SS |
12458 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
12459 | Set a fast tracepoint at specified line or function.\n\ | |
12460 | \n" | |
12461 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
12462 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12463 | set_cmd_completer (c, location_completer); | |
12464 | ||
0fb4aa4b PA |
12465 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
12466 | Set a static tracepoint at specified line, function or marker.\n\ | |
12467 | \n\ | |
12468 | strace [LOCATION] [if CONDITION]\n\ | |
12469 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
12470 | or -m MARKER_ID.\n\ | |
12471 | If a line number is specified, probe the marker at start of code\n\ | |
12472 | for that line. If a function is specified, probe the marker at start\n\ | |
12473 | of code for that function. If an address is specified, probe the marker\n\ | |
12474 | at that exact address. If a marker id is specified, probe the marker\n\ | |
12475 | with that name. With no LOCATION, uses current execution address of\n\ | |
12476 | the selected stack frame.\n\ | |
12477 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
12478 | This collects arbitrary user data passed in the probe point call to the\n\ | |
12479 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
12480 | by printing the $_sdata variable like any other convenience variable.\n\ | |
12481 | \n\ | |
12482 | CONDITION is a boolean expression.\n\ | |
12483 | \n\ | |
d41c0fc8 PA |
12484 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
12485 | conditions are different.\n\ | |
0fb4aa4b PA |
12486 | \n\ |
12487 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
12488 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12489 | set_cmd_completer (c, location_completer); | |
12490 | ||
1042e4c0 | 12491 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 12492 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
12493 | Convenience variable \"$tpnum\" contains the number of the\n\ |
12494 | last tracepoint set.")); | |
12495 | ||
12496 | add_info_alias ("tp", "tracepoints", 1); | |
12497 | ||
12498 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
12499 | Delete specified tracepoints.\n\ | |
12500 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12501 | No argument means delete all tracepoints."), | |
12502 | &deletelist); | |
12503 | ||
12504 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
12505 | Disable specified tracepoints.\n\ | |
12506 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12507 | No argument means disable all tracepoints."), | |
12508 | &disablelist); | |
12509 | deprecate_cmd (c, "disable"); | |
12510 | ||
12511 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
12512 | Enable specified tracepoints.\n\ | |
12513 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12514 | No argument means enable all tracepoints."), | |
12515 | &enablelist); | |
12516 | deprecate_cmd (c, "enable"); | |
12517 | ||
12518 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
12519 | Set the passcount for a tracepoint.\n\ | |
12520 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
12521 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
12522 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
12523 | ||
6149aea9 PA |
12524 | add_prefix_cmd ("save", class_breakpoint, save_command, |
12525 | _("Save breakpoint definitions as a script."), | |
12526 | &save_cmdlist, "save ", | |
12527 | 0/*allow-unknown*/, &cmdlist); | |
12528 | ||
12529 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
12530 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 12531 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
12532 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
12533 | session to restore them."), | |
12534 | &save_cmdlist); | |
12535 | set_cmd_completer (c, filename_completer); | |
12536 | ||
12537 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 12538 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
12539 | Use the 'source' command in another debug session to restore them."), |
12540 | &save_cmdlist); | |
1042e4c0 SS |
12541 | set_cmd_completer (c, filename_completer); |
12542 | ||
6149aea9 PA |
12543 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
12544 | deprecate_cmd (c, "save tracepoints"); | |
12545 | ||
1bedd215 | 12546 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12547 | Breakpoint specific settings\n\ |
12548 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12549 | pending breakpoint behavior"), |
fa8d40ab JJ |
12550 | &breakpoint_set_cmdlist, "set breakpoint ", |
12551 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 12552 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12553 | Breakpoint specific settings\n\ |
12554 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12555 | pending breakpoint behavior"), |
fa8d40ab JJ |
12556 | &breakpoint_show_cmdlist, "show breakpoint ", |
12557 | 0/*allow-unknown*/, &showlist); | |
12558 | ||
7915a72c AC |
12559 | add_setshow_auto_boolean_cmd ("pending", no_class, |
12560 | &pending_break_support, _("\ | |
12561 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
12562 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
12563 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
12564 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
12565 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 12566 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 12567 | NULL, |
920d2a44 | 12568 | show_pending_break_support, |
6e1d7d6c AC |
12569 | &breakpoint_set_cmdlist, |
12570 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
12571 | |
12572 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
12573 | |
12574 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
12575 | &automatic_hardware_breakpoints, _("\ | |
12576 | Set automatic usage of hardware breakpoints."), _("\ | |
12577 | Show automatic usage of hardware breakpoints."), _("\ | |
12578 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
12579 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
12580 | a warning will be emitted for such breakpoints."), | |
12581 | NULL, | |
12582 | show_automatic_hardware_breakpoints, | |
12583 | &breakpoint_set_cmdlist, | |
12584 | &breakpoint_show_cmdlist); | |
74960c60 | 12585 | |
33e5cbd6 PA |
12586 | add_setshow_enum_cmd ("always-inserted", class_support, |
12587 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
12588 | Set mode for inserting breakpoints."), _("\ |
12589 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
12590 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
12591 | resumed, and removed when execution stops. When this mode is on,\n\ | |
12592 | breakpoints are inserted immediately and removed only when the user\n\ | |
12593 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
12594 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
12595 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
12596 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
12597 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
12598 | NULL, |
12599 | &show_always_inserted_mode, | |
12600 | &breakpoint_set_cmdlist, | |
12601 | &breakpoint_show_cmdlist); | |
765dc015 VP |
12602 | |
12603 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
12604 | |
12605 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 12606 | } |