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, |
0fb0cc75 | 5 | 2008, 2009 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 | |
a14ed312 | 190 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 191 | |
d85310f7 MS |
192 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
193 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 194 | |
a14ed312 | 195 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 196 | |
a14ed312 | 197 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 198 | |
6c95b8df PA |
199 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
200 | CORE_ADDR pc); | |
1aafd4da | 201 | |
fe3f5fa8 VP |
202 | static void free_bp_location (struct bp_location *loc); |
203 | ||
39d61571 | 204 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 205 | |
b60e7edf | 206 | static void update_global_location_list (int); |
a5606eee | 207 | |
b60e7edf | 208 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
209 | |
210 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
211 | ||
212 | static void insert_breakpoint_locations (void); | |
a5606eee | 213 | |
a96d9b2e SDJ |
214 | static int syscall_catchpoint_p (struct breakpoint *b); |
215 | ||
1042e4c0 SS |
216 | static void tracepoints_info (char *, int); |
217 | ||
218 | static void delete_trace_command (char *, int); | |
219 | ||
220 | static void enable_trace_command (char *, int); | |
221 | ||
222 | static void disable_trace_command (char *, int); | |
223 | ||
224 | static void trace_pass_command (char *, int); | |
225 | ||
3daf8fe5 JG |
226 | static void skip_prologue_sal (struct symtab_and_line *sal); |
227 | ||
228 | ||
f3b1572e PA |
229 | /* Flag indicating that a command has proceeded the inferior past the |
230 | current breakpoint. */ | |
231 | ||
232 | static int breakpoint_proceeded; | |
233 | ||
2cec12e5 AR |
234 | static const char * |
235 | bpdisp_text (enum bpdisp disp) | |
236 | { | |
237 | /* NOTE: the following values are a part of MI protocol and represent | |
238 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
239 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
240 | return bpdisps[(int) disp]; | |
241 | } | |
c906108c | 242 | |
2cec12e5 | 243 | /* Prototypes for exported functions. */ |
c906108c SS |
244 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
245 | if such is available. */ | |
246 | static int can_use_hw_watchpoints; | |
247 | ||
920d2a44 AC |
248 | static void |
249 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
250 | struct cmd_list_element *c, | |
251 | const char *value) | |
252 | { | |
253 | fprintf_filtered (file, _("\ | |
254 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
255 | value); | |
256 | } | |
257 | ||
fa8d40ab JJ |
258 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
259 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
260 | for unrecognized breakpoint locations. | |
261 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
262 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
263 | static void |
264 | show_pending_break_support (struct ui_file *file, int from_tty, | |
265 | struct cmd_list_element *c, | |
266 | const char *value) | |
267 | { | |
268 | fprintf_filtered (file, _("\ | |
269 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
270 | value); | |
271 | } | |
fa8d40ab | 272 | |
765dc015 VP |
273 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
274 | set with "break" but falling in read-only memory. | |
275 | If 0, gdb will warn about such breakpoints, but won't automatically | |
276 | use hardware breakpoints. */ | |
277 | static int automatic_hardware_breakpoints; | |
278 | static void | |
279 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
280 | struct cmd_list_element *c, | |
281 | const char *value) | |
282 | { | |
283 | fprintf_filtered (file, _("\ | |
284 | Automatic usage of hardware breakpoints is %s.\n"), | |
285 | value); | |
286 | } | |
287 | ||
33e5cbd6 PA |
288 | /* If on, gdb will keep breakpoints inserted even as inferior is |
289 | stopped, and immediately insert any new breakpoints. If off, gdb | |
290 | will insert breakpoints into inferior only when resuming it, and | |
291 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
292 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
293 | ||
294 | static const char always_inserted_auto[] = "auto"; | |
295 | static const char always_inserted_on[] = "on"; | |
296 | static const char always_inserted_off[] = "off"; | |
297 | static const char *always_inserted_enums[] = { | |
298 | always_inserted_auto, | |
299 | always_inserted_off, | |
300 | always_inserted_on, | |
301 | NULL | |
302 | }; | |
303 | static const char *always_inserted_mode = always_inserted_auto; | |
304 | static void | |
74960c60 | 305 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 306 | struct cmd_list_element *c, const char *value) |
74960c60 | 307 | { |
33e5cbd6 PA |
308 | if (always_inserted_mode == always_inserted_auto) |
309 | fprintf_filtered (file, _("\ | |
310 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
311 | value, | |
312 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
313 | else | |
314 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
315 | } |
316 | ||
33e5cbd6 PA |
317 | int |
318 | breakpoints_always_inserted_mode (void) | |
319 | { | |
320 | return (always_inserted_mode == always_inserted_on | |
321 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
322 | } | |
765dc015 | 323 | |
a14ed312 | 324 | void _initialize_breakpoint (void); |
c906108c | 325 | |
c906108c SS |
326 | /* Are we executing breakpoint commands? */ |
327 | static int executing_breakpoint_commands; | |
328 | ||
c02f5703 MS |
329 | /* Are overlay event breakpoints enabled? */ |
330 | static int overlay_events_enabled; | |
331 | ||
c906108c SS |
332 | /* Walk the following statement or block through all breakpoints. |
333 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
334 | breakpoint. */ | |
335 | ||
5c44784c | 336 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 337 | |
5c44784c JM |
338 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
339 | for (B = breakpoint_chain; \ | |
340 | B ? (TMP=B->next, 1): 0; \ | |
341 | B = TMP) | |
c906108c | 342 | |
876fa593 JK |
343 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
344 | provided so update_global_location_list must not be called while executing | |
345 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 346 | |
876fa593 JK |
347 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
348 | for (BP_TMP = bp_location; \ | |
349 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
350 | BP_TMP++) | |
7cc221ef | 351 | |
1042e4c0 SS |
352 | /* Iterator for tracepoints only. */ |
353 | ||
354 | #define ALL_TRACEPOINTS(B) \ | |
355 | for (B = breakpoint_chain; B; B = B->next) \ | |
356 | if ((B)->type == bp_tracepoint) | |
357 | ||
7cc221ef | 358 | /* Chains of all breakpoints defined. */ |
c906108c SS |
359 | |
360 | struct breakpoint *breakpoint_chain; | |
361 | ||
876fa593 JK |
362 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
363 | ||
364 | static struct bp_location **bp_location; | |
365 | ||
366 | /* Number of elements of BP_LOCATION. */ | |
367 | ||
368 | static unsigned bp_location_count; | |
369 | ||
370 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
371 | for the current elements of BP_LOCATION which get a valid result from | |
372 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
373 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
374 | ||
375 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
376 | ||
377 | /* Maximum offset plus alignment between | |
378 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
379 | the current elements of BP_LOCATION which get a valid result from | |
380 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
381 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
382 | ||
383 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 384 | |
20874c92 | 385 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 386 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
387 | may still be reported by a target. */ |
388 | VEC(bp_location_p) *moribund_locations = NULL; | |
389 | ||
c906108c SS |
390 | /* Number of last breakpoint made. */ |
391 | ||
392 | int breakpoint_count; | |
393 | ||
1042e4c0 SS |
394 | /* Number of last tracepoint made. */ |
395 | ||
396 | int tracepoint_count; | |
397 | ||
468d015d JJ |
398 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
399 | static int | |
400 | breakpoint_enabled (struct breakpoint *b) | |
401 | { | |
0d381245 | 402 | return (b->enable_state == bp_enabled); |
468d015d JJ |
403 | } |
404 | ||
c906108c SS |
405 | /* Set breakpoint count to NUM. */ |
406 | ||
407 | void | |
fba45db2 | 408 | set_breakpoint_count (int num) |
c906108c SS |
409 | { |
410 | breakpoint_count = num; | |
4fa62494 | 411 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
412 | } |
413 | ||
414 | /* Used in run_command to zero the hit count when a new run starts. */ | |
415 | ||
416 | void | |
fba45db2 | 417 | clear_breakpoint_hit_counts (void) |
c906108c SS |
418 | { |
419 | struct breakpoint *b; | |
420 | ||
421 | ALL_BREAKPOINTS (b) | |
422 | b->hit_count = 0; | |
423 | } | |
424 | ||
425 | /* Default address, symtab and line to put a breakpoint at | |
426 | for "break" command with no arg. | |
427 | if default_breakpoint_valid is zero, the other three are | |
428 | not valid, and "break" with no arg is an error. | |
429 | ||
430 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
431 | ||
432 | int default_breakpoint_valid; | |
433 | CORE_ADDR default_breakpoint_address; | |
434 | struct symtab *default_breakpoint_symtab; | |
435 | int default_breakpoint_line; | |
6c95b8df PA |
436 | struct program_space *default_breakpoint_pspace; |
437 | ||
c906108c SS |
438 | \f |
439 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
440 | Advance *PP after the string and any trailing whitespace. | |
441 | ||
442 | Currently the string can either be a number or "$" followed by the name | |
443 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 444 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
445 | |
446 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
447 | |
448 | TRAILER is a character which can be found after the number; most | |
449 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 450 | static int |
fba45db2 | 451 | get_number_trailer (char **pp, int trailer) |
c906108c | 452 | { |
5c44784c | 453 | int retval = 0; /* default */ |
c906108c SS |
454 | char *p = *pp; |
455 | ||
456 | if (p == NULL) | |
457 | /* Empty line means refer to the last breakpoint. */ | |
458 | return breakpoint_count; | |
459 | else if (*p == '$') | |
460 | { | |
461 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 462 | to pass to lookup_internalvar(). */ |
c906108c SS |
463 | char *varname; |
464 | char *start = ++p; | |
4fa62494 | 465 | LONGEST val; |
c906108c SS |
466 | |
467 | while (isalnum (*p) || *p == '_') | |
468 | p++; | |
469 | varname = (char *) alloca (p - start + 1); | |
470 | strncpy (varname, start, p - start); | |
471 | varname[p - start] = '\0'; | |
4fa62494 UW |
472 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
473 | retval = (int) val; | |
5c44784c JM |
474 | else |
475 | { | |
a3f17187 | 476 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
477 | retval = 0; |
478 | } | |
c906108c SS |
479 | } |
480 | else | |
481 | { | |
482 | if (*p == '-') | |
483 | ++p; | |
484 | while (*p >= '0' && *p <= '9') | |
485 | ++p; | |
486 | if (p == *pp) | |
487 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
488 | { |
489 | /* Skip non-numeric token */ | |
490 | while (*p && !isspace((int) *p)) | |
491 | ++p; | |
492 | /* Return zero, which caller must interpret as error. */ | |
493 | retval = 0; | |
494 | } | |
495 | else | |
496 | retval = atoi (*pp); | |
497 | } | |
498 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
499 | { | |
500 | /* Trailing junk: return 0 and let caller print error msg. */ | |
501 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
502 | ++p; | |
503 | retval = 0; | |
c906108c | 504 | } |
c906108c SS |
505 | while (isspace (*p)) |
506 | p++; | |
507 | *pp = p; | |
508 | return retval; | |
509 | } | |
5c44784c | 510 | |
11cf8741 | 511 | |
5c44784c JM |
512 | /* Like get_number_trailer, but don't allow a trailer. */ |
513 | int | |
fba45db2 | 514 | get_number (char **pp) |
5c44784c JM |
515 | { |
516 | return get_number_trailer (pp, '\0'); | |
517 | } | |
518 | ||
519 | /* Parse a number or a range. | |
520 | * A number will be of the form handled by get_number. | |
521 | * A range will be of the form <number1> - <number2>, and | |
522 | * will represent all the integers between number1 and number2, | |
523 | * inclusive. | |
524 | * | |
525 | * While processing a range, this fuction is called iteratively; | |
526 | * At each call it will return the next value in the range. | |
527 | * | |
528 | * At the beginning of parsing a range, the char pointer PP will | |
529 | * be advanced past <number1> and left pointing at the '-' token. | |
530 | * Subsequent calls will not advance the pointer until the range | |
531 | * is completed. The call that completes the range will advance | |
532 | * pointer PP past <number2>. | |
533 | */ | |
534 | ||
535 | int | |
fba45db2 | 536 | get_number_or_range (char **pp) |
5c44784c JM |
537 | { |
538 | static int last_retval, end_value; | |
539 | static char *end_ptr; | |
540 | static int in_range = 0; | |
541 | ||
542 | if (**pp != '-') | |
543 | { | |
544 | /* Default case: pp is pointing either to a solo number, | |
545 | or to the first number of a range. */ | |
546 | last_retval = get_number_trailer (pp, '-'); | |
547 | if (**pp == '-') | |
548 | { | |
549 | char **temp; | |
550 | ||
551 | /* This is the start of a range (<number1> - <number2>). | |
552 | Skip the '-', parse and remember the second number, | |
553 | and also remember the end of the final token. */ | |
554 | ||
555 | temp = &end_ptr; | |
556 | end_ptr = *pp + 1; | |
557 | while (isspace ((int) *end_ptr)) | |
558 | end_ptr++; /* skip white space */ | |
559 | end_value = get_number (temp); | |
560 | if (end_value < last_retval) | |
561 | { | |
8a3fe4f8 | 562 | error (_("inverted range")); |
5c44784c JM |
563 | } |
564 | else if (end_value == last_retval) | |
565 | { | |
566 | /* degenerate range (number1 == number2). Advance the | |
567 | token pointer so that the range will be treated as a | |
568 | single number. */ | |
569 | *pp = end_ptr; | |
570 | } | |
571 | else | |
572 | in_range = 1; | |
573 | } | |
574 | } | |
575 | else if (! in_range) | |
8a3fe4f8 | 576 | error (_("negative value")); |
5c44784c JM |
577 | else |
578 | { | |
579 | /* pp points to the '-' that betokens a range. All | |
580 | number-parsing has already been done. Return the next | |
581 | integer value (one greater than the saved previous value). | |
582 | Do not advance the token pointer 'pp' until the end of range | |
583 | is reached. */ | |
584 | ||
585 | if (++last_retval == end_value) | |
586 | { | |
587 | /* End of range reached; advance token pointer. */ | |
588 | *pp = end_ptr; | |
589 | in_range = 0; | |
590 | } | |
591 | } | |
592 | return last_retval; | |
593 | } | |
594 | ||
48cb2d85 VP |
595 | /* Return the breakpoint with the specified number, or NULL |
596 | if the number does not refer to an existing breakpoint. */ | |
597 | ||
598 | struct breakpoint * | |
599 | get_breakpoint (int num) | |
600 | { | |
601 | struct breakpoint *b; | |
602 | ||
603 | ALL_BREAKPOINTS (b) | |
604 | if (b->number == num) | |
605 | return b; | |
606 | ||
607 | return NULL; | |
608 | } | |
5c44784c | 609 | |
c906108c SS |
610 | \f |
611 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
612 | ||
613 | static void | |
fba45db2 | 614 | condition_command (char *arg, int from_tty) |
c906108c | 615 | { |
52f0bd74 | 616 | struct breakpoint *b; |
c906108c | 617 | char *p; |
52f0bd74 | 618 | int bnum; |
c906108c SS |
619 | |
620 | if (arg == 0) | |
e2e0b3e5 | 621 | error_no_arg (_("breakpoint number")); |
c906108c SS |
622 | |
623 | p = arg; | |
624 | bnum = get_number (&p); | |
5c44784c | 625 | if (bnum == 0) |
8a3fe4f8 | 626 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
627 | |
628 | ALL_BREAKPOINTS (b) | |
629 | if (b->number == bnum) | |
2f069f6f JB |
630 | { |
631 | struct bp_location *loc = b->loc; | |
632 | for (; loc; loc = loc->next) | |
633 | { | |
634 | if (loc->cond) | |
635 | { | |
636 | xfree (loc->cond); | |
637 | loc->cond = 0; | |
638 | } | |
639 | } | |
640 | if (b->cond_string != NULL) | |
641 | xfree (b->cond_string); | |
c906108c | 642 | |
2f069f6f JB |
643 | if (*p == 0) |
644 | { | |
645 | b->cond_string = NULL; | |
646 | if (from_tty) | |
647 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
648 | } | |
649 | else | |
650 | { | |
651 | arg = p; | |
652 | /* I don't know if it matters whether this is the string the user | |
653 | typed in or the decompiled expression. */ | |
1b36a34b | 654 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
655 | b->condition_not_parsed = 0; |
656 | for (loc = b->loc; loc; loc = loc->next) | |
657 | { | |
658 | arg = p; | |
659 | loc->cond = | |
660 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
661 | if (*arg) | |
662 | error (_("Junk at end of expression")); | |
663 | } | |
664 | } | |
665 | breakpoints_changed (); | |
383f836e | 666 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
667 | return; |
668 | } | |
c906108c | 669 | |
8a3fe4f8 | 670 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
671 | } |
672 | ||
48cb2d85 VP |
673 | /* Set the command list of B to COMMANDS. */ |
674 | ||
675 | void | |
676 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
677 | { | |
678 | free_command_lines (&b->commands); | |
679 | b->commands = commands; | |
680 | breakpoints_changed (); | |
681 | observer_notify_breakpoint_modified (b->number); | |
682 | } | |
683 | ||
c906108c | 684 | static void |
fba45db2 | 685 | commands_command (char *arg, int from_tty) |
c906108c | 686 | { |
52f0bd74 | 687 | struct breakpoint *b; |
c906108c | 688 | char *p; |
52f0bd74 | 689 | int bnum; |
c906108c SS |
690 | struct command_line *l; |
691 | ||
692 | /* If we allowed this, we would have problems with when to | |
693 | free the storage, if we change the commands currently | |
694 | being read from. */ | |
695 | ||
696 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 697 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
698 | |
699 | p = arg; | |
700 | bnum = get_number (&p); | |
5c44784c | 701 | |
c906108c | 702 | if (p && *p) |
8a3fe4f8 | 703 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 704 | |
c906108c SS |
705 | ALL_BREAKPOINTS (b) |
706 | if (b->number == bnum) | |
9ebf4acf AC |
707 | { |
708 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
709 | bnum); | |
710 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 711 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf | 712 | do_cleanups (cleanups); |
48cb2d85 | 713 | breakpoint_set_commands (b, l); |
9ebf4acf | 714 | return; |
c5aa993b | 715 | } |
8a3fe4f8 | 716 | error (_("No breakpoint number %d."), bnum); |
c906108c | 717 | } |
40c03ae8 EZ |
718 | |
719 | /* Like commands_command, but instead of reading the commands from | |
720 | input stream, takes them from an already parsed command structure. | |
721 | ||
722 | This is used by cli-script.c to DTRT with breakpoint commands | |
723 | that are part of if and while bodies. */ | |
724 | enum command_control_type | |
725 | commands_from_control_command (char *arg, struct command_line *cmd) | |
726 | { | |
727 | struct breakpoint *b; | |
728 | char *p; | |
729 | int bnum; | |
730 | ||
731 | /* If we allowed this, we would have problems with when to | |
732 | free the storage, if we change the commands currently | |
733 | being read from. */ | |
734 | ||
735 | if (executing_breakpoint_commands) | |
736 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
737 | ||
738 | /* An empty string for the breakpoint number means the last | |
739 | breakpoint, but get_number expects a NULL pointer. */ | |
740 | if (arg && !*arg) | |
741 | p = NULL; | |
742 | else | |
743 | p = arg; | |
744 | bnum = get_number (&p); | |
745 | ||
746 | if (p && *p) | |
747 | error (_("Unexpected extra arguments following breakpoint number.")); | |
748 | ||
749 | ALL_BREAKPOINTS (b) | |
750 | if (b->number == bnum) | |
751 | { | |
752 | free_command_lines (&b->commands); | |
753 | if (cmd->body_count != 1) | |
754 | error (_("Invalid \"commands\" block structure.")); | |
755 | /* We need to copy the commands because if/while will free the | |
756 | list after it finishes execution. */ | |
757 | b->commands = copy_command_lines (cmd->body_list[0]); | |
758 | breakpoints_changed (); | |
383f836e | 759 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 760 | return simple_control; |
2f069f6f | 761 | } |
40c03ae8 EZ |
762 | error (_("No breakpoint number %d."), bnum); |
763 | } | |
876fa593 JK |
764 | |
765 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
766 | ||
767 | static int | |
768 | bp_location_has_shadow (struct bp_location *bl) | |
769 | { | |
770 | if (bl->loc_type != bp_loc_software_breakpoint) | |
771 | return 0; | |
772 | if (!bl->inserted) | |
773 | return 0; | |
774 | if (bl->target_info.shadow_len == 0) | |
775 | /* bp isn't valid, or doesn't shadow memory. */ | |
776 | return 0; | |
777 | return 1; | |
778 | } | |
779 | ||
8defab1a | 780 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
781 | by replacing any memory breakpoints with their shadowed contents. |
782 | ||
783 | The range of shadowed area by each bp_location is: | |
784 | b->address - bp_location_placed_address_before_address_max | |
785 | up to b->address + bp_location_shadow_len_after_address_max | |
786 | The range we were requested to resolve shadows for is: | |
787 | memaddr ... memaddr + len | |
788 | Thus the safe cutoff boundaries for performance optimization are | |
789 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
790 | and: | |
791 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 792 | |
8defab1a DJ |
793 | void |
794 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 795 | { |
876fa593 JK |
796 | /* Left boundary, right boundary and median element of our binary search. */ |
797 | unsigned bc_l, bc_r, bc; | |
798 | ||
799 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
800 | safe to report lower value but a failure to report higher one. */ | |
801 | ||
802 | bc_l = 0; | |
803 | bc_r = bp_location_count; | |
804 | while (bc_l + 1 < bc_r) | |
805 | { | |
806 | struct bp_location *b; | |
807 | ||
808 | bc = (bc_l + bc_r) / 2; | |
809 | b = bp_location[bc]; | |
810 | ||
811 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
812 | Then advance the left boundary only if we are sure the BC element can | |
813 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
814 | ||
815 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
816 | we cannot miss a breakpoint with its shadow range tail still reaching | |
817 | MEMADDR. */ | |
c5aa993b | 818 | |
876fa593 JK |
819 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
820 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
821 | bc_l = bc; | |
822 | else | |
823 | bc_r = bc; | |
824 | } | |
825 | ||
826 | /* Now do full processing of the found relevant range of elements. */ | |
827 | ||
828 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 829 | { |
876fa593 JK |
830 | struct bp_location *b = bp_location[bc]; |
831 | CORE_ADDR bp_addr = 0; | |
832 | int bp_size = 0; | |
833 | int bptoffset = 0; | |
834 | ||
ffce0d52 | 835 | if (b->owner->type == bp_none) |
8a3fe4f8 | 836 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
837 | b->owner->number); |
838 | ||
876fa593 JK |
839 | /* Performance optimization: any futher element can no longer affect BUF |
840 | content. */ | |
841 | ||
842 | if (b->address >= bp_location_placed_address_before_address_max | |
843 | && memaddr + len <= b->address | |
844 | - bp_location_placed_address_before_address_max) | |
845 | break; | |
846 | ||
847 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 848 | continue; |
6c95b8df PA |
849 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
850 | current_program_space->aspace, 0)) | |
851 | continue; | |
852 | ||
c5aa993b JM |
853 | /* Addresses and length of the part of the breakpoint that |
854 | we need to copy. */ | |
8181d85f DJ |
855 | bp_addr = b->target_info.placed_address; |
856 | bp_size = b->target_info.shadow_len; | |
8defab1a | 857 | |
c5aa993b JM |
858 | if (bp_addr + bp_size <= memaddr) |
859 | /* The breakpoint is entirely before the chunk of memory we | |
860 | are reading. */ | |
861 | continue; | |
8defab1a | 862 | |
c5aa993b JM |
863 | if (bp_addr >= memaddr + len) |
864 | /* The breakpoint is entirely after the chunk of memory we are | |
865 | reading. */ | |
866 | continue; | |
c5aa993b | 867 | |
8defab1a DJ |
868 | /* Offset within shadow_contents. */ |
869 | if (bp_addr < memaddr) | |
870 | { | |
871 | /* Only copy the second part of the breakpoint. */ | |
872 | bp_size -= memaddr - bp_addr; | |
873 | bptoffset = memaddr - bp_addr; | |
874 | bp_addr = memaddr; | |
875 | } | |
c5aa993b | 876 | |
8defab1a DJ |
877 | if (bp_addr + bp_size > memaddr + len) |
878 | { | |
879 | /* Only copy the first part of the breakpoint. */ | |
880 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
881 | } | |
c5aa993b | 882 | |
8defab1a DJ |
883 | memcpy (buf + bp_addr - memaddr, |
884 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 885 | } |
c906108c | 886 | } |
c906108c | 887 | \f |
c5aa993b | 888 | |
687595f9 | 889 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 890 | static void |
687595f9 DJ |
891 | insert_catchpoint (struct ui_out *uo, void *args) |
892 | { | |
893 | struct breakpoint *b = (struct breakpoint *) args; | |
894 | int val = -1; | |
895 | ||
fe798b75 JB |
896 | gdb_assert (b->type == bp_catchpoint); |
897 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
898 | ||
899 | b->ops->insert (b); | |
687595f9 DJ |
900 | } |
901 | ||
a5606eee VP |
902 | static int |
903 | is_hardware_watchpoint (struct breakpoint *bpt) | |
904 | { | |
905 | return (bpt->type == bp_hardware_watchpoint | |
906 | || bpt->type == bp_read_watchpoint | |
907 | || bpt->type == bp_access_watchpoint); | |
908 | } | |
7270d8f2 | 909 | |
fa4727a6 DJ |
910 | /* Find the current value of a watchpoint on EXP. Return the value in |
911 | *VALP and *RESULTP and the chain of intermediate and final values | |
912 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
913 | not need them. | |
914 | ||
ccc57cf9 | 915 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
916 | be set to NULL. *RESULTP may be a lazy value, if the result could |
917 | not be read from memory. It is used to determine whether a value | |
918 | is user-specified (we should watch the whole value) or intermediate | |
919 | (we should watch only the bit used to locate the final value). | |
920 | ||
921 | If the final value, or any intermediate value, could not be read | |
922 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
923 | set to any referenced values. *VALP will never be a lazy value. | |
924 | This is the value which we store in struct breakpoint. | |
925 | ||
926 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
927 | value chain. The caller must free the values individually. If | |
928 | VAL_CHAIN is NULL, all generated values will be left on the value | |
929 | chain. */ | |
930 | ||
931 | static void | |
932 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
933 | struct value **resultp, struct value **val_chain) | |
934 | { | |
935 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 936 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
937 | |
938 | *valp = NULL; | |
939 | if (resultp) | |
940 | *resultp = NULL; | |
941 | if (val_chain) | |
942 | *val_chain = NULL; | |
943 | ||
944 | /* Evaluate the expression. */ | |
945 | mark = value_mark (); | |
946 | result = NULL; | |
ccc57cf9 PA |
947 | |
948 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
949 | { | |
950 | result = evaluate_expression (exp); | |
951 | } | |
952 | if (ex.reason < 0) | |
953 | { | |
954 | /* Ignore memory errors, we want watchpoints pointing at | |
955 | inaccessible memory to still be created; otherwise, throw the | |
956 | error to some higher catcher. */ | |
957 | switch (ex.error) | |
958 | { | |
959 | case MEMORY_ERROR: | |
960 | break; | |
961 | default: | |
962 | throw_exception (ex); | |
963 | break; | |
964 | } | |
965 | } | |
966 | ||
fa4727a6 DJ |
967 | new_mark = value_mark (); |
968 | if (mark == new_mark) | |
969 | return; | |
970 | if (resultp) | |
971 | *resultp = result; | |
972 | ||
973 | /* Make sure it's not lazy, so that after the target stops again we | |
974 | have a non-lazy previous value to compare with. */ | |
975 | if (result != NULL | |
976 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
977 | *valp = result; | |
978 | ||
979 | if (val_chain) | |
980 | { | |
981 | /* Return the chain of intermediate values. We use this to | |
982 | decide which addresses to watch. */ | |
983 | *val_chain = new_mark; | |
984 | value_release_to_mark (mark); | |
985 | } | |
986 | } | |
987 | ||
f6bc2008 PA |
988 | /* Assuming that B is a watchpoint: returns true if the current thread |
989 | and its running state are safe to evaluate or update watchpoint B. | |
990 | Watchpoints on local expressions need to be evaluated in the | |
991 | context of the thread that was current when the watchpoint was | |
992 | created, and, that thread needs to be stopped to be able to select | |
993 | the correct frame context. Watchpoints on global expressions can | |
994 | be evaluated on any thread, and in any state. It is presently left | |
995 | to the target allowing memory accesses when threads are | |
996 | running. */ | |
997 | ||
998 | static int | |
999 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1000 | { | |
1001 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1002 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1003 | && !is_executing (inferior_ptid))); | |
1004 | } | |
1005 | ||
567e1b4e JB |
1006 | /* Assuming that B is a watchpoint: |
1007 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1008 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1009 | - Evaluate the condition if there is one, and store the result |
1010 | in b->loc->cond. | |
a5606eee VP |
1011 | - Update the list of values that must be watched in B->loc. |
1012 | ||
bfa149ac | 1013 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1014 | If this is local watchpoint that is out of scope, delete it. |
1015 | ||
1016 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1017 | + inserted on each stop here. Normal breakpoints must never be removed | |
1018 | because they might be missed by a running thread when debugging in non-stop | |
1019 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1020 | processed here) are specific to each LWP since they are stored in each LWP's | |
1021 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1022 | order to be able to modify its hardware watchpoints. | |
1023 | ||
1024 | Hardware watchpoints must be reset exactly once after being presented to the | |
1025 | user. It cannot be done sooner, because it would reset the data used to | |
1026 | present the watchpoint hit to the user. And it must not be done later | |
1027 | because it could display the same single watchpoint hit during multiple GDB | |
1028 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1029 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1030 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1031 | memory content has not changed. | |
1032 | ||
1033 | The following constraints influence the location where we can reset hardware | |
1034 | watchpoints: | |
1035 | ||
1036 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1037 | several times when GDB stops. | |
1038 | ||
1039 | [linux] | |
1040 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1041 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1042 | reason for stopping, and all the other hits are presented later, one after | |
1043 | the other, each time the user requests the execution to be resumed. | |
1044 | Execution is not resumed for the threads still having pending hit event | |
1045 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1046 | the inferior on the first stop the thread hit event is kept being reported | |
1047 | from its cached value by linux_nat_stopped_data_address until the real | |
1048 | thread resume happens after the watchpoint gets presented and thus its | |
1049 | LWP_INFO->STATUS gets reset. | |
1050 | ||
1051 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1052 | removal from inferior. */ | |
1053 | ||
b40ce68a | 1054 | static void |
a5606eee | 1055 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1056 | { |
a5606eee | 1057 | int within_current_scope; |
a5606eee VP |
1058 | struct frame_id saved_frame_id; |
1059 | struct bp_location *loc; | |
66076460 | 1060 | int frame_saved; |
a5606eee VP |
1061 | bpstat bs; |
1062 | ||
f6bc2008 PA |
1063 | /* If this is a local watchpoint, we only want to check if the |
1064 | watchpoint frame is in scope if the current thread is the thread | |
1065 | that was used to create the watchpoint. */ | |
1066 | if (!watchpoint_in_thread_scope (b)) | |
1067 | return; | |
1068 | ||
876fa593 | 1069 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1070 | update_global_locations will eventually delete them and remove |
1071 | breakpoints if needed. */ | |
a5606eee VP |
1072 | b->loc = NULL; |
1073 | ||
1074 | if (b->disposition == disp_del_at_next_stop) | |
1075 | return; | |
1076 | ||
66076460 | 1077 | frame_saved = 0; |
a5606eee VP |
1078 | |
1079 | /* Determine if the watchpoint is within scope. */ | |
1080 | if (b->exp_valid_block == NULL) | |
1081 | within_current_scope = 1; | |
1082 | else | |
1083 | { | |
1084 | struct frame_info *fi; | |
66076460 DJ |
1085 | |
1086 | /* Save the current frame's ID so we can restore it after | |
1087 | evaluating the watchpoint expression on its own frame. */ | |
1088 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1089 | took a frame parameter, so that we didn't have to change the | |
1090 | selected frame. */ | |
1091 | frame_saved = 1; | |
1092 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1093 | ||
a5606eee VP |
1094 | fi = frame_find_by_id (b->watchpoint_frame); |
1095 | within_current_scope = (fi != NULL); | |
1096 | if (within_current_scope) | |
1097 | select_frame (fi); | |
1098 | } | |
1099 | ||
1100 | if (within_current_scope && reparse) | |
1101 | { | |
1102 | char *s; | |
1103 | if (b->exp) | |
1104 | { | |
1105 | xfree (b->exp); | |
1106 | b->exp = NULL; | |
1107 | } | |
1108 | s = b->exp_string; | |
1109 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1110 | /* If the meaning of expression itself changed, the old value is | |
1111 | no longer relevant. We don't want to report a watchpoint hit | |
1112 | to the user when the old value and the new value may actually | |
1113 | be completely different objects. */ | |
1114 | value_free (b->val); | |
fa4727a6 DJ |
1115 | b->val = NULL; |
1116 | b->val_valid = 0; | |
a5606eee | 1117 | } |
a5606eee VP |
1118 | |
1119 | /* If we failed to parse the expression, for example because | |
1120 | it refers to a global variable in a not-yet-loaded shared library, | |
1121 | don't try to insert watchpoint. We don't automatically delete | |
1122 | such watchpoint, though, since failure to parse expression | |
1123 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1124 | if ( !target_has_execution) |
1125 | { | |
1126 | /* Without execution, memory can't change. No use to try and | |
1127 | set watchpoint locations. The watchpoint will be reset when | |
1128 | the target gains execution, through breakpoint_re_set. */ | |
1129 | } | |
1130 | else if (within_current_scope && b->exp) | |
a5606eee | 1131 | { |
fa4727a6 | 1132 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1133 | struct program_space *frame_pspace; |
a5606eee | 1134 | |
fa4727a6 | 1135 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1136 | |
a5606eee VP |
1137 | /* Avoid setting b->val if it's already set. The meaning of |
1138 | b->val is 'the last value' user saw, and we should update | |
1139 | it only if we reported that last value to user. As it | |
1140 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1141 | if (!b->val_valid) |
1142 | { | |
1143 | b->val = v; | |
1144 | b->val_valid = 1; | |
1145 | } | |
a5606eee | 1146 | |
db2ad4c3 JK |
1147 | /* Change the type of breakpoint between hardware assisted or an |
1148 | ordinary watchpoint depending on the hardware support and free | |
1149 | hardware slots. REPARSE is set when the inferior is started. */ | |
1150 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1151 | && reparse) | |
1152 | { | |
ca2d49e8 | 1153 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
1154 | |
1155 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
1156 | &other_type_used); | |
1157 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1158 | ||
ca2d49e8 | 1159 | if (!mem_cnt) |
db2ad4c3 JK |
1160 | b->type = bp_watchpoint; |
1161 | else | |
ca2d49e8 | 1162 | { |
d92524f1 | 1163 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1164 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1165 | if (target_resources_ok <= 0) | |
1166 | b->type = bp_watchpoint; | |
1167 | else | |
1168 | b->type = bp_hardware_watchpoint; | |
1169 | } | |
db2ad4c3 JK |
1170 | } |
1171 | ||
2d134ed3 PA |
1172 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1173 | ||
a5606eee | 1174 | /* Look at each value on the value chain. */ |
fa4727a6 | 1175 | for (v = val_chain; v; v = next) |
a5606eee VP |
1176 | { |
1177 | /* If it's a memory location, and GDB actually needed | |
1178 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1179 | must watch it. If the first value returned is |
1180 | still lazy, that means an error occurred reading it; | |
1181 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1182 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1183 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1184 | { |
1185 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1186 | |
a5606eee VP |
1187 | /* We only watch structs and arrays if user asked |
1188 | for it explicitly, never if they just happen to | |
1189 | appear in the middle of some value chain. */ | |
fa4727a6 | 1190 | if (v == result |
a5606eee VP |
1191 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1192 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1193 | { | |
1194 | CORE_ADDR addr; | |
1195 | int len, type; | |
1196 | struct bp_location *loc, **tmp; | |
1197 | ||
42ae5230 | 1198 | addr = value_address (v); |
a5606eee VP |
1199 | len = TYPE_LENGTH (value_type (v)); |
1200 | type = hw_write; | |
1201 | if (b->type == bp_read_watchpoint) | |
1202 | type = hw_read; | |
1203 | else if (b->type == bp_access_watchpoint) | |
1204 | type = hw_access; | |
1205 | ||
39d61571 | 1206 | loc = allocate_bp_location (b); |
a5606eee VP |
1207 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1208 | ; | |
1209 | *tmp = loc; | |
a6d9a66e | 1210 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1211 | |
1212 | loc->pspace = frame_pspace; | |
a5606eee VP |
1213 | loc->address = addr; |
1214 | loc->length = len; | |
1215 | loc->watchpoint_type = type; | |
1216 | } | |
1217 | } | |
1218 | ||
1219 | next = value_next (v); | |
1220 | if (v != b->val) | |
1221 | value_free (v); | |
1222 | } | |
1223 | ||
2ec93238 MK |
1224 | /* We just regenerated the list of breakpoint locations. |
1225 | The new location does not have its condition field set to anything | |
1226 | and therefore, we must always reparse the cond_string, independently | |
1227 | of the value of the reparse flag. */ | |
1228 | if (b->cond_string != NULL) | |
a5606eee VP |
1229 | { |
1230 | char *s = b->cond_string; | |
a5606eee VP |
1231 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1232 | } | |
1233 | } | |
1234 | else if (!within_current_scope) | |
7270d8f2 | 1235 | { |
a5606eee | 1236 | printf_filtered (_("\ |
567e1b4e | 1237 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1238 | in which its expression is valid.\n"), |
1239 | b->number); | |
1240 | if (b->related_breakpoint) | |
1241 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1242 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1243 | } |
a5606eee VP |
1244 | |
1245 | /* Restore the selected frame. */ | |
66076460 DJ |
1246 | if (frame_saved) |
1247 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1248 | } |
1249 | ||
a5606eee | 1250 | |
74960c60 VP |
1251 | /* Returns 1 iff breakpoint location should be |
1252 | inserted in the inferior. */ | |
1253 | static int | |
1254 | should_be_inserted (struct bp_location *bpt) | |
1255 | { | |
1256 | if (!breakpoint_enabled (bpt->owner)) | |
1257 | return 0; | |
1258 | ||
1259 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1260 | return 0; | |
1261 | ||
1262 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1263 | return 0; | |
1264 | ||
56710373 PA |
1265 | /* This is set for example, when we're attached to the parent of a |
1266 | vfork, and have detached from the child. The child is running | |
1267 | free, and we expect it to do an exec or exit, at which point the | |
1268 | OS makes the parent schedulable again (and the target reports | |
1269 | that the vfork is done). Until the child is done with the shared | |
1270 | memory region, do not insert breakpoints in the parent, otherwise | |
1271 | the child could still trip on the parent's breakpoints. Since | |
1272 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1273 | if (bpt->pspace->breakpoints_not_allowed) | |
1274 | return 0; | |
1275 | ||
1042e4c0 SS |
1276 | /* Tracepoints are inserted by the target at a time of its choosing, |
1277 | not by us. */ | |
1278 | if (bpt->owner->type == bp_tracepoint) | |
1279 | return 0; | |
1280 | ||
74960c60 VP |
1281 | return 1; |
1282 | } | |
1283 | ||
879bfdc2 DJ |
1284 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1285 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1286 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1287 | |
1288 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1289 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1290 | static int |
879bfdc2 | 1291 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1292 | struct ui_file *tmp_error_stream, |
fa3a767f | 1293 | int *disabled_breaks, |
26bb91f3 | 1294 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1295 | { |
1296 | int val = 0; | |
1297 | ||
74960c60 | 1298 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1299 | return 0; |
1300 | ||
8181d85f DJ |
1301 | /* Initialize the target-specific information. */ |
1302 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1303 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1304 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1305 | |
879bfdc2 DJ |
1306 | if (bpt->loc_type == bp_loc_software_breakpoint |
1307 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1308 | { | |
765dc015 VP |
1309 | if (bpt->owner->type != bp_hardware_breakpoint) |
1310 | { | |
1311 | /* If the explicitly specified breakpoint type | |
1312 | is not hardware breakpoint, check the memory map to see | |
1313 | if the breakpoint address is in read only memory or not. | |
1314 | Two important cases are: | |
1315 | - location type is not hardware breakpoint, memory | |
1316 | is readonly. We change the type of the location to | |
1317 | hardware breakpoint. | |
1318 | - location type is hardware breakpoint, memory is read-write. | |
1319 | This means we've previously made the location hardware one, but | |
1320 | then the memory map changed, so we undo. | |
1321 | ||
1322 | When breakpoints are removed, remove_breakpoints will | |
1323 | use location types we've just set here, the only possible | |
1324 | problem is that memory map has changed during running program, | |
1325 | but it's not going to work anyway with current gdb. */ | |
1326 | struct mem_region *mr | |
1327 | = lookup_mem_region (bpt->target_info.placed_address); | |
1328 | ||
1329 | if (mr) | |
1330 | { | |
1331 | if (automatic_hardware_breakpoints) | |
1332 | { | |
1333 | int changed = 0; | |
1334 | enum bp_loc_type new_type; | |
1335 | ||
1336 | if (mr->attrib.mode != MEM_RW) | |
1337 | new_type = bp_loc_hardware_breakpoint; | |
1338 | else | |
1339 | new_type = bp_loc_software_breakpoint; | |
1340 | ||
1341 | if (new_type != bpt->loc_type) | |
1342 | { | |
1343 | static int said = 0; | |
1344 | bpt->loc_type = new_type; | |
1345 | if (!said) | |
1346 | { | |
1347 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1348 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1349 | said = 1; |
1350 | } | |
1351 | } | |
1352 | } | |
1353 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1354 | && mr->attrib.mode != MEM_RW) | |
1355 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1356 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1357 | } |
1358 | } | |
1359 | ||
879bfdc2 DJ |
1360 | /* First check to see if we have to handle an overlay. */ |
1361 | if (overlay_debugging == ovly_off | |
1362 | || bpt->section == NULL | |
1363 | || !(section_is_overlay (bpt->section))) | |
1364 | { | |
1365 | /* No overlay handling: just set the breakpoint. */ | |
1366 | ||
1367 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1368 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1369 | &bpt->target_info); | |
879bfdc2 | 1370 | else |
a6d9a66e UW |
1371 | val = target_insert_breakpoint (bpt->gdbarch, |
1372 | &bpt->target_info); | |
879bfdc2 DJ |
1373 | } |
1374 | else | |
1375 | { | |
1376 | /* This breakpoint is in an overlay section. | |
1377 | Shall we set a breakpoint at the LMA? */ | |
1378 | if (!overlay_events_enabled) | |
1379 | { | |
1380 | /* Yes -- overlay event support is not active, | |
1381 | so we must try to set a breakpoint at the LMA. | |
1382 | This will not work for a hardware breakpoint. */ | |
1383 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1384 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1385 | bpt->owner->number); |
1386 | else | |
1387 | { | |
1388 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1389 | bpt->section); | |
1390 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1391 | bpt->overlay_target_info = bpt->target_info; |
1392 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1393 | val = target_insert_breakpoint (bpt->gdbarch, |
1394 | &bpt->overlay_target_info); | |
879bfdc2 | 1395 | if (val != 0) |
99361f52 DE |
1396 | fprintf_unfiltered (tmp_error_stream, |
1397 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1398 | bpt->owner->number); |
1399 | } | |
1400 | } | |
1401 | /* Shall we set a breakpoint at the VMA? */ | |
1402 | if (section_is_mapped (bpt->section)) | |
1403 | { | |
1404 | /* Yes. This overlay section is mapped into memory. */ | |
1405 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1406 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1407 | &bpt->target_info); | |
879bfdc2 | 1408 | else |
a6d9a66e UW |
1409 | val = target_insert_breakpoint (bpt->gdbarch, |
1410 | &bpt->target_info); | |
879bfdc2 DJ |
1411 | } |
1412 | else | |
1413 | { | |
1414 | /* No. This breakpoint will not be inserted. | |
1415 | No error, but do not mark the bp as 'inserted'. */ | |
1416 | return 0; | |
1417 | } | |
1418 | } | |
1419 | ||
1420 | if (val) | |
1421 | { | |
1422 | /* Can't set the breakpoint. */ | |
6c95b8df | 1423 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1424 | { |
1425 | /* See also: disable_breakpoints_in_shlibs. */ | |
1426 | val = 0; | |
0d381245 | 1427 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1428 | if (!*disabled_breaks) |
1429 | { | |
1430 | fprintf_unfiltered (tmp_error_stream, | |
1431 | "Cannot insert breakpoint %d.\n", | |
1432 | bpt->owner->number); | |
1433 | fprintf_unfiltered (tmp_error_stream, | |
1434 | "Temporarily disabling shared library breakpoints:\n"); | |
1435 | } | |
1436 | *disabled_breaks = 1; | |
1437 | fprintf_unfiltered (tmp_error_stream, | |
1438 | "breakpoint #%d\n", bpt->owner->number); | |
1439 | } | |
1440 | else | |
879bfdc2 | 1441 | { |
879bfdc2 DJ |
1442 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1443 | { | |
1444 | *hw_breakpoint_error = 1; | |
1445 | fprintf_unfiltered (tmp_error_stream, | |
1446 | "Cannot insert hardware breakpoint %d.\n", | |
1447 | bpt->owner->number); | |
1448 | } | |
1449 | else | |
1450 | { | |
1451 | fprintf_unfiltered (tmp_error_stream, | |
1452 | "Cannot insert breakpoint %d.\n", | |
1453 | bpt->owner->number); | |
1454 | fprintf_filtered (tmp_error_stream, | |
1455 | "Error accessing memory address "); | |
5af949e3 UW |
1456 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1457 | tmp_error_stream); | |
879bfdc2 DJ |
1458 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1459 | safe_strerror (val)); | |
1460 | } | |
1461 | ||
1462 | } | |
1463 | } | |
1464 | else | |
1465 | bpt->inserted = 1; | |
1466 | ||
1467 | return val; | |
1468 | } | |
1469 | ||
1470 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1471 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1472 | watchpoints. It's not clear that it's necessary... */ | |
1473 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1474 | { | |
a5606eee VP |
1475 | val = target_insert_watchpoint (bpt->address, |
1476 | bpt->length, | |
1477 | bpt->watchpoint_type); | |
1478 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1479 | } |
1480 | ||
fe798b75 | 1481 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1482 | { |
71fff37b AC |
1483 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1484 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1485 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1486 | bpt->owner->number); | |
1487 | if (e.reason < 0) | |
879bfdc2 DJ |
1488 | bpt->owner->enable_state = bp_disabled; |
1489 | else | |
1490 | bpt->inserted = 1; | |
1640b821 DJ |
1491 | |
1492 | /* We've already printed an error message if there was a problem | |
1493 | inserting this catchpoint, and we've disabled the catchpoint, | |
1494 | so just return success. */ | |
1495 | return 0; | |
879bfdc2 DJ |
1496 | } |
1497 | ||
1498 | return 0; | |
1499 | } | |
1500 | ||
6c95b8df PA |
1501 | /* This function is called when program space PSPACE is about to be |
1502 | deleted. It takes care of updating breakpoints to not reference | |
1503 | PSPACE anymore. */ | |
1504 | ||
1505 | void | |
1506 | breakpoint_program_space_exit (struct program_space *pspace) | |
1507 | { | |
1508 | struct breakpoint *b, *b_temp; | |
876fa593 | 1509 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1510 | |
1511 | /* Remove any breakpoint that was set through this program space. */ | |
1512 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1513 | { | |
1514 | if (b->pspace == pspace) | |
1515 | delete_breakpoint (b); | |
1516 | } | |
1517 | ||
1518 | /* Breakpoints set through other program spaces could have locations | |
1519 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1520 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1521 | { |
1522 | struct bp_location *tmp; | |
1523 | ||
1524 | if (loc->pspace == pspace) | |
1525 | { | |
1526 | if (loc->owner->loc == loc) | |
1527 | loc->owner->loc = loc->next; | |
1528 | else | |
1529 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1530 | if (tmp->next == loc) | |
1531 | { | |
1532 | tmp->next = loc->next; | |
1533 | break; | |
1534 | } | |
1535 | } | |
1536 | } | |
1537 | ||
1538 | /* Now update the global location list to permanently delete the | |
1539 | removed locations above. */ | |
1540 | update_global_location_list (0); | |
1541 | } | |
1542 | ||
74960c60 VP |
1543 | /* Make sure all breakpoints are inserted in inferior. |
1544 | Throws exception on any error. | |
1545 | A breakpoint that is already inserted won't be inserted | |
1546 | again, so calling this function twice is safe. */ | |
1547 | void | |
1548 | insert_breakpoints (void) | |
1549 | { | |
1550 | struct breakpoint *bpt; | |
1551 | ||
1552 | ALL_BREAKPOINTS (bpt) | |
1553 | if (is_hardware_watchpoint (bpt)) | |
1554 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1555 | ||
b60e7edf | 1556 | update_global_location_list (1); |
74960c60 | 1557 | |
c35b1492 PA |
1558 | /* update_global_location_list does not insert breakpoints when |
1559 | always_inserted_mode is not enabled. Explicitly insert them | |
1560 | now. */ | |
1561 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1562 | insert_breakpoint_locations (); |
1563 | } | |
1564 | ||
c906108c SS |
1565 | /* insert_breakpoints is used when starting or continuing the program. |
1566 | remove_breakpoints is used when the program stops. | |
1567 | Both return zero if successful, | |
1568 | or an `errno' value if could not write the inferior. */ | |
1569 | ||
74960c60 VP |
1570 | static void |
1571 | insert_breakpoint_locations (void) | |
c906108c | 1572 | { |
a5606eee | 1573 | struct breakpoint *bpt; |
876fa593 | 1574 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1575 | int error = 0; |
c906108c SS |
1576 | int val = 0; |
1577 | int disabled_breaks = 0; | |
81d0cc19 | 1578 | int hw_breakpoint_error = 0; |
c906108c | 1579 | |
81d0cc19 | 1580 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1581 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1582 | |
81d0cc19 GS |
1583 | /* Explicitly mark the warning -- this will only be printed if |
1584 | there was an error. */ | |
1585 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1586 | |
1587 | save_current_space_and_thread (); | |
1588 | ||
876fa593 | 1589 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1590 | { |
6c95b8df PA |
1591 | struct thread_info *tp; |
1592 | CORE_ADDR last_addr; | |
1593 | ||
74960c60 | 1594 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1595 | continue; |
1596 | ||
f365de73 AS |
1597 | /* There is no point inserting thread-specific breakpoints if the |
1598 | thread no longer exists. */ | |
1599 | if (b->owner->thread != -1 | |
1600 | && !valid_thread_id (b->owner->thread)) | |
1601 | continue; | |
1602 | ||
6c95b8df PA |
1603 | switch_to_program_space_and_thread (b->pspace); |
1604 | ||
1605 | /* For targets that support global breakpoints, there's no need | |
1606 | to select an inferior to insert breakpoint to. In fact, even | |
1607 | if we aren't attached to any process yet, we should still | |
1608 | insert breakpoints. */ | |
1609 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1610 | && ptid_equal (inferior_ptid, null_ptid)) | |
1611 | continue; | |
1612 | ||
879bfdc2 | 1613 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1614 | &disabled_breaks, |
879bfdc2 DJ |
1615 | &hw_breakpoint_error); |
1616 | if (val) | |
e236ba44 | 1617 | error = val; |
879bfdc2 | 1618 | } |
c906108c | 1619 | |
a5606eee VP |
1620 | /* If we failed to insert all locations of a watchpoint, |
1621 | remove them, as half-inserted watchpoint is of limited use. */ | |
1622 | ALL_BREAKPOINTS (bpt) | |
1623 | { | |
1624 | int some_failed = 0; | |
1625 | struct bp_location *loc; | |
1626 | ||
1627 | if (!is_hardware_watchpoint (bpt)) | |
1628 | continue; | |
1629 | ||
d6b74ac4 | 1630 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1631 | continue; |
74960c60 VP |
1632 | |
1633 | if (bpt->disposition == disp_del_at_next_stop) | |
1634 | continue; | |
a5606eee VP |
1635 | |
1636 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1637 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1638 | { |
1639 | some_failed = 1; | |
1640 | break; | |
1641 | } | |
1642 | if (some_failed) | |
1643 | { | |
1644 | for (loc = bpt->loc; loc; loc = loc->next) | |
1645 | if (loc->inserted) | |
1646 | remove_breakpoint (loc, mark_uninserted); | |
1647 | ||
1648 | hw_breakpoint_error = 1; | |
1649 | fprintf_unfiltered (tmp_error_stream, | |
1650 | "Could not insert hardware watchpoint %d.\n", | |
1651 | bpt->number); | |
1652 | error = -1; | |
1653 | } | |
1654 | } | |
1655 | ||
e236ba44 | 1656 | if (error) |
81d0cc19 GS |
1657 | { |
1658 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1659 | message about possibly exhausted resources. */ | |
879bfdc2 | 1660 | if (hw_breakpoint_error) |
81d0cc19 | 1661 | { |
c6510018 MS |
1662 | fprintf_unfiltered (tmp_error_stream, |
1663 | "Could not insert hardware breakpoints:\n\ | |
1664 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1665 | } |
81d0cc19 GS |
1666 | target_terminal_ours_for_output (); |
1667 | error_stream (tmp_error_stream); | |
1668 | } | |
f7545552 TT |
1669 | |
1670 | do_cleanups (cleanups); | |
c906108c SS |
1671 | } |
1672 | ||
c906108c | 1673 | int |
fba45db2 | 1674 | remove_breakpoints (void) |
c906108c | 1675 | { |
876fa593 | 1676 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1677 | int val = 0; |
c906108c | 1678 | |
876fa593 | 1679 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1680 | { |
0bde7532 | 1681 | if (b->inserted) |
3a1bae8e | 1682 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1683 | } |
3a1bae8e | 1684 | return val; |
c906108c SS |
1685 | } |
1686 | ||
6c95b8df PA |
1687 | /* Remove breakpoints of process PID. */ |
1688 | ||
1689 | int | |
1690 | remove_breakpoints_pid (int pid) | |
1691 | { | |
876fa593 | 1692 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1693 | int val; |
1694 | struct inferior *inf = find_inferior_pid (pid); | |
1695 | ||
876fa593 | 1696 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
1697 | { |
1698 | if (b->pspace != inf->pspace) | |
1699 | continue; | |
1700 | ||
1701 | if (b->inserted) | |
1702 | { | |
1703 | val = remove_breakpoint (b, mark_uninserted); | |
1704 | if (val != 0) | |
1705 | return val; | |
1706 | } | |
1707 | } | |
1708 | return 0; | |
1709 | } | |
1710 | ||
692590c1 | 1711 | int |
80ce1ecb | 1712 | remove_hw_watchpoints (void) |
692590c1 | 1713 | { |
876fa593 | 1714 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1715 | int val = 0; |
692590c1 | 1716 | |
876fa593 | 1717 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 1718 | { |
0bde7532 | 1719 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1720 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1721 | } |
3a1bae8e | 1722 | return val; |
692590c1 MS |
1723 | } |
1724 | ||
c906108c | 1725 | int |
fba45db2 | 1726 | reattach_breakpoints (int pid) |
c906108c | 1727 | { |
6c95b8df | 1728 | struct cleanup *old_chain; |
876fa593 | 1729 | struct bp_location *b, **bp_tmp; |
c906108c | 1730 | int val; |
a4954f26 | 1731 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1732 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
1733 | struct inferior *inf; |
1734 | struct thread_info *tp; | |
1735 | ||
1736 | tp = any_live_thread_of_process (pid); | |
1737 | if (tp == NULL) | |
1738 | return 1; | |
1739 | ||
1740 | inf = find_inferior_pid (pid); | |
1741 | old_chain = save_inferior_ptid (); | |
1742 | ||
1743 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
1744 | |
1745 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1746 | |
876fa593 | 1747 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1748 | { |
6c95b8df PA |
1749 | if (b->pspace != inf->pspace) |
1750 | continue; | |
1751 | ||
0bde7532 | 1752 | if (b->inserted) |
c5aa993b | 1753 | { |
a4954f26 DJ |
1754 | b->inserted = 0; |
1755 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1756 | &dummy1, &dummy2); |
c5aa993b JM |
1757 | if (val != 0) |
1758 | { | |
ce696e05 | 1759 | do_cleanups (old_chain); |
c5aa993b JM |
1760 | return val; |
1761 | } | |
1762 | } | |
1763 | } | |
ce696e05 | 1764 | do_cleanups (old_chain); |
c906108c SS |
1765 | return 0; |
1766 | } | |
1767 | ||
e58b0e63 PA |
1768 | static int internal_breakpoint_number = -1; |
1769 | ||
e62c965a | 1770 | static struct breakpoint * |
a6d9a66e UW |
1771 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1772 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1773 | { |
e62c965a PP |
1774 | struct symtab_and_line sal; |
1775 | struct breakpoint *b; | |
1776 | ||
1777 | init_sal (&sal); /* initialize to zeroes */ | |
1778 | ||
1779 | sal.pc = address; | |
1780 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 1781 | sal.pspace = current_program_space; |
e62c965a | 1782 | |
a6d9a66e | 1783 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1784 | b->number = internal_breakpoint_number--; |
1785 | b->disposition = disp_donttouch; | |
1786 | ||
1787 | return b; | |
1788 | } | |
1789 | ||
1790 | static void | |
69de3c6a | 1791 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1792 | { |
69de3c6a | 1793 | struct objfile *objfile; |
e62c965a | 1794 | |
69de3c6a PP |
1795 | ALL_OBJFILES (objfile) |
1796 | { | |
1797 | struct breakpoint *b; | |
1798 | struct minimal_symbol *m; | |
1799 | ||
1800 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1801 | if (m == NULL) | |
1802 | continue; | |
e62c965a | 1803 | |
a6d9a66e UW |
1804 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1805 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1806 | bp_overlay_event); |
1807 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1808 | |
69de3c6a PP |
1809 | if (overlay_debugging == ovly_auto) |
1810 | { | |
1811 | b->enable_state = bp_enabled; | |
1812 | overlay_events_enabled = 1; | |
1813 | } | |
1814 | else | |
1815 | { | |
1816 | b->enable_state = bp_disabled; | |
1817 | overlay_events_enabled = 0; | |
1818 | } | |
e62c965a PP |
1819 | } |
1820 | update_global_location_list (1); | |
1821 | } | |
1822 | ||
0fd8e87f UW |
1823 | static void |
1824 | create_longjmp_master_breakpoint (char *func_name) | |
1825 | { | |
6c95b8df | 1826 | struct program_space *pspace; |
0fd8e87f | 1827 | struct objfile *objfile; |
6c95b8df PA |
1828 | struct cleanup *old_chain; |
1829 | ||
1830 | old_chain = save_current_program_space (); | |
0fd8e87f | 1831 | |
6c95b8df | 1832 | ALL_PSPACES (pspace) |
0fd8e87f UW |
1833 | ALL_OBJFILES (objfile) |
1834 | { | |
1835 | struct breakpoint *b; | |
1836 | struct minimal_symbol *m; | |
1837 | ||
1838 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1839 | continue; | |
1840 | ||
6c95b8df PA |
1841 | set_current_program_space (pspace); |
1842 | ||
0fd8e87f UW |
1843 | m = lookup_minimal_symbol_text (func_name, objfile); |
1844 | if (m == NULL) | |
1845 | continue; | |
1846 | ||
a6d9a66e UW |
1847 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1848 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1849 | bp_longjmp_master); |
1850 | b->addr_string = xstrdup (func_name); | |
1851 | b->enable_state = bp_disabled; | |
1852 | } | |
1853 | update_global_location_list (1); | |
6c95b8df PA |
1854 | |
1855 | do_cleanups (old_chain); | |
0fd8e87f UW |
1856 | } |
1857 | ||
c906108c | 1858 | void |
fba45db2 | 1859 | update_breakpoints_after_exec (void) |
c906108c | 1860 | { |
c5aa993b JM |
1861 | struct breakpoint *b; |
1862 | struct breakpoint *temp; | |
876fa593 | 1863 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 1864 | |
25b22b0a PA |
1865 | /* We're about to delete breakpoints from GDB's lists. If the |
1866 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1867 | writing the breakpoints' "shadow contents" back into memory. The | |
1868 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1869 | do that. Instead, the target is responsible from marking | |
1870 | breakpoints out as soon as it detects an exec. We don't do that | |
1871 | here instead, because there may be other attempts to delete | |
1872 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 1873 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
1874 | if (bploc->pspace == current_program_space) |
1875 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1876 | |
1877 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 1878 | { |
6c95b8df PA |
1879 | if (b->pspace != current_program_space) |
1880 | continue; | |
1881 | ||
c5aa993b JM |
1882 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
1883 | if (b->type == bp_shlib_event) | |
1884 | { | |
1885 | delete_breakpoint (b); | |
1886 | continue; | |
1887 | } | |
c906108c | 1888 | |
4efc6507 DE |
1889 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
1890 | if (b->type == bp_jit_event) | |
1891 | { | |
1892 | delete_breakpoint (b); | |
1893 | continue; | |
1894 | } | |
1895 | ||
1900040c | 1896 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1897 | as must overlay event and longjmp master breakpoints. */ |
1898 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1899 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1900 | { |
1901 | delete_breakpoint (b); | |
1902 | continue; | |
1903 | } | |
1904 | ||
c5aa993b JM |
1905 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1906 | if (b->type == bp_step_resume) | |
1907 | { | |
1908 | delete_breakpoint (b); | |
1909 | continue; | |
1910 | } | |
1911 | ||
611c83ae PA |
1912 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1913 | after an exec. */ | |
1914 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1915 | { | |
1916 | delete_breakpoint (b); | |
1917 | continue; | |
1918 | } | |
1919 | ||
ce78b96d JB |
1920 | if (b->type == bp_catchpoint) |
1921 | { | |
1922 | /* For now, none of the bp_catchpoint breakpoints need to | |
1923 | do anything at this point. In the future, if some of | |
1924 | the catchpoints need to something, we will need to add | |
1925 | a new method, and call this method from here. */ | |
1926 | continue; | |
1927 | } | |
1928 | ||
c5aa993b JM |
1929 | /* bp_finish is a special case. The only way we ought to be able |
1930 | to see one of these when an exec() has happened, is if the user | |
1931 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1932 | carries them to the call-site of the current callee, by setting | |
1933 | a temporary bp there and resuming. But in this case, the finish | |
1934 | will carry them entirely through the vfork & exec. | |
1935 | ||
1936 | We don't want to allow a bp_finish to remain inserted now. But | |
1937 | we can't safely delete it, 'cause finish_command has a handle to | |
1938 | the bp on a bpstat, and will later want to delete it. There's a | |
1939 | chance (and I've seen it happen) that if we delete the bp_finish | |
1940 | here, that its storage will get reused by the time finish_command | |
1941 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1942 | We really must allow finish_command to delete a bp_finish. | |
1943 | ||
53a5351d JM |
1944 | In the absense of a general solution for the "how do we know |
1945 | it's safe to delete something others may have handles to?" | |
1946 | problem, what we'll do here is just uninsert the bp_finish, and | |
1947 | let finish_command delete it. | |
1948 | ||
1949 | (We know the bp_finish is "doomed" in the sense that it's | |
1950 | momentary, and will be deleted as soon as finish_command sees | |
1951 | the inferior stopped. So it doesn't matter that the bp's | |
1952 | address is probably bogus in the new a.out, unlike e.g., the | |
1953 | solib breakpoints.) */ | |
c5aa993b | 1954 | |
c5aa993b JM |
1955 | if (b->type == bp_finish) |
1956 | { | |
1957 | continue; | |
1958 | } | |
1959 | ||
1960 | /* Without a symbolic address, we have little hope of the | |
1961 | pre-exec() address meaning the same thing in the post-exec() | |
1962 | a.out. */ | |
1963 | if (b->addr_string == NULL) | |
1964 | { | |
1965 | delete_breakpoint (b); | |
1966 | continue; | |
1967 | } | |
c5aa993b | 1968 | } |
1900040c | 1969 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1970 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1971 | create_longjmp_master_breakpoint ("longjmp"); |
1972 | create_longjmp_master_breakpoint ("_longjmp"); | |
1973 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1974 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1975 | } |
1976 | ||
1977 | int | |
fba45db2 | 1978 | detach_breakpoints (int pid) |
c906108c | 1979 | { |
876fa593 | 1980 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1981 | int val = 0; |
ce696e05 | 1982 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 1983 | struct inferior *inf = current_inferior (); |
c5aa993b | 1984 | |
39f77062 | 1985 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1986 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1987 | |
6c95b8df | 1988 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 1989 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 1990 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1991 | { |
6c95b8df PA |
1992 | if (b->pspace != inf->pspace) |
1993 | continue; | |
1994 | ||
0bde7532 | 1995 | if (b->inserted) |
6c95b8df | 1996 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 1997 | } |
ce696e05 | 1998 | do_cleanups (old_chain); |
3a1bae8e | 1999 | return val; |
c906108c SS |
2000 | } |
2001 | ||
6c95b8df PA |
2002 | /* Remove the breakpoint location B from the current address space. |
2003 | Note that this is used to detach breakpoints from a child fork. | |
2004 | When we get here, the child isn't in the inferior list, and neither | |
2005 | do we have objects to represent its address space --- we should | |
2006 | *not* look at b->pspace->aspace here. */ | |
2007 | ||
c906108c | 2008 | static int |
6c95b8df | 2009 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2010 | { |
2011 | int val; | |
6c95b8df | 2012 | struct cleanup *old_chain; |
c5aa993b | 2013 | |
0bde7532 | 2014 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2015 | /* Permanent breakpoints cannot be inserted or removed. */ |
2016 | return 0; | |
2017 | ||
74960c60 VP |
2018 | /* The type of none suggests that owner is actually deleted. |
2019 | This should not ever happen. */ | |
2020 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2021 | |
2022 | if (b->loc_type == bp_loc_software_breakpoint | |
2023 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2024 | { |
c02f5703 MS |
2025 | /* "Normal" instruction breakpoint: either the standard |
2026 | trap-instruction bp (bp_breakpoint), or a | |
2027 | bp_hardware_breakpoint. */ | |
2028 | ||
2029 | /* First check to see if we have to handle an overlay. */ | |
2030 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2031 | || b->section == NULL |
2032 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2033 | { |
2034 | /* No overlay handling: just remove the breakpoint. */ | |
2035 | ||
0bde7532 | 2036 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2037 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2038 | else |
a6d9a66e | 2039 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2040 | } |
c906108c SS |
2041 | else |
2042 | { | |
c02f5703 MS |
2043 | /* This breakpoint is in an overlay section. |
2044 | Did we set a breakpoint at the LMA? */ | |
2045 | if (!overlay_events_enabled) | |
2046 | { | |
2047 | /* Yes -- overlay event support is not active, so we | |
2048 | should have set a breakpoint at the LMA. Remove it. | |
2049 | */ | |
c02f5703 MS |
2050 | /* Ignore any failures: if the LMA is in ROM, we will |
2051 | have already warned when we failed to insert it. */ | |
0bde7532 | 2052 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2053 | target_remove_hw_breakpoint (b->gdbarch, |
2054 | &b->overlay_target_info); | |
c02f5703 | 2055 | else |
a6d9a66e UW |
2056 | target_remove_breakpoint (b->gdbarch, |
2057 | &b->overlay_target_info); | |
c02f5703 MS |
2058 | } |
2059 | /* Did we set a breakpoint at the VMA? | |
2060 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2061 | if (b->inserted) |
c906108c | 2062 | { |
c02f5703 MS |
2063 | /* Yes -- remove it. Previously we did not bother to |
2064 | remove the breakpoint if the section had been | |
2065 | unmapped, but let's not rely on that being safe. We | |
2066 | don't know what the overlay manager might do. */ | |
0bde7532 | 2067 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2068 | val = target_remove_hw_breakpoint (b->gdbarch, |
2069 | &b->target_info); | |
aa67235e UW |
2070 | |
2071 | /* However, we should remove *software* breakpoints only | |
2072 | if the section is still mapped, or else we overwrite | |
2073 | wrong code with the saved shadow contents. */ | |
2074 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2075 | val = target_remove_breakpoint (b->gdbarch, |
2076 | &b->target_info); | |
aa67235e UW |
2077 | else |
2078 | val = 0; | |
c906108c | 2079 | } |
c02f5703 MS |
2080 | else |
2081 | { | |
2082 | /* No -- not inserted, so no need to remove. No error. */ | |
2083 | val = 0; | |
2084 | } | |
c906108c | 2085 | } |
879d1e6b UW |
2086 | |
2087 | /* In some cases, we might not be able to remove a breakpoint | |
2088 | in a shared library that has already been removed, but we | |
2089 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2090 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2091 | val = 0; |
2092 | ||
c906108c SS |
2093 | if (val) |
2094 | return val; | |
0bde7532 | 2095 | b->inserted = (is == mark_inserted); |
c906108c | 2096 | } |
a5606eee | 2097 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2098 | { |
278cd55f AC |
2099 | struct value *v; |
2100 | struct value *n; | |
c5aa993b | 2101 | |
0bde7532 | 2102 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2103 | val = target_remove_watchpoint (b->address, b->length, |
2104 | b->watchpoint_type); | |
2e70b7b9 | 2105 | |
c906108c | 2106 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2107 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2108 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2109 | b->owner->number); |
c906108c | 2110 | } |
ce78b96d JB |
2111 | else if (b->owner->type == bp_catchpoint |
2112 | && breakpoint_enabled (b->owner) | |
2113 | && !b->duplicate) | |
2114 | { | |
2115 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2116 | ||
2117 | val = b->owner->ops->remove (b->owner); | |
2118 | if (val) | |
2119 | return val; | |
2120 | b->inserted = (is == mark_inserted); | |
2121 | } | |
c906108c SS |
2122 | |
2123 | return 0; | |
2124 | } | |
2125 | ||
6c95b8df PA |
2126 | static int |
2127 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2128 | { | |
2129 | int ret; | |
2130 | struct cleanup *old_chain; | |
2131 | ||
2132 | if (b->owner->enable_state == bp_permanent) | |
2133 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2134 | return 0; | |
2135 | ||
2136 | /* The type of none suggests that owner is actually deleted. | |
2137 | This should not ever happen. */ | |
2138 | gdb_assert (b->owner->type != bp_none); | |
2139 | ||
2140 | old_chain = save_current_space_and_thread (); | |
2141 | ||
2142 | switch_to_program_space_and_thread (b->pspace); | |
2143 | ||
2144 | ret = remove_breakpoint_1 (b, is); | |
2145 | ||
2146 | do_cleanups (old_chain); | |
2147 | return ret; | |
2148 | } | |
2149 | ||
c906108c SS |
2150 | /* Clear the "inserted" flag in all breakpoints. */ |
2151 | ||
25b22b0a | 2152 | void |
fba45db2 | 2153 | mark_breakpoints_out (void) |
c906108c | 2154 | { |
876fa593 | 2155 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2156 | |
876fa593 | 2157 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2158 | if (bpt->pspace == current_program_space) |
2159 | bpt->inserted = 0; | |
c906108c SS |
2160 | } |
2161 | ||
53a5351d JM |
2162 | /* Clear the "inserted" flag in all breakpoints and delete any |
2163 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2164 | |
2165 | Plus other such housekeeping that has to be done for breakpoints | |
2166 | between runs. | |
2167 | ||
53a5351d JM |
2168 | Note: this function gets called at the end of a run (by |
2169 | generic_mourn_inferior) and when a run begins (by | |
2170 | init_wait_for_inferior). */ | |
c906108c SS |
2171 | |
2172 | ||
2173 | ||
2174 | void | |
fba45db2 | 2175 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2176 | { |
52f0bd74 | 2177 | struct breakpoint *b, *temp; |
876fa593 | 2178 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2179 | int ix; |
6c95b8df | 2180 | struct program_space *pspace = current_program_space; |
c906108c | 2181 | |
50c71eaf PA |
2182 | /* If breakpoint locations are shared across processes, then there's |
2183 | nothing to do. */ | |
2567c7d9 | 2184 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2185 | return; |
2186 | ||
876fa593 | 2187 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2188 | { |
2189 | if (bpt->pspace == pspace | |
2190 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2191 | bpt->inserted = 0; |
6c95b8df | 2192 | } |
075f6582 | 2193 | |
c906108c | 2194 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2195 | { |
6c95b8df PA |
2196 | if (b->loc && b->loc->pspace != pspace) |
2197 | continue; | |
2198 | ||
c5aa993b JM |
2199 | switch (b->type) |
2200 | { | |
2201 | case bp_call_dummy: | |
2202 | case bp_watchpoint_scope: | |
c906108c | 2203 | |
c5aa993b JM |
2204 | /* If the call dummy breakpoint is at the entry point it will |
2205 | cause problems when the inferior is rerun, so we better | |
2206 | get rid of it. | |
c906108c | 2207 | |
c5aa993b JM |
2208 | Also get rid of scope breakpoints. */ |
2209 | delete_breakpoint (b); | |
2210 | break; | |
c906108c | 2211 | |
c5aa993b JM |
2212 | case bp_watchpoint: |
2213 | case bp_hardware_watchpoint: | |
2214 | case bp_read_watchpoint: | |
2215 | case bp_access_watchpoint: | |
c906108c | 2216 | |
c5aa993b JM |
2217 | /* Likewise for watchpoints on local expressions. */ |
2218 | if (b->exp_valid_block != NULL) | |
2219 | delete_breakpoint (b); | |
967af18d | 2220 | else if (context == inf_starting) |
c860120c PM |
2221 | { |
2222 | /* Reset val field to force reread of starting value | |
2223 | in insert_breakpoints. */ | |
2224 | if (b->val) | |
2225 | value_free (b->val); | |
2226 | b->val = NULL; | |
fa4727a6 | 2227 | b->val_valid = 0; |
c860120c | 2228 | } |
c5aa993b JM |
2229 | break; |
2230 | default: | |
c5aa993b JM |
2231 | break; |
2232 | } | |
2233 | } | |
1c5cfe86 PA |
2234 | |
2235 | /* Get rid of the moribund locations. */ | |
2236 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2237 | free_bp_location (bpt); | |
2238 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2239 | } |
2240 | ||
6c95b8df PA |
2241 | /* These functions concern about actual breakpoints inserted in the |
2242 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2243 | we need to hop over the bkpt --- so we check for address space | |
2244 | match, not program space. */ | |
2245 | ||
c2c6d25f JM |
2246 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2247 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2248 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2249 | permanent breakpoint. | |
2250 | - When continuing from a location with an ordinary breakpoint, we | |
2251 | actually single step once before calling insert_breakpoints. | |
2252 | - When continuing from a localion with a permanent breakpoint, we | |
2253 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2254 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2255 | |
c2c6d25f | 2256 | enum breakpoint_here |
6c95b8df | 2257 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2258 | { |
876fa593 | 2259 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2260 | int any_breakpoint_here = 0; |
c906108c | 2261 | |
876fa593 | 2262 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2263 | { |
2264 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2265 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2266 | continue; | |
2267 | ||
468d015d | 2268 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2269 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2270 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2271 | aspace, pc)) | |
075f6582 DJ |
2272 | { |
2273 | if (overlay_debugging | |
2274 | && section_is_overlay (bpt->section) | |
2275 | && !section_is_mapped (bpt->section)) | |
2276 | continue; /* unmapped overlay -- can't be a match */ | |
2277 | else if (bpt->owner->enable_state == bp_permanent) | |
2278 | return permanent_breakpoint_here; | |
2279 | else | |
2280 | any_breakpoint_here = 1; | |
2281 | } | |
2282 | } | |
c906108c | 2283 | |
c2c6d25f | 2284 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2285 | } |
2286 | ||
1c5cfe86 PA |
2287 | /* Return true if there's a moribund breakpoint at PC. */ |
2288 | ||
2289 | int | |
6c95b8df | 2290 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2291 | { |
2292 | struct bp_location *loc; | |
2293 | int ix; | |
2294 | ||
2295 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2296 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2297 | aspace, pc)) | |
1c5cfe86 PA |
2298 | return 1; |
2299 | ||
2300 | return 0; | |
2301 | } | |
c2c6d25f | 2302 | |
c36b740a | 2303 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2304 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2305 | This does not check for single-step breakpoints, which are |
2306 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2307 | |
2308 | int | |
6c95b8df | 2309 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2310 | { |
876fa593 | 2311 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2312 | |
876fa593 | 2313 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2314 | { |
075f6582 DJ |
2315 | if (bpt->loc_type != bp_loc_software_breakpoint |
2316 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2317 | continue; | |
2318 | ||
2319 | if (bpt->inserted | |
6c95b8df PA |
2320 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2321 | aspace, pc)) | |
075f6582 DJ |
2322 | { |
2323 | if (overlay_debugging | |
2324 | && section_is_overlay (bpt->section) | |
2325 | && !section_is_mapped (bpt->section)) | |
2326 | continue; /* unmapped overlay -- can't be a match */ | |
2327 | else | |
2328 | return 1; | |
2329 | } | |
c5aa993b | 2330 | } |
c36b740a VP |
2331 | return 0; |
2332 | } | |
2333 | ||
2334 | /* Returns non-zero iff there's either regular breakpoint | |
2335 | or a single step breakpoint inserted at PC. */ | |
2336 | ||
2337 | int | |
6c95b8df | 2338 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2339 | { |
6c95b8df | 2340 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2341 | return 1; |
c906108c | 2342 | |
6c95b8df | 2343 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2344 | return 1; |
2345 | ||
c906108c SS |
2346 | return 0; |
2347 | } | |
2348 | ||
4fa8626c DJ |
2349 | /* This function returns non-zero iff there is a software breakpoint |
2350 | inserted at PC. */ | |
2351 | ||
2352 | int | |
6c95b8df | 2353 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2354 | { |
876fa593 | 2355 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2356 | int any_breakpoint_here = 0; |
2357 | ||
876fa593 | 2358 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2359 | { |
2360 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2361 | continue; | |
2362 | ||
0d381245 | 2363 | if (bpt->inserted |
6c95b8df PA |
2364 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2365 | aspace, pc)) | |
4fa8626c DJ |
2366 | { |
2367 | if (overlay_debugging | |
2368 | && section_is_overlay (bpt->section) | |
2369 | && !section_is_mapped (bpt->section)) | |
2370 | continue; /* unmapped overlay -- can't be a match */ | |
2371 | else | |
2372 | return 1; | |
2373 | } | |
2374 | } | |
2375 | ||
1aafd4da | 2376 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2377 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2378 | return 1; |
2379 | ||
4fa8626c DJ |
2380 | return 0; |
2381 | } | |
2382 | ||
9093389c PA |
2383 | int |
2384 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2385 | CORE_ADDR addr, ULONGEST len) | |
2386 | { | |
2387 | struct breakpoint *bpt; | |
2388 | ||
2389 | ALL_BREAKPOINTS (bpt) | |
2390 | { | |
2391 | struct bp_location *loc; | |
2392 | ||
2393 | if (bpt->type != bp_hardware_watchpoint | |
2394 | && bpt->type != bp_access_watchpoint) | |
2395 | continue; | |
2396 | ||
2397 | if (!breakpoint_enabled (bpt)) | |
2398 | continue; | |
2399 | ||
2400 | for (loc = bpt->loc; loc; loc = loc->next) | |
2401 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2402 | { | |
2403 | CORE_ADDR l, h; | |
2404 | ||
2405 | /* Check for intersection. */ | |
2406 | l = max (loc->address, addr); | |
2407 | h = min (loc->address + loc->length, addr + len); | |
2408 | if (l < h) | |
2409 | return 1; | |
2410 | } | |
2411 | } | |
2412 | return 0; | |
2413 | } | |
2414 | ||
075f6582 DJ |
2415 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2416 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2417 | |
2418 | int | |
6c95b8df PA |
2419 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2420 | ptid_t ptid) | |
c906108c | 2421 | { |
876fa593 | 2422 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2423 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2424 | int thread = -1; |
4a306c9a | 2425 | int task = 0; |
a6f1cd96 | 2426 | |
876fa593 | 2427 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2428 | { |
075f6582 DJ |
2429 | if (bpt->loc_type != bp_loc_software_breakpoint |
2430 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2431 | continue; | |
2432 | ||
a6f1cd96 JB |
2433 | if (!breakpoint_enabled (bpt->owner) |
2434 | && bpt->owner->enable_state != bp_permanent) | |
2435 | continue; | |
2436 | ||
6c95b8df PA |
2437 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2438 | aspace, pc)) | |
a6f1cd96 JB |
2439 | continue; |
2440 | ||
2441 | if (bpt->owner->thread != -1) | |
075f6582 | 2442 | { |
a6f1cd96 JB |
2443 | /* This is a thread-specific breakpoint. Check that ptid |
2444 | matches that thread. If thread hasn't been computed yet, | |
2445 | it is now time to do so. */ | |
2446 | if (thread == -1) | |
2447 | thread = pid_to_thread_id (ptid); | |
2448 | if (bpt->owner->thread != thread) | |
2449 | continue; | |
075f6582 | 2450 | } |
a6f1cd96 | 2451 | |
4a306c9a JB |
2452 | if (bpt->owner->task != 0) |
2453 | { | |
2454 | /* This is a task-specific breakpoint. Check that ptid | |
2455 | matches that task. If task hasn't been computed yet, | |
2456 | it is now time to do so. */ | |
2457 | if (task == 0) | |
2458 | task = ada_get_task_number (ptid); | |
2459 | if (bpt->owner->task != task) | |
2460 | continue; | |
2461 | } | |
2462 | ||
a6f1cd96 JB |
2463 | if (overlay_debugging |
2464 | && section_is_overlay (bpt->section) | |
2465 | && !section_is_mapped (bpt->section)) | |
2466 | continue; /* unmapped overlay -- can't be a match */ | |
2467 | ||
2468 | return 1; | |
c5aa993b | 2469 | } |
c906108c SS |
2470 | |
2471 | return 0; | |
2472 | } | |
c906108c | 2473 | \f |
c5aa993b | 2474 | |
c906108c SS |
2475 | /* bpstat stuff. External routines' interfaces are documented |
2476 | in breakpoint.h. */ | |
2477 | ||
2478 | int | |
fba45db2 | 2479 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2480 | { |
533be4dd | 2481 | return (ep->type == bp_catchpoint); |
c906108c SS |
2482 | } |
2483 | ||
198757a8 VP |
2484 | void |
2485 | bpstat_free (bpstat bs) | |
2486 | { | |
2487 | if (bs->old_val != NULL) | |
2488 | value_free (bs->old_val); | |
2489 | free_command_lines (&bs->commands); | |
2490 | xfree (bs); | |
2491 | } | |
2492 | ||
c906108c SS |
2493 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2494 | Also free any storage that is part of a bpstat. */ | |
2495 | ||
2496 | void | |
fba45db2 | 2497 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2498 | { |
2499 | bpstat p; | |
2500 | bpstat q; | |
2501 | ||
2502 | if (bsp == 0) | |
2503 | return; | |
2504 | p = *bsp; | |
2505 | while (p != NULL) | |
2506 | { | |
2507 | q = p->next; | |
198757a8 | 2508 | bpstat_free (p); |
c906108c SS |
2509 | p = q; |
2510 | } | |
2511 | *bsp = NULL; | |
2512 | } | |
2513 | ||
2514 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2515 | is part of the bpstat is copied as well. */ | |
2516 | ||
2517 | bpstat | |
fba45db2 | 2518 | bpstat_copy (bpstat bs) |
c906108c SS |
2519 | { |
2520 | bpstat p = NULL; | |
2521 | bpstat tmp; | |
2522 | bpstat retval = NULL; | |
2523 | ||
2524 | if (bs == NULL) | |
2525 | return bs; | |
2526 | ||
2527 | for (; bs != NULL; bs = bs->next) | |
2528 | { | |
2529 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2530 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2531 | if (bs->commands != NULL) |
2532 | tmp->commands = copy_command_lines (bs->commands); | |
2533 | if (bs->old_val != NULL) | |
3c3185ac JK |
2534 | { |
2535 | tmp->old_val = value_copy (bs->old_val); | |
2536 | release_value (tmp->old_val); | |
2537 | } | |
31cc81e9 | 2538 | |
c906108c SS |
2539 | if (p == NULL) |
2540 | /* This is the first thing in the chain. */ | |
2541 | retval = tmp; | |
2542 | else | |
2543 | p->next = tmp; | |
2544 | p = tmp; | |
2545 | } | |
2546 | p->next = NULL; | |
2547 | return retval; | |
2548 | } | |
2549 | ||
2550 | /* Find the bpstat associated with this breakpoint */ | |
2551 | ||
2552 | bpstat | |
fba45db2 | 2553 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2554 | { |
c5aa993b JM |
2555 | if (bsp == NULL) |
2556 | return NULL; | |
c906108c | 2557 | |
c5aa993b JM |
2558 | for (; bsp != NULL; bsp = bsp->next) |
2559 | { | |
4f8d1dc6 | 2560 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2561 | return bsp; |
2562 | } | |
c906108c SS |
2563 | return NULL; |
2564 | } | |
2565 | ||
2566 | /* Find a step_resume breakpoint associated with this bpstat. | |
2567 | (If there are multiple step_resume bp's on the list, this function | |
2568 | will arbitrarily pick one.) | |
2569 | ||
2570 | It is an error to use this function if BPSTAT doesn't contain a | |
2571 | step_resume breakpoint. | |
2572 | ||
2573 | See wait_for_inferior's use of this function. */ | |
2574 | struct breakpoint * | |
fba45db2 | 2575 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2576 | { |
8601f500 MS |
2577 | int current_thread; |
2578 | ||
8a3fe4f8 | 2579 | gdb_assert (bsp != NULL); |
c906108c | 2580 | |
8601f500 MS |
2581 | current_thread = pid_to_thread_id (inferior_ptid); |
2582 | ||
c906108c SS |
2583 | for (; bsp != NULL; bsp = bsp->next) |
2584 | { | |
059fb39f PM |
2585 | if ((bsp->breakpoint_at != NULL) |
2586 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2587 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2588 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2589 | return bsp->breakpoint_at->owner; |
c906108c SS |
2590 | } |
2591 | ||
8a3fe4f8 | 2592 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2593 | } |
2594 | ||
2595 | ||
8671a17b | 2596 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2597 | at. *BSP upon return is a bpstat which points to the remaining |
2598 | breakpoints stopped at (but which is not guaranteed to be good for | |
2599 | anything but further calls to bpstat_num). | |
8671a17b PA |
2600 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2601 | Return -1 if stopped at a breakpoint that has been deleted since | |
2602 | we set it. | |
2603 | Return 1 otherwise. */ | |
c906108c SS |
2604 | |
2605 | int | |
8671a17b | 2606 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2607 | { |
2608 | struct breakpoint *b; | |
2609 | ||
2610 | if ((*bsp) == NULL) | |
2611 | return 0; /* No more breakpoint values */ | |
8671a17b | 2612 | |
4f8d1dc6 VP |
2613 | /* We assume we'll never have several bpstats that |
2614 | correspond to a single breakpoint -- otherwise, | |
2615 | this function might return the same number more | |
2616 | than once and this will look ugly. */ | |
2617 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2618 | *bsp = (*bsp)->next; |
2619 | if (b == NULL) | |
2620 | return -1; /* breakpoint that's been deleted since */ | |
2621 | ||
2622 | *num = b->number; /* We have its number */ | |
2623 | return 1; | |
c906108c SS |
2624 | } |
2625 | ||
2626 | /* Modify BS so that the actions will not be performed. */ | |
2627 | ||
2628 | void | |
fba45db2 | 2629 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2630 | { |
2631 | for (; bs != NULL; bs = bs->next) | |
2632 | { | |
c2b8ed2c | 2633 | free_command_lines (&bs->commands); |
c906108c SS |
2634 | if (bs->old_val != NULL) |
2635 | { | |
2636 | value_free (bs->old_val); | |
2637 | bs->old_val = NULL; | |
2638 | } | |
2639 | } | |
2640 | } | |
2641 | ||
f3b1572e PA |
2642 | /* Called when a command is about to proceed the inferior. */ |
2643 | ||
2644 | static void | |
2645 | breakpoint_about_to_proceed (void) | |
2646 | { | |
2647 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2648 | { | |
2649 | struct thread_info *tp = inferior_thread (); | |
2650 | ||
2651 | /* Allow inferior function calls in breakpoint commands to not | |
2652 | interrupt the command list. When the call finishes | |
2653 | successfully, the inferior will be standing at the same | |
2654 | breakpoint as if nothing happened. */ | |
2655 | if (tp->in_infcall) | |
2656 | return; | |
2657 | } | |
2658 | ||
2659 | breakpoint_proceeded = 1; | |
2660 | } | |
2661 | ||
c906108c | 2662 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2663 | static void |
4efb68b1 | 2664 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2665 | { |
2666 | executing_breakpoint_commands = 0; | |
2667 | } | |
2668 | ||
2669 | /* Execute all the commands associated with all the breakpoints at this | |
2670 | location. Any of these commands could cause the process to proceed | |
2671 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2672 | the global "breakpoint_proceeded" after each command. |
c906108c | 2673 | |
347bddb7 PA |
2674 | Returns true if a breakpoint command resumed the inferior. In that |
2675 | case, it is the caller's responsibility to recall it again with the | |
2676 | bpstat of the current thread. */ | |
2677 | ||
2678 | static int | |
2679 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2680 | { |
2681 | bpstat bs; | |
2682 | struct cleanup *old_chain; | |
347bddb7 | 2683 | int again = 0; |
c906108c SS |
2684 | |
2685 | /* Avoid endless recursion if a `source' command is contained | |
2686 | in bs->commands. */ | |
2687 | if (executing_breakpoint_commands) | |
347bddb7 | 2688 | return 0; |
c906108c SS |
2689 | |
2690 | executing_breakpoint_commands = 1; | |
2691 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2692 | ||
c906108c SS |
2693 | /* This pointer will iterate over the list of bpstat's. */ |
2694 | bs = *bsp; | |
2695 | ||
2696 | breakpoint_proceeded = 0; | |
2697 | for (; bs != NULL; bs = bs->next) | |
2698 | { | |
6c50ab1c JB |
2699 | struct command_line *cmd; |
2700 | struct cleanup *this_cmd_tree_chain; | |
2701 | ||
2702 | /* Take ownership of the BSP's command tree, if it has one. | |
2703 | ||
2704 | The command tree could legitimately contain commands like | |
2705 | 'step' and 'next', which call clear_proceed_status, which | |
2706 | frees stop_bpstat's command tree. To make sure this doesn't | |
2707 | free the tree we're executing out from under us, we need to | |
2708 | take ownership of the tree ourselves. Since a given bpstat's | |
2709 | commands are only executed once, we don't need to copy it; we | |
2710 | can clear the pointer in the bpstat, and make sure we free | |
2711 | the tree when we're done. */ | |
c906108c | 2712 | cmd = bs->commands; |
6c50ab1c JB |
2713 | bs->commands = 0; |
2714 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2715 | ||
c906108c SS |
2716 | while (cmd != NULL) |
2717 | { | |
2718 | execute_control_command (cmd); | |
2719 | ||
2720 | if (breakpoint_proceeded) | |
2721 | break; | |
2722 | else | |
2723 | cmd = cmd->next; | |
2724 | } | |
6c50ab1c JB |
2725 | |
2726 | /* We can free this command tree now. */ | |
2727 | do_cleanups (this_cmd_tree_chain); | |
2728 | ||
c906108c | 2729 | if (breakpoint_proceeded) |
32c1e744 VP |
2730 | { |
2731 | if (target_can_async_p ()) | |
347bddb7 PA |
2732 | /* If we are in async mode, then the target might be still |
2733 | running, not stopped at any breakpoint, so nothing for | |
2734 | us to do here -- just return to the event loop. */ | |
2735 | ; | |
32c1e744 VP |
2736 | else |
2737 | /* In sync mode, when execute_control_command returns | |
2738 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2739 | Breakpoint commands for that stop were not run, since |
2740 | execute_command does not run breakpoint commands -- | |
2741 | only command_line_handler does, but that one is not | |
2742 | involved in execution of breakpoint commands. So, we | |
2743 | can now execute breakpoint commands. It should be | |
2744 | noted that making execute_command do bpstat actions is | |
2745 | not an option -- in this case we'll have recursive | |
2746 | invocation of bpstat for each breakpoint with a | |
2747 | command, and can easily blow up GDB stack. Instead, we | |
2748 | return true, which will trigger the caller to recall us | |
2749 | with the new stop_bpstat. */ | |
2750 | again = 1; | |
2751 | break; | |
32c1e744 | 2752 | } |
c906108c | 2753 | } |
c2b8ed2c | 2754 | do_cleanups (old_chain); |
347bddb7 PA |
2755 | return again; |
2756 | } | |
2757 | ||
2758 | void | |
2759 | bpstat_do_actions (void) | |
2760 | { | |
2761 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2762 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2763 | && target_has_execution | |
2764 | && !is_exited (inferior_ptid) | |
2765 | && !is_executing (inferior_ptid)) | |
2766 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2767 | and only return when it is stopped at the next breakpoint, we | |
2768 | keep doing breakpoint actions until it returns false to | |
2769 | indicate the inferior was not resumed. */ | |
2770 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2771 | break; | |
c906108c SS |
2772 | } |
2773 | ||
fa4727a6 DJ |
2774 | /* Print out the (old or new) value associated with a watchpoint. */ |
2775 | ||
2776 | static void | |
2777 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2778 | { | |
2779 | if (val == NULL) | |
2780 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2781 | else | |
79a45b7d TT |
2782 | { |
2783 | struct value_print_options opts; | |
2784 | get_user_print_options (&opts); | |
2785 | value_print (val, stream, &opts); | |
2786 | } | |
fa4727a6 DJ |
2787 | } |
2788 | ||
e514a9d6 | 2789 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2790 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2791 | by having it set different print_it values. |
2792 | ||
2793 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2794 | through the bpstat list of things causing this stop, calling the | |
2795 | print_bp_stop_message function on each one. The behavior of the | |
2796 | print_bp_stop_message function depends on the print_it field of | |
2797 | bpstat. If such field so indicates, call this function here. | |
2798 | ||
2799 | Return values from this routine (ultimately used by bpstat_print() | |
2800 | and normal_stop() to decide what to do): | |
2801 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2802 | don't print anything else. | |
2803 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2804 | that something to be followed by a location. | |
2805 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2806 | that something to be followed by a location. | |
2807 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2808 | analysis. */ | |
c906108c | 2809 | |
917317f4 | 2810 | static enum print_stop_action |
fba45db2 | 2811 | print_it_typical (bpstat bs) |
c906108c | 2812 | { |
f7545552 | 2813 | struct cleanup *old_chain; |
4f8d1dc6 | 2814 | struct breakpoint *b; |
89f9893c | 2815 | const struct bp_location *bl; |
8b93c638 | 2816 | struct ui_stream *stb; |
f7545552 TT |
2817 | int bp_temp = 0; |
2818 | enum print_stop_action result; | |
2819 | ||
c906108c SS |
2820 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2821 | which has since been deleted. */ | |
e514a9d6 | 2822 | if (bs->breakpoint_at == NULL) |
917317f4 | 2823 | return PRINT_UNKNOWN; |
0d381245 VP |
2824 | bl = bs->breakpoint_at; |
2825 | b = bl->owner; | |
c906108c | 2826 | |
f7545552 TT |
2827 | stb = ui_out_stream_new (uiout); |
2828 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2829 | ||
4f8d1dc6 | 2830 | switch (b->type) |
c906108c | 2831 | { |
e514a9d6 JM |
2832 | case bp_breakpoint: |
2833 | case bp_hardware_breakpoint: | |
2cec12e5 | 2834 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2835 | if (bl->address != bl->requested_address) |
2836 | breakpoint_adjustment_warning (bl->requested_address, | |
2837 | bl->address, | |
4f8d1dc6 VP |
2838 | b->number, 1); |
2839 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2840 | if (bp_temp) |
2841 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2842 | else | |
2843 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2844 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2845 | { |
2846 | ui_out_field_string (uiout, "reason", | |
2847 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2848 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2849 | } | |
4f8d1dc6 | 2850 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2851 | ui_out_text (uiout, ", "); |
f7545552 | 2852 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2853 | break; |
2854 | ||
2855 | case bp_shlib_event: | |
917317f4 JM |
2856 | /* Did we stop because the user set the stop_on_solib_events |
2857 | variable? (If so, we report this as a generic, "Stopped due | |
2858 | to shlib event" message.) */ | |
a3f17187 | 2859 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2860 | result = PRINT_NOTHING; |
e514a9d6 JM |
2861 | break; |
2862 | ||
c4093a6a JM |
2863 | case bp_thread_event: |
2864 | /* Not sure how we will get here. | |
2865 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2866 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2867 | result = PRINT_NOTHING; |
c4093a6a JM |
2868 | break; |
2869 | ||
1900040c MS |
2870 | case bp_overlay_event: |
2871 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2872 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2873 | result = PRINT_NOTHING; |
1900040c MS |
2874 | break; |
2875 | ||
0fd8e87f UW |
2876 | case bp_longjmp_master: |
2877 | /* These should never be enabled. */ | |
2878 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2879 | result = PRINT_NOTHING; | |
2880 | break; | |
2881 | ||
e514a9d6 JM |
2882 | case bp_watchpoint: |
2883 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2884 | annotate_watchpoint (b->number); |
2885 | if (ui_out_is_mi_like_p (uiout)) | |
2886 | ui_out_field_string | |
2887 | (uiout, "reason", | |
2888 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2889 | mention (b); | |
f7545552 | 2890 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2891 | ui_out_text (uiout, "\nOld value = "); |
2892 | watchpoint_value_print (bs->old_val, stb->stream); | |
2893 | ui_out_field_stream (uiout, "old", stb); | |
2894 | ui_out_text (uiout, "\nNew value = "); | |
2895 | watchpoint_value_print (b->val, stb->stream); | |
2896 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2897 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2898 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2899 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2900 | break; |
2901 | ||
2902 | case bp_read_watchpoint: | |
9dc5e2a9 | 2903 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2904 | ui_out_field_string |
2905 | (uiout, "reason", | |
2906 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2907 | mention (b); |
f7545552 | 2908 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2909 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2910 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2911 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2912 | ui_out_text (uiout, "\n"); |
f7545552 | 2913 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2914 | break; |
2915 | ||
2916 | case bp_access_watchpoint: | |
fa4727a6 | 2917 | if (bs->old_val != NULL) |
8b93c638 | 2918 | { |
4f8d1dc6 | 2919 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2920 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2921 | ui_out_field_string |
2922 | (uiout, "reason", | |
2923 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2924 | mention (b); |
f7545552 | 2925 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2926 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2927 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2928 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2929 | ui_out_text (uiout, "\nNew value = "); |
2930 | } | |
2931 | else | |
2932 | { | |
4f8d1dc6 | 2933 | mention (b); |
9dc5e2a9 | 2934 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2935 | ui_out_field_string |
2936 | (uiout, "reason", | |
2937 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2938 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2939 | ui_out_text (uiout, "\nValue = "); |
2940 | } | |
fa4727a6 | 2941 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2942 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2943 | ui_out_text (uiout, "\n"); |
f7545552 | 2944 | result = PRINT_UNKNOWN; |
e514a9d6 | 2945 | break; |
4ce44c66 | 2946 | |
e514a9d6 JM |
2947 | /* Fall through, we don't deal with these types of breakpoints |
2948 | here. */ | |
2949 | ||
11cf8741 | 2950 | case bp_finish: |
9dc5e2a9 | 2951 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2952 | ui_out_field_string |
2953 | (uiout, "reason", | |
2954 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2955 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2956 | break; |
2957 | ||
e514a9d6 | 2958 | case bp_until: |
9dc5e2a9 | 2959 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2960 | ui_out_field_string |
2961 | (uiout, "reason", | |
2962 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2963 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2964 | break; |
2965 | ||
c2d11a7d | 2966 | case bp_none: |
e514a9d6 JM |
2967 | case bp_longjmp: |
2968 | case bp_longjmp_resume: | |
2969 | case bp_step_resume: | |
e514a9d6 JM |
2970 | case bp_watchpoint_scope: |
2971 | case bp_call_dummy: | |
1042e4c0 | 2972 | case bp_tracepoint: |
4efc6507 | 2973 | case bp_jit_event: |
e514a9d6 | 2974 | default: |
f7545552 TT |
2975 | result = PRINT_UNKNOWN; |
2976 | break; | |
e514a9d6 | 2977 | } |
f7545552 TT |
2978 | |
2979 | do_cleanups (old_chain); | |
2980 | return result; | |
e514a9d6 JM |
2981 | } |
2982 | ||
2983 | /* Generic routine for printing messages indicating why we | |
2984 | stopped. The behavior of this function depends on the value | |
2985 | 'print_it' in the bpstat structure. Under some circumstances we | |
2986 | may decide not to print anything here and delegate the task to | |
2987 | normal_stop(). */ | |
2988 | ||
2989 | static enum print_stop_action | |
2990 | print_bp_stop_message (bpstat bs) | |
2991 | { | |
2992 | switch (bs->print_it) | |
2993 | { | |
2994 | case print_it_noop: | |
2995 | /* Nothing should be printed for this bpstat entry. */ | |
2996 | return PRINT_UNKNOWN; | |
2997 | break; | |
2998 | ||
2999 | case print_it_done: | |
3000 | /* We still want to print the frame, but we already printed the | |
3001 | relevant messages. */ | |
3002 | return PRINT_SRC_AND_LOC; | |
3003 | break; | |
3004 | ||
3005 | case print_it_normal: | |
4f8d1dc6 | 3006 | { |
89f9893c | 3007 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3008 | struct breakpoint *b = bl ? bl->owner : NULL; |
3009 | ||
3010 | /* Normal case. Call the breakpoint's print_it method, or | |
3011 | print_it_typical. */ | |
3012 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3013 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3014 | return b->ops->print_it (b); | |
3015 | else | |
3016 | return print_it_typical (bs); | |
3017 | } | |
3018 | break; | |
3086aeae | 3019 | |
e514a9d6 | 3020 | default: |
8e65ff28 | 3021 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3022 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3023 | break; |
c906108c | 3024 | } |
c906108c SS |
3025 | } |
3026 | ||
e514a9d6 JM |
3027 | /* Print a message indicating what happened. This is called from |
3028 | normal_stop(). The input to this routine is the head of the bpstat | |
3029 | list - a list of the eventpoints that caused this stop. This | |
3030 | routine calls the generic print routine for printing a message | |
3031 | about reasons for stopping. This will print (for example) the | |
3032 | "Breakpoint n," part of the output. The return value of this | |
3033 | routine is one of: | |
c906108c | 3034 | |
917317f4 JM |
3035 | PRINT_UNKNOWN: Means we printed nothing |
3036 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3037 | code to print the location. An example is |
3038 | "Breakpoint 1, " which should be followed by | |
3039 | the location. | |
917317f4 | 3040 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3041 | to also print the location part of the message. |
3042 | An example is the catch/throw messages, which | |
917317f4 JM |
3043 | don't require a location appended to the end. |
3044 | PRINT_NOTHING: We have done some printing and we don't need any | |
3045 | further info to be printed.*/ | |
c906108c | 3046 | |
917317f4 | 3047 | enum print_stop_action |
fba45db2 | 3048 | bpstat_print (bpstat bs) |
c906108c SS |
3049 | { |
3050 | int val; | |
c5aa993b | 3051 | |
c906108c | 3052 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3053 | (Currently all watchpoints go on the bpstat whether hit or not. |
3054 | That probably could (should) be changed, provided care is taken | |
c906108c | 3055 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3056 | for (; bs; bs = bs->next) |
3057 | { | |
3058 | val = print_bp_stop_message (bs); | |
3059 | if (val == PRINT_SRC_ONLY | |
3060 | || val == PRINT_SRC_AND_LOC | |
3061 | || val == PRINT_NOTHING) | |
3062 | return val; | |
3063 | } | |
c906108c | 3064 | |
e514a9d6 JM |
3065 | /* We reached the end of the chain, or we got a null BS to start |
3066 | with and nothing was printed. */ | |
917317f4 | 3067 | return PRINT_UNKNOWN; |
c906108c SS |
3068 | } |
3069 | ||
3070 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3071 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3072 | The argument is a "struct expression *" that has been cast to char * to | |
3073 | make it pass through catch_errors. */ | |
3074 | ||
3075 | static int | |
4efb68b1 | 3076 | breakpoint_cond_eval (void *exp) |
c906108c | 3077 | { |
278cd55f | 3078 | struct value *mark = value_mark (); |
c5aa993b | 3079 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
3080 | value_free_to_mark (mark); |
3081 | return i; | |
3082 | } | |
3083 | ||
3084 | /* Allocate a new bpstat and chain it to the current one. */ | |
3085 | ||
3086 | static bpstat | |
89f9893c | 3087 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3088 | { |
3089 | bpstat bs; | |
3090 | ||
3091 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3092 | cbs->next = bs; | |
4f8d1dc6 | 3093 | bs->breakpoint_at = bl; |
c906108c SS |
3094 | /* If the condition is false, etc., don't do the commands. */ |
3095 | bs->commands = NULL; | |
3096 | bs->old_val = NULL; | |
3097 | bs->print_it = print_it_normal; | |
3098 | return bs; | |
3099 | } | |
3100 | \f | |
d983da9c DJ |
3101 | /* The target has stopped with waitstatus WS. Check if any hardware |
3102 | watchpoints have triggered, according to the target. */ | |
3103 | ||
3104 | int | |
3105 | watchpoints_triggered (struct target_waitstatus *ws) | |
3106 | { | |
d92524f1 | 3107 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3108 | CORE_ADDR addr; |
3109 | struct breakpoint *b; | |
3110 | ||
3111 | if (!stopped_by_watchpoint) | |
3112 | { | |
3113 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3114 | as not triggered. */ | |
3115 | ALL_BREAKPOINTS (b) | |
3116 | if (b->type == bp_hardware_watchpoint | |
3117 | || b->type == bp_read_watchpoint | |
3118 | || b->type == bp_access_watchpoint) | |
3119 | b->watchpoint_triggered = watch_triggered_no; | |
3120 | ||
3121 | return 0; | |
3122 | } | |
3123 | ||
3124 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3125 | { | |
3126 | /* We were stopped by a watchpoint, but we don't know where. | |
3127 | Mark all watchpoints as unknown. */ | |
3128 | ALL_BREAKPOINTS (b) | |
3129 | if (b->type == bp_hardware_watchpoint | |
3130 | || b->type == bp_read_watchpoint | |
3131 | || b->type == bp_access_watchpoint) | |
3132 | b->watchpoint_triggered = watch_triggered_unknown; | |
3133 | ||
3134 | return stopped_by_watchpoint; | |
3135 | } | |
3136 | ||
3137 | /* The target could report the data address. Mark watchpoints | |
3138 | affected by this data address as triggered, and all others as not | |
3139 | triggered. */ | |
3140 | ||
3141 | ALL_BREAKPOINTS (b) | |
3142 | if (b->type == bp_hardware_watchpoint | |
3143 | || b->type == bp_read_watchpoint | |
3144 | || b->type == bp_access_watchpoint) | |
3145 | { | |
a5606eee | 3146 | struct bp_location *loc; |
d983da9c DJ |
3147 | struct value *v; |
3148 | ||
3149 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3150 | for (loc = b->loc; loc; loc = loc->next) |
3151 | /* Exact match not required. Within range is | |
3152 | sufficient. */ | |
5009afc5 AS |
3153 | if (target_watchpoint_addr_within_range (¤t_target, |
3154 | addr, loc->address, | |
3155 | loc->length)) | |
a5606eee VP |
3156 | { |
3157 | b->watchpoint_triggered = watch_triggered_yes; | |
3158 | break; | |
3159 | } | |
d983da9c DJ |
3160 | } |
3161 | ||
3162 | return 1; | |
3163 | } | |
3164 | ||
c906108c SS |
3165 | /* Possible return values for watchpoint_check (this can't be an enum |
3166 | because of check_errors). */ | |
3167 | /* The watchpoint has been deleted. */ | |
3168 | #define WP_DELETED 1 | |
3169 | /* The value has changed. */ | |
3170 | #define WP_VALUE_CHANGED 2 | |
3171 | /* The value has not changed. */ | |
3172 | #define WP_VALUE_NOT_CHANGED 3 | |
3173 | ||
3174 | #define BP_TEMPFLAG 1 | |
3175 | #define BP_HARDWAREFLAG 2 | |
3176 | ||
3177 | /* Check watchpoint condition. */ | |
3178 | ||
3179 | static int | |
4efb68b1 | 3180 | watchpoint_check (void *p) |
c906108c SS |
3181 | { |
3182 | bpstat bs = (bpstat) p; | |
3183 | struct breakpoint *b; | |
3184 | struct frame_info *fr; | |
3185 | int within_current_scope; | |
3186 | ||
4f8d1dc6 | 3187 | b = bs->breakpoint_at->owner; |
c906108c | 3188 | |
f6bc2008 PA |
3189 | /* If this is a local watchpoint, we only want to check if the |
3190 | watchpoint frame is in scope if the current thread is the thread | |
3191 | that was used to create the watchpoint. */ | |
3192 | if (!watchpoint_in_thread_scope (b)) | |
3193 | return WP_VALUE_NOT_CHANGED; | |
3194 | ||
c906108c SS |
3195 | if (b->exp_valid_block == NULL) |
3196 | within_current_scope = 1; | |
3197 | else | |
3198 | { | |
edb3359d DJ |
3199 | struct frame_info *frame = get_current_frame (); |
3200 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3201 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3202 | ||
101dcfbe | 3203 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3204 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3205 | |
3206 | /* If we've gotten confused in the unwinder, we might have | |
3207 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3208 | if (within_current_scope) |
3209 | { | |
3210 | struct symbol *function; | |
3211 | ||
3212 | function = get_frame_function (fr); | |
3213 | if (function == NULL | |
3214 | || !contained_in (b->exp_valid_block, | |
3215 | SYMBOL_BLOCK_VALUE (function))) | |
3216 | within_current_scope = 0; | |
3217 | } | |
69fbadd5 | 3218 | |
c12260ac CV |
3219 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3220 | in the function but the stack frame has already been invalidated. | |
3221 | Since we can't rely on the values of local variables after the | |
3222 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
3223 | state as `not changed' without further checking. Don't mark |
3224 | watchpoints as changed if the current frame is in an epilogue - | |
3225 | even if they are in some other frame, our view of the stack | |
3226 | is likely to be wrong. */ | |
3227 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
3228 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 3229 | |
edb3359d | 3230 | if (within_current_scope) |
c906108c SS |
3231 | /* If we end up stopping, the current frame will get selected |
3232 | in normal_stop. So this call to select_frame won't affect | |
3233 | the user. */ | |
0f7d239c | 3234 | select_frame (fr); |
c906108c | 3235 | } |
c5aa993b | 3236 | |
c906108c SS |
3237 | if (within_current_scope) |
3238 | { | |
3239 | /* We use value_{,free_to_}mark because it could be a | |
3240 | *long* time before we return to the command level and | |
c5aa993b JM |
3241 | call free_all_values. We can't call free_all_values because |
3242 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3243 | |
278cd55f | 3244 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3245 | struct value *new_val; |
3246 | ||
3247 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
3248 | if ((b->val != NULL) != (new_val != NULL) | |
3249 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 3250 | { |
fa4727a6 DJ |
3251 | if (new_val != NULL) |
3252 | { | |
3253 | release_value (new_val); | |
3254 | value_free_to_mark (mark); | |
3255 | } | |
c906108c SS |
3256 | bs->old_val = b->val; |
3257 | b->val = new_val; | |
fa4727a6 | 3258 | b->val_valid = 1; |
c906108c SS |
3259 | /* We will stop here */ |
3260 | return WP_VALUE_CHANGED; | |
3261 | } | |
3262 | else | |
3263 | { | |
3264 | /* Nothing changed, don't do anything. */ | |
3265 | value_free_to_mark (mark); | |
3266 | /* We won't stop here */ | |
3267 | return WP_VALUE_NOT_CHANGED; | |
3268 | } | |
3269 | } | |
3270 | else | |
3271 | { | |
3272 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3273 | if we temporarily ignored the watchpoint, then when |
3274 | we reenter the block in which it is valid it contains | |
3275 | garbage (in the case of a function, it may have two | |
3276 | garbage values, one before and one after the prologue). | |
3277 | So we can't even detect the first assignment to it and | |
3278 | watch after that (since the garbage may or may not equal | |
3279 | the first value assigned). */ | |
4ce44c66 JM |
3280 | /* We print all the stop information in print_it_typical(), but |
3281 | in this case, by the time we call print_it_typical() this bp | |
3282 | will be deleted already. So we have no choice but print the | |
3283 | information here. */ | |
9dc5e2a9 | 3284 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3285 | ui_out_field_string |
3286 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3287 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3288 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3289 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3290 | which its expression is valid.\n"); | |
4ce44c66 | 3291 | |
c906108c | 3292 | if (b->related_breakpoint) |
b5de0fa7 EZ |
3293 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
3294 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
3295 | |
3296 | return WP_DELETED; | |
3297 | } | |
3298 | } | |
3299 | ||
18a18393 VP |
3300 | /* Return true if it looks like target has stopped due to hitting |
3301 | breakpoint location BL. This function does not check if we | |
3302 | should stop, only if BL explains the stop. */ | |
3303 | static int | |
6c95b8df PA |
3304 | bpstat_check_location (const struct bp_location *bl, |
3305 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3306 | { |
3307 | struct breakpoint *b = bl->owner; | |
3308 | ||
e8595ef6 SS |
3309 | /* By definition, the inferior does not report stops at |
3310 | tracepoints. */ | |
3311 | if (b->type == bp_tracepoint) | |
3312 | return 0; | |
3313 | ||
18a18393 VP |
3314 | if (b->type != bp_watchpoint |
3315 | && b->type != bp_hardware_watchpoint | |
3316 | && b->type != bp_read_watchpoint | |
3317 | && b->type != bp_access_watchpoint | |
3318 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3319 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3320 | { |
6c95b8df PA |
3321 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3322 | aspace, bp_addr)) | |
18a18393 VP |
3323 | return 0; |
3324 | if (overlay_debugging /* unmapped overlay section */ | |
3325 | && section_is_overlay (bl->section) | |
3326 | && !section_is_mapped (bl->section)) | |
3327 | return 0; | |
3328 | } | |
3329 | ||
3330 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3331 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3332 | some data address). Otherwise gdb won't stop on a break instruction | |
3333 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3334 | been defined. Also skip watchpoints which we know did not trigger | |
3335 | (did not match the data address). */ | |
3336 | ||
3337 | if ((b->type == bp_hardware_watchpoint | |
3338 | || b->type == bp_read_watchpoint | |
3339 | || b->type == bp_access_watchpoint) | |
3340 | && b->watchpoint_triggered == watch_triggered_no) | |
3341 | return 0; | |
3342 | ||
3343 | if (b->type == bp_hardware_breakpoint) | |
3344 | { | |
3345 | if (bl->address != bp_addr) | |
3346 | return 0; | |
3347 | if (overlay_debugging /* unmapped overlay section */ | |
3348 | && section_is_overlay (bl->section) | |
3349 | && !section_is_mapped (bl->section)) | |
3350 | return 0; | |
3351 | } | |
ce78b96d | 3352 | |
ce78b96d JB |
3353 | if (b->type == bp_catchpoint) |
3354 | { | |
3355 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3356 | if (!b->ops->breakpoint_hit (b)) | |
3357 | return 0; | |
3358 | } | |
3359 | ||
18a18393 VP |
3360 | return 1; |
3361 | } | |
3362 | ||
3363 | /* If BS refers to a watchpoint, determine if the watched values | |
3364 | has actually changed, and we should stop. If not, set BS->stop | |
3365 | to 0. */ | |
3366 | static void | |
3367 | bpstat_check_watchpoint (bpstat bs) | |
3368 | { | |
3369 | const struct bp_location *bl = bs->breakpoint_at; | |
3370 | struct breakpoint *b = bl->owner; | |
3371 | ||
3372 | if (b->type == bp_watchpoint | |
3373 | || b->type == bp_read_watchpoint | |
3374 | || b->type == bp_access_watchpoint | |
3375 | || b->type == bp_hardware_watchpoint) | |
3376 | { | |
3377 | CORE_ADDR addr; | |
3378 | struct value *v; | |
3379 | int must_check_value = 0; | |
3380 | ||
3381 | if (b->type == bp_watchpoint) | |
3382 | /* For a software watchpoint, we must always check the | |
3383 | watched value. */ | |
3384 | must_check_value = 1; | |
3385 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3386 | /* We have a hardware watchpoint (read, write, or access) | |
3387 | and the target earlier reported an address watched by | |
3388 | this watchpoint. */ | |
3389 | must_check_value = 1; | |
3390 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3391 | && b->type == bp_hardware_watchpoint) | |
3392 | /* We were stopped by a hardware watchpoint, but the target could | |
3393 | not report the data address. We must check the watchpoint's | |
3394 | value. Access and read watchpoints are out of luck; without | |
3395 | a data address, we can't figure it out. */ | |
3396 | must_check_value = 1; | |
3397 | ||
3398 | if (must_check_value) | |
3399 | { | |
3400 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3401 | b->number); | |
3402 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3403 | int e = catch_errors (watchpoint_check, bs, message, | |
3404 | RETURN_MASK_ALL); | |
3405 | do_cleanups (cleanups); | |
3406 | switch (e) | |
3407 | { | |
3408 | case WP_DELETED: | |
3409 | /* We've already printed what needs to be printed. */ | |
3410 | bs->print_it = print_it_done; | |
3411 | /* Stop. */ | |
3412 | break; | |
3413 | case WP_VALUE_CHANGED: | |
3414 | if (b->type == bp_read_watchpoint) | |
3415 | { | |
3416 | /* Don't stop: read watchpoints shouldn't fire if | |
3417 | the value has changed. This is for targets | |
3418 | which cannot set read-only watchpoints. */ | |
3419 | bs->print_it = print_it_noop; | |
3420 | bs->stop = 0; | |
3421 | } | |
3422 | break; | |
3423 | case WP_VALUE_NOT_CHANGED: | |
3424 | if (b->type == bp_hardware_watchpoint | |
3425 | || b->type == bp_watchpoint) | |
3426 | { | |
3427 | /* Don't stop: write watchpoints shouldn't fire if | |
3428 | the value hasn't changed. */ | |
3429 | bs->print_it = print_it_noop; | |
3430 | bs->stop = 0; | |
3431 | } | |
3432 | /* Stop. */ | |
3433 | break; | |
3434 | default: | |
3435 | /* Can't happen. */ | |
3436 | case 0: | |
3437 | /* Error from catch_errors. */ | |
3438 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3439 | if (b->related_breakpoint) | |
3440 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3441 | b->disposition = disp_del_at_next_stop; | |
3442 | /* We've already printed what needs to be printed. */ | |
3443 | bs->print_it = print_it_done; | |
3444 | break; | |
3445 | } | |
3446 | } | |
3447 | else /* must_check_value == 0 */ | |
3448 | { | |
3449 | /* This is a case where some watchpoint(s) triggered, but | |
3450 | not at the address of this watchpoint, or else no | |
3451 | watchpoint triggered after all. So don't print | |
3452 | anything for this watchpoint. */ | |
3453 | bs->print_it = print_it_noop; | |
3454 | bs->stop = 0; | |
3455 | } | |
3456 | } | |
3457 | } | |
3458 | ||
3459 | ||
3460 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3461 | of breakpoint referred to by BS. If we should not stop for this | |
3462 | breakpoint, set BS->stop to 0. */ | |
3463 | static void | |
3464 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3465 | { | |
3466 | int thread_id = pid_to_thread_id (ptid); | |
3467 | const struct bp_location *bl = bs->breakpoint_at; | |
3468 | struct breakpoint *b = bl->owner; | |
3469 | ||
3470 | if (frame_id_p (b->frame_id) | |
edb3359d | 3471 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3472 | bs->stop = 0; |
3473 | else if (bs->stop) | |
3474 | { | |
3475 | int value_is_zero = 0; | |
3476 | ||
3477 | /* If this is a scope breakpoint, mark the associated | |
3478 | watchpoint as triggered so that we will handle the | |
3479 | out-of-scope event. We'll get to the watchpoint next | |
3480 | iteration. */ | |
3481 | if (b->type == bp_watchpoint_scope) | |
3482 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3483 | ||
3484 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3485 | { | |
c5bc3a77 DJ |
3486 | /* We use value_mark and value_free_to_mark because it could |
3487 | be a long time before we return to the command level and | |
3488 | call free_all_values. We can't call free_all_values | |
3489 | because we might be in the middle of evaluating a | |
3490 | function call. */ | |
3491 | struct value *mark = value_mark (); | |
3492 | ||
edb3359d DJ |
3493 | /* Need to select the frame, with all that implies so that |
3494 | the conditions will have the right context. Because we | |
3495 | use the frame, we will not see an inlined function's | |
3496 | variables when we arrive at a breakpoint at the start | |
3497 | of the inlined function; the current frame will be the | |
3498 | call site. */ | |
18a18393 VP |
3499 | select_frame (get_current_frame ()); |
3500 | value_is_zero | |
3501 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3502 | "Error in testing breakpoint condition:\n", | |
3503 | RETURN_MASK_ALL); | |
3504 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3505 | value_free_to_mark (mark); |
18a18393 VP |
3506 | } |
3507 | if (bl->cond && value_is_zero) | |
3508 | { | |
3509 | bs->stop = 0; | |
3510 | } | |
3511 | else if (b->thread != -1 && b->thread != thread_id) | |
3512 | { | |
3513 | bs->stop = 0; | |
3514 | } | |
3515 | else if (b->ignore_count > 0) | |
3516 | { | |
3517 | b->ignore_count--; | |
3518 | annotate_ignore_count_change (); | |
3519 | bs->stop = 0; | |
3520 | /* Increase the hit count even though we don't | |
3521 | stop. */ | |
3522 | ++(b->hit_count); | |
3523 | } | |
3524 | } | |
3525 | } | |
3526 | ||
3527 | ||
9709f61c | 3528 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3529 | BP_ADDR in thread PTID. |
c906108c | 3530 | |
d983da9c | 3531 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3532 | don't understand this stop. Result is a chain of bpstat's such that: |
3533 | ||
c5aa993b | 3534 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3535 | |
c5aa993b | 3536 | if we understand why we stopped, the result is not null. |
c906108c | 3537 | |
c5aa993b JM |
3538 | Each element of the chain refers to a particular breakpoint or |
3539 | watchpoint at which we have stopped. (We may have stopped for | |
3540 | several reasons concurrently.) | |
c906108c | 3541 | |
c5aa993b JM |
3542 | Each element of the chain has valid next, breakpoint_at, |
3543 | commands, FIXME??? fields. */ | |
c906108c SS |
3544 | |
3545 | bpstat | |
6c95b8df PA |
3546 | bpstat_stop_status (struct address_space *aspace, |
3547 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 3548 | { |
0d381245 | 3549 | struct breakpoint *b = NULL; |
876fa593 | 3550 | struct bp_location *bl, **blp_tmp; |
20874c92 | 3551 | struct bp_location *loc; |
c906108c SS |
3552 | /* Root of the chain of bpstat's */ |
3553 | struct bpstats root_bs[1]; | |
3554 | /* Pointer to the last thing in the chain currently. */ | |
3555 | bpstat bs = root_bs; | |
20874c92 | 3556 | int ix; |
876fa593 | 3557 | int need_remove_insert, update_locations = 0; |
c906108c | 3558 | |
876fa593 | 3559 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3560 | { |
0d381245 VP |
3561 | b = bl->owner; |
3562 | gdb_assert (b); | |
468d015d | 3563 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
3564 | continue; |
3565 | ||
a5606eee VP |
3566 | /* For hardware watchpoints, we look only at the first location. |
3567 | The watchpoint_check function will work on entire expression, | |
3568 | not the individual locations. For read watchopints, the | |
3569 | watchpoints_triggered function have checked all locations | |
3d947dff | 3570 | already. */ |
a5606eee VP |
3571 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
3572 | continue; | |
3573 | ||
6c95b8df | 3574 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
18a18393 VP |
3575 | continue; |
3576 | ||
c5aa993b JM |
3577 | /* Come here if it's a watchpoint, or if the break address matches */ |
3578 | ||
0d381245 | 3579 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3580 | |
18a18393 VP |
3581 | /* Assume we stop. Should we find watchpoint that is not actually |
3582 | triggered, or if condition of breakpoint is false, we'll reset | |
3583 | 'stop' to 0. */ | |
c5aa993b JM |
3584 | bs->stop = 1; |
3585 | bs->print = 1; | |
3586 | ||
18a18393 VP |
3587 | bpstat_check_watchpoint (bs); |
3588 | if (!bs->stop) | |
3589 | continue; | |
c5aa993b | 3590 | |
0fd8e87f UW |
3591 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3592 | || b->type == bp_longjmp_master) | |
18a18393 | 3593 | /* We do not stop for these. */ |
c5aa993b JM |
3594 | bs->stop = 0; |
3595 | else | |
18a18393 VP |
3596 | bpstat_check_breakpoint_conditions (bs, ptid); |
3597 | ||
3598 | if (bs->stop) | |
c5aa993b | 3599 | { |
876fa593 JK |
3600 | if (b->enable_state != bp_disabled) |
3601 | ++(b->hit_count); | |
d983da9c | 3602 | |
18a18393 VP |
3603 | /* We will stop here */ |
3604 | if (b->disposition == disp_disable) | |
c5aa993b | 3605 | { |
514f746b AR |
3606 | if (b->enable_state != bp_permanent) |
3607 | b->enable_state = bp_disabled; | |
876fa593 | 3608 | update_locations = 1; |
c5aa993b | 3609 | } |
18a18393 VP |
3610 | if (b->silent) |
3611 | bs->print = 0; | |
3612 | bs->commands = b->commands; | |
059fb39f PM |
3613 | if (bs->commands |
3614 | && (strcmp ("silent", bs->commands->line) == 0 | |
3615 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3616 | { |
18a18393 VP |
3617 | bs->commands = bs->commands->next; |
3618 | bs->print = 0; | |
c5aa993b | 3619 | } |
18a18393 | 3620 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3621 | } |
18a18393 | 3622 | |
c5aa993b JM |
3623 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3624 | if (bs->stop == 0 || bs->print == 0) | |
3625 | bs->print_it = print_it_noop; | |
3626 | } | |
c906108c | 3627 | |
876fa593 JK |
3628 | /* Delay this call which would break the ALL_BP_LOCATIONS iteration above. */ |
3629 | if (update_locations) | |
3630 | update_global_location_list (0); | |
3631 | ||
20874c92 VP |
3632 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3633 | { | |
6c95b8df PA |
3634 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
3635 | aspace, bp_addr)) | |
20874c92 VP |
3636 | { |
3637 | bs = bpstat_alloc (loc, bs); | |
3638 | /* For hits of moribund locations, we should just proceed. */ | |
3639 | bs->stop = 0; | |
3640 | bs->print = 0; | |
3641 | bs->print_it = print_it_noop; | |
3642 | } | |
3643 | } | |
3644 | ||
c906108c SS |
3645 | bs->next = NULL; /* Terminate the chain */ |
3646 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3647 | ||
d983da9c DJ |
3648 | /* If we aren't stopping, the value of some hardware watchpoint may |
3649 | not have changed, but the intermediate memory locations we are | |
3650 | watching may have. Don't bother if we're stopping; this will get | |
3651 | done later. */ | |
3652 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3653 | if (bs->stop) | |
3654 | break; | |
3655 | ||
d832cb68 | 3656 | need_remove_insert = 0; |
d983da9c DJ |
3657 | if (bs == NULL) |
3658 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3659 | if (!bs->stop | |
20874c92 | 3660 | && bs->breakpoint_at->owner |
2d134ed3 | 3661 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 3662 | { |
2d134ed3 PA |
3663 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
3664 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
3665 | Prevent further code from trying to use it. */ | |
a5606eee | 3666 | bs->breakpoint_at = NULL; |
d832cb68 | 3667 | need_remove_insert = 1; |
d983da9c DJ |
3668 | } |
3669 | ||
d832cb68 | 3670 | if (need_remove_insert) |
2d134ed3 | 3671 | update_global_location_list (1); |
d832cb68 | 3672 | |
d983da9c | 3673 | return root_bs->next; |
c906108c SS |
3674 | } |
3675 | \f | |
3676 | /* Tell what to do about this bpstat. */ | |
3677 | struct bpstat_what | |
fba45db2 | 3678 | bpstat_what (bpstat bs) |
c906108c SS |
3679 | { |
3680 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3681 | enum class |
3682 | { | |
3683 | /* This bpstat element has no effect on the main_action. */ | |
3684 | no_effect = 0, | |
3685 | ||
3686 | /* There was a watchpoint, stop but don't print. */ | |
3687 | wp_silent, | |
c906108c | 3688 | |
c5aa993b JM |
3689 | /* There was a watchpoint, stop and print. */ |
3690 | wp_noisy, | |
c906108c | 3691 | |
c5aa993b JM |
3692 | /* There was a breakpoint but we're not stopping. */ |
3693 | bp_nostop, | |
c906108c | 3694 | |
c5aa993b JM |
3695 | /* There was a breakpoint, stop but don't print. */ |
3696 | bp_silent, | |
c906108c | 3697 | |
c5aa993b JM |
3698 | /* There was a breakpoint, stop and print. */ |
3699 | bp_noisy, | |
c906108c | 3700 | |
c5aa993b JM |
3701 | /* We hit the longjmp breakpoint. */ |
3702 | long_jump, | |
c906108c | 3703 | |
c5aa993b JM |
3704 | /* We hit the longjmp_resume breakpoint. */ |
3705 | long_resume, | |
c906108c | 3706 | |
c5aa993b JM |
3707 | /* We hit the step_resume breakpoint. */ |
3708 | step_resume, | |
c906108c | 3709 | |
c5aa993b JM |
3710 | /* We hit the shared library event breakpoint. */ |
3711 | shlib_event, | |
c906108c | 3712 | |
4efc6507 DE |
3713 | /* We hit the jit event breakpoint. */ |
3714 | jit_event, | |
3715 | ||
c5aa993b JM |
3716 | /* This is just used to count how many enums there are. */ |
3717 | class_last | |
c906108c SS |
3718 | }; |
3719 | ||
3720 | /* Here is the table which drives this routine. So that we can | |
3721 | format it pretty, we define some abbreviations for the | |
3722 | enum bpstat_what codes. */ | |
3723 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3724 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3725 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3726 | #define sgl BPSTAT_WHAT_SINGLE | |
3727 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3728 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3729 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3730 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 3731 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
3732 | |
3733 | /* "Can't happen." Might want to print an error message. | |
3734 | abort() is not out of the question, but chances are GDB is just | |
3735 | a bit confused, not unusable. */ | |
3736 | #define err BPSTAT_WHAT_STOP_NOISY | |
3737 | ||
3738 | /* Given an old action and a class, come up with a new action. */ | |
3739 | /* One interesting property of this table is that wp_silent is the same | |
3740 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3741 | after stopping, the check for whether to step over a breakpoint | |
3742 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3743 | reference to how we stopped. We retain separate wp_silent and |
3744 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3745 | |
3746 | Another possibly interesting property of this table is that | |
3747 | there's a partial ordering, priority-like, of the actions. Once | |
3748 | you've decided that some action is appropriate, you'll never go | |
3749 | back and decide something of a lower priority is better. The | |
3750 | ordering is: | |
3751 | ||
4efc6507 DE |
3752 | kc < jit clr sgl shl slr sn sr ss |
3753 | sgl < jit shl slr sn sr ss | |
3754 | slr < jit err shl sn sr ss | |
3755 | clr < jit err shl sn sr ss | |
3756 | ss < jit shl sn sr | |
3757 | sn < jit shl sr | |
3758 | jit < shl sr | |
d81191fc | 3759 | shl < sr |
4d5b2cd7 | 3760 | sr < |
c5aa993b | 3761 | |
43ff13b4 JM |
3762 | What I think this means is that we don't need a damned table |
3763 | here. If you just put the rows and columns in the right order, | |
3764 | it'd look awfully regular. We could simply walk the bpstat list | |
3765 | and choose the highest priority action we find, with a little | |
78b6a731 | 3766 | logic to handle the 'err' cases. */ |
c906108c SS |
3767 | |
3768 | /* step_resume entries: a step resume breakpoint overrides another | |
3769 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3770 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3771 | |
3772 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3773 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3774 | { | |
3775 | /* old action */ | |
4efc6507 DE |
3776 | /* kc ss sn sgl slr clr sr shl jit */ |
3777 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
3778 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3779 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3780 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
3781 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3782 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3783 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
3784 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
3785 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
3786 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
3787 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 3788 | }; |
c906108c SS |
3789 | |
3790 | #undef kc | |
3791 | #undef ss | |
3792 | #undef sn | |
3793 | #undef sgl | |
3794 | #undef slr | |
3795 | #undef clr | |
c906108c SS |
3796 | #undef err |
3797 | #undef sr | |
3798 | #undef ts | |
3799 | #undef shl | |
4efc6507 | 3800 | #undef jit |
c906108c SS |
3801 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3802 | struct bpstat_what retval; | |
3803 | ||
3804 | retval.call_dummy = 0; | |
3805 | for (; bs != NULL; bs = bs->next) | |
3806 | { | |
3807 | enum class bs_class = no_effect; | |
3808 | if (bs->breakpoint_at == NULL) | |
3809 | /* I suspect this can happen if it was a momentary breakpoint | |
3810 | which has since been deleted. */ | |
3811 | continue; | |
20874c92 VP |
3812 | if (bs->breakpoint_at->owner == NULL) |
3813 | bs_class = bp_nostop; | |
3814 | else | |
4f8d1dc6 | 3815 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3816 | { |
3817 | case bp_none: | |
3818 | continue; | |
3819 | ||
3820 | case bp_breakpoint: | |
3821 | case bp_hardware_breakpoint: | |
3822 | case bp_until: | |
3823 | case bp_finish: | |
3824 | if (bs->stop) | |
3825 | { | |
3826 | if (bs->print) | |
3827 | bs_class = bp_noisy; | |
3828 | else | |
3829 | bs_class = bp_silent; | |
3830 | } | |
3831 | else | |
3832 | bs_class = bp_nostop; | |
3833 | break; | |
3834 | case bp_watchpoint: | |
3835 | case bp_hardware_watchpoint: | |
3836 | case bp_read_watchpoint: | |
3837 | case bp_access_watchpoint: | |
3838 | if (bs->stop) | |
3839 | { | |
3840 | if (bs->print) | |
3841 | bs_class = wp_noisy; | |
3842 | else | |
3843 | bs_class = wp_silent; | |
3844 | } | |
3845 | else | |
53a5351d JM |
3846 | /* There was a watchpoint, but we're not stopping. |
3847 | This requires no further action. */ | |
c906108c SS |
3848 | bs_class = no_effect; |
3849 | break; | |
3850 | case bp_longjmp: | |
3851 | bs_class = long_jump; | |
3852 | break; | |
3853 | case bp_longjmp_resume: | |
3854 | bs_class = long_resume; | |
3855 | break; | |
3856 | case bp_step_resume: | |
3857 | if (bs->stop) | |
3858 | { | |
3859 | bs_class = step_resume; | |
3860 | } | |
3861 | else | |
3862 | /* It is for the wrong frame. */ | |
3863 | bs_class = bp_nostop; | |
3864 | break; | |
c906108c SS |
3865 | case bp_watchpoint_scope: |
3866 | bs_class = bp_nostop; | |
3867 | break; | |
c5aa993b JM |
3868 | case bp_shlib_event: |
3869 | bs_class = shlib_event; | |
3870 | break; | |
4efc6507 DE |
3871 | case bp_jit_event: |
3872 | bs_class = jit_event; | |
3873 | break; | |
c4093a6a | 3874 | case bp_thread_event: |
1900040c | 3875 | case bp_overlay_event: |
0fd8e87f | 3876 | case bp_longjmp_master: |
c4093a6a JM |
3877 | bs_class = bp_nostop; |
3878 | break; | |
ce78b96d | 3879 | case bp_catchpoint: |
c5aa993b JM |
3880 | if (bs->stop) |
3881 | { | |
3882 | if (bs->print) | |
3883 | bs_class = bp_noisy; | |
3884 | else | |
3885 | bs_class = bp_silent; | |
3886 | } | |
3887 | else | |
53a5351d JM |
3888 | /* There was a catchpoint, but we're not stopping. |
3889 | This requires no further action. */ | |
c5aa993b JM |
3890 | bs_class = no_effect; |
3891 | break; | |
c906108c | 3892 | case bp_call_dummy: |
53a5351d JM |
3893 | /* Make sure the action is stop (silent or noisy), |
3894 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3895 | bs_class = bp_silent; |
3896 | retval.call_dummy = 1; | |
3897 | break; | |
1042e4c0 SS |
3898 | case bp_tracepoint: |
3899 | /* Tracepoint hits should not be reported back to GDB, and | |
3900 | if one got through somehow, it should have been filtered | |
3901 | out already. */ | |
3902 | internal_error (__FILE__, __LINE__, | |
3903 | _("bpstat_what: bp_tracepoint encountered")); | |
3904 | break; | |
c906108c | 3905 | } |
c5aa993b | 3906 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3907 | } |
3908 | retval.main_action = current_action; | |
3909 | return retval; | |
3910 | } | |
3911 | ||
3912 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3913 | without hardware support). This isn't related to a specific bpstat, | |
3914 | just to things like whether watchpoints are set. */ | |
3915 | ||
c5aa993b | 3916 | int |
fba45db2 | 3917 | bpstat_should_step (void) |
c906108c SS |
3918 | { |
3919 | struct breakpoint *b; | |
3920 | ALL_BREAKPOINTS (b) | |
717a8278 | 3921 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3922 | return 1; |
c906108c SS |
3923 | return 0; |
3924 | } | |
3925 | ||
67822962 PA |
3926 | int |
3927 | bpstat_causes_stop (bpstat bs) | |
3928 | { | |
3929 | for (; bs != NULL; bs = bs->next) | |
3930 | if (bs->stop) | |
3931 | return 1; | |
3932 | ||
3933 | return 0; | |
3934 | } | |
3935 | ||
c906108c | 3936 | \f |
c5aa993b | 3937 | |
0d381245 VP |
3938 | static void print_breakpoint_location (struct breakpoint *b, |
3939 | struct bp_location *loc, | |
3940 | char *wrap_indent, | |
3941 | struct ui_stream *stb) | |
3942 | { | |
6c95b8df PA |
3943 | struct cleanup *old_chain = save_current_program_space (); |
3944 | ||
3945 | if (loc != NULL) | |
3946 | set_current_program_space (loc->pspace); | |
3947 | ||
0d381245 VP |
3948 | if (b->source_file) |
3949 | { | |
3950 | struct symbol *sym | |
3951 | = find_pc_sect_function (loc->address, loc->section); | |
3952 | if (sym) | |
3953 | { | |
3954 | ui_out_text (uiout, "in "); | |
3955 | ui_out_field_string (uiout, "func", | |
3956 | SYMBOL_PRINT_NAME (sym)); | |
3957 | ui_out_wrap_hint (uiout, wrap_indent); | |
3958 | ui_out_text (uiout, " at "); | |
3959 | } | |
3960 | ui_out_field_string (uiout, "file", b->source_file); | |
3961 | ui_out_text (uiout, ":"); | |
3962 | ||
3963 | if (ui_out_is_mi_like_p (uiout)) | |
3964 | { | |
3965 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3966 | char *fullname = symtab_to_fullname (sal.symtab); | |
3967 | ||
3968 | if (fullname) | |
3969 | ui_out_field_string (uiout, "fullname", fullname); | |
3970 | } | |
3971 | ||
3972 | ui_out_field_int (uiout, "line", b->line_number); | |
3973 | } | |
3974 | else if (!b->loc) | |
3975 | { | |
3976 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3977 | } | |
3978 | else | |
3979 | { | |
3980 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3981 | ui_out_field_stream (uiout, "at", stb); | |
3982 | } | |
6c95b8df PA |
3983 | |
3984 | do_cleanups (old_chain); | |
0d381245 VP |
3985 | } |
3986 | ||
c4093a6a | 3987 | /* Print B to gdb_stdout. */ |
c906108c | 3988 | static void |
0d381245 VP |
3989 | print_one_breakpoint_location (struct breakpoint *b, |
3990 | struct bp_location *loc, | |
3991 | int loc_number, | |
a6d9a66e | 3992 | struct bp_location **last_loc, |
6c95b8df PA |
3993 | int print_address_bits, |
3994 | int allflag) | |
c906108c | 3995 | { |
52f0bd74 AC |
3996 | struct command_line *l; |
3997 | struct symbol *sym; | |
c4093a6a JM |
3998 | struct ep_type_description |
3999 | { | |
4000 | enum bptype type; | |
4001 | char *description; | |
4002 | }; | |
4003 | static struct ep_type_description bptypes[] = | |
c906108c | 4004 | { |
c5aa993b JM |
4005 | {bp_none, "?deleted?"}, |
4006 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4007 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4008 | {bp_until, "until"}, |
4009 | {bp_finish, "finish"}, | |
4010 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4011 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4012 | {bp_read_watchpoint, "read watchpoint"}, |
4013 | {bp_access_watchpoint, "acc watchpoint"}, | |
4014 | {bp_longjmp, "longjmp"}, | |
4015 | {bp_longjmp_resume, "longjmp resume"}, | |
4016 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4017 | {bp_watchpoint_scope, "watchpoint scope"}, |
4018 | {bp_call_dummy, "call dummy"}, | |
4019 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 4020 | {bp_thread_event, "thread events"}, |
1900040c | 4021 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4022 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 4023 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4024 | {bp_tracepoint, "tracepoint"}, |
4efc6507 | 4025 | {bp_jit_event, "jit events"}, |
c5aa993b | 4026 | }; |
c4093a6a | 4027 | |
c2c6d25f | 4028 | static char bpenables[] = "nynny"; |
c906108c | 4029 | char wrap_indent[80]; |
8b93c638 JM |
4030 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4031 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4032 | struct cleanup *bkpt_chain; |
c906108c | 4033 | |
0d381245 VP |
4034 | int header_of_multiple = 0; |
4035 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4036 | struct value_print_options opts; |
4037 | ||
4038 | get_user_print_options (&opts); | |
0d381245 VP |
4039 | |
4040 | gdb_assert (!loc || loc_number != 0); | |
4041 | /* See comment in print_one_breakpoint concerning | |
4042 | treatment of breakpoints with single disabled | |
4043 | location. */ | |
4044 | if (loc == NULL | |
4045 | && (b->loc != NULL | |
4046 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4047 | header_of_multiple = 1; | |
4048 | if (loc == NULL) | |
4049 | loc = b->loc; | |
4050 | ||
c4093a6a | 4051 | annotate_record (); |
3b31d625 | 4052 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4053 | |
4054 | /* 1 */ | |
4055 | annotate_field (0); | |
0d381245 VP |
4056 | if (part_of_multiple) |
4057 | { | |
4058 | char *formatted; | |
0c6773c1 | 4059 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4060 | ui_out_field_string (uiout, "number", formatted); |
4061 | xfree (formatted); | |
4062 | } | |
4063 | else | |
4064 | { | |
4065 | ui_out_field_int (uiout, "number", b->number); | |
4066 | } | |
c4093a6a JM |
4067 | |
4068 | /* 2 */ | |
4069 | annotate_field (1); | |
0d381245 VP |
4070 | if (part_of_multiple) |
4071 | ui_out_field_skip (uiout, "type"); | |
4072 | else | |
4073 | { | |
4074 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4075 | || ((int) b->type != bptypes[(int) b->type].type)) | |
4076 | internal_error (__FILE__, __LINE__, | |
4077 | _("bptypes table does not describe type #%d."), | |
4078 | (int) b->type); | |
4079 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
4080 | } | |
c4093a6a JM |
4081 | |
4082 | /* 3 */ | |
4083 | annotate_field (2); | |
0d381245 VP |
4084 | if (part_of_multiple) |
4085 | ui_out_field_skip (uiout, "disp"); | |
4086 | else | |
2cec12e5 | 4087 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4088 | |
c4093a6a JM |
4089 | |
4090 | /* 4 */ | |
4091 | annotate_field (3); | |
0d381245 | 4092 | if (part_of_multiple) |
54e52265 | 4093 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4094 | else |
54e52265 VP |
4095 | ui_out_field_fmt (uiout, "enabled", "%c", |
4096 | bpenables[(int) b->enable_state]); | |
4097 | ui_out_spaces (uiout, 2); | |
0d381245 | 4098 | |
c4093a6a JM |
4099 | |
4100 | /* 5 and 6 */ | |
4101 | strcpy (wrap_indent, " "); | |
79a45b7d | 4102 | if (opts.addressprint) |
75ac9d7b | 4103 | { |
a6d9a66e | 4104 | if (print_address_bits <= 32) |
75ac9d7b MS |
4105 | strcat (wrap_indent, " "); |
4106 | else | |
4107 | strcat (wrap_indent, " "); | |
4108 | } | |
c906108c | 4109 | |
3086aeae | 4110 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4111 | { |
4112 | /* Although the print_one can possibly print | |
4113 | all locations, calling it here is not likely | |
4114 | to get any nice result. So, make sure there's | |
4115 | just one location. */ | |
4116 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4117 | b->ops->print_one (b, last_loc); |
0d381245 | 4118 | } |
3086aeae DJ |
4119 | else |
4120 | switch (b->type) | |
4121 | { | |
4122 | case bp_none: | |
4123 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4124 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4125 | break; |
c906108c | 4126 | |
3086aeae DJ |
4127 | case bp_watchpoint: |
4128 | case bp_hardware_watchpoint: | |
4129 | case bp_read_watchpoint: | |
4130 | case bp_access_watchpoint: | |
4131 | /* Field 4, the address, is omitted (which makes the columns | |
4132 | not line up too nicely with the headers, but the effect | |
4133 | is relatively readable). */ | |
79a45b7d | 4134 | if (opts.addressprint) |
3086aeae DJ |
4135 | ui_out_field_skip (uiout, "addr"); |
4136 | annotate_field (5); | |
fa8a61dc | 4137 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4138 | break; |
4139 | ||
3086aeae DJ |
4140 | case bp_breakpoint: |
4141 | case bp_hardware_breakpoint: | |
4142 | case bp_until: | |
4143 | case bp_finish: | |
4144 | case bp_longjmp: | |
4145 | case bp_longjmp_resume: | |
4146 | case bp_step_resume: | |
3086aeae DJ |
4147 | case bp_watchpoint_scope: |
4148 | case bp_call_dummy: | |
4149 | case bp_shlib_event: | |
4150 | case bp_thread_event: | |
4151 | case bp_overlay_event: | |
0fd8e87f | 4152 | case bp_longjmp_master: |
1042e4c0 | 4153 | case bp_tracepoint: |
4efc6507 | 4154 | case bp_jit_event: |
79a45b7d | 4155 | if (opts.addressprint) |
3086aeae DJ |
4156 | { |
4157 | annotate_field (4); | |
54e52265 | 4158 | if (header_of_multiple) |
0d381245 | 4159 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4160 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4161 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4162 | else |
5af949e3 UW |
4163 | ui_out_field_core_addr (uiout, "addr", |
4164 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4165 | } |
4166 | annotate_field (5); | |
0d381245 VP |
4167 | if (!header_of_multiple) |
4168 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4169 | if (b->loc) | |
a6d9a66e | 4170 | *last_loc = b->loc; |
3086aeae DJ |
4171 | break; |
4172 | } | |
c906108c | 4173 | |
6c95b8df PA |
4174 | |
4175 | /* For backward compatibility, don't display inferiors unless there | |
4176 | are several. */ | |
4177 | if (loc != NULL | |
4178 | && !header_of_multiple | |
4179 | && (allflag | |
4180 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4181 | && (number_of_program_spaces () > 1 | |
4182 | || number_of_inferiors () > 1) | |
4183 | && loc->owner->type != bp_catchpoint))) | |
4184 | { | |
4185 | struct inferior *inf; | |
4186 | int first = 1; | |
4187 | ||
4188 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4189 | { | |
4190 | if (inf->pspace == loc->pspace) | |
4191 | { | |
4192 | if (first) | |
4193 | { | |
4194 | first = 0; | |
4195 | ui_out_text (uiout, " inf "); | |
4196 | } | |
4197 | else | |
4198 | ui_out_text (uiout, ", "); | |
4199 | ui_out_text (uiout, plongest (inf->num)); | |
4200 | } | |
4201 | } | |
4202 | } | |
4203 | ||
4a306c9a | 4204 | if (!part_of_multiple) |
c4093a6a | 4205 | { |
4a306c9a JB |
4206 | if (b->thread != -1) |
4207 | { | |
4208 | /* FIXME: This seems to be redundant and lost here; see the | |
4209 | "stop only in" line a little further down. */ | |
4210 | ui_out_text (uiout, " thread "); | |
4211 | ui_out_field_int (uiout, "thread", b->thread); | |
4212 | } | |
4213 | else if (b->task != 0) | |
4214 | { | |
4215 | ui_out_text (uiout, " task "); | |
4216 | ui_out_field_int (uiout, "task", b->task); | |
4217 | } | |
c4093a6a JM |
4218 | } |
4219 | ||
8b93c638 | 4220 | ui_out_text (uiout, "\n"); |
c4093a6a | 4221 | |
0d381245 | 4222 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4223 | { |
4224 | annotate_field (6); | |
8b93c638 | 4225 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4226 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4227 | the frame ID. */ | |
5af949e3 UW |
4228 | ui_out_field_core_addr (uiout, "frame", |
4229 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4230 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4231 | } |
4232 | ||
0d381245 | 4233 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4234 | { |
f7f9143b JB |
4235 | /* We do not print the condition for Ada exception catchpoints |
4236 | because the condition is an internal implementation detail | |
4237 | that we do not want to expose to the user. */ | |
c4093a6a | 4238 | annotate_field (7); |
1042e4c0 SS |
4239 | if (b->type == bp_tracepoint) |
4240 | ui_out_text (uiout, "\ttrace only if "); | |
4241 | else | |
4242 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4243 | ui_out_field_string (uiout, "cond", b->cond_string); |
4244 | ui_out_text (uiout, "\n"); | |
4245 | } | |
4246 | ||
0d381245 | 4247 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4248 | { |
4249 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4250 | ui_out_text (uiout, "\tstop only in thread "); |
4251 | ui_out_field_int (uiout, "thread", b->thread); | |
4252 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4253 | } |
4254 | ||
63c715c6 | 4255 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4256 | { |
4257 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4258 | if (ep_is_catchpoint (b)) |
4259 | ui_out_text (uiout, "\tcatchpoint"); | |
4260 | else | |
4261 | ui_out_text (uiout, "\tbreakpoint"); | |
4262 | ui_out_text (uiout, " already hit "); | |
4263 | ui_out_field_int (uiout, "times", b->hit_count); | |
4264 | if (b->hit_count == 1) | |
4265 | ui_out_text (uiout, " time\n"); | |
4266 | else | |
4267 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4268 | } |
4269 | ||
fb40c209 AC |
4270 | /* Output the count also if it is zero, but only if this is |
4271 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4272 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4273 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4274 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4275 | |
0d381245 | 4276 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4277 | { |
4278 | annotate_field (8); | |
8b93c638 JM |
4279 | ui_out_text (uiout, "\tignore next "); |
4280 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4281 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4282 | } |
059fb39f PM |
4283 | |
4284 | l = b->commands; | |
4285 | if (!part_of_multiple && l) | |
c4093a6a | 4286 | { |
3b31d625 EZ |
4287 | struct cleanup *script_chain; |
4288 | ||
c4093a6a | 4289 | annotate_field (9); |
3b31d625 | 4290 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4291 | print_command_lines (uiout, l, 4); |
3b31d625 | 4292 | do_cleanups (script_chain); |
c4093a6a | 4293 | } |
d24317b4 | 4294 | |
1042e4c0 SS |
4295 | if (!part_of_multiple && b->pass_count) |
4296 | { | |
4297 | annotate_field (10); | |
4298 | ui_out_text (uiout, "\tpass count "); | |
4299 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4300 | ui_out_text (uiout, " \n"); | |
4301 | } | |
4302 | ||
4303 | if (!part_of_multiple && b->step_count) | |
4304 | { | |
4305 | annotate_field (11); | |
4306 | ui_out_text (uiout, "\tstep count "); | |
4307 | ui_out_field_int (uiout, "step", b->step_count); | |
4308 | ui_out_text (uiout, " \n"); | |
4309 | } | |
4310 | ||
4311 | if (!part_of_multiple && b->actions) | |
4312 | { | |
4313 | struct action_line *action; | |
4314 | annotate_field (12); | |
4315 | for (action = b->actions; action; action = action->next) | |
4316 | { | |
4317 | ui_out_text (uiout, " A\t"); | |
4318 | ui_out_text (uiout, action->action); | |
4319 | ui_out_text (uiout, "\n"); | |
4320 | } | |
4321 | } | |
4322 | ||
d24317b4 VP |
4323 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4324 | { | |
4325 | if (b->addr_string) | |
4326 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4327 | else if (b->exp_string) | |
4328 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4329 | } | |
4330 | ||
3b31d625 | 4331 | do_cleanups (bkpt_chain); |
8b93c638 | 4332 | do_cleanups (old_chain); |
c4093a6a | 4333 | } |
c5aa993b | 4334 | |
0d381245 VP |
4335 | static void |
4336 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4337 | struct bp_location **last_loc, int print_address_bits, |
4338 | int allflag) | |
0d381245 | 4339 | { |
6c95b8df PA |
4340 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4341 | print_address_bits, allflag); | |
0d381245 VP |
4342 | |
4343 | /* If this breakpoint has custom print function, | |
4344 | it's already printed. Otherwise, print individual | |
4345 | locations, if any. */ | |
4346 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4347 | { | |
4348 | /* If breakpoint has a single location that is | |
4349 | disabled, we print it as if it had | |
4350 | several locations, since otherwise it's hard to | |
4351 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4352 | situation. |
4353 | Note that while hardware watchpoints have | |
4354 | several locations internally, that's no a property | |
4355 | exposed to user. */ | |
0d381245 | 4356 | if (b->loc |
a5606eee | 4357 | && !is_hardware_watchpoint (b) |
0d381245 | 4358 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4359 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4360 | { |
4361 | struct bp_location *loc; | |
4362 | int n = 1; | |
4363 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4364 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4365 | print_address_bits, allflag); |
0d381245 VP |
4366 | } |
4367 | } | |
4368 | } | |
4369 | ||
a6d9a66e UW |
4370 | static int |
4371 | breakpoint_address_bits (struct breakpoint *b) | |
4372 | { | |
4373 | int print_address_bits = 0; | |
4374 | struct bp_location *loc; | |
4375 | ||
4376 | for (loc = b->loc; loc; loc = loc->next) | |
4377 | { | |
c561c276 | 4378 | int addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
4379 | if (addr_bit > print_address_bits) |
4380 | print_address_bits = addr_bit; | |
4381 | } | |
4382 | ||
4383 | return print_address_bits; | |
4384 | } | |
0d381245 | 4385 | |
c4093a6a JM |
4386 | struct captured_breakpoint_query_args |
4387 | { | |
4388 | int bnum; | |
4389 | }; | |
c5aa993b | 4390 | |
c4093a6a | 4391 | static int |
2b65245e | 4392 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4393 | { |
4394 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4395 | struct breakpoint *b; |
a6d9a66e | 4396 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4397 | ALL_BREAKPOINTS (b) |
4398 | { | |
4399 | if (args->bnum == b->number) | |
c5aa993b | 4400 | { |
a6d9a66e | 4401 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4402 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4403 | return GDB_RC_OK; |
c5aa993b | 4404 | } |
c4093a6a JM |
4405 | } |
4406 | return GDB_RC_NONE; | |
4407 | } | |
c5aa993b | 4408 | |
c4093a6a | 4409 | enum gdb_rc |
ce43223b | 4410 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4411 | { |
4412 | struct captured_breakpoint_query_args args; | |
4413 | args.bnum = bnum; | |
4414 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4415 | an error. */ | |
b0b13bb4 DJ |
4416 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4417 | error_message, RETURN_MASK_ALL) < 0) | |
4418 | return GDB_RC_FAIL; | |
4419 | else | |
4420 | return GDB_RC_OK; | |
c4093a6a | 4421 | } |
c5aa993b | 4422 | |
7f3b0473 AC |
4423 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4424 | catchpoints, et.al.). */ | |
4425 | ||
4426 | static int | |
4427 | user_settable_breakpoint (const struct breakpoint *b) | |
4428 | { | |
4429 | return (b->type == bp_breakpoint | |
ce78b96d | 4430 | || b->type == bp_catchpoint |
7f3b0473 | 4431 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 4432 | || b->type == bp_tracepoint |
7f3b0473 AC |
4433 | || b->type == bp_watchpoint |
4434 | || b->type == bp_read_watchpoint | |
4435 | || b->type == bp_access_watchpoint | |
4436 | || b->type == bp_hardware_watchpoint); | |
4437 | } | |
4438 | ||
4439 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4440 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4441 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4442 | |
c4093a6a | 4443 | static void |
fba45db2 | 4444 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4445 | { |
52f0bd74 | 4446 | struct breakpoint *b; |
a6d9a66e | 4447 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4448 | int nr_printable_breakpoints; |
3b31d625 | 4449 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4450 | struct value_print_options opts; |
a6d9a66e | 4451 | int print_address_bits = 0; |
c4093a6a | 4452 | |
79a45b7d TT |
4453 | get_user_print_options (&opts); |
4454 | ||
a6d9a66e UW |
4455 | /* Compute the number of rows in the table, as well as the |
4456 | size required for address fields. */ | |
7f3b0473 AC |
4457 | nr_printable_breakpoints = 0; |
4458 | ALL_BREAKPOINTS (b) | |
4459 | if (bnum == -1 | |
4460 | || bnum == b->number) | |
4461 | { | |
4462 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4463 | { |
4464 | int addr_bit = breakpoint_address_bits (b); | |
4465 | if (addr_bit > print_address_bits) | |
4466 | print_address_bits = addr_bit; | |
4467 | ||
4468 | nr_printable_breakpoints++; | |
4469 | } | |
7f3b0473 AC |
4470 | } |
4471 | ||
79a45b7d | 4472 | if (opts.addressprint) |
3b31d625 EZ |
4473 | bkpttbl_chain |
4474 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4475 | "BreakpointTable"); | |
8b93c638 | 4476 | else |
3b31d625 EZ |
4477 | bkpttbl_chain |
4478 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4479 | "BreakpointTable"); | |
8b93c638 | 4480 | |
7f3b0473 | 4481 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4482 | annotate_breakpoints_headers (); |
4483 | if (nr_printable_breakpoints > 0) | |
4484 | annotate_field (0); | |
0d381245 | 4485 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4486 | if (nr_printable_breakpoints > 0) |
4487 | annotate_field (1); | |
4488 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4489 | if (nr_printable_breakpoints > 0) | |
4490 | annotate_field (2); | |
4491 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4492 | if (nr_printable_breakpoints > 0) | |
4493 | annotate_field (3); | |
54e52265 | 4494 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4495 | if (opts.addressprint) |
7f3b0473 | 4496 | { |
d7faa9e7 AC |
4497 | if (nr_printable_breakpoints > 0) |
4498 | annotate_field (4); | |
a6d9a66e | 4499 | if (print_address_bits <= 32) |
b25959ec | 4500 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4501 | else |
b25959ec | 4502 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4503 | } |
d7faa9e7 AC |
4504 | if (nr_printable_breakpoints > 0) |
4505 | annotate_field (5); | |
4506 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4507 | ui_out_table_body (uiout); | |
4508 | if (nr_printable_breakpoints > 0) | |
4509 | annotate_breakpoints_table (); | |
7f3b0473 | 4510 | |
c4093a6a JM |
4511 | ALL_BREAKPOINTS (b) |
4512 | if (bnum == -1 | |
4513 | || bnum == b->number) | |
4514 | { | |
4515 | /* We only print out user settable breakpoints unless the | |
4516 | allflag is set. */ | |
7f3b0473 | 4517 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 4518 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a JM |
4519 | } |
4520 | ||
3b31d625 | 4521 | do_cleanups (bkpttbl_chain); |
698384cd | 4522 | |
7f3b0473 | 4523 | if (nr_printable_breakpoints == 0) |
c906108c | 4524 | { |
8b93c638 JM |
4525 | if (bnum == -1) |
4526 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4527 | else | |
4528 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4529 | bnum); | |
c906108c SS |
4530 | } |
4531 | else | |
c4093a6a | 4532 | { |
a6d9a66e UW |
4533 | if (last_loc && !server_command) |
4534 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4535 | } |
c906108c | 4536 | |
c4093a6a JM |
4537 | /* FIXME? Should this be moved up so that it is only called when |
4538 | there have been breakpoints? */ | |
c906108c SS |
4539 | annotate_breakpoints_table_end (); |
4540 | } | |
4541 | ||
c906108c | 4542 | static void |
fba45db2 | 4543 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4544 | { |
4545 | int bnum = -1; | |
4546 | ||
4547 | if (bnum_exp) | |
bb518678 | 4548 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4549 | |
4550 | breakpoint_1 (bnum, 0); | |
4551 | } | |
4552 | ||
7a292a7a | 4553 | static void |
fba45db2 | 4554 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4555 | { |
4556 | int bnum = -1; | |
4557 | ||
4558 | if (bnum_exp) | |
bb518678 | 4559 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4560 | |
4561 | breakpoint_1 (bnum, 1); | |
4562 | } | |
4563 | ||
0d381245 | 4564 | static int |
714835d5 | 4565 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 4566 | struct program_space *pspace, |
714835d5 | 4567 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
4568 | { |
4569 | struct bp_location *bl = b->loc; | |
4570 | for (; bl; bl = bl->next) | |
4571 | { | |
6c95b8df PA |
4572 | if (bl->pspace == pspace |
4573 | && bl->address == pc | |
0d381245 VP |
4574 | && (!overlay_debugging || bl->section == section)) |
4575 | return 1; | |
4576 | } | |
4577 | return 0; | |
4578 | } | |
4579 | ||
6c95b8df PA |
4580 | /* Print a message describing any breakpoints set at PC. This |
4581 | concerns with logical breakpoints, so we match program spaces, not | |
4582 | address spaces. */ | |
c906108c SS |
4583 | |
4584 | static void | |
6c95b8df PA |
4585 | describe_other_breakpoints (struct gdbarch *gdbarch, |
4586 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 4587 | struct obj_section *section, int thread) |
c906108c | 4588 | { |
52f0bd74 AC |
4589 | int others = 0; |
4590 | struct breakpoint *b; | |
c906108c SS |
4591 | |
4592 | ALL_BREAKPOINTS (b) | |
6c95b8df | 4593 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
4594 | if (others > 0) |
4595 | { | |
a3f17187 AC |
4596 | if (others == 1) |
4597 | printf_filtered (_("Note: breakpoint ")); | |
4598 | else /* if (others == ???) */ | |
4599 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4600 | ALL_BREAKPOINTS (b) |
6c95b8df | 4601 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
4602 | { |
4603 | others--; | |
4604 | printf_filtered ("%d", b->number); | |
4605 | if (b->thread == -1 && thread != -1) | |
4606 | printf_filtered (" (all threads)"); | |
4607 | else if (b->thread != -1) | |
4608 | printf_filtered (" (thread %d)", b->thread); | |
4609 | printf_filtered ("%s%s ", | |
059fb39f | 4610 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4611 | || b->enable_state == bp_call_disabled |
4612 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4613 | ? " (disabled)" |
4614 | : b->enable_state == bp_permanent | |
4615 | ? " (permanent)" | |
4616 | : ""), | |
4617 | (others > 1) ? "," | |
4618 | : ((others == 1) ? " and" : "")); | |
4619 | } | |
a3f17187 | 4620 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4621 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4622 | printf_filtered (".\n"); |
4623 | } | |
4624 | } | |
4625 | \f | |
4626 | /* Set the default place to put a breakpoint | |
4627 | for the `break' command with no arguments. */ | |
4628 | ||
4629 | void | |
6c95b8df PA |
4630 | set_default_breakpoint (int valid, struct program_space *pspace, |
4631 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 4632 | int line) |
c906108c SS |
4633 | { |
4634 | default_breakpoint_valid = valid; | |
6c95b8df | 4635 | default_breakpoint_pspace = pspace; |
c906108c SS |
4636 | default_breakpoint_address = addr; |
4637 | default_breakpoint_symtab = symtab; | |
4638 | default_breakpoint_line = line; | |
4639 | } | |
4640 | ||
e4f237da KB |
4641 | /* Return true iff it is meaningful to use the address member of |
4642 | BPT. For some breakpoint types, the address member is irrelevant | |
4643 | and it makes no sense to attempt to compare it to other addresses | |
4644 | (or use it for any other purpose either). | |
4645 | ||
4646 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
4647 | have a zero valued address and we don't want to mark breakpoints of any of |
4648 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
4649 | |
4650 | bp_watchpoint | |
2d134ed3 PA |
4651 | bp_catchpoint |
4652 | ||
4653 | */ | |
e4f237da KB |
4654 | |
4655 | static int | |
4656 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4657 | { | |
4658 | enum bptype type = bpt->type; | |
4659 | ||
2d134ed3 PA |
4660 | return (type != bp_watchpoint && type != bp_catchpoint); |
4661 | } | |
4662 | ||
4663 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
4664 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
4665 | ||
4666 | static int | |
4667 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
4668 | { | |
4669 | return (loc1->owner->type == loc2->owner->type | |
4670 | && loc1->pspace->aspace == loc2->pspace->aspace | |
4671 | && loc1->address == loc2->address | |
4672 | && loc1->length == loc2->length); | |
e4f237da KB |
4673 | } |
4674 | ||
6c95b8df PA |
4675 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
4676 | same breakpoint location. In most targets, this can only be true | |
4677 | if ASPACE1 matches ASPACE2. On targets that have global | |
4678 | breakpoints, the address space doesn't really matter. */ | |
4679 | ||
4680 | static int | |
4681 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
4682 | struct address_space *aspace2, CORE_ADDR addr2) | |
4683 | { | |
4684 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
4685 | || aspace1 == aspace2) | |
4686 | && addr1 == addr2); | |
4687 | } | |
4688 | ||
2d134ed3 PA |
4689 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
4690 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
4691 | represent the same location. */ | |
4692 | ||
4693 | static int | |
4694 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
4695 | { | |
4696 | int hw_point1 = is_hardware_watchpoint (loc1->owner); | |
4697 | int hw_point2 = is_hardware_watchpoint (loc2->owner); | |
4698 | ||
4699 | if (hw_point1 != hw_point2) | |
4700 | return 0; | |
4701 | else if (hw_point1) | |
4702 | return watchpoint_locations_match (loc1, loc2); | |
4703 | else | |
4704 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
4705 | loc2->pspace->aspace, loc2->address); | |
4706 | } | |
4707 | ||
76897487 KB |
4708 | static void |
4709 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4710 | int bnum, int have_bnum) | |
4711 | { | |
4712 | char astr1[40]; | |
4713 | char astr2[40]; | |
4714 | ||
bb599908 PH |
4715 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4716 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4717 | if (have_bnum) |
8a3fe4f8 | 4718 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4719 | bnum, astr1, astr2); |
4720 | else | |
8a3fe4f8 | 4721 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4722 | } |
4723 | ||
4724 | /* Adjust a breakpoint's address to account for architectural constraints | |
4725 | on breakpoint placement. Return the adjusted address. Note: Very | |
4726 | few targets require this kind of adjustment. For most targets, | |
4727 | this function is simply the identity function. */ | |
4728 | ||
4729 | static CORE_ADDR | |
a6d9a66e UW |
4730 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4731 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4732 | { |
a6d9a66e | 4733 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4734 | { |
4735 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4736 | return bpaddr; | |
4737 | } | |
88f7da05 KB |
4738 | else if (bptype == bp_watchpoint |
4739 | || bptype == bp_hardware_watchpoint | |
4740 | || bptype == bp_read_watchpoint | |
4741 | || bptype == bp_access_watchpoint | |
fe798b75 | 4742 | || bptype == bp_catchpoint) |
88f7da05 KB |
4743 | { |
4744 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4745 | have their addresses modified. */ | |
4746 | return bpaddr; | |
4747 | } | |
76897487 KB |
4748 | else |
4749 | { | |
4750 | CORE_ADDR adjusted_bpaddr; | |
4751 | ||
4752 | /* Some targets have architectural constraints on the placement | |
4753 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4754 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4755 | |
4756 | /* An adjusted breakpoint address can significantly alter | |
4757 | a user's expectations. Print a warning if an adjustment | |
4758 | is required. */ | |
4759 | if (adjusted_bpaddr != bpaddr) | |
4760 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4761 | ||
4762 | return adjusted_bpaddr; | |
4763 | } | |
4764 | } | |
4765 | ||
7cc221ef DJ |
4766 | /* Allocate a struct bp_location. */ |
4767 | ||
26bb91f3 | 4768 | static struct bp_location * |
39d61571 | 4769 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4770 | { |
4771 | struct bp_location *loc, *loc_p; | |
4772 | ||
4773 | loc = xmalloc (sizeof (struct bp_location)); | |
4774 | memset (loc, 0, sizeof (*loc)); | |
4775 | ||
e049a4b5 | 4776 | loc->owner = bpt; |
511a6cd4 | 4777 | loc->cond = NULL; |
0d381245 VP |
4778 | loc->shlib_disabled = 0; |
4779 | loc->enabled = 1; | |
e049a4b5 | 4780 | |
39d61571 | 4781 | switch (bpt->type) |
e049a4b5 DJ |
4782 | { |
4783 | case bp_breakpoint: | |
1042e4c0 | 4784 | case bp_tracepoint: |
e049a4b5 DJ |
4785 | case bp_until: |
4786 | case bp_finish: | |
4787 | case bp_longjmp: | |
4788 | case bp_longjmp_resume: | |
4789 | case bp_step_resume: | |
e049a4b5 DJ |
4790 | case bp_watchpoint_scope: |
4791 | case bp_call_dummy: | |
4792 | case bp_shlib_event: | |
4793 | case bp_thread_event: | |
4794 | case bp_overlay_event: | |
4efc6507 | 4795 | case bp_jit_event: |
0fd8e87f | 4796 | case bp_longjmp_master: |
e049a4b5 DJ |
4797 | loc->loc_type = bp_loc_software_breakpoint; |
4798 | break; | |
4799 | case bp_hardware_breakpoint: | |
4800 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4801 | break; | |
4802 | case bp_hardware_watchpoint: | |
4803 | case bp_read_watchpoint: | |
4804 | case bp_access_watchpoint: | |
4805 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4806 | break; | |
4807 | case bp_watchpoint: | |
ce78b96d | 4808 | case bp_catchpoint: |
e049a4b5 DJ |
4809 | loc->loc_type = bp_loc_other; |
4810 | break; | |
4811 | default: | |
e2e0b3e5 | 4812 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4813 | } |
4814 | ||
7cc221ef DJ |
4815 | return loc; |
4816 | } | |
4817 | ||
fe3f5fa8 VP |
4818 | static void free_bp_location (struct bp_location *loc) |
4819 | { | |
4820 | if (loc->cond) | |
4821 | xfree (loc->cond); | |
74960c60 VP |
4822 | |
4823 | if (loc->function_name) | |
4824 | xfree (loc->function_name); | |
4825 | ||
fe3f5fa8 VP |
4826 | xfree (loc); |
4827 | } | |
4828 | ||
0d381245 VP |
4829 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4830 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4831 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 4832 | |
c40e75cd | 4833 | static struct breakpoint * |
a6d9a66e UW |
4834 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4835 | enum bptype bptype) | |
c906108c | 4836 | { |
52f0bd74 | 4837 | struct breakpoint *b, *b1; |
c906108c SS |
4838 | |
4839 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4840 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4841 | |
4d28f7a8 | 4842 | b->type = bptype; |
a6d9a66e | 4843 | b->gdbarch = gdbarch; |
c906108c SS |
4844 | b->language = current_language->la_language; |
4845 | b->input_radix = input_radix; | |
4846 | b->thread = -1; | |
b5de0fa7 | 4847 | b->enable_state = bp_enabled; |
c906108c SS |
4848 | b->next = 0; |
4849 | b->silent = 0; | |
4850 | b->ignore_count = 0; | |
4851 | b->commands = NULL; | |
818dd999 | 4852 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4853 | b->forked_inferior_pid = null_ptid; |
c906108c | 4854 | b->exec_pathname = NULL; |
a96d9b2e | 4855 | b->syscalls_to_be_caught = NULL; |
3086aeae | 4856 | b->ops = NULL; |
0d381245 | 4857 | b->condition_not_parsed = 0; |
c906108c SS |
4858 | |
4859 | /* Add this breakpoint to the end of the chain | |
4860 | so that a list of breakpoints will come out in order | |
4861 | of increasing numbers. */ | |
4862 | ||
4863 | b1 = breakpoint_chain; | |
4864 | if (b1 == 0) | |
4865 | breakpoint_chain = b; | |
4866 | else | |
4867 | { | |
4868 | while (b1->next) | |
4869 | b1 = b1->next; | |
4870 | b1->next = b; | |
4871 | } | |
0d381245 VP |
4872 | return b; |
4873 | } | |
4874 | ||
4875 | /* Initialize loc->function_name. */ | |
4876 | static void | |
4877 | set_breakpoint_location_function (struct bp_location *loc) | |
4878 | { | |
4879 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4880 | || loc->owner->type == bp_hardware_breakpoint |
4881 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4882 | { |
4883 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4884 | NULL, NULL); | |
4885 | if (loc->function_name) | |
4886 | loc->function_name = xstrdup (loc->function_name); | |
4887 | } | |
4888 | } | |
4889 | ||
a6d9a66e UW |
4890 | /* Attempt to determine architecture of location identified by SAL. */ |
4891 | static struct gdbarch * | |
4892 | get_sal_arch (struct symtab_and_line sal) | |
4893 | { | |
4894 | if (sal.section) | |
4895 | return get_objfile_arch (sal.section->objfile); | |
4896 | if (sal.symtab) | |
4897 | return get_objfile_arch (sal.symtab->objfile); | |
4898 | ||
4899 | return NULL; | |
4900 | } | |
4901 | ||
0d381245 VP |
4902 | /* set_raw_breakpoint is a low level routine for allocating and |
4903 | partially initializing a breakpoint of type BPTYPE. The newly | |
4904 | created breakpoint's address, section, source file name, and line | |
4905 | number are provided by SAL. The newly created and partially | |
4906 | initialized breakpoint is added to the breakpoint chain and | |
4907 | is also returned as the value of this function. | |
4908 | ||
4909 | It is expected that the caller will complete the initialization of | |
4910 | the newly created breakpoint struct as well as output any status | |
4911 | information regarding the creation of a new breakpoint. In | |
4912 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4913 | number! Care should be taken to not allow an error to occur | |
4914 | prior to completing the initialization of the breakpoint. If this | |
4915 | should happen, a bogus breakpoint will be left on the chain. */ | |
4916 | ||
63c252f8 | 4917 | struct breakpoint * |
a6d9a66e UW |
4918 | set_raw_breakpoint (struct gdbarch *gdbarch, |
4919 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4920 | { |
a6d9a66e | 4921 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4922 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4923 | struct gdbarch *loc_gdbarch; |
4924 | ||
4925 | loc_gdbarch = get_sal_arch (sal); | |
4926 | if (!loc_gdbarch) | |
4927 | loc_gdbarch = b->gdbarch; | |
0d381245 | 4928 | |
6c95b8df PA |
4929 | if (bptype != bp_catchpoint) |
4930 | gdb_assert (sal.pspace != NULL); | |
4931 | ||
0d381245 VP |
4932 | /* Adjust the breakpoint's address prior to allocating a location. |
4933 | Once we call allocate_bp_location(), that mostly uninitialized | |
4934 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4935 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4936 | not want its scan of the location chain to find a breakpoint and |
4937 | location that's only been partially initialized. */ | |
a6d9a66e | 4938 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4939 | |
39d61571 | 4940 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4941 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4942 | b->loc->requested_address = sal.pc; |
4943 | b->loc->address = adjusted_address; | |
6c95b8df PA |
4944 | b->loc->pspace = sal.pspace; |
4945 | ||
4946 | /* Store the program space that was used to set the breakpoint, for | |
4947 | breakpoint resetting. */ | |
4948 | b->pspace = sal.pspace; | |
0d381245 VP |
4949 | |
4950 | if (sal.symtab == NULL) | |
4951 | b->source_file = NULL; | |
4952 | else | |
1b36a34b | 4953 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4954 | b->loc->section = sal.section; |
4955 | b->line_number = sal.line; | |
4956 | ||
4957 | set_breakpoint_location_function (b->loc); | |
c906108c | 4958 | |
c906108c SS |
4959 | breakpoints_changed (); |
4960 | ||
4961 | return b; | |
4962 | } | |
4963 | ||
c2c6d25f JM |
4964 | |
4965 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4966 | instruction, hard-wired into the inferior's code. */ | |
4967 | void | |
4968 | make_breakpoint_permanent (struct breakpoint *b) | |
4969 | { | |
0d381245 | 4970 | struct bp_location *bl; |
b5de0fa7 | 4971 | b->enable_state = bp_permanent; |
c2c6d25f | 4972 | |
0d381245 VP |
4973 | /* By definition, permanent breakpoints are already present in the code. |
4974 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4975 | is called in just one place, so it's hard to say if it's reasonable | |
4976 | to have permanent breakpoint with multiple locations or not, | |
4977 | but it's easy to implmement. */ | |
4978 | for (bl = b->loc; bl; bl = bl->next) | |
4979 | bl->inserted = 1; | |
c2c6d25f JM |
4980 | } |
4981 | ||
53a5351d | 4982 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 4983 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
4984 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4985 | ||
4986 | void | |
0fd8e87f | 4987 | set_longjmp_breakpoint (int thread) |
c906108c | 4988 | { |
0fd8e87f UW |
4989 | struct breakpoint *b, *temp; |
4990 | ||
4991 | /* To avoid having to rescan all objfile symbols at every step, | |
4992 | we maintain a list of continually-inserted but always disabled | |
4993 | longjmp "master" breakpoints. Here, we simply create momentary | |
4994 | clones of those and enable them for the requested thread. */ | |
4995 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4996 | if (b->pspace == current_program_space |
4997 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
4998 | { |
4999 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5000 | clone->type = bp_longjmp; | |
5001 | clone->thread = thread; | |
5002 | } | |
c906108c SS |
5003 | } |
5004 | ||
611c83ae | 5005 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5006 | void |
611c83ae | 5007 | delete_longjmp_breakpoint (int thread) |
c906108c | 5008 | { |
611c83ae | 5009 | struct breakpoint *b, *temp; |
c906108c | 5010 | |
611c83ae PA |
5011 | ALL_BREAKPOINTS_SAFE (b, temp) |
5012 | if (b->type == bp_longjmp) | |
5013 | { | |
5014 | if (b->thread == thread) | |
5015 | delete_breakpoint (b); | |
5016 | } | |
c906108c SS |
5017 | } |
5018 | ||
1900040c MS |
5019 | void |
5020 | enable_overlay_breakpoints (void) | |
5021 | { | |
52f0bd74 | 5022 | struct breakpoint *b; |
1900040c MS |
5023 | |
5024 | ALL_BREAKPOINTS (b) | |
5025 | if (b->type == bp_overlay_event) | |
5026 | { | |
5027 | b->enable_state = bp_enabled; | |
b60e7edf | 5028 | update_global_location_list (1); |
c02f5703 | 5029 | overlay_events_enabled = 1; |
1900040c MS |
5030 | } |
5031 | } | |
5032 | ||
5033 | void | |
5034 | disable_overlay_breakpoints (void) | |
5035 | { | |
52f0bd74 | 5036 | struct breakpoint *b; |
1900040c MS |
5037 | |
5038 | ALL_BREAKPOINTS (b) | |
5039 | if (b->type == bp_overlay_event) | |
5040 | { | |
5041 | b->enable_state = bp_disabled; | |
b60e7edf | 5042 | update_global_location_list (0); |
c02f5703 | 5043 | overlay_events_enabled = 0; |
1900040c MS |
5044 | } |
5045 | } | |
5046 | ||
c4093a6a | 5047 | struct breakpoint * |
a6d9a66e | 5048 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5049 | { |
5050 | struct breakpoint *b; | |
c4093a6a | 5051 | |
a6d9a66e | 5052 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5053 | |
b5de0fa7 | 5054 | b->enable_state = bp_enabled; |
c4093a6a | 5055 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5056 | b->addr_string |
5057 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5058 | |
b60e7edf | 5059 | update_global_location_list_nothrow (1); |
74960c60 | 5060 | |
c4093a6a JM |
5061 | return b; |
5062 | } | |
5063 | ||
5064 | void | |
5065 | remove_thread_event_breakpoints (void) | |
5066 | { | |
5067 | struct breakpoint *b, *temp; | |
5068 | ||
5069 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5070 | if (b->type == bp_thread_event |
5071 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5072 | delete_breakpoint (b); |
5073 | } | |
5074 | ||
0101ce28 JJ |
5075 | struct captured_parse_breakpoint_args |
5076 | { | |
5077 | char **arg_p; | |
5078 | struct symtabs_and_lines *sals_p; | |
5079 | char ***addr_string_p; | |
5080 | int *not_found_ptr; | |
5081 | }; | |
5082 | ||
5083 | struct lang_and_radix | |
5084 | { | |
5085 | enum language lang; | |
5086 | int radix; | |
5087 | }; | |
5088 | ||
4efc6507 DE |
5089 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5090 | ||
5091 | struct breakpoint * | |
5092 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5093 | { | |
5094 | struct breakpoint *b; | |
5095 | ||
5096 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5097 | update_global_location_list_nothrow (1); | |
5098 | return b; | |
5099 | } | |
0101ce28 | 5100 | |
cae688ec JJ |
5101 | void |
5102 | remove_solib_event_breakpoints (void) | |
5103 | { | |
5104 | struct breakpoint *b, *temp; | |
5105 | ||
5106 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5107 | if (b->type == bp_shlib_event |
5108 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5109 | delete_breakpoint (b); |
5110 | } | |
5111 | ||
5112 | struct breakpoint * | |
a6d9a66e | 5113 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5114 | { |
5115 | struct breakpoint *b; | |
5116 | ||
a6d9a66e | 5117 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5118 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5119 | return b; |
5120 | } | |
5121 | ||
5122 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5123 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5124 | ||
5125 | void | |
cb851954 | 5126 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5127 | { |
876fa593 | 5128 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5129 | |
876fa593 | 5130 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5131 | { |
0d381245 VP |
5132 | struct breakpoint *b = loc->owner; |
5133 | /* We apply the check to all breakpoints, including disabled | |
5134 | for those with loc->duplicate set. This is so that when breakpoint | |
5135 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5136 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5137 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
5138 | if (((b->type == bp_breakpoint) |
5139 | || (b->type == bp_hardware_breakpoint) | |
5140 | || (b->type == bp_tracepoint)) | |
6c95b8df | 5141 | && loc->pspace == current_program_space |
0d381245 | 5142 | && !loc->shlib_disabled |
a77053c2 | 5143 | #ifdef PC_SOLIB |
0d381245 | 5144 | && PC_SOLIB (loc->address) |
a77053c2 | 5145 | #else |
6c95b8df | 5146 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5147 | #endif |
5148 | ) | |
0d381245 VP |
5149 | { |
5150 | loc->shlib_disabled = 1; | |
5151 | } | |
cae688ec JJ |
5152 | } |
5153 | } | |
5154 | ||
84acb35a JJ |
5155 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5156 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5157 | ||
75149521 | 5158 | static void |
84acb35a JJ |
5159 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5160 | { | |
876fa593 | 5161 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5162 | int disabled_shlib_breaks = 0; |
5163 | ||
c86cf029 VP |
5164 | /* SunOS a.out shared libraries are always mapped, so do not |
5165 | disable breakpoints; they will only be reported as unloaded | |
5166 | through clear_solib when GDB discards its shared library | |
5167 | list. See clear_solib for more information. */ | |
5168 | if (exec_bfd != NULL | |
5169 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5170 | return; | |
5171 | ||
876fa593 | 5172 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5173 | { |
0d381245 VP |
5174 | struct breakpoint *b = loc->owner; |
5175 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5176 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5177 | && solib->pspace == loc->pspace |
e2dd7057 PP |
5178 | && !loc->shlib_disabled |
5179 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
5180 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 5181 | { |
e2dd7057 PP |
5182 | loc->shlib_disabled = 1; |
5183 | /* At this point, we cannot rely on remove_breakpoint | |
5184 | succeeding so we must mark the breakpoint as not inserted | |
5185 | to prevent future errors occurring in remove_breakpoints. */ | |
5186 | loc->inserted = 0; | |
5187 | if (!disabled_shlib_breaks) | |
5188 | { | |
5189 | target_terminal_ours_for_output (); | |
5190 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5191 | solib->so_name); | |
84acb35a | 5192 | } |
e2dd7057 | 5193 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5194 | } |
5195 | } | |
84acb35a JJ |
5196 | } |
5197 | ||
ce78b96d JB |
5198 | /* FORK & VFORK catchpoints. */ |
5199 | ||
5200 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5201 | ||
c906108c | 5202 | static void |
ce78b96d JB |
5203 | insert_catch_fork (struct breakpoint *b) |
5204 | { | |
5205 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5206 | } | |
5207 | ||
5208 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5209 | ||
5210 | static int | |
5211 | remove_catch_fork (struct breakpoint *b) | |
5212 | { | |
5213 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5214 | } | |
5215 | ||
5216 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5217 | catchpoints. */ | |
5218 | ||
5219 | static int | |
5220 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5221 | { | |
5222 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5223 | } | |
5224 | ||
5225 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5226 | ||
5227 | static enum print_stop_action | |
5228 | print_it_catch_fork (struct breakpoint *b) | |
5229 | { | |
5230 | annotate_catchpoint (b->number); | |
5231 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5232 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5233 | return PRINT_SRC_AND_LOC; | |
5234 | } | |
5235 | ||
5236 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5237 | ||
5238 | static void | |
a6d9a66e | 5239 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5240 | { |
79a45b7d TT |
5241 | struct value_print_options opts; |
5242 | ||
5243 | get_user_print_options (&opts); | |
5244 | ||
ce78b96d JB |
5245 | /* Field 4, the address, is omitted (which makes the columns |
5246 | not line up too nicely with the headers, but the effect | |
5247 | is relatively readable). */ | |
79a45b7d | 5248 | if (opts.addressprint) |
ce78b96d JB |
5249 | ui_out_field_skip (uiout, "addr"); |
5250 | annotate_field (5); | |
5251 | ui_out_text (uiout, "fork"); | |
5252 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5253 | { | |
5254 | ui_out_text (uiout, ", process "); | |
5255 | ui_out_field_int (uiout, "what", | |
5256 | ptid_get_pid (b->forked_inferior_pid)); | |
5257 | ui_out_spaces (uiout, 1); | |
5258 | } | |
5259 | } | |
5260 | ||
5261 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5262 | catchpoints. */ | |
5263 | ||
5264 | static void | |
5265 | print_mention_catch_fork (struct breakpoint *b) | |
5266 | { | |
5267 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5268 | } | |
5269 | ||
5270 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5271 | ||
5272 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5273 | { | |
5274 | insert_catch_fork, | |
5275 | remove_catch_fork, | |
5276 | breakpoint_hit_catch_fork, | |
5277 | print_it_catch_fork, | |
5278 | print_one_catch_fork, | |
5279 | print_mention_catch_fork | |
5280 | }; | |
5281 | ||
5282 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5283 | ||
5284 | static void | |
5285 | insert_catch_vfork (struct breakpoint *b) | |
5286 | { | |
5287 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5288 | } | |
5289 | ||
5290 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5291 | ||
5292 | static int | |
5293 | remove_catch_vfork (struct breakpoint *b) | |
5294 | { | |
5295 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5296 | } | |
5297 | ||
5298 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5299 | catchpoints. */ | |
5300 | ||
5301 | static int | |
5302 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5303 | { | |
5304 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5305 | } | |
5306 | ||
5307 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5308 | ||
5309 | static enum print_stop_action | |
5310 | print_it_catch_vfork (struct breakpoint *b) | |
5311 | { | |
5312 | annotate_catchpoint (b->number); | |
5313 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5314 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5315 | return PRINT_SRC_AND_LOC; | |
5316 | } | |
5317 | ||
5318 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5319 | ||
5320 | static void | |
a6d9a66e | 5321 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5322 | { |
79a45b7d TT |
5323 | struct value_print_options opts; |
5324 | ||
5325 | get_user_print_options (&opts); | |
ce78b96d JB |
5326 | /* Field 4, the address, is omitted (which makes the columns |
5327 | not line up too nicely with the headers, but the effect | |
5328 | is relatively readable). */ | |
79a45b7d | 5329 | if (opts.addressprint) |
ce78b96d JB |
5330 | ui_out_field_skip (uiout, "addr"); |
5331 | annotate_field (5); | |
5332 | ui_out_text (uiout, "vfork"); | |
5333 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5334 | { | |
5335 | ui_out_text (uiout, ", process "); | |
5336 | ui_out_field_int (uiout, "what", | |
5337 | ptid_get_pid (b->forked_inferior_pid)); | |
5338 | ui_out_spaces (uiout, 1); | |
5339 | } | |
5340 | } | |
5341 | ||
5342 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5343 | catchpoints. */ | |
5344 | ||
5345 | static void | |
5346 | print_mention_catch_vfork (struct breakpoint *b) | |
5347 | { | |
5348 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5349 | } | |
5350 | ||
5351 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5352 | ||
5353 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5354 | { | |
5355 | insert_catch_vfork, | |
5356 | remove_catch_vfork, | |
5357 | breakpoint_hit_catch_vfork, | |
5358 | print_it_catch_vfork, | |
5359 | print_one_catch_vfork, | |
5360 | print_mention_catch_vfork | |
5361 | }; | |
5362 | ||
a96d9b2e SDJ |
5363 | /* Implement the "insert" breakpoint_ops method for syscall |
5364 | catchpoints. */ | |
5365 | ||
5366 | static void | |
5367 | insert_catch_syscall (struct breakpoint *b) | |
5368 | { | |
5369 | struct inferior *inf = current_inferior (); | |
5370 | ||
5371 | ++inf->total_syscalls_count; | |
5372 | if (!b->syscalls_to_be_caught) | |
5373 | ++inf->any_syscall_count; | |
5374 | else | |
5375 | { | |
5376 | int i, iter; | |
5377 | for (i = 0; | |
5378 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5379 | i++) | |
5380 | { | |
5381 | int elem; | |
5382 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5383 | { | |
5384 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5385 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5386 | uintptr_t vec_addr; | |
5387 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5388 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5389 | vec_addr_offset; | |
5390 | memset ((void *) vec_addr, 0, | |
5391 | (iter + 1 - old_size) * sizeof (int)); | |
5392 | } | |
5393 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5394 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5395 | } | |
5396 | } | |
5397 | ||
5398 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5399 | inf->total_syscalls_count != 0, | |
5400 | inf->any_syscall_count, | |
5401 | VEC_length (int, inf->syscalls_counts), | |
5402 | VEC_address (int, inf->syscalls_counts)); | |
5403 | } | |
5404 | ||
5405 | /* Implement the "remove" breakpoint_ops method for syscall | |
5406 | catchpoints. */ | |
5407 | ||
5408 | static int | |
5409 | remove_catch_syscall (struct breakpoint *b) | |
5410 | { | |
5411 | struct inferior *inf = current_inferior (); | |
5412 | ||
5413 | --inf->total_syscalls_count; | |
5414 | if (!b->syscalls_to_be_caught) | |
5415 | --inf->any_syscall_count; | |
5416 | else | |
5417 | { | |
5418 | int i, iter; | |
5419 | for (i = 0; | |
5420 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5421 | i++) | |
5422 | { | |
5423 | int elem; | |
5424 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5425 | /* Shouldn't happen. */ | |
5426 | continue; | |
5427 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5428 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5429 | } | |
5430 | } | |
5431 | ||
5432 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5433 | inf->total_syscalls_count != 0, | |
5434 | inf->any_syscall_count, | |
5435 | VEC_length (int, inf->syscalls_counts), | |
5436 | VEC_address (int, inf->syscalls_counts)); | |
5437 | } | |
5438 | ||
5439 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5440 | catchpoints. */ | |
5441 | ||
5442 | static int | |
5443 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5444 | { | |
5445 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5446 | If we are, then we must guarantee that the called syscall is the same | |
5447 | syscall we are catching. */ | |
5448 | int syscall_number = 0; | |
5449 | ||
5450 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5451 | return 0; | |
5452 | ||
5453 | /* Now, checking if the syscall is the same. */ | |
5454 | if (b->syscalls_to_be_caught) | |
5455 | { | |
5456 | int i, iter; | |
5457 | for (i = 0; | |
5458 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5459 | i++) | |
5460 | if (syscall_number == iter) | |
5461 | break; | |
5462 | /* Not the same. */ | |
5463 | if (!iter) | |
5464 | return 0; | |
5465 | } | |
5466 | ||
5467 | return 1; | |
5468 | } | |
5469 | ||
5470 | /* Implement the "print_it" breakpoint_ops method for syscall | |
5471 | catchpoints. */ | |
5472 | ||
5473 | static enum print_stop_action | |
5474 | print_it_catch_syscall (struct breakpoint *b) | |
5475 | { | |
5476 | /* These are needed because we want to know in which state a | |
5477 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
5478 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
5479 | must print "called syscall" or "returned from syscall". */ | |
5480 | ptid_t ptid; | |
5481 | struct target_waitstatus last; | |
5482 | struct syscall s; | |
5483 | struct cleanup *old_chain; | |
5484 | char *syscall_id; | |
5485 | ||
5486 | get_last_target_status (&ptid, &last); | |
5487 | ||
5488 | get_syscall_by_number (last.value.syscall_number, &s); | |
5489 | ||
5490 | annotate_catchpoint (b->number); | |
5491 | ||
5492 | if (s.name == NULL) | |
5493 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
5494 | else | |
5495 | syscall_id = xstrprintf ("'%s'", s.name); | |
5496 | ||
5497 | old_chain = make_cleanup (xfree, syscall_id); | |
5498 | ||
5499 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
5500 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
5501 | b->number, syscall_id); | |
5502 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
5503 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
5504 | b->number, syscall_id); | |
5505 | ||
5506 | do_cleanups (old_chain); | |
5507 | ||
5508 | return PRINT_SRC_AND_LOC; | |
5509 | } | |
5510 | ||
5511 | /* Implement the "print_one" breakpoint_ops method for syscall | |
5512 | catchpoints. */ | |
5513 | ||
5514 | static void | |
5515 | print_one_catch_syscall (struct breakpoint *b, | |
5516 | struct bp_location **last_loc) | |
5517 | { | |
5518 | struct value_print_options opts; | |
5519 | ||
5520 | get_user_print_options (&opts); | |
5521 | /* Field 4, the address, is omitted (which makes the columns | |
5522 | not line up too nicely with the headers, but the effect | |
5523 | is relatively readable). */ | |
5524 | if (opts.addressprint) | |
5525 | ui_out_field_skip (uiout, "addr"); | |
5526 | annotate_field (5); | |
5527 | ||
5528 | if (b->syscalls_to_be_caught | |
5529 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5530 | ui_out_text (uiout, "syscalls \""); | |
5531 | else | |
5532 | ui_out_text (uiout, "syscall \""); | |
5533 | ||
5534 | if (b->syscalls_to_be_caught) | |
5535 | { | |
5536 | int i, iter; | |
5537 | char *text = xstrprintf ("%s", ""); | |
5538 | for (i = 0; | |
5539 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5540 | i++) | |
5541 | { | |
5542 | char *x = text; | |
5543 | struct syscall s; | |
5544 | get_syscall_by_number (iter, &s); | |
5545 | ||
5546 | if (s.name != NULL) | |
5547 | text = xstrprintf ("%s%s, ", text, s.name); | |
5548 | else | |
5549 | text = xstrprintf ("%s%d, ", text, iter); | |
5550 | ||
5551 | /* We have to xfree the last 'text' (now stored at 'x') | |
5552 | because xstrprintf dinamically allocates new space for it | |
5553 | on every call. */ | |
5554 | xfree (x); | |
5555 | } | |
5556 | /* Remove the last comma. */ | |
5557 | text[strlen (text) - 2] = '\0'; | |
5558 | ui_out_field_string (uiout, "what", text); | |
5559 | } | |
5560 | else | |
5561 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
5562 | ui_out_text (uiout, "\" "); | |
5563 | } | |
5564 | ||
5565 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
5566 | catchpoints. */ | |
5567 | ||
5568 | static void | |
5569 | print_mention_catch_syscall (struct breakpoint *b) | |
5570 | { | |
5571 | if (b->syscalls_to_be_caught) | |
5572 | { | |
5573 | int i, iter; | |
5574 | ||
5575 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5576 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
5577 | else | |
5578 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
5579 | ||
5580 | for (i = 0; | |
5581 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5582 | i++) | |
5583 | { | |
5584 | struct syscall s; | |
5585 | get_syscall_by_number (iter, &s); | |
5586 | ||
5587 | if (s.name) | |
5588 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
5589 | else | |
5590 | printf_filtered (" %d", s.number); | |
5591 | } | |
5592 | printf_filtered (")"); | |
5593 | } | |
5594 | else | |
5595 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
5596 | b->number); | |
5597 | } | |
5598 | ||
5599 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
5600 | ||
5601 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
5602 | { | |
5603 | insert_catch_syscall, | |
5604 | remove_catch_syscall, | |
5605 | breakpoint_hit_catch_syscall, | |
5606 | print_it_catch_syscall, | |
5607 | print_one_catch_syscall, | |
5608 | print_mention_catch_syscall | |
5609 | }; | |
5610 | ||
5611 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
5612 | ||
5613 | static int | |
5614 | syscall_catchpoint_p (struct breakpoint *b) | |
5615 | { | |
5616 | return (b->ops == &catch_syscall_breakpoint_ops); | |
5617 | } | |
5618 | ||
5619 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
5620 | but does NOT mention it nor update the global location list. | |
5621 | This is useful if you need to fill more fields in the | |
5622 | struct breakpoint before calling mention. | |
ce78b96d JB |
5623 | |
5624 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5625 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5626 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5627 | to the catchpoint. */ | |
5628 | ||
5629 | static struct breakpoint * | |
a96d9b2e SDJ |
5630 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
5631 | char *cond_string, | |
5632 | struct breakpoint_ops *ops) | |
c906108c | 5633 | { |
c5aa993b JM |
5634 | struct symtab_and_line sal; |
5635 | struct breakpoint *b; | |
c5aa993b | 5636 | |
fe39c653 | 5637 | init_sal (&sal); |
6c95b8df | 5638 | sal.pspace = current_program_space; |
c5aa993b | 5639 | |
a6d9a66e | 5640 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
5641 | set_breakpoint_count (breakpoint_count + 1); |
5642 | b->number = breakpoint_count; | |
ce78b96d | 5643 | |
1b36a34b | 5644 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 5645 | b->thread = -1; |
c906108c | 5646 | b->addr_string = NULL; |
b5de0fa7 EZ |
5647 | b->enable_state = bp_enabled; |
5648 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 5649 | b->ops = ops; |
c5aa993b | 5650 | |
a96d9b2e SDJ |
5651 | return b; |
5652 | } | |
5653 | ||
5654 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
5655 | ||
5656 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5657 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5658 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5659 | to the catchpoint. */ | |
5660 | ||
5661 | static struct breakpoint * | |
5662 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
5663 | char *cond_string, struct breakpoint_ops *ops) | |
5664 | { | |
5665 | struct breakpoint *b = | |
5666 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
5667 | ||
c906108c | 5668 | mention (b); |
ce78b96d | 5669 | update_global_location_list (1); |
c906108c | 5670 | |
ce78b96d | 5671 | return b; |
c906108c | 5672 | } |
c5aa993b | 5673 | |
9b70b993 | 5674 | static void |
a6d9a66e UW |
5675 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
5676 | int tempflag, char *cond_string, | |
ce78b96d | 5677 | struct breakpoint_ops *ops) |
c906108c | 5678 | { |
a6d9a66e UW |
5679 | struct breakpoint *b |
5680 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
5681 | |
5682 | /* FIXME: We should put this information in a breakpoint private data | |
5683 | area. */ | |
5684 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
5685 | } |
5686 | ||
fe798b75 JB |
5687 | /* Exec catchpoints. */ |
5688 | ||
9b70b993 | 5689 | static void |
fe798b75 | 5690 | insert_catch_exec (struct breakpoint *b) |
c906108c | 5691 | { |
fe798b75 JB |
5692 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
5693 | } | |
c906108c | 5694 | |
fe798b75 JB |
5695 | static int |
5696 | remove_catch_exec (struct breakpoint *b) | |
5697 | { | |
5698 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
5699 | } | |
c906108c | 5700 | |
fe798b75 JB |
5701 | static int |
5702 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
5703 | { | |
5704 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
5705 | } | |
c906108c | 5706 | |
fe798b75 JB |
5707 | static enum print_stop_action |
5708 | print_it_catch_exec (struct breakpoint *b) | |
5709 | { | |
5710 | annotate_catchpoint (b->number); | |
5711 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
5712 | b->exec_pathname); | |
5713 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
5714 | } |
5715 | ||
fe798b75 | 5716 | static void |
a6d9a66e | 5717 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
5718 | { |
5719 | struct value_print_options opts; | |
5720 | ||
5721 | get_user_print_options (&opts); | |
5722 | ||
5723 | /* Field 4, the address, is omitted (which makes the columns | |
5724 | not line up too nicely with the headers, but the effect | |
5725 | is relatively readable). */ | |
5726 | if (opts.addressprint) | |
5727 | ui_out_field_skip (uiout, "addr"); | |
5728 | annotate_field (5); | |
5729 | ui_out_text (uiout, "exec"); | |
5730 | if (b->exec_pathname != NULL) | |
5731 | { | |
5732 | ui_out_text (uiout, ", program \""); | |
5733 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5734 | ui_out_text (uiout, "\" "); | |
5735 | } | |
5736 | } | |
5737 | ||
5738 | static void | |
5739 | print_mention_catch_exec (struct breakpoint *b) | |
5740 | { | |
5741 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5742 | } | |
5743 | ||
5744 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5745 | { | |
5746 | insert_catch_exec, | |
5747 | remove_catch_exec, | |
5748 | breakpoint_hit_catch_exec, | |
5749 | print_it_catch_exec, | |
5750 | print_one_catch_exec, | |
5751 | print_mention_catch_exec | |
5752 | }; | |
5753 | ||
a96d9b2e SDJ |
5754 | static void |
5755 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
5756 | struct breakpoint_ops *ops) | |
5757 | { | |
5758 | struct gdbarch *gdbarch = get_current_arch (); | |
5759 | struct breakpoint *b = | |
5760 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
5761 | ||
5762 | b->syscalls_to_be_caught = filter; | |
5763 | ||
5764 | /* Now, we have to mention the breakpoint and update the global | |
5765 | location list. */ | |
5766 | mention (b); | |
5767 | update_global_location_list (1); | |
5768 | } | |
5769 | ||
c906108c | 5770 | static int |
fba45db2 | 5771 | hw_breakpoint_used_count (void) |
c906108c | 5772 | { |
52f0bd74 | 5773 | struct breakpoint *b; |
c906108c SS |
5774 | int i = 0; |
5775 | ||
5776 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5777 | { |
d6b74ac4 | 5778 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5779 | i++; |
5780 | } | |
c906108c SS |
5781 | |
5782 | return i; | |
5783 | } | |
5784 | ||
5785 | static int | |
fba45db2 | 5786 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5787 | { |
52f0bd74 | 5788 | struct breakpoint *b; |
c906108c SS |
5789 | int i = 0; |
5790 | ||
5791 | *other_type_used = 0; | |
5792 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5793 | { |
468d015d | 5794 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5795 | { |
5796 | if (b->type == type) | |
5797 | i++; | |
059fb39f PM |
5798 | else if ((b->type == bp_hardware_watchpoint |
5799 | || b->type == bp_read_watchpoint | |
5800 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5801 | *other_type_used = 1; |
5802 | } | |
5803 | } | |
c906108c SS |
5804 | return i; |
5805 | } | |
5806 | ||
c906108c | 5807 | void |
fba45db2 | 5808 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5809 | { |
c5aa993b | 5810 | struct breakpoint *b; |
c906108c SS |
5811 | |
5812 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5813 | { |
5814 | if (((b->type == bp_watchpoint) | |
5815 | || (b->type == bp_hardware_watchpoint) | |
5816 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5817 | || (b->type == bp_access_watchpoint)) |
468d015d | 5818 | && breakpoint_enabled (b)) |
c5aa993b | 5819 | { |
b5de0fa7 | 5820 | b->enable_state = bp_call_disabled; |
b60e7edf | 5821 | update_global_location_list (0); |
c5aa993b JM |
5822 | } |
5823 | } | |
c906108c SS |
5824 | } |
5825 | ||
5826 | void | |
fba45db2 | 5827 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5828 | { |
c5aa993b | 5829 | struct breakpoint *b; |
c906108c SS |
5830 | |
5831 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5832 | { |
5833 | if (((b->type == bp_watchpoint) | |
5834 | || (b->type == bp_hardware_watchpoint) | |
5835 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5836 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5837 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5838 | { |
b5de0fa7 | 5839 | b->enable_state = bp_enabled; |
b60e7edf | 5840 | update_global_location_list (1); |
c5aa993b JM |
5841 | } |
5842 | } | |
c906108c SS |
5843 | } |
5844 | ||
8bea4e01 UW |
5845 | void |
5846 | disable_breakpoints_before_startup (void) | |
5847 | { | |
5848 | struct breakpoint *b; | |
5849 | int found = 0; | |
5850 | ||
5851 | ALL_BREAKPOINTS (b) | |
5852 | { | |
6c95b8df PA |
5853 | if (b->pspace != current_program_space) |
5854 | continue; | |
5855 | ||
8bea4e01 UW |
5856 | if ((b->type == bp_breakpoint |
5857 | || b->type == bp_hardware_breakpoint) | |
5858 | && breakpoint_enabled (b)) | |
5859 | { | |
5860 | b->enable_state = bp_startup_disabled; | |
5861 | found = 1; | |
5862 | } | |
5863 | } | |
5864 | ||
5865 | if (found) | |
5866 | update_global_location_list (0); | |
5867 | ||
6c95b8df | 5868 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
5869 | } |
5870 | ||
5871 | void | |
5872 | enable_breakpoints_after_startup (void) | |
5873 | { | |
5874 | struct breakpoint *b; | |
5875 | int found = 0; | |
5876 | ||
6c95b8df | 5877 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
5878 | |
5879 | ALL_BREAKPOINTS (b) | |
5880 | { | |
6c95b8df PA |
5881 | if (b->pspace != current_program_space) |
5882 | continue; | |
5883 | ||
8bea4e01 UW |
5884 | if ((b->type == bp_breakpoint |
5885 | || b->type == bp_hardware_breakpoint) | |
5886 | && b->enable_state == bp_startup_disabled) | |
5887 | { | |
5888 | b->enable_state = bp_enabled; | |
5889 | found = 1; | |
5890 | } | |
5891 | } | |
5892 | ||
5893 | if (found) | |
5894 | breakpoint_re_set (); | |
5895 | } | |
5896 | ||
c906108c SS |
5897 | |
5898 | /* Set a breakpoint that will evaporate an end of command | |
5899 | at address specified by SAL. | |
5900 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5901 | ||
5902 | struct breakpoint * | |
a6d9a66e UW |
5903 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5904 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5905 | { |
52f0bd74 | 5906 | struct breakpoint *b; |
edb3359d DJ |
5907 | |
5908 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5909 | one. */ | |
5910 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5911 | ||
a6d9a66e | 5912 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5913 | b->enable_state = bp_enabled; |
5914 | b->disposition = disp_donttouch; | |
818dd999 | 5915 | b->frame_id = frame_id; |
c906108c SS |
5916 | |
5917 | /* If we're debugging a multi-threaded program, then we | |
5918 | want momentary breakpoints to be active in only a | |
5919 | single thread of control. */ | |
39f77062 KB |
5920 | if (in_thread_list (inferior_ptid)) |
5921 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5922 | |
b60e7edf | 5923 | update_global_location_list_nothrow (1); |
74960c60 | 5924 | |
c906108c SS |
5925 | return b; |
5926 | } | |
611c83ae | 5927 | |
e58b0e63 PA |
5928 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5929 | ORIG is NULL. */ | |
5930 | ||
5931 | struct breakpoint * | |
5932 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5933 | { | |
5934 | struct breakpoint *copy; | |
5935 | ||
5936 | /* If there's nothing to clone, then return nothing. */ | |
5937 | if (orig == NULL) | |
5938 | return NULL; | |
5939 | ||
a6d9a66e | 5940 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5941 | copy->loc = allocate_bp_location (copy); |
5942 | set_breakpoint_location_function (copy->loc); | |
5943 | ||
a6d9a66e | 5944 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5945 | copy->loc->requested_address = orig->loc->requested_address; |
5946 | copy->loc->address = orig->loc->address; | |
5947 | copy->loc->section = orig->loc->section; | |
6c95b8df | 5948 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
5949 | |
5950 | if (orig->source_file == NULL) | |
5951 | copy->source_file = NULL; | |
5952 | else | |
5953 | copy->source_file = xstrdup (orig->source_file); | |
5954 | ||
5955 | copy->line_number = orig->line_number; | |
5956 | copy->frame_id = orig->frame_id; | |
5957 | copy->thread = orig->thread; | |
6c95b8df | 5958 | copy->pspace = orig->pspace; |
e58b0e63 PA |
5959 | |
5960 | copy->enable_state = bp_enabled; | |
5961 | copy->disposition = disp_donttouch; | |
5962 | copy->number = internal_breakpoint_number--; | |
5963 | ||
5964 | update_global_location_list_nothrow (0); | |
5965 | return copy; | |
5966 | } | |
5967 | ||
611c83ae | 5968 | struct breakpoint * |
a6d9a66e UW |
5969 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5970 | enum bptype type) | |
611c83ae PA |
5971 | { |
5972 | struct symtab_and_line sal; | |
5973 | ||
5974 | sal = find_pc_line (pc, 0); | |
5975 | sal.pc = pc; | |
5976 | sal.section = find_pc_overlay (pc); | |
5977 | sal.explicit_pc = 1; | |
5978 | ||
a6d9a66e | 5979 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 5980 | } |
c906108c | 5981 | \f |
c5aa993b | 5982 | |
c906108c SS |
5983 | /* Tell the user we have just set a breakpoint B. */ |
5984 | ||
5985 | static void | |
fba45db2 | 5986 | mention (struct breakpoint *b) |
c906108c SS |
5987 | { |
5988 | int say_where = 0; | |
fa8a61dc | 5989 | struct cleanup *ui_out_chain; |
79a45b7d TT |
5990 | struct value_print_options opts; |
5991 | ||
5992 | get_user_print_options (&opts); | |
8b93c638 | 5993 | |
9a4105ab AC |
5994 | /* FIXME: This is misplaced; mention() is called by things (like |
5995 | hitting a watchpoint) other than breakpoint creation. It should | |
5996 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 5997 | random calls to breakpoint_changed with this hook. */ |
383f836e | 5998 | observer_notify_breakpoint_created (b->number); |
c906108c | 5999 | |
3086aeae DJ |
6000 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6001 | b->ops->print_mention (b); | |
6002 | else | |
6003 | switch (b->type) | |
6004 | { | |
6005 | case bp_none: | |
a3f17187 | 6006 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6007 | break; |
6008 | case bp_watchpoint: | |
6009 | ui_out_text (uiout, "Watchpoint "); | |
6010 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6011 | ui_out_field_int (uiout, "number", b->number); | |
6012 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6013 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6014 | do_cleanups (ui_out_chain); |
6015 | break; | |
6016 | case bp_hardware_watchpoint: | |
6017 | ui_out_text (uiout, "Hardware watchpoint "); | |
6018 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6019 | ui_out_field_int (uiout, "number", b->number); | |
6020 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6021 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6022 | do_cleanups (ui_out_chain); |
6023 | break; | |
6024 | case bp_read_watchpoint: | |
6025 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6026 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6027 | ui_out_field_int (uiout, "number", b->number); | |
6028 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6029 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6030 | do_cleanups (ui_out_chain); |
6031 | break; | |
6032 | case bp_access_watchpoint: | |
6033 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6034 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6035 | ui_out_field_int (uiout, "number", b->number); | |
6036 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6037 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6038 | do_cleanups (ui_out_chain); |
6039 | break; | |
6040 | case bp_breakpoint: | |
6041 | if (ui_out_is_mi_like_p (uiout)) | |
6042 | { | |
6043 | say_where = 0; | |
6044 | break; | |
6045 | } | |
2cec12e5 AR |
6046 | if (b->disposition == disp_del) |
6047 | printf_filtered (_("Temporary breakpoint")); | |
6048 | else | |
6049 | printf_filtered (_("Breakpoint")); | |
6050 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6051 | say_where = 1; |
6052 | break; | |
6053 | case bp_hardware_breakpoint: | |
6054 | if (ui_out_is_mi_like_p (uiout)) | |
6055 | { | |
6056 | say_where = 0; | |
6057 | break; | |
6058 | } | |
a3f17187 | 6059 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6060 | say_where = 1; |
6061 | break; | |
1042e4c0 SS |
6062 | case bp_tracepoint: |
6063 | if (ui_out_is_mi_like_p (uiout)) | |
6064 | { | |
6065 | say_where = 0; | |
6066 | break; | |
6067 | } | |
6068 | printf_filtered (_("Tracepoint")); | |
6069 | printf_filtered (_(" %d"), b->number); | |
6070 | say_where = 1; | |
6071 | break; | |
3086aeae DJ |
6072 | |
6073 | case bp_until: | |
6074 | case bp_finish: | |
6075 | case bp_longjmp: | |
6076 | case bp_longjmp_resume: | |
6077 | case bp_step_resume: | |
3086aeae DJ |
6078 | case bp_call_dummy: |
6079 | case bp_watchpoint_scope: | |
6080 | case bp_shlib_event: | |
6081 | case bp_thread_event: | |
6082 | case bp_overlay_event: | |
4efc6507 | 6083 | case bp_jit_event: |
0fd8e87f | 6084 | case bp_longjmp_master: |
3086aeae DJ |
6085 | break; |
6086 | } | |
c906108c | 6087 | |
c906108c SS |
6088 | if (say_where) |
6089 | { | |
a3f17187 AC |
6090 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6091 | single string. */ | |
0d381245 | 6092 | if (b->loc == NULL) |
c906108c | 6093 | { |
a3f17187 | 6094 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6095 | } |
6096 | else | |
6097 | { | |
79a45b7d | 6098 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6099 | { |
6100 | printf_filtered (" at "); | |
5af949e3 UW |
6101 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6102 | gdb_stdout); | |
0101ce28 JJ |
6103 | } |
6104 | if (b->source_file) | |
6105 | printf_filtered (": file %s, line %d.", | |
6106 | b->source_file, b->line_number); | |
0d381245 VP |
6107 | |
6108 | if (b->loc->next) | |
6109 | { | |
6110 | struct bp_location *loc = b->loc; | |
6111 | int n = 0; | |
6112 | for (; loc; loc = loc->next) | |
6113 | ++n; | |
6114 | printf_filtered (" (%d locations)", n); | |
6115 | } | |
6116 | ||
c906108c | 6117 | } |
c906108c | 6118 | } |
9dc5e2a9 | 6119 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6120 | return; |
c906108c SS |
6121 | printf_filtered ("\n"); |
6122 | } | |
c906108c | 6123 | \f |
c5aa993b | 6124 | |
0d381245 | 6125 | static struct bp_location * |
39d61571 | 6126 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6127 | const struct symtab_and_line *sal) |
6128 | { | |
6129 | struct bp_location *loc, **tmp; | |
6130 | ||
39d61571 | 6131 | loc = allocate_bp_location (b); |
0d381245 VP |
6132 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6133 | ; | |
6134 | *tmp = loc; | |
a6d9a66e UW |
6135 | loc->gdbarch = get_sal_arch (*sal); |
6136 | if (!loc->gdbarch) | |
6137 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6138 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6139 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6140 | loc->requested_address, b->type); | |
6c95b8df PA |
6141 | loc->pspace = sal->pspace; |
6142 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6143 | loc->section = sal->section; |
6144 | ||
6145 | set_breakpoint_location_function (loc); | |
6146 | return loc; | |
6147 | } | |
514f746b AR |
6148 | \f |
6149 | ||
6150 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6151 | return 0 otherwise. */ | |
6152 | ||
6153 | static int | |
6154 | bp_loc_is_permanent (struct bp_location *loc) | |
6155 | { | |
6156 | int len; | |
6157 | CORE_ADDR addr; | |
6158 | const gdb_byte *brk; | |
6159 | gdb_byte *target_mem; | |
939c61fa JK |
6160 | struct cleanup *cleanup; |
6161 | int retval = 0; | |
514f746b AR |
6162 | |
6163 | gdb_assert (loc != NULL); | |
6164 | ||
6165 | addr = loc->address; | |
a6d9a66e | 6166 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6167 | |
939c61fa JK |
6168 | /* Software breakpoints unsupported? */ |
6169 | if (brk == NULL) | |
6170 | return 0; | |
6171 | ||
514f746b AR |
6172 | target_mem = alloca (len); |
6173 | ||
939c61fa JK |
6174 | /* Enable the automatic memory restoration from breakpoints while |
6175 | we read the memory. Otherwise we could say about our temporary | |
6176 | breakpoints they are permanent. */ | |
6c95b8df PA |
6177 | cleanup = save_current_space_and_thread (); |
6178 | ||
6179 | switch_to_program_space_and_thread (loc->pspace); | |
6180 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6181 | |
514f746b AR |
6182 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6183 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6184 | retval = 1; |
514f746b | 6185 | |
939c61fa JK |
6186 | do_cleanups (cleanup); |
6187 | ||
6188 | return retval; | |
514f746b AR |
6189 | } |
6190 | ||
6191 | ||
c3f6f71d | 6192 | |
018d34a4 VP |
6193 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6194 | as textual description of the location, and COND_STRING | |
db107f19 | 6195 | as condition expression. */ |
018d34a4 VP |
6196 | |
6197 | static void | |
a6d9a66e UW |
6198 | create_breakpoint (struct gdbarch *gdbarch, |
6199 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
6200 | char *cond_string, |
6201 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 6202 | int thread, int task, int ignore_count, |
41447f92 | 6203 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 6204 | { |
0d381245 VP |
6205 | struct breakpoint *b = NULL; |
6206 | int i; | |
018d34a4 VP |
6207 | |
6208 | if (type == bp_hardware_breakpoint) | |
6209 | { | |
6210 | int i = hw_breakpoint_used_count (); | |
6211 | int target_resources_ok = | |
d92524f1 | 6212 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6213 | i + 1, 0); |
6214 | if (target_resources_ok == 0) | |
6215 | error (_("No hardware breakpoint support in the target.")); | |
6216 | else if (target_resources_ok < 0) | |
6217 | error (_("Hardware breakpoints used exceeds limit.")); | |
6218 | } | |
6219 | ||
6c95b8df PA |
6220 | gdb_assert (sals.nelts > 0); |
6221 | ||
0d381245 VP |
6222 | for (i = 0; i < sals.nelts; ++i) |
6223 | { | |
6224 | struct symtab_and_line sal = sals.sals[i]; | |
6225 | struct bp_location *loc; | |
6226 | ||
6227 | if (from_tty) | |
5af949e3 UW |
6228 | { |
6229 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6230 | if (!loc_gdbarch) | |
6231 | loc_gdbarch = gdbarch; | |
6232 | ||
6233 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6234 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6235 | } |
0d381245 VP |
6236 | |
6237 | if (i == 0) | |
6238 | { | |
a6d9a66e | 6239 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6240 | set_breakpoint_count (breakpoint_count + 1); |
6241 | b->number = breakpoint_count; | |
6242 | b->thread = thread; | |
4a306c9a | 6243 | b->task = task; |
018d34a4 | 6244 | |
0d381245 VP |
6245 | b->cond_string = cond_string; |
6246 | b->ignore_count = ignore_count; | |
41447f92 | 6247 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6248 | b->disposition = disposition; |
018d34a4 | 6249 | |
6c95b8df PA |
6250 | b->pspace = sals.sals[0].pspace; |
6251 | ||
6252 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6253 | && (b->type == bp_breakpoint |
6254 | || b->type == bp_hardware_breakpoint)) | |
6255 | b->enable_state = bp_startup_disabled; | |
6256 | ||
0d381245 VP |
6257 | loc = b->loc; |
6258 | } | |
6259 | else | |
018d34a4 | 6260 | { |
39d61571 | 6261 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6262 | } |
6263 | ||
514f746b AR |
6264 | if (bp_loc_is_permanent (loc)) |
6265 | make_breakpoint_permanent (b); | |
6266 | ||
0d381245 VP |
6267 | if (b->cond_string) |
6268 | { | |
6269 | char *arg = b->cond_string; | |
d32a6982 | 6270 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6271 | if (*arg) |
db107f19 | 6272 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6273 | } |
0d381245 | 6274 | } |
018d34a4 VP |
6275 | |
6276 | if (addr_string) | |
6277 | b->addr_string = addr_string; | |
6278 | else | |
6279 | /* addr_string has to be used or breakpoint_re_set will delete | |
6280 | me. */ | |
5af949e3 UW |
6281 | b->addr_string |
6282 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6283 | |
604133b5 | 6284 | b->ops = ops; |
018d34a4 VP |
6285 | mention (b); |
6286 | } | |
6287 | ||
ed0616c6 VP |
6288 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6289 | elements to fill the void space. */ | |
2c0b251b PA |
6290 | static void |
6291 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6292 | { |
6293 | int i = index_to_remove+1; | |
6294 | int last_index = sal->nelts-1; | |
6295 | ||
6296 | for (;i <= last_index; ++i) | |
6297 | sal->sals[i-1] = sal->sals[i]; | |
6298 | ||
6299 | --(sal->nelts); | |
6300 | } | |
6301 | ||
6c95b8df PA |
6302 | /* If appropriate, obtains all sals that correspond to the same file |
6303 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6304 | will want to set a breakpoint at foo.c:line, and not really care | |
6305 | about program spaces. This is done only if SAL does not have | |
6306 | explicit PC and has line and file information. If we got just a | |
6307 | single expanded sal, return the original. | |
ed0616c6 | 6308 | |
6c95b8df PA |
6309 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6310 | which the name of enclosing function is different from SAL. This | |
6311 | makes sure that if we have breakpoint originally set in template | |
6312 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6313 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6314 | |
2c0b251b | 6315 | static struct symtabs_and_lines |
ed0616c6 VP |
6316 | expand_line_sal_maybe (struct symtab_and_line sal) |
6317 | { | |
6318 | struct symtabs_and_lines expanded; | |
6319 | CORE_ADDR original_pc = sal.pc; | |
6320 | char *original_function = NULL; | |
6321 | int found; | |
6322 | int i; | |
6c95b8df | 6323 | struct cleanup *old_chain; |
ed0616c6 VP |
6324 | |
6325 | /* If we have explicit pc, don't expand. | |
6326 | If we have no line number, we can't expand. */ | |
6327 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6328 | { | |
6329 | expanded.nelts = 1; | |
6330 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6331 | expanded.sals[0] = sal; | |
6332 | return expanded; | |
6333 | } | |
6334 | ||
6335 | sal.pc = 0; | |
6c95b8df PA |
6336 | |
6337 | old_chain = save_current_space_and_thread (); | |
6338 | ||
6339 | switch_to_program_space_and_thread (sal.pspace); | |
6340 | ||
ed0616c6 | 6341 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6342 | |
6343 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6344 | expanded = expand_line_sal (sal); |
6c95b8df | 6345 | |
ed0616c6 VP |
6346 | if (expanded.nelts == 1) |
6347 | { | |
3dba1c98 JB |
6348 | /* We had one sal, we got one sal. Return that sal, adjusting it |
6349 | past the function prologue if necessary. */ | |
ed0616c6 VP |
6350 | xfree (expanded.sals); |
6351 | expanded.nelts = 1; | |
6352 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6353 | sal.pc = original_pc; | |
6354 | expanded.sals[0] = sal; | |
3dba1c98 | 6355 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 6356 | do_cleanups (old_chain); |
ed0616c6 VP |
6357 | return expanded; |
6358 | } | |
6359 | ||
6360 | if (!sal.explicit_line) | |
6361 | { | |
6362 | CORE_ADDR func_addr, func_end; | |
6363 | for (i = 0; i < expanded.nelts; ++i) | |
6364 | { | |
6365 | CORE_ADDR pc = expanded.sals[i].pc; | |
6366 | char *this_function; | |
6c95b8df PA |
6367 | |
6368 | /* We need to switch threads as well since we're about to | |
6369 | read memory. */ | |
6370 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6371 | ||
ed0616c6 VP |
6372 | if (find_pc_partial_function (pc, &this_function, |
6373 | &func_addr, &func_end)) | |
6374 | { | |
059fb39f PM |
6375 | if (this_function |
6376 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6377 | { |
6378 | remove_sal (&expanded, i); | |
6379 | --i; | |
6380 | } | |
6381 | else if (func_addr == pc) | |
6382 | { | |
6383 | /* We're at beginning of a function, and should | |
6384 | skip prologue. */ | |
6385 | struct symbol *sym = find_pc_function (pc); | |
6386 | if (sym) | |
6387 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
6388 | else | |
d80b854b UW |
6389 | { |
6390 | /* Since find_pc_partial_function returned true, | |
6391 | we should really always find the section here. */ | |
6392 | struct obj_section *section = find_pc_section (pc); | |
6393 | if (section) | |
6394 | { | |
6395 | struct gdbarch *gdbarch | |
6396 | = get_objfile_arch (section->objfile); | |
6397 | expanded.sals[i].pc | |
6398 | = gdbarch_skip_prologue (gdbarch, pc); | |
6399 | } | |
6400 | } | |
ed0616c6 VP |
6401 | } |
6402 | } | |
6403 | } | |
6404 | } | |
3daf8fe5 JG |
6405 | else |
6406 | { | |
6407 | for (i = 0; i < expanded.nelts; ++i) | |
6408 | { | |
6409 | /* If this SAL corresponds to a breakpoint inserted using a | |
6410 | line number, then skip the function prologue if necessary. */ | |
6411 | skip_prologue_sal (&expanded.sals[i]); | |
6412 | } | |
6413 | } | |
ed0616c6 | 6414 | |
6c95b8df PA |
6415 | do_cleanups (old_chain); |
6416 | ||
ed0616c6 VP |
6417 | if (expanded.nelts <= 1) |
6418 | { | |
6419 | /* This is un ugly workaround. If we get zero | |
6420 | expanded sals then something is really wrong. | |
6421 | Fix that by returnign the original sal. */ | |
6422 | xfree (expanded.sals); | |
6423 | expanded.nelts = 1; | |
6424 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6425 | sal.pc = original_pc; | |
6426 | expanded.sals[0] = sal; | |
6427 | return expanded; | |
6428 | } | |
6429 | ||
6430 | if (original_pc) | |
6431 | { | |
6432 | found = 0; | |
6433 | for (i = 0; i < expanded.nelts; ++i) | |
6434 | if (expanded.sals[i].pc == original_pc) | |
6435 | { | |
6436 | found = 1; | |
6437 | break; | |
6438 | } | |
6439 | gdb_assert (found); | |
6440 | } | |
6441 | ||
6442 | return expanded; | |
6443 | } | |
6444 | ||
018d34a4 VP |
6445 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6446 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6447 | value. COND_STRING, if not NULL, specified the condition to be | |
6448 | used for all breakpoints. Essentially the only case where | |
6449 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6450 | function. In that case, it's still not possible to specify | |
6451 | separate conditions for different overloaded functions, so | |
6452 | we take just a single condition string. | |
6453 | ||
c3f6f71d | 6454 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 6455 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
6456 | array contents). If the function fails (error() is called), the |
6457 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
6458 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
6459 | |
6460 | static void | |
a6d9a66e UW |
6461 | create_breakpoints (struct gdbarch *gdbarch, |
6462 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 6463 | char *cond_string, |
c3f6f71d | 6464 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 6465 | int thread, int task, int ignore_count, |
41447f92 VP |
6466 | struct breakpoint_ops *ops, int from_tty, |
6467 | int enabled) | |
c906108c | 6468 | { |
018d34a4 VP |
6469 | int i; |
6470 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 6471 | { |
ed0616c6 VP |
6472 | struct symtabs_and_lines expanded = |
6473 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 6474 | |
a6d9a66e | 6475 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 6476 | cond_string, type, disposition, |
4a306c9a | 6477 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 6478 | } |
c3f6f71d | 6479 | } |
c906108c | 6480 | |
c3f6f71d JM |
6481 | /* Parse ARG which is assumed to be a SAL specification possibly |
6482 | followed by conditionals. On return, SALS contains an array of SAL | |
6483 | addresses found. ADDR_STRING contains a vector of (canonical) | |
6484 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 6485 | |
b9362cc7 | 6486 | static void |
c3f6f71d JM |
6487 | parse_breakpoint_sals (char **address, |
6488 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
6489 | char ***addr_string, |
6490 | int *not_found_ptr) | |
c3f6f71d JM |
6491 | { |
6492 | char *addr_start = *address; | |
6493 | *addr_string = NULL; | |
6494 | /* If no arg given, or if first arg is 'if ', use the default | |
6495 | breakpoint. */ | |
6496 | if ((*address) == NULL | |
6497 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
6498 | { |
6499 | if (default_breakpoint_valid) | |
6500 | { | |
c3f6f71d | 6501 | struct symtab_and_line sal; |
fe39c653 | 6502 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 6503 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
6504 | xmalloc (sizeof (struct symtab_and_line)); |
6505 | sal.pc = default_breakpoint_address; | |
6506 | sal.line = default_breakpoint_line; | |
6507 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 6508 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 6509 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
6510 | |
6511 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
6512 | the default_breakpoint_address. So make sure to set | |
6513 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
6514 | sals to include all other instances with the same symtab and line. | |
6515 | */ | |
6516 | sal.explicit_pc = 1; | |
6517 | ||
c3f6f71d JM |
6518 | sals->sals[0] = sal; |
6519 | sals->nelts = 1; | |
c906108c SS |
6520 | } |
6521 | else | |
8a3fe4f8 | 6522 | error (_("No default breakpoint address now.")); |
c906108c SS |
6523 | } |
6524 | else | |
6525 | { | |
c906108c | 6526 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
6527 | current_source_symtab (which is decode_line_1's default). This |
6528 | should produce the results we want almost all of the time while | |
1aeae86e AF |
6529 | leaving default_breakpoint_* alone. |
6530 | ObjC: However, don't match an Objective-C method name which | |
6531 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 6532 | |
c214a6fd | 6533 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 6534 | |
c906108c | 6535 | if (default_breakpoint_valid |
0378c332 | 6536 | && (!cursal.symtab |
1aeae86e AF |
6537 | || ((strchr ("+-", (*address)[0]) != NULL) |
6538 | && ((*address)[1] != '[')))) | |
c3f6f71d | 6539 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
6540 | default_breakpoint_line, addr_string, |
6541 | not_found_ptr); | |
c906108c | 6542 | else |
0101ce28 JJ |
6543 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
6544 | addr_string, not_found_ptr); | |
c906108c | 6545 | } |
c3f6f71d JM |
6546 | /* For any SAL that didn't have a canonical string, fill one in. */ |
6547 | if (sals->nelts > 0 && *addr_string == NULL) | |
6548 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
6549 | if (addr_start != (*address)) | |
c906108c | 6550 | { |
c3f6f71d JM |
6551 | int i; |
6552 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 6553 | { |
c3f6f71d JM |
6554 | /* Add the string if not present. */ |
6555 | if ((*addr_string)[i] == NULL) | |
6556 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
6557 | } |
6558 | } | |
c3f6f71d | 6559 | } |
c906108c | 6560 | |
c906108c | 6561 | |
c3f6f71d JM |
6562 | /* Convert each SAL into a real PC. Verify that the PC can be |
6563 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 6564 | |
b9362cc7 | 6565 | static void |
c3f6f71d JM |
6566 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
6567 | char *address) | |
6568 | { | |
6569 | int i; | |
6570 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 6571 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
6572 | } |
6573 | ||
05ff989b | 6574 | static void |
0101ce28 JJ |
6575 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
6576 | { | |
6577 | struct captured_parse_breakpoint_args *args = data; | |
6578 | ||
6579 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
6580 | args->not_found_ptr); | |
0101ce28 JJ |
6581 | } |
6582 | ||
018d34a4 VP |
6583 | /* Given TOK, a string specification of condition and thread, as |
6584 | accepted by the 'break' command, extract the condition | |
6585 | string and thread number and set *COND_STRING and *THREAD. | |
6586 | PC identifies the context at which the condition should be parsed. | |
6587 | If no condition is found, *COND_STRING is set to NULL. | |
6588 | If no thread is found, *THREAD is set to -1. */ | |
6589 | static void | |
6590 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 6591 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
6592 | { |
6593 | *cond_string = NULL; | |
6594 | *thread = -1; | |
6595 | while (tok && *tok) | |
6596 | { | |
6597 | char *end_tok; | |
6598 | int toklen; | |
6599 | char *cond_start = NULL; | |
6600 | char *cond_end = NULL; | |
6601 | while (*tok == ' ' || *tok == '\t') | |
6602 | tok++; | |
6603 | ||
6604 | end_tok = tok; | |
6605 | ||
6606 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6607 | end_tok++; | |
6608 | ||
6609 | toklen = end_tok - tok; | |
6610 | ||
6611 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6612 | { | |
f7545552 TT |
6613 | struct expression *expr; |
6614 | ||
018d34a4 | 6615 | tok = cond_start = end_tok + 1; |
f7545552 TT |
6616 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
6617 | xfree (expr); | |
018d34a4 VP |
6618 | cond_end = tok; |
6619 | *cond_string = savestring (cond_start, | |
6620 | cond_end - cond_start); | |
6621 | } | |
6622 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6623 | { | |
6624 | char *tmptok; | |
6625 | ||
6626 | tok = end_tok + 1; | |
6627 | tmptok = tok; | |
6628 | *thread = strtol (tok, &tok, 0); | |
6629 | if (tok == tmptok) | |
6630 | error (_("Junk after thread keyword.")); | |
6631 | if (!valid_thread_id (*thread)) | |
6632 | error (_("Unknown thread %d."), *thread); | |
6633 | } | |
4a306c9a JB |
6634 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
6635 | { | |
6636 | char *tmptok; | |
6637 | ||
6638 | tok = end_tok + 1; | |
6639 | tmptok = tok; | |
6640 | *task = strtol (tok, &tok, 0); | |
6641 | if (tok == tmptok) | |
6642 | error (_("Junk after task keyword.")); | |
6643 | if (!valid_task_id (*task)) | |
b6199126 | 6644 | error (_("Unknown task %d."), *task); |
4a306c9a | 6645 | } |
018d34a4 VP |
6646 | else |
6647 | error (_("Junk at end of arguments.")); | |
6648 | } | |
6649 | } | |
6650 | ||
72b2ff0e VP |
6651 | /* Set a breakpoint. This function is shared between |
6652 | CLI and MI functions for setting a breakpoint. | |
6653 | This function has two major modes of operations, | |
6654 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
6655 | If non-zero, the function will parse arg, extracting | |
6656 | breakpoint location, address and thread. Otherwise, | |
6657 | ARG is just the location of breakpoint, with condition | |
6658 | and thread specified by the COND_STRING and THREAD | |
6659 | parameters. */ | |
0101ce28 | 6660 | |
98deb0da | 6661 | static void |
a6d9a66e UW |
6662 | break_command_really (struct gdbarch *gdbarch, |
6663 | char *arg, char *cond_string, int thread, | |
60c46647 | 6664 | int parse_condition_and_thread, |
1042e4c0 | 6665 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
6666 | int ignore_count, |
6667 | enum auto_boolean pending_break_support, | |
604133b5 | 6668 | struct breakpoint_ops *ops, |
41447f92 VP |
6669 | int from_tty, |
6670 | int enabled) | |
c3f6f71d | 6671 | { |
71fff37b | 6672 | struct gdb_exception e; |
c3f6f71d | 6673 | struct symtabs_and_lines sals; |
0101ce28 | 6674 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
6675 | char *copy_arg; |
6676 | char *err_msg; | |
c3f6f71d JM |
6677 | char *addr_start = arg; |
6678 | char **addr_string; | |
6679 | struct cleanup *old_chain; | |
80c99de1 | 6680 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 6681 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 6682 | int i; |
0101ce28 | 6683 | int pending = 0; |
0101ce28 | 6684 | int not_found = 0; |
1042e4c0 | 6685 | enum bptype type_wanted; |
4a306c9a | 6686 | int task = 0; |
c3f6f71d | 6687 | |
c3f6f71d JM |
6688 | sals.sals = NULL; |
6689 | sals.nelts = 0; | |
6690 | addr_string = NULL; | |
c3f6f71d | 6691 | |
0101ce28 JJ |
6692 | parse_args.arg_p = &arg; |
6693 | parse_args.sals_p = &sals; | |
6694 | parse_args.addr_string_p = &addr_string; | |
6695 | parse_args.not_found_ptr = ¬_found; | |
6696 | ||
05ff989b AC |
6697 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
6698 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
6699 | |
6700 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 6701 | switch (e.reason) |
0101ce28 | 6702 | { |
05ff989b | 6703 | case RETURN_QUIT: |
98deb0da | 6704 | throw_exception (e); |
05ff989b AC |
6705 | case RETURN_ERROR: |
6706 | switch (e.error) | |
0101ce28 | 6707 | { |
05ff989b | 6708 | case NOT_FOUND_ERROR: |
0101ce28 | 6709 | |
05ff989b AC |
6710 | /* If pending breakpoint support is turned off, throw |
6711 | error. */ | |
fa8d40ab JJ |
6712 | |
6713 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
6714 | throw_exception (e); |
6715 | ||
6716 | exception_print (gdb_stderr, e); | |
fa8d40ab | 6717 | |
05ff989b AC |
6718 | /* If pending breakpoint support is auto query and the user |
6719 | selects no, then simply return the error code. */ | |
059fb39f PM |
6720 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
6721 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 6722 | return; |
fa8d40ab | 6723 | |
05ff989b AC |
6724 | /* At this point, either the user was queried about setting |
6725 | a pending breakpoint and selected yes, or pending | |
6726 | breakpoint behavior is on and thus a pending breakpoint | |
6727 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
6728 | copy_arg = xstrdup (addr_start); |
6729 | addr_string = ©_arg; | |
6730 | sals.nelts = 1; | |
6731 | sals.sals = &pending_sal; | |
6732 | pending_sal.pc = 0; | |
6733 | pending = 1; | |
05ff989b AC |
6734 | break; |
6735 | default: | |
98deb0da | 6736 | throw_exception (e); |
0101ce28 | 6737 | } |
05ff989b AC |
6738 | default: |
6739 | if (!sals.nelts) | |
98deb0da | 6740 | return; |
0101ce28 | 6741 | } |
c3f6f71d JM |
6742 | |
6743 | /* Create a chain of things that always need to be cleaned up. */ | |
6744 | old_chain = make_cleanup (null_cleanup, 0); | |
6745 | ||
0101ce28 JJ |
6746 | if (!pending) |
6747 | { | |
6748 | /* Make sure that all storage allocated to SALS gets freed. */ | |
6749 | make_cleanup (xfree, sals.sals); | |
6750 | ||
6751 | /* Cleanup the addr_string array but not its contents. */ | |
6752 | make_cleanup (xfree, addr_string); | |
6753 | } | |
c3f6f71d | 6754 | |
c3f6f71d JM |
6755 | /* ----------------------------- SNIP ----------------------------- |
6756 | Anything added to the cleanup chain beyond this point is assumed | |
6757 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
6758 | then the memory is not reclaimed. */ |
6759 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
6760 | |
6761 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 6762 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
6763 | for (i = 0; i < sals.nelts; i++) |
6764 | { | |
6765 | if (addr_string[i] != NULL) | |
b8c9b27d | 6766 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
6767 | } |
6768 | ||
6769 | /* Resolve all line numbers to PC's and verify that the addresses | |
6770 | are ok for the target. */ | |
0101ce28 JJ |
6771 | if (!pending) |
6772 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 6773 | |
1042e4c0 SS |
6774 | type_wanted = (traceflag |
6775 | ? bp_tracepoint | |
6776 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
6777 | ||
c3f6f71d JM |
6778 | /* Verify that condition can be parsed, before setting any |
6779 | breakpoints. Allocate a separate condition expression for each | |
6780 | breakpoint. */ | |
0101ce28 | 6781 | if (!pending) |
c3f6f71d | 6782 | { |
2f069f6f | 6783 | if (parse_condition_and_thread) |
72b2ff0e VP |
6784 | { |
6785 | /* Here we only parse 'arg' to separate condition | |
6786 | from thread number, so parsing in context of first | |
6787 | sal is OK. When setting the breakpoint we'll | |
6788 | re-parse it in context of each sal. */ | |
6789 | cond_string = NULL; | |
6790 | thread = -1; | |
4a306c9a JB |
6791 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
6792 | &thread, &task); | |
72b2ff0e VP |
6793 | if (cond_string) |
6794 | make_cleanup (xfree, cond_string); | |
6795 | } | |
2f069f6f | 6796 | else |
72b2ff0e VP |
6797 | { |
6798 | /* Create a private copy of condition string. */ | |
6799 | if (cond_string) | |
6800 | { | |
6801 | cond_string = xstrdup (cond_string); | |
6802 | make_cleanup (xfree, cond_string); | |
6803 | } | |
6804 | } | |
a6d9a66e | 6805 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 6806 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 6807 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 6808 | } |
0101ce28 JJ |
6809 | else |
6810 | { | |
fe3f5fa8 | 6811 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
6812 | struct breakpoint *b; |
6813 | ||
0101ce28 JJ |
6814 | make_cleanup (xfree, copy_arg); |
6815 | ||
a6d9a66e | 6816 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
6817 | set_breakpoint_count (breakpoint_count + 1); |
6818 | b->number = breakpoint_count; | |
72b2ff0e | 6819 | b->thread = -1; |
018d34a4 | 6820 | b->addr_string = addr_string[0]; |
72b2ff0e | 6821 | b->cond_string = NULL; |
0101ce28 | 6822 | b->ignore_count = ignore_count; |
0101ce28 | 6823 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 6824 | b->condition_not_parsed = 1; |
604133b5 | 6825 | b->ops = ops; |
41447f92 | 6826 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 6827 | b->pspace = current_program_space; |
74960c60 | 6828 | |
6c95b8df | 6829 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
6830 | && (b->type == bp_breakpoint |
6831 | || b->type == bp_hardware_breakpoint)) | |
6832 | b->enable_state = bp_startup_disabled; | |
6833 | ||
0101ce28 JJ |
6834 | mention (b); |
6835 | } | |
6836 | ||
c3f6f71d | 6837 | if (sals.nelts > 1) |
8a3fe4f8 AC |
6838 | warning (_("Multiple breakpoints were set.\n" |
6839 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6840 | /* That's it. Discard the cleanups for data inserted into the |
6841 | breakpoint. */ | |
6842 | discard_cleanups (bkpt_chain); | |
6843 | /* But cleanup everything else. */ | |
c3f6f71d | 6844 | do_cleanups (old_chain); |
217dc9e2 | 6845 | |
80c99de1 | 6846 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6847 | update_global_location_list (1); |
c3f6f71d | 6848 | } |
c906108c | 6849 | |
72b2ff0e VP |
6850 | /* Set a breakpoint. |
6851 | ARG is a string describing breakpoint address, | |
6852 | condition, and thread. | |
6853 | FLAG specifies if a breakpoint is hardware on, | |
6854 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6855 | and BP_TEMPFLAG. */ | |
6856 | ||
98deb0da | 6857 | static void |
72b2ff0e | 6858 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6859 | { |
72b2ff0e VP |
6860 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6861 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6862 | |
a6d9a66e UW |
6863 | break_command_really (get_current_arch (), |
6864 | arg, | |
98deb0da | 6865 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6866 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6867 | 0 /* Ignore count */, |
604133b5 AR |
6868 | pending_break_support, |
6869 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6870 | from_tty, |
6871 | 1 /* enabled */); | |
c906108c SS |
6872 | } |
6873 | ||
72b2ff0e | 6874 | |
98deb0da | 6875 | void |
a6d9a66e UW |
6876 | set_breakpoint (struct gdbarch *gdbarch, |
6877 | char *address, char *condition, | |
c3f6f71d | 6878 | int hardwareflag, int tempflag, |
ce43223b | 6879 | int thread, int ignore_count, |
41447f92 | 6880 | int pending, int enabled) |
c3f6f71d | 6881 | { |
a6d9a66e UW |
6882 | break_command_really (gdbarch, |
6883 | address, condition, thread, | |
98deb0da | 6884 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6885 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6886 | ignore_count, |
6887 | pending | |
6888 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6889 | NULL, 0, enabled); |
c3f6f71d JM |
6890 | } |
6891 | ||
6a048695 JB |
6892 | /* Adjust SAL to the first instruction past the function prologue. |
6893 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6894 | the debugging information. explicit_pc and explicit_line are |
6895 | not modified. | |
6a048695 JB |
6896 | |
6897 | If SAL is already past the prologue, then do nothing. */ | |
6898 | ||
6899 | static void | |
6900 | skip_prologue_sal (struct symtab_and_line *sal) | |
6901 | { | |
6c95b8df | 6902 | struct symbol *sym; |
6a048695 | 6903 | struct symtab_and_line start_sal; |
6c95b8df | 6904 | struct cleanup *old_chain; |
6a048695 | 6905 | |
6c95b8df | 6906 | old_chain = save_current_space_and_thread (); |
6a048695 | 6907 | |
6c95b8df PA |
6908 | sym = find_pc_function (sal->pc); |
6909 | if (sym != NULL) | |
3daf8fe5 | 6910 | { |
6c95b8df PA |
6911 | start_sal = find_function_start_sal (sym, 1); |
6912 | if (sal->pc < start_sal.pc) | |
6913 | { | |
6914 | start_sal.explicit_line = sal->explicit_line; | |
6915 | start_sal.explicit_pc = sal->explicit_pc; | |
6916 | *sal = start_sal; | |
6917 | } | |
3daf8fe5 | 6918 | } |
6c95b8df PA |
6919 | |
6920 | do_cleanups (old_chain); | |
6a048695 | 6921 | } |
c3f6f71d | 6922 | |
c906108c SS |
6923 | /* Helper function for break_command_1 and disassemble_command. */ |
6924 | ||
6925 | void | |
fba45db2 | 6926 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6927 | { |
6928 | CORE_ADDR pc; | |
6929 | ||
6930 | if (sal->pc == 0 && sal->symtab != NULL) | |
6931 | { | |
6932 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6933 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6934 | sal->line, sal->symtab->filename); |
6935 | sal->pc = pc; | |
6a048695 JB |
6936 | |
6937 | /* If this SAL corresponds to a breakpoint inserted using | |
6938 | a line number, then skip the function prologue if necessary. */ | |
6939 | if (sal->explicit_line) | |
56ef84b1 TT |
6940 | { |
6941 | /* Preserve the original line number. */ | |
6942 | int saved_line = sal->line; | |
6943 | skip_prologue_sal (sal); | |
6944 | sal->line = saved_line; | |
6945 | } | |
c906108c SS |
6946 | } |
6947 | ||
6948 | if (sal->section == 0 && sal->symtab != NULL) | |
6949 | { | |
6950 | struct blockvector *bv; | |
c5aa993b JM |
6951 | struct block *b; |
6952 | struct symbol *sym; | |
c906108c | 6953 | |
801e3a5b | 6954 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6955 | if (bv != NULL) |
6956 | { | |
7f0df278 | 6957 | sym = block_linkage_function (b); |
c906108c SS |
6958 | if (sym != NULL) |
6959 | { | |
6960 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6961 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6962 | } |
6963 | else | |
6964 | { | |
6965 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6966 | have to look harder. This case can be executed if we have |
6967 | line numbers but no functions (as can happen in assembly | |
6968 | source). */ | |
c906108c | 6969 | |
c5aa993b | 6970 | struct minimal_symbol *msym; |
6c95b8df PA |
6971 | struct cleanup *old_chain = save_current_space_and_thread (); |
6972 | ||
6973 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
6974 | |
6975 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6976 | if (msym) | |
714835d5 | 6977 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
6978 | |
6979 | do_cleanups (old_chain); | |
c906108c SS |
6980 | } |
6981 | } | |
6982 | } | |
6983 | } | |
6984 | ||
6985 | void | |
fba45db2 | 6986 | break_command (char *arg, int from_tty) |
c906108c | 6987 | { |
db107f19 | 6988 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6989 | } |
6990 | ||
c906108c | 6991 | void |
fba45db2 | 6992 | tbreak_command (char *arg, int from_tty) |
c906108c | 6993 | { |
db107f19 | 6994 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
6995 | } |
6996 | ||
c906108c | 6997 | static void |
fba45db2 | 6998 | hbreak_command (char *arg, int from_tty) |
c906108c | 6999 | { |
db107f19 | 7000 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7001 | } |
7002 | ||
7003 | static void | |
fba45db2 | 7004 | thbreak_command (char *arg, int from_tty) |
c906108c | 7005 | { |
db107f19 | 7006 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7007 | } |
7008 | ||
7009 | static void | |
fba45db2 | 7010 | stop_command (char *arg, int from_tty) |
c906108c | 7011 | { |
a3f17187 | 7012 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7013 | Usage: stop in <function | address>\n\ |
a3f17187 | 7014 | stop at <line>\n")); |
c906108c SS |
7015 | } |
7016 | ||
7017 | static void | |
fba45db2 | 7018 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7019 | { |
7020 | int badInput = 0; | |
7021 | ||
c5aa993b | 7022 | if (arg == (char *) NULL) |
c906108c SS |
7023 | badInput = 1; |
7024 | else if (*arg != '*') | |
7025 | { | |
7026 | char *argptr = arg; | |
7027 | int hasColon = 0; | |
7028 | ||
53a5351d JM |
7029 | /* look for a ':'. If this is a line number specification, then |
7030 | say it is bad, otherwise, it should be an address or | |
7031 | function/method name */ | |
c906108c | 7032 | while (*argptr && !hasColon) |
c5aa993b JM |
7033 | { |
7034 | hasColon = (*argptr == ':'); | |
7035 | argptr++; | |
7036 | } | |
c906108c SS |
7037 | |
7038 | if (hasColon) | |
c5aa993b | 7039 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7040 | else |
c5aa993b | 7041 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7042 | } |
7043 | ||
7044 | if (badInput) | |
a3f17187 | 7045 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7046 | else |
db107f19 | 7047 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7048 | } |
7049 | ||
7050 | static void | |
fba45db2 | 7051 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7052 | { |
7053 | int badInput = 0; | |
7054 | ||
c5aa993b | 7055 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7056 | badInput = 1; |
7057 | else | |
7058 | { | |
7059 | char *argptr = arg; | |
7060 | int hasColon = 0; | |
7061 | ||
7062 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7063 | it is probably a line number. */ |
c906108c | 7064 | while (*argptr && !hasColon) |
c5aa993b JM |
7065 | { |
7066 | hasColon = (*argptr == ':'); | |
7067 | argptr++; | |
7068 | } | |
c906108c SS |
7069 | |
7070 | if (hasColon) | |
c5aa993b | 7071 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7072 | else |
c5aa993b | 7073 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7074 | } |
7075 | ||
7076 | if (badInput) | |
a3f17187 | 7077 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7078 | else |
db107f19 | 7079 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7080 | } |
7081 | ||
53a5351d JM |
7082 | /* accessflag: hw_write: watch write, |
7083 | hw_read: watch read, | |
7084 | hw_access: watch access (read or write) */ | |
c906108c | 7085 | static void |
fba45db2 | 7086 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 7087 | { |
a6d9a66e | 7088 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 7089 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
7090 | struct expression *exp; |
7091 | struct block *exp_valid_block; | |
7092 | struct value *val, *mark; | |
7093 | struct frame_info *frame; | |
c906108c SS |
7094 | char *exp_start = NULL; |
7095 | char *exp_end = NULL; | |
37e4754d | 7096 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
7097 | int toklen; |
7098 | char *cond_start = NULL; | |
7099 | char *cond_end = NULL; | |
c906108c SS |
7100 | int i, other_type_used, target_resources_ok = 0; |
7101 | enum bptype bp_type; | |
7102 | int mem_cnt = 0; | |
37e4754d | 7103 | int thread = -1; |
c906108c | 7104 | |
37e4754d LM |
7105 | /* Make sure that we actually have parameters to parse. */ |
7106 | if (arg != NULL && arg[0] != '\0') | |
7107 | { | |
7108 | toklen = strlen (arg); /* Size of argument list. */ | |
7109 | ||
7110 | /* Points tok to the end of the argument list. */ | |
7111 | tok = arg + toklen - 1; | |
7112 | ||
7113 | /* Go backwards in the parameters list. Skip the last parameter. | |
7114 | If we're expecting a 'thread <thread_num>' parameter, this should | |
7115 | be the thread identifier. */ | |
7116 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7117 | tok--; | |
7118 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7119 | tok--; | |
7120 | ||
7121 | /* Points end_tok to the beginning of the last token. */ | |
7122 | id_tok_start = tok + 1; | |
7123 | ||
7124 | /* Go backwards in the parameters list. Skip one more parameter. | |
7125 | If we're expecting a 'thread <thread_num>' parameter, we should | |
7126 | reach a "thread" token. */ | |
7127 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7128 | tok--; | |
7129 | ||
7130 | end_tok = tok; | |
7131 | ||
7132 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7133 | tok--; | |
7134 | ||
7135 | /* Move the pointer forward to skip the whitespace and | |
7136 | calculate the length of the token. */ | |
7137 | tok++; | |
7138 | toklen = end_tok - tok; | |
7139 | ||
7140 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7141 | { | |
7142 | /* At this point we've found a "thread" token, which means | |
7143 | the user is trying to set a watchpoint that triggers | |
7144 | only in a specific thread. */ | |
7145 | char *endp; | |
7146 | ||
7147 | /* Extract the thread ID from the next token. */ | |
7148 | thread = strtol (id_tok_start, &endp, 0); | |
7149 | ||
7150 | /* Check if the user provided a valid numeric value for the | |
7151 | thread ID. */ | |
7152 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7153 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7154 | ||
7155 | /* Check if the thread actually exists. */ | |
7156 | if (!valid_thread_id (thread)) | |
7157 | error (_("Unknown thread %d."), thread); | |
7158 | ||
7159 | /* Truncate the string and get rid of the thread <thread_num> | |
7160 | parameter before the parameter list is parsed by the | |
7161 | evaluate_expression() function. */ | |
7162 | *tok = '\0'; | |
7163 | } | |
7164 | } | |
7165 | ||
7166 | /* Parse the rest of the arguments. */ | |
c906108c SS |
7167 | innermost_block = NULL; |
7168 | exp_start = arg; | |
7169 | exp = parse_exp_1 (&arg, 0, 0); | |
7170 | exp_end = arg; | |
fa8a61dc TT |
7171 | /* Remove trailing whitespace from the expression before saving it. |
7172 | This makes the eventual display of the expression string a bit | |
7173 | prettier. */ | |
7174 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7175 | --exp_end; | |
7176 | ||
c906108c SS |
7177 | exp_valid_block = innermost_block; |
7178 | mark = value_mark (); | |
fa4727a6 DJ |
7179 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7180 | if (val != NULL) | |
7181 | release_value (val); | |
c906108c SS |
7182 | |
7183 | tok = arg; | |
7184 | while (*tok == ' ' || *tok == '\t') | |
7185 | tok++; | |
7186 | end_tok = tok; | |
7187 | ||
7188 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7189 | end_tok++; | |
7190 | ||
7191 | toklen = end_tok - tok; | |
7192 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7193 | { | |
2d134ed3 PA |
7194 | struct expression *cond; |
7195 | ||
c906108c SS |
7196 | tok = cond_start = end_tok + 1; |
7197 | cond = parse_exp_1 (&tok, 0, 0); | |
2d134ed3 | 7198 | xfree (cond); |
c906108c SS |
7199 | cond_end = tok; |
7200 | } | |
7201 | if (*tok) | |
8a3fe4f8 | 7202 | error (_("Junk at end of command.")); |
c906108c | 7203 | |
53a5351d | 7204 | if (accessflag == hw_read) |
c5aa993b | 7205 | bp_type = bp_read_watchpoint; |
53a5351d | 7206 | else if (accessflag == hw_access) |
c5aa993b JM |
7207 | bp_type = bp_access_watchpoint; |
7208 | else | |
7209 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7210 | |
7211 | mem_cnt = can_use_hardware_watchpoint (val); | |
7212 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7213 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7214 | if (mem_cnt != 0) |
7215 | { | |
7216 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7217 | target_resources_ok = |
d92524f1 | 7218 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7219 | other_type_used); |
c5aa993b | 7220 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7221 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7222 | |
c5aa993b | 7223 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7224 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7225 | } |
c906108c | 7226 | |
4d28f7a8 KB |
7227 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7228 | watchpoint could not be set. */ | |
7229 | if (!mem_cnt || target_resources_ok <= 0) | |
7230 | bp_type = bp_watchpoint; | |
7231 | ||
d983da9c | 7232 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7233 | |
7234 | /* If the expression is "local", then set up a "watchpoint scope" | |
7235 | breakpoint at the point where we've left the scope of the watchpoint | |
7236 | expression. Create the scope breakpoint before the watchpoint, so | |
7237 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 7238 | if (innermost_block && frame) |
d983da9c | 7239 | { |
edb3359d DJ |
7240 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7241 | { | |
7242 | scope_breakpoint | |
a6d9a66e UW |
7243 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7244 | frame_unwind_caller_pc (frame), | |
edb3359d | 7245 | bp_watchpoint_scope); |
d983da9c | 7246 | |
edb3359d | 7247 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7248 | |
edb3359d DJ |
7249 | /* Automatically delete the breakpoint when it hits. */ |
7250 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7251 | |
edb3359d DJ |
7252 | /* Only break in the proper frame (help with recursion). */ |
7253 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7254 | |
edb3359d | 7255 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7256 | scope_breakpoint->loc->gdbarch |
7257 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7258 | scope_breakpoint->loc->requested_address |
7259 | = frame_unwind_caller_pc (frame); | |
7260 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7261 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7262 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7263 | scope_breakpoint->type); |
7264 | } | |
d983da9c DJ |
7265 | } |
7266 | ||
c906108c | 7267 | /* Now set up the breakpoint. */ |
2d134ed3 | 7268 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
7269 | set_breakpoint_count (breakpoint_count + 1); |
7270 | b->number = breakpoint_count; | |
37e4754d | 7271 | b->thread = thread; |
b5de0fa7 | 7272 | b->disposition = disp_donttouch; |
c906108c SS |
7273 | b->exp = exp; |
7274 | b->exp_valid_block = exp_valid_block; | |
7275 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
7276 | b->val = val; | |
fa4727a6 | 7277 | b->val_valid = 1; |
c906108c SS |
7278 | if (cond_start) |
7279 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7280 | else | |
7281 | b->cond_string = 0; | |
c5aa993b | 7282 | |
c906108c | 7283 | if (frame) |
f6bc2008 PA |
7284 | { |
7285 | b->watchpoint_frame = get_frame_id (frame); | |
7286 | b->watchpoint_thread = inferior_ptid; | |
7287 | } | |
c906108c | 7288 | else |
f6bc2008 PA |
7289 | { |
7290 | b->watchpoint_frame = null_frame_id; | |
7291 | b->watchpoint_thread = null_ptid; | |
7292 | } | |
c906108c | 7293 | |
d983da9c | 7294 | if (scope_breakpoint != NULL) |
c906108c | 7295 | { |
d983da9c DJ |
7296 | /* The scope breakpoint is related to the watchpoint. We will |
7297 | need to act on them together. */ | |
7298 | b->related_breakpoint = scope_breakpoint; | |
7299 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7300 | } |
d983da9c | 7301 | |
c906108c | 7302 | value_free_to_mark (mark); |
2d134ed3 PA |
7303 | |
7304 | /* Finally update the new watchpoint. This creates the locations | |
7305 | that should be inserted. */ | |
7306 | update_watchpoint (b, 1); | |
7307 | ||
c906108c | 7308 | mention (b); |
b60e7edf | 7309 | update_global_location_list (1); |
c906108c SS |
7310 | } |
7311 | ||
7312 | /* Return count of locations need to be watched and can be handled | |
7313 | in hardware. If the watchpoint can not be handled | |
7314 | in hardware return zero. */ | |
7315 | ||
c906108c | 7316 | static int |
fba45db2 | 7317 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7318 | { |
7319 | int found_memory_cnt = 0; | |
2e70b7b9 | 7320 | struct value *head = v; |
c906108c SS |
7321 | |
7322 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7323 | if (!can_use_hw_watchpoints) |
c906108c | 7324 | return 0; |
c5aa993b | 7325 | |
5c44784c JM |
7326 | /* Make sure that the value of the expression depends only upon |
7327 | memory contents, and values computed from them within GDB. If we | |
7328 | find any register references or function calls, we can't use a | |
7329 | hardware watchpoint. | |
7330 | ||
7331 | The idea here is that evaluating an expression generates a series | |
7332 | of values, one holding the value of every subexpression. (The | |
7333 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7334 | a*b+c.) GDB's values hold almost enough information to establish | |
7335 | the criteria given above --- they identify memory lvalues, | |
7336 | register lvalues, computed values, etcetera. So we can evaluate | |
7337 | the expression, and then scan the chain of values that leaves | |
7338 | behind to decide whether we can detect any possible change to the | |
7339 | expression's final value using only hardware watchpoints. | |
7340 | ||
7341 | However, I don't think that the values returned by inferior | |
7342 | function calls are special in any way. So this function may not | |
7343 | notice that an expression involving an inferior function call | |
7344 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7345 | for (; v; v = value_next (v)) |
c906108c | 7346 | { |
5c44784c | 7347 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7348 | { |
d69fe07e | 7349 | if (value_lazy (v)) |
5c44784c JM |
7350 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7351 | we either just used its address (e.g., `a' in `a.b') or | |
7352 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7353 | ; | |
53a5351d | 7354 | else |
5c44784c JM |
7355 | { |
7356 | /* Ahh, memory we actually used! Check if we can cover | |
7357 | it with hardware watchpoints. */ | |
df407dfe | 7358 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7359 | |
7360 | /* We only watch structs and arrays if user asked for it | |
7361 | explicitly, never if they just happen to appear in a | |
7362 | middle of some value chain. */ | |
7363 | if (v == head | |
7364 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7365 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7366 | { | |
42ae5230 | 7367 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7368 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7369 | |
d92524f1 | 7370 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7371 | return 0; |
7372 | else | |
7373 | found_memory_cnt++; | |
7374 | } | |
5c44784c | 7375 | } |
c5aa993b | 7376 | } |
5086187c AC |
7377 | else if (VALUE_LVAL (v) != not_lval |
7378 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7379 | return 0; /* ??? What does this represent? */ |
5086187c | 7380 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7381 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7382 | } |
7383 | ||
7384 | /* The expression itself looks suitable for using a hardware | |
7385 | watchpoint, but give the target machine a chance to reject it. */ | |
7386 | return found_memory_cnt; | |
7387 | } | |
7388 | ||
8b93c638 | 7389 | void |
fba45db2 | 7390 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7391 | { |
7392 | watch_command (arg, from_tty); | |
7393 | } | |
8926118c | 7394 | |
c5aa993b | 7395 | static void |
fba45db2 | 7396 | watch_command (char *arg, int from_tty) |
c906108c | 7397 | { |
53a5351d | 7398 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7399 | } |
7400 | ||
8b93c638 | 7401 | void |
fba45db2 | 7402 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7403 | { |
7404 | rwatch_command (arg, from_tty); | |
7405 | } | |
8926118c | 7406 | |
c5aa993b | 7407 | static void |
fba45db2 | 7408 | rwatch_command (char *arg, int from_tty) |
c906108c | 7409 | { |
53a5351d | 7410 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7411 | } |
7412 | ||
8b93c638 | 7413 | void |
fba45db2 | 7414 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7415 | { |
7416 | awatch_command (arg, from_tty); | |
7417 | } | |
8926118c | 7418 | |
c5aa993b | 7419 | static void |
fba45db2 | 7420 | awatch_command (char *arg, int from_tty) |
c906108c | 7421 | { |
53a5351d | 7422 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7423 | } |
c906108c | 7424 | \f |
c5aa993b | 7425 | |
43ff13b4 | 7426 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7427 | because it uses the mechanisms of breakpoints. */ |
7428 | ||
bfec99b2 PA |
7429 | struct until_break_command_continuation_args |
7430 | { | |
7431 | struct breakpoint *breakpoint; | |
7432 | struct breakpoint *breakpoint2; | |
7433 | }; | |
7434 | ||
43ff13b4 JM |
7435 | /* This function is called by fetch_inferior_event via the |
7436 | cmd_continuation pointer, to complete the until command. It takes | |
7437 | care of cleaning up the temporary breakpoints set up by the until | |
7438 | command. */ | |
c2c6d25f | 7439 | static void |
604ead4a | 7440 | until_break_command_continuation (void *arg) |
43ff13b4 | 7441 | { |
bfec99b2 PA |
7442 | struct until_break_command_continuation_args *a = arg; |
7443 | ||
7444 | delete_breakpoint (a->breakpoint); | |
7445 | if (a->breakpoint2) | |
7446 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
7447 | } |
7448 | ||
c906108c | 7449 | void |
ae66c1fc | 7450 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
7451 | { |
7452 | struct symtabs_and_lines sals; | |
7453 | struct symtab_and_line sal; | |
206415a3 | 7454 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 7455 | struct breakpoint *breakpoint; |
f107f563 | 7456 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
7457 | struct cleanup *old_chain; |
7458 | ||
7459 | clear_proceed_status (); | |
7460 | ||
7461 | /* Set a breakpoint where the user wants it and at return from | |
7462 | this function */ | |
c5aa993b | 7463 | |
c906108c SS |
7464 | if (default_breakpoint_valid) |
7465 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 7466 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 7467 | else |
53a5351d | 7468 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 7469 | 0, (char ***) NULL, NULL); |
c5aa993b | 7470 | |
c906108c | 7471 | if (sals.nelts != 1) |
8a3fe4f8 | 7472 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 7473 | |
c906108c | 7474 | sal = sals.sals[0]; |
b8c9b27d | 7475 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 7476 | |
c906108c | 7477 | if (*arg) |
8a3fe4f8 | 7478 | error (_("Junk at end of arguments.")); |
c5aa993b | 7479 | |
c906108c | 7480 | resolve_sal_pc (&sal); |
c5aa993b | 7481 | |
ae66c1fc EZ |
7482 | if (anywhere) |
7483 | /* If the user told us to continue until a specified location, | |
7484 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
7485 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7486 | null_frame_id, bp_until); | |
ae66c1fc | 7487 | else |
edb3359d | 7488 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 7489 | at the very same frame. */ |
a6d9a66e UW |
7490 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7491 | get_stack_frame_id (frame), | |
ae66c1fc | 7492 | bp_until); |
c5aa993b | 7493 | |
f107f563 | 7494 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 7495 | |
ae66c1fc EZ |
7496 | /* Keep within the current frame, or in frames called by the current |
7497 | one. */ | |
edb3359d DJ |
7498 | |
7499 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 7500 | { |
edb3359d DJ |
7501 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
7502 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
7503 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
7504 | sal, | |
edb3359d | 7505 | frame_unwind_caller_id (frame), |
f107f563 VP |
7506 | bp_until); |
7507 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 7508 | } |
c5aa993b | 7509 | |
c906108c | 7510 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
7511 | |
7512 | /* If we are running asynchronously, and proceed call above has actually | |
7513 | managed to start the target, arrange for breakpoints to be | |
7514 | deleted when the target stops. Otherwise, we're already stopped and | |
7515 | delete breakpoints via cleanup chain. */ | |
7516 | ||
8ea051c5 | 7517 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 7518 | { |
bfec99b2 PA |
7519 | struct until_break_command_continuation_args *args; |
7520 | args = xmalloc (sizeof (*args)); | |
f107f563 | 7521 | |
bfec99b2 PA |
7522 | args->breakpoint = breakpoint; |
7523 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
7524 | |
7525 | discard_cleanups (old_chain); | |
95e54da7 PA |
7526 | add_continuation (inferior_thread (), |
7527 | until_break_command_continuation, args, | |
604ead4a | 7528 | xfree); |
f107f563 VP |
7529 | } |
7530 | else | |
c5aa993b | 7531 | do_cleanups (old_chain); |
c906108c | 7532 | } |
ae66c1fc | 7533 | |
c906108c | 7534 | static void |
fba45db2 | 7535 | ep_skip_leading_whitespace (char **s) |
c906108c | 7536 | { |
c5aa993b JM |
7537 | if ((s == NULL) || (*s == NULL)) |
7538 | return; | |
7539 | while (isspace (**s)) | |
7540 | *s += 1; | |
c906108c | 7541 | } |
c5aa993b | 7542 | |
c906108c SS |
7543 | /* This function attempts to parse an optional "if <cond>" clause |
7544 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 7545 | |
c906108c SS |
7546 | Else, it returns a pointer to the condition string. (It does not |
7547 | attempt to evaluate the string against a particular block.) And, | |
7548 | it updates arg to point to the first character following the parsed | |
7549 | if clause in the arg string. */ | |
53a5351d | 7550 | |
c906108c | 7551 | static char * |
fba45db2 | 7552 | ep_parse_optional_if_clause (char **arg) |
c906108c | 7553 | { |
c5aa993b JM |
7554 | char *cond_string; |
7555 | ||
7556 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 7557 | return NULL; |
c5aa993b | 7558 | |
c906108c SS |
7559 | /* Skip the "if" keyword. */ |
7560 | (*arg) += 2; | |
c5aa993b | 7561 | |
c906108c SS |
7562 | /* Skip any extra leading whitespace, and record the start of the |
7563 | condition string. */ | |
7564 | ep_skip_leading_whitespace (arg); | |
7565 | cond_string = *arg; | |
c5aa993b | 7566 | |
c906108c SS |
7567 | /* Assume that the condition occupies the remainder of the arg string. */ |
7568 | (*arg) += strlen (cond_string); | |
c5aa993b | 7569 | |
c906108c SS |
7570 | return cond_string; |
7571 | } | |
c5aa993b | 7572 | |
c906108c SS |
7573 | /* This function attempts to parse an optional filename from the arg |
7574 | string. If one is not found, it returns NULL. | |
c5aa993b | 7575 | |
c906108c SS |
7576 | Else, it returns a pointer to the parsed filename. (This function |
7577 | makes no attempt to verify that a file of that name exists, or is | |
7578 | accessible.) And, it updates arg to point to the first character | |
7579 | following the parsed filename in the arg string. | |
c5aa993b | 7580 | |
c906108c SS |
7581 | Note that clients needing to preserve the returned filename for |
7582 | future access should copy it to their own buffers. */ | |
7583 | static char * | |
fba45db2 | 7584 | ep_parse_optional_filename (char **arg) |
c906108c | 7585 | { |
c5aa993b JM |
7586 | static char filename[1024]; |
7587 | char *arg_p = *arg; | |
7588 | int i; | |
7589 | char c; | |
7590 | ||
c906108c SS |
7591 | if ((*arg_p == '\0') || isspace (*arg_p)) |
7592 | return NULL; | |
c5aa993b JM |
7593 | |
7594 | for (i = 0;; i++) | |
c906108c SS |
7595 | { |
7596 | c = *arg_p; | |
7597 | if (isspace (c)) | |
c5aa993b | 7598 | c = '\0'; |
c906108c SS |
7599 | filename[i] = c; |
7600 | if (c == '\0') | |
c5aa993b | 7601 | break; |
c906108c SS |
7602 | arg_p++; |
7603 | } | |
7604 | *arg = arg_p; | |
c5aa993b | 7605 | |
c906108c SS |
7606 | return filename; |
7607 | } | |
c5aa993b | 7608 | |
c906108c SS |
7609 | /* Commands to deal with catching events, such as signals, exceptions, |
7610 | process start/exit, etc. */ | |
c5aa993b JM |
7611 | |
7612 | typedef enum | |
7613 | { | |
44feb3ce TT |
7614 | catch_fork_temporary, catch_vfork_temporary, |
7615 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
7616 | } |
7617 | catch_fork_kind; | |
7618 | ||
c906108c | 7619 | static void |
44feb3ce | 7620 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7621 | { |
a6d9a66e | 7622 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 7623 | char *cond_string = NULL; |
44feb3ce TT |
7624 | catch_fork_kind fork_kind; |
7625 | int tempflag; | |
7626 | ||
7627 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
7628 | tempflag = (fork_kind == catch_fork_temporary | |
7629 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 7630 | |
44feb3ce TT |
7631 | if (!arg) |
7632 | arg = ""; | |
c906108c | 7633 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7634 | |
c906108c | 7635 | /* The allowed syntax is: |
c5aa993b JM |
7636 | catch [v]fork |
7637 | catch [v]fork if <cond> | |
7638 | ||
c906108c SS |
7639 | First, check if there's an if clause. */ |
7640 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 7641 | |
c906108c | 7642 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 7643 | error (_("Junk at end of arguments.")); |
c5aa993b | 7644 | |
c906108c SS |
7645 | /* If this target supports it, create a fork or vfork catchpoint |
7646 | and enable reporting of such events. */ | |
c5aa993b JM |
7647 | switch (fork_kind) |
7648 | { | |
44feb3ce TT |
7649 | case catch_fork_temporary: |
7650 | case catch_fork_permanent: | |
a6d9a66e | 7651 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7652 | &catch_fork_breakpoint_ops); |
c906108c | 7653 | break; |
44feb3ce TT |
7654 | case catch_vfork_temporary: |
7655 | case catch_vfork_permanent: | |
a6d9a66e | 7656 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7657 | &catch_vfork_breakpoint_ops); |
c906108c | 7658 | break; |
c5aa993b | 7659 | default: |
8a3fe4f8 | 7660 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 7661 | break; |
c5aa993b | 7662 | } |
c906108c SS |
7663 | } |
7664 | ||
7665 | static void | |
44feb3ce | 7666 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7667 | { |
a6d9a66e | 7668 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7669 | int tempflag; |
c5aa993b | 7670 | char *cond_string = NULL; |
c906108c | 7671 | |
44feb3ce TT |
7672 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7673 | ||
7674 | if (!arg) | |
7675 | arg = ""; | |
c906108c SS |
7676 | ep_skip_leading_whitespace (&arg); |
7677 | ||
7678 | /* The allowed syntax is: | |
c5aa993b JM |
7679 | catch exec |
7680 | catch exec if <cond> | |
c906108c SS |
7681 | |
7682 | First, check if there's an if clause. */ | |
7683 | cond_string = ep_parse_optional_if_clause (&arg); | |
7684 | ||
7685 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7686 | error (_("Junk at end of arguments.")); |
c906108c SS |
7687 | |
7688 | /* If this target supports it, create an exec catchpoint | |
7689 | and enable reporting of such events. */ | |
a6d9a66e UW |
7690 | create_catchpoint (gdbarch, tempflag, cond_string, |
7691 | &catch_exec_breakpoint_ops); | |
c906108c | 7692 | } |
c5aa993b | 7693 | |
3086aeae DJ |
7694 | static enum print_stop_action |
7695 | print_exception_catchpoint (struct breakpoint *b) | |
7696 | { | |
ade92717 | 7697 | int bp_temp, bp_throw; |
3086aeae | 7698 | |
ade92717 | 7699 | annotate_catchpoint (b->number); |
3086aeae | 7700 | |
ade92717 AR |
7701 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7702 | if (b->loc->address != b->loc->requested_address) | |
7703 | breakpoint_adjustment_warning (b->loc->requested_address, | |
7704 | b->loc->address, | |
7705 | b->number, 1); | |
df2b6d2d | 7706 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7707 | ui_out_text (uiout, |
7708 | bp_temp ? "Temporary catchpoint " | |
7709 | : "Catchpoint "); | |
7710 | if (!ui_out_is_mi_like_p (uiout)) | |
7711 | ui_out_field_int (uiout, "bkptno", b->number); | |
7712 | ui_out_text (uiout, | |
c0b37c48 AR |
7713 | bp_throw ? " (exception thrown), " |
7714 | : " (exception caught), "); | |
ade92717 AR |
7715 | if (ui_out_is_mi_like_p (uiout)) |
7716 | { | |
7717 | ui_out_field_string (uiout, "reason", | |
7718 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
7719 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7720 | ui_out_field_int (uiout, "bkptno", b->number); | |
7721 | } | |
3086aeae DJ |
7722 | return PRINT_SRC_AND_LOC; |
7723 | } | |
7724 | ||
7725 | static void | |
a6d9a66e | 7726 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 7727 | { |
79a45b7d TT |
7728 | struct value_print_options opts; |
7729 | get_user_print_options (&opts); | |
7730 | if (opts.addressprint) | |
3086aeae DJ |
7731 | { |
7732 | annotate_field (4); | |
604133b5 AR |
7733 | if (b->loc == NULL || b->loc->shlib_disabled) |
7734 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
7735 | else | |
5af949e3 UW |
7736 | ui_out_field_core_addr (uiout, "addr", |
7737 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
7738 | } |
7739 | annotate_field (5); | |
604133b5 | 7740 | if (b->loc) |
a6d9a66e | 7741 | *last_loc = b->loc; |
3086aeae DJ |
7742 | if (strstr (b->addr_string, "throw") != NULL) |
7743 | ui_out_field_string (uiout, "what", "exception throw"); | |
7744 | else | |
7745 | ui_out_field_string (uiout, "what", "exception catch"); | |
7746 | } | |
7747 | ||
7748 | static void | |
7749 | print_mention_exception_catchpoint (struct breakpoint *b) | |
7750 | { | |
ade92717 AR |
7751 | int bp_temp; |
7752 | int bp_throw; | |
7753 | ||
df2b6d2d | 7754 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7755 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7756 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
7757 | : _("Catchpoint ")); | |
7758 | ui_out_field_int (uiout, "bkptno", b->number); | |
7759 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
7760 | : _(" (catch)")); | |
3086aeae DJ |
7761 | } |
7762 | ||
7763 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
7764 | NULL, /* insert */ |
7765 | NULL, /* remove */ | |
7766 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
7767 | print_exception_catchpoint, |
7768 | print_one_exception_catchpoint, | |
7769 | print_mention_exception_catchpoint | |
7770 | }; | |
7771 | ||
7772 | static int | |
7773 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
7774 | enum exception_event_kind ex_event, int from_tty) | |
7775 | { | |
604133b5 AR |
7776 | char *trigger_func_name; |
7777 | ||
3086aeae | 7778 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 7779 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 7780 | else |
604133b5 | 7781 | trigger_func_name = "__cxa_throw"; |
3086aeae | 7782 | |
a6d9a66e UW |
7783 | break_command_really (get_current_arch (), |
7784 | trigger_func_name, cond_string, -1, | |
604133b5 | 7785 | 0 /* condition and thread are valid. */, |
1042e4c0 | 7786 | tempflag, 0, 0, |
604133b5 AR |
7787 | 0, |
7788 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
7789 | &gnu_v3_exception_catchpoint_ops, from_tty, |
7790 | 1 /* enabled */); | |
3086aeae | 7791 | |
3086aeae DJ |
7792 | return 1; |
7793 | } | |
7794 | ||
c5aa993b | 7795 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
7796 | |
7797 | static void | |
fba45db2 KB |
7798 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
7799 | int tempflag, int from_tty) | |
c906108c | 7800 | { |
c5aa993b JM |
7801 | char *cond_string = NULL; |
7802 | struct symtab_and_line *sal = NULL; | |
7803 | ||
44feb3ce TT |
7804 | if (!arg) |
7805 | arg = ""; | |
c906108c | 7806 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7807 | |
c906108c SS |
7808 | cond_string = ep_parse_optional_if_clause (&arg); |
7809 | ||
7810 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7811 | error (_("Junk at end of arguments.")); |
c906108c | 7812 | |
059fb39f PM |
7813 | if (ex_event != EX_EVENT_THROW |
7814 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7815 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7816 | |
3086aeae DJ |
7817 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7818 | return; | |
7819 | ||
8a3fe4f8 | 7820 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
7821 | } |
7822 | ||
44feb3ce TT |
7823 | /* Implementation of "catch catch" command. */ |
7824 | ||
7825 | static void | |
7826 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7827 | { | |
7828 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7829 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
7830 | } | |
7831 | ||
7832 | /* Implementation of "catch throw" command. */ | |
7833 | ||
7834 | static void | |
7835 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7836 | { | |
7837 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7838 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
7839 | } | |
7840 | ||
f7f9143b JB |
7841 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
7842 | ||
7843 | static void | |
a6d9a66e UW |
7844 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
7845 | struct symtab_and_line sal, | |
f7f9143b JB |
7846 | char *addr_string, |
7847 | char *exp_string, | |
7848 | char *cond_string, | |
7849 | struct expression *cond, | |
7850 | struct breakpoint_ops *ops, | |
7851 | int tempflag, | |
7852 | int from_tty) | |
7853 | { | |
7854 | struct breakpoint *b; | |
7855 | ||
7856 | if (from_tty) | |
7857 | { | |
5af949e3 UW |
7858 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
7859 | if (!loc_gdbarch) | |
7860 | loc_gdbarch = gdbarch; | |
7861 | ||
6c95b8df PA |
7862 | describe_other_breakpoints (loc_gdbarch, |
7863 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
7864 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7865 | version for exception catchpoints, because two catchpoints | |
7866 | used for different exception names will use the same address. | |
7867 | In this case, a "breakpoint ... also set at..." warning is | |
7868 | unproductive. Besides. the warning phrasing is also a bit | |
7869 | inapropriate, we should use the word catchpoint, and tell | |
7870 | the user what type of catchpoint it is. The above is good | |
7871 | enough for now, though. */ | |
7872 | } | |
7873 | ||
a6d9a66e | 7874 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7875 | set_breakpoint_count (breakpoint_count + 1); |
7876 | ||
7877 | b->enable_state = bp_enabled; | |
7878 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7879 | b->number = breakpoint_count; | |
7880 | b->ignore_count = 0; | |
511a6cd4 | 7881 | b->loc->cond = cond; |
f7f9143b JB |
7882 | b->addr_string = addr_string; |
7883 | b->language = language_ada; | |
7884 | b->cond_string = cond_string; | |
7885 | b->exp_string = exp_string; | |
7886 | b->thread = -1; | |
7887 | b->ops = ops; | |
f7f9143b JB |
7888 | |
7889 | mention (b); | |
b60e7edf | 7890 | update_global_location_list (1); |
f7f9143b JB |
7891 | } |
7892 | ||
7893 | /* Implement the "catch exception" command. */ | |
7894 | ||
7895 | static void | |
44feb3ce TT |
7896 | catch_ada_exception_command (char *arg, int from_tty, |
7897 | struct cmd_list_element *command) | |
f7f9143b | 7898 | { |
a6d9a66e | 7899 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7900 | int tempflag; |
f7f9143b JB |
7901 | struct symtab_and_line sal; |
7902 | enum bptype type; | |
7903 | char *addr_string = NULL; | |
7904 | char *exp_string = NULL; | |
7905 | char *cond_string = NULL; | |
7906 | struct expression *cond = NULL; | |
7907 | struct breakpoint_ops *ops = NULL; | |
7908 | ||
44feb3ce TT |
7909 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7910 | ||
7911 | if (!arg) | |
7912 | arg = ""; | |
f7f9143b JB |
7913 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7914 | &cond_string, &cond, &ops); | |
a6d9a66e | 7915 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7916 | cond_string, cond, ops, tempflag, |
7917 | from_tty); | |
7918 | } | |
7919 | ||
a96d9b2e SDJ |
7920 | /* Cleanup function for a syscall filter list. */ |
7921 | static void | |
7922 | clean_up_filters (void *arg) | |
7923 | { | |
7924 | VEC(int) *iter = *(VEC(int) **) arg; | |
7925 | VEC_free (int, iter); | |
7926 | } | |
7927 | ||
7928 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
7929 | filter list, or NULL if no filtering is required. */ | |
7930 | static VEC(int) * | |
7931 | catch_syscall_split_args (char *arg) | |
7932 | { | |
7933 | VEC(int) *result = NULL; | |
7934 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
7935 | ||
7936 | while (*arg != '\0') | |
7937 | { | |
7938 | int i, syscall_number; | |
7939 | char *endptr; | |
7940 | char cur_name[128]; | |
7941 | struct syscall s; | |
7942 | ||
7943 | /* Skip whitespace. */ | |
7944 | while (isspace (*arg)) | |
7945 | arg++; | |
7946 | ||
7947 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
7948 | cur_name[i] = arg[i]; | |
7949 | cur_name[i] = '\0'; | |
7950 | arg += i; | |
7951 | ||
7952 | /* Check if the user provided a syscall name or a number. */ | |
7953 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
7954 | if (*endptr == '\0') | |
bccd0dd2 | 7955 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
7956 | else |
7957 | { | |
7958 | /* We have a name. Let's check if it's valid and convert it | |
7959 | to a number. */ | |
7960 | get_syscall_by_name (cur_name, &s); | |
7961 | ||
7962 | if (s.number == UNKNOWN_SYSCALL) | |
7963 | /* Here we have to issue an error instead of a warning, because | |
7964 | GDB cannot do anything useful if there's no syscall number to | |
7965 | be caught. */ | |
7966 | error (_("Unknown syscall name '%s'."), cur_name); | |
7967 | } | |
7968 | ||
7969 | /* Ok, it's valid. */ | |
7970 | VEC_safe_push (int, result, s.number); | |
7971 | } | |
7972 | ||
7973 | discard_cleanups (cleanup); | |
7974 | return result; | |
7975 | } | |
7976 | ||
7977 | /* Implement the "catch syscall" command. */ | |
7978 | ||
7979 | static void | |
7980 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
7981 | { | |
7982 | int tempflag; | |
7983 | VEC(int) *filter; | |
7984 | struct syscall s; | |
7985 | struct gdbarch *gdbarch = get_current_arch (); | |
7986 | ||
7987 | /* Checking if the feature if supported. */ | |
7988 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
7989 | error (_("The feature 'catch syscall' is not supported on \ | |
7990 | this architeture yet.")); | |
7991 | ||
7992 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7993 | ||
7994 | ep_skip_leading_whitespace (&arg); | |
7995 | ||
7996 | /* We need to do this first "dummy" translation in order | |
7997 | to get the syscall XML file loaded or, most important, | |
7998 | to display a warning to the user if there's no XML file | |
7999 | for his/her architecture. */ | |
8000 | get_syscall_by_number (0, &s); | |
8001 | ||
8002 | /* The allowed syntax is: | |
8003 | catch syscall | |
8004 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8005 | ||
8006 | Let's check if there's a syscall name. */ | |
8007 | ||
8008 | if (arg != NULL) | |
8009 | filter = catch_syscall_split_args (arg); | |
8010 | else | |
8011 | filter = NULL; | |
8012 | ||
8013 | create_syscall_event_catchpoint (tempflag, filter, | |
8014 | &catch_syscall_breakpoint_ops); | |
8015 | } | |
8016 | ||
f7f9143b JB |
8017 | /* Implement the "catch assert" command. */ |
8018 | ||
8019 | static void | |
44feb3ce | 8020 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8021 | { |
a6d9a66e | 8022 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8023 | int tempflag; |
f7f9143b JB |
8024 | struct symtab_and_line sal; |
8025 | char *addr_string = NULL; | |
8026 | struct breakpoint_ops *ops = NULL; | |
8027 | ||
44feb3ce TT |
8028 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8029 | ||
8030 | if (!arg) | |
8031 | arg = ""; | |
f7f9143b | 8032 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
8033 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
8034 | ops, tempflag, from_tty); | |
f7f9143b JB |
8035 | } |
8036 | ||
c906108c | 8037 | static void |
fba45db2 | 8038 | catch_command (char *arg, int from_tty) |
c906108c | 8039 | { |
44feb3ce | 8040 | error (_("Catch requires an event name.")); |
c906108c SS |
8041 | } |
8042 | \f | |
8043 | ||
8044 | static void | |
fba45db2 | 8045 | tcatch_command (char *arg, int from_tty) |
c906108c | 8046 | { |
44feb3ce | 8047 | error (_("Catch requires an event name.")); |
c906108c SS |
8048 | } |
8049 | ||
80f8a6eb | 8050 | /* Delete breakpoints by address or line. */ |
c906108c SS |
8051 | |
8052 | static void | |
fba45db2 | 8053 | clear_command (char *arg, int from_tty) |
c906108c | 8054 | { |
d6e956e5 VP |
8055 | struct breakpoint *b; |
8056 | VEC(breakpoint_p) *found = 0; | |
8057 | int ix; | |
c906108c SS |
8058 | int default_match; |
8059 | struct symtabs_and_lines sals; | |
8060 | struct symtab_and_line sal; | |
c906108c SS |
8061 | int i; |
8062 | ||
8063 | if (arg) | |
8064 | { | |
8065 | sals = decode_line_spec (arg, 1); | |
8066 | default_match = 0; | |
8067 | } | |
8068 | else | |
8069 | { | |
c5aa993b | 8070 | sals.sals = (struct symtab_and_line *) |
c906108c | 8071 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 8072 | make_cleanup (xfree, sals.sals); |
fe39c653 | 8073 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
8074 | sal.line = default_breakpoint_line; |
8075 | sal.symtab = default_breakpoint_symtab; | |
8076 | sal.pc = default_breakpoint_address; | |
6c95b8df | 8077 | sal.pspace = default_breakpoint_pspace; |
c906108c | 8078 | if (sal.symtab == 0) |
8a3fe4f8 | 8079 | error (_("No source file specified.")); |
c906108c SS |
8080 | |
8081 | sals.sals[0] = sal; | |
8082 | sals.nelts = 1; | |
8083 | ||
8084 | default_match = 1; | |
8085 | } | |
8086 | ||
ed0616c6 VP |
8087 | /* We don't call resolve_sal_pc here. That's not |
8088 | as bad as it seems, because all existing breakpoints | |
8089 | typically have both file/line and pc set. So, if | |
8090 | clear is given file/line, we can match this to existing | |
8091 | breakpoint without obtaining pc at all. | |
8092 | ||
8093 | We only support clearing given the address explicitly | |
8094 | present in breakpoint table. Say, we've set breakpoint | |
8095 | at file:line. There were several PC values for that file:line, | |
8096 | due to optimization, all in one block. | |
8097 | We've picked one PC value. If "clear" is issued with another | |
8098 | PC corresponding to the same file:line, the breakpoint won't | |
8099 | be cleared. We probably can still clear the breakpoint, but | |
8100 | since the other PC value is never presented to user, user | |
8101 | can only find it by guessing, and it does not seem important | |
8102 | to support that. */ | |
8103 | ||
c906108c | 8104 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
8105 | to it. Do it in two passes, solely to preserve the current |
8106 | behavior that from_tty is forced true if we delete more than | |
8107 | one breakpoint. */ | |
c906108c | 8108 | |
80f8a6eb | 8109 | found = NULL; |
c906108c SS |
8110 | for (i = 0; i < sals.nelts; i++) |
8111 | { | |
8112 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
8113 | If line given (pc == 0), clear all bpts on specified line. |
8114 | If defaulting, clear all bpts on default line | |
c906108c | 8115 | or at default pc. |
c5aa993b JM |
8116 | |
8117 | defaulting sal.pc != 0 tests to do | |
8118 | ||
8119 | 0 1 pc | |
8120 | 1 1 pc _and_ line | |
8121 | 0 0 line | |
8122 | 1 0 <can't happen> */ | |
c906108c SS |
8123 | |
8124 | sal = sals.sals[i]; | |
c906108c | 8125 | |
d6e956e5 VP |
8126 | /* Find all matching breakpoints and add them to |
8127 | 'found'. */ | |
8128 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8129 | { |
0d381245 | 8130 | int match = 0; |
80f8a6eb MS |
8131 | /* Are we going to delete b? */ |
8132 | if (b->type != bp_none | |
8133 | && b->type != bp_watchpoint | |
8134 | && b->type != bp_hardware_watchpoint | |
8135 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8136 | && b->type != bp_access_watchpoint) |
8137 | { | |
8138 | struct bp_location *loc = b->loc; | |
8139 | for (; loc; loc = loc->next) | |
8140 | { | |
6c95b8df PA |
8141 | int pc_match = sal.pc |
8142 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8143 | && (loc->address == sal.pc) |
8144 | && (!section_is_overlay (loc->section) | |
8145 | || loc->section == sal.section); | |
8146 | int line_match = ((default_match || (0 == sal.pc)) | |
8147 | && b->source_file != NULL | |
8148 | && sal.symtab != NULL | |
6c95b8df | 8149 | && sal.pspace == loc->pspace |
0d381245 VP |
8150 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8151 | && b->line_number == sal.line); | |
8152 | if (pc_match || line_match) | |
8153 | { | |
8154 | match = 1; | |
8155 | break; | |
8156 | } | |
8157 | } | |
8158 | } | |
8159 | ||
8160 | if (match) | |
d6e956e5 | 8161 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8162 | } |
80f8a6eb MS |
8163 | } |
8164 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8165 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8166 | { |
8167 | if (arg) | |
8a3fe4f8 | 8168 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8169 | else |
8a3fe4f8 | 8170 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8171 | } |
c906108c | 8172 | |
d6e956e5 | 8173 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8174 | from_tty = 1; /* Always report if deleted more than one */ |
8175 | if (from_tty) | |
a3f17187 | 8176 | { |
d6e956e5 | 8177 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8178 | printf_unfiltered (_("Deleted breakpoint ")); |
8179 | else | |
8180 | printf_unfiltered (_("Deleted breakpoints ")); | |
8181 | } | |
80f8a6eb | 8182 | breakpoints_changed (); |
d6e956e5 VP |
8183 | |
8184 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8185 | { |
c5aa993b | 8186 | if (from_tty) |
d6e956e5 VP |
8187 | printf_unfiltered ("%d ", b->number); |
8188 | delete_breakpoint (b); | |
c906108c | 8189 | } |
80f8a6eb MS |
8190 | if (from_tty) |
8191 | putchar_unfiltered ('\n'); | |
c906108c SS |
8192 | } |
8193 | \f | |
8194 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8195 | all breakpoints that are marked for deletion, whether hit or not. | |
8196 | This is called after any breakpoint is hit, or after errors. */ | |
8197 | ||
8198 | void | |
fba45db2 | 8199 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8200 | { |
8201 | struct breakpoint *b, *temp; | |
8202 | ||
8203 | for (; bs; bs = bs->next) | |
20874c92 VP |
8204 | if (bs->breakpoint_at |
8205 | && bs->breakpoint_at->owner | |
8206 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8207 | && bs->stop) |
4f8d1dc6 | 8208 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8209 | |
8210 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8211 | { |
b5de0fa7 | 8212 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8213 | delete_breakpoint (b); |
8214 | } | |
c906108c SS |
8215 | } |
8216 | ||
494cfb0f | 8217 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
8218 | Sort elements primarily by their ADDRESS (no matter what does |
8219 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8220 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8221 | is sorted stable way despite qsort being an instable algorithm. */ | |
8222 | ||
8223 | static int | |
494cfb0f | 8224 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 8225 | { |
494cfb0f JK |
8226 | struct bp_location *a = *(void **) ap; |
8227 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
8228 | int a_perm = a->owner->enable_state == bp_permanent; |
8229 | int b_perm = b->owner->enable_state == bp_permanent; | |
8230 | ||
8231 | if (a->address != b->address) | |
8232 | return (a->address > b->address) - (a->address < b->address); | |
8233 | ||
8234 | /* Sort permanent breakpoints first. */ | |
8235 | if (a_perm != b_perm) | |
8236 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8237 | ||
8238 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8239 | breakpoint can be sorted in arbitrary order. */ | |
8240 | ||
8241 | if (a->owner->number != b->owner->number) | |
8242 | return (a->owner->number > b->owner->number) | |
8243 | - (a->owner->number < b->owner->number); | |
8244 | ||
8245 | return (a > b) - (a < b); | |
8246 | } | |
8247 | ||
876fa593 JK |
8248 | /* Set bp_location_placed_address_before_address_max and |
8249 | bp_location_shadow_len_after_address_max according to the current content of | |
8250 | the bp_location array. */ | |
f7545552 TT |
8251 | |
8252 | static void | |
876fa593 | 8253 | bp_location_target_extensions_update (void) |
f7545552 | 8254 | { |
876fa593 JK |
8255 | struct bp_location *bl, **blp_tmp; |
8256 | ||
8257 | bp_location_placed_address_before_address_max = 0; | |
8258 | bp_location_shadow_len_after_address_max = 0; | |
8259 | ||
8260 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8261 | { | |
8262 | CORE_ADDR start, end, addr; | |
8263 | ||
8264 | if (!bp_location_has_shadow (bl)) | |
8265 | continue; | |
8266 | ||
8267 | start = bl->target_info.placed_address; | |
8268 | end = start + bl->target_info.shadow_len; | |
8269 | ||
8270 | gdb_assert (bl->address >= start); | |
8271 | addr = bl->address - start; | |
8272 | if (addr > bp_location_placed_address_before_address_max) | |
8273 | bp_location_placed_address_before_address_max = addr; | |
8274 | ||
8275 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8276 | ||
8277 | gdb_assert (bl->address < end); | |
8278 | addr = end - bl->address; | |
8279 | if (addr > bp_location_shadow_len_after_address_max) | |
8280 | bp_location_shadow_len_after_address_max = addr; | |
8281 | } | |
f7545552 TT |
8282 | } |
8283 | ||
4cd9bd08 | 8284 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8285 | into the inferior, only remove already-inserted locations that no |
8286 | longer should be inserted. Functions that delete a breakpoint or | |
8287 | breakpoints should pass false, so that deleting a breakpoint | |
8288 | doesn't have the side effect of inserting the locations of other | |
8289 | breakpoints that are marked not-inserted, but should_be_inserted | |
8290 | returns true on them. | |
8291 | ||
8292 | This behaviour is useful is situations close to tear-down -- e.g., | |
8293 | after an exec, while the target still has execution, but breakpoint | |
8294 | shadows of the previous executable image should *NOT* be restored | |
8295 | to the new image; or before detaching, where the target still has | |
8296 | execution and wants to delete breakpoints from GDB's lists, and all | |
8297 | breakpoints had already been removed from the inferior. */ | |
8298 | ||
0d381245 | 8299 | static void |
b60e7edf | 8300 | update_global_location_list (int should_insert) |
0d381245 | 8301 | { |
74960c60 | 8302 | struct breakpoint *b; |
876fa593 | 8303 | struct bp_location **locp, *loc; |
f7545552 TT |
8304 | struct cleanup *cleanups; |
8305 | ||
2d134ed3 PA |
8306 | /* Used in the duplicates detection below. When iterating over all |
8307 | bp_locations, points to the first bp_location of a given address. | |
8308 | Breakpoints and watchpoints of different types are never | |
8309 | duplicates of each other. Keep one pointer for each type of | |
8310 | breakpoint/watchpoint, so we only need to loop over all locations | |
8311 | once. */ | |
8312 | struct bp_location *bp_loc_first; /* breakpoint */ | |
8313 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
8314 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
8315 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
8316 | |
8317 | /* Saved former bp_location array which we compare against the newly built | |
8318 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8319 | struct bp_location **old_location, **old_locp; | |
8320 | unsigned old_location_count; | |
8321 | ||
8322 | old_location = bp_location; | |
8323 | old_location_count = bp_location_count; | |
8324 | bp_location = NULL; | |
8325 | bp_location_count = 0; | |
8326 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8327 | |
74960c60 | 8328 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8329 | for (loc = b->loc; loc; loc = loc->next) |
8330 | bp_location_count++; | |
8331 | ||
8332 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8333 | locp = bp_location; | |
8334 | ALL_BREAKPOINTS (b) | |
8335 | for (loc = b->loc; loc; loc = loc->next) | |
8336 | *locp++ = loc; | |
8337 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 8338 | bp_location_compare); |
876fa593 JK |
8339 | |
8340 | bp_location_target_extensions_update (); | |
74960c60 VP |
8341 | |
8342 | /* Identify bp_location instances that are no longer present in the new | |
8343 | list, and therefore should be freed. Note that it's not necessary that | |
8344 | those locations should be removed from inferior -- if there's another | |
8345 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8346 | we don't need to remove/insert the location. |
8347 | ||
8348 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8349 | former bp_location array state respectively. */ | |
8350 | ||
8351 | locp = bp_location; | |
8352 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8353 | old_locp++) | |
74960c60 | 8354 | { |
876fa593 | 8355 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 8356 | struct bp_location **loc2p; |
876fa593 JK |
8357 | |
8358 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8359 | have to free it. */ |
c7d46a38 | 8360 | int found_object = 0; |
20874c92 VP |
8361 | /* Tells if the location should remain inserted in the target. */ |
8362 | int keep_in_target = 0; | |
8363 | int removed = 0; | |
876fa593 JK |
8364 | |
8365 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8366 | at or being the one matching OLD_LOC. */ | |
8367 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 8368 | && (*locp)->address < old_loc->address) |
876fa593 | 8369 | locp++; |
c7d46a38 PA |
8370 | |
8371 | for (loc2p = locp; | |
8372 | (loc2p < bp_location + bp_location_count | |
8373 | && (*loc2p)->address == old_loc->address); | |
8374 | loc2p++) | |
8375 | { | |
8376 | if (*loc2p == old_loc) | |
8377 | { | |
8378 | found_object = 1; | |
8379 | break; | |
8380 | } | |
8381 | } | |
74960c60 VP |
8382 | |
8383 | /* If this location is no longer present, and inserted, look if there's | |
8384 | maybe a new location at the same address. If so, mark that one | |
8385 | inserted, and don't remove this one. This is needed so that we | |
8386 | don't have a time window where a breakpoint at certain location is not | |
8387 | inserted. */ | |
8388 | ||
876fa593 | 8389 | if (old_loc->inserted) |
0d381245 | 8390 | { |
74960c60 | 8391 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8392 | |
876fa593 | 8393 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8394 | { |
8395 | /* The location is still present in the location list, and still | |
8396 | should be inserted. Don't do anything. */ | |
20874c92 | 8397 | keep_in_target = 1; |
74960c60 VP |
8398 | } |
8399 | else | |
8400 | { | |
8401 | /* The location is either no longer present, or got disabled. | |
8402 | See if there's another location at the same address, in which | |
8403 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8404 | |
8405 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8406 | { | |
876fa593 | 8407 | for (loc2p = locp; |
c7d46a38 PA |
8408 | (loc2p < bp_location + bp_location_count |
8409 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
8410 | loc2p++) |
8411 | { | |
8412 | struct bp_location *loc2 = *loc2p; | |
8413 | ||
2d134ed3 | 8414 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
8415 | { |
8416 | /* For the sake of should_be_inserted. | |
8417 | Duplicates check below will fix up this later. */ | |
8418 | loc2->duplicate = 0; | |
8419 | if (loc2 != old_loc && should_be_inserted (loc2)) | |
8420 | { | |
8421 | loc2->inserted = 1; | |
8422 | loc2->target_info = old_loc->target_info; | |
8423 | keep_in_target = 1; | |
8424 | break; | |
8425 | } | |
876fa593 JK |
8426 | } |
8427 | } | |
8428 | } | |
74960c60 VP |
8429 | } |
8430 | ||
20874c92 VP |
8431 | if (!keep_in_target) |
8432 | { | |
876fa593 | 8433 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8434 | { |
8435 | /* This is just about all we can do. We could keep this | |
8436 | location on the global list, and try to remove it next | |
8437 | time, but there's no particular reason why we will | |
8438 | succeed next time. | |
8439 | ||
876fa593 | 8440 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8441 | as delete_breakpoint frees the breakpoint only |
8442 | after calling us. */ | |
8443 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 8444 | old_loc->owner->number); |
20874c92 VP |
8445 | } |
8446 | removed = 1; | |
8447 | } | |
0d381245 | 8448 | } |
74960c60 VP |
8449 | |
8450 | if (!found_object) | |
1c5cfe86 | 8451 | { |
db82e815 PA |
8452 | if (removed && non_stop |
8453 | && breakpoint_address_is_meaningful (old_loc->owner) | |
8454 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 8455 | { |
db82e815 PA |
8456 | /* This location was removed from the target. In |
8457 | non-stop mode, a race condition is possible where | |
8458 | we've removed a breakpoint, but stop events for that | |
8459 | breakpoint are already queued and will arrive later. | |
8460 | We apply an heuristic to be able to distinguish such | |
8461 | SIGTRAPs from other random SIGTRAPs: we keep this | |
8462 | breakpoint location for a bit, and will retire it | |
8463 | after we see some number of events. The theory here | |
8464 | is that reporting of events should, "on the average", | |
8465 | be fair, so after a while we'll see events from all | |
8466 | threads that have anything of interest, and no longer | |
8467 | need to keep this breakpoint location around. We | |
8468 | don't hold locations forever so to reduce chances of | |
8469 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
8470 | SIGTRAP. | |
8471 | ||
8472 | The heuristic failing can be disastrous on | |
8473 | decr_pc_after_break targets. | |
8474 | ||
8475 | On decr_pc_after_break targets, like e.g., x86-linux, | |
8476 | if we fail to recognize a late breakpoint SIGTRAP, | |
8477 | because events_till_retirement has reached 0 too | |
8478 | soon, we'll fail to do the PC adjustment, and report | |
8479 | a random SIGTRAP to the user. When the user resumes | |
8480 | the inferior, it will most likely immediately crash | |
8481 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently | |
8482 | corrupted, because of being resumed e.g., in the | |
8483 | middle of a multi-byte instruction, or skipped a | |
8484 | one-byte instruction. This was actually seen happen | |
8485 | on native x86-linux, and should be less rare on | |
8486 | targets that do not support new thread events, like | |
8487 | remote, due to the heuristic depending on | |
8488 | thread_count. | |
8489 | ||
8490 | Mistaking a random SIGTRAP for a breakpoint trap | |
8491 | causes similar symptoms (PC adjustment applied when | |
8492 | it shouldn't), but then again, playing with SIGTRAPs | |
8493 | behind the debugger's back is asking for trouble. | |
8494 | ||
8495 | Since hardware watchpoint traps are always | |
8496 | distinguishable from other traps, so we don't need to | |
8497 | apply keep hardware watchpoint moribund locations | |
8498 | around. We simply always ignore hardware watchpoint | |
8499 | traps we can no longer explain. */ | |
8500 | ||
876fa593 JK |
8501 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
8502 | old_loc->owner = NULL; | |
20874c92 | 8503 | |
876fa593 | 8504 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
8505 | } |
8506 | else | |
876fa593 | 8507 | free_bp_location (old_loc); |
20874c92 | 8508 | } |
74960c60 | 8509 | } |
1c5cfe86 | 8510 | |
2d134ed3 PA |
8511 | /* Rescan breakpoints at the same address and section, marking the |
8512 | first one as "first" and any others as "duplicates". This is so | |
8513 | that the bpt instruction is only inserted once. If we have a | |
8514 | permanent breakpoint at the same place as BPT, make that one the | |
8515 | official one, and the rest as duplicates. Permanent breakpoints | |
8516 | are sorted first for the same address. | |
8517 | ||
8518 | Do the same for hardware watchpoints, but also considering the | |
8519 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 8520 | |
2d134ed3 PA |
8521 | bp_loc_first = NULL; |
8522 | wp_loc_first = NULL; | |
8523 | awp_loc_first = NULL; | |
8524 | rwp_loc_first = NULL; | |
876fa593 | 8525 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 8526 | { |
876fa593 | 8527 | struct breakpoint *b = loc->owner; |
2d134ed3 | 8528 | struct bp_location **loc_first_p; |
876fa593 JK |
8529 | |
8530 | if (b->enable_state == bp_disabled | |
8531 | || b->enable_state == bp_call_disabled | |
8532 | || b->enable_state == bp_startup_disabled | |
8533 | || !loc->enabled | |
8534 | || loc->shlib_disabled | |
8535 | || !breakpoint_address_is_meaningful (b)) | |
8536 | continue; | |
8537 | ||
8538 | /* Permanent breakpoint should always be inserted. */ | |
8539 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
8540 | internal_error (__FILE__, __LINE__, | |
8541 | _("allegedly permanent breakpoint is not " | |
8542 | "actually inserted")); | |
8543 | ||
2d134ed3 PA |
8544 | if (b->type == bp_hardware_watchpoint) |
8545 | loc_first_p = &wp_loc_first; | |
8546 | else if (b->type == bp_read_watchpoint) | |
8547 | loc_first_p = &rwp_loc_first; | |
8548 | else if (b->type == bp_access_watchpoint) | |
8549 | loc_first_p = &awp_loc_first; | |
8550 | else | |
8551 | loc_first_p = &bp_loc_first; | |
8552 | ||
8553 | if (*loc_first_p == NULL | |
8554 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
8555 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 8556 | { |
2d134ed3 | 8557 | *loc_first_p = loc; |
876fa593 JK |
8558 | loc->duplicate = 0; |
8559 | continue; | |
8560 | } | |
8561 | ||
8562 | loc->duplicate = 1; | |
8563 | ||
2d134ed3 PA |
8564 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
8565 | && b->enable_state != bp_permanent) | |
876fa593 JK |
8566 | internal_error (__FILE__, __LINE__, |
8567 | _("another breakpoint was inserted on top of " | |
8568 | "a permanent breakpoint")); | |
0d381245 | 8569 | } |
74960c60 | 8570 | |
50c71eaf | 8571 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 8572 | && (have_live_inferiors () |
2567c7d9 | 8573 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 8574 | insert_breakpoint_locations (); |
f7545552 TT |
8575 | |
8576 | do_cleanups (cleanups); | |
74960c60 VP |
8577 | } |
8578 | ||
20874c92 VP |
8579 | void |
8580 | breakpoint_retire_moribund (void) | |
8581 | { | |
8582 | struct bp_location *loc; | |
8583 | int ix; | |
8584 | ||
8585 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
8586 | if (--(loc->events_till_retirement) == 0) | |
8587 | { | |
8588 | free_bp_location (loc); | |
8589 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
8590 | --ix; | |
8591 | } | |
8592 | } | |
8593 | ||
74960c60 | 8594 | static void |
b60e7edf | 8595 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
8596 | { |
8597 | struct gdb_exception e; | |
8598 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 8599 | update_global_location_list (inserting); |
0d381245 VP |
8600 | } |
8601 | ||
a474d7c2 PA |
8602 | /* Clear BPT from a BPS. */ |
8603 | static void | |
8604 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
8605 | { | |
8606 | bpstat bs; | |
8607 | for (bs = bps; bs; bs = bs->next) | |
8608 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
8609 | { | |
8610 | bs->breakpoint_at = NULL; | |
8611 | bs->old_val = NULL; | |
8612 | /* bs->commands will be freed later. */ | |
8613 | } | |
8614 | } | |
8615 | ||
8616 | /* Callback for iterate_over_threads. */ | |
8617 | static int | |
8618 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
8619 | { | |
8620 | struct breakpoint *bpt = data; | |
8621 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
8622 | return 0; | |
8623 | } | |
8624 | ||
53a5351d JM |
8625 | /* Delete a breakpoint and clean up all traces of it in the data |
8626 | structures. */ | |
c906108c SS |
8627 | |
8628 | void | |
fba45db2 | 8629 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8630 | { |
52f0bd74 | 8631 | struct breakpoint *b; |
74960c60 | 8632 | struct bp_location *loc, *next; |
c906108c | 8633 | |
8a3fe4f8 | 8634 | gdb_assert (bpt != NULL); |
c906108c SS |
8635 | |
8636 | /* Has this bp already been deleted? This can happen because multiple | |
8637 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
8638 | ||
8639 | One example of this happening is a watchpoint's scope bp. When the | |
8640 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
8641 | delete it. We also delete its scope bp. But the scope bp is marked | |
8642 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
8643 | checked for auto-deleting bp's, which are deleted. | |
8644 | ||
8645 | A real solution to this problem might involve reference counts in bp's, | |
8646 | and/or giving them pointers back to their referencing bpstat's, and | |
8647 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 8648 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
8649 | if (bpt->type == bp_none) |
8650 | return; | |
8651 | ||
383f836e | 8652 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 8653 | |
c906108c SS |
8654 | if (breakpoint_chain == bpt) |
8655 | breakpoint_chain = bpt->next; | |
8656 | ||
c906108c SS |
8657 | ALL_BREAKPOINTS (b) |
8658 | if (b->next == bpt) | |
c5aa993b JM |
8659 | { |
8660 | b->next = bpt->next; | |
8661 | break; | |
8662 | } | |
c906108c | 8663 | |
c906108c | 8664 | free_command_lines (&bpt->commands); |
c906108c | 8665 | if (bpt->cond_string != NULL) |
b8c9b27d | 8666 | xfree (bpt->cond_string); |
c906108c | 8667 | if (bpt->addr_string != NULL) |
b8c9b27d | 8668 | xfree (bpt->addr_string); |
c906108c | 8669 | if (bpt->exp != NULL) |
b8c9b27d | 8670 | xfree (bpt->exp); |
c906108c | 8671 | if (bpt->exp_string != NULL) |
b8c9b27d | 8672 | xfree (bpt->exp_string); |
c906108c SS |
8673 | if (bpt->val != NULL) |
8674 | value_free (bpt->val); | |
8675 | if (bpt->source_file != NULL) | |
b8c9b27d | 8676 | xfree (bpt->source_file); |
c906108c | 8677 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 8678 | xfree (bpt->exec_pathname); |
a96d9b2e | 8679 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
8680 | |
8681 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
8682 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
8683 | We just check stop_bpstat for now. Note that we cannot just |
8684 | remove bpstats pointing at bpt from the stop_bpstat list | |
8685 | entirely, as breakpoint commands are associated with the bpstat; | |
8686 | if we remove it here, then the later call to | |
8687 | bpstat_do_actions (&stop_bpstat); | |
8688 | in event-top.c won't do anything, and temporary breakpoints | |
8689 | with commands won't work. */ | |
a474d7c2 | 8690 | |
a474d7c2 | 8691 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
8692 | |
8693 | /* Now that breakpoint is removed from breakpoint | |
8694 | list, update the global location list. This | |
8695 | will remove locations that used to belong to | |
8696 | this breakpoint. Do this before freeing | |
8697 | the breakpoint itself, since remove_breakpoint | |
8698 | looks at location's owner. It might be better | |
8699 | design to have location completely self-contained, | |
8700 | but it's not the case now. */ | |
b60e7edf | 8701 | update_global_location_list (0); |
74960c60 VP |
8702 | |
8703 | ||
c906108c SS |
8704 | /* On the chance that someone will soon try again to delete this same |
8705 | bp, we mark it as deleted before freeing its storage. */ | |
8706 | bpt->type = bp_none; | |
8707 | ||
b8c9b27d | 8708 | xfree (bpt); |
c906108c SS |
8709 | } |
8710 | ||
4d6140d9 AC |
8711 | static void |
8712 | do_delete_breakpoint_cleanup (void *b) | |
8713 | { | |
8714 | delete_breakpoint (b); | |
8715 | } | |
8716 | ||
8717 | struct cleanup * | |
8718 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
8719 | { | |
8720 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
8721 | } | |
8722 | ||
c906108c | 8723 | void |
fba45db2 | 8724 | delete_command (char *arg, int from_tty) |
c906108c SS |
8725 | { |
8726 | struct breakpoint *b, *temp; | |
8727 | ||
ea9365bb TT |
8728 | dont_repeat (); |
8729 | ||
c906108c SS |
8730 | if (arg == 0) |
8731 | { | |
8732 | int breaks_to_delete = 0; | |
8733 | ||
8734 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
8735 | Do not delete internal or call-dummy breakpoints, these |
8736 | have to be deleted with an explicit breakpoint number argument. */ | |
8737 | ALL_BREAKPOINTS (b) | |
8738 | { | |
059fb39f PM |
8739 | if (b->type != bp_call_dummy |
8740 | && b->type != bp_shlib_event | |
4efc6507 | 8741 | && b->type != bp_jit_event |
059fb39f PM |
8742 | && b->type != bp_thread_event |
8743 | && b->type != bp_overlay_event | |
0fd8e87f | 8744 | && b->type != bp_longjmp_master |
059fb39f | 8745 | && b->number >= 0) |
973d738b DJ |
8746 | { |
8747 | breaks_to_delete = 1; | |
8748 | break; | |
8749 | } | |
c5aa993b | 8750 | } |
c906108c SS |
8751 | |
8752 | /* Ask user only if there are some breakpoints to delete. */ | |
8753 | if (!from_tty | |
e2e0b3e5 | 8754 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 8755 | { |
c5aa993b JM |
8756 | ALL_BREAKPOINTS_SAFE (b, temp) |
8757 | { | |
059fb39f PM |
8758 | if (b->type != bp_call_dummy |
8759 | && b->type != bp_shlib_event | |
8760 | && b->type != bp_thread_event | |
4efc6507 | 8761 | && b->type != bp_jit_event |
059fb39f | 8762 | && b->type != bp_overlay_event |
0fd8e87f | 8763 | && b->type != bp_longjmp_master |
059fb39f | 8764 | && b->number >= 0) |
c5aa993b JM |
8765 | delete_breakpoint (b); |
8766 | } | |
c906108c SS |
8767 | } |
8768 | } | |
8769 | else | |
8770 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8771 | } | |
8772 | ||
0d381245 VP |
8773 | static int |
8774 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 8775 | { |
0d381245 VP |
8776 | for (; loc; loc = loc->next) |
8777 | if (!loc->shlib_disabled) | |
8778 | return 0; | |
8779 | return 1; | |
fe3f5fa8 VP |
8780 | } |
8781 | ||
776592bf DE |
8782 | /* Subroutine of update_breakpoint_locations to simplify it. |
8783 | Return non-zero if multiple fns in list LOC have the same name. | |
8784 | Null names are ignored. */ | |
8785 | ||
8786 | static int | |
8787 | ambiguous_names_p (struct bp_location *loc) | |
8788 | { | |
8789 | struct bp_location *l; | |
8790 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
8791 | (int (*) (const void *, const void *)) streq, | |
8792 | NULL, xcalloc, xfree); | |
8793 | ||
8794 | for (l = loc; l != NULL; l = l->next) | |
8795 | { | |
8796 | const char **slot; | |
8797 | const char *name = l->function_name; | |
8798 | ||
8799 | /* Allow for some names to be NULL, ignore them. */ | |
8800 | if (name == NULL) | |
8801 | continue; | |
8802 | ||
8803 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
8804 | INSERT); | |
8805 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
8806 | NULL. */ | |
8807 | if (*slot != NULL) | |
8808 | { | |
8809 | htab_delete (htab); | |
8810 | return 1; | |
8811 | } | |
8812 | *slot = name; | |
8813 | } | |
8814 | ||
8815 | htab_delete (htab); | |
8816 | return 0; | |
8817 | } | |
8818 | ||
fe3f5fa8 | 8819 | static void |
0d381245 VP |
8820 | update_breakpoint_locations (struct breakpoint *b, |
8821 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
8822 | { |
8823 | int i; | |
8824 | char *s; | |
0d381245 VP |
8825 | struct bp_location *existing_locations = b->loc; |
8826 | ||
8827 | /* If there's no new locations, and all existing locations | |
8828 | are pending, don't do anything. This optimizes | |
8829 | the common case where all locations are in the same | |
8830 | shared library, that was unloaded. We'd like to | |
8831 | retain the location, so that when the library | |
8832 | is loaded again, we don't loose the enabled/disabled | |
8833 | status of the individual locations. */ | |
8834 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
8835 | return; |
8836 | ||
fe3f5fa8 VP |
8837 | b->loc = NULL; |
8838 | ||
0d381245 | 8839 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 8840 | { |
0d381245 | 8841 | struct bp_location *new_loc = |
39d61571 | 8842 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 8843 | |
0d381245 VP |
8844 | /* Reparse conditions, they might contain references to the |
8845 | old symtab. */ | |
8846 | if (b->cond_string != NULL) | |
8847 | { | |
8848 | struct gdb_exception e; | |
fe3f5fa8 | 8849 | |
0d381245 VP |
8850 | s = b->cond_string; |
8851 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
8852 | { | |
8853 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
8854 | 0); | |
8855 | } | |
8856 | if (e.reason < 0) | |
8857 | { | |
8858 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
8859 | b->number, e.message); | |
8860 | new_loc->enabled = 0; | |
8861 | } | |
8862 | } | |
fe3f5fa8 | 8863 | |
0d381245 VP |
8864 | if (b->source_file != NULL) |
8865 | xfree (b->source_file); | |
8866 | if (sals.sals[i].symtab == NULL) | |
8867 | b->source_file = NULL; | |
8868 | else | |
1b36a34b | 8869 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 8870 | |
0d381245 VP |
8871 | if (b->line_number == 0) |
8872 | b->line_number = sals.sals[i].line; | |
8873 | } | |
fe3f5fa8 | 8874 | |
514f746b AR |
8875 | /* Update locations of permanent breakpoints. */ |
8876 | if (b->enable_state == bp_permanent) | |
8877 | make_breakpoint_permanent (b); | |
8878 | ||
0d381245 VP |
8879 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
8880 | { | |
8881 | struct bp_location *e = existing_locations; | |
776592bf DE |
8882 | /* If there are multiple breakpoints with the same function name, |
8883 | e.g. for inline functions, comparing function names won't work. | |
8884 | Instead compare pc addresses; this is just a heuristic as things | |
8885 | may have moved, but in practice it gives the correct answer | |
8886 | often enough until a better solution is found. */ | |
8887 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
8888 | ||
0d381245 VP |
8889 | for (; e; e = e->next) |
8890 | { | |
8891 | if (!e->enabled && e->function_name) | |
8892 | { | |
8893 | struct bp_location *l = b->loc; | |
776592bf DE |
8894 | if (have_ambiguous_names) |
8895 | { | |
8896 | for (; l; l = l->next) | |
6c95b8df PA |
8897 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
8898 | l->pspace->aspace, l->address)) | |
776592bf DE |
8899 | { |
8900 | l->enabled = 0; | |
8901 | break; | |
8902 | } | |
8903 | } | |
8904 | else | |
8905 | { | |
8906 | for (; l; l = l->next) | |
8907 | if (l->function_name | |
8908 | && strcmp (e->function_name, l->function_name) == 0) | |
8909 | { | |
8910 | l->enabled = 0; | |
8911 | break; | |
8912 | } | |
8913 | } | |
0d381245 VP |
8914 | } |
8915 | } | |
8916 | } | |
fe3f5fa8 | 8917 | |
b60e7edf | 8918 | update_global_location_list (1); |
fe3f5fa8 VP |
8919 | } |
8920 | ||
8921 | ||
c906108c SS |
8922 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
8923 | The value we return ends up being the return value from catch_errors. | |
8924 | Unused in this case. */ | |
8925 | ||
8926 | static int | |
4efb68b1 | 8927 | breakpoint_re_set_one (void *bint) |
c906108c | 8928 | { |
53a5351d JM |
8929 | /* get past catch_errs */ |
8930 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
8931 | struct value *mark; |
8932 | int i; | |
fe3f5fa8 VP |
8933 | int not_found = 0; |
8934 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
8935 | struct symtabs_and_lines sals = {0}; |
8936 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 8937 | char *s; |
b5de0fa7 | 8938 | enum enable_state save_enable; |
fe3f5fa8 | 8939 | struct gdb_exception e; |
6c95b8df | 8940 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
8941 | |
8942 | switch (b->type) | |
8943 | { | |
8944 | case bp_none: | |
8a3fe4f8 | 8945 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 8946 | b->number); |
c906108c SS |
8947 | return 0; |
8948 | case bp_breakpoint: | |
8949 | case bp_hardware_breakpoint: | |
1042e4c0 | 8950 | case bp_tracepoint: |
8bea4e01 UW |
8951 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
8952 | if (b->enable_state == bp_startup_disabled) | |
8953 | return 0; | |
8954 | ||
c906108c SS |
8955 | if (b->addr_string == NULL) |
8956 | { | |
8957 | /* Anything without a string can't be re-set. */ | |
8958 | delete_breakpoint (b); | |
8959 | return 0; | |
8960 | } | |
c906108c SS |
8961 | |
8962 | set_language (b->language); | |
8963 | input_radix = b->input_radix; | |
8964 | s = b->addr_string; | |
6c95b8df PA |
8965 | |
8966 | save_current_space_and_thread (); | |
8967 | switch_to_program_space_and_thread (b->pspace); | |
8968 | ||
fe3f5fa8 | 8969 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 8970 | { |
fe3f5fa8 VP |
8971 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
8972 | not_found_ptr); | |
8973 | } | |
8974 | if (e.reason < 0) | |
8975 | { | |
8976 | int not_found_and_ok = 0; | |
8977 | /* For pending breakpoints, it's expected that parsing | |
8978 | will fail until the right shared library is loaded. | |
8979 | User has already told to create pending breakpoints and | |
8980 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
8981 | state, then user already saw the message about that breakpoint | |
8982 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
8983 | if (not_found |
8984 | && (b->condition_not_parsed | |
8985 | || (b->loc && b->loc->shlib_disabled) | |
8986 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
8987 | not_found_and_ok = 1; |
8988 | ||
8989 | if (!not_found_and_ok) | |
c906108c | 8990 | { |
fe3f5fa8 VP |
8991 | /* We surely don't want to warn about the same breakpoint |
8992 | 10 times. One solution, implemented here, is disable | |
8993 | the breakpoint on error. Another solution would be to | |
8994 | have separate 'warning emitted' flag. Since this | |
8995 | happens only when a binary has changed, I don't know | |
8996 | which approach is better. */ | |
8997 | b->enable_state = bp_disabled; | |
8998 | throw_exception (e); | |
c906108c | 8999 | } |
fe3f5fa8 | 9000 | } |
c906108c | 9001 | |
6c95b8df | 9002 | if (!not_found) |
fe3f5fa8 | 9003 | { |
6c95b8df PA |
9004 | gdb_assert (sals.nelts == 1); |
9005 | ||
9006 | resolve_sal_pc (&sals.sals[0]); | |
9007 | if (b->condition_not_parsed && s && s[0]) | |
9008 | { | |
9009 | char *cond_string = 0; | |
9010 | int thread = -1; | |
9011 | int task = 0; | |
9012 | ||
9013 | find_condition_and_thread (s, sals.sals[0].pc, | |
9014 | &cond_string, &thread, &task); | |
9015 | if (cond_string) | |
9016 | b->cond_string = cond_string; | |
9017 | b->thread = thread; | |
9018 | b->task = task; | |
9019 | b->condition_not_parsed = 0; | |
9020 | } | |
9021 | ||
9022 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 9023 | } |
6c95b8df PA |
9024 | |
9025 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 9026 | update_breakpoint_locations (b, expanded); |
c906108c SS |
9027 | break; |
9028 | ||
9029 | case bp_watchpoint: | |
9030 | case bp_hardware_watchpoint: | |
9031 | case bp_read_watchpoint: | |
9032 | case bp_access_watchpoint: | |
0b3de036 VP |
9033 | /* Watchpoint can be either on expression using entirely global variables, |
9034 | or it can be on local variables. | |
9035 | ||
9036 | Watchpoints of the first kind are never auto-deleted, and even persist | |
9037 | across program restarts. Since they can use variables from shared | |
9038 | libraries, we need to reparse expression as libraries are loaded | |
9039 | and unloaded. | |
9040 | ||
9041 | Watchpoints on local variables can also change meaning as result | |
9042 | of solib event. For example, if a watchpoint uses both a local and | |
9043 | a global variables in expression, it's a local watchpoint, but | |
9044 | unloading of a shared library will make the expression invalid. | |
9045 | This is not a very common use case, but we still re-evaluate | |
9046 | expression, to avoid surprises to the user. | |
9047 | ||
9048 | Note that for local watchpoints, we re-evaluate it only if | |
9049 | watchpoints frame id is still valid. If it's not, it means | |
9050 | the watchpoint is out of scope and will be deleted soon. In fact, | |
9051 | I'm not sure we'll ever be called in this case. | |
9052 | ||
9053 | If a local watchpoint's frame id is still valid, then | |
9054 | b->exp_valid_block is likewise valid, and we can safely use it. | |
9055 | ||
9056 | Don't do anything about disabled watchpoints, since they will | |
9057 | be reevaluated again when enabled. */ | |
a5606eee | 9058 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 9059 | break; |
c5aa993b JM |
9060 | /* We needn't really do anything to reset these, since the mask |
9061 | that requests them is unaffected by e.g., new libraries being | |
9062 | loaded. */ | |
ce78b96d | 9063 | case bp_catchpoint: |
c906108c | 9064 | break; |
c5aa993b | 9065 | |
c906108c | 9066 | default: |
a3f17187 | 9067 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 9068 | /* fall through */ |
0fd8e87f UW |
9069 | /* Delete overlay event and longjmp master breakpoints; they will be |
9070 | reset later by breakpoint_re_set. */ | |
1900040c | 9071 | case bp_overlay_event: |
0fd8e87f | 9072 | case bp_longjmp_master: |
c906108c SS |
9073 | delete_breakpoint (b); |
9074 | break; | |
9075 | ||
c5aa993b JM |
9076 | /* This breakpoint is special, it's set up when the inferior |
9077 | starts and we really don't want to touch it. */ | |
c906108c SS |
9078 | case bp_shlib_event: |
9079 | ||
c4093a6a JM |
9080 | /* Like bp_shlib_event, this breakpoint type is special. |
9081 | Once it is set up, we do not want to touch it. */ | |
9082 | case bp_thread_event: | |
9083 | ||
c5aa993b JM |
9084 | /* Keep temporary breakpoints, which can be encountered when we step |
9085 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
9086 | Otherwise these should have been blown away via the cleanup chain | |
9087 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
9088 | case bp_until: |
9089 | case bp_finish: | |
9090 | case bp_watchpoint_scope: | |
9091 | case bp_call_dummy: | |
9092 | case bp_step_resume: | |
611c83ae PA |
9093 | case bp_longjmp: |
9094 | case bp_longjmp_resume: | |
4efc6507 | 9095 | case bp_jit_event: |
c906108c SS |
9096 | break; |
9097 | } | |
9098 | ||
6c95b8df | 9099 | do_cleanups (cleanups); |
c906108c SS |
9100 | return 0; |
9101 | } | |
9102 | ||
69de3c6a | 9103 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 9104 | void |
69de3c6a | 9105 | breakpoint_re_set (void) |
c906108c SS |
9106 | { |
9107 | struct breakpoint *b, *temp; | |
9108 | enum language save_language; | |
9109 | int save_input_radix; | |
6c95b8df | 9110 | struct cleanup *old_chain; |
c5aa993b | 9111 | |
c906108c SS |
9112 | save_language = current_language->la_language; |
9113 | save_input_radix = input_radix; | |
6c95b8df PA |
9114 | old_chain = save_current_program_space (); |
9115 | ||
c906108c | 9116 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 9117 | { |
53a5351d | 9118 | /* Format possible error msg */ |
fe3f5fa8 | 9119 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
9120 | b->number); |
9121 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 9122 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 9123 | do_cleanups (cleanups); |
c5aa993b | 9124 | } |
c906108c SS |
9125 | set_language (save_language); |
9126 | input_radix = save_input_radix; | |
e62c965a | 9127 | |
0756c555 | 9128 | jit_breakpoint_re_set (); |
4efc6507 | 9129 | |
6c95b8df PA |
9130 | do_cleanups (old_chain); |
9131 | ||
69de3c6a | 9132 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
9133 | create_longjmp_master_breakpoint ("longjmp"); |
9134 | create_longjmp_master_breakpoint ("_longjmp"); | |
9135 | create_longjmp_master_breakpoint ("siglongjmp"); | |
9136 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
9137 | } |
9138 | \f | |
c906108c SS |
9139 | /* Reset the thread number of this breakpoint: |
9140 | ||
9141 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 9142 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 9143 | void |
fba45db2 | 9144 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
9145 | { |
9146 | if (b->thread != -1) | |
9147 | { | |
39f77062 KB |
9148 | if (in_thread_list (inferior_ptid)) |
9149 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
9150 | |
9151 | /* We're being called after following a fork. The new fork is | |
9152 | selected as current, and unless this was a vfork will have a | |
9153 | different program space from the original thread. Reset that | |
9154 | as well. */ | |
9155 | b->loc->pspace = current_program_space; | |
c906108c SS |
9156 | } |
9157 | } | |
9158 | ||
03ac34d5 MS |
9159 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9160 | If from_tty is nonzero, it prints a message to that effect, | |
9161 | which ends with a period (no newline). */ | |
9162 | ||
c906108c | 9163 | void |
fba45db2 | 9164 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 9165 | { |
52f0bd74 | 9166 | struct breakpoint *b; |
c906108c SS |
9167 | |
9168 | if (count < 0) | |
9169 | count = 0; | |
9170 | ||
9171 | ALL_BREAKPOINTS (b) | |
9172 | if (b->number == bptnum) | |
c5aa993b JM |
9173 | { |
9174 | b->ignore_count = count; | |
221ea385 KS |
9175 | if (from_tty) |
9176 | { | |
9177 | if (count == 0) | |
a3f17187 | 9178 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
9179 | bptnum); |
9180 | else if (count == 1) | |
a3f17187 | 9181 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
9182 | bptnum); |
9183 | else | |
a3f17187 | 9184 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
9185 | count, bptnum); |
9186 | } | |
c5aa993b | 9187 | breakpoints_changed (); |
383f836e | 9188 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
9189 | return; |
9190 | } | |
c906108c | 9191 | |
8a3fe4f8 | 9192 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
9193 | } |
9194 | ||
b2175913 MS |
9195 | void |
9196 | make_breakpoint_silent (struct breakpoint *b) | |
9197 | { | |
9198 | /* Silence the breakpoint. */ | |
9199 | b->silent = 1; | |
9200 | } | |
9201 | ||
c906108c SS |
9202 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9203 | ||
9204 | static void | |
fba45db2 | 9205 | ignore_command (char *args, int from_tty) |
c906108c SS |
9206 | { |
9207 | char *p = args; | |
52f0bd74 | 9208 | int num; |
c906108c SS |
9209 | |
9210 | if (p == 0) | |
e2e0b3e5 | 9211 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9212 | |
c906108c | 9213 | num = get_number (&p); |
5c44784c | 9214 | if (num == 0) |
8a3fe4f8 | 9215 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9216 | if (*p == 0) |
8a3fe4f8 | 9217 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9218 | |
9219 | set_ignore_count (num, | |
9220 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9221 | from_tty); | |
221ea385 KS |
9222 | if (from_tty) |
9223 | printf_filtered ("\n"); | |
c906108c SS |
9224 | } |
9225 | \f | |
9226 | /* Call FUNCTION on each of the breakpoints | |
9227 | whose numbers are given in ARGS. */ | |
9228 | ||
9229 | static void | |
831662b3 | 9230 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 9231 | { |
52f0bd74 | 9232 | char *p = args; |
c906108c | 9233 | char *p1; |
52f0bd74 AC |
9234 | int num; |
9235 | struct breakpoint *b, *tmp; | |
11cf8741 | 9236 | int match; |
c906108c SS |
9237 | |
9238 | if (p == 0) | |
e2e0b3e5 | 9239 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9240 | |
9241 | while (*p) | |
9242 | { | |
11cf8741 | 9243 | match = 0; |
c906108c | 9244 | p1 = p; |
c5aa993b | 9245 | |
5c44784c JM |
9246 | num = get_number_or_range (&p1); |
9247 | if (num == 0) | |
c5aa993b | 9248 | { |
8a3fe4f8 | 9249 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9250 | } |
9251 | else | |
9252 | { | |
9253 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9254 | if (b->number == num) | |
9255 | { | |
9256 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9257 | match = 1; |
5c44784c JM |
9258 | function (b); |
9259 | if (related_breakpoint) | |
9260 | function (related_breakpoint); | |
11cf8741 | 9261 | break; |
5c44784c | 9262 | } |
11cf8741 | 9263 | if (match == 0) |
a3f17187 | 9264 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9265 | } |
c906108c SS |
9266 | p = p1; |
9267 | } | |
9268 | } | |
9269 | ||
0d381245 VP |
9270 | static struct bp_location * |
9271 | find_location_by_number (char *number) | |
9272 | { | |
9273 | char *dot = strchr (number, '.'); | |
9274 | char *p1; | |
9275 | int bp_num; | |
9276 | int loc_num; | |
9277 | struct breakpoint *b; | |
9278 | struct bp_location *loc; | |
9279 | ||
9280 | *dot = '\0'; | |
9281 | ||
9282 | p1 = number; | |
9283 | bp_num = get_number_or_range (&p1); | |
9284 | if (bp_num == 0) | |
9285 | error (_("Bad breakpoint number '%s'"), number); | |
9286 | ||
9287 | ALL_BREAKPOINTS (b) | |
9288 | if (b->number == bp_num) | |
9289 | { | |
9290 | break; | |
9291 | } | |
9292 | ||
9293 | if (!b || b->number != bp_num) | |
9294 | error (_("Bad breakpoint number '%s'"), number); | |
9295 | ||
9296 | p1 = dot+1; | |
9297 | loc_num = get_number_or_range (&p1); | |
9298 | if (loc_num == 0) | |
9299 | error (_("Bad breakpoint location number '%s'"), number); | |
9300 | ||
9301 | --loc_num; | |
9302 | loc = b->loc; | |
9303 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9304 | ; | |
9305 | if (!loc) | |
9306 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9307 | ||
9308 | return loc; | |
9309 | } | |
9310 | ||
9311 | ||
1900040c MS |
9312 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9313 | If from_tty is nonzero, it prints a message to that effect, | |
9314 | which ends with a period (no newline). */ | |
9315 | ||
c906108c | 9316 | void |
fba45db2 | 9317 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9318 | { |
9319 | /* Never disable a watchpoint scope breakpoint; we want to | |
9320 | hit them when we leave scope so we can delete both the | |
9321 | watchpoint and its scope breakpoint at that time. */ | |
9322 | if (bpt->type == bp_watchpoint_scope) | |
9323 | return; | |
9324 | ||
c2c6d25f | 9325 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9326 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9327 | return; |
9328 | ||
b5de0fa7 | 9329 | bpt->enable_state = bp_disabled; |
c906108c | 9330 | |
b60e7edf | 9331 | update_global_location_list (0); |
c906108c | 9332 | |
383f836e | 9333 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9334 | } |
9335 | ||
c906108c | 9336 | static void |
fba45db2 | 9337 | disable_command (char *args, int from_tty) |
c906108c | 9338 | { |
52f0bd74 | 9339 | struct breakpoint *bpt; |
c906108c SS |
9340 | if (args == 0) |
9341 | ALL_BREAKPOINTS (bpt) | |
9342 | switch (bpt->type) | |
c5aa993b JM |
9343 | { |
9344 | case bp_none: | |
8a3fe4f8 | 9345 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9346 | bpt->number); |
c5aa993b JM |
9347 | continue; |
9348 | case bp_breakpoint: | |
1042e4c0 | 9349 | case bp_tracepoint: |
ce78b96d | 9350 | case bp_catchpoint: |
c5aa993b JM |
9351 | case bp_hardware_breakpoint: |
9352 | case bp_watchpoint: | |
9353 | case bp_hardware_watchpoint: | |
9354 | case bp_read_watchpoint: | |
9355 | case bp_access_watchpoint: | |
9356 | disable_breakpoint (bpt); | |
9357 | default: | |
9358 | continue; | |
9359 | } | |
0d381245 VP |
9360 | else if (strchr (args, '.')) |
9361 | { | |
9362 | struct bp_location *loc = find_location_by_number (args); | |
9363 | if (loc) | |
9364 | loc->enabled = 0; | |
b60e7edf | 9365 | update_global_location_list (0); |
0d381245 | 9366 | } |
c906108c SS |
9367 | else |
9368 | map_breakpoint_numbers (args, disable_breakpoint); | |
9369 | } | |
9370 | ||
9371 | static void | |
fba45db2 | 9372 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9373 | { |
c906108c SS |
9374 | int target_resources_ok, other_type_used; |
9375 | struct value *mark; | |
9376 | ||
9377 | if (bpt->type == bp_hardware_breakpoint) | |
9378 | { | |
9379 | int i; | |
c5aa993b | 9380 | i = hw_breakpoint_used_count (); |
53a5351d | 9381 | target_resources_ok = |
d92524f1 | 9382 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9383 | i + 1, 0); |
c906108c | 9384 | if (target_resources_ok == 0) |
8a3fe4f8 | 9385 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9386 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9387 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9388 | } |
9389 | ||
059fb39f PM |
9390 | if (bpt->type == bp_watchpoint |
9391 | || bpt->type == bp_hardware_watchpoint | |
9392 | || bpt->type == bp_read_watchpoint | |
9393 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9394 | { |
dde02812 ES |
9395 | struct gdb_exception e; |
9396 | ||
9397 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9398 | { |
dde02812 | 9399 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9400 | } |
dde02812 | 9401 | if (e.reason < 0) |
c5aa993b | 9402 | { |
dde02812 ES |
9403 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9404 | bpt->number); | |
9405 | return; | |
c5aa993b | 9406 | } |
c906108c | 9407 | } |
0101ce28 | 9408 | |
b4c291bb KH |
9409 | if (bpt->enable_state != bp_permanent) |
9410 | bpt->enable_state = bp_enabled; | |
9411 | bpt->disposition = disposition; | |
b60e7edf | 9412 | update_global_location_list (1); |
b4c291bb KH |
9413 | breakpoints_changed (); |
9414 | ||
383f836e | 9415 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9416 | } |
9417 | ||
fe3f5fa8 | 9418 | |
c906108c | 9419 | void |
fba45db2 | 9420 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9421 | { |
9422 | do_enable_breakpoint (bpt, bpt->disposition); | |
9423 | } | |
9424 | ||
9425 | /* The enable command enables the specified breakpoints (or all defined | |
9426 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 9427 | in stopping the inferior. */ |
c906108c | 9428 | |
c906108c | 9429 | static void |
fba45db2 | 9430 | enable_command (char *args, int from_tty) |
c906108c | 9431 | { |
52f0bd74 | 9432 | struct breakpoint *bpt; |
c906108c SS |
9433 | if (args == 0) |
9434 | ALL_BREAKPOINTS (bpt) | |
9435 | switch (bpt->type) | |
c5aa993b JM |
9436 | { |
9437 | case bp_none: | |
8a3fe4f8 | 9438 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 9439 | bpt->number); |
c5aa993b JM |
9440 | continue; |
9441 | case bp_breakpoint: | |
1042e4c0 | 9442 | case bp_tracepoint: |
ce78b96d | 9443 | case bp_catchpoint: |
c5aa993b JM |
9444 | case bp_hardware_breakpoint: |
9445 | case bp_watchpoint: | |
9446 | case bp_hardware_watchpoint: | |
9447 | case bp_read_watchpoint: | |
9448 | case bp_access_watchpoint: | |
9449 | enable_breakpoint (bpt); | |
9450 | default: | |
9451 | continue; | |
9452 | } | |
0d381245 VP |
9453 | else if (strchr (args, '.')) |
9454 | { | |
9455 | struct bp_location *loc = find_location_by_number (args); | |
9456 | if (loc) | |
9457 | loc->enabled = 1; | |
b60e7edf | 9458 | update_global_location_list (1); |
0d381245 | 9459 | } |
c906108c SS |
9460 | else |
9461 | map_breakpoint_numbers (args, enable_breakpoint); | |
9462 | } | |
9463 | ||
9464 | static void | |
fba45db2 | 9465 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 9466 | { |
b5de0fa7 | 9467 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
9468 | } |
9469 | ||
c906108c | 9470 | static void |
fba45db2 | 9471 | enable_once_command (char *args, int from_tty) |
c906108c SS |
9472 | { |
9473 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
9474 | } | |
9475 | ||
9476 | static void | |
fba45db2 | 9477 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9478 | { |
b5de0fa7 | 9479 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
9480 | } |
9481 | ||
c906108c | 9482 | static void |
fba45db2 | 9483 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
9484 | { |
9485 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
9486 | } | |
9487 | \f | |
fa8d40ab JJ |
9488 | static void |
9489 | set_breakpoint_cmd (char *args, int from_tty) | |
9490 | { | |
9491 | } | |
9492 | ||
9493 | static void | |
9494 | show_breakpoint_cmd (char *args, int from_tty) | |
9495 | { | |
9496 | } | |
9497 | ||
1f3b5d1b PP |
9498 | /* Invalidate last known value of any hardware watchpoint if |
9499 | the memory which that value represents has been written to by | |
9500 | GDB itself. */ | |
9501 | ||
9502 | static void | |
9503 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
9504 | const bfd_byte *data) | |
9505 | { | |
9506 | struct breakpoint *bp; | |
9507 | ||
9508 | ALL_BREAKPOINTS (bp) | |
9509 | if (bp->enable_state == bp_enabled | |
9510 | && bp->type == bp_hardware_watchpoint | |
9511 | && bp->val_valid && bp->val) | |
9512 | { | |
9513 | struct bp_location *loc; | |
9514 | ||
9515 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
9516 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
9517 | && loc->address + loc->length > addr | |
9518 | && addr + len > loc->address) | |
9519 | { | |
9520 | value_free (bp->val); | |
9521 | bp->val = NULL; | |
9522 | bp->val_valid = 0; | |
9523 | } | |
9524 | } | |
9525 | } | |
9526 | ||
c906108c SS |
9527 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
9528 | ||
9529 | struct symtabs_and_lines | |
fba45db2 | 9530 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
9531 | { |
9532 | struct symtabs_and_lines sals; | |
9533 | if (string == 0) | |
8a3fe4f8 | 9534 | error (_("Empty line specification.")); |
c906108c SS |
9535 | if (default_breakpoint_valid) |
9536 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
9537 | default_breakpoint_symtab, |
9538 | default_breakpoint_line, | |
68219205 | 9539 | (char ***) NULL, NULL); |
c906108c SS |
9540 | else |
9541 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 9542 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 9543 | if (*string) |
8a3fe4f8 | 9544 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
9545 | return sals; |
9546 | } | |
8181d85f DJ |
9547 | |
9548 | /* Create and insert a raw software breakpoint at PC. Return an | |
9549 | identifier, which should be used to remove the breakpoint later. | |
9550 | In general, places which call this should be using something on the | |
9551 | breakpoint chain instead; this function should be eliminated | |
9552 | someday. */ | |
9553 | ||
9554 | void * | |
6c95b8df PA |
9555 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
9556 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
9557 | { |
9558 | struct bp_target_info *bp_tgt; | |
9559 | ||
6c95b8df | 9560 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 9561 | |
6c95b8df | 9562 | bp_tgt->placed_address_space = aspace; |
8181d85f | 9563 | bp_tgt->placed_address = pc; |
6c95b8df | 9564 | |
a6d9a66e | 9565 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
9566 | { |
9567 | /* Could not insert the breakpoint. */ | |
9568 | xfree (bp_tgt); | |
9569 | return NULL; | |
9570 | } | |
9571 | ||
9572 | return bp_tgt; | |
9573 | } | |
9574 | ||
9575 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
9576 | ||
9577 | int | |
a6d9a66e | 9578 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
9579 | { |
9580 | struct bp_target_info *bp_tgt = bp; | |
9581 | int ret; | |
9582 | ||
a6d9a66e | 9583 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
9584 | xfree (bp_tgt); |
9585 | ||
9586 | return ret; | |
9587 | } | |
9588 | ||
9589 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
9590 | ||
9591 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 9592 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
9593 | |
9594 | /* Create and insert a breakpoint for software single step. */ | |
9595 | ||
9596 | void | |
6c95b8df PA |
9597 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
9598 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
9599 | { |
9600 | void **bpt_p; | |
9601 | ||
9602 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
9603 | { |
9604 | bpt_p = &single_step_breakpoints[0]; | |
9605 | single_step_gdbarch[0] = gdbarch; | |
9606 | } | |
8181d85f DJ |
9607 | else |
9608 | { | |
9609 | gdb_assert (single_step_breakpoints[1] == NULL); | |
9610 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 9611 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
9612 | } |
9613 | ||
9614 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
9615 | to only create the breakpoints once, and actually put them on the | |
9616 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
9617 | adjust the addresses each time they were needed. Doing this requires | |
9618 | corresponding changes elsewhere where single step breakpoints are | |
9619 | handled, however. So, for now, we use this. */ | |
9620 | ||
6c95b8df | 9621 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 9622 | if (*bpt_p == NULL) |
5af949e3 UW |
9623 | error (_("Could not insert single-step breakpoint at %s"), |
9624 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
9625 | } |
9626 | ||
9627 | /* Remove and delete any breakpoints used for software single step. */ | |
9628 | ||
9629 | void | |
9630 | remove_single_step_breakpoints (void) | |
9631 | { | |
9632 | gdb_assert (single_step_breakpoints[0] != NULL); | |
9633 | ||
9634 | /* See insert_single_step_breakpoint for more about this deprecated | |
9635 | call. */ | |
a6d9a66e UW |
9636 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
9637 | single_step_breakpoints[0]); | |
9638 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
9639 | single_step_breakpoints[0] = NULL; |
9640 | ||
9641 | if (single_step_breakpoints[1] != NULL) | |
9642 | { | |
a6d9a66e UW |
9643 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
9644 | single_step_breakpoints[1]); | |
9645 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
9646 | single_step_breakpoints[1] = NULL; |
9647 | } | |
9648 | } | |
9649 | ||
1aafd4da UW |
9650 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
9651 | ||
9652 | static int | |
6c95b8df | 9653 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
9654 | { |
9655 | int i; | |
9656 | ||
9657 | for (i = 0; i < 2; i++) | |
9658 | { | |
9659 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
9660 | if (bp_tgt |
9661 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
9662 | bp_tgt->placed_address, | |
9663 | aspace, pc)) | |
1aafd4da UW |
9664 | return 1; |
9665 | } | |
9666 | ||
9667 | return 0; | |
9668 | } | |
9669 | ||
a96d9b2e SDJ |
9670 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
9671 | non-zero otherwise. */ | |
9672 | static int | |
9673 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
9674 | { | |
9675 | if (syscall_catchpoint_p (bp) | |
9676 | && bp->enable_state != bp_disabled | |
9677 | && bp->enable_state != bp_call_disabled) | |
9678 | return 1; | |
9679 | else | |
9680 | return 0; | |
9681 | } | |
9682 | ||
9683 | int | |
9684 | catch_syscall_enabled (void) | |
9685 | { | |
9686 | struct inferior *inf = current_inferior (); | |
9687 | ||
9688 | return inf->total_syscalls_count != 0; | |
9689 | } | |
9690 | ||
9691 | int | |
9692 | catching_syscall_number (int syscall_number) | |
9693 | { | |
9694 | struct breakpoint *bp; | |
9695 | ||
9696 | ALL_BREAKPOINTS (bp) | |
9697 | if (is_syscall_catchpoint_enabled (bp)) | |
9698 | { | |
9699 | if (bp->syscalls_to_be_caught) | |
9700 | { | |
9701 | int i, iter; | |
9702 | for (i = 0; | |
9703 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
9704 | i++) | |
9705 | if (syscall_number == iter) | |
9706 | return 1; | |
9707 | } | |
9708 | else | |
9709 | return 1; | |
9710 | } | |
9711 | ||
9712 | return 0; | |
9713 | } | |
9714 | ||
9715 | /* Complete syscall names. Used by "catch syscall". */ | |
9716 | static char ** | |
9717 | catch_syscall_completer (struct cmd_list_element *cmd, | |
9718 | char *text, char *word) | |
9719 | { | |
9720 | const char **list = get_syscall_names (); | |
9721 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
9722 | } | |
9723 | ||
1042e4c0 SS |
9724 | /* Tracepoint-specific operations. */ |
9725 | ||
9726 | /* Set tracepoint count to NUM. */ | |
9727 | static void | |
9728 | set_tracepoint_count (int num) | |
9729 | { | |
9730 | tracepoint_count = num; | |
4fa62494 | 9731 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
9732 | } |
9733 | ||
9734 | void | |
9735 | trace_command (char *arg, int from_tty) | |
9736 | { | |
a6d9a66e UW |
9737 | break_command_really (get_current_arch (), |
9738 | arg, | |
1042e4c0 SS |
9739 | NULL, 0, 1 /* parse arg */, |
9740 | 0 /* tempflag */, 0 /* hardwareflag */, | |
9741 | 1 /* traceflag */, | |
9742 | 0 /* Ignore count */, | |
9743 | pending_break_support, | |
9744 | NULL, | |
9745 | from_tty, | |
9746 | 1 /* enabled */); | |
9747 | set_tracepoint_count (breakpoint_count); | |
9748 | } | |
9749 | ||
9750 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
9751 | omitted. */ | |
9752 | ||
9753 | static void | |
9754 | tracepoints_info (char *tpnum_exp, int from_tty) | |
9755 | { | |
9756 | struct breakpoint *b; | |
9757 | int tps_to_list = 0; | |
9758 | ||
9759 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
9760 | if (tpnum_exp == 0) | |
9761 | { | |
9762 | ALL_TRACEPOINTS (b) | |
9763 | { | |
9764 | if (b->number >= 0) | |
9765 | { | |
9766 | tps_to_list = 1; | |
9767 | break; | |
9768 | } | |
9769 | } | |
9770 | if (!tps_to_list) | |
9771 | { | |
9772 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
9773 | return; | |
9774 | } | |
9775 | } | |
9776 | ||
9777 | /* Otherwise be the same as "info break". */ | |
9778 | breakpoints_info (tpnum_exp, from_tty); | |
9779 | } | |
9780 | ||
9781 | /* The 'enable trace' command enables tracepoints. | |
9782 | Not supported by all targets. */ | |
9783 | static void | |
9784 | enable_trace_command (char *args, int from_tty) | |
9785 | { | |
9786 | enable_command (args, from_tty); | |
9787 | } | |
9788 | ||
9789 | /* The 'disable trace' command disables tracepoints. | |
9790 | Not supported by all targets. */ | |
9791 | static void | |
9792 | disable_trace_command (char *args, int from_tty) | |
9793 | { | |
9794 | disable_command (args, from_tty); | |
9795 | } | |
9796 | ||
9797 | /* Remove a tracepoint (or all if no argument) */ | |
9798 | static void | |
9799 | delete_trace_command (char *arg, int from_tty) | |
9800 | { | |
9801 | struct breakpoint *b, *temp; | |
9802 | ||
9803 | dont_repeat (); | |
9804 | ||
9805 | if (arg == 0) | |
9806 | { | |
9807 | int breaks_to_delete = 0; | |
9808 | ||
9809 | /* Delete all breakpoints if no argument. | |
9810 | Do not delete internal or call-dummy breakpoints, these | |
9811 | have to be deleted with an explicit breakpoint number argument. */ | |
9812 | ALL_TRACEPOINTS (b) | |
9813 | { | |
9814 | if (b->number >= 0) | |
9815 | { | |
9816 | breaks_to_delete = 1; | |
9817 | break; | |
9818 | } | |
9819 | } | |
9820 | ||
9821 | /* Ask user only if there are some breakpoints to delete. */ | |
9822 | if (!from_tty | |
9823 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
9824 | { | |
9825 | ALL_BREAKPOINTS_SAFE (b, temp) | |
9826 | { | |
059fb39f PM |
9827 | if (b->type == bp_tracepoint |
9828 | && b->number >= 0) | |
1042e4c0 SS |
9829 | delete_breakpoint (b); |
9830 | } | |
9831 | } | |
9832 | } | |
9833 | else | |
9834 | map_breakpoint_numbers (arg, delete_breakpoint); | |
9835 | } | |
9836 | ||
9837 | /* Set passcount for tracepoint. | |
9838 | ||
9839 | First command argument is passcount, second is tracepoint number. | |
9840 | If tracepoint number omitted, apply to most recently defined. | |
9841 | Also accepts special argument "all". */ | |
9842 | ||
9843 | static void | |
9844 | trace_pass_command (char *args, int from_tty) | |
9845 | { | |
9846 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
9847 | unsigned int count; | |
9848 | int all = 0; | |
9849 | ||
9850 | if (args == 0 || *args == 0) | |
9851 | error (_("passcount command requires an argument (count + optional TP num)")); | |
9852 | ||
9853 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
9854 | ||
9855 | while (*args && isspace ((int) *args)) | |
9856 | args++; | |
9857 | ||
9858 | if (*args && strncasecmp (args, "all", 3) == 0) | |
9859 | { | |
9860 | args += 3; /* Skip special argument "all". */ | |
9861 | all = 1; | |
9862 | if (*args) | |
9863 | error (_("Junk at end of arguments.")); | |
9864 | } | |
9865 | else | |
9866 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
9867 | ||
9868 | do | |
9869 | { | |
9870 | if (t1) | |
9871 | { | |
9872 | ALL_TRACEPOINTS (t2) | |
9873 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
9874 | { | |
9875 | t2->pass_count = count; | |
9876 | observer_notify_tracepoint_modified (t2->number); | |
9877 | if (from_tty) | |
9878 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
9879 | t2->number, count); | |
9880 | } | |
9881 | if (! all && *args) | |
9882 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
9883 | } | |
9884 | } | |
9885 | while (*args); | |
9886 | } | |
9887 | ||
9888 | struct breakpoint * | |
9889 | get_tracepoint (int num) | |
9890 | { | |
9891 | struct breakpoint *t; | |
9892 | ||
9893 | ALL_TRACEPOINTS (t) | |
9894 | if (t->number == num) | |
9895 | return t; | |
9896 | ||
9897 | return NULL; | |
9898 | } | |
9899 | ||
9900 | /* Utility: parse a tracepoint number and look it up in the list. | |
9901 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
9902 | if OPTIONAL_P is true, then if the argument is missing, the most | |
9903 | recent tracepoint (tracepoint_count) is returned. */ | |
9904 | struct breakpoint * | |
9905 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
9906 | { | |
9907 | extern int tracepoint_count; | |
9908 | struct breakpoint *t; | |
9909 | int tpnum; | |
9910 | char *instring = arg == NULL ? NULL : *arg; | |
9911 | ||
9912 | if (arg == NULL || *arg == NULL || ! **arg) | |
9913 | { | |
9914 | if (optional_p) | |
9915 | tpnum = tracepoint_count; | |
9916 | else | |
9917 | error_no_arg (_("tracepoint number")); | |
9918 | } | |
9919 | else | |
9920 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
9921 | ||
9922 | if (tpnum <= 0) | |
9923 | { | |
9924 | if (instring && *instring) | |
9925 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
9926 | instring); | |
9927 | else | |
9928 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
9929 | return NULL; | |
9930 | } | |
9931 | ||
9932 | ALL_TRACEPOINTS (t) | |
9933 | if (t->number == tpnum) | |
9934 | { | |
9935 | return t; | |
9936 | } | |
9937 | ||
9938 | /* FIXME: if we are in the middle of a range we don't want to give | |
9939 | a message. The current interface to get_number_or_range doesn't | |
9940 | allow us to discover this. */ | |
9941 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
9942 | return NULL; | |
9943 | } | |
9944 | ||
9945 | /* save-tracepoints command */ | |
9946 | static void | |
9947 | tracepoint_save_command (char *args, int from_tty) | |
9948 | { | |
9949 | struct breakpoint *tp; | |
9950 | int any_tp = 0; | |
9951 | struct action_line *line; | |
9952 | FILE *fp; | |
9953 | char *i1 = " ", *i2 = " "; | |
9954 | char *indent, *actionline, *pathname; | |
9955 | char tmp[40]; | |
9956 | struct cleanup *cleanup; | |
9957 | ||
9958 | if (args == 0 || *args == 0) | |
9959 | error (_("Argument required (file name in which to save tracepoints)")); | |
9960 | ||
9961 | /* See if we have anything to save. */ | |
9962 | ALL_TRACEPOINTS (tp) | |
9963 | { | |
9964 | any_tp = 1; | |
9965 | break; | |
9966 | } | |
9967 | if (!any_tp) | |
9968 | { | |
9969 | warning (_("save-tracepoints: no tracepoints to save.")); | |
9970 | return; | |
9971 | } | |
9972 | ||
9973 | pathname = tilde_expand (args); | |
9974 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
9975 | fp = fopen (pathname, "w"); |
9976 | if (!fp) | |
1042e4c0 SS |
9977 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
9978 | args, safe_strerror (errno)); | |
9979 | make_cleanup_fclose (fp); | |
9980 | ||
9981 | ALL_TRACEPOINTS (tp) | |
9982 | { | |
9983 | if (tp->addr_string) | |
9984 | fprintf (fp, "trace %s\n", tp->addr_string); | |
9985 | else | |
9986 | { | |
9987 | sprintf_vma (tmp, tp->loc->address); | |
9988 | fprintf (fp, "trace *0x%s\n", tmp); | |
9989 | } | |
9990 | ||
9991 | if (tp->pass_count) | |
9992 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
9993 | ||
9994 | if (tp->actions) | |
9995 | { | |
9996 | fprintf (fp, " actions\n"); | |
9997 | indent = i1; | |
9998 | for (line = tp->actions; line; line = line->next) | |
9999 | { | |
10000 | struct cmd_list_element *cmd; | |
10001 | ||
10002 | QUIT; /* allow user to bail out with ^C */ | |
10003 | actionline = line->action; | |
10004 | while (isspace ((int) *actionline)) | |
10005 | actionline++; | |
10006 | ||
10007 | fprintf (fp, "%s%s\n", indent, actionline); | |
10008 | if (*actionline != '#') /* skip for comment lines */ | |
10009 | { | |
10010 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
10011 | if (cmd == 0) | |
10012 | error (_("Bad action list item: %s"), actionline); | |
10013 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
10014 | indent = i2; | |
10015 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
10016 | indent = i1; | |
10017 | } | |
10018 | } | |
10019 | } | |
10020 | } | |
10021 | do_cleanups (cleanup); | |
10022 | if (from_tty) | |
10023 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
10024 | return; | |
10025 | } | |
10026 | ||
10027 | /* Create a vector of all tracepoints. */ | |
10028 | ||
10029 | VEC(breakpoint_p) * | |
10030 | all_tracepoints () | |
10031 | { | |
10032 | VEC(breakpoint_p) *tp_vec = 0; | |
10033 | struct breakpoint *tp; | |
10034 | ||
10035 | ALL_TRACEPOINTS (tp) | |
10036 | { | |
10037 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
10038 | } | |
10039 | ||
10040 | return tp_vec; | |
10041 | } | |
10042 | ||
c906108c | 10043 | \f |
31e2b00f AS |
10044 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
10045 | It is defined as a macro to prevent duplication. | |
10046 | COMMAND should be a string constant containing the name of the command. */ | |
10047 | #define BREAK_ARGS_HELP(command) \ | |
10048 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
10049 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
10050 | If a line number is specified, break at start of code for that line.\n\ | |
10051 | If a function is specified, break at start of code for that function.\n\ | |
10052 | If an address is specified, break at that exact address.\n\ | |
10053 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
10054 | This is useful for breaking on return to a stack frame.\n\ | |
10055 | \n\ | |
10056 | THREADNUM is the number from \"info threads\".\n\ | |
10057 | CONDITION is a boolean expression.\n\ | |
10058 | \n\ | |
10059 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
10060 | \n\ | |
10061 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
10062 | ||
44feb3ce TT |
10063 | /* List of subcommands for "catch". */ |
10064 | static struct cmd_list_element *catch_cmdlist; | |
10065 | ||
10066 | /* List of subcommands for "tcatch". */ | |
10067 | static struct cmd_list_element *tcatch_cmdlist; | |
10068 | ||
10069 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
10070 | lists, and pass some additional user data to the command function. */ | |
10071 | static void | |
10072 | add_catch_command (char *name, char *docstring, | |
10073 | void (*sfunc) (char *args, int from_tty, | |
10074 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
10075 | char **(*completer) (struct cmd_list_element *cmd, |
10076 | char *text, char *word), | |
44feb3ce TT |
10077 | void *user_data_catch, |
10078 | void *user_data_tcatch) | |
10079 | { | |
10080 | struct cmd_list_element *command; | |
10081 | ||
10082 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10083 | &catch_cmdlist); | |
10084 | set_cmd_sfunc (command, sfunc); | |
10085 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 10086 | set_cmd_completer (command, completer); |
44feb3ce TT |
10087 | |
10088 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10089 | &tcatch_cmdlist); | |
10090 | set_cmd_sfunc (command, sfunc); | |
10091 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 10092 | set_cmd_completer (command, completer); |
44feb3ce TT |
10093 | } |
10094 | ||
6c95b8df PA |
10095 | static void |
10096 | clear_syscall_counts (int pid) | |
10097 | { | |
10098 | struct inferior *inf = find_inferior_pid (pid); | |
10099 | ||
10100 | inf->total_syscalls_count = 0; | |
10101 | inf->any_syscall_count = 0; | |
10102 | VEC_free (int, inf->syscalls_counts); | |
10103 | } | |
10104 | ||
c906108c | 10105 | void |
fba45db2 | 10106 | _initialize_breakpoint (void) |
c906108c | 10107 | { |
fa8d40ab JJ |
10108 | static struct cmd_list_element *breakpoint_set_cmdlist; |
10109 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
10110 | struct cmd_list_element *c; |
10111 | ||
84acb35a | 10112 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 10113 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 10114 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 10115 | |
c906108c SS |
10116 | breakpoint_chain = 0; |
10117 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
10118 | before a breakpoint is set. */ | |
10119 | breakpoint_count = 0; | |
10120 | ||
1042e4c0 SS |
10121 | tracepoint_count = 0; |
10122 | ||
1bedd215 AC |
10123 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
10124 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
10125 | Usage is `ignore N COUNT'.")); | |
c906108c | 10126 | if (xdb_commands) |
c5aa993b | 10127 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 10128 | |
1bedd215 AC |
10129 | add_com ("commands", class_breakpoint, commands_command, _("\ |
10130 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
10131 | Give breakpoint number as argument after \"commands\".\n\ |
10132 | With no argument, the targeted breakpoint is the last one set.\n\ | |
10133 | The commands themselves follow starting on the next line.\n\ | |
10134 | Type a line containing \"end\" to indicate the end of them.\n\ | |
10135 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 10136 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 10137 | |
1bedd215 AC |
10138 | add_com ("condition", class_breakpoint, condition_command, _("\ |
10139 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 10140 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 10141 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 10142 | |
1bedd215 | 10143 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 10144 | Set a temporary breakpoint.\n\ |
c906108c SS |
10145 | Like \"break\" except the breakpoint is only temporary,\n\ |
10146 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
10147 | by using \"enable delete\" on the breakpoint number.\n\ |
10148 | \n" | |
10149 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 10150 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10151 | |
1bedd215 | 10152 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 10153 | Set a hardware assisted breakpoint.\n\ |
c906108c | 10154 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
10155 | some target hardware may not have this support.\n\ |
10156 | \n" | |
10157 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 10158 | set_cmd_completer (c, location_completer); |
c906108c | 10159 | |
1bedd215 | 10160 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 10161 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 10162 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
10163 | so it will be deleted when hit.\n\ |
10164 | \n" | |
10165 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 10166 | set_cmd_completer (c, location_completer); |
c906108c | 10167 | |
1bedd215 AC |
10168 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
10169 | Enable some breakpoints.\n\ | |
c906108c SS |
10170 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10171 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10172 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10173 | With a subcommand you can enable temporarily."), |
c906108c SS |
10174 | &enablelist, "enable ", 1, &cmdlist); |
10175 | if (xdb_commands) | |
1bedd215 AC |
10176 | add_com ("ab", class_breakpoint, enable_command, _("\ |
10177 | Enable some breakpoints.\n\ | |
c906108c SS |
10178 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10179 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10180 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10181 | With a subcommand you can enable temporarily.")); |
c906108c SS |
10182 | |
10183 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
10184 | ||
1bedd215 AC |
10185 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
10186 | Enable some breakpoints.\n\ | |
c906108c SS |
10187 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10188 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10189 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 10190 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 10191 | |
1a966eab AC |
10192 | add_cmd ("once", no_class, enable_once_command, _("\ |
10193 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10194 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10195 | &enablebreaklist); |
10196 | ||
1a966eab AC |
10197 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10198 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10199 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10200 | &enablebreaklist); |
10201 | ||
1a966eab AC |
10202 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10203 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10204 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10205 | &enablelist); |
10206 | ||
1a966eab AC |
10207 | add_cmd ("once", no_class, enable_once_command, _("\ |
10208 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10209 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10210 | &enablelist); |
10211 | ||
1bedd215 AC |
10212 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
10213 | Disable some breakpoints.\n\ | |
c906108c SS |
10214 | Arguments are breakpoint numbers with spaces in between.\n\ |
10215 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10216 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
10217 | &disablelist, "disable ", 1, &cmdlist); |
10218 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
10219 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
10220 | if (xdb_commands) | |
1bedd215 AC |
10221 | add_com ("sb", class_breakpoint, disable_command, _("\ |
10222 | Disable some breakpoints.\n\ | |
c906108c SS |
10223 | Arguments are breakpoint numbers with spaces in between.\n\ |
10224 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10225 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 10226 | |
1a966eab AC |
10227 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10228 | Disable some breakpoints.\n\ | |
c906108c SS |
10229 | Arguments are breakpoint numbers with spaces in between.\n\ |
10230 | To disable all breakpoints, give no argument.\n\ | |
10231 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10232 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10233 | &disablelist); |
10234 | ||
1bedd215 AC |
10235 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10236 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10237 | Arguments are breakpoint numbers with spaces in between.\n\ |
10238 | To delete all breakpoints, give no argument.\n\ | |
10239 | \n\ | |
10240 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10241 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10242 | &deletelist, "delete ", 1, &cmdlist); |
10243 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10244 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10245 | if (xdb_commands) |
1bedd215 AC |
10246 | add_com ("db", class_breakpoint, delete_command, _("\ |
10247 | Delete some breakpoints.\n\ | |
c906108c | 10248 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10249 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10250 | |
1a966eab AC |
10251 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10252 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10253 | Arguments are breakpoint numbers with spaces in between.\n\ |
10254 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10255 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10256 | &deletelist); |
10257 | ||
1bedd215 AC |
10258 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10259 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10260 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10261 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10262 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10263 | If an address is specified, breakpoints at that address are cleared.\n\ |
10264 | \n\ | |
10265 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10266 | is executing in.\n\ |
10267 | \n\ | |
1bedd215 | 10268 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10269 | |
1bedd215 | 10270 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10271 | Set breakpoint at specified line or function.\n" |
10272 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10273 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10274 | |
c906108c SS |
10275 | add_com_alias ("b", "break", class_run, 1); |
10276 | add_com_alias ("br", "break", class_run, 1); | |
10277 | add_com_alias ("bre", "break", class_run, 1); | |
10278 | add_com_alias ("brea", "break", class_run, 1); | |
10279 | ||
7681d515 PM |
10280 | if (xdb_commands) |
10281 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
10282 | |
10283 | if (dbx_commands) | |
10284 | { | |
1bedd215 AC |
10285 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
10286 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
10287 | &stoplist, "stop ", 1, &cmdlist); |
10288 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 10289 | _("Break in function or address."), &stoplist); |
c5aa993b | 10290 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 10291 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
10292 | add_com ("status", class_info, breakpoints_info, _("\ |
10293 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10294 | The \"Type\" column indicates one of:\n\ |
10295 | \tbreakpoint - normal breakpoint\n\ | |
10296 | \twatchpoint - watchpoint\n\ | |
10297 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10298 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10299 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10300 | address and file/line number respectively.\n\ |
10301 | \n\ | |
10302 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10303 | are set to the address of the last breakpoint listed unless the command\n\ |
10304 | is prefixed with \"server \".\n\n\ | |
c906108c | 10305 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10306 | breakpoint set.")); |
c906108c SS |
10307 | } |
10308 | ||
1bedd215 AC |
10309 | add_info ("breakpoints", breakpoints_info, _("\ |
10310 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10311 | The \"Type\" column indicates one of:\n\ |
10312 | \tbreakpoint - normal breakpoint\n\ | |
10313 | \twatchpoint - watchpoint\n\ | |
10314 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10315 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10316 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10317 | address and file/line number respectively.\n\ |
10318 | \n\ | |
10319 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10320 | are set to the address of the last breakpoint listed unless the command\n\ |
10321 | is prefixed with \"server \".\n\n\ | |
c906108c | 10322 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10323 | breakpoint set.")); |
c906108c | 10324 | |
6b04bdb7 MS |
10325 | add_info_alias ("b", "breakpoints", 1); |
10326 | ||
c906108c | 10327 | if (xdb_commands) |
1bedd215 AC |
10328 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
10329 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10330 | The \"Type\" column indicates one of:\n\ |
10331 | \tbreakpoint - normal breakpoint\n\ | |
10332 | \twatchpoint - watchpoint\n\ | |
10333 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10334 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10335 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10336 | address and file/line number respectively.\n\ |
10337 | \n\ | |
10338 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10339 | are set to the address of the last breakpoint listed unless the command\n\ |
10340 | is prefixed with \"server \".\n\n\ | |
c906108c | 10341 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10342 | breakpoint set.")); |
c906108c | 10343 | |
1a966eab AC |
10344 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
10345 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10346 | The \"Type\" column indicates one of:\n\ |
10347 | \tbreakpoint - normal breakpoint\n\ | |
10348 | \twatchpoint - watchpoint\n\ | |
10349 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
10350 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
10351 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
10352 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
10353 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
10354 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
10355 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
10356 | address and file/line number respectively.\n\ |
10357 | \n\ | |
10358 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10359 | are set to the address of the last breakpoint listed unless the command\n\ |
10360 | is prefixed with \"server \".\n\n\ | |
c906108c | 10361 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 10362 | breakpoint set."), |
c906108c SS |
10363 | &maintenanceinfolist); |
10364 | ||
44feb3ce TT |
10365 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
10366 | Set catchpoints to catch events."), | |
10367 | &catch_cmdlist, "catch ", | |
10368 | 0/*allow-unknown*/, &cmdlist); | |
10369 | ||
10370 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
10371 | Set temporary catchpoints to catch events."), | |
10372 | &tcatch_cmdlist, "tcatch ", | |
10373 | 0/*allow-unknown*/, &cmdlist); | |
10374 | ||
10375 | /* Add catch and tcatch sub-commands. */ | |
10376 | add_catch_command ("catch", _("\ | |
10377 | Catch an exception, when caught.\n\ | |
10378 | With an argument, catch only exceptions with the given name."), | |
10379 | catch_catch_command, | |
a96d9b2e | 10380 | NULL, |
44feb3ce TT |
10381 | CATCH_PERMANENT, |
10382 | CATCH_TEMPORARY); | |
10383 | add_catch_command ("throw", _("\ | |
10384 | Catch an exception, when thrown.\n\ | |
10385 | With an argument, catch only exceptions with the given name."), | |
10386 | catch_throw_command, | |
a96d9b2e | 10387 | NULL, |
44feb3ce TT |
10388 | CATCH_PERMANENT, |
10389 | CATCH_TEMPORARY); | |
10390 | add_catch_command ("fork", _("Catch calls to fork."), | |
10391 | catch_fork_command_1, | |
a96d9b2e | 10392 | NULL, |
44feb3ce TT |
10393 | (void *) (uintptr_t) catch_fork_permanent, |
10394 | (void *) (uintptr_t) catch_fork_temporary); | |
10395 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
10396 | catch_fork_command_1, | |
a96d9b2e | 10397 | NULL, |
44feb3ce TT |
10398 | (void *) (uintptr_t) catch_vfork_permanent, |
10399 | (void *) (uintptr_t) catch_vfork_temporary); | |
10400 | add_catch_command ("exec", _("Catch calls to exec."), | |
10401 | catch_exec_command_1, | |
a96d9b2e SDJ |
10402 | NULL, |
10403 | CATCH_PERMANENT, | |
10404 | CATCH_TEMPORARY); | |
10405 | add_catch_command ("syscall", _("\ | |
10406 | Catch system calls by their names and/or numbers.\n\ | |
10407 | Arguments say which system calls to catch. If no arguments\n\ | |
10408 | are given, every system call will be caught.\n\ | |
10409 | Arguments, if given, should be one or more system call names\n\ | |
10410 | (if your system supports that), or system call numbers."), | |
10411 | catch_syscall_command_1, | |
10412 | catch_syscall_completer, | |
44feb3ce TT |
10413 | CATCH_PERMANENT, |
10414 | CATCH_TEMPORARY); | |
44feb3ce TT |
10415 | add_catch_command ("exception", _("\ |
10416 | Catch Ada exceptions, when raised.\n\ | |
10417 | With an argument, catch only exceptions with the given name."), | |
10418 | catch_ada_exception_command, | |
a96d9b2e | 10419 | NULL, |
44feb3ce TT |
10420 | CATCH_PERMANENT, |
10421 | CATCH_TEMPORARY); | |
10422 | add_catch_command ("assert", _("\ | |
10423 | Catch failed Ada assertions, when raised.\n\ | |
10424 | With an argument, catch only exceptions with the given name."), | |
10425 | catch_assert_command, | |
a96d9b2e | 10426 | NULL, |
44feb3ce TT |
10427 | CATCH_PERMANENT, |
10428 | CATCH_TEMPORARY); | |
c5aa993b | 10429 | |
1bedd215 AC |
10430 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
10431 | Set a watchpoint for an expression.\n\ | |
c906108c | 10432 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10433 | an expression changes.")); |
65d12d83 | 10434 | set_cmd_completer (c, expression_completer); |
c906108c | 10435 | |
1bedd215 AC |
10436 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
10437 | Set a read watchpoint for an expression.\n\ | |
c906108c | 10438 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10439 | an expression is read.")); |
65d12d83 | 10440 | set_cmd_completer (c, expression_completer); |
c906108c | 10441 | |
1bedd215 AC |
10442 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
10443 | Set a watchpoint for an expression.\n\ | |
c906108c | 10444 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10445 | an expression is either read or written.")); |
65d12d83 | 10446 | set_cmd_completer (c, expression_completer); |
c906108c SS |
10447 | |
10448 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 10449 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
10450 | |
10451 | ||
920d2a44 AC |
10452 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
10453 | respond to changes - contrary to the description. */ | |
85c07804 AC |
10454 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
10455 | &can_use_hw_watchpoints, _("\ | |
10456 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
10457 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
10458 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
10459 | such is available. (However, any hardware watchpoints that were\n\ | |
10460 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
10461 | hardware.)"), |
10462 | NULL, | |
920d2a44 | 10463 | show_can_use_hw_watchpoints, |
85c07804 | 10464 | &setlist, &showlist); |
c906108c SS |
10465 | |
10466 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 10467 | |
1042e4c0 SS |
10468 | /* Tracepoint manipulation commands. */ |
10469 | ||
10470 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
10471 | Set a tracepoint at specified line or function.\n\ | |
10472 | \n" | |
10473 | BREAK_ARGS_HELP ("trace") "\n\ | |
10474 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
10475 | set_cmd_completer (c, location_completer); | |
10476 | ||
10477 | add_com_alias ("tp", "trace", class_alias, 0); | |
10478 | add_com_alias ("tr", "trace", class_alias, 1); | |
10479 | add_com_alias ("tra", "trace", class_alias, 1); | |
10480 | add_com_alias ("trac", "trace", class_alias, 1); | |
10481 | ||
10482 | add_info ("tracepoints", tracepoints_info, _("\ | |
10483 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
10484 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
10485 | last tracepoint set.")); | |
10486 | ||
10487 | add_info_alias ("tp", "tracepoints", 1); | |
10488 | ||
10489 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
10490 | Delete specified tracepoints.\n\ | |
10491 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10492 | No argument means delete all tracepoints."), | |
10493 | &deletelist); | |
10494 | ||
10495 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
10496 | Disable specified tracepoints.\n\ | |
10497 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10498 | No argument means disable all tracepoints."), | |
10499 | &disablelist); | |
10500 | deprecate_cmd (c, "disable"); | |
10501 | ||
10502 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
10503 | Enable specified tracepoints.\n\ | |
10504 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10505 | No argument means enable all tracepoints."), | |
10506 | &enablelist); | |
10507 | deprecate_cmd (c, "enable"); | |
10508 | ||
10509 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
10510 | Set the passcount for a tracepoint.\n\ | |
10511 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
10512 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
10513 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
10514 | ||
10515 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
10516 | Save current tracepoint definitions as a script.\n\ | |
10517 | Use the 'source' command in another debug session to restore them.")); | |
10518 | set_cmd_completer (c, filename_completer); | |
10519 | ||
1bedd215 | 10520 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10521 | Breakpoint specific settings\n\ |
10522 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10523 | pending breakpoint behavior"), |
fa8d40ab JJ |
10524 | &breakpoint_set_cmdlist, "set breakpoint ", |
10525 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 10526 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10527 | Breakpoint specific settings\n\ |
10528 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10529 | pending breakpoint behavior"), |
fa8d40ab JJ |
10530 | &breakpoint_show_cmdlist, "show breakpoint ", |
10531 | 0/*allow-unknown*/, &showlist); | |
10532 | ||
7915a72c AC |
10533 | add_setshow_auto_boolean_cmd ("pending", no_class, |
10534 | &pending_break_support, _("\ | |
10535 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
10536 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
10537 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
10538 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
10539 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 10540 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 10541 | NULL, |
920d2a44 | 10542 | show_pending_break_support, |
6e1d7d6c AC |
10543 | &breakpoint_set_cmdlist, |
10544 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
10545 | |
10546 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
10547 | |
10548 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
10549 | &automatic_hardware_breakpoints, _("\ | |
10550 | Set automatic usage of hardware breakpoints."), _("\ | |
10551 | Show automatic usage of hardware breakpoints."), _("\ | |
10552 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
10553 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
10554 | a warning will be emitted for such breakpoints."), | |
10555 | NULL, | |
10556 | show_automatic_hardware_breakpoints, | |
10557 | &breakpoint_set_cmdlist, | |
10558 | &breakpoint_show_cmdlist); | |
74960c60 | 10559 | |
33e5cbd6 PA |
10560 | add_setshow_enum_cmd ("always-inserted", class_support, |
10561 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
10562 | Set mode for inserting breakpoints."), _("\ |
10563 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
10564 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
10565 | resumed, and removed when execution stops. When this mode is on,\n\ | |
10566 | breakpoints are inserted immediately and removed only when the user\n\ | |
10567 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
10568 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
10569 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
10570 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
10571 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
10572 | NULL, |
10573 | &show_always_inserted_mode, | |
10574 | &breakpoint_set_cmdlist, | |
10575 | &breakpoint_show_cmdlist); | |
765dc015 VP |
10576 | |
10577 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
10578 | |
10579 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 10580 | } |