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 | ||
95a42b64 TT |
943 | void |
944 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
945 | { |
946 | struct breakpoint *b = closure; | |
cc59ec59 | 947 | |
a7bdde9e VP |
948 | validate_actionline (&line, b); |
949 | } | |
950 | ||
95a42b64 TT |
951 | /* A structure used to pass information through |
952 | map_breakpoint_numbers. */ | |
953 | ||
954 | struct commands_info | |
955 | { | |
956 | /* True if the command was typed at a tty. */ | |
957 | int from_tty; | |
86b17b60 PA |
958 | |
959 | /* The breakpoint range spec. */ | |
960 | char *arg; | |
961 | ||
95a42b64 TT |
962 | /* Non-NULL if the body of the commands are being read from this |
963 | already-parsed command. */ | |
964 | struct command_line *control; | |
86b17b60 | 965 | |
95a42b64 TT |
966 | /* The command lines read from the user, or NULL if they have not |
967 | yet been read. */ | |
968 | struct counted_command_line *cmd; | |
969 | }; | |
970 | ||
971 | /* A callback for map_breakpoint_numbers that sets the commands for | |
972 | commands_command. */ | |
973 | ||
c906108c | 974 | static void |
95a42b64 | 975 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 976 | { |
95a42b64 | 977 | struct commands_info *info = data; |
c906108c | 978 | |
95a42b64 TT |
979 | if (info->cmd == NULL) |
980 | { | |
981 | struct command_line *l; | |
5c44784c | 982 | |
95a42b64 TT |
983 | if (info->control != NULL) |
984 | l = copy_command_lines (info->control->body_list[0]); | |
985 | else | |
86b17b60 PA |
986 | { |
987 | struct cleanup *old_chain; | |
988 | char *str; | |
c5aa993b | 989 | |
3e43a32a MS |
990 | str = xstrprintf (_("Type commands for breakpoint(s) " |
991 | "%s, one per line."), | |
86b17b60 PA |
992 | info->arg); |
993 | ||
994 | old_chain = make_cleanup (xfree, str); | |
995 | ||
996 | l = read_command_lines (str, | |
997 | info->from_tty, 1, | |
d77f58be | 998 | (is_tracepoint (b) |
86b17b60 PA |
999 | ? check_tracepoint_command : 0), |
1000 | b); | |
1001 | ||
1002 | do_cleanups (old_chain); | |
1003 | } | |
a7bdde9e | 1004 | |
95a42b64 TT |
1005 | info->cmd = alloc_counted_command_line (l); |
1006 | } | |
1007 | ||
1008 | /* If a breakpoint was on the list more than once, we don't need to | |
1009 | do anything. */ | |
1010 | if (b->commands != info->cmd) | |
1011 | { | |
1012 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1013 | incref_counted_command_line (info->cmd); | |
1014 | decref_counted_command_line (&b->commands); | |
1015 | b->commands = info->cmd; | |
1016 | breakpoints_changed (); | |
1017 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 1018 | } |
95a42b64 TT |
1019 | } |
1020 | ||
1021 | static void | |
4a64f543 MS |
1022 | commands_command_1 (char *arg, int from_tty, |
1023 | struct command_line *control) | |
95a42b64 TT |
1024 | { |
1025 | struct cleanup *cleanups; | |
1026 | struct commands_info info; | |
1027 | ||
1028 | info.from_tty = from_tty; | |
1029 | info.control = control; | |
1030 | info.cmd = NULL; | |
1031 | /* If we read command lines from the user, then `info' will hold an | |
1032 | extra reference to the commands that we must clean up. */ | |
1033 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1034 | ||
1035 | if (arg == NULL || !*arg) | |
1036 | { | |
86b17b60 | 1037 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
1038 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
1039 | breakpoint_count); | |
95a42b64 TT |
1040 | else if (breakpoint_count > 0) |
1041 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1042 | else |
1043 | { | |
1044 | /* So that we don't try to free the incoming non-NULL | |
1045 | argument in the cleanup below. Mapping breakpoint | |
1046 | numbers will fail in this case. */ | |
1047 | arg = NULL; | |
1048 | } | |
95a42b64 | 1049 | } |
9766ced4 SS |
1050 | else |
1051 | /* The command loop has some static state, so we need to preserve | |
1052 | our argument. */ | |
1053 | arg = xstrdup (arg); | |
86b17b60 PA |
1054 | |
1055 | if (arg != NULL) | |
1056 | make_cleanup (xfree, arg); | |
1057 | ||
1058 | info.arg = arg; | |
95a42b64 TT |
1059 | |
1060 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1061 | ||
1062 | if (info.cmd == NULL) | |
1063 | error (_("No breakpoints specified.")); | |
1064 | ||
1065 | do_cleanups (cleanups); | |
1066 | } | |
1067 | ||
1068 | static void | |
1069 | commands_command (char *arg, int from_tty) | |
1070 | { | |
1071 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1072 | } |
40c03ae8 EZ |
1073 | |
1074 | /* Like commands_command, but instead of reading the commands from | |
1075 | input stream, takes them from an already parsed command structure. | |
1076 | ||
1077 | This is used by cli-script.c to DTRT with breakpoint commands | |
1078 | that are part of if and while bodies. */ | |
1079 | enum command_control_type | |
1080 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1081 | { | |
95a42b64 TT |
1082 | commands_command_1 (arg, 0, cmd); |
1083 | return simple_control; | |
40c03ae8 | 1084 | } |
876fa593 JK |
1085 | |
1086 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1087 | ||
1088 | static int | |
1089 | bp_location_has_shadow (struct bp_location *bl) | |
1090 | { | |
1091 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1092 | return 0; | |
1093 | if (!bl->inserted) | |
1094 | return 0; | |
1095 | if (bl->target_info.shadow_len == 0) | |
1096 | /* bp isn't valid, or doesn't shadow memory. */ | |
1097 | return 0; | |
1098 | return 1; | |
1099 | } | |
1100 | ||
8defab1a | 1101 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1102 | by replacing any memory breakpoints with their shadowed contents. |
1103 | ||
1104 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1105 | bl->address - bp_location_placed_address_before_address_max |
1106 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1107 | The range we were requested to resolve shadows for is: |
1108 | memaddr ... memaddr + len | |
1109 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1110 | memaddr + len <= (bl->address |
1111 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1112 | and: |
35df4500 | 1113 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1114 | |
8defab1a DJ |
1115 | void |
1116 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1117 | { |
4a64f543 MS |
1118 | /* Left boundary, right boundary and median element of our binary |
1119 | search. */ | |
876fa593 JK |
1120 | unsigned bc_l, bc_r, bc; |
1121 | ||
4a64f543 MS |
1122 | /* Find BC_L which is a leftmost element which may affect BUF |
1123 | content. It is safe to report lower value but a failure to | |
1124 | report higher one. */ | |
876fa593 JK |
1125 | |
1126 | bc_l = 0; | |
1127 | bc_r = bp_location_count; | |
1128 | while (bc_l + 1 < bc_r) | |
1129 | { | |
35df4500 | 1130 | struct bp_location *bl; |
876fa593 JK |
1131 | |
1132 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1133 | bl = bp_location[bc]; |
876fa593 | 1134 | |
4a64f543 MS |
1135 | /* Check first BL->ADDRESS will not overflow due to the added |
1136 | constant. Then advance the left boundary only if we are sure | |
1137 | the BC element can in no way affect the BUF content (MEMADDR | |
1138 | to MEMADDR + LEN range). | |
876fa593 | 1139 | |
4a64f543 MS |
1140 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1141 | offset so that we cannot miss a breakpoint with its shadow | |
1142 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1143 | |
35df4500 TJB |
1144 | if ((bl->address + bp_location_shadow_len_after_address_max |
1145 | >= bl->address) | |
1146 | && (bl->address + bp_location_shadow_len_after_address_max | |
1147 | <= memaddr)) | |
876fa593 JK |
1148 | bc_l = bc; |
1149 | else | |
1150 | bc_r = bc; | |
1151 | } | |
1152 | ||
128070bb PA |
1153 | /* Due to the binary search above, we need to make sure we pick the |
1154 | first location that's at BC_L's address. E.g., if there are | |
1155 | multiple locations at the same address, BC_L may end up pointing | |
1156 | at a duplicate location, and miss the "master"/"inserted" | |
1157 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1158 | B: | |
1159 | ||
1160 | L1@A, L2@A, L3@B, ... | |
1161 | ||
1162 | BC_L could end up pointing at location L2, while the "master" | |
1163 | location could be L1. Since the `loc->inserted' flag is only set | |
1164 | on "master" locations, we'd forget to restore the shadow of L1 | |
1165 | and L2. */ | |
1166 | while (bc_l > 0 | |
1167 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1168 | bc_l--; | |
1169 | ||
876fa593 JK |
1170 | /* Now do full processing of the found relevant range of elements. */ |
1171 | ||
1172 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1173 | { |
35df4500 | 1174 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1175 | CORE_ADDR bp_addr = 0; |
1176 | int bp_size = 0; | |
1177 | int bptoffset = 0; | |
1178 | ||
35df4500 TJB |
1179 | /* bp_location array has BL->OWNER always non-NULL. */ |
1180 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1181 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1182 | bl->owner->number); |
ffce0d52 | 1183 | |
876fa593 JK |
1184 | /* Performance optimization: any futher element can no longer affect BUF |
1185 | content. */ | |
1186 | ||
35df4500 TJB |
1187 | if (bl->address >= bp_location_placed_address_before_address_max |
1188 | && memaddr + len <= (bl->address | |
1189 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1190 | break; |
1191 | ||
35df4500 | 1192 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1193 | continue; |
35df4500 | 1194 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1195 | current_program_space->aspace, 0)) |
1196 | continue; | |
1197 | ||
c5aa993b JM |
1198 | /* Addresses and length of the part of the breakpoint that |
1199 | we need to copy. */ | |
35df4500 TJB |
1200 | bp_addr = bl->target_info.placed_address; |
1201 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1202 | |
c5aa993b JM |
1203 | if (bp_addr + bp_size <= memaddr) |
1204 | /* The breakpoint is entirely before the chunk of memory we | |
1205 | are reading. */ | |
1206 | continue; | |
8defab1a | 1207 | |
c5aa993b JM |
1208 | if (bp_addr >= memaddr + len) |
1209 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1210 | reading. */ |
c5aa993b | 1211 | continue; |
c5aa993b | 1212 | |
8defab1a DJ |
1213 | /* Offset within shadow_contents. */ |
1214 | if (bp_addr < memaddr) | |
1215 | { | |
1216 | /* Only copy the second part of the breakpoint. */ | |
1217 | bp_size -= memaddr - bp_addr; | |
1218 | bptoffset = memaddr - bp_addr; | |
1219 | bp_addr = memaddr; | |
1220 | } | |
c5aa993b | 1221 | |
8defab1a DJ |
1222 | if (bp_addr + bp_size > memaddr + len) |
1223 | { | |
1224 | /* Only copy the first part of the breakpoint. */ | |
1225 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1226 | } | |
c5aa993b | 1227 | |
8defab1a | 1228 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1229 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1230 | } |
c906108c | 1231 | } |
c906108c | 1232 | \f |
c5aa993b | 1233 | |
60e1c644 PA |
1234 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1235 | ||
a5606eee | 1236 | static int |
d77f58be | 1237 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1238 | { |
1239 | return (bpt->type == bp_hardware_watchpoint | |
1240 | || bpt->type == bp_read_watchpoint | |
1241 | || bpt->type == bp_access_watchpoint); | |
1242 | } | |
7270d8f2 | 1243 | |
60e1c644 PA |
1244 | /* Return true if BPT is of any watchpoint kind, hardware or |
1245 | software. */ | |
1246 | ||
1247 | static int | |
d77f58be | 1248 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1249 | { |
1250 | return (is_hardware_watchpoint (bpt) | |
1251 | || bpt->type == bp_watchpoint); | |
1252 | } | |
1253 | ||
f6bc2008 PA |
1254 | /* Assuming that B is a watchpoint: returns true if the current thread |
1255 | and its running state are safe to evaluate or update watchpoint B. | |
1256 | Watchpoints on local expressions need to be evaluated in the | |
1257 | context of the thread that was current when the watchpoint was | |
1258 | created, and, that thread needs to be stopped to be able to select | |
1259 | the correct frame context. Watchpoints on global expressions can | |
1260 | be evaluated on any thread, and in any state. It is presently left | |
1261 | to the target allowing memory accesses when threads are | |
1262 | running. */ | |
1263 | ||
1264 | static int | |
1265 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1266 | { | |
1267 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1268 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1269 | && !is_executing (inferior_ptid))); | |
1270 | } | |
1271 | ||
567e1b4e JB |
1272 | /* Assuming that B is a watchpoint: |
1273 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1274 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1275 | - Evaluate the condition if there is one, and store the result |
1276 | in b->loc->cond. | |
a5606eee VP |
1277 | - Update the list of values that must be watched in B->loc. |
1278 | ||
4a64f543 MS |
1279 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1280 | nothing. If this is local watchpoint that is out of scope, delete | |
1281 | it. | |
1282 | ||
1283 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1284 | removed + inserted on each stop here. Normal breakpoints must | |
1285 | never be removed because they might be missed by a running thread | |
1286 | when debugging in non-stop mode. On the other hand, hardware | |
1287 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1288 | to each LWP since they are stored in each LWP's hardware debug | |
1289 | registers. Therefore, such LWP must be stopped first in order to | |
1290 | be able to modify its hardware watchpoints. | |
1291 | ||
1292 | Hardware watchpoints must be reset exactly once after being | |
1293 | presented to the user. It cannot be done sooner, because it would | |
1294 | reset the data used to present the watchpoint hit to the user. And | |
1295 | it must not be done later because it could display the same single | |
1296 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1297 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1298 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1299 | not user-visible - its hit is suppressed if the memory content has | |
1300 | not changed. | |
1301 | ||
1302 | The following constraints influence the location where we can reset | |
1303 | hardware watchpoints: | |
1304 | ||
1305 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1306 | called several times when GDB stops. | |
1307 | ||
1308 | [linux] | |
1309 | * Multiple hardware watchpoints can be hit at the same time, | |
1310 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1311 | hit at a time as the reason for stopping, and all the other hits | |
1312 | are presented later, one after the other, each time the user | |
1313 | requests the execution to be resumed. Execution is not resumed | |
1314 | for the threads still having pending hit event stored in | |
1315 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1316 | the inferior on the first stop the thread hit event is kept being | |
1317 | reported from its cached value by linux_nat_stopped_data_address | |
1318 | until the real thread resume happens after the watchpoint gets | |
1319 | presented and thus its LWP_INFO->STATUS gets reset. | |
1320 | ||
1321 | Therefore the hardware watchpoint hit can get safely reset on the | |
1322 | watchpoint removal from inferior. */ | |
a79d3c27 | 1323 | |
b40ce68a | 1324 | static void |
a5606eee | 1325 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1326 | { |
a5606eee | 1327 | int within_current_scope; |
a5606eee | 1328 | struct frame_id saved_frame_id; |
66076460 | 1329 | int frame_saved; |
a5606eee | 1330 | |
f6bc2008 PA |
1331 | /* If this is a local watchpoint, we only want to check if the |
1332 | watchpoint frame is in scope if the current thread is the thread | |
1333 | that was used to create the watchpoint. */ | |
1334 | if (!watchpoint_in_thread_scope (b)) | |
1335 | return; | |
1336 | ||
4a64f543 MS |
1337 | /* We don't free locations. They are stored in bp_location array |
1338 | and update_global_locations will eventually delete them and | |
1339 | remove breakpoints if needed. */ | |
a5606eee VP |
1340 | b->loc = NULL; |
1341 | ||
1342 | if (b->disposition == disp_del_at_next_stop) | |
1343 | return; | |
1344 | ||
66076460 | 1345 | frame_saved = 0; |
a5606eee VP |
1346 | |
1347 | /* Determine if the watchpoint is within scope. */ | |
1348 | if (b->exp_valid_block == NULL) | |
1349 | within_current_scope = 1; | |
1350 | else | |
1351 | { | |
1352 | struct frame_info *fi; | |
66076460 DJ |
1353 | |
1354 | /* Save the current frame's ID so we can restore it after | |
1355 | evaluating the watchpoint expression on its own frame. */ | |
1356 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1357 | took a frame parameter, so that we didn't have to change the | |
1358 | selected frame. */ | |
1359 | frame_saved = 1; | |
1360 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1361 | ||
a5606eee VP |
1362 | fi = frame_find_by_id (b->watchpoint_frame); |
1363 | within_current_scope = (fi != NULL); | |
1364 | if (within_current_scope) | |
1365 | select_frame (fi); | |
1366 | } | |
1367 | ||
1368 | if (within_current_scope && reparse) | |
1369 | { | |
1370 | char *s; | |
d63d0675 | 1371 | |
a5606eee VP |
1372 | if (b->exp) |
1373 | { | |
1374 | xfree (b->exp); | |
1375 | b->exp = NULL; | |
1376 | } | |
d63d0675 | 1377 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1378 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1379 | /* If the meaning of expression itself changed, the old value is | |
1380 | no longer relevant. We don't want to report a watchpoint hit | |
1381 | to the user when the old value and the new value may actually | |
1382 | be completely different objects. */ | |
1383 | value_free (b->val); | |
fa4727a6 DJ |
1384 | b->val = NULL; |
1385 | b->val_valid = 0; | |
60e1c644 PA |
1386 | |
1387 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1388 | expression is stored in the breakpoint object, not in the | |
1389 | locations (re)created below. */ | |
1390 | if (b->cond_string != NULL) | |
1391 | { | |
1392 | if (b->cond_exp != NULL) | |
1393 | { | |
1394 | xfree (b->cond_exp); | |
1395 | b->cond_exp = NULL; | |
1396 | } | |
1397 | ||
1398 | s = b->cond_string; | |
1399 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1400 | } | |
a5606eee | 1401 | } |
a5606eee VP |
1402 | |
1403 | /* If we failed to parse the expression, for example because | |
1404 | it refers to a global variable in a not-yet-loaded shared library, | |
1405 | don't try to insert watchpoint. We don't automatically delete | |
1406 | such watchpoint, though, since failure to parse expression | |
1407 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1408 | if ( !target_has_execution) |
1409 | { | |
1410 | /* Without execution, memory can't change. No use to try and | |
1411 | set watchpoint locations. The watchpoint will be reset when | |
1412 | the target gains execution, through breakpoint_re_set. */ | |
1413 | } | |
1414 | else if (within_current_scope && b->exp) | |
a5606eee | 1415 | { |
0cf6dd15 | 1416 | int pc = 0; |
fa4727a6 | 1417 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1418 | struct program_space *frame_pspace; |
a5606eee | 1419 | |
0cf6dd15 | 1420 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1421 | |
a5606eee VP |
1422 | /* Avoid setting b->val if it's already set. The meaning of |
1423 | b->val is 'the last value' user saw, and we should update | |
1424 | it only if we reported that last value to user. As it | |
1425 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1426 | if (!b->val_valid) |
1427 | { | |
1428 | b->val = v; | |
1429 | b->val_valid = 1; | |
1430 | } | |
a5606eee | 1431 | |
2d134ed3 PA |
1432 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1433 | ||
a5606eee | 1434 | /* Look at each value on the value chain. */ |
9fa40276 | 1435 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1436 | { |
1437 | /* If it's a memory location, and GDB actually needed | |
1438 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1439 | must watch it. If the first value returned is |
1440 | still lazy, that means an error occurred reading it; | |
1441 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1442 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1443 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1444 | { |
1445 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1446 | |
a5606eee VP |
1447 | /* We only watch structs and arrays if user asked |
1448 | for it explicitly, never if they just happen to | |
1449 | appear in the middle of some value chain. */ | |
fa4727a6 | 1450 | if (v == result |
a5606eee VP |
1451 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1452 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1453 | { | |
1454 | CORE_ADDR addr; | |
1455 | int len, type; | |
1456 | struct bp_location *loc, **tmp; | |
1457 | ||
42ae5230 | 1458 | addr = value_address (v); |
a5606eee VP |
1459 | len = TYPE_LENGTH (value_type (v)); |
1460 | type = hw_write; | |
1461 | if (b->type == bp_read_watchpoint) | |
1462 | type = hw_read; | |
1463 | else if (b->type == bp_access_watchpoint) | |
1464 | type = hw_access; | |
1465 | ||
39d61571 | 1466 | loc = allocate_bp_location (b); |
a5606eee VP |
1467 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1468 | ; | |
1469 | *tmp = loc; | |
a6d9a66e | 1470 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1471 | |
1472 | loc->pspace = frame_pspace; | |
a5606eee VP |
1473 | loc->address = addr; |
1474 | loc->length = len; | |
1475 | loc->watchpoint_type = type; | |
1476 | } | |
1477 | } | |
9fa40276 TJB |
1478 | } |
1479 | ||
1480 | /* Change the type of breakpoint between hardware assisted or | |
1481 | an ordinary watchpoint depending on the hardware support | |
1482 | and free hardware slots. REPARSE is set when the inferior | |
1483 | is started. */ | |
1484 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1485 | && reparse) | |
1486 | { | |
e09342b5 | 1487 | int reg_cnt; |
9fa40276 TJB |
1488 | enum bp_loc_type loc_type; |
1489 | struct bp_location *bl; | |
a5606eee | 1490 | |
e09342b5 TJB |
1491 | reg_cnt = can_use_hardware_watchpoint (val_chain, b->exact); |
1492 | ||
1493 | if (reg_cnt) | |
9fa40276 TJB |
1494 | { |
1495 | int i, target_resources_ok, other_type_used; | |
e09342b5 | 1496 | enum enable_state orig_enable_state; |
9fa40276 TJB |
1497 | |
1498 | /* We need to determine how many resources are already | |
e09342b5 TJB |
1499 | used for all other hardware watchpoints plus this one |
1500 | to see if we still have enough resources to also fit | |
1501 | this watchpoint in as well. To guarantee the | |
1502 | hw_watchpoint_used_count call below counts this | |
1503 | watchpoint, make sure that it is marked as a hardware | |
1504 | watchpoint. */ | |
1505 | b->type = bp_hardware_watchpoint; | |
1506 | ||
1507 | /* hw_watchpoint_used_count ignores disabled watchpoints, | |
1508 | and b might be disabled if we're being called from | |
1509 | do_enable_breakpoint. */ | |
1510 | orig_enable_state = b->enable_state; | |
1511 | b->enable_state = bp_enabled; | |
1512 | ||
9fa40276 TJB |
1513 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1514 | &other_type_used); | |
9fa40276 | 1515 | |
e09342b5 TJB |
1516 | b->enable_state = orig_enable_state; |
1517 | ||
1518 | target_resources_ok = target_can_use_hardware_watchpoint | |
1519 | (bp_hardware_watchpoint, i, other_type_used); | |
1520 | if (target_resources_ok <= 0) | |
1521 | b->type = bp_watchpoint; | |
9fa40276 TJB |
1522 | } |
1523 | else | |
1524 | b->type = bp_watchpoint; | |
1525 | ||
1526 | loc_type = (b->type == bp_watchpoint? bp_loc_other | |
1527 | : bp_loc_hardware_watchpoint); | |
1528 | for (bl = b->loc; bl; bl = bl->next) | |
1529 | bl->loc_type = loc_type; | |
1530 | } | |
1531 | ||
1532 | for (v = val_chain; v; v = next) | |
1533 | { | |
a5606eee VP |
1534 | next = value_next (v); |
1535 | if (v != b->val) | |
1536 | value_free (v); | |
1537 | } | |
1538 | ||
c7437ca6 PA |
1539 | /* If a software watchpoint is not watching any memory, then the |
1540 | above left it without any location set up. But, | |
1541 | bpstat_stop_status requires a location to be able to report | |
1542 | stops, so make sure there's at least a dummy one. */ | |
1543 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1544 | { | |
1545 | b->loc = allocate_bp_location (b); | |
1546 | b->loc->pspace = frame_pspace; | |
1547 | b->loc->address = -1; | |
1548 | b->loc->length = -1; | |
1549 | b->loc->watchpoint_type = -1; | |
1550 | } | |
a5606eee VP |
1551 | } |
1552 | else if (!within_current_scope) | |
7270d8f2 | 1553 | { |
ac74f770 MS |
1554 | printf_filtered (_("\ |
1555 | Watchpoint %d deleted because the program has left the block\n\ | |
1556 | in which its expression is valid.\n"), | |
a5606eee VP |
1557 | b->number); |
1558 | if (b->related_breakpoint) | |
60e1c644 PA |
1559 | { |
1560 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1561 | b->related_breakpoint->related_breakpoint = NULL; | |
1562 | b->related_breakpoint= NULL; | |
1563 | } | |
a5606eee | 1564 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1565 | } |
a5606eee VP |
1566 | |
1567 | /* Restore the selected frame. */ | |
66076460 DJ |
1568 | if (frame_saved) |
1569 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1570 | } |
1571 | ||
a5606eee | 1572 | |
74960c60 VP |
1573 | /* Returns 1 iff breakpoint location should be |
1574 | inserted in the inferior. */ | |
1575 | static int | |
35df4500 | 1576 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1577 | { |
35df4500 | 1578 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1579 | return 0; |
1580 | ||
35df4500 | 1581 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1582 | return 0; |
1583 | ||
35df4500 | 1584 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1585 | return 0; |
1586 | ||
56710373 PA |
1587 | /* This is set for example, when we're attached to the parent of a |
1588 | vfork, and have detached from the child. The child is running | |
1589 | free, and we expect it to do an exec or exit, at which point the | |
1590 | OS makes the parent schedulable again (and the target reports | |
1591 | that the vfork is done). Until the child is done with the shared | |
1592 | memory region, do not insert breakpoints in the parent, otherwise | |
1593 | the child could still trip on the parent's breakpoints. Since | |
1594 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1595 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1596 | return 0; |
1597 | ||
1042e4c0 SS |
1598 | /* Tracepoints are inserted by the target at a time of its choosing, |
1599 | not by us. */ | |
35df4500 | 1600 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1601 | return 0; |
1602 | ||
74960c60 VP |
1603 | return 1; |
1604 | } | |
1605 | ||
35df4500 TJB |
1606 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1607 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
1608 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. | |
879bfdc2 | 1609 | |
4a64f543 MS |
1610 | NOTE drow/2003-09-09: This routine could be broken down to an |
1611 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1612 | static int |
35df4500 | 1613 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1614 | struct ui_file *tmp_error_stream, |
fa3a767f | 1615 | int *disabled_breaks, |
26bb91f3 | 1616 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1617 | { |
1618 | int val = 0; | |
1619 | ||
35df4500 | 1620 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1621 | return 0; |
1622 | ||
8181d85f | 1623 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1624 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1625 | bl->target_info.placed_address = bl->address; | |
1626 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
8181d85f | 1627 | |
35df4500 TJB |
1628 | if (bl->loc_type == bp_loc_software_breakpoint |
1629 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1630 | { |
35df4500 | 1631 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1632 | { |
1633 | /* If the explicitly specified breakpoint type | |
1634 | is not hardware breakpoint, check the memory map to see | |
1635 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1636 | |
765dc015 VP |
1637 | Two important cases are: |
1638 | - location type is not hardware breakpoint, memory | |
1639 | is readonly. We change the type of the location to | |
1640 | hardware breakpoint. | |
4a64f543 MS |
1641 | - location type is hardware breakpoint, memory is |
1642 | read-write. This means we've previously made the | |
1643 | location hardware one, but then the memory map changed, | |
1644 | so we undo. | |
765dc015 | 1645 | |
4a64f543 MS |
1646 | When breakpoints are removed, remove_breakpoints will use |
1647 | location types we've just set here, the only possible | |
1648 | problem is that memory map has changed during running | |
1649 | program, but it's not going to work anyway with current | |
1650 | gdb. */ | |
765dc015 | 1651 | struct mem_region *mr |
35df4500 | 1652 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1653 | |
1654 | if (mr) | |
1655 | { | |
1656 | if (automatic_hardware_breakpoints) | |
1657 | { | |
765dc015 VP |
1658 | enum bp_loc_type new_type; |
1659 | ||
1660 | if (mr->attrib.mode != MEM_RW) | |
1661 | new_type = bp_loc_hardware_breakpoint; | |
1662 | else | |
1663 | new_type = bp_loc_software_breakpoint; | |
1664 | ||
35df4500 | 1665 | if (new_type != bl->loc_type) |
765dc015 VP |
1666 | { |
1667 | static int said = 0; | |
cc59ec59 | 1668 | |
35df4500 | 1669 | bl->loc_type = new_type; |
765dc015 VP |
1670 | if (!said) |
1671 | { | |
3e43a32a MS |
1672 | fprintf_filtered (gdb_stdout, |
1673 | _("Note: automatically using " | |
1674 | "hardware breakpoints for " | |
1675 | "read-only addresses.\n")); | |
765dc015 VP |
1676 | said = 1; |
1677 | } | |
1678 | } | |
1679 | } | |
35df4500 | 1680 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1681 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1682 | warning (_("cannot set software breakpoint " |
1683 | "at readonly address %s"), | |
35df4500 | 1684 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1685 | } |
1686 | } | |
1687 | ||
879bfdc2 DJ |
1688 | /* First check to see if we have to handle an overlay. */ |
1689 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1690 | || bl->section == NULL |
1691 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1692 | { |
1693 | /* No overlay handling: just set the breakpoint. */ | |
1694 | ||
35df4500 TJB |
1695 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1696 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1697 | &bl->target_info); | |
879bfdc2 | 1698 | else |
35df4500 TJB |
1699 | val = target_insert_breakpoint (bl->gdbarch, |
1700 | &bl->target_info); | |
879bfdc2 DJ |
1701 | } |
1702 | else | |
1703 | { | |
4a64f543 | 1704 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1705 | Shall we set a breakpoint at the LMA? */ |
1706 | if (!overlay_events_enabled) | |
1707 | { | |
1708 | /* Yes -- overlay event support is not active, | |
1709 | so we must try to set a breakpoint at the LMA. | |
1710 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1711 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1712 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1713 | bl->owner->number); |
879bfdc2 DJ |
1714 | else |
1715 | { | |
35df4500 TJB |
1716 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1717 | bl->section); | |
879bfdc2 | 1718 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1719 | bl->overlay_target_info = bl->target_info; |
1720 | bl->overlay_target_info.placed_address = addr; | |
1721 | val = target_insert_breakpoint (bl->gdbarch, | |
1722 | &bl->overlay_target_info); | |
879bfdc2 | 1723 | if (val != 0) |
99361f52 | 1724 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1725 | "Overlay breakpoint %d " |
1726 | "failed: in ROM?\n", | |
35df4500 | 1727 | bl->owner->number); |
879bfdc2 DJ |
1728 | } |
1729 | } | |
1730 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1731 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1732 | { |
1733 | /* Yes. This overlay section is mapped into memory. */ | |
35df4500 TJB |
1734 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1735 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1736 | &bl->target_info); | |
879bfdc2 | 1737 | else |
35df4500 TJB |
1738 | val = target_insert_breakpoint (bl->gdbarch, |
1739 | &bl->target_info); | |
879bfdc2 DJ |
1740 | } |
1741 | else | |
1742 | { | |
1743 | /* No. This breakpoint will not be inserted. | |
1744 | No error, but do not mark the bp as 'inserted'. */ | |
1745 | return 0; | |
1746 | } | |
1747 | } | |
1748 | ||
1749 | if (val) | |
1750 | { | |
1751 | /* Can't set the breakpoint. */ | |
35df4500 | 1752 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1753 | { |
4a64f543 | 1754 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1755 | val = 0; |
35df4500 | 1756 | bl->shlib_disabled = 1; |
879bfdc2 DJ |
1757 | if (!*disabled_breaks) |
1758 | { | |
1759 | fprintf_unfiltered (tmp_error_stream, | |
1760 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1761 | bl->owner->number); |
879bfdc2 | 1762 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1763 | "Temporarily disabling shared " |
1764 | "library breakpoints:\n"); | |
879bfdc2 DJ |
1765 | } |
1766 | *disabled_breaks = 1; | |
1767 | fprintf_unfiltered (tmp_error_stream, | |
35df4500 | 1768 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1769 | } |
1770 | else | |
879bfdc2 | 1771 | { |
35df4500 | 1772 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1773 | { |
1774 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1775 | fprintf_unfiltered (tmp_error_stream, |
1776 | "Cannot insert hardware " | |
1777 | "breakpoint %d.\n", | |
35df4500 | 1778 | bl->owner->number); |
879bfdc2 DJ |
1779 | } |
1780 | else | |
1781 | { | |
1782 | fprintf_unfiltered (tmp_error_stream, | |
1783 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1784 | bl->owner->number); |
879bfdc2 DJ |
1785 | fprintf_filtered (tmp_error_stream, |
1786 | "Error accessing memory address "); | |
35df4500 | 1787 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1788 | tmp_error_stream); |
879bfdc2 DJ |
1789 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1790 | safe_strerror (val)); | |
1791 | } | |
1792 | ||
1793 | } | |
1794 | } | |
1795 | else | |
35df4500 | 1796 | bl->inserted = 1; |
879bfdc2 DJ |
1797 | |
1798 | return val; | |
1799 | } | |
1800 | ||
35df4500 | 1801 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1802 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1803 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1804 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1805 | { |
77b06cd7 TJB |
1806 | gdb_assert (bl->owner->ops != NULL |
1807 | && bl->owner->ops->insert_location != NULL); | |
1808 | ||
1809 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1810 | |
1811 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1812 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1813 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1814 | { |
1815 | struct bp_location *loc, **loc_temp; | |
1816 | ||
1817 | /* But don't try to insert it, if there's already another | |
1818 | hw_access location that would be considered a duplicate | |
1819 | of this one. */ | |
1820 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1821 | if (loc != bl |
85d721b8 | 1822 | && loc->watchpoint_type == hw_access |
35df4500 | 1823 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1824 | { |
35df4500 TJB |
1825 | bl->duplicate = 1; |
1826 | bl->inserted = 1; | |
1827 | bl->target_info = loc->target_info; | |
1828 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1829 | val = 0; |
1830 | break; | |
1831 | } | |
1832 | ||
1833 | if (val == 1) | |
1834 | { | |
77b06cd7 TJB |
1835 | bl->watchpoint_type = hw_access; |
1836 | val = bl->owner->ops->insert_location (bl); | |
1837 | ||
1838 | if (val) | |
1839 | /* Back to the original value. */ | |
1840 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1841 | } |
1842 | } | |
1843 | ||
35df4500 | 1844 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1845 | } |
1846 | ||
35df4500 | 1847 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1848 | { |
77b06cd7 TJB |
1849 | gdb_assert (bl->owner->ops != NULL |
1850 | && bl->owner->ops->insert_location != NULL); | |
1851 | ||
1852 | val = bl->owner->ops->insert_location (bl); | |
1853 | if (val) | |
1854 | { | |
1855 | bl->owner->enable_state = bp_disabled; | |
1856 | ||
1857 | if (val == 1) | |
1858 | warning (_("\ | |
1859 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1860 | of catchpoint."), bl->owner->number); | |
1861 | else | |
1862 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1863 | } | |
1864 | ||
1865 | bl->inserted = (val == 0); | |
1640b821 DJ |
1866 | |
1867 | /* We've already printed an error message if there was a problem | |
1868 | inserting this catchpoint, and we've disabled the catchpoint, | |
1869 | so just return success. */ | |
1870 | return 0; | |
879bfdc2 DJ |
1871 | } |
1872 | ||
1873 | return 0; | |
1874 | } | |
1875 | ||
6c95b8df PA |
1876 | /* This function is called when program space PSPACE is about to be |
1877 | deleted. It takes care of updating breakpoints to not reference | |
1878 | PSPACE anymore. */ | |
1879 | ||
1880 | void | |
1881 | breakpoint_program_space_exit (struct program_space *pspace) | |
1882 | { | |
1883 | struct breakpoint *b, *b_temp; | |
876fa593 | 1884 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1885 | |
1886 | /* Remove any breakpoint that was set through this program space. */ | |
1887 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1888 | { | |
1889 | if (b->pspace == pspace) | |
1890 | delete_breakpoint (b); | |
1891 | } | |
1892 | ||
1893 | /* Breakpoints set through other program spaces could have locations | |
1894 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1895 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1896 | { |
1897 | struct bp_location *tmp; | |
1898 | ||
1899 | if (loc->pspace == pspace) | |
1900 | { | |
2bdf28a0 | 1901 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1902 | if (loc->owner->loc == loc) |
1903 | loc->owner->loc = loc->next; | |
1904 | else | |
1905 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1906 | if (tmp->next == loc) | |
1907 | { | |
1908 | tmp->next = loc->next; | |
1909 | break; | |
1910 | } | |
1911 | } | |
1912 | } | |
1913 | ||
1914 | /* Now update the global location list to permanently delete the | |
1915 | removed locations above. */ | |
1916 | update_global_location_list (0); | |
1917 | } | |
1918 | ||
74960c60 VP |
1919 | /* Make sure all breakpoints are inserted in inferior. |
1920 | Throws exception on any error. | |
1921 | A breakpoint that is already inserted won't be inserted | |
1922 | again, so calling this function twice is safe. */ | |
1923 | void | |
1924 | insert_breakpoints (void) | |
1925 | { | |
1926 | struct breakpoint *bpt; | |
1927 | ||
1928 | ALL_BREAKPOINTS (bpt) | |
1929 | if (is_hardware_watchpoint (bpt)) | |
4a64f543 | 1930 | update_watchpoint (bpt, 0 /* don't reparse. */); |
74960c60 | 1931 | |
b60e7edf | 1932 | update_global_location_list (1); |
74960c60 | 1933 | |
c35b1492 PA |
1934 | /* update_global_location_list does not insert breakpoints when |
1935 | always_inserted_mode is not enabled. Explicitly insert them | |
1936 | now. */ | |
1937 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1938 | insert_breakpoint_locations (); |
1939 | } | |
1940 | ||
c906108c SS |
1941 | /* insert_breakpoints is used when starting or continuing the program. |
1942 | remove_breakpoints is used when the program stops. | |
1943 | Both return zero if successful, | |
1944 | or an `errno' value if could not write the inferior. */ | |
1945 | ||
74960c60 VP |
1946 | static void |
1947 | insert_breakpoint_locations (void) | |
c906108c | 1948 | { |
a5606eee | 1949 | struct breakpoint *bpt; |
35df4500 | 1950 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1951 | int error = 0; |
c906108c SS |
1952 | int val = 0; |
1953 | int disabled_breaks = 0; | |
81d0cc19 | 1954 | int hw_breakpoint_error = 0; |
c906108c | 1955 | |
81d0cc19 | 1956 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1957 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1958 | |
81d0cc19 GS |
1959 | /* Explicitly mark the warning -- this will only be printed if |
1960 | there was an error. */ | |
1961 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1962 | |
1963 | save_current_space_and_thread (); | |
1964 | ||
35df4500 | 1965 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1966 | { |
35df4500 | 1967 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1968 | continue; |
1969 | ||
4a64f543 MS |
1970 | /* There is no point inserting thread-specific breakpoints if |
1971 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1972 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1973 | if (bl->owner->thread != -1 |
1974 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1975 | continue; |
1976 | ||
35df4500 | 1977 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1978 | |
1979 | /* For targets that support global breakpoints, there's no need | |
1980 | to select an inferior to insert breakpoint to. In fact, even | |
1981 | if we aren't attached to any process yet, we should still | |
1982 | insert breakpoints. */ | |
1983 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1984 | && ptid_equal (inferior_ptid, null_ptid)) | |
1985 | continue; | |
1986 | ||
35df4500 | 1987 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
879bfdc2 DJ |
1988 | &hw_breakpoint_error); |
1989 | if (val) | |
e236ba44 | 1990 | error = val; |
879bfdc2 | 1991 | } |
c906108c | 1992 | |
4a64f543 MS |
1993 | /* If we failed to insert all locations of a watchpoint, remove |
1994 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1995 | ALL_BREAKPOINTS (bpt) |
1996 | { | |
1997 | int some_failed = 0; | |
1998 | struct bp_location *loc; | |
1999 | ||
2000 | if (!is_hardware_watchpoint (bpt)) | |
2001 | continue; | |
2002 | ||
d6b74ac4 | 2003 | if (!breakpoint_enabled (bpt)) |
a5606eee | 2004 | continue; |
74960c60 VP |
2005 | |
2006 | if (bpt->disposition == disp_del_at_next_stop) | |
2007 | continue; | |
a5606eee VP |
2008 | |
2009 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 2010 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
2011 | { |
2012 | some_failed = 1; | |
2013 | break; | |
2014 | } | |
2015 | if (some_failed) | |
2016 | { | |
2017 | for (loc = bpt->loc; loc; loc = loc->next) | |
2018 | if (loc->inserted) | |
2019 | remove_breakpoint (loc, mark_uninserted); | |
2020 | ||
2021 | hw_breakpoint_error = 1; | |
2022 | fprintf_unfiltered (tmp_error_stream, | |
2023 | "Could not insert hardware watchpoint %d.\n", | |
2024 | bpt->number); | |
2025 | error = -1; | |
2026 | } | |
2027 | } | |
2028 | ||
e236ba44 | 2029 | if (error) |
81d0cc19 GS |
2030 | { |
2031 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
2032 | message about possibly exhausted resources. */ | |
879bfdc2 | 2033 | if (hw_breakpoint_error) |
81d0cc19 | 2034 | { |
c6510018 MS |
2035 | fprintf_unfiltered (tmp_error_stream, |
2036 | "Could not insert hardware breakpoints:\n\ | |
2037 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 2038 | } |
81d0cc19 GS |
2039 | target_terminal_ours_for_output (); |
2040 | error_stream (tmp_error_stream); | |
2041 | } | |
f7545552 TT |
2042 | |
2043 | do_cleanups (cleanups); | |
c906108c SS |
2044 | } |
2045 | ||
c906108c | 2046 | int |
fba45db2 | 2047 | remove_breakpoints (void) |
c906108c | 2048 | { |
35df4500 | 2049 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2050 | int val = 0; |
c906108c | 2051 | |
35df4500 | 2052 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2053 | { |
35df4500 TJB |
2054 | if (bl->inserted) |
2055 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 2056 | } |
3a1bae8e | 2057 | return val; |
c906108c SS |
2058 | } |
2059 | ||
6c95b8df PA |
2060 | /* Remove breakpoints of process PID. */ |
2061 | ||
2062 | int | |
2063 | remove_breakpoints_pid (int pid) | |
2064 | { | |
35df4500 | 2065 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2066 | int val; |
2067 | struct inferior *inf = find_inferior_pid (pid); | |
2068 | ||
35df4500 | 2069 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2070 | { |
35df4500 | 2071 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2072 | continue; |
2073 | ||
35df4500 | 2074 | if (bl->inserted) |
6c95b8df | 2075 | { |
35df4500 | 2076 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2077 | if (val != 0) |
2078 | return val; | |
2079 | } | |
2080 | } | |
2081 | return 0; | |
2082 | } | |
2083 | ||
692590c1 | 2084 | int |
80ce1ecb | 2085 | remove_hw_watchpoints (void) |
692590c1 | 2086 | { |
35df4500 | 2087 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2088 | int val = 0; |
692590c1 | 2089 | |
35df4500 | 2090 | ALL_BP_LOCATIONS (bl, blp_tmp) |
692590c1 | 2091 | { |
35df4500 TJB |
2092 | if (bl->inserted && bl->loc_type == bp_loc_hardware_watchpoint) |
2093 | val |= remove_breakpoint (bl, mark_uninserted); | |
692590c1 | 2094 | } |
3a1bae8e | 2095 | return val; |
692590c1 MS |
2096 | } |
2097 | ||
c906108c | 2098 | int |
fba45db2 | 2099 | reattach_breakpoints (int pid) |
c906108c | 2100 | { |
6c95b8df | 2101 | struct cleanup *old_chain; |
35df4500 | 2102 | struct bp_location *bl, **blp_tmp; |
c906108c | 2103 | int val; |
a4954f26 | 2104 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 2105 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2106 | struct inferior *inf; |
2107 | struct thread_info *tp; | |
2108 | ||
2109 | tp = any_live_thread_of_process (pid); | |
2110 | if (tp == NULL) | |
2111 | return 1; | |
2112 | ||
2113 | inf = find_inferior_pid (pid); | |
2114 | old_chain = save_inferior_ptid (); | |
2115 | ||
2116 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2117 | |
2118 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2119 | |
35df4500 | 2120 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2121 | { |
35df4500 | 2122 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2123 | continue; |
2124 | ||
35df4500 | 2125 | if (bl->inserted) |
c5aa993b | 2126 | { |
35df4500 TJB |
2127 | bl->inserted = 0; |
2128 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); | |
c5aa993b JM |
2129 | if (val != 0) |
2130 | { | |
ce696e05 | 2131 | do_cleanups (old_chain); |
c5aa993b JM |
2132 | return val; |
2133 | } | |
2134 | } | |
2135 | } | |
ce696e05 | 2136 | do_cleanups (old_chain); |
c906108c SS |
2137 | return 0; |
2138 | } | |
2139 | ||
e58b0e63 PA |
2140 | static int internal_breakpoint_number = -1; |
2141 | ||
84f4c1fe PM |
2142 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2143 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2144 | from internal_breakpoint_number and that variable decremented. | |
2145 | Otherwis the breakpoint number will be populated from | |
2146 | breakpoint_count and that value incremented. Internal breakpoints | |
2147 | do not set the internal var bpnum. */ | |
2148 | static void | |
2149 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2150 | { | |
2151 | if (internal) | |
2152 | b->number = internal_breakpoint_number--; | |
2153 | else | |
2154 | { | |
2155 | set_breakpoint_count (breakpoint_count + 1); | |
2156 | b->number = breakpoint_count; | |
2157 | } | |
2158 | } | |
2159 | ||
e62c965a | 2160 | static struct breakpoint * |
a6d9a66e UW |
2161 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2162 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2163 | { |
e62c965a PP |
2164 | struct symtab_and_line sal; |
2165 | struct breakpoint *b; | |
2166 | ||
4a64f543 | 2167 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2168 | |
2169 | sal.pc = address; | |
2170 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2171 | sal.pspace = current_program_space; |
e62c965a | 2172 | |
a6d9a66e | 2173 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2174 | b->number = internal_breakpoint_number--; |
2175 | b->disposition = disp_donttouch; | |
2176 | ||
2177 | return b; | |
2178 | } | |
2179 | ||
2180 | static void | |
69de3c6a | 2181 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 2182 | { |
69de3c6a | 2183 | struct objfile *objfile; |
e62c965a | 2184 | |
69de3c6a PP |
2185 | ALL_OBJFILES (objfile) |
2186 | { | |
2187 | struct breakpoint *b; | |
2188 | struct minimal_symbol *m; | |
2189 | ||
2190 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2191 | if (m == NULL) | |
2192 | continue; | |
e62c965a | 2193 | |
a6d9a66e UW |
2194 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2195 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
2196 | bp_overlay_event); |
2197 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2198 | |
69de3c6a PP |
2199 | if (overlay_debugging == ovly_auto) |
2200 | { | |
2201 | b->enable_state = bp_enabled; | |
2202 | overlay_events_enabled = 1; | |
2203 | } | |
2204 | else | |
2205 | { | |
2206 | b->enable_state = bp_disabled; | |
2207 | overlay_events_enabled = 0; | |
2208 | } | |
e62c965a PP |
2209 | } |
2210 | update_global_location_list (1); | |
2211 | } | |
2212 | ||
0fd8e87f UW |
2213 | static void |
2214 | create_longjmp_master_breakpoint (char *func_name) | |
2215 | { | |
6c95b8df | 2216 | struct program_space *pspace; |
0fd8e87f | 2217 | struct objfile *objfile; |
6c95b8df PA |
2218 | struct cleanup *old_chain; |
2219 | ||
2220 | old_chain = save_current_program_space (); | |
0fd8e87f | 2221 | |
6c95b8df | 2222 | ALL_PSPACES (pspace) |
0fd8e87f UW |
2223 | ALL_OBJFILES (objfile) |
2224 | { | |
2225 | struct breakpoint *b; | |
2226 | struct minimal_symbol *m; | |
2227 | ||
2228 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
2229 | continue; | |
2230 | ||
6c95b8df PA |
2231 | set_current_program_space (pspace); |
2232 | ||
0fd8e87f UW |
2233 | m = lookup_minimal_symbol_text (func_name, objfile); |
2234 | if (m == NULL) | |
2235 | continue; | |
2236 | ||
a6d9a66e UW |
2237 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2238 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
2239 | bp_longjmp_master); |
2240 | b->addr_string = xstrdup (func_name); | |
2241 | b->enable_state = bp_disabled; | |
2242 | } | |
2243 | update_global_location_list (1); | |
6c95b8df PA |
2244 | |
2245 | do_cleanups (old_chain); | |
0fd8e87f UW |
2246 | } |
2247 | ||
aa7d318d TT |
2248 | /* Create a master std::terminate breakpoint. The actual function |
2249 | looked for is named FUNC_NAME. */ | |
2250 | static void | |
2251 | create_std_terminate_master_breakpoint (const char *func_name) | |
2252 | { | |
2253 | struct program_space *pspace; | |
2254 | struct objfile *objfile; | |
2255 | struct cleanup *old_chain; | |
2256 | ||
2257 | old_chain = save_current_program_space (); | |
2258 | ||
2259 | ALL_PSPACES (pspace) | |
2260 | ALL_OBJFILES (objfile) | |
2261 | { | |
2262 | struct breakpoint *b; | |
2263 | struct minimal_symbol *m; | |
2264 | ||
2265 | set_current_program_space (pspace); | |
2266 | ||
2267 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2268 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2269 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2270 | continue; | |
2271 | ||
2272 | b = create_internal_breakpoint (get_objfile_arch (objfile), | |
2273 | SYMBOL_VALUE_ADDRESS (m), | |
2274 | bp_std_terminate_master); | |
2275 | b->addr_string = xstrdup (func_name); | |
2276 | b->enable_state = bp_disabled; | |
2277 | } | |
2278 | update_global_location_list (1); | |
2279 | ||
2280 | do_cleanups (old_chain); | |
2281 | } | |
2282 | ||
186c406b TT |
2283 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2284 | ||
2285 | void | |
2286 | create_exception_master_breakpoint (void) | |
2287 | { | |
2288 | struct objfile *objfile; | |
2289 | ||
2290 | ALL_OBJFILES (objfile) | |
2291 | { | |
2292 | struct minimal_symbol *debug_hook; | |
2293 | ||
2294 | debug_hook = lookup_minimal_symbol ("_Unwind_DebugHook", NULL, objfile); | |
2295 | if (debug_hook != NULL) | |
2296 | { | |
2297 | struct breakpoint *b; | |
2298 | CORE_ADDR addr = SYMBOL_VALUE_ADDRESS (debug_hook); | |
2299 | struct gdbarch *gdbarch = get_objfile_arch (objfile); | |
2300 | ||
2301 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2302 | ¤t_target); | |
2303 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); | |
2304 | b->addr_string = xstrdup ("_Unwind_DebugHook"); | |
2305 | b->enable_state = bp_disabled; | |
2306 | } | |
2307 | } | |
2308 | ||
2309 | update_global_location_list (1); | |
2310 | } | |
2311 | ||
c906108c | 2312 | void |
fba45db2 | 2313 | update_breakpoints_after_exec (void) |
c906108c | 2314 | { |
35df4500 | 2315 | struct breakpoint *b, *b_tmp; |
876fa593 | 2316 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2317 | |
25b22b0a PA |
2318 | /* We're about to delete breakpoints from GDB's lists. If the |
2319 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2320 | writing the breakpoints' "shadow contents" back into memory. The | |
2321 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2322 | do that. Instead, the target is responsible from marking | |
2323 | breakpoints out as soon as it detects an exec. We don't do that | |
2324 | here instead, because there may be other attempts to delete | |
2325 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2326 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2327 | if (bploc->pspace == current_program_space) |
2328 | gdb_assert (!bploc->inserted); | |
c906108c | 2329 | |
35df4500 | 2330 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2331 | { |
6c95b8df PA |
2332 | if (b->pspace != current_program_space) |
2333 | continue; | |
2334 | ||
4a64f543 | 2335 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2336 | if (b->type == bp_shlib_event) |
2337 | { | |
2338 | delete_breakpoint (b); | |
2339 | continue; | |
2340 | } | |
c906108c | 2341 | |
4a64f543 | 2342 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2343 | if (b->type == bp_jit_event) |
2344 | { | |
2345 | delete_breakpoint (b); | |
2346 | continue; | |
2347 | } | |
2348 | ||
1900040c | 2349 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2350 | as must overlay event and longjmp master breakpoints. */ |
2351 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2352 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2353 | || b->type == bp_exception_master) | |
c4093a6a JM |
2354 | { |
2355 | delete_breakpoint (b); | |
2356 | continue; | |
2357 | } | |
2358 | ||
4a64f543 | 2359 | /* Step-resume breakpoints are meaningless after an exec(). */ |
c5aa993b JM |
2360 | if (b->type == bp_step_resume) |
2361 | { | |
2362 | delete_breakpoint (b); | |
2363 | continue; | |
2364 | } | |
2365 | ||
611c83ae PA |
2366 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2367 | after an exec. */ | |
186c406b TT |
2368 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2369 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2370 | { |
2371 | delete_breakpoint (b); | |
2372 | continue; | |
2373 | } | |
2374 | ||
ce78b96d JB |
2375 | if (b->type == bp_catchpoint) |
2376 | { | |
2377 | /* For now, none of the bp_catchpoint breakpoints need to | |
2378 | do anything at this point. In the future, if some of | |
2379 | the catchpoints need to something, we will need to add | |
2380 | a new method, and call this method from here. */ | |
2381 | continue; | |
2382 | } | |
2383 | ||
c5aa993b JM |
2384 | /* bp_finish is a special case. The only way we ought to be able |
2385 | to see one of these when an exec() has happened, is if the user | |
2386 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2387 | carries them to the call-site of the current callee, by setting | |
2388 | a temporary bp there and resuming. But in this case, the finish | |
2389 | will carry them entirely through the vfork & exec. | |
2390 | ||
2391 | We don't want to allow a bp_finish to remain inserted now. But | |
2392 | we can't safely delete it, 'cause finish_command has a handle to | |
2393 | the bp on a bpstat, and will later want to delete it. There's a | |
2394 | chance (and I've seen it happen) that if we delete the bp_finish | |
2395 | here, that its storage will get reused by the time finish_command | |
2396 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2397 | We really must allow finish_command to delete a bp_finish. | |
2398 | ||
53a5351d JM |
2399 | In the absense of a general solution for the "how do we know |
2400 | it's safe to delete something others may have handles to?" | |
2401 | problem, what we'll do here is just uninsert the bp_finish, and | |
2402 | let finish_command delete it. | |
2403 | ||
2404 | (We know the bp_finish is "doomed" in the sense that it's | |
2405 | momentary, and will be deleted as soon as finish_command sees | |
2406 | the inferior stopped. So it doesn't matter that the bp's | |
2407 | address is probably bogus in the new a.out, unlike e.g., the | |
2408 | solib breakpoints.) */ | |
c5aa993b | 2409 | |
c5aa993b JM |
2410 | if (b->type == bp_finish) |
2411 | { | |
2412 | continue; | |
2413 | } | |
2414 | ||
2415 | /* Without a symbolic address, we have little hope of the | |
2416 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2417 | a.out. */ |
c5aa993b JM |
2418 | if (b->addr_string == NULL) |
2419 | { | |
2420 | delete_breakpoint (b); | |
2421 | continue; | |
2422 | } | |
c5aa993b | 2423 | } |
1900040c | 2424 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 2425 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
2426 | create_longjmp_master_breakpoint ("longjmp"); |
2427 | create_longjmp_master_breakpoint ("_longjmp"); | |
2428 | create_longjmp_master_breakpoint ("siglongjmp"); | |
2429 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 2430 | create_std_terminate_master_breakpoint ("std::terminate()"); |
186c406b | 2431 | create_exception_master_breakpoint (); |
c906108c SS |
2432 | } |
2433 | ||
2434 | int | |
fba45db2 | 2435 | detach_breakpoints (int pid) |
c906108c | 2436 | { |
35df4500 | 2437 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2438 | int val = 0; |
ce696e05 | 2439 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2440 | struct inferior *inf = current_inferior (); |
c5aa993b | 2441 | |
39f77062 | 2442 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2443 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2444 | |
6c95b8df | 2445 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2446 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2447 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2448 | { |
35df4500 | 2449 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2450 | continue; |
2451 | ||
35df4500 TJB |
2452 | if (bl->inserted) |
2453 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2454 | } |
d03285ec UW |
2455 | |
2456 | /* Detach single-step breakpoints as well. */ | |
2457 | detach_single_step_breakpoints (); | |
2458 | ||
ce696e05 | 2459 | do_cleanups (old_chain); |
3a1bae8e | 2460 | return val; |
c906108c SS |
2461 | } |
2462 | ||
35df4500 | 2463 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2464 | Note that this is used to detach breakpoints from a child fork. |
2465 | When we get here, the child isn't in the inferior list, and neither | |
2466 | do we have objects to represent its address space --- we should | |
35df4500 | 2467 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2468 | |
c906108c | 2469 | static int |
35df4500 | 2470 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2471 | { |
2472 | int val; | |
c5aa993b | 2473 | |
35df4500 TJB |
2474 | /* BL is never in moribund_locations by our callers. */ |
2475 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2476 | |
35df4500 | 2477 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2478 | /* Permanent breakpoints cannot be inserted or removed. */ |
2479 | return 0; | |
2480 | ||
74960c60 VP |
2481 | /* The type of none suggests that owner is actually deleted. |
2482 | This should not ever happen. */ | |
35df4500 | 2483 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2484 | |
35df4500 TJB |
2485 | if (bl->loc_type == bp_loc_software_breakpoint |
2486 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2487 | { |
c02f5703 MS |
2488 | /* "Normal" instruction breakpoint: either the standard |
2489 | trap-instruction bp (bp_breakpoint), or a | |
2490 | bp_hardware_breakpoint. */ | |
2491 | ||
2492 | /* First check to see if we have to handle an overlay. */ | |
2493 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2494 | || bl->section == NULL |
2495 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2496 | { |
2497 | /* No overlay handling: just remove the breakpoint. */ | |
2498 | ||
35df4500 TJB |
2499 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2500 | val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
c02f5703 | 2501 | else |
35df4500 | 2502 | val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
c02f5703 | 2503 | } |
c906108c SS |
2504 | else |
2505 | { | |
4a64f543 | 2506 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2507 | Did we set a breakpoint at the LMA? */ |
2508 | if (!overlay_events_enabled) | |
2509 | { | |
2510 | /* Yes -- overlay event support is not active, so we | |
2511 | should have set a breakpoint at the LMA. Remove it. | |
2512 | */ | |
c02f5703 MS |
2513 | /* Ignore any failures: if the LMA is in ROM, we will |
2514 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2515 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2516 | target_remove_hw_breakpoint (bl->gdbarch, | |
2517 | &bl->overlay_target_info); | |
c02f5703 | 2518 | else |
35df4500 TJB |
2519 | target_remove_breakpoint (bl->gdbarch, |
2520 | &bl->overlay_target_info); | |
c02f5703 MS |
2521 | } |
2522 | /* Did we set a breakpoint at the VMA? | |
2523 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2524 | if (bl->inserted) |
c906108c | 2525 | { |
c02f5703 MS |
2526 | /* Yes -- remove it. Previously we did not bother to |
2527 | remove the breakpoint if the section had been | |
2528 | unmapped, but let's not rely on that being safe. We | |
2529 | don't know what the overlay manager might do. */ | |
35df4500 TJB |
2530 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2531 | val = target_remove_hw_breakpoint (bl->gdbarch, | |
2532 | &bl->target_info); | |
aa67235e UW |
2533 | |
2534 | /* However, we should remove *software* breakpoints only | |
2535 | if the section is still mapped, or else we overwrite | |
2536 | wrong code with the saved shadow contents. */ | |
35df4500 TJB |
2537 | else if (section_is_mapped (bl->section)) |
2538 | val = target_remove_breakpoint (bl->gdbarch, | |
2539 | &bl->target_info); | |
aa67235e UW |
2540 | else |
2541 | val = 0; | |
c906108c | 2542 | } |
c02f5703 MS |
2543 | else |
2544 | { | |
2545 | /* No -- not inserted, so no need to remove. No error. */ | |
2546 | val = 0; | |
2547 | } | |
c906108c | 2548 | } |
879d1e6b UW |
2549 | |
2550 | /* In some cases, we might not be able to remove a breakpoint | |
2551 | in a shared library that has already been removed, but we | |
2552 | have not yet processed the shlib unload event. */ | |
35df4500 | 2553 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2554 | val = 0; |
2555 | ||
c906108c SS |
2556 | if (val) |
2557 | return val; | |
35df4500 | 2558 | bl->inserted = (is == mark_inserted); |
c906108c | 2559 | } |
35df4500 | 2560 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2561 | { |
77b06cd7 TJB |
2562 | gdb_assert (bl->owner->ops != NULL |
2563 | && bl->owner->ops->remove_location != NULL); | |
2564 | ||
35df4500 | 2565 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2566 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2567 | |
c906108c | 2568 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2569 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2570 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2571 | bl->owner->number); |
c906108c | 2572 | } |
35df4500 TJB |
2573 | else if (bl->owner->type == bp_catchpoint |
2574 | && breakpoint_enabled (bl->owner) | |
2575 | && !bl->duplicate) | |
ce78b96d | 2576 | { |
77b06cd7 TJB |
2577 | gdb_assert (bl->owner->ops != NULL |
2578 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2579 | |
77b06cd7 | 2580 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2581 | if (val) |
2582 | return val; | |
77b06cd7 | 2583 | |
35df4500 | 2584 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2585 | } |
c906108c SS |
2586 | |
2587 | return 0; | |
2588 | } | |
2589 | ||
6c95b8df | 2590 | static int |
35df4500 | 2591 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2592 | { |
2593 | int ret; | |
2594 | struct cleanup *old_chain; | |
2595 | ||
35df4500 TJB |
2596 | /* BL is never in moribund_locations by our callers. */ |
2597 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2598 | |
35df4500 | 2599 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2600 | /* Permanent breakpoints cannot be inserted or removed. */ |
2601 | return 0; | |
2602 | ||
2603 | /* The type of none suggests that owner is actually deleted. | |
2604 | This should not ever happen. */ | |
35df4500 | 2605 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2606 | |
2607 | old_chain = save_current_space_and_thread (); | |
2608 | ||
35df4500 | 2609 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2610 | |
35df4500 | 2611 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2612 | |
2613 | do_cleanups (old_chain); | |
2614 | return ret; | |
2615 | } | |
2616 | ||
c906108c SS |
2617 | /* Clear the "inserted" flag in all breakpoints. */ |
2618 | ||
25b22b0a | 2619 | void |
fba45db2 | 2620 | mark_breakpoints_out (void) |
c906108c | 2621 | { |
35df4500 | 2622 | struct bp_location *bl, **blp_tmp; |
c906108c | 2623 | |
35df4500 TJB |
2624 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2625 | if (bl->pspace == current_program_space) | |
2626 | bl->inserted = 0; | |
c906108c SS |
2627 | } |
2628 | ||
53a5351d JM |
2629 | /* Clear the "inserted" flag in all breakpoints and delete any |
2630 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2631 | |
2632 | Plus other such housekeeping that has to be done for breakpoints | |
2633 | between runs. | |
2634 | ||
53a5351d JM |
2635 | Note: this function gets called at the end of a run (by |
2636 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2637 | init_wait_for_inferior). */ |
c906108c SS |
2638 | |
2639 | ||
2640 | ||
2641 | void | |
fba45db2 | 2642 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2643 | { |
35df4500 TJB |
2644 | struct breakpoint *b, *b_tmp; |
2645 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2646 | int ix; |
6c95b8df | 2647 | struct program_space *pspace = current_program_space; |
c906108c | 2648 | |
50c71eaf PA |
2649 | /* If breakpoint locations are shared across processes, then there's |
2650 | nothing to do. */ | |
2567c7d9 | 2651 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2652 | return; |
2653 | ||
35df4500 | 2654 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2655 | { |
35df4500 TJB |
2656 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2657 | if (bl->pspace == pspace | |
2658 | && bl->owner->enable_state != bp_permanent) | |
2659 | bl->inserted = 0; | |
6c95b8df | 2660 | } |
075f6582 | 2661 | |
35df4500 | 2662 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2663 | { |
6c95b8df PA |
2664 | if (b->loc && b->loc->pspace != pspace) |
2665 | continue; | |
2666 | ||
c5aa993b JM |
2667 | switch (b->type) |
2668 | { | |
2669 | case bp_call_dummy: | |
c906108c | 2670 | |
c5aa993b | 2671 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2672 | cause problems when the inferior is rerun, so we better get |
2673 | rid of it. */ | |
2674 | ||
2675 | case bp_watchpoint_scope: | |
2676 | ||
2677 | /* Also get rid of scope breakpoints. */ | |
2678 | ||
2679 | case bp_shlib_event: | |
2680 | ||
2681 | /* Also remove solib event breakpoints. Their addresses may | |
2682 | have changed since the last time we ran the program. | |
2683 | Actually we may now be debugging against different target; | |
2684 | and so the solib backend that installed this breakpoint may | |
2685 | not be used in by the target. E.g., | |
2686 | ||
2687 | (gdb) file prog-linux | |
2688 | (gdb) run # native linux target | |
2689 | ... | |
2690 | (gdb) kill | |
2691 | (gdb) file prog-win.exe | |
2692 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2693 | */ | |
c906108c | 2694 | |
c5aa993b JM |
2695 | delete_breakpoint (b); |
2696 | break; | |
c906108c | 2697 | |
c5aa993b JM |
2698 | case bp_watchpoint: |
2699 | case bp_hardware_watchpoint: | |
2700 | case bp_read_watchpoint: | |
2701 | case bp_access_watchpoint: | |
c906108c | 2702 | |
c5aa993b JM |
2703 | /* Likewise for watchpoints on local expressions. */ |
2704 | if (b->exp_valid_block != NULL) | |
2705 | delete_breakpoint (b); | |
967af18d | 2706 | else if (context == inf_starting) |
c860120c | 2707 | { |
4a64f543 MS |
2708 | /* Reset val field to force reread of starting value in |
2709 | insert_breakpoints. */ | |
c860120c PM |
2710 | if (b->val) |
2711 | value_free (b->val); | |
2712 | b->val = NULL; | |
fa4727a6 | 2713 | b->val_valid = 0; |
c860120c | 2714 | } |
c5aa993b JM |
2715 | break; |
2716 | default: | |
c5aa993b JM |
2717 | break; |
2718 | } | |
2719 | } | |
1c5cfe86 PA |
2720 | |
2721 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2722 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2723 | decref_bp_location (&bl); | |
1c5cfe86 | 2724 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2725 | } |
2726 | ||
6c95b8df PA |
2727 | /* These functions concern about actual breakpoints inserted in the |
2728 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2729 | we need to hop over the bkpt --- so we check for address space | |
2730 | match, not program space. */ | |
2731 | ||
c2c6d25f JM |
2732 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2733 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2734 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2735 | permanent breakpoint. | |
2736 | - When continuing from a location with an ordinary breakpoint, we | |
2737 | actually single step once before calling insert_breakpoints. | |
2738 | - When continuing from a localion with a permanent breakpoint, we | |
2739 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2740 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2741 | |
c2c6d25f | 2742 | enum breakpoint_here |
6c95b8df | 2743 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2744 | { |
35df4500 | 2745 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2746 | int any_breakpoint_here = 0; |
c906108c | 2747 | |
35df4500 | 2748 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2749 | { |
35df4500 TJB |
2750 | if (bl->loc_type != bp_loc_software_breakpoint |
2751 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2752 | continue; |
2753 | ||
35df4500 TJB |
2754 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2755 | if ((breakpoint_enabled (bl->owner) | |
2756 | || bl->owner->enable_state == bp_permanent) | |
2757 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2758 | aspace, pc)) |
075f6582 DJ |
2759 | { |
2760 | if (overlay_debugging | |
35df4500 TJB |
2761 | && section_is_overlay (bl->section) |
2762 | && !section_is_mapped (bl->section)) | |
075f6582 | 2763 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2764 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2765 | return permanent_breakpoint_here; |
2766 | else | |
2767 | any_breakpoint_here = 1; | |
2768 | } | |
2769 | } | |
c906108c | 2770 | |
c2c6d25f | 2771 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2772 | } |
2773 | ||
1c5cfe86 PA |
2774 | /* Return true if there's a moribund breakpoint at PC. */ |
2775 | ||
2776 | int | |
6c95b8df | 2777 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2778 | { |
2779 | struct bp_location *loc; | |
2780 | int ix; | |
2781 | ||
2782 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2783 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2784 | aspace, pc)) | |
1c5cfe86 PA |
2785 | return 1; |
2786 | ||
2787 | return 0; | |
2788 | } | |
c2c6d25f | 2789 | |
c36b740a | 2790 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2791 | inserted using regular breakpoint_chain / bp_location array |
2792 | mechanism. This does not check for single-step breakpoints, which | |
2793 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2794 | |
2795 | int | |
4a64f543 MS |
2796 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2797 | CORE_ADDR pc) | |
c906108c | 2798 | { |
35df4500 | 2799 | struct bp_location *bl, **blp_tmp; |
c906108c | 2800 | |
35df4500 | 2801 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2802 | { |
35df4500 TJB |
2803 | if (bl->loc_type != bp_loc_software_breakpoint |
2804 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2805 | continue; |
2806 | ||
35df4500 TJB |
2807 | if (bl->inserted |
2808 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2809 | aspace, pc)) |
075f6582 DJ |
2810 | { |
2811 | if (overlay_debugging | |
35df4500 TJB |
2812 | && section_is_overlay (bl->section) |
2813 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2814 | continue; /* unmapped overlay -- can't be a match */ |
2815 | else | |
2816 | return 1; | |
2817 | } | |
c5aa993b | 2818 | } |
c36b740a VP |
2819 | return 0; |
2820 | } | |
2821 | ||
2822 | /* Returns non-zero iff there's either regular breakpoint | |
2823 | or a single step breakpoint inserted at PC. */ | |
2824 | ||
2825 | int | |
6c95b8df | 2826 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2827 | { |
6c95b8df | 2828 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2829 | return 1; |
c906108c | 2830 | |
6c95b8df | 2831 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2832 | return 1; |
2833 | ||
c906108c SS |
2834 | return 0; |
2835 | } | |
2836 | ||
4fa8626c DJ |
2837 | /* This function returns non-zero iff there is a software breakpoint |
2838 | inserted at PC. */ | |
2839 | ||
2840 | int | |
3e43a32a MS |
2841 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2842 | CORE_ADDR pc) | |
4fa8626c | 2843 | { |
35df4500 | 2844 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2845 | |
35df4500 | 2846 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2847 | { |
35df4500 | 2848 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2849 | continue; |
2850 | ||
35df4500 TJB |
2851 | if (bl->inserted |
2852 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2853 | aspace, pc)) |
4fa8626c DJ |
2854 | { |
2855 | if (overlay_debugging | |
35df4500 TJB |
2856 | && section_is_overlay (bl->section) |
2857 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2858 | continue; /* unmapped overlay -- can't be a match */ |
2859 | else | |
2860 | return 1; | |
2861 | } | |
2862 | } | |
2863 | ||
1aafd4da | 2864 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2865 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2866 | return 1; |
2867 | ||
4fa8626c DJ |
2868 | return 0; |
2869 | } | |
2870 | ||
9093389c PA |
2871 | int |
2872 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2873 | CORE_ADDR addr, ULONGEST len) | |
2874 | { | |
2875 | struct breakpoint *bpt; | |
2876 | ||
2877 | ALL_BREAKPOINTS (bpt) | |
2878 | { | |
2879 | struct bp_location *loc; | |
2880 | ||
2881 | if (bpt->type != bp_hardware_watchpoint | |
2882 | && bpt->type != bp_access_watchpoint) | |
2883 | continue; | |
2884 | ||
2885 | if (!breakpoint_enabled (bpt)) | |
2886 | continue; | |
2887 | ||
2888 | for (loc = bpt->loc; loc; loc = loc->next) | |
2889 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2890 | { | |
2891 | CORE_ADDR l, h; | |
2892 | ||
2893 | /* Check for intersection. */ | |
2894 | l = max (loc->address, addr); | |
2895 | h = min (loc->address + loc->length, addr + len); | |
2896 | if (l < h) | |
2897 | return 1; | |
2898 | } | |
2899 | } | |
2900 | return 0; | |
2901 | } | |
2902 | ||
075f6582 DJ |
2903 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2904 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2905 | |
2906 | int | |
6c95b8df PA |
2907 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2908 | ptid_t ptid) | |
c906108c | 2909 | { |
35df4500 | 2910 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 2911 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2912 | int thread = -1; |
4a306c9a | 2913 | int task = 0; |
a6f1cd96 | 2914 | |
35df4500 | 2915 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2916 | { |
35df4500 TJB |
2917 | if (bl->loc_type != bp_loc_software_breakpoint |
2918 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2919 | continue; |
2920 | ||
35df4500 TJB |
2921 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2922 | if (!breakpoint_enabled (bl->owner) | |
2923 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
2924 | continue; |
2925 | ||
35df4500 | 2926 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
6c95b8df | 2927 | aspace, pc)) |
a6f1cd96 JB |
2928 | continue; |
2929 | ||
35df4500 | 2930 | if (bl->owner->thread != -1) |
075f6582 | 2931 | { |
a6f1cd96 JB |
2932 | /* This is a thread-specific breakpoint. Check that ptid |
2933 | matches that thread. If thread hasn't been computed yet, | |
2934 | it is now time to do so. */ | |
2935 | if (thread == -1) | |
2936 | thread = pid_to_thread_id (ptid); | |
35df4500 | 2937 | if (bl->owner->thread != thread) |
a6f1cd96 | 2938 | continue; |
075f6582 | 2939 | } |
a6f1cd96 | 2940 | |
35df4500 | 2941 | if (bl->owner->task != 0) |
4a306c9a JB |
2942 | { |
2943 | /* This is a task-specific breakpoint. Check that ptid | |
2944 | matches that task. If task hasn't been computed yet, | |
2945 | it is now time to do so. */ | |
2946 | if (task == 0) | |
2947 | task = ada_get_task_number (ptid); | |
35df4500 | 2948 | if (bl->owner->task != task) |
4a306c9a JB |
2949 | continue; |
2950 | } | |
2951 | ||
a6f1cd96 | 2952 | if (overlay_debugging |
35df4500 TJB |
2953 | && section_is_overlay (bl->section) |
2954 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
2955 | continue; /* unmapped overlay -- can't be a match */ |
2956 | ||
2957 | return 1; | |
c5aa993b | 2958 | } |
c906108c SS |
2959 | |
2960 | return 0; | |
2961 | } | |
c906108c | 2962 | \f |
c5aa993b | 2963 | |
c906108c SS |
2964 | /* bpstat stuff. External routines' interfaces are documented |
2965 | in breakpoint.h. */ | |
2966 | ||
2967 | int | |
fba45db2 | 2968 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2969 | { |
533be4dd | 2970 | return (ep->type == bp_catchpoint); |
c906108c SS |
2971 | } |
2972 | ||
f431efe5 PA |
2973 | /* Frees any storage that is part of a bpstat. Does not walk the |
2974 | 'next' chain. */ | |
2975 | ||
2976 | static void | |
198757a8 VP |
2977 | bpstat_free (bpstat bs) |
2978 | { | |
2979 | if (bs->old_val != NULL) | |
2980 | value_free (bs->old_val); | |
9add0f1b | 2981 | decref_counted_command_line (&bs->commands); |
f431efe5 | 2982 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
2983 | xfree (bs); |
2984 | } | |
2985 | ||
c906108c SS |
2986 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2987 | Also free any storage that is part of a bpstat. */ | |
2988 | ||
2989 | void | |
fba45db2 | 2990 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2991 | { |
2992 | bpstat p; | |
2993 | bpstat q; | |
2994 | ||
2995 | if (bsp == 0) | |
2996 | return; | |
2997 | p = *bsp; | |
2998 | while (p != NULL) | |
2999 | { | |
3000 | q = p->next; | |
198757a8 | 3001 | bpstat_free (p); |
c906108c SS |
3002 | p = q; |
3003 | } | |
3004 | *bsp = NULL; | |
3005 | } | |
3006 | ||
3007 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3008 | is part of the bpstat is copied as well. */ | |
3009 | ||
3010 | bpstat | |
fba45db2 | 3011 | bpstat_copy (bpstat bs) |
c906108c SS |
3012 | { |
3013 | bpstat p = NULL; | |
3014 | bpstat tmp; | |
3015 | bpstat retval = NULL; | |
3016 | ||
3017 | if (bs == NULL) | |
3018 | return bs; | |
3019 | ||
3020 | for (; bs != NULL; bs = bs->next) | |
3021 | { | |
3022 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3023 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3024 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3025 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3026 | if (bs->old_val != NULL) |
3c3185ac JK |
3027 | { |
3028 | tmp->old_val = value_copy (bs->old_val); | |
3029 | release_value (tmp->old_val); | |
3030 | } | |
31cc81e9 | 3031 | |
c906108c SS |
3032 | if (p == NULL) |
3033 | /* This is the first thing in the chain. */ | |
3034 | retval = tmp; | |
3035 | else | |
3036 | p->next = tmp; | |
3037 | p = tmp; | |
3038 | } | |
3039 | p->next = NULL; | |
3040 | return retval; | |
3041 | } | |
3042 | ||
4a64f543 | 3043 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3044 | |
3045 | bpstat | |
fba45db2 | 3046 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3047 | { |
c5aa993b JM |
3048 | if (bsp == NULL) |
3049 | return NULL; | |
c906108c | 3050 | |
c5aa993b JM |
3051 | for (; bsp != NULL; bsp = bsp->next) |
3052 | { | |
f431efe5 | 3053 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3054 | return bsp; |
3055 | } | |
c906108c SS |
3056 | return NULL; |
3057 | } | |
3058 | ||
4a64f543 MS |
3059 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3060 | stopped at. *BSP upon return is a bpstat which points to the | |
3061 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3062 | good for anything but further calls to bpstat_num). | |
3063 | ||
8671a17b PA |
3064 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3065 | Return -1 if stopped at a breakpoint that has been deleted since | |
3066 | we set it. | |
3067 | Return 1 otherwise. */ | |
c906108c SS |
3068 | |
3069 | int | |
8671a17b | 3070 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3071 | { |
3072 | struct breakpoint *b; | |
3073 | ||
3074 | if ((*bsp) == NULL) | |
3075 | return 0; /* No more breakpoint values */ | |
8671a17b | 3076 | |
4a64f543 MS |
3077 | /* We assume we'll never have several bpstats that correspond to a |
3078 | single breakpoint -- otherwise, this function might return the | |
3079 | same number more than once and this will look ugly. */ | |
f431efe5 | 3080 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3081 | *bsp = (*bsp)->next; |
3082 | if (b == NULL) | |
3083 | return -1; /* breakpoint that's been deleted since */ | |
3084 | ||
3085 | *num = b->number; /* We have its number */ | |
3086 | return 1; | |
c906108c SS |
3087 | } |
3088 | ||
3089 | /* Modify BS so that the actions will not be performed. */ | |
3090 | ||
3091 | void | |
fba45db2 | 3092 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3093 | { |
3094 | for (; bs != NULL; bs = bs->next) | |
3095 | { | |
9add0f1b | 3096 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3097 | bs->commands_left = NULL; |
c906108c SS |
3098 | if (bs->old_val != NULL) |
3099 | { | |
3100 | value_free (bs->old_val); | |
3101 | bs->old_val = NULL; | |
3102 | } | |
3103 | } | |
3104 | } | |
3105 | ||
f3b1572e PA |
3106 | /* Called when a command is about to proceed the inferior. */ |
3107 | ||
3108 | static void | |
3109 | breakpoint_about_to_proceed (void) | |
3110 | { | |
3111 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3112 | { | |
3113 | struct thread_info *tp = inferior_thread (); | |
3114 | ||
3115 | /* Allow inferior function calls in breakpoint commands to not | |
3116 | interrupt the command list. When the call finishes | |
3117 | successfully, the inferior will be standing at the same | |
3118 | breakpoint as if nothing happened. */ | |
16c381f0 | 3119 | if (tp->control.in_infcall) |
f3b1572e PA |
3120 | return; |
3121 | } | |
3122 | ||
3123 | breakpoint_proceeded = 1; | |
3124 | } | |
3125 | ||
4a64f543 MS |
3126 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3127 | command. */ | |
c906108c | 3128 | static void |
4efb68b1 | 3129 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3130 | { |
3131 | executing_breakpoint_commands = 0; | |
3132 | } | |
3133 | ||
4a64f543 MS |
3134 | /* Execute all the commands associated with all the breakpoints at |
3135 | this location. Any of these commands could cause the process to | |
3136 | proceed beyond this point, etc. We look out for such changes by | |
3137 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3138 | |
347bddb7 PA |
3139 | Returns true if a breakpoint command resumed the inferior. In that |
3140 | case, it is the caller's responsibility to recall it again with the | |
3141 | bpstat of the current thread. */ | |
3142 | ||
3143 | static int | |
3144 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3145 | { |
3146 | bpstat bs; | |
3147 | struct cleanup *old_chain; | |
347bddb7 | 3148 | int again = 0; |
c906108c SS |
3149 | |
3150 | /* Avoid endless recursion if a `source' command is contained | |
3151 | in bs->commands. */ | |
3152 | if (executing_breakpoint_commands) | |
347bddb7 | 3153 | return 0; |
c906108c SS |
3154 | |
3155 | executing_breakpoint_commands = 1; | |
3156 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3157 | ||
4a64f543 | 3158 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3159 | bs = *bsp; |
3160 | ||
3161 | breakpoint_proceeded = 0; | |
3162 | for (; bs != NULL; bs = bs->next) | |
3163 | { | |
9add0f1b | 3164 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3165 | struct command_line *cmd; |
3166 | struct cleanup *this_cmd_tree_chain; | |
3167 | ||
3168 | /* Take ownership of the BSP's command tree, if it has one. | |
3169 | ||
3170 | The command tree could legitimately contain commands like | |
3171 | 'step' and 'next', which call clear_proceed_status, which | |
3172 | frees stop_bpstat's command tree. To make sure this doesn't | |
3173 | free the tree we're executing out from under us, we need to | |
3174 | take ownership of the tree ourselves. Since a given bpstat's | |
3175 | commands are only executed once, we don't need to copy it; we | |
3176 | can clear the pointer in the bpstat, and make sure we free | |
3177 | the tree when we're done. */ | |
9add0f1b TT |
3178 | ccmd = bs->commands; |
3179 | bs->commands = NULL; | |
3180 | this_cmd_tree_chain | |
3181 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3182 | cmd = bs->commands_left; | |
3183 | bs->commands_left = NULL; | |
6c50ab1c | 3184 | |
c906108c SS |
3185 | while (cmd != NULL) |
3186 | { | |
3187 | execute_control_command (cmd); | |
3188 | ||
3189 | if (breakpoint_proceeded) | |
3190 | break; | |
3191 | else | |
3192 | cmd = cmd->next; | |
3193 | } | |
6c50ab1c JB |
3194 | |
3195 | /* We can free this command tree now. */ | |
3196 | do_cleanups (this_cmd_tree_chain); | |
3197 | ||
c906108c | 3198 | if (breakpoint_proceeded) |
32c1e744 VP |
3199 | { |
3200 | if (target_can_async_p ()) | |
347bddb7 PA |
3201 | /* If we are in async mode, then the target might be still |
3202 | running, not stopped at any breakpoint, so nothing for | |
3203 | us to do here -- just return to the event loop. */ | |
3204 | ; | |
32c1e744 VP |
3205 | else |
3206 | /* In sync mode, when execute_control_command returns | |
3207 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3208 | Breakpoint commands for that stop were not run, since |
3209 | execute_command does not run breakpoint commands -- | |
3210 | only command_line_handler does, but that one is not | |
3211 | involved in execution of breakpoint commands. So, we | |
3212 | can now execute breakpoint commands. It should be | |
3213 | noted that making execute_command do bpstat actions is | |
3214 | not an option -- in this case we'll have recursive | |
3215 | invocation of bpstat for each breakpoint with a | |
3216 | command, and can easily blow up GDB stack. Instead, we | |
3217 | return true, which will trigger the caller to recall us | |
3218 | with the new stop_bpstat. */ | |
3219 | again = 1; | |
3220 | break; | |
32c1e744 | 3221 | } |
c906108c | 3222 | } |
c2b8ed2c | 3223 | do_cleanups (old_chain); |
347bddb7 PA |
3224 | return again; |
3225 | } | |
3226 | ||
3227 | void | |
3228 | bpstat_do_actions (void) | |
3229 | { | |
3230 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3231 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3232 | && target_has_execution | |
3233 | && !is_exited (inferior_ptid) | |
3234 | && !is_executing (inferior_ptid)) | |
3235 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3236 | and only return when it is stopped at the next breakpoint, we | |
3237 | keep doing breakpoint actions until it returns false to | |
3238 | indicate the inferior was not resumed. */ | |
16c381f0 | 3239 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3240 | break; |
c906108c SS |
3241 | } |
3242 | ||
fa4727a6 DJ |
3243 | /* Print out the (old or new) value associated with a watchpoint. */ |
3244 | ||
3245 | static void | |
3246 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3247 | { | |
3248 | if (val == NULL) | |
3249 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3250 | else | |
79a45b7d TT |
3251 | { |
3252 | struct value_print_options opts; | |
3253 | get_user_print_options (&opts); | |
3254 | value_print (val, stream, &opts); | |
3255 | } | |
fa4727a6 DJ |
3256 | } |
3257 | ||
e514a9d6 | 3258 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3259 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3260 | by having it set different print_it values. |
3261 | ||
3262 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3263 | through the bpstat list of things causing this stop, calling the | |
4a64f543 | 3264 | print_bp_stop_message function on each one. The behavior of the |
e514a9d6 | 3265 | print_bp_stop_message function depends on the print_it field of |
4a64f543 | 3266 | bpstat. If such field so indicates, call this function here. |
e514a9d6 JM |
3267 | |
3268 | Return values from this routine (ultimately used by bpstat_print() | |
3269 | and normal_stop() to decide what to do): | |
3270 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3271 | don't print anything else. | |
3272 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3273 | that something to be followed by a location. | |
3274 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3275 | that something to be followed by a location. | |
3276 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3277 | analysis. */ | |
c906108c | 3278 | |
917317f4 | 3279 | static enum print_stop_action |
fba45db2 | 3280 | print_it_typical (bpstat bs) |
c906108c | 3281 | { |
f7545552 | 3282 | struct cleanup *old_chain; |
4f8d1dc6 | 3283 | struct breakpoint *b; |
89f9893c | 3284 | const struct bp_location *bl; |
8b93c638 | 3285 | struct ui_stream *stb; |
f7545552 TT |
3286 | int bp_temp = 0; |
3287 | enum print_stop_action result; | |
3288 | ||
c906108c SS |
3289 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3290 | which has since been deleted. */ | |
e514a9d6 | 3291 | if (bs->breakpoint_at == NULL) |
917317f4 | 3292 | return PRINT_UNKNOWN; |
2bdf28a0 | 3293 | |
f431efe5 PA |
3294 | gdb_assert (bs->bp_location_at != NULL); |
3295 | ||
3296 | bl = bs->bp_location_at; | |
3297 | b = bs->breakpoint_at; | |
c906108c | 3298 | |
f7545552 TT |
3299 | stb = ui_out_stream_new (uiout); |
3300 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3301 | ||
4f8d1dc6 | 3302 | switch (b->type) |
c906108c | 3303 | { |
e514a9d6 JM |
3304 | case bp_breakpoint: |
3305 | case bp_hardware_breakpoint: | |
f431efe5 | 3306 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3307 | if (bl->address != bl->requested_address) |
3308 | breakpoint_adjustment_warning (bl->requested_address, | |
3309 | bl->address, | |
4f8d1dc6 VP |
3310 | b->number, 1); |
3311 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3312 | if (bp_temp) |
3313 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3314 | else | |
3315 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3316 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3317 | { |
3318 | ui_out_field_string (uiout, "reason", | |
3319 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3320 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3321 | } | |
4f8d1dc6 | 3322 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3323 | ui_out_text (uiout, ", "); |
f7545552 | 3324 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3325 | break; |
3326 | ||
3327 | case bp_shlib_event: | |
917317f4 JM |
3328 | /* Did we stop because the user set the stop_on_solib_events |
3329 | variable? (If so, we report this as a generic, "Stopped due | |
3330 | to shlib event" message.) */ | |
a3f17187 | 3331 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3332 | result = PRINT_NOTHING; |
e514a9d6 JM |
3333 | break; |
3334 | ||
c4093a6a | 3335 | case bp_thread_event: |
4a64f543 | 3336 | /* Not sure how we will get here. |
c4093a6a | 3337 | GDB should not stop for these breakpoints. */ |
a3f17187 | 3338 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3339 | result = PRINT_NOTHING; |
c4093a6a JM |
3340 | break; |
3341 | ||
1900040c | 3342 | case bp_overlay_event: |
4a64f543 | 3343 | /* By analogy with the thread event, GDB should not stop for these. */ |
a3f17187 | 3344 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3345 | result = PRINT_NOTHING; |
1900040c MS |
3346 | break; |
3347 | ||
0fd8e87f UW |
3348 | case bp_longjmp_master: |
3349 | /* These should never be enabled. */ | |
3350 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3351 | result = PRINT_NOTHING; | |
3352 | break; | |
3353 | ||
aa7d318d TT |
3354 | case bp_std_terminate_master: |
3355 | /* These should never be enabled. */ | |
3e43a32a MS |
3356 | printf_filtered (_("std::terminate Master Breakpoint: " |
3357 | "gdb should not stop!\n")); | |
aa7d318d TT |
3358 | result = PRINT_NOTHING; |
3359 | break; | |
3360 | ||
186c406b TT |
3361 | case bp_exception_master: |
3362 | /* These should never be enabled. */ | |
3e43a32a MS |
3363 | printf_filtered (_("Exception Master Breakpoint: " |
3364 | "gdb should not stop!\n")); | |
186c406b TT |
3365 | result = PRINT_NOTHING; |
3366 | break; | |
3367 | ||
e514a9d6 JM |
3368 | case bp_watchpoint: |
3369 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3370 | annotate_watchpoint (b->number); |
3371 | if (ui_out_is_mi_like_p (uiout)) | |
3372 | ui_out_field_string | |
3373 | (uiout, "reason", | |
3374 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3375 | mention (b); | |
f7545552 | 3376 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3377 | ui_out_text (uiout, "\nOld value = "); |
3378 | watchpoint_value_print (bs->old_val, stb->stream); | |
3379 | ui_out_field_stream (uiout, "old", stb); | |
3380 | ui_out_text (uiout, "\nNew value = "); | |
3381 | watchpoint_value_print (b->val, stb->stream); | |
3382 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3383 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3384 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3385 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3386 | break; |
3387 | ||
3388 | case bp_read_watchpoint: | |
9dc5e2a9 | 3389 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3390 | ui_out_field_string |
3391 | (uiout, "reason", | |
3392 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3393 | mention (b); |
f7545552 | 3394 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3395 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3396 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3397 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3398 | ui_out_text (uiout, "\n"); |
f7545552 | 3399 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3400 | break; |
3401 | ||
3402 | case bp_access_watchpoint: | |
fa4727a6 | 3403 | if (bs->old_val != NULL) |
8b93c638 | 3404 | { |
4f8d1dc6 | 3405 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3406 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3407 | ui_out_field_string |
3408 | (uiout, "reason", | |
3409 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3410 | mention (b); |
f7545552 | 3411 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3412 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3413 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3414 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3415 | ui_out_text (uiout, "\nNew value = "); |
3416 | } | |
3417 | else | |
3418 | { | |
4f8d1dc6 | 3419 | mention (b); |
9dc5e2a9 | 3420 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3421 | ui_out_field_string |
3422 | (uiout, "reason", | |
3423 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3424 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3425 | ui_out_text (uiout, "\nValue = "); |
3426 | } | |
fa4727a6 | 3427 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3428 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3429 | ui_out_text (uiout, "\n"); |
f7545552 | 3430 | result = PRINT_UNKNOWN; |
e514a9d6 | 3431 | break; |
4ce44c66 | 3432 | |
e514a9d6 | 3433 | /* Fall through, we don't deal with these types of breakpoints |
4a64f543 | 3434 | here. */ |
e514a9d6 | 3435 | |
11cf8741 | 3436 | case bp_finish: |
9dc5e2a9 | 3437 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3438 | ui_out_field_string |
3439 | (uiout, "reason", | |
3440 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3441 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3442 | break; |
3443 | ||
e514a9d6 | 3444 | case bp_until: |
9dc5e2a9 | 3445 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3446 | ui_out_field_string |
3447 | (uiout, "reason", | |
3448 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3449 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3450 | break; |
3451 | ||
c2d11a7d | 3452 | case bp_none: |
e514a9d6 JM |
3453 | case bp_longjmp: |
3454 | case bp_longjmp_resume: | |
186c406b TT |
3455 | case bp_exception: |
3456 | case bp_exception_resume: | |
e514a9d6 | 3457 | case bp_step_resume: |
e514a9d6 JM |
3458 | case bp_watchpoint_scope: |
3459 | case bp_call_dummy: | |
aa7d318d | 3460 | case bp_std_terminate: |
1042e4c0 | 3461 | case bp_tracepoint: |
7a697b8d | 3462 | case bp_fast_tracepoint: |
4efc6507 | 3463 | case bp_jit_event: |
e514a9d6 | 3464 | default: |
f7545552 TT |
3465 | result = PRINT_UNKNOWN; |
3466 | break; | |
e514a9d6 | 3467 | } |
f7545552 TT |
3468 | |
3469 | do_cleanups (old_chain); | |
3470 | return result; | |
e514a9d6 JM |
3471 | } |
3472 | ||
3473 | /* Generic routine for printing messages indicating why we | |
4a64f543 | 3474 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3475 | 'print_it' in the bpstat structure. Under some circumstances we |
3476 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3477 | normal_stop(). */ |
e514a9d6 JM |
3478 | |
3479 | static enum print_stop_action | |
3480 | print_bp_stop_message (bpstat bs) | |
3481 | { | |
3482 | switch (bs->print_it) | |
3483 | { | |
3484 | case print_it_noop: | |
4a64f543 | 3485 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3486 | return PRINT_UNKNOWN; |
3487 | break; | |
3488 | ||
3489 | case print_it_done: | |
3490 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3491 | relevant messages. */ |
e514a9d6 JM |
3492 | return PRINT_SRC_AND_LOC; |
3493 | break; | |
3494 | ||
3495 | case print_it_normal: | |
4f8d1dc6 | 3496 | { |
f431efe5 PA |
3497 | struct breakpoint *b = bs->breakpoint_at; |
3498 | ||
4f8d1dc6 VP |
3499 | /* Normal case. Call the breakpoint's print_it method, or |
3500 | print_it_typical. */ | |
3501 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3502 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3503 | return b->ops->print_it (b); | |
3504 | else | |
3505 | return print_it_typical (bs); | |
3506 | } | |
3507 | break; | |
3086aeae | 3508 | |
e514a9d6 | 3509 | default: |
8e65ff28 | 3510 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3511 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3512 | break; |
c906108c | 3513 | } |
c906108c SS |
3514 | } |
3515 | ||
e514a9d6 JM |
3516 | /* Print a message indicating what happened. This is called from |
3517 | normal_stop(). The input to this routine is the head of the bpstat | |
3518 | list - a list of the eventpoints that caused this stop. This | |
3519 | routine calls the generic print routine for printing a message | |
3520 | about reasons for stopping. This will print (for example) the | |
3521 | "Breakpoint n," part of the output. The return value of this | |
3522 | routine is one of: | |
c906108c | 3523 | |
4a64f543 | 3524 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3525 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3526 | code to print the location. An example is |
c5aa993b JM |
3527 | "Breakpoint 1, " which should be followed by |
3528 | the location. | |
917317f4 | 3529 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3530 | to also print the location part of the message. |
3531 | An example is the catch/throw messages, which | |
4a64f543 | 3532 | don't require a location appended to the end. |
917317f4 | 3533 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3534 | further info to be printed. */ |
c906108c | 3535 | |
917317f4 | 3536 | enum print_stop_action |
fba45db2 | 3537 | bpstat_print (bpstat bs) |
c906108c SS |
3538 | { |
3539 | int val; | |
c5aa993b | 3540 | |
c906108c | 3541 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3542 | (Currently all watchpoints go on the bpstat whether hit or not. |
3543 | That probably could (should) be changed, provided care is taken | |
c906108c | 3544 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3545 | for (; bs; bs = bs->next) |
3546 | { | |
3547 | val = print_bp_stop_message (bs); | |
3548 | if (val == PRINT_SRC_ONLY | |
3549 | || val == PRINT_SRC_AND_LOC | |
3550 | || val == PRINT_NOTHING) | |
3551 | return val; | |
3552 | } | |
c906108c | 3553 | |
e514a9d6 | 3554 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3555 | with and nothing was printed. */ |
917317f4 | 3556 | return PRINT_UNKNOWN; |
c906108c SS |
3557 | } |
3558 | ||
4a64f543 MS |
3559 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3560 | used inside a catch_errors to evaluate the breakpoint condition. | |
3561 | The argument is a "struct expression *" that has been cast to a | |
3562 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3563 | |
3564 | static int | |
4efb68b1 | 3565 | breakpoint_cond_eval (void *exp) |
c906108c | 3566 | { |
278cd55f | 3567 | struct value *mark = value_mark (); |
c5aa993b | 3568 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3569 | |
c906108c SS |
3570 | value_free_to_mark (mark); |
3571 | return i; | |
3572 | } | |
3573 | ||
5760d0ab | 3574 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3575 | |
3576 | static bpstat | |
5760d0ab | 3577 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3578 | { |
3579 | bpstat bs; | |
3580 | ||
3581 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3582 | bs->next = NULL; |
3583 | **bs_link_pointer = bs; | |
3584 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3585 | bs->breakpoint_at = bl->owner; |
3586 | bs->bp_location_at = bl; | |
3587 | incref_bp_location (bl); | |
c906108c SS |
3588 | /* If the condition is false, etc., don't do the commands. */ |
3589 | bs->commands = NULL; | |
9add0f1b | 3590 | bs->commands_left = NULL; |
c906108c SS |
3591 | bs->old_val = NULL; |
3592 | bs->print_it = print_it_normal; | |
3593 | return bs; | |
3594 | } | |
3595 | \f | |
d983da9c DJ |
3596 | /* The target has stopped with waitstatus WS. Check if any hardware |
3597 | watchpoints have triggered, according to the target. */ | |
3598 | ||
3599 | int | |
3600 | watchpoints_triggered (struct target_waitstatus *ws) | |
3601 | { | |
d92524f1 | 3602 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3603 | CORE_ADDR addr; |
3604 | struct breakpoint *b; | |
3605 | ||
3606 | if (!stopped_by_watchpoint) | |
3607 | { | |
3608 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3609 | as not triggered. */ | |
3610 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3611 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3612 | b->watchpoint_triggered = watch_triggered_no; |
3613 | ||
3614 | return 0; | |
3615 | } | |
3616 | ||
3617 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3618 | { | |
3619 | /* We were stopped by a watchpoint, but we don't know where. | |
3620 | Mark all watchpoints as unknown. */ | |
3621 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3622 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3623 | b->watchpoint_triggered = watch_triggered_unknown; |
3624 | ||
3625 | return stopped_by_watchpoint; | |
3626 | } | |
3627 | ||
3628 | /* The target could report the data address. Mark watchpoints | |
3629 | affected by this data address as triggered, and all others as not | |
3630 | triggered. */ | |
3631 | ||
3632 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3633 | if (is_hardware_watchpoint (b)) |
d983da9c | 3634 | { |
a5606eee | 3635 | struct bp_location *loc; |
d983da9c DJ |
3636 | |
3637 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3638 | for (loc = b->loc; loc; loc = loc->next) |
3639 | /* Exact match not required. Within range is | |
3640 | sufficient. */ | |
5009afc5 AS |
3641 | if (target_watchpoint_addr_within_range (¤t_target, |
3642 | addr, loc->address, | |
3643 | loc->length)) | |
a5606eee VP |
3644 | { |
3645 | b->watchpoint_triggered = watch_triggered_yes; | |
3646 | break; | |
3647 | } | |
d983da9c DJ |
3648 | } |
3649 | ||
3650 | return 1; | |
3651 | } | |
3652 | ||
c906108c SS |
3653 | /* Possible return values for watchpoint_check (this can't be an enum |
3654 | because of check_errors). */ | |
3655 | /* The watchpoint has been deleted. */ | |
3656 | #define WP_DELETED 1 | |
3657 | /* The value has changed. */ | |
3658 | #define WP_VALUE_CHANGED 2 | |
3659 | /* The value has not changed. */ | |
3660 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3661 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3662 | #define WP_IGNORE 4 | |
c906108c SS |
3663 | |
3664 | #define BP_TEMPFLAG 1 | |
3665 | #define BP_HARDWAREFLAG 2 | |
3666 | ||
4a64f543 MS |
3667 | /* Evaluate watchpoint condition expression and check if its value |
3668 | changed. | |
553e4c11 JB |
3669 | |
3670 | P should be a pointer to struct bpstat, but is defined as a void * | |
3671 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3672 | |
3673 | static int | |
4efb68b1 | 3674 | watchpoint_check (void *p) |
c906108c SS |
3675 | { |
3676 | bpstat bs = (bpstat) p; | |
3677 | struct breakpoint *b; | |
3678 | struct frame_info *fr; | |
3679 | int within_current_scope; | |
3680 | ||
f431efe5 | 3681 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3682 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3683 | b = bs->breakpoint_at; |
c906108c | 3684 | |
f6bc2008 PA |
3685 | /* If this is a local watchpoint, we only want to check if the |
3686 | watchpoint frame is in scope if the current thread is the thread | |
3687 | that was used to create the watchpoint. */ | |
3688 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3689 | return WP_IGNORE; |
f6bc2008 | 3690 | |
c906108c SS |
3691 | if (b->exp_valid_block == NULL) |
3692 | within_current_scope = 1; | |
3693 | else | |
3694 | { | |
edb3359d DJ |
3695 | struct frame_info *frame = get_current_frame (); |
3696 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3697 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3698 | ||
4a64f543 MS |
3699 | /* in_function_epilogue_p() returns a non-zero value if we're |
3700 | still in the function but the stack frame has already been | |
3701 | invalidated. Since we can't rely on the values of local | |
3702 | variables after the stack has been destroyed, we are treating | |
3703 | the watchpoint in that state as `not changed' without further | |
3704 | checking. Don't mark watchpoints as changed if the current | |
3705 | frame is in an epilogue - even if they are in some other | |
3706 | frame, our view of the stack is likely to be wrong and | |
3707 | frame_find_by_id could error out. */ | |
a0f49112 | 3708 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3709 | return WP_IGNORE; |
a0f49112 | 3710 | |
101dcfbe | 3711 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3712 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3713 | |
3714 | /* If we've gotten confused in the unwinder, we might have | |
3715 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3716 | if (within_current_scope) |
3717 | { | |
3718 | struct symbol *function; | |
3719 | ||
3720 | function = get_frame_function (fr); | |
3721 | if (function == NULL | |
3722 | || !contained_in (b->exp_valid_block, | |
3723 | SYMBOL_BLOCK_VALUE (function))) | |
3724 | within_current_scope = 0; | |
3725 | } | |
69fbadd5 | 3726 | |
edb3359d | 3727 | if (within_current_scope) |
c906108c SS |
3728 | /* If we end up stopping, the current frame will get selected |
3729 | in normal_stop. So this call to select_frame won't affect | |
3730 | the user. */ | |
0f7d239c | 3731 | select_frame (fr); |
c906108c | 3732 | } |
c5aa993b | 3733 | |
c906108c SS |
3734 | if (within_current_scope) |
3735 | { | |
4a64f543 MS |
3736 | /* We use value_{,free_to_}mark because it could be a *long* |
3737 | time before we return to the command level and call | |
3738 | free_all_values. We can't call free_all_values because we | |
3739 | might be in the middle of evaluating a function call. */ | |
c906108c | 3740 | |
0cf6dd15 | 3741 | int pc = 0; |
278cd55f | 3742 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3743 | struct value *new_val; |
3744 | ||
0cf6dd15 | 3745 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3746 | |
4a64f543 MS |
3747 | /* We use value_equal_contents instead of value_equal because |
3748 | the latter coerces an array to a pointer, thus comparing just | |
3749 | the address of the array instead of its contents. This is | |
3750 | not what we want. */ | |
fa4727a6 | 3751 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3752 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3753 | { |
fa4727a6 DJ |
3754 | if (new_val != NULL) |
3755 | { | |
3756 | release_value (new_val); | |
3757 | value_free_to_mark (mark); | |
3758 | } | |
c906108c SS |
3759 | bs->old_val = b->val; |
3760 | b->val = new_val; | |
fa4727a6 | 3761 | b->val_valid = 1; |
c906108c SS |
3762 | return WP_VALUE_CHANGED; |
3763 | } | |
3764 | else | |
3765 | { | |
60e1c644 | 3766 | /* Nothing changed. */ |
c906108c | 3767 | value_free_to_mark (mark); |
c906108c SS |
3768 | return WP_VALUE_NOT_CHANGED; |
3769 | } | |
3770 | } | |
3771 | else | |
3772 | { | |
3773 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3774 | if we temporarily ignored the watchpoint, then when |
3775 | we reenter the block in which it is valid it contains | |
3776 | garbage (in the case of a function, it may have two | |
3777 | garbage values, one before and one after the prologue). | |
3778 | So we can't even detect the first assignment to it and | |
3779 | watch after that (since the garbage may or may not equal | |
3780 | the first value assigned). */ | |
4ce44c66 JM |
3781 | /* We print all the stop information in print_it_typical(), but |
3782 | in this case, by the time we call print_it_typical() this bp | |
4a64f543 MS |
3783 | will be deleted already. So we have no choice but print the |
3784 | information here. */ | |
9dc5e2a9 | 3785 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3786 | ui_out_field_string |
3787 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3788 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3789 | ui_out_field_int (uiout, "wpnum", b->number); |
3e43a32a MS |
3790 | ui_out_text (uiout, |
3791 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3792 | which its expression is valid.\n"); |
4ce44c66 | 3793 | |
c906108c | 3794 | if (b->related_breakpoint) |
60e1c644 PA |
3795 | { |
3796 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3797 | b->related_breakpoint->related_breakpoint = NULL; | |
3798 | b->related_breakpoint = NULL; | |
3799 | } | |
b5de0fa7 | 3800 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3801 | |
3802 | return WP_DELETED; | |
3803 | } | |
3804 | } | |
3805 | ||
18a18393 VP |
3806 | /* Return true if it looks like target has stopped due to hitting |
3807 | breakpoint location BL. This function does not check if we | |
3808 | should stop, only if BL explains the stop. */ | |
3809 | static int | |
6c95b8df PA |
3810 | bpstat_check_location (const struct bp_location *bl, |
3811 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3812 | { |
3813 | struct breakpoint *b = bl->owner; | |
3814 | ||
2bdf28a0 JK |
3815 | /* BL is from existing struct breakpoint. */ |
3816 | gdb_assert (b != NULL); | |
3817 | ||
e8595ef6 SS |
3818 | /* By definition, the inferior does not report stops at |
3819 | tracepoints. */ | |
d77f58be | 3820 | if (is_tracepoint (b)) |
e8595ef6 SS |
3821 | return 0; |
3822 | ||
cc60f2e3 | 3823 | if (!is_watchpoint (b) |
18a18393 | 3824 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3825 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3826 | { |
6c95b8df PA |
3827 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3828 | aspace, bp_addr)) | |
18a18393 VP |
3829 | return 0; |
3830 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3831 | && section_is_overlay (bl->section) |
18a18393 VP |
3832 | && !section_is_mapped (bl->section)) |
3833 | return 0; | |
3834 | } | |
cc60f2e3 | 3835 | |
18a18393 VP |
3836 | /* Continuable hardware watchpoints are treated as non-existent if the |
3837 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3838 | some data address). Otherwise gdb won't stop on a break instruction | |
3839 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3840 | been defined. Also skip watchpoints which we know did not trigger | |
3841 | (did not match the data address). */ | |
cc60f2e3 PA |
3842 | |
3843 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3844 | && b->watchpoint_triggered == watch_triggered_no) |
3845 | return 0; | |
3846 | ||
3847 | if (b->type == bp_hardware_breakpoint) | |
3848 | { | |
3849 | if (bl->address != bp_addr) | |
3850 | return 0; | |
3851 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3852 | && section_is_overlay (bl->section) |
18a18393 VP |
3853 | && !section_is_mapped (bl->section)) |
3854 | return 0; | |
3855 | } | |
ce78b96d | 3856 | |
ce78b96d JB |
3857 | if (b->type == bp_catchpoint) |
3858 | { | |
3859 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3860 | if (!b->ops->breakpoint_hit (b)) | |
3861 | return 0; | |
3862 | } | |
3863 | ||
18a18393 VP |
3864 | return 1; |
3865 | } | |
3866 | ||
3867 | /* If BS refers to a watchpoint, determine if the watched values | |
3868 | has actually changed, and we should stop. If not, set BS->stop | |
3869 | to 0. */ | |
3870 | static void | |
3871 | bpstat_check_watchpoint (bpstat bs) | |
3872 | { | |
2bdf28a0 JK |
3873 | const struct bp_location *bl; |
3874 | struct breakpoint *b; | |
3875 | ||
3876 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3877 | bl = bs->bp_location_at; |
2bdf28a0 | 3878 | gdb_assert (bl != NULL); |
f431efe5 | 3879 | b = bs->breakpoint_at; |
2bdf28a0 | 3880 | gdb_assert (b != NULL); |
18a18393 | 3881 | |
cc60f2e3 | 3882 | if (is_watchpoint (b)) |
18a18393 | 3883 | { |
18a18393 VP |
3884 | int must_check_value = 0; |
3885 | ||
3886 | if (b->type == bp_watchpoint) | |
3887 | /* For a software watchpoint, we must always check the | |
3888 | watched value. */ | |
3889 | must_check_value = 1; | |
3890 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3891 | /* We have a hardware watchpoint (read, write, or access) | |
3892 | and the target earlier reported an address watched by | |
3893 | this watchpoint. */ | |
3894 | must_check_value = 1; | |
3895 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3896 | && b->type == bp_hardware_watchpoint) | |
3897 | /* We were stopped by a hardware watchpoint, but the target could | |
3898 | not report the data address. We must check the watchpoint's | |
3899 | value. Access and read watchpoints are out of luck; without | |
3900 | a data address, we can't figure it out. */ | |
3901 | must_check_value = 1; | |
3902 | ||
3903 | if (must_check_value) | |
3904 | { | |
3e43a32a MS |
3905 | char *message |
3906 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3907 | b->number); | |
18a18393 VP |
3908 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3909 | int e = catch_errors (watchpoint_check, bs, message, | |
3910 | RETURN_MASK_ALL); | |
3911 | do_cleanups (cleanups); | |
3912 | switch (e) | |
3913 | { | |
3914 | case WP_DELETED: | |
3915 | /* We've already printed what needs to be printed. */ | |
3916 | bs->print_it = print_it_done; | |
3917 | /* Stop. */ | |
3918 | break; | |
60e1c644 PA |
3919 | case WP_IGNORE: |
3920 | bs->print_it = print_it_noop; | |
3921 | bs->stop = 0; | |
3922 | break; | |
18a18393 VP |
3923 | case WP_VALUE_CHANGED: |
3924 | if (b->type == bp_read_watchpoint) | |
3925 | { | |
85d721b8 PA |
3926 | /* There are two cases to consider here: |
3927 | ||
4a64f543 | 3928 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3929 | In that case, trust the target, and always report |
3930 | the watchpoint hit to the user. Even though | |
3931 | reads don't cause value changes, the value may | |
3932 | have changed since the last time it was read, and | |
3933 | since we're not trapping writes, we will not see | |
3934 | those, and as such we should ignore our notion of | |
3935 | old value. | |
3936 | ||
4a64f543 | 3937 | 2. We're watching the triggered memory for both |
85d721b8 PA |
3938 | reads and writes. There are two ways this may |
3939 | happen: | |
3940 | ||
4a64f543 | 3941 | 2.1. This is a target that can't break on data |
85d721b8 PA |
3942 | reads only, but can break on accesses (reads or |
3943 | writes), such as e.g., x86. We detect this case | |
3944 | at the time we try to insert read watchpoints. | |
3945 | ||
4a64f543 | 3946 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
3947 | watchpoints, but, the user set an access or write |
3948 | watchpoint watching the same memory as this read | |
3949 | watchpoint. | |
3950 | ||
3951 | If we're watching memory writes as well as reads, | |
3952 | ignore watchpoint hits when we find that the | |
3953 | value hasn't changed, as reads don't cause | |
3954 | changes. This still gives false positives when | |
3955 | the program writes the same value to memory as | |
3956 | what there was already in memory (we will confuse | |
3957 | it for a read), but it's much better than | |
3958 | nothing. */ | |
3959 | ||
3960 | int other_write_watchpoint = 0; | |
3961 | ||
3962 | if (bl->watchpoint_type == hw_read) | |
3963 | { | |
3964 | struct breakpoint *other_b; | |
3965 | ||
3966 | ALL_BREAKPOINTS (other_b) | |
3967 | if ((other_b->type == bp_hardware_watchpoint | |
3968 | || other_b->type == bp_access_watchpoint) | |
3969 | && (other_b->watchpoint_triggered | |
3970 | == watch_triggered_yes)) | |
3971 | { | |
3972 | other_write_watchpoint = 1; | |
3973 | break; | |
3974 | } | |
3975 | } | |
3976 | ||
3977 | if (other_write_watchpoint | |
3978 | || bl->watchpoint_type == hw_access) | |
3979 | { | |
3980 | /* We're watching the same memory for writes, | |
3981 | and the value changed since the last time we | |
3982 | updated it, so this trap must be for a write. | |
3983 | Ignore it. */ | |
3984 | bs->print_it = print_it_noop; | |
3985 | bs->stop = 0; | |
3986 | } | |
18a18393 VP |
3987 | } |
3988 | break; | |
3989 | case WP_VALUE_NOT_CHANGED: | |
3990 | if (b->type == bp_hardware_watchpoint | |
3991 | || b->type == bp_watchpoint) | |
3992 | { | |
3993 | /* Don't stop: write watchpoints shouldn't fire if | |
3994 | the value hasn't changed. */ | |
3995 | bs->print_it = print_it_noop; | |
3996 | bs->stop = 0; | |
3997 | } | |
3998 | /* Stop. */ | |
3999 | break; | |
4000 | default: | |
4001 | /* Can't happen. */ | |
4002 | case 0: | |
4003 | /* Error from catch_errors. */ | |
4004 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
4005 | if (b->related_breakpoint) | |
4006 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
4007 | b->disposition = disp_del_at_next_stop; | |
4008 | /* We've already printed what needs to be printed. */ | |
4009 | bs->print_it = print_it_done; | |
4010 | break; | |
4011 | } | |
4012 | } | |
4013 | else /* must_check_value == 0 */ | |
4014 | { | |
4015 | /* This is a case where some watchpoint(s) triggered, but | |
4016 | not at the address of this watchpoint, or else no | |
4017 | watchpoint triggered after all. So don't print | |
4018 | anything for this watchpoint. */ | |
4019 | bs->print_it = print_it_noop; | |
4020 | bs->stop = 0; | |
4021 | } | |
4022 | } | |
4023 | } | |
4024 | ||
4025 | ||
4026 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4027 | of breakpoint referred to by BS. If we should not stop for this | |
4028 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4029 | |
18a18393 VP |
4030 | static void |
4031 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4032 | { | |
4033 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4034 | const struct bp_location *bl; |
4035 | struct breakpoint *b; | |
4036 | ||
4037 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4038 | bl = bs->bp_location_at; |
2bdf28a0 | 4039 | gdb_assert (bl != NULL); |
f431efe5 | 4040 | b = bs->breakpoint_at; |
2bdf28a0 | 4041 | gdb_assert (b != NULL); |
18a18393 VP |
4042 | |
4043 | if (frame_id_p (b->frame_id) | |
edb3359d | 4044 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4045 | bs->stop = 0; |
4046 | else if (bs->stop) | |
4047 | { | |
4048 | int value_is_zero = 0; | |
60e1c644 PA |
4049 | struct expression *cond; |
4050 | ||
60e1c644 PA |
4051 | if (is_watchpoint (b)) |
4052 | cond = b->cond_exp; | |
4053 | else | |
4054 | cond = bl->cond; | |
4055 | ||
f431efe5 | 4056 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4057 | { |
60e1c644 PA |
4058 | int within_current_scope = 1; |
4059 | ||
c5bc3a77 DJ |
4060 | /* We use value_mark and value_free_to_mark because it could |
4061 | be a long time before we return to the command level and | |
4062 | call free_all_values. We can't call free_all_values | |
4063 | because we might be in the middle of evaluating a | |
4064 | function call. */ | |
4065 | struct value *mark = value_mark (); | |
4066 | ||
edb3359d DJ |
4067 | /* Need to select the frame, with all that implies so that |
4068 | the conditions will have the right context. Because we | |
4069 | use the frame, we will not see an inlined function's | |
4070 | variables when we arrive at a breakpoint at the start | |
4071 | of the inlined function; the current frame will be the | |
4072 | call site. */ | |
60e1c644 PA |
4073 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
4074 | select_frame (get_current_frame ()); | |
4075 | else | |
4076 | { | |
4077 | struct frame_info *frame; | |
4078 | ||
4079 | /* For local watchpoint expressions, which particular | |
4080 | instance of a local is being watched matters, so we | |
4081 | keep track of the frame to evaluate the expression | |
4082 | in. To evaluate the condition however, it doesn't | |
4083 | really matter which instantiation of the function | |
4084 | where the condition makes sense triggers the | |
4085 | watchpoint. This allows an expression like "watch | |
4086 | global if q > 10" set in `func', catch writes to | |
4087 | global on all threads that call `func', or catch | |
4088 | writes on all recursive calls of `func' by a single | |
4089 | thread. We simply always evaluate the condition in | |
4090 | the innermost frame that's executing where it makes | |
4091 | sense to evaluate the condition. It seems | |
4092 | intuitive. */ | |
4093 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4094 | if (frame != NULL) | |
4095 | select_frame (frame); | |
4096 | else | |
4097 | within_current_scope = 0; | |
4098 | } | |
4099 | if (within_current_scope) | |
4100 | value_is_zero | |
4101 | = catch_errors (breakpoint_cond_eval, cond, | |
4102 | "Error in testing breakpoint condition:\n", | |
4103 | RETURN_MASK_ALL); | |
4104 | else | |
4105 | { | |
4106 | warning (_("Watchpoint condition cannot be tested " | |
4107 | "in the current scope")); | |
4108 | /* If we failed to set the right context for this | |
4109 | watchpoint, unconditionally report it. */ | |
4110 | value_is_zero = 0; | |
4111 | } | |
4a64f543 | 4112 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4113 | value_free_to_mark (mark); |
18a18393 | 4114 | } |
60e1c644 PA |
4115 | |
4116 | if (cond && value_is_zero) | |
18a18393 VP |
4117 | { |
4118 | bs->stop = 0; | |
4119 | } | |
4120 | else if (b->thread != -1 && b->thread != thread_id) | |
4121 | { | |
4122 | bs->stop = 0; | |
4123 | } | |
4124 | else if (b->ignore_count > 0) | |
4125 | { | |
4126 | b->ignore_count--; | |
4127 | annotate_ignore_count_change (); | |
4128 | bs->stop = 0; | |
4a64f543 | 4129 | /* Increase the hit count even though we don't stop. */ |
18a18393 VP |
4130 | ++(b->hit_count); |
4131 | } | |
4132 | } | |
4133 | } | |
4134 | ||
4135 | ||
9709f61c | 4136 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4137 | BP_ADDR in thread PTID. |
c906108c | 4138 | |
d983da9c | 4139 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4140 | don't understand this stop. Result is a chain of bpstat's such |
4141 | that: | |
c906108c | 4142 | |
c5aa993b | 4143 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4144 | |
c5aa993b | 4145 | if we understand why we stopped, the result is not null. |
c906108c | 4146 | |
c5aa993b JM |
4147 | Each element of the chain refers to a particular breakpoint or |
4148 | watchpoint at which we have stopped. (We may have stopped for | |
4149 | several reasons concurrently.) | |
c906108c | 4150 | |
c5aa993b JM |
4151 | Each element of the chain has valid next, breakpoint_at, |
4152 | commands, FIXME??? fields. */ | |
c906108c SS |
4153 | |
4154 | bpstat | |
6c95b8df PA |
4155 | bpstat_stop_status (struct address_space *aspace, |
4156 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4157 | { |
0d381245 | 4158 | struct breakpoint *b = NULL; |
afe38095 | 4159 | struct bp_location *bl; |
20874c92 | 4160 | struct bp_location *loc; |
5760d0ab JK |
4161 | /* First item of allocated bpstat's. */ |
4162 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4163 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4164 | bpstat bs; |
20874c92 | 4165 | int ix; |
429374b8 | 4166 | int need_remove_insert; |
f431efe5 | 4167 | int removed_any; |
c906108c | 4168 | |
f431efe5 PA |
4169 | /* First, build the bpstat chain with locations that explain a |
4170 | target stop, while being careful to not set the target running, | |
4171 | as that may invalidate locations (in particular watchpoint | |
4172 | locations are recreated). Resuming will happen here with | |
4173 | breakpoint conditions or watchpoint expressions that include | |
4174 | inferior function calls. */ | |
c5aa993b | 4175 | |
429374b8 JK |
4176 | ALL_BREAKPOINTS (b) |
4177 | { | |
4178 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4179 | continue; | |
a5606eee | 4180 | |
429374b8 JK |
4181 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4182 | { | |
4a64f543 MS |
4183 | /* For hardware watchpoints, we look only at the first |
4184 | location. The watchpoint_check function will work on the | |
4185 | entire expression, not the individual locations. For | |
4186 | read watchpoints, the watchpoints_triggered function has | |
4187 | checked all locations already. */ | |
429374b8 JK |
4188 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4189 | break; | |
18a18393 | 4190 | |
429374b8 JK |
4191 | if (bl->shlib_disabled) |
4192 | continue; | |
c5aa993b | 4193 | |
429374b8 JK |
4194 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4195 | continue; | |
c5aa993b | 4196 | |
4a64f543 MS |
4197 | /* Come here if it's a watchpoint, or if the break address |
4198 | matches. */ | |
c5aa993b | 4199 | |
4a64f543 MS |
4200 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4201 | explain stop. */ | |
c5aa993b | 4202 | |
f431efe5 PA |
4203 | /* Assume we stop. Should we find a watchpoint that is not |
4204 | actually triggered, or if the condition of the breakpoint | |
4205 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4206 | bs->stop = 1; |
4207 | bs->print = 1; | |
d983da9c | 4208 | |
f431efe5 PA |
4209 | /* If this is a scope breakpoint, mark the associated |
4210 | watchpoint as triggered so that we will handle the | |
4211 | out-of-scope event. We'll get to the watchpoint next | |
4212 | iteration. */ | |
4213 | if (b->type == bp_watchpoint_scope) | |
4214 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
4215 | } | |
4216 | } | |
4217 | ||
4218 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4219 | { | |
4220 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, | |
4221 | aspace, bp_addr)) | |
4222 | { | |
5760d0ab | 4223 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4224 | /* For hits of moribund locations, we should just proceed. */ |
4225 | bs->stop = 0; | |
4226 | bs->print = 0; | |
4227 | bs->print_it = print_it_noop; | |
4228 | } | |
4229 | } | |
4230 | ||
f431efe5 PA |
4231 | /* Now go through the locations that caused the target to stop, and |
4232 | check whether we're interested in reporting this stop to higher | |
4233 | layers, or whether we should resume the target transparently. */ | |
4234 | ||
4235 | removed_any = 0; | |
4236 | ||
5760d0ab | 4237 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4238 | { |
4239 | if (!bs->stop) | |
4240 | continue; | |
4241 | ||
4242 | bpstat_check_watchpoint (bs); | |
4243 | if (!bs->stop) | |
4244 | continue; | |
4245 | ||
4246 | b = bs->breakpoint_at; | |
18a18393 | 4247 | |
429374b8 | 4248 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d | 4249 | || b->type == bp_longjmp_master |
186c406b TT |
4250 | || b->type == bp_std_terminate_master |
4251 | || b->type == bp_exception_master) | |
429374b8 JK |
4252 | /* We do not stop for these. */ |
4253 | bs->stop = 0; | |
4254 | else | |
4255 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4256 | |
429374b8 JK |
4257 | if (bs->stop) |
4258 | { | |
4259 | ++(b->hit_count); | |
c906108c | 4260 | |
4a64f543 | 4261 | /* We will stop here. */ |
429374b8 JK |
4262 | if (b->disposition == disp_disable) |
4263 | { | |
4264 | if (b->enable_state != bp_permanent) | |
4265 | b->enable_state = bp_disabled; | |
f431efe5 | 4266 | removed_any = 1; |
429374b8 JK |
4267 | } |
4268 | if (b->silent) | |
4269 | bs->print = 0; | |
4270 | bs->commands = b->commands; | |
9add0f1b TT |
4271 | incref_counted_command_line (bs->commands); |
4272 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4273 | if (bs->commands_left | |
4274 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4275 | || (xdb_commands | |
4276 | && strcmp ("Q", | |
4277 | bs->commands_left->line) == 0))) | |
429374b8 | 4278 | { |
9add0f1b | 4279 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4280 | bs->print = 0; |
4281 | } | |
429374b8 JK |
4282 | } |
4283 | ||
4284 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4285 | if (bs->stop == 0 || bs->print == 0) | |
4286 | bs->print_it = print_it_noop; | |
429374b8 | 4287 | } |
876fa593 | 4288 | |
d983da9c DJ |
4289 | /* If we aren't stopping, the value of some hardware watchpoint may |
4290 | not have changed, but the intermediate memory locations we are | |
4291 | watching may have. Don't bother if we're stopping; this will get | |
4292 | done later. */ | |
d832cb68 | 4293 | need_remove_insert = 0; |
5760d0ab JK |
4294 | if (! bpstat_causes_stop (bs_head)) |
4295 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4296 | if (!bs->stop |
f431efe5 PA |
4297 | && bs->breakpoint_at |
4298 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4299 | { |
4a64f543 | 4300 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4301 | need_remove_insert = 1; |
d983da9c DJ |
4302 | } |
4303 | ||
d832cb68 | 4304 | if (need_remove_insert) |
2d134ed3 | 4305 | update_global_location_list (1); |
f431efe5 PA |
4306 | else if (removed_any) |
4307 | update_global_location_list (0); | |
d832cb68 | 4308 | |
5760d0ab | 4309 | return bs_head; |
c906108c | 4310 | } |
628fe4e4 JK |
4311 | |
4312 | static void | |
4313 | handle_jit_event (void) | |
4314 | { | |
4315 | struct frame_info *frame; | |
4316 | struct gdbarch *gdbarch; | |
4317 | ||
4318 | /* Switch terminal for any messages produced by | |
4319 | breakpoint_re_set. */ | |
4320 | target_terminal_ours_for_output (); | |
4321 | ||
4322 | frame = get_current_frame (); | |
4323 | gdbarch = get_frame_arch (frame); | |
4324 | ||
4325 | jit_event_handler (gdbarch); | |
4326 | ||
4327 | target_terminal_inferior (); | |
4328 | } | |
4329 | ||
4330 | /* Prepare WHAT final decision for infrun. */ | |
4331 | ||
4332 | /* Decide what infrun needs to do with this bpstat. */ | |
4333 | ||
c906108c | 4334 | struct bpstat_what |
fba45db2 | 4335 | bpstat_what (bpstat bs) |
c906108c | 4336 | { |
c906108c | 4337 | struct bpstat_what retval; |
628fe4e4 JK |
4338 | /* We need to defer calling `solib_add', as adding new symbols |
4339 | resets breakpoints, which in turn deletes breakpoint locations, | |
4340 | and hence may clear unprocessed entries in the BS chain. */ | |
4341 | int shlib_event = 0; | |
4342 | int jit_event = 0; | |
c906108c | 4343 | |
628fe4e4 | 4344 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4345 | retval.call_dummy = STOP_NONE; |
186c406b | 4346 | retval.is_longjmp = 0; |
628fe4e4 | 4347 | |
c906108c SS |
4348 | for (; bs != NULL; bs = bs->next) |
4349 | { | |
628fe4e4 JK |
4350 | /* Extract this BS's action. After processing each BS, we check |
4351 | if its action overrides all we've seem so far. */ | |
4352 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4353 | enum bptype bptype; | |
4354 | ||
c906108c | 4355 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4356 | { |
4357 | /* I suspect this can happen if it was a momentary | |
4358 | breakpoint which has since been deleted. */ | |
4359 | bptype = bp_none; | |
4360 | } | |
f431efe5 | 4361 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4362 | bptype = bp_none; |
20874c92 | 4363 | else |
f431efe5 | 4364 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4365 | |
4366 | switch (bptype) | |
c906108c SS |
4367 | { |
4368 | case bp_none: | |
628fe4e4 | 4369 | break; |
c906108c SS |
4370 | case bp_breakpoint: |
4371 | case bp_hardware_breakpoint: | |
4372 | case bp_until: | |
4373 | case bp_finish: | |
4374 | if (bs->stop) | |
4375 | { | |
4376 | if (bs->print) | |
628fe4e4 | 4377 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4378 | else |
628fe4e4 | 4379 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4380 | } |
4381 | else | |
628fe4e4 | 4382 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4383 | break; |
4384 | case bp_watchpoint: | |
4385 | case bp_hardware_watchpoint: | |
4386 | case bp_read_watchpoint: | |
4387 | case bp_access_watchpoint: | |
4388 | if (bs->stop) | |
4389 | { | |
4390 | if (bs->print) | |
628fe4e4 | 4391 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4392 | else |
628fe4e4 | 4393 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4394 | } |
4395 | else | |
628fe4e4 JK |
4396 | { |
4397 | /* There was a watchpoint, but we're not stopping. | |
4398 | This requires no further action. */ | |
4399 | } | |
c906108c SS |
4400 | break; |
4401 | case bp_longjmp: | |
186c406b | 4402 | case bp_exception: |
628fe4e4 | 4403 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4404 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4405 | break; |
4406 | case bp_longjmp_resume: | |
186c406b | 4407 | case bp_exception_resume: |
628fe4e4 | 4408 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4409 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4410 | break; |
4411 | case bp_step_resume: | |
4412 | if (bs->stop) | |
628fe4e4 JK |
4413 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4414 | else | |
c906108c | 4415 | { |
628fe4e4 JK |
4416 | /* It is for the wrong frame. */ |
4417 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4418 | } |
c906108c | 4419 | break; |
c906108c | 4420 | case bp_watchpoint_scope: |
c4093a6a | 4421 | case bp_thread_event: |
1900040c | 4422 | case bp_overlay_event: |
0fd8e87f | 4423 | case bp_longjmp_master: |
aa7d318d | 4424 | case bp_std_terminate_master: |
186c406b | 4425 | case bp_exception_master: |
628fe4e4 | 4426 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4427 | break; |
ce78b96d | 4428 | case bp_catchpoint: |
c5aa993b JM |
4429 | if (bs->stop) |
4430 | { | |
4431 | if (bs->print) | |
628fe4e4 | 4432 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4433 | else |
628fe4e4 | 4434 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4435 | } |
4436 | else | |
628fe4e4 JK |
4437 | { |
4438 | /* There was a catchpoint, but we're not stopping. | |
4439 | This requires no further action. */ | |
4440 | } | |
4441 | break; | |
4442 | case bp_shlib_event: | |
4443 | shlib_event = 1; | |
4444 | ||
4445 | /* If requested, stop when the dynamic linker notifies GDB | |
4446 | of events. This allows the user to get control and place | |
4447 | breakpoints in initializer routines for dynamically | |
4448 | loaded objects (among other things). */ | |
4449 | if (stop_on_solib_events) | |
4450 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4451 | else | |
4452 | this_action = BPSTAT_WHAT_SINGLE; | |
4453 | break; | |
4454 | case bp_jit_event: | |
4455 | jit_event = 1; | |
4456 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4457 | break; |
c906108c | 4458 | case bp_call_dummy: |
53a5351d JM |
4459 | /* Make sure the action is stop (silent or noisy), |
4460 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4461 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4462 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4463 | break; |
4464 | case bp_std_terminate: | |
4465 | /* Make sure the action is stop (silent or noisy), | |
4466 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4467 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4468 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4469 | break; |
1042e4c0 | 4470 | case bp_tracepoint: |
7a697b8d | 4471 | case bp_fast_tracepoint: |
0fb4aa4b | 4472 | case bp_static_tracepoint: |
1042e4c0 SS |
4473 | /* Tracepoint hits should not be reported back to GDB, and |
4474 | if one got through somehow, it should have been filtered | |
4475 | out already. */ | |
4476 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4477 | _("bpstat_what: tracepoint encountered")); |
628fe4e4 JK |
4478 | default: |
4479 | internal_error (__FILE__, __LINE__, | |
4480 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4481 | } |
628fe4e4 JK |
4482 | |
4483 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4484 | } |
628fe4e4 JK |
4485 | |
4486 | if (shlib_event) | |
4487 | { | |
4488 | if (debug_infrun) | |
4489 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4490 | ||
4491 | /* Check for any newly added shared libraries if we're supposed | |
4492 | to be adding them automatically. */ | |
4493 | ||
4494 | /* Switch terminal for any messages produced by | |
4495 | breakpoint_re_set. */ | |
4496 | target_terminal_ours_for_output (); | |
4497 | ||
4498 | #ifdef SOLIB_ADD | |
4499 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4500 | #else | |
4501 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4502 | #endif | |
4503 | ||
4504 | target_terminal_inferior (); | |
4505 | } | |
4506 | ||
4507 | if (jit_event) | |
4508 | { | |
4509 | if (debug_infrun) | |
4510 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4511 | ||
4512 | handle_jit_event (); | |
4513 | } | |
4514 | ||
c906108c SS |
4515 | return retval; |
4516 | } | |
4517 | ||
4518 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4519 | without hardware support). This isn't related to a specific bpstat, | |
4520 | just to things like whether watchpoints are set. */ | |
4521 | ||
c5aa993b | 4522 | int |
fba45db2 | 4523 | bpstat_should_step (void) |
c906108c SS |
4524 | { |
4525 | struct breakpoint *b; | |
cc59ec59 | 4526 | |
c906108c | 4527 | ALL_BREAKPOINTS (b) |
717a8278 | 4528 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4529 | return 1; |
c906108c SS |
4530 | return 0; |
4531 | } | |
4532 | ||
67822962 PA |
4533 | int |
4534 | bpstat_causes_stop (bpstat bs) | |
4535 | { | |
4536 | for (; bs != NULL; bs = bs->next) | |
4537 | if (bs->stop) | |
4538 | return 1; | |
4539 | ||
4540 | return 0; | |
4541 | } | |
4542 | ||
c906108c | 4543 | \f |
c5aa993b | 4544 | |
859825b8 JK |
4545 | /* Print the LOC location out of the list of B->LOC locations. */ |
4546 | ||
0d381245 VP |
4547 | static void print_breakpoint_location (struct breakpoint *b, |
4548 | struct bp_location *loc, | |
4549 | char *wrap_indent, | |
4550 | struct ui_stream *stb) | |
4551 | { | |
6c95b8df PA |
4552 | struct cleanup *old_chain = save_current_program_space (); |
4553 | ||
859825b8 JK |
4554 | if (loc != NULL && loc->shlib_disabled) |
4555 | loc = NULL; | |
4556 | ||
6c95b8df PA |
4557 | if (loc != NULL) |
4558 | set_current_program_space (loc->pspace); | |
4559 | ||
859825b8 | 4560 | if (b->source_file && loc) |
0d381245 VP |
4561 | { |
4562 | struct symbol *sym | |
4563 | = find_pc_sect_function (loc->address, loc->section); | |
4564 | if (sym) | |
4565 | { | |
4566 | ui_out_text (uiout, "in "); | |
4567 | ui_out_field_string (uiout, "func", | |
4568 | SYMBOL_PRINT_NAME (sym)); | |
4569 | ui_out_wrap_hint (uiout, wrap_indent); | |
4570 | ui_out_text (uiout, " at "); | |
4571 | } | |
4572 | ui_out_field_string (uiout, "file", b->source_file); | |
4573 | ui_out_text (uiout, ":"); | |
4574 | ||
4575 | if (ui_out_is_mi_like_p (uiout)) | |
4576 | { | |
4577 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4578 | char *fullname = symtab_to_fullname (sal.symtab); | |
4579 | ||
4580 | if (fullname) | |
4581 | ui_out_field_string (uiout, "fullname", fullname); | |
4582 | } | |
4583 | ||
4584 | ui_out_field_int (uiout, "line", b->line_number); | |
4585 | } | |
859825b8 | 4586 | else if (loc) |
0d381245 | 4587 | { |
22e722e1 DJ |
4588 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4589 | demangle, ""); | |
0d381245 VP |
4590 | ui_out_field_stream (uiout, "at", stb); |
4591 | } | |
859825b8 JK |
4592 | else |
4593 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4594 | |
4595 | do_cleanups (old_chain); | |
0d381245 VP |
4596 | } |
4597 | ||
269b11a2 PA |
4598 | static const char * |
4599 | bptype_string (enum bptype type) | |
c906108c | 4600 | { |
c4093a6a JM |
4601 | struct ep_type_description |
4602 | { | |
4603 | enum bptype type; | |
4604 | char *description; | |
4605 | }; | |
4606 | static struct ep_type_description bptypes[] = | |
c906108c | 4607 | { |
c5aa993b JM |
4608 | {bp_none, "?deleted?"}, |
4609 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4610 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4611 | {bp_until, "until"}, |
4612 | {bp_finish, "finish"}, | |
4613 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4614 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4615 | {bp_read_watchpoint, "read watchpoint"}, |
4616 | {bp_access_watchpoint, "acc watchpoint"}, | |
4617 | {bp_longjmp, "longjmp"}, | |
4618 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4619 | {bp_exception, "exception"}, |
4620 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4621 | {bp_step_resume, "step resume"}, |
c5aa993b JM |
4622 | {bp_watchpoint_scope, "watchpoint scope"}, |
4623 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4624 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4625 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4626 | {bp_thread_event, "thread events"}, |
1900040c | 4627 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4628 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4629 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4630 | {bp_exception_master, "exception master"}, |
ce78b96d | 4631 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4632 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4633 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4634 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4635 | {bp_jit_event, "jit events"}, |
c5aa993b | 4636 | }; |
269b11a2 PA |
4637 | |
4638 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4639 | || ((int) type != bptypes[(int) type].type)) | |
4640 | internal_error (__FILE__, __LINE__, | |
4641 | _("bptypes table does not describe type #%d."), | |
4642 | (int) type); | |
4643 | ||
4644 | return bptypes[(int) type].description; | |
4645 | } | |
4646 | ||
4647 | /* Print B to gdb_stdout. */ | |
4648 | ||
4649 | static void | |
4650 | print_one_breakpoint_location (struct breakpoint *b, | |
4651 | struct bp_location *loc, | |
4652 | int loc_number, | |
4653 | struct bp_location **last_loc, | |
4654 | int print_address_bits, | |
4655 | int allflag) | |
4656 | { | |
4657 | struct command_line *l; | |
c2c6d25f | 4658 | static char bpenables[] = "nynny"; |
c906108c | 4659 | char wrap_indent[80]; |
8b93c638 JM |
4660 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4661 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4662 | struct cleanup *bkpt_chain; |
c906108c | 4663 | |
0d381245 VP |
4664 | int header_of_multiple = 0; |
4665 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4666 | struct value_print_options opts; |
4667 | ||
4668 | get_user_print_options (&opts); | |
0d381245 VP |
4669 | |
4670 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4671 | /* See comment in print_one_breakpoint concerning treatment of |
4672 | breakpoints with single disabled location. */ | |
0d381245 VP |
4673 | if (loc == NULL |
4674 | && (b->loc != NULL | |
4675 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4676 | header_of_multiple = 1; | |
4677 | if (loc == NULL) | |
4678 | loc = b->loc; | |
4679 | ||
c4093a6a | 4680 | annotate_record (); |
3b31d625 | 4681 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4682 | |
4683 | /* 1 */ | |
4684 | annotate_field (0); | |
0d381245 VP |
4685 | if (part_of_multiple) |
4686 | { | |
4687 | char *formatted; | |
0c6773c1 | 4688 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4689 | ui_out_field_string (uiout, "number", formatted); |
4690 | xfree (formatted); | |
4691 | } | |
4692 | else | |
4693 | { | |
4694 | ui_out_field_int (uiout, "number", b->number); | |
4695 | } | |
c4093a6a JM |
4696 | |
4697 | /* 2 */ | |
4698 | annotate_field (1); | |
0d381245 VP |
4699 | if (part_of_multiple) |
4700 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4701 | else |
4702 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4703 | |
4704 | /* 3 */ | |
4705 | annotate_field (2); | |
0d381245 VP |
4706 | if (part_of_multiple) |
4707 | ui_out_field_skip (uiout, "disp"); | |
4708 | else | |
2cec12e5 | 4709 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4710 | |
c4093a6a JM |
4711 | |
4712 | /* 4 */ | |
4713 | annotate_field (3); | |
0d381245 | 4714 | if (part_of_multiple) |
54e52265 | 4715 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4716 | else |
4a64f543 MS |
4717 | ui_out_field_fmt (uiout, "enabled", "%c", |
4718 | bpenables[(int) b->enable_state]); | |
54e52265 | 4719 | ui_out_spaces (uiout, 2); |
0d381245 | 4720 | |
c4093a6a JM |
4721 | |
4722 | /* 5 and 6 */ | |
4723 | strcpy (wrap_indent, " "); | |
79a45b7d | 4724 | if (opts.addressprint) |
75ac9d7b | 4725 | { |
a6d9a66e | 4726 | if (print_address_bits <= 32) |
75ac9d7b MS |
4727 | strcat (wrap_indent, " "); |
4728 | else | |
4729 | strcat (wrap_indent, " "); | |
4730 | } | |
c906108c | 4731 | |
3086aeae | 4732 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4733 | { |
4a64f543 MS |
4734 | /* Although the print_one can possibly print all locations, |
4735 | calling it here is not likely to get any nice result. So, | |
4736 | make sure there's just one location. */ | |
0d381245 | 4737 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4738 | b->ops->print_one (b, last_loc); |
0d381245 | 4739 | } |
3086aeae DJ |
4740 | else |
4741 | switch (b->type) | |
4742 | { | |
4743 | case bp_none: | |
4744 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4745 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4746 | break; |
c906108c | 4747 | |
3086aeae DJ |
4748 | case bp_watchpoint: |
4749 | case bp_hardware_watchpoint: | |
4750 | case bp_read_watchpoint: | |
4751 | case bp_access_watchpoint: | |
4752 | /* Field 4, the address, is omitted (which makes the columns | |
4753 | not line up too nicely with the headers, but the effect | |
4754 | is relatively readable). */ | |
79a45b7d | 4755 | if (opts.addressprint) |
3086aeae DJ |
4756 | ui_out_field_skip (uiout, "addr"); |
4757 | annotate_field (5); | |
fa8a61dc | 4758 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4759 | break; |
4760 | ||
3086aeae DJ |
4761 | case bp_breakpoint: |
4762 | case bp_hardware_breakpoint: | |
4763 | case bp_until: | |
4764 | case bp_finish: | |
4765 | case bp_longjmp: | |
4766 | case bp_longjmp_resume: | |
186c406b TT |
4767 | case bp_exception: |
4768 | case bp_exception_resume: | |
3086aeae | 4769 | case bp_step_resume: |
3086aeae DJ |
4770 | case bp_watchpoint_scope: |
4771 | case bp_call_dummy: | |
aa7d318d | 4772 | case bp_std_terminate: |
3086aeae DJ |
4773 | case bp_shlib_event: |
4774 | case bp_thread_event: | |
4775 | case bp_overlay_event: | |
0fd8e87f | 4776 | case bp_longjmp_master: |
aa7d318d | 4777 | case bp_std_terminate_master: |
186c406b | 4778 | case bp_exception_master: |
1042e4c0 | 4779 | case bp_tracepoint: |
7a697b8d | 4780 | case bp_fast_tracepoint: |
0fb4aa4b | 4781 | case bp_static_tracepoint: |
4efc6507 | 4782 | case bp_jit_event: |
79a45b7d | 4783 | if (opts.addressprint) |
3086aeae DJ |
4784 | { |
4785 | annotate_field (4); | |
54e52265 | 4786 | if (header_of_multiple) |
0d381245 | 4787 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4788 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4789 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4790 | else |
5af949e3 UW |
4791 | ui_out_field_core_addr (uiout, "addr", |
4792 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4793 | } |
4794 | annotate_field (5); | |
0d381245 VP |
4795 | if (!header_of_multiple) |
4796 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4797 | if (b->loc) | |
a6d9a66e | 4798 | *last_loc = b->loc; |
3086aeae DJ |
4799 | break; |
4800 | } | |
c906108c | 4801 | |
6c95b8df PA |
4802 | |
4803 | /* For backward compatibility, don't display inferiors unless there | |
4804 | are several. */ | |
4805 | if (loc != NULL | |
4806 | && !header_of_multiple | |
4807 | && (allflag | |
4808 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4809 | && (number_of_program_spaces () > 1 | |
4810 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4811 | /* LOC is for existing B, it cannot be in |
4812 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4813 | && loc->owner->type != bp_catchpoint))) |
4814 | { | |
4815 | struct inferior *inf; | |
4816 | int first = 1; | |
4817 | ||
4818 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4819 | { | |
4820 | if (inf->pspace == loc->pspace) | |
4821 | { | |
4822 | if (first) | |
4823 | { | |
4824 | first = 0; | |
4825 | ui_out_text (uiout, " inf "); | |
4826 | } | |
4827 | else | |
4828 | ui_out_text (uiout, ", "); | |
4829 | ui_out_text (uiout, plongest (inf->num)); | |
4830 | } | |
4831 | } | |
4832 | } | |
4833 | ||
4a306c9a | 4834 | if (!part_of_multiple) |
c4093a6a | 4835 | { |
4a306c9a JB |
4836 | if (b->thread != -1) |
4837 | { | |
4838 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4839 | "stop only in" line a little further down. */ |
4a306c9a JB |
4840 | ui_out_text (uiout, " thread "); |
4841 | ui_out_field_int (uiout, "thread", b->thread); | |
4842 | } | |
4843 | else if (b->task != 0) | |
4844 | { | |
4845 | ui_out_text (uiout, " task "); | |
4846 | ui_out_field_int (uiout, "task", b->task); | |
4847 | } | |
c4093a6a JM |
4848 | } |
4849 | ||
8b93c638 | 4850 | ui_out_text (uiout, "\n"); |
c4093a6a | 4851 | |
0fb4aa4b PA |
4852 | if (!part_of_multiple && b->static_trace_marker_id) |
4853 | { | |
4854 | gdb_assert (b->type == bp_static_tracepoint); | |
4855 | ||
4856 | ui_out_text (uiout, "\tmarker id is "); | |
4857 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
4858 | b->static_trace_marker_id); | |
4859 | ui_out_text (uiout, "\n"); | |
4860 | } | |
4861 | ||
0d381245 | 4862 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4863 | { |
4864 | annotate_field (6); | |
8b93c638 | 4865 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4866 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4867 | the frame ID. */ | |
5af949e3 UW |
4868 | ui_out_field_core_addr (uiout, "frame", |
4869 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4870 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4871 | } |
4872 | ||
0d381245 | 4873 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4874 | { |
f7f9143b JB |
4875 | /* We do not print the condition for Ada exception catchpoints |
4876 | because the condition is an internal implementation detail | |
4877 | that we do not want to expose to the user. */ | |
c4093a6a | 4878 | annotate_field (7); |
d77f58be | 4879 | if (is_tracepoint (b)) |
1042e4c0 SS |
4880 | ui_out_text (uiout, "\ttrace only if "); |
4881 | else | |
4882 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4883 | ui_out_field_string (uiout, "cond", b->cond_string); |
4884 | ui_out_text (uiout, "\n"); | |
4885 | } | |
4886 | ||
0d381245 | 4887 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 4888 | { |
4a64f543 | 4889 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4890 | ui_out_text (uiout, "\tstop only in thread "); |
4891 | ui_out_field_int (uiout, "thread", b->thread); | |
4892 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4893 | } |
4894 | ||
63c715c6 | 4895 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 4896 | { |
4a64f543 | 4897 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
4898 | if (ep_is_catchpoint (b)) |
4899 | ui_out_text (uiout, "\tcatchpoint"); | |
4900 | else | |
4901 | ui_out_text (uiout, "\tbreakpoint"); | |
4902 | ui_out_text (uiout, " already hit "); | |
4903 | ui_out_field_int (uiout, "times", b->hit_count); | |
4904 | if (b->hit_count == 1) | |
4905 | ui_out_text (uiout, " time\n"); | |
4906 | else | |
4907 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4908 | } |
4909 | ||
4a64f543 MS |
4910 | /* Output the count also if it is zero, but only if this is mi. |
4911 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4912 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4913 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4914 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4915 | |
0d381245 | 4916 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4917 | { |
4918 | annotate_field (8); | |
8b93c638 JM |
4919 | ui_out_text (uiout, "\tignore next "); |
4920 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4921 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4922 | } |
059fb39f | 4923 | |
9add0f1b | 4924 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4925 | if (!part_of_multiple && l) |
c4093a6a | 4926 | { |
3b31d625 EZ |
4927 | struct cleanup *script_chain; |
4928 | ||
c4093a6a | 4929 | annotate_field (9); |
3b31d625 | 4930 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4931 | print_command_lines (uiout, l, 4); |
3b31d625 | 4932 | do_cleanups (script_chain); |
c4093a6a | 4933 | } |
d24317b4 | 4934 | |
1042e4c0 SS |
4935 | if (!part_of_multiple && b->pass_count) |
4936 | { | |
4937 | annotate_field (10); | |
4938 | ui_out_text (uiout, "\tpass count "); | |
4939 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4940 | ui_out_text (uiout, " \n"); | |
4941 | } | |
4942 | ||
d24317b4 VP |
4943 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4944 | { | |
4945 | if (b->addr_string) | |
4946 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4947 | else if (b->exp_string) | |
4948 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4949 | } | |
4950 | ||
3b31d625 | 4951 | do_cleanups (bkpt_chain); |
8b93c638 | 4952 | do_cleanups (old_chain); |
c4093a6a | 4953 | } |
c5aa993b | 4954 | |
0d381245 VP |
4955 | static void |
4956 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 MS |
4957 | struct bp_location **last_loc, |
4958 | int print_address_bits, | |
6c95b8df | 4959 | int allflag) |
0d381245 | 4960 | { |
6c95b8df PA |
4961 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4962 | print_address_bits, allflag); | |
0d381245 VP |
4963 | |
4964 | /* If this breakpoint has custom print function, | |
4965 | it's already printed. Otherwise, print individual | |
4966 | locations, if any. */ | |
4967 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4968 | { | |
4a64f543 MS |
4969 | /* If breakpoint has a single location that is disabled, we |
4970 | print it as if it had several locations, since otherwise it's | |
4971 | hard to represent "breakpoint enabled, location disabled" | |
4972 | situation. | |
4973 | ||
4974 | Note that while hardware watchpoints have several locations | |
4975 | internally, that's no a property exposed to user. */ | |
0d381245 | 4976 | if (b->loc |
a5606eee | 4977 | && !is_hardware_watchpoint (b) |
0d381245 | 4978 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4979 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4980 | { |
4981 | struct bp_location *loc; | |
4982 | int n = 1; | |
4983 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4984 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4985 | print_address_bits, allflag); |
0d381245 VP |
4986 | } |
4987 | } | |
4988 | } | |
4989 | ||
a6d9a66e UW |
4990 | static int |
4991 | breakpoint_address_bits (struct breakpoint *b) | |
4992 | { | |
4993 | int print_address_bits = 0; | |
4994 | struct bp_location *loc; | |
4995 | ||
4996 | for (loc = b->loc; loc; loc = loc->next) | |
4997 | { | |
c7437ca6 PA |
4998 | int addr_bit; |
4999 | ||
5000 | /* Software watchpoints that aren't watching memory don't have | |
5001 | an address to print. */ | |
5002 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5003 | continue; | |
5004 | ||
5005 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5006 | if (addr_bit > print_address_bits) |
5007 | print_address_bits = addr_bit; | |
5008 | } | |
5009 | ||
5010 | return print_address_bits; | |
5011 | } | |
0d381245 | 5012 | |
c4093a6a JM |
5013 | struct captured_breakpoint_query_args |
5014 | { | |
5015 | int bnum; | |
5016 | }; | |
c5aa993b | 5017 | |
c4093a6a | 5018 | static int |
2b65245e | 5019 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5020 | { |
5021 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5022 | struct breakpoint *b; |
a6d9a66e | 5023 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5024 | |
c4093a6a JM |
5025 | ALL_BREAKPOINTS (b) |
5026 | { | |
5027 | if (args->bnum == b->number) | |
c5aa993b | 5028 | { |
a6d9a66e | 5029 | int print_address_bits = breakpoint_address_bits (b); |
cc59ec59 | 5030 | |
6c95b8df | 5031 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 5032 | return GDB_RC_OK; |
c5aa993b | 5033 | } |
c4093a6a JM |
5034 | } |
5035 | return GDB_RC_NONE; | |
5036 | } | |
c5aa993b | 5037 | |
c4093a6a | 5038 | enum gdb_rc |
4a64f543 MS |
5039 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5040 | char **error_message) | |
c4093a6a JM |
5041 | { |
5042 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5043 | |
c4093a6a JM |
5044 | args.bnum = bnum; |
5045 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5046 | an error. */ |
b0b13bb4 DJ |
5047 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5048 | error_message, RETURN_MASK_ALL) < 0) | |
5049 | return GDB_RC_FAIL; | |
5050 | else | |
5051 | return GDB_RC_OK; | |
c4093a6a | 5052 | } |
c5aa993b | 5053 | |
7f3b0473 | 5054 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4a64f543 | 5055 | catchpoints, et.al.). */ |
7f3b0473 AC |
5056 | |
5057 | static int | |
5058 | user_settable_breakpoint (const struct breakpoint *b) | |
5059 | { | |
5060 | return (b->type == bp_breakpoint | |
ce78b96d | 5061 | || b->type == bp_catchpoint |
7f3b0473 | 5062 | || b->type == bp_hardware_breakpoint |
d77f58be | 5063 | || is_tracepoint (b) |
cc60f2e3 | 5064 | || is_watchpoint (b)); |
7f3b0473 | 5065 | } |
4a64f543 | 5066 | |
7f3b0473 | 5067 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5068 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5069 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5070 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5071 | ones for which it returns non-zero. Return the total number of | |
5072 | breakpoints listed. */ | |
c906108c | 5073 | |
d77f58be | 5074 | static int |
4a64f543 MS |
5075 | breakpoint_1 (int bnum, int allflag, |
5076 | int (*filter) (const struct breakpoint *)) | |
c4093a6a | 5077 | { |
52f0bd74 | 5078 | struct breakpoint *b; |
a6d9a66e | 5079 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5080 | int nr_printable_breakpoints; |
3b31d625 | 5081 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5082 | struct value_print_options opts; |
a6d9a66e | 5083 | int print_address_bits = 0; |
269b11a2 PA |
5084 | int print_type_col_width = 14; |
5085 | ||
79a45b7d TT |
5086 | get_user_print_options (&opts); |
5087 | ||
4a64f543 MS |
5088 | /* Compute the number of rows in the table, as well as the size |
5089 | required for address fields. */ | |
7f3b0473 AC |
5090 | nr_printable_breakpoints = 0; |
5091 | ALL_BREAKPOINTS (b) | |
5092 | if (bnum == -1 | |
5093 | || bnum == b->number) | |
5094 | { | |
d77f58be SS |
5095 | /* If we have a filter, only list the breakpoints it accepts. */ |
5096 | if (filter && !filter (b)) | |
5097 | continue; | |
5098 | ||
84f4c1fe PM |
5099 | if (allflag || (user_settable_breakpoint (b) |
5100 | && b->number > 0)) | |
a6d9a66e | 5101 | { |
269b11a2 PA |
5102 | int addr_bit, type_len; |
5103 | ||
5104 | addr_bit = breakpoint_address_bits (b); | |
a6d9a66e UW |
5105 | if (addr_bit > print_address_bits) |
5106 | print_address_bits = addr_bit; | |
5107 | ||
269b11a2 PA |
5108 | type_len = strlen (bptype_string (b->type)); |
5109 | if (type_len > print_type_col_width) | |
5110 | print_type_col_width = type_len; | |
5111 | ||
a6d9a66e UW |
5112 | nr_printable_breakpoints++; |
5113 | } | |
7f3b0473 AC |
5114 | } |
5115 | ||
79a45b7d | 5116 | if (opts.addressprint) |
3b31d625 | 5117 | bkpttbl_chain |
3e43a32a MS |
5118 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5119 | nr_printable_breakpoints, | |
3b31d625 | 5120 | "BreakpointTable"); |
8b93c638 | 5121 | else |
3b31d625 | 5122 | bkpttbl_chain |
3e43a32a MS |
5123 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5124 | nr_printable_breakpoints, | |
3b31d625 | 5125 | "BreakpointTable"); |
8b93c638 | 5126 | |
7f3b0473 | 5127 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5128 | annotate_breakpoints_headers (); |
5129 | if (nr_printable_breakpoints > 0) | |
5130 | annotate_field (0); | |
4a64f543 | 5131 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5132 | if (nr_printable_breakpoints > 0) |
5133 | annotate_field (1); | |
269b11a2 | 5134 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5135 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5136 | if (nr_printable_breakpoints > 0) |
5137 | annotate_field (2); | |
4a64f543 | 5138 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5139 | if (nr_printable_breakpoints > 0) |
5140 | annotate_field (3); | |
54e52265 | 5141 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5142 | if (opts.addressprint) |
7f3b0473 | 5143 | { |
d7faa9e7 AC |
5144 | if (nr_printable_breakpoints > 0) |
5145 | annotate_field (4); | |
a6d9a66e | 5146 | if (print_address_bits <= 32) |
4a64f543 MS |
5147 | ui_out_table_header (uiout, 10, ui_left, |
5148 | "addr", "Address"); /* 5 */ | |
7f3b0473 | 5149 | else |
4a64f543 MS |
5150 | ui_out_table_header (uiout, 18, ui_left, |
5151 | "addr", "Address"); /* 5 */ | |
7f3b0473 | 5152 | } |
d7faa9e7 AC |
5153 | if (nr_printable_breakpoints > 0) |
5154 | annotate_field (5); | |
5155 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5156 | ui_out_table_body (uiout); | |
5157 | if (nr_printable_breakpoints > 0) | |
5158 | annotate_breakpoints_table (); | |
7f3b0473 | 5159 | |
c4093a6a | 5160 | ALL_BREAKPOINTS (b) |
bad56014 TT |
5161 | { |
5162 | QUIT; | |
c4093a6a JM |
5163 | if (bnum == -1 |
5164 | || bnum == b->number) | |
5165 | { | |
d77f58be SS |
5166 | /* If we have a filter, only list the breakpoints it accepts. */ |
5167 | if (filter && !filter (b)) | |
5168 | continue; | |
5169 | ||
c4093a6a | 5170 | /* We only print out user settable breakpoints unless the |
4a64f543 | 5171 | allflag is set. */ |
84f4c1fe PM |
5172 | if (allflag || (user_settable_breakpoint (b) |
5173 | && b->number > 0)) | |
6c95b8df | 5174 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a | 5175 | } |
bad56014 | 5176 | } |
c4093a6a | 5177 | |
3b31d625 | 5178 | do_cleanups (bkpttbl_chain); |
698384cd | 5179 | |
7f3b0473 | 5180 | if (nr_printable_breakpoints == 0) |
c906108c | 5181 | { |
4a64f543 MS |
5182 | /* If there's a filter, let the caller decide how to report |
5183 | empty list. */ | |
d77f58be SS |
5184 | if (!filter) |
5185 | { | |
5186 | if (bnum == -1) | |
5187 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
5188 | else | |
4a64f543 MS |
5189 | ui_out_message (uiout, 0, |
5190 | "No breakpoint or watchpoint number %d.\n", | |
d77f58be SS |
5191 | bnum); |
5192 | } | |
c906108c SS |
5193 | } |
5194 | else | |
c4093a6a | 5195 | { |
a6d9a66e UW |
5196 | if (last_loc && !server_command) |
5197 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5198 | } |
c906108c | 5199 | |
4a64f543 | 5200 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5201 | there have been breakpoints? */ |
c906108c | 5202 | annotate_breakpoints_table_end (); |
d77f58be SS |
5203 | |
5204 | return nr_printable_breakpoints; | |
c906108c SS |
5205 | } |
5206 | ||
ad443146 SS |
5207 | /* Display the value of default-collect in a way that is generally |
5208 | compatible with the breakpoint list. */ | |
5209 | ||
5210 | static void | |
5211 | default_collect_info (void) | |
5212 | { | |
5213 | /* If it has no value (which is frequently the case), say nothing; a | |
5214 | message like "No default-collect." gets in user's face when it's | |
5215 | not wanted. */ | |
5216 | if (!*default_collect) | |
5217 | return; | |
5218 | ||
5219 | /* The following phrase lines up nicely with per-tracepoint collect | |
5220 | actions. */ | |
5221 | ui_out_text (uiout, "default collect "); | |
5222 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5223 | ui_out_text (uiout, " \n"); | |
5224 | } | |
5225 | ||
c906108c | 5226 | static void |
fba45db2 | 5227 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
5228 | { |
5229 | int bnum = -1; | |
5230 | ||
5231 | if (bnum_exp) | |
bb518678 | 5232 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5233 | |
d77f58be | 5234 | breakpoint_1 (bnum, 0, NULL); |
ad443146 SS |
5235 | |
5236 | default_collect_info (); | |
d77f58be SS |
5237 | } |
5238 | ||
5239 | static void | |
5240 | watchpoints_info (char *wpnum_exp, int from_tty) | |
5241 | { | |
5242 | int wpnum = -1, num_printed; | |
5243 | ||
5244 | if (wpnum_exp) | |
5245 | wpnum = parse_and_eval_long (wpnum_exp); | |
5246 | ||
5247 | num_printed = breakpoint_1 (wpnum, 0, is_watchpoint); | |
5248 | ||
5249 | if (num_printed == 0) | |
5250 | { | |
5251 | if (wpnum == -1) | |
5252 | ui_out_message (uiout, 0, "No watchpoints.\n"); | |
5253 | else | |
5254 | ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum); | |
5255 | } | |
c906108c SS |
5256 | } |
5257 | ||
7a292a7a | 5258 | static void |
fba45db2 | 5259 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
5260 | { |
5261 | int bnum = -1; | |
5262 | ||
5263 | if (bnum_exp) | |
bb518678 | 5264 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5265 | |
d77f58be | 5266 | breakpoint_1 (bnum, 1, NULL); |
ad443146 SS |
5267 | |
5268 | default_collect_info (); | |
c906108c SS |
5269 | } |
5270 | ||
0d381245 | 5271 | static int |
714835d5 | 5272 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5273 | struct program_space *pspace, |
714835d5 | 5274 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5275 | { |
5276 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5277 | |
0d381245 VP |
5278 | for (; bl; bl = bl->next) |
5279 | { | |
6c95b8df PA |
5280 | if (bl->pspace == pspace |
5281 | && bl->address == pc | |
0d381245 VP |
5282 | && (!overlay_debugging || bl->section == section)) |
5283 | return 1; | |
5284 | } | |
5285 | return 0; | |
5286 | } | |
5287 | ||
6c95b8df PA |
5288 | /* Print a message describing any breakpoints set at PC. This |
5289 | concerns with logical breakpoints, so we match program spaces, not | |
5290 | address spaces. */ | |
c906108c SS |
5291 | |
5292 | static void | |
6c95b8df PA |
5293 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5294 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5295 | struct obj_section *section, int thread) |
c906108c | 5296 | { |
52f0bd74 AC |
5297 | int others = 0; |
5298 | struct breakpoint *b; | |
c906108c SS |
5299 | |
5300 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5301 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5302 | if (others > 0) |
5303 | { | |
a3f17187 AC |
5304 | if (others == 1) |
5305 | printf_filtered (_("Note: breakpoint ")); | |
5306 | else /* if (others == ???) */ | |
5307 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5308 | ALL_BREAKPOINTS (b) |
6c95b8df | 5309 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5310 | { |
5311 | others--; | |
5312 | printf_filtered ("%d", b->number); | |
5313 | if (b->thread == -1 && thread != -1) | |
5314 | printf_filtered (" (all threads)"); | |
5315 | else if (b->thread != -1) | |
5316 | printf_filtered (" (thread %d)", b->thread); | |
5317 | printf_filtered ("%s%s ", | |
059fb39f | 5318 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5319 | || b->enable_state == bp_call_disabled |
5320 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5321 | ? " (disabled)" |
5322 | : b->enable_state == bp_permanent | |
5323 | ? " (permanent)" | |
5324 | : ""), | |
5325 | (others > 1) ? "," | |
5326 | : ((others == 1) ? " and" : "")); | |
5327 | } | |
a3f17187 | 5328 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5329 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5330 | printf_filtered (".\n"); |
5331 | } | |
5332 | } | |
5333 | \f | |
5334 | /* Set the default place to put a breakpoint | |
5335 | for the `break' command with no arguments. */ | |
5336 | ||
5337 | void | |
6c95b8df PA |
5338 | set_default_breakpoint (int valid, struct program_space *pspace, |
5339 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5340 | int line) |
c906108c SS |
5341 | { |
5342 | default_breakpoint_valid = valid; | |
6c95b8df | 5343 | default_breakpoint_pspace = pspace; |
c906108c SS |
5344 | default_breakpoint_address = addr; |
5345 | default_breakpoint_symtab = symtab; | |
5346 | default_breakpoint_line = line; | |
5347 | } | |
5348 | ||
e4f237da KB |
5349 | /* Return true iff it is meaningful to use the address member of |
5350 | BPT. For some breakpoint types, the address member is irrelevant | |
5351 | and it makes no sense to attempt to compare it to other addresses | |
5352 | (or use it for any other purpose either). | |
5353 | ||
4a64f543 MS |
5354 | More specifically, each of the following breakpoint types will |
5355 | always have a zero valued address and we don't want to mark | |
5356 | breakpoints of any of these types to be a duplicate of an actual | |
5357 | breakpoint at address zero: | |
e4f237da KB |
5358 | |
5359 | bp_watchpoint | |
2d134ed3 PA |
5360 | bp_catchpoint |
5361 | ||
5362 | */ | |
e4f237da KB |
5363 | |
5364 | static int | |
5365 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5366 | { | |
5367 | enum bptype type = bpt->type; | |
5368 | ||
2d134ed3 PA |
5369 | return (type != bp_watchpoint && type != bp_catchpoint); |
5370 | } | |
5371 | ||
5372 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5373 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5374 | ||
5375 | static int | |
4a64f543 MS |
5376 | watchpoint_locations_match (struct bp_location *loc1, |
5377 | struct bp_location *loc2) | |
2d134ed3 | 5378 | { |
2bdf28a0 JK |
5379 | /* Both of them must not be in moribund_locations. */ |
5380 | gdb_assert (loc1->owner != NULL); | |
5381 | gdb_assert (loc2->owner != NULL); | |
5382 | ||
4a64f543 MS |
5383 | /* If the target can evaluate the condition expression in hardware, |
5384 | then we we need to insert both watchpoints even if they are at | |
5385 | the same place. Otherwise the watchpoint will only trigger when | |
5386 | the condition of whichever watchpoint was inserted evaluates to | |
5387 | true, not giving a chance for GDB to check the condition of the | |
5388 | other watchpoint. */ | |
0cf6dd15 | 5389 | if ((loc1->owner->cond_exp |
4a64f543 MS |
5390 | && target_can_accel_watchpoint_condition (loc1->address, |
5391 | loc1->length, | |
0cf6dd15 TJB |
5392 | loc1->watchpoint_type, |
5393 | loc1->owner->cond_exp)) | |
5394 | || (loc2->owner->cond_exp | |
4a64f543 MS |
5395 | && target_can_accel_watchpoint_condition (loc2->address, |
5396 | loc2->length, | |
0cf6dd15 TJB |
5397 | loc2->watchpoint_type, |
5398 | loc2->owner->cond_exp))) | |
5399 | return 0; | |
5400 | ||
85d721b8 PA |
5401 | /* Note that this checks the owner's type, not the location's. In |
5402 | case the target does not support read watchpoints, but does | |
5403 | support access watchpoints, we'll have bp_read_watchpoint | |
5404 | watchpoints with hw_access locations. Those should be considered | |
5405 | duplicates of hw_read locations. The hw_read locations will | |
5406 | become hw_access locations later. */ | |
2d134ed3 PA |
5407 | return (loc1->owner->type == loc2->owner->type |
5408 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5409 | && loc1->address == loc2->address | |
5410 | && loc1->length == loc2->length); | |
e4f237da KB |
5411 | } |
5412 | ||
6c95b8df PA |
5413 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5414 | same breakpoint location. In most targets, this can only be true | |
5415 | if ASPACE1 matches ASPACE2. On targets that have global | |
5416 | breakpoints, the address space doesn't really matter. */ | |
5417 | ||
5418 | static int | |
5419 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5420 | struct address_space *aspace2, CORE_ADDR addr2) | |
5421 | { | |
5422 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5423 | || aspace1 == aspace2) | |
5424 | && addr1 == addr2); | |
5425 | } | |
5426 | ||
2d134ed3 PA |
5427 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5428 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5429 | represent the same location. */ | |
5430 | ||
5431 | static int | |
4a64f543 MS |
5432 | breakpoint_locations_match (struct bp_location *loc1, |
5433 | struct bp_location *loc2) | |
2d134ed3 | 5434 | { |
2bdf28a0 JK |
5435 | int hw_point1, hw_point2; |
5436 | ||
5437 | /* Both of them must not be in moribund_locations. */ | |
5438 | gdb_assert (loc1->owner != NULL); | |
5439 | gdb_assert (loc2->owner != NULL); | |
5440 | ||
5441 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5442 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5443 | |
5444 | if (hw_point1 != hw_point2) | |
5445 | return 0; | |
5446 | else if (hw_point1) | |
5447 | return watchpoint_locations_match (loc1, loc2); | |
5448 | else | |
5449 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5450 | loc2->pspace->aspace, loc2->address); | |
5451 | } | |
5452 | ||
76897487 KB |
5453 | static void |
5454 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5455 | int bnum, int have_bnum) | |
5456 | { | |
5457 | char astr1[40]; | |
5458 | char astr2[40]; | |
5459 | ||
bb599908 PH |
5460 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5461 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5462 | if (have_bnum) |
8a3fe4f8 | 5463 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5464 | bnum, astr1, astr2); |
5465 | else | |
8a3fe4f8 | 5466 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5467 | } |
5468 | ||
4a64f543 MS |
5469 | /* Adjust a breakpoint's address to account for architectural |
5470 | constraints on breakpoint placement. Return the adjusted address. | |
5471 | Note: Very few targets require this kind of adjustment. For most | |
5472 | targets, this function is simply the identity function. */ | |
76897487 KB |
5473 | |
5474 | static CORE_ADDR | |
a6d9a66e UW |
5475 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5476 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5477 | { |
a6d9a66e | 5478 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5479 | { |
5480 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5481 | return bpaddr; | |
5482 | } | |
88f7da05 KB |
5483 | else if (bptype == bp_watchpoint |
5484 | || bptype == bp_hardware_watchpoint | |
5485 | || bptype == bp_read_watchpoint | |
5486 | || bptype == bp_access_watchpoint | |
fe798b75 | 5487 | || bptype == bp_catchpoint) |
88f7da05 KB |
5488 | { |
5489 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5490 | have their addresses modified. */ | |
5491 | return bpaddr; | |
5492 | } | |
76897487 KB |
5493 | else |
5494 | { | |
5495 | CORE_ADDR adjusted_bpaddr; | |
5496 | ||
5497 | /* Some targets have architectural constraints on the placement | |
5498 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5499 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5500 | |
5501 | /* An adjusted breakpoint address can significantly alter | |
5502 | a user's expectations. Print a warning if an adjustment | |
5503 | is required. */ | |
5504 | if (adjusted_bpaddr != bpaddr) | |
5505 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5506 | ||
5507 | return adjusted_bpaddr; | |
5508 | } | |
5509 | } | |
5510 | ||
7cc221ef DJ |
5511 | /* Allocate a struct bp_location. */ |
5512 | ||
26bb91f3 | 5513 | static struct bp_location * |
39d61571 | 5514 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5515 | { |
afe38095 | 5516 | struct bp_location *loc; |
7cc221ef DJ |
5517 | |
5518 | loc = xmalloc (sizeof (struct bp_location)); | |
5519 | memset (loc, 0, sizeof (*loc)); | |
5520 | ||
e049a4b5 | 5521 | loc->owner = bpt; |
511a6cd4 | 5522 | loc->cond = NULL; |
0d381245 VP |
5523 | loc->shlib_disabled = 0; |
5524 | loc->enabled = 1; | |
e049a4b5 | 5525 | |
39d61571 | 5526 | switch (bpt->type) |
e049a4b5 DJ |
5527 | { |
5528 | case bp_breakpoint: | |
5529 | case bp_until: | |
5530 | case bp_finish: | |
5531 | case bp_longjmp: | |
5532 | case bp_longjmp_resume: | |
186c406b TT |
5533 | case bp_exception: |
5534 | case bp_exception_resume: | |
e049a4b5 | 5535 | case bp_step_resume: |
e049a4b5 DJ |
5536 | case bp_watchpoint_scope: |
5537 | case bp_call_dummy: | |
aa7d318d | 5538 | case bp_std_terminate: |
e049a4b5 DJ |
5539 | case bp_shlib_event: |
5540 | case bp_thread_event: | |
5541 | case bp_overlay_event: | |
4efc6507 | 5542 | case bp_jit_event: |
0fd8e87f | 5543 | case bp_longjmp_master: |
aa7d318d | 5544 | case bp_std_terminate_master: |
186c406b | 5545 | case bp_exception_master: |
e049a4b5 DJ |
5546 | loc->loc_type = bp_loc_software_breakpoint; |
5547 | break; | |
5548 | case bp_hardware_breakpoint: | |
5549 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5550 | break; | |
5551 | case bp_hardware_watchpoint: | |
5552 | case bp_read_watchpoint: | |
5553 | case bp_access_watchpoint: | |
5554 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5555 | break; | |
5556 | case bp_watchpoint: | |
ce78b96d | 5557 | case bp_catchpoint: |
15c3d785 PA |
5558 | case bp_tracepoint: |
5559 | case bp_fast_tracepoint: | |
0fb4aa4b | 5560 | case bp_static_tracepoint: |
e049a4b5 DJ |
5561 | loc->loc_type = bp_loc_other; |
5562 | break; | |
5563 | default: | |
e2e0b3e5 | 5564 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5565 | } |
5566 | ||
f431efe5 | 5567 | loc->refc = 1; |
7cc221ef DJ |
5568 | return loc; |
5569 | } | |
5570 | ||
f431efe5 PA |
5571 | static void |
5572 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5573 | { |
5574 | if (loc->cond) | |
5575 | xfree (loc->cond); | |
74960c60 VP |
5576 | |
5577 | if (loc->function_name) | |
5578 | xfree (loc->function_name); | |
f431efe5 | 5579 | |
fe3f5fa8 VP |
5580 | xfree (loc); |
5581 | } | |
5582 | ||
f431efe5 PA |
5583 | /* Increment reference count. */ |
5584 | ||
5585 | static void | |
5586 | incref_bp_location (struct bp_location *bl) | |
5587 | { | |
5588 | ++bl->refc; | |
5589 | } | |
5590 | ||
5591 | /* Decrement reference count. If the reference count reaches 0, | |
5592 | destroy the bp_location. Sets *BLP to NULL. */ | |
5593 | ||
5594 | static void | |
5595 | decref_bp_location (struct bp_location **blp) | |
5596 | { | |
0807b50c PA |
5597 | gdb_assert ((*blp)->refc > 0); |
5598 | ||
f431efe5 PA |
5599 | if (--(*blp)->refc == 0) |
5600 | free_bp_location (*blp); | |
5601 | *blp = NULL; | |
5602 | } | |
5603 | ||
4a64f543 MS |
5604 | /* Helper to set_raw_breakpoint below. Creates a breakpoint that has |
5605 | type BPTYPE and has no locations as yet. */ | |
5606 | /* This function is used in gdbtk sources and thus can not be made | |
5607 | static. */ | |
c906108c | 5608 | |
c40e75cd | 5609 | static struct breakpoint * |
a6d9a66e UW |
5610 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5611 | enum bptype bptype) | |
c906108c | 5612 | { |
52f0bd74 | 5613 | struct breakpoint *b, *b1; |
c906108c SS |
5614 | |
5615 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5616 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5617 | |
4d28f7a8 | 5618 | b->type = bptype; |
a6d9a66e | 5619 | b->gdbarch = gdbarch; |
c906108c SS |
5620 | b->language = current_language->la_language; |
5621 | b->input_radix = input_radix; | |
5622 | b->thread = -1; | |
b5de0fa7 | 5623 | b->enable_state = bp_enabled; |
c906108c SS |
5624 | b->next = 0; |
5625 | b->silent = 0; | |
5626 | b->ignore_count = 0; | |
5627 | b->commands = NULL; | |
818dd999 | 5628 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5629 | b->forked_inferior_pid = null_ptid; |
c906108c | 5630 | b->exec_pathname = NULL; |
a96d9b2e | 5631 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5632 | b->ops = NULL; |
0d381245 | 5633 | b->condition_not_parsed = 0; |
84f4c1fe | 5634 | b->py_bp_object = NULL; |
c906108c | 5635 | |
4a64f543 MS |
5636 | /* Add this breakpoint to the end of the chain so that a list of |
5637 | breakpoints will come out in order of increasing numbers. */ | |
c906108c SS |
5638 | |
5639 | b1 = breakpoint_chain; | |
5640 | if (b1 == 0) | |
5641 | breakpoint_chain = b; | |
5642 | else | |
5643 | { | |
5644 | while (b1->next) | |
5645 | b1 = b1->next; | |
5646 | b1->next = b; | |
5647 | } | |
0d381245 VP |
5648 | return b; |
5649 | } | |
5650 | ||
5651 | /* Initialize loc->function_name. */ | |
5652 | static void | |
5653 | set_breakpoint_location_function (struct bp_location *loc) | |
5654 | { | |
2bdf28a0 JK |
5655 | gdb_assert (loc->owner != NULL); |
5656 | ||
0d381245 | 5657 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5658 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5659 | || is_tracepoint (loc->owner)) |
0d381245 VP |
5660 | { |
5661 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5662 | NULL, NULL); | |
5663 | if (loc->function_name) | |
5664 | loc->function_name = xstrdup (loc->function_name); | |
5665 | } | |
5666 | } | |
5667 | ||
a6d9a66e UW |
5668 | /* Attempt to determine architecture of location identified by SAL. */ |
5669 | static struct gdbarch * | |
5670 | get_sal_arch (struct symtab_and_line sal) | |
5671 | { | |
5672 | if (sal.section) | |
5673 | return get_objfile_arch (sal.section->objfile); | |
5674 | if (sal.symtab) | |
5675 | return get_objfile_arch (sal.symtab->objfile); | |
5676 | ||
5677 | return NULL; | |
5678 | } | |
5679 | ||
0d381245 VP |
5680 | /* set_raw_breakpoint is a low level routine for allocating and |
5681 | partially initializing a breakpoint of type BPTYPE. The newly | |
5682 | created breakpoint's address, section, source file name, and line | |
5683 | number are provided by SAL. The newly created and partially | |
5684 | initialized breakpoint is added to the breakpoint chain and | |
5685 | is also returned as the value of this function. | |
5686 | ||
5687 | It is expected that the caller will complete the initialization of | |
5688 | the newly created breakpoint struct as well as output any status | |
5689 | information regarding the creation of a new breakpoint. In | |
5690 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5691 | number! Care should be taken to not allow an error to occur | |
5692 | prior to completing the initialization of the breakpoint. If this | |
5693 | should happen, a bogus breakpoint will be left on the chain. */ | |
5694 | ||
63c252f8 | 5695 | struct breakpoint * |
a6d9a66e UW |
5696 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5697 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5698 | { |
4a64f543 MS |
5699 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, |
5700 | bptype); | |
0d381245 | 5701 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5702 | struct gdbarch *loc_gdbarch; |
5703 | ||
5704 | loc_gdbarch = get_sal_arch (sal); | |
5705 | if (!loc_gdbarch) | |
5706 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5707 | |
6c95b8df PA |
5708 | if (bptype != bp_catchpoint) |
5709 | gdb_assert (sal.pspace != NULL); | |
5710 | ||
0d381245 VP |
5711 | /* Adjust the breakpoint's address prior to allocating a location. |
5712 | Once we call allocate_bp_location(), that mostly uninitialized | |
5713 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5714 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5715 | not want its scan of the location chain to find a breakpoint and |
5716 | location that's only been partially initialized. */ | |
4a64f543 MS |
5717 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5718 | sal.pc, b->type); | |
0d381245 | 5719 | |
39d61571 | 5720 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5721 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5722 | b->loc->requested_address = sal.pc; |
5723 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5724 | b->loc->pspace = sal.pspace; |
5725 | ||
5726 | /* Store the program space that was used to set the breakpoint, for | |
5727 | breakpoint resetting. */ | |
5728 | b->pspace = sal.pspace; | |
0d381245 VP |
5729 | |
5730 | if (sal.symtab == NULL) | |
5731 | b->source_file = NULL; | |
5732 | else | |
1b36a34b | 5733 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5734 | b->loc->section = sal.section; |
5735 | b->line_number = sal.line; | |
5736 | ||
5737 | set_breakpoint_location_function (b->loc); | |
c906108c | 5738 | |
c906108c SS |
5739 | breakpoints_changed (); |
5740 | ||
5741 | return b; | |
5742 | } | |
5743 | ||
c2c6d25f JM |
5744 | |
5745 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5746 | instruction, hard-wired into the inferior's code. */ | |
5747 | void | |
5748 | make_breakpoint_permanent (struct breakpoint *b) | |
5749 | { | |
0d381245 | 5750 | struct bp_location *bl; |
cc59ec59 | 5751 | |
b5de0fa7 | 5752 | b->enable_state = bp_permanent; |
c2c6d25f | 5753 | |
4a64f543 MS |
5754 | /* By definition, permanent breakpoints are already present in the |
5755 | code. Mark all locations as inserted. For now, | |
5756 | make_breakpoint_permanent is called in just one place, so it's | |
5757 | hard to say if it's reasonable to have permanent breakpoint with | |
5758 | multiple locations or not, but it's easy to implmement. */ | |
0d381245 VP |
5759 | for (bl = b->loc; bl; bl = bl->next) |
5760 | bl->inserted = 1; | |
c2c6d25f JM |
5761 | } |
5762 | ||
53a5351d | 5763 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5764 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5765 | initiated the operation. */ | |
c906108c SS |
5766 | |
5767 | void | |
186c406b | 5768 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5769 | { |
35df4500 | 5770 | struct breakpoint *b, *b_tmp; |
186c406b | 5771 | int thread = tp->num; |
0fd8e87f UW |
5772 | |
5773 | /* To avoid having to rescan all objfile symbols at every step, | |
5774 | we maintain a list of continually-inserted but always disabled | |
5775 | longjmp "master" breakpoints. Here, we simply create momentary | |
5776 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5777 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5778 | if (b->pspace == current_program_space |
186c406b TT |
5779 | && (b->type == bp_longjmp_master |
5780 | || b->type == bp_exception_master)) | |
0fd8e87f UW |
5781 | { |
5782 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5783 | |
186c406b | 5784 | clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
0fd8e87f UW |
5785 | clone->thread = thread; |
5786 | } | |
186c406b TT |
5787 | |
5788 | tp->initiating_frame = frame; | |
c906108c SS |
5789 | } |
5790 | ||
611c83ae | 5791 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5792 | void |
611c83ae | 5793 | delete_longjmp_breakpoint (int thread) |
c906108c | 5794 | { |
35df4500 | 5795 | struct breakpoint *b, *b_tmp; |
c906108c | 5796 | |
35df4500 | 5797 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 5798 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
5799 | { |
5800 | if (b->thread == thread) | |
5801 | delete_breakpoint (b); | |
5802 | } | |
c906108c SS |
5803 | } |
5804 | ||
1900040c MS |
5805 | void |
5806 | enable_overlay_breakpoints (void) | |
5807 | { | |
52f0bd74 | 5808 | struct breakpoint *b; |
1900040c MS |
5809 | |
5810 | ALL_BREAKPOINTS (b) | |
5811 | if (b->type == bp_overlay_event) | |
5812 | { | |
5813 | b->enable_state = bp_enabled; | |
b60e7edf | 5814 | update_global_location_list (1); |
c02f5703 | 5815 | overlay_events_enabled = 1; |
1900040c MS |
5816 | } |
5817 | } | |
5818 | ||
5819 | void | |
5820 | disable_overlay_breakpoints (void) | |
5821 | { | |
52f0bd74 | 5822 | struct breakpoint *b; |
1900040c MS |
5823 | |
5824 | ALL_BREAKPOINTS (b) | |
5825 | if (b->type == bp_overlay_event) | |
5826 | { | |
5827 | b->enable_state = bp_disabled; | |
b60e7edf | 5828 | update_global_location_list (0); |
c02f5703 | 5829 | overlay_events_enabled = 0; |
1900040c MS |
5830 | } |
5831 | } | |
5832 | ||
aa7d318d TT |
5833 | /* Set an active std::terminate breakpoint for each std::terminate |
5834 | master breakpoint. */ | |
5835 | void | |
5836 | set_std_terminate_breakpoint (void) | |
5837 | { | |
35df4500 | 5838 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5839 | |
35df4500 | 5840 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5841 | if (b->pspace == current_program_space |
5842 | && b->type == bp_std_terminate_master) | |
5843 | { | |
5844 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5845 | clone->type = bp_std_terminate; | |
5846 | } | |
5847 | } | |
5848 | ||
5849 | /* Delete all the std::terminate breakpoints. */ | |
5850 | void | |
5851 | delete_std_terminate_breakpoint (void) | |
5852 | { | |
35df4500 | 5853 | struct breakpoint *b, *b_tmp; |
aa7d318d | 5854 | |
35df4500 | 5855 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
5856 | if (b->type == bp_std_terminate) |
5857 | delete_breakpoint (b); | |
5858 | } | |
5859 | ||
c4093a6a | 5860 | struct breakpoint * |
a6d9a66e | 5861 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5862 | { |
5863 | struct breakpoint *b; | |
c4093a6a | 5864 | |
a6d9a66e | 5865 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5866 | |
b5de0fa7 | 5867 | b->enable_state = bp_enabled; |
c4093a6a | 5868 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5869 | b->addr_string |
5870 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5871 | |
b60e7edf | 5872 | update_global_location_list_nothrow (1); |
74960c60 | 5873 | |
c4093a6a JM |
5874 | return b; |
5875 | } | |
5876 | ||
5877 | void | |
5878 | remove_thread_event_breakpoints (void) | |
5879 | { | |
35df4500 | 5880 | struct breakpoint *b, *b_tmp; |
c4093a6a | 5881 | |
35df4500 | 5882 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5883 | if (b->type == bp_thread_event |
5884 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5885 | delete_breakpoint (b); |
5886 | } | |
5887 | ||
0101ce28 JJ |
5888 | struct captured_parse_breakpoint_args |
5889 | { | |
5890 | char **arg_p; | |
5891 | struct symtabs_and_lines *sals_p; | |
5892 | char ***addr_string_p; | |
5893 | int *not_found_ptr; | |
5894 | }; | |
5895 | ||
5896 | struct lang_and_radix | |
5897 | { | |
5898 | enum language lang; | |
5899 | int radix; | |
5900 | }; | |
5901 | ||
4efc6507 DE |
5902 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5903 | ||
5904 | struct breakpoint * | |
5905 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5906 | { | |
5907 | struct breakpoint *b; | |
5908 | ||
5909 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5910 | update_global_location_list_nothrow (1); | |
5911 | return b; | |
5912 | } | |
0101ce28 | 5913 | |
cae688ec JJ |
5914 | void |
5915 | remove_solib_event_breakpoints (void) | |
5916 | { | |
35df4500 | 5917 | struct breakpoint *b, *b_tmp; |
cae688ec | 5918 | |
35df4500 | 5919 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
5920 | if (b->type == bp_shlib_event |
5921 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5922 | delete_breakpoint (b); |
5923 | } | |
5924 | ||
5925 | struct breakpoint * | |
a6d9a66e | 5926 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5927 | { |
5928 | struct breakpoint *b; | |
5929 | ||
a6d9a66e | 5930 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5931 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5932 | return b; |
5933 | } | |
5934 | ||
5935 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5936 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5937 | ||
5938 | void | |
cb851954 | 5939 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5940 | { |
876fa593 | 5941 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5942 | |
876fa593 | 5943 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5944 | { |
2bdf28a0 | 5945 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 5946 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 5947 | |
4a64f543 MS |
5948 | /* We apply the check to all breakpoints, including disabled for |
5949 | those with loc->duplicate set. This is so that when breakpoint | |
5950 | becomes enabled, or the duplicate is removed, gdb will try to | |
5951 | insert all breakpoints. If we don't set shlib_disabled here, | |
5952 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 5953 | if (((b->type == bp_breakpoint) |
508ccb1f | 5954 | || (b->type == bp_jit_event) |
1042e4c0 | 5955 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 5956 | || (is_tracepoint (b))) |
6c95b8df | 5957 | && loc->pspace == current_program_space |
0d381245 | 5958 | && !loc->shlib_disabled |
a77053c2 | 5959 | #ifdef PC_SOLIB |
0d381245 | 5960 | && PC_SOLIB (loc->address) |
a77053c2 | 5961 | #else |
6c95b8df | 5962 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5963 | #endif |
5964 | ) | |
0d381245 VP |
5965 | { |
5966 | loc->shlib_disabled = 1; | |
5967 | } | |
cae688ec JJ |
5968 | } |
5969 | } | |
5970 | ||
4a64f543 MS |
5971 | /* Disable any breakpoints that are in in an unloaded shared library. |
5972 | Only apply to enabled breakpoints, disabled ones can just stay | |
5973 | disabled. */ | |
84acb35a | 5974 | |
75149521 | 5975 | static void |
84acb35a JJ |
5976 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5977 | { | |
876fa593 | 5978 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5979 | int disabled_shlib_breaks = 0; |
5980 | ||
c86cf029 VP |
5981 | /* SunOS a.out shared libraries are always mapped, so do not |
5982 | disable breakpoints; they will only be reported as unloaded | |
5983 | through clear_solib when GDB discards its shared library | |
5984 | list. See clear_solib for more information. */ | |
5985 | if (exec_bfd != NULL | |
5986 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5987 | return; | |
5988 | ||
876fa593 | 5989 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5990 | { |
2bdf28a0 | 5991 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 5992 | struct breakpoint *b = loc->owner; |
cc59ec59 | 5993 | |
0d381245 VP |
5994 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
5995 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5996 | && solib->pspace == loc->pspace |
e2dd7057 | 5997 | && !loc->shlib_disabled |
508ccb1f TT |
5998 | && (b->type == bp_breakpoint |
5999 | || b->type == bp_jit_event | |
6000 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6001 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6002 | { |
e2dd7057 PP |
6003 | loc->shlib_disabled = 1; |
6004 | /* At this point, we cannot rely on remove_breakpoint | |
6005 | succeeding so we must mark the breakpoint as not inserted | |
6006 | to prevent future errors occurring in remove_breakpoints. */ | |
6007 | loc->inserted = 0; | |
6008 | if (!disabled_shlib_breaks) | |
6009 | { | |
6010 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6011 | warning (_("Temporarily disabling breakpoints " |
6012 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6013 | solib->so_name); |
84acb35a | 6014 | } |
e2dd7057 | 6015 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6016 | } |
6017 | } | |
84acb35a JJ |
6018 | } |
6019 | ||
ce78b96d JB |
6020 | /* FORK & VFORK catchpoints. */ |
6021 | ||
4a64f543 MS |
6022 | /* Implement the "insert" breakpoint_ops method for fork |
6023 | catchpoints. */ | |
ce78b96d | 6024 | |
77b06cd7 TJB |
6025 | static int |
6026 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6027 | { |
77b06cd7 | 6028 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6029 | } |
6030 | ||
4a64f543 MS |
6031 | /* Implement the "remove" breakpoint_ops method for fork |
6032 | catchpoints. */ | |
ce78b96d JB |
6033 | |
6034 | static int | |
77b06cd7 | 6035 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6036 | { |
6037 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6038 | } | |
6039 | ||
6040 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6041 | catchpoints. */ | |
6042 | ||
6043 | static int | |
6044 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
6045 | { | |
6046 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
6047 | } | |
6048 | ||
4a64f543 MS |
6049 | /* Implement the "print_it" breakpoint_ops method for fork |
6050 | catchpoints. */ | |
ce78b96d JB |
6051 | |
6052 | static enum print_stop_action | |
6053 | print_it_catch_fork (struct breakpoint *b) | |
6054 | { | |
6055 | annotate_catchpoint (b->number); | |
6056 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
6057 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6058 | return PRINT_SRC_AND_LOC; | |
6059 | } | |
6060 | ||
4a64f543 MS |
6061 | /* Implement the "print_one" breakpoint_ops method for fork |
6062 | catchpoints. */ | |
ce78b96d JB |
6063 | |
6064 | static void | |
a6d9a66e | 6065 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6066 | { |
79a45b7d TT |
6067 | struct value_print_options opts; |
6068 | ||
6069 | get_user_print_options (&opts); | |
6070 | ||
4a64f543 MS |
6071 | /* Field 4, the address, is omitted (which makes the columns not |
6072 | line up too nicely with the headers, but the effect is relatively | |
6073 | readable). */ | |
79a45b7d | 6074 | if (opts.addressprint) |
ce78b96d JB |
6075 | ui_out_field_skip (uiout, "addr"); |
6076 | annotate_field (5); | |
6077 | ui_out_text (uiout, "fork"); | |
6078 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6079 | { | |
6080 | ui_out_text (uiout, ", process "); | |
6081 | ui_out_field_int (uiout, "what", | |
6082 | ptid_get_pid (b->forked_inferior_pid)); | |
6083 | ui_out_spaces (uiout, 1); | |
6084 | } | |
6085 | } | |
6086 | ||
6087 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6088 | catchpoints. */ | |
6089 | ||
6090 | static void | |
6091 | print_mention_catch_fork (struct breakpoint *b) | |
6092 | { | |
6093 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6094 | } | |
6095 | ||
6149aea9 PA |
6096 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6097 | catchpoints. */ | |
6098 | ||
6099 | static void | |
6100 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6101 | { | |
6102 | fprintf_unfiltered (fp, "catch fork"); | |
6103 | } | |
6104 | ||
ce78b96d JB |
6105 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6106 | ||
6107 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
6108 | { | |
6109 | insert_catch_fork, | |
6110 | remove_catch_fork, | |
6111 | breakpoint_hit_catch_fork, | |
e09342b5 | 6112 | NULL, /* resources_needed */ |
ce78b96d JB |
6113 | print_it_catch_fork, |
6114 | print_one_catch_fork, | |
6149aea9 PA |
6115 | print_mention_catch_fork, |
6116 | print_recreate_catch_fork | |
ce78b96d JB |
6117 | }; |
6118 | ||
4a64f543 MS |
6119 | /* Implement the "insert" breakpoint_ops method for vfork |
6120 | catchpoints. */ | |
ce78b96d | 6121 | |
77b06cd7 TJB |
6122 | static int |
6123 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6124 | { |
77b06cd7 | 6125 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6126 | } |
6127 | ||
4a64f543 MS |
6128 | /* Implement the "remove" breakpoint_ops method for vfork |
6129 | catchpoints. */ | |
ce78b96d JB |
6130 | |
6131 | static int | |
77b06cd7 | 6132 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6133 | { |
6134 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6135 | } | |
6136 | ||
6137 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6138 | catchpoints. */ | |
6139 | ||
6140 | static int | |
6141 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
6142 | { | |
6143 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
6144 | } | |
6145 | ||
4a64f543 MS |
6146 | /* Implement the "print_it" breakpoint_ops method for vfork |
6147 | catchpoints. */ | |
ce78b96d JB |
6148 | |
6149 | static enum print_stop_action | |
6150 | print_it_catch_vfork (struct breakpoint *b) | |
6151 | { | |
6152 | annotate_catchpoint (b->number); | |
6153 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
6154 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6155 | return PRINT_SRC_AND_LOC; | |
6156 | } | |
6157 | ||
4a64f543 MS |
6158 | /* Implement the "print_one" breakpoint_ops method for vfork |
6159 | catchpoints. */ | |
ce78b96d JB |
6160 | |
6161 | static void | |
a6d9a66e | 6162 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6163 | { |
79a45b7d TT |
6164 | struct value_print_options opts; |
6165 | ||
6166 | get_user_print_options (&opts); | |
4a64f543 MS |
6167 | /* Field 4, the address, is omitted (which makes the columns not |
6168 | line up too nicely with the headers, but the effect is relatively | |
6169 | readable). */ | |
79a45b7d | 6170 | if (opts.addressprint) |
ce78b96d JB |
6171 | ui_out_field_skip (uiout, "addr"); |
6172 | annotate_field (5); | |
6173 | ui_out_text (uiout, "vfork"); | |
6174 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6175 | { | |
6176 | ui_out_text (uiout, ", process "); | |
6177 | ui_out_field_int (uiout, "what", | |
6178 | ptid_get_pid (b->forked_inferior_pid)); | |
6179 | ui_out_spaces (uiout, 1); | |
6180 | } | |
6181 | } | |
6182 | ||
6183 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6184 | catchpoints. */ | |
6185 | ||
6186 | static void | |
6187 | print_mention_catch_vfork (struct breakpoint *b) | |
6188 | { | |
6189 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6190 | } | |
6191 | ||
6149aea9 PA |
6192 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6193 | catchpoints. */ | |
6194 | ||
6195 | static void | |
6196 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6197 | { | |
6198 | fprintf_unfiltered (fp, "catch vfork"); | |
6199 | } | |
6200 | ||
ce78b96d JB |
6201 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6202 | ||
6203 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6204 | { | |
6205 | insert_catch_vfork, | |
6206 | remove_catch_vfork, | |
6207 | breakpoint_hit_catch_vfork, | |
e09342b5 | 6208 | NULL, /* resources_needed */ |
ce78b96d JB |
6209 | print_it_catch_vfork, |
6210 | print_one_catch_vfork, | |
6149aea9 PA |
6211 | print_mention_catch_vfork, |
6212 | print_recreate_catch_vfork | |
ce78b96d JB |
6213 | }; |
6214 | ||
a96d9b2e SDJ |
6215 | /* Implement the "insert" breakpoint_ops method for syscall |
6216 | catchpoints. */ | |
6217 | ||
77b06cd7 TJB |
6218 | static int |
6219 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e SDJ |
6220 | { |
6221 | struct inferior *inf = current_inferior (); | |
6222 | ||
6223 | ++inf->total_syscalls_count; | |
77b06cd7 | 6224 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6225 | ++inf->any_syscall_count; |
6226 | else | |
6227 | { | |
6228 | int i, iter; | |
cc59ec59 | 6229 | |
a96d9b2e | 6230 | for (i = 0; |
77b06cd7 | 6231 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6232 | i++) |
6233 | { | |
6234 | int elem; | |
cc59ec59 | 6235 | |
a96d9b2e SDJ |
6236 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6237 | { | |
6238 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6239 | uintptr_t vec_addr_offset |
6240 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6241 | uintptr_t vec_addr; |
6242 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6243 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6244 | vec_addr_offset; | |
6245 | memset ((void *) vec_addr, 0, | |
6246 | (iter + 1 - old_size) * sizeof (int)); | |
6247 | } | |
6248 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6249 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6250 | } | |
6251 | } | |
6252 | ||
77b06cd7 TJB |
6253 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6254 | inf->total_syscalls_count != 0, | |
6255 | inf->any_syscall_count, | |
6256 | VEC_length (int, inf->syscalls_counts), | |
6257 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6258 | } |
6259 | ||
6260 | /* Implement the "remove" breakpoint_ops method for syscall | |
6261 | catchpoints. */ | |
6262 | ||
6263 | static int | |
77b06cd7 | 6264 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e SDJ |
6265 | { |
6266 | struct inferior *inf = current_inferior (); | |
6267 | ||
6268 | --inf->total_syscalls_count; | |
77b06cd7 | 6269 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6270 | --inf->any_syscall_count; |
6271 | else | |
6272 | { | |
6273 | int i, iter; | |
cc59ec59 | 6274 | |
a96d9b2e | 6275 | for (i = 0; |
77b06cd7 | 6276 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6277 | i++) |
6278 | { | |
6279 | int elem; | |
6280 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6281 | /* Shouldn't happen. */ | |
6282 | continue; | |
6283 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6284 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6285 | } | |
6286 | } | |
6287 | ||
6288 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6289 | inf->total_syscalls_count != 0, | |
6290 | inf->any_syscall_count, | |
6291 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6292 | VEC_address (int, |
6293 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6294 | } |
6295 | ||
6296 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6297 | catchpoints. */ | |
6298 | ||
6299 | static int | |
6300 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6301 | { | |
4a64f543 MS |
6302 | /* We must check if we are catching specific syscalls in this |
6303 | breakpoint. If we are, then we must guarantee that the called | |
6304 | syscall is the same syscall we are catching. */ | |
a96d9b2e SDJ |
6305 | int syscall_number = 0; |
6306 | ||
6307 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6308 | return 0; | |
6309 | ||
6310 | /* Now, checking if the syscall is the same. */ | |
6311 | if (b->syscalls_to_be_caught) | |
6312 | { | |
6313 | int i, iter; | |
cc59ec59 | 6314 | |
a96d9b2e SDJ |
6315 | for (i = 0; |
6316 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6317 | i++) | |
6318 | if (syscall_number == iter) | |
6319 | break; | |
6320 | /* Not the same. */ | |
6321 | if (!iter) | |
6322 | return 0; | |
6323 | } | |
6324 | ||
6325 | return 1; | |
6326 | } | |
6327 | ||
6328 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6329 | catchpoints. */ | |
6330 | ||
6331 | static enum print_stop_action | |
6332 | print_it_catch_syscall (struct breakpoint *b) | |
6333 | { | |
6334 | /* These are needed because we want to know in which state a | |
6335 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6336 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6337 | must print "called syscall" or "returned from syscall". */ | |
6338 | ptid_t ptid; | |
6339 | struct target_waitstatus last; | |
6340 | struct syscall s; | |
6341 | struct cleanup *old_chain; | |
6342 | char *syscall_id; | |
6343 | ||
6344 | get_last_target_status (&ptid, &last); | |
6345 | ||
6346 | get_syscall_by_number (last.value.syscall_number, &s); | |
6347 | ||
6348 | annotate_catchpoint (b->number); | |
6349 | ||
6350 | if (s.name == NULL) | |
6351 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6352 | else | |
6353 | syscall_id = xstrprintf ("'%s'", s.name); | |
6354 | ||
6355 | old_chain = make_cleanup (xfree, syscall_id); | |
6356 | ||
6357 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6358 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6359 | b->number, syscall_id); | |
6360 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6361 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6362 | b->number, syscall_id); | |
6363 | ||
6364 | do_cleanups (old_chain); | |
6365 | ||
6366 | return PRINT_SRC_AND_LOC; | |
6367 | } | |
6368 | ||
6369 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6370 | catchpoints. */ | |
6371 | ||
6372 | static void | |
6373 | print_one_catch_syscall (struct breakpoint *b, | |
6374 | struct bp_location **last_loc) | |
6375 | { | |
6376 | struct value_print_options opts; | |
6377 | ||
6378 | get_user_print_options (&opts); | |
4a64f543 MS |
6379 | /* Field 4, the address, is omitted (which makes the columns not |
6380 | line up too nicely with the headers, but the effect is relatively | |
6381 | readable). */ | |
a96d9b2e SDJ |
6382 | if (opts.addressprint) |
6383 | ui_out_field_skip (uiout, "addr"); | |
6384 | annotate_field (5); | |
6385 | ||
6386 | if (b->syscalls_to_be_caught | |
6387 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6388 | ui_out_text (uiout, "syscalls \""); | |
6389 | else | |
6390 | ui_out_text (uiout, "syscall \""); | |
6391 | ||
6392 | if (b->syscalls_to_be_caught) | |
6393 | { | |
6394 | int i, iter; | |
6395 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6396 | |
a96d9b2e SDJ |
6397 | for (i = 0; |
6398 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6399 | i++) | |
6400 | { | |
6401 | char *x = text; | |
6402 | struct syscall s; | |
6403 | get_syscall_by_number (iter, &s); | |
6404 | ||
6405 | if (s.name != NULL) | |
6406 | text = xstrprintf ("%s%s, ", text, s.name); | |
6407 | else | |
6408 | text = xstrprintf ("%s%d, ", text, iter); | |
6409 | ||
6410 | /* We have to xfree the last 'text' (now stored at 'x') | |
6411 | because xstrprintf dinamically allocates new space for it | |
6412 | on every call. */ | |
6413 | xfree (x); | |
6414 | } | |
6415 | /* Remove the last comma. */ | |
6416 | text[strlen (text) - 2] = '\0'; | |
6417 | ui_out_field_string (uiout, "what", text); | |
6418 | } | |
6419 | else | |
6420 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6421 | ui_out_text (uiout, "\" "); | |
6422 | } | |
6423 | ||
6424 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6425 | catchpoints. */ | |
6426 | ||
6427 | static void | |
6428 | print_mention_catch_syscall (struct breakpoint *b) | |
6429 | { | |
6430 | if (b->syscalls_to_be_caught) | |
6431 | { | |
6432 | int i, iter; | |
6433 | ||
6434 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6435 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6436 | else | |
6437 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6438 | ||
6439 | for (i = 0; | |
6440 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6441 | i++) | |
6442 | { | |
6443 | struct syscall s; | |
6444 | get_syscall_by_number (iter, &s); | |
6445 | ||
6446 | if (s.name) | |
6447 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6448 | else | |
6449 | printf_filtered (" %d", s.number); | |
6450 | } | |
6451 | printf_filtered (")"); | |
6452 | } | |
6453 | else | |
6454 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6455 | b->number); | |
6456 | } | |
6457 | ||
6149aea9 PA |
6458 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6459 | catchpoints. */ | |
6460 | ||
6461 | static void | |
6462 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6463 | { | |
6464 | fprintf_unfiltered (fp, "catch syscall"); | |
6465 | ||
6466 | if (b->syscalls_to_be_caught) | |
6467 | { | |
6468 | int i, iter; | |
6469 | ||
6470 | for (i = 0; | |
6471 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6472 | i++) | |
6473 | { | |
6474 | struct syscall s; | |
6475 | ||
6476 | get_syscall_by_number (iter, &s); | |
6477 | if (s.name) | |
6478 | fprintf_unfiltered (fp, " %s", s.name); | |
6479 | else | |
6480 | fprintf_unfiltered (fp, " %d", s.number); | |
6481 | } | |
6482 | } | |
6483 | } | |
6484 | ||
a96d9b2e SDJ |
6485 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6486 | ||
6487 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6488 | { | |
6489 | insert_catch_syscall, | |
6490 | remove_catch_syscall, | |
6491 | breakpoint_hit_catch_syscall, | |
e09342b5 | 6492 | NULL, /* resources_needed */ |
a96d9b2e SDJ |
6493 | print_it_catch_syscall, |
6494 | print_one_catch_syscall, | |
6149aea9 PA |
6495 | print_mention_catch_syscall, |
6496 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6497 | }; |
6498 | ||
6499 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6500 | ||
6501 | static int | |
6502 | syscall_catchpoint_p (struct breakpoint *b) | |
6503 | { | |
6504 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6505 | } | |
6506 | ||
6507 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6508 | but does NOT mention it nor update the global location list. | |
6509 | This is useful if you need to fill more fields in the | |
6510 | struct breakpoint before calling mention. | |
ce78b96d JB |
6511 | |
6512 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6513 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6514 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6515 | to the catchpoint. */ | |
6516 | ||
6517 | static struct breakpoint * | |
a96d9b2e SDJ |
6518 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6519 | char *cond_string, | |
6520 | struct breakpoint_ops *ops) | |
c906108c | 6521 | { |
c5aa993b JM |
6522 | struct symtab_and_line sal; |
6523 | struct breakpoint *b; | |
c5aa993b | 6524 | |
fe39c653 | 6525 | init_sal (&sal); |
6c95b8df | 6526 | sal.pspace = current_program_space; |
c5aa993b | 6527 | |
a6d9a66e | 6528 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6529 | set_breakpoint_count (breakpoint_count + 1); |
6530 | b->number = breakpoint_count; | |
ce78b96d | 6531 | |
1b36a34b | 6532 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6533 | b->thread = -1; |
c906108c | 6534 | b->addr_string = NULL; |
b5de0fa7 EZ |
6535 | b->enable_state = bp_enabled; |
6536 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6537 | b->ops = ops; |
c5aa993b | 6538 | |
a96d9b2e SDJ |
6539 | return b; |
6540 | } | |
6541 | ||
6542 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6543 | ||
6544 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6545 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6546 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6547 | to the catchpoint. */ | |
6548 | ||
6549 | static struct breakpoint * | |
6550 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6551 | char *cond_string, struct breakpoint_ops *ops) | |
6552 | { | |
6553 | struct breakpoint *b = | |
6554 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6555 | ||
c906108c | 6556 | mention (b); |
ce78b96d | 6557 | update_global_location_list (1); |
c906108c | 6558 | |
ce78b96d | 6559 | return b; |
c906108c | 6560 | } |
c5aa993b | 6561 | |
9b70b993 | 6562 | static void |
a6d9a66e UW |
6563 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6564 | int tempflag, char *cond_string, | |
ce78b96d | 6565 | struct breakpoint_ops *ops) |
c906108c | 6566 | { |
a6d9a66e UW |
6567 | struct breakpoint *b |
6568 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6569 | |
6570 | /* FIXME: We should put this information in a breakpoint private data | |
6571 | area. */ | |
6572 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6573 | } |
6574 | ||
fe798b75 JB |
6575 | /* Exec catchpoints. */ |
6576 | ||
77b06cd7 TJB |
6577 | static int |
6578 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6579 | { |
77b06cd7 | 6580 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6581 | } |
c906108c | 6582 | |
fe798b75 | 6583 | static int |
77b06cd7 | 6584 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6585 | { |
6586 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6587 | } | |
c906108c | 6588 | |
fe798b75 JB |
6589 | static int |
6590 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6591 | { | |
6592 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6593 | } | |
c906108c | 6594 | |
fe798b75 JB |
6595 | static enum print_stop_action |
6596 | print_it_catch_exec (struct breakpoint *b) | |
6597 | { | |
6598 | annotate_catchpoint (b->number); | |
6599 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6600 | b->exec_pathname); | |
6601 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6602 | } |
6603 | ||
fe798b75 | 6604 | static void |
a6d9a66e | 6605 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6606 | { |
6607 | struct value_print_options opts; | |
6608 | ||
6609 | get_user_print_options (&opts); | |
6610 | ||
6611 | /* Field 4, the address, is omitted (which makes the columns | |
6612 | not line up too nicely with the headers, but the effect | |
6613 | is relatively readable). */ | |
6614 | if (opts.addressprint) | |
6615 | ui_out_field_skip (uiout, "addr"); | |
6616 | annotate_field (5); | |
6617 | ui_out_text (uiout, "exec"); | |
6618 | if (b->exec_pathname != NULL) | |
6619 | { | |
6620 | ui_out_text (uiout, ", program \""); | |
6621 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6622 | ui_out_text (uiout, "\" "); | |
6623 | } | |
6624 | } | |
6625 | ||
6626 | static void | |
6627 | print_mention_catch_exec (struct breakpoint *b) | |
6628 | { | |
6629 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6630 | } | |
6631 | ||
6149aea9 PA |
6632 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6633 | catchpoints. */ | |
6634 | ||
6635 | static void | |
6636 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6637 | { | |
6638 | fprintf_unfiltered (fp, "catch exec"); | |
6639 | } | |
6640 | ||
fe798b75 JB |
6641 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6642 | { | |
6643 | insert_catch_exec, | |
6644 | remove_catch_exec, | |
6645 | breakpoint_hit_catch_exec, | |
e09342b5 | 6646 | NULL, /* resources_needed */ |
fe798b75 JB |
6647 | print_it_catch_exec, |
6648 | print_one_catch_exec, | |
6149aea9 PA |
6649 | print_mention_catch_exec, |
6650 | print_recreate_catch_exec | |
fe798b75 JB |
6651 | }; |
6652 | ||
a96d9b2e SDJ |
6653 | static void |
6654 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6655 | struct breakpoint_ops *ops) | |
6656 | { | |
6657 | struct gdbarch *gdbarch = get_current_arch (); | |
6658 | struct breakpoint *b = | |
6659 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6660 | ||
6661 | b->syscalls_to_be_caught = filter; | |
6662 | ||
6663 | /* Now, we have to mention the breakpoint and update the global | |
6664 | location list. */ | |
6665 | mention (b); | |
6666 | update_global_location_list (1); | |
6667 | } | |
6668 | ||
c906108c | 6669 | static int |
fba45db2 | 6670 | hw_breakpoint_used_count (void) |
c906108c | 6671 | { |
52f0bd74 | 6672 | struct breakpoint *b; |
c906108c SS |
6673 | int i = 0; |
6674 | ||
6675 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6676 | { |
d6b74ac4 | 6677 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6678 | i++; |
6679 | } | |
c906108c SS |
6680 | |
6681 | return i; | |
6682 | } | |
6683 | ||
6684 | static int | |
fba45db2 | 6685 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6686 | { |
c906108c | 6687 | int i = 0; |
e09342b5 TJB |
6688 | struct breakpoint *b; |
6689 | struct bp_location *bl; | |
c906108c SS |
6690 | |
6691 | *other_type_used = 0; | |
6692 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6693 | { |
6694 | if (!breakpoint_enabled (b)) | |
6695 | continue; | |
6696 | ||
c5aa993b | 6697 | if (b->type == type) |
e09342b5 TJB |
6698 | for (bl = b->loc; bl; bl = bl->next) |
6699 | { | |
6700 | /* Special types of hardware watchpoints may use more than | |
6701 | one register. */ | |
6702 | if (b->ops && b->ops->resources_needed) | |
6703 | i += b->ops->resources_needed (bl); | |
6704 | else | |
6705 | i++; | |
6706 | } | |
cc60f2e3 | 6707 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6708 | *other_type_used = 1; |
e09342b5 TJB |
6709 | } |
6710 | ||
c906108c SS |
6711 | return i; |
6712 | } | |
6713 | ||
c906108c | 6714 | void |
fba45db2 | 6715 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6716 | { |
c5aa993b | 6717 | struct breakpoint *b; |
c906108c SS |
6718 | |
6719 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6720 | { |
cc60f2e3 | 6721 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6722 | { |
b5de0fa7 | 6723 | b->enable_state = bp_call_disabled; |
b60e7edf | 6724 | update_global_location_list (0); |
c5aa993b JM |
6725 | } |
6726 | } | |
c906108c SS |
6727 | } |
6728 | ||
6729 | void | |
fba45db2 | 6730 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6731 | { |
c5aa993b | 6732 | struct breakpoint *b; |
c906108c SS |
6733 | |
6734 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6735 | { |
cc60f2e3 | 6736 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6737 | { |
b5de0fa7 | 6738 | b->enable_state = bp_enabled; |
b60e7edf | 6739 | update_global_location_list (1); |
c5aa993b JM |
6740 | } |
6741 | } | |
c906108c SS |
6742 | } |
6743 | ||
8bea4e01 UW |
6744 | void |
6745 | disable_breakpoints_before_startup (void) | |
6746 | { | |
6747 | struct breakpoint *b; | |
6748 | int found = 0; | |
6749 | ||
6750 | ALL_BREAKPOINTS (b) | |
6751 | { | |
6c95b8df PA |
6752 | if (b->pspace != current_program_space) |
6753 | continue; | |
6754 | ||
8bea4e01 UW |
6755 | if ((b->type == bp_breakpoint |
6756 | || b->type == bp_hardware_breakpoint) | |
6757 | && breakpoint_enabled (b)) | |
6758 | { | |
6759 | b->enable_state = bp_startup_disabled; | |
6760 | found = 1; | |
6761 | } | |
6762 | } | |
6763 | ||
6764 | if (found) | |
6765 | update_global_location_list (0); | |
6766 | ||
6c95b8df | 6767 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6768 | } |
6769 | ||
6770 | void | |
6771 | enable_breakpoints_after_startup (void) | |
6772 | { | |
6773 | struct breakpoint *b; | |
6774 | int found = 0; | |
6775 | ||
6c95b8df | 6776 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6777 | |
6778 | ALL_BREAKPOINTS (b) | |
6779 | { | |
6c95b8df PA |
6780 | if (b->pspace != current_program_space) |
6781 | continue; | |
6782 | ||
8bea4e01 UW |
6783 | if ((b->type == bp_breakpoint |
6784 | || b->type == bp_hardware_breakpoint) | |
6785 | && b->enable_state == bp_startup_disabled) | |
6786 | { | |
6787 | b->enable_state = bp_enabled; | |
6788 | found = 1; | |
6789 | } | |
6790 | } | |
6791 | ||
6792 | if (found) | |
6793 | breakpoint_re_set (); | |
6794 | } | |
6795 | ||
c906108c SS |
6796 | |
6797 | /* Set a breakpoint that will evaporate an end of command | |
6798 | at address specified by SAL. | |
6799 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6800 | ||
6801 | struct breakpoint * | |
a6d9a66e UW |
6802 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6803 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6804 | { |
52f0bd74 | 6805 | struct breakpoint *b; |
edb3359d DJ |
6806 | |
6807 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6808 | one. */ | |
6809 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6810 | ||
a6d9a66e | 6811 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6812 | b->enable_state = bp_enabled; |
6813 | b->disposition = disp_donttouch; | |
818dd999 | 6814 | b->frame_id = frame_id; |
c906108c | 6815 | |
4a64f543 MS |
6816 | /* If we're debugging a multi-threaded program, then we want |
6817 | momentary breakpoints to be active in only a single thread of | |
6818 | control. */ | |
39f77062 KB |
6819 | if (in_thread_list (inferior_ptid)) |
6820 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6821 | |
b60e7edf | 6822 | update_global_location_list_nothrow (1); |
74960c60 | 6823 | |
c906108c SS |
6824 | return b; |
6825 | } | |
611c83ae | 6826 | |
e58b0e63 PA |
6827 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6828 | ORIG is NULL. */ | |
6829 | ||
6830 | struct breakpoint * | |
6831 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6832 | { | |
6833 | struct breakpoint *copy; | |
6834 | ||
6835 | /* If there's nothing to clone, then return nothing. */ | |
6836 | if (orig == NULL) | |
6837 | return NULL; | |
6838 | ||
a6d9a66e | 6839 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6840 | copy->loc = allocate_bp_location (copy); |
6841 | set_breakpoint_location_function (copy->loc); | |
6842 | ||
a6d9a66e | 6843 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6844 | copy->loc->requested_address = orig->loc->requested_address; |
6845 | copy->loc->address = orig->loc->address; | |
6846 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6847 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6848 | |
6849 | if (orig->source_file == NULL) | |
6850 | copy->source_file = NULL; | |
6851 | else | |
6852 | copy->source_file = xstrdup (orig->source_file); | |
6853 | ||
6854 | copy->line_number = orig->line_number; | |
6855 | copy->frame_id = orig->frame_id; | |
6856 | copy->thread = orig->thread; | |
6c95b8df | 6857 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6858 | |
6859 | copy->enable_state = bp_enabled; | |
6860 | copy->disposition = disp_donttouch; | |
6861 | copy->number = internal_breakpoint_number--; | |
6862 | ||
6863 | update_global_location_list_nothrow (0); | |
6864 | return copy; | |
6865 | } | |
6866 | ||
611c83ae | 6867 | struct breakpoint * |
a6d9a66e UW |
6868 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6869 | enum bptype type) | |
611c83ae PA |
6870 | { |
6871 | struct symtab_and_line sal; | |
6872 | ||
6873 | sal = find_pc_line (pc, 0); | |
6874 | sal.pc = pc; | |
6875 | sal.section = find_pc_overlay (pc); | |
6876 | sal.explicit_pc = 1; | |
6877 | ||
a6d9a66e | 6878 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6879 | } |
c906108c | 6880 | \f |
c5aa993b | 6881 | |
c906108c SS |
6882 | /* Tell the user we have just set a breakpoint B. */ |
6883 | ||
6884 | static void | |
fba45db2 | 6885 | mention (struct breakpoint *b) |
c906108c SS |
6886 | { |
6887 | int say_where = 0; | |
fa8a61dc | 6888 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6889 | struct value_print_options opts; |
6890 | ||
6891 | get_user_print_options (&opts); | |
8b93c638 | 6892 | |
9a4105ab AC |
6893 | /* FIXME: This is misplaced; mention() is called by things (like |
6894 | hitting a watchpoint) other than breakpoint creation. It should | |
6895 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6896 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6897 | observer_notify_breakpoint_created (b->number); |
c906108c | 6898 | |
3086aeae DJ |
6899 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6900 | b->ops->print_mention (b); | |
6901 | else | |
6902 | switch (b->type) | |
6903 | { | |
6904 | case bp_none: | |
3e43a32a MS |
6905 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), |
6906 | b->number); | |
3086aeae DJ |
6907 | break; |
6908 | case bp_watchpoint: | |
6909 | ui_out_text (uiout, "Watchpoint "); | |
6910 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6911 | ui_out_field_int (uiout, "number", b->number); | |
6912 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6913 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6914 | do_cleanups (ui_out_chain); |
6915 | break; | |
6916 | case bp_hardware_watchpoint: | |
6917 | ui_out_text (uiout, "Hardware watchpoint "); | |
6918 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6919 | ui_out_field_int (uiout, "number", b->number); | |
6920 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6921 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6922 | do_cleanups (ui_out_chain); |
6923 | break; | |
6924 | case bp_read_watchpoint: | |
6925 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6926 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6927 | ui_out_field_int (uiout, "number", b->number); | |
6928 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6929 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6930 | do_cleanups (ui_out_chain); |
6931 | break; | |
6932 | case bp_access_watchpoint: | |
6933 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6934 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6935 | ui_out_field_int (uiout, "number", b->number); | |
6936 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6937 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6938 | do_cleanups (ui_out_chain); |
6939 | break; | |
6940 | case bp_breakpoint: | |
6941 | if (ui_out_is_mi_like_p (uiout)) | |
6942 | { | |
6943 | say_where = 0; | |
6944 | break; | |
6945 | } | |
2cec12e5 AR |
6946 | if (b->disposition == disp_del) |
6947 | printf_filtered (_("Temporary breakpoint")); | |
6948 | else | |
6949 | printf_filtered (_("Breakpoint")); | |
6950 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6951 | say_where = 1; |
6952 | break; | |
6953 | case bp_hardware_breakpoint: | |
6954 | if (ui_out_is_mi_like_p (uiout)) | |
6955 | { | |
6956 | say_where = 0; | |
6957 | break; | |
6958 | } | |
a3f17187 | 6959 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6960 | say_where = 1; |
6961 | break; | |
1042e4c0 SS |
6962 | case bp_tracepoint: |
6963 | if (ui_out_is_mi_like_p (uiout)) | |
6964 | { | |
6965 | say_where = 0; | |
6966 | break; | |
6967 | } | |
6968 | printf_filtered (_("Tracepoint")); | |
6969 | printf_filtered (_(" %d"), b->number); | |
6970 | say_where = 1; | |
6971 | break; | |
7a697b8d SS |
6972 | case bp_fast_tracepoint: |
6973 | if (ui_out_is_mi_like_p (uiout)) | |
6974 | { | |
6975 | say_where = 0; | |
6976 | break; | |
6977 | } | |
6978 | printf_filtered (_("Fast tracepoint")); | |
6979 | printf_filtered (_(" %d"), b->number); | |
6980 | say_where = 1; | |
6981 | break; | |
0fb4aa4b PA |
6982 | case bp_static_tracepoint: |
6983 | if (ui_out_is_mi_like_p (uiout)) | |
6984 | { | |
6985 | say_where = 0; | |
6986 | break; | |
6987 | } | |
6988 | printf_filtered (_("Static tracepoint")); | |
6989 | printf_filtered (_(" %d"), b->number); | |
6990 | say_where = 1; | |
6991 | break; | |
3086aeae DJ |
6992 | |
6993 | case bp_until: | |
6994 | case bp_finish: | |
6995 | case bp_longjmp: | |
6996 | case bp_longjmp_resume: | |
186c406b TT |
6997 | case bp_exception: |
6998 | case bp_exception_resume: | |
3086aeae | 6999 | case bp_step_resume: |
3086aeae | 7000 | case bp_call_dummy: |
aa7d318d | 7001 | case bp_std_terminate: |
3086aeae DJ |
7002 | case bp_watchpoint_scope: |
7003 | case bp_shlib_event: | |
7004 | case bp_thread_event: | |
7005 | case bp_overlay_event: | |
4efc6507 | 7006 | case bp_jit_event: |
0fd8e87f | 7007 | case bp_longjmp_master: |
aa7d318d | 7008 | case bp_std_terminate_master: |
186c406b | 7009 | case bp_exception_master: |
3086aeae DJ |
7010 | break; |
7011 | } | |
c906108c | 7012 | |
c906108c SS |
7013 | if (say_where) |
7014 | { | |
a3f17187 AC |
7015 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
7016 | single string. */ | |
0d381245 | 7017 | if (b->loc == NULL) |
c906108c | 7018 | { |
a3f17187 | 7019 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
7020 | } |
7021 | else | |
7022 | { | |
79a45b7d | 7023 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
7024 | { |
7025 | printf_filtered (" at "); | |
5af949e3 UW |
7026 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
7027 | gdb_stdout); | |
0101ce28 JJ |
7028 | } |
7029 | if (b->source_file) | |
7030 | printf_filtered (": file %s, line %d.", | |
7031 | b->source_file, b->line_number); | |
0d381245 VP |
7032 | |
7033 | if (b->loc->next) | |
7034 | { | |
7035 | struct bp_location *loc = b->loc; | |
7036 | int n = 0; | |
7037 | for (; loc; loc = loc->next) | |
7038 | ++n; | |
7039 | printf_filtered (" (%d locations)", n); | |
7040 | } | |
7041 | ||
c906108c | 7042 | } |
c906108c | 7043 | } |
9dc5e2a9 | 7044 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7045 | return; |
c906108c SS |
7046 | printf_filtered ("\n"); |
7047 | } | |
c906108c | 7048 | \f |
c5aa993b | 7049 | |
0d381245 | 7050 | static struct bp_location * |
39d61571 | 7051 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7052 | const struct symtab_and_line *sal) |
7053 | { | |
7054 | struct bp_location *loc, **tmp; | |
7055 | ||
39d61571 | 7056 | loc = allocate_bp_location (b); |
0d381245 VP |
7057 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7058 | ; | |
7059 | *tmp = loc; | |
a6d9a66e UW |
7060 | loc->gdbarch = get_sal_arch (*sal); |
7061 | if (!loc->gdbarch) | |
7062 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7063 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7064 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7065 | loc->requested_address, b->type); | |
6c95b8df PA |
7066 | loc->pspace = sal->pspace; |
7067 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7068 | loc->section = sal->section; |
7069 | ||
7070 | set_breakpoint_location_function (loc); | |
7071 | return loc; | |
7072 | } | |
514f746b AR |
7073 | \f |
7074 | ||
7075 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7076 | return 0 otherwise. */ | |
7077 | ||
7078 | static int | |
7079 | bp_loc_is_permanent (struct bp_location *loc) | |
7080 | { | |
7081 | int len; | |
7082 | CORE_ADDR addr; | |
7083 | const gdb_byte *brk; | |
7084 | gdb_byte *target_mem; | |
939c61fa JK |
7085 | struct cleanup *cleanup; |
7086 | int retval = 0; | |
514f746b AR |
7087 | |
7088 | gdb_assert (loc != NULL); | |
7089 | ||
7090 | addr = loc->address; | |
a6d9a66e | 7091 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7092 | |
939c61fa JK |
7093 | /* Software breakpoints unsupported? */ |
7094 | if (brk == NULL) | |
7095 | return 0; | |
7096 | ||
514f746b AR |
7097 | target_mem = alloca (len); |
7098 | ||
939c61fa JK |
7099 | /* Enable the automatic memory restoration from breakpoints while |
7100 | we read the memory. Otherwise we could say about our temporary | |
7101 | breakpoints they are permanent. */ | |
6c95b8df PA |
7102 | cleanup = save_current_space_and_thread (); |
7103 | ||
7104 | switch_to_program_space_and_thread (loc->pspace); | |
7105 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7106 | |
514f746b AR |
7107 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7108 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7109 | retval = 1; |
514f746b | 7110 | |
939c61fa JK |
7111 | do_cleanups (cleanup); |
7112 | ||
7113 | return retval; | |
514f746b AR |
7114 | } |
7115 | ||
7116 | ||
c3f6f71d | 7117 | |
018d34a4 VP |
7118 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7119 | as textual description of the location, and COND_STRING | |
db107f19 | 7120 | as condition expression. */ |
018d34a4 VP |
7121 | |
7122 | static void | |
8cdf0e15 VP |
7123 | create_breakpoint_sal (struct gdbarch *gdbarch, |
7124 | struct symtabs_and_lines sals, char *addr_string, | |
7125 | char *cond_string, | |
7126 | enum bptype type, enum bpdisp disposition, | |
7127 | int thread, int task, int ignore_count, | |
84f4c1fe PM |
7128 | struct breakpoint_ops *ops, int from_tty, |
7129 | int enabled, int internal) | |
018d34a4 | 7130 | { |
0d381245 VP |
7131 | struct breakpoint *b = NULL; |
7132 | int i; | |
018d34a4 VP |
7133 | |
7134 | if (type == bp_hardware_breakpoint) | |
7135 | { | |
7136 | int i = hw_breakpoint_used_count (); | |
7137 | int target_resources_ok = | |
d92524f1 | 7138 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7139 | i + 1, 0); |
7140 | if (target_resources_ok == 0) | |
7141 | error (_("No hardware breakpoint support in the target.")); | |
7142 | else if (target_resources_ok < 0) | |
7143 | error (_("Hardware breakpoints used exceeds limit.")); | |
7144 | } | |
7145 | ||
6c95b8df PA |
7146 | gdb_assert (sals.nelts > 0); |
7147 | ||
0d381245 VP |
7148 | for (i = 0; i < sals.nelts; ++i) |
7149 | { | |
7150 | struct symtab_and_line sal = sals.sals[i]; | |
7151 | struct bp_location *loc; | |
7152 | ||
7153 | if (from_tty) | |
5af949e3 UW |
7154 | { |
7155 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7156 | if (!loc_gdbarch) | |
7157 | loc_gdbarch = gdbarch; | |
7158 | ||
7159 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7160 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7161 | } |
0d381245 VP |
7162 | |
7163 | if (i == 0) | |
7164 | { | |
a6d9a66e | 7165 | b = set_raw_breakpoint (gdbarch, sal, type); |
84f4c1fe | 7166 | set_breakpoint_number (internal, b); |
0d381245 | 7167 | b->thread = thread; |
4a306c9a | 7168 | b->task = task; |
018d34a4 | 7169 | |
0d381245 VP |
7170 | b->cond_string = cond_string; |
7171 | b->ignore_count = ignore_count; | |
41447f92 | 7172 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7173 | b->disposition = disposition; |
6c95b8df PA |
7174 | b->pspace = sals.sals[0].pspace; |
7175 | ||
0fb4aa4b PA |
7176 | if (type == bp_static_tracepoint) |
7177 | { | |
7178 | struct static_tracepoint_marker marker; | |
7179 | ||
7180 | if (is_marker_spec (addr_string)) | |
7181 | { | |
7182 | /* We already know the marker exists, otherwise, we | |
7183 | wouldn't see a sal for it. */ | |
7184 | char *p = &addr_string[3]; | |
7185 | char *endp; | |
7186 | char *marker_str; | |
7187 | int i; | |
7188 | ||
7189 | while (*p == ' ' || *p == '\t') | |
7190 | p++; | |
7191 | ||
7192 | endp = p; | |
7193 | while (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7194 | endp++; | |
7195 | ||
7196 | marker_str = savestring (p, endp - p); | |
7197 | b->static_trace_marker_id = marker_str; | |
7198 | ||
3e43a32a MS |
7199 | printf_filtered (_("Probed static tracepoint " |
7200 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7201 | b->static_trace_marker_id); |
7202 | } | |
7203 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7204 | { | |
7205 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
7206 | release_static_tracepoint_marker (&marker); | |
7207 | ||
3e43a32a MS |
7208 | printf_filtered (_("Probed static tracepoint " |
7209 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7210 | b->static_trace_marker_id); |
7211 | } | |
7212 | else | |
3e43a32a MS |
7213 | warning (_("Couldn't determine the static " |
7214 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7215 | } |
7216 | ||
6c95b8df | 7217 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7218 | && (b->type == bp_breakpoint |
7219 | || b->type == bp_hardware_breakpoint)) | |
7220 | b->enable_state = bp_startup_disabled; | |
7221 | ||
0d381245 VP |
7222 | loc = b->loc; |
7223 | } | |
7224 | else | |
018d34a4 | 7225 | { |
39d61571 | 7226 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7227 | } |
7228 | ||
514f746b AR |
7229 | if (bp_loc_is_permanent (loc)) |
7230 | make_breakpoint_permanent (b); | |
7231 | ||
0d381245 VP |
7232 | if (b->cond_string) |
7233 | { | |
7234 | char *arg = b->cond_string; | |
d32a6982 | 7235 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7236 | if (*arg) |
db107f19 | 7237 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7238 | } |
0d381245 | 7239 | } |
018d34a4 VP |
7240 | |
7241 | if (addr_string) | |
7242 | b->addr_string = addr_string; | |
7243 | else | |
7244 | /* addr_string has to be used or breakpoint_re_set will delete | |
7245 | me. */ | |
5af949e3 UW |
7246 | b->addr_string |
7247 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7248 | |
604133b5 | 7249 | b->ops = ops; |
84f4c1fe PM |
7250 | if (internal) |
7251 | /* Do not mention breakpoints with a negative number, but do | |
7252 | notify observers. */ | |
7253 | observer_notify_breakpoint_created (b->number); | |
7254 | else | |
7255 | mention (b); | |
018d34a4 VP |
7256 | } |
7257 | ||
ed0616c6 VP |
7258 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7259 | elements to fill the void space. */ | |
2c0b251b PA |
7260 | static void |
7261 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7262 | { |
7263 | int i = index_to_remove+1; | |
7264 | int last_index = sal->nelts-1; | |
7265 | ||
7266 | for (;i <= last_index; ++i) | |
7267 | sal->sals[i-1] = sal->sals[i]; | |
7268 | ||
7269 | --(sal->nelts); | |
7270 | } | |
7271 | ||
6c95b8df PA |
7272 | /* If appropriate, obtains all sals that correspond to the same file |
7273 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7274 | will want to set a breakpoint at foo.c:line, and not really care | |
7275 | about program spaces. This is done only if SAL does not have | |
7276 | explicit PC and has line and file information. If we got just a | |
7277 | single expanded sal, return the original. | |
ed0616c6 | 7278 | |
6c95b8df PA |
7279 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7280 | which the name of enclosing function is different from SAL. This | |
7281 | makes sure that if we have breakpoint originally set in template | |
7282 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7283 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7284 | |
2c0b251b | 7285 | static struct symtabs_and_lines |
ed0616c6 VP |
7286 | expand_line_sal_maybe (struct symtab_and_line sal) |
7287 | { | |
7288 | struct symtabs_and_lines expanded; | |
7289 | CORE_ADDR original_pc = sal.pc; | |
7290 | char *original_function = NULL; | |
7291 | int found; | |
7292 | int i; | |
6c95b8df | 7293 | struct cleanup *old_chain; |
ed0616c6 VP |
7294 | |
7295 | /* If we have explicit pc, don't expand. | |
7296 | If we have no line number, we can't expand. */ | |
7297 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7298 | { | |
7299 | expanded.nelts = 1; | |
7300 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7301 | expanded.sals[0] = sal; | |
7302 | return expanded; | |
7303 | } | |
7304 | ||
7305 | sal.pc = 0; | |
6c95b8df PA |
7306 | |
7307 | old_chain = save_current_space_and_thread (); | |
7308 | ||
7309 | switch_to_program_space_and_thread (sal.pspace); | |
7310 | ||
ed0616c6 | 7311 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7312 | |
7313 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7314 | expanded = expand_line_sal (sal); |
6c95b8df | 7315 | |
ed0616c6 VP |
7316 | if (expanded.nelts == 1) |
7317 | { | |
3dba1c98 JB |
7318 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7319 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7320 | xfree (expanded.sals); |
7321 | expanded.nelts = 1; | |
7322 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7323 | sal.pc = original_pc; | |
7324 | expanded.sals[0] = sal; | |
3dba1c98 | 7325 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7326 | do_cleanups (old_chain); |
ed0616c6 VP |
7327 | return expanded; |
7328 | } | |
7329 | ||
7330 | if (!sal.explicit_line) | |
7331 | { | |
7332 | CORE_ADDR func_addr, func_end; | |
7333 | for (i = 0; i < expanded.nelts; ++i) | |
7334 | { | |
7335 | CORE_ADDR pc = expanded.sals[i].pc; | |
7336 | char *this_function; | |
6c95b8df PA |
7337 | |
7338 | /* We need to switch threads as well since we're about to | |
7339 | read memory. */ | |
7340 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7341 | ||
ed0616c6 VP |
7342 | if (find_pc_partial_function (pc, &this_function, |
7343 | &func_addr, &func_end)) | |
7344 | { | |
059fb39f PM |
7345 | if (this_function |
7346 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7347 | { |
7348 | remove_sal (&expanded, i); | |
7349 | --i; | |
7350 | } | |
ed0616c6 VP |
7351 | } |
7352 | } | |
7353 | } | |
059acae7 UW |
7354 | |
7355 | /* Skip the function prologue if necessary. */ | |
7356 | for (i = 0; i < expanded.nelts; ++i) | |
7357 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7358 | |
6c95b8df PA |
7359 | do_cleanups (old_chain); |
7360 | ||
ed0616c6 VP |
7361 | if (expanded.nelts <= 1) |
7362 | { | |
4a64f543 MS |
7363 | /* This is un ugly workaround. If we get zero expanded sals |
7364 | then something is really wrong. Fix that by returning the | |
7365 | original sal. */ | |
7366 | ||
ed0616c6 VP |
7367 | xfree (expanded.sals); |
7368 | expanded.nelts = 1; | |
7369 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7370 | sal.pc = original_pc; | |
7371 | expanded.sals[0] = sal; | |
7372 | return expanded; | |
7373 | } | |
7374 | ||
7375 | if (original_pc) | |
7376 | { | |
7377 | found = 0; | |
7378 | for (i = 0; i < expanded.nelts; ++i) | |
7379 | if (expanded.sals[i].pc == original_pc) | |
7380 | { | |
7381 | found = 1; | |
7382 | break; | |
7383 | } | |
7384 | gdb_assert (found); | |
7385 | } | |
7386 | ||
7387 | return expanded; | |
7388 | } | |
7389 | ||
018d34a4 VP |
7390 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7391 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7392 | value. COND_STRING, if not NULL, specified the condition to be | |
7393 | used for all breakpoints. Essentially the only case where | |
7394 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7395 | function. In that case, it's still not possible to specify | |
7396 | separate conditions for different overloaded functions, so | |
7397 | we take just a single condition string. | |
7398 | ||
c3f6f71d | 7399 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7400 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7401 | array contents). If the function fails (error() is called), the |
7402 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7403 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7404 | |
7405 | static void | |
8cdf0e15 VP |
7406 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7407 | struct symtabs_and_lines sals, char **addr_string, | |
7408 | char *cond_string, | |
7409 | enum bptype type, enum bpdisp disposition, | |
7410 | int thread, int task, int ignore_count, | |
7411 | struct breakpoint_ops *ops, int from_tty, | |
84f4c1fe | 7412 | int enabled, int internal) |
c906108c | 7413 | { |
018d34a4 | 7414 | int i; |
cc59ec59 | 7415 | |
018d34a4 | 7416 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7417 | { |
ed0616c6 VP |
7418 | struct symtabs_and_lines expanded = |
7419 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7420 | |
8cdf0e15 VP |
7421 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7422 | cond_string, type, disposition, | |
84f4c1fe PM |
7423 | thread, task, ignore_count, ops, |
7424 | from_tty, enabled, internal); | |
c3f6f71d | 7425 | } |
c3f6f71d | 7426 | } |
c906108c | 7427 | |
c3f6f71d JM |
7428 | /* Parse ARG which is assumed to be a SAL specification possibly |
7429 | followed by conditionals. On return, SALS contains an array of SAL | |
4a64f543 MS |
7430 | addresses found. ADDR_STRING contains a vector of (canonical) |
7431 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 7432 | |
b9362cc7 | 7433 | static void |
c3f6f71d JM |
7434 | parse_breakpoint_sals (char **address, |
7435 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7436 | char ***addr_string, |
7437 | int *not_found_ptr) | |
c3f6f71d JM |
7438 | { |
7439 | char *addr_start = *address; | |
cc59ec59 | 7440 | |
c3f6f71d JM |
7441 | *addr_string = NULL; |
7442 | /* If no arg given, or if first arg is 'if ', use the default | |
4a64f543 | 7443 | breakpoint. */ |
c3f6f71d JM |
7444 | if ((*address) == NULL |
7445 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7446 | { |
7447 | if (default_breakpoint_valid) | |
7448 | { | |
c3f6f71d | 7449 | struct symtab_and_line sal; |
cc59ec59 | 7450 | |
4a64f543 | 7451 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7452 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7453 | xmalloc (sizeof (struct symtab_and_line)); |
7454 | sal.pc = default_breakpoint_address; | |
7455 | sal.line = default_breakpoint_line; | |
7456 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7457 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7458 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7459 | |
4a64f543 MS |
7460 | /* "break" without arguments is equivalent to "break *PC" |
7461 | where PC is the default_breakpoint_address. So make sure | |
7462 | to set sal.explicit_pc to prevent GDB from trying to | |
7463 | expand the list of sals to include all other instances | |
7464 | with the same symtab and line. */ | |
00903456 JK |
7465 | sal.explicit_pc = 1; |
7466 | ||
c3f6f71d JM |
7467 | sals->sals[0] = sal; |
7468 | sals->nelts = 1; | |
c906108c SS |
7469 | } |
7470 | else | |
8a3fe4f8 | 7471 | error (_("No default breakpoint address now.")); |
c906108c SS |
7472 | } |
7473 | else | |
7474 | { | |
c906108c | 7475 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7476 | current_source_symtab (which is decode_line_1's default). |
7477 | This should produce the results we want almost all of the | |
7478 | time while leaving default_breakpoint_* alone. | |
7479 | ||
1aeae86e AF |
7480 | ObjC: However, don't match an Objective-C method name which |
7481 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7482 | |
c214a6fd | 7483 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7484 | |
c906108c | 7485 | if (default_breakpoint_valid |
0378c332 | 7486 | && (!cursal.symtab |
1aeae86e AF |
7487 | || ((strchr ("+-", (*address)[0]) != NULL) |
7488 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7489 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7490 | default_breakpoint_line, addr_string, |
7491 | not_found_ptr); | |
c906108c | 7492 | else |
0101ce28 JJ |
7493 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7494 | addr_string, not_found_ptr); | |
c906108c | 7495 | } |
4a64f543 | 7496 | /* For any SAL that didn't have a canonical string, fill one in. */ |
c3f6f71d JM |
7497 | if (sals->nelts > 0 && *addr_string == NULL) |
7498 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7499 | if (addr_start != (*address)) | |
c906108c | 7500 | { |
c3f6f71d | 7501 | int i; |
cc59ec59 | 7502 | |
c3f6f71d | 7503 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7504 | { |
4a64f543 | 7505 | /* Add the string if not present. */ |
c3f6f71d | 7506 | if ((*addr_string)[i] == NULL) |
cc59ec59 MS |
7507 | (*addr_string)[i] = savestring (addr_start, |
7508 | (*address) - addr_start); | |
c906108c SS |
7509 | } |
7510 | } | |
c3f6f71d | 7511 | } |
c906108c | 7512 | |
c906108c | 7513 | |
c3f6f71d | 7514 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7515 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7516 | |
b9362cc7 | 7517 | static void |
23e7acfb | 7518 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7519 | { |
7520 | int i; | |
cc59ec59 | 7521 | |
c3f6f71d | 7522 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7523 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7524 | } |
7525 | ||
7a697b8d SS |
7526 | /* Fast tracepoints may have restrictions on valid locations. For |
7527 | instance, a fast tracepoint using a jump instead of a trap will | |
7528 | likely have to overwrite more bytes than a trap would, and so can | |
7529 | only be placed where the instruction is longer than the jump, or a | |
7530 | multi-instruction sequence does not have a jump into the middle of | |
7531 | it, etc. */ | |
7532 | ||
7533 | static void | |
7534 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7535 | struct symtabs_and_lines *sals) | |
7536 | { | |
7537 | int i, rslt; | |
7538 | struct symtab_and_line *sal; | |
7539 | char *msg; | |
7540 | struct cleanup *old_chain; | |
7541 | ||
7542 | for (i = 0; i < sals->nelts; i++) | |
7543 | { | |
7544 | sal = &sals->sals[i]; | |
7545 | ||
7546 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7547 | NULL, &msg); | |
7548 | old_chain = make_cleanup (xfree, msg); | |
7549 | ||
7550 | if (!rslt) | |
7551 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7552 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7553 | ||
7554 | do_cleanups (old_chain); | |
7555 | } | |
7556 | } | |
7557 | ||
05ff989b | 7558 | static void |
0101ce28 JJ |
7559 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7560 | { | |
7561 | struct captured_parse_breakpoint_args *args = data; | |
7562 | ||
7563 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7564 | args->not_found_ptr); | |
0101ce28 JJ |
7565 | } |
7566 | ||
018d34a4 VP |
7567 | /* Given TOK, a string specification of condition and thread, as |
7568 | accepted by the 'break' command, extract the condition | |
7569 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7570 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7571 | If no condition is found, *COND_STRING is set to NULL. |
7572 | If no thread is found, *THREAD is set to -1. */ | |
7573 | static void | |
7574 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7575 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7576 | { |
7577 | *cond_string = NULL; | |
7578 | *thread = -1; | |
7579 | while (tok && *tok) | |
7580 | { | |
7581 | char *end_tok; | |
7582 | int toklen; | |
7583 | char *cond_start = NULL; | |
7584 | char *cond_end = NULL; | |
cc59ec59 | 7585 | |
018d34a4 VP |
7586 | while (*tok == ' ' || *tok == '\t') |
7587 | tok++; | |
7588 | ||
7589 | end_tok = tok; | |
7590 | ||
7591 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7592 | end_tok++; | |
7593 | ||
7594 | toklen = end_tok - tok; | |
7595 | ||
7596 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7597 | { | |
f7545552 TT |
7598 | struct expression *expr; |
7599 | ||
018d34a4 | 7600 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7601 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7602 | xfree (expr); | |
018d34a4 VP |
7603 | cond_end = tok; |
7604 | *cond_string = savestring (cond_start, | |
7605 | cond_end - cond_start); | |
7606 | } | |
7607 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7608 | { | |
7609 | char *tmptok; | |
7610 | ||
7611 | tok = end_tok + 1; | |
7612 | tmptok = tok; | |
7613 | *thread = strtol (tok, &tok, 0); | |
7614 | if (tok == tmptok) | |
7615 | error (_("Junk after thread keyword.")); | |
7616 | if (!valid_thread_id (*thread)) | |
7617 | error (_("Unknown thread %d."), *thread); | |
7618 | } | |
4a306c9a JB |
7619 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7620 | { | |
7621 | char *tmptok; | |
7622 | ||
7623 | tok = end_tok + 1; | |
7624 | tmptok = tok; | |
7625 | *task = strtol (tok, &tok, 0); | |
7626 | if (tok == tmptok) | |
7627 | error (_("Junk after task keyword.")); | |
7628 | if (!valid_task_id (*task)) | |
b6199126 | 7629 | error (_("Unknown task %d."), *task); |
4a306c9a | 7630 | } |
018d34a4 VP |
7631 | else |
7632 | error (_("Junk at end of arguments.")); | |
7633 | } | |
7634 | } | |
7635 | ||
0fb4aa4b PA |
7636 | /* Decode a static tracepoint marker spec. */ |
7637 | ||
7638 | static struct symtabs_and_lines | |
7639 | decode_static_tracepoint_spec (char **arg_p) | |
7640 | { | |
7641 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7642 | struct symtabs_and_lines sals; | |
7643 | struct symtab_and_line sal; | |
7644 | struct symbol *sym; | |
7645 | struct cleanup *old_chain; | |
7646 | char *p = &(*arg_p)[3]; | |
7647 | char *endp; | |
7648 | char *marker_str; | |
7649 | int i; | |
7650 | ||
7651 | while (*p == ' ' || *p == '\t') | |
7652 | p++; | |
7653 | ||
7654 | endp = p; | |
7655 | while (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7656 | endp++; | |
7657 | ||
7658 | marker_str = savestring (p, endp - p); | |
7659 | old_chain = make_cleanup (xfree, marker_str); | |
7660 | ||
7661 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7662 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7663 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7664 | ||
7665 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7666 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7667 | ||
7668 | for (i = 0; i < sals.nelts; i++) | |
7669 | { | |
7670 | struct static_tracepoint_marker *marker; | |
7671 | ||
7672 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7673 | ||
7674 | init_sal (&sals.sals[i]); | |
7675 | ||
7676 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7677 | sals.sals[i].pc = marker->address; | |
7678 | ||
7679 | release_static_tracepoint_marker (marker); | |
7680 | } | |
7681 | ||
7682 | do_cleanups (old_chain); | |
7683 | ||
7684 | *arg_p = endp; | |
7685 | return sals; | |
7686 | } | |
7687 | ||
fd9b8c24 PA |
7688 | /* Set a breakpoint. This function is shared between CLI and MI |
7689 | functions for setting a breakpoint. This function has two major | |
7690 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7691 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7692 | breakpoint location, address and thread. Otherwise, ARG is just |
7693 | the location of breakpoint, with condition and thread specified by | |
7694 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7695 | the breakpoint number will be allocated from the internal | |
7696 | breakpoint count. Returns true if any breakpoint was created; | |
7697 | false otherwise. */ | |
0101ce28 | 7698 | |
8cdf0e15 VP |
7699 | int |
7700 | create_breakpoint (struct gdbarch *gdbarch, | |
7701 | char *arg, char *cond_string, int thread, | |
7702 | int parse_condition_and_thread, | |
0fb4aa4b | 7703 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7704 | int ignore_count, |
7705 | enum auto_boolean pending_break_support, | |
7706 | struct breakpoint_ops *ops, | |
84f4c1fe | 7707 | int from_tty, int enabled, int internal) |
c3f6f71d | 7708 | { |
71fff37b | 7709 | struct gdb_exception e; |
c3f6f71d | 7710 | struct symtabs_and_lines sals; |
0101ce28 | 7711 | struct symtab_and_line pending_sal; |
0101ce28 | 7712 | char *copy_arg; |
c3f6f71d JM |
7713 | char *addr_start = arg; |
7714 | char **addr_string; | |
7715 | struct cleanup *old_chain; | |
80c99de1 | 7716 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7717 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7718 | int i; |
0101ce28 | 7719 | int pending = 0; |
0101ce28 | 7720 | int not_found = 0; |
4a306c9a | 7721 | int task = 0; |
86b17b60 | 7722 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7723 | |
c3f6f71d JM |
7724 | sals.sals = NULL; |
7725 | sals.nelts = 0; | |
7726 | addr_string = NULL; | |
c3f6f71d | 7727 | |
0101ce28 JJ |
7728 | parse_args.arg_p = &arg; |
7729 | parse_args.sals_p = &sals; | |
7730 | parse_args.addr_string_p = &addr_string; | |
7731 | parse_args.not_found_ptr = ¬_found; | |
7732 | ||
0fb4aa4b PA |
7733 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7734 | { | |
7735 | int i; | |
7736 | ||
7737 | sals = decode_static_tracepoint_spec (&arg); | |
7738 | ||
7739 | copy_arg = savestring (addr_start, arg - addr_start); | |
7740 | addr_string = xcalloc (sals.nelts, sizeof (char **)); | |
7741 | for (i = 0; i < sals.nelts; i++) | |
7742 | addr_string[i] = xstrdup (copy_arg); | |
7743 | goto done; | |
7744 | } | |
7745 | ||
05ff989b AC |
7746 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7747 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7748 | |
7749 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7750 | switch (e.reason) |
0101ce28 | 7751 | { |
05ff989b | 7752 | case RETURN_QUIT: |
98deb0da | 7753 | throw_exception (e); |
05ff989b AC |
7754 | case RETURN_ERROR: |
7755 | switch (e.error) | |
0101ce28 | 7756 | { |
05ff989b | 7757 | case NOT_FOUND_ERROR: |
0101ce28 | 7758 | |
05ff989b AC |
7759 | /* If pending breakpoint support is turned off, throw |
7760 | error. */ | |
fa8d40ab JJ |
7761 | |
7762 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7763 | throw_exception (e); |
7764 | ||
7765 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7766 | |
05ff989b AC |
7767 | /* If pending breakpoint support is auto query and the user |
7768 | selects no, then simply return the error code. */ | |
059fb39f | 7769 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7770 | && !nquery (_("Make breakpoint pending on " |
7771 | "future shared library load? "))) | |
fd9b8c24 | 7772 | return 0; |
fa8d40ab | 7773 | |
05ff989b AC |
7774 | /* At this point, either the user was queried about setting |
7775 | a pending breakpoint and selected yes, or pending | |
7776 | breakpoint behavior is on and thus a pending breakpoint | |
7777 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7778 | copy_arg = xstrdup (addr_start); |
7779 | addr_string = ©_arg; | |
7780 | sals.nelts = 1; | |
7781 | sals.sals = &pending_sal; | |
7782 | pending_sal.pc = 0; | |
7783 | pending = 1; | |
05ff989b AC |
7784 | break; |
7785 | default: | |
98deb0da | 7786 | throw_exception (e); |
0101ce28 | 7787 | } |
05ff989b AC |
7788 | default: |
7789 | if (!sals.nelts) | |
fd9b8c24 | 7790 | return 0; |
0101ce28 | 7791 | } |
c3f6f71d | 7792 | |
0fb4aa4b PA |
7793 | done: |
7794 | ||
4a64f543 | 7795 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
7796 | old_chain = make_cleanup (null_cleanup, 0); |
7797 | ||
0101ce28 JJ |
7798 | if (!pending) |
7799 | { | |
7800 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7801 | make_cleanup (xfree, sals.sals); | |
7802 | ||
4a64f543 | 7803 | /* Cleanup the addr_string array but not its contents. */ |
0101ce28 JJ |
7804 | make_cleanup (xfree, addr_string); |
7805 | } | |
c3f6f71d | 7806 | |
c3f6f71d JM |
7807 | /* ----------------------------- SNIP ----------------------------- |
7808 | Anything added to the cleanup chain beyond this point is assumed | |
7809 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7810 | then the memory is not reclaimed. */ |
7811 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7812 | |
7813 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7814 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7815 | for (i = 0; i < sals.nelts; i++) |
7816 | { | |
7817 | if (addr_string[i] != NULL) | |
b8c9b27d | 7818 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7819 | } |
7820 | ||
7821 | /* Resolve all line numbers to PC's and verify that the addresses | |
7822 | are ok for the target. */ | |
0101ce28 | 7823 | if (!pending) |
23e7acfb | 7824 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7825 | |
7a697b8d SS |
7826 | /* Fast tracepoints may have additional restrictions on location. */ |
7827 | if (type_wanted == bp_fast_tracepoint) | |
7828 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7829 | ||
c3f6f71d JM |
7830 | /* Verify that condition can be parsed, before setting any |
7831 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 7832 | breakpoint. */ |
0101ce28 | 7833 | if (!pending) |
c3f6f71d | 7834 | { |
2f069f6f | 7835 | if (parse_condition_and_thread) |
72b2ff0e VP |
7836 | { |
7837 | /* Here we only parse 'arg' to separate condition | |
7838 | from thread number, so parsing in context of first | |
7839 | sal is OK. When setting the breakpoint we'll | |
7840 | re-parse it in context of each sal. */ | |
7841 | cond_string = NULL; | |
7842 | thread = -1; | |
4a306c9a JB |
7843 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7844 | &thread, &task); | |
72b2ff0e VP |
7845 | if (cond_string) |
7846 | make_cleanup (xfree, cond_string); | |
7847 | } | |
2f069f6f | 7848 | else |
72b2ff0e VP |
7849 | { |
7850 | /* Create a private copy of condition string. */ | |
7851 | if (cond_string) | |
7852 | { | |
7853 | cond_string = xstrdup (cond_string); | |
7854 | make_cleanup (xfree, cond_string); | |
7855 | } | |
7856 | } | |
0fb4aa4b PA |
7857 | |
7858 | /* If the user is creating a static tracepoint by marker id | |
7859 | (strace -m MARKER_ID), then store the sals index, so that | |
7860 | breakpoint_re_set can try to match up which of the newly | |
7861 | found markers corresponds to this one, and, don't try to | |
7862 | expand multiple locations for each sal, given than SALS | |
7863 | already should contain all sals for MARKER_ID. */ | |
7864 | if (type_wanted == bp_static_tracepoint | |
7865 | && is_marker_spec (addr_string[0])) | |
7866 | { | |
7867 | int i; | |
7868 | ||
7869 | for (i = 0; i < sals.nelts; ++i) | |
7870 | { | |
7871 | struct symtabs_and_lines expanded; | |
7872 | struct breakpoint *tp; | |
7873 | struct cleanup *old_chain; | |
7874 | ||
7875 | expanded.nelts = 1; | |
7876 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7877 | expanded.sals[0] = sals.sals[i]; | |
7878 | old_chain = make_cleanup (xfree, expanded.sals); | |
7879 | ||
7880 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], | |
7881 | cond_string, type_wanted, | |
7882 | tempflag ? disp_del : disp_donttouch, | |
7883 | thread, task, ignore_count, ops, | |
84f4c1fe | 7884 | from_tty, enabled, internal); |
0fb4aa4b PA |
7885 | |
7886 | do_cleanups (old_chain); | |
7887 | ||
7888 | /* Get the tracepoint we just created. */ | |
84f4c1fe PM |
7889 | if (internal) |
7890 | tp = get_breakpoint (internal_breakpoint_number); | |
7891 | else | |
7892 | tp = get_breakpoint (breakpoint_count); | |
0fb4aa4b PA |
7893 | gdb_assert (tp != NULL); |
7894 | ||
7895 | /* Given that its possible to have multiple markers with | |
7896 | the same string id, if the user is creating a static | |
7897 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7898 | store the sals index, so that breakpoint_re_set can | |
7899 | try to match up which of the newly found markers | |
7900 | corresponds to this one */ | |
7901 | tp->static_trace_marker_id_idx = i; | |
7902 | } | |
7903 | } | |
7904 | else | |
7905 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, | |
3e43a32a MS |
7906 | type_wanted, |
7907 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 7908 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 7909 | enabled, internal); |
c906108c | 7910 | } |
0101ce28 JJ |
7911 | else |
7912 | { | |
0101ce28 JJ |
7913 | struct breakpoint *b; |
7914 | ||
0101ce28 JJ |
7915 | make_cleanup (xfree, copy_arg); |
7916 | ||
a6d9a66e | 7917 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
84f4c1fe | 7918 | set_breakpoint_number (internal, b); |
72b2ff0e | 7919 | b->thread = -1; |
018d34a4 | 7920 | b->addr_string = addr_string[0]; |
72b2ff0e | 7921 | b->cond_string = NULL; |
0101ce28 | 7922 | b->ignore_count = ignore_count; |
0101ce28 | 7923 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7924 | b->condition_not_parsed = 1; |
604133b5 | 7925 | b->ops = ops; |
41447f92 | 7926 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7927 | b->pspace = current_program_space; |
84f4c1fe | 7928 | b->py_bp_object = NULL; |
74960c60 | 7929 | |
6c95b8df | 7930 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7931 | && (b->type == bp_breakpoint |
7932 | || b->type == bp_hardware_breakpoint)) | |
7933 | b->enable_state = bp_startup_disabled; | |
7934 | ||
84f4c1fe PM |
7935 | if (internal) |
7936 | /* Do not mention breakpoints with a negative number, | |
7937 | but do notify observers. */ | |
7938 | observer_notify_breakpoint_created (b->number); | |
7939 | else | |
7940 | mention (b); | |
0101ce28 JJ |
7941 | } |
7942 | ||
c3f6f71d | 7943 | if (sals.nelts > 1) |
95a42b64 | 7944 | { |
3e43a32a MS |
7945 | warning (_("Multiple breakpoints were set.\nUse the " |
7946 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7947 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7948 | } |
7949 | ||
80c99de1 PA |
7950 | /* That's it. Discard the cleanups for data inserted into the |
7951 | breakpoint. */ | |
7952 | discard_cleanups (bkpt_chain); | |
7953 | /* But cleanup everything else. */ | |
c3f6f71d | 7954 | do_cleanups (old_chain); |
217dc9e2 | 7955 | |
80c99de1 | 7956 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7957 | update_global_location_list (1); |
fd9b8c24 PA |
7958 | |
7959 | return 1; | |
c3f6f71d | 7960 | } |
c906108c | 7961 | |
72b2ff0e VP |
7962 | /* Set a breakpoint. |
7963 | ARG is a string describing breakpoint address, | |
7964 | condition, and thread. | |
7965 | FLAG specifies if a breakpoint is hardware on, | |
7966 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7967 | and BP_TEMPFLAG. */ | |
7968 | ||
98deb0da | 7969 | static void |
72b2ff0e | 7970 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7971 | { |
72b2ff0e | 7972 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
7973 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
7974 | ? bp_hardware_breakpoint | |
7975 | : bp_breakpoint); | |
c3f6f71d | 7976 | |
8cdf0e15 VP |
7977 | create_breakpoint (get_current_arch (), |
7978 | arg, | |
7979 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 7980 | tempflag, type_wanted, |
8cdf0e15 VP |
7981 | 0 /* Ignore count */, |
7982 | pending_break_support, | |
7983 | NULL /* breakpoint_ops */, | |
7984 | from_tty, | |
84f4c1fe PM |
7985 | 1 /* enabled */, |
7986 | 0 /* internal */); | |
c906108c SS |
7987 | } |
7988 | ||
72b2ff0e | 7989 | |
c906108c SS |
7990 | /* Helper function for break_command_1 and disassemble_command. */ |
7991 | ||
7992 | void | |
fba45db2 | 7993 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7994 | { |
7995 | CORE_ADDR pc; | |
7996 | ||
7997 | if (sal->pc == 0 && sal->symtab != NULL) | |
7998 | { | |
7999 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8000 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8001 | sal->line, sal->symtab->filename); |
8002 | sal->pc = pc; | |
6a048695 | 8003 | |
4a64f543 MS |
8004 | /* If this SAL corresponds to a breakpoint inserted using a line |
8005 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8006 | if (sal->explicit_line) |
059acae7 | 8007 | skip_prologue_sal (sal); |
c906108c SS |
8008 | } |
8009 | ||
8010 | if (sal->section == 0 && sal->symtab != NULL) | |
8011 | { | |
8012 | struct blockvector *bv; | |
c5aa993b JM |
8013 | struct block *b; |
8014 | struct symbol *sym; | |
c906108c | 8015 | |
801e3a5b | 8016 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8017 | if (bv != NULL) |
8018 | { | |
7f0df278 | 8019 | sym = block_linkage_function (b); |
c906108c SS |
8020 | if (sym != NULL) |
8021 | { | |
8022 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8023 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8024 | } |
8025 | else | |
8026 | { | |
4a64f543 MS |
8027 | /* It really is worthwhile to have the section, so we'll |
8028 | just have to look harder. This case can be executed | |
8029 | if we have line numbers but no functions (as can | |
8030 | happen in assembly source). */ | |
c906108c | 8031 | |
c5aa993b | 8032 | struct minimal_symbol *msym; |
6c95b8df PA |
8033 | struct cleanup *old_chain = save_current_space_and_thread (); |
8034 | ||
8035 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8036 | |
8037 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8038 | if (msym) | |
714835d5 | 8039 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8040 | |
8041 | do_cleanups (old_chain); | |
c906108c SS |
8042 | } |
8043 | } | |
8044 | } | |
8045 | } | |
8046 | ||
8047 | void | |
fba45db2 | 8048 | break_command (char *arg, int from_tty) |
c906108c | 8049 | { |
db107f19 | 8050 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8051 | } |
8052 | ||
c906108c | 8053 | void |
fba45db2 | 8054 | tbreak_command (char *arg, int from_tty) |
c906108c | 8055 | { |
db107f19 | 8056 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8057 | } |
8058 | ||
c906108c | 8059 | static void |
fba45db2 | 8060 | hbreak_command (char *arg, int from_tty) |
c906108c | 8061 | { |
db107f19 | 8062 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8063 | } |
8064 | ||
8065 | static void | |
fba45db2 | 8066 | thbreak_command (char *arg, int from_tty) |
c906108c | 8067 | { |
db107f19 | 8068 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8069 | } |
8070 | ||
8071 | static void | |
fba45db2 | 8072 | stop_command (char *arg, int from_tty) |
c906108c | 8073 | { |
a3f17187 | 8074 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8075 | Usage: stop in <function | address>\n\ |
a3f17187 | 8076 | stop at <line>\n")); |
c906108c SS |
8077 | } |
8078 | ||
8079 | static void | |
fba45db2 | 8080 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8081 | { |
8082 | int badInput = 0; | |
8083 | ||
c5aa993b | 8084 | if (arg == (char *) NULL) |
c906108c SS |
8085 | badInput = 1; |
8086 | else if (*arg != '*') | |
8087 | { | |
8088 | char *argptr = arg; | |
8089 | int hasColon = 0; | |
8090 | ||
4a64f543 | 8091 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8092 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8093 | function/method name. */ |
c906108c | 8094 | while (*argptr && !hasColon) |
c5aa993b JM |
8095 | { |
8096 | hasColon = (*argptr == ':'); | |
8097 | argptr++; | |
8098 | } | |
c906108c SS |
8099 | |
8100 | if (hasColon) | |
c5aa993b | 8101 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8102 | else |
c5aa993b | 8103 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8104 | } |
8105 | ||
8106 | if (badInput) | |
a3f17187 | 8107 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8108 | else |
db107f19 | 8109 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8110 | } |
8111 | ||
8112 | static void | |
fba45db2 | 8113 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8114 | { |
8115 | int badInput = 0; | |
8116 | ||
c5aa993b | 8117 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8118 | badInput = 1; |
8119 | else | |
8120 | { | |
8121 | char *argptr = arg; | |
8122 | int hasColon = 0; | |
8123 | ||
4a64f543 MS |
8124 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8125 | it is probably a line number. */ | |
c906108c | 8126 | while (*argptr && !hasColon) |
c5aa993b JM |
8127 | { |
8128 | hasColon = (*argptr == ':'); | |
8129 | argptr++; | |
8130 | } | |
c906108c SS |
8131 | |
8132 | if (hasColon) | |
c5aa993b | 8133 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8134 | else |
c5aa993b | 8135 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8136 | } |
8137 | ||
8138 | if (badInput) | |
a3f17187 | 8139 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8140 | else |
db107f19 | 8141 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8142 | } |
8143 | ||
4a64f543 MS |
8144 | /* Return non-zero if EXP is verified as constant. Returned zero |
8145 | means EXP is variable. Also the constant detection may fail for | |
8146 | some constant expressions and in such case still falsely return | |
8147 | zero. */ | |
65d79d4b SDJ |
8148 | static int |
8149 | watchpoint_exp_is_const (const struct expression *exp) | |
8150 | { | |
8151 | int i = exp->nelts; | |
8152 | ||
8153 | while (i > 0) | |
8154 | { | |
8155 | int oplenp, argsp; | |
8156 | ||
8157 | /* We are only interested in the descriptor of each element. */ | |
8158 | operator_length (exp, i, &oplenp, &argsp); | |
8159 | i -= oplenp; | |
8160 | ||
8161 | switch (exp->elts[i].opcode) | |
8162 | { | |
8163 | case BINOP_ADD: | |
8164 | case BINOP_SUB: | |
8165 | case BINOP_MUL: | |
8166 | case BINOP_DIV: | |
8167 | case BINOP_REM: | |
8168 | case BINOP_MOD: | |
8169 | case BINOP_LSH: | |
8170 | case BINOP_RSH: | |
8171 | case BINOP_LOGICAL_AND: | |
8172 | case BINOP_LOGICAL_OR: | |
8173 | case BINOP_BITWISE_AND: | |
8174 | case BINOP_BITWISE_IOR: | |
8175 | case BINOP_BITWISE_XOR: | |
8176 | case BINOP_EQUAL: | |
8177 | case BINOP_NOTEQUAL: | |
8178 | case BINOP_LESS: | |
8179 | case BINOP_GTR: | |
8180 | case BINOP_LEQ: | |
8181 | case BINOP_GEQ: | |
8182 | case BINOP_REPEAT: | |
8183 | case BINOP_COMMA: | |
8184 | case BINOP_EXP: | |
8185 | case BINOP_MIN: | |
8186 | case BINOP_MAX: | |
8187 | case BINOP_INTDIV: | |
8188 | case BINOP_CONCAT: | |
8189 | case BINOP_IN: | |
8190 | case BINOP_RANGE: | |
8191 | case TERNOP_COND: | |
8192 | case TERNOP_SLICE: | |
8193 | case TERNOP_SLICE_COUNT: | |
8194 | ||
8195 | case OP_LONG: | |
8196 | case OP_DOUBLE: | |
8197 | case OP_DECFLOAT: | |
8198 | case OP_LAST: | |
8199 | case OP_COMPLEX: | |
8200 | case OP_STRING: | |
8201 | case OP_BITSTRING: | |
8202 | case OP_ARRAY: | |
8203 | case OP_TYPE: | |
8204 | case OP_NAME: | |
8205 | case OP_OBJC_NSSTRING: | |
8206 | ||
8207 | case UNOP_NEG: | |
8208 | case UNOP_LOGICAL_NOT: | |
8209 | case UNOP_COMPLEMENT: | |
8210 | case UNOP_ADDR: | |
8211 | case UNOP_HIGH: | |
4a64f543 MS |
8212 | /* Unary, binary and ternary operators: We have to check |
8213 | their operands. If they are constant, then so is the | |
8214 | result of that operation. For instance, if A and B are | |
8215 | determined to be constants, then so is "A + B". | |
8216 | ||
8217 | UNOP_IND is one exception to the rule above, because the | |
8218 | value of *ADDR is not necessarily a constant, even when | |
8219 | ADDR is. */ | |
65d79d4b SDJ |
8220 | break; |
8221 | ||
8222 | case OP_VAR_VALUE: | |
8223 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8224 | |
65d79d4b | 8225 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8226 | possible that a buggy compiler could mark a variable as |
8227 | constant even when it is not, and TYPE_CONST would return | |
8228 | true in this case, while SYMBOL_CLASS wouldn't. | |
8229 | ||
8230 | We also have to check for function symbols because they | |
8231 | are always constant. */ | |
65d79d4b SDJ |
8232 | { |
8233 | struct symbol *s = exp->elts[i + 2].symbol; | |
8234 | ||
8235 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8236 | && SYMBOL_CLASS (s) != LOC_CONST | |
8237 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8238 | return 0; | |
8239 | break; | |
8240 | } | |
8241 | ||
8242 | /* The default action is to return 0 because we are using | |
8243 | the optimistic approach here: If we don't know something, | |
8244 | then it is not a constant. */ | |
8245 | default: | |
8246 | return 0; | |
8247 | } | |
8248 | } | |
8249 | ||
8250 | return 1; | |
8251 | } | |
8252 | ||
77b06cd7 TJB |
8253 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8254 | ||
8255 | static int | |
8256 | insert_watchpoint (struct bp_location *bl) | |
8257 | { | |
e09342b5 TJB |
8258 | int length = bl->owner->exact? 1 : bl->length; |
8259 | ||
8260 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
8261 | bl->owner->cond_exp); | |
77b06cd7 TJB |
8262 | } |
8263 | ||
8264 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8265 | ||
8266 | static int | |
8267 | remove_watchpoint (struct bp_location *bl) | |
8268 | { | |
e09342b5 TJB |
8269 | int length = bl->owner->exact? 1 : bl->length; |
8270 | ||
8271 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
8272 | bl->owner->cond_exp); | |
8273 | } | |
8274 | ||
8275 | /* Implement the "resources_needed" breakpoint_ops method for | |
8276 | hardware watchpoints. */ | |
8277 | ||
8278 | static int | |
8279 | resources_needed_watchpoint (const struct bp_location *bl) | |
8280 | { | |
90e4670f | 8281 | int length = bl->owner->exact? 1 : bl->length; |
e09342b5 | 8282 | |
90e4670f | 8283 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
77b06cd7 TJB |
8284 | } |
8285 | ||
8286 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ | |
8287 | ||
8288 | static struct breakpoint_ops watchpoint_breakpoint_ops = | |
8289 | { | |
8290 | insert_watchpoint, | |
8291 | remove_watchpoint, | |
8292 | NULL, /* breakpoint_hit */ | |
e09342b5 | 8293 | resources_needed_watchpoint, |
77b06cd7 TJB |
8294 | NULL, /* print_it */ |
8295 | NULL, /* print_one */ | |
8296 | NULL, /* print_mention */ | |
8297 | NULL /* print_recreate */ | |
8298 | }; | |
8299 | ||
53a5351d JM |
8300 | /* accessflag: hw_write: watch write, |
8301 | hw_read: watch read, | |
8302 | hw_access: watch access (read or write) */ | |
c906108c | 8303 | static void |
84f4c1fe PM |
8304 | watch_command_1 (char *arg, int accessflag, int from_tty, |
8305 | int just_location, int internal) | |
c906108c | 8306 | { |
d983da9c | 8307 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 8308 | struct expression *exp; |
60e1c644 | 8309 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 8310 | struct value *val, *mark, *result; |
c906108c | 8311 | struct frame_info *frame; |
c906108c SS |
8312 | char *exp_start = NULL; |
8313 | char *exp_end = NULL; | |
37e4754d | 8314 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
8315 | int toklen; |
8316 | char *cond_start = NULL; | |
8317 | char *cond_end = NULL; | |
c906108c SS |
8318 | int i, other_type_used, target_resources_ok = 0; |
8319 | enum bptype bp_type; | |
e09342b5 | 8320 | int reg_cnt = 0; |
37e4754d | 8321 | int thread = -1; |
0cf6dd15 | 8322 | int pc = 0; |
c906108c | 8323 | |
37e4754d LM |
8324 | /* Make sure that we actually have parameters to parse. */ |
8325 | if (arg != NULL && arg[0] != '\0') | |
8326 | { | |
8327 | toklen = strlen (arg); /* Size of argument list. */ | |
8328 | ||
8329 | /* Points tok to the end of the argument list. */ | |
8330 | tok = arg + toklen - 1; | |
8331 | ||
4a64f543 MS |
8332 | /* Go backwards in the parameters list. Skip the last |
8333 | parameter. If we're expecting a 'thread <thread_num>' | |
8334 | parameter, this should be the thread identifier. */ | |
37e4754d LM |
8335 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8336 | tok--; | |
8337 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8338 | tok--; | |
8339 | ||
8340 | /* Points end_tok to the beginning of the last token. */ | |
8341 | id_tok_start = tok + 1; | |
8342 | ||
4a64f543 MS |
8343 | /* Go backwards in the parameters list. Skip one more |
8344 | parameter. If we're expecting a 'thread <thread_num>' | |
8345 | parameter, we should reach a "thread" token. */ | |
37e4754d LM |
8346 | while (tok > arg && (*tok == ' ' || *tok == '\t')) |
8347 | tok--; | |
8348 | ||
8349 | end_tok = tok; | |
8350 | ||
8351 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8352 | tok--; | |
8353 | ||
8354 | /* Move the pointer forward to skip the whitespace and | |
8355 | calculate the length of the token. */ | |
8356 | tok++; | |
8357 | toklen = end_tok - tok; | |
8358 | ||
8359 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8360 | { | |
8361 | /* At this point we've found a "thread" token, which means | |
8362 | the user is trying to set a watchpoint that triggers | |
8363 | only in a specific thread. */ | |
8364 | char *endp; | |
8365 | ||
8366 | /* Extract the thread ID from the next token. */ | |
8367 | thread = strtol (id_tok_start, &endp, 0); | |
8368 | ||
8369 | /* Check if the user provided a valid numeric value for the | |
8370 | thread ID. */ | |
8371 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
8372 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
8373 | ||
8374 | /* Check if the thread actually exists. */ | |
8375 | if (!valid_thread_id (thread)) | |
8376 | error (_("Unknown thread %d."), thread); | |
8377 | ||
8378 | /* Truncate the string and get rid of the thread <thread_num> | |
8379 | parameter before the parameter list is parsed by the | |
8380 | evaluate_expression() function. */ | |
8381 | *tok = '\0'; | |
8382 | } | |
8383 | } | |
8384 | ||
8385 | /* Parse the rest of the arguments. */ | |
c906108c SS |
8386 | innermost_block = NULL; |
8387 | exp_start = arg; | |
8388 | exp = parse_exp_1 (&arg, 0, 0); | |
8389 | exp_end = arg; | |
fa8a61dc TT |
8390 | /* Remove trailing whitespace from the expression before saving it. |
8391 | This makes the eventual display of the expression string a bit | |
8392 | prettier. */ | |
8393 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
8394 | --exp_end; | |
8395 | ||
65d79d4b SDJ |
8396 | /* Checking if the expression is not constant. */ |
8397 | if (watchpoint_exp_is_const (exp)) | |
8398 | { | |
8399 | int len; | |
8400 | ||
8401 | len = exp_end - exp_start; | |
8402 | while (len > 0 && isspace (exp_start[len - 1])) | |
8403 | len--; | |
8404 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
8405 | } | |
8406 | ||
c906108c SS |
8407 | exp_valid_block = innermost_block; |
8408 | mark = value_mark (); | |
a1442452 | 8409 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
8410 | |
8411 | if (just_location) | |
8412 | { | |
8413 | exp_valid_block = NULL; | |
a1442452 | 8414 | val = value_addr (result); |
06a64a0b TT |
8415 | release_value (val); |
8416 | value_free_to_mark (mark); | |
8417 | } | |
8418 | else if (val != NULL) | |
fa4727a6 | 8419 | release_value (val); |
c906108c SS |
8420 | |
8421 | tok = arg; | |
8422 | while (*tok == ' ' || *tok == '\t') | |
8423 | tok++; | |
8424 | end_tok = tok; | |
8425 | ||
8426 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
8427 | end_tok++; | |
8428 | ||
8429 | toklen = end_tok - tok; | |
8430 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8431 | { | |
2d134ed3 PA |
8432 | struct expression *cond; |
8433 | ||
60e1c644 | 8434 | innermost_block = NULL; |
c906108c SS |
8435 | tok = cond_start = end_tok + 1; |
8436 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
8437 | |
8438 | /* The watchpoint expression may not be local, but the condition | |
8439 | may still be. E.g.: `watch global if local > 0'. */ | |
8440 | cond_exp_valid_block = innermost_block; | |
8441 | ||
2d134ed3 | 8442 | xfree (cond); |
c906108c SS |
8443 | cond_end = tok; |
8444 | } | |
8445 | if (*tok) | |
8a3fe4f8 | 8446 | error (_("Junk at end of command.")); |
c906108c | 8447 | |
53a5351d | 8448 | if (accessflag == hw_read) |
c5aa993b | 8449 | bp_type = bp_read_watchpoint; |
53a5351d | 8450 | else if (accessflag == hw_access) |
c5aa993b JM |
8451 | bp_type = bp_access_watchpoint; |
8452 | else | |
8453 | bp_type = bp_hardware_watchpoint; | |
c906108c | 8454 | |
e09342b5 TJB |
8455 | reg_cnt = can_use_hardware_watchpoint (val, target_exact_watchpoints); |
8456 | if (reg_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 8457 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
e09342b5 | 8458 | if (reg_cnt != 0) |
c5aa993b JM |
8459 | { |
8460 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 8461 | target_resources_ok = |
e09342b5 | 8462 | target_can_use_hardware_watchpoint (bp_type, i + reg_cnt, |
53a5351d | 8463 | other_type_used); |
c5aa993b | 8464 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8465 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 8466 | |
c5aa993b | 8467 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
3e43a32a MS |
8468 | error (_("Target can only support one kind " |
8469 | "of HW watchpoint at a time.")); | |
c5aa993b | 8470 | } |
c906108c | 8471 | |
4a64f543 MS |
8472 | /* Change the type of breakpoint to an ordinary watchpoint if a |
8473 | hardware watchpoint could not be set. */ | |
e09342b5 | 8474 | if (!reg_cnt || target_resources_ok <= 0) |
4d28f7a8 KB |
8475 | bp_type = bp_watchpoint; |
8476 | ||
d983da9c | 8477 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
8478 | |
8479 | /* If the expression is "local", then set up a "watchpoint scope" | |
8480 | breakpoint at the point where we've left the scope of the watchpoint | |
8481 | expression. Create the scope breakpoint before the watchpoint, so | |
8482 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 8483 | if (exp_valid_block && frame) |
d983da9c | 8484 | { |
edb3359d DJ |
8485 | if (frame_id_p (frame_unwind_caller_id (frame))) |
8486 | { | |
8487 | scope_breakpoint | |
a6d9a66e UW |
8488 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
8489 | frame_unwind_caller_pc (frame), | |
edb3359d | 8490 | bp_watchpoint_scope); |
d983da9c | 8491 | |
edb3359d | 8492 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 8493 | |
edb3359d DJ |
8494 | /* Automatically delete the breakpoint when it hits. */ |
8495 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 8496 | |
edb3359d DJ |
8497 | /* Only break in the proper frame (help with recursion). */ |
8498 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 8499 | |
edb3359d | 8500 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
8501 | scope_breakpoint->loc->gdbarch |
8502 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
8503 | scope_breakpoint->loc->requested_address |
8504 | = frame_unwind_caller_pc (frame); | |
8505 | scope_breakpoint->loc->address | |
a6d9a66e UW |
8506 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
8507 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
8508 | scope_breakpoint->type); |
8509 | } | |
d983da9c DJ |
8510 | } |
8511 | ||
c906108c | 8512 | /* Now set up the breakpoint. */ |
2d134ed3 | 8513 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
84f4c1fe | 8514 | set_breakpoint_number (internal, b); |
37e4754d | 8515 | b->thread = thread; |
b5de0fa7 | 8516 | b->disposition = disp_donttouch; |
c906108c SS |
8517 | b->exp = exp; |
8518 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 8519 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
8520 | if (just_location) |
8521 | { | |
8522 | struct type *t = value_type (val); | |
8523 | CORE_ADDR addr = value_as_address (val); | |
8524 | char *name; | |
8525 | ||
8526 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
8527 | name = type_to_string (t); | |
8528 | ||
d63d0675 JK |
8529 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
8530 | core_addr_to_string (addr)); | |
06a64a0b TT |
8531 | xfree (name); |
8532 | ||
d63d0675 JK |
8533 | b->exp_string = xstrprintf ("-location: %.*s", |
8534 | (int) (exp_end - exp_start), exp_start); | |
8535 | ||
06a64a0b TT |
8536 | /* The above expression is in C. */ |
8537 | b->language = language_c; | |
8538 | } | |
8539 | else | |
8540 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
c906108c | 8541 | b->val = val; |
fa4727a6 | 8542 | b->val_valid = 1; |
77b06cd7 TJB |
8543 | b->ops = &watchpoint_breakpoint_ops; |
8544 | ||
e09342b5 TJB |
8545 | /* Use an exact watchpoint when there's only one memory region to be |
8546 | watched, and only one debug register is needed to watch it. */ | |
8547 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
8548 | ||
c906108c SS |
8549 | if (cond_start) |
8550 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
8551 | else | |
8552 | b->cond_string = 0; | |
c5aa993b | 8553 | |
c906108c | 8554 | if (frame) |
f6bc2008 PA |
8555 | { |
8556 | b->watchpoint_frame = get_frame_id (frame); | |
8557 | b->watchpoint_thread = inferior_ptid; | |
8558 | } | |
c906108c | 8559 | else |
f6bc2008 PA |
8560 | { |
8561 | b->watchpoint_frame = null_frame_id; | |
8562 | b->watchpoint_thread = null_ptid; | |
8563 | } | |
c906108c | 8564 | |
d983da9c | 8565 | if (scope_breakpoint != NULL) |
c906108c | 8566 | { |
d983da9c DJ |
8567 | /* The scope breakpoint is related to the watchpoint. We will |
8568 | need to act on them together. */ | |
8569 | b->related_breakpoint = scope_breakpoint; | |
8570 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 8571 | } |
d983da9c | 8572 | |
06a64a0b TT |
8573 | if (!just_location) |
8574 | value_free_to_mark (mark); | |
2d134ed3 PA |
8575 | |
8576 | /* Finally update the new watchpoint. This creates the locations | |
8577 | that should be inserted. */ | |
8578 | update_watchpoint (b, 1); | |
84f4c1fe PM |
8579 | if (internal) |
8580 | /* Do not mention breakpoints with a negative number, but do | |
8581 | notify observers. */ | |
8582 | observer_notify_breakpoint_created (b->number); | |
8583 | else | |
8584 | mention (b); | |
b60e7edf | 8585 | update_global_location_list (1); |
c906108c SS |
8586 | } |
8587 | ||
e09342b5 TJB |
8588 | /* Return count of debug registers needed to watch the given expression. |
8589 | If EXACT_WATCHPOINTS is 1, then consider that only the address of | |
8590 | the start of the watched region will be monitored (i.e., all accesses | |
8591 | will be aligned). This uses less debug registers on some targets. | |
8592 | ||
8593 | If the watchpoint cannot be handled in hardware return zero. */ | |
c906108c | 8594 | |
c906108c | 8595 | static int |
e09342b5 | 8596 | can_use_hardware_watchpoint (struct value *v, int exact_watchpoints) |
c906108c SS |
8597 | { |
8598 | int found_memory_cnt = 0; | |
2e70b7b9 | 8599 | struct value *head = v; |
c906108c SS |
8600 | |
8601 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 8602 | if (!can_use_hw_watchpoints) |
c906108c | 8603 | return 0; |
c5aa993b | 8604 | |
5c44784c JM |
8605 | /* Make sure that the value of the expression depends only upon |
8606 | memory contents, and values computed from them within GDB. If we | |
8607 | find any register references or function calls, we can't use a | |
8608 | hardware watchpoint. | |
8609 | ||
8610 | The idea here is that evaluating an expression generates a series | |
8611 | of values, one holding the value of every subexpression. (The | |
8612 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
8613 | a*b+c.) GDB's values hold almost enough information to establish | |
8614 | the criteria given above --- they identify memory lvalues, | |
8615 | register lvalues, computed values, etcetera. So we can evaluate | |
8616 | the expression, and then scan the chain of values that leaves | |
8617 | behind to decide whether we can detect any possible change to the | |
8618 | expression's final value using only hardware watchpoints. | |
8619 | ||
8620 | However, I don't think that the values returned by inferior | |
8621 | function calls are special in any way. So this function may not | |
8622 | notice that an expression involving an inferior function call | |
8623 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 8624 | for (; v; v = value_next (v)) |
c906108c | 8625 | { |
5c44784c | 8626 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 8627 | { |
8464be76 DJ |
8628 | if (v != head && value_lazy (v)) |
8629 | /* A lazy memory lvalue in the chain is one that GDB never | |
8630 | needed to fetch; we either just used its address (e.g., | |
8631 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
8632 | in `a,b'). This doesn't apply to HEAD; if that is | |
8633 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 8634 | ; |
53a5351d | 8635 | else |
5c44784c JM |
8636 | { |
8637 | /* Ahh, memory we actually used! Check if we can cover | |
8638 | it with hardware watchpoints. */ | |
df407dfe | 8639 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
8640 | |
8641 | /* We only watch structs and arrays if user asked for it | |
8642 | explicitly, never if they just happen to appear in a | |
8643 | middle of some value chain. */ | |
8644 | if (v == head | |
8645 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
8646 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
8647 | { | |
42ae5230 | 8648 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
8649 | int len; |
8650 | int num_regs; | |
8651 | ||
8652 | len = (exact_watchpoints | |
8653 | && is_scalar_type_recursive (vtype))? | |
8654 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 8655 | |
e09342b5 TJB |
8656 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
8657 | if (!num_regs) | |
2e70b7b9 MS |
8658 | return 0; |
8659 | else | |
e09342b5 | 8660 | found_memory_cnt += num_regs; |
2e70b7b9 | 8661 | } |
5c44784c | 8662 | } |
c5aa993b | 8663 | } |
5086187c AC |
8664 | else if (VALUE_LVAL (v) != not_lval |
8665 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 8666 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 8667 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 8668 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
8669 | } |
8670 | ||
8671 | /* The expression itself looks suitable for using a hardware | |
8672 | watchpoint, but give the target machine a chance to reject it. */ | |
8673 | return found_memory_cnt; | |
8674 | } | |
8675 | ||
8b93c638 | 8676 | void |
84f4c1fe | 8677 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8678 | { |
84f4c1fe | 8679 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
8680 | } |
8681 | ||
8682 | /* A helper function that looks for an argument at the start of a | |
8683 | string. The argument must also either be at the end of the string, | |
8684 | or be followed by whitespace. Returns 1 if it finds the argument, | |
8685 | 0 otherwise. If the argument is found, it updates *STR. */ | |
8686 | ||
8687 | static int | |
8688 | check_for_argument (char **str, char *arg, int arg_len) | |
8689 | { | |
8690 | if (strncmp (*str, arg, arg_len) == 0 | |
8691 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
8692 | { | |
8693 | *str += arg_len; | |
8694 | return 1; | |
8695 | } | |
8696 | return 0; | |
8697 | } | |
8698 | ||
8699 | /* A helper function that looks for the "-location" argument and then | |
8700 | calls watch_command_1. */ | |
8701 | ||
8702 | static void | |
8703 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
8704 | { | |
8705 | int just_location = 0; | |
8706 | ||
8707 | if (arg | |
8708 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
8709 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
8710 | { | |
8711 | ep_skip_leading_whitespace (&arg); | |
8712 | just_location = 1; | |
8713 | } | |
8714 | ||
84f4c1fe | 8715 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 8716 | } |
8926118c | 8717 | |
c5aa993b | 8718 | static void |
fba45db2 | 8719 | watch_command (char *arg, int from_tty) |
c906108c | 8720 | { |
06a64a0b | 8721 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
8722 | } |
8723 | ||
8b93c638 | 8724 | void |
84f4c1fe | 8725 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8726 | { |
84f4c1fe | 8727 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 8728 | } |
8926118c | 8729 | |
c5aa993b | 8730 | static void |
fba45db2 | 8731 | rwatch_command (char *arg, int from_tty) |
c906108c | 8732 | { |
06a64a0b | 8733 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
8734 | } |
8735 | ||
8b93c638 | 8736 | void |
84f4c1fe | 8737 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 8738 | { |
84f4c1fe | 8739 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 8740 | } |
8926118c | 8741 | |
c5aa993b | 8742 | static void |
fba45db2 | 8743 | awatch_command (char *arg, int from_tty) |
c906108c | 8744 | { |
06a64a0b | 8745 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 8746 | } |
c906108c | 8747 | \f |
c5aa993b | 8748 | |
43ff13b4 | 8749 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8750 | because it uses the mechanisms of breakpoints. */ |
8751 | ||
bfec99b2 PA |
8752 | struct until_break_command_continuation_args |
8753 | { | |
8754 | struct breakpoint *breakpoint; | |
8755 | struct breakpoint *breakpoint2; | |
186c406b | 8756 | int thread_num; |
bfec99b2 PA |
8757 | }; |
8758 | ||
43ff13b4 | 8759 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 8760 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 8761 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 8762 | command. */ |
c2c6d25f | 8763 | static void |
604ead4a | 8764 | until_break_command_continuation (void *arg) |
43ff13b4 | 8765 | { |
bfec99b2 PA |
8766 | struct until_break_command_continuation_args *a = arg; |
8767 | ||
8768 | delete_breakpoint (a->breakpoint); | |
8769 | if (a->breakpoint2) | |
8770 | delete_breakpoint (a->breakpoint2); | |
186c406b | 8771 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
8772 | } |
8773 | ||
c906108c | 8774 | void |
ae66c1fc | 8775 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8776 | { |
8777 | struct symtabs_and_lines sals; | |
8778 | struct symtab_and_line sal; | |
206415a3 | 8779 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8780 | struct breakpoint *breakpoint; |
f107f563 | 8781 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 8782 | struct cleanup *old_chain; |
186c406b TT |
8783 | int thread; |
8784 | struct thread_info *tp; | |
c906108c SS |
8785 | |
8786 | clear_proceed_status (); | |
8787 | ||
8788 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 8789 | this function. */ |
c5aa993b | 8790 | |
c906108c SS |
8791 | if (default_breakpoint_valid) |
8792 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 8793 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 8794 | else |
53a5351d | 8795 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 8796 | 0, (char ***) NULL, NULL); |
c5aa993b | 8797 | |
c906108c | 8798 | if (sals.nelts != 1) |
8a3fe4f8 | 8799 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8800 | |
c906108c | 8801 | sal = sals.sals[0]; |
4a64f543 | 8802 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 8803 | |
c906108c | 8804 | if (*arg) |
8a3fe4f8 | 8805 | error (_("Junk at end of arguments.")); |
c5aa993b | 8806 | |
c906108c | 8807 | resolve_sal_pc (&sal); |
c5aa993b | 8808 | |
ae66c1fc EZ |
8809 | if (anywhere) |
8810 | /* If the user told us to continue until a specified location, | |
8811 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8812 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8813 | null_frame_id, bp_until); | |
ae66c1fc | 8814 | else |
4a64f543 MS |
8815 | /* Otherwise, specify the selected frame, because we want to stop |
8816 | only at the very same frame. */ | |
a6d9a66e UW |
8817 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8818 | get_stack_frame_id (frame), | |
ae66c1fc | 8819 | bp_until); |
c5aa993b | 8820 | |
f107f563 | 8821 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8822 | |
186c406b TT |
8823 | tp = inferior_thread (); |
8824 | thread = tp->num; | |
8825 | ||
ae66c1fc EZ |
8826 | /* Keep within the current frame, or in frames called by the current |
8827 | one. */ | |
edb3359d DJ |
8828 | |
8829 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8830 | { |
edb3359d DJ |
8831 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8832 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8833 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8834 | sal, | |
edb3359d | 8835 | frame_unwind_caller_id (frame), |
f107f563 VP |
8836 | bp_until); |
8837 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
8838 | |
8839 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
8840 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 8841 | } |
c5aa993b | 8842 | |
c906108c | 8843 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 8844 | |
4a64f543 MS |
8845 | /* If we are running asynchronously, and proceed call above has |
8846 | actually managed to start the target, arrange for breakpoints to | |
8847 | be deleted when the target stops. Otherwise, we're already | |
8848 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 8849 | |
8ea051c5 | 8850 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8851 | { |
bfec99b2 PA |
8852 | struct until_break_command_continuation_args *args; |
8853 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8854 | |
bfec99b2 PA |
8855 | args->breakpoint = breakpoint; |
8856 | args->breakpoint2 = breakpoint2; | |
186c406b | 8857 | args->thread_num = thread; |
f107f563 VP |
8858 | |
8859 | discard_cleanups (old_chain); | |
95e54da7 PA |
8860 | add_continuation (inferior_thread (), |
8861 | until_break_command_continuation, args, | |
604ead4a | 8862 | xfree); |
f107f563 VP |
8863 | } |
8864 | else | |
c5aa993b | 8865 | do_cleanups (old_chain); |
c906108c | 8866 | } |
ae66c1fc | 8867 | |
c906108c | 8868 | static void |
fba45db2 | 8869 | ep_skip_leading_whitespace (char **s) |
c906108c | 8870 | { |
c5aa993b JM |
8871 | if ((s == NULL) || (*s == NULL)) |
8872 | return; | |
8873 | while (isspace (**s)) | |
8874 | *s += 1; | |
c906108c | 8875 | } |
c5aa993b | 8876 | |
c906108c SS |
8877 | /* This function attempts to parse an optional "if <cond>" clause |
8878 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8879 | |
c906108c SS |
8880 | Else, it returns a pointer to the condition string. (It does not |
8881 | attempt to evaluate the string against a particular block.) And, | |
8882 | it updates arg to point to the first character following the parsed | |
4a64f543 | 8883 | if clause in the arg string. */ |
53a5351d | 8884 | |
c906108c | 8885 | static char * |
fba45db2 | 8886 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8887 | { |
c5aa993b JM |
8888 | char *cond_string; |
8889 | ||
8890 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8891 | return NULL; |
c5aa993b | 8892 | |
4a64f543 | 8893 | /* Skip the "if" keyword. */ |
c906108c | 8894 | (*arg) += 2; |
c5aa993b | 8895 | |
c906108c | 8896 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 8897 | condition string. */ |
c906108c SS |
8898 | ep_skip_leading_whitespace (arg); |
8899 | cond_string = *arg; | |
c5aa993b | 8900 | |
4a64f543 MS |
8901 | /* Assume that the condition occupies the remainder of the arg |
8902 | string. */ | |
c906108c | 8903 | (*arg) += strlen (cond_string); |
c5aa993b | 8904 | |
c906108c SS |
8905 | return cond_string; |
8906 | } | |
c5aa993b | 8907 | |
c906108c SS |
8908 | /* Commands to deal with catching events, such as signals, exceptions, |
8909 | process start/exit, etc. */ | |
c5aa993b JM |
8910 | |
8911 | typedef enum | |
8912 | { | |
44feb3ce TT |
8913 | catch_fork_temporary, catch_vfork_temporary, |
8914 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8915 | } |
8916 | catch_fork_kind; | |
8917 | ||
c906108c | 8918 | static void |
cc59ec59 MS |
8919 | catch_fork_command_1 (char *arg, int from_tty, |
8920 | struct cmd_list_element *command) | |
c906108c | 8921 | { |
a6d9a66e | 8922 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8923 | char *cond_string = NULL; |
44feb3ce TT |
8924 | catch_fork_kind fork_kind; |
8925 | int tempflag; | |
8926 | ||
8927 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8928 | tempflag = (fork_kind == catch_fork_temporary | |
8929 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8930 | |
44feb3ce TT |
8931 | if (!arg) |
8932 | arg = ""; | |
c906108c | 8933 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8934 | |
c906108c | 8935 | /* The allowed syntax is: |
c5aa993b JM |
8936 | catch [v]fork |
8937 | catch [v]fork if <cond> | |
8938 | ||
4a64f543 | 8939 | First, check if there's an if clause. */ |
c906108c | 8940 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 8941 | |
c906108c | 8942 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 8943 | error (_("Junk at end of arguments.")); |
c5aa993b | 8944 | |
c906108c | 8945 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 8946 | and enable reporting of such events. */ |
c5aa993b JM |
8947 | switch (fork_kind) |
8948 | { | |
44feb3ce TT |
8949 | case catch_fork_temporary: |
8950 | case catch_fork_permanent: | |
a6d9a66e | 8951 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8952 | &catch_fork_breakpoint_ops); |
c906108c | 8953 | break; |
44feb3ce TT |
8954 | case catch_vfork_temporary: |
8955 | case catch_vfork_permanent: | |
a6d9a66e | 8956 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8957 | &catch_vfork_breakpoint_ops); |
c906108c | 8958 | break; |
c5aa993b | 8959 | default: |
8a3fe4f8 | 8960 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 8961 | break; |
c5aa993b | 8962 | } |
c906108c SS |
8963 | } |
8964 | ||
8965 | static void | |
cc59ec59 MS |
8966 | catch_exec_command_1 (char *arg, int from_tty, |
8967 | struct cmd_list_element *command) | |
c906108c | 8968 | { |
a6d9a66e | 8969 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8970 | int tempflag; |
c5aa993b | 8971 | char *cond_string = NULL; |
c906108c | 8972 | |
44feb3ce TT |
8973 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8974 | ||
8975 | if (!arg) | |
8976 | arg = ""; | |
c906108c SS |
8977 | ep_skip_leading_whitespace (&arg); |
8978 | ||
8979 | /* The allowed syntax is: | |
c5aa993b JM |
8980 | catch exec |
8981 | catch exec if <cond> | |
c906108c | 8982 | |
4a64f543 | 8983 | First, check if there's an if clause. */ |
c906108c SS |
8984 | cond_string = ep_parse_optional_if_clause (&arg); |
8985 | ||
8986 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8987 | error (_("Junk at end of arguments.")); |
c906108c SS |
8988 | |
8989 | /* If this target supports it, create an exec catchpoint | |
4a64f543 | 8990 | and enable reporting of such events. */ |
a6d9a66e UW |
8991 | create_catchpoint (gdbarch, tempflag, cond_string, |
8992 | &catch_exec_breakpoint_ops); | |
c906108c | 8993 | } |
c5aa993b | 8994 | |
3086aeae DJ |
8995 | static enum print_stop_action |
8996 | print_exception_catchpoint (struct breakpoint *b) | |
8997 | { | |
ade92717 | 8998 | int bp_temp, bp_throw; |
3086aeae | 8999 | |
ade92717 | 9000 | annotate_catchpoint (b->number); |
3086aeae | 9001 | |
ade92717 AR |
9002 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9003 | if (b->loc->address != b->loc->requested_address) | |
9004 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9005 | b->loc->address, | |
9006 | b->number, 1); | |
df2b6d2d | 9007 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9008 | ui_out_text (uiout, |
9009 | bp_temp ? "Temporary catchpoint " | |
9010 | : "Catchpoint "); | |
9011 | if (!ui_out_is_mi_like_p (uiout)) | |
9012 | ui_out_field_int (uiout, "bkptno", b->number); | |
9013 | ui_out_text (uiout, | |
c0b37c48 AR |
9014 | bp_throw ? " (exception thrown), " |
9015 | : " (exception caught), "); | |
ade92717 AR |
9016 | if (ui_out_is_mi_like_p (uiout)) |
9017 | { | |
9018 | ui_out_field_string (uiout, "reason", | |
9019 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9020 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9021 | ui_out_field_int (uiout, "bkptno", b->number); | |
9022 | } | |
3086aeae DJ |
9023 | return PRINT_SRC_AND_LOC; |
9024 | } | |
9025 | ||
9026 | static void | |
cc59ec59 MS |
9027 | print_one_exception_catchpoint (struct breakpoint *b, |
9028 | struct bp_location **last_loc) | |
3086aeae | 9029 | { |
79a45b7d | 9030 | struct value_print_options opts; |
cc59ec59 | 9031 | |
79a45b7d TT |
9032 | get_user_print_options (&opts); |
9033 | if (opts.addressprint) | |
3086aeae DJ |
9034 | { |
9035 | annotate_field (4); | |
604133b5 AR |
9036 | if (b->loc == NULL || b->loc->shlib_disabled) |
9037 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9038 | else | |
5af949e3 UW |
9039 | ui_out_field_core_addr (uiout, "addr", |
9040 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9041 | } |
9042 | annotate_field (5); | |
604133b5 | 9043 | if (b->loc) |
a6d9a66e | 9044 | *last_loc = b->loc; |
3086aeae DJ |
9045 | if (strstr (b->addr_string, "throw") != NULL) |
9046 | ui_out_field_string (uiout, "what", "exception throw"); | |
9047 | else | |
9048 | ui_out_field_string (uiout, "what", "exception catch"); | |
9049 | } | |
9050 | ||
9051 | static void | |
9052 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9053 | { | |
ade92717 AR |
9054 | int bp_temp; |
9055 | int bp_throw; | |
9056 | ||
df2b6d2d | 9057 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9058 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9059 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9060 | : _("Catchpoint ")); | |
9061 | ui_out_field_int (uiout, "bkptno", b->number); | |
9062 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9063 | : _(" (catch)")); | |
3086aeae DJ |
9064 | } |
9065 | ||
6149aea9 PA |
9066 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9067 | catch catchpoints. */ | |
9068 | ||
9069 | static void | |
4a64f543 MS |
9070 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9071 | struct ui_file *fp) | |
6149aea9 PA |
9072 | { |
9073 | int bp_temp; | |
9074 | int bp_throw; | |
9075 | ||
9076 | bp_temp = b->disposition == disp_del; | |
9077 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9078 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9079 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
9080 | } | |
9081 | ||
3086aeae | 9082 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
9083 | NULL, /* insert */ |
9084 | NULL, /* remove */ | |
9085 | NULL, /* breakpoint_hit */ | |
e09342b5 | 9086 | NULL, /* resources_needed */ |
3086aeae DJ |
9087 | print_exception_catchpoint, |
9088 | print_one_exception_catchpoint, | |
6149aea9 PA |
9089 | print_mention_exception_catchpoint, |
9090 | print_recreate_exception_catchpoint | |
3086aeae DJ |
9091 | }; |
9092 | ||
9093 | static int | |
9094 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9095 | enum exception_event_kind ex_event, int from_tty) | |
9096 | { | |
604133b5 AR |
9097 | char *trigger_func_name; |
9098 | ||
3086aeae | 9099 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9100 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9101 | else |
604133b5 | 9102 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9103 | |
8cdf0e15 VP |
9104 | create_breakpoint (get_current_arch (), |
9105 | trigger_func_name, cond_string, -1, | |
9106 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9107 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9108 | 0, |
9109 | AUTO_BOOLEAN_TRUE /* pending */, | |
9110 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9111 | 1 /* enabled */, |
9112 | 0 /* internal */); | |
3086aeae | 9113 | |
3086aeae DJ |
9114 | return 1; |
9115 | } | |
9116 | ||
4a64f543 | 9117 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9118 | |
9119 | static void | |
fba45db2 KB |
9120 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9121 | int tempflag, int from_tty) | |
c906108c | 9122 | { |
c5aa993b | 9123 | char *cond_string = NULL; |
c5aa993b | 9124 | |
44feb3ce TT |
9125 | if (!arg) |
9126 | arg = ""; | |
c906108c | 9127 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 9128 | |
c906108c SS |
9129 | cond_string = ep_parse_optional_if_clause (&arg); |
9130 | ||
9131 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9132 | error (_("Junk at end of arguments.")); |
c906108c | 9133 | |
059fb39f PM |
9134 | if (ex_event != EX_EVENT_THROW |
9135 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9136 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9137 | |
3086aeae DJ |
9138 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9139 | return; | |
9140 | ||
8a3fe4f8 | 9141 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9142 | } |
9143 | ||
44feb3ce TT |
9144 | /* Implementation of "catch catch" command. */ |
9145 | ||
9146 | static void | |
9147 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9148 | { | |
9149 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9150 | |
44feb3ce TT |
9151 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9152 | } | |
9153 | ||
9154 | /* Implementation of "catch throw" command. */ | |
9155 | ||
9156 | static void | |
9157 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9158 | { | |
9159 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9160 | |
44feb3ce TT |
9161 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9162 | } | |
9163 | ||
f7f9143b JB |
9164 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
9165 | ||
9166 | static void | |
a6d9a66e UW |
9167 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
9168 | struct symtab_and_line sal, | |
f7f9143b JB |
9169 | char *addr_string, |
9170 | char *exp_string, | |
9171 | char *cond_string, | |
9172 | struct expression *cond, | |
9173 | struct breakpoint_ops *ops, | |
9174 | int tempflag, | |
9175 | int from_tty) | |
9176 | { | |
9177 | struct breakpoint *b; | |
9178 | ||
9179 | if (from_tty) | |
9180 | { | |
5af949e3 UW |
9181 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9182 | if (!loc_gdbarch) | |
9183 | loc_gdbarch = gdbarch; | |
9184 | ||
6c95b8df PA |
9185 | describe_other_breakpoints (loc_gdbarch, |
9186 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9187 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9188 | version for exception catchpoints, because two catchpoints | |
9189 | used for different exception names will use the same address. | |
9190 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9191 | unproductive. Besides, the warning phrasing is also a bit |
f7f9143b JB |
9192 | inapropriate, we should use the word catchpoint, and tell |
9193 | the user what type of catchpoint it is. The above is good | |
9194 | enough for now, though. */ | |
9195 | } | |
9196 | ||
a6d9a66e | 9197 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
9198 | set_breakpoint_count (breakpoint_count + 1); |
9199 | ||
9200 | b->enable_state = bp_enabled; | |
9201 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
9202 | b->number = breakpoint_count; | |
9203 | b->ignore_count = 0; | |
511a6cd4 | 9204 | b->loc->cond = cond; |
f7f9143b JB |
9205 | b->addr_string = addr_string; |
9206 | b->language = language_ada; | |
9207 | b->cond_string = cond_string; | |
9208 | b->exp_string = exp_string; | |
9209 | b->thread = -1; | |
9210 | b->ops = ops; | |
f7f9143b JB |
9211 | |
9212 | mention (b); | |
b60e7edf | 9213 | update_global_location_list (1); |
f7f9143b JB |
9214 | } |
9215 | ||
9216 | /* Implement the "catch exception" command. */ | |
9217 | ||
9218 | static void | |
44feb3ce TT |
9219 | catch_ada_exception_command (char *arg, int from_tty, |
9220 | struct cmd_list_element *command) | |
f7f9143b | 9221 | { |
a6d9a66e | 9222 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9223 | int tempflag; |
f7f9143b | 9224 | struct symtab_and_line sal; |
f7f9143b JB |
9225 | char *addr_string = NULL; |
9226 | char *exp_string = NULL; | |
9227 | char *cond_string = NULL; | |
9228 | struct expression *cond = NULL; | |
9229 | struct breakpoint_ops *ops = NULL; | |
9230 | ||
44feb3ce TT |
9231 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9232 | ||
9233 | if (!arg) | |
9234 | arg = ""; | |
f7f9143b JB |
9235 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
9236 | &cond_string, &cond, &ops); | |
a6d9a66e | 9237 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
9238 | cond_string, cond, ops, tempflag, |
9239 | from_tty); | |
9240 | } | |
9241 | ||
a96d9b2e SDJ |
9242 | /* Cleanup function for a syscall filter list. */ |
9243 | static void | |
9244 | clean_up_filters (void *arg) | |
9245 | { | |
9246 | VEC(int) *iter = *(VEC(int) **) arg; | |
9247 | VEC_free (int, iter); | |
9248 | } | |
9249 | ||
9250 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
9251 | filter list, or NULL if no filtering is required. */ | |
9252 | static VEC(int) * | |
9253 | catch_syscall_split_args (char *arg) | |
9254 | { | |
9255 | VEC(int) *result = NULL; | |
9256 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
9257 | ||
9258 | while (*arg != '\0') | |
9259 | { | |
9260 | int i, syscall_number; | |
9261 | char *endptr; | |
9262 | char cur_name[128]; | |
9263 | struct syscall s; | |
9264 | ||
9265 | /* Skip whitespace. */ | |
9266 | while (isspace (*arg)) | |
9267 | arg++; | |
9268 | ||
9269 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
9270 | cur_name[i] = arg[i]; | |
9271 | cur_name[i] = '\0'; | |
9272 | arg += i; | |
9273 | ||
9274 | /* Check if the user provided a syscall name or a number. */ | |
9275 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
9276 | if (*endptr == '\0') | |
bccd0dd2 | 9277 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
9278 | else |
9279 | { | |
9280 | /* We have a name. Let's check if it's valid and convert it | |
9281 | to a number. */ | |
9282 | get_syscall_by_name (cur_name, &s); | |
9283 | ||
9284 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
9285 | /* Here we have to issue an error instead of a warning, |
9286 | because GDB cannot do anything useful if there's no | |
9287 | syscall number to be caught. */ | |
a96d9b2e SDJ |
9288 | error (_("Unknown syscall name '%s'."), cur_name); |
9289 | } | |
9290 | ||
9291 | /* Ok, it's valid. */ | |
9292 | VEC_safe_push (int, result, s.number); | |
9293 | } | |
9294 | ||
9295 | discard_cleanups (cleanup); | |
9296 | return result; | |
9297 | } | |
9298 | ||
9299 | /* Implement the "catch syscall" command. */ | |
9300 | ||
9301 | static void | |
cc59ec59 MS |
9302 | catch_syscall_command_1 (char *arg, int from_tty, |
9303 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
9304 | { |
9305 | int tempflag; | |
9306 | VEC(int) *filter; | |
9307 | struct syscall s; | |
9308 | struct gdbarch *gdbarch = get_current_arch (); | |
9309 | ||
9310 | /* Checking if the feature if supported. */ | |
9311 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
9312 | error (_("The feature 'catch syscall' is not supported on \ | |
9313 | this architeture yet.")); | |
9314 | ||
9315 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
9316 | ||
9317 | ep_skip_leading_whitespace (&arg); | |
9318 | ||
9319 | /* We need to do this first "dummy" translation in order | |
9320 | to get the syscall XML file loaded or, most important, | |
9321 | to display a warning to the user if there's no XML file | |
9322 | for his/her architecture. */ | |
9323 | get_syscall_by_number (0, &s); | |
9324 | ||
9325 | /* The allowed syntax is: | |
9326 | catch syscall | |
9327 | catch syscall <name | number> [<name | number> ... <name | number>] | |
9328 | ||
9329 | Let's check if there's a syscall name. */ | |
9330 | ||
9331 | if (arg != NULL) | |
9332 | filter = catch_syscall_split_args (arg); | |
9333 | else | |
9334 | filter = NULL; | |
9335 | ||
9336 | create_syscall_event_catchpoint (tempflag, filter, | |
9337 | &catch_syscall_breakpoint_ops); | |
9338 | } | |
9339 | ||
f7f9143b JB |
9340 | /* Implement the "catch assert" command. */ |
9341 | ||
9342 | static void | |
3e43a32a MS |
9343 | catch_assert_command (char *arg, int from_tty, |
9344 | struct cmd_list_element *command) | |
f7f9143b | 9345 | { |
a6d9a66e | 9346 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9347 | int tempflag; |
f7f9143b JB |
9348 | struct symtab_and_line sal; |
9349 | char *addr_string = NULL; | |
9350 | struct breakpoint_ops *ops = NULL; | |
9351 | ||
44feb3ce TT |
9352 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9353 | ||
9354 | if (!arg) | |
9355 | arg = ""; | |
f7f9143b | 9356 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
9357 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
9358 | ops, tempflag, from_tty); | |
f7f9143b JB |
9359 | } |
9360 | ||
c906108c | 9361 | static void |
fba45db2 | 9362 | catch_command (char *arg, int from_tty) |
c906108c | 9363 | { |
44feb3ce | 9364 | error (_("Catch requires an event name.")); |
c906108c SS |
9365 | } |
9366 | \f | |
9367 | ||
9368 | static void | |
fba45db2 | 9369 | tcatch_command (char *arg, int from_tty) |
c906108c | 9370 | { |
44feb3ce | 9371 | error (_("Catch requires an event name.")); |
c906108c SS |
9372 | } |
9373 | ||
80f8a6eb | 9374 | /* Delete breakpoints by address or line. */ |
c906108c SS |
9375 | |
9376 | static void | |
fba45db2 | 9377 | clear_command (char *arg, int from_tty) |
c906108c | 9378 | { |
d6e956e5 VP |
9379 | struct breakpoint *b; |
9380 | VEC(breakpoint_p) *found = 0; | |
9381 | int ix; | |
c906108c SS |
9382 | int default_match; |
9383 | struct symtabs_and_lines sals; | |
9384 | struct symtab_and_line sal; | |
c906108c SS |
9385 | int i; |
9386 | ||
9387 | if (arg) | |
9388 | { | |
9389 | sals = decode_line_spec (arg, 1); | |
9390 | default_match = 0; | |
9391 | } | |
9392 | else | |
9393 | { | |
c5aa993b | 9394 | sals.sals = (struct symtab_and_line *) |
c906108c | 9395 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 9396 | make_cleanup (xfree, sals.sals); |
4a64f543 | 9397 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
9398 | sal.line = default_breakpoint_line; |
9399 | sal.symtab = default_breakpoint_symtab; | |
9400 | sal.pc = default_breakpoint_address; | |
6c95b8df | 9401 | sal.pspace = default_breakpoint_pspace; |
c906108c | 9402 | if (sal.symtab == 0) |
8a3fe4f8 | 9403 | error (_("No source file specified.")); |
c906108c SS |
9404 | |
9405 | sals.sals[0] = sal; | |
9406 | sals.nelts = 1; | |
9407 | ||
9408 | default_match = 1; | |
9409 | } | |
9410 | ||
4a64f543 MS |
9411 | /* We don't call resolve_sal_pc here. That's not as bad as it |
9412 | seems, because all existing breakpoints typically have both | |
9413 | file/line and pc set. So, if clear is given file/line, we can | |
9414 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
9415 | |
9416 | We only support clearing given the address explicitly | |
9417 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 9418 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 9419 | due to optimization, all in one block. |
4a64f543 MS |
9420 | |
9421 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
9422 | PC corresponding to the same file:line, the breakpoint won't |
9423 | be cleared. We probably can still clear the breakpoint, but | |
9424 | since the other PC value is never presented to user, user | |
9425 | can only find it by guessing, and it does not seem important | |
9426 | to support that. */ | |
9427 | ||
4a64f543 MS |
9428 | /* For each line spec given, delete bps which correspond to it. Do |
9429 | it in two passes, solely to preserve the current behavior that | |
9430 | from_tty is forced true if we delete more than one | |
9431 | breakpoint. */ | |
c906108c | 9432 | |
80f8a6eb | 9433 | found = NULL; |
c906108c SS |
9434 | for (i = 0; i < sals.nelts; i++) |
9435 | { | |
9436 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
9437 | If line given (pc == 0), clear all bpts on specified line. |
9438 | If defaulting, clear all bpts on default line | |
c906108c | 9439 | or at default pc. |
c5aa993b JM |
9440 | |
9441 | defaulting sal.pc != 0 tests to do | |
9442 | ||
9443 | 0 1 pc | |
9444 | 1 1 pc _and_ line | |
9445 | 0 0 line | |
9446 | 1 0 <can't happen> */ | |
c906108c SS |
9447 | |
9448 | sal = sals.sals[i]; | |
c906108c | 9449 | |
4a64f543 | 9450 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 9451 | ALL_BREAKPOINTS (b) |
c5aa993b | 9452 | { |
0d381245 | 9453 | int match = 0; |
4a64f543 | 9454 | /* Are we going to delete b? */ |
cc60f2e3 | 9455 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
9456 | { |
9457 | struct bp_location *loc = b->loc; | |
9458 | for (; loc; loc = loc->next) | |
9459 | { | |
6c95b8df PA |
9460 | int pc_match = sal.pc |
9461 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
9462 | && (loc->address == sal.pc) |
9463 | && (!section_is_overlay (loc->section) | |
9464 | || loc->section == sal.section); | |
9465 | int line_match = ((default_match || (0 == sal.pc)) | |
9466 | && b->source_file != NULL | |
9467 | && sal.symtab != NULL | |
6c95b8df | 9468 | && sal.pspace == loc->pspace |
3e43a32a MS |
9469 | && strcmp (b->source_file, |
9470 | sal.symtab->filename) == 0 | |
0d381245 VP |
9471 | && b->line_number == sal.line); |
9472 | if (pc_match || line_match) | |
9473 | { | |
9474 | match = 1; | |
9475 | break; | |
9476 | } | |
9477 | } | |
9478 | } | |
9479 | ||
9480 | if (match) | |
d6e956e5 | 9481 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 9482 | } |
80f8a6eb MS |
9483 | } |
9484 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 9485 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
9486 | { |
9487 | if (arg) | |
8a3fe4f8 | 9488 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 9489 | else |
8a3fe4f8 | 9490 | error (_("No breakpoint at this line.")); |
80f8a6eb | 9491 | } |
c906108c | 9492 | |
d6e956e5 | 9493 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 9494 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 9495 | if (from_tty) |
a3f17187 | 9496 | { |
d6e956e5 | 9497 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
9498 | printf_unfiltered (_("Deleted breakpoint ")); |
9499 | else | |
9500 | printf_unfiltered (_("Deleted breakpoints ")); | |
9501 | } | |
80f8a6eb | 9502 | breakpoints_changed (); |
d6e956e5 VP |
9503 | |
9504 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 9505 | { |
c5aa993b | 9506 | if (from_tty) |
d6e956e5 VP |
9507 | printf_unfiltered ("%d ", b->number); |
9508 | delete_breakpoint (b); | |
c906108c | 9509 | } |
80f8a6eb MS |
9510 | if (from_tty) |
9511 | putchar_unfiltered ('\n'); | |
c906108c SS |
9512 | } |
9513 | \f | |
9514 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
9515 | all breakpoints that are marked for deletion, whether hit or not. | |
9516 | This is called after any breakpoint is hit, or after errors. */ | |
9517 | ||
9518 | void | |
fba45db2 | 9519 | breakpoint_auto_delete (bpstat bs) |
c906108c | 9520 | { |
35df4500 | 9521 | struct breakpoint *b, *b_tmp; |
c906108c SS |
9522 | |
9523 | for (; bs; bs = bs->next) | |
f431efe5 PA |
9524 | if (bs->breakpoint_at |
9525 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 9526 | && bs->stop) |
f431efe5 | 9527 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 9528 | |
35df4500 | 9529 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 9530 | { |
b5de0fa7 | 9531 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
9532 | delete_breakpoint (b); |
9533 | } | |
c906108c SS |
9534 | } |
9535 | ||
4a64f543 MS |
9536 | /* A comparison function for bp_location AP and BP being interfaced to |
9537 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
9538 | does breakpoint_address_is_meaningful say for its OWNER), | |
9539 | secondarily by ordering first bp_permanent OWNERed elements and | |
9540 | terciarily just ensuring the array is sorted stable way despite | |
9541 | qsort being an instable algorithm. */ | |
876fa593 JK |
9542 | |
9543 | static int | |
494cfb0f | 9544 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 9545 | { |
494cfb0f JK |
9546 | struct bp_location *a = *(void **) ap; |
9547 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 9548 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
9549 | int a_perm = a->owner->enable_state == bp_permanent; |
9550 | int b_perm = b->owner->enable_state == bp_permanent; | |
9551 | ||
9552 | if (a->address != b->address) | |
9553 | return (a->address > b->address) - (a->address < b->address); | |
9554 | ||
9555 | /* Sort permanent breakpoints first. */ | |
9556 | if (a_perm != b_perm) | |
9557 | return (a_perm < b_perm) - (a_perm > b_perm); | |
9558 | ||
4a64f543 MS |
9559 | /* Make the user-visible order stable across GDB runs. Locations of |
9560 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
9561 | |
9562 | if (a->owner->number != b->owner->number) | |
9563 | return (a->owner->number > b->owner->number) | |
9564 | - (a->owner->number < b->owner->number); | |
9565 | ||
9566 | return (a > b) - (a < b); | |
9567 | } | |
9568 | ||
876fa593 | 9569 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
9570 | bp_location_shadow_len_after_address_max according to the current |
9571 | content of the bp_location array. */ | |
f7545552 TT |
9572 | |
9573 | static void | |
876fa593 | 9574 | bp_location_target_extensions_update (void) |
f7545552 | 9575 | { |
876fa593 JK |
9576 | struct bp_location *bl, **blp_tmp; |
9577 | ||
9578 | bp_location_placed_address_before_address_max = 0; | |
9579 | bp_location_shadow_len_after_address_max = 0; | |
9580 | ||
9581 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
9582 | { | |
9583 | CORE_ADDR start, end, addr; | |
9584 | ||
9585 | if (!bp_location_has_shadow (bl)) | |
9586 | continue; | |
9587 | ||
9588 | start = bl->target_info.placed_address; | |
9589 | end = start + bl->target_info.shadow_len; | |
9590 | ||
9591 | gdb_assert (bl->address >= start); | |
9592 | addr = bl->address - start; | |
9593 | if (addr > bp_location_placed_address_before_address_max) | |
9594 | bp_location_placed_address_before_address_max = addr; | |
9595 | ||
9596 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
9597 | ||
9598 | gdb_assert (bl->address < end); | |
9599 | addr = end - bl->address; | |
9600 | if (addr > bp_location_shadow_len_after_address_max) | |
9601 | bp_location_shadow_len_after_address_max = addr; | |
9602 | } | |
f7545552 TT |
9603 | } |
9604 | ||
4cd9bd08 | 9605 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
9606 | into the inferior, only remove already-inserted locations that no |
9607 | longer should be inserted. Functions that delete a breakpoint or | |
9608 | breakpoints should pass false, so that deleting a breakpoint | |
9609 | doesn't have the side effect of inserting the locations of other | |
9610 | breakpoints that are marked not-inserted, but should_be_inserted | |
9611 | returns true on them. | |
9612 | ||
9613 | This behaviour is useful is situations close to tear-down -- e.g., | |
9614 | after an exec, while the target still has execution, but breakpoint | |
9615 | shadows of the previous executable image should *NOT* be restored | |
9616 | to the new image; or before detaching, where the target still has | |
9617 | execution and wants to delete breakpoints from GDB's lists, and all | |
9618 | breakpoints had already been removed from the inferior. */ | |
9619 | ||
0d381245 | 9620 | static void |
b60e7edf | 9621 | update_global_location_list (int should_insert) |
0d381245 | 9622 | { |
74960c60 | 9623 | struct breakpoint *b; |
876fa593 | 9624 | struct bp_location **locp, *loc; |
f7545552 TT |
9625 | struct cleanup *cleanups; |
9626 | ||
2d134ed3 PA |
9627 | /* Used in the duplicates detection below. When iterating over all |
9628 | bp_locations, points to the first bp_location of a given address. | |
9629 | Breakpoints and watchpoints of different types are never | |
9630 | duplicates of each other. Keep one pointer for each type of | |
9631 | breakpoint/watchpoint, so we only need to loop over all locations | |
9632 | once. */ | |
9633 | struct bp_location *bp_loc_first; /* breakpoint */ | |
9634 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
9635 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
9636 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 9637 | |
4a64f543 MS |
9638 | /* Saved former bp_location array which we compare against the newly |
9639 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
9640 | struct bp_location **old_location, **old_locp; |
9641 | unsigned old_location_count; | |
9642 | ||
9643 | old_location = bp_location; | |
9644 | old_location_count = bp_location_count; | |
9645 | bp_location = NULL; | |
9646 | bp_location_count = 0; | |
9647 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 9648 | |
74960c60 | 9649 | ALL_BREAKPOINTS (b) |
876fa593 JK |
9650 | for (loc = b->loc; loc; loc = loc->next) |
9651 | bp_location_count++; | |
9652 | ||
9653 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
9654 | locp = bp_location; | |
9655 | ALL_BREAKPOINTS (b) | |
9656 | for (loc = b->loc; loc; loc = loc->next) | |
9657 | *locp++ = loc; | |
9658 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 9659 | bp_location_compare); |
876fa593 JK |
9660 | |
9661 | bp_location_target_extensions_update (); | |
74960c60 | 9662 | |
4a64f543 MS |
9663 | /* Identify bp_location instances that are no longer present in the |
9664 | new list, and therefore should be freed. Note that it's not | |
9665 | necessary that those locations should be removed from inferior -- | |
9666 | if there's another location at the same address (previously | |
9667 | marked as duplicate), we don't need to remove/insert the | |
9668 | location. | |
876fa593 | 9669 | |
4a64f543 MS |
9670 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
9671 | and former bp_location array state respectively. */ | |
876fa593 JK |
9672 | |
9673 | locp = bp_location; | |
9674 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
9675 | old_locp++) | |
74960c60 | 9676 | { |
876fa593 | 9677 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 9678 | struct bp_location **loc2p; |
876fa593 | 9679 | |
4a64f543 MS |
9680 | /* Tells if 'old_loc' is found amoung the new locations. If |
9681 | not, we have to free it. */ | |
c7d46a38 | 9682 | int found_object = 0; |
20874c92 VP |
9683 | /* Tells if the location should remain inserted in the target. */ |
9684 | int keep_in_target = 0; | |
9685 | int removed = 0; | |
876fa593 | 9686 | |
4a64f543 MS |
9687 | /* Skip LOCP entries which will definitely never be needed. |
9688 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 9689 | while (locp < bp_location + bp_location_count |
c7d46a38 | 9690 | && (*locp)->address < old_loc->address) |
876fa593 | 9691 | locp++; |
c7d46a38 PA |
9692 | |
9693 | for (loc2p = locp; | |
9694 | (loc2p < bp_location + bp_location_count | |
9695 | && (*loc2p)->address == old_loc->address); | |
9696 | loc2p++) | |
9697 | { | |
9698 | if (*loc2p == old_loc) | |
9699 | { | |
9700 | found_object = 1; | |
9701 | break; | |
9702 | } | |
9703 | } | |
74960c60 | 9704 | |
4a64f543 MS |
9705 | /* If this location is no longer present, and inserted, look if |
9706 | there's maybe a new location at the same address. If so, | |
9707 | mark that one inserted, and don't remove this one. This is | |
9708 | needed so that we don't have a time window where a breakpoint | |
9709 | at certain location is not inserted. */ | |
74960c60 | 9710 | |
876fa593 | 9711 | if (old_loc->inserted) |
0d381245 | 9712 | { |
4a64f543 MS |
9713 | /* If the location is inserted now, we might have to remove |
9714 | it. */ | |
74960c60 | 9715 | |
876fa593 | 9716 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 9717 | { |
4a64f543 MS |
9718 | /* The location is still present in the location list, |
9719 | and still should be inserted. Don't do anything. */ | |
20874c92 | 9720 | keep_in_target = 1; |
74960c60 VP |
9721 | } |
9722 | else | |
9723 | { | |
4a64f543 MS |
9724 | /* The location is either no longer present, or got |
9725 | disabled. See if there's another location at the | |
9726 | same address, in which case we don't need to remove | |
9727 | this one from the target. */ | |
876fa593 | 9728 | |
2bdf28a0 | 9729 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
9730 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
9731 | { | |
876fa593 | 9732 | for (loc2p = locp; |
c7d46a38 PA |
9733 | (loc2p < bp_location + bp_location_count |
9734 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
9735 | loc2p++) |
9736 | { | |
9737 | struct bp_location *loc2 = *loc2p; | |
9738 | ||
2d134ed3 | 9739 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
9740 | { |
9741 | /* For the sake of should_be_inserted. | |
4a64f543 MS |
9742 | Duplicates check below will fix up this |
9743 | later. */ | |
c7d46a38 | 9744 | loc2->duplicate = 0; |
85d721b8 PA |
9745 | |
9746 | /* Read watchpoint locations are switched to | |
9747 | access watchpoints, if the former are not | |
9748 | supported, but the latter are. */ | |
9749 | if (is_hardware_watchpoint (old_loc->owner)) | |
9750 | { | |
9751 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
9752 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
9753 | } | |
9754 | ||
c7d46a38 PA |
9755 | if (loc2 != old_loc && should_be_inserted (loc2)) |
9756 | { | |
9757 | loc2->inserted = 1; | |
9758 | loc2->target_info = old_loc->target_info; | |
9759 | keep_in_target = 1; | |
9760 | break; | |
9761 | } | |
876fa593 JK |
9762 | } |
9763 | } | |
9764 | } | |
74960c60 VP |
9765 | } |
9766 | ||
20874c92 VP |
9767 | if (!keep_in_target) |
9768 | { | |
876fa593 | 9769 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 9770 | { |
4a64f543 MS |
9771 | /* This is just about all we can do. We could keep |
9772 | this location on the global list, and try to | |
9773 | remove it next time, but there's no particular | |
9774 | reason why we will succeed next time. | |
20874c92 | 9775 | |
4a64f543 MS |
9776 | Note that at this point, old_loc->owner is still |
9777 | valid, as delete_breakpoint frees the breakpoint | |
9778 | only after calling us. */ | |
3e43a32a MS |
9779 | printf_filtered (_("warning: Error removing " |
9780 | "breakpoint %d\n"), | |
876fa593 | 9781 | old_loc->owner->number); |
20874c92 VP |
9782 | } |
9783 | removed = 1; | |
9784 | } | |
0d381245 | 9785 | } |
74960c60 VP |
9786 | |
9787 | if (!found_object) | |
1c5cfe86 | 9788 | { |
db82e815 PA |
9789 | if (removed && non_stop |
9790 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9791 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9792 | { |
db82e815 PA |
9793 | /* This location was removed from the target. In |
9794 | non-stop mode, a race condition is possible where | |
9795 | we've removed a breakpoint, but stop events for that | |
9796 | breakpoint are already queued and will arrive later. | |
9797 | We apply an heuristic to be able to distinguish such | |
9798 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9799 | breakpoint location for a bit, and will retire it | |
9800 | after we see some number of events. The theory here | |
9801 | is that reporting of events should, "on the average", | |
9802 | be fair, so after a while we'll see events from all | |
9803 | threads that have anything of interest, and no longer | |
9804 | need to keep this breakpoint location around. We | |
9805 | don't hold locations forever so to reduce chances of | |
9806 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9807 | SIGTRAP. | |
9808 | ||
9809 | The heuristic failing can be disastrous on | |
9810 | decr_pc_after_break targets. | |
9811 | ||
9812 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9813 | if we fail to recognize a late breakpoint SIGTRAP, | |
9814 | because events_till_retirement has reached 0 too | |
9815 | soon, we'll fail to do the PC adjustment, and report | |
9816 | a random SIGTRAP to the user. When the user resumes | |
9817 | the inferior, it will most likely immediately crash | |
2dec564e | 9818 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
9819 | corrupted, because of being resumed e.g., in the |
9820 | middle of a multi-byte instruction, or skipped a | |
9821 | one-byte instruction. This was actually seen happen | |
9822 | on native x86-linux, and should be less rare on | |
9823 | targets that do not support new thread events, like | |
9824 | remote, due to the heuristic depending on | |
9825 | thread_count. | |
9826 | ||
9827 | Mistaking a random SIGTRAP for a breakpoint trap | |
9828 | causes similar symptoms (PC adjustment applied when | |
9829 | it shouldn't), but then again, playing with SIGTRAPs | |
9830 | behind the debugger's back is asking for trouble. | |
9831 | ||
9832 | Since hardware watchpoint traps are always | |
9833 | distinguishable from other traps, so we don't need to | |
9834 | apply keep hardware watchpoint moribund locations | |
9835 | around. We simply always ignore hardware watchpoint | |
9836 | traps we can no longer explain. */ | |
9837 | ||
876fa593 JK |
9838 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9839 | old_loc->owner = NULL; | |
20874c92 | 9840 | |
876fa593 | 9841 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9842 | } |
9843 | else | |
f431efe5 PA |
9844 | { |
9845 | old_loc->owner = NULL; | |
9846 | decref_bp_location (&old_loc); | |
9847 | } | |
20874c92 | 9848 | } |
74960c60 | 9849 | } |
1c5cfe86 | 9850 | |
2d134ed3 PA |
9851 | /* Rescan breakpoints at the same address and section, marking the |
9852 | first one as "first" and any others as "duplicates". This is so | |
9853 | that the bpt instruction is only inserted once. If we have a | |
9854 | permanent breakpoint at the same place as BPT, make that one the | |
9855 | official one, and the rest as duplicates. Permanent breakpoints | |
9856 | are sorted first for the same address. | |
9857 | ||
9858 | Do the same for hardware watchpoints, but also considering the | |
9859 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9860 | |
2d134ed3 PA |
9861 | bp_loc_first = NULL; |
9862 | wp_loc_first = NULL; | |
9863 | awp_loc_first = NULL; | |
9864 | rwp_loc_first = NULL; | |
876fa593 | 9865 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9866 | { |
4a64f543 MS |
9867 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
9868 | non-NULL. */ | |
876fa593 | 9869 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9870 | struct bp_location **loc_first_p; |
876fa593 JK |
9871 | |
9872 | if (b->enable_state == bp_disabled | |
9873 | || b->enable_state == bp_call_disabled | |
9874 | || b->enable_state == bp_startup_disabled | |
9875 | || !loc->enabled | |
9876 | || loc->shlib_disabled | |
15c3d785 | 9877 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 9878 | || is_tracepoint (b)) |
876fa593 JK |
9879 | continue; |
9880 | ||
9881 | /* Permanent breakpoint should always be inserted. */ | |
9882 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9883 | internal_error (__FILE__, __LINE__, | |
9884 | _("allegedly permanent breakpoint is not " | |
9885 | "actually inserted")); | |
9886 | ||
2d134ed3 PA |
9887 | if (b->type == bp_hardware_watchpoint) |
9888 | loc_first_p = &wp_loc_first; | |
9889 | else if (b->type == bp_read_watchpoint) | |
9890 | loc_first_p = &rwp_loc_first; | |
9891 | else if (b->type == bp_access_watchpoint) | |
9892 | loc_first_p = &awp_loc_first; | |
9893 | else | |
9894 | loc_first_p = &bp_loc_first; | |
9895 | ||
9896 | if (*loc_first_p == NULL | |
9897 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9898 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9899 | { |
2d134ed3 | 9900 | *loc_first_p = loc; |
876fa593 JK |
9901 | loc->duplicate = 0; |
9902 | continue; | |
9903 | } | |
9904 | ||
9905 | loc->duplicate = 1; | |
9906 | ||
2d134ed3 PA |
9907 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9908 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9909 | internal_error (__FILE__, __LINE__, |
9910 | _("another breakpoint was inserted on top of " | |
9911 | "a permanent breakpoint")); | |
0d381245 | 9912 | } |
74960c60 | 9913 | |
50c71eaf | 9914 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9915 | && (have_live_inferiors () |
2567c7d9 | 9916 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9917 | insert_breakpoint_locations (); |
f7545552 TT |
9918 | |
9919 | do_cleanups (cleanups); | |
74960c60 VP |
9920 | } |
9921 | ||
20874c92 VP |
9922 | void |
9923 | breakpoint_retire_moribund (void) | |
9924 | { | |
9925 | struct bp_location *loc; | |
9926 | int ix; | |
9927 | ||
9928 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9929 | if (--(loc->events_till_retirement) == 0) | |
9930 | { | |
f431efe5 | 9931 | decref_bp_location (&loc); |
20874c92 VP |
9932 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
9933 | --ix; | |
9934 | } | |
9935 | } | |
9936 | ||
74960c60 | 9937 | static void |
b60e7edf | 9938 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9939 | { |
9940 | struct gdb_exception e; | |
cc59ec59 | 9941 | |
74960c60 | 9942 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 9943 | update_global_location_list (inserting); |
0d381245 VP |
9944 | } |
9945 | ||
f431efe5 PA |
9946 | /* Clear BKP from a BPS. */ |
9947 | ||
a474d7c2 | 9948 | static void |
f431efe5 | 9949 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
9950 | { |
9951 | bpstat bs; | |
cc59ec59 | 9952 | |
a474d7c2 | 9953 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 9954 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
9955 | { |
9956 | bs->breakpoint_at = NULL; | |
9957 | bs->old_val = NULL; | |
9958 | /* bs->commands will be freed later. */ | |
9959 | } | |
9960 | } | |
9961 | ||
9962 | /* Callback for iterate_over_threads. */ | |
9963 | static int | |
f431efe5 | 9964 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 9965 | { |
f431efe5 | 9966 | struct breakpoint *bpt = data; |
cc59ec59 | 9967 | |
16c381f0 | 9968 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
a474d7c2 PA |
9969 | return 0; |
9970 | } | |
9971 | ||
53a5351d | 9972 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 9973 | structures. */ |
c906108c SS |
9974 | |
9975 | void | |
fba45db2 | 9976 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9977 | { |
52f0bd74 | 9978 | struct breakpoint *b; |
c906108c | 9979 | |
8a3fe4f8 | 9980 | gdb_assert (bpt != NULL); |
c906108c | 9981 | |
4a64f543 MS |
9982 | /* Has this bp already been deleted? This can happen because |
9983 | multiple lists can hold pointers to bp's. bpstat lists are | |
9984 | especial culprits. | |
9985 | ||
9986 | One example of this happening is a watchpoint's scope bp. When | |
9987 | the scope bp triggers, we notice that the watchpoint is out of | |
9988 | scope, and delete it. We also delete its scope bp. But the | |
9989 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
9990 | That bpstat is then checked for auto-deleting bp's, which are | |
9991 | deleted. | |
9992 | ||
9993 | A real solution to this problem might involve reference counts in | |
9994 | bp's, and/or giving them pointers back to their referencing | |
9995 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
9996 | storage when no more references were extent. A cheaper bandaid | |
9997 | was chosen. */ | |
c906108c SS |
9998 | if (bpt->type == bp_none) |
9999 | return; | |
10000 | ||
4a64f543 MS |
10001 | /* At least avoid this stale reference until the reference counting |
10002 | of breakpoints gets resolved. */ | |
e5a0a904 JK |
10003 | if (bpt->related_breakpoint != NULL) |
10004 | { | |
10005 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
10006 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
10007 | bpt->related_breakpoint->related_breakpoint = NULL; | |
10008 | bpt->related_breakpoint = NULL; | |
10009 | } | |
10010 | ||
383f836e | 10011 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 10012 | |
c906108c SS |
10013 | if (breakpoint_chain == bpt) |
10014 | breakpoint_chain = bpt->next; | |
10015 | ||
c906108c SS |
10016 | ALL_BREAKPOINTS (b) |
10017 | if (b->next == bpt) | |
c5aa993b JM |
10018 | { |
10019 | b->next = bpt->next; | |
10020 | break; | |
10021 | } | |
c906108c | 10022 | |
9add0f1b | 10023 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
10024 | xfree (bpt->cond_string); |
10025 | xfree (bpt->cond_exp); | |
10026 | xfree (bpt->addr_string); | |
10027 | xfree (bpt->exp); | |
10028 | xfree (bpt->exp_string); | |
d63d0675 | 10029 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
10030 | value_free (bpt->val); |
10031 | xfree (bpt->source_file); | |
10032 | xfree (bpt->exec_pathname); | |
a96d9b2e | 10033 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 10034 | |
f431efe5 PA |
10035 | |
10036 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
10037 | been freed. */ | |
10038 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
10039 | in all threeds for now. Note that we cannot just remove bpstats | |
10040 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
10041 | commands are associated with the bpstat; if we remove it here, | |
10042 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
10043 | event-top.c won't do anything, and temporary breakpoints with | |
10044 | commands won't work. */ | |
10045 | ||
10046 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
10047 | ||
4a64f543 MS |
10048 | /* Now that breakpoint is removed from breakpoint list, update the |
10049 | global location list. This will remove locations that used to | |
10050 | belong to this breakpoint. Do this before freeing the breakpoint | |
10051 | itself, since remove_breakpoint looks at location's owner. It | |
10052 | might be better design to have location completely | |
10053 | self-contained, but it's not the case now. */ | |
b60e7edf | 10054 | update_global_location_list (0); |
74960c60 VP |
10055 | |
10056 | ||
4a64f543 MS |
10057 | /* On the chance that someone will soon try again to delete this |
10058 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c SS |
10059 | bpt->type = bp_none; |
10060 | ||
b8c9b27d | 10061 | xfree (bpt); |
c906108c SS |
10062 | } |
10063 | ||
4d6140d9 AC |
10064 | static void |
10065 | do_delete_breakpoint_cleanup (void *b) | |
10066 | { | |
10067 | delete_breakpoint (b); | |
10068 | } | |
10069 | ||
10070 | struct cleanup * | |
10071 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
10072 | { | |
10073 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
10074 | } | |
10075 | ||
95a42b64 TT |
10076 | /* A callback for map_breakpoint_numbers that calls |
10077 | delete_breakpoint. */ | |
10078 | ||
10079 | static void | |
10080 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
10081 | { | |
10082 | delete_breakpoint (b); | |
10083 | } | |
10084 | ||
c906108c | 10085 | void |
fba45db2 | 10086 | delete_command (char *arg, int from_tty) |
c906108c | 10087 | { |
35df4500 | 10088 | struct breakpoint *b, *b_tmp; |
c906108c | 10089 | |
ea9365bb TT |
10090 | dont_repeat (); |
10091 | ||
c906108c SS |
10092 | if (arg == 0) |
10093 | { | |
10094 | int breaks_to_delete = 0; | |
10095 | ||
10096 | /* Delete all breakpoints if no argument. | |
4a64f543 MS |
10097 | Do not delete internal or call-dummy breakpoints, these have |
10098 | to be deleted with an explicit breakpoint number argument. */ | |
c5aa993b JM |
10099 | ALL_BREAKPOINTS (b) |
10100 | { | |
059fb39f | 10101 | if (b->type != bp_call_dummy |
aa7d318d | 10102 | && b->type != bp_std_terminate |
059fb39f | 10103 | && b->type != bp_shlib_event |
4efc6507 | 10104 | && b->type != bp_jit_event |
059fb39f PM |
10105 | && b->type != bp_thread_event |
10106 | && b->type != bp_overlay_event | |
0fd8e87f | 10107 | && b->type != bp_longjmp_master |
aa7d318d | 10108 | && b->type != bp_std_terminate_master |
186c406b | 10109 | && b->type != bp_exception_master |
059fb39f | 10110 | && b->number >= 0) |
973d738b DJ |
10111 | { |
10112 | breaks_to_delete = 1; | |
10113 | break; | |
10114 | } | |
c5aa993b | 10115 | } |
c906108c SS |
10116 | |
10117 | /* Ask user only if there are some breakpoints to delete. */ | |
10118 | if (!from_tty | |
e2e0b3e5 | 10119 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 10120 | { |
35df4500 | 10121 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10122 | { |
059fb39f | 10123 | if (b->type != bp_call_dummy |
aa7d318d | 10124 | && b->type != bp_std_terminate |
059fb39f PM |
10125 | && b->type != bp_shlib_event |
10126 | && b->type != bp_thread_event | |
4efc6507 | 10127 | && b->type != bp_jit_event |
059fb39f | 10128 | && b->type != bp_overlay_event |
0fd8e87f | 10129 | && b->type != bp_longjmp_master |
aa7d318d | 10130 | && b->type != bp_std_terminate_master |
186c406b | 10131 | && b->type != bp_exception_master |
059fb39f | 10132 | && b->number >= 0) |
c5aa993b JM |
10133 | delete_breakpoint (b); |
10134 | } | |
c906108c SS |
10135 | } |
10136 | } | |
10137 | else | |
95a42b64 | 10138 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
10139 | } |
10140 | ||
0d381245 VP |
10141 | static int |
10142 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 10143 | { |
0d381245 VP |
10144 | for (; loc; loc = loc->next) |
10145 | if (!loc->shlib_disabled) | |
10146 | return 0; | |
10147 | return 1; | |
fe3f5fa8 VP |
10148 | } |
10149 | ||
776592bf DE |
10150 | /* Subroutine of update_breakpoint_locations to simplify it. |
10151 | Return non-zero if multiple fns in list LOC have the same name. | |
10152 | Null names are ignored. */ | |
10153 | ||
10154 | static int | |
10155 | ambiguous_names_p (struct bp_location *loc) | |
10156 | { | |
10157 | struct bp_location *l; | |
10158 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
10159 | (int (*) (const void *, |
10160 | const void *)) streq, | |
776592bf DE |
10161 | NULL, xcalloc, xfree); |
10162 | ||
10163 | for (l = loc; l != NULL; l = l->next) | |
10164 | { | |
10165 | const char **slot; | |
10166 | const char *name = l->function_name; | |
10167 | ||
10168 | /* Allow for some names to be NULL, ignore them. */ | |
10169 | if (name == NULL) | |
10170 | continue; | |
10171 | ||
10172 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
10173 | INSERT); | |
4a64f543 MS |
10174 | /* NOTE: We can assume slot != NULL here because xcalloc never |
10175 | returns NULL. */ | |
776592bf DE |
10176 | if (*slot != NULL) |
10177 | { | |
10178 | htab_delete (htab); | |
10179 | return 1; | |
10180 | } | |
10181 | *slot = name; | |
10182 | } | |
10183 | ||
10184 | htab_delete (htab); | |
10185 | return 0; | |
10186 | } | |
10187 | ||
0fb4aa4b PA |
10188 | /* When symbols change, it probably means the sources changed as well, |
10189 | and it might mean the static tracepoint markers are no longer at | |
10190 | the same address or line numbers they used to be at last we | |
10191 | checked. Losing your static tracepoints whenever you rebuild is | |
10192 | undesirable. This function tries to resync/rematch gdb static | |
10193 | tracepoints with the markers on the target, for static tracepoints | |
10194 | that have not been set by marker id. Static tracepoint that have | |
10195 | been set by marker id are reset by marker id in breakpoint_re_set. | |
10196 | The heuristic is: | |
10197 | ||
10198 | 1) For a tracepoint set at a specific address, look for a marker at | |
10199 | the old PC. If one is found there, assume to be the same marker. | |
10200 | If the name / string id of the marker found is different from the | |
10201 | previous known name, assume that means the user renamed the marker | |
10202 | in the sources, and output a warning. | |
10203 | ||
10204 | 2) For a tracepoint set at a given line number, look for a marker | |
10205 | at the new address of the old line number. If one is found there, | |
10206 | assume to be the same marker. If the name / string id of the | |
10207 | marker found is different from the previous known name, assume that | |
10208 | means the user renamed the marker in the sources, and output a | |
10209 | warning. | |
10210 | ||
10211 | 3) If a marker is no longer found at the same address or line, it | |
10212 | may mean the marker no longer exists. But it may also just mean | |
10213 | the code changed a bit. Maybe the user added a few lines of code | |
10214 | that made the marker move up or down (in line number terms). Ask | |
10215 | the target for info about the marker with the string id as we knew | |
10216 | it. If found, update line number and address in the matching | |
10217 | static tracepoint. This will get confused if there's more than one | |
10218 | marker with the same ID (possible in UST, although unadvised | |
10219 | precisely because it confuses tools). */ | |
10220 | ||
10221 | static struct symtab_and_line | |
10222 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
10223 | { | |
10224 | struct static_tracepoint_marker marker; | |
10225 | CORE_ADDR pc; | |
10226 | int i; | |
10227 | ||
10228 | pc = sal.pc; | |
10229 | if (sal.line) | |
10230 | find_line_pc (sal.symtab, sal.line, &pc); | |
10231 | ||
10232 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
10233 | { | |
10234 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
10235 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
10236 | b->number, | |
10237 | b->static_trace_marker_id, marker.str_id); | |
10238 | ||
10239 | xfree (b->static_trace_marker_id); | |
10240 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
10241 | release_static_tracepoint_marker (&marker); | |
10242 | ||
10243 | return sal; | |
10244 | } | |
10245 | ||
10246 | /* Old marker wasn't found on target at lineno. Try looking it up | |
10247 | by string ID. */ | |
10248 | if (!sal.explicit_pc | |
10249 | && sal.line != 0 | |
10250 | && sal.symtab != NULL | |
10251 | && b->static_trace_marker_id != NULL) | |
10252 | { | |
10253 | VEC(static_tracepoint_marker_p) *markers; | |
10254 | ||
10255 | markers | |
10256 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
10257 | ||
10258 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
10259 | { | |
10260 | struct symtab_and_line sal; | |
10261 | struct symbol *sym; | |
10262 | struct static_tracepoint_marker *marker; | |
10263 | ||
10264 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
10265 | ||
10266 | xfree (b->static_trace_marker_id); | |
10267 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
10268 | ||
10269 | warning (_("marker for static tracepoint %d (%s) not " | |
10270 | "found at previous line number"), | |
10271 | b->number, b->static_trace_marker_id); | |
10272 | ||
10273 | init_sal (&sal); | |
10274 | ||
10275 | sal.pc = marker->address; | |
10276 | ||
10277 | sal = find_pc_line (marker->address, 0); | |
10278 | sym = find_pc_sect_function (marker->address, NULL); | |
10279 | ui_out_text (uiout, "Now in "); | |
10280 | if (sym) | |
10281 | { | |
10282 | ui_out_field_string (uiout, "func", | |
10283 | SYMBOL_PRINT_NAME (sym)); | |
10284 | ui_out_text (uiout, " at "); | |
10285 | } | |
10286 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
10287 | ui_out_text (uiout, ":"); | |
10288 | ||
10289 | if (ui_out_is_mi_like_p (uiout)) | |
10290 | { | |
10291 | char *fullname = symtab_to_fullname (sal.symtab); | |
10292 | ||
10293 | if (fullname) | |
10294 | ui_out_field_string (uiout, "fullname", fullname); | |
10295 | } | |
10296 | ||
10297 | ui_out_field_int (uiout, "line", sal.line); | |
10298 | ui_out_text (uiout, "\n"); | |
10299 | ||
10300 | b->line_number = sal.line; | |
10301 | ||
10302 | xfree (b->source_file); | |
10303 | if (sym) | |
10304 | b->source_file = xstrdup (sal.symtab->filename); | |
10305 | else | |
10306 | b->source_file = NULL; | |
10307 | ||
10308 | xfree (b->addr_string); | |
10309 | b->addr_string = xstrprintf ("%s:%d", | |
10310 | sal.symtab->filename, b->line_number); | |
10311 | ||
10312 | /* Might be nice to check if function changed, and warn if | |
10313 | so. */ | |
10314 | ||
10315 | release_static_tracepoint_marker (marker); | |
10316 | } | |
10317 | } | |
10318 | return sal; | |
10319 | } | |
10320 | ||
fe3f5fa8 | 10321 | static void |
0d381245 VP |
10322 | update_breakpoint_locations (struct breakpoint *b, |
10323 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
10324 | { |
10325 | int i; | |
10326 | char *s; | |
0d381245 VP |
10327 | struct bp_location *existing_locations = b->loc; |
10328 | ||
4a64f543 MS |
10329 | /* If there's no new locations, and all existing locations are |
10330 | pending, don't do anything. This optimizes the common case where | |
10331 | all locations are in the same shared library, that was unloaded. | |
10332 | We'd like to retain the location, so that when the library is | |
10333 | loaded again, we don't loose the enabled/disabled status of the | |
10334 | individual locations. */ | |
0d381245 | 10335 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
10336 | return; |
10337 | ||
fe3f5fa8 VP |
10338 | b->loc = NULL; |
10339 | ||
0d381245 | 10340 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 10341 | { |
0d381245 | 10342 | struct bp_location *new_loc = |
39d61571 | 10343 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 10344 | |
0d381245 VP |
10345 | /* Reparse conditions, they might contain references to the |
10346 | old symtab. */ | |
10347 | if (b->cond_string != NULL) | |
10348 | { | |
10349 | struct gdb_exception e; | |
fe3f5fa8 | 10350 | |
0d381245 VP |
10351 | s = b->cond_string; |
10352 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10353 | { | |
10354 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
10355 | 0); | |
10356 | } | |
10357 | if (e.reason < 0) | |
10358 | { | |
3e43a32a MS |
10359 | warning (_("failed to reevaluate condition " |
10360 | "for breakpoint %d: %s"), | |
0d381245 VP |
10361 | b->number, e.message); |
10362 | new_loc->enabled = 0; | |
10363 | } | |
10364 | } | |
fe3f5fa8 | 10365 | |
0d381245 VP |
10366 | if (b->source_file != NULL) |
10367 | xfree (b->source_file); | |
10368 | if (sals.sals[i].symtab == NULL) | |
10369 | b->source_file = NULL; | |
10370 | else | |
1b36a34b | 10371 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 10372 | |
0d381245 VP |
10373 | if (b->line_number == 0) |
10374 | b->line_number = sals.sals[i].line; | |
10375 | } | |
fe3f5fa8 | 10376 | |
514f746b AR |
10377 | /* Update locations of permanent breakpoints. */ |
10378 | if (b->enable_state == bp_permanent) | |
10379 | make_breakpoint_permanent (b); | |
10380 | ||
4a64f543 MS |
10381 | /* If possible, carry over 'disable' status from existing |
10382 | breakpoints. */ | |
0d381245 VP |
10383 | { |
10384 | struct bp_location *e = existing_locations; | |
776592bf DE |
10385 | /* If there are multiple breakpoints with the same function name, |
10386 | e.g. for inline functions, comparing function names won't work. | |
10387 | Instead compare pc addresses; this is just a heuristic as things | |
10388 | may have moved, but in practice it gives the correct answer | |
10389 | often enough until a better solution is found. */ | |
10390 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
10391 | ||
0d381245 VP |
10392 | for (; e; e = e->next) |
10393 | { | |
10394 | if (!e->enabled && e->function_name) | |
10395 | { | |
10396 | struct bp_location *l = b->loc; | |
776592bf DE |
10397 | if (have_ambiguous_names) |
10398 | { | |
10399 | for (; l; l = l->next) | |
6c95b8df PA |
10400 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
10401 | l->pspace->aspace, l->address)) | |
776592bf DE |
10402 | { |
10403 | l->enabled = 0; | |
10404 | break; | |
10405 | } | |
10406 | } | |
10407 | else | |
10408 | { | |
10409 | for (; l; l = l->next) | |
10410 | if (l->function_name | |
10411 | && strcmp (e->function_name, l->function_name) == 0) | |
10412 | { | |
10413 | l->enabled = 0; | |
10414 | break; | |
10415 | } | |
10416 | } | |
0d381245 VP |
10417 | } |
10418 | } | |
10419 | } | |
fe3f5fa8 | 10420 | |
b60e7edf | 10421 | update_global_location_list (1); |
fe3f5fa8 VP |
10422 | } |
10423 | ||
c906108c SS |
10424 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
10425 | The value we return ends up being the return value from catch_errors. | |
10426 | Unused in this case. */ | |
10427 | ||
10428 | static int | |
4efb68b1 | 10429 | breakpoint_re_set_one (void *bint) |
c906108c | 10430 | { |
4a64f543 | 10431 | /* Get past catch_errs. */ |
53a5351d | 10432 | struct breakpoint *b = (struct breakpoint *) bint; |
fe3f5fa8 VP |
10433 | int not_found = 0; |
10434 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
10435 | struct symtabs_and_lines sals = {0}; |
10436 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 10437 | char *s; |
fe3f5fa8 | 10438 | struct gdb_exception e; |
6c95b8df | 10439 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
0fb4aa4b | 10440 | int marker_spec = 0; |
c906108c SS |
10441 | |
10442 | switch (b->type) | |
10443 | { | |
10444 | case bp_none: | |
8a3fe4f8 | 10445 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 10446 | b->number); |
c906108c SS |
10447 | return 0; |
10448 | case bp_breakpoint: | |
10449 | case bp_hardware_breakpoint: | |
1042e4c0 | 10450 | case bp_tracepoint: |
7a697b8d | 10451 | case bp_fast_tracepoint: |
0fb4aa4b | 10452 | case bp_static_tracepoint: |
8bea4e01 UW |
10453 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10454 | if (b->enable_state == bp_startup_disabled) | |
10455 | return 0; | |
10456 | ||
c906108c SS |
10457 | if (b->addr_string == NULL) |
10458 | { | |
4a64f543 | 10459 | /* Anything without a string can't be re-set. */ |
c906108c SS |
10460 | delete_breakpoint (b); |
10461 | return 0; | |
10462 | } | |
c906108c | 10463 | |
c906108c SS |
10464 | input_radix = b->input_radix; |
10465 | s = b->addr_string; | |
6c95b8df PA |
10466 | |
10467 | save_current_space_and_thread (); | |
10468 | switch_to_program_space_and_thread (b->pspace); | |
10469 | ||
0fb4aa4b PA |
10470 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); |
10471 | ||
385d04dc | 10472 | set_language (b->language); |
fe3f5fa8 | 10473 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 10474 | { |
0fb4aa4b PA |
10475 | if (marker_spec) |
10476 | { | |
10477 | sals = decode_static_tracepoint_spec (&s); | |
10478 | if (sals.nelts > b->static_trace_marker_id_idx) | |
10479 | { | |
10480 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
10481 | sals.nelts = 1; | |
10482 | } | |
10483 | else | |
10484 | error (_("marker %s not found"), b->static_trace_marker_id); | |
10485 | } | |
10486 | else | |
3e43a32a MS |
10487 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, |
10488 | (char ***) NULL, not_found_ptr); | |
fe3f5fa8 VP |
10489 | } |
10490 | if (e.reason < 0) | |
10491 | { | |
10492 | int not_found_and_ok = 0; | |
4a64f543 MS |
10493 | /* For pending breakpoints, it's expected that parsing will |
10494 | fail until the right shared library is loaded. User has | |
10495 | already told to create pending breakpoints and don't need | |
10496 | extra messages. If breakpoint is in bp_shlib_disabled | |
10497 | state, then user already saw the message about that | |
10498 | breakpoint being disabled, and don't want to see more | |
10499 | errors. */ | |
0d381245 VP |
10500 | if (not_found |
10501 | && (b->condition_not_parsed | |
10502 | || (b->loc && b->loc->shlib_disabled) | |
10503 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
10504 | not_found_and_ok = 1; |
10505 | ||
10506 | if (!not_found_and_ok) | |
c906108c | 10507 | { |
fe3f5fa8 VP |
10508 | /* We surely don't want to warn about the same breakpoint |
10509 | 10 times. One solution, implemented here, is disable | |
10510 | the breakpoint on error. Another solution would be to | |
10511 | have separate 'warning emitted' flag. Since this | |
10512 | happens only when a binary has changed, I don't know | |
10513 | which approach is better. */ | |
10514 | b->enable_state = bp_disabled; | |
10515 | throw_exception (e); | |
c906108c | 10516 | } |
fe3f5fa8 | 10517 | } |
c906108c | 10518 | |
6c95b8df | 10519 | if (!not_found) |
fe3f5fa8 | 10520 | { |
6c95b8df PA |
10521 | gdb_assert (sals.nelts == 1); |
10522 | ||
10523 | resolve_sal_pc (&sals.sals[0]); | |
10524 | if (b->condition_not_parsed && s && s[0]) | |
10525 | { | |
10526 | char *cond_string = 0; | |
10527 | int thread = -1; | |
10528 | int task = 0; | |
10529 | ||
10530 | find_condition_and_thread (s, sals.sals[0].pc, | |
10531 | &cond_string, &thread, &task); | |
10532 | if (cond_string) | |
10533 | b->cond_string = cond_string; | |
10534 | b->thread = thread; | |
10535 | b->task = task; | |
10536 | b->condition_not_parsed = 0; | |
10537 | } | |
10538 | ||
0fb4aa4b PA |
10539 | if (b->type == bp_static_tracepoint && !marker_spec) |
10540 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
10541 | ||
6c95b8df | 10542 | expanded = expand_line_sal_maybe (sals.sals[0]); |
fe3f5fa8 | 10543 | } |
6c95b8df PA |
10544 | |
10545 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 10546 | update_breakpoint_locations (b, expanded); |
c906108c SS |
10547 | break; |
10548 | ||
10549 | case bp_watchpoint: | |
10550 | case bp_hardware_watchpoint: | |
10551 | case bp_read_watchpoint: | |
10552 | case bp_access_watchpoint: | |
4a64f543 MS |
10553 | /* Watchpoint can be either on expression using entirely global |
10554 | variables, or it can be on local variables. | |
10555 | ||
10556 | Watchpoints of the first kind are never auto-deleted, and | |
10557 | even persist across program restarts. Since they can use | |
10558 | variables from shared libraries, we need to reparse | |
10559 | expression as libraries are loaded and unloaded. | |
10560 | ||
10561 | Watchpoints on local variables can also change meaning as | |
10562 | result of solib event. For example, if a watchpoint uses | |
10563 | both a local and a global variables in expression, it's a | |
10564 | local watchpoint, but unloading of a shared library will make | |
10565 | the expression invalid. This is not a very common use case, | |
10566 | but we still re-evaluate expression, to avoid surprises to | |
10567 | the user. | |
0b3de036 VP |
10568 | |
10569 | Note that for local watchpoints, we re-evaluate it only if | |
10570 | watchpoints frame id is still valid. If it's not, it means | |
4a64f543 MS |
10571 | the watchpoint is out of scope and will be deleted soon. In |
10572 | fact, I'm not sure we'll ever be called in this case. | |
0b3de036 VP |
10573 | |
10574 | If a local watchpoint's frame id is still valid, then | |
4a64f543 | 10575 | b->exp_valid_block is likewise valid, and we can safely use it. |
0b3de036 VP |
10576 | |
10577 | Don't do anything about disabled watchpoints, since they will | |
10578 | be reevaluated again when enabled. */ | |
a5606eee | 10579 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 10580 | break; |
c5aa993b JM |
10581 | /* We needn't really do anything to reset these, since the mask |
10582 | that requests them is unaffected by e.g., new libraries being | |
4a64f543 | 10583 | loaded. */ |
ce78b96d | 10584 | case bp_catchpoint: |
c906108c | 10585 | break; |
c5aa993b | 10586 | |
c906108c | 10587 | default: |
a3f17187 | 10588 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 10589 | /* fall through */ |
0fd8e87f UW |
10590 | /* Delete overlay event and longjmp master breakpoints; they will be |
10591 | reset later by breakpoint_re_set. */ | |
1900040c | 10592 | case bp_overlay_event: |
0fd8e87f | 10593 | case bp_longjmp_master: |
aa7d318d | 10594 | case bp_std_terminate_master: |
186c406b | 10595 | case bp_exception_master: |
c906108c SS |
10596 | delete_breakpoint (b); |
10597 | break; | |
10598 | ||
c5aa993b JM |
10599 | /* This breakpoint is special, it's set up when the inferior |
10600 | starts and we really don't want to touch it. */ | |
c906108c SS |
10601 | case bp_shlib_event: |
10602 | ||
c4093a6a JM |
10603 | /* Like bp_shlib_event, this breakpoint type is special. |
10604 | Once it is set up, we do not want to touch it. */ | |
10605 | case bp_thread_event: | |
10606 | ||
4a64f543 MS |
10607 | /* Keep temporary breakpoints, which can be encountered when we |
10608 | step over a dlopen call and SOLIB_ADD is resetting the | |
10609 | breakpoints. Otherwise these should have been blown away via | |
10610 | the cleanup chain or by breakpoint_init_inferior when we | |
10611 | rerun the executable. */ | |
c906108c SS |
10612 | case bp_until: |
10613 | case bp_finish: | |
10614 | case bp_watchpoint_scope: | |
10615 | case bp_call_dummy: | |
aa7d318d | 10616 | case bp_std_terminate: |
c906108c | 10617 | case bp_step_resume: |
611c83ae PA |
10618 | case bp_longjmp: |
10619 | case bp_longjmp_resume: | |
186c406b TT |
10620 | case bp_exception: |
10621 | case bp_exception_resume: | |
4efc6507 | 10622 | case bp_jit_event: |
c906108c SS |
10623 | break; |
10624 | } | |
10625 | ||
6c95b8df | 10626 | do_cleanups (cleanups); |
c906108c SS |
10627 | return 0; |
10628 | } | |
10629 | ||
69de3c6a | 10630 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 10631 | void |
69de3c6a | 10632 | breakpoint_re_set (void) |
c906108c | 10633 | { |
35df4500 | 10634 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10635 | enum language save_language; |
10636 | int save_input_radix; | |
6c95b8df | 10637 | struct cleanup *old_chain; |
c5aa993b | 10638 | |
c906108c SS |
10639 | save_language = current_language->la_language; |
10640 | save_input_radix = input_radix; | |
6c95b8df PA |
10641 | old_chain = save_current_program_space (); |
10642 | ||
35df4500 | 10643 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10644 | { |
4a64f543 | 10645 | /* Format possible error msg. */ |
fe3f5fa8 | 10646 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
10647 | b->number); |
10648 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 10649 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 10650 | do_cleanups (cleanups); |
c5aa993b | 10651 | } |
c906108c SS |
10652 | set_language (save_language); |
10653 | input_radix = save_input_radix; | |
e62c965a | 10654 | |
0756c555 | 10655 | jit_breakpoint_re_set (); |
4efc6507 | 10656 | |
6c95b8df PA |
10657 | do_cleanups (old_chain); |
10658 | ||
69de3c6a | 10659 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
10660 | create_longjmp_master_breakpoint ("longjmp"); |
10661 | create_longjmp_master_breakpoint ("_longjmp"); | |
10662 | create_longjmp_master_breakpoint ("siglongjmp"); | |
10663 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 10664 | create_std_terminate_master_breakpoint ("std::terminate()"); |
186c406b | 10665 | create_exception_master_breakpoint (); |
c906108c SS |
10666 | } |
10667 | \f | |
c906108c SS |
10668 | /* Reset the thread number of this breakpoint: |
10669 | ||
10670 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 10671 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 10672 | void |
fba45db2 | 10673 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
10674 | { |
10675 | if (b->thread != -1) | |
10676 | { | |
39f77062 KB |
10677 | if (in_thread_list (inferior_ptid)) |
10678 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
10679 | |
10680 | /* We're being called after following a fork. The new fork is | |
10681 | selected as current, and unless this was a vfork will have a | |
10682 | different program space from the original thread. Reset that | |
10683 | as well. */ | |
10684 | b->loc->pspace = current_program_space; | |
c906108c SS |
10685 | } |
10686 | } | |
10687 | ||
03ac34d5 MS |
10688 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10689 | If from_tty is nonzero, it prints a message to that effect, | |
10690 | which ends with a period (no newline). */ | |
10691 | ||
c906108c | 10692 | void |
fba45db2 | 10693 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 10694 | { |
52f0bd74 | 10695 | struct breakpoint *b; |
c906108c SS |
10696 | |
10697 | if (count < 0) | |
10698 | count = 0; | |
10699 | ||
10700 | ALL_BREAKPOINTS (b) | |
10701 | if (b->number == bptnum) | |
c5aa993b | 10702 | { |
d77f58be SS |
10703 | if (is_tracepoint (b)) |
10704 | { | |
10705 | if (from_tty && count != 0) | |
10706 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
10707 | bptnum); | |
10708 | return; | |
10709 | } | |
10710 | ||
c5aa993b | 10711 | b->ignore_count = count; |
221ea385 KS |
10712 | if (from_tty) |
10713 | { | |
10714 | if (count == 0) | |
3e43a32a MS |
10715 | printf_filtered (_("Will stop next time " |
10716 | "breakpoint %d is reached."), | |
221ea385 KS |
10717 | bptnum); |
10718 | else if (count == 1) | |
a3f17187 | 10719 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
10720 | bptnum); |
10721 | else | |
3e43a32a MS |
10722 | printf_filtered (_("Will ignore next %d " |
10723 | "crossings of breakpoint %d."), | |
221ea385 KS |
10724 | count, bptnum); |
10725 | } | |
c5aa993b | 10726 | breakpoints_changed (); |
383f836e | 10727 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
10728 | return; |
10729 | } | |
c906108c | 10730 | |
8a3fe4f8 | 10731 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
10732 | } |
10733 | ||
b2175913 MS |
10734 | void |
10735 | make_breakpoint_silent (struct breakpoint *b) | |
10736 | { | |
10737 | /* Silence the breakpoint. */ | |
10738 | b->silent = 1; | |
10739 | } | |
10740 | ||
c906108c SS |
10741 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
10742 | ||
10743 | static void | |
fba45db2 | 10744 | ignore_command (char *args, int from_tty) |
c906108c SS |
10745 | { |
10746 | char *p = args; | |
52f0bd74 | 10747 | int num; |
c906108c SS |
10748 | |
10749 | if (p == 0) | |
e2e0b3e5 | 10750 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 10751 | |
c906108c | 10752 | num = get_number (&p); |
5c44784c | 10753 | if (num == 0) |
8a3fe4f8 | 10754 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 10755 | if (*p == 0) |
8a3fe4f8 | 10756 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
10757 | |
10758 | set_ignore_count (num, | |
10759 | longest_to_int (value_as_long (parse_and_eval (p))), | |
10760 | from_tty); | |
221ea385 KS |
10761 | if (from_tty) |
10762 | printf_filtered ("\n"); | |
c906108c SS |
10763 | } |
10764 | \f | |
10765 | /* Call FUNCTION on each of the breakpoints | |
10766 | whose numbers are given in ARGS. */ | |
10767 | ||
10768 | static void | |
95a42b64 TT |
10769 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
10770 | void *), | |
10771 | void *data) | |
c906108c | 10772 | { |
52f0bd74 | 10773 | char *p = args; |
c906108c | 10774 | char *p1; |
52f0bd74 AC |
10775 | int num; |
10776 | struct breakpoint *b, *tmp; | |
11cf8741 | 10777 | int match; |
c906108c SS |
10778 | |
10779 | if (p == 0) | |
e2e0b3e5 | 10780 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
10781 | |
10782 | while (*p) | |
10783 | { | |
11cf8741 | 10784 | match = 0; |
c906108c | 10785 | p1 = p; |
c5aa993b | 10786 | |
5c44784c JM |
10787 | num = get_number_or_range (&p1); |
10788 | if (num == 0) | |
c5aa993b | 10789 | { |
8a3fe4f8 | 10790 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
10791 | } |
10792 | else | |
10793 | { | |
10794 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
10795 | if (b->number == num) | |
10796 | { | |
10797 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 10798 | match = 1; |
95a42b64 | 10799 | function (b, data); |
5c44784c | 10800 | if (related_breakpoint) |
95a42b64 | 10801 | function (related_breakpoint, data); |
11cf8741 | 10802 | break; |
5c44784c | 10803 | } |
11cf8741 | 10804 | if (match == 0) |
a3f17187 | 10805 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 10806 | } |
c906108c SS |
10807 | p = p1; |
10808 | } | |
10809 | } | |
10810 | ||
0d381245 VP |
10811 | static struct bp_location * |
10812 | find_location_by_number (char *number) | |
10813 | { | |
10814 | char *dot = strchr (number, '.'); | |
10815 | char *p1; | |
10816 | int bp_num; | |
10817 | int loc_num; | |
10818 | struct breakpoint *b; | |
10819 | struct bp_location *loc; | |
10820 | ||
10821 | *dot = '\0'; | |
10822 | ||
10823 | p1 = number; | |
10824 | bp_num = get_number_or_range (&p1); | |
10825 | if (bp_num == 0) | |
10826 | error (_("Bad breakpoint number '%s'"), number); | |
10827 | ||
10828 | ALL_BREAKPOINTS (b) | |
10829 | if (b->number == bp_num) | |
10830 | { | |
10831 | break; | |
10832 | } | |
10833 | ||
10834 | if (!b || b->number != bp_num) | |
10835 | error (_("Bad breakpoint number '%s'"), number); | |
10836 | ||
10837 | p1 = dot+1; | |
10838 | loc_num = get_number_or_range (&p1); | |
10839 | if (loc_num == 0) | |
10840 | error (_("Bad breakpoint location number '%s'"), number); | |
10841 | ||
10842 | --loc_num; | |
10843 | loc = b->loc; | |
10844 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
10845 | ; | |
10846 | if (!loc) | |
10847 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
10848 | ||
10849 | return loc; | |
10850 | } | |
10851 | ||
10852 | ||
1900040c MS |
10853 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10854 | If from_tty is nonzero, it prints a message to that effect, | |
10855 | which ends with a period (no newline). */ | |
10856 | ||
c906108c | 10857 | void |
fba45db2 | 10858 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10859 | { |
10860 | /* Never disable a watchpoint scope breakpoint; we want to | |
10861 | hit them when we leave scope so we can delete both the | |
10862 | watchpoint and its scope breakpoint at that time. */ | |
10863 | if (bpt->type == bp_watchpoint_scope) | |
10864 | return; | |
10865 | ||
c2c6d25f | 10866 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 10867 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
10868 | return; |
10869 | ||
b5de0fa7 | 10870 | bpt->enable_state = bp_disabled; |
c906108c | 10871 | |
b60e7edf | 10872 | update_global_location_list (0); |
c906108c | 10873 | |
383f836e | 10874 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10875 | } |
10876 | ||
95a42b64 TT |
10877 | /* A callback for map_breakpoint_numbers that calls |
10878 | disable_breakpoint. */ | |
10879 | ||
10880 | static void | |
10881 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
10882 | { | |
10883 | disable_breakpoint (b); | |
10884 | } | |
10885 | ||
c906108c | 10886 | static void |
fba45db2 | 10887 | disable_command (char *args, int from_tty) |
c906108c | 10888 | { |
52f0bd74 | 10889 | struct breakpoint *bpt; |
cc59ec59 | 10890 | |
c906108c SS |
10891 | if (args == 0) |
10892 | ALL_BREAKPOINTS (bpt) | |
10893 | switch (bpt->type) | |
c5aa993b JM |
10894 | { |
10895 | case bp_none: | |
8a3fe4f8 | 10896 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 10897 | bpt->number); |
c5aa993b JM |
10898 | continue; |
10899 | case bp_breakpoint: | |
1042e4c0 | 10900 | case bp_tracepoint: |
7a697b8d | 10901 | case bp_fast_tracepoint: |
0fb4aa4b | 10902 | case bp_static_tracepoint: |
ce78b96d | 10903 | case bp_catchpoint: |
c5aa993b JM |
10904 | case bp_hardware_breakpoint: |
10905 | case bp_watchpoint: | |
10906 | case bp_hardware_watchpoint: | |
10907 | case bp_read_watchpoint: | |
10908 | case bp_access_watchpoint: | |
10909 | disable_breakpoint (bpt); | |
10910 | default: | |
10911 | continue; | |
10912 | } | |
0d381245 VP |
10913 | else if (strchr (args, '.')) |
10914 | { | |
10915 | struct bp_location *loc = find_location_by_number (args); | |
10916 | if (loc) | |
10917 | loc->enabled = 0; | |
b60e7edf | 10918 | update_global_location_list (0); |
0d381245 | 10919 | } |
c906108c | 10920 | else |
95a42b64 | 10921 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
10922 | } |
10923 | ||
10924 | static void | |
fba45db2 | 10925 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 10926 | { |
afe38095 | 10927 | int target_resources_ok; |
c906108c SS |
10928 | |
10929 | if (bpt->type == bp_hardware_breakpoint) | |
10930 | { | |
10931 | int i; | |
c5aa993b | 10932 | i = hw_breakpoint_used_count (); |
53a5351d | 10933 | target_resources_ok = |
d92524f1 | 10934 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 10935 | i + 1, 0); |
c906108c | 10936 | if (target_resources_ok == 0) |
8a3fe4f8 | 10937 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 10938 | else if (target_resources_ok < 0) |
8a3fe4f8 | 10939 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
10940 | } |
10941 | ||
cc60f2e3 | 10942 | if (is_watchpoint (bpt)) |
c906108c | 10943 | { |
dde02812 ES |
10944 | struct gdb_exception e; |
10945 | ||
10946 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 10947 | { |
dde02812 | 10948 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 10949 | } |
dde02812 | 10950 | if (e.reason < 0) |
c5aa993b | 10951 | { |
dde02812 ES |
10952 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
10953 | bpt->number); | |
10954 | return; | |
c5aa993b | 10955 | } |
c906108c | 10956 | } |
0101ce28 | 10957 | |
b4c291bb KH |
10958 | if (bpt->enable_state != bp_permanent) |
10959 | bpt->enable_state = bp_enabled; | |
10960 | bpt->disposition = disposition; | |
b60e7edf | 10961 | update_global_location_list (1); |
b4c291bb KH |
10962 | breakpoints_changed (); |
10963 | ||
383f836e | 10964 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10965 | } |
10966 | ||
fe3f5fa8 | 10967 | |
c906108c | 10968 | void |
fba45db2 | 10969 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10970 | { |
10971 | do_enable_breakpoint (bpt, bpt->disposition); | |
10972 | } | |
10973 | ||
95a42b64 TT |
10974 | /* A callback for map_breakpoint_numbers that calls |
10975 | enable_breakpoint. */ | |
10976 | ||
10977 | static void | |
10978 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
10979 | { | |
10980 | enable_breakpoint (b); | |
10981 | } | |
10982 | ||
c906108c SS |
10983 | /* The enable command enables the specified breakpoints (or all defined |
10984 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 10985 | in stopping the inferior. */ |
c906108c | 10986 | |
c906108c | 10987 | static void |
fba45db2 | 10988 | enable_command (char *args, int from_tty) |
c906108c | 10989 | { |
52f0bd74 | 10990 | struct breakpoint *bpt; |
cc59ec59 | 10991 | |
c906108c SS |
10992 | if (args == 0) |
10993 | ALL_BREAKPOINTS (bpt) | |
10994 | switch (bpt->type) | |
c5aa993b JM |
10995 | { |
10996 | case bp_none: | |
8a3fe4f8 | 10997 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 10998 | bpt->number); |
c5aa993b JM |
10999 | continue; |
11000 | case bp_breakpoint: | |
1042e4c0 | 11001 | case bp_tracepoint: |
7a697b8d | 11002 | case bp_fast_tracepoint: |
0fb4aa4b | 11003 | case bp_static_tracepoint: |
ce78b96d | 11004 | case bp_catchpoint: |
c5aa993b JM |
11005 | case bp_hardware_breakpoint: |
11006 | case bp_watchpoint: | |
11007 | case bp_hardware_watchpoint: | |
11008 | case bp_read_watchpoint: | |
11009 | case bp_access_watchpoint: | |
11010 | enable_breakpoint (bpt); | |
11011 | default: | |
11012 | continue; | |
11013 | } | |
0d381245 VP |
11014 | else if (strchr (args, '.')) |
11015 | { | |
11016 | struct bp_location *loc = find_location_by_number (args); | |
11017 | if (loc) | |
11018 | loc->enabled = 1; | |
b60e7edf | 11019 | update_global_location_list (1); |
0d381245 | 11020 | } |
c906108c | 11021 | else |
95a42b64 | 11022 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
11023 | } |
11024 | ||
11025 | static void | |
95a42b64 | 11026 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11027 | { |
b5de0fa7 | 11028 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
11029 | } |
11030 | ||
c906108c | 11031 | static void |
fba45db2 | 11032 | enable_once_command (char *args, int from_tty) |
c906108c | 11033 | { |
95a42b64 | 11034 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
11035 | } |
11036 | ||
11037 | static void | |
95a42b64 | 11038 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11039 | { |
b5de0fa7 | 11040 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
11041 | } |
11042 | ||
c906108c | 11043 | static void |
fba45db2 | 11044 | enable_delete_command (char *args, int from_tty) |
c906108c | 11045 | { |
95a42b64 | 11046 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
11047 | } |
11048 | \f | |
fa8d40ab JJ |
11049 | static void |
11050 | set_breakpoint_cmd (char *args, int from_tty) | |
11051 | { | |
11052 | } | |
11053 | ||
11054 | static void | |
11055 | show_breakpoint_cmd (char *args, int from_tty) | |
11056 | { | |
11057 | } | |
11058 | ||
1f3b5d1b PP |
11059 | /* Invalidate last known value of any hardware watchpoint if |
11060 | the memory which that value represents has been written to by | |
11061 | GDB itself. */ | |
11062 | ||
11063 | static void | |
11064 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
11065 | const bfd_byte *data) | |
11066 | { | |
11067 | struct breakpoint *bp; | |
11068 | ||
11069 | ALL_BREAKPOINTS (bp) | |
11070 | if (bp->enable_state == bp_enabled | |
11071 | && bp->type == bp_hardware_watchpoint | |
11072 | && bp->val_valid && bp->val) | |
11073 | { | |
11074 | struct bp_location *loc; | |
11075 | ||
11076 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
11077 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
11078 | && loc->address + loc->length > addr | |
11079 | && addr + len > loc->address) | |
11080 | { | |
11081 | value_free (bp->val); | |
11082 | bp->val = NULL; | |
11083 | bp->val_valid = 0; | |
11084 | } | |
11085 | } | |
11086 | } | |
11087 | ||
c906108c SS |
11088 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
11089 | ||
11090 | struct symtabs_and_lines | |
fba45db2 | 11091 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
11092 | { |
11093 | struct symtabs_and_lines sals; | |
cc59ec59 | 11094 | |
c906108c | 11095 | if (string == 0) |
8a3fe4f8 | 11096 | error (_("Empty line specification.")); |
c906108c SS |
11097 | if (default_breakpoint_valid) |
11098 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
11099 | default_breakpoint_symtab, |
11100 | default_breakpoint_line, | |
68219205 | 11101 | (char ***) NULL, NULL); |
c906108c SS |
11102 | else |
11103 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 11104 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 11105 | if (*string) |
8a3fe4f8 | 11106 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
11107 | return sals; |
11108 | } | |
8181d85f DJ |
11109 | |
11110 | /* Create and insert a raw software breakpoint at PC. Return an | |
11111 | identifier, which should be used to remove the breakpoint later. | |
11112 | In general, places which call this should be using something on the | |
11113 | breakpoint chain instead; this function should be eliminated | |
11114 | someday. */ | |
11115 | ||
11116 | void * | |
6c95b8df PA |
11117 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
11118 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
11119 | { |
11120 | struct bp_target_info *bp_tgt; | |
11121 | ||
6c95b8df | 11122 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 11123 | |
6c95b8df | 11124 | bp_tgt->placed_address_space = aspace; |
8181d85f | 11125 | bp_tgt->placed_address = pc; |
6c95b8df | 11126 | |
a6d9a66e | 11127 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
11128 | { |
11129 | /* Could not insert the breakpoint. */ | |
11130 | xfree (bp_tgt); | |
11131 | return NULL; | |
11132 | } | |
11133 | ||
11134 | return bp_tgt; | |
11135 | } | |
11136 | ||
4a64f543 MS |
11137 | /* Remove a breakpoint BP inserted by |
11138 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
11139 | |
11140 | int | |
a6d9a66e | 11141 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
11142 | { |
11143 | struct bp_target_info *bp_tgt = bp; | |
11144 | int ret; | |
11145 | ||
a6d9a66e | 11146 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
11147 | xfree (bp_tgt); |
11148 | ||
11149 | return ret; | |
11150 | } | |
11151 | ||
4a64f543 MS |
11152 | /* One (or perhaps two) breakpoints used for software single |
11153 | stepping. */ | |
8181d85f DJ |
11154 | |
11155 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 11156 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
11157 | |
11158 | /* Create and insert a breakpoint for software single step. */ | |
11159 | ||
11160 | void | |
6c95b8df | 11161 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
11162 | struct address_space *aspace, |
11163 | CORE_ADDR next_pc) | |
8181d85f DJ |
11164 | { |
11165 | void **bpt_p; | |
11166 | ||
11167 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
11168 | { |
11169 | bpt_p = &single_step_breakpoints[0]; | |
11170 | single_step_gdbarch[0] = gdbarch; | |
11171 | } | |
8181d85f DJ |
11172 | else |
11173 | { | |
11174 | gdb_assert (single_step_breakpoints[1] == NULL); | |
11175 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 11176 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
11177 | } |
11178 | ||
4a64f543 MS |
11179 | /* NOTE drow/2006-04-11: A future improvement to this function would |
11180 | be to only create the breakpoints once, and actually put them on | |
11181 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
11182 | We could adjust the addresses each time they were needed. Doing | |
11183 | this requires corresponding changes elsewhere where single step | |
11184 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 11185 | |
6c95b8df | 11186 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 11187 | if (*bpt_p == NULL) |
5af949e3 UW |
11188 | error (_("Could not insert single-step breakpoint at %s"), |
11189 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
11190 | } |
11191 | ||
f02253f1 HZ |
11192 | /* Check if the breakpoints used for software single stepping |
11193 | were inserted or not. */ | |
11194 | ||
11195 | int | |
11196 | single_step_breakpoints_inserted (void) | |
11197 | { | |
11198 | return (single_step_breakpoints[0] != NULL | |
11199 | || single_step_breakpoints[1] != NULL); | |
11200 | } | |
11201 | ||
8181d85f DJ |
11202 | /* Remove and delete any breakpoints used for software single step. */ |
11203 | ||
11204 | void | |
11205 | remove_single_step_breakpoints (void) | |
11206 | { | |
11207 | gdb_assert (single_step_breakpoints[0] != NULL); | |
11208 | ||
11209 | /* See insert_single_step_breakpoint for more about this deprecated | |
11210 | call. */ | |
a6d9a66e UW |
11211 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
11212 | single_step_breakpoints[0]); | |
11213 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
11214 | single_step_breakpoints[0] = NULL; |
11215 | ||
11216 | if (single_step_breakpoints[1] != NULL) | |
11217 | { | |
a6d9a66e UW |
11218 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
11219 | single_step_breakpoints[1]); | |
11220 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
11221 | single_step_breakpoints[1] = NULL; |
11222 | } | |
11223 | } | |
11224 | ||
d03285ec UW |
11225 | /* Delete software single step breakpoints without removing them from |
11226 | the inferior. This is intended to be used if the inferior's address | |
11227 | space where they were inserted is already gone, e.g. after exit or | |
11228 | exec. */ | |
11229 | ||
11230 | void | |
11231 | cancel_single_step_breakpoints (void) | |
11232 | { | |
11233 | int i; | |
11234 | ||
11235 | for (i = 0; i < 2; i++) | |
11236 | if (single_step_breakpoints[i]) | |
11237 | { | |
11238 | xfree (single_step_breakpoints[i]); | |
11239 | single_step_breakpoints[i] = NULL; | |
11240 | single_step_gdbarch[i] = NULL; | |
11241 | } | |
11242 | } | |
11243 | ||
11244 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
11245 | removing them. */ | |
11246 | ||
11247 | static void | |
11248 | detach_single_step_breakpoints (void) | |
11249 | { | |
11250 | int i; | |
11251 | ||
11252 | for (i = 0; i < 2; i++) | |
11253 | if (single_step_breakpoints[i]) | |
11254 | target_remove_breakpoint (single_step_gdbarch[i], | |
11255 | single_step_breakpoints[i]); | |
11256 | } | |
11257 | ||
4a64f543 MS |
11258 | /* Check whether a software single-step breakpoint is inserted at |
11259 | PC. */ | |
1aafd4da UW |
11260 | |
11261 | static int | |
cc59ec59 MS |
11262 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
11263 | CORE_ADDR pc) | |
1aafd4da UW |
11264 | { |
11265 | int i; | |
11266 | ||
11267 | for (i = 0; i < 2; i++) | |
11268 | { | |
11269 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
11270 | if (bp_tgt |
11271 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
11272 | bp_tgt->placed_address, | |
11273 | aspace, pc)) | |
1aafd4da UW |
11274 | return 1; |
11275 | } | |
11276 | ||
11277 | return 0; | |
11278 | } | |
11279 | ||
a96d9b2e SDJ |
11280 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
11281 | non-zero otherwise. */ | |
11282 | static int | |
11283 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
11284 | { | |
11285 | if (syscall_catchpoint_p (bp) | |
11286 | && bp->enable_state != bp_disabled | |
11287 | && bp->enable_state != bp_call_disabled) | |
11288 | return 1; | |
11289 | else | |
11290 | return 0; | |
11291 | } | |
11292 | ||
11293 | int | |
11294 | catch_syscall_enabled (void) | |
11295 | { | |
11296 | struct inferior *inf = current_inferior (); | |
11297 | ||
11298 | return inf->total_syscalls_count != 0; | |
11299 | } | |
11300 | ||
11301 | int | |
11302 | catching_syscall_number (int syscall_number) | |
11303 | { | |
11304 | struct breakpoint *bp; | |
11305 | ||
11306 | ALL_BREAKPOINTS (bp) | |
11307 | if (is_syscall_catchpoint_enabled (bp)) | |
11308 | { | |
11309 | if (bp->syscalls_to_be_caught) | |
11310 | { | |
11311 | int i, iter; | |
11312 | for (i = 0; | |
11313 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
11314 | i++) | |
11315 | if (syscall_number == iter) | |
11316 | return 1; | |
11317 | } | |
11318 | else | |
11319 | return 1; | |
11320 | } | |
11321 | ||
11322 | return 0; | |
11323 | } | |
11324 | ||
11325 | /* Complete syscall names. Used by "catch syscall". */ | |
11326 | static char ** | |
11327 | catch_syscall_completer (struct cmd_list_element *cmd, | |
11328 | char *text, char *word) | |
11329 | { | |
11330 | const char **list = get_syscall_names (); | |
cc59ec59 | 11331 | |
a96d9b2e SDJ |
11332 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); |
11333 | } | |
11334 | ||
1042e4c0 SS |
11335 | /* Tracepoint-specific operations. */ |
11336 | ||
11337 | /* Set tracepoint count to NUM. */ | |
11338 | static void | |
11339 | set_tracepoint_count (int num) | |
11340 | { | |
11341 | tracepoint_count = num; | |
4fa62494 | 11342 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
11343 | } |
11344 | ||
11345 | void | |
11346 | trace_command (char *arg, int from_tty) | |
11347 | { | |
8cdf0e15 VP |
11348 | if (create_breakpoint (get_current_arch (), |
11349 | arg, | |
11350 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11351 | 0 /* tempflag */, |
11352 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11353 | 0 /* Ignore count */, |
11354 | pending_break_support, | |
11355 | NULL, | |
11356 | from_tty, | |
84f4c1fe PM |
11357 | 1 /* enabled */, |
11358 | 0 /* internal */)) | |
fd9b8c24 | 11359 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
11360 | } |
11361 | ||
7a697b8d SS |
11362 | void |
11363 | ftrace_command (char *arg, int from_tty) | |
11364 | { | |
8cdf0e15 VP |
11365 | if (create_breakpoint (get_current_arch (), |
11366 | arg, | |
11367 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11368 | 0 /* tempflag */, |
11369 | bp_fast_tracepoint /* type_wanted */, | |
11370 | 0 /* Ignore count */, | |
11371 | pending_break_support, | |
11372 | NULL, | |
11373 | from_tty, | |
84f4c1fe PM |
11374 | 1 /* enabled */, |
11375 | 0 /* internal */)) | |
0fb4aa4b PA |
11376 | set_tracepoint_count (breakpoint_count); |
11377 | } | |
11378 | ||
11379 | /* strace command implementation. Creates a static tracepoint. */ | |
11380 | ||
11381 | void | |
11382 | strace_command (char *arg, int from_tty) | |
11383 | { | |
11384 | if (create_breakpoint (get_current_arch (), | |
11385 | arg, | |
11386 | NULL, 0, 1 /* parse arg */, | |
11387 | 0 /* tempflag */, | |
11388 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11389 | 0 /* Ignore count */, |
11390 | pending_break_support, | |
11391 | NULL, | |
11392 | from_tty, | |
84f4c1fe PM |
11393 | 1 /* enabled */, |
11394 | 0 /* internal */)) | |
fd9b8c24 | 11395 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
11396 | } |
11397 | ||
409873ef SS |
11398 | /* Set up a fake reader function that gets command lines from a linked |
11399 | list that was acquired during tracepoint uploading. */ | |
11400 | ||
11401 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 11402 | static int next_cmd; |
409873ef SS |
11403 | |
11404 | static char * | |
11405 | read_uploaded_action (void) | |
11406 | { | |
11407 | char *rslt; | |
11408 | ||
3149d8c1 | 11409 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 11410 | |
3149d8c1 | 11411 | next_cmd++; |
409873ef SS |
11412 | |
11413 | return rslt; | |
11414 | } | |
11415 | ||
00bf0b85 SS |
11416 | /* Given information about a tracepoint as recorded on a target (which |
11417 | can be either a live system or a trace file), attempt to create an | |
11418 | equivalent GDB tracepoint. This is not a reliable process, since | |
11419 | the target does not necessarily have all the information used when | |
11420 | the tracepoint was originally defined. */ | |
11421 | ||
11422 | struct breakpoint * | |
11423 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 11424 | { |
409873ef | 11425 | char *addr_str, small_buf[100]; |
d5551862 | 11426 | struct breakpoint *tp; |
fd9b8c24 | 11427 | |
409873ef SS |
11428 | if (utp->at_string) |
11429 | addr_str = utp->at_string; | |
11430 | else | |
11431 | { | |
11432 | /* In the absence of a source location, fall back to raw | |
11433 | address. Since there is no way to confirm that the address | |
11434 | means the same thing as when the trace was started, warn the | |
11435 | user. */ | |
3e43a32a MS |
11436 | warning (_("Uploaded tracepoint %d has no " |
11437 | "source location, using raw address"), | |
409873ef SS |
11438 | utp->number); |
11439 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
11440 | addr_str = small_buf; | |
11441 | } | |
11442 | ||
11443 | /* There's not much we can do with a sequence of bytecodes. */ | |
11444 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
11445 | warning (_("Uploaded tracepoint %d condition " |
11446 | "has no source form, ignoring it"), | |
409873ef | 11447 | utp->number); |
d5551862 | 11448 | |
8cdf0e15 | 11449 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
11450 | addr_str, |
11451 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 11452 | 0 /* tempflag */, |
0fb4aa4b | 11453 | utp->type /* type_wanted */, |
8cdf0e15 VP |
11454 | 0 /* Ignore count */, |
11455 | pending_break_support, | |
11456 | NULL, | |
11457 | 0 /* from_tty */, | |
84f4c1fe PM |
11458 | utp->enabled /* enabled */, |
11459 | 0 /* internal */)) | |
fd9b8c24 PA |
11460 | return NULL; |
11461 | ||
00bf0b85 SS |
11462 | set_tracepoint_count (breakpoint_count); |
11463 | ||
409873ef | 11464 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
11465 | tp = get_tracepoint (tracepoint_count); |
11466 | gdb_assert (tp != NULL); | |
d5551862 | 11467 | |
00bf0b85 SS |
11468 | if (utp->pass > 0) |
11469 | { | |
409873ef | 11470 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 11471 | |
409873ef | 11472 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
11473 | } |
11474 | ||
409873ef SS |
11475 | /* If we have uploaded versions of the original commands, set up a |
11476 | special-purpose "reader" function and call the usual command line | |
11477 | reader, then pass the result to the breakpoint command-setting | |
11478 | function. */ | |
3149d8c1 | 11479 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 11480 | { |
409873ef | 11481 | struct command_line *cmd_list; |
00bf0b85 | 11482 | |
409873ef | 11483 | this_utp = utp; |
3149d8c1 | 11484 | next_cmd = 0; |
d5551862 | 11485 | |
409873ef SS |
11486 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
11487 | ||
11488 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 11489 | } |
3149d8c1 SS |
11490 | else if (!VEC_empty (char_ptr, utp->actions) |
11491 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
11492 | warning (_("Uploaded tracepoint %d actions " |
11493 | "have no source form, ignoring them"), | |
409873ef | 11494 | utp->number); |
00bf0b85 SS |
11495 | |
11496 | return tp; | |
11497 | } | |
11498 | ||
1042e4c0 SS |
11499 | /* Print information on tracepoint number TPNUM_EXP, or all if |
11500 | omitted. */ | |
11501 | ||
11502 | static void | |
11503 | tracepoints_info (char *tpnum_exp, int from_tty) | |
11504 | { | |
d77f58be SS |
11505 | int tpnum = -1, num_printed; |
11506 | ||
11507 | if (tpnum_exp) | |
11508 | tpnum = parse_and_eval_long (tpnum_exp); | |
1042e4c0 | 11509 | |
d77f58be SS |
11510 | num_printed = breakpoint_1 (tpnum, 0, is_tracepoint); |
11511 | ||
11512 | if (num_printed == 0) | |
1042e4c0 | 11513 | { |
d77f58be SS |
11514 | if (tpnum == -1) |
11515 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
11516 | else | |
11517 | ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum); | |
1042e4c0 | 11518 | } |
ad443146 SS |
11519 | |
11520 | default_collect_info (); | |
1042e4c0 SS |
11521 | } |
11522 | ||
4a64f543 | 11523 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
11524 | Not supported by all targets. */ |
11525 | static void | |
11526 | enable_trace_command (char *args, int from_tty) | |
11527 | { | |
11528 | enable_command (args, from_tty); | |
11529 | } | |
11530 | ||
4a64f543 | 11531 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
11532 | Not supported by all targets. */ |
11533 | static void | |
11534 | disable_trace_command (char *args, int from_tty) | |
11535 | { | |
11536 | disable_command (args, from_tty); | |
11537 | } | |
11538 | ||
4a64f543 | 11539 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
11540 | static void |
11541 | delete_trace_command (char *arg, int from_tty) | |
11542 | { | |
35df4500 | 11543 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
11544 | |
11545 | dont_repeat (); | |
11546 | ||
11547 | if (arg == 0) | |
11548 | { | |
11549 | int breaks_to_delete = 0; | |
11550 | ||
11551 | /* Delete all breakpoints if no argument. | |
11552 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
11553 | have to be deleted with an explicit breakpoint number |
11554 | argument. */ | |
1042e4c0 SS |
11555 | ALL_TRACEPOINTS (b) |
11556 | { | |
11557 | if (b->number >= 0) | |
11558 | { | |
11559 | breaks_to_delete = 1; | |
11560 | break; | |
11561 | } | |
11562 | } | |
11563 | ||
11564 | /* Ask user only if there are some breakpoints to delete. */ | |
11565 | if (!from_tty | |
11566 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
11567 | { | |
35df4500 | 11568 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
1042e4c0 | 11569 | { |
d77f58be | 11570 | if (is_tracepoint (b) |
059fb39f | 11571 | && b->number >= 0) |
1042e4c0 SS |
11572 | delete_breakpoint (b); |
11573 | } | |
11574 | } | |
11575 | } | |
11576 | else | |
95a42b64 | 11577 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
11578 | } |
11579 | ||
11580 | /* Set passcount for tracepoint. | |
11581 | ||
11582 | First command argument is passcount, second is tracepoint number. | |
11583 | If tracepoint number omitted, apply to most recently defined. | |
11584 | Also accepts special argument "all". */ | |
11585 | ||
11586 | static void | |
11587 | trace_pass_command (char *args, int from_tty) | |
11588 | { | |
11589 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
11590 | unsigned int count; | |
11591 | int all = 0; | |
11592 | ||
11593 | if (args == 0 || *args == 0) | |
3e43a32a MS |
11594 | error (_("passcount command requires an " |
11595 | "argument (count + optional TP num)")); | |
1042e4c0 | 11596 | |
4a64f543 | 11597 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
11598 | |
11599 | while (*args && isspace ((int) *args)) | |
11600 | args++; | |
11601 | ||
11602 | if (*args && strncasecmp (args, "all", 3) == 0) | |
11603 | { | |
11604 | args += 3; /* Skip special argument "all". */ | |
11605 | all = 1; | |
11606 | if (*args) | |
11607 | error (_("Junk at end of arguments.")); | |
11608 | } | |
11609 | else | |
11610 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
11611 | ||
11612 | do | |
11613 | { | |
11614 | if (t1) | |
11615 | { | |
11616 | ALL_TRACEPOINTS (t2) | |
11617 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
11618 | { | |
11619 | t2->pass_count = count; | |
11620 | observer_notify_tracepoint_modified (t2->number); | |
11621 | if (from_tty) | |
3e43a32a MS |
11622 | printf_filtered (_("Setting tracepoint %d's " |
11623 | "passcount to %d\n"), | |
1042e4c0 SS |
11624 | t2->number, count); |
11625 | } | |
11626 | if (! all && *args) | |
11627 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
11628 | } | |
11629 | } | |
11630 | while (*args); | |
11631 | } | |
11632 | ||
11633 | struct breakpoint * | |
11634 | get_tracepoint (int num) | |
11635 | { | |
11636 | struct breakpoint *t; | |
11637 | ||
11638 | ALL_TRACEPOINTS (t) | |
11639 | if (t->number == num) | |
11640 | return t; | |
11641 | ||
11642 | return NULL; | |
11643 | } | |
11644 | ||
d5551862 SS |
11645 | /* Find the tracepoint with the given target-side number (which may be |
11646 | different from the tracepoint number after disconnecting and | |
11647 | reconnecting). */ | |
11648 | ||
11649 | struct breakpoint * | |
11650 | get_tracepoint_by_number_on_target (int num) | |
11651 | { | |
11652 | struct breakpoint *t; | |
11653 | ||
11654 | ALL_TRACEPOINTS (t) | |
11655 | if (t->number_on_target == num) | |
11656 | return t; | |
11657 | ||
11658 | return NULL; | |
11659 | } | |
11660 | ||
1042e4c0 SS |
11661 | /* Utility: parse a tracepoint number and look it up in the list. |
11662 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
11663 | if OPTIONAL_P is true, then if the argument is missing, the most | |
11664 | recent tracepoint (tracepoint_count) is returned. */ | |
11665 | struct breakpoint * | |
11666 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
11667 | { | |
11668 | extern int tracepoint_count; | |
11669 | struct breakpoint *t; | |
11670 | int tpnum; | |
11671 | char *instring = arg == NULL ? NULL : *arg; | |
11672 | ||
11673 | if (arg == NULL || *arg == NULL || ! **arg) | |
11674 | { | |
11675 | if (optional_p) | |
11676 | tpnum = tracepoint_count; | |
11677 | else | |
11678 | error_no_arg (_("tracepoint number")); | |
11679 | } | |
11680 | else | |
11681 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
11682 | ||
11683 | if (tpnum <= 0) | |
11684 | { | |
11685 | if (instring && *instring) | |
11686 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
11687 | instring); | |
11688 | else | |
3e43a32a MS |
11689 | printf_filtered (_("Tracepoint argument missing " |
11690 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
11691 | return NULL; |
11692 | } | |
11693 | ||
11694 | ALL_TRACEPOINTS (t) | |
11695 | if (t->number == tpnum) | |
11696 | { | |
11697 | return t; | |
11698 | } | |
11699 | ||
11700 | /* FIXME: if we are in the middle of a range we don't want to give | |
11701 | a message. The current interface to get_number_or_range doesn't | |
11702 | allow us to discover this. */ | |
11703 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
11704 | return NULL; | |
11705 | } | |
11706 | ||
6149aea9 PA |
11707 | /* Save information on user settable breakpoints (watchpoints, etc) to |
11708 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
11709 | on each breakpoint and only include the ones for which it returns | |
11710 | non-zero. */ | |
11711 | ||
1042e4c0 | 11712 | static void |
6149aea9 PA |
11713 | save_breakpoints (char *filename, int from_tty, |
11714 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
11715 | { |
11716 | struct breakpoint *tp; | |
6149aea9 | 11717 | int any = 0; |
a7bdde9e | 11718 | char *pathname; |
1042e4c0 | 11719 | struct cleanup *cleanup; |
a7bdde9e | 11720 | struct ui_file *fp; |
6149aea9 | 11721 | int extra_trace_bits = 0; |
1042e4c0 | 11722 | |
6149aea9 PA |
11723 | if (filename == 0 || *filename == 0) |
11724 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
11725 | |
11726 | /* See if we have anything to save. */ | |
6149aea9 | 11727 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11728 | { |
6149aea9 | 11729 | /* Skip internal and momentary breakpoints. */ |
84f4c1fe | 11730 | if (!user_settable_breakpoint (tp) || tp->number < 0) |
6149aea9 PA |
11731 | continue; |
11732 | ||
11733 | /* If we have a filter, only save the breakpoints it accepts. */ | |
11734 | if (filter && !filter (tp)) | |
11735 | continue; | |
11736 | ||
11737 | any = 1; | |
11738 | ||
11739 | if (is_tracepoint (tp)) | |
11740 | { | |
11741 | extra_trace_bits = 1; | |
11742 | ||
11743 | /* We can stop searching. */ | |
11744 | break; | |
11745 | } | |
1042e4c0 | 11746 | } |
6149aea9 PA |
11747 | |
11748 | if (!any) | |
1042e4c0 | 11749 | { |
6149aea9 | 11750 | warning (_("Nothing to save.")); |
1042e4c0 SS |
11751 | return; |
11752 | } | |
11753 | ||
6149aea9 | 11754 | pathname = tilde_expand (filename); |
1042e4c0 | 11755 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 11756 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 11757 | if (!fp) |
6149aea9 PA |
11758 | error (_("Unable to open file '%s' for saving (%s)"), |
11759 | filename, safe_strerror (errno)); | |
a7bdde9e | 11760 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 11761 | |
6149aea9 PA |
11762 | if (extra_trace_bits) |
11763 | save_trace_state_variables (fp); | |
8bf6485c | 11764 | |
6149aea9 | 11765 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11766 | { |
6149aea9 | 11767 | /* Skip internal and momentary breakpoints. */ |
84f4c1fe | 11768 | if (!user_settable_breakpoint (tp) || tp->number < 0) |
6149aea9 | 11769 | continue; |
8bf6485c | 11770 | |
6149aea9 PA |
11771 | /* If we have a filter, only save the breakpoints it accepts. */ |
11772 | if (filter && !filter (tp)) | |
11773 | continue; | |
11774 | ||
11775 | if (tp->ops != NULL) | |
11776 | (tp->ops->print_recreate) (tp, fp); | |
1042e4c0 SS |
11777 | else |
11778 | { | |
6149aea9 PA |
11779 | if (tp->type == bp_fast_tracepoint) |
11780 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
11781 | if (tp->type == bp_static_tracepoint) |
11782 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
11783 | else if (tp->type == bp_tracepoint) |
11784 | fprintf_unfiltered (fp, "trace"); | |
11785 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11786 | fprintf_unfiltered (fp, "tbreak"); | |
11787 | else if (tp->type == bp_breakpoint) | |
11788 | fprintf_unfiltered (fp, "break"); | |
11789 | else if (tp->type == bp_hardware_breakpoint | |
11790 | && tp->disposition == disp_del) | |
11791 | fprintf_unfiltered (fp, "thbreak"); | |
11792 | else if (tp->type == bp_hardware_breakpoint) | |
11793 | fprintf_unfiltered (fp, "hbreak"); | |
11794 | else if (tp->type == bp_watchpoint) | |
11795 | fprintf_unfiltered (fp, "watch"); | |
11796 | else if (tp->type == bp_hardware_watchpoint) | |
11797 | fprintf_unfiltered (fp, "watch"); | |
11798 | else if (tp->type == bp_read_watchpoint) | |
11799 | fprintf_unfiltered (fp, "rwatch"); | |
11800 | else if (tp->type == bp_access_watchpoint) | |
11801 | fprintf_unfiltered (fp, "awatch"); | |
11802 | else | |
11803 | internal_error (__FILE__, __LINE__, | |
11804 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11805 | ||
11806 | if (tp->exp_string) | |
11807 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
11808 | else if (tp->addr_string) | |
11809 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
11810 | else | |
11811 | { | |
11812 | char tmp[40]; | |
11813 | ||
11814 | sprintf_vma (tmp, tp->loc->address); | |
11815 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
11816 | } | |
1042e4c0 SS |
11817 | } |
11818 | ||
6149aea9 PA |
11819 | if (tp->thread != -1) |
11820 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
11821 | ||
11822 | if (tp->task != 0) | |
11823 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
11824 | |
11825 | fprintf_unfiltered (fp, "\n"); | |
11826 | ||
6149aea9 PA |
11827 | /* Note, we can't rely on tp->number for anything, as we can't |
11828 | assume the recreated breakpoint numbers will match. Use $bpnum | |
11829 | instead. */ | |
11830 | ||
11831 | if (tp->cond_string) | |
11832 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
11833 | ||
11834 | if (tp->ignore_count) | |
11835 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
11836 | ||
1042e4c0 | 11837 | if (tp->pass_count) |
a7bdde9e | 11838 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 11839 | |
a7bdde9e | 11840 | if (tp->commands) |
1042e4c0 | 11841 | { |
a7bdde9e VP |
11842 | volatile struct gdb_exception ex; |
11843 | ||
6149aea9 | 11844 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
11845 | |
11846 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 11847 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 11848 | { |
9add0f1b | 11849 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
11850 | } |
11851 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 11852 | |
a7bdde9e VP |
11853 | if (ex.reason < 0) |
11854 | throw_exception (ex); | |
1042e4c0 | 11855 | |
a7bdde9e | 11856 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 11857 | } |
6149aea9 PA |
11858 | |
11859 | if (tp->enable_state == bp_disabled) | |
11860 | fprintf_unfiltered (fp, "disable\n"); | |
11861 | ||
11862 | /* If this is a multi-location breakpoint, check if the locations | |
11863 | should be individually disabled. Watchpoint locations are | |
11864 | special, and not user visible. */ | |
11865 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
11866 | { | |
11867 | struct bp_location *loc; | |
11868 | int n = 1; | |
11869 | ||
11870 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
11871 | if (!loc->enabled) | |
11872 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
11873 | } | |
1042e4c0 | 11874 | } |
8bf6485c | 11875 | |
6149aea9 | 11876 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
11877 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
11878 | ||
1042e4c0 SS |
11879 | do_cleanups (cleanup); |
11880 | if (from_tty) | |
6149aea9 PA |
11881 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
11882 | } | |
11883 | ||
11884 | /* The `save breakpoints' command. */ | |
11885 | ||
11886 | static void | |
11887 | save_breakpoints_command (char *args, int from_tty) | |
11888 | { | |
11889 | save_breakpoints (args, from_tty, NULL); | |
11890 | } | |
11891 | ||
11892 | /* The `save tracepoints' command. */ | |
11893 | ||
11894 | static void | |
11895 | save_tracepoints_command (char *args, int from_tty) | |
11896 | { | |
11897 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
11898 | } |
11899 | ||
11900 | /* Create a vector of all tracepoints. */ | |
11901 | ||
11902 | VEC(breakpoint_p) * | |
11903 | all_tracepoints () | |
11904 | { | |
11905 | VEC(breakpoint_p) *tp_vec = 0; | |
11906 | struct breakpoint *tp; | |
11907 | ||
11908 | ALL_TRACEPOINTS (tp) | |
11909 | { | |
11910 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
11911 | } | |
11912 | ||
11913 | return tp_vec; | |
11914 | } | |
11915 | ||
c906108c | 11916 | \f |
4a64f543 MS |
11917 | /* This help string is used for the break, hbreak, tbreak and thbreak |
11918 | commands. It is defined as a macro to prevent duplication. | |
11919 | COMMAND should be a string constant containing the name of the | |
11920 | command. */ | |
31e2b00f AS |
11921 | #define BREAK_ARGS_HELP(command) \ |
11922 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
11923 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
11924 | If a line number is specified, break at start of code for that line.\n\ | |
11925 | If a function is specified, break at start of code for that function.\n\ | |
11926 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
11927 | With no LOCATION, uses current execution address of the selected\n\ |
11928 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
11929 | \n\ |
11930 | THREADNUM is the number from \"info threads\".\n\ | |
11931 | CONDITION is a boolean expression.\n\ | |
11932 | \n\ | |
d41c0fc8 PA |
11933 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
11934 | conditions are different.\n\ | |
31e2b00f AS |
11935 | \n\ |
11936 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
11937 | ||
44feb3ce TT |
11938 | /* List of subcommands for "catch". */ |
11939 | static struct cmd_list_element *catch_cmdlist; | |
11940 | ||
11941 | /* List of subcommands for "tcatch". */ | |
11942 | static struct cmd_list_element *tcatch_cmdlist; | |
11943 | ||
11944 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
11945 | lists, and pass some additional user data to the command function. */ | |
11946 | static void | |
11947 | add_catch_command (char *name, char *docstring, | |
11948 | void (*sfunc) (char *args, int from_tty, | |
11949 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
11950 | char **(*completer) (struct cmd_list_element *cmd, |
11951 | char *text, char *word), | |
44feb3ce TT |
11952 | void *user_data_catch, |
11953 | void *user_data_tcatch) | |
11954 | { | |
11955 | struct cmd_list_element *command; | |
11956 | ||
11957 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
11958 | &catch_cmdlist); | |
11959 | set_cmd_sfunc (command, sfunc); | |
11960 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 11961 | set_cmd_completer (command, completer); |
44feb3ce TT |
11962 | |
11963 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
11964 | &tcatch_cmdlist); | |
11965 | set_cmd_sfunc (command, sfunc); | |
11966 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 11967 | set_cmd_completer (command, completer); |
44feb3ce TT |
11968 | } |
11969 | ||
6c95b8df | 11970 | static void |
a79b8f6e | 11971 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 11972 | { |
6c95b8df PA |
11973 | inf->total_syscalls_count = 0; |
11974 | inf->any_syscall_count = 0; | |
11975 | VEC_free (int, inf->syscalls_counts); | |
11976 | } | |
11977 | ||
6149aea9 PA |
11978 | static void |
11979 | save_command (char *arg, int from_tty) | |
11980 | { | |
3e43a32a MS |
11981 | printf_unfiltered (_("\"save\" must be followed by " |
11982 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
11983 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
11984 | } | |
11985 | ||
84f4c1fe PM |
11986 | struct breakpoint * |
11987 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
11988 | void *data) | |
11989 | { | |
35df4500 | 11990 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 11991 | |
35df4500 | 11992 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
11993 | { |
11994 | if ((*callback) (b, data)) | |
11995 | return b; | |
11996 | } | |
11997 | ||
11998 | return NULL; | |
11999 | } | |
12000 | ||
c906108c | 12001 | void |
fba45db2 | 12002 | _initialize_breakpoint (void) |
c906108c SS |
12003 | { |
12004 | struct cmd_list_element *c; | |
12005 | ||
84acb35a | 12006 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 12007 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 12008 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 12009 | |
c906108c SS |
12010 | breakpoint_chain = 0; |
12011 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
12012 | before a breakpoint is set. */ | |
12013 | breakpoint_count = 0; | |
12014 | ||
1042e4c0 SS |
12015 | tracepoint_count = 0; |
12016 | ||
1bedd215 AC |
12017 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
12018 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
12019 | Usage is `ignore N COUNT'.")); | |
c906108c | 12020 | if (xdb_commands) |
c5aa993b | 12021 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 12022 | |
1bedd215 AC |
12023 | add_com ("commands", class_breakpoint, commands_command, _("\ |
12024 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
12025 | Give breakpoint number as argument after \"commands\".\n\ |
12026 | With no argument, the targeted breakpoint is the last one set.\n\ | |
12027 | The commands themselves follow starting on the next line.\n\ | |
12028 | Type a line containing \"end\" to indicate the end of them.\n\ | |
12029 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 12030 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 12031 | |
1bedd215 AC |
12032 | add_com ("condition", class_breakpoint, condition_command, _("\ |
12033 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 12034 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 12035 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 12036 | |
1bedd215 | 12037 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 12038 | Set a temporary breakpoint.\n\ |
c906108c SS |
12039 | Like \"break\" except the breakpoint is only temporary,\n\ |
12040 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
12041 | by using \"enable delete\" on the breakpoint number.\n\ |
12042 | \n" | |
12043 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 12044 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12045 | |
1bedd215 | 12046 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 12047 | Set a hardware assisted breakpoint.\n\ |
c906108c | 12048 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
12049 | some target hardware may not have this support.\n\ |
12050 | \n" | |
12051 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 12052 | set_cmd_completer (c, location_completer); |
c906108c | 12053 | |
1bedd215 | 12054 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 12055 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 12056 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
12057 | so it will be deleted when hit.\n\ |
12058 | \n" | |
12059 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 12060 | set_cmd_completer (c, location_completer); |
c906108c | 12061 | |
1bedd215 AC |
12062 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
12063 | Enable some breakpoints.\n\ | |
c906108c SS |
12064 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12065 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12066 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12067 | With a subcommand you can enable temporarily."), |
c906108c SS |
12068 | &enablelist, "enable ", 1, &cmdlist); |
12069 | if (xdb_commands) | |
1bedd215 AC |
12070 | add_com ("ab", class_breakpoint, enable_command, _("\ |
12071 | Enable some breakpoints.\n\ | |
c906108c SS |
12072 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12073 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12074 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12075 | With a subcommand you can enable temporarily.")); |
c906108c SS |
12076 | |
12077 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
12078 | ||
84951ab5 | 12079 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 12080 | Enable some breakpoints.\n\ |
c906108c SS |
12081 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12082 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12083 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 12084 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 12085 | |
1a966eab AC |
12086 | add_cmd ("once", no_class, enable_once_command, _("\ |
12087 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12088 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12089 | &enablebreaklist); |
12090 | ||
1a966eab AC |
12091 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12092 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12093 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12094 | &enablebreaklist); |
12095 | ||
1a966eab AC |
12096 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12097 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12098 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12099 | &enablelist); |
12100 | ||
1a966eab AC |
12101 | add_cmd ("once", no_class, enable_once_command, _("\ |
12102 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12103 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12104 | &enablelist); |
12105 | ||
1bedd215 AC |
12106 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
12107 | Disable some breakpoints.\n\ | |
c906108c SS |
12108 | Arguments are breakpoint numbers with spaces in between.\n\ |
12109 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12110 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
12111 | &disablelist, "disable ", 1, &cmdlist); |
12112 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
12113 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
12114 | if (xdb_commands) | |
1bedd215 AC |
12115 | add_com ("sb", class_breakpoint, disable_command, _("\ |
12116 | Disable some breakpoints.\n\ | |
c906108c SS |
12117 | Arguments are breakpoint numbers with spaces in between.\n\ |
12118 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12119 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 12120 | |
1a966eab AC |
12121 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
12122 | Disable some breakpoints.\n\ | |
c906108c SS |
12123 | Arguments are breakpoint numbers with spaces in between.\n\ |
12124 | To disable all breakpoints, give no argument.\n\ | |
12125 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 12126 | This command may be abbreviated \"disable\"."), |
c906108c SS |
12127 | &disablelist); |
12128 | ||
1bedd215 AC |
12129 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
12130 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12131 | Arguments are breakpoint numbers with spaces in between.\n\ |
12132 | To delete all breakpoints, give no argument.\n\ | |
12133 | \n\ | |
12134 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 12135 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
12136 | &deletelist, "delete ", 1, &cmdlist); |
12137 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 12138 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 12139 | if (xdb_commands) |
1bedd215 AC |
12140 | add_com ("db", class_breakpoint, delete_command, _("\ |
12141 | Delete some breakpoints.\n\ | |
c906108c | 12142 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 12143 | To delete all breakpoints, give no argument.\n")); |
c906108c | 12144 | |
1a966eab AC |
12145 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
12146 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12147 | Arguments are breakpoint numbers with spaces in between.\n\ |
12148 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 12149 | This command may be abbreviated \"delete\"."), |
c906108c SS |
12150 | &deletelist); |
12151 | ||
1bedd215 AC |
12152 | add_com ("clear", class_breakpoint, clear_command, _("\ |
12153 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
12154 | Argument may be line number, function name, or \"*\" and an address.\n\ |
12155 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
12156 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
12157 | If an address is specified, breakpoints at that address are cleared.\n\ |
12158 | \n\ | |
12159 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
12160 | is executing in.\n\ |
12161 | \n\ | |
1bedd215 | 12162 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 12163 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 12164 | |
1bedd215 | 12165 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
12166 | Set breakpoint at specified line or function.\n" |
12167 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 12168 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12169 | |
c906108c SS |
12170 | add_com_alias ("b", "break", class_run, 1); |
12171 | add_com_alias ("br", "break", class_run, 1); | |
12172 | add_com_alias ("bre", "break", class_run, 1); | |
12173 | add_com_alias ("brea", "break", class_run, 1); | |
12174 | ||
7681d515 PM |
12175 | if (xdb_commands) |
12176 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
12177 | |
12178 | if (dbx_commands) | |
12179 | { | |
1bedd215 AC |
12180 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
12181 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
12182 | &stoplist, "stop ", 1, &cmdlist); |
12183 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 12184 | _("Break in function or address."), &stoplist); |
c5aa993b | 12185 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 12186 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
12187 | add_com ("status", class_info, breakpoints_info, _("\ |
12188 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12189 | The \"Type\" column indicates one of:\n\ |
12190 | \tbreakpoint - normal breakpoint\n\ | |
12191 | \twatchpoint - watchpoint\n\ | |
12192 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12193 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12194 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12195 | address and file/line number respectively.\n\ |
12196 | \n\ | |
12197 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12198 | are set to the address of the last breakpoint listed unless the command\n\ |
12199 | is prefixed with \"server \".\n\n\ | |
c906108c | 12200 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12201 | breakpoint set.")); |
c906108c SS |
12202 | } |
12203 | ||
1bedd215 AC |
12204 | add_info ("breakpoints", breakpoints_info, _("\ |
12205 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12206 | The \"Type\" column indicates one of:\n\ |
12207 | \tbreakpoint - normal breakpoint\n\ | |
12208 | \twatchpoint - watchpoint\n\ | |
12209 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12210 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12211 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12212 | address and file/line number respectively.\n\ |
12213 | \n\ | |
12214 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12215 | are set to the address of the last breakpoint listed unless the command\n\ |
12216 | is prefixed with \"server \".\n\n\ | |
c906108c | 12217 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12218 | breakpoint set.")); |
c906108c | 12219 | |
6b04bdb7 MS |
12220 | add_info_alias ("b", "breakpoints", 1); |
12221 | ||
c906108c | 12222 | if (xdb_commands) |
1bedd215 AC |
12223 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
12224 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12225 | The \"Type\" column indicates one of:\n\ |
12226 | \tbreakpoint - normal breakpoint\n\ | |
12227 | \twatchpoint - watchpoint\n\ | |
12228 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
12229 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
12230 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
12231 | address and file/line number respectively.\n\ |
12232 | \n\ | |
12233 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12234 | are set to the address of the last breakpoint listed unless the command\n\ |
12235 | is prefixed with \"server \".\n\n\ | |
c906108c | 12236 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 12237 | breakpoint set.")); |
c906108c | 12238 | |
1a966eab AC |
12239 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
12240 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
12241 | The \"Type\" column indicates one of:\n\ |
12242 | \tbreakpoint - normal breakpoint\n\ | |
12243 | \twatchpoint - watchpoint\n\ | |
12244 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
12245 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
12246 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
12247 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
12248 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
12249 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
12250 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
12251 | address and file/line number respectively.\n\ |
12252 | \n\ | |
12253 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
12254 | are set to the address of the last breakpoint listed unless the command\n\ |
12255 | is prefixed with \"server \".\n\n\ | |
c906108c | 12256 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 12257 | breakpoint set."), |
c906108c SS |
12258 | &maintenanceinfolist); |
12259 | ||
44feb3ce TT |
12260 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
12261 | Set catchpoints to catch events."), | |
12262 | &catch_cmdlist, "catch ", | |
12263 | 0/*allow-unknown*/, &cmdlist); | |
12264 | ||
12265 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
12266 | Set temporary catchpoints to catch events."), | |
12267 | &tcatch_cmdlist, "tcatch ", | |
12268 | 0/*allow-unknown*/, &cmdlist); | |
12269 | ||
12270 | /* Add catch and tcatch sub-commands. */ | |
12271 | add_catch_command ("catch", _("\ | |
12272 | Catch an exception, when caught.\n\ | |
12273 | With an argument, catch only exceptions with the given name."), | |
12274 | catch_catch_command, | |
a96d9b2e | 12275 | NULL, |
44feb3ce TT |
12276 | CATCH_PERMANENT, |
12277 | CATCH_TEMPORARY); | |
12278 | add_catch_command ("throw", _("\ | |
12279 | Catch an exception, when thrown.\n\ | |
12280 | With an argument, catch only exceptions with the given name."), | |
12281 | catch_throw_command, | |
a96d9b2e | 12282 | NULL, |
44feb3ce TT |
12283 | CATCH_PERMANENT, |
12284 | CATCH_TEMPORARY); | |
12285 | add_catch_command ("fork", _("Catch calls to fork."), | |
12286 | catch_fork_command_1, | |
a96d9b2e | 12287 | NULL, |
44feb3ce TT |
12288 | (void *) (uintptr_t) catch_fork_permanent, |
12289 | (void *) (uintptr_t) catch_fork_temporary); | |
12290 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
12291 | catch_fork_command_1, | |
a96d9b2e | 12292 | NULL, |
44feb3ce TT |
12293 | (void *) (uintptr_t) catch_vfork_permanent, |
12294 | (void *) (uintptr_t) catch_vfork_temporary); | |
12295 | add_catch_command ("exec", _("Catch calls to exec."), | |
12296 | catch_exec_command_1, | |
a96d9b2e SDJ |
12297 | NULL, |
12298 | CATCH_PERMANENT, | |
12299 | CATCH_TEMPORARY); | |
12300 | add_catch_command ("syscall", _("\ | |
12301 | Catch system calls by their names and/or numbers.\n\ | |
12302 | Arguments say which system calls to catch. If no arguments\n\ | |
12303 | are given, every system call will be caught.\n\ | |
12304 | Arguments, if given, should be one or more system call names\n\ | |
12305 | (if your system supports that), or system call numbers."), | |
12306 | catch_syscall_command_1, | |
12307 | catch_syscall_completer, | |
44feb3ce TT |
12308 | CATCH_PERMANENT, |
12309 | CATCH_TEMPORARY); | |
44feb3ce TT |
12310 | add_catch_command ("exception", _("\ |
12311 | Catch Ada exceptions, when raised.\n\ | |
12312 | With an argument, catch only exceptions with the given name."), | |
12313 | catch_ada_exception_command, | |
a96d9b2e | 12314 | NULL, |
44feb3ce TT |
12315 | CATCH_PERMANENT, |
12316 | CATCH_TEMPORARY); | |
12317 | add_catch_command ("assert", _("\ | |
12318 | Catch failed Ada assertions, when raised.\n\ | |
12319 | With an argument, catch only exceptions with the given name."), | |
12320 | catch_assert_command, | |
a96d9b2e | 12321 | NULL, |
44feb3ce TT |
12322 | CATCH_PERMANENT, |
12323 | CATCH_TEMPORARY); | |
c5aa993b | 12324 | |
1bedd215 AC |
12325 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
12326 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12327 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 12328 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12329 | an expression changes.\n\ |
12330 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12331 | the memory to which it refers.")); | |
65d12d83 | 12332 | set_cmd_completer (c, expression_completer); |
c906108c | 12333 | |
1bedd215 AC |
12334 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
12335 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 12336 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 12337 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12338 | an expression is read.\n\ |
12339 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12340 | the memory to which it refers.")); | |
65d12d83 | 12341 | set_cmd_completer (c, expression_completer); |
c906108c | 12342 | |
1bedd215 AC |
12343 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
12344 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 12345 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 12346 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
12347 | an expression is either read or written.\n\ |
12348 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
12349 | the memory to which it refers.")); | |
65d12d83 | 12350 | set_cmd_completer (c, expression_completer); |
c906108c | 12351 | |
d77f58be SS |
12352 | add_info ("watchpoints", watchpoints_info, _("\ |
12353 | Status of watchpoints, or watchpoint number NUMBER.")); | |
12354 | ||
c906108c SS |
12355 | |
12356 | ||
920d2a44 AC |
12357 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
12358 | respond to changes - contrary to the description. */ | |
85c07804 AC |
12359 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
12360 | &can_use_hw_watchpoints, _("\ | |
12361 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
12362 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
12363 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
12364 | such is available. (However, any hardware watchpoints that were\n\ | |
12365 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
12366 | hardware.)"), |
12367 | NULL, | |
920d2a44 | 12368 | show_can_use_hw_watchpoints, |
85c07804 | 12369 | &setlist, &showlist); |
c906108c SS |
12370 | |
12371 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 12372 | |
1042e4c0 SS |
12373 | /* Tracepoint manipulation commands. */ |
12374 | ||
12375 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
12376 | Set a tracepoint at specified line or function.\n\ | |
12377 | \n" | |
12378 | BREAK_ARGS_HELP ("trace") "\n\ | |
12379 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12380 | set_cmd_completer (c, location_completer); | |
12381 | ||
12382 | add_com_alias ("tp", "trace", class_alias, 0); | |
12383 | add_com_alias ("tr", "trace", class_alias, 1); | |
12384 | add_com_alias ("tra", "trace", class_alias, 1); | |
12385 | add_com_alias ("trac", "trace", class_alias, 1); | |
12386 | ||
7a697b8d SS |
12387 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
12388 | Set a fast tracepoint at specified line or function.\n\ | |
12389 | \n" | |
12390 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
12391 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12392 | set_cmd_completer (c, location_completer); | |
12393 | ||
0fb4aa4b PA |
12394 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
12395 | Set a static tracepoint at specified line, function or marker.\n\ | |
12396 | \n\ | |
12397 | strace [LOCATION] [if CONDITION]\n\ | |
12398 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
12399 | or -m MARKER_ID.\n\ | |
12400 | If a line number is specified, probe the marker at start of code\n\ | |
12401 | for that line. If a function is specified, probe the marker at start\n\ | |
12402 | of code for that function. If an address is specified, probe the marker\n\ | |
12403 | at that exact address. If a marker id is specified, probe the marker\n\ | |
12404 | with that name. With no LOCATION, uses current execution address of\n\ | |
12405 | the selected stack frame.\n\ | |
12406 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
12407 | This collects arbitrary user data passed in the probe point call to the\n\ | |
12408 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
12409 | by printing the $_sdata variable like any other convenience variable.\n\ | |
12410 | \n\ | |
12411 | CONDITION is a boolean expression.\n\ | |
12412 | \n\ | |
d41c0fc8 PA |
12413 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
12414 | conditions are different.\n\ | |
0fb4aa4b PA |
12415 | \n\ |
12416 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
12417 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12418 | set_cmd_completer (c, location_completer); | |
12419 | ||
1042e4c0 SS |
12420 | add_info ("tracepoints", tracepoints_info, _("\ |
12421 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
12422 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
12423 | last tracepoint set.")); | |
12424 | ||
12425 | add_info_alias ("tp", "tracepoints", 1); | |
12426 | ||
12427 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
12428 | Delete specified tracepoints.\n\ | |
12429 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12430 | No argument means delete all tracepoints."), | |
12431 | &deletelist); | |
12432 | ||
12433 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
12434 | Disable specified tracepoints.\n\ | |
12435 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12436 | No argument means disable all tracepoints."), | |
12437 | &disablelist); | |
12438 | deprecate_cmd (c, "disable"); | |
12439 | ||
12440 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
12441 | Enable specified tracepoints.\n\ | |
12442 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12443 | No argument means enable all tracepoints."), | |
12444 | &enablelist); | |
12445 | deprecate_cmd (c, "enable"); | |
12446 | ||
12447 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
12448 | Set the passcount for a tracepoint.\n\ | |
12449 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
12450 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
12451 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
12452 | ||
6149aea9 PA |
12453 | add_prefix_cmd ("save", class_breakpoint, save_command, |
12454 | _("Save breakpoint definitions as a script."), | |
12455 | &save_cmdlist, "save ", | |
12456 | 0/*allow-unknown*/, &cmdlist); | |
12457 | ||
12458 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
12459 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 12460 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
12461 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
12462 | session to restore them."), | |
12463 | &save_cmdlist); | |
12464 | set_cmd_completer (c, filename_completer); | |
12465 | ||
12466 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 12467 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
12468 | Use the 'source' command in another debug session to restore them."), |
12469 | &save_cmdlist); | |
1042e4c0 SS |
12470 | set_cmd_completer (c, filename_completer); |
12471 | ||
6149aea9 PA |
12472 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
12473 | deprecate_cmd (c, "save tracepoints"); | |
12474 | ||
1bedd215 | 12475 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12476 | Breakpoint specific settings\n\ |
12477 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12478 | pending breakpoint behavior"), |
fa8d40ab JJ |
12479 | &breakpoint_set_cmdlist, "set breakpoint ", |
12480 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 12481 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12482 | Breakpoint specific settings\n\ |
12483 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12484 | pending breakpoint behavior"), |
fa8d40ab JJ |
12485 | &breakpoint_show_cmdlist, "show breakpoint ", |
12486 | 0/*allow-unknown*/, &showlist); | |
12487 | ||
7915a72c AC |
12488 | add_setshow_auto_boolean_cmd ("pending", no_class, |
12489 | &pending_break_support, _("\ | |
12490 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
12491 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
12492 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
12493 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
12494 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 12495 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 12496 | NULL, |
920d2a44 | 12497 | show_pending_break_support, |
6e1d7d6c AC |
12498 | &breakpoint_set_cmdlist, |
12499 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
12500 | |
12501 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
12502 | |
12503 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
12504 | &automatic_hardware_breakpoints, _("\ | |
12505 | Set automatic usage of hardware breakpoints."), _("\ | |
12506 | Show automatic usage of hardware breakpoints."), _("\ | |
12507 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
12508 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
12509 | a warning will be emitted for such breakpoints."), | |
12510 | NULL, | |
12511 | show_automatic_hardware_breakpoints, | |
12512 | &breakpoint_set_cmdlist, | |
12513 | &breakpoint_show_cmdlist); | |
74960c60 | 12514 | |
33e5cbd6 PA |
12515 | add_setshow_enum_cmd ("always-inserted", class_support, |
12516 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
12517 | Set mode for inserting breakpoints."), _("\ |
12518 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
12519 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
12520 | resumed, and removed when execution stops. When this mode is on,\n\ | |
12521 | breakpoints are inserted immediately and removed only when the user\n\ | |
12522 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
12523 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
12524 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
12525 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
12526 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
12527 | NULL, |
12528 | &show_always_inserted_mode, | |
12529 | &breakpoint_set_cmdlist, | |
12530 | &breakpoint_show_cmdlist); | |
765dc015 VP |
12531 | |
12532 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
12533 | |
12534 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 12535 | } |