Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
7b6bb8da | 5 | 2008, 2009, 2010, 2011 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
a6d9a66e | 23 | #include "arch-utils.h" |
c906108c | 24 | #include <ctype.h> |
776592bf | 25 | #include "hashtab.h" |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
1042e4c0 | 29 | #include "tracepoint.h" |
c906108c SS |
30 | #include "gdbtypes.h" |
31 | #include "expression.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "value.h" | |
35 | #include "command.h" | |
36 | #include "inferior.h" | |
37 | #include "gdbthread.h" | |
38 | #include "target.h" | |
39 | #include "language.h" | |
40 | #include "gdb_string.h" | |
41 | #include "demangle.h" | |
42 | #include "annotate.h" | |
43 | #include "symfile.h" | |
44 | #include "objfiles.h" | |
0378c332 | 45 | #include "source.h" |
c5f0f3d0 | 46 | #include "linespec.h" |
c94fdfd0 | 47 | #include "completer.h" |
5b7f31a4 | 48 | #include "gdb.h" |
8b93c638 | 49 | #include "ui-out.h" |
e1507482 | 50 | #include "cli/cli-script.h" |
0225421b | 51 | #include "gdb_assert.h" |
fe898f56 | 52 | #include "block.h" |
a77053c2 | 53 | #include "solib.h" |
84acb35a JJ |
54 | #include "solist.h" |
55 | #include "observer.h" | |
60250e8b | 56 | #include "exceptions.h" |
765dc015 | 57 | #include "memattr.h" |
f7f9143b | 58 | #include "ada-lang.h" |
d1aa2f50 | 59 | #include "top.h" |
fa4727a6 | 60 | #include "wrapper.h" |
79a45b7d | 61 | #include "valprint.h" |
4efc6507 | 62 | #include "jit.h" |
a96d9b2e | 63 | #include "xml-syscall.h" |
65d79d4b | 64 | #include "parser-defs.h" |
c906108c | 65 | |
1042e4c0 SS |
66 | /* readline include files */ |
67 | #include "readline/readline.h" | |
68 | #include "readline/history.h" | |
69 | ||
70 | /* readline defines this. */ | |
71 | #undef savestring | |
72 | ||
034dad6f | 73 | #include "mi/mi-common.h" |
104c1213 | 74 | |
44feb3ce TT |
75 | /* Arguments to pass as context to some catch command handlers. */ |
76 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
77 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 78 | |
4a64f543 | 79 | /* Prototypes for local functions. */ |
c906108c | 80 | |
a14ed312 | 81 | static void enable_delete_command (char *, int); |
c906108c | 82 | |
a14ed312 | 83 | static void enable_once_command (char *, int); |
c906108c | 84 | |
a14ed312 | 85 | static void disable_command (char *, int); |
c906108c | 86 | |
a14ed312 | 87 | static void enable_command (char *, int); |
c906108c | 88 | |
95a42b64 TT |
89 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
90 | void *), | |
91 | void *); | |
c906108c | 92 | |
a14ed312 | 93 | static void ignore_command (char *, int); |
c906108c | 94 | |
4efb68b1 | 95 | static int breakpoint_re_set_one (void *); |
c906108c | 96 | |
a14ed312 | 97 | static void clear_command (char *, int); |
c906108c | 98 | |
a14ed312 | 99 | static void catch_command (char *, int); |
c906108c | 100 | |
e09342b5 | 101 | static int can_use_hardware_watchpoint (struct value *, int); |
c906108c | 102 | |
98deb0da | 103 | static void break_command_1 (char *, int, int); |
c906108c | 104 | |
a14ed312 | 105 | static void mention (struct breakpoint *); |
c906108c | 106 | |
4a64f543 MS |
107 | /* This function is used in gdbtk sources and thus can not be made |
108 | static. */ | |
63c252f8 | 109 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
a6d9a66e UW |
110 | struct symtab_and_line, |
111 | enum bptype); | |
c906108c | 112 | |
76897487 KB |
113 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
114 | ||
a6d9a66e UW |
115 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
116 | CORE_ADDR bpaddr, | |
88f7da05 | 117 | enum bptype bptype); |
76897487 | 118 | |
6c95b8df PA |
119 | static void describe_other_breakpoints (struct gdbarch *, |
120 | struct program_space *, CORE_ADDR, | |
5af949e3 | 121 | struct obj_section *, int); |
c906108c | 122 | |
6c95b8df PA |
123 | static int breakpoint_address_match (struct address_space *aspace1, |
124 | CORE_ADDR addr1, | |
125 | struct address_space *aspace2, | |
126 | CORE_ADDR addr2); | |
127 | ||
85d721b8 PA |
128 | static int watchpoint_locations_match (struct bp_location *loc1, |
129 | struct bp_location *loc2); | |
130 | ||
a14ed312 | 131 | static void breakpoints_info (char *, int); |
c906108c | 132 | |
d77f58be SS |
133 | static void watchpoints_info (char *, int); |
134 | ||
135 | static int breakpoint_1 (int, int, int (*) (const struct breakpoint *)); | |
c906108c | 136 | |
4efb68b1 | 137 | static int breakpoint_cond_eval (void *); |
c906108c | 138 | |
4efb68b1 | 139 | static void cleanup_executing_breakpoints (void *); |
c906108c | 140 | |
a14ed312 | 141 | static void commands_command (char *, int); |
c906108c | 142 | |
a14ed312 | 143 | static void condition_command (char *, int); |
c906108c | 144 | |
a14ed312 | 145 | static int get_number_trailer (char **, int); |
c906108c | 146 | |
c5aa993b JM |
147 | typedef enum |
148 | { | |
149 | mark_inserted, | |
150 | mark_uninserted | |
151 | } | |
152 | insertion_state_t; | |
c906108c | 153 | |
0bde7532 | 154 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 155 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 156 | |
a14ed312 | 157 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
158 | |
159 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 160 | |
4efb68b1 | 161 | static int watchpoint_check (void *); |
c906108c | 162 | |
a14ed312 | 163 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 164 | |
a14ed312 | 165 | static int hw_breakpoint_used_count (void); |
c906108c | 166 | |
a14ed312 | 167 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 168 | |
a14ed312 | 169 | static void hbreak_command (char *, int); |
c906108c | 170 | |
a14ed312 | 171 | static void thbreak_command (char *, int); |
c906108c | 172 | |
a14ed312 | 173 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 174 | |
a14ed312 | 175 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 176 | |
a14ed312 | 177 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 178 | |
a14ed312 | 179 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 180 | |
a14ed312 | 181 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 182 | |
d85310f7 MS |
183 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
184 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 185 | |
a14ed312 | 186 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 187 | |
a14ed312 | 188 | static void ep_skip_leading_whitespace (char **s); |
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 |
4a64f543 MS |
556 | /* *PP is a string denoting a breakpoint. Get the number of the |
557 | breakpoint. Advance *PP after the string and any trailing | |
558 | whitespace. | |
c906108c | 559 | |
4a64f543 MS |
560 | Currently the string can either be a number or "$" followed by the |
561 | name of a convenience variable. Making it an expression wouldn't | |
562 | work well for map_breakpoint_numbers (e.g. "4 + 5 + 6"). | |
40c03ae8 EZ |
563 | |
564 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
565 | |
566 | TRAILER is a character which can be found after the number; most | |
4a64f543 MS |
567 | commonly this is `-'. If you don't want a trailer, use \0. */ |
568 | ||
c906108c | 569 | static int |
fba45db2 | 570 | get_number_trailer (char **pp, int trailer) |
c906108c | 571 | { |
5c44784c | 572 | int retval = 0; /* default */ |
c906108c SS |
573 | char *p = *pp; |
574 | ||
575 | if (p == NULL) | |
576 | /* Empty line means refer to the last breakpoint. */ | |
577 | return breakpoint_count; | |
578 | else if (*p == '$') | |
579 | { | |
580 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 581 | to pass to lookup_internalvar(). */ |
c906108c SS |
582 | char *varname; |
583 | char *start = ++p; | |
4fa62494 | 584 | LONGEST val; |
c906108c SS |
585 | |
586 | while (isalnum (*p) || *p == '_') | |
587 | p++; | |
588 | varname = (char *) alloca (p - start + 1); | |
589 | strncpy (varname, start, p - start); | |
590 | varname[p - start] = '\0'; | |
4fa62494 UW |
591 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
592 | retval = (int) val; | |
5c44784c JM |
593 | else |
594 | { | |
3e43a32a MS |
595 | printf_filtered (_("Convenience variable must " |
596 | "have integer value.\n")); | |
5c44784c JM |
597 | retval = 0; |
598 | } | |
c906108c SS |
599 | } |
600 | else | |
601 | { | |
602 | if (*p == '-') | |
603 | ++p; | |
604 | while (*p >= '0' && *p <= '9') | |
605 | ++p; | |
606 | if (p == *pp) | |
607 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c | 608 | { |
4a64f543 | 609 | /* Skip non-numeric token. */ |
5c44784c JM |
610 | while (*p && !isspace((int) *p)) |
611 | ++p; | |
4a64f543 | 612 | /* Return zero, which caller must interpret as error. */ |
5c44784c JM |
613 | retval = 0; |
614 | } | |
615 | else | |
616 | retval = atoi (*pp); | |
617 | } | |
618 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
619 | { | |
4a64f543 | 620 | /* Trailing junk: return 0 and let caller print error msg. */ |
5c44784c JM |
621 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) |
622 | ++p; | |
623 | retval = 0; | |
c906108c | 624 | } |
c906108c SS |
625 | while (isspace (*p)) |
626 | p++; | |
627 | *pp = p; | |
628 | return retval; | |
629 | } | |
5c44784c | 630 | |
11cf8741 | 631 | |
5c44784c JM |
632 | /* Like get_number_trailer, but don't allow a trailer. */ |
633 | int | |
fba45db2 | 634 | get_number (char **pp) |
5c44784c JM |
635 | { |
636 | return get_number_trailer (pp, '\0'); | |
637 | } | |
638 | ||
639 | /* Parse a number or a range. | |
4a64f543 MS |
640 | A number will be of the form handled by get_number. |
641 | A range will be of the form <number1> - <number2>, and | |
642 | will represent all the integers between number1 and number2, | |
643 | inclusive. | |
644 | ||
645 | While processing a range, this fuction is called iteratively; | |
646 | At each call it will return the next value in the range. | |
647 | ||
648 | At the beginning of parsing a range, the char pointer PP will | |
649 | be advanced past <number1> and left pointing at the '-' token. | |
650 | Subsequent calls will not advance the pointer until the range | |
651 | is completed. The call that completes the range will advance | |
652 | pointer PP past <number2>. */ | |
5c44784c JM |
653 | |
654 | int | |
fba45db2 | 655 | get_number_or_range (char **pp) |
5c44784c JM |
656 | { |
657 | static int last_retval, end_value; | |
658 | static char *end_ptr; | |
659 | static int in_range = 0; | |
660 | ||
661 | if (**pp != '-') | |
662 | { | |
663 | /* Default case: pp is pointing either to a solo number, | |
664 | or to the first number of a range. */ | |
665 | last_retval = get_number_trailer (pp, '-'); | |
666 | if (**pp == '-') | |
667 | { | |
668 | char **temp; | |
669 | ||
670 | /* This is the start of a range (<number1> - <number2>). | |
671 | Skip the '-', parse and remember the second number, | |
672 | and also remember the end of the final token. */ | |
673 | ||
674 | temp = &end_ptr; | |
675 | end_ptr = *pp + 1; | |
676 | while (isspace ((int) *end_ptr)) | |
677 | end_ptr++; /* skip white space */ | |
678 | end_value = get_number (temp); | |
679 | if (end_value < last_retval) | |
680 | { | |
8a3fe4f8 | 681 | error (_("inverted range")); |
5c44784c JM |
682 | } |
683 | else if (end_value == last_retval) | |
684 | { | |
4a64f543 | 685 | /* Degenerate range (number1 == number2). Advance the |
5c44784c JM |
686 | token pointer so that the range will be treated as a |
687 | single number. */ | |
688 | *pp = end_ptr; | |
689 | } | |
690 | else | |
691 | in_range = 1; | |
692 | } | |
693 | } | |
694 | else if (! in_range) | |
8a3fe4f8 | 695 | error (_("negative value")); |
5c44784c JM |
696 | else |
697 | { | |
698 | /* pp points to the '-' that betokens a range. All | |
699 | number-parsing has already been done. Return the next | |
700 | integer value (one greater than the saved previous value). | |
701 | Do not advance the token pointer 'pp' until the end of range | |
702 | is reached. */ | |
703 | ||
704 | if (++last_retval == end_value) | |
705 | { | |
706 | /* End of range reached; advance token pointer. */ | |
707 | *pp = end_ptr; | |
708 | in_range = 0; | |
709 | } | |
710 | } | |
711 | return last_retval; | |
712 | } | |
713 | ||
48cb2d85 VP |
714 | /* Return the breakpoint with the specified number, or NULL |
715 | if the number does not refer to an existing breakpoint. */ | |
716 | ||
717 | struct breakpoint * | |
718 | get_breakpoint (int num) | |
719 | { | |
720 | struct breakpoint *b; | |
721 | ||
722 | ALL_BREAKPOINTS (b) | |
723 | if (b->number == num) | |
724 | return b; | |
725 | ||
726 | return NULL; | |
727 | } | |
5c44784c | 728 | |
c906108c | 729 | \f |
adc36818 PM |
730 | |
731 | void | |
732 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
733 | int from_tty) | |
734 | { | |
735 | struct bp_location *loc = b->loc; | |
736 | ||
737 | for (; loc; loc = loc->next) | |
738 | { | |
739 | xfree (loc->cond); | |
740 | loc->cond = NULL; | |
741 | } | |
742 | xfree (b->cond_string); | |
743 | b->cond_string = NULL; | |
744 | xfree (b->cond_exp); | |
745 | b->cond_exp = NULL; | |
746 | ||
747 | if (*exp == 0) | |
748 | { | |
749 | if (from_tty) | |
750 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
751 | } | |
752 | else | |
753 | { | |
754 | char *arg = exp; | |
cc59ec59 | 755 | |
adc36818 PM |
756 | /* I don't know if it matters whether this is the string the user |
757 | typed in or the decompiled expression. */ | |
758 | b->cond_string = xstrdup (arg); | |
759 | b->condition_not_parsed = 0; | |
760 | ||
761 | if (is_watchpoint (b)) | |
762 | { | |
763 | innermost_block = NULL; | |
764 | arg = exp; | |
765 | b->cond_exp = parse_exp_1 (&arg, 0, 0); | |
766 | if (*arg) | |
767 | error (_("Junk at end of expression")); | |
768 | b->cond_exp_valid_block = innermost_block; | |
769 | } | |
770 | else | |
771 | { | |
772 | for (loc = b->loc; loc; loc = loc->next) | |
773 | { | |
774 | arg = exp; | |
775 | loc->cond = | |
776 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
777 | if (*arg) | |
778 | error (_("Junk at end of expression")); | |
779 | } | |
780 | } | |
781 | } | |
782 | breakpoints_changed (); | |
783 | observer_notify_breakpoint_modified (b->number); | |
784 | } | |
785 | ||
c906108c SS |
786 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
787 | ||
788 | static void | |
fba45db2 | 789 | condition_command (char *arg, int from_tty) |
c906108c | 790 | { |
52f0bd74 | 791 | struct breakpoint *b; |
c906108c | 792 | char *p; |
52f0bd74 | 793 | int bnum; |
c906108c SS |
794 | |
795 | if (arg == 0) | |
e2e0b3e5 | 796 | error_no_arg (_("breakpoint number")); |
c906108c SS |
797 | |
798 | p = arg; | |
799 | bnum = get_number (&p); | |
5c44784c | 800 | if (bnum == 0) |
8a3fe4f8 | 801 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
802 | |
803 | ALL_BREAKPOINTS (b) | |
804 | if (b->number == bnum) | |
2f069f6f | 805 | { |
2566ad2d | 806 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
807 | return; |
808 | } | |
c906108c | 809 | |
8a3fe4f8 | 810 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
811 | } |
812 | ||
a7bdde9e VP |
813 | /* Check that COMMAND do not contain commands that are suitable |
814 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
815 | Throw if any such commands is found. */ |
816 | ||
a7bdde9e VP |
817 | static void |
818 | check_no_tracepoint_commands (struct command_line *commands) | |
819 | { | |
820 | struct command_line *c; | |
cc59ec59 | 821 | |
a7bdde9e VP |
822 | for (c = commands; c; c = c->next) |
823 | { | |
824 | int i; | |
825 | ||
826 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
827 | error (_("The 'while-stepping' command can " |
828 | "only be used for tracepoints")); | |
a7bdde9e VP |
829 | |
830 | for (i = 0; i < c->body_count; ++i) | |
831 | check_no_tracepoint_commands ((c->body_list)[i]); | |
832 | ||
833 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 834 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
835 | command directly. */ |
836 | if (strstr (c->line, "collect ") == c->line) | |
837 | error (_("The 'collect' command can only be used for tracepoints")); | |
838 | ||
51661e93 VP |
839 | if (strstr (c->line, "teval ") == c->line) |
840 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
841 | } |
842 | } | |
843 | ||
d77f58be SS |
844 | /* Encapsulate tests for different types of tracepoints. */ |
845 | ||
a7bdde9e | 846 | int |
d77f58be | 847 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 848 | { |
0fb4aa4b PA |
849 | return (b->type == bp_tracepoint |
850 | || b->type == bp_fast_tracepoint | |
851 | || b->type == bp_static_tracepoint); | |
a7bdde9e | 852 | } |
d77f58be | 853 | |
95a42b64 TT |
854 | /* A helper function that validsates that COMMANDS are valid for a |
855 | breakpoint. This function will throw an exception if a problem is | |
856 | found. */ | |
48cb2d85 | 857 | |
95a42b64 TT |
858 | static void |
859 | validate_commands_for_breakpoint (struct breakpoint *b, | |
860 | struct command_line *commands) | |
48cb2d85 | 861 | { |
d77f58be | 862 | if (is_tracepoint (b)) |
a7bdde9e | 863 | { |
4a64f543 MS |
864 | /* We need to verify that each top-level element of commands is |
865 | valid for tracepoints, that there's at most one | |
866 | while-stepping element, and that while-stepping's body has | |
867 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
868 | struct command_line *c; |
869 | struct command_line *while_stepping = 0; | |
870 | for (c = commands; c; c = c->next) | |
871 | { | |
a7bdde9e VP |
872 | if (c->control_type == while_stepping_control) |
873 | { | |
874 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
875 | error (_("The 'while-stepping' command " |
876 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 877 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
878 | error (_("The 'while-stepping' command " |
879 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
880 | |
881 | if (while_stepping) | |
3e43a32a MS |
882 | error (_("The 'while-stepping' command " |
883 | "can be used only once")); | |
a7bdde9e VP |
884 | else |
885 | while_stepping = c; | |
886 | } | |
887 | } | |
888 | if (while_stepping) | |
889 | { | |
890 | struct command_line *c2; | |
891 | ||
892 | gdb_assert (while_stepping->body_count == 1); | |
893 | c2 = while_stepping->body_list[0]; | |
894 | for (; c2; c2 = c2->next) | |
895 | { | |
a7bdde9e VP |
896 | if (c2->control_type == while_stepping_control) |
897 | error (_("The 'while-stepping' command cannot be nested")); | |
898 | } | |
899 | } | |
900 | } | |
901 | else | |
902 | { | |
903 | check_no_tracepoint_commands (commands); | |
904 | } | |
95a42b64 TT |
905 | } |
906 | ||
0fb4aa4b PA |
907 | /* Return a vector of all the static tracepoints set at ADDR. The |
908 | caller is responsible for releasing the vector. */ | |
909 | ||
910 | VEC(breakpoint_p) * | |
911 | static_tracepoints_here (CORE_ADDR addr) | |
912 | { | |
913 | struct breakpoint *b; | |
914 | VEC(breakpoint_p) *found = 0; | |
915 | struct bp_location *loc; | |
916 | ||
917 | ALL_BREAKPOINTS (b) | |
918 | if (b->type == bp_static_tracepoint) | |
919 | { | |
920 | for (loc = b->loc; loc; loc = loc->next) | |
921 | if (loc->address == addr) | |
922 | VEC_safe_push(breakpoint_p, found, b); | |
923 | } | |
924 | ||
925 | return found; | |
926 | } | |
927 | ||
95a42b64 | 928 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 929 | validate that only allowed commands are included. */ |
95a42b64 TT |
930 | |
931 | void | |
4a64f543 MS |
932 | breakpoint_set_commands (struct breakpoint *b, |
933 | struct command_line *commands) | |
95a42b64 TT |
934 | { |
935 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 936 | |
9add0f1b TT |
937 | decref_counted_command_line (&b->commands); |
938 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
939 | breakpoints_changed (); |
940 | observer_notify_breakpoint_modified (b->number); | |
941 | } | |
942 | ||
45a43567 TT |
943 | /* Set the internal `silent' flag on the breakpoint. Note that this |
944 | is not the same as the "silent" that may appear in the breakpoint's | |
945 | commands. */ | |
946 | ||
947 | void | |
948 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
949 | { | |
950 | int old_silent = b->silent; | |
951 | ||
952 | b->silent = silent; | |
953 | if (old_silent != silent) | |
954 | observer_notify_breakpoint_modified (b->number); | |
955 | } | |
956 | ||
957 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
958 | breakpoint work for any thread. */ | |
959 | ||
960 | void | |
961 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
962 | { | |
963 | int old_thread = b->thread; | |
964 | ||
965 | b->thread = thread; | |
966 | if (old_thread != thread) | |
967 | observer_notify_breakpoint_modified (b->number); | |
968 | } | |
969 | ||
970 | /* Set the task for this breakpoint. If TASK is 0, make the | |
971 | breakpoint work for any task. */ | |
972 | ||
973 | void | |
974 | breakpoint_set_task (struct breakpoint *b, int task) | |
975 | { | |
976 | int old_task = b->task; | |
977 | ||
978 | b->task = task; | |
979 | if (old_task != task) | |
980 | observer_notify_breakpoint_modified (b->number); | |
981 | } | |
982 | ||
95a42b64 TT |
983 | void |
984 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
985 | { |
986 | struct breakpoint *b = closure; | |
cc59ec59 | 987 | |
a7bdde9e VP |
988 | validate_actionline (&line, b); |
989 | } | |
990 | ||
95a42b64 TT |
991 | /* A structure used to pass information through |
992 | map_breakpoint_numbers. */ | |
993 | ||
994 | struct commands_info | |
995 | { | |
996 | /* True if the command was typed at a tty. */ | |
997 | int from_tty; | |
86b17b60 PA |
998 | |
999 | /* The breakpoint range spec. */ | |
1000 | char *arg; | |
1001 | ||
95a42b64 TT |
1002 | /* Non-NULL if the body of the commands are being read from this |
1003 | already-parsed command. */ | |
1004 | struct command_line *control; | |
86b17b60 | 1005 | |
95a42b64 TT |
1006 | /* The command lines read from the user, or NULL if they have not |
1007 | yet been read. */ | |
1008 | struct counted_command_line *cmd; | |
1009 | }; | |
1010 | ||
1011 | /* A callback for map_breakpoint_numbers that sets the commands for | |
1012 | commands_command. */ | |
1013 | ||
c906108c | 1014 | static void |
95a42b64 | 1015 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 1016 | { |
95a42b64 | 1017 | struct commands_info *info = data; |
c906108c | 1018 | |
95a42b64 TT |
1019 | if (info->cmd == NULL) |
1020 | { | |
1021 | struct command_line *l; | |
5c44784c | 1022 | |
95a42b64 TT |
1023 | if (info->control != NULL) |
1024 | l = copy_command_lines (info->control->body_list[0]); | |
1025 | else | |
86b17b60 PA |
1026 | { |
1027 | struct cleanup *old_chain; | |
1028 | char *str; | |
c5aa993b | 1029 | |
3e43a32a MS |
1030 | str = xstrprintf (_("Type commands for breakpoint(s) " |
1031 | "%s, one per line."), | |
86b17b60 PA |
1032 | info->arg); |
1033 | ||
1034 | old_chain = make_cleanup (xfree, str); | |
1035 | ||
1036 | l = read_command_lines (str, | |
1037 | info->from_tty, 1, | |
d77f58be | 1038 | (is_tracepoint (b) |
86b17b60 PA |
1039 | ? check_tracepoint_command : 0), |
1040 | b); | |
1041 | ||
1042 | do_cleanups (old_chain); | |
1043 | } | |
a7bdde9e | 1044 | |
95a42b64 TT |
1045 | info->cmd = alloc_counted_command_line (l); |
1046 | } | |
1047 | ||
1048 | /* If a breakpoint was on the list more than once, we don't need to | |
1049 | do anything. */ | |
1050 | if (b->commands != info->cmd) | |
1051 | { | |
1052 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1053 | incref_counted_command_line (info->cmd); | |
1054 | decref_counted_command_line (&b->commands); | |
1055 | b->commands = info->cmd; | |
1056 | breakpoints_changed (); | |
1057 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 1058 | } |
95a42b64 TT |
1059 | } |
1060 | ||
1061 | static void | |
4a64f543 MS |
1062 | commands_command_1 (char *arg, int from_tty, |
1063 | struct command_line *control) | |
95a42b64 TT |
1064 | { |
1065 | struct cleanup *cleanups; | |
1066 | struct commands_info info; | |
1067 | ||
1068 | info.from_tty = from_tty; | |
1069 | info.control = control; | |
1070 | info.cmd = NULL; | |
1071 | /* If we read command lines from the user, then `info' will hold an | |
1072 | extra reference to the commands that we must clean up. */ | |
1073 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1074 | ||
1075 | if (arg == NULL || !*arg) | |
1076 | { | |
86b17b60 | 1077 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1078 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1079 | breakpoint_count); | |
95a42b64 TT |
1080 | else if (breakpoint_count > 0) |
1081 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1082 | else |
1083 | { | |
1084 | /* So that we don't try to free the incoming non-NULL | |
1085 | argument in the cleanup below. Mapping breakpoint | |
1086 | numbers will fail in this case. */ | |
1087 | arg = NULL; | |
1088 | } | |
95a42b64 | 1089 | } |
9766ced4 SS |
1090 | else |
1091 | /* The command loop has some static state, so we need to preserve | |
1092 | our argument. */ | |
1093 | arg = xstrdup (arg); | |
86b17b60 PA |
1094 | |
1095 | if (arg != NULL) | |
1096 | make_cleanup (xfree, arg); | |
1097 | ||
1098 | info.arg = arg; | |
95a42b64 TT |
1099 | |
1100 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1101 | ||
1102 | if (info.cmd == NULL) | |
1103 | error (_("No breakpoints specified.")); | |
1104 | ||
1105 | do_cleanups (cleanups); | |
1106 | } | |
1107 | ||
1108 | static void | |
1109 | commands_command (char *arg, int from_tty) | |
1110 | { | |
1111 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1112 | } |
40c03ae8 EZ |
1113 | |
1114 | /* Like commands_command, but instead of reading the commands from | |
1115 | input stream, takes them from an already parsed command structure. | |
1116 | ||
1117 | This is used by cli-script.c to DTRT with breakpoint commands | |
1118 | that are part of if and while bodies. */ | |
1119 | enum command_control_type | |
1120 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1121 | { | |
95a42b64 TT |
1122 | commands_command_1 (arg, 0, cmd); |
1123 | return simple_control; | |
40c03ae8 | 1124 | } |
876fa593 JK |
1125 | |
1126 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1127 | ||
1128 | static int | |
1129 | bp_location_has_shadow (struct bp_location *bl) | |
1130 | { | |
1131 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1132 | return 0; | |
1133 | if (!bl->inserted) | |
1134 | return 0; | |
1135 | if (bl->target_info.shadow_len == 0) | |
1136 | /* bp isn't valid, or doesn't shadow memory. */ | |
1137 | return 0; | |
1138 | return 1; | |
1139 | } | |
1140 | ||
8defab1a | 1141 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1142 | by replacing any memory breakpoints with their shadowed contents. |
1143 | ||
1144 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1145 | bl->address - bp_location_placed_address_before_address_max |
1146 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1147 | The range we were requested to resolve shadows for is: |
1148 | memaddr ... memaddr + len | |
1149 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1150 | memaddr + len <= (bl->address |
1151 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1152 | and: |
35df4500 | 1153 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1154 | |
8defab1a DJ |
1155 | void |
1156 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1157 | { |
4a64f543 MS |
1158 | /* Left boundary, right boundary and median element of our binary |
1159 | search. */ | |
876fa593 JK |
1160 | unsigned bc_l, bc_r, bc; |
1161 | ||
4a64f543 MS |
1162 | /* Find BC_L which is a leftmost element which may affect BUF |
1163 | content. It is safe to report lower value but a failure to | |
1164 | report higher one. */ | |
876fa593 JK |
1165 | |
1166 | bc_l = 0; | |
1167 | bc_r = bp_location_count; | |
1168 | while (bc_l + 1 < bc_r) | |
1169 | { | |
35df4500 | 1170 | struct bp_location *bl; |
876fa593 JK |
1171 | |
1172 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1173 | bl = bp_location[bc]; |
876fa593 | 1174 | |
4a64f543 MS |
1175 | /* Check first BL->ADDRESS will not overflow due to the added |
1176 | constant. Then advance the left boundary only if we are sure | |
1177 | the BC element can in no way affect the BUF content (MEMADDR | |
1178 | to MEMADDR + LEN range). | |
876fa593 | 1179 | |
4a64f543 MS |
1180 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1181 | offset so that we cannot miss a breakpoint with its shadow | |
1182 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1183 | |
35df4500 TJB |
1184 | if ((bl->address + bp_location_shadow_len_after_address_max |
1185 | >= bl->address) | |
1186 | && (bl->address + bp_location_shadow_len_after_address_max | |
1187 | <= memaddr)) | |
876fa593 JK |
1188 | bc_l = bc; |
1189 | else | |
1190 | bc_r = bc; | |
1191 | } | |
1192 | ||
128070bb PA |
1193 | /* Due to the binary search above, we need to make sure we pick the |
1194 | first location that's at BC_L's address. E.g., if there are | |
1195 | multiple locations at the same address, BC_L may end up pointing | |
1196 | at a duplicate location, and miss the "master"/"inserted" | |
1197 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1198 | B: | |
1199 | ||
1200 | L1@A, L2@A, L3@B, ... | |
1201 | ||
1202 | BC_L could end up pointing at location L2, while the "master" | |
1203 | location could be L1. Since the `loc->inserted' flag is only set | |
1204 | on "master" locations, we'd forget to restore the shadow of L1 | |
1205 | and L2. */ | |
1206 | while (bc_l > 0 | |
1207 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1208 | bc_l--; | |
1209 | ||
876fa593 JK |
1210 | /* Now do full processing of the found relevant range of elements. */ |
1211 | ||
1212 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1213 | { |
35df4500 | 1214 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1215 | CORE_ADDR bp_addr = 0; |
1216 | int bp_size = 0; | |
1217 | int bptoffset = 0; | |
1218 | ||
35df4500 TJB |
1219 | /* bp_location array has BL->OWNER always non-NULL. */ |
1220 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1221 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1222 | bl->owner->number); |
ffce0d52 | 1223 | |
876fa593 JK |
1224 | /* Performance optimization: any futher element can no longer affect BUF |
1225 | content. */ | |
1226 | ||
35df4500 TJB |
1227 | if (bl->address >= bp_location_placed_address_before_address_max |
1228 | && memaddr + len <= (bl->address | |
1229 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1230 | break; |
1231 | ||
35df4500 | 1232 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1233 | continue; |
35df4500 | 1234 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1235 | current_program_space->aspace, 0)) |
1236 | continue; | |
1237 | ||
c5aa993b JM |
1238 | /* Addresses and length of the part of the breakpoint that |
1239 | we need to copy. */ | |
35df4500 TJB |
1240 | bp_addr = bl->target_info.placed_address; |
1241 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1242 | |
c5aa993b JM |
1243 | if (bp_addr + bp_size <= memaddr) |
1244 | /* The breakpoint is entirely before the chunk of memory we | |
1245 | are reading. */ | |
1246 | continue; | |
8defab1a | 1247 | |
c5aa993b JM |
1248 | if (bp_addr >= memaddr + len) |
1249 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1250 | reading. */ |
c5aa993b | 1251 | continue; |
c5aa993b | 1252 | |
8defab1a DJ |
1253 | /* Offset within shadow_contents. */ |
1254 | if (bp_addr < memaddr) | |
1255 | { | |
1256 | /* Only copy the second part of the breakpoint. */ | |
1257 | bp_size -= memaddr - bp_addr; | |
1258 | bptoffset = memaddr - bp_addr; | |
1259 | bp_addr = memaddr; | |
1260 | } | |
c5aa993b | 1261 | |
8defab1a DJ |
1262 | if (bp_addr + bp_size > memaddr + len) |
1263 | { | |
1264 | /* Only copy the first part of the breakpoint. */ | |
1265 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1266 | } | |
c5aa993b | 1267 | |
8defab1a | 1268 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1269 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1270 | } |
c906108c | 1271 | } |
c906108c | 1272 | \f |
c5aa993b | 1273 | |
60e1c644 PA |
1274 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1275 | ||
a5606eee | 1276 | static int |
d77f58be | 1277 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1278 | { |
1279 | return (bpt->type == bp_hardware_watchpoint | |
1280 | || bpt->type == bp_read_watchpoint | |
1281 | || bpt->type == bp_access_watchpoint); | |
1282 | } | |
7270d8f2 | 1283 | |
60e1c644 PA |
1284 | /* Return true if BPT is of any watchpoint kind, hardware or |
1285 | software. */ | |
1286 | ||
1287 | static int | |
d77f58be | 1288 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1289 | { |
1290 | return (is_hardware_watchpoint (bpt) | |
1291 | || bpt->type == bp_watchpoint); | |
1292 | } | |
1293 | ||
f6bc2008 PA |
1294 | /* Assuming that B is a watchpoint: returns true if the current thread |
1295 | and its running state are safe to evaluate or update watchpoint B. | |
1296 | Watchpoints on local expressions need to be evaluated in the | |
1297 | context of the thread that was current when the watchpoint was | |
1298 | created, and, that thread needs to be stopped to be able to select | |
1299 | the correct frame context. Watchpoints on global expressions can | |
1300 | be evaluated on any thread, and in any state. It is presently left | |
1301 | to the target allowing memory accesses when threads are | |
1302 | running. */ | |
1303 | ||
1304 | static int | |
1305 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1306 | { | |
1307 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1308 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1309 | && !is_executing (inferior_ptid))); | |
1310 | } | |
1311 | ||
567e1b4e JB |
1312 | /* Assuming that B is a watchpoint: |
1313 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1314 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1315 | - Evaluate the condition if there is one, and store the result |
1316 | in b->loc->cond. | |
a5606eee VP |
1317 | - Update the list of values that must be watched in B->loc. |
1318 | ||
4a64f543 MS |
1319 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1320 | nothing. If this is local watchpoint that is out of scope, delete | |
1321 | it. | |
1322 | ||
1323 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1324 | removed + inserted on each stop here. Normal breakpoints must | |
1325 | never be removed because they might be missed by a running thread | |
1326 | when debugging in non-stop mode. On the other hand, hardware | |
1327 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1328 | to each LWP since they are stored in each LWP's hardware debug | |
1329 | registers. Therefore, such LWP must be stopped first in order to | |
1330 | be able to modify its hardware watchpoints. | |
1331 | ||
1332 | Hardware watchpoints must be reset exactly once after being | |
1333 | presented to the user. It cannot be done sooner, because it would | |
1334 | reset the data used to present the watchpoint hit to the user. And | |
1335 | it must not be done later because it could display the same single | |
1336 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1337 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1338 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1339 | not user-visible - its hit is suppressed if the memory content has | |
1340 | not changed. | |
1341 | ||
1342 | The following constraints influence the location where we can reset | |
1343 | hardware watchpoints: | |
1344 | ||
1345 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1346 | called several times when GDB stops. | |
1347 | ||
1348 | [linux] | |
1349 | * Multiple hardware watchpoints can be hit at the same time, | |
1350 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1351 | hit at a time as the reason for stopping, and all the other hits | |
1352 | are presented later, one after the other, each time the user | |
1353 | requests the execution to be resumed. Execution is not resumed | |
1354 | for the threads still having pending hit event stored in | |
1355 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1356 | the inferior on the first stop the thread hit event is kept being | |
1357 | reported from its cached value by linux_nat_stopped_data_address | |
1358 | until the real thread resume happens after the watchpoint gets | |
1359 | presented and thus its LWP_INFO->STATUS gets reset. | |
1360 | ||
1361 | Therefore the hardware watchpoint hit can get safely reset on the | |
1362 | watchpoint removal from inferior. */ | |
a79d3c27 | 1363 | |
b40ce68a | 1364 | static void |
a5606eee | 1365 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1366 | { |
a5606eee | 1367 | int within_current_scope; |
a5606eee | 1368 | struct frame_id saved_frame_id; |
66076460 | 1369 | int frame_saved; |
a5606eee | 1370 | |
f6bc2008 PA |
1371 | /* If this is a local watchpoint, we only want to check if the |
1372 | watchpoint frame is in scope if the current thread is the thread | |
1373 | that was used to create the watchpoint. */ | |
1374 | if (!watchpoint_in_thread_scope (b)) | |
1375 | return; | |
1376 | ||
a3be7890 TJB |
1377 | /* We don't free locations. They are stored in the bp_location array |
1378 | and update_global_location_list will eventually delete them and | |
4a64f543 | 1379 | remove breakpoints if needed. */ |
a5606eee VP |
1380 | b->loc = NULL; |
1381 | ||
1382 | if (b->disposition == disp_del_at_next_stop) | |
1383 | return; | |
1384 | ||
66076460 | 1385 | frame_saved = 0; |
a5606eee VP |
1386 | |
1387 | /* Determine if the watchpoint is within scope. */ | |
1388 | if (b->exp_valid_block == NULL) | |
1389 | within_current_scope = 1; | |
1390 | else | |
1391 | { | |
1392 | struct frame_info *fi; | |
66076460 DJ |
1393 | |
1394 | /* Save the current frame's ID so we can restore it after | |
1395 | evaluating the watchpoint expression on its own frame. */ | |
1396 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1397 | took a frame parameter, so that we didn't have to change the | |
1398 | selected frame. */ | |
1399 | frame_saved = 1; | |
1400 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1401 | ||
a5606eee VP |
1402 | fi = frame_find_by_id (b->watchpoint_frame); |
1403 | within_current_scope = (fi != NULL); | |
1404 | if (within_current_scope) | |
1405 | select_frame (fi); | |
1406 | } | |
1407 | ||
1408 | if (within_current_scope && reparse) | |
1409 | { | |
1410 | char *s; | |
d63d0675 | 1411 | |
a5606eee VP |
1412 | if (b->exp) |
1413 | { | |
1414 | xfree (b->exp); | |
1415 | b->exp = NULL; | |
1416 | } | |
d63d0675 | 1417 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1418 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1419 | /* If the meaning of expression itself changed, the old value is | |
1420 | no longer relevant. We don't want to report a watchpoint hit | |
1421 | to the user when the old value and the new value may actually | |
1422 | be completely different objects. */ | |
1423 | value_free (b->val); | |
fa4727a6 DJ |
1424 | b->val = NULL; |
1425 | b->val_valid = 0; | |
60e1c644 PA |
1426 | |
1427 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1428 | expression is stored in the breakpoint object, not in the | |
1429 | locations (re)created below. */ | |
1430 | if (b->cond_string != NULL) | |
1431 | { | |
1432 | if (b->cond_exp != NULL) | |
1433 | { | |
1434 | xfree (b->cond_exp); | |
1435 | b->cond_exp = NULL; | |
1436 | } | |
1437 | ||
1438 | s = b->cond_string; | |
1439 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1440 | } | |
a5606eee | 1441 | } |
a5606eee VP |
1442 | |
1443 | /* If we failed to parse the expression, for example because | |
1444 | it refers to a global variable in a not-yet-loaded shared library, | |
1445 | don't try to insert watchpoint. We don't automatically delete | |
1446 | such watchpoint, though, since failure to parse expression | |
1447 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1448 | if ( !target_has_execution) |
1449 | { | |
1450 | /* Without execution, memory can't change. No use to try and | |
1451 | set watchpoint locations. The watchpoint will be reset when | |
1452 | the target gains execution, through breakpoint_re_set. */ | |
1453 | } | |
1454 | else if (within_current_scope && b->exp) | |
a5606eee | 1455 | { |
0cf6dd15 | 1456 | int pc = 0; |
fa4727a6 | 1457 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1458 | struct program_space *frame_pspace; |
a5606eee | 1459 | |
0cf6dd15 | 1460 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1461 | |
a5606eee VP |
1462 | /* Avoid setting b->val if it's already set. The meaning of |
1463 | b->val is 'the last value' user saw, and we should update | |
1464 | it only if we reported that last value to user. As it | |
1465 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1466 | if (!b->val_valid) |
1467 | { | |
1468 | b->val = v; | |
1469 | b->val_valid = 1; | |
1470 | } | |
a5606eee | 1471 | |
2d134ed3 PA |
1472 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1473 | ||
a5606eee | 1474 | /* Look at each value on the value chain. */ |
9fa40276 | 1475 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1476 | { |
1477 | /* If it's a memory location, and GDB actually needed | |
1478 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1479 | must watch it. If the first value returned is |
1480 | still lazy, that means an error occurred reading it; | |
1481 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1482 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1483 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1484 | { |
1485 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1486 | |
a5606eee VP |
1487 | /* We only watch structs and arrays if user asked |
1488 | for it explicitly, never if they just happen to | |
1489 | appear in the middle of some value chain. */ | |
fa4727a6 | 1490 | if (v == result |
a5606eee VP |
1491 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1492 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1493 | { | |
1494 | CORE_ADDR addr; | |
1495 | int len, type; | |
1496 | struct bp_location *loc, **tmp; | |
1497 | ||
42ae5230 | 1498 | addr = value_address (v); |
a5606eee VP |
1499 | len = TYPE_LENGTH (value_type (v)); |
1500 | type = hw_write; | |
1501 | if (b->type == bp_read_watchpoint) | |
1502 | type = hw_read; | |
1503 | else if (b->type == bp_access_watchpoint) | |
1504 | type = hw_access; | |
1505 | ||
39d61571 | 1506 | loc = allocate_bp_location (b); |
a5606eee VP |
1507 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1508 | ; | |
1509 | *tmp = loc; | |
a6d9a66e | 1510 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1511 | |
1512 | loc->pspace = frame_pspace; | |
a5606eee VP |
1513 | loc->address = addr; |
1514 | loc->length = len; | |
1515 | loc->watchpoint_type = type; | |
1516 | } | |
1517 | } | |
9fa40276 TJB |
1518 | } |
1519 | ||
1520 | /* Change the type of breakpoint between hardware assisted or | |
1521 | an ordinary watchpoint depending on the hardware support | |
1522 | and free hardware slots. REPARSE is set when the inferior | |
1523 | is started. */ | |
1524 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1525 | && reparse) | |
1526 | { | |
e09342b5 | 1527 | int reg_cnt; |
9fa40276 TJB |
1528 | enum bp_loc_type loc_type; |
1529 | struct bp_location *bl; | |
a5606eee | 1530 | |
e09342b5 TJB |
1531 | reg_cnt = can_use_hardware_watchpoint (val_chain, b->exact); |
1532 | ||
1533 | if (reg_cnt) | |
9fa40276 TJB |
1534 | { |
1535 | int i, target_resources_ok, other_type_used; | |
e09342b5 | 1536 | enum enable_state orig_enable_state; |
9fa40276 TJB |
1537 | |
1538 | /* We need to determine how many resources are already | |
e09342b5 TJB |
1539 | used for all other hardware watchpoints plus this one |
1540 | to see if we still have enough resources to also fit | |
1541 | this watchpoint in as well. To guarantee the | |
1542 | hw_watchpoint_used_count call below counts this | |
1543 | watchpoint, make sure that it is marked as a hardware | |
1544 | watchpoint. */ | |
1545 | b->type = bp_hardware_watchpoint; | |
1546 | ||
1547 | /* hw_watchpoint_used_count ignores disabled watchpoints, | |
1548 | and b might be disabled if we're being called from | |
1549 | do_enable_breakpoint. */ | |
1550 | orig_enable_state = b->enable_state; | |
1551 | b->enable_state = bp_enabled; | |
1552 | ||
9fa40276 TJB |
1553 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1554 | &other_type_used); | |
9fa40276 | 1555 | |
e09342b5 TJB |
1556 | b->enable_state = orig_enable_state; |
1557 | ||
1558 | target_resources_ok = target_can_use_hardware_watchpoint | |
1559 | (bp_hardware_watchpoint, i, other_type_used); | |
1560 | if (target_resources_ok <= 0) | |
1561 | b->type = bp_watchpoint; | |
9fa40276 TJB |
1562 | } |
1563 | else | |
1564 | b->type = bp_watchpoint; | |
1565 | ||
1566 | loc_type = (b->type == bp_watchpoint? bp_loc_other | |
1567 | : bp_loc_hardware_watchpoint); | |
1568 | for (bl = b->loc; bl; bl = bl->next) | |
1569 | bl->loc_type = loc_type; | |
1570 | } | |
1571 | ||
1572 | for (v = val_chain; v; v = next) | |
1573 | { | |
a5606eee VP |
1574 | next = value_next (v); |
1575 | if (v != b->val) | |
1576 | value_free (v); | |
1577 | } | |
1578 | ||
c7437ca6 PA |
1579 | /* If a software watchpoint is not watching any memory, then the |
1580 | above left it without any location set up. But, | |
1581 | bpstat_stop_status requires a location to be able to report | |
1582 | stops, so make sure there's at least a dummy one. */ | |
1583 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1584 | { | |
1585 | b->loc = allocate_bp_location (b); | |
1586 | b->loc->pspace = frame_pspace; | |
1587 | b->loc->address = -1; | |
1588 | b->loc->length = -1; | |
1589 | b->loc->watchpoint_type = -1; | |
1590 | } | |
a5606eee VP |
1591 | } |
1592 | else if (!within_current_scope) | |
7270d8f2 | 1593 | { |
ac74f770 MS |
1594 | printf_filtered (_("\ |
1595 | Watchpoint %d deleted because the program has left the block\n\ | |
1596 | in which its expression is valid.\n"), | |
a5606eee VP |
1597 | b->number); |
1598 | if (b->related_breakpoint) | |
60e1c644 PA |
1599 | { |
1600 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1601 | b->related_breakpoint->related_breakpoint = NULL; | |
1602 | b->related_breakpoint= NULL; | |
1603 | } | |
a5606eee | 1604 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1605 | } |
a5606eee VP |
1606 | |
1607 | /* Restore the selected frame. */ | |
66076460 DJ |
1608 | if (frame_saved) |
1609 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1610 | } |
1611 | ||
a5606eee | 1612 | |
74960c60 VP |
1613 | /* Returns 1 iff breakpoint location should be |
1614 | inserted in the inferior. */ | |
1615 | static int | |
35df4500 | 1616 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1617 | { |
35df4500 | 1618 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1619 | return 0; |
1620 | ||
35df4500 | 1621 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1622 | return 0; |
1623 | ||
35df4500 | 1624 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1625 | return 0; |
1626 | ||
56710373 PA |
1627 | /* This is set for example, when we're attached to the parent of a |
1628 | vfork, and have detached from the child. The child is running | |
1629 | free, and we expect it to do an exec or exit, at which point the | |
1630 | OS makes the parent schedulable again (and the target reports | |
1631 | that the vfork is done). Until the child is done with the shared | |
1632 | memory region, do not insert breakpoints in the parent, otherwise | |
1633 | the child could still trip on the parent's breakpoints. Since | |
1634 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1635 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1636 | return 0; |
1637 | ||
1042e4c0 SS |
1638 | /* Tracepoints are inserted by the target at a time of its choosing, |
1639 | not by us. */ | |
35df4500 | 1640 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1641 | return 0; |
1642 | ||
74960c60 VP |
1643 | return 1; |
1644 | } | |
1645 | ||
35df4500 TJB |
1646 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1647 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
1648 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. | |
879bfdc2 | 1649 | |
4a64f543 MS |
1650 | NOTE drow/2003-09-09: This routine could be broken down to an |
1651 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1652 | static int |
35df4500 | 1653 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1654 | struct ui_file *tmp_error_stream, |
fa3a767f | 1655 | int *disabled_breaks, |
26bb91f3 | 1656 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1657 | { |
1658 | int val = 0; | |
1659 | ||
35df4500 | 1660 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1661 | return 0; |
1662 | ||
8181d85f | 1663 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1664 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1665 | bl->target_info.placed_address = bl->address; | |
1666 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
8181d85f | 1667 | |
35df4500 TJB |
1668 | if (bl->loc_type == bp_loc_software_breakpoint |
1669 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1670 | { |
35df4500 | 1671 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1672 | { |
1673 | /* If the explicitly specified breakpoint type | |
1674 | is not hardware breakpoint, check the memory map to see | |
1675 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1676 | |
765dc015 VP |
1677 | Two important cases are: |
1678 | - location type is not hardware breakpoint, memory | |
1679 | is readonly. We change the type of the location to | |
1680 | hardware breakpoint. | |
4a64f543 MS |
1681 | - location type is hardware breakpoint, memory is |
1682 | read-write. This means we've previously made the | |
1683 | location hardware one, but then the memory map changed, | |
1684 | so we undo. | |
765dc015 | 1685 | |
4a64f543 MS |
1686 | When breakpoints are removed, remove_breakpoints will use |
1687 | location types we've just set here, the only possible | |
1688 | problem is that memory map has changed during running | |
1689 | program, but it's not going to work anyway with current | |
1690 | gdb. */ | |
765dc015 | 1691 | struct mem_region *mr |
35df4500 | 1692 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1693 | |
1694 | if (mr) | |
1695 | { | |
1696 | if (automatic_hardware_breakpoints) | |
1697 | { | |
765dc015 VP |
1698 | enum bp_loc_type new_type; |
1699 | ||
1700 | if (mr->attrib.mode != MEM_RW) | |
1701 | new_type = bp_loc_hardware_breakpoint; | |
1702 | else | |
1703 | new_type = bp_loc_software_breakpoint; | |
1704 | ||
35df4500 | 1705 | if (new_type != bl->loc_type) |
765dc015 VP |
1706 | { |
1707 | static int said = 0; | |
cc59ec59 | 1708 | |
35df4500 | 1709 | bl->loc_type = new_type; |
765dc015 VP |
1710 | if (!said) |
1711 | { | |
3e43a32a MS |
1712 | fprintf_filtered (gdb_stdout, |
1713 | _("Note: automatically using " | |
1714 | "hardware breakpoints for " | |
1715 | "read-only addresses.\n")); | |
765dc015 VP |
1716 | said = 1; |
1717 | } | |
1718 | } | |
1719 | } | |
35df4500 | 1720 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1721 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1722 | warning (_("cannot set software breakpoint " |
1723 | "at readonly address %s"), | |
35df4500 | 1724 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1725 | } |
1726 | } | |
1727 | ||
879bfdc2 DJ |
1728 | /* First check to see if we have to handle an overlay. */ |
1729 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1730 | || bl->section == NULL |
1731 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1732 | { |
1733 | /* No overlay handling: just set the breakpoint. */ | |
1734 | ||
35df4500 TJB |
1735 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1736 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1737 | &bl->target_info); | |
879bfdc2 | 1738 | else |
35df4500 TJB |
1739 | val = target_insert_breakpoint (bl->gdbarch, |
1740 | &bl->target_info); | |
879bfdc2 DJ |
1741 | } |
1742 | else | |
1743 | { | |
4a64f543 | 1744 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1745 | Shall we set a breakpoint at the LMA? */ |
1746 | if (!overlay_events_enabled) | |
1747 | { | |
1748 | /* Yes -- overlay event support is not active, | |
1749 | so we must try to set a breakpoint at the LMA. | |
1750 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1751 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1752 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1753 | bl->owner->number); |
879bfdc2 DJ |
1754 | else |
1755 | { | |
35df4500 TJB |
1756 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1757 | bl->section); | |
879bfdc2 | 1758 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1759 | bl->overlay_target_info = bl->target_info; |
1760 | bl->overlay_target_info.placed_address = addr; | |
1761 | val = target_insert_breakpoint (bl->gdbarch, | |
1762 | &bl->overlay_target_info); | |
879bfdc2 | 1763 | if (val != 0) |
99361f52 | 1764 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1765 | "Overlay breakpoint %d " |
1766 | "failed: in ROM?\n", | |
35df4500 | 1767 | bl->owner->number); |
879bfdc2 DJ |
1768 | } |
1769 | } | |
1770 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1771 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1772 | { |
1773 | /* Yes. This overlay section is mapped into memory. */ | |
35df4500 TJB |
1774 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1775 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1776 | &bl->target_info); | |
879bfdc2 | 1777 | else |
35df4500 TJB |
1778 | val = target_insert_breakpoint (bl->gdbarch, |
1779 | &bl->target_info); | |
879bfdc2 DJ |
1780 | } |
1781 | else | |
1782 | { | |
1783 | /* No. This breakpoint will not be inserted. | |
1784 | No error, but do not mark the bp as 'inserted'. */ | |
1785 | return 0; | |
1786 | } | |
1787 | } | |
1788 | ||
1789 | if (val) | |
1790 | { | |
1791 | /* Can't set the breakpoint. */ | |
35df4500 | 1792 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1793 | { |
4a64f543 | 1794 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1795 | val = 0; |
35df4500 | 1796 | bl->shlib_disabled = 1; |
879bfdc2 DJ |
1797 | if (!*disabled_breaks) |
1798 | { | |
1799 | fprintf_unfiltered (tmp_error_stream, | |
1800 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1801 | bl->owner->number); |
879bfdc2 | 1802 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1803 | "Temporarily disabling shared " |
1804 | "library breakpoints:\n"); | |
879bfdc2 DJ |
1805 | } |
1806 | *disabled_breaks = 1; | |
1807 | fprintf_unfiltered (tmp_error_stream, | |
35df4500 | 1808 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1809 | } |
1810 | else | |
879bfdc2 | 1811 | { |
35df4500 | 1812 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1813 | { |
1814 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1815 | fprintf_unfiltered (tmp_error_stream, |
1816 | "Cannot insert hardware " | |
1817 | "breakpoint %d.\n", | |
35df4500 | 1818 | bl->owner->number); |
879bfdc2 DJ |
1819 | } |
1820 | else | |
1821 | { | |
1822 | fprintf_unfiltered (tmp_error_stream, | |
1823 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1824 | bl->owner->number); |
879bfdc2 DJ |
1825 | fprintf_filtered (tmp_error_stream, |
1826 | "Error accessing memory address "); | |
35df4500 | 1827 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1828 | tmp_error_stream); |
879bfdc2 DJ |
1829 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1830 | safe_strerror (val)); | |
1831 | } | |
1832 | ||
1833 | } | |
1834 | } | |
1835 | else | |
35df4500 | 1836 | bl->inserted = 1; |
879bfdc2 DJ |
1837 | |
1838 | return val; | |
1839 | } | |
1840 | ||
35df4500 | 1841 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1842 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1843 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1844 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1845 | { |
77b06cd7 TJB |
1846 | gdb_assert (bl->owner->ops != NULL |
1847 | && bl->owner->ops->insert_location != NULL); | |
1848 | ||
1849 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1850 | |
1851 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1852 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1853 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1854 | { |
1855 | struct bp_location *loc, **loc_temp; | |
1856 | ||
1857 | /* But don't try to insert it, if there's already another | |
1858 | hw_access location that would be considered a duplicate | |
1859 | of this one. */ | |
1860 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1861 | if (loc != bl |
85d721b8 | 1862 | && loc->watchpoint_type == hw_access |
35df4500 | 1863 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1864 | { |
35df4500 TJB |
1865 | bl->duplicate = 1; |
1866 | bl->inserted = 1; | |
1867 | bl->target_info = loc->target_info; | |
1868 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1869 | val = 0; |
1870 | break; | |
1871 | } | |
1872 | ||
1873 | if (val == 1) | |
1874 | { | |
77b06cd7 TJB |
1875 | bl->watchpoint_type = hw_access; |
1876 | val = bl->owner->ops->insert_location (bl); | |
1877 | ||
1878 | if (val) | |
1879 | /* Back to the original value. */ | |
1880 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1881 | } |
1882 | } | |
1883 | ||
35df4500 | 1884 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1885 | } |
1886 | ||
35df4500 | 1887 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1888 | { |
77b06cd7 TJB |
1889 | gdb_assert (bl->owner->ops != NULL |
1890 | && bl->owner->ops->insert_location != NULL); | |
1891 | ||
1892 | val = bl->owner->ops->insert_location (bl); | |
1893 | if (val) | |
1894 | { | |
1895 | bl->owner->enable_state = bp_disabled; | |
1896 | ||
1897 | if (val == 1) | |
1898 | warning (_("\ | |
1899 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1900 | of catchpoint."), bl->owner->number); | |
1901 | else | |
1902 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1903 | } | |
1904 | ||
1905 | bl->inserted = (val == 0); | |
1640b821 DJ |
1906 | |
1907 | /* We've already printed an error message if there was a problem | |
1908 | inserting this catchpoint, and we've disabled the catchpoint, | |
1909 | so just return success. */ | |
1910 | return 0; | |
879bfdc2 DJ |
1911 | } |
1912 | ||
1913 | return 0; | |
1914 | } | |
1915 | ||
6c95b8df PA |
1916 | /* This function is called when program space PSPACE is about to be |
1917 | deleted. It takes care of updating breakpoints to not reference | |
1918 | PSPACE anymore. */ | |
1919 | ||
1920 | void | |
1921 | breakpoint_program_space_exit (struct program_space *pspace) | |
1922 | { | |
1923 | struct breakpoint *b, *b_temp; | |
876fa593 | 1924 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1925 | |
1926 | /* Remove any breakpoint that was set through this program space. */ | |
1927 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1928 | { | |
1929 | if (b->pspace == pspace) | |
1930 | delete_breakpoint (b); | |
1931 | } | |
1932 | ||
1933 | /* Breakpoints set through other program spaces could have locations | |
1934 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1935 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1936 | { |
1937 | struct bp_location *tmp; | |
1938 | ||
1939 | if (loc->pspace == pspace) | |
1940 | { | |
2bdf28a0 | 1941 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1942 | if (loc->owner->loc == loc) |
1943 | loc->owner->loc = loc->next; | |
1944 | else | |
1945 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1946 | if (tmp->next == loc) | |
1947 | { | |
1948 | tmp->next = loc->next; | |
1949 | break; | |
1950 | } | |
1951 | } | |
1952 | } | |
1953 | ||
1954 | /* Now update the global location list to permanently delete the | |
1955 | removed locations above. */ | |
1956 | update_global_location_list (0); | |
1957 | } | |
1958 | ||
74960c60 VP |
1959 | /* Make sure all breakpoints are inserted in inferior. |
1960 | Throws exception on any error. | |
1961 | A breakpoint that is already inserted won't be inserted | |
1962 | again, so calling this function twice is safe. */ | |
1963 | void | |
1964 | insert_breakpoints (void) | |
1965 | { | |
1966 | struct breakpoint *bpt; | |
1967 | ||
1968 | ALL_BREAKPOINTS (bpt) | |
1969 | if (is_hardware_watchpoint (bpt)) | |
4a64f543 | 1970 | update_watchpoint (bpt, 0 /* don't reparse. */); |
74960c60 | 1971 | |
b60e7edf | 1972 | update_global_location_list (1); |
74960c60 | 1973 | |
c35b1492 PA |
1974 | /* update_global_location_list does not insert breakpoints when |
1975 | always_inserted_mode is not enabled. Explicitly insert them | |
1976 | now. */ | |
1977 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1978 | insert_breakpoint_locations (); |
1979 | } | |
1980 | ||
c906108c SS |
1981 | /* insert_breakpoints is used when starting or continuing the program. |
1982 | remove_breakpoints is used when the program stops. | |
1983 | Both return zero if successful, | |
1984 | or an `errno' value if could not write the inferior. */ | |
1985 | ||
74960c60 VP |
1986 | static void |
1987 | insert_breakpoint_locations (void) | |
c906108c | 1988 | { |
a5606eee | 1989 | struct breakpoint *bpt; |
35df4500 | 1990 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1991 | int error = 0; |
c906108c SS |
1992 | int val = 0; |
1993 | int disabled_breaks = 0; | |
81d0cc19 | 1994 | int hw_breakpoint_error = 0; |
c906108c | 1995 | |
81d0cc19 | 1996 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1997 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1998 | |
81d0cc19 GS |
1999 | /* Explicitly mark the warning -- this will only be printed if |
2000 | there was an error. */ | |
2001 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
2002 | |
2003 | save_current_space_and_thread (); | |
2004 | ||
35df4500 | 2005 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 2006 | { |
35df4500 | 2007 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
2008 | continue; |
2009 | ||
4a64f543 MS |
2010 | /* There is no point inserting thread-specific breakpoints if |
2011 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
2012 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
2013 | if (bl->owner->thread != -1 |
2014 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
2015 | continue; |
2016 | ||
35df4500 | 2017 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
2018 | |
2019 | /* For targets that support global breakpoints, there's no need | |
2020 | to select an inferior to insert breakpoint to. In fact, even | |
2021 | if we aren't attached to any process yet, we should still | |
2022 | insert breakpoints. */ | |
2023 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
2024 | && ptid_equal (inferior_ptid, null_ptid)) | |
2025 | continue; | |
2026 | ||
35df4500 | 2027 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
879bfdc2 DJ |
2028 | &hw_breakpoint_error); |
2029 | if (val) | |
e236ba44 | 2030 | error = val; |
879bfdc2 | 2031 | } |
c906108c | 2032 | |
4a64f543 MS |
2033 | /* If we failed to insert all locations of a watchpoint, remove |
2034 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
2035 | ALL_BREAKPOINTS (bpt) |
2036 | { | |
2037 | int some_failed = 0; | |
2038 | struct bp_location *loc; | |
2039 | ||
2040 | if (!is_hardware_watchpoint (bpt)) | |
2041 | continue; | |
2042 | ||
d6b74ac4 | 2043 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2044 | continue; |
74960c60 VP |
2045 | |
2046 | if (bpt->disposition == disp_del_at_next_stop) | |
2047 | continue; | |
a5606eee VP |
2048 | |
2049 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2050 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2051 | { |
2052 | some_failed = 1; | |
2053 | break; | |
2054 | } | |
2055 | if (some_failed) | |
2056 | { | |
2057 | for (loc = bpt->loc; loc; loc = loc->next) | |
2058 | if (loc->inserted) | |
2059 | remove_breakpoint (loc, mark_uninserted); | |
2060 | ||
2061 | hw_breakpoint_error = 1; | |
2062 | fprintf_unfiltered (tmp_error_stream, | |
2063 | "Could not insert hardware watchpoint %d.\n", | |
2064 | bpt->number); | |
2065 | error = -1; | |
2066 | } | |
2067 | } | |
2068 | ||
e236ba44 | 2069 | if (error) |
81d0cc19 GS |
2070 | { |
2071 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2072 | message about possibly exhausted resources. */ | |
879bfdc2 | 2073 | if (hw_breakpoint_error) |
81d0cc19 | 2074 | { |
c6510018 MS |
2075 | fprintf_unfiltered (tmp_error_stream, |
2076 | "Could not insert hardware breakpoints:\n\ | |
2077 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2078 | } |
81d0cc19 GS |
2079 | target_terminal_ours_for_output (); |
2080 | error_stream (tmp_error_stream); | |
2081 | } | |
f7545552 TT |
2082 | |
2083 | do_cleanups (cleanups); | |
c906108c SS |
2084 | } |
2085 | ||
c906108c | 2086 | int |
fba45db2 | 2087 | remove_breakpoints (void) |
c906108c | 2088 | { |
35df4500 | 2089 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2090 | int val = 0; |
c906108c | 2091 | |
35df4500 | 2092 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2093 | { |
35df4500 TJB |
2094 | if (bl->inserted) |
2095 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 2096 | } |
3a1bae8e | 2097 | return val; |
c906108c SS |
2098 | } |
2099 | ||
6c95b8df PA |
2100 | /* Remove breakpoints of process PID. */ |
2101 | ||
2102 | int | |
2103 | remove_breakpoints_pid (int pid) | |
2104 | { | |
35df4500 | 2105 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2106 | int val; |
2107 | struct inferior *inf = find_inferior_pid (pid); | |
2108 | ||
35df4500 | 2109 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2110 | { |
35df4500 | 2111 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2112 | continue; |
2113 | ||
35df4500 | 2114 | if (bl->inserted) |
6c95b8df | 2115 | { |
35df4500 | 2116 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2117 | if (val != 0) |
2118 | return val; | |
2119 | } | |
2120 | } | |
2121 | return 0; | |
2122 | } | |
2123 | ||
692590c1 | 2124 | int |
80ce1ecb | 2125 | remove_hw_watchpoints (void) |
692590c1 | 2126 | { |
35df4500 | 2127 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2128 | int val = 0; |
692590c1 | 2129 | |
35df4500 | 2130 | ALL_BP_LOCATIONS (bl, blp_tmp) |
692590c1 | 2131 | { |
35df4500 TJB |
2132 | if (bl->inserted && bl->loc_type == bp_loc_hardware_watchpoint) |
2133 | val |= remove_breakpoint (bl, mark_uninserted); | |
692590c1 | 2134 | } |
3a1bae8e | 2135 | return val; |
692590c1 MS |
2136 | } |
2137 | ||
c906108c | 2138 | int |
fba45db2 | 2139 | reattach_breakpoints (int pid) |
c906108c | 2140 | { |
6c95b8df | 2141 | struct cleanup *old_chain; |
35df4500 | 2142 | struct bp_location *bl, **blp_tmp; |
c906108c | 2143 | int val; |
a4954f26 | 2144 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 2145 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2146 | struct inferior *inf; |
2147 | struct thread_info *tp; | |
2148 | ||
2149 | tp = any_live_thread_of_process (pid); | |
2150 | if (tp == NULL) | |
2151 | return 1; | |
2152 | ||
2153 | inf = find_inferior_pid (pid); | |
2154 | old_chain = save_inferior_ptid (); | |
2155 | ||
2156 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2157 | |
2158 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2159 | |
35df4500 | 2160 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2161 | { |
35df4500 | 2162 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2163 | continue; |
2164 | ||
35df4500 | 2165 | if (bl->inserted) |
c5aa993b | 2166 | { |
35df4500 TJB |
2167 | bl->inserted = 0; |
2168 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); | |
c5aa993b JM |
2169 | if (val != 0) |
2170 | { | |
ce696e05 | 2171 | do_cleanups (old_chain); |
c5aa993b JM |
2172 | return val; |
2173 | } | |
2174 | } | |
2175 | } | |
ce696e05 | 2176 | do_cleanups (old_chain); |
c906108c SS |
2177 | return 0; |
2178 | } | |
2179 | ||
e58b0e63 PA |
2180 | static int internal_breakpoint_number = -1; |
2181 | ||
84f4c1fe PM |
2182 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2183 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2184 | from internal_breakpoint_number and that variable decremented. | |
2185 | Otherwis the breakpoint number will be populated from | |
2186 | breakpoint_count and that value incremented. Internal breakpoints | |
2187 | do not set the internal var bpnum. */ | |
2188 | static void | |
2189 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2190 | { | |
2191 | if (internal) | |
2192 | b->number = internal_breakpoint_number--; | |
2193 | else | |
2194 | { | |
2195 | set_breakpoint_count (breakpoint_count + 1); | |
2196 | b->number = breakpoint_count; | |
2197 | } | |
2198 | } | |
2199 | ||
e62c965a | 2200 | static struct breakpoint * |
a6d9a66e UW |
2201 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2202 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2203 | { |
e62c965a PP |
2204 | struct symtab_and_line sal; |
2205 | struct breakpoint *b; | |
2206 | ||
4a64f543 | 2207 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2208 | |
2209 | sal.pc = address; | |
2210 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2211 | sal.pspace = current_program_space; |
e62c965a | 2212 | |
a6d9a66e | 2213 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2214 | b->number = internal_breakpoint_number--; |
2215 | b->disposition = disp_donttouch; | |
2216 | ||
2217 | return b; | |
2218 | } | |
2219 | ||
2220 | static void | |
af02033e | 2221 | create_overlay_event_breakpoint (void) |
e62c965a | 2222 | { |
69de3c6a | 2223 | struct objfile *objfile; |
af02033e | 2224 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2225 | |
69de3c6a PP |
2226 | ALL_OBJFILES (objfile) |
2227 | { | |
2228 | struct breakpoint *b; | |
2229 | struct minimal_symbol *m; | |
2230 | ||
2231 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2232 | if (m == NULL) | |
2233 | continue; | |
e62c965a | 2234 | |
a6d9a66e UW |
2235 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2236 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
2237 | bp_overlay_event); |
2238 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2239 | |
69de3c6a PP |
2240 | if (overlay_debugging == ovly_auto) |
2241 | { | |
2242 | b->enable_state = bp_enabled; | |
2243 | overlay_events_enabled = 1; | |
2244 | } | |
2245 | else | |
2246 | { | |
2247 | b->enable_state = bp_disabled; | |
2248 | overlay_events_enabled = 0; | |
2249 | } | |
e62c965a PP |
2250 | } |
2251 | update_global_location_list (1); | |
2252 | } | |
2253 | ||
0fd8e87f | 2254 | static void |
af02033e | 2255 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2256 | { |
6c95b8df | 2257 | struct program_space *pspace; |
6c95b8df PA |
2258 | struct cleanup *old_chain; |
2259 | ||
2260 | old_chain = save_current_program_space (); | |
0fd8e87f | 2261 | |
6c95b8df | 2262 | ALL_PSPACES (pspace) |
af02033e PP |
2263 | { |
2264 | struct objfile *objfile; | |
2265 | ||
2266 | set_current_program_space (pspace); | |
2267 | ||
2268 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2269 | { |
af02033e PP |
2270 | const char *const longjmp_names[] |
2271 | = { "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" }; | |
2272 | const int num_longjmp_names | |
2273 | = sizeof (longjmp_names) / sizeof (longjmp_names[0]); | |
2274 | int i; | |
2275 | struct gdbarch *gdbarch; | |
0fd8e87f | 2276 | |
af02033e PP |
2277 | gdbarch = get_objfile_arch (objfile); |
2278 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2279 | continue; |
2280 | ||
af02033e PP |
2281 | for (i = 0; i < num_longjmp_names; i++) |
2282 | { | |
2283 | struct breakpoint *b; | |
2284 | struct minimal_symbol *m; | |
2285 | const char *func_name; | |
6c95b8df | 2286 | |
af02033e PP |
2287 | func_name = longjmp_names[i]; |
2288 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2289 | if (m == NULL) | |
2290 | continue; | |
0fd8e87f | 2291 | |
af02033e PP |
2292 | b = create_internal_breakpoint (gdbarch, |
2293 | SYMBOL_VALUE_ADDRESS (m), | |
2294 | bp_longjmp_master); | |
2295 | b->addr_string = xstrdup (func_name); | |
2296 | b->enable_state = bp_disabled; | |
2297 | } | |
0fd8e87f | 2298 | } |
af02033e | 2299 | } |
0fd8e87f | 2300 | update_global_location_list (1); |
6c95b8df PA |
2301 | |
2302 | do_cleanups (old_chain); | |
0fd8e87f UW |
2303 | } |
2304 | ||
af02033e | 2305 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2306 | static void |
af02033e | 2307 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2308 | { |
2309 | struct program_space *pspace; | |
2310 | struct objfile *objfile; | |
2311 | struct cleanup *old_chain; | |
af02033e | 2312 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2313 | |
2314 | old_chain = save_current_program_space (); | |
2315 | ||
2316 | ALL_PSPACES (pspace) | |
2317 | ALL_OBJFILES (objfile) | |
2318 | { | |
2319 | struct breakpoint *b; | |
2320 | struct minimal_symbol *m; | |
2321 | ||
2322 | set_current_program_space (pspace); | |
2323 | ||
2324 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2325 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2326 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2327 | continue; | |
2328 | ||
2329 | b = create_internal_breakpoint (get_objfile_arch (objfile), | |
2330 | SYMBOL_VALUE_ADDRESS (m), | |
2331 | bp_std_terminate_master); | |
2332 | b->addr_string = xstrdup (func_name); | |
2333 | b->enable_state = bp_disabled; | |
2334 | } | |
2335 | update_global_location_list (1); | |
2336 | ||
2337 | do_cleanups (old_chain); | |
2338 | } | |
2339 | ||
186c406b TT |
2340 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2341 | ||
2342 | void | |
2343 | create_exception_master_breakpoint (void) | |
2344 | { | |
2345 | struct objfile *objfile; | |
2346 | ||
2347 | ALL_OBJFILES (objfile) | |
2348 | { | |
2349 | struct minimal_symbol *debug_hook; | |
2350 | ||
2351 | debug_hook = lookup_minimal_symbol ("_Unwind_DebugHook", NULL, objfile); | |
2352 | if (debug_hook != NULL) | |
2353 | { | |
2354 | struct breakpoint *b; | |
2355 | CORE_ADDR addr = SYMBOL_VALUE_ADDRESS (debug_hook); | |
2356 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
2357 | ||
2358 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2359 | ¤t_target); | |
2360 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); | |
2361 | b->addr_string = xstrdup ("_Unwind_DebugHook"); | |
2362 | b->enable_state = bp_disabled; | |
2363 | } | |
2364 | } | |
2365 | ||
2366 | update_global_location_list (1); | |
2367 | } | |
2368 | ||
c906108c | 2369 | void |
fba45db2 | 2370 | update_breakpoints_after_exec (void) |
c906108c | 2371 | { |
35df4500 | 2372 | struct breakpoint *b, *b_tmp; |
876fa593 | 2373 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2374 | |
25b22b0a PA |
2375 | /* We're about to delete breakpoints from GDB's lists. If the |
2376 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2377 | writing the breakpoints' "shadow contents" back into memory. The | |
2378 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2379 | do that. Instead, the target is responsible from marking | |
2380 | breakpoints out as soon as it detects an exec. We don't do that | |
2381 | here instead, because there may be other attempts to delete | |
2382 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2383 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2384 | if (bploc->pspace == current_program_space) |
2385 | gdb_assert (!bploc->inserted); | |
c906108c | 2386 | |
35df4500 | 2387 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2388 | { |
6c95b8df PA |
2389 | if (b->pspace != current_program_space) |
2390 | continue; | |
2391 | ||
4a64f543 | 2392 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2393 | if (b->type == bp_shlib_event) |
2394 | { | |
2395 | delete_breakpoint (b); | |
2396 | continue; | |
2397 | } | |
c906108c | 2398 | |
4a64f543 | 2399 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2400 | if (b->type == bp_jit_event) |
2401 | { | |
2402 | delete_breakpoint (b); | |
2403 | continue; | |
2404 | } | |
2405 | ||
1900040c | 2406 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2407 | as must overlay event and longjmp master breakpoints. */ |
2408 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2409 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2410 | || b->type == bp_exception_master) | |
c4093a6a JM |
2411 | { |
2412 | delete_breakpoint (b); | |
2413 | continue; | |
2414 | } | |
2415 | ||
4a64f543 | 2416 | /* Step-resume breakpoints are meaningless after an exec(). */ |
c5aa993b JM |
2417 | if (b->type == bp_step_resume) |
2418 | { | |
2419 | delete_breakpoint (b); | |
2420 | continue; | |
2421 | } | |
2422 | ||
611c83ae PA |
2423 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2424 | after an exec. */ | |
186c406b TT |
2425 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2426 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2427 | { |
2428 | delete_breakpoint (b); | |
2429 | continue; | |
2430 | } | |
2431 | ||
ce78b96d JB |
2432 | if (b->type == bp_catchpoint) |
2433 | { | |
2434 | /* For now, none of the bp_catchpoint breakpoints need to | |
2435 | do anything at this point. In the future, if some of | |
2436 | the catchpoints need to something, we will need to add | |
2437 | a new method, and call this method from here. */ | |
2438 | continue; | |
2439 | } | |
2440 | ||
c5aa993b JM |
2441 | /* bp_finish is a special case. The only way we ought to be able |
2442 | to see one of these when an exec() has happened, is if the user | |
2443 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2444 | carries them to the call-site of the current callee, by setting | |
2445 | a temporary bp there and resuming. But in this case, the finish | |
2446 | will carry them entirely through the vfork & exec. | |
2447 | ||
2448 | We don't want to allow a bp_finish to remain inserted now. But | |
2449 | we can't safely delete it, 'cause finish_command has a handle to | |
2450 | the bp on a bpstat, and will later want to delete it. There's a | |
2451 | chance (and I've seen it happen) that if we delete the bp_finish | |
2452 | here, that its storage will get reused by the time finish_command | |
2453 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2454 | We really must allow finish_command to delete a bp_finish. | |
2455 | ||
53a5351d JM |
2456 | In the absense of a general solution for the "how do we know |
2457 | it's safe to delete something others may have handles to?" | |
2458 | problem, what we'll do here is just uninsert the bp_finish, and | |
2459 | let finish_command delete it. | |
2460 | ||
2461 | (We know the bp_finish is "doomed" in the sense that it's | |
2462 | momentary, and will be deleted as soon as finish_command sees | |
2463 | the inferior stopped. So it doesn't matter that the bp's | |
2464 | address is probably bogus in the new a.out, unlike e.g., the | |
2465 | solib breakpoints.) */ | |
c5aa993b | 2466 | |
c5aa993b JM |
2467 | if (b->type == bp_finish) |
2468 | { | |
2469 | continue; | |
2470 | } | |
2471 | ||
2472 | /* Without a symbolic address, we have little hope of the | |
2473 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2474 | a.out. */ |
c5aa993b JM |
2475 | if (b->addr_string == NULL) |
2476 | { | |
2477 | delete_breakpoint (b); | |
2478 | continue; | |
2479 | } | |
c5aa993b | 2480 | } |
1900040c | 2481 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2482 | create_overlay_event_breakpoint (); |
2483 | create_longjmp_master_breakpoint (); | |
2484 | create_std_terminate_master_breakpoint (); | |
186c406b | 2485 | create_exception_master_breakpoint (); |
c906108c SS |
2486 | } |
2487 | ||
2488 | int | |
fba45db2 | 2489 | detach_breakpoints (int pid) |
c906108c | 2490 | { |
35df4500 | 2491 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2492 | int val = 0; |
ce696e05 | 2493 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2494 | struct inferior *inf = current_inferior (); |
c5aa993b | 2495 | |
39f77062 | 2496 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2497 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2498 | |
6c95b8df | 2499 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2500 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2501 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2502 | { |
35df4500 | 2503 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2504 | continue; |
2505 | ||
35df4500 TJB |
2506 | if (bl->inserted) |
2507 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2508 | } |
d03285ec UW |
2509 | |
2510 | /* Detach single-step breakpoints as well. */ | |
2511 | detach_single_step_breakpoints (); | |
2512 | ||
ce696e05 | 2513 | do_cleanups (old_chain); |
3a1bae8e | 2514 | return val; |
c906108c SS |
2515 | } |
2516 | ||
35df4500 | 2517 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2518 | Note that this is used to detach breakpoints from a child fork. |
2519 | When we get here, the child isn't in the inferior list, and neither | |
2520 | do we have objects to represent its address space --- we should | |
35df4500 | 2521 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2522 | |
c906108c | 2523 | static int |
35df4500 | 2524 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2525 | { |
2526 | int val; | |
c5aa993b | 2527 | |
35df4500 TJB |
2528 | /* BL is never in moribund_locations by our callers. */ |
2529 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2530 | |
35df4500 | 2531 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2532 | /* Permanent breakpoints cannot be inserted or removed. */ |
2533 | return 0; | |
2534 | ||
74960c60 VP |
2535 | /* The type of none suggests that owner is actually deleted. |
2536 | This should not ever happen. */ | |
35df4500 | 2537 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2538 | |
35df4500 TJB |
2539 | if (bl->loc_type == bp_loc_software_breakpoint |
2540 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2541 | { |
c02f5703 MS |
2542 | /* "Normal" instruction breakpoint: either the standard |
2543 | trap-instruction bp (bp_breakpoint), or a | |
2544 | bp_hardware_breakpoint. */ | |
2545 | ||
2546 | /* First check to see if we have to handle an overlay. */ | |
2547 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2548 | || bl->section == NULL |
2549 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2550 | { |
2551 | /* No overlay handling: just remove the breakpoint. */ | |
2552 | ||
35df4500 TJB |
2553 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2554 | val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
c02f5703 | 2555 | else |
35df4500 | 2556 | val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
c02f5703 | 2557 | } |
c906108c SS |
2558 | else |
2559 | { | |
4a64f543 | 2560 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2561 | Did we set a breakpoint at the LMA? */ |
2562 | if (!overlay_events_enabled) | |
2563 | { | |
2564 | /* Yes -- overlay event support is not active, so we | |
2565 | should have set a breakpoint at the LMA. Remove it. | |
2566 | */ | |
c02f5703 MS |
2567 | /* Ignore any failures: if the LMA is in ROM, we will |
2568 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2569 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2570 | target_remove_hw_breakpoint (bl->gdbarch, | |
2571 | &bl->overlay_target_info); | |
c02f5703 | 2572 | else |
35df4500 TJB |
2573 | target_remove_breakpoint (bl->gdbarch, |
2574 | &bl->overlay_target_info); | |
c02f5703 MS |
2575 | } |
2576 | /* Did we set a breakpoint at the VMA? | |
2577 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2578 | if (bl->inserted) |
c906108c | 2579 | { |
c02f5703 MS |
2580 | /* Yes -- remove it. Previously we did not bother to |
2581 | remove the breakpoint if the section had been | |
2582 | unmapped, but let's not rely on that being safe. We | |
2583 | don't know what the overlay manager might do. */ | |
35df4500 TJB |
2584 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2585 | val = target_remove_hw_breakpoint (bl->gdbarch, | |
2586 | &bl->target_info); | |
aa67235e UW |
2587 | |
2588 | /* However, we should remove *software* breakpoints only | |
2589 | if the section is still mapped, or else we overwrite | |
2590 | wrong code with the saved shadow contents. */ | |
35df4500 TJB |
2591 | else if (section_is_mapped (bl->section)) |
2592 | val = target_remove_breakpoint (bl->gdbarch, | |
2593 | &bl->target_info); | |
aa67235e UW |
2594 | else |
2595 | val = 0; | |
c906108c | 2596 | } |
c02f5703 MS |
2597 | else |
2598 | { | |
2599 | /* No -- not inserted, so no need to remove. No error. */ | |
2600 | val = 0; | |
2601 | } | |
c906108c | 2602 | } |
879d1e6b UW |
2603 | |
2604 | /* In some cases, we might not be able to remove a breakpoint | |
2605 | in a shared library that has already been removed, but we | |
2606 | have not yet processed the shlib unload event. */ | |
35df4500 | 2607 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2608 | val = 0; |
2609 | ||
c906108c SS |
2610 | if (val) |
2611 | return val; | |
35df4500 | 2612 | bl->inserted = (is == mark_inserted); |
c906108c | 2613 | } |
35df4500 | 2614 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2615 | { |
77b06cd7 TJB |
2616 | gdb_assert (bl->owner->ops != NULL |
2617 | && bl->owner->ops->remove_location != NULL); | |
2618 | ||
35df4500 | 2619 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2620 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2621 | |
c906108c | 2622 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2623 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2624 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2625 | bl->owner->number); |
c906108c | 2626 | } |
35df4500 TJB |
2627 | else if (bl->owner->type == bp_catchpoint |
2628 | && breakpoint_enabled (bl->owner) | |
2629 | && !bl->duplicate) | |
ce78b96d | 2630 | { |
77b06cd7 TJB |
2631 | gdb_assert (bl->owner->ops != NULL |
2632 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2633 | |
77b06cd7 | 2634 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2635 | if (val) |
2636 | return val; | |
77b06cd7 | 2637 | |
35df4500 | 2638 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2639 | } |
c906108c SS |
2640 | |
2641 | return 0; | |
2642 | } | |
2643 | ||
6c95b8df | 2644 | static int |
35df4500 | 2645 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2646 | { |
2647 | int ret; | |
2648 | struct cleanup *old_chain; | |
2649 | ||
35df4500 TJB |
2650 | /* BL is never in moribund_locations by our callers. */ |
2651 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2652 | |
35df4500 | 2653 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2654 | /* Permanent breakpoints cannot be inserted or removed. */ |
2655 | return 0; | |
2656 | ||
2657 | /* The type of none suggests that owner is actually deleted. | |
2658 | This should not ever happen. */ | |
35df4500 | 2659 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2660 | |
2661 | old_chain = save_current_space_and_thread (); | |
2662 | ||
35df4500 | 2663 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2664 | |
35df4500 | 2665 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2666 | |
2667 | do_cleanups (old_chain); | |
2668 | return ret; | |
2669 | } | |
2670 | ||
c906108c SS |
2671 | /* Clear the "inserted" flag in all breakpoints. */ |
2672 | ||
25b22b0a | 2673 | void |
fba45db2 | 2674 | mark_breakpoints_out (void) |
c906108c | 2675 | { |
35df4500 | 2676 | struct bp_location *bl, **blp_tmp; |
c906108c | 2677 | |
35df4500 TJB |
2678 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2679 | if (bl->pspace == current_program_space) | |
2680 | bl->inserted = 0; | |
c906108c SS |
2681 | } |
2682 | ||
53a5351d JM |
2683 | /* Clear the "inserted" flag in all breakpoints and delete any |
2684 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2685 | |
2686 | Plus other such housekeeping that has to be done for breakpoints | |
2687 | between runs. | |
2688 | ||
53a5351d JM |
2689 | Note: this function gets called at the end of a run (by |
2690 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2691 | init_wait_for_inferior). */ |
c906108c SS |
2692 | |
2693 | ||
2694 | ||
2695 | void | |
fba45db2 | 2696 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2697 | { |
35df4500 TJB |
2698 | struct breakpoint *b, *b_tmp; |
2699 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2700 | int ix; |
6c95b8df | 2701 | struct program_space *pspace = current_program_space; |
c906108c | 2702 | |
50c71eaf PA |
2703 | /* If breakpoint locations are shared across processes, then there's |
2704 | nothing to do. */ | |
2567c7d9 | 2705 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2706 | return; |
2707 | ||
35df4500 | 2708 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2709 | { |
35df4500 TJB |
2710 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2711 | if (bl->pspace == pspace | |
2712 | && bl->owner->enable_state != bp_permanent) | |
2713 | bl->inserted = 0; | |
6c95b8df | 2714 | } |
075f6582 | 2715 | |
35df4500 | 2716 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2717 | { |
6c95b8df PA |
2718 | if (b->loc && b->loc->pspace != pspace) |
2719 | continue; | |
2720 | ||
c5aa993b JM |
2721 | switch (b->type) |
2722 | { | |
2723 | case bp_call_dummy: | |
c906108c | 2724 | |
c5aa993b | 2725 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2726 | cause problems when the inferior is rerun, so we better get |
2727 | rid of it. */ | |
2728 | ||
2729 | case bp_watchpoint_scope: | |
2730 | ||
2731 | /* Also get rid of scope breakpoints. */ | |
2732 | ||
2733 | case bp_shlib_event: | |
2734 | ||
2735 | /* Also remove solib event breakpoints. Their addresses may | |
2736 | have changed since the last time we ran the program. | |
2737 | Actually we may now be debugging against different target; | |
2738 | and so the solib backend that installed this breakpoint may | |
2739 | not be used in by the target. E.g., | |
2740 | ||
2741 | (gdb) file prog-linux | |
2742 | (gdb) run # native linux target | |
2743 | ... | |
2744 | (gdb) kill | |
2745 | (gdb) file prog-win.exe | |
2746 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2747 | */ | |
c906108c | 2748 | |
c5aa993b JM |
2749 | delete_breakpoint (b); |
2750 | break; | |
c906108c | 2751 | |
c5aa993b JM |
2752 | case bp_watchpoint: |
2753 | case bp_hardware_watchpoint: | |
2754 | case bp_read_watchpoint: | |
2755 | case bp_access_watchpoint: | |
c906108c | 2756 | |
c5aa993b JM |
2757 | /* Likewise for watchpoints on local expressions. */ |
2758 | if (b->exp_valid_block != NULL) | |
2759 | delete_breakpoint (b); | |
967af18d | 2760 | else if (context == inf_starting) |
c860120c | 2761 | { |
4a64f543 MS |
2762 | /* Reset val field to force reread of starting value in |
2763 | insert_breakpoints. */ | |
c860120c PM |
2764 | if (b->val) |
2765 | value_free (b->val); | |
2766 | b->val = NULL; | |
fa4727a6 | 2767 | b->val_valid = 0; |
c860120c | 2768 | } |
c5aa993b JM |
2769 | break; |
2770 | default: | |
c5aa993b JM |
2771 | break; |
2772 | } | |
2773 | } | |
1c5cfe86 PA |
2774 | |
2775 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2776 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2777 | decref_bp_location (&bl); | |
1c5cfe86 | 2778 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2779 | } |
2780 | ||
6c95b8df PA |
2781 | /* These functions concern about actual breakpoints inserted in the |
2782 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2783 | we need to hop over the bkpt --- so we check for address space | |
2784 | match, not program space. */ | |
2785 | ||
c2c6d25f JM |
2786 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2787 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2788 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2789 | permanent breakpoint. | |
2790 | - When continuing from a location with an ordinary breakpoint, we | |
2791 | actually single step once before calling insert_breakpoints. | |
2792 | - When continuing from a localion with a permanent breakpoint, we | |
2793 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2794 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2795 | |
c2c6d25f | 2796 | enum breakpoint_here |
6c95b8df | 2797 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2798 | { |
35df4500 | 2799 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2800 | int any_breakpoint_here = 0; |
c906108c | 2801 | |
35df4500 | 2802 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2803 | { |
35df4500 TJB |
2804 | if (bl->loc_type != bp_loc_software_breakpoint |
2805 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2806 | continue; |
2807 | ||
35df4500 TJB |
2808 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2809 | if ((breakpoint_enabled (bl->owner) | |
2810 | || bl->owner->enable_state == bp_permanent) | |
2811 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2812 | aspace, pc)) |
075f6582 DJ |
2813 | { |
2814 | if (overlay_debugging | |
35df4500 TJB |
2815 | && section_is_overlay (bl->section) |
2816 | && !section_is_mapped (bl->section)) | |
075f6582 | 2817 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2818 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2819 | return permanent_breakpoint_here; |
2820 | else | |
2821 | any_breakpoint_here = 1; | |
2822 | } | |
2823 | } | |
c906108c | 2824 | |
c2c6d25f | 2825 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2826 | } |
2827 | ||
1c5cfe86 PA |
2828 | /* Return true if there's a moribund breakpoint at PC. */ |
2829 | ||
2830 | int | |
6c95b8df | 2831 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2832 | { |
2833 | struct bp_location *loc; | |
2834 | int ix; | |
2835 | ||
2836 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2837 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2838 | aspace, pc)) | |
1c5cfe86 PA |
2839 | return 1; |
2840 | ||
2841 | return 0; | |
2842 | } | |
c2c6d25f | 2843 | |
c36b740a | 2844 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2845 | inserted using regular breakpoint_chain / bp_location array |
2846 | mechanism. This does not check for single-step breakpoints, which | |
2847 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2848 | |
2849 | int | |
4a64f543 MS |
2850 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2851 | CORE_ADDR pc) | |
c906108c | 2852 | { |
35df4500 | 2853 | struct bp_location *bl, **blp_tmp; |
c906108c | 2854 | |
35df4500 | 2855 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2856 | { |
35df4500 TJB |
2857 | if (bl->loc_type != bp_loc_software_breakpoint |
2858 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2859 | continue; |
2860 | ||
35df4500 TJB |
2861 | if (bl->inserted |
2862 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2863 | aspace, pc)) |
075f6582 DJ |
2864 | { |
2865 | if (overlay_debugging | |
35df4500 TJB |
2866 | && section_is_overlay (bl->section) |
2867 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2868 | continue; /* unmapped overlay -- can't be a match */ |
2869 | else | |
2870 | return 1; | |
2871 | } | |
c5aa993b | 2872 | } |
c36b740a VP |
2873 | return 0; |
2874 | } | |
2875 | ||
2876 | /* Returns non-zero iff there's either regular breakpoint | |
2877 | or a single step breakpoint inserted at PC. */ | |
2878 | ||
2879 | int | |
6c95b8df | 2880 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2881 | { |
6c95b8df | 2882 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2883 | return 1; |
c906108c | 2884 | |
6c95b8df | 2885 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2886 | return 1; |
2887 | ||
c906108c SS |
2888 | return 0; |
2889 | } | |
2890 | ||
4fa8626c DJ |
2891 | /* This function returns non-zero iff there is a software breakpoint |
2892 | inserted at PC. */ | |
2893 | ||
2894 | int | |
3e43a32a MS |
2895 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2896 | CORE_ADDR pc) | |
4fa8626c | 2897 | { |
35df4500 | 2898 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2899 | |
35df4500 | 2900 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2901 | { |
35df4500 | 2902 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2903 | continue; |
2904 | ||
35df4500 TJB |
2905 | if (bl->inserted |
2906 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2907 | aspace, pc)) |
4fa8626c DJ |
2908 | { |
2909 | if (overlay_debugging | |
35df4500 TJB |
2910 | && section_is_overlay (bl->section) |
2911 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2912 | continue; /* unmapped overlay -- can't be a match */ |
2913 | else | |
2914 | return 1; | |
2915 | } | |
2916 | } | |
2917 | ||
1aafd4da | 2918 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2919 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2920 | return 1; |
2921 | ||
4fa8626c DJ |
2922 | return 0; |
2923 | } | |
2924 | ||
9093389c PA |
2925 | int |
2926 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2927 | CORE_ADDR addr, ULONGEST len) | |
2928 | { | |
2929 | struct breakpoint *bpt; | |
2930 | ||
2931 | ALL_BREAKPOINTS (bpt) | |
2932 | { | |
2933 | struct bp_location *loc; | |
2934 | ||
2935 | if (bpt->type != bp_hardware_watchpoint | |
2936 | && bpt->type != bp_access_watchpoint) | |
2937 | continue; | |
2938 | ||
2939 | if (!breakpoint_enabled (bpt)) | |
2940 | continue; | |
2941 | ||
2942 | for (loc = bpt->loc; loc; loc = loc->next) | |
2943 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2944 | { | |
2945 | CORE_ADDR l, h; | |
2946 | ||
2947 | /* Check for intersection. */ | |
2948 | l = max (loc->address, addr); | |
2949 | h = min (loc->address + loc->length, addr + len); | |
2950 | if (l < h) | |
2951 | return 1; | |
2952 | } | |
2953 | } | |
2954 | return 0; | |
2955 | } | |
2956 | ||
075f6582 DJ |
2957 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2958 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2959 | |
2960 | int | |
6c95b8df PA |
2961 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2962 | ptid_t ptid) | |
c906108c | 2963 | { |
35df4500 | 2964 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 2965 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2966 | int thread = -1; |
4a306c9a | 2967 | int task = 0; |
a6f1cd96 | 2968 | |
35df4500 | 2969 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2970 | { |
35df4500 TJB |
2971 | if (bl->loc_type != bp_loc_software_breakpoint |
2972 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2973 | continue; |
2974 | ||
35df4500 TJB |
2975 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2976 | if (!breakpoint_enabled (bl->owner) | |
2977 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
2978 | continue; |
2979 | ||
35df4500 | 2980 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
6c95b8df | 2981 | aspace, pc)) |
a6f1cd96 JB |
2982 | continue; |
2983 | ||
35df4500 | 2984 | if (bl->owner->thread != -1) |
075f6582 | 2985 | { |
a6f1cd96 JB |
2986 | /* This is a thread-specific breakpoint. Check that ptid |
2987 | matches that thread. If thread hasn't been computed yet, | |
2988 | it is now time to do so. */ | |
2989 | if (thread == -1) | |
2990 | thread = pid_to_thread_id (ptid); | |
35df4500 | 2991 | if (bl->owner->thread != thread) |
a6f1cd96 | 2992 | continue; |
075f6582 | 2993 | } |
a6f1cd96 | 2994 | |
35df4500 | 2995 | if (bl->owner->task != 0) |
4a306c9a JB |
2996 | { |
2997 | /* This is a task-specific breakpoint. Check that ptid | |
2998 | matches that task. If task hasn't been computed yet, | |
2999 | it is now time to do so. */ | |
3000 | if (task == 0) | |
3001 | task = ada_get_task_number (ptid); | |
35df4500 | 3002 | if (bl->owner->task != task) |
4a306c9a JB |
3003 | continue; |
3004 | } | |
3005 | ||
a6f1cd96 | 3006 | if (overlay_debugging |
35df4500 TJB |
3007 | && section_is_overlay (bl->section) |
3008 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3009 | continue; /* unmapped overlay -- can't be a match */ |
3010 | ||
3011 | return 1; | |
c5aa993b | 3012 | } |
c906108c SS |
3013 | |
3014 | return 0; | |
3015 | } | |
c906108c | 3016 | \f |
c5aa993b | 3017 | |
c906108c SS |
3018 | /* bpstat stuff. External routines' interfaces are documented |
3019 | in breakpoint.h. */ | |
3020 | ||
3021 | int | |
fba45db2 | 3022 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3023 | { |
533be4dd | 3024 | return (ep->type == bp_catchpoint); |
c906108c SS |
3025 | } |
3026 | ||
f431efe5 PA |
3027 | /* Frees any storage that is part of a bpstat. Does not walk the |
3028 | 'next' chain. */ | |
3029 | ||
3030 | static void | |
198757a8 VP |
3031 | bpstat_free (bpstat bs) |
3032 | { | |
3033 | if (bs->old_val != NULL) | |
3034 | value_free (bs->old_val); | |
9add0f1b | 3035 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3036 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3037 | xfree (bs); |
3038 | } | |
3039 | ||
c906108c SS |
3040 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3041 | Also free any storage that is part of a bpstat. */ | |
3042 | ||
3043 | void | |
fba45db2 | 3044 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3045 | { |
3046 | bpstat p; | |
3047 | bpstat q; | |
3048 | ||
3049 | if (bsp == 0) | |
3050 | return; | |
3051 | p = *bsp; | |
3052 | while (p != NULL) | |
3053 | { | |
3054 | q = p->next; | |
198757a8 | 3055 | bpstat_free (p); |
c906108c SS |
3056 | p = q; |
3057 | } | |
3058 | *bsp = NULL; | |
3059 | } | |
3060 | ||
3061 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3062 | is part of the bpstat is copied as well. */ | |
3063 | ||
3064 | bpstat | |
fba45db2 | 3065 | bpstat_copy (bpstat bs) |
c906108c SS |
3066 | { |
3067 | bpstat p = NULL; | |
3068 | bpstat tmp; | |
3069 | bpstat retval = NULL; | |
3070 | ||
3071 | if (bs == NULL) | |
3072 | return bs; | |
3073 | ||
3074 | for (; bs != NULL; bs = bs->next) | |
3075 | { | |
3076 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3077 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3078 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3079 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3080 | if (bs->old_val != NULL) |
3c3185ac JK |
3081 | { |
3082 | tmp->old_val = value_copy (bs->old_val); | |
3083 | release_value (tmp->old_val); | |
3084 | } | |
31cc81e9 | 3085 | |
c906108c SS |
3086 | if (p == NULL) |
3087 | /* This is the first thing in the chain. */ | |
3088 | retval = tmp; | |
3089 | else | |
3090 | p->next = tmp; | |
3091 | p = tmp; | |
3092 | } | |
3093 | p->next = NULL; | |
3094 | return retval; | |
3095 | } | |
3096 | ||
4a64f543 | 3097 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3098 | |
3099 | bpstat | |
fba45db2 | 3100 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3101 | { |
c5aa993b JM |
3102 | if (bsp == NULL) |
3103 | return NULL; | |
c906108c | 3104 | |
c5aa993b JM |
3105 | for (; bsp != NULL; bsp = bsp->next) |
3106 | { | |
f431efe5 | 3107 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3108 | return bsp; |
3109 | } | |
c906108c SS |
3110 | return NULL; |
3111 | } | |
3112 | ||
4a64f543 MS |
3113 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3114 | stopped at. *BSP upon return is a bpstat which points to the | |
3115 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3116 | good for anything but further calls to bpstat_num). | |
3117 | ||
8671a17b PA |
3118 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3119 | Return -1 if stopped at a breakpoint that has been deleted since | |
3120 | we set it. | |
3121 | Return 1 otherwise. */ | |
c906108c SS |
3122 | |
3123 | int | |
8671a17b | 3124 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3125 | { |
3126 | struct breakpoint *b; | |
3127 | ||
3128 | if ((*bsp) == NULL) | |
3129 | return 0; /* No more breakpoint values */ | |
8671a17b | 3130 | |
4a64f543 MS |
3131 | /* We assume we'll never have several bpstats that correspond to a |
3132 | single breakpoint -- otherwise, this function might return the | |
3133 | same number more than once and this will look ugly. */ | |
f431efe5 | 3134 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3135 | *bsp = (*bsp)->next; |
3136 | if (b == NULL) | |
3137 | return -1; /* breakpoint that's been deleted since */ | |
3138 | ||
3139 | *num = b->number; /* We have its number */ | |
3140 | return 1; | |
c906108c SS |
3141 | } |
3142 | ||
3143 | /* Modify BS so that the actions will not be performed. */ | |
3144 | ||
3145 | void | |
fba45db2 | 3146 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3147 | { |
3148 | for (; bs != NULL; bs = bs->next) | |
3149 | { | |
9add0f1b | 3150 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3151 | bs->commands_left = NULL; |
c906108c SS |
3152 | if (bs->old_val != NULL) |
3153 | { | |
3154 | value_free (bs->old_val); | |
3155 | bs->old_val = NULL; | |
3156 | } | |
3157 | } | |
3158 | } | |
3159 | ||
f3b1572e PA |
3160 | /* Called when a command is about to proceed the inferior. */ |
3161 | ||
3162 | static void | |
3163 | breakpoint_about_to_proceed (void) | |
3164 | { | |
3165 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3166 | { | |
3167 | struct thread_info *tp = inferior_thread (); | |
3168 | ||
3169 | /* Allow inferior function calls in breakpoint commands to not | |
3170 | interrupt the command list. When the call finishes | |
3171 | successfully, the inferior will be standing at the same | |
3172 | breakpoint as if nothing happened. */ | |
16c381f0 | 3173 | if (tp->control.in_infcall) |
f3b1572e PA |
3174 | return; |
3175 | } | |
3176 | ||
3177 | breakpoint_proceeded = 1; | |
3178 | } | |
3179 | ||
4a64f543 MS |
3180 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3181 | command. */ | |
c906108c | 3182 | static void |
4efb68b1 | 3183 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3184 | { |
3185 | executing_breakpoint_commands = 0; | |
3186 | } | |
3187 | ||
4a64f543 MS |
3188 | /* Execute all the commands associated with all the breakpoints at |
3189 | this location. Any of these commands could cause the process to | |
3190 | proceed beyond this point, etc. We look out for such changes by | |
3191 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3192 | |
347bddb7 PA |
3193 | Returns true if a breakpoint command resumed the inferior. In that |
3194 | case, it is the caller's responsibility to recall it again with the | |
3195 | bpstat of the current thread. */ | |
3196 | ||
3197 | static int | |
3198 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3199 | { |
3200 | bpstat bs; | |
3201 | struct cleanup *old_chain; | |
347bddb7 | 3202 | int again = 0; |
c906108c SS |
3203 | |
3204 | /* Avoid endless recursion if a `source' command is contained | |
3205 | in bs->commands. */ | |
3206 | if (executing_breakpoint_commands) | |
347bddb7 | 3207 | return 0; |
c906108c SS |
3208 | |
3209 | executing_breakpoint_commands = 1; | |
3210 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3211 | ||
4a64f543 | 3212 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3213 | bs = *bsp; |
3214 | ||
3215 | breakpoint_proceeded = 0; | |
3216 | for (; bs != NULL; bs = bs->next) | |
3217 | { | |
9add0f1b | 3218 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3219 | struct command_line *cmd; |
3220 | struct cleanup *this_cmd_tree_chain; | |
3221 | ||
3222 | /* Take ownership of the BSP's command tree, if it has one. | |
3223 | ||
3224 | The command tree could legitimately contain commands like | |
3225 | 'step' and 'next', which call clear_proceed_status, which | |
3226 | frees stop_bpstat's command tree. To make sure this doesn't | |
3227 | free the tree we're executing out from under us, we need to | |
3228 | take ownership of the tree ourselves. Since a given bpstat's | |
3229 | commands are only executed once, we don't need to copy it; we | |
3230 | can clear the pointer in the bpstat, and make sure we free | |
3231 | the tree when we're done. */ | |
9add0f1b TT |
3232 | ccmd = bs->commands; |
3233 | bs->commands = NULL; | |
3234 | this_cmd_tree_chain | |
3235 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3236 | cmd = bs->commands_left; | |
3237 | bs->commands_left = NULL; | |
6c50ab1c | 3238 | |
c906108c SS |
3239 | while (cmd != NULL) |
3240 | { | |
3241 | execute_control_command (cmd); | |
3242 | ||
3243 | if (breakpoint_proceeded) | |
3244 | break; | |
3245 | else | |
3246 | cmd = cmd->next; | |
3247 | } | |
6c50ab1c JB |
3248 | |
3249 | /* We can free this command tree now. */ | |
3250 | do_cleanups (this_cmd_tree_chain); | |
3251 | ||
c906108c | 3252 | if (breakpoint_proceeded) |
32c1e744 VP |
3253 | { |
3254 | if (target_can_async_p ()) | |
347bddb7 PA |
3255 | /* If we are in async mode, then the target might be still |
3256 | running, not stopped at any breakpoint, so nothing for | |
3257 | us to do here -- just return to the event loop. */ | |
3258 | ; | |
32c1e744 VP |
3259 | else |
3260 | /* In sync mode, when execute_control_command returns | |
3261 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3262 | Breakpoint commands for that stop were not run, since |
3263 | execute_command does not run breakpoint commands -- | |
3264 | only command_line_handler does, but that one is not | |
3265 | involved in execution of breakpoint commands. So, we | |
3266 | can now execute breakpoint commands. It should be | |
3267 | noted that making execute_command do bpstat actions is | |
3268 | not an option -- in this case we'll have recursive | |
3269 | invocation of bpstat for each breakpoint with a | |
3270 | command, and can easily blow up GDB stack. Instead, we | |
3271 | return true, which will trigger the caller to recall us | |
3272 | with the new stop_bpstat. */ | |
3273 | again = 1; | |
3274 | break; | |
32c1e744 | 3275 | } |
c906108c | 3276 | } |
c2b8ed2c | 3277 | do_cleanups (old_chain); |
347bddb7 PA |
3278 | return again; |
3279 | } | |
3280 | ||
3281 | void | |
3282 | bpstat_do_actions (void) | |
3283 | { | |
3284 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3285 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3286 | && target_has_execution | |
3287 | && !is_exited (inferior_ptid) | |
3288 | && !is_executing (inferior_ptid)) | |
3289 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3290 | and only return when it is stopped at the next breakpoint, we | |
3291 | keep doing breakpoint actions until it returns false to | |
3292 | indicate the inferior was not resumed. */ | |
16c381f0 | 3293 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3294 | break; |
c906108c SS |
3295 | } |
3296 | ||
fa4727a6 DJ |
3297 | /* Print out the (old or new) value associated with a watchpoint. */ |
3298 | ||
3299 | static void | |
3300 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3301 | { | |
3302 | if (val == NULL) | |
3303 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3304 | else | |
79a45b7d TT |
3305 | { |
3306 | struct value_print_options opts; | |
3307 | get_user_print_options (&opts); | |
3308 | value_print (val, stream, &opts); | |
3309 | } | |
fa4727a6 DJ |
3310 | } |
3311 | ||
e514a9d6 | 3312 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3313 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3314 | by having it set different print_it values. |
3315 | ||
3316 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3317 | through the bpstat list of things causing this stop, calling the | |
4a64f543 | 3318 | print_bp_stop_message function on each one. The behavior of the |
e514a9d6 | 3319 | print_bp_stop_message function depends on the print_it field of |
4a64f543 | 3320 | bpstat. If such field so indicates, call this function here. |
e514a9d6 JM |
3321 | |
3322 | Return values from this routine (ultimately used by bpstat_print() | |
3323 | and normal_stop() to decide what to do): | |
3324 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3325 | don't print anything else. | |
3326 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3327 | that something to be followed by a location. | |
3328 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3329 | that something to be followed by a location. | |
3330 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3331 | analysis. */ | |
c906108c | 3332 | |
917317f4 | 3333 | static enum print_stop_action |
fba45db2 | 3334 | print_it_typical (bpstat bs) |
c906108c | 3335 | { |
f7545552 | 3336 | struct cleanup *old_chain; |
4f8d1dc6 | 3337 | struct breakpoint *b; |
89f9893c | 3338 | const struct bp_location *bl; |
8b93c638 | 3339 | struct ui_stream *stb; |
f7545552 TT |
3340 | int bp_temp = 0; |
3341 | enum print_stop_action result; | |
3342 | ||
c906108c SS |
3343 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3344 | which has since been deleted. */ | |
e514a9d6 | 3345 | if (bs->breakpoint_at == NULL) |
917317f4 | 3346 | return PRINT_UNKNOWN; |
2bdf28a0 | 3347 | |
f431efe5 PA |
3348 | gdb_assert (bs->bp_location_at != NULL); |
3349 | ||
3350 | bl = bs->bp_location_at; | |
3351 | b = bs->breakpoint_at; | |
c906108c | 3352 | |
f7545552 TT |
3353 | stb = ui_out_stream_new (uiout); |
3354 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3355 | ||
4f8d1dc6 | 3356 | switch (b->type) |
c906108c | 3357 | { |
e514a9d6 JM |
3358 | case bp_breakpoint: |
3359 | case bp_hardware_breakpoint: | |
f431efe5 | 3360 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3361 | if (bl->address != bl->requested_address) |
3362 | breakpoint_adjustment_warning (bl->requested_address, | |
3363 | bl->address, | |
4f8d1dc6 VP |
3364 | b->number, 1); |
3365 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3366 | if (bp_temp) |
3367 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3368 | else | |
3369 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3370 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3371 | { |
3372 | ui_out_field_string (uiout, "reason", | |
3373 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3374 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3375 | } | |
4f8d1dc6 | 3376 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3377 | ui_out_text (uiout, ", "); |
f7545552 | 3378 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3379 | break; |
3380 | ||
3381 | case bp_shlib_event: | |
917317f4 JM |
3382 | /* Did we stop because the user set the stop_on_solib_events |
3383 | variable? (If so, we report this as a generic, "Stopped due | |
3384 | to shlib event" message.) */ | |
a3f17187 | 3385 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3386 | result = PRINT_NOTHING; |
e514a9d6 JM |
3387 | break; |
3388 | ||
c4093a6a | 3389 | case bp_thread_event: |
4a64f543 | 3390 | /* Not sure how we will get here. |
c4093a6a | 3391 | GDB should not stop for these breakpoints. */ |
a3f17187 | 3392 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3393 | result = PRINT_NOTHING; |
c4093a6a JM |
3394 | break; |
3395 | ||
1900040c | 3396 | case bp_overlay_event: |
4a64f543 | 3397 | /* By analogy with the thread event, GDB should not stop for these. */ |
a3f17187 | 3398 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3399 | result = PRINT_NOTHING; |
1900040c MS |
3400 | break; |
3401 | ||
0fd8e87f UW |
3402 | case bp_longjmp_master: |
3403 | /* These should never be enabled. */ | |
3404 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3405 | result = PRINT_NOTHING; | |
3406 | break; | |
3407 | ||
aa7d318d TT |
3408 | case bp_std_terminate_master: |
3409 | /* These should never be enabled. */ | |
3e43a32a MS |
3410 | printf_filtered (_("std::terminate Master Breakpoint: " |
3411 | "gdb should not stop!\n")); | |
aa7d318d TT |
3412 | result = PRINT_NOTHING; |
3413 | break; | |
3414 | ||
186c406b TT |
3415 | case bp_exception_master: |
3416 | /* These should never be enabled. */ | |
3e43a32a MS |
3417 | printf_filtered (_("Exception Master Breakpoint: " |
3418 | "gdb should not stop!\n")); | |
186c406b TT |
3419 | result = PRINT_NOTHING; |
3420 | break; | |
3421 | ||
e514a9d6 JM |
3422 | case bp_watchpoint: |
3423 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3424 | annotate_watchpoint (b->number); |
3425 | if (ui_out_is_mi_like_p (uiout)) | |
3426 | ui_out_field_string | |
3427 | (uiout, "reason", | |
3428 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3429 | mention (b); | |
f7545552 | 3430 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3431 | ui_out_text (uiout, "\nOld value = "); |
3432 | watchpoint_value_print (bs->old_val, stb->stream); | |
3433 | ui_out_field_stream (uiout, "old", stb); | |
3434 | ui_out_text (uiout, "\nNew value = "); | |
3435 | watchpoint_value_print (b->val, stb->stream); | |
3436 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3437 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3438 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3439 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3440 | break; |
3441 | ||
3442 | case bp_read_watchpoint: | |
9dc5e2a9 | 3443 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3444 | ui_out_field_string |
3445 | (uiout, "reason", | |
3446 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3447 | mention (b); |
f7545552 | 3448 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3449 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3450 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3451 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3452 | ui_out_text (uiout, "\n"); |
f7545552 | 3453 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3454 | break; |
3455 | ||
3456 | case bp_access_watchpoint: | |
fa4727a6 | 3457 | if (bs->old_val != NULL) |
8b93c638 | 3458 | { |
4f8d1dc6 | 3459 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3460 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3461 | ui_out_field_string |
3462 | (uiout, "reason", | |
3463 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3464 | mention (b); |
f7545552 | 3465 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3466 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3467 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3468 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3469 | ui_out_text (uiout, "\nNew value = "); |
3470 | } | |
3471 | else | |
3472 | { | |
4f8d1dc6 | 3473 | mention (b); |
9dc5e2a9 | 3474 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3475 | ui_out_field_string |
3476 | (uiout, "reason", | |
3477 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3478 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3479 | ui_out_text (uiout, "\nValue = "); |
3480 | } | |
fa4727a6 | 3481 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3482 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3483 | ui_out_text (uiout, "\n"); |
f7545552 | 3484 | result = PRINT_UNKNOWN; |
e514a9d6 | 3485 | break; |
4ce44c66 | 3486 | |
e514a9d6 | 3487 | /* Fall through, we don't deal with these types of breakpoints |
4a64f543 | 3488 | here. */ |
e514a9d6 | 3489 | |
11cf8741 | 3490 | case bp_finish: |
9dc5e2a9 | 3491 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3492 | ui_out_field_string |
3493 | (uiout, "reason", | |
3494 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3495 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3496 | break; |
3497 | ||
e514a9d6 | 3498 | case bp_until: |
9dc5e2a9 | 3499 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3500 | ui_out_field_string |
3501 | (uiout, "reason", | |
3502 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3503 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3504 | break; |
3505 | ||
c2d11a7d | 3506 | case bp_none: |
e514a9d6 JM |
3507 | case bp_longjmp: |
3508 | case bp_longjmp_resume: | |
186c406b TT |
3509 | case bp_exception: |
3510 | case bp_exception_resume: | |
e514a9d6 | 3511 | case bp_step_resume: |
e514a9d6 JM |
3512 | case bp_watchpoint_scope: |
3513 | case bp_call_dummy: | |
aa7d318d | 3514 | case bp_std_terminate: |
1042e4c0 | 3515 | case bp_tracepoint: |
7a697b8d | 3516 | case bp_fast_tracepoint: |
4efc6507 | 3517 | case bp_jit_event: |
e514a9d6 | 3518 | default: |
f7545552 TT |
3519 | result = PRINT_UNKNOWN; |
3520 | break; | |
e514a9d6 | 3521 | } |
f7545552 TT |
3522 | |
3523 | do_cleanups (old_chain); | |
3524 | return result; | |
e514a9d6 JM |
3525 | } |
3526 | ||
3527 | /* Generic routine for printing messages indicating why we | |
4a64f543 | 3528 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3529 | 'print_it' in the bpstat structure. Under some circumstances we |
3530 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3531 | normal_stop(). */ |
e514a9d6 JM |
3532 | |
3533 | static enum print_stop_action | |
3534 | print_bp_stop_message (bpstat bs) | |
3535 | { | |
3536 | switch (bs->print_it) | |
3537 | { | |
3538 | case print_it_noop: | |
4a64f543 | 3539 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3540 | return PRINT_UNKNOWN; |
3541 | break; | |
3542 | ||
3543 | case print_it_done: | |
3544 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3545 | relevant messages. */ |
e514a9d6 JM |
3546 | return PRINT_SRC_AND_LOC; |
3547 | break; | |
3548 | ||
3549 | case print_it_normal: | |
4f8d1dc6 | 3550 | { |
f431efe5 PA |
3551 | struct breakpoint *b = bs->breakpoint_at; |
3552 | ||
4f8d1dc6 VP |
3553 | /* Normal case. Call the breakpoint's print_it method, or |
3554 | print_it_typical. */ | |
3555 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3556 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3557 | return b->ops->print_it (b); | |
3558 | else | |
3559 | return print_it_typical (bs); | |
3560 | } | |
3561 | break; | |
3086aeae | 3562 | |
e514a9d6 | 3563 | default: |
8e65ff28 | 3564 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3565 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3566 | break; |
c906108c | 3567 | } |
c906108c SS |
3568 | } |
3569 | ||
e514a9d6 JM |
3570 | /* Print a message indicating what happened. This is called from |
3571 | normal_stop(). The input to this routine is the head of the bpstat | |
3572 | list - a list of the eventpoints that caused this stop. This | |
3573 | routine calls the generic print routine for printing a message | |
3574 | about reasons for stopping. This will print (for example) the | |
3575 | "Breakpoint n," part of the output. The return value of this | |
3576 | routine is one of: | |
c906108c | 3577 | |
4a64f543 | 3578 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3579 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3580 | code to print the location. An example is |
c5aa993b JM |
3581 | "Breakpoint 1, " which should be followed by |
3582 | the location. | |
917317f4 | 3583 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3584 | to also print the location part of the message. |
3585 | An example is the catch/throw messages, which | |
4a64f543 | 3586 | don't require a location appended to the end. |
917317f4 | 3587 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3588 | further info to be printed. */ |
c906108c | 3589 | |
917317f4 | 3590 | enum print_stop_action |
fba45db2 | 3591 | bpstat_print (bpstat bs) |
c906108c SS |
3592 | { |
3593 | int val; | |
c5aa993b | 3594 | |
c906108c | 3595 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3596 | (Currently all watchpoints go on the bpstat whether hit or not. |
3597 | That probably could (should) be changed, provided care is taken | |
c906108c | 3598 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3599 | for (; bs; bs = bs->next) |
3600 | { | |
3601 | val = print_bp_stop_message (bs); | |
3602 | if (val == PRINT_SRC_ONLY | |
3603 | || val == PRINT_SRC_AND_LOC | |
3604 | || val == PRINT_NOTHING) | |
3605 | return val; | |
3606 | } | |
c906108c | 3607 | |
e514a9d6 | 3608 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3609 | with and nothing was printed. */ |
917317f4 | 3610 | return PRINT_UNKNOWN; |
c906108c SS |
3611 | } |
3612 | ||
4a64f543 MS |
3613 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3614 | used inside a catch_errors to evaluate the breakpoint condition. | |
3615 | The argument is a "struct expression *" that has been cast to a | |
3616 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3617 | |
3618 | static int | |
4efb68b1 | 3619 | breakpoint_cond_eval (void *exp) |
c906108c | 3620 | { |
278cd55f | 3621 | struct value *mark = value_mark (); |
c5aa993b | 3622 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3623 | |
c906108c SS |
3624 | value_free_to_mark (mark); |
3625 | return i; | |
3626 | } | |
3627 | ||
5760d0ab | 3628 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3629 | |
3630 | static bpstat | |
5760d0ab | 3631 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3632 | { |
3633 | bpstat bs; | |
3634 | ||
3635 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3636 | bs->next = NULL; |
3637 | **bs_link_pointer = bs; | |
3638 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3639 | bs->breakpoint_at = bl->owner; |
3640 | bs->bp_location_at = bl; | |
3641 | incref_bp_location (bl); | |
c906108c SS |
3642 | /* If the condition is false, etc., don't do the commands. */ |
3643 | bs->commands = NULL; | |
9add0f1b | 3644 | bs->commands_left = NULL; |
c906108c SS |
3645 | bs->old_val = NULL; |
3646 | bs->print_it = print_it_normal; | |
3647 | return bs; | |
3648 | } | |
3649 | \f | |
d983da9c DJ |
3650 | /* The target has stopped with waitstatus WS. Check if any hardware |
3651 | watchpoints have triggered, according to the target. */ | |
3652 | ||
3653 | int | |
3654 | watchpoints_triggered (struct target_waitstatus *ws) | |
3655 | { | |
d92524f1 | 3656 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3657 | CORE_ADDR addr; |
3658 | struct breakpoint *b; | |
3659 | ||
3660 | if (!stopped_by_watchpoint) | |
3661 | { | |
3662 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3663 | as not triggered. */ | |
3664 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3665 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3666 | b->watchpoint_triggered = watch_triggered_no; |
3667 | ||
3668 | return 0; | |
3669 | } | |
3670 | ||
3671 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3672 | { | |
3673 | /* We were stopped by a watchpoint, but we don't know where. | |
3674 | Mark all watchpoints as unknown. */ | |
3675 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3676 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3677 | b->watchpoint_triggered = watch_triggered_unknown; |
3678 | ||
3679 | return stopped_by_watchpoint; | |
3680 | } | |
3681 | ||
3682 | /* The target could report the data address. Mark watchpoints | |
3683 | affected by this data address as triggered, and all others as not | |
3684 | triggered. */ | |
3685 | ||
3686 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3687 | if (is_hardware_watchpoint (b)) |
d983da9c | 3688 | { |
a5606eee | 3689 | struct bp_location *loc; |
d983da9c DJ |
3690 | |
3691 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3692 | for (loc = b->loc; loc; loc = loc->next) |
3693 | /* Exact match not required. Within range is | |
3694 | sufficient. */ | |
5009afc5 AS |
3695 | if (target_watchpoint_addr_within_range (¤t_target, |
3696 | addr, loc->address, | |
3697 | loc->length)) | |
a5606eee VP |
3698 | { |
3699 | b->watchpoint_triggered = watch_triggered_yes; | |
3700 | break; | |
3701 | } | |
d983da9c DJ |
3702 | } |
3703 | ||
3704 | return 1; | |
3705 | } | |
3706 | ||
c906108c SS |
3707 | /* Possible return values for watchpoint_check (this can't be an enum |
3708 | because of check_errors). */ | |
3709 | /* The watchpoint has been deleted. */ | |
3710 | #define WP_DELETED 1 | |
3711 | /* The value has changed. */ | |
3712 | #define WP_VALUE_CHANGED 2 | |
3713 | /* The value has not changed. */ | |
3714 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3715 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3716 | #define WP_IGNORE 4 | |
c906108c SS |
3717 | |
3718 | #define BP_TEMPFLAG 1 | |
3719 | #define BP_HARDWAREFLAG 2 | |
3720 | ||
4a64f543 MS |
3721 | /* Evaluate watchpoint condition expression and check if its value |
3722 | changed. | |
553e4c11 JB |
3723 | |
3724 | P should be a pointer to struct bpstat, but is defined as a void * | |
3725 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3726 | |
3727 | static int | |
4efb68b1 | 3728 | watchpoint_check (void *p) |
c906108c SS |
3729 | { |
3730 | bpstat bs = (bpstat) p; | |
3731 | struct breakpoint *b; | |
3732 | struct frame_info *fr; | |
3733 | int within_current_scope; | |
3734 | ||
f431efe5 | 3735 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3736 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3737 | b = bs->breakpoint_at; |
c906108c | 3738 | |
f6bc2008 PA |
3739 | /* If this is a local watchpoint, we only want to check if the |
3740 | watchpoint frame is in scope if the current thread is the thread | |
3741 | that was used to create the watchpoint. */ | |
3742 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3743 | return WP_IGNORE; |
f6bc2008 | 3744 | |
c906108c SS |
3745 | if (b->exp_valid_block == NULL) |
3746 | within_current_scope = 1; | |
3747 | else | |
3748 | { | |
edb3359d DJ |
3749 | struct frame_info *frame = get_current_frame (); |
3750 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3751 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3752 | ||
4a64f543 MS |
3753 | /* in_function_epilogue_p() returns a non-zero value if we're |
3754 | still in the function but the stack frame has already been | |
3755 | invalidated. Since we can't rely on the values of local | |
3756 | variables after the stack has been destroyed, we are treating | |
3757 | the watchpoint in that state as `not changed' without further | |
3758 | checking. Don't mark watchpoints as changed if the current | |
3759 | frame is in an epilogue - even if they are in some other | |
3760 | frame, our view of the stack is likely to be wrong and | |
3761 | frame_find_by_id could error out. */ | |
a0f49112 | 3762 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3763 | return WP_IGNORE; |
a0f49112 | 3764 | |
101dcfbe | 3765 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3766 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3767 | |
3768 | /* If we've gotten confused in the unwinder, we might have | |
3769 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3770 | if (within_current_scope) |
3771 | { | |
3772 | struct symbol *function; | |
3773 | ||
3774 | function = get_frame_function (fr); | |
3775 | if (function == NULL | |
3776 | || !contained_in (b->exp_valid_block, | |
3777 | SYMBOL_BLOCK_VALUE (function))) | |
3778 | within_current_scope = 0; | |
3779 | } | |
69fbadd5 | 3780 | |
edb3359d | 3781 | if (within_current_scope) |
c906108c SS |
3782 | /* If we end up stopping, the current frame will get selected |
3783 | in normal_stop. So this call to select_frame won't affect | |
3784 | the user. */ | |
0f7d239c | 3785 | select_frame (fr); |
c906108c | 3786 | } |
c5aa993b | 3787 | |
c906108c SS |
3788 | if (within_current_scope) |
3789 | { | |
4a64f543 MS |
3790 | /* We use value_{,free_to_}mark because it could be a *long* |
3791 | time before we return to the command level and call | |
3792 | free_all_values. We can't call free_all_values because we | |
3793 | might be in the middle of evaluating a function call. */ | |
c906108c | 3794 | |
0cf6dd15 | 3795 | int pc = 0; |
278cd55f | 3796 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3797 | struct value *new_val; |
3798 | ||
0cf6dd15 | 3799 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3800 | |
4a64f543 MS |
3801 | /* We use value_equal_contents instead of value_equal because |
3802 | the latter coerces an array to a pointer, thus comparing just | |
3803 | the address of the array instead of its contents. This is | |
3804 | not what we want. */ | |
fa4727a6 | 3805 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3806 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3807 | { |
fa4727a6 DJ |
3808 | if (new_val != NULL) |
3809 | { | |
3810 | release_value (new_val); | |
3811 | value_free_to_mark (mark); | |
3812 | } | |
c906108c SS |
3813 | bs->old_val = b->val; |
3814 | b->val = new_val; | |
fa4727a6 | 3815 | b->val_valid = 1; |
c906108c SS |
3816 | return WP_VALUE_CHANGED; |
3817 | } | |
3818 | else | |
3819 | { | |
60e1c644 | 3820 | /* Nothing changed. */ |
c906108c | 3821 | value_free_to_mark (mark); |
c906108c SS |
3822 | return WP_VALUE_NOT_CHANGED; |
3823 | } | |
3824 | } | |
3825 | else | |
3826 | { | |
3827 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3828 | if we temporarily ignored the watchpoint, then when |
3829 | we reenter the block in which it is valid it contains | |
3830 | garbage (in the case of a function, it may have two | |
3831 | garbage values, one before and one after the prologue). | |
3832 | So we can't even detect the first assignment to it and | |
3833 | watch after that (since the garbage may or may not equal | |
3834 | the first value assigned). */ | |
4ce44c66 JM |
3835 | /* We print all the stop information in print_it_typical(), but |
3836 | in this case, by the time we call print_it_typical() this bp | |
4a64f543 MS |
3837 | will be deleted already. So we have no choice but print the |
3838 | information here. */ | |
9dc5e2a9 | 3839 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3840 | ui_out_field_string |
3841 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3842 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3843 | ui_out_field_int (uiout, "wpnum", b->number); |
3e43a32a MS |
3844 | ui_out_text (uiout, |
3845 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3846 | which its expression is valid.\n"); |
4ce44c66 | 3847 | |
c906108c | 3848 | if (b->related_breakpoint) |
60e1c644 PA |
3849 | { |
3850 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3851 | b->related_breakpoint->related_breakpoint = NULL; | |
3852 | b->related_breakpoint = NULL; | |
3853 | } | |
b5de0fa7 | 3854 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3855 | |
3856 | return WP_DELETED; | |
3857 | } | |
3858 | } | |
3859 | ||
18a18393 VP |
3860 | /* Return true if it looks like target has stopped due to hitting |
3861 | breakpoint location BL. This function does not check if we | |
3862 | should stop, only if BL explains the stop. */ | |
3863 | static int | |
6c95b8df PA |
3864 | bpstat_check_location (const struct bp_location *bl, |
3865 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3866 | { |
3867 | struct breakpoint *b = bl->owner; | |
3868 | ||
2bdf28a0 JK |
3869 | /* BL is from existing struct breakpoint. */ |
3870 | gdb_assert (b != NULL); | |
3871 | ||
e8595ef6 SS |
3872 | /* By definition, the inferior does not report stops at |
3873 | tracepoints. */ | |
d77f58be | 3874 | if (is_tracepoint (b)) |
e8595ef6 SS |
3875 | return 0; |
3876 | ||
cc60f2e3 | 3877 | if (!is_watchpoint (b) |
18a18393 | 3878 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3879 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3880 | { |
6c95b8df PA |
3881 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3882 | aspace, bp_addr)) | |
18a18393 VP |
3883 | return 0; |
3884 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3885 | && section_is_overlay (bl->section) |
18a18393 VP |
3886 | && !section_is_mapped (bl->section)) |
3887 | return 0; | |
3888 | } | |
cc60f2e3 | 3889 | |
18a18393 VP |
3890 | /* Continuable hardware watchpoints are treated as non-existent if the |
3891 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3892 | some data address). Otherwise gdb won't stop on a break instruction | |
3893 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3894 | been defined. Also skip watchpoints which we know did not trigger | |
3895 | (did not match the data address). */ | |
cc60f2e3 PA |
3896 | |
3897 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3898 | && b->watchpoint_triggered == watch_triggered_no) |
3899 | return 0; | |
3900 | ||
3901 | if (b->type == bp_hardware_breakpoint) | |
3902 | { | |
3903 | if (bl->address != bp_addr) | |
3904 | return 0; | |
3905 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3906 | && section_is_overlay (bl->section) |
18a18393 VP |
3907 | && !section_is_mapped (bl->section)) |
3908 | return 0; | |
3909 | } | |
ce78b96d | 3910 | |
ce78b96d JB |
3911 | if (b->type == bp_catchpoint) |
3912 | { | |
3913 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3914 | if (!b->ops->breakpoint_hit (b)) | |
3915 | return 0; | |
3916 | } | |
3917 | ||
18a18393 VP |
3918 | return 1; |
3919 | } | |
3920 | ||
3921 | /* If BS refers to a watchpoint, determine if the watched values | |
3922 | has actually changed, and we should stop. If not, set BS->stop | |
3923 | to 0. */ | |
3924 | static void | |
3925 | bpstat_check_watchpoint (bpstat bs) | |
3926 | { | |
2bdf28a0 JK |
3927 | const struct bp_location *bl; |
3928 | struct breakpoint *b; | |
3929 | ||
3930 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3931 | bl = bs->bp_location_at; |
2bdf28a0 | 3932 | gdb_assert (bl != NULL); |
f431efe5 | 3933 | b = bs->breakpoint_at; |
2bdf28a0 | 3934 | gdb_assert (b != NULL); |
18a18393 | 3935 | |
cc60f2e3 | 3936 | if (is_watchpoint (b)) |
18a18393 | 3937 | { |
18a18393 VP |
3938 | int must_check_value = 0; |
3939 | ||
3940 | if (b->type == bp_watchpoint) | |
3941 | /* For a software watchpoint, we must always check the | |
3942 | watched value. */ | |
3943 | must_check_value = 1; | |
3944 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3945 | /* We have a hardware watchpoint (read, write, or access) | |
3946 | and the target earlier reported an address watched by | |
3947 | this watchpoint. */ | |
3948 | must_check_value = 1; | |
3949 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3950 | && b->type == bp_hardware_watchpoint) | |
3951 | /* We were stopped by a hardware watchpoint, but the target could | |
3952 | not report the data address. We must check the watchpoint's | |
3953 | value. Access and read watchpoints are out of luck; without | |
3954 | a data address, we can't figure it out. */ | |
3955 | must_check_value = 1; | |
3956 | ||
3957 | if (must_check_value) | |
3958 | { | |
3e43a32a MS |
3959 | char *message |
3960 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3961 | b->number); | |
18a18393 VP |
3962 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3963 | int e = catch_errors (watchpoint_check, bs, message, | |
3964 | RETURN_MASK_ALL); | |
3965 | do_cleanups (cleanups); | |
3966 | switch (e) | |
3967 | { | |
3968 | case WP_DELETED: | |
3969 | /* We've already printed what needs to be printed. */ | |
3970 | bs->print_it = print_it_done; | |
3971 | /* Stop. */ | |
3972 | break; | |
60e1c644 PA |
3973 | case WP_IGNORE: |
3974 | bs->print_it = print_it_noop; | |
3975 | bs->stop = 0; | |
3976 | break; | |
18a18393 VP |
3977 | case WP_VALUE_CHANGED: |
3978 | if (b->type == bp_read_watchpoint) | |
3979 | { | |
85d721b8 PA |
3980 | /* There are two cases to consider here: |
3981 | ||
4a64f543 | 3982 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3983 | In that case, trust the target, and always report |
3984 | the watchpoint hit to the user. Even though | |
3985 | reads don't cause value changes, the value may | |
3986 | have changed since the last time it was read, and | |
3987 | since we're not trapping writes, we will not see | |
3988 | those, and as such we should ignore our notion of | |
3989 | old value. | |
3990 | ||
4a64f543 | 3991 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3992 | reads and writes. There are two ways this may |
3993 | happen: | |
3994 | ||
4a64f543 | 3995 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3996 | reads only, but can break on accesses (reads or |
3997 | writes), such as e.g., x86. We detect this case | |
3998 | at the time we try to insert read watchpoints. | |
3999 | ||
4a64f543 | 4000 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
4001 | watchpoints, but, the user set an access or write |
4002 | watchpoint watching the same memory as this read | |
4003 | watchpoint. | |
4004 | ||
4005 | If we're watching memory writes as well as reads, | |
4006 | ignore watchpoint hits when we find that the | |
4007 | value hasn't changed, as reads don't cause | |
4008 | changes. This still gives false positives when | |
4009 | the program writes the same value to memory as | |
4010 | what there was already in memory (we will confuse | |
4011 | it for a read), but it's much better than | |
4012 | nothing. */ | |
4013 | ||
4014 | int other_write_watchpoint = 0; | |
4015 | ||
4016 | if (bl->watchpoint_type == hw_read) | |
4017 | { | |
4018 | struct breakpoint *other_b; | |
4019 | ||
4020 | ALL_BREAKPOINTS (other_b) | |
4021 | if ((other_b->type == bp_hardware_watchpoint | |
4022 | || other_b->type == bp_access_watchpoint) | |
4023 | && (other_b->watchpoint_triggered | |
4024 | == watch_triggered_yes)) | |
4025 | { | |
4026 | other_write_watchpoint = 1; | |
4027 | break; | |
4028 | } | |
4029 | } | |
4030 | ||
4031 | if (other_write_watchpoint | |
4032 | || bl->watchpoint_type == hw_access) | |
4033 | { | |
4034 | /* We're watching the same memory for writes, | |
4035 | and the value changed since the last time we | |
4036 | updated it, so this trap must be for a write. | |
4037 | Ignore it. */ | |
4038 | bs->print_it = print_it_noop; | |
4039 | bs->stop = 0; | |
4040 | } | |
18a18393 VP |
4041 | } |
4042 | break; | |
4043 | case WP_VALUE_NOT_CHANGED: | |
4044 | if (b->type == bp_hardware_watchpoint | |
4045 | || b->type == bp_watchpoint) | |
4046 | { | |
4047 | /* Don't stop: write watchpoints shouldn't fire if | |
4048 | the value hasn't changed. */ | |
4049 | bs->print_it = print_it_noop; | |
4050 | bs->stop = 0; | |
4051 | } | |
4052 | /* Stop. */ | |
4053 | break; | |
4054 | default: | |
4055 | /* Can't happen. */ | |
4056 | case 0: | |
4057 | /* Error from catch_errors. */ | |
4058 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
4059 | if (b->related_breakpoint) | |
4060 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
4061 | b->disposition = disp_del_at_next_stop; | |
4062 | /* We've already printed what needs to be printed. */ | |
4063 | bs->print_it = print_it_done; | |
4064 | break; | |
4065 | } | |
4066 | } | |
4067 | else /* must_check_value == 0 */ | |
4068 | { | |
4069 | /* This is a case where some watchpoint(s) triggered, but | |
4070 | not at the address of this watchpoint, or else no | |
4071 | watchpoint triggered after all. So don't print | |
4072 | anything for this watchpoint. */ | |
4073 | bs->print_it = print_it_noop; | |
4074 | bs->stop = 0; | |
4075 | } | |
4076 | } | |
4077 | } | |
4078 | ||
4079 | ||
4080 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4081 | of breakpoint referred to by BS. If we should not stop for this | |
4082 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4083 | |
18a18393 VP |
4084 | static void |
4085 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4086 | { | |
4087 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4088 | const struct bp_location *bl; |
4089 | struct breakpoint *b; | |
4090 | ||
4091 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4092 | bl = bs->bp_location_at; |
2bdf28a0 | 4093 | gdb_assert (bl != NULL); |
f431efe5 | 4094 | b = bs->breakpoint_at; |
2bdf28a0 | 4095 | gdb_assert (b != NULL); |
18a18393 VP |
4096 | |
4097 | if (frame_id_p (b->frame_id) | |
edb3359d | 4098 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4099 | bs->stop = 0; |
4100 | else if (bs->stop) | |
4101 | { | |
4102 | int value_is_zero = 0; | |
60e1c644 PA |
4103 | struct expression *cond; |
4104 | ||
60e1c644 PA |
4105 | if (is_watchpoint (b)) |
4106 | cond = b->cond_exp; | |
4107 | else | |
4108 | cond = bl->cond; | |
4109 | ||
f431efe5 | 4110 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4111 | { |
60e1c644 PA |
4112 | int within_current_scope = 1; |
4113 | ||
c5bc3a77 DJ |
4114 | /* We use value_mark and value_free_to_mark because it could |
4115 | be a long time before we return to the command level and | |
4116 | call free_all_values. We can't call free_all_values | |
4117 | because we might be in the middle of evaluating a | |
4118 | function call. */ | |
4119 | struct value *mark = value_mark (); | |
4120 | ||
edb3359d DJ |
4121 | /* Need to select the frame, with all that implies so that |
4122 | the conditions will have the right context. Because we | |
4123 | use the frame, we will not see an inlined function's | |
4124 | variables when we arrive at a breakpoint at the start | |
4125 | of the inlined function; the current frame will be the | |
4126 | call site. */ | |
60e1c644 PA |
4127 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
4128 | select_frame (get_current_frame ()); | |
4129 | else | |
4130 | { | |
4131 | struct frame_info *frame; | |
4132 | ||
4133 | /* For local watchpoint expressions, which particular | |
4134 | instance of a local is being watched matters, so we | |
4135 | keep track of the frame to evaluate the expression | |
4136 | in. To evaluate the condition however, it doesn't | |
4137 | really matter which instantiation of the function | |
4138 | where the condition makes sense triggers the | |
4139 | watchpoint. This allows an expression like "watch | |
4140 | global if q > 10" set in `func', catch writes to | |
4141 | global on all threads that call `func', or catch | |
4142 | writes on all recursive calls of `func' by a single | |
4143 | thread. We simply always evaluate the condition in | |
4144 | the innermost frame that's executing where it makes | |
4145 | sense to evaluate the condition. It seems | |
4146 | intuitive. */ | |
4147 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4148 | if (frame != NULL) | |
4149 | select_frame (frame); | |
4150 | else | |
4151 | within_current_scope = 0; | |
4152 | } | |
4153 | if (within_current_scope) | |
4154 | value_is_zero | |
4155 | = catch_errors (breakpoint_cond_eval, cond, | |
4156 | "Error in testing breakpoint condition:\n", | |
4157 | RETURN_MASK_ALL); | |
4158 | else | |
4159 | { | |
4160 | warning (_("Watchpoint condition cannot be tested " | |
4161 | "in the current scope")); | |
4162 | /* If we failed to set the right context for this | |
4163 | watchpoint, unconditionally report it. */ | |
4164 | value_is_zero = 0; | |
4165 | } | |
4a64f543 | 4166 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4167 | value_free_to_mark (mark); |
18a18393 | 4168 | } |
60e1c644 PA |
4169 | |
4170 | if (cond && value_is_zero) | |
18a18393 VP |
4171 | { |
4172 | bs->stop = 0; | |
4173 | } | |
4174 | else if (b->thread != -1 && b->thread != thread_id) | |
4175 | { | |
4176 | bs->stop = 0; | |
4177 | } | |
4178 | else if (b->ignore_count > 0) | |
4179 | { | |
4180 | b->ignore_count--; | |
4181 | annotate_ignore_count_change (); | |
4182 | bs->stop = 0; | |
4a64f543 | 4183 | /* Increase the hit count even though we don't stop. */ |
18a18393 VP |
4184 | ++(b->hit_count); |
4185 | } | |
4186 | } | |
4187 | } | |
4188 | ||
4189 | ||
9709f61c | 4190 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4191 | BP_ADDR in thread PTID. |
c906108c | 4192 | |
d983da9c | 4193 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4194 | don't understand this stop. Result is a chain of bpstat's such |
4195 | that: | |
c906108c | 4196 | |
c5aa993b | 4197 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4198 | |
c5aa993b | 4199 | if we understand why we stopped, the result is not null. |
c906108c | 4200 | |
c5aa993b JM |
4201 | Each element of the chain refers to a particular breakpoint or |
4202 | watchpoint at which we have stopped. (We may have stopped for | |
4203 | several reasons concurrently.) | |
c906108c | 4204 | |
c5aa993b JM |
4205 | Each element of the chain has valid next, breakpoint_at, |
4206 | commands, FIXME??? fields. */ | |
c906108c SS |
4207 | |
4208 | bpstat | |
6c95b8df PA |
4209 | bpstat_stop_status (struct address_space *aspace, |
4210 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4211 | { |
0d381245 | 4212 | struct breakpoint *b = NULL; |
afe38095 | 4213 | struct bp_location *bl; |
20874c92 | 4214 | struct bp_location *loc; |
5760d0ab JK |
4215 | /* First item of allocated bpstat's. */ |
4216 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4217 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4218 | bpstat bs; |
20874c92 | 4219 | int ix; |
429374b8 | 4220 | int need_remove_insert; |
f431efe5 | 4221 | int removed_any; |
c906108c | 4222 | |
f431efe5 PA |
4223 | /* First, build the bpstat chain with locations that explain a |
4224 | target stop, while being careful to not set the target running, | |
4225 | as that may invalidate locations (in particular watchpoint | |
4226 | locations are recreated). Resuming will happen here with | |
4227 | breakpoint conditions or watchpoint expressions that include | |
4228 | inferior function calls. */ | |
c5aa993b | 4229 | |
429374b8 JK |
4230 | ALL_BREAKPOINTS (b) |
4231 | { | |
4232 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4233 | continue; | |
a5606eee | 4234 | |
429374b8 JK |
4235 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4236 | { | |
4a64f543 MS |
4237 | /* For hardware watchpoints, we look only at the first |
4238 | location. The watchpoint_check function will work on the | |
4239 | entire expression, not the individual locations. For | |
4240 | read watchpoints, the watchpoints_triggered function has | |
4241 | checked all locations already. */ | |
429374b8 JK |
4242 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4243 | break; | |
18a18393 | 4244 | |
429374b8 JK |
4245 | if (bl->shlib_disabled) |
4246 | continue; | |
c5aa993b | 4247 | |
429374b8 JK |
4248 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4249 | continue; | |
c5aa993b | 4250 | |
4a64f543 MS |
4251 | /* Come here if it's a watchpoint, or if the break address |
4252 | matches. */ | |
c5aa993b | 4253 | |
4a64f543 MS |
4254 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4255 | explain stop. */ | |
c5aa993b | 4256 | |
f431efe5 PA |
4257 | /* Assume we stop. Should we find a watchpoint that is not |
4258 | actually triggered, or if the condition of the breakpoint | |
4259 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4260 | bs->stop = 1; |
4261 | bs->print = 1; | |
d983da9c | 4262 | |
f431efe5 PA |
4263 | /* If this is a scope breakpoint, mark the associated |
4264 | watchpoint as triggered so that we will handle the | |
4265 | out-of-scope event. We'll get to the watchpoint next | |
4266 | iteration. */ | |
4267 | if (b->type == bp_watchpoint_scope) | |
4268 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
4269 | } | |
4270 | } | |
4271 | ||
4272 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4273 | { | |
4274 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, | |
4275 | aspace, bp_addr)) | |
4276 | { | |
5760d0ab | 4277 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4278 | /* For hits of moribund locations, we should just proceed. */ |
4279 | bs->stop = 0; | |
4280 | bs->print = 0; | |
4281 | bs->print_it = print_it_noop; | |
4282 | } | |
4283 | } | |
4284 | ||
f431efe5 PA |
4285 | /* Now go through the locations that caused the target to stop, and |
4286 | check whether we're interested in reporting this stop to higher | |
4287 | layers, or whether we should resume the target transparently. */ | |
4288 | ||
4289 | removed_any = 0; | |
4290 | ||
5760d0ab | 4291 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4292 | { |
4293 | if (!bs->stop) | |
4294 | continue; | |
4295 | ||
4296 | bpstat_check_watchpoint (bs); | |
4297 | if (!bs->stop) | |
4298 | continue; | |
4299 | ||
4300 | b = bs->breakpoint_at; | |
18a18393 | 4301 | |
429374b8 | 4302 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d | 4303 | || b->type == bp_longjmp_master |
186c406b TT |
4304 | || b->type == bp_std_terminate_master |
4305 | || b->type == bp_exception_master) | |
429374b8 JK |
4306 | /* We do not stop for these. */ |
4307 | bs->stop = 0; | |
4308 | else | |
4309 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4310 | |
429374b8 JK |
4311 | if (bs->stop) |
4312 | { | |
4313 | ++(b->hit_count); | |
c906108c | 4314 | |
4a64f543 | 4315 | /* We will stop here. */ |
429374b8 JK |
4316 | if (b->disposition == disp_disable) |
4317 | { | |
4318 | if (b->enable_state != bp_permanent) | |
4319 | b->enable_state = bp_disabled; | |
f431efe5 | 4320 | removed_any = 1; |
429374b8 JK |
4321 | } |
4322 | if (b->silent) | |
4323 | bs->print = 0; | |
4324 | bs->commands = b->commands; | |
9add0f1b TT |
4325 | incref_counted_command_line (bs->commands); |
4326 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4327 | if (bs->commands_left | |
4328 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4329 | || (xdb_commands | |
4330 | && strcmp ("Q", | |
4331 | bs->commands_left->line) == 0))) | |
429374b8 | 4332 | { |
9add0f1b | 4333 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4334 | bs->print = 0; |
4335 | } | |
429374b8 JK |
4336 | } |
4337 | ||
4338 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4339 | if (bs->stop == 0 || bs->print == 0) | |
4340 | bs->print_it = print_it_noop; | |
429374b8 | 4341 | } |
876fa593 | 4342 | |
d983da9c DJ |
4343 | /* If we aren't stopping, the value of some hardware watchpoint may |
4344 | not have changed, but the intermediate memory locations we are | |
4345 | watching may have. Don't bother if we're stopping; this will get | |
4346 | done later. */ | |
d832cb68 | 4347 | need_remove_insert = 0; |
5760d0ab JK |
4348 | if (! bpstat_causes_stop (bs_head)) |
4349 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4350 | if (!bs->stop |
f431efe5 PA |
4351 | && bs->breakpoint_at |
4352 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4353 | { |
4a64f543 | 4354 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4355 | need_remove_insert = 1; |
d983da9c DJ |
4356 | } |
4357 | ||
d832cb68 | 4358 | if (need_remove_insert) |
2d134ed3 | 4359 | update_global_location_list (1); |
f431efe5 PA |
4360 | else if (removed_any) |
4361 | update_global_location_list (0); | |
d832cb68 | 4362 | |
5760d0ab | 4363 | return bs_head; |
c906108c | 4364 | } |
628fe4e4 JK |
4365 | |
4366 | static void | |
4367 | handle_jit_event (void) | |
4368 | { | |
4369 | struct frame_info *frame; | |
4370 | struct gdbarch *gdbarch; | |
4371 | ||
4372 | /* Switch terminal for any messages produced by | |
4373 | breakpoint_re_set. */ | |
4374 | target_terminal_ours_for_output (); | |
4375 | ||
4376 | frame = get_current_frame (); | |
4377 | gdbarch = get_frame_arch (frame); | |
4378 | ||
4379 | jit_event_handler (gdbarch); | |
4380 | ||
4381 | target_terminal_inferior (); | |
4382 | } | |
4383 | ||
4384 | /* Prepare WHAT final decision for infrun. */ | |
4385 | ||
4386 | /* Decide what infrun needs to do with this bpstat. */ | |
4387 | ||
c906108c | 4388 | struct bpstat_what |
fba45db2 | 4389 | bpstat_what (bpstat bs) |
c906108c | 4390 | { |
c906108c | 4391 | struct bpstat_what retval; |
628fe4e4 JK |
4392 | /* We need to defer calling `solib_add', as adding new symbols |
4393 | resets breakpoints, which in turn deletes breakpoint locations, | |
4394 | and hence may clear unprocessed entries in the BS chain. */ | |
4395 | int shlib_event = 0; | |
4396 | int jit_event = 0; | |
c906108c | 4397 | |
628fe4e4 | 4398 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4399 | retval.call_dummy = STOP_NONE; |
186c406b | 4400 | retval.is_longjmp = 0; |
628fe4e4 | 4401 | |
c906108c SS |
4402 | for (; bs != NULL; bs = bs->next) |
4403 | { | |
628fe4e4 JK |
4404 | /* Extract this BS's action. After processing each BS, we check |
4405 | if its action overrides all we've seem so far. */ | |
4406 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4407 | enum bptype bptype; | |
4408 | ||
c906108c | 4409 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4410 | { |
4411 | /* I suspect this can happen if it was a momentary | |
4412 | breakpoint which has since been deleted. */ | |
4413 | bptype = bp_none; | |
4414 | } | |
f431efe5 | 4415 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4416 | bptype = bp_none; |
20874c92 | 4417 | else |
f431efe5 | 4418 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4419 | |
4420 | switch (bptype) | |
c906108c SS |
4421 | { |
4422 | case bp_none: | |
628fe4e4 | 4423 | break; |
c906108c SS |
4424 | case bp_breakpoint: |
4425 | case bp_hardware_breakpoint: | |
4426 | case bp_until: | |
4427 | case bp_finish: | |
4428 | if (bs->stop) | |
4429 | { | |
4430 | if (bs->print) | |
628fe4e4 | 4431 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4432 | else |
628fe4e4 | 4433 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4434 | } |
4435 | else | |
628fe4e4 | 4436 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4437 | break; |
4438 | case bp_watchpoint: | |
4439 | case bp_hardware_watchpoint: | |
4440 | case bp_read_watchpoint: | |
4441 | case bp_access_watchpoint: | |
4442 | if (bs->stop) | |
4443 | { | |
4444 | if (bs->print) | |
628fe4e4 | 4445 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4446 | else |
628fe4e4 | 4447 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4448 | } |
4449 | else | |
628fe4e4 JK |
4450 | { |
4451 | /* There was a watchpoint, but we're not stopping. | |
4452 | This requires no further action. */ | |
4453 | } | |
c906108c SS |
4454 | break; |
4455 | case bp_longjmp: | |
186c406b | 4456 | case bp_exception: |
628fe4e4 | 4457 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4458 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4459 | break; |
4460 | case bp_longjmp_resume: | |
186c406b | 4461 | case bp_exception_resume: |
628fe4e4 | 4462 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4463 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4464 | break; |
4465 | case bp_step_resume: | |
4466 | if (bs->stop) | |
628fe4e4 JK |
4467 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4468 | else | |
c906108c | 4469 | { |
628fe4e4 JK |
4470 | /* It is for the wrong frame. */ |
4471 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4472 | } |
c906108c | 4473 | break; |
c906108c | 4474 | case bp_watchpoint_scope: |
c4093a6a | 4475 | case bp_thread_event: |
1900040c | 4476 | case bp_overlay_event: |
0fd8e87f | 4477 | case bp_longjmp_master: |
aa7d318d | 4478 | case bp_std_terminate_master: |
186c406b | 4479 | case bp_exception_master: |
628fe4e4 | 4480 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4481 | break; |
ce78b96d | 4482 | case bp_catchpoint: |
c5aa993b JM |
4483 | if (bs->stop) |
4484 | { | |
4485 | if (bs->print) | |
628fe4e4 | 4486 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4487 | else |
628fe4e4 | 4488 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4489 | } |
4490 | else | |
628fe4e4 JK |
4491 | { |
4492 | /* There was a catchpoint, but we're not stopping. | |
4493 | This requires no further action. */ | |
4494 | } | |
4495 | break; | |
4496 | case bp_shlib_event: | |
4497 | shlib_event = 1; | |
4498 | ||
4499 | /* If requested, stop when the dynamic linker notifies GDB | |
4500 | of events. This allows the user to get control and place | |
4501 | breakpoints in initializer routines for dynamically | |
4502 | loaded objects (among other things). */ | |
4503 | if (stop_on_solib_events) | |
4504 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4505 | else | |
4506 | this_action = BPSTAT_WHAT_SINGLE; | |
4507 | break; | |
4508 | case bp_jit_event: | |
4509 | jit_event = 1; | |
4510 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4511 | break; |
c906108c | 4512 | case bp_call_dummy: |
53a5351d JM |
4513 | /* Make sure the action is stop (silent or noisy), |
4514 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4515 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4516 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4517 | break; |
4518 | case bp_std_terminate: | |
4519 | /* Make sure the action is stop (silent or noisy), | |
4520 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4521 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4522 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4523 | break; |
1042e4c0 | 4524 | case bp_tracepoint: |
7a697b8d | 4525 | case bp_fast_tracepoint: |
0fb4aa4b | 4526 | case bp_static_tracepoint: |
1042e4c0 SS |
4527 | /* Tracepoint hits should not be reported back to GDB, and |
4528 | if one got through somehow, it should have been filtered | |
4529 | out already. */ | |
4530 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4531 | _("bpstat_what: tracepoint encountered")); |
628fe4e4 JK |
4532 | default: |
4533 | internal_error (__FILE__, __LINE__, | |
4534 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4535 | } |
628fe4e4 JK |
4536 | |
4537 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4538 | } |
628fe4e4 JK |
4539 | |
4540 | if (shlib_event) | |
4541 | { | |
4542 | if (debug_infrun) | |
4543 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4544 | ||
4545 | /* Check for any newly added shared libraries if we're supposed | |
4546 | to be adding them automatically. */ | |
4547 | ||
4548 | /* Switch terminal for any messages produced by | |
4549 | breakpoint_re_set. */ | |
4550 | target_terminal_ours_for_output (); | |
4551 | ||
4552 | #ifdef SOLIB_ADD | |
4553 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4554 | #else | |
4555 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4556 | #endif | |
4557 | ||
4558 | target_terminal_inferior (); | |
4559 | } | |
4560 | ||
4561 | if (jit_event) | |
4562 | { | |
4563 | if (debug_infrun) | |
4564 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4565 | ||
4566 | handle_jit_event (); | |
4567 | } | |
4568 | ||
c906108c SS |
4569 | return retval; |
4570 | } | |
4571 | ||
4572 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4573 | without hardware support). This isn't related to a specific bpstat, | |
4574 | just to things like whether watchpoints are set. */ | |
4575 | ||
c5aa993b | 4576 | int |
fba45db2 | 4577 | bpstat_should_step (void) |
c906108c SS |
4578 | { |
4579 | struct breakpoint *b; | |
cc59ec59 | 4580 | |
c906108c | 4581 | ALL_BREAKPOINTS (b) |
717a8278 | 4582 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4583 | return 1; |
c906108c SS |
4584 | return 0; |
4585 | } | |
4586 | ||
67822962 PA |
4587 | int |
4588 | bpstat_causes_stop (bpstat bs) | |
4589 | { | |
4590 | for (; bs != NULL; bs = bs->next) | |
4591 | if (bs->stop) | |
4592 | return 1; | |
4593 | ||
4594 | return 0; | |
4595 | } | |
4596 | ||
c906108c | 4597 | \f |
c5aa993b | 4598 | |
859825b8 JK |
4599 | /* Print the LOC location out of the list of B->LOC locations. */ |
4600 | ||
0d381245 VP |
4601 | static void print_breakpoint_location (struct breakpoint *b, |
4602 | struct bp_location *loc, | |
4603 | char *wrap_indent, | |
4604 | struct ui_stream *stb) | |
4605 | { | |
6c95b8df PA |
4606 | struct cleanup *old_chain = save_current_program_space (); |
4607 | ||
859825b8 JK |
4608 | if (loc != NULL && loc->shlib_disabled) |
4609 | loc = NULL; | |
4610 | ||
6c95b8df PA |
4611 | if (loc != NULL) |
4612 | set_current_program_space (loc->pspace); | |
4613 | ||
859825b8 | 4614 | if (b->source_file && loc) |
0d381245 VP |
4615 | { |
4616 | struct symbol *sym | |
4617 | = find_pc_sect_function (loc->address, loc->section); | |
4618 | if (sym) | |
4619 | { | |
4620 | ui_out_text (uiout, "in "); | |
4621 | ui_out_field_string (uiout, "func", | |
4622 | SYMBOL_PRINT_NAME (sym)); | |
4623 | ui_out_wrap_hint (uiout, wrap_indent); | |
4624 | ui_out_text (uiout, " at "); | |
4625 | } | |
4626 | ui_out_field_string (uiout, "file", b->source_file); | |
4627 | ui_out_text (uiout, ":"); | |
4628 | ||
4629 | if (ui_out_is_mi_like_p (uiout)) | |
4630 | { | |
4631 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4632 | char *fullname = symtab_to_fullname (sal.symtab); | |
4633 | ||
4634 | if (fullname) | |
4635 | ui_out_field_string (uiout, "fullname", fullname); | |
4636 | } | |
4637 | ||
4638 | ui_out_field_int (uiout, "line", b->line_number); | |
4639 | } | |
859825b8 | 4640 | else if (loc) |
0d381245 | 4641 | { |
22e722e1 DJ |
4642 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4643 | demangle, ""); | |
0d381245 VP |
4644 | ui_out_field_stream (uiout, "at", stb); |
4645 | } | |
859825b8 JK |
4646 | else |
4647 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4648 | |
4649 | do_cleanups (old_chain); | |
0d381245 VP |
4650 | } |
4651 | ||
269b11a2 PA |
4652 | static const char * |
4653 | bptype_string (enum bptype type) | |
c906108c | 4654 | { |
c4093a6a JM |
4655 | struct ep_type_description |
4656 | { | |
4657 | enum bptype type; | |
4658 | char *description; | |
4659 | }; | |
4660 | static struct ep_type_description bptypes[] = | |
c906108c | 4661 | { |
c5aa993b JM |
4662 | {bp_none, "?deleted?"}, |
4663 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4664 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4665 | {bp_until, "until"}, |
4666 | {bp_finish, "finish"}, | |
4667 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4668 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4669 | {bp_read_watchpoint, "read watchpoint"}, |
4670 | {bp_access_watchpoint, "acc watchpoint"}, | |
4671 | {bp_longjmp, "longjmp"}, | |
4672 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4673 | {bp_exception, "exception"}, |
4674 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4675 | {bp_step_resume, "step resume"}, |
c5aa993b JM |
4676 | {bp_watchpoint_scope, "watchpoint scope"}, |
4677 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4678 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4679 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4680 | {bp_thread_event, "thread events"}, |
1900040c | 4681 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4682 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4683 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4684 | {bp_exception_master, "exception master"}, |
ce78b96d | 4685 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4686 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4687 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4688 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4689 | {bp_jit_event, "jit events"}, |
c5aa993b | 4690 | }; |
269b11a2 PA |
4691 | |
4692 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4693 | || ((int) type != bptypes[(int) type].type)) | |
4694 | internal_error (__FILE__, __LINE__, | |
4695 | _("bptypes table does not describe type #%d."), | |
4696 | (int) type); | |
4697 | ||
4698 | return bptypes[(int) type].description; | |
4699 | } | |
4700 | ||
4701 | /* Print B to gdb_stdout. */ | |
4702 | ||
4703 | static void | |
4704 | print_one_breakpoint_location (struct breakpoint *b, | |
4705 | struct bp_location *loc, | |
4706 | int loc_number, | |
4707 | struct bp_location **last_loc, | |
4708 | int print_address_bits, | |
4709 | int allflag) | |
4710 | { | |
4711 | struct command_line *l; | |
c2c6d25f | 4712 | static char bpenables[] = "nynny"; |
c906108c | 4713 | char wrap_indent[80]; |
8b93c638 JM |
4714 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4715 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4716 | struct cleanup *bkpt_chain; |
c906108c | 4717 | |
0d381245 VP |
4718 | int header_of_multiple = 0; |
4719 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4720 | struct value_print_options opts; |
4721 | ||
4722 | get_user_print_options (&opts); | |
0d381245 VP |
4723 | |
4724 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4725 | /* See comment in print_one_breakpoint concerning treatment of |
4726 | breakpoints with single disabled location. */ | |
0d381245 VP |
4727 | if (loc == NULL |
4728 | && (b->loc != NULL | |
4729 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4730 | header_of_multiple = 1; | |
4731 | if (loc == NULL) | |
4732 | loc = b->loc; | |
4733 | ||
c4093a6a | 4734 | annotate_record (); |
3b31d625 | 4735 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4736 | |
4737 | /* 1 */ | |
4738 | annotate_field (0); | |
0d381245 VP |
4739 | if (part_of_multiple) |
4740 | { | |
4741 | char *formatted; | |
0c6773c1 | 4742 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4743 | ui_out_field_string (uiout, "number", formatted); |
4744 | xfree (formatted); | |
4745 | } | |
4746 | else | |
4747 | { | |
4748 | ui_out_field_int (uiout, "number", b->number); | |
4749 | } | |
c4093a6a JM |
4750 | |
4751 | /* 2 */ | |
4752 | annotate_field (1); | |
0d381245 VP |
4753 | if (part_of_multiple) |
4754 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4755 | else |
4756 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4757 | |
4758 | /* 3 */ | |
4759 | annotate_field (2); | |
0d381245 VP |
4760 | if (part_of_multiple) |
4761 | ui_out_field_skip (uiout, "disp"); | |
4762 | else | |
2cec12e5 | 4763 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4764 | |
c4093a6a JM |
4765 | |
4766 | /* 4 */ | |
4767 | annotate_field (3); | |
0d381245 | 4768 | if (part_of_multiple) |
54e52265 | 4769 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4770 | else |
4a64f543 MS |
4771 | ui_out_field_fmt (uiout, "enabled", "%c", |
4772 | bpenables[(int) b->enable_state]); | |
54e52265 | 4773 | ui_out_spaces (uiout, 2); |
0d381245 | 4774 | |
c4093a6a JM |
4775 | |
4776 | /* 5 and 6 */ | |
4777 | strcpy (wrap_indent, " "); | |
79a45b7d | 4778 | if (opts.addressprint) |
75ac9d7b | 4779 | { |
a6d9a66e | 4780 | if (print_address_bits <= 32) |
75ac9d7b MS |
4781 | strcat (wrap_indent, " "); |
4782 | else | |
4783 | strcat (wrap_indent, " "); | |
4784 | } | |
c906108c | 4785 | |
3086aeae | 4786 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4787 | { |
4a64f543 MS |
4788 | /* Although the print_one can possibly print all locations, |
4789 | calling it here is not likely to get any nice result. So, | |
4790 | make sure there's just one location. */ | |
0d381245 | 4791 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4792 | b->ops->print_one (b, last_loc); |
0d381245 | 4793 | } |
3086aeae DJ |
4794 | else |
4795 | switch (b->type) | |
4796 | { | |
4797 | case bp_none: | |
4798 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4799 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4800 | break; |
c906108c | 4801 | |
3086aeae DJ |
4802 | case bp_watchpoint: |
4803 | case bp_hardware_watchpoint: | |
4804 | case bp_read_watchpoint: | |
4805 | case bp_access_watchpoint: | |
4806 | /* Field 4, the address, is omitted (which makes the columns | |
4807 | not line up too nicely with the headers, but the effect | |
4808 | is relatively readable). */ | |
79a45b7d | 4809 | if (opts.addressprint) |
3086aeae DJ |
4810 | ui_out_field_skip (uiout, "addr"); |
4811 | annotate_field (5); | |
fa8a61dc | 4812 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4813 | break; |
4814 | ||
3086aeae DJ |
4815 | case bp_breakpoint: |
4816 | case bp_hardware_breakpoint: | |
4817 | case bp_until: | |
4818 | case bp_finish: | |
4819 | case bp_longjmp: | |
4820 | case bp_longjmp_resume: | |
186c406b TT |
4821 | case bp_exception: |
4822 | case bp_exception_resume: | |
3086aeae | 4823 | case bp_step_resume: |
3086aeae DJ |
4824 | case bp_watchpoint_scope: |
4825 | case bp_call_dummy: | |
aa7d318d | 4826 | case bp_std_terminate: |
3086aeae DJ |
4827 | case bp_shlib_event: |
4828 | case bp_thread_event: | |
4829 | case bp_overlay_event: | |
0fd8e87f | 4830 | case bp_longjmp_master: |
aa7d318d | 4831 | case bp_std_terminate_master: |
186c406b | 4832 | case bp_exception_master: |
1042e4c0 | 4833 | case bp_tracepoint: |
7a697b8d | 4834 | case bp_fast_tracepoint: |
0fb4aa4b | 4835 | case bp_static_tracepoint: |
4efc6507 | 4836 | case bp_jit_event: |
79a45b7d | 4837 | if (opts.addressprint) |
3086aeae DJ |
4838 | { |
4839 | annotate_field (4); | |
54e52265 | 4840 | if (header_of_multiple) |
0d381245 | 4841 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4842 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4843 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4844 | else |
5af949e3 UW |
4845 | ui_out_field_core_addr (uiout, "addr", |
4846 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4847 | } |
4848 | annotate_field (5); | |
0d381245 VP |
4849 | if (!header_of_multiple) |
4850 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4851 | if (b->loc) | |
a6d9a66e | 4852 | *last_loc = b->loc; |
3086aeae DJ |
4853 | break; |
4854 | } | |
c906108c | 4855 | |
6c95b8df PA |
4856 | |
4857 | /* For backward compatibility, don't display inferiors unless there | |
4858 | are several. */ | |
4859 | if (loc != NULL | |
4860 | && !header_of_multiple | |
4861 | && (allflag | |
4862 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4863 | && (number_of_program_spaces () > 1 | |
4864 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4865 | /* LOC is for existing B, it cannot be in |
4866 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4867 | && loc->owner->type != bp_catchpoint))) |
4868 | { | |
4869 | struct inferior *inf; | |
4870 | int first = 1; | |
4871 | ||
4872 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4873 | { | |
4874 | if (inf->pspace == loc->pspace) | |
4875 | { | |
4876 | if (first) | |
4877 | { | |
4878 | first = 0; | |
4879 | ui_out_text (uiout, " inf "); | |
4880 | } | |
4881 | else | |
4882 | ui_out_text (uiout, ", "); | |
4883 | ui_out_text (uiout, plongest (inf->num)); | |
4884 | } | |
4885 | } | |
4886 | } | |
4887 | ||
4a306c9a | 4888 | if (!part_of_multiple) |
c4093a6a | 4889 | { |
4a306c9a JB |
4890 | if (b->thread != -1) |
4891 | { | |
4892 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4893 | "stop only in" line a little further down. */ |
4a306c9a JB |
4894 | ui_out_text (uiout, " thread "); |
4895 | ui_out_field_int (uiout, "thread", b->thread); | |
4896 | } | |
4897 | else if (b->task != 0) | |
4898 | { | |
4899 | ui_out_text (uiout, " task "); | |
4900 | ui_out_field_int (uiout, "task", b->task); | |
4901 | } | |
c4093a6a JM |
4902 | } |
4903 | ||
8b93c638 | 4904 | ui_out_text (uiout, "\n"); |
c4093a6a | 4905 | |
0fb4aa4b PA |
4906 | if (!part_of_multiple && b->static_trace_marker_id) |
4907 | { | |
4908 | gdb_assert (b->type == bp_static_tracepoint); | |
4909 | ||
4910 | ui_out_text (uiout, "\tmarker id is "); | |
4911 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
4912 | b->static_trace_marker_id); | |
4913 | ui_out_text (uiout, "\n"); | |
4914 | } | |
4915 | ||
0d381245 | 4916 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4917 | { |
4918 | annotate_field (6); | |
8b93c638 | 4919 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4920 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4921 | the frame ID. */ | |
5af949e3 UW |
4922 | ui_out_field_core_addr (uiout, "frame", |
4923 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4924 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4925 | } |
4926 | ||
0d381245 | 4927 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4928 | { |
f7f9143b JB |
4929 | /* We do not print the condition for Ada exception catchpoints |
4930 | because the condition is an internal implementation detail | |
4931 | that we do not want to expose to the user. */ | |
c4093a6a | 4932 | annotate_field (7); |
d77f58be | 4933 | if (is_tracepoint (b)) |
1042e4c0 SS |
4934 | ui_out_text (uiout, "\ttrace only if "); |
4935 | else | |
4936 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4937 | ui_out_field_string (uiout, "cond", b->cond_string); |
4938 | ui_out_text (uiout, "\n"); | |
4939 | } | |
4940 | ||
0d381245 | 4941 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4942 | { |
4a64f543 | 4943 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4944 | ui_out_text (uiout, "\tstop only in thread "); |
4945 | ui_out_field_int (uiout, "thread", b->thread); | |
4946 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4947 | } |
4948 | ||
63c715c6 | 4949 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4950 | { |
4a64f543 | 4951 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4952 | if (ep_is_catchpoint (b)) |
4953 | ui_out_text (uiout, "\tcatchpoint"); | |
4954 | else | |
4955 | ui_out_text (uiout, "\tbreakpoint"); | |
4956 | ui_out_text (uiout, " already hit "); | |
4957 | ui_out_field_int (uiout, "times", b->hit_count); | |
4958 | if (b->hit_count == 1) | |
4959 | ui_out_text (uiout, " time\n"); | |
4960 | else | |
4961 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4962 | } |
4963 | ||
4a64f543 MS |
4964 | /* Output the count also if it is zero, but only if this is mi. |
4965 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4966 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4967 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4968 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4969 | |
0d381245 | 4970 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4971 | { |
4972 | annotate_field (8); | |
8b93c638 JM |
4973 | ui_out_text (uiout, "\tignore next "); |
4974 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4975 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4976 | } |
059fb39f | 4977 | |
9add0f1b | 4978 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4979 | if (!part_of_multiple && l) |
c4093a6a | 4980 | { |
3b31d625 EZ |
4981 | struct cleanup *script_chain; |
4982 | ||
c4093a6a | 4983 | annotate_field (9); |
3b31d625 | 4984 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4985 | print_command_lines (uiout, l, 4); |
3b31d625 | 4986 | do_cleanups (script_chain); |
c4093a6a | 4987 | } |
d24317b4 | 4988 | |
1042e4c0 SS |
4989 | if (!part_of_multiple && b->pass_count) |
4990 | { | |
4991 | annotate_field (10); | |
4992 | ui_out_text (uiout, "\tpass count "); | |
4993 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4994 | ui_out_text (uiout, " \n"); | |
4995 | } | |
4996 | ||
d24317b4 VP |
4997 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4998 | { | |
4999 | if (b->addr_string) | |
5000 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
5001 | else if (b->exp_string) | |
5002 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
5003 | } | |
5004 | ||
3b31d625 | 5005 | do_cleanups (bkpt_chain); |
8b93c638 | 5006 | do_cleanups (old_chain); |
c4093a6a | 5007 | } |
c5aa993b | 5008 | |
0d381245 VP |
5009 | static void |
5010 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 MS |
5011 | struct bp_location **last_loc, |
5012 | int print_address_bits, | |
6c95b8df | 5013 | int allflag) |
0d381245 | 5014 | { |
6c95b8df PA |
5015 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
5016 | print_address_bits, allflag); | |
0d381245 VP |
5017 | |
5018 | /* If this breakpoint has custom print function, | |
5019 | it's already printed. Otherwise, print individual | |
5020 | locations, if any. */ | |
5021 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5022 | { | |
4a64f543 MS |
5023 | /* If breakpoint has a single location that is disabled, we |
5024 | print it as if it had several locations, since otherwise it's | |
5025 | hard to represent "breakpoint enabled, location disabled" | |
5026 | situation. | |
5027 | ||
5028 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5029 | internally, that's not a property exposed to user. */ |
0d381245 | 5030 | if (b->loc |
a5606eee | 5031 | && !is_hardware_watchpoint (b) |
0d381245 | 5032 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 5033 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
5034 | { |
5035 | struct bp_location *loc; | |
5036 | int n = 1; | |
5037 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 5038 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 5039 | print_address_bits, allflag); |
0d381245 VP |
5040 | } |
5041 | } | |
5042 | } | |
5043 | ||
a6d9a66e UW |
5044 | static int |
5045 | breakpoint_address_bits (struct breakpoint *b) | |
5046 | { | |
5047 | int print_address_bits = 0; | |
5048 | struct bp_location *loc; | |
5049 | ||
5050 | for (loc = b->loc; loc; loc = loc->next) | |
5051 | { | |
c7437ca6 PA |
5052 | int addr_bit; |
5053 | ||
5054 | /* Software watchpoints that aren't watching memory don't have | |
5055 | an address to print. */ | |
5056 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5057 | continue; | |
5058 | ||
5059 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5060 | if (addr_bit > print_address_bits) |
5061 | print_address_bits = addr_bit; | |
5062 | } | |
5063 | ||
5064 | return print_address_bits; | |
5065 | } | |
0d381245 | 5066 | |
c4093a6a JM |
5067 | struct captured_breakpoint_query_args |
5068 | { | |
5069 | int bnum; | |
5070 | }; | |
c5aa993b | 5071 | |
c4093a6a | 5072 | static int |
2b65245e | 5073 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5074 | { |
5075 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5076 | struct breakpoint *b; |
a6d9a66e | 5077 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5078 | |
c4093a6a JM |
5079 | ALL_BREAKPOINTS (b) |
5080 | { | |
5081 | if (args->bnum == b->number) | |
c5aa993b | 5082 | { |
a6d9a66e | 5083 | int print_address_bits = breakpoint_address_bits (b); |
cc59ec59 | 5084 | |
6c95b8df | 5085 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 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 |
4a64f543 MS |
5138 | breakpoint_1 (int bnum, int allflag, |
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) | |
5155 | if (bnum == -1 | |
5156 | || bnum == b->number) | |
5157 | { | |
d77f58be SS |
5158 | /* If we have a filter, only list the breakpoints it accepts. */ |
5159 | if (filter && !filter (b)) | |
5160 | continue; | |
5161 | ||
09d682a4 | 5162 | if (allflag || user_breakpoint_p (b)) |
a6d9a66e | 5163 | { |
269b11a2 PA |
5164 | int addr_bit, type_len; |
5165 | ||
5166 | addr_bit = breakpoint_address_bits (b); | |
a6d9a66e UW |
5167 | if (addr_bit > print_address_bits) |
5168 | print_address_bits = addr_bit; | |
5169 | ||
269b11a2 PA |
5170 | type_len = strlen (bptype_string (b->type)); |
5171 | if (type_len > print_type_col_width) | |
5172 | print_type_col_width = type_len; | |
5173 | ||
a6d9a66e UW |
5174 | nr_printable_breakpoints++; |
5175 | } | |
7f3b0473 AC |
5176 | } |
5177 | ||
79a45b7d | 5178 | if (opts.addressprint) |
3b31d625 | 5179 | bkpttbl_chain |
3e43a32a MS |
5180 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5181 | nr_printable_breakpoints, | |
3b31d625 | 5182 | "BreakpointTable"); |
8b93c638 | 5183 | else |
3b31d625 | 5184 | bkpttbl_chain |
3e43a32a MS |
5185 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5186 | nr_printable_breakpoints, | |
3b31d625 | 5187 | "BreakpointTable"); |
8b93c638 | 5188 | |
7f3b0473 | 5189 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5190 | annotate_breakpoints_headers (); |
5191 | if (nr_printable_breakpoints > 0) | |
5192 | annotate_field (0); | |
4a64f543 | 5193 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5194 | if (nr_printable_breakpoints > 0) |
5195 | annotate_field (1); | |
269b11a2 | 5196 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5197 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5198 | if (nr_printable_breakpoints > 0) |
5199 | annotate_field (2); | |
4a64f543 | 5200 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5201 | if (nr_printable_breakpoints > 0) |
5202 | annotate_field (3); | |
54e52265 | 5203 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5204 | if (opts.addressprint) |
7f3b0473 | 5205 | { |
d7faa9e7 AC |
5206 | if (nr_printable_breakpoints > 0) |
5207 | annotate_field (4); | |
a6d9a66e | 5208 | if (print_address_bits <= 32) |
4a64f543 MS |
5209 | ui_out_table_header (uiout, 10, ui_left, |
5210 | "addr", "Address"); /* 5 */ | |
7f3b0473 | 5211 | else |
4a64f543 MS |
5212 | ui_out_table_header (uiout, 18, ui_left, |
5213 | "addr", "Address"); /* 5 */ | |
7f3b0473 | 5214 | } |
d7faa9e7 AC |
5215 | if (nr_printable_breakpoints > 0) |
5216 | annotate_field (5); | |
5217 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5218 | ui_out_table_body (uiout); | |
5219 | if (nr_printable_breakpoints > 0) | |
5220 | annotate_breakpoints_table (); | |
7f3b0473 | 5221 | |
c4093a6a | 5222 | ALL_BREAKPOINTS (b) |
bad56014 TT |
5223 | { |
5224 | QUIT; | |
c4093a6a JM |
5225 | if (bnum == -1 |
5226 | || bnum == b->number) | |
5227 | { | |
d77f58be SS |
5228 | /* If we have a filter, only list the breakpoints it accepts. */ |
5229 | if (filter && !filter (b)) | |
5230 | continue; | |
5231 | ||
c4093a6a | 5232 | /* We only print out user settable breakpoints unless the |
4a64f543 | 5233 | allflag is set. */ |
09d682a4 | 5234 | if (allflag || user_breakpoint_p (b)) |
6c95b8df | 5235 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a | 5236 | } |
bad56014 | 5237 | } |
c4093a6a | 5238 | |
3b31d625 | 5239 | do_cleanups (bkpttbl_chain); |
698384cd | 5240 | |
7f3b0473 | 5241 | if (nr_printable_breakpoints == 0) |
c906108c | 5242 | { |
4a64f543 MS |
5243 | /* If there's a filter, let the caller decide how to report |
5244 | empty list. */ | |
d77f58be SS |
5245 | if (!filter) |
5246 | { | |
5247 | if (bnum == -1) | |
5248 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
5249 | else | |
4a64f543 MS |
5250 | ui_out_message (uiout, 0, |
5251 | "No breakpoint or watchpoint number %d.\n", | |
d77f58be SS |
5252 | bnum); |
5253 | } | |
c906108c SS |
5254 | } |
5255 | else | |
c4093a6a | 5256 | { |
a6d9a66e UW |
5257 | if (last_loc && !server_command) |
5258 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5259 | } |
c906108c | 5260 | |
4a64f543 | 5261 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5262 | there have been breakpoints? */ |
c906108c | 5263 | annotate_breakpoints_table_end (); |
d77f58be SS |
5264 | |
5265 | return nr_printable_breakpoints; | |
c906108c SS |
5266 | } |
5267 | ||
ad443146 SS |
5268 | /* Display the value of default-collect in a way that is generally |
5269 | compatible with the breakpoint list. */ | |
5270 | ||
5271 | static void | |
5272 | default_collect_info (void) | |
5273 | { | |
5274 | /* If it has no value (which is frequently the case), say nothing; a | |
5275 | message like "No default-collect." gets in user's face when it's | |
5276 | not wanted. */ | |
5277 | if (!*default_collect) | |
5278 | return; | |
5279 | ||
5280 | /* The following phrase lines up nicely with per-tracepoint collect | |
5281 | actions. */ | |
5282 | ui_out_text (uiout, "default collect "); | |
5283 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5284 | ui_out_text (uiout, " \n"); | |
5285 | } | |
5286 | ||
c906108c | 5287 | static void |
fba45db2 | 5288 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
5289 | { |
5290 | int bnum = -1; | |
5291 | ||
5292 | if (bnum_exp) | |
bb518678 | 5293 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5294 | |
d77f58be | 5295 | breakpoint_1 (bnum, 0, NULL); |
ad443146 SS |
5296 | |
5297 | default_collect_info (); | |
d77f58be SS |
5298 | } |
5299 | ||
5300 | static void | |
5301 | watchpoints_info (char *wpnum_exp, int from_tty) | |
5302 | { | |
5303 | int wpnum = -1, num_printed; | |
5304 | ||
5305 | if (wpnum_exp) | |
5306 | wpnum = parse_and_eval_long (wpnum_exp); | |
5307 | ||
5308 | num_printed = breakpoint_1 (wpnum, 0, is_watchpoint); | |
5309 | ||
5310 | if (num_printed == 0) | |
5311 | { | |
5312 | if (wpnum == -1) | |
5313 | ui_out_message (uiout, 0, "No watchpoints.\n"); | |
5314 | else | |
5315 | ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum); | |
5316 | } | |
c906108c SS |
5317 | } |
5318 | ||
7a292a7a | 5319 | static void |
fba45db2 | 5320 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
5321 | { |
5322 | int bnum = -1; | |
5323 | ||
5324 | if (bnum_exp) | |
bb518678 | 5325 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5326 | |
d77f58be | 5327 | breakpoint_1 (bnum, 1, NULL); |
ad443146 SS |
5328 | |
5329 | default_collect_info (); | |
c906108c SS |
5330 | } |
5331 | ||
0d381245 | 5332 | static int |
714835d5 | 5333 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5334 | struct program_space *pspace, |
714835d5 | 5335 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5336 | { |
5337 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5338 | |
0d381245 VP |
5339 | for (; bl; bl = bl->next) |
5340 | { | |
6c95b8df PA |
5341 | if (bl->pspace == pspace |
5342 | && bl->address == pc | |
0d381245 VP |
5343 | && (!overlay_debugging || bl->section == section)) |
5344 | return 1; | |
5345 | } | |
5346 | return 0; | |
5347 | } | |
5348 | ||
6c95b8df PA |
5349 | /* Print a message describing any breakpoints set at PC. This |
5350 | concerns with logical breakpoints, so we match program spaces, not | |
5351 | address spaces. */ | |
c906108c SS |
5352 | |
5353 | static void | |
6c95b8df PA |
5354 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5355 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5356 | struct obj_section *section, int thread) |
c906108c | 5357 | { |
52f0bd74 AC |
5358 | int others = 0; |
5359 | struct breakpoint *b; | |
c906108c SS |
5360 | |
5361 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5362 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5363 | if (others > 0) |
5364 | { | |
a3f17187 AC |
5365 | if (others == 1) |
5366 | printf_filtered (_("Note: breakpoint ")); | |
5367 | else /* if (others == ???) */ | |
5368 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5369 | ALL_BREAKPOINTS (b) |
6c95b8df | 5370 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5371 | { |
5372 | others--; | |
5373 | printf_filtered ("%d", b->number); | |
5374 | if (b->thread == -1 && thread != -1) | |
5375 | printf_filtered (" (all threads)"); | |
5376 | else if (b->thread != -1) | |
5377 | printf_filtered (" (thread %d)", b->thread); | |
5378 | printf_filtered ("%s%s ", | |
059fb39f | 5379 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5380 | || b->enable_state == bp_call_disabled |
5381 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5382 | ? " (disabled)" |
5383 | : b->enable_state == bp_permanent | |
5384 | ? " (permanent)" | |
5385 | : ""), | |
5386 | (others > 1) ? "," | |
5387 | : ((others == 1) ? " and" : "")); | |
5388 | } | |
a3f17187 | 5389 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5390 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5391 | printf_filtered (".\n"); |
5392 | } | |
5393 | } | |
5394 | \f | |
5395 | /* Set the default place to put a breakpoint | |
5396 | for the `break' command with no arguments. */ | |
5397 | ||
5398 | void | |
6c95b8df PA |
5399 | set_default_breakpoint (int valid, struct program_space *pspace, |
5400 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5401 | int line) |
c906108c SS |
5402 | { |
5403 | default_breakpoint_valid = valid; | |
6c95b8df | 5404 | default_breakpoint_pspace = pspace; |
c906108c SS |
5405 | default_breakpoint_address = addr; |
5406 | default_breakpoint_symtab = symtab; | |
5407 | default_breakpoint_line = line; | |
5408 | } | |
5409 | ||
e4f237da KB |
5410 | /* Return true iff it is meaningful to use the address member of |
5411 | BPT. For some breakpoint types, the address member is irrelevant | |
5412 | and it makes no sense to attempt to compare it to other addresses | |
5413 | (or use it for any other purpose either). | |
5414 | ||
4a64f543 MS |
5415 | More specifically, each of the following breakpoint types will |
5416 | always have a zero valued address and we don't want to mark | |
5417 | breakpoints of any of these types to be a duplicate of an actual | |
5418 | breakpoint at address zero: | |
e4f237da KB |
5419 | |
5420 | bp_watchpoint | |
2d134ed3 PA |
5421 | bp_catchpoint |
5422 | ||
5423 | */ | |
e4f237da KB |
5424 | |
5425 | static int | |
5426 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5427 | { | |
5428 | enum bptype type = bpt->type; | |
5429 | ||
2d134ed3 PA |
5430 | return (type != bp_watchpoint && type != bp_catchpoint); |
5431 | } | |
5432 | ||
5433 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5434 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5435 | ||
5436 | static int | |
4a64f543 MS |
5437 | watchpoint_locations_match (struct bp_location *loc1, |
5438 | struct bp_location *loc2) | |
2d134ed3 | 5439 | { |
2bdf28a0 JK |
5440 | /* Both of them must not be in moribund_locations. */ |
5441 | gdb_assert (loc1->owner != NULL); | |
5442 | gdb_assert (loc2->owner != NULL); | |
5443 | ||
4a64f543 MS |
5444 | /* If the target can evaluate the condition expression in hardware, |
5445 | then we we need to insert both watchpoints even if they are at | |
5446 | the same place. Otherwise the watchpoint will only trigger when | |
5447 | the condition of whichever watchpoint was inserted evaluates to | |
5448 | true, not giving a chance for GDB to check the condition of the | |
5449 | other watchpoint. */ | |
0cf6dd15 | 5450 | if ((loc1->owner->cond_exp |
4a64f543 MS |
5451 | && target_can_accel_watchpoint_condition (loc1->address, |
5452 | loc1->length, | |
0cf6dd15 TJB |
5453 | loc1->watchpoint_type, |
5454 | loc1->owner->cond_exp)) | |
5455 | || (loc2->owner->cond_exp | |
4a64f543 MS |
5456 | && target_can_accel_watchpoint_condition (loc2->address, |
5457 | loc2->length, | |
0cf6dd15 TJB |
5458 | loc2->watchpoint_type, |
5459 | loc2->owner->cond_exp))) | |
5460 | return 0; | |
5461 | ||
85d721b8 PA |
5462 | /* Note that this checks the owner's type, not the location's. In |
5463 | case the target does not support read watchpoints, but does | |
5464 | support access watchpoints, we'll have bp_read_watchpoint | |
5465 | watchpoints with hw_access locations. Those should be considered | |
5466 | duplicates of hw_read locations. The hw_read locations will | |
5467 | become hw_access locations later. */ | |
2d134ed3 PA |
5468 | return (loc1->owner->type == loc2->owner->type |
5469 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5470 | && loc1->address == loc2->address | |
5471 | && loc1->length == loc2->length); | |
e4f237da KB |
5472 | } |
5473 | ||
6c95b8df PA |
5474 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5475 | same breakpoint location. In most targets, this can only be true | |
5476 | if ASPACE1 matches ASPACE2. On targets that have global | |
5477 | breakpoints, the address space doesn't really matter. */ | |
5478 | ||
5479 | static int | |
5480 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5481 | struct address_space *aspace2, CORE_ADDR addr2) | |
5482 | { | |
5483 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5484 | || aspace1 == aspace2) | |
5485 | && addr1 == addr2); | |
5486 | } | |
5487 | ||
2d134ed3 PA |
5488 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5489 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5490 | represent the same location. */ | |
5491 | ||
5492 | static int | |
4a64f543 MS |
5493 | breakpoint_locations_match (struct bp_location *loc1, |
5494 | struct bp_location *loc2) | |
2d134ed3 | 5495 | { |
2bdf28a0 JK |
5496 | int hw_point1, hw_point2; |
5497 | ||
5498 | /* Both of them must not be in moribund_locations. */ | |
5499 | gdb_assert (loc1->owner != NULL); | |
5500 | gdb_assert (loc2->owner != NULL); | |
5501 | ||
5502 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5503 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5504 | |
5505 | if (hw_point1 != hw_point2) | |
5506 | return 0; | |
5507 | else if (hw_point1) | |
5508 | return watchpoint_locations_match (loc1, loc2); | |
5509 | else | |
5510 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5511 | loc2->pspace->aspace, loc2->address); | |
5512 | } | |
5513 | ||
76897487 KB |
5514 | static void |
5515 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5516 | int bnum, int have_bnum) | |
5517 | { | |
5518 | char astr1[40]; | |
5519 | char astr2[40]; | |
5520 | ||
bb599908 PH |
5521 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5522 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5523 | if (have_bnum) |
8a3fe4f8 | 5524 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5525 | bnum, astr1, astr2); |
5526 | else | |
8a3fe4f8 | 5527 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5528 | } |
5529 | ||
4a64f543 MS |
5530 | /* Adjust a breakpoint's address to account for architectural |
5531 | constraints on breakpoint placement. Return the adjusted address. | |
5532 | Note: Very few targets require this kind of adjustment. For most | |
5533 | targets, this function is simply the identity function. */ | |
76897487 KB |
5534 | |
5535 | static CORE_ADDR | |
a6d9a66e UW |
5536 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5537 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5538 | { |
a6d9a66e | 5539 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5540 | { |
5541 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5542 | return bpaddr; | |
5543 | } | |
88f7da05 KB |
5544 | else if (bptype == bp_watchpoint |
5545 | || bptype == bp_hardware_watchpoint | |
5546 | || bptype == bp_read_watchpoint | |
5547 | || bptype == bp_access_watchpoint | |
fe798b75 | 5548 | || bptype == bp_catchpoint) |
88f7da05 KB |
5549 | { |
5550 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5551 | have their addresses modified. */ | |
5552 | return bpaddr; | |
5553 | } | |
76897487 KB |
5554 | else |
5555 | { | |
5556 | CORE_ADDR adjusted_bpaddr; | |
5557 | ||
5558 | /* Some targets have architectural constraints on the placement | |
5559 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5560 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5561 | |
5562 | /* An adjusted breakpoint address can significantly alter | |
5563 | a user's expectations. Print a warning if an adjustment | |
5564 | is required. */ | |
5565 | if (adjusted_bpaddr != bpaddr) | |
5566 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5567 | ||
5568 | return adjusted_bpaddr; | |
5569 | } | |
5570 | } | |
5571 | ||
7cc221ef DJ |
5572 | /* Allocate a struct bp_location. */ |
5573 | ||
26bb91f3 | 5574 | static struct bp_location * |
39d61571 | 5575 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5576 | { |
afe38095 | 5577 | struct bp_location *loc; |
7cc221ef DJ |
5578 | |
5579 | loc = xmalloc (sizeof (struct bp_location)); | |
5580 | memset (loc, 0, sizeof (*loc)); | |
5581 | ||
e049a4b5 | 5582 | loc->owner = bpt; |
511a6cd4 | 5583 | loc->cond = NULL; |
0d381245 VP |
5584 | loc->shlib_disabled = 0; |
5585 | loc->enabled = 1; | |
e049a4b5 | 5586 | |
39d61571 | 5587 | switch (bpt->type) |
e049a4b5 DJ |
5588 | { |
5589 | case bp_breakpoint: | |
5590 | case bp_until: | |
5591 | case bp_finish: | |
5592 | case bp_longjmp: | |
5593 | case bp_longjmp_resume: | |
186c406b TT |
5594 | case bp_exception: |
5595 | case bp_exception_resume: | |
e049a4b5 | 5596 | case bp_step_resume: |
e049a4b5 DJ |
5597 | case bp_watchpoint_scope: |
5598 | case bp_call_dummy: | |
aa7d318d | 5599 | case bp_std_terminate: |
e049a4b5 DJ |
5600 | case bp_shlib_event: |
5601 | case bp_thread_event: | |
5602 | case bp_overlay_event: | |
4efc6507 | 5603 | case bp_jit_event: |
0fd8e87f | 5604 | case bp_longjmp_master: |
aa7d318d | 5605 | case bp_std_terminate_master: |
186c406b | 5606 | case bp_exception_master: |
e049a4b5 DJ |
5607 | loc->loc_type = bp_loc_software_breakpoint; |
5608 | break; | |
5609 | case bp_hardware_breakpoint: | |
5610 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5611 | break; | |
5612 | case bp_hardware_watchpoint: | |
5613 | case bp_read_watchpoint: | |
5614 | case bp_access_watchpoint: | |
5615 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5616 | break; | |
5617 | case bp_watchpoint: | |
ce78b96d | 5618 | case bp_catchpoint: |
15c3d785 PA |
5619 | case bp_tracepoint: |
5620 | case bp_fast_tracepoint: | |
0fb4aa4b | 5621 | case bp_static_tracepoint: |
e049a4b5 DJ |
5622 | loc->loc_type = bp_loc_other; |
5623 | break; | |
5624 | default: | |
e2e0b3e5 | 5625 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5626 | } |
5627 | ||
f431efe5 | 5628 | loc->refc = 1; |
7cc221ef DJ |
5629 | return loc; |
5630 | } | |
5631 | ||
f431efe5 PA |
5632 | static void |
5633 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5634 | { |
5635 | if (loc->cond) | |
5636 | xfree (loc->cond); | |
74960c60 VP |
5637 | |
5638 | if (loc->function_name) | |
5639 | xfree (loc->function_name); | |
f431efe5 | 5640 | |
fe3f5fa8 VP |
5641 | xfree (loc); |
5642 | } | |
5643 | ||
f431efe5 PA |
5644 | /* Increment reference count. */ |
5645 | ||
5646 | static void | |
5647 | incref_bp_location (struct bp_location *bl) | |
5648 | { | |
5649 | ++bl->refc; | |
5650 | } | |
5651 | ||
5652 | /* Decrement reference count. If the reference count reaches 0, | |
5653 | destroy the bp_location. Sets *BLP to NULL. */ | |
5654 | ||
5655 | static void | |
5656 | decref_bp_location (struct bp_location **blp) | |
5657 | { | |
0807b50c PA |
5658 | gdb_assert ((*blp)->refc > 0); |
5659 | ||
f431efe5 PA |
5660 | if (--(*blp)->refc == 0) |
5661 | free_bp_location (*blp); | |
5662 | *blp = NULL; | |
5663 | } | |
5664 | ||
4a64f543 MS |
5665 | /* Helper to set_raw_breakpoint below. Creates a breakpoint that has |
5666 | type BPTYPE and has no locations as yet. */ | |
5667 | /* This function is used in gdbtk sources and thus can not be made | |
5668 | static. */ | |
c906108c | 5669 | |
c40e75cd | 5670 | static struct breakpoint * |
a6d9a66e UW |
5671 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5672 | enum bptype bptype) | |
c906108c | 5673 | { |
52f0bd74 | 5674 | struct breakpoint *b, *b1; |
c906108c SS |
5675 | |
5676 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5677 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5678 | |
4d28f7a8 | 5679 | b->type = bptype; |
a6d9a66e | 5680 | b->gdbarch = gdbarch; |
c906108c SS |
5681 | b->language = current_language->la_language; |
5682 | b->input_radix = input_radix; | |
5683 | b->thread = -1; | |
b5de0fa7 | 5684 | b->enable_state = bp_enabled; |
c906108c SS |
5685 | b->next = 0; |
5686 | b->silent = 0; | |
5687 | b->ignore_count = 0; | |
5688 | b->commands = NULL; | |
818dd999 | 5689 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5690 | b->forked_inferior_pid = null_ptid; |
c906108c | 5691 | b->exec_pathname = NULL; |
a96d9b2e | 5692 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5693 | b->ops = NULL; |
0d381245 | 5694 | b->condition_not_parsed = 0; |
84f4c1fe | 5695 | b->py_bp_object = NULL; |
c906108c | 5696 | |
4a64f543 MS |
5697 | /* Add this breakpoint to the end of the chain so that a list of |
5698 | breakpoints will come out in order of increasing numbers. */ | |
c906108c SS |
5699 | |
5700 | b1 = breakpoint_chain; | |
5701 | if (b1 == 0) | |
5702 | breakpoint_chain = b; | |
5703 | else | |
5704 | { | |
5705 | while (b1->next) | |
5706 | b1 = b1->next; | |
5707 | b1->next = b; | |
5708 | } | |
0d381245 VP |
5709 | return b; |
5710 | } | |
5711 | ||
5712 | /* Initialize loc->function_name. */ | |
5713 | static void | |
5714 | set_breakpoint_location_function (struct bp_location *loc) | |
5715 | { | |
2bdf28a0 JK |
5716 | gdb_assert (loc->owner != NULL); |
5717 | ||
0d381245 | 5718 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5719 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5720 | || is_tracepoint (loc->owner)) |
0d381245 VP |
5721 | { |
5722 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5723 | NULL, NULL); | |
5724 | if (loc->function_name) | |
5725 | loc->function_name = xstrdup (loc->function_name); | |
5726 | } | |
5727 | } | |
5728 | ||
a6d9a66e UW |
5729 | /* Attempt to determine architecture of location identified by SAL. */ |
5730 | static struct gdbarch * | |
5731 | get_sal_arch (struct symtab_and_line sal) | |
5732 | { | |
5733 | if (sal.section) | |
5734 | return get_objfile_arch (sal.section->objfile); | |
5735 | if (sal.symtab) | |
5736 | return get_objfile_arch (sal.symtab->objfile); | |
5737 | ||
5738 | return NULL; | |
5739 | } | |
5740 | ||
0d381245 VP |
5741 | /* set_raw_breakpoint is a low level routine for allocating and |
5742 | partially initializing a breakpoint of type BPTYPE. The newly | |
5743 | created breakpoint's address, section, source file name, and line | |
5744 | number are provided by SAL. The newly created and partially | |
5745 | initialized breakpoint is added to the breakpoint chain and | |
5746 | is also returned as the value of this function. | |
5747 | ||
5748 | It is expected that the caller will complete the initialization of | |
5749 | the newly created breakpoint struct as well as output any status | |
5750 | information regarding the creation of a new breakpoint. In | |
5751 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5752 | number! Care should be taken to not allow an error to occur | |
5753 | prior to completing the initialization of the breakpoint. If this | |
5754 | should happen, a bogus breakpoint will be left on the chain. */ | |
5755 | ||
63c252f8 | 5756 | struct breakpoint * |
a6d9a66e UW |
5757 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5758 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5759 | { |
4a64f543 MS |
5760 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, |
5761 | bptype); | |
0d381245 | 5762 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5763 | struct gdbarch *loc_gdbarch; |
5764 | ||
5765 | loc_gdbarch = get_sal_arch (sal); | |
5766 | if (!loc_gdbarch) | |
5767 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5768 | |
6c95b8df PA |
5769 | if (bptype != bp_catchpoint) |
5770 | gdb_assert (sal.pspace != NULL); | |
5771 | ||
0d381245 VP |
5772 | /* Adjust the breakpoint's address prior to allocating a location. |
5773 | Once we call allocate_bp_location(), that mostly uninitialized | |
5774 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5775 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5776 | not want its scan of the location chain to find a breakpoint and |
5777 | location that's only been partially initialized. */ | |
4a64f543 MS |
5778 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5779 | sal.pc, b->type); | |
0d381245 | 5780 | |
39d61571 | 5781 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5782 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5783 | b->loc->requested_address = sal.pc; |
5784 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5785 | b->loc->pspace = sal.pspace; |
5786 | ||
5787 | /* Store the program space that was used to set the breakpoint, for | |
5788 | breakpoint resetting. */ | |
5789 | b->pspace = sal.pspace; | |
0d381245 VP |
5790 | |
5791 | if (sal.symtab == NULL) | |
5792 | b->source_file = NULL; | |
5793 | else | |
1b36a34b | 5794 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5795 | b->loc->section = sal.section; |
5796 | b->line_number = sal.line; | |
5797 | ||
5798 | set_breakpoint_location_function (b->loc); | |
c906108c | 5799 | |
c906108c SS |
5800 | breakpoints_changed (); |
5801 | ||
5802 | return b; | |
5803 | } | |
5804 | ||
c2c6d25f JM |
5805 | |
5806 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5807 | instruction, hard-wired into the inferior's code. */ | |
5808 | void | |
5809 | make_breakpoint_permanent (struct breakpoint *b) | |
5810 | { | |
0d381245 | 5811 | struct bp_location *bl; |
cc59ec59 | 5812 | |
b5de0fa7 | 5813 | b->enable_state = bp_permanent; |
c2c6d25f | 5814 | |
4a64f543 MS |
5815 | /* By definition, permanent breakpoints are already present in the |
5816 | code. Mark all locations as inserted. For now, | |
5817 | make_breakpoint_permanent is called in just one place, so it's | |
5818 | hard to say if it's reasonable to have permanent breakpoint with | |
5819 | multiple locations or not, but it's easy to implmement. */ | |
0d381245 VP |
5820 | for (bl = b->loc; bl; bl = bl->next) |
5821 | bl->inserted = 1; | |
c2c6d25f JM |
5822 | } |
5823 | ||
53a5351d | 5824 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5825 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5826 | initiated the operation. */ | |
c906108c SS |
5827 | |
5828 | void | |
186c406b | 5829 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5830 | { |
35df4500 | 5831 | struct breakpoint *b, *b_tmp; |
186c406b | 5832 | int thread = tp->num; |
0fd8e87f UW |
5833 | |
5834 | /* To avoid having to rescan all objfile symbols at every step, | |
5835 | we maintain a list of continually-inserted but always disabled | |
5836 | longjmp "master" breakpoints. Here, we simply create momentary | |
5837 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5838 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5839 | if (b->pspace == current_program_space |
186c406b TT |
5840 | && (b->type == bp_longjmp_master |
5841 | || b->type == bp_exception_master)) | |
0fd8e87f UW |
5842 | { |
5843 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5844 | |
186c406b | 5845 | clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
0fd8e87f UW |
5846 | clone->thread = thread; |
5847 | } | |
186c406b TT |
5848 | |
5849 | tp->initiating_frame = frame; | |
c906108c SS |
5850 | } |
5851 | ||
611c83ae | 5852 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5853 | void |
611c83ae | 5854 | delete_longjmp_breakpoint (int thread) |
c906108c | 5855 | { |
35df4500 | 5856 | struct breakpoint *b, *b_tmp; |
c906108c | 5857 | |
35df4500 | 5858 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5859 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5860 | { |
5861 | if (b->thread == thread) | |
5862 | delete_breakpoint (b); | |
5863 | } | |
c906108c SS |
5864 | } |
5865 | ||
1900040c MS |
5866 | void |
5867 | enable_overlay_breakpoints (void) | |
5868 | { | |
52f0bd74 | 5869 | struct breakpoint *b; |
1900040c MS |
5870 | |
5871 | ALL_BREAKPOINTS (b) | |
5872 | if (b->type == bp_overlay_event) | |
5873 | { | |
5874 | b->enable_state = bp_enabled; | |
b60e7edf | 5875 | update_global_location_list (1); |
c02f5703 | 5876 | overlay_events_enabled = 1; |
1900040c MS |
5877 | } |
5878 | } | |
5879 | ||
5880 | void | |
5881 | disable_overlay_breakpoints (void) | |
5882 | { | |
52f0bd74 | 5883 | struct breakpoint *b; |
1900040c MS |
5884 | |
5885 | ALL_BREAKPOINTS (b) | |
5886 | if (b->type == bp_overlay_event) | |
5887 | { | |
5888 | b->enable_state = bp_disabled; | |
b60e7edf | 5889 | update_global_location_list (0); |
c02f5703 | 5890 | overlay_events_enabled = 0; |
1900040c MS |
5891 | } |
5892 | } | |
5893 | ||
aa7d318d TT |
5894 | /* Set an active std::terminate breakpoint for each std::terminate |
5895 | master breakpoint. */ | |
5896 | void | |
5897 | set_std_terminate_breakpoint (void) | |
5898 | { | |
35df4500 | 5899 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5900 | |
35df4500 | 5901 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5902 | if (b->pspace == current_program_space |
5903 | && b->type == bp_std_terminate_master) | |
5904 | { | |
5905 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5906 | clone->type = bp_std_terminate; | |
5907 | } | |
5908 | } | |
5909 | ||
5910 | /* Delete all the std::terminate breakpoints. */ | |
5911 | void | |
5912 | delete_std_terminate_breakpoint (void) | |
5913 | { | |
35df4500 | 5914 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5915 | |
35df4500 | 5916 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5917 | if (b->type == bp_std_terminate) |
5918 | delete_breakpoint (b); | |
5919 | } | |
5920 | ||
c4093a6a | 5921 | struct breakpoint * |
a6d9a66e | 5922 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5923 | { |
5924 | struct breakpoint *b; | |
c4093a6a | 5925 | |
a6d9a66e | 5926 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5927 | |
b5de0fa7 | 5928 | b->enable_state = bp_enabled; |
c4093a6a | 5929 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5930 | b->addr_string |
5931 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5932 | |
b60e7edf | 5933 | update_global_location_list_nothrow (1); |
74960c60 | 5934 | |
c4093a6a JM |
5935 | return b; |
5936 | } | |
5937 | ||
5938 | void | |
5939 | remove_thread_event_breakpoints (void) | |
5940 | { | |
35df4500 | 5941 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5942 | |
35df4500 | 5943 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5944 | if (b->type == bp_thread_event |
5945 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5946 | delete_breakpoint (b); |
5947 | } | |
5948 | ||
0101ce28 JJ |
5949 | struct captured_parse_breakpoint_args |
5950 | { | |
5951 | char **arg_p; | |
5952 | struct symtabs_and_lines *sals_p; | |
5953 | char ***addr_string_p; | |
5954 | int *not_found_ptr; | |
5955 | }; | |
5956 | ||
5957 | struct lang_and_radix | |
5958 | { | |
5959 | enum language lang; | |
5960 | int radix; | |
5961 | }; | |
5962 | ||
4efc6507 DE |
5963 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5964 | ||
5965 | struct breakpoint * | |
5966 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5967 | { | |
5968 | struct breakpoint *b; | |
5969 | ||
5970 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5971 | update_global_location_list_nothrow (1); | |
5972 | return b; | |
5973 | } | |
0101ce28 | 5974 | |
03673fc7 PP |
5975 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
5976 | ||
5977 | void | |
5978 | remove_jit_event_breakpoints (void) | |
5979 | { | |
5980 | struct breakpoint *b, *b_tmp; | |
5981 | ||
5982 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
5983 | if (b->type == bp_jit_event | |
5984 | && b->loc->pspace == current_program_space) | |
5985 | delete_breakpoint (b); | |
5986 | } | |
5987 | ||
cae688ec JJ |
5988 | void |
5989 | remove_solib_event_breakpoints (void) | |
5990 | { | |
35df4500 | 5991 | struct breakpoint *b, *b_tmp; |
cae688ec | 5992 | |
35df4500 | 5993 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5994 | if (b->type == bp_shlib_event |
5995 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5996 | delete_breakpoint (b); |
5997 | } | |
5998 | ||
5999 | struct breakpoint * | |
a6d9a66e | 6000 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6001 | { |
6002 | struct breakpoint *b; | |
6003 | ||
a6d9a66e | 6004 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 6005 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6006 | return b; |
6007 | } | |
6008 | ||
6009 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6010 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6011 | ||
6012 | void | |
cb851954 | 6013 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6014 | { |
876fa593 | 6015 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6016 | |
876fa593 | 6017 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6018 | { |
2bdf28a0 | 6019 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6020 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6021 | |
4a64f543 MS |
6022 | /* We apply the check to all breakpoints, including disabled for |
6023 | those with loc->duplicate set. This is so that when breakpoint | |
6024 | becomes enabled, or the duplicate is removed, gdb will try to | |
6025 | insert all breakpoints. If we don't set shlib_disabled here, | |
6026 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6027 | if (((b->type == bp_breakpoint) |
508ccb1f | 6028 | || (b->type == bp_jit_event) |
1042e4c0 | 6029 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6030 | || (is_tracepoint (b))) |
6c95b8df | 6031 | && loc->pspace == current_program_space |
0d381245 | 6032 | && !loc->shlib_disabled |
a77053c2 | 6033 | #ifdef PC_SOLIB |
0d381245 | 6034 | && PC_SOLIB (loc->address) |
a77053c2 | 6035 | #else |
6c95b8df | 6036 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6037 | #endif |
6038 | ) | |
0d381245 VP |
6039 | { |
6040 | loc->shlib_disabled = 1; | |
6041 | } | |
cae688ec JJ |
6042 | } |
6043 | } | |
6044 | ||
4a64f543 MS |
6045 | /* Disable any breakpoints that are in in an unloaded shared library. |
6046 | Only apply to enabled breakpoints, disabled ones can just stay | |
6047 | disabled. */ | |
84acb35a | 6048 | |
75149521 | 6049 | static void |
84acb35a JJ |
6050 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6051 | { | |
876fa593 | 6052 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6053 | int disabled_shlib_breaks = 0; |
6054 | ||
c86cf029 VP |
6055 | /* SunOS a.out shared libraries are always mapped, so do not |
6056 | disable breakpoints; they will only be reported as unloaded | |
6057 | through clear_solib when GDB discards its shared library | |
6058 | list. See clear_solib for more information. */ | |
6059 | if (exec_bfd != NULL | |
6060 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6061 | return; | |
6062 | ||
876fa593 | 6063 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6064 | { |
2bdf28a0 | 6065 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6066 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6067 | |
0d381245 VP |
6068 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6069 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6070 | && solib->pspace == loc->pspace |
e2dd7057 | 6071 | && !loc->shlib_disabled |
508ccb1f TT |
6072 | && (b->type == bp_breakpoint |
6073 | || b->type == bp_jit_event | |
6074 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6075 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6076 | { |
e2dd7057 PP |
6077 | loc->shlib_disabled = 1; |
6078 | /* At this point, we cannot rely on remove_breakpoint | |
6079 | succeeding so we must mark the breakpoint as not inserted | |
6080 | to prevent future errors occurring in remove_breakpoints. */ | |
6081 | loc->inserted = 0; | |
6082 | if (!disabled_shlib_breaks) | |
6083 | { | |
6084 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6085 | warning (_("Temporarily disabling breakpoints " |
6086 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6087 | solib->so_name); |
84acb35a | 6088 | } |
e2dd7057 | 6089 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6090 | } |
6091 | } | |
84acb35a JJ |
6092 | } |
6093 | ||
ce78b96d JB |
6094 | /* FORK & VFORK catchpoints. */ |
6095 | ||
4a64f543 MS |
6096 | /* Implement the "insert" breakpoint_ops method for fork |
6097 | catchpoints. */ | |
ce78b96d | 6098 | |
77b06cd7 TJB |
6099 | static int |
6100 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6101 | { |
77b06cd7 | 6102 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6103 | } |
6104 | ||
4a64f543 MS |
6105 | /* Implement the "remove" breakpoint_ops method for fork |
6106 | catchpoints. */ | |
ce78b96d JB |
6107 | |
6108 | static int | |
77b06cd7 | 6109 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6110 | { |
6111 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6112 | } | |
6113 | ||
6114 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6115 | catchpoints. */ | |
6116 | ||
6117 | static int | |
6118 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
6119 | { | |
6120 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
6121 | } | |
6122 | ||
4a64f543 MS |
6123 | /* Implement the "print_it" breakpoint_ops method for fork |
6124 | catchpoints. */ | |
ce78b96d JB |
6125 | |
6126 | static enum print_stop_action | |
6127 | print_it_catch_fork (struct breakpoint *b) | |
6128 | { | |
6129 | annotate_catchpoint (b->number); | |
6130 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
6131 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6132 | return PRINT_SRC_AND_LOC; | |
6133 | } | |
6134 | ||
4a64f543 MS |
6135 | /* Implement the "print_one" breakpoint_ops method for fork |
6136 | catchpoints. */ | |
ce78b96d JB |
6137 | |
6138 | static void | |
a6d9a66e | 6139 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6140 | { |
79a45b7d TT |
6141 | struct value_print_options opts; |
6142 | ||
6143 | get_user_print_options (&opts); | |
6144 | ||
4a64f543 MS |
6145 | /* Field 4, the address, is omitted (which makes the columns not |
6146 | line up too nicely with the headers, but the effect is relatively | |
6147 | readable). */ | |
79a45b7d | 6148 | if (opts.addressprint) |
ce78b96d JB |
6149 | ui_out_field_skip (uiout, "addr"); |
6150 | annotate_field (5); | |
6151 | ui_out_text (uiout, "fork"); | |
6152 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6153 | { | |
6154 | ui_out_text (uiout, ", process "); | |
6155 | ui_out_field_int (uiout, "what", | |
6156 | ptid_get_pid (b->forked_inferior_pid)); | |
6157 | ui_out_spaces (uiout, 1); | |
6158 | } | |
6159 | } | |
6160 | ||
6161 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6162 | catchpoints. */ | |
6163 | ||
6164 | static void | |
6165 | print_mention_catch_fork (struct breakpoint *b) | |
6166 | { | |
6167 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6168 | } | |
6169 | ||
6149aea9 PA |
6170 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6171 | catchpoints. */ | |
6172 | ||
6173 | static void | |
6174 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6175 | { | |
6176 | fprintf_unfiltered (fp, "catch fork"); | |
6177 | } | |
6178 | ||
ce78b96d JB |
6179 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6180 | ||
6181 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
6182 | { | |
6183 | insert_catch_fork, | |
6184 | remove_catch_fork, | |
6185 | breakpoint_hit_catch_fork, | |
e09342b5 | 6186 | NULL, /* resources_needed */ |
ce78b96d JB |
6187 | print_it_catch_fork, |
6188 | print_one_catch_fork, | |
6149aea9 PA |
6189 | print_mention_catch_fork, |
6190 | print_recreate_catch_fork | |
ce78b96d JB |
6191 | }; |
6192 | ||
4a64f543 MS |
6193 | /* Implement the "insert" breakpoint_ops method for vfork |
6194 | catchpoints. */ | |
ce78b96d | 6195 | |
77b06cd7 TJB |
6196 | static int |
6197 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6198 | { |
77b06cd7 | 6199 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6200 | } |
6201 | ||
4a64f543 MS |
6202 | /* Implement the "remove" breakpoint_ops method for vfork |
6203 | catchpoints. */ | |
ce78b96d JB |
6204 | |
6205 | static int | |
77b06cd7 | 6206 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6207 | { |
6208 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6209 | } | |
6210 | ||
6211 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6212 | catchpoints. */ | |
6213 | ||
6214 | static int | |
6215 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
6216 | { | |
6217 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
6218 | } | |
6219 | ||
4a64f543 MS |
6220 | /* Implement the "print_it" breakpoint_ops method for vfork |
6221 | catchpoints. */ | |
ce78b96d JB |
6222 | |
6223 | static enum print_stop_action | |
6224 | print_it_catch_vfork (struct breakpoint *b) | |
6225 | { | |
6226 | annotate_catchpoint (b->number); | |
6227 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
6228 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6229 | return PRINT_SRC_AND_LOC; | |
6230 | } | |
6231 | ||
4a64f543 MS |
6232 | /* Implement the "print_one" breakpoint_ops method for vfork |
6233 | catchpoints. */ | |
ce78b96d JB |
6234 | |
6235 | static void | |
a6d9a66e | 6236 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6237 | { |
79a45b7d TT |
6238 | struct value_print_options opts; |
6239 | ||
6240 | get_user_print_options (&opts); | |
4a64f543 MS |
6241 | /* Field 4, the address, is omitted (which makes the columns not |
6242 | line up too nicely with the headers, but the effect is relatively | |
6243 | readable). */ | |
79a45b7d | 6244 | if (opts.addressprint) |
ce78b96d JB |
6245 | ui_out_field_skip (uiout, "addr"); |
6246 | annotate_field (5); | |
6247 | ui_out_text (uiout, "vfork"); | |
6248 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6249 | { | |
6250 | ui_out_text (uiout, ", process "); | |
6251 | ui_out_field_int (uiout, "what", | |
6252 | ptid_get_pid (b->forked_inferior_pid)); | |
6253 | ui_out_spaces (uiout, 1); | |
6254 | } | |
6255 | } | |
6256 | ||
6257 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6258 | catchpoints. */ | |
6259 | ||
6260 | static void | |
6261 | print_mention_catch_vfork (struct breakpoint *b) | |
6262 | { | |
6263 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6264 | } | |
6265 | ||
6149aea9 PA |
6266 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6267 | catchpoints. */ | |
6268 | ||
6269 | static void | |
6270 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6271 | { | |
6272 | fprintf_unfiltered (fp, "catch vfork"); | |
6273 | } | |
6274 | ||
ce78b96d JB |
6275 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6276 | ||
6277 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6278 | { | |
6279 | insert_catch_vfork, | |
6280 | remove_catch_vfork, | |
6281 | breakpoint_hit_catch_vfork, | |
e09342b5 | 6282 | NULL, /* resources_needed */ |
ce78b96d JB |
6283 | print_it_catch_vfork, |
6284 | print_one_catch_vfork, | |
6149aea9 PA |
6285 | print_mention_catch_vfork, |
6286 | print_recreate_catch_vfork | |
ce78b96d JB |
6287 | }; |
6288 | ||
a96d9b2e SDJ |
6289 | /* Implement the "insert" breakpoint_ops method for syscall |
6290 | catchpoints. */ | |
6291 | ||
77b06cd7 TJB |
6292 | static int |
6293 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e SDJ |
6294 | { |
6295 | struct inferior *inf = current_inferior (); | |
6296 | ||
6297 | ++inf->total_syscalls_count; | |
77b06cd7 | 6298 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6299 | ++inf->any_syscall_count; |
6300 | else | |
6301 | { | |
6302 | int i, iter; | |
cc59ec59 | 6303 | |
a96d9b2e | 6304 | for (i = 0; |
77b06cd7 | 6305 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6306 | i++) |
6307 | { | |
6308 | int elem; | |
cc59ec59 | 6309 | |
a96d9b2e SDJ |
6310 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6311 | { | |
6312 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6313 | uintptr_t vec_addr_offset |
6314 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6315 | uintptr_t vec_addr; |
6316 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6317 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6318 | vec_addr_offset; | |
6319 | memset ((void *) vec_addr, 0, | |
6320 | (iter + 1 - old_size) * sizeof (int)); | |
6321 | } | |
6322 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6323 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6324 | } | |
6325 | } | |
6326 | ||
77b06cd7 TJB |
6327 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6328 | inf->total_syscalls_count != 0, | |
6329 | inf->any_syscall_count, | |
6330 | VEC_length (int, inf->syscalls_counts), | |
6331 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6332 | } |
6333 | ||
6334 | /* Implement the "remove" breakpoint_ops method for syscall | |
6335 | catchpoints. */ | |
6336 | ||
6337 | static int | |
77b06cd7 | 6338 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e SDJ |
6339 | { |
6340 | struct inferior *inf = current_inferior (); | |
6341 | ||
6342 | --inf->total_syscalls_count; | |
77b06cd7 | 6343 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6344 | --inf->any_syscall_count; |
6345 | else | |
6346 | { | |
6347 | int i, iter; | |
cc59ec59 | 6348 | |
a96d9b2e | 6349 | for (i = 0; |
77b06cd7 | 6350 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6351 | i++) |
6352 | { | |
6353 | int elem; | |
6354 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6355 | /* Shouldn't happen. */ | |
6356 | continue; | |
6357 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6358 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6359 | } | |
6360 | } | |
6361 | ||
6362 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6363 | inf->total_syscalls_count != 0, | |
6364 | inf->any_syscall_count, | |
6365 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6366 | VEC_address (int, |
6367 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6368 | } |
6369 | ||
6370 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6371 | catchpoints. */ | |
6372 | ||
6373 | static int | |
6374 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6375 | { | |
4a64f543 MS |
6376 | /* We must check if we are catching specific syscalls in this |
6377 | breakpoint. If we are, then we must guarantee that the called | |
6378 | syscall is the same syscall we are catching. */ | |
a96d9b2e SDJ |
6379 | int syscall_number = 0; |
6380 | ||
6381 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6382 | return 0; | |
6383 | ||
6384 | /* Now, checking if the syscall is the same. */ | |
6385 | if (b->syscalls_to_be_caught) | |
6386 | { | |
6387 | int i, iter; | |
cc59ec59 | 6388 | |
a96d9b2e SDJ |
6389 | for (i = 0; |
6390 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6391 | i++) | |
6392 | if (syscall_number == iter) | |
6393 | break; | |
6394 | /* Not the same. */ | |
6395 | if (!iter) | |
6396 | return 0; | |
6397 | } | |
6398 | ||
6399 | return 1; | |
6400 | } | |
6401 | ||
6402 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6403 | catchpoints. */ | |
6404 | ||
6405 | static enum print_stop_action | |
6406 | print_it_catch_syscall (struct breakpoint *b) | |
6407 | { | |
6408 | /* These are needed because we want to know in which state a | |
6409 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6410 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6411 | must print "called syscall" or "returned from syscall". */ | |
6412 | ptid_t ptid; | |
6413 | struct target_waitstatus last; | |
6414 | struct syscall s; | |
6415 | struct cleanup *old_chain; | |
6416 | char *syscall_id; | |
6417 | ||
6418 | get_last_target_status (&ptid, &last); | |
6419 | ||
6420 | get_syscall_by_number (last.value.syscall_number, &s); | |
6421 | ||
6422 | annotate_catchpoint (b->number); | |
6423 | ||
6424 | if (s.name == NULL) | |
6425 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6426 | else | |
6427 | syscall_id = xstrprintf ("'%s'", s.name); | |
6428 | ||
6429 | old_chain = make_cleanup (xfree, syscall_id); | |
6430 | ||
6431 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6432 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6433 | b->number, syscall_id); | |
6434 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6435 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6436 | b->number, syscall_id); | |
6437 | ||
6438 | do_cleanups (old_chain); | |
6439 | ||
6440 | return PRINT_SRC_AND_LOC; | |
6441 | } | |
6442 | ||
6443 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6444 | catchpoints. */ | |
6445 | ||
6446 | static void | |
6447 | print_one_catch_syscall (struct breakpoint *b, | |
6448 | struct bp_location **last_loc) | |
6449 | { | |
6450 | struct value_print_options opts; | |
6451 | ||
6452 | get_user_print_options (&opts); | |
4a64f543 MS |
6453 | /* Field 4, the address, is omitted (which makes the columns not |
6454 | line up too nicely with the headers, but the effect is relatively | |
6455 | readable). */ | |
a96d9b2e SDJ |
6456 | if (opts.addressprint) |
6457 | ui_out_field_skip (uiout, "addr"); | |
6458 | annotate_field (5); | |
6459 | ||
6460 | if (b->syscalls_to_be_caught | |
6461 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6462 | ui_out_text (uiout, "syscalls \""); | |
6463 | else | |
6464 | ui_out_text (uiout, "syscall \""); | |
6465 | ||
6466 | if (b->syscalls_to_be_caught) | |
6467 | { | |
6468 | int i, iter; | |
6469 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6470 | |
a96d9b2e SDJ |
6471 | for (i = 0; |
6472 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6473 | i++) | |
6474 | { | |
6475 | char *x = text; | |
6476 | struct syscall s; | |
6477 | get_syscall_by_number (iter, &s); | |
6478 | ||
6479 | if (s.name != NULL) | |
6480 | text = xstrprintf ("%s%s, ", text, s.name); | |
6481 | else | |
6482 | text = xstrprintf ("%s%d, ", text, iter); | |
6483 | ||
6484 | /* We have to xfree the last 'text' (now stored at 'x') | |
6485 | because xstrprintf dinamically allocates new space for it | |
6486 | on every call. */ | |
6487 | xfree (x); | |
6488 | } | |
6489 | /* Remove the last comma. */ | |
6490 | text[strlen (text) - 2] = '\0'; | |
6491 | ui_out_field_string (uiout, "what", text); | |
6492 | } | |
6493 | else | |
6494 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6495 | ui_out_text (uiout, "\" "); | |
6496 | } | |
6497 | ||
6498 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6499 | catchpoints. */ | |
6500 | ||
6501 | static void | |
6502 | print_mention_catch_syscall (struct breakpoint *b) | |
6503 | { | |
6504 | if (b->syscalls_to_be_caught) | |
6505 | { | |
6506 | int i, iter; | |
6507 | ||
6508 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6509 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6510 | else | |
6511 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6512 | ||
6513 | for (i = 0; | |
6514 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6515 | i++) | |
6516 | { | |
6517 | struct syscall s; | |
6518 | get_syscall_by_number (iter, &s); | |
6519 | ||
6520 | if (s.name) | |
6521 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6522 | else | |
6523 | printf_filtered (" %d", s.number); | |
6524 | } | |
6525 | printf_filtered (")"); | |
6526 | } | |
6527 | else | |
6528 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6529 | b->number); | |
6530 | } | |
6531 | ||
6149aea9 PA |
6532 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6533 | catchpoints. */ | |
6534 | ||
6535 | static void | |
6536 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6537 | { | |
6538 | fprintf_unfiltered (fp, "catch syscall"); | |
6539 | ||
6540 | if (b->syscalls_to_be_caught) | |
6541 | { | |
6542 | int i, iter; | |
6543 | ||
6544 | for (i = 0; | |
6545 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6546 | i++) | |
6547 | { | |
6548 | struct syscall s; | |
6549 | ||
6550 | get_syscall_by_number (iter, &s); | |
6551 | if (s.name) | |
6552 | fprintf_unfiltered (fp, " %s", s.name); | |
6553 | else | |
6554 | fprintf_unfiltered (fp, " %d", s.number); | |
6555 | } | |
6556 | } | |
6557 | } | |
6558 | ||
a96d9b2e SDJ |
6559 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6560 | ||
6561 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6562 | { | |
6563 | insert_catch_syscall, | |
6564 | remove_catch_syscall, | |
6565 | breakpoint_hit_catch_syscall, | |
e09342b5 | 6566 | NULL, /* resources_needed */ |
a96d9b2e SDJ |
6567 | print_it_catch_syscall, |
6568 | print_one_catch_syscall, | |
6149aea9 PA |
6569 | print_mention_catch_syscall, |
6570 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6571 | }; |
6572 | ||
6573 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6574 | ||
6575 | static int | |
6576 | syscall_catchpoint_p (struct breakpoint *b) | |
6577 | { | |
6578 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6579 | } | |
6580 | ||
6581 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6582 | but does NOT mention it nor update the global location list. | |
6583 | This is useful if you need to fill more fields in the | |
6584 | struct breakpoint before calling mention. | |
ce78b96d JB |
6585 | |
6586 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6587 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6588 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6589 | to the catchpoint. */ | |
6590 | ||
6591 | static struct breakpoint * | |
a96d9b2e SDJ |
6592 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6593 | char *cond_string, | |
6594 | struct breakpoint_ops *ops) | |
c906108c | 6595 | { |
c5aa993b JM |
6596 | struct symtab_and_line sal; |
6597 | struct breakpoint *b; | |
c5aa993b | 6598 | |
fe39c653 | 6599 | init_sal (&sal); |
6c95b8df | 6600 | sal.pspace = current_program_space; |
c5aa993b | 6601 | |
a6d9a66e | 6602 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6603 | set_breakpoint_count (breakpoint_count + 1); |
6604 | b->number = breakpoint_count; | |
ce78b96d | 6605 | |
1b36a34b | 6606 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6607 | b->thread = -1; |
c906108c | 6608 | b->addr_string = NULL; |
b5de0fa7 EZ |
6609 | b->enable_state = bp_enabled; |
6610 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6611 | b->ops = ops; |
c5aa993b | 6612 | |
a96d9b2e SDJ |
6613 | return b; |
6614 | } | |
6615 | ||
6616 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6617 | ||
6618 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6619 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6620 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6621 | to the catchpoint. */ | |
6622 | ||
6623 | static struct breakpoint * | |
6624 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6625 | char *cond_string, struct breakpoint_ops *ops) | |
6626 | { | |
6627 | struct breakpoint *b = | |
6628 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6629 | ||
c906108c | 6630 | mention (b); |
ce78b96d | 6631 | update_global_location_list (1); |
c906108c | 6632 | |
ce78b96d | 6633 | return b; |
c906108c | 6634 | } |
c5aa993b | 6635 | |
9b70b993 | 6636 | static void |
a6d9a66e UW |
6637 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6638 | int tempflag, char *cond_string, | |
ce78b96d | 6639 | struct breakpoint_ops *ops) |
c906108c | 6640 | { |
a6d9a66e UW |
6641 | struct breakpoint *b |
6642 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6643 | |
6644 | /* FIXME: We should put this information in a breakpoint private data | |
6645 | area. */ | |
6646 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6647 | } |
6648 | ||
fe798b75 JB |
6649 | /* Exec catchpoints. */ |
6650 | ||
77b06cd7 TJB |
6651 | static int |
6652 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6653 | { |
77b06cd7 | 6654 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6655 | } |
c906108c | 6656 | |
fe798b75 | 6657 | static int |
77b06cd7 | 6658 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6659 | { |
6660 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6661 | } | |
c906108c | 6662 | |
fe798b75 JB |
6663 | static int |
6664 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6665 | { | |
6666 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6667 | } | |
c906108c | 6668 | |
fe798b75 JB |
6669 | static enum print_stop_action |
6670 | print_it_catch_exec (struct breakpoint *b) | |
6671 | { | |
6672 | annotate_catchpoint (b->number); | |
6673 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6674 | b->exec_pathname); | |
6675 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6676 | } |
6677 | ||
fe798b75 | 6678 | static void |
a6d9a66e | 6679 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6680 | { |
6681 | struct value_print_options opts; | |
6682 | ||
6683 | get_user_print_options (&opts); | |
6684 | ||
6685 | /* Field 4, the address, is omitted (which makes the columns | |
6686 | not line up too nicely with the headers, but the effect | |
6687 | is relatively readable). */ | |
6688 | if (opts.addressprint) | |
6689 | ui_out_field_skip (uiout, "addr"); | |
6690 | annotate_field (5); | |
6691 | ui_out_text (uiout, "exec"); | |
6692 | if (b->exec_pathname != NULL) | |
6693 | { | |
6694 | ui_out_text (uiout, ", program \""); | |
6695 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6696 | ui_out_text (uiout, "\" "); | |
6697 | } | |
6698 | } | |
6699 | ||
6700 | static void | |
6701 | print_mention_catch_exec (struct breakpoint *b) | |
6702 | { | |
6703 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6704 | } | |
6705 | ||
6149aea9 PA |
6706 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6707 | catchpoints. */ | |
6708 | ||
6709 | static void | |
6710 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6711 | { | |
6712 | fprintf_unfiltered (fp, "catch exec"); | |
6713 | } | |
6714 | ||
fe798b75 JB |
6715 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6716 | { | |
6717 | insert_catch_exec, | |
6718 | remove_catch_exec, | |
6719 | breakpoint_hit_catch_exec, | |
e09342b5 | 6720 | NULL, /* resources_needed */ |
fe798b75 JB |
6721 | print_it_catch_exec, |
6722 | print_one_catch_exec, | |
6149aea9 PA |
6723 | print_mention_catch_exec, |
6724 | print_recreate_catch_exec | |
fe798b75 JB |
6725 | }; |
6726 | ||
a96d9b2e SDJ |
6727 | static void |
6728 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6729 | struct breakpoint_ops *ops) | |
6730 | { | |
6731 | struct gdbarch *gdbarch = get_current_arch (); | |
6732 | struct breakpoint *b = | |
6733 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6734 | ||
6735 | b->syscalls_to_be_caught = filter; | |
6736 | ||
6737 | /* Now, we have to mention the breakpoint and update the global | |
6738 | location list. */ | |
6739 | mention (b); | |
6740 | update_global_location_list (1); | |
6741 | } | |
6742 | ||
c906108c | 6743 | static int |
fba45db2 | 6744 | hw_breakpoint_used_count (void) |
c906108c | 6745 | { |
52f0bd74 | 6746 | struct breakpoint *b; |
c906108c SS |
6747 | int i = 0; |
6748 | ||
6749 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6750 | { |
d6b74ac4 | 6751 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6752 | i++; |
6753 | } | |
c906108c SS |
6754 | |
6755 | return i; | |
6756 | } | |
6757 | ||
6758 | static int | |
fba45db2 | 6759 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6760 | { |
c906108c | 6761 | int i = 0; |
e09342b5 TJB |
6762 | struct breakpoint *b; |
6763 | struct bp_location *bl; | |
c906108c SS |
6764 | |
6765 | *other_type_used = 0; | |
6766 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6767 | { |
6768 | if (!breakpoint_enabled (b)) | |
6769 | continue; | |
6770 | ||
c5aa993b | 6771 | if (b->type == type) |
e09342b5 TJB |
6772 | for (bl = b->loc; bl; bl = bl->next) |
6773 | { | |
6774 | /* Special types of hardware watchpoints may use more than | |
6775 | one register. */ | |
6776 | if (b->ops && b->ops->resources_needed) | |
6777 | i += b->ops->resources_needed (bl); | |
6778 | else | |
6779 | i++; | |
6780 | } | |
cc60f2e3 | 6781 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6782 | *other_type_used = 1; |
e09342b5 TJB |
6783 | } |
6784 | ||
c906108c SS |
6785 | return i; |
6786 | } | |
6787 | ||
c906108c | 6788 | void |
fba45db2 | 6789 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6790 | { |
c5aa993b | 6791 | struct breakpoint *b; |
c906108c SS |
6792 | |
6793 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6794 | { |
cc60f2e3 | 6795 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6796 | { |
b5de0fa7 | 6797 | b->enable_state = bp_call_disabled; |
b60e7edf | 6798 | update_global_location_list (0); |
c5aa993b JM |
6799 | } |
6800 | } | |
c906108c SS |
6801 | } |
6802 | ||
6803 | void | |
fba45db2 | 6804 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6805 | { |
c5aa993b | 6806 | struct breakpoint *b; |
c906108c SS |
6807 | |
6808 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6809 | { |
cc60f2e3 | 6810 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6811 | { |
b5de0fa7 | 6812 | b->enable_state = bp_enabled; |
b60e7edf | 6813 | update_global_location_list (1); |
c5aa993b JM |
6814 | } |
6815 | } | |
c906108c SS |
6816 | } |
6817 | ||
8bea4e01 UW |
6818 | void |
6819 | disable_breakpoints_before_startup (void) | |
6820 | { | |
6821 | struct breakpoint *b; | |
6822 | int found = 0; | |
6823 | ||
6824 | ALL_BREAKPOINTS (b) | |
6825 | { | |
6c95b8df PA |
6826 | if (b->pspace != current_program_space) |
6827 | continue; | |
6828 | ||
8bea4e01 UW |
6829 | if ((b->type == bp_breakpoint |
6830 | || b->type == bp_hardware_breakpoint) | |
6831 | && breakpoint_enabled (b)) | |
6832 | { | |
6833 | b->enable_state = bp_startup_disabled; | |
6834 | found = 1; | |
6835 | } | |
6836 | } | |
6837 | ||
6838 | if (found) | |
6839 | update_global_location_list (0); | |
6840 | ||
6c95b8df | 6841 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6842 | } |
6843 | ||
6844 | void | |
6845 | enable_breakpoints_after_startup (void) | |
6846 | { | |
6847 | struct breakpoint *b; | |
6848 | int found = 0; | |
6849 | ||
6c95b8df | 6850 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6851 | |
6852 | ALL_BREAKPOINTS (b) | |
6853 | { | |
6c95b8df PA |
6854 | if (b->pspace != current_program_space) |
6855 | continue; | |
6856 | ||
8bea4e01 UW |
6857 | if ((b->type == bp_breakpoint |
6858 | || b->type == bp_hardware_breakpoint) | |
6859 | && b->enable_state == bp_startup_disabled) | |
6860 | { | |
6861 | b->enable_state = bp_enabled; | |
6862 | found = 1; | |
6863 | } | |
6864 | } | |
6865 | ||
6866 | if (found) | |
6867 | breakpoint_re_set (); | |
6868 | } | |
6869 | ||
c906108c SS |
6870 | |
6871 | /* Set a breakpoint that will evaporate an end of command | |
6872 | at address specified by SAL. | |
6873 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6874 | ||
6875 | struct breakpoint * | |
a6d9a66e UW |
6876 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6877 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6878 | { |
52f0bd74 | 6879 | struct breakpoint *b; |
edb3359d DJ |
6880 | |
6881 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6882 | one. */ | |
6883 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6884 | ||
a6d9a66e | 6885 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6886 | b->enable_state = bp_enabled; |
6887 | b->disposition = disp_donttouch; | |
818dd999 | 6888 | b->frame_id = frame_id; |
c906108c | 6889 | |
4a64f543 MS |
6890 | /* If we're debugging a multi-threaded program, then we want |
6891 | momentary breakpoints to be active in only a single thread of | |
6892 | control. */ | |
39f77062 KB |
6893 | if (in_thread_list (inferior_ptid)) |
6894 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6895 | |
b60e7edf | 6896 | update_global_location_list_nothrow (1); |
74960c60 | 6897 | |
c906108c SS |
6898 | return b; |
6899 | } | |
611c83ae | 6900 | |
e58b0e63 PA |
6901 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6902 | ORIG is NULL. */ | |
6903 | ||
6904 | struct breakpoint * | |
6905 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6906 | { | |
6907 | struct breakpoint *copy; | |
6908 | ||
6909 | /* If there's nothing to clone, then return nothing. */ | |
6910 | if (orig == NULL) | |
6911 | return NULL; | |
6912 | ||
a6d9a66e | 6913 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6914 | copy->loc = allocate_bp_location (copy); |
6915 | set_breakpoint_location_function (copy->loc); | |
6916 | ||
a6d9a66e | 6917 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6918 | copy->loc->requested_address = orig->loc->requested_address; |
6919 | copy->loc->address = orig->loc->address; | |
6920 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6921 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6922 | |
6923 | if (orig->source_file == NULL) | |
6924 | copy->source_file = NULL; | |
6925 | else | |
6926 | copy->source_file = xstrdup (orig->source_file); | |
6927 | ||
6928 | copy->line_number = orig->line_number; | |
6929 | copy->frame_id = orig->frame_id; | |
6930 | copy->thread = orig->thread; | |
6c95b8df | 6931 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6932 | |
6933 | copy->enable_state = bp_enabled; | |
6934 | copy->disposition = disp_donttouch; | |
6935 | copy->number = internal_breakpoint_number--; | |
6936 | ||
6937 | update_global_location_list_nothrow (0); | |
6938 | return copy; | |
6939 | } | |
6940 | ||
611c83ae | 6941 | struct breakpoint * |
a6d9a66e UW |
6942 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6943 | enum bptype type) | |
611c83ae PA |
6944 | { |
6945 | struct symtab_and_line sal; | |
6946 | ||
6947 | sal = find_pc_line (pc, 0); | |
6948 | sal.pc = pc; | |
6949 | sal.section = find_pc_overlay (pc); | |
6950 | sal.explicit_pc = 1; | |
6951 | ||
a6d9a66e | 6952 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6953 | } |
c906108c | 6954 | \f |
c5aa993b | 6955 | |
c906108c SS |
6956 | /* Tell the user we have just set a breakpoint B. */ |
6957 | ||
6958 | static void | |
fba45db2 | 6959 | mention (struct breakpoint *b) |
c906108c SS |
6960 | { |
6961 | int say_where = 0; | |
fa8a61dc | 6962 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6963 | struct value_print_options opts; |
6964 | ||
6965 | get_user_print_options (&opts); | |
8b93c638 | 6966 | |
9a4105ab AC |
6967 | /* FIXME: This is misplaced; mention() is called by things (like |
6968 | hitting a watchpoint) other than breakpoint creation. It should | |
6969 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6970 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6971 | observer_notify_breakpoint_created (b->number); |
c906108c | 6972 | |
3086aeae DJ |
6973 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6974 | b->ops->print_mention (b); | |
6975 | else | |
6976 | switch (b->type) | |
6977 | { | |
6978 | case bp_none: | |
3e43a32a MS |
6979 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), |
6980 | b->number); | |
3086aeae DJ |
6981 | break; |
6982 | case bp_watchpoint: | |
6983 | ui_out_text (uiout, "Watchpoint "); | |
6984 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6985 | ui_out_field_int (uiout, "number", b->number); | |
6986 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6987 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6988 | do_cleanups (ui_out_chain); |
6989 | break; | |
6990 | case bp_hardware_watchpoint: | |
6991 | ui_out_text (uiout, "Hardware watchpoint "); | |
6992 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6993 | ui_out_field_int (uiout, "number", b->number); | |
6994 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6995 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6996 | do_cleanups (ui_out_chain); |
6997 | break; | |
6998 | case bp_read_watchpoint: | |
6999 | ui_out_text (uiout, "Hardware read watchpoint "); | |
7000 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
7001 | ui_out_field_int (uiout, "number", b->number); | |
7002 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7003 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7004 | do_cleanups (ui_out_chain); |
7005 | break; | |
7006 | case bp_access_watchpoint: | |
7007 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
7008 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
7009 | ui_out_field_int (uiout, "number", b->number); | |
7010 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7011 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7012 | do_cleanups (ui_out_chain); |
7013 | break; | |
7014 | case bp_breakpoint: | |
7015 | if (ui_out_is_mi_like_p (uiout)) | |
7016 | { | |
7017 | say_where = 0; | |
7018 | break; | |
7019 | } | |
2cec12e5 AR |
7020 | if (b->disposition == disp_del) |
7021 | printf_filtered (_("Temporary breakpoint")); | |
7022 | else | |
7023 | printf_filtered (_("Breakpoint")); | |
7024 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
7025 | say_where = 1; |
7026 | break; | |
7027 | case bp_hardware_breakpoint: | |
7028 | if (ui_out_is_mi_like_p (uiout)) | |
7029 | { | |
7030 | say_where = 0; | |
7031 | break; | |
7032 | } | |
a3f17187 | 7033 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
7034 | say_where = 1; |
7035 | break; | |
1042e4c0 SS |
7036 | case bp_tracepoint: |
7037 | if (ui_out_is_mi_like_p (uiout)) | |
7038 | { | |
7039 | say_where = 0; | |
7040 | break; | |
7041 | } | |
7042 | printf_filtered (_("Tracepoint")); | |
7043 | printf_filtered (_(" %d"), b->number); | |
7044 | say_where = 1; | |
7045 | break; | |
7a697b8d SS |
7046 | case bp_fast_tracepoint: |
7047 | if (ui_out_is_mi_like_p (uiout)) | |
7048 | { | |
7049 | say_where = 0; | |
7050 | break; | |
7051 | } | |
7052 | printf_filtered (_("Fast tracepoint")); | |
7053 | printf_filtered (_(" %d"), b->number); | |
7054 | say_where = 1; | |
7055 | break; | |
0fb4aa4b PA |
7056 | case bp_static_tracepoint: |
7057 | if (ui_out_is_mi_like_p (uiout)) | |
7058 | { | |
7059 | say_where = 0; | |
7060 | break; | |
7061 | } | |
7062 | printf_filtered (_("Static tracepoint")); | |
7063 | printf_filtered (_(" %d"), b->number); | |
7064 | say_where = 1; | |
7065 | break; | |
3086aeae DJ |
7066 | |
7067 | case bp_until: | |
7068 | case bp_finish: | |
7069 | case bp_longjmp: | |
7070 | case bp_longjmp_resume: | |
186c406b TT |
7071 | case bp_exception: |
7072 | case bp_exception_resume: | |
3086aeae | 7073 | case bp_step_resume: |
3086aeae | 7074 | case bp_call_dummy: |
aa7d318d | 7075 | case bp_std_terminate: |
3086aeae DJ |
7076 | case bp_watchpoint_scope: |
7077 | case bp_shlib_event: | |
7078 | case bp_thread_event: | |
7079 | case bp_overlay_event: | |
4efc6507 | 7080 | case bp_jit_event: |
0fd8e87f | 7081 | case bp_longjmp_master: |
aa7d318d | 7082 | case bp_std_terminate_master: |
186c406b | 7083 | case bp_exception_master: |
3086aeae DJ |
7084 | break; |
7085 | } | |
c906108c | 7086 | |
c906108c SS |
7087 | if (say_where) |
7088 | { | |
a3f17187 AC |
7089 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
7090 | single string. */ | |
0d381245 | 7091 | if (b->loc == NULL) |
c906108c | 7092 | { |
a3f17187 | 7093 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
7094 | } |
7095 | else | |
7096 | { | |
79a45b7d | 7097 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
7098 | { |
7099 | printf_filtered (" at "); | |
5af949e3 UW |
7100 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
7101 | gdb_stdout); | |
0101ce28 JJ |
7102 | } |
7103 | if (b->source_file) | |
7104 | printf_filtered (": file %s, line %d.", | |
7105 | b->source_file, b->line_number); | |
0d381245 VP |
7106 | |
7107 | if (b->loc->next) | |
7108 | { | |
7109 | struct bp_location *loc = b->loc; | |
7110 | int n = 0; | |
7111 | for (; loc; loc = loc->next) | |
7112 | ++n; | |
7113 | printf_filtered (" (%d locations)", n); | |
7114 | } | |
7115 | ||
c906108c | 7116 | } |
c906108c | 7117 | } |
9dc5e2a9 | 7118 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7119 | return; |
c906108c SS |
7120 | printf_filtered ("\n"); |
7121 | } | |
c906108c | 7122 | \f |
c5aa993b | 7123 | |
0d381245 | 7124 | static struct bp_location * |
39d61571 | 7125 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7126 | const struct symtab_and_line *sal) |
7127 | { | |
7128 | struct bp_location *loc, **tmp; | |
7129 | ||
39d61571 | 7130 | loc = allocate_bp_location (b); |
0d381245 VP |
7131 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7132 | ; | |
7133 | *tmp = loc; | |
a6d9a66e UW |
7134 | loc->gdbarch = get_sal_arch (*sal); |
7135 | if (!loc->gdbarch) | |
7136 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7137 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7138 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7139 | loc->requested_address, b->type); | |
6c95b8df PA |
7140 | loc->pspace = sal->pspace; |
7141 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7142 | loc->section = sal->section; |
7143 | ||
7144 | set_breakpoint_location_function (loc); | |
7145 | return loc; | |
7146 | } | |
514f746b AR |
7147 | \f |
7148 | ||
7149 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7150 | return 0 otherwise. */ | |
7151 | ||
7152 | static int | |
7153 | bp_loc_is_permanent (struct bp_location *loc) | |
7154 | { | |
7155 | int len; | |
7156 | CORE_ADDR addr; | |
7157 | const gdb_byte *brk; | |
7158 | gdb_byte *target_mem; | |
939c61fa JK |
7159 | struct cleanup *cleanup; |
7160 | int retval = 0; | |
514f746b AR |
7161 | |
7162 | gdb_assert (loc != NULL); | |
7163 | ||
7164 | addr = loc->address; | |
a6d9a66e | 7165 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7166 | |
939c61fa JK |
7167 | /* Software breakpoints unsupported? */ |
7168 | if (brk == NULL) | |
7169 | return 0; | |
7170 | ||
514f746b AR |
7171 | target_mem = alloca (len); |
7172 | ||
939c61fa JK |
7173 | /* Enable the automatic memory restoration from breakpoints while |
7174 | we read the memory. Otherwise we could say about our temporary | |
7175 | breakpoints they are permanent. */ | |
6c95b8df PA |
7176 | cleanup = save_current_space_and_thread (); |
7177 | ||
7178 | switch_to_program_space_and_thread (loc->pspace); | |
7179 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7180 | |
514f746b AR |
7181 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7182 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7183 | retval = 1; |
514f746b | 7184 | |
939c61fa JK |
7185 | do_cleanups (cleanup); |
7186 | ||
7187 | return retval; | |
514f746b AR |
7188 | } |
7189 | ||
7190 | ||
c3f6f71d | 7191 | |
018d34a4 VP |
7192 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7193 | as textual description of the location, and COND_STRING | |
db107f19 | 7194 | as condition expression. */ |
018d34a4 VP |
7195 | |
7196 | static void | |
8cdf0e15 VP |
7197 | create_breakpoint_sal (struct gdbarch *gdbarch, |
7198 | struct symtabs_and_lines sals, char *addr_string, | |
7199 | char *cond_string, | |
7200 | enum bptype type, enum bpdisp disposition, | |
7201 | int thread, int task, int ignore_count, | |
84f4c1fe PM |
7202 | struct breakpoint_ops *ops, int from_tty, |
7203 | int enabled, int internal) | |
018d34a4 | 7204 | { |
0d381245 VP |
7205 | struct breakpoint *b = NULL; |
7206 | int i; | |
018d34a4 VP |
7207 | |
7208 | if (type == bp_hardware_breakpoint) | |
7209 | { | |
7210 | int i = hw_breakpoint_used_count (); | |
7211 | int target_resources_ok = | |
d92524f1 | 7212 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7213 | i + 1, 0); |
7214 | if (target_resources_ok == 0) | |
7215 | error (_("No hardware breakpoint support in the target.")); | |
7216 | else if (target_resources_ok < 0) | |
7217 | error (_("Hardware breakpoints used exceeds limit.")); | |
7218 | } | |
7219 | ||
6c95b8df PA |
7220 | gdb_assert (sals.nelts > 0); |
7221 | ||
0d381245 VP |
7222 | for (i = 0; i < sals.nelts; ++i) |
7223 | { | |
7224 | struct symtab_and_line sal = sals.sals[i]; | |
7225 | struct bp_location *loc; | |
7226 | ||
7227 | if (from_tty) | |
5af949e3 UW |
7228 | { |
7229 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7230 | if (!loc_gdbarch) | |
7231 | loc_gdbarch = gdbarch; | |
7232 | ||
7233 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7234 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7235 | } |
0d381245 VP |
7236 | |
7237 | if (i == 0) | |
7238 | { | |
a6d9a66e | 7239 | b = set_raw_breakpoint (gdbarch, sal, type); |
84f4c1fe | 7240 | set_breakpoint_number (internal, b); |
0d381245 | 7241 | b->thread = thread; |
4a306c9a | 7242 | b->task = task; |
018d34a4 | 7243 | |
0d381245 VP |
7244 | b->cond_string = cond_string; |
7245 | b->ignore_count = ignore_count; | |
41447f92 | 7246 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7247 | b->disposition = disposition; |
6c95b8df PA |
7248 | b->pspace = sals.sals[0].pspace; |
7249 | ||
0fb4aa4b PA |
7250 | if (type == bp_static_tracepoint) |
7251 | { | |
7252 | struct static_tracepoint_marker marker; | |
7253 | ||
7254 | if (is_marker_spec (addr_string)) | |
7255 | { | |
7256 | /* We already know the marker exists, otherwise, we | |
7257 | wouldn't see a sal for it. */ | |
7258 | char *p = &addr_string[3]; | |
7259 | char *endp; | |
7260 | char *marker_str; | |
7261 | int i; | |
7262 | ||
7263 | while (*p == ' ' || *p == '\t') | |
7264 | p++; | |
7265 | ||
7266 | endp = p; | |
7267 | while (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7268 | endp++; | |
7269 | ||
7270 | marker_str = savestring (p, endp - p); | |
7271 | b->static_trace_marker_id = marker_str; | |
7272 | ||
3e43a32a MS |
7273 | printf_filtered (_("Probed static tracepoint " |
7274 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7275 | b->static_trace_marker_id); |
7276 | } | |
7277 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7278 | { | |
7279 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
7280 | release_static_tracepoint_marker (&marker); | |
7281 | ||
3e43a32a MS |
7282 | printf_filtered (_("Probed static tracepoint " |
7283 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7284 | b->static_trace_marker_id); |
7285 | } | |
7286 | else | |
3e43a32a MS |
7287 | warning (_("Couldn't determine the static " |
7288 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7289 | } |
7290 | ||
6c95b8df | 7291 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7292 | && (b->type == bp_breakpoint |
7293 | || b->type == bp_hardware_breakpoint)) | |
7294 | b->enable_state = bp_startup_disabled; | |
7295 | ||
0d381245 VP |
7296 | loc = b->loc; |
7297 | } | |
7298 | else | |
018d34a4 | 7299 | { |
39d61571 | 7300 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7301 | } |
7302 | ||
514f746b AR |
7303 | if (bp_loc_is_permanent (loc)) |
7304 | make_breakpoint_permanent (b); | |
7305 | ||
0d381245 VP |
7306 | if (b->cond_string) |
7307 | { | |
7308 | char *arg = b->cond_string; | |
d32a6982 | 7309 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7310 | if (*arg) |
db107f19 | 7311 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7312 | } |
0d381245 | 7313 | } |
018d34a4 VP |
7314 | |
7315 | if (addr_string) | |
7316 | b->addr_string = addr_string; | |
7317 | else | |
7318 | /* addr_string has to be used or breakpoint_re_set will delete | |
7319 | me. */ | |
5af949e3 UW |
7320 | b->addr_string |
7321 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7322 | |
604133b5 | 7323 | b->ops = ops; |
84f4c1fe PM |
7324 | if (internal) |
7325 | /* Do not mention breakpoints with a negative number, but do | |
7326 | notify observers. */ | |
7327 | observer_notify_breakpoint_created (b->number); | |
7328 | else | |
7329 | mention (b); | |
018d34a4 VP |
7330 | } |
7331 | ||
ed0616c6 VP |
7332 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7333 | elements to fill the void space. */ | |
2c0b251b PA |
7334 | static void |
7335 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7336 | { |
7337 | int i = index_to_remove+1; | |
7338 | int last_index = sal->nelts-1; | |
7339 | ||
7340 | for (;i <= last_index; ++i) | |
7341 | sal->sals[i-1] = sal->sals[i]; | |
7342 | ||
7343 | --(sal->nelts); | |
7344 | } | |
7345 | ||
6c95b8df PA |
7346 | /* If appropriate, obtains all sals that correspond to the same file |
7347 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7348 | will want to set a breakpoint at foo.c:line, and not really care | |
7349 | about program spaces. This is done only if SAL does not have | |
7350 | explicit PC and has line and file information. If we got just a | |
7351 | single expanded sal, return the original. | |
ed0616c6 | 7352 | |
6c95b8df PA |
7353 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7354 | which the name of enclosing function is different from SAL. This | |
7355 | makes sure that if we have breakpoint originally set in template | |
7356 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7357 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7358 | |
2c0b251b | 7359 | static struct symtabs_and_lines |
ed0616c6 VP |
7360 | expand_line_sal_maybe (struct symtab_and_line sal) |
7361 | { | |
7362 | struct symtabs_and_lines expanded; | |
7363 | CORE_ADDR original_pc = sal.pc; | |
7364 | char *original_function = NULL; | |
7365 | int found; | |
7366 | int i; | |
6c95b8df | 7367 | struct cleanup *old_chain; |
ed0616c6 VP |
7368 | |
7369 | /* If we have explicit pc, don't expand. | |
7370 | If we have no line number, we can't expand. */ | |
7371 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7372 | { | |
7373 | expanded.nelts = 1; | |
7374 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7375 | expanded.sals[0] = sal; | |
7376 | return expanded; | |
7377 | } | |
7378 | ||
7379 | sal.pc = 0; | |
6c95b8df PA |
7380 | |
7381 | old_chain = save_current_space_and_thread (); | |
7382 | ||
7383 | switch_to_program_space_and_thread (sal.pspace); | |
7384 | ||
ed0616c6 | 7385 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7386 | |
7387 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7388 | expanded = expand_line_sal (sal); |
6c95b8df | 7389 | |
ed0616c6 VP |
7390 | if (expanded.nelts == 1) |
7391 | { | |
3dba1c98 JB |
7392 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7393 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7394 | xfree (expanded.sals); |
7395 | expanded.nelts = 1; | |
7396 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7397 | sal.pc = original_pc; | |
7398 | expanded.sals[0] = sal; | |
3dba1c98 | 7399 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7400 | do_cleanups (old_chain); |
ed0616c6 VP |
7401 | return expanded; |
7402 | } | |
7403 | ||
7404 | if (!sal.explicit_line) | |
7405 | { | |
7406 | CORE_ADDR func_addr, func_end; | |
7407 | for (i = 0; i < expanded.nelts; ++i) | |
7408 | { | |
7409 | CORE_ADDR pc = expanded.sals[i].pc; | |
7410 | char *this_function; | |
6c95b8df PA |
7411 | |
7412 | /* We need to switch threads as well since we're about to | |
7413 | read memory. */ | |
7414 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7415 | ||
ed0616c6 VP |
7416 | if (find_pc_partial_function (pc, &this_function, |
7417 | &func_addr, &func_end)) | |
7418 | { | |
059fb39f PM |
7419 | if (this_function |
7420 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7421 | { |
7422 | remove_sal (&expanded, i); | |
7423 | --i; | |
7424 | } | |
ed0616c6 VP |
7425 | } |
7426 | } | |
7427 | } | |
059acae7 UW |
7428 | |
7429 | /* Skip the function prologue if necessary. */ | |
7430 | for (i = 0; i < expanded.nelts; ++i) | |
7431 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7432 | |
6c95b8df PA |
7433 | do_cleanups (old_chain); |
7434 | ||
ed0616c6 VP |
7435 | if (expanded.nelts <= 1) |
7436 | { | |
4a64f543 MS |
7437 | /* This is un ugly workaround. If we get zero expanded sals |
7438 | then something is really wrong. Fix that by returning the | |
7439 | original sal. */ | |
7440 | ||
ed0616c6 VP |
7441 | xfree (expanded.sals); |
7442 | expanded.nelts = 1; | |
7443 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7444 | sal.pc = original_pc; | |
7445 | expanded.sals[0] = sal; | |
7446 | return expanded; | |
7447 | } | |
7448 | ||
7449 | if (original_pc) | |
7450 | { | |
7451 | found = 0; | |
7452 | for (i = 0; i < expanded.nelts; ++i) | |
7453 | if (expanded.sals[i].pc == original_pc) | |
7454 | { | |
7455 | found = 1; | |
7456 | break; | |
7457 | } | |
7458 | gdb_assert (found); | |
7459 | } | |
7460 | ||
7461 | return expanded; | |
7462 | } | |
7463 | ||
018d34a4 VP |
7464 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7465 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7466 | value. COND_STRING, if not NULL, specified the condition to be | |
7467 | used for all breakpoints. Essentially the only case where | |
7468 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7469 | function. In that case, it's still not possible to specify | |
7470 | separate conditions for different overloaded functions, so | |
7471 | we take just a single condition string. | |
7472 | ||
c3f6f71d | 7473 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7474 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7475 | array contents). If the function fails (error() is called), the |
7476 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7477 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7478 | |
7479 | static void | |
8cdf0e15 VP |
7480 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7481 | struct symtabs_and_lines sals, char **addr_string, | |
7482 | char *cond_string, | |
7483 | enum bptype type, enum bpdisp disposition, | |
7484 | int thread, int task, int ignore_count, | |
7485 | struct breakpoint_ops *ops, int from_tty, | |
84f4c1fe | 7486 | int enabled, int internal) |
c906108c | 7487 | { |
018d34a4 | 7488 | int i; |
cc59ec59 | 7489 | |
018d34a4 | 7490 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7491 | { |
ed0616c6 VP |
7492 | struct symtabs_and_lines expanded = |
7493 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7494 | |
8cdf0e15 VP |
7495 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7496 | cond_string, type, disposition, | |
84f4c1fe PM |
7497 | thread, task, ignore_count, ops, |
7498 | from_tty, enabled, internal); | |
c3f6f71d | 7499 | } |
c3f6f71d | 7500 | } |
c906108c | 7501 | |
9998af43 | 7502 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7503 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7504 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7505 | address strings. ADDRESS points to the end of the SAL. |
7506 | ||
7507 | The array and the line spec strings are allocated on the heap, it is | |
7508 | the caller's responsibility to free them. */ | |
c906108c | 7509 | |
b9362cc7 | 7510 | static void |
c3f6f71d JM |
7511 | parse_breakpoint_sals (char **address, |
7512 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7513 | char ***addr_string, |
7514 | int *not_found_ptr) | |
c3f6f71d JM |
7515 | { |
7516 | char *addr_start = *address; | |
cc59ec59 | 7517 | |
c3f6f71d JM |
7518 | *addr_string = NULL; |
7519 | /* If no arg given, or if first arg is 'if ', use the default | |
4a64f543 | 7520 | breakpoint. */ |
c3f6f71d JM |
7521 | if ((*address) == NULL |
7522 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7523 | { |
7524 | if (default_breakpoint_valid) | |
7525 | { | |
c3f6f71d | 7526 | struct symtab_and_line sal; |
cc59ec59 | 7527 | |
4a64f543 | 7528 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7529 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7530 | xmalloc (sizeof (struct symtab_and_line)); |
7531 | sal.pc = default_breakpoint_address; | |
7532 | sal.line = default_breakpoint_line; | |
7533 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7534 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7535 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7536 | |
4a64f543 MS |
7537 | /* "break" without arguments is equivalent to "break *PC" |
7538 | where PC is the default_breakpoint_address. So make sure | |
7539 | to set sal.explicit_pc to prevent GDB from trying to | |
7540 | expand the list of sals to include all other instances | |
7541 | with the same symtab and line. */ | |
00903456 JK |
7542 | sal.explicit_pc = 1; |
7543 | ||
c3f6f71d JM |
7544 | sals->sals[0] = sal; |
7545 | sals->nelts = 1; | |
c906108c SS |
7546 | } |
7547 | else | |
8a3fe4f8 | 7548 | error (_("No default breakpoint address now.")); |
c906108c SS |
7549 | } |
7550 | else | |
7551 | { | |
c906108c | 7552 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7553 | current_source_symtab (which is decode_line_1's default). |
7554 | This should produce the results we want almost all of the | |
7555 | time while leaving default_breakpoint_* alone. | |
7556 | ||
1aeae86e AF |
7557 | ObjC: However, don't match an Objective-C method name which |
7558 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7559 | |
c214a6fd | 7560 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7561 | |
c906108c | 7562 | if (default_breakpoint_valid |
0378c332 | 7563 | && (!cursal.symtab |
1aeae86e AF |
7564 | || ((strchr ("+-", (*address)[0]) != NULL) |
7565 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7566 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7567 | default_breakpoint_line, addr_string, |
7568 | not_found_ptr); | |
c906108c | 7569 | else |
0101ce28 JJ |
7570 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7571 | addr_string, not_found_ptr); | |
c906108c | 7572 | } |
4a64f543 | 7573 | /* For any SAL that didn't have a canonical string, fill one in. */ |
c3f6f71d JM |
7574 | if (sals->nelts > 0 && *addr_string == NULL) |
7575 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7576 | if (addr_start != (*address)) | |
c906108c | 7577 | { |
c3f6f71d | 7578 | int i; |
cc59ec59 | 7579 | |
c3f6f71d | 7580 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7581 | { |
4a64f543 | 7582 | /* Add the string if not present. */ |
c3f6f71d | 7583 | if ((*addr_string)[i] == NULL) |
cc59ec59 MS |
7584 | (*addr_string)[i] = savestring (addr_start, |
7585 | (*address) - addr_start); | |
c906108c SS |
7586 | } |
7587 | } | |
c3f6f71d | 7588 | } |
c906108c | 7589 | |
c906108c | 7590 | |
c3f6f71d | 7591 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7592 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7593 | |
b9362cc7 | 7594 | static void |
23e7acfb | 7595 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7596 | { |
7597 | int i; | |
cc59ec59 | 7598 | |
c3f6f71d | 7599 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7600 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7601 | } |
7602 | ||
7a697b8d SS |
7603 | /* Fast tracepoints may have restrictions on valid locations. For |
7604 | instance, a fast tracepoint using a jump instead of a trap will | |
7605 | likely have to overwrite more bytes than a trap would, and so can | |
7606 | only be placed where the instruction is longer than the jump, or a | |
7607 | multi-instruction sequence does not have a jump into the middle of | |
7608 | it, etc. */ | |
7609 | ||
7610 | static void | |
7611 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7612 | struct symtabs_and_lines *sals) | |
7613 | { | |
7614 | int i, rslt; | |
7615 | struct symtab_and_line *sal; | |
7616 | char *msg; | |
7617 | struct cleanup *old_chain; | |
7618 | ||
7619 | for (i = 0; i < sals->nelts; i++) | |
7620 | { | |
7621 | sal = &sals->sals[i]; | |
7622 | ||
7623 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7624 | NULL, &msg); | |
7625 | old_chain = make_cleanup (xfree, msg); | |
7626 | ||
7627 | if (!rslt) | |
7628 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7629 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7630 | ||
7631 | do_cleanups (old_chain); | |
7632 | } | |
7633 | } | |
7634 | ||
05ff989b | 7635 | static void |
0101ce28 JJ |
7636 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7637 | { | |
7638 | struct captured_parse_breakpoint_args *args = data; | |
7639 | ||
7640 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7641 | args->not_found_ptr); | |
0101ce28 JJ |
7642 | } |
7643 | ||
018d34a4 VP |
7644 | /* Given TOK, a string specification of condition and thread, as |
7645 | accepted by the 'break' command, extract the condition | |
7646 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7647 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7648 | If no condition is found, *COND_STRING is set to NULL. |
7649 | If no thread is found, *THREAD is set to -1. */ | |
7650 | static void | |
7651 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7652 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7653 | { |
7654 | *cond_string = NULL; | |
7655 | *thread = -1; | |
7656 | while (tok && *tok) | |
7657 | { | |
7658 | char *end_tok; | |
7659 | int toklen; | |
7660 | char *cond_start = NULL; | |
7661 | char *cond_end = NULL; | |
cc59ec59 | 7662 | |
018d34a4 VP |
7663 | while (*tok == ' ' || *tok == '\t') |
7664 | tok++; | |
7665 | ||
7666 | end_tok = tok; | |
7667 | ||
7668 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7669 | end_tok++; | |
7670 | ||
7671 | toklen = end_tok - tok; | |
7672 | ||
7673 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7674 | { | |
f7545552 TT |
7675 | struct expression *expr; |
7676 | ||
018d34a4 | 7677 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7678 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7679 | xfree (expr); | |
018d34a4 VP |
7680 | cond_end = tok; |
7681 | *cond_string = savestring (cond_start, | |
7682 | cond_end - cond_start); | |
7683 | } | |
7684 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7685 | { | |
7686 | char *tmptok; | |
7687 | ||
7688 | tok = end_tok + 1; | |
7689 | tmptok = tok; | |
7690 | *thread = strtol (tok, &tok, 0); | |
7691 | if (tok == tmptok) | |
7692 | error (_("Junk after thread keyword.")); | |
7693 | if (!valid_thread_id (*thread)) | |
7694 | error (_("Unknown thread %d."), *thread); | |
7695 | } | |
4a306c9a JB |
7696 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7697 | { | |
7698 | char *tmptok; | |
7699 | ||
7700 | tok = end_tok + 1; | |
7701 | tmptok = tok; | |
7702 | *task = strtol (tok, &tok, 0); | |
7703 | if (tok == tmptok) | |
7704 | error (_("Junk after task keyword.")); | |
7705 | if (!valid_task_id (*task)) | |
b6199126 | 7706 | error (_("Unknown task %d."), *task); |
4a306c9a | 7707 | } |
018d34a4 VP |
7708 | else |
7709 | error (_("Junk at end of arguments.")); | |
7710 | } | |
7711 | } | |
7712 | ||
0fb4aa4b PA |
7713 | /* Decode a static tracepoint marker spec. */ |
7714 | ||
7715 | static struct symtabs_and_lines | |
7716 | decode_static_tracepoint_spec (char **arg_p) | |
7717 | { | |
7718 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7719 | struct symtabs_and_lines sals; | |
7720 | struct symtab_and_line sal; | |
7721 | struct symbol *sym; | |
7722 | struct cleanup *old_chain; | |
7723 | char *p = &(*arg_p)[3]; | |
7724 | char *endp; | |
7725 | char *marker_str; | |
7726 | int i; | |
7727 | ||
7728 | while (*p == ' ' || *p == '\t') | |
7729 | p++; | |
7730 | ||
7731 | endp = p; | |
7732 | while (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7733 | endp++; | |
7734 | ||
7735 | marker_str = savestring (p, endp - p); | |
7736 | old_chain = make_cleanup (xfree, marker_str); | |
7737 | ||
7738 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7739 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7740 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7741 | ||
7742 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7743 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7744 | ||
7745 | for (i = 0; i < sals.nelts; i++) | |
7746 | { | |
7747 | struct static_tracepoint_marker *marker; | |
7748 | ||
7749 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7750 | ||
7751 | init_sal (&sals.sals[i]); | |
7752 | ||
7753 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7754 | sals.sals[i].pc = marker->address; | |
7755 | ||
7756 | release_static_tracepoint_marker (marker); | |
7757 | } | |
7758 | ||
7759 | do_cleanups (old_chain); | |
7760 | ||
7761 | *arg_p = endp; | |
7762 | return sals; | |
7763 | } | |
7764 | ||
fd9b8c24 PA |
7765 | /* Set a breakpoint. This function is shared between CLI and MI |
7766 | functions for setting a breakpoint. This function has two major | |
7767 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7768 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7769 | breakpoint location, address and thread. Otherwise, ARG is just |
7770 | the location of breakpoint, with condition and thread specified by | |
7771 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7772 | the breakpoint number will be allocated from the internal | |
7773 | breakpoint count. Returns true if any breakpoint was created; | |
7774 | false otherwise. */ | |
0101ce28 | 7775 | |
8cdf0e15 VP |
7776 | int |
7777 | create_breakpoint (struct gdbarch *gdbarch, | |
7778 | char *arg, char *cond_string, int thread, | |
7779 | int parse_condition_and_thread, | |
0fb4aa4b | 7780 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7781 | int ignore_count, |
7782 | enum auto_boolean pending_break_support, | |
7783 | struct breakpoint_ops *ops, | |
84f4c1fe | 7784 | int from_tty, int enabled, int internal) |
c3f6f71d | 7785 | { |
71fff37b | 7786 | struct gdb_exception e; |
c3f6f71d | 7787 | struct symtabs_and_lines sals; |
0101ce28 | 7788 | struct symtab_and_line pending_sal; |
0101ce28 | 7789 | char *copy_arg; |
c3f6f71d JM |
7790 | char *addr_start = arg; |
7791 | char **addr_string; | |
7792 | struct cleanup *old_chain; | |
80c99de1 | 7793 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7794 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7795 | int i; |
0101ce28 | 7796 | int pending = 0; |
0101ce28 | 7797 | int not_found = 0; |
4a306c9a | 7798 | int task = 0; |
86b17b60 | 7799 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7800 | |
c3f6f71d JM |
7801 | sals.sals = NULL; |
7802 | sals.nelts = 0; | |
7803 | addr_string = NULL; | |
c3f6f71d | 7804 | |
0101ce28 JJ |
7805 | parse_args.arg_p = &arg; |
7806 | parse_args.sals_p = &sals; | |
7807 | parse_args.addr_string_p = &addr_string; | |
7808 | parse_args.not_found_ptr = ¬_found; | |
7809 | ||
0fb4aa4b PA |
7810 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7811 | { | |
7812 | int i; | |
7813 | ||
7814 | sals = decode_static_tracepoint_spec (&arg); | |
7815 | ||
7816 | copy_arg = savestring (addr_start, arg - addr_start); | |
7817 | addr_string = xcalloc (sals.nelts, sizeof (char **)); | |
7818 | for (i = 0; i < sals.nelts; i++) | |
7819 | addr_string[i] = xstrdup (copy_arg); | |
7820 | goto done; | |
7821 | } | |
7822 | ||
05ff989b AC |
7823 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7824 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7825 | |
7826 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7827 | switch (e.reason) |
0101ce28 | 7828 | { |
05ff989b | 7829 | case RETURN_QUIT: |
98deb0da | 7830 | throw_exception (e); |
05ff989b AC |
7831 | case RETURN_ERROR: |
7832 | switch (e.error) | |
0101ce28 | 7833 | { |
05ff989b | 7834 | case NOT_FOUND_ERROR: |
0101ce28 | 7835 | |
05ff989b AC |
7836 | /* If pending breakpoint support is turned off, throw |
7837 | error. */ | |
fa8d40ab JJ |
7838 | |
7839 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7840 | throw_exception (e); |
7841 | ||
7842 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7843 | |
05ff989b AC |
7844 | /* If pending breakpoint support is auto query and the user |
7845 | selects no, then simply return the error code. */ | |
059fb39f | 7846 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7847 | && !nquery (_("Make breakpoint pending on " |
7848 | "future shared library load? "))) | |
fd9b8c24 | 7849 | return 0; |
fa8d40ab | 7850 | |
05ff989b AC |
7851 | /* At this point, either the user was queried about setting |
7852 | a pending breakpoint and selected yes, or pending | |
7853 | breakpoint behavior is on and thus a pending breakpoint | |
7854 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7855 | copy_arg = xstrdup (addr_start); |
7856 | addr_string = ©_arg; | |
7857 | sals.nelts = 1; | |
7858 | sals.sals = &pending_sal; | |
7859 | pending_sal.pc = 0; | |
7860 | pending = 1; | |
05ff989b AC |
7861 | break; |
7862 | default: | |
98deb0da | 7863 | throw_exception (e); |
0101ce28 | 7864 | } |
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 | ||
4a64f543 | 7880 | /* Cleanup the addr_string array but not its contents. */ |
0101ce28 JJ |
7881 | make_cleanup (xfree, addr_string); |
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 JM |
7889 | |
7890 | /* Mark the contents of the addr_string 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 | { | |
7894 | if (addr_string[i] != NULL) | |
b8c9b27d | 7895 | make_cleanup (xfree, addr_string[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 | |
7942 | && is_marker_spec (addr_string[0])) | |
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 | ||
7957 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], | |
7958 | cond_string, type_wanted, | |
7959 | tempflag ? disp_del : disp_donttouch, | |
7960 | thread, task, ignore_count, ops, | |
84f4c1fe | 7961 | from_tty, enabled, internal); |
0fb4aa4b PA |
7962 | |
7963 | do_cleanups (old_chain); | |
7964 | ||
7965 | /* Get the tracepoint we just created. */ | |
84f4c1fe PM |
7966 | if (internal) |
7967 | tp = get_breakpoint (internal_breakpoint_number); | |
7968 | else | |
7969 | tp = get_breakpoint (breakpoint_count); | |
0fb4aa4b PA |
7970 | gdb_assert (tp != NULL); |
7971 | ||
7972 | /* Given that its possible to have multiple markers with | |
7973 | the same string id, if the user is creating a static | |
7974 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7975 | store the sals index, so that breakpoint_re_set can | |
7976 | try to match up which of the newly found markers | |
7977 | corresponds to this one */ | |
7978 | tp->static_trace_marker_id_idx = i; | |
7979 | } | |
7980 | } | |
7981 | else | |
7982 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, | |
3e43a32a MS |
7983 | type_wanted, |
7984 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7985 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7986 | enabled, internal); |
c906108c | 7987 | } |
0101ce28 JJ |
7988 | else |
7989 | { | |
0101ce28 JJ |
7990 | struct breakpoint *b; |
7991 | ||
0101ce28 JJ |
7992 | make_cleanup (xfree, copy_arg); |
7993 | ||
a6d9a66e | 7994 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
84f4c1fe | 7995 | set_breakpoint_number (internal, b); |
72b2ff0e | 7996 | b->thread = -1; |
018d34a4 | 7997 | b->addr_string = addr_string[0]; |
72b2ff0e | 7998 | b->cond_string = NULL; |
0101ce28 | 7999 | b->ignore_count = ignore_count; |
0101ce28 | 8000 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8001 | b->condition_not_parsed = 1; |
604133b5 | 8002 | b->ops = ops; |
41447f92 | 8003 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 8004 | b->pspace = current_program_space; |
84f4c1fe | 8005 | b->py_bp_object = NULL; |
74960c60 | 8006 | |
6c95b8df | 8007 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8008 | && (b->type == bp_breakpoint |
8009 | || b->type == bp_hardware_breakpoint)) | |
8010 | b->enable_state = bp_startup_disabled; | |
8011 | ||
84f4c1fe PM |
8012 | if (internal) |
8013 | /* Do not mention breakpoints with a negative number, | |
8014 | but do notify observers. */ | |
8015 | observer_notify_breakpoint_created (b->number); | |
8016 | else | |
8017 | mention (b); | |
0101ce28 JJ |
8018 | } |
8019 | ||
c3f6f71d | 8020 | if (sals.nelts > 1) |
95a42b64 | 8021 | { |
3e43a32a MS |
8022 | warning (_("Multiple breakpoints were set.\nUse the " |
8023 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8024 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8025 | } |
8026 | ||
80c99de1 PA |
8027 | /* That's it. Discard the cleanups for data inserted into the |
8028 | breakpoint. */ | |
8029 | discard_cleanups (bkpt_chain); | |
8030 | /* But cleanup everything else. */ | |
c3f6f71d | 8031 | do_cleanups (old_chain); |
217dc9e2 | 8032 | |
80c99de1 | 8033 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8034 | update_global_location_list (1); |
fd9b8c24 PA |
8035 | |
8036 | return 1; | |
c3f6f71d | 8037 | } |
c906108c | 8038 | |
72b2ff0e VP |
8039 | /* Set a breakpoint. |
8040 | ARG is a string describing breakpoint address, | |
8041 | condition, and thread. | |
8042 | FLAG specifies if a breakpoint is hardware on, | |
8043 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8044 | and BP_TEMPFLAG. */ | |
8045 | ||
98deb0da | 8046 | static void |
72b2ff0e | 8047 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8048 | { |
72b2ff0e | 8049 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8050 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8051 | ? bp_hardware_breakpoint | |
8052 | : bp_breakpoint); | |
c3f6f71d | 8053 | |
8cdf0e15 VP |
8054 | create_breakpoint (get_current_arch (), |
8055 | arg, | |
8056 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8057 | tempflag, type_wanted, |
8cdf0e15 VP |
8058 | 0 /* Ignore count */, |
8059 | pending_break_support, | |
8060 | NULL /* breakpoint_ops */, | |
8061 | from_tty, | |
84f4c1fe PM |
8062 | 1 /* enabled */, |
8063 | 0 /* internal */); | |
c906108c SS |
8064 | } |
8065 | ||
72b2ff0e | 8066 | |
c906108c SS |
8067 | /* Helper function for break_command_1 and disassemble_command. */ |
8068 | ||
8069 | void | |
fba45db2 | 8070 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8071 | { |
8072 | CORE_ADDR pc; | |
8073 | ||
8074 | if (sal->pc == 0 && sal->symtab != NULL) | |
8075 | { | |
8076 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8077 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8078 | sal->line, sal->symtab->filename); |
8079 | sal->pc = pc; | |
6a048695 | 8080 | |
4a64f543 MS |
8081 | /* If this SAL corresponds to a breakpoint inserted using a line |
8082 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8083 | if (sal->explicit_line) |
059acae7 | 8084 | skip_prologue_sal (sal); |
c906108c SS |
8085 | } |
8086 | ||
8087 | if (sal->section == 0 && sal->symtab != NULL) | |
8088 | { | |
8089 | struct blockvector *bv; | |
c5aa993b JM |
8090 | struct block *b; |
8091 | struct symbol *sym; | |
c906108c | 8092 | |
801e3a5b | 8093 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8094 | if (bv != NULL) |
8095 | { | |
7f0df278 | 8096 | sym = block_linkage_function (b); |
c906108c SS |
8097 | if (sym != NULL) |
8098 | { | |
8099 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8100 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8101 | } |
8102 | else | |
8103 | { | |
4a64f543 MS |
8104 | /* It really is worthwhile to have the section, so we'll |
8105 | just have to look harder. This case can be executed | |
8106 | if we have line numbers but no functions (as can | |
8107 | happen in assembly source). */ | |
c906108c | 8108 | |
c5aa993b | 8109 | struct minimal_symbol *msym; |
6c95b8df PA |
8110 | struct cleanup *old_chain = save_current_space_and_thread (); |
8111 | ||
8112 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8113 | |
8114 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8115 | if (msym) | |
714835d5 | 8116 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8117 | |
8118 | do_cleanups (old_chain); | |
c906108c SS |
8119 | } |
8120 | } | |
8121 | } | |
8122 | } | |
8123 | ||
8124 | void | |
fba45db2 | 8125 | break_command (char *arg, int from_tty) |
c906108c | 8126 | { |
db107f19 | 8127 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8128 | } |
8129 | ||
c906108c | 8130 | void |
fba45db2 | 8131 | tbreak_command (char *arg, int from_tty) |
c906108c | 8132 | { |
db107f19 | 8133 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8134 | } |
8135 | ||
c906108c | 8136 | static void |
fba45db2 | 8137 | hbreak_command (char *arg, int from_tty) |
c906108c | 8138 | { |
db107f19 | 8139 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8140 | } |
8141 | ||
8142 | static void | |
fba45db2 | 8143 | thbreak_command (char *arg, int from_tty) |
c906108c | 8144 | { |
db107f19 | 8145 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8146 | } |
8147 | ||
8148 | static void | |
fba45db2 | 8149 | stop_command (char *arg, int from_tty) |
c906108c | 8150 | { |
a3f17187 | 8151 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8152 | Usage: stop in <function | address>\n\ |
a3f17187 | 8153 | stop at <line>\n")); |
c906108c SS |
8154 | } |
8155 | ||
8156 | static void | |
fba45db2 | 8157 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8158 | { |
8159 | int badInput = 0; | |
8160 | ||
c5aa993b | 8161 | if (arg == (char *) NULL) |
c906108c SS |
8162 | badInput = 1; |
8163 | else if (*arg != '*') | |
8164 | { | |
8165 | char *argptr = arg; | |
8166 | int hasColon = 0; | |
8167 | ||
4a64f543 | 8168 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8169 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8170 | function/method name. */ |
c906108c | 8171 | while (*argptr && !hasColon) |
c5aa993b JM |
8172 | { |
8173 | hasColon = (*argptr == ':'); | |
8174 | argptr++; | |
8175 | } | |
c906108c SS |
8176 | |
8177 | if (hasColon) | |
c5aa993b | 8178 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8179 | else |
c5aa993b | 8180 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8181 | } |
8182 | ||
8183 | if (badInput) | |
a3f17187 | 8184 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8185 | else |
db107f19 | 8186 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8187 | } |
8188 | ||
8189 | static void | |
fba45db2 | 8190 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8191 | { |
8192 | int badInput = 0; | |
8193 | ||
c5aa993b | 8194 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8195 | badInput = 1; |
8196 | else | |
8197 | { | |
8198 | char *argptr = arg; | |
8199 | int hasColon = 0; | |
8200 | ||
4a64f543 MS |
8201 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8202 | it is probably a line number. */ | |
c906108c | 8203 | while (*argptr && !hasColon) |
c5aa993b JM |
8204 | { |
8205 | hasColon = (*argptr == ':'); | |
8206 | argptr++; | |
8207 | } | |
c906108c SS |
8208 | |
8209 | if (hasColon) | |
c5aa993b | 8210 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8211 | else |
c5aa993b | 8212 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8213 | } |
8214 | ||
8215 | if (badInput) | |
a3f17187 | 8216 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8217 | else |
db107f19 | 8218 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8219 | } |
8220 | ||
4a64f543 MS |
8221 | /* Return non-zero if EXP is verified as constant. Returned zero |
8222 | means EXP is variable. Also the constant detection may fail for | |
8223 | some constant expressions and in such case still falsely return | |
8224 | zero. */ | |
65d79d4b SDJ |
8225 | static int |
8226 | watchpoint_exp_is_const (const struct expression *exp) | |
8227 | { | |
8228 | int i = exp->nelts; | |
8229 | ||
8230 | while (i > 0) | |
8231 | { | |
8232 | int oplenp, argsp; | |
8233 | ||
8234 | /* We are only interested in the descriptor of each element. */ | |
8235 | operator_length (exp, i, &oplenp, &argsp); | |
8236 | i -= oplenp; | |
8237 | ||
8238 | switch (exp->elts[i].opcode) | |
8239 | { | |
8240 | case BINOP_ADD: | |
8241 | case BINOP_SUB: | |
8242 | case BINOP_MUL: | |
8243 | case BINOP_DIV: | |
8244 | case BINOP_REM: | |
8245 | case BINOP_MOD: | |
8246 | case BINOP_LSH: | |
8247 | case BINOP_RSH: | |
8248 | case BINOP_LOGICAL_AND: | |
8249 | case BINOP_LOGICAL_OR: | |
8250 | case BINOP_BITWISE_AND: | |
8251 | case BINOP_BITWISE_IOR: | |
8252 | case BINOP_BITWISE_XOR: | |
8253 | case BINOP_EQUAL: | |
8254 | case BINOP_NOTEQUAL: | |
8255 | case BINOP_LESS: | |
8256 | case BINOP_GTR: | |
8257 | case BINOP_LEQ: | |
8258 | case BINOP_GEQ: | |
8259 | case BINOP_REPEAT: | |
8260 | case BINOP_COMMA: | |
8261 | case BINOP_EXP: | |
8262 | case BINOP_MIN: | |
8263 | case BINOP_MAX: | |
8264 | case BINOP_INTDIV: | |
8265 | case BINOP_CONCAT: | |
8266 | case BINOP_IN: | |
8267 | case BINOP_RANGE: | |
8268 | case TERNOP_COND: | |
8269 | case TERNOP_SLICE: | |
8270 | case TERNOP_SLICE_COUNT: | |
8271 | ||
8272 | case OP_LONG: | |
8273 | case OP_DOUBLE: | |
8274 | case OP_DECFLOAT: | |
8275 | case OP_LAST: | |
8276 | case OP_COMPLEX: | |
8277 | case OP_STRING: | |
8278 | case OP_BITSTRING: | |
8279 | case OP_ARRAY: | |
8280 | case OP_TYPE: | |
8281 | case OP_NAME: | |
8282 | case OP_OBJC_NSSTRING: | |
8283 | ||
8284 | case UNOP_NEG: | |
8285 | case UNOP_LOGICAL_NOT: | |
8286 | case UNOP_COMPLEMENT: | |
8287 | case UNOP_ADDR: | |
8288 | case UNOP_HIGH: | |
4a64f543 MS |
8289 | /* Unary, binary and ternary operators: We have to check |
8290 | their operands. If they are constant, then so is the | |
8291 | result of that operation. For instance, if A and B are | |
8292 | determined to be constants, then so is "A + B". | |
8293 | ||
8294 | UNOP_IND is one exception to the rule above, because the | |
8295 | value of *ADDR is not necessarily a constant, even when | |
8296 | ADDR is. */ | |
65d79d4b SDJ |
8297 | break; |
8298 | ||
8299 | case OP_VAR_VALUE: | |
8300 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8301 | |
65d79d4b | 8302 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8303 | possible that a buggy compiler could mark a variable as |
8304 | constant even when it is not, and TYPE_CONST would return | |
8305 | true in this case, while SYMBOL_CLASS wouldn't. | |
8306 | ||
8307 | We also have to check for function symbols because they | |
8308 | are always constant. */ | |
65d79d4b SDJ |
8309 | { |
8310 | struct symbol *s = exp->elts[i + 2].symbol; | |
8311 | ||
8312 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8313 | && SYMBOL_CLASS (s) != LOC_CONST | |
8314 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8315 | return 0; | |
8316 | break; | |
8317 | } | |
8318 | ||
8319 | /* The default action is to return 0 because we are using | |
8320 | the optimistic approach here: If we don't know something, | |
8321 | then it is not a constant. */ | |
8322 | default: | |
8323 | return 0; | |
8324 | } | |
8325 | } | |
8326 | ||
8327 | return 1; | |
8328 | } | |
8329 | ||
77b06cd7 TJB |
8330 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8331 | ||
8332 | static int | |
8333 | insert_watchpoint (struct bp_location *bl) | |
8334 | { | |
e09342b5 TJB |
8335 | int length = bl->owner->exact? 1 : bl->length; |
8336 | ||
8337 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
8338 | bl->owner->cond_exp); | |
77b06cd7 TJB |
8339 | } |
8340 | ||
8341 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8342 | ||
8343 | static int | |
8344 | remove_watchpoint (struct bp_location *bl) | |
8345 | { | |
e09342b5 TJB |
8346 | int length = bl->owner->exact? 1 : bl->length; |
8347 | ||
8348 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
8349 | bl->owner->cond_exp); | |
8350 | } | |
8351 | ||
8352 | /* Implement the "resources_needed" breakpoint_ops method for | |
8353 | hardware watchpoints. */ | |
8354 | ||
8355 | static int | |
8356 | resources_needed_watchpoint (const struct bp_location *bl) | |
8357 | { | |
90e4670f | 8358 | int length = bl->owner->exact? 1 : bl->length; |
e09342b5 | 8359 | |
90e4670f | 8360 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
77b06cd7 TJB |
8361 | } |
8362 | ||
8363 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8364 | ||
8365 | static struct breakpoint_ops watchpoint_breakpoint_ops = | |
8366 | { | |
8367 | insert_watchpoint, | |
8368 | remove_watchpoint, | |
8369 | NULL, /* breakpoint_hit */ | |
e09342b5 | 8370 | resources_needed_watchpoint, |
77b06cd7 TJB |
8371 | NULL, /* print_it */ |
8372 | NULL, /* print_one */ | |
8373 | NULL, /* print_mention */ | |
8374 | NULL /* print_recreate */ | |
8375 | }; | |
8376 | ||
53a5351d JM |
8377 | /* accessflag: hw_write: watch write, |
8378 | hw_read: watch read, | |
8379 | hw_access: watch access (read or write) */ | |
c906108c | 8380 | static void |
84f4c1fe PM |
8381 | watch_command_1 (char *arg, int accessflag, int from_tty, |
8382 | int just_location, int internal) | |
c906108c | 8383 | { |
d983da9c | 8384 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 8385 | struct expression *exp; |
60e1c644 | 8386 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 8387 | struct value *val, *mark, *result; |
c906108c | 8388 | struct frame_info *frame; |
c906108c SS |
8389 | char *exp_start = NULL; |
8390 | char *exp_end = NULL; | |
37e4754d | 8391 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
8392 | int toklen; |
8393 | char *cond_start = NULL; | |
8394 | char *cond_end = NULL; | |
c906108c SS |
8395 | int i, other_type_used, target_resources_ok = 0; |
8396 | enum bptype bp_type; | |
e09342b5 | 8397 | int reg_cnt = 0; |
37e4754d | 8398 | int thread = -1; |
0cf6dd15 | 8399 | int pc = 0; |
c906108c | 8400 | |
37e4754d LM |
8401 | /* Make sure that we actually have parameters to parse. */ |
8402 | if (arg != NULL && arg[0] != '\0') | |
8403 | { | |
8404 | toklen = strlen (arg); /* Size of argument list. */ | |
8405 | ||
8406 | /* Points tok to the end of the argument list. */ | |
8407 | tok = arg + toklen - 1; | |
8408 | ||
4a64f543 MS |
8409 | /* Go backwards in the parameters list. Skip the last |
8410 | parameter. If we're expecting a 'thread <thread_num>' | |
8411 | parameter, this should be the thread identifier. */ | |
37e4754d LM |
8412 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8413 | tok--; | |
8414 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8415 | tok--; | |
8416 | ||
8417 | /* Points end_tok to the beginning of the last token. */ | |
8418 | id_tok_start = tok + 1; | |
8419 | ||
4a64f543 MS |
8420 | /* Go backwards in the parameters list. Skip one more |
8421 | parameter. If we're expecting a 'thread <thread_num>' | |
8422 | parameter, we should reach a "thread" token. */ | |
37e4754d LM |
8423 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8424 | tok--; | |
8425 | ||
8426 | end_tok = tok; | |
8427 | ||
8428 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8429 | tok--; | |
8430 | ||
8431 | /* Move the pointer forward to skip the whitespace and | |
8432 | calculate the length of the token. */ | |
8433 | tok++; | |
8434 | toklen = end_tok - tok; | |
8435 | ||
8436 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8437 | { | |
8438 | /* At this point we've found a "thread" token, which means | |
8439 | the user is trying to set a watchpoint that triggers | |
8440 | only in a specific thread. */ | |
8441 | char *endp; | |
8442 | ||
8443 | /* Extract the thread ID from the next token. */ | |
8444 | thread = strtol (id_tok_start, &endp, 0); | |
8445 | ||
8446 | /* Check if the user provided a valid numeric value for the | |
8447 | thread ID. */ | |
8448 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
8449 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
8450 | ||
8451 | /* Check if the thread actually exists. */ | |
8452 | if (!valid_thread_id (thread)) | |
8453 | error (_("Unknown thread %d."), thread); | |
8454 | ||
8455 | /* Truncate the string and get rid of the thread <thread_num> | |
8456 | parameter before the parameter list is parsed by the | |
8457 | evaluate_expression() function. */ | |
8458 | *tok = '\0'; | |
8459 | } | |
8460 | } | |
8461 | ||
8462 | /* Parse the rest of the arguments. */ | |
c906108c SS |
8463 | innermost_block = NULL; |
8464 | exp_start = arg; | |
8465 | exp = parse_exp_1 (&arg, 0, 0); | |
8466 | exp_end = arg; | |
fa8a61dc TT |
8467 | /* Remove trailing whitespace from the expression before saving it. |
8468 | This makes the eventual display of the expression string a bit | |
8469 | prettier. */ | |
8470 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
8471 | --exp_end; | |
8472 | ||
65d79d4b SDJ |
8473 | /* Checking if the expression is not constant. */ |
8474 | if (watchpoint_exp_is_const (exp)) | |
8475 | { | |
8476 | int len; | |
8477 | ||
8478 | len = exp_end - exp_start; | |
8479 | while (len > 0 && isspace (exp_start[len - 1])) | |
8480 | len--; | |
8481 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
8482 | } | |
8483 | ||
c906108c SS |
8484 | exp_valid_block = innermost_block; |
8485 | mark = value_mark (); | |
a1442452 | 8486 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
8487 | |
8488 | if (just_location) | |
8489 | { | |
8490 | exp_valid_block = NULL; | |
a1442452 | 8491 | val = value_addr (result); |
06a64a0b TT |
8492 | release_value (val); |
8493 | value_free_to_mark (mark); | |
8494 | } | |
8495 | else if (val != NULL) | |
fa4727a6 | 8496 | release_value (val); |
c906108c SS |
8497 | |
8498 | tok = arg; | |
8499 | while (*tok == ' ' || *tok == '\t') | |
8500 | tok++; | |
8501 | end_tok = tok; | |
8502 | ||
8503 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
8504 | end_tok++; | |
8505 | ||
8506 | toklen = end_tok - tok; | |
8507 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8508 | { | |
2d134ed3 PA |
8509 | struct expression *cond; |
8510 | ||
60e1c644 | 8511 | innermost_block = NULL; |
c906108c SS |
8512 | tok = cond_start = end_tok + 1; |
8513 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
8514 | |
8515 | /* The watchpoint expression may not be local, but the condition | |
8516 | may still be. E.g.: `watch global if local > 0'. */ | |
8517 | cond_exp_valid_block = innermost_block; | |
8518 | ||
2d134ed3 | 8519 | xfree (cond); |
c906108c SS |
8520 | cond_end = tok; |
8521 | } | |
8522 | if (*tok) | |
8a3fe4f8 | 8523 | error (_("Junk at end of command.")); |
c906108c | 8524 | |
53a5351d | 8525 | if (accessflag == hw_read) |
c5aa993b | 8526 | bp_type = bp_read_watchpoint; |
53a5351d | 8527 | else if (accessflag == hw_access) |
c5aa993b JM |
8528 | bp_type = bp_access_watchpoint; |
8529 | else | |
8530 | bp_type = bp_hardware_watchpoint; | |
c906108c | 8531 | |
e09342b5 TJB |
8532 | reg_cnt = can_use_hardware_watchpoint (val, target_exact_watchpoints); |
8533 | if (reg_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 8534 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
e09342b5 | 8535 | if (reg_cnt != 0) |
c5aa993b JM |
8536 | { |
8537 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 8538 | target_resources_ok = |
e09342b5 | 8539 | target_can_use_hardware_watchpoint (bp_type, i + reg_cnt, |
53a5351d | 8540 | other_type_used); |
c5aa993b | 8541 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8542 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 8543 | |
c5aa993b | 8544 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
3e43a32a MS |
8545 | error (_("Target can only support one kind " |
8546 | "of HW watchpoint at a time.")); | |
c5aa993b | 8547 | } |
c906108c | 8548 | |
4a64f543 MS |
8549 | /* Change the type of breakpoint to an ordinary watchpoint if a |
8550 | hardware watchpoint could not be set. */ | |
e09342b5 | 8551 | if (!reg_cnt || target_resources_ok <= 0) |
4d28f7a8 KB |
8552 | bp_type = bp_watchpoint; |
8553 | ||
d983da9c | 8554 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
8555 | |
8556 | /* If the expression is "local", then set up a "watchpoint scope" | |
8557 | breakpoint at the point where we've left the scope of the watchpoint | |
8558 | expression. Create the scope breakpoint before the watchpoint, so | |
8559 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 8560 | if (exp_valid_block && frame) |
d983da9c | 8561 | { |
edb3359d DJ |
8562 | if (frame_id_p (frame_unwind_caller_id (frame))) |
8563 | { | |
8564 | scope_breakpoint | |
a6d9a66e UW |
8565 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
8566 | frame_unwind_caller_pc (frame), | |
edb3359d | 8567 | bp_watchpoint_scope); |
d983da9c | 8568 | |
edb3359d | 8569 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 8570 | |
edb3359d DJ |
8571 | /* Automatically delete the breakpoint when it hits. */ |
8572 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 8573 | |
edb3359d DJ |
8574 | /* Only break in the proper frame (help with recursion). */ |
8575 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 8576 | |
edb3359d | 8577 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
8578 | scope_breakpoint->loc->gdbarch |
8579 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
8580 | scope_breakpoint->loc->requested_address |
8581 | = frame_unwind_caller_pc (frame); | |
8582 | scope_breakpoint->loc->address | |
a6d9a66e UW |
8583 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
8584 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
8585 | scope_breakpoint->type); |
8586 | } | |
d983da9c DJ |
8587 | } |
8588 | ||
c906108c | 8589 | /* Now set up the breakpoint. */ |
2d134ed3 | 8590 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
84f4c1fe | 8591 | set_breakpoint_number (internal, b); |
37e4754d | 8592 | b->thread = thread; |
b5de0fa7 | 8593 | b->disposition = disp_donttouch; |
c906108c SS |
8594 | b->exp = exp; |
8595 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 8596 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
8597 | if (just_location) |
8598 | { | |
8599 | struct type *t = value_type (val); | |
8600 | CORE_ADDR addr = value_as_address (val); | |
8601 | char *name; | |
8602 | ||
8603 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
8604 | name = type_to_string (t); | |
8605 | ||
d63d0675 JK |
8606 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
8607 | core_addr_to_string (addr)); | |
06a64a0b TT |
8608 | xfree (name); |
8609 | ||
d63d0675 JK |
8610 | b->exp_string = xstrprintf ("-location: %.*s", |
8611 | (int) (exp_end - exp_start), exp_start); | |
8612 | ||
06a64a0b TT |
8613 | /* The above expression is in C. */ |
8614 | b->language = language_c; | |
8615 | } | |
8616 | else | |
8617 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
c906108c | 8618 | b->val = val; |
fa4727a6 | 8619 | b->val_valid = 1; |
77b06cd7 TJB |
8620 | b->ops = &watchpoint_breakpoint_ops; |
8621 | ||
e09342b5 TJB |
8622 | /* Use an exact watchpoint when there's only one memory region to be |
8623 | watched, and only one debug register is needed to watch it. */ | |
8624 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
8625 | ||
c906108c SS |
8626 | if (cond_start) |
8627 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
8628 | else | |
8629 | b->cond_string = 0; | |
c5aa993b | 8630 | |
c906108c | 8631 | if (frame) |
f6bc2008 PA |
8632 | { |
8633 | b->watchpoint_frame = get_frame_id (frame); | |
8634 | b->watchpoint_thread = inferior_ptid; | |
8635 | } | |
c906108c | 8636 | else |
f6bc2008 PA |
8637 | { |
8638 | b->watchpoint_frame = null_frame_id; | |
8639 | b->watchpoint_thread = null_ptid; | |
8640 | } | |
c906108c | 8641 | |
d983da9c | 8642 | if (scope_breakpoint != NULL) |
c906108c | 8643 | { |
d983da9c DJ |
8644 | /* The scope breakpoint is related to the watchpoint. We will |
8645 | need to act on them together. */ | |
8646 | b->related_breakpoint = scope_breakpoint; | |
8647 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 8648 | } |
d983da9c | 8649 | |
06a64a0b TT |
8650 | if (!just_location) |
8651 | value_free_to_mark (mark); | |
2d134ed3 PA |
8652 | |
8653 | /* Finally update the new watchpoint. This creates the locations | |
8654 | that should be inserted. */ | |
8655 | update_watchpoint (b, 1); | |
84f4c1fe PM |
8656 | if (internal) |
8657 | /* Do not mention breakpoints with a negative number, but do | |
8658 | notify observers. */ | |
8659 | observer_notify_breakpoint_created (b->number); | |
8660 | else | |
8661 | mention (b); | |
b60e7edf | 8662 | update_global_location_list (1); |
c906108c SS |
8663 | } |
8664 | ||
e09342b5 TJB |
8665 | /* Return count of debug registers needed to watch the given expression. |
8666 | If EXACT_WATCHPOINTS is 1, then consider that only the address of | |
8667 | the start of the watched region will be monitored (i.e., all accesses | |
8668 | will be aligned). This uses less debug registers on some targets. | |
8669 | ||
8670 | If the watchpoint cannot be handled in hardware return zero. */ | |
c906108c | 8671 | |
c906108c | 8672 | static int |
e09342b5 | 8673 | can_use_hardware_watchpoint (struct value *v, int exact_watchpoints) |
c906108c SS |
8674 | { |
8675 | int found_memory_cnt = 0; | |
2e70b7b9 | 8676 | struct value *head = v; |
c906108c SS |
8677 | |
8678 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 8679 | if (!can_use_hw_watchpoints) |
c906108c | 8680 | return 0; |
c5aa993b | 8681 | |
5c44784c JM |
8682 | /* Make sure that the value of the expression depends only upon |
8683 | memory contents, and values computed from them within GDB. If we | |
8684 | find any register references or function calls, we can't use a | |
8685 | hardware watchpoint. | |
8686 | ||
8687 | The idea here is that evaluating an expression generates a series | |
8688 | of values, one holding the value of every subexpression. (The | |
8689 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
8690 | a*b+c.) GDB's values hold almost enough information to establish | |
8691 | the criteria given above --- they identify memory lvalues, | |
8692 | register lvalues, computed values, etcetera. So we can evaluate | |
8693 | the expression, and then scan the chain of values that leaves | |
8694 | behind to decide whether we can detect any possible change to the | |
8695 | expression's final value using only hardware watchpoints. | |
8696 | ||
8697 | However, I don't think that the values returned by inferior | |
8698 | function calls are special in any way. So this function may not | |
8699 | notice that an expression involving an inferior function call | |
8700 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 8701 | for (; v; v = value_next (v)) |
c906108c | 8702 | { |
5c44784c | 8703 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 8704 | { |
8464be76 DJ |
8705 | if (v != head && value_lazy (v)) |
8706 | /* A lazy memory lvalue in the chain is one that GDB never | |
8707 | needed to fetch; we either just used its address (e.g., | |
8708 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
8709 | in `a,b'). This doesn't apply to HEAD; if that is | |
8710 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 8711 | ; |
53a5351d | 8712 | else |
5c44784c JM |
8713 | { |
8714 | /* Ahh, memory we actually used! Check if we can cover | |
8715 | it with hardware watchpoints. */ | |
df407dfe | 8716 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
8717 | |
8718 | /* We only watch structs and arrays if user asked for it | |
8719 | explicitly, never if they just happen to appear in a | |
8720 | middle of some value chain. */ | |
8721 | if (v == head | |
8722 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
8723 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
8724 | { | |
42ae5230 | 8725 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
8726 | int len; |
8727 | int num_regs; | |
8728 | ||
8729 | len = (exact_watchpoints | |
8730 | && is_scalar_type_recursive (vtype))? | |
8731 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 8732 | |
e09342b5 TJB |
8733 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
8734 | if (!num_regs) | |
2e70b7b9 MS |
8735 | return 0; |
8736 | else | |
e09342b5 | 8737 | found_memory_cnt += num_regs; |
2e70b7b9 | 8738 | } |
5c44784c | 8739 | } |
c5aa993b | 8740 | } |
5086187c AC |
8741 | else if (VALUE_LVAL (v) != not_lval |
8742 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 8743 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 8744 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 8745 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
8746 | } |
8747 | ||
8748 | /* The expression itself looks suitable for using a hardware | |
8749 | watchpoint, but give the target machine a chance to reject it. */ | |
8750 | return found_memory_cnt; | |
8751 | } | |
8752 | ||
8b93c638 | 8753 | void |
84f4c1fe | 8754 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8755 | { |
84f4c1fe | 8756 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
8757 | } |
8758 | ||
8759 | /* A helper function that looks for an argument at the start of a | |
8760 | string. The argument must also either be at the end of the string, | |
8761 | or be followed by whitespace. Returns 1 if it finds the argument, | |
8762 | 0 otherwise. If the argument is found, it updates *STR. */ | |
8763 | ||
8764 | static int | |
8765 | check_for_argument (char **str, char *arg, int arg_len) | |
8766 | { | |
8767 | if (strncmp (*str, arg, arg_len) == 0 | |
8768 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
8769 | { | |
8770 | *str += arg_len; | |
8771 | return 1; | |
8772 | } | |
8773 | return 0; | |
8774 | } | |
8775 | ||
8776 | /* A helper function that looks for the "-location" argument and then | |
8777 | calls watch_command_1. */ | |
8778 | ||
8779 | static void | |
8780 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
8781 | { | |
8782 | int just_location = 0; | |
8783 | ||
8784 | if (arg | |
8785 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
8786 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
8787 | { | |
8788 | ep_skip_leading_whitespace (&arg); | |
8789 | just_location = 1; | |
8790 | } | |
8791 | ||
84f4c1fe | 8792 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 8793 | } |
8926118c | 8794 | |
c5aa993b | 8795 | static void |
fba45db2 | 8796 | watch_command (char *arg, int from_tty) |
c906108c | 8797 | { |
06a64a0b | 8798 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
8799 | } |
8800 | ||
8b93c638 | 8801 | void |
84f4c1fe | 8802 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8803 | { |
84f4c1fe | 8804 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 8805 | } |
8926118c | 8806 | |
c5aa993b | 8807 | static void |
fba45db2 | 8808 | rwatch_command (char *arg, int from_tty) |
c906108c | 8809 | { |
06a64a0b | 8810 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
8811 | } |
8812 | ||
8b93c638 | 8813 | void |
84f4c1fe | 8814 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8815 | { |
84f4c1fe | 8816 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 8817 | } |
8926118c | 8818 | |
c5aa993b | 8819 | static void |
fba45db2 | 8820 | awatch_command (char *arg, int from_tty) |
c906108c | 8821 | { |
06a64a0b | 8822 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 8823 | } |
c906108c | 8824 | \f |
c5aa993b | 8825 | |
43ff13b4 | 8826 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8827 | because it uses the mechanisms of breakpoints. */ |
8828 | ||
bfec99b2 PA |
8829 | struct until_break_command_continuation_args |
8830 | { | |
8831 | struct breakpoint *breakpoint; | |
8832 | struct breakpoint *breakpoint2; | |
186c406b | 8833 | int thread_num; |
bfec99b2 PA |
8834 | }; |
8835 | ||
43ff13b4 | 8836 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 8837 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 8838 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 8839 | command. */ |
c2c6d25f | 8840 | static void |
604ead4a | 8841 | until_break_command_continuation (void *arg) |
43ff13b4 | 8842 | { |
bfec99b2 PA |
8843 | struct until_break_command_continuation_args *a = arg; |
8844 | ||
8845 | delete_breakpoint (a->breakpoint); | |
8846 | if (a->breakpoint2) | |
8847 | delete_breakpoint (a->breakpoint2); | |
186c406b | 8848 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
8849 | } |
8850 | ||
c906108c | 8851 | void |
ae66c1fc | 8852 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8853 | { |
8854 | struct symtabs_and_lines sals; | |
8855 | struct symtab_and_line sal; | |
206415a3 | 8856 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8857 | struct breakpoint *breakpoint; |
f107f563 | 8858 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 8859 | struct cleanup *old_chain; |
186c406b TT |
8860 | int thread; |
8861 | struct thread_info *tp; | |
c906108c SS |
8862 | |
8863 | clear_proceed_status (); | |
8864 | ||
8865 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 8866 | this function. */ |
c5aa993b | 8867 | |
c906108c SS |
8868 | if (default_breakpoint_valid) |
8869 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 8870 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 8871 | else |
53a5351d | 8872 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 8873 | 0, (char ***) NULL, NULL); |
c5aa993b | 8874 | |
c906108c | 8875 | if (sals.nelts != 1) |
8a3fe4f8 | 8876 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8877 | |
c906108c | 8878 | sal = sals.sals[0]; |
4a64f543 | 8879 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 8880 | |
c906108c | 8881 | if (*arg) |
8a3fe4f8 | 8882 | error (_("Junk at end of arguments.")); |
c5aa993b | 8883 | |
c906108c | 8884 | resolve_sal_pc (&sal); |
c5aa993b | 8885 | |
ae66c1fc EZ |
8886 | if (anywhere) |
8887 | /* If the user told us to continue until a specified location, | |
8888 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8889 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8890 | null_frame_id, bp_until); | |
ae66c1fc | 8891 | else |
4a64f543 MS |
8892 | /* Otherwise, specify the selected frame, because we want to stop |
8893 | only at the very same frame. */ | |
a6d9a66e UW |
8894 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8895 | get_stack_frame_id (frame), | |
ae66c1fc | 8896 | bp_until); |
c5aa993b | 8897 | |
f107f563 | 8898 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8899 | |
186c406b TT |
8900 | tp = inferior_thread (); |
8901 | thread = tp->num; | |
8902 | ||
ae66c1fc EZ |
8903 | /* Keep within the current frame, or in frames called by the current |
8904 | one. */ | |
edb3359d DJ |
8905 | |
8906 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8907 | { |
edb3359d DJ |
8908 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8909 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8910 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8911 | sal, | |
edb3359d | 8912 | frame_unwind_caller_id (frame), |
f107f563 VP |
8913 | bp_until); |
8914 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
8915 | |
8916 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
8917 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 8918 | } |
c5aa993b | 8919 | |
c906108c | 8920 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 8921 | |
4a64f543 MS |
8922 | /* If we are running asynchronously, and proceed call above has |
8923 | actually managed to start the target, arrange for breakpoints to | |
8924 | be deleted when the target stops. Otherwise, we're already | |
8925 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 8926 | |
8ea051c5 | 8927 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8928 | { |
bfec99b2 PA |
8929 | struct until_break_command_continuation_args *args; |
8930 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8931 | |
bfec99b2 PA |
8932 | args->breakpoint = breakpoint; |
8933 | args->breakpoint2 = breakpoint2; | |
186c406b | 8934 | args->thread_num = thread; |
f107f563 VP |
8935 | |
8936 | discard_cleanups (old_chain); | |
95e54da7 PA |
8937 | add_continuation (inferior_thread (), |
8938 | until_break_command_continuation, args, | |
604ead4a | 8939 | xfree); |
f107f563 VP |
8940 | } |
8941 | else | |
c5aa993b | 8942 | do_cleanups (old_chain); |
c906108c | 8943 | } |
ae66c1fc | 8944 | |
c906108c | 8945 | static void |
fba45db2 | 8946 | ep_skip_leading_whitespace (char **s) |
c906108c | 8947 | { |
c5aa993b JM |
8948 | if ((s == NULL) || (*s == NULL)) |
8949 | return; | |
8950 | while (isspace (**s)) | |
8951 | *s += 1; | |
c906108c | 8952 | } |
c5aa993b | 8953 | |
c906108c SS |
8954 | /* This function attempts to parse an optional "if <cond>" clause |
8955 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8956 | |
c906108c SS |
8957 | Else, it returns a pointer to the condition string. (It does not |
8958 | attempt to evaluate the string against a particular block.) And, | |
8959 | it updates arg to point to the first character following the parsed | |
4a64f543 | 8960 | if clause in the arg string. */ |
53a5351d | 8961 | |
c906108c | 8962 | static char * |
fba45db2 | 8963 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8964 | { |
c5aa993b JM |
8965 | char *cond_string; |
8966 | ||
8967 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8968 | return NULL; |
c5aa993b | 8969 | |
4a64f543 | 8970 | /* Skip the "if" keyword. */ |
c906108c | 8971 | (*arg) += 2; |
c5aa993b | 8972 | |
c906108c | 8973 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 8974 | condition string. */ |
c906108c SS |
8975 | ep_skip_leading_whitespace (arg); |
8976 | cond_string = *arg; | |
c5aa993b | 8977 | |
4a64f543 MS |
8978 | /* Assume that the condition occupies the remainder of the arg |
8979 | string. */ | |
c906108c | 8980 | (*arg) += strlen (cond_string); |
c5aa993b | 8981 | |
c906108c SS |
8982 | return cond_string; |
8983 | } | |
c5aa993b | 8984 | |
c906108c SS |
8985 | /* Commands to deal with catching events, such as signals, exceptions, |
8986 | process start/exit, etc. */ | |
c5aa993b JM |
8987 | |
8988 | typedef enum | |
8989 | { | |
44feb3ce TT |
8990 | catch_fork_temporary, catch_vfork_temporary, |
8991 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8992 | } |
8993 | catch_fork_kind; | |
8994 | ||
c906108c | 8995 | static void |
cc59ec59 MS |
8996 | catch_fork_command_1 (char *arg, int from_tty, |
8997 | struct cmd_list_element *command) | |
c906108c | 8998 | { |
a6d9a66e | 8999 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9000 | char *cond_string = NULL; |
44feb3ce TT |
9001 | catch_fork_kind fork_kind; |
9002 | int tempflag; | |
9003 | ||
9004 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9005 | tempflag = (fork_kind == catch_fork_temporary | |
9006 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9007 | |
44feb3ce TT |
9008 | if (!arg) |
9009 | arg = ""; | |
c906108c | 9010 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 9011 | |
c906108c | 9012 | /* The allowed syntax is: |
c5aa993b JM |
9013 | catch [v]fork |
9014 | catch [v]fork if <cond> | |
9015 | ||
4a64f543 | 9016 | First, check if there's an if clause. */ |
c906108c | 9017 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9018 | |
c906108c | 9019 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9020 | error (_("Junk at end of arguments.")); |
c5aa993b | 9021 | |
c906108c | 9022 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9023 | and enable reporting of such events. */ |
c5aa993b JM |
9024 | switch (fork_kind) |
9025 | { | |
44feb3ce TT |
9026 | case catch_fork_temporary: |
9027 | case catch_fork_permanent: | |
a6d9a66e | 9028 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9029 | &catch_fork_breakpoint_ops); |
c906108c | 9030 | break; |
44feb3ce TT |
9031 | case catch_vfork_temporary: |
9032 | case catch_vfork_permanent: | |
a6d9a66e | 9033 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9034 | &catch_vfork_breakpoint_ops); |
c906108c | 9035 | break; |
c5aa993b | 9036 | default: |
8a3fe4f8 | 9037 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9038 | break; |
c5aa993b | 9039 | } |
c906108c SS |
9040 | } |
9041 | ||
9042 | static void | |
cc59ec59 MS |
9043 | catch_exec_command_1 (char *arg, int from_tty, |
9044 | struct cmd_list_element *command) | |
c906108c | 9045 | { |
a6d9a66e | 9046 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9047 | int tempflag; |
c5aa993b | 9048 | char *cond_string = NULL; |
c906108c | 9049 | |
44feb3ce TT |
9050 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9051 | ||
9052 | if (!arg) | |
9053 | arg = ""; | |
c906108c SS |
9054 | ep_skip_leading_whitespace (&arg); |
9055 | ||
9056 | /* The allowed syntax is: | |
c5aa993b JM |
9057 | catch exec |
9058 | catch exec if <cond> | |
c906108c | 9059 | |
4a64f543 | 9060 | First, check if there's an if clause. */ |
c906108c SS |
9061 | cond_string = ep_parse_optional_if_clause (&arg); |
9062 | ||
9063 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9064 | error (_("Junk at end of arguments.")); |
c906108c SS |
9065 | |
9066 | /* If this target supports it, create an exec catchpoint | |
4a64f543 | 9067 | and enable reporting of such events. */ |
a6d9a66e UW |
9068 | create_catchpoint (gdbarch, tempflag, cond_string, |
9069 | &catch_exec_breakpoint_ops); | |
c906108c | 9070 | } |
c5aa993b | 9071 | |
3086aeae DJ |
9072 | static enum print_stop_action |
9073 | print_exception_catchpoint (struct breakpoint *b) | |
9074 | { | |
ade92717 | 9075 | int bp_temp, bp_throw; |
3086aeae | 9076 | |
ade92717 | 9077 | annotate_catchpoint (b->number); |
3086aeae | 9078 | |
ade92717 AR |
9079 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9080 | if (b->loc->address != b->loc->requested_address) | |
9081 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9082 | b->loc->address, | |
9083 | b->number, 1); | |
df2b6d2d | 9084 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9085 | ui_out_text (uiout, |
9086 | bp_temp ? "Temporary catchpoint " | |
9087 | : "Catchpoint "); | |
9088 | if (!ui_out_is_mi_like_p (uiout)) | |
9089 | ui_out_field_int (uiout, "bkptno", b->number); | |
9090 | ui_out_text (uiout, | |
c0b37c48 AR |
9091 | bp_throw ? " (exception thrown), " |
9092 | : " (exception caught), "); | |
ade92717 AR |
9093 | if (ui_out_is_mi_like_p (uiout)) |
9094 | { | |
9095 | ui_out_field_string (uiout, "reason", | |
9096 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9097 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9098 | ui_out_field_int (uiout, "bkptno", b->number); | |
9099 | } | |
3086aeae DJ |
9100 | return PRINT_SRC_AND_LOC; |
9101 | } | |
9102 | ||
9103 | static void | |
cc59ec59 MS |
9104 | print_one_exception_catchpoint (struct breakpoint *b, |
9105 | struct bp_location **last_loc) | |
3086aeae | 9106 | { |
79a45b7d | 9107 | struct value_print_options opts; |
cc59ec59 | 9108 | |
79a45b7d TT |
9109 | get_user_print_options (&opts); |
9110 | if (opts.addressprint) | |
3086aeae DJ |
9111 | { |
9112 | annotate_field (4); | |
604133b5 AR |
9113 | if (b->loc == NULL || b->loc->shlib_disabled) |
9114 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9115 | else | |
5af949e3 UW |
9116 | ui_out_field_core_addr (uiout, "addr", |
9117 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9118 | } |
9119 | annotate_field (5); | |
604133b5 | 9120 | if (b->loc) |
a6d9a66e | 9121 | *last_loc = b->loc; |
3086aeae DJ |
9122 | if (strstr (b->addr_string, "throw") != NULL) |
9123 | ui_out_field_string (uiout, "what", "exception throw"); | |
9124 | else | |
9125 | ui_out_field_string (uiout, "what", "exception catch"); | |
9126 | } | |
9127 | ||
9128 | static void | |
9129 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9130 | { | |
ade92717 AR |
9131 | int bp_temp; |
9132 | int bp_throw; | |
9133 | ||
df2b6d2d | 9134 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9135 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9136 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9137 | : _("Catchpoint ")); | |
9138 | ui_out_field_int (uiout, "bkptno", b->number); | |
9139 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9140 | : _(" (catch)")); | |
3086aeae DJ |
9141 | } |
9142 | ||
6149aea9 PA |
9143 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9144 | catch catchpoints. */ | |
9145 | ||
9146 | static void | |
4a64f543 MS |
9147 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9148 | struct ui_file *fp) | |
6149aea9 PA |
9149 | { |
9150 | int bp_temp; | |
9151 | int bp_throw; | |
9152 | ||
9153 | bp_temp = b->disposition == disp_del; | |
9154 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9155 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9156 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
9157 | } | |
9158 | ||
3086aeae | 9159 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
9160 | NULL, /* insert */ |
9161 | NULL, /* remove */ | |
9162 | NULL, /* breakpoint_hit */ | |
e09342b5 | 9163 | NULL, /* resources_needed */ |
3086aeae DJ |
9164 | print_exception_catchpoint, |
9165 | print_one_exception_catchpoint, | |
6149aea9 PA |
9166 | print_mention_exception_catchpoint, |
9167 | print_recreate_exception_catchpoint | |
3086aeae DJ |
9168 | }; |
9169 | ||
9170 | static int | |
9171 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9172 | enum exception_event_kind ex_event, int from_tty) | |
9173 | { | |
604133b5 AR |
9174 | char *trigger_func_name; |
9175 | ||
3086aeae | 9176 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9177 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9178 | else |
604133b5 | 9179 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9180 | |
8cdf0e15 VP |
9181 | create_breakpoint (get_current_arch (), |
9182 | trigger_func_name, cond_string, -1, | |
9183 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9184 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9185 | 0, |
9186 | AUTO_BOOLEAN_TRUE /* pending */, | |
9187 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9188 | 1 /* enabled */, |
9189 | 0 /* internal */); | |
3086aeae | 9190 | |
3086aeae DJ |
9191 | return 1; |
9192 | } | |
9193 | ||
4a64f543 | 9194 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9195 | |
9196 | static void | |
fba45db2 KB |
9197 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9198 | int tempflag, int from_tty) | |
c906108c | 9199 | { |
c5aa993b | 9200 | char *cond_string = NULL; |
c5aa993b | 9201 | |
44feb3ce TT |
9202 | if (!arg) |
9203 | arg = ""; | |
c906108c | 9204 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 9205 | |
c906108c SS |
9206 | cond_string = ep_parse_optional_if_clause (&arg); |
9207 | ||
9208 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9209 | error (_("Junk at end of arguments.")); |
c906108c | 9210 | |
059fb39f PM |
9211 | if (ex_event != EX_EVENT_THROW |
9212 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9213 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9214 | |
3086aeae DJ |
9215 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9216 | return; | |
9217 | ||
8a3fe4f8 | 9218 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9219 | } |
9220 | ||
44feb3ce TT |
9221 | /* Implementation of "catch catch" command. */ |
9222 | ||
9223 | static void | |
9224 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9225 | { | |
9226 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9227 | |
44feb3ce TT |
9228 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9229 | } | |
9230 | ||
9231 | /* Implementation of "catch throw" command. */ | |
9232 | ||
9233 | static void | |
9234 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9235 | { | |
9236 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9237 | |
44feb3ce TT |
9238 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9239 | } | |
9240 | ||
f7f9143b JB |
9241 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
9242 | ||
9243 | static void | |
a6d9a66e UW |
9244 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
9245 | struct symtab_and_line sal, | |
f7f9143b JB |
9246 | char *addr_string, |
9247 | char *exp_string, | |
9248 | char *cond_string, | |
9249 | struct expression *cond, | |
9250 | struct breakpoint_ops *ops, | |
9251 | int tempflag, | |
9252 | int from_tty) | |
9253 | { | |
9254 | struct breakpoint *b; | |
9255 | ||
9256 | if (from_tty) | |
9257 | { | |
5af949e3 UW |
9258 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9259 | if (!loc_gdbarch) | |
9260 | loc_gdbarch = gdbarch; | |
9261 | ||
6c95b8df PA |
9262 | describe_other_breakpoints (loc_gdbarch, |
9263 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9264 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9265 | version for exception catchpoints, because two catchpoints | |
9266 | used for different exception names will use the same address. | |
9267 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9268 | unproductive. Besides, the warning phrasing is also a bit |
f7f9143b JB |
9269 | inapropriate, we should use the word catchpoint, and tell |
9270 | the user what type of catchpoint it is. The above is good | |
9271 | enough for now, though. */ | |
9272 | } | |
9273 | ||
a6d9a66e | 9274 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
9275 | set_breakpoint_count (breakpoint_count + 1); |
9276 | ||
9277 | b->enable_state = bp_enabled; | |
9278 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
9279 | b->number = breakpoint_count; | |
9280 | b->ignore_count = 0; | |
511a6cd4 | 9281 | b->loc->cond = cond; |
f7f9143b JB |
9282 | b->addr_string = addr_string; |
9283 | b->language = language_ada; | |
9284 | b->cond_string = cond_string; | |
9285 | b->exp_string = exp_string; | |
9286 | b->thread = -1; | |
9287 | b->ops = ops; | |
f7f9143b JB |
9288 | |
9289 | mention (b); | |
b60e7edf | 9290 | update_global_location_list (1); |
f7f9143b JB |
9291 | } |
9292 | ||
9293 | /* Implement the "catch exception" command. */ | |
9294 | ||
9295 | static void | |
44feb3ce TT |
9296 | catch_ada_exception_command (char *arg, int from_tty, |
9297 | struct cmd_list_element *command) | |
f7f9143b | 9298 | { |
a6d9a66e | 9299 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9300 | int tempflag; |
f7f9143b | 9301 | struct symtab_and_line sal; |
f7f9143b JB |
9302 | char *addr_string = NULL; |
9303 | char *exp_string = NULL; | |
9304 | char *cond_string = NULL; | |
9305 | struct expression *cond = NULL; | |
9306 | struct breakpoint_ops *ops = NULL; | |
9307 | ||
44feb3ce TT |
9308 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9309 | ||
9310 | if (!arg) | |
9311 | arg = ""; | |
f7f9143b JB |
9312 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
9313 | &cond_string, &cond, &ops); | |
a6d9a66e | 9314 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
9315 | cond_string, cond, ops, tempflag, |
9316 | from_tty); | |
9317 | } | |
9318 | ||
a96d9b2e SDJ |
9319 | /* Cleanup function for a syscall filter list. */ |
9320 | static void | |
9321 | clean_up_filters (void *arg) | |
9322 | { | |
9323 | VEC(int) *iter = *(VEC(int) **) arg; | |
9324 | VEC_free (int, iter); | |
9325 | } | |
9326 | ||
9327 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
9328 | filter list, or NULL if no filtering is required. */ | |
9329 | static VEC(int) * | |
9330 | catch_syscall_split_args (char *arg) | |
9331 | { | |
9332 | VEC(int) *result = NULL; | |
9333 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
9334 | ||
9335 | while (*arg != '\0') | |
9336 | { | |
9337 | int i, syscall_number; | |
9338 | char *endptr; | |
9339 | char cur_name[128]; | |
9340 | struct syscall s; | |
9341 | ||
9342 | /* Skip whitespace. */ | |
9343 | while (isspace (*arg)) | |
9344 | arg++; | |
9345 | ||
9346 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9347 | cur_name[i] = arg[i]; | |
9348 | cur_name[i] = '\0'; | |
9349 | arg += i; | |
9350 | ||
9351 | /* Check if the user provided a syscall name or a number. */ | |
9352 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9353 | if (*endptr == '\0') | |
bccd0dd2 | 9354 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9355 | else |
9356 | { | |
9357 | /* We have a name. Let's check if it's valid and convert it | |
9358 | to a number. */ | |
9359 | get_syscall_by_name (cur_name, &s); | |
9360 | ||
9361 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9362 | /* Here we have to issue an error instead of a warning, |
9363 | because GDB cannot do anything useful if there's no | |
9364 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9365 | error (_("Unknown syscall name '%s'."), cur_name); |
9366 | } | |
9367 | ||
9368 | /* Ok, it's valid. */ | |
9369 | VEC_safe_push (int, result, s.number); | |
9370 | } | |
9371 | ||
9372 | discard_cleanups (cleanup); | |
9373 | return result; | |
9374 | } | |
9375 | ||
9376 | /* Implement the "catch syscall" command. */ | |
9377 | ||
9378 | static void | |
cc59ec59 MS |
9379 | catch_syscall_command_1 (char *arg, int from_tty, |
9380 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
9381 | { |
9382 | int tempflag; | |
9383 | VEC(int) *filter; | |
9384 | struct syscall s; | |
9385 | struct gdbarch *gdbarch = get_current_arch (); | |
9386 | ||
9387 | /* Checking if the feature if supported. */ | |
9388 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
9389 | error (_("The feature 'catch syscall' is not supported on \ | |
9390 | this architeture yet.")); | |
9391 | ||
9392 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
9393 | ||
9394 | ep_skip_leading_whitespace (&arg); | |
9395 | ||
9396 | /* We need to do this first "dummy" translation in order | |
9397 | to get the syscall XML file loaded or, most important, | |
9398 | to display a warning to the user if there's no XML file | |
9399 | for his/her architecture. */ | |
9400 | get_syscall_by_number (0, &s); | |
9401 | ||
9402 | /* The allowed syntax is: | |
9403 | catch syscall | |
9404 | catch syscall <name | number> [<name | number> ... <name | number>] | |
9405 | ||
9406 | Let's check if there's a syscall name. */ | |
9407 | ||
9408 | if (arg != NULL) | |
9409 | filter = catch_syscall_split_args (arg); | |
9410 | else | |
9411 | filter = NULL; | |
9412 | ||
9413 | create_syscall_event_catchpoint (tempflag, filter, | |
9414 | &catch_syscall_breakpoint_ops); | |
9415 | } | |
9416 | ||
f7f9143b JB |
9417 | /* Implement the "catch assert" command. */ |
9418 | ||
9419 | static void | |
3e43a32a MS |
9420 | catch_assert_command (char *arg, int from_tty, |
9421 | struct cmd_list_element *command) | |
f7f9143b | 9422 | { |
a6d9a66e | 9423 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9424 | int tempflag; |
f7f9143b JB |
9425 | struct symtab_and_line sal; |
9426 | char *addr_string = NULL; | |
9427 | struct breakpoint_ops *ops = NULL; | |
9428 | ||
44feb3ce TT |
9429 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9430 | ||
9431 | if (!arg) | |
9432 | arg = ""; | |
f7f9143b | 9433 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
9434 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
9435 | ops, tempflag, from_tty); | |
f7f9143b JB |
9436 | } |
9437 | ||
c906108c | 9438 | static void |
fba45db2 | 9439 | catch_command (char *arg, int from_tty) |
c906108c | 9440 | { |
44feb3ce | 9441 | error (_("Catch requires an event name.")); |
c906108c SS |
9442 | } |
9443 | \f | |
9444 | ||
9445 | static void | |
fba45db2 | 9446 | tcatch_command (char *arg, int from_tty) |
c906108c | 9447 | { |
44feb3ce | 9448 | error (_("Catch requires an event name.")); |
c906108c SS |
9449 | } |
9450 | ||
80f8a6eb | 9451 | /* Delete breakpoints by address or line. */ |
c906108c SS |
9452 | |
9453 | static void | |
fba45db2 | 9454 | clear_command (char *arg, int from_tty) |
c906108c | 9455 | { |
d6e956e5 VP |
9456 | struct breakpoint *b; |
9457 | VEC(breakpoint_p) *found = 0; | |
9458 | int ix; | |
c906108c SS |
9459 | int default_match; |
9460 | struct symtabs_and_lines sals; | |
9461 | struct symtab_and_line sal; | |
c906108c SS |
9462 | int i; |
9463 | ||
9464 | if (arg) | |
9465 | { | |
9466 | sals = decode_line_spec (arg, 1); | |
9467 | default_match = 0; | |
9468 | } | |
9469 | else | |
9470 | { | |
c5aa993b | 9471 | sals.sals = (struct symtab_and_line *) |
c906108c | 9472 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 9473 | make_cleanup (xfree, sals.sals); |
4a64f543 | 9474 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
9475 | sal.line = default_breakpoint_line; |
9476 | sal.symtab = default_breakpoint_symtab; | |
9477 | sal.pc = default_breakpoint_address; | |
6c95b8df | 9478 | sal.pspace = default_breakpoint_pspace; |
c906108c | 9479 | if (sal.symtab == 0) |
8a3fe4f8 | 9480 | error (_("No source file specified.")); |
c906108c SS |
9481 | |
9482 | sals.sals[0] = sal; | |
9483 | sals.nelts = 1; | |
9484 | ||
9485 | default_match = 1; | |
9486 | } | |
9487 | ||
4a64f543 MS |
9488 | /* We don't call resolve_sal_pc here. That's not as bad as it |
9489 | seems, because all existing breakpoints typically have both | |
9490 | file/line and pc set. So, if clear is given file/line, we can | |
9491 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
9492 | |
9493 | We only support clearing given the address explicitly | |
9494 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 9495 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 9496 | due to optimization, all in one block. |
4a64f543 MS |
9497 | |
9498 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
9499 | PC corresponding to the same file:line, the breakpoint won't |
9500 | be cleared. We probably can still clear the breakpoint, but | |
9501 | since the other PC value is never presented to user, user | |
9502 | can only find it by guessing, and it does not seem important | |
9503 | to support that. */ | |
9504 | ||
4a64f543 MS |
9505 | /* For each line spec given, delete bps which correspond to it. Do |
9506 | it in two passes, solely to preserve the current behavior that | |
9507 | from_tty is forced true if we delete more than one | |
9508 | breakpoint. */ | |
c906108c | 9509 | |
80f8a6eb | 9510 | found = NULL; |
c906108c SS |
9511 | for (i = 0; i < sals.nelts; i++) |
9512 | { | |
9513 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
9514 | If line given (pc == 0), clear all bpts on specified line. |
9515 | If defaulting, clear all bpts on default line | |
c906108c | 9516 | or at default pc. |
c5aa993b JM |
9517 | |
9518 | defaulting sal.pc != 0 tests to do | |
9519 | ||
9520 | 0 1 pc | |
9521 | 1 1 pc _and_ line | |
9522 | 0 0 line | |
9523 | 1 0 <can't happen> */ | |
c906108c SS |
9524 | |
9525 | sal = sals.sals[i]; | |
c906108c | 9526 | |
4a64f543 | 9527 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 9528 | ALL_BREAKPOINTS (b) |
c5aa993b | 9529 | { |
0d381245 | 9530 | int match = 0; |
4a64f543 | 9531 | /* Are we going to delete b? */ |
cc60f2e3 | 9532 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
9533 | { |
9534 | struct bp_location *loc = b->loc; | |
9535 | for (; loc; loc = loc->next) | |
9536 | { | |
6c95b8df PA |
9537 | int pc_match = sal.pc |
9538 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
9539 | && (loc->address == sal.pc) |
9540 | && (!section_is_overlay (loc->section) | |
9541 | || loc->section == sal.section); | |
9542 | int line_match = ((default_match || (0 == sal.pc)) | |
9543 | && b->source_file != NULL | |
9544 | && sal.symtab != NULL | |
6c95b8df | 9545 | && sal.pspace == loc->pspace |
3e43a32a MS |
9546 | && strcmp (b->source_file, |
9547 | sal.symtab->filename) == 0 | |
0d381245 VP |
9548 | && b->line_number == sal.line); |
9549 | if (pc_match || line_match) | |
9550 | { | |
9551 | match = 1; | |
9552 | break; | |
9553 | } | |
9554 | } | |
9555 | } | |
9556 | ||
9557 | if (match) | |
d6e956e5 | 9558 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 9559 | } |
80f8a6eb MS |
9560 | } |
9561 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 9562 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
9563 | { |
9564 | if (arg) | |
8a3fe4f8 | 9565 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 9566 | else |
8a3fe4f8 | 9567 | error (_("No breakpoint at this line.")); |
80f8a6eb | 9568 | } |
c906108c | 9569 | |
d6e956e5 | 9570 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 9571 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 9572 | if (from_tty) |
a3f17187 | 9573 | { |
d6e956e5 | 9574 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
9575 | printf_unfiltered (_("Deleted breakpoint ")); |
9576 | else | |
9577 | printf_unfiltered (_("Deleted breakpoints ")); | |
9578 | } | |
80f8a6eb | 9579 | breakpoints_changed (); |
d6e956e5 VP |
9580 | |
9581 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 9582 | { |
c5aa993b | 9583 | if (from_tty) |
d6e956e5 VP |
9584 | printf_unfiltered ("%d ", b->number); |
9585 | delete_breakpoint (b); | |
c906108c | 9586 | } |
80f8a6eb MS |
9587 | if (from_tty) |
9588 | putchar_unfiltered ('\n'); | |
c906108c SS |
9589 | } |
9590 | \f | |
9591 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
9592 | all breakpoints that are marked for deletion, whether hit or not. | |
9593 | This is called after any breakpoint is hit, or after errors. */ | |
9594 | ||
9595 | void | |
fba45db2 | 9596 | breakpoint_auto_delete (bpstat bs) |
c906108c | 9597 | { |
35df4500 | 9598 | struct breakpoint *b, *b_tmp; |
c906108c SS |
9599 | |
9600 | for (; bs; bs = bs->next) | |
f431efe5 PA |
9601 | if (bs->breakpoint_at |
9602 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 9603 | && bs->stop) |
f431efe5 | 9604 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 9605 | |
35df4500 | 9606 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 9607 | { |
b5de0fa7 | 9608 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
9609 | delete_breakpoint (b); |
9610 | } | |
c906108c SS |
9611 | } |
9612 | ||
4a64f543 MS |
9613 | /* A comparison function for bp_location AP and BP being interfaced to |
9614 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
9615 | does breakpoint_address_is_meaningful say for its OWNER), | |
9616 | secondarily by ordering first bp_permanent OWNERed elements and | |
9617 | terciarily just ensuring the array is sorted stable way despite | |
9618 | qsort being an instable algorithm. */ | |
876fa593 JK |
9619 | |
9620 | static int | |
494cfb0f | 9621 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 9622 | { |
494cfb0f JK |
9623 | struct bp_location *a = *(void **) ap; |
9624 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 9625 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
9626 | int a_perm = a->owner->enable_state == bp_permanent; |
9627 | int b_perm = b->owner->enable_state == bp_permanent; | |
9628 | ||
9629 | if (a->address != b->address) | |
9630 | return (a->address > b->address) - (a->address < b->address); | |
9631 | ||
9632 | /* Sort permanent breakpoints first. */ | |
9633 | if (a_perm != b_perm) | |
9634 | return (a_perm < b_perm) - (a_perm > b_perm); | |
9635 | ||
4a64f543 MS |
9636 | /* Make the user-visible order stable across GDB runs. Locations of |
9637 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
9638 | |
9639 | if (a->owner->number != b->owner->number) | |
9640 | return (a->owner->number > b->owner->number) | |
9641 | - (a->owner->number < b->owner->number); | |
9642 | ||
9643 | return (a > b) - (a < b); | |
9644 | } | |
9645 | ||
876fa593 | 9646 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
9647 | bp_location_shadow_len_after_address_max according to the current |
9648 | content of the bp_location array. */ | |
f7545552 TT |
9649 | |
9650 | static void | |
876fa593 | 9651 | bp_location_target_extensions_update (void) |
f7545552 | 9652 | { |
876fa593 JK |
9653 | struct bp_location *bl, **blp_tmp; |
9654 | ||
9655 | bp_location_placed_address_before_address_max = 0; | |
9656 | bp_location_shadow_len_after_address_max = 0; | |
9657 | ||
9658 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
9659 | { | |
9660 | CORE_ADDR start, end, addr; | |
9661 | ||
9662 | if (!bp_location_has_shadow (bl)) | |
9663 | continue; | |
9664 | ||
9665 | start = bl->target_info.placed_address; | |
9666 | end = start + bl->target_info.shadow_len; | |
9667 | ||
9668 | gdb_assert (bl->address >= start); | |
9669 | addr = bl->address - start; | |
9670 | if (addr > bp_location_placed_address_before_address_max) | |
9671 | bp_location_placed_address_before_address_max = addr; | |
9672 | ||
9673 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
9674 | ||
9675 | gdb_assert (bl->address < end); | |
9676 | addr = end - bl->address; | |
9677 | if (addr > bp_location_shadow_len_after_address_max) | |
9678 | bp_location_shadow_len_after_address_max = addr; | |
9679 | } | |
f7545552 TT |
9680 | } |
9681 | ||
4cd9bd08 | 9682 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
9683 | into the inferior, only remove already-inserted locations that no |
9684 | longer should be inserted. Functions that delete a breakpoint or | |
9685 | breakpoints should pass false, so that deleting a breakpoint | |
9686 | doesn't have the side effect of inserting the locations of other | |
9687 | breakpoints that are marked not-inserted, but should_be_inserted | |
9688 | returns true on them. | |
9689 | ||
9690 | This behaviour is useful is situations close to tear-down -- e.g., | |
9691 | after an exec, while the target still has execution, but breakpoint | |
9692 | shadows of the previous executable image should *NOT* be restored | |
9693 | to the new image; or before detaching, where the target still has | |
9694 | execution and wants to delete breakpoints from GDB's lists, and all | |
9695 | breakpoints had already been removed from the inferior. */ | |
9696 | ||
0d381245 | 9697 | static void |
b60e7edf | 9698 | update_global_location_list (int should_insert) |
0d381245 | 9699 | { |
74960c60 | 9700 | struct breakpoint *b; |
876fa593 | 9701 | struct bp_location **locp, *loc; |
f7545552 TT |
9702 | struct cleanup *cleanups; |
9703 | ||
2d134ed3 PA |
9704 | /* Used in the duplicates detection below. When iterating over all |
9705 | bp_locations, points to the first bp_location of a given address. | |
9706 | Breakpoints and watchpoints of different types are never | |
9707 | duplicates of each other. Keep one pointer for each type of | |
9708 | breakpoint/watchpoint, so we only need to loop over all locations | |
9709 | once. */ | |
9710 | struct bp_location *bp_loc_first; /* breakpoint */ | |
9711 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
9712 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
9713 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 9714 | |
4a64f543 MS |
9715 | /* Saved former bp_location array which we compare against the newly |
9716 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
9717 | struct bp_location **old_location, **old_locp; |
9718 | unsigned old_location_count; | |
9719 | ||
9720 | old_location = bp_location; | |
9721 | old_location_count = bp_location_count; | |
9722 | bp_location = NULL; | |
9723 | bp_location_count = 0; | |
9724 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 9725 | |
74960c60 | 9726 | ALL_BREAKPOINTS (b) |
876fa593 JK |
9727 | for (loc = b->loc; loc; loc = loc->next) |
9728 | bp_location_count++; | |
9729 | ||
9730 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
9731 | locp = bp_location; | |
9732 | ALL_BREAKPOINTS (b) | |
9733 | for (loc = b->loc; loc; loc = loc->next) | |
9734 | *locp++ = loc; | |
9735 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 9736 | bp_location_compare); |
876fa593 JK |
9737 | |
9738 | bp_location_target_extensions_update (); | |
74960c60 | 9739 | |
4a64f543 MS |
9740 | /* Identify bp_location instances that are no longer present in the |
9741 | new list, and therefore should be freed. Note that it's not | |
9742 | necessary that those locations should be removed from inferior -- | |
9743 | if there's another location at the same address (previously | |
9744 | marked as duplicate), we don't need to remove/insert the | |
9745 | location. | |
876fa593 | 9746 | |
4a64f543 MS |
9747 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
9748 | and former bp_location array state respectively. */ | |
876fa593 JK |
9749 | |
9750 | locp = bp_location; | |
9751 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
9752 | old_locp++) | |
74960c60 | 9753 | { |
876fa593 | 9754 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 9755 | struct bp_location **loc2p; |
876fa593 | 9756 | |
4a64f543 MS |
9757 | /* Tells if 'old_loc' is found amoung the new locations. If |
9758 | not, we have to free it. */ | |
c7d46a38 | 9759 | int found_object = 0; |
20874c92 VP |
9760 | /* Tells if the location should remain inserted in the target. */ |
9761 | int keep_in_target = 0; | |
9762 | int removed = 0; | |
876fa593 | 9763 | |
4a64f543 MS |
9764 | /* Skip LOCP entries which will definitely never be needed. |
9765 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 9766 | while (locp < bp_location + bp_location_count |
c7d46a38 | 9767 | && (*locp)->address < old_loc->address) |
876fa593 | 9768 | locp++; |
c7d46a38 PA |
9769 | |
9770 | for (loc2p = locp; | |
9771 | (loc2p < bp_location + bp_location_count | |
9772 | && (*loc2p)->address == old_loc->address); | |
9773 | loc2p++) | |
9774 | { | |
9775 | if (*loc2p == old_loc) | |
9776 | { | |
9777 | found_object = 1; | |
9778 | break; | |
9779 | } | |
9780 | } | |
74960c60 | 9781 | |
4a64f543 MS |
9782 | /* If this location is no longer present, and inserted, look if |
9783 | there's maybe a new location at the same address. If so, | |
9784 | mark that one inserted, and don't remove this one. This is | |
9785 | needed so that we don't have a time window where a breakpoint | |
9786 | at certain location is not inserted. */ | |
74960c60 | 9787 | |
876fa593 | 9788 | if (old_loc->inserted) |
0d381245 | 9789 | { |
4a64f543 MS |
9790 | /* If the location is inserted now, we might have to remove |
9791 | it. */ | |
74960c60 | 9792 | |
876fa593 | 9793 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 9794 | { |
4a64f543 MS |
9795 | /* The location is still present in the location list, |
9796 | and still should be inserted. Don't do anything. */ | |
20874c92 | 9797 | keep_in_target = 1; |
74960c60 VP |
9798 | } |
9799 | else | |
9800 | { | |
4a64f543 MS |
9801 | /* The location is either no longer present, or got |
9802 | disabled. See if there's another location at the | |
9803 | same address, in which case we don't need to remove | |
9804 | this one from the target. */ | |
876fa593 | 9805 | |
2bdf28a0 | 9806 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
9807 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
9808 | { | |
876fa593 | 9809 | for (loc2p = locp; |
c7d46a38 PA |
9810 | (loc2p < bp_location + bp_location_count |
9811 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
9812 | loc2p++) |
9813 | { | |
9814 | struct bp_location *loc2 = *loc2p; | |
9815 | ||
2d134ed3 | 9816 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
9817 | { |
9818 | /* For the sake of should_be_inserted. | |
4a64f543 MS |
9819 | Duplicates check below will fix up this |
9820 | later. */ | |
c7d46a38 | 9821 | loc2->duplicate = 0; |
85d721b8 PA |
9822 | |
9823 | /* Read watchpoint locations are switched to | |
9824 | access watchpoints, if the former are not | |
9825 | supported, but the latter are. */ | |
9826 | if (is_hardware_watchpoint (old_loc->owner)) | |
9827 | { | |
9828 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
9829 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
9830 | } | |
9831 | ||
c7d46a38 PA |
9832 | if (loc2 != old_loc && should_be_inserted (loc2)) |
9833 | { | |
9834 | loc2->inserted = 1; | |
9835 | loc2->target_info = old_loc->target_info; | |
9836 | keep_in_target = 1; | |
9837 | break; | |
9838 | } | |
876fa593 JK |
9839 | } |
9840 | } | |
9841 | } | |
74960c60 VP |
9842 | } |
9843 | ||
20874c92 VP |
9844 | if (!keep_in_target) |
9845 | { | |
876fa593 | 9846 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 9847 | { |
4a64f543 MS |
9848 | /* This is just about all we can do. We could keep |
9849 | this location on the global list, and try to | |
9850 | remove it next time, but there's no particular | |
9851 | reason why we will succeed next time. | |
20874c92 | 9852 | |
4a64f543 MS |
9853 | Note that at this point, old_loc->owner is still |
9854 | valid, as delete_breakpoint frees the breakpoint | |
9855 | only after calling us. */ | |
3e43a32a MS |
9856 | printf_filtered (_("warning: Error removing " |
9857 | "breakpoint %d\n"), | |
876fa593 | 9858 | old_loc->owner->number); |
20874c92 VP |
9859 | } |
9860 | removed = 1; | |
9861 | } | |
0d381245 | 9862 | } |
74960c60 VP |
9863 | |
9864 | if (!found_object) | |
1c5cfe86 | 9865 | { |
db82e815 PA |
9866 | if (removed && non_stop |
9867 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9868 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9869 | { |
db82e815 PA |
9870 | /* This location was removed from the target. In |
9871 | non-stop mode, a race condition is possible where | |
9872 | we've removed a breakpoint, but stop events for that | |
9873 | breakpoint are already queued and will arrive later. | |
9874 | We apply an heuristic to be able to distinguish such | |
9875 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9876 | breakpoint location for a bit, and will retire it | |
9877 | after we see some number of events. The theory here | |
9878 | is that reporting of events should, "on the average", | |
9879 | be fair, so after a while we'll see events from all | |
9880 | threads that have anything of interest, and no longer | |
9881 | need to keep this breakpoint location around. We | |
9882 | don't hold locations forever so to reduce chances of | |
9883 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9884 | SIGTRAP. | |
9885 | ||
9886 | The heuristic failing can be disastrous on | |
9887 | decr_pc_after_break targets. | |
9888 | ||
9889 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9890 | if we fail to recognize a late breakpoint SIGTRAP, | |
9891 | because events_till_retirement has reached 0 too | |
9892 | soon, we'll fail to do the PC adjustment, and report | |
9893 | a random SIGTRAP to the user. When the user resumes | |
9894 | the inferior, it will most likely immediately crash | |
2dec564e | 9895 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
9896 | corrupted, because of being resumed e.g., in the |
9897 | middle of a multi-byte instruction, or skipped a | |
9898 | one-byte instruction. This was actually seen happen | |
9899 | on native x86-linux, and should be less rare on | |
9900 | targets that do not support new thread events, like | |
9901 | remote, due to the heuristic depending on | |
9902 | thread_count. | |
9903 | ||
9904 | Mistaking a random SIGTRAP for a breakpoint trap | |
9905 | causes similar symptoms (PC adjustment applied when | |
9906 | it shouldn't), but then again, playing with SIGTRAPs | |
9907 | behind the debugger's back is asking for trouble. | |
9908 | ||
9909 | Since hardware watchpoint traps are always | |
9910 | distinguishable from other traps, so we don't need to | |
9911 | apply keep hardware watchpoint moribund locations | |
9912 | around. We simply always ignore hardware watchpoint | |
9913 | traps we can no longer explain. */ | |
9914 | ||
876fa593 JK |
9915 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9916 | old_loc->owner = NULL; | |
20874c92 | 9917 | |
876fa593 | 9918 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9919 | } |
9920 | else | |
f431efe5 PA |
9921 | { |
9922 | old_loc->owner = NULL; | |
9923 | decref_bp_location (&old_loc); | |
9924 | } | |
20874c92 | 9925 | } |
74960c60 | 9926 | } |
1c5cfe86 | 9927 | |
2d134ed3 PA |
9928 | /* Rescan breakpoints at the same address and section, marking the |
9929 | first one as "first" and any others as "duplicates". This is so | |
9930 | that the bpt instruction is only inserted once. If we have a | |
9931 | permanent breakpoint at the same place as BPT, make that one the | |
9932 | official one, and the rest as duplicates. Permanent breakpoints | |
9933 | are sorted first for the same address. | |
9934 | ||
9935 | Do the same for hardware watchpoints, but also considering the | |
9936 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9937 | |
2d134ed3 PA |
9938 | bp_loc_first = NULL; |
9939 | wp_loc_first = NULL; | |
9940 | awp_loc_first = NULL; | |
9941 | rwp_loc_first = NULL; | |
876fa593 | 9942 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9943 | { |
4a64f543 MS |
9944 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
9945 | non-NULL. */ | |
876fa593 | 9946 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9947 | struct bp_location **loc_first_p; |
876fa593 JK |
9948 | |
9949 | if (b->enable_state == bp_disabled | |
9950 | || b->enable_state == bp_call_disabled | |
9951 | || b->enable_state == bp_startup_disabled | |
9952 | || !loc->enabled | |
9953 | || loc->shlib_disabled | |
15c3d785 | 9954 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 9955 | || is_tracepoint (b)) |
876fa593 JK |
9956 | continue; |
9957 | ||
9958 | /* Permanent breakpoint should always be inserted. */ | |
9959 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9960 | internal_error (__FILE__, __LINE__, | |
9961 | _("allegedly permanent breakpoint is not " | |
9962 | "actually inserted")); | |
9963 | ||
2d134ed3 PA |
9964 | if (b->type == bp_hardware_watchpoint) |
9965 | loc_first_p = &wp_loc_first; | |
9966 | else if (b->type == bp_read_watchpoint) | |
9967 | loc_first_p = &rwp_loc_first; | |
9968 | else if (b->type == bp_access_watchpoint) | |
9969 | loc_first_p = &awp_loc_first; | |
9970 | else | |
9971 | loc_first_p = &bp_loc_first; | |
9972 | ||
9973 | if (*loc_first_p == NULL | |
9974 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9975 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9976 | { |
2d134ed3 | 9977 | *loc_first_p = loc; |
876fa593 JK |
9978 | loc->duplicate = 0; |
9979 | continue; | |
9980 | } | |
9981 | ||
9982 | loc->duplicate = 1; | |
9983 | ||
2d134ed3 PA |
9984 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9985 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9986 | internal_error (__FILE__, __LINE__, |
9987 | _("another breakpoint was inserted on top of " | |
9988 | "a permanent breakpoint")); | |
0d381245 | 9989 | } |
74960c60 | 9990 | |
50c71eaf | 9991 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9992 | && (have_live_inferiors () |
2567c7d9 | 9993 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9994 | insert_breakpoint_locations (); |
f7545552 TT |
9995 | |
9996 | do_cleanups (cleanups); | |
74960c60 VP |
9997 | } |
9998 | ||
20874c92 VP |
9999 | void |
10000 | breakpoint_retire_moribund (void) | |
10001 | { | |
10002 | struct bp_location *loc; | |
10003 | int ix; | |
10004 | ||
10005 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10006 | if (--(loc->events_till_retirement) == 0) | |
10007 | { | |
f431efe5 | 10008 | decref_bp_location (&loc); |
20874c92 VP |
10009 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
10010 | --ix; | |
10011 | } | |
10012 | } | |
10013 | ||
74960c60 | 10014 | static void |
b60e7edf | 10015 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
10016 | { |
10017 | struct gdb_exception e; | |
cc59ec59 | 10018 | |
74960c60 | 10019 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 10020 | update_global_location_list (inserting); |
0d381245 VP |
10021 | } |
10022 | ||
f431efe5 PA |
10023 | /* Clear BKP from a BPS. */ |
10024 | ||
a474d7c2 | 10025 | static void |
f431efe5 | 10026 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
10027 | { |
10028 | bpstat bs; | |
cc59ec59 | 10029 | |
a474d7c2 | 10030 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 10031 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
10032 | { |
10033 | bs->breakpoint_at = NULL; | |
10034 | bs->old_val = NULL; | |
10035 | /* bs->commands will be freed later. */ | |
10036 | } | |
10037 | } | |
10038 | ||
10039 | /* Callback for iterate_over_threads. */ | |
10040 | static int | |
f431efe5 | 10041 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 10042 | { |
f431efe5 | 10043 | struct breakpoint *bpt = data; |
cc59ec59 | 10044 | |
16c381f0 | 10045 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
a474d7c2 PA |
10046 | return 0; |
10047 | } | |
10048 | ||
53a5351d | 10049 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 10050 | structures. */ |
c906108c SS |
10051 | |
10052 | void | |
fba45db2 | 10053 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 10054 | { |
52f0bd74 | 10055 | struct breakpoint *b; |
c906108c | 10056 | |
8a3fe4f8 | 10057 | gdb_assert (bpt != NULL); |
c906108c | 10058 | |
4a64f543 MS |
10059 | /* Has this bp already been deleted? This can happen because |
10060 | multiple lists can hold pointers to bp's. bpstat lists are | |
10061 | especial culprits. | |
10062 | ||
10063 | One example of this happening is a watchpoint's scope bp. When | |
10064 | the scope bp triggers, we notice that the watchpoint is out of | |
10065 | scope, and delete it. We also delete its scope bp. But the | |
10066 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
10067 | That bpstat is then checked for auto-deleting bp's, which are | |
10068 | deleted. | |
10069 | ||
10070 | A real solution to this problem might involve reference counts in | |
10071 | bp's, and/or giving them pointers back to their referencing | |
10072 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
10073 | storage when no more references were extent. A cheaper bandaid | |
10074 | was chosen. */ | |
c906108c SS |
10075 | if (bpt->type == bp_none) |
10076 | return; | |
10077 | ||
4a64f543 MS |
10078 | /* At least avoid this stale reference until the reference counting |
10079 | of breakpoints gets resolved. */ | |
e5a0a904 JK |
10080 | if (bpt->related_breakpoint != NULL) |
10081 | { | |
10082 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
10083 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
10084 | bpt->related_breakpoint->related_breakpoint = NULL; | |
10085 | bpt->related_breakpoint = NULL; | |
10086 | } | |
10087 | ||
383f836e | 10088 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 10089 | |
c906108c SS |
10090 | if (breakpoint_chain == bpt) |
10091 | breakpoint_chain = bpt->next; | |
10092 | ||
c906108c SS |
10093 | ALL_BREAKPOINTS (b) |
10094 | if (b->next == bpt) | |
c5aa993b JM |
10095 | { |
10096 | b->next = bpt->next; | |
10097 | break; | |
10098 | } | |
c906108c | 10099 | |
9add0f1b | 10100 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
10101 | xfree (bpt->cond_string); |
10102 | xfree (bpt->cond_exp); | |
10103 | xfree (bpt->addr_string); | |
10104 | xfree (bpt->exp); | |
10105 | xfree (bpt->exp_string); | |
d63d0675 | 10106 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
10107 | value_free (bpt->val); |
10108 | xfree (bpt->source_file); | |
10109 | xfree (bpt->exec_pathname); | |
a96d9b2e | 10110 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 10111 | |
f431efe5 PA |
10112 | |
10113 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
10114 | been freed. */ | |
10115 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
10116 | in all threeds for now. Note that we cannot just remove bpstats | |
10117 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
10118 | commands are associated with the bpstat; if we remove it here, | |
10119 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
10120 | event-top.c won't do anything, and temporary breakpoints with | |
10121 | commands won't work. */ | |
10122 | ||
10123 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
10124 | ||
4a64f543 MS |
10125 | /* Now that breakpoint is removed from breakpoint list, update the |
10126 | global location list. This will remove locations that used to | |
10127 | belong to this breakpoint. Do this before freeing the breakpoint | |
10128 | itself, since remove_breakpoint looks at location's owner. It | |
10129 | might be better design to have location completely | |
10130 | self-contained, but it's not the case now. */ | |
b60e7edf | 10131 | update_global_location_list (0); |
74960c60 VP |
10132 | |
10133 | ||
4a64f543 MS |
10134 | /* On the chance that someone will soon try again to delete this |
10135 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c SS |
10136 | bpt->type = bp_none; |
10137 | ||
b8c9b27d | 10138 | xfree (bpt); |
c906108c SS |
10139 | } |
10140 | ||
4d6140d9 AC |
10141 | static void |
10142 | do_delete_breakpoint_cleanup (void *b) | |
10143 | { | |
10144 | delete_breakpoint (b); | |
10145 | } | |
10146 | ||
10147 | struct cleanup * | |
10148 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
10149 | { | |
10150 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
10151 | } | |
10152 | ||
95a42b64 TT |
10153 | /* A callback for map_breakpoint_numbers that calls |
10154 | delete_breakpoint. */ | |
10155 | ||
10156 | static void | |
10157 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
10158 | { | |
10159 | delete_breakpoint (b); | |
10160 | } | |
10161 | ||
c906108c | 10162 | void |
fba45db2 | 10163 | delete_command (char *arg, int from_tty) |
c906108c | 10164 | { |
35df4500 | 10165 | struct breakpoint *b, *b_tmp; |
c906108c | 10166 | |
ea9365bb TT |
10167 | dont_repeat (); |
10168 | ||
c906108c SS |
10169 | if (arg == 0) |
10170 | { | |
10171 | int breaks_to_delete = 0; | |
10172 | ||
10173 | /* Delete all breakpoints if no argument. | |
4a64f543 MS |
10174 | Do not delete internal or call-dummy breakpoints, these have |
10175 | to be deleted with an explicit breakpoint number argument. */ | |
c5aa993b JM |
10176 | ALL_BREAKPOINTS (b) |
10177 | { | |
059fb39f | 10178 | if (b->type != bp_call_dummy |
aa7d318d | 10179 | && b->type != bp_std_terminate |
059fb39f | 10180 | && b->type != bp_shlib_event |
4efc6507 | 10181 | && b->type != bp_jit_event |
059fb39f PM |
10182 | && b->type != bp_thread_event |
10183 | && b->type != bp_overlay_event | |
0fd8e87f | 10184 | && b->type != bp_longjmp_master |
aa7d318d | 10185 | && b->type != bp_std_terminate_master |
186c406b | 10186 | && b->type != bp_exception_master |
059fb39f | 10187 | && b->number >= 0) |
973d738b DJ |
10188 | { |
10189 | breaks_to_delete = 1; | |
10190 | break; | |
10191 | } | |
c5aa993b | 10192 | } |
c906108c SS |
10193 | |
10194 | /* Ask user only if there are some breakpoints to delete. */ | |
10195 | if (!from_tty | |
e2e0b3e5 | 10196 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 10197 | { |
35df4500 | 10198 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10199 | { |
059fb39f | 10200 | if (b->type != bp_call_dummy |
aa7d318d | 10201 | && b->type != bp_std_terminate |
059fb39f PM |
10202 | && b->type != bp_shlib_event |
10203 | && b->type != bp_thread_event | |
4efc6507 | 10204 | && b->type != bp_jit_event |
059fb39f | 10205 | && b->type != bp_overlay_event |
0fd8e87f | 10206 | && b->type != bp_longjmp_master |
aa7d318d | 10207 | && b->type != bp_std_terminate_master |
186c406b | 10208 | && b->type != bp_exception_master |
059fb39f | 10209 | && b->number >= 0) |
c5aa993b JM |
10210 | delete_breakpoint (b); |
10211 | } | |
c906108c SS |
10212 | } |
10213 | } | |
10214 | else | |
95a42b64 | 10215 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
10216 | } |
10217 | ||
0d381245 VP |
10218 | static int |
10219 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 10220 | { |
0d381245 VP |
10221 | for (; loc; loc = loc->next) |
10222 | if (!loc->shlib_disabled) | |
10223 | return 0; | |
10224 | return 1; | |
fe3f5fa8 VP |
10225 | } |
10226 | ||
776592bf DE |
10227 | /* Subroutine of update_breakpoint_locations to simplify it. |
10228 | Return non-zero if multiple fns in list LOC have the same name. | |
10229 | Null names are ignored. */ | |
10230 | ||
10231 | static int | |
10232 | ambiguous_names_p (struct bp_location *loc) | |
10233 | { | |
10234 | struct bp_location *l; | |
10235 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
10236 | (int (*) (const void *, |
10237 | const void *)) streq, | |
776592bf DE |
10238 | NULL, xcalloc, xfree); |
10239 | ||
10240 | for (l = loc; l != NULL; l = l->next) | |
10241 | { | |
10242 | const char **slot; | |
10243 | const char *name = l->function_name; | |
10244 | ||
10245 | /* Allow for some names to be NULL, ignore them. */ | |
10246 | if (name == NULL) | |
10247 | continue; | |
10248 | ||
10249 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
10250 | INSERT); | |
4a64f543 MS |
10251 | /* NOTE: We can assume slot != NULL here because xcalloc never |
10252 | returns NULL. */ | |
776592bf DE |
10253 | if (*slot != NULL) |
10254 | { | |
10255 | htab_delete (htab); | |
10256 | return 1; | |
10257 | } | |
10258 | *slot = name; | |
10259 | } | |
10260 | ||
10261 | htab_delete (htab); | |
10262 | return 0; | |
10263 | } | |
10264 | ||
0fb4aa4b PA |
10265 | /* When symbols change, it probably means the sources changed as well, |
10266 | and it might mean the static tracepoint markers are no longer at | |
10267 | the same address or line numbers they used to be at last we | |
10268 | checked. Losing your static tracepoints whenever you rebuild is | |
10269 | undesirable. This function tries to resync/rematch gdb static | |
10270 | tracepoints with the markers on the target, for static tracepoints | |
10271 | that have not been set by marker id. Static tracepoint that have | |
10272 | been set by marker id are reset by marker id in breakpoint_re_set. | |
10273 | The heuristic is: | |
10274 | ||
10275 | 1) For a tracepoint set at a specific address, look for a marker at | |
10276 | the old PC. If one is found there, assume to be the same marker. | |
10277 | If the name / string id of the marker found is different from the | |
10278 | previous known name, assume that means the user renamed the marker | |
10279 | in the sources, and output a warning. | |
10280 | ||
10281 | 2) For a tracepoint set at a given line number, look for a marker | |
10282 | at the new address of the old line number. If one is found there, | |
10283 | assume to be the same marker. If the name / string id of the | |
10284 | marker found is different from the previous known name, assume that | |
10285 | means the user renamed the marker in the sources, and output a | |
10286 | warning. | |
10287 | ||
10288 | 3) If a marker is no longer found at the same address or line, it | |
10289 | may mean the marker no longer exists. But it may also just mean | |
10290 | the code changed a bit. Maybe the user added a few lines of code | |
10291 | that made the marker move up or down (in line number terms). Ask | |
10292 | the target for info about the marker with the string id as we knew | |
10293 | it. If found, update line number and address in the matching | |
10294 | static tracepoint. This will get confused if there's more than one | |
10295 | marker with the same ID (possible in UST, although unadvised | |
10296 | precisely because it confuses tools). */ | |
10297 | ||
10298 | static struct symtab_and_line | |
10299 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
10300 | { | |
10301 | struct static_tracepoint_marker marker; | |
10302 | CORE_ADDR pc; | |
10303 | int i; | |
10304 | ||
10305 | pc = sal.pc; | |
10306 | if (sal.line) | |
10307 | find_line_pc (sal.symtab, sal.line, &pc); | |
10308 | ||
10309 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
10310 | { | |
10311 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
10312 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
10313 | b->number, | |
10314 | b->static_trace_marker_id, marker.str_id); | |
10315 | ||
10316 | xfree (b->static_trace_marker_id); | |
10317 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
10318 | release_static_tracepoint_marker (&marker); | |
10319 | ||
10320 | return sal; | |
10321 | } | |
10322 | ||
10323 | /* Old marker wasn't found on target at lineno. Try looking it up | |
10324 | by string ID. */ | |
10325 | if (!sal.explicit_pc | |
10326 | && sal.line != 0 | |
10327 | && sal.symtab != NULL | |
10328 | && b->static_trace_marker_id != NULL) | |
10329 | { | |
10330 | VEC(static_tracepoint_marker_p) *markers; | |
10331 | ||
10332 | markers | |
10333 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
10334 | ||
10335 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
10336 | { | |
10337 | struct symtab_and_line sal; | |
10338 | struct symbol *sym; | |
10339 | struct static_tracepoint_marker *marker; | |
10340 | ||
10341 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
10342 | ||
10343 | xfree (b->static_trace_marker_id); | |
10344 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
10345 | ||
10346 | warning (_("marker for static tracepoint %d (%s) not " | |
10347 | "found at previous line number"), | |
10348 | b->number, b->static_trace_marker_id); | |
10349 | ||
10350 | init_sal (&sal); | |
10351 | ||
10352 | sal.pc = marker->address; | |
10353 | ||
10354 | sal = find_pc_line (marker->address, 0); | |
10355 | sym = find_pc_sect_function (marker->address, NULL); | |
10356 | ui_out_text (uiout, "Now in "); | |
10357 | if (sym) | |
10358 | { | |
10359 | ui_out_field_string (uiout, "func", | |
10360 | SYMBOL_PRINT_NAME (sym)); | |
10361 | ui_out_text (uiout, " at "); | |
10362 | } | |
10363 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
10364 | ui_out_text (uiout, ":"); | |
10365 | ||
10366 | if (ui_out_is_mi_like_p (uiout)) | |
10367 | { | |
10368 | char *fullname = symtab_to_fullname (sal.symtab); | |
10369 | ||
10370 | if (fullname) | |
10371 | ui_out_field_string (uiout, "fullname", fullname); | |
10372 | } | |
10373 | ||
10374 | ui_out_field_int (uiout, "line", sal.line); | |
10375 | ui_out_text (uiout, "\n"); | |
10376 | ||
10377 | b->line_number = sal.line; | |
10378 | ||
10379 | xfree (b->source_file); | |
10380 | if (sym) | |
10381 | b->source_file = xstrdup (sal.symtab->filename); | |
10382 | else | |
10383 | b->source_file = NULL; | |
10384 | ||
10385 | xfree (b->addr_string); | |
10386 | b->addr_string = xstrprintf ("%s:%d", | |
10387 | sal.symtab->filename, b->line_number); | |
10388 | ||
10389 | /* Might be nice to check if function changed, and warn if | |
10390 | so. */ | |
10391 | ||
10392 | release_static_tracepoint_marker (marker); | |
10393 | } | |
10394 | } | |
10395 | return sal; | |
10396 | } | |
10397 | ||
fe3f5fa8 | 10398 | static void |
0d381245 VP |
10399 | update_breakpoint_locations (struct breakpoint *b, |
10400 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
10401 | { |
10402 | int i; | |
10403 | char *s; | |
0d381245 VP |
10404 | struct bp_location *existing_locations = b->loc; |
10405 | ||
4a64f543 MS |
10406 | /* If there's no new locations, and all existing locations are |
10407 | pending, don't do anything. This optimizes the common case where | |
10408 | all locations are in the same shared library, that was unloaded. | |
10409 | We'd like to retain the location, so that when the library is | |
10410 | loaded again, we don't loose the enabled/disabled status of the | |
10411 | individual locations. */ | |
0d381245 | 10412 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
10413 | return; |
10414 | ||
fe3f5fa8 VP |
10415 | b->loc = NULL; |
10416 | ||
0d381245 | 10417 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 10418 | { |
0d381245 | 10419 | struct bp_location *new_loc = |
39d61571 | 10420 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 10421 | |
0d381245 VP |
10422 | /* Reparse conditions, they might contain references to the |
10423 | old symtab. */ | |
10424 | if (b->cond_string != NULL) | |
10425 | { | |
10426 | struct gdb_exception e; | |
fe3f5fa8 | 10427 | |
0d381245 VP |
10428 | s = b->cond_string; |
10429 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10430 | { | |
10431 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
10432 | 0); | |
10433 | } | |
10434 | if (e.reason < 0) | |
10435 | { | |
3e43a32a MS |
10436 | warning (_("failed to reevaluate condition " |
10437 | "for breakpoint %d: %s"), | |
0d381245 VP |
10438 | b->number, e.message); |
10439 | new_loc->enabled = 0; | |
10440 | } | |
10441 | } | |
fe3f5fa8 | 10442 | |
0d381245 VP |
10443 | if (b->source_file != NULL) |
10444 | xfree (b->source_file); | |
10445 | if (sals.sals[i].symtab == NULL) | |
10446 | b->source_file = NULL; | |
10447 | else | |
1b36a34b | 10448 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 10449 | |
0d381245 VP |
10450 | if (b->line_number == 0) |
10451 | b->line_number = sals.sals[i].line; | |
10452 | } | |
fe3f5fa8 | 10453 | |
514f746b AR |
10454 | /* Update locations of permanent breakpoints. */ |
10455 | if (b->enable_state == bp_permanent) | |
10456 | make_breakpoint_permanent (b); | |
10457 | ||
4a64f543 MS |
10458 | /* If possible, carry over 'disable' status from existing |
10459 | breakpoints. */ | |
0d381245 VP |
10460 | { |
10461 | struct bp_location *e = existing_locations; | |
776592bf DE |
10462 | /* If there are multiple breakpoints with the same function name, |
10463 | e.g. for inline functions, comparing function names won't work. | |
10464 | Instead compare pc addresses; this is just a heuristic as things | |
10465 | may have moved, but in practice it gives the correct answer | |
10466 | often enough until a better solution is found. */ | |
10467 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
10468 | ||
0d381245 VP |
10469 | for (; e; e = e->next) |
10470 | { | |
10471 | if (!e->enabled && e->function_name) | |
10472 | { | |
10473 | struct bp_location *l = b->loc; | |
776592bf DE |
10474 | if (have_ambiguous_names) |
10475 | { | |
10476 | for (; l; l = l->next) | |
6c95b8df PA |
10477 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
10478 | l->pspace->aspace, l->address)) | |
776592bf DE |
10479 | { |
10480 | l->enabled = 0; | |
10481 | break; | |
10482 | } | |
10483 | } | |
10484 | else | |
10485 | { | |
10486 | for (; l; l = l->next) | |
10487 | if (l->function_name | |
10488 | && strcmp (e->function_name, l->function_name) == 0) | |
10489 | { | |
10490 | l->enabled = 0; | |
10491 | break; | |
10492 | } | |
10493 | } | |
0d381245 VP |
10494 | } |
10495 | } | |
10496 | } | |
fe3f5fa8 | 10497 | |
b60e7edf | 10498 | update_global_location_list (1); |
fe3f5fa8 VP |
10499 | } |
10500 | ||
c906108c SS |
10501 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
10502 | The value we return ends up being the return value from catch_errors. | |
10503 | Unused in this case. */ | |
10504 | ||
10505 | static int | |
4efb68b1 | 10506 | breakpoint_re_set_one (void *bint) |
c906108c | 10507 | { |
4a64f543 | 10508 | /* Get past catch_errs. */ |
53a5351d | 10509 | struct breakpoint *b = (struct breakpoint *) bint; |
fe3f5fa8 VP |
10510 | int not_found = 0; |
10511 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
10512 | struct symtabs_and_lines sals = {0}; |
10513 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 10514 | char *s; |
fe3f5fa8 | 10515 | struct gdb_exception e; |
6c95b8df | 10516 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
0fb4aa4b | 10517 | int marker_spec = 0; |
c906108c SS |
10518 | |
10519 | switch (b->type) | |
10520 | { | |
10521 | case bp_none: | |
8a3fe4f8 | 10522 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 10523 | b->number); |
c906108c SS |
10524 | return 0; |
10525 | case bp_breakpoint: | |
10526 | case bp_hardware_breakpoint: | |
1042e4c0 | 10527 | case bp_tracepoint: |
7a697b8d | 10528 | case bp_fast_tracepoint: |
0fb4aa4b | 10529 | case bp_static_tracepoint: |
8bea4e01 UW |
10530 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10531 | if (b->enable_state == bp_startup_disabled) | |
10532 | return 0; | |
10533 | ||
c906108c SS |
10534 | if (b->addr_string == NULL) |
10535 | { | |
4a64f543 | 10536 | /* Anything without a string can't be re-set. */ |
c906108c SS |
10537 | delete_breakpoint (b); |
10538 | return 0; | |
10539 | } | |
c906108c | 10540 | |
c906108c SS |
10541 | input_radix = b->input_radix; |
10542 | s = b->addr_string; | |
6c95b8df PA |
10543 | |
10544 | save_current_space_and_thread (); | |
10545 | switch_to_program_space_and_thread (b->pspace); | |
10546 | ||
0fb4aa4b PA |
10547 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); |
10548 | ||
385d04dc | 10549 | set_language (b->language); |
fe3f5fa8 | 10550 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 10551 | { |
0fb4aa4b PA |
10552 | if (marker_spec) |
10553 | { | |
10554 | sals = decode_static_tracepoint_spec (&s); | |
10555 | if (sals.nelts > b->static_trace_marker_id_idx) | |
10556 | { | |
10557 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
10558 | sals.nelts = 1; | |
10559 | } | |
10560 | else | |
10561 | error (_("marker %s not found"), b->static_trace_marker_id); | |
10562 | } | |
10563 | else | |
3e43a32a MS |
10564 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, |
10565 | (char ***) NULL, not_found_ptr); | |
fe3f5fa8 VP |
10566 | } |
10567 | if (e.reason < 0) | |
10568 | { | |
10569 | int not_found_and_ok = 0; | |
4a64f543 MS |
10570 | /* For pending breakpoints, it's expected that parsing will |
10571 | fail until the right shared library is loaded. User has | |
10572 | already told to create pending breakpoints and don't need | |
10573 | extra messages. If breakpoint is in bp_shlib_disabled | |
10574 | state, then user already saw the message about that | |
10575 | breakpoint being disabled, and don't want to see more | |
10576 | errors. */ | |
0d381245 VP |
10577 | if (not_found |
10578 | && (b->condition_not_parsed | |
10579 | || (b->loc && b->loc->shlib_disabled) | |
10580 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
10581 | not_found_and_ok = 1; |
10582 | ||
10583 | if (!not_found_and_ok) | |
c906108c | 10584 | { |
fe3f5fa8 VP |
10585 | /* We surely don't want to warn about the same breakpoint |
10586 | 10 times. One solution, implemented here, is disable | |
10587 | the breakpoint on error. Another solution would be to | |
10588 | have separate 'warning emitted' flag. Since this | |
10589 | happens only when a binary has changed, I don't know | |
10590 | which approach is better. */ | |
10591 | b->enable_state = bp_disabled; | |
10592 | throw_exception (e); | |
c906108c | 10593 | } |
fe3f5fa8 | 10594 | } |
c906108c | 10595 | |
6c95b8df | 10596 | if (!not_found) |
fe3f5fa8 | 10597 | { |
6c95b8df PA |
10598 | gdb_assert (sals.nelts == 1); |
10599 | ||
10600 | resolve_sal_pc (&sals.sals[0]); | |
10601 | if (b->condition_not_parsed && s && s[0]) | |
10602 | { | |
10603 | char *cond_string = 0; | |
10604 | int thread = -1; | |
10605 | int task = 0; | |
10606 | ||
10607 | find_condition_and_thread (s, sals.sals[0].pc, | |
10608 | &cond_string, &thread, &task); | |
10609 | if (cond_string) | |
10610 | b->cond_string = cond_string; | |
10611 | b->thread = thread; | |
10612 | b->task = task; | |
10613 | b->condition_not_parsed = 0; | |
10614 | } | |
10615 | ||
0fb4aa4b PA |
10616 | if (b->type == bp_static_tracepoint && !marker_spec) |
10617 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
10618 | ||
6c95b8df | 10619 | expanded = expand_line_sal_maybe (sals.sals[0]); |
fe3f5fa8 | 10620 | } |
6c95b8df PA |
10621 | |
10622 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 10623 | update_breakpoint_locations (b, expanded); |
c906108c SS |
10624 | break; |
10625 | ||
10626 | case bp_watchpoint: | |
10627 | case bp_hardware_watchpoint: | |
10628 | case bp_read_watchpoint: | |
10629 | case bp_access_watchpoint: | |
4a64f543 MS |
10630 | /* Watchpoint can be either on expression using entirely global |
10631 | variables, or it can be on local variables. | |
10632 | ||
10633 | Watchpoints of the first kind are never auto-deleted, and | |
10634 | even persist across program restarts. Since they can use | |
10635 | variables from shared libraries, we need to reparse | |
10636 | expression as libraries are loaded and unloaded. | |
10637 | ||
10638 | Watchpoints on local variables can also change meaning as | |
10639 | result of solib event. For example, if a watchpoint uses | |
10640 | both a local and a global variables in expression, it's a | |
10641 | local watchpoint, but unloading of a shared library will make | |
10642 | the expression invalid. This is not a very common use case, | |
10643 | but we still re-evaluate expression, to avoid surprises to | |
10644 | the user. | |
0b3de036 VP |
10645 | |
10646 | Note that for local watchpoints, we re-evaluate it only if | |
10647 | watchpoints frame id is still valid. If it's not, it means | |
4a64f543 MS |
10648 | the watchpoint is out of scope and will be deleted soon. In |
10649 | fact, I'm not sure we'll ever be called in this case. | |
0b3de036 VP |
10650 | |
10651 | If a local watchpoint's frame id is still valid, then | |
4a64f543 | 10652 | b->exp_valid_block is likewise valid, and we can safely use it. |
0b3de036 VP |
10653 | |
10654 | Don't do anything about disabled watchpoints, since they will | |
10655 | be reevaluated again when enabled. */ | |
a5606eee | 10656 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 10657 | break; |
c5aa993b JM |
10658 | /* We needn't really do anything to reset these, since the mask |
10659 | that requests them is unaffected by e.g., new libraries being | |
4a64f543 | 10660 | loaded. */ |
ce78b96d | 10661 | case bp_catchpoint: |
c906108c | 10662 | break; |
c5aa993b | 10663 | |
c906108c | 10664 | default: |
a3f17187 | 10665 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 10666 | /* fall through */ |
0fd8e87f UW |
10667 | /* Delete overlay event and longjmp master breakpoints; they will be |
10668 | reset later by breakpoint_re_set. */ | |
1900040c | 10669 | case bp_overlay_event: |
0fd8e87f | 10670 | case bp_longjmp_master: |
aa7d318d | 10671 | case bp_std_terminate_master: |
186c406b | 10672 | case bp_exception_master: |
c906108c SS |
10673 | delete_breakpoint (b); |
10674 | break; | |
10675 | ||
c5aa993b JM |
10676 | /* This breakpoint is special, it's set up when the inferior |
10677 | starts and we really don't want to touch it. */ | |
c906108c SS |
10678 | case bp_shlib_event: |
10679 | ||
c4093a6a JM |
10680 | /* Like bp_shlib_event, this breakpoint type is special. |
10681 | Once it is set up, we do not want to touch it. */ | |
10682 | case bp_thread_event: | |
10683 | ||
4a64f543 MS |
10684 | /* Keep temporary breakpoints, which can be encountered when we |
10685 | step over a dlopen call and SOLIB_ADD is resetting the | |
10686 | breakpoints. Otherwise these should have been blown away via | |
10687 | the cleanup chain or by breakpoint_init_inferior when we | |
10688 | rerun the executable. */ | |
c906108c SS |
10689 | case bp_until: |
10690 | case bp_finish: | |
10691 | case bp_watchpoint_scope: | |
10692 | case bp_call_dummy: | |
aa7d318d | 10693 | case bp_std_terminate: |
c906108c | 10694 | case bp_step_resume: |
611c83ae PA |
10695 | case bp_longjmp: |
10696 | case bp_longjmp_resume: | |
186c406b TT |
10697 | case bp_exception: |
10698 | case bp_exception_resume: | |
4efc6507 | 10699 | case bp_jit_event: |
c906108c SS |
10700 | break; |
10701 | } | |
10702 | ||
6c95b8df | 10703 | do_cleanups (cleanups); |
c906108c SS |
10704 | return 0; |
10705 | } | |
10706 | ||
69de3c6a | 10707 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 10708 | void |
69de3c6a | 10709 | breakpoint_re_set (void) |
c906108c | 10710 | { |
35df4500 | 10711 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10712 | enum language save_language; |
10713 | int save_input_radix; | |
6c95b8df | 10714 | struct cleanup *old_chain; |
c5aa993b | 10715 | |
c906108c SS |
10716 | save_language = current_language->la_language; |
10717 | save_input_radix = input_radix; | |
6c95b8df PA |
10718 | old_chain = save_current_program_space (); |
10719 | ||
35df4500 | 10720 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10721 | { |
4a64f543 | 10722 | /* Format possible error msg. */ |
fe3f5fa8 | 10723 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
10724 | b->number); |
10725 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 10726 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 10727 | do_cleanups (cleanups); |
c5aa993b | 10728 | } |
c906108c SS |
10729 | set_language (save_language); |
10730 | input_radix = save_input_radix; | |
e62c965a | 10731 | |
0756c555 | 10732 | jit_breakpoint_re_set (); |
4efc6507 | 10733 | |
6c95b8df PA |
10734 | do_cleanups (old_chain); |
10735 | ||
af02033e PP |
10736 | create_overlay_event_breakpoint (); |
10737 | create_longjmp_master_breakpoint (); | |
10738 | create_std_terminate_master_breakpoint (); | |
186c406b | 10739 | create_exception_master_breakpoint (); |
c906108c SS |
10740 | } |
10741 | \f | |
c906108c SS |
10742 | /* Reset the thread number of this breakpoint: |
10743 | ||
10744 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 10745 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 10746 | void |
fba45db2 | 10747 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
10748 | { |
10749 | if (b->thread != -1) | |
10750 | { | |
39f77062 KB |
10751 | if (in_thread_list (inferior_ptid)) |
10752 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
10753 | |
10754 | /* We're being called after following a fork. The new fork is | |
10755 | selected as current, and unless this was a vfork will have a | |
10756 | different program space from the original thread. Reset that | |
10757 | as well. */ | |
10758 | b->loc->pspace = current_program_space; | |
c906108c SS |
10759 | } |
10760 | } | |
10761 | ||
03ac34d5 MS |
10762 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10763 | If from_tty is nonzero, it prints a message to that effect, | |
10764 | which ends with a period (no newline). */ | |
10765 | ||
c906108c | 10766 | void |
fba45db2 | 10767 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 10768 | { |
52f0bd74 | 10769 | struct breakpoint *b; |
c906108c SS |
10770 | |
10771 | if (count < 0) | |
10772 | count = 0; | |
10773 | ||
10774 | ALL_BREAKPOINTS (b) | |
10775 | if (b->number == bptnum) | |
c5aa993b | 10776 | { |
d77f58be SS |
10777 | if (is_tracepoint (b)) |
10778 | { | |
10779 | if (from_tty && count != 0) | |
10780 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
10781 | bptnum); | |
10782 | return; | |
10783 | } | |
10784 | ||
c5aa993b | 10785 | b->ignore_count = count; |
221ea385 KS |
10786 | if (from_tty) |
10787 | { | |
10788 | if (count == 0) | |
3e43a32a MS |
10789 | printf_filtered (_("Will stop next time " |
10790 | "breakpoint %d is reached."), | |
221ea385 KS |
10791 | bptnum); |
10792 | else if (count == 1) | |
a3f17187 | 10793 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
10794 | bptnum); |
10795 | else | |
3e43a32a MS |
10796 | printf_filtered (_("Will ignore next %d " |
10797 | "crossings of breakpoint %d."), | |
221ea385 KS |
10798 | count, bptnum); |
10799 | } | |
c5aa993b | 10800 | breakpoints_changed (); |
383f836e | 10801 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
10802 | return; |
10803 | } | |
c906108c | 10804 | |
8a3fe4f8 | 10805 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
10806 | } |
10807 | ||
c906108c SS |
10808 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
10809 | ||
10810 | static void | |
fba45db2 | 10811 | ignore_command (char *args, int from_tty) |
c906108c SS |
10812 | { |
10813 | char *p = args; | |
52f0bd74 | 10814 | int num; |
c906108c SS |
10815 | |
10816 | if (p == 0) | |
e2e0b3e5 | 10817 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 10818 | |
c906108c | 10819 | num = get_number (&p); |
5c44784c | 10820 | if (num == 0) |
8a3fe4f8 | 10821 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 10822 | if (*p == 0) |
8a3fe4f8 | 10823 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
10824 | |
10825 | set_ignore_count (num, | |
10826 | longest_to_int (value_as_long (parse_and_eval (p))), | |
10827 | from_tty); | |
221ea385 KS |
10828 | if (from_tty) |
10829 | printf_filtered ("\n"); | |
c906108c SS |
10830 | } |
10831 | \f | |
10832 | /* Call FUNCTION on each of the breakpoints | |
10833 | whose numbers are given in ARGS. */ | |
10834 | ||
10835 | static void | |
95a42b64 TT |
10836 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
10837 | void *), | |
10838 | void *data) | |
c906108c | 10839 | { |
52f0bd74 | 10840 | char *p = args; |
c906108c | 10841 | char *p1; |
52f0bd74 AC |
10842 | int num; |
10843 | struct breakpoint *b, *tmp; | |
11cf8741 | 10844 | int match; |
c906108c SS |
10845 | |
10846 | if (p == 0) | |
e2e0b3e5 | 10847 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
10848 | |
10849 | while (*p) | |
10850 | { | |
11cf8741 | 10851 | match = 0; |
c906108c | 10852 | p1 = p; |
c5aa993b | 10853 | |
5c44784c JM |
10854 | num = get_number_or_range (&p1); |
10855 | if (num == 0) | |
c5aa993b | 10856 | { |
8a3fe4f8 | 10857 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
10858 | } |
10859 | else | |
10860 | { | |
10861 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
10862 | if (b->number == num) | |
10863 | { | |
10864 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 10865 | match = 1; |
95a42b64 | 10866 | function (b, data); |
5c44784c | 10867 | if (related_breakpoint) |
95a42b64 | 10868 | function (related_breakpoint, data); |
11cf8741 | 10869 | break; |
5c44784c | 10870 | } |
11cf8741 | 10871 | if (match == 0) |
a3f17187 | 10872 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 10873 | } |
c906108c SS |
10874 | p = p1; |
10875 | } | |
10876 | } | |
10877 | ||
0d381245 VP |
10878 | static struct bp_location * |
10879 | find_location_by_number (char *number) | |
10880 | { | |
10881 | char *dot = strchr (number, '.'); | |
10882 | char *p1; | |
10883 | int bp_num; | |
10884 | int loc_num; | |
10885 | struct breakpoint *b; | |
10886 | struct bp_location *loc; | |
10887 | ||
10888 | *dot = '\0'; | |
10889 | ||
10890 | p1 = number; | |
10891 | bp_num = get_number_or_range (&p1); | |
10892 | if (bp_num == 0) | |
10893 | error (_("Bad breakpoint number '%s'"), number); | |
10894 | ||
10895 | ALL_BREAKPOINTS (b) | |
10896 | if (b->number == bp_num) | |
10897 | { | |
10898 | break; | |
10899 | } | |
10900 | ||
10901 | if (!b || b->number != bp_num) | |
10902 | error (_("Bad breakpoint number '%s'"), number); | |
10903 | ||
10904 | p1 = dot+1; | |
10905 | loc_num = get_number_or_range (&p1); | |
10906 | if (loc_num == 0) | |
10907 | error (_("Bad breakpoint location number '%s'"), number); | |
10908 | ||
10909 | --loc_num; | |
10910 | loc = b->loc; | |
10911 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
10912 | ; | |
10913 | if (!loc) | |
10914 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
10915 | ||
10916 | return loc; | |
10917 | } | |
10918 | ||
10919 | ||
1900040c MS |
10920 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10921 | If from_tty is nonzero, it prints a message to that effect, | |
10922 | which ends with a period (no newline). */ | |
10923 | ||
c906108c | 10924 | void |
fba45db2 | 10925 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10926 | { |
10927 | /* Never disable a watchpoint scope breakpoint; we want to | |
10928 | hit them when we leave scope so we can delete both the | |
10929 | watchpoint and its scope breakpoint at that time. */ | |
10930 | if (bpt->type == bp_watchpoint_scope) | |
10931 | return; | |
10932 | ||
c2c6d25f | 10933 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 10934 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
10935 | return; |
10936 | ||
b5de0fa7 | 10937 | bpt->enable_state = bp_disabled; |
c906108c | 10938 | |
b60e7edf | 10939 | update_global_location_list (0); |
c906108c | 10940 | |
383f836e | 10941 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10942 | } |
10943 | ||
95a42b64 TT |
10944 | /* A callback for map_breakpoint_numbers that calls |
10945 | disable_breakpoint. */ | |
10946 | ||
10947 | static void | |
10948 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
10949 | { | |
10950 | disable_breakpoint (b); | |
10951 | } | |
10952 | ||
c906108c | 10953 | static void |
fba45db2 | 10954 | disable_command (char *args, int from_tty) |
c906108c | 10955 | { |
52f0bd74 | 10956 | struct breakpoint *bpt; |
cc59ec59 | 10957 | |
c906108c SS |
10958 | if (args == 0) |
10959 | ALL_BREAKPOINTS (bpt) | |
10960 | switch (bpt->type) | |
c5aa993b JM |
10961 | { |
10962 | case bp_none: | |
8a3fe4f8 | 10963 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 10964 | bpt->number); |
c5aa993b JM |
10965 | continue; |
10966 | case bp_breakpoint: | |
1042e4c0 | 10967 | case bp_tracepoint: |
7a697b8d | 10968 | case bp_fast_tracepoint: |
0fb4aa4b | 10969 | case bp_static_tracepoint: |
ce78b96d | 10970 | case bp_catchpoint: |
c5aa993b JM |
10971 | case bp_hardware_breakpoint: |
10972 | case bp_watchpoint: | |
10973 | case bp_hardware_watchpoint: | |
10974 | case bp_read_watchpoint: | |
10975 | case bp_access_watchpoint: | |
10976 | disable_breakpoint (bpt); | |
10977 | default: | |
10978 | continue; | |
10979 | } | |
0d381245 VP |
10980 | else if (strchr (args, '.')) |
10981 | { | |
10982 | struct bp_location *loc = find_location_by_number (args); | |
10983 | if (loc) | |
10984 | loc->enabled = 0; | |
b60e7edf | 10985 | update_global_location_list (0); |
0d381245 | 10986 | } |
c906108c | 10987 | else |
95a42b64 | 10988 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
10989 | } |
10990 | ||
10991 | static void | |
fba45db2 | 10992 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 10993 | { |
afe38095 | 10994 | int target_resources_ok; |
c906108c SS |
10995 | |
10996 | if (bpt->type == bp_hardware_breakpoint) | |
10997 | { | |
10998 | int i; | |
c5aa993b | 10999 | i = hw_breakpoint_used_count (); |
53a5351d | 11000 | target_resources_ok = |
d92524f1 | 11001 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 11002 | i + 1, 0); |
c906108c | 11003 | if (target_resources_ok == 0) |
8a3fe4f8 | 11004 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 11005 | else if (target_resources_ok < 0) |
8a3fe4f8 | 11006 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
11007 | } |
11008 | ||
cc60f2e3 | 11009 | if (is_watchpoint (bpt)) |
c906108c | 11010 | { |
dde02812 ES |
11011 | struct gdb_exception e; |
11012 | ||
11013 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 11014 | { |
dde02812 | 11015 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 11016 | } |
dde02812 | 11017 | if (e.reason < 0) |
c5aa993b | 11018 | { |
dde02812 ES |
11019 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
11020 | bpt->number); | |
11021 | return; | |
c5aa993b | 11022 | } |
c906108c | 11023 | } |
0101ce28 | 11024 | |
b4c291bb KH |
11025 | if (bpt->enable_state != bp_permanent) |
11026 | bpt->enable_state = bp_enabled; | |
11027 | bpt->disposition = disposition; | |
b60e7edf | 11028 | update_global_location_list (1); |
b4c291bb KH |
11029 | breakpoints_changed (); |
11030 | ||
383f836e | 11031 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
11032 | } |
11033 | ||
fe3f5fa8 | 11034 | |
c906108c | 11035 | void |
fba45db2 | 11036 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
11037 | { |
11038 | do_enable_breakpoint (bpt, bpt->disposition); | |
11039 | } | |
11040 | ||
95a42b64 TT |
11041 | /* A callback for map_breakpoint_numbers that calls |
11042 | enable_breakpoint. */ | |
11043 | ||
11044 | static void | |
11045 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
11046 | { | |
11047 | enable_breakpoint (b); | |
11048 | } | |
11049 | ||
c906108c SS |
11050 | /* The enable command enables the specified breakpoints (or all defined |
11051 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 11052 | in stopping the inferior. */ |
c906108c | 11053 | |
c906108c | 11054 | static void |
fba45db2 | 11055 | enable_command (char *args, int from_tty) |
c906108c | 11056 | { |
52f0bd74 | 11057 | struct breakpoint *bpt; |
cc59ec59 | 11058 | |
c906108c SS |
11059 | if (args == 0) |
11060 | ALL_BREAKPOINTS (bpt) | |
11061 | switch (bpt->type) | |
c5aa993b JM |
11062 | { |
11063 | case bp_none: | |
8a3fe4f8 | 11064 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 11065 | bpt->number); |
c5aa993b JM |
11066 | continue; |
11067 | case bp_breakpoint: | |
1042e4c0 | 11068 | case bp_tracepoint: |
7a697b8d | 11069 | case bp_fast_tracepoint: |
0fb4aa4b | 11070 | case bp_static_tracepoint: |
ce78b96d | 11071 | case bp_catchpoint: |
c5aa993b JM |
11072 | case bp_hardware_breakpoint: |
11073 | case bp_watchpoint: | |
11074 | case bp_hardware_watchpoint: | |
11075 | case bp_read_watchpoint: | |
11076 | case bp_access_watchpoint: | |
11077 | enable_breakpoint (bpt); | |
11078 | default: | |
11079 | continue; | |
11080 | } | |
0d381245 VP |
11081 | else if (strchr (args, '.')) |
11082 | { | |
11083 | struct bp_location *loc = find_location_by_number (args); | |
11084 | if (loc) | |
11085 | loc->enabled = 1; | |
b60e7edf | 11086 | update_global_location_list (1); |
0d381245 | 11087 | } |
c906108c | 11088 | else |
95a42b64 | 11089 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
11090 | } |
11091 | ||
11092 | static void | |
95a42b64 | 11093 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11094 | { |
b5de0fa7 | 11095 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
11096 | } |
11097 | ||
c906108c | 11098 | static void |
fba45db2 | 11099 | enable_once_command (char *args, int from_tty) |
c906108c | 11100 | { |
95a42b64 | 11101 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
11102 | } |
11103 | ||
11104 | static void | |
95a42b64 | 11105 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11106 | { |
b5de0fa7 | 11107 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
11108 | } |
11109 | ||
c906108c | 11110 | static void |
fba45db2 | 11111 | enable_delete_command (char *args, int from_tty) |
c906108c | 11112 | { |
95a42b64 | 11113 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
11114 | } |
11115 | \f | |
fa8d40ab JJ |
11116 | static void |
11117 | set_breakpoint_cmd (char *args, int from_tty) | |
11118 | { | |
11119 | } | |
11120 | ||
11121 | static void | |
11122 | show_breakpoint_cmd (char *args, int from_tty) | |
11123 | { | |
11124 | } | |
11125 | ||
1f3b5d1b PP |
11126 | /* Invalidate last known value of any hardware watchpoint if |
11127 | the memory which that value represents has been written to by | |
11128 | GDB itself. */ | |
11129 | ||
11130 | static void | |
11131 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
11132 | const bfd_byte *data) | |
11133 | { | |
11134 | struct breakpoint *bp; | |
11135 | ||
11136 | ALL_BREAKPOINTS (bp) | |
11137 | if (bp->enable_state == bp_enabled | |
11138 | && bp->type == bp_hardware_watchpoint | |
11139 | && bp->val_valid && bp->val) | |
11140 | { | |
11141 | struct bp_location *loc; | |
11142 | ||
11143 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
11144 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
11145 | && loc->address + loc->length > addr | |
11146 | && addr + len > loc->address) | |
11147 | { | |
11148 | value_free (bp->val); | |
11149 | bp->val = NULL; | |
11150 | bp->val_valid = 0; | |
11151 | } | |
11152 | } | |
11153 | } | |
11154 | ||
c906108c SS |
11155 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
11156 | ||
11157 | struct symtabs_and_lines | |
fba45db2 | 11158 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
11159 | { |
11160 | struct symtabs_and_lines sals; | |
cc59ec59 | 11161 | |
c906108c | 11162 | if (string == 0) |
8a3fe4f8 | 11163 | error (_("Empty line specification.")); |
c906108c SS |
11164 | if (default_breakpoint_valid) |
11165 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
11166 | default_breakpoint_symtab, |
11167 | default_breakpoint_line, | |
68219205 | 11168 | (char ***) NULL, NULL); |
c906108c SS |
11169 | else |
11170 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 11171 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 11172 | if (*string) |
8a3fe4f8 | 11173 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
11174 | return sals; |
11175 | } | |
8181d85f DJ |
11176 | |
11177 | /* Create and insert a raw software breakpoint at PC. Return an | |
11178 | identifier, which should be used to remove the breakpoint later. | |
11179 | In general, places which call this should be using something on the | |
11180 | breakpoint chain instead; this function should be eliminated | |
11181 | someday. */ | |
11182 | ||
11183 | void * | |
6c95b8df PA |
11184 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
11185 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
11186 | { |
11187 | struct bp_target_info *bp_tgt; | |
11188 | ||
6c95b8df | 11189 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 11190 | |
6c95b8df | 11191 | bp_tgt->placed_address_space = aspace; |
8181d85f | 11192 | bp_tgt->placed_address = pc; |
6c95b8df | 11193 | |
a6d9a66e | 11194 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
11195 | { |
11196 | /* Could not insert the breakpoint. */ | |
11197 | xfree (bp_tgt); | |
11198 | return NULL; | |
11199 | } | |
11200 | ||
11201 | return bp_tgt; | |
11202 | } | |
11203 | ||
4a64f543 MS |
11204 | /* Remove a breakpoint BP inserted by |
11205 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
11206 | |
11207 | int | |
a6d9a66e | 11208 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
11209 | { |
11210 | struct bp_target_info *bp_tgt = bp; | |
11211 | int ret; | |
11212 | ||
a6d9a66e | 11213 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
11214 | xfree (bp_tgt); |
11215 | ||
11216 | return ret; | |
11217 | } | |
11218 | ||
4a64f543 MS |
11219 | /* One (or perhaps two) breakpoints used for software single |
11220 | stepping. */ | |
8181d85f DJ |
11221 | |
11222 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 11223 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
11224 | |
11225 | /* Create and insert a breakpoint for software single step. */ | |
11226 | ||
11227 | void | |
6c95b8df | 11228 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
11229 | struct address_space *aspace, |
11230 | CORE_ADDR next_pc) | |
8181d85f DJ |
11231 | { |
11232 | void **bpt_p; | |
11233 | ||
11234 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
11235 | { |
11236 | bpt_p = &single_step_breakpoints[0]; | |
11237 | single_step_gdbarch[0] = gdbarch; | |
11238 | } | |
8181d85f DJ |
11239 | else |
11240 | { | |
11241 | gdb_assert (single_step_breakpoints[1] == NULL); | |
11242 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 11243 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
11244 | } |
11245 | ||
4a64f543 MS |
11246 | /* NOTE drow/2006-04-11: A future improvement to this function would |
11247 | be to only create the breakpoints once, and actually put them on | |
11248 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
11249 | We could adjust the addresses each time they were needed. Doing | |
11250 | this requires corresponding changes elsewhere where single step | |
11251 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 11252 | |
6c95b8df | 11253 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 11254 | if (*bpt_p == NULL) |
5af949e3 UW |
11255 | error (_("Could not insert single-step breakpoint at %s"), |
11256 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
11257 | } |
11258 | ||
f02253f1 HZ |
11259 | /* Check if the breakpoints used for software single stepping |
11260 | were inserted or not. */ | |
11261 | ||
11262 | int | |
11263 | single_step_breakpoints_inserted (void) | |
11264 | { | |
11265 | return (single_step_breakpoints[0] != NULL | |
11266 | || single_step_breakpoints[1] != NULL); | |
11267 | } | |
11268 | ||
8181d85f DJ |
11269 | /* Remove and delete any breakpoints used for software single step. */ |
11270 | ||
11271 | void | |
11272 | remove_single_step_breakpoints (void) | |
11273 | { | |
11274 | gdb_assert (single_step_breakpoints[0] != NULL); | |
11275 | ||
11276 | /* See insert_single_step_breakpoint for more about this deprecated | |
11277 | call. */ | |
a6d9a66e UW |
11278 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
11279 | single_step_breakpoints[0]); | |
11280 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
11281 | single_step_breakpoints[0] = NULL; |
11282 | ||
11283 | if (single_step_breakpoints[1] != NULL) | |
11284 | { | |
a6d9a66e UW |
11285 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
11286 | single_step_breakpoints[1]); | |
11287 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
11288 | single_step_breakpoints[1] = NULL; |
11289 | } | |
11290 | } | |
11291 | ||
d03285ec UW |
11292 | /* Delete software single step breakpoints without removing them from |
11293 | the inferior. This is intended to be used if the inferior's address | |
11294 | space where they were inserted is already gone, e.g. after exit or | |
11295 | exec. */ | |
11296 | ||
11297 | void | |
11298 | cancel_single_step_breakpoints (void) | |
11299 | { | |
11300 | int i; | |
11301 | ||
11302 | for (i = 0; i < 2; i++) | |
11303 | if (single_step_breakpoints[i]) | |
11304 | { | |
11305 | xfree (single_step_breakpoints[i]); | |
11306 | single_step_breakpoints[i] = NULL; | |
11307 | single_step_gdbarch[i] = NULL; | |
11308 | } | |
11309 | } | |
11310 | ||
11311 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
11312 | removing them. */ | |
11313 | ||
11314 | static void | |
11315 | detach_single_step_breakpoints (void) | |
11316 | { | |
11317 | int i; | |
11318 | ||
11319 | for (i = 0; i < 2; i++) | |
11320 | if (single_step_breakpoints[i]) | |
11321 | target_remove_breakpoint (single_step_gdbarch[i], | |
11322 | single_step_breakpoints[i]); | |
11323 | } | |
11324 | ||
4a64f543 MS |
11325 | /* Check whether a software single-step breakpoint is inserted at |
11326 | PC. */ | |
1aafd4da UW |
11327 | |
11328 | static int | |
cc59ec59 MS |
11329 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
11330 | CORE_ADDR pc) | |
1aafd4da UW |
11331 | { |
11332 | int i; | |
11333 | ||
11334 | for (i = 0; i < 2; i++) | |
11335 | { | |
11336 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
11337 | if (bp_tgt |
11338 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
11339 | bp_tgt->placed_address, | |
11340 | aspace, pc)) | |
1aafd4da UW |
11341 | return 1; |
11342 | } | |
11343 | ||
11344 | return 0; | |
11345 | } | |
11346 | ||
a96d9b2e SDJ |
11347 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
11348 | non-zero otherwise. */ | |
11349 | static int | |
11350 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
11351 | { | |
11352 | if (syscall_catchpoint_p (bp) | |
11353 | && bp->enable_state != bp_disabled | |
11354 | && bp->enable_state != bp_call_disabled) | |
11355 | return 1; | |
11356 | else | |
11357 | return 0; | |
11358 | } | |
11359 | ||
11360 | int | |
11361 | catch_syscall_enabled (void) | |
11362 | { | |
11363 | struct inferior *inf = current_inferior (); | |
11364 | ||
11365 | return inf->total_syscalls_count != 0; | |
11366 | } | |
11367 | ||
11368 | int | |
11369 | catching_syscall_number (int syscall_number) | |
11370 | { | |
11371 | struct breakpoint *bp; | |
11372 | ||
11373 | ALL_BREAKPOINTS (bp) | |
11374 | if (is_syscall_catchpoint_enabled (bp)) | |
11375 | { | |
11376 | if (bp->syscalls_to_be_caught) | |
11377 | { | |
11378 | int i, iter; | |
11379 | for (i = 0; | |
11380 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
11381 | i++) | |
11382 | if (syscall_number == iter) | |
11383 | return 1; | |
11384 | } | |
11385 | else | |
11386 | return 1; | |
11387 | } | |
11388 | ||
11389 | return 0; | |
11390 | } | |
11391 | ||
11392 | /* Complete syscall names. Used by "catch syscall". */ | |
11393 | static char ** | |
11394 | catch_syscall_completer (struct cmd_list_element *cmd, | |
11395 | char *text, char *word) | |
11396 | { | |
11397 | const char **list = get_syscall_names (); | |
cc59ec59 | 11398 | |
a96d9b2e SDJ |
11399 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); |
11400 | } | |
11401 | ||
1042e4c0 SS |
11402 | /* Tracepoint-specific operations. */ |
11403 | ||
11404 | /* Set tracepoint count to NUM. */ | |
11405 | static void | |
11406 | set_tracepoint_count (int num) | |
11407 | { | |
11408 | tracepoint_count = num; | |
4fa62494 | 11409 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
11410 | } |
11411 | ||
11412 | void | |
11413 | trace_command (char *arg, int from_tty) | |
11414 | { | |
8cdf0e15 VP |
11415 | if (create_breakpoint (get_current_arch (), |
11416 | arg, | |
11417 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11418 | 0 /* tempflag */, |
11419 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11420 | 0 /* Ignore count */, |
11421 | pending_break_support, | |
11422 | NULL, | |
11423 | from_tty, | |
84f4c1fe PM |
11424 | 1 /* enabled */, |
11425 | 0 /* internal */)) | |
fd9b8c24 | 11426 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
11427 | } |
11428 | ||
7a697b8d SS |
11429 | void |
11430 | ftrace_command (char *arg, int from_tty) | |
11431 | { | |
8cdf0e15 VP |
11432 | if (create_breakpoint (get_current_arch (), |
11433 | arg, | |
11434 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11435 | 0 /* tempflag */, |
11436 | bp_fast_tracepoint /* type_wanted */, | |
11437 | 0 /* Ignore count */, | |
11438 | pending_break_support, | |
11439 | NULL, | |
11440 | from_tty, | |
84f4c1fe PM |
11441 | 1 /* enabled */, |
11442 | 0 /* internal */)) | |
0fb4aa4b PA |
11443 | set_tracepoint_count (breakpoint_count); |
11444 | } | |
11445 | ||
11446 | /* strace command implementation. Creates a static tracepoint. */ | |
11447 | ||
11448 | void | |
11449 | strace_command (char *arg, int from_tty) | |
11450 | { | |
11451 | if (create_breakpoint (get_current_arch (), | |
11452 | arg, | |
11453 | NULL, 0, 1 /* parse arg */, | |
11454 | 0 /* tempflag */, | |
11455 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11456 | 0 /* Ignore count */, |
11457 | pending_break_support, | |
11458 | NULL, | |
11459 | from_tty, | |
84f4c1fe PM |
11460 | 1 /* enabled */, |
11461 | 0 /* internal */)) | |
fd9b8c24 | 11462 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
11463 | } |
11464 | ||
409873ef SS |
11465 | /* Set up a fake reader function that gets command lines from a linked |
11466 | list that was acquired during tracepoint uploading. */ | |
11467 | ||
11468 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 11469 | static int next_cmd; |
409873ef SS |
11470 | |
11471 | static char * | |
11472 | read_uploaded_action (void) | |
11473 | { | |
11474 | char *rslt; | |
11475 | ||
3149d8c1 | 11476 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 11477 | |
3149d8c1 | 11478 | next_cmd++; |
409873ef SS |
11479 | |
11480 | return rslt; | |
11481 | } | |
11482 | ||
00bf0b85 SS |
11483 | /* Given information about a tracepoint as recorded on a target (which |
11484 | can be either a live system or a trace file), attempt to create an | |
11485 | equivalent GDB tracepoint. This is not a reliable process, since | |
11486 | the target does not necessarily have all the information used when | |
11487 | the tracepoint was originally defined. */ | |
11488 | ||
11489 | struct breakpoint * | |
11490 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 11491 | { |
409873ef | 11492 | char *addr_str, small_buf[100]; |
d5551862 | 11493 | struct breakpoint *tp; |
fd9b8c24 | 11494 | |
409873ef SS |
11495 | if (utp->at_string) |
11496 | addr_str = utp->at_string; | |
11497 | else | |
11498 | { | |
11499 | /* In the absence of a source location, fall back to raw | |
11500 | address. Since there is no way to confirm that the address | |
11501 | means the same thing as when the trace was started, warn the | |
11502 | user. */ | |
3e43a32a MS |
11503 | warning (_("Uploaded tracepoint %d has no " |
11504 | "source location, using raw address"), | |
409873ef SS |
11505 | utp->number); |
11506 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
11507 | addr_str = small_buf; | |
11508 | } | |
11509 | ||
11510 | /* There's not much we can do with a sequence of bytecodes. */ | |
11511 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
11512 | warning (_("Uploaded tracepoint %d condition " |
11513 | "has no source form, ignoring it"), | |
409873ef | 11514 | utp->number); |
d5551862 | 11515 | |
8cdf0e15 | 11516 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
11517 | addr_str, |
11518 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 11519 | 0 /* tempflag */, |
0fb4aa4b | 11520 | utp->type /* type_wanted */, |
8cdf0e15 VP |
11521 | 0 /* Ignore count */, |
11522 | pending_break_support, | |
11523 | NULL, | |
11524 | 0 /* from_tty */, | |
84f4c1fe PM |
11525 | utp->enabled /* enabled */, |
11526 | 0 /* internal */)) | |
fd9b8c24 PA |
11527 | return NULL; |
11528 | ||
00bf0b85 SS |
11529 | set_tracepoint_count (breakpoint_count); |
11530 | ||
409873ef | 11531 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
11532 | tp = get_tracepoint (tracepoint_count); |
11533 | gdb_assert (tp != NULL); | |
d5551862 | 11534 | |
00bf0b85 SS |
11535 | if (utp->pass > 0) |
11536 | { | |
409873ef | 11537 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 11538 | |
409873ef | 11539 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
11540 | } |
11541 | ||
409873ef SS |
11542 | /* If we have uploaded versions of the original commands, set up a |
11543 | special-purpose "reader" function and call the usual command line | |
11544 | reader, then pass the result to the breakpoint command-setting | |
11545 | function. */ | |
3149d8c1 | 11546 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 11547 | { |
409873ef | 11548 | struct command_line *cmd_list; |
00bf0b85 | 11549 | |
409873ef | 11550 | this_utp = utp; |
3149d8c1 | 11551 | next_cmd = 0; |
d5551862 | 11552 | |
409873ef SS |
11553 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
11554 | ||
11555 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 11556 | } |
3149d8c1 SS |
11557 | else if (!VEC_empty (char_ptr, utp->actions) |
11558 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
11559 | warning (_("Uploaded tracepoint %d actions " |
11560 | "have no source form, ignoring them"), | |
409873ef | 11561 | utp->number); |
00bf0b85 SS |
11562 | |
11563 | return tp; | |
11564 | } | |
11565 | ||
1042e4c0 SS |
11566 | /* Print information on tracepoint number TPNUM_EXP, or all if |
11567 | omitted. */ | |
11568 | ||
11569 | static void | |
11570 | tracepoints_info (char *tpnum_exp, int from_tty) | |
11571 | { | |
d77f58be SS |
11572 | int tpnum = -1, num_printed; |
11573 | ||
11574 | if (tpnum_exp) | |
11575 | tpnum = parse_and_eval_long (tpnum_exp); | |
1042e4c0 | 11576 | |
d77f58be SS |
11577 | num_printed = breakpoint_1 (tpnum, 0, is_tracepoint); |
11578 | ||
11579 | if (num_printed == 0) | |
1042e4c0 | 11580 | { |
d77f58be SS |
11581 | if (tpnum == -1) |
11582 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
11583 | else | |
11584 | ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum); | |
1042e4c0 | 11585 | } |
ad443146 SS |
11586 | |
11587 | default_collect_info (); | |
1042e4c0 SS |
11588 | } |
11589 | ||
4a64f543 | 11590 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
11591 | Not supported by all targets. */ |
11592 | static void | |
11593 | enable_trace_command (char *args, int from_tty) | |
11594 | { | |
11595 | enable_command (args, from_tty); | |
11596 | } | |
11597 | ||
4a64f543 | 11598 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
11599 | Not supported by all targets. */ |
11600 | static void | |
11601 | disable_trace_command (char *args, int from_tty) | |
11602 | { | |
11603 | disable_command (args, from_tty); | |
11604 | } | |
11605 | ||
4a64f543 | 11606 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
11607 | static void |
11608 | delete_trace_command (char *arg, int from_tty) | |
11609 | { | |
35df4500 | 11610 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
11611 | |
11612 | dont_repeat (); | |
11613 | ||
11614 | if (arg == 0) | |
11615 | { | |
11616 | int breaks_to_delete = 0; | |
11617 | ||
11618 | /* Delete all breakpoints if no argument. | |
11619 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
11620 | have to be deleted with an explicit breakpoint number |
11621 | argument. */ | |
1042e4c0 SS |
11622 | ALL_TRACEPOINTS (b) |
11623 | { | |
11624 | if (b->number >= 0) | |
11625 | { | |
11626 | breaks_to_delete = 1; | |
11627 | break; | |
11628 | } | |
11629 | } | |
11630 | ||
11631 | /* Ask user only if there are some breakpoints to delete. */ | |
11632 | if (!from_tty | |
11633 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
11634 | { | |
35df4500 | 11635 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
1042e4c0 | 11636 | { |
d77f58be | 11637 | if (is_tracepoint (b) |
059fb39f | 11638 | && b->number >= 0) |
1042e4c0 SS |
11639 | delete_breakpoint (b); |
11640 | } | |
11641 | } | |
11642 | } | |
11643 | else | |
95a42b64 | 11644 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
11645 | } |
11646 | ||
11647 | /* Set passcount for tracepoint. | |
11648 | ||
11649 | First command argument is passcount, second is tracepoint number. | |
11650 | If tracepoint number omitted, apply to most recently defined. | |
11651 | Also accepts special argument "all". */ | |
11652 | ||
11653 | static void | |
11654 | trace_pass_command (char *args, int from_tty) | |
11655 | { | |
11656 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
11657 | unsigned int count; | |
11658 | int all = 0; | |
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". */ | |
11672 | all = 1; | |
11673 | if (*args) | |
11674 | error (_("Junk at end of arguments.")); | |
11675 | } | |
11676 | else | |
11677 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
11678 | ||
11679 | do | |
11680 | { | |
11681 | if (t1) | |
11682 | { | |
11683 | ALL_TRACEPOINTS (t2) | |
11684 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
11685 | { | |
11686 | t2->pass_count = count; | |
11687 | observer_notify_tracepoint_modified (t2->number); | |
11688 | if (from_tty) | |
3e43a32a MS |
11689 | printf_filtered (_("Setting tracepoint %d's " |
11690 | "passcount to %d\n"), | |
1042e4c0 SS |
11691 | t2->number, count); |
11692 | } | |
11693 | if (! all && *args) | |
11694 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
11695 | } | |
11696 | } | |
11697 | while (*args); | |
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 SS |
11728 | /* Utility: parse a tracepoint number and look it up in the list. |
11729 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
11730 | if OPTIONAL_P is true, then if the argument is missing, the most | |
11731 | recent tracepoint (tracepoint_count) is returned. */ | |
11732 | struct breakpoint * | |
11733 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
11734 | { | |
11735 | extern int tracepoint_count; | |
11736 | struct breakpoint *t; | |
11737 | int tpnum; | |
11738 | char *instring = arg == NULL ? NULL : *arg; | |
11739 | ||
11740 | if (arg == NULL || *arg == NULL || ! **arg) | |
11741 | { | |
11742 | if (optional_p) | |
11743 | tpnum = tracepoint_count; | |
11744 | else | |
11745 | error_no_arg (_("tracepoint number")); | |
11746 | } | |
11747 | else | |
11748 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
11749 | ||
11750 | if (tpnum <= 0) | |
11751 | { | |
11752 | if (instring && *instring) | |
11753 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
11754 | instring); | |
11755 | else | |
3e43a32a MS |
11756 | printf_filtered (_("Tracepoint argument missing " |
11757 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
11758 | return NULL; |
11759 | } | |
11760 | ||
11761 | ALL_TRACEPOINTS (t) | |
11762 | if (t->number == tpnum) | |
11763 | { | |
11764 | return t; | |
11765 | } | |
11766 | ||
11767 | /* FIXME: if we are in the middle of a range we don't want to give | |
11768 | a message. The current interface to get_number_or_range doesn't | |
11769 | allow us to discover this. */ | |
11770 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
11771 | return NULL; | |
11772 | } | |
11773 | ||
6149aea9 PA |
11774 | /* Save information on user settable breakpoints (watchpoints, etc) to |
11775 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
11776 | on each breakpoint and only include the ones for which it returns | |
11777 | non-zero. */ | |
11778 | ||
1042e4c0 | 11779 | static void |
6149aea9 PA |
11780 | save_breakpoints (char *filename, int from_tty, |
11781 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
11782 | { |
11783 | struct breakpoint *tp; | |
6149aea9 | 11784 | int any = 0; |
a7bdde9e | 11785 | char *pathname; |
1042e4c0 | 11786 | struct cleanup *cleanup; |
a7bdde9e | 11787 | struct ui_file *fp; |
6149aea9 | 11788 | int extra_trace_bits = 0; |
1042e4c0 | 11789 | |
6149aea9 PA |
11790 | if (filename == 0 || *filename == 0) |
11791 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
11792 | |
11793 | /* See if we have anything to save. */ | |
6149aea9 | 11794 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11795 | { |
6149aea9 | 11796 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11797 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
11798 | continue; |
11799 | ||
11800 | /* If we have a filter, only save the breakpoints it accepts. */ | |
11801 | if (filter && !filter (tp)) | |
11802 | continue; | |
11803 | ||
11804 | any = 1; | |
11805 | ||
11806 | if (is_tracepoint (tp)) | |
11807 | { | |
11808 | extra_trace_bits = 1; | |
11809 | ||
11810 | /* We can stop searching. */ | |
11811 | break; | |
11812 | } | |
1042e4c0 | 11813 | } |
6149aea9 PA |
11814 | |
11815 | if (!any) | |
1042e4c0 | 11816 | { |
6149aea9 | 11817 | warning (_("Nothing to save.")); |
1042e4c0 SS |
11818 | return; |
11819 | } | |
11820 | ||
6149aea9 | 11821 | pathname = tilde_expand (filename); |
1042e4c0 | 11822 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 11823 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 11824 | if (!fp) |
6149aea9 PA |
11825 | error (_("Unable to open file '%s' for saving (%s)"), |
11826 | filename, safe_strerror (errno)); | |
a7bdde9e | 11827 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 11828 | |
6149aea9 PA |
11829 | if (extra_trace_bits) |
11830 | save_trace_state_variables (fp); | |
8bf6485c | 11831 | |
6149aea9 | 11832 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11833 | { |
6149aea9 | 11834 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 11835 | if (!user_breakpoint_p (tp)) |
6149aea9 | 11836 | continue; |
8bf6485c | 11837 | |
6149aea9 PA |
11838 | /* If we have a filter, only save the breakpoints it accepts. */ |
11839 | if (filter && !filter (tp)) | |
11840 | continue; | |
11841 | ||
11842 | if (tp->ops != NULL) | |
11843 | (tp->ops->print_recreate) (tp, fp); | |
1042e4c0 SS |
11844 | else |
11845 | { | |
6149aea9 PA |
11846 | if (tp->type == bp_fast_tracepoint) |
11847 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
11848 | if (tp->type == bp_static_tracepoint) |
11849 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
11850 | else if (tp->type == bp_tracepoint) |
11851 | fprintf_unfiltered (fp, "trace"); | |
11852 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11853 | fprintf_unfiltered (fp, "tbreak"); | |
11854 | else if (tp->type == bp_breakpoint) | |
11855 | fprintf_unfiltered (fp, "break"); | |
11856 | else if (tp->type == bp_hardware_breakpoint | |
11857 | && tp->disposition == disp_del) | |
11858 | fprintf_unfiltered (fp, "thbreak"); | |
11859 | else if (tp->type == bp_hardware_breakpoint) | |
11860 | fprintf_unfiltered (fp, "hbreak"); | |
11861 | else if (tp->type == bp_watchpoint) | |
11862 | fprintf_unfiltered (fp, "watch"); | |
11863 | else if (tp->type == bp_hardware_watchpoint) | |
11864 | fprintf_unfiltered (fp, "watch"); | |
11865 | else if (tp->type == bp_read_watchpoint) | |
11866 | fprintf_unfiltered (fp, "rwatch"); | |
11867 | else if (tp->type == bp_access_watchpoint) | |
11868 | fprintf_unfiltered (fp, "awatch"); | |
11869 | else | |
11870 | internal_error (__FILE__, __LINE__, | |
11871 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11872 | ||
11873 | if (tp->exp_string) | |
11874 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
11875 | else if (tp->addr_string) | |
11876 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
11877 | else | |
11878 | { | |
11879 | char tmp[40]; | |
11880 | ||
11881 | sprintf_vma (tmp, tp->loc->address); | |
11882 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
11883 | } | |
1042e4c0 SS |
11884 | } |
11885 | ||
6149aea9 PA |
11886 | if (tp->thread != -1) |
11887 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
11888 | ||
11889 | if (tp->task != 0) | |
11890 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
11891 | |
11892 | fprintf_unfiltered (fp, "\n"); | |
11893 | ||
6149aea9 PA |
11894 | /* Note, we can't rely on tp->number for anything, as we can't |
11895 | assume the recreated breakpoint numbers will match. Use $bpnum | |
11896 | instead. */ | |
11897 | ||
11898 | if (tp->cond_string) | |
11899 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
11900 | ||
11901 | if (tp->ignore_count) | |
11902 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
11903 | ||
1042e4c0 | 11904 | if (tp->pass_count) |
a7bdde9e | 11905 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 11906 | |
a7bdde9e | 11907 | if (tp->commands) |
1042e4c0 | 11908 | { |
a7bdde9e VP |
11909 | volatile struct gdb_exception ex; |
11910 | ||
6149aea9 | 11911 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
11912 | |
11913 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 11914 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 11915 | { |
9add0f1b | 11916 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
11917 | } |
11918 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 11919 | |
a7bdde9e VP |
11920 | if (ex.reason < 0) |
11921 | throw_exception (ex); | |
1042e4c0 | 11922 | |
a7bdde9e | 11923 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 11924 | } |
6149aea9 PA |
11925 | |
11926 | if (tp->enable_state == bp_disabled) | |
11927 | fprintf_unfiltered (fp, "disable\n"); | |
11928 | ||
11929 | /* If this is a multi-location breakpoint, check if the locations | |
11930 | should be individually disabled. Watchpoint locations are | |
11931 | special, and not user visible. */ | |
11932 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
11933 | { | |
11934 | struct bp_location *loc; | |
11935 | int n = 1; | |
11936 | ||
11937 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
11938 | if (!loc->enabled) | |
11939 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
11940 | } | |
1042e4c0 | 11941 | } |
8bf6485c | 11942 | |
6149aea9 | 11943 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
11944 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
11945 | ||
1042e4c0 SS |
11946 | do_cleanups (cleanup); |
11947 | if (from_tty) | |
6149aea9 PA |
11948 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
11949 | } | |
11950 | ||
11951 | /* The `save breakpoints' command. */ | |
11952 | ||
11953 | static void | |
11954 | save_breakpoints_command (char *args, int from_tty) | |
11955 | { | |
11956 | save_breakpoints (args, from_tty, NULL); | |
11957 | } | |
11958 | ||
11959 | /* The `save tracepoints' command. */ | |
11960 | ||
11961 | static void | |
11962 | save_tracepoints_command (char *args, int from_tty) | |
11963 | { | |
11964 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
11965 | } |
11966 | ||
11967 | /* Create a vector of all tracepoints. */ | |
11968 | ||
11969 | VEC(breakpoint_p) * | |
11970 | all_tracepoints () | |
11971 | { | |
11972 | VEC(breakpoint_p) *tp_vec = 0; | |
11973 | struct breakpoint *tp; | |
11974 | ||
11975 | ALL_TRACEPOINTS (tp) | |
11976 | { | |
11977 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
11978 | } | |
11979 | ||
11980 | return tp_vec; | |
11981 | } | |
11982 | ||
c906108c | 11983 | \f |
4a64f543 MS |
11984 | /* This help string is used for the break, hbreak, tbreak and thbreak |
11985 | commands. It is defined as a macro to prevent duplication. | |
11986 | COMMAND should be a string constant containing the name of the | |
11987 | command. */ | |
31e2b00f AS |
11988 | #define BREAK_ARGS_HELP(command) \ |
11989 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
11990 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
11991 | If a line number is specified, break at start of code for that line.\n\ | |
11992 | If a function is specified, break at start of code for that function.\n\ | |
11993 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
11994 | With no LOCATION, uses current execution address of the selected\n\ |
11995 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
11996 | \n\ |
11997 | THREADNUM is the number from \"info threads\".\n\ | |
11998 | CONDITION is a boolean expression.\n\ | |
11999 | \n\ | |
d41c0fc8 PA |
12000 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
12001 | conditions are different.\n\ | |
31e2b00f AS |
12002 | \n\ |
12003 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
12004 | ||
44feb3ce TT |
12005 | /* List of subcommands for "catch". */ |
12006 | static struct cmd_list_element *catch_cmdlist; | |
12007 | ||
12008 | /* List of subcommands for "tcatch". */ | |
12009 | static struct cmd_list_element *tcatch_cmdlist; | |
12010 | ||
12011 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
12012 | lists, and pass some additional user data to the command function. */ | |
12013 | static void | |
12014 | add_catch_command (char *name, char *docstring, | |
12015 | void (*sfunc) (char *args, int from_tty, | |
12016 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
12017 | char **(*completer) (struct cmd_list_element *cmd, |
12018 | char *text, char *word), | |
44feb3ce TT |
12019 | void *user_data_catch, |
12020 | void *user_data_tcatch) | |
12021 | { | |
12022 | struct cmd_list_element *command; | |
12023 | ||
12024 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12025 | &catch_cmdlist); | |
12026 | set_cmd_sfunc (command, sfunc); | |
12027 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 12028 | set_cmd_completer (command, completer); |
44feb3ce TT |
12029 | |
12030 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12031 | &tcatch_cmdlist); | |
12032 | set_cmd_sfunc (command, sfunc); | |
12033 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 12034 | set_cmd_completer (command, completer); |
44feb3ce TT |
12035 | } |
12036 | ||
6c95b8df | 12037 | static void |
a79b8f6e | 12038 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 12039 | { |
6c95b8df PA |
12040 | inf->total_syscalls_count = 0; |
12041 | inf->any_syscall_count = 0; | |
12042 | VEC_free (int, inf->syscalls_counts); | |
12043 | } | |
12044 | ||
6149aea9 PA |
12045 | static void |
12046 | save_command (char *arg, int from_tty) | |
12047 | { | |
3e43a32a MS |
12048 | printf_unfiltered (_("\"save\" must be followed by " |
12049 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
12050 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
12051 | } | |
12052 | ||
84f4c1fe PM |
12053 | struct breakpoint * |
12054 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
12055 | void *data) | |
12056 | { | |
35df4500 | 12057 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 12058 | |
35df4500 | 12059 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
12060 | { |
12061 | if ((*callback) (b, data)) | |
12062 | return b; | |
12063 | } | |
12064 | ||
12065 | return NULL; | |
12066 | } | |
12067 | ||
c906108c | 12068 | void |
fba45db2 | 12069 | _initialize_breakpoint (void) |
c906108c SS |
12070 | { |
12071 | struct cmd_list_element *c; | |
12072 | ||
84acb35a | 12073 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 12074 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 12075 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 12076 | |
c906108c SS |
12077 | breakpoint_chain = 0; |
12078 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
12079 | before a breakpoint is set. */ | |
12080 | breakpoint_count = 0; | |
12081 | ||
1042e4c0 SS |
12082 | tracepoint_count = 0; |
12083 | ||
1bedd215 AC |
12084 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
12085 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
12086 | Usage is `ignore N COUNT'.")); | |
c906108c | 12087 | if (xdb_commands) |
c5aa993b | 12088 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 12089 | |
1bedd215 AC |
12090 | add_com ("commands", class_breakpoint, commands_command, _("\ |
12091 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
12092 | Give breakpoint number as argument after \"commands\".\n\ |
12093 | With no argument, the targeted breakpoint is the last one set.\n\ | |
12094 | The commands themselves follow starting on the next line.\n\ | |
12095 | Type a line containing \"end\" to indicate the end of them.\n\ | |
12096 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 12097 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 12098 | |
1bedd215 AC |
12099 | add_com ("condition", class_breakpoint, condition_command, _("\ |
12100 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 12101 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 12102 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 12103 | |
1bedd215 | 12104 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 12105 | Set a temporary breakpoint.\n\ |
c906108c SS |
12106 | Like \"break\" except the breakpoint is only temporary,\n\ |
12107 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
12108 | by using \"enable delete\" on the breakpoint number.\n\ |
12109 | \n" | |
12110 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 12111 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12112 | |
1bedd215 | 12113 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 12114 | Set a hardware assisted breakpoint.\n\ |
c906108c | 12115 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
12116 | some target hardware may not have this support.\n\ |
12117 | \n" | |
12118 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 12119 | set_cmd_completer (c, location_completer); |
c906108c | 12120 | |
1bedd215 | 12121 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 12122 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 12123 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
12124 | so it will be deleted when hit.\n\ |
12125 | \n" | |
12126 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 12127 | set_cmd_completer (c, location_completer); |
c906108c | 12128 | |
1bedd215 AC |
12129 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
12130 | Enable some breakpoints.\n\ | |
c906108c SS |
12131 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12132 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12133 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12134 | With a subcommand you can enable temporarily."), |
c906108c SS |
12135 | &enablelist, "enable ", 1, &cmdlist); |
12136 | if (xdb_commands) | |
1bedd215 AC |
12137 | add_com ("ab", class_breakpoint, enable_command, _("\ |
12138 | Enable some breakpoints.\n\ | |
c906108c SS |
12139 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12140 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12141 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12142 | With a subcommand you can enable temporarily.")); |
c906108c SS |
12143 | |
12144 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
12145 | ||
84951ab5 | 12146 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 12147 | Enable some breakpoints.\n\ |
c906108c SS |
12148 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12149 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12150 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 12151 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 12152 | |
1a966eab AC |
12153 | add_cmd ("once", no_class, enable_once_command, _("\ |
12154 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12155 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12156 | &enablebreaklist); |
12157 | ||
1a966eab AC |
12158 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12159 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12160 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12161 | &enablebreaklist); |
12162 | ||
1a966eab AC |
12163 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12164 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12165 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12166 | &enablelist); |
12167 | ||
1a966eab AC |
12168 | add_cmd ("once", no_class, enable_once_command, _("\ |
12169 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12170 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12171 | &enablelist); |
12172 | ||
1bedd215 AC |
12173 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
12174 | Disable some breakpoints.\n\ | |
c906108c SS |
12175 | Arguments are breakpoint numbers with spaces in between.\n\ |
12176 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12177 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
12178 | &disablelist, "disable ", 1, &cmdlist); |
12179 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
12180 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
12181 | if (xdb_commands) | |
1bedd215 AC |
12182 | add_com ("sb", class_breakpoint, disable_command, _("\ |
12183 | Disable some breakpoints.\n\ | |
c906108c SS |
12184 | Arguments are breakpoint numbers with spaces in between.\n\ |
12185 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12186 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 12187 | |
1a966eab AC |
12188 | add_cmd ("breakpoints", class_alias, 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\ | |
12192 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 12193 | This command may be abbreviated \"disable\"."), |
c906108c SS |
12194 | &disablelist); |
12195 | ||
1bedd215 AC |
12196 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
12197 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12198 | Arguments are breakpoint numbers with spaces in between.\n\ |
12199 | To delete all breakpoints, give no argument.\n\ | |
12200 | \n\ | |
12201 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 12202 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
12203 | &deletelist, "delete ", 1, &cmdlist); |
12204 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 12205 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 12206 | if (xdb_commands) |
1bedd215 AC |
12207 | add_com ("db", class_breakpoint, delete_command, _("\ |
12208 | Delete some breakpoints.\n\ | |
c906108c | 12209 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 12210 | To delete all breakpoints, give no argument.\n")); |
c906108c | 12211 | |
1a966eab AC |
12212 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
12213 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12214 | Arguments are breakpoint numbers with spaces in between.\n\ |
12215 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 12216 | This command may be abbreviated \"delete\"."), |
c906108c SS |
12217 | &deletelist); |
12218 | ||
1bedd215 AC |
12219 | add_com ("clear", class_breakpoint, clear_command, _("\ |
12220 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
12221 | Argument may be line number, function name, or \"*\" and an address.\n\ |
12222 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
12223 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
12224 | If an address is specified, breakpoints at that address are cleared.\n\ |
12225 | \n\ | |
12226 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
12227 | is executing in.\n\ |
12228 | \n\ | |
1bedd215 | 12229 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 12230 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 12231 | |
1bedd215 | 12232 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
12233 | Set breakpoint at specified line or function.\n" |
12234 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 12235 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12236 | |
c906108c SS |
12237 | add_com_alias ("b", "break", class_run, 1); |
12238 | add_com_alias ("br", "break", class_run, 1); | |
12239 | add_com_alias ("bre", "break", class_run, 1); | |
12240 | add_com_alias ("brea", "break", class_run, 1); | |
12241 | ||
7681d515 PM |
12242 | if (xdb_commands) |
12243 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
12244 | |
12245 | if (dbx_commands) | |
12246 | { | |
1bedd215 AC |
12247 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
12248 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
12249 | &stoplist, "stop ", 1, &cmdlist); |
12250 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 12251 | _("Break in function or address."), &stoplist); |
c5aa993b | 12252 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 12253 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
12254 | add_com ("status", class_info, breakpoints_info, _("\ |
12255 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12256 | The \"Type\" column indicates one of:\n\ |
12257 | \tbreakpoint - normal breakpoint\n\ | |
12258 | \twatchpoint - watchpoint\n\ | |
12259 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12260 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12261 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12262 | address and file/line number respectively.\n\ |
12263 | \n\ | |
12264 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12265 | are set to the address of the last breakpoint listed unless the command\n\ |
12266 | is prefixed with \"server \".\n\n\ | |
c906108c | 12267 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12268 | breakpoint set.")); |
c906108c SS |
12269 | } |
12270 | ||
1bedd215 AC |
12271 | add_info ("breakpoints", breakpoints_info, _("\ |
12272 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12273 | The \"Type\" column indicates one of:\n\ |
12274 | \tbreakpoint - normal breakpoint\n\ | |
12275 | \twatchpoint - watchpoint\n\ | |
12276 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12277 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12278 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12279 | address and file/line number respectively.\n\ |
12280 | \n\ | |
12281 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12282 | are set to the address of the last breakpoint listed unless the command\n\ |
12283 | is prefixed with \"server \".\n\n\ | |
c906108c | 12284 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12285 | breakpoint set.")); |
c906108c | 12286 | |
6b04bdb7 MS |
12287 | add_info_alias ("b", "breakpoints", 1); |
12288 | ||
c906108c | 12289 | if (xdb_commands) |
1bedd215 AC |
12290 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
12291 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12292 | The \"Type\" column indicates one of:\n\ |
12293 | \tbreakpoint - normal breakpoint\n\ | |
12294 | \twatchpoint - watchpoint\n\ | |
12295 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12296 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12297 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12298 | address and file/line number respectively.\n\ |
12299 | \n\ | |
12300 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12301 | are set to the address of the last breakpoint listed unless the command\n\ |
12302 | is prefixed with \"server \".\n\n\ | |
c906108c | 12303 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12304 | breakpoint set.")); |
c906108c | 12305 | |
1a966eab AC |
12306 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
12307 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12308 | The \"Type\" column indicates one of:\n\ |
12309 | \tbreakpoint - normal breakpoint\n\ | |
12310 | \twatchpoint - watchpoint\n\ | |
12311 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
12312 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
12313 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
12314 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
12315 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
12316 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
12317 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
12318 | address and file/line number respectively.\n\ |
12319 | \n\ | |
12320 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12321 | are set to the address of the last breakpoint listed unless the command\n\ |
12322 | is prefixed with \"server \".\n\n\ | |
c906108c | 12323 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 12324 | breakpoint set."), |
c906108c SS |
12325 | &maintenanceinfolist); |
12326 | ||
44feb3ce TT |
12327 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
12328 | Set catchpoints to catch events."), | |
12329 | &catch_cmdlist, "catch ", | |
12330 | 0/*allow-unknown*/, &cmdlist); | |
12331 | ||
12332 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
12333 | Set temporary catchpoints to catch events."), | |
12334 | &tcatch_cmdlist, "tcatch ", | |
12335 | 0/*allow-unknown*/, &cmdlist); | |
12336 | ||
12337 | /* Add catch and tcatch sub-commands. */ | |
12338 | add_catch_command ("catch", _("\ | |
12339 | Catch an exception, when caught.\n\ | |
12340 | With an argument, catch only exceptions with the given name."), | |
12341 | catch_catch_command, | |
a96d9b2e | 12342 | NULL, |
44feb3ce TT |
12343 | CATCH_PERMANENT, |
12344 | CATCH_TEMPORARY); | |
12345 | add_catch_command ("throw", _("\ | |
12346 | Catch an exception, when thrown.\n\ | |
12347 | With an argument, catch only exceptions with the given name."), | |
12348 | catch_throw_command, | |
a96d9b2e | 12349 | NULL, |
44feb3ce TT |
12350 | CATCH_PERMANENT, |
12351 | CATCH_TEMPORARY); | |
12352 | add_catch_command ("fork", _("Catch calls to fork."), | |
12353 | catch_fork_command_1, | |
a96d9b2e | 12354 | NULL, |
44feb3ce TT |
12355 | (void *) (uintptr_t) catch_fork_permanent, |
12356 | (void *) (uintptr_t) catch_fork_temporary); | |
12357 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
12358 | catch_fork_command_1, | |
a96d9b2e | 12359 | NULL, |
44feb3ce TT |
12360 | (void *) (uintptr_t) catch_vfork_permanent, |
12361 | (void *) (uintptr_t) catch_vfork_temporary); | |
12362 | add_catch_command ("exec", _("Catch calls to exec."), | |
12363 | catch_exec_command_1, | |
a96d9b2e SDJ |
12364 | NULL, |
12365 | CATCH_PERMANENT, | |
12366 | CATCH_TEMPORARY); | |
12367 | add_catch_command ("syscall", _("\ | |
12368 | Catch system calls by their names and/or numbers.\n\ | |
12369 | Arguments say which system calls to catch. If no arguments\n\ | |
12370 | are given, every system call will be caught.\n\ | |
12371 | Arguments, if given, should be one or more system call names\n\ | |
12372 | (if your system supports that), or system call numbers."), | |
12373 | catch_syscall_command_1, | |
12374 | catch_syscall_completer, | |
44feb3ce TT |
12375 | CATCH_PERMANENT, |
12376 | CATCH_TEMPORARY); | |
44feb3ce TT |
12377 | add_catch_command ("exception", _("\ |
12378 | Catch Ada exceptions, when raised.\n\ | |
12379 | With an argument, catch only exceptions with the given name."), | |
12380 | catch_ada_exception_command, | |
a96d9b2e | 12381 | NULL, |
44feb3ce TT |
12382 | CATCH_PERMANENT, |
12383 | CATCH_TEMPORARY); | |
12384 | add_catch_command ("assert", _("\ | |
12385 | Catch failed Ada assertions, when raised.\n\ | |
12386 | With an argument, catch only exceptions with the given name."), | |
12387 | catch_assert_command, | |
a96d9b2e | 12388 | NULL, |
44feb3ce TT |
12389 | CATCH_PERMANENT, |
12390 | CATCH_TEMPORARY); | |
c5aa993b | 12391 | |
1bedd215 AC |
12392 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
12393 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12394 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 12395 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12396 | an expression changes.\n\ |
12397 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12398 | the memory to which it refers.")); | |
65d12d83 | 12399 | set_cmd_completer (c, expression_completer); |
c906108c | 12400 | |
1bedd215 AC |
12401 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
12402 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 12403 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 12404 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12405 | an expression is read.\n\ |
12406 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12407 | the memory to which it refers.")); | |
65d12d83 | 12408 | set_cmd_completer (c, expression_completer); |
c906108c | 12409 | |
1bedd215 AC |
12410 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
12411 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12412 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 12413 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12414 | an expression is either read or written.\n\ |
12415 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12416 | the memory to which it refers.")); | |
65d12d83 | 12417 | set_cmd_completer (c, expression_completer); |
c906108c | 12418 | |
d77f58be SS |
12419 | add_info ("watchpoints", watchpoints_info, _("\ |
12420 | Status of watchpoints, or watchpoint number NUMBER.")); | |
12421 | ||
c906108c SS |
12422 | |
12423 | ||
920d2a44 AC |
12424 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
12425 | respond to changes - contrary to the description. */ | |
85c07804 AC |
12426 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
12427 | &can_use_hw_watchpoints, _("\ | |
12428 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
12429 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
12430 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
12431 | such is available. (However, any hardware watchpoints that were\n\ | |
12432 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
12433 | hardware.)"), |
12434 | NULL, | |
920d2a44 | 12435 | show_can_use_hw_watchpoints, |
85c07804 | 12436 | &setlist, &showlist); |
c906108c SS |
12437 | |
12438 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 12439 | |
1042e4c0 SS |
12440 | /* Tracepoint manipulation commands. */ |
12441 | ||
12442 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
12443 | Set a tracepoint at specified line or function.\n\ | |
12444 | \n" | |
12445 | BREAK_ARGS_HELP ("trace") "\n\ | |
12446 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12447 | set_cmd_completer (c, location_completer); | |
12448 | ||
12449 | add_com_alias ("tp", "trace", class_alias, 0); | |
12450 | add_com_alias ("tr", "trace", class_alias, 1); | |
12451 | add_com_alias ("tra", "trace", class_alias, 1); | |
12452 | add_com_alias ("trac", "trace", class_alias, 1); | |
12453 | ||
7a697b8d SS |
12454 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
12455 | Set a fast tracepoint at specified line or function.\n\ | |
12456 | \n" | |
12457 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
12458 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12459 | set_cmd_completer (c, location_completer); | |
12460 | ||
0fb4aa4b PA |
12461 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
12462 | Set a static tracepoint at specified line, function or marker.\n\ | |
12463 | \n\ | |
12464 | strace [LOCATION] [if CONDITION]\n\ | |
12465 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
12466 | or -m MARKER_ID.\n\ | |
12467 | If a line number is specified, probe the marker at start of code\n\ | |
12468 | for that line. If a function is specified, probe the marker at start\n\ | |
12469 | of code for that function. If an address is specified, probe the marker\n\ | |
12470 | at that exact address. If a marker id is specified, probe the marker\n\ | |
12471 | with that name. With no LOCATION, uses current execution address of\n\ | |
12472 | the selected stack frame.\n\ | |
12473 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
12474 | This collects arbitrary user data passed in the probe point call to the\n\ | |
12475 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
12476 | by printing the $_sdata variable like any other convenience variable.\n\ | |
12477 | \n\ | |
12478 | CONDITION is a boolean expression.\n\ | |
12479 | \n\ | |
d41c0fc8 PA |
12480 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
12481 | conditions are different.\n\ | |
0fb4aa4b PA |
12482 | \n\ |
12483 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
12484 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12485 | set_cmd_completer (c, location_completer); | |
12486 | ||
1042e4c0 SS |
12487 | add_info ("tracepoints", tracepoints_info, _("\ |
12488 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
12489 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
12490 | last tracepoint set.")); | |
12491 | ||
12492 | add_info_alias ("tp", "tracepoints", 1); | |
12493 | ||
12494 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
12495 | Delete specified tracepoints.\n\ | |
12496 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12497 | No argument means delete all tracepoints."), | |
12498 | &deletelist); | |
12499 | ||
12500 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
12501 | Disable specified tracepoints.\n\ | |
12502 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12503 | No argument means disable all tracepoints."), | |
12504 | &disablelist); | |
12505 | deprecate_cmd (c, "disable"); | |
12506 | ||
12507 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
12508 | Enable specified tracepoints.\n\ | |
12509 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12510 | No argument means enable all tracepoints."), | |
12511 | &enablelist); | |
12512 | deprecate_cmd (c, "enable"); | |
12513 | ||
12514 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
12515 | Set the passcount for a tracepoint.\n\ | |
12516 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
12517 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
12518 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
12519 | ||
6149aea9 PA |
12520 | add_prefix_cmd ("save", class_breakpoint, save_command, |
12521 | _("Save breakpoint definitions as a script."), | |
12522 | &save_cmdlist, "save ", | |
12523 | 0/*allow-unknown*/, &cmdlist); | |
12524 | ||
12525 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
12526 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 12527 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
12528 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
12529 | session to restore them."), | |
12530 | &save_cmdlist); | |
12531 | set_cmd_completer (c, filename_completer); | |
12532 | ||
12533 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 12534 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
12535 | Use the 'source' command in another debug session to restore them."), |
12536 | &save_cmdlist); | |
1042e4c0 SS |
12537 | set_cmd_completer (c, filename_completer); |
12538 | ||
6149aea9 PA |
12539 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
12540 | deprecate_cmd (c, "save tracepoints"); | |
12541 | ||
1bedd215 | 12542 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12543 | Breakpoint specific settings\n\ |
12544 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12545 | pending breakpoint behavior"), |
fa8d40ab JJ |
12546 | &breakpoint_set_cmdlist, "set breakpoint ", |
12547 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 12548 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12549 | Breakpoint specific settings\n\ |
12550 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12551 | pending breakpoint behavior"), |
fa8d40ab JJ |
12552 | &breakpoint_show_cmdlist, "show breakpoint ", |
12553 | 0/*allow-unknown*/, &showlist); | |
12554 | ||
7915a72c AC |
12555 | add_setshow_auto_boolean_cmd ("pending", no_class, |
12556 | &pending_break_support, _("\ | |
12557 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
12558 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
12559 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
12560 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
12561 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 12562 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 12563 | NULL, |
920d2a44 | 12564 | show_pending_break_support, |
6e1d7d6c AC |
12565 | &breakpoint_set_cmdlist, |
12566 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
12567 | |
12568 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
12569 | |
12570 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
12571 | &automatic_hardware_breakpoints, _("\ | |
12572 | Set automatic usage of hardware breakpoints."), _("\ | |
12573 | Show automatic usage of hardware breakpoints."), _("\ | |
12574 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
12575 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
12576 | a warning will be emitted for such breakpoints."), | |
12577 | NULL, | |
12578 | show_automatic_hardware_breakpoints, | |
12579 | &breakpoint_set_cmdlist, | |
12580 | &breakpoint_show_cmdlist); | |
74960c60 | 12581 | |
33e5cbd6 PA |
12582 | add_setshow_enum_cmd ("always-inserted", class_support, |
12583 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
12584 | Set mode for inserting breakpoints."), _("\ |
12585 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
12586 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
12587 | resumed, and removed when execution stops. When this mode is on,\n\ | |
12588 | breakpoints are inserted immediately and removed only when the user\n\ | |
12589 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
12590 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
12591 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
12592 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
12593 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
12594 | NULL, |
12595 | &show_always_inserted_mode, | |
12596 | &breakpoint_set_cmdlist, | |
12597 | &breakpoint_show_cmdlist); | |
765dc015 VP |
12598 | |
12599 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
12600 | |
12601 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 12602 | } |