Commit | Line | Data |
---|---|---|
c906108c | 1 | /* Everything about breakpoints, for GDB. |
8926118c | 2 | |
6aba47ca | 3 | Copyright (C) 1986, 1987, 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, |
9b254dd1 | 4 | 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, |
4c38e0a4 | 5 | 2008, 2009, 2010 Free Software Foundation, Inc. |
c906108c | 6 | |
c5aa993b | 7 | This file is part of GDB. |
c906108c | 8 | |
c5aa993b JM |
9 | This program is free software; you can redistribute it and/or modify |
10 | it under the terms of the GNU General Public License as published by | |
a9762ec7 | 11 | the Free Software Foundation; either version 3 of the License, or |
c5aa993b | 12 | (at your option) any later version. |
c906108c | 13 | |
c5aa993b JM |
14 | This program is distributed in the hope that it will be useful, |
15 | but WITHOUT ANY WARRANTY; without even the implied warranty of | |
16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
17 | GNU General Public License for more details. | |
c906108c | 18 | |
c5aa993b | 19 | You should have received a copy of the GNU General Public License |
a9762ec7 | 20 | along with this program. If not, see <http://www.gnu.org/licenses/>. */ |
c906108c SS |
21 | |
22 | #include "defs.h" | |
a6d9a66e | 23 | #include "arch-utils.h" |
c906108c | 24 | #include <ctype.h> |
776592bf | 25 | #include "hashtab.h" |
c906108c SS |
26 | #include "symtab.h" |
27 | #include "frame.h" | |
28 | #include "breakpoint.h" | |
1042e4c0 | 29 | #include "tracepoint.h" |
c906108c SS |
30 | #include "gdbtypes.h" |
31 | #include "expression.h" | |
32 | #include "gdbcore.h" | |
33 | #include "gdbcmd.h" | |
34 | #include "value.h" | |
35 | #include "command.h" | |
36 | #include "inferior.h" | |
37 | #include "gdbthread.h" | |
38 | #include "target.h" | |
39 | #include "language.h" | |
40 | #include "gdb_string.h" | |
41 | #include "demangle.h" | |
42 | #include "annotate.h" | |
43 | #include "symfile.h" | |
44 | #include "objfiles.h" | |
0378c332 | 45 | #include "source.h" |
c5f0f3d0 | 46 | #include "linespec.h" |
c94fdfd0 | 47 | #include "completer.h" |
5b7f31a4 | 48 | #include "gdb.h" |
8b93c638 | 49 | #include "ui-out.h" |
e1507482 | 50 | #include "cli/cli-script.h" |
0225421b | 51 | #include "gdb_assert.h" |
fe898f56 | 52 | #include "block.h" |
a77053c2 | 53 | #include "solib.h" |
84acb35a JJ |
54 | #include "solist.h" |
55 | #include "observer.h" | |
60250e8b | 56 | #include "exceptions.h" |
765dc015 | 57 | #include "memattr.h" |
f7f9143b | 58 | #include "ada-lang.h" |
d1aa2f50 | 59 | #include "top.h" |
fa4727a6 | 60 | #include "wrapper.h" |
79a45b7d | 61 | #include "valprint.h" |
4efc6507 | 62 | #include "jit.h" |
a96d9b2e | 63 | #include "xml-syscall.h" |
c906108c | 64 | |
1042e4c0 SS |
65 | /* readline include files */ |
66 | #include "readline/readline.h" | |
67 | #include "readline/history.h" | |
68 | ||
69 | /* readline defines this. */ | |
70 | #undef savestring | |
71 | ||
034dad6f | 72 | #include "mi/mi-common.h" |
104c1213 | 73 | |
44feb3ce TT |
74 | /* Arguments to pass as context to some catch command handlers. */ |
75 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
76 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 77 | |
44feb3ce | 78 | /* Prototypes for local functions. */ |
c906108c | 79 | |
a14ed312 | 80 | static void enable_delete_command (char *, int); |
c906108c | 81 | |
a14ed312 | 82 | static void enable_delete_breakpoint (struct breakpoint *); |
c906108c | 83 | |
a14ed312 | 84 | static void enable_once_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void enable_once_breakpoint (struct breakpoint *); |
c906108c | 87 | |
a14ed312 | 88 | static void disable_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void enable_command (char *, int); |
c906108c | 91 | |
a14ed312 | 92 | static void map_breakpoint_numbers (char *, void (*)(struct breakpoint *)); |
c906108c | 93 | |
a14ed312 | 94 | static void ignore_command (char *, int); |
c906108c | 95 | |
4efb68b1 | 96 | static int breakpoint_re_set_one (void *); |
c906108c | 97 | |
a14ed312 | 98 | static void clear_command (char *, int); |
c906108c | 99 | |
a14ed312 | 100 | static void catch_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void watch_command (char *, int); |
c906108c | 103 | |
a14ed312 | 104 | static int can_use_hardware_watchpoint (struct value *); |
c906108c | 105 | |
98deb0da | 106 | static void break_command_1 (char *, int, int); |
c906108c | 107 | |
a14ed312 | 108 | static void mention (struct breakpoint *); |
c906108c | 109 | |
63c252f8 PM |
110 | /* This function is used in gdbtk sources and thus can not be made static. */ |
111 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, | |
a6d9a66e UW |
112 | struct symtab_and_line, |
113 | enum bptype); | |
c906108c | 114 | |
76897487 KB |
115 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
116 | ||
a6d9a66e UW |
117 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
118 | CORE_ADDR bpaddr, | |
88f7da05 | 119 | enum bptype bptype); |
76897487 | 120 | |
6c95b8df PA |
121 | static void describe_other_breakpoints (struct gdbarch *, |
122 | struct program_space *, CORE_ADDR, | |
5af949e3 | 123 | struct obj_section *, int); |
c906108c | 124 | |
6c95b8df PA |
125 | static int breakpoint_address_match (struct address_space *aspace1, |
126 | CORE_ADDR addr1, | |
127 | struct address_space *aspace2, | |
128 | CORE_ADDR addr2); | |
129 | ||
a14ed312 | 130 | static void breakpoints_info (char *, int); |
c906108c | 131 | |
a14ed312 | 132 | static void breakpoint_1 (int, int); |
c906108c | 133 | |
89f9893c | 134 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 135 | |
4efb68b1 | 136 | static int breakpoint_cond_eval (void *); |
c906108c | 137 | |
4efb68b1 | 138 | static void cleanup_executing_breakpoints (void *); |
c906108c | 139 | |
a14ed312 | 140 | static void commands_command (char *, int); |
c906108c | 141 | |
a14ed312 | 142 | static void condition_command (char *, int); |
c906108c | 143 | |
a14ed312 | 144 | static int get_number_trailer (char **, int); |
c906108c | 145 | |
a14ed312 | 146 | void set_breakpoint_count (int); |
c906108c | 147 | |
c5aa993b JM |
148 | typedef enum |
149 | { | |
150 | mark_inserted, | |
151 | mark_uninserted | |
152 | } | |
153 | insertion_state_t; | |
c906108c | 154 | |
0bde7532 | 155 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 156 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 157 | |
a14ed312 | 158 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
159 | |
160 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 161 | |
4efb68b1 | 162 | static int watchpoint_check (void *); |
c906108c | 163 | |
a14ed312 | 164 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 165 | |
a14ed312 | 166 | static int hw_breakpoint_used_count (void); |
c906108c | 167 | |
a14ed312 | 168 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 169 | |
a14ed312 | 170 | static void hbreak_command (char *, int); |
c906108c | 171 | |
a14ed312 | 172 | static void thbreak_command (char *, int); |
c906108c | 173 | |
a14ed312 | 174 | static void watch_command_1 (char *, int, int); |
c906108c | 175 | |
a14ed312 | 176 | static void rwatch_command (char *, int); |
c906108c | 177 | |
a14ed312 | 178 | static void awatch_command (char *, int); |
c906108c | 179 | |
a14ed312 | 180 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 181 | |
a14ed312 | 182 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 183 | |
a14ed312 | 184 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 185 | |
a14ed312 | 186 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 187 | |
a14ed312 | 188 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 189 | |
a14ed312 | 190 | static char *ep_parse_optional_filename (char **arg); |
7a292a7a | 191 | |
d85310f7 MS |
192 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
193 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 194 | |
a14ed312 | 195 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 196 | |
a14ed312 | 197 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 198 | |
6c95b8df PA |
199 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
200 | CORE_ADDR pc); | |
1aafd4da | 201 | |
fe3f5fa8 VP |
202 | static void free_bp_location (struct bp_location *loc); |
203 | ||
39d61571 | 204 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 205 | |
b60e7edf | 206 | static void update_global_location_list (int); |
a5606eee | 207 | |
b60e7edf | 208 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
209 | |
210 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
211 | ||
212 | static void insert_breakpoint_locations (void); | |
a5606eee | 213 | |
a96d9b2e SDJ |
214 | static int syscall_catchpoint_p (struct breakpoint *b); |
215 | ||
1042e4c0 SS |
216 | static void tracepoints_info (char *, int); |
217 | ||
218 | static void delete_trace_command (char *, int); | |
219 | ||
220 | static void enable_trace_command (char *, int); | |
221 | ||
222 | static void disable_trace_command (char *, int); | |
223 | ||
224 | static void trace_pass_command (char *, int); | |
225 | ||
3daf8fe5 JG |
226 | static void skip_prologue_sal (struct symtab_and_line *sal); |
227 | ||
228 | ||
f3b1572e PA |
229 | /* Flag indicating that a command has proceeded the inferior past the |
230 | current breakpoint. */ | |
231 | ||
232 | static int breakpoint_proceeded; | |
233 | ||
2cec12e5 AR |
234 | static const char * |
235 | bpdisp_text (enum bpdisp disp) | |
236 | { | |
237 | /* NOTE: the following values are a part of MI protocol and represent | |
238 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
239 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
240 | return bpdisps[(int) disp]; | |
241 | } | |
c906108c | 242 | |
2cec12e5 | 243 | /* Prototypes for exported functions. */ |
c906108c SS |
244 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
245 | if such is available. */ | |
246 | static int can_use_hw_watchpoints; | |
247 | ||
920d2a44 AC |
248 | static void |
249 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
250 | struct cmd_list_element *c, | |
251 | const char *value) | |
252 | { | |
253 | fprintf_filtered (file, _("\ | |
254 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
255 | value); | |
256 | } | |
257 | ||
fa8d40ab JJ |
258 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
259 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
260 | for unrecognized breakpoint locations. | |
261 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
262 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
263 | static void |
264 | show_pending_break_support (struct ui_file *file, int from_tty, | |
265 | struct cmd_list_element *c, | |
266 | const char *value) | |
267 | { | |
268 | fprintf_filtered (file, _("\ | |
269 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
270 | value); | |
271 | } | |
fa8d40ab | 272 | |
765dc015 VP |
273 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
274 | set with "break" but falling in read-only memory. | |
275 | If 0, gdb will warn about such breakpoints, but won't automatically | |
276 | use hardware breakpoints. */ | |
277 | static int automatic_hardware_breakpoints; | |
278 | static void | |
279 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
280 | struct cmd_list_element *c, | |
281 | const char *value) | |
282 | { | |
283 | fprintf_filtered (file, _("\ | |
284 | Automatic usage of hardware breakpoints is %s.\n"), | |
285 | value); | |
286 | } | |
287 | ||
33e5cbd6 PA |
288 | /* If on, gdb will keep breakpoints inserted even as inferior is |
289 | stopped, and immediately insert any new breakpoints. If off, gdb | |
290 | will insert breakpoints into inferior only when resuming it, and | |
291 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
292 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
293 | ||
294 | static const char always_inserted_auto[] = "auto"; | |
295 | static const char always_inserted_on[] = "on"; | |
296 | static const char always_inserted_off[] = "off"; | |
297 | static const char *always_inserted_enums[] = { | |
298 | always_inserted_auto, | |
299 | always_inserted_off, | |
300 | always_inserted_on, | |
301 | NULL | |
302 | }; | |
303 | static const char *always_inserted_mode = always_inserted_auto; | |
304 | static void | |
74960c60 | 305 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 306 | struct cmd_list_element *c, const char *value) |
74960c60 | 307 | { |
33e5cbd6 PA |
308 | if (always_inserted_mode == always_inserted_auto) |
309 | fprintf_filtered (file, _("\ | |
310 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
311 | value, | |
312 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
313 | else | |
314 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
315 | } |
316 | ||
33e5cbd6 PA |
317 | int |
318 | breakpoints_always_inserted_mode (void) | |
319 | { | |
320 | return (always_inserted_mode == always_inserted_on | |
321 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
322 | } | |
765dc015 | 323 | |
a14ed312 | 324 | void _initialize_breakpoint (void); |
c906108c | 325 | |
c906108c SS |
326 | /* Are we executing breakpoint commands? */ |
327 | static int executing_breakpoint_commands; | |
328 | ||
c02f5703 MS |
329 | /* Are overlay event breakpoints enabled? */ |
330 | static int overlay_events_enabled; | |
331 | ||
c906108c SS |
332 | /* Walk the following statement or block through all breakpoints. |
333 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
334 | breakpoint. */ | |
335 | ||
5c44784c | 336 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 337 | |
5c44784c JM |
338 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
339 | for (B = breakpoint_chain; \ | |
340 | B ? (TMP=B->next, 1): 0; \ | |
341 | B = TMP) | |
c906108c | 342 | |
876fa593 JK |
343 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
344 | provided so update_global_location_list must not be called while executing | |
345 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 346 | |
876fa593 JK |
347 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
348 | for (BP_TMP = bp_location; \ | |
349 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
350 | BP_TMP++) | |
7cc221ef | 351 | |
1042e4c0 SS |
352 | /* Iterator for tracepoints only. */ |
353 | ||
354 | #define ALL_TRACEPOINTS(B) \ | |
355 | for (B = breakpoint_chain; B; B = B->next) \ | |
356 | if ((B)->type == bp_tracepoint) | |
357 | ||
7cc221ef | 358 | /* Chains of all breakpoints defined. */ |
c906108c SS |
359 | |
360 | struct breakpoint *breakpoint_chain; | |
361 | ||
876fa593 JK |
362 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
363 | ||
364 | static struct bp_location **bp_location; | |
365 | ||
366 | /* Number of elements of BP_LOCATION. */ | |
367 | ||
368 | static unsigned bp_location_count; | |
369 | ||
370 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
371 | for the current elements of BP_LOCATION which get a valid result from | |
372 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
373 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
374 | ||
375 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
376 | ||
377 | /* Maximum offset plus alignment between | |
378 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
379 | the current elements of BP_LOCATION which get a valid result from | |
380 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
381 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
382 | ||
383 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 384 | |
20874c92 | 385 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 386 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
387 | may still be reported by a target. */ |
388 | VEC(bp_location_p) *moribund_locations = NULL; | |
389 | ||
c906108c SS |
390 | /* Number of last breakpoint made. */ |
391 | ||
392 | int breakpoint_count; | |
393 | ||
1042e4c0 SS |
394 | /* Number of last tracepoint made. */ |
395 | ||
396 | int tracepoint_count; | |
397 | ||
468d015d JJ |
398 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
399 | static int | |
400 | breakpoint_enabled (struct breakpoint *b) | |
401 | { | |
0d381245 | 402 | return (b->enable_state == bp_enabled); |
468d015d JJ |
403 | } |
404 | ||
c906108c SS |
405 | /* Set breakpoint count to NUM. */ |
406 | ||
407 | void | |
fba45db2 | 408 | set_breakpoint_count (int num) |
c906108c SS |
409 | { |
410 | breakpoint_count = num; | |
4fa62494 | 411 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
412 | } |
413 | ||
414 | /* Used in run_command to zero the hit count when a new run starts. */ | |
415 | ||
416 | void | |
fba45db2 | 417 | clear_breakpoint_hit_counts (void) |
c906108c SS |
418 | { |
419 | struct breakpoint *b; | |
420 | ||
421 | ALL_BREAKPOINTS (b) | |
422 | b->hit_count = 0; | |
423 | } | |
424 | ||
425 | /* Default address, symtab and line to put a breakpoint at | |
426 | for "break" command with no arg. | |
427 | if default_breakpoint_valid is zero, the other three are | |
428 | not valid, and "break" with no arg is an error. | |
429 | ||
430 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
431 | ||
432 | int default_breakpoint_valid; | |
433 | CORE_ADDR default_breakpoint_address; | |
434 | struct symtab *default_breakpoint_symtab; | |
435 | int default_breakpoint_line; | |
6c95b8df PA |
436 | struct program_space *default_breakpoint_pspace; |
437 | ||
c906108c SS |
438 | \f |
439 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
440 | Advance *PP after the string and any trailing whitespace. | |
441 | ||
442 | Currently the string can either be a number or "$" followed by the name | |
443 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 444 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
445 | |
446 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
447 | |
448 | TRAILER is a character which can be found after the number; most | |
449 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 450 | static int |
fba45db2 | 451 | get_number_trailer (char **pp, int trailer) |
c906108c | 452 | { |
5c44784c | 453 | int retval = 0; /* default */ |
c906108c SS |
454 | char *p = *pp; |
455 | ||
456 | if (p == NULL) | |
457 | /* Empty line means refer to the last breakpoint. */ | |
458 | return breakpoint_count; | |
459 | else if (*p == '$') | |
460 | { | |
461 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 462 | to pass to lookup_internalvar(). */ |
c906108c SS |
463 | char *varname; |
464 | char *start = ++p; | |
4fa62494 | 465 | LONGEST val; |
c906108c SS |
466 | |
467 | while (isalnum (*p) || *p == '_') | |
468 | p++; | |
469 | varname = (char *) alloca (p - start + 1); | |
470 | strncpy (varname, start, p - start); | |
471 | varname[p - start] = '\0'; | |
4fa62494 UW |
472 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
473 | retval = (int) val; | |
5c44784c JM |
474 | else |
475 | { | |
a3f17187 | 476 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
477 | retval = 0; |
478 | } | |
c906108c SS |
479 | } |
480 | else | |
481 | { | |
482 | if (*p == '-') | |
483 | ++p; | |
484 | while (*p >= '0' && *p <= '9') | |
485 | ++p; | |
486 | if (p == *pp) | |
487 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
488 | { |
489 | /* Skip non-numeric token */ | |
490 | while (*p && !isspace((int) *p)) | |
491 | ++p; | |
492 | /* Return zero, which caller must interpret as error. */ | |
493 | retval = 0; | |
494 | } | |
495 | else | |
496 | retval = atoi (*pp); | |
497 | } | |
498 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
499 | { | |
500 | /* Trailing junk: return 0 and let caller print error msg. */ | |
501 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
502 | ++p; | |
503 | retval = 0; | |
c906108c | 504 | } |
c906108c SS |
505 | while (isspace (*p)) |
506 | p++; | |
507 | *pp = p; | |
508 | return retval; | |
509 | } | |
5c44784c | 510 | |
11cf8741 | 511 | |
5c44784c JM |
512 | /* Like get_number_trailer, but don't allow a trailer. */ |
513 | int | |
fba45db2 | 514 | get_number (char **pp) |
5c44784c JM |
515 | { |
516 | return get_number_trailer (pp, '\0'); | |
517 | } | |
518 | ||
519 | /* Parse a number or a range. | |
520 | * A number will be of the form handled by get_number. | |
521 | * A range will be of the form <number1> - <number2>, and | |
522 | * will represent all the integers between number1 and number2, | |
523 | * inclusive. | |
524 | * | |
525 | * While processing a range, this fuction is called iteratively; | |
526 | * At each call it will return the next value in the range. | |
527 | * | |
528 | * At the beginning of parsing a range, the char pointer PP will | |
529 | * be advanced past <number1> and left pointing at the '-' token. | |
530 | * Subsequent calls will not advance the pointer until the range | |
531 | * is completed. The call that completes the range will advance | |
532 | * pointer PP past <number2>. | |
533 | */ | |
534 | ||
535 | int | |
fba45db2 | 536 | get_number_or_range (char **pp) |
5c44784c JM |
537 | { |
538 | static int last_retval, end_value; | |
539 | static char *end_ptr; | |
540 | static int in_range = 0; | |
541 | ||
542 | if (**pp != '-') | |
543 | { | |
544 | /* Default case: pp is pointing either to a solo number, | |
545 | or to the first number of a range. */ | |
546 | last_retval = get_number_trailer (pp, '-'); | |
547 | if (**pp == '-') | |
548 | { | |
549 | char **temp; | |
550 | ||
551 | /* This is the start of a range (<number1> - <number2>). | |
552 | Skip the '-', parse and remember the second number, | |
553 | and also remember the end of the final token. */ | |
554 | ||
555 | temp = &end_ptr; | |
556 | end_ptr = *pp + 1; | |
557 | while (isspace ((int) *end_ptr)) | |
558 | end_ptr++; /* skip white space */ | |
559 | end_value = get_number (temp); | |
560 | if (end_value < last_retval) | |
561 | { | |
8a3fe4f8 | 562 | error (_("inverted range")); |
5c44784c JM |
563 | } |
564 | else if (end_value == last_retval) | |
565 | { | |
566 | /* degenerate range (number1 == number2). Advance the | |
567 | token pointer so that the range will be treated as a | |
568 | single number. */ | |
569 | *pp = end_ptr; | |
570 | } | |
571 | else | |
572 | in_range = 1; | |
573 | } | |
574 | } | |
575 | else if (! in_range) | |
8a3fe4f8 | 576 | error (_("negative value")); |
5c44784c JM |
577 | else |
578 | { | |
579 | /* pp points to the '-' that betokens a range. All | |
580 | number-parsing has already been done. Return the next | |
581 | integer value (one greater than the saved previous value). | |
582 | Do not advance the token pointer 'pp' until the end of range | |
583 | is reached. */ | |
584 | ||
585 | if (++last_retval == end_value) | |
586 | { | |
587 | /* End of range reached; advance token pointer. */ | |
588 | *pp = end_ptr; | |
589 | in_range = 0; | |
590 | } | |
591 | } | |
592 | return last_retval; | |
593 | } | |
594 | ||
48cb2d85 VP |
595 | /* Return the breakpoint with the specified number, or NULL |
596 | if the number does not refer to an existing breakpoint. */ | |
597 | ||
598 | struct breakpoint * | |
599 | get_breakpoint (int num) | |
600 | { | |
601 | struct breakpoint *b; | |
602 | ||
603 | ALL_BREAKPOINTS (b) | |
604 | if (b->number == num) | |
605 | return b; | |
606 | ||
607 | return NULL; | |
608 | } | |
5c44784c | 609 | |
c906108c SS |
610 | \f |
611 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
612 | ||
613 | static void | |
fba45db2 | 614 | condition_command (char *arg, int from_tty) |
c906108c | 615 | { |
52f0bd74 | 616 | struct breakpoint *b; |
c906108c | 617 | char *p; |
52f0bd74 | 618 | int bnum; |
c906108c SS |
619 | |
620 | if (arg == 0) | |
e2e0b3e5 | 621 | error_no_arg (_("breakpoint number")); |
c906108c SS |
622 | |
623 | p = arg; | |
624 | bnum = get_number (&p); | |
5c44784c | 625 | if (bnum == 0) |
8a3fe4f8 | 626 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
627 | |
628 | ALL_BREAKPOINTS (b) | |
629 | if (b->number == bnum) | |
2f069f6f JB |
630 | { |
631 | struct bp_location *loc = b->loc; | |
632 | for (; loc; loc = loc->next) | |
633 | { | |
634 | if (loc->cond) | |
635 | { | |
636 | xfree (loc->cond); | |
637 | loc->cond = 0; | |
638 | } | |
639 | } | |
640 | if (b->cond_string != NULL) | |
641 | xfree (b->cond_string); | |
c906108c | 642 | |
2f069f6f JB |
643 | if (*p == 0) |
644 | { | |
645 | b->cond_string = NULL; | |
646 | if (from_tty) | |
647 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
648 | } | |
649 | else | |
650 | { | |
651 | arg = p; | |
652 | /* I don't know if it matters whether this is the string the user | |
653 | typed in or the decompiled expression. */ | |
1b36a34b | 654 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
655 | b->condition_not_parsed = 0; |
656 | for (loc = b->loc; loc; loc = loc->next) | |
657 | { | |
658 | arg = p; | |
659 | loc->cond = | |
660 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
661 | if (*arg) | |
662 | error (_("Junk at end of expression")); | |
663 | } | |
664 | } | |
665 | breakpoints_changed (); | |
383f836e | 666 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
667 | return; |
668 | } | |
c906108c | 669 | |
8a3fe4f8 | 670 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
671 | } |
672 | ||
48cb2d85 VP |
673 | /* Set the command list of B to COMMANDS. */ |
674 | ||
675 | void | |
676 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
677 | { | |
678 | free_command_lines (&b->commands); | |
679 | b->commands = commands; | |
680 | breakpoints_changed (); | |
681 | observer_notify_breakpoint_modified (b->number); | |
682 | } | |
683 | ||
c906108c | 684 | static void |
fba45db2 | 685 | commands_command (char *arg, int from_tty) |
c906108c | 686 | { |
52f0bd74 | 687 | struct breakpoint *b; |
c906108c | 688 | char *p; |
52f0bd74 | 689 | int bnum; |
c906108c SS |
690 | struct command_line *l; |
691 | ||
692 | /* If we allowed this, we would have problems with when to | |
693 | free the storage, if we change the commands currently | |
694 | being read from. */ | |
695 | ||
696 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 697 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
698 | |
699 | p = arg; | |
700 | bnum = get_number (&p); | |
5c44784c | 701 | |
c906108c | 702 | if (p && *p) |
8a3fe4f8 | 703 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 704 | |
c906108c SS |
705 | ALL_BREAKPOINTS (b) |
706 | if (b->number == bnum) | |
9ebf4acf AC |
707 | { |
708 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
709 | bnum); | |
710 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 711 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf | 712 | do_cleanups (cleanups); |
48cb2d85 | 713 | breakpoint_set_commands (b, l); |
9ebf4acf | 714 | return; |
c5aa993b | 715 | } |
8a3fe4f8 | 716 | error (_("No breakpoint number %d."), bnum); |
c906108c | 717 | } |
40c03ae8 EZ |
718 | |
719 | /* Like commands_command, but instead of reading the commands from | |
720 | input stream, takes them from an already parsed command structure. | |
721 | ||
722 | This is used by cli-script.c to DTRT with breakpoint commands | |
723 | that are part of if and while bodies. */ | |
724 | enum command_control_type | |
725 | commands_from_control_command (char *arg, struct command_line *cmd) | |
726 | { | |
727 | struct breakpoint *b; | |
728 | char *p; | |
729 | int bnum; | |
730 | ||
731 | /* If we allowed this, we would have problems with when to | |
732 | free the storage, if we change the commands currently | |
733 | being read from. */ | |
734 | ||
735 | if (executing_breakpoint_commands) | |
736 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
737 | ||
738 | /* An empty string for the breakpoint number means the last | |
739 | breakpoint, but get_number expects a NULL pointer. */ | |
740 | if (arg && !*arg) | |
741 | p = NULL; | |
742 | else | |
743 | p = arg; | |
744 | bnum = get_number (&p); | |
745 | ||
746 | if (p && *p) | |
747 | error (_("Unexpected extra arguments following breakpoint number.")); | |
748 | ||
749 | ALL_BREAKPOINTS (b) | |
750 | if (b->number == bnum) | |
751 | { | |
752 | free_command_lines (&b->commands); | |
753 | if (cmd->body_count != 1) | |
754 | error (_("Invalid \"commands\" block structure.")); | |
755 | /* We need to copy the commands because if/while will free the | |
756 | list after it finishes execution. */ | |
757 | b->commands = copy_command_lines (cmd->body_list[0]); | |
758 | breakpoints_changed (); | |
383f836e | 759 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 760 | return simple_control; |
2f069f6f | 761 | } |
40c03ae8 EZ |
762 | error (_("No breakpoint number %d."), bnum); |
763 | } | |
876fa593 JK |
764 | |
765 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
766 | ||
767 | static int | |
768 | bp_location_has_shadow (struct bp_location *bl) | |
769 | { | |
770 | if (bl->loc_type != bp_loc_software_breakpoint) | |
771 | return 0; | |
772 | if (!bl->inserted) | |
773 | return 0; | |
774 | if (bl->target_info.shadow_len == 0) | |
775 | /* bp isn't valid, or doesn't shadow memory. */ | |
776 | return 0; | |
777 | return 1; | |
778 | } | |
779 | ||
8defab1a | 780 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
781 | by replacing any memory breakpoints with their shadowed contents. |
782 | ||
783 | The range of shadowed area by each bp_location is: | |
784 | b->address - bp_location_placed_address_before_address_max | |
785 | up to b->address + bp_location_shadow_len_after_address_max | |
786 | The range we were requested to resolve shadows for is: | |
787 | memaddr ... memaddr + len | |
788 | Thus the safe cutoff boundaries for performance optimization are | |
789 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
790 | and: | |
791 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 792 | |
8defab1a DJ |
793 | void |
794 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 795 | { |
876fa593 JK |
796 | /* Left boundary, right boundary and median element of our binary search. */ |
797 | unsigned bc_l, bc_r, bc; | |
798 | ||
799 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
800 | safe to report lower value but a failure to report higher one. */ | |
801 | ||
802 | bc_l = 0; | |
803 | bc_r = bp_location_count; | |
804 | while (bc_l + 1 < bc_r) | |
805 | { | |
806 | struct bp_location *b; | |
807 | ||
808 | bc = (bc_l + bc_r) / 2; | |
809 | b = bp_location[bc]; | |
810 | ||
811 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
812 | Then advance the left boundary only if we are sure the BC element can | |
813 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
814 | ||
815 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
816 | we cannot miss a breakpoint with its shadow range tail still reaching | |
817 | MEMADDR. */ | |
c5aa993b | 818 | |
876fa593 JK |
819 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
820 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
821 | bc_l = bc; | |
822 | else | |
823 | bc_r = bc; | |
824 | } | |
825 | ||
826 | /* Now do full processing of the found relevant range of elements. */ | |
827 | ||
828 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 829 | { |
876fa593 JK |
830 | struct bp_location *b = bp_location[bc]; |
831 | CORE_ADDR bp_addr = 0; | |
832 | int bp_size = 0; | |
833 | int bptoffset = 0; | |
834 | ||
ffce0d52 | 835 | if (b->owner->type == bp_none) |
8a3fe4f8 | 836 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
837 | b->owner->number); |
838 | ||
876fa593 JK |
839 | /* Performance optimization: any futher element can no longer affect BUF |
840 | content. */ | |
841 | ||
842 | if (b->address >= bp_location_placed_address_before_address_max | |
843 | && memaddr + len <= b->address | |
844 | - bp_location_placed_address_before_address_max) | |
845 | break; | |
846 | ||
847 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 848 | continue; |
6c95b8df PA |
849 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
850 | current_program_space->aspace, 0)) | |
851 | continue; | |
852 | ||
c5aa993b JM |
853 | /* Addresses and length of the part of the breakpoint that |
854 | we need to copy. */ | |
8181d85f DJ |
855 | bp_addr = b->target_info.placed_address; |
856 | bp_size = b->target_info.shadow_len; | |
8defab1a | 857 | |
c5aa993b JM |
858 | if (bp_addr + bp_size <= memaddr) |
859 | /* The breakpoint is entirely before the chunk of memory we | |
860 | are reading. */ | |
861 | continue; | |
8defab1a | 862 | |
c5aa993b JM |
863 | if (bp_addr >= memaddr + len) |
864 | /* The breakpoint is entirely after the chunk of memory we are | |
865 | reading. */ | |
866 | continue; | |
c5aa993b | 867 | |
8defab1a DJ |
868 | /* Offset within shadow_contents. */ |
869 | if (bp_addr < memaddr) | |
870 | { | |
871 | /* Only copy the second part of the breakpoint. */ | |
872 | bp_size -= memaddr - bp_addr; | |
873 | bptoffset = memaddr - bp_addr; | |
874 | bp_addr = memaddr; | |
875 | } | |
c5aa993b | 876 | |
8defab1a DJ |
877 | if (bp_addr + bp_size > memaddr + len) |
878 | { | |
879 | /* Only copy the first part of the breakpoint. */ | |
880 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
881 | } | |
c5aa993b | 882 | |
8defab1a DJ |
883 | memcpy (buf + bp_addr - memaddr, |
884 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 885 | } |
c906108c | 886 | } |
c906108c | 887 | \f |
c5aa993b | 888 | |
687595f9 | 889 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 890 | static void |
687595f9 DJ |
891 | insert_catchpoint (struct ui_out *uo, void *args) |
892 | { | |
893 | struct breakpoint *b = (struct breakpoint *) args; | |
894 | int val = -1; | |
895 | ||
fe798b75 JB |
896 | gdb_assert (b->type == bp_catchpoint); |
897 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
898 | ||
899 | b->ops->insert (b); | |
687595f9 DJ |
900 | } |
901 | ||
a5606eee VP |
902 | static int |
903 | is_hardware_watchpoint (struct breakpoint *bpt) | |
904 | { | |
905 | return (bpt->type == bp_hardware_watchpoint | |
906 | || bpt->type == bp_read_watchpoint | |
907 | || bpt->type == bp_access_watchpoint); | |
908 | } | |
7270d8f2 | 909 | |
fa4727a6 DJ |
910 | /* Find the current value of a watchpoint on EXP. Return the value in |
911 | *VALP and *RESULTP and the chain of intermediate and final values | |
912 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
913 | not need them. | |
914 | ||
ccc57cf9 | 915 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
916 | be set to NULL. *RESULTP may be a lazy value, if the result could |
917 | not be read from memory. It is used to determine whether a value | |
918 | is user-specified (we should watch the whole value) or intermediate | |
919 | (we should watch only the bit used to locate the final value). | |
920 | ||
921 | If the final value, or any intermediate value, could not be read | |
922 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
923 | set to any referenced values. *VALP will never be a lazy value. | |
924 | This is the value which we store in struct breakpoint. | |
925 | ||
926 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
927 | value chain. The caller must free the values individually. If | |
928 | VAL_CHAIN is NULL, all generated values will be left on the value | |
929 | chain. */ | |
930 | ||
931 | static void | |
932 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
933 | struct value **resultp, struct value **val_chain) | |
934 | { | |
935 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 936 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
937 | |
938 | *valp = NULL; | |
939 | if (resultp) | |
940 | *resultp = NULL; | |
941 | if (val_chain) | |
942 | *val_chain = NULL; | |
943 | ||
944 | /* Evaluate the expression. */ | |
945 | mark = value_mark (); | |
946 | result = NULL; | |
ccc57cf9 PA |
947 | |
948 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
949 | { | |
950 | result = evaluate_expression (exp); | |
951 | } | |
952 | if (ex.reason < 0) | |
953 | { | |
954 | /* Ignore memory errors, we want watchpoints pointing at | |
955 | inaccessible memory to still be created; otherwise, throw the | |
956 | error to some higher catcher. */ | |
957 | switch (ex.error) | |
958 | { | |
959 | case MEMORY_ERROR: | |
960 | break; | |
961 | default: | |
962 | throw_exception (ex); | |
963 | break; | |
964 | } | |
965 | } | |
966 | ||
fa4727a6 DJ |
967 | new_mark = value_mark (); |
968 | if (mark == new_mark) | |
969 | return; | |
970 | if (resultp) | |
971 | *resultp = result; | |
972 | ||
973 | /* Make sure it's not lazy, so that after the target stops again we | |
974 | have a non-lazy previous value to compare with. */ | |
975 | if (result != NULL | |
976 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
977 | *valp = result; | |
978 | ||
979 | if (val_chain) | |
980 | { | |
981 | /* Return the chain of intermediate values. We use this to | |
982 | decide which addresses to watch. */ | |
983 | *val_chain = new_mark; | |
984 | value_release_to_mark (mark); | |
985 | } | |
986 | } | |
987 | ||
f6bc2008 PA |
988 | /* Assuming that B is a watchpoint: returns true if the current thread |
989 | and its running state are safe to evaluate or update watchpoint B. | |
990 | Watchpoints on local expressions need to be evaluated in the | |
991 | context of the thread that was current when the watchpoint was | |
992 | created, and, that thread needs to be stopped to be able to select | |
993 | the correct frame context. Watchpoints on global expressions can | |
994 | be evaluated on any thread, and in any state. It is presently left | |
995 | to the target allowing memory accesses when threads are | |
996 | running. */ | |
997 | ||
998 | static int | |
999 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1000 | { | |
1001 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1002 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1003 | && !is_executing (inferior_ptid))); | |
1004 | } | |
1005 | ||
567e1b4e JB |
1006 | /* Assuming that B is a watchpoint: |
1007 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1008 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1009 | - Evaluate the condition if there is one, and store the result |
1010 | in b->loc->cond. | |
a5606eee VP |
1011 | - Update the list of values that must be watched in B->loc. |
1012 | ||
bfa149ac | 1013 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1014 | If this is local watchpoint that is out of scope, delete it. |
1015 | ||
1016 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1017 | + inserted on each stop here. Normal breakpoints must never be removed | |
1018 | because they might be missed by a running thread when debugging in non-stop | |
1019 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1020 | processed here) are specific to each LWP since they are stored in each LWP's | |
1021 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1022 | order to be able to modify its hardware watchpoints. | |
1023 | ||
1024 | Hardware watchpoints must be reset exactly once after being presented to the | |
1025 | user. It cannot be done sooner, because it would reset the data used to | |
1026 | present the watchpoint hit to the user. And it must not be done later | |
1027 | because it could display the same single watchpoint hit during multiple GDB | |
1028 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1029 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1030 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1031 | memory content has not changed. | |
1032 | ||
1033 | The following constraints influence the location where we can reset hardware | |
1034 | watchpoints: | |
1035 | ||
1036 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1037 | several times when GDB stops. | |
1038 | ||
1039 | [linux] | |
1040 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1041 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1042 | reason for stopping, and all the other hits are presented later, one after | |
1043 | the other, each time the user requests the execution to be resumed. | |
1044 | Execution is not resumed for the threads still having pending hit event | |
1045 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1046 | the inferior on the first stop the thread hit event is kept being reported | |
1047 | from its cached value by linux_nat_stopped_data_address until the real | |
1048 | thread resume happens after the watchpoint gets presented and thus its | |
1049 | LWP_INFO->STATUS gets reset. | |
1050 | ||
1051 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1052 | removal from inferior. */ | |
1053 | ||
b40ce68a | 1054 | static void |
a5606eee | 1055 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1056 | { |
a5606eee | 1057 | int within_current_scope; |
a5606eee VP |
1058 | struct frame_id saved_frame_id; |
1059 | struct bp_location *loc; | |
66076460 | 1060 | int frame_saved; |
a5606eee VP |
1061 | bpstat bs; |
1062 | ||
f6bc2008 PA |
1063 | /* If this is a local watchpoint, we only want to check if the |
1064 | watchpoint frame is in scope if the current thread is the thread | |
1065 | that was used to create the watchpoint. */ | |
1066 | if (!watchpoint_in_thread_scope (b)) | |
1067 | return; | |
1068 | ||
876fa593 | 1069 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1070 | update_global_locations will eventually delete them and remove |
1071 | breakpoints if needed. */ | |
a5606eee VP |
1072 | b->loc = NULL; |
1073 | ||
1074 | if (b->disposition == disp_del_at_next_stop) | |
1075 | return; | |
1076 | ||
66076460 | 1077 | frame_saved = 0; |
a5606eee VP |
1078 | |
1079 | /* Determine if the watchpoint is within scope. */ | |
1080 | if (b->exp_valid_block == NULL) | |
1081 | within_current_scope = 1; | |
1082 | else | |
1083 | { | |
1084 | struct frame_info *fi; | |
66076460 DJ |
1085 | |
1086 | /* Save the current frame's ID so we can restore it after | |
1087 | evaluating the watchpoint expression on its own frame. */ | |
1088 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1089 | took a frame parameter, so that we didn't have to change the | |
1090 | selected frame. */ | |
1091 | frame_saved = 1; | |
1092 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1093 | ||
a5606eee VP |
1094 | fi = frame_find_by_id (b->watchpoint_frame); |
1095 | within_current_scope = (fi != NULL); | |
1096 | if (within_current_scope) | |
1097 | select_frame (fi); | |
1098 | } | |
1099 | ||
1100 | if (within_current_scope && reparse) | |
1101 | { | |
1102 | char *s; | |
1103 | if (b->exp) | |
1104 | { | |
1105 | xfree (b->exp); | |
1106 | b->exp = NULL; | |
1107 | } | |
1108 | s = b->exp_string; | |
1109 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1110 | /* If the meaning of expression itself changed, the old value is | |
1111 | no longer relevant. We don't want to report a watchpoint hit | |
1112 | to the user when the old value and the new value may actually | |
1113 | be completely different objects. */ | |
1114 | value_free (b->val); | |
fa4727a6 DJ |
1115 | b->val = NULL; |
1116 | b->val_valid = 0; | |
a5606eee | 1117 | } |
a5606eee VP |
1118 | |
1119 | /* If we failed to parse the expression, for example because | |
1120 | it refers to a global variable in a not-yet-loaded shared library, | |
1121 | don't try to insert watchpoint. We don't automatically delete | |
1122 | such watchpoint, though, since failure to parse expression | |
1123 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1124 | if ( !target_has_execution) |
1125 | { | |
1126 | /* Without execution, memory can't change. No use to try and | |
1127 | set watchpoint locations. The watchpoint will be reset when | |
1128 | the target gains execution, through breakpoint_re_set. */ | |
1129 | } | |
1130 | else if (within_current_scope && b->exp) | |
a5606eee | 1131 | { |
fa4727a6 | 1132 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1133 | struct program_space *frame_pspace; |
a5606eee | 1134 | |
fa4727a6 | 1135 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1136 | |
a5606eee VP |
1137 | /* Avoid setting b->val if it's already set. The meaning of |
1138 | b->val is 'the last value' user saw, and we should update | |
1139 | it only if we reported that last value to user. As it | |
1140 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1141 | if (!b->val_valid) |
1142 | { | |
1143 | b->val = v; | |
1144 | b->val_valid = 1; | |
1145 | } | |
a5606eee | 1146 | |
db2ad4c3 JK |
1147 | /* Change the type of breakpoint between hardware assisted or an |
1148 | ordinary watchpoint depending on the hardware support and free | |
1149 | hardware slots. REPARSE is set when the inferior is started. */ | |
1150 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1151 | && reparse) | |
1152 | { | |
ca2d49e8 | 1153 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1154 | |
7b838ca2 TJB |
1155 | /* We need to determine how many resources are already used |
1156 | for all other hardware watchpoints to see if we still have | |
1157 | enough resources to also fit this watchpoint in as well. | |
1158 | To avoid the hw_watchpoint_used_count call below from counting | |
1159 | this watchpoint, make sure that it is marked as a software | |
1160 | watchpoint. */ | |
1161 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1162 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1163 | &other_type_used); | |
1164 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1165 | ||
ca2d49e8 | 1166 | if (!mem_cnt) |
db2ad4c3 JK |
1167 | b->type = bp_watchpoint; |
1168 | else | |
ca2d49e8 | 1169 | { |
d92524f1 | 1170 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1171 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1172 | if (target_resources_ok <= 0) | |
1173 | b->type = bp_watchpoint; | |
1174 | else | |
1175 | b->type = bp_hardware_watchpoint; | |
1176 | } | |
db2ad4c3 JK |
1177 | } |
1178 | ||
2d134ed3 PA |
1179 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1180 | ||
a5606eee | 1181 | /* Look at each value on the value chain. */ |
fa4727a6 | 1182 | for (v = val_chain; v; v = next) |
a5606eee VP |
1183 | { |
1184 | /* If it's a memory location, and GDB actually needed | |
1185 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1186 | must watch it. If the first value returned is |
1187 | still lazy, that means an error occurred reading it; | |
1188 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1189 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1190 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1191 | { |
1192 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1193 | |
a5606eee VP |
1194 | /* We only watch structs and arrays if user asked |
1195 | for it explicitly, never if they just happen to | |
1196 | appear in the middle of some value chain. */ | |
fa4727a6 | 1197 | if (v == result |
a5606eee VP |
1198 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1199 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1200 | { | |
1201 | CORE_ADDR addr; | |
1202 | int len, type; | |
1203 | struct bp_location *loc, **tmp; | |
1204 | ||
42ae5230 | 1205 | addr = value_address (v); |
a5606eee VP |
1206 | len = TYPE_LENGTH (value_type (v)); |
1207 | type = hw_write; | |
1208 | if (b->type == bp_read_watchpoint) | |
1209 | type = hw_read; | |
1210 | else if (b->type == bp_access_watchpoint) | |
1211 | type = hw_access; | |
1212 | ||
39d61571 | 1213 | loc = allocate_bp_location (b); |
a5606eee VP |
1214 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1215 | ; | |
1216 | *tmp = loc; | |
a6d9a66e | 1217 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1218 | |
1219 | loc->pspace = frame_pspace; | |
a5606eee VP |
1220 | loc->address = addr; |
1221 | loc->length = len; | |
1222 | loc->watchpoint_type = type; | |
1223 | } | |
1224 | } | |
1225 | ||
1226 | next = value_next (v); | |
1227 | if (v != b->val) | |
1228 | value_free (v); | |
1229 | } | |
1230 | ||
2ec93238 MK |
1231 | /* We just regenerated the list of breakpoint locations. |
1232 | The new location does not have its condition field set to anything | |
1233 | and therefore, we must always reparse the cond_string, independently | |
1234 | of the value of the reparse flag. */ | |
1235 | if (b->cond_string != NULL) | |
a5606eee VP |
1236 | { |
1237 | char *s = b->cond_string; | |
a5606eee VP |
1238 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1239 | } | |
1240 | } | |
1241 | else if (!within_current_scope) | |
7270d8f2 | 1242 | { |
a5606eee | 1243 | printf_filtered (_("\ |
567e1b4e | 1244 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1245 | in which its expression is valid.\n"), |
1246 | b->number); | |
1247 | if (b->related_breakpoint) | |
1248 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1249 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1250 | } |
a5606eee VP |
1251 | |
1252 | /* Restore the selected frame. */ | |
66076460 DJ |
1253 | if (frame_saved) |
1254 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1255 | } |
1256 | ||
a5606eee | 1257 | |
74960c60 VP |
1258 | /* Returns 1 iff breakpoint location should be |
1259 | inserted in the inferior. */ | |
1260 | static int | |
1261 | should_be_inserted (struct bp_location *bpt) | |
1262 | { | |
1263 | if (!breakpoint_enabled (bpt->owner)) | |
1264 | return 0; | |
1265 | ||
1266 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1267 | return 0; | |
1268 | ||
1269 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1270 | return 0; | |
1271 | ||
56710373 PA |
1272 | /* This is set for example, when we're attached to the parent of a |
1273 | vfork, and have detached from the child. The child is running | |
1274 | free, and we expect it to do an exec or exit, at which point the | |
1275 | OS makes the parent schedulable again (and the target reports | |
1276 | that the vfork is done). Until the child is done with the shared | |
1277 | memory region, do not insert breakpoints in the parent, otherwise | |
1278 | the child could still trip on the parent's breakpoints. Since | |
1279 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1280 | if (bpt->pspace->breakpoints_not_allowed) | |
1281 | return 0; | |
1282 | ||
1042e4c0 SS |
1283 | /* Tracepoints are inserted by the target at a time of its choosing, |
1284 | not by us. */ | |
1285 | if (bpt->owner->type == bp_tracepoint) | |
1286 | return 0; | |
1287 | ||
74960c60 VP |
1288 | return 1; |
1289 | } | |
1290 | ||
879bfdc2 DJ |
1291 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1292 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1293 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1294 | |
1295 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1296 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1297 | static int |
879bfdc2 | 1298 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1299 | struct ui_file *tmp_error_stream, |
fa3a767f | 1300 | int *disabled_breaks, |
26bb91f3 | 1301 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1302 | { |
1303 | int val = 0; | |
1304 | ||
74960c60 | 1305 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1306 | return 0; |
1307 | ||
8181d85f DJ |
1308 | /* Initialize the target-specific information. */ |
1309 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1310 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1311 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1312 | |
879bfdc2 DJ |
1313 | if (bpt->loc_type == bp_loc_software_breakpoint |
1314 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1315 | { | |
765dc015 VP |
1316 | if (bpt->owner->type != bp_hardware_breakpoint) |
1317 | { | |
1318 | /* If the explicitly specified breakpoint type | |
1319 | is not hardware breakpoint, check the memory map to see | |
1320 | if the breakpoint address is in read only memory or not. | |
1321 | Two important cases are: | |
1322 | - location type is not hardware breakpoint, memory | |
1323 | is readonly. We change the type of the location to | |
1324 | hardware breakpoint. | |
1325 | - location type is hardware breakpoint, memory is read-write. | |
1326 | This means we've previously made the location hardware one, but | |
1327 | then the memory map changed, so we undo. | |
1328 | ||
1329 | When breakpoints are removed, remove_breakpoints will | |
1330 | use location types we've just set here, the only possible | |
1331 | problem is that memory map has changed during running program, | |
1332 | but it's not going to work anyway with current gdb. */ | |
1333 | struct mem_region *mr | |
1334 | = lookup_mem_region (bpt->target_info.placed_address); | |
1335 | ||
1336 | if (mr) | |
1337 | { | |
1338 | if (automatic_hardware_breakpoints) | |
1339 | { | |
1340 | int changed = 0; | |
1341 | enum bp_loc_type new_type; | |
1342 | ||
1343 | if (mr->attrib.mode != MEM_RW) | |
1344 | new_type = bp_loc_hardware_breakpoint; | |
1345 | else | |
1346 | new_type = bp_loc_software_breakpoint; | |
1347 | ||
1348 | if (new_type != bpt->loc_type) | |
1349 | { | |
1350 | static int said = 0; | |
1351 | bpt->loc_type = new_type; | |
1352 | if (!said) | |
1353 | { | |
1354 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1355 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1356 | said = 1; |
1357 | } | |
1358 | } | |
1359 | } | |
1360 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1361 | && mr->attrib.mode != MEM_RW) | |
1362 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1363 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1364 | } |
1365 | } | |
1366 | ||
879bfdc2 DJ |
1367 | /* First check to see if we have to handle an overlay. */ |
1368 | if (overlay_debugging == ovly_off | |
1369 | || bpt->section == NULL | |
1370 | || !(section_is_overlay (bpt->section))) | |
1371 | { | |
1372 | /* No overlay handling: just set the breakpoint. */ | |
1373 | ||
1374 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1375 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1376 | &bpt->target_info); | |
879bfdc2 | 1377 | else |
a6d9a66e UW |
1378 | val = target_insert_breakpoint (bpt->gdbarch, |
1379 | &bpt->target_info); | |
879bfdc2 DJ |
1380 | } |
1381 | else | |
1382 | { | |
1383 | /* This breakpoint is in an overlay section. | |
1384 | Shall we set a breakpoint at the LMA? */ | |
1385 | if (!overlay_events_enabled) | |
1386 | { | |
1387 | /* Yes -- overlay event support is not active, | |
1388 | so we must try to set a breakpoint at the LMA. | |
1389 | This will not work for a hardware breakpoint. */ | |
1390 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1391 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1392 | bpt->owner->number); |
1393 | else | |
1394 | { | |
1395 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1396 | bpt->section); | |
1397 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1398 | bpt->overlay_target_info = bpt->target_info; |
1399 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1400 | val = target_insert_breakpoint (bpt->gdbarch, |
1401 | &bpt->overlay_target_info); | |
879bfdc2 | 1402 | if (val != 0) |
99361f52 DE |
1403 | fprintf_unfiltered (tmp_error_stream, |
1404 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1405 | bpt->owner->number); |
1406 | } | |
1407 | } | |
1408 | /* Shall we set a breakpoint at the VMA? */ | |
1409 | if (section_is_mapped (bpt->section)) | |
1410 | { | |
1411 | /* Yes. This overlay section is mapped into memory. */ | |
1412 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1413 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1414 | &bpt->target_info); | |
879bfdc2 | 1415 | else |
a6d9a66e UW |
1416 | val = target_insert_breakpoint (bpt->gdbarch, |
1417 | &bpt->target_info); | |
879bfdc2 DJ |
1418 | } |
1419 | else | |
1420 | { | |
1421 | /* No. This breakpoint will not be inserted. | |
1422 | No error, but do not mark the bp as 'inserted'. */ | |
1423 | return 0; | |
1424 | } | |
1425 | } | |
1426 | ||
1427 | if (val) | |
1428 | { | |
1429 | /* Can't set the breakpoint. */ | |
6c95b8df | 1430 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1431 | { |
1432 | /* See also: disable_breakpoints_in_shlibs. */ | |
1433 | val = 0; | |
0d381245 | 1434 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1435 | if (!*disabled_breaks) |
1436 | { | |
1437 | fprintf_unfiltered (tmp_error_stream, | |
1438 | "Cannot insert breakpoint %d.\n", | |
1439 | bpt->owner->number); | |
1440 | fprintf_unfiltered (tmp_error_stream, | |
1441 | "Temporarily disabling shared library breakpoints:\n"); | |
1442 | } | |
1443 | *disabled_breaks = 1; | |
1444 | fprintf_unfiltered (tmp_error_stream, | |
1445 | "breakpoint #%d\n", bpt->owner->number); | |
1446 | } | |
1447 | else | |
879bfdc2 | 1448 | { |
879bfdc2 DJ |
1449 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1450 | { | |
1451 | *hw_breakpoint_error = 1; | |
1452 | fprintf_unfiltered (tmp_error_stream, | |
1453 | "Cannot insert hardware breakpoint %d.\n", | |
1454 | bpt->owner->number); | |
1455 | } | |
1456 | else | |
1457 | { | |
1458 | fprintf_unfiltered (tmp_error_stream, | |
1459 | "Cannot insert breakpoint %d.\n", | |
1460 | bpt->owner->number); | |
1461 | fprintf_filtered (tmp_error_stream, | |
1462 | "Error accessing memory address "); | |
5af949e3 UW |
1463 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1464 | tmp_error_stream); | |
879bfdc2 DJ |
1465 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1466 | safe_strerror (val)); | |
1467 | } | |
1468 | ||
1469 | } | |
1470 | } | |
1471 | else | |
1472 | bpt->inserted = 1; | |
1473 | ||
1474 | return val; | |
1475 | } | |
1476 | ||
1477 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1478 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1479 | watchpoints. It's not clear that it's necessary... */ | |
1480 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1481 | { | |
a5606eee VP |
1482 | val = target_insert_watchpoint (bpt->address, |
1483 | bpt->length, | |
1484 | bpt->watchpoint_type); | |
1485 | bpt->inserted = (val != -1); | |
879bfdc2 DJ |
1486 | } |
1487 | ||
fe798b75 | 1488 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1489 | { |
71fff37b AC |
1490 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1491 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1492 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1493 | bpt->owner->number); | |
1494 | if (e.reason < 0) | |
879bfdc2 DJ |
1495 | bpt->owner->enable_state = bp_disabled; |
1496 | else | |
1497 | bpt->inserted = 1; | |
1640b821 DJ |
1498 | |
1499 | /* We've already printed an error message if there was a problem | |
1500 | inserting this catchpoint, and we've disabled the catchpoint, | |
1501 | so just return success. */ | |
1502 | return 0; | |
879bfdc2 DJ |
1503 | } |
1504 | ||
1505 | return 0; | |
1506 | } | |
1507 | ||
6c95b8df PA |
1508 | /* This function is called when program space PSPACE is about to be |
1509 | deleted. It takes care of updating breakpoints to not reference | |
1510 | PSPACE anymore. */ | |
1511 | ||
1512 | void | |
1513 | breakpoint_program_space_exit (struct program_space *pspace) | |
1514 | { | |
1515 | struct breakpoint *b, *b_temp; | |
876fa593 | 1516 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1517 | |
1518 | /* Remove any breakpoint that was set through this program space. */ | |
1519 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1520 | { | |
1521 | if (b->pspace == pspace) | |
1522 | delete_breakpoint (b); | |
1523 | } | |
1524 | ||
1525 | /* Breakpoints set through other program spaces could have locations | |
1526 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1527 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1528 | { |
1529 | struct bp_location *tmp; | |
1530 | ||
1531 | if (loc->pspace == pspace) | |
1532 | { | |
1533 | if (loc->owner->loc == loc) | |
1534 | loc->owner->loc = loc->next; | |
1535 | else | |
1536 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1537 | if (tmp->next == loc) | |
1538 | { | |
1539 | tmp->next = loc->next; | |
1540 | break; | |
1541 | } | |
1542 | } | |
1543 | } | |
1544 | ||
1545 | /* Now update the global location list to permanently delete the | |
1546 | removed locations above. */ | |
1547 | update_global_location_list (0); | |
1548 | } | |
1549 | ||
74960c60 VP |
1550 | /* Make sure all breakpoints are inserted in inferior. |
1551 | Throws exception on any error. | |
1552 | A breakpoint that is already inserted won't be inserted | |
1553 | again, so calling this function twice is safe. */ | |
1554 | void | |
1555 | insert_breakpoints (void) | |
1556 | { | |
1557 | struct breakpoint *bpt; | |
1558 | ||
1559 | ALL_BREAKPOINTS (bpt) | |
1560 | if (is_hardware_watchpoint (bpt)) | |
1561 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1562 | ||
b60e7edf | 1563 | update_global_location_list (1); |
74960c60 | 1564 | |
c35b1492 PA |
1565 | /* update_global_location_list does not insert breakpoints when |
1566 | always_inserted_mode is not enabled. Explicitly insert them | |
1567 | now. */ | |
1568 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1569 | insert_breakpoint_locations (); |
1570 | } | |
1571 | ||
c906108c SS |
1572 | /* insert_breakpoints is used when starting or continuing the program. |
1573 | remove_breakpoints is used when the program stops. | |
1574 | Both return zero if successful, | |
1575 | or an `errno' value if could not write the inferior. */ | |
1576 | ||
74960c60 VP |
1577 | static void |
1578 | insert_breakpoint_locations (void) | |
c906108c | 1579 | { |
a5606eee | 1580 | struct breakpoint *bpt; |
876fa593 | 1581 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1582 | int error = 0; |
c906108c SS |
1583 | int val = 0; |
1584 | int disabled_breaks = 0; | |
81d0cc19 | 1585 | int hw_breakpoint_error = 0; |
c906108c | 1586 | |
81d0cc19 | 1587 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1588 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1589 | |
81d0cc19 GS |
1590 | /* Explicitly mark the warning -- this will only be printed if |
1591 | there was an error. */ | |
1592 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1593 | |
1594 | save_current_space_and_thread (); | |
1595 | ||
876fa593 | 1596 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1597 | { |
6c95b8df PA |
1598 | struct thread_info *tp; |
1599 | CORE_ADDR last_addr; | |
1600 | ||
74960c60 | 1601 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1602 | continue; |
1603 | ||
f365de73 AS |
1604 | /* There is no point inserting thread-specific breakpoints if the |
1605 | thread no longer exists. */ | |
1606 | if (b->owner->thread != -1 | |
1607 | && !valid_thread_id (b->owner->thread)) | |
1608 | continue; | |
1609 | ||
6c95b8df PA |
1610 | switch_to_program_space_and_thread (b->pspace); |
1611 | ||
1612 | /* For targets that support global breakpoints, there's no need | |
1613 | to select an inferior to insert breakpoint to. In fact, even | |
1614 | if we aren't attached to any process yet, we should still | |
1615 | insert breakpoints. */ | |
1616 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1617 | && ptid_equal (inferior_ptid, null_ptid)) | |
1618 | continue; | |
1619 | ||
879bfdc2 | 1620 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1621 | &disabled_breaks, |
879bfdc2 DJ |
1622 | &hw_breakpoint_error); |
1623 | if (val) | |
e236ba44 | 1624 | error = val; |
879bfdc2 | 1625 | } |
c906108c | 1626 | |
a5606eee VP |
1627 | /* If we failed to insert all locations of a watchpoint, |
1628 | remove them, as half-inserted watchpoint is of limited use. */ | |
1629 | ALL_BREAKPOINTS (bpt) | |
1630 | { | |
1631 | int some_failed = 0; | |
1632 | struct bp_location *loc; | |
1633 | ||
1634 | if (!is_hardware_watchpoint (bpt)) | |
1635 | continue; | |
1636 | ||
d6b74ac4 | 1637 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1638 | continue; |
74960c60 VP |
1639 | |
1640 | if (bpt->disposition == disp_del_at_next_stop) | |
1641 | continue; | |
a5606eee VP |
1642 | |
1643 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1644 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1645 | { |
1646 | some_failed = 1; | |
1647 | break; | |
1648 | } | |
1649 | if (some_failed) | |
1650 | { | |
1651 | for (loc = bpt->loc; loc; loc = loc->next) | |
1652 | if (loc->inserted) | |
1653 | remove_breakpoint (loc, mark_uninserted); | |
1654 | ||
1655 | hw_breakpoint_error = 1; | |
1656 | fprintf_unfiltered (tmp_error_stream, | |
1657 | "Could not insert hardware watchpoint %d.\n", | |
1658 | bpt->number); | |
1659 | error = -1; | |
1660 | } | |
1661 | } | |
1662 | ||
e236ba44 | 1663 | if (error) |
81d0cc19 GS |
1664 | { |
1665 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1666 | message about possibly exhausted resources. */ | |
879bfdc2 | 1667 | if (hw_breakpoint_error) |
81d0cc19 | 1668 | { |
c6510018 MS |
1669 | fprintf_unfiltered (tmp_error_stream, |
1670 | "Could not insert hardware breakpoints:\n\ | |
1671 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1672 | } |
81d0cc19 GS |
1673 | target_terminal_ours_for_output (); |
1674 | error_stream (tmp_error_stream); | |
1675 | } | |
f7545552 TT |
1676 | |
1677 | do_cleanups (cleanups); | |
c906108c SS |
1678 | } |
1679 | ||
c906108c | 1680 | int |
fba45db2 | 1681 | remove_breakpoints (void) |
c906108c | 1682 | { |
876fa593 | 1683 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1684 | int val = 0; |
c906108c | 1685 | |
876fa593 | 1686 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1687 | { |
0bde7532 | 1688 | if (b->inserted) |
3a1bae8e | 1689 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1690 | } |
3a1bae8e | 1691 | return val; |
c906108c SS |
1692 | } |
1693 | ||
6c95b8df PA |
1694 | /* Remove breakpoints of process PID. */ |
1695 | ||
1696 | int | |
1697 | remove_breakpoints_pid (int pid) | |
1698 | { | |
876fa593 | 1699 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1700 | int val; |
1701 | struct inferior *inf = find_inferior_pid (pid); | |
1702 | ||
876fa593 | 1703 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
1704 | { |
1705 | if (b->pspace != inf->pspace) | |
1706 | continue; | |
1707 | ||
1708 | if (b->inserted) | |
1709 | { | |
1710 | val = remove_breakpoint (b, mark_uninserted); | |
1711 | if (val != 0) | |
1712 | return val; | |
1713 | } | |
1714 | } | |
1715 | return 0; | |
1716 | } | |
1717 | ||
692590c1 | 1718 | int |
80ce1ecb | 1719 | remove_hw_watchpoints (void) |
692590c1 | 1720 | { |
876fa593 | 1721 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1722 | int val = 0; |
692590c1 | 1723 | |
876fa593 | 1724 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 1725 | { |
0bde7532 | 1726 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1727 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1728 | } |
3a1bae8e | 1729 | return val; |
692590c1 MS |
1730 | } |
1731 | ||
c906108c | 1732 | int |
fba45db2 | 1733 | reattach_breakpoints (int pid) |
c906108c | 1734 | { |
6c95b8df | 1735 | struct cleanup *old_chain; |
876fa593 | 1736 | struct bp_location *b, **bp_tmp; |
c906108c | 1737 | int val; |
a4954f26 | 1738 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1739 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
1740 | struct inferior *inf; |
1741 | struct thread_info *tp; | |
1742 | ||
1743 | tp = any_live_thread_of_process (pid); | |
1744 | if (tp == NULL) | |
1745 | return 1; | |
1746 | ||
1747 | inf = find_inferior_pid (pid); | |
1748 | old_chain = save_inferior_ptid (); | |
1749 | ||
1750 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
1751 | |
1752 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1753 | |
876fa593 | 1754 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1755 | { |
6c95b8df PA |
1756 | if (b->pspace != inf->pspace) |
1757 | continue; | |
1758 | ||
0bde7532 | 1759 | if (b->inserted) |
c5aa993b | 1760 | { |
a4954f26 DJ |
1761 | b->inserted = 0; |
1762 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1763 | &dummy1, &dummy2); |
c5aa993b JM |
1764 | if (val != 0) |
1765 | { | |
ce696e05 | 1766 | do_cleanups (old_chain); |
c5aa993b JM |
1767 | return val; |
1768 | } | |
1769 | } | |
1770 | } | |
ce696e05 | 1771 | do_cleanups (old_chain); |
c906108c SS |
1772 | return 0; |
1773 | } | |
1774 | ||
e58b0e63 PA |
1775 | static int internal_breakpoint_number = -1; |
1776 | ||
e62c965a | 1777 | static struct breakpoint * |
a6d9a66e UW |
1778 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1779 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1780 | { |
e62c965a PP |
1781 | struct symtab_and_line sal; |
1782 | struct breakpoint *b; | |
1783 | ||
1784 | init_sal (&sal); /* initialize to zeroes */ | |
1785 | ||
1786 | sal.pc = address; | |
1787 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 1788 | sal.pspace = current_program_space; |
e62c965a | 1789 | |
a6d9a66e | 1790 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1791 | b->number = internal_breakpoint_number--; |
1792 | b->disposition = disp_donttouch; | |
1793 | ||
1794 | return b; | |
1795 | } | |
1796 | ||
1797 | static void | |
69de3c6a | 1798 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1799 | { |
69de3c6a | 1800 | struct objfile *objfile; |
e62c965a | 1801 | |
69de3c6a PP |
1802 | ALL_OBJFILES (objfile) |
1803 | { | |
1804 | struct breakpoint *b; | |
1805 | struct minimal_symbol *m; | |
1806 | ||
1807 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1808 | if (m == NULL) | |
1809 | continue; | |
e62c965a | 1810 | |
a6d9a66e UW |
1811 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1812 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1813 | bp_overlay_event); |
1814 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1815 | |
69de3c6a PP |
1816 | if (overlay_debugging == ovly_auto) |
1817 | { | |
1818 | b->enable_state = bp_enabled; | |
1819 | overlay_events_enabled = 1; | |
1820 | } | |
1821 | else | |
1822 | { | |
1823 | b->enable_state = bp_disabled; | |
1824 | overlay_events_enabled = 0; | |
1825 | } | |
e62c965a PP |
1826 | } |
1827 | update_global_location_list (1); | |
1828 | } | |
1829 | ||
0fd8e87f UW |
1830 | static void |
1831 | create_longjmp_master_breakpoint (char *func_name) | |
1832 | { | |
6c95b8df | 1833 | struct program_space *pspace; |
0fd8e87f | 1834 | struct objfile *objfile; |
6c95b8df PA |
1835 | struct cleanup *old_chain; |
1836 | ||
1837 | old_chain = save_current_program_space (); | |
0fd8e87f | 1838 | |
6c95b8df | 1839 | ALL_PSPACES (pspace) |
0fd8e87f UW |
1840 | ALL_OBJFILES (objfile) |
1841 | { | |
1842 | struct breakpoint *b; | |
1843 | struct minimal_symbol *m; | |
1844 | ||
1845 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1846 | continue; | |
1847 | ||
6c95b8df PA |
1848 | set_current_program_space (pspace); |
1849 | ||
0fd8e87f UW |
1850 | m = lookup_minimal_symbol_text (func_name, objfile); |
1851 | if (m == NULL) | |
1852 | continue; | |
1853 | ||
a6d9a66e UW |
1854 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1855 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1856 | bp_longjmp_master); |
1857 | b->addr_string = xstrdup (func_name); | |
1858 | b->enable_state = bp_disabled; | |
1859 | } | |
1860 | update_global_location_list (1); | |
6c95b8df PA |
1861 | |
1862 | do_cleanups (old_chain); | |
0fd8e87f UW |
1863 | } |
1864 | ||
c906108c | 1865 | void |
fba45db2 | 1866 | update_breakpoints_after_exec (void) |
c906108c | 1867 | { |
c5aa993b JM |
1868 | struct breakpoint *b; |
1869 | struct breakpoint *temp; | |
876fa593 | 1870 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 1871 | |
25b22b0a PA |
1872 | /* We're about to delete breakpoints from GDB's lists. If the |
1873 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1874 | writing the breakpoints' "shadow contents" back into memory. The | |
1875 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1876 | do that. Instead, the target is responsible from marking | |
1877 | breakpoints out as soon as it detects an exec. We don't do that | |
1878 | here instead, because there may be other attempts to delete | |
1879 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 1880 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
1881 | if (bploc->pspace == current_program_space) |
1882 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1883 | |
1884 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 1885 | { |
6c95b8df PA |
1886 | if (b->pspace != current_program_space) |
1887 | continue; | |
1888 | ||
c5aa993b JM |
1889 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
1890 | if (b->type == bp_shlib_event) | |
1891 | { | |
1892 | delete_breakpoint (b); | |
1893 | continue; | |
1894 | } | |
c906108c | 1895 | |
4efc6507 DE |
1896 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
1897 | if (b->type == bp_jit_event) | |
1898 | { | |
1899 | delete_breakpoint (b); | |
1900 | continue; | |
1901 | } | |
1902 | ||
1900040c | 1903 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1904 | as must overlay event and longjmp master breakpoints. */ |
1905 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1906 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1907 | { |
1908 | delete_breakpoint (b); | |
1909 | continue; | |
1910 | } | |
1911 | ||
c5aa993b JM |
1912 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1913 | if (b->type == bp_step_resume) | |
1914 | { | |
1915 | delete_breakpoint (b); | |
1916 | continue; | |
1917 | } | |
1918 | ||
611c83ae PA |
1919 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1920 | after an exec. */ | |
1921 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1922 | { | |
1923 | delete_breakpoint (b); | |
1924 | continue; | |
1925 | } | |
1926 | ||
ce78b96d JB |
1927 | if (b->type == bp_catchpoint) |
1928 | { | |
1929 | /* For now, none of the bp_catchpoint breakpoints need to | |
1930 | do anything at this point. In the future, if some of | |
1931 | the catchpoints need to something, we will need to add | |
1932 | a new method, and call this method from here. */ | |
1933 | continue; | |
1934 | } | |
1935 | ||
c5aa993b JM |
1936 | /* bp_finish is a special case. The only way we ought to be able |
1937 | to see one of these when an exec() has happened, is if the user | |
1938 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1939 | carries them to the call-site of the current callee, by setting | |
1940 | a temporary bp there and resuming. But in this case, the finish | |
1941 | will carry them entirely through the vfork & exec. | |
1942 | ||
1943 | We don't want to allow a bp_finish to remain inserted now. But | |
1944 | we can't safely delete it, 'cause finish_command has a handle to | |
1945 | the bp on a bpstat, and will later want to delete it. There's a | |
1946 | chance (and I've seen it happen) that if we delete the bp_finish | |
1947 | here, that its storage will get reused by the time finish_command | |
1948 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
1949 | We really must allow finish_command to delete a bp_finish. | |
1950 | ||
53a5351d JM |
1951 | In the absense of a general solution for the "how do we know |
1952 | it's safe to delete something others may have handles to?" | |
1953 | problem, what we'll do here is just uninsert the bp_finish, and | |
1954 | let finish_command delete it. | |
1955 | ||
1956 | (We know the bp_finish is "doomed" in the sense that it's | |
1957 | momentary, and will be deleted as soon as finish_command sees | |
1958 | the inferior stopped. So it doesn't matter that the bp's | |
1959 | address is probably bogus in the new a.out, unlike e.g., the | |
1960 | solib breakpoints.) */ | |
c5aa993b | 1961 | |
c5aa993b JM |
1962 | if (b->type == bp_finish) |
1963 | { | |
1964 | continue; | |
1965 | } | |
1966 | ||
1967 | /* Without a symbolic address, we have little hope of the | |
1968 | pre-exec() address meaning the same thing in the post-exec() | |
1969 | a.out. */ | |
1970 | if (b->addr_string == NULL) | |
1971 | { | |
1972 | delete_breakpoint (b); | |
1973 | continue; | |
1974 | } | |
c5aa993b | 1975 | } |
1900040c | 1976 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 1977 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
1978 | create_longjmp_master_breakpoint ("longjmp"); |
1979 | create_longjmp_master_breakpoint ("_longjmp"); | |
1980 | create_longjmp_master_breakpoint ("siglongjmp"); | |
1981 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
1982 | } |
1983 | ||
1984 | int | |
fba45db2 | 1985 | detach_breakpoints (int pid) |
c906108c | 1986 | { |
876fa593 | 1987 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1988 | int val = 0; |
ce696e05 | 1989 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 1990 | struct inferior *inf = current_inferior (); |
c5aa993b | 1991 | |
39f77062 | 1992 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 1993 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 1994 | |
6c95b8df | 1995 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 1996 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 1997 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1998 | { |
6c95b8df PA |
1999 | if (b->pspace != inf->pspace) |
2000 | continue; | |
2001 | ||
0bde7532 | 2002 | if (b->inserted) |
6c95b8df | 2003 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2004 | } |
ce696e05 | 2005 | do_cleanups (old_chain); |
3a1bae8e | 2006 | return val; |
c906108c SS |
2007 | } |
2008 | ||
6c95b8df PA |
2009 | /* Remove the breakpoint location B from the current address space. |
2010 | Note that this is used to detach breakpoints from a child fork. | |
2011 | When we get here, the child isn't in the inferior list, and neither | |
2012 | do we have objects to represent its address space --- we should | |
2013 | *not* look at b->pspace->aspace here. */ | |
2014 | ||
c906108c | 2015 | static int |
6c95b8df | 2016 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2017 | { |
2018 | int val; | |
6c95b8df | 2019 | struct cleanup *old_chain; |
c5aa993b | 2020 | |
0bde7532 | 2021 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2022 | /* Permanent breakpoints cannot be inserted or removed. */ |
2023 | return 0; | |
2024 | ||
74960c60 VP |
2025 | /* The type of none suggests that owner is actually deleted. |
2026 | This should not ever happen. */ | |
2027 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2028 | |
2029 | if (b->loc_type == bp_loc_software_breakpoint | |
2030 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2031 | { |
c02f5703 MS |
2032 | /* "Normal" instruction breakpoint: either the standard |
2033 | trap-instruction bp (bp_breakpoint), or a | |
2034 | bp_hardware_breakpoint. */ | |
2035 | ||
2036 | /* First check to see if we have to handle an overlay. */ | |
2037 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2038 | || b->section == NULL |
2039 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2040 | { |
2041 | /* No overlay handling: just remove the breakpoint. */ | |
2042 | ||
0bde7532 | 2043 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2044 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2045 | else |
a6d9a66e | 2046 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2047 | } |
c906108c SS |
2048 | else |
2049 | { | |
c02f5703 MS |
2050 | /* This breakpoint is in an overlay section. |
2051 | Did we set a breakpoint at the LMA? */ | |
2052 | if (!overlay_events_enabled) | |
2053 | { | |
2054 | /* Yes -- overlay event support is not active, so we | |
2055 | should have set a breakpoint at the LMA. Remove it. | |
2056 | */ | |
c02f5703 MS |
2057 | /* Ignore any failures: if the LMA is in ROM, we will |
2058 | have already warned when we failed to insert it. */ | |
0bde7532 | 2059 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2060 | target_remove_hw_breakpoint (b->gdbarch, |
2061 | &b->overlay_target_info); | |
c02f5703 | 2062 | else |
a6d9a66e UW |
2063 | target_remove_breakpoint (b->gdbarch, |
2064 | &b->overlay_target_info); | |
c02f5703 MS |
2065 | } |
2066 | /* Did we set a breakpoint at the VMA? | |
2067 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2068 | if (b->inserted) |
c906108c | 2069 | { |
c02f5703 MS |
2070 | /* Yes -- remove it. Previously we did not bother to |
2071 | remove the breakpoint if the section had been | |
2072 | unmapped, but let's not rely on that being safe. We | |
2073 | don't know what the overlay manager might do. */ | |
0bde7532 | 2074 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2075 | val = target_remove_hw_breakpoint (b->gdbarch, |
2076 | &b->target_info); | |
aa67235e UW |
2077 | |
2078 | /* However, we should remove *software* breakpoints only | |
2079 | if the section is still mapped, or else we overwrite | |
2080 | wrong code with the saved shadow contents. */ | |
2081 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2082 | val = target_remove_breakpoint (b->gdbarch, |
2083 | &b->target_info); | |
aa67235e UW |
2084 | else |
2085 | val = 0; | |
c906108c | 2086 | } |
c02f5703 MS |
2087 | else |
2088 | { | |
2089 | /* No -- not inserted, so no need to remove. No error. */ | |
2090 | val = 0; | |
2091 | } | |
c906108c | 2092 | } |
879d1e6b UW |
2093 | |
2094 | /* In some cases, we might not be able to remove a breakpoint | |
2095 | in a shared library that has already been removed, but we | |
2096 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2097 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2098 | val = 0; |
2099 | ||
c906108c SS |
2100 | if (val) |
2101 | return val; | |
0bde7532 | 2102 | b->inserted = (is == mark_inserted); |
c906108c | 2103 | } |
a5606eee | 2104 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2105 | { |
278cd55f AC |
2106 | struct value *v; |
2107 | struct value *n; | |
c5aa993b | 2108 | |
0bde7532 | 2109 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2110 | val = target_remove_watchpoint (b->address, b->length, |
2111 | b->watchpoint_type); | |
2e70b7b9 | 2112 | |
c906108c | 2113 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2114 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2115 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2116 | b->owner->number); |
c906108c | 2117 | } |
ce78b96d JB |
2118 | else if (b->owner->type == bp_catchpoint |
2119 | && breakpoint_enabled (b->owner) | |
2120 | && !b->duplicate) | |
2121 | { | |
2122 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2123 | ||
2124 | val = b->owner->ops->remove (b->owner); | |
2125 | if (val) | |
2126 | return val; | |
2127 | b->inserted = (is == mark_inserted); | |
2128 | } | |
c906108c SS |
2129 | |
2130 | return 0; | |
2131 | } | |
2132 | ||
6c95b8df PA |
2133 | static int |
2134 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2135 | { | |
2136 | int ret; | |
2137 | struct cleanup *old_chain; | |
2138 | ||
2139 | if (b->owner->enable_state == bp_permanent) | |
2140 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2141 | return 0; | |
2142 | ||
2143 | /* The type of none suggests that owner is actually deleted. | |
2144 | This should not ever happen. */ | |
2145 | gdb_assert (b->owner->type != bp_none); | |
2146 | ||
2147 | old_chain = save_current_space_and_thread (); | |
2148 | ||
2149 | switch_to_program_space_and_thread (b->pspace); | |
2150 | ||
2151 | ret = remove_breakpoint_1 (b, is); | |
2152 | ||
2153 | do_cleanups (old_chain); | |
2154 | return ret; | |
2155 | } | |
2156 | ||
c906108c SS |
2157 | /* Clear the "inserted" flag in all breakpoints. */ |
2158 | ||
25b22b0a | 2159 | void |
fba45db2 | 2160 | mark_breakpoints_out (void) |
c906108c | 2161 | { |
876fa593 | 2162 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2163 | |
876fa593 | 2164 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2165 | if (bpt->pspace == current_program_space) |
2166 | bpt->inserted = 0; | |
c906108c SS |
2167 | } |
2168 | ||
53a5351d JM |
2169 | /* Clear the "inserted" flag in all breakpoints and delete any |
2170 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2171 | |
2172 | Plus other such housekeeping that has to be done for breakpoints | |
2173 | between runs. | |
2174 | ||
53a5351d JM |
2175 | Note: this function gets called at the end of a run (by |
2176 | generic_mourn_inferior) and when a run begins (by | |
2177 | init_wait_for_inferior). */ | |
c906108c SS |
2178 | |
2179 | ||
2180 | ||
2181 | void | |
fba45db2 | 2182 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2183 | { |
52f0bd74 | 2184 | struct breakpoint *b, *temp; |
876fa593 | 2185 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2186 | int ix; |
6c95b8df | 2187 | struct program_space *pspace = current_program_space; |
c906108c | 2188 | |
50c71eaf PA |
2189 | /* If breakpoint locations are shared across processes, then there's |
2190 | nothing to do. */ | |
2567c7d9 | 2191 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2192 | return; |
2193 | ||
876fa593 | 2194 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2195 | { |
2196 | if (bpt->pspace == pspace | |
2197 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2198 | bpt->inserted = 0; |
6c95b8df | 2199 | } |
075f6582 | 2200 | |
c906108c | 2201 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2202 | { |
6c95b8df PA |
2203 | if (b->loc && b->loc->pspace != pspace) |
2204 | continue; | |
2205 | ||
c5aa993b JM |
2206 | switch (b->type) |
2207 | { | |
2208 | case bp_call_dummy: | |
2209 | case bp_watchpoint_scope: | |
c906108c | 2210 | |
c5aa993b JM |
2211 | /* If the call dummy breakpoint is at the entry point it will |
2212 | cause problems when the inferior is rerun, so we better | |
2213 | get rid of it. | |
c906108c | 2214 | |
c5aa993b JM |
2215 | Also get rid of scope breakpoints. */ |
2216 | delete_breakpoint (b); | |
2217 | break; | |
c906108c | 2218 | |
c5aa993b JM |
2219 | case bp_watchpoint: |
2220 | case bp_hardware_watchpoint: | |
2221 | case bp_read_watchpoint: | |
2222 | case bp_access_watchpoint: | |
c906108c | 2223 | |
c5aa993b JM |
2224 | /* Likewise for watchpoints on local expressions. */ |
2225 | if (b->exp_valid_block != NULL) | |
2226 | delete_breakpoint (b); | |
967af18d | 2227 | else if (context == inf_starting) |
c860120c PM |
2228 | { |
2229 | /* Reset val field to force reread of starting value | |
2230 | in insert_breakpoints. */ | |
2231 | if (b->val) | |
2232 | value_free (b->val); | |
2233 | b->val = NULL; | |
fa4727a6 | 2234 | b->val_valid = 0; |
c860120c | 2235 | } |
c5aa993b JM |
2236 | break; |
2237 | default: | |
c5aa993b JM |
2238 | break; |
2239 | } | |
2240 | } | |
1c5cfe86 PA |
2241 | |
2242 | /* Get rid of the moribund locations. */ | |
2243 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2244 | free_bp_location (bpt); | |
2245 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2246 | } |
2247 | ||
6c95b8df PA |
2248 | /* These functions concern about actual breakpoints inserted in the |
2249 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2250 | we need to hop over the bkpt --- so we check for address space | |
2251 | match, not program space. */ | |
2252 | ||
c2c6d25f JM |
2253 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2254 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2255 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2256 | permanent breakpoint. | |
2257 | - When continuing from a location with an ordinary breakpoint, we | |
2258 | actually single step once before calling insert_breakpoints. | |
2259 | - When continuing from a localion with a permanent breakpoint, we | |
2260 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2261 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2262 | |
c2c6d25f | 2263 | enum breakpoint_here |
6c95b8df | 2264 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2265 | { |
876fa593 | 2266 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2267 | int any_breakpoint_here = 0; |
c906108c | 2268 | |
876fa593 | 2269 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2270 | { |
2271 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2272 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2273 | continue; | |
2274 | ||
468d015d | 2275 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2276 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2277 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2278 | aspace, pc)) | |
075f6582 DJ |
2279 | { |
2280 | if (overlay_debugging | |
2281 | && section_is_overlay (bpt->section) | |
2282 | && !section_is_mapped (bpt->section)) | |
2283 | continue; /* unmapped overlay -- can't be a match */ | |
2284 | else if (bpt->owner->enable_state == bp_permanent) | |
2285 | return permanent_breakpoint_here; | |
2286 | else | |
2287 | any_breakpoint_here = 1; | |
2288 | } | |
2289 | } | |
c906108c | 2290 | |
c2c6d25f | 2291 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2292 | } |
2293 | ||
1c5cfe86 PA |
2294 | /* Return true if there's a moribund breakpoint at PC. */ |
2295 | ||
2296 | int | |
6c95b8df | 2297 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2298 | { |
2299 | struct bp_location *loc; | |
2300 | int ix; | |
2301 | ||
2302 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2303 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2304 | aspace, pc)) | |
1c5cfe86 PA |
2305 | return 1; |
2306 | ||
2307 | return 0; | |
2308 | } | |
c2c6d25f | 2309 | |
c36b740a | 2310 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2311 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2312 | This does not check for single-step breakpoints, which are |
2313 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2314 | |
2315 | int | |
6c95b8df | 2316 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2317 | { |
876fa593 | 2318 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2319 | |
876fa593 | 2320 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2321 | { |
075f6582 DJ |
2322 | if (bpt->loc_type != bp_loc_software_breakpoint |
2323 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2324 | continue; | |
2325 | ||
2326 | if (bpt->inserted | |
6c95b8df PA |
2327 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2328 | aspace, pc)) | |
075f6582 DJ |
2329 | { |
2330 | if (overlay_debugging | |
2331 | && section_is_overlay (bpt->section) | |
2332 | && !section_is_mapped (bpt->section)) | |
2333 | continue; /* unmapped overlay -- can't be a match */ | |
2334 | else | |
2335 | return 1; | |
2336 | } | |
c5aa993b | 2337 | } |
c36b740a VP |
2338 | return 0; |
2339 | } | |
2340 | ||
2341 | /* Returns non-zero iff there's either regular breakpoint | |
2342 | or a single step breakpoint inserted at PC. */ | |
2343 | ||
2344 | int | |
6c95b8df | 2345 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2346 | { |
6c95b8df | 2347 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2348 | return 1; |
c906108c | 2349 | |
6c95b8df | 2350 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2351 | return 1; |
2352 | ||
c906108c SS |
2353 | return 0; |
2354 | } | |
2355 | ||
4fa8626c DJ |
2356 | /* This function returns non-zero iff there is a software breakpoint |
2357 | inserted at PC. */ | |
2358 | ||
2359 | int | |
6c95b8df | 2360 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2361 | { |
876fa593 | 2362 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2363 | int any_breakpoint_here = 0; |
2364 | ||
876fa593 | 2365 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2366 | { |
2367 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2368 | continue; | |
2369 | ||
0d381245 | 2370 | if (bpt->inserted |
6c95b8df PA |
2371 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2372 | aspace, pc)) | |
4fa8626c DJ |
2373 | { |
2374 | if (overlay_debugging | |
2375 | && section_is_overlay (bpt->section) | |
2376 | && !section_is_mapped (bpt->section)) | |
2377 | continue; /* unmapped overlay -- can't be a match */ | |
2378 | else | |
2379 | return 1; | |
2380 | } | |
2381 | } | |
2382 | ||
1aafd4da | 2383 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2384 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2385 | return 1; |
2386 | ||
4fa8626c DJ |
2387 | return 0; |
2388 | } | |
2389 | ||
9093389c PA |
2390 | int |
2391 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2392 | CORE_ADDR addr, ULONGEST len) | |
2393 | { | |
2394 | struct breakpoint *bpt; | |
2395 | ||
2396 | ALL_BREAKPOINTS (bpt) | |
2397 | { | |
2398 | struct bp_location *loc; | |
2399 | ||
2400 | if (bpt->type != bp_hardware_watchpoint | |
2401 | && bpt->type != bp_access_watchpoint) | |
2402 | continue; | |
2403 | ||
2404 | if (!breakpoint_enabled (bpt)) | |
2405 | continue; | |
2406 | ||
2407 | for (loc = bpt->loc; loc; loc = loc->next) | |
2408 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2409 | { | |
2410 | CORE_ADDR l, h; | |
2411 | ||
2412 | /* Check for intersection. */ | |
2413 | l = max (loc->address, addr); | |
2414 | h = min (loc->address + loc->length, addr + len); | |
2415 | if (l < h) | |
2416 | return 1; | |
2417 | } | |
2418 | } | |
2419 | return 0; | |
2420 | } | |
2421 | ||
075f6582 DJ |
2422 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2423 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2424 | |
2425 | int | |
6c95b8df PA |
2426 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2427 | ptid_t ptid) | |
c906108c | 2428 | { |
876fa593 | 2429 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2430 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2431 | int thread = -1; |
4a306c9a | 2432 | int task = 0; |
a6f1cd96 | 2433 | |
876fa593 | 2434 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2435 | { |
075f6582 DJ |
2436 | if (bpt->loc_type != bp_loc_software_breakpoint |
2437 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2438 | continue; | |
2439 | ||
a6f1cd96 JB |
2440 | if (!breakpoint_enabled (bpt->owner) |
2441 | && bpt->owner->enable_state != bp_permanent) | |
2442 | continue; | |
2443 | ||
6c95b8df PA |
2444 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2445 | aspace, pc)) | |
a6f1cd96 JB |
2446 | continue; |
2447 | ||
2448 | if (bpt->owner->thread != -1) | |
075f6582 | 2449 | { |
a6f1cd96 JB |
2450 | /* This is a thread-specific breakpoint. Check that ptid |
2451 | matches that thread. If thread hasn't been computed yet, | |
2452 | it is now time to do so. */ | |
2453 | if (thread == -1) | |
2454 | thread = pid_to_thread_id (ptid); | |
2455 | if (bpt->owner->thread != thread) | |
2456 | continue; | |
075f6582 | 2457 | } |
a6f1cd96 | 2458 | |
4a306c9a JB |
2459 | if (bpt->owner->task != 0) |
2460 | { | |
2461 | /* This is a task-specific breakpoint. Check that ptid | |
2462 | matches that task. If task hasn't been computed yet, | |
2463 | it is now time to do so. */ | |
2464 | if (task == 0) | |
2465 | task = ada_get_task_number (ptid); | |
2466 | if (bpt->owner->task != task) | |
2467 | continue; | |
2468 | } | |
2469 | ||
a6f1cd96 JB |
2470 | if (overlay_debugging |
2471 | && section_is_overlay (bpt->section) | |
2472 | && !section_is_mapped (bpt->section)) | |
2473 | continue; /* unmapped overlay -- can't be a match */ | |
2474 | ||
2475 | return 1; | |
c5aa993b | 2476 | } |
c906108c SS |
2477 | |
2478 | return 0; | |
2479 | } | |
c906108c | 2480 | \f |
c5aa993b | 2481 | |
c906108c SS |
2482 | /* bpstat stuff. External routines' interfaces are documented |
2483 | in breakpoint.h. */ | |
2484 | ||
2485 | int | |
fba45db2 | 2486 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2487 | { |
533be4dd | 2488 | return (ep->type == bp_catchpoint); |
c906108c SS |
2489 | } |
2490 | ||
198757a8 VP |
2491 | void |
2492 | bpstat_free (bpstat bs) | |
2493 | { | |
2494 | if (bs->old_val != NULL) | |
2495 | value_free (bs->old_val); | |
2496 | free_command_lines (&bs->commands); | |
2497 | xfree (bs); | |
2498 | } | |
2499 | ||
c906108c SS |
2500 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2501 | Also free any storage that is part of a bpstat. */ | |
2502 | ||
2503 | void | |
fba45db2 | 2504 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2505 | { |
2506 | bpstat p; | |
2507 | bpstat q; | |
2508 | ||
2509 | if (bsp == 0) | |
2510 | return; | |
2511 | p = *bsp; | |
2512 | while (p != NULL) | |
2513 | { | |
2514 | q = p->next; | |
198757a8 | 2515 | bpstat_free (p); |
c906108c SS |
2516 | p = q; |
2517 | } | |
2518 | *bsp = NULL; | |
2519 | } | |
2520 | ||
2521 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2522 | is part of the bpstat is copied as well. */ | |
2523 | ||
2524 | bpstat | |
fba45db2 | 2525 | bpstat_copy (bpstat bs) |
c906108c SS |
2526 | { |
2527 | bpstat p = NULL; | |
2528 | bpstat tmp; | |
2529 | bpstat retval = NULL; | |
2530 | ||
2531 | if (bs == NULL) | |
2532 | return bs; | |
2533 | ||
2534 | for (; bs != NULL; bs = bs->next) | |
2535 | { | |
2536 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2537 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2538 | if (bs->commands != NULL) |
2539 | tmp->commands = copy_command_lines (bs->commands); | |
2540 | if (bs->old_val != NULL) | |
3c3185ac JK |
2541 | { |
2542 | tmp->old_val = value_copy (bs->old_val); | |
2543 | release_value (tmp->old_val); | |
2544 | } | |
31cc81e9 | 2545 | |
c906108c SS |
2546 | if (p == NULL) |
2547 | /* This is the first thing in the chain. */ | |
2548 | retval = tmp; | |
2549 | else | |
2550 | p->next = tmp; | |
2551 | p = tmp; | |
2552 | } | |
2553 | p->next = NULL; | |
2554 | return retval; | |
2555 | } | |
2556 | ||
2557 | /* Find the bpstat associated with this breakpoint */ | |
2558 | ||
2559 | bpstat | |
fba45db2 | 2560 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2561 | { |
c5aa993b JM |
2562 | if (bsp == NULL) |
2563 | return NULL; | |
c906108c | 2564 | |
c5aa993b JM |
2565 | for (; bsp != NULL; bsp = bsp->next) |
2566 | { | |
4f8d1dc6 | 2567 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2568 | return bsp; |
2569 | } | |
c906108c SS |
2570 | return NULL; |
2571 | } | |
2572 | ||
2573 | /* Find a step_resume breakpoint associated with this bpstat. | |
2574 | (If there are multiple step_resume bp's on the list, this function | |
2575 | will arbitrarily pick one.) | |
2576 | ||
2577 | It is an error to use this function if BPSTAT doesn't contain a | |
2578 | step_resume breakpoint. | |
2579 | ||
2580 | See wait_for_inferior's use of this function. */ | |
2581 | struct breakpoint * | |
fba45db2 | 2582 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2583 | { |
8601f500 MS |
2584 | int current_thread; |
2585 | ||
8a3fe4f8 | 2586 | gdb_assert (bsp != NULL); |
c906108c | 2587 | |
8601f500 MS |
2588 | current_thread = pid_to_thread_id (inferior_ptid); |
2589 | ||
c906108c SS |
2590 | for (; bsp != NULL; bsp = bsp->next) |
2591 | { | |
059fb39f PM |
2592 | if ((bsp->breakpoint_at != NULL) |
2593 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2594 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2595 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2596 | return bsp->breakpoint_at->owner; |
c906108c SS |
2597 | } |
2598 | ||
8a3fe4f8 | 2599 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2600 | } |
2601 | ||
2602 | ||
8671a17b | 2603 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2604 | at. *BSP upon return is a bpstat which points to the remaining |
2605 | breakpoints stopped at (but which is not guaranteed to be good for | |
2606 | anything but further calls to bpstat_num). | |
8671a17b PA |
2607 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2608 | Return -1 if stopped at a breakpoint that has been deleted since | |
2609 | we set it. | |
2610 | Return 1 otherwise. */ | |
c906108c SS |
2611 | |
2612 | int | |
8671a17b | 2613 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2614 | { |
2615 | struct breakpoint *b; | |
2616 | ||
2617 | if ((*bsp) == NULL) | |
2618 | return 0; /* No more breakpoint values */ | |
8671a17b | 2619 | |
4f8d1dc6 VP |
2620 | /* We assume we'll never have several bpstats that |
2621 | correspond to a single breakpoint -- otherwise, | |
2622 | this function might return the same number more | |
2623 | than once and this will look ugly. */ | |
2624 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2625 | *bsp = (*bsp)->next; |
2626 | if (b == NULL) | |
2627 | return -1; /* breakpoint that's been deleted since */ | |
2628 | ||
2629 | *num = b->number; /* We have its number */ | |
2630 | return 1; | |
c906108c SS |
2631 | } |
2632 | ||
2633 | /* Modify BS so that the actions will not be performed. */ | |
2634 | ||
2635 | void | |
fba45db2 | 2636 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2637 | { |
2638 | for (; bs != NULL; bs = bs->next) | |
2639 | { | |
c2b8ed2c | 2640 | free_command_lines (&bs->commands); |
c906108c SS |
2641 | if (bs->old_val != NULL) |
2642 | { | |
2643 | value_free (bs->old_val); | |
2644 | bs->old_val = NULL; | |
2645 | } | |
2646 | } | |
2647 | } | |
2648 | ||
f3b1572e PA |
2649 | /* Called when a command is about to proceed the inferior. */ |
2650 | ||
2651 | static void | |
2652 | breakpoint_about_to_proceed (void) | |
2653 | { | |
2654 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2655 | { | |
2656 | struct thread_info *tp = inferior_thread (); | |
2657 | ||
2658 | /* Allow inferior function calls in breakpoint commands to not | |
2659 | interrupt the command list. When the call finishes | |
2660 | successfully, the inferior will be standing at the same | |
2661 | breakpoint as if nothing happened. */ | |
2662 | if (tp->in_infcall) | |
2663 | return; | |
2664 | } | |
2665 | ||
2666 | breakpoint_proceeded = 1; | |
2667 | } | |
2668 | ||
c906108c | 2669 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2670 | static void |
4efb68b1 | 2671 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2672 | { |
2673 | executing_breakpoint_commands = 0; | |
2674 | } | |
2675 | ||
2676 | /* Execute all the commands associated with all the breakpoints at this | |
2677 | location. Any of these commands could cause the process to proceed | |
2678 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2679 | the global "breakpoint_proceeded" after each command. |
c906108c | 2680 | |
347bddb7 PA |
2681 | Returns true if a breakpoint command resumed the inferior. In that |
2682 | case, it is the caller's responsibility to recall it again with the | |
2683 | bpstat of the current thread. */ | |
2684 | ||
2685 | static int | |
2686 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2687 | { |
2688 | bpstat bs; | |
2689 | struct cleanup *old_chain; | |
347bddb7 | 2690 | int again = 0; |
c906108c SS |
2691 | |
2692 | /* Avoid endless recursion if a `source' command is contained | |
2693 | in bs->commands. */ | |
2694 | if (executing_breakpoint_commands) | |
347bddb7 | 2695 | return 0; |
c906108c SS |
2696 | |
2697 | executing_breakpoint_commands = 1; | |
2698 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2699 | ||
c906108c SS |
2700 | /* This pointer will iterate over the list of bpstat's. */ |
2701 | bs = *bsp; | |
2702 | ||
2703 | breakpoint_proceeded = 0; | |
2704 | for (; bs != NULL; bs = bs->next) | |
2705 | { | |
6c50ab1c JB |
2706 | struct command_line *cmd; |
2707 | struct cleanup *this_cmd_tree_chain; | |
2708 | ||
2709 | /* Take ownership of the BSP's command tree, if it has one. | |
2710 | ||
2711 | The command tree could legitimately contain commands like | |
2712 | 'step' and 'next', which call clear_proceed_status, which | |
2713 | frees stop_bpstat's command tree. To make sure this doesn't | |
2714 | free the tree we're executing out from under us, we need to | |
2715 | take ownership of the tree ourselves. Since a given bpstat's | |
2716 | commands are only executed once, we don't need to copy it; we | |
2717 | can clear the pointer in the bpstat, and make sure we free | |
2718 | the tree when we're done. */ | |
c906108c | 2719 | cmd = bs->commands; |
6c50ab1c JB |
2720 | bs->commands = 0; |
2721 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2722 | ||
c906108c SS |
2723 | while (cmd != NULL) |
2724 | { | |
2725 | execute_control_command (cmd); | |
2726 | ||
2727 | if (breakpoint_proceeded) | |
2728 | break; | |
2729 | else | |
2730 | cmd = cmd->next; | |
2731 | } | |
6c50ab1c JB |
2732 | |
2733 | /* We can free this command tree now. */ | |
2734 | do_cleanups (this_cmd_tree_chain); | |
2735 | ||
c906108c | 2736 | if (breakpoint_proceeded) |
32c1e744 VP |
2737 | { |
2738 | if (target_can_async_p ()) | |
347bddb7 PA |
2739 | /* If we are in async mode, then the target might be still |
2740 | running, not stopped at any breakpoint, so nothing for | |
2741 | us to do here -- just return to the event loop. */ | |
2742 | ; | |
32c1e744 VP |
2743 | else |
2744 | /* In sync mode, when execute_control_command returns | |
2745 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2746 | Breakpoint commands for that stop were not run, since |
2747 | execute_command does not run breakpoint commands -- | |
2748 | only command_line_handler does, but that one is not | |
2749 | involved in execution of breakpoint commands. So, we | |
2750 | can now execute breakpoint commands. It should be | |
2751 | noted that making execute_command do bpstat actions is | |
2752 | not an option -- in this case we'll have recursive | |
2753 | invocation of bpstat for each breakpoint with a | |
2754 | command, and can easily blow up GDB stack. Instead, we | |
2755 | return true, which will trigger the caller to recall us | |
2756 | with the new stop_bpstat. */ | |
2757 | again = 1; | |
2758 | break; | |
32c1e744 | 2759 | } |
c906108c | 2760 | } |
c2b8ed2c | 2761 | do_cleanups (old_chain); |
347bddb7 PA |
2762 | return again; |
2763 | } | |
2764 | ||
2765 | void | |
2766 | bpstat_do_actions (void) | |
2767 | { | |
2768 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2769 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2770 | && target_has_execution | |
2771 | && !is_exited (inferior_ptid) | |
2772 | && !is_executing (inferior_ptid)) | |
2773 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2774 | and only return when it is stopped at the next breakpoint, we | |
2775 | keep doing breakpoint actions until it returns false to | |
2776 | indicate the inferior was not resumed. */ | |
2777 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2778 | break; | |
c906108c SS |
2779 | } |
2780 | ||
fa4727a6 DJ |
2781 | /* Print out the (old or new) value associated with a watchpoint. */ |
2782 | ||
2783 | static void | |
2784 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2785 | { | |
2786 | if (val == NULL) | |
2787 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2788 | else | |
79a45b7d TT |
2789 | { |
2790 | struct value_print_options opts; | |
2791 | get_user_print_options (&opts); | |
2792 | value_print (val, stream, &opts); | |
2793 | } | |
fa4727a6 DJ |
2794 | } |
2795 | ||
e514a9d6 | 2796 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2797 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2798 | by having it set different print_it values. |
2799 | ||
2800 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2801 | through the bpstat list of things causing this stop, calling the | |
2802 | print_bp_stop_message function on each one. The behavior of the | |
2803 | print_bp_stop_message function depends on the print_it field of | |
2804 | bpstat. If such field so indicates, call this function here. | |
2805 | ||
2806 | Return values from this routine (ultimately used by bpstat_print() | |
2807 | and normal_stop() to decide what to do): | |
2808 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2809 | don't print anything else. | |
2810 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2811 | that something to be followed by a location. | |
2812 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2813 | that something to be followed by a location. | |
2814 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2815 | analysis. */ | |
c906108c | 2816 | |
917317f4 | 2817 | static enum print_stop_action |
fba45db2 | 2818 | print_it_typical (bpstat bs) |
c906108c | 2819 | { |
f7545552 | 2820 | struct cleanup *old_chain; |
4f8d1dc6 | 2821 | struct breakpoint *b; |
89f9893c | 2822 | const struct bp_location *bl; |
8b93c638 | 2823 | struct ui_stream *stb; |
f7545552 TT |
2824 | int bp_temp = 0; |
2825 | enum print_stop_action result; | |
2826 | ||
c906108c SS |
2827 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2828 | which has since been deleted. */ | |
e514a9d6 | 2829 | if (bs->breakpoint_at == NULL) |
917317f4 | 2830 | return PRINT_UNKNOWN; |
0d381245 VP |
2831 | bl = bs->breakpoint_at; |
2832 | b = bl->owner; | |
c906108c | 2833 | |
f7545552 TT |
2834 | stb = ui_out_stream_new (uiout); |
2835 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2836 | ||
4f8d1dc6 | 2837 | switch (b->type) |
c906108c | 2838 | { |
e514a9d6 JM |
2839 | case bp_breakpoint: |
2840 | case bp_hardware_breakpoint: | |
2cec12e5 | 2841 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2842 | if (bl->address != bl->requested_address) |
2843 | breakpoint_adjustment_warning (bl->requested_address, | |
2844 | bl->address, | |
4f8d1dc6 VP |
2845 | b->number, 1); |
2846 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2847 | if (bp_temp) |
2848 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2849 | else | |
2850 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2851 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2852 | { |
2853 | ui_out_field_string (uiout, "reason", | |
2854 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2855 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2856 | } | |
4f8d1dc6 | 2857 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2858 | ui_out_text (uiout, ", "); |
f7545552 | 2859 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2860 | break; |
2861 | ||
2862 | case bp_shlib_event: | |
917317f4 JM |
2863 | /* Did we stop because the user set the stop_on_solib_events |
2864 | variable? (If so, we report this as a generic, "Stopped due | |
2865 | to shlib event" message.) */ | |
a3f17187 | 2866 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2867 | result = PRINT_NOTHING; |
e514a9d6 JM |
2868 | break; |
2869 | ||
c4093a6a JM |
2870 | case bp_thread_event: |
2871 | /* Not sure how we will get here. | |
2872 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2873 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2874 | result = PRINT_NOTHING; |
c4093a6a JM |
2875 | break; |
2876 | ||
1900040c MS |
2877 | case bp_overlay_event: |
2878 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2879 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2880 | result = PRINT_NOTHING; |
1900040c MS |
2881 | break; |
2882 | ||
0fd8e87f UW |
2883 | case bp_longjmp_master: |
2884 | /* These should never be enabled. */ | |
2885 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2886 | result = PRINT_NOTHING; | |
2887 | break; | |
2888 | ||
e514a9d6 JM |
2889 | case bp_watchpoint: |
2890 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2891 | annotate_watchpoint (b->number); |
2892 | if (ui_out_is_mi_like_p (uiout)) | |
2893 | ui_out_field_string | |
2894 | (uiout, "reason", | |
2895 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2896 | mention (b); | |
f7545552 | 2897 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2898 | ui_out_text (uiout, "\nOld value = "); |
2899 | watchpoint_value_print (bs->old_val, stb->stream); | |
2900 | ui_out_field_stream (uiout, "old", stb); | |
2901 | ui_out_text (uiout, "\nNew value = "); | |
2902 | watchpoint_value_print (b->val, stb->stream); | |
2903 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2904 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2905 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2906 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2907 | break; |
2908 | ||
2909 | case bp_read_watchpoint: | |
9dc5e2a9 | 2910 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2911 | ui_out_field_string |
2912 | (uiout, "reason", | |
2913 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2914 | mention (b); |
f7545552 | 2915 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2916 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2917 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2918 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2919 | ui_out_text (uiout, "\n"); |
f7545552 | 2920 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2921 | break; |
2922 | ||
2923 | case bp_access_watchpoint: | |
fa4727a6 | 2924 | if (bs->old_val != NULL) |
8b93c638 | 2925 | { |
4f8d1dc6 | 2926 | annotate_watchpoint (b->number); |
9dc5e2a9 | 2927 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2928 | ui_out_field_string |
2929 | (uiout, "reason", | |
2930 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2931 | mention (b); |
f7545552 | 2932 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2933 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 2934 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 2935 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
2936 | ui_out_text (uiout, "\nNew value = "); |
2937 | } | |
2938 | else | |
2939 | { | |
4f8d1dc6 | 2940 | mention (b); |
9dc5e2a9 | 2941 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2942 | ui_out_field_string |
2943 | (uiout, "reason", | |
2944 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 2945 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
2946 | ui_out_text (uiout, "\nValue = "); |
2947 | } | |
fa4727a6 | 2948 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2949 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 2950 | ui_out_text (uiout, "\n"); |
f7545552 | 2951 | result = PRINT_UNKNOWN; |
e514a9d6 | 2952 | break; |
4ce44c66 | 2953 | |
e514a9d6 JM |
2954 | /* Fall through, we don't deal with these types of breakpoints |
2955 | here. */ | |
2956 | ||
11cf8741 | 2957 | case bp_finish: |
9dc5e2a9 | 2958 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2959 | ui_out_field_string |
2960 | (uiout, "reason", | |
2961 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 2962 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2963 | break; |
2964 | ||
e514a9d6 | 2965 | case bp_until: |
9dc5e2a9 | 2966 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
2967 | ui_out_field_string |
2968 | (uiout, "reason", | |
2969 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 2970 | result = PRINT_UNKNOWN; |
8b93c638 JM |
2971 | break; |
2972 | ||
c2d11a7d | 2973 | case bp_none: |
e514a9d6 JM |
2974 | case bp_longjmp: |
2975 | case bp_longjmp_resume: | |
2976 | case bp_step_resume: | |
e514a9d6 JM |
2977 | case bp_watchpoint_scope: |
2978 | case bp_call_dummy: | |
1042e4c0 | 2979 | case bp_tracepoint: |
4efc6507 | 2980 | case bp_jit_event: |
e514a9d6 | 2981 | default: |
f7545552 TT |
2982 | result = PRINT_UNKNOWN; |
2983 | break; | |
e514a9d6 | 2984 | } |
f7545552 TT |
2985 | |
2986 | do_cleanups (old_chain); | |
2987 | return result; | |
e514a9d6 JM |
2988 | } |
2989 | ||
2990 | /* Generic routine for printing messages indicating why we | |
2991 | stopped. The behavior of this function depends on the value | |
2992 | 'print_it' in the bpstat structure. Under some circumstances we | |
2993 | may decide not to print anything here and delegate the task to | |
2994 | normal_stop(). */ | |
2995 | ||
2996 | static enum print_stop_action | |
2997 | print_bp_stop_message (bpstat bs) | |
2998 | { | |
2999 | switch (bs->print_it) | |
3000 | { | |
3001 | case print_it_noop: | |
3002 | /* Nothing should be printed for this bpstat entry. */ | |
3003 | return PRINT_UNKNOWN; | |
3004 | break; | |
3005 | ||
3006 | case print_it_done: | |
3007 | /* We still want to print the frame, but we already printed the | |
3008 | relevant messages. */ | |
3009 | return PRINT_SRC_AND_LOC; | |
3010 | break; | |
3011 | ||
3012 | case print_it_normal: | |
4f8d1dc6 | 3013 | { |
89f9893c | 3014 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3015 | struct breakpoint *b = bl ? bl->owner : NULL; |
3016 | ||
3017 | /* Normal case. Call the breakpoint's print_it method, or | |
3018 | print_it_typical. */ | |
3019 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3020 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3021 | return b->ops->print_it (b); | |
3022 | else | |
3023 | return print_it_typical (bs); | |
3024 | } | |
3025 | break; | |
3086aeae | 3026 | |
e514a9d6 | 3027 | default: |
8e65ff28 | 3028 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3029 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3030 | break; |
c906108c | 3031 | } |
c906108c SS |
3032 | } |
3033 | ||
e514a9d6 JM |
3034 | /* Print a message indicating what happened. This is called from |
3035 | normal_stop(). The input to this routine is the head of the bpstat | |
3036 | list - a list of the eventpoints that caused this stop. This | |
3037 | routine calls the generic print routine for printing a message | |
3038 | about reasons for stopping. This will print (for example) the | |
3039 | "Breakpoint n," part of the output. The return value of this | |
3040 | routine is one of: | |
c906108c | 3041 | |
917317f4 JM |
3042 | PRINT_UNKNOWN: Means we printed nothing |
3043 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3044 | code to print the location. An example is |
3045 | "Breakpoint 1, " which should be followed by | |
3046 | the location. | |
917317f4 | 3047 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3048 | to also print the location part of the message. |
3049 | An example is the catch/throw messages, which | |
917317f4 JM |
3050 | don't require a location appended to the end. |
3051 | PRINT_NOTHING: We have done some printing and we don't need any | |
3052 | further info to be printed.*/ | |
c906108c | 3053 | |
917317f4 | 3054 | enum print_stop_action |
fba45db2 | 3055 | bpstat_print (bpstat bs) |
c906108c SS |
3056 | { |
3057 | int val; | |
c5aa993b | 3058 | |
c906108c | 3059 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3060 | (Currently all watchpoints go on the bpstat whether hit or not. |
3061 | That probably could (should) be changed, provided care is taken | |
c906108c | 3062 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3063 | for (; bs; bs = bs->next) |
3064 | { | |
3065 | val = print_bp_stop_message (bs); | |
3066 | if (val == PRINT_SRC_ONLY | |
3067 | || val == PRINT_SRC_AND_LOC | |
3068 | || val == PRINT_NOTHING) | |
3069 | return val; | |
3070 | } | |
c906108c | 3071 | |
e514a9d6 JM |
3072 | /* We reached the end of the chain, or we got a null BS to start |
3073 | with and nothing was printed. */ | |
917317f4 | 3074 | return PRINT_UNKNOWN; |
c906108c SS |
3075 | } |
3076 | ||
3077 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3078 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3079 | The argument is a "struct expression *" that has been cast to char * to | |
3080 | make it pass through catch_errors. */ | |
3081 | ||
3082 | static int | |
4efb68b1 | 3083 | breakpoint_cond_eval (void *exp) |
c906108c | 3084 | { |
278cd55f | 3085 | struct value *mark = value_mark (); |
c5aa993b | 3086 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
3087 | value_free_to_mark (mark); |
3088 | return i; | |
3089 | } | |
3090 | ||
3091 | /* Allocate a new bpstat and chain it to the current one. */ | |
3092 | ||
3093 | static bpstat | |
89f9893c | 3094 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3095 | { |
3096 | bpstat bs; | |
3097 | ||
3098 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3099 | cbs->next = bs; | |
4f8d1dc6 | 3100 | bs->breakpoint_at = bl; |
c906108c SS |
3101 | /* If the condition is false, etc., don't do the commands. */ |
3102 | bs->commands = NULL; | |
3103 | bs->old_val = NULL; | |
3104 | bs->print_it = print_it_normal; | |
3105 | return bs; | |
3106 | } | |
3107 | \f | |
d983da9c DJ |
3108 | /* The target has stopped with waitstatus WS. Check if any hardware |
3109 | watchpoints have triggered, according to the target. */ | |
3110 | ||
3111 | int | |
3112 | watchpoints_triggered (struct target_waitstatus *ws) | |
3113 | { | |
d92524f1 | 3114 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3115 | CORE_ADDR addr; |
3116 | struct breakpoint *b; | |
3117 | ||
3118 | if (!stopped_by_watchpoint) | |
3119 | { | |
3120 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3121 | as not triggered. */ | |
3122 | ALL_BREAKPOINTS (b) | |
3123 | if (b->type == bp_hardware_watchpoint | |
3124 | || b->type == bp_read_watchpoint | |
3125 | || b->type == bp_access_watchpoint) | |
3126 | b->watchpoint_triggered = watch_triggered_no; | |
3127 | ||
3128 | return 0; | |
3129 | } | |
3130 | ||
3131 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3132 | { | |
3133 | /* We were stopped by a watchpoint, but we don't know where. | |
3134 | Mark all watchpoints as unknown. */ | |
3135 | ALL_BREAKPOINTS (b) | |
3136 | if (b->type == bp_hardware_watchpoint | |
3137 | || b->type == bp_read_watchpoint | |
3138 | || b->type == bp_access_watchpoint) | |
3139 | b->watchpoint_triggered = watch_triggered_unknown; | |
3140 | ||
3141 | return stopped_by_watchpoint; | |
3142 | } | |
3143 | ||
3144 | /* The target could report the data address. Mark watchpoints | |
3145 | affected by this data address as triggered, and all others as not | |
3146 | triggered. */ | |
3147 | ||
3148 | ALL_BREAKPOINTS (b) | |
3149 | if (b->type == bp_hardware_watchpoint | |
3150 | || b->type == bp_read_watchpoint | |
3151 | || b->type == bp_access_watchpoint) | |
3152 | { | |
a5606eee | 3153 | struct bp_location *loc; |
d983da9c DJ |
3154 | struct value *v; |
3155 | ||
3156 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3157 | for (loc = b->loc; loc; loc = loc->next) |
3158 | /* Exact match not required. Within range is | |
3159 | sufficient. */ | |
5009afc5 AS |
3160 | if (target_watchpoint_addr_within_range (¤t_target, |
3161 | addr, loc->address, | |
3162 | loc->length)) | |
a5606eee VP |
3163 | { |
3164 | b->watchpoint_triggered = watch_triggered_yes; | |
3165 | break; | |
3166 | } | |
d983da9c DJ |
3167 | } |
3168 | ||
3169 | return 1; | |
3170 | } | |
3171 | ||
c906108c SS |
3172 | /* Possible return values for watchpoint_check (this can't be an enum |
3173 | because of check_errors). */ | |
3174 | /* The watchpoint has been deleted. */ | |
3175 | #define WP_DELETED 1 | |
3176 | /* The value has changed. */ | |
3177 | #define WP_VALUE_CHANGED 2 | |
3178 | /* The value has not changed. */ | |
3179 | #define WP_VALUE_NOT_CHANGED 3 | |
3180 | ||
3181 | #define BP_TEMPFLAG 1 | |
3182 | #define BP_HARDWAREFLAG 2 | |
3183 | ||
553e4c11 JB |
3184 | /* Evaluate watchpoint condition expression and check if its value changed. |
3185 | ||
3186 | P should be a pointer to struct bpstat, but is defined as a void * | |
3187 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3188 | |
3189 | static int | |
4efb68b1 | 3190 | watchpoint_check (void *p) |
c906108c SS |
3191 | { |
3192 | bpstat bs = (bpstat) p; | |
3193 | struct breakpoint *b; | |
3194 | struct frame_info *fr; | |
3195 | int within_current_scope; | |
3196 | ||
4f8d1dc6 | 3197 | b = bs->breakpoint_at->owner; |
c906108c | 3198 | |
f6bc2008 PA |
3199 | /* If this is a local watchpoint, we only want to check if the |
3200 | watchpoint frame is in scope if the current thread is the thread | |
3201 | that was used to create the watchpoint. */ | |
3202 | if (!watchpoint_in_thread_scope (b)) | |
3203 | return WP_VALUE_NOT_CHANGED; | |
3204 | ||
c906108c SS |
3205 | if (b->exp_valid_block == NULL) |
3206 | within_current_scope = 1; | |
3207 | else | |
3208 | { | |
edb3359d DJ |
3209 | struct frame_info *frame = get_current_frame (); |
3210 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3211 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3212 | ||
101dcfbe | 3213 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3214 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3215 | |
3216 | /* If we've gotten confused in the unwinder, we might have | |
3217 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3218 | if (within_current_scope) |
3219 | { | |
3220 | struct symbol *function; | |
3221 | ||
3222 | function = get_frame_function (fr); | |
3223 | if (function == NULL | |
3224 | || !contained_in (b->exp_valid_block, | |
3225 | SYMBOL_BLOCK_VALUE (function))) | |
3226 | within_current_scope = 0; | |
3227 | } | |
69fbadd5 | 3228 | |
c12260ac CV |
3229 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3230 | in the function but the stack frame has already been invalidated. | |
3231 | Since we can't rely on the values of local variables after the | |
3232 | stack has been destroyed, we are treating the watchpoint in that | |
edb3359d DJ |
3233 | state as `not changed' without further checking. Don't mark |
3234 | watchpoints as changed if the current frame is in an epilogue - | |
3235 | even if they are in some other frame, our view of the stack | |
3236 | is likely to be wrong. */ | |
3237 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
3238 | return WP_VALUE_NOT_CHANGED; | |
fb14de7b | 3239 | |
edb3359d | 3240 | if (within_current_scope) |
c906108c SS |
3241 | /* If we end up stopping, the current frame will get selected |
3242 | in normal_stop. So this call to select_frame won't affect | |
3243 | the user. */ | |
0f7d239c | 3244 | select_frame (fr); |
c906108c | 3245 | } |
c5aa993b | 3246 | |
c906108c SS |
3247 | if (within_current_scope) |
3248 | { | |
3249 | /* We use value_{,free_to_}mark because it could be a | |
3250 | *long* time before we return to the command level and | |
c5aa993b JM |
3251 | call free_all_values. We can't call free_all_values because |
3252 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3253 | |
278cd55f | 3254 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3255 | struct value *new_val; |
3256 | ||
3257 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
218d2fc6 TJB |
3258 | |
3259 | /* We use value_equal_contents instead of value_equal because the latter | |
3260 | coerces an array to a pointer, thus comparing just the address of the | |
3261 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3262 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3263 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3264 | { |
fa4727a6 DJ |
3265 | if (new_val != NULL) |
3266 | { | |
3267 | release_value (new_val); | |
3268 | value_free_to_mark (mark); | |
3269 | } | |
c906108c SS |
3270 | bs->old_val = b->val; |
3271 | b->val = new_val; | |
fa4727a6 | 3272 | b->val_valid = 1; |
c906108c SS |
3273 | /* We will stop here */ |
3274 | return WP_VALUE_CHANGED; | |
3275 | } | |
3276 | else | |
3277 | { | |
3278 | /* Nothing changed, don't do anything. */ | |
3279 | value_free_to_mark (mark); | |
3280 | /* We won't stop here */ | |
3281 | return WP_VALUE_NOT_CHANGED; | |
3282 | } | |
3283 | } | |
3284 | else | |
3285 | { | |
3286 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3287 | if we temporarily ignored the watchpoint, then when |
3288 | we reenter the block in which it is valid it contains | |
3289 | garbage (in the case of a function, it may have two | |
3290 | garbage values, one before and one after the prologue). | |
3291 | So we can't even detect the first assignment to it and | |
3292 | watch after that (since the garbage may or may not equal | |
3293 | the first value assigned). */ | |
4ce44c66 JM |
3294 | /* We print all the stop information in print_it_typical(), but |
3295 | in this case, by the time we call print_it_typical() this bp | |
3296 | will be deleted already. So we have no choice but print the | |
3297 | information here. */ | |
9dc5e2a9 | 3298 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3299 | ui_out_field_string |
3300 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3301 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3302 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3303 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3304 | which its expression is valid.\n"); | |
4ce44c66 | 3305 | |
c906108c | 3306 | if (b->related_breakpoint) |
b5de0fa7 EZ |
3307 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
3308 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
3309 | |
3310 | return WP_DELETED; | |
3311 | } | |
3312 | } | |
3313 | ||
18a18393 VP |
3314 | /* Return true if it looks like target has stopped due to hitting |
3315 | breakpoint location BL. This function does not check if we | |
3316 | should stop, only if BL explains the stop. */ | |
3317 | static int | |
6c95b8df PA |
3318 | bpstat_check_location (const struct bp_location *bl, |
3319 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3320 | { |
3321 | struct breakpoint *b = bl->owner; | |
3322 | ||
e8595ef6 SS |
3323 | /* By definition, the inferior does not report stops at |
3324 | tracepoints. */ | |
3325 | if (b->type == bp_tracepoint) | |
3326 | return 0; | |
3327 | ||
18a18393 VP |
3328 | if (b->type != bp_watchpoint |
3329 | && b->type != bp_hardware_watchpoint | |
3330 | && b->type != bp_read_watchpoint | |
3331 | && b->type != bp_access_watchpoint | |
3332 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3333 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3334 | { |
6c95b8df PA |
3335 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3336 | aspace, bp_addr)) | |
18a18393 VP |
3337 | return 0; |
3338 | if (overlay_debugging /* unmapped overlay section */ | |
3339 | && section_is_overlay (bl->section) | |
3340 | && !section_is_mapped (bl->section)) | |
3341 | return 0; | |
3342 | } | |
3343 | ||
3344 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3345 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3346 | some data address). Otherwise gdb won't stop on a break instruction | |
3347 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3348 | been defined. Also skip watchpoints which we know did not trigger | |
3349 | (did not match the data address). */ | |
3350 | ||
3351 | if ((b->type == bp_hardware_watchpoint | |
3352 | || b->type == bp_read_watchpoint | |
3353 | || b->type == bp_access_watchpoint) | |
3354 | && b->watchpoint_triggered == watch_triggered_no) | |
3355 | return 0; | |
3356 | ||
3357 | if (b->type == bp_hardware_breakpoint) | |
3358 | { | |
3359 | if (bl->address != bp_addr) | |
3360 | return 0; | |
3361 | if (overlay_debugging /* unmapped overlay section */ | |
3362 | && section_is_overlay (bl->section) | |
3363 | && !section_is_mapped (bl->section)) | |
3364 | return 0; | |
3365 | } | |
ce78b96d | 3366 | |
ce78b96d JB |
3367 | if (b->type == bp_catchpoint) |
3368 | { | |
3369 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3370 | if (!b->ops->breakpoint_hit (b)) | |
3371 | return 0; | |
3372 | } | |
3373 | ||
18a18393 VP |
3374 | return 1; |
3375 | } | |
3376 | ||
3377 | /* If BS refers to a watchpoint, determine if the watched values | |
3378 | has actually changed, and we should stop. If not, set BS->stop | |
3379 | to 0. */ | |
3380 | static void | |
3381 | bpstat_check_watchpoint (bpstat bs) | |
3382 | { | |
3383 | const struct bp_location *bl = bs->breakpoint_at; | |
3384 | struct breakpoint *b = bl->owner; | |
3385 | ||
3386 | if (b->type == bp_watchpoint | |
3387 | || b->type == bp_read_watchpoint | |
3388 | || b->type == bp_access_watchpoint | |
3389 | || b->type == bp_hardware_watchpoint) | |
3390 | { | |
3391 | CORE_ADDR addr; | |
3392 | struct value *v; | |
3393 | int must_check_value = 0; | |
3394 | ||
3395 | if (b->type == bp_watchpoint) | |
3396 | /* For a software watchpoint, we must always check the | |
3397 | watched value. */ | |
3398 | must_check_value = 1; | |
3399 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3400 | /* We have a hardware watchpoint (read, write, or access) | |
3401 | and the target earlier reported an address watched by | |
3402 | this watchpoint. */ | |
3403 | must_check_value = 1; | |
3404 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3405 | && b->type == bp_hardware_watchpoint) | |
3406 | /* We were stopped by a hardware watchpoint, but the target could | |
3407 | not report the data address. We must check the watchpoint's | |
3408 | value. Access and read watchpoints are out of luck; without | |
3409 | a data address, we can't figure it out. */ | |
3410 | must_check_value = 1; | |
3411 | ||
3412 | if (must_check_value) | |
3413 | { | |
3414 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3415 | b->number); | |
3416 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3417 | int e = catch_errors (watchpoint_check, bs, message, | |
3418 | RETURN_MASK_ALL); | |
3419 | do_cleanups (cleanups); | |
3420 | switch (e) | |
3421 | { | |
3422 | case WP_DELETED: | |
3423 | /* We've already printed what needs to be printed. */ | |
3424 | bs->print_it = print_it_done; | |
3425 | /* Stop. */ | |
3426 | break; | |
3427 | case WP_VALUE_CHANGED: | |
3428 | if (b->type == bp_read_watchpoint) | |
3429 | { | |
3430 | /* Don't stop: read watchpoints shouldn't fire if | |
3431 | the value has changed. This is for targets | |
3432 | which cannot set read-only watchpoints. */ | |
3433 | bs->print_it = print_it_noop; | |
3434 | bs->stop = 0; | |
3435 | } | |
3436 | break; | |
3437 | case WP_VALUE_NOT_CHANGED: | |
3438 | if (b->type == bp_hardware_watchpoint | |
3439 | || b->type == bp_watchpoint) | |
3440 | { | |
3441 | /* Don't stop: write watchpoints shouldn't fire if | |
3442 | the value hasn't changed. */ | |
3443 | bs->print_it = print_it_noop; | |
3444 | bs->stop = 0; | |
3445 | } | |
3446 | /* Stop. */ | |
3447 | break; | |
3448 | default: | |
3449 | /* Can't happen. */ | |
3450 | case 0: | |
3451 | /* Error from catch_errors. */ | |
3452 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3453 | if (b->related_breakpoint) | |
3454 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3455 | b->disposition = disp_del_at_next_stop; | |
3456 | /* We've already printed what needs to be printed. */ | |
3457 | bs->print_it = print_it_done; | |
3458 | break; | |
3459 | } | |
3460 | } | |
3461 | else /* must_check_value == 0 */ | |
3462 | { | |
3463 | /* This is a case where some watchpoint(s) triggered, but | |
3464 | not at the address of this watchpoint, or else no | |
3465 | watchpoint triggered after all. So don't print | |
3466 | anything for this watchpoint. */ | |
3467 | bs->print_it = print_it_noop; | |
3468 | bs->stop = 0; | |
3469 | } | |
3470 | } | |
3471 | } | |
3472 | ||
3473 | ||
3474 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3475 | of breakpoint referred to by BS. If we should not stop for this | |
3476 | breakpoint, set BS->stop to 0. */ | |
3477 | static void | |
3478 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3479 | { | |
3480 | int thread_id = pid_to_thread_id (ptid); | |
3481 | const struct bp_location *bl = bs->breakpoint_at; | |
3482 | struct breakpoint *b = bl->owner; | |
3483 | ||
3484 | if (frame_id_p (b->frame_id) | |
edb3359d | 3485 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3486 | bs->stop = 0; |
3487 | else if (bs->stop) | |
3488 | { | |
3489 | int value_is_zero = 0; | |
3490 | ||
3491 | /* If this is a scope breakpoint, mark the associated | |
3492 | watchpoint as triggered so that we will handle the | |
3493 | out-of-scope event. We'll get to the watchpoint next | |
3494 | iteration. */ | |
3495 | if (b->type == bp_watchpoint_scope) | |
3496 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3497 | ||
3498 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3499 | { | |
c5bc3a77 DJ |
3500 | /* We use value_mark and value_free_to_mark because it could |
3501 | be a long time before we return to the command level and | |
3502 | call free_all_values. We can't call free_all_values | |
3503 | because we might be in the middle of evaluating a | |
3504 | function call. */ | |
3505 | struct value *mark = value_mark (); | |
3506 | ||
edb3359d DJ |
3507 | /* Need to select the frame, with all that implies so that |
3508 | the conditions will have the right context. Because we | |
3509 | use the frame, we will not see an inlined function's | |
3510 | variables when we arrive at a breakpoint at the start | |
3511 | of the inlined function; the current frame will be the | |
3512 | call site. */ | |
18a18393 VP |
3513 | select_frame (get_current_frame ()); |
3514 | value_is_zero | |
3515 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3516 | "Error in testing breakpoint condition:\n", | |
3517 | RETURN_MASK_ALL); | |
3518 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3519 | value_free_to_mark (mark); |
18a18393 VP |
3520 | } |
3521 | if (bl->cond && value_is_zero) | |
3522 | { | |
3523 | bs->stop = 0; | |
3524 | } | |
3525 | else if (b->thread != -1 && b->thread != thread_id) | |
3526 | { | |
3527 | bs->stop = 0; | |
3528 | } | |
3529 | else if (b->ignore_count > 0) | |
3530 | { | |
3531 | b->ignore_count--; | |
3532 | annotate_ignore_count_change (); | |
3533 | bs->stop = 0; | |
3534 | /* Increase the hit count even though we don't | |
3535 | stop. */ | |
3536 | ++(b->hit_count); | |
3537 | } | |
3538 | } | |
3539 | } | |
3540 | ||
3541 | ||
9709f61c | 3542 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3543 | BP_ADDR in thread PTID. |
c906108c | 3544 | |
d983da9c | 3545 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3546 | don't understand this stop. Result is a chain of bpstat's such that: |
3547 | ||
c5aa993b | 3548 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3549 | |
c5aa993b | 3550 | if we understand why we stopped, the result is not null. |
c906108c | 3551 | |
c5aa993b JM |
3552 | Each element of the chain refers to a particular breakpoint or |
3553 | watchpoint at which we have stopped. (We may have stopped for | |
3554 | several reasons concurrently.) | |
c906108c | 3555 | |
c5aa993b JM |
3556 | Each element of the chain has valid next, breakpoint_at, |
3557 | commands, FIXME??? fields. */ | |
c906108c SS |
3558 | |
3559 | bpstat | |
6c95b8df PA |
3560 | bpstat_stop_status (struct address_space *aspace, |
3561 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 3562 | { |
0d381245 | 3563 | struct breakpoint *b = NULL; |
876fa593 | 3564 | struct bp_location *bl, **blp_tmp; |
20874c92 | 3565 | struct bp_location *loc; |
c906108c SS |
3566 | /* Root of the chain of bpstat's */ |
3567 | struct bpstats root_bs[1]; | |
3568 | /* Pointer to the last thing in the chain currently. */ | |
3569 | bpstat bs = root_bs; | |
20874c92 | 3570 | int ix; |
429374b8 | 3571 | int need_remove_insert; |
c906108c | 3572 | |
429374b8 JK |
3573 | /* ALL_BP_LOCATIONS iteration would break across |
3574 | update_global_location_list possibly executed by | |
3575 | bpstat_check_breakpoint_conditions's inferior call. */ | |
c5aa993b | 3576 | |
429374b8 JK |
3577 | ALL_BREAKPOINTS (b) |
3578 | { | |
3579 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
3580 | continue; | |
a5606eee | 3581 | |
429374b8 JK |
3582 | for (bl = b->loc; bl != NULL; bl = bl->next) |
3583 | { | |
3584 | /* For hardware watchpoints, we look only at the first location. | |
3585 | The watchpoint_check function will work on entire expression, | |
3586 | not the individual locations. For read watchopints, the | |
3587 | watchpoints_triggered function have checked all locations | |
3588 | already. */ | |
3589 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
3590 | break; | |
18a18393 | 3591 | |
429374b8 JK |
3592 | if (bl->shlib_disabled) |
3593 | continue; | |
c5aa993b | 3594 | |
429374b8 JK |
3595 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
3596 | continue; | |
c5aa993b | 3597 | |
429374b8 | 3598 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 3599 | |
429374b8 | 3600 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3601 | |
429374b8 JK |
3602 | /* Assume we stop. Should we find watchpoint that is not actually |
3603 | triggered, or if condition of breakpoint is false, we'll reset | |
3604 | 'stop' to 0. */ | |
3605 | bs->stop = 1; | |
3606 | bs->print = 1; | |
d983da9c | 3607 | |
429374b8 JK |
3608 | bpstat_check_watchpoint (bs); |
3609 | if (!bs->stop) | |
3610 | continue; | |
18a18393 | 3611 | |
429374b8 JK |
3612 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3613 | || b->type == bp_longjmp_master) | |
3614 | /* We do not stop for these. */ | |
3615 | bs->stop = 0; | |
3616 | else | |
3617 | bpstat_check_breakpoint_conditions (bs, ptid); | |
3618 | ||
3619 | if (bs->stop) | |
3620 | { | |
3621 | ++(b->hit_count); | |
c906108c | 3622 | |
429374b8 JK |
3623 | /* We will stop here */ |
3624 | if (b->disposition == disp_disable) | |
3625 | { | |
3626 | if (b->enable_state != bp_permanent) | |
3627 | b->enable_state = bp_disabled; | |
3628 | update_global_location_list (0); | |
3629 | } | |
3630 | if (b->silent) | |
3631 | bs->print = 0; | |
3632 | bs->commands = b->commands; | |
3633 | if (bs->commands | |
3634 | && (strcmp ("silent", bs->commands->line) == 0 | |
3635 | || (xdb_commands && strcmp ("Q", | |
3636 | bs->commands->line) == 0))) | |
3637 | { | |
3638 | bs->commands = bs->commands->next; | |
3639 | bs->print = 0; | |
3640 | } | |
3641 | bs->commands = copy_command_lines (bs->commands); | |
3642 | } | |
3643 | ||
3644 | /* Print nothing for this entry if we dont stop or dont print. */ | |
3645 | if (bs->stop == 0 || bs->print == 0) | |
3646 | bs->print_it = print_it_noop; | |
3647 | } | |
3648 | } | |
876fa593 | 3649 | |
20874c92 VP |
3650 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3651 | { | |
6c95b8df PA |
3652 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
3653 | aspace, bp_addr)) | |
20874c92 VP |
3654 | { |
3655 | bs = bpstat_alloc (loc, bs); | |
3656 | /* For hits of moribund locations, we should just proceed. */ | |
3657 | bs->stop = 0; | |
3658 | bs->print = 0; | |
3659 | bs->print_it = print_it_noop; | |
3660 | } | |
3661 | } | |
3662 | ||
c906108c SS |
3663 | bs->next = NULL; /* Terminate the chain */ |
3664 | bs = root_bs->next; /* Re-grab the head of the chain */ | |
3665 | ||
d983da9c DJ |
3666 | /* If we aren't stopping, the value of some hardware watchpoint may |
3667 | not have changed, but the intermediate memory locations we are | |
3668 | watching may have. Don't bother if we're stopping; this will get | |
3669 | done later. */ | |
3670 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3671 | if (bs->stop) | |
3672 | break; | |
3673 | ||
d832cb68 | 3674 | need_remove_insert = 0; |
d983da9c DJ |
3675 | if (bs == NULL) |
3676 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3677 | if (!bs->stop | |
20874c92 | 3678 | && bs->breakpoint_at->owner |
2d134ed3 | 3679 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 3680 | { |
2d134ed3 PA |
3681 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
3682 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
3683 | Prevent further code from trying to use it. */ | |
a5606eee | 3684 | bs->breakpoint_at = NULL; |
d832cb68 | 3685 | need_remove_insert = 1; |
d983da9c DJ |
3686 | } |
3687 | ||
d832cb68 | 3688 | if (need_remove_insert) |
2d134ed3 | 3689 | update_global_location_list (1); |
d832cb68 | 3690 | |
d983da9c | 3691 | return root_bs->next; |
c906108c SS |
3692 | } |
3693 | \f | |
3694 | /* Tell what to do about this bpstat. */ | |
3695 | struct bpstat_what | |
fba45db2 | 3696 | bpstat_what (bpstat bs) |
c906108c SS |
3697 | { |
3698 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3699 | enum class |
3700 | { | |
3701 | /* This bpstat element has no effect on the main_action. */ | |
3702 | no_effect = 0, | |
3703 | ||
3704 | /* There was a watchpoint, stop but don't print. */ | |
3705 | wp_silent, | |
c906108c | 3706 | |
c5aa993b JM |
3707 | /* There was a watchpoint, stop and print. */ |
3708 | wp_noisy, | |
c906108c | 3709 | |
c5aa993b JM |
3710 | /* There was a breakpoint but we're not stopping. */ |
3711 | bp_nostop, | |
c906108c | 3712 | |
c5aa993b JM |
3713 | /* There was a breakpoint, stop but don't print. */ |
3714 | bp_silent, | |
c906108c | 3715 | |
c5aa993b JM |
3716 | /* There was a breakpoint, stop and print. */ |
3717 | bp_noisy, | |
c906108c | 3718 | |
c5aa993b JM |
3719 | /* We hit the longjmp breakpoint. */ |
3720 | long_jump, | |
c906108c | 3721 | |
c5aa993b JM |
3722 | /* We hit the longjmp_resume breakpoint. */ |
3723 | long_resume, | |
c906108c | 3724 | |
c5aa993b JM |
3725 | /* We hit the step_resume breakpoint. */ |
3726 | step_resume, | |
c906108c | 3727 | |
c5aa993b JM |
3728 | /* We hit the shared library event breakpoint. */ |
3729 | shlib_event, | |
c906108c | 3730 | |
4efc6507 DE |
3731 | /* We hit the jit event breakpoint. */ |
3732 | jit_event, | |
3733 | ||
c5aa993b JM |
3734 | /* This is just used to count how many enums there are. */ |
3735 | class_last | |
c906108c SS |
3736 | }; |
3737 | ||
3738 | /* Here is the table which drives this routine. So that we can | |
3739 | format it pretty, we define some abbreviations for the | |
3740 | enum bpstat_what codes. */ | |
3741 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3742 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3743 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3744 | #define sgl BPSTAT_WHAT_SINGLE | |
3745 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3746 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3747 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3748 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 3749 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
3750 | |
3751 | /* "Can't happen." Might want to print an error message. | |
3752 | abort() is not out of the question, but chances are GDB is just | |
3753 | a bit confused, not unusable. */ | |
3754 | #define err BPSTAT_WHAT_STOP_NOISY | |
3755 | ||
3756 | /* Given an old action and a class, come up with a new action. */ | |
3757 | /* One interesting property of this table is that wp_silent is the same | |
3758 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3759 | after stopping, the check for whether to step over a breakpoint | |
3760 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3761 | reference to how we stopped. We retain separate wp_silent and |
3762 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3763 | |
3764 | Another possibly interesting property of this table is that | |
3765 | there's a partial ordering, priority-like, of the actions. Once | |
3766 | you've decided that some action is appropriate, you'll never go | |
3767 | back and decide something of a lower priority is better. The | |
3768 | ordering is: | |
3769 | ||
4efc6507 DE |
3770 | kc < jit clr sgl shl slr sn sr ss |
3771 | sgl < jit shl slr sn sr ss | |
3772 | slr < jit err shl sn sr ss | |
3773 | clr < jit err shl sn sr ss | |
3774 | ss < jit shl sn sr | |
3775 | sn < jit shl sr | |
3776 | jit < shl sr | |
d81191fc | 3777 | shl < sr |
4d5b2cd7 | 3778 | sr < |
c5aa993b | 3779 | |
43ff13b4 JM |
3780 | What I think this means is that we don't need a damned table |
3781 | here. If you just put the rows and columns in the right order, | |
3782 | it'd look awfully regular. We could simply walk the bpstat list | |
3783 | and choose the highest priority action we find, with a little | |
78b6a731 | 3784 | logic to handle the 'err' cases. */ |
c906108c SS |
3785 | |
3786 | /* step_resume entries: a step resume breakpoint overrides another | |
3787 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3788 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3789 | |
3790 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3791 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3792 | { | |
3793 | /* old action */ | |
4efc6507 DE |
3794 | /* kc ss sn sgl slr clr sr shl jit */ |
3795 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
3796 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3797 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3798 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
3799 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3800 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3801 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
3802 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
3803 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
3804 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
3805 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 3806 | }; |
c906108c SS |
3807 | |
3808 | #undef kc | |
3809 | #undef ss | |
3810 | #undef sn | |
3811 | #undef sgl | |
3812 | #undef slr | |
3813 | #undef clr | |
c906108c SS |
3814 | #undef err |
3815 | #undef sr | |
3816 | #undef ts | |
3817 | #undef shl | |
4efc6507 | 3818 | #undef jit |
c906108c SS |
3819 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3820 | struct bpstat_what retval; | |
3821 | ||
3822 | retval.call_dummy = 0; | |
3823 | for (; bs != NULL; bs = bs->next) | |
3824 | { | |
3825 | enum class bs_class = no_effect; | |
3826 | if (bs->breakpoint_at == NULL) | |
3827 | /* I suspect this can happen if it was a momentary breakpoint | |
3828 | which has since been deleted. */ | |
3829 | continue; | |
20874c92 VP |
3830 | if (bs->breakpoint_at->owner == NULL) |
3831 | bs_class = bp_nostop; | |
3832 | else | |
4f8d1dc6 | 3833 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3834 | { |
3835 | case bp_none: | |
3836 | continue; | |
3837 | ||
3838 | case bp_breakpoint: | |
3839 | case bp_hardware_breakpoint: | |
3840 | case bp_until: | |
3841 | case bp_finish: | |
3842 | if (bs->stop) | |
3843 | { | |
3844 | if (bs->print) | |
3845 | bs_class = bp_noisy; | |
3846 | else | |
3847 | bs_class = bp_silent; | |
3848 | } | |
3849 | else | |
3850 | bs_class = bp_nostop; | |
3851 | break; | |
3852 | case bp_watchpoint: | |
3853 | case bp_hardware_watchpoint: | |
3854 | case bp_read_watchpoint: | |
3855 | case bp_access_watchpoint: | |
3856 | if (bs->stop) | |
3857 | { | |
3858 | if (bs->print) | |
3859 | bs_class = wp_noisy; | |
3860 | else | |
3861 | bs_class = wp_silent; | |
3862 | } | |
3863 | else | |
53a5351d JM |
3864 | /* There was a watchpoint, but we're not stopping. |
3865 | This requires no further action. */ | |
c906108c SS |
3866 | bs_class = no_effect; |
3867 | break; | |
3868 | case bp_longjmp: | |
3869 | bs_class = long_jump; | |
3870 | break; | |
3871 | case bp_longjmp_resume: | |
3872 | bs_class = long_resume; | |
3873 | break; | |
3874 | case bp_step_resume: | |
3875 | if (bs->stop) | |
3876 | { | |
3877 | bs_class = step_resume; | |
3878 | } | |
3879 | else | |
3880 | /* It is for the wrong frame. */ | |
3881 | bs_class = bp_nostop; | |
3882 | break; | |
c906108c SS |
3883 | case bp_watchpoint_scope: |
3884 | bs_class = bp_nostop; | |
3885 | break; | |
c5aa993b JM |
3886 | case bp_shlib_event: |
3887 | bs_class = shlib_event; | |
3888 | break; | |
4efc6507 DE |
3889 | case bp_jit_event: |
3890 | bs_class = jit_event; | |
3891 | break; | |
c4093a6a | 3892 | case bp_thread_event: |
1900040c | 3893 | case bp_overlay_event: |
0fd8e87f | 3894 | case bp_longjmp_master: |
c4093a6a JM |
3895 | bs_class = bp_nostop; |
3896 | break; | |
ce78b96d | 3897 | case bp_catchpoint: |
c5aa993b JM |
3898 | if (bs->stop) |
3899 | { | |
3900 | if (bs->print) | |
3901 | bs_class = bp_noisy; | |
3902 | else | |
3903 | bs_class = bp_silent; | |
3904 | } | |
3905 | else | |
53a5351d JM |
3906 | /* There was a catchpoint, but we're not stopping. |
3907 | This requires no further action. */ | |
c5aa993b JM |
3908 | bs_class = no_effect; |
3909 | break; | |
c906108c | 3910 | case bp_call_dummy: |
53a5351d JM |
3911 | /* Make sure the action is stop (silent or noisy), |
3912 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
3913 | bs_class = bp_silent; |
3914 | retval.call_dummy = 1; | |
3915 | break; | |
1042e4c0 SS |
3916 | case bp_tracepoint: |
3917 | /* Tracepoint hits should not be reported back to GDB, and | |
3918 | if one got through somehow, it should have been filtered | |
3919 | out already. */ | |
3920 | internal_error (__FILE__, __LINE__, | |
3921 | _("bpstat_what: bp_tracepoint encountered")); | |
3922 | break; | |
c906108c | 3923 | } |
c5aa993b | 3924 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
3925 | } |
3926 | retval.main_action = current_action; | |
3927 | return retval; | |
3928 | } | |
3929 | ||
3930 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
3931 | without hardware support). This isn't related to a specific bpstat, | |
3932 | just to things like whether watchpoints are set. */ | |
3933 | ||
c5aa993b | 3934 | int |
fba45db2 | 3935 | bpstat_should_step (void) |
c906108c SS |
3936 | { |
3937 | struct breakpoint *b; | |
3938 | ALL_BREAKPOINTS (b) | |
717a8278 | 3939 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 3940 | return 1; |
c906108c SS |
3941 | return 0; |
3942 | } | |
3943 | ||
67822962 PA |
3944 | int |
3945 | bpstat_causes_stop (bpstat bs) | |
3946 | { | |
3947 | for (; bs != NULL; bs = bs->next) | |
3948 | if (bs->stop) | |
3949 | return 1; | |
3950 | ||
3951 | return 0; | |
3952 | } | |
3953 | ||
c906108c | 3954 | \f |
c5aa993b | 3955 | |
859825b8 JK |
3956 | /* Print the LOC location out of the list of B->LOC locations. */ |
3957 | ||
0d381245 VP |
3958 | static void print_breakpoint_location (struct breakpoint *b, |
3959 | struct bp_location *loc, | |
3960 | char *wrap_indent, | |
3961 | struct ui_stream *stb) | |
3962 | { | |
6c95b8df PA |
3963 | struct cleanup *old_chain = save_current_program_space (); |
3964 | ||
859825b8 JK |
3965 | if (loc != NULL && loc->shlib_disabled) |
3966 | loc = NULL; | |
3967 | ||
6c95b8df PA |
3968 | if (loc != NULL) |
3969 | set_current_program_space (loc->pspace); | |
3970 | ||
859825b8 | 3971 | if (b->source_file && loc) |
0d381245 VP |
3972 | { |
3973 | struct symbol *sym | |
3974 | = find_pc_sect_function (loc->address, loc->section); | |
3975 | if (sym) | |
3976 | { | |
3977 | ui_out_text (uiout, "in "); | |
3978 | ui_out_field_string (uiout, "func", | |
3979 | SYMBOL_PRINT_NAME (sym)); | |
3980 | ui_out_wrap_hint (uiout, wrap_indent); | |
3981 | ui_out_text (uiout, " at "); | |
3982 | } | |
3983 | ui_out_field_string (uiout, "file", b->source_file); | |
3984 | ui_out_text (uiout, ":"); | |
3985 | ||
3986 | if (ui_out_is_mi_like_p (uiout)) | |
3987 | { | |
3988 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
3989 | char *fullname = symtab_to_fullname (sal.symtab); | |
3990 | ||
3991 | if (fullname) | |
3992 | ui_out_field_string (uiout, "fullname", fullname); | |
3993 | } | |
3994 | ||
3995 | ui_out_field_int (uiout, "line", b->line_number); | |
3996 | } | |
859825b8 | 3997 | else if (loc) |
0d381245 | 3998 | { |
22e722e1 DJ |
3999 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4000 | demangle, ""); | |
0d381245 VP |
4001 | ui_out_field_stream (uiout, "at", stb); |
4002 | } | |
859825b8 JK |
4003 | else |
4004 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4005 | |
4006 | do_cleanups (old_chain); | |
0d381245 VP |
4007 | } |
4008 | ||
c4093a6a | 4009 | /* Print B to gdb_stdout. */ |
c906108c | 4010 | static void |
0d381245 VP |
4011 | print_one_breakpoint_location (struct breakpoint *b, |
4012 | struct bp_location *loc, | |
4013 | int loc_number, | |
a6d9a66e | 4014 | struct bp_location **last_loc, |
6c95b8df PA |
4015 | int print_address_bits, |
4016 | int allflag) | |
c906108c | 4017 | { |
52f0bd74 AC |
4018 | struct command_line *l; |
4019 | struct symbol *sym; | |
c4093a6a JM |
4020 | struct ep_type_description |
4021 | { | |
4022 | enum bptype type; | |
4023 | char *description; | |
4024 | }; | |
4025 | static struct ep_type_description bptypes[] = | |
c906108c | 4026 | { |
c5aa993b JM |
4027 | {bp_none, "?deleted?"}, |
4028 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4029 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4030 | {bp_until, "until"}, |
4031 | {bp_finish, "finish"}, | |
4032 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4033 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4034 | {bp_read_watchpoint, "read watchpoint"}, |
4035 | {bp_access_watchpoint, "acc watchpoint"}, | |
4036 | {bp_longjmp, "longjmp"}, | |
4037 | {bp_longjmp_resume, "longjmp resume"}, | |
4038 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4039 | {bp_watchpoint_scope, "watchpoint scope"}, |
4040 | {bp_call_dummy, "call dummy"}, | |
4041 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 4042 | {bp_thread_event, "thread events"}, |
1900040c | 4043 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4044 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 4045 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4046 | {bp_tracepoint, "tracepoint"}, |
4efc6507 | 4047 | {bp_jit_event, "jit events"}, |
c5aa993b | 4048 | }; |
c4093a6a | 4049 | |
c2c6d25f | 4050 | static char bpenables[] = "nynny"; |
c906108c | 4051 | char wrap_indent[80]; |
8b93c638 JM |
4052 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4053 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4054 | struct cleanup *bkpt_chain; |
c906108c | 4055 | |
0d381245 VP |
4056 | int header_of_multiple = 0; |
4057 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4058 | struct value_print_options opts; |
4059 | ||
4060 | get_user_print_options (&opts); | |
0d381245 VP |
4061 | |
4062 | gdb_assert (!loc || loc_number != 0); | |
4063 | /* See comment in print_one_breakpoint concerning | |
4064 | treatment of breakpoints with single disabled | |
4065 | location. */ | |
4066 | if (loc == NULL | |
4067 | && (b->loc != NULL | |
4068 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4069 | header_of_multiple = 1; | |
4070 | if (loc == NULL) | |
4071 | loc = b->loc; | |
4072 | ||
c4093a6a | 4073 | annotate_record (); |
3b31d625 | 4074 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4075 | |
4076 | /* 1 */ | |
4077 | annotate_field (0); | |
0d381245 VP |
4078 | if (part_of_multiple) |
4079 | { | |
4080 | char *formatted; | |
0c6773c1 | 4081 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4082 | ui_out_field_string (uiout, "number", formatted); |
4083 | xfree (formatted); | |
4084 | } | |
4085 | else | |
4086 | { | |
4087 | ui_out_field_int (uiout, "number", b->number); | |
4088 | } | |
c4093a6a JM |
4089 | |
4090 | /* 2 */ | |
4091 | annotate_field (1); | |
0d381245 VP |
4092 | if (part_of_multiple) |
4093 | ui_out_field_skip (uiout, "type"); | |
4094 | else | |
4095 | { | |
4096 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4097 | || ((int) b->type != bptypes[(int) b->type].type)) | |
4098 | internal_error (__FILE__, __LINE__, | |
4099 | _("bptypes table does not describe type #%d."), | |
4100 | (int) b->type); | |
4101 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
4102 | } | |
c4093a6a JM |
4103 | |
4104 | /* 3 */ | |
4105 | annotate_field (2); | |
0d381245 VP |
4106 | if (part_of_multiple) |
4107 | ui_out_field_skip (uiout, "disp"); | |
4108 | else | |
2cec12e5 | 4109 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4110 | |
c4093a6a JM |
4111 | |
4112 | /* 4 */ | |
4113 | annotate_field (3); | |
0d381245 | 4114 | if (part_of_multiple) |
54e52265 | 4115 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4116 | else |
54e52265 VP |
4117 | ui_out_field_fmt (uiout, "enabled", "%c", |
4118 | bpenables[(int) b->enable_state]); | |
4119 | ui_out_spaces (uiout, 2); | |
0d381245 | 4120 | |
c4093a6a JM |
4121 | |
4122 | /* 5 and 6 */ | |
4123 | strcpy (wrap_indent, " "); | |
79a45b7d | 4124 | if (opts.addressprint) |
75ac9d7b | 4125 | { |
a6d9a66e | 4126 | if (print_address_bits <= 32) |
75ac9d7b MS |
4127 | strcat (wrap_indent, " "); |
4128 | else | |
4129 | strcat (wrap_indent, " "); | |
4130 | } | |
c906108c | 4131 | |
3086aeae | 4132 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4133 | { |
4134 | /* Although the print_one can possibly print | |
4135 | all locations, calling it here is not likely | |
4136 | to get any nice result. So, make sure there's | |
4137 | just one location. */ | |
4138 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4139 | b->ops->print_one (b, last_loc); |
0d381245 | 4140 | } |
3086aeae DJ |
4141 | else |
4142 | switch (b->type) | |
4143 | { | |
4144 | case bp_none: | |
4145 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4146 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4147 | break; |
c906108c | 4148 | |
3086aeae DJ |
4149 | case bp_watchpoint: |
4150 | case bp_hardware_watchpoint: | |
4151 | case bp_read_watchpoint: | |
4152 | case bp_access_watchpoint: | |
4153 | /* Field 4, the address, is omitted (which makes the columns | |
4154 | not line up too nicely with the headers, but the effect | |
4155 | is relatively readable). */ | |
79a45b7d | 4156 | if (opts.addressprint) |
3086aeae DJ |
4157 | ui_out_field_skip (uiout, "addr"); |
4158 | annotate_field (5); | |
fa8a61dc | 4159 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4160 | break; |
4161 | ||
3086aeae DJ |
4162 | case bp_breakpoint: |
4163 | case bp_hardware_breakpoint: | |
4164 | case bp_until: | |
4165 | case bp_finish: | |
4166 | case bp_longjmp: | |
4167 | case bp_longjmp_resume: | |
4168 | case bp_step_resume: | |
3086aeae DJ |
4169 | case bp_watchpoint_scope: |
4170 | case bp_call_dummy: | |
4171 | case bp_shlib_event: | |
4172 | case bp_thread_event: | |
4173 | case bp_overlay_event: | |
0fd8e87f | 4174 | case bp_longjmp_master: |
1042e4c0 | 4175 | case bp_tracepoint: |
4efc6507 | 4176 | case bp_jit_event: |
79a45b7d | 4177 | if (opts.addressprint) |
3086aeae DJ |
4178 | { |
4179 | annotate_field (4); | |
54e52265 | 4180 | if (header_of_multiple) |
0d381245 | 4181 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4182 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4183 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4184 | else |
5af949e3 UW |
4185 | ui_out_field_core_addr (uiout, "addr", |
4186 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4187 | } |
4188 | annotate_field (5); | |
0d381245 VP |
4189 | if (!header_of_multiple) |
4190 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4191 | if (b->loc) | |
a6d9a66e | 4192 | *last_loc = b->loc; |
3086aeae DJ |
4193 | break; |
4194 | } | |
c906108c | 4195 | |
6c95b8df PA |
4196 | |
4197 | /* For backward compatibility, don't display inferiors unless there | |
4198 | are several. */ | |
4199 | if (loc != NULL | |
4200 | && !header_of_multiple | |
4201 | && (allflag | |
4202 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4203 | && (number_of_program_spaces () > 1 | |
4204 | || number_of_inferiors () > 1) | |
4205 | && loc->owner->type != bp_catchpoint))) | |
4206 | { | |
4207 | struct inferior *inf; | |
4208 | int first = 1; | |
4209 | ||
4210 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4211 | { | |
4212 | if (inf->pspace == loc->pspace) | |
4213 | { | |
4214 | if (first) | |
4215 | { | |
4216 | first = 0; | |
4217 | ui_out_text (uiout, " inf "); | |
4218 | } | |
4219 | else | |
4220 | ui_out_text (uiout, ", "); | |
4221 | ui_out_text (uiout, plongest (inf->num)); | |
4222 | } | |
4223 | } | |
4224 | } | |
4225 | ||
4a306c9a | 4226 | if (!part_of_multiple) |
c4093a6a | 4227 | { |
4a306c9a JB |
4228 | if (b->thread != -1) |
4229 | { | |
4230 | /* FIXME: This seems to be redundant and lost here; see the | |
4231 | "stop only in" line a little further down. */ | |
4232 | ui_out_text (uiout, " thread "); | |
4233 | ui_out_field_int (uiout, "thread", b->thread); | |
4234 | } | |
4235 | else if (b->task != 0) | |
4236 | { | |
4237 | ui_out_text (uiout, " task "); | |
4238 | ui_out_field_int (uiout, "task", b->task); | |
4239 | } | |
c4093a6a JM |
4240 | } |
4241 | ||
8b93c638 | 4242 | ui_out_text (uiout, "\n"); |
c4093a6a | 4243 | |
0d381245 | 4244 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4245 | { |
4246 | annotate_field (6); | |
8b93c638 | 4247 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4248 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4249 | the frame ID. */ | |
5af949e3 UW |
4250 | ui_out_field_core_addr (uiout, "frame", |
4251 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4252 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4253 | } |
4254 | ||
0d381245 | 4255 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4256 | { |
f7f9143b JB |
4257 | /* We do not print the condition for Ada exception catchpoints |
4258 | because the condition is an internal implementation detail | |
4259 | that we do not want to expose to the user. */ | |
c4093a6a | 4260 | annotate_field (7); |
1042e4c0 SS |
4261 | if (b->type == bp_tracepoint) |
4262 | ui_out_text (uiout, "\ttrace only if "); | |
4263 | else | |
4264 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4265 | ui_out_field_string (uiout, "cond", b->cond_string); |
4266 | ui_out_text (uiout, "\n"); | |
4267 | } | |
4268 | ||
0d381245 | 4269 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4270 | { |
4271 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4272 | ui_out_text (uiout, "\tstop only in thread "); |
4273 | ui_out_field_int (uiout, "thread", b->thread); | |
4274 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4275 | } |
4276 | ||
63c715c6 | 4277 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4278 | { |
4279 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4280 | if (ep_is_catchpoint (b)) |
4281 | ui_out_text (uiout, "\tcatchpoint"); | |
4282 | else | |
4283 | ui_out_text (uiout, "\tbreakpoint"); | |
4284 | ui_out_text (uiout, " already hit "); | |
4285 | ui_out_field_int (uiout, "times", b->hit_count); | |
4286 | if (b->hit_count == 1) | |
4287 | ui_out_text (uiout, " time\n"); | |
4288 | else | |
4289 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4290 | } |
4291 | ||
fb40c209 AC |
4292 | /* Output the count also if it is zero, but only if this is |
4293 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4294 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4295 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4296 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4297 | |
0d381245 | 4298 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4299 | { |
4300 | annotate_field (8); | |
8b93c638 JM |
4301 | ui_out_text (uiout, "\tignore next "); |
4302 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4303 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4304 | } |
059fb39f PM |
4305 | |
4306 | l = b->commands; | |
4307 | if (!part_of_multiple && l) | |
c4093a6a | 4308 | { |
3b31d625 EZ |
4309 | struct cleanup *script_chain; |
4310 | ||
c4093a6a | 4311 | annotate_field (9); |
3b31d625 | 4312 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4313 | print_command_lines (uiout, l, 4); |
3b31d625 | 4314 | do_cleanups (script_chain); |
c4093a6a | 4315 | } |
d24317b4 | 4316 | |
1042e4c0 SS |
4317 | if (!part_of_multiple && b->pass_count) |
4318 | { | |
4319 | annotate_field (10); | |
4320 | ui_out_text (uiout, "\tpass count "); | |
4321 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4322 | ui_out_text (uiout, " \n"); | |
4323 | } | |
4324 | ||
4325 | if (!part_of_multiple && b->step_count) | |
4326 | { | |
4327 | annotate_field (11); | |
4328 | ui_out_text (uiout, "\tstep count "); | |
4329 | ui_out_field_int (uiout, "step", b->step_count); | |
4330 | ui_out_text (uiout, " \n"); | |
4331 | } | |
4332 | ||
4333 | if (!part_of_multiple && b->actions) | |
4334 | { | |
4335 | struct action_line *action; | |
4336 | annotate_field (12); | |
4337 | for (action = b->actions; action; action = action->next) | |
4338 | { | |
4339 | ui_out_text (uiout, " A\t"); | |
4340 | ui_out_text (uiout, action->action); | |
4341 | ui_out_text (uiout, "\n"); | |
4342 | } | |
4343 | } | |
4344 | ||
d24317b4 VP |
4345 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4346 | { | |
4347 | if (b->addr_string) | |
4348 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4349 | else if (b->exp_string) | |
4350 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4351 | } | |
4352 | ||
3b31d625 | 4353 | do_cleanups (bkpt_chain); |
8b93c638 | 4354 | do_cleanups (old_chain); |
c4093a6a | 4355 | } |
c5aa993b | 4356 | |
0d381245 VP |
4357 | static void |
4358 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4359 | struct bp_location **last_loc, int print_address_bits, |
4360 | int allflag) | |
0d381245 | 4361 | { |
6c95b8df PA |
4362 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4363 | print_address_bits, allflag); | |
0d381245 VP |
4364 | |
4365 | /* If this breakpoint has custom print function, | |
4366 | it's already printed. Otherwise, print individual | |
4367 | locations, if any. */ | |
4368 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4369 | { | |
4370 | /* If breakpoint has a single location that is | |
4371 | disabled, we print it as if it had | |
4372 | several locations, since otherwise it's hard to | |
4373 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4374 | situation. |
4375 | Note that while hardware watchpoints have | |
4376 | several locations internally, that's no a property | |
4377 | exposed to user. */ | |
0d381245 | 4378 | if (b->loc |
a5606eee | 4379 | && !is_hardware_watchpoint (b) |
0d381245 | 4380 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4381 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4382 | { |
4383 | struct bp_location *loc; | |
4384 | int n = 1; | |
4385 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4386 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4387 | print_address_bits, allflag); |
0d381245 VP |
4388 | } |
4389 | } | |
4390 | } | |
4391 | ||
a6d9a66e UW |
4392 | static int |
4393 | breakpoint_address_bits (struct breakpoint *b) | |
4394 | { | |
4395 | int print_address_bits = 0; | |
4396 | struct bp_location *loc; | |
4397 | ||
4398 | for (loc = b->loc; loc; loc = loc->next) | |
4399 | { | |
c561c276 | 4400 | int addr_bit = gdbarch_addr_bit (loc->gdbarch); |
a6d9a66e UW |
4401 | if (addr_bit > print_address_bits) |
4402 | print_address_bits = addr_bit; | |
4403 | } | |
4404 | ||
4405 | return print_address_bits; | |
4406 | } | |
0d381245 | 4407 | |
c4093a6a JM |
4408 | struct captured_breakpoint_query_args |
4409 | { | |
4410 | int bnum; | |
4411 | }; | |
c5aa993b | 4412 | |
c4093a6a | 4413 | static int |
2b65245e | 4414 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4415 | { |
4416 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4417 | struct breakpoint *b; |
a6d9a66e | 4418 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4419 | ALL_BREAKPOINTS (b) |
4420 | { | |
4421 | if (args->bnum == b->number) | |
c5aa993b | 4422 | { |
a6d9a66e | 4423 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4424 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4425 | return GDB_RC_OK; |
c5aa993b | 4426 | } |
c4093a6a JM |
4427 | } |
4428 | return GDB_RC_NONE; | |
4429 | } | |
c5aa993b | 4430 | |
c4093a6a | 4431 | enum gdb_rc |
ce43223b | 4432 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4433 | { |
4434 | struct captured_breakpoint_query_args args; | |
4435 | args.bnum = bnum; | |
4436 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4437 | an error. */ | |
b0b13bb4 DJ |
4438 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4439 | error_message, RETURN_MASK_ALL) < 0) | |
4440 | return GDB_RC_FAIL; | |
4441 | else | |
4442 | return GDB_RC_OK; | |
c4093a6a | 4443 | } |
c5aa993b | 4444 | |
7f3b0473 AC |
4445 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4446 | catchpoints, et.al.). */ | |
4447 | ||
4448 | static int | |
4449 | user_settable_breakpoint (const struct breakpoint *b) | |
4450 | { | |
4451 | return (b->type == bp_breakpoint | |
ce78b96d | 4452 | || b->type == bp_catchpoint |
7f3b0473 | 4453 | || b->type == bp_hardware_breakpoint |
1042e4c0 | 4454 | || b->type == bp_tracepoint |
7f3b0473 AC |
4455 | || b->type == bp_watchpoint |
4456 | || b->type == bp_read_watchpoint | |
4457 | || b->type == bp_access_watchpoint | |
4458 | || b->type == bp_hardware_watchpoint); | |
4459 | } | |
4460 | ||
4461 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4462 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4463 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4464 | |
c4093a6a | 4465 | static void |
fba45db2 | 4466 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4467 | { |
52f0bd74 | 4468 | struct breakpoint *b; |
a6d9a66e | 4469 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4470 | int nr_printable_breakpoints; |
3b31d625 | 4471 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4472 | struct value_print_options opts; |
a6d9a66e | 4473 | int print_address_bits = 0; |
c4093a6a | 4474 | |
79a45b7d TT |
4475 | get_user_print_options (&opts); |
4476 | ||
a6d9a66e UW |
4477 | /* Compute the number of rows in the table, as well as the |
4478 | size required for address fields. */ | |
7f3b0473 AC |
4479 | nr_printable_breakpoints = 0; |
4480 | ALL_BREAKPOINTS (b) | |
4481 | if (bnum == -1 | |
4482 | || bnum == b->number) | |
4483 | { | |
4484 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4485 | { |
4486 | int addr_bit = breakpoint_address_bits (b); | |
4487 | if (addr_bit > print_address_bits) | |
4488 | print_address_bits = addr_bit; | |
4489 | ||
4490 | nr_printable_breakpoints++; | |
4491 | } | |
7f3b0473 AC |
4492 | } |
4493 | ||
79a45b7d | 4494 | if (opts.addressprint) |
3b31d625 EZ |
4495 | bkpttbl_chain |
4496 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4497 | "BreakpointTable"); | |
8b93c638 | 4498 | else |
3b31d625 EZ |
4499 | bkpttbl_chain |
4500 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4501 | "BreakpointTable"); | |
8b93c638 | 4502 | |
7f3b0473 | 4503 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4504 | annotate_breakpoints_headers (); |
4505 | if (nr_printable_breakpoints > 0) | |
4506 | annotate_field (0); | |
0d381245 | 4507 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4508 | if (nr_printable_breakpoints > 0) |
4509 | annotate_field (1); | |
4510 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4511 | if (nr_printable_breakpoints > 0) | |
4512 | annotate_field (2); | |
4513 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4514 | if (nr_printable_breakpoints > 0) | |
4515 | annotate_field (3); | |
54e52265 | 4516 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4517 | if (opts.addressprint) |
7f3b0473 | 4518 | { |
d7faa9e7 AC |
4519 | if (nr_printable_breakpoints > 0) |
4520 | annotate_field (4); | |
a6d9a66e | 4521 | if (print_address_bits <= 32) |
b25959ec | 4522 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4523 | else |
b25959ec | 4524 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4525 | } |
d7faa9e7 AC |
4526 | if (nr_printable_breakpoints > 0) |
4527 | annotate_field (5); | |
4528 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4529 | ui_out_table_body (uiout); | |
4530 | if (nr_printable_breakpoints > 0) | |
4531 | annotate_breakpoints_table (); | |
7f3b0473 | 4532 | |
c4093a6a JM |
4533 | ALL_BREAKPOINTS (b) |
4534 | if (bnum == -1 | |
4535 | || bnum == b->number) | |
4536 | { | |
4537 | /* We only print out user settable breakpoints unless the | |
4538 | allflag is set. */ | |
7f3b0473 | 4539 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 4540 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a JM |
4541 | } |
4542 | ||
3b31d625 | 4543 | do_cleanups (bkpttbl_chain); |
698384cd | 4544 | |
7f3b0473 | 4545 | if (nr_printable_breakpoints == 0) |
c906108c | 4546 | { |
8b93c638 JM |
4547 | if (bnum == -1) |
4548 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4549 | else | |
4550 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4551 | bnum); | |
c906108c SS |
4552 | } |
4553 | else | |
c4093a6a | 4554 | { |
a6d9a66e UW |
4555 | if (last_loc && !server_command) |
4556 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4557 | } |
c906108c | 4558 | |
c4093a6a JM |
4559 | /* FIXME? Should this be moved up so that it is only called when |
4560 | there have been breakpoints? */ | |
c906108c SS |
4561 | annotate_breakpoints_table_end (); |
4562 | } | |
4563 | ||
c906108c | 4564 | static void |
fba45db2 | 4565 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4566 | { |
4567 | int bnum = -1; | |
4568 | ||
4569 | if (bnum_exp) | |
bb518678 | 4570 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4571 | |
4572 | breakpoint_1 (bnum, 0); | |
4573 | } | |
4574 | ||
7a292a7a | 4575 | static void |
fba45db2 | 4576 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4577 | { |
4578 | int bnum = -1; | |
4579 | ||
4580 | if (bnum_exp) | |
bb518678 | 4581 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4582 | |
4583 | breakpoint_1 (bnum, 1); | |
4584 | } | |
4585 | ||
0d381245 | 4586 | static int |
714835d5 | 4587 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 4588 | struct program_space *pspace, |
714835d5 | 4589 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
4590 | { |
4591 | struct bp_location *bl = b->loc; | |
4592 | for (; bl; bl = bl->next) | |
4593 | { | |
6c95b8df PA |
4594 | if (bl->pspace == pspace |
4595 | && bl->address == pc | |
0d381245 VP |
4596 | && (!overlay_debugging || bl->section == section)) |
4597 | return 1; | |
4598 | } | |
4599 | return 0; | |
4600 | } | |
4601 | ||
6c95b8df PA |
4602 | /* Print a message describing any breakpoints set at PC. This |
4603 | concerns with logical breakpoints, so we match program spaces, not | |
4604 | address spaces. */ | |
c906108c SS |
4605 | |
4606 | static void | |
6c95b8df PA |
4607 | describe_other_breakpoints (struct gdbarch *gdbarch, |
4608 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 4609 | struct obj_section *section, int thread) |
c906108c | 4610 | { |
52f0bd74 AC |
4611 | int others = 0; |
4612 | struct breakpoint *b; | |
c906108c SS |
4613 | |
4614 | ALL_BREAKPOINTS (b) | |
6c95b8df | 4615 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
4616 | if (others > 0) |
4617 | { | |
a3f17187 AC |
4618 | if (others == 1) |
4619 | printf_filtered (_("Note: breakpoint ")); | |
4620 | else /* if (others == ???) */ | |
4621 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4622 | ALL_BREAKPOINTS (b) |
6c95b8df | 4623 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
4624 | { |
4625 | others--; | |
4626 | printf_filtered ("%d", b->number); | |
4627 | if (b->thread == -1 && thread != -1) | |
4628 | printf_filtered (" (all threads)"); | |
4629 | else if (b->thread != -1) | |
4630 | printf_filtered (" (thread %d)", b->thread); | |
4631 | printf_filtered ("%s%s ", | |
059fb39f | 4632 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4633 | || b->enable_state == bp_call_disabled |
4634 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4635 | ? " (disabled)" |
4636 | : b->enable_state == bp_permanent | |
4637 | ? " (permanent)" | |
4638 | : ""), | |
4639 | (others > 1) ? "," | |
4640 | : ((others == 1) ? " and" : "")); | |
4641 | } | |
a3f17187 | 4642 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4643 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4644 | printf_filtered (".\n"); |
4645 | } | |
4646 | } | |
4647 | \f | |
4648 | /* Set the default place to put a breakpoint | |
4649 | for the `break' command with no arguments. */ | |
4650 | ||
4651 | void | |
6c95b8df PA |
4652 | set_default_breakpoint (int valid, struct program_space *pspace, |
4653 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 4654 | int line) |
c906108c SS |
4655 | { |
4656 | default_breakpoint_valid = valid; | |
6c95b8df | 4657 | default_breakpoint_pspace = pspace; |
c906108c SS |
4658 | default_breakpoint_address = addr; |
4659 | default_breakpoint_symtab = symtab; | |
4660 | default_breakpoint_line = line; | |
4661 | } | |
4662 | ||
e4f237da KB |
4663 | /* Return true iff it is meaningful to use the address member of |
4664 | BPT. For some breakpoint types, the address member is irrelevant | |
4665 | and it makes no sense to attempt to compare it to other addresses | |
4666 | (or use it for any other purpose either). | |
4667 | ||
4668 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
4669 | have a zero valued address and we don't want to mark breakpoints of any of |
4670 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
4671 | |
4672 | bp_watchpoint | |
2d134ed3 PA |
4673 | bp_catchpoint |
4674 | ||
4675 | */ | |
e4f237da KB |
4676 | |
4677 | static int | |
4678 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4679 | { | |
4680 | enum bptype type = bpt->type; | |
4681 | ||
2d134ed3 PA |
4682 | return (type != bp_watchpoint && type != bp_catchpoint); |
4683 | } | |
4684 | ||
4685 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
4686 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
4687 | ||
4688 | static int | |
4689 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
4690 | { | |
4691 | return (loc1->owner->type == loc2->owner->type | |
4692 | && loc1->pspace->aspace == loc2->pspace->aspace | |
4693 | && loc1->address == loc2->address | |
4694 | && loc1->length == loc2->length); | |
e4f237da KB |
4695 | } |
4696 | ||
6c95b8df PA |
4697 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
4698 | same breakpoint location. In most targets, this can only be true | |
4699 | if ASPACE1 matches ASPACE2. On targets that have global | |
4700 | breakpoints, the address space doesn't really matter. */ | |
4701 | ||
4702 | static int | |
4703 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
4704 | struct address_space *aspace2, CORE_ADDR addr2) | |
4705 | { | |
4706 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
4707 | || aspace1 == aspace2) | |
4708 | && addr1 == addr2); | |
4709 | } | |
4710 | ||
2d134ed3 PA |
4711 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
4712 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
4713 | represent the same location. */ | |
4714 | ||
4715 | static int | |
4716 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
4717 | { | |
4718 | int hw_point1 = is_hardware_watchpoint (loc1->owner); | |
4719 | int hw_point2 = is_hardware_watchpoint (loc2->owner); | |
4720 | ||
4721 | if (hw_point1 != hw_point2) | |
4722 | return 0; | |
4723 | else if (hw_point1) | |
4724 | return watchpoint_locations_match (loc1, loc2); | |
4725 | else | |
4726 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
4727 | loc2->pspace->aspace, loc2->address); | |
4728 | } | |
4729 | ||
76897487 KB |
4730 | static void |
4731 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4732 | int bnum, int have_bnum) | |
4733 | { | |
4734 | char astr1[40]; | |
4735 | char astr2[40]; | |
4736 | ||
bb599908 PH |
4737 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4738 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4739 | if (have_bnum) |
8a3fe4f8 | 4740 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4741 | bnum, astr1, astr2); |
4742 | else | |
8a3fe4f8 | 4743 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4744 | } |
4745 | ||
4746 | /* Adjust a breakpoint's address to account for architectural constraints | |
4747 | on breakpoint placement. Return the adjusted address. Note: Very | |
4748 | few targets require this kind of adjustment. For most targets, | |
4749 | this function is simply the identity function. */ | |
4750 | ||
4751 | static CORE_ADDR | |
a6d9a66e UW |
4752 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4753 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4754 | { |
a6d9a66e | 4755 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4756 | { |
4757 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4758 | return bpaddr; | |
4759 | } | |
88f7da05 KB |
4760 | else if (bptype == bp_watchpoint |
4761 | || bptype == bp_hardware_watchpoint | |
4762 | || bptype == bp_read_watchpoint | |
4763 | || bptype == bp_access_watchpoint | |
fe798b75 | 4764 | || bptype == bp_catchpoint) |
88f7da05 KB |
4765 | { |
4766 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4767 | have their addresses modified. */ | |
4768 | return bpaddr; | |
4769 | } | |
76897487 KB |
4770 | else |
4771 | { | |
4772 | CORE_ADDR adjusted_bpaddr; | |
4773 | ||
4774 | /* Some targets have architectural constraints on the placement | |
4775 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4776 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4777 | |
4778 | /* An adjusted breakpoint address can significantly alter | |
4779 | a user's expectations. Print a warning if an adjustment | |
4780 | is required. */ | |
4781 | if (adjusted_bpaddr != bpaddr) | |
4782 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4783 | ||
4784 | return adjusted_bpaddr; | |
4785 | } | |
4786 | } | |
4787 | ||
7cc221ef DJ |
4788 | /* Allocate a struct bp_location. */ |
4789 | ||
26bb91f3 | 4790 | static struct bp_location * |
39d61571 | 4791 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4792 | { |
4793 | struct bp_location *loc, *loc_p; | |
4794 | ||
4795 | loc = xmalloc (sizeof (struct bp_location)); | |
4796 | memset (loc, 0, sizeof (*loc)); | |
4797 | ||
e049a4b5 | 4798 | loc->owner = bpt; |
511a6cd4 | 4799 | loc->cond = NULL; |
0d381245 VP |
4800 | loc->shlib_disabled = 0; |
4801 | loc->enabled = 1; | |
e049a4b5 | 4802 | |
39d61571 | 4803 | switch (bpt->type) |
e049a4b5 DJ |
4804 | { |
4805 | case bp_breakpoint: | |
1042e4c0 | 4806 | case bp_tracepoint: |
e049a4b5 DJ |
4807 | case bp_until: |
4808 | case bp_finish: | |
4809 | case bp_longjmp: | |
4810 | case bp_longjmp_resume: | |
4811 | case bp_step_resume: | |
e049a4b5 DJ |
4812 | case bp_watchpoint_scope: |
4813 | case bp_call_dummy: | |
4814 | case bp_shlib_event: | |
4815 | case bp_thread_event: | |
4816 | case bp_overlay_event: | |
4efc6507 | 4817 | case bp_jit_event: |
0fd8e87f | 4818 | case bp_longjmp_master: |
e049a4b5 DJ |
4819 | loc->loc_type = bp_loc_software_breakpoint; |
4820 | break; | |
4821 | case bp_hardware_breakpoint: | |
4822 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4823 | break; | |
4824 | case bp_hardware_watchpoint: | |
4825 | case bp_read_watchpoint: | |
4826 | case bp_access_watchpoint: | |
4827 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4828 | break; | |
4829 | case bp_watchpoint: | |
ce78b96d | 4830 | case bp_catchpoint: |
e049a4b5 DJ |
4831 | loc->loc_type = bp_loc_other; |
4832 | break; | |
4833 | default: | |
e2e0b3e5 | 4834 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4835 | } |
4836 | ||
7cc221ef DJ |
4837 | return loc; |
4838 | } | |
4839 | ||
fe3f5fa8 VP |
4840 | static void free_bp_location (struct bp_location *loc) |
4841 | { | |
4842 | if (loc->cond) | |
4843 | xfree (loc->cond); | |
74960c60 VP |
4844 | |
4845 | if (loc->function_name) | |
4846 | xfree (loc->function_name); | |
4847 | ||
fe3f5fa8 VP |
4848 | xfree (loc); |
4849 | } | |
4850 | ||
0d381245 VP |
4851 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4852 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4853 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 4854 | |
c40e75cd | 4855 | static struct breakpoint * |
a6d9a66e UW |
4856 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
4857 | enum bptype bptype) | |
c906108c | 4858 | { |
52f0bd74 | 4859 | struct breakpoint *b, *b1; |
c906108c SS |
4860 | |
4861 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
4862 | memset (b, 0, sizeof (*b)); | |
2219d63c | 4863 | |
4d28f7a8 | 4864 | b->type = bptype; |
a6d9a66e | 4865 | b->gdbarch = gdbarch; |
c906108c SS |
4866 | b->language = current_language->la_language; |
4867 | b->input_radix = input_radix; | |
4868 | b->thread = -1; | |
b5de0fa7 | 4869 | b->enable_state = bp_enabled; |
c906108c SS |
4870 | b->next = 0; |
4871 | b->silent = 0; | |
4872 | b->ignore_count = 0; | |
4873 | b->commands = NULL; | |
818dd999 | 4874 | b->frame_id = null_frame_id; |
3a3e9ee3 | 4875 | b->forked_inferior_pid = null_ptid; |
c906108c | 4876 | b->exec_pathname = NULL; |
a96d9b2e | 4877 | b->syscalls_to_be_caught = NULL; |
3086aeae | 4878 | b->ops = NULL; |
0d381245 | 4879 | b->condition_not_parsed = 0; |
c906108c SS |
4880 | |
4881 | /* Add this breakpoint to the end of the chain | |
4882 | so that a list of breakpoints will come out in order | |
4883 | of increasing numbers. */ | |
4884 | ||
4885 | b1 = breakpoint_chain; | |
4886 | if (b1 == 0) | |
4887 | breakpoint_chain = b; | |
4888 | else | |
4889 | { | |
4890 | while (b1->next) | |
4891 | b1 = b1->next; | |
4892 | b1->next = b; | |
4893 | } | |
0d381245 VP |
4894 | return b; |
4895 | } | |
4896 | ||
4897 | /* Initialize loc->function_name. */ | |
4898 | static void | |
4899 | set_breakpoint_location_function (struct bp_location *loc) | |
4900 | { | |
4901 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 SS |
4902 | || loc->owner->type == bp_hardware_breakpoint |
4903 | || loc->owner->type == bp_tracepoint) | |
0d381245 VP |
4904 | { |
4905 | find_pc_partial_function (loc->address, &(loc->function_name), | |
4906 | NULL, NULL); | |
4907 | if (loc->function_name) | |
4908 | loc->function_name = xstrdup (loc->function_name); | |
4909 | } | |
4910 | } | |
4911 | ||
a6d9a66e UW |
4912 | /* Attempt to determine architecture of location identified by SAL. */ |
4913 | static struct gdbarch * | |
4914 | get_sal_arch (struct symtab_and_line sal) | |
4915 | { | |
4916 | if (sal.section) | |
4917 | return get_objfile_arch (sal.section->objfile); | |
4918 | if (sal.symtab) | |
4919 | return get_objfile_arch (sal.symtab->objfile); | |
4920 | ||
4921 | return NULL; | |
4922 | } | |
4923 | ||
0d381245 VP |
4924 | /* set_raw_breakpoint is a low level routine for allocating and |
4925 | partially initializing a breakpoint of type BPTYPE. The newly | |
4926 | created breakpoint's address, section, source file name, and line | |
4927 | number are provided by SAL. The newly created and partially | |
4928 | initialized breakpoint is added to the breakpoint chain and | |
4929 | is also returned as the value of this function. | |
4930 | ||
4931 | It is expected that the caller will complete the initialization of | |
4932 | the newly created breakpoint struct as well as output any status | |
4933 | information regarding the creation of a new breakpoint. In | |
4934 | particular, set_raw_breakpoint does NOT set the breakpoint | |
4935 | number! Care should be taken to not allow an error to occur | |
4936 | prior to completing the initialization of the breakpoint. If this | |
4937 | should happen, a bogus breakpoint will be left on the chain. */ | |
4938 | ||
63c252f8 | 4939 | struct breakpoint * |
a6d9a66e UW |
4940 | set_raw_breakpoint (struct gdbarch *gdbarch, |
4941 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 4942 | { |
a6d9a66e | 4943 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 4944 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
4945 | struct gdbarch *loc_gdbarch; |
4946 | ||
4947 | loc_gdbarch = get_sal_arch (sal); | |
4948 | if (!loc_gdbarch) | |
4949 | loc_gdbarch = b->gdbarch; | |
0d381245 | 4950 | |
6c95b8df PA |
4951 | if (bptype != bp_catchpoint) |
4952 | gdb_assert (sal.pspace != NULL); | |
4953 | ||
0d381245 VP |
4954 | /* Adjust the breakpoint's address prior to allocating a location. |
4955 | Once we call allocate_bp_location(), that mostly uninitialized | |
4956 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 4957 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
4958 | not want its scan of the location chain to find a breakpoint and |
4959 | location that's only been partially initialized. */ | |
a6d9a66e | 4960 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 4961 | |
39d61571 | 4962 | b->loc = allocate_bp_location (b); |
a6d9a66e | 4963 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
4964 | b->loc->requested_address = sal.pc; |
4965 | b->loc->address = adjusted_address; | |
6c95b8df PA |
4966 | b->loc->pspace = sal.pspace; |
4967 | ||
4968 | /* Store the program space that was used to set the breakpoint, for | |
4969 | breakpoint resetting. */ | |
4970 | b->pspace = sal.pspace; | |
0d381245 VP |
4971 | |
4972 | if (sal.symtab == NULL) | |
4973 | b->source_file = NULL; | |
4974 | else | |
1b36a34b | 4975 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
4976 | b->loc->section = sal.section; |
4977 | b->line_number = sal.line; | |
4978 | ||
4979 | set_breakpoint_location_function (b->loc); | |
c906108c | 4980 | |
c906108c SS |
4981 | breakpoints_changed (); |
4982 | ||
4983 | return b; | |
4984 | } | |
4985 | ||
c2c6d25f JM |
4986 | |
4987 | /* Note that the breakpoint object B describes a permanent breakpoint | |
4988 | instruction, hard-wired into the inferior's code. */ | |
4989 | void | |
4990 | make_breakpoint_permanent (struct breakpoint *b) | |
4991 | { | |
0d381245 | 4992 | struct bp_location *bl; |
b5de0fa7 | 4993 | b->enable_state = bp_permanent; |
c2c6d25f | 4994 | |
0d381245 VP |
4995 | /* By definition, permanent breakpoints are already present in the code. |
4996 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
4997 | is called in just one place, so it's hard to say if it's reasonable | |
4998 | to have permanent breakpoint with multiple locations or not, | |
4999 | but it's easy to implmement. */ | |
5000 | for (bl = b->loc; bl; bl = bl->next) | |
5001 | bl->inserted = 1; | |
c2c6d25f JM |
5002 | } |
5003 | ||
53a5351d | 5004 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5005 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5006 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5007 | ||
5008 | void | |
0fd8e87f | 5009 | set_longjmp_breakpoint (int thread) |
c906108c | 5010 | { |
0fd8e87f UW |
5011 | struct breakpoint *b, *temp; |
5012 | ||
5013 | /* To avoid having to rescan all objfile symbols at every step, | |
5014 | we maintain a list of continually-inserted but always disabled | |
5015 | longjmp "master" breakpoints. Here, we simply create momentary | |
5016 | clones of those and enable them for the requested thread. */ | |
5017 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5018 | if (b->pspace == current_program_space |
5019 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5020 | { |
5021 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5022 | clone->type = bp_longjmp; | |
5023 | clone->thread = thread; | |
5024 | } | |
c906108c SS |
5025 | } |
5026 | ||
611c83ae | 5027 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5028 | void |
611c83ae | 5029 | delete_longjmp_breakpoint (int thread) |
c906108c | 5030 | { |
611c83ae | 5031 | struct breakpoint *b, *temp; |
c906108c | 5032 | |
611c83ae PA |
5033 | ALL_BREAKPOINTS_SAFE (b, temp) |
5034 | if (b->type == bp_longjmp) | |
5035 | { | |
5036 | if (b->thread == thread) | |
5037 | delete_breakpoint (b); | |
5038 | } | |
c906108c SS |
5039 | } |
5040 | ||
1900040c MS |
5041 | void |
5042 | enable_overlay_breakpoints (void) | |
5043 | { | |
52f0bd74 | 5044 | struct breakpoint *b; |
1900040c MS |
5045 | |
5046 | ALL_BREAKPOINTS (b) | |
5047 | if (b->type == bp_overlay_event) | |
5048 | { | |
5049 | b->enable_state = bp_enabled; | |
b60e7edf | 5050 | update_global_location_list (1); |
c02f5703 | 5051 | overlay_events_enabled = 1; |
1900040c MS |
5052 | } |
5053 | } | |
5054 | ||
5055 | void | |
5056 | disable_overlay_breakpoints (void) | |
5057 | { | |
52f0bd74 | 5058 | struct breakpoint *b; |
1900040c MS |
5059 | |
5060 | ALL_BREAKPOINTS (b) | |
5061 | if (b->type == bp_overlay_event) | |
5062 | { | |
5063 | b->enable_state = bp_disabled; | |
b60e7edf | 5064 | update_global_location_list (0); |
c02f5703 | 5065 | overlay_events_enabled = 0; |
1900040c MS |
5066 | } |
5067 | } | |
5068 | ||
c4093a6a | 5069 | struct breakpoint * |
a6d9a66e | 5070 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5071 | { |
5072 | struct breakpoint *b; | |
c4093a6a | 5073 | |
a6d9a66e | 5074 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5075 | |
b5de0fa7 | 5076 | b->enable_state = bp_enabled; |
c4093a6a | 5077 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5078 | b->addr_string |
5079 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5080 | |
b60e7edf | 5081 | update_global_location_list_nothrow (1); |
74960c60 | 5082 | |
c4093a6a JM |
5083 | return b; |
5084 | } | |
5085 | ||
5086 | void | |
5087 | remove_thread_event_breakpoints (void) | |
5088 | { | |
5089 | struct breakpoint *b, *temp; | |
5090 | ||
5091 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5092 | if (b->type == bp_thread_event |
5093 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5094 | delete_breakpoint (b); |
5095 | } | |
5096 | ||
0101ce28 JJ |
5097 | struct captured_parse_breakpoint_args |
5098 | { | |
5099 | char **arg_p; | |
5100 | struct symtabs_and_lines *sals_p; | |
5101 | char ***addr_string_p; | |
5102 | int *not_found_ptr; | |
5103 | }; | |
5104 | ||
5105 | struct lang_and_radix | |
5106 | { | |
5107 | enum language lang; | |
5108 | int radix; | |
5109 | }; | |
5110 | ||
4efc6507 DE |
5111 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5112 | ||
5113 | struct breakpoint * | |
5114 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5115 | { | |
5116 | struct breakpoint *b; | |
5117 | ||
5118 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5119 | update_global_location_list_nothrow (1); | |
5120 | return b; | |
5121 | } | |
0101ce28 | 5122 | |
cae688ec JJ |
5123 | void |
5124 | remove_solib_event_breakpoints (void) | |
5125 | { | |
5126 | struct breakpoint *b, *temp; | |
5127 | ||
5128 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5129 | if (b->type == bp_shlib_event |
5130 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5131 | delete_breakpoint (b); |
5132 | } | |
5133 | ||
5134 | struct breakpoint * | |
a6d9a66e | 5135 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5136 | { |
5137 | struct breakpoint *b; | |
5138 | ||
a6d9a66e | 5139 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5140 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5141 | return b; |
5142 | } | |
5143 | ||
5144 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5145 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5146 | ||
5147 | void | |
cb851954 | 5148 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5149 | { |
876fa593 | 5150 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5151 | |
876fa593 | 5152 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5153 | { |
0d381245 VP |
5154 | struct breakpoint *b = loc->owner; |
5155 | /* We apply the check to all breakpoints, including disabled | |
5156 | for those with loc->duplicate set. This is so that when breakpoint | |
5157 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5158 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5159 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
5160 | if (((b->type == bp_breakpoint) |
5161 | || (b->type == bp_hardware_breakpoint) | |
5162 | || (b->type == bp_tracepoint)) | |
6c95b8df | 5163 | && loc->pspace == current_program_space |
0d381245 | 5164 | && !loc->shlib_disabled |
a77053c2 | 5165 | #ifdef PC_SOLIB |
0d381245 | 5166 | && PC_SOLIB (loc->address) |
a77053c2 | 5167 | #else |
6c95b8df | 5168 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5169 | #endif |
5170 | ) | |
0d381245 VP |
5171 | { |
5172 | loc->shlib_disabled = 1; | |
5173 | } | |
cae688ec JJ |
5174 | } |
5175 | } | |
5176 | ||
84acb35a JJ |
5177 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5178 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5179 | ||
75149521 | 5180 | static void |
84acb35a JJ |
5181 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5182 | { | |
876fa593 | 5183 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5184 | int disabled_shlib_breaks = 0; |
5185 | ||
c86cf029 VP |
5186 | /* SunOS a.out shared libraries are always mapped, so do not |
5187 | disable breakpoints; they will only be reported as unloaded | |
5188 | through clear_solib when GDB discards its shared library | |
5189 | list. See clear_solib for more information. */ | |
5190 | if (exec_bfd != NULL | |
5191 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5192 | return; | |
5193 | ||
876fa593 | 5194 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5195 | { |
0d381245 VP |
5196 | struct breakpoint *b = loc->owner; |
5197 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5198 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5199 | && solib->pspace == loc->pspace |
e2dd7057 PP |
5200 | && !loc->shlib_disabled |
5201 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
5202 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 5203 | { |
e2dd7057 PP |
5204 | loc->shlib_disabled = 1; |
5205 | /* At this point, we cannot rely on remove_breakpoint | |
5206 | succeeding so we must mark the breakpoint as not inserted | |
5207 | to prevent future errors occurring in remove_breakpoints. */ | |
5208 | loc->inserted = 0; | |
5209 | if (!disabled_shlib_breaks) | |
5210 | { | |
5211 | target_terminal_ours_for_output (); | |
5212 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5213 | solib->so_name); | |
84acb35a | 5214 | } |
e2dd7057 | 5215 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5216 | } |
5217 | } | |
84acb35a JJ |
5218 | } |
5219 | ||
ce78b96d JB |
5220 | /* FORK & VFORK catchpoints. */ |
5221 | ||
5222 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5223 | ||
c906108c | 5224 | static void |
ce78b96d JB |
5225 | insert_catch_fork (struct breakpoint *b) |
5226 | { | |
5227 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5228 | } | |
5229 | ||
5230 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5231 | ||
5232 | static int | |
5233 | remove_catch_fork (struct breakpoint *b) | |
5234 | { | |
5235 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5236 | } | |
5237 | ||
5238 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5239 | catchpoints. */ | |
5240 | ||
5241 | static int | |
5242 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5243 | { | |
5244 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5245 | } | |
5246 | ||
5247 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5248 | ||
5249 | static enum print_stop_action | |
5250 | print_it_catch_fork (struct breakpoint *b) | |
5251 | { | |
5252 | annotate_catchpoint (b->number); | |
5253 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5254 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5255 | return PRINT_SRC_AND_LOC; | |
5256 | } | |
5257 | ||
5258 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5259 | ||
5260 | static void | |
a6d9a66e | 5261 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5262 | { |
79a45b7d TT |
5263 | struct value_print_options opts; |
5264 | ||
5265 | get_user_print_options (&opts); | |
5266 | ||
ce78b96d JB |
5267 | /* Field 4, the address, is omitted (which makes the columns |
5268 | not line up too nicely with the headers, but the effect | |
5269 | is relatively readable). */ | |
79a45b7d | 5270 | if (opts.addressprint) |
ce78b96d JB |
5271 | ui_out_field_skip (uiout, "addr"); |
5272 | annotate_field (5); | |
5273 | ui_out_text (uiout, "fork"); | |
5274 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5275 | { | |
5276 | ui_out_text (uiout, ", process "); | |
5277 | ui_out_field_int (uiout, "what", | |
5278 | ptid_get_pid (b->forked_inferior_pid)); | |
5279 | ui_out_spaces (uiout, 1); | |
5280 | } | |
5281 | } | |
5282 | ||
5283 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5284 | catchpoints. */ | |
5285 | ||
5286 | static void | |
5287 | print_mention_catch_fork (struct breakpoint *b) | |
5288 | { | |
5289 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5290 | } | |
5291 | ||
5292 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5293 | ||
5294 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5295 | { | |
5296 | insert_catch_fork, | |
5297 | remove_catch_fork, | |
5298 | breakpoint_hit_catch_fork, | |
5299 | print_it_catch_fork, | |
5300 | print_one_catch_fork, | |
5301 | print_mention_catch_fork | |
5302 | }; | |
5303 | ||
5304 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5305 | ||
5306 | static void | |
5307 | insert_catch_vfork (struct breakpoint *b) | |
5308 | { | |
5309 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5310 | } | |
5311 | ||
5312 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5313 | ||
5314 | static int | |
5315 | remove_catch_vfork (struct breakpoint *b) | |
5316 | { | |
5317 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5318 | } | |
5319 | ||
5320 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5321 | catchpoints. */ | |
5322 | ||
5323 | static int | |
5324 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5325 | { | |
5326 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5327 | } | |
5328 | ||
5329 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5330 | ||
5331 | static enum print_stop_action | |
5332 | print_it_catch_vfork (struct breakpoint *b) | |
5333 | { | |
5334 | annotate_catchpoint (b->number); | |
5335 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5336 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5337 | return PRINT_SRC_AND_LOC; | |
5338 | } | |
5339 | ||
5340 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5341 | ||
5342 | static void | |
a6d9a66e | 5343 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5344 | { |
79a45b7d TT |
5345 | struct value_print_options opts; |
5346 | ||
5347 | get_user_print_options (&opts); | |
ce78b96d JB |
5348 | /* Field 4, the address, is omitted (which makes the columns |
5349 | not line up too nicely with the headers, but the effect | |
5350 | is relatively readable). */ | |
79a45b7d | 5351 | if (opts.addressprint) |
ce78b96d JB |
5352 | ui_out_field_skip (uiout, "addr"); |
5353 | annotate_field (5); | |
5354 | ui_out_text (uiout, "vfork"); | |
5355 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5356 | { | |
5357 | ui_out_text (uiout, ", process "); | |
5358 | ui_out_field_int (uiout, "what", | |
5359 | ptid_get_pid (b->forked_inferior_pid)); | |
5360 | ui_out_spaces (uiout, 1); | |
5361 | } | |
5362 | } | |
5363 | ||
5364 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5365 | catchpoints. */ | |
5366 | ||
5367 | static void | |
5368 | print_mention_catch_vfork (struct breakpoint *b) | |
5369 | { | |
5370 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5371 | } | |
5372 | ||
5373 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5374 | ||
5375 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5376 | { | |
5377 | insert_catch_vfork, | |
5378 | remove_catch_vfork, | |
5379 | breakpoint_hit_catch_vfork, | |
5380 | print_it_catch_vfork, | |
5381 | print_one_catch_vfork, | |
5382 | print_mention_catch_vfork | |
5383 | }; | |
5384 | ||
a96d9b2e SDJ |
5385 | /* Implement the "insert" breakpoint_ops method for syscall |
5386 | catchpoints. */ | |
5387 | ||
5388 | static void | |
5389 | insert_catch_syscall (struct breakpoint *b) | |
5390 | { | |
5391 | struct inferior *inf = current_inferior (); | |
5392 | ||
5393 | ++inf->total_syscalls_count; | |
5394 | if (!b->syscalls_to_be_caught) | |
5395 | ++inf->any_syscall_count; | |
5396 | else | |
5397 | { | |
5398 | int i, iter; | |
5399 | for (i = 0; | |
5400 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5401 | i++) | |
5402 | { | |
5403 | int elem; | |
5404 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5405 | { | |
5406 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5407 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5408 | uintptr_t vec_addr; | |
5409 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5410 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5411 | vec_addr_offset; | |
5412 | memset ((void *) vec_addr, 0, | |
5413 | (iter + 1 - old_size) * sizeof (int)); | |
5414 | } | |
5415 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5416 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5417 | } | |
5418 | } | |
5419 | ||
5420 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5421 | inf->total_syscalls_count != 0, | |
5422 | inf->any_syscall_count, | |
5423 | VEC_length (int, inf->syscalls_counts), | |
5424 | VEC_address (int, inf->syscalls_counts)); | |
5425 | } | |
5426 | ||
5427 | /* Implement the "remove" breakpoint_ops method for syscall | |
5428 | catchpoints. */ | |
5429 | ||
5430 | static int | |
5431 | remove_catch_syscall (struct breakpoint *b) | |
5432 | { | |
5433 | struct inferior *inf = current_inferior (); | |
5434 | ||
5435 | --inf->total_syscalls_count; | |
5436 | if (!b->syscalls_to_be_caught) | |
5437 | --inf->any_syscall_count; | |
5438 | else | |
5439 | { | |
5440 | int i, iter; | |
5441 | for (i = 0; | |
5442 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5443 | i++) | |
5444 | { | |
5445 | int elem; | |
5446 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5447 | /* Shouldn't happen. */ | |
5448 | continue; | |
5449 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5450 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5451 | } | |
5452 | } | |
5453 | ||
5454 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5455 | inf->total_syscalls_count != 0, | |
5456 | inf->any_syscall_count, | |
5457 | VEC_length (int, inf->syscalls_counts), | |
5458 | VEC_address (int, inf->syscalls_counts)); | |
5459 | } | |
5460 | ||
5461 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5462 | catchpoints. */ | |
5463 | ||
5464 | static int | |
5465 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5466 | { | |
5467 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5468 | If we are, then we must guarantee that the called syscall is the same | |
5469 | syscall we are catching. */ | |
5470 | int syscall_number = 0; | |
5471 | ||
5472 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5473 | return 0; | |
5474 | ||
5475 | /* Now, checking if the syscall is the same. */ | |
5476 | if (b->syscalls_to_be_caught) | |
5477 | { | |
5478 | int i, iter; | |
5479 | for (i = 0; | |
5480 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5481 | i++) | |
5482 | if (syscall_number == iter) | |
5483 | break; | |
5484 | /* Not the same. */ | |
5485 | if (!iter) | |
5486 | return 0; | |
5487 | } | |
5488 | ||
5489 | return 1; | |
5490 | } | |
5491 | ||
5492 | /* Implement the "print_it" breakpoint_ops method for syscall | |
5493 | catchpoints. */ | |
5494 | ||
5495 | static enum print_stop_action | |
5496 | print_it_catch_syscall (struct breakpoint *b) | |
5497 | { | |
5498 | /* These are needed because we want to know in which state a | |
5499 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
5500 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
5501 | must print "called syscall" or "returned from syscall". */ | |
5502 | ptid_t ptid; | |
5503 | struct target_waitstatus last; | |
5504 | struct syscall s; | |
5505 | struct cleanup *old_chain; | |
5506 | char *syscall_id; | |
5507 | ||
5508 | get_last_target_status (&ptid, &last); | |
5509 | ||
5510 | get_syscall_by_number (last.value.syscall_number, &s); | |
5511 | ||
5512 | annotate_catchpoint (b->number); | |
5513 | ||
5514 | if (s.name == NULL) | |
5515 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
5516 | else | |
5517 | syscall_id = xstrprintf ("'%s'", s.name); | |
5518 | ||
5519 | old_chain = make_cleanup (xfree, syscall_id); | |
5520 | ||
5521 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
5522 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
5523 | b->number, syscall_id); | |
5524 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
5525 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
5526 | b->number, syscall_id); | |
5527 | ||
5528 | do_cleanups (old_chain); | |
5529 | ||
5530 | return PRINT_SRC_AND_LOC; | |
5531 | } | |
5532 | ||
5533 | /* Implement the "print_one" breakpoint_ops method for syscall | |
5534 | catchpoints. */ | |
5535 | ||
5536 | static void | |
5537 | print_one_catch_syscall (struct breakpoint *b, | |
5538 | struct bp_location **last_loc) | |
5539 | { | |
5540 | struct value_print_options opts; | |
5541 | ||
5542 | get_user_print_options (&opts); | |
5543 | /* Field 4, the address, is omitted (which makes the columns | |
5544 | not line up too nicely with the headers, but the effect | |
5545 | is relatively readable). */ | |
5546 | if (opts.addressprint) | |
5547 | ui_out_field_skip (uiout, "addr"); | |
5548 | annotate_field (5); | |
5549 | ||
5550 | if (b->syscalls_to_be_caught | |
5551 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5552 | ui_out_text (uiout, "syscalls \""); | |
5553 | else | |
5554 | ui_out_text (uiout, "syscall \""); | |
5555 | ||
5556 | if (b->syscalls_to_be_caught) | |
5557 | { | |
5558 | int i, iter; | |
5559 | char *text = xstrprintf ("%s", ""); | |
5560 | for (i = 0; | |
5561 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5562 | i++) | |
5563 | { | |
5564 | char *x = text; | |
5565 | struct syscall s; | |
5566 | get_syscall_by_number (iter, &s); | |
5567 | ||
5568 | if (s.name != NULL) | |
5569 | text = xstrprintf ("%s%s, ", text, s.name); | |
5570 | else | |
5571 | text = xstrprintf ("%s%d, ", text, iter); | |
5572 | ||
5573 | /* We have to xfree the last 'text' (now stored at 'x') | |
5574 | because xstrprintf dinamically allocates new space for it | |
5575 | on every call. */ | |
5576 | xfree (x); | |
5577 | } | |
5578 | /* Remove the last comma. */ | |
5579 | text[strlen (text) - 2] = '\0'; | |
5580 | ui_out_field_string (uiout, "what", text); | |
5581 | } | |
5582 | else | |
5583 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
5584 | ui_out_text (uiout, "\" "); | |
5585 | } | |
5586 | ||
5587 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
5588 | catchpoints. */ | |
5589 | ||
5590 | static void | |
5591 | print_mention_catch_syscall (struct breakpoint *b) | |
5592 | { | |
5593 | if (b->syscalls_to_be_caught) | |
5594 | { | |
5595 | int i, iter; | |
5596 | ||
5597 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5598 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
5599 | else | |
5600 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
5601 | ||
5602 | for (i = 0; | |
5603 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5604 | i++) | |
5605 | { | |
5606 | struct syscall s; | |
5607 | get_syscall_by_number (iter, &s); | |
5608 | ||
5609 | if (s.name) | |
5610 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
5611 | else | |
5612 | printf_filtered (" %d", s.number); | |
5613 | } | |
5614 | printf_filtered (")"); | |
5615 | } | |
5616 | else | |
5617 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
5618 | b->number); | |
5619 | } | |
5620 | ||
5621 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
5622 | ||
5623 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
5624 | { | |
5625 | insert_catch_syscall, | |
5626 | remove_catch_syscall, | |
5627 | breakpoint_hit_catch_syscall, | |
5628 | print_it_catch_syscall, | |
5629 | print_one_catch_syscall, | |
5630 | print_mention_catch_syscall | |
5631 | }; | |
5632 | ||
5633 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
5634 | ||
5635 | static int | |
5636 | syscall_catchpoint_p (struct breakpoint *b) | |
5637 | { | |
5638 | return (b->ops == &catch_syscall_breakpoint_ops); | |
5639 | } | |
5640 | ||
5641 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
5642 | but does NOT mention it nor update the global location list. | |
5643 | This is useful if you need to fill more fields in the | |
5644 | struct breakpoint before calling mention. | |
ce78b96d JB |
5645 | |
5646 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5647 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5648 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5649 | to the catchpoint. */ | |
5650 | ||
5651 | static struct breakpoint * | |
a96d9b2e SDJ |
5652 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
5653 | char *cond_string, | |
5654 | struct breakpoint_ops *ops) | |
c906108c | 5655 | { |
c5aa993b JM |
5656 | struct symtab_and_line sal; |
5657 | struct breakpoint *b; | |
c5aa993b | 5658 | |
fe39c653 | 5659 | init_sal (&sal); |
6c95b8df | 5660 | sal.pspace = current_program_space; |
c5aa993b | 5661 | |
a6d9a66e | 5662 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
5663 | set_breakpoint_count (breakpoint_count + 1); |
5664 | b->number = breakpoint_count; | |
ce78b96d | 5665 | |
1b36a34b | 5666 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 5667 | b->thread = -1; |
c906108c | 5668 | b->addr_string = NULL; |
b5de0fa7 EZ |
5669 | b->enable_state = bp_enabled; |
5670 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 5671 | b->ops = ops; |
c5aa993b | 5672 | |
a96d9b2e SDJ |
5673 | return b; |
5674 | } | |
5675 | ||
5676 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
5677 | ||
5678 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5679 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5680 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5681 | to the catchpoint. */ | |
5682 | ||
5683 | static struct breakpoint * | |
5684 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
5685 | char *cond_string, struct breakpoint_ops *ops) | |
5686 | { | |
5687 | struct breakpoint *b = | |
5688 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
5689 | ||
c906108c | 5690 | mention (b); |
ce78b96d | 5691 | update_global_location_list (1); |
c906108c | 5692 | |
ce78b96d | 5693 | return b; |
c906108c | 5694 | } |
c5aa993b | 5695 | |
9b70b993 | 5696 | static void |
a6d9a66e UW |
5697 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
5698 | int tempflag, char *cond_string, | |
ce78b96d | 5699 | struct breakpoint_ops *ops) |
c906108c | 5700 | { |
a6d9a66e UW |
5701 | struct breakpoint *b |
5702 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
5703 | |
5704 | /* FIXME: We should put this information in a breakpoint private data | |
5705 | area. */ | |
5706 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
5707 | } |
5708 | ||
fe798b75 JB |
5709 | /* Exec catchpoints. */ |
5710 | ||
9b70b993 | 5711 | static void |
fe798b75 | 5712 | insert_catch_exec (struct breakpoint *b) |
c906108c | 5713 | { |
fe798b75 JB |
5714 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
5715 | } | |
c906108c | 5716 | |
fe798b75 JB |
5717 | static int |
5718 | remove_catch_exec (struct breakpoint *b) | |
5719 | { | |
5720 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
5721 | } | |
c906108c | 5722 | |
fe798b75 JB |
5723 | static int |
5724 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
5725 | { | |
5726 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
5727 | } | |
c906108c | 5728 | |
fe798b75 JB |
5729 | static enum print_stop_action |
5730 | print_it_catch_exec (struct breakpoint *b) | |
5731 | { | |
5732 | annotate_catchpoint (b->number); | |
5733 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
5734 | b->exec_pathname); | |
5735 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
5736 | } |
5737 | ||
fe798b75 | 5738 | static void |
a6d9a66e | 5739 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
5740 | { |
5741 | struct value_print_options opts; | |
5742 | ||
5743 | get_user_print_options (&opts); | |
5744 | ||
5745 | /* Field 4, the address, is omitted (which makes the columns | |
5746 | not line up too nicely with the headers, but the effect | |
5747 | is relatively readable). */ | |
5748 | if (opts.addressprint) | |
5749 | ui_out_field_skip (uiout, "addr"); | |
5750 | annotate_field (5); | |
5751 | ui_out_text (uiout, "exec"); | |
5752 | if (b->exec_pathname != NULL) | |
5753 | { | |
5754 | ui_out_text (uiout, ", program \""); | |
5755 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5756 | ui_out_text (uiout, "\" "); | |
5757 | } | |
5758 | } | |
5759 | ||
5760 | static void | |
5761 | print_mention_catch_exec (struct breakpoint *b) | |
5762 | { | |
5763 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5764 | } | |
5765 | ||
5766 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5767 | { | |
5768 | insert_catch_exec, | |
5769 | remove_catch_exec, | |
5770 | breakpoint_hit_catch_exec, | |
5771 | print_it_catch_exec, | |
5772 | print_one_catch_exec, | |
5773 | print_mention_catch_exec | |
5774 | }; | |
5775 | ||
a96d9b2e SDJ |
5776 | static void |
5777 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
5778 | struct breakpoint_ops *ops) | |
5779 | { | |
5780 | struct gdbarch *gdbarch = get_current_arch (); | |
5781 | struct breakpoint *b = | |
5782 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
5783 | ||
5784 | b->syscalls_to_be_caught = filter; | |
5785 | ||
5786 | /* Now, we have to mention the breakpoint and update the global | |
5787 | location list. */ | |
5788 | mention (b); | |
5789 | update_global_location_list (1); | |
5790 | } | |
5791 | ||
c906108c | 5792 | static int |
fba45db2 | 5793 | hw_breakpoint_used_count (void) |
c906108c | 5794 | { |
52f0bd74 | 5795 | struct breakpoint *b; |
c906108c SS |
5796 | int i = 0; |
5797 | ||
5798 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5799 | { |
d6b74ac4 | 5800 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5801 | i++; |
5802 | } | |
c906108c SS |
5803 | |
5804 | return i; | |
5805 | } | |
5806 | ||
5807 | static int | |
fba45db2 | 5808 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5809 | { |
52f0bd74 | 5810 | struct breakpoint *b; |
c906108c SS |
5811 | int i = 0; |
5812 | ||
5813 | *other_type_used = 0; | |
5814 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5815 | { |
468d015d | 5816 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5817 | { |
5818 | if (b->type == type) | |
5819 | i++; | |
059fb39f PM |
5820 | else if ((b->type == bp_hardware_watchpoint |
5821 | || b->type == bp_read_watchpoint | |
5822 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5823 | *other_type_used = 1; |
5824 | } | |
5825 | } | |
c906108c SS |
5826 | return i; |
5827 | } | |
5828 | ||
c906108c | 5829 | void |
fba45db2 | 5830 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5831 | { |
c5aa993b | 5832 | struct breakpoint *b; |
c906108c SS |
5833 | |
5834 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5835 | { |
5836 | if (((b->type == bp_watchpoint) | |
5837 | || (b->type == bp_hardware_watchpoint) | |
5838 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5839 | || (b->type == bp_access_watchpoint)) |
468d015d | 5840 | && breakpoint_enabled (b)) |
c5aa993b | 5841 | { |
b5de0fa7 | 5842 | b->enable_state = bp_call_disabled; |
b60e7edf | 5843 | update_global_location_list (0); |
c5aa993b JM |
5844 | } |
5845 | } | |
c906108c SS |
5846 | } |
5847 | ||
5848 | void | |
fba45db2 | 5849 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5850 | { |
c5aa993b | 5851 | struct breakpoint *b; |
c906108c SS |
5852 | |
5853 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5854 | { |
5855 | if (((b->type == bp_watchpoint) | |
5856 | || (b->type == bp_hardware_watchpoint) | |
5857 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5858 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 5859 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 5860 | { |
b5de0fa7 | 5861 | b->enable_state = bp_enabled; |
b60e7edf | 5862 | update_global_location_list (1); |
c5aa993b JM |
5863 | } |
5864 | } | |
c906108c SS |
5865 | } |
5866 | ||
8bea4e01 UW |
5867 | void |
5868 | disable_breakpoints_before_startup (void) | |
5869 | { | |
5870 | struct breakpoint *b; | |
5871 | int found = 0; | |
5872 | ||
5873 | ALL_BREAKPOINTS (b) | |
5874 | { | |
6c95b8df PA |
5875 | if (b->pspace != current_program_space) |
5876 | continue; | |
5877 | ||
8bea4e01 UW |
5878 | if ((b->type == bp_breakpoint |
5879 | || b->type == bp_hardware_breakpoint) | |
5880 | && breakpoint_enabled (b)) | |
5881 | { | |
5882 | b->enable_state = bp_startup_disabled; | |
5883 | found = 1; | |
5884 | } | |
5885 | } | |
5886 | ||
5887 | if (found) | |
5888 | update_global_location_list (0); | |
5889 | ||
6c95b8df | 5890 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
5891 | } |
5892 | ||
5893 | void | |
5894 | enable_breakpoints_after_startup (void) | |
5895 | { | |
5896 | struct breakpoint *b; | |
5897 | int found = 0; | |
5898 | ||
6c95b8df | 5899 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
5900 | |
5901 | ALL_BREAKPOINTS (b) | |
5902 | { | |
6c95b8df PA |
5903 | if (b->pspace != current_program_space) |
5904 | continue; | |
5905 | ||
8bea4e01 UW |
5906 | if ((b->type == bp_breakpoint |
5907 | || b->type == bp_hardware_breakpoint) | |
5908 | && b->enable_state == bp_startup_disabled) | |
5909 | { | |
5910 | b->enable_state = bp_enabled; | |
5911 | found = 1; | |
5912 | } | |
5913 | } | |
5914 | ||
5915 | if (found) | |
5916 | breakpoint_re_set (); | |
5917 | } | |
5918 | ||
c906108c SS |
5919 | |
5920 | /* Set a breakpoint that will evaporate an end of command | |
5921 | at address specified by SAL. | |
5922 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
5923 | ||
5924 | struct breakpoint * | |
a6d9a66e UW |
5925 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
5926 | struct frame_id frame_id, enum bptype type) | |
c906108c | 5927 | { |
52f0bd74 | 5928 | struct breakpoint *b; |
edb3359d DJ |
5929 | |
5930 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
5931 | one. */ | |
5932 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
5933 | ||
a6d9a66e | 5934 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
5935 | b->enable_state = bp_enabled; |
5936 | b->disposition = disp_donttouch; | |
818dd999 | 5937 | b->frame_id = frame_id; |
c906108c SS |
5938 | |
5939 | /* If we're debugging a multi-threaded program, then we | |
5940 | want momentary breakpoints to be active in only a | |
5941 | single thread of control. */ | |
39f77062 KB |
5942 | if (in_thread_list (inferior_ptid)) |
5943 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 5944 | |
b60e7edf | 5945 | update_global_location_list_nothrow (1); |
74960c60 | 5946 | |
c906108c SS |
5947 | return b; |
5948 | } | |
611c83ae | 5949 | |
e58b0e63 PA |
5950 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
5951 | ORIG is NULL. */ | |
5952 | ||
5953 | struct breakpoint * | |
5954 | clone_momentary_breakpoint (struct breakpoint *orig) | |
5955 | { | |
5956 | struct breakpoint *copy; | |
5957 | ||
5958 | /* If there's nothing to clone, then return nothing. */ | |
5959 | if (orig == NULL) | |
5960 | return NULL; | |
5961 | ||
a6d9a66e | 5962 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
5963 | copy->loc = allocate_bp_location (copy); |
5964 | set_breakpoint_location_function (copy->loc); | |
5965 | ||
a6d9a66e | 5966 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
5967 | copy->loc->requested_address = orig->loc->requested_address; |
5968 | copy->loc->address = orig->loc->address; | |
5969 | copy->loc->section = orig->loc->section; | |
6c95b8df | 5970 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
5971 | |
5972 | if (orig->source_file == NULL) | |
5973 | copy->source_file = NULL; | |
5974 | else | |
5975 | copy->source_file = xstrdup (orig->source_file); | |
5976 | ||
5977 | copy->line_number = orig->line_number; | |
5978 | copy->frame_id = orig->frame_id; | |
5979 | copy->thread = orig->thread; | |
6c95b8df | 5980 | copy->pspace = orig->pspace; |
e58b0e63 PA |
5981 | |
5982 | copy->enable_state = bp_enabled; | |
5983 | copy->disposition = disp_donttouch; | |
5984 | copy->number = internal_breakpoint_number--; | |
5985 | ||
5986 | update_global_location_list_nothrow (0); | |
5987 | return copy; | |
5988 | } | |
5989 | ||
611c83ae | 5990 | struct breakpoint * |
a6d9a66e UW |
5991 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
5992 | enum bptype type) | |
611c83ae PA |
5993 | { |
5994 | struct symtab_and_line sal; | |
5995 | ||
5996 | sal = find_pc_line (pc, 0); | |
5997 | sal.pc = pc; | |
5998 | sal.section = find_pc_overlay (pc); | |
5999 | sal.explicit_pc = 1; | |
6000 | ||
a6d9a66e | 6001 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6002 | } |
c906108c | 6003 | \f |
c5aa993b | 6004 | |
c906108c SS |
6005 | /* Tell the user we have just set a breakpoint B. */ |
6006 | ||
6007 | static void | |
fba45db2 | 6008 | mention (struct breakpoint *b) |
c906108c SS |
6009 | { |
6010 | int say_where = 0; | |
fa8a61dc | 6011 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6012 | struct value_print_options opts; |
6013 | ||
6014 | get_user_print_options (&opts); | |
8b93c638 | 6015 | |
9a4105ab AC |
6016 | /* FIXME: This is misplaced; mention() is called by things (like |
6017 | hitting a watchpoint) other than breakpoint creation. It should | |
6018 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6019 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6020 | observer_notify_breakpoint_created (b->number); |
c906108c | 6021 | |
3086aeae DJ |
6022 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6023 | b->ops->print_mention (b); | |
6024 | else | |
6025 | switch (b->type) | |
6026 | { | |
6027 | case bp_none: | |
a3f17187 | 6028 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6029 | break; |
6030 | case bp_watchpoint: | |
6031 | ui_out_text (uiout, "Watchpoint "); | |
6032 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6033 | ui_out_field_int (uiout, "number", b->number); | |
6034 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6035 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6036 | do_cleanups (ui_out_chain); |
6037 | break; | |
6038 | case bp_hardware_watchpoint: | |
6039 | ui_out_text (uiout, "Hardware watchpoint "); | |
6040 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6041 | ui_out_field_int (uiout, "number", b->number); | |
6042 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6043 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6044 | do_cleanups (ui_out_chain); |
6045 | break; | |
6046 | case bp_read_watchpoint: | |
6047 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6048 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6049 | ui_out_field_int (uiout, "number", b->number); | |
6050 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6051 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6052 | do_cleanups (ui_out_chain); |
6053 | break; | |
6054 | case bp_access_watchpoint: | |
6055 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6056 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6057 | ui_out_field_int (uiout, "number", b->number); | |
6058 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6059 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6060 | do_cleanups (ui_out_chain); |
6061 | break; | |
6062 | case bp_breakpoint: | |
6063 | if (ui_out_is_mi_like_p (uiout)) | |
6064 | { | |
6065 | say_where = 0; | |
6066 | break; | |
6067 | } | |
2cec12e5 AR |
6068 | if (b->disposition == disp_del) |
6069 | printf_filtered (_("Temporary breakpoint")); | |
6070 | else | |
6071 | printf_filtered (_("Breakpoint")); | |
6072 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6073 | say_where = 1; |
6074 | break; | |
6075 | case bp_hardware_breakpoint: | |
6076 | if (ui_out_is_mi_like_p (uiout)) | |
6077 | { | |
6078 | say_where = 0; | |
6079 | break; | |
6080 | } | |
a3f17187 | 6081 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6082 | say_where = 1; |
6083 | break; | |
1042e4c0 SS |
6084 | case bp_tracepoint: |
6085 | if (ui_out_is_mi_like_p (uiout)) | |
6086 | { | |
6087 | say_where = 0; | |
6088 | break; | |
6089 | } | |
6090 | printf_filtered (_("Tracepoint")); | |
6091 | printf_filtered (_(" %d"), b->number); | |
6092 | say_where = 1; | |
6093 | break; | |
3086aeae DJ |
6094 | |
6095 | case bp_until: | |
6096 | case bp_finish: | |
6097 | case bp_longjmp: | |
6098 | case bp_longjmp_resume: | |
6099 | case bp_step_resume: | |
3086aeae DJ |
6100 | case bp_call_dummy: |
6101 | case bp_watchpoint_scope: | |
6102 | case bp_shlib_event: | |
6103 | case bp_thread_event: | |
6104 | case bp_overlay_event: | |
4efc6507 | 6105 | case bp_jit_event: |
0fd8e87f | 6106 | case bp_longjmp_master: |
3086aeae DJ |
6107 | break; |
6108 | } | |
c906108c | 6109 | |
c906108c SS |
6110 | if (say_where) |
6111 | { | |
a3f17187 AC |
6112 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6113 | single string. */ | |
0d381245 | 6114 | if (b->loc == NULL) |
c906108c | 6115 | { |
a3f17187 | 6116 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6117 | } |
6118 | else | |
6119 | { | |
79a45b7d | 6120 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6121 | { |
6122 | printf_filtered (" at "); | |
5af949e3 UW |
6123 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6124 | gdb_stdout); | |
0101ce28 JJ |
6125 | } |
6126 | if (b->source_file) | |
6127 | printf_filtered (": file %s, line %d.", | |
6128 | b->source_file, b->line_number); | |
0d381245 VP |
6129 | |
6130 | if (b->loc->next) | |
6131 | { | |
6132 | struct bp_location *loc = b->loc; | |
6133 | int n = 0; | |
6134 | for (; loc; loc = loc->next) | |
6135 | ++n; | |
6136 | printf_filtered (" (%d locations)", n); | |
6137 | } | |
6138 | ||
c906108c | 6139 | } |
c906108c | 6140 | } |
9dc5e2a9 | 6141 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6142 | return; |
c906108c SS |
6143 | printf_filtered ("\n"); |
6144 | } | |
c906108c | 6145 | \f |
c5aa993b | 6146 | |
0d381245 | 6147 | static struct bp_location * |
39d61571 | 6148 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6149 | const struct symtab_and_line *sal) |
6150 | { | |
6151 | struct bp_location *loc, **tmp; | |
6152 | ||
39d61571 | 6153 | loc = allocate_bp_location (b); |
0d381245 VP |
6154 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6155 | ; | |
6156 | *tmp = loc; | |
a6d9a66e UW |
6157 | loc->gdbarch = get_sal_arch (*sal); |
6158 | if (!loc->gdbarch) | |
6159 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6160 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6161 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6162 | loc->requested_address, b->type); | |
6c95b8df PA |
6163 | loc->pspace = sal->pspace; |
6164 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6165 | loc->section = sal->section; |
6166 | ||
6167 | set_breakpoint_location_function (loc); | |
6168 | return loc; | |
6169 | } | |
514f746b AR |
6170 | \f |
6171 | ||
6172 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6173 | return 0 otherwise. */ | |
6174 | ||
6175 | static int | |
6176 | bp_loc_is_permanent (struct bp_location *loc) | |
6177 | { | |
6178 | int len; | |
6179 | CORE_ADDR addr; | |
6180 | const gdb_byte *brk; | |
6181 | gdb_byte *target_mem; | |
939c61fa JK |
6182 | struct cleanup *cleanup; |
6183 | int retval = 0; | |
514f746b AR |
6184 | |
6185 | gdb_assert (loc != NULL); | |
6186 | ||
6187 | addr = loc->address; | |
a6d9a66e | 6188 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6189 | |
939c61fa JK |
6190 | /* Software breakpoints unsupported? */ |
6191 | if (brk == NULL) | |
6192 | return 0; | |
6193 | ||
514f746b AR |
6194 | target_mem = alloca (len); |
6195 | ||
939c61fa JK |
6196 | /* Enable the automatic memory restoration from breakpoints while |
6197 | we read the memory. Otherwise we could say about our temporary | |
6198 | breakpoints they are permanent. */ | |
6c95b8df PA |
6199 | cleanup = save_current_space_and_thread (); |
6200 | ||
6201 | switch_to_program_space_and_thread (loc->pspace); | |
6202 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6203 | |
514f746b AR |
6204 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6205 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6206 | retval = 1; |
514f746b | 6207 | |
939c61fa JK |
6208 | do_cleanups (cleanup); |
6209 | ||
6210 | return retval; | |
514f746b AR |
6211 | } |
6212 | ||
6213 | ||
c3f6f71d | 6214 | |
018d34a4 VP |
6215 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6216 | as textual description of the location, and COND_STRING | |
db107f19 | 6217 | as condition expression. */ |
018d34a4 VP |
6218 | |
6219 | static void | |
a6d9a66e UW |
6220 | create_breakpoint (struct gdbarch *gdbarch, |
6221 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
6222 | char *cond_string, |
6223 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 6224 | int thread, int task, int ignore_count, |
41447f92 | 6225 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 6226 | { |
0d381245 VP |
6227 | struct breakpoint *b = NULL; |
6228 | int i; | |
018d34a4 VP |
6229 | |
6230 | if (type == bp_hardware_breakpoint) | |
6231 | { | |
6232 | int i = hw_breakpoint_used_count (); | |
6233 | int target_resources_ok = | |
d92524f1 | 6234 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6235 | i + 1, 0); |
6236 | if (target_resources_ok == 0) | |
6237 | error (_("No hardware breakpoint support in the target.")); | |
6238 | else if (target_resources_ok < 0) | |
6239 | error (_("Hardware breakpoints used exceeds limit.")); | |
6240 | } | |
6241 | ||
6c95b8df PA |
6242 | gdb_assert (sals.nelts > 0); |
6243 | ||
0d381245 VP |
6244 | for (i = 0; i < sals.nelts; ++i) |
6245 | { | |
6246 | struct symtab_and_line sal = sals.sals[i]; | |
6247 | struct bp_location *loc; | |
6248 | ||
6249 | if (from_tty) | |
5af949e3 UW |
6250 | { |
6251 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6252 | if (!loc_gdbarch) | |
6253 | loc_gdbarch = gdbarch; | |
6254 | ||
6255 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6256 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6257 | } |
0d381245 VP |
6258 | |
6259 | if (i == 0) | |
6260 | { | |
a6d9a66e | 6261 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6262 | set_breakpoint_count (breakpoint_count + 1); |
6263 | b->number = breakpoint_count; | |
6264 | b->thread = thread; | |
4a306c9a | 6265 | b->task = task; |
018d34a4 | 6266 | |
0d381245 VP |
6267 | b->cond_string = cond_string; |
6268 | b->ignore_count = ignore_count; | |
41447f92 | 6269 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6270 | b->disposition = disposition; |
018d34a4 | 6271 | |
6c95b8df PA |
6272 | b->pspace = sals.sals[0].pspace; |
6273 | ||
6274 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6275 | && (b->type == bp_breakpoint |
6276 | || b->type == bp_hardware_breakpoint)) | |
6277 | b->enable_state = bp_startup_disabled; | |
6278 | ||
0d381245 VP |
6279 | loc = b->loc; |
6280 | } | |
6281 | else | |
018d34a4 | 6282 | { |
39d61571 | 6283 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6284 | } |
6285 | ||
514f746b AR |
6286 | if (bp_loc_is_permanent (loc)) |
6287 | make_breakpoint_permanent (b); | |
6288 | ||
0d381245 VP |
6289 | if (b->cond_string) |
6290 | { | |
6291 | char *arg = b->cond_string; | |
d32a6982 | 6292 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6293 | if (*arg) |
db107f19 | 6294 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6295 | } |
0d381245 | 6296 | } |
018d34a4 VP |
6297 | |
6298 | if (addr_string) | |
6299 | b->addr_string = addr_string; | |
6300 | else | |
6301 | /* addr_string has to be used or breakpoint_re_set will delete | |
6302 | me. */ | |
5af949e3 UW |
6303 | b->addr_string |
6304 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6305 | |
604133b5 | 6306 | b->ops = ops; |
018d34a4 VP |
6307 | mention (b); |
6308 | } | |
6309 | ||
ed0616c6 VP |
6310 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6311 | elements to fill the void space. */ | |
2c0b251b PA |
6312 | static void |
6313 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6314 | { |
6315 | int i = index_to_remove+1; | |
6316 | int last_index = sal->nelts-1; | |
6317 | ||
6318 | for (;i <= last_index; ++i) | |
6319 | sal->sals[i-1] = sal->sals[i]; | |
6320 | ||
6321 | --(sal->nelts); | |
6322 | } | |
6323 | ||
6c95b8df PA |
6324 | /* If appropriate, obtains all sals that correspond to the same file |
6325 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6326 | will want to set a breakpoint at foo.c:line, and not really care | |
6327 | about program spaces. This is done only if SAL does not have | |
6328 | explicit PC and has line and file information. If we got just a | |
6329 | single expanded sal, return the original. | |
ed0616c6 | 6330 | |
6c95b8df PA |
6331 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6332 | which the name of enclosing function is different from SAL. This | |
6333 | makes sure that if we have breakpoint originally set in template | |
6334 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6335 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6336 | |
2c0b251b | 6337 | static struct symtabs_and_lines |
ed0616c6 VP |
6338 | expand_line_sal_maybe (struct symtab_and_line sal) |
6339 | { | |
6340 | struct symtabs_and_lines expanded; | |
6341 | CORE_ADDR original_pc = sal.pc; | |
6342 | char *original_function = NULL; | |
6343 | int found; | |
6344 | int i; | |
6c95b8df | 6345 | struct cleanup *old_chain; |
ed0616c6 VP |
6346 | |
6347 | /* If we have explicit pc, don't expand. | |
6348 | If we have no line number, we can't expand. */ | |
6349 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6350 | { | |
6351 | expanded.nelts = 1; | |
6352 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6353 | expanded.sals[0] = sal; | |
6354 | return expanded; | |
6355 | } | |
6356 | ||
6357 | sal.pc = 0; | |
6c95b8df PA |
6358 | |
6359 | old_chain = save_current_space_and_thread (); | |
6360 | ||
6361 | switch_to_program_space_and_thread (sal.pspace); | |
6362 | ||
ed0616c6 | 6363 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6364 | |
6365 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6366 | expanded = expand_line_sal (sal); |
6c95b8df | 6367 | |
ed0616c6 VP |
6368 | if (expanded.nelts == 1) |
6369 | { | |
3dba1c98 JB |
6370 | /* We had one sal, we got one sal. Return that sal, adjusting it |
6371 | past the function prologue if necessary. */ | |
ed0616c6 VP |
6372 | xfree (expanded.sals); |
6373 | expanded.nelts = 1; | |
6374 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6375 | sal.pc = original_pc; | |
6376 | expanded.sals[0] = sal; | |
3dba1c98 | 6377 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 6378 | do_cleanups (old_chain); |
ed0616c6 VP |
6379 | return expanded; |
6380 | } | |
6381 | ||
6382 | if (!sal.explicit_line) | |
6383 | { | |
6384 | CORE_ADDR func_addr, func_end; | |
6385 | for (i = 0; i < expanded.nelts; ++i) | |
6386 | { | |
6387 | CORE_ADDR pc = expanded.sals[i].pc; | |
6388 | char *this_function; | |
6c95b8df PA |
6389 | |
6390 | /* We need to switch threads as well since we're about to | |
6391 | read memory. */ | |
6392 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6393 | ||
ed0616c6 VP |
6394 | if (find_pc_partial_function (pc, &this_function, |
6395 | &func_addr, &func_end)) | |
6396 | { | |
059fb39f PM |
6397 | if (this_function |
6398 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6399 | { |
6400 | remove_sal (&expanded, i); | |
6401 | --i; | |
6402 | } | |
6403 | else if (func_addr == pc) | |
6404 | { | |
6405 | /* We're at beginning of a function, and should | |
6406 | skip prologue. */ | |
6407 | struct symbol *sym = find_pc_function (pc); | |
6408 | if (sym) | |
6409 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
6410 | else | |
d80b854b UW |
6411 | { |
6412 | /* Since find_pc_partial_function returned true, | |
6413 | we should really always find the section here. */ | |
6414 | struct obj_section *section = find_pc_section (pc); | |
6415 | if (section) | |
6416 | { | |
6417 | struct gdbarch *gdbarch | |
6418 | = get_objfile_arch (section->objfile); | |
6419 | expanded.sals[i].pc | |
6420 | = gdbarch_skip_prologue (gdbarch, pc); | |
6421 | } | |
6422 | } | |
ed0616c6 VP |
6423 | } |
6424 | } | |
6425 | } | |
6426 | } | |
3daf8fe5 JG |
6427 | else |
6428 | { | |
6429 | for (i = 0; i < expanded.nelts; ++i) | |
6430 | { | |
6431 | /* If this SAL corresponds to a breakpoint inserted using a | |
6432 | line number, then skip the function prologue if necessary. */ | |
6433 | skip_prologue_sal (&expanded.sals[i]); | |
6434 | } | |
6435 | } | |
ed0616c6 | 6436 | |
6c95b8df PA |
6437 | do_cleanups (old_chain); |
6438 | ||
ed0616c6 VP |
6439 | if (expanded.nelts <= 1) |
6440 | { | |
6441 | /* This is un ugly workaround. If we get zero | |
6442 | expanded sals then something is really wrong. | |
6443 | Fix that by returnign the original sal. */ | |
6444 | xfree (expanded.sals); | |
6445 | expanded.nelts = 1; | |
6446 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6447 | sal.pc = original_pc; | |
6448 | expanded.sals[0] = sal; | |
6449 | return expanded; | |
6450 | } | |
6451 | ||
6452 | if (original_pc) | |
6453 | { | |
6454 | found = 0; | |
6455 | for (i = 0; i < expanded.nelts; ++i) | |
6456 | if (expanded.sals[i].pc == original_pc) | |
6457 | { | |
6458 | found = 1; | |
6459 | break; | |
6460 | } | |
6461 | gdb_assert (found); | |
6462 | } | |
6463 | ||
6464 | return expanded; | |
6465 | } | |
6466 | ||
018d34a4 VP |
6467 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6468 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6469 | value. COND_STRING, if not NULL, specified the condition to be | |
6470 | used for all breakpoints. Essentially the only case where | |
6471 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6472 | function. In that case, it's still not possible to specify | |
6473 | separate conditions for different overloaded functions, so | |
6474 | we take just a single condition string. | |
6475 | ||
c3f6f71d | 6476 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 6477 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
6478 | array contents). If the function fails (error() is called), the |
6479 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
6480 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
6481 | |
6482 | static void | |
a6d9a66e UW |
6483 | create_breakpoints (struct gdbarch *gdbarch, |
6484 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 6485 | char *cond_string, |
c3f6f71d | 6486 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 6487 | int thread, int task, int ignore_count, |
41447f92 VP |
6488 | struct breakpoint_ops *ops, int from_tty, |
6489 | int enabled) | |
c906108c | 6490 | { |
018d34a4 VP |
6491 | int i; |
6492 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 6493 | { |
ed0616c6 VP |
6494 | struct symtabs_and_lines expanded = |
6495 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 6496 | |
a6d9a66e | 6497 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 6498 | cond_string, type, disposition, |
4a306c9a | 6499 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 6500 | } |
c3f6f71d | 6501 | } |
c906108c | 6502 | |
c3f6f71d JM |
6503 | /* Parse ARG which is assumed to be a SAL specification possibly |
6504 | followed by conditionals. On return, SALS contains an array of SAL | |
6505 | addresses found. ADDR_STRING contains a vector of (canonical) | |
6506 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 6507 | |
b9362cc7 | 6508 | static void |
c3f6f71d JM |
6509 | parse_breakpoint_sals (char **address, |
6510 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
6511 | char ***addr_string, |
6512 | int *not_found_ptr) | |
c3f6f71d JM |
6513 | { |
6514 | char *addr_start = *address; | |
6515 | *addr_string = NULL; | |
6516 | /* If no arg given, or if first arg is 'if ', use the default | |
6517 | breakpoint. */ | |
6518 | if ((*address) == NULL | |
6519 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
6520 | { |
6521 | if (default_breakpoint_valid) | |
6522 | { | |
c3f6f71d | 6523 | struct symtab_and_line sal; |
fe39c653 | 6524 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 6525 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
6526 | xmalloc (sizeof (struct symtab_and_line)); |
6527 | sal.pc = default_breakpoint_address; | |
6528 | sal.line = default_breakpoint_line; | |
6529 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 6530 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 6531 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
6532 | |
6533 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
6534 | the default_breakpoint_address. So make sure to set | |
6535 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
6536 | sals to include all other instances with the same symtab and line. | |
6537 | */ | |
6538 | sal.explicit_pc = 1; | |
6539 | ||
c3f6f71d JM |
6540 | sals->sals[0] = sal; |
6541 | sals->nelts = 1; | |
c906108c SS |
6542 | } |
6543 | else | |
8a3fe4f8 | 6544 | error (_("No default breakpoint address now.")); |
c906108c SS |
6545 | } |
6546 | else | |
6547 | { | |
c906108c | 6548 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
6549 | current_source_symtab (which is decode_line_1's default). This |
6550 | should produce the results we want almost all of the time while | |
1aeae86e AF |
6551 | leaving default_breakpoint_* alone. |
6552 | ObjC: However, don't match an Objective-C method name which | |
6553 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 6554 | |
c214a6fd | 6555 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 6556 | |
c906108c | 6557 | if (default_breakpoint_valid |
0378c332 | 6558 | && (!cursal.symtab |
1aeae86e AF |
6559 | || ((strchr ("+-", (*address)[0]) != NULL) |
6560 | && ((*address)[1] != '[')))) | |
c3f6f71d | 6561 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
6562 | default_breakpoint_line, addr_string, |
6563 | not_found_ptr); | |
c906108c | 6564 | else |
0101ce28 JJ |
6565 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
6566 | addr_string, not_found_ptr); | |
c906108c | 6567 | } |
c3f6f71d JM |
6568 | /* For any SAL that didn't have a canonical string, fill one in. */ |
6569 | if (sals->nelts > 0 && *addr_string == NULL) | |
6570 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
6571 | if (addr_start != (*address)) | |
c906108c | 6572 | { |
c3f6f71d JM |
6573 | int i; |
6574 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 6575 | { |
c3f6f71d JM |
6576 | /* Add the string if not present. */ |
6577 | if ((*addr_string)[i] == NULL) | |
6578 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
6579 | } |
6580 | } | |
c3f6f71d | 6581 | } |
c906108c | 6582 | |
c906108c | 6583 | |
c3f6f71d JM |
6584 | /* Convert each SAL into a real PC. Verify that the PC can be |
6585 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 6586 | |
b9362cc7 | 6587 | static void |
c3f6f71d JM |
6588 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
6589 | char *address) | |
6590 | { | |
6591 | int i; | |
6592 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 6593 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
6594 | } |
6595 | ||
05ff989b | 6596 | static void |
0101ce28 JJ |
6597 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
6598 | { | |
6599 | struct captured_parse_breakpoint_args *args = data; | |
6600 | ||
6601 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
6602 | args->not_found_ptr); | |
0101ce28 JJ |
6603 | } |
6604 | ||
018d34a4 VP |
6605 | /* Given TOK, a string specification of condition and thread, as |
6606 | accepted by the 'break' command, extract the condition | |
6607 | string and thread number and set *COND_STRING and *THREAD. | |
6608 | PC identifies the context at which the condition should be parsed. | |
6609 | If no condition is found, *COND_STRING is set to NULL. | |
6610 | If no thread is found, *THREAD is set to -1. */ | |
6611 | static void | |
6612 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 6613 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
6614 | { |
6615 | *cond_string = NULL; | |
6616 | *thread = -1; | |
6617 | while (tok && *tok) | |
6618 | { | |
6619 | char *end_tok; | |
6620 | int toklen; | |
6621 | char *cond_start = NULL; | |
6622 | char *cond_end = NULL; | |
6623 | while (*tok == ' ' || *tok == '\t') | |
6624 | tok++; | |
6625 | ||
6626 | end_tok = tok; | |
6627 | ||
6628 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6629 | end_tok++; | |
6630 | ||
6631 | toklen = end_tok - tok; | |
6632 | ||
6633 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6634 | { | |
f7545552 TT |
6635 | struct expression *expr; |
6636 | ||
018d34a4 | 6637 | tok = cond_start = end_tok + 1; |
f7545552 TT |
6638 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
6639 | xfree (expr); | |
018d34a4 VP |
6640 | cond_end = tok; |
6641 | *cond_string = savestring (cond_start, | |
6642 | cond_end - cond_start); | |
6643 | } | |
6644 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6645 | { | |
6646 | char *tmptok; | |
6647 | ||
6648 | tok = end_tok + 1; | |
6649 | tmptok = tok; | |
6650 | *thread = strtol (tok, &tok, 0); | |
6651 | if (tok == tmptok) | |
6652 | error (_("Junk after thread keyword.")); | |
6653 | if (!valid_thread_id (*thread)) | |
6654 | error (_("Unknown thread %d."), *thread); | |
6655 | } | |
4a306c9a JB |
6656 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
6657 | { | |
6658 | char *tmptok; | |
6659 | ||
6660 | tok = end_tok + 1; | |
6661 | tmptok = tok; | |
6662 | *task = strtol (tok, &tok, 0); | |
6663 | if (tok == tmptok) | |
6664 | error (_("Junk after task keyword.")); | |
6665 | if (!valid_task_id (*task)) | |
b6199126 | 6666 | error (_("Unknown task %d."), *task); |
4a306c9a | 6667 | } |
018d34a4 VP |
6668 | else |
6669 | error (_("Junk at end of arguments.")); | |
6670 | } | |
6671 | } | |
6672 | ||
72b2ff0e VP |
6673 | /* Set a breakpoint. This function is shared between |
6674 | CLI and MI functions for setting a breakpoint. | |
6675 | This function has two major modes of operations, | |
6676 | selected by the PARSE_CONDITION_AND_THREAD parameter. | |
6677 | If non-zero, the function will parse arg, extracting | |
6678 | breakpoint location, address and thread. Otherwise, | |
6679 | ARG is just the location of breakpoint, with condition | |
6680 | and thread specified by the COND_STRING and THREAD | |
6681 | parameters. */ | |
0101ce28 | 6682 | |
98deb0da | 6683 | static void |
a6d9a66e UW |
6684 | break_command_really (struct gdbarch *gdbarch, |
6685 | char *arg, char *cond_string, int thread, | |
60c46647 | 6686 | int parse_condition_and_thread, |
1042e4c0 | 6687 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
6688 | int ignore_count, |
6689 | enum auto_boolean pending_break_support, | |
604133b5 | 6690 | struct breakpoint_ops *ops, |
41447f92 VP |
6691 | int from_tty, |
6692 | int enabled) | |
c3f6f71d | 6693 | { |
71fff37b | 6694 | struct gdb_exception e; |
c3f6f71d | 6695 | struct symtabs_and_lines sals; |
0101ce28 | 6696 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
6697 | char *copy_arg; |
6698 | char *err_msg; | |
c3f6f71d JM |
6699 | char *addr_start = arg; |
6700 | char **addr_string; | |
6701 | struct cleanup *old_chain; | |
80c99de1 | 6702 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 6703 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 6704 | int i; |
0101ce28 | 6705 | int pending = 0; |
0101ce28 | 6706 | int not_found = 0; |
1042e4c0 | 6707 | enum bptype type_wanted; |
4a306c9a | 6708 | int task = 0; |
c3f6f71d | 6709 | |
c3f6f71d JM |
6710 | sals.sals = NULL; |
6711 | sals.nelts = 0; | |
6712 | addr_string = NULL; | |
c3f6f71d | 6713 | |
0101ce28 JJ |
6714 | parse_args.arg_p = &arg; |
6715 | parse_args.sals_p = &sals; | |
6716 | parse_args.addr_string_p = &addr_string; | |
6717 | parse_args.not_found_ptr = ¬_found; | |
6718 | ||
05ff989b AC |
6719 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
6720 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
6721 | |
6722 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 6723 | switch (e.reason) |
0101ce28 | 6724 | { |
05ff989b | 6725 | case RETURN_QUIT: |
98deb0da | 6726 | throw_exception (e); |
05ff989b AC |
6727 | case RETURN_ERROR: |
6728 | switch (e.error) | |
0101ce28 | 6729 | { |
05ff989b | 6730 | case NOT_FOUND_ERROR: |
0101ce28 | 6731 | |
05ff989b AC |
6732 | /* If pending breakpoint support is turned off, throw |
6733 | error. */ | |
fa8d40ab JJ |
6734 | |
6735 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
6736 | throw_exception (e); |
6737 | ||
6738 | exception_print (gdb_stderr, e); | |
fa8d40ab | 6739 | |
05ff989b AC |
6740 | /* If pending breakpoint support is auto query and the user |
6741 | selects no, then simply return the error code. */ | |
059fb39f PM |
6742 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
6743 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
98deb0da | 6744 | return; |
fa8d40ab | 6745 | |
05ff989b AC |
6746 | /* At this point, either the user was queried about setting |
6747 | a pending breakpoint and selected yes, or pending | |
6748 | breakpoint behavior is on and thus a pending breakpoint | |
6749 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
6750 | copy_arg = xstrdup (addr_start); |
6751 | addr_string = ©_arg; | |
6752 | sals.nelts = 1; | |
6753 | sals.sals = &pending_sal; | |
6754 | pending_sal.pc = 0; | |
6755 | pending = 1; | |
05ff989b AC |
6756 | break; |
6757 | default: | |
98deb0da | 6758 | throw_exception (e); |
0101ce28 | 6759 | } |
05ff989b AC |
6760 | default: |
6761 | if (!sals.nelts) | |
98deb0da | 6762 | return; |
0101ce28 | 6763 | } |
c3f6f71d JM |
6764 | |
6765 | /* Create a chain of things that always need to be cleaned up. */ | |
6766 | old_chain = make_cleanup (null_cleanup, 0); | |
6767 | ||
0101ce28 JJ |
6768 | if (!pending) |
6769 | { | |
6770 | /* Make sure that all storage allocated to SALS gets freed. */ | |
6771 | make_cleanup (xfree, sals.sals); | |
6772 | ||
6773 | /* Cleanup the addr_string array but not its contents. */ | |
6774 | make_cleanup (xfree, addr_string); | |
6775 | } | |
c3f6f71d | 6776 | |
c3f6f71d JM |
6777 | /* ----------------------------- SNIP ----------------------------- |
6778 | Anything added to the cleanup chain beyond this point is assumed | |
6779 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
6780 | then the memory is not reclaimed. */ |
6781 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
6782 | |
6783 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 6784 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
6785 | for (i = 0; i < sals.nelts; i++) |
6786 | { | |
6787 | if (addr_string[i] != NULL) | |
b8c9b27d | 6788 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
6789 | } |
6790 | ||
6791 | /* Resolve all line numbers to PC's and verify that the addresses | |
6792 | are ok for the target. */ | |
0101ce28 JJ |
6793 | if (!pending) |
6794 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 6795 | |
1042e4c0 SS |
6796 | type_wanted = (traceflag |
6797 | ? bp_tracepoint | |
6798 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); | |
6799 | ||
c3f6f71d JM |
6800 | /* Verify that condition can be parsed, before setting any |
6801 | breakpoints. Allocate a separate condition expression for each | |
6802 | breakpoint. */ | |
0101ce28 | 6803 | if (!pending) |
c3f6f71d | 6804 | { |
2f069f6f | 6805 | if (parse_condition_and_thread) |
72b2ff0e VP |
6806 | { |
6807 | /* Here we only parse 'arg' to separate condition | |
6808 | from thread number, so parsing in context of first | |
6809 | sal is OK. When setting the breakpoint we'll | |
6810 | re-parse it in context of each sal. */ | |
6811 | cond_string = NULL; | |
6812 | thread = -1; | |
4a306c9a JB |
6813 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
6814 | &thread, &task); | |
72b2ff0e VP |
6815 | if (cond_string) |
6816 | make_cleanup (xfree, cond_string); | |
6817 | } | |
2f069f6f | 6818 | else |
72b2ff0e VP |
6819 | { |
6820 | /* Create a private copy of condition string. */ | |
6821 | if (cond_string) | |
6822 | { | |
6823 | cond_string = xstrdup (cond_string); | |
6824 | make_cleanup (xfree, cond_string); | |
6825 | } | |
6826 | } | |
a6d9a66e | 6827 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 6828 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 6829 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 6830 | } |
0101ce28 JJ |
6831 | else |
6832 | { | |
fe3f5fa8 | 6833 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
6834 | struct breakpoint *b; |
6835 | ||
0101ce28 JJ |
6836 | make_cleanup (xfree, copy_arg); |
6837 | ||
a6d9a66e | 6838 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
6839 | set_breakpoint_count (breakpoint_count + 1); |
6840 | b->number = breakpoint_count; | |
72b2ff0e | 6841 | b->thread = -1; |
018d34a4 | 6842 | b->addr_string = addr_string[0]; |
72b2ff0e | 6843 | b->cond_string = NULL; |
0101ce28 | 6844 | b->ignore_count = ignore_count; |
0101ce28 | 6845 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 6846 | b->condition_not_parsed = 1; |
604133b5 | 6847 | b->ops = ops; |
41447f92 | 6848 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 6849 | b->pspace = current_program_space; |
74960c60 | 6850 | |
6c95b8df | 6851 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
6852 | && (b->type == bp_breakpoint |
6853 | || b->type == bp_hardware_breakpoint)) | |
6854 | b->enable_state = bp_startup_disabled; | |
6855 | ||
0101ce28 JJ |
6856 | mention (b); |
6857 | } | |
6858 | ||
c3f6f71d | 6859 | if (sals.nelts > 1) |
8a3fe4f8 AC |
6860 | warning (_("Multiple breakpoints were set.\n" |
6861 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
6862 | /* That's it. Discard the cleanups for data inserted into the |
6863 | breakpoint. */ | |
6864 | discard_cleanups (bkpt_chain); | |
6865 | /* But cleanup everything else. */ | |
c3f6f71d | 6866 | do_cleanups (old_chain); |
217dc9e2 | 6867 | |
80c99de1 | 6868 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 6869 | update_global_location_list (1); |
c3f6f71d | 6870 | } |
c906108c | 6871 | |
72b2ff0e VP |
6872 | /* Set a breakpoint. |
6873 | ARG is a string describing breakpoint address, | |
6874 | condition, and thread. | |
6875 | FLAG specifies if a breakpoint is hardware on, | |
6876 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
6877 | and BP_TEMPFLAG. */ | |
6878 | ||
98deb0da | 6879 | static void |
72b2ff0e | 6880 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 6881 | { |
72b2ff0e VP |
6882 | int hardwareflag = flag & BP_HARDWAREFLAG; |
6883 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 6884 | |
a6d9a66e UW |
6885 | break_command_really (get_current_arch (), |
6886 | arg, | |
98deb0da | 6887 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 6888 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 6889 | 0 /* Ignore count */, |
604133b5 AR |
6890 | pending_break_support, |
6891 | NULL /* breakpoint_ops */, | |
41447f92 VP |
6892 | from_tty, |
6893 | 1 /* enabled */); | |
c906108c SS |
6894 | } |
6895 | ||
72b2ff0e | 6896 | |
98deb0da | 6897 | void |
a6d9a66e UW |
6898 | set_breakpoint (struct gdbarch *gdbarch, |
6899 | char *address, char *condition, | |
c3f6f71d | 6900 | int hardwareflag, int tempflag, |
ce43223b | 6901 | int thread, int ignore_count, |
41447f92 | 6902 | int pending, int enabled) |
c3f6f71d | 6903 | { |
a6d9a66e UW |
6904 | break_command_really (gdbarch, |
6905 | address, condition, thread, | |
98deb0da | 6906 | 0 /* condition and thread are valid. */, |
1042e4c0 | 6907 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
6908 | ignore_count, |
6909 | pending | |
6910 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 6911 | NULL, 0, enabled); |
c3f6f71d JM |
6912 | } |
6913 | ||
6a048695 JB |
6914 | /* Adjust SAL to the first instruction past the function prologue. |
6915 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
6916 | the debugging information. explicit_pc and explicit_line are |
6917 | not modified. | |
6a048695 JB |
6918 | |
6919 | If SAL is already past the prologue, then do nothing. */ | |
6920 | ||
6921 | static void | |
6922 | skip_prologue_sal (struct symtab_and_line *sal) | |
6923 | { | |
6c95b8df | 6924 | struct symbol *sym; |
6a048695 | 6925 | struct symtab_and_line start_sal; |
6c95b8df | 6926 | struct cleanup *old_chain; |
6a048695 | 6927 | |
6c95b8df | 6928 | old_chain = save_current_space_and_thread (); |
6a048695 | 6929 | |
6c95b8df PA |
6930 | sym = find_pc_function (sal->pc); |
6931 | if (sym != NULL) | |
3daf8fe5 | 6932 | { |
6c95b8df PA |
6933 | start_sal = find_function_start_sal (sym, 1); |
6934 | if (sal->pc < start_sal.pc) | |
6935 | { | |
6936 | start_sal.explicit_line = sal->explicit_line; | |
6937 | start_sal.explicit_pc = sal->explicit_pc; | |
6938 | *sal = start_sal; | |
6939 | } | |
3daf8fe5 | 6940 | } |
6c95b8df PA |
6941 | |
6942 | do_cleanups (old_chain); | |
6a048695 | 6943 | } |
c3f6f71d | 6944 | |
c906108c SS |
6945 | /* Helper function for break_command_1 and disassemble_command. */ |
6946 | ||
6947 | void | |
fba45db2 | 6948 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
6949 | { |
6950 | CORE_ADDR pc; | |
6951 | ||
6952 | if (sal->pc == 0 && sal->symtab != NULL) | |
6953 | { | |
6954 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 6955 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
6956 | sal->line, sal->symtab->filename); |
6957 | sal->pc = pc; | |
6a048695 JB |
6958 | |
6959 | /* If this SAL corresponds to a breakpoint inserted using | |
6960 | a line number, then skip the function prologue if necessary. */ | |
6961 | if (sal->explicit_line) | |
56ef84b1 TT |
6962 | { |
6963 | /* Preserve the original line number. */ | |
6964 | int saved_line = sal->line; | |
6965 | skip_prologue_sal (sal); | |
6966 | sal->line = saved_line; | |
6967 | } | |
c906108c SS |
6968 | } |
6969 | ||
6970 | if (sal->section == 0 && sal->symtab != NULL) | |
6971 | { | |
6972 | struct blockvector *bv; | |
c5aa993b JM |
6973 | struct block *b; |
6974 | struct symbol *sym; | |
c906108c | 6975 | |
801e3a5b | 6976 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
6977 | if (bv != NULL) |
6978 | { | |
7f0df278 | 6979 | sym = block_linkage_function (b); |
c906108c SS |
6980 | if (sym != NULL) |
6981 | { | |
6982 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 6983 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
6984 | } |
6985 | else | |
6986 | { | |
6987 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
6988 | have to look harder. This case can be executed if we have |
6989 | line numbers but no functions (as can happen in assembly | |
6990 | source). */ | |
c906108c | 6991 | |
c5aa993b | 6992 | struct minimal_symbol *msym; |
6c95b8df PA |
6993 | struct cleanup *old_chain = save_current_space_and_thread (); |
6994 | ||
6995 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
6996 | |
6997 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
6998 | if (msym) | |
714835d5 | 6999 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7000 | |
7001 | do_cleanups (old_chain); | |
c906108c SS |
7002 | } |
7003 | } | |
7004 | } | |
7005 | } | |
7006 | ||
7007 | void | |
fba45db2 | 7008 | break_command (char *arg, int from_tty) |
c906108c | 7009 | { |
db107f19 | 7010 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7011 | } |
7012 | ||
c906108c | 7013 | void |
fba45db2 | 7014 | tbreak_command (char *arg, int from_tty) |
c906108c | 7015 | { |
db107f19 | 7016 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7017 | } |
7018 | ||
c906108c | 7019 | static void |
fba45db2 | 7020 | hbreak_command (char *arg, int from_tty) |
c906108c | 7021 | { |
db107f19 | 7022 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7023 | } |
7024 | ||
7025 | static void | |
fba45db2 | 7026 | thbreak_command (char *arg, int from_tty) |
c906108c | 7027 | { |
db107f19 | 7028 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7029 | } |
7030 | ||
7031 | static void | |
fba45db2 | 7032 | stop_command (char *arg, int from_tty) |
c906108c | 7033 | { |
a3f17187 | 7034 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7035 | Usage: stop in <function | address>\n\ |
a3f17187 | 7036 | stop at <line>\n")); |
c906108c SS |
7037 | } |
7038 | ||
7039 | static void | |
fba45db2 | 7040 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7041 | { |
7042 | int badInput = 0; | |
7043 | ||
c5aa993b | 7044 | if (arg == (char *) NULL) |
c906108c SS |
7045 | badInput = 1; |
7046 | else if (*arg != '*') | |
7047 | { | |
7048 | char *argptr = arg; | |
7049 | int hasColon = 0; | |
7050 | ||
53a5351d JM |
7051 | /* look for a ':'. If this is a line number specification, then |
7052 | say it is bad, otherwise, it should be an address or | |
7053 | function/method name */ | |
c906108c | 7054 | while (*argptr && !hasColon) |
c5aa993b JM |
7055 | { |
7056 | hasColon = (*argptr == ':'); | |
7057 | argptr++; | |
7058 | } | |
c906108c SS |
7059 | |
7060 | if (hasColon) | |
c5aa993b | 7061 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7062 | else |
c5aa993b | 7063 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7064 | } |
7065 | ||
7066 | if (badInput) | |
a3f17187 | 7067 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7068 | else |
db107f19 | 7069 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7070 | } |
7071 | ||
7072 | static void | |
fba45db2 | 7073 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7074 | { |
7075 | int badInput = 0; | |
7076 | ||
c5aa993b | 7077 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7078 | badInput = 1; |
7079 | else | |
7080 | { | |
7081 | char *argptr = arg; | |
7082 | int hasColon = 0; | |
7083 | ||
7084 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7085 | it is probably a line number. */ |
c906108c | 7086 | while (*argptr && !hasColon) |
c5aa993b JM |
7087 | { |
7088 | hasColon = (*argptr == ':'); | |
7089 | argptr++; | |
7090 | } | |
c906108c SS |
7091 | |
7092 | if (hasColon) | |
c5aa993b | 7093 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7094 | else |
c5aa993b | 7095 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7096 | } |
7097 | ||
7098 | if (badInput) | |
a3f17187 | 7099 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7100 | else |
db107f19 | 7101 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7102 | } |
7103 | ||
53a5351d JM |
7104 | /* accessflag: hw_write: watch write, |
7105 | hw_read: watch read, | |
7106 | hw_access: watch access (read or write) */ | |
c906108c | 7107 | static void |
fba45db2 | 7108 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 7109 | { |
a6d9a66e | 7110 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 7111 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
7112 | struct expression *exp; |
7113 | struct block *exp_valid_block; | |
7114 | struct value *val, *mark; | |
7115 | struct frame_info *frame; | |
c906108c SS |
7116 | char *exp_start = NULL; |
7117 | char *exp_end = NULL; | |
37e4754d | 7118 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
7119 | int toklen; |
7120 | char *cond_start = NULL; | |
7121 | char *cond_end = NULL; | |
c906108c SS |
7122 | int i, other_type_used, target_resources_ok = 0; |
7123 | enum bptype bp_type; | |
7124 | int mem_cnt = 0; | |
37e4754d | 7125 | int thread = -1; |
c906108c | 7126 | |
37e4754d LM |
7127 | /* Make sure that we actually have parameters to parse. */ |
7128 | if (arg != NULL && arg[0] != '\0') | |
7129 | { | |
7130 | toklen = strlen (arg); /* Size of argument list. */ | |
7131 | ||
7132 | /* Points tok to the end of the argument list. */ | |
7133 | tok = arg + toklen - 1; | |
7134 | ||
7135 | /* Go backwards in the parameters list. Skip the last parameter. | |
7136 | If we're expecting a 'thread <thread_num>' parameter, this should | |
7137 | be the thread identifier. */ | |
7138 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7139 | tok--; | |
7140 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7141 | tok--; | |
7142 | ||
7143 | /* Points end_tok to the beginning of the last token. */ | |
7144 | id_tok_start = tok + 1; | |
7145 | ||
7146 | /* Go backwards in the parameters list. Skip one more parameter. | |
7147 | If we're expecting a 'thread <thread_num>' parameter, we should | |
7148 | reach a "thread" token. */ | |
7149 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7150 | tok--; | |
7151 | ||
7152 | end_tok = tok; | |
7153 | ||
7154 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7155 | tok--; | |
7156 | ||
7157 | /* Move the pointer forward to skip the whitespace and | |
7158 | calculate the length of the token. */ | |
7159 | tok++; | |
7160 | toklen = end_tok - tok; | |
7161 | ||
7162 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7163 | { | |
7164 | /* At this point we've found a "thread" token, which means | |
7165 | the user is trying to set a watchpoint that triggers | |
7166 | only in a specific thread. */ | |
7167 | char *endp; | |
7168 | ||
7169 | /* Extract the thread ID from the next token. */ | |
7170 | thread = strtol (id_tok_start, &endp, 0); | |
7171 | ||
7172 | /* Check if the user provided a valid numeric value for the | |
7173 | thread ID. */ | |
7174 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7175 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7176 | ||
7177 | /* Check if the thread actually exists. */ | |
7178 | if (!valid_thread_id (thread)) | |
7179 | error (_("Unknown thread %d."), thread); | |
7180 | ||
7181 | /* Truncate the string and get rid of the thread <thread_num> | |
7182 | parameter before the parameter list is parsed by the | |
7183 | evaluate_expression() function. */ | |
7184 | *tok = '\0'; | |
7185 | } | |
7186 | } | |
7187 | ||
7188 | /* Parse the rest of the arguments. */ | |
c906108c SS |
7189 | innermost_block = NULL; |
7190 | exp_start = arg; | |
7191 | exp = parse_exp_1 (&arg, 0, 0); | |
7192 | exp_end = arg; | |
fa8a61dc TT |
7193 | /* Remove trailing whitespace from the expression before saving it. |
7194 | This makes the eventual display of the expression string a bit | |
7195 | prettier. */ | |
7196 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7197 | --exp_end; | |
7198 | ||
c906108c SS |
7199 | exp_valid_block = innermost_block; |
7200 | mark = value_mark (); | |
fa4727a6 DJ |
7201 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7202 | if (val != NULL) | |
7203 | release_value (val); | |
c906108c SS |
7204 | |
7205 | tok = arg; | |
7206 | while (*tok == ' ' || *tok == '\t') | |
7207 | tok++; | |
7208 | end_tok = tok; | |
7209 | ||
7210 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7211 | end_tok++; | |
7212 | ||
7213 | toklen = end_tok - tok; | |
7214 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7215 | { | |
2d134ed3 PA |
7216 | struct expression *cond; |
7217 | ||
c906108c SS |
7218 | tok = cond_start = end_tok + 1; |
7219 | cond = parse_exp_1 (&tok, 0, 0); | |
2d134ed3 | 7220 | xfree (cond); |
c906108c SS |
7221 | cond_end = tok; |
7222 | } | |
7223 | if (*tok) | |
8a3fe4f8 | 7224 | error (_("Junk at end of command.")); |
c906108c | 7225 | |
53a5351d | 7226 | if (accessflag == hw_read) |
c5aa993b | 7227 | bp_type = bp_read_watchpoint; |
53a5351d | 7228 | else if (accessflag == hw_access) |
c5aa993b JM |
7229 | bp_type = bp_access_watchpoint; |
7230 | else | |
7231 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7232 | |
7233 | mem_cnt = can_use_hardware_watchpoint (val); | |
7234 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7235 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7236 | if (mem_cnt != 0) |
7237 | { | |
7238 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7239 | target_resources_ok = |
d92524f1 | 7240 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7241 | other_type_used); |
c5aa993b | 7242 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7243 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7244 | |
c5aa993b | 7245 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7246 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7247 | } |
c906108c | 7248 | |
4d28f7a8 KB |
7249 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7250 | watchpoint could not be set. */ | |
7251 | if (!mem_cnt || target_resources_ok <= 0) | |
7252 | bp_type = bp_watchpoint; | |
7253 | ||
d983da9c | 7254 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7255 | |
7256 | /* If the expression is "local", then set up a "watchpoint scope" | |
7257 | breakpoint at the point where we've left the scope of the watchpoint | |
7258 | expression. Create the scope breakpoint before the watchpoint, so | |
7259 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 7260 | if (innermost_block && frame) |
d983da9c | 7261 | { |
edb3359d DJ |
7262 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7263 | { | |
7264 | scope_breakpoint | |
a6d9a66e UW |
7265 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7266 | frame_unwind_caller_pc (frame), | |
edb3359d | 7267 | bp_watchpoint_scope); |
d983da9c | 7268 | |
edb3359d | 7269 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7270 | |
edb3359d DJ |
7271 | /* Automatically delete the breakpoint when it hits. */ |
7272 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7273 | |
edb3359d DJ |
7274 | /* Only break in the proper frame (help with recursion). */ |
7275 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7276 | |
edb3359d | 7277 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7278 | scope_breakpoint->loc->gdbarch |
7279 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7280 | scope_breakpoint->loc->requested_address |
7281 | = frame_unwind_caller_pc (frame); | |
7282 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7283 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7284 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7285 | scope_breakpoint->type); |
7286 | } | |
d983da9c DJ |
7287 | } |
7288 | ||
c906108c | 7289 | /* Now set up the breakpoint. */ |
2d134ed3 | 7290 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
7291 | set_breakpoint_count (breakpoint_count + 1); |
7292 | b->number = breakpoint_count; | |
37e4754d | 7293 | b->thread = thread; |
b5de0fa7 | 7294 | b->disposition = disp_donttouch; |
c906108c SS |
7295 | b->exp = exp; |
7296 | b->exp_valid_block = exp_valid_block; | |
7297 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
7298 | b->val = val; | |
fa4727a6 | 7299 | b->val_valid = 1; |
c906108c SS |
7300 | if (cond_start) |
7301 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7302 | else | |
7303 | b->cond_string = 0; | |
c5aa993b | 7304 | |
c906108c | 7305 | if (frame) |
f6bc2008 PA |
7306 | { |
7307 | b->watchpoint_frame = get_frame_id (frame); | |
7308 | b->watchpoint_thread = inferior_ptid; | |
7309 | } | |
c906108c | 7310 | else |
f6bc2008 PA |
7311 | { |
7312 | b->watchpoint_frame = null_frame_id; | |
7313 | b->watchpoint_thread = null_ptid; | |
7314 | } | |
c906108c | 7315 | |
d983da9c | 7316 | if (scope_breakpoint != NULL) |
c906108c | 7317 | { |
d983da9c DJ |
7318 | /* The scope breakpoint is related to the watchpoint. We will |
7319 | need to act on them together. */ | |
7320 | b->related_breakpoint = scope_breakpoint; | |
7321 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7322 | } |
d983da9c | 7323 | |
c906108c | 7324 | value_free_to_mark (mark); |
2d134ed3 PA |
7325 | |
7326 | /* Finally update the new watchpoint. This creates the locations | |
7327 | that should be inserted. */ | |
7328 | update_watchpoint (b, 1); | |
7329 | ||
c906108c | 7330 | mention (b); |
b60e7edf | 7331 | update_global_location_list (1); |
c906108c SS |
7332 | } |
7333 | ||
7334 | /* Return count of locations need to be watched and can be handled | |
7335 | in hardware. If the watchpoint can not be handled | |
7336 | in hardware return zero. */ | |
7337 | ||
c906108c | 7338 | static int |
fba45db2 | 7339 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7340 | { |
7341 | int found_memory_cnt = 0; | |
2e70b7b9 | 7342 | struct value *head = v; |
c906108c SS |
7343 | |
7344 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7345 | if (!can_use_hw_watchpoints) |
c906108c | 7346 | return 0; |
c5aa993b | 7347 | |
5c44784c JM |
7348 | /* Make sure that the value of the expression depends only upon |
7349 | memory contents, and values computed from them within GDB. If we | |
7350 | find any register references or function calls, we can't use a | |
7351 | hardware watchpoint. | |
7352 | ||
7353 | The idea here is that evaluating an expression generates a series | |
7354 | of values, one holding the value of every subexpression. (The | |
7355 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7356 | a*b+c.) GDB's values hold almost enough information to establish | |
7357 | the criteria given above --- they identify memory lvalues, | |
7358 | register lvalues, computed values, etcetera. So we can evaluate | |
7359 | the expression, and then scan the chain of values that leaves | |
7360 | behind to decide whether we can detect any possible change to the | |
7361 | expression's final value using only hardware watchpoints. | |
7362 | ||
7363 | However, I don't think that the values returned by inferior | |
7364 | function calls are special in any way. So this function may not | |
7365 | notice that an expression involving an inferior function call | |
7366 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7367 | for (; v; v = value_next (v)) |
c906108c | 7368 | { |
5c44784c | 7369 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7370 | { |
d69fe07e | 7371 | if (value_lazy (v)) |
5c44784c JM |
7372 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7373 | we either just used its address (e.g., `a' in `a.b') or | |
7374 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7375 | ; | |
53a5351d | 7376 | else |
5c44784c JM |
7377 | { |
7378 | /* Ahh, memory we actually used! Check if we can cover | |
7379 | it with hardware watchpoints. */ | |
df407dfe | 7380 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7381 | |
7382 | /* We only watch structs and arrays if user asked for it | |
7383 | explicitly, never if they just happen to appear in a | |
7384 | middle of some value chain. */ | |
7385 | if (v == head | |
7386 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7387 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7388 | { | |
42ae5230 | 7389 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7390 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7391 | |
d92524f1 | 7392 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7393 | return 0; |
7394 | else | |
7395 | found_memory_cnt++; | |
7396 | } | |
5c44784c | 7397 | } |
c5aa993b | 7398 | } |
5086187c AC |
7399 | else if (VALUE_LVAL (v) != not_lval |
7400 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7401 | return 0; /* ??? What does this represent? */ |
5086187c | 7402 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7403 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7404 | } |
7405 | ||
7406 | /* The expression itself looks suitable for using a hardware | |
7407 | watchpoint, but give the target machine a chance to reject it. */ | |
7408 | return found_memory_cnt; | |
7409 | } | |
7410 | ||
8b93c638 | 7411 | void |
fba45db2 | 7412 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7413 | { |
7414 | watch_command (arg, from_tty); | |
7415 | } | |
8926118c | 7416 | |
c5aa993b | 7417 | static void |
fba45db2 | 7418 | watch_command (char *arg, int from_tty) |
c906108c | 7419 | { |
53a5351d | 7420 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7421 | } |
7422 | ||
8b93c638 | 7423 | void |
fba45db2 | 7424 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7425 | { |
7426 | rwatch_command (arg, from_tty); | |
7427 | } | |
8926118c | 7428 | |
c5aa993b | 7429 | static void |
fba45db2 | 7430 | rwatch_command (char *arg, int from_tty) |
c906108c | 7431 | { |
53a5351d | 7432 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7433 | } |
7434 | ||
8b93c638 | 7435 | void |
fba45db2 | 7436 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7437 | { |
7438 | awatch_command (arg, from_tty); | |
7439 | } | |
8926118c | 7440 | |
c5aa993b | 7441 | static void |
fba45db2 | 7442 | awatch_command (char *arg, int from_tty) |
c906108c | 7443 | { |
53a5351d | 7444 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7445 | } |
c906108c | 7446 | \f |
c5aa993b | 7447 | |
43ff13b4 | 7448 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7449 | because it uses the mechanisms of breakpoints. */ |
7450 | ||
bfec99b2 PA |
7451 | struct until_break_command_continuation_args |
7452 | { | |
7453 | struct breakpoint *breakpoint; | |
7454 | struct breakpoint *breakpoint2; | |
7455 | }; | |
7456 | ||
43ff13b4 JM |
7457 | /* This function is called by fetch_inferior_event via the |
7458 | cmd_continuation pointer, to complete the until command. It takes | |
7459 | care of cleaning up the temporary breakpoints set up by the until | |
7460 | command. */ | |
c2c6d25f | 7461 | static void |
604ead4a | 7462 | until_break_command_continuation (void *arg) |
43ff13b4 | 7463 | { |
bfec99b2 PA |
7464 | struct until_break_command_continuation_args *a = arg; |
7465 | ||
7466 | delete_breakpoint (a->breakpoint); | |
7467 | if (a->breakpoint2) | |
7468 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
7469 | } |
7470 | ||
c906108c | 7471 | void |
ae66c1fc | 7472 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
7473 | { |
7474 | struct symtabs_and_lines sals; | |
7475 | struct symtab_and_line sal; | |
206415a3 | 7476 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 7477 | struct breakpoint *breakpoint; |
f107f563 | 7478 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
7479 | struct cleanup *old_chain; |
7480 | ||
7481 | clear_proceed_status (); | |
7482 | ||
7483 | /* Set a breakpoint where the user wants it and at return from | |
7484 | this function */ | |
c5aa993b | 7485 | |
c906108c SS |
7486 | if (default_breakpoint_valid) |
7487 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 7488 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 7489 | else |
53a5351d | 7490 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 7491 | 0, (char ***) NULL, NULL); |
c5aa993b | 7492 | |
c906108c | 7493 | if (sals.nelts != 1) |
8a3fe4f8 | 7494 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 7495 | |
c906108c | 7496 | sal = sals.sals[0]; |
b8c9b27d | 7497 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 7498 | |
c906108c | 7499 | if (*arg) |
8a3fe4f8 | 7500 | error (_("Junk at end of arguments.")); |
c5aa993b | 7501 | |
c906108c | 7502 | resolve_sal_pc (&sal); |
c5aa993b | 7503 | |
ae66c1fc EZ |
7504 | if (anywhere) |
7505 | /* If the user told us to continue until a specified location, | |
7506 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
7507 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7508 | null_frame_id, bp_until); | |
ae66c1fc | 7509 | else |
edb3359d | 7510 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 7511 | at the very same frame. */ |
a6d9a66e UW |
7512 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7513 | get_stack_frame_id (frame), | |
ae66c1fc | 7514 | bp_until); |
c5aa993b | 7515 | |
f107f563 | 7516 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 7517 | |
ae66c1fc EZ |
7518 | /* Keep within the current frame, or in frames called by the current |
7519 | one. */ | |
edb3359d DJ |
7520 | |
7521 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 7522 | { |
edb3359d DJ |
7523 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
7524 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
7525 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
7526 | sal, | |
edb3359d | 7527 | frame_unwind_caller_id (frame), |
f107f563 VP |
7528 | bp_until); |
7529 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 7530 | } |
c5aa993b | 7531 | |
c906108c | 7532 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
7533 | |
7534 | /* If we are running asynchronously, and proceed call above has actually | |
7535 | managed to start the target, arrange for breakpoints to be | |
7536 | deleted when the target stops. Otherwise, we're already stopped and | |
7537 | delete breakpoints via cleanup chain. */ | |
7538 | ||
8ea051c5 | 7539 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 7540 | { |
bfec99b2 PA |
7541 | struct until_break_command_continuation_args *args; |
7542 | args = xmalloc (sizeof (*args)); | |
f107f563 | 7543 | |
bfec99b2 PA |
7544 | args->breakpoint = breakpoint; |
7545 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
7546 | |
7547 | discard_cleanups (old_chain); | |
95e54da7 PA |
7548 | add_continuation (inferior_thread (), |
7549 | until_break_command_continuation, args, | |
604ead4a | 7550 | xfree); |
f107f563 VP |
7551 | } |
7552 | else | |
c5aa993b | 7553 | do_cleanups (old_chain); |
c906108c | 7554 | } |
ae66c1fc | 7555 | |
c906108c | 7556 | static void |
fba45db2 | 7557 | ep_skip_leading_whitespace (char **s) |
c906108c | 7558 | { |
c5aa993b JM |
7559 | if ((s == NULL) || (*s == NULL)) |
7560 | return; | |
7561 | while (isspace (**s)) | |
7562 | *s += 1; | |
c906108c | 7563 | } |
c5aa993b | 7564 | |
c906108c SS |
7565 | /* This function attempts to parse an optional "if <cond>" clause |
7566 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 7567 | |
c906108c SS |
7568 | Else, it returns a pointer to the condition string. (It does not |
7569 | attempt to evaluate the string against a particular block.) And, | |
7570 | it updates arg to point to the first character following the parsed | |
7571 | if clause in the arg string. */ | |
53a5351d | 7572 | |
c906108c | 7573 | static char * |
fba45db2 | 7574 | ep_parse_optional_if_clause (char **arg) |
c906108c | 7575 | { |
c5aa993b JM |
7576 | char *cond_string; |
7577 | ||
7578 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 7579 | return NULL; |
c5aa993b | 7580 | |
c906108c SS |
7581 | /* Skip the "if" keyword. */ |
7582 | (*arg) += 2; | |
c5aa993b | 7583 | |
c906108c SS |
7584 | /* Skip any extra leading whitespace, and record the start of the |
7585 | condition string. */ | |
7586 | ep_skip_leading_whitespace (arg); | |
7587 | cond_string = *arg; | |
c5aa993b | 7588 | |
c906108c SS |
7589 | /* Assume that the condition occupies the remainder of the arg string. */ |
7590 | (*arg) += strlen (cond_string); | |
c5aa993b | 7591 | |
c906108c SS |
7592 | return cond_string; |
7593 | } | |
c5aa993b | 7594 | |
c906108c SS |
7595 | /* This function attempts to parse an optional filename from the arg |
7596 | string. If one is not found, it returns NULL. | |
c5aa993b | 7597 | |
c906108c SS |
7598 | Else, it returns a pointer to the parsed filename. (This function |
7599 | makes no attempt to verify that a file of that name exists, or is | |
7600 | accessible.) And, it updates arg to point to the first character | |
7601 | following the parsed filename in the arg string. | |
c5aa993b | 7602 | |
c906108c SS |
7603 | Note that clients needing to preserve the returned filename for |
7604 | future access should copy it to their own buffers. */ | |
7605 | static char * | |
fba45db2 | 7606 | ep_parse_optional_filename (char **arg) |
c906108c | 7607 | { |
c5aa993b JM |
7608 | static char filename[1024]; |
7609 | char *arg_p = *arg; | |
7610 | int i; | |
7611 | char c; | |
7612 | ||
c906108c SS |
7613 | if ((*arg_p == '\0') || isspace (*arg_p)) |
7614 | return NULL; | |
c5aa993b JM |
7615 | |
7616 | for (i = 0;; i++) | |
c906108c SS |
7617 | { |
7618 | c = *arg_p; | |
7619 | if (isspace (c)) | |
c5aa993b | 7620 | c = '\0'; |
c906108c SS |
7621 | filename[i] = c; |
7622 | if (c == '\0') | |
c5aa993b | 7623 | break; |
c906108c SS |
7624 | arg_p++; |
7625 | } | |
7626 | *arg = arg_p; | |
c5aa993b | 7627 | |
c906108c SS |
7628 | return filename; |
7629 | } | |
c5aa993b | 7630 | |
c906108c SS |
7631 | /* Commands to deal with catching events, such as signals, exceptions, |
7632 | process start/exit, etc. */ | |
c5aa993b JM |
7633 | |
7634 | typedef enum | |
7635 | { | |
44feb3ce TT |
7636 | catch_fork_temporary, catch_vfork_temporary, |
7637 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
7638 | } |
7639 | catch_fork_kind; | |
7640 | ||
c906108c | 7641 | static void |
44feb3ce | 7642 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7643 | { |
a6d9a66e | 7644 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 7645 | char *cond_string = NULL; |
44feb3ce TT |
7646 | catch_fork_kind fork_kind; |
7647 | int tempflag; | |
7648 | ||
7649 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
7650 | tempflag = (fork_kind == catch_fork_temporary | |
7651 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 7652 | |
44feb3ce TT |
7653 | if (!arg) |
7654 | arg = ""; | |
c906108c | 7655 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7656 | |
c906108c | 7657 | /* The allowed syntax is: |
c5aa993b JM |
7658 | catch [v]fork |
7659 | catch [v]fork if <cond> | |
7660 | ||
c906108c SS |
7661 | First, check if there's an if clause. */ |
7662 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 7663 | |
c906108c | 7664 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 7665 | error (_("Junk at end of arguments.")); |
c5aa993b | 7666 | |
c906108c SS |
7667 | /* If this target supports it, create a fork or vfork catchpoint |
7668 | and enable reporting of such events. */ | |
c5aa993b JM |
7669 | switch (fork_kind) |
7670 | { | |
44feb3ce TT |
7671 | case catch_fork_temporary: |
7672 | case catch_fork_permanent: | |
a6d9a66e | 7673 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7674 | &catch_fork_breakpoint_ops); |
c906108c | 7675 | break; |
44feb3ce TT |
7676 | case catch_vfork_temporary: |
7677 | case catch_vfork_permanent: | |
a6d9a66e | 7678 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7679 | &catch_vfork_breakpoint_ops); |
c906108c | 7680 | break; |
c5aa993b | 7681 | default: |
8a3fe4f8 | 7682 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 7683 | break; |
c5aa993b | 7684 | } |
c906108c SS |
7685 | } |
7686 | ||
7687 | static void | |
44feb3ce | 7688 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7689 | { |
a6d9a66e | 7690 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7691 | int tempflag; |
c5aa993b | 7692 | char *cond_string = NULL; |
c906108c | 7693 | |
44feb3ce TT |
7694 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7695 | ||
7696 | if (!arg) | |
7697 | arg = ""; | |
c906108c SS |
7698 | ep_skip_leading_whitespace (&arg); |
7699 | ||
7700 | /* The allowed syntax is: | |
c5aa993b JM |
7701 | catch exec |
7702 | catch exec if <cond> | |
c906108c SS |
7703 | |
7704 | First, check if there's an if clause. */ | |
7705 | cond_string = ep_parse_optional_if_clause (&arg); | |
7706 | ||
7707 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7708 | error (_("Junk at end of arguments.")); |
c906108c SS |
7709 | |
7710 | /* If this target supports it, create an exec catchpoint | |
7711 | and enable reporting of such events. */ | |
a6d9a66e UW |
7712 | create_catchpoint (gdbarch, tempflag, cond_string, |
7713 | &catch_exec_breakpoint_ops); | |
c906108c | 7714 | } |
c5aa993b | 7715 | |
3086aeae DJ |
7716 | static enum print_stop_action |
7717 | print_exception_catchpoint (struct breakpoint *b) | |
7718 | { | |
ade92717 | 7719 | int bp_temp, bp_throw; |
3086aeae | 7720 | |
ade92717 | 7721 | annotate_catchpoint (b->number); |
3086aeae | 7722 | |
ade92717 AR |
7723 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7724 | if (b->loc->address != b->loc->requested_address) | |
7725 | breakpoint_adjustment_warning (b->loc->requested_address, | |
7726 | b->loc->address, | |
7727 | b->number, 1); | |
df2b6d2d | 7728 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7729 | ui_out_text (uiout, |
7730 | bp_temp ? "Temporary catchpoint " | |
7731 | : "Catchpoint "); | |
7732 | if (!ui_out_is_mi_like_p (uiout)) | |
7733 | ui_out_field_int (uiout, "bkptno", b->number); | |
7734 | ui_out_text (uiout, | |
c0b37c48 AR |
7735 | bp_throw ? " (exception thrown), " |
7736 | : " (exception caught), "); | |
ade92717 AR |
7737 | if (ui_out_is_mi_like_p (uiout)) |
7738 | { | |
7739 | ui_out_field_string (uiout, "reason", | |
7740 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
7741 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7742 | ui_out_field_int (uiout, "bkptno", b->number); | |
7743 | } | |
3086aeae DJ |
7744 | return PRINT_SRC_AND_LOC; |
7745 | } | |
7746 | ||
7747 | static void | |
a6d9a66e | 7748 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 7749 | { |
79a45b7d TT |
7750 | struct value_print_options opts; |
7751 | get_user_print_options (&opts); | |
7752 | if (opts.addressprint) | |
3086aeae DJ |
7753 | { |
7754 | annotate_field (4); | |
604133b5 AR |
7755 | if (b->loc == NULL || b->loc->shlib_disabled) |
7756 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
7757 | else | |
5af949e3 UW |
7758 | ui_out_field_core_addr (uiout, "addr", |
7759 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
7760 | } |
7761 | annotate_field (5); | |
604133b5 | 7762 | if (b->loc) |
a6d9a66e | 7763 | *last_loc = b->loc; |
3086aeae DJ |
7764 | if (strstr (b->addr_string, "throw") != NULL) |
7765 | ui_out_field_string (uiout, "what", "exception throw"); | |
7766 | else | |
7767 | ui_out_field_string (uiout, "what", "exception catch"); | |
7768 | } | |
7769 | ||
7770 | static void | |
7771 | print_mention_exception_catchpoint (struct breakpoint *b) | |
7772 | { | |
ade92717 AR |
7773 | int bp_temp; |
7774 | int bp_throw; | |
7775 | ||
df2b6d2d | 7776 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7777 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7778 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
7779 | : _("Catchpoint ")); | |
7780 | ui_out_field_int (uiout, "bkptno", b->number); | |
7781 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
7782 | : _(" (catch)")); | |
3086aeae DJ |
7783 | } |
7784 | ||
7785 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
7786 | NULL, /* insert */ |
7787 | NULL, /* remove */ | |
7788 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
7789 | print_exception_catchpoint, |
7790 | print_one_exception_catchpoint, | |
7791 | print_mention_exception_catchpoint | |
7792 | }; | |
7793 | ||
7794 | static int | |
7795 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
7796 | enum exception_event_kind ex_event, int from_tty) | |
7797 | { | |
604133b5 AR |
7798 | char *trigger_func_name; |
7799 | ||
3086aeae | 7800 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 7801 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 7802 | else |
604133b5 | 7803 | trigger_func_name = "__cxa_throw"; |
3086aeae | 7804 | |
a6d9a66e UW |
7805 | break_command_really (get_current_arch (), |
7806 | trigger_func_name, cond_string, -1, | |
604133b5 | 7807 | 0 /* condition and thread are valid. */, |
1042e4c0 | 7808 | tempflag, 0, 0, |
604133b5 AR |
7809 | 0, |
7810 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
7811 | &gnu_v3_exception_catchpoint_ops, from_tty, |
7812 | 1 /* enabled */); | |
3086aeae | 7813 | |
3086aeae DJ |
7814 | return 1; |
7815 | } | |
7816 | ||
c5aa993b | 7817 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
7818 | |
7819 | static void | |
fba45db2 KB |
7820 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
7821 | int tempflag, int from_tty) | |
c906108c | 7822 | { |
c5aa993b JM |
7823 | char *cond_string = NULL; |
7824 | struct symtab_and_line *sal = NULL; | |
7825 | ||
44feb3ce TT |
7826 | if (!arg) |
7827 | arg = ""; | |
c906108c | 7828 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7829 | |
c906108c SS |
7830 | cond_string = ep_parse_optional_if_clause (&arg); |
7831 | ||
7832 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7833 | error (_("Junk at end of arguments.")); |
c906108c | 7834 | |
059fb39f PM |
7835 | if (ex_event != EX_EVENT_THROW |
7836 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7837 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7838 | |
3086aeae DJ |
7839 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7840 | return; | |
7841 | ||
8a3fe4f8 | 7842 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
7843 | } |
7844 | ||
44feb3ce TT |
7845 | /* Implementation of "catch catch" command. */ |
7846 | ||
7847 | static void | |
7848 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7849 | { | |
7850 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7851 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
7852 | } | |
7853 | ||
7854 | /* Implementation of "catch throw" command. */ | |
7855 | ||
7856 | static void | |
7857 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
7858 | { | |
7859 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
7860 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
7861 | } | |
7862 | ||
f7f9143b JB |
7863 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
7864 | ||
7865 | static void | |
a6d9a66e UW |
7866 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
7867 | struct symtab_and_line sal, | |
f7f9143b JB |
7868 | char *addr_string, |
7869 | char *exp_string, | |
7870 | char *cond_string, | |
7871 | struct expression *cond, | |
7872 | struct breakpoint_ops *ops, | |
7873 | int tempflag, | |
7874 | int from_tty) | |
7875 | { | |
7876 | struct breakpoint *b; | |
7877 | ||
7878 | if (from_tty) | |
7879 | { | |
5af949e3 UW |
7880 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
7881 | if (!loc_gdbarch) | |
7882 | loc_gdbarch = gdbarch; | |
7883 | ||
6c95b8df PA |
7884 | describe_other_breakpoints (loc_gdbarch, |
7885 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
7886 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
7887 | version for exception catchpoints, because two catchpoints | |
7888 | used for different exception names will use the same address. | |
7889 | In this case, a "breakpoint ... also set at..." warning is | |
7890 | unproductive. Besides. the warning phrasing is also a bit | |
7891 | inapropriate, we should use the word catchpoint, and tell | |
7892 | the user what type of catchpoint it is. The above is good | |
7893 | enough for now, though. */ | |
7894 | } | |
7895 | ||
a6d9a66e | 7896 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
7897 | set_breakpoint_count (breakpoint_count + 1); |
7898 | ||
7899 | b->enable_state = bp_enabled; | |
7900 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
7901 | b->number = breakpoint_count; | |
7902 | b->ignore_count = 0; | |
511a6cd4 | 7903 | b->loc->cond = cond; |
f7f9143b JB |
7904 | b->addr_string = addr_string; |
7905 | b->language = language_ada; | |
7906 | b->cond_string = cond_string; | |
7907 | b->exp_string = exp_string; | |
7908 | b->thread = -1; | |
7909 | b->ops = ops; | |
f7f9143b JB |
7910 | |
7911 | mention (b); | |
b60e7edf | 7912 | update_global_location_list (1); |
f7f9143b JB |
7913 | } |
7914 | ||
7915 | /* Implement the "catch exception" command. */ | |
7916 | ||
7917 | static void | |
44feb3ce TT |
7918 | catch_ada_exception_command (char *arg, int from_tty, |
7919 | struct cmd_list_element *command) | |
f7f9143b | 7920 | { |
a6d9a66e | 7921 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7922 | int tempflag; |
f7f9143b JB |
7923 | struct symtab_and_line sal; |
7924 | enum bptype type; | |
7925 | char *addr_string = NULL; | |
7926 | char *exp_string = NULL; | |
7927 | char *cond_string = NULL; | |
7928 | struct expression *cond = NULL; | |
7929 | struct breakpoint_ops *ops = NULL; | |
7930 | ||
44feb3ce TT |
7931 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7932 | ||
7933 | if (!arg) | |
7934 | arg = ""; | |
f7f9143b JB |
7935 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
7936 | &cond_string, &cond, &ops); | |
a6d9a66e | 7937 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
7938 | cond_string, cond, ops, tempflag, |
7939 | from_tty); | |
7940 | } | |
7941 | ||
a96d9b2e SDJ |
7942 | /* Cleanup function for a syscall filter list. */ |
7943 | static void | |
7944 | clean_up_filters (void *arg) | |
7945 | { | |
7946 | VEC(int) *iter = *(VEC(int) **) arg; | |
7947 | VEC_free (int, iter); | |
7948 | } | |
7949 | ||
7950 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
7951 | filter list, or NULL if no filtering is required. */ | |
7952 | static VEC(int) * | |
7953 | catch_syscall_split_args (char *arg) | |
7954 | { | |
7955 | VEC(int) *result = NULL; | |
7956 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
7957 | ||
7958 | while (*arg != '\0') | |
7959 | { | |
7960 | int i, syscall_number; | |
7961 | char *endptr; | |
7962 | char cur_name[128]; | |
7963 | struct syscall s; | |
7964 | ||
7965 | /* Skip whitespace. */ | |
7966 | while (isspace (*arg)) | |
7967 | arg++; | |
7968 | ||
7969 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
7970 | cur_name[i] = arg[i]; | |
7971 | cur_name[i] = '\0'; | |
7972 | arg += i; | |
7973 | ||
7974 | /* Check if the user provided a syscall name or a number. */ | |
7975 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
7976 | if (*endptr == '\0') | |
bccd0dd2 | 7977 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
7978 | else |
7979 | { | |
7980 | /* We have a name. Let's check if it's valid and convert it | |
7981 | to a number. */ | |
7982 | get_syscall_by_name (cur_name, &s); | |
7983 | ||
7984 | if (s.number == UNKNOWN_SYSCALL) | |
7985 | /* Here we have to issue an error instead of a warning, because | |
7986 | GDB cannot do anything useful if there's no syscall number to | |
7987 | be caught. */ | |
7988 | error (_("Unknown syscall name '%s'."), cur_name); | |
7989 | } | |
7990 | ||
7991 | /* Ok, it's valid. */ | |
7992 | VEC_safe_push (int, result, s.number); | |
7993 | } | |
7994 | ||
7995 | discard_cleanups (cleanup); | |
7996 | return result; | |
7997 | } | |
7998 | ||
7999 | /* Implement the "catch syscall" command. */ | |
8000 | ||
8001 | static void | |
8002 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
8003 | { | |
8004 | int tempflag; | |
8005 | VEC(int) *filter; | |
8006 | struct syscall s; | |
8007 | struct gdbarch *gdbarch = get_current_arch (); | |
8008 | ||
8009 | /* Checking if the feature if supported. */ | |
8010 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8011 | error (_("The feature 'catch syscall' is not supported on \ | |
8012 | this architeture yet.")); | |
8013 | ||
8014 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8015 | ||
8016 | ep_skip_leading_whitespace (&arg); | |
8017 | ||
8018 | /* We need to do this first "dummy" translation in order | |
8019 | to get the syscall XML file loaded or, most important, | |
8020 | to display a warning to the user if there's no XML file | |
8021 | for his/her architecture. */ | |
8022 | get_syscall_by_number (0, &s); | |
8023 | ||
8024 | /* The allowed syntax is: | |
8025 | catch syscall | |
8026 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8027 | ||
8028 | Let's check if there's a syscall name. */ | |
8029 | ||
8030 | if (arg != NULL) | |
8031 | filter = catch_syscall_split_args (arg); | |
8032 | else | |
8033 | filter = NULL; | |
8034 | ||
8035 | create_syscall_event_catchpoint (tempflag, filter, | |
8036 | &catch_syscall_breakpoint_ops); | |
8037 | } | |
8038 | ||
f7f9143b JB |
8039 | /* Implement the "catch assert" command. */ |
8040 | ||
8041 | static void | |
44feb3ce | 8042 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8043 | { |
a6d9a66e | 8044 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8045 | int tempflag; |
f7f9143b JB |
8046 | struct symtab_and_line sal; |
8047 | char *addr_string = NULL; | |
8048 | struct breakpoint_ops *ops = NULL; | |
8049 | ||
44feb3ce TT |
8050 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8051 | ||
8052 | if (!arg) | |
8053 | arg = ""; | |
f7f9143b | 8054 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
8055 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
8056 | ops, tempflag, from_tty); | |
f7f9143b JB |
8057 | } |
8058 | ||
c906108c | 8059 | static void |
fba45db2 | 8060 | catch_command (char *arg, int from_tty) |
c906108c | 8061 | { |
44feb3ce | 8062 | error (_("Catch requires an event name.")); |
c906108c SS |
8063 | } |
8064 | \f | |
8065 | ||
8066 | static void | |
fba45db2 | 8067 | tcatch_command (char *arg, int from_tty) |
c906108c | 8068 | { |
44feb3ce | 8069 | error (_("Catch requires an event name.")); |
c906108c SS |
8070 | } |
8071 | ||
80f8a6eb | 8072 | /* Delete breakpoints by address or line. */ |
c906108c SS |
8073 | |
8074 | static void | |
fba45db2 | 8075 | clear_command (char *arg, int from_tty) |
c906108c | 8076 | { |
d6e956e5 VP |
8077 | struct breakpoint *b; |
8078 | VEC(breakpoint_p) *found = 0; | |
8079 | int ix; | |
c906108c SS |
8080 | int default_match; |
8081 | struct symtabs_and_lines sals; | |
8082 | struct symtab_and_line sal; | |
c906108c SS |
8083 | int i; |
8084 | ||
8085 | if (arg) | |
8086 | { | |
8087 | sals = decode_line_spec (arg, 1); | |
8088 | default_match = 0; | |
8089 | } | |
8090 | else | |
8091 | { | |
c5aa993b | 8092 | sals.sals = (struct symtab_and_line *) |
c906108c | 8093 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 8094 | make_cleanup (xfree, sals.sals); |
fe39c653 | 8095 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
8096 | sal.line = default_breakpoint_line; |
8097 | sal.symtab = default_breakpoint_symtab; | |
8098 | sal.pc = default_breakpoint_address; | |
6c95b8df | 8099 | sal.pspace = default_breakpoint_pspace; |
c906108c | 8100 | if (sal.symtab == 0) |
8a3fe4f8 | 8101 | error (_("No source file specified.")); |
c906108c SS |
8102 | |
8103 | sals.sals[0] = sal; | |
8104 | sals.nelts = 1; | |
8105 | ||
8106 | default_match = 1; | |
8107 | } | |
8108 | ||
ed0616c6 VP |
8109 | /* We don't call resolve_sal_pc here. That's not |
8110 | as bad as it seems, because all existing breakpoints | |
8111 | typically have both file/line and pc set. So, if | |
8112 | clear is given file/line, we can match this to existing | |
8113 | breakpoint without obtaining pc at all. | |
8114 | ||
8115 | We only support clearing given the address explicitly | |
8116 | present in breakpoint table. Say, we've set breakpoint | |
8117 | at file:line. There were several PC values for that file:line, | |
8118 | due to optimization, all in one block. | |
8119 | We've picked one PC value. If "clear" is issued with another | |
8120 | PC corresponding to the same file:line, the breakpoint won't | |
8121 | be cleared. We probably can still clear the breakpoint, but | |
8122 | since the other PC value is never presented to user, user | |
8123 | can only find it by guessing, and it does not seem important | |
8124 | to support that. */ | |
8125 | ||
c906108c | 8126 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
8127 | to it. Do it in two passes, solely to preserve the current |
8128 | behavior that from_tty is forced true if we delete more than | |
8129 | one breakpoint. */ | |
c906108c | 8130 | |
80f8a6eb | 8131 | found = NULL; |
c906108c SS |
8132 | for (i = 0; i < sals.nelts; i++) |
8133 | { | |
8134 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
8135 | If line given (pc == 0), clear all bpts on specified line. |
8136 | If defaulting, clear all bpts on default line | |
c906108c | 8137 | or at default pc. |
c5aa993b JM |
8138 | |
8139 | defaulting sal.pc != 0 tests to do | |
8140 | ||
8141 | 0 1 pc | |
8142 | 1 1 pc _and_ line | |
8143 | 0 0 line | |
8144 | 1 0 <can't happen> */ | |
c906108c SS |
8145 | |
8146 | sal = sals.sals[i]; | |
c906108c | 8147 | |
d6e956e5 VP |
8148 | /* Find all matching breakpoints and add them to |
8149 | 'found'. */ | |
8150 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8151 | { |
0d381245 | 8152 | int match = 0; |
80f8a6eb MS |
8153 | /* Are we going to delete b? */ |
8154 | if (b->type != bp_none | |
8155 | && b->type != bp_watchpoint | |
8156 | && b->type != bp_hardware_watchpoint | |
8157 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8158 | && b->type != bp_access_watchpoint) |
8159 | { | |
8160 | struct bp_location *loc = b->loc; | |
8161 | for (; loc; loc = loc->next) | |
8162 | { | |
6c95b8df PA |
8163 | int pc_match = sal.pc |
8164 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8165 | && (loc->address == sal.pc) |
8166 | && (!section_is_overlay (loc->section) | |
8167 | || loc->section == sal.section); | |
8168 | int line_match = ((default_match || (0 == sal.pc)) | |
8169 | && b->source_file != NULL | |
8170 | && sal.symtab != NULL | |
6c95b8df | 8171 | && sal.pspace == loc->pspace |
0d381245 VP |
8172 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8173 | && b->line_number == sal.line); | |
8174 | if (pc_match || line_match) | |
8175 | { | |
8176 | match = 1; | |
8177 | break; | |
8178 | } | |
8179 | } | |
8180 | } | |
8181 | ||
8182 | if (match) | |
d6e956e5 | 8183 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8184 | } |
80f8a6eb MS |
8185 | } |
8186 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8187 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8188 | { |
8189 | if (arg) | |
8a3fe4f8 | 8190 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8191 | else |
8a3fe4f8 | 8192 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8193 | } |
c906108c | 8194 | |
d6e956e5 | 8195 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8196 | from_tty = 1; /* Always report if deleted more than one */ |
8197 | if (from_tty) | |
a3f17187 | 8198 | { |
d6e956e5 | 8199 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8200 | printf_unfiltered (_("Deleted breakpoint ")); |
8201 | else | |
8202 | printf_unfiltered (_("Deleted breakpoints ")); | |
8203 | } | |
80f8a6eb | 8204 | breakpoints_changed (); |
d6e956e5 VP |
8205 | |
8206 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8207 | { |
c5aa993b | 8208 | if (from_tty) |
d6e956e5 VP |
8209 | printf_unfiltered ("%d ", b->number); |
8210 | delete_breakpoint (b); | |
c906108c | 8211 | } |
80f8a6eb MS |
8212 | if (from_tty) |
8213 | putchar_unfiltered ('\n'); | |
c906108c SS |
8214 | } |
8215 | \f | |
8216 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8217 | all breakpoints that are marked for deletion, whether hit or not. | |
8218 | This is called after any breakpoint is hit, or after errors. */ | |
8219 | ||
8220 | void | |
fba45db2 | 8221 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8222 | { |
8223 | struct breakpoint *b, *temp; | |
8224 | ||
8225 | for (; bs; bs = bs->next) | |
20874c92 VP |
8226 | if (bs->breakpoint_at |
8227 | && bs->breakpoint_at->owner | |
8228 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8229 | && bs->stop) |
4f8d1dc6 | 8230 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8231 | |
8232 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8233 | { |
b5de0fa7 | 8234 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8235 | delete_breakpoint (b); |
8236 | } | |
c906108c SS |
8237 | } |
8238 | ||
494cfb0f | 8239 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
8240 | Sort elements primarily by their ADDRESS (no matter what does |
8241 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8242 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8243 | is sorted stable way despite qsort being an instable algorithm. */ | |
8244 | ||
8245 | static int | |
494cfb0f | 8246 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 8247 | { |
494cfb0f JK |
8248 | struct bp_location *a = *(void **) ap; |
8249 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
8250 | int a_perm = a->owner->enable_state == bp_permanent; |
8251 | int b_perm = b->owner->enable_state == bp_permanent; | |
8252 | ||
8253 | if (a->address != b->address) | |
8254 | return (a->address > b->address) - (a->address < b->address); | |
8255 | ||
8256 | /* Sort permanent breakpoints first. */ | |
8257 | if (a_perm != b_perm) | |
8258 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8259 | ||
8260 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8261 | breakpoint can be sorted in arbitrary order. */ | |
8262 | ||
8263 | if (a->owner->number != b->owner->number) | |
8264 | return (a->owner->number > b->owner->number) | |
8265 | - (a->owner->number < b->owner->number); | |
8266 | ||
8267 | return (a > b) - (a < b); | |
8268 | } | |
8269 | ||
876fa593 JK |
8270 | /* Set bp_location_placed_address_before_address_max and |
8271 | bp_location_shadow_len_after_address_max according to the current content of | |
8272 | the bp_location array. */ | |
f7545552 TT |
8273 | |
8274 | static void | |
876fa593 | 8275 | bp_location_target_extensions_update (void) |
f7545552 | 8276 | { |
876fa593 JK |
8277 | struct bp_location *bl, **blp_tmp; |
8278 | ||
8279 | bp_location_placed_address_before_address_max = 0; | |
8280 | bp_location_shadow_len_after_address_max = 0; | |
8281 | ||
8282 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8283 | { | |
8284 | CORE_ADDR start, end, addr; | |
8285 | ||
8286 | if (!bp_location_has_shadow (bl)) | |
8287 | continue; | |
8288 | ||
8289 | start = bl->target_info.placed_address; | |
8290 | end = start + bl->target_info.shadow_len; | |
8291 | ||
8292 | gdb_assert (bl->address >= start); | |
8293 | addr = bl->address - start; | |
8294 | if (addr > bp_location_placed_address_before_address_max) | |
8295 | bp_location_placed_address_before_address_max = addr; | |
8296 | ||
8297 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8298 | ||
8299 | gdb_assert (bl->address < end); | |
8300 | addr = end - bl->address; | |
8301 | if (addr > bp_location_shadow_len_after_address_max) | |
8302 | bp_location_shadow_len_after_address_max = addr; | |
8303 | } | |
f7545552 TT |
8304 | } |
8305 | ||
4cd9bd08 | 8306 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8307 | into the inferior, only remove already-inserted locations that no |
8308 | longer should be inserted. Functions that delete a breakpoint or | |
8309 | breakpoints should pass false, so that deleting a breakpoint | |
8310 | doesn't have the side effect of inserting the locations of other | |
8311 | breakpoints that are marked not-inserted, but should_be_inserted | |
8312 | returns true on them. | |
8313 | ||
8314 | This behaviour is useful is situations close to tear-down -- e.g., | |
8315 | after an exec, while the target still has execution, but breakpoint | |
8316 | shadows of the previous executable image should *NOT* be restored | |
8317 | to the new image; or before detaching, where the target still has | |
8318 | execution and wants to delete breakpoints from GDB's lists, and all | |
8319 | breakpoints had already been removed from the inferior. */ | |
8320 | ||
0d381245 | 8321 | static void |
b60e7edf | 8322 | update_global_location_list (int should_insert) |
0d381245 | 8323 | { |
74960c60 | 8324 | struct breakpoint *b; |
876fa593 | 8325 | struct bp_location **locp, *loc; |
f7545552 TT |
8326 | struct cleanup *cleanups; |
8327 | ||
2d134ed3 PA |
8328 | /* Used in the duplicates detection below. When iterating over all |
8329 | bp_locations, points to the first bp_location of a given address. | |
8330 | Breakpoints and watchpoints of different types are never | |
8331 | duplicates of each other. Keep one pointer for each type of | |
8332 | breakpoint/watchpoint, so we only need to loop over all locations | |
8333 | once. */ | |
8334 | struct bp_location *bp_loc_first; /* breakpoint */ | |
8335 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
8336 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
8337 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
8338 | |
8339 | /* Saved former bp_location array which we compare against the newly built | |
8340 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8341 | struct bp_location **old_location, **old_locp; | |
8342 | unsigned old_location_count; | |
8343 | ||
8344 | old_location = bp_location; | |
8345 | old_location_count = bp_location_count; | |
8346 | bp_location = NULL; | |
8347 | bp_location_count = 0; | |
8348 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8349 | |
74960c60 | 8350 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8351 | for (loc = b->loc; loc; loc = loc->next) |
8352 | bp_location_count++; | |
8353 | ||
8354 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8355 | locp = bp_location; | |
8356 | ALL_BREAKPOINTS (b) | |
8357 | for (loc = b->loc; loc; loc = loc->next) | |
8358 | *locp++ = loc; | |
8359 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 8360 | bp_location_compare); |
876fa593 JK |
8361 | |
8362 | bp_location_target_extensions_update (); | |
74960c60 VP |
8363 | |
8364 | /* Identify bp_location instances that are no longer present in the new | |
8365 | list, and therefore should be freed. Note that it's not necessary that | |
8366 | those locations should be removed from inferior -- if there's another | |
8367 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8368 | we don't need to remove/insert the location. |
8369 | ||
8370 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8371 | former bp_location array state respectively. */ | |
8372 | ||
8373 | locp = bp_location; | |
8374 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8375 | old_locp++) | |
74960c60 | 8376 | { |
876fa593 | 8377 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 8378 | struct bp_location **loc2p; |
876fa593 JK |
8379 | |
8380 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8381 | have to free it. */ |
c7d46a38 | 8382 | int found_object = 0; |
20874c92 VP |
8383 | /* Tells if the location should remain inserted in the target. */ |
8384 | int keep_in_target = 0; | |
8385 | int removed = 0; | |
876fa593 JK |
8386 | |
8387 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8388 | at or being the one matching OLD_LOC. */ | |
8389 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 8390 | && (*locp)->address < old_loc->address) |
876fa593 | 8391 | locp++; |
c7d46a38 PA |
8392 | |
8393 | for (loc2p = locp; | |
8394 | (loc2p < bp_location + bp_location_count | |
8395 | && (*loc2p)->address == old_loc->address); | |
8396 | loc2p++) | |
8397 | { | |
8398 | if (*loc2p == old_loc) | |
8399 | { | |
8400 | found_object = 1; | |
8401 | break; | |
8402 | } | |
8403 | } | |
74960c60 VP |
8404 | |
8405 | /* If this location is no longer present, and inserted, look if there's | |
8406 | maybe a new location at the same address. If so, mark that one | |
8407 | inserted, and don't remove this one. This is needed so that we | |
8408 | don't have a time window where a breakpoint at certain location is not | |
8409 | inserted. */ | |
8410 | ||
876fa593 | 8411 | if (old_loc->inserted) |
0d381245 | 8412 | { |
74960c60 | 8413 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8414 | |
876fa593 | 8415 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8416 | { |
8417 | /* The location is still present in the location list, and still | |
8418 | should be inserted. Don't do anything. */ | |
20874c92 | 8419 | keep_in_target = 1; |
74960c60 VP |
8420 | } |
8421 | else | |
8422 | { | |
8423 | /* The location is either no longer present, or got disabled. | |
8424 | See if there's another location at the same address, in which | |
8425 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8426 | |
8427 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8428 | { | |
876fa593 | 8429 | for (loc2p = locp; |
c7d46a38 PA |
8430 | (loc2p < bp_location + bp_location_count |
8431 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
8432 | loc2p++) |
8433 | { | |
8434 | struct bp_location *loc2 = *loc2p; | |
8435 | ||
2d134ed3 | 8436 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
8437 | { |
8438 | /* For the sake of should_be_inserted. | |
8439 | Duplicates check below will fix up this later. */ | |
8440 | loc2->duplicate = 0; | |
8441 | if (loc2 != old_loc && should_be_inserted (loc2)) | |
8442 | { | |
8443 | loc2->inserted = 1; | |
8444 | loc2->target_info = old_loc->target_info; | |
8445 | keep_in_target = 1; | |
8446 | break; | |
8447 | } | |
876fa593 JK |
8448 | } |
8449 | } | |
8450 | } | |
74960c60 VP |
8451 | } |
8452 | ||
20874c92 VP |
8453 | if (!keep_in_target) |
8454 | { | |
876fa593 | 8455 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8456 | { |
8457 | /* This is just about all we can do. We could keep this | |
8458 | location on the global list, and try to remove it next | |
8459 | time, but there's no particular reason why we will | |
8460 | succeed next time. | |
8461 | ||
876fa593 | 8462 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8463 | as delete_breakpoint frees the breakpoint only |
8464 | after calling us. */ | |
8465 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 8466 | old_loc->owner->number); |
20874c92 VP |
8467 | } |
8468 | removed = 1; | |
8469 | } | |
0d381245 | 8470 | } |
74960c60 VP |
8471 | |
8472 | if (!found_object) | |
1c5cfe86 | 8473 | { |
db82e815 PA |
8474 | if (removed && non_stop |
8475 | && breakpoint_address_is_meaningful (old_loc->owner) | |
8476 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 8477 | { |
db82e815 PA |
8478 | /* This location was removed from the target. In |
8479 | non-stop mode, a race condition is possible where | |
8480 | we've removed a breakpoint, but stop events for that | |
8481 | breakpoint are already queued and will arrive later. | |
8482 | We apply an heuristic to be able to distinguish such | |
8483 | SIGTRAPs from other random SIGTRAPs: we keep this | |
8484 | breakpoint location for a bit, and will retire it | |
8485 | after we see some number of events. The theory here | |
8486 | is that reporting of events should, "on the average", | |
8487 | be fair, so after a while we'll see events from all | |
8488 | threads that have anything of interest, and no longer | |
8489 | need to keep this breakpoint location around. We | |
8490 | don't hold locations forever so to reduce chances of | |
8491 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
8492 | SIGTRAP. | |
8493 | ||
8494 | The heuristic failing can be disastrous on | |
8495 | decr_pc_after_break targets. | |
8496 | ||
8497 | On decr_pc_after_break targets, like e.g., x86-linux, | |
8498 | if we fail to recognize a late breakpoint SIGTRAP, | |
8499 | because events_till_retirement has reached 0 too | |
8500 | soon, we'll fail to do the PC adjustment, and report | |
8501 | a random SIGTRAP to the user. When the user resumes | |
8502 | the inferior, it will most likely immediately crash | |
8503 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently | |
8504 | corrupted, because of being resumed e.g., in the | |
8505 | middle of a multi-byte instruction, or skipped a | |
8506 | one-byte instruction. This was actually seen happen | |
8507 | on native x86-linux, and should be less rare on | |
8508 | targets that do not support new thread events, like | |
8509 | remote, due to the heuristic depending on | |
8510 | thread_count. | |
8511 | ||
8512 | Mistaking a random SIGTRAP for a breakpoint trap | |
8513 | causes similar symptoms (PC adjustment applied when | |
8514 | it shouldn't), but then again, playing with SIGTRAPs | |
8515 | behind the debugger's back is asking for trouble. | |
8516 | ||
8517 | Since hardware watchpoint traps are always | |
8518 | distinguishable from other traps, so we don't need to | |
8519 | apply keep hardware watchpoint moribund locations | |
8520 | around. We simply always ignore hardware watchpoint | |
8521 | traps we can no longer explain. */ | |
8522 | ||
876fa593 JK |
8523 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
8524 | old_loc->owner = NULL; | |
20874c92 | 8525 | |
876fa593 | 8526 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
8527 | } |
8528 | else | |
876fa593 | 8529 | free_bp_location (old_loc); |
20874c92 | 8530 | } |
74960c60 | 8531 | } |
1c5cfe86 | 8532 | |
2d134ed3 PA |
8533 | /* Rescan breakpoints at the same address and section, marking the |
8534 | first one as "first" and any others as "duplicates". This is so | |
8535 | that the bpt instruction is only inserted once. If we have a | |
8536 | permanent breakpoint at the same place as BPT, make that one the | |
8537 | official one, and the rest as duplicates. Permanent breakpoints | |
8538 | are sorted first for the same address. | |
8539 | ||
8540 | Do the same for hardware watchpoints, but also considering the | |
8541 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 8542 | |
2d134ed3 PA |
8543 | bp_loc_first = NULL; |
8544 | wp_loc_first = NULL; | |
8545 | awp_loc_first = NULL; | |
8546 | rwp_loc_first = NULL; | |
876fa593 | 8547 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 8548 | { |
876fa593 | 8549 | struct breakpoint *b = loc->owner; |
2d134ed3 | 8550 | struct bp_location **loc_first_p; |
876fa593 JK |
8551 | |
8552 | if (b->enable_state == bp_disabled | |
8553 | || b->enable_state == bp_call_disabled | |
8554 | || b->enable_state == bp_startup_disabled | |
8555 | || !loc->enabled | |
8556 | || loc->shlib_disabled | |
8557 | || !breakpoint_address_is_meaningful (b)) | |
8558 | continue; | |
8559 | ||
8560 | /* Permanent breakpoint should always be inserted. */ | |
8561 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
8562 | internal_error (__FILE__, __LINE__, | |
8563 | _("allegedly permanent breakpoint is not " | |
8564 | "actually inserted")); | |
8565 | ||
2d134ed3 PA |
8566 | if (b->type == bp_hardware_watchpoint) |
8567 | loc_first_p = &wp_loc_first; | |
8568 | else if (b->type == bp_read_watchpoint) | |
8569 | loc_first_p = &rwp_loc_first; | |
8570 | else if (b->type == bp_access_watchpoint) | |
8571 | loc_first_p = &awp_loc_first; | |
8572 | else | |
8573 | loc_first_p = &bp_loc_first; | |
8574 | ||
8575 | if (*loc_first_p == NULL | |
8576 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
8577 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 8578 | { |
2d134ed3 | 8579 | *loc_first_p = loc; |
876fa593 JK |
8580 | loc->duplicate = 0; |
8581 | continue; | |
8582 | } | |
8583 | ||
8584 | loc->duplicate = 1; | |
8585 | ||
2d134ed3 PA |
8586 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
8587 | && b->enable_state != bp_permanent) | |
876fa593 JK |
8588 | internal_error (__FILE__, __LINE__, |
8589 | _("another breakpoint was inserted on top of " | |
8590 | "a permanent breakpoint")); | |
0d381245 | 8591 | } |
74960c60 | 8592 | |
50c71eaf | 8593 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 8594 | && (have_live_inferiors () |
2567c7d9 | 8595 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 8596 | insert_breakpoint_locations (); |
f7545552 TT |
8597 | |
8598 | do_cleanups (cleanups); | |
74960c60 VP |
8599 | } |
8600 | ||
20874c92 VP |
8601 | void |
8602 | breakpoint_retire_moribund (void) | |
8603 | { | |
8604 | struct bp_location *loc; | |
8605 | int ix; | |
8606 | ||
8607 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
8608 | if (--(loc->events_till_retirement) == 0) | |
8609 | { | |
8610 | free_bp_location (loc); | |
8611 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
8612 | --ix; | |
8613 | } | |
8614 | } | |
8615 | ||
74960c60 | 8616 | static void |
b60e7edf | 8617 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
8618 | { |
8619 | struct gdb_exception e; | |
8620 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 8621 | update_global_location_list (inserting); |
0d381245 VP |
8622 | } |
8623 | ||
a474d7c2 PA |
8624 | /* Clear BPT from a BPS. */ |
8625 | static void | |
8626 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
8627 | { | |
8628 | bpstat bs; | |
8629 | for (bs = bps; bs; bs = bs->next) | |
8630 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
8631 | { | |
8632 | bs->breakpoint_at = NULL; | |
8633 | bs->old_val = NULL; | |
8634 | /* bs->commands will be freed later. */ | |
8635 | } | |
8636 | } | |
8637 | ||
8638 | /* Callback for iterate_over_threads. */ | |
8639 | static int | |
8640 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
8641 | { | |
8642 | struct breakpoint *bpt = data; | |
8643 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
8644 | return 0; | |
8645 | } | |
8646 | ||
53a5351d JM |
8647 | /* Delete a breakpoint and clean up all traces of it in the data |
8648 | structures. */ | |
c906108c SS |
8649 | |
8650 | void | |
fba45db2 | 8651 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8652 | { |
52f0bd74 | 8653 | struct breakpoint *b; |
74960c60 | 8654 | struct bp_location *loc, *next; |
c906108c | 8655 | |
8a3fe4f8 | 8656 | gdb_assert (bpt != NULL); |
c906108c SS |
8657 | |
8658 | /* Has this bp already been deleted? This can happen because multiple | |
8659 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
8660 | ||
8661 | One example of this happening is a watchpoint's scope bp. When the | |
8662 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
8663 | delete it. We also delete its scope bp. But the scope bp is marked | |
8664 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
8665 | checked for auto-deleting bp's, which are deleted. | |
8666 | ||
8667 | A real solution to this problem might involve reference counts in bp's, | |
8668 | and/or giving them pointers back to their referencing bpstat's, and | |
8669 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 8670 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
8671 | if (bpt->type == bp_none) |
8672 | return; | |
8673 | ||
383f836e | 8674 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 8675 | |
c906108c SS |
8676 | if (breakpoint_chain == bpt) |
8677 | breakpoint_chain = bpt->next; | |
8678 | ||
c906108c SS |
8679 | ALL_BREAKPOINTS (b) |
8680 | if (b->next == bpt) | |
c5aa993b JM |
8681 | { |
8682 | b->next = bpt->next; | |
8683 | break; | |
8684 | } | |
c906108c | 8685 | |
c906108c | 8686 | free_command_lines (&bpt->commands); |
c906108c | 8687 | if (bpt->cond_string != NULL) |
b8c9b27d | 8688 | xfree (bpt->cond_string); |
c906108c | 8689 | if (bpt->addr_string != NULL) |
b8c9b27d | 8690 | xfree (bpt->addr_string); |
c906108c | 8691 | if (bpt->exp != NULL) |
b8c9b27d | 8692 | xfree (bpt->exp); |
c906108c | 8693 | if (bpt->exp_string != NULL) |
b8c9b27d | 8694 | xfree (bpt->exp_string); |
c906108c SS |
8695 | if (bpt->val != NULL) |
8696 | value_free (bpt->val); | |
8697 | if (bpt->source_file != NULL) | |
b8c9b27d | 8698 | xfree (bpt->source_file); |
c906108c | 8699 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 8700 | xfree (bpt->exec_pathname); |
a96d9b2e | 8701 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
8702 | |
8703 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
8704 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
8705 | We just check stop_bpstat for now. Note that we cannot just |
8706 | remove bpstats pointing at bpt from the stop_bpstat list | |
8707 | entirely, as breakpoint commands are associated with the bpstat; | |
8708 | if we remove it here, then the later call to | |
8709 | bpstat_do_actions (&stop_bpstat); | |
8710 | in event-top.c won't do anything, and temporary breakpoints | |
8711 | with commands won't work. */ | |
a474d7c2 | 8712 | |
a474d7c2 | 8713 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
8714 | |
8715 | /* Now that breakpoint is removed from breakpoint | |
8716 | list, update the global location list. This | |
8717 | will remove locations that used to belong to | |
8718 | this breakpoint. Do this before freeing | |
8719 | the breakpoint itself, since remove_breakpoint | |
8720 | looks at location's owner. It might be better | |
8721 | design to have location completely self-contained, | |
8722 | but it's not the case now. */ | |
b60e7edf | 8723 | update_global_location_list (0); |
74960c60 VP |
8724 | |
8725 | ||
c906108c SS |
8726 | /* On the chance that someone will soon try again to delete this same |
8727 | bp, we mark it as deleted before freeing its storage. */ | |
8728 | bpt->type = bp_none; | |
8729 | ||
b8c9b27d | 8730 | xfree (bpt); |
c906108c SS |
8731 | } |
8732 | ||
4d6140d9 AC |
8733 | static void |
8734 | do_delete_breakpoint_cleanup (void *b) | |
8735 | { | |
8736 | delete_breakpoint (b); | |
8737 | } | |
8738 | ||
8739 | struct cleanup * | |
8740 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
8741 | { | |
8742 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
8743 | } | |
8744 | ||
c906108c | 8745 | void |
fba45db2 | 8746 | delete_command (char *arg, int from_tty) |
c906108c SS |
8747 | { |
8748 | struct breakpoint *b, *temp; | |
8749 | ||
ea9365bb TT |
8750 | dont_repeat (); |
8751 | ||
c906108c SS |
8752 | if (arg == 0) |
8753 | { | |
8754 | int breaks_to_delete = 0; | |
8755 | ||
8756 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
8757 | Do not delete internal or call-dummy breakpoints, these |
8758 | have to be deleted with an explicit breakpoint number argument. */ | |
8759 | ALL_BREAKPOINTS (b) | |
8760 | { | |
059fb39f PM |
8761 | if (b->type != bp_call_dummy |
8762 | && b->type != bp_shlib_event | |
4efc6507 | 8763 | && b->type != bp_jit_event |
059fb39f PM |
8764 | && b->type != bp_thread_event |
8765 | && b->type != bp_overlay_event | |
0fd8e87f | 8766 | && b->type != bp_longjmp_master |
059fb39f | 8767 | && b->number >= 0) |
973d738b DJ |
8768 | { |
8769 | breaks_to_delete = 1; | |
8770 | break; | |
8771 | } | |
c5aa993b | 8772 | } |
c906108c SS |
8773 | |
8774 | /* Ask user only if there are some breakpoints to delete. */ | |
8775 | if (!from_tty | |
e2e0b3e5 | 8776 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 8777 | { |
c5aa993b JM |
8778 | ALL_BREAKPOINTS_SAFE (b, temp) |
8779 | { | |
059fb39f PM |
8780 | if (b->type != bp_call_dummy |
8781 | && b->type != bp_shlib_event | |
8782 | && b->type != bp_thread_event | |
4efc6507 | 8783 | && b->type != bp_jit_event |
059fb39f | 8784 | && b->type != bp_overlay_event |
0fd8e87f | 8785 | && b->type != bp_longjmp_master |
059fb39f | 8786 | && b->number >= 0) |
c5aa993b JM |
8787 | delete_breakpoint (b); |
8788 | } | |
c906108c SS |
8789 | } |
8790 | } | |
8791 | else | |
8792 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8793 | } | |
8794 | ||
0d381245 VP |
8795 | static int |
8796 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 8797 | { |
0d381245 VP |
8798 | for (; loc; loc = loc->next) |
8799 | if (!loc->shlib_disabled) | |
8800 | return 0; | |
8801 | return 1; | |
fe3f5fa8 VP |
8802 | } |
8803 | ||
776592bf DE |
8804 | /* Subroutine of update_breakpoint_locations to simplify it. |
8805 | Return non-zero if multiple fns in list LOC have the same name. | |
8806 | Null names are ignored. */ | |
8807 | ||
8808 | static int | |
8809 | ambiguous_names_p (struct bp_location *loc) | |
8810 | { | |
8811 | struct bp_location *l; | |
8812 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
8813 | (int (*) (const void *, const void *)) streq, | |
8814 | NULL, xcalloc, xfree); | |
8815 | ||
8816 | for (l = loc; l != NULL; l = l->next) | |
8817 | { | |
8818 | const char **slot; | |
8819 | const char *name = l->function_name; | |
8820 | ||
8821 | /* Allow for some names to be NULL, ignore them. */ | |
8822 | if (name == NULL) | |
8823 | continue; | |
8824 | ||
8825 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
8826 | INSERT); | |
8827 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
8828 | NULL. */ | |
8829 | if (*slot != NULL) | |
8830 | { | |
8831 | htab_delete (htab); | |
8832 | return 1; | |
8833 | } | |
8834 | *slot = name; | |
8835 | } | |
8836 | ||
8837 | htab_delete (htab); | |
8838 | return 0; | |
8839 | } | |
8840 | ||
fe3f5fa8 | 8841 | static void |
0d381245 VP |
8842 | update_breakpoint_locations (struct breakpoint *b, |
8843 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
8844 | { |
8845 | int i; | |
8846 | char *s; | |
0d381245 VP |
8847 | struct bp_location *existing_locations = b->loc; |
8848 | ||
8849 | /* If there's no new locations, and all existing locations | |
8850 | are pending, don't do anything. This optimizes | |
8851 | the common case where all locations are in the same | |
8852 | shared library, that was unloaded. We'd like to | |
8853 | retain the location, so that when the library | |
8854 | is loaded again, we don't loose the enabled/disabled | |
8855 | status of the individual locations. */ | |
8856 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
8857 | return; |
8858 | ||
fe3f5fa8 VP |
8859 | b->loc = NULL; |
8860 | ||
0d381245 | 8861 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 8862 | { |
0d381245 | 8863 | struct bp_location *new_loc = |
39d61571 | 8864 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 8865 | |
0d381245 VP |
8866 | /* Reparse conditions, they might contain references to the |
8867 | old symtab. */ | |
8868 | if (b->cond_string != NULL) | |
8869 | { | |
8870 | struct gdb_exception e; | |
fe3f5fa8 | 8871 | |
0d381245 VP |
8872 | s = b->cond_string; |
8873 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
8874 | { | |
8875 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
8876 | 0); | |
8877 | } | |
8878 | if (e.reason < 0) | |
8879 | { | |
8880 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
8881 | b->number, e.message); | |
8882 | new_loc->enabled = 0; | |
8883 | } | |
8884 | } | |
fe3f5fa8 | 8885 | |
0d381245 VP |
8886 | if (b->source_file != NULL) |
8887 | xfree (b->source_file); | |
8888 | if (sals.sals[i].symtab == NULL) | |
8889 | b->source_file = NULL; | |
8890 | else | |
1b36a34b | 8891 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 8892 | |
0d381245 VP |
8893 | if (b->line_number == 0) |
8894 | b->line_number = sals.sals[i].line; | |
8895 | } | |
fe3f5fa8 | 8896 | |
514f746b AR |
8897 | /* Update locations of permanent breakpoints. */ |
8898 | if (b->enable_state == bp_permanent) | |
8899 | make_breakpoint_permanent (b); | |
8900 | ||
0d381245 VP |
8901 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
8902 | { | |
8903 | struct bp_location *e = existing_locations; | |
776592bf DE |
8904 | /* If there are multiple breakpoints with the same function name, |
8905 | e.g. for inline functions, comparing function names won't work. | |
8906 | Instead compare pc addresses; this is just a heuristic as things | |
8907 | may have moved, but in practice it gives the correct answer | |
8908 | often enough until a better solution is found. */ | |
8909 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
8910 | ||
0d381245 VP |
8911 | for (; e; e = e->next) |
8912 | { | |
8913 | if (!e->enabled && e->function_name) | |
8914 | { | |
8915 | struct bp_location *l = b->loc; | |
776592bf DE |
8916 | if (have_ambiguous_names) |
8917 | { | |
8918 | for (; l; l = l->next) | |
6c95b8df PA |
8919 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
8920 | l->pspace->aspace, l->address)) | |
776592bf DE |
8921 | { |
8922 | l->enabled = 0; | |
8923 | break; | |
8924 | } | |
8925 | } | |
8926 | else | |
8927 | { | |
8928 | for (; l; l = l->next) | |
8929 | if (l->function_name | |
8930 | && strcmp (e->function_name, l->function_name) == 0) | |
8931 | { | |
8932 | l->enabled = 0; | |
8933 | break; | |
8934 | } | |
8935 | } | |
0d381245 VP |
8936 | } |
8937 | } | |
8938 | } | |
fe3f5fa8 | 8939 | |
b60e7edf | 8940 | update_global_location_list (1); |
fe3f5fa8 VP |
8941 | } |
8942 | ||
8943 | ||
c906108c SS |
8944 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
8945 | The value we return ends up being the return value from catch_errors. | |
8946 | Unused in this case. */ | |
8947 | ||
8948 | static int | |
4efb68b1 | 8949 | breakpoint_re_set_one (void *bint) |
c906108c | 8950 | { |
53a5351d JM |
8951 | /* get past catch_errs */ |
8952 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
8953 | struct value *mark; |
8954 | int i; | |
fe3f5fa8 VP |
8955 | int not_found = 0; |
8956 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
8957 | struct symtabs_and_lines sals = {0}; |
8958 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 8959 | char *s; |
b5de0fa7 | 8960 | enum enable_state save_enable; |
fe3f5fa8 | 8961 | struct gdb_exception e; |
6c95b8df | 8962 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
8963 | |
8964 | switch (b->type) | |
8965 | { | |
8966 | case bp_none: | |
8a3fe4f8 | 8967 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 8968 | b->number); |
c906108c SS |
8969 | return 0; |
8970 | case bp_breakpoint: | |
8971 | case bp_hardware_breakpoint: | |
1042e4c0 | 8972 | case bp_tracepoint: |
8bea4e01 UW |
8973 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
8974 | if (b->enable_state == bp_startup_disabled) | |
8975 | return 0; | |
8976 | ||
c906108c SS |
8977 | if (b->addr_string == NULL) |
8978 | { | |
8979 | /* Anything without a string can't be re-set. */ | |
8980 | delete_breakpoint (b); | |
8981 | return 0; | |
8982 | } | |
c906108c SS |
8983 | |
8984 | set_language (b->language); | |
8985 | input_radix = b->input_radix; | |
8986 | s = b->addr_string; | |
6c95b8df PA |
8987 | |
8988 | save_current_space_and_thread (); | |
8989 | switch_to_program_space_and_thread (b->pspace); | |
8990 | ||
fe3f5fa8 | 8991 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 8992 | { |
fe3f5fa8 VP |
8993 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
8994 | not_found_ptr); | |
8995 | } | |
8996 | if (e.reason < 0) | |
8997 | { | |
8998 | int not_found_and_ok = 0; | |
8999 | /* For pending breakpoints, it's expected that parsing | |
9000 | will fail until the right shared library is loaded. | |
9001 | User has already told to create pending breakpoints and | |
9002 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
9003 | state, then user already saw the message about that breakpoint | |
9004 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
9005 | if (not_found |
9006 | && (b->condition_not_parsed | |
9007 | || (b->loc && b->loc->shlib_disabled) | |
9008 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
9009 | not_found_and_ok = 1; |
9010 | ||
9011 | if (!not_found_and_ok) | |
c906108c | 9012 | { |
fe3f5fa8 VP |
9013 | /* We surely don't want to warn about the same breakpoint |
9014 | 10 times. One solution, implemented here, is disable | |
9015 | the breakpoint on error. Another solution would be to | |
9016 | have separate 'warning emitted' flag. Since this | |
9017 | happens only when a binary has changed, I don't know | |
9018 | which approach is better. */ | |
9019 | b->enable_state = bp_disabled; | |
9020 | throw_exception (e); | |
c906108c | 9021 | } |
fe3f5fa8 | 9022 | } |
c906108c | 9023 | |
6c95b8df | 9024 | if (!not_found) |
fe3f5fa8 | 9025 | { |
6c95b8df PA |
9026 | gdb_assert (sals.nelts == 1); |
9027 | ||
9028 | resolve_sal_pc (&sals.sals[0]); | |
9029 | if (b->condition_not_parsed && s && s[0]) | |
9030 | { | |
9031 | char *cond_string = 0; | |
9032 | int thread = -1; | |
9033 | int task = 0; | |
9034 | ||
9035 | find_condition_and_thread (s, sals.sals[0].pc, | |
9036 | &cond_string, &thread, &task); | |
9037 | if (cond_string) | |
9038 | b->cond_string = cond_string; | |
9039 | b->thread = thread; | |
9040 | b->task = task; | |
9041 | b->condition_not_parsed = 0; | |
9042 | } | |
9043 | ||
9044 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 9045 | } |
6c95b8df PA |
9046 | |
9047 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 9048 | update_breakpoint_locations (b, expanded); |
c906108c SS |
9049 | break; |
9050 | ||
9051 | case bp_watchpoint: | |
9052 | case bp_hardware_watchpoint: | |
9053 | case bp_read_watchpoint: | |
9054 | case bp_access_watchpoint: | |
0b3de036 VP |
9055 | /* Watchpoint can be either on expression using entirely global variables, |
9056 | or it can be on local variables. | |
9057 | ||
9058 | Watchpoints of the first kind are never auto-deleted, and even persist | |
9059 | across program restarts. Since they can use variables from shared | |
9060 | libraries, we need to reparse expression as libraries are loaded | |
9061 | and unloaded. | |
9062 | ||
9063 | Watchpoints on local variables can also change meaning as result | |
9064 | of solib event. For example, if a watchpoint uses both a local and | |
9065 | a global variables in expression, it's a local watchpoint, but | |
9066 | unloading of a shared library will make the expression invalid. | |
9067 | This is not a very common use case, but we still re-evaluate | |
9068 | expression, to avoid surprises to the user. | |
9069 | ||
9070 | Note that for local watchpoints, we re-evaluate it only if | |
9071 | watchpoints frame id is still valid. If it's not, it means | |
9072 | the watchpoint is out of scope and will be deleted soon. In fact, | |
9073 | I'm not sure we'll ever be called in this case. | |
9074 | ||
9075 | If a local watchpoint's frame id is still valid, then | |
9076 | b->exp_valid_block is likewise valid, and we can safely use it. | |
9077 | ||
9078 | Don't do anything about disabled watchpoints, since they will | |
9079 | be reevaluated again when enabled. */ | |
a5606eee | 9080 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 9081 | break; |
c5aa993b JM |
9082 | /* We needn't really do anything to reset these, since the mask |
9083 | that requests them is unaffected by e.g., new libraries being | |
9084 | loaded. */ | |
ce78b96d | 9085 | case bp_catchpoint: |
c906108c | 9086 | break; |
c5aa993b | 9087 | |
c906108c | 9088 | default: |
a3f17187 | 9089 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 9090 | /* fall through */ |
0fd8e87f UW |
9091 | /* Delete overlay event and longjmp master breakpoints; they will be |
9092 | reset later by breakpoint_re_set. */ | |
1900040c | 9093 | case bp_overlay_event: |
0fd8e87f | 9094 | case bp_longjmp_master: |
c906108c SS |
9095 | delete_breakpoint (b); |
9096 | break; | |
9097 | ||
c5aa993b JM |
9098 | /* This breakpoint is special, it's set up when the inferior |
9099 | starts and we really don't want to touch it. */ | |
c906108c SS |
9100 | case bp_shlib_event: |
9101 | ||
c4093a6a JM |
9102 | /* Like bp_shlib_event, this breakpoint type is special. |
9103 | Once it is set up, we do not want to touch it. */ | |
9104 | case bp_thread_event: | |
9105 | ||
c5aa993b JM |
9106 | /* Keep temporary breakpoints, which can be encountered when we step |
9107 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
9108 | Otherwise these should have been blown away via the cleanup chain | |
9109 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
9110 | case bp_until: |
9111 | case bp_finish: | |
9112 | case bp_watchpoint_scope: | |
9113 | case bp_call_dummy: | |
9114 | case bp_step_resume: | |
611c83ae PA |
9115 | case bp_longjmp: |
9116 | case bp_longjmp_resume: | |
4efc6507 | 9117 | case bp_jit_event: |
c906108c SS |
9118 | break; |
9119 | } | |
9120 | ||
6c95b8df | 9121 | do_cleanups (cleanups); |
c906108c SS |
9122 | return 0; |
9123 | } | |
9124 | ||
69de3c6a | 9125 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 9126 | void |
69de3c6a | 9127 | breakpoint_re_set (void) |
c906108c SS |
9128 | { |
9129 | struct breakpoint *b, *temp; | |
9130 | enum language save_language; | |
9131 | int save_input_radix; | |
6c95b8df | 9132 | struct cleanup *old_chain; |
c5aa993b | 9133 | |
c906108c SS |
9134 | save_language = current_language->la_language; |
9135 | save_input_radix = input_radix; | |
6c95b8df PA |
9136 | old_chain = save_current_program_space (); |
9137 | ||
c906108c | 9138 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 9139 | { |
53a5351d | 9140 | /* Format possible error msg */ |
fe3f5fa8 | 9141 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
9142 | b->number); |
9143 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 9144 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 9145 | do_cleanups (cleanups); |
c5aa993b | 9146 | } |
c906108c SS |
9147 | set_language (save_language); |
9148 | input_radix = save_input_radix; | |
e62c965a | 9149 | |
0756c555 | 9150 | jit_breakpoint_re_set (); |
4efc6507 | 9151 | |
6c95b8df PA |
9152 | do_cleanups (old_chain); |
9153 | ||
69de3c6a | 9154 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
9155 | create_longjmp_master_breakpoint ("longjmp"); |
9156 | create_longjmp_master_breakpoint ("_longjmp"); | |
9157 | create_longjmp_master_breakpoint ("siglongjmp"); | |
9158 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
9159 | } |
9160 | \f | |
c906108c SS |
9161 | /* Reset the thread number of this breakpoint: |
9162 | ||
9163 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 9164 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 9165 | void |
fba45db2 | 9166 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
9167 | { |
9168 | if (b->thread != -1) | |
9169 | { | |
39f77062 KB |
9170 | if (in_thread_list (inferior_ptid)) |
9171 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
9172 | |
9173 | /* We're being called after following a fork. The new fork is | |
9174 | selected as current, and unless this was a vfork will have a | |
9175 | different program space from the original thread. Reset that | |
9176 | as well. */ | |
9177 | b->loc->pspace = current_program_space; | |
c906108c SS |
9178 | } |
9179 | } | |
9180 | ||
03ac34d5 MS |
9181 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9182 | If from_tty is nonzero, it prints a message to that effect, | |
9183 | which ends with a period (no newline). */ | |
9184 | ||
c906108c | 9185 | void |
fba45db2 | 9186 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 9187 | { |
52f0bd74 | 9188 | struct breakpoint *b; |
c906108c SS |
9189 | |
9190 | if (count < 0) | |
9191 | count = 0; | |
9192 | ||
9193 | ALL_BREAKPOINTS (b) | |
9194 | if (b->number == bptnum) | |
c5aa993b JM |
9195 | { |
9196 | b->ignore_count = count; | |
221ea385 KS |
9197 | if (from_tty) |
9198 | { | |
9199 | if (count == 0) | |
a3f17187 | 9200 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
9201 | bptnum); |
9202 | else if (count == 1) | |
a3f17187 | 9203 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
9204 | bptnum); |
9205 | else | |
a3f17187 | 9206 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
9207 | count, bptnum); |
9208 | } | |
c5aa993b | 9209 | breakpoints_changed (); |
383f836e | 9210 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
9211 | return; |
9212 | } | |
c906108c | 9213 | |
8a3fe4f8 | 9214 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
9215 | } |
9216 | ||
b2175913 MS |
9217 | void |
9218 | make_breakpoint_silent (struct breakpoint *b) | |
9219 | { | |
9220 | /* Silence the breakpoint. */ | |
9221 | b->silent = 1; | |
9222 | } | |
9223 | ||
c906108c SS |
9224 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9225 | ||
9226 | static void | |
fba45db2 | 9227 | ignore_command (char *args, int from_tty) |
c906108c SS |
9228 | { |
9229 | char *p = args; | |
52f0bd74 | 9230 | int num; |
c906108c SS |
9231 | |
9232 | if (p == 0) | |
e2e0b3e5 | 9233 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9234 | |
c906108c | 9235 | num = get_number (&p); |
5c44784c | 9236 | if (num == 0) |
8a3fe4f8 | 9237 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9238 | if (*p == 0) |
8a3fe4f8 | 9239 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9240 | |
9241 | set_ignore_count (num, | |
9242 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9243 | from_tty); | |
221ea385 KS |
9244 | if (from_tty) |
9245 | printf_filtered ("\n"); | |
c906108c SS |
9246 | } |
9247 | \f | |
9248 | /* Call FUNCTION on each of the breakpoints | |
9249 | whose numbers are given in ARGS. */ | |
9250 | ||
9251 | static void | |
831662b3 | 9252 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 9253 | { |
52f0bd74 | 9254 | char *p = args; |
c906108c | 9255 | char *p1; |
52f0bd74 AC |
9256 | int num; |
9257 | struct breakpoint *b, *tmp; | |
11cf8741 | 9258 | int match; |
c906108c SS |
9259 | |
9260 | if (p == 0) | |
e2e0b3e5 | 9261 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9262 | |
9263 | while (*p) | |
9264 | { | |
11cf8741 | 9265 | match = 0; |
c906108c | 9266 | p1 = p; |
c5aa993b | 9267 | |
5c44784c JM |
9268 | num = get_number_or_range (&p1); |
9269 | if (num == 0) | |
c5aa993b | 9270 | { |
8a3fe4f8 | 9271 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9272 | } |
9273 | else | |
9274 | { | |
9275 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9276 | if (b->number == num) | |
9277 | { | |
9278 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9279 | match = 1; |
5c44784c JM |
9280 | function (b); |
9281 | if (related_breakpoint) | |
9282 | function (related_breakpoint); | |
11cf8741 | 9283 | break; |
5c44784c | 9284 | } |
11cf8741 | 9285 | if (match == 0) |
a3f17187 | 9286 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9287 | } |
c906108c SS |
9288 | p = p1; |
9289 | } | |
9290 | } | |
9291 | ||
0d381245 VP |
9292 | static struct bp_location * |
9293 | find_location_by_number (char *number) | |
9294 | { | |
9295 | char *dot = strchr (number, '.'); | |
9296 | char *p1; | |
9297 | int bp_num; | |
9298 | int loc_num; | |
9299 | struct breakpoint *b; | |
9300 | struct bp_location *loc; | |
9301 | ||
9302 | *dot = '\0'; | |
9303 | ||
9304 | p1 = number; | |
9305 | bp_num = get_number_or_range (&p1); | |
9306 | if (bp_num == 0) | |
9307 | error (_("Bad breakpoint number '%s'"), number); | |
9308 | ||
9309 | ALL_BREAKPOINTS (b) | |
9310 | if (b->number == bp_num) | |
9311 | { | |
9312 | break; | |
9313 | } | |
9314 | ||
9315 | if (!b || b->number != bp_num) | |
9316 | error (_("Bad breakpoint number '%s'"), number); | |
9317 | ||
9318 | p1 = dot+1; | |
9319 | loc_num = get_number_or_range (&p1); | |
9320 | if (loc_num == 0) | |
9321 | error (_("Bad breakpoint location number '%s'"), number); | |
9322 | ||
9323 | --loc_num; | |
9324 | loc = b->loc; | |
9325 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9326 | ; | |
9327 | if (!loc) | |
9328 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9329 | ||
9330 | return loc; | |
9331 | } | |
9332 | ||
9333 | ||
1900040c MS |
9334 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9335 | If from_tty is nonzero, it prints a message to that effect, | |
9336 | which ends with a period (no newline). */ | |
9337 | ||
c906108c | 9338 | void |
fba45db2 | 9339 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9340 | { |
9341 | /* Never disable a watchpoint scope breakpoint; we want to | |
9342 | hit them when we leave scope so we can delete both the | |
9343 | watchpoint and its scope breakpoint at that time. */ | |
9344 | if (bpt->type == bp_watchpoint_scope) | |
9345 | return; | |
9346 | ||
c2c6d25f | 9347 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9348 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9349 | return; |
9350 | ||
b5de0fa7 | 9351 | bpt->enable_state = bp_disabled; |
c906108c | 9352 | |
b60e7edf | 9353 | update_global_location_list (0); |
c906108c | 9354 | |
383f836e | 9355 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9356 | } |
9357 | ||
c906108c | 9358 | static void |
fba45db2 | 9359 | disable_command (char *args, int from_tty) |
c906108c | 9360 | { |
52f0bd74 | 9361 | struct breakpoint *bpt; |
c906108c SS |
9362 | if (args == 0) |
9363 | ALL_BREAKPOINTS (bpt) | |
9364 | switch (bpt->type) | |
c5aa993b JM |
9365 | { |
9366 | case bp_none: | |
8a3fe4f8 | 9367 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9368 | bpt->number); |
c5aa993b JM |
9369 | continue; |
9370 | case bp_breakpoint: | |
1042e4c0 | 9371 | case bp_tracepoint: |
ce78b96d | 9372 | case bp_catchpoint: |
c5aa993b JM |
9373 | case bp_hardware_breakpoint: |
9374 | case bp_watchpoint: | |
9375 | case bp_hardware_watchpoint: | |
9376 | case bp_read_watchpoint: | |
9377 | case bp_access_watchpoint: | |
9378 | disable_breakpoint (bpt); | |
9379 | default: | |
9380 | continue; | |
9381 | } | |
0d381245 VP |
9382 | else if (strchr (args, '.')) |
9383 | { | |
9384 | struct bp_location *loc = find_location_by_number (args); | |
9385 | if (loc) | |
9386 | loc->enabled = 0; | |
b60e7edf | 9387 | update_global_location_list (0); |
0d381245 | 9388 | } |
c906108c SS |
9389 | else |
9390 | map_breakpoint_numbers (args, disable_breakpoint); | |
9391 | } | |
9392 | ||
9393 | static void | |
fba45db2 | 9394 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9395 | { |
c906108c SS |
9396 | int target_resources_ok, other_type_used; |
9397 | struct value *mark; | |
9398 | ||
9399 | if (bpt->type == bp_hardware_breakpoint) | |
9400 | { | |
9401 | int i; | |
c5aa993b | 9402 | i = hw_breakpoint_used_count (); |
53a5351d | 9403 | target_resources_ok = |
d92524f1 | 9404 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9405 | i + 1, 0); |
c906108c | 9406 | if (target_resources_ok == 0) |
8a3fe4f8 | 9407 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9408 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9409 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9410 | } |
9411 | ||
059fb39f PM |
9412 | if (bpt->type == bp_watchpoint |
9413 | || bpt->type == bp_hardware_watchpoint | |
9414 | || bpt->type == bp_read_watchpoint | |
9415 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9416 | { |
dde02812 ES |
9417 | struct gdb_exception e; |
9418 | ||
9419 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9420 | { |
dde02812 | 9421 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9422 | } |
dde02812 | 9423 | if (e.reason < 0) |
c5aa993b | 9424 | { |
dde02812 ES |
9425 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9426 | bpt->number); | |
9427 | return; | |
c5aa993b | 9428 | } |
c906108c | 9429 | } |
0101ce28 | 9430 | |
b4c291bb KH |
9431 | if (bpt->enable_state != bp_permanent) |
9432 | bpt->enable_state = bp_enabled; | |
9433 | bpt->disposition = disposition; | |
b60e7edf | 9434 | update_global_location_list (1); |
b4c291bb KH |
9435 | breakpoints_changed (); |
9436 | ||
383f836e | 9437 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9438 | } |
9439 | ||
fe3f5fa8 | 9440 | |
c906108c | 9441 | void |
fba45db2 | 9442 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9443 | { |
9444 | do_enable_breakpoint (bpt, bpt->disposition); | |
9445 | } | |
9446 | ||
9447 | /* The enable command enables the specified breakpoints (or all defined | |
9448 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 9449 | in stopping the inferior. */ |
c906108c | 9450 | |
c906108c | 9451 | static void |
fba45db2 | 9452 | enable_command (char *args, int from_tty) |
c906108c | 9453 | { |
52f0bd74 | 9454 | struct breakpoint *bpt; |
c906108c SS |
9455 | if (args == 0) |
9456 | ALL_BREAKPOINTS (bpt) | |
9457 | switch (bpt->type) | |
c5aa993b JM |
9458 | { |
9459 | case bp_none: | |
8a3fe4f8 | 9460 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 9461 | bpt->number); |
c5aa993b JM |
9462 | continue; |
9463 | case bp_breakpoint: | |
1042e4c0 | 9464 | case bp_tracepoint: |
ce78b96d | 9465 | case bp_catchpoint: |
c5aa993b JM |
9466 | case bp_hardware_breakpoint: |
9467 | case bp_watchpoint: | |
9468 | case bp_hardware_watchpoint: | |
9469 | case bp_read_watchpoint: | |
9470 | case bp_access_watchpoint: | |
9471 | enable_breakpoint (bpt); | |
9472 | default: | |
9473 | continue; | |
9474 | } | |
0d381245 VP |
9475 | else if (strchr (args, '.')) |
9476 | { | |
9477 | struct bp_location *loc = find_location_by_number (args); | |
9478 | if (loc) | |
9479 | loc->enabled = 1; | |
b60e7edf | 9480 | update_global_location_list (1); |
0d381245 | 9481 | } |
c906108c SS |
9482 | else |
9483 | map_breakpoint_numbers (args, enable_breakpoint); | |
9484 | } | |
9485 | ||
9486 | static void | |
fba45db2 | 9487 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 9488 | { |
b5de0fa7 | 9489 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
9490 | } |
9491 | ||
c906108c | 9492 | static void |
fba45db2 | 9493 | enable_once_command (char *args, int from_tty) |
c906108c SS |
9494 | { |
9495 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
9496 | } | |
9497 | ||
9498 | static void | |
fba45db2 | 9499 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9500 | { |
b5de0fa7 | 9501 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
9502 | } |
9503 | ||
c906108c | 9504 | static void |
fba45db2 | 9505 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
9506 | { |
9507 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
9508 | } | |
9509 | \f | |
fa8d40ab JJ |
9510 | static void |
9511 | set_breakpoint_cmd (char *args, int from_tty) | |
9512 | { | |
9513 | } | |
9514 | ||
9515 | static void | |
9516 | show_breakpoint_cmd (char *args, int from_tty) | |
9517 | { | |
9518 | } | |
9519 | ||
1f3b5d1b PP |
9520 | /* Invalidate last known value of any hardware watchpoint if |
9521 | the memory which that value represents has been written to by | |
9522 | GDB itself. */ | |
9523 | ||
9524 | static void | |
9525 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
9526 | const bfd_byte *data) | |
9527 | { | |
9528 | struct breakpoint *bp; | |
9529 | ||
9530 | ALL_BREAKPOINTS (bp) | |
9531 | if (bp->enable_state == bp_enabled | |
9532 | && bp->type == bp_hardware_watchpoint | |
9533 | && bp->val_valid && bp->val) | |
9534 | { | |
9535 | struct bp_location *loc; | |
9536 | ||
9537 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
9538 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
9539 | && loc->address + loc->length > addr | |
9540 | && addr + len > loc->address) | |
9541 | { | |
9542 | value_free (bp->val); | |
9543 | bp->val = NULL; | |
9544 | bp->val_valid = 0; | |
9545 | } | |
9546 | } | |
9547 | } | |
9548 | ||
c906108c SS |
9549 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
9550 | ||
9551 | struct symtabs_and_lines | |
fba45db2 | 9552 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
9553 | { |
9554 | struct symtabs_and_lines sals; | |
9555 | if (string == 0) | |
8a3fe4f8 | 9556 | error (_("Empty line specification.")); |
c906108c SS |
9557 | if (default_breakpoint_valid) |
9558 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
9559 | default_breakpoint_symtab, |
9560 | default_breakpoint_line, | |
68219205 | 9561 | (char ***) NULL, NULL); |
c906108c SS |
9562 | else |
9563 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 9564 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 9565 | if (*string) |
8a3fe4f8 | 9566 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
9567 | return sals; |
9568 | } | |
8181d85f DJ |
9569 | |
9570 | /* Create and insert a raw software breakpoint at PC. Return an | |
9571 | identifier, which should be used to remove the breakpoint later. | |
9572 | In general, places which call this should be using something on the | |
9573 | breakpoint chain instead; this function should be eliminated | |
9574 | someday. */ | |
9575 | ||
9576 | void * | |
6c95b8df PA |
9577 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
9578 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
9579 | { |
9580 | struct bp_target_info *bp_tgt; | |
9581 | ||
6c95b8df | 9582 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 9583 | |
6c95b8df | 9584 | bp_tgt->placed_address_space = aspace; |
8181d85f | 9585 | bp_tgt->placed_address = pc; |
6c95b8df | 9586 | |
a6d9a66e | 9587 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
9588 | { |
9589 | /* Could not insert the breakpoint. */ | |
9590 | xfree (bp_tgt); | |
9591 | return NULL; | |
9592 | } | |
9593 | ||
9594 | return bp_tgt; | |
9595 | } | |
9596 | ||
9597 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
9598 | ||
9599 | int | |
a6d9a66e | 9600 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
9601 | { |
9602 | struct bp_target_info *bp_tgt = bp; | |
9603 | int ret; | |
9604 | ||
a6d9a66e | 9605 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
9606 | xfree (bp_tgt); |
9607 | ||
9608 | return ret; | |
9609 | } | |
9610 | ||
9611 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
9612 | ||
9613 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 9614 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
9615 | |
9616 | /* Create and insert a breakpoint for software single step. */ | |
9617 | ||
9618 | void | |
6c95b8df PA |
9619 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
9620 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
9621 | { |
9622 | void **bpt_p; | |
9623 | ||
9624 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
9625 | { |
9626 | bpt_p = &single_step_breakpoints[0]; | |
9627 | single_step_gdbarch[0] = gdbarch; | |
9628 | } | |
8181d85f DJ |
9629 | else |
9630 | { | |
9631 | gdb_assert (single_step_breakpoints[1] == NULL); | |
9632 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 9633 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
9634 | } |
9635 | ||
9636 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
9637 | to only create the breakpoints once, and actually put them on the | |
9638 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
9639 | adjust the addresses each time they were needed. Doing this requires | |
9640 | corresponding changes elsewhere where single step breakpoints are | |
9641 | handled, however. So, for now, we use this. */ | |
9642 | ||
6c95b8df | 9643 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 9644 | if (*bpt_p == NULL) |
5af949e3 UW |
9645 | error (_("Could not insert single-step breakpoint at %s"), |
9646 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
9647 | } |
9648 | ||
9649 | /* Remove and delete any breakpoints used for software single step. */ | |
9650 | ||
9651 | void | |
9652 | remove_single_step_breakpoints (void) | |
9653 | { | |
9654 | gdb_assert (single_step_breakpoints[0] != NULL); | |
9655 | ||
9656 | /* See insert_single_step_breakpoint for more about this deprecated | |
9657 | call. */ | |
a6d9a66e UW |
9658 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
9659 | single_step_breakpoints[0]); | |
9660 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
9661 | single_step_breakpoints[0] = NULL; |
9662 | ||
9663 | if (single_step_breakpoints[1] != NULL) | |
9664 | { | |
a6d9a66e UW |
9665 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
9666 | single_step_breakpoints[1]); | |
9667 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
9668 | single_step_breakpoints[1] = NULL; |
9669 | } | |
9670 | } | |
9671 | ||
1aafd4da UW |
9672 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
9673 | ||
9674 | static int | |
6c95b8df | 9675 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
9676 | { |
9677 | int i; | |
9678 | ||
9679 | for (i = 0; i < 2; i++) | |
9680 | { | |
9681 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
9682 | if (bp_tgt |
9683 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
9684 | bp_tgt->placed_address, | |
9685 | aspace, pc)) | |
1aafd4da UW |
9686 | return 1; |
9687 | } | |
9688 | ||
9689 | return 0; | |
9690 | } | |
9691 | ||
a96d9b2e SDJ |
9692 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
9693 | non-zero otherwise. */ | |
9694 | static int | |
9695 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
9696 | { | |
9697 | if (syscall_catchpoint_p (bp) | |
9698 | && bp->enable_state != bp_disabled | |
9699 | && bp->enable_state != bp_call_disabled) | |
9700 | return 1; | |
9701 | else | |
9702 | return 0; | |
9703 | } | |
9704 | ||
9705 | int | |
9706 | catch_syscall_enabled (void) | |
9707 | { | |
9708 | struct inferior *inf = current_inferior (); | |
9709 | ||
9710 | return inf->total_syscalls_count != 0; | |
9711 | } | |
9712 | ||
9713 | int | |
9714 | catching_syscall_number (int syscall_number) | |
9715 | { | |
9716 | struct breakpoint *bp; | |
9717 | ||
9718 | ALL_BREAKPOINTS (bp) | |
9719 | if (is_syscall_catchpoint_enabled (bp)) | |
9720 | { | |
9721 | if (bp->syscalls_to_be_caught) | |
9722 | { | |
9723 | int i, iter; | |
9724 | for (i = 0; | |
9725 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
9726 | i++) | |
9727 | if (syscall_number == iter) | |
9728 | return 1; | |
9729 | } | |
9730 | else | |
9731 | return 1; | |
9732 | } | |
9733 | ||
9734 | return 0; | |
9735 | } | |
9736 | ||
9737 | /* Complete syscall names. Used by "catch syscall". */ | |
9738 | static char ** | |
9739 | catch_syscall_completer (struct cmd_list_element *cmd, | |
9740 | char *text, char *word) | |
9741 | { | |
9742 | const char **list = get_syscall_names (); | |
9743 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
9744 | } | |
9745 | ||
1042e4c0 SS |
9746 | /* Tracepoint-specific operations. */ |
9747 | ||
9748 | /* Set tracepoint count to NUM. */ | |
9749 | static void | |
9750 | set_tracepoint_count (int num) | |
9751 | { | |
9752 | tracepoint_count = num; | |
4fa62494 | 9753 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
9754 | } |
9755 | ||
9756 | void | |
9757 | trace_command (char *arg, int from_tty) | |
9758 | { | |
a6d9a66e UW |
9759 | break_command_really (get_current_arch (), |
9760 | arg, | |
1042e4c0 SS |
9761 | NULL, 0, 1 /* parse arg */, |
9762 | 0 /* tempflag */, 0 /* hardwareflag */, | |
9763 | 1 /* traceflag */, | |
9764 | 0 /* Ignore count */, | |
9765 | pending_break_support, | |
9766 | NULL, | |
9767 | from_tty, | |
9768 | 1 /* enabled */); | |
9769 | set_tracepoint_count (breakpoint_count); | |
9770 | } | |
9771 | ||
9772 | /* Print information on tracepoint number TPNUM_EXP, or all if | |
9773 | omitted. */ | |
9774 | ||
9775 | static void | |
9776 | tracepoints_info (char *tpnum_exp, int from_tty) | |
9777 | { | |
9778 | struct breakpoint *b; | |
9779 | int tps_to_list = 0; | |
9780 | ||
9781 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
9782 | if (tpnum_exp == 0) | |
9783 | { | |
9784 | ALL_TRACEPOINTS (b) | |
9785 | { | |
9786 | if (b->number >= 0) | |
9787 | { | |
9788 | tps_to_list = 1; | |
9789 | break; | |
9790 | } | |
9791 | } | |
9792 | if (!tps_to_list) | |
9793 | { | |
9794 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
9795 | return; | |
9796 | } | |
9797 | } | |
9798 | ||
9799 | /* Otherwise be the same as "info break". */ | |
9800 | breakpoints_info (tpnum_exp, from_tty); | |
9801 | } | |
9802 | ||
9803 | /* The 'enable trace' command enables tracepoints. | |
9804 | Not supported by all targets. */ | |
9805 | static void | |
9806 | enable_trace_command (char *args, int from_tty) | |
9807 | { | |
9808 | enable_command (args, from_tty); | |
9809 | } | |
9810 | ||
9811 | /* The 'disable trace' command disables tracepoints. | |
9812 | Not supported by all targets. */ | |
9813 | static void | |
9814 | disable_trace_command (char *args, int from_tty) | |
9815 | { | |
9816 | disable_command (args, from_tty); | |
9817 | } | |
9818 | ||
9819 | /* Remove a tracepoint (or all if no argument) */ | |
9820 | static void | |
9821 | delete_trace_command (char *arg, int from_tty) | |
9822 | { | |
9823 | struct breakpoint *b, *temp; | |
9824 | ||
9825 | dont_repeat (); | |
9826 | ||
9827 | if (arg == 0) | |
9828 | { | |
9829 | int breaks_to_delete = 0; | |
9830 | ||
9831 | /* Delete all breakpoints if no argument. | |
9832 | Do not delete internal or call-dummy breakpoints, these | |
9833 | have to be deleted with an explicit breakpoint number argument. */ | |
9834 | ALL_TRACEPOINTS (b) | |
9835 | { | |
9836 | if (b->number >= 0) | |
9837 | { | |
9838 | breaks_to_delete = 1; | |
9839 | break; | |
9840 | } | |
9841 | } | |
9842 | ||
9843 | /* Ask user only if there are some breakpoints to delete. */ | |
9844 | if (!from_tty | |
9845 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
9846 | { | |
9847 | ALL_BREAKPOINTS_SAFE (b, temp) | |
9848 | { | |
059fb39f PM |
9849 | if (b->type == bp_tracepoint |
9850 | && b->number >= 0) | |
1042e4c0 SS |
9851 | delete_breakpoint (b); |
9852 | } | |
9853 | } | |
9854 | } | |
9855 | else | |
9856 | map_breakpoint_numbers (arg, delete_breakpoint); | |
9857 | } | |
9858 | ||
9859 | /* Set passcount for tracepoint. | |
9860 | ||
9861 | First command argument is passcount, second is tracepoint number. | |
9862 | If tracepoint number omitted, apply to most recently defined. | |
9863 | Also accepts special argument "all". */ | |
9864 | ||
9865 | static void | |
9866 | trace_pass_command (char *args, int from_tty) | |
9867 | { | |
9868 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
9869 | unsigned int count; | |
9870 | int all = 0; | |
9871 | ||
9872 | if (args == 0 || *args == 0) | |
9873 | error (_("passcount command requires an argument (count + optional TP num)")); | |
9874 | ||
9875 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
9876 | ||
9877 | while (*args && isspace ((int) *args)) | |
9878 | args++; | |
9879 | ||
9880 | if (*args && strncasecmp (args, "all", 3) == 0) | |
9881 | { | |
9882 | args += 3; /* Skip special argument "all". */ | |
9883 | all = 1; | |
9884 | if (*args) | |
9885 | error (_("Junk at end of arguments.")); | |
9886 | } | |
9887 | else | |
9888 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
9889 | ||
9890 | do | |
9891 | { | |
9892 | if (t1) | |
9893 | { | |
9894 | ALL_TRACEPOINTS (t2) | |
9895 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
9896 | { | |
9897 | t2->pass_count = count; | |
9898 | observer_notify_tracepoint_modified (t2->number); | |
9899 | if (from_tty) | |
9900 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
9901 | t2->number, count); | |
9902 | } | |
9903 | if (! all && *args) | |
9904 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
9905 | } | |
9906 | } | |
9907 | while (*args); | |
9908 | } | |
9909 | ||
9910 | struct breakpoint * | |
9911 | get_tracepoint (int num) | |
9912 | { | |
9913 | struct breakpoint *t; | |
9914 | ||
9915 | ALL_TRACEPOINTS (t) | |
9916 | if (t->number == num) | |
9917 | return t; | |
9918 | ||
9919 | return NULL; | |
9920 | } | |
9921 | ||
9922 | /* Utility: parse a tracepoint number and look it up in the list. | |
9923 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
9924 | if OPTIONAL_P is true, then if the argument is missing, the most | |
9925 | recent tracepoint (tracepoint_count) is returned. */ | |
9926 | struct breakpoint * | |
9927 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
9928 | { | |
9929 | extern int tracepoint_count; | |
9930 | struct breakpoint *t; | |
9931 | int tpnum; | |
9932 | char *instring = arg == NULL ? NULL : *arg; | |
9933 | ||
9934 | if (arg == NULL || *arg == NULL || ! **arg) | |
9935 | { | |
9936 | if (optional_p) | |
9937 | tpnum = tracepoint_count; | |
9938 | else | |
9939 | error_no_arg (_("tracepoint number")); | |
9940 | } | |
9941 | else | |
9942 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
9943 | ||
9944 | if (tpnum <= 0) | |
9945 | { | |
9946 | if (instring && *instring) | |
9947 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
9948 | instring); | |
9949 | else | |
9950 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
9951 | return NULL; | |
9952 | } | |
9953 | ||
9954 | ALL_TRACEPOINTS (t) | |
9955 | if (t->number == tpnum) | |
9956 | { | |
9957 | return t; | |
9958 | } | |
9959 | ||
9960 | /* FIXME: if we are in the middle of a range we don't want to give | |
9961 | a message. The current interface to get_number_or_range doesn't | |
9962 | allow us to discover this. */ | |
9963 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
9964 | return NULL; | |
9965 | } | |
9966 | ||
9967 | /* save-tracepoints command */ | |
9968 | static void | |
9969 | tracepoint_save_command (char *args, int from_tty) | |
9970 | { | |
9971 | struct breakpoint *tp; | |
9972 | int any_tp = 0; | |
9973 | struct action_line *line; | |
9974 | FILE *fp; | |
9975 | char *i1 = " ", *i2 = " "; | |
9976 | char *indent, *actionline, *pathname; | |
9977 | char tmp[40]; | |
9978 | struct cleanup *cleanup; | |
9979 | ||
9980 | if (args == 0 || *args == 0) | |
9981 | error (_("Argument required (file name in which to save tracepoints)")); | |
9982 | ||
9983 | /* See if we have anything to save. */ | |
9984 | ALL_TRACEPOINTS (tp) | |
9985 | { | |
9986 | any_tp = 1; | |
9987 | break; | |
9988 | } | |
9989 | if (!any_tp) | |
9990 | { | |
9991 | warning (_("save-tracepoints: no tracepoints to save.")); | |
9992 | return; | |
9993 | } | |
9994 | ||
9995 | pathname = tilde_expand (args); | |
9996 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
9997 | fp = fopen (pathname, "w"); |
9998 | if (!fp) | |
1042e4c0 SS |
9999 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
10000 | args, safe_strerror (errno)); | |
10001 | make_cleanup_fclose (fp); | |
10002 | ||
10003 | ALL_TRACEPOINTS (tp) | |
10004 | { | |
10005 | if (tp->addr_string) | |
10006 | fprintf (fp, "trace %s\n", tp->addr_string); | |
10007 | else | |
10008 | { | |
10009 | sprintf_vma (tmp, tp->loc->address); | |
10010 | fprintf (fp, "trace *0x%s\n", tmp); | |
10011 | } | |
10012 | ||
10013 | if (tp->pass_count) | |
10014 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
10015 | ||
10016 | if (tp->actions) | |
10017 | { | |
10018 | fprintf (fp, " actions\n"); | |
10019 | indent = i1; | |
10020 | for (line = tp->actions; line; line = line->next) | |
10021 | { | |
10022 | struct cmd_list_element *cmd; | |
10023 | ||
10024 | QUIT; /* allow user to bail out with ^C */ | |
10025 | actionline = line->action; | |
10026 | while (isspace ((int) *actionline)) | |
10027 | actionline++; | |
10028 | ||
10029 | fprintf (fp, "%s%s\n", indent, actionline); | |
10030 | if (*actionline != '#') /* skip for comment lines */ | |
10031 | { | |
10032 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
10033 | if (cmd == 0) | |
10034 | error (_("Bad action list item: %s"), actionline); | |
10035 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
10036 | indent = i2; | |
10037 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
10038 | indent = i1; | |
10039 | } | |
10040 | } | |
10041 | } | |
10042 | } | |
10043 | do_cleanups (cleanup); | |
10044 | if (from_tty) | |
10045 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
10046 | return; | |
10047 | } | |
10048 | ||
10049 | /* Create a vector of all tracepoints. */ | |
10050 | ||
10051 | VEC(breakpoint_p) * | |
10052 | all_tracepoints () | |
10053 | { | |
10054 | VEC(breakpoint_p) *tp_vec = 0; | |
10055 | struct breakpoint *tp; | |
10056 | ||
10057 | ALL_TRACEPOINTS (tp) | |
10058 | { | |
10059 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
10060 | } | |
10061 | ||
10062 | return tp_vec; | |
10063 | } | |
10064 | ||
c906108c | 10065 | \f |
31e2b00f AS |
10066 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
10067 | It is defined as a macro to prevent duplication. | |
10068 | COMMAND should be a string constant containing the name of the command. */ | |
10069 | #define BREAK_ARGS_HELP(command) \ | |
10070 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
10071 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
10072 | If a line number is specified, break at start of code for that line.\n\ | |
10073 | If a function is specified, break at start of code for that function.\n\ | |
10074 | If an address is specified, break at that exact address.\n\ | |
10075 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
10076 | This is useful for breaking on return to a stack frame.\n\ | |
10077 | \n\ | |
10078 | THREADNUM is the number from \"info threads\".\n\ | |
10079 | CONDITION is a boolean expression.\n\ | |
10080 | \n\ | |
10081 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
10082 | \n\ | |
10083 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
10084 | ||
44feb3ce TT |
10085 | /* List of subcommands for "catch". */ |
10086 | static struct cmd_list_element *catch_cmdlist; | |
10087 | ||
10088 | /* List of subcommands for "tcatch". */ | |
10089 | static struct cmd_list_element *tcatch_cmdlist; | |
10090 | ||
10091 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
10092 | lists, and pass some additional user data to the command function. */ | |
10093 | static void | |
10094 | add_catch_command (char *name, char *docstring, | |
10095 | void (*sfunc) (char *args, int from_tty, | |
10096 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
10097 | char **(*completer) (struct cmd_list_element *cmd, |
10098 | char *text, char *word), | |
44feb3ce TT |
10099 | void *user_data_catch, |
10100 | void *user_data_tcatch) | |
10101 | { | |
10102 | struct cmd_list_element *command; | |
10103 | ||
10104 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10105 | &catch_cmdlist); | |
10106 | set_cmd_sfunc (command, sfunc); | |
10107 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 10108 | set_cmd_completer (command, completer); |
44feb3ce TT |
10109 | |
10110 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10111 | &tcatch_cmdlist); | |
10112 | set_cmd_sfunc (command, sfunc); | |
10113 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 10114 | set_cmd_completer (command, completer); |
44feb3ce TT |
10115 | } |
10116 | ||
6c95b8df PA |
10117 | static void |
10118 | clear_syscall_counts (int pid) | |
10119 | { | |
10120 | struct inferior *inf = find_inferior_pid (pid); | |
10121 | ||
10122 | inf->total_syscalls_count = 0; | |
10123 | inf->any_syscall_count = 0; | |
10124 | VEC_free (int, inf->syscalls_counts); | |
10125 | } | |
10126 | ||
c906108c | 10127 | void |
fba45db2 | 10128 | _initialize_breakpoint (void) |
c906108c | 10129 | { |
fa8d40ab JJ |
10130 | static struct cmd_list_element *breakpoint_set_cmdlist; |
10131 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
10132 | struct cmd_list_element *c; |
10133 | ||
84acb35a | 10134 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 10135 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 10136 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 10137 | |
c906108c SS |
10138 | breakpoint_chain = 0; |
10139 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
10140 | before a breakpoint is set. */ | |
10141 | breakpoint_count = 0; | |
10142 | ||
1042e4c0 SS |
10143 | tracepoint_count = 0; |
10144 | ||
1bedd215 AC |
10145 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
10146 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
10147 | Usage is `ignore N COUNT'.")); | |
c906108c | 10148 | if (xdb_commands) |
c5aa993b | 10149 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 10150 | |
1bedd215 AC |
10151 | add_com ("commands", class_breakpoint, commands_command, _("\ |
10152 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
10153 | Give breakpoint number as argument after \"commands\".\n\ |
10154 | With no argument, the targeted breakpoint is the last one set.\n\ | |
10155 | The commands themselves follow starting on the next line.\n\ | |
10156 | Type a line containing \"end\" to indicate the end of them.\n\ | |
10157 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 10158 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 10159 | |
1bedd215 AC |
10160 | add_com ("condition", class_breakpoint, condition_command, _("\ |
10161 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 10162 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 10163 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 10164 | |
1bedd215 | 10165 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 10166 | Set a temporary breakpoint.\n\ |
c906108c SS |
10167 | Like \"break\" except the breakpoint is only temporary,\n\ |
10168 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
10169 | by using \"enable delete\" on the breakpoint number.\n\ |
10170 | \n" | |
10171 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 10172 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10173 | |
1bedd215 | 10174 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 10175 | Set a hardware assisted breakpoint.\n\ |
c906108c | 10176 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
10177 | some target hardware may not have this support.\n\ |
10178 | \n" | |
10179 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 10180 | set_cmd_completer (c, location_completer); |
c906108c | 10181 | |
1bedd215 | 10182 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 10183 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 10184 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
10185 | so it will be deleted when hit.\n\ |
10186 | \n" | |
10187 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 10188 | set_cmd_completer (c, location_completer); |
c906108c | 10189 | |
1bedd215 AC |
10190 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
10191 | Enable some breakpoints.\n\ | |
c906108c SS |
10192 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10193 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10194 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10195 | With a subcommand you can enable temporarily."), |
c906108c SS |
10196 | &enablelist, "enable ", 1, &cmdlist); |
10197 | if (xdb_commands) | |
1bedd215 AC |
10198 | add_com ("ab", class_breakpoint, enable_command, _("\ |
10199 | Enable some breakpoints.\n\ | |
c906108c SS |
10200 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10201 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10202 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10203 | With a subcommand you can enable temporarily.")); |
c906108c SS |
10204 | |
10205 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
10206 | ||
1bedd215 AC |
10207 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
10208 | Enable some breakpoints.\n\ | |
c906108c SS |
10209 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10210 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10211 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 10212 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 10213 | |
1a966eab AC |
10214 | add_cmd ("once", no_class, enable_once_command, _("\ |
10215 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10216 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10217 | &enablebreaklist); |
10218 | ||
1a966eab AC |
10219 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10220 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10221 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10222 | &enablebreaklist); |
10223 | ||
1a966eab AC |
10224 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10225 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10226 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10227 | &enablelist); |
10228 | ||
1a966eab AC |
10229 | add_cmd ("once", no_class, enable_once_command, _("\ |
10230 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10231 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10232 | &enablelist); |
10233 | ||
1bedd215 AC |
10234 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
10235 | Disable some breakpoints.\n\ | |
c906108c SS |
10236 | Arguments are breakpoint numbers with spaces in between.\n\ |
10237 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10238 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
10239 | &disablelist, "disable ", 1, &cmdlist); |
10240 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
10241 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
10242 | if (xdb_commands) | |
1bedd215 AC |
10243 | add_com ("sb", class_breakpoint, disable_command, _("\ |
10244 | Disable some breakpoints.\n\ | |
c906108c SS |
10245 | Arguments are breakpoint numbers with spaces in between.\n\ |
10246 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10247 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 10248 | |
1a966eab AC |
10249 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10250 | Disable some breakpoints.\n\ | |
c906108c SS |
10251 | Arguments are breakpoint numbers with spaces in between.\n\ |
10252 | To disable all breakpoints, give no argument.\n\ | |
10253 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10254 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10255 | &disablelist); |
10256 | ||
1bedd215 AC |
10257 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10258 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10259 | Arguments are breakpoint numbers with spaces in between.\n\ |
10260 | To delete all breakpoints, give no argument.\n\ | |
10261 | \n\ | |
10262 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10263 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10264 | &deletelist, "delete ", 1, &cmdlist); |
10265 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10266 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10267 | if (xdb_commands) |
1bedd215 AC |
10268 | add_com ("db", class_breakpoint, delete_command, _("\ |
10269 | Delete some breakpoints.\n\ | |
c906108c | 10270 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10271 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10272 | |
1a966eab AC |
10273 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10274 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10275 | Arguments are breakpoint numbers with spaces in between.\n\ |
10276 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10277 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10278 | &deletelist); |
10279 | ||
1bedd215 AC |
10280 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10281 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10282 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10283 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10284 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10285 | If an address is specified, breakpoints at that address are cleared.\n\ |
10286 | \n\ | |
10287 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10288 | is executing in.\n\ |
10289 | \n\ | |
1bedd215 | 10290 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10291 | |
1bedd215 | 10292 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10293 | Set breakpoint at specified line or function.\n" |
10294 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10295 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10296 | |
c906108c SS |
10297 | add_com_alias ("b", "break", class_run, 1); |
10298 | add_com_alias ("br", "break", class_run, 1); | |
10299 | add_com_alias ("bre", "break", class_run, 1); | |
10300 | add_com_alias ("brea", "break", class_run, 1); | |
10301 | ||
7681d515 PM |
10302 | if (xdb_commands) |
10303 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
10304 | |
10305 | if (dbx_commands) | |
10306 | { | |
1bedd215 AC |
10307 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
10308 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
10309 | &stoplist, "stop ", 1, &cmdlist); |
10310 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 10311 | _("Break in function or address."), &stoplist); |
c5aa993b | 10312 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 10313 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
10314 | add_com ("status", class_info, breakpoints_info, _("\ |
10315 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10316 | The \"Type\" column indicates one of:\n\ |
10317 | \tbreakpoint - normal breakpoint\n\ | |
10318 | \twatchpoint - watchpoint\n\ | |
10319 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10320 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10321 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10322 | address and file/line number respectively.\n\ |
10323 | \n\ | |
10324 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10325 | are set to the address of the last breakpoint listed unless the command\n\ |
10326 | is prefixed with \"server \".\n\n\ | |
c906108c | 10327 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10328 | breakpoint set.")); |
c906108c SS |
10329 | } |
10330 | ||
1bedd215 AC |
10331 | add_info ("breakpoints", breakpoints_info, _("\ |
10332 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10333 | The \"Type\" column indicates one of:\n\ |
10334 | \tbreakpoint - normal breakpoint\n\ | |
10335 | \twatchpoint - watchpoint\n\ | |
10336 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10337 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10338 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10339 | address and file/line number respectively.\n\ |
10340 | \n\ | |
10341 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10342 | are set to the address of the last breakpoint listed unless the command\n\ |
10343 | is prefixed with \"server \".\n\n\ | |
c906108c | 10344 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10345 | breakpoint set.")); |
c906108c | 10346 | |
6b04bdb7 MS |
10347 | add_info_alias ("b", "breakpoints", 1); |
10348 | ||
c906108c | 10349 | if (xdb_commands) |
1bedd215 AC |
10350 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
10351 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10352 | The \"Type\" column indicates one of:\n\ |
10353 | \tbreakpoint - normal breakpoint\n\ | |
10354 | \twatchpoint - watchpoint\n\ | |
10355 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10356 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10357 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10358 | address and file/line number respectively.\n\ |
10359 | \n\ | |
10360 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10361 | are set to the address of the last breakpoint listed unless the command\n\ |
10362 | is prefixed with \"server \".\n\n\ | |
c906108c | 10363 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10364 | breakpoint set.")); |
c906108c | 10365 | |
1a966eab AC |
10366 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
10367 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10368 | The \"Type\" column indicates one of:\n\ |
10369 | \tbreakpoint - normal breakpoint\n\ | |
10370 | \twatchpoint - watchpoint\n\ | |
10371 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
10372 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
10373 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
10374 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
10375 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
10376 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
10377 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
10378 | address and file/line number respectively.\n\ |
10379 | \n\ | |
10380 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10381 | are set to the address of the last breakpoint listed unless the command\n\ |
10382 | is prefixed with \"server \".\n\n\ | |
c906108c | 10383 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 10384 | breakpoint set."), |
c906108c SS |
10385 | &maintenanceinfolist); |
10386 | ||
44feb3ce TT |
10387 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
10388 | Set catchpoints to catch events."), | |
10389 | &catch_cmdlist, "catch ", | |
10390 | 0/*allow-unknown*/, &cmdlist); | |
10391 | ||
10392 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
10393 | Set temporary catchpoints to catch events."), | |
10394 | &tcatch_cmdlist, "tcatch ", | |
10395 | 0/*allow-unknown*/, &cmdlist); | |
10396 | ||
10397 | /* Add catch and tcatch sub-commands. */ | |
10398 | add_catch_command ("catch", _("\ | |
10399 | Catch an exception, when caught.\n\ | |
10400 | With an argument, catch only exceptions with the given name."), | |
10401 | catch_catch_command, | |
a96d9b2e | 10402 | NULL, |
44feb3ce TT |
10403 | CATCH_PERMANENT, |
10404 | CATCH_TEMPORARY); | |
10405 | add_catch_command ("throw", _("\ | |
10406 | Catch an exception, when thrown.\n\ | |
10407 | With an argument, catch only exceptions with the given name."), | |
10408 | catch_throw_command, | |
a96d9b2e | 10409 | NULL, |
44feb3ce TT |
10410 | CATCH_PERMANENT, |
10411 | CATCH_TEMPORARY); | |
10412 | add_catch_command ("fork", _("Catch calls to fork."), | |
10413 | catch_fork_command_1, | |
a96d9b2e | 10414 | NULL, |
44feb3ce TT |
10415 | (void *) (uintptr_t) catch_fork_permanent, |
10416 | (void *) (uintptr_t) catch_fork_temporary); | |
10417 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
10418 | catch_fork_command_1, | |
a96d9b2e | 10419 | NULL, |
44feb3ce TT |
10420 | (void *) (uintptr_t) catch_vfork_permanent, |
10421 | (void *) (uintptr_t) catch_vfork_temporary); | |
10422 | add_catch_command ("exec", _("Catch calls to exec."), | |
10423 | catch_exec_command_1, | |
a96d9b2e SDJ |
10424 | NULL, |
10425 | CATCH_PERMANENT, | |
10426 | CATCH_TEMPORARY); | |
10427 | add_catch_command ("syscall", _("\ | |
10428 | Catch system calls by their names and/or numbers.\n\ | |
10429 | Arguments say which system calls to catch. If no arguments\n\ | |
10430 | are given, every system call will be caught.\n\ | |
10431 | Arguments, if given, should be one or more system call names\n\ | |
10432 | (if your system supports that), or system call numbers."), | |
10433 | catch_syscall_command_1, | |
10434 | catch_syscall_completer, | |
44feb3ce TT |
10435 | CATCH_PERMANENT, |
10436 | CATCH_TEMPORARY); | |
44feb3ce TT |
10437 | add_catch_command ("exception", _("\ |
10438 | Catch Ada exceptions, when raised.\n\ | |
10439 | With an argument, catch only exceptions with the given name."), | |
10440 | catch_ada_exception_command, | |
a96d9b2e | 10441 | NULL, |
44feb3ce TT |
10442 | CATCH_PERMANENT, |
10443 | CATCH_TEMPORARY); | |
10444 | add_catch_command ("assert", _("\ | |
10445 | Catch failed Ada assertions, when raised.\n\ | |
10446 | With an argument, catch only exceptions with the given name."), | |
10447 | catch_assert_command, | |
a96d9b2e | 10448 | NULL, |
44feb3ce TT |
10449 | CATCH_PERMANENT, |
10450 | CATCH_TEMPORARY); | |
c5aa993b | 10451 | |
1bedd215 AC |
10452 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
10453 | Set a watchpoint for an expression.\n\ | |
c906108c | 10454 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10455 | an expression changes.")); |
65d12d83 | 10456 | set_cmd_completer (c, expression_completer); |
c906108c | 10457 | |
1bedd215 AC |
10458 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
10459 | Set a read watchpoint for an expression.\n\ | |
c906108c | 10460 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10461 | an expression is read.")); |
65d12d83 | 10462 | set_cmd_completer (c, expression_completer); |
c906108c | 10463 | |
1bedd215 AC |
10464 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
10465 | Set a watchpoint for an expression.\n\ | |
c906108c | 10466 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10467 | an expression is either read or written.")); |
65d12d83 | 10468 | set_cmd_completer (c, expression_completer); |
c906108c SS |
10469 | |
10470 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 10471 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
10472 | |
10473 | ||
920d2a44 AC |
10474 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
10475 | respond to changes - contrary to the description. */ | |
85c07804 AC |
10476 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
10477 | &can_use_hw_watchpoints, _("\ | |
10478 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
10479 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
10480 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
10481 | such is available. (However, any hardware watchpoints that were\n\ | |
10482 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
10483 | hardware.)"), |
10484 | NULL, | |
920d2a44 | 10485 | show_can_use_hw_watchpoints, |
85c07804 | 10486 | &setlist, &showlist); |
c906108c SS |
10487 | |
10488 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 10489 | |
1042e4c0 SS |
10490 | /* Tracepoint manipulation commands. */ |
10491 | ||
10492 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
10493 | Set a tracepoint at specified line or function.\n\ | |
10494 | \n" | |
10495 | BREAK_ARGS_HELP ("trace") "\n\ | |
10496 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
10497 | set_cmd_completer (c, location_completer); | |
10498 | ||
10499 | add_com_alias ("tp", "trace", class_alias, 0); | |
10500 | add_com_alias ("tr", "trace", class_alias, 1); | |
10501 | add_com_alias ("tra", "trace", class_alias, 1); | |
10502 | add_com_alias ("trac", "trace", class_alias, 1); | |
10503 | ||
10504 | add_info ("tracepoints", tracepoints_info, _("\ | |
10505 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
10506 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
10507 | last tracepoint set.")); | |
10508 | ||
10509 | add_info_alias ("tp", "tracepoints", 1); | |
10510 | ||
10511 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
10512 | Delete specified tracepoints.\n\ | |
10513 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10514 | No argument means delete all tracepoints."), | |
10515 | &deletelist); | |
10516 | ||
10517 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
10518 | Disable specified tracepoints.\n\ | |
10519 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10520 | No argument means disable all tracepoints."), | |
10521 | &disablelist); | |
10522 | deprecate_cmd (c, "disable"); | |
10523 | ||
10524 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
10525 | Enable specified tracepoints.\n\ | |
10526 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10527 | No argument means enable all tracepoints."), | |
10528 | &enablelist); | |
10529 | deprecate_cmd (c, "enable"); | |
10530 | ||
10531 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
10532 | Set the passcount for a tracepoint.\n\ | |
10533 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
10534 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
10535 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
10536 | ||
10537 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
10538 | Save current tracepoint definitions as a script.\n\ | |
10539 | Use the 'source' command in another debug session to restore them.")); | |
10540 | set_cmd_completer (c, filename_completer); | |
10541 | ||
1bedd215 | 10542 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10543 | Breakpoint specific settings\n\ |
10544 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10545 | pending breakpoint behavior"), |
fa8d40ab JJ |
10546 | &breakpoint_set_cmdlist, "set breakpoint ", |
10547 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 10548 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10549 | Breakpoint specific settings\n\ |
10550 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10551 | pending breakpoint behavior"), |
fa8d40ab JJ |
10552 | &breakpoint_show_cmdlist, "show breakpoint ", |
10553 | 0/*allow-unknown*/, &showlist); | |
10554 | ||
7915a72c AC |
10555 | add_setshow_auto_boolean_cmd ("pending", no_class, |
10556 | &pending_break_support, _("\ | |
10557 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
10558 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
10559 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
10560 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
10561 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 10562 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 10563 | NULL, |
920d2a44 | 10564 | show_pending_break_support, |
6e1d7d6c AC |
10565 | &breakpoint_set_cmdlist, |
10566 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
10567 | |
10568 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
10569 | |
10570 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
10571 | &automatic_hardware_breakpoints, _("\ | |
10572 | Set automatic usage of hardware breakpoints."), _("\ | |
10573 | Show automatic usage of hardware breakpoints."), _("\ | |
10574 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
10575 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
10576 | a warning will be emitted for such breakpoints."), | |
10577 | NULL, | |
10578 | show_automatic_hardware_breakpoints, | |
10579 | &breakpoint_set_cmdlist, | |
10580 | &breakpoint_show_cmdlist); | |
74960c60 | 10581 | |
33e5cbd6 PA |
10582 | add_setshow_enum_cmd ("always-inserted", class_support, |
10583 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
10584 | Set mode for inserting breakpoints."), _("\ |
10585 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
10586 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
10587 | resumed, and removed when execution stops. When this mode is on,\n\ | |
10588 | breakpoints are inserted immediately and removed only when the user\n\ | |
10589 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
10590 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
10591 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
10592 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
10593 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
10594 | NULL, |
10595 | &show_always_inserted_mode, | |
10596 | &breakpoint_set_cmdlist, | |
10597 | &breakpoint_show_cmdlist); | |
765dc015 VP |
10598 | |
10599 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
10600 | |
10601 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 10602 | } |