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" |
c906108c | 64 | |
1042e4c0 SS |
65 | /* readline include files */ |
66 | #include "readline/readline.h" | |
67 | #include "readline/history.h" | |
68 | ||
69 | /* readline defines this. */ | |
70 | #undef savestring | |
71 | ||
034dad6f | 72 | #include "mi/mi-common.h" |
104c1213 | 73 | |
44feb3ce TT |
74 | /* Arguments to pass as context to some catch command handlers. */ |
75 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
76 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 77 | |
44feb3ce | 78 | /* Prototypes for local functions. */ |
c906108c | 79 | |
a14ed312 | 80 | static void enable_delete_command (char *, int); |
c906108c | 81 | |
a14ed312 | 82 | static void enable_delete_breakpoint (struct breakpoint *); |
c906108c | 83 | |
a14ed312 | 84 | static void enable_once_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void enable_once_breakpoint (struct breakpoint *); |
c906108c | 87 | |
a14ed312 | 88 | static void disable_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void enable_command (char *, int); |
c906108c | 91 | |
a14ed312 | 92 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
c906108c | 93 | |
a14ed312 | 94 | static void ignore_command (char *, int); |
c906108c | 95 | |
4efb68b1 | 96 | static int breakpoint_re_set_one (void *); |
c906108c | 97 | |
a14ed312 | 98 | static void clear_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void catch_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void watch_command (char *, int); |
c906108c | 103 | |
a14ed312 | 104 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 105 | |
98deb0da | 106 | static void break_command_1 (char *, int, int); |
c906108c | 107 | |
a14ed312 | 108 | static void mention (struct breakpoint *); |
c906108c | 109 | |
63c252f8 PM |
110 | /* This function is used in gdbtk sources and thus can not be made static. */ |
111 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, | |
a6d9a66e UW |
112 | struct symtab_and_line, |
113 | enum bptype); | |
c906108c | 114 | |
76897487 KB |
115 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
116 | ||
a6d9a66e UW |
117 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
118 | CORE_ADDR bpaddr, | |
88f7da05 | 119 | enum bptype bptype); |
76897487 | 120 | |
6c95b8df PA |
121 | static void describe_other_breakpoints (struct gdbarch *, |
122 | struct program_space *, CORE_ADDR, | |
5af949e3 | 123 | struct obj_section *, int); |
c906108c | 124 | |
6c95b8df PA |
125 | static int breakpoint_address_match (struct address_space *aspace1, |
126 | CORE_ADDR addr1, | |
127 | struct address_space *aspace2, | |
128 | CORE_ADDR addr2); | |
129 | ||
a14ed312 | 130 | static void breakpoints_info (char *, int); |
c906108c | 131 | |
a14ed312 | 132 | static void breakpoint_1 (int, int); |
c906108c | 133 | |
89f9893c | 134 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 135 | |
4efb68b1 | 136 | static int breakpoint_cond_eval (void *); |
c906108c | 137 | |
4efb68b1 | 138 | static void cleanup_executing_breakpoints (void *); |
c906108c | 139 | |
a14ed312 | 140 | static void commands_command (char *, int); |
c906108c | 141 | |
a14ed312 | 142 | static void condition_command (char *, int); |
c906108c | 143 | |
a14ed312 | 144 | static int get_number_trailer (char **, int); |
c906108c | 145 | |
a14ed312 | 146 | void set_breakpoint_count (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 watch_command_1 (char *, int, int); |
c906108c | 175 | |
a14ed312 | 176 | static void rwatch_command (char *, int); |
c906108c | 177 | |
a14ed312 | 178 | static void awatch_command (char *, int); |
c906108c | 179 | |
a14ed312 | 180 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 181 | |
a14ed312 | 182 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 183 | |
a14ed312 | 184 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 185 | |
a14ed312 | 186 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 187 | |
a14ed312 | 188 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 189 | |
d85310f7 MS |
190 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
191 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 192 | |
a14ed312 | 193 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 194 | |
a14ed312 | 195 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 196 | |
6c95b8df PA |
197 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
198 | CORE_ADDR pc); | |
1aafd4da | 199 | |
fe3f5fa8 VP |
200 | static void free_bp_location (struct bp_location *loc); |
201 | ||
39d61571 | 202 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 203 | |
b60e7edf | 204 | static void update_global_location_list (int); |
a5606eee | 205 | |
b60e7edf | 206 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
207 | |
208 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
209 | ||
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 | ||
3daf8fe5 JG |
224 | static void skip_prologue_sal (struct symtab_and_line *sal); |
225 | ||
226 | ||
f3b1572e PA |
227 | /* Flag indicating that a command has proceeded the inferior past the |
228 | current breakpoint. */ | |
229 | ||
230 | static int breakpoint_proceeded; | |
231 | ||
2cec12e5 AR |
232 | static const char * |
233 | bpdisp_text (enum bpdisp disp) | |
234 | { | |
235 | /* NOTE: the following values are a part of MI protocol and represent | |
236 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
237 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
238 | return bpdisps[(int) disp]; | |
239 | } | |
c906108c | 240 | |
2cec12e5 | 241 | /* Prototypes for exported functions. */ |
c906108c SS |
242 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
243 | if such is available. */ | |
244 | static int can_use_hw_watchpoints; | |
245 | ||
920d2a44 AC |
246 | static void |
247 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
248 | struct cmd_list_element *c, | |
249 | const char *value) | |
250 | { | |
251 | fprintf_filtered (file, _("\ | |
252 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
253 | value); | |
254 | } | |
255 | ||
fa8d40ab JJ |
256 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
257 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
258 | for unrecognized breakpoint locations. | |
259 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
260 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
261 | static void |
262 | show_pending_break_support (struct ui_file *file, int from_tty, | |
263 | struct cmd_list_element *c, | |
264 | const char *value) | |
265 | { | |
266 | fprintf_filtered (file, _("\ | |
267 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
268 | value); | |
269 | } | |
fa8d40ab | 270 | |
765dc015 VP |
271 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
272 | set with "break" but falling in read-only memory. | |
273 | If 0, gdb will warn about such breakpoints, but won't automatically | |
274 | use hardware breakpoints. */ | |
275 | static int automatic_hardware_breakpoints; | |
276 | static void | |
277 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
278 | struct cmd_list_element *c, | |
279 | const char *value) | |
280 | { | |
281 | fprintf_filtered (file, _("\ | |
282 | Automatic usage of hardware breakpoints is %s.\n"), | |
283 | value); | |
284 | } | |
285 | ||
33e5cbd6 PA |
286 | /* If on, gdb will keep breakpoints inserted even as inferior is |
287 | stopped, and immediately insert any new breakpoints. If off, gdb | |
288 | will insert breakpoints into inferior only when resuming it, and | |
289 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
290 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
291 | ||
292 | static const char always_inserted_auto[] = "auto"; | |
293 | static const char always_inserted_on[] = "on"; | |
294 | static const char always_inserted_off[] = "off"; | |
295 | static const char *always_inserted_enums[] = { | |
296 | always_inserted_auto, | |
297 | always_inserted_off, | |
298 | always_inserted_on, | |
299 | NULL | |
300 | }; | |
301 | static const char *always_inserted_mode = always_inserted_auto; | |
302 | static void | |
74960c60 | 303 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 304 | struct cmd_list_element *c, const char *value) |
74960c60 | 305 | { |
33e5cbd6 PA |
306 | if (always_inserted_mode == always_inserted_auto) |
307 | fprintf_filtered (file, _("\ | |
308 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
309 | value, | |
310 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
311 | else | |
312 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
313 | } |
314 | ||
33e5cbd6 PA |
315 | int |
316 | breakpoints_always_inserted_mode (void) | |
317 | { | |
318 | return (always_inserted_mode == always_inserted_on | |
319 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
320 | } | |
765dc015 | 321 | |
a14ed312 | 322 | void _initialize_breakpoint (void); |
c906108c | 323 | |
c906108c SS |
324 | /* Are we executing breakpoint commands? */ |
325 | static int executing_breakpoint_commands; | |
326 | ||
c02f5703 MS |
327 | /* Are overlay event breakpoints enabled? */ |
328 | static int overlay_events_enabled; | |
329 | ||
c906108c SS |
330 | /* Walk the following statement or block through all breakpoints. |
331 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
332 | breakpoint. */ | |
333 | ||
5c44784c | 334 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 335 | |
5c44784c JM |
336 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
337 | for (B = breakpoint_chain; \ | |
338 | B ? (TMP=B->next, 1): 0; \ | |
339 | B = TMP) | |
c906108c | 340 | |
876fa593 JK |
341 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
342 | provided so update_global_location_list must not be called while executing | |
343 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 344 | |
876fa593 JK |
345 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
346 | for (BP_TMP = bp_location; \ | |
347 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
348 | BP_TMP++) | |
7cc221ef | 349 | |
1042e4c0 SS |
350 | /* Iterator for tracepoints only. */ |
351 | ||
352 | #define ALL_TRACEPOINTS(B) \ | |
353 | for (B = breakpoint_chain; B; B = B->next) \ | |
7a697b8d | 354 | if (tracepoint_type (B)) |
1042e4c0 | 355 | |
7cc221ef | 356 | /* Chains of all breakpoints defined. */ |
c906108c SS |
357 | |
358 | struct breakpoint *breakpoint_chain; | |
359 | ||
876fa593 JK |
360 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
361 | ||
362 | static struct bp_location **bp_location; | |
363 | ||
364 | /* Number of elements of BP_LOCATION. */ | |
365 | ||
366 | static unsigned bp_location_count; | |
367 | ||
368 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
369 | for the current elements of BP_LOCATION which get a valid result from | |
370 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
371 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
372 | ||
373 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
374 | ||
375 | /* Maximum offset plus alignment between | |
376 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
377 | the current elements of BP_LOCATION which get a valid result from | |
378 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
379 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
380 | ||
381 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 382 | |
20874c92 | 383 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 384 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
385 | may still be reported by a target. */ |
386 | VEC(bp_location_p) *moribund_locations = NULL; | |
387 | ||
c906108c SS |
388 | /* Number of last breakpoint made. */ |
389 | ||
390 | int breakpoint_count; | |
391 | ||
1042e4c0 SS |
392 | /* Number of last tracepoint made. */ |
393 | ||
394 | int tracepoint_count; | |
395 | ||
468d015d JJ |
396 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
397 | static int | |
398 | breakpoint_enabled (struct breakpoint *b) | |
399 | { | |
0d381245 | 400 | return (b->enable_state == bp_enabled); |
468d015d JJ |
401 | } |
402 | ||
c906108c SS |
403 | /* Set breakpoint count to NUM. */ |
404 | ||
405 | void | |
fba45db2 | 406 | set_breakpoint_count (int num) |
c906108c SS |
407 | { |
408 | breakpoint_count = num; | |
4fa62494 | 409 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
410 | } |
411 | ||
412 | /* Used in run_command to zero the hit count when a new run starts. */ | |
413 | ||
414 | void | |
fba45db2 | 415 | clear_breakpoint_hit_counts (void) |
c906108c SS |
416 | { |
417 | struct breakpoint *b; | |
418 | ||
419 | ALL_BREAKPOINTS (b) | |
420 | b->hit_count = 0; | |
421 | } | |
422 | ||
7a697b8d SS |
423 | /* Encapsulate tests for different types of tracepoints. */ |
424 | ||
425 | static int | |
426 | tracepoint_type (const struct breakpoint *b) | |
427 | { | |
428 | return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint); | |
429 | } | |
430 | ||
c906108c SS |
431 | /* Default address, symtab and line to put a breakpoint at |
432 | for "break" command with no arg. | |
433 | if default_breakpoint_valid is zero, the other three are | |
434 | not valid, and "break" with no arg is an error. | |
435 | ||
436 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
437 | ||
438 | int default_breakpoint_valid; | |
439 | CORE_ADDR default_breakpoint_address; | |
440 | struct symtab *default_breakpoint_symtab; | |
441 | int default_breakpoint_line; | |
6c95b8df PA |
442 | struct program_space *default_breakpoint_pspace; |
443 | ||
c906108c SS |
444 | \f |
445 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
446 | Advance *PP after the string and any trailing whitespace. | |
447 | ||
448 | Currently the string can either be a number or "$" followed by the name | |
449 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 450 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
451 | |
452 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
453 | |
454 | TRAILER is a character which can be found after the number; most | |
455 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 456 | static int |
fba45db2 | 457 | get_number_trailer (char **pp, int trailer) |
c906108c | 458 | { |
5c44784c | 459 | int retval = 0; /* default */ |
c906108c SS |
460 | char *p = *pp; |
461 | ||
462 | if (p == NULL) | |
463 | /* Empty line means refer to the last breakpoint. */ | |
464 | return breakpoint_count; | |
465 | else if (*p == '$') | |
466 | { | |
467 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 468 | to pass to lookup_internalvar(). */ |
c906108c SS |
469 | char *varname; |
470 | char *start = ++p; | |
4fa62494 | 471 | LONGEST val; |
c906108c SS |
472 | |
473 | while (isalnum (*p) || *p == '_') | |
474 | p++; | |
475 | varname = (char *) alloca (p - start + 1); | |
476 | strncpy (varname, start, p - start); | |
477 | varname[p - start] = '\0'; | |
4fa62494 UW |
478 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
479 | retval = (int) val; | |
5c44784c JM |
480 | else |
481 | { | |
a3f17187 | 482 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
483 | retval = 0; |
484 | } | |
c906108c SS |
485 | } |
486 | else | |
487 | { | |
488 | if (*p == '-') | |
489 | ++p; | |
490 | while (*p >= '0' && *p <= '9') | |
491 | ++p; | |
492 | if (p == *pp) | |
493 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
494 | { |
495 | /* Skip non-numeric token */ | |
496 | while (*p && !isspace((int) *p)) | |
497 | ++p; | |
498 | /* Return zero, which caller must interpret as error. */ | |
499 | retval = 0; | |
500 | } | |
501 | else | |
502 | retval = atoi (*pp); | |
503 | } | |
504 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
505 | { | |
506 | /* Trailing junk: return 0 and let caller print error msg. */ | |
507 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
508 | ++p; | |
509 | retval = 0; | |
c906108c | 510 | } |
c906108c SS |
511 | while (isspace (*p)) |
512 | p++; | |
513 | *pp = p; | |
514 | return retval; | |
515 | } | |
5c44784c | 516 | |
11cf8741 | 517 | |
5c44784c JM |
518 | /* Like get_number_trailer, but don't allow a trailer. */ |
519 | int | |
fba45db2 | 520 | get_number (char **pp) |
5c44784c JM |
521 | { |
522 | return get_number_trailer (pp, '\0'); | |
523 | } | |
524 | ||
525 | /* Parse a number or a range. | |
526 | * A number will be of the form handled by get_number. | |
527 | * A range will be of the form <number1> - <number2>, and | |
528 | * will represent all the integers between number1 and number2, | |
529 | * inclusive. | |
530 | * | |
531 | * While processing a range, this fuction is called iteratively; | |
532 | * At each call it will return the next value in the range. | |
533 | * | |
534 | * At the beginning of parsing a range, the char pointer PP will | |
535 | * be advanced past <number1> and left pointing at the '-' token. | |
536 | * Subsequent calls will not advance the pointer until the range | |
537 | * is completed. The call that completes the range will advance | |
538 | * pointer PP past <number2>. | |
539 | */ | |
540 | ||
541 | int | |
fba45db2 | 542 | get_number_or_range (char **pp) |
5c44784c JM |
543 | { |
544 | static int last_retval, end_value; | |
545 | static char *end_ptr; | |
546 | static int in_range = 0; | |
547 | ||
548 | if (**pp != '-') | |
549 | { | |
550 | /* Default case: pp is pointing either to a solo number, | |
551 | or to the first number of a range. */ | |
552 | last_retval = get_number_trailer (pp, '-'); | |
553 | if (**pp == '-') | |
554 | { | |
555 | char **temp; | |
556 | ||
557 | /* This is the start of a range (<number1> - <number2>). | |
558 | Skip the '-', parse and remember the second number, | |
559 | and also remember the end of the final token. */ | |
560 | ||
561 | temp = &end_ptr; | |
562 | end_ptr = *pp + 1; | |
563 | while (isspace ((int) *end_ptr)) | |
564 | end_ptr++; /* skip white space */ | |
565 | end_value = get_number (temp); | |
566 | if (end_value < last_retval) | |
567 | { | |
8a3fe4f8 | 568 | error (_("inverted range")); |
5c44784c JM |
569 | } |
570 | else if (end_value == last_retval) | |
571 | { | |
572 | /* degenerate range (number1 == number2). Advance the | |
573 | token pointer so that the range will be treated as a | |
574 | single number. */ | |
575 | *pp = end_ptr; | |
576 | } | |
577 | else | |
578 | in_range = 1; | |
579 | } | |
580 | } | |
581 | else if (! in_range) | |
8a3fe4f8 | 582 | error (_("negative value")); |
5c44784c JM |
583 | else |
584 | { | |
585 | /* pp points to the '-' that betokens a range. All | |
586 | number-parsing has already been done. Return the next | |
587 | integer value (one greater than the saved previous value). | |
588 | Do not advance the token pointer 'pp' until the end of range | |
589 | is reached. */ | |
590 | ||
591 | if (++last_retval == end_value) | |
592 | { | |
593 | /* End of range reached; advance token pointer. */ | |
594 | *pp = end_ptr; | |
595 | in_range = 0; | |
596 | } | |
597 | } | |
598 | return last_retval; | |
599 | } | |
600 | ||
48cb2d85 VP |
601 | /* Return the breakpoint with the specified number, or NULL |
602 | if the number does not refer to an existing breakpoint. */ | |
603 | ||
604 | struct breakpoint * | |
605 | get_breakpoint (int num) | |
606 | { | |
607 | struct breakpoint *b; | |
608 | ||
609 | ALL_BREAKPOINTS (b) | |
610 | if (b->number == num) | |
611 | return b; | |
612 | ||
613 | return NULL; | |
614 | } | |
5c44784c | 615 | |
c906108c SS |
616 | \f |
617 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
618 | ||
619 | static void | |
fba45db2 | 620 | condition_command (char *arg, int from_tty) |
c906108c | 621 | { |
52f0bd74 | 622 | struct breakpoint *b; |
c906108c | 623 | char *p; |
52f0bd74 | 624 | int bnum; |
c906108c SS |
625 | |
626 | if (arg == 0) | |
e2e0b3e5 | 627 | error_no_arg (_("breakpoint number")); |
c906108c SS |
628 | |
629 | p = arg; | |
630 | bnum = get_number (&p); | |
5c44784c | 631 | if (bnum == 0) |
8a3fe4f8 | 632 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
633 | |
634 | ALL_BREAKPOINTS (b) | |
635 | if (b->number == bnum) | |
2f069f6f JB |
636 | { |
637 | struct bp_location *loc = b->loc; | |
638 | for (; loc; loc = loc->next) | |
639 | { | |
640 | if (loc->cond) | |
641 | { | |
642 | xfree (loc->cond); | |
643 | loc->cond = 0; | |
644 | } | |
645 | } | |
646 | if (b->cond_string != NULL) | |
647 | xfree (b->cond_string); | |
c906108c | 648 | |
2f069f6f JB |
649 | if (*p == 0) |
650 | { | |
651 | b->cond_string = NULL; | |
652 | if (from_tty) | |
653 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
654 | } | |
655 | else | |
656 | { | |
657 | arg = p; | |
658 | /* I don't know if it matters whether this is the string the user | |
659 | typed in or the decompiled expression. */ | |
1b36a34b | 660 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
661 | b->condition_not_parsed = 0; |
662 | for (loc = b->loc; loc; loc = loc->next) | |
663 | { | |
664 | arg = p; | |
665 | loc->cond = | |
666 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
667 | if (*arg) | |
668 | error (_("Junk at end of expression")); | |
669 | } | |
670 | } | |
671 | breakpoints_changed (); | |
383f836e | 672 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
673 | return; |
674 | } | |
c906108c | 675 | |
8a3fe4f8 | 676 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
677 | } |
678 | ||
48cb2d85 VP |
679 | /* Set the command list of B to COMMANDS. */ |
680 | ||
681 | void | |
682 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
683 | { | |
684 | free_command_lines (&b->commands); | |
685 | b->commands = commands; | |
686 | breakpoints_changed (); | |
687 | observer_notify_breakpoint_modified (b->number); | |
688 | } | |
689 | ||
c906108c | 690 | static void |
fba45db2 | 691 | commands_command (char *arg, int from_tty) |
c906108c | 692 | { |
52f0bd74 | 693 | struct breakpoint *b; |
c906108c | 694 | char *p; |
52f0bd74 | 695 | int bnum; |
c906108c SS |
696 | struct command_line *l; |
697 | ||
698 | /* If we allowed this, we would have problems with when to | |
699 | free the storage, if we change the commands currently | |
700 | being read from. */ | |
701 | ||
702 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 703 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
704 | |
705 | p = arg; | |
706 | bnum = get_number (&p); | |
5c44784c | 707 | |
c906108c | 708 | if (p && *p) |
8a3fe4f8 | 709 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 710 | |
c906108c SS |
711 | ALL_BREAKPOINTS (b) |
712 | if (b->number == bnum) | |
9ebf4acf AC |
713 | { |
714 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
715 | bnum); | |
716 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 717 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf | 718 | do_cleanups (cleanups); |
48cb2d85 | 719 | breakpoint_set_commands (b, l); |
9ebf4acf | 720 | return; |
c5aa993b | 721 | } |
8a3fe4f8 | 722 | error (_("No breakpoint number %d."), bnum); |
c906108c | 723 | } |
40c03ae8 EZ |
724 | |
725 | /* Like commands_command, but instead of reading the commands from | |
726 | input stream, takes them from an already parsed command structure. | |
727 | ||
728 | This is used by cli-script.c to DTRT with breakpoint commands | |
729 | that are part of if and while bodies. */ | |
730 | enum command_control_type | |
731 | commands_from_control_command (char *arg, struct command_line *cmd) | |
732 | { | |
733 | struct breakpoint *b; | |
734 | char *p; | |
735 | int bnum; | |
736 | ||
737 | /* If we allowed this, we would have problems with when to | |
738 | free the storage, if we change the commands currently | |
739 | being read from. */ | |
740 | ||
741 | if (executing_breakpoint_commands) | |
742 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
743 | ||
744 | /* An empty string for the breakpoint number means the last | |
745 | breakpoint, but get_number expects a NULL pointer. */ | |
746 | if (arg && !*arg) | |
747 | p = NULL; | |
748 | else | |
749 | p = arg; | |
750 | bnum = get_number (&p); | |
751 | ||
752 | if (p && *p) | |
753 | error (_("Unexpected extra arguments following breakpoint number.")); | |
754 | ||
755 | ALL_BREAKPOINTS (b) | |
756 | if (b->number == bnum) | |
757 | { | |
758 | free_command_lines (&b->commands); | |
759 | if (cmd->body_count != 1) | |
760 | error (_("Invalid \"commands\" block structure.")); | |
761 | /* We need to copy the commands because if/while will free the | |
762 | list after it finishes execution. */ | |
763 | b->commands = copy_command_lines (cmd->body_list[0]); | |
764 | breakpoints_changed (); | |
383f836e | 765 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 766 | return simple_control; |
2f069f6f | 767 | } |
40c03ae8 EZ |
768 | error (_("No breakpoint number %d."), bnum); |
769 | } | |
876fa593 JK |
770 | |
771 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
772 | ||
773 | static int | |
774 | bp_location_has_shadow (struct bp_location *bl) | |
775 | { | |
776 | if (bl->loc_type != bp_loc_software_breakpoint) | |
777 | return 0; | |
778 | if (!bl->inserted) | |
779 | return 0; | |
780 | if (bl->target_info.shadow_len == 0) | |
781 | /* bp isn't valid, or doesn't shadow memory. */ | |
782 | return 0; | |
783 | return 1; | |
784 | } | |
785 | ||
8defab1a | 786 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
787 | by replacing any memory breakpoints with their shadowed contents. |
788 | ||
789 | The range of shadowed area by each bp_location is: | |
790 | b->address - bp_location_placed_address_before_address_max | |
791 | up to b->address + bp_location_shadow_len_after_address_max | |
792 | The range we were requested to resolve shadows for is: | |
793 | memaddr ... memaddr + len | |
794 | Thus the safe cutoff boundaries for performance optimization are | |
795 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
796 | and: | |
797 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 798 | |
8defab1a DJ |
799 | void |
800 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 801 | { |
876fa593 JK |
802 | /* Left boundary, right boundary and median element of our binary search. */ |
803 | unsigned bc_l, bc_r, bc; | |
804 | ||
805 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
806 | safe to report lower value but a failure to report higher one. */ | |
807 | ||
808 | bc_l = 0; | |
809 | bc_r = bp_location_count; | |
810 | while (bc_l + 1 < bc_r) | |
811 | { | |
812 | struct bp_location *b; | |
813 | ||
814 | bc = (bc_l + bc_r) / 2; | |
815 | b = bp_location[bc]; | |
816 | ||
817 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
818 | Then advance the left boundary only if we are sure the BC element can | |
819 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
820 | ||
821 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
822 | we cannot miss a breakpoint with its shadow range tail still reaching | |
823 | MEMADDR. */ | |
c5aa993b | 824 | |
876fa593 JK |
825 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
826 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
827 | bc_l = bc; | |
828 | else | |
829 | bc_r = bc; | |
830 | } | |
831 | ||
832 | /* Now do full processing of the found relevant range of elements. */ | |
833 | ||
834 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 835 | { |
876fa593 JK |
836 | struct bp_location *b = bp_location[bc]; |
837 | CORE_ADDR bp_addr = 0; | |
838 | int bp_size = 0; | |
839 | int bptoffset = 0; | |
840 | ||
ffce0d52 | 841 | if (b->owner->type == bp_none) |
8a3fe4f8 | 842 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
843 | b->owner->number); |
844 | ||
876fa593 JK |
845 | /* Performance optimization: any futher element can no longer affect BUF |
846 | content. */ | |
847 | ||
848 | if (b->address >= bp_location_placed_address_before_address_max | |
849 | && memaddr + len <= b->address | |
850 | - bp_location_placed_address_before_address_max) | |
851 | break; | |
852 | ||
853 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 854 | continue; |
6c95b8df PA |
855 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
856 | current_program_space->aspace, 0)) | |
857 | continue; | |
858 | ||
c5aa993b JM |
859 | /* Addresses and length of the part of the breakpoint that |
860 | we need to copy. */ | |
8181d85f DJ |
861 | bp_addr = b->target_info.placed_address; |
862 | bp_size = b->target_info.shadow_len; | |
8defab1a | 863 | |
c5aa993b JM |
864 | if (bp_addr + bp_size <= memaddr) |
865 | /* The breakpoint is entirely before the chunk of memory we | |
866 | are reading. */ | |
867 | continue; | |
8defab1a | 868 | |
c5aa993b JM |
869 | if (bp_addr >= memaddr + len) |
870 | /* The breakpoint is entirely after the chunk of memory we are | |
871 | reading. */ | |
872 | continue; | |
c5aa993b | 873 | |
8defab1a DJ |
874 | /* Offset within shadow_contents. */ |
875 | if (bp_addr < memaddr) | |
876 | { | |
877 | /* Only copy the second part of the breakpoint. */ | |
878 | bp_size -= memaddr - bp_addr; | |
879 | bptoffset = memaddr - bp_addr; | |
880 | bp_addr = memaddr; | |
881 | } | |
c5aa993b | 882 | |
8defab1a DJ |
883 | if (bp_addr + bp_size > memaddr + len) |
884 | { | |
885 | /* Only copy the first part of the breakpoint. */ | |
886 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
887 | } | |
c5aa993b | 888 | |
8defab1a DJ |
889 | memcpy (buf + bp_addr - memaddr, |
890 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 891 | } |
c906108c | 892 | } |
c906108c | 893 | \f |
c5aa993b | 894 | |
687595f9 | 895 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 896 | static void |
687595f9 DJ |
897 | insert_catchpoint (struct ui_out *uo, void *args) |
898 | { | |
899 | struct breakpoint *b = (struct breakpoint *) args; | |
900 | int val = -1; | |
901 | ||
fe798b75 JB |
902 | gdb_assert (b->type == bp_catchpoint); |
903 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
904 | ||
905 | b->ops->insert (b); | |
687595f9 DJ |
906 | } |
907 | ||
a5606eee VP |
908 | static int |
909 | is_hardware_watchpoint (struct breakpoint *bpt) | |
910 | { | |
911 | return (bpt->type == bp_hardware_watchpoint | |
912 | || bpt->type == bp_read_watchpoint | |
913 | || bpt->type == bp_access_watchpoint); | |
914 | } | |
7270d8f2 | 915 | |
fa4727a6 DJ |
916 | /* Find the current value of a watchpoint on EXP. Return the value in |
917 | *VALP and *RESULTP and the chain of intermediate and final values | |
918 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
919 | not need them. | |
920 | ||
ccc57cf9 | 921 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
922 | be set to NULL. *RESULTP may be a lazy value, if the result could |
923 | not be read from memory. It is used to determine whether a value | |
924 | is user-specified (we should watch the whole value) or intermediate | |
925 | (we should watch only the bit used to locate the final value). | |
926 | ||
927 | If the final value, or any intermediate value, could not be read | |
928 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
929 | set to any referenced values. *VALP will never be a lazy value. | |
930 | This is the value which we store in struct breakpoint. | |
931 | ||
932 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
933 | value chain. The caller must free the values individually. If | |
934 | VAL_CHAIN is NULL, all generated values will be left on the value | |
935 | chain. */ | |
936 | ||
937 | static void | |
938 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
939 | struct value **resultp, struct value **val_chain) | |
940 | { | |
941 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 942 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
943 | |
944 | *valp = NULL; | |
945 | if (resultp) | |
946 | *resultp = NULL; | |
947 | if (val_chain) | |
948 | *val_chain = NULL; | |
949 | ||
950 | /* Evaluate the expression. */ | |
951 | mark = value_mark (); | |
952 | result = NULL; | |
ccc57cf9 PA |
953 | |
954 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
955 | { | |
956 | result = evaluate_expression (exp); | |
957 | } | |
958 | if (ex.reason < 0) | |
959 | { | |
960 | /* Ignore memory errors, we want watchpoints pointing at | |
961 | inaccessible memory to still be created; otherwise, throw the | |
962 | error to some higher catcher. */ | |
963 | switch (ex.error) | |
964 | { | |
965 | case MEMORY_ERROR: | |
966 | break; | |
967 | default: | |
968 | throw_exception (ex); | |
969 | break; | |
970 | } | |
971 | } | |
972 | ||
fa4727a6 DJ |
973 | new_mark = value_mark (); |
974 | if (mark == new_mark) | |
975 | return; | |
976 | if (resultp) | |
977 | *resultp = result; | |
978 | ||
979 | /* Make sure it's not lazy, so that after the target stops again we | |
980 | have a non-lazy previous value to compare with. */ | |
981 | if (result != NULL | |
982 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
983 | *valp = result; | |
984 | ||
985 | if (val_chain) | |
986 | { | |
987 | /* Return the chain of intermediate values. We use this to | |
988 | decide which addresses to watch. */ | |
989 | *val_chain = new_mark; | |
990 | value_release_to_mark (mark); | |
991 | } | |
992 | } | |
993 | ||
f6bc2008 PA |
994 | /* Assuming that B is a watchpoint: returns true if the current thread |
995 | and its running state are safe to evaluate or update watchpoint B. | |
996 | Watchpoints on local expressions need to be evaluated in the | |
997 | context of the thread that was current when the watchpoint was | |
998 | created, and, that thread needs to be stopped to be able to select | |
999 | the correct frame context. Watchpoints on global expressions can | |
1000 | be evaluated on any thread, and in any state. It is presently left | |
1001 | to the target allowing memory accesses when threads are | |
1002 | running. */ | |
1003 | ||
1004 | static int | |
1005 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1006 | { | |
1007 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1008 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1009 | && !is_executing (inferior_ptid))); | |
1010 | } | |
1011 | ||
567e1b4e JB |
1012 | /* Assuming that B is a watchpoint: |
1013 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1014 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1015 | - Evaluate the condition if there is one, and store the result |
1016 | in b->loc->cond. | |
a5606eee VP |
1017 | - Update the list of values that must be watched in B->loc. |
1018 | ||
bfa149ac | 1019 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1020 | If this is local watchpoint that is out of scope, delete it. |
1021 | ||
1022 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1023 | + inserted on each stop here. Normal breakpoints must never be removed | |
1024 | because they might be missed by a running thread when debugging in non-stop | |
1025 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1026 | processed here) are specific to each LWP since they are stored in each LWP's | |
1027 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1028 | order to be able to modify its hardware watchpoints. | |
1029 | ||
1030 | Hardware watchpoints must be reset exactly once after being presented to the | |
1031 | user. It cannot be done sooner, because it would reset the data used to | |
1032 | present the watchpoint hit to the user. And it must not be done later | |
1033 | because it could display the same single watchpoint hit during multiple GDB | |
1034 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1035 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1036 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1037 | memory content has not changed. | |
1038 | ||
1039 | The following constraints influence the location where we can reset hardware | |
1040 | watchpoints: | |
1041 | ||
1042 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1043 | several times when GDB stops. | |
1044 | ||
1045 | [linux] | |
1046 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1047 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1048 | reason for stopping, and all the other hits are presented later, one after | |
1049 | the other, each time the user requests the execution to be resumed. | |
1050 | Execution is not resumed for the threads still having pending hit event | |
1051 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1052 | the inferior on the first stop the thread hit event is kept being reported | |
1053 | from its cached value by linux_nat_stopped_data_address until the real | |
1054 | thread resume happens after the watchpoint gets presented and thus its | |
1055 | LWP_INFO->STATUS gets reset. | |
1056 | ||
1057 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1058 | removal from inferior. */ | |
1059 | ||
b40ce68a | 1060 | static void |
a5606eee | 1061 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1062 | { |
a5606eee | 1063 | int within_current_scope; |
a5606eee VP |
1064 | struct frame_id saved_frame_id; |
1065 | struct bp_location *loc; | |
66076460 | 1066 | int frame_saved; |
a5606eee VP |
1067 | bpstat bs; |
1068 | ||
f6bc2008 PA |
1069 | /* If this is a local watchpoint, we only want to check if the |
1070 | watchpoint frame is in scope if the current thread is the thread | |
1071 | that was used to create the watchpoint. */ | |
1072 | if (!watchpoint_in_thread_scope (b)) | |
1073 | return; | |
1074 | ||
876fa593 | 1075 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1076 | update_global_locations will eventually delete them and remove |
1077 | breakpoints if needed. */ | |
a5606eee VP |
1078 | b->loc = NULL; |
1079 | ||
1080 | if (b->disposition == disp_del_at_next_stop) | |
1081 | return; | |
1082 | ||
66076460 | 1083 | frame_saved = 0; |
a5606eee VP |
1084 | |
1085 | /* Determine if the watchpoint is within scope. */ | |
1086 | if (b->exp_valid_block == NULL) | |
1087 | within_current_scope = 1; | |
1088 | else | |
1089 | { | |
1090 | struct frame_info *fi; | |
66076460 DJ |
1091 | |
1092 | /* Save the current frame's ID so we can restore it after | |
1093 | evaluating the watchpoint expression on its own frame. */ | |
1094 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1095 | took a frame parameter, so that we didn't have to change the | |
1096 | selected frame. */ | |
1097 | frame_saved = 1; | |
1098 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1099 | ||
a5606eee VP |
1100 | fi = frame_find_by_id (b->watchpoint_frame); |
1101 | within_current_scope = (fi != NULL); | |
1102 | if (within_current_scope) | |
1103 | select_frame (fi); | |
1104 | } | |
1105 | ||
1106 | if (within_current_scope && reparse) | |
1107 | { | |
1108 | char *s; | |
1109 | if (b->exp) | |
1110 | { | |
1111 | xfree (b->exp); | |
1112 | b->exp = NULL; | |
1113 | } | |
1114 | s = b->exp_string; | |
1115 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1116 | /* If the meaning of expression itself changed, the old value is | |
1117 | no longer relevant. We don't want to report a watchpoint hit | |
1118 | to the user when the old value and the new value may actually | |
1119 | be completely different objects. */ | |
1120 | value_free (b->val); | |
fa4727a6 DJ |
1121 | b->val = NULL; |
1122 | b->val_valid = 0; | |
a5606eee | 1123 | } |
a5606eee VP |
1124 | |
1125 | /* If we failed to parse the expression, for example because | |
1126 | it refers to a global variable in a not-yet-loaded shared library, | |
1127 | don't try to insert watchpoint. We don't automatically delete | |
1128 | such watchpoint, though, since failure to parse expression | |
1129 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1130 | if ( !target_has_execution) |
1131 | { | |
1132 | /* Without execution, memory can't change. No use to try and | |
1133 | set watchpoint locations. The watchpoint will be reset when | |
1134 | the target gains execution, through breakpoint_re_set. */ | |
1135 | } | |
1136 | else if (within_current_scope && b->exp) | |
a5606eee | 1137 | { |
fa4727a6 | 1138 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1139 | struct program_space *frame_pspace; |
a5606eee | 1140 | |
fa4727a6 | 1141 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1142 | |
a5606eee VP |
1143 | /* Avoid setting b->val if it's already set. The meaning of |
1144 | b->val is 'the last value' user saw, and we should update | |
1145 | it only if we reported that last value to user. As it | |
1146 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1147 | if (!b->val_valid) |
1148 | { | |
1149 | b->val = v; | |
1150 | b->val_valid = 1; | |
1151 | } | |
a5606eee | 1152 | |
db2ad4c3 JK |
1153 | /* Change the type of breakpoint between hardware assisted or an |
1154 | ordinary watchpoint depending on the hardware support and free | |
1155 | hardware slots. REPARSE is set when the inferior is started. */ | |
1156 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1157 | && reparse) | |
1158 | { | |
ca2d49e8 | 1159 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1160 | |
7b838ca2 TJB |
1161 | /* We need to determine how many resources are already used |
1162 | for all other hardware watchpoints to see if we still have | |
1163 | enough resources to also fit this watchpoint in as well. | |
1164 | To avoid the hw_watchpoint_used_count call below from counting | |
1165 | this watchpoint, make sure that it is marked as a software | |
1166 | watchpoint. */ | |
1167 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1168 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1169 | &other_type_used); | |
1170 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1171 | ||
ca2d49e8 | 1172 | if (!mem_cnt) |
db2ad4c3 JK |
1173 | b->type = bp_watchpoint; |
1174 | else | |
ca2d49e8 | 1175 | { |
d92524f1 | 1176 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1177 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1178 | if (target_resources_ok <= 0) | |
1179 | b->type = bp_watchpoint; | |
1180 | else | |
1181 | b->type = bp_hardware_watchpoint; | |
1182 | } | |
db2ad4c3 JK |
1183 | } |
1184 | ||
2d134ed3 PA |
1185 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1186 | ||
a5606eee | 1187 | /* Look at each value on the value chain. */ |
fa4727a6 | 1188 | for (v = val_chain; v; v = next) |
a5606eee VP |
1189 | { |
1190 | /* If it's a memory location, and GDB actually needed | |
1191 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1192 | must watch it. If the first value returned is |
1193 | still lazy, that means an error occurred reading it; | |
1194 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1195 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1196 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1197 | { |
1198 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1199 | |
a5606eee VP |
1200 | /* We only watch structs and arrays if user asked |
1201 | for it explicitly, never if they just happen to | |
1202 | appear in the middle of some value chain. */ | |
fa4727a6 | 1203 | if (v == result |
a5606eee VP |
1204 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1205 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1206 | { | |
1207 | CORE_ADDR addr; | |
1208 | int len, type; | |
1209 | struct bp_location *loc, **tmp; | |
1210 | ||
42ae5230 | 1211 | addr = value_address (v); |
a5606eee VP |
1212 | len = TYPE_LENGTH (value_type (v)); |
1213 | type = hw_write; | |
1214 | if (b->type == bp_read_watchpoint) | |
1215 | type = hw_read; | |
1216 | else if (b->type == bp_access_watchpoint) | |
1217 | type = hw_access; | |
1218 | ||
39d61571 | 1219 | loc = allocate_bp_location (b); |
a5606eee VP |
1220 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1221 | ; | |
1222 | *tmp = loc; | |
a6d9a66e | 1223 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1224 | |
1225 | loc->pspace = frame_pspace; | |
a5606eee VP |
1226 | loc->address = addr; |
1227 | loc->length = len; | |
1228 | loc->watchpoint_type = type; | |
1229 | } | |
1230 | } | |
1231 | ||
1232 | next = value_next (v); | |
1233 | if (v != b->val) | |
1234 | value_free (v); | |
1235 | } | |
1236 | ||
2ec93238 MK |
1237 | /* We just regenerated the list of breakpoint locations. |
1238 | The new location does not have its condition field set to anything | |
1239 | and therefore, we must always reparse the cond_string, independently | |
1240 | of the value of the reparse flag. */ | |
1241 | if (b->cond_string != NULL) | |
a5606eee VP |
1242 | { |
1243 | char *s = b->cond_string; | |
a5606eee VP |
1244 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1245 | } | |
1246 | } | |
1247 | else if (!within_current_scope) | |
7270d8f2 | 1248 | { |
a5606eee | 1249 | printf_filtered (_("\ |
567e1b4e | 1250 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1251 | in which its expression is valid.\n"), |
1252 | b->number); | |
1253 | if (b->related_breakpoint) | |
1254 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1255 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1256 | } |
a5606eee VP |
1257 | |
1258 | /* Restore the selected frame. */ | |
66076460 DJ |
1259 | if (frame_saved) |
1260 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1261 | } |
1262 | ||
a5606eee | 1263 | |
74960c60 VP |
1264 | /* Returns 1 iff breakpoint location should be |
1265 | inserted in the inferior. */ | |
1266 | static int | |
1267 | should_be_inserted (struct bp_location *bpt) | |
1268 | { | |
1269 | if (!breakpoint_enabled (bpt->owner)) | |
1270 | return 0; | |
1271 | ||
1272 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1273 | return 0; | |
1274 | ||
1275 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1276 | return 0; | |
1277 | ||
56710373 PA |
1278 | /* This is set for example, when we're attached to the parent of a |
1279 | vfork, and have detached from the child. The child is running | |
1280 | free, and we expect it to do an exec or exit, at which point the | |
1281 | OS makes the parent schedulable again (and the target reports | |
1282 | that the vfork is done). Until the child is done with the shared | |
1283 | memory region, do not insert breakpoints in the parent, otherwise | |
1284 | the child could still trip on the parent's breakpoints. Since | |
1285 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1286 | if (bpt->pspace->breakpoints_not_allowed) | |
1287 | return 0; | |
1288 | ||
1042e4c0 SS |
1289 | /* Tracepoints are inserted by the target at a time of its choosing, |
1290 | not by us. */ | |
7a697b8d | 1291 | if (tracepoint_type (bpt->owner)) |
1042e4c0 SS |
1292 | return 0; |
1293 | ||
74960c60 VP |
1294 | return 1; |
1295 | } | |
1296 | ||
879bfdc2 DJ |
1297 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1298 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1299 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1300 | |
1301 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1302 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1303 | static int |
879bfdc2 | 1304 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1305 | struct ui_file *tmp_error_stream, |
fa3a767f | 1306 | int *disabled_breaks, |
26bb91f3 | 1307 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1308 | { |
1309 | int val = 0; | |
1310 | ||
74960c60 | 1311 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1312 | return 0; |
1313 | ||
8181d85f DJ |
1314 | /* Initialize the target-specific information. */ |
1315 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1316 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1317 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1318 | |
879bfdc2 DJ |
1319 | if (bpt->loc_type == bp_loc_software_breakpoint |
1320 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1321 | { | |
765dc015 VP |
1322 | if (bpt->owner->type != bp_hardware_breakpoint) |
1323 | { | |
1324 | /* If the explicitly specified breakpoint type | |
1325 | is not hardware breakpoint, check the memory map to see | |
1326 | if the breakpoint address is in read only memory or not. | |
1327 | Two important cases are: | |
1328 | - location type is not hardware breakpoint, memory | |
1329 | is readonly. We change the type of the location to | |
1330 | hardware breakpoint. | |
1331 | - location type is hardware breakpoint, memory is read-write. | |
1332 | This means we've previously made the location hardware one, but | |
1333 | then the memory map changed, so we undo. | |
1334 | ||
1335 | When breakpoints are removed, remove_breakpoints will | |
1336 | use location types we've just set here, the only possible | |
1337 | problem is that memory map has changed during running program, | |
1338 | but it's not going to work anyway with current gdb. */ | |
1339 | struct mem_region *mr | |
1340 | = lookup_mem_region (bpt->target_info.placed_address); | |
1341 | ||
1342 | if (mr) | |
1343 | { | |
1344 | if (automatic_hardware_breakpoints) | |
1345 | { | |
1346 | int changed = 0; | |
1347 | enum bp_loc_type new_type; | |
1348 | ||
1349 | if (mr->attrib.mode != MEM_RW) | |
1350 | new_type = bp_loc_hardware_breakpoint; | |
1351 | else | |
1352 | new_type = bp_loc_software_breakpoint; | |
1353 | ||
1354 | if (new_type != bpt->loc_type) | |
1355 | { | |
1356 | static int said = 0; | |
1357 | bpt->loc_type = new_type; | |
1358 | if (!said) | |
1359 | { | |
1360 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1361 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1362 | said = 1; |
1363 | } | |
1364 | } | |
1365 | } | |
1366 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1367 | && mr->attrib.mode != MEM_RW) | |
1368 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1369 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1370 | } |
1371 | } | |
1372 | ||
879bfdc2 DJ |
1373 | /* First check to see if we have to handle an overlay. */ |
1374 | if (overlay_debugging == ovly_off | |
1375 | || bpt->section == NULL | |
1376 | || !(section_is_overlay (bpt->section))) | |
1377 | { | |
1378 | /* No overlay handling: just set the breakpoint. */ | |
1379 | ||
1380 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1381 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1382 | &bpt->target_info); | |
879bfdc2 | 1383 | else |
a6d9a66e UW |
1384 | val = target_insert_breakpoint (bpt->gdbarch, |
1385 | &bpt->target_info); | |
879bfdc2 DJ |
1386 | } |
1387 | else | |
1388 | { | |
1389 | /* This breakpoint is in an overlay section. | |
1390 | Shall we set a breakpoint at the LMA? */ | |
1391 | if (!overlay_events_enabled) | |
1392 | { | |
1393 | /* Yes -- overlay event support is not active, | |
1394 | so we must try to set a breakpoint at the LMA. | |
1395 | This will not work for a hardware breakpoint. */ | |
1396 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1397 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1398 | bpt->owner->number); |
1399 | else | |
1400 | { | |
1401 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1402 | bpt->section); | |
1403 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1404 | bpt->overlay_target_info = bpt->target_info; |
1405 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1406 | val = target_insert_breakpoint (bpt->gdbarch, |
1407 | &bpt->overlay_target_info); | |
879bfdc2 | 1408 | if (val != 0) |
99361f52 DE |
1409 | fprintf_unfiltered (tmp_error_stream, |
1410 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1411 | bpt->owner->number); |
1412 | } | |
1413 | } | |
1414 | /* Shall we set a breakpoint at the VMA? */ | |
1415 | if (section_is_mapped (bpt->section)) | |
1416 | { | |
1417 | /* Yes. This overlay section is mapped into memory. */ | |
1418 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1419 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1420 | &bpt->target_info); | |
879bfdc2 | 1421 | else |
a6d9a66e UW |
1422 | val = target_insert_breakpoint (bpt->gdbarch, |
1423 | &bpt->target_info); | |
879bfdc2 DJ |
1424 | } |
1425 | else | |
1426 | { | |
1427 | /* No. This breakpoint will not be inserted. | |
1428 | No error, but do not mark the bp as 'inserted'. */ | |
1429 | return 0; | |
1430 | } | |
1431 | } | |
1432 | ||
1433 | if (val) | |
1434 | { | |
1435 | /* Can't set the breakpoint. */ | |
6c95b8df | 1436 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1437 | { |
1438 | /* See also: disable_breakpoints_in_shlibs. */ | |
1439 | val = 0; | |
0d381245 | 1440 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1441 | if (!*disabled_breaks) |
1442 | { | |
1443 | fprintf_unfiltered (tmp_error_stream, | |
1444 | "Cannot insert breakpoint %d.\n", | |
1445 | bpt->owner->number); | |
1446 | fprintf_unfiltered (tmp_error_stream, | |
1447 | "Temporarily disabling shared library breakpoints:\n"); | |
1448 | } | |
1449 | *disabled_breaks = 1; | |
1450 | fprintf_unfiltered (tmp_error_stream, | |
1451 | "breakpoint #%d\n", bpt->owner->number); | |
1452 | } | |
1453 | else | |
879bfdc2 | 1454 | { |
879bfdc2 DJ |
1455 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1456 | { | |
1457 | *hw_breakpoint_error = 1; | |
1458 | fprintf_unfiltered (tmp_error_stream, | |
1459 | "Cannot insert hardware breakpoint %d.\n", | |
1460 | bpt->owner->number); | |
1461 | } | |
1462 | else | |
1463 | { | |
1464 | fprintf_unfiltered (tmp_error_stream, | |
1465 | "Cannot insert breakpoint %d.\n", | |
1466 | bpt->owner->number); | |
1467 | fprintf_filtered (tmp_error_stream, | |
1468 | "Error accessing memory address "); | |
5af949e3 UW |
1469 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1470 | tmp_error_stream); | |
879bfdc2 DJ |
1471 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1472 | safe_strerror (val)); | |
1473 | } | |
1474 | ||
1475 | } | |
1476 | } | |
1477 | else | |
1478 | bpt->inserted = 1; | |
1479 | ||
1480 | return val; | |
1481 | } | |
1482 | ||
1483 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1484 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1485 | watchpoints. It's not clear that it's necessary... */ | |
1486 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1487 | { | |
a5606eee VP |
1488 | val = target_insert_watchpoint (bpt->address, |
1489 | bpt->length, | |
1490 | bpt->watchpoint_type); | |
1491 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1492 | } |
1493 | ||
fe798b75 | 1494 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1495 | { |
71fff37b AC |
1496 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1497 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1498 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1499 | bpt->owner->number); | |
1500 | if (e.reason < 0) | |
879bfdc2 DJ |
1501 | bpt->owner->enable_state = bp_disabled; |
1502 | else | |
1503 | bpt->inserted = 1; | |
1640b821 DJ |
1504 | |
1505 | /* We've already printed an error message if there was a problem | |
1506 | inserting this catchpoint, and we've disabled the catchpoint, | |
1507 | so just return success. */ | |
1508 | return 0; | |
879bfdc2 DJ |
1509 | } |
1510 | ||
1511 | return 0; | |
1512 | } | |
1513 | ||
6c95b8df PA |
1514 | /* This function is called when program space PSPACE is about to be |
1515 | deleted. It takes care of updating breakpoints to not reference | |
1516 | PSPACE anymore. */ | |
1517 | ||
1518 | void | |
1519 | breakpoint_program_space_exit (struct program_space *pspace) | |
1520 | { | |
1521 | struct breakpoint *b, *b_temp; | |
876fa593 | 1522 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1523 | |
1524 | /* Remove any breakpoint that was set through this program space. */ | |
1525 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1526 | { | |
1527 | if (b->pspace == pspace) | |
1528 | delete_breakpoint (b); | |
1529 | } | |
1530 | ||
1531 | /* Breakpoints set through other program spaces could have locations | |
1532 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1533 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1534 | { |
1535 | struct bp_location *tmp; | |
1536 | ||
1537 | if (loc->pspace == pspace) | |
1538 | { | |
1539 | if (loc->owner->loc == loc) | |
1540 | loc->owner->loc = loc->next; | |
1541 | else | |
1542 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1543 | if (tmp->next == loc) | |
1544 | { | |
1545 | tmp->next = loc->next; | |
1546 | break; | |
1547 | } | |
1548 | } | |
1549 | } | |
1550 | ||
1551 | /* Now update the global location list to permanently delete the | |
1552 | removed locations above. */ | |
1553 | update_global_location_list (0); | |
1554 | } | |
1555 | ||
74960c60 VP |
1556 | /* Make sure all breakpoints are inserted in inferior. |
1557 | Throws exception on any error. | |
1558 | A breakpoint that is already inserted won't be inserted | |
1559 | again, so calling this function twice is safe. */ | |
1560 | void | |
1561 | insert_breakpoints (void) | |
1562 | { | |
1563 | struct breakpoint *bpt; | |
1564 | ||
1565 | ALL_BREAKPOINTS (bpt) | |
1566 | if (is_hardware_watchpoint (bpt)) | |
1567 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1568 | ||
b60e7edf | 1569 | update_global_location_list (1); |
74960c60 | 1570 | |
c35b1492 PA |
1571 | /* update_global_location_list does not insert breakpoints when |
1572 | always_inserted_mode is not enabled. Explicitly insert them | |
1573 | now. */ | |
1574 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1575 | insert_breakpoint_locations (); |
1576 | } | |
1577 | ||
c906108c SS |
1578 | /* insert_breakpoints is used when starting or continuing the program. |
1579 | remove_breakpoints is used when the program stops. | |
1580 | Both return zero if successful, | |
1581 | or an `errno' value if could not write the inferior. */ | |
1582 | ||
74960c60 VP |
1583 | static void |
1584 | insert_breakpoint_locations (void) | |
c906108c | 1585 | { |
a5606eee | 1586 | struct breakpoint *bpt; |
876fa593 | 1587 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1588 | int error = 0; |
c906108c SS |
1589 | int val = 0; |
1590 | int disabled_breaks = 0; | |
81d0cc19 | 1591 | int hw_breakpoint_error = 0; |
c906108c | 1592 | |
81d0cc19 | 1593 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1594 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1595 | |
81d0cc19 GS |
1596 | /* Explicitly mark the warning -- this will only be printed if |
1597 | there was an error. */ | |
1598 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1599 | |
1600 | save_current_space_and_thread (); | |
1601 | ||
876fa593 | 1602 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1603 | { |
6c95b8df PA |
1604 | struct thread_info *tp; |
1605 | CORE_ADDR last_addr; | |
1606 | ||
74960c60 | 1607 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1608 | continue; |
1609 | ||
f365de73 AS |
1610 | /* There is no point inserting thread-specific breakpoints if the |
1611 | thread no longer exists. */ | |
1612 | if (b->owner->thread != -1 | |
1613 | && !valid_thread_id (b->owner->thread)) | |
1614 | continue; | |
1615 | ||
6c95b8df PA |
1616 | switch_to_program_space_and_thread (b->pspace); |
1617 | ||
1618 | /* For targets that support global breakpoints, there's no need | |
1619 | to select an inferior to insert breakpoint to. In fact, even | |
1620 | if we aren't attached to any process yet, we should still | |
1621 | insert breakpoints. */ | |
1622 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1623 | && ptid_equal (inferior_ptid, null_ptid)) | |
1624 | continue; | |
1625 | ||
879bfdc2 | 1626 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1627 | &disabled_breaks, |
879bfdc2 DJ |
1628 | &hw_breakpoint_error); |
1629 | if (val) | |
e236ba44 | 1630 | error = val; |
879bfdc2 | 1631 | } |
c906108c | 1632 | |
a5606eee VP |
1633 | /* If we failed to insert all locations of a watchpoint, |
1634 | remove them, as half-inserted watchpoint is of limited use. */ | |
1635 | ALL_BREAKPOINTS (bpt) | |
1636 | { | |
1637 | int some_failed = 0; | |
1638 | struct bp_location *loc; | |
1639 | ||
1640 | if (!is_hardware_watchpoint (bpt)) | |
1641 | continue; | |
1642 | ||
d6b74ac4 | 1643 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1644 | continue; |
74960c60 VP |
1645 | |
1646 | if (bpt->disposition == disp_del_at_next_stop) | |
1647 | continue; | |
a5606eee VP |
1648 | |
1649 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1650 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1651 | { |
1652 | some_failed = 1; | |
1653 | break; | |
1654 | } | |
1655 | if (some_failed) | |
1656 | { | |
1657 | for (loc = bpt->loc; loc; loc = loc->next) | |
1658 | if (loc->inserted) | |
1659 | remove_breakpoint (loc, mark_uninserted); | |
1660 | ||
1661 | hw_breakpoint_error = 1; | |
1662 | fprintf_unfiltered (tmp_error_stream, | |
1663 | "Could not insert hardware watchpoint %d.\n", | |
1664 | bpt->number); | |
1665 | error = -1; | |
1666 | } | |
1667 | } | |
1668 | ||
e236ba44 | 1669 | if (error) |
81d0cc19 GS |
1670 | { |
1671 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1672 | message about possibly exhausted resources. */ | |
879bfdc2 | 1673 | if (hw_breakpoint_error) |
81d0cc19 | 1674 | { |
c6510018 MS |
1675 | fprintf_unfiltered (tmp_error_stream, |
1676 | "Could not insert hardware breakpoints:\n\ | |
1677 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1678 | } |
81d0cc19 GS |
1679 | target_terminal_ours_for_output (); |
1680 | error_stream (tmp_error_stream); | |
1681 | } | |
f7545552 TT |
1682 | |
1683 | do_cleanups (cleanups); | |
c906108c SS |
1684 | } |
1685 | ||
c906108c | 1686 | int |
fba45db2 | 1687 | remove_breakpoints (void) |
c906108c | 1688 | { |
876fa593 | 1689 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1690 | int val = 0; |
c906108c | 1691 | |
876fa593 | 1692 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1693 | { |
0bde7532 | 1694 | if (b->inserted) |
3a1bae8e | 1695 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1696 | } |
3a1bae8e | 1697 | return val; |
c906108c SS |
1698 | } |
1699 | ||
6c95b8df PA |
1700 | /* Remove breakpoints of process PID. */ |
1701 | ||
1702 | int | |
1703 | remove_breakpoints_pid (int pid) | |
1704 | { | |
876fa593 | 1705 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1706 | int val; |
1707 | struct inferior *inf = find_inferior_pid (pid); | |
1708 | ||
876fa593 | 1709 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
1710 | { |
1711 | if (b->pspace != inf->pspace) | |
1712 | continue; | |
1713 | ||
1714 | if (b->inserted) | |
1715 | { | |
1716 | val = remove_breakpoint (b, mark_uninserted); | |
1717 | if (val != 0) | |
1718 | return val; | |
1719 | } | |
1720 | } | |
1721 | return 0; | |
1722 | } | |
1723 | ||
692590c1 | 1724 | int |
80ce1ecb | 1725 | remove_hw_watchpoints (void) |
692590c1 | 1726 | { |
876fa593 | 1727 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1728 | int val = 0; |
692590c1 | 1729 | |
876fa593 | 1730 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 1731 | { |
0bde7532 | 1732 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1733 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1734 | } |
3a1bae8e | 1735 | return val; |
692590c1 MS |
1736 | } |
1737 | ||
c906108c | 1738 | int |
fba45db2 | 1739 | reattach_breakpoints (int pid) |
c906108c | 1740 | { |
6c95b8df | 1741 | struct cleanup *old_chain; |
876fa593 | 1742 | struct bp_location *b, **bp_tmp; |
c906108c | 1743 | int val; |
a4954f26 | 1744 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1745 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
1746 | struct inferior *inf; |
1747 | struct thread_info *tp; | |
1748 | ||
1749 | tp = any_live_thread_of_process (pid); | |
1750 | if (tp == NULL) | |
1751 | return 1; | |
1752 | ||
1753 | inf = find_inferior_pid (pid); | |
1754 | old_chain = save_inferior_ptid (); | |
1755 | ||
1756 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
1757 | |
1758 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1759 | |
876fa593 | 1760 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1761 | { |
6c95b8df PA |
1762 | if (b->pspace != inf->pspace) |
1763 | continue; | |
1764 | ||
0bde7532 | 1765 | if (b->inserted) |
c5aa993b | 1766 | { |
a4954f26 DJ |
1767 | b->inserted = 0; |
1768 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1769 | &dummy1, &dummy2); |
c5aa993b JM |
1770 | if (val != 0) |
1771 | { | |
ce696e05 | 1772 | do_cleanups (old_chain); |
c5aa993b JM |
1773 | return val; |
1774 | } | |
1775 | } | |
1776 | } | |
ce696e05 | 1777 | do_cleanups (old_chain); |
c906108c SS |
1778 | return 0; |
1779 | } | |
1780 | ||
e58b0e63 PA |
1781 | static int internal_breakpoint_number = -1; |
1782 | ||
e62c965a | 1783 | static struct breakpoint * |
a6d9a66e UW |
1784 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1785 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1786 | { |
e62c965a PP |
1787 | struct symtab_and_line sal; |
1788 | struct breakpoint *b; | |
1789 | ||
1790 | init_sal (&sal); /* initialize to zeroes */ | |
1791 | ||
1792 | sal.pc = address; | |
1793 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 1794 | sal.pspace = current_program_space; |
e62c965a | 1795 | |
a6d9a66e | 1796 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1797 | b->number = internal_breakpoint_number--; |
1798 | b->disposition = disp_donttouch; | |
1799 | ||
1800 | return b; | |
1801 | } | |
1802 | ||
1803 | static void | |
69de3c6a | 1804 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1805 | { |
69de3c6a | 1806 | struct objfile *objfile; |
e62c965a | 1807 | |
69de3c6a PP |
1808 | ALL_OBJFILES (objfile) |
1809 | { | |
1810 | struct breakpoint *b; | |
1811 | struct minimal_symbol *m; | |
1812 | ||
1813 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1814 | if (m == NULL) | |
1815 | continue; | |
e62c965a | 1816 | |
a6d9a66e UW |
1817 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1818 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1819 | bp_overlay_event); |
1820 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1821 | |
69de3c6a PP |
1822 | if (overlay_debugging == ovly_auto) |
1823 | { | |
1824 | b->enable_state = bp_enabled; | |
1825 | overlay_events_enabled = 1; | |
1826 | } | |
1827 | else | |
1828 | { | |
1829 | b->enable_state = bp_disabled; | |
1830 | overlay_events_enabled = 0; | |
1831 | } | |
e62c965a PP |
1832 | } |
1833 | update_global_location_list (1); | |
1834 | } | |
1835 | ||
0fd8e87f UW |
1836 | static void |
1837 | create_longjmp_master_breakpoint (char *func_name) | |
1838 | { | |
6c95b8df | 1839 | struct program_space *pspace; |
0fd8e87f | 1840 | struct objfile *objfile; |
6c95b8df PA |
1841 | struct cleanup *old_chain; |
1842 | ||
1843 | old_chain = save_current_program_space (); | |
0fd8e87f | 1844 | |
6c95b8df | 1845 | ALL_PSPACES (pspace) |
0fd8e87f UW |
1846 | ALL_OBJFILES (objfile) |
1847 | { | |
1848 | struct breakpoint *b; | |
1849 | struct minimal_symbol *m; | |
1850 | ||
1851 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1852 | continue; | |
1853 | ||
6c95b8df PA |
1854 | set_current_program_space (pspace); |
1855 | ||
0fd8e87f UW |
1856 | m = lookup_minimal_symbol_text (func_name, objfile); |
1857 | if (m == NULL) | |
1858 | continue; | |
1859 | ||
a6d9a66e UW |
1860 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1861 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1862 | bp_longjmp_master); |
1863 | b->addr_string = xstrdup (func_name); | |
1864 | b->enable_state = bp_disabled; | |
1865 | } | |
1866 | update_global_location_list (1); | |
6c95b8df PA |
1867 | |
1868 | do_cleanups (old_chain); | |
0fd8e87f UW |
1869 | } |
1870 | ||
c906108c | 1871 | void |
fba45db2 | 1872 | update_breakpoints_after_exec (void) |
c906108c | 1873 | { |
c5aa993b JM |
1874 | struct breakpoint *b; |
1875 | struct breakpoint *temp; | |
876fa593 | 1876 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 1877 | |
25b22b0a PA |
1878 | /* We're about to delete breakpoints from GDB's lists. If the |
1879 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1880 | writing the breakpoints' "shadow contents" back into memory. The | |
1881 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1882 | do that. Instead, the target is responsible from marking | |
1883 | breakpoints out as soon as it detects an exec. We don't do that | |
1884 | here instead, because there may be other attempts to delete | |
1885 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 1886 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
1887 | if (bploc->pspace == current_program_space) |
1888 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1889 | |
1890 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 1891 | { |
6c95b8df PA |
1892 | if (b->pspace != current_program_space) |
1893 | continue; | |
1894 | ||
c5aa993b JM |
1895 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
1896 | if (b->type == bp_shlib_event) | |
1897 | { | |
1898 | delete_breakpoint (b); | |
1899 | continue; | |
1900 | } | |
c906108c | 1901 | |
4efc6507 DE |
1902 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
1903 | if (b->type == bp_jit_event) | |
1904 | { | |
1905 | delete_breakpoint (b); | |
1906 | continue; | |
1907 | } | |
1908 | ||
1900040c | 1909 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1910 | as must overlay event and longjmp master breakpoints. */ |
1911 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1912 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1913 | { |
1914 | delete_breakpoint (b); | |
1915 | continue; | |
1916 | } | |
1917 | ||
c5aa993b JM |
1918 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1919 | if (b->type == bp_step_resume) | |
1920 | { | |
1921 | delete_breakpoint (b); | |
1922 | continue; | |
1923 | } | |
1924 | ||
611c83ae PA |
1925 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1926 | after an exec. */ | |
1927 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1928 | { | |
1929 | delete_breakpoint (b); | |
1930 | continue; | |
1931 | } | |
1932 | ||
ce78b96d JB |
1933 | if (b->type == bp_catchpoint) |
1934 | { | |
1935 | /* For now, none of the bp_catchpoint breakpoints need to | |
1936 | do anything at this point. In the future, if some of | |
1937 | the catchpoints need to something, we will need to add | |
1938 | a new method, and call this method from here. */ | |
1939 | continue; | |
1940 | } | |
1941 | ||
c5aa993b JM |
1942 | /* bp_finish is a special case. The only way we ought to be able |
1943 | to see one of these when an exec() has happened, is if the user | |
1944 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1945 | carries them to the call-site of the current callee, by setting | |
1946 | a temporary bp there and resuming. But in this case, the finish | |
1947 | will carry them entirely through the vfork & exec. | |
1948 | ||
1949 | We don't want to allow a bp_finish to remain inserted now. But | |
1950 | we can't safely delete it, 'cause finish_command has a handle to | |
1951 | the bp on a bpstat, and will later want to delete it. There's a | |
1952 | chance (and I've seen it happen) that if we delete the bp_finish | |
1953 | here, that its storage will get reused by the time finish_command | |
1954 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1955 | We really must allow finish_command to delete a bp_finish. | |
1956 | ||
53a5351d JM |
1957 | In the absense of a general solution for the "how do we know |
1958 | it's safe to delete something others may have handles to?" | |
1959 | problem, what we'll do here is just uninsert the bp_finish, and | |
1960 | let finish_command delete it. | |
1961 | ||
1962 | (We know the bp_finish is "doomed" in the sense that it's | |
1963 | momentary, and will be deleted as soon as finish_command sees | |
1964 | the inferior stopped. So it doesn't matter that the bp's | |
1965 | address is probably bogus in the new a.out, unlike e.g., the | |
1966 | solib breakpoints.) */ | |
c5aa993b | 1967 | |
c5aa993b JM |
1968 | if (b->type == bp_finish) |
1969 | { | |
1970 | continue; | |
1971 | } | |
1972 | ||
1973 | /* Without a symbolic address, we have little hope of the | |
1974 | pre-exec() address meaning the same thing in the post-exec() | |
1975 | a.out. */ | |
1976 | if (b->addr_string == NULL) | |
1977 | { | |
1978 | delete_breakpoint (b); | |
1979 | continue; | |
1980 | } | |
c5aa993b | 1981 | } |
1900040c | 1982 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1983 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1984 | create_longjmp_master_breakpoint ("longjmp"); |
1985 | create_longjmp_master_breakpoint ("_longjmp"); | |
1986 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1987 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1988 | } |
1989 | ||
1990 | int | |
fba45db2 | 1991 | detach_breakpoints (int pid) |
c906108c | 1992 | { |
876fa593 | 1993 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1994 | int val = 0; |
ce696e05 | 1995 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 1996 | struct inferior *inf = current_inferior (); |
c5aa993b | 1997 | |
39f77062 | 1998 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1999 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2000 | |
6c95b8df | 2001 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2002 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 2003 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2004 | { |
6c95b8df PA |
2005 | if (b->pspace != inf->pspace) |
2006 | continue; | |
2007 | ||
0bde7532 | 2008 | if (b->inserted) |
6c95b8df | 2009 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2010 | } |
ce696e05 | 2011 | do_cleanups (old_chain); |
3a1bae8e | 2012 | return val; |
c906108c SS |
2013 | } |
2014 | ||
6c95b8df PA |
2015 | /* Remove the breakpoint location B from the current address space. |
2016 | Note that this is used to detach breakpoints from a child fork. | |
2017 | When we get here, the child isn't in the inferior list, and neither | |
2018 | do we have objects to represent its address space --- we should | |
2019 | *not* look at b->pspace->aspace here. */ | |
2020 | ||
c906108c | 2021 | static int |
6c95b8df | 2022 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2023 | { |
2024 | int val; | |
6c95b8df | 2025 | struct cleanup *old_chain; |
c5aa993b | 2026 | |
0bde7532 | 2027 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2028 | /* Permanent breakpoints cannot be inserted or removed. */ |
2029 | return 0; | |
2030 | ||
74960c60 VP |
2031 | /* The type of none suggests that owner is actually deleted. |
2032 | This should not ever happen. */ | |
2033 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2034 | |
2035 | if (b->loc_type == bp_loc_software_breakpoint | |
2036 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2037 | { |
c02f5703 MS |
2038 | /* "Normal" instruction breakpoint: either the standard |
2039 | trap-instruction bp (bp_breakpoint), or a | |
2040 | bp_hardware_breakpoint. */ | |
2041 | ||
2042 | /* First check to see if we have to handle an overlay. */ | |
2043 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2044 | || b->section == NULL |
2045 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2046 | { |
2047 | /* No overlay handling: just remove the breakpoint. */ | |
2048 | ||
0bde7532 | 2049 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2050 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2051 | else |
a6d9a66e | 2052 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2053 | } |
c906108c SS |
2054 | else |
2055 | { | |
c02f5703 MS |
2056 | /* This breakpoint is in an overlay section. |
2057 | Did we set a breakpoint at the LMA? */ | |
2058 | if (!overlay_events_enabled) | |
2059 | { | |
2060 | /* Yes -- overlay event support is not active, so we | |
2061 | should have set a breakpoint at the LMA. Remove it. | |
2062 | */ | |
c02f5703 MS |
2063 | /* Ignore any failures: if the LMA is in ROM, we will |
2064 | have already warned when we failed to insert it. */ | |
0bde7532 | 2065 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2066 | target_remove_hw_breakpoint (b->gdbarch, |
2067 | &b->overlay_target_info); | |
c02f5703 | 2068 | else |
a6d9a66e UW |
2069 | target_remove_breakpoint (b->gdbarch, |
2070 | &b->overlay_target_info); | |
c02f5703 MS |
2071 | } |
2072 | /* Did we set a breakpoint at the VMA? | |
2073 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2074 | if (b->inserted) |
c906108c | 2075 | { |
c02f5703 MS |
2076 | /* Yes -- remove it. Previously we did not bother to |
2077 | remove the breakpoint if the section had been | |
2078 | unmapped, but let's not rely on that being safe. We | |
2079 | don't know what the overlay manager might do. */ | |
0bde7532 | 2080 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2081 | val = target_remove_hw_breakpoint (b->gdbarch, |
2082 | &b->target_info); | |
aa67235e UW |
2083 | |
2084 | /* However, we should remove *software* breakpoints only | |
2085 | if the section is still mapped, or else we overwrite | |
2086 | wrong code with the saved shadow contents. */ | |
2087 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2088 | val = target_remove_breakpoint (b->gdbarch, |
2089 | &b->target_info); | |
aa67235e UW |
2090 | else |
2091 | val = 0; | |
c906108c | 2092 | } |
c02f5703 MS |
2093 | else |
2094 | { | |
2095 | /* No -- not inserted, so no need to remove. No error. */ | |
2096 | val = 0; | |
2097 | } | |
c906108c | 2098 | } |
879d1e6b UW |
2099 | |
2100 | /* In some cases, we might not be able to remove a breakpoint | |
2101 | in a shared library that has already been removed, but we | |
2102 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2103 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2104 | val = 0; |
2105 | ||
c906108c SS |
2106 | if (val) |
2107 | return val; | |
0bde7532 | 2108 | b->inserted = (is == mark_inserted); |
c906108c | 2109 | } |
a5606eee | 2110 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2111 | { |
278cd55f AC |
2112 | struct value *v; |
2113 | struct value *n; | |
c5aa993b | 2114 | |
0bde7532 | 2115 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2116 | val = target_remove_watchpoint (b->address, b->length, |
2117 | b->watchpoint_type); | |
2e70b7b9 | 2118 | |
c906108c | 2119 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2120 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2121 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2122 | b->owner->number); |
c906108c | 2123 | } |
ce78b96d JB |
2124 | else if (b->owner->type == bp_catchpoint |
2125 | && breakpoint_enabled (b->owner) | |
2126 | && !b->duplicate) | |
2127 | { | |
2128 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2129 | ||
2130 | val = b->owner->ops->remove (b->owner); | |
2131 | if (val) | |
2132 | return val; | |
2133 | b->inserted = (is == mark_inserted); | |
2134 | } | |
c906108c SS |
2135 | |
2136 | return 0; | |
2137 | } | |
2138 | ||
6c95b8df PA |
2139 | static int |
2140 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2141 | { | |
2142 | int ret; | |
2143 | struct cleanup *old_chain; | |
2144 | ||
2145 | if (b->owner->enable_state == bp_permanent) | |
2146 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2147 | return 0; | |
2148 | ||
2149 | /* The type of none suggests that owner is actually deleted. | |
2150 | This should not ever happen. */ | |
2151 | gdb_assert (b->owner->type != bp_none); | |
2152 | ||
2153 | old_chain = save_current_space_and_thread (); | |
2154 | ||
2155 | switch_to_program_space_and_thread (b->pspace); | |
2156 | ||
2157 | ret = remove_breakpoint_1 (b, is); | |
2158 | ||
2159 | do_cleanups (old_chain); | |
2160 | return ret; | |
2161 | } | |
2162 | ||
c906108c SS |
2163 | /* Clear the "inserted" flag in all breakpoints. */ |
2164 | ||
25b22b0a | 2165 | void |
fba45db2 | 2166 | mark_breakpoints_out (void) |
c906108c | 2167 | { |
876fa593 | 2168 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2169 | |
876fa593 | 2170 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2171 | if (bpt->pspace == current_program_space) |
2172 | bpt->inserted = 0; | |
c906108c SS |
2173 | } |
2174 | ||
53a5351d JM |
2175 | /* Clear the "inserted" flag in all breakpoints and delete any |
2176 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2177 | |
2178 | Plus other such housekeeping that has to be done for breakpoints | |
2179 | between runs. | |
2180 | ||
53a5351d JM |
2181 | Note: this function gets called at the end of a run (by |
2182 | generic_mourn_inferior) and when a run begins (by | |
2183 | init_wait_for_inferior). */ | |
c906108c SS |
2184 | |
2185 | ||
2186 | ||
2187 | void | |
fba45db2 | 2188 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2189 | { |
52f0bd74 | 2190 | struct breakpoint *b, *temp; |
876fa593 | 2191 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2192 | int ix; |
6c95b8df | 2193 | struct program_space *pspace = current_program_space; |
c906108c | 2194 | |
50c71eaf PA |
2195 | /* If breakpoint locations are shared across processes, then there's |
2196 | nothing to do. */ | |
2567c7d9 | 2197 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2198 | return; |
2199 | ||
876fa593 | 2200 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2201 | { |
2202 | if (bpt->pspace == pspace | |
2203 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2204 | bpt->inserted = 0; |
6c95b8df | 2205 | } |
075f6582 | 2206 | |
c906108c | 2207 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2208 | { |
6c95b8df PA |
2209 | if (b->loc && b->loc->pspace != pspace) |
2210 | continue; | |
2211 | ||
c5aa993b JM |
2212 | switch (b->type) |
2213 | { | |
2214 | case bp_call_dummy: | |
2215 | case bp_watchpoint_scope: | |
c906108c | 2216 | |
c5aa993b JM |
2217 | /* If the call dummy breakpoint is at the entry point it will |
2218 | cause problems when the inferior is rerun, so we better | |
2219 | get rid of it. | |
c906108c | 2220 | |
c5aa993b JM |
2221 | Also get rid of scope breakpoints. */ |
2222 | delete_breakpoint (b); | |
2223 | break; | |
c906108c | 2224 | |
c5aa993b JM |
2225 | case bp_watchpoint: |
2226 | case bp_hardware_watchpoint: | |
2227 | case bp_read_watchpoint: | |
2228 | case bp_access_watchpoint: | |
c906108c | 2229 | |
c5aa993b JM |
2230 | /* Likewise for watchpoints on local expressions. */ |
2231 | if (b->exp_valid_block != NULL) | |
2232 | delete_breakpoint (b); | |
967af18d | 2233 | else if (context == inf_starting) |
c860120c PM |
2234 | { |
2235 | /* Reset val field to force reread of starting value | |
2236 | in insert_breakpoints. */ | |
2237 | if (b->val) | |
2238 | value_free (b->val); | |
2239 | b->val = NULL; | |
fa4727a6 | 2240 | b->val_valid = 0; |
c860120c | 2241 | } |
c5aa993b JM |
2242 | break; |
2243 | default: | |
c5aa993b JM |
2244 | break; |
2245 | } | |
2246 | } | |
1c5cfe86 PA |
2247 | |
2248 | /* Get rid of the moribund locations. */ | |
2249 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2250 | free_bp_location (bpt); | |
2251 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2252 | } |
2253 | ||
6c95b8df PA |
2254 | /* These functions concern about actual breakpoints inserted in the |
2255 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2256 | we need to hop over the bkpt --- so we check for address space | |
2257 | match, not program space. */ | |
2258 | ||
c2c6d25f JM |
2259 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2260 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2261 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2262 | permanent breakpoint. | |
2263 | - When continuing from a location with an ordinary breakpoint, we | |
2264 | actually single step once before calling insert_breakpoints. | |
2265 | - When continuing from a localion with a permanent breakpoint, we | |
2266 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2267 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2268 | |
c2c6d25f | 2269 | enum breakpoint_here |
6c95b8df | 2270 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2271 | { |
876fa593 | 2272 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2273 | int any_breakpoint_here = 0; |
c906108c | 2274 | |
876fa593 | 2275 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2276 | { |
2277 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2278 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2279 | continue; | |
2280 | ||
468d015d | 2281 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2282 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2283 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2284 | aspace, pc)) | |
075f6582 DJ |
2285 | { |
2286 | if (overlay_debugging | |
2287 | && section_is_overlay (bpt->section) | |
2288 | && !section_is_mapped (bpt->section)) | |
2289 | continue; /* unmapped overlay -- can't be a match */ | |
2290 | else if (bpt->owner->enable_state == bp_permanent) | |
2291 | return permanent_breakpoint_here; | |
2292 | else | |
2293 | any_breakpoint_here = 1; | |
2294 | } | |
2295 | } | |
c906108c | 2296 | |
c2c6d25f | 2297 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2298 | } |
2299 | ||
1c5cfe86 PA |
2300 | /* Return true if there's a moribund breakpoint at PC. */ |
2301 | ||
2302 | int | |
6c95b8df | 2303 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2304 | { |
2305 | struct bp_location *loc; | |
2306 | int ix; | |
2307 | ||
2308 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2309 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2310 | aspace, pc)) | |
1c5cfe86 PA |
2311 | return 1; |
2312 | ||
2313 | return 0; | |
2314 | } | |
c2c6d25f | 2315 | |
c36b740a | 2316 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2317 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2318 | This does not check for single-step breakpoints, which are |
2319 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2320 | |
2321 | int | |
6c95b8df | 2322 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2323 | { |
876fa593 | 2324 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2325 | |
876fa593 | 2326 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2327 | { |
075f6582 DJ |
2328 | if (bpt->loc_type != bp_loc_software_breakpoint |
2329 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2330 | continue; | |
2331 | ||
2332 | if (bpt->inserted | |
6c95b8df PA |
2333 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2334 | aspace, pc)) | |
075f6582 DJ |
2335 | { |
2336 | if (overlay_debugging | |
2337 | && section_is_overlay (bpt->section) | |
2338 | && !section_is_mapped (bpt->section)) | |
2339 | continue; /* unmapped overlay -- can't be a match */ | |
2340 | else | |
2341 | return 1; | |
2342 | } | |
c5aa993b | 2343 | } |
c36b740a VP |
2344 | return 0; |
2345 | } | |
2346 | ||
2347 | /* Returns non-zero iff there's either regular breakpoint | |
2348 | or a single step breakpoint inserted at PC. */ | |
2349 | ||
2350 | int | |
6c95b8df | 2351 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2352 | { |
6c95b8df | 2353 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2354 | return 1; |
c906108c | 2355 | |
6c95b8df | 2356 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2357 | return 1; |
2358 | ||
c906108c SS |
2359 | return 0; |
2360 | } | |
2361 | ||
4fa8626c DJ |
2362 | /* This function returns non-zero iff there is a software breakpoint |
2363 | inserted at PC. */ | |
2364 | ||
2365 | int | |
6c95b8df | 2366 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2367 | { |
876fa593 | 2368 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2369 | int any_breakpoint_here = 0; |
2370 | ||
876fa593 | 2371 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2372 | { |
2373 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2374 | continue; | |
2375 | ||
0d381245 | 2376 | if (bpt->inserted |
6c95b8df PA |
2377 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2378 | aspace, pc)) | |
4fa8626c DJ |
2379 | { |
2380 | if (overlay_debugging | |
2381 | && section_is_overlay (bpt->section) | |
2382 | && !section_is_mapped (bpt->section)) | |
2383 | continue; /* unmapped overlay -- can't be a match */ | |
2384 | else | |
2385 | return 1; | |
2386 | } | |
2387 | } | |
2388 | ||
1aafd4da | 2389 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2390 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2391 | return 1; |
2392 | ||
4fa8626c DJ |
2393 | return 0; |
2394 | } | |
2395 | ||
9093389c PA |
2396 | int |
2397 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2398 | CORE_ADDR addr, ULONGEST len) | |
2399 | { | |
2400 | struct breakpoint *bpt; | |
2401 | ||
2402 | ALL_BREAKPOINTS (bpt) | |
2403 | { | |
2404 | struct bp_location *loc; | |
2405 | ||
2406 | if (bpt->type != bp_hardware_watchpoint | |
2407 | && bpt->type != bp_access_watchpoint) | |
2408 | continue; | |
2409 | ||
2410 | if (!breakpoint_enabled (bpt)) | |
2411 | continue; | |
2412 | ||
2413 | for (loc = bpt->loc; loc; loc = loc->next) | |
2414 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2415 | { | |
2416 | CORE_ADDR l, h; | |
2417 | ||
2418 | /* Check for intersection. */ | |
2419 | l = max (loc->address, addr); | |
2420 | h = min (loc->address + loc->length, addr + len); | |
2421 | if (l < h) | |
2422 | return 1; | |
2423 | } | |
2424 | } | |
2425 | return 0; | |
2426 | } | |
2427 | ||
075f6582 DJ |
2428 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2429 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2430 | |
2431 | int | |
6c95b8df PA |
2432 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2433 | ptid_t ptid) | |
c906108c | 2434 | { |
876fa593 | 2435 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2436 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2437 | int thread = -1; |
4a306c9a | 2438 | int task = 0; |
a6f1cd96 | 2439 | |
876fa593 | 2440 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2441 | { |
075f6582 DJ |
2442 | if (bpt->loc_type != bp_loc_software_breakpoint |
2443 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2444 | continue; | |
2445 | ||
a6f1cd96 JB |
2446 | if (!breakpoint_enabled (bpt->owner) |
2447 | && bpt->owner->enable_state != bp_permanent) | |
2448 | continue; | |
2449 | ||
6c95b8df PA |
2450 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2451 | aspace, pc)) | |
a6f1cd96 JB |
2452 | continue; |
2453 | ||
2454 | if (bpt->owner->thread != -1) | |
075f6582 | 2455 | { |
a6f1cd96 JB |
2456 | /* This is a thread-specific breakpoint. Check that ptid |
2457 | matches that thread. If thread hasn't been computed yet, | |
2458 | it is now time to do so. */ | |
2459 | if (thread == -1) | |
2460 | thread = pid_to_thread_id (ptid); | |
2461 | if (bpt->owner->thread != thread) | |
2462 | continue; | |
075f6582 | 2463 | } |
a6f1cd96 | 2464 | |
4a306c9a JB |
2465 | if (bpt->owner->task != 0) |
2466 | { | |
2467 | /* This is a task-specific breakpoint. Check that ptid | |
2468 | matches that task. If task hasn't been computed yet, | |
2469 | it is now time to do so. */ | |
2470 | if (task == 0) | |
2471 | task = ada_get_task_number (ptid); | |
2472 | if (bpt->owner->task != task) | |
2473 | continue; | |
2474 | } | |
2475 | ||
a6f1cd96 JB |
2476 | if (overlay_debugging |
2477 | && section_is_overlay (bpt->section) | |
2478 | && !section_is_mapped (bpt->section)) | |
2479 | continue; /* unmapped overlay -- can't be a match */ | |
2480 | ||
2481 | return 1; | |
c5aa993b | 2482 | } |
c906108c SS |
2483 | |
2484 | return 0; | |
2485 | } | |
c906108c | 2486 | \f |
c5aa993b | 2487 | |
c906108c SS |
2488 | /* bpstat stuff. External routines' interfaces are documented |
2489 | in breakpoint.h. */ | |
2490 | ||
2491 | int | |
fba45db2 | 2492 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2493 | { |
533be4dd | 2494 | return (ep->type == bp_catchpoint); |
c906108c SS |
2495 | } |
2496 | ||
198757a8 VP |
2497 | void |
2498 | bpstat_free (bpstat bs) | |
2499 | { | |
2500 | if (bs->old_val != NULL) | |
2501 | value_free (bs->old_val); | |
2502 | free_command_lines (&bs->commands); | |
2503 | xfree (bs); | |
2504 | } | |
2505 | ||
c906108c SS |
2506 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2507 | Also free any storage that is part of a bpstat. */ | |
2508 | ||
2509 | void | |
fba45db2 | 2510 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2511 | { |
2512 | bpstat p; | |
2513 | bpstat q; | |
2514 | ||
2515 | if (bsp == 0) | |
2516 | return; | |
2517 | p = *bsp; | |
2518 | while (p != NULL) | |
2519 | { | |
2520 | q = p->next; | |
198757a8 | 2521 | bpstat_free (p); |
c906108c SS |
2522 | p = q; |
2523 | } | |
2524 | *bsp = NULL; | |
2525 | } | |
2526 | ||
2527 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2528 | is part of the bpstat is copied as well. */ | |
2529 | ||
2530 | bpstat | |
fba45db2 | 2531 | bpstat_copy (bpstat bs) |
c906108c SS |
2532 | { |
2533 | bpstat p = NULL; | |
2534 | bpstat tmp; | |
2535 | bpstat retval = NULL; | |
2536 | ||
2537 | if (bs == NULL) | |
2538 | return bs; | |
2539 | ||
2540 | for (; bs != NULL; bs = bs->next) | |
2541 | { | |
2542 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2543 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2544 | if (bs->commands != NULL) |
2545 | tmp->commands = copy_command_lines (bs->commands); | |
2546 | if (bs->old_val != NULL) | |
3c3185ac JK |
2547 | { |
2548 | tmp->old_val = value_copy (bs->old_val); | |
2549 | release_value (tmp->old_val); | |
2550 | } | |
31cc81e9 | 2551 | |
c906108c SS |
2552 | if (p == NULL) |
2553 | /* This is the first thing in the chain. */ | |
2554 | retval = tmp; | |
2555 | else | |
2556 | p->next = tmp; | |
2557 | p = tmp; | |
2558 | } | |
2559 | p->next = NULL; | |
2560 | return retval; | |
2561 | } | |
2562 | ||
2563 | /* Find the bpstat associated with this breakpoint */ | |
2564 | ||
2565 | bpstat | |
fba45db2 | 2566 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2567 | { |
c5aa993b JM |
2568 | if (bsp == NULL) |
2569 | return NULL; | |
c906108c | 2570 | |
c5aa993b JM |
2571 | for (; bsp != NULL; bsp = bsp->next) |
2572 | { | |
4f8d1dc6 | 2573 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2574 | return bsp; |
2575 | } | |
c906108c SS |
2576 | return NULL; |
2577 | } | |
2578 | ||
2579 | /* Find a step_resume breakpoint associated with this bpstat. | |
2580 | (If there are multiple step_resume bp's on the list, this function | |
2581 | will arbitrarily pick one.) | |
2582 | ||
2583 | It is an error to use this function if BPSTAT doesn't contain a | |
2584 | step_resume breakpoint. | |
2585 | ||
2586 | See wait_for_inferior's use of this function. */ | |
2587 | struct breakpoint * | |
fba45db2 | 2588 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2589 | { |
8601f500 MS |
2590 | int current_thread; |
2591 | ||
8a3fe4f8 | 2592 | gdb_assert (bsp != NULL); |
c906108c | 2593 | |
8601f500 MS |
2594 | current_thread = pid_to_thread_id (inferior_ptid); |
2595 | ||
c906108c SS |
2596 | for (; bsp != NULL; bsp = bsp->next) |
2597 | { | |
059fb39f PM |
2598 | if ((bsp->breakpoint_at != NULL) |
2599 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2600 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2601 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2602 | return bsp->breakpoint_at->owner; |
c906108c SS |
2603 | } |
2604 | ||
8a3fe4f8 | 2605 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2606 | } |
2607 | ||
2608 | ||
8671a17b | 2609 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2610 | at. *BSP upon return is a bpstat which points to the remaining |
2611 | breakpoints stopped at (but which is not guaranteed to be good for | |
2612 | anything but further calls to bpstat_num). | |
8671a17b PA |
2613 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2614 | Return -1 if stopped at a breakpoint that has been deleted since | |
2615 | we set it. | |
2616 | Return 1 otherwise. */ | |
c906108c SS |
2617 | |
2618 | int | |
8671a17b | 2619 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2620 | { |
2621 | struct breakpoint *b; | |
2622 | ||
2623 | if ((*bsp) == NULL) | |
2624 | return 0; /* No more breakpoint values */ | |
8671a17b | 2625 | |
4f8d1dc6 VP |
2626 | /* We assume we'll never have several bpstats that |
2627 | correspond to a single breakpoint -- otherwise, | |
2628 | this function might return the same number more | |
2629 | than once and this will look ugly. */ | |
2630 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2631 | *bsp = (*bsp)->next; |
2632 | if (b == NULL) | |
2633 | return -1; /* breakpoint that's been deleted since */ | |
2634 | ||
2635 | *num = b->number; /* We have its number */ | |
2636 | return 1; | |
c906108c SS |
2637 | } |
2638 | ||
2639 | /* Modify BS so that the actions will not be performed. */ | |
2640 | ||
2641 | void | |
fba45db2 | 2642 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2643 | { |
2644 | for (; bs != NULL; bs = bs->next) | |
2645 | { | |
c2b8ed2c | 2646 | free_command_lines (&bs->commands); |
c906108c SS |
2647 | if (bs->old_val != NULL) |
2648 | { | |
2649 | value_free (bs->old_val); | |
2650 | bs->old_val = NULL; | |
2651 | } | |
2652 | } | |
2653 | } | |
2654 | ||
f3b1572e PA |
2655 | /* Called when a command is about to proceed the inferior. */ |
2656 | ||
2657 | static void | |
2658 | breakpoint_about_to_proceed (void) | |
2659 | { | |
2660 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2661 | { | |
2662 | struct thread_info *tp = inferior_thread (); | |
2663 | ||
2664 | /* Allow inferior function calls in breakpoint commands to not | |
2665 | interrupt the command list. When the call finishes | |
2666 | successfully, the inferior will be standing at the same | |
2667 | breakpoint as if nothing happened. */ | |
2668 | if (tp->in_infcall) | |
2669 | return; | |
2670 | } | |
2671 | ||
2672 | breakpoint_proceeded = 1; | |
2673 | } | |
2674 | ||
c906108c | 2675 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2676 | static void |
4efb68b1 | 2677 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2678 | { |
2679 | executing_breakpoint_commands = 0; | |
2680 | } | |
2681 | ||
2682 | /* Execute all the commands associated with all the breakpoints at this | |
2683 | location. Any of these commands could cause the process to proceed | |
2684 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2685 | the global "breakpoint_proceeded" after each command. |
c906108c | 2686 | |
347bddb7 PA |
2687 | Returns true if a breakpoint command resumed the inferior. In that |
2688 | case, it is the caller's responsibility to recall it again with the | |
2689 | bpstat of the current thread. */ | |
2690 | ||
2691 | static int | |
2692 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2693 | { |
2694 | bpstat bs; | |
2695 | struct cleanup *old_chain; | |
347bddb7 | 2696 | int again = 0; |
c906108c SS |
2697 | |
2698 | /* Avoid endless recursion if a `source' command is contained | |
2699 | in bs->commands. */ | |
2700 | if (executing_breakpoint_commands) | |
347bddb7 | 2701 | return 0; |
c906108c SS |
2702 | |
2703 | executing_breakpoint_commands = 1; | |
2704 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2705 | ||
c906108c SS |
2706 | /* This pointer will iterate over the list of bpstat's. */ |
2707 | bs = *bsp; | |
2708 | ||
2709 | breakpoint_proceeded = 0; | |
2710 | for (; bs != NULL; bs = bs->next) | |
2711 | { | |
6c50ab1c JB |
2712 | struct command_line *cmd; |
2713 | struct cleanup *this_cmd_tree_chain; | |
2714 | ||
2715 | /* Take ownership of the BSP's command tree, if it has one. | |
2716 | ||
2717 | The command tree could legitimately contain commands like | |
2718 | 'step' and 'next', which call clear_proceed_status, which | |
2719 | frees stop_bpstat's command tree. To make sure this doesn't | |
2720 | free the tree we're executing out from under us, we need to | |
2721 | take ownership of the tree ourselves. Since a given bpstat's | |
2722 | commands are only executed once, we don't need to copy it; we | |
2723 | can clear the pointer in the bpstat, and make sure we free | |
2724 | the tree when we're done. */ | |
c906108c | 2725 | cmd = bs->commands; |
6c50ab1c JB |
2726 | bs->commands = 0; |
2727 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2728 | ||
c906108c SS |
2729 | while (cmd != NULL) |
2730 | { | |
2731 | execute_control_command (cmd); | |
2732 | ||
2733 | if (breakpoint_proceeded) | |
2734 | break; | |
2735 | else | |
2736 | cmd = cmd->next; | |
2737 | } | |
6c50ab1c JB |
2738 | |
2739 | /* We can free this command tree now. */ | |
2740 | do_cleanups (this_cmd_tree_chain); | |
2741 | ||
c906108c | 2742 | if (breakpoint_proceeded) |
32c1e744 VP |
2743 | { |
2744 | if (target_can_async_p ()) | |
347bddb7 PA |
2745 | /* If we are in async mode, then the target might be still |
2746 | running, not stopped at any breakpoint, so nothing for | |
2747 | us to do here -- just return to the event loop. */ | |
2748 | ; | |
32c1e744 VP |
2749 | else |
2750 | /* In sync mode, when execute_control_command returns | |
2751 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2752 | Breakpoint commands for that stop were not run, since |
2753 | execute_command does not run breakpoint commands -- | |
2754 | only command_line_handler does, but that one is not | |
2755 | involved in execution of breakpoint commands. So, we | |
2756 | can now execute breakpoint commands. It should be | |
2757 | noted that making execute_command do bpstat actions is | |
2758 | not an option -- in this case we'll have recursive | |
2759 | invocation of bpstat for each breakpoint with a | |
2760 | command, and can easily blow up GDB stack. Instead, we | |
2761 | return true, which will trigger the caller to recall us | |
2762 | with the new stop_bpstat. */ | |
2763 | again = 1; | |
2764 | break; | |
32c1e744 | 2765 | } |
c906108c | 2766 | } |
c2b8ed2c | 2767 | do_cleanups (old_chain); |
347bddb7 PA |
2768 | return again; |
2769 | } | |
2770 | ||
2771 | void | |
2772 | bpstat_do_actions (void) | |
2773 | { | |
2774 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2775 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2776 | && target_has_execution | |
2777 | && !is_exited (inferior_ptid) | |
2778 | && !is_executing (inferior_ptid)) | |
2779 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2780 | and only return when it is stopped at the next breakpoint, we | |
2781 | keep doing breakpoint actions until it returns false to | |
2782 | indicate the inferior was not resumed. */ | |
2783 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2784 | break; | |
c906108c SS |
2785 | } |
2786 | ||
fa4727a6 DJ |
2787 | /* Print out the (old or new) value associated with a watchpoint. */ |
2788 | ||
2789 | static void | |
2790 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2791 | { | |
2792 | if (val == NULL) | |
2793 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2794 | else | |
79a45b7d TT |
2795 | { |
2796 | struct value_print_options opts; | |
2797 | get_user_print_options (&opts); | |
2798 | value_print (val, stream, &opts); | |
2799 | } | |
fa4727a6 DJ |
2800 | } |
2801 | ||
e514a9d6 | 2802 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2803 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2804 | by having it set different print_it values. |
2805 | ||
2806 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2807 | through the bpstat list of things causing this stop, calling the | |
2808 | print_bp_stop_message function on each one. The behavior of the | |
2809 | print_bp_stop_message function depends on the print_it field of | |
2810 | bpstat. If such field so indicates, call this function here. | |
2811 | ||
2812 | Return values from this routine (ultimately used by bpstat_print() | |
2813 | and normal_stop() to decide what to do): | |
2814 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2815 | don't print anything else. | |
2816 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2817 | that something to be followed by a location. | |
2818 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2819 | that something to be followed by a location. | |
2820 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2821 | analysis. */ | |
c906108c | 2822 | |
917317f4 | 2823 | static enum print_stop_action |
fba45db2 | 2824 | print_it_typical (bpstat bs) |
c906108c | 2825 | { |
f7545552 | 2826 | struct cleanup *old_chain; |
4f8d1dc6 | 2827 | struct breakpoint *b; |
89f9893c | 2828 | const struct bp_location *bl; |
8b93c638 | 2829 | struct ui_stream *stb; |
f7545552 TT |
2830 | int bp_temp = 0; |
2831 | enum print_stop_action result; | |
2832 | ||
c906108c SS |
2833 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2834 | which has since been deleted. */ | |
e514a9d6 | 2835 | if (bs->breakpoint_at == NULL) |
917317f4 | 2836 | return PRINT_UNKNOWN; |
0d381245 VP |
2837 | bl = bs->breakpoint_at; |
2838 | b = bl->owner; | |
c906108c | 2839 | |
f7545552 TT |
2840 | stb = ui_out_stream_new (uiout); |
2841 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2842 | ||
4f8d1dc6 | 2843 | switch (b->type) |
c906108c | 2844 | { |
e514a9d6 JM |
2845 | case bp_breakpoint: |
2846 | case bp_hardware_breakpoint: | |
2cec12e5 | 2847 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2848 | if (bl->address != bl->requested_address) |
2849 | breakpoint_adjustment_warning (bl->requested_address, | |
2850 | bl->address, | |
4f8d1dc6 VP |
2851 | b->number, 1); |
2852 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2853 | if (bp_temp) |
2854 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2855 | else | |
2856 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2857 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2858 | { |
2859 | ui_out_field_string (uiout, "reason", | |
2860 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2861 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2862 | } | |
4f8d1dc6 | 2863 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2864 | ui_out_text (uiout, ", "); |
f7545552 | 2865 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2866 | break; |
2867 | ||
2868 | case bp_shlib_event: | |
917317f4 JM |
2869 | /* Did we stop because the user set the stop_on_solib_events |
2870 | variable? (If so, we report this as a generic, "Stopped due | |
2871 | to shlib event" message.) */ | |
a3f17187 | 2872 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2873 | result = PRINT_NOTHING; |
e514a9d6 JM |
2874 | break; |
2875 | ||
c4093a6a JM |
2876 | case bp_thread_event: |
2877 | /* Not sure how we will get here. | |
2878 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2879 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2880 | result = PRINT_NOTHING; |
c4093a6a JM |
2881 | break; |
2882 | ||
1900040c MS |
2883 | case bp_overlay_event: |
2884 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2885 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2886 | result = PRINT_NOTHING; |
1900040c MS |
2887 | break; |
2888 | ||
0fd8e87f UW |
2889 | case bp_longjmp_master: |
2890 | /* These should never be enabled. */ | |
2891 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2892 | result = PRINT_NOTHING; | |
2893 | break; | |
2894 | ||
e514a9d6 JM |
2895 | case bp_watchpoint: |
2896 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2897 | annotate_watchpoint (b->number); |
2898 | if (ui_out_is_mi_like_p (uiout)) | |
2899 | ui_out_field_string | |
2900 | (uiout, "reason", | |
2901 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2902 | mention (b); | |
f7545552 | 2903 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2904 | ui_out_text (uiout, "\nOld value = "); |
2905 | watchpoint_value_print (bs->old_val, stb->stream); | |
2906 | ui_out_field_stream (uiout, "old", stb); | |
2907 | ui_out_text (uiout, "\nNew value = "); | |
2908 | watchpoint_value_print (b->val, stb->stream); | |
2909 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2910 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2911 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2912 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2913 | break; |
2914 | ||
2915 | case bp_read_watchpoint: | |
9dc5e2a9 | 2916 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2917 | ui_out_field_string |
2918 | (uiout, "reason", | |
2919 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2920 | mention (b); |
f7545552 | 2921 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2922 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2923 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2924 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2925 | ui_out_text (uiout, "\n"); |
f7545552 | 2926 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2927 | break; |
2928 | ||
2929 | case bp_access_watchpoint: | |
fa4727a6 | 2930 | if (bs->old_val != NULL) |
8b93c638 | 2931 | { |
4f8d1dc6 | 2932 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2933 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2934 | ui_out_field_string |
2935 | (uiout, "reason", | |
2936 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2937 | mention (b); |
f7545552 | 2938 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2939 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2940 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2941 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2942 | ui_out_text (uiout, "\nNew value = "); |
2943 | } | |
2944 | else | |
2945 | { | |
4f8d1dc6 | 2946 | mention (b); |
9dc5e2a9 | 2947 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2948 | ui_out_field_string |
2949 | (uiout, "reason", | |
2950 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2951 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2952 | ui_out_text (uiout, "\nValue = "); |
2953 | } | |
fa4727a6 | 2954 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2955 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2956 | ui_out_text (uiout, "\n"); |
f7545552 | 2957 | result = PRINT_UNKNOWN; |
e514a9d6 | 2958 | break; |
4ce44c66 | 2959 | |
e514a9d6 JM |
2960 | /* Fall through, we don't deal with these types of breakpoints |
2961 | here. */ | |
2962 | ||
11cf8741 | 2963 | case bp_finish: |
9dc5e2a9 | 2964 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2965 | ui_out_field_string |
2966 | (uiout, "reason", | |
2967 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2968 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2969 | break; |
2970 | ||
e514a9d6 | 2971 | case bp_until: |
9dc5e2a9 | 2972 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2973 | ui_out_field_string |
2974 | (uiout, "reason", | |
2975 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2976 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2977 | break; |
2978 | ||
c2d11a7d | 2979 | case bp_none: |
e514a9d6 JM |
2980 | case bp_longjmp: |
2981 | case bp_longjmp_resume: | |
2982 | case bp_step_resume: | |
e514a9d6 JM |
2983 | case bp_watchpoint_scope: |
2984 | case bp_call_dummy: | |
1042e4c0 | 2985 | case bp_tracepoint: |
7a697b8d | 2986 | case bp_fast_tracepoint: |
4efc6507 | 2987 | case bp_jit_event: |
e514a9d6 | 2988 | default: |
f7545552 TT |
2989 | result = PRINT_UNKNOWN; |
2990 | break; | |
e514a9d6 | 2991 | } |
f7545552 TT |
2992 | |
2993 | do_cleanups (old_chain); | |
2994 | return result; | |
e514a9d6 JM |
2995 | } |
2996 | ||
2997 | /* Generic routine for printing messages indicating why we | |
2998 | stopped. The behavior of this function depends on the value | |
2999 | 'print_it' in the bpstat structure. Under some circumstances we | |
3000 | may decide not to print anything here and delegate the task to | |
3001 | normal_stop(). */ | |
3002 | ||
3003 | static enum print_stop_action | |
3004 | print_bp_stop_message (bpstat bs) | |
3005 | { | |
3006 | switch (bs->print_it) | |
3007 | { | |
3008 | case print_it_noop: | |
3009 | /* Nothing should be printed for this bpstat entry. */ | |
3010 | return PRINT_UNKNOWN; | |
3011 | break; | |
3012 | ||
3013 | case print_it_done: | |
3014 | /* We still want to print the frame, but we already printed the | |
3015 | relevant messages. */ | |
3016 | return PRINT_SRC_AND_LOC; | |
3017 | break; | |
3018 | ||
3019 | case print_it_normal: | |
4f8d1dc6 | 3020 | { |
89f9893c | 3021 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3022 | struct breakpoint *b = bl ? bl->owner : NULL; |
3023 | ||
3024 | /* Normal case. Call the breakpoint's print_it method, or | |
3025 | print_it_typical. */ | |
3026 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3027 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3028 | return b->ops->print_it (b); | |
3029 | else | |
3030 | return print_it_typical (bs); | |
3031 | } | |
3032 | break; | |
3086aeae | 3033 | |
e514a9d6 | 3034 | default: |
8e65ff28 | 3035 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3036 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3037 | break; |
c906108c | 3038 | } |
c906108c SS |
3039 | } |
3040 | ||
e514a9d6 JM |
3041 | /* Print a message indicating what happened. This is called from |
3042 | normal_stop(). The input to this routine is the head of the bpstat | |
3043 | list - a list of the eventpoints that caused this stop. This | |
3044 | routine calls the generic print routine for printing a message | |
3045 | about reasons for stopping. This will print (for example) the | |
3046 | "Breakpoint n," part of the output. The return value of this | |
3047 | routine is one of: | |
c906108c | 3048 | |
917317f4 JM |
3049 | PRINT_UNKNOWN: Means we printed nothing |
3050 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3051 | code to print the location. An example is |
3052 | "Breakpoint 1, " which should be followed by | |
3053 | the location. | |
917317f4 | 3054 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3055 | to also print the location part of the message. |
3056 | An example is the catch/throw messages, which | |
917317f4 JM |
3057 | don't require a location appended to the end. |
3058 | PRINT_NOTHING: We have done some printing and we don't need any | |
3059 | further info to be printed.*/ | |
c906108c | 3060 | |
917317f4 | 3061 | enum print_stop_action |
fba45db2 | 3062 | bpstat_print (bpstat bs) |
c906108c SS |
3063 | { |
3064 | int val; | |
c5aa993b | 3065 | |
c906108c | 3066 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3067 | (Currently all watchpoints go on the bpstat whether hit or not. |
3068 | That probably could (should) be changed, provided care is taken | |
c906108c | 3069 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3070 | for (; bs; bs = bs->next) |
3071 | { | |
3072 | val = print_bp_stop_message (bs); | |
3073 | if (val == PRINT_SRC_ONLY | |
3074 | || val == PRINT_SRC_AND_LOC | |
3075 | || val == PRINT_NOTHING) | |
3076 | return val; | |
3077 | } | |
c906108c | 3078 | |
e514a9d6 JM |
3079 | /* We reached the end of the chain, or we got a null BS to start |
3080 | with and nothing was printed. */ | |
917317f4 | 3081 | return PRINT_UNKNOWN; |
c906108c SS |
3082 | } |
3083 | ||
3084 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3085 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3086 | The argument is a "struct expression *" that has been cast to char * to | |
3087 | make it pass through catch_errors. */ | |
3088 | ||
3089 | static int | |
4efb68b1 | 3090 | breakpoint_cond_eval (void *exp) |
c906108c | 3091 | { |
278cd55f | 3092 | struct value *mark = value_mark (); |
c5aa993b | 3093 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
3094 | value_free_to_mark (mark); |
3095 | return i; | |
3096 | } | |
3097 | ||
3098 | /* Allocate a new bpstat and chain it to the current one. */ | |
3099 | ||
3100 | static bpstat | |
89f9893c | 3101 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3102 | { |
3103 | bpstat bs; | |
3104 | ||
3105 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3106 | cbs->next = bs; | |
4f8d1dc6 | 3107 | bs->breakpoint_at = bl; |
c906108c SS |
3108 | /* If the condition is false, etc., don't do the commands. */ |
3109 | bs->commands = NULL; | |
3110 | bs->old_val = NULL; | |
3111 | bs->print_it = print_it_normal; | |
3112 | return bs; | |
3113 | } | |
3114 | \f | |
d983da9c DJ |
3115 | /* The target has stopped with waitstatus WS. Check if any hardware |
3116 | watchpoints have triggered, according to the target. */ | |
3117 | ||
3118 | int | |
3119 | watchpoints_triggered (struct target_waitstatus *ws) | |
3120 | { | |
d92524f1 | 3121 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3122 | CORE_ADDR addr; |
3123 | struct breakpoint *b; | |
3124 | ||
3125 | if (!stopped_by_watchpoint) | |
3126 | { | |
3127 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3128 | as not triggered. */ | |
3129 | ALL_BREAKPOINTS (b) | |
3130 | if (b->type == bp_hardware_watchpoint | |
3131 | || b->type == bp_read_watchpoint | |
3132 | || b->type == bp_access_watchpoint) | |
3133 | b->watchpoint_triggered = watch_triggered_no; | |
3134 | ||
3135 | return 0; | |
3136 | } | |
3137 | ||
3138 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3139 | { | |
3140 | /* We were stopped by a watchpoint, but we don't know where. | |
3141 | Mark all watchpoints as unknown. */ | |
3142 | ALL_BREAKPOINTS (b) | |
3143 | if (b->type == bp_hardware_watchpoint | |
3144 | || b->type == bp_read_watchpoint | |
3145 | || b->type == bp_access_watchpoint) | |
3146 | b->watchpoint_triggered = watch_triggered_unknown; | |
3147 | ||
3148 | return stopped_by_watchpoint; | |
3149 | } | |
3150 | ||
3151 | /* The target could report the data address. Mark watchpoints | |
3152 | affected by this data address as triggered, and all others as not | |
3153 | triggered. */ | |
3154 | ||
3155 | ALL_BREAKPOINTS (b) | |
3156 | if (b->type == bp_hardware_watchpoint | |
3157 | || b->type == bp_read_watchpoint | |
3158 | || b->type == bp_access_watchpoint) | |
3159 | { | |
a5606eee | 3160 | struct bp_location *loc; |
d983da9c DJ |
3161 | struct value *v; |
3162 | ||
3163 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3164 | for (loc = b->loc; loc; loc = loc->next) |
3165 | /* Exact match not required. Within range is | |
3166 | sufficient. */ | |
5009afc5 AS |
3167 | if (target_watchpoint_addr_within_range (¤t_target, |
3168 | addr, loc->address, | |
3169 | loc->length)) | |
a5606eee VP |
3170 | { |
3171 | b->watchpoint_triggered = watch_triggered_yes; | |
3172 | break; | |
3173 | } | |
d983da9c DJ |
3174 | } |
3175 | ||
3176 | return 1; | |
3177 | } | |
3178 | ||
c906108c SS |
3179 | /* Possible return values for watchpoint_check (this can't be an enum |
3180 | because of check_errors). */ | |
3181 | /* The watchpoint has been deleted. */ | |
3182 | #define WP_DELETED 1 | |
3183 | /* The value has changed. */ | |
3184 | #define WP_VALUE_CHANGED 2 | |
3185 | /* The value has not changed. */ | |
3186 | #define WP_VALUE_NOT_CHANGED 3 | |
3187 | ||
3188 | #define BP_TEMPFLAG 1 | |
3189 | #define BP_HARDWAREFLAG 2 | |
3190 | ||
553e4c11 JB |
3191 | /* Evaluate watchpoint condition expression and check if its value changed. |
3192 | ||
3193 | P should be a pointer to struct bpstat, but is defined as a void * | |
3194 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3195 | |
3196 | static int | |
4efb68b1 | 3197 | watchpoint_check (void *p) |
c906108c SS |
3198 | { |
3199 | bpstat bs = (bpstat) p; | |
3200 | struct breakpoint *b; | |
3201 | struct frame_info *fr; | |
3202 | int within_current_scope; | |
3203 | ||
4f8d1dc6 | 3204 | b = bs->breakpoint_at->owner; |
c906108c | 3205 | |
f6bc2008 PA |
3206 | /* If this is a local watchpoint, we only want to check if the |
3207 | watchpoint frame is in scope if the current thread is the thread | |
3208 | that was used to create the watchpoint. */ | |
3209 | if (!watchpoint_in_thread_scope (b)) | |
3210 | return WP_VALUE_NOT_CHANGED; | |
3211 | ||
c906108c SS |
3212 | if (b->exp_valid_block == NULL) |
3213 | within_current_scope = 1; | |
3214 | else | |
3215 | { | |
edb3359d DJ |
3216 | struct frame_info *frame = get_current_frame (); |
3217 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3218 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3219 | ||
a0f49112 JK |
3220 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3221 | in the function but the stack frame has already been invalidated. | |
3222 | Since we can't rely on the values of local variables after the | |
3223 | stack has been destroyed, we are treating the watchpoint in that | |
3224 | state as `not changed' without further checking. Don't mark | |
3225 | watchpoints as changed if the current frame is in an epilogue - | |
3226 | even if they are in some other frame, our view of the stack | |
3227 | is likely to be wrong and frame_find_by_id could error out. */ | |
3228 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
3229 | return WP_VALUE_NOT_CHANGED; | |
3230 | ||
101dcfbe | 3231 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3232 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3233 | |
3234 | /* If we've gotten confused in the unwinder, we might have | |
3235 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3236 | if (within_current_scope) |
3237 | { | |
3238 | struct symbol *function; | |
3239 | ||
3240 | function = get_frame_function (fr); | |
3241 | if (function == NULL | |
3242 | || !contained_in (b->exp_valid_block, | |
3243 | SYMBOL_BLOCK_VALUE (function))) | |
3244 | within_current_scope = 0; | |
3245 | } | |
69fbadd5 | 3246 | |
edb3359d | 3247 | if (within_current_scope) |
c906108c SS |
3248 | /* If we end up stopping, the current frame will get selected |
3249 | in normal_stop. So this call to select_frame won't affect | |
3250 | the user. */ | |
0f7d239c | 3251 | select_frame (fr); |
c906108c | 3252 | } |
c5aa993b | 3253 | |
c906108c SS |
3254 | if (within_current_scope) |
3255 | { | |
3256 | /* We use value_{,free_to_}mark because it could be a | |
3257 | *long* time before we return to the command level and | |
c5aa993b JM |
3258 | call free_all_values. We can't call free_all_values because |
3259 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3260 | |
278cd55f | 3261 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3262 | struct value *new_val; |
3263 | ||
3264 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
218d2fc6 TJB |
3265 | |
3266 | /* We use value_equal_contents instead of value_equal because the latter | |
3267 | coerces an array to a pointer, thus comparing just the address of the | |
3268 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3269 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3270 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3271 | { |
fa4727a6 DJ |
3272 | if (new_val != NULL) |
3273 | { | |
3274 | release_value (new_val); | |
3275 | value_free_to_mark (mark); | |
3276 | } | |
c906108c SS |
3277 | bs->old_val = b->val; |
3278 | b->val = new_val; | |
fa4727a6 | 3279 | b->val_valid = 1; |
c906108c SS |
3280 | /* We will stop here */ |
3281 | return WP_VALUE_CHANGED; | |
3282 | } | |
3283 | else | |
3284 | { | |
3285 | /* Nothing changed, don't do anything. */ | |
3286 | value_free_to_mark (mark); | |
3287 | /* We won't stop here */ | |
3288 | return WP_VALUE_NOT_CHANGED; | |
3289 | } | |
3290 | } | |
3291 | else | |
3292 | { | |
3293 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3294 | if we temporarily ignored the watchpoint, then when |
3295 | we reenter the block in which it is valid it contains | |
3296 | garbage (in the case of a function, it may have two | |
3297 | garbage values, one before and one after the prologue). | |
3298 | So we can't even detect the first assignment to it and | |
3299 | watch after that (since the garbage may or may not equal | |
3300 | the first value assigned). */ | |
4ce44c66 JM |
3301 | /* We print all the stop information in print_it_typical(), but |
3302 | in this case, by the time we call print_it_typical() this bp | |
3303 | will be deleted already. So we have no choice but print the | |
3304 | information here. */ | |
9dc5e2a9 | 3305 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3306 | ui_out_field_string |
3307 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3308 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3309 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3310 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3311 | which its expression is valid.\n"); | |
4ce44c66 | 3312 | |
c906108c | 3313 | if (b->related_breakpoint) |
b5de0fa7 EZ |
3314 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
3315 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
3316 | |
3317 | return WP_DELETED; | |
3318 | } | |
3319 | } | |
3320 | ||
18a18393 VP |
3321 | /* Return true if it looks like target has stopped due to hitting |
3322 | breakpoint location BL. This function does not check if we | |
3323 | should stop, only if BL explains the stop. */ | |
3324 | static int | |
6c95b8df PA |
3325 | bpstat_check_location (const struct bp_location *bl, |
3326 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3327 | { |
3328 | struct breakpoint *b = bl->owner; | |
3329 | ||
e8595ef6 SS |
3330 | /* By definition, the inferior does not report stops at |
3331 | tracepoints. */ | |
7a697b8d | 3332 | if (tracepoint_type (b)) |
e8595ef6 SS |
3333 | return 0; |
3334 | ||
18a18393 VP |
3335 | if (b->type != bp_watchpoint |
3336 | && b->type != bp_hardware_watchpoint | |
3337 | && b->type != bp_read_watchpoint | |
3338 | && b->type != bp_access_watchpoint | |
3339 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3340 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3341 | { |
6c95b8df PA |
3342 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3343 | aspace, bp_addr)) | |
18a18393 VP |
3344 | return 0; |
3345 | if (overlay_debugging /* unmapped overlay section */ | |
3346 | && section_is_overlay (bl->section) | |
3347 | && !section_is_mapped (bl->section)) | |
3348 | return 0; | |
3349 | } | |
3350 | ||
3351 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3352 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3353 | some data address). Otherwise gdb won't stop on a break instruction | |
3354 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3355 | been defined. Also skip watchpoints which we know did not trigger | |
3356 | (did not match the data address). */ | |
3357 | ||
3358 | if ((b->type == bp_hardware_watchpoint | |
3359 | || b->type == bp_read_watchpoint | |
3360 | || b->type == bp_access_watchpoint) | |
3361 | && b->watchpoint_triggered == watch_triggered_no) | |
3362 | return 0; | |
3363 | ||
3364 | if (b->type == bp_hardware_breakpoint) | |
3365 | { | |
3366 | if (bl->address != bp_addr) | |
3367 | return 0; | |
3368 | if (overlay_debugging /* unmapped overlay section */ | |
3369 | && section_is_overlay (bl->section) | |
3370 | && !section_is_mapped (bl->section)) | |
3371 | return 0; | |
3372 | } | |
ce78b96d | 3373 | |
ce78b96d JB |
3374 | if (b->type == bp_catchpoint) |
3375 | { | |
3376 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3377 | if (!b->ops->breakpoint_hit (b)) | |
3378 | return 0; | |
3379 | } | |
3380 | ||
18a18393 VP |
3381 | return 1; |
3382 | } | |
3383 | ||
3384 | /* If BS refers to a watchpoint, determine if the watched values | |
3385 | has actually changed, and we should stop. If not, set BS->stop | |
3386 | to 0. */ | |
3387 | static void | |
3388 | bpstat_check_watchpoint (bpstat bs) | |
3389 | { | |
3390 | const struct bp_location *bl = bs->breakpoint_at; | |
3391 | struct breakpoint *b = bl->owner; | |
3392 | ||
3393 | if (b->type == bp_watchpoint | |
3394 | || b->type == bp_read_watchpoint | |
3395 | || b->type == bp_access_watchpoint | |
3396 | || b->type == bp_hardware_watchpoint) | |
3397 | { | |
3398 | CORE_ADDR addr; | |
3399 | struct value *v; | |
3400 | int must_check_value = 0; | |
3401 | ||
3402 | if (b->type == bp_watchpoint) | |
3403 | /* For a software watchpoint, we must always check the | |
3404 | watched value. */ | |
3405 | must_check_value = 1; | |
3406 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3407 | /* We have a hardware watchpoint (read, write, or access) | |
3408 | and the target earlier reported an address watched by | |
3409 | this watchpoint. */ | |
3410 | must_check_value = 1; | |
3411 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3412 | && b->type == bp_hardware_watchpoint) | |
3413 | /* We were stopped by a hardware watchpoint, but the target could | |
3414 | not report the data address. We must check the watchpoint's | |
3415 | value. Access and read watchpoints are out of luck; without | |
3416 | a data address, we can't figure it out. */ | |
3417 | must_check_value = 1; | |
3418 | ||
3419 | if (must_check_value) | |
3420 | { | |
3421 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3422 | b->number); | |
3423 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3424 | int e = catch_errors (watchpoint_check, bs, message, | |
3425 | RETURN_MASK_ALL); | |
3426 | do_cleanups (cleanups); | |
3427 | switch (e) | |
3428 | { | |
3429 | case WP_DELETED: | |
3430 | /* We've already printed what needs to be printed. */ | |
3431 | bs->print_it = print_it_done; | |
3432 | /* Stop. */ | |
3433 | break; | |
3434 | case WP_VALUE_CHANGED: | |
3435 | if (b->type == bp_read_watchpoint) | |
3436 | { | |
3437 | /* Don't stop: read watchpoints shouldn't fire if | |
3438 | the value has changed. This is for targets | |
3439 | which cannot set read-only watchpoints. */ | |
3440 | bs->print_it = print_it_noop; | |
3441 | bs->stop = 0; | |
3442 | } | |
3443 | break; | |
3444 | case WP_VALUE_NOT_CHANGED: | |
3445 | if (b->type == bp_hardware_watchpoint | |
3446 | || b->type == bp_watchpoint) | |
3447 | { | |
3448 | /* Don't stop: write watchpoints shouldn't fire if | |
3449 | the value hasn't changed. */ | |
3450 | bs->print_it = print_it_noop; | |
3451 | bs->stop = 0; | |
3452 | } | |
3453 | /* Stop. */ | |
3454 | break; | |
3455 | default: | |
3456 | /* Can't happen. */ | |
3457 | case 0: | |
3458 | /* Error from catch_errors. */ | |
3459 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3460 | if (b->related_breakpoint) | |
3461 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3462 | b->disposition = disp_del_at_next_stop; | |
3463 | /* We've already printed what needs to be printed. */ | |
3464 | bs->print_it = print_it_done; | |
3465 | break; | |
3466 | } | |
3467 | } | |
3468 | else /* must_check_value == 0 */ | |
3469 | { | |
3470 | /* This is a case where some watchpoint(s) triggered, but | |
3471 | not at the address of this watchpoint, or else no | |
3472 | watchpoint triggered after all. So don't print | |
3473 | anything for this watchpoint. */ | |
3474 | bs->print_it = print_it_noop; | |
3475 | bs->stop = 0; | |
3476 | } | |
3477 | } | |
3478 | } | |
3479 | ||
3480 | ||
3481 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3482 | of breakpoint referred to by BS. If we should not stop for this | |
3483 | breakpoint, set BS->stop to 0. */ | |
3484 | static void | |
3485 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3486 | { | |
3487 | int thread_id = pid_to_thread_id (ptid); | |
3488 | const struct bp_location *bl = bs->breakpoint_at; | |
3489 | struct breakpoint *b = bl->owner; | |
3490 | ||
3491 | if (frame_id_p (b->frame_id) | |
edb3359d | 3492 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3493 | bs->stop = 0; |
3494 | else if (bs->stop) | |
3495 | { | |
3496 | int value_is_zero = 0; | |
3497 | ||
3498 | /* If this is a scope breakpoint, mark the associated | |
3499 | watchpoint as triggered so that we will handle the | |
3500 | out-of-scope event. We'll get to the watchpoint next | |
3501 | iteration. */ | |
3502 | if (b->type == bp_watchpoint_scope) | |
3503 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3504 | ||
3505 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3506 | { | |
c5bc3a77 DJ |
3507 | /* We use value_mark and value_free_to_mark because it could |
3508 | be a long time before we return to the command level and | |
3509 | call free_all_values. We can't call free_all_values | |
3510 | because we might be in the middle of evaluating a | |
3511 | function call. */ | |
3512 | struct value *mark = value_mark (); | |
3513 | ||
edb3359d DJ |
3514 | /* Need to select the frame, with all that implies so that |
3515 | the conditions will have the right context. Because we | |
3516 | use the frame, we will not see an inlined function's | |
3517 | variables when we arrive at a breakpoint at the start | |
3518 | of the inlined function; the current frame will be the | |
3519 | call site. */ | |
18a18393 VP |
3520 | select_frame (get_current_frame ()); |
3521 | value_is_zero | |
3522 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3523 | "Error in testing breakpoint condition:\n", | |
3524 | RETURN_MASK_ALL); | |
3525 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3526 | value_free_to_mark (mark); |
18a18393 VP |
3527 | } |
3528 | if (bl->cond && value_is_zero) | |
3529 | { | |
3530 | bs->stop = 0; | |
3531 | } | |
3532 | else if (b->thread != -1 && b->thread != thread_id) | |
3533 | { | |
3534 | bs->stop = 0; | |
3535 | } | |
3536 | else if (b->ignore_count > 0) | |
3537 | { | |
3538 | b->ignore_count--; | |
3539 | annotate_ignore_count_change (); | |
3540 | bs->stop = 0; | |
3541 | /* Increase the hit count even though we don't | |
3542 | stop. */ | |
3543 | ++(b->hit_count); | |
3544 | } | |
3545 | } | |
3546 | } | |
3547 | ||
3548 | ||
9709f61c | 3549 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3550 | BP_ADDR in thread PTID. |
c906108c | 3551 | |
d983da9c | 3552 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3553 | don't understand this stop. Result is a chain of bpstat's such that: |
3554 | ||
c5aa993b | 3555 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3556 | |
c5aa993b | 3557 | if we understand why we stopped, the result is not null. |
c906108c | 3558 | |
c5aa993b JM |
3559 | Each element of the chain refers to a particular breakpoint or |
3560 | watchpoint at which we have stopped. (We may have stopped for | |
3561 | several reasons concurrently.) | |
c906108c | 3562 | |
c5aa993b JM |
3563 | Each element of the chain has valid next, breakpoint_at, |
3564 | commands, FIXME??? fields. */ | |
c906108c SS |
3565 | |
3566 | bpstat | |
6c95b8df PA |
3567 | bpstat_stop_status (struct address_space *aspace, |
3568 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 3569 | { |
0d381245 | 3570 | struct breakpoint *b = NULL; |
876fa593 | 3571 | struct bp_location *bl, **blp_tmp; |
20874c92 | 3572 | struct bp_location *loc; |
c906108c SS |
3573 | /* Root of the chain of bpstat's */ |
3574 | struct bpstats root_bs[1]; | |
3575 | /* Pointer to the last thing in the chain currently. */ | |
3576 | bpstat bs = root_bs; | |
20874c92 | 3577 | int ix; |
429374b8 | 3578 | int need_remove_insert; |
c906108c | 3579 | |
429374b8 JK |
3580 | /* ALL_BP_LOCATIONS iteration would break across |
3581 | update_global_location_list possibly executed by | |
3582 | bpstat_check_breakpoint_conditions's inferior call. */ | |
c5aa993b | 3583 | |
429374b8 JK |
3584 | ALL_BREAKPOINTS (b) |
3585 | { | |
3586 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
3587 | continue; | |
a5606eee | 3588 | |
429374b8 JK |
3589 | for (bl = b->loc; bl != NULL; bl = bl->next) |
3590 | { | |
3591 | /* For hardware watchpoints, we look only at the first location. | |
3592 | The watchpoint_check function will work on entire expression, | |
3593 | not the individual locations. For read watchopints, the | |
3594 | watchpoints_triggered function have checked all locations | |
3595 | already. */ | |
3596 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
3597 | break; | |
18a18393 | 3598 | |
429374b8 JK |
3599 | if (bl->shlib_disabled) |
3600 | continue; | |
c5aa993b | 3601 | |
429374b8 JK |
3602 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
3603 | continue; | |
c5aa993b | 3604 | |
429374b8 | 3605 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 3606 | |
429374b8 | 3607 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3608 | |
429374b8 JK |
3609 | /* Assume we stop. Should we find watchpoint that is not actually |
3610 | triggered, or if condition of breakpoint is false, we'll reset | |
3611 | 'stop' to 0. */ | |
3612 | bs->stop = 1; | |
3613 | bs->print = 1; | |
d983da9c | 3614 | |
429374b8 JK |
3615 | bpstat_check_watchpoint (bs); |
3616 | if (!bs->stop) | |
3617 | continue; | |
18a18393 | 3618 | |
429374b8 JK |
3619 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3620 | || b->type == bp_longjmp_master) | |
3621 | /* We do not stop for these. */ | |
3622 | bs->stop = 0; | |
3623 | else | |
3624 | bpstat_check_breakpoint_conditions (bs, ptid); | |
3625 | ||
3626 | if (bs->stop) | |
3627 | { | |
3628 | ++(b->hit_count); | |
c906108c | 3629 | |
429374b8 JK |
3630 | /* We will stop here */ |
3631 | if (b->disposition == disp_disable) | |
3632 | { | |
3633 | if (b->enable_state != bp_permanent) | |
3634 | b->enable_state = bp_disabled; | |
3635 | update_global_location_list (0); | |
3636 | } | |
3637 | if (b->silent) | |
3638 | bs->print = 0; | |
3639 | bs->commands = b->commands; | |
3640 | if (bs->commands | |
3641 | && (strcmp ("silent", bs->commands->line) == 0 | |
3642 | || (xdb_commands && strcmp ("Q", | |
3643 | bs->commands->line) == 0))) | |
3644 | { | |
3645 | bs->commands = bs->commands->next; | |
3646 | bs->print = 0; | |
3647 | } | |
3648 | bs->commands = copy_command_lines (bs->commands); | |
3649 | } | |
3650 | ||
3651 | /* Print nothing for this entry if we dont stop or dont print. */ | |
3652 | if (bs->stop == 0 || bs->print == 0) | |
3653 | bs->print_it = print_it_noop; | |
3654 | } | |
3655 | } | |
876fa593 | 3656 | |
20874c92 VP |
3657 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3658 | { | |
6c95b8df PA |
3659 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
3660 | aspace, bp_addr)) | |
20874c92 VP |
3661 | { |
3662 | bs = bpstat_alloc (loc, bs); | |
3663 | /* For hits of moribund locations, we should just proceed. */ | |
3664 | bs->stop = 0; | |
3665 | bs->print = 0; | |
3666 | bs->print_it = print_it_noop; | |
3667 | } | |
3668 | } | |
3669 | ||
c906108c SS |
3670 | bs->next = NULL; /* Terminate the chain */ |
3671 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3672 | ||
d983da9c DJ |
3673 | /* If we aren't stopping, the value of some hardware watchpoint may |
3674 | not have changed, but the intermediate memory locations we are | |
3675 | watching may have. Don't bother if we're stopping; this will get | |
3676 | done later. */ | |
3677 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3678 | if (bs->stop) | |
3679 | break; | |
3680 | ||
d832cb68 | 3681 | need_remove_insert = 0; |
d983da9c DJ |
3682 | if (bs == NULL) |
3683 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3684 | if (!bs->stop | |
20874c92 | 3685 | && bs->breakpoint_at->owner |
2d134ed3 | 3686 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 3687 | { |
2d134ed3 PA |
3688 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
3689 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
3690 | Prevent further code from trying to use it. */ | |
a5606eee | 3691 | bs->breakpoint_at = NULL; |
d832cb68 | 3692 | need_remove_insert = 1; |
d983da9c DJ |
3693 | } |
3694 | ||
d832cb68 | 3695 | if (need_remove_insert) |
2d134ed3 | 3696 | update_global_location_list (1); |
d832cb68 | 3697 | |
d983da9c | 3698 | return root_bs->next; |
c906108c SS |
3699 | } |
3700 | \f | |
3701 | /* Tell what to do about this bpstat. */ | |
3702 | struct bpstat_what | |
fba45db2 | 3703 | bpstat_what (bpstat bs) |
c906108c SS |
3704 | { |
3705 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3706 | enum class |
3707 | { | |
3708 | /* This bpstat element has no effect on the main_action. */ | |
3709 | no_effect = 0, | |
3710 | ||
3711 | /* There was a watchpoint, stop but don't print. */ | |
3712 | wp_silent, | |
c906108c | 3713 | |
c5aa993b JM |
3714 | /* There was a watchpoint, stop and print. */ |
3715 | wp_noisy, | |
c906108c | 3716 | |
c5aa993b JM |
3717 | /* There was a breakpoint but we're not stopping. */ |
3718 | bp_nostop, | |
c906108c | 3719 | |
c5aa993b JM |
3720 | /* There was a breakpoint, stop but don't print. */ |
3721 | bp_silent, | |
c906108c | 3722 | |
c5aa993b JM |
3723 | /* There was a breakpoint, stop and print. */ |
3724 | bp_noisy, | |
c906108c | 3725 | |
c5aa993b JM |
3726 | /* We hit the longjmp breakpoint. */ |
3727 | long_jump, | |
c906108c | 3728 | |
c5aa993b JM |
3729 | /* We hit the longjmp_resume breakpoint. */ |
3730 | long_resume, | |
c906108c | 3731 | |
c5aa993b JM |
3732 | /* We hit the step_resume breakpoint. */ |
3733 | step_resume, | |
c906108c | 3734 | |
c5aa993b JM |
3735 | /* We hit the shared library event breakpoint. */ |
3736 | shlib_event, | |
c906108c | 3737 | |
4efc6507 DE |
3738 | /* We hit the jit event breakpoint. */ |
3739 | jit_event, | |
3740 | ||
c5aa993b JM |
3741 | /* This is just used to count how many enums there are. */ |
3742 | class_last | |
c906108c SS |
3743 | }; |
3744 | ||
3745 | /* Here is the table which drives this routine. So that we can | |
3746 | format it pretty, we define some abbreviations for the | |
3747 | enum bpstat_what codes. */ | |
3748 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3749 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3750 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3751 | #define sgl BPSTAT_WHAT_SINGLE | |
3752 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3753 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3754 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3755 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 3756 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
3757 | |
3758 | /* "Can't happen." Might want to print an error message. | |
3759 | abort() is not out of the question, but chances are GDB is just | |
3760 | a bit confused, not unusable. */ | |
3761 | #define err BPSTAT_WHAT_STOP_NOISY | |
3762 | ||
3763 | /* Given an old action and a class, come up with a new action. */ | |
3764 | /* One interesting property of this table is that wp_silent is the same | |
3765 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3766 | after stopping, the check for whether to step over a breakpoint | |
3767 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3768 | reference to how we stopped. We retain separate wp_silent and |
3769 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3770 | |
3771 | Another possibly interesting property of this table is that | |
3772 | there's a partial ordering, priority-like, of the actions. Once | |
3773 | you've decided that some action is appropriate, you'll never go | |
3774 | back and decide something of a lower priority is better. The | |
3775 | ordering is: | |
3776 | ||
4efc6507 DE |
3777 | kc < jit clr sgl shl slr sn sr ss |
3778 | sgl < jit shl slr sn sr ss | |
3779 | slr < jit err shl sn sr ss | |
3780 | clr < jit err shl sn sr ss | |
3781 | ss < jit shl sn sr | |
3782 | sn < jit shl sr | |
3783 | jit < shl sr | |
d81191fc | 3784 | shl < sr |
4d5b2cd7 | 3785 | sr < |
c5aa993b | 3786 | |
43ff13b4 JM |
3787 | What I think this means is that we don't need a damned table |
3788 | here. If you just put the rows and columns in the right order, | |
3789 | it'd look awfully regular. We could simply walk the bpstat list | |
3790 | and choose the highest priority action we find, with a little | |
78b6a731 | 3791 | logic to handle the 'err' cases. */ |
c906108c SS |
3792 | |
3793 | /* step_resume entries: a step resume breakpoint overrides another | |
3794 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3795 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3796 | |
3797 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3798 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3799 | { | |
3800 | /* old action */ | |
4efc6507 DE |
3801 | /* kc ss sn sgl slr clr sr shl jit */ |
3802 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
3803 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3804 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3805 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
3806 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3807 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3808 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
3809 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
3810 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
3811 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
3812 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 3813 | }; |
c906108c SS |
3814 | |
3815 | #undef kc | |
3816 | #undef ss | |
3817 | #undef sn | |
3818 | #undef sgl | |
3819 | #undef slr | |
3820 | #undef clr | |
c906108c SS |
3821 | #undef err |
3822 | #undef sr | |
3823 | #undef ts | |
3824 | #undef shl | |
4efc6507 | 3825 | #undef jit |
c906108c SS |
3826 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3827 | struct bpstat_what retval; | |
3828 | ||
3829 | retval.call_dummy = 0; | |
3830 | for (; bs != NULL; bs = bs->next) | |
3831 | { | |
3832 | enum class bs_class = no_effect; | |
3833 | if (bs->breakpoint_at == NULL) | |
3834 | /* I suspect this can happen if it was a momentary breakpoint | |
3835 | which has since been deleted. */ | |
3836 | continue; | |
20874c92 VP |
3837 | if (bs->breakpoint_at->owner == NULL) |
3838 | bs_class = bp_nostop; | |
3839 | else | |
4f8d1dc6 | 3840 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3841 | { |
3842 | case bp_none: | |
3843 | continue; | |
3844 | ||
3845 | case bp_breakpoint: | |
3846 | case bp_hardware_breakpoint: | |
3847 | case bp_until: | |
3848 | case bp_finish: | |
3849 | if (bs->stop) | |
3850 | { | |
3851 | if (bs->print) | |
3852 | bs_class = bp_noisy; | |
3853 | else | |
3854 | bs_class = bp_silent; | |
3855 | } | |
3856 | else | |
3857 | bs_class = bp_nostop; | |
3858 | break; | |
3859 | case bp_watchpoint: | |
3860 | case bp_hardware_watchpoint: | |
3861 | case bp_read_watchpoint: | |
3862 | case bp_access_watchpoint: | |
3863 | if (bs->stop) | |
3864 | { | |
3865 | if (bs->print) | |
3866 | bs_class = wp_noisy; | |
3867 | else | |
3868 | bs_class = wp_silent; | |
3869 | } | |
3870 | else | |
53a5351d JM |
3871 | /* There was a watchpoint, but we're not stopping. |
3872 | This requires no further action. */ | |
c906108c SS |
3873 | bs_class = no_effect; |
3874 | break; | |
3875 | case bp_longjmp: | |
3876 | bs_class = long_jump; | |
3877 | break; | |
3878 | case bp_longjmp_resume: | |
3879 | bs_class = long_resume; | |
3880 | break; | |
3881 | case bp_step_resume: | |
3882 | if (bs->stop) | |
3883 | { | |
3884 | bs_class = step_resume; | |
3885 | } | |
3886 | else | |
3887 | /* It is for the wrong frame. */ | |
3888 | bs_class = bp_nostop; | |
3889 | break; | |
c906108c SS |
3890 | case bp_watchpoint_scope: |
3891 | bs_class = bp_nostop; | |
3892 | break; | |
c5aa993b JM |
3893 | case bp_shlib_event: |
3894 | bs_class = shlib_event; | |
3895 | break; | |
4efc6507 DE |
3896 | case bp_jit_event: |
3897 | bs_class = jit_event; | |
3898 | break; | |
c4093a6a | 3899 | case bp_thread_event: |
1900040c | 3900 | case bp_overlay_event: |
0fd8e87f | 3901 | case bp_longjmp_master: |
c4093a6a JM |
3902 | bs_class = bp_nostop; |
3903 | break; | |
ce78b96d | 3904 | case bp_catchpoint: |
c5aa993b JM |
3905 | if (bs->stop) |
3906 | { | |
3907 | if (bs->print) | |
3908 | bs_class = bp_noisy; | |
3909 | else | |
3910 | bs_class = bp_silent; | |
3911 | } | |
3912 | else | |
53a5351d JM |
3913 | /* There was a catchpoint, but we're not stopping. |
3914 | This requires no further action. */ | |
c5aa993b JM |
3915 | bs_class = no_effect; |
3916 | break; | |
c906108c | 3917 | case bp_call_dummy: |
53a5351d JM |
3918 | /* Make sure the action is stop (silent or noisy), |
3919 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3920 | bs_class = bp_silent; |
3921 | retval.call_dummy = 1; | |
3922 | break; | |
1042e4c0 | 3923 | case bp_tracepoint: |
7a697b8d | 3924 | case bp_fast_tracepoint: |
1042e4c0 SS |
3925 | /* Tracepoint hits should not be reported back to GDB, and |
3926 | if one got through somehow, it should have been filtered | |
3927 | out already. */ | |
3928 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 3929 | _("bpstat_what: tracepoint encountered")); |
1042e4c0 | 3930 | break; |
c906108c | 3931 | } |
c5aa993b | 3932 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3933 | } |
3934 | retval.main_action = current_action; | |
3935 | return retval; | |
3936 | } | |
3937 | ||
3938 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3939 | without hardware support). This isn't related to a specific bpstat, | |
3940 | just to things like whether watchpoints are set. */ | |
3941 | ||
c5aa993b | 3942 | int |
fba45db2 | 3943 | bpstat_should_step (void) |
c906108c SS |
3944 | { |
3945 | struct breakpoint *b; | |
3946 | ALL_BREAKPOINTS (b) | |
717a8278 | 3947 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3948 | return 1; |
c906108c SS |
3949 | return 0; |
3950 | } | |
3951 | ||
67822962 PA |
3952 | int |
3953 | bpstat_causes_stop (bpstat bs) | |
3954 | { | |
3955 | for (; bs != NULL; bs = bs->next) | |
3956 | if (bs->stop) | |
3957 | return 1; | |
3958 | ||
3959 | return 0; | |
3960 | } | |
3961 | ||
c906108c | 3962 | \f |
c5aa993b | 3963 | |
859825b8 JK |
3964 | /* Print the LOC location out of the list of B->LOC locations. */ |
3965 | ||
0d381245 VP |
3966 | static void print_breakpoint_location (struct breakpoint *b, |
3967 | struct bp_location *loc, | |
3968 | char *wrap_indent, | |
3969 | struct ui_stream *stb) | |
3970 | { | |
6c95b8df PA |
3971 | struct cleanup *old_chain = save_current_program_space (); |
3972 | ||
859825b8 JK |
3973 | if (loc != NULL && loc->shlib_disabled) |
3974 | loc = NULL; | |
3975 | ||
6c95b8df PA |
3976 | if (loc != NULL) |
3977 | set_current_program_space (loc->pspace); | |
3978 | ||
859825b8 | 3979 | if (b->source_file && loc) |
0d381245 VP |
3980 | { |
3981 | struct symbol *sym | |
3982 | = find_pc_sect_function (loc->address, loc->section); | |
3983 | if (sym) | |
3984 | { | |
3985 | ui_out_text (uiout, "in "); | |
3986 | ui_out_field_string (uiout, "func", | |
3987 | SYMBOL_PRINT_NAME (sym)); | |
3988 | ui_out_wrap_hint (uiout, wrap_indent); | |
3989 | ui_out_text (uiout, " at "); | |
3990 | } | |
3991 | ui_out_field_string (uiout, "file", b->source_file); | |
3992 | ui_out_text (uiout, ":"); | |
3993 | ||
3994 | if (ui_out_is_mi_like_p (uiout)) | |
3995 | { | |
3996 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3997 | char *fullname = symtab_to_fullname (sal.symtab); | |
3998 | ||
3999 | if (fullname) | |
4000 | ui_out_field_string (uiout, "fullname", fullname); | |
4001 | } | |
4002 | ||
4003 | ui_out_field_int (uiout, "line", b->line_number); | |
4004 | } | |
859825b8 | 4005 | else if (loc) |
0d381245 | 4006 | { |
22e722e1 DJ |
4007 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4008 | demangle, ""); | |
0d381245 VP |
4009 | ui_out_field_stream (uiout, "at", stb); |
4010 | } | |
859825b8 JK |
4011 | else |
4012 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4013 | |
4014 | do_cleanups (old_chain); | |
0d381245 VP |
4015 | } |
4016 | ||
c4093a6a | 4017 | /* Print B to gdb_stdout. */ |
c906108c | 4018 | static void |
0d381245 VP |
4019 | print_one_breakpoint_location (struct breakpoint *b, |
4020 | struct bp_location *loc, | |
4021 | int loc_number, | |
a6d9a66e | 4022 | struct bp_location **last_loc, |
6c95b8df PA |
4023 | int print_address_bits, |
4024 | int allflag) | |
c906108c | 4025 | { |
52f0bd74 AC |
4026 | struct command_line *l; |
4027 | struct symbol *sym; | |
c4093a6a JM |
4028 | struct ep_type_description |
4029 | { | |
4030 | enum bptype type; | |
4031 | char *description; | |
4032 | }; | |
4033 | static struct ep_type_description bptypes[] = | |
c906108c | 4034 | { |
c5aa993b JM |
4035 | {bp_none, "?deleted?"}, |
4036 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4037 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4038 | {bp_until, "until"}, |
4039 | {bp_finish, "finish"}, | |
4040 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4041 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4042 | {bp_read_watchpoint, "read watchpoint"}, |
4043 | {bp_access_watchpoint, "acc watchpoint"}, | |
4044 | {bp_longjmp, "longjmp"}, | |
4045 | {bp_longjmp_resume, "longjmp resume"}, | |
4046 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4047 | {bp_watchpoint_scope, "watchpoint scope"}, |
4048 | {bp_call_dummy, "call dummy"}, | |
4049 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 4050 | {bp_thread_event, "thread events"}, |
1900040c | 4051 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4052 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 4053 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4054 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4055 | {bp_fast_tracepoint, "fast tracepoint"}, |
4efc6507 | 4056 | {bp_jit_event, "jit events"}, |
c5aa993b | 4057 | }; |
c4093a6a | 4058 | |
c2c6d25f | 4059 | static char bpenables[] = "nynny"; |
c906108c | 4060 | char wrap_indent[80]; |
8b93c638 JM |
4061 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4062 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4063 | struct cleanup *bkpt_chain; |
c906108c | 4064 | |
0d381245 VP |
4065 | int header_of_multiple = 0; |
4066 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4067 | struct value_print_options opts; |
4068 | ||
4069 | get_user_print_options (&opts); | |
0d381245 VP |
4070 | |
4071 | gdb_assert (!loc || loc_number != 0); | |
4072 | /* See comment in print_one_breakpoint concerning | |
4073 | treatment of breakpoints with single disabled | |
4074 | location. */ | |
4075 | if (loc == NULL | |
4076 | && (b->loc != NULL | |
4077 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4078 | header_of_multiple = 1; | |
4079 | if (loc == NULL) | |
4080 | loc = b->loc; | |
4081 | ||
c4093a6a | 4082 | annotate_record (); |
3b31d625 | 4083 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4084 | |
4085 | /* 1 */ | |
4086 | annotate_field (0); | |
0d381245 VP |
4087 | if (part_of_multiple) |
4088 | { | |
4089 | char *formatted; | |
0c6773c1 | 4090 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4091 | ui_out_field_string (uiout, "number", formatted); |
4092 | xfree (formatted); | |
4093 | } | |
4094 | else | |
4095 | { | |
4096 | ui_out_field_int (uiout, "number", b->number); | |
4097 | } | |
c4093a6a JM |
4098 | |
4099 | /* 2 */ | |
4100 | annotate_field (1); | |
0d381245 VP |
4101 | if (part_of_multiple) |
4102 | ui_out_field_skip (uiout, "type"); | |
4103 | else | |
4104 | { | |
4105 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4106 | || ((int) b->type != bptypes[(int) b->type].type)) | |
4107 | internal_error (__FILE__, __LINE__, | |
4108 | _("bptypes table does not describe type #%d."), | |
4109 | (int) b->type); | |
4110 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
4111 | } | |
c4093a6a JM |
4112 | |
4113 | /* 3 */ | |
4114 | annotate_field (2); | |
0d381245 VP |
4115 | if (part_of_multiple) |
4116 | ui_out_field_skip (uiout, "disp"); | |
4117 | else | |
2cec12e5 | 4118 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4119 | |
c4093a6a JM |
4120 | |
4121 | /* 4 */ | |
4122 | annotate_field (3); | |
0d381245 | 4123 | if (part_of_multiple) |
54e52265 | 4124 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4125 | else |
54e52265 VP |
4126 | ui_out_field_fmt (uiout, "enabled", "%c", |
4127 | bpenables[(int) b->enable_state]); | |
4128 | ui_out_spaces (uiout, 2); | |
0d381245 | 4129 | |
c4093a6a JM |
4130 | |
4131 | /* 5 and 6 */ | |
4132 | strcpy (wrap_indent, " "); | |
79a45b7d | 4133 | if (opts.addressprint) |
75ac9d7b | 4134 | { |
a6d9a66e | 4135 | if (print_address_bits <= 32) |
75ac9d7b MS |
4136 | strcat (wrap_indent, " "); |
4137 | else | |
4138 | strcat (wrap_indent, " "); | |
4139 | } | |
c906108c | 4140 | |
3086aeae | 4141 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4142 | { |
4143 | /* Although the print_one can possibly print | |
4144 | all locations, calling it here is not likely | |
4145 | to get any nice result. So, make sure there's | |
4146 | just one location. */ | |
4147 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4148 | b->ops->print_one (b, last_loc); |
0d381245 | 4149 | } |
3086aeae DJ |
4150 | else |
4151 | switch (b->type) | |
4152 | { | |
4153 | case bp_none: | |
4154 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4155 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4156 | break; |
c906108c | 4157 | |
3086aeae DJ |
4158 | case bp_watchpoint: |
4159 | case bp_hardware_watchpoint: | |
4160 | case bp_read_watchpoint: | |
4161 | case bp_access_watchpoint: | |
4162 | /* Field 4, the address, is omitted (which makes the columns | |
4163 | not line up too nicely with the headers, but the effect | |
4164 | is relatively readable). */ | |
79a45b7d | 4165 | if (opts.addressprint) |
3086aeae DJ |
4166 | ui_out_field_skip (uiout, "addr"); |
4167 | annotate_field (5); | |
fa8a61dc | 4168 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4169 | break; |
4170 | ||
3086aeae DJ |
4171 | case bp_breakpoint: |
4172 | case bp_hardware_breakpoint: | |
4173 | case bp_until: | |
4174 | case bp_finish: | |
4175 | case bp_longjmp: | |
4176 | case bp_longjmp_resume: | |
4177 | case bp_step_resume: | |
3086aeae DJ |
4178 | case bp_watchpoint_scope: |
4179 | case bp_call_dummy: | |
4180 | case bp_shlib_event: | |
4181 | case bp_thread_event: | |
4182 | case bp_overlay_event: | |
0fd8e87f | 4183 | case bp_longjmp_master: |
1042e4c0 | 4184 | case bp_tracepoint: |
7a697b8d | 4185 | case bp_fast_tracepoint: |
4efc6507 | 4186 | case bp_jit_event: |
79a45b7d | 4187 | if (opts.addressprint) |
3086aeae DJ |
4188 | { |
4189 | annotate_field (4); | |
54e52265 | 4190 | if (header_of_multiple) |
0d381245 | 4191 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4192 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4193 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4194 | else |
5af949e3 UW |
4195 | ui_out_field_core_addr (uiout, "addr", |
4196 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4197 | } |
4198 | annotate_field (5); | |
0d381245 VP |
4199 | if (!header_of_multiple) |
4200 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4201 | if (b->loc) | |
a6d9a66e | 4202 | *last_loc = b->loc; |
3086aeae DJ |
4203 | break; |
4204 | } | |
c906108c | 4205 | |
6c95b8df PA |
4206 | |
4207 | /* For backward compatibility, don't display inferiors unless there | |
4208 | are several. */ | |
4209 | if (loc != NULL | |
4210 | && !header_of_multiple | |
4211 | && (allflag | |
4212 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4213 | && (number_of_program_spaces () > 1 | |
4214 | || number_of_inferiors () > 1) | |
4215 | && loc->owner->type != bp_catchpoint))) | |
4216 | { | |
4217 | struct inferior *inf; | |
4218 | int first = 1; | |
4219 | ||
4220 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4221 | { | |
4222 | if (inf->pspace == loc->pspace) | |
4223 | { | |
4224 | if (first) | |
4225 | { | |
4226 | first = 0; | |
4227 | ui_out_text (uiout, " inf "); | |
4228 | } | |
4229 | else | |
4230 | ui_out_text (uiout, ", "); | |
4231 | ui_out_text (uiout, plongest (inf->num)); | |
4232 | } | |
4233 | } | |
4234 | } | |
4235 | ||
4a306c9a | 4236 | if (!part_of_multiple) |
c4093a6a | 4237 | { |
4a306c9a JB |
4238 | if (b->thread != -1) |
4239 | { | |
4240 | /* FIXME: This seems to be redundant and lost here; see the | |
4241 | "stop only in" line a little further down. */ | |
4242 | ui_out_text (uiout, " thread "); | |
4243 | ui_out_field_int (uiout, "thread", b->thread); | |
4244 | } | |
4245 | else if (b->task != 0) | |
4246 | { | |
4247 | ui_out_text (uiout, " task "); | |
4248 | ui_out_field_int (uiout, "task", b->task); | |
4249 | } | |
c4093a6a JM |
4250 | } |
4251 | ||
8b93c638 | 4252 | ui_out_text (uiout, "\n"); |
c4093a6a | 4253 | |
0d381245 | 4254 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4255 | { |
4256 | annotate_field (6); | |
8b93c638 | 4257 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4258 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4259 | the frame ID. */ | |
5af949e3 UW |
4260 | ui_out_field_core_addr (uiout, "frame", |
4261 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4262 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4263 | } |
4264 | ||
0d381245 | 4265 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4266 | { |
f7f9143b JB |
4267 | /* We do not print the condition for Ada exception catchpoints |
4268 | because the condition is an internal implementation detail | |
4269 | that we do not want to expose to the user. */ | |
c4093a6a | 4270 | annotate_field (7); |
7a697b8d | 4271 | if (tracepoint_type (b)) |
1042e4c0 SS |
4272 | ui_out_text (uiout, "\ttrace only if "); |
4273 | else | |
4274 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4275 | ui_out_field_string (uiout, "cond", b->cond_string); |
4276 | ui_out_text (uiout, "\n"); | |
4277 | } | |
4278 | ||
0d381245 | 4279 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4280 | { |
4281 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4282 | ui_out_text (uiout, "\tstop only in thread "); |
4283 | ui_out_field_int (uiout, "thread", b->thread); | |
4284 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4285 | } |
4286 | ||
63c715c6 | 4287 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4288 | { |
4289 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4290 | if (ep_is_catchpoint (b)) |
4291 | ui_out_text (uiout, "\tcatchpoint"); | |
4292 | else | |
4293 | ui_out_text (uiout, "\tbreakpoint"); | |
4294 | ui_out_text (uiout, " already hit "); | |
4295 | ui_out_field_int (uiout, "times", b->hit_count); | |
4296 | if (b->hit_count == 1) | |
4297 | ui_out_text (uiout, " time\n"); | |
4298 | else | |
4299 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4300 | } |
4301 | ||
fb40c209 AC |
4302 | /* Output the count also if it is zero, but only if this is |
4303 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4304 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4305 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4306 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4307 | |
0d381245 | 4308 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4309 | { |
4310 | annotate_field (8); | |
8b93c638 JM |
4311 | ui_out_text (uiout, "\tignore next "); |
4312 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4313 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4314 | } |
059fb39f PM |
4315 | |
4316 | l = b->commands; | |
4317 | if (!part_of_multiple && l) | |
c4093a6a | 4318 | { |
3b31d625 EZ |
4319 | struct cleanup *script_chain; |
4320 | ||
c4093a6a | 4321 | annotate_field (9); |
3b31d625 | 4322 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4323 | print_command_lines (uiout, l, 4); |
3b31d625 | 4324 | do_cleanups (script_chain); |
c4093a6a | 4325 | } |
d24317b4 | 4326 | |
1042e4c0 SS |
4327 | if (!part_of_multiple && b->pass_count) |
4328 | { | |
4329 | annotate_field (10); | |
4330 | ui_out_text (uiout, "\tpass count "); | |
4331 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4332 | ui_out_text (uiout, " \n"); | |
4333 | } | |
4334 | ||
4335 | if (!part_of_multiple && b->step_count) | |
4336 | { | |
4337 | annotate_field (11); | |
4338 | ui_out_text (uiout, "\tstep count "); | |
4339 | ui_out_field_int (uiout, "step", b->step_count); | |
4340 | ui_out_text (uiout, " \n"); | |
4341 | } | |
4342 | ||
4343 | if (!part_of_multiple && b->actions) | |
4344 | { | |
4345 | struct action_line *action; | |
4346 | annotate_field (12); | |
4347 | for (action = b->actions; action; action = action->next) | |
4348 | { | |
4349 | ui_out_text (uiout, " A\t"); | |
4350 | ui_out_text (uiout, action->action); | |
4351 | ui_out_text (uiout, "\n"); | |
4352 | } | |
4353 | } | |
4354 | ||
d24317b4 VP |
4355 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4356 | { | |
4357 | if (b->addr_string) | |
4358 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4359 | else if (b->exp_string) | |
4360 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4361 | } | |
4362 | ||
3b31d625 | 4363 | do_cleanups (bkpt_chain); |
8b93c638 | 4364 | do_cleanups (old_chain); |
c4093a6a | 4365 | } |
c5aa993b | 4366 | |
0d381245 VP |
4367 | static void |
4368 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4369 | struct bp_location **last_loc, int print_address_bits, |
4370 | int allflag) | |
0d381245 | 4371 | { |
6c95b8df PA |
4372 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4373 | print_address_bits, allflag); | |
0d381245 VP |
4374 | |
4375 | /* If this breakpoint has custom print function, | |
4376 | it's already printed. Otherwise, print individual | |
4377 | locations, if any. */ | |
4378 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4379 | { | |
4380 | /* If breakpoint has a single location that is | |
4381 | disabled, we print it as if it had | |
4382 | several locations, since otherwise it's hard to | |
4383 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4384 | situation. |
4385 | Note that while hardware watchpoints have | |
4386 | several locations internally, that's no a property | |
4387 | exposed to user. */ | |
0d381245 | 4388 | if (b->loc |
a5606eee | 4389 | && !is_hardware_watchpoint (b) |
0d381245 | 4390 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4391 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4392 | { |
4393 | struct bp_location *loc; | |
4394 | int n = 1; | |
4395 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4396 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4397 | print_address_bits, allflag); |
0d381245 VP |
4398 | } |
4399 | } | |
4400 | } | |
4401 | ||
a6d9a66e UW |
4402 | static int |
4403 | breakpoint_address_bits (struct breakpoint *b) | |
4404 | { | |
4405 | int print_address_bits = 0; | |
4406 | struct bp_location *loc; | |
4407 | ||
4408 | for (loc = b->loc; loc; loc = loc->next) | |
4409 | { | |
c561c276 | 4410 | int addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
4411 | if (addr_bit > print_address_bits) |
4412 | print_address_bits = addr_bit; | |
4413 | } | |
4414 | ||
4415 | return print_address_bits; | |
4416 | } | |
0d381245 | 4417 | |
c4093a6a JM |
4418 | struct captured_breakpoint_query_args |
4419 | { | |
4420 | int bnum; | |
4421 | }; | |
c5aa993b | 4422 | |
c4093a6a | 4423 | static int |
2b65245e | 4424 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4425 | { |
4426 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4427 | struct breakpoint *b; |
a6d9a66e | 4428 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4429 | ALL_BREAKPOINTS (b) |
4430 | { | |
4431 | if (args->bnum == b->number) | |
c5aa993b | 4432 | { |
a6d9a66e | 4433 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4434 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4435 | return GDB_RC_OK; |
c5aa993b | 4436 | } |
c4093a6a JM |
4437 | } |
4438 | return GDB_RC_NONE; | |
4439 | } | |
c5aa993b | 4440 | |
c4093a6a | 4441 | enum gdb_rc |
ce43223b | 4442 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4443 | { |
4444 | struct captured_breakpoint_query_args args; | |
4445 | args.bnum = bnum; | |
4446 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4447 | an error. */ | |
b0b13bb4 DJ |
4448 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4449 | error_message, RETURN_MASK_ALL) < 0) | |
4450 | return GDB_RC_FAIL; | |
4451 | else | |
4452 | return GDB_RC_OK; | |
c4093a6a | 4453 | } |
c5aa993b | 4454 | |
7f3b0473 AC |
4455 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4456 | catchpoints, et.al.). */ | |
4457 | ||
4458 | static int | |
4459 | user_settable_breakpoint (const struct breakpoint *b) | |
4460 | { | |
4461 | return (b->type == bp_breakpoint | |
ce78b96d | 4462 | || b->type == bp_catchpoint |
7f3b0473 | 4463 | || b->type == bp_hardware_breakpoint |
7a697b8d | 4464 | || tracepoint_type (b) |
7f3b0473 AC |
4465 | || b->type == bp_watchpoint |
4466 | || b->type == bp_read_watchpoint | |
4467 | || b->type == bp_access_watchpoint | |
4468 | || b->type == bp_hardware_watchpoint); | |
4469 | } | |
4470 | ||
4471 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4472 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4473 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4474 | |
c4093a6a | 4475 | static void |
fba45db2 | 4476 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4477 | { |
52f0bd74 | 4478 | struct breakpoint *b; |
a6d9a66e | 4479 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4480 | int nr_printable_breakpoints; |
3b31d625 | 4481 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4482 | struct value_print_options opts; |
a6d9a66e | 4483 | int print_address_bits = 0; |
c4093a6a | 4484 | |
79a45b7d TT |
4485 | get_user_print_options (&opts); |
4486 | ||
a6d9a66e UW |
4487 | /* Compute the number of rows in the table, as well as the |
4488 | size required for address fields. */ | |
7f3b0473 AC |
4489 | nr_printable_breakpoints = 0; |
4490 | ALL_BREAKPOINTS (b) | |
4491 | if (bnum == -1 | |
4492 | || bnum == b->number) | |
4493 | { | |
4494 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4495 | { |
4496 | int addr_bit = breakpoint_address_bits (b); | |
4497 | if (addr_bit > print_address_bits) | |
4498 | print_address_bits = addr_bit; | |
4499 | ||
4500 | nr_printable_breakpoints++; | |
4501 | } | |
7f3b0473 AC |
4502 | } |
4503 | ||
79a45b7d | 4504 | if (opts.addressprint) |
3b31d625 EZ |
4505 | bkpttbl_chain |
4506 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4507 | "BreakpointTable"); | |
8b93c638 | 4508 | else |
3b31d625 EZ |
4509 | bkpttbl_chain |
4510 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4511 | "BreakpointTable"); | |
8b93c638 | 4512 | |
7f3b0473 | 4513 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4514 | annotate_breakpoints_headers (); |
4515 | if (nr_printable_breakpoints > 0) | |
4516 | annotate_field (0); | |
0d381245 | 4517 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4518 | if (nr_printable_breakpoints > 0) |
4519 | annotate_field (1); | |
4520 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4521 | if (nr_printable_breakpoints > 0) | |
4522 | annotate_field (2); | |
4523 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4524 | if (nr_printable_breakpoints > 0) | |
4525 | annotate_field (3); | |
54e52265 | 4526 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4527 | if (opts.addressprint) |
7f3b0473 | 4528 | { |
d7faa9e7 AC |
4529 | if (nr_printable_breakpoints > 0) |
4530 | annotate_field (4); | |
a6d9a66e | 4531 | if (print_address_bits <= 32) |
b25959ec | 4532 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4533 | else |
b25959ec | 4534 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4535 | } |
d7faa9e7 AC |
4536 | if (nr_printable_breakpoints > 0) |
4537 | annotate_field (5); | |
4538 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4539 | ui_out_table_body (uiout); | |
4540 | if (nr_printable_breakpoints > 0) | |
4541 | annotate_breakpoints_table (); | |
7f3b0473 | 4542 | |
c4093a6a JM |
4543 | ALL_BREAKPOINTS (b) |
4544 | if (bnum == -1 | |
4545 | || bnum == b->number) | |
4546 | { | |
4547 | /* We only print out user settable breakpoints unless the | |
4548 | allflag is set. */ | |
7f3b0473 | 4549 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 4550 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a JM |
4551 | } |
4552 | ||
3b31d625 | 4553 | do_cleanups (bkpttbl_chain); |
698384cd | 4554 | |
7f3b0473 | 4555 | if (nr_printable_breakpoints == 0) |
c906108c | 4556 | { |
8b93c638 JM |
4557 | if (bnum == -1) |
4558 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4559 | else | |
4560 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4561 | bnum); | |
c906108c SS |
4562 | } |
4563 | else | |
c4093a6a | 4564 | { |
a6d9a66e UW |
4565 | if (last_loc && !server_command) |
4566 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4567 | } |
c906108c | 4568 | |
c4093a6a JM |
4569 | /* FIXME? Should this be moved up so that it is only called when |
4570 | there have been breakpoints? */ | |
c906108c SS |
4571 | annotate_breakpoints_table_end (); |
4572 | } | |
4573 | ||
c906108c | 4574 | static void |
fba45db2 | 4575 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4576 | { |
4577 | int bnum = -1; | |
4578 | ||
4579 | if (bnum_exp) | |
bb518678 | 4580 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4581 | |
4582 | breakpoint_1 (bnum, 0); | |
4583 | } | |
4584 | ||
7a292a7a | 4585 | static void |
fba45db2 | 4586 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4587 | { |
4588 | int bnum = -1; | |
4589 | ||
4590 | if (bnum_exp) | |
bb518678 | 4591 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4592 | |
4593 | breakpoint_1 (bnum, 1); | |
4594 | } | |
4595 | ||
0d381245 | 4596 | static int |
714835d5 | 4597 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 4598 | struct program_space *pspace, |
714835d5 | 4599 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
4600 | { |
4601 | struct bp_location *bl = b->loc; | |
4602 | for (; bl; bl = bl->next) | |
4603 | { | |
6c95b8df PA |
4604 | if (bl->pspace == pspace |
4605 | && bl->address == pc | |
0d381245 VP |
4606 | && (!overlay_debugging || bl->section == section)) |
4607 | return 1; | |
4608 | } | |
4609 | return 0; | |
4610 | } | |
4611 | ||
6c95b8df PA |
4612 | /* Print a message describing any breakpoints set at PC. This |
4613 | concerns with logical breakpoints, so we match program spaces, not | |
4614 | address spaces. */ | |
c906108c SS |
4615 | |
4616 | static void | |
6c95b8df PA |
4617 | describe_other_breakpoints (struct gdbarch *gdbarch, |
4618 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 4619 | struct obj_section *section, int thread) |
c906108c | 4620 | { |
52f0bd74 AC |
4621 | int others = 0; |
4622 | struct breakpoint *b; | |
c906108c SS |
4623 | |
4624 | ALL_BREAKPOINTS (b) | |
6c95b8df | 4625 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
4626 | if (others > 0) |
4627 | { | |
a3f17187 AC |
4628 | if (others == 1) |
4629 | printf_filtered (_("Note: breakpoint ")); | |
4630 | else /* if (others == ???) */ | |
4631 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4632 | ALL_BREAKPOINTS (b) |
6c95b8df | 4633 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
4634 | { |
4635 | others--; | |
4636 | printf_filtered ("%d", b->number); | |
4637 | if (b->thread == -1 && thread != -1) | |
4638 | printf_filtered (" (all threads)"); | |
4639 | else if (b->thread != -1) | |
4640 | printf_filtered (" (thread %d)", b->thread); | |
4641 | printf_filtered ("%s%s ", | |
059fb39f | 4642 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4643 | || b->enable_state == bp_call_disabled |
4644 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4645 | ? " (disabled)" |
4646 | : b->enable_state == bp_permanent | |
4647 | ? " (permanent)" | |
4648 | : ""), | |
4649 | (others > 1) ? "," | |
4650 | : ((others == 1) ? " and" : "")); | |
4651 | } | |
a3f17187 | 4652 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4653 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4654 | printf_filtered (".\n"); |
4655 | } | |
4656 | } | |
4657 | \f | |
4658 | /* Set the default place to put a breakpoint | |
4659 | for the `break' command with no arguments. */ | |
4660 | ||
4661 | void | |
6c95b8df PA |
4662 | set_default_breakpoint (int valid, struct program_space *pspace, |
4663 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 4664 | int line) |
c906108c SS |
4665 | { |
4666 | default_breakpoint_valid = valid; | |
6c95b8df | 4667 | default_breakpoint_pspace = pspace; |
c906108c SS |
4668 | default_breakpoint_address = addr; |
4669 | default_breakpoint_symtab = symtab; | |
4670 | default_breakpoint_line = line; | |
4671 | } | |
4672 | ||
e4f237da KB |
4673 | /* Return true iff it is meaningful to use the address member of |
4674 | BPT. For some breakpoint types, the address member is irrelevant | |
4675 | and it makes no sense to attempt to compare it to other addresses | |
4676 | (or use it for any other purpose either). | |
4677 | ||
4678 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
4679 | have a zero valued address and we don't want to mark breakpoints of any of |
4680 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
4681 | |
4682 | bp_watchpoint | |
2d134ed3 PA |
4683 | bp_catchpoint |
4684 | ||
4685 | */ | |
e4f237da KB |
4686 | |
4687 | static int | |
4688 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4689 | { | |
4690 | enum bptype type = bpt->type; | |
4691 | ||
2d134ed3 PA |
4692 | return (type != bp_watchpoint && type != bp_catchpoint); |
4693 | } | |
4694 | ||
4695 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
4696 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
4697 | ||
4698 | static int | |
4699 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
4700 | { | |
4701 | return (loc1->owner->type == loc2->owner->type | |
4702 | && loc1->pspace->aspace == loc2->pspace->aspace | |
4703 | && loc1->address == loc2->address | |
4704 | && loc1->length == loc2->length); | |
e4f237da KB |
4705 | } |
4706 | ||
6c95b8df PA |
4707 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
4708 | same breakpoint location. In most targets, this can only be true | |
4709 | if ASPACE1 matches ASPACE2. On targets that have global | |
4710 | breakpoints, the address space doesn't really matter. */ | |
4711 | ||
4712 | static int | |
4713 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
4714 | struct address_space *aspace2, CORE_ADDR addr2) | |
4715 | { | |
4716 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
4717 | || aspace1 == aspace2) | |
4718 | && addr1 == addr2); | |
4719 | } | |
4720 | ||
2d134ed3 PA |
4721 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
4722 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
4723 | represent the same location. */ | |
4724 | ||
4725 | static int | |
4726 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
4727 | { | |
4728 | int hw_point1 = is_hardware_watchpoint (loc1->owner); | |
4729 | int hw_point2 = is_hardware_watchpoint (loc2->owner); | |
4730 | ||
4731 | if (hw_point1 != hw_point2) | |
4732 | return 0; | |
4733 | else if (hw_point1) | |
4734 | return watchpoint_locations_match (loc1, loc2); | |
4735 | else | |
4736 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
4737 | loc2->pspace->aspace, loc2->address); | |
4738 | } | |
4739 | ||
76897487 KB |
4740 | static void |
4741 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4742 | int bnum, int have_bnum) | |
4743 | { | |
4744 | char astr1[40]; | |
4745 | char astr2[40]; | |
4746 | ||
bb599908 PH |
4747 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4748 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4749 | if (have_bnum) |
8a3fe4f8 | 4750 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4751 | bnum, astr1, astr2); |
4752 | else | |
8a3fe4f8 | 4753 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4754 | } |
4755 | ||
4756 | /* Adjust a breakpoint's address to account for architectural constraints | |
4757 | on breakpoint placement. Return the adjusted address. Note: Very | |
4758 | few targets require this kind of adjustment. For most targets, | |
4759 | this function is simply the identity function. */ | |
4760 | ||
4761 | static CORE_ADDR | |
a6d9a66e UW |
4762 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4763 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4764 | { |
a6d9a66e | 4765 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4766 | { |
4767 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4768 | return bpaddr; | |
4769 | } | |
88f7da05 KB |
4770 | else if (bptype == bp_watchpoint |
4771 | || bptype == bp_hardware_watchpoint | |
4772 | || bptype == bp_read_watchpoint | |
4773 | || bptype == bp_access_watchpoint | |
fe798b75 | 4774 | || bptype == bp_catchpoint) |
88f7da05 KB |
4775 | { |
4776 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4777 | have their addresses modified. */ | |
4778 | return bpaddr; | |
4779 | } | |
76897487 KB |
4780 | else |
4781 | { | |
4782 | CORE_ADDR adjusted_bpaddr; | |
4783 | ||
4784 | /* Some targets have architectural constraints on the placement | |
4785 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4786 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4787 | |
4788 | /* An adjusted breakpoint address can significantly alter | |
4789 | a user's expectations. Print a warning if an adjustment | |
4790 | is required. */ | |
4791 | if (adjusted_bpaddr != bpaddr) | |
4792 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4793 | ||
4794 | return adjusted_bpaddr; | |
4795 | } | |
4796 | } | |
4797 | ||
7cc221ef DJ |
4798 | /* Allocate a struct bp_location. */ |
4799 | ||
26bb91f3 | 4800 | static struct bp_location * |
39d61571 | 4801 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4802 | { |
4803 | struct bp_location *loc, *loc_p; | |
4804 | ||
4805 | loc = xmalloc (sizeof (struct bp_location)); | |
4806 | memset (loc, 0, sizeof (*loc)); | |
4807 | ||
e049a4b5 | 4808 | loc->owner = bpt; |
511a6cd4 | 4809 | loc->cond = NULL; |
0d381245 VP |
4810 | loc->shlib_disabled = 0; |
4811 | loc->enabled = 1; | |
e049a4b5 | 4812 | |
39d61571 | 4813 | switch (bpt->type) |
e049a4b5 DJ |
4814 | { |
4815 | case bp_breakpoint: | |
1042e4c0 | 4816 | case bp_tracepoint: |
7a697b8d | 4817 | case bp_fast_tracepoint: |
e049a4b5 DJ |
4818 | case bp_until: |
4819 | case bp_finish: | |
4820 | case bp_longjmp: | |
4821 | case bp_longjmp_resume: | |
4822 | case bp_step_resume: | |
e049a4b5 DJ |
4823 | case bp_watchpoint_scope: |
4824 | case bp_call_dummy: | |
4825 | case bp_shlib_event: | |
4826 | case bp_thread_event: | |
4827 | case bp_overlay_event: | |
4efc6507 | 4828 | case bp_jit_event: |
0fd8e87f | 4829 | case bp_longjmp_master: |
e049a4b5 DJ |
4830 | loc->loc_type = bp_loc_software_breakpoint; |
4831 | break; | |
4832 | case bp_hardware_breakpoint: | |
4833 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4834 | break; | |
4835 | case bp_hardware_watchpoint: | |
4836 | case bp_read_watchpoint: | |
4837 | case bp_access_watchpoint: | |
4838 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4839 | break; | |
4840 | case bp_watchpoint: | |
ce78b96d | 4841 | case bp_catchpoint: |
e049a4b5 DJ |
4842 | loc->loc_type = bp_loc_other; |
4843 | break; | |
4844 | default: | |
e2e0b3e5 | 4845 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4846 | } |
4847 | ||
7cc221ef DJ |
4848 | return loc; |
4849 | } | |
4850 | ||
fe3f5fa8 VP |
4851 | static void free_bp_location (struct bp_location *loc) |
4852 | { | |
4853 | if (loc->cond) | |
4854 | xfree (loc->cond); | |
74960c60 VP |
4855 | |
4856 | if (loc->function_name) | |
4857 | xfree (loc->function_name); | |
4858 | ||
fe3f5fa8 VP |
4859 | xfree (loc); |
4860 | } | |
4861 | ||
0d381245 VP |
4862 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4863 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4864 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 4865 | |
c40e75cd | 4866 | static struct breakpoint * |
a6d9a66e UW |
4867 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4868 | enum bptype bptype) | |
c906108c | 4869 | { |
52f0bd74 | 4870 | struct breakpoint *b, *b1; |
c906108c SS |
4871 | |
4872 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4873 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4874 | |
4d28f7a8 | 4875 | b->type = bptype; |
a6d9a66e | 4876 | b->gdbarch = gdbarch; |
c906108c SS |
4877 | b->language = current_language->la_language; |
4878 | b->input_radix = input_radix; | |
4879 | b->thread = -1; | |
b5de0fa7 | 4880 | b->enable_state = bp_enabled; |
c906108c SS |
4881 | b->next = 0; |
4882 | b->silent = 0; | |
4883 | b->ignore_count = 0; | |
4884 | b->commands = NULL; | |
818dd999 | 4885 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4886 | b->forked_inferior_pid = null_ptid; |
c906108c | 4887 | b->exec_pathname = NULL; |
a96d9b2e | 4888 | b->syscalls_to_be_caught = NULL; |
3086aeae | 4889 | b->ops = NULL; |
0d381245 | 4890 | b->condition_not_parsed = 0; |
c906108c SS |
4891 | |
4892 | /* Add this breakpoint to the end of the chain | |
4893 | so that a list of breakpoints will come out in order | |
4894 | of increasing numbers. */ | |
4895 | ||
4896 | b1 = breakpoint_chain; | |
4897 | if (b1 == 0) | |
4898 | breakpoint_chain = b; | |
4899 | else | |
4900 | { | |
4901 | while (b1->next) | |
4902 | b1 = b1->next; | |
4903 | b1->next = b; | |
4904 | } | |
0d381245 VP |
4905 | return b; |
4906 | } | |
4907 | ||
4908 | /* Initialize loc->function_name. */ | |
4909 | static void | |
4910 | set_breakpoint_location_function (struct bp_location *loc) | |
4911 | { | |
4912 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 | 4913 | || loc->owner->type == bp_hardware_breakpoint |
7a697b8d | 4914 | || tracepoint_type (loc->owner)) |
0d381245 VP |
4915 | { |
4916 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4917 | NULL, NULL); | |
4918 | if (loc->function_name) | |
4919 | loc->function_name = xstrdup (loc->function_name); | |
4920 | } | |
4921 | } | |
4922 | ||
a6d9a66e UW |
4923 | /* Attempt to determine architecture of location identified by SAL. */ |
4924 | static struct gdbarch * | |
4925 | get_sal_arch (struct symtab_and_line sal) | |
4926 | { | |
4927 | if (sal.section) | |
4928 | return get_objfile_arch (sal.section->objfile); | |
4929 | if (sal.symtab) | |
4930 | return get_objfile_arch (sal.symtab->objfile); | |
4931 | ||
4932 | return NULL; | |
4933 | } | |
4934 | ||
0d381245 VP |
4935 | /* set_raw_breakpoint is a low level routine for allocating and |
4936 | partially initializing a breakpoint of type BPTYPE. The newly | |
4937 | created breakpoint's address, section, source file name, and line | |
4938 | number are provided by SAL. The newly created and partially | |
4939 | initialized breakpoint is added to the breakpoint chain and | |
4940 | is also returned as the value of this function. | |
4941 | ||
4942 | It is expected that the caller will complete the initialization of | |
4943 | the newly created breakpoint struct as well as output any status | |
4944 | information regarding the creation of a new breakpoint. In | |
4945 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4946 | number! Care should be taken to not allow an error to occur | |
4947 | prior to completing the initialization of the breakpoint. If this | |
4948 | should happen, a bogus breakpoint will be left on the chain. */ | |
4949 | ||
63c252f8 | 4950 | struct breakpoint * |
a6d9a66e UW |
4951 | set_raw_breakpoint (struct gdbarch *gdbarch, |
4952 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4953 | { |
a6d9a66e | 4954 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4955 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4956 | struct gdbarch *loc_gdbarch; |
4957 | ||
4958 | loc_gdbarch = get_sal_arch (sal); | |
4959 | if (!loc_gdbarch) | |
4960 | loc_gdbarch = b->gdbarch; | |
0d381245 | 4961 | |
6c95b8df PA |
4962 | if (bptype != bp_catchpoint) |
4963 | gdb_assert (sal.pspace != NULL); | |
4964 | ||
0d381245 VP |
4965 | /* Adjust the breakpoint's address prior to allocating a location. |
4966 | Once we call allocate_bp_location(), that mostly uninitialized | |
4967 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4968 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4969 | not want its scan of the location chain to find a breakpoint and |
4970 | location that's only been partially initialized. */ | |
a6d9a66e | 4971 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4972 | |
39d61571 | 4973 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4974 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4975 | b->loc->requested_address = sal.pc; |
4976 | b->loc->address = adjusted_address; | |
6c95b8df PA |
4977 | b->loc->pspace = sal.pspace; |
4978 | ||
4979 | /* Store the program space that was used to set the breakpoint, for | |
4980 | breakpoint resetting. */ | |
4981 | b->pspace = sal.pspace; | |
0d381245 VP |
4982 | |
4983 | if (sal.symtab == NULL) | |
4984 | b->source_file = NULL; | |
4985 | else | |
1b36a34b | 4986 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4987 | b->loc->section = sal.section; |
4988 | b->line_number = sal.line; | |
4989 | ||
4990 | set_breakpoint_location_function (b->loc); | |
c906108c | 4991 | |
c906108c SS |
4992 | breakpoints_changed (); |
4993 | ||
4994 | return b; | |
4995 | } | |
4996 | ||
c2c6d25f JM |
4997 | |
4998 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4999 | instruction, hard-wired into the inferior's code. */ | |
5000 | void | |
5001 | make_breakpoint_permanent (struct breakpoint *b) | |
5002 | { | |
0d381245 | 5003 | struct bp_location *bl; |
b5de0fa7 | 5004 | b->enable_state = bp_permanent; |
c2c6d25f | 5005 | |
0d381245 VP |
5006 | /* By definition, permanent breakpoints are already present in the code. |
5007 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
5008 | is called in just one place, so it's hard to say if it's reasonable | |
5009 | to have permanent breakpoint with multiple locations or not, | |
5010 | but it's easy to implmement. */ | |
5011 | for (bl = b->loc; bl; bl = bl->next) | |
5012 | bl->inserted = 1; | |
c2c6d25f JM |
5013 | } |
5014 | ||
53a5351d | 5015 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5016 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5017 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5018 | ||
5019 | void | |
0fd8e87f | 5020 | set_longjmp_breakpoint (int thread) |
c906108c | 5021 | { |
0fd8e87f UW |
5022 | struct breakpoint *b, *temp; |
5023 | ||
5024 | /* To avoid having to rescan all objfile symbols at every step, | |
5025 | we maintain a list of continually-inserted but always disabled | |
5026 | longjmp "master" breakpoints. Here, we simply create momentary | |
5027 | clones of those and enable them for the requested thread. */ | |
5028 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5029 | if (b->pspace == current_program_space |
5030 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5031 | { |
5032 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5033 | clone->type = bp_longjmp; | |
5034 | clone->thread = thread; | |
5035 | } | |
c906108c SS |
5036 | } |
5037 | ||
611c83ae | 5038 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5039 | void |
611c83ae | 5040 | delete_longjmp_breakpoint (int thread) |
c906108c | 5041 | { |
611c83ae | 5042 | struct breakpoint *b, *temp; |
c906108c | 5043 | |
611c83ae PA |
5044 | ALL_BREAKPOINTS_SAFE (b, temp) |
5045 | if (b->type == bp_longjmp) | |
5046 | { | |
5047 | if (b->thread == thread) | |
5048 | delete_breakpoint (b); | |
5049 | } | |
c906108c SS |
5050 | } |
5051 | ||
1900040c MS |
5052 | void |
5053 | enable_overlay_breakpoints (void) | |
5054 | { | |
52f0bd74 | 5055 | struct breakpoint *b; |
1900040c MS |
5056 | |
5057 | ALL_BREAKPOINTS (b) | |
5058 | if (b->type == bp_overlay_event) | |
5059 | { | |
5060 | b->enable_state = bp_enabled; | |
b60e7edf | 5061 | update_global_location_list (1); |
c02f5703 | 5062 | overlay_events_enabled = 1; |
1900040c MS |
5063 | } |
5064 | } | |
5065 | ||
5066 | void | |
5067 | disable_overlay_breakpoints (void) | |
5068 | { | |
52f0bd74 | 5069 | struct breakpoint *b; |
1900040c MS |
5070 | |
5071 | ALL_BREAKPOINTS (b) | |
5072 | if (b->type == bp_overlay_event) | |
5073 | { | |
5074 | b->enable_state = bp_disabled; | |
b60e7edf | 5075 | update_global_location_list (0); |
c02f5703 | 5076 | overlay_events_enabled = 0; |
1900040c MS |
5077 | } |
5078 | } | |
5079 | ||
c4093a6a | 5080 | struct breakpoint * |
a6d9a66e | 5081 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5082 | { |
5083 | struct breakpoint *b; | |
c4093a6a | 5084 | |
a6d9a66e | 5085 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5086 | |
b5de0fa7 | 5087 | b->enable_state = bp_enabled; |
c4093a6a | 5088 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5089 | b->addr_string |
5090 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5091 | |
b60e7edf | 5092 | update_global_location_list_nothrow (1); |
74960c60 | 5093 | |
c4093a6a JM |
5094 | return b; |
5095 | } | |
5096 | ||
5097 | void | |
5098 | remove_thread_event_breakpoints (void) | |
5099 | { | |
5100 | struct breakpoint *b, *temp; | |
5101 | ||
5102 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5103 | if (b->type == bp_thread_event |
5104 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5105 | delete_breakpoint (b); |
5106 | } | |
5107 | ||
0101ce28 JJ |
5108 | struct captured_parse_breakpoint_args |
5109 | { | |
5110 | char **arg_p; | |
5111 | struct symtabs_and_lines *sals_p; | |
5112 | char ***addr_string_p; | |
5113 | int *not_found_ptr; | |
5114 | }; | |
5115 | ||
5116 | struct lang_and_radix | |
5117 | { | |
5118 | enum language lang; | |
5119 | int radix; | |
5120 | }; | |
5121 | ||
4efc6507 DE |
5122 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5123 | ||
5124 | struct breakpoint * | |
5125 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5126 | { | |
5127 | struct breakpoint *b; | |
5128 | ||
5129 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5130 | update_global_location_list_nothrow (1); | |
5131 | return b; | |
5132 | } | |
0101ce28 | 5133 | |
cae688ec JJ |
5134 | void |
5135 | remove_solib_event_breakpoints (void) | |
5136 | { | |
5137 | struct breakpoint *b, *temp; | |
5138 | ||
5139 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5140 | if (b->type == bp_shlib_event |
5141 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5142 | delete_breakpoint (b); |
5143 | } | |
5144 | ||
5145 | struct breakpoint * | |
a6d9a66e | 5146 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5147 | { |
5148 | struct breakpoint *b; | |
5149 | ||
a6d9a66e | 5150 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5151 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5152 | return b; |
5153 | } | |
5154 | ||
5155 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5156 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5157 | ||
5158 | void | |
cb851954 | 5159 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5160 | { |
876fa593 | 5161 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5162 | |
876fa593 | 5163 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5164 | { |
0d381245 VP |
5165 | struct breakpoint *b = loc->owner; |
5166 | /* We apply the check to all breakpoints, including disabled | |
5167 | for those with loc->duplicate set. This is so that when breakpoint | |
5168 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5169 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5170 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
5171 | if (((b->type == bp_breakpoint) |
5172 | || (b->type == bp_hardware_breakpoint) | |
7a697b8d | 5173 | || (tracepoint_type (b))) |
6c95b8df | 5174 | && loc->pspace == current_program_space |
0d381245 | 5175 | && !loc->shlib_disabled |
a77053c2 | 5176 | #ifdef PC_SOLIB |
0d381245 | 5177 | && PC_SOLIB (loc->address) |
a77053c2 | 5178 | #else |
6c95b8df | 5179 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5180 | #endif |
5181 | ) | |
0d381245 VP |
5182 | { |
5183 | loc->shlib_disabled = 1; | |
5184 | } | |
cae688ec JJ |
5185 | } |
5186 | } | |
5187 | ||
84acb35a JJ |
5188 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5189 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5190 | ||
75149521 | 5191 | static void |
84acb35a JJ |
5192 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5193 | { | |
876fa593 | 5194 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5195 | int disabled_shlib_breaks = 0; |
5196 | ||
c86cf029 VP |
5197 | /* SunOS a.out shared libraries are always mapped, so do not |
5198 | disable breakpoints; they will only be reported as unloaded | |
5199 | through clear_solib when GDB discards its shared library | |
5200 | list. See clear_solib for more information. */ | |
5201 | if (exec_bfd != NULL | |
5202 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5203 | return; | |
5204 | ||
876fa593 | 5205 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5206 | { |
0d381245 VP |
5207 | struct breakpoint *b = loc->owner; |
5208 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5209 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5210 | && solib->pspace == loc->pspace |
e2dd7057 PP |
5211 | && !loc->shlib_disabled |
5212 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
5213 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 5214 | { |
e2dd7057 PP |
5215 | loc->shlib_disabled = 1; |
5216 | /* At this point, we cannot rely on remove_breakpoint | |
5217 | succeeding so we must mark the breakpoint as not inserted | |
5218 | to prevent future errors occurring in remove_breakpoints. */ | |
5219 | loc->inserted = 0; | |
5220 | if (!disabled_shlib_breaks) | |
5221 | { | |
5222 | target_terminal_ours_for_output (); | |
5223 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5224 | solib->so_name); | |
84acb35a | 5225 | } |
e2dd7057 | 5226 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5227 | } |
5228 | } | |
84acb35a JJ |
5229 | } |
5230 | ||
ce78b96d JB |
5231 | /* FORK & VFORK catchpoints. */ |
5232 | ||
5233 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5234 | ||
c906108c | 5235 | static void |
ce78b96d JB |
5236 | insert_catch_fork (struct breakpoint *b) |
5237 | { | |
5238 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5239 | } | |
5240 | ||
5241 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5242 | ||
5243 | static int | |
5244 | remove_catch_fork (struct breakpoint *b) | |
5245 | { | |
5246 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5247 | } | |
5248 | ||
5249 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5250 | catchpoints. */ | |
5251 | ||
5252 | static int | |
5253 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5254 | { | |
5255 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5256 | } | |
5257 | ||
5258 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5259 | ||
5260 | static enum print_stop_action | |
5261 | print_it_catch_fork (struct breakpoint *b) | |
5262 | { | |
5263 | annotate_catchpoint (b->number); | |
5264 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5265 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5266 | return PRINT_SRC_AND_LOC; | |
5267 | } | |
5268 | ||
5269 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5270 | ||
5271 | static void | |
a6d9a66e | 5272 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5273 | { |
79a45b7d TT |
5274 | struct value_print_options opts; |
5275 | ||
5276 | get_user_print_options (&opts); | |
5277 | ||
ce78b96d JB |
5278 | /* Field 4, the address, is omitted (which makes the columns |
5279 | not line up too nicely with the headers, but the effect | |
5280 | is relatively readable). */ | |
79a45b7d | 5281 | if (opts.addressprint) |
ce78b96d JB |
5282 | ui_out_field_skip (uiout, "addr"); |
5283 | annotate_field (5); | |
5284 | ui_out_text (uiout, "fork"); | |
5285 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5286 | { | |
5287 | ui_out_text (uiout, ", process "); | |
5288 | ui_out_field_int (uiout, "what", | |
5289 | ptid_get_pid (b->forked_inferior_pid)); | |
5290 | ui_out_spaces (uiout, 1); | |
5291 | } | |
5292 | } | |
5293 | ||
5294 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5295 | catchpoints. */ | |
5296 | ||
5297 | static void | |
5298 | print_mention_catch_fork (struct breakpoint *b) | |
5299 | { | |
5300 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5301 | } | |
5302 | ||
5303 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5304 | ||
5305 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5306 | { | |
5307 | insert_catch_fork, | |
5308 | remove_catch_fork, | |
5309 | breakpoint_hit_catch_fork, | |
5310 | print_it_catch_fork, | |
5311 | print_one_catch_fork, | |
5312 | print_mention_catch_fork | |
5313 | }; | |
5314 | ||
5315 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5316 | ||
5317 | static void | |
5318 | insert_catch_vfork (struct breakpoint *b) | |
5319 | { | |
5320 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5321 | } | |
5322 | ||
5323 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5324 | ||
5325 | static int | |
5326 | remove_catch_vfork (struct breakpoint *b) | |
5327 | { | |
5328 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5329 | } | |
5330 | ||
5331 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5332 | catchpoints. */ | |
5333 | ||
5334 | static int | |
5335 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5336 | { | |
5337 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5338 | } | |
5339 | ||
5340 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5341 | ||
5342 | static enum print_stop_action | |
5343 | print_it_catch_vfork (struct breakpoint *b) | |
5344 | { | |
5345 | annotate_catchpoint (b->number); | |
5346 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5347 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5348 | return PRINT_SRC_AND_LOC; | |
5349 | } | |
5350 | ||
5351 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5352 | ||
5353 | static void | |
a6d9a66e | 5354 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5355 | { |
79a45b7d TT |
5356 | struct value_print_options opts; |
5357 | ||
5358 | get_user_print_options (&opts); | |
ce78b96d JB |
5359 | /* Field 4, the address, is omitted (which makes the columns |
5360 | not line up too nicely with the headers, but the effect | |
5361 | is relatively readable). */ | |
79a45b7d | 5362 | if (opts.addressprint) |
ce78b96d JB |
5363 | ui_out_field_skip (uiout, "addr"); |
5364 | annotate_field (5); | |
5365 | ui_out_text (uiout, "vfork"); | |
5366 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5367 | { | |
5368 | ui_out_text (uiout, ", process "); | |
5369 | ui_out_field_int (uiout, "what", | |
5370 | ptid_get_pid (b->forked_inferior_pid)); | |
5371 | ui_out_spaces (uiout, 1); | |
5372 | } | |
5373 | } | |
5374 | ||
5375 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5376 | catchpoints. */ | |
5377 | ||
5378 | static void | |
5379 | print_mention_catch_vfork (struct breakpoint *b) | |
5380 | { | |
5381 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5382 | } | |
5383 | ||
5384 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5385 | ||
5386 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5387 | { | |
5388 | insert_catch_vfork, | |
5389 | remove_catch_vfork, | |
5390 | breakpoint_hit_catch_vfork, | |
5391 | print_it_catch_vfork, | |
5392 | print_one_catch_vfork, | |
5393 | print_mention_catch_vfork | |
5394 | }; | |
5395 | ||
a96d9b2e SDJ |
5396 | /* Implement the "insert" breakpoint_ops method for syscall |
5397 | catchpoints. */ | |
5398 | ||
5399 | static void | |
5400 | insert_catch_syscall (struct breakpoint *b) | |
5401 | { | |
5402 | struct inferior *inf = current_inferior (); | |
5403 | ||
5404 | ++inf->total_syscalls_count; | |
5405 | if (!b->syscalls_to_be_caught) | |
5406 | ++inf->any_syscall_count; | |
5407 | else | |
5408 | { | |
5409 | int i, iter; | |
5410 | for (i = 0; | |
5411 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5412 | i++) | |
5413 | { | |
5414 | int elem; | |
5415 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5416 | { | |
5417 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5418 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5419 | uintptr_t vec_addr; | |
5420 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5421 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5422 | vec_addr_offset; | |
5423 | memset ((void *) vec_addr, 0, | |
5424 | (iter + 1 - old_size) * sizeof (int)); | |
5425 | } | |
5426 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5427 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5428 | } | |
5429 | } | |
5430 | ||
5431 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5432 | inf->total_syscalls_count != 0, | |
5433 | inf->any_syscall_count, | |
5434 | VEC_length (int, inf->syscalls_counts), | |
5435 | VEC_address (int, inf->syscalls_counts)); | |
5436 | } | |
5437 | ||
5438 | /* Implement the "remove" breakpoint_ops method for syscall | |
5439 | catchpoints. */ | |
5440 | ||
5441 | static int | |
5442 | remove_catch_syscall (struct breakpoint *b) | |
5443 | { | |
5444 | struct inferior *inf = current_inferior (); | |
5445 | ||
5446 | --inf->total_syscalls_count; | |
5447 | if (!b->syscalls_to_be_caught) | |
5448 | --inf->any_syscall_count; | |
5449 | else | |
5450 | { | |
5451 | int i, iter; | |
5452 | for (i = 0; | |
5453 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5454 | i++) | |
5455 | { | |
5456 | int elem; | |
5457 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5458 | /* Shouldn't happen. */ | |
5459 | continue; | |
5460 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5461 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5462 | } | |
5463 | } | |
5464 | ||
5465 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5466 | inf->total_syscalls_count != 0, | |
5467 | inf->any_syscall_count, | |
5468 | VEC_length (int, inf->syscalls_counts), | |
5469 | VEC_address (int, inf->syscalls_counts)); | |
5470 | } | |
5471 | ||
5472 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5473 | catchpoints. */ | |
5474 | ||
5475 | static int | |
5476 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5477 | { | |
5478 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5479 | If we are, then we must guarantee that the called syscall is the same | |
5480 | syscall we are catching. */ | |
5481 | int syscall_number = 0; | |
5482 | ||
5483 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5484 | return 0; | |
5485 | ||
5486 | /* Now, checking if the syscall is the same. */ | |
5487 | if (b->syscalls_to_be_caught) | |
5488 | { | |
5489 | int i, iter; | |
5490 | for (i = 0; | |
5491 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5492 | i++) | |
5493 | if (syscall_number == iter) | |
5494 | break; | |
5495 | /* Not the same. */ | |
5496 | if (!iter) | |
5497 | return 0; | |
5498 | } | |
5499 | ||
5500 | return 1; | |
5501 | } | |
5502 | ||
5503 | /* Implement the "print_it" breakpoint_ops method for syscall | |
5504 | catchpoints. */ | |
5505 | ||
5506 | static enum print_stop_action | |
5507 | print_it_catch_syscall (struct breakpoint *b) | |
5508 | { | |
5509 | /* These are needed because we want to know in which state a | |
5510 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
5511 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
5512 | must print "called syscall" or "returned from syscall". */ | |
5513 | ptid_t ptid; | |
5514 | struct target_waitstatus last; | |
5515 | struct syscall s; | |
5516 | struct cleanup *old_chain; | |
5517 | char *syscall_id; | |
5518 | ||
5519 | get_last_target_status (&ptid, &last); | |
5520 | ||
5521 | get_syscall_by_number (last.value.syscall_number, &s); | |
5522 | ||
5523 | annotate_catchpoint (b->number); | |
5524 | ||
5525 | if (s.name == NULL) | |
5526 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
5527 | else | |
5528 | syscall_id = xstrprintf ("'%s'", s.name); | |
5529 | ||
5530 | old_chain = make_cleanup (xfree, syscall_id); | |
5531 | ||
5532 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
5533 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
5534 | b->number, syscall_id); | |
5535 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
5536 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
5537 | b->number, syscall_id); | |
5538 | ||
5539 | do_cleanups (old_chain); | |
5540 | ||
5541 | return PRINT_SRC_AND_LOC; | |
5542 | } | |
5543 | ||
5544 | /* Implement the "print_one" breakpoint_ops method for syscall | |
5545 | catchpoints. */ | |
5546 | ||
5547 | static void | |
5548 | print_one_catch_syscall (struct breakpoint *b, | |
5549 | struct bp_location **last_loc) | |
5550 | { | |
5551 | struct value_print_options opts; | |
5552 | ||
5553 | get_user_print_options (&opts); | |
5554 | /* Field 4, the address, is omitted (which makes the columns | |
5555 | not line up too nicely with the headers, but the effect | |
5556 | is relatively readable). */ | |
5557 | if (opts.addressprint) | |
5558 | ui_out_field_skip (uiout, "addr"); | |
5559 | annotate_field (5); | |
5560 | ||
5561 | if (b->syscalls_to_be_caught | |
5562 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5563 | ui_out_text (uiout, "syscalls \""); | |
5564 | else | |
5565 | ui_out_text (uiout, "syscall \""); | |
5566 | ||
5567 | if (b->syscalls_to_be_caught) | |
5568 | { | |
5569 | int i, iter; | |
5570 | char *text = xstrprintf ("%s", ""); | |
5571 | for (i = 0; | |
5572 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5573 | i++) | |
5574 | { | |
5575 | char *x = text; | |
5576 | struct syscall s; | |
5577 | get_syscall_by_number (iter, &s); | |
5578 | ||
5579 | if (s.name != NULL) | |
5580 | text = xstrprintf ("%s%s, ", text, s.name); | |
5581 | else | |
5582 | text = xstrprintf ("%s%d, ", text, iter); | |
5583 | ||
5584 | /* We have to xfree the last 'text' (now stored at 'x') | |
5585 | because xstrprintf dinamically allocates new space for it | |
5586 | on every call. */ | |
5587 | xfree (x); | |
5588 | } | |
5589 | /* Remove the last comma. */ | |
5590 | text[strlen (text) - 2] = '\0'; | |
5591 | ui_out_field_string (uiout, "what", text); | |
5592 | } | |
5593 | else | |
5594 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
5595 | ui_out_text (uiout, "\" "); | |
5596 | } | |
5597 | ||
5598 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
5599 | catchpoints. */ | |
5600 | ||
5601 | static void | |
5602 | print_mention_catch_syscall (struct breakpoint *b) | |
5603 | { | |
5604 | if (b->syscalls_to_be_caught) | |
5605 | { | |
5606 | int i, iter; | |
5607 | ||
5608 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5609 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
5610 | else | |
5611 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
5612 | ||
5613 | for (i = 0; | |
5614 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5615 | i++) | |
5616 | { | |
5617 | struct syscall s; | |
5618 | get_syscall_by_number (iter, &s); | |
5619 | ||
5620 | if (s.name) | |
5621 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
5622 | else | |
5623 | printf_filtered (" %d", s.number); | |
5624 | } | |
5625 | printf_filtered (")"); | |
5626 | } | |
5627 | else | |
5628 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
5629 | b->number); | |
5630 | } | |
5631 | ||
5632 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
5633 | ||
5634 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
5635 | { | |
5636 | insert_catch_syscall, | |
5637 | remove_catch_syscall, | |
5638 | breakpoint_hit_catch_syscall, | |
5639 | print_it_catch_syscall, | |
5640 | print_one_catch_syscall, | |
5641 | print_mention_catch_syscall | |
5642 | }; | |
5643 | ||
5644 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
5645 | ||
5646 | static int | |
5647 | syscall_catchpoint_p (struct breakpoint *b) | |
5648 | { | |
5649 | return (b->ops == &catch_syscall_breakpoint_ops); | |
5650 | } | |
5651 | ||
5652 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
5653 | but does NOT mention it nor update the global location list. | |
5654 | This is useful if you need to fill more fields in the | |
5655 | struct breakpoint before calling mention. | |
ce78b96d JB |
5656 | |
5657 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5658 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5659 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5660 | to the catchpoint. */ | |
5661 | ||
5662 | static struct breakpoint * | |
a96d9b2e SDJ |
5663 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
5664 | char *cond_string, | |
5665 | struct breakpoint_ops *ops) | |
c906108c | 5666 | { |
c5aa993b JM |
5667 | struct symtab_and_line sal; |
5668 | struct breakpoint *b; | |
c5aa993b | 5669 | |
fe39c653 | 5670 | init_sal (&sal); |
6c95b8df | 5671 | sal.pspace = current_program_space; |
c5aa993b | 5672 | |
a6d9a66e | 5673 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
5674 | set_breakpoint_count (breakpoint_count + 1); |
5675 | b->number = breakpoint_count; | |
ce78b96d | 5676 | |
1b36a34b | 5677 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 5678 | b->thread = -1; |
c906108c | 5679 | b->addr_string = NULL; |
b5de0fa7 EZ |
5680 | b->enable_state = bp_enabled; |
5681 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 5682 | b->ops = ops; |
c5aa993b | 5683 | |
a96d9b2e SDJ |
5684 | return b; |
5685 | } | |
5686 | ||
5687 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
5688 | ||
5689 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5690 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5691 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5692 | to the catchpoint. */ | |
5693 | ||
5694 | static struct breakpoint * | |
5695 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
5696 | char *cond_string, struct breakpoint_ops *ops) | |
5697 | { | |
5698 | struct breakpoint *b = | |
5699 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
5700 | ||
c906108c | 5701 | mention (b); |
ce78b96d | 5702 | update_global_location_list (1); |
c906108c | 5703 | |
ce78b96d | 5704 | return b; |
c906108c | 5705 | } |
c5aa993b | 5706 | |
9b70b993 | 5707 | static void |
a6d9a66e UW |
5708 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
5709 | int tempflag, char *cond_string, | |
ce78b96d | 5710 | struct breakpoint_ops *ops) |
c906108c | 5711 | { |
a6d9a66e UW |
5712 | struct breakpoint *b |
5713 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
5714 | |
5715 | /* FIXME: We should put this information in a breakpoint private data | |
5716 | area. */ | |
5717 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
5718 | } |
5719 | ||
fe798b75 JB |
5720 | /* Exec catchpoints. */ |
5721 | ||
9b70b993 | 5722 | static void |
fe798b75 | 5723 | insert_catch_exec (struct breakpoint *b) |
c906108c | 5724 | { |
fe798b75 JB |
5725 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
5726 | } | |
c906108c | 5727 | |
fe798b75 JB |
5728 | static int |
5729 | remove_catch_exec (struct breakpoint *b) | |
5730 | { | |
5731 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
5732 | } | |
c906108c | 5733 | |
fe798b75 JB |
5734 | static int |
5735 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
5736 | { | |
5737 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
5738 | } | |
c906108c | 5739 | |
fe798b75 JB |
5740 | static enum print_stop_action |
5741 | print_it_catch_exec (struct breakpoint *b) | |
5742 | { | |
5743 | annotate_catchpoint (b->number); | |
5744 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
5745 | b->exec_pathname); | |
5746 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
5747 | } |
5748 | ||
fe798b75 | 5749 | static void |
a6d9a66e | 5750 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
5751 | { |
5752 | struct value_print_options opts; | |
5753 | ||
5754 | get_user_print_options (&opts); | |
5755 | ||
5756 | /* Field 4, the address, is omitted (which makes the columns | |
5757 | not line up too nicely with the headers, but the effect | |
5758 | is relatively readable). */ | |
5759 | if (opts.addressprint) | |
5760 | ui_out_field_skip (uiout, "addr"); | |
5761 | annotate_field (5); | |
5762 | ui_out_text (uiout, "exec"); | |
5763 | if (b->exec_pathname != NULL) | |
5764 | { | |
5765 | ui_out_text (uiout, ", program \""); | |
5766 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5767 | ui_out_text (uiout, "\" "); | |
5768 | } | |
5769 | } | |
5770 | ||
5771 | static void | |
5772 | print_mention_catch_exec (struct breakpoint *b) | |
5773 | { | |
5774 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5775 | } | |
5776 | ||
5777 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5778 | { | |
5779 | insert_catch_exec, | |
5780 | remove_catch_exec, | |
5781 | breakpoint_hit_catch_exec, | |
5782 | print_it_catch_exec, | |
5783 | print_one_catch_exec, | |
5784 | print_mention_catch_exec | |
5785 | }; | |
5786 | ||
a96d9b2e SDJ |
5787 | static void |
5788 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
5789 | struct breakpoint_ops *ops) | |
5790 | { | |
5791 | struct gdbarch *gdbarch = get_current_arch (); | |
5792 | struct breakpoint *b = | |
5793 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
5794 | ||
5795 | b->syscalls_to_be_caught = filter; | |
5796 | ||
5797 | /* Now, we have to mention the breakpoint and update the global | |
5798 | location list. */ | |
5799 | mention (b); | |
5800 | update_global_location_list (1); | |
5801 | } | |
5802 | ||
c906108c | 5803 | static int |
fba45db2 | 5804 | hw_breakpoint_used_count (void) |
c906108c | 5805 | { |
52f0bd74 | 5806 | struct breakpoint *b; |
c906108c SS |
5807 | int i = 0; |
5808 | ||
5809 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5810 | { |
d6b74ac4 | 5811 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5812 | i++; |
5813 | } | |
c906108c SS |
5814 | |
5815 | return i; | |
5816 | } | |
5817 | ||
5818 | static int | |
fba45db2 | 5819 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5820 | { |
52f0bd74 | 5821 | struct breakpoint *b; |
c906108c SS |
5822 | int i = 0; |
5823 | ||
5824 | *other_type_used = 0; | |
5825 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5826 | { |
468d015d | 5827 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5828 | { |
5829 | if (b->type == type) | |
5830 | i++; | |
059fb39f PM |
5831 | else if ((b->type == bp_hardware_watchpoint |
5832 | || b->type == bp_read_watchpoint | |
5833 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5834 | *other_type_used = 1; |
5835 | } | |
5836 | } | |
c906108c SS |
5837 | return i; |
5838 | } | |
5839 | ||
c906108c | 5840 | void |
fba45db2 | 5841 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5842 | { |
c5aa993b | 5843 | struct breakpoint *b; |
c906108c SS |
5844 | |
5845 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5846 | { |
5847 | if (((b->type == bp_watchpoint) | |
5848 | || (b->type == bp_hardware_watchpoint) | |
5849 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5850 | || (b->type == bp_access_watchpoint)) |
468d015d | 5851 | && breakpoint_enabled (b)) |
c5aa993b | 5852 | { |
b5de0fa7 | 5853 | b->enable_state = bp_call_disabled; |
b60e7edf | 5854 | update_global_location_list (0); |
c5aa993b JM |
5855 | } |
5856 | } | |
c906108c SS |
5857 | } |
5858 | ||
5859 | void | |
fba45db2 | 5860 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5861 | { |
c5aa993b | 5862 | struct breakpoint *b; |
c906108c SS |
5863 | |
5864 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5865 | { |
5866 | if (((b->type == bp_watchpoint) | |
5867 | || (b->type == bp_hardware_watchpoint) | |
5868 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5869 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5870 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5871 | { |
b5de0fa7 | 5872 | b->enable_state = bp_enabled; |
b60e7edf | 5873 | update_global_location_list (1); |
c5aa993b JM |
5874 | } |
5875 | } | |
c906108c SS |
5876 | } |
5877 | ||
8bea4e01 UW |
5878 | void |
5879 | disable_breakpoints_before_startup (void) | |
5880 | { | |
5881 | struct breakpoint *b; | |
5882 | int found = 0; | |
5883 | ||
5884 | ALL_BREAKPOINTS (b) | |
5885 | { | |
6c95b8df PA |
5886 | if (b->pspace != current_program_space) |
5887 | continue; | |
5888 | ||
8bea4e01 UW |
5889 | if ((b->type == bp_breakpoint |
5890 | || b->type == bp_hardware_breakpoint) | |
5891 | && breakpoint_enabled (b)) | |
5892 | { | |
5893 | b->enable_state = bp_startup_disabled; | |
5894 | found = 1; | |
5895 | } | |
5896 | } | |
5897 | ||
5898 | if (found) | |
5899 | update_global_location_list (0); | |
5900 | ||
6c95b8df | 5901 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
5902 | } |
5903 | ||
5904 | void | |
5905 | enable_breakpoints_after_startup (void) | |
5906 | { | |
5907 | struct breakpoint *b; | |
5908 | int found = 0; | |
5909 | ||
6c95b8df | 5910 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
5911 | |
5912 | ALL_BREAKPOINTS (b) | |
5913 | { | |
6c95b8df PA |
5914 | if (b->pspace != current_program_space) |
5915 | continue; | |
5916 | ||
8bea4e01 UW |
5917 | if ((b->type == bp_breakpoint |
5918 | || b->type == bp_hardware_breakpoint) | |
5919 | && b->enable_state == bp_startup_disabled) | |
5920 | { | |
5921 | b->enable_state = bp_enabled; | |
5922 | found = 1; | |
5923 | } | |
5924 | } | |
5925 | ||
5926 | if (found) | |
5927 | breakpoint_re_set (); | |
5928 | } | |
5929 | ||
c906108c SS |
5930 | |
5931 | /* Set a breakpoint that will evaporate an end of command | |
5932 | at address specified by SAL. | |
5933 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5934 | ||
5935 | struct breakpoint * | |
a6d9a66e UW |
5936 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5937 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5938 | { |
52f0bd74 | 5939 | struct breakpoint *b; |
edb3359d DJ |
5940 | |
5941 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5942 | one. */ | |
5943 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5944 | ||
a6d9a66e | 5945 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5946 | b->enable_state = bp_enabled; |
5947 | b->disposition = disp_donttouch; | |
818dd999 | 5948 | b->frame_id = frame_id; |
c906108c SS |
5949 | |
5950 | /* If we're debugging a multi-threaded program, then we | |
5951 | want momentary breakpoints to be active in only a | |
5952 | single thread of control. */ | |
39f77062 KB |
5953 | if (in_thread_list (inferior_ptid)) |
5954 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5955 | |
b60e7edf | 5956 | update_global_location_list_nothrow (1); |
74960c60 | 5957 | |
c906108c SS |
5958 | return b; |
5959 | } | |
611c83ae | 5960 | |
e58b0e63 PA |
5961 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5962 | ORIG is NULL. */ | |
5963 | ||
5964 | struct breakpoint * | |
5965 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5966 | { | |
5967 | struct breakpoint *copy; | |
5968 | ||
5969 | /* If there's nothing to clone, then return nothing. */ | |
5970 | if (orig == NULL) | |
5971 | return NULL; | |
5972 | ||
a6d9a66e | 5973 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5974 | copy->loc = allocate_bp_location (copy); |
5975 | set_breakpoint_location_function (copy->loc); | |
5976 | ||
a6d9a66e | 5977 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5978 | copy->loc->requested_address = orig->loc->requested_address; |
5979 | copy->loc->address = orig->loc->address; | |
5980 | copy->loc->section = orig->loc->section; | |
6c95b8df | 5981 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
5982 | |
5983 | if (orig->source_file == NULL) | |
5984 | copy->source_file = NULL; | |
5985 | else | |
5986 | copy->source_file = xstrdup (orig->source_file); | |
5987 | ||
5988 | copy->line_number = orig->line_number; | |
5989 | copy->frame_id = orig->frame_id; | |
5990 | copy->thread = orig->thread; | |
6c95b8df | 5991 | copy->pspace = orig->pspace; |
e58b0e63 PA |
5992 | |
5993 | copy->enable_state = bp_enabled; | |
5994 | copy->disposition = disp_donttouch; | |
5995 | copy->number = internal_breakpoint_number--; | |
5996 | ||
5997 | update_global_location_list_nothrow (0); | |
5998 | return copy; | |
5999 | } | |
6000 | ||
611c83ae | 6001 | struct breakpoint * |
a6d9a66e UW |
6002 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6003 | enum bptype type) | |
611c83ae PA |
6004 | { |
6005 | struct symtab_and_line sal; | |
6006 | ||
6007 | sal = find_pc_line (pc, 0); | |
6008 | sal.pc = pc; | |
6009 | sal.section = find_pc_overlay (pc); | |
6010 | sal.explicit_pc = 1; | |
6011 | ||
a6d9a66e | 6012 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6013 | } |
c906108c | 6014 | \f |
c5aa993b | 6015 | |
c906108c SS |
6016 | /* Tell the user we have just set a breakpoint B. */ |
6017 | ||
6018 | static void | |
fba45db2 | 6019 | mention (struct breakpoint *b) |
c906108c SS |
6020 | { |
6021 | int say_where = 0; | |
fa8a61dc | 6022 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6023 | struct value_print_options opts; |
6024 | ||
6025 | get_user_print_options (&opts); | |
8b93c638 | 6026 | |
9a4105ab AC |
6027 | /* FIXME: This is misplaced; mention() is called by things (like |
6028 | hitting a watchpoint) other than breakpoint creation. It should | |
6029 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6030 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6031 | observer_notify_breakpoint_created (b->number); |
c906108c | 6032 | |
3086aeae DJ |
6033 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6034 | b->ops->print_mention (b); | |
6035 | else | |
6036 | switch (b->type) | |
6037 | { | |
6038 | case bp_none: | |
a3f17187 | 6039 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6040 | break; |
6041 | case bp_watchpoint: | |
6042 | ui_out_text (uiout, "Watchpoint "); | |
6043 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6044 | ui_out_field_int (uiout, "number", b->number); | |
6045 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6046 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6047 | do_cleanups (ui_out_chain); |
6048 | break; | |
6049 | case bp_hardware_watchpoint: | |
6050 | ui_out_text (uiout, "Hardware watchpoint "); | |
6051 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6052 | ui_out_field_int (uiout, "number", b->number); | |
6053 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6054 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6055 | do_cleanups (ui_out_chain); |
6056 | break; | |
6057 | case bp_read_watchpoint: | |
6058 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6059 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6060 | ui_out_field_int (uiout, "number", b->number); | |
6061 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6062 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6063 | do_cleanups (ui_out_chain); |
6064 | break; | |
6065 | case bp_access_watchpoint: | |
6066 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6067 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6068 | ui_out_field_int (uiout, "number", b->number); | |
6069 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6070 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6071 | do_cleanups (ui_out_chain); |
6072 | break; | |
6073 | case bp_breakpoint: | |
6074 | if (ui_out_is_mi_like_p (uiout)) | |
6075 | { | |
6076 | say_where = 0; | |
6077 | break; | |
6078 | } | |
2cec12e5 AR |
6079 | if (b->disposition == disp_del) |
6080 | printf_filtered (_("Temporary breakpoint")); | |
6081 | else | |
6082 | printf_filtered (_("Breakpoint")); | |
6083 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6084 | say_where = 1; |
6085 | break; | |
6086 | case bp_hardware_breakpoint: | |
6087 | if (ui_out_is_mi_like_p (uiout)) | |
6088 | { | |
6089 | say_where = 0; | |
6090 | break; | |
6091 | } | |
a3f17187 | 6092 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6093 | say_where = 1; |
6094 | break; | |
1042e4c0 SS |
6095 | case bp_tracepoint: |
6096 | if (ui_out_is_mi_like_p (uiout)) | |
6097 | { | |
6098 | say_where = 0; | |
6099 | break; | |
6100 | } | |
6101 | printf_filtered (_("Tracepoint")); | |
6102 | printf_filtered (_(" %d"), b->number); | |
6103 | say_where = 1; | |
6104 | break; | |
7a697b8d SS |
6105 | case bp_fast_tracepoint: |
6106 | if (ui_out_is_mi_like_p (uiout)) | |
6107 | { | |
6108 | say_where = 0; | |
6109 | break; | |
6110 | } | |
6111 | printf_filtered (_("Fast tracepoint")); | |
6112 | printf_filtered (_(" %d"), b->number); | |
6113 | say_where = 1; | |
6114 | break; | |
3086aeae DJ |
6115 | |
6116 | case bp_until: | |
6117 | case bp_finish: | |
6118 | case bp_longjmp: | |
6119 | case bp_longjmp_resume: | |
6120 | case bp_step_resume: | |
3086aeae DJ |
6121 | case bp_call_dummy: |
6122 | case bp_watchpoint_scope: | |
6123 | case bp_shlib_event: | |
6124 | case bp_thread_event: | |
6125 | case bp_overlay_event: | |
4efc6507 | 6126 | case bp_jit_event: |
0fd8e87f | 6127 | case bp_longjmp_master: |
3086aeae DJ |
6128 | break; |
6129 | } | |
c906108c | 6130 | |
c906108c SS |
6131 | if (say_where) |
6132 | { | |
a3f17187 AC |
6133 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6134 | single string. */ | |
0d381245 | 6135 | if (b->loc == NULL) |
c906108c | 6136 | { |
a3f17187 | 6137 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6138 | } |
6139 | else | |
6140 | { | |
79a45b7d | 6141 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6142 | { |
6143 | printf_filtered (" at "); | |
5af949e3 UW |
6144 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6145 | gdb_stdout); | |
0101ce28 JJ |
6146 | } |
6147 | if (b->source_file) | |
6148 | printf_filtered (": file %s, line %d.", | |
6149 | b->source_file, b->line_number); | |
0d381245 VP |
6150 | |
6151 | if (b->loc->next) | |
6152 | { | |
6153 | struct bp_location *loc = b->loc; | |
6154 | int n = 0; | |
6155 | for (; loc; loc = loc->next) | |
6156 | ++n; | |
6157 | printf_filtered (" (%d locations)", n); | |
6158 | } | |
6159 | ||
c906108c | 6160 | } |
c906108c | 6161 | } |
9dc5e2a9 | 6162 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6163 | return; |
c906108c SS |
6164 | printf_filtered ("\n"); |
6165 | } | |
c906108c | 6166 | \f |
c5aa993b | 6167 | |
0d381245 | 6168 | static struct bp_location * |
39d61571 | 6169 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6170 | const struct symtab_and_line *sal) |
6171 | { | |
6172 | struct bp_location *loc, **tmp; | |
6173 | ||
39d61571 | 6174 | loc = allocate_bp_location (b); |
0d381245 VP |
6175 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6176 | ; | |
6177 | *tmp = loc; | |
a6d9a66e UW |
6178 | loc->gdbarch = get_sal_arch (*sal); |
6179 | if (!loc->gdbarch) | |
6180 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6181 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6182 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6183 | loc->requested_address, b->type); | |
6c95b8df PA |
6184 | loc->pspace = sal->pspace; |
6185 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6186 | loc->section = sal->section; |
6187 | ||
6188 | set_breakpoint_location_function (loc); | |
6189 | return loc; | |
6190 | } | |
514f746b AR |
6191 | \f |
6192 | ||
6193 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6194 | return 0 otherwise. */ | |
6195 | ||
6196 | static int | |
6197 | bp_loc_is_permanent (struct bp_location *loc) | |
6198 | { | |
6199 | int len; | |
6200 | CORE_ADDR addr; | |
6201 | const gdb_byte *brk; | |
6202 | gdb_byte *target_mem; | |
939c61fa JK |
6203 | struct cleanup *cleanup; |
6204 | int retval = 0; | |
514f746b AR |
6205 | |
6206 | gdb_assert (loc != NULL); | |
6207 | ||
6208 | addr = loc->address; | |
a6d9a66e | 6209 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6210 | |
939c61fa JK |
6211 | /* Software breakpoints unsupported? */ |
6212 | if (brk == NULL) | |
6213 | return 0; | |
6214 | ||
514f746b AR |
6215 | target_mem = alloca (len); |
6216 | ||
939c61fa JK |
6217 | /* Enable the automatic memory restoration from breakpoints while |
6218 | we read the memory. Otherwise we could say about our temporary | |
6219 | breakpoints they are permanent. */ | |
6c95b8df PA |
6220 | cleanup = save_current_space_and_thread (); |
6221 | ||
6222 | switch_to_program_space_and_thread (loc->pspace); | |
6223 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6224 | |
514f746b AR |
6225 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6226 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6227 | retval = 1; |
514f746b | 6228 | |
939c61fa JK |
6229 | do_cleanups (cleanup); |
6230 | ||
6231 | return retval; | |
514f746b AR |
6232 | } |
6233 | ||
6234 | ||
c3f6f71d | 6235 | |
018d34a4 VP |
6236 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6237 | as textual description of the location, and COND_STRING | |
db107f19 | 6238 | as condition expression. */ |
018d34a4 VP |
6239 | |
6240 | static void | |
a6d9a66e UW |
6241 | create_breakpoint (struct gdbarch *gdbarch, |
6242 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
6243 | char *cond_string, |
6244 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 6245 | int thread, int task, int ignore_count, |
41447f92 | 6246 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 6247 | { |
0d381245 VP |
6248 | struct breakpoint *b = NULL; |
6249 | int i; | |
018d34a4 VP |
6250 | |
6251 | if (type == bp_hardware_breakpoint) | |
6252 | { | |
6253 | int i = hw_breakpoint_used_count (); | |
6254 | int target_resources_ok = | |
d92524f1 | 6255 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6256 | i + 1, 0); |
6257 | if (target_resources_ok == 0) | |
6258 | error (_("No hardware breakpoint support in the target.")); | |
6259 | else if (target_resources_ok < 0) | |
6260 | error (_("Hardware breakpoints used exceeds limit.")); | |
6261 | } | |
6262 | ||
6c95b8df PA |
6263 | gdb_assert (sals.nelts > 0); |
6264 | ||
0d381245 VP |
6265 | for (i = 0; i < sals.nelts; ++i) |
6266 | { | |
6267 | struct symtab_and_line sal = sals.sals[i]; | |
6268 | struct bp_location *loc; | |
6269 | ||
6270 | if (from_tty) | |
5af949e3 UW |
6271 | { |
6272 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6273 | if (!loc_gdbarch) | |
6274 | loc_gdbarch = gdbarch; | |
6275 | ||
6276 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6277 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6278 | } |
0d381245 VP |
6279 | |
6280 | if (i == 0) | |
6281 | { | |
a6d9a66e | 6282 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6283 | set_breakpoint_count (breakpoint_count + 1); |
6284 | b->number = breakpoint_count; | |
6285 | b->thread = thread; | |
4a306c9a | 6286 | b->task = task; |
018d34a4 | 6287 | |
0d381245 VP |
6288 | b->cond_string = cond_string; |
6289 | b->ignore_count = ignore_count; | |
41447f92 | 6290 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6291 | b->disposition = disposition; |
018d34a4 | 6292 | |
6c95b8df PA |
6293 | b->pspace = sals.sals[0].pspace; |
6294 | ||
6295 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6296 | && (b->type == bp_breakpoint |
6297 | || b->type == bp_hardware_breakpoint)) | |
6298 | b->enable_state = bp_startup_disabled; | |
6299 | ||
0d381245 VP |
6300 | loc = b->loc; |
6301 | } | |
6302 | else | |
018d34a4 | 6303 | { |
39d61571 | 6304 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6305 | } |
6306 | ||
514f746b AR |
6307 | if (bp_loc_is_permanent (loc)) |
6308 | make_breakpoint_permanent (b); | |
6309 | ||
0d381245 VP |
6310 | if (b->cond_string) |
6311 | { | |
6312 | char *arg = b->cond_string; | |
d32a6982 | 6313 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6314 | if (*arg) |
db107f19 | 6315 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6316 | } |
0d381245 | 6317 | } |
018d34a4 VP |
6318 | |
6319 | if (addr_string) | |
6320 | b->addr_string = addr_string; | |
6321 | else | |
6322 | /* addr_string has to be used or breakpoint_re_set will delete | |
6323 | me. */ | |
5af949e3 UW |
6324 | b->addr_string |
6325 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6326 | |
604133b5 | 6327 | b->ops = ops; |
018d34a4 VP |
6328 | mention (b); |
6329 | } | |
6330 | ||
ed0616c6 VP |
6331 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6332 | elements to fill the void space. */ | |
2c0b251b PA |
6333 | static void |
6334 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6335 | { |
6336 | int i = index_to_remove+1; | |
6337 | int last_index = sal->nelts-1; | |
6338 | ||
6339 | for (;i <= last_index; ++i) | |
6340 | sal->sals[i-1] = sal->sals[i]; | |
6341 | ||
6342 | --(sal->nelts); | |
6343 | } | |
6344 | ||
6c95b8df PA |
6345 | /* If appropriate, obtains all sals that correspond to the same file |
6346 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6347 | will want to set a breakpoint at foo.c:line, and not really care | |
6348 | about program spaces. This is done only if SAL does not have | |
6349 | explicit PC and has line and file information. If we got just a | |
6350 | single expanded sal, return the original. | |
ed0616c6 | 6351 | |
6c95b8df PA |
6352 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6353 | which the name of enclosing function is different from SAL. This | |
6354 | makes sure that if we have breakpoint originally set in template | |
6355 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6356 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6357 | |
2c0b251b | 6358 | static struct symtabs_and_lines |
ed0616c6 VP |
6359 | expand_line_sal_maybe (struct symtab_and_line sal) |
6360 | { | |
6361 | struct symtabs_and_lines expanded; | |
6362 | CORE_ADDR original_pc = sal.pc; | |
6363 | char *original_function = NULL; | |
6364 | int found; | |
6365 | int i; | |
6c95b8df | 6366 | struct cleanup *old_chain; |
ed0616c6 VP |
6367 | |
6368 | /* If we have explicit pc, don't expand. | |
6369 | If we have no line number, we can't expand. */ | |
6370 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6371 | { | |
6372 | expanded.nelts = 1; | |
6373 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6374 | expanded.sals[0] = sal; | |
6375 | return expanded; | |
6376 | } | |
6377 | ||
6378 | sal.pc = 0; | |
6c95b8df PA |
6379 | |
6380 | old_chain = save_current_space_and_thread (); | |
6381 | ||
6382 | switch_to_program_space_and_thread (sal.pspace); | |
6383 | ||
ed0616c6 | 6384 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6385 | |
6386 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6387 | expanded = expand_line_sal (sal); |
6c95b8df | 6388 | |
ed0616c6 VP |
6389 | if (expanded.nelts == 1) |
6390 | { | |
3dba1c98 JB |
6391 | /* We had one sal, we got one sal. Return that sal, adjusting it |
6392 | past the function prologue if necessary. */ | |
ed0616c6 VP |
6393 | xfree (expanded.sals); |
6394 | expanded.nelts = 1; | |
6395 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6396 | sal.pc = original_pc; | |
6397 | expanded.sals[0] = sal; | |
3dba1c98 | 6398 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 6399 | do_cleanups (old_chain); |
ed0616c6 VP |
6400 | return expanded; |
6401 | } | |
6402 | ||
6403 | if (!sal.explicit_line) | |
6404 | { | |
6405 | CORE_ADDR func_addr, func_end; | |
6406 | for (i = 0; i < expanded.nelts; ++i) | |
6407 | { | |
6408 | CORE_ADDR pc = expanded.sals[i].pc; | |
6409 | char *this_function; | |
6c95b8df PA |
6410 | |
6411 | /* We need to switch threads as well since we're about to | |
6412 | read memory. */ | |
6413 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6414 | ||
ed0616c6 VP |
6415 | if (find_pc_partial_function (pc, &this_function, |
6416 | &func_addr, &func_end)) | |
6417 | { | |
059fb39f PM |
6418 | if (this_function |
6419 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6420 | { |
6421 | remove_sal (&expanded, i); | |
6422 | --i; | |
6423 | } | |
6424 | else if (func_addr == pc) | |
6425 | { | |
6426 | /* We're at beginning of a function, and should | |
6427 | skip prologue. */ | |
6428 | struct symbol *sym = find_pc_function (pc); | |
6429 | if (sym) | |
6430 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
6431 | else | |
d80b854b UW |
6432 | { |
6433 | /* Since find_pc_partial_function returned true, | |
6434 | we should really always find the section here. */ | |
6435 | struct obj_section *section = find_pc_section (pc); | |
6436 | if (section) | |
6437 | { | |
6438 | struct gdbarch *gdbarch | |
6439 | = get_objfile_arch (section->objfile); | |
6440 | expanded.sals[i].pc | |
6441 | = gdbarch_skip_prologue (gdbarch, pc); | |
6442 | } | |
6443 | } | |
ed0616c6 VP |
6444 | } |
6445 | } | |
6446 | } | |
6447 | } | |
3daf8fe5 JG |
6448 | else |
6449 | { | |
6450 | for (i = 0; i < expanded.nelts; ++i) | |
6451 | { | |
6452 | /* If this SAL corresponds to a breakpoint inserted using a | |
6453 | line number, then skip the function prologue if necessary. */ | |
6454 | skip_prologue_sal (&expanded.sals[i]); | |
6455 | } | |
6456 | } | |
ed0616c6 | 6457 | |
6c95b8df PA |
6458 | do_cleanups (old_chain); |
6459 | ||
ed0616c6 VP |
6460 | if (expanded.nelts <= 1) |
6461 | { | |
6462 | /* This is un ugly workaround. If we get zero | |
6463 | expanded sals then something is really wrong. | |
6464 | Fix that by returnign the original sal. */ | |
6465 | xfree (expanded.sals); | |
6466 | expanded.nelts = 1; | |
6467 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6468 | sal.pc = original_pc; | |
6469 | expanded.sals[0] = sal; | |
6470 | return expanded; | |
6471 | } | |
6472 | ||
6473 | if (original_pc) | |
6474 | { | |
6475 | found = 0; | |
6476 | for (i = 0; i < expanded.nelts; ++i) | |
6477 | if (expanded.sals[i].pc == original_pc) | |
6478 | { | |
6479 | found = 1; | |
6480 | break; | |
6481 | } | |
6482 | gdb_assert (found); | |
6483 | } | |
6484 | ||
6485 | return expanded; | |
6486 | } | |
6487 | ||
018d34a4 VP |
6488 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6489 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6490 | value. COND_STRING, if not NULL, specified the condition to be | |
6491 | used for all breakpoints. Essentially the only case where | |
6492 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6493 | function. In that case, it's still not possible to specify | |
6494 | separate conditions for different overloaded functions, so | |
6495 | we take just a single condition string. | |
6496 | ||
c3f6f71d | 6497 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 6498 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
6499 | array contents). If the function fails (error() is called), the |
6500 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
6501 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
6502 | |
6503 | static void | |
a6d9a66e UW |
6504 | create_breakpoints (struct gdbarch *gdbarch, |
6505 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 6506 | char *cond_string, |
c3f6f71d | 6507 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 6508 | int thread, int task, int ignore_count, |
41447f92 VP |
6509 | struct breakpoint_ops *ops, int from_tty, |
6510 | int enabled) | |
c906108c | 6511 | { |
018d34a4 VP |
6512 | int i; |
6513 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 6514 | { |
ed0616c6 VP |
6515 | struct symtabs_and_lines expanded = |
6516 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 6517 | |
a6d9a66e | 6518 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 6519 | cond_string, type, disposition, |
4a306c9a | 6520 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 6521 | } |
c3f6f71d | 6522 | } |
c906108c | 6523 | |
c3f6f71d JM |
6524 | /* Parse ARG which is assumed to be a SAL specification possibly |
6525 | followed by conditionals. On return, SALS contains an array of SAL | |
6526 | addresses found. ADDR_STRING contains a vector of (canonical) | |
6527 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 6528 | |
b9362cc7 | 6529 | static void |
c3f6f71d JM |
6530 | parse_breakpoint_sals (char **address, |
6531 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
6532 | char ***addr_string, |
6533 | int *not_found_ptr) | |
c3f6f71d JM |
6534 | { |
6535 | char *addr_start = *address; | |
6536 | *addr_string = NULL; | |
6537 | /* If no arg given, or if first arg is 'if ', use the default | |
6538 | breakpoint. */ | |
6539 | if ((*address) == NULL | |
6540 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
6541 | { |
6542 | if (default_breakpoint_valid) | |
6543 | { | |
c3f6f71d | 6544 | struct symtab_and_line sal; |
fe39c653 | 6545 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 6546 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
6547 | xmalloc (sizeof (struct symtab_and_line)); |
6548 | sal.pc = default_breakpoint_address; | |
6549 | sal.line = default_breakpoint_line; | |
6550 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 6551 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 6552 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
6553 | |
6554 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
6555 | the default_breakpoint_address. So make sure to set | |
6556 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
6557 | sals to include all other instances with the same symtab and line. | |
6558 | */ | |
6559 | sal.explicit_pc = 1; | |
6560 | ||
c3f6f71d JM |
6561 | sals->sals[0] = sal; |
6562 | sals->nelts = 1; | |
c906108c SS |
6563 | } |
6564 | else | |
8a3fe4f8 | 6565 | error (_("No default breakpoint address now.")); |
c906108c SS |
6566 | } |
6567 | else | |
6568 | { | |
c906108c | 6569 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
6570 | current_source_symtab (which is decode_line_1's default). This |
6571 | should produce the results we want almost all of the time while | |
1aeae86e AF |
6572 | leaving default_breakpoint_* alone. |
6573 | ObjC: However, don't match an Objective-C method name which | |
6574 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 6575 | |
c214a6fd | 6576 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 6577 | |
c906108c | 6578 | if (default_breakpoint_valid |
0378c332 | 6579 | && (!cursal.symtab |
1aeae86e AF |
6580 | || ((strchr ("+-", (*address)[0]) != NULL) |
6581 | && ((*address)[1] != '[')))) | |
c3f6f71d | 6582 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
6583 | default_breakpoint_line, addr_string, |
6584 | not_found_ptr); | |
c906108c | 6585 | else |
0101ce28 JJ |
6586 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
6587 | addr_string, not_found_ptr); | |
c906108c | 6588 | } |
c3f6f71d JM |
6589 | /* For any SAL that didn't have a canonical string, fill one in. */ |
6590 | if (sals->nelts > 0 && *addr_string == NULL) | |
6591 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
6592 | if (addr_start != (*address)) | |
c906108c | 6593 | { |
c3f6f71d JM |
6594 | int i; |
6595 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 6596 | { |
c3f6f71d JM |
6597 | /* Add the string if not present. */ |
6598 | if ((*addr_string)[i] == NULL) | |
6599 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
6600 | } |
6601 | } | |
c3f6f71d | 6602 | } |
c906108c | 6603 | |
c906108c | 6604 | |
c3f6f71d JM |
6605 | /* Convert each SAL into a real PC. Verify that the PC can be |
6606 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 6607 | |
b9362cc7 | 6608 | static void |
c3f6f71d JM |
6609 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
6610 | char *address) | |
6611 | { | |
6612 | int i; | |
6613 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 6614 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
6615 | } |
6616 | ||
7a697b8d SS |
6617 | /* Fast tracepoints may have restrictions on valid locations. For |
6618 | instance, a fast tracepoint using a jump instead of a trap will | |
6619 | likely have to overwrite more bytes than a trap would, and so can | |
6620 | only be placed where the instruction is longer than the jump, or a | |
6621 | multi-instruction sequence does not have a jump into the middle of | |
6622 | it, etc. */ | |
6623 | ||
6624 | static void | |
6625 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6626 | struct symtabs_and_lines *sals) | |
6627 | { | |
6628 | int i, rslt; | |
6629 | struct symtab_and_line *sal; | |
6630 | char *msg; | |
6631 | struct cleanup *old_chain; | |
6632 | ||
6633 | for (i = 0; i < sals->nelts; i++) | |
6634 | { | |
6635 | sal = &sals->sals[i]; | |
6636 | ||
6637 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
6638 | NULL, &msg); | |
6639 | old_chain = make_cleanup (xfree, msg); | |
6640 | ||
6641 | if (!rslt) | |
6642 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
6643 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
6644 | ||
6645 | do_cleanups (old_chain); | |
6646 | } | |
6647 | } | |
6648 | ||
05ff989b | 6649 | static void |
0101ce28 JJ |
6650 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
6651 | { | |
6652 | struct captured_parse_breakpoint_args *args = data; | |
6653 | ||
6654 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
6655 | args->not_found_ptr); | |
0101ce28 JJ |
6656 | } |
6657 | ||
018d34a4 VP |
6658 | /* Given TOK, a string specification of condition and thread, as |
6659 | accepted by the 'break' command, extract the condition | |
6660 | string and thread number and set *COND_STRING and *THREAD. | |
6661 | PC identifies the context at which the condition should be parsed. | |
6662 | If no condition is found, *COND_STRING is set to NULL. | |
6663 | If no thread is found, *THREAD is set to -1. */ | |
6664 | static void | |
6665 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 6666 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
6667 | { |
6668 | *cond_string = NULL; | |
6669 | *thread = -1; | |
6670 | while (tok && *tok) | |
6671 | { | |
6672 | char *end_tok; | |
6673 | int toklen; | |
6674 | char *cond_start = NULL; | |
6675 | char *cond_end = NULL; | |
6676 | while (*tok == ' ' || *tok == '\t') | |
6677 | tok++; | |
6678 | ||
6679 | end_tok = tok; | |
6680 | ||
6681 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6682 | end_tok++; | |
6683 | ||
6684 | toklen = end_tok - tok; | |
6685 | ||
6686 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6687 | { | |
f7545552 TT |
6688 | struct expression *expr; |
6689 | ||
018d34a4 | 6690 | tok = cond_start = end_tok + 1; |
f7545552 TT |
6691 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
6692 | xfree (expr); | |
018d34a4 VP |
6693 | cond_end = tok; |
6694 | *cond_string = savestring (cond_start, | |
6695 | cond_end - cond_start); | |
6696 | } | |
6697 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6698 | { | |
6699 | char *tmptok; | |
6700 | ||
6701 | tok = end_tok + 1; | |
6702 | tmptok = tok; | |
6703 | *thread = strtol (tok, &tok, 0); | |
6704 | if (tok == tmptok) | |
6705 | error (_("Junk after thread keyword.")); | |
6706 | if (!valid_thread_id (*thread)) | |
6707 | error (_("Unknown thread %d."), *thread); | |
6708 | } | |
4a306c9a JB |
6709 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
6710 | { | |
6711 | char *tmptok; | |
6712 | ||
6713 | tok = end_tok + 1; | |
6714 | tmptok = tok; | |
6715 | *task = strtol (tok, &tok, 0); | |
6716 | if (tok == tmptok) | |
6717 | error (_("Junk after task keyword.")); | |
6718 | if (!valid_task_id (*task)) | |
b6199126 | 6719 | error (_("Unknown task %d."), *task); |
4a306c9a | 6720 | } |
018d34a4 VP |
6721 | else |
6722 | error (_("Junk at end of arguments.")); | |
6723 | } | |
6724 | } | |
6725 | ||
72b2ff0e VP |
6726 | /* Set a breakpoint. This function is shared between |
6727 | CLI and MI functions for setting a breakpoint. | |
6728 | This function has two major modes of operations, | |
6729 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
6730 | If non-zero, the function will parse arg, extracting | |
6731 | breakpoint location, address and thread. Otherwise, | |
6732 | ARG is just the location of breakpoint, with condition | |
6733 | and thread specified by the COND_STRING and THREAD | |
6734 | parameters. */ | |
0101ce28 | 6735 | |
98deb0da | 6736 | static void |
a6d9a66e UW |
6737 | break_command_really (struct gdbarch *gdbarch, |
6738 | char *arg, char *cond_string, int thread, | |
60c46647 | 6739 | int parse_condition_and_thread, |
1042e4c0 | 6740 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
6741 | int ignore_count, |
6742 | enum auto_boolean pending_break_support, | |
604133b5 | 6743 | struct breakpoint_ops *ops, |
41447f92 VP |
6744 | int from_tty, |
6745 | int enabled) | |
c3f6f71d | 6746 | { |
71fff37b | 6747 | struct gdb_exception e; |
c3f6f71d | 6748 | struct symtabs_and_lines sals; |
0101ce28 | 6749 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
6750 | char *copy_arg; |
6751 | char *err_msg; | |
c3f6f71d JM |
6752 | char *addr_start = arg; |
6753 | char **addr_string; | |
6754 | struct cleanup *old_chain; | |
80c99de1 | 6755 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 6756 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 6757 | int i; |
0101ce28 | 6758 | int pending = 0; |
0101ce28 | 6759 | int not_found = 0; |
1042e4c0 | 6760 | enum bptype type_wanted; |
4a306c9a | 6761 | int task = 0; |
c3f6f71d | 6762 | |
c3f6f71d JM |
6763 | sals.sals = NULL; |
6764 | sals.nelts = 0; | |
6765 | addr_string = NULL; | |
c3f6f71d | 6766 | |
0101ce28 JJ |
6767 | parse_args.arg_p = &arg; |
6768 | parse_args.sals_p = &sals; | |
6769 | parse_args.addr_string_p = &addr_string; | |
6770 | parse_args.not_found_ptr = ¬_found; | |
6771 | ||
05ff989b AC |
6772 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
6773 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
6774 | |
6775 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 6776 | switch (e.reason) |
0101ce28 | 6777 | { |
05ff989b | 6778 | case RETURN_QUIT: |
98deb0da | 6779 | throw_exception (e); |
05ff989b AC |
6780 | case RETURN_ERROR: |
6781 | switch (e.error) | |
0101ce28 | 6782 | { |
05ff989b | 6783 | case NOT_FOUND_ERROR: |
0101ce28 | 6784 | |
05ff989b AC |
6785 | /* If pending breakpoint support is turned off, throw |
6786 | error. */ | |
fa8d40ab JJ |
6787 | |
6788 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
6789 | throw_exception (e); |
6790 | ||
6791 | exception_print (gdb_stderr, e); | |
fa8d40ab | 6792 | |
05ff989b AC |
6793 | /* If pending breakpoint support is auto query and the user |
6794 | selects no, then simply return the error code. */ | |
059fb39f PM |
6795 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
6796 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 6797 | return; |
fa8d40ab | 6798 | |
05ff989b AC |
6799 | /* At this point, either the user was queried about setting |
6800 | a pending breakpoint and selected yes, or pending | |
6801 | breakpoint behavior is on and thus a pending breakpoint | |
6802 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
6803 | copy_arg = xstrdup (addr_start); |
6804 | addr_string = ©_arg; | |
6805 | sals.nelts = 1; | |
6806 | sals.sals = &pending_sal; | |
6807 | pending_sal.pc = 0; | |
6808 | pending = 1; | |
05ff989b AC |
6809 | break; |
6810 | default: | |
98deb0da | 6811 | throw_exception (e); |
0101ce28 | 6812 | } |
05ff989b AC |
6813 | default: |
6814 | if (!sals.nelts) | |
98deb0da | 6815 | return; |
0101ce28 | 6816 | } |
c3f6f71d JM |
6817 | |
6818 | /* Create a chain of things that always need to be cleaned up. */ | |
6819 | old_chain = make_cleanup (null_cleanup, 0); | |
6820 | ||
0101ce28 JJ |
6821 | if (!pending) |
6822 | { | |
6823 | /* Make sure that all storage allocated to SALS gets freed. */ | |
6824 | make_cleanup (xfree, sals.sals); | |
6825 | ||
6826 | /* Cleanup the addr_string array but not its contents. */ | |
6827 | make_cleanup (xfree, addr_string); | |
6828 | } | |
c3f6f71d | 6829 | |
c3f6f71d JM |
6830 | /* ----------------------------- SNIP ----------------------------- |
6831 | Anything added to the cleanup chain beyond this point is assumed | |
6832 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
6833 | then the memory is not reclaimed. */ |
6834 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
6835 | |
6836 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 6837 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
6838 | for (i = 0; i < sals.nelts; i++) |
6839 | { | |
6840 | if (addr_string[i] != NULL) | |
b8c9b27d | 6841 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
6842 | } |
6843 | ||
6844 | /* Resolve all line numbers to PC's and verify that the addresses | |
6845 | are ok for the target. */ | |
0101ce28 JJ |
6846 | if (!pending) |
6847 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 6848 | |
1042e4c0 | 6849 | type_wanted = (traceflag |
7a697b8d | 6850 | ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint) |
1042e4c0 SS |
6851 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); |
6852 | ||
7a697b8d SS |
6853 | /* Fast tracepoints may have additional restrictions on location. */ |
6854 | if (type_wanted == bp_fast_tracepoint) | |
6855 | check_fast_tracepoint_sals (gdbarch, &sals); | |
6856 | ||
c3f6f71d JM |
6857 | /* Verify that condition can be parsed, before setting any |
6858 | breakpoints. Allocate a separate condition expression for each | |
6859 | breakpoint. */ | |
0101ce28 | 6860 | if (!pending) |
c3f6f71d | 6861 | { |
2f069f6f | 6862 | if (parse_condition_and_thread) |
72b2ff0e VP |
6863 | { |
6864 | /* Here we only parse 'arg' to separate condition | |
6865 | from thread number, so parsing in context of first | |
6866 | sal is OK. When setting the breakpoint we'll | |
6867 | re-parse it in context of each sal. */ | |
6868 | cond_string = NULL; | |
6869 | thread = -1; | |
4a306c9a JB |
6870 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
6871 | &thread, &task); | |
72b2ff0e VP |
6872 | if (cond_string) |
6873 | make_cleanup (xfree, cond_string); | |
6874 | } | |
2f069f6f | 6875 | else |
72b2ff0e VP |
6876 | { |
6877 | /* Create a private copy of condition string. */ | |
6878 | if (cond_string) | |
6879 | { | |
6880 | cond_string = xstrdup (cond_string); | |
6881 | make_cleanup (xfree, cond_string); | |
6882 | } | |
6883 | } | |
a6d9a66e | 6884 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 6885 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 6886 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 6887 | } |
0101ce28 JJ |
6888 | else |
6889 | { | |
fe3f5fa8 | 6890 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
6891 | struct breakpoint *b; |
6892 | ||
0101ce28 JJ |
6893 | make_cleanup (xfree, copy_arg); |
6894 | ||
a6d9a66e | 6895 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
6896 | set_breakpoint_count (breakpoint_count + 1); |
6897 | b->number = breakpoint_count; | |
72b2ff0e | 6898 | b->thread = -1; |
018d34a4 | 6899 | b->addr_string = addr_string[0]; |
72b2ff0e | 6900 | b->cond_string = NULL; |
0101ce28 | 6901 | b->ignore_count = ignore_count; |
0101ce28 | 6902 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 6903 | b->condition_not_parsed = 1; |
604133b5 | 6904 | b->ops = ops; |
41447f92 | 6905 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 6906 | b->pspace = current_program_space; |
74960c60 | 6907 | |
6c95b8df | 6908 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
6909 | && (b->type == bp_breakpoint |
6910 | || b->type == bp_hardware_breakpoint)) | |
6911 | b->enable_state = bp_startup_disabled; | |
6912 | ||
0101ce28 JJ |
6913 | mention (b); |
6914 | } | |
6915 | ||
c3f6f71d | 6916 | if (sals.nelts > 1) |
8a3fe4f8 AC |
6917 | warning (_("Multiple breakpoints were set.\n" |
6918 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6919 | /* That's it. Discard the cleanups for data inserted into the |
6920 | breakpoint. */ | |
6921 | discard_cleanups (bkpt_chain); | |
6922 | /* But cleanup everything else. */ | |
c3f6f71d | 6923 | do_cleanups (old_chain); |
217dc9e2 | 6924 | |
80c99de1 | 6925 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6926 | update_global_location_list (1); |
c3f6f71d | 6927 | } |
c906108c | 6928 | |
72b2ff0e VP |
6929 | /* Set a breakpoint. |
6930 | ARG is a string describing breakpoint address, | |
6931 | condition, and thread. | |
6932 | FLAG specifies if a breakpoint is hardware on, | |
6933 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6934 | and BP_TEMPFLAG. */ | |
6935 | ||
98deb0da | 6936 | static void |
72b2ff0e | 6937 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6938 | { |
72b2ff0e VP |
6939 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6940 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6941 | |
a6d9a66e UW |
6942 | break_command_really (get_current_arch (), |
6943 | arg, | |
98deb0da | 6944 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6945 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6946 | 0 /* Ignore count */, |
604133b5 AR |
6947 | pending_break_support, |
6948 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6949 | from_tty, |
6950 | 1 /* enabled */); | |
c906108c SS |
6951 | } |
6952 | ||
72b2ff0e | 6953 | |
98deb0da | 6954 | void |
a6d9a66e UW |
6955 | set_breakpoint (struct gdbarch *gdbarch, |
6956 | char *address, char *condition, | |
c3f6f71d | 6957 | int hardwareflag, int tempflag, |
ce43223b | 6958 | int thread, int ignore_count, |
41447f92 | 6959 | int pending, int enabled) |
c3f6f71d | 6960 | { |
a6d9a66e UW |
6961 | break_command_really (gdbarch, |
6962 | address, condition, thread, | |
98deb0da | 6963 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6964 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6965 | ignore_count, |
6966 | pending | |
6967 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6968 | NULL, 0, enabled); |
c3f6f71d JM |
6969 | } |
6970 | ||
6a048695 JB |
6971 | /* Adjust SAL to the first instruction past the function prologue. |
6972 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6973 | the debugging information. explicit_pc and explicit_line are |
6974 | not modified. | |
6a048695 JB |
6975 | |
6976 | If SAL is already past the prologue, then do nothing. */ | |
6977 | ||
6978 | static void | |
6979 | skip_prologue_sal (struct symtab_and_line *sal) | |
6980 | { | |
6c95b8df | 6981 | struct symbol *sym; |
6a048695 | 6982 | struct symtab_and_line start_sal; |
6c95b8df | 6983 | struct cleanup *old_chain; |
6a048695 | 6984 | |
6c95b8df | 6985 | old_chain = save_current_space_and_thread (); |
6a048695 | 6986 | |
6c95b8df PA |
6987 | sym = find_pc_function (sal->pc); |
6988 | if (sym != NULL) | |
3daf8fe5 | 6989 | { |
6c95b8df PA |
6990 | start_sal = find_function_start_sal (sym, 1); |
6991 | if (sal->pc < start_sal.pc) | |
6992 | { | |
6993 | start_sal.explicit_line = sal->explicit_line; | |
6994 | start_sal.explicit_pc = sal->explicit_pc; | |
6995 | *sal = start_sal; | |
6996 | } | |
3daf8fe5 | 6997 | } |
6c95b8df PA |
6998 | |
6999 | do_cleanups (old_chain); | |
6a048695 | 7000 | } |
c3f6f71d | 7001 | |
c906108c SS |
7002 | /* Helper function for break_command_1 and disassemble_command. */ |
7003 | ||
7004 | void | |
fba45db2 | 7005 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7006 | { |
7007 | CORE_ADDR pc; | |
7008 | ||
7009 | if (sal->pc == 0 && sal->symtab != NULL) | |
7010 | { | |
7011 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7012 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7013 | sal->line, sal->symtab->filename); |
7014 | sal->pc = pc; | |
6a048695 JB |
7015 | |
7016 | /* If this SAL corresponds to a breakpoint inserted using | |
7017 | a line number, then skip the function prologue if necessary. */ | |
7018 | if (sal->explicit_line) | |
56ef84b1 TT |
7019 | { |
7020 | /* Preserve the original line number. */ | |
7021 | int saved_line = sal->line; | |
7022 | skip_prologue_sal (sal); | |
7023 | sal->line = saved_line; | |
7024 | } | |
c906108c SS |
7025 | } |
7026 | ||
7027 | if (sal->section == 0 && sal->symtab != NULL) | |
7028 | { | |
7029 | struct blockvector *bv; | |
c5aa993b JM |
7030 | struct block *b; |
7031 | struct symbol *sym; | |
c906108c | 7032 | |
801e3a5b | 7033 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7034 | if (bv != NULL) |
7035 | { | |
7f0df278 | 7036 | sym = block_linkage_function (b); |
c906108c SS |
7037 | if (sym != NULL) |
7038 | { | |
7039 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7040 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7041 | } |
7042 | else | |
7043 | { | |
7044 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
7045 | have to look harder. This case can be executed if we have |
7046 | line numbers but no functions (as can happen in assembly | |
7047 | source). */ | |
c906108c | 7048 | |
c5aa993b | 7049 | struct minimal_symbol *msym; |
6c95b8df PA |
7050 | struct cleanup *old_chain = save_current_space_and_thread (); |
7051 | ||
7052 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
7053 | |
7054 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7055 | if (msym) | |
714835d5 | 7056 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7057 | |
7058 | do_cleanups (old_chain); | |
c906108c SS |
7059 | } |
7060 | } | |
7061 | } | |
7062 | } | |
7063 | ||
7064 | void | |
fba45db2 | 7065 | break_command (char *arg, int from_tty) |
c906108c | 7066 | { |
db107f19 | 7067 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7068 | } |
7069 | ||
c906108c | 7070 | void |
fba45db2 | 7071 | tbreak_command (char *arg, int from_tty) |
c906108c | 7072 | { |
db107f19 | 7073 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7074 | } |
7075 | ||
c906108c | 7076 | static void |
fba45db2 | 7077 | hbreak_command (char *arg, int from_tty) |
c906108c | 7078 | { |
db107f19 | 7079 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7080 | } |
7081 | ||
7082 | static void | |
fba45db2 | 7083 | thbreak_command (char *arg, int from_tty) |
c906108c | 7084 | { |
db107f19 | 7085 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7086 | } |
7087 | ||
7088 | static void | |
fba45db2 | 7089 | stop_command (char *arg, int from_tty) |
c906108c | 7090 | { |
a3f17187 | 7091 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7092 | Usage: stop in <function | address>\n\ |
a3f17187 | 7093 | stop at <line>\n")); |
c906108c SS |
7094 | } |
7095 | ||
7096 | static void | |
fba45db2 | 7097 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7098 | { |
7099 | int badInput = 0; | |
7100 | ||
c5aa993b | 7101 | if (arg == (char *) NULL) |
c906108c SS |
7102 | badInput = 1; |
7103 | else if (*arg != '*') | |
7104 | { | |
7105 | char *argptr = arg; | |
7106 | int hasColon = 0; | |
7107 | ||
53a5351d JM |
7108 | /* look for a ':'. If this is a line number specification, then |
7109 | say it is bad, otherwise, it should be an address or | |
7110 | function/method name */ | |
c906108c | 7111 | while (*argptr && !hasColon) |
c5aa993b JM |
7112 | { |
7113 | hasColon = (*argptr == ':'); | |
7114 | argptr++; | |
7115 | } | |
c906108c SS |
7116 | |
7117 | if (hasColon) | |
c5aa993b | 7118 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7119 | else |
c5aa993b | 7120 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7121 | } |
7122 | ||
7123 | if (badInput) | |
a3f17187 | 7124 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7125 | else |
db107f19 | 7126 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7127 | } |
7128 | ||
7129 | static void | |
fba45db2 | 7130 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7131 | { |
7132 | int badInput = 0; | |
7133 | ||
c5aa993b | 7134 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7135 | badInput = 1; |
7136 | else | |
7137 | { | |
7138 | char *argptr = arg; | |
7139 | int hasColon = 0; | |
7140 | ||
7141 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7142 | it is probably a line number. */ |
c906108c | 7143 | while (*argptr && !hasColon) |
c5aa993b JM |
7144 | { |
7145 | hasColon = (*argptr == ':'); | |
7146 | argptr++; | |
7147 | } | |
c906108c SS |
7148 | |
7149 | if (hasColon) | |
c5aa993b | 7150 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7151 | else |
c5aa993b | 7152 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7153 | } |
7154 | ||
7155 | if (badInput) | |
a3f17187 | 7156 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7157 | else |
db107f19 | 7158 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7159 | } |
7160 | ||
53a5351d JM |
7161 | /* accessflag: hw_write: watch write, |
7162 | hw_read: watch read, | |
7163 | hw_access: watch access (read or write) */ | |
c906108c | 7164 | static void |
fba45db2 | 7165 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 7166 | { |
a6d9a66e | 7167 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 7168 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
7169 | struct expression *exp; |
7170 | struct block *exp_valid_block; | |
7171 | struct value *val, *mark; | |
7172 | struct frame_info *frame; | |
c906108c SS |
7173 | char *exp_start = NULL; |
7174 | char *exp_end = NULL; | |
37e4754d | 7175 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
7176 | int toklen; |
7177 | char *cond_start = NULL; | |
7178 | char *cond_end = NULL; | |
c906108c SS |
7179 | int i, other_type_used, target_resources_ok = 0; |
7180 | enum bptype bp_type; | |
7181 | int mem_cnt = 0; | |
37e4754d | 7182 | int thread = -1; |
c906108c | 7183 | |
37e4754d LM |
7184 | /* Make sure that we actually have parameters to parse. */ |
7185 | if (arg != NULL && arg[0] != '\0') | |
7186 | { | |
7187 | toklen = strlen (arg); /* Size of argument list. */ | |
7188 | ||
7189 | /* Points tok to the end of the argument list. */ | |
7190 | tok = arg + toklen - 1; | |
7191 | ||
7192 | /* Go backwards in the parameters list. Skip the last parameter. | |
7193 | If we're expecting a 'thread <thread_num>' parameter, this should | |
7194 | be the thread identifier. */ | |
7195 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7196 | tok--; | |
7197 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7198 | tok--; | |
7199 | ||
7200 | /* Points end_tok to the beginning of the last token. */ | |
7201 | id_tok_start = tok + 1; | |
7202 | ||
7203 | /* Go backwards in the parameters list. Skip one more parameter. | |
7204 | If we're expecting a 'thread <thread_num>' parameter, we should | |
7205 | reach a "thread" token. */ | |
7206 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7207 | tok--; | |
7208 | ||
7209 | end_tok = tok; | |
7210 | ||
7211 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7212 | tok--; | |
7213 | ||
7214 | /* Move the pointer forward to skip the whitespace and | |
7215 | calculate the length of the token. */ | |
7216 | tok++; | |
7217 | toklen = end_tok - tok; | |
7218 | ||
7219 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7220 | { | |
7221 | /* At this point we've found a "thread" token, which means | |
7222 | the user is trying to set a watchpoint that triggers | |
7223 | only in a specific thread. */ | |
7224 | char *endp; | |
7225 | ||
7226 | /* Extract the thread ID from the next token. */ | |
7227 | thread = strtol (id_tok_start, &endp, 0); | |
7228 | ||
7229 | /* Check if the user provided a valid numeric value for the | |
7230 | thread ID. */ | |
7231 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7232 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7233 | ||
7234 | /* Check if the thread actually exists. */ | |
7235 | if (!valid_thread_id (thread)) | |
7236 | error (_("Unknown thread %d."), thread); | |
7237 | ||
7238 | /* Truncate the string and get rid of the thread <thread_num> | |
7239 | parameter before the parameter list is parsed by the | |
7240 | evaluate_expression() function. */ | |
7241 | *tok = '\0'; | |
7242 | } | |
7243 | } | |
7244 | ||
7245 | /* Parse the rest of the arguments. */ | |
c906108c SS |
7246 | innermost_block = NULL; |
7247 | exp_start = arg; | |
7248 | exp = parse_exp_1 (&arg, 0, 0); | |
7249 | exp_end = arg; | |
fa8a61dc TT |
7250 | /* Remove trailing whitespace from the expression before saving it. |
7251 | This makes the eventual display of the expression string a bit | |
7252 | prettier. */ | |
7253 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7254 | --exp_end; | |
7255 | ||
c906108c SS |
7256 | exp_valid_block = innermost_block; |
7257 | mark = value_mark (); | |
fa4727a6 DJ |
7258 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7259 | if (val != NULL) | |
7260 | release_value (val); | |
c906108c SS |
7261 | |
7262 | tok = arg; | |
7263 | while (*tok == ' ' || *tok == '\t') | |
7264 | tok++; | |
7265 | end_tok = tok; | |
7266 | ||
7267 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7268 | end_tok++; | |
7269 | ||
7270 | toklen = end_tok - tok; | |
7271 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7272 | { | |
2d134ed3 PA |
7273 | struct expression *cond; |
7274 | ||
c906108c SS |
7275 | tok = cond_start = end_tok + 1; |
7276 | cond = parse_exp_1 (&tok, 0, 0); | |
2d134ed3 | 7277 | xfree (cond); |
c906108c SS |
7278 | cond_end = tok; |
7279 | } | |
7280 | if (*tok) | |
8a3fe4f8 | 7281 | error (_("Junk at end of command.")); |
c906108c | 7282 | |
53a5351d | 7283 | if (accessflag == hw_read) |
c5aa993b | 7284 | bp_type = bp_read_watchpoint; |
53a5351d | 7285 | else if (accessflag == hw_access) |
c5aa993b JM |
7286 | bp_type = bp_access_watchpoint; |
7287 | else | |
7288 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7289 | |
7290 | mem_cnt = can_use_hardware_watchpoint (val); | |
7291 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7292 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7293 | if (mem_cnt != 0) |
7294 | { | |
7295 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7296 | target_resources_ok = |
d92524f1 | 7297 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7298 | other_type_used); |
c5aa993b | 7299 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7300 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7301 | |
c5aa993b | 7302 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7303 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7304 | } |
c906108c | 7305 | |
4d28f7a8 KB |
7306 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7307 | watchpoint could not be set. */ | |
7308 | if (!mem_cnt || target_resources_ok <= 0) | |
7309 | bp_type = bp_watchpoint; | |
7310 | ||
d983da9c | 7311 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7312 | |
7313 | /* If the expression is "local", then set up a "watchpoint scope" | |
7314 | breakpoint at the point where we've left the scope of the watchpoint | |
7315 | expression. Create the scope breakpoint before the watchpoint, so | |
7316 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 7317 | if (innermost_block && frame) |
d983da9c | 7318 | { |
edb3359d DJ |
7319 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7320 | { | |
7321 | scope_breakpoint | |
a6d9a66e UW |
7322 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7323 | frame_unwind_caller_pc (frame), | |
edb3359d | 7324 | bp_watchpoint_scope); |
d983da9c | 7325 | |
edb3359d | 7326 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7327 | |
edb3359d DJ |
7328 | /* Automatically delete the breakpoint when it hits. */ |
7329 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7330 | |
edb3359d DJ |
7331 | /* Only break in the proper frame (help with recursion). */ |
7332 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7333 | |
edb3359d | 7334 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7335 | scope_breakpoint->loc->gdbarch |
7336 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7337 | scope_breakpoint->loc->requested_address |
7338 | = frame_unwind_caller_pc (frame); | |
7339 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7340 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7341 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7342 | scope_breakpoint->type); |
7343 | } | |
d983da9c DJ |
7344 | } |
7345 | ||
c906108c | 7346 | /* Now set up the breakpoint. */ |
2d134ed3 | 7347 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
7348 | set_breakpoint_count (breakpoint_count + 1); |
7349 | b->number = breakpoint_count; | |
37e4754d | 7350 | b->thread = thread; |
b5de0fa7 | 7351 | b->disposition = disp_donttouch; |
c906108c SS |
7352 | b->exp = exp; |
7353 | b->exp_valid_block = exp_valid_block; | |
7354 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
7355 | b->val = val; | |
fa4727a6 | 7356 | b->val_valid = 1; |
c906108c SS |
7357 | if (cond_start) |
7358 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7359 | else | |
7360 | b->cond_string = 0; | |
c5aa993b | 7361 | |
c906108c | 7362 | if (frame) |
f6bc2008 PA |
7363 | { |
7364 | b->watchpoint_frame = get_frame_id (frame); | |
7365 | b->watchpoint_thread = inferior_ptid; | |
7366 | } | |
c906108c | 7367 | else |
f6bc2008 PA |
7368 | { |
7369 | b->watchpoint_frame = null_frame_id; | |
7370 | b->watchpoint_thread = null_ptid; | |
7371 | } | |
c906108c | 7372 | |
d983da9c | 7373 | if (scope_breakpoint != NULL) |
c906108c | 7374 | { |
d983da9c DJ |
7375 | /* The scope breakpoint is related to the watchpoint. We will |
7376 | need to act on them together. */ | |
7377 | b->related_breakpoint = scope_breakpoint; | |
7378 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7379 | } |
d983da9c | 7380 | |
c906108c | 7381 | value_free_to_mark (mark); |
2d134ed3 PA |
7382 | |
7383 | /* Finally update the new watchpoint. This creates the locations | |
7384 | that should be inserted. */ | |
7385 | update_watchpoint (b, 1); | |
7386 | ||
c906108c | 7387 | mention (b); |
b60e7edf | 7388 | update_global_location_list (1); |
c906108c SS |
7389 | } |
7390 | ||
7391 | /* Return count of locations need to be watched and can be handled | |
7392 | in hardware. If the watchpoint can not be handled | |
7393 | in hardware return zero. */ | |
7394 | ||
c906108c | 7395 | static int |
fba45db2 | 7396 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7397 | { |
7398 | int found_memory_cnt = 0; | |
2e70b7b9 | 7399 | struct value *head = v; |
c906108c SS |
7400 | |
7401 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7402 | if (!can_use_hw_watchpoints) |
c906108c | 7403 | return 0; |
c5aa993b | 7404 | |
5c44784c JM |
7405 | /* Make sure that the value of the expression depends only upon |
7406 | memory contents, and values computed from them within GDB. If we | |
7407 | find any register references or function calls, we can't use a | |
7408 | hardware watchpoint. | |
7409 | ||
7410 | The idea here is that evaluating an expression generates a series | |
7411 | of values, one holding the value of every subexpression. (The | |
7412 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7413 | a*b+c.) GDB's values hold almost enough information to establish | |
7414 | the criteria given above --- they identify memory lvalues, | |
7415 | register lvalues, computed values, etcetera. So we can evaluate | |
7416 | the expression, and then scan the chain of values that leaves | |
7417 | behind to decide whether we can detect any possible change to the | |
7418 | expression's final value using only hardware watchpoints. | |
7419 | ||
7420 | However, I don't think that the values returned by inferior | |
7421 | function calls are special in any way. So this function may not | |
7422 | notice that an expression involving an inferior function call | |
7423 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7424 | for (; v; v = value_next (v)) |
c906108c | 7425 | { |
5c44784c | 7426 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7427 | { |
d69fe07e | 7428 | if (value_lazy (v)) |
5c44784c JM |
7429 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7430 | we either just used its address (e.g., `a' in `a.b') or | |
7431 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7432 | ; | |
53a5351d | 7433 | else |
5c44784c JM |
7434 | { |
7435 | /* Ahh, memory we actually used! Check if we can cover | |
7436 | it with hardware watchpoints. */ | |
df407dfe | 7437 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7438 | |
7439 | /* We only watch structs and arrays if user asked for it | |
7440 | explicitly, never if they just happen to appear in a | |
7441 | middle of some value chain. */ | |
7442 | if (v == head | |
7443 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7444 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7445 | { | |
42ae5230 | 7446 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7447 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7448 | |
d92524f1 | 7449 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7450 | return 0; |
7451 | else | |
7452 | found_memory_cnt++; | |
7453 | } | |
5c44784c | 7454 | } |
c5aa993b | 7455 | } |
5086187c AC |
7456 | else if (VALUE_LVAL (v) != not_lval |
7457 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7458 | return 0; /* ??? What does this represent? */ |
5086187c | 7459 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7460 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7461 | } |
7462 | ||
7463 | /* The expression itself looks suitable for using a hardware | |
7464 | watchpoint, but give the target machine a chance to reject it. */ | |
7465 | return found_memory_cnt; | |
7466 | } | |
7467 | ||
8b93c638 | 7468 | void |
fba45db2 | 7469 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7470 | { |
7471 | watch_command (arg, from_tty); | |
7472 | } | |
8926118c | 7473 | |
c5aa993b | 7474 | static void |
fba45db2 | 7475 | watch_command (char *arg, int from_tty) |
c906108c | 7476 | { |
53a5351d | 7477 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7478 | } |
7479 | ||
8b93c638 | 7480 | void |
fba45db2 | 7481 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7482 | { |
7483 | rwatch_command (arg, from_tty); | |
7484 | } | |
8926118c | 7485 | |
c5aa993b | 7486 | static void |
fba45db2 | 7487 | rwatch_command (char *arg, int from_tty) |
c906108c | 7488 | { |
53a5351d | 7489 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7490 | } |
7491 | ||
8b93c638 | 7492 | void |
fba45db2 | 7493 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7494 | { |
7495 | awatch_command (arg, from_tty); | |
7496 | } | |
8926118c | 7497 | |
c5aa993b | 7498 | static void |
fba45db2 | 7499 | awatch_command (char *arg, int from_tty) |
c906108c | 7500 | { |
53a5351d | 7501 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7502 | } |
c906108c | 7503 | \f |
c5aa993b | 7504 | |
43ff13b4 | 7505 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7506 | because it uses the mechanisms of breakpoints. */ |
7507 | ||
bfec99b2 PA |
7508 | struct until_break_command_continuation_args |
7509 | { | |
7510 | struct breakpoint *breakpoint; | |
7511 | struct breakpoint *breakpoint2; | |
7512 | }; | |
7513 | ||
43ff13b4 JM |
7514 | /* This function is called by fetch_inferior_event via the |
7515 | cmd_continuation pointer, to complete the until command. It takes | |
7516 | care of cleaning up the temporary breakpoints set up by the until | |
7517 | command. */ | |
c2c6d25f | 7518 | static void |
604ead4a | 7519 | until_break_command_continuation (void *arg) |
43ff13b4 | 7520 | { |
bfec99b2 PA |
7521 | struct until_break_command_continuation_args *a = arg; |
7522 | ||
7523 | delete_breakpoint (a->breakpoint); | |
7524 | if (a->breakpoint2) | |
7525 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
7526 | } |
7527 | ||
c906108c | 7528 | void |
ae66c1fc | 7529 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
7530 | { |
7531 | struct symtabs_and_lines sals; | |
7532 | struct symtab_and_line sal; | |
206415a3 | 7533 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 7534 | struct breakpoint *breakpoint; |
f107f563 | 7535 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
7536 | struct cleanup *old_chain; |
7537 | ||
7538 | clear_proceed_status (); | |
7539 | ||
7540 | /* Set a breakpoint where the user wants it and at return from | |
7541 | this function */ | |
c5aa993b | 7542 | |
c906108c SS |
7543 | if (default_breakpoint_valid) |
7544 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 7545 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 7546 | else |
53a5351d | 7547 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 7548 | 0, (char ***) NULL, NULL); |
c5aa993b | 7549 | |
c906108c | 7550 | if (sals.nelts != 1) |
8a3fe4f8 | 7551 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 7552 | |
c906108c | 7553 | sal = sals.sals[0]; |
b8c9b27d | 7554 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 7555 | |
c906108c | 7556 | if (*arg) |
8a3fe4f8 | 7557 | error (_("Junk at end of arguments.")); |
c5aa993b | 7558 | |
c906108c | 7559 | resolve_sal_pc (&sal); |
c5aa993b | 7560 | |
ae66c1fc EZ |
7561 | if (anywhere) |
7562 | /* If the user told us to continue until a specified location, | |
7563 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
7564 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7565 | null_frame_id, bp_until); | |
ae66c1fc | 7566 | else |
edb3359d | 7567 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 7568 | at the very same frame. */ |
a6d9a66e UW |
7569 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7570 | get_stack_frame_id (frame), | |
ae66c1fc | 7571 | bp_until); |
c5aa993b | 7572 | |
f107f563 | 7573 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 7574 | |
ae66c1fc EZ |
7575 | /* Keep within the current frame, or in frames called by the current |
7576 | one. */ | |
edb3359d DJ |
7577 | |
7578 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 7579 | { |
edb3359d DJ |
7580 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
7581 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
7582 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
7583 | sal, | |
edb3359d | 7584 | frame_unwind_caller_id (frame), |
f107f563 VP |
7585 | bp_until); |
7586 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 7587 | } |
c5aa993b | 7588 | |
c906108c | 7589 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
7590 | |
7591 | /* If we are running asynchronously, and proceed call above has actually | |
7592 | managed to start the target, arrange for breakpoints to be | |
7593 | deleted when the target stops. Otherwise, we're already stopped and | |
7594 | delete breakpoints via cleanup chain. */ | |
7595 | ||
8ea051c5 | 7596 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 7597 | { |
bfec99b2 PA |
7598 | struct until_break_command_continuation_args *args; |
7599 | args = xmalloc (sizeof (*args)); | |
f107f563 | 7600 | |
bfec99b2 PA |
7601 | args->breakpoint = breakpoint; |
7602 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
7603 | |
7604 | discard_cleanups (old_chain); | |
95e54da7 PA |
7605 | add_continuation (inferior_thread (), |
7606 | until_break_command_continuation, args, | |
604ead4a | 7607 | xfree); |
f107f563 VP |
7608 | } |
7609 | else | |
c5aa993b | 7610 | do_cleanups (old_chain); |
c906108c | 7611 | } |
ae66c1fc | 7612 | |
c906108c | 7613 | static void |
fba45db2 | 7614 | ep_skip_leading_whitespace (char **s) |
c906108c | 7615 | { |
c5aa993b JM |
7616 | if ((s == NULL) || (*s == NULL)) |
7617 | return; | |
7618 | while (isspace (**s)) | |
7619 | *s += 1; | |
c906108c | 7620 | } |
c5aa993b | 7621 | |
c906108c SS |
7622 | /* This function attempts to parse an optional "if <cond>" clause |
7623 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 7624 | |
c906108c SS |
7625 | Else, it returns a pointer to the condition string. (It does not |
7626 | attempt to evaluate the string against a particular block.) And, | |
7627 | it updates arg to point to the first character following the parsed | |
7628 | if clause in the arg string. */ | |
53a5351d | 7629 | |
c906108c | 7630 | static char * |
fba45db2 | 7631 | ep_parse_optional_if_clause (char **arg) |
c906108c | 7632 | { |
c5aa993b JM |
7633 | char *cond_string; |
7634 | ||
7635 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 7636 | return NULL; |
c5aa993b | 7637 | |
c906108c SS |
7638 | /* Skip the "if" keyword. */ |
7639 | (*arg) += 2; | |
c5aa993b | 7640 | |
c906108c SS |
7641 | /* Skip any extra leading whitespace, and record the start of the |
7642 | condition string. */ | |
7643 | ep_skip_leading_whitespace (arg); | |
7644 | cond_string = *arg; | |
c5aa993b | 7645 | |
c906108c SS |
7646 | /* Assume that the condition occupies the remainder of the arg string. */ |
7647 | (*arg) += strlen (cond_string); | |
c5aa993b | 7648 | |
c906108c SS |
7649 | return cond_string; |
7650 | } | |
c5aa993b | 7651 | |
c906108c SS |
7652 | /* Commands to deal with catching events, such as signals, exceptions, |
7653 | process start/exit, etc. */ | |
c5aa993b JM |
7654 | |
7655 | typedef enum | |
7656 | { | |
44feb3ce TT |
7657 | catch_fork_temporary, catch_vfork_temporary, |
7658 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
7659 | } |
7660 | catch_fork_kind; | |
7661 | ||
c906108c | 7662 | static void |
44feb3ce | 7663 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7664 | { |
a6d9a66e | 7665 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 7666 | char *cond_string = NULL; |
44feb3ce TT |
7667 | catch_fork_kind fork_kind; |
7668 | int tempflag; | |
7669 | ||
7670 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
7671 | tempflag = (fork_kind == catch_fork_temporary | |
7672 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 7673 | |
44feb3ce TT |
7674 | if (!arg) |
7675 | arg = ""; | |
c906108c | 7676 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7677 | |
c906108c | 7678 | /* The allowed syntax is: |
c5aa993b JM |
7679 | catch [v]fork |
7680 | catch [v]fork if <cond> | |
7681 | ||
c906108c SS |
7682 | First, check if there's an if clause. */ |
7683 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 7684 | |
c906108c | 7685 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 7686 | error (_("Junk at end of arguments.")); |
c5aa993b | 7687 | |
c906108c SS |
7688 | /* If this target supports it, create a fork or vfork catchpoint |
7689 | and enable reporting of such events. */ | |
c5aa993b JM |
7690 | switch (fork_kind) |
7691 | { | |
44feb3ce TT |
7692 | case catch_fork_temporary: |
7693 | case catch_fork_permanent: | |
a6d9a66e | 7694 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7695 | &catch_fork_breakpoint_ops); |
c906108c | 7696 | break; |
44feb3ce TT |
7697 | case catch_vfork_temporary: |
7698 | case catch_vfork_permanent: | |
a6d9a66e | 7699 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7700 | &catch_vfork_breakpoint_ops); |
c906108c | 7701 | break; |
c5aa993b | 7702 | default: |
8a3fe4f8 | 7703 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 7704 | break; |
c5aa993b | 7705 | } |
c906108c SS |
7706 | } |
7707 | ||
7708 | static void | |
44feb3ce | 7709 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7710 | { |
a6d9a66e | 7711 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7712 | int tempflag; |
c5aa993b | 7713 | char *cond_string = NULL; |
c906108c | 7714 | |
44feb3ce TT |
7715 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7716 | ||
7717 | if (!arg) | |
7718 | arg = ""; | |
c906108c SS |
7719 | ep_skip_leading_whitespace (&arg); |
7720 | ||
7721 | /* The allowed syntax is: | |
c5aa993b JM |
7722 | catch exec |
7723 | catch exec if <cond> | |
c906108c SS |
7724 | |
7725 | First, check if there's an if clause. */ | |
7726 | cond_string = ep_parse_optional_if_clause (&arg); | |
7727 | ||
7728 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7729 | error (_("Junk at end of arguments.")); |
c906108c SS |
7730 | |
7731 | /* If this target supports it, create an exec catchpoint | |
7732 | and enable reporting of such events. */ | |
a6d9a66e UW |
7733 | create_catchpoint (gdbarch, tempflag, cond_string, |
7734 | &catch_exec_breakpoint_ops); | |
c906108c | 7735 | } |
c5aa993b | 7736 | |
3086aeae DJ |
7737 | static enum print_stop_action |
7738 | print_exception_catchpoint (struct breakpoint *b) | |
7739 | { | |
ade92717 | 7740 | int bp_temp, bp_throw; |
3086aeae | 7741 | |
ade92717 | 7742 | annotate_catchpoint (b->number); |
3086aeae | 7743 | |
ade92717 AR |
7744 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7745 | if (b->loc->address != b->loc->requested_address) | |
7746 | breakpoint_adjustment_warning (b->loc->requested_address, | |
7747 | b->loc->address, | |
7748 | b->number, 1); | |
df2b6d2d | 7749 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7750 | ui_out_text (uiout, |
7751 | bp_temp ? "Temporary catchpoint " | |
7752 | : "Catchpoint "); | |
7753 | if (!ui_out_is_mi_like_p (uiout)) | |
7754 | ui_out_field_int (uiout, "bkptno", b->number); | |
7755 | ui_out_text (uiout, | |
c0b37c48 AR |
7756 | bp_throw ? " (exception thrown), " |
7757 | : " (exception caught), "); | |
ade92717 AR |
7758 | if (ui_out_is_mi_like_p (uiout)) |
7759 | { | |
7760 | ui_out_field_string (uiout, "reason", | |
7761 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
7762 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7763 | ui_out_field_int (uiout, "bkptno", b->number); | |
7764 | } | |
3086aeae DJ |
7765 | return PRINT_SRC_AND_LOC; |
7766 | } | |
7767 | ||
7768 | static void | |
a6d9a66e | 7769 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 7770 | { |
79a45b7d TT |
7771 | struct value_print_options opts; |
7772 | get_user_print_options (&opts); | |
7773 | if (opts.addressprint) | |
3086aeae DJ |
7774 | { |
7775 | annotate_field (4); | |
604133b5 AR |
7776 | if (b->loc == NULL || b->loc->shlib_disabled) |
7777 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
7778 | else | |
5af949e3 UW |
7779 | ui_out_field_core_addr (uiout, "addr", |
7780 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
7781 | } |
7782 | annotate_field (5); | |
604133b5 | 7783 | if (b->loc) |
a6d9a66e | 7784 | *last_loc = b->loc; |
3086aeae DJ |
7785 | if (strstr (b->addr_string, "throw") != NULL) |
7786 | ui_out_field_string (uiout, "what", "exception throw"); | |
7787 | else | |
7788 | ui_out_field_string (uiout, "what", "exception catch"); | |
7789 | } | |
7790 | ||
7791 | static void | |
7792 | print_mention_exception_catchpoint (struct breakpoint *b) | |
7793 | { | |
ade92717 AR |
7794 | int bp_temp; |
7795 | int bp_throw; | |
7796 | ||
df2b6d2d | 7797 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7798 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7799 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
7800 | : _("Catchpoint ")); | |
7801 | ui_out_field_int (uiout, "bkptno", b->number); | |
7802 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
7803 | : _(" (catch)")); | |
3086aeae DJ |
7804 | } |
7805 | ||
7806 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
7807 | NULL, /* insert */ |
7808 | NULL, /* remove */ | |
7809 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
7810 | print_exception_catchpoint, |
7811 | print_one_exception_catchpoint, | |
7812 | print_mention_exception_catchpoint | |
7813 | }; | |
7814 | ||
7815 | static int | |
7816 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
7817 | enum exception_event_kind ex_event, int from_tty) | |
7818 | { | |
604133b5 AR |
7819 | char *trigger_func_name; |
7820 | ||
3086aeae | 7821 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 7822 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 7823 | else |
604133b5 | 7824 | trigger_func_name = "__cxa_throw"; |
3086aeae | 7825 | |
a6d9a66e UW |
7826 | break_command_really (get_current_arch (), |
7827 | trigger_func_name, cond_string, -1, | |
604133b5 | 7828 | 0 /* condition and thread are valid. */, |
1042e4c0 | 7829 | tempflag, 0, 0, |
604133b5 AR |
7830 | 0, |
7831 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
7832 | &gnu_v3_exception_catchpoint_ops, from_tty, |
7833 | 1 /* enabled */); | |
3086aeae | 7834 | |
3086aeae DJ |
7835 | return 1; |
7836 | } | |
7837 | ||
c5aa993b | 7838 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
7839 | |
7840 | static void | |
fba45db2 KB |
7841 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
7842 | int tempflag, int from_tty) | |
c906108c | 7843 | { |
c5aa993b JM |
7844 | char *cond_string = NULL; |
7845 | struct symtab_and_line *sal = NULL; | |
7846 | ||
44feb3ce TT |
7847 | if (!arg) |
7848 | arg = ""; | |
c906108c | 7849 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7850 | |
c906108c SS |
7851 | cond_string = ep_parse_optional_if_clause (&arg); |
7852 | ||
7853 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7854 | error (_("Junk at end of arguments.")); |
c906108c | 7855 | |
059fb39f PM |
7856 | if (ex_event != EX_EVENT_THROW |
7857 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7858 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7859 | |
3086aeae DJ |
7860 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7861 | return; | |
7862 | ||
8a3fe4f8 | 7863 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
7864 | } |
7865 | ||
44feb3ce TT |
7866 | /* Implementation of "catch catch" command. */ |
7867 | ||
7868 | static void | |
7869 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7870 | { | |
7871 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7872 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
7873 | } | |
7874 | ||
7875 | /* Implementation of "catch throw" command. */ | |
7876 | ||
7877 | static void | |
7878 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7879 | { | |
7880 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7881 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
7882 | } | |
7883 | ||
f7f9143b JB |
7884 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
7885 | ||
7886 | static void | |
a6d9a66e UW |
7887 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
7888 | struct symtab_and_line sal, | |
f7f9143b JB |
7889 | char *addr_string, |
7890 | char *exp_string, | |
7891 | char *cond_string, | |
7892 | struct expression *cond, | |
7893 | struct breakpoint_ops *ops, | |
7894 | int tempflag, | |
7895 | int from_tty) | |
7896 | { | |
7897 | struct breakpoint *b; | |
7898 | ||
7899 | if (from_tty) | |
7900 | { | |
5af949e3 UW |
7901 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
7902 | if (!loc_gdbarch) | |
7903 | loc_gdbarch = gdbarch; | |
7904 | ||
6c95b8df PA |
7905 | describe_other_breakpoints (loc_gdbarch, |
7906 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
7907 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7908 | version for exception catchpoints, because two catchpoints | |
7909 | used for different exception names will use the same address. | |
7910 | In this case, a "breakpoint ... also set at..." warning is | |
7911 | unproductive. Besides. the warning phrasing is also a bit | |
7912 | inapropriate, we should use the word catchpoint, and tell | |
7913 | the user what type of catchpoint it is. The above is good | |
7914 | enough for now, though. */ | |
7915 | } | |
7916 | ||
a6d9a66e | 7917 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7918 | set_breakpoint_count (breakpoint_count + 1); |
7919 | ||
7920 | b->enable_state = bp_enabled; | |
7921 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7922 | b->number = breakpoint_count; | |
7923 | b->ignore_count = 0; | |
511a6cd4 | 7924 | b->loc->cond = cond; |
f7f9143b JB |
7925 | b->addr_string = addr_string; |
7926 | b->language = language_ada; | |
7927 | b->cond_string = cond_string; | |
7928 | b->exp_string = exp_string; | |
7929 | b->thread = -1; | |
7930 | b->ops = ops; | |
f7f9143b JB |
7931 | |
7932 | mention (b); | |
b60e7edf | 7933 | update_global_location_list (1); |
f7f9143b JB |
7934 | } |
7935 | ||
7936 | /* Implement the "catch exception" command. */ | |
7937 | ||
7938 | static void | |
44feb3ce TT |
7939 | catch_ada_exception_command (char *arg, int from_tty, |
7940 | struct cmd_list_element *command) | |
f7f9143b | 7941 | { |
a6d9a66e | 7942 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7943 | int tempflag; |
f7f9143b JB |
7944 | struct symtab_and_line sal; |
7945 | enum bptype type; | |
7946 | char *addr_string = NULL; | |
7947 | char *exp_string = NULL; | |
7948 | char *cond_string = NULL; | |
7949 | struct expression *cond = NULL; | |
7950 | struct breakpoint_ops *ops = NULL; | |
7951 | ||
44feb3ce TT |
7952 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7953 | ||
7954 | if (!arg) | |
7955 | arg = ""; | |
f7f9143b JB |
7956 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7957 | &cond_string, &cond, &ops); | |
a6d9a66e | 7958 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7959 | cond_string, cond, ops, tempflag, |
7960 | from_tty); | |
7961 | } | |
7962 | ||
a96d9b2e SDJ |
7963 | /* Cleanup function for a syscall filter list. */ |
7964 | static void | |
7965 | clean_up_filters (void *arg) | |
7966 | { | |
7967 | VEC(int) *iter = *(VEC(int) **) arg; | |
7968 | VEC_free (int, iter); | |
7969 | } | |
7970 | ||
7971 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
7972 | filter list, or NULL if no filtering is required. */ | |
7973 | static VEC(int) * | |
7974 | catch_syscall_split_args (char *arg) | |
7975 | { | |
7976 | VEC(int) *result = NULL; | |
7977 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
7978 | ||
7979 | while (*arg != '\0') | |
7980 | { | |
7981 | int i, syscall_number; | |
7982 | char *endptr; | |
7983 | char cur_name[128]; | |
7984 | struct syscall s; | |
7985 | ||
7986 | /* Skip whitespace. */ | |
7987 | while (isspace (*arg)) | |
7988 | arg++; | |
7989 | ||
7990 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
7991 | cur_name[i] = arg[i]; | |
7992 | cur_name[i] = '\0'; | |
7993 | arg += i; | |
7994 | ||
7995 | /* Check if the user provided a syscall name or a number. */ | |
7996 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
7997 | if (*endptr == '\0') | |
bccd0dd2 | 7998 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
7999 | else |
8000 | { | |
8001 | /* We have a name. Let's check if it's valid and convert it | |
8002 | to a number. */ | |
8003 | get_syscall_by_name (cur_name, &s); | |
8004 | ||
8005 | if (s.number == UNKNOWN_SYSCALL) | |
8006 | /* Here we have to issue an error instead of a warning, because | |
8007 | GDB cannot do anything useful if there's no syscall number to | |
8008 | be caught. */ | |
8009 | error (_("Unknown syscall name '%s'."), cur_name); | |
8010 | } | |
8011 | ||
8012 | /* Ok, it's valid. */ | |
8013 | VEC_safe_push (int, result, s.number); | |
8014 | } | |
8015 | ||
8016 | discard_cleanups (cleanup); | |
8017 | return result; | |
8018 | } | |
8019 | ||
8020 | /* Implement the "catch syscall" command. */ | |
8021 | ||
8022 | static void | |
8023 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
8024 | { | |
8025 | int tempflag; | |
8026 | VEC(int) *filter; | |
8027 | struct syscall s; | |
8028 | struct gdbarch *gdbarch = get_current_arch (); | |
8029 | ||
8030 | /* Checking if the feature if supported. */ | |
8031 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8032 | error (_("The feature 'catch syscall' is not supported on \ | |
8033 | this architeture yet.")); | |
8034 | ||
8035 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8036 | ||
8037 | ep_skip_leading_whitespace (&arg); | |
8038 | ||
8039 | /* We need to do this first "dummy" translation in order | |
8040 | to get the syscall XML file loaded or, most important, | |
8041 | to display a warning to the user if there's no XML file | |
8042 | for his/her architecture. */ | |
8043 | get_syscall_by_number (0, &s); | |
8044 | ||
8045 | /* The allowed syntax is: | |
8046 | catch syscall | |
8047 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8048 | ||
8049 | Let's check if there's a syscall name. */ | |
8050 | ||
8051 | if (arg != NULL) | |
8052 | filter = catch_syscall_split_args (arg); | |
8053 | else | |
8054 | filter = NULL; | |
8055 | ||
8056 | create_syscall_event_catchpoint (tempflag, filter, | |
8057 | &catch_syscall_breakpoint_ops); | |
8058 | } | |
8059 | ||
f7f9143b JB |
8060 | /* Implement the "catch assert" command. */ |
8061 | ||
8062 | static void | |
44feb3ce | 8063 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8064 | { |
a6d9a66e | 8065 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8066 | int tempflag; |
f7f9143b JB |
8067 | struct symtab_and_line sal; |
8068 | char *addr_string = NULL; | |
8069 | struct breakpoint_ops *ops = NULL; | |
8070 | ||
44feb3ce TT |
8071 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8072 | ||
8073 | if (!arg) | |
8074 | arg = ""; | |
f7f9143b | 8075 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
8076 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
8077 | ops, tempflag, from_tty); | |
f7f9143b JB |
8078 | } |
8079 | ||
c906108c | 8080 | static void |
fba45db2 | 8081 | catch_command (char *arg, int from_tty) |
c906108c | 8082 | { |
44feb3ce | 8083 | error (_("Catch requires an event name.")); |
c906108c SS |
8084 | } |
8085 | \f | |
8086 | ||
8087 | static void | |
fba45db2 | 8088 | tcatch_command (char *arg, int from_tty) |
c906108c | 8089 | { |
44feb3ce | 8090 | error (_("Catch requires an event name.")); |
c906108c SS |
8091 | } |
8092 | ||
80f8a6eb | 8093 | /* Delete breakpoints by address or line. */ |
c906108c SS |
8094 | |
8095 | static void | |
fba45db2 | 8096 | clear_command (char *arg, int from_tty) |
c906108c | 8097 | { |
d6e956e5 VP |
8098 | struct breakpoint *b; |
8099 | VEC(breakpoint_p) *found = 0; | |
8100 | int ix; | |
c906108c SS |
8101 | int default_match; |
8102 | struct symtabs_and_lines sals; | |
8103 | struct symtab_and_line sal; | |
c906108c SS |
8104 | int i; |
8105 | ||
8106 | if (arg) | |
8107 | { | |
8108 | sals = decode_line_spec (arg, 1); | |
8109 | default_match = 0; | |
8110 | } | |
8111 | else | |
8112 | { | |
c5aa993b | 8113 | sals.sals = (struct symtab_and_line *) |
c906108c | 8114 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 8115 | make_cleanup (xfree, sals.sals); |
fe39c653 | 8116 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
8117 | sal.line = default_breakpoint_line; |
8118 | sal.symtab = default_breakpoint_symtab; | |
8119 | sal.pc = default_breakpoint_address; | |
6c95b8df | 8120 | sal.pspace = default_breakpoint_pspace; |
c906108c | 8121 | if (sal.symtab == 0) |
8a3fe4f8 | 8122 | error (_("No source file specified.")); |
c906108c SS |
8123 | |
8124 | sals.sals[0] = sal; | |
8125 | sals.nelts = 1; | |
8126 | ||
8127 | default_match = 1; | |
8128 | } | |
8129 | ||
ed0616c6 VP |
8130 | /* We don't call resolve_sal_pc here. That's not |
8131 | as bad as it seems, because all existing breakpoints | |
8132 | typically have both file/line and pc set. So, if | |
8133 | clear is given file/line, we can match this to existing | |
8134 | breakpoint without obtaining pc at all. | |
8135 | ||
8136 | We only support clearing given the address explicitly | |
8137 | present in breakpoint table. Say, we've set breakpoint | |
8138 | at file:line. There were several PC values for that file:line, | |
8139 | due to optimization, all in one block. | |
8140 | We've picked one PC value. If "clear" is issued with another | |
8141 | PC corresponding to the same file:line, the breakpoint won't | |
8142 | be cleared. We probably can still clear the breakpoint, but | |
8143 | since the other PC value is never presented to user, user | |
8144 | can only find it by guessing, and it does not seem important | |
8145 | to support that. */ | |
8146 | ||
c906108c | 8147 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
8148 | to it. Do it in two passes, solely to preserve the current |
8149 | behavior that from_tty is forced true if we delete more than | |
8150 | one breakpoint. */ | |
c906108c | 8151 | |
80f8a6eb | 8152 | found = NULL; |
c906108c SS |
8153 | for (i = 0; i < sals.nelts; i++) |
8154 | { | |
8155 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
8156 | If line given (pc == 0), clear all bpts on specified line. |
8157 | If defaulting, clear all bpts on default line | |
c906108c | 8158 | or at default pc. |
c5aa993b JM |
8159 | |
8160 | defaulting sal.pc != 0 tests to do | |
8161 | ||
8162 | 0 1 pc | |
8163 | 1 1 pc _and_ line | |
8164 | 0 0 line | |
8165 | 1 0 <can't happen> */ | |
c906108c SS |
8166 | |
8167 | sal = sals.sals[i]; | |
c906108c | 8168 | |
d6e956e5 VP |
8169 | /* Find all matching breakpoints and add them to |
8170 | 'found'. */ | |
8171 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8172 | { |
0d381245 | 8173 | int match = 0; |
80f8a6eb MS |
8174 | /* Are we going to delete b? */ |
8175 | if (b->type != bp_none | |
8176 | && b->type != bp_watchpoint | |
8177 | && b->type != bp_hardware_watchpoint | |
8178 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8179 | && b->type != bp_access_watchpoint) |
8180 | { | |
8181 | struct bp_location *loc = b->loc; | |
8182 | for (; loc; loc = loc->next) | |
8183 | { | |
6c95b8df PA |
8184 | int pc_match = sal.pc |
8185 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8186 | && (loc->address == sal.pc) |
8187 | && (!section_is_overlay (loc->section) | |
8188 | || loc->section == sal.section); | |
8189 | int line_match = ((default_match || (0 == sal.pc)) | |
8190 | && b->source_file != NULL | |
8191 | && sal.symtab != NULL | |
6c95b8df | 8192 | && sal.pspace == loc->pspace |
0d381245 VP |
8193 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8194 | && b->line_number == sal.line); | |
8195 | if (pc_match || line_match) | |
8196 | { | |
8197 | match = 1; | |
8198 | break; | |
8199 | } | |
8200 | } | |
8201 | } | |
8202 | ||
8203 | if (match) | |
d6e956e5 | 8204 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8205 | } |
80f8a6eb MS |
8206 | } |
8207 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8208 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8209 | { |
8210 | if (arg) | |
8a3fe4f8 | 8211 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8212 | else |
8a3fe4f8 | 8213 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8214 | } |
c906108c | 8215 | |
d6e956e5 | 8216 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8217 | from_tty = 1; /* Always report if deleted more than one */ |
8218 | if (from_tty) | |
a3f17187 | 8219 | { |
d6e956e5 | 8220 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8221 | printf_unfiltered (_("Deleted breakpoint ")); |
8222 | else | |
8223 | printf_unfiltered (_("Deleted breakpoints ")); | |
8224 | } | |
80f8a6eb | 8225 | breakpoints_changed (); |
d6e956e5 VP |
8226 | |
8227 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8228 | { |
c5aa993b | 8229 | if (from_tty) |
d6e956e5 VP |
8230 | printf_unfiltered ("%d ", b->number); |
8231 | delete_breakpoint (b); | |
c906108c | 8232 | } |
80f8a6eb MS |
8233 | if (from_tty) |
8234 | putchar_unfiltered ('\n'); | |
c906108c SS |
8235 | } |
8236 | \f | |
8237 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8238 | all breakpoints that are marked for deletion, whether hit or not. | |
8239 | This is called after any breakpoint is hit, or after errors. */ | |
8240 | ||
8241 | void | |
fba45db2 | 8242 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8243 | { |
8244 | struct breakpoint *b, *temp; | |
8245 | ||
8246 | for (; bs; bs = bs->next) | |
20874c92 VP |
8247 | if (bs->breakpoint_at |
8248 | && bs->breakpoint_at->owner | |
8249 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8250 | && bs->stop) |
4f8d1dc6 | 8251 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8252 | |
8253 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8254 | { |
b5de0fa7 | 8255 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8256 | delete_breakpoint (b); |
8257 | } | |
c906108c SS |
8258 | } |
8259 | ||
494cfb0f | 8260 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
8261 | Sort elements primarily by their ADDRESS (no matter what does |
8262 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8263 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8264 | is sorted stable way despite qsort being an instable algorithm. */ | |
8265 | ||
8266 | static int | |
494cfb0f | 8267 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 8268 | { |
494cfb0f JK |
8269 | struct bp_location *a = *(void **) ap; |
8270 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
8271 | int a_perm = a->owner->enable_state == bp_permanent; |
8272 | int b_perm = b->owner->enable_state == bp_permanent; | |
8273 | ||
8274 | if (a->address != b->address) | |
8275 | return (a->address > b->address) - (a->address < b->address); | |
8276 | ||
8277 | /* Sort permanent breakpoints first. */ | |
8278 | if (a_perm != b_perm) | |
8279 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8280 | ||
8281 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8282 | breakpoint can be sorted in arbitrary order. */ | |
8283 | ||
8284 | if (a->owner->number != b->owner->number) | |
8285 | return (a->owner->number > b->owner->number) | |
8286 | - (a->owner->number < b->owner->number); | |
8287 | ||
8288 | return (a > b) - (a < b); | |
8289 | } | |
8290 | ||
876fa593 JK |
8291 | /* Set bp_location_placed_address_before_address_max and |
8292 | bp_location_shadow_len_after_address_max according to the current content of | |
8293 | the bp_location array. */ | |
f7545552 TT |
8294 | |
8295 | static void | |
876fa593 | 8296 | bp_location_target_extensions_update (void) |
f7545552 | 8297 | { |
876fa593 JK |
8298 | struct bp_location *bl, **blp_tmp; |
8299 | ||
8300 | bp_location_placed_address_before_address_max = 0; | |
8301 | bp_location_shadow_len_after_address_max = 0; | |
8302 | ||
8303 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8304 | { | |
8305 | CORE_ADDR start, end, addr; | |
8306 | ||
8307 | if (!bp_location_has_shadow (bl)) | |
8308 | continue; | |
8309 | ||
8310 | start = bl->target_info.placed_address; | |
8311 | end = start + bl->target_info.shadow_len; | |
8312 | ||
8313 | gdb_assert (bl->address >= start); | |
8314 | addr = bl->address - start; | |
8315 | if (addr > bp_location_placed_address_before_address_max) | |
8316 | bp_location_placed_address_before_address_max = addr; | |
8317 | ||
8318 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8319 | ||
8320 | gdb_assert (bl->address < end); | |
8321 | addr = end - bl->address; | |
8322 | if (addr > bp_location_shadow_len_after_address_max) | |
8323 | bp_location_shadow_len_after_address_max = addr; | |
8324 | } | |
f7545552 TT |
8325 | } |
8326 | ||
4cd9bd08 | 8327 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8328 | into the inferior, only remove already-inserted locations that no |
8329 | longer should be inserted. Functions that delete a breakpoint or | |
8330 | breakpoints should pass false, so that deleting a breakpoint | |
8331 | doesn't have the side effect of inserting the locations of other | |
8332 | breakpoints that are marked not-inserted, but should_be_inserted | |
8333 | returns true on them. | |
8334 | ||
8335 | This behaviour is useful is situations close to tear-down -- e.g., | |
8336 | after an exec, while the target still has execution, but breakpoint | |
8337 | shadows of the previous executable image should *NOT* be restored | |
8338 | to the new image; or before detaching, where the target still has | |
8339 | execution and wants to delete breakpoints from GDB's lists, and all | |
8340 | breakpoints had already been removed from the inferior. */ | |
8341 | ||
0d381245 | 8342 | static void |
b60e7edf | 8343 | update_global_location_list (int should_insert) |
0d381245 | 8344 | { |
74960c60 | 8345 | struct breakpoint *b; |
876fa593 | 8346 | struct bp_location **locp, *loc; |
f7545552 TT |
8347 | struct cleanup *cleanups; |
8348 | ||
2d134ed3 PA |
8349 | /* Used in the duplicates detection below. When iterating over all |
8350 | bp_locations, points to the first bp_location of a given address. | |
8351 | Breakpoints and watchpoints of different types are never | |
8352 | duplicates of each other. Keep one pointer for each type of | |
8353 | breakpoint/watchpoint, so we only need to loop over all locations | |
8354 | once. */ | |
8355 | struct bp_location *bp_loc_first; /* breakpoint */ | |
8356 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
8357 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
8358 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
8359 | |
8360 | /* Saved former bp_location array which we compare against the newly built | |
8361 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8362 | struct bp_location **old_location, **old_locp; | |
8363 | unsigned old_location_count; | |
8364 | ||
8365 | old_location = bp_location; | |
8366 | old_location_count = bp_location_count; | |
8367 | bp_location = NULL; | |
8368 | bp_location_count = 0; | |
8369 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8370 | |
74960c60 | 8371 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8372 | for (loc = b->loc; loc; loc = loc->next) |
8373 | bp_location_count++; | |
8374 | ||
8375 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8376 | locp = bp_location; | |
8377 | ALL_BREAKPOINTS (b) | |
8378 | for (loc = b->loc; loc; loc = loc->next) | |
8379 | *locp++ = loc; | |
8380 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 8381 | bp_location_compare); |
876fa593 JK |
8382 | |
8383 | bp_location_target_extensions_update (); | |
74960c60 VP |
8384 | |
8385 | /* Identify bp_location instances that are no longer present in the new | |
8386 | list, and therefore should be freed. Note that it's not necessary that | |
8387 | those locations should be removed from inferior -- if there's another | |
8388 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8389 | we don't need to remove/insert the location. |
8390 | ||
8391 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8392 | former bp_location array state respectively. */ | |
8393 | ||
8394 | locp = bp_location; | |
8395 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8396 | old_locp++) | |
74960c60 | 8397 | { |
876fa593 | 8398 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 8399 | struct bp_location **loc2p; |
876fa593 JK |
8400 | |
8401 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8402 | have to free it. */ |
c7d46a38 | 8403 | int found_object = 0; |
20874c92 VP |
8404 | /* Tells if the location should remain inserted in the target. */ |
8405 | int keep_in_target = 0; | |
8406 | int removed = 0; | |
876fa593 JK |
8407 | |
8408 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8409 | at or being the one matching OLD_LOC. */ | |
8410 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 8411 | && (*locp)->address < old_loc->address) |
876fa593 | 8412 | locp++; |
c7d46a38 PA |
8413 | |
8414 | for (loc2p = locp; | |
8415 | (loc2p < bp_location + bp_location_count | |
8416 | && (*loc2p)->address == old_loc->address); | |
8417 | loc2p++) | |
8418 | { | |
8419 | if (*loc2p == old_loc) | |
8420 | { | |
8421 | found_object = 1; | |
8422 | break; | |
8423 | } | |
8424 | } | |
74960c60 VP |
8425 | |
8426 | /* If this location is no longer present, and inserted, look if there's | |
8427 | maybe a new location at the same address. If so, mark that one | |
8428 | inserted, and don't remove this one. This is needed so that we | |
8429 | don't have a time window where a breakpoint at certain location is not | |
8430 | inserted. */ | |
8431 | ||
876fa593 | 8432 | if (old_loc->inserted) |
0d381245 | 8433 | { |
74960c60 | 8434 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8435 | |
876fa593 | 8436 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8437 | { |
8438 | /* The location is still present in the location list, and still | |
8439 | should be inserted. Don't do anything. */ | |
20874c92 | 8440 | keep_in_target = 1; |
74960c60 VP |
8441 | } |
8442 | else | |
8443 | { | |
8444 | /* The location is either no longer present, or got disabled. | |
8445 | See if there's another location at the same address, in which | |
8446 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8447 | |
8448 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8449 | { | |
876fa593 | 8450 | for (loc2p = locp; |
c7d46a38 PA |
8451 | (loc2p < bp_location + bp_location_count |
8452 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
8453 | loc2p++) |
8454 | { | |
8455 | struct bp_location *loc2 = *loc2p; | |
8456 | ||
2d134ed3 | 8457 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
8458 | { |
8459 | /* For the sake of should_be_inserted. | |
8460 | Duplicates check below will fix up this later. */ | |
8461 | loc2->duplicate = 0; | |
8462 | if (loc2 != old_loc && should_be_inserted (loc2)) | |
8463 | { | |
8464 | loc2->inserted = 1; | |
8465 | loc2->target_info = old_loc->target_info; | |
8466 | keep_in_target = 1; | |
8467 | break; | |
8468 | } | |
876fa593 JK |
8469 | } |
8470 | } | |
8471 | } | |
74960c60 VP |
8472 | } |
8473 | ||
20874c92 VP |
8474 | if (!keep_in_target) |
8475 | { | |
876fa593 | 8476 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8477 | { |
8478 | /* This is just about all we can do. We could keep this | |
8479 | location on the global list, and try to remove it next | |
8480 | time, but there's no particular reason why we will | |
8481 | succeed next time. | |
8482 | ||
876fa593 | 8483 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8484 | as delete_breakpoint frees the breakpoint only |
8485 | after calling us. */ | |
8486 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 8487 | old_loc->owner->number); |
20874c92 VP |
8488 | } |
8489 | removed = 1; | |
8490 | } | |
0d381245 | 8491 | } |
74960c60 VP |
8492 | |
8493 | if (!found_object) | |
1c5cfe86 | 8494 | { |
db82e815 PA |
8495 | if (removed && non_stop |
8496 | && breakpoint_address_is_meaningful (old_loc->owner) | |
8497 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 8498 | { |
db82e815 PA |
8499 | /* This location was removed from the target. In |
8500 | non-stop mode, a race condition is possible where | |
8501 | we've removed a breakpoint, but stop events for that | |
8502 | breakpoint are already queued and will arrive later. | |
8503 | We apply an heuristic to be able to distinguish such | |
8504 | SIGTRAPs from other random SIGTRAPs: we keep this | |
8505 | breakpoint location for a bit, and will retire it | |
8506 | after we see some number of events. The theory here | |
8507 | is that reporting of events should, "on the average", | |
8508 | be fair, so after a while we'll see events from all | |
8509 | threads that have anything of interest, and no longer | |
8510 | need to keep this breakpoint location around. We | |
8511 | don't hold locations forever so to reduce chances of | |
8512 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
8513 | SIGTRAP. | |
8514 | ||
8515 | The heuristic failing can be disastrous on | |
8516 | decr_pc_after_break targets. | |
8517 | ||
8518 | On decr_pc_after_break targets, like e.g., x86-linux, | |
8519 | if we fail to recognize a late breakpoint SIGTRAP, | |
8520 | because events_till_retirement has reached 0 too | |
8521 | soon, we'll fail to do the PC adjustment, and report | |
8522 | a random SIGTRAP to the user. When the user resumes | |
8523 | the inferior, it will most likely immediately crash | |
8524 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently | |
8525 | corrupted, because of being resumed e.g., in the | |
8526 | middle of a multi-byte instruction, or skipped a | |
8527 | one-byte instruction. This was actually seen happen | |
8528 | on native x86-linux, and should be less rare on | |
8529 | targets that do not support new thread events, like | |
8530 | remote, due to the heuristic depending on | |
8531 | thread_count. | |
8532 | ||
8533 | Mistaking a random SIGTRAP for a breakpoint trap | |
8534 | causes similar symptoms (PC adjustment applied when | |
8535 | it shouldn't), but then again, playing with SIGTRAPs | |
8536 | behind the debugger's back is asking for trouble. | |
8537 | ||
8538 | Since hardware watchpoint traps are always | |
8539 | distinguishable from other traps, so we don't need to | |
8540 | apply keep hardware watchpoint moribund locations | |
8541 | around. We simply always ignore hardware watchpoint | |
8542 | traps we can no longer explain. */ | |
8543 | ||
876fa593 JK |
8544 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
8545 | old_loc->owner = NULL; | |
20874c92 | 8546 | |
876fa593 | 8547 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
8548 | } |
8549 | else | |
876fa593 | 8550 | free_bp_location (old_loc); |
20874c92 | 8551 | } |
74960c60 | 8552 | } |
1c5cfe86 | 8553 | |
2d134ed3 PA |
8554 | /* Rescan breakpoints at the same address and section, marking the |
8555 | first one as "first" and any others as "duplicates". This is so | |
8556 | that the bpt instruction is only inserted once. If we have a | |
8557 | permanent breakpoint at the same place as BPT, make that one the | |
8558 | official one, and the rest as duplicates. Permanent breakpoints | |
8559 | are sorted first for the same address. | |
8560 | ||
8561 | Do the same for hardware watchpoints, but also considering the | |
8562 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 8563 | |
2d134ed3 PA |
8564 | bp_loc_first = NULL; |
8565 | wp_loc_first = NULL; | |
8566 | awp_loc_first = NULL; | |
8567 | rwp_loc_first = NULL; | |
876fa593 | 8568 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 8569 | { |
876fa593 | 8570 | struct breakpoint *b = loc->owner; |
2d134ed3 | 8571 | struct bp_location **loc_first_p; |
876fa593 JK |
8572 | |
8573 | if (b->enable_state == bp_disabled | |
8574 | || b->enable_state == bp_call_disabled | |
8575 | || b->enable_state == bp_startup_disabled | |
8576 | || !loc->enabled | |
8577 | || loc->shlib_disabled | |
8578 | || !breakpoint_address_is_meaningful (b)) | |
8579 | continue; | |
8580 | ||
8581 | /* Permanent breakpoint should always be inserted. */ | |
8582 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
8583 | internal_error (__FILE__, __LINE__, | |
8584 | _("allegedly permanent breakpoint is not " | |
8585 | "actually inserted")); | |
8586 | ||
2d134ed3 PA |
8587 | if (b->type == bp_hardware_watchpoint) |
8588 | loc_first_p = &wp_loc_first; | |
8589 | else if (b->type == bp_read_watchpoint) | |
8590 | loc_first_p = &rwp_loc_first; | |
8591 | else if (b->type == bp_access_watchpoint) | |
8592 | loc_first_p = &awp_loc_first; | |
8593 | else | |
8594 | loc_first_p = &bp_loc_first; | |
8595 | ||
8596 | if (*loc_first_p == NULL | |
8597 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
8598 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 8599 | { |
2d134ed3 | 8600 | *loc_first_p = loc; |
876fa593 JK |
8601 | loc->duplicate = 0; |
8602 | continue; | |
8603 | } | |
8604 | ||
8605 | loc->duplicate = 1; | |
8606 | ||
2d134ed3 PA |
8607 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
8608 | && b->enable_state != bp_permanent) | |
876fa593 JK |
8609 | internal_error (__FILE__, __LINE__, |
8610 | _("another breakpoint was inserted on top of " | |
8611 | "a permanent breakpoint")); | |
0d381245 | 8612 | } |
74960c60 | 8613 | |
50c71eaf | 8614 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 8615 | && (have_live_inferiors () |
2567c7d9 | 8616 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 8617 | insert_breakpoint_locations (); |
f7545552 TT |
8618 | |
8619 | do_cleanups (cleanups); | |
74960c60 VP |
8620 | } |
8621 | ||
20874c92 VP |
8622 | void |
8623 | breakpoint_retire_moribund (void) | |
8624 | { | |
8625 | struct bp_location *loc; | |
8626 | int ix; | |
8627 | ||
8628 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
8629 | if (--(loc->events_till_retirement) == 0) | |
8630 | { | |
8631 | free_bp_location (loc); | |
8632 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
8633 | --ix; | |
8634 | } | |
8635 | } | |
8636 | ||
74960c60 | 8637 | static void |
b60e7edf | 8638 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
8639 | { |
8640 | struct gdb_exception e; | |
8641 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 8642 | update_global_location_list (inserting); |
0d381245 VP |
8643 | } |
8644 | ||
a474d7c2 PA |
8645 | /* Clear BPT from a BPS. */ |
8646 | static void | |
8647 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
8648 | { | |
8649 | bpstat bs; | |
8650 | for (bs = bps; bs; bs = bs->next) | |
8651 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
8652 | { | |
8653 | bs->breakpoint_at = NULL; | |
8654 | bs->old_val = NULL; | |
8655 | /* bs->commands will be freed later. */ | |
8656 | } | |
8657 | } | |
8658 | ||
8659 | /* Callback for iterate_over_threads. */ | |
8660 | static int | |
8661 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
8662 | { | |
8663 | struct breakpoint *bpt = data; | |
8664 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
8665 | return 0; | |
8666 | } | |
8667 | ||
53a5351d JM |
8668 | /* Delete a breakpoint and clean up all traces of it in the data |
8669 | structures. */ | |
c906108c SS |
8670 | |
8671 | void | |
fba45db2 | 8672 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8673 | { |
52f0bd74 | 8674 | struct breakpoint *b; |
74960c60 | 8675 | struct bp_location *loc, *next; |
c906108c | 8676 | |
8a3fe4f8 | 8677 | gdb_assert (bpt != NULL); |
c906108c SS |
8678 | |
8679 | /* Has this bp already been deleted? This can happen because multiple | |
8680 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
8681 | ||
8682 | One example of this happening is a watchpoint's scope bp. When the | |
8683 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
8684 | delete it. We also delete its scope bp. But the scope bp is marked | |
8685 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
8686 | checked for auto-deleting bp's, which are deleted. | |
8687 | ||
8688 | A real solution to this problem might involve reference counts in bp's, | |
8689 | and/or giving them pointers back to their referencing bpstat's, and | |
8690 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 8691 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
8692 | if (bpt->type == bp_none) |
8693 | return; | |
8694 | ||
383f836e | 8695 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 8696 | |
c906108c SS |
8697 | if (breakpoint_chain == bpt) |
8698 | breakpoint_chain = bpt->next; | |
8699 | ||
c906108c SS |
8700 | ALL_BREAKPOINTS (b) |
8701 | if (b->next == bpt) | |
c5aa993b JM |
8702 | { |
8703 | b->next = bpt->next; | |
8704 | break; | |
8705 | } | |
c906108c | 8706 | |
c906108c | 8707 | free_command_lines (&bpt->commands); |
c906108c | 8708 | if (bpt->cond_string != NULL) |
b8c9b27d | 8709 | xfree (bpt->cond_string); |
c906108c | 8710 | if (bpt->addr_string != NULL) |
b8c9b27d | 8711 | xfree (bpt->addr_string); |
c906108c | 8712 | if (bpt->exp != NULL) |
b8c9b27d | 8713 | xfree (bpt->exp); |
c906108c | 8714 | if (bpt->exp_string != NULL) |
b8c9b27d | 8715 | xfree (bpt->exp_string); |
c906108c SS |
8716 | if (bpt->val != NULL) |
8717 | value_free (bpt->val); | |
8718 | if (bpt->source_file != NULL) | |
b8c9b27d | 8719 | xfree (bpt->source_file); |
c906108c | 8720 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 8721 | xfree (bpt->exec_pathname); |
a96d9b2e | 8722 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
8723 | |
8724 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
8725 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
8726 | We just check stop_bpstat for now. Note that we cannot just |
8727 | remove bpstats pointing at bpt from the stop_bpstat list | |
8728 | entirely, as breakpoint commands are associated with the bpstat; | |
8729 | if we remove it here, then the later call to | |
8730 | bpstat_do_actions (&stop_bpstat); | |
8731 | in event-top.c won't do anything, and temporary breakpoints | |
8732 | with commands won't work. */ | |
a474d7c2 | 8733 | |
a474d7c2 | 8734 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
8735 | |
8736 | /* Now that breakpoint is removed from breakpoint | |
8737 | list, update the global location list. This | |
8738 | will remove locations that used to belong to | |
8739 | this breakpoint. Do this before freeing | |
8740 | the breakpoint itself, since remove_breakpoint | |
8741 | looks at location's owner. It might be better | |
8742 | design to have location completely self-contained, | |
8743 | but it's not the case now. */ | |
b60e7edf | 8744 | update_global_location_list (0); |
74960c60 VP |
8745 | |
8746 | ||
c906108c SS |
8747 | /* On the chance that someone will soon try again to delete this same |
8748 | bp, we mark it as deleted before freeing its storage. */ | |
8749 | bpt->type = bp_none; | |
8750 | ||
b8c9b27d | 8751 | xfree (bpt); |
c906108c SS |
8752 | } |
8753 | ||
4d6140d9 AC |
8754 | static void |
8755 | do_delete_breakpoint_cleanup (void *b) | |
8756 | { | |
8757 | delete_breakpoint (b); | |
8758 | } | |
8759 | ||
8760 | struct cleanup * | |
8761 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
8762 | { | |
8763 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
8764 | } | |
8765 | ||
c906108c | 8766 | void |
fba45db2 | 8767 | delete_command (char *arg, int from_tty) |
c906108c SS |
8768 | { |
8769 | struct breakpoint *b, *temp; | |
8770 | ||
ea9365bb TT |
8771 | dont_repeat (); |
8772 | ||
c906108c SS |
8773 | if (arg == 0) |
8774 | { | |
8775 | int breaks_to_delete = 0; | |
8776 | ||
8777 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
8778 | Do not delete internal or call-dummy breakpoints, these |
8779 | have to be deleted with an explicit breakpoint number argument. */ | |
8780 | ALL_BREAKPOINTS (b) | |
8781 | { | |
059fb39f PM |
8782 | if (b->type != bp_call_dummy |
8783 | && b->type != bp_shlib_event | |
4efc6507 | 8784 | && b->type != bp_jit_event |
059fb39f PM |
8785 | && b->type != bp_thread_event |
8786 | && b->type != bp_overlay_event | |
0fd8e87f | 8787 | && b->type != bp_longjmp_master |
059fb39f | 8788 | && b->number >= 0) |
973d738b DJ |
8789 | { |
8790 | breaks_to_delete = 1; | |
8791 | break; | |
8792 | } | |
c5aa993b | 8793 | } |
c906108c SS |
8794 | |
8795 | /* Ask user only if there are some breakpoints to delete. */ | |
8796 | if (!from_tty | |
e2e0b3e5 | 8797 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 8798 | { |
c5aa993b JM |
8799 | ALL_BREAKPOINTS_SAFE (b, temp) |
8800 | { | |
059fb39f PM |
8801 | if (b->type != bp_call_dummy |
8802 | && b->type != bp_shlib_event | |
8803 | && b->type != bp_thread_event | |
4efc6507 | 8804 | && b->type != bp_jit_event |
059fb39f | 8805 | && b->type != bp_overlay_event |
0fd8e87f | 8806 | && b->type != bp_longjmp_master |
059fb39f | 8807 | && b->number >= 0) |
c5aa993b JM |
8808 | delete_breakpoint (b); |
8809 | } | |
c906108c SS |
8810 | } |
8811 | } | |
8812 | else | |
8813 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8814 | } | |
8815 | ||
0d381245 VP |
8816 | static int |
8817 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 8818 | { |
0d381245 VP |
8819 | for (; loc; loc = loc->next) |
8820 | if (!loc->shlib_disabled) | |
8821 | return 0; | |
8822 | return 1; | |
fe3f5fa8 VP |
8823 | } |
8824 | ||
776592bf DE |
8825 | /* Subroutine of update_breakpoint_locations to simplify it. |
8826 | Return non-zero if multiple fns in list LOC have the same name. | |
8827 | Null names are ignored. */ | |
8828 | ||
8829 | static int | |
8830 | ambiguous_names_p (struct bp_location *loc) | |
8831 | { | |
8832 | struct bp_location *l; | |
8833 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
8834 | (int (*) (const void *, const void *)) streq, | |
8835 | NULL, xcalloc, xfree); | |
8836 | ||
8837 | for (l = loc; l != NULL; l = l->next) | |
8838 | { | |
8839 | const char **slot; | |
8840 | const char *name = l->function_name; | |
8841 | ||
8842 | /* Allow for some names to be NULL, ignore them. */ | |
8843 | if (name == NULL) | |
8844 | continue; | |
8845 | ||
8846 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
8847 | INSERT); | |
8848 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
8849 | NULL. */ | |
8850 | if (*slot != NULL) | |
8851 | { | |
8852 | htab_delete (htab); | |
8853 | return 1; | |
8854 | } | |
8855 | *slot = name; | |
8856 | } | |
8857 | ||
8858 | htab_delete (htab); | |
8859 | return 0; | |
8860 | } | |
8861 | ||
fe3f5fa8 | 8862 | static void |
0d381245 VP |
8863 | update_breakpoint_locations (struct breakpoint *b, |
8864 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
8865 | { |
8866 | int i; | |
8867 | char *s; | |
0d381245 VP |
8868 | struct bp_location *existing_locations = b->loc; |
8869 | ||
8870 | /* If there's no new locations, and all existing locations | |
8871 | are pending, don't do anything. This optimizes | |
8872 | the common case where all locations are in the same | |
8873 | shared library, that was unloaded. We'd like to | |
8874 | retain the location, so that when the library | |
8875 | is loaded again, we don't loose the enabled/disabled | |
8876 | status of the individual locations. */ | |
8877 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
8878 | return; |
8879 | ||
fe3f5fa8 VP |
8880 | b->loc = NULL; |
8881 | ||
0d381245 | 8882 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 8883 | { |
0d381245 | 8884 | struct bp_location *new_loc = |
39d61571 | 8885 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 8886 | |
0d381245 VP |
8887 | /* Reparse conditions, they might contain references to the |
8888 | old symtab. */ | |
8889 | if (b->cond_string != NULL) | |
8890 | { | |
8891 | struct gdb_exception e; | |
fe3f5fa8 | 8892 | |
0d381245 VP |
8893 | s = b->cond_string; |
8894 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
8895 | { | |
8896 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
8897 | 0); | |
8898 | } | |
8899 | if (e.reason < 0) | |
8900 | { | |
8901 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
8902 | b->number, e.message); | |
8903 | new_loc->enabled = 0; | |
8904 | } | |
8905 | } | |
fe3f5fa8 | 8906 | |
0d381245 VP |
8907 | if (b->source_file != NULL) |
8908 | xfree (b->source_file); | |
8909 | if (sals.sals[i].symtab == NULL) | |
8910 | b->source_file = NULL; | |
8911 | else | |
1b36a34b | 8912 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 8913 | |
0d381245 VP |
8914 | if (b->line_number == 0) |
8915 | b->line_number = sals.sals[i].line; | |
8916 | } | |
fe3f5fa8 | 8917 | |
514f746b AR |
8918 | /* Update locations of permanent breakpoints. */ |
8919 | if (b->enable_state == bp_permanent) | |
8920 | make_breakpoint_permanent (b); | |
8921 | ||
0d381245 VP |
8922 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
8923 | { | |
8924 | struct bp_location *e = existing_locations; | |
776592bf DE |
8925 | /* If there are multiple breakpoints with the same function name, |
8926 | e.g. for inline functions, comparing function names won't work. | |
8927 | Instead compare pc addresses; this is just a heuristic as things | |
8928 | may have moved, but in practice it gives the correct answer | |
8929 | often enough until a better solution is found. */ | |
8930 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
8931 | ||
0d381245 VP |
8932 | for (; e; e = e->next) |
8933 | { | |
8934 | if (!e->enabled && e->function_name) | |
8935 | { | |
8936 | struct bp_location *l = b->loc; | |
776592bf DE |
8937 | if (have_ambiguous_names) |
8938 | { | |
8939 | for (; l; l = l->next) | |
6c95b8df PA |
8940 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
8941 | l->pspace->aspace, l->address)) | |
776592bf DE |
8942 | { |
8943 | l->enabled = 0; | |
8944 | break; | |
8945 | } | |
8946 | } | |
8947 | else | |
8948 | { | |
8949 | for (; l; l = l->next) | |
8950 | if (l->function_name | |
8951 | && strcmp (e->function_name, l->function_name) == 0) | |
8952 | { | |
8953 | l->enabled = 0; | |
8954 | break; | |
8955 | } | |
8956 | } | |
0d381245 VP |
8957 | } |
8958 | } | |
8959 | } | |
fe3f5fa8 | 8960 | |
b60e7edf | 8961 | update_global_location_list (1); |
fe3f5fa8 VP |
8962 | } |
8963 | ||
8964 | ||
c906108c SS |
8965 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
8966 | The value we return ends up being the return value from catch_errors. | |
8967 | Unused in this case. */ | |
8968 | ||
8969 | static int | |
4efb68b1 | 8970 | breakpoint_re_set_one (void *bint) |
c906108c | 8971 | { |
53a5351d JM |
8972 | /* get past catch_errs */ |
8973 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
8974 | struct value *mark; |
8975 | int i; | |
fe3f5fa8 VP |
8976 | int not_found = 0; |
8977 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
8978 | struct symtabs_and_lines sals = {0}; |
8979 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 8980 | char *s; |
b5de0fa7 | 8981 | enum enable_state save_enable; |
fe3f5fa8 | 8982 | struct gdb_exception e; |
6c95b8df | 8983 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
8984 | |
8985 | switch (b->type) | |
8986 | { | |
8987 | case bp_none: | |
8a3fe4f8 | 8988 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 8989 | b->number); |
c906108c SS |
8990 | return 0; |
8991 | case bp_breakpoint: | |
8992 | case bp_hardware_breakpoint: | |
1042e4c0 | 8993 | case bp_tracepoint: |
7a697b8d | 8994 | case bp_fast_tracepoint: |
8bea4e01 UW |
8995 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
8996 | if (b->enable_state == bp_startup_disabled) | |
8997 | return 0; | |
8998 | ||
c906108c SS |
8999 | if (b->addr_string == NULL) |
9000 | { | |
9001 | /* Anything without a string can't be re-set. */ | |
9002 | delete_breakpoint (b); | |
9003 | return 0; | |
9004 | } | |
c906108c SS |
9005 | |
9006 | set_language (b->language); | |
9007 | input_radix = b->input_radix; | |
9008 | s = b->addr_string; | |
6c95b8df PA |
9009 | |
9010 | save_current_space_and_thread (); | |
9011 | switch_to_program_space_and_thread (b->pspace); | |
9012 | ||
fe3f5fa8 | 9013 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 9014 | { |
fe3f5fa8 VP |
9015 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
9016 | not_found_ptr); | |
9017 | } | |
9018 | if (e.reason < 0) | |
9019 | { | |
9020 | int not_found_and_ok = 0; | |
9021 | /* For pending breakpoints, it's expected that parsing | |
9022 | will fail until the right shared library is loaded. | |
9023 | User has already told to create pending breakpoints and | |
9024 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
9025 | state, then user already saw the message about that breakpoint | |
9026 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
9027 | if (not_found |
9028 | && (b->condition_not_parsed | |
9029 | || (b->loc && b->loc->shlib_disabled) | |
9030 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
9031 | not_found_and_ok = 1; |
9032 | ||
9033 | if (!not_found_and_ok) | |
c906108c | 9034 | { |
fe3f5fa8 VP |
9035 | /* We surely don't want to warn about the same breakpoint |
9036 | 10 times. One solution, implemented here, is disable | |
9037 | the breakpoint on error. Another solution would be to | |
9038 | have separate 'warning emitted' flag. Since this | |
9039 | happens only when a binary has changed, I don't know | |
9040 | which approach is better. */ | |
9041 | b->enable_state = bp_disabled; | |
9042 | throw_exception (e); | |
c906108c | 9043 | } |
fe3f5fa8 | 9044 | } |
c906108c | 9045 | |
6c95b8df | 9046 | if (!not_found) |
fe3f5fa8 | 9047 | { |
6c95b8df PA |
9048 | gdb_assert (sals.nelts == 1); |
9049 | ||
9050 | resolve_sal_pc (&sals.sals[0]); | |
9051 | if (b->condition_not_parsed && s && s[0]) | |
9052 | { | |
9053 | char *cond_string = 0; | |
9054 | int thread = -1; | |
9055 | int task = 0; | |
9056 | ||
9057 | find_condition_and_thread (s, sals.sals[0].pc, | |
9058 | &cond_string, &thread, &task); | |
9059 | if (cond_string) | |
9060 | b->cond_string = cond_string; | |
9061 | b->thread = thread; | |
9062 | b->task = task; | |
9063 | b->condition_not_parsed = 0; | |
9064 | } | |
9065 | ||
9066 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 9067 | } |
6c95b8df PA |
9068 | |
9069 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 9070 | update_breakpoint_locations (b, expanded); |
c906108c SS |
9071 | break; |
9072 | ||
9073 | case bp_watchpoint: | |
9074 | case bp_hardware_watchpoint: | |
9075 | case bp_read_watchpoint: | |
9076 | case bp_access_watchpoint: | |
0b3de036 VP |
9077 | /* Watchpoint can be either on expression using entirely global variables, |
9078 | or it can be on local variables. | |
9079 | ||
9080 | Watchpoints of the first kind are never auto-deleted, and even persist | |
9081 | across program restarts. Since they can use variables from shared | |
9082 | libraries, we need to reparse expression as libraries are loaded | |
9083 | and unloaded. | |
9084 | ||
9085 | Watchpoints on local variables can also change meaning as result | |
9086 | of solib event. For example, if a watchpoint uses both a local and | |
9087 | a global variables in expression, it's a local watchpoint, but | |
9088 | unloading of a shared library will make the expression invalid. | |
9089 | This is not a very common use case, but we still re-evaluate | |
9090 | expression, to avoid surprises to the user. | |
9091 | ||
9092 | Note that for local watchpoints, we re-evaluate it only if | |
9093 | watchpoints frame id is still valid. If it's not, it means | |
9094 | the watchpoint is out of scope and will be deleted soon. In fact, | |
9095 | I'm not sure we'll ever be called in this case. | |
9096 | ||
9097 | If a local watchpoint's frame id is still valid, then | |
9098 | b->exp_valid_block is likewise valid, and we can safely use it. | |
9099 | ||
9100 | Don't do anything about disabled watchpoints, since they will | |
9101 | be reevaluated again when enabled. */ | |
a5606eee | 9102 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 9103 | break; |
c5aa993b JM |
9104 | /* We needn't really do anything to reset these, since the mask |
9105 | that requests them is unaffected by e.g., new libraries being | |
9106 | loaded. */ | |
ce78b96d | 9107 | case bp_catchpoint: |
c906108c | 9108 | break; |
c5aa993b | 9109 | |
c906108c | 9110 | default: |
a3f17187 | 9111 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 9112 | /* fall through */ |
0fd8e87f UW |
9113 | /* Delete overlay event and longjmp master breakpoints; they will be |
9114 | reset later by breakpoint_re_set. */ | |
1900040c | 9115 | case bp_overlay_event: |
0fd8e87f | 9116 | case bp_longjmp_master: |
c906108c SS |
9117 | delete_breakpoint (b); |
9118 | break; | |
9119 | ||
c5aa993b JM |
9120 | /* This breakpoint is special, it's set up when the inferior |
9121 | starts and we really don't want to touch it. */ | |
c906108c SS |
9122 | case bp_shlib_event: |
9123 | ||
c4093a6a JM |
9124 | /* Like bp_shlib_event, this breakpoint type is special. |
9125 | Once it is set up, we do not want to touch it. */ | |
9126 | case bp_thread_event: | |
9127 | ||
c5aa993b JM |
9128 | /* Keep temporary breakpoints, which can be encountered when we step |
9129 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
9130 | Otherwise these should have been blown away via the cleanup chain | |
9131 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
9132 | case bp_until: |
9133 | case bp_finish: | |
9134 | case bp_watchpoint_scope: | |
9135 | case bp_call_dummy: | |
9136 | case bp_step_resume: | |
611c83ae PA |
9137 | case bp_longjmp: |
9138 | case bp_longjmp_resume: | |
4efc6507 | 9139 | case bp_jit_event: |
c906108c SS |
9140 | break; |
9141 | } | |
9142 | ||
6c95b8df | 9143 | do_cleanups (cleanups); |
c906108c SS |
9144 | return 0; |
9145 | } | |
9146 | ||
69de3c6a | 9147 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 9148 | void |
69de3c6a | 9149 | breakpoint_re_set (void) |
c906108c SS |
9150 | { |
9151 | struct breakpoint *b, *temp; | |
9152 | enum language save_language; | |
9153 | int save_input_radix; | |
6c95b8df | 9154 | struct cleanup *old_chain; |
c5aa993b | 9155 | |
c906108c SS |
9156 | save_language = current_language->la_language; |
9157 | save_input_radix = input_radix; | |
6c95b8df PA |
9158 | old_chain = save_current_program_space (); |
9159 | ||
c906108c | 9160 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 9161 | { |
53a5351d | 9162 | /* Format possible error msg */ |
fe3f5fa8 | 9163 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
9164 | b->number); |
9165 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 9166 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 9167 | do_cleanups (cleanups); |
c5aa993b | 9168 | } |
c906108c SS |
9169 | set_language (save_language); |
9170 | input_radix = save_input_radix; | |
e62c965a | 9171 | |
0756c555 | 9172 | jit_breakpoint_re_set (); |
4efc6507 | 9173 | |
6c95b8df PA |
9174 | do_cleanups (old_chain); |
9175 | ||
69de3c6a | 9176 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
9177 | create_longjmp_master_breakpoint ("longjmp"); |
9178 | create_longjmp_master_breakpoint ("_longjmp"); | |
9179 | create_longjmp_master_breakpoint ("siglongjmp"); | |
9180 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
9181 | } |
9182 | \f | |
c906108c SS |
9183 | /* Reset the thread number of this breakpoint: |
9184 | ||
9185 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 9186 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 9187 | void |
fba45db2 | 9188 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
9189 | { |
9190 | if (b->thread != -1) | |
9191 | { | |
39f77062 KB |
9192 | if (in_thread_list (inferior_ptid)) |
9193 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
9194 | |
9195 | /* We're being called after following a fork. The new fork is | |
9196 | selected as current, and unless this was a vfork will have a | |
9197 | different program space from the original thread. Reset that | |
9198 | as well. */ | |
9199 | b->loc->pspace = current_program_space; | |
c906108c SS |
9200 | } |
9201 | } | |
9202 | ||
03ac34d5 MS |
9203 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9204 | If from_tty is nonzero, it prints a message to that effect, | |
9205 | which ends with a period (no newline). */ | |
9206 | ||
c906108c | 9207 | void |
fba45db2 | 9208 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 9209 | { |
52f0bd74 | 9210 | struct breakpoint *b; |
c906108c SS |
9211 | |
9212 | if (count < 0) | |
9213 | count = 0; | |
9214 | ||
9215 | ALL_BREAKPOINTS (b) | |
9216 | if (b->number == bptnum) | |
c5aa993b JM |
9217 | { |
9218 | b->ignore_count = count; | |
221ea385 KS |
9219 | if (from_tty) |
9220 | { | |
9221 | if (count == 0) | |
a3f17187 | 9222 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
9223 | bptnum); |
9224 | else if (count == 1) | |
a3f17187 | 9225 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
9226 | bptnum); |
9227 | else | |
a3f17187 | 9228 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
9229 | count, bptnum); |
9230 | } | |
c5aa993b | 9231 | breakpoints_changed (); |
383f836e | 9232 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
9233 | return; |
9234 | } | |
c906108c | 9235 | |
8a3fe4f8 | 9236 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
9237 | } |
9238 | ||
b2175913 MS |
9239 | void |
9240 | make_breakpoint_silent (struct breakpoint *b) | |
9241 | { | |
9242 | /* Silence the breakpoint. */ | |
9243 | b->silent = 1; | |
9244 | } | |
9245 | ||
c906108c SS |
9246 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9247 | ||
9248 | static void | |
fba45db2 | 9249 | ignore_command (char *args, int from_tty) |
c906108c SS |
9250 | { |
9251 | char *p = args; | |
52f0bd74 | 9252 | int num; |
c906108c SS |
9253 | |
9254 | if (p == 0) | |
e2e0b3e5 | 9255 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9256 | |
c906108c | 9257 | num = get_number (&p); |
5c44784c | 9258 | if (num == 0) |
8a3fe4f8 | 9259 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9260 | if (*p == 0) |
8a3fe4f8 | 9261 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9262 | |
9263 | set_ignore_count (num, | |
9264 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9265 | from_tty); | |
221ea385 KS |
9266 | if (from_tty) |
9267 | printf_filtered ("\n"); | |
c906108c SS |
9268 | } |
9269 | \f | |
9270 | /* Call FUNCTION on each of the breakpoints | |
9271 | whose numbers are given in ARGS. */ | |
9272 | ||
9273 | static void | |
831662b3 | 9274 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 9275 | { |
52f0bd74 | 9276 | char *p = args; |
c906108c | 9277 | char *p1; |
52f0bd74 AC |
9278 | int num; |
9279 | struct breakpoint *b, *tmp; | |
11cf8741 | 9280 | int match; |
c906108c SS |
9281 | |
9282 | if (p == 0) | |
e2e0b3e5 | 9283 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9284 | |
9285 | while (*p) | |
9286 | { | |
11cf8741 | 9287 | match = 0; |
c906108c | 9288 | p1 = p; |
c5aa993b | 9289 | |
5c44784c JM |
9290 | num = get_number_or_range (&p1); |
9291 | if (num == 0) | |
c5aa993b | 9292 | { |
8a3fe4f8 | 9293 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9294 | } |
9295 | else | |
9296 | { | |
9297 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9298 | if (b->number == num) | |
9299 | { | |
9300 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9301 | match = 1; |
5c44784c JM |
9302 | function (b); |
9303 | if (related_breakpoint) | |
9304 | function (related_breakpoint); | |
11cf8741 | 9305 | break; |
5c44784c | 9306 | } |
11cf8741 | 9307 | if (match == 0) |
a3f17187 | 9308 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9309 | } |
c906108c SS |
9310 | p = p1; |
9311 | } | |
9312 | } | |
9313 | ||
0d381245 VP |
9314 | static struct bp_location * |
9315 | find_location_by_number (char *number) | |
9316 | { | |
9317 | char *dot = strchr (number, '.'); | |
9318 | char *p1; | |
9319 | int bp_num; | |
9320 | int loc_num; | |
9321 | struct breakpoint *b; | |
9322 | struct bp_location *loc; | |
9323 | ||
9324 | *dot = '\0'; | |
9325 | ||
9326 | p1 = number; | |
9327 | bp_num = get_number_or_range (&p1); | |
9328 | if (bp_num == 0) | |
9329 | error (_("Bad breakpoint number '%s'"), number); | |
9330 | ||
9331 | ALL_BREAKPOINTS (b) | |
9332 | if (b->number == bp_num) | |
9333 | { | |
9334 | break; | |
9335 | } | |
9336 | ||
9337 | if (!b || b->number != bp_num) | |
9338 | error (_("Bad breakpoint number '%s'"), number); | |
9339 | ||
9340 | p1 = dot+1; | |
9341 | loc_num = get_number_or_range (&p1); | |
9342 | if (loc_num == 0) | |
9343 | error (_("Bad breakpoint location number '%s'"), number); | |
9344 | ||
9345 | --loc_num; | |
9346 | loc = b->loc; | |
9347 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9348 | ; | |
9349 | if (!loc) | |
9350 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9351 | ||
9352 | return loc; | |
9353 | } | |
9354 | ||
9355 | ||
1900040c MS |
9356 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9357 | If from_tty is nonzero, it prints a message to that effect, | |
9358 | which ends with a period (no newline). */ | |
9359 | ||
c906108c | 9360 | void |
fba45db2 | 9361 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9362 | { |
9363 | /* Never disable a watchpoint scope breakpoint; we want to | |
9364 | hit them when we leave scope so we can delete both the | |
9365 | watchpoint and its scope breakpoint at that time. */ | |
9366 | if (bpt->type == bp_watchpoint_scope) | |
9367 | return; | |
9368 | ||
c2c6d25f | 9369 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9370 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9371 | return; |
9372 | ||
b5de0fa7 | 9373 | bpt->enable_state = bp_disabled; |
c906108c | 9374 | |
b60e7edf | 9375 | update_global_location_list (0); |
c906108c | 9376 | |
383f836e | 9377 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9378 | } |
9379 | ||
c906108c | 9380 | static void |
fba45db2 | 9381 | disable_command (char *args, int from_tty) |
c906108c | 9382 | { |
52f0bd74 | 9383 | struct breakpoint *bpt; |
c906108c SS |
9384 | if (args == 0) |
9385 | ALL_BREAKPOINTS (bpt) | |
9386 | switch (bpt->type) | |
c5aa993b JM |
9387 | { |
9388 | case bp_none: | |
8a3fe4f8 | 9389 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9390 | bpt->number); |
c5aa993b JM |
9391 | continue; |
9392 | case bp_breakpoint: | |
1042e4c0 | 9393 | case bp_tracepoint: |
7a697b8d | 9394 | case bp_fast_tracepoint: |
ce78b96d | 9395 | case bp_catchpoint: |
c5aa993b JM |
9396 | case bp_hardware_breakpoint: |
9397 | case bp_watchpoint: | |
9398 | case bp_hardware_watchpoint: | |
9399 | case bp_read_watchpoint: | |
9400 | case bp_access_watchpoint: | |
9401 | disable_breakpoint (bpt); | |
9402 | default: | |
9403 | continue; | |
9404 | } | |
0d381245 VP |
9405 | else if (strchr (args, '.')) |
9406 | { | |
9407 | struct bp_location *loc = find_location_by_number (args); | |
9408 | if (loc) | |
9409 | loc->enabled = 0; | |
b60e7edf | 9410 | update_global_location_list (0); |
0d381245 | 9411 | } |
c906108c SS |
9412 | else |
9413 | map_breakpoint_numbers (args, disable_breakpoint); | |
9414 | } | |
9415 | ||
9416 | static void | |
fba45db2 | 9417 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9418 | { |
c906108c SS |
9419 | int target_resources_ok, other_type_used; |
9420 | struct value *mark; | |
9421 | ||
9422 | if (bpt->type == bp_hardware_breakpoint) | |
9423 | { | |
9424 | int i; | |
c5aa993b | 9425 | i = hw_breakpoint_used_count (); |
53a5351d | 9426 | target_resources_ok = |
d92524f1 | 9427 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9428 | i + 1, 0); |
c906108c | 9429 | if (target_resources_ok == 0) |
8a3fe4f8 | 9430 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9431 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9432 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9433 | } |
9434 | ||
059fb39f PM |
9435 | if (bpt->type == bp_watchpoint |
9436 | || bpt->type == bp_hardware_watchpoint | |
9437 | || bpt->type == bp_read_watchpoint | |
9438 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9439 | { |
dde02812 ES |
9440 | struct gdb_exception e; |
9441 | ||
9442 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9443 | { |
dde02812 | 9444 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9445 | } |
dde02812 | 9446 | if (e.reason < 0) |
c5aa993b | 9447 | { |
dde02812 ES |
9448 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9449 | bpt->number); | |
9450 | return; | |
c5aa993b | 9451 | } |
c906108c | 9452 | } |
0101ce28 | 9453 | |
b4c291bb KH |
9454 | if (bpt->enable_state != bp_permanent) |
9455 | bpt->enable_state = bp_enabled; | |
9456 | bpt->disposition = disposition; | |
b60e7edf | 9457 | update_global_location_list (1); |
b4c291bb KH |
9458 | breakpoints_changed (); |
9459 | ||
383f836e | 9460 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9461 | } |
9462 | ||
fe3f5fa8 | 9463 | |
c906108c | 9464 | void |
fba45db2 | 9465 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9466 | { |
9467 | do_enable_breakpoint (bpt, bpt->disposition); | |
9468 | } | |
9469 | ||
9470 | /* The enable command enables the specified breakpoints (or all defined | |
9471 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 9472 | in stopping the inferior. */ |
c906108c | 9473 | |
c906108c | 9474 | static void |
fba45db2 | 9475 | enable_command (char *args, int from_tty) |
c906108c | 9476 | { |
52f0bd74 | 9477 | struct breakpoint *bpt; |
c906108c SS |
9478 | if (args == 0) |
9479 | ALL_BREAKPOINTS (bpt) | |
9480 | switch (bpt->type) | |
c5aa993b JM |
9481 | { |
9482 | case bp_none: | |
8a3fe4f8 | 9483 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 9484 | bpt->number); |
c5aa993b JM |
9485 | continue; |
9486 | case bp_breakpoint: | |
1042e4c0 | 9487 | case bp_tracepoint: |
7a697b8d | 9488 | case bp_fast_tracepoint: |
ce78b96d | 9489 | case bp_catchpoint: |
c5aa993b JM |
9490 | case bp_hardware_breakpoint: |
9491 | case bp_watchpoint: | |
9492 | case bp_hardware_watchpoint: | |
9493 | case bp_read_watchpoint: | |
9494 | case bp_access_watchpoint: | |
9495 | enable_breakpoint (bpt); | |
9496 | default: | |
9497 | continue; | |
9498 | } | |
0d381245 VP |
9499 | else if (strchr (args, '.')) |
9500 | { | |
9501 | struct bp_location *loc = find_location_by_number (args); | |
9502 | if (loc) | |
9503 | loc->enabled = 1; | |
b60e7edf | 9504 | update_global_location_list (1); |
0d381245 | 9505 | } |
c906108c SS |
9506 | else |
9507 | map_breakpoint_numbers (args, enable_breakpoint); | |
9508 | } | |
9509 | ||
9510 | static void | |
fba45db2 | 9511 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 9512 | { |
b5de0fa7 | 9513 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
9514 | } |
9515 | ||
c906108c | 9516 | static void |
fba45db2 | 9517 | enable_once_command (char *args, int from_tty) |
c906108c SS |
9518 | { |
9519 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
9520 | } | |
9521 | ||
9522 | static void | |
fba45db2 | 9523 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9524 | { |
b5de0fa7 | 9525 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
9526 | } |
9527 | ||
c906108c | 9528 | static void |
fba45db2 | 9529 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
9530 | { |
9531 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
9532 | } | |
9533 | \f | |
fa8d40ab JJ |
9534 | static void |
9535 | set_breakpoint_cmd (char *args, int from_tty) | |
9536 | { | |
9537 | } | |
9538 | ||
9539 | static void | |
9540 | show_breakpoint_cmd (char *args, int from_tty) | |
9541 | { | |
9542 | } | |
9543 | ||
1f3b5d1b PP |
9544 | /* Invalidate last known value of any hardware watchpoint if |
9545 | the memory which that value represents has been written to by | |
9546 | GDB itself. */ | |
9547 | ||
9548 | static void | |
9549 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
9550 | const bfd_byte *data) | |
9551 | { | |
9552 | struct breakpoint *bp; | |
9553 | ||
9554 | ALL_BREAKPOINTS (bp) | |
9555 | if (bp->enable_state == bp_enabled | |
9556 | && bp->type == bp_hardware_watchpoint | |
9557 | && bp->val_valid && bp->val) | |
9558 | { | |
9559 | struct bp_location *loc; | |
9560 | ||
9561 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
9562 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
9563 | && loc->address + loc->length > addr | |
9564 | && addr + len > loc->address) | |
9565 | { | |
9566 | value_free (bp->val); | |
9567 | bp->val = NULL; | |
9568 | bp->val_valid = 0; | |
9569 | } | |
9570 | } | |
9571 | } | |
9572 | ||
c906108c SS |
9573 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
9574 | ||
9575 | struct symtabs_and_lines | |
fba45db2 | 9576 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
9577 | { |
9578 | struct symtabs_and_lines sals; | |
9579 | if (string == 0) | |
8a3fe4f8 | 9580 | error (_("Empty line specification.")); |
c906108c SS |
9581 | if (default_breakpoint_valid) |
9582 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
9583 | default_breakpoint_symtab, |
9584 | default_breakpoint_line, | |
68219205 | 9585 | (char ***) NULL, NULL); |
c906108c SS |
9586 | else |
9587 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 9588 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 9589 | if (*string) |
8a3fe4f8 | 9590 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
9591 | return sals; |
9592 | } | |
8181d85f DJ |
9593 | |
9594 | /* Create and insert a raw software breakpoint at PC. Return an | |
9595 | identifier, which should be used to remove the breakpoint later. | |
9596 | In general, places which call this should be using something on the | |
9597 | breakpoint chain instead; this function should be eliminated | |
9598 | someday. */ | |
9599 | ||
9600 | void * | |
6c95b8df PA |
9601 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
9602 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
9603 | { |
9604 | struct bp_target_info *bp_tgt; | |
9605 | ||
6c95b8df | 9606 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 9607 | |
6c95b8df | 9608 | bp_tgt->placed_address_space = aspace; |
8181d85f | 9609 | bp_tgt->placed_address = pc; |
6c95b8df | 9610 | |
a6d9a66e | 9611 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
9612 | { |
9613 | /* Could not insert the breakpoint. */ | |
9614 | xfree (bp_tgt); | |
9615 | return NULL; | |
9616 | } | |
9617 | ||
9618 | return bp_tgt; | |
9619 | } | |
9620 | ||
9621 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
9622 | ||
9623 | int | |
a6d9a66e | 9624 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
9625 | { |
9626 | struct bp_target_info *bp_tgt = bp; | |
9627 | int ret; | |
9628 | ||
a6d9a66e | 9629 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
9630 | xfree (bp_tgt); |
9631 | ||
9632 | return ret; | |
9633 | } | |
9634 | ||
9635 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
9636 | ||
9637 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 9638 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
9639 | |
9640 | /* Create and insert a breakpoint for software single step. */ | |
9641 | ||
9642 | void | |
6c95b8df PA |
9643 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
9644 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
9645 | { |
9646 | void **bpt_p; | |
9647 | ||
9648 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
9649 | { |
9650 | bpt_p = &single_step_breakpoints[0]; | |
9651 | single_step_gdbarch[0] = gdbarch; | |
9652 | } | |
8181d85f DJ |
9653 | else |
9654 | { | |
9655 | gdb_assert (single_step_breakpoints[1] == NULL); | |
9656 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 9657 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
9658 | } |
9659 | ||
9660 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
9661 | to only create the breakpoints once, and actually put them on the | |
9662 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
9663 | adjust the addresses each time they were needed. Doing this requires | |
9664 | corresponding changes elsewhere where single step breakpoints are | |
9665 | handled, however. So, for now, we use this. */ | |
9666 | ||
6c95b8df | 9667 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 9668 | if (*bpt_p == NULL) |
5af949e3 UW |
9669 | error (_("Could not insert single-step breakpoint at %s"), |
9670 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
9671 | } |
9672 | ||
9673 | /* Remove and delete any breakpoints used for software single step. */ | |
9674 | ||
9675 | void | |
9676 | remove_single_step_breakpoints (void) | |
9677 | { | |
9678 | gdb_assert (single_step_breakpoints[0] != NULL); | |
9679 | ||
9680 | /* See insert_single_step_breakpoint for more about this deprecated | |
9681 | call. */ | |
a6d9a66e UW |
9682 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
9683 | single_step_breakpoints[0]); | |
9684 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
9685 | single_step_breakpoints[0] = NULL; |
9686 | ||
9687 | if (single_step_breakpoints[1] != NULL) | |
9688 | { | |
a6d9a66e UW |
9689 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
9690 | single_step_breakpoints[1]); | |
9691 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
9692 | single_step_breakpoints[1] = NULL; |
9693 | } | |
9694 | } | |
9695 | ||
1aafd4da UW |
9696 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
9697 | ||
9698 | static int | |
6c95b8df | 9699 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
9700 | { |
9701 | int i; | |
9702 | ||
9703 | for (i = 0; i < 2; i++) | |
9704 | { | |
9705 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
9706 | if (bp_tgt |
9707 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
9708 | bp_tgt->placed_address, | |
9709 | aspace, pc)) | |
1aafd4da UW |
9710 | return 1; |
9711 | } | |
9712 | ||
9713 | return 0; | |
9714 | } | |
9715 | ||
a96d9b2e SDJ |
9716 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
9717 | non-zero otherwise. */ | |
9718 | static int | |
9719 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
9720 | { | |
9721 | if (syscall_catchpoint_p (bp) | |
9722 | && bp->enable_state != bp_disabled | |
9723 | && bp->enable_state != bp_call_disabled) | |
9724 | return 1; | |
9725 | else | |
9726 | return 0; | |
9727 | } | |
9728 | ||
9729 | int | |
9730 | catch_syscall_enabled (void) | |
9731 | { | |
9732 | struct inferior *inf = current_inferior (); | |
9733 | ||
9734 | return inf->total_syscalls_count != 0; | |
9735 | } | |
9736 | ||
9737 | int | |
9738 | catching_syscall_number (int syscall_number) | |
9739 | { | |
9740 | struct breakpoint *bp; | |
9741 | ||
9742 | ALL_BREAKPOINTS (bp) | |
9743 | if (is_syscall_catchpoint_enabled (bp)) | |
9744 | { | |
9745 | if (bp->syscalls_to_be_caught) | |
9746 | { | |
9747 | int i, iter; | |
9748 | for (i = 0; | |
9749 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
9750 | i++) | |
9751 | if (syscall_number == iter) | |
9752 | return 1; | |
9753 | } | |
9754 | else | |
9755 | return 1; | |
9756 | } | |
9757 | ||
9758 | return 0; | |
9759 | } | |
9760 | ||
9761 | /* Complete syscall names. Used by "catch syscall". */ | |
9762 | static char ** | |
9763 | catch_syscall_completer (struct cmd_list_element *cmd, | |
9764 | char *text, char *word) | |
9765 | { | |
9766 | const char **list = get_syscall_names (); | |
9767 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
9768 | } | |
9769 | ||
1042e4c0 SS |
9770 | /* Tracepoint-specific operations. */ |
9771 | ||
9772 | /* Set tracepoint count to NUM. */ | |
9773 | static void | |
9774 | set_tracepoint_count (int num) | |
9775 | { | |
9776 | tracepoint_count = num; | |
4fa62494 | 9777 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
9778 | } |
9779 | ||
9780 | void | |
9781 | trace_command (char *arg, int from_tty) | |
9782 | { | |
a6d9a66e UW |
9783 | break_command_really (get_current_arch (), |
9784 | arg, | |
1042e4c0 SS |
9785 | NULL, 0, 1 /* parse arg */, |
9786 | 0 /* tempflag */, 0 /* hardwareflag */, | |
9787 | 1 /* traceflag */, | |
9788 | 0 /* Ignore count */, | |
9789 | pending_break_support, | |
9790 | NULL, | |
9791 | from_tty, | |
9792 | 1 /* enabled */); | |
9793 | set_tracepoint_count (breakpoint_count); | |
9794 | } | |
9795 | ||
7a697b8d SS |
9796 | void |
9797 | ftrace_command (char *arg, int from_tty) | |
9798 | { | |
9799 | break_command_really (get_current_arch (), | |
9800 | arg, | |
9801 | NULL, 0, 1 /* parse arg */, | |
9802 | 0 /* tempflag */, 1 /* hardwareflag */, | |
9803 | 1 /* traceflag */, | |
9804 | 0 /* Ignore count */, | |
9805 | pending_break_support, | |
9806 | NULL, | |
9807 | from_tty, | |
9808 | 1 /* enabled */); | |
9809 | set_tracepoint_count (breakpoint_count); | |
9810 | } | |
9811 | ||
00bf0b85 SS |
9812 | /* Given information about a tracepoint as recorded on a target (which |
9813 | can be either a live system or a trace file), attempt to create an | |
9814 | equivalent GDB tracepoint. This is not a reliable process, since | |
9815 | the target does not necessarily have all the information used when | |
9816 | the tracepoint was originally defined. */ | |
9817 | ||
9818 | struct breakpoint * | |
9819 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 SS |
9820 | { |
9821 | char buf[100]; | |
9822 | struct breakpoint *tp; | |
00bf0b85 SS |
9823 | |
9824 | /* In the absence of a source location, fall back to raw address. */ | |
9825 | sprintf (buf, "*%s", paddress (get_current_arch(), utp->addr)); | |
d5551862 | 9826 | |
00bf0b85 SS |
9827 | break_command_really (get_current_arch (), |
9828 | buf, | |
9829 | NULL, 0, 1 /* parse arg */, | |
9830 | 0 /* tempflag */, | |
9831 | (utp->type == bp_fast_tracepoint) /* hardwareflag */, | |
9832 | 1 /* traceflag */, | |
9833 | 0 /* Ignore count */, | |
9834 | pending_break_support, | |
9835 | NULL, | |
9836 | 0 /* from_tty */, | |
9837 | utp->enabled /* enabled */); | |
9838 | set_tracepoint_count (breakpoint_count); | |
9839 | ||
9840 | tp = get_tracepoint (tracepoint_count); | |
d5551862 | 9841 | |
00bf0b85 SS |
9842 | if (utp->pass > 0) |
9843 | { | |
9844 | sprintf (buf, "%d %d", utp->pass, tp->number); | |
9845 | ||
9846 | trace_pass_command (buf, 0); | |
9847 | } | |
9848 | ||
9849 | if (utp->cond) | |
9850 | { | |
9851 | printf_filtered ("Want to restore a condition\n"); | |
9852 | } | |
9853 | ||
9854 | if (utp->numactions > 0) | |
9855 | { | |
9856 | printf_filtered ("Want to restore action list\n"); | |
9857 | } | |
d5551862 | 9858 | |
00bf0b85 SS |
9859 | if (utp->num_step_actions > 0) |
9860 | { | |
9861 | printf_filtered ("Want to restore action list\n"); | |
9862 | } | |
9863 | ||
9864 | return tp; | |
9865 | } | |
9866 | ||
1042e4c0 SS |
9867 | /* Print information on tracepoint number TPNUM_EXP, or all if |
9868 | omitted. */ | |
9869 | ||
9870 | static void | |
9871 | tracepoints_info (char *tpnum_exp, int from_tty) | |
9872 | { | |
9873 | struct breakpoint *b; | |
9874 | int tps_to_list = 0; | |
9875 | ||
9876 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
9877 | if (tpnum_exp == 0) | |
9878 | { | |
9879 | ALL_TRACEPOINTS (b) | |
9880 | { | |
9881 | if (b->number >= 0) | |
9882 | { | |
9883 | tps_to_list = 1; | |
9884 | break; | |
9885 | } | |
9886 | } | |
9887 | if (!tps_to_list) | |
9888 | { | |
9889 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
9890 | return; | |
9891 | } | |
9892 | } | |
9893 | ||
9894 | /* Otherwise be the same as "info break". */ | |
9895 | breakpoints_info (tpnum_exp, from_tty); | |
9896 | } | |
9897 | ||
9898 | /* The 'enable trace' command enables tracepoints. | |
9899 | Not supported by all targets. */ | |
9900 | static void | |
9901 | enable_trace_command (char *args, int from_tty) | |
9902 | { | |
9903 | enable_command (args, from_tty); | |
9904 | } | |
9905 | ||
9906 | /* The 'disable trace' command disables tracepoints. | |
9907 | Not supported by all targets. */ | |
9908 | static void | |
9909 | disable_trace_command (char *args, int from_tty) | |
9910 | { | |
9911 | disable_command (args, from_tty); | |
9912 | } | |
9913 | ||
9914 | /* Remove a tracepoint (or all if no argument) */ | |
9915 | static void | |
9916 | delete_trace_command (char *arg, int from_tty) | |
9917 | { | |
9918 | struct breakpoint *b, *temp; | |
9919 | ||
9920 | dont_repeat (); | |
9921 | ||
9922 | if (arg == 0) | |
9923 | { | |
9924 | int breaks_to_delete = 0; | |
9925 | ||
9926 | /* Delete all breakpoints if no argument. | |
9927 | Do not delete internal or call-dummy breakpoints, these | |
9928 | have to be deleted with an explicit breakpoint number argument. */ | |
9929 | ALL_TRACEPOINTS (b) | |
9930 | { | |
9931 | if (b->number >= 0) | |
9932 | { | |
9933 | breaks_to_delete = 1; | |
9934 | break; | |
9935 | } | |
9936 | } | |
9937 | ||
9938 | /* Ask user only if there are some breakpoints to delete. */ | |
9939 | if (!from_tty | |
9940 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
9941 | { | |
9942 | ALL_BREAKPOINTS_SAFE (b, temp) | |
9943 | { | |
7a697b8d | 9944 | if (tracepoint_type (b) |
059fb39f | 9945 | && b->number >= 0) |
1042e4c0 SS |
9946 | delete_breakpoint (b); |
9947 | } | |
9948 | } | |
9949 | } | |
9950 | else | |
9951 | map_breakpoint_numbers (arg, delete_breakpoint); | |
9952 | } | |
9953 | ||
9954 | /* Set passcount for tracepoint. | |
9955 | ||
9956 | First command argument is passcount, second is tracepoint number. | |
9957 | If tracepoint number omitted, apply to most recently defined. | |
9958 | Also accepts special argument "all". */ | |
9959 | ||
9960 | static void | |
9961 | trace_pass_command (char *args, int from_tty) | |
9962 | { | |
9963 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
9964 | unsigned int count; | |
9965 | int all = 0; | |
9966 | ||
9967 | if (args == 0 || *args == 0) | |
9968 | error (_("passcount command requires an argument (count + optional TP num)")); | |
9969 | ||
9970 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
9971 | ||
9972 | while (*args && isspace ((int) *args)) | |
9973 | args++; | |
9974 | ||
9975 | if (*args && strncasecmp (args, "all", 3) == 0) | |
9976 | { | |
9977 | args += 3; /* Skip special argument "all". */ | |
9978 | all = 1; | |
9979 | if (*args) | |
9980 | error (_("Junk at end of arguments.")); | |
9981 | } | |
9982 | else | |
9983 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
9984 | ||
9985 | do | |
9986 | { | |
9987 | if (t1) | |
9988 | { | |
9989 | ALL_TRACEPOINTS (t2) | |
9990 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
9991 | { | |
9992 | t2->pass_count = count; | |
9993 | observer_notify_tracepoint_modified (t2->number); | |
9994 | if (from_tty) | |
9995 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
9996 | t2->number, count); | |
9997 | } | |
9998 | if (! all && *args) | |
9999 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
10000 | } | |
10001 | } | |
10002 | while (*args); | |
10003 | } | |
10004 | ||
10005 | struct breakpoint * | |
10006 | get_tracepoint (int num) | |
10007 | { | |
10008 | struct breakpoint *t; | |
10009 | ||
10010 | ALL_TRACEPOINTS (t) | |
10011 | if (t->number == num) | |
10012 | return t; | |
10013 | ||
10014 | return NULL; | |
10015 | } | |
10016 | ||
d5551862 SS |
10017 | /* Find the tracepoint with the given target-side number (which may be |
10018 | different from the tracepoint number after disconnecting and | |
10019 | reconnecting). */ | |
10020 | ||
10021 | struct breakpoint * | |
10022 | get_tracepoint_by_number_on_target (int num) | |
10023 | { | |
10024 | struct breakpoint *t; | |
10025 | ||
10026 | ALL_TRACEPOINTS (t) | |
10027 | if (t->number_on_target == num) | |
10028 | return t; | |
10029 | ||
10030 | return NULL; | |
10031 | } | |
10032 | ||
1042e4c0 SS |
10033 | /* Utility: parse a tracepoint number and look it up in the list. |
10034 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
10035 | if OPTIONAL_P is true, then if the argument is missing, the most | |
10036 | recent tracepoint (tracepoint_count) is returned. */ | |
10037 | struct breakpoint * | |
10038 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
10039 | { | |
10040 | extern int tracepoint_count; | |
10041 | struct breakpoint *t; | |
10042 | int tpnum; | |
10043 | char *instring = arg == NULL ? NULL : *arg; | |
10044 | ||
10045 | if (arg == NULL || *arg == NULL || ! **arg) | |
10046 | { | |
10047 | if (optional_p) | |
10048 | tpnum = tracepoint_count; | |
10049 | else | |
10050 | error_no_arg (_("tracepoint number")); | |
10051 | } | |
10052 | else | |
10053 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
10054 | ||
10055 | if (tpnum <= 0) | |
10056 | { | |
10057 | if (instring && *instring) | |
10058 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
10059 | instring); | |
10060 | else | |
10061 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
10062 | return NULL; | |
10063 | } | |
10064 | ||
10065 | ALL_TRACEPOINTS (t) | |
10066 | if (t->number == tpnum) | |
10067 | { | |
10068 | return t; | |
10069 | } | |
10070 | ||
10071 | /* FIXME: if we are in the middle of a range we don't want to give | |
10072 | a message. The current interface to get_number_or_range doesn't | |
10073 | allow us to discover this. */ | |
10074 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
10075 | return NULL; | |
10076 | } | |
10077 | ||
10078 | /* save-tracepoints command */ | |
10079 | static void | |
10080 | tracepoint_save_command (char *args, int from_tty) | |
10081 | { | |
10082 | struct breakpoint *tp; | |
10083 | int any_tp = 0; | |
10084 | struct action_line *line; | |
10085 | FILE *fp; | |
10086 | char *i1 = " ", *i2 = " "; | |
10087 | char *indent, *actionline, *pathname; | |
10088 | char tmp[40]; | |
10089 | struct cleanup *cleanup; | |
10090 | ||
10091 | if (args == 0 || *args == 0) | |
10092 | error (_("Argument required (file name in which to save tracepoints)")); | |
10093 | ||
10094 | /* See if we have anything to save. */ | |
10095 | ALL_TRACEPOINTS (tp) | |
10096 | { | |
10097 | any_tp = 1; | |
10098 | break; | |
10099 | } | |
10100 | if (!any_tp) | |
10101 | { | |
10102 | warning (_("save-tracepoints: no tracepoints to save.")); | |
10103 | return; | |
10104 | } | |
10105 | ||
10106 | pathname = tilde_expand (args); | |
10107 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
10108 | fp = fopen (pathname, "w"); |
10109 | if (!fp) | |
1042e4c0 SS |
10110 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
10111 | args, safe_strerror (errno)); | |
10112 | make_cleanup_fclose (fp); | |
10113 | ||
10114 | ALL_TRACEPOINTS (tp) | |
10115 | { | |
10116 | if (tp->addr_string) | |
10117 | fprintf (fp, "trace %s\n", tp->addr_string); | |
10118 | else | |
10119 | { | |
10120 | sprintf_vma (tmp, tp->loc->address); | |
10121 | fprintf (fp, "trace *0x%s\n", tmp); | |
10122 | } | |
10123 | ||
10124 | if (tp->pass_count) | |
10125 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
10126 | ||
10127 | if (tp->actions) | |
10128 | { | |
10129 | fprintf (fp, " actions\n"); | |
10130 | indent = i1; | |
10131 | for (line = tp->actions; line; line = line->next) | |
10132 | { | |
10133 | struct cmd_list_element *cmd; | |
10134 | ||
10135 | QUIT; /* allow user to bail out with ^C */ | |
10136 | actionline = line->action; | |
10137 | while (isspace ((int) *actionline)) | |
10138 | actionline++; | |
10139 | ||
10140 | fprintf (fp, "%s%s\n", indent, actionline); | |
10141 | if (*actionline != '#') /* skip for comment lines */ | |
10142 | { | |
10143 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
10144 | if (cmd == 0) | |
10145 | error (_("Bad action list item: %s"), actionline); | |
10146 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
10147 | indent = i2; | |
10148 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
10149 | indent = i1; | |
10150 | } | |
10151 | } | |
10152 | } | |
10153 | } | |
10154 | do_cleanups (cleanup); | |
10155 | if (from_tty) | |
10156 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
10157 | return; | |
10158 | } | |
10159 | ||
10160 | /* Create a vector of all tracepoints. */ | |
10161 | ||
10162 | VEC(breakpoint_p) * | |
10163 | all_tracepoints () | |
10164 | { | |
10165 | VEC(breakpoint_p) *tp_vec = 0; | |
10166 | struct breakpoint *tp; | |
10167 | ||
10168 | ALL_TRACEPOINTS (tp) | |
10169 | { | |
10170 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
10171 | } | |
10172 | ||
10173 | return tp_vec; | |
10174 | } | |
10175 | ||
c906108c | 10176 | \f |
31e2b00f AS |
10177 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
10178 | It is defined as a macro to prevent duplication. | |
10179 | COMMAND should be a string constant containing the name of the command. */ | |
10180 | #define BREAK_ARGS_HELP(command) \ | |
10181 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
10182 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
10183 | If a line number is specified, break at start of code for that line.\n\ | |
10184 | If a function is specified, break at start of code for that function.\n\ | |
10185 | If an address is specified, break at that exact address.\n\ | |
10186 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
10187 | This is useful for breaking on return to a stack frame.\n\ | |
10188 | \n\ | |
10189 | THREADNUM is the number from \"info threads\".\n\ | |
10190 | CONDITION is a boolean expression.\n\ | |
10191 | \n\ | |
10192 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
10193 | \n\ | |
10194 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
10195 | ||
44feb3ce TT |
10196 | /* List of subcommands for "catch". */ |
10197 | static struct cmd_list_element *catch_cmdlist; | |
10198 | ||
10199 | /* List of subcommands for "tcatch". */ | |
10200 | static struct cmd_list_element *tcatch_cmdlist; | |
10201 | ||
10202 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
10203 | lists, and pass some additional user data to the command function. */ | |
10204 | static void | |
10205 | add_catch_command (char *name, char *docstring, | |
10206 | void (*sfunc) (char *args, int from_tty, | |
10207 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
10208 | char **(*completer) (struct cmd_list_element *cmd, |
10209 | char *text, char *word), | |
44feb3ce TT |
10210 | void *user_data_catch, |
10211 | void *user_data_tcatch) | |
10212 | { | |
10213 | struct cmd_list_element *command; | |
10214 | ||
10215 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10216 | &catch_cmdlist); | |
10217 | set_cmd_sfunc (command, sfunc); | |
10218 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 10219 | set_cmd_completer (command, completer); |
44feb3ce TT |
10220 | |
10221 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10222 | &tcatch_cmdlist); | |
10223 | set_cmd_sfunc (command, sfunc); | |
10224 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 10225 | set_cmd_completer (command, completer); |
44feb3ce TT |
10226 | } |
10227 | ||
6c95b8df PA |
10228 | static void |
10229 | clear_syscall_counts (int pid) | |
10230 | { | |
10231 | struct inferior *inf = find_inferior_pid (pid); | |
10232 | ||
10233 | inf->total_syscalls_count = 0; | |
10234 | inf->any_syscall_count = 0; | |
10235 | VEC_free (int, inf->syscalls_counts); | |
10236 | } | |
10237 | ||
c906108c | 10238 | void |
fba45db2 | 10239 | _initialize_breakpoint (void) |
c906108c | 10240 | { |
fa8d40ab JJ |
10241 | static struct cmd_list_element *breakpoint_set_cmdlist; |
10242 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
10243 | struct cmd_list_element *c; |
10244 | ||
84acb35a | 10245 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 10246 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 10247 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 10248 | |
c906108c SS |
10249 | breakpoint_chain = 0; |
10250 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
10251 | before a breakpoint is set. */ | |
10252 | breakpoint_count = 0; | |
10253 | ||
1042e4c0 SS |
10254 | tracepoint_count = 0; |
10255 | ||
1bedd215 AC |
10256 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
10257 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
10258 | Usage is `ignore N COUNT'.")); | |
c906108c | 10259 | if (xdb_commands) |
c5aa993b | 10260 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 10261 | |
1bedd215 AC |
10262 | add_com ("commands", class_breakpoint, commands_command, _("\ |
10263 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
10264 | Give breakpoint number as argument after \"commands\".\n\ |
10265 | With no argument, the targeted breakpoint is the last one set.\n\ | |
10266 | The commands themselves follow starting on the next line.\n\ | |
10267 | Type a line containing \"end\" to indicate the end of them.\n\ | |
10268 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 10269 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 10270 | |
1bedd215 AC |
10271 | add_com ("condition", class_breakpoint, condition_command, _("\ |
10272 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 10273 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 10274 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 10275 | |
1bedd215 | 10276 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 10277 | Set a temporary breakpoint.\n\ |
c906108c SS |
10278 | Like \"break\" except the breakpoint is only temporary,\n\ |
10279 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
10280 | by using \"enable delete\" on the breakpoint number.\n\ |
10281 | \n" | |
10282 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 10283 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10284 | |
1bedd215 | 10285 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 10286 | Set a hardware assisted breakpoint.\n\ |
c906108c | 10287 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
10288 | some target hardware may not have this support.\n\ |
10289 | \n" | |
10290 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 10291 | set_cmd_completer (c, location_completer); |
c906108c | 10292 | |
1bedd215 | 10293 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 10294 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 10295 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
10296 | so it will be deleted when hit.\n\ |
10297 | \n" | |
10298 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 10299 | set_cmd_completer (c, location_completer); |
c906108c | 10300 | |
1bedd215 AC |
10301 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
10302 | Enable some breakpoints.\n\ | |
c906108c SS |
10303 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10304 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10305 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10306 | With a subcommand you can enable temporarily."), |
c906108c SS |
10307 | &enablelist, "enable ", 1, &cmdlist); |
10308 | if (xdb_commands) | |
1bedd215 AC |
10309 | add_com ("ab", class_breakpoint, enable_command, _("\ |
10310 | Enable some breakpoints.\n\ | |
c906108c SS |
10311 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10312 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10313 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10314 | With a subcommand you can enable temporarily.")); |
c906108c SS |
10315 | |
10316 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
10317 | ||
1bedd215 AC |
10318 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
10319 | Enable some breakpoints.\n\ | |
c906108c SS |
10320 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10321 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10322 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 10323 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 10324 | |
1a966eab AC |
10325 | add_cmd ("once", no_class, enable_once_command, _("\ |
10326 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10327 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10328 | &enablebreaklist); |
10329 | ||
1a966eab AC |
10330 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10331 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10332 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10333 | &enablebreaklist); |
10334 | ||
1a966eab AC |
10335 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10336 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10337 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10338 | &enablelist); |
10339 | ||
1a966eab AC |
10340 | add_cmd ("once", no_class, enable_once_command, _("\ |
10341 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10342 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10343 | &enablelist); |
10344 | ||
1bedd215 AC |
10345 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
10346 | Disable some breakpoints.\n\ | |
c906108c SS |
10347 | Arguments are breakpoint numbers with spaces in between.\n\ |
10348 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10349 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
10350 | &disablelist, "disable ", 1, &cmdlist); |
10351 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
10352 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
10353 | if (xdb_commands) | |
1bedd215 AC |
10354 | add_com ("sb", class_breakpoint, disable_command, _("\ |
10355 | Disable some breakpoints.\n\ | |
c906108c SS |
10356 | Arguments are breakpoint numbers with spaces in between.\n\ |
10357 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10358 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 10359 | |
1a966eab AC |
10360 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10361 | Disable some breakpoints.\n\ | |
c906108c SS |
10362 | Arguments are breakpoint numbers with spaces in between.\n\ |
10363 | To disable all breakpoints, give no argument.\n\ | |
10364 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10365 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10366 | &disablelist); |
10367 | ||
1bedd215 AC |
10368 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10369 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10370 | Arguments are breakpoint numbers with spaces in between.\n\ |
10371 | To delete all breakpoints, give no argument.\n\ | |
10372 | \n\ | |
10373 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10374 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10375 | &deletelist, "delete ", 1, &cmdlist); |
10376 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10377 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10378 | if (xdb_commands) |
1bedd215 AC |
10379 | add_com ("db", class_breakpoint, delete_command, _("\ |
10380 | Delete some breakpoints.\n\ | |
c906108c | 10381 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10382 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10383 | |
1a966eab AC |
10384 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10385 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10386 | Arguments are breakpoint numbers with spaces in between.\n\ |
10387 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10388 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10389 | &deletelist); |
10390 | ||
1bedd215 AC |
10391 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10392 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10393 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10394 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10395 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10396 | If an address is specified, breakpoints at that address are cleared.\n\ |
10397 | \n\ | |
10398 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10399 | is executing in.\n\ |
10400 | \n\ | |
1bedd215 | 10401 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10402 | |
1bedd215 | 10403 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10404 | Set breakpoint at specified line or function.\n" |
10405 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10406 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10407 | |
c906108c SS |
10408 | add_com_alias ("b", "break", class_run, 1); |
10409 | add_com_alias ("br", "break", class_run, 1); | |
10410 | add_com_alias ("bre", "break", class_run, 1); | |
10411 | add_com_alias ("brea", "break", class_run, 1); | |
10412 | ||
7681d515 PM |
10413 | if (xdb_commands) |
10414 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
10415 | |
10416 | if (dbx_commands) | |
10417 | { | |
1bedd215 AC |
10418 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
10419 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
10420 | &stoplist, "stop ", 1, &cmdlist); |
10421 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 10422 | _("Break in function or address."), &stoplist); |
c5aa993b | 10423 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 10424 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
10425 | add_com ("status", class_info, breakpoints_info, _("\ |
10426 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10427 | The \"Type\" column indicates one of:\n\ |
10428 | \tbreakpoint - normal breakpoint\n\ | |
10429 | \twatchpoint - watchpoint\n\ | |
10430 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10431 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10432 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10433 | address and file/line number respectively.\n\ |
10434 | \n\ | |
10435 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10436 | are set to the address of the last breakpoint listed unless the command\n\ |
10437 | is prefixed with \"server \".\n\n\ | |
c906108c | 10438 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10439 | breakpoint set.")); |
c906108c SS |
10440 | } |
10441 | ||
1bedd215 AC |
10442 | add_info ("breakpoints", breakpoints_info, _("\ |
10443 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10444 | The \"Type\" column indicates one of:\n\ |
10445 | \tbreakpoint - normal breakpoint\n\ | |
10446 | \twatchpoint - watchpoint\n\ | |
10447 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10448 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10449 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10450 | address and file/line number respectively.\n\ |
10451 | \n\ | |
10452 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10453 | are set to the address of the last breakpoint listed unless the command\n\ |
10454 | is prefixed with \"server \".\n\n\ | |
c906108c | 10455 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10456 | breakpoint set.")); |
c906108c | 10457 | |
6b04bdb7 MS |
10458 | add_info_alias ("b", "breakpoints", 1); |
10459 | ||
c906108c | 10460 | if (xdb_commands) |
1bedd215 AC |
10461 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
10462 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10463 | The \"Type\" column indicates one of:\n\ |
10464 | \tbreakpoint - normal breakpoint\n\ | |
10465 | \twatchpoint - watchpoint\n\ | |
10466 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10467 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10468 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10469 | address and file/line number respectively.\n\ |
10470 | \n\ | |
10471 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10472 | are set to the address of the last breakpoint listed unless the command\n\ |
10473 | is prefixed with \"server \".\n\n\ | |
c906108c | 10474 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10475 | breakpoint set.")); |
c906108c | 10476 | |
1a966eab AC |
10477 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
10478 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10479 | The \"Type\" column indicates one of:\n\ |
10480 | \tbreakpoint - normal breakpoint\n\ | |
10481 | \twatchpoint - watchpoint\n\ | |
10482 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
10483 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
10484 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
10485 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
10486 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
10487 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
10488 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
10489 | address and file/line number respectively.\n\ |
10490 | \n\ | |
10491 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10492 | are set to the address of the last breakpoint listed unless the command\n\ |
10493 | is prefixed with \"server \".\n\n\ | |
c906108c | 10494 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 10495 | breakpoint set."), |
c906108c SS |
10496 | &maintenanceinfolist); |
10497 | ||
44feb3ce TT |
10498 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
10499 | Set catchpoints to catch events."), | |
10500 | &catch_cmdlist, "catch ", | |
10501 | 0/*allow-unknown*/, &cmdlist); | |
10502 | ||
10503 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
10504 | Set temporary catchpoints to catch events."), | |
10505 | &tcatch_cmdlist, "tcatch ", | |
10506 | 0/*allow-unknown*/, &cmdlist); | |
10507 | ||
10508 | /* Add catch and tcatch sub-commands. */ | |
10509 | add_catch_command ("catch", _("\ | |
10510 | Catch an exception, when caught.\n\ | |
10511 | With an argument, catch only exceptions with the given name."), | |
10512 | catch_catch_command, | |
a96d9b2e | 10513 | NULL, |
44feb3ce TT |
10514 | CATCH_PERMANENT, |
10515 | CATCH_TEMPORARY); | |
10516 | add_catch_command ("throw", _("\ | |
10517 | Catch an exception, when thrown.\n\ | |
10518 | With an argument, catch only exceptions with the given name."), | |
10519 | catch_throw_command, | |
a96d9b2e | 10520 | NULL, |
44feb3ce TT |
10521 | CATCH_PERMANENT, |
10522 | CATCH_TEMPORARY); | |
10523 | add_catch_command ("fork", _("Catch calls to fork."), | |
10524 | catch_fork_command_1, | |
a96d9b2e | 10525 | NULL, |
44feb3ce TT |
10526 | (void *) (uintptr_t) catch_fork_permanent, |
10527 | (void *) (uintptr_t) catch_fork_temporary); | |
10528 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
10529 | catch_fork_command_1, | |
a96d9b2e | 10530 | NULL, |
44feb3ce TT |
10531 | (void *) (uintptr_t) catch_vfork_permanent, |
10532 | (void *) (uintptr_t) catch_vfork_temporary); | |
10533 | add_catch_command ("exec", _("Catch calls to exec."), | |
10534 | catch_exec_command_1, | |
a96d9b2e SDJ |
10535 | NULL, |
10536 | CATCH_PERMANENT, | |
10537 | CATCH_TEMPORARY); | |
10538 | add_catch_command ("syscall", _("\ | |
10539 | Catch system calls by their names and/or numbers.\n\ | |
10540 | Arguments say which system calls to catch. If no arguments\n\ | |
10541 | are given, every system call will be caught.\n\ | |
10542 | Arguments, if given, should be one or more system call names\n\ | |
10543 | (if your system supports that), or system call numbers."), | |
10544 | catch_syscall_command_1, | |
10545 | catch_syscall_completer, | |
44feb3ce TT |
10546 | CATCH_PERMANENT, |
10547 | CATCH_TEMPORARY); | |
44feb3ce TT |
10548 | add_catch_command ("exception", _("\ |
10549 | Catch Ada exceptions, when raised.\n\ | |
10550 | With an argument, catch only exceptions with the given name."), | |
10551 | catch_ada_exception_command, | |
a96d9b2e | 10552 | NULL, |
44feb3ce TT |
10553 | CATCH_PERMANENT, |
10554 | CATCH_TEMPORARY); | |
10555 | add_catch_command ("assert", _("\ | |
10556 | Catch failed Ada assertions, when raised.\n\ | |
10557 | With an argument, catch only exceptions with the given name."), | |
10558 | catch_assert_command, | |
a96d9b2e | 10559 | NULL, |
44feb3ce TT |
10560 | CATCH_PERMANENT, |
10561 | CATCH_TEMPORARY); | |
c5aa993b | 10562 | |
1bedd215 AC |
10563 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
10564 | Set a watchpoint for an expression.\n\ | |
c906108c | 10565 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10566 | an expression changes.")); |
65d12d83 | 10567 | set_cmd_completer (c, expression_completer); |
c906108c | 10568 | |
1bedd215 AC |
10569 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
10570 | Set a read watchpoint for an expression.\n\ | |
c906108c | 10571 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10572 | an expression is read.")); |
65d12d83 | 10573 | set_cmd_completer (c, expression_completer); |
c906108c | 10574 | |
1bedd215 AC |
10575 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
10576 | Set a watchpoint for an expression.\n\ | |
c906108c | 10577 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10578 | an expression is either read or written.")); |
65d12d83 | 10579 | set_cmd_completer (c, expression_completer); |
c906108c SS |
10580 | |
10581 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 10582 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
10583 | |
10584 | ||
920d2a44 AC |
10585 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
10586 | respond to changes - contrary to the description. */ | |
85c07804 AC |
10587 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
10588 | &can_use_hw_watchpoints, _("\ | |
10589 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
10590 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
10591 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
10592 | such is available. (However, any hardware watchpoints that were\n\ | |
10593 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
10594 | hardware.)"), |
10595 | NULL, | |
920d2a44 | 10596 | show_can_use_hw_watchpoints, |
85c07804 | 10597 | &setlist, &showlist); |
c906108c SS |
10598 | |
10599 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 10600 | |
1042e4c0 SS |
10601 | /* Tracepoint manipulation commands. */ |
10602 | ||
10603 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
10604 | Set a tracepoint at specified line or function.\n\ | |
10605 | \n" | |
10606 | BREAK_ARGS_HELP ("trace") "\n\ | |
10607 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
10608 | set_cmd_completer (c, location_completer); | |
10609 | ||
10610 | add_com_alias ("tp", "trace", class_alias, 0); | |
10611 | add_com_alias ("tr", "trace", class_alias, 1); | |
10612 | add_com_alias ("tra", "trace", class_alias, 1); | |
10613 | add_com_alias ("trac", "trace", class_alias, 1); | |
10614 | ||
7a697b8d SS |
10615 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
10616 | Set a fast tracepoint at specified line or function.\n\ | |
10617 | \n" | |
10618 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
10619 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
10620 | set_cmd_completer (c, location_completer); | |
10621 | ||
1042e4c0 SS |
10622 | add_info ("tracepoints", tracepoints_info, _("\ |
10623 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
10624 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
10625 | last tracepoint set.")); | |
10626 | ||
10627 | add_info_alias ("tp", "tracepoints", 1); | |
10628 | ||
10629 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
10630 | Delete specified tracepoints.\n\ | |
10631 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10632 | No argument means delete all tracepoints."), | |
10633 | &deletelist); | |
10634 | ||
10635 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
10636 | Disable specified tracepoints.\n\ | |
10637 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10638 | No argument means disable all tracepoints."), | |
10639 | &disablelist); | |
10640 | deprecate_cmd (c, "disable"); | |
10641 | ||
10642 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
10643 | Enable specified tracepoints.\n\ | |
10644 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10645 | No argument means enable all tracepoints."), | |
10646 | &enablelist); | |
10647 | deprecate_cmd (c, "enable"); | |
10648 | ||
10649 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
10650 | Set the passcount for a tracepoint.\n\ | |
10651 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
10652 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
10653 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
10654 | ||
10655 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
10656 | Save current tracepoint definitions as a script.\n\ | |
10657 | Use the 'source' command in another debug session to restore them.")); | |
10658 | set_cmd_completer (c, filename_completer); | |
10659 | ||
1bedd215 | 10660 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10661 | Breakpoint specific settings\n\ |
10662 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10663 | pending breakpoint behavior"), |
fa8d40ab JJ |
10664 | &breakpoint_set_cmdlist, "set breakpoint ", |
10665 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 10666 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10667 | Breakpoint specific settings\n\ |
10668 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10669 | pending breakpoint behavior"), |
fa8d40ab JJ |
10670 | &breakpoint_show_cmdlist, "show breakpoint ", |
10671 | 0/*allow-unknown*/, &showlist); | |
10672 | ||
7915a72c AC |
10673 | add_setshow_auto_boolean_cmd ("pending", no_class, |
10674 | &pending_break_support, _("\ | |
10675 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
10676 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
10677 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
10678 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
10679 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 10680 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 10681 | NULL, |
920d2a44 | 10682 | show_pending_break_support, |
6e1d7d6c AC |
10683 | &breakpoint_set_cmdlist, |
10684 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
10685 | |
10686 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
10687 | |
10688 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
10689 | &automatic_hardware_breakpoints, _("\ | |
10690 | Set automatic usage of hardware breakpoints."), _("\ | |
10691 | Show automatic usage of hardware breakpoints."), _("\ | |
10692 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
10693 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
10694 | a warning will be emitted for such breakpoints."), | |
10695 | NULL, | |
10696 | show_automatic_hardware_breakpoints, | |
10697 | &breakpoint_set_cmdlist, | |
10698 | &breakpoint_show_cmdlist); | |
74960c60 | 10699 | |
33e5cbd6 PA |
10700 | add_setshow_enum_cmd ("always-inserted", class_support, |
10701 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
10702 | Set mode for inserting breakpoints."), _("\ |
10703 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
10704 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
10705 | resumed, and removed when execution stops. When this mode is on,\n\ | |
10706 | breakpoints are inserted immediately and removed only when the user\n\ | |
10707 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
10708 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
10709 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
10710 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
10711 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
10712 | NULL, |
10713 | &show_always_inserted_mode, | |
10714 | &breakpoint_set_cmdlist, | |
10715 | &breakpoint_show_cmdlist); | |
765dc015 VP |
10716 | |
10717 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
10718 | |
10719 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 10720 | } |