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 | ||
567e1b4e JB |
988 | /* Assuming that B is a watchpoint: |
989 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 990 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
991 | - Evaluate the condition if there is one, and store the result |
992 | in b->loc->cond. | |
a5606eee VP |
993 | - Update the list of values that must be watched in B->loc. |
994 | ||
bfa149ac JB |
995 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
996 | If this is local watchpoint that is out of scope, delete it. */ | |
b40ce68a | 997 | static void |
a5606eee | 998 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 999 | { |
a5606eee | 1000 | int within_current_scope; |
a5606eee VP |
1001 | struct frame_id saved_frame_id; |
1002 | struct bp_location *loc; | |
1003 | bpstat bs; | |
6c95b8df | 1004 | struct program_space *frame_pspace; |
a5606eee | 1005 | |
876fa593 | 1006 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1007 | update_global_locations will eventually delete them and remove |
1008 | breakpoints if needed. */ | |
a5606eee VP |
1009 | b->loc = NULL; |
1010 | ||
1011 | if (b->disposition == disp_del_at_next_stop) | |
1012 | return; | |
1013 | ||
1014 | /* Save the current frame's ID so we can restore it after | |
1015 | evaluating the watchpoint expression on its own frame. */ | |
1016 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1017 | took a frame parameter, so that we didn't have to change the | |
1018 | selected frame. */ | |
1019 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1020 | ||
1021 | /* Determine if the watchpoint is within scope. */ | |
1022 | if (b->exp_valid_block == NULL) | |
1023 | within_current_scope = 1; | |
1024 | else | |
1025 | { | |
1026 | struct frame_info *fi; | |
1027 | fi = frame_find_by_id (b->watchpoint_frame); | |
1028 | within_current_scope = (fi != NULL); | |
1029 | if (within_current_scope) | |
1030 | select_frame (fi); | |
1031 | } | |
1032 | ||
6c95b8df PA |
1033 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1034 | ||
a5606eee VP |
1035 | if (within_current_scope && reparse) |
1036 | { | |
1037 | char *s; | |
1038 | if (b->exp) | |
1039 | { | |
1040 | xfree (b->exp); | |
1041 | b->exp = NULL; | |
1042 | } | |
1043 | s = b->exp_string; | |
1044 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1045 | /* If the meaning of expression itself changed, the old value is | |
1046 | no longer relevant. We don't want to report a watchpoint hit | |
1047 | to the user when the old value and the new value may actually | |
1048 | be completely different objects. */ | |
1049 | value_free (b->val); | |
fa4727a6 DJ |
1050 | b->val = NULL; |
1051 | b->val_valid = 0; | |
a5606eee | 1052 | } |
a5606eee VP |
1053 | |
1054 | /* If we failed to parse the expression, for example because | |
1055 | it refers to a global variable in a not-yet-loaded shared library, | |
1056 | don't try to insert watchpoint. We don't automatically delete | |
1057 | such watchpoint, though, since failure to parse expression | |
1058 | is different from out-of-scope watchpoint. */ | |
1059 | if (within_current_scope && b->exp) | |
1060 | { | |
fa4727a6 | 1061 | struct value *val_chain, *v, *result, *next; |
a5606eee | 1062 | |
fa4727a6 | 1063 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1064 | |
a5606eee VP |
1065 | /* Avoid setting b->val if it's already set. The meaning of |
1066 | b->val is 'the last value' user saw, and we should update | |
1067 | it only if we reported that last value to user. As it | |
1068 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1069 | if (!b->val_valid) |
1070 | { | |
1071 | b->val = v; | |
1072 | b->val_valid = 1; | |
1073 | } | |
a5606eee | 1074 | |
db2ad4c3 JK |
1075 | /* Change the type of breakpoint between hardware assisted or an |
1076 | ordinary watchpoint depending on the hardware support and free | |
1077 | hardware slots. REPARSE is set when the inferior is started. */ | |
1078 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1079 | && reparse) | |
1080 | { | |
ca2d49e8 | 1081 | int i, mem_cnt, other_type_used; |
db2ad4c3 JK |
1082 | |
1083 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, | |
1084 | &other_type_used); | |
1085 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1086 | ||
ca2d49e8 | 1087 | if (!mem_cnt) |
db2ad4c3 JK |
1088 | b->type = bp_watchpoint; |
1089 | else | |
ca2d49e8 | 1090 | { |
d92524f1 | 1091 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1092 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1093 | if (target_resources_ok <= 0) | |
1094 | b->type = bp_watchpoint; | |
1095 | else | |
1096 | b->type = bp_hardware_watchpoint; | |
1097 | } | |
db2ad4c3 JK |
1098 | } |
1099 | ||
a5606eee | 1100 | /* Look at each value on the value chain. */ |
fa4727a6 | 1101 | for (v = val_chain; v; v = next) |
a5606eee VP |
1102 | { |
1103 | /* If it's a memory location, and GDB actually needed | |
1104 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1105 | must watch it. If the first value returned is |
1106 | still lazy, that means an error occurred reading it; | |
1107 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1108 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1109 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1110 | { |
1111 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1112 | |
a5606eee VP |
1113 | /* We only watch structs and arrays if user asked |
1114 | for it explicitly, never if they just happen to | |
1115 | appear in the middle of some value chain. */ | |
fa4727a6 | 1116 | if (v == result |
a5606eee VP |
1117 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1118 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1119 | { | |
1120 | CORE_ADDR addr; | |
1121 | int len, type; | |
1122 | struct bp_location *loc, **tmp; | |
1123 | ||
42ae5230 | 1124 | addr = value_address (v); |
a5606eee VP |
1125 | len = TYPE_LENGTH (value_type (v)); |
1126 | type = hw_write; | |
1127 | if (b->type == bp_read_watchpoint) | |
1128 | type = hw_read; | |
1129 | else if (b->type == bp_access_watchpoint) | |
1130 | type = hw_access; | |
1131 | ||
39d61571 | 1132 | loc = allocate_bp_location (b); |
a5606eee VP |
1133 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1134 | ; | |
1135 | *tmp = loc; | |
a6d9a66e | 1136 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1137 | |
1138 | loc->pspace = frame_pspace; | |
a5606eee VP |
1139 | loc->address = addr; |
1140 | loc->length = len; | |
1141 | loc->watchpoint_type = type; | |
1142 | } | |
1143 | } | |
1144 | ||
1145 | next = value_next (v); | |
1146 | if (v != b->val) | |
1147 | value_free (v); | |
1148 | } | |
1149 | ||
2ec93238 MK |
1150 | /* We just regenerated the list of breakpoint locations. |
1151 | The new location does not have its condition field set to anything | |
1152 | and therefore, we must always reparse the cond_string, independently | |
1153 | of the value of the reparse flag. */ | |
1154 | if (b->cond_string != NULL) | |
a5606eee VP |
1155 | { |
1156 | char *s = b->cond_string; | |
a5606eee VP |
1157 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1158 | } | |
1159 | } | |
1160 | else if (!within_current_scope) | |
7270d8f2 | 1161 | { |
a5606eee | 1162 | printf_filtered (_("\ |
567e1b4e | 1163 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1164 | in which its expression is valid.\n"), |
1165 | b->number); | |
1166 | if (b->related_breakpoint) | |
1167 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1168 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1169 | } |
a5606eee VP |
1170 | |
1171 | /* Restore the selected frame. */ | |
1172 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1173 | } |
1174 | ||
a5606eee | 1175 | |
74960c60 VP |
1176 | /* Returns 1 iff breakpoint location should be |
1177 | inserted in the inferior. */ | |
1178 | static int | |
1179 | should_be_inserted (struct bp_location *bpt) | |
1180 | { | |
1181 | if (!breakpoint_enabled (bpt->owner)) | |
1182 | return 0; | |
1183 | ||
1184 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1185 | return 0; | |
1186 | ||
1187 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1188 | return 0; | |
1189 | ||
1042e4c0 SS |
1190 | /* Tracepoints are inserted by the target at a time of its choosing, |
1191 | not by us. */ | |
1192 | if (bpt->owner->type == bp_tracepoint) | |
1193 | return 0; | |
1194 | ||
74960c60 VP |
1195 | return 1; |
1196 | } | |
1197 | ||
879bfdc2 DJ |
1198 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1199 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1200 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1201 | |
1202 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1203 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1204 | static int |
879bfdc2 | 1205 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1206 | struct ui_file *tmp_error_stream, |
fa3a767f | 1207 | int *disabled_breaks, |
26bb91f3 | 1208 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1209 | { |
1210 | int val = 0; | |
1211 | ||
74960c60 | 1212 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1213 | return 0; |
1214 | ||
8181d85f DJ |
1215 | /* Initialize the target-specific information. */ |
1216 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1217 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1218 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1219 | |
879bfdc2 DJ |
1220 | if (bpt->loc_type == bp_loc_software_breakpoint |
1221 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1222 | { | |
765dc015 VP |
1223 | if (bpt->owner->type != bp_hardware_breakpoint) |
1224 | { | |
1225 | /* If the explicitly specified breakpoint type | |
1226 | is not hardware breakpoint, check the memory map to see | |
1227 | if the breakpoint address is in read only memory or not. | |
1228 | Two important cases are: | |
1229 | - location type is not hardware breakpoint, memory | |
1230 | is readonly. We change the type of the location to | |
1231 | hardware breakpoint. | |
1232 | - location type is hardware breakpoint, memory is read-write. | |
1233 | This means we've previously made the location hardware one, but | |
1234 | then the memory map changed, so we undo. | |
1235 | ||
1236 | When breakpoints are removed, remove_breakpoints will | |
1237 | use location types we've just set here, the only possible | |
1238 | problem is that memory map has changed during running program, | |
1239 | but it's not going to work anyway with current gdb. */ | |
1240 | struct mem_region *mr | |
1241 | = lookup_mem_region (bpt->target_info.placed_address); | |
1242 | ||
1243 | if (mr) | |
1244 | { | |
1245 | if (automatic_hardware_breakpoints) | |
1246 | { | |
1247 | int changed = 0; | |
1248 | enum bp_loc_type new_type; | |
1249 | ||
1250 | if (mr->attrib.mode != MEM_RW) | |
1251 | new_type = bp_loc_hardware_breakpoint; | |
1252 | else | |
1253 | new_type = bp_loc_software_breakpoint; | |
1254 | ||
1255 | if (new_type != bpt->loc_type) | |
1256 | { | |
1257 | static int said = 0; | |
1258 | bpt->loc_type = new_type; | |
1259 | if (!said) | |
1260 | { | |
1261 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1262 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1263 | said = 1; |
1264 | } | |
1265 | } | |
1266 | } | |
1267 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1268 | && mr->attrib.mode != MEM_RW) | |
1269 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1270 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1271 | } |
1272 | } | |
1273 | ||
879bfdc2 DJ |
1274 | /* First check to see if we have to handle an overlay. */ |
1275 | if (overlay_debugging == ovly_off | |
1276 | || bpt->section == NULL | |
1277 | || !(section_is_overlay (bpt->section))) | |
1278 | { | |
1279 | /* No overlay handling: just set the breakpoint. */ | |
1280 | ||
1281 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1282 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1283 | &bpt->target_info); | |
879bfdc2 | 1284 | else |
a6d9a66e UW |
1285 | val = target_insert_breakpoint (bpt->gdbarch, |
1286 | &bpt->target_info); | |
879bfdc2 DJ |
1287 | } |
1288 | else | |
1289 | { | |
1290 | /* This breakpoint is in an overlay section. | |
1291 | Shall we set a breakpoint at the LMA? */ | |
1292 | if (!overlay_events_enabled) | |
1293 | { | |
1294 | /* Yes -- overlay event support is not active, | |
1295 | so we must try to set a breakpoint at the LMA. | |
1296 | This will not work for a hardware breakpoint. */ | |
1297 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1298 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1299 | bpt->owner->number); |
1300 | else | |
1301 | { | |
1302 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1303 | bpt->section); | |
1304 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1305 | bpt->overlay_target_info = bpt->target_info; |
1306 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1307 | val = target_insert_breakpoint (bpt->gdbarch, |
1308 | &bpt->overlay_target_info); | |
879bfdc2 | 1309 | if (val != 0) |
99361f52 DE |
1310 | fprintf_unfiltered (tmp_error_stream, |
1311 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1312 | bpt->owner->number); |
1313 | } | |
1314 | } | |
1315 | /* Shall we set a breakpoint at the VMA? */ | |
1316 | if (section_is_mapped (bpt->section)) | |
1317 | { | |
1318 | /* Yes. This overlay section is mapped into memory. */ | |
1319 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1320 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1321 | &bpt->target_info); | |
879bfdc2 | 1322 | else |
a6d9a66e UW |
1323 | val = target_insert_breakpoint (bpt->gdbarch, |
1324 | &bpt->target_info); | |
879bfdc2 DJ |
1325 | } |
1326 | else | |
1327 | { | |
1328 | /* No. This breakpoint will not be inserted. | |
1329 | No error, but do not mark the bp as 'inserted'. */ | |
1330 | return 0; | |
1331 | } | |
1332 | } | |
1333 | ||
1334 | if (val) | |
1335 | { | |
1336 | /* Can't set the breakpoint. */ | |
6c95b8df | 1337 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1338 | { |
1339 | /* See also: disable_breakpoints_in_shlibs. */ | |
1340 | val = 0; | |
0d381245 | 1341 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1342 | if (!*disabled_breaks) |
1343 | { | |
1344 | fprintf_unfiltered (tmp_error_stream, | |
1345 | "Cannot insert breakpoint %d.\n", | |
1346 | bpt->owner->number); | |
1347 | fprintf_unfiltered (tmp_error_stream, | |
1348 | "Temporarily disabling shared library breakpoints:\n"); | |
1349 | } | |
1350 | *disabled_breaks = 1; | |
1351 | fprintf_unfiltered (tmp_error_stream, | |
1352 | "breakpoint #%d\n", bpt->owner->number); | |
1353 | } | |
1354 | else | |
879bfdc2 | 1355 | { |
879bfdc2 DJ |
1356 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1357 | { | |
1358 | *hw_breakpoint_error = 1; | |
1359 | fprintf_unfiltered (tmp_error_stream, | |
1360 | "Cannot insert hardware breakpoint %d.\n", | |
1361 | bpt->owner->number); | |
1362 | } | |
1363 | else | |
1364 | { | |
1365 | fprintf_unfiltered (tmp_error_stream, | |
1366 | "Cannot insert breakpoint %d.\n", | |
1367 | bpt->owner->number); | |
1368 | fprintf_filtered (tmp_error_stream, | |
1369 | "Error accessing memory address "); | |
5af949e3 UW |
1370 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1371 | tmp_error_stream); | |
879bfdc2 DJ |
1372 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1373 | safe_strerror (val)); | |
1374 | } | |
1375 | ||
1376 | } | |
1377 | } | |
1378 | else | |
1379 | bpt->inserted = 1; | |
1380 | ||
1381 | return val; | |
1382 | } | |
1383 | ||
1384 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1385 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1386 | watchpoints. It's not clear that it's necessary... */ | |
1387 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1388 | { | |
a5606eee VP |
1389 | val = target_insert_watchpoint (bpt->address, |
1390 | bpt->length, | |
1391 | bpt->watchpoint_type); | |
1392 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1393 | } |
1394 | ||
fe798b75 | 1395 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1396 | { |
71fff37b AC |
1397 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1398 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1399 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1400 | bpt->owner->number); | |
1401 | if (e.reason < 0) | |
879bfdc2 DJ |
1402 | bpt->owner->enable_state = bp_disabled; |
1403 | else | |
1404 | bpt->inserted = 1; | |
1640b821 DJ |
1405 | |
1406 | /* We've already printed an error message if there was a problem | |
1407 | inserting this catchpoint, and we've disabled the catchpoint, | |
1408 | so just return success. */ | |
1409 | return 0; | |
879bfdc2 DJ |
1410 | } |
1411 | ||
1412 | return 0; | |
1413 | } | |
1414 | ||
6c95b8df PA |
1415 | /* This function is called when program space PSPACE is about to be |
1416 | deleted. It takes care of updating breakpoints to not reference | |
1417 | PSPACE anymore. */ | |
1418 | ||
1419 | void | |
1420 | breakpoint_program_space_exit (struct program_space *pspace) | |
1421 | { | |
1422 | struct breakpoint *b, *b_temp; | |
876fa593 | 1423 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1424 | |
1425 | /* Remove any breakpoint that was set through this program space. */ | |
1426 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1427 | { | |
1428 | if (b->pspace == pspace) | |
1429 | delete_breakpoint (b); | |
1430 | } | |
1431 | ||
1432 | /* Breakpoints set through other program spaces could have locations | |
1433 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1434 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1435 | { |
1436 | struct bp_location *tmp; | |
1437 | ||
1438 | if (loc->pspace == pspace) | |
1439 | { | |
1440 | if (loc->owner->loc == loc) | |
1441 | loc->owner->loc = loc->next; | |
1442 | else | |
1443 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1444 | if (tmp->next == loc) | |
1445 | { | |
1446 | tmp->next = loc->next; | |
1447 | break; | |
1448 | } | |
1449 | } | |
1450 | } | |
1451 | ||
1452 | /* Now update the global location list to permanently delete the | |
1453 | removed locations above. */ | |
1454 | update_global_location_list (0); | |
1455 | } | |
1456 | ||
74960c60 VP |
1457 | /* Make sure all breakpoints are inserted in inferior. |
1458 | Throws exception on any error. | |
1459 | A breakpoint that is already inserted won't be inserted | |
1460 | again, so calling this function twice is safe. */ | |
1461 | void | |
1462 | insert_breakpoints (void) | |
1463 | { | |
1464 | struct breakpoint *bpt; | |
1465 | ||
1466 | ALL_BREAKPOINTS (bpt) | |
1467 | if (is_hardware_watchpoint (bpt)) | |
1468 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1469 | ||
b60e7edf | 1470 | update_global_location_list (1); |
74960c60 | 1471 | |
c35b1492 PA |
1472 | /* update_global_location_list does not insert breakpoints when |
1473 | always_inserted_mode is not enabled. Explicitly insert them | |
1474 | now. */ | |
1475 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1476 | insert_breakpoint_locations (); |
1477 | } | |
1478 | ||
c906108c SS |
1479 | /* insert_breakpoints is used when starting or continuing the program. |
1480 | remove_breakpoints is used when the program stops. | |
1481 | Both return zero if successful, | |
1482 | or an `errno' value if could not write the inferior. */ | |
1483 | ||
74960c60 VP |
1484 | static void |
1485 | insert_breakpoint_locations (void) | |
c906108c | 1486 | { |
a5606eee | 1487 | struct breakpoint *bpt; |
876fa593 | 1488 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1489 | int error = 0; |
c906108c SS |
1490 | int val = 0; |
1491 | int disabled_breaks = 0; | |
81d0cc19 | 1492 | int hw_breakpoint_error = 0; |
c906108c | 1493 | |
81d0cc19 | 1494 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1495 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1496 | |
81d0cc19 GS |
1497 | /* Explicitly mark the warning -- this will only be printed if |
1498 | there was an error. */ | |
1499 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1500 | |
1501 | save_current_space_and_thread (); | |
1502 | ||
876fa593 | 1503 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1504 | { |
6c95b8df PA |
1505 | struct thread_info *tp; |
1506 | CORE_ADDR last_addr; | |
1507 | ||
74960c60 | 1508 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1509 | continue; |
1510 | ||
f365de73 AS |
1511 | /* There is no point inserting thread-specific breakpoints if the |
1512 | thread no longer exists. */ | |
1513 | if (b->owner->thread != -1 | |
1514 | && !valid_thread_id (b->owner->thread)) | |
1515 | continue; | |
1516 | ||
6c95b8df PA |
1517 | switch_to_program_space_and_thread (b->pspace); |
1518 | ||
1519 | /* For targets that support global breakpoints, there's no need | |
1520 | to select an inferior to insert breakpoint to. In fact, even | |
1521 | if we aren't attached to any process yet, we should still | |
1522 | insert breakpoints. */ | |
1523 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1524 | && ptid_equal (inferior_ptid, null_ptid)) | |
1525 | continue; | |
1526 | ||
1527 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
1528 | { | |
1529 | struct inferior *inf = current_inferior (); | |
1530 | if (inf->waiting_for_vfork_done) | |
1531 | { | |
1532 | /* This is set when we're attached to the parent of the | |
1533 | vfork, and have detached from the child. The child | |
1534 | is running free, and we expect it to do an exec or | |
1535 | exit, at which point the OS makes the parent | |
1536 | schedulable again (and the target reports that the | |
1537 | vfork is done). Until the child is done with the | |
1538 | shared memory region, do not insert breakpoints in | |
1539 | parent, otherwise the child could still trip on the | |
1540 | parent's breakpoints. Since the parent is blocked | |
1541 | anyway, it won't miss any breakpoint. */ | |
1542 | continue; | |
1543 | } | |
1544 | } | |
1545 | ||
879bfdc2 | 1546 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1547 | &disabled_breaks, |
879bfdc2 DJ |
1548 | &hw_breakpoint_error); |
1549 | if (val) | |
e236ba44 | 1550 | error = val; |
879bfdc2 | 1551 | } |
c906108c | 1552 | |
a5606eee VP |
1553 | /* If we failed to insert all locations of a watchpoint, |
1554 | remove them, as half-inserted watchpoint is of limited use. */ | |
1555 | ALL_BREAKPOINTS (bpt) | |
1556 | { | |
1557 | int some_failed = 0; | |
1558 | struct bp_location *loc; | |
1559 | ||
1560 | if (!is_hardware_watchpoint (bpt)) | |
1561 | continue; | |
1562 | ||
d6b74ac4 | 1563 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1564 | continue; |
74960c60 VP |
1565 | |
1566 | if (bpt->disposition == disp_del_at_next_stop) | |
1567 | continue; | |
a5606eee VP |
1568 | |
1569 | for (loc = bpt->loc; loc; loc = loc->next) | |
1570 | if (!loc->inserted) | |
1571 | { | |
1572 | some_failed = 1; | |
1573 | break; | |
1574 | } | |
1575 | if (some_failed) | |
1576 | { | |
1577 | for (loc = bpt->loc; loc; loc = loc->next) | |
1578 | if (loc->inserted) | |
1579 | remove_breakpoint (loc, mark_uninserted); | |
1580 | ||
1581 | hw_breakpoint_error = 1; | |
1582 | fprintf_unfiltered (tmp_error_stream, | |
1583 | "Could not insert hardware watchpoint %d.\n", | |
1584 | bpt->number); | |
1585 | error = -1; | |
1586 | } | |
1587 | } | |
1588 | ||
e236ba44 | 1589 | if (error) |
81d0cc19 GS |
1590 | { |
1591 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1592 | message about possibly exhausted resources. */ | |
879bfdc2 | 1593 | if (hw_breakpoint_error) |
81d0cc19 | 1594 | { |
c6510018 MS |
1595 | fprintf_unfiltered (tmp_error_stream, |
1596 | "Could not insert hardware breakpoints:\n\ | |
1597 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1598 | } |
81d0cc19 GS |
1599 | target_terminal_ours_for_output (); |
1600 | error_stream (tmp_error_stream); | |
1601 | } | |
f7545552 TT |
1602 | |
1603 | do_cleanups (cleanups); | |
c906108c SS |
1604 | } |
1605 | ||
c906108c | 1606 | int |
fba45db2 | 1607 | remove_breakpoints (void) |
c906108c | 1608 | { |
876fa593 | 1609 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1610 | int val = 0; |
c906108c | 1611 | |
876fa593 | 1612 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1613 | { |
0bde7532 | 1614 | if (b->inserted) |
3a1bae8e | 1615 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1616 | } |
3a1bae8e | 1617 | return val; |
c906108c SS |
1618 | } |
1619 | ||
6c95b8df PA |
1620 | /* Remove breakpoints of process PID. */ |
1621 | ||
1622 | int | |
1623 | remove_breakpoints_pid (int pid) | |
1624 | { | |
876fa593 | 1625 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1626 | int val; |
1627 | struct inferior *inf = find_inferior_pid (pid); | |
1628 | ||
876fa593 | 1629 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
1630 | { |
1631 | if (b->pspace != inf->pspace) | |
1632 | continue; | |
1633 | ||
1634 | if (b->inserted) | |
1635 | { | |
1636 | val = remove_breakpoint (b, mark_uninserted); | |
1637 | if (val != 0) | |
1638 | return val; | |
1639 | } | |
1640 | } | |
1641 | return 0; | |
1642 | } | |
1643 | ||
692590c1 | 1644 | int |
80ce1ecb | 1645 | remove_hw_watchpoints (void) |
692590c1 | 1646 | { |
876fa593 | 1647 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1648 | int val = 0; |
692590c1 | 1649 | |
876fa593 | 1650 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 1651 | { |
0bde7532 | 1652 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1653 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1654 | } |
3a1bae8e | 1655 | return val; |
692590c1 MS |
1656 | } |
1657 | ||
c906108c | 1658 | int |
fba45db2 | 1659 | reattach_breakpoints (int pid) |
c906108c | 1660 | { |
6c95b8df | 1661 | struct cleanup *old_chain; |
876fa593 | 1662 | struct bp_location *b, **bp_tmp; |
c906108c | 1663 | int val; |
a4954f26 | 1664 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1665 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
1666 | struct inferior *inf; |
1667 | struct thread_info *tp; | |
1668 | ||
1669 | tp = any_live_thread_of_process (pid); | |
1670 | if (tp == NULL) | |
1671 | return 1; | |
1672 | ||
1673 | inf = find_inferior_pid (pid); | |
1674 | old_chain = save_inferior_ptid (); | |
1675 | ||
1676 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
1677 | |
1678 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1679 | |
876fa593 | 1680 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1681 | { |
6c95b8df PA |
1682 | if (b->pspace != inf->pspace) |
1683 | continue; | |
1684 | ||
0bde7532 | 1685 | if (b->inserted) |
c5aa993b | 1686 | { |
a4954f26 DJ |
1687 | b->inserted = 0; |
1688 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1689 | &dummy1, &dummy2); |
c5aa993b JM |
1690 | if (val != 0) |
1691 | { | |
ce696e05 | 1692 | do_cleanups (old_chain); |
c5aa993b JM |
1693 | return val; |
1694 | } | |
1695 | } | |
1696 | } | |
ce696e05 | 1697 | do_cleanups (old_chain); |
c906108c SS |
1698 | return 0; |
1699 | } | |
1700 | ||
e58b0e63 PA |
1701 | static int internal_breakpoint_number = -1; |
1702 | ||
e62c965a | 1703 | static struct breakpoint * |
a6d9a66e UW |
1704 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1705 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1706 | { |
e62c965a PP |
1707 | struct symtab_and_line sal; |
1708 | struct breakpoint *b; | |
1709 | ||
1710 | init_sal (&sal); /* initialize to zeroes */ | |
1711 | ||
1712 | sal.pc = address; | |
1713 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 1714 | sal.pspace = current_program_space; |
e62c965a | 1715 | |
a6d9a66e | 1716 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1717 | b->number = internal_breakpoint_number--; |
1718 | b->disposition = disp_donttouch; | |
1719 | ||
1720 | return b; | |
1721 | } | |
1722 | ||
1723 | static void | |
69de3c6a | 1724 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1725 | { |
69de3c6a | 1726 | struct objfile *objfile; |
e62c965a | 1727 | |
69de3c6a PP |
1728 | ALL_OBJFILES (objfile) |
1729 | { | |
1730 | struct breakpoint *b; | |
1731 | struct minimal_symbol *m; | |
1732 | ||
1733 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1734 | if (m == NULL) | |
1735 | continue; | |
e62c965a | 1736 | |
a6d9a66e UW |
1737 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1738 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1739 | bp_overlay_event); |
1740 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1741 | |
69de3c6a PP |
1742 | if (overlay_debugging == ovly_auto) |
1743 | { | |
1744 | b->enable_state = bp_enabled; | |
1745 | overlay_events_enabled = 1; | |
1746 | } | |
1747 | else | |
1748 | { | |
1749 | b->enable_state = bp_disabled; | |
1750 | overlay_events_enabled = 0; | |
1751 | } | |
e62c965a PP |
1752 | } |
1753 | update_global_location_list (1); | |
1754 | } | |
1755 | ||
0fd8e87f UW |
1756 | static void |
1757 | create_longjmp_master_breakpoint (char *func_name) | |
1758 | { | |
6c95b8df | 1759 | struct program_space *pspace; |
0fd8e87f | 1760 | struct objfile *objfile; |
6c95b8df PA |
1761 | struct cleanup *old_chain; |
1762 | ||
1763 | old_chain = save_current_program_space (); | |
0fd8e87f | 1764 | |
6c95b8df | 1765 | ALL_PSPACES (pspace) |
0fd8e87f UW |
1766 | ALL_OBJFILES (objfile) |
1767 | { | |
1768 | struct breakpoint *b; | |
1769 | struct minimal_symbol *m; | |
1770 | ||
1771 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1772 | continue; | |
1773 | ||
6c95b8df PA |
1774 | set_current_program_space (pspace); |
1775 | ||
0fd8e87f UW |
1776 | m = lookup_minimal_symbol_text (func_name, objfile); |
1777 | if (m == NULL) | |
1778 | continue; | |
1779 | ||
a6d9a66e UW |
1780 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1781 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1782 | bp_longjmp_master); |
1783 | b->addr_string = xstrdup (func_name); | |
1784 | b->enable_state = bp_disabled; | |
1785 | } | |
1786 | update_global_location_list (1); | |
6c95b8df PA |
1787 | |
1788 | do_cleanups (old_chain); | |
0fd8e87f UW |
1789 | } |
1790 | ||
c906108c | 1791 | void |
fba45db2 | 1792 | update_breakpoints_after_exec (void) |
c906108c | 1793 | { |
c5aa993b JM |
1794 | struct breakpoint *b; |
1795 | struct breakpoint *temp; | |
876fa593 | 1796 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 1797 | |
25b22b0a PA |
1798 | /* We're about to delete breakpoints from GDB's lists. If the |
1799 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1800 | writing the breakpoints' "shadow contents" back into memory. The | |
1801 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1802 | do that. Instead, the target is responsible from marking | |
1803 | breakpoints out as soon as it detects an exec. We don't do that | |
1804 | here instead, because there may be other attempts to delete | |
1805 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 1806 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
1807 | if (bploc->pspace == current_program_space) |
1808 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1809 | |
1810 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 1811 | { |
6c95b8df PA |
1812 | if (b->pspace != current_program_space) |
1813 | continue; | |
1814 | ||
c5aa993b JM |
1815 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
1816 | if (b->type == bp_shlib_event) | |
1817 | { | |
1818 | delete_breakpoint (b); | |
1819 | continue; | |
1820 | } | |
c906108c | 1821 | |
4efc6507 DE |
1822 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
1823 | if (b->type == bp_jit_event) | |
1824 | { | |
1825 | delete_breakpoint (b); | |
1826 | continue; | |
1827 | } | |
1828 | ||
1900040c | 1829 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1830 | as must overlay event and longjmp master breakpoints. */ |
1831 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1832 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1833 | { |
1834 | delete_breakpoint (b); | |
1835 | continue; | |
1836 | } | |
1837 | ||
c5aa993b JM |
1838 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1839 | if (b->type == bp_step_resume) | |
1840 | { | |
1841 | delete_breakpoint (b); | |
1842 | continue; | |
1843 | } | |
1844 | ||
611c83ae PA |
1845 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1846 | after an exec. */ | |
1847 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1848 | { | |
1849 | delete_breakpoint (b); | |
1850 | continue; | |
1851 | } | |
1852 | ||
ce78b96d JB |
1853 | if (b->type == bp_catchpoint) |
1854 | { | |
1855 | /* For now, none of the bp_catchpoint breakpoints need to | |
1856 | do anything at this point. In the future, if some of | |
1857 | the catchpoints need to something, we will need to add | |
1858 | a new method, and call this method from here. */ | |
1859 | continue; | |
1860 | } | |
1861 | ||
c5aa993b JM |
1862 | /* bp_finish is a special case. The only way we ought to be able |
1863 | to see one of these when an exec() has happened, is if the user | |
1864 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1865 | carries them to the call-site of the current callee, by setting | |
1866 | a temporary bp there and resuming. But in this case, the finish | |
1867 | will carry them entirely through the vfork & exec. | |
1868 | ||
1869 | We don't want to allow a bp_finish to remain inserted now. But | |
1870 | we can't safely delete it, 'cause finish_command has a handle to | |
1871 | the bp on a bpstat, and will later want to delete it. There's a | |
1872 | chance (and I've seen it happen) that if we delete the bp_finish | |
1873 | here, that its storage will get reused by the time finish_command | |
1874 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1875 | We really must allow finish_command to delete a bp_finish. | |
1876 | ||
53a5351d JM |
1877 | In the absense of a general solution for the "how do we know |
1878 | it's safe to delete something others may have handles to?" | |
1879 | problem, what we'll do here is just uninsert the bp_finish, and | |
1880 | let finish_command delete it. | |
1881 | ||
1882 | (We know the bp_finish is "doomed" in the sense that it's | |
1883 | momentary, and will be deleted as soon as finish_command sees | |
1884 | the inferior stopped. So it doesn't matter that the bp's | |
1885 | address is probably bogus in the new a.out, unlike e.g., the | |
1886 | solib breakpoints.) */ | |
c5aa993b | 1887 | |
c5aa993b JM |
1888 | if (b->type == bp_finish) |
1889 | { | |
1890 | continue; | |
1891 | } | |
1892 | ||
1893 | /* Without a symbolic address, we have little hope of the | |
1894 | pre-exec() address meaning the same thing in the post-exec() | |
1895 | a.out. */ | |
1896 | if (b->addr_string == NULL) | |
1897 | { | |
1898 | delete_breakpoint (b); | |
1899 | continue; | |
1900 | } | |
c5aa993b | 1901 | } |
1900040c | 1902 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1903 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1904 | create_longjmp_master_breakpoint ("longjmp"); |
1905 | create_longjmp_master_breakpoint ("_longjmp"); | |
1906 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1907 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1908 | } |
1909 | ||
1910 | int | |
fba45db2 | 1911 | detach_breakpoints (int pid) |
c906108c | 1912 | { |
876fa593 | 1913 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1914 | int val = 0; |
ce696e05 | 1915 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 1916 | struct inferior *inf = current_inferior (); |
c5aa993b | 1917 | |
39f77062 | 1918 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1919 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1920 | |
6c95b8df | 1921 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 1922 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 1923 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1924 | { |
6c95b8df PA |
1925 | if (b->pspace != inf->pspace) |
1926 | continue; | |
1927 | ||
0bde7532 | 1928 | if (b->inserted) |
6c95b8df | 1929 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 1930 | } |
ce696e05 | 1931 | do_cleanups (old_chain); |
3a1bae8e | 1932 | return val; |
c906108c SS |
1933 | } |
1934 | ||
6c95b8df PA |
1935 | /* Remove the breakpoint location B from the current address space. |
1936 | Note that this is used to detach breakpoints from a child fork. | |
1937 | When we get here, the child isn't in the inferior list, and neither | |
1938 | do we have objects to represent its address space --- we should | |
1939 | *not* look at b->pspace->aspace here. */ | |
1940 | ||
c906108c | 1941 | static int |
6c95b8df | 1942 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
1943 | { |
1944 | int val; | |
6c95b8df | 1945 | struct cleanup *old_chain; |
c5aa993b | 1946 | |
0bde7532 | 1947 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
1948 | /* Permanent breakpoints cannot be inserted or removed. */ |
1949 | return 0; | |
1950 | ||
74960c60 VP |
1951 | /* The type of none suggests that owner is actually deleted. |
1952 | This should not ever happen. */ | |
1953 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
1954 | |
1955 | if (b->loc_type == bp_loc_software_breakpoint | |
1956 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 1957 | { |
c02f5703 MS |
1958 | /* "Normal" instruction breakpoint: either the standard |
1959 | trap-instruction bp (bp_breakpoint), or a | |
1960 | bp_hardware_breakpoint. */ | |
1961 | ||
1962 | /* First check to see if we have to handle an overlay. */ | |
1963 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
1964 | || b->section == NULL |
1965 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
1966 | { |
1967 | /* No overlay handling: just remove the breakpoint. */ | |
1968 | ||
0bde7532 | 1969 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 1970 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1971 | else |
a6d9a66e | 1972 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 1973 | } |
c906108c SS |
1974 | else |
1975 | { | |
c02f5703 MS |
1976 | /* This breakpoint is in an overlay section. |
1977 | Did we set a breakpoint at the LMA? */ | |
1978 | if (!overlay_events_enabled) | |
1979 | { | |
1980 | /* Yes -- overlay event support is not active, so we | |
1981 | should have set a breakpoint at the LMA. Remove it. | |
1982 | */ | |
c02f5703 MS |
1983 | /* Ignore any failures: if the LMA is in ROM, we will |
1984 | have already warned when we failed to insert it. */ | |
0bde7532 | 1985 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
1986 | target_remove_hw_breakpoint (b->gdbarch, |
1987 | &b->overlay_target_info); | |
c02f5703 | 1988 | else |
a6d9a66e UW |
1989 | target_remove_breakpoint (b->gdbarch, |
1990 | &b->overlay_target_info); | |
c02f5703 MS |
1991 | } |
1992 | /* Did we set a breakpoint at the VMA? | |
1993 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 1994 | if (b->inserted) |
c906108c | 1995 | { |
c02f5703 MS |
1996 | /* Yes -- remove it. Previously we did not bother to |
1997 | remove the breakpoint if the section had been | |
1998 | unmapped, but let's not rely on that being safe. We | |
1999 | don't know what the overlay manager might do. */ | |
0bde7532 | 2000 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2001 | val = target_remove_hw_breakpoint (b->gdbarch, |
2002 | &b->target_info); | |
aa67235e UW |
2003 | |
2004 | /* However, we should remove *software* breakpoints only | |
2005 | if the section is still mapped, or else we overwrite | |
2006 | wrong code with the saved shadow contents. */ | |
2007 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2008 | val = target_remove_breakpoint (b->gdbarch, |
2009 | &b->target_info); | |
aa67235e UW |
2010 | else |
2011 | val = 0; | |
c906108c | 2012 | } |
c02f5703 MS |
2013 | else |
2014 | { | |
2015 | /* No -- not inserted, so no need to remove. No error. */ | |
2016 | val = 0; | |
2017 | } | |
c906108c | 2018 | } |
879d1e6b UW |
2019 | |
2020 | /* In some cases, we might not be able to remove a breakpoint | |
2021 | in a shared library that has already been removed, but we | |
2022 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2023 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2024 | val = 0; |
2025 | ||
c906108c SS |
2026 | if (val) |
2027 | return val; | |
0bde7532 | 2028 | b->inserted = (is == mark_inserted); |
c906108c | 2029 | } |
a5606eee | 2030 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2031 | { |
278cd55f AC |
2032 | struct value *v; |
2033 | struct value *n; | |
c5aa993b | 2034 | |
0bde7532 | 2035 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2036 | val = target_remove_watchpoint (b->address, b->length, |
2037 | b->watchpoint_type); | |
2e70b7b9 | 2038 | |
c906108c | 2039 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2040 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2041 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2042 | b->owner->number); |
c906108c | 2043 | } |
ce78b96d JB |
2044 | else if (b->owner->type == bp_catchpoint |
2045 | && breakpoint_enabled (b->owner) | |
2046 | && !b->duplicate) | |
2047 | { | |
2048 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2049 | ||
2050 | val = b->owner->ops->remove (b->owner); | |
2051 | if (val) | |
2052 | return val; | |
2053 | b->inserted = (is == mark_inserted); | |
2054 | } | |
c906108c SS |
2055 | |
2056 | return 0; | |
2057 | } | |
2058 | ||
6c95b8df PA |
2059 | static int |
2060 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2061 | { | |
2062 | int ret; | |
2063 | struct cleanup *old_chain; | |
2064 | ||
2065 | if (b->owner->enable_state == bp_permanent) | |
2066 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2067 | return 0; | |
2068 | ||
2069 | /* The type of none suggests that owner is actually deleted. | |
2070 | This should not ever happen. */ | |
2071 | gdb_assert (b->owner->type != bp_none); | |
2072 | ||
2073 | old_chain = save_current_space_and_thread (); | |
2074 | ||
2075 | switch_to_program_space_and_thread (b->pspace); | |
2076 | ||
2077 | ret = remove_breakpoint_1 (b, is); | |
2078 | ||
2079 | do_cleanups (old_chain); | |
2080 | return ret; | |
2081 | } | |
2082 | ||
c906108c SS |
2083 | /* Clear the "inserted" flag in all breakpoints. */ |
2084 | ||
25b22b0a | 2085 | void |
fba45db2 | 2086 | mark_breakpoints_out (void) |
c906108c | 2087 | { |
876fa593 | 2088 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2089 | |
876fa593 | 2090 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2091 | if (bpt->pspace == current_program_space) |
2092 | bpt->inserted = 0; | |
c906108c SS |
2093 | } |
2094 | ||
53a5351d JM |
2095 | /* Clear the "inserted" flag in all breakpoints and delete any |
2096 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2097 | |
2098 | Plus other such housekeeping that has to be done for breakpoints | |
2099 | between runs. | |
2100 | ||
53a5351d JM |
2101 | Note: this function gets called at the end of a run (by |
2102 | generic_mourn_inferior) and when a run begins (by | |
2103 | init_wait_for_inferior). */ | |
c906108c SS |
2104 | |
2105 | ||
2106 | ||
2107 | void | |
fba45db2 | 2108 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2109 | { |
52f0bd74 | 2110 | struct breakpoint *b, *temp; |
876fa593 | 2111 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2112 | int ix; |
6c95b8df | 2113 | struct program_space *pspace = current_program_space; |
c906108c | 2114 | |
50c71eaf PA |
2115 | /* If breakpoint locations are shared across processes, then there's |
2116 | nothing to do. */ | |
2567c7d9 | 2117 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2118 | return; |
2119 | ||
876fa593 | 2120 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2121 | { |
2122 | if (bpt->pspace == pspace | |
2123 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2124 | bpt->inserted = 0; |
6c95b8df | 2125 | } |
075f6582 | 2126 | |
c906108c | 2127 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2128 | { |
6c95b8df PA |
2129 | if (b->loc && b->loc->pspace != pspace) |
2130 | continue; | |
2131 | ||
c5aa993b JM |
2132 | switch (b->type) |
2133 | { | |
2134 | case bp_call_dummy: | |
2135 | case bp_watchpoint_scope: | |
c906108c | 2136 | |
c5aa993b JM |
2137 | /* If the call dummy breakpoint is at the entry point it will |
2138 | cause problems when the inferior is rerun, so we better | |
2139 | get rid of it. | |
c906108c | 2140 | |
c5aa993b JM |
2141 | Also get rid of scope breakpoints. */ |
2142 | delete_breakpoint (b); | |
2143 | break; | |
c906108c | 2144 | |
c5aa993b JM |
2145 | case bp_watchpoint: |
2146 | case bp_hardware_watchpoint: | |
2147 | case bp_read_watchpoint: | |
2148 | case bp_access_watchpoint: | |
c906108c | 2149 | |
c5aa993b JM |
2150 | /* Likewise for watchpoints on local expressions. */ |
2151 | if (b->exp_valid_block != NULL) | |
2152 | delete_breakpoint (b); | |
967af18d | 2153 | else if (context == inf_starting) |
c860120c PM |
2154 | { |
2155 | /* Reset val field to force reread of starting value | |
2156 | in insert_breakpoints. */ | |
2157 | if (b->val) | |
2158 | value_free (b->val); | |
2159 | b->val = NULL; | |
fa4727a6 | 2160 | b->val_valid = 0; |
c860120c | 2161 | } |
c5aa993b JM |
2162 | break; |
2163 | default: | |
c5aa993b JM |
2164 | break; |
2165 | } | |
2166 | } | |
1c5cfe86 PA |
2167 | |
2168 | /* Get rid of the moribund locations. */ | |
2169 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2170 | free_bp_location (bpt); | |
2171 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2172 | } |
2173 | ||
6c95b8df PA |
2174 | /* These functions concern about actual breakpoints inserted in the |
2175 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2176 | we need to hop over the bkpt --- so we check for address space | |
2177 | match, not program space. */ | |
2178 | ||
c2c6d25f JM |
2179 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2180 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2181 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2182 | permanent breakpoint. | |
2183 | - When continuing from a location with an ordinary breakpoint, we | |
2184 | actually single step once before calling insert_breakpoints. | |
2185 | - When continuing from a localion with a permanent breakpoint, we | |
2186 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2187 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2188 | |
c2c6d25f | 2189 | enum breakpoint_here |
6c95b8df | 2190 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2191 | { |
876fa593 | 2192 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2193 | int any_breakpoint_here = 0; |
c906108c | 2194 | |
876fa593 | 2195 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2196 | { |
2197 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2198 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2199 | continue; | |
2200 | ||
468d015d | 2201 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2202 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2203 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2204 | aspace, pc)) | |
075f6582 DJ |
2205 | { |
2206 | if (overlay_debugging | |
2207 | && section_is_overlay (bpt->section) | |
2208 | && !section_is_mapped (bpt->section)) | |
2209 | continue; /* unmapped overlay -- can't be a match */ | |
2210 | else if (bpt->owner->enable_state == bp_permanent) | |
2211 | return permanent_breakpoint_here; | |
2212 | else | |
2213 | any_breakpoint_here = 1; | |
2214 | } | |
2215 | } | |
c906108c | 2216 | |
c2c6d25f | 2217 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2218 | } |
2219 | ||
1c5cfe86 PA |
2220 | /* Return true if there's a moribund breakpoint at PC. */ |
2221 | ||
2222 | int | |
6c95b8df | 2223 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2224 | { |
2225 | struct bp_location *loc; | |
2226 | int ix; | |
2227 | ||
2228 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2229 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2230 | aspace, pc)) | |
1c5cfe86 PA |
2231 | return 1; |
2232 | ||
2233 | return 0; | |
2234 | } | |
c2c6d25f | 2235 | |
c36b740a | 2236 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2237 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2238 | This does not check for single-step breakpoints, which are |
2239 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2240 | |
2241 | int | |
6c95b8df | 2242 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2243 | { |
876fa593 | 2244 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2245 | |
876fa593 | 2246 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2247 | { |
075f6582 DJ |
2248 | if (bpt->loc_type != bp_loc_software_breakpoint |
2249 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2250 | continue; | |
2251 | ||
2252 | if (bpt->inserted | |
6c95b8df PA |
2253 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2254 | aspace, pc)) | |
075f6582 DJ |
2255 | { |
2256 | if (overlay_debugging | |
2257 | && section_is_overlay (bpt->section) | |
2258 | && !section_is_mapped (bpt->section)) | |
2259 | continue; /* unmapped overlay -- can't be a match */ | |
2260 | else | |
2261 | return 1; | |
2262 | } | |
c5aa993b | 2263 | } |
c36b740a VP |
2264 | return 0; |
2265 | } | |
2266 | ||
2267 | /* Returns non-zero iff there's either regular breakpoint | |
2268 | or a single step breakpoint inserted at PC. */ | |
2269 | ||
2270 | int | |
6c95b8df | 2271 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2272 | { |
6c95b8df | 2273 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2274 | return 1; |
c906108c | 2275 | |
6c95b8df | 2276 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2277 | return 1; |
2278 | ||
c906108c SS |
2279 | return 0; |
2280 | } | |
2281 | ||
4fa8626c DJ |
2282 | /* This function returns non-zero iff there is a software breakpoint |
2283 | inserted at PC. */ | |
2284 | ||
2285 | int | |
6c95b8df | 2286 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2287 | { |
876fa593 | 2288 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2289 | int any_breakpoint_here = 0; |
2290 | ||
876fa593 | 2291 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2292 | { |
2293 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2294 | continue; | |
2295 | ||
0d381245 | 2296 | if (bpt->inserted |
6c95b8df PA |
2297 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2298 | aspace, pc)) | |
4fa8626c DJ |
2299 | { |
2300 | if (overlay_debugging | |
2301 | && section_is_overlay (bpt->section) | |
2302 | && !section_is_mapped (bpt->section)) | |
2303 | continue; /* unmapped overlay -- can't be a match */ | |
2304 | else | |
2305 | return 1; | |
2306 | } | |
2307 | } | |
2308 | ||
1aafd4da | 2309 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2310 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2311 | return 1; |
2312 | ||
4fa8626c DJ |
2313 | return 0; |
2314 | } | |
2315 | ||
075f6582 DJ |
2316 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2317 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2318 | |
2319 | int | |
6c95b8df PA |
2320 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2321 | ptid_t ptid) | |
c906108c | 2322 | { |
876fa593 | 2323 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2324 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2325 | int thread = -1; |
4a306c9a | 2326 | int task = 0; |
a6f1cd96 | 2327 | |
876fa593 | 2328 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2329 | { |
075f6582 DJ |
2330 | if (bpt->loc_type != bp_loc_software_breakpoint |
2331 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2332 | continue; | |
2333 | ||
a6f1cd96 JB |
2334 | if (!breakpoint_enabled (bpt->owner) |
2335 | && bpt->owner->enable_state != bp_permanent) | |
2336 | continue; | |
2337 | ||
6c95b8df PA |
2338 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2339 | aspace, pc)) | |
a6f1cd96 JB |
2340 | continue; |
2341 | ||
2342 | if (bpt->owner->thread != -1) | |
075f6582 | 2343 | { |
a6f1cd96 JB |
2344 | /* This is a thread-specific breakpoint. Check that ptid |
2345 | matches that thread. If thread hasn't been computed yet, | |
2346 | it is now time to do so. */ | |
2347 | if (thread == -1) | |
2348 | thread = pid_to_thread_id (ptid); | |
2349 | if (bpt->owner->thread != thread) | |
2350 | continue; | |
075f6582 | 2351 | } |
a6f1cd96 | 2352 | |
4a306c9a JB |
2353 | if (bpt->owner->task != 0) |
2354 | { | |
2355 | /* This is a task-specific breakpoint. Check that ptid | |
2356 | matches that task. If task hasn't been computed yet, | |
2357 | it is now time to do so. */ | |
2358 | if (task == 0) | |
2359 | task = ada_get_task_number (ptid); | |
2360 | if (bpt->owner->task != task) | |
2361 | continue; | |
2362 | } | |
2363 | ||
a6f1cd96 JB |
2364 | if (overlay_debugging |
2365 | && section_is_overlay (bpt->section) | |
2366 | && !section_is_mapped (bpt->section)) | |
2367 | continue; /* unmapped overlay -- can't be a match */ | |
2368 | ||
2369 | return 1; | |
c5aa993b | 2370 | } |
c906108c SS |
2371 | |
2372 | return 0; | |
2373 | } | |
c906108c | 2374 | \f |
c5aa993b | 2375 | |
c906108c SS |
2376 | /* bpstat stuff. External routines' interfaces are documented |
2377 | in breakpoint.h. */ | |
2378 | ||
2379 | int | |
fba45db2 | 2380 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2381 | { |
533be4dd | 2382 | return (ep->type == bp_catchpoint); |
c906108c SS |
2383 | } |
2384 | ||
198757a8 VP |
2385 | void |
2386 | bpstat_free (bpstat bs) | |
2387 | { | |
2388 | if (bs->old_val != NULL) | |
2389 | value_free (bs->old_val); | |
2390 | free_command_lines (&bs->commands); | |
2391 | xfree (bs); | |
2392 | } | |
2393 | ||
c906108c SS |
2394 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2395 | Also free any storage that is part of a bpstat. */ | |
2396 | ||
2397 | void | |
fba45db2 | 2398 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2399 | { |
2400 | bpstat p; | |
2401 | bpstat q; | |
2402 | ||
2403 | if (bsp == 0) | |
2404 | return; | |
2405 | p = *bsp; | |
2406 | while (p != NULL) | |
2407 | { | |
2408 | q = p->next; | |
198757a8 | 2409 | bpstat_free (p); |
c906108c SS |
2410 | p = q; |
2411 | } | |
2412 | *bsp = NULL; | |
2413 | } | |
2414 | ||
2415 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2416 | is part of the bpstat is copied as well. */ | |
2417 | ||
2418 | bpstat | |
fba45db2 | 2419 | bpstat_copy (bpstat bs) |
c906108c SS |
2420 | { |
2421 | bpstat p = NULL; | |
2422 | bpstat tmp; | |
2423 | bpstat retval = NULL; | |
2424 | ||
2425 | if (bs == NULL) | |
2426 | return bs; | |
2427 | ||
2428 | for (; bs != NULL; bs = bs->next) | |
2429 | { | |
2430 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2431 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2432 | if (bs->commands != NULL) |
2433 | tmp->commands = copy_command_lines (bs->commands); | |
2434 | if (bs->old_val != NULL) | |
3c3185ac JK |
2435 | { |
2436 | tmp->old_val = value_copy (bs->old_val); | |
2437 | release_value (tmp->old_val); | |
2438 | } | |
31cc81e9 | 2439 | |
c906108c SS |
2440 | if (p == NULL) |
2441 | /* This is the first thing in the chain. */ | |
2442 | retval = tmp; | |
2443 | else | |
2444 | p->next = tmp; | |
2445 | p = tmp; | |
2446 | } | |
2447 | p->next = NULL; | |
2448 | return retval; | |
2449 | } | |
2450 | ||
2451 | /* Find the bpstat associated with this breakpoint */ | |
2452 | ||
2453 | bpstat | |
fba45db2 | 2454 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2455 | { |
c5aa993b JM |
2456 | if (bsp == NULL) |
2457 | return NULL; | |
c906108c | 2458 | |
c5aa993b JM |
2459 | for (; bsp != NULL; bsp = bsp->next) |
2460 | { | |
4f8d1dc6 | 2461 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2462 | return bsp; |
2463 | } | |
c906108c SS |
2464 | return NULL; |
2465 | } | |
2466 | ||
2467 | /* Find a step_resume breakpoint associated with this bpstat. | |
2468 | (If there are multiple step_resume bp's on the list, this function | |
2469 | will arbitrarily pick one.) | |
2470 | ||
2471 | It is an error to use this function if BPSTAT doesn't contain a | |
2472 | step_resume breakpoint. | |
2473 | ||
2474 | See wait_for_inferior's use of this function. */ | |
2475 | struct breakpoint * | |
fba45db2 | 2476 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2477 | { |
8601f500 MS |
2478 | int current_thread; |
2479 | ||
8a3fe4f8 | 2480 | gdb_assert (bsp != NULL); |
c906108c | 2481 | |
8601f500 MS |
2482 | current_thread = pid_to_thread_id (inferior_ptid); |
2483 | ||
c906108c SS |
2484 | for (; bsp != NULL; bsp = bsp->next) |
2485 | { | |
059fb39f PM |
2486 | if ((bsp->breakpoint_at != NULL) |
2487 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2488 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2489 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2490 | return bsp->breakpoint_at->owner; |
c906108c SS |
2491 | } |
2492 | ||
8a3fe4f8 | 2493 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2494 | } |
2495 | ||
2496 | ||
8671a17b | 2497 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2498 | at. *BSP upon return is a bpstat which points to the remaining |
2499 | breakpoints stopped at (but which is not guaranteed to be good for | |
2500 | anything but further calls to bpstat_num). | |
8671a17b PA |
2501 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2502 | Return -1 if stopped at a breakpoint that has been deleted since | |
2503 | we set it. | |
2504 | Return 1 otherwise. */ | |
c906108c SS |
2505 | |
2506 | int | |
8671a17b | 2507 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2508 | { |
2509 | struct breakpoint *b; | |
2510 | ||
2511 | if ((*bsp) == NULL) | |
2512 | return 0; /* No more breakpoint values */ | |
8671a17b | 2513 | |
4f8d1dc6 VP |
2514 | /* We assume we'll never have several bpstats that |
2515 | correspond to a single breakpoint -- otherwise, | |
2516 | this function might return the same number more | |
2517 | than once and this will look ugly. */ | |
2518 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2519 | *bsp = (*bsp)->next; |
2520 | if (b == NULL) | |
2521 | return -1; /* breakpoint that's been deleted since */ | |
2522 | ||
2523 | *num = b->number; /* We have its number */ | |
2524 | return 1; | |
c906108c SS |
2525 | } |
2526 | ||
2527 | /* Modify BS so that the actions will not be performed. */ | |
2528 | ||
2529 | void | |
fba45db2 | 2530 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2531 | { |
2532 | for (; bs != NULL; bs = bs->next) | |
2533 | { | |
c2b8ed2c | 2534 | free_command_lines (&bs->commands); |
c906108c SS |
2535 | if (bs->old_val != NULL) |
2536 | { | |
2537 | value_free (bs->old_val); | |
2538 | bs->old_val = NULL; | |
2539 | } | |
2540 | } | |
2541 | } | |
2542 | ||
f3b1572e PA |
2543 | /* Called when a command is about to proceed the inferior. */ |
2544 | ||
2545 | static void | |
2546 | breakpoint_about_to_proceed (void) | |
2547 | { | |
2548 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2549 | { | |
2550 | struct thread_info *tp = inferior_thread (); | |
2551 | ||
2552 | /* Allow inferior function calls in breakpoint commands to not | |
2553 | interrupt the command list. When the call finishes | |
2554 | successfully, the inferior will be standing at the same | |
2555 | breakpoint as if nothing happened. */ | |
2556 | if (tp->in_infcall) | |
2557 | return; | |
2558 | } | |
2559 | ||
2560 | breakpoint_proceeded = 1; | |
2561 | } | |
2562 | ||
c906108c | 2563 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2564 | static void |
4efb68b1 | 2565 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2566 | { |
2567 | executing_breakpoint_commands = 0; | |
2568 | } | |
2569 | ||
2570 | /* Execute all the commands associated with all the breakpoints at this | |
2571 | location. Any of these commands could cause the process to proceed | |
2572 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2573 | the global "breakpoint_proceeded" after each command. |
c906108c | 2574 | |
347bddb7 PA |
2575 | Returns true if a breakpoint command resumed the inferior. In that |
2576 | case, it is the caller's responsibility to recall it again with the | |
2577 | bpstat of the current thread. */ | |
2578 | ||
2579 | static int | |
2580 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2581 | { |
2582 | bpstat bs; | |
2583 | struct cleanup *old_chain; | |
347bddb7 | 2584 | int again = 0; |
c906108c SS |
2585 | |
2586 | /* Avoid endless recursion if a `source' command is contained | |
2587 | in bs->commands. */ | |
2588 | if (executing_breakpoint_commands) | |
347bddb7 | 2589 | return 0; |
c906108c SS |
2590 | |
2591 | executing_breakpoint_commands = 1; | |
2592 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2593 | ||
c906108c SS |
2594 | /* This pointer will iterate over the list of bpstat's. */ |
2595 | bs = *bsp; | |
2596 | ||
2597 | breakpoint_proceeded = 0; | |
2598 | for (; bs != NULL; bs = bs->next) | |
2599 | { | |
6c50ab1c JB |
2600 | struct command_line *cmd; |
2601 | struct cleanup *this_cmd_tree_chain; | |
2602 | ||
2603 | /* Take ownership of the BSP's command tree, if it has one. | |
2604 | ||
2605 | The command tree could legitimately contain commands like | |
2606 | 'step' and 'next', which call clear_proceed_status, which | |
2607 | frees stop_bpstat's command tree. To make sure this doesn't | |
2608 | free the tree we're executing out from under us, we need to | |
2609 | take ownership of the tree ourselves. Since a given bpstat's | |
2610 | commands are only executed once, we don't need to copy it; we | |
2611 | can clear the pointer in the bpstat, and make sure we free | |
2612 | the tree when we're done. */ | |
c906108c | 2613 | cmd = bs->commands; |
6c50ab1c JB |
2614 | bs->commands = 0; |
2615 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2616 | ||
c906108c SS |
2617 | while (cmd != NULL) |
2618 | { | |
2619 | execute_control_command (cmd); | |
2620 | ||
2621 | if (breakpoint_proceeded) | |
2622 | break; | |
2623 | else | |
2624 | cmd = cmd->next; | |
2625 | } | |
6c50ab1c JB |
2626 | |
2627 | /* We can free this command tree now. */ | |
2628 | do_cleanups (this_cmd_tree_chain); | |
2629 | ||
c906108c | 2630 | if (breakpoint_proceeded) |
32c1e744 VP |
2631 | { |
2632 | if (target_can_async_p ()) | |
347bddb7 PA |
2633 | /* If we are in async mode, then the target might be still |
2634 | running, not stopped at any breakpoint, so nothing for | |
2635 | us to do here -- just return to the event loop. */ | |
2636 | ; | |
32c1e744 VP |
2637 | else |
2638 | /* In sync mode, when execute_control_command returns | |
2639 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2640 | Breakpoint commands for that stop were not run, since |
2641 | execute_command does not run breakpoint commands -- | |
2642 | only command_line_handler does, but that one is not | |
2643 | involved in execution of breakpoint commands. So, we | |
2644 | can now execute breakpoint commands. It should be | |
2645 | noted that making execute_command do bpstat actions is | |
2646 | not an option -- in this case we'll have recursive | |
2647 | invocation of bpstat for each breakpoint with a | |
2648 | command, and can easily blow up GDB stack. Instead, we | |
2649 | return true, which will trigger the caller to recall us | |
2650 | with the new stop_bpstat. */ | |
2651 | again = 1; | |
2652 | break; | |
32c1e744 | 2653 | } |
c906108c | 2654 | } |
c2b8ed2c | 2655 | do_cleanups (old_chain); |
347bddb7 PA |
2656 | return again; |
2657 | } | |
2658 | ||
2659 | void | |
2660 | bpstat_do_actions (void) | |
2661 | { | |
2662 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2663 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2664 | && target_has_execution | |
2665 | && !is_exited (inferior_ptid) | |
2666 | && !is_executing (inferior_ptid)) | |
2667 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2668 | and only return when it is stopped at the next breakpoint, we | |
2669 | keep doing breakpoint actions until it returns false to | |
2670 | indicate the inferior was not resumed. */ | |
2671 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2672 | break; | |
c906108c SS |
2673 | } |
2674 | ||
fa4727a6 DJ |
2675 | /* Print out the (old or new) value associated with a watchpoint. */ |
2676 | ||
2677 | static void | |
2678 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2679 | { | |
2680 | if (val == NULL) | |
2681 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2682 | else | |
79a45b7d TT |
2683 | { |
2684 | struct value_print_options opts; | |
2685 | get_user_print_options (&opts); | |
2686 | value_print (val, stream, &opts); | |
2687 | } | |
fa4727a6 DJ |
2688 | } |
2689 | ||
e514a9d6 | 2690 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2691 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2692 | by having it set different print_it values. |
2693 | ||
2694 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2695 | through the bpstat list of things causing this stop, calling the | |
2696 | print_bp_stop_message function on each one. The behavior of the | |
2697 | print_bp_stop_message function depends on the print_it field of | |
2698 | bpstat. If such field so indicates, call this function here. | |
2699 | ||
2700 | Return values from this routine (ultimately used by bpstat_print() | |
2701 | and normal_stop() to decide what to do): | |
2702 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2703 | don't print anything else. | |
2704 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2705 | that something to be followed by a location. | |
2706 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2707 | that something to be followed by a location. | |
2708 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2709 | analysis. */ | |
c906108c | 2710 | |
917317f4 | 2711 | static enum print_stop_action |
fba45db2 | 2712 | print_it_typical (bpstat bs) |
c906108c | 2713 | { |
f7545552 | 2714 | struct cleanup *old_chain; |
4f8d1dc6 | 2715 | struct breakpoint *b; |
89f9893c | 2716 | const struct bp_location *bl; |
8b93c638 | 2717 | struct ui_stream *stb; |
f7545552 TT |
2718 | int bp_temp = 0; |
2719 | enum print_stop_action result; | |
2720 | ||
c906108c SS |
2721 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2722 | which has since been deleted. */ | |
e514a9d6 | 2723 | if (bs->breakpoint_at == NULL) |
917317f4 | 2724 | return PRINT_UNKNOWN; |
0d381245 VP |
2725 | bl = bs->breakpoint_at; |
2726 | b = bl->owner; | |
c906108c | 2727 | |
f7545552 TT |
2728 | stb = ui_out_stream_new (uiout); |
2729 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2730 | ||
4f8d1dc6 | 2731 | switch (b->type) |
c906108c | 2732 | { |
e514a9d6 JM |
2733 | case bp_breakpoint: |
2734 | case bp_hardware_breakpoint: | |
2cec12e5 | 2735 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2736 | if (bl->address != bl->requested_address) |
2737 | breakpoint_adjustment_warning (bl->requested_address, | |
2738 | bl->address, | |
4f8d1dc6 VP |
2739 | b->number, 1); |
2740 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2741 | if (bp_temp) |
2742 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2743 | else | |
2744 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2745 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2746 | { |
2747 | ui_out_field_string (uiout, "reason", | |
2748 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2749 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2750 | } | |
4f8d1dc6 | 2751 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2752 | ui_out_text (uiout, ", "); |
f7545552 | 2753 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2754 | break; |
2755 | ||
2756 | case bp_shlib_event: | |
917317f4 JM |
2757 | /* Did we stop because the user set the stop_on_solib_events |
2758 | variable? (If so, we report this as a generic, "Stopped due | |
2759 | to shlib event" message.) */ | |
a3f17187 | 2760 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2761 | result = PRINT_NOTHING; |
e514a9d6 JM |
2762 | break; |
2763 | ||
c4093a6a JM |
2764 | case bp_thread_event: |
2765 | /* Not sure how we will get here. | |
2766 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2767 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2768 | result = PRINT_NOTHING; |
c4093a6a JM |
2769 | break; |
2770 | ||
1900040c MS |
2771 | case bp_overlay_event: |
2772 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2773 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2774 | result = PRINT_NOTHING; |
1900040c MS |
2775 | break; |
2776 | ||
0fd8e87f UW |
2777 | case bp_longjmp_master: |
2778 | /* These should never be enabled. */ | |
2779 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2780 | result = PRINT_NOTHING; | |
2781 | break; | |
2782 | ||
e514a9d6 JM |
2783 | case bp_watchpoint: |
2784 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2785 | annotate_watchpoint (b->number); |
2786 | if (ui_out_is_mi_like_p (uiout)) | |
2787 | ui_out_field_string | |
2788 | (uiout, "reason", | |
2789 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2790 | mention (b); | |
f7545552 | 2791 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2792 | ui_out_text (uiout, "\nOld value = "); |
2793 | watchpoint_value_print (bs->old_val, stb->stream); | |
2794 | ui_out_field_stream (uiout, "old", stb); | |
2795 | ui_out_text (uiout, "\nNew value = "); | |
2796 | watchpoint_value_print (b->val, stb->stream); | |
2797 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2798 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2799 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2800 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2801 | break; |
2802 | ||
2803 | case bp_read_watchpoint: | |
9dc5e2a9 | 2804 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2805 | ui_out_field_string |
2806 | (uiout, "reason", | |
2807 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2808 | mention (b); |
f7545552 | 2809 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2810 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2811 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2812 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2813 | ui_out_text (uiout, "\n"); |
f7545552 | 2814 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2815 | break; |
2816 | ||
2817 | case bp_access_watchpoint: | |
fa4727a6 | 2818 | if (bs->old_val != NULL) |
8b93c638 | 2819 | { |
4f8d1dc6 | 2820 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2821 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2822 | ui_out_field_string |
2823 | (uiout, "reason", | |
2824 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2825 | mention (b); |
f7545552 | 2826 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2827 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2828 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2829 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2830 | ui_out_text (uiout, "\nNew value = "); |
2831 | } | |
2832 | else | |
2833 | { | |
4f8d1dc6 | 2834 | mention (b); |
9dc5e2a9 | 2835 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2836 | ui_out_field_string |
2837 | (uiout, "reason", | |
2838 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2839 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2840 | ui_out_text (uiout, "\nValue = "); |
2841 | } | |
fa4727a6 | 2842 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2843 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2844 | ui_out_text (uiout, "\n"); |
f7545552 | 2845 | result = PRINT_UNKNOWN; |
e514a9d6 | 2846 | break; |
4ce44c66 | 2847 | |
e514a9d6 JM |
2848 | /* Fall through, we don't deal with these types of breakpoints |
2849 | here. */ | |
2850 | ||
11cf8741 | 2851 | case bp_finish: |
9dc5e2a9 | 2852 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2853 | ui_out_field_string |
2854 | (uiout, "reason", | |
2855 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2856 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2857 | break; |
2858 | ||
e514a9d6 | 2859 | case bp_until: |
9dc5e2a9 | 2860 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2861 | ui_out_field_string |
2862 | (uiout, "reason", | |
2863 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2864 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2865 | break; |
2866 | ||
c2d11a7d | 2867 | case bp_none: |
e514a9d6 JM |
2868 | case bp_longjmp: |
2869 | case bp_longjmp_resume: | |
2870 | case bp_step_resume: | |
e514a9d6 JM |
2871 | case bp_watchpoint_scope: |
2872 | case bp_call_dummy: | |
1042e4c0 | 2873 | case bp_tracepoint: |
4efc6507 | 2874 | case bp_jit_event: |
e514a9d6 | 2875 | default: |
f7545552 TT |
2876 | result = PRINT_UNKNOWN; |
2877 | break; | |
e514a9d6 | 2878 | } |
f7545552 TT |
2879 | |
2880 | do_cleanups (old_chain); | |
2881 | return result; | |
e514a9d6 JM |
2882 | } |
2883 | ||
2884 | /* Generic routine for printing messages indicating why we | |
2885 | stopped. The behavior of this function depends on the value | |
2886 | 'print_it' in the bpstat structure. Under some circumstances we | |
2887 | may decide not to print anything here and delegate the task to | |
2888 | normal_stop(). */ | |
2889 | ||
2890 | static enum print_stop_action | |
2891 | print_bp_stop_message (bpstat bs) | |
2892 | { | |
2893 | switch (bs->print_it) | |
2894 | { | |
2895 | case print_it_noop: | |
2896 | /* Nothing should be printed for this bpstat entry. */ | |
2897 | return PRINT_UNKNOWN; | |
2898 | break; | |
2899 | ||
2900 | case print_it_done: | |
2901 | /* We still want to print the frame, but we already printed the | |
2902 | relevant messages. */ | |
2903 | return PRINT_SRC_AND_LOC; | |
2904 | break; | |
2905 | ||
2906 | case print_it_normal: | |
4f8d1dc6 | 2907 | { |
89f9893c | 2908 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
2909 | struct breakpoint *b = bl ? bl->owner : NULL; |
2910 | ||
2911 | /* Normal case. Call the breakpoint's print_it method, or | |
2912 | print_it_typical. */ | |
2913 | /* FIXME: how breakpoint can ever be NULL here? */ | |
2914 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
2915 | return b->ops->print_it (b); | |
2916 | else | |
2917 | return print_it_typical (bs); | |
2918 | } | |
2919 | break; | |
3086aeae | 2920 | |
e514a9d6 | 2921 | default: |
8e65ff28 | 2922 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 2923 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 2924 | break; |
c906108c | 2925 | } |
c906108c SS |
2926 | } |
2927 | ||
e514a9d6 JM |
2928 | /* Print a message indicating what happened. This is called from |
2929 | normal_stop(). The input to this routine is the head of the bpstat | |
2930 | list - a list of the eventpoints that caused this stop. This | |
2931 | routine calls the generic print routine for printing a message | |
2932 | about reasons for stopping. This will print (for example) the | |
2933 | "Breakpoint n," part of the output. The return value of this | |
2934 | routine is one of: | |
c906108c | 2935 | |
917317f4 JM |
2936 | PRINT_UNKNOWN: Means we printed nothing |
2937 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
2938 | code to print the location. An example is |
2939 | "Breakpoint 1, " which should be followed by | |
2940 | the location. | |
917317f4 | 2941 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
2942 | to also print the location part of the message. |
2943 | An example is the catch/throw messages, which | |
917317f4 JM |
2944 | don't require a location appended to the end. |
2945 | PRINT_NOTHING: We have done some printing and we don't need any | |
2946 | further info to be printed.*/ | |
c906108c | 2947 | |
917317f4 | 2948 | enum print_stop_action |
fba45db2 | 2949 | bpstat_print (bpstat bs) |
c906108c SS |
2950 | { |
2951 | int val; | |
c5aa993b | 2952 | |
c906108c | 2953 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
2954 | (Currently all watchpoints go on the bpstat whether hit or not. |
2955 | That probably could (should) be changed, provided care is taken | |
c906108c | 2956 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
2957 | for (; bs; bs = bs->next) |
2958 | { | |
2959 | val = print_bp_stop_message (bs); | |
2960 | if (val == PRINT_SRC_ONLY | |
2961 | || val == PRINT_SRC_AND_LOC | |
2962 | || val == PRINT_NOTHING) | |
2963 | return val; | |
2964 | } | |
c906108c | 2965 | |
e514a9d6 JM |
2966 | /* We reached the end of the chain, or we got a null BS to start |
2967 | with and nothing was printed. */ | |
917317f4 | 2968 | return PRINT_UNKNOWN; |
c906108c SS |
2969 | } |
2970 | ||
2971 | /* Evaluate the expression EXP and return 1 if value is zero. | |
2972 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
2973 | The argument is a "struct expression *" that has been cast to char * to | |
2974 | make it pass through catch_errors. */ | |
2975 | ||
2976 | static int | |
4efb68b1 | 2977 | breakpoint_cond_eval (void *exp) |
c906108c | 2978 | { |
278cd55f | 2979 | struct value *mark = value_mark (); |
c5aa993b | 2980 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
2981 | value_free_to_mark (mark); |
2982 | return i; | |
2983 | } | |
2984 | ||
2985 | /* Allocate a new bpstat and chain it to the current one. */ | |
2986 | ||
2987 | static bpstat | |
89f9893c | 2988 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
2989 | { |
2990 | bpstat bs; | |
2991 | ||
2992 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
2993 | cbs->next = bs; | |
4f8d1dc6 | 2994 | bs->breakpoint_at = bl; |
c906108c SS |
2995 | /* If the condition is false, etc., don't do the commands. */ |
2996 | bs->commands = NULL; | |
2997 | bs->old_val = NULL; | |
2998 | bs->print_it = print_it_normal; | |
2999 | return bs; | |
3000 | } | |
3001 | \f | |
d983da9c DJ |
3002 | /* The target has stopped with waitstatus WS. Check if any hardware |
3003 | watchpoints have triggered, according to the target. */ | |
3004 | ||
3005 | int | |
3006 | watchpoints_triggered (struct target_waitstatus *ws) | |
3007 | { | |
d92524f1 | 3008 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3009 | CORE_ADDR addr; |
3010 | struct breakpoint *b; | |
3011 | ||
3012 | if (!stopped_by_watchpoint) | |
3013 | { | |
3014 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3015 | as not triggered. */ | |
3016 | ALL_BREAKPOINTS (b) | |
3017 | if (b->type == bp_hardware_watchpoint | |
3018 | || b->type == bp_read_watchpoint | |
3019 | || b->type == bp_access_watchpoint) | |
3020 | b->watchpoint_triggered = watch_triggered_no; | |
3021 | ||
3022 | return 0; | |
3023 | } | |
3024 | ||
3025 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3026 | { | |
3027 | /* We were stopped by a watchpoint, but we don't know where. | |
3028 | Mark all watchpoints as unknown. */ | |
3029 | ALL_BREAKPOINTS (b) | |
3030 | if (b->type == bp_hardware_watchpoint | |
3031 | || b->type == bp_read_watchpoint | |
3032 | || b->type == bp_access_watchpoint) | |
3033 | b->watchpoint_triggered = watch_triggered_unknown; | |
3034 | ||
3035 | return stopped_by_watchpoint; | |
3036 | } | |
3037 | ||
3038 | /* The target could report the data address. Mark watchpoints | |
3039 | affected by this data address as triggered, and all others as not | |
3040 | triggered. */ | |
3041 | ||
3042 | ALL_BREAKPOINTS (b) | |
3043 | if (b->type == bp_hardware_watchpoint | |
3044 | || b->type == bp_read_watchpoint | |
3045 | || b->type == bp_access_watchpoint) | |
3046 | { | |
a5606eee | 3047 | struct bp_location *loc; |
d983da9c DJ |
3048 | struct value *v; |
3049 | ||
3050 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3051 | for (loc = b->loc; loc; loc = loc->next) |
3052 | /* Exact match not required. Within range is | |
3053 | sufficient. */ | |
5009afc5 AS |
3054 | if (target_watchpoint_addr_within_range (¤t_target, |
3055 | addr, loc->address, | |
3056 | loc->length)) | |
a5606eee VP |
3057 | { |
3058 | b->watchpoint_triggered = watch_triggered_yes; | |
3059 | break; | |
3060 | } | |
d983da9c DJ |
3061 | } |
3062 | ||
3063 | return 1; | |
3064 | } | |
3065 | ||
c906108c SS |
3066 | /* Possible return values for watchpoint_check (this can't be an enum |
3067 | because of check_errors). */ | |
3068 | /* The watchpoint has been deleted. */ | |
3069 | #define WP_DELETED 1 | |
3070 | /* The value has changed. */ | |
3071 | #define WP_VALUE_CHANGED 2 | |
3072 | /* The value has not changed. */ | |
3073 | #define WP_VALUE_NOT_CHANGED 3 | |
3074 | ||
3075 | #define BP_TEMPFLAG 1 | |
3076 | #define BP_HARDWAREFLAG 2 | |
3077 | ||
3078 | /* Check watchpoint condition. */ | |
3079 | ||
3080 | static int | |
4efb68b1 | 3081 | watchpoint_check (void *p) |
c906108c SS |
3082 | { |
3083 | bpstat bs = (bpstat) p; | |
3084 | struct breakpoint *b; | |
3085 | struct frame_info *fr; | |
3086 | int within_current_scope; | |
3087 | ||
4f8d1dc6 | 3088 | b = bs->breakpoint_at->owner; |
c906108c SS |
3089 | |
3090 | if (b->exp_valid_block == NULL) | |
3091 | within_current_scope = 1; | |
3092 | else | |
3093 | { | |
edb3359d DJ |
3094 | struct frame_info *frame = get_current_frame (); |
3095 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3096 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3097 | ||
101dcfbe | 3098 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3099 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3100 | |
3101 | /* If we've gotten confused in the unwinder, we might have | |
3102 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3103 | if (within_current_scope) |
3104 | { | |
3105 | struct symbol *function; | |
3106 | ||
3107 | function = get_frame_function (fr); | |
3108 | if (function == NULL | |
3109 | || !contained_in (b->exp_valid_block, | |
3110 | SYMBOL_BLOCK_VALUE (function))) | |
3111 | within_current_scope = 0; | |
3112 | } | |
69fbadd5 | 3113 | |
c12260ac CV |
3114 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3115 | in the function but the stack frame has already been invalidated. | |
3116 | Since we can't rely on the values of local variables after the | |
3117 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
3118 | state as `not changed' without further checking. Don't mark |
3119 | watchpoints as changed if the current frame is in an epilogue - | |
3120 | even if they are in some other frame, our view of the stack | |
3121 | is likely to be wrong. */ | |
3122 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
3123 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 3124 | |
edb3359d | 3125 | if (within_current_scope) |
c906108c SS |
3126 | /* If we end up stopping, the current frame will get selected |
3127 | in normal_stop. So this call to select_frame won't affect | |
3128 | the user. */ | |
0f7d239c | 3129 | select_frame (fr); |
c906108c | 3130 | } |
c5aa993b | 3131 | |
c906108c SS |
3132 | if (within_current_scope) |
3133 | { | |
3134 | /* We use value_{,free_to_}mark because it could be a | |
3135 | *long* time before we return to the command level and | |
c5aa993b JM |
3136 | call free_all_values. We can't call free_all_values because |
3137 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3138 | |
278cd55f | 3139 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3140 | struct value *new_val; |
3141 | ||
3142 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
3143 | if ((b->val != NULL) != (new_val != NULL) | |
3144 | || (b->val != NULL && !value_equal (b->val, new_val))) | |
c906108c | 3145 | { |
fa4727a6 DJ |
3146 | if (new_val != NULL) |
3147 | { | |
3148 | release_value (new_val); | |
3149 | value_free_to_mark (mark); | |
3150 | } | |
c906108c SS |
3151 | bs->old_val = b->val; |
3152 | b->val = new_val; | |
fa4727a6 | 3153 | b->val_valid = 1; |
c906108c SS |
3154 | /* We will stop here */ |
3155 | return WP_VALUE_CHANGED; | |
3156 | } | |
3157 | else | |
3158 | { | |
3159 | /* Nothing changed, don't do anything. */ | |
3160 | value_free_to_mark (mark); | |
3161 | /* We won't stop here */ | |
3162 | return WP_VALUE_NOT_CHANGED; | |
3163 | } | |
3164 | } | |
3165 | else | |
3166 | { | |
3167 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3168 | if we temporarily ignored the watchpoint, then when |
3169 | we reenter the block in which it is valid it contains | |
3170 | garbage (in the case of a function, it may have two | |
3171 | garbage values, one before and one after the prologue). | |
3172 | So we can't even detect the first assignment to it and | |
3173 | watch after that (since the garbage may or may not equal | |
3174 | the first value assigned). */ | |
4ce44c66 JM |
3175 | /* We print all the stop information in print_it_typical(), but |
3176 | in this case, by the time we call print_it_typical() this bp | |
3177 | will be deleted already. So we have no choice but print the | |
3178 | information here. */ | |
9dc5e2a9 | 3179 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3180 | ui_out_field_string |
3181 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3182 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3183 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3184 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3185 | which its expression is valid.\n"); | |
4ce44c66 | 3186 | |
c906108c | 3187 | if (b->related_breakpoint) |
b5de0fa7 EZ |
3188 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
3189 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
3190 | |
3191 | return WP_DELETED; | |
3192 | } | |
3193 | } | |
3194 | ||
18a18393 VP |
3195 | /* Return true if it looks like target has stopped due to hitting |
3196 | breakpoint location BL. This function does not check if we | |
3197 | should stop, only if BL explains the stop. */ | |
3198 | static int | |
6c95b8df PA |
3199 | bpstat_check_location (const struct bp_location *bl, |
3200 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3201 | { |
3202 | struct breakpoint *b = bl->owner; | |
3203 | ||
3204 | if (b->type != bp_watchpoint | |
3205 | && b->type != bp_hardware_watchpoint | |
3206 | && b->type != bp_read_watchpoint | |
3207 | && b->type != bp_access_watchpoint | |
3208 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3209 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3210 | { |
6c95b8df PA |
3211 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3212 | aspace, bp_addr)) | |
18a18393 VP |
3213 | return 0; |
3214 | if (overlay_debugging /* unmapped overlay section */ | |
3215 | && section_is_overlay (bl->section) | |
3216 | && !section_is_mapped (bl->section)) | |
3217 | return 0; | |
3218 | } | |
3219 | ||
3220 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3221 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3222 | some data address). Otherwise gdb won't stop on a break instruction | |
3223 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3224 | been defined. Also skip watchpoints which we know did not trigger | |
3225 | (did not match the data address). */ | |
3226 | ||
3227 | if ((b->type == bp_hardware_watchpoint | |
3228 | || b->type == bp_read_watchpoint | |
3229 | || b->type == bp_access_watchpoint) | |
3230 | && b->watchpoint_triggered == watch_triggered_no) | |
3231 | return 0; | |
3232 | ||
3233 | if (b->type == bp_hardware_breakpoint) | |
3234 | { | |
3235 | if (bl->address != bp_addr) | |
3236 | return 0; | |
3237 | if (overlay_debugging /* unmapped overlay section */ | |
3238 | && section_is_overlay (bl->section) | |
3239 | && !section_is_mapped (bl->section)) | |
3240 | return 0; | |
3241 | } | |
ce78b96d | 3242 | |
ce78b96d JB |
3243 | if (b->type == bp_catchpoint) |
3244 | { | |
3245 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3246 | if (!b->ops->breakpoint_hit (b)) | |
3247 | return 0; | |
3248 | } | |
3249 | ||
18a18393 VP |
3250 | return 1; |
3251 | } | |
3252 | ||
3253 | /* If BS refers to a watchpoint, determine if the watched values | |
3254 | has actually changed, and we should stop. If not, set BS->stop | |
3255 | to 0. */ | |
3256 | static void | |
3257 | bpstat_check_watchpoint (bpstat bs) | |
3258 | { | |
3259 | const struct bp_location *bl = bs->breakpoint_at; | |
3260 | struct breakpoint *b = bl->owner; | |
3261 | ||
3262 | if (b->type == bp_watchpoint | |
3263 | || b->type == bp_read_watchpoint | |
3264 | || b->type == bp_access_watchpoint | |
3265 | || b->type == bp_hardware_watchpoint) | |
3266 | { | |
3267 | CORE_ADDR addr; | |
3268 | struct value *v; | |
3269 | int must_check_value = 0; | |
3270 | ||
3271 | if (b->type == bp_watchpoint) | |
3272 | /* For a software watchpoint, we must always check the | |
3273 | watched value. */ | |
3274 | must_check_value = 1; | |
3275 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3276 | /* We have a hardware watchpoint (read, write, or access) | |
3277 | and the target earlier reported an address watched by | |
3278 | this watchpoint. */ | |
3279 | must_check_value = 1; | |
3280 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3281 | && b->type == bp_hardware_watchpoint) | |
3282 | /* We were stopped by a hardware watchpoint, but the target could | |
3283 | not report the data address. We must check the watchpoint's | |
3284 | value. Access and read watchpoints are out of luck; without | |
3285 | a data address, we can't figure it out. */ | |
3286 | must_check_value = 1; | |
3287 | ||
3288 | if (must_check_value) | |
3289 | { | |
3290 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3291 | b->number); | |
3292 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3293 | int e = catch_errors (watchpoint_check, bs, message, | |
3294 | RETURN_MASK_ALL); | |
3295 | do_cleanups (cleanups); | |
3296 | switch (e) | |
3297 | { | |
3298 | case WP_DELETED: | |
3299 | /* We've already printed what needs to be printed. */ | |
3300 | bs->print_it = print_it_done; | |
3301 | /* Stop. */ | |
3302 | break; | |
3303 | case WP_VALUE_CHANGED: | |
3304 | if (b->type == bp_read_watchpoint) | |
3305 | { | |
3306 | /* Don't stop: read watchpoints shouldn't fire if | |
3307 | the value has changed. This is for targets | |
3308 | which cannot set read-only watchpoints. */ | |
3309 | bs->print_it = print_it_noop; | |
3310 | bs->stop = 0; | |
3311 | } | |
3312 | break; | |
3313 | case WP_VALUE_NOT_CHANGED: | |
3314 | if (b->type == bp_hardware_watchpoint | |
3315 | || b->type == bp_watchpoint) | |
3316 | { | |
3317 | /* Don't stop: write watchpoints shouldn't fire if | |
3318 | the value hasn't changed. */ | |
3319 | bs->print_it = print_it_noop; | |
3320 | bs->stop = 0; | |
3321 | } | |
3322 | /* Stop. */ | |
3323 | break; | |
3324 | default: | |
3325 | /* Can't happen. */ | |
3326 | case 0: | |
3327 | /* Error from catch_errors. */ | |
3328 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3329 | if (b->related_breakpoint) | |
3330 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3331 | b->disposition = disp_del_at_next_stop; | |
3332 | /* We've already printed what needs to be printed. */ | |
3333 | bs->print_it = print_it_done; | |
3334 | break; | |
3335 | } | |
3336 | } | |
3337 | else /* must_check_value == 0 */ | |
3338 | { | |
3339 | /* This is a case where some watchpoint(s) triggered, but | |
3340 | not at the address of this watchpoint, or else no | |
3341 | watchpoint triggered after all. So don't print | |
3342 | anything for this watchpoint. */ | |
3343 | bs->print_it = print_it_noop; | |
3344 | bs->stop = 0; | |
3345 | } | |
3346 | } | |
3347 | } | |
3348 | ||
3349 | ||
3350 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3351 | of breakpoint referred to by BS. If we should not stop for this | |
3352 | breakpoint, set BS->stop to 0. */ | |
3353 | static void | |
3354 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3355 | { | |
3356 | int thread_id = pid_to_thread_id (ptid); | |
3357 | const struct bp_location *bl = bs->breakpoint_at; | |
3358 | struct breakpoint *b = bl->owner; | |
3359 | ||
3360 | if (frame_id_p (b->frame_id) | |
edb3359d | 3361 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3362 | bs->stop = 0; |
3363 | else if (bs->stop) | |
3364 | { | |
3365 | int value_is_zero = 0; | |
3366 | ||
3367 | /* If this is a scope breakpoint, mark the associated | |
3368 | watchpoint as triggered so that we will handle the | |
3369 | out-of-scope event. We'll get to the watchpoint next | |
3370 | iteration. */ | |
3371 | if (b->type == bp_watchpoint_scope) | |
3372 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3373 | ||
3374 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3375 | { | |
c5bc3a77 DJ |
3376 | /* We use value_mark and value_free_to_mark because it could |
3377 | be a long time before we return to the command level and | |
3378 | call free_all_values. We can't call free_all_values | |
3379 | because we might be in the middle of evaluating a | |
3380 | function call. */ | |
3381 | struct value *mark = value_mark (); | |
3382 | ||
edb3359d DJ |
3383 | /* Need to select the frame, with all that implies so that |
3384 | the conditions will have the right context. Because we | |
3385 | use the frame, we will not see an inlined function's | |
3386 | variables when we arrive at a breakpoint at the start | |
3387 | of the inlined function; the current frame will be the | |
3388 | call site. */ | |
18a18393 VP |
3389 | select_frame (get_current_frame ()); |
3390 | value_is_zero | |
3391 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3392 | "Error in testing breakpoint condition:\n", | |
3393 | RETURN_MASK_ALL); | |
3394 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3395 | value_free_to_mark (mark); |
18a18393 VP |
3396 | } |
3397 | if (bl->cond && value_is_zero) | |
3398 | { | |
3399 | bs->stop = 0; | |
3400 | } | |
3401 | else if (b->thread != -1 && b->thread != thread_id) | |
3402 | { | |
3403 | bs->stop = 0; | |
3404 | } | |
3405 | else if (b->ignore_count > 0) | |
3406 | { | |
3407 | b->ignore_count--; | |
3408 | annotate_ignore_count_change (); | |
3409 | bs->stop = 0; | |
3410 | /* Increase the hit count even though we don't | |
3411 | stop. */ | |
3412 | ++(b->hit_count); | |
3413 | } | |
3414 | } | |
3415 | } | |
3416 | ||
3417 | ||
9709f61c | 3418 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3419 | BP_ADDR in thread PTID. |
c906108c | 3420 | |
d983da9c | 3421 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3422 | don't understand this stop. Result is a chain of bpstat's such that: |
3423 | ||
c5aa993b | 3424 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3425 | |
c5aa993b | 3426 | if we understand why we stopped, the result is not null. |
c906108c | 3427 | |
c5aa993b JM |
3428 | Each element of the chain refers to a particular breakpoint or |
3429 | watchpoint at which we have stopped. (We may have stopped for | |
3430 | several reasons concurrently.) | |
c906108c | 3431 | |
c5aa993b JM |
3432 | Each element of the chain has valid next, breakpoint_at, |
3433 | commands, FIXME??? fields. */ | |
c906108c SS |
3434 | |
3435 | bpstat | |
6c95b8df PA |
3436 | bpstat_stop_status (struct address_space *aspace, |
3437 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 3438 | { |
0d381245 | 3439 | struct breakpoint *b = NULL; |
876fa593 | 3440 | struct bp_location *bl, **blp_tmp; |
20874c92 | 3441 | struct bp_location *loc; |
c906108c SS |
3442 | /* Root of the chain of bpstat's */ |
3443 | struct bpstats root_bs[1]; | |
3444 | /* Pointer to the last thing in the chain currently. */ | |
3445 | bpstat bs = root_bs; | |
20874c92 | 3446 | int ix; |
876fa593 | 3447 | int need_remove_insert, update_locations = 0; |
c906108c | 3448 | |
876fa593 | 3449 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 3450 | { |
0d381245 VP |
3451 | b = bl->owner; |
3452 | gdb_assert (b); | |
468d015d | 3453 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) |
c5aa993b JM |
3454 | continue; |
3455 | ||
a5606eee VP |
3456 | /* For hardware watchpoints, we look only at the first location. |
3457 | The watchpoint_check function will work on entire expression, | |
3458 | not the individual locations. For read watchopints, the | |
3459 | watchpoints_triggered function have checked all locations | |
3d947dff | 3460 | already. */ |
a5606eee VP |
3461 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
3462 | continue; | |
3463 | ||
6c95b8df | 3464 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
18a18393 VP |
3465 | continue; |
3466 | ||
c5aa993b JM |
3467 | /* Come here if it's a watchpoint, or if the break address matches */ |
3468 | ||
0d381245 | 3469 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3470 | |
18a18393 VP |
3471 | /* Assume we stop. Should we find watchpoint that is not actually |
3472 | triggered, or if condition of breakpoint is false, we'll reset | |
3473 | 'stop' to 0. */ | |
c5aa993b JM |
3474 | bs->stop = 1; |
3475 | bs->print = 1; | |
3476 | ||
18a18393 VP |
3477 | bpstat_check_watchpoint (bs); |
3478 | if (!bs->stop) | |
3479 | continue; | |
c5aa993b | 3480 | |
0fd8e87f UW |
3481 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3482 | || b->type == bp_longjmp_master) | |
18a18393 | 3483 | /* We do not stop for these. */ |
c5aa993b JM |
3484 | bs->stop = 0; |
3485 | else | |
18a18393 VP |
3486 | bpstat_check_breakpoint_conditions (bs, ptid); |
3487 | ||
3488 | if (bs->stop) | |
c5aa993b | 3489 | { |
876fa593 JK |
3490 | if (b->enable_state != bp_disabled) |
3491 | ++(b->hit_count); | |
d983da9c | 3492 | |
18a18393 VP |
3493 | /* We will stop here */ |
3494 | if (b->disposition == disp_disable) | |
c5aa993b | 3495 | { |
514f746b AR |
3496 | if (b->enable_state != bp_permanent) |
3497 | b->enable_state = bp_disabled; | |
876fa593 | 3498 | update_locations = 1; |
c5aa993b | 3499 | } |
18a18393 VP |
3500 | if (b->silent) |
3501 | bs->print = 0; | |
3502 | bs->commands = b->commands; | |
059fb39f PM |
3503 | if (bs->commands |
3504 | && (strcmp ("silent", bs->commands->line) == 0 | |
3505 | || (xdb_commands && strcmp ("Q", bs->commands->line) == 0))) | |
c5aa993b | 3506 | { |
18a18393 VP |
3507 | bs->commands = bs->commands->next; |
3508 | bs->print = 0; | |
c5aa993b | 3509 | } |
18a18393 | 3510 | bs->commands = copy_command_lines (bs->commands); |
c5aa993b | 3511 | } |
18a18393 | 3512 | |
c5aa993b JM |
3513 | /* Print nothing for this entry if we dont stop or if we dont print. */ |
3514 | if (bs->stop == 0 || bs->print == 0) | |
3515 | bs->print_it = print_it_noop; | |
3516 | } | |
c906108c | 3517 | |
876fa593 JK |
3518 | /* Delay this call which would break the ALL_BP_LOCATIONS iteration above. */ |
3519 | if (update_locations) | |
3520 | update_global_location_list (0); | |
3521 | ||
20874c92 VP |
3522 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3523 | { | |
6c95b8df PA |
3524 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
3525 | aspace, bp_addr)) | |
20874c92 VP |
3526 | { |
3527 | bs = bpstat_alloc (loc, bs); | |
3528 | /* For hits of moribund locations, we should just proceed. */ | |
3529 | bs->stop = 0; | |
3530 | bs->print = 0; | |
3531 | bs->print_it = print_it_noop; | |
3532 | } | |
3533 | } | |
3534 | ||
c906108c SS |
3535 | bs->next = NULL; /* Terminate the chain */ |
3536 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3537 | ||
d983da9c DJ |
3538 | /* If we aren't stopping, the value of some hardware watchpoint may |
3539 | not have changed, but the intermediate memory locations we are | |
3540 | watching may have. Don't bother if we're stopping; this will get | |
3541 | done later. */ | |
3542 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3543 | if (bs->stop) | |
3544 | break; | |
3545 | ||
d832cb68 | 3546 | need_remove_insert = 0; |
d983da9c DJ |
3547 | if (bs == NULL) |
3548 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3549 | if (!bs->stop | |
20874c92 | 3550 | && bs->breakpoint_at->owner |
d983da9c DJ |
3551 | && (bs->breakpoint_at->owner->type == bp_hardware_watchpoint |
3552 | || bs->breakpoint_at->owner->type == bp_read_watchpoint | |
3553 | || bs->breakpoint_at->owner->type == bp_access_watchpoint)) | |
3554 | { | |
a5606eee VP |
3555 | /* remove/insert can invalidate bs->breakpoint_at, if this |
3556 | location is no longer used by the watchpoint. Prevent | |
3557 | further code from trying to use it. */ | |
3558 | bs->breakpoint_at = NULL; | |
d832cb68 | 3559 | need_remove_insert = 1; |
d983da9c DJ |
3560 | } |
3561 | ||
d832cb68 DD |
3562 | if (need_remove_insert) |
3563 | { | |
3564 | remove_breakpoints (); | |
3565 | insert_breakpoints (); | |
3566 | } | |
3567 | ||
d983da9c | 3568 | return root_bs->next; |
c906108c SS |
3569 | } |
3570 | \f | |
3571 | /* Tell what to do about this bpstat. */ | |
3572 | struct bpstat_what | |
fba45db2 | 3573 | bpstat_what (bpstat bs) |
c906108c SS |
3574 | { |
3575 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3576 | enum class |
3577 | { | |
3578 | /* This bpstat element has no effect on the main_action. */ | |
3579 | no_effect = 0, | |
3580 | ||
3581 | /* There was a watchpoint, stop but don't print. */ | |
3582 | wp_silent, | |
c906108c | 3583 | |
c5aa993b JM |
3584 | /* There was a watchpoint, stop and print. */ |
3585 | wp_noisy, | |
c906108c | 3586 | |
c5aa993b JM |
3587 | /* There was a breakpoint but we're not stopping. */ |
3588 | bp_nostop, | |
c906108c | 3589 | |
c5aa993b JM |
3590 | /* There was a breakpoint, stop but don't print. */ |
3591 | bp_silent, | |
c906108c | 3592 | |
c5aa993b JM |
3593 | /* There was a breakpoint, stop and print. */ |
3594 | bp_noisy, | |
c906108c | 3595 | |
c5aa993b JM |
3596 | /* We hit the longjmp breakpoint. */ |
3597 | long_jump, | |
c906108c | 3598 | |
c5aa993b JM |
3599 | /* We hit the longjmp_resume breakpoint. */ |
3600 | long_resume, | |
c906108c | 3601 | |
c5aa993b JM |
3602 | /* We hit the step_resume breakpoint. */ |
3603 | step_resume, | |
c906108c | 3604 | |
c5aa993b JM |
3605 | /* We hit the shared library event breakpoint. */ |
3606 | shlib_event, | |
c906108c | 3607 | |
4efc6507 DE |
3608 | /* We hit the jit event breakpoint. */ |
3609 | jit_event, | |
3610 | ||
c5aa993b JM |
3611 | /* This is just used to count how many enums there are. */ |
3612 | class_last | |
c906108c SS |
3613 | }; |
3614 | ||
3615 | /* Here is the table which drives this routine. So that we can | |
3616 | format it pretty, we define some abbreviations for the | |
3617 | enum bpstat_what codes. */ | |
3618 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3619 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3620 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3621 | #define sgl BPSTAT_WHAT_SINGLE | |
3622 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3623 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3624 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3625 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 3626 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
3627 | |
3628 | /* "Can't happen." Might want to print an error message. | |
3629 | abort() is not out of the question, but chances are GDB is just | |
3630 | a bit confused, not unusable. */ | |
3631 | #define err BPSTAT_WHAT_STOP_NOISY | |
3632 | ||
3633 | /* Given an old action and a class, come up with a new action. */ | |
3634 | /* One interesting property of this table is that wp_silent is the same | |
3635 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3636 | after stopping, the check for whether to step over a breakpoint | |
3637 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3638 | reference to how we stopped. We retain separate wp_silent and |
3639 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3640 | |
3641 | Another possibly interesting property of this table is that | |
3642 | there's a partial ordering, priority-like, of the actions. Once | |
3643 | you've decided that some action is appropriate, you'll never go | |
3644 | back and decide something of a lower priority is better. The | |
3645 | ordering is: | |
3646 | ||
4efc6507 DE |
3647 | kc < jit clr sgl shl slr sn sr ss |
3648 | sgl < jit shl slr sn sr ss | |
3649 | slr < jit err shl sn sr ss | |
3650 | clr < jit err shl sn sr ss | |
3651 | ss < jit shl sn sr | |
3652 | sn < jit shl sr | |
3653 | jit < shl sr | |
d81191fc | 3654 | shl < sr |
4d5b2cd7 | 3655 | sr < |
c5aa993b | 3656 | |
43ff13b4 JM |
3657 | What I think this means is that we don't need a damned table |
3658 | here. If you just put the rows and columns in the right order, | |
3659 | it'd look awfully regular. We could simply walk the bpstat list | |
3660 | and choose the highest priority action we find, with a little | |
78b6a731 | 3661 | logic to handle the 'err' cases. */ |
c906108c SS |
3662 | |
3663 | /* step_resume entries: a step resume breakpoint overrides another | |
3664 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3665 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3666 | |
3667 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3668 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3669 | { | |
3670 | /* old action */ | |
4efc6507 DE |
3671 | /* kc ss sn sgl slr clr sr shl jit */ |
3672 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
3673 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3674 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3675 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
3676 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3677 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3678 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
3679 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
3680 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
3681 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
3682 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 3683 | }; |
c906108c SS |
3684 | |
3685 | #undef kc | |
3686 | #undef ss | |
3687 | #undef sn | |
3688 | #undef sgl | |
3689 | #undef slr | |
3690 | #undef clr | |
c906108c SS |
3691 | #undef err |
3692 | #undef sr | |
3693 | #undef ts | |
3694 | #undef shl | |
4efc6507 | 3695 | #undef jit |
c906108c SS |
3696 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3697 | struct bpstat_what retval; | |
3698 | ||
3699 | retval.call_dummy = 0; | |
3700 | for (; bs != NULL; bs = bs->next) | |
3701 | { | |
3702 | enum class bs_class = no_effect; | |
3703 | if (bs->breakpoint_at == NULL) | |
3704 | /* I suspect this can happen if it was a momentary breakpoint | |
3705 | which has since been deleted. */ | |
3706 | continue; | |
20874c92 VP |
3707 | if (bs->breakpoint_at->owner == NULL) |
3708 | bs_class = bp_nostop; | |
3709 | else | |
4f8d1dc6 | 3710 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3711 | { |
3712 | case bp_none: | |
3713 | continue; | |
3714 | ||
3715 | case bp_breakpoint: | |
3716 | case bp_hardware_breakpoint: | |
3717 | case bp_until: | |
3718 | case bp_finish: | |
3719 | if (bs->stop) | |
3720 | { | |
3721 | if (bs->print) | |
3722 | bs_class = bp_noisy; | |
3723 | else | |
3724 | bs_class = bp_silent; | |
3725 | } | |
3726 | else | |
3727 | bs_class = bp_nostop; | |
3728 | break; | |
3729 | case bp_watchpoint: | |
3730 | case bp_hardware_watchpoint: | |
3731 | case bp_read_watchpoint: | |
3732 | case bp_access_watchpoint: | |
3733 | if (bs->stop) | |
3734 | { | |
3735 | if (bs->print) | |
3736 | bs_class = wp_noisy; | |
3737 | else | |
3738 | bs_class = wp_silent; | |
3739 | } | |
3740 | else | |
53a5351d JM |
3741 | /* There was a watchpoint, but we're not stopping. |
3742 | This requires no further action. */ | |
c906108c SS |
3743 | bs_class = no_effect; |
3744 | break; | |
3745 | case bp_longjmp: | |
3746 | bs_class = long_jump; | |
3747 | break; | |
3748 | case bp_longjmp_resume: | |
3749 | bs_class = long_resume; | |
3750 | break; | |
3751 | case bp_step_resume: | |
3752 | if (bs->stop) | |
3753 | { | |
3754 | bs_class = step_resume; | |
3755 | } | |
3756 | else | |
3757 | /* It is for the wrong frame. */ | |
3758 | bs_class = bp_nostop; | |
3759 | break; | |
c906108c SS |
3760 | case bp_watchpoint_scope: |
3761 | bs_class = bp_nostop; | |
3762 | break; | |
c5aa993b JM |
3763 | case bp_shlib_event: |
3764 | bs_class = shlib_event; | |
3765 | break; | |
4efc6507 DE |
3766 | case bp_jit_event: |
3767 | bs_class = jit_event; | |
3768 | break; | |
c4093a6a | 3769 | case bp_thread_event: |
1900040c | 3770 | case bp_overlay_event: |
0fd8e87f | 3771 | case bp_longjmp_master: |
c4093a6a JM |
3772 | bs_class = bp_nostop; |
3773 | break; | |
ce78b96d | 3774 | case bp_catchpoint: |
c5aa993b JM |
3775 | if (bs->stop) |
3776 | { | |
3777 | if (bs->print) | |
3778 | bs_class = bp_noisy; | |
3779 | else | |
3780 | bs_class = bp_silent; | |
3781 | } | |
3782 | else | |
53a5351d JM |
3783 | /* There was a catchpoint, but we're not stopping. |
3784 | This requires no further action. */ | |
c5aa993b JM |
3785 | bs_class = no_effect; |
3786 | break; | |
c906108c | 3787 | case bp_call_dummy: |
53a5351d JM |
3788 | /* Make sure the action is stop (silent or noisy), |
3789 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3790 | bs_class = bp_silent; |
3791 | retval.call_dummy = 1; | |
3792 | break; | |
1042e4c0 SS |
3793 | case bp_tracepoint: |
3794 | /* Tracepoint hits should not be reported back to GDB, and | |
3795 | if one got through somehow, it should have been filtered | |
3796 | out already. */ | |
3797 | internal_error (__FILE__, __LINE__, | |
3798 | _("bpstat_what: bp_tracepoint encountered")); | |
3799 | break; | |
c906108c | 3800 | } |
c5aa993b | 3801 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3802 | } |
3803 | retval.main_action = current_action; | |
3804 | return retval; | |
3805 | } | |
3806 | ||
3807 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3808 | without hardware support). This isn't related to a specific bpstat, | |
3809 | just to things like whether watchpoints are set. */ | |
3810 | ||
c5aa993b | 3811 | int |
fba45db2 | 3812 | bpstat_should_step (void) |
c906108c SS |
3813 | { |
3814 | struct breakpoint *b; | |
3815 | ALL_BREAKPOINTS (b) | |
717a8278 | 3816 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3817 | return 1; |
c906108c SS |
3818 | return 0; |
3819 | } | |
3820 | ||
c906108c | 3821 | \f |
c5aa993b | 3822 | |
0d381245 VP |
3823 | static void print_breakpoint_location (struct breakpoint *b, |
3824 | struct bp_location *loc, | |
3825 | char *wrap_indent, | |
3826 | struct ui_stream *stb) | |
3827 | { | |
6c95b8df PA |
3828 | struct cleanup *old_chain = save_current_program_space (); |
3829 | ||
3830 | if (loc != NULL) | |
3831 | set_current_program_space (loc->pspace); | |
3832 | ||
0d381245 VP |
3833 | if (b->source_file) |
3834 | { | |
3835 | struct symbol *sym | |
3836 | = find_pc_sect_function (loc->address, loc->section); | |
3837 | if (sym) | |
3838 | { | |
3839 | ui_out_text (uiout, "in "); | |
3840 | ui_out_field_string (uiout, "func", | |
3841 | SYMBOL_PRINT_NAME (sym)); | |
3842 | ui_out_wrap_hint (uiout, wrap_indent); | |
3843 | ui_out_text (uiout, " at "); | |
3844 | } | |
3845 | ui_out_field_string (uiout, "file", b->source_file); | |
3846 | ui_out_text (uiout, ":"); | |
3847 | ||
3848 | if (ui_out_is_mi_like_p (uiout)) | |
3849 | { | |
3850 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3851 | char *fullname = symtab_to_fullname (sal.symtab); | |
3852 | ||
3853 | if (fullname) | |
3854 | ui_out_field_string (uiout, "fullname", fullname); | |
3855 | } | |
3856 | ||
3857 | ui_out_field_int (uiout, "line", b->line_number); | |
3858 | } | |
3859 | else if (!b->loc) | |
3860 | { | |
3861 | ui_out_field_string (uiout, "pending", b->addr_string); | |
3862 | } | |
3863 | else | |
3864 | { | |
3865 | print_address_symbolic (loc->address, stb->stream, demangle, ""); | |
3866 | ui_out_field_stream (uiout, "at", stb); | |
3867 | } | |
6c95b8df PA |
3868 | |
3869 | do_cleanups (old_chain); | |
0d381245 VP |
3870 | } |
3871 | ||
c4093a6a | 3872 | /* Print B to gdb_stdout. */ |
c906108c | 3873 | static void |
0d381245 VP |
3874 | print_one_breakpoint_location (struct breakpoint *b, |
3875 | struct bp_location *loc, | |
3876 | int loc_number, | |
a6d9a66e | 3877 | struct bp_location **last_loc, |
6c95b8df PA |
3878 | int print_address_bits, |
3879 | int allflag) | |
c906108c | 3880 | { |
52f0bd74 AC |
3881 | struct command_line *l; |
3882 | struct symbol *sym; | |
c4093a6a JM |
3883 | struct ep_type_description |
3884 | { | |
3885 | enum bptype type; | |
3886 | char *description; | |
3887 | }; | |
3888 | static struct ep_type_description bptypes[] = | |
c906108c | 3889 | { |
c5aa993b JM |
3890 | {bp_none, "?deleted?"}, |
3891 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 3892 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
3893 | {bp_until, "until"}, |
3894 | {bp_finish, "finish"}, | |
3895 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 3896 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
3897 | {bp_read_watchpoint, "read watchpoint"}, |
3898 | {bp_access_watchpoint, "acc watchpoint"}, | |
3899 | {bp_longjmp, "longjmp"}, | |
3900 | {bp_longjmp_resume, "longjmp resume"}, | |
3901 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
3902 | {bp_watchpoint_scope, "watchpoint scope"}, |
3903 | {bp_call_dummy, "call dummy"}, | |
3904 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 3905 | {bp_thread_event, "thread events"}, |
1900040c | 3906 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 3907 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 3908 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 3909 | {bp_tracepoint, "tracepoint"}, |
4efc6507 | 3910 | {bp_jit_event, "jit events"}, |
c5aa993b | 3911 | }; |
c4093a6a | 3912 | |
c2c6d25f | 3913 | static char bpenables[] = "nynny"; |
c906108c | 3914 | char wrap_indent[80]; |
8b93c638 JM |
3915 | struct ui_stream *stb = ui_out_stream_new (uiout); |
3916 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 3917 | struct cleanup *bkpt_chain; |
c906108c | 3918 | |
0d381245 VP |
3919 | int header_of_multiple = 0; |
3920 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
3921 | struct value_print_options opts; |
3922 | ||
3923 | get_user_print_options (&opts); | |
0d381245 VP |
3924 | |
3925 | gdb_assert (!loc || loc_number != 0); | |
3926 | /* See comment in print_one_breakpoint concerning | |
3927 | treatment of breakpoints with single disabled | |
3928 | location. */ | |
3929 | if (loc == NULL | |
3930 | && (b->loc != NULL | |
3931 | && (b->loc->next != NULL || !b->loc->enabled))) | |
3932 | header_of_multiple = 1; | |
3933 | if (loc == NULL) | |
3934 | loc = b->loc; | |
3935 | ||
c4093a6a | 3936 | annotate_record (); |
3b31d625 | 3937 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
3938 | |
3939 | /* 1 */ | |
3940 | annotate_field (0); | |
0d381245 VP |
3941 | if (part_of_multiple) |
3942 | { | |
3943 | char *formatted; | |
0c6773c1 | 3944 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
3945 | ui_out_field_string (uiout, "number", formatted); |
3946 | xfree (formatted); | |
3947 | } | |
3948 | else | |
3949 | { | |
3950 | ui_out_field_int (uiout, "number", b->number); | |
3951 | } | |
c4093a6a JM |
3952 | |
3953 | /* 2 */ | |
3954 | annotate_field (1); | |
0d381245 VP |
3955 | if (part_of_multiple) |
3956 | ui_out_field_skip (uiout, "type"); | |
3957 | else | |
3958 | { | |
3959 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
3960 | || ((int) b->type != bptypes[(int) b->type].type)) | |
3961 | internal_error (__FILE__, __LINE__, | |
3962 | _("bptypes table does not describe type #%d."), | |
3963 | (int) b->type); | |
3964 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
3965 | } | |
c4093a6a JM |
3966 | |
3967 | /* 3 */ | |
3968 | annotate_field (2); | |
0d381245 VP |
3969 | if (part_of_multiple) |
3970 | ui_out_field_skip (uiout, "disp"); | |
3971 | else | |
2cec12e5 | 3972 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 3973 | |
c4093a6a JM |
3974 | |
3975 | /* 4 */ | |
3976 | annotate_field (3); | |
0d381245 | 3977 | if (part_of_multiple) |
54e52265 | 3978 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 3979 | else |
54e52265 VP |
3980 | ui_out_field_fmt (uiout, "enabled", "%c", |
3981 | bpenables[(int) b->enable_state]); | |
3982 | ui_out_spaces (uiout, 2); | |
0d381245 | 3983 | |
c4093a6a JM |
3984 | |
3985 | /* 5 and 6 */ | |
3986 | strcpy (wrap_indent, " "); | |
79a45b7d | 3987 | if (opts.addressprint) |
75ac9d7b | 3988 | { |
a6d9a66e | 3989 | if (print_address_bits <= 32) |
75ac9d7b MS |
3990 | strcat (wrap_indent, " "); |
3991 | else | |
3992 | strcat (wrap_indent, " "); | |
3993 | } | |
c906108c | 3994 | |
3086aeae | 3995 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
3996 | { |
3997 | /* Although the print_one can possibly print | |
3998 | all locations, calling it here is not likely | |
3999 | to get any nice result. So, make sure there's | |
4000 | just one location. */ | |
4001 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4002 | b->ops->print_one (b, last_loc); |
0d381245 | 4003 | } |
3086aeae DJ |
4004 | else |
4005 | switch (b->type) | |
4006 | { | |
4007 | case bp_none: | |
4008 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4009 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4010 | break; |
c906108c | 4011 | |
3086aeae DJ |
4012 | case bp_watchpoint: |
4013 | case bp_hardware_watchpoint: | |
4014 | case bp_read_watchpoint: | |
4015 | case bp_access_watchpoint: | |
4016 | /* Field 4, the address, is omitted (which makes the columns | |
4017 | not line up too nicely with the headers, but the effect | |
4018 | is relatively readable). */ | |
79a45b7d | 4019 | if (opts.addressprint) |
3086aeae DJ |
4020 | ui_out_field_skip (uiout, "addr"); |
4021 | annotate_field (5); | |
fa8a61dc | 4022 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4023 | break; |
4024 | ||
3086aeae DJ |
4025 | case bp_breakpoint: |
4026 | case bp_hardware_breakpoint: | |
4027 | case bp_until: | |
4028 | case bp_finish: | |
4029 | case bp_longjmp: | |
4030 | case bp_longjmp_resume: | |
4031 | case bp_step_resume: | |
3086aeae DJ |
4032 | case bp_watchpoint_scope: |
4033 | case bp_call_dummy: | |
4034 | case bp_shlib_event: | |
4035 | case bp_thread_event: | |
4036 | case bp_overlay_event: | |
0fd8e87f | 4037 | case bp_longjmp_master: |
1042e4c0 | 4038 | case bp_tracepoint: |
4efc6507 | 4039 | case bp_jit_event: |
79a45b7d | 4040 | if (opts.addressprint) |
3086aeae DJ |
4041 | { |
4042 | annotate_field (4); | |
54e52265 | 4043 | if (header_of_multiple) |
0d381245 | 4044 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4045 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4046 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4047 | else |
5af949e3 UW |
4048 | ui_out_field_core_addr (uiout, "addr", |
4049 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4050 | } |
4051 | annotate_field (5); | |
0d381245 VP |
4052 | if (!header_of_multiple) |
4053 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4054 | if (b->loc) | |
a6d9a66e | 4055 | *last_loc = b->loc; |
3086aeae DJ |
4056 | break; |
4057 | } | |
c906108c | 4058 | |
6c95b8df PA |
4059 | |
4060 | /* For backward compatibility, don't display inferiors unless there | |
4061 | are several. */ | |
4062 | if (loc != NULL | |
4063 | && !header_of_multiple | |
4064 | && (allflag | |
4065 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4066 | && (number_of_program_spaces () > 1 | |
4067 | || number_of_inferiors () > 1) | |
4068 | && loc->owner->type != bp_catchpoint))) | |
4069 | { | |
4070 | struct inferior *inf; | |
4071 | int first = 1; | |
4072 | ||
4073 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4074 | { | |
4075 | if (inf->pspace == loc->pspace) | |
4076 | { | |
4077 | if (first) | |
4078 | { | |
4079 | first = 0; | |
4080 | ui_out_text (uiout, " inf "); | |
4081 | } | |
4082 | else | |
4083 | ui_out_text (uiout, ", "); | |
4084 | ui_out_text (uiout, plongest (inf->num)); | |
4085 | } | |
4086 | } | |
4087 | } | |
4088 | ||
4a306c9a | 4089 | if (!part_of_multiple) |
c4093a6a | 4090 | { |
4a306c9a JB |
4091 | if (b->thread != -1) |
4092 | { | |
4093 | /* FIXME: This seems to be redundant and lost here; see the | |
4094 | "stop only in" line a little further down. */ | |
4095 | ui_out_text (uiout, " thread "); | |
4096 | ui_out_field_int (uiout, "thread", b->thread); | |
4097 | } | |
4098 | else if (b->task != 0) | |
4099 | { | |
4100 | ui_out_text (uiout, " task "); | |
4101 | ui_out_field_int (uiout, "task", b->task); | |
4102 | } | |
c4093a6a JM |
4103 | } |
4104 | ||
8b93c638 | 4105 | ui_out_text (uiout, "\n"); |
c4093a6a | 4106 | |
0d381245 | 4107 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4108 | { |
4109 | annotate_field (6); | |
8b93c638 | 4110 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4111 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4112 | the frame ID. */ | |
5af949e3 UW |
4113 | ui_out_field_core_addr (uiout, "frame", |
4114 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4115 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4116 | } |
4117 | ||
0d381245 | 4118 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4119 | { |
f7f9143b JB |
4120 | /* We do not print the condition for Ada exception catchpoints |
4121 | because the condition is an internal implementation detail | |
4122 | that we do not want to expose to the user. */ | |
c4093a6a | 4123 | annotate_field (7); |
1042e4c0 SS |
4124 | if (b->type == bp_tracepoint) |
4125 | ui_out_text (uiout, "\ttrace only if "); | |
4126 | else | |
4127 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4128 | ui_out_field_string (uiout, "cond", b->cond_string); |
4129 | ui_out_text (uiout, "\n"); | |
4130 | } | |
4131 | ||
0d381245 | 4132 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4133 | { |
4134 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4135 | ui_out_text (uiout, "\tstop only in thread "); |
4136 | ui_out_field_int (uiout, "thread", b->thread); | |
4137 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4138 | } |
4139 | ||
63c715c6 | 4140 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4141 | { |
4142 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4143 | if (ep_is_catchpoint (b)) |
4144 | ui_out_text (uiout, "\tcatchpoint"); | |
4145 | else | |
4146 | ui_out_text (uiout, "\tbreakpoint"); | |
4147 | ui_out_text (uiout, " already hit "); | |
4148 | ui_out_field_int (uiout, "times", b->hit_count); | |
4149 | if (b->hit_count == 1) | |
4150 | ui_out_text (uiout, " time\n"); | |
4151 | else | |
4152 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4153 | } |
4154 | ||
fb40c209 AC |
4155 | /* Output the count also if it is zero, but only if this is |
4156 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4157 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4158 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4159 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4160 | |
0d381245 | 4161 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4162 | { |
4163 | annotate_field (8); | |
8b93c638 JM |
4164 | ui_out_text (uiout, "\tignore next "); |
4165 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4166 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4167 | } |
059fb39f PM |
4168 | |
4169 | l = b->commands; | |
4170 | if (!part_of_multiple && l) | |
c4093a6a | 4171 | { |
3b31d625 EZ |
4172 | struct cleanup *script_chain; |
4173 | ||
c4093a6a | 4174 | annotate_field (9); |
3b31d625 | 4175 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4176 | print_command_lines (uiout, l, 4); |
3b31d625 | 4177 | do_cleanups (script_chain); |
c4093a6a | 4178 | } |
d24317b4 | 4179 | |
1042e4c0 SS |
4180 | if (!part_of_multiple && b->pass_count) |
4181 | { | |
4182 | annotate_field (10); | |
4183 | ui_out_text (uiout, "\tpass count "); | |
4184 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4185 | ui_out_text (uiout, " \n"); | |
4186 | } | |
4187 | ||
4188 | if (!part_of_multiple && b->step_count) | |
4189 | { | |
4190 | annotate_field (11); | |
4191 | ui_out_text (uiout, "\tstep count "); | |
4192 | ui_out_field_int (uiout, "step", b->step_count); | |
4193 | ui_out_text (uiout, " \n"); | |
4194 | } | |
4195 | ||
4196 | if (!part_of_multiple && b->actions) | |
4197 | { | |
4198 | struct action_line *action; | |
4199 | annotate_field (12); | |
4200 | for (action = b->actions; action; action = action->next) | |
4201 | { | |
4202 | ui_out_text (uiout, " A\t"); | |
4203 | ui_out_text (uiout, action->action); | |
4204 | ui_out_text (uiout, "\n"); | |
4205 | } | |
4206 | } | |
4207 | ||
d24317b4 VP |
4208 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4209 | { | |
4210 | if (b->addr_string) | |
4211 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4212 | else if (b->exp_string) | |
4213 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4214 | } | |
4215 | ||
3b31d625 | 4216 | do_cleanups (bkpt_chain); |
8b93c638 | 4217 | do_cleanups (old_chain); |
c4093a6a | 4218 | } |
c5aa993b | 4219 | |
0d381245 VP |
4220 | static void |
4221 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4222 | struct bp_location **last_loc, int print_address_bits, |
4223 | int allflag) | |
0d381245 | 4224 | { |
6c95b8df PA |
4225 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4226 | print_address_bits, allflag); | |
0d381245 VP |
4227 | |
4228 | /* If this breakpoint has custom print function, | |
4229 | it's already printed. Otherwise, print individual | |
4230 | locations, if any. */ | |
4231 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4232 | { | |
4233 | /* If breakpoint has a single location that is | |
4234 | disabled, we print it as if it had | |
4235 | several locations, since otherwise it's hard to | |
4236 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4237 | situation. |
4238 | Note that while hardware watchpoints have | |
4239 | several locations internally, that's no a property | |
4240 | exposed to user. */ | |
0d381245 | 4241 | if (b->loc |
a5606eee | 4242 | && !is_hardware_watchpoint (b) |
0d381245 | 4243 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4244 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4245 | { |
4246 | struct bp_location *loc; | |
4247 | int n = 1; | |
4248 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4249 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4250 | print_address_bits, allflag); |
0d381245 VP |
4251 | } |
4252 | } | |
4253 | } | |
4254 | ||
a6d9a66e UW |
4255 | static int |
4256 | breakpoint_address_bits (struct breakpoint *b) | |
4257 | { | |
4258 | int print_address_bits = 0; | |
4259 | struct bp_location *loc; | |
4260 | ||
4261 | for (loc = b->loc; loc; loc = loc->next) | |
4262 | { | |
4263 | int addr_bit = gdbarch_addr_bit (b->gdbarch); | |
4264 | if (addr_bit > print_address_bits) | |
4265 | print_address_bits = addr_bit; | |
4266 | } | |
4267 | ||
4268 | return print_address_bits; | |
4269 | } | |
0d381245 | 4270 | |
c4093a6a JM |
4271 | struct captured_breakpoint_query_args |
4272 | { | |
4273 | int bnum; | |
4274 | }; | |
c5aa993b | 4275 | |
c4093a6a | 4276 | static int |
2b65245e | 4277 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4278 | { |
4279 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4280 | struct breakpoint *b; |
a6d9a66e | 4281 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4282 | ALL_BREAKPOINTS (b) |
4283 | { | |
4284 | if (args->bnum == b->number) | |
c5aa993b | 4285 | { |
a6d9a66e | 4286 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4287 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4288 | return GDB_RC_OK; |
c5aa993b | 4289 | } |
c4093a6a JM |
4290 | } |
4291 | return GDB_RC_NONE; | |
4292 | } | |
c5aa993b | 4293 | |
c4093a6a | 4294 | enum gdb_rc |
ce43223b | 4295 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4296 | { |
4297 | struct captured_breakpoint_query_args args; | |
4298 | args.bnum = bnum; | |
4299 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4300 | an error. */ | |
b0b13bb4 DJ |
4301 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4302 | error_message, RETURN_MASK_ALL) < 0) | |
4303 | return GDB_RC_FAIL; | |
4304 | else | |
4305 | return GDB_RC_OK; | |
c4093a6a | 4306 | } |
c5aa993b | 4307 | |
7f3b0473 AC |
4308 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4309 | catchpoints, et.al.). */ | |
4310 | ||
4311 | static int | |
4312 | user_settable_breakpoint (const struct breakpoint *b) | |
4313 | { | |
4314 | return (b->type == bp_breakpoint | |
ce78b96d | 4315 | || b->type == bp_catchpoint |
7f3b0473 | 4316 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 4317 | || b->type == bp_tracepoint |
7f3b0473 AC |
4318 | || b->type == bp_watchpoint |
4319 | || b->type == bp_read_watchpoint | |
4320 | || b->type == bp_access_watchpoint | |
4321 | || b->type == bp_hardware_watchpoint); | |
4322 | } | |
4323 | ||
4324 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4325 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4326 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4327 | |
c4093a6a | 4328 | static void |
fba45db2 | 4329 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4330 | { |
52f0bd74 | 4331 | struct breakpoint *b; |
a6d9a66e | 4332 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4333 | int nr_printable_breakpoints; |
3b31d625 | 4334 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4335 | struct value_print_options opts; |
a6d9a66e | 4336 | int print_address_bits = 0; |
c4093a6a | 4337 | |
79a45b7d TT |
4338 | get_user_print_options (&opts); |
4339 | ||
a6d9a66e UW |
4340 | /* Compute the number of rows in the table, as well as the |
4341 | size required for address fields. */ | |
7f3b0473 AC |
4342 | nr_printable_breakpoints = 0; |
4343 | ALL_BREAKPOINTS (b) | |
4344 | if (bnum == -1 | |
4345 | || bnum == b->number) | |
4346 | { | |
4347 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4348 | { |
4349 | int addr_bit = breakpoint_address_bits (b); | |
4350 | if (addr_bit > print_address_bits) | |
4351 | print_address_bits = addr_bit; | |
4352 | ||
4353 | nr_printable_breakpoints++; | |
4354 | } | |
7f3b0473 AC |
4355 | } |
4356 | ||
79a45b7d | 4357 | if (opts.addressprint) |
3b31d625 EZ |
4358 | bkpttbl_chain |
4359 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4360 | "BreakpointTable"); | |
8b93c638 | 4361 | else |
3b31d625 EZ |
4362 | bkpttbl_chain |
4363 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4364 | "BreakpointTable"); | |
8b93c638 | 4365 | |
7f3b0473 | 4366 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4367 | annotate_breakpoints_headers (); |
4368 | if (nr_printable_breakpoints > 0) | |
4369 | annotate_field (0); | |
0d381245 | 4370 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4371 | if (nr_printable_breakpoints > 0) |
4372 | annotate_field (1); | |
4373 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4374 | if (nr_printable_breakpoints > 0) | |
4375 | annotate_field (2); | |
4376 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4377 | if (nr_printable_breakpoints > 0) | |
4378 | annotate_field (3); | |
54e52265 | 4379 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4380 | if (opts.addressprint) |
7f3b0473 | 4381 | { |
d7faa9e7 AC |
4382 | if (nr_printable_breakpoints > 0) |
4383 | annotate_field (4); | |
a6d9a66e | 4384 | if (print_address_bits <= 32) |
b25959ec | 4385 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4386 | else |
b25959ec | 4387 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4388 | } |
d7faa9e7 AC |
4389 | if (nr_printable_breakpoints > 0) |
4390 | annotate_field (5); | |
4391 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4392 | ui_out_table_body (uiout); | |
4393 | if (nr_printable_breakpoints > 0) | |
4394 | annotate_breakpoints_table (); | |
7f3b0473 | 4395 | |
c4093a6a JM |
4396 | ALL_BREAKPOINTS (b) |
4397 | if (bnum == -1 | |
4398 | || bnum == b->number) | |
4399 | { | |
4400 | /* We only print out user settable breakpoints unless the | |
4401 | allflag is set. */ | |
7f3b0473 | 4402 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 4403 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a JM |
4404 | } |
4405 | ||
3b31d625 | 4406 | do_cleanups (bkpttbl_chain); |
698384cd | 4407 | |
7f3b0473 | 4408 | if (nr_printable_breakpoints == 0) |
c906108c | 4409 | { |
8b93c638 JM |
4410 | if (bnum == -1) |
4411 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4412 | else | |
4413 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4414 | bnum); | |
c906108c SS |
4415 | } |
4416 | else | |
c4093a6a | 4417 | { |
a6d9a66e UW |
4418 | if (last_loc && !server_command) |
4419 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4420 | } |
c906108c | 4421 | |
c4093a6a JM |
4422 | /* FIXME? Should this be moved up so that it is only called when |
4423 | there have been breakpoints? */ | |
c906108c SS |
4424 | annotate_breakpoints_table_end (); |
4425 | } | |
4426 | ||
c906108c | 4427 | static void |
fba45db2 | 4428 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4429 | { |
4430 | int bnum = -1; | |
4431 | ||
4432 | if (bnum_exp) | |
bb518678 | 4433 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4434 | |
4435 | breakpoint_1 (bnum, 0); | |
4436 | } | |
4437 | ||
7a292a7a | 4438 | static void |
fba45db2 | 4439 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4440 | { |
4441 | int bnum = -1; | |
4442 | ||
4443 | if (bnum_exp) | |
bb518678 | 4444 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4445 | |
4446 | breakpoint_1 (bnum, 1); | |
4447 | } | |
4448 | ||
0d381245 | 4449 | static int |
714835d5 | 4450 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 4451 | struct program_space *pspace, |
714835d5 | 4452 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
4453 | { |
4454 | struct bp_location *bl = b->loc; | |
4455 | for (; bl; bl = bl->next) | |
4456 | { | |
6c95b8df PA |
4457 | if (bl->pspace == pspace |
4458 | && bl->address == pc | |
0d381245 VP |
4459 | && (!overlay_debugging || bl->section == section)) |
4460 | return 1; | |
4461 | } | |
4462 | return 0; | |
4463 | } | |
4464 | ||
6c95b8df PA |
4465 | /* Print a message describing any breakpoints set at PC. This |
4466 | concerns with logical breakpoints, so we match program spaces, not | |
4467 | address spaces. */ | |
c906108c SS |
4468 | |
4469 | static void | |
6c95b8df PA |
4470 | describe_other_breakpoints (struct gdbarch *gdbarch, |
4471 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 4472 | struct obj_section *section, int thread) |
c906108c | 4473 | { |
52f0bd74 AC |
4474 | int others = 0; |
4475 | struct breakpoint *b; | |
c906108c SS |
4476 | |
4477 | ALL_BREAKPOINTS (b) | |
6c95b8df | 4478 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
4479 | if (others > 0) |
4480 | { | |
a3f17187 AC |
4481 | if (others == 1) |
4482 | printf_filtered (_("Note: breakpoint ")); | |
4483 | else /* if (others == ???) */ | |
4484 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4485 | ALL_BREAKPOINTS (b) |
6c95b8df | 4486 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
4487 | { |
4488 | others--; | |
4489 | printf_filtered ("%d", b->number); | |
4490 | if (b->thread == -1 && thread != -1) | |
4491 | printf_filtered (" (all threads)"); | |
4492 | else if (b->thread != -1) | |
4493 | printf_filtered (" (thread %d)", b->thread); | |
4494 | printf_filtered ("%s%s ", | |
059fb39f | 4495 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4496 | || b->enable_state == bp_call_disabled |
4497 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4498 | ? " (disabled)" |
4499 | : b->enable_state == bp_permanent | |
4500 | ? " (permanent)" | |
4501 | : ""), | |
4502 | (others > 1) ? "," | |
4503 | : ((others == 1) ? " and" : "")); | |
4504 | } | |
a3f17187 | 4505 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4506 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4507 | printf_filtered (".\n"); |
4508 | } | |
4509 | } | |
4510 | \f | |
4511 | /* Set the default place to put a breakpoint | |
4512 | for the `break' command with no arguments. */ | |
4513 | ||
4514 | void | |
6c95b8df PA |
4515 | set_default_breakpoint (int valid, struct program_space *pspace, |
4516 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 4517 | int line) |
c906108c SS |
4518 | { |
4519 | default_breakpoint_valid = valid; | |
6c95b8df | 4520 | default_breakpoint_pspace = pspace; |
c906108c SS |
4521 | default_breakpoint_address = addr; |
4522 | default_breakpoint_symtab = symtab; | |
4523 | default_breakpoint_line = line; | |
4524 | } | |
4525 | ||
e4f237da KB |
4526 | /* Return true iff it is meaningful to use the address member of |
4527 | BPT. For some breakpoint types, the address member is irrelevant | |
4528 | and it makes no sense to attempt to compare it to other addresses | |
4529 | (or use it for any other purpose either). | |
4530 | ||
4531 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
4532 | have a zero valued address and we don't want to mark breakpoints of any of |
4533 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
4534 | |
4535 | bp_watchpoint | |
4536 | bp_hardware_watchpoint | |
4537 | bp_read_watchpoint | |
4538 | bp_access_watchpoint | |
fe798b75 | 4539 | bp_catchpoint */ |
e4f237da KB |
4540 | |
4541 | static int | |
4542 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4543 | { | |
4544 | enum bptype type = bpt->type; | |
4545 | ||
4546 | return (type != bp_watchpoint | |
4547 | && type != bp_hardware_watchpoint | |
4548 | && type != bp_read_watchpoint | |
4549 | && type != bp_access_watchpoint | |
fe798b75 | 4550 | && type != bp_catchpoint); |
e4f237da KB |
4551 | } |
4552 | ||
6c95b8df PA |
4553 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
4554 | same breakpoint location. In most targets, this can only be true | |
4555 | if ASPACE1 matches ASPACE2. On targets that have global | |
4556 | breakpoints, the address space doesn't really matter. */ | |
4557 | ||
4558 | static int | |
4559 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
4560 | struct address_space *aspace2, CORE_ADDR addr2) | |
4561 | { | |
4562 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
4563 | || aspace1 == aspace2) | |
4564 | && addr1 == addr2); | |
4565 | } | |
4566 | ||
76897487 KB |
4567 | static void |
4568 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4569 | int bnum, int have_bnum) | |
4570 | { | |
4571 | char astr1[40]; | |
4572 | char astr2[40]; | |
4573 | ||
bb599908 PH |
4574 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4575 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4576 | if (have_bnum) |
8a3fe4f8 | 4577 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4578 | bnum, astr1, astr2); |
4579 | else | |
8a3fe4f8 | 4580 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4581 | } |
4582 | ||
4583 | /* Adjust a breakpoint's address to account for architectural constraints | |
4584 | on breakpoint placement. Return the adjusted address. Note: Very | |
4585 | few targets require this kind of adjustment. For most targets, | |
4586 | this function is simply the identity function. */ | |
4587 | ||
4588 | static CORE_ADDR | |
a6d9a66e UW |
4589 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4590 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4591 | { |
a6d9a66e | 4592 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4593 | { |
4594 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4595 | return bpaddr; | |
4596 | } | |
88f7da05 KB |
4597 | else if (bptype == bp_watchpoint |
4598 | || bptype == bp_hardware_watchpoint | |
4599 | || bptype == bp_read_watchpoint | |
4600 | || bptype == bp_access_watchpoint | |
fe798b75 | 4601 | || bptype == bp_catchpoint) |
88f7da05 KB |
4602 | { |
4603 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4604 | have their addresses modified. */ | |
4605 | return bpaddr; | |
4606 | } | |
76897487 KB |
4607 | else |
4608 | { | |
4609 | CORE_ADDR adjusted_bpaddr; | |
4610 | ||
4611 | /* Some targets have architectural constraints on the placement | |
4612 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4613 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4614 | |
4615 | /* An adjusted breakpoint address can significantly alter | |
4616 | a user's expectations. Print a warning if an adjustment | |
4617 | is required. */ | |
4618 | if (adjusted_bpaddr != bpaddr) | |
4619 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4620 | ||
4621 | return adjusted_bpaddr; | |
4622 | } | |
4623 | } | |
4624 | ||
7cc221ef DJ |
4625 | /* Allocate a struct bp_location. */ |
4626 | ||
26bb91f3 | 4627 | static struct bp_location * |
39d61571 | 4628 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4629 | { |
4630 | struct bp_location *loc, *loc_p; | |
4631 | ||
4632 | loc = xmalloc (sizeof (struct bp_location)); | |
4633 | memset (loc, 0, sizeof (*loc)); | |
4634 | ||
e049a4b5 | 4635 | loc->owner = bpt; |
511a6cd4 | 4636 | loc->cond = NULL; |
0d381245 VP |
4637 | loc->shlib_disabled = 0; |
4638 | loc->enabled = 1; | |
e049a4b5 | 4639 | |
39d61571 | 4640 | switch (bpt->type) |
e049a4b5 DJ |
4641 | { |
4642 | case bp_breakpoint: | |
1042e4c0 | 4643 | case bp_tracepoint: |
e049a4b5 DJ |
4644 | case bp_until: |
4645 | case bp_finish: | |
4646 | case bp_longjmp: | |
4647 | case bp_longjmp_resume: | |
4648 | case bp_step_resume: | |
e049a4b5 DJ |
4649 | case bp_watchpoint_scope: |
4650 | case bp_call_dummy: | |
4651 | case bp_shlib_event: | |
4652 | case bp_thread_event: | |
4653 | case bp_overlay_event: | |
4efc6507 | 4654 | case bp_jit_event: |
0fd8e87f | 4655 | case bp_longjmp_master: |
e049a4b5 DJ |
4656 | loc->loc_type = bp_loc_software_breakpoint; |
4657 | break; | |
4658 | case bp_hardware_breakpoint: | |
4659 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4660 | break; | |
4661 | case bp_hardware_watchpoint: | |
4662 | case bp_read_watchpoint: | |
4663 | case bp_access_watchpoint: | |
4664 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4665 | break; | |
4666 | case bp_watchpoint: | |
ce78b96d | 4667 | case bp_catchpoint: |
e049a4b5 DJ |
4668 | loc->loc_type = bp_loc_other; |
4669 | break; | |
4670 | default: | |
e2e0b3e5 | 4671 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4672 | } |
4673 | ||
7cc221ef DJ |
4674 | return loc; |
4675 | } | |
4676 | ||
fe3f5fa8 VP |
4677 | static void free_bp_location (struct bp_location *loc) |
4678 | { | |
4679 | if (loc->cond) | |
4680 | xfree (loc->cond); | |
74960c60 VP |
4681 | |
4682 | if (loc->function_name) | |
4683 | xfree (loc->function_name); | |
4684 | ||
fe3f5fa8 VP |
4685 | xfree (loc); |
4686 | } | |
4687 | ||
0d381245 VP |
4688 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4689 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4690 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 4691 | |
c40e75cd | 4692 | static struct breakpoint * |
a6d9a66e UW |
4693 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4694 | enum bptype bptype) | |
c906108c | 4695 | { |
52f0bd74 | 4696 | struct breakpoint *b, *b1; |
c906108c SS |
4697 | |
4698 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4699 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4700 | |
4d28f7a8 | 4701 | b->type = bptype; |
a6d9a66e | 4702 | b->gdbarch = gdbarch; |
c906108c SS |
4703 | b->language = current_language->la_language; |
4704 | b->input_radix = input_radix; | |
4705 | b->thread = -1; | |
b5de0fa7 | 4706 | b->enable_state = bp_enabled; |
c906108c SS |
4707 | b->next = 0; |
4708 | b->silent = 0; | |
4709 | b->ignore_count = 0; | |
4710 | b->commands = NULL; | |
818dd999 | 4711 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4712 | b->forked_inferior_pid = null_ptid; |
c906108c | 4713 | b->exec_pathname = NULL; |
a96d9b2e | 4714 | b->syscalls_to_be_caught = NULL; |
3086aeae | 4715 | b->ops = NULL; |
0d381245 | 4716 | b->condition_not_parsed = 0; |
c906108c SS |
4717 | |
4718 | /* Add this breakpoint to the end of the chain | |
4719 | so that a list of breakpoints will come out in order | |
4720 | of increasing numbers. */ | |
4721 | ||
4722 | b1 = breakpoint_chain; | |
4723 | if (b1 == 0) | |
4724 | breakpoint_chain = b; | |
4725 | else | |
4726 | { | |
4727 | while (b1->next) | |
4728 | b1 = b1->next; | |
4729 | b1->next = b; | |
4730 | } | |
0d381245 VP |
4731 | return b; |
4732 | } | |
4733 | ||
4734 | /* Initialize loc->function_name. */ | |
4735 | static void | |
4736 | set_breakpoint_location_function (struct bp_location *loc) | |
4737 | { | |
4738 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4739 | || loc->owner->type == bp_hardware_breakpoint |
4740 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4741 | { |
4742 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4743 | NULL, NULL); | |
4744 | if (loc->function_name) | |
4745 | loc->function_name = xstrdup (loc->function_name); | |
4746 | } | |
4747 | } | |
4748 | ||
a6d9a66e UW |
4749 | /* Attempt to determine architecture of location identified by SAL. */ |
4750 | static struct gdbarch * | |
4751 | get_sal_arch (struct symtab_and_line sal) | |
4752 | { | |
4753 | if (sal.section) | |
4754 | return get_objfile_arch (sal.section->objfile); | |
4755 | if (sal.symtab) | |
4756 | return get_objfile_arch (sal.symtab->objfile); | |
4757 | ||
4758 | return NULL; | |
4759 | } | |
4760 | ||
0d381245 VP |
4761 | /* set_raw_breakpoint is a low level routine for allocating and |
4762 | partially initializing a breakpoint of type BPTYPE. The newly | |
4763 | created breakpoint's address, section, source file name, and line | |
4764 | number are provided by SAL. The newly created and partially | |
4765 | initialized breakpoint is added to the breakpoint chain and | |
4766 | is also returned as the value of this function. | |
4767 | ||
4768 | It is expected that the caller will complete the initialization of | |
4769 | the newly created breakpoint struct as well as output any status | |
4770 | information regarding the creation of a new breakpoint. In | |
4771 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4772 | number! Care should be taken to not allow an error to occur | |
4773 | prior to completing the initialization of the breakpoint. If this | |
4774 | should happen, a bogus breakpoint will be left on the chain. */ | |
4775 | ||
63c252f8 | 4776 | struct breakpoint * |
a6d9a66e UW |
4777 | set_raw_breakpoint (struct gdbarch *gdbarch, |
4778 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4779 | { |
a6d9a66e | 4780 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4781 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4782 | struct gdbarch *loc_gdbarch; |
4783 | ||
4784 | loc_gdbarch = get_sal_arch (sal); | |
4785 | if (!loc_gdbarch) | |
4786 | loc_gdbarch = b->gdbarch; | |
0d381245 | 4787 | |
6c95b8df PA |
4788 | if (bptype != bp_catchpoint) |
4789 | gdb_assert (sal.pspace != NULL); | |
4790 | ||
0d381245 VP |
4791 | /* Adjust the breakpoint's address prior to allocating a location. |
4792 | Once we call allocate_bp_location(), that mostly uninitialized | |
4793 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4794 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4795 | not want its scan of the location chain to find a breakpoint and |
4796 | location that's only been partially initialized. */ | |
a6d9a66e | 4797 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4798 | |
39d61571 | 4799 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4800 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4801 | b->loc->requested_address = sal.pc; |
4802 | b->loc->address = adjusted_address; | |
6c95b8df PA |
4803 | b->loc->pspace = sal.pspace; |
4804 | ||
4805 | /* Store the program space that was used to set the breakpoint, for | |
4806 | breakpoint resetting. */ | |
4807 | b->pspace = sal.pspace; | |
0d381245 VP |
4808 | |
4809 | if (sal.symtab == NULL) | |
4810 | b->source_file = NULL; | |
4811 | else | |
1b36a34b | 4812 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4813 | b->loc->section = sal.section; |
4814 | b->line_number = sal.line; | |
4815 | ||
4816 | set_breakpoint_location_function (b->loc); | |
c906108c | 4817 | |
c906108c SS |
4818 | breakpoints_changed (); |
4819 | ||
4820 | return b; | |
4821 | } | |
4822 | ||
c2c6d25f JM |
4823 | |
4824 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4825 | instruction, hard-wired into the inferior's code. */ | |
4826 | void | |
4827 | make_breakpoint_permanent (struct breakpoint *b) | |
4828 | { | |
0d381245 | 4829 | struct bp_location *bl; |
b5de0fa7 | 4830 | b->enable_state = bp_permanent; |
c2c6d25f | 4831 | |
0d381245 VP |
4832 | /* By definition, permanent breakpoints are already present in the code. |
4833 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4834 | is called in just one place, so it's hard to say if it's reasonable | |
4835 | to have permanent breakpoint with multiple locations or not, | |
4836 | but it's easy to implmement. */ | |
4837 | for (bl = b->loc; bl; bl = bl->next) | |
4838 | bl->inserted = 1; | |
c2c6d25f JM |
4839 | } |
4840 | ||
53a5351d | 4841 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 4842 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
4843 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
4844 | ||
4845 | void | |
0fd8e87f | 4846 | set_longjmp_breakpoint (int thread) |
c906108c | 4847 | { |
0fd8e87f UW |
4848 | struct breakpoint *b, *temp; |
4849 | ||
4850 | /* To avoid having to rescan all objfile symbols at every step, | |
4851 | we maintain a list of continually-inserted but always disabled | |
4852 | longjmp "master" breakpoints. Here, we simply create momentary | |
4853 | clones of those and enable them for the requested thread. */ | |
4854 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4855 | if (b->pspace == current_program_space |
4856 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
4857 | { |
4858 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
4859 | clone->type = bp_longjmp; | |
4860 | clone->thread = thread; | |
4861 | } | |
c906108c SS |
4862 | } |
4863 | ||
611c83ae | 4864 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 4865 | void |
611c83ae | 4866 | delete_longjmp_breakpoint (int thread) |
c906108c | 4867 | { |
611c83ae | 4868 | struct breakpoint *b, *temp; |
c906108c | 4869 | |
611c83ae PA |
4870 | ALL_BREAKPOINTS_SAFE (b, temp) |
4871 | if (b->type == bp_longjmp) | |
4872 | { | |
4873 | if (b->thread == thread) | |
4874 | delete_breakpoint (b); | |
4875 | } | |
c906108c SS |
4876 | } |
4877 | ||
1900040c MS |
4878 | void |
4879 | enable_overlay_breakpoints (void) | |
4880 | { | |
52f0bd74 | 4881 | struct breakpoint *b; |
1900040c MS |
4882 | |
4883 | ALL_BREAKPOINTS (b) | |
4884 | if (b->type == bp_overlay_event) | |
4885 | { | |
4886 | b->enable_state = bp_enabled; | |
b60e7edf | 4887 | update_global_location_list (1); |
c02f5703 | 4888 | overlay_events_enabled = 1; |
1900040c MS |
4889 | } |
4890 | } | |
4891 | ||
4892 | void | |
4893 | disable_overlay_breakpoints (void) | |
4894 | { | |
52f0bd74 | 4895 | struct breakpoint *b; |
1900040c MS |
4896 | |
4897 | ALL_BREAKPOINTS (b) | |
4898 | if (b->type == bp_overlay_event) | |
4899 | { | |
4900 | b->enable_state = bp_disabled; | |
b60e7edf | 4901 | update_global_location_list (0); |
c02f5703 | 4902 | overlay_events_enabled = 0; |
1900040c MS |
4903 | } |
4904 | } | |
4905 | ||
c4093a6a | 4906 | struct breakpoint * |
a6d9a66e | 4907 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
4908 | { |
4909 | struct breakpoint *b; | |
c4093a6a | 4910 | |
a6d9a66e | 4911 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 4912 | |
b5de0fa7 | 4913 | b->enable_state = bp_enabled; |
c4093a6a | 4914 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
4915 | b->addr_string |
4916 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 4917 | |
b60e7edf | 4918 | update_global_location_list_nothrow (1); |
74960c60 | 4919 | |
c4093a6a JM |
4920 | return b; |
4921 | } | |
4922 | ||
4923 | void | |
4924 | remove_thread_event_breakpoints (void) | |
4925 | { | |
4926 | struct breakpoint *b, *temp; | |
4927 | ||
4928 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4929 | if (b->type == bp_thread_event |
4930 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
4931 | delete_breakpoint (b); |
4932 | } | |
4933 | ||
0101ce28 JJ |
4934 | struct captured_parse_breakpoint_args |
4935 | { | |
4936 | char **arg_p; | |
4937 | struct symtabs_and_lines *sals_p; | |
4938 | char ***addr_string_p; | |
4939 | int *not_found_ptr; | |
4940 | }; | |
4941 | ||
4942 | struct lang_and_radix | |
4943 | { | |
4944 | enum language lang; | |
4945 | int radix; | |
4946 | }; | |
4947 | ||
4efc6507 DE |
4948 | /* Create a breakpoint for JIT code registration and unregistration. */ |
4949 | ||
4950 | struct breakpoint * | |
4951 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
4952 | { | |
4953 | struct breakpoint *b; | |
4954 | ||
4955 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
4956 | update_global_location_list_nothrow (1); | |
4957 | return b; | |
4958 | } | |
0101ce28 | 4959 | |
cae688ec JJ |
4960 | void |
4961 | remove_solib_event_breakpoints (void) | |
4962 | { | |
4963 | struct breakpoint *b, *temp; | |
4964 | ||
4965 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
4966 | if (b->type == bp_shlib_event |
4967 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
4968 | delete_breakpoint (b); |
4969 | } | |
4970 | ||
4971 | struct breakpoint * | |
a6d9a66e | 4972 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
4973 | { |
4974 | struct breakpoint *b; | |
4975 | ||
a6d9a66e | 4976 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 4977 | update_global_location_list_nothrow (1); |
cae688ec JJ |
4978 | return b; |
4979 | } | |
4980 | ||
4981 | /* Disable any breakpoints that are on code in shared libraries. Only | |
4982 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
4983 | ||
4984 | void | |
cb851954 | 4985 | disable_breakpoints_in_shlibs (void) |
cae688ec | 4986 | { |
876fa593 | 4987 | struct bp_location *loc, **locp_tmp; |
cae688ec | 4988 | |
876fa593 | 4989 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 4990 | { |
0d381245 VP |
4991 | struct breakpoint *b = loc->owner; |
4992 | /* We apply the check to all breakpoints, including disabled | |
4993 | for those with loc->duplicate set. This is so that when breakpoint | |
4994 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
4995 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
4996 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
4997 | if (((b->type == bp_breakpoint) |
4998 | || (b->type == bp_hardware_breakpoint) | |
4999 | || (b->type == bp_tracepoint)) | |
6c95b8df | 5000 | && loc->pspace == current_program_space |
0d381245 | 5001 | && !loc->shlib_disabled |
a77053c2 | 5002 | #ifdef PC_SOLIB |
0d381245 | 5003 | && PC_SOLIB (loc->address) |
a77053c2 | 5004 | #else |
6c95b8df | 5005 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5006 | #endif |
5007 | ) | |
0d381245 VP |
5008 | { |
5009 | loc->shlib_disabled = 1; | |
5010 | } | |
cae688ec JJ |
5011 | } |
5012 | } | |
5013 | ||
84acb35a JJ |
5014 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5015 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5016 | ||
75149521 | 5017 | static void |
84acb35a JJ |
5018 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5019 | { | |
876fa593 | 5020 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5021 | int disabled_shlib_breaks = 0; |
5022 | ||
c86cf029 VP |
5023 | /* SunOS a.out shared libraries are always mapped, so do not |
5024 | disable breakpoints; they will only be reported as unloaded | |
5025 | through clear_solib when GDB discards its shared library | |
5026 | list. See clear_solib for more information. */ | |
5027 | if (exec_bfd != NULL | |
5028 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5029 | return; | |
5030 | ||
876fa593 | 5031 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5032 | { |
0d381245 VP |
5033 | struct breakpoint *b = loc->owner; |
5034 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5035 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5036 | && solib->pspace == loc->pspace |
e2dd7057 PP |
5037 | && !loc->shlib_disabled |
5038 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
5039 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 5040 | { |
e2dd7057 PP |
5041 | loc->shlib_disabled = 1; |
5042 | /* At this point, we cannot rely on remove_breakpoint | |
5043 | succeeding so we must mark the breakpoint as not inserted | |
5044 | to prevent future errors occurring in remove_breakpoints. */ | |
5045 | loc->inserted = 0; | |
5046 | if (!disabled_shlib_breaks) | |
5047 | { | |
5048 | target_terminal_ours_for_output (); | |
5049 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5050 | solib->so_name); | |
84acb35a | 5051 | } |
e2dd7057 | 5052 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5053 | } |
5054 | } | |
84acb35a JJ |
5055 | } |
5056 | ||
ce78b96d JB |
5057 | /* FORK & VFORK catchpoints. */ |
5058 | ||
5059 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5060 | ||
c906108c | 5061 | static void |
ce78b96d JB |
5062 | insert_catch_fork (struct breakpoint *b) |
5063 | { | |
5064 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5065 | } | |
5066 | ||
5067 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5068 | ||
5069 | static int | |
5070 | remove_catch_fork (struct breakpoint *b) | |
5071 | { | |
5072 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5073 | } | |
5074 | ||
5075 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5076 | catchpoints. */ | |
5077 | ||
5078 | static int | |
5079 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5080 | { | |
5081 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5082 | } | |
5083 | ||
5084 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5085 | ||
5086 | static enum print_stop_action | |
5087 | print_it_catch_fork (struct breakpoint *b) | |
5088 | { | |
5089 | annotate_catchpoint (b->number); | |
5090 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5091 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5092 | return PRINT_SRC_AND_LOC; | |
5093 | } | |
5094 | ||
5095 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5096 | ||
5097 | static void | |
a6d9a66e | 5098 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5099 | { |
79a45b7d TT |
5100 | struct value_print_options opts; |
5101 | ||
5102 | get_user_print_options (&opts); | |
5103 | ||
ce78b96d JB |
5104 | /* Field 4, the address, is omitted (which makes the columns |
5105 | not line up too nicely with the headers, but the effect | |
5106 | is relatively readable). */ | |
79a45b7d | 5107 | if (opts.addressprint) |
ce78b96d JB |
5108 | ui_out_field_skip (uiout, "addr"); |
5109 | annotate_field (5); | |
5110 | ui_out_text (uiout, "fork"); | |
5111 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5112 | { | |
5113 | ui_out_text (uiout, ", process "); | |
5114 | ui_out_field_int (uiout, "what", | |
5115 | ptid_get_pid (b->forked_inferior_pid)); | |
5116 | ui_out_spaces (uiout, 1); | |
5117 | } | |
5118 | } | |
5119 | ||
5120 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5121 | catchpoints. */ | |
5122 | ||
5123 | static void | |
5124 | print_mention_catch_fork (struct breakpoint *b) | |
5125 | { | |
5126 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5127 | } | |
5128 | ||
5129 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5130 | ||
5131 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5132 | { | |
5133 | insert_catch_fork, | |
5134 | remove_catch_fork, | |
5135 | breakpoint_hit_catch_fork, | |
5136 | print_it_catch_fork, | |
5137 | print_one_catch_fork, | |
5138 | print_mention_catch_fork | |
5139 | }; | |
5140 | ||
5141 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5142 | ||
5143 | static void | |
5144 | insert_catch_vfork (struct breakpoint *b) | |
5145 | { | |
5146 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5147 | } | |
5148 | ||
5149 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5150 | ||
5151 | static int | |
5152 | remove_catch_vfork (struct breakpoint *b) | |
5153 | { | |
5154 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5155 | } | |
5156 | ||
5157 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5158 | catchpoints. */ | |
5159 | ||
5160 | static int | |
5161 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5162 | { | |
5163 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5164 | } | |
5165 | ||
5166 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5167 | ||
5168 | static enum print_stop_action | |
5169 | print_it_catch_vfork (struct breakpoint *b) | |
5170 | { | |
5171 | annotate_catchpoint (b->number); | |
5172 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5173 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5174 | return PRINT_SRC_AND_LOC; | |
5175 | } | |
5176 | ||
5177 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5178 | ||
5179 | static void | |
a6d9a66e | 5180 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5181 | { |
79a45b7d TT |
5182 | struct value_print_options opts; |
5183 | ||
5184 | get_user_print_options (&opts); | |
ce78b96d JB |
5185 | /* Field 4, the address, is omitted (which makes the columns |
5186 | not line up too nicely with the headers, but the effect | |
5187 | is relatively readable). */ | |
79a45b7d | 5188 | if (opts.addressprint) |
ce78b96d JB |
5189 | ui_out_field_skip (uiout, "addr"); |
5190 | annotate_field (5); | |
5191 | ui_out_text (uiout, "vfork"); | |
5192 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5193 | { | |
5194 | ui_out_text (uiout, ", process "); | |
5195 | ui_out_field_int (uiout, "what", | |
5196 | ptid_get_pid (b->forked_inferior_pid)); | |
5197 | ui_out_spaces (uiout, 1); | |
5198 | } | |
5199 | } | |
5200 | ||
5201 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5202 | catchpoints. */ | |
5203 | ||
5204 | static void | |
5205 | print_mention_catch_vfork (struct breakpoint *b) | |
5206 | { | |
5207 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5208 | } | |
5209 | ||
5210 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5211 | ||
5212 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5213 | { | |
5214 | insert_catch_vfork, | |
5215 | remove_catch_vfork, | |
5216 | breakpoint_hit_catch_vfork, | |
5217 | print_it_catch_vfork, | |
5218 | print_one_catch_vfork, | |
5219 | print_mention_catch_vfork | |
5220 | }; | |
5221 | ||
a96d9b2e SDJ |
5222 | /* Implement the "insert" breakpoint_ops method for syscall |
5223 | catchpoints. */ | |
5224 | ||
5225 | static void | |
5226 | insert_catch_syscall (struct breakpoint *b) | |
5227 | { | |
5228 | struct inferior *inf = current_inferior (); | |
5229 | ||
5230 | ++inf->total_syscalls_count; | |
5231 | if (!b->syscalls_to_be_caught) | |
5232 | ++inf->any_syscall_count; | |
5233 | else | |
5234 | { | |
5235 | int i, iter; | |
5236 | for (i = 0; | |
5237 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5238 | i++) | |
5239 | { | |
5240 | int elem; | |
5241 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5242 | { | |
5243 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5244 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5245 | uintptr_t vec_addr; | |
5246 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5247 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5248 | vec_addr_offset; | |
5249 | memset ((void *) vec_addr, 0, | |
5250 | (iter + 1 - old_size) * sizeof (int)); | |
5251 | } | |
5252 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5253 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5254 | } | |
5255 | } | |
5256 | ||
5257 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5258 | inf->total_syscalls_count != 0, | |
5259 | inf->any_syscall_count, | |
5260 | VEC_length (int, inf->syscalls_counts), | |
5261 | VEC_address (int, inf->syscalls_counts)); | |
5262 | } | |
5263 | ||
5264 | /* Implement the "remove" breakpoint_ops method for syscall | |
5265 | catchpoints. */ | |
5266 | ||
5267 | static int | |
5268 | remove_catch_syscall (struct breakpoint *b) | |
5269 | { | |
5270 | struct inferior *inf = current_inferior (); | |
5271 | ||
5272 | --inf->total_syscalls_count; | |
5273 | if (!b->syscalls_to_be_caught) | |
5274 | --inf->any_syscall_count; | |
5275 | else | |
5276 | { | |
5277 | int i, iter; | |
5278 | for (i = 0; | |
5279 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5280 | i++) | |
5281 | { | |
5282 | int elem; | |
5283 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5284 | /* Shouldn't happen. */ | |
5285 | continue; | |
5286 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5287 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5288 | } | |
5289 | } | |
5290 | ||
5291 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5292 | inf->total_syscalls_count != 0, | |
5293 | inf->any_syscall_count, | |
5294 | VEC_length (int, inf->syscalls_counts), | |
5295 | VEC_address (int, inf->syscalls_counts)); | |
5296 | } | |
5297 | ||
5298 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5299 | catchpoints. */ | |
5300 | ||
5301 | static int | |
5302 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5303 | { | |
5304 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5305 | If we are, then we must guarantee that the called syscall is the same | |
5306 | syscall we are catching. */ | |
5307 | int syscall_number = 0; | |
5308 | ||
5309 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5310 | return 0; | |
5311 | ||
5312 | /* Now, checking if the syscall is the same. */ | |
5313 | if (b->syscalls_to_be_caught) | |
5314 | { | |
5315 | int i, iter; | |
5316 | for (i = 0; | |
5317 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5318 | i++) | |
5319 | if (syscall_number == iter) | |
5320 | break; | |
5321 | /* Not the same. */ | |
5322 | if (!iter) | |
5323 | return 0; | |
5324 | } | |
5325 | ||
5326 | return 1; | |
5327 | } | |
5328 | ||
5329 | /* Implement the "print_it" breakpoint_ops method for syscall | |
5330 | catchpoints. */ | |
5331 | ||
5332 | static enum print_stop_action | |
5333 | print_it_catch_syscall (struct breakpoint *b) | |
5334 | { | |
5335 | /* These are needed because we want to know in which state a | |
5336 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
5337 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
5338 | must print "called syscall" or "returned from syscall". */ | |
5339 | ptid_t ptid; | |
5340 | struct target_waitstatus last; | |
5341 | struct syscall s; | |
5342 | struct cleanup *old_chain; | |
5343 | char *syscall_id; | |
5344 | ||
5345 | get_last_target_status (&ptid, &last); | |
5346 | ||
5347 | get_syscall_by_number (last.value.syscall_number, &s); | |
5348 | ||
5349 | annotate_catchpoint (b->number); | |
5350 | ||
5351 | if (s.name == NULL) | |
5352 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
5353 | else | |
5354 | syscall_id = xstrprintf ("'%s'", s.name); | |
5355 | ||
5356 | old_chain = make_cleanup (xfree, syscall_id); | |
5357 | ||
5358 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
5359 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
5360 | b->number, syscall_id); | |
5361 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
5362 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
5363 | b->number, syscall_id); | |
5364 | ||
5365 | do_cleanups (old_chain); | |
5366 | ||
5367 | return PRINT_SRC_AND_LOC; | |
5368 | } | |
5369 | ||
5370 | /* Implement the "print_one" breakpoint_ops method for syscall | |
5371 | catchpoints. */ | |
5372 | ||
5373 | static void | |
5374 | print_one_catch_syscall (struct breakpoint *b, | |
5375 | struct bp_location **last_loc) | |
5376 | { | |
5377 | struct value_print_options opts; | |
5378 | ||
5379 | get_user_print_options (&opts); | |
5380 | /* Field 4, the address, is omitted (which makes the columns | |
5381 | not line up too nicely with the headers, but the effect | |
5382 | is relatively readable). */ | |
5383 | if (opts.addressprint) | |
5384 | ui_out_field_skip (uiout, "addr"); | |
5385 | annotate_field (5); | |
5386 | ||
5387 | if (b->syscalls_to_be_caught | |
5388 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5389 | ui_out_text (uiout, "syscalls \""); | |
5390 | else | |
5391 | ui_out_text (uiout, "syscall \""); | |
5392 | ||
5393 | if (b->syscalls_to_be_caught) | |
5394 | { | |
5395 | int i, iter; | |
5396 | char *text = xstrprintf ("%s", ""); | |
5397 | for (i = 0; | |
5398 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5399 | i++) | |
5400 | { | |
5401 | char *x = text; | |
5402 | struct syscall s; | |
5403 | get_syscall_by_number (iter, &s); | |
5404 | ||
5405 | if (s.name != NULL) | |
5406 | text = xstrprintf ("%s%s, ", text, s.name); | |
5407 | else | |
5408 | text = xstrprintf ("%s%d, ", text, iter); | |
5409 | ||
5410 | /* We have to xfree the last 'text' (now stored at 'x') | |
5411 | because xstrprintf dinamically allocates new space for it | |
5412 | on every call. */ | |
5413 | xfree (x); | |
5414 | } | |
5415 | /* Remove the last comma. */ | |
5416 | text[strlen (text) - 2] = '\0'; | |
5417 | ui_out_field_string (uiout, "what", text); | |
5418 | } | |
5419 | else | |
5420 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
5421 | ui_out_text (uiout, "\" "); | |
5422 | } | |
5423 | ||
5424 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
5425 | catchpoints. */ | |
5426 | ||
5427 | static void | |
5428 | print_mention_catch_syscall (struct breakpoint *b) | |
5429 | { | |
5430 | if (b->syscalls_to_be_caught) | |
5431 | { | |
5432 | int i, iter; | |
5433 | ||
5434 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5435 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
5436 | else | |
5437 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
5438 | ||
5439 | for (i = 0; | |
5440 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5441 | i++) | |
5442 | { | |
5443 | struct syscall s; | |
5444 | get_syscall_by_number (iter, &s); | |
5445 | ||
5446 | if (s.name) | |
5447 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
5448 | else | |
5449 | printf_filtered (" %d", s.number); | |
5450 | } | |
5451 | printf_filtered (")"); | |
5452 | } | |
5453 | else | |
5454 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
5455 | b->number); | |
5456 | } | |
5457 | ||
5458 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
5459 | ||
5460 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
5461 | { | |
5462 | insert_catch_syscall, | |
5463 | remove_catch_syscall, | |
5464 | breakpoint_hit_catch_syscall, | |
5465 | print_it_catch_syscall, | |
5466 | print_one_catch_syscall, | |
5467 | print_mention_catch_syscall | |
5468 | }; | |
5469 | ||
5470 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
5471 | ||
5472 | static int | |
5473 | syscall_catchpoint_p (struct breakpoint *b) | |
5474 | { | |
5475 | return (b->ops == &catch_syscall_breakpoint_ops); | |
5476 | } | |
5477 | ||
5478 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
5479 | but does NOT mention it nor update the global location list. | |
5480 | This is useful if you need to fill more fields in the | |
5481 | struct breakpoint before calling mention. | |
ce78b96d JB |
5482 | |
5483 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5484 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5485 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5486 | to the catchpoint. */ | |
5487 | ||
5488 | static struct breakpoint * | |
a96d9b2e SDJ |
5489 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
5490 | char *cond_string, | |
5491 | struct breakpoint_ops *ops) | |
c906108c | 5492 | { |
c5aa993b JM |
5493 | struct symtab_and_line sal; |
5494 | struct breakpoint *b; | |
c5aa993b | 5495 | |
fe39c653 | 5496 | init_sal (&sal); |
6c95b8df | 5497 | sal.pspace = current_program_space; |
c5aa993b | 5498 | |
a6d9a66e | 5499 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
5500 | set_breakpoint_count (breakpoint_count + 1); |
5501 | b->number = breakpoint_count; | |
ce78b96d | 5502 | |
1b36a34b | 5503 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 5504 | b->thread = -1; |
c906108c | 5505 | b->addr_string = NULL; |
b5de0fa7 EZ |
5506 | b->enable_state = bp_enabled; |
5507 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 5508 | b->ops = ops; |
c5aa993b | 5509 | |
a96d9b2e SDJ |
5510 | return b; |
5511 | } | |
5512 | ||
5513 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
5514 | ||
5515 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5516 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5517 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5518 | to the catchpoint. */ | |
5519 | ||
5520 | static struct breakpoint * | |
5521 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
5522 | char *cond_string, struct breakpoint_ops *ops) | |
5523 | { | |
5524 | struct breakpoint *b = | |
5525 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
5526 | ||
c906108c | 5527 | mention (b); |
ce78b96d | 5528 | update_global_location_list (1); |
c906108c | 5529 | |
ce78b96d | 5530 | return b; |
c906108c | 5531 | } |
c5aa993b | 5532 | |
9b70b993 | 5533 | static void |
a6d9a66e UW |
5534 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
5535 | int tempflag, char *cond_string, | |
ce78b96d | 5536 | struct breakpoint_ops *ops) |
c906108c | 5537 | { |
a6d9a66e UW |
5538 | struct breakpoint *b |
5539 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
5540 | |
5541 | /* FIXME: We should put this information in a breakpoint private data | |
5542 | area. */ | |
5543 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
5544 | } |
5545 | ||
fe798b75 JB |
5546 | /* Exec catchpoints. */ |
5547 | ||
9b70b993 | 5548 | static void |
fe798b75 | 5549 | insert_catch_exec (struct breakpoint *b) |
c906108c | 5550 | { |
fe798b75 JB |
5551 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
5552 | } | |
c906108c | 5553 | |
fe798b75 JB |
5554 | static int |
5555 | remove_catch_exec (struct breakpoint *b) | |
5556 | { | |
5557 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
5558 | } | |
c906108c | 5559 | |
fe798b75 JB |
5560 | static int |
5561 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
5562 | { | |
5563 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
5564 | } | |
c906108c | 5565 | |
fe798b75 JB |
5566 | static enum print_stop_action |
5567 | print_it_catch_exec (struct breakpoint *b) | |
5568 | { | |
5569 | annotate_catchpoint (b->number); | |
5570 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
5571 | b->exec_pathname); | |
5572 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
5573 | } |
5574 | ||
fe798b75 | 5575 | static void |
a6d9a66e | 5576 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
5577 | { |
5578 | struct value_print_options opts; | |
5579 | ||
5580 | get_user_print_options (&opts); | |
5581 | ||
5582 | /* Field 4, the address, is omitted (which makes the columns | |
5583 | not line up too nicely with the headers, but the effect | |
5584 | is relatively readable). */ | |
5585 | if (opts.addressprint) | |
5586 | ui_out_field_skip (uiout, "addr"); | |
5587 | annotate_field (5); | |
5588 | ui_out_text (uiout, "exec"); | |
5589 | if (b->exec_pathname != NULL) | |
5590 | { | |
5591 | ui_out_text (uiout, ", program \""); | |
5592 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5593 | ui_out_text (uiout, "\" "); | |
5594 | } | |
5595 | } | |
5596 | ||
5597 | static void | |
5598 | print_mention_catch_exec (struct breakpoint *b) | |
5599 | { | |
5600 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5601 | } | |
5602 | ||
5603 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5604 | { | |
5605 | insert_catch_exec, | |
5606 | remove_catch_exec, | |
5607 | breakpoint_hit_catch_exec, | |
5608 | print_it_catch_exec, | |
5609 | print_one_catch_exec, | |
5610 | print_mention_catch_exec | |
5611 | }; | |
5612 | ||
a96d9b2e SDJ |
5613 | static void |
5614 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
5615 | struct breakpoint_ops *ops) | |
5616 | { | |
5617 | struct gdbarch *gdbarch = get_current_arch (); | |
5618 | struct breakpoint *b = | |
5619 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
5620 | ||
5621 | b->syscalls_to_be_caught = filter; | |
5622 | ||
5623 | /* Now, we have to mention the breakpoint and update the global | |
5624 | location list. */ | |
5625 | mention (b); | |
5626 | update_global_location_list (1); | |
5627 | } | |
5628 | ||
c906108c | 5629 | static int |
fba45db2 | 5630 | hw_breakpoint_used_count (void) |
c906108c | 5631 | { |
52f0bd74 | 5632 | struct breakpoint *b; |
c906108c SS |
5633 | int i = 0; |
5634 | ||
5635 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5636 | { |
d6b74ac4 | 5637 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5638 | i++; |
5639 | } | |
c906108c SS |
5640 | |
5641 | return i; | |
5642 | } | |
5643 | ||
5644 | static int | |
fba45db2 | 5645 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5646 | { |
52f0bd74 | 5647 | struct breakpoint *b; |
c906108c SS |
5648 | int i = 0; |
5649 | ||
5650 | *other_type_used = 0; | |
5651 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5652 | { |
468d015d | 5653 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5654 | { |
5655 | if (b->type == type) | |
5656 | i++; | |
059fb39f PM |
5657 | else if ((b->type == bp_hardware_watchpoint |
5658 | || b->type == bp_read_watchpoint | |
5659 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5660 | *other_type_used = 1; |
5661 | } | |
5662 | } | |
c906108c SS |
5663 | return i; |
5664 | } | |
5665 | ||
c906108c | 5666 | void |
fba45db2 | 5667 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5668 | { |
c5aa993b | 5669 | struct breakpoint *b; |
c906108c SS |
5670 | |
5671 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5672 | { |
5673 | if (((b->type == bp_watchpoint) | |
5674 | || (b->type == bp_hardware_watchpoint) | |
5675 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5676 | || (b->type == bp_access_watchpoint)) |
468d015d | 5677 | && breakpoint_enabled (b)) |
c5aa993b | 5678 | { |
b5de0fa7 | 5679 | b->enable_state = bp_call_disabled; |
b60e7edf | 5680 | update_global_location_list (0); |
c5aa993b JM |
5681 | } |
5682 | } | |
c906108c SS |
5683 | } |
5684 | ||
5685 | void | |
fba45db2 | 5686 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5687 | { |
c5aa993b | 5688 | struct breakpoint *b; |
c906108c SS |
5689 | |
5690 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5691 | { |
5692 | if (((b->type == bp_watchpoint) | |
5693 | || (b->type == bp_hardware_watchpoint) | |
5694 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5695 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5696 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5697 | { |
b5de0fa7 | 5698 | b->enable_state = bp_enabled; |
b60e7edf | 5699 | update_global_location_list (1); |
c5aa993b JM |
5700 | } |
5701 | } | |
c906108c SS |
5702 | } |
5703 | ||
8bea4e01 UW |
5704 | void |
5705 | disable_breakpoints_before_startup (void) | |
5706 | { | |
5707 | struct breakpoint *b; | |
5708 | int found = 0; | |
5709 | ||
5710 | ALL_BREAKPOINTS (b) | |
5711 | { | |
6c95b8df PA |
5712 | if (b->pspace != current_program_space) |
5713 | continue; | |
5714 | ||
8bea4e01 UW |
5715 | if ((b->type == bp_breakpoint |
5716 | || b->type == bp_hardware_breakpoint) | |
5717 | && breakpoint_enabled (b)) | |
5718 | { | |
5719 | b->enable_state = bp_startup_disabled; | |
5720 | found = 1; | |
5721 | } | |
5722 | } | |
5723 | ||
5724 | if (found) | |
5725 | update_global_location_list (0); | |
5726 | ||
6c95b8df | 5727 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
5728 | } |
5729 | ||
5730 | void | |
5731 | enable_breakpoints_after_startup (void) | |
5732 | { | |
5733 | struct breakpoint *b; | |
5734 | int found = 0; | |
5735 | ||
6c95b8df | 5736 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
5737 | |
5738 | ALL_BREAKPOINTS (b) | |
5739 | { | |
6c95b8df PA |
5740 | if (b->pspace != current_program_space) |
5741 | continue; | |
5742 | ||
8bea4e01 UW |
5743 | if ((b->type == bp_breakpoint |
5744 | || b->type == bp_hardware_breakpoint) | |
5745 | && b->enable_state == bp_startup_disabled) | |
5746 | { | |
5747 | b->enable_state = bp_enabled; | |
5748 | found = 1; | |
5749 | } | |
5750 | } | |
5751 | ||
5752 | if (found) | |
5753 | breakpoint_re_set (); | |
5754 | } | |
5755 | ||
c906108c SS |
5756 | |
5757 | /* Set a breakpoint that will evaporate an end of command | |
5758 | at address specified by SAL. | |
5759 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5760 | ||
5761 | struct breakpoint * | |
a6d9a66e UW |
5762 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5763 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5764 | { |
52f0bd74 | 5765 | struct breakpoint *b; |
edb3359d DJ |
5766 | |
5767 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5768 | one. */ | |
5769 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5770 | ||
a6d9a66e | 5771 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5772 | b->enable_state = bp_enabled; |
5773 | b->disposition = disp_donttouch; | |
818dd999 | 5774 | b->frame_id = frame_id; |
c906108c SS |
5775 | |
5776 | /* If we're debugging a multi-threaded program, then we | |
5777 | want momentary breakpoints to be active in only a | |
5778 | single thread of control. */ | |
39f77062 KB |
5779 | if (in_thread_list (inferior_ptid)) |
5780 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5781 | |
b60e7edf | 5782 | update_global_location_list_nothrow (1); |
74960c60 | 5783 | |
c906108c SS |
5784 | return b; |
5785 | } | |
611c83ae | 5786 | |
e58b0e63 PA |
5787 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5788 | ORIG is NULL. */ | |
5789 | ||
5790 | struct breakpoint * | |
5791 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5792 | { | |
5793 | struct breakpoint *copy; | |
5794 | ||
5795 | /* If there's nothing to clone, then return nothing. */ | |
5796 | if (orig == NULL) | |
5797 | return NULL; | |
5798 | ||
a6d9a66e | 5799 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5800 | copy->loc = allocate_bp_location (copy); |
5801 | set_breakpoint_location_function (copy->loc); | |
5802 | ||
a6d9a66e | 5803 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5804 | copy->loc->requested_address = orig->loc->requested_address; |
5805 | copy->loc->address = orig->loc->address; | |
5806 | copy->loc->section = orig->loc->section; | |
6c95b8df | 5807 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
5808 | |
5809 | if (orig->source_file == NULL) | |
5810 | copy->source_file = NULL; | |
5811 | else | |
5812 | copy->source_file = xstrdup (orig->source_file); | |
5813 | ||
5814 | copy->line_number = orig->line_number; | |
5815 | copy->frame_id = orig->frame_id; | |
5816 | copy->thread = orig->thread; | |
6c95b8df | 5817 | copy->pspace = orig->pspace; |
e58b0e63 PA |
5818 | |
5819 | copy->enable_state = bp_enabled; | |
5820 | copy->disposition = disp_donttouch; | |
5821 | copy->number = internal_breakpoint_number--; | |
5822 | ||
5823 | update_global_location_list_nothrow (0); | |
5824 | return copy; | |
5825 | } | |
5826 | ||
611c83ae | 5827 | struct breakpoint * |
a6d9a66e UW |
5828 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5829 | enum bptype type) | |
611c83ae PA |
5830 | { |
5831 | struct symtab_and_line sal; | |
5832 | ||
5833 | sal = find_pc_line (pc, 0); | |
5834 | sal.pc = pc; | |
5835 | sal.section = find_pc_overlay (pc); | |
5836 | sal.explicit_pc = 1; | |
5837 | ||
a6d9a66e | 5838 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 5839 | } |
c906108c | 5840 | \f |
c5aa993b | 5841 | |
c906108c SS |
5842 | /* Tell the user we have just set a breakpoint B. */ |
5843 | ||
5844 | static void | |
fba45db2 | 5845 | mention (struct breakpoint *b) |
c906108c SS |
5846 | { |
5847 | int say_where = 0; | |
fa8a61dc | 5848 | struct cleanup *ui_out_chain; |
79a45b7d TT |
5849 | struct value_print_options opts; |
5850 | ||
5851 | get_user_print_options (&opts); | |
8b93c638 | 5852 | |
9a4105ab AC |
5853 | /* FIXME: This is misplaced; mention() is called by things (like |
5854 | hitting a watchpoint) other than breakpoint creation. It should | |
5855 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 5856 | random calls to breakpoint_changed with this hook. */ |
383f836e | 5857 | observer_notify_breakpoint_created (b->number); |
c906108c | 5858 | |
3086aeae DJ |
5859 | if (b->ops != NULL && b->ops->print_mention != NULL) |
5860 | b->ops->print_mention (b); | |
5861 | else | |
5862 | switch (b->type) | |
5863 | { | |
5864 | case bp_none: | |
a3f17187 | 5865 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
5866 | break; |
5867 | case bp_watchpoint: | |
5868 | ui_out_text (uiout, "Watchpoint "); | |
5869 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5870 | ui_out_field_int (uiout, "number", b->number); | |
5871 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5872 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5873 | do_cleanups (ui_out_chain); |
5874 | break; | |
5875 | case bp_hardware_watchpoint: | |
5876 | ui_out_text (uiout, "Hardware watchpoint "); | |
5877 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
5878 | ui_out_field_int (uiout, "number", b->number); | |
5879 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5880 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5881 | do_cleanups (ui_out_chain); |
5882 | break; | |
5883 | case bp_read_watchpoint: | |
5884 | ui_out_text (uiout, "Hardware read watchpoint "); | |
5885 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
5886 | ui_out_field_int (uiout, "number", b->number); | |
5887 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5888 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5889 | do_cleanups (ui_out_chain); |
5890 | break; | |
5891 | case bp_access_watchpoint: | |
5892 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
5893 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
5894 | ui_out_field_int (uiout, "number", b->number); | |
5895 | ui_out_text (uiout, ": "); | |
fa8a61dc | 5896 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
5897 | do_cleanups (ui_out_chain); |
5898 | break; | |
5899 | case bp_breakpoint: | |
5900 | if (ui_out_is_mi_like_p (uiout)) | |
5901 | { | |
5902 | say_where = 0; | |
5903 | break; | |
5904 | } | |
2cec12e5 AR |
5905 | if (b->disposition == disp_del) |
5906 | printf_filtered (_("Temporary breakpoint")); | |
5907 | else | |
5908 | printf_filtered (_("Breakpoint")); | |
5909 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
5910 | say_where = 1; |
5911 | break; | |
5912 | case bp_hardware_breakpoint: | |
5913 | if (ui_out_is_mi_like_p (uiout)) | |
5914 | { | |
5915 | say_where = 0; | |
5916 | break; | |
5917 | } | |
a3f17187 | 5918 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
5919 | say_where = 1; |
5920 | break; | |
1042e4c0 SS |
5921 | case bp_tracepoint: |
5922 | if (ui_out_is_mi_like_p (uiout)) | |
5923 | { | |
5924 | say_where = 0; | |
5925 | break; | |
5926 | } | |
5927 | printf_filtered (_("Tracepoint")); | |
5928 | printf_filtered (_(" %d"), b->number); | |
5929 | say_where = 1; | |
5930 | break; | |
3086aeae DJ |
5931 | |
5932 | case bp_until: | |
5933 | case bp_finish: | |
5934 | case bp_longjmp: | |
5935 | case bp_longjmp_resume: | |
5936 | case bp_step_resume: | |
3086aeae DJ |
5937 | case bp_call_dummy: |
5938 | case bp_watchpoint_scope: | |
5939 | case bp_shlib_event: | |
5940 | case bp_thread_event: | |
5941 | case bp_overlay_event: | |
4efc6507 | 5942 | case bp_jit_event: |
0fd8e87f | 5943 | case bp_longjmp_master: |
3086aeae DJ |
5944 | break; |
5945 | } | |
c906108c | 5946 | |
c906108c SS |
5947 | if (say_where) |
5948 | { | |
a3f17187 AC |
5949 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
5950 | single string. */ | |
0d381245 | 5951 | if (b->loc == NULL) |
c906108c | 5952 | { |
a3f17187 | 5953 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
5954 | } |
5955 | else | |
5956 | { | |
79a45b7d | 5957 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
5958 | { |
5959 | printf_filtered (" at "); | |
5af949e3 UW |
5960 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
5961 | gdb_stdout); | |
0101ce28 JJ |
5962 | } |
5963 | if (b->source_file) | |
5964 | printf_filtered (": file %s, line %d.", | |
5965 | b->source_file, b->line_number); | |
0d381245 VP |
5966 | |
5967 | if (b->loc->next) | |
5968 | { | |
5969 | struct bp_location *loc = b->loc; | |
5970 | int n = 0; | |
5971 | for (; loc; loc = loc->next) | |
5972 | ++n; | |
5973 | printf_filtered (" (%d locations)", n); | |
5974 | } | |
5975 | ||
c906108c | 5976 | } |
c906108c | 5977 | } |
9dc5e2a9 | 5978 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 5979 | return; |
c906108c SS |
5980 | printf_filtered ("\n"); |
5981 | } | |
c906108c | 5982 | \f |
c5aa993b | 5983 | |
0d381245 | 5984 | static struct bp_location * |
39d61571 | 5985 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
5986 | const struct symtab_and_line *sal) |
5987 | { | |
5988 | struct bp_location *loc, **tmp; | |
5989 | ||
39d61571 | 5990 | loc = allocate_bp_location (b); |
0d381245 VP |
5991 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
5992 | ; | |
5993 | *tmp = loc; | |
a6d9a66e UW |
5994 | loc->gdbarch = get_sal_arch (*sal); |
5995 | if (!loc->gdbarch) | |
5996 | loc->gdbarch = b->gdbarch; | |
0d381245 | 5997 | loc->requested_address = sal->pc; |
a6d9a66e UW |
5998 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
5999 | loc->requested_address, b->type); | |
6c95b8df PA |
6000 | loc->pspace = sal->pspace; |
6001 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6002 | loc->section = sal->section; |
6003 | ||
6004 | set_breakpoint_location_function (loc); | |
6005 | return loc; | |
6006 | } | |
514f746b AR |
6007 | \f |
6008 | ||
6009 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6010 | return 0 otherwise. */ | |
6011 | ||
6012 | static int | |
6013 | bp_loc_is_permanent (struct bp_location *loc) | |
6014 | { | |
6015 | int len; | |
6016 | CORE_ADDR addr; | |
6017 | const gdb_byte *brk; | |
6018 | gdb_byte *target_mem; | |
939c61fa JK |
6019 | struct cleanup *cleanup; |
6020 | int retval = 0; | |
514f746b AR |
6021 | |
6022 | gdb_assert (loc != NULL); | |
6023 | ||
6024 | addr = loc->address; | |
a6d9a66e | 6025 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6026 | |
939c61fa JK |
6027 | /* Software breakpoints unsupported? */ |
6028 | if (brk == NULL) | |
6029 | return 0; | |
6030 | ||
514f746b AR |
6031 | target_mem = alloca (len); |
6032 | ||
939c61fa JK |
6033 | /* Enable the automatic memory restoration from breakpoints while |
6034 | we read the memory. Otherwise we could say about our temporary | |
6035 | breakpoints they are permanent. */ | |
6c95b8df PA |
6036 | cleanup = save_current_space_and_thread (); |
6037 | ||
6038 | switch_to_program_space_and_thread (loc->pspace); | |
6039 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6040 | |
514f746b AR |
6041 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6042 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6043 | retval = 1; |
514f746b | 6044 | |
939c61fa JK |
6045 | do_cleanups (cleanup); |
6046 | ||
6047 | return retval; | |
514f746b AR |
6048 | } |
6049 | ||
6050 | ||
c3f6f71d | 6051 | |
018d34a4 VP |
6052 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6053 | as textual description of the location, and COND_STRING | |
db107f19 | 6054 | as condition expression. */ |
018d34a4 VP |
6055 | |
6056 | static void | |
a6d9a66e UW |
6057 | create_breakpoint (struct gdbarch *gdbarch, |
6058 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
6059 | char *cond_string, |
6060 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 6061 | int thread, int task, int ignore_count, |
41447f92 | 6062 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 6063 | { |
0d381245 VP |
6064 | struct breakpoint *b = NULL; |
6065 | int i; | |
018d34a4 VP |
6066 | |
6067 | if (type == bp_hardware_breakpoint) | |
6068 | { | |
6069 | int i = hw_breakpoint_used_count (); | |
6070 | int target_resources_ok = | |
d92524f1 | 6071 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6072 | i + 1, 0); |
6073 | if (target_resources_ok == 0) | |
6074 | error (_("No hardware breakpoint support in the target.")); | |
6075 | else if (target_resources_ok < 0) | |
6076 | error (_("Hardware breakpoints used exceeds limit.")); | |
6077 | } | |
6078 | ||
6c95b8df PA |
6079 | gdb_assert (sals.nelts > 0); |
6080 | ||
0d381245 VP |
6081 | for (i = 0; i < sals.nelts; ++i) |
6082 | { | |
6083 | struct symtab_and_line sal = sals.sals[i]; | |
6084 | struct bp_location *loc; | |
6085 | ||
6086 | if (from_tty) | |
5af949e3 UW |
6087 | { |
6088 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6089 | if (!loc_gdbarch) | |
6090 | loc_gdbarch = gdbarch; | |
6091 | ||
6092 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6093 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6094 | } |
0d381245 VP |
6095 | |
6096 | if (i == 0) | |
6097 | { | |
a6d9a66e | 6098 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6099 | set_breakpoint_count (breakpoint_count + 1); |
6100 | b->number = breakpoint_count; | |
6101 | b->thread = thread; | |
4a306c9a | 6102 | b->task = task; |
018d34a4 | 6103 | |
0d381245 VP |
6104 | b->cond_string = cond_string; |
6105 | b->ignore_count = ignore_count; | |
41447f92 | 6106 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6107 | b->disposition = disposition; |
018d34a4 | 6108 | |
6c95b8df PA |
6109 | b->pspace = sals.sals[0].pspace; |
6110 | ||
6111 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6112 | && (b->type == bp_breakpoint |
6113 | || b->type == bp_hardware_breakpoint)) | |
6114 | b->enable_state = bp_startup_disabled; | |
6115 | ||
0d381245 VP |
6116 | loc = b->loc; |
6117 | } | |
6118 | else | |
018d34a4 | 6119 | { |
39d61571 | 6120 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6121 | } |
6122 | ||
514f746b AR |
6123 | if (bp_loc_is_permanent (loc)) |
6124 | make_breakpoint_permanent (b); | |
6125 | ||
0d381245 VP |
6126 | if (b->cond_string) |
6127 | { | |
6128 | char *arg = b->cond_string; | |
d32a6982 | 6129 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6130 | if (*arg) |
db107f19 | 6131 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6132 | } |
0d381245 | 6133 | } |
018d34a4 VP |
6134 | |
6135 | if (addr_string) | |
6136 | b->addr_string = addr_string; | |
6137 | else | |
6138 | /* addr_string has to be used or breakpoint_re_set will delete | |
6139 | me. */ | |
5af949e3 UW |
6140 | b->addr_string |
6141 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6142 | |
604133b5 | 6143 | b->ops = ops; |
018d34a4 VP |
6144 | mention (b); |
6145 | } | |
6146 | ||
ed0616c6 VP |
6147 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6148 | elements to fill the void space. */ | |
2c0b251b PA |
6149 | static void |
6150 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6151 | { |
6152 | int i = index_to_remove+1; | |
6153 | int last_index = sal->nelts-1; | |
6154 | ||
6155 | for (;i <= last_index; ++i) | |
6156 | sal->sals[i-1] = sal->sals[i]; | |
6157 | ||
6158 | --(sal->nelts); | |
6159 | } | |
6160 | ||
6c95b8df PA |
6161 | /* If appropriate, obtains all sals that correspond to the same file |
6162 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6163 | will want to set a breakpoint at foo.c:line, and not really care | |
6164 | about program spaces. This is done only if SAL does not have | |
6165 | explicit PC and has line and file information. If we got just a | |
6166 | single expanded sal, return the original. | |
ed0616c6 | 6167 | |
6c95b8df PA |
6168 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6169 | which the name of enclosing function is different from SAL. This | |
6170 | makes sure that if we have breakpoint originally set in template | |
6171 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6172 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6173 | |
2c0b251b | 6174 | static struct symtabs_and_lines |
ed0616c6 VP |
6175 | expand_line_sal_maybe (struct symtab_and_line sal) |
6176 | { | |
6177 | struct symtabs_and_lines expanded; | |
6178 | CORE_ADDR original_pc = sal.pc; | |
6179 | char *original_function = NULL; | |
6180 | int found; | |
6181 | int i; | |
6c95b8df | 6182 | struct cleanup *old_chain; |
ed0616c6 VP |
6183 | |
6184 | /* If we have explicit pc, don't expand. | |
6185 | If we have no line number, we can't expand. */ | |
6186 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6187 | { | |
6188 | expanded.nelts = 1; | |
6189 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6190 | expanded.sals[0] = sal; | |
6191 | return expanded; | |
6192 | } | |
6193 | ||
6194 | sal.pc = 0; | |
6c95b8df PA |
6195 | |
6196 | old_chain = save_current_space_and_thread (); | |
6197 | ||
6198 | switch_to_program_space_and_thread (sal.pspace); | |
6199 | ||
ed0616c6 | 6200 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6201 | |
6202 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6203 | expanded = expand_line_sal (sal); |
6c95b8df | 6204 | |
ed0616c6 VP |
6205 | if (expanded.nelts == 1) |
6206 | { | |
6207 | /* We had one sal, we got one sal. Without futher | |
6208 | processing, just return the original sal. */ | |
6209 | xfree (expanded.sals); | |
6210 | expanded.nelts = 1; | |
6211 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6212 | sal.pc = original_pc; | |
6213 | expanded.sals[0] = sal; | |
6c95b8df | 6214 | do_cleanups (old_chain); |
ed0616c6 VP |
6215 | return expanded; |
6216 | } | |
6217 | ||
6218 | if (!sal.explicit_line) | |
6219 | { | |
6220 | CORE_ADDR func_addr, func_end; | |
6221 | for (i = 0; i < expanded.nelts; ++i) | |
6222 | { | |
6223 | CORE_ADDR pc = expanded.sals[i].pc; | |
6224 | char *this_function; | |
6c95b8df PA |
6225 | |
6226 | /* We need to switch threads as well since we're about to | |
6227 | read memory. */ | |
6228 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6229 | ||
ed0616c6 VP |
6230 | if (find_pc_partial_function (pc, &this_function, |
6231 | &func_addr, &func_end)) | |
6232 | { | |
059fb39f PM |
6233 | if (this_function |
6234 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6235 | { |
6236 | remove_sal (&expanded, i); | |
6237 | --i; | |
6238 | } | |
6239 | else if (func_addr == pc) | |
6240 | { | |
6241 | /* We're at beginning of a function, and should | |
6242 | skip prologue. */ | |
6243 | struct symbol *sym = find_pc_function (pc); | |
6244 | if (sym) | |
6245 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
6246 | else | |
d80b854b UW |
6247 | { |
6248 | /* Since find_pc_partial_function returned true, | |
6249 | we should really always find the section here. */ | |
6250 | struct obj_section *section = find_pc_section (pc); | |
6251 | if (section) | |
6252 | { | |
6253 | struct gdbarch *gdbarch | |
6254 | = get_objfile_arch (section->objfile); | |
6255 | expanded.sals[i].pc | |
6256 | = gdbarch_skip_prologue (gdbarch, pc); | |
6257 | } | |
6258 | } | |
ed0616c6 VP |
6259 | } |
6260 | } | |
6261 | } | |
6262 | } | |
3daf8fe5 JG |
6263 | else |
6264 | { | |
6265 | for (i = 0; i < expanded.nelts; ++i) | |
6266 | { | |
6267 | /* If this SAL corresponds to a breakpoint inserted using a | |
6268 | line number, then skip the function prologue if necessary. */ | |
6269 | skip_prologue_sal (&expanded.sals[i]); | |
6270 | } | |
6271 | } | |
ed0616c6 | 6272 | |
6c95b8df PA |
6273 | do_cleanups (old_chain); |
6274 | ||
ed0616c6 VP |
6275 | if (expanded.nelts <= 1) |
6276 | { | |
6277 | /* This is un ugly workaround. If we get zero | |
6278 | expanded sals then something is really wrong. | |
6279 | Fix that by returnign the original sal. */ | |
6280 | xfree (expanded.sals); | |
6281 | expanded.nelts = 1; | |
6282 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6283 | sal.pc = original_pc; | |
6284 | expanded.sals[0] = sal; | |
6285 | return expanded; | |
6286 | } | |
6287 | ||
6288 | if (original_pc) | |
6289 | { | |
6290 | found = 0; | |
6291 | for (i = 0; i < expanded.nelts; ++i) | |
6292 | if (expanded.sals[i].pc == original_pc) | |
6293 | { | |
6294 | found = 1; | |
6295 | break; | |
6296 | } | |
6297 | gdb_assert (found); | |
6298 | } | |
6299 | ||
6300 | return expanded; | |
6301 | } | |
6302 | ||
018d34a4 VP |
6303 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6304 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6305 | value. COND_STRING, if not NULL, specified the condition to be | |
6306 | used for all breakpoints. Essentially the only case where | |
6307 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6308 | function. In that case, it's still not possible to specify | |
6309 | separate conditions for different overloaded functions, so | |
6310 | we take just a single condition string. | |
6311 | ||
c3f6f71d | 6312 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 6313 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
6314 | array contents). If the function fails (error() is called), the |
6315 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
6316 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
6317 | |
6318 | static void | |
a6d9a66e UW |
6319 | create_breakpoints (struct gdbarch *gdbarch, |
6320 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 6321 | char *cond_string, |
c3f6f71d | 6322 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 6323 | int thread, int task, int ignore_count, |
41447f92 VP |
6324 | struct breakpoint_ops *ops, int from_tty, |
6325 | int enabled) | |
c906108c | 6326 | { |
018d34a4 VP |
6327 | int i; |
6328 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 6329 | { |
ed0616c6 VP |
6330 | struct symtabs_and_lines expanded = |
6331 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 6332 | |
a6d9a66e | 6333 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 6334 | cond_string, type, disposition, |
4a306c9a | 6335 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 6336 | } |
c3f6f71d | 6337 | } |
c906108c | 6338 | |
c3f6f71d JM |
6339 | /* Parse ARG which is assumed to be a SAL specification possibly |
6340 | followed by conditionals. On return, SALS contains an array of SAL | |
6341 | addresses found. ADDR_STRING contains a vector of (canonical) | |
6342 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 6343 | |
b9362cc7 | 6344 | static void |
c3f6f71d JM |
6345 | parse_breakpoint_sals (char **address, |
6346 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
6347 | char ***addr_string, |
6348 | int *not_found_ptr) | |
c3f6f71d JM |
6349 | { |
6350 | char *addr_start = *address; | |
6351 | *addr_string = NULL; | |
6352 | /* If no arg given, or if first arg is 'if ', use the default | |
6353 | breakpoint. */ | |
6354 | if ((*address) == NULL | |
6355 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
6356 | { |
6357 | if (default_breakpoint_valid) | |
6358 | { | |
c3f6f71d | 6359 | struct symtab_and_line sal; |
fe39c653 | 6360 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 6361 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
6362 | xmalloc (sizeof (struct symtab_and_line)); |
6363 | sal.pc = default_breakpoint_address; | |
6364 | sal.line = default_breakpoint_line; | |
6365 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 6366 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 6367 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
6368 | |
6369 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
6370 | the default_breakpoint_address. So make sure to set | |
6371 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
6372 | sals to include all other instances with the same symtab and line. | |
6373 | */ | |
6374 | sal.explicit_pc = 1; | |
6375 | ||
c3f6f71d JM |
6376 | sals->sals[0] = sal; |
6377 | sals->nelts = 1; | |
c906108c SS |
6378 | } |
6379 | else | |
8a3fe4f8 | 6380 | error (_("No default breakpoint address now.")); |
c906108c SS |
6381 | } |
6382 | else | |
6383 | { | |
c906108c | 6384 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
6385 | current_source_symtab (which is decode_line_1's default). This |
6386 | should produce the results we want almost all of the time while | |
1aeae86e AF |
6387 | leaving default_breakpoint_* alone. |
6388 | ObjC: However, don't match an Objective-C method name which | |
6389 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 6390 | |
c214a6fd | 6391 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 6392 | |
c906108c | 6393 | if (default_breakpoint_valid |
0378c332 | 6394 | && (!cursal.symtab |
1aeae86e AF |
6395 | || ((strchr ("+-", (*address)[0]) != NULL) |
6396 | && ((*address)[1] != '[')))) | |
c3f6f71d | 6397 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
6398 | default_breakpoint_line, addr_string, |
6399 | not_found_ptr); | |
c906108c | 6400 | else |
0101ce28 JJ |
6401 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
6402 | addr_string, not_found_ptr); | |
c906108c | 6403 | } |
c3f6f71d JM |
6404 | /* For any SAL that didn't have a canonical string, fill one in. */ |
6405 | if (sals->nelts > 0 && *addr_string == NULL) | |
6406 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
6407 | if (addr_start != (*address)) | |
c906108c | 6408 | { |
c3f6f71d JM |
6409 | int i; |
6410 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 6411 | { |
c3f6f71d JM |
6412 | /* Add the string if not present. */ |
6413 | if ((*addr_string)[i] == NULL) | |
6414 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
6415 | } |
6416 | } | |
c3f6f71d | 6417 | } |
c906108c | 6418 | |
c906108c | 6419 | |
c3f6f71d JM |
6420 | /* Convert each SAL into a real PC. Verify that the PC can be |
6421 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 6422 | |
b9362cc7 | 6423 | static void |
c3f6f71d JM |
6424 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
6425 | char *address) | |
6426 | { | |
6427 | int i; | |
6428 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 6429 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
6430 | } |
6431 | ||
05ff989b | 6432 | static void |
0101ce28 JJ |
6433 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
6434 | { | |
6435 | struct captured_parse_breakpoint_args *args = data; | |
6436 | ||
6437 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
6438 | args->not_found_ptr); | |
0101ce28 JJ |
6439 | } |
6440 | ||
018d34a4 VP |
6441 | /* Given TOK, a string specification of condition and thread, as |
6442 | accepted by the 'break' command, extract the condition | |
6443 | string and thread number and set *COND_STRING and *THREAD. | |
6444 | PC identifies the context at which the condition should be parsed. | |
6445 | If no condition is found, *COND_STRING is set to NULL. | |
6446 | If no thread is found, *THREAD is set to -1. */ | |
6447 | static void | |
6448 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 6449 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
6450 | { |
6451 | *cond_string = NULL; | |
6452 | *thread = -1; | |
6453 | while (tok && *tok) | |
6454 | { | |
6455 | char *end_tok; | |
6456 | int toklen; | |
6457 | char *cond_start = NULL; | |
6458 | char *cond_end = NULL; | |
6459 | while (*tok == ' ' || *tok == '\t') | |
6460 | tok++; | |
6461 | ||
6462 | end_tok = tok; | |
6463 | ||
6464 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6465 | end_tok++; | |
6466 | ||
6467 | toklen = end_tok - tok; | |
6468 | ||
6469 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6470 | { | |
f7545552 TT |
6471 | struct expression *expr; |
6472 | ||
018d34a4 | 6473 | tok = cond_start = end_tok + 1; |
f7545552 TT |
6474 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
6475 | xfree (expr); | |
018d34a4 VP |
6476 | cond_end = tok; |
6477 | *cond_string = savestring (cond_start, | |
6478 | cond_end - cond_start); | |
6479 | } | |
6480 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6481 | { | |
6482 | char *tmptok; | |
6483 | ||
6484 | tok = end_tok + 1; | |
6485 | tmptok = tok; | |
6486 | *thread = strtol (tok, &tok, 0); | |
6487 | if (tok == tmptok) | |
6488 | error (_("Junk after thread keyword.")); | |
6489 | if (!valid_thread_id (*thread)) | |
6490 | error (_("Unknown thread %d."), *thread); | |
6491 | } | |
4a306c9a JB |
6492 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
6493 | { | |
6494 | char *tmptok; | |
6495 | ||
6496 | tok = end_tok + 1; | |
6497 | tmptok = tok; | |
6498 | *task = strtol (tok, &tok, 0); | |
6499 | if (tok == tmptok) | |
6500 | error (_("Junk after task keyword.")); | |
6501 | if (!valid_task_id (*task)) | |
6502 | error (_("Unknown task %d\n"), *task); | |
6503 | } | |
018d34a4 VP |
6504 | else |
6505 | error (_("Junk at end of arguments.")); | |
6506 | } | |
6507 | } | |
6508 | ||
72b2ff0e VP |
6509 | /* Set a breakpoint. This function is shared between |
6510 | CLI and MI functions for setting a breakpoint. | |
6511 | This function has two major modes of operations, | |
6512 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
6513 | If non-zero, the function will parse arg, extracting | |
6514 | breakpoint location, address and thread. Otherwise, | |
6515 | ARG is just the location of breakpoint, with condition | |
6516 | and thread specified by the COND_STRING and THREAD | |
6517 | parameters. */ | |
0101ce28 | 6518 | |
98deb0da | 6519 | static void |
a6d9a66e UW |
6520 | break_command_really (struct gdbarch *gdbarch, |
6521 | char *arg, char *cond_string, int thread, | |
60c46647 | 6522 | int parse_condition_and_thread, |
1042e4c0 | 6523 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
6524 | int ignore_count, |
6525 | enum auto_boolean pending_break_support, | |
604133b5 | 6526 | struct breakpoint_ops *ops, |
41447f92 VP |
6527 | int from_tty, |
6528 | int enabled) | |
c3f6f71d | 6529 | { |
71fff37b | 6530 | struct gdb_exception e; |
c3f6f71d | 6531 | struct symtabs_and_lines sals; |
0101ce28 | 6532 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
6533 | char *copy_arg; |
6534 | char *err_msg; | |
c3f6f71d JM |
6535 | char *addr_start = arg; |
6536 | char **addr_string; | |
6537 | struct cleanup *old_chain; | |
80c99de1 | 6538 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 6539 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 6540 | int i; |
0101ce28 | 6541 | int pending = 0; |
0101ce28 | 6542 | int not_found = 0; |
1042e4c0 | 6543 | enum bptype type_wanted; |
4a306c9a | 6544 | int task = 0; |
c3f6f71d | 6545 | |
c3f6f71d JM |
6546 | sals.sals = NULL; |
6547 | sals.nelts = 0; | |
6548 | addr_string = NULL; | |
c3f6f71d | 6549 | |
0101ce28 JJ |
6550 | parse_args.arg_p = &arg; |
6551 | parse_args.sals_p = &sals; | |
6552 | parse_args.addr_string_p = &addr_string; | |
6553 | parse_args.not_found_ptr = ¬_found; | |
6554 | ||
05ff989b AC |
6555 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
6556 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
6557 | |
6558 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 6559 | switch (e.reason) |
0101ce28 | 6560 | { |
05ff989b | 6561 | case RETURN_QUIT: |
98deb0da | 6562 | throw_exception (e); |
05ff989b AC |
6563 | case RETURN_ERROR: |
6564 | switch (e.error) | |
0101ce28 | 6565 | { |
05ff989b | 6566 | case NOT_FOUND_ERROR: |
0101ce28 | 6567 | |
05ff989b AC |
6568 | /* If pending breakpoint support is turned off, throw |
6569 | error. */ | |
fa8d40ab JJ |
6570 | |
6571 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
6572 | throw_exception (e); |
6573 | ||
6574 | exception_print (gdb_stderr, e); | |
fa8d40ab | 6575 | |
05ff989b AC |
6576 | /* If pending breakpoint support is auto query and the user |
6577 | selects no, then simply return the error code. */ | |
059fb39f PM |
6578 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
6579 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 6580 | return; |
fa8d40ab | 6581 | |
05ff989b AC |
6582 | /* At this point, either the user was queried about setting |
6583 | a pending breakpoint and selected yes, or pending | |
6584 | breakpoint behavior is on and thus a pending breakpoint | |
6585 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
6586 | copy_arg = xstrdup (addr_start); |
6587 | addr_string = ©_arg; | |
6588 | sals.nelts = 1; | |
6589 | sals.sals = &pending_sal; | |
6590 | pending_sal.pc = 0; | |
6591 | pending = 1; | |
05ff989b AC |
6592 | break; |
6593 | default: | |
98deb0da | 6594 | throw_exception (e); |
0101ce28 | 6595 | } |
05ff989b AC |
6596 | default: |
6597 | if (!sals.nelts) | |
98deb0da | 6598 | return; |
0101ce28 | 6599 | } |
c3f6f71d JM |
6600 | |
6601 | /* Create a chain of things that always need to be cleaned up. */ | |
6602 | old_chain = make_cleanup (null_cleanup, 0); | |
6603 | ||
0101ce28 JJ |
6604 | if (!pending) |
6605 | { | |
6606 | /* Make sure that all storage allocated to SALS gets freed. */ | |
6607 | make_cleanup (xfree, sals.sals); | |
6608 | ||
6609 | /* Cleanup the addr_string array but not its contents. */ | |
6610 | make_cleanup (xfree, addr_string); | |
6611 | } | |
c3f6f71d | 6612 | |
c3f6f71d JM |
6613 | /* ----------------------------- SNIP ----------------------------- |
6614 | Anything added to the cleanup chain beyond this point is assumed | |
6615 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
6616 | then the memory is not reclaimed. */ |
6617 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
6618 | |
6619 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 6620 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
6621 | for (i = 0; i < sals.nelts; i++) |
6622 | { | |
6623 | if (addr_string[i] != NULL) | |
b8c9b27d | 6624 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
6625 | } |
6626 | ||
6627 | /* Resolve all line numbers to PC's and verify that the addresses | |
6628 | are ok for the target. */ | |
0101ce28 JJ |
6629 | if (!pending) |
6630 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 6631 | |
1042e4c0 SS |
6632 | type_wanted = (traceflag |
6633 | ? bp_tracepoint | |
6634 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
6635 | ||
c3f6f71d JM |
6636 | /* Verify that condition can be parsed, before setting any |
6637 | breakpoints. Allocate a separate condition expression for each | |
6638 | breakpoint. */ | |
0101ce28 | 6639 | if (!pending) |
c3f6f71d | 6640 | { |
2f069f6f | 6641 | if (parse_condition_and_thread) |
72b2ff0e VP |
6642 | { |
6643 | /* Here we only parse 'arg' to separate condition | |
6644 | from thread number, so parsing in context of first | |
6645 | sal is OK. When setting the breakpoint we'll | |
6646 | re-parse it in context of each sal. */ | |
6647 | cond_string = NULL; | |
6648 | thread = -1; | |
4a306c9a JB |
6649 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
6650 | &thread, &task); | |
72b2ff0e VP |
6651 | if (cond_string) |
6652 | make_cleanup (xfree, cond_string); | |
6653 | } | |
2f069f6f | 6654 | else |
72b2ff0e VP |
6655 | { |
6656 | /* Create a private copy of condition string. */ | |
6657 | if (cond_string) | |
6658 | { | |
6659 | cond_string = xstrdup (cond_string); | |
6660 | make_cleanup (xfree, cond_string); | |
6661 | } | |
6662 | } | |
a6d9a66e | 6663 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 6664 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 6665 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 6666 | } |
0101ce28 JJ |
6667 | else |
6668 | { | |
fe3f5fa8 | 6669 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
6670 | struct breakpoint *b; |
6671 | ||
0101ce28 JJ |
6672 | make_cleanup (xfree, copy_arg); |
6673 | ||
a6d9a66e | 6674 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
6675 | set_breakpoint_count (breakpoint_count + 1); |
6676 | b->number = breakpoint_count; | |
72b2ff0e | 6677 | b->thread = -1; |
018d34a4 | 6678 | b->addr_string = addr_string[0]; |
72b2ff0e | 6679 | b->cond_string = NULL; |
0101ce28 | 6680 | b->ignore_count = ignore_count; |
0101ce28 | 6681 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 6682 | b->condition_not_parsed = 1; |
604133b5 | 6683 | b->ops = ops; |
41447f92 | 6684 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 6685 | b->pspace = current_program_space; |
74960c60 | 6686 | |
6c95b8df | 6687 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
6688 | && (b->type == bp_breakpoint |
6689 | || b->type == bp_hardware_breakpoint)) | |
6690 | b->enable_state = bp_startup_disabled; | |
6691 | ||
0101ce28 JJ |
6692 | mention (b); |
6693 | } | |
6694 | ||
c3f6f71d | 6695 | if (sals.nelts > 1) |
8a3fe4f8 AC |
6696 | warning (_("Multiple breakpoints were set.\n" |
6697 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6698 | /* That's it. Discard the cleanups for data inserted into the |
6699 | breakpoint. */ | |
6700 | discard_cleanups (bkpt_chain); | |
6701 | /* But cleanup everything else. */ | |
c3f6f71d | 6702 | do_cleanups (old_chain); |
217dc9e2 | 6703 | |
80c99de1 | 6704 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6705 | update_global_location_list (1); |
c3f6f71d | 6706 | } |
c906108c | 6707 | |
72b2ff0e VP |
6708 | /* Set a breakpoint. |
6709 | ARG is a string describing breakpoint address, | |
6710 | condition, and thread. | |
6711 | FLAG specifies if a breakpoint is hardware on, | |
6712 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6713 | and BP_TEMPFLAG. */ | |
6714 | ||
98deb0da | 6715 | static void |
72b2ff0e | 6716 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6717 | { |
72b2ff0e VP |
6718 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6719 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6720 | |
a6d9a66e UW |
6721 | break_command_really (get_current_arch (), |
6722 | arg, | |
98deb0da | 6723 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6724 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6725 | 0 /* Ignore count */, |
604133b5 AR |
6726 | pending_break_support, |
6727 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6728 | from_tty, |
6729 | 1 /* enabled */); | |
c906108c SS |
6730 | } |
6731 | ||
72b2ff0e | 6732 | |
98deb0da | 6733 | void |
a6d9a66e UW |
6734 | set_breakpoint (struct gdbarch *gdbarch, |
6735 | char *address, char *condition, | |
c3f6f71d | 6736 | int hardwareflag, int tempflag, |
ce43223b | 6737 | int thread, int ignore_count, |
41447f92 | 6738 | int pending, int enabled) |
c3f6f71d | 6739 | { |
a6d9a66e UW |
6740 | break_command_really (gdbarch, |
6741 | address, condition, thread, | |
98deb0da | 6742 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6743 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6744 | ignore_count, |
6745 | pending | |
6746 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6747 | NULL, 0, enabled); |
c3f6f71d JM |
6748 | } |
6749 | ||
6a048695 JB |
6750 | /* Adjust SAL to the first instruction past the function prologue. |
6751 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6752 | the debugging information. explicit_pc and explicit_line are |
6753 | not modified. | |
6a048695 JB |
6754 | |
6755 | If SAL is already past the prologue, then do nothing. */ | |
6756 | ||
6757 | static void | |
6758 | skip_prologue_sal (struct symtab_and_line *sal) | |
6759 | { | |
6c95b8df | 6760 | struct symbol *sym; |
6a048695 | 6761 | struct symtab_and_line start_sal; |
6c95b8df | 6762 | struct cleanup *old_chain; |
6a048695 | 6763 | |
6c95b8df | 6764 | old_chain = save_current_space_and_thread (); |
6a048695 | 6765 | |
6c95b8df PA |
6766 | sym = find_pc_function (sal->pc); |
6767 | if (sym != NULL) | |
3daf8fe5 | 6768 | { |
6c95b8df PA |
6769 | start_sal = find_function_start_sal (sym, 1); |
6770 | if (sal->pc < start_sal.pc) | |
6771 | { | |
6772 | start_sal.explicit_line = sal->explicit_line; | |
6773 | start_sal.explicit_pc = sal->explicit_pc; | |
6774 | *sal = start_sal; | |
6775 | } | |
3daf8fe5 | 6776 | } |
6c95b8df PA |
6777 | |
6778 | do_cleanups (old_chain); | |
6a048695 | 6779 | } |
c3f6f71d | 6780 | |
c906108c SS |
6781 | /* Helper function for break_command_1 and disassemble_command. */ |
6782 | ||
6783 | void | |
fba45db2 | 6784 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6785 | { |
6786 | CORE_ADDR pc; | |
6787 | ||
6788 | if (sal->pc == 0 && sal->symtab != NULL) | |
6789 | { | |
6790 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6791 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6792 | sal->line, sal->symtab->filename); |
6793 | sal->pc = pc; | |
6a048695 JB |
6794 | |
6795 | /* If this SAL corresponds to a breakpoint inserted using | |
6796 | a line number, then skip the function prologue if necessary. */ | |
6797 | if (sal->explicit_line) | |
56ef84b1 TT |
6798 | { |
6799 | /* Preserve the original line number. */ | |
6800 | int saved_line = sal->line; | |
6801 | skip_prologue_sal (sal); | |
6802 | sal->line = saved_line; | |
6803 | } | |
c906108c SS |
6804 | } |
6805 | ||
6806 | if (sal->section == 0 && sal->symtab != NULL) | |
6807 | { | |
6808 | struct blockvector *bv; | |
c5aa993b JM |
6809 | struct block *b; |
6810 | struct symbol *sym; | |
c906108c | 6811 | |
801e3a5b | 6812 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6813 | if (bv != NULL) |
6814 | { | |
7f0df278 | 6815 | sym = block_linkage_function (b); |
c906108c SS |
6816 | if (sym != NULL) |
6817 | { | |
6818 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6819 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6820 | } |
6821 | else | |
6822 | { | |
6823 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6824 | have to look harder. This case can be executed if we have |
6825 | line numbers but no functions (as can happen in assembly | |
6826 | source). */ | |
c906108c | 6827 | |
c5aa993b | 6828 | struct minimal_symbol *msym; |
6c95b8df PA |
6829 | struct cleanup *old_chain = save_current_space_and_thread (); |
6830 | ||
6831 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
6832 | |
6833 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6834 | if (msym) | |
714835d5 | 6835 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
6836 | |
6837 | do_cleanups (old_chain); | |
c906108c SS |
6838 | } |
6839 | } | |
6840 | } | |
6841 | } | |
6842 | ||
6843 | void | |
fba45db2 | 6844 | break_command (char *arg, int from_tty) |
c906108c | 6845 | { |
db107f19 | 6846 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6847 | } |
6848 | ||
c906108c | 6849 | void |
fba45db2 | 6850 | tbreak_command (char *arg, int from_tty) |
c906108c | 6851 | { |
db107f19 | 6852 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
6853 | } |
6854 | ||
c906108c | 6855 | static void |
fba45db2 | 6856 | hbreak_command (char *arg, int from_tty) |
c906108c | 6857 | { |
db107f19 | 6858 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
6859 | } |
6860 | ||
6861 | static void | |
fba45db2 | 6862 | thbreak_command (char *arg, int from_tty) |
c906108c | 6863 | { |
db107f19 | 6864 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
6865 | } |
6866 | ||
6867 | static void | |
fba45db2 | 6868 | stop_command (char *arg, int from_tty) |
c906108c | 6869 | { |
a3f17187 | 6870 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 6871 | Usage: stop in <function | address>\n\ |
a3f17187 | 6872 | stop at <line>\n")); |
c906108c SS |
6873 | } |
6874 | ||
6875 | static void | |
fba45db2 | 6876 | stopin_command (char *arg, int from_tty) |
c906108c SS |
6877 | { |
6878 | int badInput = 0; | |
6879 | ||
c5aa993b | 6880 | if (arg == (char *) NULL) |
c906108c SS |
6881 | badInput = 1; |
6882 | else if (*arg != '*') | |
6883 | { | |
6884 | char *argptr = arg; | |
6885 | int hasColon = 0; | |
6886 | ||
53a5351d JM |
6887 | /* look for a ':'. If this is a line number specification, then |
6888 | say it is bad, otherwise, it should be an address or | |
6889 | function/method name */ | |
c906108c | 6890 | while (*argptr && !hasColon) |
c5aa993b JM |
6891 | { |
6892 | hasColon = (*argptr == ':'); | |
6893 | argptr++; | |
6894 | } | |
c906108c SS |
6895 | |
6896 | if (hasColon) | |
c5aa993b | 6897 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 6898 | else |
c5aa993b | 6899 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
6900 | } |
6901 | ||
6902 | if (badInput) | |
a3f17187 | 6903 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 6904 | else |
db107f19 | 6905 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6906 | } |
6907 | ||
6908 | static void | |
fba45db2 | 6909 | stopat_command (char *arg, int from_tty) |
c906108c SS |
6910 | { |
6911 | int badInput = 0; | |
6912 | ||
c5aa993b | 6913 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
6914 | badInput = 1; |
6915 | else | |
6916 | { | |
6917 | char *argptr = arg; | |
6918 | int hasColon = 0; | |
6919 | ||
6920 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 6921 | it is probably a line number. */ |
c906108c | 6922 | while (*argptr && !hasColon) |
c5aa993b JM |
6923 | { |
6924 | hasColon = (*argptr == ':'); | |
6925 | argptr++; | |
6926 | } | |
c906108c SS |
6927 | |
6928 | if (hasColon) | |
c5aa993b | 6929 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 6930 | else |
c5aa993b | 6931 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
6932 | } |
6933 | ||
6934 | if (badInput) | |
a3f17187 | 6935 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 6936 | else |
db107f19 | 6937 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
6938 | } |
6939 | ||
53a5351d JM |
6940 | /* accessflag: hw_write: watch write, |
6941 | hw_read: watch read, | |
6942 | hw_access: watch access (read or write) */ | |
c906108c | 6943 | static void |
fba45db2 | 6944 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 6945 | { |
a6d9a66e | 6946 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 6947 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
6948 | struct symtab_and_line sal; |
6949 | struct expression *exp; | |
6950 | struct block *exp_valid_block; | |
6951 | struct value *val, *mark; | |
6952 | struct frame_info *frame; | |
c906108c SS |
6953 | char *exp_start = NULL; |
6954 | char *exp_end = NULL; | |
37e4754d | 6955 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
6956 | int toklen; |
6957 | char *cond_start = NULL; | |
6958 | char *cond_end = NULL; | |
6959 | struct expression *cond = NULL; | |
6960 | int i, other_type_used, target_resources_ok = 0; | |
6961 | enum bptype bp_type; | |
6962 | int mem_cnt = 0; | |
37e4754d | 6963 | int thread = -1; |
c906108c | 6964 | |
fe39c653 | 6965 | init_sal (&sal); /* initialize to zeroes */ |
c5aa993b | 6966 | |
37e4754d LM |
6967 | /* Make sure that we actually have parameters to parse. */ |
6968 | if (arg != NULL && arg[0] != '\0') | |
6969 | { | |
6970 | toklen = strlen (arg); /* Size of argument list. */ | |
6971 | ||
6972 | /* Points tok to the end of the argument list. */ | |
6973 | tok = arg + toklen - 1; | |
6974 | ||
6975 | /* Go backwards in the parameters list. Skip the last parameter. | |
6976 | If we're expecting a 'thread <thread_num>' parameter, this should | |
6977 | be the thread identifier. */ | |
6978 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6979 | tok--; | |
6980 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6981 | tok--; | |
6982 | ||
6983 | /* Points end_tok to the beginning of the last token. */ | |
6984 | id_tok_start = tok + 1; | |
6985 | ||
6986 | /* Go backwards in the parameters list. Skip one more parameter. | |
6987 | If we're expecting a 'thread <thread_num>' parameter, we should | |
6988 | reach a "thread" token. */ | |
6989 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
6990 | tok--; | |
6991 | ||
6992 | end_tok = tok; | |
6993 | ||
6994 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
6995 | tok--; | |
6996 | ||
6997 | /* Move the pointer forward to skip the whitespace and | |
6998 | calculate the length of the token. */ | |
6999 | tok++; | |
7000 | toklen = end_tok - tok; | |
7001 | ||
7002 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7003 | { | |
7004 | /* At this point we've found a "thread" token, which means | |
7005 | the user is trying to set a watchpoint that triggers | |
7006 | only in a specific thread. */ | |
7007 | char *endp; | |
7008 | ||
7009 | /* Extract the thread ID from the next token. */ | |
7010 | thread = strtol (id_tok_start, &endp, 0); | |
7011 | ||
7012 | /* Check if the user provided a valid numeric value for the | |
7013 | thread ID. */ | |
7014 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7015 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7016 | ||
7017 | /* Check if the thread actually exists. */ | |
7018 | if (!valid_thread_id (thread)) | |
7019 | error (_("Unknown thread %d."), thread); | |
7020 | ||
7021 | /* Truncate the string and get rid of the thread <thread_num> | |
7022 | parameter before the parameter list is parsed by the | |
7023 | evaluate_expression() function. */ | |
7024 | *tok = '\0'; | |
7025 | } | |
7026 | } | |
7027 | ||
6c95b8df PA |
7028 | sal.pspace = current_program_space; |
7029 | ||
37e4754d | 7030 | /* Parse the rest of the arguments. */ |
c906108c SS |
7031 | innermost_block = NULL; |
7032 | exp_start = arg; | |
7033 | exp = parse_exp_1 (&arg, 0, 0); | |
7034 | exp_end = arg; | |
fa8a61dc TT |
7035 | /* Remove trailing whitespace from the expression before saving it. |
7036 | This makes the eventual display of the expression string a bit | |
7037 | prettier. */ | |
7038 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7039 | --exp_end; | |
7040 | ||
c906108c SS |
7041 | exp_valid_block = innermost_block; |
7042 | mark = value_mark (); | |
fa4727a6 DJ |
7043 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7044 | if (val != NULL) | |
7045 | release_value (val); | |
c906108c SS |
7046 | |
7047 | tok = arg; | |
7048 | while (*tok == ' ' || *tok == '\t') | |
7049 | tok++; | |
7050 | end_tok = tok; | |
7051 | ||
7052 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7053 | end_tok++; | |
7054 | ||
7055 | toklen = end_tok - tok; | |
7056 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7057 | { | |
7058 | tok = cond_start = end_tok + 1; | |
7059 | cond = parse_exp_1 (&tok, 0, 0); | |
7060 | cond_end = tok; | |
7061 | } | |
7062 | if (*tok) | |
8a3fe4f8 | 7063 | error (_("Junk at end of command.")); |
c906108c | 7064 | |
53a5351d | 7065 | if (accessflag == hw_read) |
c5aa993b | 7066 | bp_type = bp_read_watchpoint; |
53a5351d | 7067 | else if (accessflag == hw_access) |
c5aa993b JM |
7068 | bp_type = bp_access_watchpoint; |
7069 | else | |
7070 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7071 | |
7072 | mem_cnt = can_use_hardware_watchpoint (val); | |
7073 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7074 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7075 | if (mem_cnt != 0) |
7076 | { | |
7077 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7078 | target_resources_ok = |
d92524f1 | 7079 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7080 | other_type_used); |
c5aa993b | 7081 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7082 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7083 | |
c5aa993b | 7084 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7085 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7086 | } |
c906108c | 7087 | |
4d28f7a8 KB |
7088 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7089 | watchpoint could not be set. */ | |
7090 | if (!mem_cnt || target_resources_ok <= 0) | |
7091 | bp_type = bp_watchpoint; | |
7092 | ||
d983da9c | 7093 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7094 | |
7095 | /* If the expression is "local", then set up a "watchpoint scope" | |
7096 | breakpoint at the point where we've left the scope of the watchpoint | |
7097 | expression. Create the scope breakpoint before the watchpoint, so | |
7098 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 7099 | if (innermost_block && frame) |
d983da9c | 7100 | { |
edb3359d DJ |
7101 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7102 | { | |
7103 | scope_breakpoint | |
a6d9a66e UW |
7104 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7105 | frame_unwind_caller_pc (frame), | |
edb3359d | 7106 | bp_watchpoint_scope); |
d983da9c | 7107 | |
edb3359d | 7108 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7109 | |
edb3359d DJ |
7110 | /* Automatically delete the breakpoint when it hits. */ |
7111 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7112 | |
edb3359d DJ |
7113 | /* Only break in the proper frame (help with recursion). */ |
7114 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7115 | |
edb3359d | 7116 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7117 | scope_breakpoint->loc->gdbarch |
7118 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7119 | scope_breakpoint->loc->requested_address |
7120 | = frame_unwind_caller_pc (frame); | |
7121 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7122 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7123 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7124 | scope_breakpoint->type); |
7125 | } | |
d983da9c DJ |
7126 | } |
7127 | ||
c906108c | 7128 | /* Now set up the breakpoint. */ |
a6d9a66e | 7129 | b = set_raw_breakpoint (gdbarch, sal, bp_type); |
c906108c SS |
7130 | set_breakpoint_count (breakpoint_count + 1); |
7131 | b->number = breakpoint_count; | |
37e4754d | 7132 | b->thread = thread; |
b5de0fa7 | 7133 | b->disposition = disp_donttouch; |
c906108c SS |
7134 | b->exp = exp; |
7135 | b->exp_valid_block = exp_valid_block; | |
7136 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
7137 | b->val = val; | |
fa4727a6 | 7138 | b->val_valid = 1; |
511a6cd4 | 7139 | b->loc->cond = cond; |
c906108c SS |
7140 | if (cond_start) |
7141 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7142 | else | |
7143 | b->cond_string = 0; | |
c5aa993b | 7144 | |
c906108c | 7145 | if (frame) |
d983da9c | 7146 | b->watchpoint_frame = get_frame_id (frame); |
c906108c | 7147 | else |
35a487f1 | 7148 | b->watchpoint_frame = null_frame_id; |
c906108c | 7149 | |
d983da9c | 7150 | if (scope_breakpoint != NULL) |
c906108c | 7151 | { |
d983da9c DJ |
7152 | /* The scope breakpoint is related to the watchpoint. We will |
7153 | need to act on them together. */ | |
7154 | b->related_breakpoint = scope_breakpoint; | |
7155 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7156 | } |
d983da9c | 7157 | |
c906108c SS |
7158 | value_free_to_mark (mark); |
7159 | mention (b); | |
b60e7edf | 7160 | update_global_location_list (1); |
c906108c SS |
7161 | } |
7162 | ||
7163 | /* Return count of locations need to be watched and can be handled | |
7164 | in hardware. If the watchpoint can not be handled | |
7165 | in hardware return zero. */ | |
7166 | ||
c906108c | 7167 | static int |
fba45db2 | 7168 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7169 | { |
7170 | int found_memory_cnt = 0; | |
2e70b7b9 | 7171 | struct value *head = v; |
c906108c SS |
7172 | |
7173 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7174 | if (!can_use_hw_watchpoints) |
c906108c | 7175 | return 0; |
c5aa993b | 7176 | |
5c44784c JM |
7177 | /* Make sure that the value of the expression depends only upon |
7178 | memory contents, and values computed from them within GDB. If we | |
7179 | find any register references or function calls, we can't use a | |
7180 | hardware watchpoint. | |
7181 | ||
7182 | The idea here is that evaluating an expression generates a series | |
7183 | of values, one holding the value of every subexpression. (The | |
7184 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7185 | a*b+c.) GDB's values hold almost enough information to establish | |
7186 | the criteria given above --- they identify memory lvalues, | |
7187 | register lvalues, computed values, etcetera. So we can evaluate | |
7188 | the expression, and then scan the chain of values that leaves | |
7189 | behind to decide whether we can detect any possible change to the | |
7190 | expression's final value using only hardware watchpoints. | |
7191 | ||
7192 | However, I don't think that the values returned by inferior | |
7193 | function calls are special in any way. So this function may not | |
7194 | notice that an expression involving an inferior function call | |
7195 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7196 | for (; v; v = value_next (v)) |
c906108c | 7197 | { |
5c44784c | 7198 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7199 | { |
d69fe07e | 7200 | if (value_lazy (v)) |
5c44784c JM |
7201 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7202 | we either just used its address (e.g., `a' in `a.b') or | |
7203 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7204 | ; | |
53a5351d | 7205 | else |
5c44784c JM |
7206 | { |
7207 | /* Ahh, memory we actually used! Check if we can cover | |
7208 | it with hardware watchpoints. */ | |
df407dfe | 7209 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7210 | |
7211 | /* We only watch structs and arrays if user asked for it | |
7212 | explicitly, never if they just happen to appear in a | |
7213 | middle of some value chain. */ | |
7214 | if (v == head | |
7215 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7216 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7217 | { | |
42ae5230 | 7218 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7219 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7220 | |
d92524f1 | 7221 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7222 | return 0; |
7223 | else | |
7224 | found_memory_cnt++; | |
7225 | } | |
5c44784c | 7226 | } |
c5aa993b | 7227 | } |
5086187c AC |
7228 | else if (VALUE_LVAL (v) != not_lval |
7229 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7230 | return 0; /* ??? What does this represent? */ |
5086187c | 7231 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7232 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7233 | } |
7234 | ||
7235 | /* The expression itself looks suitable for using a hardware | |
7236 | watchpoint, but give the target machine a chance to reject it. */ | |
7237 | return found_memory_cnt; | |
7238 | } | |
7239 | ||
8b93c638 | 7240 | void |
fba45db2 | 7241 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7242 | { |
7243 | watch_command (arg, from_tty); | |
7244 | } | |
8926118c | 7245 | |
c5aa993b | 7246 | static void |
fba45db2 | 7247 | watch_command (char *arg, int from_tty) |
c906108c | 7248 | { |
53a5351d | 7249 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7250 | } |
7251 | ||
8b93c638 | 7252 | void |
fba45db2 | 7253 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7254 | { |
7255 | rwatch_command (arg, from_tty); | |
7256 | } | |
8926118c | 7257 | |
c5aa993b | 7258 | static void |
fba45db2 | 7259 | rwatch_command (char *arg, int from_tty) |
c906108c | 7260 | { |
53a5351d | 7261 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7262 | } |
7263 | ||
8b93c638 | 7264 | void |
fba45db2 | 7265 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7266 | { |
7267 | awatch_command (arg, from_tty); | |
7268 | } | |
8926118c | 7269 | |
c5aa993b | 7270 | static void |
fba45db2 | 7271 | awatch_command (char *arg, int from_tty) |
c906108c | 7272 | { |
53a5351d | 7273 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7274 | } |
c906108c | 7275 | \f |
c5aa993b | 7276 | |
43ff13b4 | 7277 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7278 | because it uses the mechanisms of breakpoints. */ |
7279 | ||
bfec99b2 PA |
7280 | struct until_break_command_continuation_args |
7281 | { | |
7282 | struct breakpoint *breakpoint; | |
7283 | struct breakpoint *breakpoint2; | |
7284 | }; | |
7285 | ||
43ff13b4 JM |
7286 | /* This function is called by fetch_inferior_event via the |
7287 | cmd_continuation pointer, to complete the until command. It takes | |
7288 | care of cleaning up the temporary breakpoints set up by the until | |
7289 | command. */ | |
c2c6d25f | 7290 | static void |
604ead4a | 7291 | until_break_command_continuation (void *arg) |
43ff13b4 | 7292 | { |
bfec99b2 PA |
7293 | struct until_break_command_continuation_args *a = arg; |
7294 | ||
7295 | delete_breakpoint (a->breakpoint); | |
7296 | if (a->breakpoint2) | |
7297 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
7298 | } |
7299 | ||
c906108c | 7300 | void |
ae66c1fc | 7301 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
7302 | { |
7303 | struct symtabs_and_lines sals; | |
7304 | struct symtab_and_line sal; | |
206415a3 | 7305 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 7306 | struct breakpoint *breakpoint; |
f107f563 | 7307 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
7308 | struct cleanup *old_chain; |
7309 | ||
7310 | clear_proceed_status (); | |
7311 | ||
7312 | /* Set a breakpoint where the user wants it and at return from | |
7313 | this function */ | |
c5aa993b | 7314 | |
c906108c SS |
7315 | if (default_breakpoint_valid) |
7316 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 7317 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 7318 | else |
53a5351d | 7319 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 7320 | 0, (char ***) NULL, NULL); |
c5aa993b | 7321 | |
c906108c | 7322 | if (sals.nelts != 1) |
8a3fe4f8 | 7323 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 7324 | |
c906108c | 7325 | sal = sals.sals[0]; |
b8c9b27d | 7326 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 7327 | |
c906108c | 7328 | if (*arg) |
8a3fe4f8 | 7329 | error (_("Junk at end of arguments.")); |
c5aa993b | 7330 | |
c906108c | 7331 | resolve_sal_pc (&sal); |
c5aa993b | 7332 | |
ae66c1fc EZ |
7333 | if (anywhere) |
7334 | /* If the user told us to continue until a specified location, | |
7335 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
7336 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7337 | null_frame_id, bp_until); | |
ae66c1fc | 7338 | else |
edb3359d | 7339 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 7340 | at the very same frame. */ |
a6d9a66e UW |
7341 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7342 | get_stack_frame_id (frame), | |
ae66c1fc | 7343 | bp_until); |
c5aa993b | 7344 | |
f107f563 | 7345 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 7346 | |
ae66c1fc EZ |
7347 | /* Keep within the current frame, or in frames called by the current |
7348 | one. */ | |
edb3359d DJ |
7349 | |
7350 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 7351 | { |
edb3359d DJ |
7352 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
7353 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
7354 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
7355 | sal, | |
edb3359d | 7356 | frame_unwind_caller_id (frame), |
f107f563 VP |
7357 | bp_until); |
7358 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 7359 | } |
c5aa993b | 7360 | |
c906108c | 7361 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
7362 | |
7363 | /* If we are running asynchronously, and proceed call above has actually | |
7364 | managed to start the target, arrange for breakpoints to be | |
7365 | deleted when the target stops. Otherwise, we're already stopped and | |
7366 | delete breakpoints via cleanup chain. */ | |
7367 | ||
8ea051c5 | 7368 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 7369 | { |
bfec99b2 PA |
7370 | struct until_break_command_continuation_args *args; |
7371 | args = xmalloc (sizeof (*args)); | |
f107f563 | 7372 | |
bfec99b2 PA |
7373 | args->breakpoint = breakpoint; |
7374 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
7375 | |
7376 | discard_cleanups (old_chain); | |
95e54da7 PA |
7377 | add_continuation (inferior_thread (), |
7378 | until_break_command_continuation, args, | |
604ead4a | 7379 | xfree); |
f107f563 VP |
7380 | } |
7381 | else | |
c5aa993b | 7382 | do_cleanups (old_chain); |
c906108c | 7383 | } |
ae66c1fc | 7384 | |
c906108c | 7385 | static void |
fba45db2 | 7386 | ep_skip_leading_whitespace (char **s) |
c906108c | 7387 | { |
c5aa993b JM |
7388 | if ((s == NULL) || (*s == NULL)) |
7389 | return; | |
7390 | while (isspace (**s)) | |
7391 | *s += 1; | |
c906108c | 7392 | } |
c5aa993b | 7393 | |
c906108c SS |
7394 | /* This function attempts to parse an optional "if <cond>" clause |
7395 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 7396 | |
c906108c SS |
7397 | Else, it returns a pointer to the condition string. (It does not |
7398 | attempt to evaluate the string against a particular block.) And, | |
7399 | it updates arg to point to the first character following the parsed | |
7400 | if clause in the arg string. */ | |
53a5351d | 7401 | |
c906108c | 7402 | static char * |
fba45db2 | 7403 | ep_parse_optional_if_clause (char **arg) |
c906108c | 7404 | { |
c5aa993b JM |
7405 | char *cond_string; |
7406 | ||
7407 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 7408 | return NULL; |
c5aa993b | 7409 | |
c906108c SS |
7410 | /* Skip the "if" keyword. */ |
7411 | (*arg) += 2; | |
c5aa993b | 7412 | |
c906108c SS |
7413 | /* Skip any extra leading whitespace, and record the start of the |
7414 | condition string. */ | |
7415 | ep_skip_leading_whitespace (arg); | |
7416 | cond_string = *arg; | |
c5aa993b | 7417 | |
c906108c SS |
7418 | /* Assume that the condition occupies the remainder of the arg string. */ |
7419 | (*arg) += strlen (cond_string); | |
c5aa993b | 7420 | |
c906108c SS |
7421 | return cond_string; |
7422 | } | |
c5aa993b | 7423 | |
c906108c SS |
7424 | /* This function attempts to parse an optional filename from the arg |
7425 | string. If one is not found, it returns NULL. | |
c5aa993b | 7426 | |
c906108c SS |
7427 | Else, it returns a pointer to the parsed filename. (This function |
7428 | makes no attempt to verify that a file of that name exists, or is | |
7429 | accessible.) And, it updates arg to point to the first character | |
7430 | following the parsed filename in the arg string. | |
c5aa993b | 7431 | |
c906108c SS |
7432 | Note that clients needing to preserve the returned filename for |
7433 | future access should copy it to their own buffers. */ | |
7434 | static char * | |
fba45db2 | 7435 | ep_parse_optional_filename (char **arg) |
c906108c | 7436 | { |
c5aa993b JM |
7437 | static char filename[1024]; |
7438 | char *arg_p = *arg; | |
7439 | int i; | |
7440 | char c; | |
7441 | ||
c906108c SS |
7442 | if ((*arg_p == '\0') || isspace (*arg_p)) |
7443 | return NULL; | |
c5aa993b JM |
7444 | |
7445 | for (i = 0;; i++) | |
c906108c SS |
7446 | { |
7447 | c = *arg_p; | |
7448 | if (isspace (c)) | |
c5aa993b | 7449 | c = '\0'; |
c906108c SS |
7450 | filename[i] = c; |
7451 | if (c == '\0') | |
c5aa993b | 7452 | break; |
c906108c SS |
7453 | arg_p++; |
7454 | } | |
7455 | *arg = arg_p; | |
c5aa993b | 7456 | |
c906108c SS |
7457 | return filename; |
7458 | } | |
c5aa993b | 7459 | |
c906108c SS |
7460 | /* Commands to deal with catching events, such as signals, exceptions, |
7461 | process start/exit, etc. */ | |
c5aa993b JM |
7462 | |
7463 | typedef enum | |
7464 | { | |
44feb3ce TT |
7465 | catch_fork_temporary, catch_vfork_temporary, |
7466 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
7467 | } |
7468 | catch_fork_kind; | |
7469 | ||
c906108c | 7470 | static void |
44feb3ce | 7471 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7472 | { |
a6d9a66e | 7473 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 7474 | char *cond_string = NULL; |
44feb3ce TT |
7475 | catch_fork_kind fork_kind; |
7476 | int tempflag; | |
7477 | ||
7478 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
7479 | tempflag = (fork_kind == catch_fork_temporary | |
7480 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 7481 | |
44feb3ce TT |
7482 | if (!arg) |
7483 | arg = ""; | |
c906108c | 7484 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7485 | |
c906108c | 7486 | /* The allowed syntax is: |
c5aa993b JM |
7487 | catch [v]fork |
7488 | catch [v]fork if <cond> | |
7489 | ||
c906108c SS |
7490 | First, check if there's an if clause. */ |
7491 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 7492 | |
c906108c | 7493 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 7494 | error (_("Junk at end of arguments.")); |
c5aa993b | 7495 | |
c906108c SS |
7496 | /* If this target supports it, create a fork or vfork catchpoint |
7497 | and enable reporting of such events. */ | |
c5aa993b JM |
7498 | switch (fork_kind) |
7499 | { | |
44feb3ce TT |
7500 | case catch_fork_temporary: |
7501 | case catch_fork_permanent: | |
a6d9a66e | 7502 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7503 | &catch_fork_breakpoint_ops); |
c906108c | 7504 | break; |
44feb3ce TT |
7505 | case catch_vfork_temporary: |
7506 | case catch_vfork_permanent: | |
a6d9a66e | 7507 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7508 | &catch_vfork_breakpoint_ops); |
c906108c | 7509 | break; |
c5aa993b | 7510 | default: |
8a3fe4f8 | 7511 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 7512 | break; |
c5aa993b | 7513 | } |
c906108c SS |
7514 | } |
7515 | ||
7516 | static void | |
44feb3ce | 7517 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7518 | { |
a6d9a66e | 7519 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7520 | int tempflag; |
c5aa993b | 7521 | char *cond_string = NULL; |
c906108c | 7522 | |
44feb3ce TT |
7523 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7524 | ||
7525 | if (!arg) | |
7526 | arg = ""; | |
c906108c SS |
7527 | ep_skip_leading_whitespace (&arg); |
7528 | ||
7529 | /* The allowed syntax is: | |
c5aa993b JM |
7530 | catch exec |
7531 | catch exec if <cond> | |
c906108c SS |
7532 | |
7533 | First, check if there's an if clause. */ | |
7534 | cond_string = ep_parse_optional_if_clause (&arg); | |
7535 | ||
7536 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7537 | error (_("Junk at end of arguments.")); |
c906108c SS |
7538 | |
7539 | /* If this target supports it, create an exec catchpoint | |
7540 | and enable reporting of such events. */ | |
a6d9a66e UW |
7541 | create_catchpoint (gdbarch, tempflag, cond_string, |
7542 | &catch_exec_breakpoint_ops); | |
c906108c | 7543 | } |
c5aa993b | 7544 | |
3086aeae DJ |
7545 | static enum print_stop_action |
7546 | print_exception_catchpoint (struct breakpoint *b) | |
7547 | { | |
ade92717 | 7548 | int bp_temp, bp_throw; |
3086aeae | 7549 | |
ade92717 | 7550 | annotate_catchpoint (b->number); |
3086aeae | 7551 | |
ade92717 AR |
7552 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7553 | if (b->loc->address != b->loc->requested_address) | |
7554 | breakpoint_adjustment_warning (b->loc->requested_address, | |
7555 | b->loc->address, | |
7556 | b->number, 1); | |
df2b6d2d | 7557 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7558 | ui_out_text (uiout, |
7559 | bp_temp ? "Temporary catchpoint " | |
7560 | : "Catchpoint "); | |
7561 | if (!ui_out_is_mi_like_p (uiout)) | |
7562 | ui_out_field_int (uiout, "bkptno", b->number); | |
7563 | ui_out_text (uiout, | |
c0b37c48 AR |
7564 | bp_throw ? " (exception thrown), " |
7565 | : " (exception caught), "); | |
ade92717 AR |
7566 | if (ui_out_is_mi_like_p (uiout)) |
7567 | { | |
7568 | ui_out_field_string (uiout, "reason", | |
7569 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
7570 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7571 | ui_out_field_int (uiout, "bkptno", b->number); | |
7572 | } | |
3086aeae DJ |
7573 | return PRINT_SRC_AND_LOC; |
7574 | } | |
7575 | ||
7576 | static void | |
a6d9a66e | 7577 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 7578 | { |
79a45b7d TT |
7579 | struct value_print_options opts; |
7580 | get_user_print_options (&opts); | |
7581 | if (opts.addressprint) | |
3086aeae DJ |
7582 | { |
7583 | annotate_field (4); | |
604133b5 AR |
7584 | if (b->loc == NULL || b->loc->shlib_disabled) |
7585 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
7586 | else | |
5af949e3 UW |
7587 | ui_out_field_core_addr (uiout, "addr", |
7588 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
7589 | } |
7590 | annotate_field (5); | |
604133b5 | 7591 | if (b->loc) |
a6d9a66e | 7592 | *last_loc = b->loc; |
3086aeae DJ |
7593 | if (strstr (b->addr_string, "throw") != NULL) |
7594 | ui_out_field_string (uiout, "what", "exception throw"); | |
7595 | else | |
7596 | ui_out_field_string (uiout, "what", "exception catch"); | |
7597 | } | |
7598 | ||
7599 | static void | |
7600 | print_mention_exception_catchpoint (struct breakpoint *b) | |
7601 | { | |
ade92717 AR |
7602 | int bp_temp; |
7603 | int bp_throw; | |
7604 | ||
df2b6d2d | 7605 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7606 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7607 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
7608 | : _("Catchpoint ")); | |
7609 | ui_out_field_int (uiout, "bkptno", b->number); | |
7610 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
7611 | : _(" (catch)")); | |
3086aeae DJ |
7612 | } |
7613 | ||
7614 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
7615 | NULL, /* insert */ |
7616 | NULL, /* remove */ | |
7617 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
7618 | print_exception_catchpoint, |
7619 | print_one_exception_catchpoint, | |
7620 | print_mention_exception_catchpoint | |
7621 | }; | |
7622 | ||
7623 | static int | |
7624 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
7625 | enum exception_event_kind ex_event, int from_tty) | |
7626 | { | |
604133b5 AR |
7627 | char *trigger_func_name; |
7628 | ||
3086aeae | 7629 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 7630 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 7631 | else |
604133b5 | 7632 | trigger_func_name = "__cxa_throw"; |
3086aeae | 7633 | |
a6d9a66e UW |
7634 | break_command_really (get_current_arch (), |
7635 | trigger_func_name, cond_string, -1, | |
604133b5 | 7636 | 0 /* condition and thread are valid. */, |
1042e4c0 | 7637 | tempflag, 0, 0, |
604133b5 AR |
7638 | 0, |
7639 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
7640 | &gnu_v3_exception_catchpoint_ops, from_tty, |
7641 | 1 /* enabled */); | |
3086aeae | 7642 | |
3086aeae DJ |
7643 | return 1; |
7644 | } | |
7645 | ||
c5aa993b | 7646 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
7647 | |
7648 | static void | |
fba45db2 KB |
7649 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
7650 | int tempflag, int from_tty) | |
c906108c | 7651 | { |
c5aa993b JM |
7652 | char *cond_string = NULL; |
7653 | struct symtab_and_line *sal = NULL; | |
7654 | ||
44feb3ce TT |
7655 | if (!arg) |
7656 | arg = ""; | |
c906108c | 7657 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7658 | |
c906108c SS |
7659 | cond_string = ep_parse_optional_if_clause (&arg); |
7660 | ||
7661 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7662 | error (_("Junk at end of arguments.")); |
c906108c | 7663 | |
059fb39f PM |
7664 | if (ex_event != EX_EVENT_THROW |
7665 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7666 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7667 | |
3086aeae DJ |
7668 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7669 | return; | |
7670 | ||
8a3fe4f8 | 7671 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
7672 | } |
7673 | ||
44feb3ce TT |
7674 | /* Implementation of "catch catch" command. */ |
7675 | ||
7676 | static void | |
7677 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7678 | { | |
7679 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7680 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
7681 | } | |
7682 | ||
7683 | /* Implementation of "catch throw" command. */ | |
7684 | ||
7685 | static void | |
7686 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7687 | { | |
7688 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7689 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
7690 | } | |
7691 | ||
f7f9143b JB |
7692 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
7693 | ||
7694 | static void | |
a6d9a66e UW |
7695 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
7696 | struct symtab_and_line sal, | |
f7f9143b JB |
7697 | char *addr_string, |
7698 | char *exp_string, | |
7699 | char *cond_string, | |
7700 | struct expression *cond, | |
7701 | struct breakpoint_ops *ops, | |
7702 | int tempflag, | |
7703 | int from_tty) | |
7704 | { | |
7705 | struct breakpoint *b; | |
7706 | ||
7707 | if (from_tty) | |
7708 | { | |
5af949e3 UW |
7709 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
7710 | if (!loc_gdbarch) | |
7711 | loc_gdbarch = gdbarch; | |
7712 | ||
6c95b8df PA |
7713 | describe_other_breakpoints (loc_gdbarch, |
7714 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
7715 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7716 | version for exception catchpoints, because two catchpoints | |
7717 | used for different exception names will use the same address. | |
7718 | In this case, a "breakpoint ... also set at..." warning is | |
7719 | unproductive. Besides. the warning phrasing is also a bit | |
7720 | inapropriate, we should use the word catchpoint, and tell | |
7721 | the user what type of catchpoint it is. The above is good | |
7722 | enough for now, though. */ | |
7723 | } | |
7724 | ||
a6d9a66e | 7725 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7726 | set_breakpoint_count (breakpoint_count + 1); |
7727 | ||
7728 | b->enable_state = bp_enabled; | |
7729 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7730 | b->number = breakpoint_count; | |
7731 | b->ignore_count = 0; | |
511a6cd4 | 7732 | b->loc->cond = cond; |
f7f9143b JB |
7733 | b->addr_string = addr_string; |
7734 | b->language = language_ada; | |
7735 | b->cond_string = cond_string; | |
7736 | b->exp_string = exp_string; | |
7737 | b->thread = -1; | |
7738 | b->ops = ops; | |
f7f9143b JB |
7739 | |
7740 | mention (b); | |
b60e7edf | 7741 | update_global_location_list (1); |
f7f9143b JB |
7742 | } |
7743 | ||
7744 | /* Implement the "catch exception" command. */ | |
7745 | ||
7746 | static void | |
44feb3ce TT |
7747 | catch_ada_exception_command (char *arg, int from_tty, |
7748 | struct cmd_list_element *command) | |
f7f9143b | 7749 | { |
a6d9a66e | 7750 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7751 | int tempflag; |
f7f9143b JB |
7752 | struct symtab_and_line sal; |
7753 | enum bptype type; | |
7754 | char *addr_string = NULL; | |
7755 | char *exp_string = NULL; | |
7756 | char *cond_string = NULL; | |
7757 | struct expression *cond = NULL; | |
7758 | struct breakpoint_ops *ops = NULL; | |
7759 | ||
44feb3ce TT |
7760 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7761 | ||
7762 | if (!arg) | |
7763 | arg = ""; | |
f7f9143b JB |
7764 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7765 | &cond_string, &cond, &ops); | |
a6d9a66e | 7766 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7767 | cond_string, cond, ops, tempflag, |
7768 | from_tty); | |
7769 | } | |
7770 | ||
a96d9b2e SDJ |
7771 | /* Cleanup function for a syscall filter list. */ |
7772 | static void | |
7773 | clean_up_filters (void *arg) | |
7774 | { | |
7775 | VEC(int) *iter = *(VEC(int) **) arg; | |
7776 | VEC_free (int, iter); | |
7777 | } | |
7778 | ||
7779 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
7780 | filter list, or NULL if no filtering is required. */ | |
7781 | static VEC(int) * | |
7782 | catch_syscall_split_args (char *arg) | |
7783 | { | |
7784 | VEC(int) *result = NULL; | |
7785 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
7786 | ||
7787 | while (*arg != '\0') | |
7788 | { | |
7789 | int i, syscall_number; | |
7790 | char *endptr; | |
7791 | char cur_name[128]; | |
7792 | struct syscall s; | |
7793 | ||
7794 | /* Skip whitespace. */ | |
7795 | while (isspace (*arg)) | |
7796 | arg++; | |
7797 | ||
7798 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
7799 | cur_name[i] = arg[i]; | |
7800 | cur_name[i] = '\0'; | |
7801 | arg += i; | |
7802 | ||
7803 | /* Check if the user provided a syscall name or a number. */ | |
7804 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
7805 | if (*endptr == '\0') | |
bccd0dd2 | 7806 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
7807 | else |
7808 | { | |
7809 | /* We have a name. Let's check if it's valid and convert it | |
7810 | to a number. */ | |
7811 | get_syscall_by_name (cur_name, &s); | |
7812 | ||
7813 | if (s.number == UNKNOWN_SYSCALL) | |
7814 | /* Here we have to issue an error instead of a warning, because | |
7815 | GDB cannot do anything useful if there's no syscall number to | |
7816 | be caught. */ | |
7817 | error (_("Unknown syscall name '%s'."), cur_name); | |
7818 | } | |
7819 | ||
7820 | /* Ok, it's valid. */ | |
7821 | VEC_safe_push (int, result, s.number); | |
7822 | } | |
7823 | ||
7824 | discard_cleanups (cleanup); | |
7825 | return result; | |
7826 | } | |
7827 | ||
7828 | /* Implement the "catch syscall" command. */ | |
7829 | ||
7830 | static void | |
7831 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
7832 | { | |
7833 | int tempflag; | |
7834 | VEC(int) *filter; | |
7835 | struct syscall s; | |
7836 | struct gdbarch *gdbarch = get_current_arch (); | |
7837 | ||
7838 | /* Checking if the feature if supported. */ | |
7839 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
7840 | error (_("The feature 'catch syscall' is not supported on \ | |
7841 | this architeture yet.")); | |
7842 | ||
7843 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7844 | ||
7845 | ep_skip_leading_whitespace (&arg); | |
7846 | ||
7847 | /* We need to do this first "dummy" translation in order | |
7848 | to get the syscall XML file loaded or, most important, | |
7849 | to display a warning to the user if there's no XML file | |
7850 | for his/her architecture. */ | |
7851 | get_syscall_by_number (0, &s); | |
7852 | ||
7853 | /* The allowed syntax is: | |
7854 | catch syscall | |
7855 | catch syscall <name | number> [<name | number> ... <name | number>] | |
7856 | ||
7857 | Let's check if there's a syscall name. */ | |
7858 | ||
7859 | if (arg != NULL) | |
7860 | filter = catch_syscall_split_args (arg); | |
7861 | else | |
7862 | filter = NULL; | |
7863 | ||
7864 | create_syscall_event_catchpoint (tempflag, filter, | |
7865 | &catch_syscall_breakpoint_ops); | |
7866 | } | |
7867 | ||
f7f9143b JB |
7868 | /* Implement the "catch assert" command. */ |
7869 | ||
7870 | static void | |
44feb3ce | 7871 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 7872 | { |
a6d9a66e | 7873 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7874 | int tempflag; |
f7f9143b JB |
7875 | struct symtab_and_line sal; |
7876 | char *addr_string = NULL; | |
7877 | struct breakpoint_ops *ops = NULL; | |
7878 | ||
44feb3ce TT |
7879 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7880 | ||
7881 | if (!arg) | |
7882 | arg = ""; | |
f7f9143b | 7883 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
7884 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
7885 | ops, tempflag, from_tty); | |
f7f9143b JB |
7886 | } |
7887 | ||
c906108c | 7888 | static void |
fba45db2 | 7889 | catch_command (char *arg, int from_tty) |
c906108c | 7890 | { |
44feb3ce | 7891 | error (_("Catch requires an event name.")); |
c906108c SS |
7892 | } |
7893 | \f | |
7894 | ||
7895 | static void | |
fba45db2 | 7896 | tcatch_command (char *arg, int from_tty) |
c906108c | 7897 | { |
44feb3ce | 7898 | error (_("Catch requires an event name.")); |
c906108c SS |
7899 | } |
7900 | ||
80f8a6eb | 7901 | /* Delete breakpoints by address or line. */ |
c906108c SS |
7902 | |
7903 | static void | |
fba45db2 | 7904 | clear_command (char *arg, int from_tty) |
c906108c | 7905 | { |
d6e956e5 VP |
7906 | struct breakpoint *b; |
7907 | VEC(breakpoint_p) *found = 0; | |
7908 | int ix; | |
c906108c SS |
7909 | int default_match; |
7910 | struct symtabs_and_lines sals; | |
7911 | struct symtab_and_line sal; | |
c906108c SS |
7912 | int i; |
7913 | ||
7914 | if (arg) | |
7915 | { | |
7916 | sals = decode_line_spec (arg, 1); | |
7917 | default_match = 0; | |
7918 | } | |
7919 | else | |
7920 | { | |
c5aa993b | 7921 | sals.sals = (struct symtab_and_line *) |
c906108c | 7922 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 7923 | make_cleanup (xfree, sals.sals); |
fe39c653 | 7924 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
7925 | sal.line = default_breakpoint_line; |
7926 | sal.symtab = default_breakpoint_symtab; | |
7927 | sal.pc = default_breakpoint_address; | |
6c95b8df | 7928 | sal.pspace = default_breakpoint_pspace; |
c906108c | 7929 | if (sal.symtab == 0) |
8a3fe4f8 | 7930 | error (_("No source file specified.")); |
c906108c SS |
7931 | |
7932 | sals.sals[0] = sal; | |
7933 | sals.nelts = 1; | |
7934 | ||
7935 | default_match = 1; | |
7936 | } | |
7937 | ||
ed0616c6 VP |
7938 | /* We don't call resolve_sal_pc here. That's not |
7939 | as bad as it seems, because all existing breakpoints | |
7940 | typically have both file/line and pc set. So, if | |
7941 | clear is given file/line, we can match this to existing | |
7942 | breakpoint without obtaining pc at all. | |
7943 | ||
7944 | We only support clearing given the address explicitly | |
7945 | present in breakpoint table. Say, we've set breakpoint | |
7946 | at file:line. There were several PC values for that file:line, | |
7947 | due to optimization, all in one block. | |
7948 | We've picked one PC value. If "clear" is issued with another | |
7949 | PC corresponding to the same file:line, the breakpoint won't | |
7950 | be cleared. We probably can still clear the breakpoint, but | |
7951 | since the other PC value is never presented to user, user | |
7952 | can only find it by guessing, and it does not seem important | |
7953 | to support that. */ | |
7954 | ||
c906108c | 7955 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
7956 | to it. Do it in two passes, solely to preserve the current |
7957 | behavior that from_tty is forced true if we delete more than | |
7958 | one breakpoint. */ | |
c906108c | 7959 | |
80f8a6eb | 7960 | found = NULL; |
c906108c SS |
7961 | for (i = 0; i < sals.nelts; i++) |
7962 | { | |
7963 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
7964 | If line given (pc == 0), clear all bpts on specified line. |
7965 | If defaulting, clear all bpts on default line | |
c906108c | 7966 | or at default pc. |
c5aa993b JM |
7967 | |
7968 | defaulting sal.pc != 0 tests to do | |
7969 | ||
7970 | 0 1 pc | |
7971 | 1 1 pc _and_ line | |
7972 | 0 0 line | |
7973 | 1 0 <can't happen> */ | |
c906108c SS |
7974 | |
7975 | sal = sals.sals[i]; | |
c906108c | 7976 | |
d6e956e5 VP |
7977 | /* Find all matching breakpoints and add them to |
7978 | 'found'. */ | |
7979 | ALL_BREAKPOINTS (b) | |
c5aa993b | 7980 | { |
0d381245 | 7981 | int match = 0; |
80f8a6eb MS |
7982 | /* Are we going to delete b? */ |
7983 | if (b->type != bp_none | |
7984 | && b->type != bp_watchpoint | |
7985 | && b->type != bp_hardware_watchpoint | |
7986 | && b->type != bp_read_watchpoint | |
0d381245 VP |
7987 | && b->type != bp_access_watchpoint) |
7988 | { | |
7989 | struct bp_location *loc = b->loc; | |
7990 | for (; loc; loc = loc->next) | |
7991 | { | |
6c95b8df PA |
7992 | int pc_match = sal.pc |
7993 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
7994 | && (loc->address == sal.pc) |
7995 | && (!section_is_overlay (loc->section) | |
7996 | || loc->section == sal.section); | |
7997 | int line_match = ((default_match || (0 == sal.pc)) | |
7998 | && b->source_file != NULL | |
7999 | && sal.symtab != NULL | |
6c95b8df | 8000 | && sal.pspace == loc->pspace |
0d381245 VP |
8001 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8002 | && b->line_number == sal.line); | |
8003 | if (pc_match || line_match) | |
8004 | { | |
8005 | match = 1; | |
8006 | break; | |
8007 | } | |
8008 | } | |
8009 | } | |
8010 | ||
8011 | if (match) | |
d6e956e5 | 8012 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8013 | } |
80f8a6eb MS |
8014 | } |
8015 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8016 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8017 | { |
8018 | if (arg) | |
8a3fe4f8 | 8019 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8020 | else |
8a3fe4f8 | 8021 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8022 | } |
c906108c | 8023 | |
d6e956e5 | 8024 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8025 | from_tty = 1; /* Always report if deleted more than one */ |
8026 | if (from_tty) | |
a3f17187 | 8027 | { |
d6e956e5 | 8028 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8029 | printf_unfiltered (_("Deleted breakpoint ")); |
8030 | else | |
8031 | printf_unfiltered (_("Deleted breakpoints ")); | |
8032 | } | |
80f8a6eb | 8033 | breakpoints_changed (); |
d6e956e5 VP |
8034 | |
8035 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8036 | { |
c5aa993b | 8037 | if (from_tty) |
d6e956e5 VP |
8038 | printf_unfiltered ("%d ", b->number); |
8039 | delete_breakpoint (b); | |
c906108c | 8040 | } |
80f8a6eb MS |
8041 | if (from_tty) |
8042 | putchar_unfiltered ('\n'); | |
c906108c SS |
8043 | } |
8044 | \f | |
8045 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8046 | all breakpoints that are marked for deletion, whether hit or not. | |
8047 | This is called after any breakpoint is hit, or after errors. */ | |
8048 | ||
8049 | void | |
fba45db2 | 8050 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8051 | { |
8052 | struct breakpoint *b, *temp; | |
8053 | ||
8054 | for (; bs; bs = bs->next) | |
20874c92 VP |
8055 | if (bs->breakpoint_at |
8056 | && bs->breakpoint_at->owner | |
8057 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8058 | && bs->stop) |
4f8d1dc6 | 8059 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8060 | |
8061 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8062 | { |
b5de0fa7 | 8063 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8064 | delete_breakpoint (b); |
8065 | } | |
c906108c SS |
8066 | } |
8067 | ||
876fa593 JK |
8068 | /* A comparison function for bp_location A and B being interfaced to qsort. |
8069 | Sort elements primarily by their ADDRESS (no matter what does | |
8070 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8071 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8072 | is sorted stable way despite qsort being an instable algorithm. */ | |
8073 | ||
8074 | static int | |
8075 | bp_location_compare (struct bp_location *a, struct bp_location *b) | |
8076 | { | |
8077 | int a_perm = a->owner->enable_state == bp_permanent; | |
8078 | int b_perm = b->owner->enable_state == bp_permanent; | |
8079 | ||
8080 | if (a->address != b->address) | |
8081 | return (a->address > b->address) - (a->address < b->address); | |
8082 | ||
8083 | /* Sort permanent breakpoints first. */ | |
8084 | if (a_perm != b_perm) | |
8085 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8086 | ||
8087 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8088 | breakpoint can be sorted in arbitrary order. */ | |
8089 | ||
8090 | if (a->owner->number != b->owner->number) | |
8091 | return (a->owner->number > b->owner->number) | |
8092 | - (a->owner->number < b->owner->number); | |
8093 | ||
8094 | return (a > b) - (a < b); | |
8095 | } | |
8096 | ||
8097 | /* Interface bp_location_compare as the COMPAR parameter of qsort function. */ | |
8098 | ||
8099 | static int | |
8100 | bp_location_compare_for_qsort (const void *ap, const void *bp) | |
8101 | { | |
8102 | struct bp_location *a = *(void **) ap; | |
8103 | struct bp_location *b = *(void **) bp; | |
8104 | ||
8105 | return bp_location_compare (a, b); | |
8106 | } | |
8107 | ||
8108 | /* Set bp_location_placed_address_before_address_max and | |
8109 | bp_location_shadow_len_after_address_max according to the current content of | |
8110 | the bp_location array. */ | |
f7545552 TT |
8111 | |
8112 | static void | |
876fa593 | 8113 | bp_location_target_extensions_update (void) |
f7545552 | 8114 | { |
876fa593 JK |
8115 | struct bp_location *bl, **blp_tmp; |
8116 | ||
8117 | bp_location_placed_address_before_address_max = 0; | |
8118 | bp_location_shadow_len_after_address_max = 0; | |
8119 | ||
8120 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8121 | { | |
8122 | CORE_ADDR start, end, addr; | |
8123 | ||
8124 | if (!bp_location_has_shadow (bl)) | |
8125 | continue; | |
8126 | ||
8127 | start = bl->target_info.placed_address; | |
8128 | end = start + bl->target_info.shadow_len; | |
8129 | ||
8130 | gdb_assert (bl->address >= start); | |
8131 | addr = bl->address - start; | |
8132 | if (addr > bp_location_placed_address_before_address_max) | |
8133 | bp_location_placed_address_before_address_max = addr; | |
8134 | ||
8135 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8136 | ||
8137 | gdb_assert (bl->address < end); | |
8138 | addr = end - bl->address; | |
8139 | if (addr > bp_location_shadow_len_after_address_max) | |
8140 | bp_location_shadow_len_after_address_max = addr; | |
8141 | } | |
f7545552 TT |
8142 | } |
8143 | ||
4cd9bd08 | 8144 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8145 | into the inferior, only remove already-inserted locations that no |
8146 | longer should be inserted. Functions that delete a breakpoint or | |
8147 | breakpoints should pass false, so that deleting a breakpoint | |
8148 | doesn't have the side effect of inserting the locations of other | |
8149 | breakpoints that are marked not-inserted, but should_be_inserted | |
8150 | returns true on them. | |
8151 | ||
8152 | This behaviour is useful is situations close to tear-down -- e.g., | |
8153 | after an exec, while the target still has execution, but breakpoint | |
8154 | shadows of the previous executable image should *NOT* be restored | |
8155 | to the new image; or before detaching, where the target still has | |
8156 | execution and wants to delete breakpoints from GDB's lists, and all | |
8157 | breakpoints had already been removed from the inferior. */ | |
8158 | ||
0d381245 | 8159 | static void |
b60e7edf | 8160 | update_global_location_list (int should_insert) |
0d381245 | 8161 | { |
74960c60 | 8162 | struct breakpoint *b; |
876fa593 | 8163 | struct bp_location **locp, *loc; |
f7545552 TT |
8164 | struct cleanup *cleanups; |
8165 | ||
876fa593 JK |
8166 | /* The first bp_location being the only one non-DUPLICATE for the current run |
8167 | of the same ADDRESS. */ | |
8168 | struct bp_location *loc_first; | |
8169 | ||
8170 | /* Saved former bp_location array which we compare against the newly built | |
8171 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8172 | struct bp_location **old_location, **old_locp; | |
8173 | unsigned old_location_count; | |
8174 | ||
8175 | old_location = bp_location; | |
8176 | old_location_count = bp_location_count; | |
8177 | bp_location = NULL; | |
8178 | bp_location_count = 0; | |
8179 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8180 | |
74960c60 | 8181 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8182 | for (loc = b->loc; loc; loc = loc->next) |
8183 | bp_location_count++; | |
8184 | ||
8185 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8186 | locp = bp_location; | |
8187 | ALL_BREAKPOINTS (b) | |
8188 | for (loc = b->loc; loc; loc = loc->next) | |
8189 | *locp++ = loc; | |
8190 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
8191 | bp_location_compare_for_qsort); | |
8192 | ||
8193 | bp_location_target_extensions_update (); | |
74960c60 VP |
8194 | |
8195 | /* Identify bp_location instances that are no longer present in the new | |
8196 | list, and therefore should be freed. Note that it's not necessary that | |
8197 | those locations should be removed from inferior -- if there's another | |
8198 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8199 | we don't need to remove/insert the location. |
8200 | ||
8201 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8202 | former bp_location array state respectively. */ | |
8203 | ||
8204 | locp = bp_location; | |
8205 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8206 | old_locp++) | |
74960c60 | 8207 | { |
876fa593 JK |
8208 | struct bp_location *old_loc = *old_locp; |
8209 | ||
8210 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8211 | have to free it. */ |
876fa593 | 8212 | int found_object; |
20874c92 VP |
8213 | /* Tells if the location should remain inserted in the target. */ |
8214 | int keep_in_target = 0; | |
8215 | int removed = 0; | |
876fa593 JK |
8216 | |
8217 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8218 | at or being the one matching OLD_LOC. */ | |
8219 | while (locp < bp_location + bp_location_count | |
8220 | && bp_location_compare (*locp, old_loc) < 0) | |
8221 | locp++; | |
8222 | found_object = locp < bp_location + bp_location_count && *locp == old_loc; | |
74960c60 VP |
8223 | |
8224 | /* If this location is no longer present, and inserted, look if there's | |
8225 | maybe a new location at the same address. If so, mark that one | |
8226 | inserted, and don't remove this one. This is needed so that we | |
8227 | don't have a time window where a breakpoint at certain location is not | |
8228 | inserted. */ | |
8229 | ||
876fa593 | 8230 | if (old_loc->inserted) |
0d381245 | 8231 | { |
74960c60 | 8232 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8233 | |
876fa593 | 8234 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8235 | { |
8236 | /* The location is still present in the location list, and still | |
8237 | should be inserted. Don't do anything. */ | |
20874c92 | 8238 | keep_in_target = 1; |
74960c60 VP |
8239 | } |
8240 | else | |
8241 | { | |
8242 | /* The location is either no longer present, or got disabled. | |
8243 | See if there's another location at the same address, in which | |
8244 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8245 | |
8246 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8247 | { | |
8248 | struct bp_location **loc2p; | |
8249 | ||
8250 | for (loc2p = locp; | |
8251 | loc2p < bp_location + bp_location_count | |
8252 | && breakpoint_address_match ((*loc2p)->pspace->aspace, | |
8253 | (*loc2p)->address, | |
8254 | old_loc->pspace->aspace, | |
8255 | old_loc->address); | |
8256 | loc2p++) | |
8257 | { | |
8258 | struct bp_location *loc2 = *loc2p; | |
8259 | ||
8260 | /* For the sake of should_be_inserted. | |
8261 | Duplicates check below will fix up this later. */ | |
8262 | loc2->duplicate = 0; | |
8263 | if (loc2 != old_loc && should_be_inserted (loc2)) | |
8264 | { | |
8265 | loc2->inserted = 1; | |
8266 | loc2->target_info = old_loc->target_info; | |
8267 | keep_in_target = 1; | |
8268 | break; | |
8269 | } | |
8270 | } | |
8271 | } | |
74960c60 VP |
8272 | } |
8273 | ||
20874c92 VP |
8274 | if (!keep_in_target) |
8275 | { | |
876fa593 | 8276 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8277 | { |
8278 | /* This is just about all we can do. We could keep this | |
8279 | location on the global list, and try to remove it next | |
8280 | time, but there's no particular reason why we will | |
8281 | succeed next time. | |
8282 | ||
876fa593 | 8283 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8284 | as delete_breakpoint frees the breakpoint only |
8285 | after calling us. */ | |
8286 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 8287 | old_loc->owner->number); |
20874c92 VP |
8288 | } |
8289 | removed = 1; | |
8290 | } | |
0d381245 | 8291 | } |
74960c60 VP |
8292 | |
8293 | if (!found_object) | |
1c5cfe86 PA |
8294 | { |
8295 | if (removed && non_stop) | |
20874c92 VP |
8296 | { |
8297 | /* This location was removed from the targets. In non-stop mode, | |
8298 | a race condition is possible where we've removed a breakpoint, | |
8299 | but stop events for that breakpoint are already queued and will | |
8300 | arrive later. To suppress spurious SIGTRAPs reported to user, | |
8301 | we keep this breakpoint location for a bit, and will retire it | |
8302 | after we see 3 * thread_count events. | |
1c5cfe86 | 8303 | The theory here is that reporting of events should, |
20874c92 VP |
8304 | "on the average", be fair, so after that many event we'll see |
8305 | events from all threads that have anything of interest, and no | |
1c5cfe86 | 8306 | longer need to keep this breakpoint. This is just a |
20874c92 | 8307 | heuristic, but if it's wrong, we'll report unexpected SIGTRAP, |
1c5cfe86 | 8308 | which is usability issue, but not a correctness problem. */ |
876fa593 JK |
8309 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
8310 | old_loc->owner = NULL; | |
20874c92 | 8311 | |
876fa593 | 8312 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
8313 | } |
8314 | else | |
876fa593 | 8315 | free_bp_location (old_loc); |
20874c92 | 8316 | } |
74960c60 | 8317 | } |
1c5cfe86 | 8318 | |
876fa593 JK |
8319 | /* Rescan breakpoints at the same address and section, |
8320 | marking the first one as "first" and any others as "duplicates". | |
8321 | This is so that the bpt instruction is only inserted once. | |
8322 | If we have a permanent breakpoint at the same place as BPT, make | |
8323 | that one the official one, and the rest as duplicates. Permanent | |
8324 | breakpoints are sorted first for the same address. */ | |
8325 | ||
8326 | loc_first = NULL; | |
8327 | ALL_BP_LOCATIONS (loc, locp) | |
74960c60 | 8328 | { |
876fa593 JK |
8329 | struct breakpoint *b = loc->owner; |
8330 | ||
8331 | if (b->enable_state == bp_disabled | |
8332 | || b->enable_state == bp_call_disabled | |
8333 | || b->enable_state == bp_startup_disabled | |
8334 | || !loc->enabled | |
8335 | || loc->shlib_disabled | |
8336 | || !breakpoint_address_is_meaningful (b)) | |
8337 | continue; | |
8338 | ||
8339 | /* Permanent breakpoint should always be inserted. */ | |
8340 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
8341 | internal_error (__FILE__, __LINE__, | |
8342 | _("allegedly permanent breakpoint is not " | |
8343 | "actually inserted")); | |
8344 | ||
8345 | if (loc_first == NULL | |
8346 | || (overlay_debugging && loc->section != loc_first->section) | |
8347 | || !breakpoint_address_match (loc->pspace->aspace, loc->address, | |
8348 | loc_first->pspace->aspace, | |
8349 | loc_first->address)) | |
8350 | { | |
8351 | loc_first = loc; | |
8352 | loc->duplicate = 0; | |
8353 | continue; | |
8354 | } | |
8355 | ||
8356 | loc->duplicate = 1; | |
8357 | ||
8358 | if (loc_first->owner->enable_state == bp_permanent && loc->inserted | |
8359 | && b->enable_state != bp_permanent) | |
8360 | internal_error (__FILE__, __LINE__, | |
8361 | _("another breakpoint was inserted on top of " | |
8362 | "a permanent breakpoint")); | |
0d381245 | 8363 | } |
74960c60 | 8364 | |
50c71eaf | 8365 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 8366 | && (have_live_inferiors () |
2567c7d9 | 8367 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 8368 | insert_breakpoint_locations (); |
f7545552 TT |
8369 | |
8370 | do_cleanups (cleanups); | |
74960c60 VP |
8371 | } |
8372 | ||
20874c92 VP |
8373 | void |
8374 | breakpoint_retire_moribund (void) | |
8375 | { | |
8376 | struct bp_location *loc; | |
8377 | int ix; | |
8378 | ||
8379 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
8380 | if (--(loc->events_till_retirement) == 0) | |
8381 | { | |
8382 | free_bp_location (loc); | |
8383 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
8384 | --ix; | |
8385 | } | |
8386 | } | |
8387 | ||
74960c60 | 8388 | static void |
b60e7edf | 8389 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
8390 | { |
8391 | struct gdb_exception e; | |
8392 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 8393 | update_global_location_list (inserting); |
0d381245 VP |
8394 | } |
8395 | ||
a474d7c2 PA |
8396 | /* Clear BPT from a BPS. */ |
8397 | static void | |
8398 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
8399 | { | |
8400 | bpstat bs; | |
8401 | for (bs = bps; bs; bs = bs->next) | |
8402 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
8403 | { | |
8404 | bs->breakpoint_at = NULL; | |
8405 | bs->old_val = NULL; | |
8406 | /* bs->commands will be freed later. */ | |
8407 | } | |
8408 | } | |
8409 | ||
8410 | /* Callback for iterate_over_threads. */ | |
8411 | static int | |
8412 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
8413 | { | |
8414 | struct breakpoint *bpt = data; | |
8415 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
8416 | return 0; | |
8417 | } | |
8418 | ||
53a5351d JM |
8419 | /* Delete a breakpoint and clean up all traces of it in the data |
8420 | structures. */ | |
c906108c SS |
8421 | |
8422 | void | |
fba45db2 | 8423 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8424 | { |
52f0bd74 | 8425 | struct breakpoint *b; |
74960c60 | 8426 | struct bp_location *loc, *next; |
c906108c | 8427 | |
8a3fe4f8 | 8428 | gdb_assert (bpt != NULL); |
c906108c SS |
8429 | |
8430 | /* Has this bp already been deleted? This can happen because multiple | |
8431 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
8432 | ||
8433 | One example of this happening is a watchpoint's scope bp. When the | |
8434 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
8435 | delete it. We also delete its scope bp. But the scope bp is marked | |
8436 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
8437 | checked for auto-deleting bp's, which are deleted. | |
8438 | ||
8439 | A real solution to this problem might involve reference counts in bp's, | |
8440 | and/or giving them pointers back to their referencing bpstat's, and | |
8441 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 8442 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
8443 | if (bpt->type == bp_none) |
8444 | return; | |
8445 | ||
383f836e | 8446 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 8447 | |
c906108c SS |
8448 | if (breakpoint_chain == bpt) |
8449 | breakpoint_chain = bpt->next; | |
8450 | ||
c906108c SS |
8451 | ALL_BREAKPOINTS (b) |
8452 | if (b->next == bpt) | |
c5aa993b JM |
8453 | { |
8454 | b->next = bpt->next; | |
8455 | break; | |
8456 | } | |
c906108c | 8457 | |
c906108c | 8458 | free_command_lines (&bpt->commands); |
c906108c | 8459 | if (bpt->cond_string != NULL) |
b8c9b27d | 8460 | xfree (bpt->cond_string); |
c906108c | 8461 | if (bpt->addr_string != NULL) |
b8c9b27d | 8462 | xfree (bpt->addr_string); |
c906108c | 8463 | if (bpt->exp != NULL) |
b8c9b27d | 8464 | xfree (bpt->exp); |
c906108c | 8465 | if (bpt->exp_string != NULL) |
b8c9b27d | 8466 | xfree (bpt->exp_string); |
c906108c SS |
8467 | if (bpt->val != NULL) |
8468 | value_free (bpt->val); | |
8469 | if (bpt->source_file != NULL) | |
b8c9b27d | 8470 | xfree (bpt->source_file); |
c906108c | 8471 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 8472 | xfree (bpt->exec_pathname); |
a96d9b2e | 8473 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
8474 | |
8475 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
8476 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
8477 | We just check stop_bpstat for now. Note that we cannot just |
8478 | remove bpstats pointing at bpt from the stop_bpstat list | |
8479 | entirely, as breakpoint commands are associated with the bpstat; | |
8480 | if we remove it here, then the later call to | |
8481 | bpstat_do_actions (&stop_bpstat); | |
8482 | in event-top.c won't do anything, and temporary breakpoints | |
8483 | with commands won't work. */ | |
a474d7c2 | 8484 | |
a474d7c2 | 8485 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
8486 | |
8487 | /* Now that breakpoint is removed from breakpoint | |
8488 | list, update the global location list. This | |
8489 | will remove locations that used to belong to | |
8490 | this breakpoint. Do this before freeing | |
8491 | the breakpoint itself, since remove_breakpoint | |
8492 | looks at location's owner. It might be better | |
8493 | design to have location completely self-contained, | |
8494 | but it's not the case now. */ | |
b60e7edf | 8495 | update_global_location_list (0); |
74960c60 VP |
8496 | |
8497 | ||
c906108c SS |
8498 | /* On the chance that someone will soon try again to delete this same |
8499 | bp, we mark it as deleted before freeing its storage. */ | |
8500 | bpt->type = bp_none; | |
8501 | ||
b8c9b27d | 8502 | xfree (bpt); |
c906108c SS |
8503 | } |
8504 | ||
4d6140d9 AC |
8505 | static void |
8506 | do_delete_breakpoint_cleanup (void *b) | |
8507 | { | |
8508 | delete_breakpoint (b); | |
8509 | } | |
8510 | ||
8511 | struct cleanup * | |
8512 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
8513 | { | |
8514 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
8515 | } | |
8516 | ||
c906108c | 8517 | void |
fba45db2 | 8518 | delete_command (char *arg, int from_tty) |
c906108c SS |
8519 | { |
8520 | struct breakpoint *b, *temp; | |
8521 | ||
ea9365bb TT |
8522 | dont_repeat (); |
8523 | ||
c906108c SS |
8524 | if (arg == 0) |
8525 | { | |
8526 | int breaks_to_delete = 0; | |
8527 | ||
8528 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
8529 | Do not delete internal or call-dummy breakpoints, these |
8530 | have to be deleted with an explicit breakpoint number argument. */ | |
8531 | ALL_BREAKPOINTS (b) | |
8532 | { | |
059fb39f PM |
8533 | if (b->type != bp_call_dummy |
8534 | && b->type != bp_shlib_event | |
4efc6507 | 8535 | && b->type != bp_jit_event |
059fb39f PM |
8536 | && b->type != bp_thread_event |
8537 | && b->type != bp_overlay_event | |
0fd8e87f | 8538 | && b->type != bp_longjmp_master |
059fb39f | 8539 | && b->number >= 0) |
973d738b DJ |
8540 | { |
8541 | breaks_to_delete = 1; | |
8542 | break; | |
8543 | } | |
c5aa993b | 8544 | } |
c906108c SS |
8545 | |
8546 | /* Ask user only if there are some breakpoints to delete. */ | |
8547 | if (!from_tty | |
e2e0b3e5 | 8548 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 8549 | { |
c5aa993b JM |
8550 | ALL_BREAKPOINTS_SAFE (b, temp) |
8551 | { | |
059fb39f PM |
8552 | if (b->type != bp_call_dummy |
8553 | && b->type != bp_shlib_event | |
8554 | && b->type != bp_thread_event | |
4efc6507 | 8555 | && b->type != bp_jit_event |
059fb39f | 8556 | && b->type != bp_overlay_event |
0fd8e87f | 8557 | && b->type != bp_longjmp_master |
059fb39f | 8558 | && b->number >= 0) |
c5aa993b JM |
8559 | delete_breakpoint (b); |
8560 | } | |
c906108c SS |
8561 | } |
8562 | } | |
8563 | else | |
8564 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8565 | } | |
8566 | ||
0d381245 VP |
8567 | static int |
8568 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 8569 | { |
0d381245 VP |
8570 | for (; loc; loc = loc->next) |
8571 | if (!loc->shlib_disabled) | |
8572 | return 0; | |
8573 | return 1; | |
fe3f5fa8 VP |
8574 | } |
8575 | ||
776592bf DE |
8576 | /* Subroutine of update_breakpoint_locations to simplify it. |
8577 | Return non-zero if multiple fns in list LOC have the same name. | |
8578 | Null names are ignored. */ | |
8579 | ||
8580 | static int | |
8581 | ambiguous_names_p (struct bp_location *loc) | |
8582 | { | |
8583 | struct bp_location *l; | |
8584 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
8585 | (int (*) (const void *, const void *)) streq, | |
8586 | NULL, xcalloc, xfree); | |
8587 | ||
8588 | for (l = loc; l != NULL; l = l->next) | |
8589 | { | |
8590 | const char **slot; | |
8591 | const char *name = l->function_name; | |
8592 | ||
8593 | /* Allow for some names to be NULL, ignore them. */ | |
8594 | if (name == NULL) | |
8595 | continue; | |
8596 | ||
8597 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
8598 | INSERT); | |
8599 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
8600 | NULL. */ | |
8601 | if (*slot != NULL) | |
8602 | { | |
8603 | htab_delete (htab); | |
8604 | return 1; | |
8605 | } | |
8606 | *slot = name; | |
8607 | } | |
8608 | ||
8609 | htab_delete (htab); | |
8610 | return 0; | |
8611 | } | |
8612 | ||
fe3f5fa8 | 8613 | static void |
0d381245 VP |
8614 | update_breakpoint_locations (struct breakpoint *b, |
8615 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
8616 | { |
8617 | int i; | |
8618 | char *s; | |
0d381245 VP |
8619 | struct bp_location *existing_locations = b->loc; |
8620 | ||
8621 | /* If there's no new locations, and all existing locations | |
8622 | are pending, don't do anything. This optimizes | |
8623 | the common case where all locations are in the same | |
8624 | shared library, that was unloaded. We'd like to | |
8625 | retain the location, so that when the library | |
8626 | is loaded again, we don't loose the enabled/disabled | |
8627 | status of the individual locations. */ | |
8628 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
8629 | return; |
8630 | ||
fe3f5fa8 VP |
8631 | b->loc = NULL; |
8632 | ||
0d381245 | 8633 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 8634 | { |
0d381245 | 8635 | struct bp_location *new_loc = |
39d61571 | 8636 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 8637 | |
0d381245 VP |
8638 | /* Reparse conditions, they might contain references to the |
8639 | old symtab. */ | |
8640 | if (b->cond_string != NULL) | |
8641 | { | |
8642 | struct gdb_exception e; | |
fe3f5fa8 | 8643 | |
0d381245 VP |
8644 | s = b->cond_string; |
8645 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
8646 | { | |
8647 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
8648 | 0); | |
8649 | } | |
8650 | if (e.reason < 0) | |
8651 | { | |
8652 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
8653 | b->number, e.message); | |
8654 | new_loc->enabled = 0; | |
8655 | } | |
8656 | } | |
fe3f5fa8 | 8657 | |
0d381245 VP |
8658 | if (b->source_file != NULL) |
8659 | xfree (b->source_file); | |
8660 | if (sals.sals[i].symtab == NULL) | |
8661 | b->source_file = NULL; | |
8662 | else | |
1b36a34b | 8663 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 8664 | |
0d381245 VP |
8665 | if (b->line_number == 0) |
8666 | b->line_number = sals.sals[i].line; | |
8667 | } | |
fe3f5fa8 | 8668 | |
514f746b AR |
8669 | /* Update locations of permanent breakpoints. */ |
8670 | if (b->enable_state == bp_permanent) | |
8671 | make_breakpoint_permanent (b); | |
8672 | ||
0d381245 VP |
8673 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
8674 | { | |
8675 | struct bp_location *e = existing_locations; | |
776592bf DE |
8676 | /* If there are multiple breakpoints with the same function name, |
8677 | e.g. for inline functions, comparing function names won't work. | |
8678 | Instead compare pc addresses; this is just a heuristic as things | |
8679 | may have moved, but in practice it gives the correct answer | |
8680 | often enough until a better solution is found. */ | |
8681 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
8682 | ||
0d381245 VP |
8683 | for (; e; e = e->next) |
8684 | { | |
8685 | if (!e->enabled && e->function_name) | |
8686 | { | |
8687 | struct bp_location *l = b->loc; | |
776592bf DE |
8688 | if (have_ambiguous_names) |
8689 | { | |
8690 | for (; l; l = l->next) | |
6c95b8df PA |
8691 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
8692 | l->pspace->aspace, l->address)) | |
776592bf DE |
8693 | { |
8694 | l->enabled = 0; | |
8695 | break; | |
8696 | } | |
8697 | } | |
8698 | else | |
8699 | { | |
8700 | for (; l; l = l->next) | |
8701 | if (l->function_name | |
8702 | && strcmp (e->function_name, l->function_name) == 0) | |
8703 | { | |
8704 | l->enabled = 0; | |
8705 | break; | |
8706 | } | |
8707 | } | |
0d381245 VP |
8708 | } |
8709 | } | |
8710 | } | |
fe3f5fa8 | 8711 | |
b60e7edf | 8712 | update_global_location_list (1); |
fe3f5fa8 VP |
8713 | } |
8714 | ||
8715 | ||
c906108c SS |
8716 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
8717 | The value we return ends up being the return value from catch_errors. | |
8718 | Unused in this case. */ | |
8719 | ||
8720 | static int | |
4efb68b1 | 8721 | breakpoint_re_set_one (void *bint) |
c906108c | 8722 | { |
53a5351d JM |
8723 | /* get past catch_errs */ |
8724 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
8725 | struct value *mark; |
8726 | int i; | |
fe3f5fa8 VP |
8727 | int not_found = 0; |
8728 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
8729 | struct symtabs_and_lines sals = {0}; |
8730 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 8731 | char *s; |
b5de0fa7 | 8732 | enum enable_state save_enable; |
fe3f5fa8 | 8733 | struct gdb_exception e; |
6c95b8df | 8734 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
8735 | |
8736 | switch (b->type) | |
8737 | { | |
8738 | case bp_none: | |
8a3fe4f8 | 8739 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 8740 | b->number); |
c906108c SS |
8741 | return 0; |
8742 | case bp_breakpoint: | |
8743 | case bp_hardware_breakpoint: | |
1042e4c0 | 8744 | case bp_tracepoint: |
8bea4e01 UW |
8745 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
8746 | if (b->enable_state == bp_startup_disabled) | |
8747 | return 0; | |
8748 | ||
c906108c SS |
8749 | if (b->addr_string == NULL) |
8750 | { | |
8751 | /* Anything without a string can't be re-set. */ | |
8752 | delete_breakpoint (b); | |
8753 | return 0; | |
8754 | } | |
c906108c SS |
8755 | |
8756 | set_language (b->language); | |
8757 | input_radix = b->input_radix; | |
8758 | s = b->addr_string; | |
6c95b8df PA |
8759 | |
8760 | save_current_space_and_thread (); | |
8761 | switch_to_program_space_and_thread (b->pspace); | |
8762 | ||
fe3f5fa8 | 8763 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 8764 | { |
fe3f5fa8 VP |
8765 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
8766 | not_found_ptr); | |
8767 | } | |
8768 | if (e.reason < 0) | |
8769 | { | |
8770 | int not_found_and_ok = 0; | |
8771 | /* For pending breakpoints, it's expected that parsing | |
8772 | will fail until the right shared library is loaded. | |
8773 | User has already told to create pending breakpoints and | |
8774 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
8775 | state, then user already saw the message about that breakpoint | |
8776 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
8777 | if (not_found |
8778 | && (b->condition_not_parsed | |
8779 | || (b->loc && b->loc->shlib_disabled) | |
8780 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
8781 | not_found_and_ok = 1; |
8782 | ||
8783 | if (!not_found_and_ok) | |
c906108c | 8784 | { |
fe3f5fa8 VP |
8785 | /* We surely don't want to warn about the same breakpoint |
8786 | 10 times. One solution, implemented here, is disable | |
8787 | the breakpoint on error. Another solution would be to | |
8788 | have separate 'warning emitted' flag. Since this | |
8789 | happens only when a binary has changed, I don't know | |
8790 | which approach is better. */ | |
8791 | b->enable_state = bp_disabled; | |
8792 | throw_exception (e); | |
c906108c | 8793 | } |
fe3f5fa8 | 8794 | } |
c906108c | 8795 | |
6c95b8df | 8796 | if (!not_found) |
fe3f5fa8 | 8797 | { |
6c95b8df PA |
8798 | gdb_assert (sals.nelts == 1); |
8799 | ||
8800 | resolve_sal_pc (&sals.sals[0]); | |
8801 | if (b->condition_not_parsed && s && s[0]) | |
8802 | { | |
8803 | char *cond_string = 0; | |
8804 | int thread = -1; | |
8805 | int task = 0; | |
8806 | ||
8807 | find_condition_and_thread (s, sals.sals[0].pc, | |
8808 | &cond_string, &thread, &task); | |
8809 | if (cond_string) | |
8810 | b->cond_string = cond_string; | |
8811 | b->thread = thread; | |
8812 | b->task = task; | |
8813 | b->condition_not_parsed = 0; | |
8814 | } | |
8815 | ||
8816 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 8817 | } |
6c95b8df PA |
8818 | |
8819 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 8820 | update_breakpoint_locations (b, expanded); |
c906108c SS |
8821 | break; |
8822 | ||
8823 | case bp_watchpoint: | |
8824 | case bp_hardware_watchpoint: | |
8825 | case bp_read_watchpoint: | |
8826 | case bp_access_watchpoint: | |
0b3de036 VP |
8827 | /* Watchpoint can be either on expression using entirely global variables, |
8828 | or it can be on local variables. | |
8829 | ||
8830 | Watchpoints of the first kind are never auto-deleted, and even persist | |
8831 | across program restarts. Since they can use variables from shared | |
8832 | libraries, we need to reparse expression as libraries are loaded | |
8833 | and unloaded. | |
8834 | ||
8835 | Watchpoints on local variables can also change meaning as result | |
8836 | of solib event. For example, if a watchpoint uses both a local and | |
8837 | a global variables in expression, it's a local watchpoint, but | |
8838 | unloading of a shared library will make the expression invalid. | |
8839 | This is not a very common use case, but we still re-evaluate | |
8840 | expression, to avoid surprises to the user. | |
8841 | ||
8842 | Note that for local watchpoints, we re-evaluate it only if | |
8843 | watchpoints frame id is still valid. If it's not, it means | |
8844 | the watchpoint is out of scope and will be deleted soon. In fact, | |
8845 | I'm not sure we'll ever be called in this case. | |
8846 | ||
8847 | If a local watchpoint's frame id is still valid, then | |
8848 | b->exp_valid_block is likewise valid, and we can safely use it. | |
8849 | ||
8850 | Don't do anything about disabled watchpoints, since they will | |
8851 | be reevaluated again when enabled. */ | |
a5606eee | 8852 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 8853 | break; |
c5aa993b JM |
8854 | /* We needn't really do anything to reset these, since the mask |
8855 | that requests them is unaffected by e.g., new libraries being | |
8856 | loaded. */ | |
ce78b96d | 8857 | case bp_catchpoint: |
c906108c | 8858 | break; |
c5aa993b | 8859 | |
c906108c | 8860 | default: |
a3f17187 | 8861 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 8862 | /* fall through */ |
0fd8e87f UW |
8863 | /* Delete overlay event and longjmp master breakpoints; they will be |
8864 | reset later by breakpoint_re_set. */ | |
1900040c | 8865 | case bp_overlay_event: |
0fd8e87f | 8866 | case bp_longjmp_master: |
c906108c SS |
8867 | delete_breakpoint (b); |
8868 | break; | |
8869 | ||
c5aa993b JM |
8870 | /* This breakpoint is special, it's set up when the inferior |
8871 | starts and we really don't want to touch it. */ | |
c906108c SS |
8872 | case bp_shlib_event: |
8873 | ||
c4093a6a JM |
8874 | /* Like bp_shlib_event, this breakpoint type is special. |
8875 | Once it is set up, we do not want to touch it. */ | |
8876 | case bp_thread_event: | |
8877 | ||
c5aa993b JM |
8878 | /* Keep temporary breakpoints, which can be encountered when we step |
8879 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
8880 | Otherwise these should have been blown away via the cleanup chain | |
8881 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
8882 | case bp_until: |
8883 | case bp_finish: | |
8884 | case bp_watchpoint_scope: | |
8885 | case bp_call_dummy: | |
8886 | case bp_step_resume: | |
611c83ae PA |
8887 | case bp_longjmp: |
8888 | case bp_longjmp_resume: | |
4efc6507 | 8889 | case bp_jit_event: |
c906108c SS |
8890 | break; |
8891 | } | |
8892 | ||
6c95b8df | 8893 | do_cleanups (cleanups); |
c906108c SS |
8894 | return 0; |
8895 | } | |
8896 | ||
69de3c6a | 8897 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 8898 | void |
69de3c6a | 8899 | breakpoint_re_set (void) |
c906108c SS |
8900 | { |
8901 | struct breakpoint *b, *temp; | |
8902 | enum language save_language; | |
8903 | int save_input_radix; | |
6c95b8df | 8904 | struct cleanup *old_chain; |
c5aa993b | 8905 | |
c906108c SS |
8906 | save_language = current_language->la_language; |
8907 | save_input_radix = input_radix; | |
6c95b8df PA |
8908 | old_chain = save_current_program_space (); |
8909 | ||
c906108c | 8910 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 8911 | { |
53a5351d | 8912 | /* Format possible error msg */ |
fe3f5fa8 | 8913 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
8914 | b->number); |
8915 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 8916 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 8917 | do_cleanups (cleanups); |
c5aa993b | 8918 | } |
c906108c SS |
8919 | set_language (save_language); |
8920 | input_radix = save_input_radix; | |
e62c965a | 8921 | |
0756c555 | 8922 | jit_breakpoint_re_set (); |
4efc6507 | 8923 | |
6c95b8df PA |
8924 | do_cleanups (old_chain); |
8925 | ||
69de3c6a | 8926 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
8927 | create_longjmp_master_breakpoint ("longjmp"); |
8928 | create_longjmp_master_breakpoint ("_longjmp"); | |
8929 | create_longjmp_master_breakpoint ("siglongjmp"); | |
8930 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
8931 | } |
8932 | \f | |
c906108c SS |
8933 | /* Reset the thread number of this breakpoint: |
8934 | ||
8935 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 8936 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 8937 | void |
fba45db2 | 8938 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
8939 | { |
8940 | if (b->thread != -1) | |
8941 | { | |
39f77062 KB |
8942 | if (in_thread_list (inferior_ptid)) |
8943 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
8944 | |
8945 | /* We're being called after following a fork. The new fork is | |
8946 | selected as current, and unless this was a vfork will have a | |
8947 | different program space from the original thread. Reset that | |
8948 | as well. */ | |
8949 | b->loc->pspace = current_program_space; | |
c906108c SS |
8950 | } |
8951 | } | |
8952 | ||
03ac34d5 MS |
8953 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
8954 | If from_tty is nonzero, it prints a message to that effect, | |
8955 | which ends with a period (no newline). */ | |
8956 | ||
c906108c | 8957 | void |
fba45db2 | 8958 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 8959 | { |
52f0bd74 | 8960 | struct breakpoint *b; |
c906108c SS |
8961 | |
8962 | if (count < 0) | |
8963 | count = 0; | |
8964 | ||
8965 | ALL_BREAKPOINTS (b) | |
8966 | if (b->number == bptnum) | |
c5aa993b JM |
8967 | { |
8968 | b->ignore_count = count; | |
221ea385 KS |
8969 | if (from_tty) |
8970 | { | |
8971 | if (count == 0) | |
a3f17187 | 8972 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
8973 | bptnum); |
8974 | else if (count == 1) | |
a3f17187 | 8975 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
8976 | bptnum); |
8977 | else | |
a3f17187 | 8978 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
8979 | count, bptnum); |
8980 | } | |
c5aa993b | 8981 | breakpoints_changed (); |
383f836e | 8982 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
8983 | return; |
8984 | } | |
c906108c | 8985 | |
8a3fe4f8 | 8986 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
8987 | } |
8988 | ||
b2175913 MS |
8989 | void |
8990 | make_breakpoint_silent (struct breakpoint *b) | |
8991 | { | |
8992 | /* Silence the breakpoint. */ | |
8993 | b->silent = 1; | |
8994 | } | |
8995 | ||
c906108c SS |
8996 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
8997 | ||
8998 | static void | |
fba45db2 | 8999 | ignore_command (char *args, int from_tty) |
c906108c SS |
9000 | { |
9001 | char *p = args; | |
52f0bd74 | 9002 | int num; |
c906108c SS |
9003 | |
9004 | if (p == 0) | |
e2e0b3e5 | 9005 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9006 | |
c906108c | 9007 | num = get_number (&p); |
5c44784c | 9008 | if (num == 0) |
8a3fe4f8 | 9009 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9010 | if (*p == 0) |
8a3fe4f8 | 9011 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9012 | |
9013 | set_ignore_count (num, | |
9014 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9015 | from_tty); | |
221ea385 KS |
9016 | if (from_tty) |
9017 | printf_filtered ("\n"); | |
c906108c SS |
9018 | } |
9019 | \f | |
9020 | /* Call FUNCTION on each of the breakpoints | |
9021 | whose numbers are given in ARGS. */ | |
9022 | ||
9023 | static void | |
831662b3 | 9024 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 9025 | { |
52f0bd74 | 9026 | char *p = args; |
c906108c | 9027 | char *p1; |
52f0bd74 AC |
9028 | int num; |
9029 | struct breakpoint *b, *tmp; | |
11cf8741 | 9030 | int match; |
c906108c SS |
9031 | |
9032 | if (p == 0) | |
e2e0b3e5 | 9033 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9034 | |
9035 | while (*p) | |
9036 | { | |
11cf8741 | 9037 | match = 0; |
c906108c | 9038 | p1 = p; |
c5aa993b | 9039 | |
5c44784c JM |
9040 | num = get_number_or_range (&p1); |
9041 | if (num == 0) | |
c5aa993b | 9042 | { |
8a3fe4f8 | 9043 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9044 | } |
9045 | else | |
9046 | { | |
9047 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9048 | if (b->number == num) | |
9049 | { | |
9050 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9051 | match = 1; |
5c44784c JM |
9052 | function (b); |
9053 | if (related_breakpoint) | |
9054 | function (related_breakpoint); | |
11cf8741 | 9055 | break; |
5c44784c | 9056 | } |
11cf8741 | 9057 | if (match == 0) |
a3f17187 | 9058 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9059 | } |
c906108c SS |
9060 | p = p1; |
9061 | } | |
9062 | } | |
9063 | ||
0d381245 VP |
9064 | static struct bp_location * |
9065 | find_location_by_number (char *number) | |
9066 | { | |
9067 | char *dot = strchr (number, '.'); | |
9068 | char *p1; | |
9069 | int bp_num; | |
9070 | int loc_num; | |
9071 | struct breakpoint *b; | |
9072 | struct bp_location *loc; | |
9073 | ||
9074 | *dot = '\0'; | |
9075 | ||
9076 | p1 = number; | |
9077 | bp_num = get_number_or_range (&p1); | |
9078 | if (bp_num == 0) | |
9079 | error (_("Bad breakpoint number '%s'"), number); | |
9080 | ||
9081 | ALL_BREAKPOINTS (b) | |
9082 | if (b->number == bp_num) | |
9083 | { | |
9084 | break; | |
9085 | } | |
9086 | ||
9087 | if (!b || b->number != bp_num) | |
9088 | error (_("Bad breakpoint number '%s'"), number); | |
9089 | ||
9090 | p1 = dot+1; | |
9091 | loc_num = get_number_or_range (&p1); | |
9092 | if (loc_num == 0) | |
9093 | error (_("Bad breakpoint location number '%s'"), number); | |
9094 | ||
9095 | --loc_num; | |
9096 | loc = b->loc; | |
9097 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9098 | ; | |
9099 | if (!loc) | |
9100 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9101 | ||
9102 | return loc; | |
9103 | } | |
9104 | ||
9105 | ||
1900040c MS |
9106 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9107 | If from_tty is nonzero, it prints a message to that effect, | |
9108 | which ends with a period (no newline). */ | |
9109 | ||
c906108c | 9110 | void |
fba45db2 | 9111 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9112 | { |
9113 | /* Never disable a watchpoint scope breakpoint; we want to | |
9114 | hit them when we leave scope so we can delete both the | |
9115 | watchpoint and its scope breakpoint at that time. */ | |
9116 | if (bpt->type == bp_watchpoint_scope) | |
9117 | return; | |
9118 | ||
c2c6d25f | 9119 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9120 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9121 | return; |
9122 | ||
b5de0fa7 | 9123 | bpt->enable_state = bp_disabled; |
c906108c | 9124 | |
b60e7edf | 9125 | update_global_location_list (0); |
c906108c | 9126 | |
383f836e | 9127 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9128 | } |
9129 | ||
c906108c | 9130 | static void |
fba45db2 | 9131 | disable_command (char *args, int from_tty) |
c906108c | 9132 | { |
52f0bd74 | 9133 | struct breakpoint *bpt; |
c906108c SS |
9134 | if (args == 0) |
9135 | ALL_BREAKPOINTS (bpt) | |
9136 | switch (bpt->type) | |
c5aa993b JM |
9137 | { |
9138 | case bp_none: | |
8a3fe4f8 | 9139 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9140 | bpt->number); |
c5aa993b JM |
9141 | continue; |
9142 | case bp_breakpoint: | |
1042e4c0 | 9143 | case bp_tracepoint: |
ce78b96d | 9144 | case bp_catchpoint: |
c5aa993b JM |
9145 | case bp_hardware_breakpoint: |
9146 | case bp_watchpoint: | |
9147 | case bp_hardware_watchpoint: | |
9148 | case bp_read_watchpoint: | |
9149 | case bp_access_watchpoint: | |
9150 | disable_breakpoint (bpt); | |
9151 | default: | |
9152 | continue; | |
9153 | } | |
0d381245 VP |
9154 | else if (strchr (args, '.')) |
9155 | { | |
9156 | struct bp_location *loc = find_location_by_number (args); | |
9157 | if (loc) | |
9158 | loc->enabled = 0; | |
b60e7edf | 9159 | update_global_location_list (0); |
0d381245 | 9160 | } |
c906108c SS |
9161 | else |
9162 | map_breakpoint_numbers (args, disable_breakpoint); | |
9163 | } | |
9164 | ||
9165 | static void | |
fba45db2 | 9166 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9167 | { |
c906108c SS |
9168 | int target_resources_ok, other_type_used; |
9169 | struct value *mark; | |
9170 | ||
9171 | if (bpt->type == bp_hardware_breakpoint) | |
9172 | { | |
9173 | int i; | |
c5aa993b | 9174 | i = hw_breakpoint_used_count (); |
53a5351d | 9175 | target_resources_ok = |
d92524f1 | 9176 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9177 | i + 1, 0); |
c906108c | 9178 | if (target_resources_ok == 0) |
8a3fe4f8 | 9179 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9180 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9181 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9182 | } |
9183 | ||
059fb39f PM |
9184 | if (bpt->type == bp_watchpoint |
9185 | || bpt->type == bp_hardware_watchpoint | |
9186 | || bpt->type == bp_read_watchpoint | |
9187 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9188 | { |
dde02812 ES |
9189 | struct gdb_exception e; |
9190 | ||
9191 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9192 | { |
dde02812 | 9193 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9194 | } |
dde02812 | 9195 | if (e.reason < 0) |
c5aa993b | 9196 | { |
dde02812 ES |
9197 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9198 | bpt->number); | |
9199 | return; | |
c5aa993b | 9200 | } |
c906108c | 9201 | } |
0101ce28 | 9202 | |
b4c291bb KH |
9203 | if (bpt->enable_state != bp_permanent) |
9204 | bpt->enable_state = bp_enabled; | |
9205 | bpt->disposition = disposition; | |
b60e7edf | 9206 | update_global_location_list (1); |
b4c291bb KH |
9207 | breakpoints_changed (); |
9208 | ||
383f836e | 9209 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9210 | } |
9211 | ||
fe3f5fa8 | 9212 | |
c906108c | 9213 | void |
fba45db2 | 9214 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9215 | { |
9216 | do_enable_breakpoint (bpt, bpt->disposition); | |
9217 | } | |
9218 | ||
9219 | /* The enable command enables the specified breakpoints (or all defined | |
9220 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 9221 | in stopping the inferior. */ |
c906108c | 9222 | |
c906108c | 9223 | static void |
fba45db2 | 9224 | enable_command (char *args, int from_tty) |
c906108c | 9225 | { |
52f0bd74 | 9226 | struct breakpoint *bpt; |
c906108c SS |
9227 | if (args == 0) |
9228 | ALL_BREAKPOINTS (bpt) | |
9229 | switch (bpt->type) | |
c5aa993b JM |
9230 | { |
9231 | case bp_none: | |
8a3fe4f8 | 9232 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 9233 | bpt->number); |
c5aa993b JM |
9234 | continue; |
9235 | case bp_breakpoint: | |
1042e4c0 | 9236 | case bp_tracepoint: |
ce78b96d | 9237 | case bp_catchpoint: |
c5aa993b JM |
9238 | case bp_hardware_breakpoint: |
9239 | case bp_watchpoint: | |
9240 | case bp_hardware_watchpoint: | |
9241 | case bp_read_watchpoint: | |
9242 | case bp_access_watchpoint: | |
9243 | enable_breakpoint (bpt); | |
9244 | default: | |
9245 | continue; | |
9246 | } | |
0d381245 VP |
9247 | else if (strchr (args, '.')) |
9248 | { | |
9249 | struct bp_location *loc = find_location_by_number (args); | |
9250 | if (loc) | |
9251 | loc->enabled = 1; | |
b60e7edf | 9252 | update_global_location_list (1); |
0d381245 | 9253 | } |
c906108c SS |
9254 | else |
9255 | map_breakpoint_numbers (args, enable_breakpoint); | |
9256 | } | |
9257 | ||
9258 | static void | |
fba45db2 | 9259 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 9260 | { |
b5de0fa7 | 9261 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
9262 | } |
9263 | ||
c906108c | 9264 | static void |
fba45db2 | 9265 | enable_once_command (char *args, int from_tty) |
c906108c SS |
9266 | { |
9267 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
9268 | } | |
9269 | ||
9270 | static void | |
fba45db2 | 9271 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9272 | { |
b5de0fa7 | 9273 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
9274 | } |
9275 | ||
c906108c | 9276 | static void |
fba45db2 | 9277 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
9278 | { |
9279 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
9280 | } | |
9281 | \f | |
fa8d40ab JJ |
9282 | static void |
9283 | set_breakpoint_cmd (char *args, int from_tty) | |
9284 | { | |
9285 | } | |
9286 | ||
9287 | static void | |
9288 | show_breakpoint_cmd (char *args, int from_tty) | |
9289 | { | |
9290 | } | |
9291 | ||
c906108c SS |
9292 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
9293 | ||
9294 | struct symtabs_and_lines | |
fba45db2 | 9295 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
9296 | { |
9297 | struct symtabs_and_lines sals; | |
9298 | if (string == 0) | |
8a3fe4f8 | 9299 | error (_("Empty line specification.")); |
c906108c SS |
9300 | if (default_breakpoint_valid) |
9301 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
9302 | default_breakpoint_symtab, |
9303 | default_breakpoint_line, | |
68219205 | 9304 | (char ***) NULL, NULL); |
c906108c SS |
9305 | else |
9306 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 9307 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 9308 | if (*string) |
8a3fe4f8 | 9309 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
9310 | return sals; |
9311 | } | |
8181d85f DJ |
9312 | |
9313 | /* Create and insert a raw software breakpoint at PC. Return an | |
9314 | identifier, which should be used to remove the breakpoint later. | |
9315 | In general, places which call this should be using something on the | |
9316 | breakpoint chain instead; this function should be eliminated | |
9317 | someday. */ | |
9318 | ||
9319 | void * | |
6c95b8df PA |
9320 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
9321 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
9322 | { |
9323 | struct bp_target_info *bp_tgt; | |
9324 | ||
6c95b8df | 9325 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 9326 | |
6c95b8df | 9327 | bp_tgt->placed_address_space = aspace; |
8181d85f | 9328 | bp_tgt->placed_address = pc; |
6c95b8df | 9329 | |
a6d9a66e | 9330 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
9331 | { |
9332 | /* Could not insert the breakpoint. */ | |
9333 | xfree (bp_tgt); | |
9334 | return NULL; | |
9335 | } | |
9336 | ||
9337 | return bp_tgt; | |
9338 | } | |
9339 | ||
9340 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
9341 | ||
9342 | int | |
a6d9a66e | 9343 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
9344 | { |
9345 | struct bp_target_info *bp_tgt = bp; | |
9346 | int ret; | |
9347 | ||
a6d9a66e | 9348 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
9349 | xfree (bp_tgt); |
9350 | ||
9351 | return ret; | |
9352 | } | |
9353 | ||
9354 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
9355 | ||
9356 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 9357 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
9358 | |
9359 | /* Create and insert a breakpoint for software single step. */ | |
9360 | ||
9361 | void | |
6c95b8df PA |
9362 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
9363 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
9364 | { |
9365 | void **bpt_p; | |
9366 | ||
9367 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
9368 | { |
9369 | bpt_p = &single_step_breakpoints[0]; | |
9370 | single_step_gdbarch[0] = gdbarch; | |
9371 | } | |
8181d85f DJ |
9372 | else |
9373 | { | |
9374 | gdb_assert (single_step_breakpoints[1] == NULL); | |
9375 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 9376 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
9377 | } |
9378 | ||
9379 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
9380 | to only create the breakpoints once, and actually put them on the | |
9381 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
9382 | adjust the addresses each time they were needed. Doing this requires | |
9383 | corresponding changes elsewhere where single step breakpoints are | |
9384 | handled, however. So, for now, we use this. */ | |
9385 | ||
6c95b8df | 9386 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 9387 | if (*bpt_p == NULL) |
5af949e3 UW |
9388 | error (_("Could not insert single-step breakpoint at %s"), |
9389 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
9390 | } |
9391 | ||
9392 | /* Remove and delete any breakpoints used for software single step. */ | |
9393 | ||
9394 | void | |
9395 | remove_single_step_breakpoints (void) | |
9396 | { | |
9397 | gdb_assert (single_step_breakpoints[0] != NULL); | |
9398 | ||
9399 | /* See insert_single_step_breakpoint for more about this deprecated | |
9400 | call. */ | |
a6d9a66e UW |
9401 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
9402 | single_step_breakpoints[0]); | |
9403 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
9404 | single_step_breakpoints[0] = NULL; |
9405 | ||
9406 | if (single_step_breakpoints[1] != NULL) | |
9407 | { | |
a6d9a66e UW |
9408 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
9409 | single_step_breakpoints[1]); | |
9410 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
9411 | single_step_breakpoints[1] = NULL; |
9412 | } | |
9413 | } | |
9414 | ||
1aafd4da UW |
9415 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
9416 | ||
9417 | static int | |
6c95b8df | 9418 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
9419 | { |
9420 | int i; | |
9421 | ||
9422 | for (i = 0; i < 2; i++) | |
9423 | { | |
9424 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
9425 | if (bp_tgt |
9426 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
9427 | bp_tgt->placed_address, | |
9428 | aspace, pc)) | |
1aafd4da UW |
9429 | return 1; |
9430 | } | |
9431 | ||
9432 | return 0; | |
9433 | } | |
9434 | ||
a96d9b2e SDJ |
9435 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
9436 | non-zero otherwise. */ | |
9437 | static int | |
9438 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
9439 | { | |
9440 | if (syscall_catchpoint_p (bp) | |
9441 | && bp->enable_state != bp_disabled | |
9442 | && bp->enable_state != bp_call_disabled) | |
9443 | return 1; | |
9444 | else | |
9445 | return 0; | |
9446 | } | |
9447 | ||
9448 | int | |
9449 | catch_syscall_enabled (void) | |
9450 | { | |
9451 | struct inferior *inf = current_inferior (); | |
9452 | ||
9453 | return inf->total_syscalls_count != 0; | |
9454 | } | |
9455 | ||
9456 | int | |
9457 | catching_syscall_number (int syscall_number) | |
9458 | { | |
9459 | struct breakpoint *bp; | |
9460 | ||
9461 | ALL_BREAKPOINTS (bp) | |
9462 | if (is_syscall_catchpoint_enabled (bp)) | |
9463 | { | |
9464 | if (bp->syscalls_to_be_caught) | |
9465 | { | |
9466 | int i, iter; | |
9467 | for (i = 0; | |
9468 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
9469 | i++) | |
9470 | if (syscall_number == iter) | |
9471 | return 1; | |
9472 | } | |
9473 | else | |
9474 | return 1; | |
9475 | } | |
9476 | ||
9477 | return 0; | |
9478 | } | |
9479 | ||
9480 | /* Complete syscall names. Used by "catch syscall". */ | |
9481 | static char ** | |
9482 | catch_syscall_completer (struct cmd_list_element *cmd, | |
9483 | char *text, char *word) | |
9484 | { | |
9485 | const char **list = get_syscall_names (); | |
9486 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
9487 | } | |
9488 | ||
1042e4c0 SS |
9489 | /* Tracepoint-specific operations. */ |
9490 | ||
9491 | /* Set tracepoint count to NUM. */ | |
9492 | static void | |
9493 | set_tracepoint_count (int num) | |
9494 | { | |
9495 | tracepoint_count = num; | |
4fa62494 | 9496 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
9497 | } |
9498 | ||
9499 | void | |
9500 | trace_command (char *arg, int from_tty) | |
9501 | { | |
a6d9a66e UW |
9502 | break_command_really (get_current_arch (), |
9503 | arg, | |
1042e4c0 SS |
9504 | NULL, 0, 1 /* parse arg */, |
9505 | 0 /* tempflag */, 0 /* hardwareflag */, | |
9506 | 1 /* traceflag */, | |
9507 | 0 /* Ignore count */, | |
9508 | pending_break_support, | |
9509 | NULL, | |
9510 | from_tty, | |
9511 | 1 /* enabled */); | |
9512 | set_tracepoint_count (breakpoint_count); | |
9513 | } | |
9514 | ||
9515 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
9516 | omitted. */ | |
9517 | ||
9518 | static void | |
9519 | tracepoints_info (char *tpnum_exp, int from_tty) | |
9520 | { | |
9521 | struct breakpoint *b; | |
9522 | int tps_to_list = 0; | |
9523 | ||
9524 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
9525 | if (tpnum_exp == 0) | |
9526 | { | |
9527 | ALL_TRACEPOINTS (b) | |
9528 | { | |
9529 | if (b->number >= 0) | |
9530 | { | |
9531 | tps_to_list = 1; | |
9532 | break; | |
9533 | } | |
9534 | } | |
9535 | if (!tps_to_list) | |
9536 | { | |
9537 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
9538 | return; | |
9539 | } | |
9540 | } | |
9541 | ||
9542 | /* Otherwise be the same as "info break". */ | |
9543 | breakpoints_info (tpnum_exp, from_tty); | |
9544 | } | |
9545 | ||
9546 | /* The 'enable trace' command enables tracepoints. | |
9547 | Not supported by all targets. */ | |
9548 | static void | |
9549 | enable_trace_command (char *args, int from_tty) | |
9550 | { | |
9551 | enable_command (args, from_tty); | |
9552 | } | |
9553 | ||
9554 | /* The 'disable trace' command disables tracepoints. | |
9555 | Not supported by all targets. */ | |
9556 | static void | |
9557 | disable_trace_command (char *args, int from_tty) | |
9558 | { | |
9559 | disable_command (args, from_tty); | |
9560 | } | |
9561 | ||
9562 | /* Remove a tracepoint (or all if no argument) */ | |
9563 | static void | |
9564 | delete_trace_command (char *arg, int from_tty) | |
9565 | { | |
9566 | struct breakpoint *b, *temp; | |
9567 | ||
9568 | dont_repeat (); | |
9569 | ||
9570 | if (arg == 0) | |
9571 | { | |
9572 | int breaks_to_delete = 0; | |
9573 | ||
9574 | /* Delete all breakpoints if no argument. | |
9575 | Do not delete internal or call-dummy breakpoints, these | |
9576 | have to be deleted with an explicit breakpoint number argument. */ | |
9577 | ALL_TRACEPOINTS (b) | |
9578 | { | |
9579 | if (b->number >= 0) | |
9580 | { | |
9581 | breaks_to_delete = 1; | |
9582 | break; | |
9583 | } | |
9584 | } | |
9585 | ||
9586 | /* Ask user only if there are some breakpoints to delete. */ | |
9587 | if (!from_tty | |
9588 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
9589 | { | |
9590 | ALL_BREAKPOINTS_SAFE (b, temp) | |
9591 | { | |
059fb39f PM |
9592 | if (b->type == bp_tracepoint |
9593 | && b->number >= 0) | |
1042e4c0 SS |
9594 | delete_breakpoint (b); |
9595 | } | |
9596 | } | |
9597 | } | |
9598 | else | |
9599 | map_breakpoint_numbers (arg, delete_breakpoint); | |
9600 | } | |
9601 | ||
9602 | /* Set passcount for tracepoint. | |
9603 | ||
9604 | First command argument is passcount, second is tracepoint number. | |
9605 | If tracepoint number omitted, apply to most recently defined. | |
9606 | Also accepts special argument "all". */ | |
9607 | ||
9608 | static void | |
9609 | trace_pass_command (char *args, int from_tty) | |
9610 | { | |
9611 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
9612 | unsigned int count; | |
9613 | int all = 0; | |
9614 | ||
9615 | if (args == 0 || *args == 0) | |
9616 | error (_("passcount command requires an argument (count + optional TP num)")); | |
9617 | ||
9618 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
9619 | ||
9620 | while (*args && isspace ((int) *args)) | |
9621 | args++; | |
9622 | ||
9623 | if (*args && strncasecmp (args, "all", 3) == 0) | |
9624 | { | |
9625 | args += 3; /* Skip special argument "all". */ | |
9626 | all = 1; | |
9627 | if (*args) | |
9628 | error (_("Junk at end of arguments.")); | |
9629 | } | |
9630 | else | |
9631 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
9632 | ||
9633 | do | |
9634 | { | |
9635 | if (t1) | |
9636 | { | |
9637 | ALL_TRACEPOINTS (t2) | |
9638 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
9639 | { | |
9640 | t2->pass_count = count; | |
9641 | observer_notify_tracepoint_modified (t2->number); | |
9642 | if (from_tty) | |
9643 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
9644 | t2->number, count); | |
9645 | } | |
9646 | if (! all && *args) | |
9647 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
9648 | } | |
9649 | } | |
9650 | while (*args); | |
9651 | } | |
9652 | ||
9653 | struct breakpoint * | |
9654 | get_tracepoint (int num) | |
9655 | { | |
9656 | struct breakpoint *t; | |
9657 | ||
9658 | ALL_TRACEPOINTS (t) | |
9659 | if (t->number == num) | |
9660 | return t; | |
9661 | ||
9662 | return NULL; | |
9663 | } | |
9664 | ||
9665 | /* Utility: parse a tracepoint number and look it up in the list. | |
9666 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
9667 | if OPTIONAL_P is true, then if the argument is missing, the most | |
9668 | recent tracepoint (tracepoint_count) is returned. */ | |
9669 | struct breakpoint * | |
9670 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
9671 | { | |
9672 | extern int tracepoint_count; | |
9673 | struct breakpoint *t; | |
9674 | int tpnum; | |
9675 | char *instring = arg == NULL ? NULL : *arg; | |
9676 | ||
9677 | if (arg == NULL || *arg == NULL || ! **arg) | |
9678 | { | |
9679 | if (optional_p) | |
9680 | tpnum = tracepoint_count; | |
9681 | else | |
9682 | error_no_arg (_("tracepoint number")); | |
9683 | } | |
9684 | else | |
9685 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
9686 | ||
9687 | if (tpnum <= 0) | |
9688 | { | |
9689 | if (instring && *instring) | |
9690 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
9691 | instring); | |
9692 | else | |
9693 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
9694 | return NULL; | |
9695 | } | |
9696 | ||
9697 | ALL_TRACEPOINTS (t) | |
9698 | if (t->number == tpnum) | |
9699 | { | |
9700 | return t; | |
9701 | } | |
9702 | ||
9703 | /* FIXME: if we are in the middle of a range we don't want to give | |
9704 | a message. The current interface to get_number_or_range doesn't | |
9705 | allow us to discover this. */ | |
9706 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
9707 | return NULL; | |
9708 | } | |
9709 | ||
9710 | /* save-tracepoints command */ | |
9711 | static void | |
9712 | tracepoint_save_command (char *args, int from_tty) | |
9713 | { | |
9714 | struct breakpoint *tp; | |
9715 | int any_tp = 0; | |
9716 | struct action_line *line; | |
9717 | FILE *fp; | |
9718 | char *i1 = " ", *i2 = " "; | |
9719 | char *indent, *actionline, *pathname; | |
9720 | char tmp[40]; | |
9721 | struct cleanup *cleanup; | |
9722 | ||
9723 | if (args == 0 || *args == 0) | |
9724 | error (_("Argument required (file name in which to save tracepoints)")); | |
9725 | ||
9726 | /* See if we have anything to save. */ | |
9727 | ALL_TRACEPOINTS (tp) | |
9728 | { | |
9729 | any_tp = 1; | |
9730 | break; | |
9731 | } | |
9732 | if (!any_tp) | |
9733 | { | |
9734 | warning (_("save-tracepoints: no tracepoints to save.")); | |
9735 | return; | |
9736 | } | |
9737 | ||
9738 | pathname = tilde_expand (args); | |
9739 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
9740 | fp = fopen (pathname, "w"); |
9741 | if (!fp) | |
1042e4c0 SS |
9742 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
9743 | args, safe_strerror (errno)); | |
9744 | make_cleanup_fclose (fp); | |
9745 | ||
9746 | ALL_TRACEPOINTS (tp) | |
9747 | { | |
9748 | if (tp->addr_string) | |
9749 | fprintf (fp, "trace %s\n", tp->addr_string); | |
9750 | else | |
9751 | { | |
9752 | sprintf_vma (tmp, tp->loc->address); | |
9753 | fprintf (fp, "trace *0x%s\n", tmp); | |
9754 | } | |
9755 | ||
9756 | if (tp->pass_count) | |
9757 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
9758 | ||
9759 | if (tp->actions) | |
9760 | { | |
9761 | fprintf (fp, " actions\n"); | |
9762 | indent = i1; | |
9763 | for (line = tp->actions; line; line = line->next) | |
9764 | { | |
9765 | struct cmd_list_element *cmd; | |
9766 | ||
9767 | QUIT; /* allow user to bail out with ^C */ | |
9768 | actionline = line->action; | |
9769 | while (isspace ((int) *actionline)) | |
9770 | actionline++; | |
9771 | ||
9772 | fprintf (fp, "%s%s\n", indent, actionline); | |
9773 | if (*actionline != '#') /* skip for comment lines */ | |
9774 | { | |
9775 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
9776 | if (cmd == 0) | |
9777 | error (_("Bad action list item: %s"), actionline); | |
9778 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
9779 | indent = i2; | |
9780 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
9781 | indent = i1; | |
9782 | } | |
9783 | } | |
9784 | } | |
9785 | } | |
9786 | do_cleanups (cleanup); | |
9787 | if (from_tty) | |
9788 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
9789 | return; | |
9790 | } | |
9791 | ||
9792 | /* Create a vector of all tracepoints. */ | |
9793 | ||
9794 | VEC(breakpoint_p) * | |
9795 | all_tracepoints () | |
9796 | { | |
9797 | VEC(breakpoint_p) *tp_vec = 0; | |
9798 | struct breakpoint *tp; | |
9799 | ||
9800 | ALL_TRACEPOINTS (tp) | |
9801 | { | |
9802 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
9803 | } | |
9804 | ||
9805 | return tp_vec; | |
9806 | } | |
9807 | ||
c906108c | 9808 | \f |
31e2b00f AS |
9809 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
9810 | It is defined as a macro to prevent duplication. | |
9811 | COMMAND should be a string constant containing the name of the command. */ | |
9812 | #define BREAK_ARGS_HELP(command) \ | |
9813 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
9814 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
9815 | If a line number is specified, break at start of code for that line.\n\ | |
9816 | If a function is specified, break at start of code for that function.\n\ | |
9817 | If an address is specified, break at that exact address.\n\ | |
9818 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
9819 | This is useful for breaking on return to a stack frame.\n\ | |
9820 | \n\ | |
9821 | THREADNUM is the number from \"info threads\".\n\ | |
9822 | CONDITION is a boolean expression.\n\ | |
9823 | \n\ | |
9824 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
9825 | \n\ | |
9826 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
9827 | ||
44feb3ce TT |
9828 | /* List of subcommands for "catch". */ |
9829 | static struct cmd_list_element *catch_cmdlist; | |
9830 | ||
9831 | /* List of subcommands for "tcatch". */ | |
9832 | static struct cmd_list_element *tcatch_cmdlist; | |
9833 | ||
9834 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
9835 | lists, and pass some additional user data to the command function. */ | |
9836 | static void | |
9837 | add_catch_command (char *name, char *docstring, | |
9838 | void (*sfunc) (char *args, int from_tty, | |
9839 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
9840 | char **(*completer) (struct cmd_list_element *cmd, |
9841 | char *text, char *word), | |
44feb3ce TT |
9842 | void *user_data_catch, |
9843 | void *user_data_tcatch) | |
9844 | { | |
9845 | struct cmd_list_element *command; | |
9846 | ||
9847 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
9848 | &catch_cmdlist); | |
9849 | set_cmd_sfunc (command, sfunc); | |
9850 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 9851 | set_cmd_completer (command, completer); |
44feb3ce TT |
9852 | |
9853 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
9854 | &tcatch_cmdlist); | |
9855 | set_cmd_sfunc (command, sfunc); | |
9856 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 9857 | set_cmd_completer (command, completer); |
44feb3ce TT |
9858 | } |
9859 | ||
6c95b8df PA |
9860 | static void |
9861 | clear_syscall_counts (int pid) | |
9862 | { | |
9863 | struct inferior *inf = find_inferior_pid (pid); | |
9864 | ||
9865 | inf->total_syscalls_count = 0; | |
9866 | inf->any_syscall_count = 0; | |
9867 | VEC_free (int, inf->syscalls_counts); | |
9868 | } | |
9869 | ||
c906108c | 9870 | void |
fba45db2 | 9871 | _initialize_breakpoint (void) |
c906108c | 9872 | { |
fa8d40ab JJ |
9873 | static struct cmd_list_element *breakpoint_set_cmdlist; |
9874 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
9875 | struct cmd_list_element *c; |
9876 | ||
84acb35a | 9877 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 9878 | observer_attach_inferior_exit (clear_syscall_counts); |
84acb35a | 9879 | |
c906108c SS |
9880 | breakpoint_chain = 0; |
9881 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
9882 | before a breakpoint is set. */ | |
9883 | breakpoint_count = 0; | |
9884 | ||
1042e4c0 SS |
9885 | tracepoint_count = 0; |
9886 | ||
1bedd215 AC |
9887 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
9888 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
9889 | Usage is `ignore N COUNT'.")); | |
c906108c | 9890 | if (xdb_commands) |
c5aa993b | 9891 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 9892 | |
1bedd215 AC |
9893 | add_com ("commands", class_breakpoint, commands_command, _("\ |
9894 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
9895 | Give breakpoint number as argument after \"commands\".\n\ |
9896 | With no argument, the targeted breakpoint is the last one set.\n\ | |
9897 | The commands themselves follow starting on the next line.\n\ | |
9898 | Type a line containing \"end\" to indicate the end of them.\n\ | |
9899 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 9900 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 9901 | |
1bedd215 AC |
9902 | add_com ("condition", class_breakpoint, condition_command, _("\ |
9903 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 9904 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 9905 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 9906 | |
1bedd215 | 9907 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 9908 | Set a temporary breakpoint.\n\ |
c906108c SS |
9909 | Like \"break\" except the breakpoint is only temporary,\n\ |
9910 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
9911 | by using \"enable delete\" on the breakpoint number.\n\ |
9912 | \n" | |
9913 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 9914 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 9915 | |
1bedd215 | 9916 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 9917 | Set a hardware assisted breakpoint.\n\ |
c906108c | 9918 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
9919 | some target hardware may not have this support.\n\ |
9920 | \n" | |
9921 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 9922 | set_cmd_completer (c, location_completer); |
c906108c | 9923 | |
1bedd215 | 9924 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 9925 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 9926 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
9927 | so it will be deleted when hit.\n\ |
9928 | \n" | |
9929 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 9930 | set_cmd_completer (c, location_completer); |
c906108c | 9931 | |
1bedd215 AC |
9932 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
9933 | Enable some breakpoints.\n\ | |
c906108c SS |
9934 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9935 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
9936 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9937 | With a subcommand you can enable temporarily."), |
c906108c SS |
9938 | &enablelist, "enable ", 1, &cmdlist); |
9939 | if (xdb_commands) | |
1bedd215 AC |
9940 | add_com ("ab", class_breakpoint, enable_command, _("\ |
9941 | Enable some breakpoints.\n\ | |
c906108c SS |
9942 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9943 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
9944 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9945 | With a subcommand you can enable temporarily.")); |
c906108c SS |
9946 | |
9947 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
9948 | ||
1bedd215 AC |
9949 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
9950 | Enable some breakpoints.\n\ | |
c906108c SS |
9951 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
9952 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 9953 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 9954 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 9955 | |
1a966eab AC |
9956 | add_cmd ("once", no_class, enable_once_command, _("\ |
9957 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
9958 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
9959 | &enablebreaklist); |
9960 | ||
1a966eab AC |
9961 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
9962 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
9963 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
9964 | &enablebreaklist); |
9965 | ||
1a966eab AC |
9966 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
9967 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
9968 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
9969 | &enablelist); |
9970 | ||
1a966eab AC |
9971 | add_cmd ("once", no_class, enable_once_command, _("\ |
9972 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
9973 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
9974 | &enablelist); |
9975 | ||
1bedd215 AC |
9976 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
9977 | Disable some breakpoints.\n\ | |
c906108c SS |
9978 | Arguments are breakpoint numbers with spaces in between.\n\ |
9979 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9980 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
9981 | &disablelist, "disable ", 1, &cmdlist); |
9982 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
9983 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
9984 | if (xdb_commands) | |
1bedd215 AC |
9985 | add_com ("sb", class_breakpoint, disable_command, _("\ |
9986 | Disable some breakpoints.\n\ | |
c906108c SS |
9987 | Arguments are breakpoint numbers with spaces in between.\n\ |
9988 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 9989 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 9990 | |
1a966eab AC |
9991 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
9992 | Disable some breakpoints.\n\ | |
c906108c SS |
9993 | Arguments are breakpoint numbers with spaces in between.\n\ |
9994 | To disable all breakpoints, give no argument.\n\ | |
9995 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 9996 | This command may be abbreviated \"disable\"."), |
c906108c SS |
9997 | &disablelist); |
9998 | ||
1bedd215 AC |
9999 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10000 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10001 | Arguments are breakpoint numbers with spaces in between.\n\ |
10002 | To delete all breakpoints, give no argument.\n\ | |
10003 | \n\ | |
10004 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10005 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10006 | &deletelist, "delete ", 1, &cmdlist); |
10007 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10008 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10009 | if (xdb_commands) |
1bedd215 AC |
10010 | add_com ("db", class_breakpoint, delete_command, _("\ |
10011 | Delete some breakpoints.\n\ | |
c906108c | 10012 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10013 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10014 | |
1a966eab AC |
10015 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10016 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10017 | Arguments are breakpoint numbers with spaces in between.\n\ |
10018 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10019 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10020 | &deletelist); |
10021 | ||
1bedd215 AC |
10022 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10023 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10024 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10025 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10026 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10027 | If an address is specified, breakpoints at that address are cleared.\n\ |
10028 | \n\ | |
10029 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10030 | is executing in.\n\ |
10031 | \n\ | |
1bedd215 | 10032 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10033 | |
1bedd215 | 10034 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10035 | Set breakpoint at specified line or function.\n" |
10036 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10037 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10038 | |
c906108c SS |
10039 | add_com_alias ("b", "break", class_run, 1); |
10040 | add_com_alias ("br", "break", class_run, 1); | |
10041 | add_com_alias ("bre", "break", class_run, 1); | |
10042 | add_com_alias ("brea", "break", class_run, 1); | |
10043 | ||
7681d515 PM |
10044 | if (xdb_commands) |
10045 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
10046 | |
10047 | if (dbx_commands) | |
10048 | { | |
1bedd215 AC |
10049 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
10050 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
10051 | &stoplist, "stop ", 1, &cmdlist); |
10052 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 10053 | _("Break in function or address."), &stoplist); |
c5aa993b | 10054 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 10055 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
10056 | add_com ("status", class_info, breakpoints_info, _("\ |
10057 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10058 | The \"Type\" column indicates one of:\n\ |
10059 | \tbreakpoint - normal breakpoint\n\ | |
10060 | \twatchpoint - watchpoint\n\ | |
10061 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10062 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10063 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10064 | address and file/line number respectively.\n\ |
10065 | \n\ | |
10066 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10067 | are set to the address of the last breakpoint listed unless the command\n\ |
10068 | is prefixed with \"server \".\n\n\ | |
c906108c | 10069 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10070 | breakpoint set.")); |
c906108c SS |
10071 | } |
10072 | ||
1bedd215 AC |
10073 | add_info ("breakpoints", breakpoints_info, _("\ |
10074 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10075 | The \"Type\" column indicates one of:\n\ |
10076 | \tbreakpoint - normal breakpoint\n\ | |
10077 | \twatchpoint - watchpoint\n\ | |
10078 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10079 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10080 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10081 | address and file/line number respectively.\n\ |
10082 | \n\ | |
10083 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10084 | are set to the address of the last breakpoint listed unless the command\n\ |
10085 | is prefixed with \"server \".\n\n\ | |
c906108c | 10086 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10087 | breakpoint set.")); |
c906108c SS |
10088 | |
10089 | if (xdb_commands) | |
1bedd215 AC |
10090 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
10091 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10092 | The \"Type\" column indicates one of:\n\ |
10093 | \tbreakpoint - normal breakpoint\n\ | |
10094 | \twatchpoint - watchpoint\n\ | |
10095 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10096 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10097 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10098 | address and file/line number respectively.\n\ |
10099 | \n\ | |
10100 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10101 | are set to the address of the last breakpoint listed unless the command\n\ |
10102 | is prefixed with \"server \".\n\n\ | |
c906108c | 10103 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10104 | breakpoint set.")); |
c906108c | 10105 | |
1a966eab AC |
10106 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
10107 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10108 | The \"Type\" column indicates one of:\n\ |
10109 | \tbreakpoint - normal breakpoint\n\ | |
10110 | \twatchpoint - watchpoint\n\ | |
10111 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
10112 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
10113 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
10114 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
10115 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
10116 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
10117 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
10118 | address and file/line number respectively.\n\ |
10119 | \n\ | |
10120 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10121 | are set to the address of the last breakpoint listed unless the command\n\ |
10122 | is prefixed with \"server \".\n\n\ | |
c906108c | 10123 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 10124 | breakpoint set."), |
c906108c SS |
10125 | &maintenanceinfolist); |
10126 | ||
44feb3ce TT |
10127 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
10128 | Set catchpoints to catch events."), | |
10129 | &catch_cmdlist, "catch ", | |
10130 | 0/*allow-unknown*/, &cmdlist); | |
10131 | ||
10132 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
10133 | Set temporary catchpoints to catch events."), | |
10134 | &tcatch_cmdlist, "tcatch ", | |
10135 | 0/*allow-unknown*/, &cmdlist); | |
10136 | ||
10137 | /* Add catch and tcatch sub-commands. */ | |
10138 | add_catch_command ("catch", _("\ | |
10139 | Catch an exception, when caught.\n\ | |
10140 | With an argument, catch only exceptions with the given name."), | |
10141 | catch_catch_command, | |
a96d9b2e | 10142 | NULL, |
44feb3ce TT |
10143 | CATCH_PERMANENT, |
10144 | CATCH_TEMPORARY); | |
10145 | add_catch_command ("throw", _("\ | |
10146 | Catch an exception, when thrown.\n\ | |
10147 | With an argument, catch only exceptions with the given name."), | |
10148 | catch_throw_command, | |
a96d9b2e | 10149 | NULL, |
44feb3ce TT |
10150 | CATCH_PERMANENT, |
10151 | CATCH_TEMPORARY); | |
10152 | add_catch_command ("fork", _("Catch calls to fork."), | |
10153 | catch_fork_command_1, | |
a96d9b2e | 10154 | NULL, |
44feb3ce TT |
10155 | (void *) (uintptr_t) catch_fork_permanent, |
10156 | (void *) (uintptr_t) catch_fork_temporary); | |
10157 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
10158 | catch_fork_command_1, | |
a96d9b2e | 10159 | NULL, |
44feb3ce TT |
10160 | (void *) (uintptr_t) catch_vfork_permanent, |
10161 | (void *) (uintptr_t) catch_vfork_temporary); | |
10162 | add_catch_command ("exec", _("Catch calls to exec."), | |
10163 | catch_exec_command_1, | |
a96d9b2e SDJ |
10164 | NULL, |
10165 | CATCH_PERMANENT, | |
10166 | CATCH_TEMPORARY); | |
10167 | add_catch_command ("syscall", _("\ | |
10168 | Catch system calls by their names and/or numbers.\n\ | |
10169 | Arguments say which system calls to catch. If no arguments\n\ | |
10170 | are given, every system call will be caught.\n\ | |
10171 | Arguments, if given, should be one or more system call names\n\ | |
10172 | (if your system supports that), or system call numbers."), | |
10173 | catch_syscall_command_1, | |
10174 | catch_syscall_completer, | |
44feb3ce TT |
10175 | CATCH_PERMANENT, |
10176 | CATCH_TEMPORARY); | |
44feb3ce TT |
10177 | add_catch_command ("exception", _("\ |
10178 | Catch Ada exceptions, when raised.\n\ | |
10179 | With an argument, catch only exceptions with the given name."), | |
10180 | catch_ada_exception_command, | |
a96d9b2e | 10181 | NULL, |
44feb3ce TT |
10182 | CATCH_PERMANENT, |
10183 | CATCH_TEMPORARY); | |
10184 | add_catch_command ("assert", _("\ | |
10185 | Catch failed Ada assertions, when raised.\n\ | |
10186 | With an argument, catch only exceptions with the given name."), | |
10187 | catch_assert_command, | |
a96d9b2e | 10188 | NULL, |
44feb3ce TT |
10189 | CATCH_PERMANENT, |
10190 | CATCH_TEMPORARY); | |
c5aa993b | 10191 | |
1bedd215 AC |
10192 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
10193 | Set a watchpoint for an expression.\n\ | |
c906108c | 10194 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10195 | an expression changes.")); |
65d12d83 | 10196 | set_cmd_completer (c, expression_completer); |
c906108c | 10197 | |
1bedd215 AC |
10198 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
10199 | Set a read watchpoint for an expression.\n\ | |
c906108c | 10200 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10201 | an expression is read.")); |
65d12d83 | 10202 | set_cmd_completer (c, expression_completer); |
c906108c | 10203 | |
1bedd215 AC |
10204 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
10205 | Set a watchpoint for an expression.\n\ | |
c906108c | 10206 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10207 | an expression is either read or written.")); |
65d12d83 | 10208 | set_cmd_completer (c, expression_completer); |
c906108c SS |
10209 | |
10210 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 10211 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
10212 | |
10213 | ||
920d2a44 AC |
10214 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
10215 | respond to changes - contrary to the description. */ | |
85c07804 AC |
10216 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
10217 | &can_use_hw_watchpoints, _("\ | |
10218 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
10219 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
10220 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
10221 | such is available. (However, any hardware watchpoints that were\n\ | |
10222 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
10223 | hardware.)"), |
10224 | NULL, | |
920d2a44 | 10225 | show_can_use_hw_watchpoints, |
85c07804 | 10226 | &setlist, &showlist); |
c906108c SS |
10227 | |
10228 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 10229 | |
1042e4c0 SS |
10230 | /* Tracepoint manipulation commands. */ |
10231 | ||
10232 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
10233 | Set a tracepoint at specified line or function.\n\ | |
10234 | \n" | |
10235 | BREAK_ARGS_HELP ("trace") "\n\ | |
10236 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
10237 | set_cmd_completer (c, location_completer); | |
10238 | ||
10239 | add_com_alias ("tp", "trace", class_alias, 0); | |
10240 | add_com_alias ("tr", "trace", class_alias, 1); | |
10241 | add_com_alias ("tra", "trace", class_alias, 1); | |
10242 | add_com_alias ("trac", "trace", class_alias, 1); | |
10243 | ||
10244 | add_info ("tracepoints", tracepoints_info, _("\ | |
10245 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
10246 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
10247 | last tracepoint set.")); | |
10248 | ||
10249 | add_info_alias ("tp", "tracepoints", 1); | |
10250 | ||
10251 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
10252 | Delete specified tracepoints.\n\ | |
10253 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10254 | No argument means delete all tracepoints."), | |
10255 | &deletelist); | |
10256 | ||
10257 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
10258 | Disable specified tracepoints.\n\ | |
10259 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10260 | No argument means disable all tracepoints."), | |
10261 | &disablelist); | |
10262 | deprecate_cmd (c, "disable"); | |
10263 | ||
10264 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
10265 | Enable specified tracepoints.\n\ | |
10266 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10267 | No argument means enable all tracepoints."), | |
10268 | &enablelist); | |
10269 | deprecate_cmd (c, "enable"); | |
10270 | ||
10271 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
10272 | Set the passcount for a tracepoint.\n\ | |
10273 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
10274 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
10275 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
10276 | ||
10277 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
10278 | Save current tracepoint definitions as a script.\n\ | |
10279 | Use the 'source' command in another debug session to restore them.")); | |
10280 | set_cmd_completer (c, filename_completer); | |
10281 | ||
1bedd215 | 10282 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10283 | Breakpoint specific settings\n\ |
10284 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10285 | pending breakpoint behavior"), |
fa8d40ab JJ |
10286 | &breakpoint_set_cmdlist, "set breakpoint ", |
10287 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 10288 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10289 | Breakpoint specific settings\n\ |
10290 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10291 | pending breakpoint behavior"), |
fa8d40ab JJ |
10292 | &breakpoint_show_cmdlist, "show breakpoint ", |
10293 | 0/*allow-unknown*/, &showlist); | |
10294 | ||
7915a72c AC |
10295 | add_setshow_auto_boolean_cmd ("pending", no_class, |
10296 | &pending_break_support, _("\ | |
10297 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
10298 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
10299 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
10300 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
10301 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 10302 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 10303 | NULL, |
920d2a44 | 10304 | show_pending_break_support, |
6e1d7d6c AC |
10305 | &breakpoint_set_cmdlist, |
10306 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
10307 | |
10308 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
10309 | |
10310 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
10311 | &automatic_hardware_breakpoints, _("\ | |
10312 | Set automatic usage of hardware breakpoints."), _("\ | |
10313 | Show automatic usage of hardware breakpoints."), _("\ | |
10314 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
10315 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
10316 | a warning will be emitted for such breakpoints."), | |
10317 | NULL, | |
10318 | show_automatic_hardware_breakpoints, | |
10319 | &breakpoint_set_cmdlist, | |
10320 | &breakpoint_show_cmdlist); | |
74960c60 | 10321 | |
33e5cbd6 PA |
10322 | add_setshow_enum_cmd ("always-inserted", class_support, |
10323 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
10324 | Set mode for inserting breakpoints."), _("\ |
10325 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
10326 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
10327 | resumed, and removed when execution stops. When this mode is on,\n\ | |
10328 | breakpoints are inserted immediately and removed only when the user\n\ | |
10329 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
10330 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
10331 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
10332 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
10333 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
10334 | NULL, |
10335 | &show_always_inserted_mode, | |
10336 | &breakpoint_set_cmdlist, | |
10337 | &breakpoint_show_cmdlist); | |
765dc015 VP |
10338 | |
10339 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
10340 | |
10341 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 10342 | } |