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, |
4c38e0a4 | 5 | 2008, 2009, 2010 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 | |
44feb3ce | 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 | |
a14ed312 | 101 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 102 | |
98deb0da | 103 | static void break_command_1 (char *, int, int); |
c906108c | 104 | |
a14ed312 | 105 | static void mention (struct breakpoint *); |
c906108c | 106 | |
63c252f8 PM |
107 | /* This function is used in gdbtk sources and thus can not be made static. */ |
108 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, | |
a6d9a66e UW |
109 | struct symtab_and_line, |
110 | enum bptype); | |
c906108c | 111 | |
76897487 KB |
112 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
113 | ||
a6d9a66e UW |
114 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
115 | CORE_ADDR bpaddr, | |
88f7da05 | 116 | enum bptype bptype); |
76897487 | 117 | |
6c95b8df PA |
118 | static void describe_other_breakpoints (struct gdbarch *, |
119 | struct program_space *, CORE_ADDR, | |
5af949e3 | 120 | struct obj_section *, int); |
c906108c | 121 | |
6c95b8df PA |
122 | static int breakpoint_address_match (struct address_space *aspace1, |
123 | CORE_ADDR addr1, | |
124 | struct address_space *aspace2, | |
125 | CORE_ADDR addr2); | |
126 | ||
85d721b8 PA |
127 | static int watchpoint_locations_match (struct bp_location *loc1, |
128 | struct bp_location *loc2); | |
129 | ||
a14ed312 | 130 | static void breakpoints_info (char *, int); |
c906108c | 131 | |
d77f58be SS |
132 | static void watchpoints_info (char *, int); |
133 | ||
134 | static int breakpoint_1 (int, int, int (*) (const struct breakpoint *)); | |
c906108c | 135 | |
f431efe5 | 136 | static bpstat bpstat_alloc (struct bp_location *, bpstat); |
c906108c | 137 | |
4efb68b1 | 138 | static int breakpoint_cond_eval (void *); |
c906108c | 139 | |
4efb68b1 | 140 | static void cleanup_executing_breakpoints (void *); |
c906108c | 141 | |
a14ed312 | 142 | static void commands_command (char *, int); |
c906108c | 143 | |
a14ed312 | 144 | static void condition_command (char *, int); |
c906108c | 145 | |
a14ed312 | 146 | static int get_number_trailer (char **, int); |
c906108c | 147 | |
c5aa993b JM |
148 | typedef enum |
149 | { | |
150 | mark_inserted, | |
151 | mark_uninserted | |
152 | } | |
153 | insertion_state_t; | |
c906108c | 154 | |
0bde7532 | 155 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 156 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 157 | |
a14ed312 | 158 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
159 | |
160 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 161 | |
4efb68b1 | 162 | static int watchpoint_check (void *); |
c906108c | 163 | |
a14ed312 | 164 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 165 | |
a14ed312 | 166 | static int hw_breakpoint_used_count (void); |
c906108c | 167 | |
a14ed312 | 168 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 169 | |
a14ed312 | 170 | static void hbreak_command (char *, int); |
c906108c | 171 | |
a14ed312 | 172 | static void thbreak_command (char *, int); |
c906108c | 173 | |
a14ed312 | 174 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 175 | |
a14ed312 | 176 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 177 | |
a14ed312 | 178 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 179 | |
a14ed312 | 180 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 181 | |
a14ed312 | 182 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 183 | |
d85310f7 MS |
184 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
185 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 186 | |
a14ed312 | 187 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 188 | |
a14ed312 | 189 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 190 | |
d03285ec UW |
191 | static void detach_single_step_breakpoints (void); |
192 | ||
6c95b8df PA |
193 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
194 | CORE_ADDR pc); | |
1aafd4da | 195 | |
fe3f5fa8 | 196 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
197 | static void incref_bp_location (struct bp_location *loc); |
198 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 199 | |
39d61571 | 200 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 201 | |
b60e7edf | 202 | static void update_global_location_list (int); |
a5606eee | 203 | |
b60e7edf | 204 | static void update_global_location_list_nothrow (int); |
74960c60 | 205 | |
d77f58be | 206 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 | 207 | |
d77f58be | 208 | static int is_watchpoint (const struct breakpoint *bpt); |
60e1c644 | 209 | |
74960c60 | 210 | static void insert_breakpoint_locations (void); |
a5606eee | 211 | |
a96d9b2e SDJ |
212 | static int syscall_catchpoint_p (struct breakpoint *b); |
213 | ||
1042e4c0 SS |
214 | static void tracepoints_info (char *, int); |
215 | ||
216 | static void delete_trace_command (char *, int); | |
217 | ||
218 | static void enable_trace_command (char *, int); | |
219 | ||
220 | static void disable_trace_command (char *, int); | |
221 | ||
222 | static void trace_pass_command (char *, int); | |
223 | ||
0fb4aa4b PA |
224 | /* Assuming we're creating a static tracepoint, does S look like a |
225 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
226 | #define is_marker_spec(s) \ | |
227 | (strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) | |
228 | ||
5cea2a26 PA |
229 | /* A reference-counted struct command_line. This lets multiple |
230 | breakpoints share a single command list. */ | |
231 | struct counted_command_line | |
232 | { | |
233 | /* The reference count. */ | |
234 | int refc; | |
235 | ||
236 | /* The command list. */ | |
237 | struct command_line *commands; | |
238 | }; | |
239 | ||
240 | struct command_line * | |
241 | breakpoint_commands (struct breakpoint *b) | |
242 | { | |
243 | return b->commands ? b->commands->commands : NULL; | |
244 | } | |
3daf8fe5 | 245 | |
f3b1572e PA |
246 | /* Flag indicating that a command has proceeded the inferior past the |
247 | current breakpoint. */ | |
248 | ||
249 | static int breakpoint_proceeded; | |
250 | ||
2cec12e5 AR |
251 | static const char * |
252 | bpdisp_text (enum bpdisp disp) | |
253 | { | |
254 | /* NOTE: the following values are a part of MI protocol and represent | |
255 | values of 'disp' field returned when inferior stops at 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 | |
2cec12e5 | 261 | /* Prototypes for exported functions. */ |
c906108c SS |
262 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
263 | if such is available. */ | |
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 | { | |
271 | fprintf_filtered (file, _("\ | |
272 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
273 | value); | |
274 | } | |
275 | ||
fa8d40ab JJ |
276 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
277 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
278 | for unrecognized breakpoint locations. | |
279 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
280 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
281 | static void |
282 | show_pending_break_support (struct ui_file *file, int from_tty, | |
283 | struct cmd_list_element *c, | |
284 | const char *value) | |
285 | { | |
286 | fprintf_filtered (file, _("\ | |
287 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
288 | value); | |
289 | } | |
fa8d40ab | 290 | |
765dc015 VP |
291 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
292 | set with "break" but falling in read-only memory. | |
293 | If 0, gdb will warn about such breakpoints, but won't automatically | |
294 | use hardware breakpoints. */ | |
295 | static int automatic_hardware_breakpoints; | |
296 | static void | |
297 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
298 | struct cmd_list_element *c, | |
299 | const char *value) | |
300 | { | |
301 | fprintf_filtered (file, _("\ | |
302 | Automatic usage of hardware breakpoints is %s.\n"), | |
303 | value); | |
304 | } | |
305 | ||
33e5cbd6 PA |
306 | /* If on, gdb will keep breakpoints inserted even as inferior is |
307 | stopped, and immediately insert any new breakpoints. If off, gdb | |
308 | will insert breakpoints into inferior only when resuming it, and | |
309 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
310 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
311 | ||
312 | static const char always_inserted_auto[] = "auto"; | |
313 | static const char always_inserted_on[] = "on"; | |
314 | static const char always_inserted_off[] = "off"; | |
315 | static const char *always_inserted_enums[] = { | |
316 | always_inserted_auto, | |
317 | always_inserted_off, | |
318 | always_inserted_on, | |
319 | NULL | |
320 | }; | |
321 | static const char *always_inserted_mode = always_inserted_auto; | |
322 | static void | |
74960c60 | 323 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 324 | struct cmd_list_element *c, const char *value) |
74960c60 | 325 | { |
33e5cbd6 PA |
326 | if (always_inserted_mode == always_inserted_auto) |
327 | fprintf_filtered (file, _("\ | |
328 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
329 | value, | |
330 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
331 | else | |
332 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
333 | } |
334 | ||
33e5cbd6 PA |
335 | int |
336 | breakpoints_always_inserted_mode (void) | |
337 | { | |
338 | return (always_inserted_mode == always_inserted_on | |
339 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
340 | } | |
765dc015 | 341 | |
a14ed312 | 342 | void _initialize_breakpoint (void); |
c906108c | 343 | |
c906108c SS |
344 | /* Are we executing breakpoint commands? */ |
345 | static int executing_breakpoint_commands; | |
346 | ||
c02f5703 MS |
347 | /* Are overlay event breakpoints enabled? */ |
348 | static int overlay_events_enabled; | |
349 | ||
c906108c SS |
350 | /* Walk the following statement or block through all breakpoints. |
351 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
352 | breakpoint. */ | |
353 | ||
5c44784c | 354 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 355 | |
5c44784c JM |
356 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
357 | for (B = breakpoint_chain; \ | |
358 | B ? (TMP=B->next, 1): 0; \ | |
359 | B = TMP) | |
c906108c | 360 | |
876fa593 JK |
361 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
362 | provided so update_global_location_list must not be called while executing | |
363 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 364 | |
876fa593 JK |
365 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
366 | for (BP_TMP = bp_location; \ | |
367 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
368 | BP_TMP++) | |
7cc221ef | 369 | |
1042e4c0 SS |
370 | /* Iterator for tracepoints only. */ |
371 | ||
372 | #define ALL_TRACEPOINTS(B) \ | |
373 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 374 | if (is_tracepoint (B)) |
1042e4c0 | 375 | |
7cc221ef | 376 | /* Chains of all breakpoints defined. */ |
c906108c SS |
377 | |
378 | struct breakpoint *breakpoint_chain; | |
379 | ||
876fa593 JK |
380 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
381 | ||
382 | static struct bp_location **bp_location; | |
383 | ||
384 | /* Number of elements of BP_LOCATION. */ | |
385 | ||
386 | static unsigned bp_location_count; | |
387 | ||
388 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
389 | for the current elements of BP_LOCATION which get a valid result from | |
390 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
391 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
392 | ||
393 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
394 | ||
395 | /* Maximum offset plus alignment between | |
396 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
397 | the current elements of BP_LOCATION which get a valid result from | |
398 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
399 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
400 | ||
401 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 402 | |
20874c92 | 403 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 404 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
405 | may still be reported by a target. */ |
406 | VEC(bp_location_p) *moribund_locations = NULL; | |
407 | ||
c906108c SS |
408 | /* Number of last breakpoint made. */ |
409 | ||
95a42b64 TT |
410 | static int breakpoint_count; |
411 | ||
86b17b60 PA |
412 | /* The value of `breakpoint_count' before the last command that |
413 | created breakpoints. If the last (break-like) command created more | |
414 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
415 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
416 | static int prev_breakpoint_count; | |
c906108c | 417 | |
1042e4c0 SS |
418 | /* Number of last tracepoint made. */ |
419 | ||
95a42b64 | 420 | static int tracepoint_count; |
1042e4c0 | 421 | |
6149aea9 PA |
422 | static struct cmd_list_element *breakpoint_set_cmdlist; |
423 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 424 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 425 | |
468d015d JJ |
426 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
427 | static int | |
428 | breakpoint_enabled (struct breakpoint *b) | |
429 | { | |
0d381245 | 430 | return (b->enable_state == bp_enabled); |
468d015d JJ |
431 | } |
432 | ||
c906108c SS |
433 | /* Set breakpoint count to NUM. */ |
434 | ||
95a42b64 | 435 | static void |
fba45db2 | 436 | set_breakpoint_count (int num) |
c906108c | 437 | { |
86b17b60 | 438 | prev_breakpoint_count = breakpoint_count; |
c906108c | 439 | breakpoint_count = num; |
4fa62494 | 440 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
441 | } |
442 | ||
86b17b60 PA |
443 | /* Used by `start_rbreak_breakpoints' below, to record the current |
444 | breakpoint count before "rbreak" creates any breakpoint. */ | |
445 | static int rbreak_start_breakpoint_count; | |
446 | ||
95a42b64 TT |
447 | /* Called at the start an "rbreak" command to record the first |
448 | breakpoint made. */ | |
86b17b60 | 449 | |
95a42b64 TT |
450 | void |
451 | start_rbreak_breakpoints (void) | |
452 | { | |
86b17b60 | 453 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
454 | } |
455 | ||
456 | /* Called at the end of an "rbreak" command to record the last | |
457 | breakpoint made. */ | |
86b17b60 | 458 | |
95a42b64 TT |
459 | void |
460 | end_rbreak_breakpoints (void) | |
461 | { | |
86b17b60 | 462 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
463 | } |
464 | ||
c906108c SS |
465 | /* Used in run_command to zero the hit count when a new run starts. */ |
466 | ||
467 | void | |
fba45db2 | 468 | clear_breakpoint_hit_counts (void) |
c906108c SS |
469 | { |
470 | struct breakpoint *b; | |
471 | ||
472 | ALL_BREAKPOINTS (b) | |
473 | b->hit_count = 0; | |
474 | } | |
475 | ||
9add0f1b TT |
476 | /* Allocate a new counted_command_line with reference count of 1. |
477 | The new structure owns COMMANDS. */ | |
478 | ||
479 | static struct counted_command_line * | |
480 | alloc_counted_command_line (struct command_line *commands) | |
481 | { | |
482 | struct counted_command_line *result | |
483 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 484 | |
9add0f1b TT |
485 | result->refc = 1; |
486 | result->commands = commands; | |
487 | return result; | |
488 | } | |
489 | ||
490 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
491 | ||
492 | static void | |
493 | incref_counted_command_line (struct counted_command_line *cmd) | |
494 | { | |
495 | if (cmd) | |
496 | ++cmd->refc; | |
497 | } | |
498 | ||
499 | /* Decrement reference count. If the reference count reaches 0, | |
500 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
501 | nothing if *CMDP is NULL. */ | |
502 | ||
503 | static void | |
504 | decref_counted_command_line (struct counted_command_line **cmdp) | |
505 | { | |
506 | if (*cmdp) | |
507 | { | |
508 | if (--(*cmdp)->refc == 0) | |
509 | { | |
510 | free_command_lines (&(*cmdp)->commands); | |
511 | xfree (*cmdp); | |
512 | } | |
513 | *cmdp = NULL; | |
514 | } | |
515 | } | |
516 | ||
517 | /* A cleanup function that calls decref_counted_command_line. */ | |
518 | ||
519 | static void | |
520 | do_cleanup_counted_command_line (void *arg) | |
521 | { | |
522 | decref_counted_command_line (arg); | |
523 | } | |
524 | ||
525 | /* Create a cleanup that calls decref_counted_command_line on the | |
526 | argument. */ | |
527 | ||
528 | static struct cleanup * | |
529 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
530 | { | |
531 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
532 | } | |
533 | ||
c906108c SS |
534 | /* Default address, symtab and line to put a breakpoint at |
535 | for "break" command with no arg. | |
536 | if default_breakpoint_valid is zero, the other three are | |
537 | not valid, and "break" with no arg is an error. | |
538 | ||
539 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
540 | ||
541 | int default_breakpoint_valid; | |
542 | CORE_ADDR default_breakpoint_address; | |
543 | struct symtab *default_breakpoint_symtab; | |
544 | int default_breakpoint_line; | |
6c95b8df PA |
545 | struct program_space *default_breakpoint_pspace; |
546 | ||
c906108c SS |
547 | \f |
548 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
549 | Advance *PP after the string and any trailing whitespace. | |
550 | ||
551 | Currently the string can either be a number or "$" followed by the name | |
552 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 553 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
554 | |
555 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
556 | |
557 | TRAILER is a character which can be found after the number; most | |
558 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 559 | static int |
fba45db2 | 560 | get_number_trailer (char **pp, int trailer) |
c906108c | 561 | { |
5c44784c | 562 | int retval = 0; /* default */ |
c906108c SS |
563 | char *p = *pp; |
564 | ||
565 | if (p == NULL) | |
566 | /* Empty line means refer to the last breakpoint. */ | |
567 | return breakpoint_count; | |
568 | else if (*p == '$') | |
569 | { | |
570 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 571 | to pass to lookup_internalvar(). */ |
c906108c SS |
572 | char *varname; |
573 | char *start = ++p; | |
4fa62494 | 574 | LONGEST val; |
c906108c SS |
575 | |
576 | while (isalnum (*p) || *p == '_') | |
577 | p++; | |
578 | varname = (char *) alloca (p - start + 1); | |
579 | strncpy (varname, start, p - start); | |
580 | varname[p - start] = '\0'; | |
4fa62494 UW |
581 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
582 | retval = (int) val; | |
5c44784c JM |
583 | else |
584 | { | |
a3f17187 | 585 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
586 | retval = 0; |
587 | } | |
c906108c SS |
588 | } |
589 | else | |
590 | { | |
591 | if (*p == '-') | |
592 | ++p; | |
593 | while (*p >= '0' && *p <= '9') | |
594 | ++p; | |
595 | if (p == *pp) | |
596 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
597 | { |
598 | /* Skip non-numeric token */ | |
599 | while (*p && !isspace((int) *p)) | |
600 | ++p; | |
601 | /* Return zero, which caller must interpret as error. */ | |
602 | retval = 0; | |
603 | } | |
604 | else | |
605 | retval = atoi (*pp); | |
606 | } | |
607 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
608 | { | |
609 | /* Trailing junk: return 0 and let caller print error msg. */ | |
610 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
611 | ++p; | |
612 | retval = 0; | |
c906108c | 613 | } |
c906108c SS |
614 | while (isspace (*p)) |
615 | p++; | |
616 | *pp = p; | |
617 | return retval; | |
618 | } | |
5c44784c | 619 | |
11cf8741 | 620 | |
5c44784c JM |
621 | /* Like get_number_trailer, but don't allow a trailer. */ |
622 | int | |
fba45db2 | 623 | get_number (char **pp) |
5c44784c JM |
624 | { |
625 | return get_number_trailer (pp, '\0'); | |
626 | } | |
627 | ||
628 | /* Parse a number or a range. | |
629 | * A number will be of the form handled by get_number. | |
630 | * A range will be of the form <number1> - <number2>, and | |
631 | * will represent all the integers between number1 and number2, | |
632 | * inclusive. | |
633 | * | |
634 | * While processing a range, this fuction is called iteratively; | |
635 | * At each call it will return the next value in the range. | |
636 | * | |
637 | * At the beginning of parsing a range, the char pointer PP will | |
638 | * be advanced past <number1> and left pointing at the '-' token. | |
639 | * Subsequent calls will not advance the pointer until the range | |
640 | * is completed. The call that completes the range will advance | |
641 | * pointer PP past <number2>. | |
642 | */ | |
643 | ||
644 | int | |
fba45db2 | 645 | get_number_or_range (char **pp) |
5c44784c JM |
646 | { |
647 | static int last_retval, end_value; | |
648 | static char *end_ptr; | |
649 | static int in_range = 0; | |
650 | ||
651 | if (**pp != '-') | |
652 | { | |
653 | /* Default case: pp is pointing either to a solo number, | |
654 | or to the first number of a range. */ | |
655 | last_retval = get_number_trailer (pp, '-'); | |
656 | if (**pp == '-') | |
657 | { | |
658 | char **temp; | |
659 | ||
660 | /* This is the start of a range (<number1> - <number2>). | |
661 | Skip the '-', parse and remember the second number, | |
662 | and also remember the end of the final token. */ | |
663 | ||
664 | temp = &end_ptr; | |
665 | end_ptr = *pp + 1; | |
666 | while (isspace ((int) *end_ptr)) | |
667 | end_ptr++; /* skip white space */ | |
668 | end_value = get_number (temp); | |
669 | if (end_value < last_retval) | |
670 | { | |
8a3fe4f8 | 671 | error (_("inverted range")); |
5c44784c JM |
672 | } |
673 | else if (end_value == last_retval) | |
674 | { | |
675 | /* degenerate range (number1 == number2). Advance the | |
676 | token pointer so that the range will be treated as a | |
677 | single number. */ | |
678 | *pp = end_ptr; | |
679 | } | |
680 | else | |
681 | in_range = 1; | |
682 | } | |
683 | } | |
684 | else if (! in_range) | |
8a3fe4f8 | 685 | error (_("negative value")); |
5c44784c JM |
686 | else |
687 | { | |
688 | /* pp points to the '-' that betokens a range. All | |
689 | number-parsing has already been done. Return the next | |
690 | integer value (one greater than the saved previous value). | |
691 | Do not advance the token pointer 'pp' until the end of range | |
692 | is reached. */ | |
693 | ||
694 | if (++last_retval == end_value) | |
695 | { | |
696 | /* End of range reached; advance token pointer. */ | |
697 | *pp = end_ptr; | |
698 | in_range = 0; | |
699 | } | |
700 | } | |
701 | return last_retval; | |
702 | } | |
703 | ||
48cb2d85 VP |
704 | /* Return the breakpoint with the specified number, or NULL |
705 | if the number does not refer to an existing breakpoint. */ | |
706 | ||
707 | struct breakpoint * | |
708 | get_breakpoint (int num) | |
709 | { | |
710 | struct breakpoint *b; | |
711 | ||
712 | ALL_BREAKPOINTS (b) | |
713 | if (b->number == num) | |
714 | return b; | |
715 | ||
716 | return NULL; | |
717 | } | |
5c44784c | 718 | |
c906108c | 719 | \f |
adc36818 PM |
720 | |
721 | void | |
722 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
723 | int from_tty) | |
724 | { | |
725 | struct bp_location *loc = b->loc; | |
726 | ||
727 | for (; loc; loc = loc->next) | |
728 | { | |
729 | xfree (loc->cond); | |
730 | loc->cond = NULL; | |
731 | } | |
732 | xfree (b->cond_string); | |
733 | b->cond_string = NULL; | |
734 | xfree (b->cond_exp); | |
735 | b->cond_exp = NULL; | |
736 | ||
737 | if (*exp == 0) | |
738 | { | |
739 | if (from_tty) | |
740 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
741 | } | |
742 | else | |
743 | { | |
744 | char *arg = exp; | |
cc59ec59 | 745 | |
adc36818 PM |
746 | /* I don't know if it matters whether this is the string the user |
747 | typed in or the decompiled expression. */ | |
748 | b->cond_string = xstrdup (arg); | |
749 | b->condition_not_parsed = 0; | |
750 | ||
751 | if (is_watchpoint (b)) | |
752 | { | |
753 | innermost_block = NULL; | |
754 | arg = exp; | |
755 | b->cond_exp = parse_exp_1 (&arg, 0, 0); | |
756 | if (*arg) | |
757 | error (_("Junk at end of expression")); | |
758 | b->cond_exp_valid_block = innermost_block; | |
759 | } | |
760 | else | |
761 | { | |
762 | for (loc = b->loc; loc; loc = loc->next) | |
763 | { | |
764 | arg = exp; | |
765 | loc->cond = | |
766 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
767 | if (*arg) | |
768 | error (_("Junk at end of expression")); | |
769 | } | |
770 | } | |
771 | } | |
772 | breakpoints_changed (); | |
773 | observer_notify_breakpoint_modified (b->number); | |
774 | } | |
775 | ||
c906108c SS |
776 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
777 | ||
778 | static void | |
fba45db2 | 779 | condition_command (char *arg, int from_tty) |
c906108c | 780 | { |
52f0bd74 | 781 | struct breakpoint *b; |
c906108c | 782 | char *p; |
52f0bd74 | 783 | int bnum; |
c906108c SS |
784 | |
785 | if (arg == 0) | |
e2e0b3e5 | 786 | error_no_arg (_("breakpoint number")); |
c906108c SS |
787 | |
788 | p = arg; | |
789 | bnum = get_number (&p); | |
5c44784c | 790 | if (bnum == 0) |
8a3fe4f8 | 791 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
792 | |
793 | ALL_BREAKPOINTS (b) | |
794 | if (b->number == bnum) | |
2f069f6f | 795 | { |
2566ad2d | 796 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
797 | return; |
798 | } | |
c906108c | 799 | |
8a3fe4f8 | 800 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
801 | } |
802 | ||
a7bdde9e VP |
803 | /* Check that COMMAND do not contain commands that are suitable |
804 | only for tracepoints and not suitable for ordinary breakpoints. | |
805 | Throw if any such commands is found. | |
806 | */ | |
807 | static void | |
808 | check_no_tracepoint_commands (struct command_line *commands) | |
809 | { | |
810 | struct command_line *c; | |
cc59ec59 | 811 | |
a7bdde9e VP |
812 | for (c = commands; c; c = c->next) |
813 | { | |
814 | int i; | |
815 | ||
816 | if (c->control_type == while_stepping_control) | |
817 | error (_("The 'while-stepping' command can only be used for tracepoints")); | |
818 | ||
819 | for (i = 0; i < c->body_count; ++i) | |
820 | check_no_tracepoint_commands ((c->body_list)[i]); | |
821 | ||
822 | /* Not that command parsing removes leading whitespace and comment | |
823 | lines and also empty lines. So, we only need to check for | |
824 | command directly. */ | |
825 | if (strstr (c->line, "collect ") == c->line) | |
826 | error (_("The 'collect' command can only be used for tracepoints")); | |
827 | ||
51661e93 VP |
828 | if (strstr (c->line, "teval ") == c->line) |
829 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
830 | } |
831 | } | |
832 | ||
d77f58be SS |
833 | /* Encapsulate tests for different types of tracepoints. */ |
834 | ||
a7bdde9e | 835 | int |
d77f58be | 836 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 837 | { |
0fb4aa4b PA |
838 | return (b->type == bp_tracepoint |
839 | || b->type == bp_fast_tracepoint | |
840 | || b->type == bp_static_tracepoint); | |
a7bdde9e | 841 | } |
d77f58be | 842 | |
95a42b64 TT |
843 | /* A helper function that validsates that COMMANDS are valid for a |
844 | breakpoint. This function will throw an exception if a problem is | |
845 | found. */ | |
48cb2d85 | 846 | |
95a42b64 TT |
847 | static void |
848 | validate_commands_for_breakpoint (struct breakpoint *b, | |
849 | struct command_line *commands) | |
48cb2d85 | 850 | { |
d77f58be | 851 | if (is_tracepoint (b)) |
a7bdde9e VP |
852 | { |
853 | /* We need to verify that each top-level element of commands | |
854 | is valid for tracepoints, that there's at most one while-stepping | |
855 | element, and that while-stepping's body has valid tracing commands | |
856 | excluding nested while-stepping. */ | |
857 | struct command_line *c; | |
858 | struct command_line *while_stepping = 0; | |
859 | for (c = commands; c; c = c->next) | |
860 | { | |
a7bdde9e VP |
861 | if (c->control_type == while_stepping_control) |
862 | { | |
863 | if (b->type == bp_fast_tracepoint) | |
0fb4aa4b PA |
864 | error (_("\ |
865 | The 'while-stepping' command cannot be used for fast tracepoint")); | |
866 | else if (b->type == bp_static_tracepoint) | |
867 | error (_("\ | |
868 | The 'while-stepping' command cannot be used for static tracepoint")); | |
a7bdde9e VP |
869 | |
870 | if (while_stepping) | |
871 | error (_("The 'while-stepping' command can be used only once")); | |
872 | else | |
873 | while_stepping = c; | |
874 | } | |
875 | } | |
876 | if (while_stepping) | |
877 | { | |
878 | struct command_line *c2; | |
879 | ||
880 | gdb_assert (while_stepping->body_count == 1); | |
881 | c2 = while_stepping->body_list[0]; | |
882 | for (; c2; c2 = c2->next) | |
883 | { | |
a7bdde9e VP |
884 | if (c2->control_type == while_stepping_control) |
885 | error (_("The 'while-stepping' command cannot be nested")); | |
886 | } | |
887 | } | |
888 | } | |
889 | else | |
890 | { | |
891 | check_no_tracepoint_commands (commands); | |
892 | } | |
95a42b64 TT |
893 | } |
894 | ||
0fb4aa4b PA |
895 | /* Return a vector of all the static tracepoints set at ADDR. The |
896 | caller is responsible for releasing the vector. */ | |
897 | ||
898 | VEC(breakpoint_p) * | |
899 | static_tracepoints_here (CORE_ADDR addr) | |
900 | { | |
901 | struct breakpoint *b; | |
902 | VEC(breakpoint_p) *found = 0; | |
903 | struct bp_location *loc; | |
904 | ||
905 | ALL_BREAKPOINTS (b) | |
906 | if (b->type == bp_static_tracepoint) | |
907 | { | |
908 | for (loc = b->loc; loc; loc = loc->next) | |
909 | if (loc->address == addr) | |
910 | VEC_safe_push(breakpoint_p, found, b); | |
911 | } | |
912 | ||
913 | return found; | |
914 | } | |
915 | ||
95a42b64 TT |
916 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
917 | validate that only allowed commands are included. | |
918 | */ | |
919 | ||
920 | void | |
921 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
922 | { | |
923 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 924 | |
9add0f1b TT |
925 | decref_counted_command_line (&b->commands); |
926 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 VP |
927 | breakpoints_changed (); |
928 | observer_notify_breakpoint_modified (b->number); | |
929 | } | |
930 | ||
95a42b64 TT |
931 | void |
932 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
933 | { |
934 | struct breakpoint *b = closure; | |
cc59ec59 | 935 | |
a7bdde9e VP |
936 | validate_actionline (&line, b); |
937 | } | |
938 | ||
95a42b64 TT |
939 | /* A structure used to pass information through |
940 | map_breakpoint_numbers. */ | |
941 | ||
942 | struct commands_info | |
943 | { | |
944 | /* True if the command was typed at a tty. */ | |
945 | int from_tty; | |
86b17b60 PA |
946 | |
947 | /* The breakpoint range spec. */ | |
948 | char *arg; | |
949 | ||
95a42b64 TT |
950 | /* Non-NULL if the body of the commands are being read from this |
951 | already-parsed command. */ | |
952 | struct command_line *control; | |
86b17b60 | 953 | |
95a42b64 TT |
954 | /* The command lines read from the user, or NULL if they have not |
955 | yet been read. */ | |
956 | struct counted_command_line *cmd; | |
957 | }; | |
958 | ||
959 | /* A callback for map_breakpoint_numbers that sets the commands for | |
960 | commands_command. */ | |
961 | ||
c906108c | 962 | static void |
95a42b64 | 963 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 964 | { |
95a42b64 | 965 | struct commands_info *info = data; |
c906108c | 966 | |
95a42b64 TT |
967 | if (info->cmd == NULL) |
968 | { | |
969 | struct command_line *l; | |
5c44784c | 970 | |
95a42b64 TT |
971 | if (info->control != NULL) |
972 | l = copy_command_lines (info->control->body_list[0]); | |
973 | else | |
86b17b60 PA |
974 | { |
975 | struct cleanup *old_chain; | |
976 | char *str; | |
c5aa993b | 977 | |
86b17b60 PA |
978 | str = xstrprintf (_("Type commands for breakpoint(s) %s, one per line."), |
979 | info->arg); | |
980 | ||
981 | old_chain = make_cleanup (xfree, str); | |
982 | ||
983 | l = read_command_lines (str, | |
984 | info->from_tty, 1, | |
d77f58be | 985 | (is_tracepoint (b) |
86b17b60 PA |
986 | ? check_tracepoint_command : 0), |
987 | b); | |
988 | ||
989 | do_cleanups (old_chain); | |
990 | } | |
a7bdde9e | 991 | |
95a42b64 TT |
992 | info->cmd = alloc_counted_command_line (l); |
993 | } | |
994 | ||
995 | /* If a breakpoint was on the list more than once, we don't need to | |
996 | do anything. */ | |
997 | if (b->commands != info->cmd) | |
998 | { | |
999 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
1000 | incref_counted_command_line (info->cmd); | |
1001 | decref_counted_command_line (&b->commands); | |
1002 | b->commands = info->cmd; | |
1003 | breakpoints_changed (); | |
1004 | observer_notify_breakpoint_modified (b->number); | |
c5aa993b | 1005 | } |
95a42b64 TT |
1006 | } |
1007 | ||
1008 | static void | |
1009 | commands_command_1 (char *arg, int from_tty, struct command_line *control) | |
1010 | { | |
1011 | struct cleanup *cleanups; | |
1012 | struct commands_info info; | |
1013 | ||
1014 | info.from_tty = from_tty; | |
1015 | info.control = control; | |
1016 | info.cmd = NULL; | |
1017 | /* If we read command lines from the user, then `info' will hold an | |
1018 | extra reference to the commands that we must clean up. */ | |
1019 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
1020 | ||
1021 | if (arg == NULL || !*arg) | |
1022 | { | |
86b17b60 PA |
1023 | if (breakpoint_count - prev_breakpoint_count > 1) |
1024 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, breakpoint_count); | |
95a42b64 TT |
1025 | else if (breakpoint_count > 0) |
1026 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
1027 | else |
1028 | { | |
1029 | /* So that we don't try to free the incoming non-NULL | |
1030 | argument in the cleanup below. Mapping breakpoint | |
1031 | numbers will fail in this case. */ | |
1032 | arg = NULL; | |
1033 | } | |
95a42b64 | 1034 | } |
9766ced4 SS |
1035 | else |
1036 | /* The command loop has some static state, so we need to preserve | |
1037 | our argument. */ | |
1038 | arg = xstrdup (arg); | |
86b17b60 PA |
1039 | |
1040 | if (arg != NULL) | |
1041 | make_cleanup (xfree, arg); | |
1042 | ||
1043 | info.arg = arg; | |
95a42b64 TT |
1044 | |
1045 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
1046 | ||
1047 | if (info.cmd == NULL) | |
1048 | error (_("No breakpoints specified.")); | |
1049 | ||
1050 | do_cleanups (cleanups); | |
1051 | } | |
1052 | ||
1053 | static void | |
1054 | commands_command (char *arg, int from_tty) | |
1055 | { | |
1056 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 1057 | } |
40c03ae8 EZ |
1058 | |
1059 | /* Like commands_command, but instead of reading the commands from | |
1060 | input stream, takes them from an already parsed command structure. | |
1061 | ||
1062 | This is used by cli-script.c to DTRT with breakpoint commands | |
1063 | that are part of if and while bodies. */ | |
1064 | enum command_control_type | |
1065 | commands_from_control_command (char *arg, struct command_line *cmd) | |
1066 | { | |
95a42b64 TT |
1067 | commands_command_1 (arg, 0, cmd); |
1068 | return simple_control; | |
40c03ae8 | 1069 | } |
876fa593 JK |
1070 | |
1071 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
1072 | ||
1073 | static int | |
1074 | bp_location_has_shadow (struct bp_location *bl) | |
1075 | { | |
1076 | if (bl->loc_type != bp_loc_software_breakpoint) | |
1077 | return 0; | |
1078 | if (!bl->inserted) | |
1079 | return 0; | |
1080 | if (bl->target_info.shadow_len == 0) | |
1081 | /* bp isn't valid, or doesn't shadow memory. */ | |
1082 | return 0; | |
1083 | return 1; | |
1084 | } | |
1085 | ||
8defab1a | 1086 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
1087 | by replacing any memory breakpoints with their shadowed contents. |
1088 | ||
1089 | The range of shadowed area by each bp_location is: | |
1090 | b->address - bp_location_placed_address_before_address_max | |
1091 | up to b->address + bp_location_shadow_len_after_address_max | |
1092 | The range we were requested to resolve shadows for is: | |
1093 | memaddr ... memaddr + len | |
1094 | Thus the safe cutoff boundaries for performance optimization are | |
1095 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
1096 | and: | |
1097 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 1098 | |
8defab1a DJ |
1099 | void |
1100 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1101 | { |
876fa593 JK |
1102 | /* Left boundary, right boundary and median element of our binary search. */ |
1103 | unsigned bc_l, bc_r, bc; | |
1104 | ||
1105 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
1106 | safe to report lower value but a failure to report higher one. */ | |
1107 | ||
1108 | bc_l = 0; | |
1109 | bc_r = bp_location_count; | |
1110 | while (bc_l + 1 < bc_r) | |
1111 | { | |
1112 | struct bp_location *b; | |
1113 | ||
1114 | bc = (bc_l + bc_r) / 2; | |
1115 | b = bp_location[bc]; | |
1116 | ||
1117 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
1118 | Then advance the left boundary only if we are sure the BC element can | |
1119 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
1120 | ||
1121 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
1122 | we cannot miss a breakpoint with its shadow range tail still reaching | |
1123 | MEMADDR. */ | |
c5aa993b | 1124 | |
876fa593 JK |
1125 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
1126 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
1127 | bc_l = bc; | |
1128 | else | |
1129 | bc_r = bc; | |
1130 | } | |
1131 | ||
1132 | /* Now do full processing of the found relevant range of elements. */ | |
1133 | ||
1134 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1135 | { |
876fa593 JK |
1136 | struct bp_location *b = bp_location[bc]; |
1137 | CORE_ADDR bp_addr = 0; | |
1138 | int bp_size = 0; | |
1139 | int bptoffset = 0; | |
1140 | ||
2bdf28a0 | 1141 | /* bp_location array has B->OWNER always non-NULL. */ |
ffce0d52 | 1142 | if (b->owner->type == bp_none) |
8a3fe4f8 | 1143 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
1144 | b->owner->number); |
1145 | ||
876fa593 JK |
1146 | /* Performance optimization: any futher element can no longer affect BUF |
1147 | content. */ | |
1148 | ||
1149 | if (b->address >= bp_location_placed_address_before_address_max | |
1150 | && memaddr + len <= b->address | |
1151 | - bp_location_placed_address_before_address_max) | |
1152 | break; | |
1153 | ||
1154 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 1155 | continue; |
6c95b8df PA |
1156 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
1157 | current_program_space->aspace, 0)) | |
1158 | continue; | |
1159 | ||
c5aa993b JM |
1160 | /* Addresses and length of the part of the breakpoint that |
1161 | we need to copy. */ | |
8181d85f DJ |
1162 | bp_addr = b->target_info.placed_address; |
1163 | bp_size = b->target_info.shadow_len; | |
8defab1a | 1164 | |
c5aa993b JM |
1165 | if (bp_addr + bp_size <= memaddr) |
1166 | /* The breakpoint is entirely before the chunk of memory we | |
1167 | are reading. */ | |
1168 | continue; | |
8defab1a | 1169 | |
c5aa993b JM |
1170 | if (bp_addr >= memaddr + len) |
1171 | /* The breakpoint is entirely after the chunk of memory we are | |
1172 | reading. */ | |
1173 | continue; | |
c5aa993b | 1174 | |
8defab1a DJ |
1175 | /* Offset within shadow_contents. */ |
1176 | if (bp_addr < memaddr) | |
1177 | { | |
1178 | /* Only copy the second part of the breakpoint. */ | |
1179 | bp_size -= memaddr - bp_addr; | |
1180 | bptoffset = memaddr - bp_addr; | |
1181 | bp_addr = memaddr; | |
1182 | } | |
c5aa993b | 1183 | |
8defab1a DJ |
1184 | if (bp_addr + bp_size > memaddr + len) |
1185 | { | |
1186 | /* Only copy the first part of the breakpoint. */ | |
1187 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1188 | } | |
c5aa993b | 1189 | |
8defab1a DJ |
1190 | memcpy (buf + bp_addr - memaddr, |
1191 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 1192 | } |
c906108c | 1193 | } |
c906108c | 1194 | \f |
c5aa993b | 1195 | |
687595f9 | 1196 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 1197 | static void |
687595f9 DJ |
1198 | insert_catchpoint (struct ui_out *uo, void *args) |
1199 | { | |
1200 | struct breakpoint *b = (struct breakpoint *) args; | |
687595f9 | 1201 | |
fe798b75 JB |
1202 | gdb_assert (b->type == bp_catchpoint); |
1203 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
1204 | ||
1205 | b->ops->insert (b); | |
687595f9 DJ |
1206 | } |
1207 | ||
60e1c644 PA |
1208 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1209 | ||
a5606eee | 1210 | static int |
d77f58be | 1211 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1212 | { |
1213 | return (bpt->type == bp_hardware_watchpoint | |
1214 | || bpt->type == bp_read_watchpoint | |
1215 | || bpt->type == bp_access_watchpoint); | |
1216 | } | |
7270d8f2 | 1217 | |
60e1c644 PA |
1218 | /* Return true if BPT is of any watchpoint kind, hardware or |
1219 | software. */ | |
1220 | ||
1221 | static int | |
d77f58be | 1222 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1223 | { |
1224 | return (is_hardware_watchpoint (bpt) | |
1225 | || bpt->type == bp_watchpoint); | |
1226 | } | |
1227 | ||
f6bc2008 PA |
1228 | /* Assuming that B is a watchpoint: returns true if the current thread |
1229 | and its running state are safe to evaluate or update watchpoint B. | |
1230 | Watchpoints on local expressions need to be evaluated in the | |
1231 | context of the thread that was current when the watchpoint was | |
1232 | created, and, that thread needs to be stopped to be able to select | |
1233 | the correct frame context. Watchpoints on global expressions can | |
1234 | be evaluated on any thread, and in any state. It is presently left | |
1235 | to the target allowing memory accesses when threads are | |
1236 | running. */ | |
1237 | ||
1238 | static int | |
1239 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1240 | { | |
1241 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1242 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1243 | && !is_executing (inferior_ptid))); | |
1244 | } | |
1245 | ||
567e1b4e JB |
1246 | /* Assuming that B is a watchpoint: |
1247 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1248 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1249 | - Evaluate the condition if there is one, and store the result |
1250 | in b->loc->cond. | |
a5606eee VP |
1251 | - Update the list of values that must be watched in B->loc. |
1252 | ||
bfa149ac | 1253 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1254 | If this is local watchpoint that is out of scope, delete it. |
1255 | ||
1256 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1257 | + inserted on each stop here. Normal breakpoints must never be removed | |
1258 | because they might be missed by a running thread when debugging in non-stop | |
1259 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1260 | processed here) are specific to each LWP since they are stored in each LWP's | |
1261 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1262 | order to be able to modify its hardware watchpoints. | |
1263 | ||
1264 | Hardware watchpoints must be reset exactly once after being presented to the | |
1265 | user. It cannot be done sooner, because it would reset the data used to | |
1266 | present the watchpoint hit to the user. And it must not be done later | |
1267 | because it could display the same single watchpoint hit during multiple GDB | |
1268 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1269 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1270 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1271 | memory content has not changed. | |
1272 | ||
1273 | The following constraints influence the location where we can reset hardware | |
1274 | watchpoints: | |
1275 | ||
1276 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1277 | several times when GDB stops. | |
1278 | ||
1279 | [linux] | |
1280 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1281 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1282 | reason for stopping, and all the other hits are presented later, one after | |
1283 | the other, each time the user requests the execution to be resumed. | |
1284 | Execution is not resumed for the threads still having pending hit event | |
1285 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1286 | the inferior on the first stop the thread hit event is kept being reported | |
1287 | from its cached value by linux_nat_stopped_data_address until the real | |
1288 | thread resume happens after the watchpoint gets presented and thus its | |
1289 | LWP_INFO->STATUS gets reset. | |
1290 | ||
1291 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1292 | removal from inferior. */ | |
1293 | ||
b40ce68a | 1294 | static void |
a5606eee | 1295 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1296 | { |
a5606eee | 1297 | int within_current_scope; |
a5606eee | 1298 | struct frame_id saved_frame_id; |
66076460 | 1299 | int frame_saved; |
a5606eee | 1300 | |
f6bc2008 PA |
1301 | /* If this is a local watchpoint, we only want to check if the |
1302 | watchpoint frame is in scope if the current thread is the thread | |
1303 | that was used to create the watchpoint. */ | |
1304 | if (!watchpoint_in_thread_scope (b)) | |
1305 | return; | |
1306 | ||
876fa593 | 1307 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1308 | update_global_locations will eventually delete them and remove |
1309 | breakpoints if needed. */ | |
a5606eee VP |
1310 | b->loc = NULL; |
1311 | ||
1312 | if (b->disposition == disp_del_at_next_stop) | |
1313 | return; | |
1314 | ||
66076460 | 1315 | frame_saved = 0; |
a5606eee VP |
1316 | |
1317 | /* Determine if the watchpoint is within scope. */ | |
1318 | if (b->exp_valid_block == NULL) | |
1319 | within_current_scope = 1; | |
1320 | else | |
1321 | { | |
1322 | struct frame_info *fi; | |
66076460 DJ |
1323 | |
1324 | /* Save the current frame's ID so we can restore it after | |
1325 | evaluating the watchpoint expression on its own frame. */ | |
1326 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1327 | took a frame parameter, so that we didn't have to change the | |
1328 | selected frame. */ | |
1329 | frame_saved = 1; | |
1330 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1331 | ||
a5606eee VP |
1332 | fi = frame_find_by_id (b->watchpoint_frame); |
1333 | within_current_scope = (fi != NULL); | |
1334 | if (within_current_scope) | |
1335 | select_frame (fi); | |
1336 | } | |
1337 | ||
1338 | if (within_current_scope && reparse) | |
1339 | { | |
1340 | char *s; | |
d63d0675 | 1341 | |
a5606eee VP |
1342 | if (b->exp) |
1343 | { | |
1344 | xfree (b->exp); | |
1345 | b->exp = NULL; | |
1346 | } | |
d63d0675 | 1347 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1348 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1349 | /* If the meaning of expression itself changed, the old value is | |
1350 | no longer relevant. We don't want to report a watchpoint hit | |
1351 | to the user when the old value and the new value may actually | |
1352 | be completely different objects. */ | |
1353 | value_free (b->val); | |
fa4727a6 DJ |
1354 | b->val = NULL; |
1355 | b->val_valid = 0; | |
60e1c644 PA |
1356 | |
1357 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1358 | expression is stored in the breakpoint object, not in the | |
1359 | locations (re)created below. */ | |
1360 | if (b->cond_string != NULL) | |
1361 | { | |
1362 | if (b->cond_exp != NULL) | |
1363 | { | |
1364 | xfree (b->cond_exp); | |
1365 | b->cond_exp = NULL; | |
1366 | } | |
1367 | ||
1368 | s = b->cond_string; | |
1369 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1370 | } | |
a5606eee | 1371 | } |
a5606eee VP |
1372 | |
1373 | /* If we failed to parse the expression, for example because | |
1374 | it refers to a global variable in a not-yet-loaded shared library, | |
1375 | don't try to insert watchpoint. We don't automatically delete | |
1376 | such watchpoint, though, since failure to parse expression | |
1377 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1378 | if ( !target_has_execution) |
1379 | { | |
1380 | /* Without execution, memory can't change. No use to try and | |
1381 | set watchpoint locations. The watchpoint will be reset when | |
1382 | the target gains execution, through breakpoint_re_set. */ | |
1383 | } | |
1384 | else if (within_current_scope && b->exp) | |
a5606eee | 1385 | { |
0cf6dd15 | 1386 | int pc = 0; |
fa4727a6 | 1387 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1388 | struct program_space *frame_pspace; |
a5606eee | 1389 | |
0cf6dd15 | 1390 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1391 | |
a5606eee VP |
1392 | /* Avoid setting b->val if it's already set. The meaning of |
1393 | b->val is 'the last value' user saw, and we should update | |
1394 | it only if we reported that last value to user. As it | |
1395 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1396 | if (!b->val_valid) |
1397 | { | |
1398 | b->val = v; | |
1399 | b->val_valid = 1; | |
1400 | } | |
a5606eee | 1401 | |
db2ad4c3 JK |
1402 | /* Change the type of breakpoint between hardware assisted or an |
1403 | ordinary watchpoint depending on the hardware support and free | |
1404 | hardware slots. REPARSE is set when the inferior is started. */ | |
1405 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1406 | && reparse) | |
1407 | { | |
ca2d49e8 | 1408 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1409 | |
7b838ca2 TJB |
1410 | /* We need to determine how many resources are already used |
1411 | for all other hardware watchpoints to see if we still have | |
1412 | enough resources to also fit this watchpoint in as well. | |
1413 | To avoid the hw_watchpoint_used_count call below from counting | |
1414 | this watchpoint, make sure that it is marked as a software | |
1415 | watchpoint. */ | |
1416 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1417 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1418 | &other_type_used); | |
1419 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1420 | ||
ca2d49e8 | 1421 | if (!mem_cnt) |
db2ad4c3 JK |
1422 | b->type = bp_watchpoint; |
1423 | else | |
ca2d49e8 | 1424 | { |
d92524f1 | 1425 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1426 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1427 | if (target_resources_ok <= 0) | |
1428 | b->type = bp_watchpoint; | |
1429 | else | |
1430 | b->type = bp_hardware_watchpoint; | |
1431 | } | |
db2ad4c3 JK |
1432 | } |
1433 | ||
2d134ed3 PA |
1434 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1435 | ||
a5606eee | 1436 | /* Look at each value on the value chain. */ |
fa4727a6 | 1437 | for (v = val_chain; v; v = next) |
a5606eee VP |
1438 | { |
1439 | /* If it's a memory location, and GDB actually needed | |
1440 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1441 | must watch it. If the first value returned is |
1442 | still lazy, that means an error occurred reading it; | |
1443 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1444 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1445 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1446 | { |
1447 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1448 | |
a5606eee VP |
1449 | /* We only watch structs and arrays if user asked |
1450 | for it explicitly, never if they just happen to | |
1451 | appear in the middle of some value chain. */ | |
fa4727a6 | 1452 | if (v == result |
a5606eee VP |
1453 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1454 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1455 | { | |
1456 | CORE_ADDR addr; | |
1457 | int len, type; | |
1458 | struct bp_location *loc, **tmp; | |
1459 | ||
42ae5230 | 1460 | addr = value_address (v); |
a5606eee VP |
1461 | len = TYPE_LENGTH (value_type (v)); |
1462 | type = hw_write; | |
1463 | if (b->type == bp_read_watchpoint) | |
1464 | type = hw_read; | |
1465 | else if (b->type == bp_access_watchpoint) | |
1466 | type = hw_access; | |
1467 | ||
39d61571 | 1468 | loc = allocate_bp_location (b); |
a5606eee VP |
1469 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1470 | ; | |
1471 | *tmp = loc; | |
a6d9a66e | 1472 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1473 | |
1474 | loc->pspace = frame_pspace; | |
a5606eee VP |
1475 | loc->address = addr; |
1476 | loc->length = len; | |
1477 | loc->watchpoint_type = type; | |
1478 | } | |
1479 | } | |
1480 | ||
1481 | next = value_next (v); | |
1482 | if (v != b->val) | |
1483 | value_free (v); | |
1484 | } | |
1485 | ||
c7437ca6 PA |
1486 | /* If a software watchpoint is not watching any memory, then the |
1487 | above left it without any location set up. But, | |
1488 | bpstat_stop_status requires a location to be able to report | |
1489 | stops, so make sure there's at least a dummy one. */ | |
1490 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1491 | { | |
1492 | b->loc = allocate_bp_location (b); | |
1493 | b->loc->pspace = frame_pspace; | |
1494 | b->loc->address = -1; | |
1495 | b->loc->length = -1; | |
1496 | b->loc->watchpoint_type = -1; | |
1497 | } | |
a5606eee VP |
1498 | } |
1499 | else if (!within_current_scope) | |
7270d8f2 | 1500 | { |
a5606eee | 1501 | printf_filtered (_("\ |
cce7e648 | 1502 | Watchpoint %d deleted because the program has left the block\n\ |
a5606eee VP |
1503 | in which its expression is valid.\n"), |
1504 | b->number); | |
1505 | if (b->related_breakpoint) | |
60e1c644 PA |
1506 | { |
1507 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1508 | b->related_breakpoint->related_breakpoint = NULL; | |
1509 | b->related_breakpoint= NULL; | |
1510 | } | |
a5606eee | 1511 | b->disposition = disp_del_at_next_stop; |
7270d8f2 | 1512 | } |
a5606eee VP |
1513 | |
1514 | /* Restore the selected frame. */ | |
66076460 DJ |
1515 | if (frame_saved) |
1516 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1517 | } |
1518 | ||
a5606eee | 1519 | |
74960c60 VP |
1520 | /* Returns 1 iff breakpoint location should be |
1521 | inserted in the inferior. */ | |
1522 | static int | |
1523 | should_be_inserted (struct bp_location *bpt) | |
1524 | { | |
2bdf28a0 | 1525 | if (bpt->owner == NULL || !breakpoint_enabled (bpt->owner)) |
74960c60 VP |
1526 | return 0; |
1527 | ||
1528 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1529 | return 0; | |
1530 | ||
1531 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1532 | return 0; | |
1533 | ||
56710373 PA |
1534 | /* This is set for example, when we're attached to the parent of a |
1535 | vfork, and have detached from the child. The child is running | |
1536 | free, and we expect it to do an exec or exit, at which point the | |
1537 | OS makes the parent schedulable again (and the target reports | |
1538 | that the vfork is done). Until the child is done with the shared | |
1539 | memory region, do not insert breakpoints in the parent, otherwise | |
1540 | the child could still trip on the parent's breakpoints. Since | |
1541 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1542 | if (bpt->pspace->breakpoints_not_allowed) | |
1543 | return 0; | |
1544 | ||
1042e4c0 SS |
1545 | /* Tracepoints are inserted by the target at a time of its choosing, |
1546 | not by us. */ | |
d77f58be | 1547 | if (is_tracepoint (bpt->owner)) |
1042e4c0 SS |
1548 | return 0; |
1549 | ||
74960c60 VP |
1550 | return 1; |
1551 | } | |
1552 | ||
879bfdc2 DJ |
1553 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1554 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1555 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1556 | |
1557 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1558 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1559 | static int |
879bfdc2 | 1560 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1561 | struct ui_file *tmp_error_stream, |
fa3a767f | 1562 | int *disabled_breaks, |
26bb91f3 | 1563 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1564 | { |
1565 | int val = 0; | |
1566 | ||
74960c60 | 1567 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1568 | return 0; |
1569 | ||
8181d85f DJ |
1570 | /* Initialize the target-specific information. */ |
1571 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1572 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1573 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1574 | |
879bfdc2 DJ |
1575 | if (bpt->loc_type == bp_loc_software_breakpoint |
1576 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1577 | { | |
765dc015 VP |
1578 | if (bpt->owner->type != bp_hardware_breakpoint) |
1579 | { | |
1580 | /* If the explicitly specified breakpoint type | |
1581 | is not hardware breakpoint, check the memory map to see | |
1582 | if the breakpoint address is in read only memory or not. | |
1583 | Two important cases are: | |
1584 | - location type is not hardware breakpoint, memory | |
1585 | is readonly. We change the type of the location to | |
1586 | hardware breakpoint. | |
1587 | - location type is hardware breakpoint, memory is read-write. | |
1588 | This means we've previously made the location hardware one, but | |
1589 | then the memory map changed, so we undo. | |
1590 | ||
1591 | When breakpoints are removed, remove_breakpoints will | |
1592 | use location types we've just set here, the only possible | |
1593 | problem is that memory map has changed during running program, | |
1594 | but it's not going to work anyway with current gdb. */ | |
1595 | struct mem_region *mr | |
1596 | = lookup_mem_region (bpt->target_info.placed_address); | |
1597 | ||
1598 | if (mr) | |
1599 | { | |
1600 | if (automatic_hardware_breakpoints) | |
1601 | { | |
765dc015 VP |
1602 | enum bp_loc_type new_type; |
1603 | ||
1604 | if (mr->attrib.mode != MEM_RW) | |
1605 | new_type = bp_loc_hardware_breakpoint; | |
1606 | else | |
1607 | new_type = bp_loc_software_breakpoint; | |
1608 | ||
1609 | if (new_type != bpt->loc_type) | |
1610 | { | |
1611 | static int said = 0; | |
cc59ec59 | 1612 | |
765dc015 VP |
1613 | bpt->loc_type = new_type; |
1614 | if (!said) | |
1615 | { | |
1616 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1617 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1618 | said = 1; |
1619 | } | |
1620 | } | |
1621 | } | |
1622 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1623 | && mr->attrib.mode != MEM_RW) | |
1624 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1625 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1626 | } |
1627 | } | |
1628 | ||
879bfdc2 DJ |
1629 | /* First check to see if we have to handle an overlay. */ |
1630 | if (overlay_debugging == ovly_off | |
1631 | || bpt->section == NULL | |
1632 | || !(section_is_overlay (bpt->section))) | |
1633 | { | |
1634 | /* No overlay handling: just set the breakpoint. */ | |
1635 | ||
1636 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1637 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1638 | &bpt->target_info); | |
879bfdc2 | 1639 | else |
a6d9a66e UW |
1640 | val = target_insert_breakpoint (bpt->gdbarch, |
1641 | &bpt->target_info); | |
879bfdc2 DJ |
1642 | } |
1643 | else | |
1644 | { | |
1645 | /* This breakpoint is in an overlay section. | |
1646 | Shall we set a breakpoint at the LMA? */ | |
1647 | if (!overlay_events_enabled) | |
1648 | { | |
1649 | /* Yes -- overlay event support is not active, | |
1650 | so we must try to set a breakpoint at the LMA. | |
1651 | This will not work for a hardware breakpoint. */ | |
1652 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1653 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1654 | bpt->owner->number); |
1655 | else | |
1656 | { | |
1657 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1658 | bpt->section); | |
1659 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1660 | bpt->overlay_target_info = bpt->target_info; |
1661 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1662 | val = target_insert_breakpoint (bpt->gdbarch, |
1663 | &bpt->overlay_target_info); | |
879bfdc2 | 1664 | if (val != 0) |
99361f52 DE |
1665 | fprintf_unfiltered (tmp_error_stream, |
1666 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1667 | bpt->owner->number); |
1668 | } | |
1669 | } | |
1670 | /* Shall we set a breakpoint at the VMA? */ | |
1671 | if (section_is_mapped (bpt->section)) | |
1672 | { | |
1673 | /* Yes. This overlay section is mapped into memory. */ | |
1674 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1675 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1676 | &bpt->target_info); | |
879bfdc2 | 1677 | else |
a6d9a66e UW |
1678 | val = target_insert_breakpoint (bpt->gdbarch, |
1679 | &bpt->target_info); | |
879bfdc2 DJ |
1680 | } |
1681 | else | |
1682 | { | |
1683 | /* No. This breakpoint will not be inserted. | |
1684 | No error, but do not mark the bp as 'inserted'. */ | |
1685 | return 0; | |
1686 | } | |
1687 | } | |
1688 | ||
1689 | if (val) | |
1690 | { | |
1691 | /* Can't set the breakpoint. */ | |
6c95b8df | 1692 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1693 | { |
1694 | /* See also: disable_breakpoints_in_shlibs. */ | |
1695 | val = 0; | |
0d381245 | 1696 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1697 | if (!*disabled_breaks) |
1698 | { | |
1699 | fprintf_unfiltered (tmp_error_stream, | |
1700 | "Cannot insert breakpoint %d.\n", | |
1701 | bpt->owner->number); | |
1702 | fprintf_unfiltered (tmp_error_stream, | |
1703 | "Temporarily disabling shared library breakpoints:\n"); | |
1704 | } | |
1705 | *disabled_breaks = 1; | |
1706 | fprintf_unfiltered (tmp_error_stream, | |
1707 | "breakpoint #%d\n", bpt->owner->number); | |
1708 | } | |
1709 | else | |
879bfdc2 | 1710 | { |
879bfdc2 DJ |
1711 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1712 | { | |
1713 | *hw_breakpoint_error = 1; | |
1714 | fprintf_unfiltered (tmp_error_stream, | |
1715 | "Cannot insert hardware breakpoint %d.\n", | |
1716 | bpt->owner->number); | |
1717 | } | |
1718 | else | |
1719 | { | |
1720 | fprintf_unfiltered (tmp_error_stream, | |
1721 | "Cannot insert breakpoint %d.\n", | |
1722 | bpt->owner->number); | |
1723 | fprintf_filtered (tmp_error_stream, | |
1724 | "Error accessing memory address "); | |
5af949e3 UW |
1725 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1726 | tmp_error_stream); | |
879bfdc2 DJ |
1727 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1728 | safe_strerror (val)); | |
1729 | } | |
1730 | ||
1731 | } | |
1732 | } | |
1733 | else | |
1734 | bpt->inserted = 1; | |
1735 | ||
1736 | return val; | |
1737 | } | |
1738 | ||
1739 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1740 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1741 | watchpoints. It's not clear that it's necessary... */ | |
1742 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1743 | { | |
85d721b8 | 1744 | val = target_insert_watchpoint (bpt->address, |
a5606eee | 1745 | bpt->length, |
0cf6dd15 TJB |
1746 | bpt->watchpoint_type, |
1747 | bpt->owner->cond_exp); | |
85d721b8 PA |
1748 | |
1749 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1750 | supported, try emulating one with an access watchpoint. */ | |
1751 | if (val == 1 && bpt->watchpoint_type == hw_read) | |
1752 | { | |
1753 | struct bp_location *loc, **loc_temp; | |
1754 | ||
1755 | /* But don't try to insert it, if there's already another | |
1756 | hw_access location that would be considered a duplicate | |
1757 | of this one. */ | |
1758 | ALL_BP_LOCATIONS (loc, loc_temp) | |
1759 | if (loc != bpt | |
1760 | && loc->watchpoint_type == hw_access | |
1761 | && watchpoint_locations_match (bpt, loc)) | |
1762 | { | |
1763 | bpt->duplicate = 1; | |
1764 | bpt->inserted = 1; | |
1765 | bpt->target_info = loc->target_info; | |
1766 | bpt->watchpoint_type = hw_access; | |
1767 | val = 0; | |
1768 | break; | |
1769 | } | |
1770 | ||
1771 | if (val == 1) | |
1772 | { | |
1773 | val = target_insert_watchpoint (bpt->address, | |
1774 | bpt->length, | |
0cf6dd15 TJB |
1775 | hw_access, |
1776 | bpt->owner->cond_exp); | |
85d721b8 PA |
1777 | if (val == 0) |
1778 | bpt->watchpoint_type = hw_access; | |
1779 | } | |
1780 | } | |
1781 | ||
1782 | bpt->inserted = (val == 0); | |
879bfdc2 DJ |
1783 | } |
1784 | ||
fe798b75 | 1785 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1786 | { |
71fff37b AC |
1787 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1788 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1789 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1790 | bpt->owner->number); | |
1791 | if (e.reason < 0) | |
879bfdc2 DJ |
1792 | bpt->owner->enable_state = bp_disabled; |
1793 | else | |
1794 | bpt->inserted = 1; | |
1640b821 DJ |
1795 | |
1796 | /* We've already printed an error message if there was a problem | |
1797 | inserting this catchpoint, and we've disabled the catchpoint, | |
1798 | so just return success. */ | |
1799 | return 0; | |
879bfdc2 DJ |
1800 | } |
1801 | ||
1802 | return 0; | |
1803 | } | |
1804 | ||
6c95b8df PA |
1805 | /* This function is called when program space PSPACE is about to be |
1806 | deleted. It takes care of updating breakpoints to not reference | |
1807 | PSPACE anymore. */ | |
1808 | ||
1809 | void | |
1810 | breakpoint_program_space_exit (struct program_space *pspace) | |
1811 | { | |
1812 | struct breakpoint *b, *b_temp; | |
876fa593 | 1813 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1814 | |
1815 | /* Remove any breakpoint that was set through this program space. */ | |
1816 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1817 | { | |
1818 | if (b->pspace == pspace) | |
1819 | delete_breakpoint (b); | |
1820 | } | |
1821 | ||
1822 | /* Breakpoints set through other program spaces could have locations | |
1823 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1824 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1825 | { |
1826 | struct bp_location *tmp; | |
1827 | ||
1828 | if (loc->pspace == pspace) | |
1829 | { | |
2bdf28a0 | 1830 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1831 | if (loc->owner->loc == loc) |
1832 | loc->owner->loc = loc->next; | |
1833 | else | |
1834 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1835 | if (tmp->next == loc) | |
1836 | { | |
1837 | tmp->next = loc->next; | |
1838 | break; | |
1839 | } | |
1840 | } | |
1841 | } | |
1842 | ||
1843 | /* Now update the global location list to permanently delete the | |
1844 | removed locations above. */ | |
1845 | update_global_location_list (0); | |
1846 | } | |
1847 | ||
74960c60 VP |
1848 | /* Make sure all breakpoints are inserted in inferior. |
1849 | Throws exception on any error. | |
1850 | A breakpoint that is already inserted won't be inserted | |
1851 | again, so calling this function twice is safe. */ | |
1852 | void | |
1853 | insert_breakpoints (void) | |
1854 | { | |
1855 | struct breakpoint *bpt; | |
1856 | ||
1857 | ALL_BREAKPOINTS (bpt) | |
1858 | if (is_hardware_watchpoint (bpt)) | |
1859 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1860 | ||
b60e7edf | 1861 | update_global_location_list (1); |
74960c60 | 1862 | |
c35b1492 PA |
1863 | /* update_global_location_list does not insert breakpoints when |
1864 | always_inserted_mode is not enabled. Explicitly insert them | |
1865 | now. */ | |
1866 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1867 | insert_breakpoint_locations (); |
1868 | } | |
1869 | ||
c906108c SS |
1870 | /* insert_breakpoints is used when starting or continuing the program. |
1871 | remove_breakpoints is used when the program stops. | |
1872 | Both return zero if successful, | |
1873 | or an `errno' value if could not write the inferior. */ | |
1874 | ||
74960c60 VP |
1875 | static void |
1876 | insert_breakpoint_locations (void) | |
c906108c | 1877 | { |
a5606eee | 1878 | struct breakpoint *bpt; |
876fa593 | 1879 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1880 | int error = 0; |
c906108c SS |
1881 | int val = 0; |
1882 | int disabled_breaks = 0; | |
81d0cc19 | 1883 | int hw_breakpoint_error = 0; |
c906108c | 1884 | |
81d0cc19 | 1885 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1886 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1887 | |
81d0cc19 GS |
1888 | /* Explicitly mark the warning -- this will only be printed if |
1889 | there was an error. */ | |
1890 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1891 | |
1892 | save_current_space_and_thread (); | |
1893 | ||
876fa593 | 1894 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1895 | { |
74960c60 | 1896 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1897 | continue; |
1898 | ||
f365de73 | 1899 | /* There is no point inserting thread-specific breakpoints if the |
2bdf28a0 JK |
1900 | thread no longer exists. ALL_BP_LOCATIONS bp_location has B->OWNER |
1901 | always non-NULL. */ | |
f365de73 AS |
1902 | if (b->owner->thread != -1 |
1903 | && !valid_thread_id (b->owner->thread)) | |
1904 | continue; | |
1905 | ||
6c95b8df PA |
1906 | switch_to_program_space_and_thread (b->pspace); |
1907 | ||
1908 | /* For targets that support global breakpoints, there's no need | |
1909 | to select an inferior to insert breakpoint to. In fact, even | |
1910 | if we aren't attached to any process yet, we should still | |
1911 | insert breakpoints. */ | |
1912 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1913 | && ptid_equal (inferior_ptid, null_ptid)) | |
1914 | continue; | |
1915 | ||
879bfdc2 | 1916 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1917 | &disabled_breaks, |
879bfdc2 DJ |
1918 | &hw_breakpoint_error); |
1919 | if (val) | |
e236ba44 | 1920 | error = val; |
879bfdc2 | 1921 | } |
c906108c | 1922 | |
a5606eee VP |
1923 | /* If we failed to insert all locations of a watchpoint, |
1924 | remove them, as half-inserted watchpoint is of limited use. */ | |
1925 | ALL_BREAKPOINTS (bpt) | |
1926 | { | |
1927 | int some_failed = 0; | |
1928 | struct bp_location *loc; | |
1929 | ||
1930 | if (!is_hardware_watchpoint (bpt)) | |
1931 | continue; | |
1932 | ||
d6b74ac4 | 1933 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1934 | continue; |
74960c60 VP |
1935 | |
1936 | if (bpt->disposition == disp_del_at_next_stop) | |
1937 | continue; | |
a5606eee VP |
1938 | |
1939 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1940 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1941 | { |
1942 | some_failed = 1; | |
1943 | break; | |
1944 | } | |
1945 | if (some_failed) | |
1946 | { | |
1947 | for (loc = bpt->loc; loc; loc = loc->next) | |
1948 | if (loc->inserted) | |
1949 | remove_breakpoint (loc, mark_uninserted); | |
1950 | ||
1951 | hw_breakpoint_error = 1; | |
1952 | fprintf_unfiltered (tmp_error_stream, | |
1953 | "Could not insert hardware watchpoint %d.\n", | |
1954 | bpt->number); | |
1955 | error = -1; | |
1956 | } | |
1957 | } | |
1958 | ||
e236ba44 | 1959 | if (error) |
81d0cc19 GS |
1960 | { |
1961 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1962 | message about possibly exhausted resources. */ | |
879bfdc2 | 1963 | if (hw_breakpoint_error) |
81d0cc19 | 1964 | { |
c6510018 MS |
1965 | fprintf_unfiltered (tmp_error_stream, |
1966 | "Could not insert hardware breakpoints:\n\ | |
1967 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1968 | } |
81d0cc19 GS |
1969 | target_terminal_ours_for_output (); |
1970 | error_stream (tmp_error_stream); | |
1971 | } | |
f7545552 TT |
1972 | |
1973 | do_cleanups (cleanups); | |
c906108c SS |
1974 | } |
1975 | ||
c906108c | 1976 | int |
fba45db2 | 1977 | remove_breakpoints (void) |
c906108c | 1978 | { |
876fa593 | 1979 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1980 | int val = 0; |
c906108c | 1981 | |
876fa593 | 1982 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1983 | { |
0bde7532 | 1984 | if (b->inserted) |
3a1bae8e | 1985 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1986 | } |
3a1bae8e | 1987 | return val; |
c906108c SS |
1988 | } |
1989 | ||
6c95b8df PA |
1990 | /* Remove breakpoints of process PID. */ |
1991 | ||
1992 | int | |
1993 | remove_breakpoints_pid (int pid) | |
1994 | { | |
876fa593 | 1995 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1996 | int val; |
1997 | struct inferior *inf = find_inferior_pid (pid); | |
1998 | ||
876fa593 | 1999 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
2000 | { |
2001 | if (b->pspace != inf->pspace) | |
2002 | continue; | |
2003 | ||
2004 | if (b->inserted) | |
2005 | { | |
2006 | val = remove_breakpoint (b, mark_uninserted); | |
2007 | if (val != 0) | |
2008 | return val; | |
2009 | } | |
2010 | } | |
2011 | return 0; | |
2012 | } | |
2013 | ||
692590c1 | 2014 | int |
80ce1ecb | 2015 | remove_hw_watchpoints (void) |
692590c1 | 2016 | { |
876fa593 | 2017 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2018 | int val = 0; |
692590c1 | 2019 | |
876fa593 | 2020 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 2021 | { |
0bde7532 | 2022 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 2023 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 2024 | } |
3a1bae8e | 2025 | return val; |
692590c1 MS |
2026 | } |
2027 | ||
c906108c | 2028 | int |
fba45db2 | 2029 | reattach_breakpoints (int pid) |
c906108c | 2030 | { |
6c95b8df | 2031 | struct cleanup *old_chain; |
876fa593 | 2032 | struct bp_location *b, **bp_tmp; |
c906108c | 2033 | int val; |
a4954f26 | 2034 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 2035 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2036 | struct inferior *inf; |
2037 | struct thread_info *tp; | |
2038 | ||
2039 | tp = any_live_thread_of_process (pid); | |
2040 | if (tp == NULL) | |
2041 | return 1; | |
2042 | ||
2043 | inf = find_inferior_pid (pid); | |
2044 | old_chain = save_inferior_ptid (); | |
2045 | ||
2046 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
2047 | |
2048 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 2049 | |
876fa593 | 2050 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2051 | { |
6c95b8df PA |
2052 | if (b->pspace != inf->pspace) |
2053 | continue; | |
2054 | ||
0bde7532 | 2055 | if (b->inserted) |
c5aa993b | 2056 | { |
a4954f26 DJ |
2057 | b->inserted = 0; |
2058 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 2059 | &dummy1, &dummy2); |
c5aa993b JM |
2060 | if (val != 0) |
2061 | { | |
ce696e05 | 2062 | do_cleanups (old_chain); |
c5aa993b JM |
2063 | return val; |
2064 | } | |
2065 | } | |
2066 | } | |
ce696e05 | 2067 | do_cleanups (old_chain); |
c906108c SS |
2068 | return 0; |
2069 | } | |
2070 | ||
e58b0e63 PA |
2071 | static int internal_breakpoint_number = -1; |
2072 | ||
e62c965a | 2073 | static struct breakpoint * |
a6d9a66e UW |
2074 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2075 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2076 | { |
e62c965a PP |
2077 | struct symtab_and_line sal; |
2078 | struct breakpoint *b; | |
2079 | ||
2080 | init_sal (&sal); /* initialize to zeroes */ | |
2081 | ||
2082 | sal.pc = address; | |
2083 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2084 | sal.pspace = current_program_space; |
e62c965a | 2085 | |
a6d9a66e | 2086 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2087 | b->number = internal_breakpoint_number--; |
2088 | b->disposition = disp_donttouch; | |
2089 | ||
2090 | return b; | |
2091 | } | |
2092 | ||
2093 | static void | |
69de3c6a | 2094 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 2095 | { |
69de3c6a | 2096 | struct objfile *objfile; |
e62c965a | 2097 | |
69de3c6a PP |
2098 | ALL_OBJFILES (objfile) |
2099 | { | |
2100 | struct breakpoint *b; | |
2101 | struct minimal_symbol *m; | |
2102 | ||
2103 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2104 | if (m == NULL) | |
2105 | continue; | |
e62c965a | 2106 | |
a6d9a66e UW |
2107 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2108 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
2109 | bp_overlay_event); |
2110 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2111 | |
69de3c6a PP |
2112 | if (overlay_debugging == ovly_auto) |
2113 | { | |
2114 | b->enable_state = bp_enabled; | |
2115 | overlay_events_enabled = 1; | |
2116 | } | |
2117 | else | |
2118 | { | |
2119 | b->enable_state = bp_disabled; | |
2120 | overlay_events_enabled = 0; | |
2121 | } | |
e62c965a PP |
2122 | } |
2123 | update_global_location_list (1); | |
2124 | } | |
2125 | ||
0fd8e87f UW |
2126 | static void |
2127 | create_longjmp_master_breakpoint (char *func_name) | |
2128 | { | |
6c95b8df | 2129 | struct program_space *pspace; |
0fd8e87f | 2130 | struct objfile *objfile; |
6c95b8df PA |
2131 | struct cleanup *old_chain; |
2132 | ||
2133 | old_chain = save_current_program_space (); | |
0fd8e87f | 2134 | |
6c95b8df | 2135 | ALL_PSPACES (pspace) |
0fd8e87f UW |
2136 | ALL_OBJFILES (objfile) |
2137 | { | |
2138 | struct breakpoint *b; | |
2139 | struct minimal_symbol *m; | |
2140 | ||
2141 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
2142 | continue; | |
2143 | ||
6c95b8df PA |
2144 | set_current_program_space (pspace); |
2145 | ||
0fd8e87f UW |
2146 | m = lookup_minimal_symbol_text (func_name, objfile); |
2147 | if (m == NULL) | |
2148 | continue; | |
2149 | ||
a6d9a66e UW |
2150 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
2151 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
2152 | bp_longjmp_master); |
2153 | b->addr_string = xstrdup (func_name); | |
2154 | b->enable_state = bp_disabled; | |
2155 | } | |
2156 | update_global_location_list (1); | |
6c95b8df PA |
2157 | |
2158 | do_cleanups (old_chain); | |
0fd8e87f UW |
2159 | } |
2160 | ||
aa7d318d TT |
2161 | /* Create a master std::terminate breakpoint. The actual function |
2162 | looked for is named FUNC_NAME. */ | |
2163 | static void | |
2164 | create_std_terminate_master_breakpoint (const char *func_name) | |
2165 | { | |
2166 | struct program_space *pspace; | |
2167 | struct objfile *objfile; | |
2168 | struct cleanup *old_chain; | |
2169 | ||
2170 | old_chain = save_current_program_space (); | |
2171 | ||
2172 | ALL_PSPACES (pspace) | |
2173 | ALL_OBJFILES (objfile) | |
2174 | { | |
2175 | struct breakpoint *b; | |
2176 | struct minimal_symbol *m; | |
2177 | ||
2178 | set_current_program_space (pspace); | |
2179 | ||
2180 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2181 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2182 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2183 | continue; | |
2184 | ||
2185 | b = create_internal_breakpoint (get_objfile_arch (objfile), | |
2186 | SYMBOL_VALUE_ADDRESS (m), | |
2187 | bp_std_terminate_master); | |
2188 | b->addr_string = xstrdup (func_name); | |
2189 | b->enable_state = bp_disabled; | |
2190 | } | |
2191 | update_global_location_list (1); | |
2192 | ||
2193 | do_cleanups (old_chain); | |
2194 | } | |
2195 | ||
c906108c | 2196 | void |
fba45db2 | 2197 | update_breakpoints_after_exec (void) |
c906108c | 2198 | { |
c5aa993b JM |
2199 | struct breakpoint *b; |
2200 | struct breakpoint *temp; | |
876fa593 | 2201 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2202 | |
25b22b0a PA |
2203 | /* We're about to delete breakpoints from GDB's lists. If the |
2204 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2205 | writing the breakpoints' "shadow contents" back into memory. The | |
2206 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2207 | do that. Instead, the target is responsible from marking | |
2208 | breakpoints out as soon as it detects an exec. We don't do that | |
2209 | here instead, because there may be other attempts to delete | |
2210 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2211 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2212 | if (bploc->pspace == current_program_space) |
2213 | gdb_assert (!bploc->inserted); | |
c906108c SS |
2214 | |
2215 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 2216 | { |
6c95b8df PA |
2217 | if (b->pspace != current_program_space) |
2218 | continue; | |
2219 | ||
c5aa993b JM |
2220 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
2221 | if (b->type == bp_shlib_event) | |
2222 | { | |
2223 | delete_breakpoint (b); | |
2224 | continue; | |
2225 | } | |
c906108c | 2226 | |
4efc6507 DE |
2227 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
2228 | if (b->type == bp_jit_event) | |
2229 | { | |
2230 | delete_breakpoint (b); | |
2231 | continue; | |
2232 | } | |
2233 | ||
1900040c | 2234 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2235 | as must overlay event and longjmp master breakpoints. */ |
2236 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
aa7d318d | 2237 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master) |
c4093a6a JM |
2238 | { |
2239 | delete_breakpoint (b); | |
2240 | continue; | |
2241 | } | |
2242 | ||
c5aa993b JM |
2243 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2244 | if (b->type == bp_step_resume) | |
2245 | { | |
2246 | delete_breakpoint (b); | |
2247 | continue; | |
2248 | } | |
2249 | ||
611c83ae PA |
2250 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2251 | after an exec. */ | |
2252 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
2253 | { | |
2254 | delete_breakpoint (b); | |
2255 | continue; | |
2256 | } | |
2257 | ||
ce78b96d JB |
2258 | if (b->type == bp_catchpoint) |
2259 | { | |
2260 | /* For now, none of the bp_catchpoint breakpoints need to | |
2261 | do anything at this point. In the future, if some of | |
2262 | the catchpoints need to something, we will need to add | |
2263 | a new method, and call this method from here. */ | |
2264 | continue; | |
2265 | } | |
2266 | ||
c5aa993b JM |
2267 | /* bp_finish is a special case. The only way we ought to be able |
2268 | to see one of these when an exec() has happened, is if the user | |
2269 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2270 | carries them to the call-site of the current callee, by setting | |
2271 | a temporary bp there and resuming. But in this case, the finish | |
2272 | will carry them entirely through the vfork & exec. | |
2273 | ||
2274 | We don't want to allow a bp_finish to remain inserted now. But | |
2275 | we can't safely delete it, 'cause finish_command has a handle to | |
2276 | the bp on a bpstat, and will later want to delete it. There's a | |
2277 | chance (and I've seen it happen) that if we delete the bp_finish | |
2278 | here, that its storage will get reused by the time finish_command | |
2279 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2280 | We really must allow finish_command to delete a bp_finish. | |
2281 | ||
53a5351d JM |
2282 | In the absense of a general solution for the "how do we know |
2283 | it's safe to delete something others may have handles to?" | |
2284 | problem, what we'll do here is just uninsert the bp_finish, and | |
2285 | let finish_command delete it. | |
2286 | ||
2287 | (We know the bp_finish is "doomed" in the sense that it's | |
2288 | momentary, and will be deleted as soon as finish_command sees | |
2289 | the inferior stopped. So it doesn't matter that the bp's | |
2290 | address is probably bogus in the new a.out, unlike e.g., the | |
2291 | solib breakpoints.) */ | |
c5aa993b | 2292 | |
c5aa993b JM |
2293 | if (b->type == bp_finish) |
2294 | { | |
2295 | continue; | |
2296 | } | |
2297 | ||
2298 | /* Without a symbolic address, we have little hope of the | |
2299 | pre-exec() address meaning the same thing in the post-exec() | |
2300 | a.out. */ | |
2301 | if (b->addr_string == NULL) | |
2302 | { | |
2303 | delete_breakpoint (b); | |
2304 | continue; | |
2305 | } | |
c5aa993b | 2306 | } |
1900040c | 2307 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 2308 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
2309 | create_longjmp_master_breakpoint ("longjmp"); |
2310 | create_longjmp_master_breakpoint ("_longjmp"); | |
2311 | create_longjmp_master_breakpoint ("siglongjmp"); | |
2312 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 2313 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
2314 | } |
2315 | ||
2316 | int | |
fba45db2 | 2317 | detach_breakpoints (int pid) |
c906108c | 2318 | { |
876fa593 | 2319 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2320 | int val = 0; |
ce696e05 | 2321 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2322 | struct inferior *inf = current_inferior (); |
c5aa993b | 2323 | |
39f77062 | 2324 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2325 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2326 | |
6c95b8df | 2327 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2328 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 2329 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2330 | { |
6c95b8df PA |
2331 | if (b->pspace != inf->pspace) |
2332 | continue; | |
2333 | ||
0bde7532 | 2334 | if (b->inserted) |
6c95b8df | 2335 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2336 | } |
d03285ec UW |
2337 | |
2338 | /* Detach single-step breakpoints as well. */ | |
2339 | detach_single_step_breakpoints (); | |
2340 | ||
ce696e05 | 2341 | do_cleanups (old_chain); |
3a1bae8e | 2342 | return val; |
c906108c SS |
2343 | } |
2344 | ||
6c95b8df PA |
2345 | /* Remove the breakpoint location B from the current address space. |
2346 | Note that this is used to detach breakpoints from a child fork. | |
2347 | When we get here, the child isn't in the inferior list, and neither | |
2348 | do we have objects to represent its address space --- we should | |
2349 | *not* look at b->pspace->aspace here. */ | |
2350 | ||
c906108c | 2351 | static int |
6c95b8df | 2352 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2353 | { |
2354 | int val; | |
c5aa993b | 2355 | |
2bdf28a0 JK |
2356 | /* B is never in moribund_locations by our callers. */ |
2357 | gdb_assert (b->owner != NULL); | |
2358 | ||
0bde7532 | 2359 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2360 | /* Permanent breakpoints cannot be inserted or removed. */ |
2361 | return 0; | |
2362 | ||
74960c60 VP |
2363 | /* The type of none suggests that owner is actually deleted. |
2364 | This should not ever happen. */ | |
2365 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2366 | |
2367 | if (b->loc_type == bp_loc_software_breakpoint | |
2368 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2369 | { |
c02f5703 MS |
2370 | /* "Normal" instruction breakpoint: either the standard |
2371 | trap-instruction bp (bp_breakpoint), or a | |
2372 | bp_hardware_breakpoint. */ | |
2373 | ||
2374 | /* First check to see if we have to handle an overlay. */ | |
2375 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2376 | || b->section == NULL |
2377 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2378 | { |
2379 | /* No overlay handling: just remove the breakpoint. */ | |
2380 | ||
0bde7532 | 2381 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2382 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2383 | else |
a6d9a66e | 2384 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2385 | } |
c906108c SS |
2386 | else |
2387 | { | |
c02f5703 MS |
2388 | /* This breakpoint is in an overlay section. |
2389 | Did we set a breakpoint at the LMA? */ | |
2390 | if (!overlay_events_enabled) | |
2391 | { | |
2392 | /* Yes -- overlay event support is not active, so we | |
2393 | should have set a breakpoint at the LMA. Remove it. | |
2394 | */ | |
c02f5703 MS |
2395 | /* Ignore any failures: if the LMA is in ROM, we will |
2396 | have already warned when we failed to insert it. */ | |
0bde7532 | 2397 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2398 | target_remove_hw_breakpoint (b->gdbarch, |
2399 | &b->overlay_target_info); | |
c02f5703 | 2400 | else |
a6d9a66e UW |
2401 | target_remove_breakpoint (b->gdbarch, |
2402 | &b->overlay_target_info); | |
c02f5703 MS |
2403 | } |
2404 | /* Did we set a breakpoint at the VMA? | |
2405 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2406 | if (b->inserted) |
c906108c | 2407 | { |
c02f5703 MS |
2408 | /* Yes -- remove it. Previously we did not bother to |
2409 | remove the breakpoint if the section had been | |
2410 | unmapped, but let's not rely on that being safe. We | |
2411 | don't know what the overlay manager might do. */ | |
0bde7532 | 2412 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2413 | val = target_remove_hw_breakpoint (b->gdbarch, |
2414 | &b->target_info); | |
aa67235e UW |
2415 | |
2416 | /* However, we should remove *software* breakpoints only | |
2417 | if the section is still mapped, or else we overwrite | |
2418 | wrong code with the saved shadow contents. */ | |
2419 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2420 | val = target_remove_breakpoint (b->gdbarch, |
2421 | &b->target_info); | |
aa67235e UW |
2422 | else |
2423 | val = 0; | |
c906108c | 2424 | } |
c02f5703 MS |
2425 | else |
2426 | { | |
2427 | /* No -- not inserted, so no need to remove. No error. */ | |
2428 | val = 0; | |
2429 | } | |
c906108c | 2430 | } |
879d1e6b UW |
2431 | |
2432 | /* In some cases, we might not be able to remove a breakpoint | |
2433 | in a shared library that has already been removed, but we | |
2434 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2435 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2436 | val = 0; |
2437 | ||
c906108c SS |
2438 | if (val) |
2439 | return val; | |
0bde7532 | 2440 | b->inserted = (is == mark_inserted); |
c906108c | 2441 | } |
a5606eee | 2442 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2443 | { |
0bde7532 | 2444 | b->inserted = (is == mark_inserted); |
0cf6dd15 TJB |
2445 | val = target_remove_watchpoint (b->address, b->length, |
2446 | b->watchpoint_type, b->owner->cond_exp); | |
2e70b7b9 | 2447 | |
c906108c | 2448 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2449 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2450 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2451 | b->owner->number); |
c906108c | 2452 | } |
ce78b96d JB |
2453 | else if (b->owner->type == bp_catchpoint |
2454 | && breakpoint_enabled (b->owner) | |
2455 | && !b->duplicate) | |
2456 | { | |
2457 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2458 | ||
2459 | val = b->owner->ops->remove (b->owner); | |
2460 | if (val) | |
2461 | return val; | |
2462 | b->inserted = (is == mark_inserted); | |
2463 | } | |
c906108c SS |
2464 | |
2465 | return 0; | |
2466 | } | |
2467 | ||
6c95b8df PA |
2468 | static int |
2469 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2470 | { | |
2471 | int ret; | |
2472 | struct cleanup *old_chain; | |
2473 | ||
2bdf28a0 JK |
2474 | /* B is never in moribund_locations by our callers. */ |
2475 | gdb_assert (b->owner != NULL); | |
2476 | ||
6c95b8df PA |
2477 | if (b->owner->enable_state == bp_permanent) |
2478 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2479 | return 0; | |
2480 | ||
2481 | /* The type of none suggests that owner is actually deleted. | |
2482 | This should not ever happen. */ | |
2483 | gdb_assert (b->owner->type != bp_none); | |
2484 | ||
2485 | old_chain = save_current_space_and_thread (); | |
2486 | ||
2487 | switch_to_program_space_and_thread (b->pspace); | |
2488 | ||
2489 | ret = remove_breakpoint_1 (b, is); | |
2490 | ||
2491 | do_cleanups (old_chain); | |
2492 | return ret; | |
2493 | } | |
2494 | ||
c906108c SS |
2495 | /* Clear the "inserted" flag in all breakpoints. */ |
2496 | ||
25b22b0a | 2497 | void |
fba45db2 | 2498 | mark_breakpoints_out (void) |
c906108c | 2499 | { |
876fa593 | 2500 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2501 | |
876fa593 | 2502 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2503 | if (bpt->pspace == current_program_space) |
2504 | bpt->inserted = 0; | |
c906108c SS |
2505 | } |
2506 | ||
53a5351d JM |
2507 | /* Clear the "inserted" flag in all breakpoints and delete any |
2508 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2509 | |
2510 | Plus other such housekeeping that has to be done for breakpoints | |
2511 | between runs. | |
2512 | ||
53a5351d JM |
2513 | Note: this function gets called at the end of a run (by |
2514 | generic_mourn_inferior) and when a run begins (by | |
2515 | init_wait_for_inferior). */ | |
c906108c SS |
2516 | |
2517 | ||
2518 | ||
2519 | void | |
fba45db2 | 2520 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2521 | { |
52f0bd74 | 2522 | struct breakpoint *b, *temp; |
876fa593 | 2523 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2524 | int ix; |
6c95b8df | 2525 | struct program_space *pspace = current_program_space; |
c906108c | 2526 | |
50c71eaf PA |
2527 | /* If breakpoint locations are shared across processes, then there's |
2528 | nothing to do. */ | |
2567c7d9 | 2529 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2530 | return; |
2531 | ||
876fa593 | 2532 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df | 2533 | { |
2bdf28a0 | 2534 | /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */ |
6c95b8df PA |
2535 | if (bpt->pspace == pspace |
2536 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2537 | bpt->inserted = 0; |
6c95b8df | 2538 | } |
075f6582 | 2539 | |
c906108c | 2540 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2541 | { |
6c95b8df PA |
2542 | if (b->loc && b->loc->pspace != pspace) |
2543 | continue; | |
2544 | ||
c5aa993b JM |
2545 | switch (b->type) |
2546 | { | |
2547 | case bp_call_dummy: | |
c906108c | 2548 | |
c5aa993b | 2549 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2550 | cause problems when the inferior is rerun, so we better get |
2551 | rid of it. */ | |
2552 | ||
2553 | case bp_watchpoint_scope: | |
2554 | ||
2555 | /* Also get rid of scope breakpoints. */ | |
2556 | ||
2557 | case bp_shlib_event: | |
2558 | ||
2559 | /* Also remove solib event breakpoints. Their addresses may | |
2560 | have changed since the last time we ran the program. | |
2561 | Actually we may now be debugging against different target; | |
2562 | and so the solib backend that installed this breakpoint may | |
2563 | not be used in by the target. E.g., | |
2564 | ||
2565 | (gdb) file prog-linux | |
2566 | (gdb) run # native linux target | |
2567 | ... | |
2568 | (gdb) kill | |
2569 | (gdb) file prog-win.exe | |
2570 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2571 | */ | |
c906108c | 2572 | |
c5aa993b JM |
2573 | delete_breakpoint (b); |
2574 | break; | |
c906108c | 2575 | |
c5aa993b JM |
2576 | case bp_watchpoint: |
2577 | case bp_hardware_watchpoint: | |
2578 | case bp_read_watchpoint: | |
2579 | case bp_access_watchpoint: | |
c906108c | 2580 | |
c5aa993b JM |
2581 | /* Likewise for watchpoints on local expressions. */ |
2582 | if (b->exp_valid_block != NULL) | |
2583 | delete_breakpoint (b); | |
967af18d | 2584 | else if (context == inf_starting) |
c860120c PM |
2585 | { |
2586 | /* Reset val field to force reread of starting value | |
2587 | in insert_breakpoints. */ | |
2588 | if (b->val) | |
2589 | value_free (b->val); | |
2590 | b->val = NULL; | |
fa4727a6 | 2591 | b->val_valid = 0; |
c860120c | 2592 | } |
c5aa993b JM |
2593 | break; |
2594 | default: | |
c5aa993b JM |
2595 | break; |
2596 | } | |
2597 | } | |
1c5cfe86 PA |
2598 | |
2599 | /* Get rid of the moribund locations. */ | |
2600 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
f431efe5 | 2601 | decref_bp_location (&bpt); |
1c5cfe86 | 2602 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2603 | } |
2604 | ||
6c95b8df PA |
2605 | /* These functions concern about actual breakpoints inserted in the |
2606 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2607 | we need to hop over the bkpt --- so we check for address space | |
2608 | match, not program space. */ | |
2609 | ||
c2c6d25f JM |
2610 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2611 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2612 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2613 | permanent breakpoint. | |
2614 | - When continuing from a location with an ordinary breakpoint, we | |
2615 | actually single step once before calling insert_breakpoints. | |
2616 | - When continuing from a localion with a permanent breakpoint, we | |
2617 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2618 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2619 | |
c2c6d25f | 2620 | enum breakpoint_here |
6c95b8df | 2621 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2622 | { |
876fa593 | 2623 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2624 | int any_breakpoint_here = 0; |
c906108c | 2625 | |
876fa593 | 2626 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2627 | { |
2628 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2629 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2630 | continue; | |
2631 | ||
2bdf28a0 | 2632 | /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */ |
468d015d | 2633 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2634 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2635 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2636 | aspace, pc)) | |
075f6582 DJ |
2637 | { |
2638 | if (overlay_debugging | |
2639 | && section_is_overlay (bpt->section) | |
2640 | && !section_is_mapped (bpt->section)) | |
2641 | continue; /* unmapped overlay -- can't be a match */ | |
2642 | else if (bpt->owner->enable_state == bp_permanent) | |
2643 | return permanent_breakpoint_here; | |
2644 | else | |
2645 | any_breakpoint_here = 1; | |
2646 | } | |
2647 | } | |
c906108c | 2648 | |
c2c6d25f | 2649 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2650 | } |
2651 | ||
1c5cfe86 PA |
2652 | /* Return true if there's a moribund breakpoint at PC. */ |
2653 | ||
2654 | int | |
6c95b8df | 2655 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2656 | { |
2657 | struct bp_location *loc; | |
2658 | int ix; | |
2659 | ||
2660 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2661 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2662 | aspace, pc)) | |
1c5cfe86 PA |
2663 | return 1; |
2664 | ||
2665 | return 0; | |
2666 | } | |
c2c6d25f | 2667 | |
c36b740a | 2668 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2669 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2670 | This does not check for single-step breakpoints, which are |
2671 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2672 | |
2673 | int | |
6c95b8df | 2674 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2675 | { |
876fa593 | 2676 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2677 | |
876fa593 | 2678 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2679 | { |
075f6582 DJ |
2680 | if (bpt->loc_type != bp_loc_software_breakpoint |
2681 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2682 | continue; | |
2683 | ||
2684 | if (bpt->inserted | |
6c95b8df PA |
2685 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2686 | aspace, pc)) | |
075f6582 DJ |
2687 | { |
2688 | if (overlay_debugging | |
2689 | && section_is_overlay (bpt->section) | |
2690 | && !section_is_mapped (bpt->section)) | |
2691 | continue; /* unmapped overlay -- can't be a match */ | |
2692 | else | |
2693 | return 1; | |
2694 | } | |
c5aa993b | 2695 | } |
c36b740a VP |
2696 | return 0; |
2697 | } | |
2698 | ||
2699 | /* Returns non-zero iff there's either regular breakpoint | |
2700 | or a single step breakpoint inserted at PC. */ | |
2701 | ||
2702 | int | |
6c95b8df | 2703 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2704 | { |
6c95b8df | 2705 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2706 | return 1; |
c906108c | 2707 | |
6c95b8df | 2708 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2709 | return 1; |
2710 | ||
c906108c SS |
2711 | return 0; |
2712 | } | |
2713 | ||
4fa8626c DJ |
2714 | /* This function returns non-zero iff there is a software breakpoint |
2715 | inserted at PC. */ | |
2716 | ||
2717 | int | |
6c95b8df | 2718 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2719 | { |
876fa593 | 2720 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c | 2721 | |
876fa593 | 2722 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2723 | { |
2724 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2725 | continue; | |
2726 | ||
0d381245 | 2727 | if (bpt->inserted |
6c95b8df PA |
2728 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2729 | aspace, pc)) | |
4fa8626c DJ |
2730 | { |
2731 | if (overlay_debugging | |
2732 | && section_is_overlay (bpt->section) | |
2733 | && !section_is_mapped (bpt->section)) | |
2734 | continue; /* unmapped overlay -- can't be a match */ | |
2735 | else | |
2736 | return 1; | |
2737 | } | |
2738 | } | |
2739 | ||
1aafd4da | 2740 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2741 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2742 | return 1; |
2743 | ||
4fa8626c DJ |
2744 | return 0; |
2745 | } | |
2746 | ||
9093389c PA |
2747 | int |
2748 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2749 | CORE_ADDR addr, ULONGEST len) | |
2750 | { | |
2751 | struct breakpoint *bpt; | |
2752 | ||
2753 | ALL_BREAKPOINTS (bpt) | |
2754 | { | |
2755 | struct bp_location *loc; | |
2756 | ||
2757 | if (bpt->type != bp_hardware_watchpoint | |
2758 | && bpt->type != bp_access_watchpoint) | |
2759 | continue; | |
2760 | ||
2761 | if (!breakpoint_enabled (bpt)) | |
2762 | continue; | |
2763 | ||
2764 | for (loc = bpt->loc; loc; loc = loc->next) | |
2765 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2766 | { | |
2767 | CORE_ADDR l, h; | |
2768 | ||
2769 | /* Check for intersection. */ | |
2770 | l = max (loc->address, addr); | |
2771 | h = min (loc->address + loc->length, addr + len); | |
2772 | if (l < h) | |
2773 | return 1; | |
2774 | } | |
2775 | } | |
2776 | return 0; | |
2777 | } | |
2778 | ||
075f6582 DJ |
2779 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2780 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2781 | |
2782 | int | |
6c95b8df PA |
2783 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2784 | ptid_t ptid) | |
c906108c | 2785 | { |
876fa593 | 2786 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2787 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2788 | int thread = -1; |
4a306c9a | 2789 | int task = 0; |
a6f1cd96 | 2790 | |
876fa593 | 2791 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2792 | { |
075f6582 DJ |
2793 | if (bpt->loc_type != bp_loc_software_breakpoint |
2794 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2795 | continue; | |
2796 | ||
2bdf28a0 | 2797 | /* ALL_BP_LOCATIONS bp_location has BPT->OWNER always non-NULL. */ |
a6f1cd96 JB |
2798 | if (!breakpoint_enabled (bpt->owner) |
2799 | && bpt->owner->enable_state != bp_permanent) | |
2800 | continue; | |
2801 | ||
6c95b8df PA |
2802 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2803 | aspace, pc)) | |
a6f1cd96 JB |
2804 | continue; |
2805 | ||
2806 | if (bpt->owner->thread != -1) | |
075f6582 | 2807 | { |
a6f1cd96 JB |
2808 | /* This is a thread-specific breakpoint. Check that ptid |
2809 | matches that thread. If thread hasn't been computed yet, | |
2810 | it is now time to do so. */ | |
2811 | if (thread == -1) | |
2812 | thread = pid_to_thread_id (ptid); | |
2813 | if (bpt->owner->thread != thread) | |
2814 | continue; | |
075f6582 | 2815 | } |
a6f1cd96 | 2816 | |
4a306c9a JB |
2817 | if (bpt->owner->task != 0) |
2818 | { | |
2819 | /* This is a task-specific breakpoint. Check that ptid | |
2820 | matches that task. If task hasn't been computed yet, | |
2821 | it is now time to do so. */ | |
2822 | if (task == 0) | |
2823 | task = ada_get_task_number (ptid); | |
2824 | if (bpt->owner->task != task) | |
2825 | continue; | |
2826 | } | |
2827 | ||
a6f1cd96 JB |
2828 | if (overlay_debugging |
2829 | && section_is_overlay (bpt->section) | |
2830 | && !section_is_mapped (bpt->section)) | |
2831 | continue; /* unmapped overlay -- can't be a match */ | |
2832 | ||
2833 | return 1; | |
c5aa993b | 2834 | } |
c906108c SS |
2835 | |
2836 | return 0; | |
2837 | } | |
c906108c | 2838 | \f |
c5aa993b | 2839 | |
c906108c SS |
2840 | /* bpstat stuff. External routines' interfaces are documented |
2841 | in breakpoint.h. */ | |
2842 | ||
2843 | int | |
fba45db2 | 2844 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2845 | { |
533be4dd | 2846 | return (ep->type == bp_catchpoint); |
c906108c SS |
2847 | } |
2848 | ||
f431efe5 PA |
2849 | /* Frees any storage that is part of a bpstat. Does not walk the |
2850 | 'next' chain. */ | |
2851 | ||
2852 | static void | |
198757a8 VP |
2853 | bpstat_free (bpstat bs) |
2854 | { | |
2855 | if (bs->old_val != NULL) | |
2856 | value_free (bs->old_val); | |
9add0f1b | 2857 | decref_counted_command_line (&bs->commands); |
f431efe5 | 2858 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
2859 | xfree (bs); |
2860 | } | |
2861 | ||
c906108c SS |
2862 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2863 | Also free any storage that is part of a bpstat. */ | |
2864 | ||
2865 | void | |
fba45db2 | 2866 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2867 | { |
2868 | bpstat p; | |
2869 | bpstat q; | |
2870 | ||
2871 | if (bsp == 0) | |
2872 | return; | |
2873 | p = *bsp; | |
2874 | while (p != NULL) | |
2875 | { | |
2876 | q = p->next; | |
198757a8 | 2877 | bpstat_free (p); |
c906108c SS |
2878 | p = q; |
2879 | } | |
2880 | *bsp = NULL; | |
2881 | } | |
2882 | ||
2883 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2884 | is part of the bpstat is copied as well. */ | |
2885 | ||
2886 | bpstat | |
fba45db2 | 2887 | bpstat_copy (bpstat bs) |
c906108c SS |
2888 | { |
2889 | bpstat p = NULL; | |
2890 | bpstat tmp; | |
2891 | bpstat retval = NULL; | |
2892 | ||
2893 | if (bs == NULL) | |
2894 | return bs; | |
2895 | ||
2896 | for (; bs != NULL; bs = bs->next) | |
2897 | { | |
2898 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2899 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 2900 | incref_counted_command_line (tmp->commands); |
f431efe5 | 2901 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 2902 | if (bs->old_val != NULL) |
3c3185ac JK |
2903 | { |
2904 | tmp->old_val = value_copy (bs->old_val); | |
2905 | release_value (tmp->old_val); | |
2906 | } | |
31cc81e9 | 2907 | |
c906108c SS |
2908 | if (p == NULL) |
2909 | /* This is the first thing in the chain. */ | |
2910 | retval = tmp; | |
2911 | else | |
2912 | p->next = tmp; | |
2913 | p = tmp; | |
2914 | } | |
2915 | p->next = NULL; | |
2916 | return retval; | |
2917 | } | |
2918 | ||
2919 | /* Find the bpstat associated with this breakpoint */ | |
2920 | ||
2921 | bpstat | |
fba45db2 | 2922 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2923 | { |
c5aa993b JM |
2924 | if (bsp == NULL) |
2925 | return NULL; | |
c906108c | 2926 | |
c5aa993b JM |
2927 | for (; bsp != NULL; bsp = bsp->next) |
2928 | { | |
f431efe5 | 2929 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
2930 | return bsp; |
2931 | } | |
c906108c SS |
2932 | return NULL; |
2933 | } | |
2934 | ||
8671a17b | 2935 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2936 | at. *BSP upon return is a bpstat which points to the remaining |
2937 | breakpoints stopped at (but which is not guaranteed to be good for | |
2938 | anything but further calls to bpstat_num). | |
8671a17b PA |
2939 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2940 | Return -1 if stopped at a breakpoint that has been deleted since | |
2941 | we set it. | |
2942 | Return 1 otherwise. */ | |
c906108c SS |
2943 | |
2944 | int | |
8671a17b | 2945 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2946 | { |
2947 | struct breakpoint *b; | |
2948 | ||
2949 | if ((*bsp) == NULL) | |
2950 | return 0; /* No more breakpoint values */ | |
8671a17b | 2951 | |
4f8d1dc6 VP |
2952 | /* We assume we'll never have several bpstats that |
2953 | correspond to a single breakpoint -- otherwise, | |
2954 | this function might return the same number more | |
2955 | than once and this will look ugly. */ | |
f431efe5 | 2956 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
2957 | *bsp = (*bsp)->next; |
2958 | if (b == NULL) | |
2959 | return -1; /* breakpoint that's been deleted since */ | |
2960 | ||
2961 | *num = b->number; /* We have its number */ | |
2962 | return 1; | |
c906108c SS |
2963 | } |
2964 | ||
2965 | /* Modify BS so that the actions will not be performed. */ | |
2966 | ||
2967 | void | |
fba45db2 | 2968 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2969 | { |
2970 | for (; bs != NULL; bs = bs->next) | |
2971 | { | |
9add0f1b | 2972 | decref_counted_command_line (&bs->commands); |
dde2d684 | 2973 | bs->commands_left = NULL; |
c906108c SS |
2974 | if (bs->old_val != NULL) |
2975 | { | |
2976 | value_free (bs->old_val); | |
2977 | bs->old_val = NULL; | |
2978 | } | |
2979 | } | |
2980 | } | |
2981 | ||
f3b1572e PA |
2982 | /* Called when a command is about to proceed the inferior. */ |
2983 | ||
2984 | static void | |
2985 | breakpoint_about_to_proceed (void) | |
2986 | { | |
2987 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2988 | { | |
2989 | struct thread_info *tp = inferior_thread (); | |
2990 | ||
2991 | /* Allow inferior function calls in breakpoint commands to not | |
2992 | interrupt the command list. When the call finishes | |
2993 | successfully, the inferior will be standing at the same | |
2994 | breakpoint as if nothing happened. */ | |
2995 | if (tp->in_infcall) | |
2996 | return; | |
2997 | } | |
2998 | ||
2999 | breakpoint_proceeded = 1; | |
3000 | } | |
3001 | ||
c906108c | 3002 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 3003 | static void |
4efb68b1 | 3004 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3005 | { |
3006 | executing_breakpoint_commands = 0; | |
3007 | } | |
3008 | ||
3009 | /* Execute all the commands associated with all the breakpoints at this | |
3010 | location. Any of these commands could cause the process to proceed | |
3011 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 3012 | the global "breakpoint_proceeded" after each command. |
c906108c | 3013 | |
347bddb7 PA |
3014 | Returns true if a breakpoint command resumed the inferior. In that |
3015 | case, it is the caller's responsibility to recall it again with the | |
3016 | bpstat of the current thread. */ | |
3017 | ||
3018 | static int | |
3019 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3020 | { |
3021 | bpstat bs; | |
3022 | struct cleanup *old_chain; | |
347bddb7 | 3023 | int again = 0; |
c906108c SS |
3024 | |
3025 | /* Avoid endless recursion if a `source' command is contained | |
3026 | in bs->commands. */ | |
3027 | if (executing_breakpoint_commands) | |
347bddb7 | 3028 | return 0; |
c906108c SS |
3029 | |
3030 | executing_breakpoint_commands = 1; | |
3031 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3032 | ||
c906108c SS |
3033 | /* This pointer will iterate over the list of bpstat's. */ |
3034 | bs = *bsp; | |
3035 | ||
3036 | breakpoint_proceeded = 0; | |
3037 | for (; bs != NULL; bs = bs->next) | |
3038 | { | |
9add0f1b | 3039 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3040 | struct command_line *cmd; |
3041 | struct cleanup *this_cmd_tree_chain; | |
3042 | ||
3043 | /* Take ownership of the BSP's command tree, if it has one. | |
3044 | ||
3045 | The command tree could legitimately contain commands like | |
3046 | 'step' and 'next', which call clear_proceed_status, which | |
3047 | frees stop_bpstat's command tree. To make sure this doesn't | |
3048 | free the tree we're executing out from under us, we need to | |
3049 | take ownership of the tree ourselves. Since a given bpstat's | |
3050 | commands are only executed once, we don't need to copy it; we | |
3051 | can clear the pointer in the bpstat, and make sure we free | |
3052 | the tree when we're done. */ | |
9add0f1b TT |
3053 | ccmd = bs->commands; |
3054 | bs->commands = NULL; | |
3055 | this_cmd_tree_chain | |
3056 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3057 | cmd = bs->commands_left; | |
3058 | bs->commands_left = NULL; | |
6c50ab1c | 3059 | |
c906108c SS |
3060 | while (cmd != NULL) |
3061 | { | |
3062 | execute_control_command (cmd); | |
3063 | ||
3064 | if (breakpoint_proceeded) | |
3065 | break; | |
3066 | else | |
3067 | cmd = cmd->next; | |
3068 | } | |
6c50ab1c JB |
3069 | |
3070 | /* We can free this command tree now. */ | |
3071 | do_cleanups (this_cmd_tree_chain); | |
3072 | ||
c906108c | 3073 | if (breakpoint_proceeded) |
32c1e744 VP |
3074 | { |
3075 | if (target_can_async_p ()) | |
347bddb7 PA |
3076 | /* If we are in async mode, then the target might be still |
3077 | running, not stopped at any breakpoint, so nothing for | |
3078 | us to do here -- just return to the event loop. */ | |
3079 | ; | |
32c1e744 VP |
3080 | else |
3081 | /* In sync mode, when execute_control_command returns | |
3082 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3083 | Breakpoint commands for that stop were not run, since |
3084 | execute_command does not run breakpoint commands -- | |
3085 | only command_line_handler does, but that one is not | |
3086 | involved in execution of breakpoint commands. So, we | |
3087 | can now execute breakpoint commands. It should be | |
3088 | noted that making execute_command do bpstat actions is | |
3089 | not an option -- in this case we'll have recursive | |
3090 | invocation of bpstat for each breakpoint with a | |
3091 | command, and can easily blow up GDB stack. Instead, we | |
3092 | return true, which will trigger the caller to recall us | |
3093 | with the new stop_bpstat. */ | |
3094 | again = 1; | |
3095 | break; | |
32c1e744 | 3096 | } |
c906108c | 3097 | } |
c2b8ed2c | 3098 | do_cleanups (old_chain); |
347bddb7 PA |
3099 | return again; |
3100 | } | |
3101 | ||
3102 | void | |
3103 | bpstat_do_actions (void) | |
3104 | { | |
3105 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3106 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3107 | && target_has_execution | |
3108 | && !is_exited (inferior_ptid) | |
3109 | && !is_executing (inferior_ptid)) | |
3110 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3111 | and only return when it is stopped at the next breakpoint, we | |
3112 | keep doing breakpoint actions until it returns false to | |
3113 | indicate the inferior was not resumed. */ | |
3114 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
3115 | break; | |
c906108c SS |
3116 | } |
3117 | ||
fa4727a6 DJ |
3118 | /* Print out the (old or new) value associated with a watchpoint. */ |
3119 | ||
3120 | static void | |
3121 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3122 | { | |
3123 | if (val == NULL) | |
3124 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3125 | else | |
79a45b7d TT |
3126 | { |
3127 | struct value_print_options opts; | |
3128 | get_user_print_options (&opts); | |
3129 | value_print (val, stream, &opts); | |
3130 | } | |
fa4727a6 DJ |
3131 | } |
3132 | ||
e514a9d6 | 3133 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3134 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3135 | by having it set different print_it values. |
3136 | ||
3137 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3138 | through the bpstat list of things causing this stop, calling the | |
3139 | print_bp_stop_message function on each one. The behavior of the | |
3140 | print_bp_stop_message function depends on the print_it field of | |
3141 | bpstat. If such field so indicates, call this function here. | |
3142 | ||
3143 | Return values from this routine (ultimately used by bpstat_print() | |
3144 | and normal_stop() to decide what to do): | |
3145 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3146 | don't print anything else. | |
3147 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3148 | that something to be followed by a location. | |
3149 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3150 | that something to be followed by a location. | |
3151 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3152 | analysis. */ | |
c906108c | 3153 | |
917317f4 | 3154 | static enum print_stop_action |
fba45db2 | 3155 | print_it_typical (bpstat bs) |
c906108c | 3156 | { |
f7545552 | 3157 | struct cleanup *old_chain; |
4f8d1dc6 | 3158 | struct breakpoint *b; |
89f9893c | 3159 | const struct bp_location *bl; |
8b93c638 | 3160 | struct ui_stream *stb; |
f7545552 TT |
3161 | int bp_temp = 0; |
3162 | enum print_stop_action result; | |
3163 | ||
c906108c SS |
3164 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3165 | which has since been deleted. */ | |
e514a9d6 | 3166 | if (bs->breakpoint_at == NULL) |
917317f4 | 3167 | return PRINT_UNKNOWN; |
2bdf28a0 | 3168 | |
f431efe5 PA |
3169 | gdb_assert (bs->bp_location_at != NULL); |
3170 | ||
3171 | bl = bs->bp_location_at; | |
3172 | b = bs->breakpoint_at; | |
c906108c | 3173 | |
f7545552 TT |
3174 | stb = ui_out_stream_new (uiout); |
3175 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3176 | ||
4f8d1dc6 | 3177 | switch (b->type) |
c906108c | 3178 | { |
e514a9d6 JM |
3179 | case bp_breakpoint: |
3180 | case bp_hardware_breakpoint: | |
f431efe5 | 3181 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3182 | if (bl->address != bl->requested_address) |
3183 | breakpoint_adjustment_warning (bl->requested_address, | |
3184 | bl->address, | |
4f8d1dc6 VP |
3185 | b->number, 1); |
3186 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3187 | if (bp_temp) |
3188 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3189 | else | |
3190 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3191 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3192 | { |
3193 | ui_out_field_string (uiout, "reason", | |
3194 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3195 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3196 | } | |
4f8d1dc6 | 3197 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3198 | ui_out_text (uiout, ", "); |
f7545552 | 3199 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3200 | break; |
3201 | ||
3202 | case bp_shlib_event: | |
917317f4 JM |
3203 | /* Did we stop because the user set the stop_on_solib_events |
3204 | variable? (If so, we report this as a generic, "Stopped due | |
3205 | to shlib event" message.) */ | |
a3f17187 | 3206 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3207 | result = PRINT_NOTHING; |
e514a9d6 JM |
3208 | break; |
3209 | ||
c4093a6a JM |
3210 | case bp_thread_event: |
3211 | /* Not sure how we will get here. | |
3212 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 3213 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3214 | result = PRINT_NOTHING; |
c4093a6a JM |
3215 | break; |
3216 | ||
1900040c MS |
3217 | case bp_overlay_event: |
3218 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 3219 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3220 | result = PRINT_NOTHING; |
1900040c MS |
3221 | break; |
3222 | ||
0fd8e87f UW |
3223 | case bp_longjmp_master: |
3224 | /* These should never be enabled. */ | |
3225 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3226 | result = PRINT_NOTHING; | |
3227 | break; | |
3228 | ||
aa7d318d TT |
3229 | case bp_std_terminate_master: |
3230 | /* These should never be enabled. */ | |
3231 | printf_filtered (_("std::terminate Master Breakpoint: gdb should not stop!\n")); | |
3232 | result = PRINT_NOTHING; | |
3233 | break; | |
3234 | ||
e514a9d6 JM |
3235 | case bp_watchpoint: |
3236 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3237 | annotate_watchpoint (b->number); |
3238 | if (ui_out_is_mi_like_p (uiout)) | |
3239 | ui_out_field_string | |
3240 | (uiout, "reason", | |
3241 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3242 | mention (b); | |
f7545552 | 3243 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3244 | ui_out_text (uiout, "\nOld value = "); |
3245 | watchpoint_value_print (bs->old_val, stb->stream); | |
3246 | ui_out_field_stream (uiout, "old", stb); | |
3247 | ui_out_text (uiout, "\nNew value = "); | |
3248 | watchpoint_value_print (b->val, stb->stream); | |
3249 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3250 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3251 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3252 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3253 | break; |
3254 | ||
3255 | case bp_read_watchpoint: | |
9dc5e2a9 | 3256 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3257 | ui_out_field_string |
3258 | (uiout, "reason", | |
3259 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3260 | mention (b); |
f7545552 | 3261 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3262 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3263 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3264 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3265 | ui_out_text (uiout, "\n"); |
f7545552 | 3266 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3267 | break; |
3268 | ||
3269 | case bp_access_watchpoint: | |
fa4727a6 | 3270 | if (bs->old_val != NULL) |
8b93c638 | 3271 | { |
4f8d1dc6 | 3272 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3273 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3274 | ui_out_field_string |
3275 | (uiout, "reason", | |
3276 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3277 | mention (b); |
f7545552 | 3278 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3279 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3280 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3281 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3282 | ui_out_text (uiout, "\nNew value = "); |
3283 | } | |
3284 | else | |
3285 | { | |
4f8d1dc6 | 3286 | mention (b); |
9dc5e2a9 | 3287 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3288 | ui_out_field_string |
3289 | (uiout, "reason", | |
3290 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3291 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3292 | ui_out_text (uiout, "\nValue = "); |
3293 | } | |
fa4727a6 | 3294 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3295 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3296 | ui_out_text (uiout, "\n"); |
f7545552 | 3297 | result = PRINT_UNKNOWN; |
e514a9d6 | 3298 | break; |
4ce44c66 | 3299 | |
e514a9d6 JM |
3300 | /* Fall through, we don't deal with these types of breakpoints |
3301 | here. */ | |
3302 | ||
11cf8741 | 3303 | case bp_finish: |
9dc5e2a9 | 3304 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3305 | ui_out_field_string |
3306 | (uiout, "reason", | |
3307 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3308 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3309 | break; |
3310 | ||
e514a9d6 | 3311 | case bp_until: |
9dc5e2a9 | 3312 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3313 | ui_out_field_string |
3314 | (uiout, "reason", | |
3315 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3316 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3317 | break; |
3318 | ||
c2d11a7d | 3319 | case bp_none: |
e514a9d6 JM |
3320 | case bp_longjmp: |
3321 | case bp_longjmp_resume: | |
3322 | case bp_step_resume: | |
e514a9d6 JM |
3323 | case bp_watchpoint_scope: |
3324 | case bp_call_dummy: | |
aa7d318d | 3325 | case bp_std_terminate: |
1042e4c0 | 3326 | case bp_tracepoint: |
7a697b8d | 3327 | case bp_fast_tracepoint: |
4efc6507 | 3328 | case bp_jit_event: |
e514a9d6 | 3329 | default: |
f7545552 TT |
3330 | result = PRINT_UNKNOWN; |
3331 | break; | |
e514a9d6 | 3332 | } |
f7545552 TT |
3333 | |
3334 | do_cleanups (old_chain); | |
3335 | return result; | |
e514a9d6 JM |
3336 | } |
3337 | ||
3338 | /* Generic routine for printing messages indicating why we | |
3339 | stopped. The behavior of this function depends on the value | |
3340 | 'print_it' in the bpstat structure. Under some circumstances we | |
3341 | may decide not to print anything here and delegate the task to | |
3342 | normal_stop(). */ | |
3343 | ||
3344 | static enum print_stop_action | |
3345 | print_bp_stop_message (bpstat bs) | |
3346 | { | |
3347 | switch (bs->print_it) | |
3348 | { | |
3349 | case print_it_noop: | |
3350 | /* Nothing should be printed for this bpstat entry. */ | |
3351 | return PRINT_UNKNOWN; | |
3352 | break; | |
3353 | ||
3354 | case print_it_done: | |
3355 | /* We still want to print the frame, but we already printed the | |
3356 | relevant messages. */ | |
3357 | return PRINT_SRC_AND_LOC; | |
3358 | break; | |
3359 | ||
3360 | case print_it_normal: | |
4f8d1dc6 | 3361 | { |
f431efe5 PA |
3362 | struct breakpoint *b = bs->breakpoint_at; |
3363 | ||
4f8d1dc6 VP |
3364 | /* Normal case. Call the breakpoint's print_it method, or |
3365 | print_it_typical. */ | |
3366 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3367 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3368 | return b->ops->print_it (b); | |
3369 | else | |
3370 | return print_it_typical (bs); | |
3371 | } | |
3372 | break; | |
3086aeae | 3373 | |
e514a9d6 | 3374 | default: |
8e65ff28 | 3375 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3376 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3377 | break; |
c906108c | 3378 | } |
c906108c SS |
3379 | } |
3380 | ||
e514a9d6 JM |
3381 | /* Print a message indicating what happened. This is called from |
3382 | normal_stop(). The input to this routine is the head of the bpstat | |
3383 | list - a list of the eventpoints that caused this stop. This | |
3384 | routine calls the generic print routine for printing a message | |
3385 | about reasons for stopping. This will print (for example) the | |
3386 | "Breakpoint n," part of the output. The return value of this | |
3387 | routine is one of: | |
c906108c | 3388 | |
917317f4 JM |
3389 | PRINT_UNKNOWN: Means we printed nothing |
3390 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3391 | code to print the location. An example is |
3392 | "Breakpoint 1, " which should be followed by | |
3393 | the location. | |
917317f4 | 3394 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3395 | to also print the location part of the message. |
3396 | An example is the catch/throw messages, which | |
917317f4 JM |
3397 | don't require a location appended to the end. |
3398 | PRINT_NOTHING: We have done some printing and we don't need any | |
3399 | further info to be printed.*/ | |
c906108c | 3400 | |
917317f4 | 3401 | enum print_stop_action |
fba45db2 | 3402 | bpstat_print (bpstat bs) |
c906108c SS |
3403 | { |
3404 | int val; | |
c5aa993b | 3405 | |
c906108c | 3406 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3407 | (Currently all watchpoints go on the bpstat whether hit or not. |
3408 | That probably could (should) be changed, provided care is taken | |
c906108c | 3409 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3410 | for (; bs; bs = bs->next) |
3411 | { | |
3412 | val = print_bp_stop_message (bs); | |
3413 | if (val == PRINT_SRC_ONLY | |
3414 | || val == PRINT_SRC_AND_LOC | |
3415 | || val == PRINT_NOTHING) | |
3416 | return val; | |
3417 | } | |
c906108c | 3418 | |
e514a9d6 JM |
3419 | /* We reached the end of the chain, or we got a null BS to start |
3420 | with and nothing was printed. */ | |
917317f4 | 3421 | return PRINT_UNKNOWN; |
c906108c SS |
3422 | } |
3423 | ||
3424 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3425 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3426 | The argument is a "struct expression *" that has been cast to char * to | |
3427 | make it pass through catch_errors. */ | |
3428 | ||
3429 | static int | |
4efb68b1 | 3430 | breakpoint_cond_eval (void *exp) |
c906108c | 3431 | { |
278cd55f | 3432 | struct value *mark = value_mark (); |
c5aa993b | 3433 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3434 | |
c906108c SS |
3435 | value_free_to_mark (mark); |
3436 | return i; | |
3437 | } | |
3438 | ||
3439 | /* Allocate a new bpstat and chain it to the current one. */ | |
3440 | ||
3441 | static bpstat | |
f431efe5 | 3442 | bpstat_alloc (struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3443 | { |
3444 | bpstat bs; | |
3445 | ||
3446 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3447 | cbs->next = bs; | |
f431efe5 PA |
3448 | bs->breakpoint_at = bl->owner; |
3449 | bs->bp_location_at = bl; | |
3450 | incref_bp_location (bl); | |
c906108c SS |
3451 | /* If the condition is false, etc., don't do the commands. */ |
3452 | bs->commands = NULL; | |
9add0f1b | 3453 | bs->commands_left = NULL; |
c906108c SS |
3454 | bs->old_val = NULL; |
3455 | bs->print_it = print_it_normal; | |
3456 | return bs; | |
3457 | } | |
3458 | \f | |
d983da9c DJ |
3459 | /* The target has stopped with waitstatus WS. Check if any hardware |
3460 | watchpoints have triggered, according to the target. */ | |
3461 | ||
3462 | int | |
3463 | watchpoints_triggered (struct target_waitstatus *ws) | |
3464 | { | |
d92524f1 | 3465 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3466 | CORE_ADDR addr; |
3467 | struct breakpoint *b; | |
3468 | ||
3469 | if (!stopped_by_watchpoint) | |
3470 | { | |
3471 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3472 | as not triggered. */ | |
3473 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3474 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3475 | b->watchpoint_triggered = watch_triggered_no; |
3476 | ||
3477 | return 0; | |
3478 | } | |
3479 | ||
3480 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3481 | { | |
3482 | /* We were stopped by a watchpoint, but we don't know where. | |
3483 | Mark all watchpoints as unknown. */ | |
3484 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3485 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3486 | b->watchpoint_triggered = watch_triggered_unknown; |
3487 | ||
3488 | return stopped_by_watchpoint; | |
3489 | } | |
3490 | ||
3491 | /* The target could report the data address. Mark watchpoints | |
3492 | affected by this data address as triggered, and all others as not | |
3493 | triggered. */ | |
3494 | ||
3495 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3496 | if (is_hardware_watchpoint (b)) |
d983da9c | 3497 | { |
a5606eee | 3498 | struct bp_location *loc; |
d983da9c DJ |
3499 | |
3500 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3501 | for (loc = b->loc; loc; loc = loc->next) |
3502 | /* Exact match not required. Within range is | |
3503 | sufficient. */ | |
5009afc5 AS |
3504 | if (target_watchpoint_addr_within_range (¤t_target, |
3505 | addr, loc->address, | |
3506 | loc->length)) | |
a5606eee VP |
3507 | { |
3508 | b->watchpoint_triggered = watch_triggered_yes; | |
3509 | break; | |
3510 | } | |
d983da9c DJ |
3511 | } |
3512 | ||
3513 | return 1; | |
3514 | } | |
3515 | ||
c906108c SS |
3516 | /* Possible return values for watchpoint_check (this can't be an enum |
3517 | because of check_errors). */ | |
3518 | /* The watchpoint has been deleted. */ | |
3519 | #define WP_DELETED 1 | |
3520 | /* The value has changed. */ | |
3521 | #define WP_VALUE_CHANGED 2 | |
3522 | /* The value has not changed. */ | |
3523 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3524 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3525 | #define WP_IGNORE 4 | |
c906108c SS |
3526 | |
3527 | #define BP_TEMPFLAG 1 | |
3528 | #define BP_HARDWAREFLAG 2 | |
3529 | ||
553e4c11 JB |
3530 | /* Evaluate watchpoint condition expression and check if its value changed. |
3531 | ||
3532 | P should be a pointer to struct bpstat, but is defined as a void * | |
3533 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3534 | |
3535 | static int | |
4efb68b1 | 3536 | watchpoint_check (void *p) |
c906108c SS |
3537 | { |
3538 | bpstat bs = (bpstat) p; | |
3539 | struct breakpoint *b; | |
3540 | struct frame_info *fr; | |
3541 | int within_current_scope; | |
3542 | ||
f431efe5 | 3543 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3544 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3545 | b = bs->breakpoint_at; |
c906108c | 3546 | |
f6bc2008 PA |
3547 | /* If this is a local watchpoint, we only want to check if the |
3548 | watchpoint frame is in scope if the current thread is the thread | |
3549 | that was used to create the watchpoint. */ | |
3550 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3551 | return WP_IGNORE; |
f6bc2008 | 3552 | |
c906108c SS |
3553 | if (b->exp_valid_block == NULL) |
3554 | within_current_scope = 1; | |
3555 | else | |
3556 | { | |
edb3359d DJ |
3557 | struct frame_info *frame = get_current_frame (); |
3558 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3559 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3560 | ||
a0f49112 JK |
3561 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3562 | in the function but the stack frame has already been invalidated. | |
3563 | Since we can't rely on the values of local variables after the | |
3564 | stack has been destroyed, we are treating the watchpoint in that | |
3565 | state as `not changed' without further checking. Don't mark | |
3566 | watchpoints as changed if the current frame is in an epilogue - | |
3567 | even if they are in some other frame, our view of the stack | |
3568 | is likely to be wrong and frame_find_by_id could error out. */ | |
3569 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
60e1c644 | 3570 | return WP_IGNORE; |
a0f49112 | 3571 | |
101dcfbe | 3572 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3573 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3574 | |
3575 | /* If we've gotten confused in the unwinder, we might have | |
3576 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3577 | if (within_current_scope) |
3578 | { | |
3579 | struct symbol *function; | |
3580 | ||
3581 | function = get_frame_function (fr); | |
3582 | if (function == NULL | |
3583 | || !contained_in (b->exp_valid_block, | |
3584 | SYMBOL_BLOCK_VALUE (function))) | |
3585 | within_current_scope = 0; | |
3586 | } | |
69fbadd5 | 3587 | |
edb3359d | 3588 | if (within_current_scope) |
c906108c SS |
3589 | /* If we end up stopping, the current frame will get selected |
3590 | in normal_stop. So this call to select_frame won't affect | |
3591 | the user. */ | |
0f7d239c | 3592 | select_frame (fr); |
c906108c | 3593 | } |
c5aa993b | 3594 | |
c906108c SS |
3595 | if (within_current_scope) |
3596 | { | |
3597 | /* We use value_{,free_to_}mark because it could be a | |
3598 | *long* time before we return to the command level and | |
c5aa993b JM |
3599 | call free_all_values. We can't call free_all_values because |
3600 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3601 | |
0cf6dd15 | 3602 | int pc = 0; |
278cd55f | 3603 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3604 | struct value *new_val; |
3605 | ||
0cf6dd15 | 3606 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 TJB |
3607 | |
3608 | /* We use value_equal_contents instead of value_equal because the latter | |
3609 | coerces an array to a pointer, thus comparing just the address of the | |
3610 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3611 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3612 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3613 | { |
fa4727a6 DJ |
3614 | if (new_val != NULL) |
3615 | { | |
3616 | release_value (new_val); | |
3617 | value_free_to_mark (mark); | |
3618 | } | |
c906108c SS |
3619 | bs->old_val = b->val; |
3620 | b->val = new_val; | |
fa4727a6 | 3621 | b->val_valid = 1; |
c906108c SS |
3622 | return WP_VALUE_CHANGED; |
3623 | } | |
3624 | else | |
3625 | { | |
60e1c644 | 3626 | /* Nothing changed. */ |
c906108c | 3627 | value_free_to_mark (mark); |
c906108c SS |
3628 | return WP_VALUE_NOT_CHANGED; |
3629 | } | |
3630 | } | |
3631 | else | |
3632 | { | |
3633 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3634 | if we temporarily ignored the watchpoint, then when |
3635 | we reenter the block in which it is valid it contains | |
3636 | garbage (in the case of a function, it may have two | |
3637 | garbage values, one before and one after the prologue). | |
3638 | So we can't even detect the first assignment to it and | |
3639 | watch after that (since the garbage may or may not equal | |
3640 | the first value assigned). */ | |
4ce44c66 JM |
3641 | /* We print all the stop information in print_it_typical(), but |
3642 | in this case, by the time we call print_it_typical() this bp | |
3643 | will be deleted already. So we have no choice but print the | |
3644 | information here. */ | |
9dc5e2a9 | 3645 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3646 | ui_out_field_string |
3647 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3648 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3649 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3650 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3651 | which its expression is valid.\n"); | |
4ce44c66 | 3652 | |
c906108c | 3653 | if (b->related_breakpoint) |
60e1c644 PA |
3654 | { |
3655 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3656 | b->related_breakpoint->related_breakpoint = NULL; | |
3657 | b->related_breakpoint = NULL; | |
3658 | } | |
b5de0fa7 | 3659 | b->disposition = disp_del_at_next_stop; |
c906108c SS |
3660 | |
3661 | return WP_DELETED; | |
3662 | } | |
3663 | } | |
3664 | ||
18a18393 VP |
3665 | /* Return true if it looks like target has stopped due to hitting |
3666 | breakpoint location BL. This function does not check if we | |
3667 | should stop, only if BL explains the stop. */ | |
3668 | static int | |
6c95b8df PA |
3669 | bpstat_check_location (const struct bp_location *bl, |
3670 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3671 | { |
3672 | struct breakpoint *b = bl->owner; | |
3673 | ||
2bdf28a0 JK |
3674 | /* BL is from existing struct breakpoint. */ |
3675 | gdb_assert (b != NULL); | |
3676 | ||
e8595ef6 SS |
3677 | /* By definition, the inferior does not report stops at |
3678 | tracepoints. */ | |
d77f58be | 3679 | if (is_tracepoint (b)) |
e8595ef6 SS |
3680 | return 0; |
3681 | ||
cc60f2e3 | 3682 | if (!is_watchpoint (b) |
18a18393 | 3683 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3684 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3685 | { |
6c95b8df PA |
3686 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3687 | aspace, bp_addr)) | |
18a18393 VP |
3688 | return 0; |
3689 | if (overlay_debugging /* unmapped overlay section */ | |
3690 | && section_is_overlay (bl->section) | |
3691 | && !section_is_mapped (bl->section)) | |
3692 | return 0; | |
3693 | } | |
cc60f2e3 | 3694 | |
18a18393 VP |
3695 | /* Continuable hardware watchpoints are treated as non-existent if the |
3696 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3697 | some data address). Otherwise gdb won't stop on a break instruction | |
3698 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3699 | been defined. Also skip watchpoints which we know did not trigger | |
3700 | (did not match the data address). */ | |
cc60f2e3 PA |
3701 | |
3702 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3703 | && b->watchpoint_triggered == watch_triggered_no) |
3704 | return 0; | |
3705 | ||
3706 | if (b->type == bp_hardware_breakpoint) | |
3707 | { | |
3708 | if (bl->address != bp_addr) | |
3709 | return 0; | |
3710 | if (overlay_debugging /* unmapped overlay section */ | |
3711 | && section_is_overlay (bl->section) | |
3712 | && !section_is_mapped (bl->section)) | |
3713 | return 0; | |
3714 | } | |
ce78b96d | 3715 | |
ce78b96d JB |
3716 | if (b->type == bp_catchpoint) |
3717 | { | |
3718 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3719 | if (!b->ops->breakpoint_hit (b)) | |
3720 | return 0; | |
3721 | } | |
3722 | ||
18a18393 VP |
3723 | return 1; |
3724 | } | |
3725 | ||
3726 | /* If BS refers to a watchpoint, determine if the watched values | |
3727 | has actually changed, and we should stop. If not, set BS->stop | |
3728 | to 0. */ | |
3729 | static void | |
3730 | bpstat_check_watchpoint (bpstat bs) | |
3731 | { | |
2bdf28a0 JK |
3732 | const struct bp_location *bl; |
3733 | struct breakpoint *b; | |
3734 | ||
3735 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3736 | bl = bs->bp_location_at; |
2bdf28a0 | 3737 | gdb_assert (bl != NULL); |
f431efe5 | 3738 | b = bs->breakpoint_at; |
2bdf28a0 | 3739 | gdb_assert (b != NULL); |
18a18393 | 3740 | |
cc60f2e3 | 3741 | if (is_watchpoint (b)) |
18a18393 | 3742 | { |
18a18393 VP |
3743 | int must_check_value = 0; |
3744 | ||
3745 | if (b->type == bp_watchpoint) | |
3746 | /* For a software watchpoint, we must always check the | |
3747 | watched value. */ | |
3748 | must_check_value = 1; | |
3749 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3750 | /* We have a hardware watchpoint (read, write, or access) | |
3751 | and the target earlier reported an address watched by | |
3752 | this watchpoint. */ | |
3753 | must_check_value = 1; | |
3754 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3755 | && b->type == bp_hardware_watchpoint) | |
3756 | /* We were stopped by a hardware watchpoint, but the target could | |
3757 | not report the data address. We must check the watchpoint's | |
3758 | value. Access and read watchpoints are out of luck; without | |
3759 | a data address, we can't figure it out. */ | |
3760 | must_check_value = 1; | |
3761 | ||
3762 | if (must_check_value) | |
3763 | { | |
3764 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3765 | b->number); | |
3766 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3767 | int e = catch_errors (watchpoint_check, bs, message, | |
3768 | RETURN_MASK_ALL); | |
3769 | do_cleanups (cleanups); | |
3770 | switch (e) | |
3771 | { | |
3772 | case WP_DELETED: | |
3773 | /* We've already printed what needs to be printed. */ | |
3774 | bs->print_it = print_it_done; | |
3775 | /* Stop. */ | |
3776 | break; | |
60e1c644 PA |
3777 | case WP_IGNORE: |
3778 | bs->print_it = print_it_noop; | |
3779 | bs->stop = 0; | |
3780 | break; | |
18a18393 VP |
3781 | case WP_VALUE_CHANGED: |
3782 | if (b->type == bp_read_watchpoint) | |
3783 | { | |
85d721b8 PA |
3784 | /* There are two cases to consider here: |
3785 | ||
3786 | 1. we're watching the triggered memory for reads. | |
3787 | In that case, trust the target, and always report | |
3788 | the watchpoint hit to the user. Even though | |
3789 | reads don't cause value changes, the value may | |
3790 | have changed since the last time it was read, and | |
3791 | since we're not trapping writes, we will not see | |
3792 | those, and as such we should ignore our notion of | |
3793 | old value. | |
3794 | ||
3795 | 2. we're watching the triggered memory for both | |
3796 | reads and writes. There are two ways this may | |
3797 | happen: | |
3798 | ||
3799 | 2.1. this is a target that can't break on data | |
3800 | reads only, but can break on accesses (reads or | |
3801 | writes), such as e.g., x86. We detect this case | |
3802 | at the time we try to insert read watchpoints. | |
3803 | ||
3804 | 2.2. otherwise, the target supports read | |
3805 | watchpoints, but, the user set an access or write | |
3806 | watchpoint watching the same memory as this read | |
3807 | watchpoint. | |
3808 | ||
3809 | If we're watching memory writes as well as reads, | |
3810 | ignore watchpoint hits when we find that the | |
3811 | value hasn't changed, as reads don't cause | |
3812 | changes. This still gives false positives when | |
3813 | the program writes the same value to memory as | |
3814 | what there was already in memory (we will confuse | |
3815 | it for a read), but it's much better than | |
3816 | nothing. */ | |
3817 | ||
3818 | int other_write_watchpoint = 0; | |
3819 | ||
3820 | if (bl->watchpoint_type == hw_read) | |
3821 | { | |
3822 | struct breakpoint *other_b; | |
3823 | ||
3824 | ALL_BREAKPOINTS (other_b) | |
3825 | if ((other_b->type == bp_hardware_watchpoint | |
3826 | || other_b->type == bp_access_watchpoint) | |
3827 | && (other_b->watchpoint_triggered | |
3828 | == watch_triggered_yes)) | |
3829 | { | |
3830 | other_write_watchpoint = 1; | |
3831 | break; | |
3832 | } | |
3833 | } | |
3834 | ||
3835 | if (other_write_watchpoint | |
3836 | || bl->watchpoint_type == hw_access) | |
3837 | { | |
3838 | /* We're watching the same memory for writes, | |
3839 | and the value changed since the last time we | |
3840 | updated it, so this trap must be for a write. | |
3841 | Ignore it. */ | |
3842 | bs->print_it = print_it_noop; | |
3843 | bs->stop = 0; | |
3844 | } | |
18a18393 VP |
3845 | } |
3846 | break; | |
3847 | case WP_VALUE_NOT_CHANGED: | |
3848 | if (b->type == bp_hardware_watchpoint | |
3849 | || b->type == bp_watchpoint) | |
3850 | { | |
3851 | /* Don't stop: write watchpoints shouldn't fire if | |
3852 | the value hasn't changed. */ | |
3853 | bs->print_it = print_it_noop; | |
3854 | bs->stop = 0; | |
3855 | } | |
3856 | /* Stop. */ | |
3857 | break; | |
3858 | default: | |
3859 | /* Can't happen. */ | |
3860 | case 0: | |
3861 | /* Error from catch_errors. */ | |
3862 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3863 | if (b->related_breakpoint) | |
3864 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3865 | b->disposition = disp_del_at_next_stop; | |
3866 | /* We've already printed what needs to be printed. */ | |
3867 | bs->print_it = print_it_done; | |
3868 | break; | |
3869 | } | |
3870 | } | |
3871 | else /* must_check_value == 0 */ | |
3872 | { | |
3873 | /* This is a case where some watchpoint(s) triggered, but | |
3874 | not at the address of this watchpoint, or else no | |
3875 | watchpoint triggered after all. So don't print | |
3876 | anything for this watchpoint. */ | |
3877 | bs->print_it = print_it_noop; | |
3878 | bs->stop = 0; | |
3879 | } | |
3880 | } | |
3881 | } | |
3882 | ||
3883 | ||
3884 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3885 | of breakpoint referred to by BS. If we should not stop for this | |
3886 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 3887 | |
18a18393 VP |
3888 | static void |
3889 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3890 | { | |
3891 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
3892 | const struct bp_location *bl; |
3893 | struct breakpoint *b; | |
3894 | ||
3895 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3896 | bl = bs->bp_location_at; |
2bdf28a0 | 3897 | gdb_assert (bl != NULL); |
f431efe5 | 3898 | b = bs->breakpoint_at; |
2bdf28a0 | 3899 | gdb_assert (b != NULL); |
18a18393 VP |
3900 | |
3901 | if (frame_id_p (b->frame_id) | |
edb3359d | 3902 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3903 | bs->stop = 0; |
3904 | else if (bs->stop) | |
3905 | { | |
3906 | int value_is_zero = 0; | |
60e1c644 PA |
3907 | struct expression *cond; |
3908 | ||
60e1c644 PA |
3909 | if (is_watchpoint (b)) |
3910 | cond = b->cond_exp; | |
3911 | else | |
3912 | cond = bl->cond; | |
3913 | ||
f431efe5 | 3914 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 3915 | { |
60e1c644 PA |
3916 | int within_current_scope = 1; |
3917 | ||
c5bc3a77 DJ |
3918 | /* We use value_mark and value_free_to_mark because it could |
3919 | be a long time before we return to the command level and | |
3920 | call free_all_values. We can't call free_all_values | |
3921 | because we might be in the middle of evaluating a | |
3922 | function call. */ | |
3923 | struct value *mark = value_mark (); | |
3924 | ||
edb3359d DJ |
3925 | /* Need to select the frame, with all that implies so that |
3926 | the conditions will have the right context. Because we | |
3927 | use the frame, we will not see an inlined function's | |
3928 | variables when we arrive at a breakpoint at the start | |
3929 | of the inlined function; the current frame will be the | |
3930 | call site. */ | |
60e1c644 PA |
3931 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
3932 | select_frame (get_current_frame ()); | |
3933 | else | |
3934 | { | |
3935 | struct frame_info *frame; | |
3936 | ||
3937 | /* For local watchpoint expressions, which particular | |
3938 | instance of a local is being watched matters, so we | |
3939 | keep track of the frame to evaluate the expression | |
3940 | in. To evaluate the condition however, it doesn't | |
3941 | really matter which instantiation of the function | |
3942 | where the condition makes sense triggers the | |
3943 | watchpoint. This allows an expression like "watch | |
3944 | global if q > 10" set in `func', catch writes to | |
3945 | global on all threads that call `func', or catch | |
3946 | writes on all recursive calls of `func' by a single | |
3947 | thread. We simply always evaluate the condition in | |
3948 | the innermost frame that's executing where it makes | |
3949 | sense to evaluate the condition. It seems | |
3950 | intuitive. */ | |
3951 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
3952 | if (frame != NULL) | |
3953 | select_frame (frame); | |
3954 | else | |
3955 | within_current_scope = 0; | |
3956 | } | |
3957 | if (within_current_scope) | |
3958 | value_is_zero | |
3959 | = catch_errors (breakpoint_cond_eval, cond, | |
3960 | "Error in testing breakpoint condition:\n", | |
3961 | RETURN_MASK_ALL); | |
3962 | else | |
3963 | { | |
3964 | warning (_("Watchpoint condition cannot be tested " | |
3965 | "in the current scope")); | |
3966 | /* If we failed to set the right context for this | |
3967 | watchpoint, unconditionally report it. */ | |
3968 | value_is_zero = 0; | |
3969 | } | |
18a18393 | 3970 | /* FIXME-someday, should give breakpoint # */ |
c5bc3a77 | 3971 | value_free_to_mark (mark); |
18a18393 | 3972 | } |
60e1c644 PA |
3973 | |
3974 | if (cond && value_is_zero) | |
18a18393 VP |
3975 | { |
3976 | bs->stop = 0; | |
3977 | } | |
3978 | else if (b->thread != -1 && b->thread != thread_id) | |
3979 | { | |
3980 | bs->stop = 0; | |
3981 | } | |
3982 | else if (b->ignore_count > 0) | |
3983 | { | |
3984 | b->ignore_count--; | |
3985 | annotate_ignore_count_change (); | |
3986 | bs->stop = 0; | |
3987 | /* Increase the hit count even though we don't | |
3988 | stop. */ | |
3989 | ++(b->hit_count); | |
3990 | } | |
3991 | } | |
3992 | } | |
3993 | ||
3994 | ||
9709f61c | 3995 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3996 | BP_ADDR in thread PTID. |
c906108c | 3997 | |
d983da9c | 3998 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3999 | don't understand this stop. Result is a chain of bpstat's such that: |
4000 | ||
c5aa993b | 4001 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4002 | |
c5aa993b | 4003 | if we understand why we stopped, the result is not null. |
c906108c | 4004 | |
c5aa993b JM |
4005 | Each element of the chain refers to a particular breakpoint or |
4006 | watchpoint at which we have stopped. (We may have stopped for | |
4007 | several reasons concurrently.) | |
c906108c | 4008 | |
c5aa993b JM |
4009 | Each element of the chain has valid next, breakpoint_at, |
4010 | commands, FIXME??? fields. */ | |
c906108c SS |
4011 | |
4012 | bpstat | |
6c95b8df PA |
4013 | bpstat_stop_status (struct address_space *aspace, |
4014 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4015 | { |
0d381245 | 4016 | struct breakpoint *b = NULL; |
afe38095 | 4017 | struct bp_location *bl; |
20874c92 | 4018 | struct bp_location *loc; |
c906108c SS |
4019 | /* Root of the chain of bpstat's */ |
4020 | struct bpstats root_bs[1]; | |
4021 | /* Pointer to the last thing in the chain currently. */ | |
4022 | bpstat bs = root_bs; | |
20874c92 | 4023 | int ix; |
429374b8 | 4024 | int need_remove_insert; |
f431efe5 | 4025 | int removed_any; |
c906108c | 4026 | |
f431efe5 PA |
4027 | /* First, build the bpstat chain with locations that explain a |
4028 | target stop, while being careful to not set the target running, | |
4029 | as that may invalidate locations (in particular watchpoint | |
4030 | locations are recreated). Resuming will happen here with | |
4031 | breakpoint conditions or watchpoint expressions that include | |
4032 | inferior function calls. */ | |
c5aa993b | 4033 | |
429374b8 JK |
4034 | ALL_BREAKPOINTS (b) |
4035 | { | |
4036 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4037 | continue; | |
a5606eee | 4038 | |
429374b8 JK |
4039 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4040 | { | |
4041 | /* For hardware watchpoints, we look only at the first location. | |
cc60f2e3 PA |
4042 | The watchpoint_check function will work on the entire expression, |
4043 | not the individual locations. For read watchpoints, the | |
4044 | watchpoints_triggered function has checked all locations | |
429374b8 JK |
4045 | already. */ |
4046 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
4047 | break; | |
18a18393 | 4048 | |
429374b8 JK |
4049 | if (bl->shlib_disabled) |
4050 | continue; | |
c5aa993b | 4051 | |
429374b8 JK |
4052 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4053 | continue; | |
c5aa993b | 4054 | |
429374b8 | 4055 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 4056 | |
429374b8 | 4057 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 4058 | |
f431efe5 PA |
4059 | /* Assume we stop. Should we find a watchpoint that is not |
4060 | actually triggered, or if the condition of the breakpoint | |
4061 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4062 | bs->stop = 1; |
4063 | bs->print = 1; | |
d983da9c | 4064 | |
f431efe5 PA |
4065 | /* If this is a scope breakpoint, mark the associated |
4066 | watchpoint as triggered so that we will handle the | |
4067 | out-of-scope event. We'll get to the watchpoint next | |
4068 | iteration. */ | |
4069 | if (b->type == bp_watchpoint_scope) | |
4070 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
4071 | } | |
4072 | } | |
4073 | ||
4074 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4075 | { | |
4076 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, | |
4077 | aspace, bp_addr)) | |
4078 | { | |
4079 | bs = bpstat_alloc (loc, bs); | |
4080 | /* For hits of moribund locations, we should just proceed. */ | |
4081 | bs->stop = 0; | |
4082 | bs->print = 0; | |
4083 | bs->print_it = print_it_noop; | |
4084 | } | |
4085 | } | |
4086 | ||
4087 | /* Terminate the chain. */ | |
4088 | bs->next = NULL; | |
4089 | ||
4090 | /* Now go through the locations that caused the target to stop, and | |
4091 | check whether we're interested in reporting this stop to higher | |
4092 | layers, or whether we should resume the target transparently. */ | |
4093 | ||
4094 | removed_any = 0; | |
4095 | ||
4096 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
4097 | { | |
4098 | if (!bs->stop) | |
4099 | continue; | |
4100 | ||
4101 | bpstat_check_watchpoint (bs); | |
4102 | if (!bs->stop) | |
4103 | continue; | |
4104 | ||
4105 | b = bs->breakpoint_at; | |
18a18393 | 4106 | |
429374b8 | 4107 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d TT |
4108 | || b->type == bp_longjmp_master |
4109 | || b->type == bp_std_terminate_master) | |
429374b8 JK |
4110 | /* We do not stop for these. */ |
4111 | bs->stop = 0; | |
4112 | else | |
4113 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4114 | |
429374b8 JK |
4115 | if (bs->stop) |
4116 | { | |
4117 | ++(b->hit_count); | |
c906108c | 4118 | |
429374b8 JK |
4119 | /* We will stop here */ |
4120 | if (b->disposition == disp_disable) | |
4121 | { | |
4122 | if (b->enable_state != bp_permanent) | |
4123 | b->enable_state = bp_disabled; | |
f431efe5 | 4124 | removed_any = 1; |
429374b8 JK |
4125 | } |
4126 | if (b->silent) | |
4127 | bs->print = 0; | |
4128 | bs->commands = b->commands; | |
9add0f1b TT |
4129 | incref_counted_command_line (bs->commands); |
4130 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4131 | if (bs->commands_left | |
4132 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4133 | || (xdb_commands | |
4134 | && strcmp ("Q", | |
4135 | bs->commands_left->line) == 0))) | |
429374b8 | 4136 | { |
9add0f1b | 4137 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4138 | bs->print = 0; |
4139 | } | |
429374b8 JK |
4140 | } |
4141 | ||
4142 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4143 | if (bs->stop == 0 || bs->print == 0) | |
4144 | bs->print_it = print_it_noop; | |
429374b8 | 4145 | } |
876fa593 | 4146 | |
d983da9c DJ |
4147 | /* If we aren't stopping, the value of some hardware watchpoint may |
4148 | not have changed, but the intermediate memory locations we are | |
4149 | watching may have. Don't bother if we're stopping; this will get | |
4150 | done later. */ | |
d832cb68 | 4151 | need_remove_insert = 0; |
1f7ccab2 | 4152 | if (! bpstat_causes_stop (root_bs->next)) |
d983da9c DJ |
4153 | for (bs = root_bs->next; bs != NULL; bs = bs->next) |
4154 | if (!bs->stop | |
f431efe5 PA |
4155 | && bs->breakpoint_at |
4156 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4157 | { |
f431efe5 | 4158 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4159 | need_remove_insert = 1; |
d983da9c DJ |
4160 | } |
4161 | ||
d832cb68 | 4162 | if (need_remove_insert) |
2d134ed3 | 4163 | update_global_location_list (1); |
f431efe5 PA |
4164 | else if (removed_any) |
4165 | update_global_location_list (0); | |
d832cb68 | 4166 | |
d983da9c | 4167 | return root_bs->next; |
c906108c | 4168 | } |
628fe4e4 JK |
4169 | |
4170 | static void | |
4171 | handle_jit_event (void) | |
4172 | { | |
4173 | struct frame_info *frame; | |
4174 | struct gdbarch *gdbarch; | |
4175 | ||
4176 | /* Switch terminal for any messages produced by | |
4177 | breakpoint_re_set. */ | |
4178 | target_terminal_ours_for_output (); | |
4179 | ||
4180 | frame = get_current_frame (); | |
4181 | gdbarch = get_frame_arch (frame); | |
4182 | ||
4183 | jit_event_handler (gdbarch); | |
4184 | ||
4185 | target_terminal_inferior (); | |
4186 | } | |
4187 | ||
4188 | /* Prepare WHAT final decision for infrun. */ | |
4189 | ||
4190 | /* Decide what infrun needs to do with this bpstat. */ | |
4191 | ||
c906108c | 4192 | struct bpstat_what |
fba45db2 | 4193 | bpstat_what (bpstat bs) |
c906108c | 4194 | { |
c906108c | 4195 | struct bpstat_what retval; |
628fe4e4 JK |
4196 | /* We need to defer calling `solib_add', as adding new symbols |
4197 | resets breakpoints, which in turn deletes breakpoint locations, | |
4198 | and hence may clear unprocessed entries in the BS chain. */ | |
4199 | int shlib_event = 0; | |
4200 | int jit_event = 0; | |
c906108c | 4201 | |
628fe4e4 | 4202 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4203 | retval.call_dummy = STOP_NONE; |
628fe4e4 | 4204 | |
c906108c SS |
4205 | for (; bs != NULL; bs = bs->next) |
4206 | { | |
628fe4e4 JK |
4207 | /* Extract this BS's action. After processing each BS, we check |
4208 | if its action overrides all we've seem so far. */ | |
4209 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4210 | enum bptype bptype; | |
4211 | ||
c906108c | 4212 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4213 | { |
4214 | /* I suspect this can happen if it was a momentary | |
4215 | breakpoint which has since been deleted. */ | |
4216 | bptype = bp_none; | |
4217 | } | |
f431efe5 | 4218 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4219 | bptype = bp_none; |
20874c92 | 4220 | else |
f431efe5 | 4221 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4222 | |
4223 | switch (bptype) | |
c906108c SS |
4224 | { |
4225 | case bp_none: | |
628fe4e4 | 4226 | break; |
c906108c SS |
4227 | case bp_breakpoint: |
4228 | case bp_hardware_breakpoint: | |
4229 | case bp_until: | |
4230 | case bp_finish: | |
4231 | if (bs->stop) | |
4232 | { | |
4233 | if (bs->print) | |
628fe4e4 | 4234 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4235 | else |
628fe4e4 | 4236 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4237 | } |
4238 | else | |
628fe4e4 | 4239 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4240 | break; |
4241 | case bp_watchpoint: | |
4242 | case bp_hardware_watchpoint: | |
4243 | case bp_read_watchpoint: | |
4244 | case bp_access_watchpoint: | |
4245 | if (bs->stop) | |
4246 | { | |
4247 | if (bs->print) | |
628fe4e4 | 4248 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4249 | else |
628fe4e4 | 4250 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4251 | } |
4252 | else | |
628fe4e4 JK |
4253 | { |
4254 | /* There was a watchpoint, but we're not stopping. | |
4255 | This requires no further action. */ | |
4256 | } | |
c906108c SS |
4257 | break; |
4258 | case bp_longjmp: | |
628fe4e4 | 4259 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
c906108c SS |
4260 | break; |
4261 | case bp_longjmp_resume: | |
628fe4e4 | 4262 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
c906108c SS |
4263 | break; |
4264 | case bp_step_resume: | |
4265 | if (bs->stop) | |
628fe4e4 JK |
4266 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4267 | else | |
c906108c | 4268 | { |
628fe4e4 JK |
4269 | /* It is for the wrong frame. */ |
4270 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4271 | } |
c906108c | 4272 | break; |
c906108c | 4273 | case bp_watchpoint_scope: |
c4093a6a | 4274 | case bp_thread_event: |
1900040c | 4275 | case bp_overlay_event: |
0fd8e87f | 4276 | case bp_longjmp_master: |
aa7d318d | 4277 | case bp_std_terminate_master: |
628fe4e4 | 4278 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4279 | break; |
ce78b96d | 4280 | case bp_catchpoint: |
c5aa993b JM |
4281 | if (bs->stop) |
4282 | { | |
4283 | if (bs->print) | |
628fe4e4 | 4284 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4285 | else |
628fe4e4 | 4286 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4287 | } |
4288 | else | |
628fe4e4 JK |
4289 | { |
4290 | /* There was a catchpoint, but we're not stopping. | |
4291 | This requires no further action. */ | |
4292 | } | |
4293 | break; | |
4294 | case bp_shlib_event: | |
4295 | shlib_event = 1; | |
4296 | ||
4297 | /* If requested, stop when the dynamic linker notifies GDB | |
4298 | of events. This allows the user to get control and place | |
4299 | breakpoints in initializer routines for dynamically | |
4300 | loaded objects (among other things). */ | |
4301 | if (stop_on_solib_events) | |
4302 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4303 | else | |
4304 | this_action = BPSTAT_WHAT_SINGLE; | |
4305 | break; | |
4306 | case bp_jit_event: | |
4307 | jit_event = 1; | |
4308 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4309 | break; |
c906108c | 4310 | case bp_call_dummy: |
53a5351d JM |
4311 | /* Make sure the action is stop (silent or noisy), |
4312 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4313 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4314 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4315 | break; |
4316 | case bp_std_terminate: | |
4317 | /* Make sure the action is stop (silent or noisy), | |
4318 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4319 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4320 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4321 | break; |
1042e4c0 | 4322 | case bp_tracepoint: |
7a697b8d | 4323 | case bp_fast_tracepoint: |
0fb4aa4b | 4324 | case bp_static_tracepoint: |
1042e4c0 SS |
4325 | /* Tracepoint hits should not be reported back to GDB, and |
4326 | if one got through somehow, it should have been filtered | |
4327 | out already. */ | |
4328 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4329 | _("bpstat_what: tracepoint encountered")); |
628fe4e4 JK |
4330 | default: |
4331 | internal_error (__FILE__, __LINE__, | |
4332 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4333 | } |
628fe4e4 JK |
4334 | |
4335 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4336 | } |
628fe4e4 JK |
4337 | |
4338 | if (shlib_event) | |
4339 | { | |
4340 | if (debug_infrun) | |
4341 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4342 | ||
4343 | /* Check for any newly added shared libraries if we're supposed | |
4344 | to be adding them automatically. */ | |
4345 | ||
4346 | /* Switch terminal for any messages produced by | |
4347 | breakpoint_re_set. */ | |
4348 | target_terminal_ours_for_output (); | |
4349 | ||
4350 | #ifdef SOLIB_ADD | |
4351 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4352 | #else | |
4353 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4354 | #endif | |
4355 | ||
4356 | target_terminal_inferior (); | |
4357 | } | |
4358 | ||
4359 | if (jit_event) | |
4360 | { | |
4361 | if (debug_infrun) | |
4362 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4363 | ||
4364 | handle_jit_event (); | |
4365 | } | |
4366 | ||
c906108c SS |
4367 | return retval; |
4368 | } | |
4369 | ||
4370 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4371 | without hardware support). This isn't related to a specific bpstat, | |
4372 | just to things like whether watchpoints are set. */ | |
4373 | ||
c5aa993b | 4374 | int |
fba45db2 | 4375 | bpstat_should_step (void) |
c906108c SS |
4376 | { |
4377 | struct breakpoint *b; | |
cc59ec59 | 4378 | |
c906108c | 4379 | ALL_BREAKPOINTS (b) |
717a8278 | 4380 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4381 | return 1; |
c906108c SS |
4382 | return 0; |
4383 | } | |
4384 | ||
67822962 PA |
4385 | int |
4386 | bpstat_causes_stop (bpstat bs) | |
4387 | { | |
4388 | for (; bs != NULL; bs = bs->next) | |
4389 | if (bs->stop) | |
4390 | return 1; | |
4391 | ||
4392 | return 0; | |
4393 | } | |
4394 | ||
c906108c | 4395 | \f |
c5aa993b | 4396 | |
859825b8 JK |
4397 | /* Print the LOC location out of the list of B->LOC locations. */ |
4398 | ||
0d381245 VP |
4399 | static void print_breakpoint_location (struct breakpoint *b, |
4400 | struct bp_location *loc, | |
4401 | char *wrap_indent, | |
4402 | struct ui_stream *stb) | |
4403 | { | |
6c95b8df PA |
4404 | struct cleanup *old_chain = save_current_program_space (); |
4405 | ||
859825b8 JK |
4406 | if (loc != NULL && loc->shlib_disabled) |
4407 | loc = NULL; | |
4408 | ||
6c95b8df PA |
4409 | if (loc != NULL) |
4410 | set_current_program_space (loc->pspace); | |
4411 | ||
859825b8 | 4412 | if (b->source_file && loc) |
0d381245 VP |
4413 | { |
4414 | struct symbol *sym | |
4415 | = find_pc_sect_function (loc->address, loc->section); | |
4416 | if (sym) | |
4417 | { | |
4418 | ui_out_text (uiout, "in "); | |
4419 | ui_out_field_string (uiout, "func", | |
4420 | SYMBOL_PRINT_NAME (sym)); | |
4421 | ui_out_wrap_hint (uiout, wrap_indent); | |
4422 | ui_out_text (uiout, " at "); | |
4423 | } | |
4424 | ui_out_field_string (uiout, "file", b->source_file); | |
4425 | ui_out_text (uiout, ":"); | |
4426 | ||
4427 | if (ui_out_is_mi_like_p (uiout)) | |
4428 | { | |
4429 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4430 | char *fullname = symtab_to_fullname (sal.symtab); | |
4431 | ||
4432 | if (fullname) | |
4433 | ui_out_field_string (uiout, "fullname", fullname); | |
4434 | } | |
4435 | ||
4436 | ui_out_field_int (uiout, "line", b->line_number); | |
4437 | } | |
859825b8 | 4438 | else if (loc) |
0d381245 | 4439 | { |
22e722e1 DJ |
4440 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4441 | demangle, ""); | |
0d381245 VP |
4442 | ui_out_field_stream (uiout, "at", stb); |
4443 | } | |
859825b8 JK |
4444 | else |
4445 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4446 | |
4447 | do_cleanups (old_chain); | |
0d381245 VP |
4448 | } |
4449 | ||
269b11a2 PA |
4450 | static const char * |
4451 | bptype_string (enum bptype type) | |
c906108c | 4452 | { |
c4093a6a JM |
4453 | struct ep_type_description |
4454 | { | |
4455 | enum bptype type; | |
4456 | char *description; | |
4457 | }; | |
4458 | static struct ep_type_description bptypes[] = | |
c906108c | 4459 | { |
c5aa993b JM |
4460 | {bp_none, "?deleted?"}, |
4461 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4462 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4463 | {bp_until, "until"}, |
4464 | {bp_finish, "finish"}, | |
4465 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4466 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4467 | {bp_read_watchpoint, "read watchpoint"}, |
4468 | {bp_access_watchpoint, "acc watchpoint"}, | |
4469 | {bp_longjmp, "longjmp"}, | |
4470 | {bp_longjmp_resume, "longjmp resume"}, | |
4471 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4472 | {bp_watchpoint_scope, "watchpoint scope"}, |
4473 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4474 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4475 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4476 | {bp_thread_event, "thread events"}, |
1900040c | 4477 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4478 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4479 | {bp_std_terminate_master, "std::terminate master"}, |
ce78b96d | 4480 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4481 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4482 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4483 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4484 | {bp_jit_event, "jit events"}, |
c5aa993b | 4485 | }; |
269b11a2 PA |
4486 | |
4487 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4488 | || ((int) type != bptypes[(int) type].type)) | |
4489 | internal_error (__FILE__, __LINE__, | |
4490 | _("bptypes table does not describe type #%d."), | |
4491 | (int) type); | |
4492 | ||
4493 | return bptypes[(int) type].description; | |
4494 | } | |
4495 | ||
4496 | /* Print B to gdb_stdout. */ | |
4497 | ||
4498 | static void | |
4499 | print_one_breakpoint_location (struct breakpoint *b, | |
4500 | struct bp_location *loc, | |
4501 | int loc_number, | |
4502 | struct bp_location **last_loc, | |
4503 | int print_address_bits, | |
4504 | int allflag) | |
4505 | { | |
4506 | struct command_line *l; | |
c2c6d25f | 4507 | static char bpenables[] = "nynny"; |
c906108c | 4508 | char wrap_indent[80]; |
8b93c638 JM |
4509 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4510 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4511 | struct cleanup *bkpt_chain; |
c906108c | 4512 | |
0d381245 VP |
4513 | int header_of_multiple = 0; |
4514 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4515 | struct value_print_options opts; |
4516 | ||
4517 | get_user_print_options (&opts); | |
0d381245 VP |
4518 | |
4519 | gdb_assert (!loc || loc_number != 0); | |
4520 | /* See comment in print_one_breakpoint concerning | |
4521 | treatment of breakpoints with single disabled | |
4522 | location. */ | |
4523 | if (loc == NULL | |
4524 | && (b->loc != NULL | |
4525 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4526 | header_of_multiple = 1; | |
4527 | if (loc == NULL) | |
4528 | loc = b->loc; | |
4529 | ||
c4093a6a | 4530 | annotate_record (); |
3b31d625 | 4531 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4532 | |
4533 | /* 1 */ | |
4534 | annotate_field (0); | |
0d381245 VP |
4535 | if (part_of_multiple) |
4536 | { | |
4537 | char *formatted; | |
0c6773c1 | 4538 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4539 | ui_out_field_string (uiout, "number", formatted); |
4540 | xfree (formatted); | |
4541 | } | |
4542 | else | |
4543 | { | |
4544 | ui_out_field_int (uiout, "number", b->number); | |
4545 | } | |
c4093a6a JM |
4546 | |
4547 | /* 2 */ | |
4548 | annotate_field (1); | |
0d381245 VP |
4549 | if (part_of_multiple) |
4550 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4551 | else |
4552 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4553 | |
4554 | /* 3 */ | |
4555 | annotate_field (2); | |
0d381245 VP |
4556 | if (part_of_multiple) |
4557 | ui_out_field_skip (uiout, "disp"); | |
4558 | else | |
2cec12e5 | 4559 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4560 | |
c4093a6a JM |
4561 | |
4562 | /* 4 */ | |
4563 | annotate_field (3); | |
0d381245 | 4564 | if (part_of_multiple) |
54e52265 | 4565 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4566 | else |
54e52265 VP |
4567 | ui_out_field_fmt (uiout, "enabled", "%c", |
4568 | bpenables[(int) b->enable_state]); | |
4569 | ui_out_spaces (uiout, 2); | |
0d381245 | 4570 | |
c4093a6a JM |
4571 | |
4572 | /* 5 and 6 */ | |
4573 | strcpy (wrap_indent, " "); | |
79a45b7d | 4574 | if (opts.addressprint) |
75ac9d7b | 4575 | { |
a6d9a66e | 4576 | if (print_address_bits <= 32) |
75ac9d7b MS |
4577 | strcat (wrap_indent, " "); |
4578 | else | |
4579 | strcat (wrap_indent, " "); | |
4580 | } | |
c906108c | 4581 | |
3086aeae | 4582 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4583 | { |
4584 | /* Although the print_one can possibly print | |
4585 | all locations, calling it here is not likely | |
4586 | to get any nice result. So, make sure there's | |
4587 | just one location. */ | |
4588 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4589 | b->ops->print_one (b, last_loc); |
0d381245 | 4590 | } |
3086aeae DJ |
4591 | else |
4592 | switch (b->type) | |
4593 | { | |
4594 | case bp_none: | |
4595 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4596 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4597 | break; |
c906108c | 4598 | |
3086aeae DJ |
4599 | case bp_watchpoint: |
4600 | case bp_hardware_watchpoint: | |
4601 | case bp_read_watchpoint: | |
4602 | case bp_access_watchpoint: | |
4603 | /* Field 4, the address, is omitted (which makes the columns | |
4604 | not line up too nicely with the headers, but the effect | |
4605 | is relatively readable). */ | |
79a45b7d | 4606 | if (opts.addressprint) |
3086aeae DJ |
4607 | ui_out_field_skip (uiout, "addr"); |
4608 | annotate_field (5); | |
fa8a61dc | 4609 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4610 | break; |
4611 | ||
3086aeae DJ |
4612 | case bp_breakpoint: |
4613 | case bp_hardware_breakpoint: | |
4614 | case bp_until: | |
4615 | case bp_finish: | |
4616 | case bp_longjmp: | |
4617 | case bp_longjmp_resume: | |
4618 | case bp_step_resume: | |
3086aeae DJ |
4619 | case bp_watchpoint_scope: |
4620 | case bp_call_dummy: | |
aa7d318d | 4621 | case bp_std_terminate: |
3086aeae DJ |
4622 | case bp_shlib_event: |
4623 | case bp_thread_event: | |
4624 | case bp_overlay_event: | |
0fd8e87f | 4625 | case bp_longjmp_master: |
aa7d318d | 4626 | case bp_std_terminate_master: |
1042e4c0 | 4627 | case bp_tracepoint: |
7a697b8d | 4628 | case bp_fast_tracepoint: |
0fb4aa4b | 4629 | case bp_static_tracepoint: |
4efc6507 | 4630 | case bp_jit_event: |
79a45b7d | 4631 | if (opts.addressprint) |
3086aeae DJ |
4632 | { |
4633 | annotate_field (4); | |
54e52265 | 4634 | if (header_of_multiple) |
0d381245 | 4635 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4636 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4637 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4638 | else |
5af949e3 UW |
4639 | ui_out_field_core_addr (uiout, "addr", |
4640 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4641 | } |
4642 | annotate_field (5); | |
0d381245 VP |
4643 | if (!header_of_multiple) |
4644 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4645 | if (b->loc) | |
a6d9a66e | 4646 | *last_loc = b->loc; |
3086aeae DJ |
4647 | break; |
4648 | } | |
c906108c | 4649 | |
6c95b8df PA |
4650 | |
4651 | /* For backward compatibility, don't display inferiors unless there | |
4652 | are several. */ | |
4653 | if (loc != NULL | |
4654 | && !header_of_multiple | |
4655 | && (allflag | |
4656 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4657 | && (number_of_program_spaces () > 1 | |
4658 | || number_of_inferiors () > 1) | |
2bdf28a0 JK |
4659 | /* LOC is for existing B, it cannot be in moribund_locations and |
4660 | thus having NULL OWNER. */ | |
6c95b8df PA |
4661 | && loc->owner->type != bp_catchpoint))) |
4662 | { | |
4663 | struct inferior *inf; | |
4664 | int first = 1; | |
4665 | ||
4666 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4667 | { | |
4668 | if (inf->pspace == loc->pspace) | |
4669 | { | |
4670 | if (first) | |
4671 | { | |
4672 | first = 0; | |
4673 | ui_out_text (uiout, " inf "); | |
4674 | } | |
4675 | else | |
4676 | ui_out_text (uiout, ", "); | |
4677 | ui_out_text (uiout, plongest (inf->num)); | |
4678 | } | |
4679 | } | |
4680 | } | |
4681 | ||
4a306c9a | 4682 | if (!part_of_multiple) |
c4093a6a | 4683 | { |
4a306c9a JB |
4684 | if (b->thread != -1) |
4685 | { | |
4686 | /* FIXME: This seems to be redundant and lost here; see the | |
4687 | "stop only in" line a little further down. */ | |
4688 | ui_out_text (uiout, " thread "); | |
4689 | ui_out_field_int (uiout, "thread", b->thread); | |
4690 | } | |
4691 | else if (b->task != 0) | |
4692 | { | |
4693 | ui_out_text (uiout, " task "); | |
4694 | ui_out_field_int (uiout, "task", b->task); | |
4695 | } | |
c4093a6a JM |
4696 | } |
4697 | ||
8b93c638 | 4698 | ui_out_text (uiout, "\n"); |
c4093a6a | 4699 | |
0fb4aa4b PA |
4700 | if (!part_of_multiple && b->static_trace_marker_id) |
4701 | { | |
4702 | gdb_assert (b->type == bp_static_tracepoint); | |
4703 | ||
4704 | ui_out_text (uiout, "\tmarker id is "); | |
4705 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
4706 | b->static_trace_marker_id); | |
4707 | ui_out_text (uiout, "\n"); | |
4708 | } | |
4709 | ||
0d381245 | 4710 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4711 | { |
4712 | annotate_field (6); | |
8b93c638 | 4713 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4714 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4715 | the frame ID. */ | |
5af949e3 UW |
4716 | ui_out_field_core_addr (uiout, "frame", |
4717 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4718 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4719 | } |
4720 | ||
0d381245 | 4721 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4722 | { |
f7f9143b JB |
4723 | /* We do not print the condition for Ada exception catchpoints |
4724 | because the condition is an internal implementation detail | |
4725 | that we do not want to expose to the user. */ | |
c4093a6a | 4726 | annotate_field (7); |
d77f58be | 4727 | if (is_tracepoint (b)) |
1042e4c0 SS |
4728 | ui_out_text (uiout, "\ttrace only if "); |
4729 | else | |
4730 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4731 | ui_out_field_string (uiout, "cond", b->cond_string); |
4732 | ui_out_text (uiout, "\n"); | |
4733 | } | |
4734 | ||
0d381245 | 4735 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4736 | { |
4737 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4738 | ui_out_text (uiout, "\tstop only in thread "); |
4739 | ui_out_field_int (uiout, "thread", b->thread); | |
4740 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4741 | } |
4742 | ||
63c715c6 | 4743 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4744 | { |
4745 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4746 | if (ep_is_catchpoint (b)) |
4747 | ui_out_text (uiout, "\tcatchpoint"); | |
4748 | else | |
4749 | ui_out_text (uiout, "\tbreakpoint"); | |
4750 | ui_out_text (uiout, " already hit "); | |
4751 | ui_out_field_int (uiout, "times", b->hit_count); | |
4752 | if (b->hit_count == 1) | |
4753 | ui_out_text (uiout, " time\n"); | |
4754 | else | |
4755 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4756 | } |
4757 | ||
fb40c209 AC |
4758 | /* Output the count also if it is zero, but only if this is |
4759 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4760 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4761 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4762 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4763 | |
0d381245 | 4764 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4765 | { |
4766 | annotate_field (8); | |
8b93c638 JM |
4767 | ui_out_text (uiout, "\tignore next "); |
4768 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4769 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4770 | } |
059fb39f | 4771 | |
9add0f1b | 4772 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 4773 | if (!part_of_multiple && l) |
c4093a6a | 4774 | { |
3b31d625 EZ |
4775 | struct cleanup *script_chain; |
4776 | ||
c4093a6a | 4777 | annotate_field (9); |
3b31d625 | 4778 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4779 | print_command_lines (uiout, l, 4); |
3b31d625 | 4780 | do_cleanups (script_chain); |
c4093a6a | 4781 | } |
d24317b4 | 4782 | |
1042e4c0 SS |
4783 | if (!part_of_multiple && b->pass_count) |
4784 | { | |
4785 | annotate_field (10); | |
4786 | ui_out_text (uiout, "\tpass count "); | |
4787 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4788 | ui_out_text (uiout, " \n"); | |
4789 | } | |
4790 | ||
d24317b4 VP |
4791 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4792 | { | |
4793 | if (b->addr_string) | |
4794 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4795 | else if (b->exp_string) | |
4796 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4797 | } | |
4798 | ||
3b31d625 | 4799 | do_cleanups (bkpt_chain); |
8b93c638 | 4800 | do_cleanups (old_chain); |
c4093a6a | 4801 | } |
c5aa993b | 4802 | |
0d381245 VP |
4803 | static void |
4804 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4805 | struct bp_location **last_loc, int print_address_bits, |
4806 | int allflag) | |
0d381245 | 4807 | { |
6c95b8df PA |
4808 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4809 | print_address_bits, allflag); | |
0d381245 VP |
4810 | |
4811 | /* If this breakpoint has custom print function, | |
4812 | it's already printed. Otherwise, print individual | |
4813 | locations, if any. */ | |
4814 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4815 | { | |
4816 | /* If breakpoint has a single location that is | |
4817 | disabled, we print it as if it had | |
4818 | several locations, since otherwise it's hard to | |
4819 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4820 | situation. |
4821 | Note that while hardware watchpoints have | |
4822 | several locations internally, that's no a property | |
4823 | exposed to user. */ | |
0d381245 | 4824 | if (b->loc |
a5606eee | 4825 | && !is_hardware_watchpoint (b) |
0d381245 | 4826 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4827 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4828 | { |
4829 | struct bp_location *loc; | |
4830 | int n = 1; | |
4831 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4832 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4833 | print_address_bits, allflag); |
0d381245 VP |
4834 | } |
4835 | } | |
4836 | } | |
4837 | ||
a6d9a66e UW |
4838 | static int |
4839 | breakpoint_address_bits (struct breakpoint *b) | |
4840 | { | |
4841 | int print_address_bits = 0; | |
4842 | struct bp_location *loc; | |
4843 | ||
4844 | for (loc = b->loc; loc; loc = loc->next) | |
4845 | { | |
c7437ca6 PA |
4846 | int addr_bit; |
4847 | ||
4848 | /* Software watchpoints that aren't watching memory don't have | |
4849 | an address to print. */ | |
4850 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4851 | continue; | |
4852 | ||
4853 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4854 | if (addr_bit > print_address_bits) |
4855 | print_address_bits = addr_bit; | |
4856 | } | |
4857 | ||
4858 | return print_address_bits; | |
4859 | } | |
0d381245 | 4860 | |
c4093a6a JM |
4861 | struct captured_breakpoint_query_args |
4862 | { | |
4863 | int bnum; | |
4864 | }; | |
c5aa993b | 4865 | |
c4093a6a | 4866 | static int |
2b65245e | 4867 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4868 | { |
4869 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4870 | struct breakpoint *b; |
a6d9a66e | 4871 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 4872 | |
c4093a6a JM |
4873 | ALL_BREAKPOINTS (b) |
4874 | { | |
4875 | if (args->bnum == b->number) | |
c5aa993b | 4876 | { |
a6d9a66e | 4877 | int print_address_bits = breakpoint_address_bits (b); |
cc59ec59 | 4878 | |
6c95b8df | 4879 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4880 | return GDB_RC_OK; |
c5aa993b | 4881 | } |
c4093a6a JM |
4882 | } |
4883 | return GDB_RC_NONE; | |
4884 | } | |
c5aa993b | 4885 | |
c4093a6a | 4886 | enum gdb_rc |
ce43223b | 4887 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4888 | { |
4889 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 4890 | |
c4093a6a JM |
4891 | args.bnum = bnum; |
4892 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4893 | an error. */ | |
b0b13bb4 DJ |
4894 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4895 | error_message, RETURN_MASK_ALL) < 0) | |
4896 | return GDB_RC_FAIL; | |
4897 | else | |
4898 | return GDB_RC_OK; | |
c4093a6a | 4899 | } |
c5aa993b | 4900 | |
7f3b0473 AC |
4901 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4902 | catchpoints, et.al.). */ | |
4903 | ||
4904 | static int | |
4905 | user_settable_breakpoint (const struct breakpoint *b) | |
4906 | { | |
4907 | return (b->type == bp_breakpoint | |
ce78b96d | 4908 | || b->type == bp_catchpoint |
7f3b0473 | 4909 | || b->type == bp_hardware_breakpoint |
d77f58be | 4910 | || is_tracepoint (b) |
cc60f2e3 | 4911 | || is_watchpoint (b)); |
7f3b0473 AC |
4912 | } |
4913 | ||
4914 | /* Print information on user settable breakpoint (watchpoint, etc) | |
d77f58be SS |
4915 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
4916 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
4917 | FILTER is non-NULL, call it on each breakpoint and only include the | |
4918 | ones for which it returns non-zero. Return the total number of | |
4919 | breakpoints listed. */ | |
c906108c | 4920 | |
d77f58be SS |
4921 | static int |
4922 | breakpoint_1 (int bnum, int allflag, int (*filter) (const struct breakpoint *)) | |
c4093a6a | 4923 | { |
52f0bd74 | 4924 | struct breakpoint *b; |
a6d9a66e | 4925 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4926 | int nr_printable_breakpoints; |
3b31d625 | 4927 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4928 | struct value_print_options opts; |
a6d9a66e | 4929 | int print_address_bits = 0; |
269b11a2 PA |
4930 | int print_type_col_width = 14; |
4931 | ||
79a45b7d TT |
4932 | get_user_print_options (&opts); |
4933 | ||
a6d9a66e UW |
4934 | /* Compute the number of rows in the table, as well as the |
4935 | size required for address fields. */ | |
7f3b0473 AC |
4936 | nr_printable_breakpoints = 0; |
4937 | ALL_BREAKPOINTS (b) | |
4938 | if (bnum == -1 | |
4939 | || bnum == b->number) | |
4940 | { | |
d77f58be SS |
4941 | /* If we have a filter, only list the breakpoints it accepts. */ |
4942 | if (filter && !filter (b)) | |
4943 | continue; | |
4944 | ||
7f3b0473 | 4945 | if (allflag || user_settable_breakpoint (b)) |
a6d9a66e | 4946 | { |
269b11a2 PA |
4947 | int addr_bit, type_len; |
4948 | ||
4949 | addr_bit = breakpoint_address_bits (b); | |
a6d9a66e UW |
4950 | if (addr_bit > print_address_bits) |
4951 | print_address_bits = addr_bit; | |
4952 | ||
269b11a2 PA |
4953 | type_len = strlen (bptype_string (b->type)); |
4954 | if (type_len > print_type_col_width) | |
4955 | print_type_col_width = type_len; | |
4956 | ||
a6d9a66e UW |
4957 | nr_printable_breakpoints++; |
4958 | } | |
7f3b0473 AC |
4959 | } |
4960 | ||
79a45b7d | 4961 | if (opts.addressprint) |
3b31d625 EZ |
4962 | bkpttbl_chain |
4963 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4964 | "BreakpointTable"); | |
8b93c638 | 4965 | else |
3b31d625 EZ |
4966 | bkpttbl_chain |
4967 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4968 | "BreakpointTable"); | |
8b93c638 | 4969 | |
7f3b0473 | 4970 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4971 | annotate_breakpoints_headers (); |
4972 | if (nr_printable_breakpoints > 0) | |
4973 | annotate_field (0); | |
0d381245 | 4974 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4975 | if (nr_printable_breakpoints > 0) |
4976 | annotate_field (1); | |
269b11a2 PA |
4977 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4978 | "type", "Type"); /* 2 */ | |
d7faa9e7 AC |
4979 | if (nr_printable_breakpoints > 0) |
4980 | annotate_field (2); | |
4981 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4982 | if (nr_printable_breakpoints > 0) | |
4983 | annotate_field (3); | |
54e52265 | 4984 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4985 | if (opts.addressprint) |
7f3b0473 | 4986 | { |
d7faa9e7 AC |
4987 | if (nr_printable_breakpoints > 0) |
4988 | annotate_field (4); | |
a6d9a66e | 4989 | if (print_address_bits <= 32) |
b25959ec | 4990 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4991 | else |
b25959ec | 4992 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4993 | } |
d7faa9e7 AC |
4994 | if (nr_printable_breakpoints > 0) |
4995 | annotate_field (5); | |
4996 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4997 | ui_out_table_body (uiout); | |
4998 | if (nr_printable_breakpoints > 0) | |
4999 | annotate_breakpoints_table (); | |
7f3b0473 | 5000 | |
c4093a6a | 5001 | ALL_BREAKPOINTS (b) |
bad56014 TT |
5002 | { |
5003 | QUIT; | |
c4093a6a JM |
5004 | if (bnum == -1 |
5005 | || bnum == b->number) | |
5006 | { | |
d77f58be SS |
5007 | /* If we have a filter, only list the breakpoints it accepts. */ |
5008 | if (filter && !filter (b)) | |
5009 | continue; | |
5010 | ||
c4093a6a JM |
5011 | /* We only print out user settable breakpoints unless the |
5012 | allflag is set. */ | |
7f3b0473 | 5013 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 5014 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a | 5015 | } |
bad56014 | 5016 | } |
c4093a6a | 5017 | |
3b31d625 | 5018 | do_cleanups (bkpttbl_chain); |
698384cd | 5019 | |
7f3b0473 | 5020 | if (nr_printable_breakpoints == 0) |
c906108c | 5021 | { |
d77f58be SS |
5022 | /* If there's a filter, let the caller decide how to report empty list. */ |
5023 | if (!filter) | |
5024 | { | |
5025 | if (bnum == -1) | |
5026 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
5027 | else | |
5028 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
5029 | bnum); | |
5030 | } | |
c906108c SS |
5031 | } |
5032 | else | |
c4093a6a | 5033 | { |
a6d9a66e UW |
5034 | if (last_loc && !server_command) |
5035 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5036 | } |
c906108c | 5037 | |
c4093a6a JM |
5038 | /* FIXME? Should this be moved up so that it is only called when |
5039 | there have been breakpoints? */ | |
c906108c | 5040 | annotate_breakpoints_table_end (); |
d77f58be SS |
5041 | |
5042 | return nr_printable_breakpoints; | |
c906108c SS |
5043 | } |
5044 | ||
ad443146 SS |
5045 | /* Display the value of default-collect in a way that is generally |
5046 | compatible with the breakpoint list. */ | |
5047 | ||
5048 | static void | |
5049 | default_collect_info (void) | |
5050 | { | |
5051 | /* If it has no value (which is frequently the case), say nothing; a | |
5052 | message like "No default-collect." gets in user's face when it's | |
5053 | not wanted. */ | |
5054 | if (!*default_collect) | |
5055 | return; | |
5056 | ||
5057 | /* The following phrase lines up nicely with per-tracepoint collect | |
5058 | actions. */ | |
5059 | ui_out_text (uiout, "default collect "); | |
5060 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5061 | ui_out_text (uiout, " \n"); | |
5062 | } | |
5063 | ||
c906108c | 5064 | static void |
fba45db2 | 5065 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
5066 | { |
5067 | int bnum = -1; | |
5068 | ||
5069 | if (bnum_exp) | |
bb518678 | 5070 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5071 | |
d77f58be | 5072 | breakpoint_1 (bnum, 0, NULL); |
ad443146 SS |
5073 | |
5074 | default_collect_info (); | |
d77f58be SS |
5075 | } |
5076 | ||
5077 | static void | |
5078 | watchpoints_info (char *wpnum_exp, int from_tty) | |
5079 | { | |
5080 | int wpnum = -1, num_printed; | |
5081 | ||
5082 | if (wpnum_exp) | |
5083 | wpnum = parse_and_eval_long (wpnum_exp); | |
5084 | ||
5085 | num_printed = breakpoint_1 (wpnum, 0, is_watchpoint); | |
5086 | ||
5087 | if (num_printed == 0) | |
5088 | { | |
5089 | if (wpnum == -1) | |
5090 | ui_out_message (uiout, 0, "No watchpoints.\n"); | |
5091 | else | |
5092 | ui_out_message (uiout, 0, "No watchpoint number %d.\n", wpnum); | |
5093 | } | |
c906108c SS |
5094 | } |
5095 | ||
7a292a7a | 5096 | static void |
fba45db2 | 5097 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
5098 | { |
5099 | int bnum = -1; | |
5100 | ||
5101 | if (bnum_exp) | |
bb518678 | 5102 | bnum = parse_and_eval_long (bnum_exp); |
c906108c | 5103 | |
d77f58be | 5104 | breakpoint_1 (bnum, 1, NULL); |
ad443146 SS |
5105 | |
5106 | default_collect_info (); | |
c906108c SS |
5107 | } |
5108 | ||
0d381245 | 5109 | static int |
714835d5 | 5110 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5111 | struct program_space *pspace, |
714835d5 | 5112 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5113 | { |
5114 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5115 | |
0d381245 VP |
5116 | for (; bl; bl = bl->next) |
5117 | { | |
6c95b8df PA |
5118 | if (bl->pspace == pspace |
5119 | && bl->address == pc | |
0d381245 VP |
5120 | && (!overlay_debugging || bl->section == section)) |
5121 | return 1; | |
5122 | } | |
5123 | return 0; | |
5124 | } | |
5125 | ||
6c95b8df PA |
5126 | /* Print a message describing any breakpoints set at PC. This |
5127 | concerns with logical breakpoints, so we match program spaces, not | |
5128 | address spaces. */ | |
c906108c SS |
5129 | |
5130 | static void | |
6c95b8df PA |
5131 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5132 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5133 | struct obj_section *section, int thread) |
c906108c | 5134 | { |
52f0bd74 AC |
5135 | int others = 0; |
5136 | struct breakpoint *b; | |
c906108c SS |
5137 | |
5138 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5139 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5140 | if (others > 0) |
5141 | { | |
a3f17187 AC |
5142 | if (others == 1) |
5143 | printf_filtered (_("Note: breakpoint ")); | |
5144 | else /* if (others == ???) */ | |
5145 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5146 | ALL_BREAKPOINTS (b) |
6c95b8df | 5147 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5148 | { |
5149 | others--; | |
5150 | printf_filtered ("%d", b->number); | |
5151 | if (b->thread == -1 && thread != -1) | |
5152 | printf_filtered (" (all threads)"); | |
5153 | else if (b->thread != -1) | |
5154 | printf_filtered (" (thread %d)", b->thread); | |
5155 | printf_filtered ("%s%s ", | |
059fb39f | 5156 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5157 | || b->enable_state == bp_call_disabled |
5158 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5159 | ? " (disabled)" |
5160 | : b->enable_state == bp_permanent | |
5161 | ? " (permanent)" | |
5162 | : ""), | |
5163 | (others > 1) ? "," | |
5164 | : ((others == 1) ? " and" : "")); | |
5165 | } | |
a3f17187 | 5166 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5167 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5168 | printf_filtered (".\n"); |
5169 | } | |
5170 | } | |
5171 | \f | |
5172 | /* Set the default place to put a breakpoint | |
5173 | for the `break' command with no arguments. */ | |
5174 | ||
5175 | void | |
6c95b8df PA |
5176 | set_default_breakpoint (int valid, struct program_space *pspace, |
5177 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5178 | int line) |
c906108c SS |
5179 | { |
5180 | default_breakpoint_valid = valid; | |
6c95b8df | 5181 | default_breakpoint_pspace = pspace; |
c906108c SS |
5182 | default_breakpoint_address = addr; |
5183 | default_breakpoint_symtab = symtab; | |
5184 | default_breakpoint_line = line; | |
5185 | } | |
5186 | ||
e4f237da KB |
5187 | /* Return true iff it is meaningful to use the address member of |
5188 | BPT. For some breakpoint types, the address member is irrelevant | |
5189 | and it makes no sense to attempt to compare it to other addresses | |
5190 | (or use it for any other purpose either). | |
5191 | ||
5192 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
5193 | have a zero valued address and we don't want to mark breakpoints of any of |
5194 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
5195 | |
5196 | bp_watchpoint | |
2d134ed3 PA |
5197 | bp_catchpoint |
5198 | ||
5199 | */ | |
e4f237da KB |
5200 | |
5201 | static int | |
5202 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5203 | { | |
5204 | enum bptype type = bpt->type; | |
5205 | ||
2d134ed3 PA |
5206 | return (type != bp_watchpoint && type != bp_catchpoint); |
5207 | } | |
5208 | ||
5209 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5210 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5211 | ||
5212 | static int | |
5213 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5214 | { | |
2bdf28a0 JK |
5215 | /* Both of them must not be in moribund_locations. */ |
5216 | gdb_assert (loc1->owner != NULL); | |
5217 | gdb_assert (loc2->owner != NULL); | |
5218 | ||
0cf6dd15 TJB |
5219 | /* If the target can evaluate the condition expression in hardware, then we |
5220 | we need to insert both watchpoints even if they are at the same place. | |
5221 | Otherwise the watchpoint will only trigger when the condition of whichever | |
5222 | watchpoint was inserted evaluates to true, not giving a chance for GDB to | |
5223 | check the condition of the other watchpoint. */ | |
5224 | if ((loc1->owner->cond_exp | |
5225 | && target_can_accel_watchpoint_condition (loc1->address, loc1->length, | |
5226 | loc1->watchpoint_type, | |
5227 | loc1->owner->cond_exp)) | |
5228 | || (loc2->owner->cond_exp | |
5229 | && target_can_accel_watchpoint_condition (loc2->address, loc2->length, | |
5230 | loc2->watchpoint_type, | |
5231 | loc2->owner->cond_exp))) | |
5232 | return 0; | |
5233 | ||
85d721b8 PA |
5234 | /* Note that this checks the owner's type, not the location's. In |
5235 | case the target does not support read watchpoints, but does | |
5236 | support access watchpoints, we'll have bp_read_watchpoint | |
5237 | watchpoints with hw_access locations. Those should be considered | |
5238 | duplicates of hw_read locations. The hw_read locations will | |
5239 | become hw_access locations later. */ | |
2d134ed3 PA |
5240 | return (loc1->owner->type == loc2->owner->type |
5241 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5242 | && loc1->address == loc2->address | |
5243 | && loc1->length == loc2->length); | |
e4f237da KB |
5244 | } |
5245 | ||
6c95b8df PA |
5246 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5247 | same breakpoint location. In most targets, this can only be true | |
5248 | if ASPACE1 matches ASPACE2. On targets that have global | |
5249 | breakpoints, the address space doesn't really matter. */ | |
5250 | ||
5251 | static int | |
5252 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5253 | struct address_space *aspace2, CORE_ADDR addr2) | |
5254 | { | |
5255 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5256 | || aspace1 == aspace2) | |
5257 | && addr1 == addr2); | |
5258 | } | |
5259 | ||
2d134ed3 PA |
5260 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5261 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5262 | represent the same location. */ | |
5263 | ||
5264 | static int | |
5265 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
5266 | { | |
2bdf28a0 JK |
5267 | int hw_point1, hw_point2; |
5268 | ||
5269 | /* Both of them must not be in moribund_locations. */ | |
5270 | gdb_assert (loc1->owner != NULL); | |
5271 | gdb_assert (loc2->owner != NULL); | |
5272 | ||
5273 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5274 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5275 | |
5276 | if (hw_point1 != hw_point2) | |
5277 | return 0; | |
5278 | else if (hw_point1) | |
5279 | return watchpoint_locations_match (loc1, loc2); | |
5280 | else | |
5281 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5282 | loc2->pspace->aspace, loc2->address); | |
5283 | } | |
5284 | ||
76897487 KB |
5285 | static void |
5286 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5287 | int bnum, int have_bnum) | |
5288 | { | |
5289 | char astr1[40]; | |
5290 | char astr2[40]; | |
5291 | ||
bb599908 PH |
5292 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5293 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5294 | if (have_bnum) |
8a3fe4f8 | 5295 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5296 | bnum, astr1, astr2); |
5297 | else | |
8a3fe4f8 | 5298 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5299 | } |
5300 | ||
5301 | /* Adjust a breakpoint's address to account for architectural constraints | |
5302 | on breakpoint placement. Return the adjusted address. Note: Very | |
5303 | few targets require this kind of adjustment. For most targets, | |
5304 | this function is simply the identity function. */ | |
5305 | ||
5306 | static CORE_ADDR | |
a6d9a66e UW |
5307 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5308 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5309 | { |
a6d9a66e | 5310 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5311 | { |
5312 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5313 | return bpaddr; | |
5314 | } | |
88f7da05 KB |
5315 | else if (bptype == bp_watchpoint |
5316 | || bptype == bp_hardware_watchpoint | |
5317 | || bptype == bp_read_watchpoint | |
5318 | || bptype == bp_access_watchpoint | |
fe798b75 | 5319 | || bptype == bp_catchpoint) |
88f7da05 KB |
5320 | { |
5321 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5322 | have their addresses modified. */ | |
5323 | return bpaddr; | |
5324 | } | |
76897487 KB |
5325 | else |
5326 | { | |
5327 | CORE_ADDR adjusted_bpaddr; | |
5328 | ||
5329 | /* Some targets have architectural constraints on the placement | |
5330 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5331 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5332 | |
5333 | /* An adjusted breakpoint address can significantly alter | |
5334 | a user's expectations. Print a warning if an adjustment | |
5335 | is required. */ | |
5336 | if (adjusted_bpaddr != bpaddr) | |
5337 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5338 | ||
5339 | return adjusted_bpaddr; | |
5340 | } | |
5341 | } | |
5342 | ||
7cc221ef DJ |
5343 | /* Allocate a struct bp_location. */ |
5344 | ||
26bb91f3 | 5345 | static struct bp_location * |
39d61571 | 5346 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5347 | { |
afe38095 | 5348 | struct bp_location *loc; |
7cc221ef DJ |
5349 | |
5350 | loc = xmalloc (sizeof (struct bp_location)); | |
5351 | memset (loc, 0, sizeof (*loc)); | |
5352 | ||
e049a4b5 | 5353 | loc->owner = bpt; |
511a6cd4 | 5354 | loc->cond = NULL; |
0d381245 VP |
5355 | loc->shlib_disabled = 0; |
5356 | loc->enabled = 1; | |
e049a4b5 | 5357 | |
39d61571 | 5358 | switch (bpt->type) |
e049a4b5 DJ |
5359 | { |
5360 | case bp_breakpoint: | |
5361 | case bp_until: | |
5362 | case bp_finish: | |
5363 | case bp_longjmp: | |
5364 | case bp_longjmp_resume: | |
5365 | case bp_step_resume: | |
e049a4b5 DJ |
5366 | case bp_watchpoint_scope: |
5367 | case bp_call_dummy: | |
aa7d318d | 5368 | case bp_std_terminate: |
e049a4b5 DJ |
5369 | case bp_shlib_event: |
5370 | case bp_thread_event: | |
5371 | case bp_overlay_event: | |
4efc6507 | 5372 | case bp_jit_event: |
0fd8e87f | 5373 | case bp_longjmp_master: |
aa7d318d | 5374 | case bp_std_terminate_master: |
e049a4b5 DJ |
5375 | loc->loc_type = bp_loc_software_breakpoint; |
5376 | break; | |
5377 | case bp_hardware_breakpoint: | |
5378 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5379 | break; | |
5380 | case bp_hardware_watchpoint: | |
5381 | case bp_read_watchpoint: | |
5382 | case bp_access_watchpoint: | |
5383 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5384 | break; | |
5385 | case bp_watchpoint: | |
ce78b96d | 5386 | case bp_catchpoint: |
15c3d785 PA |
5387 | case bp_tracepoint: |
5388 | case bp_fast_tracepoint: | |
0fb4aa4b | 5389 | case bp_static_tracepoint: |
e049a4b5 DJ |
5390 | loc->loc_type = bp_loc_other; |
5391 | break; | |
5392 | default: | |
e2e0b3e5 | 5393 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5394 | } |
5395 | ||
f431efe5 | 5396 | loc->refc = 1; |
7cc221ef DJ |
5397 | return loc; |
5398 | } | |
5399 | ||
f431efe5 PA |
5400 | static void |
5401 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5402 | { |
5403 | if (loc->cond) | |
5404 | xfree (loc->cond); | |
74960c60 VP |
5405 | |
5406 | if (loc->function_name) | |
5407 | xfree (loc->function_name); | |
f431efe5 | 5408 | |
fe3f5fa8 VP |
5409 | xfree (loc); |
5410 | } | |
5411 | ||
f431efe5 PA |
5412 | /* Increment reference count. */ |
5413 | ||
5414 | static void | |
5415 | incref_bp_location (struct bp_location *bl) | |
5416 | { | |
5417 | ++bl->refc; | |
5418 | } | |
5419 | ||
5420 | /* Decrement reference count. If the reference count reaches 0, | |
5421 | destroy the bp_location. Sets *BLP to NULL. */ | |
5422 | ||
5423 | static void | |
5424 | decref_bp_location (struct bp_location **blp) | |
5425 | { | |
5426 | if (--(*blp)->refc == 0) | |
5427 | free_bp_location (*blp); | |
5428 | *blp = NULL; | |
5429 | } | |
5430 | ||
0d381245 VP |
5431 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
5432 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 5433 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 5434 | |
c40e75cd | 5435 | static struct breakpoint * |
a6d9a66e UW |
5436 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5437 | enum bptype bptype) | |
c906108c | 5438 | { |
52f0bd74 | 5439 | struct breakpoint *b, *b1; |
c906108c SS |
5440 | |
5441 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5442 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5443 | |
4d28f7a8 | 5444 | b->type = bptype; |
a6d9a66e | 5445 | b->gdbarch = gdbarch; |
c906108c SS |
5446 | b->language = current_language->la_language; |
5447 | b->input_radix = input_radix; | |
5448 | b->thread = -1; | |
b5de0fa7 | 5449 | b->enable_state = bp_enabled; |
c906108c SS |
5450 | b->next = 0; |
5451 | b->silent = 0; | |
5452 | b->ignore_count = 0; | |
5453 | b->commands = NULL; | |
818dd999 | 5454 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5455 | b->forked_inferior_pid = null_ptid; |
c906108c | 5456 | b->exec_pathname = NULL; |
a96d9b2e | 5457 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5458 | b->ops = NULL; |
0d381245 | 5459 | b->condition_not_parsed = 0; |
c906108c SS |
5460 | |
5461 | /* Add this breakpoint to the end of the chain | |
5462 | so that a list of breakpoints will come out in order | |
5463 | of increasing numbers. */ | |
5464 | ||
5465 | b1 = breakpoint_chain; | |
5466 | if (b1 == 0) | |
5467 | breakpoint_chain = b; | |
5468 | else | |
5469 | { | |
5470 | while (b1->next) | |
5471 | b1 = b1->next; | |
5472 | b1->next = b; | |
5473 | } | |
0d381245 VP |
5474 | return b; |
5475 | } | |
5476 | ||
5477 | /* Initialize loc->function_name. */ | |
5478 | static void | |
5479 | set_breakpoint_location_function (struct bp_location *loc) | |
5480 | { | |
2bdf28a0 JK |
5481 | gdb_assert (loc->owner != NULL); |
5482 | ||
0d381245 | 5483 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5484 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5485 | || is_tracepoint (loc->owner)) |
0d381245 VP |
5486 | { |
5487 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5488 | NULL, NULL); | |
5489 | if (loc->function_name) | |
5490 | loc->function_name = xstrdup (loc->function_name); | |
5491 | } | |
5492 | } | |
5493 | ||
a6d9a66e UW |
5494 | /* Attempt to determine architecture of location identified by SAL. */ |
5495 | static struct gdbarch * | |
5496 | get_sal_arch (struct symtab_and_line sal) | |
5497 | { | |
5498 | if (sal.section) | |
5499 | return get_objfile_arch (sal.section->objfile); | |
5500 | if (sal.symtab) | |
5501 | return get_objfile_arch (sal.symtab->objfile); | |
5502 | ||
5503 | return NULL; | |
5504 | } | |
5505 | ||
0d381245 VP |
5506 | /* set_raw_breakpoint is a low level routine for allocating and |
5507 | partially initializing a breakpoint of type BPTYPE. The newly | |
5508 | created breakpoint's address, section, source file name, and line | |
5509 | number are provided by SAL. The newly created and partially | |
5510 | initialized breakpoint is added to the breakpoint chain and | |
5511 | is also returned as the value of this function. | |
5512 | ||
5513 | It is expected that the caller will complete the initialization of | |
5514 | the newly created breakpoint struct as well as output any status | |
5515 | information regarding the creation of a new breakpoint. In | |
5516 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5517 | number! Care should be taken to not allow an error to occur | |
5518 | prior to completing the initialization of the breakpoint. If this | |
5519 | should happen, a bogus breakpoint will be left on the chain. */ | |
5520 | ||
63c252f8 | 5521 | struct breakpoint * |
a6d9a66e UW |
5522 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5523 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5524 | { |
a6d9a66e | 5525 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 5526 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5527 | struct gdbarch *loc_gdbarch; |
5528 | ||
5529 | loc_gdbarch = get_sal_arch (sal); | |
5530 | if (!loc_gdbarch) | |
5531 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5532 | |
6c95b8df PA |
5533 | if (bptype != bp_catchpoint) |
5534 | gdb_assert (sal.pspace != NULL); | |
5535 | ||
0d381245 VP |
5536 | /* Adjust the breakpoint's address prior to allocating a location. |
5537 | Once we call allocate_bp_location(), that mostly uninitialized | |
5538 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5539 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5540 | not want its scan of the location chain to find a breakpoint and |
5541 | location that's only been partially initialized. */ | |
a6d9a66e | 5542 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 5543 | |
39d61571 | 5544 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5545 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5546 | b->loc->requested_address = sal.pc; |
5547 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5548 | b->loc->pspace = sal.pspace; |
5549 | ||
5550 | /* Store the program space that was used to set the breakpoint, for | |
5551 | breakpoint resetting. */ | |
5552 | b->pspace = sal.pspace; | |
0d381245 VP |
5553 | |
5554 | if (sal.symtab == NULL) | |
5555 | b->source_file = NULL; | |
5556 | else | |
1b36a34b | 5557 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5558 | b->loc->section = sal.section; |
5559 | b->line_number = sal.line; | |
5560 | ||
5561 | set_breakpoint_location_function (b->loc); | |
c906108c | 5562 | |
c906108c SS |
5563 | breakpoints_changed (); |
5564 | ||
5565 | return b; | |
5566 | } | |
5567 | ||
c2c6d25f JM |
5568 | |
5569 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5570 | instruction, hard-wired into the inferior's code. */ | |
5571 | void | |
5572 | make_breakpoint_permanent (struct breakpoint *b) | |
5573 | { | |
0d381245 | 5574 | struct bp_location *bl; |
cc59ec59 | 5575 | |
b5de0fa7 | 5576 | b->enable_state = bp_permanent; |
c2c6d25f | 5577 | |
0d381245 VP |
5578 | /* By definition, permanent breakpoints are already present in the code. |
5579 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
5580 | is called in just one place, so it's hard to say if it's reasonable | |
5581 | to have permanent breakpoint with multiple locations or not, | |
5582 | but it's easy to implmement. */ | |
5583 | for (bl = b->loc; bl; bl = bl->next) | |
5584 | bl->inserted = 1; | |
c2c6d25f JM |
5585 | } |
5586 | ||
53a5351d | 5587 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5588 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5589 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5590 | ||
5591 | void | |
0fd8e87f | 5592 | set_longjmp_breakpoint (int thread) |
c906108c | 5593 | { |
0fd8e87f UW |
5594 | struct breakpoint *b, *temp; |
5595 | ||
5596 | /* To avoid having to rescan all objfile symbols at every step, | |
5597 | we maintain a list of continually-inserted but always disabled | |
5598 | longjmp "master" breakpoints. Here, we simply create momentary | |
5599 | clones of those and enable them for the requested thread. */ | |
5600 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5601 | if (b->pspace == current_program_space |
5602 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5603 | { |
5604 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5605 | |
0fd8e87f UW |
5606 | clone->type = bp_longjmp; |
5607 | clone->thread = thread; | |
5608 | } | |
c906108c SS |
5609 | } |
5610 | ||
611c83ae | 5611 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5612 | void |
611c83ae | 5613 | delete_longjmp_breakpoint (int thread) |
c906108c | 5614 | { |
611c83ae | 5615 | struct breakpoint *b, *temp; |
c906108c | 5616 | |
611c83ae PA |
5617 | ALL_BREAKPOINTS_SAFE (b, temp) |
5618 | if (b->type == bp_longjmp) | |
5619 | { | |
5620 | if (b->thread == thread) | |
5621 | delete_breakpoint (b); | |
5622 | } | |
c906108c SS |
5623 | } |
5624 | ||
1900040c MS |
5625 | void |
5626 | enable_overlay_breakpoints (void) | |
5627 | { | |
52f0bd74 | 5628 | struct breakpoint *b; |
1900040c MS |
5629 | |
5630 | ALL_BREAKPOINTS (b) | |
5631 | if (b->type == bp_overlay_event) | |
5632 | { | |
5633 | b->enable_state = bp_enabled; | |
b60e7edf | 5634 | update_global_location_list (1); |
c02f5703 | 5635 | overlay_events_enabled = 1; |
1900040c MS |
5636 | } |
5637 | } | |
5638 | ||
5639 | void | |
5640 | disable_overlay_breakpoints (void) | |
5641 | { | |
52f0bd74 | 5642 | struct breakpoint *b; |
1900040c MS |
5643 | |
5644 | ALL_BREAKPOINTS (b) | |
5645 | if (b->type == bp_overlay_event) | |
5646 | { | |
5647 | b->enable_state = bp_disabled; | |
b60e7edf | 5648 | update_global_location_list (0); |
c02f5703 | 5649 | overlay_events_enabled = 0; |
1900040c MS |
5650 | } |
5651 | } | |
5652 | ||
aa7d318d TT |
5653 | /* Set an active std::terminate breakpoint for each std::terminate |
5654 | master breakpoint. */ | |
5655 | void | |
5656 | set_std_terminate_breakpoint (void) | |
5657 | { | |
5658 | struct breakpoint *b, *temp; | |
5659 | ||
5660 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5661 | if (b->pspace == current_program_space | |
5662 | && b->type == bp_std_terminate_master) | |
5663 | { | |
5664 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5665 | clone->type = bp_std_terminate; | |
5666 | } | |
5667 | } | |
5668 | ||
5669 | /* Delete all the std::terminate breakpoints. */ | |
5670 | void | |
5671 | delete_std_terminate_breakpoint (void) | |
5672 | { | |
5673 | struct breakpoint *b, *temp; | |
5674 | ||
5675 | ALL_BREAKPOINTS_SAFE (b, temp) | |
5676 | if (b->type == bp_std_terminate) | |
5677 | delete_breakpoint (b); | |
5678 | } | |
5679 | ||
c4093a6a | 5680 | struct breakpoint * |
a6d9a66e | 5681 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5682 | { |
5683 | struct breakpoint *b; | |
c4093a6a | 5684 | |
a6d9a66e | 5685 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5686 | |
b5de0fa7 | 5687 | b->enable_state = bp_enabled; |
c4093a6a | 5688 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5689 | b->addr_string |
5690 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5691 | |
b60e7edf | 5692 | update_global_location_list_nothrow (1); |
74960c60 | 5693 | |
c4093a6a JM |
5694 | return b; |
5695 | } | |
5696 | ||
5697 | void | |
5698 | remove_thread_event_breakpoints (void) | |
5699 | { | |
5700 | struct breakpoint *b, *temp; | |
5701 | ||
5702 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5703 | if (b->type == bp_thread_event |
5704 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5705 | delete_breakpoint (b); |
5706 | } | |
5707 | ||
0101ce28 JJ |
5708 | struct captured_parse_breakpoint_args |
5709 | { | |
5710 | char **arg_p; | |
5711 | struct symtabs_and_lines *sals_p; | |
5712 | char ***addr_string_p; | |
5713 | int *not_found_ptr; | |
5714 | }; | |
5715 | ||
5716 | struct lang_and_radix | |
5717 | { | |
5718 | enum language lang; | |
5719 | int radix; | |
5720 | }; | |
5721 | ||
4efc6507 DE |
5722 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5723 | ||
5724 | struct breakpoint * | |
5725 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5726 | { | |
5727 | struct breakpoint *b; | |
5728 | ||
5729 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5730 | update_global_location_list_nothrow (1); | |
5731 | return b; | |
5732 | } | |
0101ce28 | 5733 | |
cae688ec JJ |
5734 | void |
5735 | remove_solib_event_breakpoints (void) | |
5736 | { | |
5737 | struct breakpoint *b, *temp; | |
5738 | ||
5739 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5740 | if (b->type == bp_shlib_event |
5741 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5742 | delete_breakpoint (b); |
5743 | } | |
5744 | ||
5745 | struct breakpoint * | |
a6d9a66e | 5746 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5747 | { |
5748 | struct breakpoint *b; | |
5749 | ||
a6d9a66e | 5750 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5751 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5752 | return b; |
5753 | } | |
5754 | ||
5755 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5756 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5757 | ||
5758 | void | |
cb851954 | 5759 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5760 | { |
876fa593 | 5761 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5762 | |
876fa593 | 5763 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5764 | { |
2bdf28a0 | 5765 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 5766 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 5767 | |
0d381245 VP |
5768 | /* We apply the check to all breakpoints, including disabled |
5769 | for those with loc->duplicate set. This is so that when breakpoint | |
5770 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5771 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5772 | to insert those breakpoints and fail. */ | |
1042e4c0 | 5773 | if (((b->type == bp_breakpoint) |
508ccb1f | 5774 | || (b->type == bp_jit_event) |
1042e4c0 | 5775 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 5776 | || (is_tracepoint (b))) |
6c95b8df | 5777 | && loc->pspace == current_program_space |
0d381245 | 5778 | && !loc->shlib_disabled |
a77053c2 | 5779 | #ifdef PC_SOLIB |
0d381245 | 5780 | && PC_SOLIB (loc->address) |
a77053c2 | 5781 | #else |
6c95b8df | 5782 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5783 | #endif |
5784 | ) | |
0d381245 VP |
5785 | { |
5786 | loc->shlib_disabled = 1; | |
5787 | } | |
cae688ec JJ |
5788 | } |
5789 | } | |
5790 | ||
84acb35a JJ |
5791 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5792 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5793 | ||
75149521 | 5794 | static void |
84acb35a JJ |
5795 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5796 | { | |
876fa593 | 5797 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5798 | int disabled_shlib_breaks = 0; |
5799 | ||
c86cf029 VP |
5800 | /* SunOS a.out shared libraries are always mapped, so do not |
5801 | disable breakpoints; they will only be reported as unloaded | |
5802 | through clear_solib when GDB discards its shared library | |
5803 | list. See clear_solib for more information. */ | |
5804 | if (exec_bfd != NULL | |
5805 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5806 | return; | |
5807 | ||
876fa593 | 5808 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5809 | { |
2bdf28a0 | 5810 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 5811 | struct breakpoint *b = loc->owner; |
cc59ec59 | 5812 | |
0d381245 VP |
5813 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
5814 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5815 | && solib->pspace == loc->pspace |
e2dd7057 | 5816 | && !loc->shlib_disabled |
508ccb1f TT |
5817 | && (b->type == bp_breakpoint |
5818 | || b->type == bp_jit_event | |
5819 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 5820 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 5821 | { |
e2dd7057 PP |
5822 | loc->shlib_disabled = 1; |
5823 | /* At this point, we cannot rely on remove_breakpoint | |
5824 | succeeding so we must mark the breakpoint as not inserted | |
5825 | to prevent future errors occurring in remove_breakpoints. */ | |
5826 | loc->inserted = 0; | |
5827 | if (!disabled_shlib_breaks) | |
5828 | { | |
5829 | target_terminal_ours_for_output (); | |
5830 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5831 | solib->so_name); | |
84acb35a | 5832 | } |
e2dd7057 | 5833 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5834 | } |
5835 | } | |
84acb35a JJ |
5836 | } |
5837 | ||
ce78b96d JB |
5838 | /* FORK & VFORK catchpoints. */ |
5839 | ||
5840 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5841 | ||
c906108c | 5842 | static void |
ce78b96d JB |
5843 | insert_catch_fork (struct breakpoint *b) |
5844 | { | |
5845 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5846 | } | |
5847 | ||
5848 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5849 | ||
5850 | static int | |
5851 | remove_catch_fork (struct breakpoint *b) | |
5852 | { | |
5853 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5854 | } | |
5855 | ||
5856 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5857 | catchpoints. */ | |
5858 | ||
5859 | static int | |
5860 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5861 | { | |
5862 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5863 | } | |
5864 | ||
5865 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5866 | ||
5867 | static enum print_stop_action | |
5868 | print_it_catch_fork (struct breakpoint *b) | |
5869 | { | |
5870 | annotate_catchpoint (b->number); | |
5871 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5872 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5873 | return PRINT_SRC_AND_LOC; | |
5874 | } | |
5875 | ||
5876 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5877 | ||
5878 | static void | |
a6d9a66e | 5879 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5880 | { |
79a45b7d TT |
5881 | struct value_print_options opts; |
5882 | ||
5883 | get_user_print_options (&opts); | |
5884 | ||
ce78b96d JB |
5885 | /* Field 4, the address, is omitted (which makes the columns |
5886 | not line up too nicely with the headers, but the effect | |
5887 | is relatively readable). */ | |
79a45b7d | 5888 | if (opts.addressprint) |
ce78b96d JB |
5889 | ui_out_field_skip (uiout, "addr"); |
5890 | annotate_field (5); | |
5891 | ui_out_text (uiout, "fork"); | |
5892 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5893 | { | |
5894 | ui_out_text (uiout, ", process "); | |
5895 | ui_out_field_int (uiout, "what", | |
5896 | ptid_get_pid (b->forked_inferior_pid)); | |
5897 | ui_out_spaces (uiout, 1); | |
5898 | } | |
5899 | } | |
5900 | ||
5901 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5902 | catchpoints. */ | |
5903 | ||
5904 | static void | |
5905 | print_mention_catch_fork (struct breakpoint *b) | |
5906 | { | |
5907 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5908 | } | |
5909 | ||
6149aea9 PA |
5910 | /* Implement the "print_recreate" breakpoint_ops method for fork |
5911 | catchpoints. */ | |
5912 | ||
5913 | static void | |
5914 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
5915 | { | |
5916 | fprintf_unfiltered (fp, "catch fork"); | |
5917 | } | |
5918 | ||
ce78b96d JB |
5919 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
5920 | ||
5921 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5922 | { | |
5923 | insert_catch_fork, | |
5924 | remove_catch_fork, | |
5925 | breakpoint_hit_catch_fork, | |
5926 | print_it_catch_fork, | |
5927 | print_one_catch_fork, | |
6149aea9 PA |
5928 | print_mention_catch_fork, |
5929 | print_recreate_catch_fork | |
ce78b96d JB |
5930 | }; |
5931 | ||
5932 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5933 | ||
5934 | static void | |
5935 | insert_catch_vfork (struct breakpoint *b) | |
5936 | { | |
5937 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5938 | } | |
5939 | ||
5940 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5941 | ||
5942 | static int | |
5943 | remove_catch_vfork (struct breakpoint *b) | |
5944 | { | |
5945 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5946 | } | |
5947 | ||
5948 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5949 | catchpoints. */ | |
5950 | ||
5951 | static int | |
5952 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5953 | { | |
5954 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5955 | } | |
5956 | ||
5957 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5958 | ||
5959 | static enum print_stop_action | |
5960 | print_it_catch_vfork (struct breakpoint *b) | |
5961 | { | |
5962 | annotate_catchpoint (b->number); | |
5963 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5964 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5965 | return PRINT_SRC_AND_LOC; | |
5966 | } | |
5967 | ||
5968 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5969 | ||
5970 | static void | |
a6d9a66e | 5971 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5972 | { |
79a45b7d TT |
5973 | struct value_print_options opts; |
5974 | ||
5975 | get_user_print_options (&opts); | |
ce78b96d JB |
5976 | /* Field 4, the address, is omitted (which makes the columns |
5977 | not line up too nicely with the headers, but the effect | |
5978 | is relatively readable). */ | |
79a45b7d | 5979 | if (opts.addressprint) |
ce78b96d JB |
5980 | ui_out_field_skip (uiout, "addr"); |
5981 | annotate_field (5); | |
5982 | ui_out_text (uiout, "vfork"); | |
5983 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5984 | { | |
5985 | ui_out_text (uiout, ", process "); | |
5986 | ui_out_field_int (uiout, "what", | |
5987 | ptid_get_pid (b->forked_inferior_pid)); | |
5988 | ui_out_spaces (uiout, 1); | |
5989 | } | |
5990 | } | |
5991 | ||
5992 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5993 | catchpoints. */ | |
5994 | ||
5995 | static void | |
5996 | print_mention_catch_vfork (struct breakpoint *b) | |
5997 | { | |
5998 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5999 | } | |
6000 | ||
6149aea9 PA |
6001 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6002 | catchpoints. */ | |
6003 | ||
6004 | static void | |
6005 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6006 | { | |
6007 | fprintf_unfiltered (fp, "catch vfork"); | |
6008 | } | |
6009 | ||
ce78b96d JB |
6010 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6011 | ||
6012 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6013 | { | |
6014 | insert_catch_vfork, | |
6015 | remove_catch_vfork, | |
6016 | breakpoint_hit_catch_vfork, | |
6017 | print_it_catch_vfork, | |
6018 | print_one_catch_vfork, | |
6149aea9 PA |
6019 | print_mention_catch_vfork, |
6020 | print_recreate_catch_vfork | |
ce78b96d JB |
6021 | }; |
6022 | ||
a96d9b2e SDJ |
6023 | /* Implement the "insert" breakpoint_ops method for syscall |
6024 | catchpoints. */ | |
6025 | ||
6026 | static void | |
6027 | insert_catch_syscall (struct breakpoint *b) | |
6028 | { | |
6029 | struct inferior *inf = current_inferior (); | |
6030 | ||
6031 | ++inf->total_syscalls_count; | |
6032 | if (!b->syscalls_to_be_caught) | |
6033 | ++inf->any_syscall_count; | |
6034 | else | |
6035 | { | |
6036 | int i, iter; | |
cc59ec59 | 6037 | |
a96d9b2e SDJ |
6038 | for (i = 0; |
6039 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6040 | i++) | |
6041 | { | |
6042 | int elem; | |
cc59ec59 | 6043 | |
a96d9b2e SDJ |
6044 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6045 | { | |
6046 | int old_size = VEC_length (int, inf->syscalls_counts); | |
6047 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
6048 | uintptr_t vec_addr; | |
6049 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6050 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6051 | vec_addr_offset; | |
6052 | memset ((void *) vec_addr, 0, | |
6053 | (iter + 1 - old_size) * sizeof (int)); | |
6054 | } | |
6055 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6056 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6057 | } | |
6058 | } | |
6059 | ||
6060 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6061 | inf->total_syscalls_count != 0, | |
6062 | inf->any_syscall_count, | |
6063 | VEC_length (int, inf->syscalls_counts), | |
6064 | VEC_address (int, inf->syscalls_counts)); | |
6065 | } | |
6066 | ||
6067 | /* Implement the "remove" breakpoint_ops method for syscall | |
6068 | catchpoints. */ | |
6069 | ||
6070 | static int | |
6071 | remove_catch_syscall (struct breakpoint *b) | |
6072 | { | |
6073 | struct inferior *inf = current_inferior (); | |
6074 | ||
6075 | --inf->total_syscalls_count; | |
6076 | if (!b->syscalls_to_be_caught) | |
6077 | --inf->any_syscall_count; | |
6078 | else | |
6079 | { | |
6080 | int i, iter; | |
cc59ec59 | 6081 | |
a96d9b2e SDJ |
6082 | for (i = 0; |
6083 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6084 | i++) | |
6085 | { | |
6086 | int elem; | |
6087 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6088 | /* Shouldn't happen. */ | |
6089 | continue; | |
6090 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6091 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6092 | } | |
6093 | } | |
6094 | ||
6095 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6096 | inf->total_syscalls_count != 0, | |
6097 | inf->any_syscall_count, | |
6098 | VEC_length (int, inf->syscalls_counts), | |
6099 | VEC_address (int, inf->syscalls_counts)); | |
6100 | } | |
6101 | ||
6102 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6103 | catchpoints. */ | |
6104 | ||
6105 | static int | |
6106 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
6107 | { | |
6108 | /* We must check if we are catching specific syscalls in this breakpoint. | |
6109 | If we are, then we must guarantee that the called syscall is the same | |
6110 | syscall we are catching. */ | |
6111 | int syscall_number = 0; | |
6112 | ||
6113 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6114 | return 0; | |
6115 | ||
6116 | /* Now, checking if the syscall is the same. */ | |
6117 | if (b->syscalls_to_be_caught) | |
6118 | { | |
6119 | int i, iter; | |
cc59ec59 | 6120 | |
a96d9b2e SDJ |
6121 | for (i = 0; |
6122 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6123 | i++) | |
6124 | if (syscall_number == iter) | |
6125 | break; | |
6126 | /* Not the same. */ | |
6127 | if (!iter) | |
6128 | return 0; | |
6129 | } | |
6130 | ||
6131 | return 1; | |
6132 | } | |
6133 | ||
6134 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6135 | catchpoints. */ | |
6136 | ||
6137 | static enum print_stop_action | |
6138 | print_it_catch_syscall (struct breakpoint *b) | |
6139 | { | |
6140 | /* These are needed because we want to know in which state a | |
6141 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6142 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6143 | must print "called syscall" or "returned from syscall". */ | |
6144 | ptid_t ptid; | |
6145 | struct target_waitstatus last; | |
6146 | struct syscall s; | |
6147 | struct cleanup *old_chain; | |
6148 | char *syscall_id; | |
6149 | ||
6150 | get_last_target_status (&ptid, &last); | |
6151 | ||
6152 | get_syscall_by_number (last.value.syscall_number, &s); | |
6153 | ||
6154 | annotate_catchpoint (b->number); | |
6155 | ||
6156 | if (s.name == NULL) | |
6157 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6158 | else | |
6159 | syscall_id = xstrprintf ("'%s'", s.name); | |
6160 | ||
6161 | old_chain = make_cleanup (xfree, syscall_id); | |
6162 | ||
6163 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6164 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6165 | b->number, syscall_id); | |
6166 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6167 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6168 | b->number, syscall_id); | |
6169 | ||
6170 | do_cleanups (old_chain); | |
6171 | ||
6172 | return PRINT_SRC_AND_LOC; | |
6173 | } | |
6174 | ||
6175 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6176 | catchpoints. */ | |
6177 | ||
6178 | static void | |
6179 | print_one_catch_syscall (struct breakpoint *b, | |
6180 | struct bp_location **last_loc) | |
6181 | { | |
6182 | struct value_print_options opts; | |
6183 | ||
6184 | get_user_print_options (&opts); | |
6185 | /* Field 4, the address, is omitted (which makes the columns | |
6186 | not line up too nicely with the headers, but the effect | |
6187 | is relatively readable). */ | |
6188 | if (opts.addressprint) | |
6189 | ui_out_field_skip (uiout, "addr"); | |
6190 | annotate_field (5); | |
6191 | ||
6192 | if (b->syscalls_to_be_caught | |
6193 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6194 | ui_out_text (uiout, "syscalls \""); | |
6195 | else | |
6196 | ui_out_text (uiout, "syscall \""); | |
6197 | ||
6198 | if (b->syscalls_to_be_caught) | |
6199 | { | |
6200 | int i, iter; | |
6201 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6202 | |
a96d9b2e SDJ |
6203 | for (i = 0; |
6204 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6205 | i++) | |
6206 | { | |
6207 | char *x = text; | |
6208 | struct syscall s; | |
6209 | get_syscall_by_number (iter, &s); | |
6210 | ||
6211 | if (s.name != NULL) | |
6212 | text = xstrprintf ("%s%s, ", text, s.name); | |
6213 | else | |
6214 | text = xstrprintf ("%s%d, ", text, iter); | |
6215 | ||
6216 | /* We have to xfree the last 'text' (now stored at 'x') | |
6217 | because xstrprintf dinamically allocates new space for it | |
6218 | on every call. */ | |
6219 | xfree (x); | |
6220 | } | |
6221 | /* Remove the last comma. */ | |
6222 | text[strlen (text) - 2] = '\0'; | |
6223 | ui_out_field_string (uiout, "what", text); | |
6224 | } | |
6225 | else | |
6226 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6227 | ui_out_text (uiout, "\" "); | |
6228 | } | |
6229 | ||
6230 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6231 | catchpoints. */ | |
6232 | ||
6233 | static void | |
6234 | print_mention_catch_syscall (struct breakpoint *b) | |
6235 | { | |
6236 | if (b->syscalls_to_be_caught) | |
6237 | { | |
6238 | int i, iter; | |
6239 | ||
6240 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6241 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6242 | else | |
6243 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6244 | ||
6245 | for (i = 0; | |
6246 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6247 | i++) | |
6248 | { | |
6249 | struct syscall s; | |
6250 | get_syscall_by_number (iter, &s); | |
6251 | ||
6252 | if (s.name) | |
6253 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6254 | else | |
6255 | printf_filtered (" %d", s.number); | |
6256 | } | |
6257 | printf_filtered (")"); | |
6258 | } | |
6259 | else | |
6260 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6261 | b->number); | |
6262 | } | |
6263 | ||
6149aea9 PA |
6264 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6265 | catchpoints. */ | |
6266 | ||
6267 | static void | |
6268 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6269 | { | |
6270 | fprintf_unfiltered (fp, "catch syscall"); | |
6271 | ||
6272 | if (b->syscalls_to_be_caught) | |
6273 | { | |
6274 | int i, iter; | |
6275 | ||
6276 | for (i = 0; | |
6277 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6278 | i++) | |
6279 | { | |
6280 | struct syscall s; | |
6281 | ||
6282 | get_syscall_by_number (iter, &s); | |
6283 | if (s.name) | |
6284 | fprintf_unfiltered (fp, " %s", s.name); | |
6285 | else | |
6286 | fprintf_unfiltered (fp, " %d", s.number); | |
6287 | } | |
6288 | } | |
6289 | } | |
6290 | ||
a96d9b2e SDJ |
6291 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6292 | ||
6293 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6294 | { | |
6295 | insert_catch_syscall, | |
6296 | remove_catch_syscall, | |
6297 | breakpoint_hit_catch_syscall, | |
6298 | print_it_catch_syscall, | |
6299 | print_one_catch_syscall, | |
6149aea9 PA |
6300 | print_mention_catch_syscall, |
6301 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6302 | }; |
6303 | ||
6304 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6305 | ||
6306 | static int | |
6307 | syscall_catchpoint_p (struct breakpoint *b) | |
6308 | { | |
6309 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6310 | } | |
6311 | ||
6312 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6313 | but does NOT mention it nor update the global location list. | |
6314 | This is useful if you need to fill more fields in the | |
6315 | struct breakpoint before calling mention. | |
ce78b96d JB |
6316 | |
6317 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6318 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6319 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6320 | to the catchpoint. */ | |
6321 | ||
6322 | static struct breakpoint * | |
a96d9b2e SDJ |
6323 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6324 | char *cond_string, | |
6325 | struct breakpoint_ops *ops) | |
c906108c | 6326 | { |
c5aa993b JM |
6327 | struct symtab_and_line sal; |
6328 | struct breakpoint *b; | |
c5aa993b | 6329 | |
fe39c653 | 6330 | init_sal (&sal); |
6c95b8df | 6331 | sal.pspace = current_program_space; |
c5aa993b | 6332 | |
a6d9a66e | 6333 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6334 | set_breakpoint_count (breakpoint_count + 1); |
6335 | b->number = breakpoint_count; | |
ce78b96d | 6336 | |
1b36a34b | 6337 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6338 | b->thread = -1; |
c906108c | 6339 | b->addr_string = NULL; |
b5de0fa7 EZ |
6340 | b->enable_state = bp_enabled; |
6341 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6342 | b->ops = ops; |
c5aa993b | 6343 | |
a96d9b2e SDJ |
6344 | return b; |
6345 | } | |
6346 | ||
6347 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6348 | ||
6349 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6350 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6351 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6352 | to the catchpoint. */ | |
6353 | ||
6354 | static struct breakpoint * | |
6355 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6356 | char *cond_string, struct breakpoint_ops *ops) | |
6357 | { | |
6358 | struct breakpoint *b = | |
6359 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6360 | ||
c906108c | 6361 | mention (b); |
ce78b96d | 6362 | update_global_location_list (1); |
c906108c | 6363 | |
ce78b96d | 6364 | return b; |
c906108c | 6365 | } |
c5aa993b | 6366 | |
9b70b993 | 6367 | static void |
a6d9a66e UW |
6368 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6369 | int tempflag, char *cond_string, | |
ce78b96d | 6370 | struct breakpoint_ops *ops) |
c906108c | 6371 | { |
a6d9a66e UW |
6372 | struct breakpoint *b |
6373 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6374 | |
6375 | /* FIXME: We should put this information in a breakpoint private data | |
6376 | area. */ | |
6377 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6378 | } |
6379 | ||
fe798b75 JB |
6380 | /* Exec catchpoints. */ |
6381 | ||
9b70b993 | 6382 | static void |
fe798b75 | 6383 | insert_catch_exec (struct breakpoint *b) |
c906108c | 6384 | { |
fe798b75 JB |
6385 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
6386 | } | |
c906108c | 6387 | |
fe798b75 JB |
6388 | static int |
6389 | remove_catch_exec (struct breakpoint *b) | |
6390 | { | |
6391 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6392 | } | |
c906108c | 6393 | |
fe798b75 JB |
6394 | static int |
6395 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
6396 | { | |
6397 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
6398 | } | |
c906108c | 6399 | |
fe798b75 JB |
6400 | static enum print_stop_action |
6401 | print_it_catch_exec (struct breakpoint *b) | |
6402 | { | |
6403 | annotate_catchpoint (b->number); | |
6404 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6405 | b->exec_pathname); | |
6406 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6407 | } |
6408 | ||
fe798b75 | 6409 | static void |
a6d9a66e | 6410 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6411 | { |
6412 | struct value_print_options opts; | |
6413 | ||
6414 | get_user_print_options (&opts); | |
6415 | ||
6416 | /* Field 4, the address, is omitted (which makes the columns | |
6417 | not line up too nicely with the headers, but the effect | |
6418 | is relatively readable). */ | |
6419 | if (opts.addressprint) | |
6420 | ui_out_field_skip (uiout, "addr"); | |
6421 | annotate_field (5); | |
6422 | ui_out_text (uiout, "exec"); | |
6423 | if (b->exec_pathname != NULL) | |
6424 | { | |
6425 | ui_out_text (uiout, ", program \""); | |
6426 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6427 | ui_out_text (uiout, "\" "); | |
6428 | } | |
6429 | } | |
6430 | ||
6431 | static void | |
6432 | print_mention_catch_exec (struct breakpoint *b) | |
6433 | { | |
6434 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6435 | } | |
6436 | ||
6149aea9 PA |
6437 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6438 | catchpoints. */ | |
6439 | ||
6440 | static void | |
6441 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6442 | { | |
6443 | fprintf_unfiltered (fp, "catch exec"); | |
6444 | } | |
6445 | ||
fe798b75 JB |
6446 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6447 | { | |
6448 | insert_catch_exec, | |
6449 | remove_catch_exec, | |
6450 | breakpoint_hit_catch_exec, | |
6451 | print_it_catch_exec, | |
6452 | print_one_catch_exec, | |
6149aea9 PA |
6453 | print_mention_catch_exec, |
6454 | print_recreate_catch_exec | |
fe798b75 JB |
6455 | }; |
6456 | ||
a96d9b2e SDJ |
6457 | static void |
6458 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6459 | struct breakpoint_ops *ops) | |
6460 | { | |
6461 | struct gdbarch *gdbarch = get_current_arch (); | |
6462 | struct breakpoint *b = | |
6463 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6464 | ||
6465 | b->syscalls_to_be_caught = filter; | |
6466 | ||
6467 | /* Now, we have to mention the breakpoint and update the global | |
6468 | location list. */ | |
6469 | mention (b); | |
6470 | update_global_location_list (1); | |
6471 | } | |
6472 | ||
c906108c | 6473 | static int |
fba45db2 | 6474 | hw_breakpoint_used_count (void) |
c906108c | 6475 | { |
52f0bd74 | 6476 | struct breakpoint *b; |
c906108c SS |
6477 | int i = 0; |
6478 | ||
6479 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6480 | { |
d6b74ac4 | 6481 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
6482 | i++; |
6483 | } | |
c906108c SS |
6484 | |
6485 | return i; | |
6486 | } | |
6487 | ||
6488 | static int | |
fba45db2 | 6489 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6490 | { |
52f0bd74 | 6491 | struct breakpoint *b; |
c906108c SS |
6492 | int i = 0; |
6493 | ||
6494 | *other_type_used = 0; | |
6495 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6496 | { |
468d015d | 6497 | if (breakpoint_enabled (b)) |
c5aa993b JM |
6498 | { |
6499 | if (b->type == type) | |
6500 | i++; | |
cc60f2e3 | 6501 | else if (is_hardware_watchpoint (b)) |
c5aa993b JM |
6502 | *other_type_used = 1; |
6503 | } | |
6504 | } | |
c906108c SS |
6505 | return i; |
6506 | } | |
6507 | ||
c906108c | 6508 | void |
fba45db2 | 6509 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6510 | { |
c5aa993b | 6511 | struct breakpoint *b; |
c906108c SS |
6512 | |
6513 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6514 | { |
cc60f2e3 | 6515 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6516 | { |
b5de0fa7 | 6517 | b->enable_state = bp_call_disabled; |
b60e7edf | 6518 | update_global_location_list (0); |
c5aa993b JM |
6519 | } |
6520 | } | |
c906108c SS |
6521 | } |
6522 | ||
6523 | void | |
fba45db2 | 6524 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6525 | { |
c5aa993b | 6526 | struct breakpoint *b; |
c906108c SS |
6527 | |
6528 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6529 | { |
cc60f2e3 | 6530 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6531 | { |
b5de0fa7 | 6532 | b->enable_state = bp_enabled; |
b60e7edf | 6533 | update_global_location_list (1); |
c5aa993b JM |
6534 | } |
6535 | } | |
c906108c SS |
6536 | } |
6537 | ||
8bea4e01 UW |
6538 | void |
6539 | disable_breakpoints_before_startup (void) | |
6540 | { | |
6541 | struct breakpoint *b; | |
6542 | int found = 0; | |
6543 | ||
6544 | ALL_BREAKPOINTS (b) | |
6545 | { | |
6c95b8df PA |
6546 | if (b->pspace != current_program_space) |
6547 | continue; | |
6548 | ||
8bea4e01 UW |
6549 | if ((b->type == bp_breakpoint |
6550 | || b->type == bp_hardware_breakpoint) | |
6551 | && breakpoint_enabled (b)) | |
6552 | { | |
6553 | b->enable_state = bp_startup_disabled; | |
6554 | found = 1; | |
6555 | } | |
6556 | } | |
6557 | ||
6558 | if (found) | |
6559 | update_global_location_list (0); | |
6560 | ||
6c95b8df | 6561 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6562 | } |
6563 | ||
6564 | void | |
6565 | enable_breakpoints_after_startup (void) | |
6566 | { | |
6567 | struct breakpoint *b; | |
6568 | int found = 0; | |
6569 | ||
6c95b8df | 6570 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6571 | |
6572 | ALL_BREAKPOINTS (b) | |
6573 | { | |
6c95b8df PA |
6574 | if (b->pspace != current_program_space) |
6575 | continue; | |
6576 | ||
8bea4e01 UW |
6577 | if ((b->type == bp_breakpoint |
6578 | || b->type == bp_hardware_breakpoint) | |
6579 | && b->enable_state == bp_startup_disabled) | |
6580 | { | |
6581 | b->enable_state = bp_enabled; | |
6582 | found = 1; | |
6583 | } | |
6584 | } | |
6585 | ||
6586 | if (found) | |
6587 | breakpoint_re_set (); | |
6588 | } | |
6589 | ||
c906108c SS |
6590 | |
6591 | /* Set a breakpoint that will evaporate an end of command | |
6592 | at address specified by SAL. | |
6593 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6594 | ||
6595 | struct breakpoint * | |
a6d9a66e UW |
6596 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6597 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6598 | { |
52f0bd74 | 6599 | struct breakpoint *b; |
edb3359d DJ |
6600 | |
6601 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6602 | one. */ | |
6603 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6604 | ||
a6d9a66e | 6605 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6606 | b->enable_state = bp_enabled; |
6607 | b->disposition = disp_donttouch; | |
818dd999 | 6608 | b->frame_id = frame_id; |
c906108c SS |
6609 | |
6610 | /* If we're debugging a multi-threaded program, then we | |
6611 | want momentary breakpoints to be active in only a | |
6612 | single thread of control. */ | |
39f77062 KB |
6613 | if (in_thread_list (inferior_ptid)) |
6614 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6615 | |
b60e7edf | 6616 | update_global_location_list_nothrow (1); |
74960c60 | 6617 | |
c906108c SS |
6618 | return b; |
6619 | } | |
611c83ae | 6620 | |
e58b0e63 PA |
6621 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6622 | ORIG is NULL. */ | |
6623 | ||
6624 | struct breakpoint * | |
6625 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6626 | { | |
6627 | struct breakpoint *copy; | |
6628 | ||
6629 | /* If there's nothing to clone, then return nothing. */ | |
6630 | if (orig == NULL) | |
6631 | return NULL; | |
6632 | ||
a6d9a66e | 6633 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6634 | copy->loc = allocate_bp_location (copy); |
6635 | set_breakpoint_location_function (copy->loc); | |
6636 | ||
a6d9a66e | 6637 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6638 | copy->loc->requested_address = orig->loc->requested_address; |
6639 | copy->loc->address = orig->loc->address; | |
6640 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6641 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6642 | |
6643 | if (orig->source_file == NULL) | |
6644 | copy->source_file = NULL; | |
6645 | else | |
6646 | copy->source_file = xstrdup (orig->source_file); | |
6647 | ||
6648 | copy->line_number = orig->line_number; | |
6649 | copy->frame_id = orig->frame_id; | |
6650 | copy->thread = orig->thread; | |
6c95b8df | 6651 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6652 | |
6653 | copy->enable_state = bp_enabled; | |
6654 | copy->disposition = disp_donttouch; | |
6655 | copy->number = internal_breakpoint_number--; | |
6656 | ||
6657 | update_global_location_list_nothrow (0); | |
6658 | return copy; | |
6659 | } | |
6660 | ||
611c83ae | 6661 | struct breakpoint * |
a6d9a66e UW |
6662 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6663 | enum bptype type) | |
611c83ae PA |
6664 | { |
6665 | struct symtab_and_line sal; | |
6666 | ||
6667 | sal = find_pc_line (pc, 0); | |
6668 | sal.pc = pc; | |
6669 | sal.section = find_pc_overlay (pc); | |
6670 | sal.explicit_pc = 1; | |
6671 | ||
a6d9a66e | 6672 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6673 | } |
c906108c | 6674 | \f |
c5aa993b | 6675 | |
c906108c SS |
6676 | /* Tell the user we have just set a breakpoint B. */ |
6677 | ||
6678 | static void | |
fba45db2 | 6679 | mention (struct breakpoint *b) |
c906108c SS |
6680 | { |
6681 | int say_where = 0; | |
fa8a61dc | 6682 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6683 | struct value_print_options opts; |
6684 | ||
6685 | get_user_print_options (&opts); | |
8b93c638 | 6686 | |
9a4105ab AC |
6687 | /* FIXME: This is misplaced; mention() is called by things (like |
6688 | hitting a watchpoint) other than breakpoint creation. It should | |
6689 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6690 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6691 | observer_notify_breakpoint_created (b->number); |
c906108c | 6692 | |
3086aeae DJ |
6693 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6694 | b->ops->print_mention (b); | |
6695 | else | |
6696 | switch (b->type) | |
6697 | { | |
6698 | case bp_none: | |
a3f17187 | 6699 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6700 | break; |
6701 | case bp_watchpoint: | |
6702 | ui_out_text (uiout, "Watchpoint "); | |
6703 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6704 | ui_out_field_int (uiout, "number", b->number); | |
6705 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6706 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6707 | do_cleanups (ui_out_chain); |
6708 | break; | |
6709 | case bp_hardware_watchpoint: | |
6710 | ui_out_text (uiout, "Hardware watchpoint "); | |
6711 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6712 | ui_out_field_int (uiout, "number", b->number); | |
6713 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6714 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6715 | do_cleanups (ui_out_chain); |
6716 | break; | |
6717 | case bp_read_watchpoint: | |
6718 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6719 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6720 | ui_out_field_int (uiout, "number", b->number); | |
6721 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6722 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6723 | do_cleanups (ui_out_chain); |
6724 | break; | |
6725 | case bp_access_watchpoint: | |
6726 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6727 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6728 | ui_out_field_int (uiout, "number", b->number); | |
6729 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6730 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6731 | do_cleanups (ui_out_chain); |
6732 | break; | |
6733 | case bp_breakpoint: | |
6734 | if (ui_out_is_mi_like_p (uiout)) | |
6735 | { | |
6736 | say_where = 0; | |
6737 | break; | |
6738 | } | |
2cec12e5 AR |
6739 | if (b->disposition == disp_del) |
6740 | printf_filtered (_("Temporary breakpoint")); | |
6741 | else | |
6742 | printf_filtered (_("Breakpoint")); | |
6743 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6744 | say_where = 1; |
6745 | break; | |
6746 | case bp_hardware_breakpoint: | |
6747 | if (ui_out_is_mi_like_p (uiout)) | |
6748 | { | |
6749 | say_where = 0; | |
6750 | break; | |
6751 | } | |
a3f17187 | 6752 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6753 | say_where = 1; |
6754 | break; | |
1042e4c0 SS |
6755 | case bp_tracepoint: |
6756 | if (ui_out_is_mi_like_p (uiout)) | |
6757 | { | |
6758 | say_where = 0; | |
6759 | break; | |
6760 | } | |
6761 | printf_filtered (_("Tracepoint")); | |
6762 | printf_filtered (_(" %d"), b->number); | |
6763 | say_where = 1; | |
6764 | break; | |
7a697b8d SS |
6765 | case bp_fast_tracepoint: |
6766 | if (ui_out_is_mi_like_p (uiout)) | |
6767 | { | |
6768 | say_where = 0; | |
6769 | break; | |
6770 | } | |
6771 | printf_filtered (_("Fast tracepoint")); | |
6772 | printf_filtered (_(" %d"), b->number); | |
6773 | say_where = 1; | |
6774 | break; | |
0fb4aa4b PA |
6775 | case bp_static_tracepoint: |
6776 | if (ui_out_is_mi_like_p (uiout)) | |
6777 | { | |
6778 | say_where = 0; | |
6779 | break; | |
6780 | } | |
6781 | printf_filtered (_("Static tracepoint")); | |
6782 | printf_filtered (_(" %d"), b->number); | |
6783 | say_where = 1; | |
6784 | break; | |
3086aeae DJ |
6785 | |
6786 | case bp_until: | |
6787 | case bp_finish: | |
6788 | case bp_longjmp: | |
6789 | case bp_longjmp_resume: | |
6790 | case bp_step_resume: | |
3086aeae | 6791 | case bp_call_dummy: |
aa7d318d | 6792 | case bp_std_terminate: |
3086aeae DJ |
6793 | case bp_watchpoint_scope: |
6794 | case bp_shlib_event: | |
6795 | case bp_thread_event: | |
6796 | case bp_overlay_event: | |
4efc6507 | 6797 | case bp_jit_event: |
0fd8e87f | 6798 | case bp_longjmp_master: |
aa7d318d | 6799 | case bp_std_terminate_master: |
3086aeae DJ |
6800 | break; |
6801 | } | |
c906108c | 6802 | |
c906108c SS |
6803 | if (say_where) |
6804 | { | |
a3f17187 AC |
6805 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6806 | single string. */ | |
0d381245 | 6807 | if (b->loc == NULL) |
c906108c | 6808 | { |
a3f17187 | 6809 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6810 | } |
6811 | else | |
6812 | { | |
79a45b7d | 6813 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6814 | { |
6815 | printf_filtered (" at "); | |
5af949e3 UW |
6816 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6817 | gdb_stdout); | |
0101ce28 JJ |
6818 | } |
6819 | if (b->source_file) | |
6820 | printf_filtered (": file %s, line %d.", | |
6821 | b->source_file, b->line_number); | |
0d381245 VP |
6822 | |
6823 | if (b->loc->next) | |
6824 | { | |
6825 | struct bp_location *loc = b->loc; | |
6826 | int n = 0; | |
6827 | for (; loc; loc = loc->next) | |
6828 | ++n; | |
6829 | printf_filtered (" (%d locations)", n); | |
6830 | } | |
6831 | ||
c906108c | 6832 | } |
c906108c | 6833 | } |
9dc5e2a9 | 6834 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6835 | return; |
c906108c SS |
6836 | printf_filtered ("\n"); |
6837 | } | |
c906108c | 6838 | \f |
c5aa993b | 6839 | |
0d381245 | 6840 | static struct bp_location * |
39d61571 | 6841 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6842 | const struct symtab_and_line *sal) |
6843 | { | |
6844 | struct bp_location *loc, **tmp; | |
6845 | ||
39d61571 | 6846 | loc = allocate_bp_location (b); |
0d381245 VP |
6847 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6848 | ; | |
6849 | *tmp = loc; | |
a6d9a66e UW |
6850 | loc->gdbarch = get_sal_arch (*sal); |
6851 | if (!loc->gdbarch) | |
6852 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6853 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6854 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6855 | loc->requested_address, b->type); | |
6c95b8df PA |
6856 | loc->pspace = sal->pspace; |
6857 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6858 | loc->section = sal->section; |
6859 | ||
6860 | set_breakpoint_location_function (loc); | |
6861 | return loc; | |
6862 | } | |
514f746b AR |
6863 | \f |
6864 | ||
6865 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6866 | return 0 otherwise. */ | |
6867 | ||
6868 | static int | |
6869 | bp_loc_is_permanent (struct bp_location *loc) | |
6870 | { | |
6871 | int len; | |
6872 | CORE_ADDR addr; | |
6873 | const gdb_byte *brk; | |
6874 | gdb_byte *target_mem; | |
939c61fa JK |
6875 | struct cleanup *cleanup; |
6876 | int retval = 0; | |
514f746b AR |
6877 | |
6878 | gdb_assert (loc != NULL); | |
6879 | ||
6880 | addr = loc->address; | |
a6d9a66e | 6881 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6882 | |
939c61fa JK |
6883 | /* Software breakpoints unsupported? */ |
6884 | if (brk == NULL) | |
6885 | return 0; | |
6886 | ||
514f746b AR |
6887 | target_mem = alloca (len); |
6888 | ||
939c61fa JK |
6889 | /* Enable the automatic memory restoration from breakpoints while |
6890 | we read the memory. Otherwise we could say about our temporary | |
6891 | breakpoints they are permanent. */ | |
6c95b8df PA |
6892 | cleanup = save_current_space_and_thread (); |
6893 | ||
6894 | switch_to_program_space_and_thread (loc->pspace); | |
6895 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6896 | |
514f746b AR |
6897 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6898 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6899 | retval = 1; |
514f746b | 6900 | |
939c61fa JK |
6901 | do_cleanups (cleanup); |
6902 | ||
6903 | return retval; | |
514f746b AR |
6904 | } |
6905 | ||
6906 | ||
c3f6f71d | 6907 | |
018d34a4 VP |
6908 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6909 | as textual description of the location, and COND_STRING | |
db107f19 | 6910 | as condition expression. */ |
018d34a4 VP |
6911 | |
6912 | static void | |
8cdf0e15 VP |
6913 | create_breakpoint_sal (struct gdbarch *gdbarch, |
6914 | struct symtabs_and_lines sals, char *addr_string, | |
6915 | char *cond_string, | |
6916 | enum bptype type, enum bpdisp disposition, | |
6917 | int thread, int task, int ignore_count, | |
6918 | struct breakpoint_ops *ops, int from_tty, int enabled) | |
018d34a4 | 6919 | { |
0d381245 VP |
6920 | struct breakpoint *b = NULL; |
6921 | int i; | |
018d34a4 VP |
6922 | |
6923 | if (type == bp_hardware_breakpoint) | |
6924 | { | |
6925 | int i = hw_breakpoint_used_count (); | |
6926 | int target_resources_ok = | |
d92524f1 | 6927 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6928 | i + 1, 0); |
6929 | if (target_resources_ok == 0) | |
6930 | error (_("No hardware breakpoint support in the target.")); | |
6931 | else if (target_resources_ok < 0) | |
6932 | error (_("Hardware breakpoints used exceeds limit.")); | |
6933 | } | |
6934 | ||
6c95b8df PA |
6935 | gdb_assert (sals.nelts > 0); |
6936 | ||
0d381245 VP |
6937 | for (i = 0; i < sals.nelts; ++i) |
6938 | { | |
6939 | struct symtab_and_line sal = sals.sals[i]; | |
6940 | struct bp_location *loc; | |
6941 | ||
6942 | if (from_tty) | |
5af949e3 UW |
6943 | { |
6944 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6945 | if (!loc_gdbarch) | |
6946 | loc_gdbarch = gdbarch; | |
6947 | ||
6948 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6949 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6950 | } |
0d381245 VP |
6951 | |
6952 | if (i == 0) | |
6953 | { | |
a6d9a66e | 6954 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6955 | set_breakpoint_count (breakpoint_count + 1); |
6956 | b->number = breakpoint_count; | |
6957 | b->thread = thread; | |
4a306c9a | 6958 | b->task = task; |
018d34a4 | 6959 | |
0d381245 VP |
6960 | b->cond_string = cond_string; |
6961 | b->ignore_count = ignore_count; | |
41447f92 | 6962 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6963 | b->disposition = disposition; |
6c95b8df PA |
6964 | b->pspace = sals.sals[0].pspace; |
6965 | ||
0fb4aa4b PA |
6966 | if (type == bp_static_tracepoint) |
6967 | { | |
6968 | struct static_tracepoint_marker marker; | |
6969 | ||
6970 | if (is_marker_spec (addr_string)) | |
6971 | { | |
6972 | /* We already know the marker exists, otherwise, we | |
6973 | wouldn't see a sal for it. */ | |
6974 | char *p = &addr_string[3]; | |
6975 | char *endp; | |
6976 | char *marker_str; | |
6977 | int i; | |
6978 | ||
6979 | while (*p == ' ' || *p == '\t') | |
6980 | p++; | |
6981 | ||
6982 | endp = p; | |
6983 | while (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
6984 | endp++; | |
6985 | ||
6986 | marker_str = savestring (p, endp - p); | |
6987 | b->static_trace_marker_id = marker_str; | |
6988 | ||
6989 | printf_filtered (_("Probed static tracepoint marker \"%s\"\n"), | |
6990 | b->static_trace_marker_id); | |
6991 | } | |
6992 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
6993 | { | |
6994 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
6995 | release_static_tracepoint_marker (&marker); | |
6996 | ||
6997 | printf_filtered (_("Probed static tracepoint marker \"%s\"\n"), | |
6998 | b->static_trace_marker_id); | |
6999 | } | |
7000 | else | |
7001 | warning (_("\ | |
7002 | Couldn't determine the static tracepoint marker to probe")); | |
7003 | } | |
7004 | ||
6c95b8df | 7005 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7006 | && (b->type == bp_breakpoint |
7007 | || b->type == bp_hardware_breakpoint)) | |
7008 | b->enable_state = bp_startup_disabled; | |
7009 | ||
0d381245 VP |
7010 | loc = b->loc; |
7011 | } | |
7012 | else | |
018d34a4 | 7013 | { |
39d61571 | 7014 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7015 | } |
7016 | ||
514f746b AR |
7017 | if (bp_loc_is_permanent (loc)) |
7018 | make_breakpoint_permanent (b); | |
7019 | ||
0d381245 VP |
7020 | if (b->cond_string) |
7021 | { | |
7022 | char *arg = b->cond_string; | |
d32a6982 | 7023 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7024 | if (*arg) |
db107f19 | 7025 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7026 | } |
0d381245 | 7027 | } |
018d34a4 VP |
7028 | |
7029 | if (addr_string) | |
7030 | b->addr_string = addr_string; | |
7031 | else | |
7032 | /* addr_string has to be used or breakpoint_re_set will delete | |
7033 | me. */ | |
5af949e3 UW |
7034 | b->addr_string |
7035 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7036 | |
604133b5 | 7037 | b->ops = ops; |
018d34a4 VP |
7038 | mention (b); |
7039 | } | |
7040 | ||
ed0616c6 VP |
7041 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7042 | elements to fill the void space. */ | |
2c0b251b PA |
7043 | static void |
7044 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7045 | { |
7046 | int i = index_to_remove+1; | |
7047 | int last_index = sal->nelts-1; | |
7048 | ||
7049 | for (;i <= last_index; ++i) | |
7050 | sal->sals[i-1] = sal->sals[i]; | |
7051 | ||
7052 | --(sal->nelts); | |
7053 | } | |
7054 | ||
6c95b8df PA |
7055 | /* If appropriate, obtains all sals that correspond to the same file |
7056 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7057 | will want to set a breakpoint at foo.c:line, and not really care | |
7058 | about program spaces. This is done only if SAL does not have | |
7059 | explicit PC and has line and file information. If we got just a | |
7060 | single expanded sal, return the original. | |
ed0616c6 | 7061 | |
6c95b8df PA |
7062 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7063 | which the name of enclosing function is different from SAL. This | |
7064 | makes sure that if we have breakpoint originally set in template | |
7065 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7066 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7067 | |
2c0b251b | 7068 | static struct symtabs_and_lines |
ed0616c6 VP |
7069 | expand_line_sal_maybe (struct symtab_and_line sal) |
7070 | { | |
7071 | struct symtabs_and_lines expanded; | |
7072 | CORE_ADDR original_pc = sal.pc; | |
7073 | char *original_function = NULL; | |
7074 | int found; | |
7075 | int i; | |
6c95b8df | 7076 | struct cleanup *old_chain; |
ed0616c6 VP |
7077 | |
7078 | /* If we have explicit pc, don't expand. | |
7079 | If we have no line number, we can't expand. */ | |
7080 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7081 | { | |
7082 | expanded.nelts = 1; | |
7083 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7084 | expanded.sals[0] = sal; | |
7085 | return expanded; | |
7086 | } | |
7087 | ||
7088 | sal.pc = 0; | |
6c95b8df PA |
7089 | |
7090 | old_chain = save_current_space_and_thread (); | |
7091 | ||
7092 | switch_to_program_space_and_thread (sal.pspace); | |
7093 | ||
ed0616c6 | 7094 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7095 | |
7096 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7097 | expanded = expand_line_sal (sal); |
6c95b8df | 7098 | |
ed0616c6 VP |
7099 | if (expanded.nelts == 1) |
7100 | { | |
3dba1c98 JB |
7101 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7102 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7103 | xfree (expanded.sals); |
7104 | expanded.nelts = 1; | |
7105 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7106 | sal.pc = original_pc; | |
7107 | expanded.sals[0] = sal; | |
3dba1c98 | 7108 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7109 | do_cleanups (old_chain); |
ed0616c6 VP |
7110 | return expanded; |
7111 | } | |
7112 | ||
7113 | if (!sal.explicit_line) | |
7114 | { | |
7115 | CORE_ADDR func_addr, func_end; | |
7116 | for (i = 0; i < expanded.nelts; ++i) | |
7117 | { | |
7118 | CORE_ADDR pc = expanded.sals[i].pc; | |
7119 | char *this_function; | |
6c95b8df PA |
7120 | |
7121 | /* We need to switch threads as well since we're about to | |
7122 | read memory. */ | |
7123 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7124 | ||
ed0616c6 VP |
7125 | if (find_pc_partial_function (pc, &this_function, |
7126 | &func_addr, &func_end)) | |
7127 | { | |
059fb39f PM |
7128 | if (this_function |
7129 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7130 | { |
7131 | remove_sal (&expanded, i); | |
7132 | --i; | |
7133 | } | |
ed0616c6 VP |
7134 | } |
7135 | } | |
7136 | } | |
059acae7 UW |
7137 | |
7138 | /* Skip the function prologue if necessary. */ | |
7139 | for (i = 0; i < expanded.nelts; ++i) | |
7140 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7141 | |
6c95b8df PA |
7142 | do_cleanups (old_chain); |
7143 | ||
ed0616c6 VP |
7144 | if (expanded.nelts <= 1) |
7145 | { | |
7146 | /* This is un ugly workaround. If we get zero | |
7147 | expanded sals then something is really wrong. | |
7148 | Fix that by returnign the original sal. */ | |
7149 | xfree (expanded.sals); | |
7150 | expanded.nelts = 1; | |
7151 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7152 | sal.pc = original_pc; | |
7153 | expanded.sals[0] = sal; | |
7154 | return expanded; | |
7155 | } | |
7156 | ||
7157 | if (original_pc) | |
7158 | { | |
7159 | found = 0; | |
7160 | for (i = 0; i < expanded.nelts; ++i) | |
7161 | if (expanded.sals[i].pc == original_pc) | |
7162 | { | |
7163 | found = 1; | |
7164 | break; | |
7165 | } | |
7166 | gdb_assert (found); | |
7167 | } | |
7168 | ||
7169 | return expanded; | |
7170 | } | |
7171 | ||
018d34a4 VP |
7172 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7173 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7174 | value. COND_STRING, if not NULL, specified the condition to be | |
7175 | used for all breakpoints. Essentially the only case where | |
7176 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7177 | function. In that case, it's still not possible to specify | |
7178 | separate conditions for different overloaded functions, so | |
7179 | we take just a single condition string. | |
7180 | ||
c3f6f71d | 7181 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7182 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7183 | array contents). If the function fails (error() is called), the |
7184 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
7185 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
7186 | |
7187 | static void | |
8cdf0e15 VP |
7188 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7189 | struct symtabs_and_lines sals, char **addr_string, | |
7190 | char *cond_string, | |
7191 | enum bptype type, enum bpdisp disposition, | |
7192 | int thread, int task, int ignore_count, | |
7193 | struct breakpoint_ops *ops, int from_tty, | |
7194 | int enabled) | |
c906108c | 7195 | { |
018d34a4 | 7196 | int i; |
cc59ec59 | 7197 | |
018d34a4 | 7198 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7199 | { |
ed0616c6 VP |
7200 | struct symtabs_and_lines expanded = |
7201 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7202 | |
8cdf0e15 VP |
7203 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], |
7204 | cond_string, type, disposition, | |
7205 | thread, task, ignore_count, ops, from_tty, enabled); | |
c3f6f71d | 7206 | } |
c3f6f71d | 7207 | } |
c906108c | 7208 | |
c3f6f71d JM |
7209 | /* Parse ARG which is assumed to be a SAL specification possibly |
7210 | followed by conditionals. On return, SALS contains an array of SAL | |
7211 | addresses found. ADDR_STRING contains a vector of (canonical) | |
7212 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 7213 | |
b9362cc7 | 7214 | static void |
c3f6f71d JM |
7215 | parse_breakpoint_sals (char **address, |
7216 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
7217 | char ***addr_string, |
7218 | int *not_found_ptr) | |
c3f6f71d JM |
7219 | { |
7220 | char *addr_start = *address; | |
cc59ec59 | 7221 | |
c3f6f71d JM |
7222 | *addr_string = NULL; |
7223 | /* If no arg given, or if first arg is 'if ', use the default | |
7224 | breakpoint. */ | |
7225 | if ((*address) == NULL | |
7226 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7227 | { |
7228 | if (default_breakpoint_valid) | |
7229 | { | |
c3f6f71d | 7230 | struct symtab_and_line sal; |
cc59ec59 | 7231 | |
fe39c653 | 7232 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 7233 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7234 | xmalloc (sizeof (struct symtab_and_line)); |
7235 | sal.pc = default_breakpoint_address; | |
7236 | sal.line = default_breakpoint_line; | |
7237 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7238 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7239 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
7240 | |
7241 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
7242 | the default_breakpoint_address. So make sure to set | |
7243 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
7244 | sals to include all other instances with the same symtab and line. | |
7245 | */ | |
7246 | sal.explicit_pc = 1; | |
7247 | ||
c3f6f71d JM |
7248 | sals->sals[0] = sal; |
7249 | sals->nelts = 1; | |
c906108c SS |
7250 | } |
7251 | else | |
8a3fe4f8 | 7252 | error (_("No default breakpoint address now.")); |
c906108c SS |
7253 | } |
7254 | else | |
7255 | { | |
c906108c | 7256 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
7257 | current_source_symtab (which is decode_line_1's default). This |
7258 | should produce the results we want almost all of the time while | |
1aeae86e AF |
7259 | leaving default_breakpoint_* alone. |
7260 | ObjC: However, don't match an Objective-C method name which | |
7261 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7262 | |
c214a6fd | 7263 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7264 | |
c906108c | 7265 | if (default_breakpoint_valid |
0378c332 | 7266 | && (!cursal.symtab |
1aeae86e AF |
7267 | || ((strchr ("+-", (*address)[0]) != NULL) |
7268 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7269 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
7270 | default_breakpoint_line, addr_string, |
7271 | not_found_ptr); | |
c906108c | 7272 | else |
0101ce28 JJ |
7273 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
7274 | addr_string, not_found_ptr); | |
c906108c | 7275 | } |
c3f6f71d JM |
7276 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7277 | if (sals->nelts > 0 && *addr_string == NULL) | |
7278 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
7279 | if (addr_start != (*address)) | |
c906108c | 7280 | { |
c3f6f71d | 7281 | int i; |
cc59ec59 | 7282 | |
c3f6f71d | 7283 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7284 | { |
c3f6f71d JM |
7285 | /* Add the string if not present. */ |
7286 | if ((*addr_string)[i] == NULL) | |
cc59ec59 MS |
7287 | (*addr_string)[i] = savestring (addr_start, |
7288 | (*address) - addr_start); | |
c906108c SS |
7289 | } |
7290 | } | |
c3f6f71d | 7291 | } |
c906108c | 7292 | |
c906108c | 7293 | |
c3f6f71d JM |
7294 | /* Convert each SAL into a real PC. Verify that the PC can be |
7295 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 7296 | |
b9362cc7 | 7297 | static void |
23e7acfb | 7298 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7299 | { |
7300 | int i; | |
cc59ec59 | 7301 | |
c3f6f71d | 7302 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7303 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7304 | } |
7305 | ||
7a697b8d SS |
7306 | /* Fast tracepoints may have restrictions on valid locations. For |
7307 | instance, a fast tracepoint using a jump instead of a trap will | |
7308 | likely have to overwrite more bytes than a trap would, and so can | |
7309 | only be placed where the instruction is longer than the jump, or a | |
7310 | multi-instruction sequence does not have a jump into the middle of | |
7311 | it, etc. */ | |
7312 | ||
7313 | static void | |
7314 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7315 | struct symtabs_and_lines *sals) | |
7316 | { | |
7317 | int i, rslt; | |
7318 | struct symtab_and_line *sal; | |
7319 | char *msg; | |
7320 | struct cleanup *old_chain; | |
7321 | ||
7322 | for (i = 0; i < sals->nelts; i++) | |
7323 | { | |
7324 | sal = &sals->sals[i]; | |
7325 | ||
7326 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7327 | NULL, &msg); | |
7328 | old_chain = make_cleanup (xfree, msg); | |
7329 | ||
7330 | if (!rslt) | |
7331 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7332 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7333 | ||
7334 | do_cleanups (old_chain); | |
7335 | } | |
7336 | } | |
7337 | ||
05ff989b | 7338 | static void |
0101ce28 JJ |
7339 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
7340 | { | |
7341 | struct captured_parse_breakpoint_args *args = data; | |
7342 | ||
7343 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
7344 | args->not_found_ptr); | |
0101ce28 JJ |
7345 | } |
7346 | ||
018d34a4 VP |
7347 | /* Given TOK, a string specification of condition and thread, as |
7348 | accepted by the 'break' command, extract the condition | |
7349 | string and thread number and set *COND_STRING and *THREAD. | |
7350 | PC identifies the context at which the condition should be parsed. | |
7351 | If no condition is found, *COND_STRING is set to NULL. | |
7352 | If no thread is found, *THREAD is set to -1. */ | |
7353 | static void | |
7354 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7355 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7356 | { |
7357 | *cond_string = NULL; | |
7358 | *thread = -1; | |
7359 | while (tok && *tok) | |
7360 | { | |
7361 | char *end_tok; | |
7362 | int toklen; | |
7363 | char *cond_start = NULL; | |
7364 | char *cond_end = NULL; | |
cc59ec59 | 7365 | |
018d34a4 VP |
7366 | while (*tok == ' ' || *tok == '\t') |
7367 | tok++; | |
7368 | ||
7369 | end_tok = tok; | |
7370 | ||
7371 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7372 | end_tok++; | |
7373 | ||
7374 | toklen = end_tok - tok; | |
7375 | ||
7376 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7377 | { | |
f7545552 TT |
7378 | struct expression *expr; |
7379 | ||
018d34a4 | 7380 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7381 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7382 | xfree (expr); | |
018d34a4 VP |
7383 | cond_end = tok; |
7384 | *cond_string = savestring (cond_start, | |
7385 | cond_end - cond_start); | |
7386 | } | |
7387 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7388 | { | |
7389 | char *tmptok; | |
7390 | ||
7391 | tok = end_tok + 1; | |
7392 | tmptok = tok; | |
7393 | *thread = strtol (tok, &tok, 0); | |
7394 | if (tok == tmptok) | |
7395 | error (_("Junk after thread keyword.")); | |
7396 | if (!valid_thread_id (*thread)) | |
7397 | error (_("Unknown thread %d."), *thread); | |
7398 | } | |
4a306c9a JB |
7399 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7400 | { | |
7401 | char *tmptok; | |
7402 | ||
7403 | tok = end_tok + 1; | |
7404 | tmptok = tok; | |
7405 | *task = strtol (tok, &tok, 0); | |
7406 | if (tok == tmptok) | |
7407 | error (_("Junk after task keyword.")); | |
7408 | if (!valid_task_id (*task)) | |
b6199126 | 7409 | error (_("Unknown task %d."), *task); |
4a306c9a | 7410 | } |
018d34a4 VP |
7411 | else |
7412 | error (_("Junk at end of arguments.")); | |
7413 | } | |
7414 | } | |
7415 | ||
0fb4aa4b PA |
7416 | /* Decode a static tracepoint marker spec. */ |
7417 | ||
7418 | static struct symtabs_and_lines | |
7419 | decode_static_tracepoint_spec (char **arg_p) | |
7420 | { | |
7421 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7422 | struct symtabs_and_lines sals; | |
7423 | struct symtab_and_line sal; | |
7424 | struct symbol *sym; | |
7425 | struct cleanup *old_chain; | |
7426 | char *p = &(*arg_p)[3]; | |
7427 | char *endp; | |
7428 | char *marker_str; | |
7429 | int i; | |
7430 | ||
7431 | while (*p == ' ' || *p == '\t') | |
7432 | p++; | |
7433 | ||
7434 | endp = p; | |
7435 | while (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7436 | endp++; | |
7437 | ||
7438 | marker_str = savestring (p, endp - p); | |
7439 | old_chain = make_cleanup (xfree, marker_str); | |
7440 | ||
7441 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7442 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7443 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7444 | ||
7445 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7446 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7447 | ||
7448 | for (i = 0; i < sals.nelts; i++) | |
7449 | { | |
7450 | struct static_tracepoint_marker *marker; | |
7451 | ||
7452 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7453 | ||
7454 | init_sal (&sals.sals[i]); | |
7455 | ||
7456 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7457 | sals.sals[i].pc = marker->address; | |
7458 | ||
7459 | release_static_tracepoint_marker (marker); | |
7460 | } | |
7461 | ||
7462 | do_cleanups (old_chain); | |
7463 | ||
7464 | *arg_p = endp; | |
7465 | return sals; | |
7466 | } | |
7467 | ||
fd9b8c24 PA |
7468 | /* Set a breakpoint. This function is shared between CLI and MI |
7469 | functions for setting a breakpoint. This function has two major | |
7470 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7471 | parameter. If non-zero, the function will parse arg, extracting | |
7472 | breakpoint location, address and thread. Otherwise, ARG is just the | |
7473 | location of breakpoint, with condition and thread specified by the | |
7474 | COND_STRING and THREAD parameters. Returns true if any breakpoint | |
7475 | was created; false otherwise. */ | |
0101ce28 | 7476 | |
8cdf0e15 VP |
7477 | int |
7478 | create_breakpoint (struct gdbarch *gdbarch, | |
7479 | char *arg, char *cond_string, int thread, | |
7480 | int parse_condition_and_thread, | |
0fb4aa4b | 7481 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7482 | int ignore_count, |
7483 | enum auto_boolean pending_break_support, | |
7484 | struct breakpoint_ops *ops, | |
7485 | int from_tty, | |
7486 | int enabled) | |
c3f6f71d | 7487 | { |
71fff37b | 7488 | struct gdb_exception e; |
c3f6f71d | 7489 | struct symtabs_and_lines sals; |
0101ce28 | 7490 | struct symtab_and_line pending_sal; |
0101ce28 | 7491 | char *copy_arg; |
c3f6f71d JM |
7492 | char *addr_start = arg; |
7493 | char **addr_string; | |
7494 | struct cleanup *old_chain; | |
80c99de1 | 7495 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 7496 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 7497 | int i; |
0101ce28 | 7498 | int pending = 0; |
0101ce28 | 7499 | int not_found = 0; |
4a306c9a | 7500 | int task = 0; |
86b17b60 | 7501 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7502 | |
c3f6f71d JM |
7503 | sals.sals = NULL; |
7504 | sals.nelts = 0; | |
7505 | addr_string = NULL; | |
c3f6f71d | 7506 | |
0101ce28 JJ |
7507 | parse_args.arg_p = &arg; |
7508 | parse_args.sals_p = &sals; | |
7509 | parse_args.addr_string_p = &addr_string; | |
7510 | parse_args.not_found_ptr = ¬_found; | |
7511 | ||
0fb4aa4b PA |
7512 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7513 | { | |
7514 | int i; | |
7515 | ||
7516 | sals = decode_static_tracepoint_spec (&arg); | |
7517 | ||
7518 | copy_arg = savestring (addr_start, arg - addr_start); | |
7519 | addr_string = xcalloc (sals.nelts, sizeof (char **)); | |
7520 | for (i = 0; i < sals.nelts; i++) | |
7521 | addr_string[i] = xstrdup (copy_arg); | |
7522 | goto done; | |
7523 | } | |
7524 | ||
05ff989b AC |
7525 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
7526 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
7527 | |
7528 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7529 | switch (e.reason) |
0101ce28 | 7530 | { |
05ff989b | 7531 | case RETURN_QUIT: |
98deb0da | 7532 | throw_exception (e); |
05ff989b AC |
7533 | case RETURN_ERROR: |
7534 | switch (e.error) | |
0101ce28 | 7535 | { |
05ff989b | 7536 | case NOT_FOUND_ERROR: |
0101ce28 | 7537 | |
05ff989b AC |
7538 | /* If pending breakpoint support is turned off, throw |
7539 | error. */ | |
fa8d40ab JJ |
7540 | |
7541 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7542 | throw_exception (e); |
7543 | ||
7544 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7545 | |
05ff989b AC |
7546 | /* If pending breakpoint support is auto query and the user |
7547 | selects no, then simply return the error code. */ | |
059fb39f PM |
7548 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
7549 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
fd9b8c24 | 7550 | return 0; |
fa8d40ab | 7551 | |
05ff989b AC |
7552 | /* At this point, either the user was queried about setting |
7553 | a pending breakpoint and selected yes, or pending | |
7554 | breakpoint behavior is on and thus a pending breakpoint | |
7555 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
7556 | copy_arg = xstrdup (addr_start); |
7557 | addr_string = ©_arg; | |
7558 | sals.nelts = 1; | |
7559 | sals.sals = &pending_sal; | |
7560 | pending_sal.pc = 0; | |
7561 | pending = 1; | |
05ff989b AC |
7562 | break; |
7563 | default: | |
98deb0da | 7564 | throw_exception (e); |
0101ce28 | 7565 | } |
05ff989b AC |
7566 | default: |
7567 | if (!sals.nelts) | |
fd9b8c24 | 7568 | return 0; |
0101ce28 | 7569 | } |
c3f6f71d | 7570 | |
0fb4aa4b PA |
7571 | done: |
7572 | ||
c3f6f71d JM |
7573 | /* Create a chain of things that always need to be cleaned up. */ |
7574 | old_chain = make_cleanup (null_cleanup, 0); | |
7575 | ||
0101ce28 JJ |
7576 | if (!pending) |
7577 | { | |
7578 | /* Make sure that all storage allocated to SALS gets freed. */ | |
7579 | make_cleanup (xfree, sals.sals); | |
7580 | ||
7581 | /* Cleanup the addr_string array but not its contents. */ | |
7582 | make_cleanup (xfree, addr_string); | |
7583 | } | |
c3f6f71d | 7584 | |
c3f6f71d JM |
7585 | /* ----------------------------- SNIP ----------------------------- |
7586 | Anything added to the cleanup chain beyond this point is assumed | |
7587 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
7588 | then the memory is not reclaimed. */ |
7589 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
7590 | |
7591 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 7592 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
7593 | for (i = 0; i < sals.nelts; i++) |
7594 | { | |
7595 | if (addr_string[i] != NULL) | |
b8c9b27d | 7596 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
7597 | } |
7598 | ||
7599 | /* Resolve all line numbers to PC's and verify that the addresses | |
7600 | are ok for the target. */ | |
0101ce28 | 7601 | if (!pending) |
23e7acfb | 7602 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 7603 | |
7a697b8d SS |
7604 | /* Fast tracepoints may have additional restrictions on location. */ |
7605 | if (type_wanted == bp_fast_tracepoint) | |
7606 | check_fast_tracepoint_sals (gdbarch, &sals); | |
7607 | ||
c3f6f71d JM |
7608 | /* Verify that condition can be parsed, before setting any |
7609 | breakpoints. Allocate a separate condition expression for each | |
7610 | breakpoint. */ | |
0101ce28 | 7611 | if (!pending) |
c3f6f71d | 7612 | { |
2f069f6f | 7613 | if (parse_condition_and_thread) |
72b2ff0e VP |
7614 | { |
7615 | /* Here we only parse 'arg' to separate condition | |
7616 | from thread number, so parsing in context of first | |
7617 | sal is OK. When setting the breakpoint we'll | |
7618 | re-parse it in context of each sal. */ | |
7619 | cond_string = NULL; | |
7620 | thread = -1; | |
4a306c9a JB |
7621 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7622 | &thread, &task); | |
72b2ff0e VP |
7623 | if (cond_string) |
7624 | make_cleanup (xfree, cond_string); | |
7625 | } | |
2f069f6f | 7626 | else |
72b2ff0e VP |
7627 | { |
7628 | /* Create a private copy of condition string. */ | |
7629 | if (cond_string) | |
7630 | { | |
7631 | cond_string = xstrdup (cond_string); | |
7632 | make_cleanup (xfree, cond_string); | |
7633 | } | |
7634 | } | |
0fb4aa4b PA |
7635 | |
7636 | /* If the user is creating a static tracepoint by marker id | |
7637 | (strace -m MARKER_ID), then store the sals index, so that | |
7638 | breakpoint_re_set can try to match up which of the newly | |
7639 | found markers corresponds to this one, and, don't try to | |
7640 | expand multiple locations for each sal, given than SALS | |
7641 | already should contain all sals for MARKER_ID. */ | |
7642 | if (type_wanted == bp_static_tracepoint | |
7643 | && is_marker_spec (addr_string[0])) | |
7644 | { | |
7645 | int i; | |
7646 | ||
7647 | for (i = 0; i < sals.nelts; ++i) | |
7648 | { | |
7649 | struct symtabs_and_lines expanded; | |
7650 | struct breakpoint *tp; | |
7651 | struct cleanup *old_chain; | |
7652 | ||
7653 | expanded.nelts = 1; | |
7654 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7655 | expanded.sals[0] = sals.sals[i]; | |
7656 | old_chain = make_cleanup (xfree, expanded.sals); | |
7657 | ||
7658 | create_breakpoint_sal (gdbarch, expanded, addr_string[i], | |
7659 | cond_string, type_wanted, | |
7660 | tempflag ? disp_del : disp_donttouch, | |
7661 | thread, task, ignore_count, ops, | |
7662 | from_tty, enabled); | |
7663 | ||
7664 | do_cleanups (old_chain); | |
7665 | ||
7666 | /* Get the tracepoint we just created. */ | |
7667 | tp = get_breakpoint (breakpoint_count); | |
7668 | gdb_assert (tp != NULL); | |
7669 | ||
7670 | /* Given that its possible to have multiple markers with | |
7671 | the same string id, if the user is creating a static | |
7672 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
7673 | store the sals index, so that breakpoint_re_set can | |
7674 | try to match up which of the newly found markers | |
7675 | corresponds to this one */ | |
7676 | tp->static_trace_marker_id_idx = i; | |
7677 | } | |
7678 | } | |
7679 | else | |
7680 | create_breakpoints_sal (gdbarch, sals, addr_string, cond_string, | |
7681 | type_wanted, tempflag ? disp_del : disp_donttouch, | |
7682 | thread, task, ignore_count, ops, from_tty, | |
7683 | enabled); | |
c906108c | 7684 | } |
0101ce28 JJ |
7685 | else |
7686 | { | |
0101ce28 JJ |
7687 | struct breakpoint *b; |
7688 | ||
0101ce28 JJ |
7689 | make_cleanup (xfree, copy_arg); |
7690 | ||
a6d9a66e | 7691 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
7692 | set_breakpoint_count (breakpoint_count + 1); |
7693 | b->number = breakpoint_count; | |
72b2ff0e | 7694 | b->thread = -1; |
018d34a4 | 7695 | b->addr_string = addr_string[0]; |
72b2ff0e | 7696 | b->cond_string = NULL; |
0101ce28 | 7697 | b->ignore_count = ignore_count; |
0101ce28 | 7698 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7699 | b->condition_not_parsed = 1; |
604133b5 | 7700 | b->ops = ops; |
41447f92 | 7701 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7702 | b->pspace = current_program_space; |
74960c60 | 7703 | |
6c95b8df | 7704 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7705 | && (b->type == bp_breakpoint |
7706 | || b->type == bp_hardware_breakpoint)) | |
7707 | b->enable_state = bp_startup_disabled; | |
7708 | ||
0101ce28 JJ |
7709 | mention (b); |
7710 | } | |
7711 | ||
c3f6f71d | 7712 | if (sals.nelts > 1) |
95a42b64 TT |
7713 | { |
7714 | warning (_("Multiple breakpoints were set.\n" | |
7715 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 7716 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
7717 | } |
7718 | ||
80c99de1 PA |
7719 | /* That's it. Discard the cleanups for data inserted into the |
7720 | breakpoint. */ | |
7721 | discard_cleanups (bkpt_chain); | |
7722 | /* But cleanup everything else. */ | |
c3f6f71d | 7723 | do_cleanups (old_chain); |
217dc9e2 | 7724 | |
80c99de1 | 7725 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7726 | update_global_location_list (1); |
fd9b8c24 PA |
7727 | |
7728 | return 1; | |
c3f6f71d | 7729 | } |
c906108c | 7730 | |
72b2ff0e VP |
7731 | /* Set a breakpoint. |
7732 | ARG is a string describing breakpoint address, | |
7733 | condition, and thread. | |
7734 | FLAG specifies if a breakpoint is hardware on, | |
7735 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7736 | and BP_TEMPFLAG. */ | |
7737 | ||
98deb0da | 7738 | static void |
72b2ff0e | 7739 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7740 | { |
72b2ff0e | 7741 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
7742 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
7743 | ? bp_hardware_breakpoint | |
7744 | : bp_breakpoint); | |
c3f6f71d | 7745 | |
8cdf0e15 VP |
7746 | create_breakpoint (get_current_arch (), |
7747 | arg, | |
7748 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 7749 | tempflag, type_wanted, |
8cdf0e15 VP |
7750 | 0 /* Ignore count */, |
7751 | pending_break_support, | |
7752 | NULL /* breakpoint_ops */, | |
7753 | from_tty, | |
7754 | 1 /* enabled */); | |
c906108c SS |
7755 | } |
7756 | ||
72b2ff0e | 7757 | |
c906108c SS |
7758 | /* Helper function for break_command_1 and disassemble_command. */ |
7759 | ||
7760 | void | |
fba45db2 | 7761 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7762 | { |
7763 | CORE_ADDR pc; | |
7764 | ||
7765 | if (sal->pc == 0 && sal->symtab != NULL) | |
7766 | { | |
7767 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7768 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7769 | sal->line, sal->symtab->filename); |
7770 | sal->pc = pc; | |
6a048695 JB |
7771 | |
7772 | /* If this SAL corresponds to a breakpoint inserted using | |
7773 | a line number, then skip the function prologue if necessary. */ | |
7774 | if (sal->explicit_line) | |
059acae7 | 7775 | skip_prologue_sal (sal); |
c906108c SS |
7776 | } |
7777 | ||
7778 | if (sal->section == 0 && sal->symtab != NULL) | |
7779 | { | |
7780 | struct blockvector *bv; | |
c5aa993b JM |
7781 | struct block *b; |
7782 | struct symbol *sym; | |
c906108c | 7783 | |
801e3a5b | 7784 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7785 | if (bv != NULL) |
7786 | { | |
7f0df278 | 7787 | sym = block_linkage_function (b); |
c906108c SS |
7788 | if (sym != NULL) |
7789 | { | |
7790 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7791 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7792 | } |
7793 | else | |
7794 | { | |
7795 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
7796 | have to look harder. This case can be executed if we have |
7797 | line numbers but no functions (as can happen in assembly | |
7798 | source). */ | |
c906108c | 7799 | |
c5aa993b | 7800 | struct minimal_symbol *msym; |
6c95b8df PA |
7801 | struct cleanup *old_chain = save_current_space_and_thread (); |
7802 | ||
7803 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
7804 | |
7805 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7806 | if (msym) | |
714835d5 | 7807 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7808 | |
7809 | do_cleanups (old_chain); | |
c906108c SS |
7810 | } |
7811 | } | |
7812 | } | |
7813 | } | |
7814 | ||
7815 | void | |
fba45db2 | 7816 | break_command (char *arg, int from_tty) |
c906108c | 7817 | { |
db107f19 | 7818 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7819 | } |
7820 | ||
c906108c | 7821 | void |
fba45db2 | 7822 | tbreak_command (char *arg, int from_tty) |
c906108c | 7823 | { |
db107f19 | 7824 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7825 | } |
7826 | ||
c906108c | 7827 | static void |
fba45db2 | 7828 | hbreak_command (char *arg, int from_tty) |
c906108c | 7829 | { |
db107f19 | 7830 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7831 | } |
7832 | ||
7833 | static void | |
fba45db2 | 7834 | thbreak_command (char *arg, int from_tty) |
c906108c | 7835 | { |
db107f19 | 7836 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7837 | } |
7838 | ||
7839 | static void | |
fba45db2 | 7840 | stop_command (char *arg, int from_tty) |
c906108c | 7841 | { |
a3f17187 | 7842 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7843 | Usage: stop in <function | address>\n\ |
a3f17187 | 7844 | stop at <line>\n")); |
c906108c SS |
7845 | } |
7846 | ||
7847 | static void | |
fba45db2 | 7848 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7849 | { |
7850 | int badInput = 0; | |
7851 | ||
c5aa993b | 7852 | if (arg == (char *) NULL) |
c906108c SS |
7853 | badInput = 1; |
7854 | else if (*arg != '*') | |
7855 | { | |
7856 | char *argptr = arg; | |
7857 | int hasColon = 0; | |
7858 | ||
53a5351d JM |
7859 | /* look for a ':'. If this is a line number specification, then |
7860 | say it is bad, otherwise, it should be an address or | |
7861 | function/method name */ | |
c906108c | 7862 | while (*argptr && !hasColon) |
c5aa993b JM |
7863 | { |
7864 | hasColon = (*argptr == ':'); | |
7865 | argptr++; | |
7866 | } | |
c906108c SS |
7867 | |
7868 | if (hasColon) | |
c5aa993b | 7869 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7870 | else |
c5aa993b | 7871 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7872 | } |
7873 | ||
7874 | if (badInput) | |
a3f17187 | 7875 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7876 | else |
db107f19 | 7877 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7878 | } |
7879 | ||
7880 | static void | |
fba45db2 | 7881 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7882 | { |
7883 | int badInput = 0; | |
7884 | ||
c5aa993b | 7885 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7886 | badInput = 1; |
7887 | else | |
7888 | { | |
7889 | char *argptr = arg; | |
7890 | int hasColon = 0; | |
7891 | ||
7892 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7893 | it is probably a line number. */ |
c906108c | 7894 | while (*argptr && !hasColon) |
c5aa993b JM |
7895 | { |
7896 | hasColon = (*argptr == ':'); | |
7897 | argptr++; | |
7898 | } | |
c906108c SS |
7899 | |
7900 | if (hasColon) | |
c5aa993b | 7901 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7902 | else |
c5aa993b | 7903 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7904 | } |
7905 | ||
7906 | if (badInput) | |
a3f17187 | 7907 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7908 | else |
db107f19 | 7909 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7910 | } |
7911 | ||
65d79d4b SDJ |
7912 | /* Return non-zero if EXP is verified as constant. Returned zero means EXP is |
7913 | variable. Also the constant detection may fail for some constant | |
7914 | expressions and in such case still falsely return zero. */ | |
7915 | static int | |
7916 | watchpoint_exp_is_const (const struct expression *exp) | |
7917 | { | |
7918 | int i = exp->nelts; | |
7919 | ||
7920 | while (i > 0) | |
7921 | { | |
7922 | int oplenp, argsp; | |
7923 | ||
7924 | /* We are only interested in the descriptor of each element. */ | |
7925 | operator_length (exp, i, &oplenp, &argsp); | |
7926 | i -= oplenp; | |
7927 | ||
7928 | switch (exp->elts[i].opcode) | |
7929 | { | |
7930 | case BINOP_ADD: | |
7931 | case BINOP_SUB: | |
7932 | case BINOP_MUL: | |
7933 | case BINOP_DIV: | |
7934 | case BINOP_REM: | |
7935 | case BINOP_MOD: | |
7936 | case BINOP_LSH: | |
7937 | case BINOP_RSH: | |
7938 | case BINOP_LOGICAL_AND: | |
7939 | case BINOP_LOGICAL_OR: | |
7940 | case BINOP_BITWISE_AND: | |
7941 | case BINOP_BITWISE_IOR: | |
7942 | case BINOP_BITWISE_XOR: | |
7943 | case BINOP_EQUAL: | |
7944 | case BINOP_NOTEQUAL: | |
7945 | case BINOP_LESS: | |
7946 | case BINOP_GTR: | |
7947 | case BINOP_LEQ: | |
7948 | case BINOP_GEQ: | |
7949 | case BINOP_REPEAT: | |
7950 | case BINOP_COMMA: | |
7951 | case BINOP_EXP: | |
7952 | case BINOP_MIN: | |
7953 | case BINOP_MAX: | |
7954 | case BINOP_INTDIV: | |
7955 | case BINOP_CONCAT: | |
7956 | case BINOP_IN: | |
7957 | case BINOP_RANGE: | |
7958 | case TERNOP_COND: | |
7959 | case TERNOP_SLICE: | |
7960 | case TERNOP_SLICE_COUNT: | |
7961 | ||
7962 | case OP_LONG: | |
7963 | case OP_DOUBLE: | |
7964 | case OP_DECFLOAT: | |
7965 | case OP_LAST: | |
7966 | case OP_COMPLEX: | |
7967 | case OP_STRING: | |
7968 | case OP_BITSTRING: | |
7969 | case OP_ARRAY: | |
7970 | case OP_TYPE: | |
7971 | case OP_NAME: | |
7972 | case OP_OBJC_NSSTRING: | |
7973 | ||
7974 | case UNOP_NEG: | |
7975 | case UNOP_LOGICAL_NOT: | |
7976 | case UNOP_COMPLEMENT: | |
7977 | case UNOP_ADDR: | |
7978 | case UNOP_HIGH: | |
7979 | /* Unary, binary and ternary operators: We have to check their | |
7980 | operands. If they are constant, then so is the result of | |
7981 | that operation. For instance, if A and B are determined to be | |
7982 | constants, then so is "A + B". | |
7983 | ||
7984 | UNOP_IND is one exception to the rule above, because the value | |
7985 | of *ADDR is not necessarily a constant, even when ADDR is. */ | |
7986 | break; | |
7987 | ||
7988 | case OP_VAR_VALUE: | |
7989 | /* Check whether the associated symbol is a constant. | |
7990 | We use SYMBOL_CLASS rather than TYPE_CONST because it's | |
7991 | possible that a buggy compiler could mark a variable as constant | |
7992 | even when it is not, and TYPE_CONST would return true in this | |
7993 | case, while SYMBOL_CLASS wouldn't. | |
7994 | We also have to check for function symbols because they are | |
7995 | always constant. */ | |
7996 | { | |
7997 | struct symbol *s = exp->elts[i + 2].symbol; | |
7998 | ||
7999 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8000 | && SYMBOL_CLASS (s) != LOC_CONST | |
8001 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8002 | return 0; | |
8003 | break; | |
8004 | } | |
8005 | ||
8006 | /* The default action is to return 0 because we are using | |
8007 | the optimistic approach here: If we don't know something, | |
8008 | then it is not a constant. */ | |
8009 | default: | |
8010 | return 0; | |
8011 | } | |
8012 | } | |
8013 | ||
8014 | return 1; | |
8015 | } | |
8016 | ||
53a5351d JM |
8017 | /* accessflag: hw_write: watch write, |
8018 | hw_read: watch read, | |
8019 | hw_access: watch access (read or write) */ | |
c906108c | 8020 | static void |
06a64a0b | 8021 | watch_command_1 (char *arg, int accessflag, int from_tty, int just_location) |
c906108c | 8022 | { |
d983da9c | 8023 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 8024 | struct expression *exp; |
60e1c644 | 8025 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
c906108c SS |
8026 | struct value *val, *mark; |
8027 | struct frame_info *frame; | |
c906108c SS |
8028 | char *exp_start = NULL; |
8029 | char *exp_end = NULL; | |
37e4754d | 8030 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
8031 | int toklen; |
8032 | char *cond_start = NULL; | |
8033 | char *cond_end = NULL; | |
c906108c SS |
8034 | int i, other_type_used, target_resources_ok = 0; |
8035 | enum bptype bp_type; | |
8036 | int mem_cnt = 0; | |
37e4754d | 8037 | int thread = -1; |
0cf6dd15 | 8038 | int pc = 0; |
c906108c | 8039 | |
37e4754d LM |
8040 | /* Make sure that we actually have parameters to parse. */ |
8041 | if (arg != NULL && arg[0] != '\0') | |
8042 | { | |
8043 | toklen = strlen (arg); /* Size of argument list. */ | |
8044 | ||
8045 | /* Points tok to the end of the argument list. */ | |
8046 | tok = arg + toklen - 1; | |
8047 | ||
8048 | /* Go backwards in the parameters list. Skip the last parameter. | |
8049 | If we're expecting a 'thread <thread_num>' parameter, this should | |
8050 | be the thread identifier. */ | |
8051 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
8052 | tok--; | |
8053 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8054 | tok--; | |
8055 | ||
8056 | /* Points end_tok to the beginning of the last token. */ | |
8057 | id_tok_start = tok + 1; | |
8058 | ||
8059 | /* Go backwards in the parameters list. Skip one more parameter. | |
8060 | If we're expecting a 'thread <thread_num>' parameter, we should | |
8061 | reach a "thread" token. */ | |
8062 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
8063 | tok--; | |
8064 | ||
8065 | end_tok = tok; | |
8066 | ||
8067 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
8068 | tok--; | |
8069 | ||
8070 | /* Move the pointer forward to skip the whitespace and | |
8071 | calculate the length of the token. */ | |
8072 | tok++; | |
8073 | toklen = end_tok - tok; | |
8074 | ||
8075 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
8076 | { | |
8077 | /* At this point we've found a "thread" token, which means | |
8078 | the user is trying to set a watchpoint that triggers | |
8079 | only in a specific thread. */ | |
8080 | char *endp; | |
8081 | ||
8082 | /* Extract the thread ID from the next token. */ | |
8083 | thread = strtol (id_tok_start, &endp, 0); | |
8084 | ||
8085 | /* Check if the user provided a valid numeric value for the | |
8086 | thread ID. */ | |
8087 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
8088 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
8089 | ||
8090 | /* Check if the thread actually exists. */ | |
8091 | if (!valid_thread_id (thread)) | |
8092 | error (_("Unknown thread %d."), thread); | |
8093 | ||
8094 | /* Truncate the string and get rid of the thread <thread_num> | |
8095 | parameter before the parameter list is parsed by the | |
8096 | evaluate_expression() function. */ | |
8097 | *tok = '\0'; | |
8098 | } | |
8099 | } | |
8100 | ||
8101 | /* Parse the rest of the arguments. */ | |
c906108c SS |
8102 | innermost_block = NULL; |
8103 | exp_start = arg; | |
8104 | exp = parse_exp_1 (&arg, 0, 0); | |
8105 | exp_end = arg; | |
fa8a61dc TT |
8106 | /* Remove trailing whitespace from the expression before saving it. |
8107 | This makes the eventual display of the expression string a bit | |
8108 | prettier. */ | |
8109 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
8110 | --exp_end; | |
8111 | ||
65d79d4b SDJ |
8112 | /* Checking if the expression is not constant. */ |
8113 | if (watchpoint_exp_is_const (exp)) | |
8114 | { | |
8115 | int len; | |
8116 | ||
8117 | len = exp_end - exp_start; | |
8118 | while (len > 0 && isspace (exp_start[len - 1])) | |
8119 | len--; | |
8120 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
8121 | } | |
8122 | ||
c906108c SS |
8123 | exp_valid_block = innermost_block; |
8124 | mark = value_mark (); | |
0cf6dd15 | 8125 | fetch_subexp_value (exp, &pc, &val, NULL, NULL); |
06a64a0b TT |
8126 | |
8127 | if (just_location) | |
8128 | { | |
8129 | exp_valid_block = NULL; | |
8130 | val = value_addr (val); | |
8131 | release_value (val); | |
8132 | value_free_to_mark (mark); | |
8133 | } | |
8134 | else if (val != NULL) | |
fa4727a6 | 8135 | release_value (val); |
c906108c SS |
8136 | |
8137 | tok = arg; | |
8138 | while (*tok == ' ' || *tok == '\t') | |
8139 | tok++; | |
8140 | end_tok = tok; | |
8141 | ||
8142 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
8143 | end_tok++; | |
8144 | ||
8145 | toklen = end_tok - tok; | |
8146 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
8147 | { | |
2d134ed3 PA |
8148 | struct expression *cond; |
8149 | ||
60e1c644 | 8150 | innermost_block = NULL; |
c906108c SS |
8151 | tok = cond_start = end_tok + 1; |
8152 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
8153 | |
8154 | /* The watchpoint expression may not be local, but the condition | |
8155 | may still be. E.g.: `watch global if local > 0'. */ | |
8156 | cond_exp_valid_block = innermost_block; | |
8157 | ||
2d134ed3 | 8158 | xfree (cond); |
c906108c SS |
8159 | cond_end = tok; |
8160 | } | |
8161 | if (*tok) | |
8a3fe4f8 | 8162 | error (_("Junk at end of command.")); |
c906108c | 8163 | |
53a5351d | 8164 | if (accessflag == hw_read) |
c5aa993b | 8165 | bp_type = bp_read_watchpoint; |
53a5351d | 8166 | else if (accessflag == hw_access) |
c5aa993b JM |
8167 | bp_type = bp_access_watchpoint; |
8168 | else | |
8169 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
8170 | |
8171 | mem_cnt = can_use_hardware_watchpoint (val); | |
8172 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 8173 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
8174 | if (mem_cnt != 0) |
8175 | { | |
8176 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 8177 | target_resources_ok = |
d92524f1 | 8178 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 8179 | other_type_used); |
c5aa993b | 8180 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8181 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 8182 | |
c5aa993b | 8183 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 8184 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 8185 | } |
c906108c | 8186 | |
4d28f7a8 KB |
8187 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
8188 | watchpoint could not be set. */ | |
8189 | if (!mem_cnt || target_resources_ok <= 0) | |
8190 | bp_type = bp_watchpoint; | |
8191 | ||
d983da9c | 8192 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
8193 | |
8194 | /* If the expression is "local", then set up a "watchpoint scope" | |
8195 | breakpoint at the point where we've left the scope of the watchpoint | |
8196 | expression. Create the scope breakpoint before the watchpoint, so | |
8197 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 8198 | if (exp_valid_block && frame) |
d983da9c | 8199 | { |
edb3359d DJ |
8200 | if (frame_id_p (frame_unwind_caller_id (frame))) |
8201 | { | |
8202 | scope_breakpoint | |
a6d9a66e UW |
8203 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
8204 | frame_unwind_caller_pc (frame), | |
edb3359d | 8205 | bp_watchpoint_scope); |
d983da9c | 8206 | |
edb3359d | 8207 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 8208 | |
edb3359d DJ |
8209 | /* Automatically delete the breakpoint when it hits. */ |
8210 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 8211 | |
edb3359d DJ |
8212 | /* Only break in the proper frame (help with recursion). */ |
8213 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 8214 | |
edb3359d | 8215 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
8216 | scope_breakpoint->loc->gdbarch |
8217 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
8218 | scope_breakpoint->loc->requested_address |
8219 | = frame_unwind_caller_pc (frame); | |
8220 | scope_breakpoint->loc->address | |
a6d9a66e UW |
8221 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
8222 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
8223 | scope_breakpoint->type); |
8224 | } | |
d983da9c DJ |
8225 | } |
8226 | ||
c906108c | 8227 | /* Now set up the breakpoint. */ |
2d134ed3 | 8228 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
8229 | set_breakpoint_count (breakpoint_count + 1); |
8230 | b->number = breakpoint_count; | |
37e4754d | 8231 | b->thread = thread; |
b5de0fa7 | 8232 | b->disposition = disp_donttouch; |
c906108c SS |
8233 | b->exp = exp; |
8234 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 8235 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
8236 | if (just_location) |
8237 | { | |
8238 | struct type *t = value_type (val); | |
8239 | CORE_ADDR addr = value_as_address (val); | |
8240 | char *name; | |
8241 | ||
8242 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
8243 | name = type_to_string (t); | |
8244 | ||
d63d0675 JK |
8245 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
8246 | core_addr_to_string (addr)); | |
06a64a0b TT |
8247 | xfree (name); |
8248 | ||
d63d0675 JK |
8249 | b->exp_string = xstrprintf ("-location: %.*s", |
8250 | (int) (exp_end - exp_start), exp_start); | |
8251 | ||
06a64a0b TT |
8252 | /* The above expression is in C. */ |
8253 | b->language = language_c; | |
8254 | } | |
8255 | else | |
8256 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
c906108c | 8257 | b->val = val; |
fa4727a6 | 8258 | b->val_valid = 1; |
c906108c SS |
8259 | if (cond_start) |
8260 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
8261 | else | |
8262 | b->cond_string = 0; | |
c5aa993b | 8263 | |
c906108c | 8264 | if (frame) |
f6bc2008 PA |
8265 | { |
8266 | b->watchpoint_frame = get_frame_id (frame); | |
8267 | b->watchpoint_thread = inferior_ptid; | |
8268 | } | |
c906108c | 8269 | else |
f6bc2008 PA |
8270 | { |
8271 | b->watchpoint_frame = null_frame_id; | |
8272 | b->watchpoint_thread = null_ptid; | |
8273 | } | |
c906108c | 8274 | |
d983da9c | 8275 | if (scope_breakpoint != NULL) |
c906108c | 8276 | { |
d983da9c DJ |
8277 | /* The scope breakpoint is related to the watchpoint. We will |
8278 | need to act on them together. */ | |
8279 | b->related_breakpoint = scope_breakpoint; | |
8280 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 8281 | } |
d983da9c | 8282 | |
06a64a0b TT |
8283 | if (!just_location) |
8284 | value_free_to_mark (mark); | |
2d134ed3 PA |
8285 | |
8286 | /* Finally update the new watchpoint. This creates the locations | |
8287 | that should be inserted. */ | |
8288 | update_watchpoint (b, 1); | |
8289 | ||
c906108c | 8290 | mention (b); |
b60e7edf | 8291 | update_global_location_list (1); |
c906108c SS |
8292 | } |
8293 | ||
8294 | /* Return count of locations need to be watched and can be handled | |
8295 | in hardware. If the watchpoint can not be handled | |
8296 | in hardware return zero. */ | |
8297 | ||
c906108c | 8298 | static int |
fba45db2 | 8299 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
8300 | { |
8301 | int found_memory_cnt = 0; | |
2e70b7b9 | 8302 | struct value *head = v; |
c906108c SS |
8303 | |
8304 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 8305 | if (!can_use_hw_watchpoints) |
c906108c | 8306 | return 0; |
c5aa993b | 8307 | |
5c44784c JM |
8308 | /* Make sure that the value of the expression depends only upon |
8309 | memory contents, and values computed from them within GDB. If we | |
8310 | find any register references or function calls, we can't use a | |
8311 | hardware watchpoint. | |
8312 | ||
8313 | The idea here is that evaluating an expression generates a series | |
8314 | of values, one holding the value of every subexpression. (The | |
8315 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
8316 | a*b+c.) GDB's values hold almost enough information to establish | |
8317 | the criteria given above --- they identify memory lvalues, | |
8318 | register lvalues, computed values, etcetera. So we can evaluate | |
8319 | the expression, and then scan the chain of values that leaves | |
8320 | behind to decide whether we can detect any possible change to the | |
8321 | expression's final value using only hardware watchpoints. | |
8322 | ||
8323 | However, I don't think that the values returned by inferior | |
8324 | function calls are special in any way. So this function may not | |
8325 | notice that an expression involving an inferior function call | |
8326 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 8327 | for (; v; v = value_next (v)) |
c906108c | 8328 | { |
5c44784c | 8329 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 8330 | { |
d69fe07e | 8331 | if (value_lazy (v)) |
5c44784c JM |
8332 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
8333 | we either just used its address (e.g., `a' in `a.b') or | |
8334 | we never needed it at all (e.g., `a' in `a,b'). */ | |
8335 | ; | |
53a5351d | 8336 | else |
5c44784c JM |
8337 | { |
8338 | /* Ahh, memory we actually used! Check if we can cover | |
8339 | it with hardware watchpoints. */ | |
df407dfe | 8340 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
8341 | |
8342 | /* We only watch structs and arrays if user asked for it | |
8343 | explicitly, never if they just happen to appear in a | |
8344 | middle of some value chain. */ | |
8345 | if (v == head | |
8346 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
8347 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
8348 | { | |
42ae5230 | 8349 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 8350 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 8351 | |
d92524f1 | 8352 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
8353 | return 0; |
8354 | else | |
8355 | found_memory_cnt++; | |
8356 | } | |
5c44784c | 8357 | } |
c5aa993b | 8358 | } |
5086187c AC |
8359 | else if (VALUE_LVAL (v) != not_lval |
8360 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 8361 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 8362 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 8363 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
8364 | } |
8365 | ||
8366 | /* The expression itself looks suitable for using a hardware | |
8367 | watchpoint, but give the target machine a chance to reject it. */ | |
8368 | return found_memory_cnt; | |
8369 | } | |
8370 | ||
8b93c638 | 8371 | void |
fba45db2 | 8372 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 | 8373 | { |
06a64a0b TT |
8374 | watch_command_1 (arg, hw_write, from_tty, 0); |
8375 | } | |
8376 | ||
8377 | /* A helper function that looks for an argument at the start of a | |
8378 | string. The argument must also either be at the end of the string, | |
8379 | or be followed by whitespace. Returns 1 if it finds the argument, | |
8380 | 0 otherwise. If the argument is found, it updates *STR. */ | |
8381 | ||
8382 | static int | |
8383 | check_for_argument (char **str, char *arg, int arg_len) | |
8384 | { | |
8385 | if (strncmp (*str, arg, arg_len) == 0 | |
8386 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
8387 | { | |
8388 | *str += arg_len; | |
8389 | return 1; | |
8390 | } | |
8391 | return 0; | |
8392 | } | |
8393 | ||
8394 | /* A helper function that looks for the "-location" argument and then | |
8395 | calls watch_command_1. */ | |
8396 | ||
8397 | static void | |
8398 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
8399 | { | |
8400 | int just_location = 0; | |
8401 | ||
8402 | if (arg | |
8403 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
8404 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
8405 | { | |
8406 | ep_skip_leading_whitespace (&arg); | |
8407 | just_location = 1; | |
8408 | } | |
8409 | ||
8410 | watch_command_1 (arg, accessflag, from_tty, just_location); | |
8b93c638 | 8411 | } |
8926118c | 8412 | |
c5aa993b | 8413 | static void |
fba45db2 | 8414 | watch_command (char *arg, int from_tty) |
c906108c | 8415 | { |
06a64a0b | 8416 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
8417 | } |
8418 | ||
8b93c638 | 8419 | void |
fba45db2 | 8420 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 | 8421 | { |
06a64a0b | 8422 | watch_command_1 (arg, hw_read, from_tty, 0); |
8b93c638 | 8423 | } |
8926118c | 8424 | |
c5aa993b | 8425 | static void |
fba45db2 | 8426 | rwatch_command (char *arg, int from_tty) |
c906108c | 8427 | { |
06a64a0b | 8428 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
8429 | } |
8430 | ||
8b93c638 | 8431 | void |
fba45db2 | 8432 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 | 8433 | { |
06a64a0b | 8434 | watch_command_1 (arg, hw_access, from_tty, 0); |
8b93c638 | 8435 | } |
8926118c | 8436 | |
c5aa993b | 8437 | static void |
fba45db2 | 8438 | awatch_command (char *arg, int from_tty) |
c906108c | 8439 | { |
06a64a0b | 8440 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 8441 | } |
c906108c | 8442 | \f |
c5aa993b | 8443 | |
43ff13b4 | 8444 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
8445 | because it uses the mechanisms of breakpoints. */ |
8446 | ||
bfec99b2 PA |
8447 | struct until_break_command_continuation_args |
8448 | { | |
8449 | struct breakpoint *breakpoint; | |
8450 | struct breakpoint *breakpoint2; | |
8451 | }; | |
8452 | ||
43ff13b4 JM |
8453 | /* This function is called by fetch_inferior_event via the |
8454 | cmd_continuation pointer, to complete the until command. It takes | |
8455 | care of cleaning up the temporary breakpoints set up by the until | |
8456 | command. */ | |
c2c6d25f | 8457 | static void |
604ead4a | 8458 | until_break_command_continuation (void *arg) |
43ff13b4 | 8459 | { |
bfec99b2 PA |
8460 | struct until_break_command_continuation_args *a = arg; |
8461 | ||
8462 | delete_breakpoint (a->breakpoint); | |
8463 | if (a->breakpoint2) | |
8464 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
8465 | } |
8466 | ||
c906108c | 8467 | void |
ae66c1fc | 8468 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
8469 | { |
8470 | struct symtabs_and_lines sals; | |
8471 | struct symtab_and_line sal; | |
206415a3 | 8472 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 8473 | struct breakpoint *breakpoint; |
f107f563 | 8474 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
8475 | struct cleanup *old_chain; |
8476 | ||
8477 | clear_proceed_status (); | |
8478 | ||
8479 | /* Set a breakpoint where the user wants it and at return from | |
8480 | this function */ | |
c5aa993b | 8481 | |
c906108c SS |
8482 | if (default_breakpoint_valid) |
8483 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 8484 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 8485 | else |
53a5351d | 8486 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 8487 | 0, (char ***) NULL, NULL); |
c5aa993b | 8488 | |
c906108c | 8489 | if (sals.nelts != 1) |
8a3fe4f8 | 8490 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 8491 | |
c906108c | 8492 | sal = sals.sals[0]; |
b8c9b27d | 8493 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 8494 | |
c906108c | 8495 | if (*arg) |
8a3fe4f8 | 8496 | error (_("Junk at end of arguments.")); |
c5aa993b | 8497 | |
c906108c | 8498 | resolve_sal_pc (&sal); |
c5aa993b | 8499 | |
ae66c1fc EZ |
8500 | if (anywhere) |
8501 | /* If the user told us to continue until a specified location, | |
8502 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
8503 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8504 | null_frame_id, bp_until); | |
ae66c1fc | 8505 | else |
edb3359d | 8506 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 8507 | at the very same frame. */ |
a6d9a66e UW |
8508 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
8509 | get_stack_frame_id (frame), | |
ae66c1fc | 8510 | bp_until); |
c5aa993b | 8511 | |
f107f563 | 8512 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 8513 | |
ae66c1fc EZ |
8514 | /* Keep within the current frame, or in frames called by the current |
8515 | one. */ | |
edb3359d DJ |
8516 | |
8517 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 8518 | { |
edb3359d DJ |
8519 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
8520 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
8521 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
8522 | sal, | |
edb3359d | 8523 | frame_unwind_caller_id (frame), |
f107f563 VP |
8524 | bp_until); |
8525 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 8526 | } |
c5aa993b | 8527 | |
c906108c | 8528 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
8529 | |
8530 | /* If we are running asynchronously, and proceed call above has actually | |
8531 | managed to start the target, arrange for breakpoints to be | |
8532 | deleted when the target stops. Otherwise, we're already stopped and | |
8533 | delete breakpoints via cleanup chain. */ | |
8534 | ||
8ea051c5 | 8535 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 8536 | { |
bfec99b2 PA |
8537 | struct until_break_command_continuation_args *args; |
8538 | args = xmalloc (sizeof (*args)); | |
f107f563 | 8539 | |
bfec99b2 PA |
8540 | args->breakpoint = breakpoint; |
8541 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
8542 | |
8543 | discard_cleanups (old_chain); | |
95e54da7 PA |
8544 | add_continuation (inferior_thread (), |
8545 | until_break_command_continuation, args, | |
604ead4a | 8546 | xfree); |
f107f563 VP |
8547 | } |
8548 | else | |
c5aa993b | 8549 | do_cleanups (old_chain); |
c906108c | 8550 | } |
ae66c1fc | 8551 | |
c906108c | 8552 | static void |
fba45db2 | 8553 | ep_skip_leading_whitespace (char **s) |
c906108c | 8554 | { |
c5aa993b JM |
8555 | if ((s == NULL) || (*s == NULL)) |
8556 | return; | |
8557 | while (isspace (**s)) | |
8558 | *s += 1; | |
c906108c | 8559 | } |
c5aa993b | 8560 | |
c906108c SS |
8561 | /* This function attempts to parse an optional "if <cond>" clause |
8562 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 8563 | |
c906108c SS |
8564 | Else, it returns a pointer to the condition string. (It does not |
8565 | attempt to evaluate the string against a particular block.) And, | |
8566 | it updates arg to point to the first character following the parsed | |
8567 | if clause in the arg string. */ | |
53a5351d | 8568 | |
c906108c | 8569 | static char * |
fba45db2 | 8570 | ep_parse_optional_if_clause (char **arg) |
c906108c | 8571 | { |
c5aa993b JM |
8572 | char *cond_string; |
8573 | ||
8574 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 8575 | return NULL; |
c5aa993b | 8576 | |
c906108c SS |
8577 | /* Skip the "if" keyword. */ |
8578 | (*arg) += 2; | |
c5aa993b | 8579 | |
c906108c SS |
8580 | /* Skip any extra leading whitespace, and record the start of the |
8581 | condition string. */ | |
8582 | ep_skip_leading_whitespace (arg); | |
8583 | cond_string = *arg; | |
c5aa993b | 8584 | |
c906108c SS |
8585 | /* Assume that the condition occupies the remainder of the arg string. */ |
8586 | (*arg) += strlen (cond_string); | |
c5aa993b | 8587 | |
c906108c SS |
8588 | return cond_string; |
8589 | } | |
c5aa993b | 8590 | |
c906108c SS |
8591 | /* Commands to deal with catching events, such as signals, exceptions, |
8592 | process start/exit, etc. */ | |
c5aa993b JM |
8593 | |
8594 | typedef enum | |
8595 | { | |
44feb3ce TT |
8596 | catch_fork_temporary, catch_vfork_temporary, |
8597 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
8598 | } |
8599 | catch_fork_kind; | |
8600 | ||
c906108c | 8601 | static void |
cc59ec59 MS |
8602 | catch_fork_command_1 (char *arg, int from_tty, |
8603 | struct cmd_list_element *command) | |
c906108c | 8604 | { |
a6d9a66e | 8605 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 8606 | char *cond_string = NULL; |
44feb3ce TT |
8607 | catch_fork_kind fork_kind; |
8608 | int tempflag; | |
8609 | ||
8610 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
8611 | tempflag = (fork_kind == catch_fork_temporary | |
8612 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 8613 | |
44feb3ce TT |
8614 | if (!arg) |
8615 | arg = ""; | |
c906108c | 8616 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8617 | |
c906108c | 8618 | /* The allowed syntax is: |
c5aa993b JM |
8619 | catch [v]fork |
8620 | catch [v]fork if <cond> | |
8621 | ||
c906108c SS |
8622 | First, check if there's an if clause. */ |
8623 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 8624 | |
c906108c | 8625 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 8626 | error (_("Junk at end of arguments.")); |
c5aa993b | 8627 | |
c906108c SS |
8628 | /* If this target supports it, create a fork or vfork catchpoint |
8629 | and enable reporting of such events. */ | |
c5aa993b JM |
8630 | switch (fork_kind) |
8631 | { | |
44feb3ce TT |
8632 | case catch_fork_temporary: |
8633 | case catch_fork_permanent: | |
a6d9a66e | 8634 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8635 | &catch_fork_breakpoint_ops); |
c906108c | 8636 | break; |
44feb3ce TT |
8637 | case catch_vfork_temporary: |
8638 | case catch_vfork_permanent: | |
a6d9a66e | 8639 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 8640 | &catch_vfork_breakpoint_ops); |
c906108c | 8641 | break; |
c5aa993b | 8642 | default: |
8a3fe4f8 | 8643 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 8644 | break; |
c5aa993b | 8645 | } |
c906108c SS |
8646 | } |
8647 | ||
8648 | static void | |
cc59ec59 MS |
8649 | catch_exec_command_1 (char *arg, int from_tty, |
8650 | struct cmd_list_element *command) | |
c906108c | 8651 | { |
a6d9a66e | 8652 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8653 | int tempflag; |
c5aa993b | 8654 | char *cond_string = NULL; |
c906108c | 8655 | |
44feb3ce TT |
8656 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8657 | ||
8658 | if (!arg) | |
8659 | arg = ""; | |
c906108c SS |
8660 | ep_skip_leading_whitespace (&arg); |
8661 | ||
8662 | /* The allowed syntax is: | |
c5aa993b JM |
8663 | catch exec |
8664 | catch exec if <cond> | |
c906108c SS |
8665 | |
8666 | First, check if there's an if clause. */ | |
8667 | cond_string = ep_parse_optional_if_clause (&arg); | |
8668 | ||
8669 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8670 | error (_("Junk at end of arguments.")); |
c906108c SS |
8671 | |
8672 | /* If this target supports it, create an exec catchpoint | |
8673 | and enable reporting of such events. */ | |
a6d9a66e UW |
8674 | create_catchpoint (gdbarch, tempflag, cond_string, |
8675 | &catch_exec_breakpoint_ops); | |
c906108c | 8676 | } |
c5aa993b | 8677 | |
3086aeae DJ |
8678 | static enum print_stop_action |
8679 | print_exception_catchpoint (struct breakpoint *b) | |
8680 | { | |
ade92717 | 8681 | int bp_temp, bp_throw; |
3086aeae | 8682 | |
ade92717 | 8683 | annotate_catchpoint (b->number); |
3086aeae | 8684 | |
ade92717 AR |
8685 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8686 | if (b->loc->address != b->loc->requested_address) | |
8687 | breakpoint_adjustment_warning (b->loc->requested_address, | |
8688 | b->loc->address, | |
8689 | b->number, 1); | |
df2b6d2d | 8690 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8691 | ui_out_text (uiout, |
8692 | bp_temp ? "Temporary catchpoint " | |
8693 | : "Catchpoint "); | |
8694 | if (!ui_out_is_mi_like_p (uiout)) | |
8695 | ui_out_field_int (uiout, "bkptno", b->number); | |
8696 | ui_out_text (uiout, | |
c0b37c48 AR |
8697 | bp_throw ? " (exception thrown), " |
8698 | : " (exception caught), "); | |
ade92717 AR |
8699 | if (ui_out_is_mi_like_p (uiout)) |
8700 | { | |
8701 | ui_out_field_string (uiout, "reason", | |
8702 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8703 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8704 | ui_out_field_int (uiout, "bkptno", b->number); | |
8705 | } | |
3086aeae DJ |
8706 | return PRINT_SRC_AND_LOC; |
8707 | } | |
8708 | ||
8709 | static void | |
cc59ec59 MS |
8710 | print_one_exception_catchpoint (struct breakpoint *b, |
8711 | struct bp_location **last_loc) | |
3086aeae | 8712 | { |
79a45b7d | 8713 | struct value_print_options opts; |
cc59ec59 | 8714 | |
79a45b7d TT |
8715 | get_user_print_options (&opts); |
8716 | if (opts.addressprint) | |
3086aeae DJ |
8717 | { |
8718 | annotate_field (4); | |
604133b5 AR |
8719 | if (b->loc == NULL || b->loc->shlib_disabled) |
8720 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
8721 | else | |
5af949e3 UW |
8722 | ui_out_field_core_addr (uiout, "addr", |
8723 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
8724 | } |
8725 | annotate_field (5); | |
604133b5 | 8726 | if (b->loc) |
a6d9a66e | 8727 | *last_loc = b->loc; |
3086aeae DJ |
8728 | if (strstr (b->addr_string, "throw") != NULL) |
8729 | ui_out_field_string (uiout, "what", "exception throw"); | |
8730 | else | |
8731 | ui_out_field_string (uiout, "what", "exception catch"); | |
8732 | } | |
8733 | ||
8734 | static void | |
8735 | print_mention_exception_catchpoint (struct breakpoint *b) | |
8736 | { | |
ade92717 AR |
8737 | int bp_temp; |
8738 | int bp_throw; | |
8739 | ||
df2b6d2d | 8740 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
8741 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
8742 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
8743 | : _("Catchpoint ")); | |
8744 | ui_out_field_int (uiout, "bkptno", b->number); | |
8745 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
8746 | : _(" (catch)")); | |
3086aeae DJ |
8747 | } |
8748 | ||
6149aea9 PA |
8749 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
8750 | catch catchpoints. */ | |
8751 | ||
8752 | static void | |
8753 | print_recreate_exception_catchpoint (struct breakpoint *b, struct ui_file *fp) | |
8754 | { | |
8755 | int bp_temp; | |
8756 | int bp_throw; | |
8757 | ||
8758 | bp_temp = b->disposition == disp_del; | |
8759 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
8760 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
8761 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
8762 | } | |
8763 | ||
3086aeae | 8764 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
8765 | NULL, /* insert */ |
8766 | NULL, /* remove */ | |
8767 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
8768 | print_exception_catchpoint, |
8769 | print_one_exception_catchpoint, | |
6149aea9 PA |
8770 | print_mention_exception_catchpoint, |
8771 | print_recreate_exception_catchpoint | |
3086aeae DJ |
8772 | }; |
8773 | ||
8774 | static int | |
8775 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
8776 | enum exception_event_kind ex_event, int from_tty) | |
8777 | { | |
604133b5 AR |
8778 | char *trigger_func_name; |
8779 | ||
3086aeae | 8780 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 8781 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 8782 | else |
604133b5 | 8783 | trigger_func_name = "__cxa_throw"; |
3086aeae | 8784 | |
8cdf0e15 VP |
8785 | create_breakpoint (get_current_arch (), |
8786 | trigger_func_name, cond_string, -1, | |
8787 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 8788 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
8789 | 0, |
8790 | AUTO_BOOLEAN_TRUE /* pending */, | |
8791 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
8792 | 1 /* enabled */); | |
3086aeae | 8793 | |
3086aeae DJ |
8794 | return 1; |
8795 | } | |
8796 | ||
c5aa993b | 8797 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
8798 | |
8799 | static void | |
fba45db2 KB |
8800 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
8801 | int tempflag, int from_tty) | |
c906108c | 8802 | { |
c5aa993b | 8803 | char *cond_string = NULL; |
c5aa993b | 8804 | |
44feb3ce TT |
8805 | if (!arg) |
8806 | arg = ""; | |
c906108c | 8807 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 8808 | |
c906108c SS |
8809 | cond_string = ep_parse_optional_if_clause (&arg); |
8810 | ||
8811 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 8812 | error (_("Junk at end of arguments.")); |
c906108c | 8813 | |
059fb39f PM |
8814 | if (ex_event != EX_EVENT_THROW |
8815 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 8816 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 8817 | |
3086aeae DJ |
8818 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
8819 | return; | |
8820 | ||
8a3fe4f8 | 8821 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
8822 | } |
8823 | ||
44feb3ce TT |
8824 | /* Implementation of "catch catch" command. */ |
8825 | ||
8826 | static void | |
8827 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8828 | { | |
8829 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 8830 | |
44feb3ce TT |
8831 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
8832 | } | |
8833 | ||
8834 | /* Implementation of "catch throw" command. */ | |
8835 | ||
8836 | static void | |
8837 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8838 | { | |
8839 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 8840 | |
44feb3ce TT |
8841 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
8842 | } | |
8843 | ||
f7f9143b JB |
8844 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
8845 | ||
8846 | static void | |
a6d9a66e UW |
8847 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
8848 | struct symtab_and_line sal, | |
f7f9143b JB |
8849 | char *addr_string, |
8850 | char *exp_string, | |
8851 | char *cond_string, | |
8852 | struct expression *cond, | |
8853 | struct breakpoint_ops *ops, | |
8854 | int tempflag, | |
8855 | int from_tty) | |
8856 | { | |
8857 | struct breakpoint *b; | |
8858 | ||
8859 | if (from_tty) | |
8860 | { | |
5af949e3 UW |
8861 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
8862 | if (!loc_gdbarch) | |
8863 | loc_gdbarch = gdbarch; | |
8864 | ||
6c95b8df PA |
8865 | describe_other_breakpoints (loc_gdbarch, |
8866 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
8867 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
8868 | version for exception catchpoints, because two catchpoints | |
8869 | used for different exception names will use the same address. | |
8870 | In this case, a "breakpoint ... also set at..." warning is | |
8871 | unproductive. Besides. the warning phrasing is also a bit | |
8872 | inapropriate, we should use the word catchpoint, and tell | |
8873 | the user what type of catchpoint it is. The above is good | |
8874 | enough for now, though. */ | |
8875 | } | |
8876 | ||
a6d9a66e | 8877 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
8878 | set_breakpoint_count (breakpoint_count + 1); |
8879 | ||
8880 | b->enable_state = bp_enabled; | |
8881 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
8882 | b->number = breakpoint_count; | |
8883 | b->ignore_count = 0; | |
511a6cd4 | 8884 | b->loc->cond = cond; |
f7f9143b JB |
8885 | b->addr_string = addr_string; |
8886 | b->language = language_ada; | |
8887 | b->cond_string = cond_string; | |
8888 | b->exp_string = exp_string; | |
8889 | b->thread = -1; | |
8890 | b->ops = ops; | |
f7f9143b JB |
8891 | |
8892 | mention (b); | |
b60e7edf | 8893 | update_global_location_list (1); |
f7f9143b JB |
8894 | } |
8895 | ||
8896 | /* Implement the "catch exception" command. */ | |
8897 | ||
8898 | static void | |
44feb3ce TT |
8899 | catch_ada_exception_command (char *arg, int from_tty, |
8900 | struct cmd_list_element *command) | |
f7f9143b | 8901 | { |
a6d9a66e | 8902 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8903 | int tempflag; |
f7f9143b | 8904 | struct symtab_and_line sal; |
f7f9143b JB |
8905 | char *addr_string = NULL; |
8906 | char *exp_string = NULL; | |
8907 | char *cond_string = NULL; | |
8908 | struct expression *cond = NULL; | |
8909 | struct breakpoint_ops *ops = NULL; | |
8910 | ||
44feb3ce TT |
8911 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8912 | ||
8913 | if (!arg) | |
8914 | arg = ""; | |
f7f9143b JB |
8915 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
8916 | &cond_string, &cond, &ops); | |
a6d9a66e | 8917 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
8918 | cond_string, cond, ops, tempflag, |
8919 | from_tty); | |
8920 | } | |
8921 | ||
a96d9b2e SDJ |
8922 | /* Cleanup function for a syscall filter list. */ |
8923 | static void | |
8924 | clean_up_filters (void *arg) | |
8925 | { | |
8926 | VEC(int) *iter = *(VEC(int) **) arg; | |
8927 | VEC_free (int, iter); | |
8928 | } | |
8929 | ||
8930 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
8931 | filter list, or NULL if no filtering is required. */ | |
8932 | static VEC(int) * | |
8933 | catch_syscall_split_args (char *arg) | |
8934 | { | |
8935 | VEC(int) *result = NULL; | |
8936 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
8937 | ||
8938 | while (*arg != '\0') | |
8939 | { | |
8940 | int i, syscall_number; | |
8941 | char *endptr; | |
8942 | char cur_name[128]; | |
8943 | struct syscall s; | |
8944 | ||
8945 | /* Skip whitespace. */ | |
8946 | while (isspace (*arg)) | |
8947 | arg++; | |
8948 | ||
8949 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
8950 | cur_name[i] = arg[i]; | |
8951 | cur_name[i] = '\0'; | |
8952 | arg += i; | |
8953 | ||
8954 | /* Check if the user provided a syscall name or a number. */ | |
8955 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
8956 | if (*endptr == '\0') | |
bccd0dd2 | 8957 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
8958 | else |
8959 | { | |
8960 | /* We have a name. Let's check if it's valid and convert it | |
8961 | to a number. */ | |
8962 | get_syscall_by_name (cur_name, &s); | |
8963 | ||
8964 | if (s.number == UNKNOWN_SYSCALL) | |
8965 | /* Here we have to issue an error instead of a warning, because | |
8966 | GDB cannot do anything useful if there's no syscall number to | |
8967 | be caught. */ | |
8968 | error (_("Unknown syscall name '%s'."), cur_name); | |
8969 | } | |
8970 | ||
8971 | /* Ok, it's valid. */ | |
8972 | VEC_safe_push (int, result, s.number); | |
8973 | } | |
8974 | ||
8975 | discard_cleanups (cleanup); | |
8976 | return result; | |
8977 | } | |
8978 | ||
8979 | /* Implement the "catch syscall" command. */ | |
8980 | ||
8981 | static void | |
cc59ec59 MS |
8982 | catch_syscall_command_1 (char *arg, int from_tty, |
8983 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
8984 | { |
8985 | int tempflag; | |
8986 | VEC(int) *filter; | |
8987 | struct syscall s; | |
8988 | struct gdbarch *gdbarch = get_current_arch (); | |
8989 | ||
8990 | /* Checking if the feature if supported. */ | |
8991 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8992 | error (_("The feature 'catch syscall' is not supported on \ | |
8993 | this architeture yet.")); | |
8994 | ||
8995 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8996 | ||
8997 | ep_skip_leading_whitespace (&arg); | |
8998 | ||
8999 | /* We need to do this first "dummy" translation in order | |
9000 | to get the syscall XML file loaded or, most important, | |
9001 | to display a warning to the user if there's no XML file | |
9002 | for his/her architecture. */ | |
9003 | get_syscall_by_number (0, &s); | |
9004 | ||
9005 | /* The allowed syntax is: | |
9006 | catch syscall | |
9007 | catch syscall <name | number> [<name | number> ... <name | number>] | |
9008 | ||
9009 | Let's check if there's a syscall name. */ | |
9010 | ||
9011 | if (arg != NULL) | |
9012 | filter = catch_syscall_split_args (arg); | |
9013 | else | |
9014 | filter = NULL; | |
9015 | ||
9016 | create_syscall_event_catchpoint (tempflag, filter, | |
9017 | &catch_syscall_breakpoint_ops); | |
9018 | } | |
9019 | ||
f7f9143b JB |
9020 | /* Implement the "catch assert" command. */ |
9021 | ||
9022 | static void | |
44feb3ce | 9023 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 9024 | { |
a6d9a66e | 9025 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9026 | int tempflag; |
f7f9143b JB |
9027 | struct symtab_and_line sal; |
9028 | char *addr_string = NULL; | |
9029 | struct breakpoint_ops *ops = NULL; | |
9030 | ||
44feb3ce TT |
9031 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9032 | ||
9033 | if (!arg) | |
9034 | arg = ""; | |
f7f9143b | 9035 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
9036 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
9037 | ops, tempflag, from_tty); | |
f7f9143b JB |
9038 | } |
9039 | ||
c906108c | 9040 | static void |
fba45db2 | 9041 | catch_command (char *arg, int from_tty) |
c906108c | 9042 | { |
44feb3ce | 9043 | error (_("Catch requires an event name.")); |
c906108c SS |
9044 | } |
9045 | \f | |
9046 | ||
9047 | static void | |
fba45db2 | 9048 | tcatch_command (char *arg, int from_tty) |
c906108c | 9049 | { |
44feb3ce | 9050 | error (_("Catch requires an event name.")); |
c906108c SS |
9051 | } |
9052 | ||
80f8a6eb | 9053 | /* Delete breakpoints by address or line. */ |
c906108c SS |
9054 | |
9055 | static void | |
fba45db2 | 9056 | clear_command (char *arg, int from_tty) |
c906108c | 9057 | { |
d6e956e5 VP |
9058 | struct breakpoint *b; |
9059 | VEC(breakpoint_p) *found = 0; | |
9060 | int ix; | |
c906108c SS |
9061 | int default_match; |
9062 | struct symtabs_and_lines sals; | |
9063 | struct symtab_and_line sal; | |
c906108c SS |
9064 | int i; |
9065 | ||
9066 | if (arg) | |
9067 | { | |
9068 | sals = decode_line_spec (arg, 1); | |
9069 | default_match = 0; | |
9070 | } | |
9071 | else | |
9072 | { | |
c5aa993b | 9073 | sals.sals = (struct symtab_and_line *) |
c906108c | 9074 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 9075 | make_cleanup (xfree, sals.sals); |
fe39c653 | 9076 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
9077 | sal.line = default_breakpoint_line; |
9078 | sal.symtab = default_breakpoint_symtab; | |
9079 | sal.pc = default_breakpoint_address; | |
6c95b8df | 9080 | sal.pspace = default_breakpoint_pspace; |
c906108c | 9081 | if (sal.symtab == 0) |
8a3fe4f8 | 9082 | error (_("No source file specified.")); |
c906108c SS |
9083 | |
9084 | sals.sals[0] = sal; | |
9085 | sals.nelts = 1; | |
9086 | ||
9087 | default_match = 1; | |
9088 | } | |
9089 | ||
ed0616c6 VP |
9090 | /* We don't call resolve_sal_pc here. That's not |
9091 | as bad as it seems, because all existing breakpoints | |
9092 | typically have both file/line and pc set. So, if | |
9093 | clear is given file/line, we can match this to existing | |
9094 | breakpoint without obtaining pc at all. | |
9095 | ||
9096 | We only support clearing given the address explicitly | |
9097 | present in breakpoint table. Say, we've set breakpoint | |
9098 | at file:line. There were several PC values for that file:line, | |
9099 | due to optimization, all in one block. | |
9100 | We've picked one PC value. If "clear" is issued with another | |
9101 | PC corresponding to the same file:line, the breakpoint won't | |
9102 | be cleared. We probably can still clear the breakpoint, but | |
9103 | since the other PC value is never presented to user, user | |
9104 | can only find it by guessing, and it does not seem important | |
9105 | to support that. */ | |
9106 | ||
c906108c | 9107 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
9108 | to it. Do it in two passes, solely to preserve the current |
9109 | behavior that from_tty is forced true if we delete more than | |
9110 | one breakpoint. */ | |
c906108c | 9111 | |
80f8a6eb | 9112 | found = NULL; |
c906108c SS |
9113 | for (i = 0; i < sals.nelts; i++) |
9114 | { | |
9115 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
9116 | If line given (pc == 0), clear all bpts on specified line. |
9117 | If defaulting, clear all bpts on default line | |
c906108c | 9118 | or at default pc. |
c5aa993b JM |
9119 | |
9120 | defaulting sal.pc != 0 tests to do | |
9121 | ||
9122 | 0 1 pc | |
9123 | 1 1 pc _and_ line | |
9124 | 0 0 line | |
9125 | 1 0 <can't happen> */ | |
c906108c SS |
9126 | |
9127 | sal = sals.sals[i]; | |
c906108c | 9128 | |
d6e956e5 VP |
9129 | /* Find all matching breakpoints and add them to |
9130 | 'found'. */ | |
9131 | ALL_BREAKPOINTS (b) | |
c5aa993b | 9132 | { |
0d381245 | 9133 | int match = 0; |
80f8a6eb | 9134 | /* Are we going to delete b? */ |
cc60f2e3 | 9135 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
9136 | { |
9137 | struct bp_location *loc = b->loc; | |
9138 | for (; loc; loc = loc->next) | |
9139 | { | |
6c95b8df PA |
9140 | int pc_match = sal.pc |
9141 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
9142 | && (loc->address == sal.pc) |
9143 | && (!section_is_overlay (loc->section) | |
9144 | || loc->section == sal.section); | |
9145 | int line_match = ((default_match || (0 == sal.pc)) | |
9146 | && b->source_file != NULL | |
9147 | && sal.symtab != NULL | |
6c95b8df | 9148 | && sal.pspace == loc->pspace |
0d381245 VP |
9149 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
9150 | && b->line_number == sal.line); | |
9151 | if (pc_match || line_match) | |
9152 | { | |
9153 | match = 1; | |
9154 | break; | |
9155 | } | |
9156 | } | |
9157 | } | |
9158 | ||
9159 | if (match) | |
d6e956e5 | 9160 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 9161 | } |
80f8a6eb MS |
9162 | } |
9163 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 9164 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
9165 | { |
9166 | if (arg) | |
8a3fe4f8 | 9167 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 9168 | else |
8a3fe4f8 | 9169 | error (_("No breakpoint at this line.")); |
80f8a6eb | 9170 | } |
c906108c | 9171 | |
d6e956e5 | 9172 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
9173 | from_tty = 1; /* Always report if deleted more than one */ |
9174 | if (from_tty) | |
a3f17187 | 9175 | { |
d6e956e5 | 9176 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
9177 | printf_unfiltered (_("Deleted breakpoint ")); |
9178 | else | |
9179 | printf_unfiltered (_("Deleted breakpoints ")); | |
9180 | } | |
80f8a6eb | 9181 | breakpoints_changed (); |
d6e956e5 VP |
9182 | |
9183 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 9184 | { |
c5aa993b | 9185 | if (from_tty) |
d6e956e5 VP |
9186 | printf_unfiltered ("%d ", b->number); |
9187 | delete_breakpoint (b); | |
c906108c | 9188 | } |
80f8a6eb MS |
9189 | if (from_tty) |
9190 | putchar_unfiltered ('\n'); | |
c906108c SS |
9191 | } |
9192 | \f | |
9193 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
9194 | all breakpoints that are marked for deletion, whether hit or not. | |
9195 | This is called after any breakpoint is hit, or after errors. */ | |
9196 | ||
9197 | void | |
fba45db2 | 9198 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
9199 | { |
9200 | struct breakpoint *b, *temp; | |
9201 | ||
9202 | for (; bs; bs = bs->next) | |
f431efe5 PA |
9203 | if (bs->breakpoint_at |
9204 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 9205 | && bs->stop) |
f431efe5 | 9206 | delete_breakpoint (bs->breakpoint_at); |
c906108c SS |
9207 | |
9208 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 9209 | { |
b5de0fa7 | 9210 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
9211 | delete_breakpoint (b); |
9212 | } | |
c906108c SS |
9213 | } |
9214 | ||
494cfb0f | 9215 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
9216 | Sort elements primarily by their ADDRESS (no matter what does |
9217 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
9218 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
9219 | is sorted stable way despite qsort being an instable algorithm. */ | |
9220 | ||
9221 | static int | |
494cfb0f | 9222 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 9223 | { |
494cfb0f JK |
9224 | struct bp_location *a = *(void **) ap; |
9225 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 9226 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
9227 | int a_perm = a->owner->enable_state == bp_permanent; |
9228 | int b_perm = b->owner->enable_state == bp_permanent; | |
9229 | ||
9230 | if (a->address != b->address) | |
9231 | return (a->address > b->address) - (a->address < b->address); | |
9232 | ||
9233 | /* Sort permanent breakpoints first. */ | |
9234 | if (a_perm != b_perm) | |
9235 | return (a_perm < b_perm) - (a_perm > b_perm); | |
9236 | ||
9237 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
9238 | breakpoint can be sorted in arbitrary order. */ | |
9239 | ||
9240 | if (a->owner->number != b->owner->number) | |
9241 | return (a->owner->number > b->owner->number) | |
9242 | - (a->owner->number < b->owner->number); | |
9243 | ||
9244 | return (a > b) - (a < b); | |
9245 | } | |
9246 | ||
876fa593 JK |
9247 | /* Set bp_location_placed_address_before_address_max and |
9248 | bp_location_shadow_len_after_address_max according to the current content of | |
9249 | the bp_location array. */ | |
f7545552 TT |
9250 | |
9251 | static void | |
876fa593 | 9252 | bp_location_target_extensions_update (void) |
f7545552 | 9253 | { |
876fa593 JK |
9254 | struct bp_location *bl, **blp_tmp; |
9255 | ||
9256 | bp_location_placed_address_before_address_max = 0; | |
9257 | bp_location_shadow_len_after_address_max = 0; | |
9258 | ||
9259 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
9260 | { | |
9261 | CORE_ADDR start, end, addr; | |
9262 | ||
9263 | if (!bp_location_has_shadow (bl)) | |
9264 | continue; | |
9265 | ||
9266 | start = bl->target_info.placed_address; | |
9267 | end = start + bl->target_info.shadow_len; | |
9268 | ||
9269 | gdb_assert (bl->address >= start); | |
9270 | addr = bl->address - start; | |
9271 | if (addr > bp_location_placed_address_before_address_max) | |
9272 | bp_location_placed_address_before_address_max = addr; | |
9273 | ||
9274 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
9275 | ||
9276 | gdb_assert (bl->address < end); | |
9277 | addr = end - bl->address; | |
9278 | if (addr > bp_location_shadow_len_after_address_max) | |
9279 | bp_location_shadow_len_after_address_max = addr; | |
9280 | } | |
f7545552 TT |
9281 | } |
9282 | ||
4cd9bd08 | 9283 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
9284 | into the inferior, only remove already-inserted locations that no |
9285 | longer should be inserted. Functions that delete a breakpoint or | |
9286 | breakpoints should pass false, so that deleting a breakpoint | |
9287 | doesn't have the side effect of inserting the locations of other | |
9288 | breakpoints that are marked not-inserted, but should_be_inserted | |
9289 | returns true on them. | |
9290 | ||
9291 | This behaviour is useful is situations close to tear-down -- e.g., | |
9292 | after an exec, while the target still has execution, but breakpoint | |
9293 | shadows of the previous executable image should *NOT* be restored | |
9294 | to the new image; or before detaching, where the target still has | |
9295 | execution and wants to delete breakpoints from GDB's lists, and all | |
9296 | breakpoints had already been removed from the inferior. */ | |
9297 | ||
0d381245 | 9298 | static void |
b60e7edf | 9299 | update_global_location_list (int should_insert) |
0d381245 | 9300 | { |
74960c60 | 9301 | struct breakpoint *b; |
876fa593 | 9302 | struct bp_location **locp, *loc; |
f7545552 TT |
9303 | struct cleanup *cleanups; |
9304 | ||
2d134ed3 PA |
9305 | /* Used in the duplicates detection below. When iterating over all |
9306 | bp_locations, points to the first bp_location of a given address. | |
9307 | Breakpoints and watchpoints of different types are never | |
9308 | duplicates of each other. Keep one pointer for each type of | |
9309 | breakpoint/watchpoint, so we only need to loop over all locations | |
9310 | once. */ | |
9311 | struct bp_location *bp_loc_first; /* breakpoint */ | |
9312 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
9313 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
9314 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
9315 | |
9316 | /* Saved former bp_location array which we compare against the newly built | |
9317 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
9318 | struct bp_location **old_location, **old_locp; | |
9319 | unsigned old_location_count; | |
9320 | ||
9321 | old_location = bp_location; | |
9322 | old_location_count = bp_location_count; | |
9323 | bp_location = NULL; | |
9324 | bp_location_count = 0; | |
9325 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 9326 | |
74960c60 | 9327 | ALL_BREAKPOINTS (b) |
876fa593 JK |
9328 | for (loc = b->loc; loc; loc = loc->next) |
9329 | bp_location_count++; | |
9330 | ||
9331 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
9332 | locp = bp_location; | |
9333 | ALL_BREAKPOINTS (b) | |
9334 | for (loc = b->loc; loc; loc = loc->next) | |
9335 | *locp++ = loc; | |
9336 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 9337 | bp_location_compare); |
876fa593 JK |
9338 | |
9339 | bp_location_target_extensions_update (); | |
74960c60 VP |
9340 | |
9341 | /* Identify bp_location instances that are no longer present in the new | |
9342 | list, and therefore should be freed. Note that it's not necessary that | |
9343 | those locations should be removed from inferior -- if there's another | |
9344 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
9345 | we don't need to remove/insert the location. |
9346 | ||
9347 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
9348 | former bp_location array state respectively. */ | |
9349 | ||
9350 | locp = bp_location; | |
9351 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
9352 | old_locp++) | |
74960c60 | 9353 | { |
876fa593 | 9354 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 9355 | struct bp_location **loc2p; |
876fa593 JK |
9356 | |
9357 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 9358 | have to free it. */ |
c7d46a38 | 9359 | int found_object = 0; |
20874c92 VP |
9360 | /* Tells if the location should remain inserted in the target. */ |
9361 | int keep_in_target = 0; | |
9362 | int removed = 0; | |
876fa593 JK |
9363 | |
9364 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
9365 | at or being the one matching OLD_LOC. */ | |
9366 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 9367 | && (*locp)->address < old_loc->address) |
876fa593 | 9368 | locp++; |
c7d46a38 PA |
9369 | |
9370 | for (loc2p = locp; | |
9371 | (loc2p < bp_location + bp_location_count | |
9372 | && (*loc2p)->address == old_loc->address); | |
9373 | loc2p++) | |
9374 | { | |
9375 | if (*loc2p == old_loc) | |
9376 | { | |
9377 | found_object = 1; | |
9378 | break; | |
9379 | } | |
9380 | } | |
74960c60 VP |
9381 | |
9382 | /* If this location is no longer present, and inserted, look if there's | |
9383 | maybe a new location at the same address. If so, mark that one | |
9384 | inserted, and don't remove this one. This is needed so that we | |
9385 | don't have a time window where a breakpoint at certain location is not | |
9386 | inserted. */ | |
9387 | ||
876fa593 | 9388 | if (old_loc->inserted) |
0d381245 | 9389 | { |
74960c60 | 9390 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 9391 | |
876fa593 | 9392 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
9393 | { |
9394 | /* The location is still present in the location list, and still | |
9395 | should be inserted. Don't do anything. */ | |
20874c92 | 9396 | keep_in_target = 1; |
74960c60 VP |
9397 | } |
9398 | else | |
9399 | { | |
9400 | /* The location is either no longer present, or got disabled. | |
9401 | See if there's another location at the same address, in which | |
9402 | case we don't need to remove this one from the target. */ | |
876fa593 | 9403 | |
2bdf28a0 | 9404 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
9405 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
9406 | { | |
876fa593 | 9407 | for (loc2p = locp; |
c7d46a38 PA |
9408 | (loc2p < bp_location + bp_location_count |
9409 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
9410 | loc2p++) |
9411 | { | |
9412 | struct bp_location *loc2 = *loc2p; | |
9413 | ||
2d134ed3 | 9414 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
9415 | { |
9416 | /* For the sake of should_be_inserted. | |
9417 | Duplicates check below will fix up this later. */ | |
9418 | loc2->duplicate = 0; | |
85d721b8 PA |
9419 | |
9420 | /* Read watchpoint locations are switched to | |
9421 | access watchpoints, if the former are not | |
9422 | supported, but the latter are. */ | |
9423 | if (is_hardware_watchpoint (old_loc->owner)) | |
9424 | { | |
9425 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
9426 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
9427 | } | |
9428 | ||
c7d46a38 PA |
9429 | if (loc2 != old_loc && should_be_inserted (loc2)) |
9430 | { | |
9431 | loc2->inserted = 1; | |
9432 | loc2->target_info = old_loc->target_info; | |
9433 | keep_in_target = 1; | |
9434 | break; | |
9435 | } | |
876fa593 JK |
9436 | } |
9437 | } | |
9438 | } | |
74960c60 VP |
9439 | } |
9440 | ||
20874c92 VP |
9441 | if (!keep_in_target) |
9442 | { | |
876fa593 | 9443 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
9444 | { |
9445 | /* This is just about all we can do. We could keep this | |
9446 | location on the global list, and try to remove it next | |
9447 | time, but there's no particular reason why we will | |
9448 | succeed next time. | |
9449 | ||
876fa593 | 9450 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
9451 | as delete_breakpoint frees the breakpoint only |
9452 | after calling us. */ | |
9453 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 9454 | old_loc->owner->number); |
20874c92 VP |
9455 | } |
9456 | removed = 1; | |
9457 | } | |
0d381245 | 9458 | } |
74960c60 VP |
9459 | |
9460 | if (!found_object) | |
1c5cfe86 | 9461 | { |
db82e815 PA |
9462 | if (removed && non_stop |
9463 | && breakpoint_address_is_meaningful (old_loc->owner) | |
9464 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 9465 | { |
db82e815 PA |
9466 | /* This location was removed from the target. In |
9467 | non-stop mode, a race condition is possible where | |
9468 | we've removed a breakpoint, but stop events for that | |
9469 | breakpoint are already queued and will arrive later. | |
9470 | We apply an heuristic to be able to distinguish such | |
9471 | SIGTRAPs from other random SIGTRAPs: we keep this | |
9472 | breakpoint location for a bit, and will retire it | |
9473 | after we see some number of events. The theory here | |
9474 | is that reporting of events should, "on the average", | |
9475 | be fair, so after a while we'll see events from all | |
9476 | threads that have anything of interest, and no longer | |
9477 | need to keep this breakpoint location around. We | |
9478 | don't hold locations forever so to reduce chances of | |
9479 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
9480 | SIGTRAP. | |
9481 | ||
9482 | The heuristic failing can be disastrous on | |
9483 | decr_pc_after_break targets. | |
9484 | ||
9485 | On decr_pc_after_break targets, like e.g., x86-linux, | |
9486 | if we fail to recognize a late breakpoint SIGTRAP, | |
9487 | because events_till_retirement has reached 0 too | |
9488 | soon, we'll fail to do the PC adjustment, and report | |
9489 | a random SIGTRAP to the user. When the user resumes | |
9490 | the inferior, it will most likely immediately crash | |
2dec564e | 9491 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
9492 | corrupted, because of being resumed e.g., in the |
9493 | middle of a multi-byte instruction, or skipped a | |
9494 | one-byte instruction. This was actually seen happen | |
9495 | on native x86-linux, and should be less rare on | |
9496 | targets that do not support new thread events, like | |
9497 | remote, due to the heuristic depending on | |
9498 | thread_count. | |
9499 | ||
9500 | Mistaking a random SIGTRAP for a breakpoint trap | |
9501 | causes similar symptoms (PC adjustment applied when | |
9502 | it shouldn't), but then again, playing with SIGTRAPs | |
9503 | behind the debugger's back is asking for trouble. | |
9504 | ||
9505 | Since hardware watchpoint traps are always | |
9506 | distinguishable from other traps, so we don't need to | |
9507 | apply keep hardware watchpoint moribund locations | |
9508 | around. We simply always ignore hardware watchpoint | |
9509 | traps we can no longer explain. */ | |
9510 | ||
876fa593 JK |
9511 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
9512 | old_loc->owner = NULL; | |
20874c92 | 9513 | |
876fa593 | 9514 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
9515 | } |
9516 | else | |
f431efe5 PA |
9517 | { |
9518 | old_loc->owner = NULL; | |
9519 | decref_bp_location (&old_loc); | |
9520 | } | |
20874c92 | 9521 | } |
74960c60 | 9522 | } |
1c5cfe86 | 9523 | |
2d134ed3 PA |
9524 | /* Rescan breakpoints at the same address and section, marking the |
9525 | first one as "first" and any others as "duplicates". This is so | |
9526 | that the bpt instruction is only inserted once. If we have a | |
9527 | permanent breakpoint at the same place as BPT, make that one the | |
9528 | official one, and the rest as duplicates. Permanent breakpoints | |
9529 | are sorted first for the same address. | |
9530 | ||
9531 | Do the same for hardware watchpoints, but also considering the | |
9532 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 9533 | |
2d134ed3 PA |
9534 | bp_loc_first = NULL; |
9535 | wp_loc_first = NULL; | |
9536 | awp_loc_first = NULL; | |
9537 | rwp_loc_first = NULL; | |
876fa593 | 9538 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 9539 | { |
2bdf28a0 | 9540 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
876fa593 | 9541 | struct breakpoint *b = loc->owner; |
2d134ed3 | 9542 | struct bp_location **loc_first_p; |
876fa593 JK |
9543 | |
9544 | if (b->enable_state == bp_disabled | |
9545 | || b->enable_state == bp_call_disabled | |
9546 | || b->enable_state == bp_startup_disabled | |
9547 | || !loc->enabled | |
9548 | || loc->shlib_disabled | |
15c3d785 | 9549 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 9550 | || is_tracepoint (b)) |
876fa593 JK |
9551 | continue; |
9552 | ||
9553 | /* Permanent breakpoint should always be inserted. */ | |
9554 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
9555 | internal_error (__FILE__, __LINE__, | |
9556 | _("allegedly permanent breakpoint is not " | |
9557 | "actually inserted")); | |
9558 | ||
2d134ed3 PA |
9559 | if (b->type == bp_hardware_watchpoint) |
9560 | loc_first_p = &wp_loc_first; | |
9561 | else if (b->type == bp_read_watchpoint) | |
9562 | loc_first_p = &rwp_loc_first; | |
9563 | else if (b->type == bp_access_watchpoint) | |
9564 | loc_first_p = &awp_loc_first; | |
9565 | else | |
9566 | loc_first_p = &bp_loc_first; | |
9567 | ||
9568 | if (*loc_first_p == NULL | |
9569 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
9570 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 9571 | { |
2d134ed3 | 9572 | *loc_first_p = loc; |
876fa593 JK |
9573 | loc->duplicate = 0; |
9574 | continue; | |
9575 | } | |
9576 | ||
9577 | loc->duplicate = 1; | |
9578 | ||
2d134ed3 PA |
9579 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
9580 | && b->enable_state != bp_permanent) | |
876fa593 JK |
9581 | internal_error (__FILE__, __LINE__, |
9582 | _("another breakpoint was inserted on top of " | |
9583 | "a permanent breakpoint")); | |
0d381245 | 9584 | } |
74960c60 | 9585 | |
50c71eaf | 9586 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 9587 | && (have_live_inferiors () |
2567c7d9 | 9588 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 9589 | insert_breakpoint_locations (); |
f7545552 TT |
9590 | |
9591 | do_cleanups (cleanups); | |
74960c60 VP |
9592 | } |
9593 | ||
20874c92 VP |
9594 | void |
9595 | breakpoint_retire_moribund (void) | |
9596 | { | |
9597 | struct bp_location *loc; | |
9598 | int ix; | |
9599 | ||
9600 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
9601 | if (--(loc->events_till_retirement) == 0) | |
9602 | { | |
f431efe5 | 9603 | decref_bp_location (&loc); |
20874c92 VP |
9604 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
9605 | --ix; | |
9606 | } | |
9607 | } | |
9608 | ||
74960c60 | 9609 | static void |
b60e7edf | 9610 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
9611 | { |
9612 | struct gdb_exception e; | |
cc59ec59 | 9613 | |
74960c60 | 9614 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 9615 | update_global_location_list (inserting); |
0d381245 VP |
9616 | } |
9617 | ||
f431efe5 PA |
9618 | /* Clear BKP from a BPS. */ |
9619 | ||
a474d7c2 | 9620 | static void |
f431efe5 | 9621 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
9622 | { |
9623 | bpstat bs; | |
cc59ec59 | 9624 | |
a474d7c2 | 9625 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 9626 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
9627 | { |
9628 | bs->breakpoint_at = NULL; | |
9629 | bs->old_val = NULL; | |
9630 | /* bs->commands will be freed later. */ | |
9631 | } | |
9632 | } | |
9633 | ||
9634 | /* Callback for iterate_over_threads. */ | |
9635 | static int | |
f431efe5 | 9636 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 9637 | { |
f431efe5 | 9638 | struct breakpoint *bpt = data; |
cc59ec59 | 9639 | |
f431efe5 | 9640 | bpstat_remove_bp_location (th->stop_bpstat, bpt); |
a474d7c2 PA |
9641 | return 0; |
9642 | } | |
9643 | ||
53a5351d | 9644 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 9645 | structures. */ |
c906108c SS |
9646 | |
9647 | void | |
fba45db2 | 9648 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9649 | { |
52f0bd74 | 9650 | struct breakpoint *b; |
c906108c | 9651 | |
8a3fe4f8 | 9652 | gdb_assert (bpt != NULL); |
c906108c SS |
9653 | |
9654 | /* Has this bp already been deleted? This can happen because multiple | |
9655 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
9656 | ||
9657 | One example of this happening is a watchpoint's scope bp. When the | |
9658 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
9659 | delete it. We also delete its scope bp. But the scope bp is marked | |
9660 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
9661 | checked for auto-deleting bp's, which are deleted. | |
9662 | ||
9663 | A real solution to this problem might involve reference counts in bp's, | |
9664 | and/or giving them pointers back to their referencing bpstat's, and | |
9665 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 9666 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
9667 | if (bpt->type == bp_none) |
9668 | return; | |
9669 | ||
e5a0a904 JK |
9670 | /* At least avoid this stale reference until the reference counting of |
9671 | breakpoints gets resolved. */ | |
9672 | if (bpt->related_breakpoint != NULL) | |
9673 | { | |
9674 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
9675 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
9676 | bpt->related_breakpoint->related_breakpoint = NULL; | |
9677 | bpt->related_breakpoint = NULL; | |
9678 | } | |
9679 | ||
383f836e | 9680 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 9681 | |
c906108c SS |
9682 | if (breakpoint_chain == bpt) |
9683 | breakpoint_chain = bpt->next; | |
9684 | ||
c906108c SS |
9685 | ALL_BREAKPOINTS (b) |
9686 | if (b->next == bpt) | |
c5aa993b JM |
9687 | { |
9688 | b->next = bpt->next; | |
9689 | break; | |
9690 | } | |
c906108c | 9691 | |
9add0f1b | 9692 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
9693 | xfree (bpt->cond_string); |
9694 | xfree (bpt->cond_exp); | |
9695 | xfree (bpt->addr_string); | |
9696 | xfree (bpt->exp); | |
9697 | xfree (bpt->exp_string); | |
d63d0675 | 9698 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
9699 | value_free (bpt->val); |
9700 | xfree (bpt->source_file); | |
9701 | xfree (bpt->exec_pathname); | |
a96d9b2e | 9702 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 9703 | |
f431efe5 PA |
9704 | |
9705 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
9706 | been freed. */ | |
9707 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
9708 | in all threeds for now. Note that we cannot just remove bpstats | |
9709 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
9710 | commands are associated with the bpstat; if we remove it here, | |
9711 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
9712 | event-top.c won't do anything, and temporary breakpoints with | |
9713 | commands won't work. */ | |
9714 | ||
9715 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
9716 | ||
74960c60 VP |
9717 | /* Now that breakpoint is removed from breakpoint |
9718 | list, update the global location list. This | |
9719 | will remove locations that used to belong to | |
9720 | this breakpoint. Do this before freeing | |
9721 | the breakpoint itself, since remove_breakpoint | |
9722 | looks at location's owner. It might be better | |
9723 | design to have location completely self-contained, | |
9724 | but it's not the case now. */ | |
b60e7edf | 9725 | update_global_location_list (0); |
74960c60 VP |
9726 | |
9727 | ||
c906108c SS |
9728 | /* On the chance that someone will soon try again to delete this same |
9729 | bp, we mark it as deleted before freeing its storage. */ | |
9730 | bpt->type = bp_none; | |
9731 | ||
b8c9b27d | 9732 | xfree (bpt); |
c906108c SS |
9733 | } |
9734 | ||
4d6140d9 AC |
9735 | static void |
9736 | do_delete_breakpoint_cleanup (void *b) | |
9737 | { | |
9738 | delete_breakpoint (b); | |
9739 | } | |
9740 | ||
9741 | struct cleanup * | |
9742 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
9743 | { | |
9744 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
9745 | } | |
9746 | ||
95a42b64 TT |
9747 | /* A callback for map_breakpoint_numbers that calls |
9748 | delete_breakpoint. */ | |
9749 | ||
9750 | static void | |
9751 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
9752 | { | |
9753 | delete_breakpoint (b); | |
9754 | } | |
9755 | ||
c906108c | 9756 | void |
fba45db2 | 9757 | delete_command (char *arg, int from_tty) |
c906108c SS |
9758 | { |
9759 | struct breakpoint *b, *temp; | |
9760 | ||
ea9365bb TT |
9761 | dont_repeat (); |
9762 | ||
c906108c SS |
9763 | if (arg == 0) |
9764 | { | |
9765 | int breaks_to_delete = 0; | |
9766 | ||
9767 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
9768 | Do not delete internal or call-dummy breakpoints, these |
9769 | have to be deleted with an explicit breakpoint number argument. */ | |
9770 | ALL_BREAKPOINTS (b) | |
9771 | { | |
059fb39f | 9772 | if (b->type != bp_call_dummy |
aa7d318d | 9773 | && b->type != bp_std_terminate |
059fb39f | 9774 | && b->type != bp_shlib_event |
4efc6507 | 9775 | && b->type != bp_jit_event |
059fb39f PM |
9776 | && b->type != bp_thread_event |
9777 | && b->type != bp_overlay_event | |
0fd8e87f | 9778 | && b->type != bp_longjmp_master |
aa7d318d | 9779 | && b->type != bp_std_terminate_master |
059fb39f | 9780 | && b->number >= 0) |
973d738b DJ |
9781 | { |
9782 | breaks_to_delete = 1; | |
9783 | break; | |
9784 | } | |
c5aa993b | 9785 | } |
c906108c SS |
9786 | |
9787 | /* Ask user only if there are some breakpoints to delete. */ | |
9788 | if (!from_tty | |
e2e0b3e5 | 9789 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 9790 | { |
c5aa993b JM |
9791 | ALL_BREAKPOINTS_SAFE (b, temp) |
9792 | { | |
059fb39f | 9793 | if (b->type != bp_call_dummy |
aa7d318d | 9794 | && b->type != bp_std_terminate |
059fb39f PM |
9795 | && b->type != bp_shlib_event |
9796 | && b->type != bp_thread_event | |
4efc6507 | 9797 | && b->type != bp_jit_event |
059fb39f | 9798 | && b->type != bp_overlay_event |
0fd8e87f | 9799 | && b->type != bp_longjmp_master |
aa7d318d | 9800 | && b->type != bp_std_terminate_master |
059fb39f | 9801 | && b->number >= 0) |
c5aa993b JM |
9802 | delete_breakpoint (b); |
9803 | } | |
c906108c SS |
9804 | } |
9805 | } | |
9806 | else | |
95a42b64 | 9807 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
9808 | } |
9809 | ||
0d381245 VP |
9810 | static int |
9811 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 9812 | { |
0d381245 VP |
9813 | for (; loc; loc = loc->next) |
9814 | if (!loc->shlib_disabled) | |
9815 | return 0; | |
9816 | return 1; | |
fe3f5fa8 VP |
9817 | } |
9818 | ||
776592bf DE |
9819 | /* Subroutine of update_breakpoint_locations to simplify it. |
9820 | Return non-zero if multiple fns in list LOC have the same name. | |
9821 | Null names are ignored. */ | |
9822 | ||
9823 | static int | |
9824 | ambiguous_names_p (struct bp_location *loc) | |
9825 | { | |
9826 | struct bp_location *l; | |
9827 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
9828 | (int (*) (const void *, |
9829 | const void *)) streq, | |
776592bf DE |
9830 | NULL, xcalloc, xfree); |
9831 | ||
9832 | for (l = loc; l != NULL; l = l->next) | |
9833 | { | |
9834 | const char **slot; | |
9835 | const char *name = l->function_name; | |
9836 | ||
9837 | /* Allow for some names to be NULL, ignore them. */ | |
9838 | if (name == NULL) | |
9839 | continue; | |
9840 | ||
9841 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
9842 | INSERT); | |
9843 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
9844 | NULL. */ | |
9845 | if (*slot != NULL) | |
9846 | { | |
9847 | htab_delete (htab); | |
9848 | return 1; | |
9849 | } | |
9850 | *slot = name; | |
9851 | } | |
9852 | ||
9853 | htab_delete (htab); | |
9854 | return 0; | |
9855 | } | |
9856 | ||
0fb4aa4b PA |
9857 | /* When symbols change, it probably means the sources changed as well, |
9858 | and it might mean the static tracepoint markers are no longer at | |
9859 | the same address or line numbers they used to be at last we | |
9860 | checked. Losing your static tracepoints whenever you rebuild is | |
9861 | undesirable. This function tries to resync/rematch gdb static | |
9862 | tracepoints with the markers on the target, for static tracepoints | |
9863 | that have not been set by marker id. Static tracepoint that have | |
9864 | been set by marker id are reset by marker id in breakpoint_re_set. | |
9865 | The heuristic is: | |
9866 | ||
9867 | 1) For a tracepoint set at a specific address, look for a marker at | |
9868 | the old PC. If one is found there, assume to be the same marker. | |
9869 | If the name / string id of the marker found is different from the | |
9870 | previous known name, assume that means the user renamed the marker | |
9871 | in the sources, and output a warning. | |
9872 | ||
9873 | 2) For a tracepoint set at a given line number, look for a marker | |
9874 | at the new address of the old line number. If one is found there, | |
9875 | assume to be the same marker. If the name / string id of the | |
9876 | marker found is different from the previous known name, assume that | |
9877 | means the user renamed the marker in the sources, and output a | |
9878 | warning. | |
9879 | ||
9880 | 3) If a marker is no longer found at the same address or line, it | |
9881 | may mean the marker no longer exists. But it may also just mean | |
9882 | the code changed a bit. Maybe the user added a few lines of code | |
9883 | that made the marker move up or down (in line number terms). Ask | |
9884 | the target for info about the marker with the string id as we knew | |
9885 | it. If found, update line number and address in the matching | |
9886 | static tracepoint. This will get confused if there's more than one | |
9887 | marker with the same ID (possible in UST, although unadvised | |
9888 | precisely because it confuses tools). */ | |
9889 | ||
9890 | static struct symtab_and_line | |
9891 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
9892 | { | |
9893 | struct static_tracepoint_marker marker; | |
9894 | CORE_ADDR pc; | |
9895 | int i; | |
9896 | ||
9897 | pc = sal.pc; | |
9898 | if (sal.line) | |
9899 | find_line_pc (sal.symtab, sal.line, &pc); | |
9900 | ||
9901 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
9902 | { | |
9903 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
9904 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
9905 | b->number, | |
9906 | b->static_trace_marker_id, marker.str_id); | |
9907 | ||
9908 | xfree (b->static_trace_marker_id); | |
9909 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
9910 | release_static_tracepoint_marker (&marker); | |
9911 | ||
9912 | return sal; | |
9913 | } | |
9914 | ||
9915 | /* Old marker wasn't found on target at lineno. Try looking it up | |
9916 | by string ID. */ | |
9917 | if (!sal.explicit_pc | |
9918 | && sal.line != 0 | |
9919 | && sal.symtab != NULL | |
9920 | && b->static_trace_marker_id != NULL) | |
9921 | { | |
9922 | VEC(static_tracepoint_marker_p) *markers; | |
9923 | ||
9924 | markers | |
9925 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
9926 | ||
9927 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
9928 | { | |
9929 | struct symtab_and_line sal; | |
9930 | struct symbol *sym; | |
9931 | struct static_tracepoint_marker *marker; | |
9932 | ||
9933 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
9934 | ||
9935 | xfree (b->static_trace_marker_id); | |
9936 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
9937 | ||
9938 | warning (_("marker for static tracepoint %d (%s) not " | |
9939 | "found at previous line number"), | |
9940 | b->number, b->static_trace_marker_id); | |
9941 | ||
9942 | init_sal (&sal); | |
9943 | ||
9944 | sal.pc = marker->address; | |
9945 | ||
9946 | sal = find_pc_line (marker->address, 0); | |
9947 | sym = find_pc_sect_function (marker->address, NULL); | |
9948 | ui_out_text (uiout, "Now in "); | |
9949 | if (sym) | |
9950 | { | |
9951 | ui_out_field_string (uiout, "func", | |
9952 | SYMBOL_PRINT_NAME (sym)); | |
9953 | ui_out_text (uiout, " at "); | |
9954 | } | |
9955 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
9956 | ui_out_text (uiout, ":"); | |
9957 | ||
9958 | if (ui_out_is_mi_like_p (uiout)) | |
9959 | { | |
9960 | char *fullname = symtab_to_fullname (sal.symtab); | |
9961 | ||
9962 | if (fullname) | |
9963 | ui_out_field_string (uiout, "fullname", fullname); | |
9964 | } | |
9965 | ||
9966 | ui_out_field_int (uiout, "line", sal.line); | |
9967 | ui_out_text (uiout, "\n"); | |
9968 | ||
9969 | b->line_number = sal.line; | |
9970 | ||
9971 | xfree (b->source_file); | |
9972 | if (sym) | |
9973 | b->source_file = xstrdup (sal.symtab->filename); | |
9974 | else | |
9975 | b->source_file = NULL; | |
9976 | ||
9977 | xfree (b->addr_string); | |
9978 | b->addr_string = xstrprintf ("%s:%d", | |
9979 | sal.symtab->filename, b->line_number); | |
9980 | ||
9981 | /* Might be nice to check if function changed, and warn if | |
9982 | so. */ | |
9983 | ||
9984 | release_static_tracepoint_marker (marker); | |
9985 | } | |
9986 | } | |
9987 | return sal; | |
9988 | } | |
9989 | ||
fe3f5fa8 | 9990 | static void |
0d381245 VP |
9991 | update_breakpoint_locations (struct breakpoint *b, |
9992 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
9993 | { |
9994 | int i; | |
9995 | char *s; | |
0d381245 VP |
9996 | struct bp_location *existing_locations = b->loc; |
9997 | ||
9998 | /* If there's no new locations, and all existing locations | |
9999 | are pending, don't do anything. This optimizes | |
10000 | the common case where all locations are in the same | |
10001 | shared library, that was unloaded. We'd like to | |
10002 | retain the location, so that when the library | |
10003 | is loaded again, we don't loose the enabled/disabled | |
10004 | status of the individual locations. */ | |
10005 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
10006 | return; |
10007 | ||
fe3f5fa8 VP |
10008 | b->loc = NULL; |
10009 | ||
0d381245 | 10010 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 10011 | { |
0d381245 | 10012 | struct bp_location *new_loc = |
39d61571 | 10013 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 10014 | |
0d381245 VP |
10015 | /* Reparse conditions, they might contain references to the |
10016 | old symtab. */ | |
10017 | if (b->cond_string != NULL) | |
10018 | { | |
10019 | struct gdb_exception e; | |
fe3f5fa8 | 10020 | |
0d381245 VP |
10021 | s = b->cond_string; |
10022 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
10023 | { | |
10024 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
10025 | 0); | |
10026 | } | |
10027 | if (e.reason < 0) | |
10028 | { | |
10029 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
10030 | b->number, e.message); | |
10031 | new_loc->enabled = 0; | |
10032 | } | |
10033 | } | |
fe3f5fa8 | 10034 | |
0d381245 VP |
10035 | if (b->source_file != NULL) |
10036 | xfree (b->source_file); | |
10037 | if (sals.sals[i].symtab == NULL) | |
10038 | b->source_file = NULL; | |
10039 | else | |
1b36a34b | 10040 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 10041 | |
0d381245 VP |
10042 | if (b->line_number == 0) |
10043 | b->line_number = sals.sals[i].line; | |
10044 | } | |
fe3f5fa8 | 10045 | |
514f746b AR |
10046 | /* Update locations of permanent breakpoints. */ |
10047 | if (b->enable_state == bp_permanent) | |
10048 | make_breakpoint_permanent (b); | |
10049 | ||
0d381245 VP |
10050 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
10051 | { | |
10052 | struct bp_location *e = existing_locations; | |
776592bf DE |
10053 | /* If there are multiple breakpoints with the same function name, |
10054 | e.g. for inline functions, comparing function names won't work. | |
10055 | Instead compare pc addresses; this is just a heuristic as things | |
10056 | may have moved, but in practice it gives the correct answer | |
10057 | often enough until a better solution is found. */ | |
10058 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
10059 | ||
0d381245 VP |
10060 | for (; e; e = e->next) |
10061 | { | |
10062 | if (!e->enabled && e->function_name) | |
10063 | { | |
10064 | struct bp_location *l = b->loc; | |
776592bf DE |
10065 | if (have_ambiguous_names) |
10066 | { | |
10067 | for (; l; l = l->next) | |
6c95b8df PA |
10068 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
10069 | l->pspace->aspace, l->address)) | |
776592bf DE |
10070 | { |
10071 | l->enabled = 0; | |
10072 | break; | |
10073 | } | |
10074 | } | |
10075 | else | |
10076 | { | |
10077 | for (; l; l = l->next) | |
10078 | if (l->function_name | |
10079 | && strcmp (e->function_name, l->function_name) == 0) | |
10080 | { | |
10081 | l->enabled = 0; | |
10082 | break; | |
10083 | } | |
10084 | } | |
0d381245 VP |
10085 | } |
10086 | } | |
10087 | } | |
fe3f5fa8 | 10088 | |
b60e7edf | 10089 | update_global_location_list (1); |
fe3f5fa8 VP |
10090 | } |
10091 | ||
c906108c SS |
10092 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
10093 | The value we return ends up being the return value from catch_errors. | |
10094 | Unused in this case. */ | |
10095 | ||
10096 | static int | |
4efb68b1 | 10097 | breakpoint_re_set_one (void *bint) |
c906108c | 10098 | { |
53a5351d JM |
10099 | /* get past catch_errs */ |
10100 | struct breakpoint *b = (struct breakpoint *) bint; | |
fe3f5fa8 VP |
10101 | int not_found = 0; |
10102 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
10103 | struct symtabs_and_lines sals = {0}; |
10104 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 10105 | char *s; |
fe3f5fa8 | 10106 | struct gdb_exception e; |
6c95b8df | 10107 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
0fb4aa4b | 10108 | int marker_spec = 0; |
c906108c SS |
10109 | |
10110 | switch (b->type) | |
10111 | { | |
10112 | case bp_none: | |
8a3fe4f8 | 10113 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 10114 | b->number); |
c906108c SS |
10115 | return 0; |
10116 | case bp_breakpoint: | |
10117 | case bp_hardware_breakpoint: | |
1042e4c0 | 10118 | case bp_tracepoint: |
7a697b8d | 10119 | case bp_fast_tracepoint: |
0fb4aa4b | 10120 | case bp_static_tracepoint: |
8bea4e01 UW |
10121 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
10122 | if (b->enable_state == bp_startup_disabled) | |
10123 | return 0; | |
10124 | ||
c906108c SS |
10125 | if (b->addr_string == NULL) |
10126 | { | |
10127 | /* Anything without a string can't be re-set. */ | |
10128 | delete_breakpoint (b); | |
10129 | return 0; | |
10130 | } | |
c906108c | 10131 | |
c906108c SS |
10132 | input_radix = b->input_radix; |
10133 | s = b->addr_string; | |
6c95b8df PA |
10134 | |
10135 | save_current_space_and_thread (); | |
10136 | switch_to_program_space_and_thread (b->pspace); | |
10137 | ||
0fb4aa4b PA |
10138 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); |
10139 | ||
385d04dc | 10140 | set_language (b->language); |
fe3f5fa8 | 10141 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 10142 | { |
0fb4aa4b PA |
10143 | if (marker_spec) |
10144 | { | |
10145 | sals = decode_static_tracepoint_spec (&s); | |
10146 | if (sals.nelts > b->static_trace_marker_id_idx) | |
10147 | { | |
10148 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
10149 | sals.nelts = 1; | |
10150 | } | |
10151 | else | |
10152 | error (_("marker %s not found"), b->static_trace_marker_id); | |
10153 | } | |
10154 | else | |
10155 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, | |
10156 | not_found_ptr); | |
fe3f5fa8 VP |
10157 | } |
10158 | if (e.reason < 0) | |
10159 | { | |
10160 | int not_found_and_ok = 0; | |
10161 | /* For pending breakpoints, it's expected that parsing | |
10162 | will fail until the right shared library is loaded. | |
10163 | User has already told to create pending breakpoints and | |
10164 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
10165 | state, then user already saw the message about that breakpoint | |
10166 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
10167 | if (not_found |
10168 | && (b->condition_not_parsed | |
10169 | || (b->loc && b->loc->shlib_disabled) | |
10170 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
10171 | not_found_and_ok = 1; |
10172 | ||
10173 | if (!not_found_and_ok) | |
c906108c | 10174 | { |
fe3f5fa8 VP |
10175 | /* We surely don't want to warn about the same breakpoint |
10176 | 10 times. One solution, implemented here, is disable | |
10177 | the breakpoint on error. Another solution would be to | |
10178 | have separate 'warning emitted' flag. Since this | |
10179 | happens only when a binary has changed, I don't know | |
10180 | which approach is better. */ | |
10181 | b->enable_state = bp_disabled; | |
10182 | throw_exception (e); | |
c906108c | 10183 | } |
fe3f5fa8 | 10184 | } |
c906108c | 10185 | |
6c95b8df | 10186 | if (!not_found) |
fe3f5fa8 | 10187 | { |
6c95b8df PA |
10188 | gdb_assert (sals.nelts == 1); |
10189 | ||
10190 | resolve_sal_pc (&sals.sals[0]); | |
10191 | if (b->condition_not_parsed && s && s[0]) | |
10192 | { | |
10193 | char *cond_string = 0; | |
10194 | int thread = -1; | |
10195 | int task = 0; | |
10196 | ||
10197 | find_condition_and_thread (s, sals.sals[0].pc, | |
10198 | &cond_string, &thread, &task); | |
10199 | if (cond_string) | |
10200 | b->cond_string = cond_string; | |
10201 | b->thread = thread; | |
10202 | b->task = task; | |
10203 | b->condition_not_parsed = 0; | |
10204 | } | |
10205 | ||
0fb4aa4b PA |
10206 | if (b->type == bp_static_tracepoint && !marker_spec) |
10207 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
10208 | ||
6c95b8df | 10209 | expanded = expand_line_sal_maybe (sals.sals[0]); |
fe3f5fa8 | 10210 | } |
6c95b8df PA |
10211 | |
10212 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 10213 | update_breakpoint_locations (b, expanded); |
c906108c SS |
10214 | break; |
10215 | ||
10216 | case bp_watchpoint: | |
10217 | case bp_hardware_watchpoint: | |
10218 | case bp_read_watchpoint: | |
10219 | case bp_access_watchpoint: | |
0b3de036 VP |
10220 | /* Watchpoint can be either on expression using entirely global variables, |
10221 | or it can be on local variables. | |
10222 | ||
10223 | Watchpoints of the first kind are never auto-deleted, and even persist | |
10224 | across program restarts. Since they can use variables from shared | |
10225 | libraries, we need to reparse expression as libraries are loaded | |
10226 | and unloaded. | |
10227 | ||
10228 | Watchpoints on local variables can also change meaning as result | |
10229 | of solib event. For example, if a watchpoint uses both a local and | |
10230 | a global variables in expression, it's a local watchpoint, but | |
10231 | unloading of a shared library will make the expression invalid. | |
10232 | This is not a very common use case, but we still re-evaluate | |
10233 | expression, to avoid surprises to the user. | |
10234 | ||
10235 | Note that for local watchpoints, we re-evaluate it only if | |
10236 | watchpoints frame id is still valid. If it's not, it means | |
10237 | the watchpoint is out of scope and will be deleted soon. In fact, | |
10238 | I'm not sure we'll ever be called in this case. | |
10239 | ||
10240 | If a local watchpoint's frame id is still valid, then | |
10241 | b->exp_valid_block is likewise valid, and we can safely use it. | |
10242 | ||
10243 | Don't do anything about disabled watchpoints, since they will | |
10244 | be reevaluated again when enabled. */ | |
a5606eee | 10245 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 10246 | break; |
c5aa993b JM |
10247 | /* We needn't really do anything to reset these, since the mask |
10248 | that requests them is unaffected by e.g., new libraries being | |
10249 | loaded. */ | |
ce78b96d | 10250 | case bp_catchpoint: |
c906108c | 10251 | break; |
c5aa993b | 10252 | |
c906108c | 10253 | default: |
a3f17187 | 10254 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 10255 | /* fall through */ |
0fd8e87f UW |
10256 | /* Delete overlay event and longjmp master breakpoints; they will be |
10257 | reset later by breakpoint_re_set. */ | |
1900040c | 10258 | case bp_overlay_event: |
0fd8e87f | 10259 | case bp_longjmp_master: |
aa7d318d | 10260 | case bp_std_terminate_master: |
c906108c SS |
10261 | delete_breakpoint (b); |
10262 | break; | |
10263 | ||
c5aa993b JM |
10264 | /* This breakpoint is special, it's set up when the inferior |
10265 | starts and we really don't want to touch it. */ | |
c906108c SS |
10266 | case bp_shlib_event: |
10267 | ||
c4093a6a JM |
10268 | /* Like bp_shlib_event, this breakpoint type is special. |
10269 | Once it is set up, we do not want to touch it. */ | |
10270 | case bp_thread_event: | |
10271 | ||
c5aa993b JM |
10272 | /* Keep temporary breakpoints, which can be encountered when we step |
10273 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
10274 | Otherwise these should have been blown away via the cleanup chain | |
10275 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
10276 | case bp_until: |
10277 | case bp_finish: | |
10278 | case bp_watchpoint_scope: | |
10279 | case bp_call_dummy: | |
aa7d318d | 10280 | case bp_std_terminate: |
c906108c | 10281 | case bp_step_resume: |
611c83ae PA |
10282 | case bp_longjmp: |
10283 | case bp_longjmp_resume: | |
4efc6507 | 10284 | case bp_jit_event: |
c906108c SS |
10285 | break; |
10286 | } | |
10287 | ||
6c95b8df | 10288 | do_cleanups (cleanups); |
c906108c SS |
10289 | return 0; |
10290 | } | |
10291 | ||
69de3c6a | 10292 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 10293 | void |
69de3c6a | 10294 | breakpoint_re_set (void) |
c906108c SS |
10295 | { |
10296 | struct breakpoint *b, *temp; | |
10297 | enum language save_language; | |
10298 | int save_input_radix; | |
6c95b8df | 10299 | struct cleanup *old_chain; |
c5aa993b | 10300 | |
c906108c SS |
10301 | save_language = current_language->la_language; |
10302 | save_input_radix = input_radix; | |
6c95b8df PA |
10303 | old_chain = save_current_program_space (); |
10304 | ||
c906108c | 10305 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 10306 | { |
53a5351d | 10307 | /* Format possible error msg */ |
fe3f5fa8 | 10308 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
10309 | b->number); |
10310 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 10311 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 10312 | do_cleanups (cleanups); |
c5aa993b | 10313 | } |
c906108c SS |
10314 | set_language (save_language); |
10315 | input_radix = save_input_radix; | |
e62c965a | 10316 | |
0756c555 | 10317 | jit_breakpoint_re_set (); |
4efc6507 | 10318 | |
6c95b8df PA |
10319 | do_cleanups (old_chain); |
10320 | ||
69de3c6a | 10321 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
10322 | create_longjmp_master_breakpoint ("longjmp"); |
10323 | create_longjmp_master_breakpoint ("_longjmp"); | |
10324 | create_longjmp_master_breakpoint ("siglongjmp"); | |
10325 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
aa7d318d | 10326 | create_std_terminate_master_breakpoint ("std::terminate()"); |
c906108c SS |
10327 | } |
10328 | \f | |
c906108c SS |
10329 | /* Reset the thread number of this breakpoint: |
10330 | ||
10331 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 10332 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 10333 | void |
fba45db2 | 10334 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
10335 | { |
10336 | if (b->thread != -1) | |
10337 | { | |
39f77062 KB |
10338 | if (in_thread_list (inferior_ptid)) |
10339 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
10340 | |
10341 | /* We're being called after following a fork. The new fork is | |
10342 | selected as current, and unless this was a vfork will have a | |
10343 | different program space from the original thread. Reset that | |
10344 | as well. */ | |
10345 | b->loc->pspace = current_program_space; | |
c906108c SS |
10346 | } |
10347 | } | |
10348 | ||
03ac34d5 MS |
10349 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10350 | If from_tty is nonzero, it prints a message to that effect, | |
10351 | which ends with a period (no newline). */ | |
10352 | ||
c906108c | 10353 | void |
fba45db2 | 10354 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 10355 | { |
52f0bd74 | 10356 | struct breakpoint *b; |
c906108c SS |
10357 | |
10358 | if (count < 0) | |
10359 | count = 0; | |
10360 | ||
10361 | ALL_BREAKPOINTS (b) | |
10362 | if (b->number == bptnum) | |
c5aa993b | 10363 | { |
d77f58be SS |
10364 | if (is_tracepoint (b)) |
10365 | { | |
10366 | if (from_tty && count != 0) | |
10367 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
10368 | bptnum); | |
10369 | return; | |
10370 | } | |
10371 | ||
c5aa993b | 10372 | b->ignore_count = count; |
221ea385 KS |
10373 | if (from_tty) |
10374 | { | |
10375 | if (count == 0) | |
a3f17187 | 10376 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
10377 | bptnum); |
10378 | else if (count == 1) | |
a3f17187 | 10379 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
10380 | bptnum); |
10381 | else | |
a3f17187 | 10382 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
10383 | count, bptnum); |
10384 | } | |
c5aa993b | 10385 | breakpoints_changed (); |
383f836e | 10386 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
10387 | return; |
10388 | } | |
c906108c | 10389 | |
8a3fe4f8 | 10390 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
10391 | } |
10392 | ||
b2175913 MS |
10393 | void |
10394 | make_breakpoint_silent (struct breakpoint *b) | |
10395 | { | |
10396 | /* Silence the breakpoint. */ | |
10397 | b->silent = 1; | |
10398 | } | |
10399 | ||
c906108c SS |
10400 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
10401 | ||
10402 | static void | |
fba45db2 | 10403 | ignore_command (char *args, int from_tty) |
c906108c SS |
10404 | { |
10405 | char *p = args; | |
52f0bd74 | 10406 | int num; |
c906108c SS |
10407 | |
10408 | if (p == 0) | |
e2e0b3e5 | 10409 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 10410 | |
c906108c | 10411 | num = get_number (&p); |
5c44784c | 10412 | if (num == 0) |
8a3fe4f8 | 10413 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 10414 | if (*p == 0) |
8a3fe4f8 | 10415 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
10416 | |
10417 | set_ignore_count (num, | |
10418 | longest_to_int (value_as_long (parse_and_eval (p))), | |
10419 | from_tty); | |
221ea385 KS |
10420 | if (from_tty) |
10421 | printf_filtered ("\n"); | |
c906108c SS |
10422 | } |
10423 | \f | |
10424 | /* Call FUNCTION on each of the breakpoints | |
10425 | whose numbers are given in ARGS. */ | |
10426 | ||
10427 | static void | |
95a42b64 TT |
10428 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
10429 | void *), | |
10430 | void *data) | |
c906108c | 10431 | { |
52f0bd74 | 10432 | char *p = args; |
c906108c | 10433 | char *p1; |
52f0bd74 AC |
10434 | int num; |
10435 | struct breakpoint *b, *tmp; | |
11cf8741 | 10436 | int match; |
c906108c SS |
10437 | |
10438 | if (p == 0) | |
e2e0b3e5 | 10439 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
10440 | |
10441 | while (*p) | |
10442 | { | |
11cf8741 | 10443 | match = 0; |
c906108c | 10444 | p1 = p; |
c5aa993b | 10445 | |
5c44784c JM |
10446 | num = get_number_or_range (&p1); |
10447 | if (num == 0) | |
c5aa993b | 10448 | { |
8a3fe4f8 | 10449 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
10450 | } |
10451 | else | |
10452 | { | |
10453 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
10454 | if (b->number == num) | |
10455 | { | |
10456 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 10457 | match = 1; |
95a42b64 | 10458 | function (b, data); |
5c44784c | 10459 | if (related_breakpoint) |
95a42b64 | 10460 | function (related_breakpoint, data); |
11cf8741 | 10461 | break; |
5c44784c | 10462 | } |
11cf8741 | 10463 | if (match == 0) |
a3f17187 | 10464 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 10465 | } |
c906108c SS |
10466 | p = p1; |
10467 | } | |
10468 | } | |
10469 | ||
0d381245 VP |
10470 | static struct bp_location * |
10471 | find_location_by_number (char *number) | |
10472 | { | |
10473 | char *dot = strchr (number, '.'); | |
10474 | char *p1; | |
10475 | int bp_num; | |
10476 | int loc_num; | |
10477 | struct breakpoint *b; | |
10478 | struct bp_location *loc; | |
10479 | ||
10480 | *dot = '\0'; | |
10481 | ||
10482 | p1 = number; | |
10483 | bp_num = get_number_or_range (&p1); | |
10484 | if (bp_num == 0) | |
10485 | error (_("Bad breakpoint number '%s'"), number); | |
10486 | ||
10487 | ALL_BREAKPOINTS (b) | |
10488 | if (b->number == bp_num) | |
10489 | { | |
10490 | break; | |
10491 | } | |
10492 | ||
10493 | if (!b || b->number != bp_num) | |
10494 | error (_("Bad breakpoint number '%s'"), number); | |
10495 | ||
10496 | p1 = dot+1; | |
10497 | loc_num = get_number_or_range (&p1); | |
10498 | if (loc_num == 0) | |
10499 | error (_("Bad breakpoint location number '%s'"), number); | |
10500 | ||
10501 | --loc_num; | |
10502 | loc = b->loc; | |
10503 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
10504 | ; | |
10505 | if (!loc) | |
10506 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
10507 | ||
10508 | return loc; | |
10509 | } | |
10510 | ||
10511 | ||
1900040c MS |
10512 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
10513 | If from_tty is nonzero, it prints a message to that effect, | |
10514 | which ends with a period (no newline). */ | |
10515 | ||
c906108c | 10516 | void |
fba45db2 | 10517 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10518 | { |
10519 | /* Never disable a watchpoint scope breakpoint; we want to | |
10520 | hit them when we leave scope so we can delete both the | |
10521 | watchpoint and its scope breakpoint at that time. */ | |
10522 | if (bpt->type == bp_watchpoint_scope) | |
10523 | return; | |
10524 | ||
c2c6d25f | 10525 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 10526 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
10527 | return; |
10528 | ||
b5de0fa7 | 10529 | bpt->enable_state = bp_disabled; |
c906108c | 10530 | |
b60e7edf | 10531 | update_global_location_list (0); |
c906108c | 10532 | |
383f836e | 10533 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10534 | } |
10535 | ||
95a42b64 TT |
10536 | /* A callback for map_breakpoint_numbers that calls |
10537 | disable_breakpoint. */ | |
10538 | ||
10539 | static void | |
10540 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
10541 | { | |
10542 | disable_breakpoint (b); | |
10543 | } | |
10544 | ||
c906108c | 10545 | static void |
fba45db2 | 10546 | disable_command (char *args, int from_tty) |
c906108c | 10547 | { |
52f0bd74 | 10548 | struct breakpoint *bpt; |
cc59ec59 | 10549 | |
c906108c SS |
10550 | if (args == 0) |
10551 | ALL_BREAKPOINTS (bpt) | |
10552 | switch (bpt->type) | |
c5aa993b JM |
10553 | { |
10554 | case bp_none: | |
8a3fe4f8 | 10555 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 10556 | bpt->number); |
c5aa993b JM |
10557 | continue; |
10558 | case bp_breakpoint: | |
1042e4c0 | 10559 | case bp_tracepoint: |
7a697b8d | 10560 | case bp_fast_tracepoint: |
0fb4aa4b | 10561 | case bp_static_tracepoint: |
ce78b96d | 10562 | case bp_catchpoint: |
c5aa993b JM |
10563 | case bp_hardware_breakpoint: |
10564 | case bp_watchpoint: | |
10565 | case bp_hardware_watchpoint: | |
10566 | case bp_read_watchpoint: | |
10567 | case bp_access_watchpoint: | |
10568 | disable_breakpoint (bpt); | |
10569 | default: | |
10570 | continue; | |
10571 | } | |
0d381245 VP |
10572 | else if (strchr (args, '.')) |
10573 | { | |
10574 | struct bp_location *loc = find_location_by_number (args); | |
10575 | if (loc) | |
10576 | loc->enabled = 0; | |
b60e7edf | 10577 | update_global_location_list (0); |
0d381245 | 10578 | } |
c906108c | 10579 | else |
95a42b64 | 10580 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
10581 | } |
10582 | ||
10583 | static void | |
fba45db2 | 10584 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 10585 | { |
afe38095 | 10586 | int target_resources_ok; |
c906108c SS |
10587 | |
10588 | if (bpt->type == bp_hardware_breakpoint) | |
10589 | { | |
10590 | int i; | |
c5aa993b | 10591 | i = hw_breakpoint_used_count (); |
53a5351d | 10592 | target_resources_ok = |
d92524f1 | 10593 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 10594 | i + 1, 0); |
c906108c | 10595 | if (target_resources_ok == 0) |
8a3fe4f8 | 10596 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 10597 | else if (target_resources_ok < 0) |
8a3fe4f8 | 10598 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
10599 | } |
10600 | ||
cc60f2e3 | 10601 | if (is_watchpoint (bpt)) |
c906108c | 10602 | { |
dde02812 ES |
10603 | struct gdb_exception e; |
10604 | ||
10605 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 10606 | { |
dde02812 | 10607 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 10608 | } |
dde02812 | 10609 | if (e.reason < 0) |
c5aa993b | 10610 | { |
dde02812 ES |
10611 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
10612 | bpt->number); | |
10613 | return; | |
c5aa993b | 10614 | } |
c906108c | 10615 | } |
0101ce28 | 10616 | |
b4c291bb KH |
10617 | if (bpt->enable_state != bp_permanent) |
10618 | bpt->enable_state = bp_enabled; | |
10619 | bpt->disposition = disposition; | |
b60e7edf | 10620 | update_global_location_list (1); |
b4c291bb KH |
10621 | breakpoints_changed (); |
10622 | ||
383f836e | 10623 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
10624 | } |
10625 | ||
fe3f5fa8 | 10626 | |
c906108c | 10627 | void |
fba45db2 | 10628 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
10629 | { |
10630 | do_enable_breakpoint (bpt, bpt->disposition); | |
10631 | } | |
10632 | ||
95a42b64 TT |
10633 | /* A callback for map_breakpoint_numbers that calls |
10634 | enable_breakpoint. */ | |
10635 | ||
10636 | static void | |
10637 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
10638 | { | |
10639 | enable_breakpoint (b); | |
10640 | } | |
10641 | ||
c906108c SS |
10642 | /* The enable command enables the specified breakpoints (or all defined |
10643 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 10644 | in stopping the inferior. */ |
c906108c | 10645 | |
c906108c | 10646 | static void |
fba45db2 | 10647 | enable_command (char *args, int from_tty) |
c906108c | 10648 | { |
52f0bd74 | 10649 | struct breakpoint *bpt; |
cc59ec59 | 10650 | |
c906108c SS |
10651 | if (args == 0) |
10652 | ALL_BREAKPOINTS (bpt) | |
10653 | switch (bpt->type) | |
c5aa993b JM |
10654 | { |
10655 | case bp_none: | |
8a3fe4f8 | 10656 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 10657 | bpt->number); |
c5aa993b JM |
10658 | continue; |
10659 | case bp_breakpoint: | |
1042e4c0 | 10660 | case bp_tracepoint: |
7a697b8d | 10661 | case bp_fast_tracepoint: |
0fb4aa4b | 10662 | case bp_static_tracepoint: |
ce78b96d | 10663 | case bp_catchpoint: |
c5aa993b JM |
10664 | case bp_hardware_breakpoint: |
10665 | case bp_watchpoint: | |
10666 | case bp_hardware_watchpoint: | |
10667 | case bp_read_watchpoint: | |
10668 | case bp_access_watchpoint: | |
10669 | enable_breakpoint (bpt); | |
10670 | default: | |
10671 | continue; | |
10672 | } | |
0d381245 VP |
10673 | else if (strchr (args, '.')) |
10674 | { | |
10675 | struct bp_location *loc = find_location_by_number (args); | |
10676 | if (loc) | |
10677 | loc->enabled = 1; | |
b60e7edf | 10678 | update_global_location_list (1); |
0d381245 | 10679 | } |
c906108c | 10680 | else |
95a42b64 | 10681 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
10682 | } |
10683 | ||
10684 | static void | |
95a42b64 | 10685 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10686 | { |
b5de0fa7 | 10687 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
10688 | } |
10689 | ||
c906108c | 10690 | static void |
fba45db2 | 10691 | enable_once_command (char *args, int from_tty) |
c906108c | 10692 | { |
95a42b64 | 10693 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
10694 | } |
10695 | ||
10696 | static void | |
95a42b64 | 10697 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 10698 | { |
b5de0fa7 | 10699 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
10700 | } |
10701 | ||
c906108c | 10702 | static void |
fba45db2 | 10703 | enable_delete_command (char *args, int from_tty) |
c906108c | 10704 | { |
95a42b64 | 10705 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
10706 | } |
10707 | \f | |
fa8d40ab JJ |
10708 | static void |
10709 | set_breakpoint_cmd (char *args, int from_tty) | |
10710 | { | |
10711 | } | |
10712 | ||
10713 | static void | |
10714 | show_breakpoint_cmd (char *args, int from_tty) | |
10715 | { | |
10716 | } | |
10717 | ||
1f3b5d1b PP |
10718 | /* Invalidate last known value of any hardware watchpoint if |
10719 | the memory which that value represents has been written to by | |
10720 | GDB itself. */ | |
10721 | ||
10722 | static void | |
10723 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
10724 | const bfd_byte *data) | |
10725 | { | |
10726 | struct breakpoint *bp; | |
10727 | ||
10728 | ALL_BREAKPOINTS (bp) | |
10729 | if (bp->enable_state == bp_enabled | |
10730 | && bp->type == bp_hardware_watchpoint | |
10731 | && bp->val_valid && bp->val) | |
10732 | { | |
10733 | struct bp_location *loc; | |
10734 | ||
10735 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
10736 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
10737 | && loc->address + loc->length > addr | |
10738 | && addr + len > loc->address) | |
10739 | { | |
10740 | value_free (bp->val); | |
10741 | bp->val = NULL; | |
10742 | bp->val_valid = 0; | |
10743 | } | |
10744 | } | |
10745 | } | |
10746 | ||
c906108c SS |
10747 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
10748 | ||
10749 | struct symtabs_and_lines | |
fba45db2 | 10750 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
10751 | { |
10752 | struct symtabs_and_lines sals; | |
cc59ec59 | 10753 | |
c906108c | 10754 | if (string == 0) |
8a3fe4f8 | 10755 | error (_("Empty line specification.")); |
c906108c SS |
10756 | if (default_breakpoint_valid) |
10757 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
10758 | default_breakpoint_symtab, |
10759 | default_breakpoint_line, | |
68219205 | 10760 | (char ***) NULL, NULL); |
c906108c SS |
10761 | else |
10762 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 10763 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 10764 | if (*string) |
8a3fe4f8 | 10765 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
10766 | return sals; |
10767 | } | |
8181d85f DJ |
10768 | |
10769 | /* Create and insert a raw software breakpoint at PC. Return an | |
10770 | identifier, which should be used to remove the breakpoint later. | |
10771 | In general, places which call this should be using something on the | |
10772 | breakpoint chain instead; this function should be eliminated | |
10773 | someday. */ | |
10774 | ||
10775 | void * | |
6c95b8df PA |
10776 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
10777 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
10778 | { |
10779 | struct bp_target_info *bp_tgt; | |
10780 | ||
6c95b8df | 10781 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 10782 | |
6c95b8df | 10783 | bp_tgt->placed_address_space = aspace; |
8181d85f | 10784 | bp_tgt->placed_address = pc; |
6c95b8df | 10785 | |
a6d9a66e | 10786 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
10787 | { |
10788 | /* Could not insert the breakpoint. */ | |
10789 | xfree (bp_tgt); | |
10790 | return NULL; | |
10791 | } | |
10792 | ||
10793 | return bp_tgt; | |
10794 | } | |
10795 | ||
10796 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
10797 | ||
10798 | int | |
a6d9a66e | 10799 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
10800 | { |
10801 | struct bp_target_info *bp_tgt = bp; | |
10802 | int ret; | |
10803 | ||
a6d9a66e | 10804 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
10805 | xfree (bp_tgt); |
10806 | ||
10807 | return ret; | |
10808 | } | |
10809 | ||
10810 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
10811 | ||
10812 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 10813 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
10814 | |
10815 | /* Create and insert a breakpoint for software single step. */ | |
10816 | ||
10817 | void | |
6c95b8df PA |
10818 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
10819 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
10820 | { |
10821 | void **bpt_p; | |
10822 | ||
10823 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
10824 | { |
10825 | bpt_p = &single_step_breakpoints[0]; | |
10826 | single_step_gdbarch[0] = gdbarch; | |
10827 | } | |
8181d85f DJ |
10828 | else |
10829 | { | |
10830 | gdb_assert (single_step_breakpoints[1] == NULL); | |
10831 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 10832 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
10833 | } |
10834 | ||
10835 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
10836 | to only create the breakpoints once, and actually put them on the | |
10837 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
10838 | adjust the addresses each time they were needed. Doing this requires | |
10839 | corresponding changes elsewhere where single step breakpoints are | |
10840 | handled, however. So, for now, we use this. */ | |
10841 | ||
6c95b8df | 10842 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 10843 | if (*bpt_p == NULL) |
5af949e3 UW |
10844 | error (_("Could not insert single-step breakpoint at %s"), |
10845 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
10846 | } |
10847 | ||
f02253f1 HZ |
10848 | /* Check if the breakpoints used for software single stepping |
10849 | were inserted or not. */ | |
10850 | ||
10851 | int | |
10852 | single_step_breakpoints_inserted (void) | |
10853 | { | |
10854 | return (single_step_breakpoints[0] != NULL | |
10855 | || single_step_breakpoints[1] != NULL); | |
10856 | } | |
10857 | ||
8181d85f DJ |
10858 | /* Remove and delete any breakpoints used for software single step. */ |
10859 | ||
10860 | void | |
10861 | remove_single_step_breakpoints (void) | |
10862 | { | |
10863 | gdb_assert (single_step_breakpoints[0] != NULL); | |
10864 | ||
10865 | /* See insert_single_step_breakpoint for more about this deprecated | |
10866 | call. */ | |
a6d9a66e UW |
10867 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
10868 | single_step_breakpoints[0]); | |
10869 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
10870 | single_step_breakpoints[0] = NULL; |
10871 | ||
10872 | if (single_step_breakpoints[1] != NULL) | |
10873 | { | |
a6d9a66e UW |
10874 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
10875 | single_step_breakpoints[1]); | |
10876 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
10877 | single_step_breakpoints[1] = NULL; |
10878 | } | |
10879 | } | |
10880 | ||
d03285ec UW |
10881 | /* Delete software single step breakpoints without removing them from |
10882 | the inferior. This is intended to be used if the inferior's address | |
10883 | space where they were inserted is already gone, e.g. after exit or | |
10884 | exec. */ | |
10885 | ||
10886 | void | |
10887 | cancel_single_step_breakpoints (void) | |
10888 | { | |
10889 | int i; | |
10890 | ||
10891 | for (i = 0; i < 2; i++) | |
10892 | if (single_step_breakpoints[i]) | |
10893 | { | |
10894 | xfree (single_step_breakpoints[i]); | |
10895 | single_step_breakpoints[i] = NULL; | |
10896 | single_step_gdbarch[i] = NULL; | |
10897 | } | |
10898 | } | |
10899 | ||
10900 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
10901 | removing them. */ | |
10902 | ||
10903 | static void | |
10904 | detach_single_step_breakpoints (void) | |
10905 | { | |
10906 | int i; | |
10907 | ||
10908 | for (i = 0; i < 2; i++) | |
10909 | if (single_step_breakpoints[i]) | |
10910 | target_remove_breakpoint (single_step_gdbarch[i], | |
10911 | single_step_breakpoints[i]); | |
10912 | } | |
10913 | ||
1aafd4da UW |
10914 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
10915 | ||
10916 | static int | |
cc59ec59 MS |
10917 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
10918 | CORE_ADDR pc) | |
1aafd4da UW |
10919 | { |
10920 | int i; | |
10921 | ||
10922 | for (i = 0; i < 2; i++) | |
10923 | { | |
10924 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
10925 | if (bp_tgt |
10926 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
10927 | bp_tgt->placed_address, | |
10928 | aspace, pc)) | |
1aafd4da UW |
10929 | return 1; |
10930 | } | |
10931 | ||
10932 | return 0; | |
10933 | } | |
10934 | ||
a96d9b2e SDJ |
10935 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
10936 | non-zero otherwise. */ | |
10937 | static int | |
10938 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
10939 | { | |
10940 | if (syscall_catchpoint_p (bp) | |
10941 | && bp->enable_state != bp_disabled | |
10942 | && bp->enable_state != bp_call_disabled) | |
10943 | return 1; | |
10944 | else | |
10945 | return 0; | |
10946 | } | |
10947 | ||
10948 | int | |
10949 | catch_syscall_enabled (void) | |
10950 | { | |
10951 | struct inferior *inf = current_inferior (); | |
10952 | ||
10953 | return inf->total_syscalls_count != 0; | |
10954 | } | |
10955 | ||
10956 | int | |
10957 | catching_syscall_number (int syscall_number) | |
10958 | { | |
10959 | struct breakpoint *bp; | |
10960 | ||
10961 | ALL_BREAKPOINTS (bp) | |
10962 | if (is_syscall_catchpoint_enabled (bp)) | |
10963 | { | |
10964 | if (bp->syscalls_to_be_caught) | |
10965 | { | |
10966 | int i, iter; | |
10967 | for (i = 0; | |
10968 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
10969 | i++) | |
10970 | if (syscall_number == iter) | |
10971 | return 1; | |
10972 | } | |
10973 | else | |
10974 | return 1; | |
10975 | } | |
10976 | ||
10977 | return 0; | |
10978 | } | |
10979 | ||
10980 | /* Complete syscall names. Used by "catch syscall". */ | |
10981 | static char ** | |
10982 | catch_syscall_completer (struct cmd_list_element *cmd, | |
10983 | char *text, char *word) | |
10984 | { | |
10985 | const char **list = get_syscall_names (); | |
cc59ec59 | 10986 | |
a96d9b2e SDJ |
10987 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); |
10988 | } | |
10989 | ||
1042e4c0 SS |
10990 | /* Tracepoint-specific operations. */ |
10991 | ||
10992 | /* Set tracepoint count to NUM. */ | |
10993 | static void | |
10994 | set_tracepoint_count (int num) | |
10995 | { | |
10996 | tracepoint_count = num; | |
4fa62494 | 10997 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
10998 | } |
10999 | ||
11000 | void | |
11001 | trace_command (char *arg, int from_tty) | |
11002 | { | |
8cdf0e15 VP |
11003 | if (create_breakpoint (get_current_arch (), |
11004 | arg, | |
11005 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11006 | 0 /* tempflag */, |
11007 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11008 | 0 /* Ignore count */, |
11009 | pending_break_support, | |
11010 | NULL, | |
11011 | from_tty, | |
11012 | 1 /* enabled */)) | |
fd9b8c24 | 11013 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
11014 | } |
11015 | ||
7a697b8d SS |
11016 | void |
11017 | ftrace_command (char *arg, int from_tty) | |
11018 | { | |
8cdf0e15 VP |
11019 | if (create_breakpoint (get_current_arch (), |
11020 | arg, | |
11021 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
11022 | 0 /* tempflag */, |
11023 | bp_fast_tracepoint /* type_wanted */, | |
11024 | 0 /* Ignore count */, | |
11025 | pending_break_support, | |
11026 | NULL, | |
11027 | from_tty, | |
11028 | 1 /* enabled */)) | |
11029 | set_tracepoint_count (breakpoint_count); | |
11030 | } | |
11031 | ||
11032 | /* strace command implementation. Creates a static tracepoint. */ | |
11033 | ||
11034 | void | |
11035 | strace_command (char *arg, int from_tty) | |
11036 | { | |
11037 | if (create_breakpoint (get_current_arch (), | |
11038 | arg, | |
11039 | NULL, 0, 1 /* parse arg */, | |
11040 | 0 /* tempflag */, | |
11041 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
11042 | 0 /* Ignore count */, |
11043 | pending_break_support, | |
11044 | NULL, | |
11045 | from_tty, | |
11046 | 1 /* enabled */)) | |
fd9b8c24 | 11047 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
11048 | } |
11049 | ||
409873ef SS |
11050 | /* Set up a fake reader function that gets command lines from a linked |
11051 | list that was acquired during tracepoint uploading. */ | |
11052 | ||
11053 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 11054 | static int next_cmd; |
409873ef SS |
11055 | |
11056 | static char * | |
11057 | read_uploaded_action (void) | |
11058 | { | |
11059 | char *rslt; | |
11060 | ||
3149d8c1 | 11061 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 11062 | |
3149d8c1 | 11063 | next_cmd++; |
409873ef SS |
11064 | |
11065 | return rslt; | |
11066 | } | |
11067 | ||
00bf0b85 SS |
11068 | /* Given information about a tracepoint as recorded on a target (which |
11069 | can be either a live system or a trace file), attempt to create an | |
11070 | equivalent GDB tracepoint. This is not a reliable process, since | |
11071 | the target does not necessarily have all the information used when | |
11072 | the tracepoint was originally defined. */ | |
11073 | ||
11074 | struct breakpoint * | |
11075 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 11076 | { |
409873ef | 11077 | char *addr_str, small_buf[100]; |
d5551862 | 11078 | struct breakpoint *tp; |
fd9b8c24 | 11079 | |
409873ef SS |
11080 | if (utp->at_string) |
11081 | addr_str = utp->at_string; | |
11082 | else | |
11083 | { | |
11084 | /* In the absence of a source location, fall back to raw | |
11085 | address. Since there is no way to confirm that the address | |
11086 | means the same thing as when the trace was started, warn the | |
11087 | user. */ | |
11088 | warning (_("Uploaded tracepoint %d has no source location, using raw address"), | |
11089 | utp->number); | |
11090 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
11091 | addr_str = small_buf; | |
11092 | } | |
11093 | ||
11094 | /* There's not much we can do with a sequence of bytecodes. */ | |
11095 | if (utp->cond && !utp->cond_string) | |
11096 | warning (_("Uploaded tracepoint %d condition has no source form, ignoring it"), | |
11097 | utp->number); | |
d5551862 | 11098 | |
8cdf0e15 | 11099 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
11100 | addr_str, |
11101 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 11102 | 0 /* tempflag */, |
0fb4aa4b | 11103 | utp->type /* type_wanted */, |
8cdf0e15 VP |
11104 | 0 /* Ignore count */, |
11105 | pending_break_support, | |
11106 | NULL, | |
11107 | 0 /* from_tty */, | |
11108 | utp->enabled /* enabled */)) | |
fd9b8c24 PA |
11109 | return NULL; |
11110 | ||
00bf0b85 SS |
11111 | set_tracepoint_count (breakpoint_count); |
11112 | ||
409873ef | 11113 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
11114 | tp = get_tracepoint (tracepoint_count); |
11115 | gdb_assert (tp != NULL); | |
d5551862 | 11116 | |
00bf0b85 SS |
11117 | if (utp->pass > 0) |
11118 | { | |
409873ef | 11119 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 11120 | |
409873ef | 11121 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
11122 | } |
11123 | ||
409873ef SS |
11124 | /* If we have uploaded versions of the original commands, set up a |
11125 | special-purpose "reader" function and call the usual command line | |
11126 | reader, then pass the result to the breakpoint command-setting | |
11127 | function. */ | |
3149d8c1 | 11128 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 11129 | { |
409873ef | 11130 | struct command_line *cmd_list; |
00bf0b85 | 11131 | |
409873ef | 11132 | this_utp = utp; |
3149d8c1 | 11133 | next_cmd = 0; |
d5551862 | 11134 | |
409873ef SS |
11135 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
11136 | ||
11137 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 11138 | } |
3149d8c1 SS |
11139 | else if (!VEC_empty (char_ptr, utp->actions) |
11140 | || !VEC_empty (char_ptr, utp->step_actions)) | |
409873ef SS |
11141 | warning (_("Uploaded tracepoint %d actions have no source form, ignoring them"), |
11142 | utp->number); | |
00bf0b85 SS |
11143 | |
11144 | return tp; | |
11145 | } | |
11146 | ||
1042e4c0 SS |
11147 | /* Print information on tracepoint number TPNUM_EXP, or all if |
11148 | omitted. */ | |
11149 | ||
11150 | static void | |
11151 | tracepoints_info (char *tpnum_exp, int from_tty) | |
11152 | { | |
d77f58be SS |
11153 | int tpnum = -1, num_printed; |
11154 | ||
11155 | if (tpnum_exp) | |
11156 | tpnum = parse_and_eval_long (tpnum_exp); | |
1042e4c0 | 11157 | |
d77f58be SS |
11158 | num_printed = breakpoint_1 (tpnum, 0, is_tracepoint); |
11159 | ||
11160 | if (num_printed == 0) | |
1042e4c0 | 11161 | { |
d77f58be SS |
11162 | if (tpnum == -1) |
11163 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
11164 | else | |
11165 | ui_out_message (uiout, 0, "No tracepoint number %d.\n", tpnum); | |
1042e4c0 | 11166 | } |
ad443146 SS |
11167 | |
11168 | default_collect_info (); | |
1042e4c0 SS |
11169 | } |
11170 | ||
11171 | /* The 'enable trace' command enables tracepoints. | |
11172 | Not supported by all targets. */ | |
11173 | static void | |
11174 | enable_trace_command (char *args, int from_tty) | |
11175 | { | |
11176 | enable_command (args, from_tty); | |
11177 | } | |
11178 | ||
11179 | /* The 'disable trace' command disables tracepoints. | |
11180 | Not supported by all targets. */ | |
11181 | static void | |
11182 | disable_trace_command (char *args, int from_tty) | |
11183 | { | |
11184 | disable_command (args, from_tty); | |
11185 | } | |
11186 | ||
11187 | /* Remove a tracepoint (or all if no argument) */ | |
11188 | static void | |
11189 | delete_trace_command (char *arg, int from_tty) | |
11190 | { | |
11191 | struct breakpoint *b, *temp; | |
11192 | ||
11193 | dont_repeat (); | |
11194 | ||
11195 | if (arg == 0) | |
11196 | { | |
11197 | int breaks_to_delete = 0; | |
11198 | ||
11199 | /* Delete all breakpoints if no argument. | |
11200 | Do not delete internal or call-dummy breakpoints, these | |
11201 | have to be deleted with an explicit breakpoint number argument. */ | |
11202 | ALL_TRACEPOINTS (b) | |
11203 | { | |
11204 | if (b->number >= 0) | |
11205 | { | |
11206 | breaks_to_delete = 1; | |
11207 | break; | |
11208 | } | |
11209 | } | |
11210 | ||
11211 | /* Ask user only if there are some breakpoints to delete. */ | |
11212 | if (!from_tty | |
11213 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
11214 | { | |
11215 | ALL_BREAKPOINTS_SAFE (b, temp) | |
11216 | { | |
d77f58be | 11217 | if (is_tracepoint (b) |
059fb39f | 11218 | && b->number >= 0) |
1042e4c0 SS |
11219 | delete_breakpoint (b); |
11220 | } | |
11221 | } | |
11222 | } | |
11223 | else | |
95a42b64 | 11224 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
11225 | } |
11226 | ||
11227 | /* Set passcount for tracepoint. | |
11228 | ||
11229 | First command argument is passcount, second is tracepoint number. | |
11230 | If tracepoint number omitted, apply to most recently defined. | |
11231 | Also accepts special argument "all". */ | |
11232 | ||
11233 | static void | |
11234 | trace_pass_command (char *args, int from_tty) | |
11235 | { | |
11236 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
11237 | unsigned int count; | |
11238 | int all = 0; | |
11239 | ||
11240 | if (args == 0 || *args == 0) | |
11241 | error (_("passcount command requires an argument (count + optional TP num)")); | |
11242 | ||
11243 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
11244 | ||
11245 | while (*args && isspace ((int) *args)) | |
11246 | args++; | |
11247 | ||
11248 | if (*args && strncasecmp (args, "all", 3) == 0) | |
11249 | { | |
11250 | args += 3; /* Skip special argument "all". */ | |
11251 | all = 1; | |
11252 | if (*args) | |
11253 | error (_("Junk at end of arguments.")); | |
11254 | } | |
11255 | else | |
11256 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
11257 | ||
11258 | do | |
11259 | { | |
11260 | if (t1) | |
11261 | { | |
11262 | ALL_TRACEPOINTS (t2) | |
11263 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
11264 | { | |
11265 | t2->pass_count = count; | |
11266 | observer_notify_tracepoint_modified (t2->number); | |
11267 | if (from_tty) | |
11268 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
11269 | t2->number, count); | |
11270 | } | |
11271 | if (! all && *args) | |
11272 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
11273 | } | |
11274 | } | |
11275 | while (*args); | |
11276 | } | |
11277 | ||
11278 | struct breakpoint * | |
11279 | get_tracepoint (int num) | |
11280 | { | |
11281 | struct breakpoint *t; | |
11282 | ||
11283 | ALL_TRACEPOINTS (t) | |
11284 | if (t->number == num) | |
11285 | return t; | |
11286 | ||
11287 | return NULL; | |
11288 | } | |
11289 | ||
d5551862 SS |
11290 | /* Find the tracepoint with the given target-side number (which may be |
11291 | different from the tracepoint number after disconnecting and | |
11292 | reconnecting). */ | |
11293 | ||
11294 | struct breakpoint * | |
11295 | get_tracepoint_by_number_on_target (int num) | |
11296 | { | |
11297 | struct breakpoint *t; | |
11298 | ||
11299 | ALL_TRACEPOINTS (t) | |
11300 | if (t->number_on_target == num) | |
11301 | return t; | |
11302 | ||
11303 | return NULL; | |
11304 | } | |
11305 | ||
1042e4c0 SS |
11306 | /* Utility: parse a tracepoint number and look it up in the list. |
11307 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
11308 | if OPTIONAL_P is true, then if the argument is missing, the most | |
11309 | recent tracepoint (tracepoint_count) is returned. */ | |
11310 | struct breakpoint * | |
11311 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
11312 | { | |
11313 | extern int tracepoint_count; | |
11314 | struct breakpoint *t; | |
11315 | int tpnum; | |
11316 | char *instring = arg == NULL ? NULL : *arg; | |
11317 | ||
11318 | if (arg == NULL || *arg == NULL || ! **arg) | |
11319 | { | |
11320 | if (optional_p) | |
11321 | tpnum = tracepoint_count; | |
11322 | else | |
11323 | error_no_arg (_("tracepoint number")); | |
11324 | } | |
11325 | else | |
11326 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
11327 | ||
11328 | if (tpnum <= 0) | |
11329 | { | |
11330 | if (instring && *instring) | |
11331 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
11332 | instring); | |
11333 | else | |
11334 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
11335 | return NULL; | |
11336 | } | |
11337 | ||
11338 | ALL_TRACEPOINTS (t) | |
11339 | if (t->number == tpnum) | |
11340 | { | |
11341 | return t; | |
11342 | } | |
11343 | ||
11344 | /* FIXME: if we are in the middle of a range we don't want to give | |
11345 | a message. The current interface to get_number_or_range doesn't | |
11346 | allow us to discover this. */ | |
11347 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
11348 | return NULL; | |
11349 | } | |
11350 | ||
6149aea9 PA |
11351 | /* Save information on user settable breakpoints (watchpoints, etc) to |
11352 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
11353 | on each breakpoint and only include the ones for which it returns | |
11354 | non-zero. */ | |
11355 | ||
1042e4c0 | 11356 | static void |
6149aea9 PA |
11357 | save_breakpoints (char *filename, int from_tty, |
11358 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
11359 | { |
11360 | struct breakpoint *tp; | |
6149aea9 | 11361 | int any = 0; |
a7bdde9e | 11362 | char *pathname; |
1042e4c0 | 11363 | struct cleanup *cleanup; |
a7bdde9e | 11364 | struct ui_file *fp; |
6149aea9 | 11365 | int extra_trace_bits = 0; |
1042e4c0 | 11366 | |
6149aea9 PA |
11367 | if (filename == 0 || *filename == 0) |
11368 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
11369 | |
11370 | /* See if we have anything to save. */ | |
6149aea9 | 11371 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11372 | { |
6149aea9 PA |
11373 | /* Skip internal and momentary breakpoints. */ |
11374 | if (!user_settable_breakpoint (tp)) | |
11375 | continue; | |
11376 | ||
11377 | /* If we have a filter, only save the breakpoints it accepts. */ | |
11378 | if (filter && !filter (tp)) | |
11379 | continue; | |
11380 | ||
11381 | any = 1; | |
11382 | ||
11383 | if (is_tracepoint (tp)) | |
11384 | { | |
11385 | extra_trace_bits = 1; | |
11386 | ||
11387 | /* We can stop searching. */ | |
11388 | break; | |
11389 | } | |
1042e4c0 | 11390 | } |
6149aea9 PA |
11391 | |
11392 | if (!any) | |
1042e4c0 | 11393 | { |
6149aea9 | 11394 | warning (_("Nothing to save.")); |
1042e4c0 SS |
11395 | return; |
11396 | } | |
11397 | ||
6149aea9 | 11398 | pathname = tilde_expand (filename); |
1042e4c0 | 11399 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 11400 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 11401 | if (!fp) |
6149aea9 PA |
11402 | error (_("Unable to open file '%s' for saving (%s)"), |
11403 | filename, safe_strerror (errno)); | |
a7bdde9e | 11404 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 11405 | |
6149aea9 PA |
11406 | if (extra_trace_bits) |
11407 | save_trace_state_variables (fp); | |
8bf6485c | 11408 | |
6149aea9 | 11409 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 11410 | { |
6149aea9 PA |
11411 | /* Skip internal and momentary breakpoints. */ |
11412 | if (!user_settable_breakpoint (tp)) | |
11413 | continue; | |
8bf6485c | 11414 | |
6149aea9 PA |
11415 | /* If we have a filter, only save the breakpoints it accepts. */ |
11416 | if (filter && !filter (tp)) | |
11417 | continue; | |
11418 | ||
11419 | if (tp->ops != NULL) | |
11420 | (tp->ops->print_recreate) (tp, fp); | |
1042e4c0 SS |
11421 | else |
11422 | { | |
6149aea9 PA |
11423 | if (tp->type == bp_fast_tracepoint) |
11424 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
11425 | if (tp->type == bp_static_tracepoint) |
11426 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
11427 | else if (tp->type == bp_tracepoint) |
11428 | fprintf_unfiltered (fp, "trace"); | |
11429 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
11430 | fprintf_unfiltered (fp, "tbreak"); | |
11431 | else if (tp->type == bp_breakpoint) | |
11432 | fprintf_unfiltered (fp, "break"); | |
11433 | else if (tp->type == bp_hardware_breakpoint | |
11434 | && tp->disposition == disp_del) | |
11435 | fprintf_unfiltered (fp, "thbreak"); | |
11436 | else if (tp->type == bp_hardware_breakpoint) | |
11437 | fprintf_unfiltered (fp, "hbreak"); | |
11438 | else if (tp->type == bp_watchpoint) | |
11439 | fprintf_unfiltered (fp, "watch"); | |
11440 | else if (tp->type == bp_hardware_watchpoint) | |
11441 | fprintf_unfiltered (fp, "watch"); | |
11442 | else if (tp->type == bp_read_watchpoint) | |
11443 | fprintf_unfiltered (fp, "rwatch"); | |
11444 | else if (tp->type == bp_access_watchpoint) | |
11445 | fprintf_unfiltered (fp, "awatch"); | |
11446 | else | |
11447 | internal_error (__FILE__, __LINE__, | |
11448 | _("unhandled breakpoint type %d"), (int) tp->type); | |
11449 | ||
11450 | if (tp->exp_string) | |
11451 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
11452 | else if (tp->addr_string) | |
11453 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
11454 | else | |
11455 | { | |
11456 | char tmp[40]; | |
11457 | ||
11458 | sprintf_vma (tmp, tp->loc->address); | |
11459 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
11460 | } | |
1042e4c0 SS |
11461 | } |
11462 | ||
6149aea9 PA |
11463 | if (tp->thread != -1) |
11464 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
11465 | ||
11466 | if (tp->task != 0) | |
11467 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
11468 | |
11469 | fprintf_unfiltered (fp, "\n"); | |
11470 | ||
6149aea9 PA |
11471 | /* Note, we can't rely on tp->number for anything, as we can't |
11472 | assume the recreated breakpoint numbers will match. Use $bpnum | |
11473 | instead. */ | |
11474 | ||
11475 | if (tp->cond_string) | |
11476 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
11477 | ||
11478 | if (tp->ignore_count) | |
11479 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
11480 | ||
1042e4c0 | 11481 | if (tp->pass_count) |
a7bdde9e | 11482 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 11483 | |
a7bdde9e | 11484 | if (tp->commands) |
1042e4c0 | 11485 | { |
a7bdde9e VP |
11486 | volatile struct gdb_exception ex; |
11487 | ||
6149aea9 | 11488 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
11489 | |
11490 | ui_out_redirect (uiout, fp); | |
11491 | TRY_CATCH (ex, RETURN_MASK_ERROR) | |
1042e4c0 | 11492 | { |
9add0f1b | 11493 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
11494 | } |
11495 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 11496 | |
a7bdde9e VP |
11497 | if (ex.reason < 0) |
11498 | throw_exception (ex); | |
1042e4c0 | 11499 | |
a7bdde9e | 11500 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 11501 | } |
6149aea9 PA |
11502 | |
11503 | if (tp->enable_state == bp_disabled) | |
11504 | fprintf_unfiltered (fp, "disable\n"); | |
11505 | ||
11506 | /* If this is a multi-location breakpoint, check if the locations | |
11507 | should be individually disabled. Watchpoint locations are | |
11508 | special, and not user visible. */ | |
11509 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
11510 | { | |
11511 | struct bp_location *loc; | |
11512 | int n = 1; | |
11513 | ||
11514 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
11515 | if (!loc->enabled) | |
11516 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
11517 | } | |
1042e4c0 | 11518 | } |
8bf6485c | 11519 | |
6149aea9 | 11520 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
11521 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
11522 | ||
1042e4c0 SS |
11523 | do_cleanups (cleanup); |
11524 | if (from_tty) | |
6149aea9 PA |
11525 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
11526 | } | |
11527 | ||
11528 | /* The `save breakpoints' command. */ | |
11529 | ||
11530 | static void | |
11531 | save_breakpoints_command (char *args, int from_tty) | |
11532 | { | |
11533 | save_breakpoints (args, from_tty, NULL); | |
11534 | } | |
11535 | ||
11536 | /* The `save tracepoints' command. */ | |
11537 | ||
11538 | static void | |
11539 | save_tracepoints_command (char *args, int from_tty) | |
11540 | { | |
11541 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
11542 | } |
11543 | ||
11544 | /* Create a vector of all tracepoints. */ | |
11545 | ||
11546 | VEC(breakpoint_p) * | |
11547 | all_tracepoints () | |
11548 | { | |
11549 | VEC(breakpoint_p) *tp_vec = 0; | |
11550 | struct breakpoint *tp; | |
11551 | ||
11552 | ALL_TRACEPOINTS (tp) | |
11553 | { | |
11554 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
11555 | } | |
11556 | ||
11557 | return tp_vec; | |
11558 | } | |
11559 | ||
c906108c | 11560 | \f |
31e2b00f AS |
11561 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
11562 | It is defined as a macro to prevent duplication. | |
11563 | COMMAND should be a string constant containing the name of the command. */ | |
11564 | #define BREAK_ARGS_HELP(command) \ | |
11565 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
11566 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
11567 | If a line number is specified, break at start of code for that line.\n\ | |
11568 | If a function is specified, break at start of code for that function.\n\ | |
11569 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
11570 | With no LOCATION, uses current execution address of the selected\n\ |
11571 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
11572 | \n\ |
11573 | THREADNUM is the number from \"info threads\".\n\ | |
11574 | CONDITION is a boolean expression.\n\ | |
11575 | \n\ | |
d41c0fc8 PA |
11576 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
11577 | conditions are different.\n\ | |
31e2b00f AS |
11578 | \n\ |
11579 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
11580 | ||
44feb3ce TT |
11581 | /* List of subcommands for "catch". */ |
11582 | static struct cmd_list_element *catch_cmdlist; | |
11583 | ||
11584 | /* List of subcommands for "tcatch". */ | |
11585 | static struct cmd_list_element *tcatch_cmdlist; | |
11586 | ||
11587 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
11588 | lists, and pass some additional user data to the command function. */ | |
11589 | static void | |
11590 | add_catch_command (char *name, char *docstring, | |
11591 | void (*sfunc) (char *args, int from_tty, | |
11592 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
11593 | char **(*completer) (struct cmd_list_element *cmd, |
11594 | char *text, char *word), | |
44feb3ce TT |
11595 | void *user_data_catch, |
11596 | void *user_data_tcatch) | |
11597 | { | |
11598 | struct cmd_list_element *command; | |
11599 | ||
11600 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
11601 | &catch_cmdlist); | |
11602 | set_cmd_sfunc (command, sfunc); | |
11603 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 11604 | set_cmd_completer (command, completer); |
44feb3ce TT |
11605 | |
11606 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
11607 | &tcatch_cmdlist); | |
11608 | set_cmd_sfunc (command, sfunc); | |
11609 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 11610 | set_cmd_completer (command, completer); |
44feb3ce TT |
11611 | } |
11612 | ||
6c95b8df | 11613 | static void |
a79b8f6e | 11614 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 11615 | { |
6c95b8df PA |
11616 | inf->total_syscalls_count = 0; |
11617 | inf->any_syscall_count = 0; | |
11618 | VEC_free (int, inf->syscalls_counts); | |
11619 | } | |
11620 | ||
6149aea9 PA |
11621 | static void |
11622 | save_command (char *arg, int from_tty) | |
11623 | { | |
11624 | printf_unfiltered (_("\ | |
11625 | \"save\" must be followed by the name of a save subcommand.\n")); | |
11626 | help_list (save_cmdlist, "save ", -1, gdb_stdout); | |
11627 | } | |
11628 | ||
c906108c | 11629 | void |
fba45db2 | 11630 | _initialize_breakpoint (void) |
c906108c SS |
11631 | { |
11632 | struct cmd_list_element *c; | |
11633 | ||
84acb35a | 11634 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 11635 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 11636 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 11637 | |
c906108c SS |
11638 | breakpoint_chain = 0; |
11639 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
11640 | before a breakpoint is set. */ | |
11641 | breakpoint_count = 0; | |
11642 | ||
1042e4c0 SS |
11643 | tracepoint_count = 0; |
11644 | ||
1bedd215 AC |
11645 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
11646 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
11647 | Usage is `ignore N COUNT'.")); | |
c906108c | 11648 | if (xdb_commands) |
c5aa993b | 11649 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 11650 | |
1bedd215 AC |
11651 | add_com ("commands", class_breakpoint, commands_command, _("\ |
11652 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
11653 | Give breakpoint number as argument after \"commands\".\n\ |
11654 | With no argument, the targeted breakpoint is the last one set.\n\ | |
11655 | The commands themselves follow starting on the next line.\n\ | |
11656 | Type a line containing \"end\" to indicate the end of them.\n\ | |
11657 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 11658 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 11659 | |
1bedd215 AC |
11660 | add_com ("condition", class_breakpoint, condition_command, _("\ |
11661 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 11662 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 11663 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 11664 | |
1bedd215 | 11665 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 11666 | Set a temporary breakpoint.\n\ |
c906108c SS |
11667 | Like \"break\" except the breakpoint is only temporary,\n\ |
11668 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
11669 | by using \"enable delete\" on the breakpoint number.\n\ |
11670 | \n" | |
11671 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 11672 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 11673 | |
1bedd215 | 11674 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 11675 | Set a hardware assisted breakpoint.\n\ |
c906108c | 11676 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
11677 | some target hardware may not have this support.\n\ |
11678 | \n" | |
11679 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 11680 | set_cmd_completer (c, location_completer); |
c906108c | 11681 | |
1bedd215 | 11682 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 11683 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 11684 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
11685 | so it will be deleted when hit.\n\ |
11686 | \n" | |
11687 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 11688 | set_cmd_completer (c, location_completer); |
c906108c | 11689 | |
1bedd215 AC |
11690 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
11691 | Enable some breakpoints.\n\ | |
c906108c SS |
11692 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
11693 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
11694 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 11695 | With a subcommand you can enable temporarily."), |
c906108c SS |
11696 | &enablelist, "enable ", 1, &cmdlist); |
11697 | if (xdb_commands) | |
1bedd215 AC |
11698 | add_com ("ab", class_breakpoint, enable_command, _("\ |
11699 | Enable some breakpoints.\n\ | |
c906108c SS |
11700 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
11701 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
11702 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 11703 | With a subcommand you can enable temporarily.")); |
c906108c SS |
11704 | |
11705 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
11706 | ||
84951ab5 | 11707 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 11708 | Enable some breakpoints.\n\ |
c906108c SS |
11709 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
11710 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 11711 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 11712 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 11713 | |
1a966eab AC |
11714 | add_cmd ("once", no_class, enable_once_command, _("\ |
11715 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
11716 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
11717 | &enablebreaklist); |
11718 | ||
1a966eab AC |
11719 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
11720 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
11721 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
11722 | &enablebreaklist); |
11723 | ||
1a966eab AC |
11724 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
11725 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
11726 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
11727 | &enablelist); |
11728 | ||
1a966eab AC |
11729 | add_cmd ("once", no_class, enable_once_command, _("\ |
11730 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
11731 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
11732 | &enablelist); |
11733 | ||
1bedd215 AC |
11734 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
11735 | Disable some breakpoints.\n\ | |
c906108c SS |
11736 | Arguments are breakpoint numbers with spaces in between.\n\ |
11737 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 11738 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
11739 | &disablelist, "disable ", 1, &cmdlist); |
11740 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
11741 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
11742 | if (xdb_commands) | |
1bedd215 AC |
11743 | add_com ("sb", class_breakpoint, disable_command, _("\ |
11744 | Disable some breakpoints.\n\ | |
c906108c SS |
11745 | Arguments are breakpoint numbers with spaces in between.\n\ |
11746 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 11747 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 11748 | |
1a966eab AC |
11749 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
11750 | Disable some breakpoints.\n\ | |
c906108c SS |
11751 | Arguments are breakpoint numbers with spaces in between.\n\ |
11752 | To disable all breakpoints, give no argument.\n\ | |
11753 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 11754 | This command may be abbreviated \"disable\"."), |
c906108c SS |
11755 | &disablelist); |
11756 | ||
1bedd215 AC |
11757 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
11758 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
11759 | Arguments are breakpoint numbers with spaces in between.\n\ |
11760 | To delete all breakpoints, give no argument.\n\ | |
11761 | \n\ | |
11762 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 11763 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
11764 | &deletelist, "delete ", 1, &cmdlist); |
11765 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 11766 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 11767 | if (xdb_commands) |
1bedd215 AC |
11768 | add_com ("db", class_breakpoint, delete_command, _("\ |
11769 | Delete some breakpoints.\n\ | |
c906108c | 11770 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 11771 | To delete all breakpoints, give no argument.\n")); |
c906108c | 11772 | |
1a966eab AC |
11773 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
11774 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
11775 | Arguments are breakpoint numbers with spaces in between.\n\ |
11776 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 11777 | This command may be abbreviated \"delete\"."), |
c906108c SS |
11778 | &deletelist); |
11779 | ||
1bedd215 AC |
11780 | add_com ("clear", class_breakpoint, clear_command, _("\ |
11781 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
11782 | Argument may be line number, function name, or \"*\" and an address.\n\ |
11783 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
11784 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
11785 | If an address is specified, breakpoints at that address are cleared.\n\ |
11786 | \n\ | |
11787 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
11788 | is executing in.\n\ |
11789 | \n\ | |
1bedd215 | 11790 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 11791 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 11792 | |
1bedd215 | 11793 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
11794 | Set breakpoint at specified line or function.\n" |
11795 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 11796 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 11797 | |
c906108c SS |
11798 | add_com_alias ("b", "break", class_run, 1); |
11799 | add_com_alias ("br", "break", class_run, 1); | |
11800 | add_com_alias ("bre", "break", class_run, 1); | |
11801 | add_com_alias ("brea", "break", class_run, 1); | |
11802 | ||
7681d515 PM |
11803 | if (xdb_commands) |
11804 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
11805 | |
11806 | if (dbx_commands) | |
11807 | { | |
1bedd215 AC |
11808 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
11809 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
11810 | &stoplist, "stop ", 1, &cmdlist); |
11811 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 11812 | _("Break in function or address."), &stoplist); |
c5aa993b | 11813 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 11814 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
11815 | add_com ("status", class_info, breakpoints_info, _("\ |
11816 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11817 | The \"Type\" column indicates one of:\n\ |
11818 | \tbreakpoint - normal breakpoint\n\ | |
11819 | \twatchpoint - watchpoint\n\ | |
11820 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11821 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11822 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11823 | address and file/line number respectively.\n\ |
11824 | \n\ | |
11825 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11826 | are set to the address of the last breakpoint listed unless the command\n\ |
11827 | is prefixed with \"server \".\n\n\ | |
c906108c | 11828 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11829 | breakpoint set.")); |
c906108c SS |
11830 | } |
11831 | ||
1bedd215 AC |
11832 | add_info ("breakpoints", breakpoints_info, _("\ |
11833 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11834 | The \"Type\" column indicates one of:\n\ |
11835 | \tbreakpoint - normal breakpoint\n\ | |
11836 | \twatchpoint - watchpoint\n\ | |
11837 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11838 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11839 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11840 | address and file/line number respectively.\n\ |
11841 | \n\ | |
11842 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11843 | are set to the address of the last breakpoint listed unless the command\n\ |
11844 | is prefixed with \"server \".\n\n\ | |
c906108c | 11845 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11846 | breakpoint set.")); |
c906108c | 11847 | |
6b04bdb7 MS |
11848 | add_info_alias ("b", "breakpoints", 1); |
11849 | ||
c906108c | 11850 | if (xdb_commands) |
1bedd215 AC |
11851 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
11852 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11853 | The \"Type\" column indicates one of:\n\ |
11854 | \tbreakpoint - normal breakpoint\n\ | |
11855 | \twatchpoint - watchpoint\n\ | |
11856 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
11857 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
11858 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
11859 | address and file/line number respectively.\n\ |
11860 | \n\ | |
11861 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11862 | are set to the address of the last breakpoint listed unless the command\n\ |
11863 | is prefixed with \"server \".\n\n\ | |
c906108c | 11864 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 11865 | breakpoint set.")); |
c906108c | 11866 | |
1a966eab AC |
11867 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
11868 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
11869 | The \"Type\" column indicates one of:\n\ |
11870 | \tbreakpoint - normal breakpoint\n\ | |
11871 | \twatchpoint - watchpoint\n\ | |
11872 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
11873 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
11874 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
11875 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
11876 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
11877 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
11878 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
11879 | address and file/line number respectively.\n\ |
11880 | \n\ | |
11881 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
11882 | are set to the address of the last breakpoint listed unless the command\n\ |
11883 | is prefixed with \"server \".\n\n\ | |
c906108c | 11884 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 11885 | breakpoint set."), |
c906108c SS |
11886 | &maintenanceinfolist); |
11887 | ||
44feb3ce TT |
11888 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
11889 | Set catchpoints to catch events."), | |
11890 | &catch_cmdlist, "catch ", | |
11891 | 0/*allow-unknown*/, &cmdlist); | |
11892 | ||
11893 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
11894 | Set temporary catchpoints to catch events."), | |
11895 | &tcatch_cmdlist, "tcatch ", | |
11896 | 0/*allow-unknown*/, &cmdlist); | |
11897 | ||
11898 | /* Add catch and tcatch sub-commands. */ | |
11899 | add_catch_command ("catch", _("\ | |
11900 | Catch an exception, when caught.\n\ | |
11901 | With an argument, catch only exceptions with the given name."), | |
11902 | catch_catch_command, | |
a96d9b2e | 11903 | NULL, |
44feb3ce TT |
11904 | CATCH_PERMANENT, |
11905 | CATCH_TEMPORARY); | |
11906 | add_catch_command ("throw", _("\ | |
11907 | Catch an exception, when thrown.\n\ | |
11908 | With an argument, catch only exceptions with the given name."), | |
11909 | catch_throw_command, | |
a96d9b2e | 11910 | NULL, |
44feb3ce TT |
11911 | CATCH_PERMANENT, |
11912 | CATCH_TEMPORARY); | |
11913 | add_catch_command ("fork", _("Catch calls to fork."), | |
11914 | catch_fork_command_1, | |
a96d9b2e | 11915 | NULL, |
44feb3ce TT |
11916 | (void *) (uintptr_t) catch_fork_permanent, |
11917 | (void *) (uintptr_t) catch_fork_temporary); | |
11918 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
11919 | catch_fork_command_1, | |
a96d9b2e | 11920 | NULL, |
44feb3ce TT |
11921 | (void *) (uintptr_t) catch_vfork_permanent, |
11922 | (void *) (uintptr_t) catch_vfork_temporary); | |
11923 | add_catch_command ("exec", _("Catch calls to exec."), | |
11924 | catch_exec_command_1, | |
a96d9b2e SDJ |
11925 | NULL, |
11926 | CATCH_PERMANENT, | |
11927 | CATCH_TEMPORARY); | |
11928 | add_catch_command ("syscall", _("\ | |
11929 | Catch system calls by their names and/or numbers.\n\ | |
11930 | Arguments say which system calls to catch. If no arguments\n\ | |
11931 | are given, every system call will be caught.\n\ | |
11932 | Arguments, if given, should be one or more system call names\n\ | |
11933 | (if your system supports that), or system call numbers."), | |
11934 | catch_syscall_command_1, | |
11935 | catch_syscall_completer, | |
44feb3ce TT |
11936 | CATCH_PERMANENT, |
11937 | CATCH_TEMPORARY); | |
44feb3ce TT |
11938 | add_catch_command ("exception", _("\ |
11939 | Catch Ada exceptions, when raised.\n\ | |
11940 | With an argument, catch only exceptions with the given name."), | |
11941 | catch_ada_exception_command, | |
a96d9b2e | 11942 | NULL, |
44feb3ce TT |
11943 | CATCH_PERMANENT, |
11944 | CATCH_TEMPORARY); | |
11945 | add_catch_command ("assert", _("\ | |
11946 | Catch failed Ada assertions, when raised.\n\ | |
11947 | With an argument, catch only exceptions with the given name."), | |
11948 | catch_assert_command, | |
a96d9b2e | 11949 | NULL, |
44feb3ce TT |
11950 | CATCH_PERMANENT, |
11951 | CATCH_TEMPORARY); | |
c5aa993b | 11952 | |
1bedd215 AC |
11953 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
11954 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 11955 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 11956 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
11957 | an expression changes.\n\ |
11958 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
11959 | the memory to which it refers.")); | |
65d12d83 | 11960 | set_cmd_completer (c, expression_completer); |
c906108c | 11961 | |
1bedd215 AC |
11962 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
11963 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 11964 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 11965 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
11966 | an expression is read.\n\ |
11967 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
11968 | the memory to which it refers.")); | |
65d12d83 | 11969 | set_cmd_completer (c, expression_completer); |
c906108c | 11970 | |
1bedd215 AC |
11971 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
11972 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 11973 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 11974 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
11975 | an expression is either read or written.\n\ |
11976 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
11977 | the memory to which it refers.")); | |
65d12d83 | 11978 | set_cmd_completer (c, expression_completer); |
c906108c | 11979 | |
d77f58be SS |
11980 | add_info ("watchpoints", watchpoints_info, _("\ |
11981 | Status of watchpoints, or watchpoint number NUMBER.")); | |
11982 | ||
c906108c SS |
11983 | |
11984 | ||
920d2a44 AC |
11985 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
11986 | respond to changes - contrary to the description. */ | |
85c07804 AC |
11987 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
11988 | &can_use_hw_watchpoints, _("\ | |
11989 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
11990 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
11991 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
11992 | such is available. (However, any hardware watchpoints that were\n\ | |
11993 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
11994 | hardware.)"), |
11995 | NULL, | |
920d2a44 | 11996 | show_can_use_hw_watchpoints, |
85c07804 | 11997 | &setlist, &showlist); |
c906108c SS |
11998 | |
11999 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 12000 | |
1042e4c0 SS |
12001 | /* Tracepoint manipulation commands. */ |
12002 | ||
12003 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
12004 | Set a tracepoint at specified line or function.\n\ | |
12005 | \n" | |
12006 | BREAK_ARGS_HELP ("trace") "\n\ | |
12007 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12008 | set_cmd_completer (c, location_completer); | |
12009 | ||
12010 | add_com_alias ("tp", "trace", class_alias, 0); | |
12011 | add_com_alias ("tr", "trace", class_alias, 1); | |
12012 | add_com_alias ("tra", "trace", class_alias, 1); | |
12013 | add_com_alias ("trac", "trace", class_alias, 1); | |
12014 | ||
7a697b8d SS |
12015 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
12016 | Set a fast tracepoint at specified line or function.\n\ | |
12017 | \n" | |
12018 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
12019 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12020 | set_cmd_completer (c, location_completer); | |
12021 | ||
0fb4aa4b PA |
12022 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
12023 | Set a static tracepoint at specified line, function or marker.\n\ | |
12024 | \n\ | |
12025 | strace [LOCATION] [if CONDITION]\n\ | |
12026 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
12027 | or -m MARKER_ID.\n\ | |
12028 | If a line number is specified, probe the marker at start of code\n\ | |
12029 | for that line. If a function is specified, probe the marker at start\n\ | |
12030 | of code for that function. If an address is specified, probe the marker\n\ | |
12031 | at that exact address. If a marker id is specified, probe the marker\n\ | |
12032 | with that name. With no LOCATION, uses current execution address of\n\ | |
12033 | the selected stack frame.\n\ | |
12034 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
12035 | This collects arbitrary user data passed in the probe point call to the\n\ | |
12036 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
12037 | by printing the $_sdata variable like any other convenience variable.\n\ | |
12038 | \n\ | |
12039 | CONDITION is a boolean expression.\n\ | |
12040 | \n\ | |
d41c0fc8 PA |
12041 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
12042 | conditions are different.\n\ | |
0fb4aa4b PA |
12043 | \n\ |
12044 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
12045 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
12046 | set_cmd_completer (c, location_completer); | |
12047 | ||
1042e4c0 SS |
12048 | add_info ("tracepoints", tracepoints_info, _("\ |
12049 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
12050 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
12051 | last tracepoint set.")); | |
12052 | ||
12053 | add_info_alias ("tp", "tracepoints", 1); | |
12054 | ||
12055 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
12056 | Delete specified tracepoints.\n\ | |
12057 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12058 | No argument means delete all tracepoints."), | |
12059 | &deletelist); | |
12060 | ||
12061 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
12062 | Disable specified tracepoints.\n\ | |
12063 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12064 | No argument means disable all tracepoints."), | |
12065 | &disablelist); | |
12066 | deprecate_cmd (c, "disable"); | |
12067 | ||
12068 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
12069 | Enable specified tracepoints.\n\ | |
12070 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
12071 | No argument means enable all tracepoints."), | |
12072 | &enablelist); | |
12073 | deprecate_cmd (c, "enable"); | |
12074 | ||
12075 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
12076 | Set the passcount for a tracepoint.\n\ | |
12077 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
12078 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
12079 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
12080 | ||
6149aea9 PA |
12081 | add_prefix_cmd ("save", class_breakpoint, save_command, |
12082 | _("Save breakpoint definitions as a script."), | |
12083 | &save_cmdlist, "save ", | |
12084 | 0/*allow-unknown*/, &cmdlist); | |
12085 | ||
12086 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
12087 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 12088 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
12089 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
12090 | session to restore them."), | |
12091 | &save_cmdlist); | |
12092 | set_cmd_completer (c, filename_completer); | |
12093 | ||
12094 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 12095 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
12096 | Use the 'source' command in another debug session to restore them."), |
12097 | &save_cmdlist); | |
1042e4c0 SS |
12098 | set_cmd_completer (c, filename_completer); |
12099 | ||
6149aea9 PA |
12100 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
12101 | deprecate_cmd (c, "save tracepoints"); | |
12102 | ||
1bedd215 | 12103 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12104 | Breakpoint specific settings\n\ |
12105 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12106 | pending breakpoint behavior"), |
fa8d40ab JJ |
12107 | &breakpoint_set_cmdlist, "set breakpoint ", |
12108 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 12109 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
12110 | Breakpoint specific settings\n\ |
12111 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 12112 | pending breakpoint behavior"), |
fa8d40ab JJ |
12113 | &breakpoint_show_cmdlist, "show breakpoint ", |
12114 | 0/*allow-unknown*/, &showlist); | |
12115 | ||
7915a72c AC |
12116 | add_setshow_auto_boolean_cmd ("pending", no_class, |
12117 | &pending_break_support, _("\ | |
12118 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
12119 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
12120 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
12121 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
12122 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 12123 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 12124 | NULL, |
920d2a44 | 12125 | show_pending_break_support, |
6e1d7d6c AC |
12126 | &breakpoint_set_cmdlist, |
12127 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
12128 | |
12129 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
12130 | |
12131 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
12132 | &automatic_hardware_breakpoints, _("\ | |
12133 | Set automatic usage of hardware breakpoints."), _("\ | |
12134 | Show automatic usage of hardware breakpoints."), _("\ | |
12135 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
12136 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
12137 | a warning will be emitted for such breakpoints."), | |
12138 | NULL, | |
12139 | show_automatic_hardware_breakpoints, | |
12140 | &breakpoint_set_cmdlist, | |
12141 | &breakpoint_show_cmdlist); | |
74960c60 | 12142 | |
33e5cbd6 PA |
12143 | add_setshow_enum_cmd ("always-inserted", class_support, |
12144 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
12145 | Set mode for inserting breakpoints."), _("\ |
12146 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
12147 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
12148 | resumed, and removed when execution stops. When this mode is on,\n\ | |
12149 | breakpoints are inserted immediately and removed only when the user\n\ | |
12150 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
12151 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
12152 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
12153 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
12154 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
12155 | NULL, |
12156 | &show_always_inserted_mode, | |
12157 | &breakpoint_set_cmdlist, | |
12158 | &breakpoint_show_cmdlist); | |
765dc015 VP |
12159 | |
12160 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
12161 | |
12162 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 12163 | } |