]>
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 | ||
85d721b8 PA |
130 | static int watchpoint_locations_match (struct bp_location *loc1, |
131 | struct bp_location *loc2); | |
132 | ||
a14ed312 | 133 | static void breakpoints_info (char *, int); |
c906108c | 134 | |
a14ed312 | 135 | static void breakpoint_1 (int, int); |
c906108c | 136 | |
89f9893c | 137 | static bpstat bpstat_alloc (const struct bp_location *, bpstat); |
c906108c | 138 | |
4efb68b1 | 139 | static int breakpoint_cond_eval (void *); |
c906108c | 140 | |
4efb68b1 | 141 | static void cleanup_executing_breakpoints (void *); |
c906108c | 142 | |
a14ed312 | 143 | static void commands_command (char *, int); |
c906108c | 144 | |
a14ed312 | 145 | static void condition_command (char *, int); |
c906108c | 146 | |
a14ed312 | 147 | static int get_number_trailer (char **, int); |
c906108c | 148 | |
a14ed312 | 149 | void set_breakpoint_count (int); |
c906108c | 150 | |
c5aa993b JM |
151 | typedef enum |
152 | { | |
153 | mark_inserted, | |
154 | mark_uninserted | |
155 | } | |
156 | insertion_state_t; | |
c906108c | 157 | |
0bde7532 | 158 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 159 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 160 | |
a14ed312 | 161 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
162 | |
163 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 164 | |
4efb68b1 | 165 | static int watchpoint_check (void *); |
c906108c | 166 | |
a14ed312 | 167 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 168 | |
a14ed312 | 169 | static int hw_breakpoint_used_count (void); |
c906108c | 170 | |
a14ed312 | 171 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 172 | |
a14ed312 | 173 | static void hbreak_command (char *, int); |
c906108c | 174 | |
a14ed312 | 175 | static void thbreak_command (char *, int); |
c906108c | 176 | |
a14ed312 | 177 | static void watch_command_1 (char *, int, int); |
c906108c | 178 | |
a14ed312 | 179 | static void rwatch_command (char *, int); |
c906108c | 180 | |
a14ed312 | 181 | static void awatch_command (char *, int); |
c906108c | 182 | |
a14ed312 | 183 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 184 | |
a14ed312 | 185 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 186 | |
a14ed312 | 187 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 188 | |
a14ed312 | 189 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 190 | |
a14ed312 | 191 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 192 | |
d85310f7 MS |
193 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
194 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 195 | |
a14ed312 | 196 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 197 | |
a14ed312 | 198 | static void ep_skip_leading_whitespace (char **s); |
7a292a7a | 199 | |
6c95b8df PA |
200 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
201 | CORE_ADDR pc); | |
1aafd4da | 202 | |
fe3f5fa8 VP |
203 | static void free_bp_location (struct bp_location *loc); |
204 | ||
39d61571 | 205 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 206 | |
b60e7edf | 207 | static void update_global_location_list (int); |
a5606eee | 208 | |
b60e7edf | 209 | static void update_global_location_list_nothrow (int); |
74960c60 VP |
210 | |
211 | static int is_hardware_watchpoint (struct breakpoint *bpt); | |
212 | ||
213 | static void insert_breakpoint_locations (void); | |
a5606eee | 214 | |
a96d9b2e SDJ |
215 | static int syscall_catchpoint_p (struct breakpoint *b); |
216 | ||
1042e4c0 SS |
217 | static void tracepoints_info (char *, int); |
218 | ||
219 | static void delete_trace_command (char *, int); | |
220 | ||
221 | static void enable_trace_command (char *, int); | |
222 | ||
223 | static void disable_trace_command (char *, int); | |
224 | ||
225 | static void trace_pass_command (char *, int); | |
226 | ||
3daf8fe5 JG |
227 | static void skip_prologue_sal (struct symtab_and_line *sal); |
228 | ||
229 | ||
f3b1572e PA |
230 | /* Flag indicating that a command has proceeded the inferior past the |
231 | current breakpoint. */ | |
232 | ||
233 | static int breakpoint_proceeded; | |
234 | ||
2cec12e5 AR |
235 | static const char * |
236 | bpdisp_text (enum bpdisp disp) | |
237 | { | |
238 | /* NOTE: the following values are a part of MI protocol and represent | |
239 | values of 'disp' field returned when inferior stops at a breakpoint. */ | |
240 | static char *bpdisps[] = {"del", "dstp", "dis", "keep"}; | |
241 | return bpdisps[(int) disp]; | |
242 | } | |
c906108c | 243 | |
2cec12e5 | 244 | /* Prototypes for exported functions. */ |
c906108c SS |
245 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
246 | if such is available. */ | |
247 | static int can_use_hw_watchpoints; | |
248 | ||
920d2a44 AC |
249 | static void |
250 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
251 | struct cmd_list_element *c, | |
252 | const char *value) | |
253 | { | |
254 | fprintf_filtered (file, _("\ | |
255 | Debugger's willingness to use watchpoint hardware is %s.\n"), | |
256 | value); | |
257 | } | |
258 | ||
fa8d40ab JJ |
259 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
260 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
261 | for unrecognized breakpoint locations. | |
262 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ | |
263 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
264 | static void |
265 | show_pending_break_support (struct ui_file *file, int from_tty, | |
266 | struct cmd_list_element *c, | |
267 | const char *value) | |
268 | { | |
269 | fprintf_filtered (file, _("\ | |
270 | Debugger's behavior regarding pending breakpoints is %s.\n"), | |
271 | value); | |
272 | } | |
fa8d40ab | 273 | |
765dc015 VP |
274 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
275 | set with "break" but falling in read-only memory. | |
276 | If 0, gdb will warn about such breakpoints, but won't automatically | |
277 | use hardware breakpoints. */ | |
278 | static int automatic_hardware_breakpoints; | |
279 | static void | |
280 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
281 | struct cmd_list_element *c, | |
282 | const char *value) | |
283 | { | |
284 | fprintf_filtered (file, _("\ | |
285 | Automatic usage of hardware breakpoints is %s.\n"), | |
286 | value); | |
287 | } | |
288 | ||
33e5cbd6 PA |
289 | /* If on, gdb will keep breakpoints inserted even as inferior is |
290 | stopped, and immediately insert any new breakpoints. If off, gdb | |
291 | will insert breakpoints into inferior only when resuming it, and | |
292 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
293 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
294 | ||
295 | static const char always_inserted_auto[] = "auto"; | |
296 | static const char always_inserted_on[] = "on"; | |
297 | static const char always_inserted_off[] = "off"; | |
298 | static const char *always_inserted_enums[] = { | |
299 | always_inserted_auto, | |
300 | always_inserted_off, | |
301 | always_inserted_on, | |
302 | NULL | |
303 | }; | |
304 | static const char *always_inserted_mode = always_inserted_auto; | |
305 | static void | |
74960c60 | 306 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 307 | struct cmd_list_element *c, const char *value) |
74960c60 | 308 | { |
33e5cbd6 PA |
309 | if (always_inserted_mode == always_inserted_auto) |
310 | fprintf_filtered (file, _("\ | |
311 | Always inserted breakpoint mode is %s (currently %s).\n"), | |
312 | value, | |
313 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
314 | else | |
315 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), value); | |
74960c60 VP |
316 | } |
317 | ||
33e5cbd6 PA |
318 | int |
319 | breakpoints_always_inserted_mode (void) | |
320 | { | |
321 | return (always_inserted_mode == always_inserted_on | |
322 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
323 | } | |
765dc015 | 324 | |
a14ed312 | 325 | void _initialize_breakpoint (void); |
c906108c | 326 | |
c906108c SS |
327 | /* Are we executing breakpoint commands? */ |
328 | static int executing_breakpoint_commands; | |
329 | ||
c02f5703 MS |
330 | /* Are overlay event breakpoints enabled? */ |
331 | static int overlay_events_enabled; | |
332 | ||
c906108c SS |
333 | /* Walk the following statement or block through all breakpoints. |
334 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the current | |
335 | breakpoint. */ | |
336 | ||
5c44784c | 337 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 338 | |
5c44784c JM |
339 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
340 | for (B = breakpoint_chain; \ | |
341 | B ? (TMP=B->next, 1): 0; \ | |
342 | B = TMP) | |
c906108c | 343 | |
876fa593 JK |
344 | /* Similar iterator for the low-level breakpoints. SAFE variant is not |
345 | provided so update_global_location_list must not be called while executing | |
346 | the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 347 | |
876fa593 JK |
348 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
349 | for (BP_TMP = bp_location; \ | |
350 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
351 | BP_TMP++) | |
7cc221ef | 352 | |
1042e4c0 SS |
353 | /* Iterator for tracepoints only. */ |
354 | ||
355 | #define ALL_TRACEPOINTS(B) \ | |
356 | for (B = breakpoint_chain; B; B = B->next) \ | |
7a697b8d | 357 | if (tracepoint_type (B)) |
1042e4c0 | 358 | |
7cc221ef | 359 | /* Chains of all breakpoints defined. */ |
c906108c SS |
360 | |
361 | struct breakpoint *breakpoint_chain; | |
362 | ||
876fa593 JK |
363 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
364 | ||
365 | static struct bp_location **bp_location; | |
366 | ||
367 | /* Number of elements of BP_LOCATION. */ | |
368 | ||
369 | static unsigned bp_location_count; | |
370 | ||
371 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and ADDRESS | |
372 | for the current elements of BP_LOCATION which get a valid result from | |
373 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
374 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
375 | ||
376 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
377 | ||
378 | /* Maximum offset plus alignment between | |
379 | bp_target_info.PLACED_ADDRESS + bp_target_info.SHADOW_LEN and ADDRESS for | |
380 | the current elements of BP_LOCATION which get a valid result from | |
381 | bp_location_has_shadow. You can use it for roughly limiting the subrange of | |
382 | BP_LOCATION to scan for shadow bytes for an address you need to read. */ | |
383 | ||
384 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 385 | |
20874c92 | 386 | /* The locations that no longer correspond to any breakpoint, |
876fa593 | 387 | unlinked from bp_location array, but for which a hit |
20874c92 VP |
388 | may still be reported by a target. */ |
389 | VEC(bp_location_p) *moribund_locations = NULL; | |
390 | ||
c906108c SS |
391 | /* Number of last breakpoint made. */ |
392 | ||
393 | int breakpoint_count; | |
394 | ||
1042e4c0 SS |
395 | /* Number of last tracepoint made. */ |
396 | ||
397 | int tracepoint_count; | |
398 | ||
468d015d JJ |
399 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
400 | static int | |
401 | breakpoint_enabled (struct breakpoint *b) | |
402 | { | |
0d381245 | 403 | return (b->enable_state == bp_enabled); |
468d015d JJ |
404 | } |
405 | ||
c906108c SS |
406 | /* Set breakpoint count to NUM. */ |
407 | ||
408 | void | |
fba45db2 | 409 | set_breakpoint_count (int num) |
c906108c SS |
410 | { |
411 | breakpoint_count = num; | |
4fa62494 | 412 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
413 | } |
414 | ||
415 | /* Used in run_command to zero the hit count when a new run starts. */ | |
416 | ||
417 | void | |
fba45db2 | 418 | clear_breakpoint_hit_counts (void) |
c906108c SS |
419 | { |
420 | struct breakpoint *b; | |
421 | ||
422 | ALL_BREAKPOINTS (b) | |
423 | b->hit_count = 0; | |
424 | } | |
425 | ||
7a697b8d SS |
426 | /* Encapsulate tests for different types of tracepoints. */ |
427 | ||
428 | static int | |
429 | tracepoint_type (const struct breakpoint *b) | |
430 | { | |
431 | return (b->type == bp_tracepoint || b->type == bp_fast_tracepoint); | |
432 | } | |
433 | ||
c906108c SS |
434 | /* Default address, symtab and line to put a breakpoint at |
435 | for "break" command with no arg. | |
436 | if default_breakpoint_valid is zero, the other three are | |
437 | not valid, and "break" with no arg is an error. | |
438 | ||
439 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
440 | ||
441 | int default_breakpoint_valid; | |
442 | CORE_ADDR default_breakpoint_address; | |
443 | struct symtab *default_breakpoint_symtab; | |
444 | int default_breakpoint_line; | |
6c95b8df PA |
445 | struct program_space *default_breakpoint_pspace; |
446 | ||
c906108c SS |
447 | \f |
448 | /* *PP is a string denoting a breakpoint. Get the number of the breakpoint. | |
449 | Advance *PP after the string and any trailing whitespace. | |
450 | ||
451 | Currently the string can either be a number or "$" followed by the name | |
452 | of a convenience variable. Making it an expression wouldn't work well | |
5c44784c | 453 | for map_breakpoint_numbers (e.g. "4 + 5 + 6"). |
40c03ae8 EZ |
454 | |
455 | If the string is a NULL pointer, that denotes the last breakpoint. | |
5c44784c JM |
456 | |
457 | TRAILER is a character which can be found after the number; most | |
458 | commonly this is `-'. If you don't want a trailer, use \0. */ | |
c906108c | 459 | static int |
fba45db2 | 460 | get_number_trailer (char **pp, int trailer) |
c906108c | 461 | { |
5c44784c | 462 | int retval = 0; /* default */ |
c906108c SS |
463 | char *p = *pp; |
464 | ||
465 | if (p == NULL) | |
466 | /* Empty line means refer to the last breakpoint. */ | |
467 | return breakpoint_count; | |
468 | else if (*p == '$') | |
469 | { | |
470 | /* Make a copy of the name, so we can null-terminate it | |
c5aa993b | 471 | to pass to lookup_internalvar(). */ |
c906108c SS |
472 | char *varname; |
473 | char *start = ++p; | |
4fa62494 | 474 | LONGEST val; |
c906108c SS |
475 | |
476 | while (isalnum (*p) || *p == '_') | |
477 | p++; | |
478 | varname = (char *) alloca (p - start + 1); | |
479 | strncpy (varname, start, p - start); | |
480 | varname[p - start] = '\0'; | |
4fa62494 UW |
481 | if (get_internalvar_integer (lookup_internalvar (varname), &val)) |
482 | retval = (int) val; | |
5c44784c JM |
483 | else |
484 | { | |
a3f17187 | 485 | printf_filtered (_("Convenience variable must have integer value.\n")); |
5c44784c JM |
486 | retval = 0; |
487 | } | |
c906108c SS |
488 | } |
489 | else | |
490 | { | |
491 | if (*p == '-') | |
492 | ++p; | |
493 | while (*p >= '0' && *p <= '9') | |
494 | ++p; | |
495 | if (p == *pp) | |
496 | /* There is no number here. (e.g. "cond a == b"). */ | |
5c44784c JM |
497 | { |
498 | /* Skip non-numeric token */ | |
499 | while (*p && !isspace((int) *p)) | |
500 | ++p; | |
501 | /* Return zero, which caller must interpret as error. */ | |
502 | retval = 0; | |
503 | } | |
504 | else | |
505 | retval = atoi (*pp); | |
506 | } | |
507 | if (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
508 | { | |
509 | /* Trailing junk: return 0 and let caller print error msg. */ | |
510 | while (!(isspace (*p) || *p == '\0' || *p == trailer)) | |
511 | ++p; | |
512 | retval = 0; | |
c906108c | 513 | } |
c906108c SS |
514 | while (isspace (*p)) |
515 | p++; | |
516 | *pp = p; | |
517 | return retval; | |
518 | } | |
5c44784c | 519 | |
11cf8741 | 520 | |
5c44784c JM |
521 | /* Like get_number_trailer, but don't allow a trailer. */ |
522 | int | |
fba45db2 | 523 | get_number (char **pp) |
5c44784c JM |
524 | { |
525 | return get_number_trailer (pp, '\0'); | |
526 | } | |
527 | ||
528 | /* Parse a number or a range. | |
529 | * A number will be of the form handled by get_number. | |
530 | * A range will be of the form <number1> - <number2>, and | |
531 | * will represent all the integers between number1 and number2, | |
532 | * inclusive. | |
533 | * | |
534 | * While processing a range, this fuction is called iteratively; | |
535 | * At each call it will return the next value in the range. | |
536 | * | |
537 | * At the beginning of parsing a range, the char pointer PP will | |
538 | * be advanced past <number1> and left pointing at the '-' token. | |
539 | * Subsequent calls will not advance the pointer until the range | |
540 | * is completed. The call that completes the range will advance | |
541 | * pointer PP past <number2>. | |
542 | */ | |
543 | ||
544 | int | |
fba45db2 | 545 | get_number_or_range (char **pp) |
5c44784c JM |
546 | { |
547 | static int last_retval, end_value; | |
548 | static char *end_ptr; | |
549 | static int in_range = 0; | |
550 | ||
551 | if (**pp != '-') | |
552 | { | |
553 | /* Default case: pp is pointing either to a solo number, | |
554 | or to the first number of a range. */ | |
555 | last_retval = get_number_trailer (pp, '-'); | |
556 | if (**pp == '-') | |
557 | { | |
558 | char **temp; | |
559 | ||
560 | /* This is the start of a range (<number1> - <number2>). | |
561 | Skip the '-', parse and remember the second number, | |
562 | and also remember the end of the final token. */ | |
563 | ||
564 | temp = &end_ptr; | |
565 | end_ptr = *pp + 1; | |
566 | while (isspace ((int) *end_ptr)) | |
567 | end_ptr++; /* skip white space */ | |
568 | end_value = get_number (temp); | |
569 | if (end_value < last_retval) | |
570 | { | |
8a3fe4f8 | 571 | error (_("inverted range")); |
5c44784c JM |
572 | } |
573 | else if (end_value == last_retval) | |
574 | { | |
575 | /* degenerate range (number1 == number2). Advance the | |
576 | token pointer so that the range will be treated as a | |
577 | single number. */ | |
578 | *pp = end_ptr; | |
579 | } | |
580 | else | |
581 | in_range = 1; | |
582 | } | |
583 | } | |
584 | else if (! in_range) | |
8a3fe4f8 | 585 | error (_("negative value")); |
5c44784c JM |
586 | else |
587 | { | |
588 | /* pp points to the '-' that betokens a range. All | |
589 | number-parsing has already been done. Return the next | |
590 | integer value (one greater than the saved previous value). | |
591 | Do not advance the token pointer 'pp' until the end of range | |
592 | is reached. */ | |
593 | ||
594 | if (++last_retval == end_value) | |
595 | { | |
596 | /* End of range reached; advance token pointer. */ | |
597 | *pp = end_ptr; | |
598 | in_range = 0; | |
599 | } | |
600 | } | |
601 | return last_retval; | |
602 | } | |
603 | ||
48cb2d85 VP |
604 | /* Return the breakpoint with the specified number, or NULL |
605 | if the number does not refer to an existing breakpoint. */ | |
606 | ||
607 | struct breakpoint * | |
608 | get_breakpoint (int num) | |
609 | { | |
610 | struct breakpoint *b; | |
611 | ||
612 | ALL_BREAKPOINTS (b) | |
613 | if (b->number == num) | |
614 | return b; | |
615 | ||
616 | return NULL; | |
617 | } | |
5c44784c | 618 | |
c906108c SS |
619 | \f |
620 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ | |
621 | ||
622 | static void | |
fba45db2 | 623 | condition_command (char *arg, int from_tty) |
c906108c | 624 | { |
52f0bd74 | 625 | struct breakpoint *b; |
c906108c | 626 | char *p; |
52f0bd74 | 627 | int bnum; |
c906108c SS |
628 | |
629 | if (arg == 0) | |
e2e0b3e5 | 630 | error_no_arg (_("breakpoint number")); |
c906108c SS |
631 | |
632 | p = arg; | |
633 | bnum = get_number (&p); | |
5c44784c | 634 | if (bnum == 0) |
8a3fe4f8 | 635 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
636 | |
637 | ALL_BREAKPOINTS (b) | |
638 | if (b->number == bnum) | |
2f069f6f JB |
639 | { |
640 | struct bp_location *loc = b->loc; | |
641 | for (; loc; loc = loc->next) | |
642 | { | |
643 | if (loc->cond) | |
644 | { | |
645 | xfree (loc->cond); | |
646 | loc->cond = 0; | |
647 | } | |
648 | } | |
649 | if (b->cond_string != NULL) | |
650 | xfree (b->cond_string); | |
c906108c | 651 | |
2f069f6f JB |
652 | if (*p == 0) |
653 | { | |
654 | b->cond_string = NULL; | |
655 | if (from_tty) | |
656 | printf_filtered (_("Breakpoint %d now unconditional.\n"), bnum); | |
657 | } | |
658 | else | |
659 | { | |
660 | arg = p; | |
661 | /* I don't know if it matters whether this is the string the user | |
662 | typed in or the decompiled expression. */ | |
1b36a34b | 663 | b->cond_string = xstrdup (arg); |
2f069f6f JB |
664 | b->condition_not_parsed = 0; |
665 | for (loc = b->loc; loc; loc = loc->next) | |
666 | { | |
667 | arg = p; | |
668 | loc->cond = | |
669 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
670 | if (*arg) | |
671 | error (_("Junk at end of expression")); | |
672 | } | |
673 | } | |
674 | breakpoints_changed (); | |
383f836e | 675 | observer_notify_breakpoint_modified (b->number); |
2f069f6f JB |
676 | return; |
677 | } | |
c906108c | 678 | |
8a3fe4f8 | 679 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
680 | } |
681 | ||
48cb2d85 VP |
682 | /* Set the command list of B to COMMANDS. */ |
683 | ||
684 | void | |
685 | breakpoint_set_commands (struct breakpoint *b, struct command_line *commands) | |
686 | { | |
687 | free_command_lines (&b->commands); | |
688 | b->commands = commands; | |
689 | breakpoints_changed (); | |
690 | observer_notify_breakpoint_modified (b->number); | |
691 | } | |
692 | ||
c906108c | 693 | static void |
fba45db2 | 694 | commands_command (char *arg, int from_tty) |
c906108c | 695 | { |
52f0bd74 | 696 | struct breakpoint *b; |
c906108c | 697 | char *p; |
52f0bd74 | 698 | int bnum; |
c906108c SS |
699 | struct command_line *l; |
700 | ||
701 | /* If we allowed this, we would have problems with when to | |
702 | free the storage, if we change the commands currently | |
703 | being read from. */ | |
704 | ||
705 | if (executing_breakpoint_commands) | |
8a3fe4f8 | 706 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); |
c906108c SS |
707 | |
708 | p = arg; | |
709 | bnum = get_number (&p); | |
5c44784c | 710 | |
c906108c | 711 | if (p && *p) |
8a3fe4f8 | 712 | error (_("Unexpected extra arguments following breakpoint number.")); |
c5aa993b | 713 | |
c906108c SS |
714 | ALL_BREAKPOINTS (b) |
715 | if (b->number == bnum) | |
9ebf4acf AC |
716 | { |
717 | char *tmpbuf = xstrprintf ("Type commands for when breakpoint %d is hit, one per line.", | |
718 | bnum); | |
719 | struct cleanup *cleanups = make_cleanup (xfree, tmpbuf); | |
311a4e6b | 720 | l = read_command_lines (tmpbuf, from_tty, 1); |
9ebf4acf | 721 | do_cleanups (cleanups); |
48cb2d85 | 722 | breakpoint_set_commands (b, l); |
9ebf4acf | 723 | return; |
c5aa993b | 724 | } |
8a3fe4f8 | 725 | error (_("No breakpoint number %d."), bnum); |
c906108c | 726 | } |
40c03ae8 EZ |
727 | |
728 | /* Like commands_command, but instead of reading the commands from | |
729 | input stream, takes them from an already parsed command structure. | |
730 | ||
731 | This is used by cli-script.c to DTRT with breakpoint commands | |
732 | that are part of if and while bodies. */ | |
733 | enum command_control_type | |
734 | commands_from_control_command (char *arg, struct command_line *cmd) | |
735 | { | |
736 | struct breakpoint *b; | |
737 | char *p; | |
738 | int bnum; | |
739 | ||
740 | /* If we allowed this, we would have problems with when to | |
741 | free the storage, if we change the commands currently | |
742 | being read from. */ | |
743 | ||
744 | if (executing_breakpoint_commands) | |
745 | error (_("Can't use the \"commands\" command among a breakpoint's commands.")); | |
746 | ||
747 | /* An empty string for the breakpoint number means the last | |
748 | breakpoint, but get_number expects a NULL pointer. */ | |
749 | if (arg && !*arg) | |
750 | p = NULL; | |
751 | else | |
752 | p = arg; | |
753 | bnum = get_number (&p); | |
754 | ||
755 | if (p && *p) | |
756 | error (_("Unexpected extra arguments following breakpoint number.")); | |
757 | ||
758 | ALL_BREAKPOINTS (b) | |
759 | if (b->number == bnum) | |
760 | { | |
761 | free_command_lines (&b->commands); | |
762 | if (cmd->body_count != 1) | |
763 | error (_("Invalid \"commands\" block structure.")); | |
764 | /* We need to copy the commands because if/while will free the | |
765 | list after it finishes execution. */ | |
766 | b->commands = copy_command_lines (cmd->body_list[0]); | |
767 | breakpoints_changed (); | |
383f836e | 768 | observer_notify_breakpoint_modified (b->number); |
40c03ae8 | 769 | return simple_control; |
2f069f6f | 770 | } |
40c03ae8 EZ |
771 | error (_("No breakpoint number %d."), bnum); |
772 | } | |
876fa593 JK |
773 | |
774 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
775 | ||
776 | static int | |
777 | bp_location_has_shadow (struct bp_location *bl) | |
778 | { | |
779 | if (bl->loc_type != bp_loc_software_breakpoint) | |
780 | return 0; | |
781 | if (!bl->inserted) | |
782 | return 0; | |
783 | if (bl->target_info.shadow_len == 0) | |
784 | /* bp isn't valid, or doesn't shadow memory. */ | |
785 | return 0; | |
786 | return 1; | |
787 | } | |
788 | ||
8defab1a | 789 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
790 | by replacing any memory breakpoints with their shadowed contents. |
791 | ||
792 | The range of shadowed area by each bp_location is: | |
793 | b->address - bp_location_placed_address_before_address_max | |
794 | up to b->address + bp_location_shadow_len_after_address_max | |
795 | The range we were requested to resolve shadows for is: | |
796 | memaddr ... memaddr + len | |
797 | Thus the safe cutoff boundaries for performance optimization are | |
798 | memaddr + len <= b->address - bp_location_placed_address_before_address_max | |
799 | and: | |
800 | b->address + bp_location_shadow_len_after_address_max <= memaddr */ | |
c906108c | 801 | |
8defab1a DJ |
802 | void |
803 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 804 | { |
876fa593 JK |
805 | /* Left boundary, right boundary and median element of our binary search. */ |
806 | unsigned bc_l, bc_r, bc; | |
807 | ||
808 | /* Find BC_L which is a leftmost element which may affect BUF content. It is | |
809 | safe to report lower value but a failure to report higher one. */ | |
810 | ||
811 | bc_l = 0; | |
812 | bc_r = bp_location_count; | |
813 | while (bc_l + 1 < bc_r) | |
814 | { | |
815 | struct bp_location *b; | |
816 | ||
817 | bc = (bc_l + bc_r) / 2; | |
818 | b = bp_location[bc]; | |
819 | ||
820 | /* Check first B->ADDRESS will not overflow due to the added constant. | |
821 | Then advance the left boundary only if we are sure the BC element can | |
822 | in no way affect the BUF content (MEMADDR to MEMADDR + LEN range). | |
823 | ||
824 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety offset so that | |
825 | we cannot miss a breakpoint with its shadow range tail still reaching | |
826 | MEMADDR. */ | |
c5aa993b | 827 | |
876fa593 JK |
828 | if (b->address + bp_location_shadow_len_after_address_max >= b->address |
829 | && b->address + bp_location_shadow_len_after_address_max <= memaddr) | |
830 | bc_l = bc; | |
831 | else | |
832 | bc_r = bc; | |
833 | } | |
834 | ||
835 | /* Now do full processing of the found relevant range of elements. */ | |
836 | ||
837 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 838 | { |
876fa593 JK |
839 | struct bp_location *b = bp_location[bc]; |
840 | CORE_ADDR bp_addr = 0; | |
841 | int bp_size = 0; | |
842 | int bptoffset = 0; | |
843 | ||
ffce0d52 | 844 | if (b->owner->type == bp_none) |
8a3fe4f8 | 845 | warning (_("reading through apparently deleted breakpoint #%d?"), |
ffce0d52 DJ |
846 | b->owner->number); |
847 | ||
876fa593 JK |
848 | /* Performance optimization: any futher element can no longer affect BUF |
849 | content. */ | |
850 | ||
851 | if (b->address >= bp_location_placed_address_before_address_max | |
852 | && memaddr + len <= b->address | |
853 | - bp_location_placed_address_before_address_max) | |
854 | break; | |
855 | ||
856 | if (!bp_location_has_shadow (b)) | |
c5aa993b | 857 | continue; |
6c95b8df PA |
858 | if (!breakpoint_address_match (b->target_info.placed_address_space, 0, |
859 | current_program_space->aspace, 0)) | |
860 | continue; | |
861 | ||
c5aa993b JM |
862 | /* Addresses and length of the part of the breakpoint that |
863 | we need to copy. */ | |
8181d85f DJ |
864 | bp_addr = b->target_info.placed_address; |
865 | bp_size = b->target_info.shadow_len; | |
8defab1a | 866 | |
c5aa993b JM |
867 | if (bp_addr + bp_size <= memaddr) |
868 | /* The breakpoint is entirely before the chunk of memory we | |
869 | are reading. */ | |
870 | continue; | |
8defab1a | 871 | |
c5aa993b JM |
872 | if (bp_addr >= memaddr + len) |
873 | /* The breakpoint is entirely after the chunk of memory we are | |
874 | reading. */ | |
875 | continue; | |
c5aa993b | 876 | |
8defab1a DJ |
877 | /* Offset within shadow_contents. */ |
878 | if (bp_addr < memaddr) | |
879 | { | |
880 | /* Only copy the second part of the breakpoint. */ | |
881 | bp_size -= memaddr - bp_addr; | |
882 | bptoffset = memaddr - bp_addr; | |
883 | bp_addr = memaddr; | |
884 | } | |
c5aa993b | 885 | |
8defab1a DJ |
886 | if (bp_addr + bp_size > memaddr + len) |
887 | { | |
888 | /* Only copy the first part of the breakpoint. */ | |
889 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
890 | } | |
c5aa993b | 891 | |
8defab1a DJ |
892 | memcpy (buf + bp_addr - memaddr, |
893 | b->target_info.shadow_contents + bptoffset, bp_size); | |
c5aa993b | 894 | } |
c906108c | 895 | } |
c906108c | 896 | \f |
c5aa993b | 897 | |
687595f9 | 898 | /* A wrapper function for inserting catchpoints. */ |
9cbc821d | 899 | static void |
687595f9 DJ |
900 | insert_catchpoint (struct ui_out *uo, void *args) |
901 | { | |
902 | struct breakpoint *b = (struct breakpoint *) args; | |
903 | int val = -1; | |
904 | ||
fe798b75 JB |
905 | gdb_assert (b->type == bp_catchpoint); |
906 | gdb_assert (b->ops != NULL && b->ops->insert != NULL); | |
907 | ||
908 | b->ops->insert (b); | |
687595f9 DJ |
909 | } |
910 | ||
a5606eee VP |
911 | static int |
912 | is_hardware_watchpoint (struct breakpoint *bpt) | |
913 | { | |
914 | return (bpt->type == bp_hardware_watchpoint | |
915 | || bpt->type == bp_read_watchpoint | |
916 | || bpt->type == bp_access_watchpoint); | |
917 | } | |
7270d8f2 | 918 | |
fa4727a6 DJ |
919 | /* Find the current value of a watchpoint on EXP. Return the value in |
920 | *VALP and *RESULTP and the chain of intermediate and final values | |
921 | in *VAL_CHAIN. RESULTP and VAL_CHAIN may be NULL if the caller does | |
922 | not need them. | |
923 | ||
ccc57cf9 | 924 | If a memory error occurs while evaluating the expression, *RESULTP will |
fa4727a6 DJ |
925 | be set to NULL. *RESULTP may be a lazy value, if the result could |
926 | not be read from memory. It is used to determine whether a value | |
927 | is user-specified (we should watch the whole value) or intermediate | |
928 | (we should watch only the bit used to locate the final value). | |
929 | ||
930 | If the final value, or any intermediate value, could not be read | |
931 | from memory, *VALP will be set to NULL. *VAL_CHAIN will still be | |
932 | set to any referenced values. *VALP will never be a lazy value. | |
933 | This is the value which we store in struct breakpoint. | |
934 | ||
935 | If VAL_CHAIN is non-NULL, *VAL_CHAIN will be released from the | |
936 | value chain. The caller must free the values individually. If | |
937 | VAL_CHAIN is NULL, all generated values will be left on the value | |
938 | chain. */ | |
939 | ||
940 | static void | |
941 | fetch_watchpoint_value (struct expression *exp, struct value **valp, | |
942 | struct value **resultp, struct value **val_chain) | |
943 | { | |
944 | struct value *mark, *new_mark, *result; | |
ccc57cf9 | 945 | volatile struct gdb_exception ex; |
fa4727a6 DJ |
946 | |
947 | *valp = NULL; | |
948 | if (resultp) | |
949 | *resultp = NULL; | |
950 | if (val_chain) | |
951 | *val_chain = NULL; | |
952 | ||
953 | /* Evaluate the expression. */ | |
954 | mark = value_mark (); | |
955 | result = NULL; | |
ccc57cf9 PA |
956 | |
957 | TRY_CATCH (ex, RETURN_MASK_ALL) | |
958 | { | |
959 | result = evaluate_expression (exp); | |
960 | } | |
961 | if (ex.reason < 0) | |
962 | { | |
963 | /* Ignore memory errors, we want watchpoints pointing at | |
964 | inaccessible memory to still be created; otherwise, throw the | |
965 | error to some higher catcher. */ | |
966 | switch (ex.error) | |
967 | { | |
968 | case MEMORY_ERROR: | |
969 | break; | |
970 | default: | |
971 | throw_exception (ex); | |
972 | break; | |
973 | } | |
974 | } | |
975 | ||
fa4727a6 DJ |
976 | new_mark = value_mark (); |
977 | if (mark == new_mark) | |
978 | return; | |
979 | if (resultp) | |
980 | *resultp = result; | |
981 | ||
982 | /* Make sure it's not lazy, so that after the target stops again we | |
983 | have a non-lazy previous value to compare with. */ | |
984 | if (result != NULL | |
985 | && (!value_lazy (result) || gdb_value_fetch_lazy (result))) | |
986 | *valp = result; | |
987 | ||
988 | if (val_chain) | |
989 | { | |
990 | /* Return the chain of intermediate values. We use this to | |
991 | decide which addresses to watch. */ | |
992 | *val_chain = new_mark; | |
993 | value_release_to_mark (mark); | |
994 | } | |
995 | } | |
996 | ||
f6bc2008 PA |
997 | /* Assuming that B is a watchpoint: returns true if the current thread |
998 | and its running state are safe to evaluate or update watchpoint B. | |
999 | Watchpoints on local expressions need to be evaluated in the | |
1000 | context of the thread that was current when the watchpoint was | |
1001 | created, and, that thread needs to be stopped to be able to select | |
1002 | the correct frame context. Watchpoints on global expressions can | |
1003 | be evaluated on any thread, and in any state. It is presently left | |
1004 | to the target allowing memory accesses when threads are | |
1005 | running. */ | |
1006 | ||
1007 | static int | |
1008 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1009 | { | |
1010 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1011 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1012 | && !is_executing (inferior_ptid))); | |
1013 | } | |
1014 | ||
567e1b4e JB |
1015 | /* Assuming that B is a watchpoint: |
1016 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1017 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1018 | - Evaluate the condition if there is one, and store the result |
1019 | in b->loc->cond. | |
a5606eee VP |
1020 | - Update the list of values that must be watched in B->loc. |
1021 | ||
bfa149ac | 1022 | If the watchpoint disposition is disp_del_at_next_stop, then do nothing. |
a79d3c27 JK |
1023 | If this is local watchpoint that is out of scope, delete it. |
1024 | ||
1025 | Even with `set breakpoint always-inserted on' the watchpoints are removed | |
1026 | + inserted on each stop here. Normal breakpoints must never be removed | |
1027 | because they might be missed by a running thread when debugging in non-stop | |
1028 | mode. On the other hand, hardware watchpoints (is_hardware_watchpoint; | |
1029 | processed here) are specific to each LWP since they are stored in each LWP's | |
1030 | hardware debug registers. Therefore, such LWP must be stopped first in | |
1031 | order to be able to modify its hardware watchpoints. | |
1032 | ||
1033 | Hardware watchpoints must be reset exactly once after being presented to the | |
1034 | user. It cannot be done sooner, because it would reset the data used to | |
1035 | present the watchpoint hit to the user. And it must not be done later | |
1036 | because it could display the same single watchpoint hit during multiple GDB | |
1037 | stops. Note that the latter is relevant only to the hardware watchpoint | |
1038 | types bp_read_watchpoint and bp_access_watchpoint. False hit by | |
1039 | bp_hardware_watchpoint is not user-visible - its hit is suppressed if the | |
1040 | memory content has not changed. | |
1041 | ||
1042 | The following constraints influence the location where we can reset hardware | |
1043 | watchpoints: | |
1044 | ||
1045 | * target_stopped_by_watchpoint and target_stopped_data_address are called | |
1046 | several times when GDB stops. | |
1047 | ||
1048 | [linux] | |
1049 | * Multiple hardware watchpoints can be hit at the same time, causing GDB to | |
1050 | stop. GDB only presents one hardware watchpoint hit at a time as the | |
1051 | reason for stopping, and all the other hits are presented later, one after | |
1052 | the other, each time the user requests the execution to be resumed. | |
1053 | Execution is not resumed for the threads still having pending hit event | |
1054 | stored in LWP_INFO->STATUS. While the watchpoint is already removed from | |
1055 | the inferior on the first stop the thread hit event is kept being reported | |
1056 | from its cached value by linux_nat_stopped_data_address until the real | |
1057 | thread resume happens after the watchpoint gets presented and thus its | |
1058 | LWP_INFO->STATUS gets reset. | |
1059 | ||
1060 | Therefore the hardware watchpoint hit can get safely reset on the watchpoint | |
1061 | removal from inferior. */ | |
1062 | ||
b40ce68a | 1063 | static void |
a5606eee | 1064 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1065 | { |
a5606eee | 1066 | int within_current_scope; |
a5606eee VP |
1067 | struct frame_id saved_frame_id; |
1068 | struct bp_location *loc; | |
66076460 | 1069 | int frame_saved; |
a5606eee VP |
1070 | bpstat bs; |
1071 | ||
f6bc2008 PA |
1072 | /* If this is a local watchpoint, we only want to check if the |
1073 | watchpoint frame is in scope if the current thread is the thread | |
1074 | that was used to create the watchpoint. */ | |
1075 | if (!watchpoint_in_thread_scope (b)) | |
1076 | return; | |
1077 | ||
876fa593 | 1078 | /* We don't free locations. They are stored in bp_location array and |
567e1b4e JB |
1079 | update_global_locations will eventually delete them and remove |
1080 | breakpoints if needed. */ | |
a5606eee VP |
1081 | b->loc = NULL; |
1082 | ||
1083 | if (b->disposition == disp_del_at_next_stop) | |
1084 | return; | |
1085 | ||
66076460 | 1086 | frame_saved = 0; |
a5606eee VP |
1087 | |
1088 | /* Determine if the watchpoint is within scope. */ | |
1089 | if (b->exp_valid_block == NULL) | |
1090 | within_current_scope = 1; | |
1091 | else | |
1092 | { | |
1093 | struct frame_info *fi; | |
66076460 DJ |
1094 | |
1095 | /* Save the current frame's ID so we can restore it after | |
1096 | evaluating the watchpoint expression on its own frame. */ | |
1097 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1098 | took a frame parameter, so that we didn't have to change the | |
1099 | selected frame. */ | |
1100 | frame_saved = 1; | |
1101 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1102 | ||
a5606eee VP |
1103 | fi = frame_find_by_id (b->watchpoint_frame); |
1104 | within_current_scope = (fi != NULL); | |
1105 | if (within_current_scope) | |
1106 | select_frame (fi); | |
1107 | } | |
1108 | ||
1109 | if (within_current_scope && reparse) | |
1110 | { | |
1111 | char *s; | |
1112 | if (b->exp) | |
1113 | { | |
1114 | xfree (b->exp); | |
1115 | b->exp = NULL; | |
1116 | } | |
1117 | s = b->exp_string; | |
1118 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); | |
1119 | /* If the meaning of expression itself changed, the old value is | |
1120 | no longer relevant. We don't want to report a watchpoint hit | |
1121 | to the user when the old value and the new value may actually | |
1122 | be completely different objects. */ | |
1123 | value_free (b->val); | |
fa4727a6 DJ |
1124 | b->val = NULL; |
1125 | b->val_valid = 0; | |
a5606eee | 1126 | } |
a5606eee VP |
1127 | |
1128 | /* If we failed to parse the expression, for example because | |
1129 | it refers to a global variable in a not-yet-loaded shared library, | |
1130 | don't try to insert watchpoint. We don't automatically delete | |
1131 | such watchpoint, though, since failure to parse expression | |
1132 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1133 | if ( !target_has_execution) |
1134 | { | |
1135 | /* Without execution, memory can't change. No use to try and | |
1136 | set watchpoint locations. The watchpoint will be reset when | |
1137 | the target gains execution, through breakpoint_re_set. */ | |
1138 | } | |
1139 | else if (within_current_scope && b->exp) | |
a5606eee | 1140 | { |
fa4727a6 | 1141 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1142 | struct program_space *frame_pspace; |
a5606eee | 1143 | |
fa4727a6 | 1144 | fetch_watchpoint_value (b->exp, &v, &result, &val_chain); |
a5606eee | 1145 | |
a5606eee VP |
1146 | /* Avoid setting b->val if it's already set. The meaning of |
1147 | b->val is 'the last value' user saw, and we should update | |
1148 | it only if we reported that last value to user. As it | |
1149 | happens, the code that reports it updates b->val directly. */ | |
fa4727a6 DJ |
1150 | if (!b->val_valid) |
1151 | { | |
1152 | b->val = v; | |
1153 | b->val_valid = 1; | |
1154 | } | |
a5606eee | 1155 | |
db2ad4c3 JK |
1156 | /* Change the type of breakpoint between hardware assisted or an |
1157 | ordinary watchpoint depending on the hardware support and free | |
1158 | hardware slots. REPARSE is set when the inferior is started. */ | |
1159 | if ((b->type == bp_watchpoint || b->type == bp_hardware_watchpoint) | |
1160 | && reparse) | |
1161 | { | |
ca2d49e8 | 1162 | int i, mem_cnt, other_type_used; |
db2ad4c3 | 1163 | |
7b838ca2 TJB |
1164 | /* We need to determine how many resources are already used |
1165 | for all other hardware watchpoints to see if we still have | |
1166 | enough resources to also fit this watchpoint in as well. | |
1167 | To avoid the hw_watchpoint_used_count call below from counting | |
1168 | this watchpoint, make sure that it is marked as a software | |
1169 | watchpoint. */ | |
1170 | b->type = bp_watchpoint; | |
db2ad4c3 JK |
1171 | i = hw_watchpoint_used_count (bp_hardware_watchpoint, |
1172 | &other_type_used); | |
1173 | mem_cnt = can_use_hardware_watchpoint (val_chain); | |
1174 | ||
ca2d49e8 | 1175 | if (!mem_cnt) |
db2ad4c3 JK |
1176 | b->type = bp_watchpoint; |
1177 | else | |
ca2d49e8 | 1178 | { |
d92524f1 | 1179 | int target_resources_ok = target_can_use_hardware_watchpoint |
ca2d49e8 SL |
1180 | (bp_hardware_watchpoint, i + mem_cnt, other_type_used); |
1181 | if (target_resources_ok <= 0) | |
1182 | b->type = bp_watchpoint; | |
1183 | else | |
1184 | b->type = bp_hardware_watchpoint; | |
1185 | } | |
db2ad4c3 JK |
1186 | } |
1187 | ||
2d134ed3 PA |
1188 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1189 | ||
a5606eee | 1190 | /* Look at each value on the value chain. */ |
fa4727a6 | 1191 | for (v = val_chain; v; v = next) |
a5606eee VP |
1192 | { |
1193 | /* If it's a memory location, and GDB actually needed | |
1194 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1195 | must watch it. If the first value returned is |
1196 | still lazy, that means an error occurred reading it; | |
1197 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1198 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1199 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1200 | { |
1201 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1202 | |
a5606eee VP |
1203 | /* We only watch structs and arrays if user asked |
1204 | for it explicitly, never if they just happen to | |
1205 | appear in the middle of some value chain. */ | |
fa4727a6 | 1206 | if (v == result |
a5606eee VP |
1207 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1208 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1209 | { | |
1210 | CORE_ADDR addr; | |
1211 | int len, type; | |
1212 | struct bp_location *loc, **tmp; | |
1213 | ||
42ae5230 | 1214 | addr = value_address (v); |
a5606eee VP |
1215 | len = TYPE_LENGTH (value_type (v)); |
1216 | type = hw_write; | |
1217 | if (b->type == bp_read_watchpoint) | |
1218 | type = hw_read; | |
1219 | else if (b->type == bp_access_watchpoint) | |
1220 | type = hw_access; | |
1221 | ||
39d61571 | 1222 | loc = allocate_bp_location (b); |
a5606eee VP |
1223 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1224 | ; | |
1225 | *tmp = loc; | |
a6d9a66e | 1226 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1227 | |
1228 | loc->pspace = frame_pspace; | |
a5606eee VP |
1229 | loc->address = addr; |
1230 | loc->length = len; | |
1231 | loc->watchpoint_type = type; | |
1232 | } | |
1233 | } | |
1234 | ||
1235 | next = value_next (v); | |
1236 | if (v != b->val) | |
1237 | value_free (v); | |
1238 | } | |
1239 | ||
c7437ca6 PA |
1240 | /* If a software watchpoint is not watching any memory, then the |
1241 | above left it without any location set up. But, | |
1242 | bpstat_stop_status requires a location to be able to report | |
1243 | stops, so make sure there's at least a dummy one. */ | |
1244 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1245 | { | |
1246 | b->loc = allocate_bp_location (b); | |
1247 | b->loc->pspace = frame_pspace; | |
1248 | b->loc->address = -1; | |
1249 | b->loc->length = -1; | |
1250 | b->loc->watchpoint_type = -1; | |
1251 | } | |
1252 | ||
2ec93238 MK |
1253 | /* We just regenerated the list of breakpoint locations. |
1254 | The new location does not have its condition field set to anything | |
1255 | and therefore, we must always reparse the cond_string, independently | |
1256 | of the value of the reparse flag. */ | |
1257 | if (b->cond_string != NULL) | |
a5606eee VP |
1258 | { |
1259 | char *s = b->cond_string; | |
a5606eee VP |
1260 | b->loc->cond = parse_exp_1 (&s, b->exp_valid_block, 0); |
1261 | } | |
1262 | } | |
1263 | else if (!within_current_scope) | |
7270d8f2 | 1264 | { |
a5606eee | 1265 | printf_filtered (_("\ |
567e1b4e | 1266 | Watchpoint %d deleted because the program has left the block \n\ |
a5606eee VP |
1267 | in which its expression is valid.\n"), |
1268 | b->number); | |
1269 | if (b->related_breakpoint) | |
1270 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1271 | b->disposition = disp_del_at_next_stop; | |
7270d8f2 | 1272 | } |
a5606eee VP |
1273 | |
1274 | /* Restore the selected frame. */ | |
66076460 DJ |
1275 | if (frame_saved) |
1276 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1277 | } |
1278 | ||
a5606eee | 1279 | |
74960c60 VP |
1280 | /* Returns 1 iff breakpoint location should be |
1281 | inserted in the inferior. */ | |
1282 | static int | |
1283 | should_be_inserted (struct bp_location *bpt) | |
1284 | { | |
1285 | if (!breakpoint_enabled (bpt->owner)) | |
1286 | return 0; | |
1287 | ||
1288 | if (bpt->owner->disposition == disp_del_at_next_stop) | |
1289 | return 0; | |
1290 | ||
1291 | if (!bpt->enabled || bpt->shlib_disabled || bpt->duplicate) | |
1292 | return 0; | |
1293 | ||
56710373 PA |
1294 | /* This is set for example, when we're attached to the parent of a |
1295 | vfork, and have detached from the child. The child is running | |
1296 | free, and we expect it to do an exec or exit, at which point the | |
1297 | OS makes the parent schedulable again (and the target reports | |
1298 | that the vfork is done). Until the child is done with the shared | |
1299 | memory region, do not insert breakpoints in the parent, otherwise | |
1300 | the child could still trip on the parent's breakpoints. Since | |
1301 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
1302 | if (bpt->pspace->breakpoints_not_allowed) | |
1303 | return 0; | |
1304 | ||
1042e4c0 SS |
1305 | /* Tracepoints are inserted by the target at a time of its choosing, |
1306 | not by us. */ | |
7a697b8d | 1307 | if (tracepoint_type (bpt->owner)) |
1042e4c0 SS |
1308 | return 0; |
1309 | ||
74960c60 VP |
1310 | return 1; |
1311 | } | |
1312 | ||
879bfdc2 DJ |
1313 | /* Insert a low-level "breakpoint" of some type. BPT is the breakpoint. |
1314 | Any error messages are printed to TMP_ERROR_STREAM; and DISABLED_BREAKS, | |
fa3a767f | 1315 | and HW_BREAKPOINT_ERROR are used to report problems. |
879bfdc2 DJ |
1316 | |
1317 | NOTE drow/2003-09-09: This routine could be broken down to an object-style | |
1318 | method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1319 | static int |
879bfdc2 | 1320 | insert_bp_location (struct bp_location *bpt, |
26bb91f3 | 1321 | struct ui_file *tmp_error_stream, |
fa3a767f | 1322 | int *disabled_breaks, |
26bb91f3 | 1323 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1324 | { |
1325 | int val = 0; | |
1326 | ||
74960c60 | 1327 | if (!should_be_inserted (bpt) || bpt->inserted) |
879bfdc2 DJ |
1328 | return 0; |
1329 | ||
8181d85f DJ |
1330 | /* Initialize the target-specific information. */ |
1331 | memset (&bpt->target_info, 0, sizeof (bpt->target_info)); | |
1332 | bpt->target_info.placed_address = bpt->address; | |
6c95b8df | 1333 | bpt->target_info.placed_address_space = bpt->pspace->aspace; |
8181d85f | 1334 | |
879bfdc2 DJ |
1335 | if (bpt->loc_type == bp_loc_software_breakpoint |
1336 | || bpt->loc_type == bp_loc_hardware_breakpoint) | |
1337 | { | |
765dc015 VP |
1338 | if (bpt->owner->type != bp_hardware_breakpoint) |
1339 | { | |
1340 | /* If the explicitly specified breakpoint type | |
1341 | is not hardware breakpoint, check the memory map to see | |
1342 | if the breakpoint address is in read only memory or not. | |
1343 | Two important cases are: | |
1344 | - location type is not hardware breakpoint, memory | |
1345 | is readonly. We change the type of the location to | |
1346 | hardware breakpoint. | |
1347 | - location type is hardware breakpoint, memory is read-write. | |
1348 | This means we've previously made the location hardware one, but | |
1349 | then the memory map changed, so we undo. | |
1350 | ||
1351 | When breakpoints are removed, remove_breakpoints will | |
1352 | use location types we've just set here, the only possible | |
1353 | problem is that memory map has changed during running program, | |
1354 | but it's not going to work anyway with current gdb. */ | |
1355 | struct mem_region *mr | |
1356 | = lookup_mem_region (bpt->target_info.placed_address); | |
1357 | ||
1358 | if (mr) | |
1359 | { | |
1360 | if (automatic_hardware_breakpoints) | |
1361 | { | |
1362 | int changed = 0; | |
1363 | enum bp_loc_type new_type; | |
1364 | ||
1365 | if (mr->attrib.mode != MEM_RW) | |
1366 | new_type = bp_loc_hardware_breakpoint; | |
1367 | else | |
1368 | new_type = bp_loc_software_breakpoint; | |
1369 | ||
1370 | if (new_type != bpt->loc_type) | |
1371 | { | |
1372 | static int said = 0; | |
1373 | bpt->loc_type = new_type; | |
1374 | if (!said) | |
1375 | { | |
1376 | fprintf_filtered (gdb_stdout, _("\ | |
0767c96d | 1377 | Note: automatically using hardware breakpoints for read-only addresses.\n")); |
765dc015 VP |
1378 | said = 1; |
1379 | } | |
1380 | } | |
1381 | } | |
1382 | else if (bpt->loc_type == bp_loc_software_breakpoint | |
1383 | && mr->attrib.mode != MEM_RW) | |
1384 | warning (_("cannot set software breakpoint at readonly address %s"), | |
5af949e3 | 1385 | paddress (bpt->gdbarch, bpt->address)); |
765dc015 VP |
1386 | } |
1387 | } | |
1388 | ||
879bfdc2 DJ |
1389 | /* First check to see if we have to handle an overlay. */ |
1390 | if (overlay_debugging == ovly_off | |
1391 | || bpt->section == NULL | |
1392 | || !(section_is_overlay (bpt->section))) | |
1393 | { | |
1394 | /* No overlay handling: just set the breakpoint. */ | |
1395 | ||
1396 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1397 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1398 | &bpt->target_info); | |
879bfdc2 | 1399 | else |
a6d9a66e UW |
1400 | val = target_insert_breakpoint (bpt->gdbarch, |
1401 | &bpt->target_info); | |
879bfdc2 DJ |
1402 | } |
1403 | else | |
1404 | { | |
1405 | /* This breakpoint is in an overlay section. | |
1406 | Shall we set a breakpoint at the LMA? */ | |
1407 | if (!overlay_events_enabled) | |
1408 | { | |
1409 | /* Yes -- overlay event support is not active, | |
1410 | so we must try to set a breakpoint at the LMA. | |
1411 | This will not work for a hardware breakpoint. */ | |
1412 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
8a3fe4f8 | 1413 | warning (_("hardware breakpoint %d not supported in overlay!"), |
879bfdc2 DJ |
1414 | bpt->owner->number); |
1415 | else | |
1416 | { | |
1417 | CORE_ADDR addr = overlay_unmapped_address (bpt->address, | |
1418 | bpt->section); | |
1419 | /* Set a software (trap) breakpoint at the LMA. */ | |
8181d85f DJ |
1420 | bpt->overlay_target_info = bpt->target_info; |
1421 | bpt->overlay_target_info.placed_address = addr; | |
a6d9a66e UW |
1422 | val = target_insert_breakpoint (bpt->gdbarch, |
1423 | &bpt->overlay_target_info); | |
879bfdc2 | 1424 | if (val != 0) |
99361f52 DE |
1425 | fprintf_unfiltered (tmp_error_stream, |
1426 | "Overlay breakpoint %d failed: in ROM?\n", | |
879bfdc2 DJ |
1427 | bpt->owner->number); |
1428 | } | |
1429 | } | |
1430 | /* Shall we set a breakpoint at the VMA? */ | |
1431 | if (section_is_mapped (bpt->section)) | |
1432 | { | |
1433 | /* Yes. This overlay section is mapped into memory. */ | |
1434 | if (bpt->loc_type == bp_loc_hardware_breakpoint) | |
a6d9a66e UW |
1435 | val = target_insert_hw_breakpoint (bpt->gdbarch, |
1436 | &bpt->target_info); | |
879bfdc2 | 1437 | else |
a6d9a66e UW |
1438 | val = target_insert_breakpoint (bpt->gdbarch, |
1439 | &bpt->target_info); | |
879bfdc2 DJ |
1440 | } |
1441 | else | |
1442 | { | |
1443 | /* No. This breakpoint will not be inserted. | |
1444 | No error, but do not mark the bp as 'inserted'. */ | |
1445 | return 0; | |
1446 | } | |
1447 | } | |
1448 | ||
1449 | if (val) | |
1450 | { | |
1451 | /* Can't set the breakpoint. */ | |
6c95b8df | 1452 | if (solib_name_from_address (bpt->pspace, bpt->address)) |
879bfdc2 DJ |
1453 | { |
1454 | /* See also: disable_breakpoints_in_shlibs. */ | |
1455 | val = 0; | |
0d381245 | 1456 | bpt->shlib_disabled = 1; |
879bfdc2 DJ |
1457 | if (!*disabled_breaks) |
1458 | { | |
1459 | fprintf_unfiltered (tmp_error_stream, | |
1460 | "Cannot insert breakpoint %d.\n", | |
1461 | bpt->owner->number); | |
1462 | fprintf_unfiltered (tmp_error_stream, | |
1463 | "Temporarily disabling shared library breakpoints:\n"); | |
1464 | } | |
1465 | *disabled_breaks = 1; | |
1466 | fprintf_unfiltered (tmp_error_stream, | |
1467 | "breakpoint #%d\n", bpt->owner->number); | |
1468 | } | |
1469 | else | |
879bfdc2 | 1470 | { |
879bfdc2 DJ |
1471 | if (bpt->loc_type == bp_loc_hardware_breakpoint) |
1472 | { | |
1473 | *hw_breakpoint_error = 1; | |
1474 | fprintf_unfiltered (tmp_error_stream, | |
1475 | "Cannot insert hardware breakpoint %d.\n", | |
1476 | bpt->owner->number); | |
1477 | } | |
1478 | else | |
1479 | { | |
1480 | fprintf_unfiltered (tmp_error_stream, | |
1481 | "Cannot insert breakpoint %d.\n", | |
1482 | bpt->owner->number); | |
1483 | fprintf_filtered (tmp_error_stream, | |
1484 | "Error accessing memory address "); | |
5af949e3 UW |
1485 | fputs_filtered (paddress (bpt->gdbarch, bpt->address), |
1486 | tmp_error_stream); | |
879bfdc2 DJ |
1487 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1488 | safe_strerror (val)); | |
1489 | } | |
1490 | ||
1491 | } | |
1492 | } | |
1493 | else | |
1494 | bpt->inserted = 1; | |
1495 | ||
1496 | return val; | |
1497 | } | |
1498 | ||
1499 | else if (bpt->loc_type == bp_loc_hardware_watchpoint | |
1500 | /* NOTE drow/2003-09-08: This state only exists for removing | |
1501 | watchpoints. It's not clear that it's necessary... */ | |
1502 | && bpt->owner->disposition != disp_del_at_next_stop) | |
1503 | { | |
85d721b8 | 1504 | val = target_insert_watchpoint (bpt->address, |
a5606eee VP |
1505 | bpt->length, |
1506 | bpt->watchpoint_type); | |
85d721b8 PA |
1507 | |
1508 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1509 | supported, try emulating one with an access watchpoint. */ | |
1510 | if (val == 1 && bpt->watchpoint_type == hw_read) | |
1511 | { | |
1512 | struct bp_location *loc, **loc_temp; | |
1513 | ||
1514 | /* But don't try to insert it, if there's already another | |
1515 | hw_access location that would be considered a duplicate | |
1516 | of this one. */ | |
1517 | ALL_BP_LOCATIONS (loc, loc_temp) | |
1518 | if (loc != bpt | |
1519 | && loc->watchpoint_type == hw_access | |
1520 | && watchpoint_locations_match (bpt, loc)) | |
1521 | { | |
1522 | bpt->duplicate = 1; | |
1523 | bpt->inserted = 1; | |
1524 | bpt->target_info = loc->target_info; | |
1525 | bpt->watchpoint_type = hw_access; | |
1526 | val = 0; | |
1527 | break; | |
1528 | } | |
1529 | ||
1530 | if (val == 1) | |
1531 | { | |
1532 | val = target_insert_watchpoint (bpt->address, | |
1533 | bpt->length, | |
1534 | hw_access); | |
1535 | if (val == 0) | |
1536 | bpt->watchpoint_type = hw_access; | |
1537 | } | |
1538 | } | |
1539 | ||
1540 | bpt->inserted = (val == 0); | |
879bfdc2 DJ |
1541 | } |
1542 | ||
fe798b75 | 1543 | else if (bpt->owner->type == bp_catchpoint) |
879bfdc2 | 1544 | { |
71fff37b AC |
1545 | struct gdb_exception e = catch_exception (uiout, insert_catchpoint, |
1546 | bpt->owner, RETURN_MASK_ERROR); | |
9cbc821d AC |
1547 | exception_fprintf (gdb_stderr, e, "warning: inserting catchpoint %d: ", |
1548 | bpt->owner->number); | |
1549 | if (e.reason < 0) | |
879bfdc2 DJ |
1550 | bpt->owner->enable_state = bp_disabled; |
1551 | else | |
1552 | bpt->inserted = 1; | |
1640b821 DJ |
1553 | |
1554 | /* We've already printed an error message if there was a problem | |
1555 | inserting this catchpoint, and we've disabled the catchpoint, | |
1556 | so just return success. */ | |
1557 | return 0; | |
879bfdc2 DJ |
1558 | } |
1559 | ||
1560 | return 0; | |
1561 | } | |
1562 | ||
6c95b8df PA |
1563 | /* This function is called when program space PSPACE is about to be |
1564 | deleted. It takes care of updating breakpoints to not reference | |
1565 | PSPACE anymore. */ | |
1566 | ||
1567 | void | |
1568 | breakpoint_program_space_exit (struct program_space *pspace) | |
1569 | { | |
1570 | struct breakpoint *b, *b_temp; | |
876fa593 | 1571 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1572 | |
1573 | /* Remove any breakpoint that was set through this program space. */ | |
1574 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1575 | { | |
1576 | if (b->pspace == pspace) | |
1577 | delete_breakpoint (b); | |
1578 | } | |
1579 | ||
1580 | /* Breakpoints set through other program spaces could have locations | |
1581 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1582 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1583 | { |
1584 | struct bp_location *tmp; | |
1585 | ||
1586 | if (loc->pspace == pspace) | |
1587 | { | |
1588 | if (loc->owner->loc == loc) | |
1589 | loc->owner->loc = loc->next; | |
1590 | else | |
1591 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1592 | if (tmp->next == loc) | |
1593 | { | |
1594 | tmp->next = loc->next; | |
1595 | break; | |
1596 | } | |
1597 | } | |
1598 | } | |
1599 | ||
1600 | /* Now update the global location list to permanently delete the | |
1601 | removed locations above. */ | |
1602 | update_global_location_list (0); | |
1603 | } | |
1604 | ||
74960c60 VP |
1605 | /* Make sure all breakpoints are inserted in inferior. |
1606 | Throws exception on any error. | |
1607 | A breakpoint that is already inserted won't be inserted | |
1608 | again, so calling this function twice is safe. */ | |
1609 | void | |
1610 | insert_breakpoints (void) | |
1611 | { | |
1612 | struct breakpoint *bpt; | |
1613 | ||
1614 | ALL_BREAKPOINTS (bpt) | |
1615 | if (is_hardware_watchpoint (bpt)) | |
1616 | update_watchpoint (bpt, 0 /* don't reparse. */); | |
1617 | ||
b60e7edf | 1618 | update_global_location_list (1); |
74960c60 | 1619 | |
c35b1492 PA |
1620 | /* update_global_location_list does not insert breakpoints when |
1621 | always_inserted_mode is not enabled. Explicitly insert them | |
1622 | now. */ | |
1623 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1624 | insert_breakpoint_locations (); |
1625 | } | |
1626 | ||
c906108c SS |
1627 | /* insert_breakpoints is used when starting or continuing the program. |
1628 | remove_breakpoints is used when the program stops. | |
1629 | Both return zero if successful, | |
1630 | or an `errno' value if could not write the inferior. */ | |
1631 | ||
74960c60 VP |
1632 | static void |
1633 | insert_breakpoint_locations (void) | |
c906108c | 1634 | { |
a5606eee | 1635 | struct breakpoint *bpt; |
876fa593 | 1636 | struct bp_location *b, **bp_tmp; |
e236ba44 | 1637 | int error = 0; |
c906108c SS |
1638 | int val = 0; |
1639 | int disabled_breaks = 0; | |
81d0cc19 | 1640 | int hw_breakpoint_error = 0; |
c906108c | 1641 | |
81d0cc19 | 1642 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1643 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1644 | |
81d0cc19 GS |
1645 | /* Explicitly mark the warning -- this will only be printed if |
1646 | there was an error. */ | |
1647 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1648 | |
1649 | save_current_space_and_thread (); | |
1650 | ||
876fa593 | 1651 | ALL_BP_LOCATIONS (b, bp_tmp) |
879bfdc2 | 1652 | { |
6c95b8df PA |
1653 | struct thread_info *tp; |
1654 | CORE_ADDR last_addr; | |
1655 | ||
74960c60 | 1656 | if (!should_be_inserted (b) || b->inserted) |
879bfdc2 DJ |
1657 | continue; |
1658 | ||
f365de73 AS |
1659 | /* There is no point inserting thread-specific breakpoints if the |
1660 | thread no longer exists. */ | |
1661 | if (b->owner->thread != -1 | |
1662 | && !valid_thread_id (b->owner->thread)) | |
1663 | continue; | |
1664 | ||
6c95b8df PA |
1665 | switch_to_program_space_and_thread (b->pspace); |
1666 | ||
1667 | /* For targets that support global breakpoints, there's no need | |
1668 | to select an inferior to insert breakpoint to. In fact, even | |
1669 | if we aren't attached to any process yet, we should still | |
1670 | insert breakpoints. */ | |
1671 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1672 | && ptid_equal (inferior_ptid, null_ptid)) | |
1673 | continue; | |
1674 | ||
879bfdc2 | 1675 | val = insert_bp_location (b, tmp_error_stream, |
fa3a767f | 1676 | &disabled_breaks, |
879bfdc2 DJ |
1677 | &hw_breakpoint_error); |
1678 | if (val) | |
e236ba44 | 1679 | error = val; |
879bfdc2 | 1680 | } |
c906108c | 1681 | |
a5606eee VP |
1682 | /* If we failed to insert all locations of a watchpoint, |
1683 | remove them, as half-inserted watchpoint is of limited use. */ | |
1684 | ALL_BREAKPOINTS (bpt) | |
1685 | { | |
1686 | int some_failed = 0; | |
1687 | struct bp_location *loc; | |
1688 | ||
1689 | if (!is_hardware_watchpoint (bpt)) | |
1690 | continue; | |
1691 | ||
d6b74ac4 | 1692 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1693 | continue; |
74960c60 VP |
1694 | |
1695 | if (bpt->disposition == disp_del_at_next_stop) | |
1696 | continue; | |
a5606eee VP |
1697 | |
1698 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1699 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1700 | { |
1701 | some_failed = 1; | |
1702 | break; | |
1703 | } | |
1704 | if (some_failed) | |
1705 | { | |
1706 | for (loc = bpt->loc; loc; loc = loc->next) | |
1707 | if (loc->inserted) | |
1708 | remove_breakpoint (loc, mark_uninserted); | |
1709 | ||
1710 | hw_breakpoint_error = 1; | |
1711 | fprintf_unfiltered (tmp_error_stream, | |
1712 | "Could not insert hardware watchpoint %d.\n", | |
1713 | bpt->number); | |
1714 | error = -1; | |
1715 | } | |
1716 | } | |
1717 | ||
e236ba44 | 1718 | if (error) |
81d0cc19 GS |
1719 | { |
1720 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1721 | message about possibly exhausted resources. */ | |
879bfdc2 | 1722 | if (hw_breakpoint_error) |
81d0cc19 | 1723 | { |
c6510018 MS |
1724 | fprintf_unfiltered (tmp_error_stream, |
1725 | "Could not insert hardware breakpoints:\n\ | |
1726 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1727 | } |
81d0cc19 GS |
1728 | target_terminal_ours_for_output (); |
1729 | error_stream (tmp_error_stream); | |
1730 | } | |
f7545552 TT |
1731 | |
1732 | do_cleanups (cleanups); | |
c906108c SS |
1733 | } |
1734 | ||
c906108c | 1735 | int |
fba45db2 | 1736 | remove_breakpoints (void) |
c906108c | 1737 | { |
876fa593 | 1738 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1739 | int val = 0; |
c906108c | 1740 | |
876fa593 | 1741 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1742 | { |
0bde7532 | 1743 | if (b->inserted) |
3a1bae8e | 1744 | val |= remove_breakpoint (b, mark_uninserted); |
c5aa993b | 1745 | } |
3a1bae8e | 1746 | return val; |
c906108c SS |
1747 | } |
1748 | ||
6c95b8df PA |
1749 | /* Remove breakpoints of process PID. */ |
1750 | ||
1751 | int | |
1752 | remove_breakpoints_pid (int pid) | |
1753 | { | |
876fa593 | 1754 | struct bp_location *b, **b_tmp; |
6c95b8df PA |
1755 | int val; |
1756 | struct inferior *inf = find_inferior_pid (pid); | |
1757 | ||
876fa593 | 1758 | ALL_BP_LOCATIONS (b, b_tmp) |
6c95b8df PA |
1759 | { |
1760 | if (b->pspace != inf->pspace) | |
1761 | continue; | |
1762 | ||
1763 | if (b->inserted) | |
1764 | { | |
1765 | val = remove_breakpoint (b, mark_uninserted); | |
1766 | if (val != 0) | |
1767 | return val; | |
1768 | } | |
1769 | } | |
1770 | return 0; | |
1771 | } | |
1772 | ||
692590c1 | 1773 | int |
80ce1ecb | 1774 | remove_hw_watchpoints (void) |
692590c1 | 1775 | { |
876fa593 | 1776 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 1777 | int val = 0; |
692590c1 | 1778 | |
876fa593 | 1779 | ALL_BP_LOCATIONS (b, bp_tmp) |
692590c1 | 1780 | { |
0bde7532 | 1781 | if (b->inserted && b->loc_type == bp_loc_hardware_watchpoint) |
3a1bae8e | 1782 | val |= remove_breakpoint (b, mark_uninserted); |
692590c1 | 1783 | } |
3a1bae8e | 1784 | return val; |
692590c1 MS |
1785 | } |
1786 | ||
c906108c | 1787 | int |
fba45db2 | 1788 | reattach_breakpoints (int pid) |
c906108c | 1789 | { |
6c95b8df | 1790 | struct cleanup *old_chain; |
876fa593 | 1791 | struct bp_location *b, **bp_tmp; |
c906108c | 1792 | int val; |
a4954f26 | 1793 | struct ui_file *tmp_error_stream = mem_fileopen (); |
fa3a767f | 1794 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
1795 | struct inferior *inf; |
1796 | struct thread_info *tp; | |
1797 | ||
1798 | tp = any_live_thread_of_process (pid); | |
1799 | if (tp == NULL) | |
1800 | return 1; | |
1801 | ||
1802 | inf = find_inferior_pid (pid); | |
1803 | old_chain = save_inferior_ptid (); | |
1804 | ||
1805 | inferior_ptid = tp->ptid; | |
a4954f26 DJ |
1806 | |
1807 | make_cleanup_ui_file_delete (tmp_error_stream); | |
c906108c | 1808 | |
876fa593 | 1809 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 1810 | { |
6c95b8df PA |
1811 | if (b->pspace != inf->pspace) |
1812 | continue; | |
1813 | ||
0bde7532 | 1814 | if (b->inserted) |
c5aa993b | 1815 | { |
a4954f26 DJ |
1816 | b->inserted = 0; |
1817 | val = insert_bp_location (b, tmp_error_stream, | |
fa3a767f | 1818 | &dummy1, &dummy2); |
c5aa993b JM |
1819 | if (val != 0) |
1820 | { | |
ce696e05 | 1821 | do_cleanups (old_chain); |
c5aa993b JM |
1822 | return val; |
1823 | } | |
1824 | } | |
1825 | } | |
ce696e05 | 1826 | do_cleanups (old_chain); |
c906108c SS |
1827 | return 0; |
1828 | } | |
1829 | ||
e58b0e63 PA |
1830 | static int internal_breakpoint_number = -1; |
1831 | ||
e62c965a | 1832 | static struct breakpoint * |
a6d9a66e UW |
1833 | create_internal_breakpoint (struct gdbarch *gdbarch, |
1834 | CORE_ADDR address, enum bptype type) | |
e62c965a | 1835 | { |
e62c965a PP |
1836 | struct symtab_and_line sal; |
1837 | struct breakpoint *b; | |
1838 | ||
1839 | init_sal (&sal); /* initialize to zeroes */ | |
1840 | ||
1841 | sal.pc = address; | |
1842 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 1843 | sal.pspace = current_program_space; |
e62c965a | 1844 | |
a6d9a66e | 1845 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
1846 | b->number = internal_breakpoint_number--; |
1847 | b->disposition = disp_donttouch; | |
1848 | ||
1849 | return b; | |
1850 | } | |
1851 | ||
1852 | static void | |
69de3c6a | 1853 | create_overlay_event_breakpoint (char *func_name) |
e62c965a | 1854 | { |
69de3c6a | 1855 | struct objfile *objfile; |
e62c965a | 1856 | |
69de3c6a PP |
1857 | ALL_OBJFILES (objfile) |
1858 | { | |
1859 | struct breakpoint *b; | |
1860 | struct minimal_symbol *m; | |
1861 | ||
1862 | m = lookup_minimal_symbol_text (func_name, objfile); | |
1863 | if (m == NULL) | |
1864 | continue; | |
e62c965a | 1865 | |
a6d9a66e UW |
1866 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1867 | SYMBOL_VALUE_ADDRESS (m), | |
69de3c6a PP |
1868 | bp_overlay_event); |
1869 | b->addr_string = xstrdup (func_name); | |
e62c965a | 1870 | |
69de3c6a PP |
1871 | if (overlay_debugging == ovly_auto) |
1872 | { | |
1873 | b->enable_state = bp_enabled; | |
1874 | overlay_events_enabled = 1; | |
1875 | } | |
1876 | else | |
1877 | { | |
1878 | b->enable_state = bp_disabled; | |
1879 | overlay_events_enabled = 0; | |
1880 | } | |
e62c965a PP |
1881 | } |
1882 | update_global_location_list (1); | |
1883 | } | |
1884 | ||
0fd8e87f UW |
1885 | static void |
1886 | create_longjmp_master_breakpoint (char *func_name) | |
1887 | { | |
6c95b8df | 1888 | struct program_space *pspace; |
0fd8e87f | 1889 | struct objfile *objfile; |
6c95b8df PA |
1890 | struct cleanup *old_chain; |
1891 | ||
1892 | old_chain = save_current_program_space (); | |
0fd8e87f | 1893 | |
6c95b8df | 1894 | ALL_PSPACES (pspace) |
0fd8e87f UW |
1895 | ALL_OBJFILES (objfile) |
1896 | { | |
1897 | struct breakpoint *b; | |
1898 | struct minimal_symbol *m; | |
1899 | ||
1900 | if (!gdbarch_get_longjmp_target_p (get_objfile_arch (objfile))) | |
1901 | continue; | |
1902 | ||
6c95b8df PA |
1903 | set_current_program_space (pspace); |
1904 | ||
0fd8e87f UW |
1905 | m = lookup_minimal_symbol_text (func_name, objfile); |
1906 | if (m == NULL) | |
1907 | continue; | |
1908 | ||
a6d9a66e UW |
1909 | b = create_internal_breakpoint (get_objfile_arch (objfile), |
1910 | SYMBOL_VALUE_ADDRESS (m), | |
0fd8e87f UW |
1911 | bp_longjmp_master); |
1912 | b->addr_string = xstrdup (func_name); | |
1913 | b->enable_state = bp_disabled; | |
1914 | } | |
1915 | update_global_location_list (1); | |
6c95b8df PA |
1916 | |
1917 | do_cleanups (old_chain); | |
0fd8e87f UW |
1918 | } |
1919 | ||
c906108c | 1920 | void |
fba45db2 | 1921 | update_breakpoints_after_exec (void) |
c906108c | 1922 | { |
c5aa993b JM |
1923 | struct breakpoint *b; |
1924 | struct breakpoint *temp; | |
876fa593 | 1925 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 1926 | |
25b22b0a PA |
1927 | /* We're about to delete breakpoints from GDB's lists. If the |
1928 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
1929 | writing the breakpoints' "shadow contents" back into memory. The | |
1930 | "shadow contents" are NOT valid after an exec, so GDB should not | |
1931 | do that. Instead, the target is responsible from marking | |
1932 | breakpoints out as soon as it detects an exec. We don't do that | |
1933 | here instead, because there may be other attempts to delete | |
1934 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 1935 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
1936 | if (bploc->pspace == current_program_space) |
1937 | gdb_assert (!bploc->inserted); | |
c906108c SS |
1938 | |
1939 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 1940 | { |
6c95b8df PA |
1941 | if (b->pspace != current_program_space) |
1942 | continue; | |
1943 | ||
c5aa993b JM |
1944 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
1945 | if (b->type == bp_shlib_event) | |
1946 | { | |
1947 | delete_breakpoint (b); | |
1948 | continue; | |
1949 | } | |
c906108c | 1950 | |
4efc6507 DE |
1951 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
1952 | if (b->type == bp_jit_event) | |
1953 | { | |
1954 | delete_breakpoint (b); | |
1955 | continue; | |
1956 | } | |
1957 | ||
1900040c | 1958 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
1959 | as must overlay event and longjmp master breakpoints. */ |
1960 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
1961 | || b->type == bp_longjmp_master) | |
c4093a6a JM |
1962 | { |
1963 | delete_breakpoint (b); | |
1964 | continue; | |
1965 | } | |
1966 | ||
c5aa993b JM |
1967 | /* Step-resume breakpoints are meaningless after an exec(). */ |
1968 | if (b->type == bp_step_resume) | |
1969 | { | |
1970 | delete_breakpoint (b); | |
1971 | continue; | |
1972 | } | |
1973 | ||
611c83ae PA |
1974 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
1975 | after an exec. */ | |
1976 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume) | |
1977 | { | |
1978 | delete_breakpoint (b); | |
1979 | continue; | |
1980 | } | |
1981 | ||
ce78b96d JB |
1982 | if (b->type == bp_catchpoint) |
1983 | { | |
1984 | /* For now, none of the bp_catchpoint breakpoints need to | |
1985 | do anything at this point. In the future, if some of | |
1986 | the catchpoints need to something, we will need to add | |
1987 | a new method, and call this method from here. */ | |
1988 | continue; | |
1989 | } | |
1990 | ||
c5aa993b JM |
1991 | /* bp_finish is a special case. The only way we ought to be able |
1992 | to see one of these when an exec() has happened, is if the user | |
1993 | caught a vfork, and then said "finish". Ordinarily a finish just | |
1994 | carries them to the call-site of the current callee, by setting | |
1995 | a temporary bp there and resuming. But in this case, the finish | |
1996 | will carry them entirely through the vfork & exec. | |
1997 | ||
1998 | We don't want to allow a bp_finish to remain inserted now. But | |
1999 | we can't safely delete it, 'cause finish_command has a handle to | |
2000 | the bp on a bpstat, and will later want to delete it. There's a | |
2001 | chance (and I've seen it happen) that if we delete the bp_finish | |
2002 | here, that its storage will get reused by the time finish_command | |
2003 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2004 | We really must allow finish_command to delete a bp_finish. | |
2005 | ||
53a5351d JM |
2006 | In the absense of a general solution for the "how do we know |
2007 | it's safe to delete something others may have handles to?" | |
2008 | problem, what we'll do here is just uninsert the bp_finish, and | |
2009 | let finish_command delete it. | |
2010 | ||
2011 | (We know the bp_finish is "doomed" in the sense that it's | |
2012 | momentary, and will be deleted as soon as finish_command sees | |
2013 | the inferior stopped. So it doesn't matter that the bp's | |
2014 | address is probably bogus in the new a.out, unlike e.g., the | |
2015 | solib breakpoints.) */ | |
c5aa993b | 2016 | |
c5aa993b JM |
2017 | if (b->type == bp_finish) |
2018 | { | |
2019 | continue; | |
2020 | } | |
2021 | ||
2022 | /* Without a symbolic address, we have little hope of the | |
2023 | pre-exec() address meaning the same thing in the post-exec() | |
2024 | a.out. */ | |
2025 | if (b->addr_string == NULL) | |
2026 | { | |
2027 | delete_breakpoint (b); | |
2028 | continue; | |
2029 | } | |
c5aa993b | 2030 | } |
1900040c | 2031 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
69de3c6a | 2032 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
2033 | create_longjmp_master_breakpoint ("longjmp"); |
2034 | create_longjmp_master_breakpoint ("_longjmp"); | |
2035 | create_longjmp_master_breakpoint ("siglongjmp"); | |
2036 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
2037 | } |
2038 | ||
2039 | int | |
fba45db2 | 2040 | detach_breakpoints (int pid) |
c906108c | 2041 | { |
876fa593 | 2042 | struct bp_location *b, **bp_tmp; |
3a1bae8e | 2043 | int val = 0; |
ce696e05 | 2044 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2045 | struct inferior *inf = current_inferior (); |
c5aa993b | 2046 | |
39f77062 | 2047 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2048 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2049 | |
6c95b8df | 2050 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2051 | inferior_ptid = pid_to_ptid (pid); |
876fa593 | 2052 | ALL_BP_LOCATIONS (b, bp_tmp) |
c5aa993b | 2053 | { |
6c95b8df PA |
2054 | if (b->pspace != inf->pspace) |
2055 | continue; | |
2056 | ||
0bde7532 | 2057 | if (b->inserted) |
6c95b8df | 2058 | val |= remove_breakpoint_1 (b, mark_inserted); |
c5aa993b | 2059 | } |
ce696e05 | 2060 | do_cleanups (old_chain); |
3a1bae8e | 2061 | return val; |
c906108c SS |
2062 | } |
2063 | ||
6c95b8df PA |
2064 | /* Remove the breakpoint location B from the current address space. |
2065 | Note that this is used to detach breakpoints from a child fork. | |
2066 | When we get here, the child isn't in the inferior list, and neither | |
2067 | do we have objects to represent its address space --- we should | |
2068 | *not* look at b->pspace->aspace here. */ | |
2069 | ||
c906108c | 2070 | static int |
6c95b8df | 2071 | remove_breakpoint_1 (struct bp_location *b, insertion_state_t is) |
c906108c SS |
2072 | { |
2073 | int val; | |
6c95b8df | 2074 | struct cleanup *old_chain; |
c5aa993b | 2075 | |
0bde7532 | 2076 | if (b->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2077 | /* Permanent breakpoints cannot be inserted or removed. */ |
2078 | return 0; | |
2079 | ||
74960c60 VP |
2080 | /* The type of none suggests that owner is actually deleted. |
2081 | This should not ever happen. */ | |
2082 | gdb_assert (b->owner->type != bp_none); | |
0bde7532 DJ |
2083 | |
2084 | if (b->loc_type == bp_loc_software_breakpoint | |
2085 | || b->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2086 | { |
c02f5703 MS |
2087 | /* "Normal" instruction breakpoint: either the standard |
2088 | trap-instruction bp (bp_breakpoint), or a | |
2089 | bp_hardware_breakpoint. */ | |
2090 | ||
2091 | /* First check to see if we have to handle an overlay. */ | |
2092 | if (overlay_debugging == ovly_off | |
0bde7532 DJ |
2093 | || b->section == NULL |
2094 | || !(section_is_overlay (b->section))) | |
c02f5703 MS |
2095 | { |
2096 | /* No overlay handling: just remove the breakpoint. */ | |
2097 | ||
0bde7532 | 2098 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e | 2099 | val = target_remove_hw_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2100 | else |
a6d9a66e | 2101 | val = target_remove_breakpoint (b->gdbarch, &b->target_info); |
c02f5703 | 2102 | } |
c906108c SS |
2103 | else |
2104 | { | |
c02f5703 MS |
2105 | /* This breakpoint is in an overlay section. |
2106 | Did we set a breakpoint at the LMA? */ | |
2107 | if (!overlay_events_enabled) | |
2108 | { | |
2109 | /* Yes -- overlay event support is not active, so we | |
2110 | should have set a breakpoint at the LMA. Remove it. | |
2111 | */ | |
c02f5703 MS |
2112 | /* Ignore any failures: if the LMA is in ROM, we will |
2113 | have already warned when we failed to insert it. */ | |
0bde7532 | 2114 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2115 | target_remove_hw_breakpoint (b->gdbarch, |
2116 | &b->overlay_target_info); | |
c02f5703 | 2117 | else |
a6d9a66e UW |
2118 | target_remove_breakpoint (b->gdbarch, |
2119 | &b->overlay_target_info); | |
c02f5703 MS |
2120 | } |
2121 | /* Did we set a breakpoint at the VMA? | |
2122 | If so, we will have marked the breakpoint 'inserted'. */ | |
0bde7532 | 2123 | if (b->inserted) |
c906108c | 2124 | { |
c02f5703 MS |
2125 | /* Yes -- remove it. Previously we did not bother to |
2126 | remove the breakpoint if the section had been | |
2127 | unmapped, but let's not rely on that being safe. We | |
2128 | don't know what the overlay manager might do. */ | |
0bde7532 | 2129 | if (b->loc_type == bp_loc_hardware_breakpoint) |
a6d9a66e UW |
2130 | val = target_remove_hw_breakpoint (b->gdbarch, |
2131 | &b->target_info); | |
aa67235e UW |
2132 | |
2133 | /* However, we should remove *software* breakpoints only | |
2134 | if the section is still mapped, or else we overwrite | |
2135 | wrong code with the saved shadow contents. */ | |
2136 | else if (section_is_mapped (b->section)) | |
a6d9a66e UW |
2137 | val = target_remove_breakpoint (b->gdbarch, |
2138 | &b->target_info); | |
aa67235e UW |
2139 | else |
2140 | val = 0; | |
c906108c | 2141 | } |
c02f5703 MS |
2142 | else |
2143 | { | |
2144 | /* No -- not inserted, so no need to remove. No error. */ | |
2145 | val = 0; | |
2146 | } | |
c906108c | 2147 | } |
879d1e6b UW |
2148 | |
2149 | /* In some cases, we might not be able to remove a breakpoint | |
2150 | in a shared library that has already been removed, but we | |
2151 | have not yet processed the shlib unload event. */ | |
6c95b8df | 2152 | if (val && solib_name_from_address (b->pspace, b->address)) |
879d1e6b UW |
2153 | val = 0; |
2154 | ||
c906108c SS |
2155 | if (val) |
2156 | return val; | |
0bde7532 | 2157 | b->inserted = (is == mark_inserted); |
c906108c | 2158 | } |
a5606eee | 2159 | else if (b->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2160 | { |
278cd55f AC |
2161 | struct value *v; |
2162 | struct value *n; | |
c5aa993b | 2163 | |
0bde7532 | 2164 | b->inserted = (is == mark_inserted); |
a5606eee VP |
2165 | val = target_remove_watchpoint (b->address, b->length, |
2166 | b->watchpoint_type); | |
2e70b7b9 | 2167 | |
c906108c | 2168 | /* Failure to remove any of the hardware watchpoints comes here. */ |
0bde7532 | 2169 | if ((is == mark_uninserted) && (b->inserted)) |
8a3fe4f8 | 2170 | warning (_("Could not remove hardware watchpoint %d."), |
0bde7532 | 2171 | b->owner->number); |
c906108c | 2172 | } |
ce78b96d JB |
2173 | else if (b->owner->type == bp_catchpoint |
2174 | && breakpoint_enabled (b->owner) | |
2175 | && !b->duplicate) | |
2176 | { | |
2177 | gdb_assert (b->owner->ops != NULL && b->owner->ops->remove != NULL); | |
2178 | ||
2179 | val = b->owner->ops->remove (b->owner); | |
2180 | if (val) | |
2181 | return val; | |
2182 | b->inserted = (is == mark_inserted); | |
2183 | } | |
c906108c SS |
2184 | |
2185 | return 0; | |
2186 | } | |
2187 | ||
6c95b8df PA |
2188 | static int |
2189 | remove_breakpoint (struct bp_location *b, insertion_state_t is) | |
2190 | { | |
2191 | int ret; | |
2192 | struct cleanup *old_chain; | |
2193 | ||
2194 | if (b->owner->enable_state == bp_permanent) | |
2195 | /* Permanent breakpoints cannot be inserted or removed. */ | |
2196 | return 0; | |
2197 | ||
2198 | /* The type of none suggests that owner is actually deleted. | |
2199 | This should not ever happen. */ | |
2200 | gdb_assert (b->owner->type != bp_none); | |
2201 | ||
2202 | old_chain = save_current_space_and_thread (); | |
2203 | ||
2204 | switch_to_program_space_and_thread (b->pspace); | |
2205 | ||
2206 | ret = remove_breakpoint_1 (b, is); | |
2207 | ||
2208 | do_cleanups (old_chain); | |
2209 | return ret; | |
2210 | } | |
2211 | ||
c906108c SS |
2212 | /* Clear the "inserted" flag in all breakpoints. */ |
2213 | ||
25b22b0a | 2214 | void |
fba45db2 | 2215 | mark_breakpoints_out (void) |
c906108c | 2216 | { |
876fa593 | 2217 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2218 | |
876fa593 | 2219 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2220 | if (bpt->pspace == current_program_space) |
2221 | bpt->inserted = 0; | |
c906108c SS |
2222 | } |
2223 | ||
53a5351d JM |
2224 | /* Clear the "inserted" flag in all breakpoints and delete any |
2225 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2226 | |
2227 | Plus other such housekeeping that has to be done for breakpoints | |
2228 | between runs. | |
2229 | ||
53a5351d JM |
2230 | Note: this function gets called at the end of a run (by |
2231 | generic_mourn_inferior) and when a run begins (by | |
2232 | init_wait_for_inferior). */ | |
c906108c SS |
2233 | |
2234 | ||
2235 | ||
2236 | void | |
fba45db2 | 2237 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2238 | { |
52f0bd74 | 2239 | struct breakpoint *b, *temp; |
876fa593 | 2240 | struct bp_location *bpt, **bptp_tmp; |
1c5cfe86 | 2241 | int ix; |
6c95b8df | 2242 | struct program_space *pspace = current_program_space; |
c906108c | 2243 | |
50c71eaf PA |
2244 | /* If breakpoint locations are shared across processes, then there's |
2245 | nothing to do. */ | |
2567c7d9 | 2246 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2247 | return; |
2248 | ||
876fa593 | 2249 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
6c95b8df PA |
2250 | { |
2251 | if (bpt->pspace == pspace | |
2252 | && bpt->owner->enable_state != bp_permanent) | |
514f746b | 2253 | bpt->inserted = 0; |
6c95b8df | 2254 | } |
075f6582 | 2255 | |
c906108c | 2256 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 2257 | { |
6c95b8df PA |
2258 | if (b->loc && b->loc->pspace != pspace) |
2259 | continue; | |
2260 | ||
c5aa993b JM |
2261 | switch (b->type) |
2262 | { | |
2263 | case bp_call_dummy: | |
c906108c | 2264 | |
c5aa993b | 2265 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2266 | cause problems when the inferior is rerun, so we better get |
2267 | rid of it. */ | |
2268 | ||
2269 | case bp_watchpoint_scope: | |
2270 | ||
2271 | /* Also get rid of scope breakpoints. */ | |
2272 | ||
2273 | case bp_shlib_event: | |
2274 | ||
2275 | /* Also remove solib event breakpoints. Their addresses may | |
2276 | have changed since the last time we ran the program. | |
2277 | Actually we may now be debugging against different target; | |
2278 | and so the solib backend that installed this breakpoint may | |
2279 | not be used in by the target. E.g., | |
2280 | ||
2281 | (gdb) file prog-linux | |
2282 | (gdb) run # native linux target | |
2283 | ... | |
2284 | (gdb) kill | |
2285 | (gdb) file prog-win.exe | |
2286 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2287 | */ | |
c906108c | 2288 | |
c5aa993b JM |
2289 | delete_breakpoint (b); |
2290 | break; | |
c906108c | 2291 | |
c5aa993b JM |
2292 | case bp_watchpoint: |
2293 | case bp_hardware_watchpoint: | |
2294 | case bp_read_watchpoint: | |
2295 | case bp_access_watchpoint: | |
c906108c | 2296 | |
c5aa993b JM |
2297 | /* Likewise for watchpoints on local expressions. */ |
2298 | if (b->exp_valid_block != NULL) | |
2299 | delete_breakpoint (b); | |
967af18d | 2300 | else if (context == inf_starting) |
c860120c PM |
2301 | { |
2302 | /* Reset val field to force reread of starting value | |
2303 | in insert_breakpoints. */ | |
2304 | if (b->val) | |
2305 | value_free (b->val); | |
2306 | b->val = NULL; | |
fa4727a6 | 2307 | b->val_valid = 0; |
c860120c | 2308 | } |
c5aa993b JM |
2309 | break; |
2310 | default: | |
c5aa993b JM |
2311 | break; |
2312 | } | |
2313 | } | |
1c5cfe86 PA |
2314 | |
2315 | /* Get rid of the moribund locations. */ | |
2316 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bpt); ++ix) | |
2317 | free_bp_location (bpt); | |
2318 | VEC_free (bp_location_p, moribund_locations); | |
c906108c SS |
2319 | } |
2320 | ||
6c95b8df PA |
2321 | /* These functions concern about actual breakpoints inserted in the |
2322 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2323 | we need to hop over the bkpt --- so we check for address space | |
2324 | match, not program space. */ | |
2325 | ||
c2c6d25f JM |
2326 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2327 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2328 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2329 | permanent breakpoint. | |
2330 | - When continuing from a location with an ordinary breakpoint, we | |
2331 | actually single step once before calling insert_breakpoints. | |
2332 | - When continuing from a localion with a permanent breakpoint, we | |
2333 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2334 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2335 | |
c2c6d25f | 2336 | enum breakpoint_here |
6c95b8df | 2337 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2338 | { |
876fa593 | 2339 | struct bp_location *bpt, **bptp_tmp; |
c2c6d25f | 2340 | int any_breakpoint_here = 0; |
c906108c | 2341 | |
876fa593 | 2342 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
075f6582 DJ |
2343 | { |
2344 | if (bpt->loc_type != bp_loc_software_breakpoint | |
2345 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2346 | continue; | |
2347 | ||
468d015d | 2348 | if ((breakpoint_enabled (bpt->owner) |
075f6582 | 2349 | || bpt->owner->enable_state == bp_permanent) |
6c95b8df PA |
2350 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2351 | aspace, pc)) | |
075f6582 DJ |
2352 | { |
2353 | if (overlay_debugging | |
2354 | && section_is_overlay (bpt->section) | |
2355 | && !section_is_mapped (bpt->section)) | |
2356 | continue; /* unmapped overlay -- can't be a match */ | |
2357 | else if (bpt->owner->enable_state == bp_permanent) | |
2358 | return permanent_breakpoint_here; | |
2359 | else | |
2360 | any_breakpoint_here = 1; | |
2361 | } | |
2362 | } | |
c906108c | 2363 | |
c2c6d25f | 2364 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2365 | } |
2366 | ||
1c5cfe86 PA |
2367 | /* Return true if there's a moribund breakpoint at PC. */ |
2368 | ||
2369 | int | |
6c95b8df | 2370 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2371 | { |
2372 | struct bp_location *loc; | |
2373 | int ix; | |
2374 | ||
2375 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
6c95b8df PA |
2376 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
2377 | aspace, pc)) | |
1c5cfe86 PA |
2378 | return 1; |
2379 | ||
2380 | return 0; | |
2381 | } | |
c2c6d25f | 2382 | |
c36b740a | 2383 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
876fa593 | 2384 | inserted using regular breakpoint_chain / bp_location array mechanism. |
c36b740a VP |
2385 | This does not check for single-step breakpoints, which are |
2386 | inserted and removed using direct target manipulation. */ | |
c906108c SS |
2387 | |
2388 | int | |
6c95b8df | 2389 | regular_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2390 | { |
876fa593 | 2391 | struct bp_location *bpt, **bptp_tmp; |
c906108c | 2392 | |
876fa593 | 2393 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2394 | { |
075f6582 DJ |
2395 | if (bpt->loc_type != bp_loc_software_breakpoint |
2396 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2397 | continue; | |
2398 | ||
2399 | if (bpt->inserted | |
6c95b8df PA |
2400 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2401 | aspace, pc)) | |
075f6582 DJ |
2402 | { |
2403 | if (overlay_debugging | |
2404 | && section_is_overlay (bpt->section) | |
2405 | && !section_is_mapped (bpt->section)) | |
2406 | continue; /* unmapped overlay -- can't be a match */ | |
2407 | else | |
2408 | return 1; | |
2409 | } | |
c5aa993b | 2410 | } |
c36b740a VP |
2411 | return 0; |
2412 | } | |
2413 | ||
2414 | /* Returns non-zero iff there's either regular breakpoint | |
2415 | or a single step breakpoint inserted at PC. */ | |
2416 | ||
2417 | int | |
6c95b8df | 2418 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2419 | { |
6c95b8df | 2420 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2421 | return 1; |
c906108c | 2422 | |
6c95b8df | 2423 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2424 | return 1; |
2425 | ||
c906108c SS |
2426 | return 0; |
2427 | } | |
2428 | ||
4fa8626c DJ |
2429 | /* This function returns non-zero iff there is a software breakpoint |
2430 | inserted at PC. */ | |
2431 | ||
2432 | int | |
6c95b8df | 2433 | software_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
4fa8626c | 2434 | { |
876fa593 | 2435 | struct bp_location *bpt, **bptp_tmp; |
4fa8626c DJ |
2436 | int any_breakpoint_here = 0; |
2437 | ||
876fa593 | 2438 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
4fa8626c DJ |
2439 | { |
2440 | if (bpt->loc_type != bp_loc_software_breakpoint) | |
2441 | continue; | |
2442 | ||
0d381245 | 2443 | if (bpt->inserted |
6c95b8df PA |
2444 | && breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2445 | aspace, pc)) | |
4fa8626c DJ |
2446 | { |
2447 | if (overlay_debugging | |
2448 | && section_is_overlay (bpt->section) | |
2449 | && !section_is_mapped (bpt->section)) | |
2450 | continue; /* unmapped overlay -- can't be a match */ | |
2451 | else | |
2452 | return 1; | |
2453 | } | |
2454 | } | |
2455 | ||
1aafd4da | 2456 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2457 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2458 | return 1; |
2459 | ||
4fa8626c DJ |
2460 | return 0; |
2461 | } | |
2462 | ||
9093389c PA |
2463 | int |
2464 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2465 | CORE_ADDR addr, ULONGEST len) | |
2466 | { | |
2467 | struct breakpoint *bpt; | |
2468 | ||
2469 | ALL_BREAKPOINTS (bpt) | |
2470 | { | |
2471 | struct bp_location *loc; | |
2472 | ||
2473 | if (bpt->type != bp_hardware_watchpoint | |
2474 | && bpt->type != bp_access_watchpoint) | |
2475 | continue; | |
2476 | ||
2477 | if (!breakpoint_enabled (bpt)) | |
2478 | continue; | |
2479 | ||
2480 | for (loc = bpt->loc; loc; loc = loc->next) | |
2481 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2482 | { | |
2483 | CORE_ADDR l, h; | |
2484 | ||
2485 | /* Check for intersection. */ | |
2486 | l = max (loc->address, addr); | |
2487 | h = min (loc->address + loc->length, addr + len); | |
2488 | if (l < h) | |
2489 | return 1; | |
2490 | } | |
2491 | } | |
2492 | return 0; | |
2493 | } | |
2494 | ||
075f6582 DJ |
2495 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2496 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2497 | |
2498 | int | |
6c95b8df PA |
2499 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2500 | ptid_t ptid) | |
c906108c | 2501 | { |
876fa593 | 2502 | struct bp_location *bpt, **bptp_tmp; |
4a306c9a | 2503 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2504 | int thread = -1; |
4a306c9a | 2505 | int task = 0; |
a6f1cd96 | 2506 | |
876fa593 | 2507 | ALL_BP_LOCATIONS (bpt, bptp_tmp) |
c5aa993b | 2508 | { |
075f6582 DJ |
2509 | if (bpt->loc_type != bp_loc_software_breakpoint |
2510 | && bpt->loc_type != bp_loc_hardware_breakpoint) | |
2511 | continue; | |
2512 | ||
a6f1cd96 JB |
2513 | if (!breakpoint_enabled (bpt->owner) |
2514 | && bpt->owner->enable_state != bp_permanent) | |
2515 | continue; | |
2516 | ||
6c95b8df PA |
2517 | if (!breakpoint_address_match (bpt->pspace->aspace, bpt->address, |
2518 | aspace, pc)) | |
a6f1cd96 JB |
2519 | continue; |
2520 | ||
2521 | if (bpt->owner->thread != -1) | |
075f6582 | 2522 | { |
a6f1cd96 JB |
2523 | /* This is a thread-specific breakpoint. Check that ptid |
2524 | matches that thread. If thread hasn't been computed yet, | |
2525 | it is now time to do so. */ | |
2526 | if (thread == -1) | |
2527 | thread = pid_to_thread_id (ptid); | |
2528 | if (bpt->owner->thread != thread) | |
2529 | continue; | |
075f6582 | 2530 | } |
a6f1cd96 | 2531 | |
4a306c9a JB |
2532 | if (bpt->owner->task != 0) |
2533 | { | |
2534 | /* This is a task-specific breakpoint. Check that ptid | |
2535 | matches that task. If task hasn't been computed yet, | |
2536 | it is now time to do so. */ | |
2537 | if (task == 0) | |
2538 | task = ada_get_task_number (ptid); | |
2539 | if (bpt->owner->task != task) | |
2540 | continue; | |
2541 | } | |
2542 | ||
a6f1cd96 JB |
2543 | if (overlay_debugging |
2544 | && section_is_overlay (bpt->section) | |
2545 | && !section_is_mapped (bpt->section)) | |
2546 | continue; /* unmapped overlay -- can't be a match */ | |
2547 | ||
2548 | return 1; | |
c5aa993b | 2549 | } |
c906108c SS |
2550 | |
2551 | return 0; | |
2552 | } | |
c906108c | 2553 | \f |
c5aa993b | 2554 | |
c906108c SS |
2555 | /* bpstat stuff. External routines' interfaces are documented |
2556 | in breakpoint.h. */ | |
2557 | ||
2558 | int | |
fba45db2 | 2559 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 2560 | { |
533be4dd | 2561 | return (ep->type == bp_catchpoint); |
c906108c SS |
2562 | } |
2563 | ||
198757a8 VP |
2564 | void |
2565 | bpstat_free (bpstat bs) | |
2566 | { | |
2567 | if (bs->old_val != NULL) | |
2568 | value_free (bs->old_val); | |
2569 | free_command_lines (&bs->commands); | |
2570 | xfree (bs); | |
2571 | } | |
2572 | ||
c906108c SS |
2573 | /* Clear a bpstat so that it says we are not at any breakpoint. |
2574 | Also free any storage that is part of a bpstat. */ | |
2575 | ||
2576 | void | |
fba45db2 | 2577 | bpstat_clear (bpstat *bsp) |
c906108c SS |
2578 | { |
2579 | bpstat p; | |
2580 | bpstat q; | |
2581 | ||
2582 | if (bsp == 0) | |
2583 | return; | |
2584 | p = *bsp; | |
2585 | while (p != NULL) | |
2586 | { | |
2587 | q = p->next; | |
198757a8 | 2588 | bpstat_free (p); |
c906108c SS |
2589 | p = q; |
2590 | } | |
2591 | *bsp = NULL; | |
2592 | } | |
2593 | ||
2594 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
2595 | is part of the bpstat is copied as well. */ | |
2596 | ||
2597 | bpstat | |
fba45db2 | 2598 | bpstat_copy (bpstat bs) |
c906108c SS |
2599 | { |
2600 | bpstat p = NULL; | |
2601 | bpstat tmp; | |
2602 | bpstat retval = NULL; | |
2603 | ||
2604 | if (bs == NULL) | |
2605 | return bs; | |
2606 | ||
2607 | for (; bs != NULL; bs = bs->next) | |
2608 | { | |
2609 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
2610 | memcpy (tmp, bs, sizeof (*tmp)); | |
31cc81e9 DJ |
2611 | if (bs->commands != NULL) |
2612 | tmp->commands = copy_command_lines (bs->commands); | |
2613 | if (bs->old_val != NULL) | |
3c3185ac JK |
2614 | { |
2615 | tmp->old_val = value_copy (bs->old_val); | |
2616 | release_value (tmp->old_val); | |
2617 | } | |
31cc81e9 | 2618 | |
c906108c SS |
2619 | if (p == NULL) |
2620 | /* This is the first thing in the chain. */ | |
2621 | retval = tmp; | |
2622 | else | |
2623 | p->next = tmp; | |
2624 | p = tmp; | |
2625 | } | |
2626 | p->next = NULL; | |
2627 | return retval; | |
2628 | } | |
2629 | ||
2630 | /* Find the bpstat associated with this breakpoint */ | |
2631 | ||
2632 | bpstat | |
fba45db2 | 2633 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 2634 | { |
c5aa993b JM |
2635 | if (bsp == NULL) |
2636 | return NULL; | |
c906108c | 2637 | |
c5aa993b JM |
2638 | for (; bsp != NULL; bsp = bsp->next) |
2639 | { | |
4f8d1dc6 | 2640 | if (bsp->breakpoint_at && bsp->breakpoint_at->owner == breakpoint) |
c5aa993b JM |
2641 | return bsp; |
2642 | } | |
c906108c SS |
2643 | return NULL; |
2644 | } | |
2645 | ||
2646 | /* Find a step_resume breakpoint associated with this bpstat. | |
2647 | (If there are multiple step_resume bp's on the list, this function | |
2648 | will arbitrarily pick one.) | |
2649 | ||
2650 | It is an error to use this function if BPSTAT doesn't contain a | |
2651 | step_resume breakpoint. | |
2652 | ||
2653 | See wait_for_inferior's use of this function. */ | |
2654 | struct breakpoint * | |
fba45db2 | 2655 | bpstat_find_step_resume_breakpoint (bpstat bsp) |
c906108c | 2656 | { |
8601f500 MS |
2657 | int current_thread; |
2658 | ||
8a3fe4f8 | 2659 | gdb_assert (bsp != NULL); |
c906108c | 2660 | |
8601f500 MS |
2661 | current_thread = pid_to_thread_id (inferior_ptid); |
2662 | ||
c906108c SS |
2663 | for (; bsp != NULL; bsp = bsp->next) |
2664 | { | |
059fb39f PM |
2665 | if ((bsp->breakpoint_at != NULL) |
2666 | && (bsp->breakpoint_at->owner->type == bp_step_resume) | |
2667 | && (bsp->breakpoint_at->owner->thread == current_thread | |
2668 | || bsp->breakpoint_at->owner->thread == -1)) | |
4f8d1dc6 | 2669 | return bsp->breakpoint_at->owner; |
c906108c SS |
2670 | } |
2671 | ||
8a3fe4f8 | 2672 | internal_error (__FILE__, __LINE__, _("No step_resume breakpoint found.")); |
c906108c SS |
2673 | } |
2674 | ||
2675 | ||
8671a17b | 2676 | /* Put in *NUM the breakpoint number of the first breakpoint we are stopped |
c906108c SS |
2677 | at. *BSP upon return is a bpstat which points to the remaining |
2678 | breakpoints stopped at (but which is not guaranteed to be good for | |
2679 | anything but further calls to bpstat_num). | |
8671a17b PA |
2680 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
2681 | Return -1 if stopped at a breakpoint that has been deleted since | |
2682 | we set it. | |
2683 | Return 1 otherwise. */ | |
c906108c SS |
2684 | |
2685 | int | |
8671a17b | 2686 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
2687 | { |
2688 | struct breakpoint *b; | |
2689 | ||
2690 | if ((*bsp) == NULL) | |
2691 | return 0; /* No more breakpoint values */ | |
8671a17b | 2692 | |
4f8d1dc6 VP |
2693 | /* We assume we'll never have several bpstats that |
2694 | correspond to a single breakpoint -- otherwise, | |
2695 | this function might return the same number more | |
2696 | than once and this will look ugly. */ | |
2697 | b = (*bsp)->breakpoint_at ? (*bsp)->breakpoint_at->owner : NULL; | |
8671a17b PA |
2698 | *bsp = (*bsp)->next; |
2699 | if (b == NULL) | |
2700 | return -1; /* breakpoint that's been deleted since */ | |
2701 | ||
2702 | *num = b->number; /* We have its number */ | |
2703 | return 1; | |
c906108c SS |
2704 | } |
2705 | ||
2706 | /* Modify BS so that the actions will not be performed. */ | |
2707 | ||
2708 | void | |
fba45db2 | 2709 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
2710 | { |
2711 | for (; bs != NULL; bs = bs->next) | |
2712 | { | |
c2b8ed2c | 2713 | free_command_lines (&bs->commands); |
c906108c SS |
2714 | if (bs->old_val != NULL) |
2715 | { | |
2716 | value_free (bs->old_val); | |
2717 | bs->old_val = NULL; | |
2718 | } | |
2719 | } | |
2720 | } | |
2721 | ||
f3b1572e PA |
2722 | /* Called when a command is about to proceed the inferior. */ |
2723 | ||
2724 | static void | |
2725 | breakpoint_about_to_proceed (void) | |
2726 | { | |
2727 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
2728 | { | |
2729 | struct thread_info *tp = inferior_thread (); | |
2730 | ||
2731 | /* Allow inferior function calls in breakpoint commands to not | |
2732 | interrupt the command list. When the call finishes | |
2733 | successfully, the inferior will be standing at the same | |
2734 | breakpoint as if nothing happened. */ | |
2735 | if (tp->in_infcall) | |
2736 | return; | |
2737 | } | |
2738 | ||
2739 | breakpoint_proceeded = 1; | |
2740 | } | |
2741 | ||
c906108c | 2742 | /* Stub for cleaning up our state if we error-out of a breakpoint command */ |
c906108c | 2743 | static void |
4efb68b1 | 2744 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
2745 | { |
2746 | executing_breakpoint_commands = 0; | |
2747 | } | |
2748 | ||
2749 | /* Execute all the commands associated with all the breakpoints at this | |
2750 | location. Any of these commands could cause the process to proceed | |
2751 | beyond this point, etc. We look out for such changes by checking | |
347bddb7 | 2752 | the global "breakpoint_proceeded" after each command. |
c906108c | 2753 | |
347bddb7 PA |
2754 | Returns true if a breakpoint command resumed the inferior. In that |
2755 | case, it is the caller's responsibility to recall it again with the | |
2756 | bpstat of the current thread. */ | |
2757 | ||
2758 | static int | |
2759 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
2760 | { |
2761 | bpstat bs; | |
2762 | struct cleanup *old_chain; | |
347bddb7 | 2763 | int again = 0; |
c906108c SS |
2764 | |
2765 | /* Avoid endless recursion if a `source' command is contained | |
2766 | in bs->commands. */ | |
2767 | if (executing_breakpoint_commands) | |
347bddb7 | 2768 | return 0; |
c906108c SS |
2769 | |
2770 | executing_breakpoint_commands = 1; | |
2771 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
2772 | ||
c906108c SS |
2773 | /* This pointer will iterate over the list of bpstat's. */ |
2774 | bs = *bsp; | |
2775 | ||
2776 | breakpoint_proceeded = 0; | |
2777 | for (; bs != NULL; bs = bs->next) | |
2778 | { | |
6c50ab1c JB |
2779 | struct command_line *cmd; |
2780 | struct cleanup *this_cmd_tree_chain; | |
2781 | ||
2782 | /* Take ownership of the BSP's command tree, if it has one. | |
2783 | ||
2784 | The command tree could legitimately contain commands like | |
2785 | 'step' and 'next', which call clear_proceed_status, which | |
2786 | frees stop_bpstat's command tree. To make sure this doesn't | |
2787 | free the tree we're executing out from under us, we need to | |
2788 | take ownership of the tree ourselves. Since a given bpstat's | |
2789 | commands are only executed once, we don't need to copy it; we | |
2790 | can clear the pointer in the bpstat, and make sure we free | |
2791 | the tree when we're done. */ | |
c906108c | 2792 | cmd = bs->commands; |
6c50ab1c JB |
2793 | bs->commands = 0; |
2794 | this_cmd_tree_chain = make_cleanup_free_command_lines (&cmd); | |
2795 | ||
c906108c SS |
2796 | while (cmd != NULL) |
2797 | { | |
2798 | execute_control_command (cmd); | |
2799 | ||
2800 | if (breakpoint_proceeded) | |
2801 | break; | |
2802 | else | |
2803 | cmd = cmd->next; | |
2804 | } | |
6c50ab1c JB |
2805 | |
2806 | /* We can free this command tree now. */ | |
2807 | do_cleanups (this_cmd_tree_chain); | |
2808 | ||
c906108c | 2809 | if (breakpoint_proceeded) |
32c1e744 VP |
2810 | { |
2811 | if (target_can_async_p ()) | |
347bddb7 PA |
2812 | /* If we are in async mode, then the target might be still |
2813 | running, not stopped at any breakpoint, so nothing for | |
2814 | us to do here -- just return to the event loop. */ | |
2815 | ; | |
32c1e744 VP |
2816 | else |
2817 | /* In sync mode, when execute_control_command returns | |
2818 | we're already standing on the next breakpoint. | |
347bddb7 PA |
2819 | Breakpoint commands for that stop were not run, since |
2820 | execute_command does not run breakpoint commands -- | |
2821 | only command_line_handler does, but that one is not | |
2822 | involved in execution of breakpoint commands. So, we | |
2823 | can now execute breakpoint commands. It should be | |
2824 | noted that making execute_command do bpstat actions is | |
2825 | not an option -- in this case we'll have recursive | |
2826 | invocation of bpstat for each breakpoint with a | |
2827 | command, and can easily blow up GDB stack. Instead, we | |
2828 | return true, which will trigger the caller to recall us | |
2829 | with the new stop_bpstat. */ | |
2830 | again = 1; | |
2831 | break; | |
32c1e744 | 2832 | } |
c906108c | 2833 | } |
c2b8ed2c | 2834 | do_cleanups (old_chain); |
347bddb7 PA |
2835 | return again; |
2836 | } | |
2837 | ||
2838 | void | |
2839 | bpstat_do_actions (void) | |
2840 | { | |
2841 | /* Do any commands attached to breakpoint we are stopped at. */ | |
2842 | while (!ptid_equal (inferior_ptid, null_ptid) | |
2843 | && target_has_execution | |
2844 | && !is_exited (inferior_ptid) | |
2845 | && !is_executing (inferior_ptid)) | |
2846 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
2847 | and only return when it is stopped at the next breakpoint, we | |
2848 | keep doing breakpoint actions until it returns false to | |
2849 | indicate the inferior was not resumed. */ | |
2850 | if (!bpstat_do_actions_1 (&inferior_thread ()->stop_bpstat)) | |
2851 | break; | |
c906108c SS |
2852 | } |
2853 | ||
fa4727a6 DJ |
2854 | /* Print out the (old or new) value associated with a watchpoint. */ |
2855 | ||
2856 | static void | |
2857 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
2858 | { | |
2859 | if (val == NULL) | |
2860 | fprintf_unfiltered (stream, _("<unreadable>")); | |
2861 | else | |
79a45b7d TT |
2862 | { |
2863 | struct value_print_options opts; | |
2864 | get_user_print_options (&opts); | |
2865 | value_print (val, stream, &opts); | |
2866 | } | |
fa4727a6 DJ |
2867 | } |
2868 | ||
e514a9d6 | 2869 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 2870 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
2871 | by having it set different print_it values. |
2872 | ||
2873 | Current scheme: When we stop, bpstat_print() is called. It loops | |
2874 | through the bpstat list of things causing this stop, calling the | |
2875 | print_bp_stop_message function on each one. The behavior of the | |
2876 | print_bp_stop_message function depends on the print_it field of | |
2877 | bpstat. If such field so indicates, call this function here. | |
2878 | ||
2879 | Return values from this routine (ultimately used by bpstat_print() | |
2880 | and normal_stop() to decide what to do): | |
2881 | PRINT_NOTHING: Means we already printed all we needed to print, | |
2882 | don't print anything else. | |
2883 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
2884 | that something to be followed by a location. | |
2885 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
2886 | that something to be followed by a location. | |
2887 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
2888 | analysis. */ | |
c906108c | 2889 | |
917317f4 | 2890 | static enum print_stop_action |
fba45db2 | 2891 | print_it_typical (bpstat bs) |
c906108c | 2892 | { |
f7545552 | 2893 | struct cleanup *old_chain; |
4f8d1dc6 | 2894 | struct breakpoint *b; |
89f9893c | 2895 | const struct bp_location *bl; |
8b93c638 | 2896 | struct ui_stream *stb; |
f7545552 TT |
2897 | int bp_temp = 0; |
2898 | enum print_stop_action result; | |
2899 | ||
c906108c SS |
2900 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
2901 | which has since been deleted. */ | |
e514a9d6 | 2902 | if (bs->breakpoint_at == NULL) |
917317f4 | 2903 | return PRINT_UNKNOWN; |
0d381245 VP |
2904 | bl = bs->breakpoint_at; |
2905 | b = bl->owner; | |
c906108c | 2906 | |
f7545552 TT |
2907 | stb = ui_out_stream_new (uiout); |
2908 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
2909 | ||
4f8d1dc6 | 2910 | switch (b->type) |
c906108c | 2911 | { |
e514a9d6 JM |
2912 | case bp_breakpoint: |
2913 | case bp_hardware_breakpoint: | |
2cec12e5 | 2914 | bp_temp = bs->breakpoint_at->owner->disposition == disp_del; |
0d381245 VP |
2915 | if (bl->address != bl->requested_address) |
2916 | breakpoint_adjustment_warning (bl->requested_address, | |
2917 | bl->address, | |
4f8d1dc6 VP |
2918 | b->number, 1); |
2919 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
2920 | if (bp_temp) |
2921 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
2922 | else | |
2923 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 2924 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
2925 | { |
2926 | ui_out_field_string (uiout, "reason", | |
2927 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
2928 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
2929 | } | |
4f8d1dc6 | 2930 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 2931 | ui_out_text (uiout, ", "); |
f7545552 | 2932 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
2933 | break; |
2934 | ||
2935 | case bp_shlib_event: | |
917317f4 JM |
2936 | /* Did we stop because the user set the stop_on_solib_events |
2937 | variable? (If so, we report this as a generic, "Stopped due | |
2938 | to shlib event" message.) */ | |
a3f17187 | 2939 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 2940 | result = PRINT_NOTHING; |
e514a9d6 JM |
2941 | break; |
2942 | ||
c4093a6a JM |
2943 | case bp_thread_event: |
2944 | /* Not sure how we will get here. | |
2945 | GDB should not stop for these breakpoints. */ | |
a3f17187 | 2946 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2947 | result = PRINT_NOTHING; |
c4093a6a JM |
2948 | break; |
2949 | ||
1900040c MS |
2950 | case bp_overlay_event: |
2951 | /* By analogy with the thread event, GDB should not stop for these. */ | |
a3f17187 | 2952 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 2953 | result = PRINT_NOTHING; |
1900040c MS |
2954 | break; |
2955 | ||
0fd8e87f UW |
2956 | case bp_longjmp_master: |
2957 | /* These should never be enabled. */ | |
2958 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
2959 | result = PRINT_NOTHING; | |
2960 | break; | |
2961 | ||
e514a9d6 JM |
2962 | case bp_watchpoint: |
2963 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
2964 | annotate_watchpoint (b->number); |
2965 | if (ui_out_is_mi_like_p (uiout)) | |
2966 | ui_out_field_string | |
2967 | (uiout, "reason", | |
2968 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
2969 | mention (b); | |
f7545552 | 2970 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
2971 | ui_out_text (uiout, "\nOld value = "); |
2972 | watchpoint_value_print (bs->old_val, stb->stream); | |
2973 | ui_out_field_stream (uiout, "old", stb); | |
2974 | ui_out_text (uiout, "\nNew value = "); | |
2975 | watchpoint_value_print (b->val, stb->stream); | |
2976 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 2977 | ui_out_text (uiout, "\n"); |
e514a9d6 | 2978 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 2979 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2980 | break; |
2981 | ||
2982 | case bp_read_watchpoint: | |
9dc5e2a9 | 2983 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
2984 | ui_out_field_string |
2985 | (uiout, "reason", | |
2986 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 2987 | mention (b); |
f7545552 | 2988 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 2989 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 2990 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 2991 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 2992 | ui_out_text (uiout, "\n"); |
f7545552 | 2993 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
2994 | break; |
2995 | ||
2996 | case bp_access_watchpoint: | |
fa4727a6 | 2997 | if (bs->old_val != NULL) |
8b93c638 | 2998 | { |
4f8d1dc6 | 2999 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3000 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3001 | ui_out_field_string |
3002 | (uiout, "reason", | |
3003 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3004 | mention (b); |
f7545552 | 3005 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3006 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3007 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3008 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3009 | ui_out_text (uiout, "\nNew value = "); |
3010 | } | |
3011 | else | |
3012 | { | |
4f8d1dc6 | 3013 | mention (b); |
9dc5e2a9 | 3014 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3015 | ui_out_field_string |
3016 | (uiout, "reason", | |
3017 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3018 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3019 | ui_out_text (uiout, "\nValue = "); |
3020 | } | |
fa4727a6 | 3021 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3022 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3023 | ui_out_text (uiout, "\n"); |
f7545552 | 3024 | result = PRINT_UNKNOWN; |
e514a9d6 | 3025 | break; |
4ce44c66 | 3026 | |
e514a9d6 JM |
3027 | /* Fall through, we don't deal with these types of breakpoints |
3028 | here. */ | |
3029 | ||
11cf8741 | 3030 | case bp_finish: |
9dc5e2a9 | 3031 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3032 | ui_out_field_string |
3033 | (uiout, "reason", | |
3034 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3035 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3036 | break; |
3037 | ||
e514a9d6 | 3038 | case bp_until: |
9dc5e2a9 | 3039 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3040 | ui_out_field_string |
3041 | (uiout, "reason", | |
3042 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3043 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3044 | break; |
3045 | ||
c2d11a7d | 3046 | case bp_none: |
e514a9d6 JM |
3047 | case bp_longjmp: |
3048 | case bp_longjmp_resume: | |
3049 | case bp_step_resume: | |
e514a9d6 JM |
3050 | case bp_watchpoint_scope: |
3051 | case bp_call_dummy: | |
1042e4c0 | 3052 | case bp_tracepoint: |
7a697b8d | 3053 | case bp_fast_tracepoint: |
4efc6507 | 3054 | case bp_jit_event: |
e514a9d6 | 3055 | default: |
f7545552 TT |
3056 | result = PRINT_UNKNOWN; |
3057 | break; | |
e514a9d6 | 3058 | } |
f7545552 TT |
3059 | |
3060 | do_cleanups (old_chain); | |
3061 | return result; | |
e514a9d6 JM |
3062 | } |
3063 | ||
3064 | /* Generic routine for printing messages indicating why we | |
3065 | stopped. The behavior of this function depends on the value | |
3066 | 'print_it' in the bpstat structure. Under some circumstances we | |
3067 | may decide not to print anything here and delegate the task to | |
3068 | normal_stop(). */ | |
3069 | ||
3070 | static enum print_stop_action | |
3071 | print_bp_stop_message (bpstat bs) | |
3072 | { | |
3073 | switch (bs->print_it) | |
3074 | { | |
3075 | case print_it_noop: | |
3076 | /* Nothing should be printed for this bpstat entry. */ | |
3077 | return PRINT_UNKNOWN; | |
3078 | break; | |
3079 | ||
3080 | case print_it_done: | |
3081 | /* We still want to print the frame, but we already printed the | |
3082 | relevant messages. */ | |
3083 | return PRINT_SRC_AND_LOC; | |
3084 | break; | |
3085 | ||
3086 | case print_it_normal: | |
4f8d1dc6 | 3087 | { |
89f9893c | 3088 | const struct bp_location *bl = bs->breakpoint_at; |
4f8d1dc6 VP |
3089 | struct breakpoint *b = bl ? bl->owner : NULL; |
3090 | ||
3091 | /* Normal case. Call the breakpoint's print_it method, or | |
3092 | print_it_typical. */ | |
3093 | /* FIXME: how breakpoint can ever be NULL here? */ | |
3094 | if (b != NULL && b->ops != NULL && b->ops->print_it != NULL) | |
3095 | return b->ops->print_it (b); | |
3096 | else | |
3097 | return print_it_typical (bs); | |
3098 | } | |
3099 | break; | |
3086aeae | 3100 | |
e514a9d6 | 3101 | default: |
8e65ff28 | 3102 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3103 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3104 | break; |
c906108c | 3105 | } |
c906108c SS |
3106 | } |
3107 | ||
e514a9d6 JM |
3108 | /* Print a message indicating what happened. This is called from |
3109 | normal_stop(). The input to this routine is the head of the bpstat | |
3110 | list - a list of the eventpoints that caused this stop. This | |
3111 | routine calls the generic print routine for printing a message | |
3112 | about reasons for stopping. This will print (for example) the | |
3113 | "Breakpoint n," part of the output. The return value of this | |
3114 | routine is one of: | |
c906108c | 3115 | |
917317f4 JM |
3116 | PRINT_UNKNOWN: Means we printed nothing |
3117 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent | |
c5aa993b JM |
3118 | code to print the location. An example is |
3119 | "Breakpoint 1, " which should be followed by | |
3120 | the location. | |
917317f4 | 3121 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3122 | to also print the location part of the message. |
3123 | An example is the catch/throw messages, which | |
917317f4 JM |
3124 | don't require a location appended to the end. |
3125 | PRINT_NOTHING: We have done some printing and we don't need any | |
3126 | further info to be printed.*/ | |
c906108c | 3127 | |
917317f4 | 3128 | enum print_stop_action |
fba45db2 | 3129 | bpstat_print (bpstat bs) |
c906108c SS |
3130 | { |
3131 | int val; | |
c5aa993b | 3132 | |
c906108c | 3133 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3134 | (Currently all watchpoints go on the bpstat whether hit or not. |
3135 | That probably could (should) be changed, provided care is taken | |
c906108c | 3136 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3137 | for (; bs; bs = bs->next) |
3138 | { | |
3139 | val = print_bp_stop_message (bs); | |
3140 | if (val == PRINT_SRC_ONLY | |
3141 | || val == PRINT_SRC_AND_LOC | |
3142 | || val == PRINT_NOTHING) | |
3143 | return val; | |
3144 | } | |
c906108c | 3145 | |
e514a9d6 JM |
3146 | /* We reached the end of the chain, or we got a null BS to start |
3147 | with and nothing was printed. */ | |
917317f4 | 3148 | return PRINT_UNKNOWN; |
c906108c SS |
3149 | } |
3150 | ||
3151 | /* Evaluate the expression EXP and return 1 if value is zero. | |
3152 | This is used inside a catch_errors to evaluate the breakpoint condition. | |
3153 | The argument is a "struct expression *" that has been cast to char * to | |
3154 | make it pass through catch_errors. */ | |
3155 | ||
3156 | static int | |
4efb68b1 | 3157 | breakpoint_cond_eval (void *exp) |
c906108c | 3158 | { |
278cd55f | 3159 | struct value *mark = value_mark (); |
c5aa993b | 3160 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
c906108c SS |
3161 | value_free_to_mark (mark); |
3162 | return i; | |
3163 | } | |
3164 | ||
3165 | /* Allocate a new bpstat and chain it to the current one. */ | |
3166 | ||
3167 | static bpstat | |
89f9893c | 3168 | bpstat_alloc (const struct bp_location *bl, bpstat cbs /* Current "bs" value */ ) |
c906108c SS |
3169 | { |
3170 | bpstat bs; | |
3171 | ||
3172 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
3173 | cbs->next = bs; | |
4f8d1dc6 | 3174 | bs->breakpoint_at = bl; |
c906108c SS |
3175 | /* If the condition is false, etc., don't do the commands. */ |
3176 | bs->commands = NULL; | |
3177 | bs->old_val = NULL; | |
3178 | bs->print_it = print_it_normal; | |
3179 | return bs; | |
3180 | } | |
3181 | \f | |
d983da9c DJ |
3182 | /* The target has stopped with waitstatus WS. Check if any hardware |
3183 | watchpoints have triggered, according to the target. */ | |
3184 | ||
3185 | int | |
3186 | watchpoints_triggered (struct target_waitstatus *ws) | |
3187 | { | |
d92524f1 | 3188 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3189 | CORE_ADDR addr; |
3190 | struct breakpoint *b; | |
3191 | ||
3192 | if (!stopped_by_watchpoint) | |
3193 | { | |
3194 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3195 | as not triggered. */ | |
3196 | ALL_BREAKPOINTS (b) | |
3197 | if (b->type == bp_hardware_watchpoint | |
3198 | || b->type == bp_read_watchpoint | |
3199 | || b->type == bp_access_watchpoint) | |
3200 | b->watchpoint_triggered = watch_triggered_no; | |
3201 | ||
3202 | return 0; | |
3203 | } | |
3204 | ||
3205 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3206 | { | |
3207 | /* We were stopped by a watchpoint, but we don't know where. | |
3208 | Mark all watchpoints as unknown. */ | |
3209 | ALL_BREAKPOINTS (b) | |
3210 | if (b->type == bp_hardware_watchpoint | |
3211 | || b->type == bp_read_watchpoint | |
3212 | || b->type == bp_access_watchpoint) | |
3213 | b->watchpoint_triggered = watch_triggered_unknown; | |
3214 | ||
3215 | return stopped_by_watchpoint; | |
3216 | } | |
3217 | ||
3218 | /* The target could report the data address. Mark watchpoints | |
3219 | affected by this data address as triggered, and all others as not | |
3220 | triggered. */ | |
3221 | ||
3222 | ALL_BREAKPOINTS (b) | |
3223 | if (b->type == bp_hardware_watchpoint | |
3224 | || b->type == bp_read_watchpoint | |
3225 | || b->type == bp_access_watchpoint) | |
3226 | { | |
a5606eee | 3227 | struct bp_location *loc; |
d983da9c DJ |
3228 | struct value *v; |
3229 | ||
3230 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee VP |
3231 | for (loc = b->loc; loc; loc = loc->next) |
3232 | /* Exact match not required. Within range is | |
3233 | sufficient. */ | |
5009afc5 AS |
3234 | if (target_watchpoint_addr_within_range (¤t_target, |
3235 | addr, loc->address, | |
3236 | loc->length)) | |
a5606eee VP |
3237 | { |
3238 | b->watchpoint_triggered = watch_triggered_yes; | |
3239 | break; | |
3240 | } | |
d983da9c DJ |
3241 | } |
3242 | ||
3243 | return 1; | |
3244 | } | |
3245 | ||
c906108c SS |
3246 | /* Possible return values for watchpoint_check (this can't be an enum |
3247 | because of check_errors). */ | |
3248 | /* The watchpoint has been deleted. */ | |
3249 | #define WP_DELETED 1 | |
3250 | /* The value has changed. */ | |
3251 | #define WP_VALUE_CHANGED 2 | |
3252 | /* The value has not changed. */ | |
3253 | #define WP_VALUE_NOT_CHANGED 3 | |
3254 | ||
3255 | #define BP_TEMPFLAG 1 | |
3256 | #define BP_HARDWAREFLAG 2 | |
3257 | ||
553e4c11 JB |
3258 | /* Evaluate watchpoint condition expression and check if its value changed. |
3259 | ||
3260 | P should be a pointer to struct bpstat, but is defined as a void * | |
3261 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3262 | |
3263 | static int | |
4efb68b1 | 3264 | watchpoint_check (void *p) |
c906108c SS |
3265 | { |
3266 | bpstat bs = (bpstat) p; | |
3267 | struct breakpoint *b; | |
3268 | struct frame_info *fr; | |
3269 | int within_current_scope; | |
3270 | ||
4f8d1dc6 | 3271 | b = bs->breakpoint_at->owner; |
c906108c | 3272 | |
f6bc2008 PA |
3273 | /* If this is a local watchpoint, we only want to check if the |
3274 | watchpoint frame is in scope if the current thread is the thread | |
3275 | that was used to create the watchpoint. */ | |
3276 | if (!watchpoint_in_thread_scope (b)) | |
3277 | return WP_VALUE_NOT_CHANGED; | |
3278 | ||
c906108c SS |
3279 | if (b->exp_valid_block == NULL) |
3280 | within_current_scope = 1; | |
3281 | else | |
3282 | { | |
edb3359d DJ |
3283 | struct frame_info *frame = get_current_frame (); |
3284 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3285 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3286 | ||
a0f49112 JK |
3287 | /* in_function_epilogue_p() returns a non-zero value if we're still |
3288 | in the function but the stack frame has already been invalidated. | |
3289 | Since we can't rely on the values of local variables after the | |
3290 | stack has been destroyed, we are treating the watchpoint in that | |
3291 | state as `not changed' without further checking. Don't mark | |
3292 | watchpoints as changed if the current frame is in an epilogue - | |
3293 | even if they are in some other frame, our view of the stack | |
3294 | is likely to be wrong and frame_find_by_id could error out. */ | |
3295 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
3296 | return WP_VALUE_NOT_CHANGED; | |
3297 | ||
101dcfbe | 3298 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3299 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3300 | |
3301 | /* If we've gotten confused in the unwinder, we might have | |
3302 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3303 | if (within_current_scope) |
3304 | { | |
3305 | struct symbol *function; | |
3306 | ||
3307 | function = get_frame_function (fr); | |
3308 | if (function == NULL | |
3309 | || !contained_in (b->exp_valid_block, | |
3310 | SYMBOL_BLOCK_VALUE (function))) | |
3311 | within_current_scope = 0; | |
3312 | } | |
69fbadd5 | 3313 | |
edb3359d | 3314 | if (within_current_scope) |
c906108c SS |
3315 | /* If we end up stopping, the current frame will get selected |
3316 | in normal_stop. So this call to select_frame won't affect | |
3317 | the user. */ | |
0f7d239c | 3318 | select_frame (fr); |
c906108c | 3319 | } |
c5aa993b | 3320 | |
c906108c SS |
3321 | if (within_current_scope) |
3322 | { | |
3323 | /* We use value_{,free_to_}mark because it could be a | |
3324 | *long* time before we return to the command level and | |
c5aa993b JM |
3325 | call free_all_values. We can't call free_all_values because |
3326 | we might be in the middle of evaluating a function call. */ | |
c906108c | 3327 | |
278cd55f | 3328 | struct value *mark = value_mark (); |
fa4727a6 DJ |
3329 | struct value *new_val; |
3330 | ||
3331 | fetch_watchpoint_value (b->exp, &new_val, NULL, NULL); | |
218d2fc6 TJB |
3332 | |
3333 | /* We use value_equal_contents instead of value_equal because the latter | |
3334 | coerces an array to a pointer, thus comparing just the address of the | |
3335 | array instead of its contents. This is not what we want. */ | |
fa4727a6 | 3336 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3337 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3338 | { |
fa4727a6 DJ |
3339 | if (new_val != NULL) |
3340 | { | |
3341 | release_value (new_val); | |
3342 | value_free_to_mark (mark); | |
3343 | } | |
c906108c SS |
3344 | bs->old_val = b->val; |
3345 | b->val = new_val; | |
fa4727a6 | 3346 | b->val_valid = 1; |
c906108c SS |
3347 | /* We will stop here */ |
3348 | return WP_VALUE_CHANGED; | |
3349 | } | |
3350 | else | |
3351 | { | |
3352 | /* Nothing changed, don't do anything. */ | |
3353 | value_free_to_mark (mark); | |
3354 | /* We won't stop here */ | |
3355 | return WP_VALUE_NOT_CHANGED; | |
3356 | } | |
3357 | } | |
3358 | else | |
3359 | { | |
3360 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3361 | if we temporarily ignored the watchpoint, then when |
3362 | we reenter the block in which it is valid it contains | |
3363 | garbage (in the case of a function, it may have two | |
3364 | garbage values, one before and one after the prologue). | |
3365 | So we can't even detect the first assignment to it and | |
3366 | watch after that (since the garbage may or may not equal | |
3367 | the first value assigned). */ | |
4ce44c66 JM |
3368 | /* We print all the stop information in print_it_typical(), but |
3369 | in this case, by the time we call print_it_typical() this bp | |
3370 | will be deleted already. So we have no choice but print the | |
3371 | information here. */ | |
9dc5e2a9 | 3372 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3373 | ui_out_field_string |
3374 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3375 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3376 | ui_out_field_int (uiout, "wpnum", b->number); |
8b93c638 JM |
3377 | ui_out_text (uiout, " deleted because the program has left the block in\n\ |
3378 | which its expression is valid.\n"); | |
4ce44c66 | 3379 | |
c906108c | 3380 | if (b->related_breakpoint) |
b5de0fa7 EZ |
3381 | b->related_breakpoint->disposition = disp_del_at_next_stop; |
3382 | b->disposition = disp_del_at_next_stop; | |
c906108c SS |
3383 | |
3384 | return WP_DELETED; | |
3385 | } | |
3386 | } | |
3387 | ||
18a18393 VP |
3388 | /* Return true if it looks like target has stopped due to hitting |
3389 | breakpoint location BL. This function does not check if we | |
3390 | should stop, only if BL explains the stop. */ | |
3391 | static int | |
6c95b8df PA |
3392 | bpstat_check_location (const struct bp_location *bl, |
3393 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3394 | { |
3395 | struct breakpoint *b = bl->owner; | |
3396 | ||
e8595ef6 SS |
3397 | /* By definition, the inferior does not report stops at |
3398 | tracepoints. */ | |
7a697b8d | 3399 | if (tracepoint_type (b)) |
e8595ef6 SS |
3400 | return 0; |
3401 | ||
18a18393 VP |
3402 | if (b->type != bp_watchpoint |
3403 | && b->type != bp_hardware_watchpoint | |
3404 | && b->type != bp_read_watchpoint | |
3405 | && b->type != bp_access_watchpoint | |
3406 | && b->type != bp_hardware_breakpoint | |
fe798b75 | 3407 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3408 | { |
6c95b8df PA |
3409 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3410 | aspace, bp_addr)) | |
18a18393 VP |
3411 | return 0; |
3412 | if (overlay_debugging /* unmapped overlay section */ | |
3413 | && section_is_overlay (bl->section) | |
3414 | && !section_is_mapped (bl->section)) | |
3415 | return 0; | |
3416 | } | |
3417 | ||
3418 | /* Continuable hardware watchpoints are treated as non-existent if the | |
3419 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3420 | some data address). Otherwise gdb won't stop on a break instruction | |
3421 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3422 | been defined. Also skip watchpoints which we know did not trigger | |
3423 | (did not match the data address). */ | |
3424 | ||
3425 | if ((b->type == bp_hardware_watchpoint | |
3426 | || b->type == bp_read_watchpoint | |
3427 | || b->type == bp_access_watchpoint) | |
3428 | && b->watchpoint_triggered == watch_triggered_no) | |
3429 | return 0; | |
3430 | ||
3431 | if (b->type == bp_hardware_breakpoint) | |
3432 | { | |
3433 | if (bl->address != bp_addr) | |
3434 | return 0; | |
3435 | if (overlay_debugging /* unmapped overlay section */ | |
3436 | && section_is_overlay (bl->section) | |
3437 | && !section_is_mapped (bl->section)) | |
3438 | return 0; | |
3439 | } | |
ce78b96d | 3440 | |
ce78b96d JB |
3441 | if (b->type == bp_catchpoint) |
3442 | { | |
3443 | gdb_assert (b->ops != NULL && b->ops->breakpoint_hit != NULL); | |
3444 | if (!b->ops->breakpoint_hit (b)) | |
3445 | return 0; | |
3446 | } | |
3447 | ||
18a18393 VP |
3448 | return 1; |
3449 | } | |
3450 | ||
3451 | /* If BS refers to a watchpoint, determine if the watched values | |
3452 | has actually changed, and we should stop. If not, set BS->stop | |
3453 | to 0. */ | |
3454 | static void | |
3455 | bpstat_check_watchpoint (bpstat bs) | |
3456 | { | |
3457 | const struct bp_location *bl = bs->breakpoint_at; | |
3458 | struct breakpoint *b = bl->owner; | |
3459 | ||
3460 | if (b->type == bp_watchpoint | |
3461 | || b->type == bp_read_watchpoint | |
3462 | || b->type == bp_access_watchpoint | |
3463 | || b->type == bp_hardware_watchpoint) | |
3464 | { | |
3465 | CORE_ADDR addr; | |
3466 | struct value *v; | |
3467 | int must_check_value = 0; | |
3468 | ||
3469 | if (b->type == bp_watchpoint) | |
3470 | /* For a software watchpoint, we must always check the | |
3471 | watched value. */ | |
3472 | must_check_value = 1; | |
3473 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3474 | /* We have a hardware watchpoint (read, write, or access) | |
3475 | and the target earlier reported an address watched by | |
3476 | this watchpoint. */ | |
3477 | must_check_value = 1; | |
3478 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3479 | && b->type == bp_hardware_watchpoint) | |
3480 | /* We were stopped by a hardware watchpoint, but the target could | |
3481 | not report the data address. We must check the watchpoint's | |
3482 | value. Access and read watchpoints are out of luck; without | |
3483 | a data address, we can't figure it out. */ | |
3484 | must_check_value = 1; | |
3485 | ||
3486 | if (must_check_value) | |
3487 | { | |
3488 | char *message = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3489 | b->number); | |
3490 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
3491 | int e = catch_errors (watchpoint_check, bs, message, | |
3492 | RETURN_MASK_ALL); | |
3493 | do_cleanups (cleanups); | |
3494 | switch (e) | |
3495 | { | |
3496 | case WP_DELETED: | |
3497 | /* We've already printed what needs to be printed. */ | |
3498 | bs->print_it = print_it_done; | |
3499 | /* Stop. */ | |
3500 | break; | |
3501 | case WP_VALUE_CHANGED: | |
3502 | if (b->type == bp_read_watchpoint) | |
3503 | { | |
85d721b8 PA |
3504 | /* There are two cases to consider here: |
3505 | ||
3506 | 1. we're watching the triggered memory for reads. | |
3507 | In that case, trust the target, and always report | |
3508 | the watchpoint hit to the user. Even though | |
3509 | reads don't cause value changes, the value may | |
3510 | have changed since the last time it was read, and | |
3511 | since we're not trapping writes, we will not see | |
3512 | those, and as such we should ignore our notion of | |
3513 | old value. | |
3514 | ||
3515 | 2. we're watching the triggered memory for both | |
3516 | reads and writes. There are two ways this may | |
3517 | happen: | |
3518 | ||
3519 | 2.1. this is a target that can't break on data | |
3520 | reads only, but can break on accesses (reads or | |
3521 | writes), such as e.g., x86. We detect this case | |
3522 | at the time we try to insert read watchpoints. | |
3523 | ||
3524 | 2.2. otherwise, the target supports read | |
3525 | watchpoints, but, the user set an access or write | |
3526 | watchpoint watching the same memory as this read | |
3527 | watchpoint. | |
3528 | ||
3529 | If we're watching memory writes as well as reads, | |
3530 | ignore watchpoint hits when we find that the | |
3531 | value hasn't changed, as reads don't cause | |
3532 | changes. This still gives false positives when | |
3533 | the program writes the same value to memory as | |
3534 | what there was already in memory (we will confuse | |
3535 | it for a read), but it's much better than | |
3536 | nothing. */ | |
3537 | ||
3538 | int other_write_watchpoint = 0; | |
3539 | ||
3540 | if (bl->watchpoint_type == hw_read) | |
3541 | { | |
3542 | struct breakpoint *other_b; | |
3543 | ||
3544 | ALL_BREAKPOINTS (other_b) | |
3545 | if ((other_b->type == bp_hardware_watchpoint | |
3546 | || other_b->type == bp_access_watchpoint) | |
3547 | && (other_b->watchpoint_triggered | |
3548 | == watch_triggered_yes)) | |
3549 | { | |
3550 | other_write_watchpoint = 1; | |
3551 | break; | |
3552 | } | |
3553 | } | |
3554 | ||
3555 | if (other_write_watchpoint | |
3556 | || bl->watchpoint_type == hw_access) | |
3557 | { | |
3558 | /* We're watching the same memory for writes, | |
3559 | and the value changed since the last time we | |
3560 | updated it, so this trap must be for a write. | |
3561 | Ignore it. */ | |
3562 | bs->print_it = print_it_noop; | |
3563 | bs->stop = 0; | |
3564 | } | |
18a18393 VP |
3565 | } |
3566 | break; | |
3567 | case WP_VALUE_NOT_CHANGED: | |
3568 | if (b->type == bp_hardware_watchpoint | |
3569 | || b->type == bp_watchpoint) | |
3570 | { | |
3571 | /* Don't stop: write watchpoints shouldn't fire if | |
3572 | the value hasn't changed. */ | |
3573 | bs->print_it = print_it_noop; | |
3574 | bs->stop = 0; | |
3575 | } | |
3576 | /* Stop. */ | |
3577 | break; | |
3578 | default: | |
3579 | /* Can't happen. */ | |
3580 | case 0: | |
3581 | /* Error from catch_errors. */ | |
3582 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
3583 | if (b->related_breakpoint) | |
3584 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
3585 | b->disposition = disp_del_at_next_stop; | |
3586 | /* We've already printed what needs to be printed. */ | |
3587 | bs->print_it = print_it_done; | |
3588 | break; | |
3589 | } | |
3590 | } | |
3591 | else /* must_check_value == 0 */ | |
3592 | { | |
3593 | /* This is a case where some watchpoint(s) triggered, but | |
3594 | not at the address of this watchpoint, or else no | |
3595 | watchpoint triggered after all. So don't print | |
3596 | anything for this watchpoint. */ | |
3597 | bs->print_it = print_it_noop; | |
3598 | bs->stop = 0; | |
3599 | } | |
3600 | } | |
3601 | } | |
3602 | ||
3603 | ||
3604 | /* Check conditions (condition proper, frame, thread and ignore count) | |
3605 | of breakpoint referred to by BS. If we should not stop for this | |
3606 | breakpoint, set BS->stop to 0. */ | |
3607 | static void | |
3608 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
3609 | { | |
3610 | int thread_id = pid_to_thread_id (ptid); | |
3611 | const struct bp_location *bl = bs->breakpoint_at; | |
3612 | struct breakpoint *b = bl->owner; | |
3613 | ||
3614 | if (frame_id_p (b->frame_id) | |
edb3359d | 3615 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
3616 | bs->stop = 0; |
3617 | else if (bs->stop) | |
3618 | { | |
3619 | int value_is_zero = 0; | |
3620 | ||
3621 | /* If this is a scope breakpoint, mark the associated | |
3622 | watchpoint as triggered so that we will handle the | |
3623 | out-of-scope event. We'll get to the watchpoint next | |
3624 | iteration. */ | |
3625 | if (b->type == bp_watchpoint_scope) | |
3626 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; | |
3627 | ||
3628 | if (bl->cond && bl->owner->disposition != disp_del_at_next_stop) | |
3629 | { | |
c5bc3a77 DJ |
3630 | /* We use value_mark and value_free_to_mark because it could |
3631 | be a long time before we return to the command level and | |
3632 | call free_all_values. We can't call free_all_values | |
3633 | because we might be in the middle of evaluating a | |
3634 | function call. */ | |
3635 | struct value *mark = value_mark (); | |
3636 | ||
edb3359d DJ |
3637 | /* Need to select the frame, with all that implies so that |
3638 | the conditions will have the right context. Because we | |
3639 | use the frame, we will not see an inlined function's | |
3640 | variables when we arrive at a breakpoint at the start | |
3641 | of the inlined function; the current frame will be the | |
3642 | call site. */ | |
18a18393 VP |
3643 | select_frame (get_current_frame ()); |
3644 | value_is_zero | |
3645 | = catch_errors (breakpoint_cond_eval, (bl->cond), | |
3646 | "Error in testing breakpoint condition:\n", | |
3647 | RETURN_MASK_ALL); | |
3648 | /* FIXME-someday, should give breakpoint # */ | |
c5bc3a77 | 3649 | value_free_to_mark (mark); |
18a18393 VP |
3650 | } |
3651 | if (bl->cond && value_is_zero) | |
3652 | { | |
3653 | bs->stop = 0; | |
3654 | } | |
3655 | else if (b->thread != -1 && b->thread != thread_id) | |
3656 | { | |
3657 | bs->stop = 0; | |
3658 | } | |
3659 | else if (b->ignore_count > 0) | |
3660 | { | |
3661 | b->ignore_count--; | |
3662 | annotate_ignore_count_change (); | |
3663 | bs->stop = 0; | |
3664 | /* Increase the hit count even though we don't | |
3665 | stop. */ | |
3666 | ++(b->hit_count); | |
3667 | } | |
3668 | } | |
3669 | } | |
3670 | ||
3671 | ||
9709f61c | 3672 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 3673 | BP_ADDR in thread PTID. |
c906108c | 3674 | |
d983da9c | 3675 | Determine whether we stopped at a breakpoint, etc, or whether we |
c906108c SS |
3676 | don't understand this stop. Result is a chain of bpstat's such that: |
3677 | ||
c5aa993b | 3678 | if we don't understand the stop, the result is a null pointer. |
c906108c | 3679 | |
c5aa993b | 3680 | if we understand why we stopped, the result is not null. |
c906108c | 3681 | |
c5aa993b JM |
3682 | Each element of the chain refers to a particular breakpoint or |
3683 | watchpoint at which we have stopped. (We may have stopped for | |
3684 | several reasons concurrently.) | |
c906108c | 3685 | |
c5aa993b JM |
3686 | Each element of the chain has valid next, breakpoint_at, |
3687 | commands, FIXME??? fields. */ | |
c906108c SS |
3688 | |
3689 | bpstat | |
6c95b8df PA |
3690 | bpstat_stop_status (struct address_space *aspace, |
3691 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 3692 | { |
0d381245 | 3693 | struct breakpoint *b = NULL; |
876fa593 | 3694 | struct bp_location *bl, **blp_tmp; |
20874c92 | 3695 | struct bp_location *loc; |
c906108c SS |
3696 | /* Root of the chain of bpstat's */ |
3697 | struct bpstats root_bs[1]; | |
3698 | /* Pointer to the last thing in the chain currently. */ | |
3699 | bpstat bs = root_bs; | |
20874c92 | 3700 | int ix; |
429374b8 | 3701 | int need_remove_insert; |
c906108c | 3702 | |
429374b8 JK |
3703 | /* ALL_BP_LOCATIONS iteration would break across |
3704 | update_global_location_list possibly executed by | |
3705 | bpstat_check_breakpoint_conditions's inferior call. */ | |
c5aa993b | 3706 | |
429374b8 JK |
3707 | ALL_BREAKPOINTS (b) |
3708 | { | |
3709 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
3710 | continue; | |
a5606eee | 3711 | |
429374b8 JK |
3712 | for (bl = b->loc; bl != NULL; bl = bl->next) |
3713 | { | |
3714 | /* For hardware watchpoints, we look only at the first location. | |
3715 | The watchpoint_check function will work on entire expression, | |
3716 | not the individual locations. For read watchopints, the | |
3717 | watchpoints_triggered function have checked all locations | |
3718 | already. */ | |
3719 | if (b->type == bp_hardware_watchpoint && bl != b->loc) | |
3720 | break; | |
18a18393 | 3721 | |
429374b8 JK |
3722 | if (bl->shlib_disabled) |
3723 | continue; | |
c5aa993b | 3724 | |
429374b8 JK |
3725 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
3726 | continue; | |
c5aa993b | 3727 | |
429374b8 | 3728 | /* Come here if it's a watchpoint, or if the break address matches */ |
c5aa993b | 3729 | |
429374b8 | 3730 | bs = bpstat_alloc (bl, bs); /* Alloc a bpstat to explain stop */ |
c5aa993b | 3731 | |
429374b8 JK |
3732 | /* Assume we stop. Should we find watchpoint that is not actually |
3733 | triggered, or if condition of breakpoint is false, we'll reset | |
3734 | 'stop' to 0. */ | |
3735 | bs->stop = 1; | |
3736 | bs->print = 1; | |
d983da9c | 3737 | |
429374b8 JK |
3738 | bpstat_check_watchpoint (bs); |
3739 | if (!bs->stop) | |
3740 | continue; | |
18a18393 | 3741 | |
429374b8 JK |
3742 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
3743 | || b->type == bp_longjmp_master) | |
3744 | /* We do not stop for these. */ | |
3745 | bs->stop = 0; | |
3746 | else | |
3747 | bpstat_check_breakpoint_conditions (bs, ptid); | |
3748 | ||
3749 | if (bs->stop) | |
3750 | { | |
3751 | ++(b->hit_count); | |
c906108c | 3752 | |
429374b8 JK |
3753 | /* We will stop here */ |
3754 | if (b->disposition == disp_disable) | |
3755 | { | |
3756 | if (b->enable_state != bp_permanent) | |
3757 | b->enable_state = bp_disabled; | |
3758 | update_global_location_list (0); | |
3759 | } | |
3760 | if (b->silent) | |
3761 | bs->print = 0; | |
3762 | bs->commands = b->commands; | |
3763 | if (bs->commands | |
3764 | && (strcmp ("silent", bs->commands->line) == 0 | |
3765 | || (xdb_commands && strcmp ("Q", | |
3766 | bs->commands->line) == 0))) | |
3767 | { | |
3768 | bs->commands = bs->commands->next; | |
3769 | bs->print = 0; | |
3770 | } | |
3771 | bs->commands = copy_command_lines (bs->commands); | |
3772 | } | |
3773 | ||
3774 | /* Print nothing for this entry if we dont stop or dont print. */ | |
3775 | if (bs->stop == 0 || bs->print == 0) | |
3776 | bs->print_it = print_it_noop; | |
3777 | } | |
3778 | } | |
876fa593 | 3779 | |
20874c92 VP |
3780 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) |
3781 | { | |
6c95b8df PA |
3782 | if (breakpoint_address_match (loc->pspace->aspace, loc->address, |
3783 | aspace, bp_addr)) | |
20874c92 VP |
3784 | { |
3785 | bs = bpstat_alloc (loc, bs); | |
3786 | /* For hits of moribund locations, we should just proceed. */ | |
3787 | bs->stop = 0; | |
3788 | bs->print = 0; | |
3789 | bs->print_it = print_it_noop; | |
3790 | } | |
3791 | } | |
3792 | ||
c906108c | 3793 | bs->next = NULL; /* Terminate the chain */ |
c906108c | 3794 | |
d983da9c DJ |
3795 | /* If we aren't stopping, the value of some hardware watchpoint may |
3796 | not have changed, but the intermediate memory locations we are | |
3797 | watching may have. Don't bother if we're stopping; this will get | |
3798 | done later. */ | |
3799 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3800 | if (bs->stop) | |
3801 | break; | |
3802 | ||
d832cb68 | 3803 | need_remove_insert = 0; |
d983da9c DJ |
3804 | if (bs == NULL) |
3805 | for (bs = root_bs->next; bs != NULL; bs = bs->next) | |
3806 | if (!bs->stop | |
20874c92 | 3807 | && bs->breakpoint_at->owner |
2d134ed3 | 3808 | && is_hardware_watchpoint (bs->breakpoint_at->owner)) |
d983da9c | 3809 | { |
2d134ed3 PA |
3810 | update_watchpoint (bs->breakpoint_at->owner, 0 /* don't reparse. */); |
3811 | /* Updating watchpoints invalidates bs->breakpoint_at. | |
3812 | Prevent further code from trying to use it. */ | |
a5606eee | 3813 | bs->breakpoint_at = NULL; |
d832cb68 | 3814 | need_remove_insert = 1; |
d983da9c DJ |
3815 | } |
3816 | ||
d832cb68 | 3817 | if (need_remove_insert) |
2d134ed3 | 3818 | update_global_location_list (1); |
d832cb68 | 3819 | |
d983da9c | 3820 | return root_bs->next; |
c906108c SS |
3821 | } |
3822 | \f | |
3823 | /* Tell what to do about this bpstat. */ | |
3824 | struct bpstat_what | |
fba45db2 | 3825 | bpstat_what (bpstat bs) |
c906108c SS |
3826 | { |
3827 | /* Classify each bpstat as one of the following. */ | |
c5aa993b JM |
3828 | enum class |
3829 | { | |
3830 | /* This bpstat element has no effect on the main_action. */ | |
3831 | no_effect = 0, | |
3832 | ||
3833 | /* There was a watchpoint, stop but don't print. */ | |
3834 | wp_silent, | |
c906108c | 3835 | |
c5aa993b JM |
3836 | /* There was a watchpoint, stop and print. */ |
3837 | wp_noisy, | |
c906108c | 3838 | |
c5aa993b JM |
3839 | /* There was a breakpoint but we're not stopping. */ |
3840 | bp_nostop, | |
c906108c | 3841 | |
c5aa993b JM |
3842 | /* There was a breakpoint, stop but don't print. */ |
3843 | bp_silent, | |
c906108c | 3844 | |
c5aa993b JM |
3845 | /* There was a breakpoint, stop and print. */ |
3846 | bp_noisy, | |
c906108c | 3847 | |
c5aa993b JM |
3848 | /* We hit the longjmp breakpoint. */ |
3849 | long_jump, | |
c906108c | 3850 | |
c5aa993b JM |
3851 | /* We hit the longjmp_resume breakpoint. */ |
3852 | long_resume, | |
c906108c | 3853 | |
c5aa993b JM |
3854 | /* We hit the step_resume breakpoint. */ |
3855 | step_resume, | |
c906108c | 3856 | |
c5aa993b JM |
3857 | /* We hit the shared library event breakpoint. */ |
3858 | shlib_event, | |
c906108c | 3859 | |
4efc6507 DE |
3860 | /* We hit the jit event breakpoint. */ |
3861 | jit_event, | |
3862 | ||
c5aa993b JM |
3863 | /* This is just used to count how many enums there are. */ |
3864 | class_last | |
c906108c SS |
3865 | }; |
3866 | ||
3867 | /* Here is the table which drives this routine. So that we can | |
3868 | format it pretty, we define some abbreviations for the | |
3869 | enum bpstat_what codes. */ | |
3870 | #define kc BPSTAT_WHAT_KEEP_CHECKING | |
3871 | #define ss BPSTAT_WHAT_STOP_SILENT | |
3872 | #define sn BPSTAT_WHAT_STOP_NOISY | |
3873 | #define sgl BPSTAT_WHAT_SINGLE | |
3874 | #define slr BPSTAT_WHAT_SET_LONGJMP_RESUME | |
3875 | #define clr BPSTAT_WHAT_CLEAR_LONGJMP_RESUME | |
c906108c | 3876 | #define sr BPSTAT_WHAT_STEP_RESUME |
c906108c | 3877 | #define shl BPSTAT_WHAT_CHECK_SHLIBS |
4efc6507 | 3878 | #define jit BPSTAT_WHAT_CHECK_JIT |
c906108c SS |
3879 | |
3880 | /* "Can't happen." Might want to print an error message. | |
3881 | abort() is not out of the question, but chances are GDB is just | |
3882 | a bit confused, not unusable. */ | |
3883 | #define err BPSTAT_WHAT_STOP_NOISY | |
3884 | ||
3885 | /* Given an old action and a class, come up with a new action. */ | |
3886 | /* One interesting property of this table is that wp_silent is the same | |
3887 | as bp_silent and wp_noisy is the same as bp_noisy. That is because | |
3888 | after stopping, the check for whether to step over a breakpoint | |
3889 | (BPSTAT_WHAT_SINGLE type stuff) is handled in proceed() without | |
53a5351d JM |
3890 | reference to how we stopped. We retain separate wp_silent and |
3891 | bp_silent codes in case we want to change that someday. | |
43ff13b4 JM |
3892 | |
3893 | Another possibly interesting property of this table is that | |
3894 | there's a partial ordering, priority-like, of the actions. Once | |
3895 | you've decided that some action is appropriate, you'll never go | |
3896 | back and decide something of a lower priority is better. The | |
3897 | ordering is: | |
3898 | ||
4efc6507 DE |
3899 | kc < jit clr sgl shl slr sn sr ss |
3900 | sgl < jit shl slr sn sr ss | |
3901 | slr < jit err shl sn sr ss | |
3902 | clr < jit err shl sn sr ss | |
3903 | ss < jit shl sn sr | |
3904 | sn < jit shl sr | |
3905 | jit < shl sr | |
d81191fc | 3906 | shl < sr |
4d5b2cd7 | 3907 | sr < |
c5aa993b | 3908 | |
43ff13b4 JM |
3909 | What I think this means is that we don't need a damned table |
3910 | here. If you just put the rows and columns in the right order, | |
3911 | it'd look awfully regular. We could simply walk the bpstat list | |
3912 | and choose the highest priority action we find, with a little | |
78b6a731 | 3913 | logic to handle the 'err' cases. */ |
c906108c SS |
3914 | |
3915 | /* step_resume entries: a step resume breakpoint overrides another | |
3916 | breakpoint of signal handling (see comment in wait_for_inferior | |
fcf70625 | 3917 | at where we set the step_resume breakpoint). */ |
c906108c SS |
3918 | |
3919 | static const enum bpstat_what_main_action | |
c5aa993b JM |
3920 | table[(int) class_last][(int) BPSTAT_WHAT_LAST] = |
3921 | { | |
3922 | /* old action */ | |
4efc6507 DE |
3923 | /* kc ss sn sgl slr clr sr shl jit */ |
3924 | /* no_effect */ {kc, ss, sn, sgl, slr, clr, sr, shl, jit}, | |
3925 | /* wp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3926 | /* wp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3927 | /* bp_nostop */ {sgl, ss, sn, sgl, slr, slr, sr, shl, jit}, | |
3928 | /* bp_silent */ {ss, ss, sn, ss, ss, ss, sr, shl, jit}, | |
3929 | /* bp_noisy */ {sn, sn, sn, sn, sn, sn, sr, shl, jit}, | |
3930 | /* long_jump */ {slr, ss, sn, slr, slr, err, sr, shl, jit}, | |
3931 | /* long_resume */ {clr, ss, sn, err, err, err, sr, shl, jit}, | |
3932 | /* step_resume */ {sr, sr, sr, sr, sr, sr, sr, sr, sr }, | |
3933 | /* shlib */ {shl, shl, shl, shl, shl, shl, sr, shl, shl}, | |
3934 | /* jit_event */ {jit, jit, jit, jit, jit, jit, sr, jit, jit} | |
c5aa993b | 3935 | }; |
c906108c SS |
3936 | |
3937 | #undef kc | |
3938 | #undef ss | |
3939 | #undef sn | |
3940 | #undef sgl | |
3941 | #undef slr | |
3942 | #undef clr | |
c906108c SS |
3943 | #undef err |
3944 | #undef sr | |
3945 | #undef ts | |
3946 | #undef shl | |
4efc6507 | 3947 | #undef jit |
c906108c SS |
3948 | enum bpstat_what_main_action current_action = BPSTAT_WHAT_KEEP_CHECKING; |
3949 | struct bpstat_what retval; | |
3950 | ||
3951 | retval.call_dummy = 0; | |
3952 | for (; bs != NULL; bs = bs->next) | |
3953 | { | |
3954 | enum class bs_class = no_effect; | |
3955 | if (bs->breakpoint_at == NULL) | |
3956 | /* I suspect this can happen if it was a momentary breakpoint | |
3957 | which has since been deleted. */ | |
3958 | continue; | |
20874c92 VP |
3959 | if (bs->breakpoint_at->owner == NULL) |
3960 | bs_class = bp_nostop; | |
3961 | else | |
4f8d1dc6 | 3962 | switch (bs->breakpoint_at->owner->type) |
c906108c SS |
3963 | { |
3964 | case bp_none: | |
3965 | continue; | |
3966 | ||
3967 | case bp_breakpoint: | |
3968 | case bp_hardware_breakpoint: | |
3969 | case bp_until: | |
3970 | case bp_finish: | |
3971 | if (bs->stop) | |
3972 | { | |
3973 | if (bs->print) | |
3974 | bs_class = bp_noisy; | |
3975 | else | |
3976 | bs_class = bp_silent; | |
3977 | } | |
3978 | else | |
3979 | bs_class = bp_nostop; | |
3980 | break; | |
3981 | case bp_watchpoint: | |
3982 | case bp_hardware_watchpoint: | |
3983 | case bp_read_watchpoint: | |
3984 | case bp_access_watchpoint: | |
3985 | if (bs->stop) | |
3986 | { | |
3987 | if (bs->print) | |
3988 | bs_class = wp_noisy; | |
3989 | else | |
3990 | bs_class = wp_silent; | |
3991 | } | |
3992 | else | |
53a5351d JM |
3993 | /* There was a watchpoint, but we're not stopping. |
3994 | This requires no further action. */ | |
c906108c SS |
3995 | bs_class = no_effect; |
3996 | break; | |
3997 | case bp_longjmp: | |
3998 | bs_class = long_jump; | |
3999 | break; | |
4000 | case bp_longjmp_resume: | |
4001 | bs_class = long_resume; | |
4002 | break; | |
4003 | case bp_step_resume: | |
4004 | if (bs->stop) | |
4005 | { | |
4006 | bs_class = step_resume; | |
4007 | } | |
4008 | else | |
4009 | /* It is for the wrong frame. */ | |
4010 | bs_class = bp_nostop; | |
4011 | break; | |
c906108c SS |
4012 | case bp_watchpoint_scope: |
4013 | bs_class = bp_nostop; | |
4014 | break; | |
c5aa993b JM |
4015 | case bp_shlib_event: |
4016 | bs_class = shlib_event; | |
4017 | break; | |
4efc6507 DE |
4018 | case bp_jit_event: |
4019 | bs_class = jit_event; | |
4020 | break; | |
c4093a6a | 4021 | case bp_thread_event: |
1900040c | 4022 | case bp_overlay_event: |
0fd8e87f | 4023 | case bp_longjmp_master: |
c4093a6a JM |
4024 | bs_class = bp_nostop; |
4025 | break; | |
ce78b96d | 4026 | case bp_catchpoint: |
c5aa993b JM |
4027 | if (bs->stop) |
4028 | { | |
4029 | if (bs->print) | |
4030 | bs_class = bp_noisy; | |
4031 | else | |
4032 | bs_class = bp_silent; | |
4033 | } | |
4034 | else | |
53a5351d JM |
4035 | /* There was a catchpoint, but we're not stopping. |
4036 | This requires no further action. */ | |
c5aa993b JM |
4037 | bs_class = no_effect; |
4038 | break; | |
c906108c | 4039 | case bp_call_dummy: |
53a5351d JM |
4040 | /* Make sure the action is stop (silent or noisy), |
4041 | so infrun.c pops the dummy frame. */ | |
c906108c SS |
4042 | bs_class = bp_silent; |
4043 | retval.call_dummy = 1; | |
4044 | break; | |
1042e4c0 | 4045 | case bp_tracepoint: |
7a697b8d | 4046 | case bp_fast_tracepoint: |
1042e4c0 SS |
4047 | /* Tracepoint hits should not be reported back to GDB, and |
4048 | if one got through somehow, it should have been filtered | |
4049 | out already. */ | |
4050 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4051 | _("bpstat_what: tracepoint encountered")); |
1042e4c0 | 4052 | break; |
c906108c | 4053 | } |
c5aa993b | 4054 | current_action = table[(int) bs_class][(int) current_action]; |
c906108c SS |
4055 | } |
4056 | retval.main_action = current_action; | |
4057 | return retval; | |
4058 | } | |
4059 | ||
4060 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4061 | without hardware support). This isn't related to a specific bpstat, | |
4062 | just to things like whether watchpoints are set. */ | |
4063 | ||
c5aa993b | 4064 | int |
fba45db2 | 4065 | bpstat_should_step (void) |
c906108c SS |
4066 | { |
4067 | struct breakpoint *b; | |
4068 | ALL_BREAKPOINTS (b) | |
717a8278 | 4069 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4070 | return 1; |
c906108c SS |
4071 | return 0; |
4072 | } | |
4073 | ||
67822962 PA |
4074 | int |
4075 | bpstat_causes_stop (bpstat bs) | |
4076 | { | |
4077 | for (; bs != NULL; bs = bs->next) | |
4078 | if (bs->stop) | |
4079 | return 1; | |
4080 | ||
4081 | return 0; | |
4082 | } | |
4083 | ||
c906108c | 4084 | \f |
c5aa993b | 4085 | |
859825b8 JK |
4086 | /* Print the LOC location out of the list of B->LOC locations. */ |
4087 | ||
0d381245 VP |
4088 | static void print_breakpoint_location (struct breakpoint *b, |
4089 | struct bp_location *loc, | |
4090 | char *wrap_indent, | |
4091 | struct ui_stream *stb) | |
4092 | { | |
6c95b8df PA |
4093 | struct cleanup *old_chain = save_current_program_space (); |
4094 | ||
859825b8 JK |
4095 | if (loc != NULL && loc->shlib_disabled) |
4096 | loc = NULL; | |
4097 | ||
6c95b8df PA |
4098 | if (loc != NULL) |
4099 | set_current_program_space (loc->pspace); | |
4100 | ||
859825b8 | 4101 | if (b->source_file && loc) |
0d381245 VP |
4102 | { |
4103 | struct symbol *sym | |
4104 | = find_pc_sect_function (loc->address, loc->section); | |
4105 | if (sym) | |
4106 | { | |
4107 | ui_out_text (uiout, "in "); | |
4108 | ui_out_field_string (uiout, "func", | |
4109 | SYMBOL_PRINT_NAME (sym)); | |
4110 | ui_out_wrap_hint (uiout, wrap_indent); | |
4111 | ui_out_text (uiout, " at "); | |
4112 | } | |
4113 | ui_out_field_string (uiout, "file", b->source_file); | |
4114 | ui_out_text (uiout, ":"); | |
4115 | ||
4116 | if (ui_out_is_mi_like_p (uiout)) | |
4117 | { | |
4118 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4119 | char *fullname = symtab_to_fullname (sal.symtab); | |
4120 | ||
4121 | if (fullname) | |
4122 | ui_out_field_string (uiout, "fullname", fullname); | |
4123 | } | |
4124 | ||
4125 | ui_out_field_int (uiout, "line", b->line_number); | |
4126 | } | |
859825b8 | 4127 | else if (loc) |
0d381245 | 4128 | { |
22e722e1 DJ |
4129 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4130 | demangle, ""); | |
0d381245 VP |
4131 | ui_out_field_stream (uiout, "at", stb); |
4132 | } | |
859825b8 JK |
4133 | else |
4134 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4135 | |
4136 | do_cleanups (old_chain); | |
0d381245 VP |
4137 | } |
4138 | ||
c4093a6a | 4139 | /* Print B to gdb_stdout. */ |
c906108c | 4140 | static void |
0d381245 VP |
4141 | print_one_breakpoint_location (struct breakpoint *b, |
4142 | struct bp_location *loc, | |
4143 | int loc_number, | |
a6d9a66e | 4144 | struct bp_location **last_loc, |
6c95b8df PA |
4145 | int print_address_bits, |
4146 | int allflag) | |
c906108c | 4147 | { |
52f0bd74 AC |
4148 | struct command_line *l; |
4149 | struct symbol *sym; | |
c4093a6a JM |
4150 | struct ep_type_description |
4151 | { | |
4152 | enum bptype type; | |
4153 | char *description; | |
4154 | }; | |
4155 | static struct ep_type_description bptypes[] = | |
c906108c | 4156 | { |
c5aa993b JM |
4157 | {bp_none, "?deleted?"}, |
4158 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4159 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4160 | {bp_until, "until"}, |
4161 | {bp_finish, "finish"}, | |
4162 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4163 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4164 | {bp_read_watchpoint, "read watchpoint"}, |
4165 | {bp_access_watchpoint, "acc watchpoint"}, | |
4166 | {bp_longjmp, "longjmp"}, | |
4167 | {bp_longjmp_resume, "longjmp resume"}, | |
4168 | {bp_step_resume, "step resume"}, | |
c5aa993b JM |
4169 | {bp_watchpoint_scope, "watchpoint scope"}, |
4170 | {bp_call_dummy, "call dummy"}, | |
4171 | {bp_shlib_event, "shlib events"}, | |
c4093a6a | 4172 | {bp_thread_event, "thread events"}, |
1900040c | 4173 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4174 | {bp_longjmp_master, "longjmp master"}, |
ce78b96d | 4175 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4176 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4177 | {bp_fast_tracepoint, "fast tracepoint"}, |
4efc6507 | 4178 | {bp_jit_event, "jit events"}, |
c5aa993b | 4179 | }; |
c4093a6a | 4180 | |
c2c6d25f | 4181 | static char bpenables[] = "nynny"; |
c906108c | 4182 | char wrap_indent[80]; |
8b93c638 JM |
4183 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4184 | struct cleanup *old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3b31d625 | 4185 | struct cleanup *bkpt_chain; |
c906108c | 4186 | |
0d381245 VP |
4187 | int header_of_multiple = 0; |
4188 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4189 | struct value_print_options opts; |
4190 | ||
4191 | get_user_print_options (&opts); | |
0d381245 VP |
4192 | |
4193 | gdb_assert (!loc || loc_number != 0); | |
4194 | /* See comment in print_one_breakpoint concerning | |
4195 | treatment of breakpoints with single disabled | |
4196 | location. */ | |
4197 | if (loc == NULL | |
4198 | && (b->loc != NULL | |
4199 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4200 | header_of_multiple = 1; | |
4201 | if (loc == NULL) | |
4202 | loc = b->loc; | |
4203 | ||
c4093a6a | 4204 | annotate_record (); |
3b31d625 | 4205 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); |
c4093a6a JM |
4206 | |
4207 | /* 1 */ | |
4208 | annotate_field (0); | |
0d381245 VP |
4209 | if (part_of_multiple) |
4210 | { | |
4211 | char *formatted; | |
0c6773c1 | 4212 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4213 | ui_out_field_string (uiout, "number", formatted); |
4214 | xfree (formatted); | |
4215 | } | |
4216 | else | |
4217 | { | |
4218 | ui_out_field_int (uiout, "number", b->number); | |
4219 | } | |
c4093a6a JM |
4220 | |
4221 | /* 2 */ | |
4222 | annotate_field (1); | |
0d381245 VP |
4223 | if (part_of_multiple) |
4224 | ui_out_field_skip (uiout, "type"); | |
4225 | else | |
4226 | { | |
4227 | if (((int) b->type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4228 | || ((int) b->type != bptypes[(int) b->type].type)) | |
4229 | internal_error (__FILE__, __LINE__, | |
4230 | _("bptypes table does not describe type #%d."), | |
4231 | (int) b->type); | |
4232 | ui_out_field_string (uiout, "type", bptypes[(int) b->type].description); | |
4233 | } | |
c4093a6a JM |
4234 | |
4235 | /* 3 */ | |
4236 | annotate_field (2); | |
0d381245 VP |
4237 | if (part_of_multiple) |
4238 | ui_out_field_skip (uiout, "disp"); | |
4239 | else | |
2cec12e5 | 4240 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4241 | |
c4093a6a JM |
4242 | |
4243 | /* 4 */ | |
4244 | annotate_field (3); | |
0d381245 | 4245 | if (part_of_multiple) |
54e52265 | 4246 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4247 | else |
54e52265 VP |
4248 | ui_out_field_fmt (uiout, "enabled", "%c", |
4249 | bpenables[(int) b->enable_state]); | |
4250 | ui_out_spaces (uiout, 2); | |
0d381245 | 4251 | |
c4093a6a JM |
4252 | |
4253 | /* 5 and 6 */ | |
4254 | strcpy (wrap_indent, " "); | |
79a45b7d | 4255 | if (opts.addressprint) |
75ac9d7b | 4256 | { |
a6d9a66e | 4257 | if (print_address_bits <= 32) |
75ac9d7b MS |
4258 | strcat (wrap_indent, " "); |
4259 | else | |
4260 | strcat (wrap_indent, " "); | |
4261 | } | |
c906108c | 4262 | |
3086aeae | 4263 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 VP |
4264 | { |
4265 | /* Although the print_one can possibly print | |
4266 | all locations, calling it here is not likely | |
4267 | to get any nice result. So, make sure there's | |
4268 | just one location. */ | |
4269 | gdb_assert (b->loc == NULL || b->loc->next == NULL); | |
a6d9a66e | 4270 | b->ops->print_one (b, last_loc); |
0d381245 | 4271 | } |
3086aeae DJ |
4272 | else |
4273 | switch (b->type) | |
4274 | { | |
4275 | case bp_none: | |
4276 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4277 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4278 | break; |
c906108c | 4279 | |
3086aeae DJ |
4280 | case bp_watchpoint: |
4281 | case bp_hardware_watchpoint: | |
4282 | case bp_read_watchpoint: | |
4283 | case bp_access_watchpoint: | |
4284 | /* Field 4, the address, is omitted (which makes the columns | |
4285 | not line up too nicely with the headers, but the effect | |
4286 | is relatively readable). */ | |
79a45b7d | 4287 | if (opts.addressprint) |
3086aeae DJ |
4288 | ui_out_field_skip (uiout, "addr"); |
4289 | annotate_field (5); | |
fa8a61dc | 4290 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4291 | break; |
4292 | ||
3086aeae DJ |
4293 | case bp_breakpoint: |
4294 | case bp_hardware_breakpoint: | |
4295 | case bp_until: | |
4296 | case bp_finish: | |
4297 | case bp_longjmp: | |
4298 | case bp_longjmp_resume: | |
4299 | case bp_step_resume: | |
3086aeae DJ |
4300 | case bp_watchpoint_scope: |
4301 | case bp_call_dummy: | |
4302 | case bp_shlib_event: | |
4303 | case bp_thread_event: | |
4304 | case bp_overlay_event: | |
0fd8e87f | 4305 | case bp_longjmp_master: |
1042e4c0 | 4306 | case bp_tracepoint: |
7a697b8d | 4307 | case bp_fast_tracepoint: |
4efc6507 | 4308 | case bp_jit_event: |
79a45b7d | 4309 | if (opts.addressprint) |
3086aeae DJ |
4310 | { |
4311 | annotate_field (4); | |
54e52265 | 4312 | if (header_of_multiple) |
0d381245 | 4313 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4314 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4315 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4316 | else |
5af949e3 UW |
4317 | ui_out_field_core_addr (uiout, "addr", |
4318 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4319 | } |
4320 | annotate_field (5); | |
0d381245 VP |
4321 | if (!header_of_multiple) |
4322 | print_breakpoint_location (b, loc, wrap_indent, stb); | |
4323 | if (b->loc) | |
a6d9a66e | 4324 | *last_loc = b->loc; |
3086aeae DJ |
4325 | break; |
4326 | } | |
c906108c | 4327 | |
6c95b8df PA |
4328 | |
4329 | /* For backward compatibility, don't display inferiors unless there | |
4330 | are several. */ | |
4331 | if (loc != NULL | |
4332 | && !header_of_multiple | |
4333 | && (allflag | |
4334 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4335 | && (number_of_program_spaces () > 1 | |
4336 | || number_of_inferiors () > 1) | |
4337 | && loc->owner->type != bp_catchpoint))) | |
4338 | { | |
4339 | struct inferior *inf; | |
4340 | int first = 1; | |
4341 | ||
4342 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4343 | { | |
4344 | if (inf->pspace == loc->pspace) | |
4345 | { | |
4346 | if (first) | |
4347 | { | |
4348 | first = 0; | |
4349 | ui_out_text (uiout, " inf "); | |
4350 | } | |
4351 | else | |
4352 | ui_out_text (uiout, ", "); | |
4353 | ui_out_text (uiout, plongest (inf->num)); | |
4354 | } | |
4355 | } | |
4356 | } | |
4357 | ||
4a306c9a | 4358 | if (!part_of_multiple) |
c4093a6a | 4359 | { |
4a306c9a JB |
4360 | if (b->thread != -1) |
4361 | { | |
4362 | /* FIXME: This seems to be redundant and lost here; see the | |
4363 | "stop only in" line a little further down. */ | |
4364 | ui_out_text (uiout, " thread "); | |
4365 | ui_out_field_int (uiout, "thread", b->thread); | |
4366 | } | |
4367 | else if (b->task != 0) | |
4368 | { | |
4369 | ui_out_text (uiout, " task "); | |
4370 | ui_out_field_int (uiout, "task", b->task); | |
4371 | } | |
c4093a6a JM |
4372 | } |
4373 | ||
8b93c638 | 4374 | ui_out_text (uiout, "\n"); |
c4093a6a | 4375 | |
0d381245 | 4376 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
4377 | { |
4378 | annotate_field (6); | |
8b93c638 | 4379 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
4380 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
4381 | the frame ID. */ | |
5af949e3 UW |
4382 | ui_out_field_core_addr (uiout, "frame", |
4383 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 4384 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
4385 | } |
4386 | ||
0d381245 | 4387 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 4388 | { |
f7f9143b JB |
4389 | /* We do not print the condition for Ada exception catchpoints |
4390 | because the condition is an internal implementation detail | |
4391 | that we do not want to expose to the user. */ | |
c4093a6a | 4392 | annotate_field (7); |
7a697b8d | 4393 | if (tracepoint_type (b)) |
1042e4c0 SS |
4394 | ui_out_text (uiout, "\ttrace only if "); |
4395 | else | |
4396 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
4397 | ui_out_field_string (uiout, "cond", b->cond_string); |
4398 | ui_out_text (uiout, "\n"); | |
4399 | } | |
4400 | ||
0d381245 | 4401 | if (!part_of_multiple && b->thread != -1) |
c4093a6a JM |
4402 | { |
4403 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4404 | ui_out_text (uiout, "\tstop only in thread "); |
4405 | ui_out_field_int (uiout, "thread", b->thread); | |
4406 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
4407 | } |
4408 | ||
63c715c6 | 4409 | if (!part_of_multiple && b->hit_count) |
c4093a6a JM |
4410 | { |
4411 | /* FIXME should make an annotation for this */ | |
8b93c638 JM |
4412 | if (ep_is_catchpoint (b)) |
4413 | ui_out_text (uiout, "\tcatchpoint"); | |
4414 | else | |
4415 | ui_out_text (uiout, "\tbreakpoint"); | |
4416 | ui_out_text (uiout, " already hit "); | |
4417 | ui_out_field_int (uiout, "times", b->hit_count); | |
4418 | if (b->hit_count == 1) | |
4419 | ui_out_text (uiout, " time\n"); | |
4420 | else | |
4421 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
4422 | } |
4423 | ||
fb40c209 AC |
4424 | /* Output the count also if it is zero, but only if this is |
4425 | mi. FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 4426 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 4427 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 4428 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 4429 | |
0d381245 | 4430 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
4431 | { |
4432 | annotate_field (8); | |
8b93c638 JM |
4433 | ui_out_text (uiout, "\tignore next "); |
4434 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
4435 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 4436 | } |
059fb39f PM |
4437 | |
4438 | l = b->commands; | |
4439 | if (!part_of_multiple && l) | |
c4093a6a | 4440 | { |
3b31d625 EZ |
4441 | struct cleanup *script_chain; |
4442 | ||
c4093a6a | 4443 | annotate_field (9); |
3b31d625 | 4444 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 4445 | print_command_lines (uiout, l, 4); |
3b31d625 | 4446 | do_cleanups (script_chain); |
c4093a6a | 4447 | } |
d24317b4 | 4448 | |
1042e4c0 SS |
4449 | if (!part_of_multiple && b->pass_count) |
4450 | { | |
4451 | annotate_field (10); | |
4452 | ui_out_text (uiout, "\tpass count "); | |
4453 | ui_out_field_int (uiout, "pass", b->pass_count); | |
4454 | ui_out_text (uiout, " \n"); | |
4455 | } | |
4456 | ||
4457 | if (!part_of_multiple && b->step_count) | |
4458 | { | |
4459 | annotate_field (11); | |
4460 | ui_out_text (uiout, "\tstep count "); | |
4461 | ui_out_field_int (uiout, "step", b->step_count); | |
4462 | ui_out_text (uiout, " \n"); | |
4463 | } | |
4464 | ||
4465 | if (!part_of_multiple && b->actions) | |
4466 | { | |
4467 | struct action_line *action; | |
4468 | annotate_field (12); | |
4469 | for (action = b->actions; action; action = action->next) | |
4470 | { | |
4471 | ui_out_text (uiout, " A\t"); | |
4472 | ui_out_text (uiout, action->action); | |
4473 | ui_out_text (uiout, "\n"); | |
4474 | } | |
4475 | } | |
4476 | ||
d24317b4 VP |
4477 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
4478 | { | |
4479 | if (b->addr_string) | |
4480 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
4481 | else if (b->exp_string) | |
4482 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
4483 | } | |
4484 | ||
3b31d625 | 4485 | do_cleanups (bkpt_chain); |
8b93c638 | 4486 | do_cleanups (old_chain); |
c4093a6a | 4487 | } |
c5aa993b | 4488 | |
0d381245 VP |
4489 | static void |
4490 | print_one_breakpoint (struct breakpoint *b, | |
6c95b8df PA |
4491 | struct bp_location **last_loc, int print_address_bits, |
4492 | int allflag) | |
0d381245 | 4493 | { |
6c95b8df PA |
4494 | print_one_breakpoint_location (b, NULL, 0, last_loc, |
4495 | print_address_bits, allflag); | |
0d381245 VP |
4496 | |
4497 | /* If this breakpoint has custom print function, | |
4498 | it's already printed. Otherwise, print individual | |
4499 | locations, if any. */ | |
4500 | if (b->ops == NULL || b->ops->print_one == NULL) | |
4501 | { | |
4502 | /* If breakpoint has a single location that is | |
4503 | disabled, we print it as if it had | |
4504 | several locations, since otherwise it's hard to | |
4505 | represent "breakpoint enabled, location disabled" | |
a5606eee VP |
4506 | situation. |
4507 | Note that while hardware watchpoints have | |
4508 | several locations internally, that's no a property | |
4509 | exposed to user. */ | |
0d381245 | 4510 | if (b->loc |
a5606eee | 4511 | && !is_hardware_watchpoint (b) |
0d381245 | 4512 | && (b->loc->next || !b->loc->enabled) |
a5606eee | 4513 | && !ui_out_is_mi_like_p (uiout)) |
0d381245 VP |
4514 | { |
4515 | struct bp_location *loc; | |
4516 | int n = 1; | |
4517 | for (loc = b->loc; loc; loc = loc->next, ++n) | |
a6d9a66e | 4518 | print_one_breakpoint_location (b, loc, n, last_loc, |
6c95b8df | 4519 | print_address_bits, allflag); |
0d381245 VP |
4520 | } |
4521 | } | |
4522 | } | |
4523 | ||
a6d9a66e UW |
4524 | static int |
4525 | breakpoint_address_bits (struct breakpoint *b) | |
4526 | { | |
4527 | int print_address_bits = 0; | |
4528 | struct bp_location *loc; | |
4529 | ||
4530 | for (loc = b->loc; loc; loc = loc->next) | |
4531 | { | |
c7437ca6 PA |
4532 | int addr_bit; |
4533 | ||
4534 | /* Software watchpoints that aren't watching memory don't have | |
4535 | an address to print. */ | |
4536 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
4537 | continue; | |
4538 | ||
4539 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
4540 | if (addr_bit > print_address_bits) |
4541 | print_address_bits = addr_bit; | |
4542 | } | |
4543 | ||
4544 | return print_address_bits; | |
4545 | } | |
0d381245 | 4546 | |
c4093a6a JM |
4547 | struct captured_breakpoint_query_args |
4548 | { | |
4549 | int bnum; | |
4550 | }; | |
c5aa993b | 4551 | |
c4093a6a | 4552 | static int |
2b65245e | 4553 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
4554 | { |
4555 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 4556 | struct breakpoint *b; |
a6d9a66e | 4557 | struct bp_location *dummy_loc = NULL; |
c4093a6a JM |
4558 | ALL_BREAKPOINTS (b) |
4559 | { | |
4560 | if (args->bnum == b->number) | |
c5aa993b | 4561 | { |
a6d9a66e | 4562 | int print_address_bits = breakpoint_address_bits (b); |
6c95b8df | 4563 | print_one_breakpoint (b, &dummy_loc, print_address_bits, 0); |
c4093a6a | 4564 | return GDB_RC_OK; |
c5aa993b | 4565 | } |
c4093a6a JM |
4566 | } |
4567 | return GDB_RC_NONE; | |
4568 | } | |
c5aa993b | 4569 | |
c4093a6a | 4570 | enum gdb_rc |
ce43223b | 4571 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, char **error_message) |
c4093a6a JM |
4572 | { |
4573 | struct captured_breakpoint_query_args args; | |
4574 | args.bnum = bnum; | |
4575 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4576 | an error. */ | |
b0b13bb4 DJ |
4577 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
4578 | error_message, RETURN_MASK_ALL) < 0) | |
4579 | return GDB_RC_FAIL; | |
4580 | else | |
4581 | return GDB_RC_OK; | |
c4093a6a | 4582 | } |
c5aa993b | 4583 | |
7f3b0473 AC |
4584 | /* Return non-zero if B is user settable (breakpoints, watchpoints, |
4585 | catchpoints, et.al.). */ | |
4586 | ||
4587 | static int | |
4588 | user_settable_breakpoint (const struct breakpoint *b) | |
4589 | { | |
4590 | return (b->type == bp_breakpoint | |
ce78b96d | 4591 | || b->type == bp_catchpoint |
7f3b0473 | 4592 | || b->type == bp_hardware_breakpoint |
7a697b8d | 4593 | || tracepoint_type (b) |
7f3b0473 AC |
4594 | || b->type == bp_watchpoint |
4595 | || b->type == bp_read_watchpoint | |
4596 | || b->type == bp_access_watchpoint | |
4597 | || b->type == bp_hardware_watchpoint); | |
4598 | } | |
4599 | ||
4600 | /* Print information on user settable breakpoint (watchpoint, etc) | |
4601 | number BNUM. If BNUM is -1 print all user settable breakpoints. | |
4602 | If ALLFLAG is non-zero, include non- user settable breakpoints. */ | |
c906108c | 4603 | |
c4093a6a | 4604 | static void |
fba45db2 | 4605 | breakpoint_1 (int bnum, int allflag) |
c4093a6a | 4606 | { |
52f0bd74 | 4607 | struct breakpoint *b; |
a6d9a66e | 4608 | struct bp_location *last_loc = NULL; |
7f3b0473 | 4609 | int nr_printable_breakpoints; |
3b31d625 | 4610 | struct cleanup *bkpttbl_chain; |
79a45b7d | 4611 | struct value_print_options opts; |
a6d9a66e | 4612 | int print_address_bits = 0; |
c4093a6a | 4613 | |
79a45b7d TT |
4614 | get_user_print_options (&opts); |
4615 | ||
a6d9a66e UW |
4616 | /* Compute the number of rows in the table, as well as the |
4617 | size required for address fields. */ | |
7f3b0473 AC |
4618 | nr_printable_breakpoints = 0; |
4619 | ALL_BREAKPOINTS (b) | |
4620 | if (bnum == -1 | |
4621 | || bnum == b->number) | |
4622 | { | |
4623 | if (allflag || user_settable_breakpoint (b)) | |
a6d9a66e UW |
4624 | { |
4625 | int addr_bit = breakpoint_address_bits (b); | |
4626 | if (addr_bit > print_address_bits) | |
4627 | print_address_bits = addr_bit; | |
4628 | ||
4629 | nr_printable_breakpoints++; | |
4630 | } | |
7f3b0473 AC |
4631 | } |
4632 | ||
79a45b7d | 4633 | if (opts.addressprint) |
3b31d625 EZ |
4634 | bkpttbl_chain |
4635 | = make_cleanup_ui_out_table_begin_end (uiout, 6, nr_printable_breakpoints, | |
4636 | "BreakpointTable"); | |
8b93c638 | 4637 | else |
3b31d625 EZ |
4638 | bkpttbl_chain |
4639 | = make_cleanup_ui_out_table_begin_end (uiout, 5, nr_printable_breakpoints, | |
4640 | "BreakpointTable"); | |
8b93c638 | 4641 | |
7f3b0473 | 4642 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
4643 | annotate_breakpoints_headers (); |
4644 | if (nr_printable_breakpoints > 0) | |
4645 | annotate_field (0); | |
0d381245 | 4646 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
4647 | if (nr_printable_breakpoints > 0) |
4648 | annotate_field (1); | |
4649 | ui_out_table_header (uiout, 14, ui_left, "type", "Type"); /* 2 */ | |
4650 | if (nr_printable_breakpoints > 0) | |
4651 | annotate_field (2); | |
4652 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ | |
4653 | if (nr_printable_breakpoints > 0) | |
4654 | annotate_field (3); | |
54e52265 | 4655 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 4656 | if (opts.addressprint) |
7f3b0473 | 4657 | { |
d7faa9e7 AC |
4658 | if (nr_printable_breakpoints > 0) |
4659 | annotate_field (4); | |
a6d9a66e | 4660 | if (print_address_bits <= 32) |
b25959ec | 4661 | ui_out_table_header (uiout, 10, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4662 | else |
b25959ec | 4663 | ui_out_table_header (uiout, 18, ui_left, "addr", "Address");/* 5 */ |
7f3b0473 | 4664 | } |
d7faa9e7 AC |
4665 | if (nr_printable_breakpoints > 0) |
4666 | annotate_field (5); | |
4667 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
4668 | ui_out_table_body (uiout); | |
4669 | if (nr_printable_breakpoints > 0) | |
4670 | annotate_breakpoints_table (); | |
7f3b0473 | 4671 | |
c4093a6a JM |
4672 | ALL_BREAKPOINTS (b) |
4673 | if (bnum == -1 | |
4674 | || bnum == b->number) | |
4675 | { | |
4676 | /* We only print out user settable breakpoints unless the | |
4677 | allflag is set. */ | |
7f3b0473 | 4678 | if (allflag || user_settable_breakpoint (b)) |
6c95b8df | 4679 | print_one_breakpoint (b, &last_loc, print_address_bits, allflag); |
c4093a6a JM |
4680 | } |
4681 | ||
3b31d625 | 4682 | do_cleanups (bkpttbl_chain); |
698384cd | 4683 | |
7f3b0473 | 4684 | if (nr_printable_breakpoints == 0) |
c906108c | 4685 | { |
8b93c638 JM |
4686 | if (bnum == -1) |
4687 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); | |
4688 | else | |
4689 | ui_out_message (uiout, 0, "No breakpoint or watchpoint number %d.\n", | |
4690 | bnum); | |
c906108c SS |
4691 | } |
4692 | else | |
c4093a6a | 4693 | { |
a6d9a66e UW |
4694 | if (last_loc && !server_command) |
4695 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 4696 | } |
c906108c | 4697 | |
c4093a6a JM |
4698 | /* FIXME? Should this be moved up so that it is only called when |
4699 | there have been breakpoints? */ | |
c906108c SS |
4700 | annotate_breakpoints_table_end (); |
4701 | } | |
4702 | ||
c906108c | 4703 | static void |
fba45db2 | 4704 | breakpoints_info (char *bnum_exp, int from_tty) |
c906108c SS |
4705 | { |
4706 | int bnum = -1; | |
4707 | ||
4708 | if (bnum_exp) | |
bb518678 | 4709 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4710 | |
4711 | breakpoint_1 (bnum, 0); | |
4712 | } | |
4713 | ||
7a292a7a | 4714 | static void |
fba45db2 | 4715 | maintenance_info_breakpoints (char *bnum_exp, int from_tty) |
c906108c SS |
4716 | { |
4717 | int bnum = -1; | |
4718 | ||
4719 | if (bnum_exp) | |
bb518678 | 4720 | bnum = parse_and_eval_long (bnum_exp); |
c906108c SS |
4721 | |
4722 | breakpoint_1 (bnum, 1); | |
4723 | } | |
4724 | ||
0d381245 | 4725 | static int |
714835d5 | 4726 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 4727 | struct program_space *pspace, |
714835d5 | 4728 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
4729 | { |
4730 | struct bp_location *bl = b->loc; | |
4731 | for (; bl; bl = bl->next) | |
4732 | { | |
6c95b8df PA |
4733 | if (bl->pspace == pspace |
4734 | && bl->address == pc | |
0d381245 VP |
4735 | && (!overlay_debugging || bl->section == section)) |
4736 | return 1; | |
4737 | } | |
4738 | return 0; | |
4739 | } | |
4740 | ||
6c95b8df PA |
4741 | /* Print a message describing any breakpoints set at PC. This |
4742 | concerns with logical breakpoints, so we match program spaces, not | |
4743 | address spaces. */ | |
c906108c SS |
4744 | |
4745 | static void | |
6c95b8df PA |
4746 | describe_other_breakpoints (struct gdbarch *gdbarch, |
4747 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 4748 | struct obj_section *section, int thread) |
c906108c | 4749 | { |
52f0bd74 AC |
4750 | int others = 0; |
4751 | struct breakpoint *b; | |
c906108c SS |
4752 | |
4753 | ALL_BREAKPOINTS (b) | |
6c95b8df | 4754 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
4755 | if (others > 0) |
4756 | { | |
a3f17187 AC |
4757 | if (others == 1) |
4758 | printf_filtered (_("Note: breakpoint ")); | |
4759 | else /* if (others == ???) */ | |
4760 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 4761 | ALL_BREAKPOINTS (b) |
6c95b8df | 4762 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
4763 | { |
4764 | others--; | |
4765 | printf_filtered ("%d", b->number); | |
4766 | if (b->thread == -1 && thread != -1) | |
4767 | printf_filtered (" (all threads)"); | |
4768 | else if (b->thread != -1) | |
4769 | printf_filtered (" (thread %d)", b->thread); | |
4770 | printf_filtered ("%s%s ", | |
059fb39f | 4771 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
4772 | || b->enable_state == bp_call_disabled |
4773 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
4774 | ? " (disabled)" |
4775 | : b->enable_state == bp_permanent | |
4776 | ? " (permanent)" | |
4777 | : ""), | |
4778 | (others > 1) ? "," | |
4779 | : ((others == 1) ? " and" : "")); | |
4780 | } | |
a3f17187 | 4781 | printf_filtered (_("also set at pc ")); |
5af949e3 | 4782 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
4783 | printf_filtered (".\n"); |
4784 | } | |
4785 | } | |
4786 | \f | |
4787 | /* Set the default place to put a breakpoint | |
4788 | for the `break' command with no arguments. */ | |
4789 | ||
4790 | void | |
6c95b8df PA |
4791 | set_default_breakpoint (int valid, struct program_space *pspace, |
4792 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 4793 | int line) |
c906108c SS |
4794 | { |
4795 | default_breakpoint_valid = valid; | |
6c95b8df | 4796 | default_breakpoint_pspace = pspace; |
c906108c SS |
4797 | default_breakpoint_address = addr; |
4798 | default_breakpoint_symtab = symtab; | |
4799 | default_breakpoint_line = line; | |
4800 | } | |
4801 | ||
e4f237da KB |
4802 | /* Return true iff it is meaningful to use the address member of |
4803 | BPT. For some breakpoint types, the address member is irrelevant | |
4804 | and it makes no sense to attempt to compare it to other addresses | |
4805 | (or use it for any other purpose either). | |
4806 | ||
4807 | More specifically, each of the following breakpoint types will always | |
876fa593 JK |
4808 | have a zero valued address and we don't want to mark breakpoints of any of |
4809 | these types to be a duplicate of an actual breakpoint at address zero: | |
e4f237da KB |
4810 | |
4811 | bp_watchpoint | |
2d134ed3 PA |
4812 | bp_catchpoint |
4813 | ||
4814 | */ | |
e4f237da KB |
4815 | |
4816 | static int | |
4817 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
4818 | { | |
4819 | enum bptype type = bpt->type; | |
4820 | ||
2d134ed3 PA |
4821 | return (type != bp_watchpoint && type != bp_catchpoint); |
4822 | } | |
4823 | ||
4824 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
4825 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
4826 | ||
4827 | static int | |
4828 | watchpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
4829 | { | |
85d721b8 PA |
4830 | /* Note that this checks the owner's type, not the location's. In |
4831 | case the target does not support read watchpoints, but does | |
4832 | support access watchpoints, we'll have bp_read_watchpoint | |
4833 | watchpoints with hw_access locations. Those should be considered | |
4834 | duplicates of hw_read locations. The hw_read locations will | |
4835 | become hw_access locations later. */ | |
2d134ed3 PA |
4836 | return (loc1->owner->type == loc2->owner->type |
4837 | && loc1->pspace->aspace == loc2->pspace->aspace | |
4838 | && loc1->address == loc2->address | |
4839 | && loc1->length == loc2->length); | |
e4f237da KB |
4840 | } |
4841 | ||
6c95b8df PA |
4842 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
4843 | same breakpoint location. In most targets, this can only be true | |
4844 | if ASPACE1 matches ASPACE2. On targets that have global | |
4845 | breakpoints, the address space doesn't really matter. */ | |
4846 | ||
4847 | static int | |
4848 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
4849 | struct address_space *aspace2, CORE_ADDR addr2) | |
4850 | { | |
4851 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
4852 | || aspace1 == aspace2) | |
4853 | && addr1 == addr2); | |
4854 | } | |
4855 | ||
2d134ed3 PA |
4856 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
4857 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
4858 | represent the same location. */ | |
4859 | ||
4860 | static int | |
4861 | breakpoint_locations_match (struct bp_location *loc1, struct bp_location *loc2) | |
4862 | { | |
4863 | int hw_point1 = is_hardware_watchpoint (loc1->owner); | |
4864 | int hw_point2 = is_hardware_watchpoint (loc2->owner); | |
4865 | ||
4866 | if (hw_point1 != hw_point2) | |
4867 | return 0; | |
4868 | else if (hw_point1) | |
4869 | return watchpoint_locations_match (loc1, loc2); | |
4870 | else | |
4871 | return breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
4872 | loc2->pspace->aspace, loc2->address); | |
4873 | } | |
4874 | ||
76897487 KB |
4875 | static void |
4876 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
4877 | int bnum, int have_bnum) | |
4878 | { | |
4879 | char astr1[40]; | |
4880 | char astr2[40]; | |
4881 | ||
bb599908 PH |
4882 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
4883 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 4884 | if (have_bnum) |
8a3fe4f8 | 4885 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
4886 | bnum, astr1, astr2); |
4887 | else | |
8a3fe4f8 | 4888 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
4889 | } |
4890 | ||
4891 | /* Adjust a breakpoint's address to account for architectural constraints | |
4892 | on breakpoint placement. Return the adjusted address. Note: Very | |
4893 | few targets require this kind of adjustment. For most targets, | |
4894 | this function is simply the identity function. */ | |
4895 | ||
4896 | static CORE_ADDR | |
a6d9a66e UW |
4897 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
4898 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 4899 | { |
a6d9a66e | 4900 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
4901 | { |
4902 | /* Very few targets need any kind of breakpoint adjustment. */ | |
4903 | return bpaddr; | |
4904 | } | |
88f7da05 KB |
4905 | else if (bptype == bp_watchpoint |
4906 | || bptype == bp_hardware_watchpoint | |
4907 | || bptype == bp_read_watchpoint | |
4908 | || bptype == bp_access_watchpoint | |
fe798b75 | 4909 | || bptype == bp_catchpoint) |
88f7da05 KB |
4910 | { |
4911 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
4912 | have their addresses modified. */ | |
4913 | return bpaddr; | |
4914 | } | |
76897487 KB |
4915 | else |
4916 | { | |
4917 | CORE_ADDR adjusted_bpaddr; | |
4918 | ||
4919 | /* Some targets have architectural constraints on the placement | |
4920 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 4921 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
4922 | |
4923 | /* An adjusted breakpoint address can significantly alter | |
4924 | a user's expectations. Print a warning if an adjustment | |
4925 | is required. */ | |
4926 | if (adjusted_bpaddr != bpaddr) | |
4927 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
4928 | ||
4929 | return adjusted_bpaddr; | |
4930 | } | |
4931 | } | |
4932 | ||
7cc221ef DJ |
4933 | /* Allocate a struct bp_location. */ |
4934 | ||
26bb91f3 | 4935 | static struct bp_location * |
39d61571 | 4936 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef DJ |
4937 | { |
4938 | struct bp_location *loc, *loc_p; | |
4939 | ||
4940 | loc = xmalloc (sizeof (struct bp_location)); | |
4941 | memset (loc, 0, sizeof (*loc)); | |
4942 | ||
e049a4b5 | 4943 | loc->owner = bpt; |
511a6cd4 | 4944 | loc->cond = NULL; |
0d381245 VP |
4945 | loc->shlib_disabled = 0; |
4946 | loc->enabled = 1; | |
e049a4b5 | 4947 | |
39d61571 | 4948 | switch (bpt->type) |
e049a4b5 DJ |
4949 | { |
4950 | case bp_breakpoint: | |
4951 | case bp_until: | |
4952 | case bp_finish: | |
4953 | case bp_longjmp: | |
4954 | case bp_longjmp_resume: | |
4955 | case bp_step_resume: | |
e049a4b5 DJ |
4956 | case bp_watchpoint_scope: |
4957 | case bp_call_dummy: | |
4958 | case bp_shlib_event: | |
4959 | case bp_thread_event: | |
4960 | case bp_overlay_event: | |
4efc6507 | 4961 | case bp_jit_event: |
0fd8e87f | 4962 | case bp_longjmp_master: |
e049a4b5 DJ |
4963 | loc->loc_type = bp_loc_software_breakpoint; |
4964 | break; | |
4965 | case bp_hardware_breakpoint: | |
4966 | loc->loc_type = bp_loc_hardware_breakpoint; | |
4967 | break; | |
4968 | case bp_hardware_watchpoint: | |
4969 | case bp_read_watchpoint: | |
4970 | case bp_access_watchpoint: | |
4971 | loc->loc_type = bp_loc_hardware_watchpoint; | |
4972 | break; | |
4973 | case bp_watchpoint: | |
ce78b96d | 4974 | case bp_catchpoint: |
15c3d785 PA |
4975 | case bp_tracepoint: |
4976 | case bp_fast_tracepoint: | |
e049a4b5 DJ |
4977 | loc->loc_type = bp_loc_other; |
4978 | break; | |
4979 | default: | |
e2e0b3e5 | 4980 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
4981 | } |
4982 | ||
7cc221ef DJ |
4983 | return loc; |
4984 | } | |
4985 | ||
fe3f5fa8 VP |
4986 | static void free_bp_location (struct bp_location *loc) |
4987 | { | |
4988 | if (loc->cond) | |
4989 | xfree (loc->cond); | |
74960c60 VP |
4990 | |
4991 | if (loc->function_name) | |
4992 | xfree (loc->function_name); | |
4993 | ||
fe3f5fa8 VP |
4994 | xfree (loc); |
4995 | } | |
4996 | ||
0d381245 VP |
4997 | /* Helper to set_raw_breakpoint below. Creates a breakpoint |
4998 | that has type BPTYPE and has no locations as yet. */ | |
63c252f8 | 4999 | /* This function is used in gdbtk sources and thus can not be made static. */ |
c906108c | 5000 | |
c40e75cd | 5001 | static struct breakpoint * |
a6d9a66e UW |
5002 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5003 | enum bptype bptype) | |
c906108c | 5004 | { |
52f0bd74 | 5005 | struct breakpoint *b, *b1; |
c906108c SS |
5006 | |
5007 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5008 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5009 | |
4d28f7a8 | 5010 | b->type = bptype; |
a6d9a66e | 5011 | b->gdbarch = gdbarch; |
c906108c SS |
5012 | b->language = current_language->la_language; |
5013 | b->input_radix = input_radix; | |
5014 | b->thread = -1; | |
b5de0fa7 | 5015 | b->enable_state = bp_enabled; |
c906108c SS |
5016 | b->next = 0; |
5017 | b->silent = 0; | |
5018 | b->ignore_count = 0; | |
5019 | b->commands = NULL; | |
818dd999 | 5020 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5021 | b->forked_inferior_pid = null_ptid; |
c906108c | 5022 | b->exec_pathname = NULL; |
a96d9b2e | 5023 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5024 | b->ops = NULL; |
0d381245 | 5025 | b->condition_not_parsed = 0; |
c906108c SS |
5026 | |
5027 | /* Add this breakpoint to the end of the chain | |
5028 | so that a list of breakpoints will come out in order | |
5029 | of increasing numbers. */ | |
5030 | ||
5031 | b1 = breakpoint_chain; | |
5032 | if (b1 == 0) | |
5033 | breakpoint_chain = b; | |
5034 | else | |
5035 | { | |
5036 | while (b1->next) | |
5037 | b1 = b1->next; | |
5038 | b1->next = b; | |
5039 | } | |
0d381245 VP |
5040 | return b; |
5041 | } | |
5042 | ||
5043 | /* Initialize loc->function_name. */ | |
5044 | static void | |
5045 | set_breakpoint_location_function (struct bp_location *loc) | |
5046 | { | |
5047 | if (loc->owner->type == bp_breakpoint | |
1042e4c0 | 5048 | || loc->owner->type == bp_hardware_breakpoint |
7a697b8d | 5049 | || tracepoint_type (loc->owner)) |
0d381245 VP |
5050 | { |
5051 | find_pc_partial_function (loc->address, &(loc->function_name), | |
5052 | NULL, NULL); | |
5053 | if (loc->function_name) | |
5054 | loc->function_name = xstrdup (loc->function_name); | |
5055 | } | |
5056 | } | |
5057 | ||
a6d9a66e UW |
5058 | /* Attempt to determine architecture of location identified by SAL. */ |
5059 | static struct gdbarch * | |
5060 | get_sal_arch (struct symtab_and_line sal) | |
5061 | { | |
5062 | if (sal.section) | |
5063 | return get_objfile_arch (sal.section->objfile); | |
5064 | if (sal.symtab) | |
5065 | return get_objfile_arch (sal.symtab->objfile); | |
5066 | ||
5067 | return NULL; | |
5068 | } | |
5069 | ||
0d381245 VP |
5070 | /* set_raw_breakpoint is a low level routine for allocating and |
5071 | partially initializing a breakpoint of type BPTYPE. The newly | |
5072 | created breakpoint's address, section, source file name, and line | |
5073 | number are provided by SAL. The newly created and partially | |
5074 | initialized breakpoint is added to the breakpoint chain and | |
5075 | is also returned as the value of this function. | |
5076 | ||
5077 | It is expected that the caller will complete the initialization of | |
5078 | the newly created breakpoint struct as well as output any status | |
5079 | information regarding the creation of a new breakpoint. In | |
5080 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5081 | number! Care should be taken to not allow an error to occur | |
5082 | prior to completing the initialization of the breakpoint. If this | |
5083 | should happen, a bogus breakpoint will be left on the chain. */ | |
5084 | ||
63c252f8 | 5085 | struct breakpoint * |
a6d9a66e UW |
5086 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5087 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5088 | { |
a6d9a66e | 5089 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, bptype); |
0d381245 | 5090 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5091 | struct gdbarch *loc_gdbarch; |
5092 | ||
5093 | loc_gdbarch = get_sal_arch (sal); | |
5094 | if (!loc_gdbarch) | |
5095 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5096 | |
6c95b8df PA |
5097 | if (bptype != bp_catchpoint) |
5098 | gdb_assert (sal.pspace != NULL); | |
5099 | ||
0d381245 VP |
5100 | /* Adjust the breakpoint's address prior to allocating a location. |
5101 | Once we call allocate_bp_location(), that mostly uninitialized | |
5102 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5103 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5104 | not want its scan of the location chain to find a breakpoint and |
5105 | location that's only been partially initialized. */ | |
a6d9a66e | 5106 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, sal.pc, b->type); |
0d381245 | 5107 | |
39d61571 | 5108 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5109 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5110 | b->loc->requested_address = sal.pc; |
5111 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5112 | b->loc->pspace = sal.pspace; |
5113 | ||
5114 | /* Store the program space that was used to set the breakpoint, for | |
5115 | breakpoint resetting. */ | |
5116 | b->pspace = sal.pspace; | |
0d381245 VP |
5117 | |
5118 | if (sal.symtab == NULL) | |
5119 | b->source_file = NULL; | |
5120 | else | |
1b36a34b | 5121 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5122 | b->loc->section = sal.section; |
5123 | b->line_number = sal.line; | |
5124 | ||
5125 | set_breakpoint_location_function (b->loc); | |
c906108c | 5126 | |
c906108c SS |
5127 | breakpoints_changed (); |
5128 | ||
5129 | return b; | |
5130 | } | |
5131 | ||
c2c6d25f JM |
5132 | |
5133 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5134 | instruction, hard-wired into the inferior's code. */ | |
5135 | void | |
5136 | make_breakpoint_permanent (struct breakpoint *b) | |
5137 | { | |
0d381245 | 5138 | struct bp_location *bl; |
b5de0fa7 | 5139 | b->enable_state = bp_permanent; |
c2c6d25f | 5140 | |
0d381245 VP |
5141 | /* By definition, permanent breakpoints are already present in the code. |
5142 | Mark all locations as inserted. For now, make_breakpoint_permanent | |
5143 | is called in just one place, so it's hard to say if it's reasonable | |
5144 | to have permanent breakpoint with multiple locations or not, | |
5145 | but it's easy to implmement. */ | |
5146 | for (bl = b->loc; bl; bl = bl->next) | |
5147 | bl->inserted = 1; | |
c2c6d25f JM |
5148 | } |
5149 | ||
53a5351d | 5150 | /* Call this routine when stepping and nexting to enable a breakpoint |
0fd8e87f | 5151 | if we do a longjmp() in THREAD. When we hit that breakpoint, call |
c906108c SS |
5152 | set_longjmp_resume_breakpoint() to figure out where we are going. */ |
5153 | ||
5154 | void | |
0fd8e87f | 5155 | set_longjmp_breakpoint (int thread) |
c906108c | 5156 | { |
0fd8e87f UW |
5157 | struct breakpoint *b, *temp; |
5158 | ||
5159 | /* To avoid having to rescan all objfile symbols at every step, | |
5160 | we maintain a list of continually-inserted but always disabled | |
5161 | longjmp "master" breakpoints. Here, we simply create momentary | |
5162 | clones of those and enable them for the requested thread. */ | |
5163 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5164 | if (b->pspace == current_program_space |
5165 | && b->type == bp_longjmp_master) | |
0fd8e87f UW |
5166 | { |
5167 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
5168 | clone->type = bp_longjmp; | |
5169 | clone->thread = thread; | |
5170 | } | |
c906108c SS |
5171 | } |
5172 | ||
611c83ae | 5173 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 5174 | void |
611c83ae | 5175 | delete_longjmp_breakpoint (int thread) |
c906108c | 5176 | { |
611c83ae | 5177 | struct breakpoint *b, *temp; |
c906108c | 5178 | |
611c83ae PA |
5179 | ALL_BREAKPOINTS_SAFE (b, temp) |
5180 | if (b->type == bp_longjmp) | |
5181 | { | |
5182 | if (b->thread == thread) | |
5183 | delete_breakpoint (b); | |
5184 | } | |
c906108c SS |
5185 | } |
5186 | ||
1900040c MS |
5187 | void |
5188 | enable_overlay_breakpoints (void) | |
5189 | { | |
52f0bd74 | 5190 | struct breakpoint *b; |
1900040c MS |
5191 | |
5192 | ALL_BREAKPOINTS (b) | |
5193 | if (b->type == bp_overlay_event) | |
5194 | { | |
5195 | b->enable_state = bp_enabled; | |
b60e7edf | 5196 | update_global_location_list (1); |
c02f5703 | 5197 | overlay_events_enabled = 1; |
1900040c MS |
5198 | } |
5199 | } | |
5200 | ||
5201 | void | |
5202 | disable_overlay_breakpoints (void) | |
5203 | { | |
52f0bd74 | 5204 | struct breakpoint *b; |
1900040c MS |
5205 | |
5206 | ALL_BREAKPOINTS (b) | |
5207 | if (b->type == bp_overlay_event) | |
5208 | { | |
5209 | b->enable_state = bp_disabled; | |
b60e7edf | 5210 | update_global_location_list (0); |
c02f5703 | 5211 | overlay_events_enabled = 0; |
1900040c MS |
5212 | } |
5213 | } | |
5214 | ||
c4093a6a | 5215 | struct breakpoint * |
a6d9a66e | 5216 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
5217 | { |
5218 | struct breakpoint *b; | |
c4093a6a | 5219 | |
a6d9a66e | 5220 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 5221 | |
b5de0fa7 | 5222 | b->enable_state = bp_enabled; |
c4093a6a | 5223 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
5224 | b->addr_string |
5225 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 5226 | |
b60e7edf | 5227 | update_global_location_list_nothrow (1); |
74960c60 | 5228 | |
c4093a6a JM |
5229 | return b; |
5230 | } | |
5231 | ||
5232 | void | |
5233 | remove_thread_event_breakpoints (void) | |
5234 | { | |
5235 | struct breakpoint *b, *temp; | |
5236 | ||
5237 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5238 | if (b->type == bp_thread_event |
5239 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
5240 | delete_breakpoint (b); |
5241 | } | |
5242 | ||
0101ce28 JJ |
5243 | struct captured_parse_breakpoint_args |
5244 | { | |
5245 | char **arg_p; | |
5246 | struct symtabs_and_lines *sals_p; | |
5247 | char ***addr_string_p; | |
5248 | int *not_found_ptr; | |
5249 | }; | |
5250 | ||
5251 | struct lang_and_radix | |
5252 | { | |
5253 | enum language lang; | |
5254 | int radix; | |
5255 | }; | |
5256 | ||
4efc6507 DE |
5257 | /* Create a breakpoint for JIT code registration and unregistration. */ |
5258 | ||
5259 | struct breakpoint * | |
5260 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
5261 | { | |
5262 | struct breakpoint *b; | |
5263 | ||
5264 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
5265 | update_global_location_list_nothrow (1); | |
5266 | return b; | |
5267 | } | |
0101ce28 | 5268 | |
cae688ec JJ |
5269 | void |
5270 | remove_solib_event_breakpoints (void) | |
5271 | { | |
5272 | struct breakpoint *b, *temp; | |
5273 | ||
5274 | ALL_BREAKPOINTS_SAFE (b, temp) | |
6c95b8df PA |
5275 | if (b->type == bp_shlib_event |
5276 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
5277 | delete_breakpoint (b); |
5278 | } | |
5279 | ||
5280 | struct breakpoint * | |
a6d9a66e | 5281 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
5282 | { |
5283 | struct breakpoint *b; | |
5284 | ||
a6d9a66e | 5285 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 5286 | update_global_location_list_nothrow (1); |
cae688ec JJ |
5287 | return b; |
5288 | } | |
5289 | ||
5290 | /* Disable any breakpoints that are on code in shared libraries. Only | |
5291 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5292 | ||
5293 | void | |
cb851954 | 5294 | disable_breakpoints_in_shlibs (void) |
cae688ec | 5295 | { |
876fa593 | 5296 | struct bp_location *loc, **locp_tmp; |
cae688ec | 5297 | |
876fa593 | 5298 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 5299 | { |
0d381245 VP |
5300 | struct breakpoint *b = loc->owner; |
5301 | /* We apply the check to all breakpoints, including disabled | |
5302 | for those with loc->duplicate set. This is so that when breakpoint | |
5303 | becomes enabled, or the duplicate is removed, gdb will try to insert | |
5304 | all breakpoints. If we don't set shlib_disabled here, we'll try | |
5305 | to insert those breakpoints and fail. */ | |
1042e4c0 SS |
5306 | if (((b->type == bp_breakpoint) |
5307 | || (b->type == bp_hardware_breakpoint) | |
7a697b8d | 5308 | || (tracepoint_type (b))) |
6c95b8df | 5309 | && loc->pspace == current_program_space |
0d381245 | 5310 | && !loc->shlib_disabled |
a77053c2 | 5311 | #ifdef PC_SOLIB |
0d381245 | 5312 | && PC_SOLIB (loc->address) |
a77053c2 | 5313 | #else |
6c95b8df | 5314 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
5315 | #endif |
5316 | ) | |
0d381245 VP |
5317 | { |
5318 | loc->shlib_disabled = 1; | |
5319 | } | |
cae688ec JJ |
5320 | } |
5321 | } | |
5322 | ||
84acb35a JJ |
5323 | /* Disable any breakpoints that are in in an unloaded shared library. Only |
5324 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
5325 | ||
75149521 | 5326 | static void |
84acb35a JJ |
5327 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
5328 | { | |
876fa593 | 5329 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
5330 | int disabled_shlib_breaks = 0; |
5331 | ||
c86cf029 VP |
5332 | /* SunOS a.out shared libraries are always mapped, so do not |
5333 | disable breakpoints; they will only be reported as unloaded | |
5334 | through clear_solib when GDB discards its shared library | |
5335 | list. See clear_solib for more information. */ | |
5336 | if (exec_bfd != NULL | |
5337 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
5338 | return; | |
5339 | ||
876fa593 | 5340 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 5341 | { |
0d381245 VP |
5342 | struct breakpoint *b = loc->owner; |
5343 | if ((loc->loc_type == bp_loc_hardware_breakpoint | |
5344 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 5345 | && solib->pspace == loc->pspace |
e2dd7057 PP |
5346 | && !loc->shlib_disabled |
5347 | && (b->type == bp_breakpoint || b->type == bp_hardware_breakpoint) | |
5348 | && solib_contains_address_p (solib, loc->address)) | |
84acb35a | 5349 | { |
e2dd7057 PP |
5350 | loc->shlib_disabled = 1; |
5351 | /* At this point, we cannot rely on remove_breakpoint | |
5352 | succeeding so we must mark the breakpoint as not inserted | |
5353 | to prevent future errors occurring in remove_breakpoints. */ | |
5354 | loc->inserted = 0; | |
5355 | if (!disabled_shlib_breaks) | |
5356 | { | |
5357 | target_terminal_ours_for_output (); | |
5358 | warning (_("Temporarily disabling breakpoints for unloaded shared library \"%s\""), | |
5359 | solib->so_name); | |
84acb35a | 5360 | } |
e2dd7057 | 5361 | disabled_shlib_breaks = 1; |
84acb35a JJ |
5362 | } |
5363 | } | |
84acb35a JJ |
5364 | } |
5365 | ||
ce78b96d JB |
5366 | /* FORK & VFORK catchpoints. */ |
5367 | ||
5368 | /* Implement the "insert" breakpoint_ops method for fork catchpoints. */ | |
5369 | ||
c906108c | 5370 | static void |
ce78b96d JB |
5371 | insert_catch_fork (struct breakpoint *b) |
5372 | { | |
5373 | target_insert_fork_catchpoint (PIDGET (inferior_ptid)); | |
5374 | } | |
5375 | ||
5376 | /* Implement the "remove" breakpoint_ops method for fork catchpoints. */ | |
5377 | ||
5378 | static int | |
5379 | remove_catch_fork (struct breakpoint *b) | |
5380 | { | |
5381 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
5382 | } | |
5383 | ||
5384 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
5385 | catchpoints. */ | |
5386 | ||
5387 | static int | |
5388 | breakpoint_hit_catch_fork (struct breakpoint *b) | |
5389 | { | |
5390 | return inferior_has_forked (inferior_ptid, &b->forked_inferior_pid); | |
5391 | } | |
5392 | ||
5393 | /* Implement the "print_it" breakpoint_ops method for fork catchpoints. */ | |
5394 | ||
5395 | static enum print_stop_action | |
5396 | print_it_catch_fork (struct breakpoint *b) | |
5397 | { | |
5398 | annotate_catchpoint (b->number); | |
5399 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
5400 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5401 | return PRINT_SRC_AND_LOC; | |
5402 | } | |
5403 | ||
5404 | /* Implement the "print_one" breakpoint_ops method for fork catchpoints. */ | |
5405 | ||
5406 | static void | |
a6d9a66e | 5407 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5408 | { |
79a45b7d TT |
5409 | struct value_print_options opts; |
5410 | ||
5411 | get_user_print_options (&opts); | |
5412 | ||
ce78b96d JB |
5413 | /* Field 4, the address, is omitted (which makes the columns |
5414 | not line up too nicely with the headers, but the effect | |
5415 | is relatively readable). */ | |
79a45b7d | 5416 | if (opts.addressprint) |
ce78b96d JB |
5417 | ui_out_field_skip (uiout, "addr"); |
5418 | annotate_field (5); | |
5419 | ui_out_text (uiout, "fork"); | |
5420 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5421 | { | |
5422 | ui_out_text (uiout, ", process "); | |
5423 | ui_out_field_int (uiout, "what", | |
5424 | ptid_get_pid (b->forked_inferior_pid)); | |
5425 | ui_out_spaces (uiout, 1); | |
5426 | } | |
5427 | } | |
5428 | ||
5429 | /* Implement the "print_mention" breakpoint_ops method for fork | |
5430 | catchpoints. */ | |
5431 | ||
5432 | static void | |
5433 | print_mention_catch_fork (struct breakpoint *b) | |
5434 | { | |
5435 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
5436 | } | |
5437 | ||
5438 | /* The breakpoint_ops structure to be used in fork catchpoints. */ | |
5439 | ||
5440 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
5441 | { | |
5442 | insert_catch_fork, | |
5443 | remove_catch_fork, | |
5444 | breakpoint_hit_catch_fork, | |
5445 | print_it_catch_fork, | |
5446 | print_one_catch_fork, | |
5447 | print_mention_catch_fork | |
5448 | }; | |
5449 | ||
5450 | /* Implement the "insert" breakpoint_ops method for vfork catchpoints. */ | |
5451 | ||
5452 | static void | |
5453 | insert_catch_vfork (struct breakpoint *b) | |
5454 | { | |
5455 | target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5456 | } | |
5457 | ||
5458 | /* Implement the "remove" breakpoint_ops method for vfork catchpoints. */ | |
5459 | ||
5460 | static int | |
5461 | remove_catch_vfork (struct breakpoint *b) | |
5462 | { | |
5463 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
5464 | } | |
5465 | ||
5466 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
5467 | catchpoints. */ | |
5468 | ||
5469 | static int | |
5470 | breakpoint_hit_catch_vfork (struct breakpoint *b) | |
5471 | { | |
5472 | return inferior_has_vforked (inferior_ptid, &b->forked_inferior_pid); | |
5473 | } | |
5474 | ||
5475 | /* Implement the "print_it" breakpoint_ops method for vfork catchpoints. */ | |
5476 | ||
5477 | static enum print_stop_action | |
5478 | print_it_catch_vfork (struct breakpoint *b) | |
5479 | { | |
5480 | annotate_catchpoint (b->number); | |
5481 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
5482 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
5483 | return PRINT_SRC_AND_LOC; | |
5484 | } | |
5485 | ||
5486 | /* Implement the "print_one" breakpoint_ops method for vfork catchpoints. */ | |
5487 | ||
5488 | static void | |
a6d9a66e | 5489 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 5490 | { |
79a45b7d TT |
5491 | struct value_print_options opts; |
5492 | ||
5493 | get_user_print_options (&opts); | |
ce78b96d JB |
5494 | /* Field 4, the address, is omitted (which makes the columns |
5495 | not line up too nicely with the headers, but the effect | |
5496 | is relatively readable). */ | |
79a45b7d | 5497 | if (opts.addressprint) |
ce78b96d JB |
5498 | ui_out_field_skip (uiout, "addr"); |
5499 | annotate_field (5); | |
5500 | ui_out_text (uiout, "vfork"); | |
5501 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
5502 | { | |
5503 | ui_out_text (uiout, ", process "); | |
5504 | ui_out_field_int (uiout, "what", | |
5505 | ptid_get_pid (b->forked_inferior_pid)); | |
5506 | ui_out_spaces (uiout, 1); | |
5507 | } | |
5508 | } | |
5509 | ||
5510 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
5511 | catchpoints. */ | |
5512 | ||
5513 | static void | |
5514 | print_mention_catch_vfork (struct breakpoint *b) | |
5515 | { | |
5516 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
5517 | } | |
5518 | ||
5519 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ | |
5520 | ||
5521 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
5522 | { | |
5523 | insert_catch_vfork, | |
5524 | remove_catch_vfork, | |
5525 | breakpoint_hit_catch_vfork, | |
5526 | print_it_catch_vfork, | |
5527 | print_one_catch_vfork, | |
5528 | print_mention_catch_vfork | |
5529 | }; | |
5530 | ||
a96d9b2e SDJ |
5531 | /* Implement the "insert" breakpoint_ops method for syscall |
5532 | catchpoints. */ | |
5533 | ||
5534 | static void | |
5535 | insert_catch_syscall (struct breakpoint *b) | |
5536 | { | |
5537 | struct inferior *inf = current_inferior (); | |
5538 | ||
5539 | ++inf->total_syscalls_count; | |
5540 | if (!b->syscalls_to_be_caught) | |
5541 | ++inf->any_syscall_count; | |
5542 | else | |
5543 | { | |
5544 | int i, iter; | |
5545 | for (i = 0; | |
5546 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5547 | i++) | |
5548 | { | |
5549 | int elem; | |
5550 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5551 | { | |
5552 | int old_size = VEC_length (int, inf->syscalls_counts); | |
5553 | uintptr_t vec_addr_offset = old_size * ((uintptr_t) sizeof (int)); | |
5554 | uintptr_t vec_addr; | |
5555 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
5556 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
5557 | vec_addr_offset; | |
5558 | memset ((void *) vec_addr, 0, | |
5559 | (iter + 1 - old_size) * sizeof (int)); | |
5560 | } | |
5561 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5562 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
5563 | } | |
5564 | } | |
5565 | ||
5566 | target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5567 | inf->total_syscalls_count != 0, | |
5568 | inf->any_syscall_count, | |
5569 | VEC_length (int, inf->syscalls_counts), | |
5570 | VEC_address (int, inf->syscalls_counts)); | |
5571 | } | |
5572 | ||
5573 | /* Implement the "remove" breakpoint_ops method for syscall | |
5574 | catchpoints. */ | |
5575 | ||
5576 | static int | |
5577 | remove_catch_syscall (struct breakpoint *b) | |
5578 | { | |
5579 | struct inferior *inf = current_inferior (); | |
5580 | ||
5581 | --inf->total_syscalls_count; | |
5582 | if (!b->syscalls_to_be_caught) | |
5583 | --inf->any_syscall_count; | |
5584 | else | |
5585 | { | |
5586 | int i, iter; | |
5587 | for (i = 0; | |
5588 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5589 | i++) | |
5590 | { | |
5591 | int elem; | |
5592 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
5593 | /* Shouldn't happen. */ | |
5594 | continue; | |
5595 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
5596 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
5597 | } | |
5598 | } | |
5599 | ||
5600 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
5601 | inf->total_syscalls_count != 0, | |
5602 | inf->any_syscall_count, | |
5603 | VEC_length (int, inf->syscalls_counts), | |
5604 | VEC_address (int, inf->syscalls_counts)); | |
5605 | } | |
5606 | ||
5607 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
5608 | catchpoints. */ | |
5609 | ||
5610 | static int | |
5611 | breakpoint_hit_catch_syscall (struct breakpoint *b) | |
5612 | { | |
5613 | /* We must check if we are catching specific syscalls in this breakpoint. | |
5614 | If we are, then we must guarantee that the called syscall is the same | |
5615 | syscall we are catching. */ | |
5616 | int syscall_number = 0; | |
5617 | ||
5618 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
5619 | return 0; | |
5620 | ||
5621 | /* Now, checking if the syscall is the same. */ | |
5622 | if (b->syscalls_to_be_caught) | |
5623 | { | |
5624 | int i, iter; | |
5625 | for (i = 0; | |
5626 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5627 | i++) | |
5628 | if (syscall_number == iter) | |
5629 | break; | |
5630 | /* Not the same. */ | |
5631 | if (!iter) | |
5632 | return 0; | |
5633 | } | |
5634 | ||
5635 | return 1; | |
5636 | } | |
5637 | ||
5638 | /* Implement the "print_it" breakpoint_ops method for syscall | |
5639 | catchpoints. */ | |
5640 | ||
5641 | static enum print_stop_action | |
5642 | print_it_catch_syscall (struct breakpoint *b) | |
5643 | { | |
5644 | /* These are needed because we want to know in which state a | |
5645 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
5646 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
5647 | must print "called syscall" or "returned from syscall". */ | |
5648 | ptid_t ptid; | |
5649 | struct target_waitstatus last; | |
5650 | struct syscall s; | |
5651 | struct cleanup *old_chain; | |
5652 | char *syscall_id; | |
5653 | ||
5654 | get_last_target_status (&ptid, &last); | |
5655 | ||
5656 | get_syscall_by_number (last.value.syscall_number, &s); | |
5657 | ||
5658 | annotate_catchpoint (b->number); | |
5659 | ||
5660 | if (s.name == NULL) | |
5661 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
5662 | else | |
5663 | syscall_id = xstrprintf ("'%s'", s.name); | |
5664 | ||
5665 | old_chain = make_cleanup (xfree, syscall_id); | |
5666 | ||
5667 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
5668 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
5669 | b->number, syscall_id); | |
5670 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
5671 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
5672 | b->number, syscall_id); | |
5673 | ||
5674 | do_cleanups (old_chain); | |
5675 | ||
5676 | return PRINT_SRC_AND_LOC; | |
5677 | } | |
5678 | ||
5679 | /* Implement the "print_one" breakpoint_ops method for syscall | |
5680 | catchpoints. */ | |
5681 | ||
5682 | static void | |
5683 | print_one_catch_syscall (struct breakpoint *b, | |
5684 | struct bp_location **last_loc) | |
5685 | { | |
5686 | struct value_print_options opts; | |
5687 | ||
5688 | get_user_print_options (&opts); | |
5689 | /* Field 4, the address, is omitted (which makes the columns | |
5690 | not line up too nicely with the headers, but the effect | |
5691 | is relatively readable). */ | |
5692 | if (opts.addressprint) | |
5693 | ui_out_field_skip (uiout, "addr"); | |
5694 | annotate_field (5); | |
5695 | ||
5696 | if (b->syscalls_to_be_caught | |
5697 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5698 | ui_out_text (uiout, "syscalls \""); | |
5699 | else | |
5700 | ui_out_text (uiout, "syscall \""); | |
5701 | ||
5702 | if (b->syscalls_to_be_caught) | |
5703 | { | |
5704 | int i, iter; | |
5705 | char *text = xstrprintf ("%s", ""); | |
5706 | for (i = 0; | |
5707 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5708 | i++) | |
5709 | { | |
5710 | char *x = text; | |
5711 | struct syscall s; | |
5712 | get_syscall_by_number (iter, &s); | |
5713 | ||
5714 | if (s.name != NULL) | |
5715 | text = xstrprintf ("%s%s, ", text, s.name); | |
5716 | else | |
5717 | text = xstrprintf ("%s%d, ", text, iter); | |
5718 | ||
5719 | /* We have to xfree the last 'text' (now stored at 'x') | |
5720 | because xstrprintf dinamically allocates new space for it | |
5721 | on every call. */ | |
5722 | xfree (x); | |
5723 | } | |
5724 | /* Remove the last comma. */ | |
5725 | text[strlen (text) - 2] = '\0'; | |
5726 | ui_out_field_string (uiout, "what", text); | |
5727 | } | |
5728 | else | |
5729 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
5730 | ui_out_text (uiout, "\" "); | |
5731 | } | |
5732 | ||
5733 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
5734 | catchpoints. */ | |
5735 | ||
5736 | static void | |
5737 | print_mention_catch_syscall (struct breakpoint *b) | |
5738 | { | |
5739 | if (b->syscalls_to_be_caught) | |
5740 | { | |
5741 | int i, iter; | |
5742 | ||
5743 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
5744 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
5745 | else | |
5746 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
5747 | ||
5748 | for (i = 0; | |
5749 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
5750 | i++) | |
5751 | { | |
5752 | struct syscall s; | |
5753 | get_syscall_by_number (iter, &s); | |
5754 | ||
5755 | if (s.name) | |
5756 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
5757 | else | |
5758 | printf_filtered (" %d", s.number); | |
5759 | } | |
5760 | printf_filtered (")"); | |
5761 | } | |
5762 | else | |
5763 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
5764 | b->number); | |
5765 | } | |
5766 | ||
5767 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ | |
5768 | ||
5769 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
5770 | { | |
5771 | insert_catch_syscall, | |
5772 | remove_catch_syscall, | |
5773 | breakpoint_hit_catch_syscall, | |
5774 | print_it_catch_syscall, | |
5775 | print_one_catch_syscall, | |
5776 | print_mention_catch_syscall | |
5777 | }; | |
5778 | ||
5779 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
5780 | ||
5781 | static int | |
5782 | syscall_catchpoint_p (struct breakpoint *b) | |
5783 | { | |
5784 | return (b->ops == &catch_syscall_breakpoint_ops); | |
5785 | } | |
5786 | ||
5787 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
5788 | but does NOT mention it nor update the global location list. | |
5789 | This is useful if you need to fill more fields in the | |
5790 | struct breakpoint before calling mention. | |
ce78b96d JB |
5791 | |
5792 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5793 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5794 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5795 | to the catchpoint. */ | |
5796 | ||
5797 | static struct breakpoint * | |
a96d9b2e SDJ |
5798 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
5799 | char *cond_string, | |
5800 | struct breakpoint_ops *ops) | |
c906108c | 5801 | { |
c5aa993b JM |
5802 | struct symtab_and_line sal; |
5803 | struct breakpoint *b; | |
c5aa993b | 5804 | |
fe39c653 | 5805 | init_sal (&sal); |
6c95b8df | 5806 | sal.pspace = current_program_space; |
c5aa993b | 5807 | |
a6d9a66e | 5808 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
5809 | set_breakpoint_count (breakpoint_count + 1); |
5810 | b->number = breakpoint_count; | |
ce78b96d | 5811 | |
1b36a34b | 5812 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 5813 | b->thread = -1; |
c906108c | 5814 | b->addr_string = NULL; |
b5de0fa7 EZ |
5815 | b->enable_state = bp_enabled; |
5816 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 5817 | b->ops = ops; |
c5aa993b | 5818 | |
a96d9b2e SDJ |
5819 | return b; |
5820 | } | |
5821 | ||
5822 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
5823 | ||
5824 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
5825 | If COND_STRING is not NULL, then store it in the breakpoint. | |
5826 | OPS, if not NULL, is the breakpoint_ops structure associated | |
5827 | to the catchpoint. */ | |
5828 | ||
5829 | static struct breakpoint * | |
5830 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
5831 | char *cond_string, struct breakpoint_ops *ops) | |
5832 | { | |
5833 | struct breakpoint *b = | |
5834 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
5835 | ||
c906108c | 5836 | mention (b); |
ce78b96d | 5837 | update_global_location_list (1); |
c906108c | 5838 | |
ce78b96d | 5839 | return b; |
c906108c | 5840 | } |
c5aa993b | 5841 | |
9b70b993 | 5842 | static void |
a6d9a66e UW |
5843 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
5844 | int tempflag, char *cond_string, | |
ce78b96d | 5845 | struct breakpoint_ops *ops) |
c906108c | 5846 | { |
a6d9a66e UW |
5847 | struct breakpoint *b |
5848 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
5849 | |
5850 | /* FIXME: We should put this information in a breakpoint private data | |
5851 | area. */ | |
5852 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
5853 | } |
5854 | ||
fe798b75 JB |
5855 | /* Exec catchpoints. */ |
5856 | ||
9b70b993 | 5857 | static void |
fe798b75 | 5858 | insert_catch_exec (struct breakpoint *b) |
c906108c | 5859 | { |
fe798b75 JB |
5860 | target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
5861 | } | |
c906108c | 5862 | |
fe798b75 JB |
5863 | static int |
5864 | remove_catch_exec (struct breakpoint *b) | |
5865 | { | |
5866 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
5867 | } | |
c906108c | 5868 | |
fe798b75 JB |
5869 | static int |
5870 | breakpoint_hit_catch_exec (struct breakpoint *b) | |
5871 | { | |
5872 | return inferior_has_execd (inferior_ptid, &b->exec_pathname); | |
5873 | } | |
c906108c | 5874 | |
fe798b75 JB |
5875 | static enum print_stop_action |
5876 | print_it_catch_exec (struct breakpoint *b) | |
5877 | { | |
5878 | annotate_catchpoint (b->number); | |
5879 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
5880 | b->exec_pathname); | |
5881 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
5882 | } |
5883 | ||
fe798b75 | 5884 | static void |
a6d9a66e | 5885 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
5886 | { |
5887 | struct value_print_options opts; | |
5888 | ||
5889 | get_user_print_options (&opts); | |
5890 | ||
5891 | /* Field 4, the address, is omitted (which makes the columns | |
5892 | not line up too nicely with the headers, but the effect | |
5893 | is relatively readable). */ | |
5894 | if (opts.addressprint) | |
5895 | ui_out_field_skip (uiout, "addr"); | |
5896 | annotate_field (5); | |
5897 | ui_out_text (uiout, "exec"); | |
5898 | if (b->exec_pathname != NULL) | |
5899 | { | |
5900 | ui_out_text (uiout, ", program \""); | |
5901 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
5902 | ui_out_text (uiout, "\" "); | |
5903 | } | |
5904 | } | |
5905 | ||
5906 | static void | |
5907 | print_mention_catch_exec (struct breakpoint *b) | |
5908 | { | |
5909 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
5910 | } | |
5911 | ||
5912 | static struct breakpoint_ops catch_exec_breakpoint_ops = | |
5913 | { | |
5914 | insert_catch_exec, | |
5915 | remove_catch_exec, | |
5916 | breakpoint_hit_catch_exec, | |
5917 | print_it_catch_exec, | |
5918 | print_one_catch_exec, | |
5919 | print_mention_catch_exec | |
5920 | }; | |
5921 | ||
a96d9b2e SDJ |
5922 | static void |
5923 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
5924 | struct breakpoint_ops *ops) | |
5925 | { | |
5926 | struct gdbarch *gdbarch = get_current_arch (); | |
5927 | struct breakpoint *b = | |
5928 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
5929 | ||
5930 | b->syscalls_to_be_caught = filter; | |
5931 | ||
5932 | /* Now, we have to mention the breakpoint and update the global | |
5933 | location list. */ | |
5934 | mention (b); | |
5935 | update_global_location_list (1); | |
5936 | } | |
5937 | ||
c906108c | 5938 | static int |
fba45db2 | 5939 | hw_breakpoint_used_count (void) |
c906108c | 5940 | { |
52f0bd74 | 5941 | struct breakpoint *b; |
c906108c SS |
5942 | int i = 0; |
5943 | ||
5944 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5945 | { |
d6b74ac4 | 5946 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
c5aa993b JM |
5947 | i++; |
5948 | } | |
c906108c SS |
5949 | |
5950 | return i; | |
5951 | } | |
5952 | ||
5953 | static int | |
fba45db2 | 5954 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 5955 | { |
52f0bd74 | 5956 | struct breakpoint *b; |
c906108c SS |
5957 | int i = 0; |
5958 | ||
5959 | *other_type_used = 0; | |
5960 | ALL_BREAKPOINTS (b) | |
c5aa993b | 5961 | { |
468d015d | 5962 | if (breakpoint_enabled (b)) |
c5aa993b JM |
5963 | { |
5964 | if (b->type == type) | |
5965 | i++; | |
059fb39f PM |
5966 | else if ((b->type == bp_hardware_watchpoint |
5967 | || b->type == bp_read_watchpoint | |
5968 | || b->type == bp_access_watchpoint)) | |
c5aa993b JM |
5969 | *other_type_used = 1; |
5970 | } | |
5971 | } | |
c906108c SS |
5972 | return i; |
5973 | } | |
5974 | ||
c906108c | 5975 | void |
fba45db2 | 5976 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 5977 | { |
c5aa993b | 5978 | struct breakpoint *b; |
c906108c SS |
5979 | |
5980 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
5981 | { |
5982 | if (((b->type == bp_watchpoint) | |
5983 | || (b->type == bp_hardware_watchpoint) | |
5984 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 5985 | || (b->type == bp_access_watchpoint)) |
468d015d | 5986 | && breakpoint_enabled (b)) |
c5aa993b | 5987 | { |
b5de0fa7 | 5988 | b->enable_state = bp_call_disabled; |
b60e7edf | 5989 | update_global_location_list (0); |
c5aa993b JM |
5990 | } |
5991 | } | |
c906108c SS |
5992 | } |
5993 | ||
5994 | void | |
fba45db2 | 5995 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 5996 | { |
c5aa993b | 5997 | struct breakpoint *b; |
c906108c SS |
5998 | |
5999 | ALL_BREAKPOINTS (b) | |
c5aa993b JM |
6000 | { |
6001 | if (((b->type == bp_watchpoint) | |
6002 | || (b->type == bp_hardware_watchpoint) | |
6003 | || (b->type == bp_read_watchpoint) | |
dfdfb3ca | 6004 | || (b->type == bp_access_watchpoint)) |
b5de0fa7 | 6005 | && (b->enable_state == bp_call_disabled)) |
c5aa993b | 6006 | { |
b5de0fa7 | 6007 | b->enable_state = bp_enabled; |
b60e7edf | 6008 | update_global_location_list (1); |
c5aa993b JM |
6009 | } |
6010 | } | |
c906108c SS |
6011 | } |
6012 | ||
8bea4e01 UW |
6013 | void |
6014 | disable_breakpoints_before_startup (void) | |
6015 | { | |
6016 | struct breakpoint *b; | |
6017 | int found = 0; | |
6018 | ||
6019 | ALL_BREAKPOINTS (b) | |
6020 | { | |
6c95b8df PA |
6021 | if (b->pspace != current_program_space) |
6022 | continue; | |
6023 | ||
8bea4e01 UW |
6024 | if ((b->type == bp_breakpoint |
6025 | || b->type == bp_hardware_breakpoint) | |
6026 | && breakpoint_enabled (b)) | |
6027 | { | |
6028 | b->enable_state = bp_startup_disabled; | |
6029 | found = 1; | |
6030 | } | |
6031 | } | |
6032 | ||
6033 | if (found) | |
6034 | update_global_location_list (0); | |
6035 | ||
6c95b8df | 6036 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
6037 | } |
6038 | ||
6039 | void | |
6040 | enable_breakpoints_after_startup (void) | |
6041 | { | |
6042 | struct breakpoint *b; | |
6043 | int found = 0; | |
6044 | ||
6c95b8df | 6045 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
6046 | |
6047 | ALL_BREAKPOINTS (b) | |
6048 | { | |
6c95b8df PA |
6049 | if (b->pspace != current_program_space) |
6050 | continue; | |
6051 | ||
8bea4e01 UW |
6052 | if ((b->type == bp_breakpoint |
6053 | || b->type == bp_hardware_breakpoint) | |
6054 | && b->enable_state == bp_startup_disabled) | |
6055 | { | |
6056 | b->enable_state = bp_enabled; | |
6057 | found = 1; | |
6058 | } | |
6059 | } | |
6060 | ||
6061 | if (found) | |
6062 | breakpoint_re_set (); | |
6063 | } | |
6064 | ||
c906108c SS |
6065 | |
6066 | /* Set a breakpoint that will evaporate an end of command | |
6067 | at address specified by SAL. | |
6068 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
6069 | ||
6070 | struct breakpoint * | |
a6d9a66e UW |
6071 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
6072 | struct frame_id frame_id, enum bptype type) | |
c906108c | 6073 | { |
52f0bd74 | 6074 | struct breakpoint *b; |
edb3359d DJ |
6075 | |
6076 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
6077 | one. */ | |
6078 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
6079 | ||
a6d9a66e | 6080 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
6081 | b->enable_state = bp_enabled; |
6082 | b->disposition = disp_donttouch; | |
818dd999 | 6083 | b->frame_id = frame_id; |
c906108c SS |
6084 | |
6085 | /* If we're debugging a multi-threaded program, then we | |
6086 | want momentary breakpoints to be active in only a | |
6087 | single thread of control. */ | |
39f77062 KB |
6088 | if (in_thread_list (inferior_ptid)) |
6089 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 6090 | |
b60e7edf | 6091 | update_global_location_list_nothrow (1); |
74960c60 | 6092 | |
c906108c SS |
6093 | return b; |
6094 | } | |
611c83ae | 6095 | |
e58b0e63 PA |
6096 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
6097 | ORIG is NULL. */ | |
6098 | ||
6099 | struct breakpoint * | |
6100 | clone_momentary_breakpoint (struct breakpoint *orig) | |
6101 | { | |
6102 | struct breakpoint *copy; | |
6103 | ||
6104 | /* If there's nothing to clone, then return nothing. */ | |
6105 | if (orig == NULL) | |
6106 | return NULL; | |
6107 | ||
a6d9a66e | 6108 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 PA |
6109 | copy->loc = allocate_bp_location (copy); |
6110 | set_breakpoint_location_function (copy->loc); | |
6111 | ||
a6d9a66e | 6112 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
6113 | copy->loc->requested_address = orig->loc->requested_address; |
6114 | copy->loc->address = orig->loc->address; | |
6115 | copy->loc->section = orig->loc->section; | |
6c95b8df | 6116 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
6117 | |
6118 | if (orig->source_file == NULL) | |
6119 | copy->source_file = NULL; | |
6120 | else | |
6121 | copy->source_file = xstrdup (orig->source_file); | |
6122 | ||
6123 | copy->line_number = orig->line_number; | |
6124 | copy->frame_id = orig->frame_id; | |
6125 | copy->thread = orig->thread; | |
6c95b8df | 6126 | copy->pspace = orig->pspace; |
e58b0e63 PA |
6127 | |
6128 | copy->enable_state = bp_enabled; | |
6129 | copy->disposition = disp_donttouch; | |
6130 | copy->number = internal_breakpoint_number--; | |
6131 | ||
6132 | update_global_location_list_nothrow (0); | |
6133 | return copy; | |
6134 | } | |
6135 | ||
611c83ae | 6136 | struct breakpoint * |
a6d9a66e UW |
6137 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
6138 | enum bptype type) | |
611c83ae PA |
6139 | { |
6140 | struct symtab_and_line sal; | |
6141 | ||
6142 | sal = find_pc_line (pc, 0); | |
6143 | sal.pc = pc; | |
6144 | sal.section = find_pc_overlay (pc); | |
6145 | sal.explicit_pc = 1; | |
6146 | ||
a6d9a66e | 6147 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 6148 | } |
c906108c | 6149 | \f |
c5aa993b | 6150 | |
c906108c SS |
6151 | /* Tell the user we have just set a breakpoint B. */ |
6152 | ||
6153 | static void | |
fba45db2 | 6154 | mention (struct breakpoint *b) |
c906108c SS |
6155 | { |
6156 | int say_where = 0; | |
fa8a61dc | 6157 | struct cleanup *ui_out_chain; |
79a45b7d TT |
6158 | struct value_print_options opts; |
6159 | ||
6160 | get_user_print_options (&opts); | |
8b93c638 | 6161 | |
9a4105ab AC |
6162 | /* FIXME: This is misplaced; mention() is called by things (like |
6163 | hitting a watchpoint) other than breakpoint creation. It should | |
6164 | be possible to clean this up and at the same time replace the | |
7f4b89d1 | 6165 | random calls to breakpoint_changed with this hook. */ |
383f836e | 6166 | observer_notify_breakpoint_created (b->number); |
c906108c | 6167 | |
3086aeae DJ |
6168 | if (b->ops != NULL && b->ops->print_mention != NULL) |
6169 | b->ops->print_mention (b); | |
6170 | else | |
6171 | switch (b->type) | |
6172 | { | |
6173 | case bp_none: | |
a3f17187 | 6174 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), b->number); |
3086aeae DJ |
6175 | break; |
6176 | case bp_watchpoint: | |
6177 | ui_out_text (uiout, "Watchpoint "); | |
6178 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6179 | ui_out_field_int (uiout, "number", b->number); | |
6180 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6181 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6182 | do_cleanups (ui_out_chain); |
6183 | break; | |
6184 | case bp_hardware_watchpoint: | |
6185 | ui_out_text (uiout, "Hardware watchpoint "); | |
6186 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
6187 | ui_out_field_int (uiout, "number", b->number); | |
6188 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6189 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6190 | do_cleanups (ui_out_chain); |
6191 | break; | |
6192 | case bp_read_watchpoint: | |
6193 | ui_out_text (uiout, "Hardware read watchpoint "); | |
6194 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
6195 | ui_out_field_int (uiout, "number", b->number); | |
6196 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6197 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6198 | do_cleanups (ui_out_chain); |
6199 | break; | |
6200 | case bp_access_watchpoint: | |
6201 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
6202 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
6203 | ui_out_field_int (uiout, "number", b->number); | |
6204 | ui_out_text (uiout, ": "); | |
fa8a61dc | 6205 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
6206 | do_cleanups (ui_out_chain); |
6207 | break; | |
6208 | case bp_breakpoint: | |
6209 | if (ui_out_is_mi_like_p (uiout)) | |
6210 | { | |
6211 | say_where = 0; | |
6212 | break; | |
6213 | } | |
2cec12e5 AR |
6214 | if (b->disposition == disp_del) |
6215 | printf_filtered (_("Temporary breakpoint")); | |
6216 | else | |
6217 | printf_filtered (_("Breakpoint")); | |
6218 | printf_filtered (_(" %d"), b->number); | |
3086aeae DJ |
6219 | say_where = 1; |
6220 | break; | |
6221 | case bp_hardware_breakpoint: | |
6222 | if (ui_out_is_mi_like_p (uiout)) | |
6223 | { | |
6224 | say_where = 0; | |
6225 | break; | |
6226 | } | |
a3f17187 | 6227 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
6228 | say_where = 1; |
6229 | break; | |
1042e4c0 SS |
6230 | case bp_tracepoint: |
6231 | if (ui_out_is_mi_like_p (uiout)) | |
6232 | { | |
6233 | say_where = 0; | |
6234 | break; | |
6235 | } | |
6236 | printf_filtered (_("Tracepoint")); | |
6237 | printf_filtered (_(" %d"), b->number); | |
6238 | say_where = 1; | |
6239 | break; | |
7a697b8d SS |
6240 | case bp_fast_tracepoint: |
6241 | if (ui_out_is_mi_like_p (uiout)) | |
6242 | { | |
6243 | say_where = 0; | |
6244 | break; | |
6245 | } | |
6246 | printf_filtered (_("Fast tracepoint")); | |
6247 | printf_filtered (_(" %d"), b->number); | |
6248 | say_where = 1; | |
6249 | break; | |
3086aeae DJ |
6250 | |
6251 | case bp_until: | |
6252 | case bp_finish: | |
6253 | case bp_longjmp: | |
6254 | case bp_longjmp_resume: | |
6255 | case bp_step_resume: | |
3086aeae DJ |
6256 | case bp_call_dummy: |
6257 | case bp_watchpoint_scope: | |
6258 | case bp_shlib_event: | |
6259 | case bp_thread_event: | |
6260 | case bp_overlay_event: | |
4efc6507 | 6261 | case bp_jit_event: |
0fd8e87f | 6262 | case bp_longjmp_master: |
3086aeae DJ |
6263 | break; |
6264 | } | |
c906108c | 6265 | |
c906108c SS |
6266 | if (say_where) |
6267 | { | |
a3f17187 AC |
6268 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
6269 | single string. */ | |
0d381245 | 6270 | if (b->loc == NULL) |
c906108c | 6271 | { |
a3f17187 | 6272 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
6273 | } |
6274 | else | |
6275 | { | |
79a45b7d | 6276 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
6277 | { |
6278 | printf_filtered (" at "); | |
5af949e3 UW |
6279 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
6280 | gdb_stdout); | |
0101ce28 JJ |
6281 | } |
6282 | if (b->source_file) | |
6283 | printf_filtered (": file %s, line %d.", | |
6284 | b->source_file, b->line_number); | |
0d381245 VP |
6285 | |
6286 | if (b->loc->next) | |
6287 | { | |
6288 | struct bp_location *loc = b->loc; | |
6289 | int n = 0; | |
6290 | for (; loc; loc = loc->next) | |
6291 | ++n; | |
6292 | printf_filtered (" (%d locations)", n); | |
6293 | } | |
6294 | ||
c906108c | 6295 | } |
c906108c | 6296 | } |
9dc5e2a9 | 6297 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 6298 | return; |
c906108c SS |
6299 | printf_filtered ("\n"); |
6300 | } | |
c906108c | 6301 | \f |
c5aa993b | 6302 | |
0d381245 | 6303 | static struct bp_location * |
39d61571 | 6304 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
6305 | const struct symtab_and_line *sal) |
6306 | { | |
6307 | struct bp_location *loc, **tmp; | |
6308 | ||
39d61571 | 6309 | loc = allocate_bp_location (b); |
0d381245 VP |
6310 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
6311 | ; | |
6312 | *tmp = loc; | |
a6d9a66e UW |
6313 | loc->gdbarch = get_sal_arch (*sal); |
6314 | if (!loc->gdbarch) | |
6315 | loc->gdbarch = b->gdbarch; | |
0d381245 | 6316 | loc->requested_address = sal->pc; |
a6d9a66e UW |
6317 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
6318 | loc->requested_address, b->type); | |
6c95b8df PA |
6319 | loc->pspace = sal->pspace; |
6320 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
6321 | loc->section = sal->section; |
6322 | ||
6323 | set_breakpoint_location_function (loc); | |
6324 | return loc; | |
6325 | } | |
514f746b AR |
6326 | \f |
6327 | ||
6328 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
6329 | return 0 otherwise. */ | |
6330 | ||
6331 | static int | |
6332 | bp_loc_is_permanent (struct bp_location *loc) | |
6333 | { | |
6334 | int len; | |
6335 | CORE_ADDR addr; | |
6336 | const gdb_byte *brk; | |
6337 | gdb_byte *target_mem; | |
939c61fa JK |
6338 | struct cleanup *cleanup; |
6339 | int retval = 0; | |
514f746b AR |
6340 | |
6341 | gdb_assert (loc != NULL); | |
6342 | ||
6343 | addr = loc->address; | |
a6d9a66e | 6344 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 6345 | |
939c61fa JK |
6346 | /* Software breakpoints unsupported? */ |
6347 | if (brk == NULL) | |
6348 | return 0; | |
6349 | ||
514f746b AR |
6350 | target_mem = alloca (len); |
6351 | ||
939c61fa JK |
6352 | /* Enable the automatic memory restoration from breakpoints while |
6353 | we read the memory. Otherwise we could say about our temporary | |
6354 | breakpoints they are permanent. */ | |
6c95b8df PA |
6355 | cleanup = save_current_space_and_thread (); |
6356 | ||
6357 | switch_to_program_space_and_thread (loc->pspace); | |
6358 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 6359 | |
514f746b AR |
6360 | if (target_read_memory (loc->address, target_mem, len) == 0 |
6361 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 6362 | retval = 1; |
514f746b | 6363 | |
939c61fa JK |
6364 | do_cleanups (cleanup); |
6365 | ||
6366 | return retval; | |
514f746b AR |
6367 | } |
6368 | ||
6369 | ||
c3f6f71d | 6370 | |
018d34a4 VP |
6371 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
6372 | as textual description of the location, and COND_STRING | |
db107f19 | 6373 | as condition expression. */ |
018d34a4 VP |
6374 | |
6375 | static void | |
a6d9a66e UW |
6376 | create_breakpoint (struct gdbarch *gdbarch, |
6377 | struct symtabs_and_lines sals, char *addr_string, | |
018d34a4 VP |
6378 | char *cond_string, |
6379 | enum bptype type, enum bpdisp disposition, | |
4a306c9a | 6380 | int thread, int task, int ignore_count, |
41447f92 | 6381 | struct breakpoint_ops *ops, int from_tty, int enabled) |
018d34a4 | 6382 | { |
0d381245 VP |
6383 | struct breakpoint *b = NULL; |
6384 | int i; | |
018d34a4 VP |
6385 | |
6386 | if (type == bp_hardware_breakpoint) | |
6387 | { | |
6388 | int i = hw_breakpoint_used_count (); | |
6389 | int target_resources_ok = | |
d92524f1 | 6390 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
6391 | i + 1, 0); |
6392 | if (target_resources_ok == 0) | |
6393 | error (_("No hardware breakpoint support in the target.")); | |
6394 | else if (target_resources_ok < 0) | |
6395 | error (_("Hardware breakpoints used exceeds limit.")); | |
6396 | } | |
6397 | ||
6c95b8df PA |
6398 | gdb_assert (sals.nelts > 0); |
6399 | ||
0d381245 VP |
6400 | for (i = 0; i < sals.nelts; ++i) |
6401 | { | |
6402 | struct symtab_and_line sal = sals.sals[i]; | |
6403 | struct bp_location *loc; | |
6404 | ||
6405 | if (from_tty) | |
5af949e3 UW |
6406 | { |
6407 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
6408 | if (!loc_gdbarch) | |
6409 | loc_gdbarch = gdbarch; | |
6410 | ||
6411 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 6412 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 6413 | } |
0d381245 VP |
6414 | |
6415 | if (i == 0) | |
6416 | { | |
a6d9a66e | 6417 | b = set_raw_breakpoint (gdbarch, sal, type); |
0d381245 VP |
6418 | set_breakpoint_count (breakpoint_count + 1); |
6419 | b->number = breakpoint_count; | |
6420 | b->thread = thread; | |
4a306c9a | 6421 | b->task = task; |
018d34a4 | 6422 | |
0d381245 VP |
6423 | b->cond_string = cond_string; |
6424 | b->ignore_count = ignore_count; | |
41447f92 | 6425 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 6426 | b->disposition = disposition; |
018d34a4 | 6427 | |
6c95b8df PA |
6428 | b->pspace = sals.sals[0].pspace; |
6429 | ||
6430 | if (enabled && b->pspace->executing_startup | |
8bea4e01 UW |
6431 | && (b->type == bp_breakpoint |
6432 | || b->type == bp_hardware_breakpoint)) | |
6433 | b->enable_state = bp_startup_disabled; | |
6434 | ||
0d381245 VP |
6435 | loc = b->loc; |
6436 | } | |
6437 | else | |
018d34a4 | 6438 | { |
39d61571 | 6439 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
6440 | } |
6441 | ||
514f746b AR |
6442 | if (bp_loc_is_permanent (loc)) |
6443 | make_breakpoint_permanent (b); | |
6444 | ||
0d381245 VP |
6445 | if (b->cond_string) |
6446 | { | |
6447 | char *arg = b->cond_string; | |
d32a6982 | 6448 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 6449 | if (*arg) |
db107f19 | 6450 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 6451 | } |
0d381245 | 6452 | } |
018d34a4 VP |
6453 | |
6454 | if (addr_string) | |
6455 | b->addr_string = addr_string; | |
6456 | else | |
6457 | /* addr_string has to be used or breakpoint_re_set will delete | |
6458 | me. */ | |
5af949e3 UW |
6459 | b->addr_string |
6460 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 6461 | |
604133b5 | 6462 | b->ops = ops; |
018d34a4 VP |
6463 | mention (b); |
6464 | } | |
6465 | ||
ed0616c6 VP |
6466 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
6467 | elements to fill the void space. */ | |
2c0b251b PA |
6468 | static void |
6469 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
6470 | { |
6471 | int i = index_to_remove+1; | |
6472 | int last_index = sal->nelts-1; | |
6473 | ||
6474 | for (;i <= last_index; ++i) | |
6475 | sal->sals[i-1] = sal->sals[i]; | |
6476 | ||
6477 | --(sal->nelts); | |
6478 | } | |
6479 | ||
6c95b8df PA |
6480 | /* If appropriate, obtains all sals that correspond to the same file |
6481 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
6482 | will want to set a breakpoint at foo.c:line, and not really care | |
6483 | about program spaces. This is done only if SAL does not have | |
6484 | explicit PC and has line and file information. If we got just a | |
6485 | single expanded sal, return the original. | |
ed0616c6 | 6486 | |
6c95b8df PA |
6487 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
6488 | which the name of enclosing function is different from SAL. This | |
6489 | makes sure that if we have breakpoint originally set in template | |
6490 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
6491 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 6492 | |
2c0b251b | 6493 | static struct symtabs_and_lines |
ed0616c6 VP |
6494 | expand_line_sal_maybe (struct symtab_and_line sal) |
6495 | { | |
6496 | struct symtabs_and_lines expanded; | |
6497 | CORE_ADDR original_pc = sal.pc; | |
6498 | char *original_function = NULL; | |
6499 | int found; | |
6500 | int i; | |
6c95b8df | 6501 | struct cleanup *old_chain; |
ed0616c6 VP |
6502 | |
6503 | /* If we have explicit pc, don't expand. | |
6504 | If we have no line number, we can't expand. */ | |
6505 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
6506 | { | |
6507 | expanded.nelts = 1; | |
6508 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6509 | expanded.sals[0] = sal; | |
6510 | return expanded; | |
6511 | } | |
6512 | ||
6513 | sal.pc = 0; | |
6c95b8df PA |
6514 | |
6515 | old_chain = save_current_space_and_thread (); | |
6516 | ||
6517 | switch_to_program_space_and_thread (sal.pspace); | |
6518 | ||
ed0616c6 | 6519 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
6520 | |
6521 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 6522 | expanded = expand_line_sal (sal); |
6c95b8df | 6523 | |
ed0616c6 VP |
6524 | if (expanded.nelts == 1) |
6525 | { | |
3dba1c98 JB |
6526 | /* We had one sal, we got one sal. Return that sal, adjusting it |
6527 | past the function prologue if necessary. */ | |
ed0616c6 VP |
6528 | xfree (expanded.sals); |
6529 | expanded.nelts = 1; | |
6530 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6531 | sal.pc = original_pc; | |
6532 | expanded.sals[0] = sal; | |
3dba1c98 | 6533 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 6534 | do_cleanups (old_chain); |
ed0616c6 VP |
6535 | return expanded; |
6536 | } | |
6537 | ||
6538 | if (!sal.explicit_line) | |
6539 | { | |
6540 | CORE_ADDR func_addr, func_end; | |
6541 | for (i = 0; i < expanded.nelts; ++i) | |
6542 | { | |
6543 | CORE_ADDR pc = expanded.sals[i].pc; | |
6544 | char *this_function; | |
6c95b8df PA |
6545 | |
6546 | /* We need to switch threads as well since we're about to | |
6547 | read memory. */ | |
6548 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
6549 | ||
ed0616c6 VP |
6550 | if (find_pc_partial_function (pc, &this_function, |
6551 | &func_addr, &func_end)) | |
6552 | { | |
059fb39f PM |
6553 | if (this_function |
6554 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
6555 | { |
6556 | remove_sal (&expanded, i); | |
6557 | --i; | |
6558 | } | |
6559 | else if (func_addr == pc) | |
6560 | { | |
6561 | /* We're at beginning of a function, and should | |
6562 | skip prologue. */ | |
6563 | struct symbol *sym = find_pc_function (pc); | |
6564 | if (sym) | |
6565 | expanded.sals[i] = find_function_start_sal (sym, 1); | |
6566 | else | |
d80b854b UW |
6567 | { |
6568 | /* Since find_pc_partial_function returned true, | |
6569 | we should really always find the section here. */ | |
6570 | struct obj_section *section = find_pc_section (pc); | |
6571 | if (section) | |
6572 | { | |
6573 | struct gdbarch *gdbarch | |
6574 | = get_objfile_arch (section->objfile); | |
6575 | expanded.sals[i].pc | |
6576 | = gdbarch_skip_prologue (gdbarch, pc); | |
6577 | } | |
6578 | } | |
ed0616c6 VP |
6579 | } |
6580 | } | |
6581 | } | |
6582 | } | |
3daf8fe5 JG |
6583 | else |
6584 | { | |
6585 | for (i = 0; i < expanded.nelts; ++i) | |
6586 | { | |
6587 | /* If this SAL corresponds to a breakpoint inserted using a | |
6588 | line number, then skip the function prologue if necessary. */ | |
6589 | skip_prologue_sal (&expanded.sals[i]); | |
6590 | } | |
6591 | } | |
ed0616c6 | 6592 | |
6c95b8df PA |
6593 | do_cleanups (old_chain); |
6594 | ||
ed0616c6 VP |
6595 | if (expanded.nelts <= 1) |
6596 | { | |
6597 | /* This is un ugly workaround. If we get zero | |
6598 | expanded sals then something is really wrong. | |
6599 | Fix that by returnign the original sal. */ | |
6600 | xfree (expanded.sals); | |
6601 | expanded.nelts = 1; | |
6602 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
6603 | sal.pc = original_pc; | |
6604 | expanded.sals[0] = sal; | |
6605 | return expanded; | |
6606 | } | |
6607 | ||
6608 | if (original_pc) | |
6609 | { | |
6610 | found = 0; | |
6611 | for (i = 0; i < expanded.nelts; ++i) | |
6612 | if (expanded.sals[i].pc == original_pc) | |
6613 | { | |
6614 | found = 1; | |
6615 | break; | |
6616 | } | |
6617 | gdb_assert (found); | |
6618 | } | |
6619 | ||
6620 | return expanded; | |
6621 | } | |
6622 | ||
018d34a4 VP |
6623 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
6624 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
6625 | value. COND_STRING, if not NULL, specified the condition to be | |
6626 | used for all breakpoints. Essentially the only case where | |
6627 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
6628 | function. In that case, it's still not possible to specify | |
6629 | separate conditions for different overloaded functions, so | |
6630 | we take just a single condition string. | |
6631 | ||
c3f6f71d | 6632 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 6633 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
6634 | array contents). If the function fails (error() is called), the |
6635 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
6636 | COND and SALS arrays and each of those arrays contents. */ | |
c906108c SS |
6637 | |
6638 | static void | |
a6d9a66e UW |
6639 | create_breakpoints (struct gdbarch *gdbarch, |
6640 | struct symtabs_and_lines sals, char **addr_string, | |
018d34a4 | 6641 | char *cond_string, |
c3f6f71d | 6642 | enum bptype type, enum bpdisp disposition, |
4a306c9a | 6643 | int thread, int task, int ignore_count, |
41447f92 VP |
6644 | struct breakpoint_ops *ops, int from_tty, |
6645 | int enabled) | |
c906108c | 6646 | { |
018d34a4 VP |
6647 | int i; |
6648 | for (i = 0; i < sals.nelts; ++i) | |
c3f6f71d | 6649 | { |
ed0616c6 VP |
6650 | struct symtabs_and_lines expanded = |
6651 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 6652 | |
a6d9a66e | 6653 | create_breakpoint (gdbarch, expanded, addr_string[i], |
018d34a4 | 6654 | cond_string, type, disposition, |
4a306c9a | 6655 | thread, task, ignore_count, ops, from_tty, enabled); |
c3f6f71d | 6656 | } |
c3f6f71d | 6657 | } |
c906108c | 6658 | |
c3f6f71d JM |
6659 | /* Parse ARG which is assumed to be a SAL specification possibly |
6660 | followed by conditionals. On return, SALS contains an array of SAL | |
6661 | addresses found. ADDR_STRING contains a vector of (canonical) | |
6662 | address strings. ARG points to the end of the SAL. */ | |
c906108c | 6663 | |
b9362cc7 | 6664 | static void |
c3f6f71d JM |
6665 | parse_breakpoint_sals (char **address, |
6666 | struct symtabs_and_lines *sals, | |
0101ce28 JJ |
6667 | char ***addr_string, |
6668 | int *not_found_ptr) | |
c3f6f71d JM |
6669 | { |
6670 | char *addr_start = *address; | |
6671 | *addr_string = NULL; | |
6672 | /* If no arg given, or if first arg is 'if ', use the default | |
6673 | breakpoint. */ | |
6674 | if ((*address) == NULL | |
6675 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
6676 | { |
6677 | if (default_breakpoint_valid) | |
6678 | { | |
c3f6f71d | 6679 | struct symtab_and_line sal; |
fe39c653 | 6680 | init_sal (&sal); /* initialize to zeroes */ |
c3f6f71d | 6681 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
6682 | xmalloc (sizeof (struct symtab_and_line)); |
6683 | sal.pc = default_breakpoint_address; | |
6684 | sal.line = default_breakpoint_line; | |
6685 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 6686 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 6687 | sal.section = find_pc_overlay (sal.pc); |
00903456 JK |
6688 | |
6689 | /* "break" without arguments is equivalent to "break *PC" where PC is | |
6690 | the default_breakpoint_address. So make sure to set | |
6691 | sal.explicit_pc to prevent GDB from trying to expand the list of | |
6692 | sals to include all other instances with the same symtab and line. | |
6693 | */ | |
6694 | sal.explicit_pc = 1; | |
6695 | ||
c3f6f71d JM |
6696 | sals->sals[0] = sal; |
6697 | sals->nelts = 1; | |
c906108c SS |
6698 | } |
6699 | else | |
8a3fe4f8 | 6700 | error (_("No default breakpoint address now.")); |
c906108c SS |
6701 | } |
6702 | else | |
6703 | { | |
c906108c | 6704 | /* Force almost all breakpoints to be in terms of the |
c5aa993b JM |
6705 | current_source_symtab (which is decode_line_1's default). This |
6706 | should produce the results we want almost all of the time while | |
1aeae86e AF |
6707 | leaving default_breakpoint_* alone. |
6708 | ObjC: However, don't match an Objective-C method name which | |
6709 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 6710 | |
c214a6fd | 6711 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 6712 | |
c906108c | 6713 | if (default_breakpoint_valid |
0378c332 | 6714 | && (!cursal.symtab |
1aeae86e AF |
6715 | || ((strchr ("+-", (*address)[0]) != NULL) |
6716 | && ((*address)[1] != '[')))) | |
c3f6f71d | 6717 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
0101ce28 JJ |
6718 | default_breakpoint_line, addr_string, |
6719 | not_found_ptr); | |
c906108c | 6720 | else |
0101ce28 JJ |
6721 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
6722 | addr_string, not_found_ptr); | |
c906108c | 6723 | } |
c3f6f71d JM |
6724 | /* For any SAL that didn't have a canonical string, fill one in. */ |
6725 | if (sals->nelts > 0 && *addr_string == NULL) | |
6726 | *addr_string = xcalloc (sals->nelts, sizeof (char **)); | |
6727 | if (addr_start != (*address)) | |
c906108c | 6728 | { |
c3f6f71d JM |
6729 | int i; |
6730 | for (i = 0; i < sals->nelts; i++) | |
c906108c | 6731 | { |
c3f6f71d JM |
6732 | /* Add the string if not present. */ |
6733 | if ((*addr_string)[i] == NULL) | |
6734 | (*addr_string)[i] = savestring (addr_start, (*address) - addr_start); | |
c906108c SS |
6735 | } |
6736 | } | |
c3f6f71d | 6737 | } |
c906108c | 6738 | |
c906108c | 6739 | |
c3f6f71d JM |
6740 | /* Convert each SAL into a real PC. Verify that the PC can be |
6741 | inserted as a breakpoint. If it can't throw an error. */ | |
c906108c | 6742 | |
b9362cc7 | 6743 | static void |
c3f6f71d JM |
6744 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals, |
6745 | char *address) | |
6746 | { | |
6747 | int i; | |
6748 | for (i = 0; i < sals->nelts; i++) | |
ee53e872 | 6749 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
6750 | } |
6751 | ||
7a697b8d SS |
6752 | /* Fast tracepoints may have restrictions on valid locations. For |
6753 | instance, a fast tracepoint using a jump instead of a trap will | |
6754 | likely have to overwrite more bytes than a trap would, and so can | |
6755 | only be placed where the instruction is longer than the jump, or a | |
6756 | multi-instruction sequence does not have a jump into the middle of | |
6757 | it, etc. */ | |
6758 | ||
6759 | static void | |
6760 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
6761 | struct symtabs_and_lines *sals) | |
6762 | { | |
6763 | int i, rslt; | |
6764 | struct symtab_and_line *sal; | |
6765 | char *msg; | |
6766 | struct cleanup *old_chain; | |
6767 | ||
6768 | for (i = 0; i < sals->nelts; i++) | |
6769 | { | |
6770 | sal = &sals->sals[i]; | |
6771 | ||
6772 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
6773 | NULL, &msg); | |
6774 | old_chain = make_cleanup (xfree, msg); | |
6775 | ||
6776 | if (!rslt) | |
6777 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
6778 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
6779 | ||
6780 | do_cleanups (old_chain); | |
6781 | } | |
6782 | } | |
6783 | ||
05ff989b | 6784 | static void |
0101ce28 JJ |
6785 | do_captured_parse_breakpoint (struct ui_out *ui, void *data) |
6786 | { | |
6787 | struct captured_parse_breakpoint_args *args = data; | |
6788 | ||
6789 | parse_breakpoint_sals (args->arg_p, args->sals_p, args->addr_string_p, | |
6790 | args->not_found_ptr); | |
0101ce28 JJ |
6791 | } |
6792 | ||
018d34a4 VP |
6793 | /* Given TOK, a string specification of condition and thread, as |
6794 | accepted by the 'break' command, extract the condition | |
6795 | string and thread number and set *COND_STRING and *THREAD. | |
6796 | PC identifies the context at which the condition should be parsed. | |
6797 | If no condition is found, *COND_STRING is set to NULL. | |
6798 | If no thread is found, *THREAD is set to -1. */ | |
6799 | static void | |
6800 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 6801 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
6802 | { |
6803 | *cond_string = NULL; | |
6804 | *thread = -1; | |
6805 | while (tok && *tok) | |
6806 | { | |
6807 | char *end_tok; | |
6808 | int toklen; | |
6809 | char *cond_start = NULL; | |
6810 | char *cond_end = NULL; | |
6811 | while (*tok == ' ' || *tok == '\t') | |
6812 | tok++; | |
6813 | ||
6814 | end_tok = tok; | |
6815 | ||
6816 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
6817 | end_tok++; | |
6818 | ||
6819 | toklen = end_tok - tok; | |
6820 | ||
6821 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
6822 | { | |
f7545552 TT |
6823 | struct expression *expr; |
6824 | ||
018d34a4 | 6825 | tok = cond_start = end_tok + 1; |
f7545552 TT |
6826 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
6827 | xfree (expr); | |
018d34a4 VP |
6828 | cond_end = tok; |
6829 | *cond_string = savestring (cond_start, | |
6830 | cond_end - cond_start); | |
6831 | } | |
6832 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
6833 | { | |
6834 | char *tmptok; | |
6835 | ||
6836 | tok = end_tok + 1; | |
6837 | tmptok = tok; | |
6838 | *thread = strtol (tok, &tok, 0); | |
6839 | if (tok == tmptok) | |
6840 | error (_("Junk after thread keyword.")); | |
6841 | if (!valid_thread_id (*thread)) | |
6842 | error (_("Unknown thread %d."), *thread); | |
6843 | } | |
4a306c9a JB |
6844 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
6845 | { | |
6846 | char *tmptok; | |
6847 | ||
6848 | tok = end_tok + 1; | |
6849 | tmptok = tok; | |
6850 | *task = strtol (tok, &tok, 0); | |
6851 | if (tok == tmptok) | |
6852 | error (_("Junk after task keyword.")); | |
6853 | if (!valid_task_id (*task)) | |
b6199126 | 6854 | error (_("Unknown task %d."), *task); |
4a306c9a | 6855 | } |
018d34a4 VP |
6856 | else |
6857 | error (_("Junk at end of arguments.")); | |
6858 | } | |
6859 | } | |
6860 | ||
fd9b8c24 PA |
6861 | /* Set a breakpoint. This function is shared between CLI and MI |
6862 | functions for setting a breakpoint. This function has two major | |
6863 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
6864 | parameter. If non-zero, the function will parse arg, extracting | |
6865 | breakpoint location, address and thread. Otherwise, ARG is just the | |
6866 | location of breakpoint, with condition and thread specified by the | |
6867 | COND_STRING and THREAD parameters. Returns true if any breakpoint | |
6868 | was created; false otherwise. */ | |
0101ce28 | 6869 | |
fd9b8c24 | 6870 | static int |
a6d9a66e UW |
6871 | break_command_really (struct gdbarch *gdbarch, |
6872 | char *arg, char *cond_string, int thread, | |
60c46647 | 6873 | int parse_condition_and_thread, |
1042e4c0 | 6874 | int tempflag, int hardwareflag, int traceflag, |
60c46647 VP |
6875 | int ignore_count, |
6876 | enum auto_boolean pending_break_support, | |
604133b5 | 6877 | struct breakpoint_ops *ops, |
41447f92 VP |
6878 | int from_tty, |
6879 | int enabled) | |
c3f6f71d | 6880 | { |
71fff37b | 6881 | struct gdb_exception e; |
c3f6f71d | 6882 | struct symtabs_and_lines sals; |
0101ce28 | 6883 | struct symtab_and_line pending_sal; |
0101ce28 JJ |
6884 | char *copy_arg; |
6885 | char *err_msg; | |
c3f6f71d JM |
6886 | char *addr_start = arg; |
6887 | char **addr_string; | |
6888 | struct cleanup *old_chain; | |
80c99de1 | 6889 | struct cleanup *bkpt_chain = NULL; |
0101ce28 | 6890 | struct captured_parse_breakpoint_args parse_args; |
05ff989b | 6891 | int i; |
0101ce28 | 6892 | int pending = 0; |
0101ce28 | 6893 | int not_found = 0; |
1042e4c0 | 6894 | enum bptype type_wanted; |
4a306c9a | 6895 | int task = 0; |
c3f6f71d | 6896 | |
c3f6f71d JM |
6897 | sals.sals = NULL; |
6898 | sals.nelts = 0; | |
6899 | addr_string = NULL; | |
c3f6f71d | 6900 | |
0101ce28 JJ |
6901 | parse_args.arg_p = &arg; |
6902 | parse_args.sals_p = &sals; | |
6903 | parse_args.addr_string_p = &addr_string; | |
6904 | parse_args.not_found_ptr = ¬_found; | |
6905 | ||
05ff989b AC |
6906 | e = catch_exception (uiout, do_captured_parse_breakpoint, |
6907 | &parse_args, RETURN_MASK_ALL); | |
0101ce28 JJ |
6908 | |
6909 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 6910 | switch (e.reason) |
0101ce28 | 6911 | { |
05ff989b | 6912 | case RETURN_QUIT: |
98deb0da | 6913 | throw_exception (e); |
05ff989b AC |
6914 | case RETURN_ERROR: |
6915 | switch (e.error) | |
0101ce28 | 6916 | { |
05ff989b | 6917 | case NOT_FOUND_ERROR: |
0101ce28 | 6918 | |
05ff989b AC |
6919 | /* If pending breakpoint support is turned off, throw |
6920 | error. */ | |
fa8d40ab JJ |
6921 | |
6922 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
6923 | throw_exception (e); |
6924 | ||
6925 | exception_print (gdb_stderr, e); | |
fa8d40ab | 6926 | |
05ff989b AC |
6927 | /* If pending breakpoint support is auto query and the user |
6928 | selects no, then simply return the error code. */ | |
059fb39f PM |
6929 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
6930 | && !nquery ("Make breakpoint pending on future shared library load? ")) | |
fd9b8c24 | 6931 | return 0; |
fa8d40ab | 6932 | |
05ff989b AC |
6933 | /* At this point, either the user was queried about setting |
6934 | a pending breakpoint and selected yes, or pending | |
6935 | breakpoint behavior is on and thus a pending breakpoint | |
6936 | is defaulted on behalf of the user. */ | |
0101ce28 JJ |
6937 | copy_arg = xstrdup (addr_start); |
6938 | addr_string = ©_arg; | |
6939 | sals.nelts = 1; | |
6940 | sals.sals = &pending_sal; | |
6941 | pending_sal.pc = 0; | |
6942 | pending = 1; | |
05ff989b AC |
6943 | break; |
6944 | default: | |
98deb0da | 6945 | throw_exception (e); |
0101ce28 | 6946 | } |
05ff989b AC |
6947 | default: |
6948 | if (!sals.nelts) | |
fd9b8c24 | 6949 | return 0; |
0101ce28 | 6950 | } |
c3f6f71d JM |
6951 | |
6952 | /* Create a chain of things that always need to be cleaned up. */ | |
6953 | old_chain = make_cleanup (null_cleanup, 0); | |
6954 | ||
0101ce28 JJ |
6955 | if (!pending) |
6956 | { | |
6957 | /* Make sure that all storage allocated to SALS gets freed. */ | |
6958 | make_cleanup (xfree, sals.sals); | |
6959 | ||
6960 | /* Cleanup the addr_string array but not its contents. */ | |
6961 | make_cleanup (xfree, addr_string); | |
6962 | } | |
c3f6f71d | 6963 | |
c3f6f71d JM |
6964 | /* ----------------------------- SNIP ----------------------------- |
6965 | Anything added to the cleanup chain beyond this point is assumed | |
6966 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
6967 | then the memory is not reclaimed. */ |
6968 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d JM |
6969 | |
6970 | /* Mark the contents of the addr_string for cleanup. These go on | |
80c99de1 | 6971 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
6972 | for (i = 0; i < sals.nelts; i++) |
6973 | { | |
6974 | if (addr_string[i] != NULL) | |
b8c9b27d | 6975 | make_cleanup (xfree, addr_string[i]); |
c3f6f71d JM |
6976 | } |
6977 | ||
6978 | /* Resolve all line numbers to PC's and verify that the addresses | |
6979 | are ok for the target. */ | |
0101ce28 JJ |
6980 | if (!pending) |
6981 | breakpoint_sals_to_pc (&sals, addr_start); | |
c3f6f71d | 6982 | |
1042e4c0 | 6983 | type_wanted = (traceflag |
7a697b8d | 6984 | ? (hardwareflag ? bp_fast_tracepoint : bp_tracepoint) |
1042e4c0 SS |
6985 | : (hardwareflag ? bp_hardware_breakpoint : bp_breakpoint)); |
6986 | ||
7a697b8d SS |
6987 | /* Fast tracepoints may have additional restrictions on location. */ |
6988 | if (type_wanted == bp_fast_tracepoint) | |
6989 | check_fast_tracepoint_sals (gdbarch, &sals); | |
6990 | ||
c3f6f71d JM |
6991 | /* Verify that condition can be parsed, before setting any |
6992 | breakpoints. Allocate a separate condition expression for each | |
6993 | breakpoint. */ | |
0101ce28 | 6994 | if (!pending) |
c3f6f71d | 6995 | { |
2f069f6f | 6996 | if (parse_condition_and_thread) |
72b2ff0e VP |
6997 | { |
6998 | /* Here we only parse 'arg' to separate condition | |
6999 | from thread number, so parsing in context of first | |
7000 | sal is OK. When setting the breakpoint we'll | |
7001 | re-parse it in context of each sal. */ | |
7002 | cond_string = NULL; | |
7003 | thread = -1; | |
4a306c9a JB |
7004 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
7005 | &thread, &task); | |
72b2ff0e VP |
7006 | if (cond_string) |
7007 | make_cleanup (xfree, cond_string); | |
7008 | } | |
2f069f6f | 7009 | else |
72b2ff0e VP |
7010 | { |
7011 | /* Create a private copy of condition string. */ | |
7012 | if (cond_string) | |
7013 | { | |
7014 | cond_string = xstrdup (cond_string); | |
7015 | make_cleanup (xfree, cond_string); | |
7016 | } | |
7017 | } | |
a6d9a66e | 7018 | create_breakpoints (gdbarch, sals, addr_string, cond_string, type_wanted, |
0101ce28 | 7019 | tempflag ? disp_del : disp_donttouch, |
4a306c9a | 7020 | thread, task, ignore_count, ops, from_tty, enabled); |
c906108c | 7021 | } |
0101ce28 JJ |
7022 | else |
7023 | { | |
fe3f5fa8 | 7024 | struct symtab_and_line sal = {0}; |
0101ce28 JJ |
7025 | struct breakpoint *b; |
7026 | ||
0101ce28 JJ |
7027 | make_cleanup (xfree, copy_arg); |
7028 | ||
a6d9a66e | 7029 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
0101ce28 JJ |
7030 | set_breakpoint_count (breakpoint_count + 1); |
7031 | b->number = breakpoint_count; | |
72b2ff0e | 7032 | b->thread = -1; |
018d34a4 | 7033 | b->addr_string = addr_string[0]; |
72b2ff0e | 7034 | b->cond_string = NULL; |
0101ce28 | 7035 | b->ignore_count = ignore_count; |
0101ce28 | 7036 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 7037 | b->condition_not_parsed = 1; |
604133b5 | 7038 | b->ops = ops; |
41447f92 | 7039 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 7040 | b->pspace = current_program_space; |
74960c60 | 7041 | |
6c95b8df | 7042 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7043 | && (b->type == bp_breakpoint |
7044 | || b->type == bp_hardware_breakpoint)) | |
7045 | b->enable_state = bp_startup_disabled; | |
7046 | ||
0101ce28 JJ |
7047 | mention (b); |
7048 | } | |
7049 | ||
c3f6f71d | 7050 | if (sals.nelts > 1) |
8a3fe4f8 AC |
7051 | warning (_("Multiple breakpoints were set.\n" |
7052 | "Use the \"delete\" command to delete unwanted breakpoints.")); | |
80c99de1 PA |
7053 | /* That's it. Discard the cleanups for data inserted into the |
7054 | breakpoint. */ | |
7055 | discard_cleanups (bkpt_chain); | |
7056 | /* But cleanup everything else. */ | |
c3f6f71d | 7057 | do_cleanups (old_chain); |
217dc9e2 | 7058 | |
80c99de1 | 7059 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 7060 | update_global_location_list (1); |
fd9b8c24 PA |
7061 | |
7062 | return 1; | |
c3f6f71d | 7063 | } |
c906108c | 7064 | |
72b2ff0e VP |
7065 | /* Set a breakpoint. |
7066 | ARG is a string describing breakpoint address, | |
7067 | condition, and thread. | |
7068 | FLAG specifies if a breakpoint is hardware on, | |
7069 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
7070 | and BP_TEMPFLAG. */ | |
7071 | ||
98deb0da | 7072 | static void |
72b2ff0e | 7073 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 7074 | { |
72b2ff0e VP |
7075 | int hardwareflag = flag & BP_HARDWAREFLAG; |
7076 | int tempflag = flag & BP_TEMPFLAG; | |
c3f6f71d | 7077 | |
a6d9a66e UW |
7078 | break_command_really (get_current_arch (), |
7079 | arg, | |
98deb0da | 7080 | NULL, 0, 1 /* parse arg */, |
1042e4c0 | 7081 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da | 7082 | 0 /* Ignore count */, |
604133b5 AR |
7083 | pending_break_support, |
7084 | NULL /* breakpoint_ops */, | |
41447f92 VP |
7085 | from_tty, |
7086 | 1 /* enabled */); | |
c906108c SS |
7087 | } |
7088 | ||
72b2ff0e | 7089 | |
98deb0da | 7090 | void |
a6d9a66e UW |
7091 | set_breakpoint (struct gdbarch *gdbarch, |
7092 | char *address, char *condition, | |
c3f6f71d | 7093 | int hardwareflag, int tempflag, |
ce43223b | 7094 | int thread, int ignore_count, |
41447f92 | 7095 | int pending, int enabled) |
c3f6f71d | 7096 | { |
a6d9a66e UW |
7097 | break_command_really (gdbarch, |
7098 | address, condition, thread, | |
98deb0da | 7099 | 0 /* condition and thread are valid. */, |
1042e4c0 | 7100 | tempflag, hardwareflag, 0 /* traceflag */, |
98deb0da VP |
7101 | ignore_count, |
7102 | pending | |
7103 | ? AUTO_BOOLEAN_TRUE : AUTO_BOOLEAN_FALSE, | |
41447f92 | 7104 | NULL, 0, enabled); |
c3f6f71d JM |
7105 | } |
7106 | ||
6a048695 JB |
7107 | /* Adjust SAL to the first instruction past the function prologue. |
7108 | The end of the prologue is determined using the line table from | |
3daf8fe5 JG |
7109 | the debugging information. explicit_pc and explicit_line are |
7110 | not modified. | |
6a048695 JB |
7111 | |
7112 | If SAL is already past the prologue, then do nothing. */ | |
7113 | ||
7114 | static void | |
7115 | skip_prologue_sal (struct symtab_and_line *sal) | |
7116 | { | |
6c95b8df | 7117 | struct symbol *sym; |
6a048695 | 7118 | struct symtab_and_line start_sal; |
6c95b8df | 7119 | struct cleanup *old_chain; |
6a048695 | 7120 | |
6c95b8df | 7121 | old_chain = save_current_space_and_thread (); |
6a048695 | 7122 | |
6c95b8df PA |
7123 | sym = find_pc_function (sal->pc); |
7124 | if (sym != NULL) | |
3daf8fe5 | 7125 | { |
6c95b8df PA |
7126 | start_sal = find_function_start_sal (sym, 1); |
7127 | if (sal->pc < start_sal.pc) | |
7128 | { | |
7129 | start_sal.explicit_line = sal->explicit_line; | |
7130 | start_sal.explicit_pc = sal->explicit_pc; | |
7131 | *sal = start_sal; | |
7132 | } | |
3daf8fe5 | 7133 | } |
6c95b8df PA |
7134 | |
7135 | do_cleanups (old_chain); | |
6a048695 | 7136 | } |
c3f6f71d | 7137 | |
c906108c SS |
7138 | /* Helper function for break_command_1 and disassemble_command. */ |
7139 | ||
7140 | void | |
fba45db2 | 7141 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
7142 | { |
7143 | CORE_ADDR pc; | |
7144 | ||
7145 | if (sal->pc == 0 && sal->symtab != NULL) | |
7146 | { | |
7147 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 7148 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
7149 | sal->line, sal->symtab->filename); |
7150 | sal->pc = pc; | |
6a048695 JB |
7151 | |
7152 | /* If this SAL corresponds to a breakpoint inserted using | |
7153 | a line number, then skip the function prologue if necessary. */ | |
7154 | if (sal->explicit_line) | |
56ef84b1 TT |
7155 | { |
7156 | /* Preserve the original line number. */ | |
7157 | int saved_line = sal->line; | |
7158 | skip_prologue_sal (sal); | |
7159 | sal->line = saved_line; | |
7160 | } | |
c906108c SS |
7161 | } |
7162 | ||
7163 | if (sal->section == 0 && sal->symtab != NULL) | |
7164 | { | |
7165 | struct blockvector *bv; | |
c5aa993b JM |
7166 | struct block *b; |
7167 | struct symbol *sym; | |
c906108c | 7168 | |
801e3a5b | 7169 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
7170 | if (bv != NULL) |
7171 | { | |
7f0df278 | 7172 | sym = block_linkage_function (b); |
c906108c SS |
7173 | if (sym != NULL) |
7174 | { | |
7175 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 7176 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
7177 | } |
7178 | else | |
7179 | { | |
7180 | /* It really is worthwhile to have the section, so we'll just | |
c5aa993b JM |
7181 | have to look harder. This case can be executed if we have |
7182 | line numbers but no functions (as can happen in assembly | |
7183 | source). */ | |
c906108c | 7184 | |
c5aa993b | 7185 | struct minimal_symbol *msym; |
6c95b8df PA |
7186 | struct cleanup *old_chain = save_current_space_and_thread (); |
7187 | ||
7188 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
7189 | |
7190 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
7191 | if (msym) | |
714835d5 | 7192 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
7193 | |
7194 | do_cleanups (old_chain); | |
c906108c SS |
7195 | } |
7196 | } | |
7197 | } | |
7198 | } | |
7199 | ||
7200 | void | |
fba45db2 | 7201 | break_command (char *arg, int from_tty) |
c906108c | 7202 | { |
db107f19 | 7203 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7204 | } |
7205 | ||
c906108c | 7206 | void |
fba45db2 | 7207 | tbreak_command (char *arg, int from_tty) |
c906108c | 7208 | { |
db107f19 | 7209 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
7210 | } |
7211 | ||
c906108c | 7212 | static void |
fba45db2 | 7213 | hbreak_command (char *arg, int from_tty) |
c906108c | 7214 | { |
db107f19 | 7215 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
7216 | } |
7217 | ||
7218 | static void | |
fba45db2 | 7219 | thbreak_command (char *arg, int from_tty) |
c906108c | 7220 | { |
db107f19 | 7221 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
7222 | } |
7223 | ||
7224 | static void | |
fba45db2 | 7225 | stop_command (char *arg, int from_tty) |
c906108c | 7226 | { |
a3f17187 | 7227 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 7228 | Usage: stop in <function | address>\n\ |
a3f17187 | 7229 | stop at <line>\n")); |
c906108c SS |
7230 | } |
7231 | ||
7232 | static void | |
fba45db2 | 7233 | stopin_command (char *arg, int from_tty) |
c906108c SS |
7234 | { |
7235 | int badInput = 0; | |
7236 | ||
c5aa993b | 7237 | if (arg == (char *) NULL) |
c906108c SS |
7238 | badInput = 1; |
7239 | else if (*arg != '*') | |
7240 | { | |
7241 | char *argptr = arg; | |
7242 | int hasColon = 0; | |
7243 | ||
53a5351d JM |
7244 | /* look for a ':'. If this is a line number specification, then |
7245 | say it is bad, otherwise, it should be an address or | |
7246 | function/method name */ | |
c906108c | 7247 | while (*argptr && !hasColon) |
c5aa993b JM |
7248 | { |
7249 | hasColon = (*argptr == ':'); | |
7250 | argptr++; | |
7251 | } | |
c906108c SS |
7252 | |
7253 | if (hasColon) | |
c5aa993b | 7254 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 7255 | else |
c5aa993b | 7256 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
7257 | } |
7258 | ||
7259 | if (badInput) | |
a3f17187 | 7260 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 7261 | else |
db107f19 | 7262 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7263 | } |
7264 | ||
7265 | static void | |
fba45db2 | 7266 | stopat_command (char *arg, int from_tty) |
c906108c SS |
7267 | { |
7268 | int badInput = 0; | |
7269 | ||
c5aa993b | 7270 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
7271 | badInput = 1; |
7272 | else | |
7273 | { | |
7274 | char *argptr = arg; | |
7275 | int hasColon = 0; | |
7276 | ||
7277 | /* look for a ':'. If there is a '::' then get out, otherwise | |
c5aa993b | 7278 | it is probably a line number. */ |
c906108c | 7279 | while (*argptr && !hasColon) |
c5aa993b JM |
7280 | { |
7281 | hasColon = (*argptr == ':'); | |
7282 | argptr++; | |
7283 | } | |
c906108c SS |
7284 | |
7285 | if (hasColon) | |
c5aa993b | 7286 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 7287 | else |
c5aa993b | 7288 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
7289 | } |
7290 | ||
7291 | if (badInput) | |
a3f17187 | 7292 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 7293 | else |
db107f19 | 7294 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
7295 | } |
7296 | ||
53a5351d JM |
7297 | /* accessflag: hw_write: watch write, |
7298 | hw_read: watch read, | |
7299 | hw_access: watch access (read or write) */ | |
c906108c | 7300 | static void |
fba45db2 | 7301 | watch_command_1 (char *arg, int accessflag, int from_tty) |
c906108c | 7302 | { |
a6d9a66e | 7303 | struct gdbarch *gdbarch = get_current_arch (); |
d983da9c | 7304 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c SS |
7305 | struct expression *exp; |
7306 | struct block *exp_valid_block; | |
7307 | struct value *val, *mark; | |
7308 | struct frame_info *frame; | |
c906108c SS |
7309 | char *exp_start = NULL; |
7310 | char *exp_end = NULL; | |
37e4754d | 7311 | char *tok, *id_tok_start, *end_tok; |
c906108c SS |
7312 | int toklen; |
7313 | char *cond_start = NULL; | |
7314 | char *cond_end = NULL; | |
c906108c SS |
7315 | int i, other_type_used, target_resources_ok = 0; |
7316 | enum bptype bp_type; | |
7317 | int mem_cnt = 0; | |
37e4754d | 7318 | int thread = -1; |
c906108c | 7319 | |
37e4754d LM |
7320 | /* Make sure that we actually have parameters to parse. */ |
7321 | if (arg != NULL && arg[0] != '\0') | |
7322 | { | |
7323 | toklen = strlen (arg); /* Size of argument list. */ | |
7324 | ||
7325 | /* Points tok to the end of the argument list. */ | |
7326 | tok = arg + toklen - 1; | |
7327 | ||
7328 | /* Go backwards in the parameters list. Skip the last parameter. | |
7329 | If we're expecting a 'thread <thread_num>' parameter, this should | |
7330 | be the thread identifier. */ | |
7331 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7332 | tok--; | |
7333 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7334 | tok--; | |
7335 | ||
7336 | /* Points end_tok to the beginning of the last token. */ | |
7337 | id_tok_start = tok + 1; | |
7338 | ||
7339 | /* Go backwards in the parameters list. Skip one more parameter. | |
7340 | If we're expecting a 'thread <thread_num>' parameter, we should | |
7341 | reach a "thread" token. */ | |
7342 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
7343 | tok--; | |
7344 | ||
7345 | end_tok = tok; | |
7346 | ||
7347 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
7348 | tok--; | |
7349 | ||
7350 | /* Move the pointer forward to skip the whitespace and | |
7351 | calculate the length of the token. */ | |
7352 | tok++; | |
7353 | toklen = end_tok - tok; | |
7354 | ||
7355 | if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7356 | { | |
7357 | /* At this point we've found a "thread" token, which means | |
7358 | the user is trying to set a watchpoint that triggers | |
7359 | only in a specific thread. */ | |
7360 | char *endp; | |
7361 | ||
7362 | /* Extract the thread ID from the next token. */ | |
7363 | thread = strtol (id_tok_start, &endp, 0); | |
7364 | ||
7365 | /* Check if the user provided a valid numeric value for the | |
7366 | thread ID. */ | |
7367 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
7368 | error (_("Invalid thread ID specification %s."), id_tok_start); | |
7369 | ||
7370 | /* Check if the thread actually exists. */ | |
7371 | if (!valid_thread_id (thread)) | |
7372 | error (_("Unknown thread %d."), thread); | |
7373 | ||
7374 | /* Truncate the string and get rid of the thread <thread_num> | |
7375 | parameter before the parameter list is parsed by the | |
7376 | evaluate_expression() function. */ | |
7377 | *tok = '\0'; | |
7378 | } | |
7379 | } | |
7380 | ||
7381 | /* Parse the rest of the arguments. */ | |
c906108c SS |
7382 | innermost_block = NULL; |
7383 | exp_start = arg; | |
7384 | exp = parse_exp_1 (&arg, 0, 0); | |
7385 | exp_end = arg; | |
fa8a61dc TT |
7386 | /* Remove trailing whitespace from the expression before saving it. |
7387 | This makes the eventual display of the expression string a bit | |
7388 | prettier. */ | |
7389 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
7390 | --exp_end; | |
7391 | ||
c906108c SS |
7392 | exp_valid_block = innermost_block; |
7393 | mark = value_mark (); | |
fa4727a6 DJ |
7394 | fetch_watchpoint_value (exp, &val, NULL, NULL); |
7395 | if (val != NULL) | |
7396 | release_value (val); | |
c906108c SS |
7397 | |
7398 | tok = arg; | |
7399 | while (*tok == ' ' || *tok == '\t') | |
7400 | tok++; | |
7401 | end_tok = tok; | |
7402 | ||
7403 | while (*end_tok != ' ' && *end_tok != '\t' && *end_tok != '\000') | |
7404 | end_tok++; | |
7405 | ||
7406 | toklen = end_tok - tok; | |
7407 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7408 | { | |
2d134ed3 PA |
7409 | struct expression *cond; |
7410 | ||
c906108c SS |
7411 | tok = cond_start = end_tok + 1; |
7412 | cond = parse_exp_1 (&tok, 0, 0); | |
2d134ed3 | 7413 | xfree (cond); |
c906108c SS |
7414 | cond_end = tok; |
7415 | } | |
7416 | if (*tok) | |
8a3fe4f8 | 7417 | error (_("Junk at end of command.")); |
c906108c | 7418 | |
53a5351d | 7419 | if (accessflag == hw_read) |
c5aa993b | 7420 | bp_type = bp_read_watchpoint; |
53a5351d | 7421 | else if (accessflag == hw_access) |
c5aa993b JM |
7422 | bp_type = bp_access_watchpoint; |
7423 | else | |
7424 | bp_type = bp_hardware_watchpoint; | |
c906108c SS |
7425 | |
7426 | mem_cnt = can_use_hardware_watchpoint (val); | |
7427 | if (mem_cnt == 0 && bp_type != bp_hardware_watchpoint) | |
8a3fe4f8 | 7428 | error (_("Expression cannot be implemented with read/access watchpoint.")); |
c5aa993b JM |
7429 | if (mem_cnt != 0) |
7430 | { | |
7431 | i = hw_watchpoint_used_count (bp_type, &other_type_used); | |
53a5351d | 7432 | target_resources_ok = |
d92524f1 | 7433 | target_can_use_hardware_watchpoint (bp_type, i + mem_cnt, |
53a5351d | 7434 | other_type_used); |
c5aa993b | 7435 | if (target_resources_ok == 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7436 | error (_("Target does not support this type of hardware watchpoint.")); |
53a5351d | 7437 | |
c5aa993b | 7438 | if (target_resources_ok < 0 && bp_type != bp_hardware_watchpoint) |
8a3fe4f8 | 7439 | error (_("Target can only support one kind of HW watchpoint at a time.")); |
c5aa993b | 7440 | } |
c906108c | 7441 | |
4d28f7a8 KB |
7442 | /* Change the type of breakpoint to an ordinary watchpoint if a hardware |
7443 | watchpoint could not be set. */ | |
7444 | if (!mem_cnt || target_resources_ok <= 0) | |
7445 | bp_type = bp_watchpoint; | |
7446 | ||
d983da9c | 7447 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
7448 | |
7449 | /* If the expression is "local", then set up a "watchpoint scope" | |
7450 | breakpoint at the point where we've left the scope of the watchpoint | |
7451 | expression. Create the scope breakpoint before the watchpoint, so | |
7452 | that we will encounter it first in bpstat_stop_status. */ | |
edb3359d | 7453 | if (innermost_block && frame) |
d983da9c | 7454 | { |
edb3359d DJ |
7455 | if (frame_id_p (frame_unwind_caller_id (frame))) |
7456 | { | |
7457 | scope_breakpoint | |
a6d9a66e UW |
7458 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
7459 | frame_unwind_caller_pc (frame), | |
edb3359d | 7460 | bp_watchpoint_scope); |
d983da9c | 7461 | |
edb3359d | 7462 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 7463 | |
edb3359d DJ |
7464 | /* Automatically delete the breakpoint when it hits. */ |
7465 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 7466 | |
edb3359d DJ |
7467 | /* Only break in the proper frame (help with recursion). */ |
7468 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 7469 | |
edb3359d | 7470 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
7471 | scope_breakpoint->loc->gdbarch |
7472 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
7473 | scope_breakpoint->loc->requested_address |
7474 | = frame_unwind_caller_pc (frame); | |
7475 | scope_breakpoint->loc->address | |
a6d9a66e UW |
7476 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
7477 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
7478 | scope_breakpoint->type); |
7479 | } | |
d983da9c DJ |
7480 | } |
7481 | ||
c906108c | 7482 | /* Now set up the breakpoint. */ |
2d134ed3 | 7483 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
c906108c SS |
7484 | set_breakpoint_count (breakpoint_count + 1); |
7485 | b->number = breakpoint_count; | |
37e4754d | 7486 | b->thread = thread; |
b5de0fa7 | 7487 | b->disposition = disp_donttouch; |
c906108c SS |
7488 | b->exp = exp; |
7489 | b->exp_valid_block = exp_valid_block; | |
7490 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
7491 | b->val = val; | |
fa4727a6 | 7492 | b->val_valid = 1; |
c906108c SS |
7493 | if (cond_start) |
7494 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
7495 | else | |
7496 | b->cond_string = 0; | |
c5aa993b | 7497 | |
c906108c | 7498 | if (frame) |
f6bc2008 PA |
7499 | { |
7500 | b->watchpoint_frame = get_frame_id (frame); | |
7501 | b->watchpoint_thread = inferior_ptid; | |
7502 | } | |
c906108c | 7503 | else |
f6bc2008 PA |
7504 | { |
7505 | b->watchpoint_frame = null_frame_id; | |
7506 | b->watchpoint_thread = null_ptid; | |
7507 | } | |
c906108c | 7508 | |
d983da9c | 7509 | if (scope_breakpoint != NULL) |
c906108c | 7510 | { |
d983da9c DJ |
7511 | /* The scope breakpoint is related to the watchpoint. We will |
7512 | need to act on them together. */ | |
7513 | b->related_breakpoint = scope_breakpoint; | |
7514 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 7515 | } |
d983da9c | 7516 | |
c906108c | 7517 | value_free_to_mark (mark); |
2d134ed3 PA |
7518 | |
7519 | /* Finally update the new watchpoint. This creates the locations | |
7520 | that should be inserted. */ | |
7521 | update_watchpoint (b, 1); | |
7522 | ||
c906108c | 7523 | mention (b); |
b60e7edf | 7524 | update_global_location_list (1); |
c906108c SS |
7525 | } |
7526 | ||
7527 | /* Return count of locations need to be watched and can be handled | |
7528 | in hardware. If the watchpoint can not be handled | |
7529 | in hardware return zero. */ | |
7530 | ||
c906108c | 7531 | static int |
fba45db2 | 7532 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
7533 | { |
7534 | int found_memory_cnt = 0; | |
2e70b7b9 | 7535 | struct value *head = v; |
c906108c SS |
7536 | |
7537 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 7538 | if (!can_use_hw_watchpoints) |
c906108c | 7539 | return 0; |
c5aa993b | 7540 | |
5c44784c JM |
7541 | /* Make sure that the value of the expression depends only upon |
7542 | memory contents, and values computed from them within GDB. If we | |
7543 | find any register references or function calls, we can't use a | |
7544 | hardware watchpoint. | |
7545 | ||
7546 | The idea here is that evaluating an expression generates a series | |
7547 | of values, one holding the value of every subexpression. (The | |
7548 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
7549 | a*b+c.) GDB's values hold almost enough information to establish | |
7550 | the criteria given above --- they identify memory lvalues, | |
7551 | register lvalues, computed values, etcetera. So we can evaluate | |
7552 | the expression, and then scan the chain of values that leaves | |
7553 | behind to decide whether we can detect any possible change to the | |
7554 | expression's final value using only hardware watchpoints. | |
7555 | ||
7556 | However, I don't think that the values returned by inferior | |
7557 | function calls are special in any way. So this function may not | |
7558 | notice that an expression involving an inferior function call | |
7559 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 7560 | for (; v; v = value_next (v)) |
c906108c | 7561 | { |
5c44784c | 7562 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 7563 | { |
d69fe07e | 7564 | if (value_lazy (v)) |
5c44784c JM |
7565 | /* A lazy memory lvalue is one that GDB never needed to fetch; |
7566 | we either just used its address (e.g., `a' in `a.b') or | |
7567 | we never needed it at all (e.g., `a' in `a,b'). */ | |
7568 | ; | |
53a5351d | 7569 | else |
5c44784c JM |
7570 | { |
7571 | /* Ahh, memory we actually used! Check if we can cover | |
7572 | it with hardware watchpoints. */ | |
df407dfe | 7573 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
7574 | |
7575 | /* We only watch structs and arrays if user asked for it | |
7576 | explicitly, never if they just happen to appear in a | |
7577 | middle of some value chain. */ | |
7578 | if (v == head | |
7579 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
7580 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
7581 | { | |
42ae5230 | 7582 | CORE_ADDR vaddr = value_address (v); |
df407dfe | 7583 | int len = TYPE_LENGTH (value_type (v)); |
2e70b7b9 | 7584 | |
d92524f1 | 7585 | if (!target_region_ok_for_hw_watchpoint (vaddr, len)) |
2e70b7b9 MS |
7586 | return 0; |
7587 | else | |
7588 | found_memory_cnt++; | |
7589 | } | |
5c44784c | 7590 | } |
c5aa993b | 7591 | } |
5086187c AC |
7592 | else if (VALUE_LVAL (v) != not_lval |
7593 | && deprecated_value_modifiable (v) == 0) | |
53a5351d | 7594 | return 0; /* ??? What does this represent? */ |
5086187c | 7595 | else if (VALUE_LVAL (v) == lval_register) |
53a5351d | 7596 | return 0; /* cannot watch a register with a HW watchpoint */ |
c906108c SS |
7597 | } |
7598 | ||
7599 | /* The expression itself looks suitable for using a hardware | |
7600 | watchpoint, but give the target machine a chance to reject it. */ | |
7601 | return found_memory_cnt; | |
7602 | } | |
7603 | ||
8b93c638 | 7604 | void |
fba45db2 | 7605 | watch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7606 | { |
7607 | watch_command (arg, from_tty); | |
7608 | } | |
8926118c | 7609 | |
c5aa993b | 7610 | static void |
fba45db2 | 7611 | watch_command (char *arg, int from_tty) |
c906108c | 7612 | { |
53a5351d | 7613 | watch_command_1 (arg, hw_write, from_tty); |
c906108c SS |
7614 | } |
7615 | ||
8b93c638 | 7616 | void |
fba45db2 | 7617 | rwatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7618 | { |
7619 | rwatch_command (arg, from_tty); | |
7620 | } | |
8926118c | 7621 | |
c5aa993b | 7622 | static void |
fba45db2 | 7623 | rwatch_command (char *arg, int from_tty) |
c906108c | 7624 | { |
53a5351d | 7625 | watch_command_1 (arg, hw_read, from_tty); |
c906108c SS |
7626 | } |
7627 | ||
8b93c638 | 7628 | void |
fba45db2 | 7629 | awatch_command_wrapper (char *arg, int from_tty) |
8b93c638 JM |
7630 | { |
7631 | awatch_command (arg, from_tty); | |
7632 | } | |
8926118c | 7633 | |
c5aa993b | 7634 | static void |
fba45db2 | 7635 | awatch_command (char *arg, int from_tty) |
c906108c | 7636 | { |
53a5351d | 7637 | watch_command_1 (arg, hw_access, from_tty); |
c906108c | 7638 | } |
c906108c | 7639 | \f |
c5aa993b | 7640 | |
43ff13b4 | 7641 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
7642 | because it uses the mechanisms of breakpoints. */ |
7643 | ||
bfec99b2 PA |
7644 | struct until_break_command_continuation_args |
7645 | { | |
7646 | struct breakpoint *breakpoint; | |
7647 | struct breakpoint *breakpoint2; | |
7648 | }; | |
7649 | ||
43ff13b4 JM |
7650 | /* This function is called by fetch_inferior_event via the |
7651 | cmd_continuation pointer, to complete the until command. It takes | |
7652 | care of cleaning up the temporary breakpoints set up by the until | |
7653 | command. */ | |
c2c6d25f | 7654 | static void |
604ead4a | 7655 | until_break_command_continuation (void *arg) |
43ff13b4 | 7656 | { |
bfec99b2 PA |
7657 | struct until_break_command_continuation_args *a = arg; |
7658 | ||
7659 | delete_breakpoint (a->breakpoint); | |
7660 | if (a->breakpoint2) | |
7661 | delete_breakpoint (a->breakpoint2); | |
43ff13b4 JM |
7662 | } |
7663 | ||
c906108c | 7664 | void |
ae66c1fc | 7665 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
7666 | { |
7667 | struct symtabs_and_lines sals; | |
7668 | struct symtab_and_line sal; | |
206415a3 | 7669 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 7670 | struct breakpoint *breakpoint; |
f107f563 | 7671 | struct breakpoint *breakpoint2 = NULL; |
c906108c SS |
7672 | struct cleanup *old_chain; |
7673 | ||
7674 | clear_proceed_status (); | |
7675 | ||
7676 | /* Set a breakpoint where the user wants it and at return from | |
7677 | this function */ | |
c5aa993b | 7678 | |
c906108c SS |
7679 | if (default_breakpoint_valid) |
7680 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
68219205 | 7681 | default_breakpoint_line, (char ***) NULL, NULL); |
c906108c | 7682 | else |
53a5351d | 7683 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, |
68219205 | 7684 | 0, (char ***) NULL, NULL); |
c5aa993b | 7685 | |
c906108c | 7686 | if (sals.nelts != 1) |
8a3fe4f8 | 7687 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 7688 | |
c906108c | 7689 | sal = sals.sals[0]; |
b8c9b27d | 7690 | xfree (sals.sals); /* malloc'd, so freed */ |
c5aa993b | 7691 | |
c906108c | 7692 | if (*arg) |
8a3fe4f8 | 7693 | error (_("Junk at end of arguments.")); |
c5aa993b | 7694 | |
c906108c | 7695 | resolve_sal_pc (&sal); |
c5aa993b | 7696 | |
ae66c1fc EZ |
7697 | if (anywhere) |
7698 | /* If the user told us to continue until a specified location, | |
7699 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
7700 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7701 | null_frame_id, bp_until); | |
ae66c1fc | 7702 | else |
edb3359d | 7703 | /* Otherwise, specify the selected frame, because we want to stop only |
ae66c1fc | 7704 | at the very same frame. */ |
a6d9a66e UW |
7705 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
7706 | get_stack_frame_id (frame), | |
ae66c1fc | 7707 | bp_until); |
c5aa993b | 7708 | |
f107f563 | 7709 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 7710 | |
ae66c1fc EZ |
7711 | /* Keep within the current frame, or in frames called by the current |
7712 | one. */ | |
edb3359d DJ |
7713 | |
7714 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 7715 | { |
edb3359d DJ |
7716 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
7717 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
7718 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
7719 | sal, | |
edb3359d | 7720 | frame_unwind_caller_id (frame), |
f107f563 VP |
7721 | bp_until); |
7722 | make_cleanup_delete_breakpoint (breakpoint2); | |
c906108c | 7723 | } |
c5aa993b | 7724 | |
c906108c | 7725 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 VP |
7726 | |
7727 | /* If we are running asynchronously, and proceed call above has actually | |
7728 | managed to start the target, arrange for breakpoints to be | |
7729 | deleted when the target stops. Otherwise, we're already stopped and | |
7730 | delete breakpoints via cleanup chain. */ | |
7731 | ||
8ea051c5 | 7732 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 7733 | { |
bfec99b2 PA |
7734 | struct until_break_command_continuation_args *args; |
7735 | args = xmalloc (sizeof (*args)); | |
f107f563 | 7736 | |
bfec99b2 PA |
7737 | args->breakpoint = breakpoint; |
7738 | args->breakpoint2 = breakpoint2; | |
f107f563 VP |
7739 | |
7740 | discard_cleanups (old_chain); | |
95e54da7 PA |
7741 | add_continuation (inferior_thread (), |
7742 | until_break_command_continuation, args, | |
604ead4a | 7743 | xfree); |
f107f563 VP |
7744 | } |
7745 | else | |
c5aa993b | 7746 | do_cleanups (old_chain); |
c906108c | 7747 | } |
ae66c1fc | 7748 | |
c906108c | 7749 | static void |
fba45db2 | 7750 | ep_skip_leading_whitespace (char **s) |
c906108c | 7751 | { |
c5aa993b JM |
7752 | if ((s == NULL) || (*s == NULL)) |
7753 | return; | |
7754 | while (isspace (**s)) | |
7755 | *s += 1; | |
c906108c | 7756 | } |
c5aa993b | 7757 | |
c906108c SS |
7758 | /* This function attempts to parse an optional "if <cond>" clause |
7759 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 7760 | |
c906108c SS |
7761 | Else, it returns a pointer to the condition string. (It does not |
7762 | attempt to evaluate the string against a particular block.) And, | |
7763 | it updates arg to point to the first character following the parsed | |
7764 | if clause in the arg string. */ | |
53a5351d | 7765 | |
c906108c | 7766 | static char * |
fba45db2 | 7767 | ep_parse_optional_if_clause (char **arg) |
c906108c | 7768 | { |
c5aa993b JM |
7769 | char *cond_string; |
7770 | ||
7771 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 7772 | return NULL; |
c5aa993b | 7773 | |
c906108c SS |
7774 | /* Skip the "if" keyword. */ |
7775 | (*arg) += 2; | |
c5aa993b | 7776 | |
c906108c SS |
7777 | /* Skip any extra leading whitespace, and record the start of the |
7778 | condition string. */ | |
7779 | ep_skip_leading_whitespace (arg); | |
7780 | cond_string = *arg; | |
c5aa993b | 7781 | |
c906108c SS |
7782 | /* Assume that the condition occupies the remainder of the arg string. */ |
7783 | (*arg) += strlen (cond_string); | |
c5aa993b | 7784 | |
c906108c SS |
7785 | return cond_string; |
7786 | } | |
c5aa993b | 7787 | |
c906108c SS |
7788 | /* Commands to deal with catching events, such as signals, exceptions, |
7789 | process start/exit, etc. */ | |
c5aa993b JM |
7790 | |
7791 | typedef enum | |
7792 | { | |
44feb3ce TT |
7793 | catch_fork_temporary, catch_vfork_temporary, |
7794 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
7795 | } |
7796 | catch_fork_kind; | |
7797 | ||
c906108c | 7798 | static void |
44feb3ce | 7799 | catch_fork_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7800 | { |
a6d9a66e | 7801 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 7802 | char *cond_string = NULL; |
44feb3ce TT |
7803 | catch_fork_kind fork_kind; |
7804 | int tempflag; | |
7805 | ||
7806 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
7807 | tempflag = (fork_kind == catch_fork_temporary | |
7808 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 7809 | |
44feb3ce TT |
7810 | if (!arg) |
7811 | arg = ""; | |
c906108c | 7812 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7813 | |
c906108c | 7814 | /* The allowed syntax is: |
c5aa993b JM |
7815 | catch [v]fork |
7816 | catch [v]fork if <cond> | |
7817 | ||
c906108c SS |
7818 | First, check if there's an if clause. */ |
7819 | cond_string = ep_parse_optional_if_clause (&arg); | |
c5aa993b | 7820 | |
c906108c | 7821 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 7822 | error (_("Junk at end of arguments.")); |
c5aa993b | 7823 | |
c906108c SS |
7824 | /* If this target supports it, create a fork or vfork catchpoint |
7825 | and enable reporting of such events. */ | |
c5aa993b JM |
7826 | switch (fork_kind) |
7827 | { | |
44feb3ce TT |
7828 | case catch_fork_temporary: |
7829 | case catch_fork_permanent: | |
a6d9a66e | 7830 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7831 | &catch_fork_breakpoint_ops); |
c906108c | 7832 | break; |
44feb3ce TT |
7833 | case catch_vfork_temporary: |
7834 | case catch_vfork_permanent: | |
a6d9a66e | 7835 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 7836 | &catch_vfork_breakpoint_ops); |
c906108c | 7837 | break; |
c5aa993b | 7838 | default: |
8a3fe4f8 | 7839 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 7840 | break; |
c5aa993b | 7841 | } |
c906108c SS |
7842 | } |
7843 | ||
7844 | static void | |
44feb3ce | 7845 | catch_exec_command_1 (char *arg, int from_tty, struct cmd_list_element *command) |
c906108c | 7846 | { |
a6d9a66e | 7847 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 7848 | int tempflag; |
c5aa993b | 7849 | char *cond_string = NULL; |
c906108c | 7850 | |
44feb3ce TT |
7851 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
7852 | ||
7853 | if (!arg) | |
7854 | arg = ""; | |
c906108c SS |
7855 | ep_skip_leading_whitespace (&arg); |
7856 | ||
7857 | /* The allowed syntax is: | |
c5aa993b JM |
7858 | catch exec |
7859 | catch exec if <cond> | |
c906108c SS |
7860 | |
7861 | First, check if there's an if clause. */ | |
7862 | cond_string = ep_parse_optional_if_clause (&arg); | |
7863 | ||
7864 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7865 | error (_("Junk at end of arguments.")); |
c906108c SS |
7866 | |
7867 | /* If this target supports it, create an exec catchpoint | |
7868 | and enable reporting of such events. */ | |
a6d9a66e UW |
7869 | create_catchpoint (gdbarch, tempflag, cond_string, |
7870 | &catch_exec_breakpoint_ops); | |
c906108c | 7871 | } |
c5aa993b | 7872 | |
3086aeae DJ |
7873 | static enum print_stop_action |
7874 | print_exception_catchpoint (struct breakpoint *b) | |
7875 | { | |
ade92717 | 7876 | int bp_temp, bp_throw; |
3086aeae | 7877 | |
ade92717 | 7878 | annotate_catchpoint (b->number); |
3086aeae | 7879 | |
ade92717 AR |
7880 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7881 | if (b->loc->address != b->loc->requested_address) | |
7882 | breakpoint_adjustment_warning (b->loc->requested_address, | |
7883 | b->loc->address, | |
7884 | b->number, 1); | |
df2b6d2d | 7885 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7886 | ui_out_text (uiout, |
7887 | bp_temp ? "Temporary catchpoint " | |
7888 | : "Catchpoint "); | |
7889 | if (!ui_out_is_mi_like_p (uiout)) | |
7890 | ui_out_field_int (uiout, "bkptno", b->number); | |
7891 | ui_out_text (uiout, | |
c0b37c48 AR |
7892 | bp_throw ? " (exception thrown), " |
7893 | : " (exception caught), "); | |
ade92717 AR |
7894 | if (ui_out_is_mi_like_p (uiout)) |
7895 | { | |
7896 | ui_out_field_string (uiout, "reason", | |
7897 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
7898 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
7899 | ui_out_field_int (uiout, "bkptno", b->number); | |
7900 | } | |
3086aeae DJ |
7901 | return PRINT_SRC_AND_LOC; |
7902 | } | |
7903 | ||
7904 | static void | |
a6d9a66e | 7905 | print_one_exception_catchpoint (struct breakpoint *b, struct bp_location **last_loc) |
3086aeae | 7906 | { |
79a45b7d TT |
7907 | struct value_print_options opts; |
7908 | get_user_print_options (&opts); | |
7909 | if (opts.addressprint) | |
3086aeae DJ |
7910 | { |
7911 | annotate_field (4); | |
604133b5 AR |
7912 | if (b->loc == NULL || b->loc->shlib_disabled) |
7913 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
7914 | else | |
5af949e3 UW |
7915 | ui_out_field_core_addr (uiout, "addr", |
7916 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
7917 | } |
7918 | annotate_field (5); | |
604133b5 | 7919 | if (b->loc) |
a6d9a66e | 7920 | *last_loc = b->loc; |
3086aeae DJ |
7921 | if (strstr (b->addr_string, "throw") != NULL) |
7922 | ui_out_field_string (uiout, "what", "exception throw"); | |
7923 | else | |
7924 | ui_out_field_string (uiout, "what", "exception catch"); | |
7925 | } | |
7926 | ||
7927 | static void | |
7928 | print_mention_exception_catchpoint (struct breakpoint *b) | |
7929 | { | |
ade92717 AR |
7930 | int bp_temp; |
7931 | int bp_throw; | |
7932 | ||
df2b6d2d | 7933 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
7934 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
7935 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
7936 | : _("Catchpoint ")); | |
7937 | ui_out_field_int (uiout, "bkptno", b->number); | |
7938 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
7939 | : _(" (catch)")); | |
3086aeae DJ |
7940 | } |
7941 | ||
7942 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { | |
ce78b96d JB |
7943 | NULL, /* insert */ |
7944 | NULL, /* remove */ | |
7945 | NULL, /* breakpoint_hit */ | |
3086aeae DJ |
7946 | print_exception_catchpoint, |
7947 | print_one_exception_catchpoint, | |
7948 | print_mention_exception_catchpoint | |
7949 | }; | |
7950 | ||
7951 | static int | |
7952 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
7953 | enum exception_event_kind ex_event, int from_tty) | |
7954 | { | |
604133b5 AR |
7955 | char *trigger_func_name; |
7956 | ||
3086aeae | 7957 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 7958 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 7959 | else |
604133b5 | 7960 | trigger_func_name = "__cxa_throw"; |
3086aeae | 7961 | |
a6d9a66e UW |
7962 | break_command_really (get_current_arch (), |
7963 | trigger_func_name, cond_string, -1, | |
604133b5 | 7964 | 0 /* condition and thread are valid. */, |
1042e4c0 | 7965 | tempflag, 0, 0, |
604133b5 AR |
7966 | 0, |
7967 | AUTO_BOOLEAN_TRUE /* pending */, | |
41447f92 VP |
7968 | &gnu_v3_exception_catchpoint_ops, from_tty, |
7969 | 1 /* enabled */); | |
3086aeae | 7970 | |
3086aeae DJ |
7971 | return 1; |
7972 | } | |
7973 | ||
c5aa993b | 7974 | /* Deal with "catch catch" and "catch throw" commands */ |
c906108c SS |
7975 | |
7976 | static void | |
fba45db2 KB |
7977 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
7978 | int tempflag, int from_tty) | |
c906108c | 7979 | { |
c5aa993b JM |
7980 | char *cond_string = NULL; |
7981 | struct symtab_and_line *sal = NULL; | |
7982 | ||
44feb3ce TT |
7983 | if (!arg) |
7984 | arg = ""; | |
c906108c | 7985 | ep_skip_leading_whitespace (&arg); |
c5aa993b | 7986 | |
c906108c SS |
7987 | cond_string = ep_parse_optional_if_clause (&arg); |
7988 | ||
7989 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 7990 | error (_("Junk at end of arguments.")); |
c906108c | 7991 | |
059fb39f PM |
7992 | if (ex_event != EX_EVENT_THROW |
7993 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 7994 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 7995 | |
3086aeae DJ |
7996 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
7997 | return; | |
7998 | ||
8a3fe4f8 | 7999 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
8000 | } |
8001 | ||
44feb3ce TT |
8002 | /* Implementation of "catch catch" command. */ |
8003 | ||
8004 | static void | |
8005 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8006 | { | |
8007 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8008 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); | |
8009 | } | |
8010 | ||
8011 | /* Implementation of "catch throw" command. */ | |
8012 | ||
8013 | static void | |
8014 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
8015 | { | |
8016 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8017 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); | |
8018 | } | |
8019 | ||
f7f9143b JB |
8020 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
8021 | ||
8022 | static void | |
a6d9a66e UW |
8023 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
8024 | struct symtab_and_line sal, | |
f7f9143b JB |
8025 | char *addr_string, |
8026 | char *exp_string, | |
8027 | char *cond_string, | |
8028 | struct expression *cond, | |
8029 | struct breakpoint_ops *ops, | |
8030 | int tempflag, | |
8031 | int from_tty) | |
8032 | { | |
8033 | struct breakpoint *b; | |
8034 | ||
8035 | if (from_tty) | |
8036 | { | |
5af949e3 UW |
8037 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
8038 | if (!loc_gdbarch) | |
8039 | loc_gdbarch = gdbarch; | |
8040 | ||
6c95b8df PA |
8041 | describe_other_breakpoints (loc_gdbarch, |
8042 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
8043 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
8044 | version for exception catchpoints, because two catchpoints | |
8045 | used for different exception names will use the same address. | |
8046 | In this case, a "breakpoint ... also set at..." warning is | |
8047 | unproductive. Besides. the warning phrasing is also a bit | |
8048 | inapropriate, we should use the word catchpoint, and tell | |
8049 | the user what type of catchpoint it is. The above is good | |
8050 | enough for now, though. */ | |
8051 | } | |
8052 | ||
a6d9a66e | 8053 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
8054 | set_breakpoint_count (breakpoint_count + 1); |
8055 | ||
8056 | b->enable_state = bp_enabled; | |
8057 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
8058 | b->number = breakpoint_count; | |
8059 | b->ignore_count = 0; | |
511a6cd4 | 8060 | b->loc->cond = cond; |
f7f9143b JB |
8061 | b->addr_string = addr_string; |
8062 | b->language = language_ada; | |
8063 | b->cond_string = cond_string; | |
8064 | b->exp_string = exp_string; | |
8065 | b->thread = -1; | |
8066 | b->ops = ops; | |
f7f9143b JB |
8067 | |
8068 | mention (b); | |
b60e7edf | 8069 | update_global_location_list (1); |
f7f9143b JB |
8070 | } |
8071 | ||
8072 | /* Implement the "catch exception" command. */ | |
8073 | ||
8074 | static void | |
44feb3ce TT |
8075 | catch_ada_exception_command (char *arg, int from_tty, |
8076 | struct cmd_list_element *command) | |
f7f9143b | 8077 | { |
a6d9a66e | 8078 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8079 | int tempflag; |
f7f9143b JB |
8080 | struct symtab_and_line sal; |
8081 | enum bptype type; | |
8082 | char *addr_string = NULL; | |
8083 | char *exp_string = NULL; | |
8084 | char *cond_string = NULL; | |
8085 | struct expression *cond = NULL; | |
8086 | struct breakpoint_ops *ops = NULL; | |
8087 | ||
44feb3ce TT |
8088 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8089 | ||
8090 | if (!arg) | |
8091 | arg = ""; | |
f7f9143b JB |
8092 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
8093 | &cond_string, &cond, &ops); | |
a6d9a66e | 8094 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
8095 | cond_string, cond, ops, tempflag, |
8096 | from_tty); | |
8097 | } | |
8098 | ||
a96d9b2e SDJ |
8099 | /* Cleanup function for a syscall filter list. */ |
8100 | static void | |
8101 | clean_up_filters (void *arg) | |
8102 | { | |
8103 | VEC(int) *iter = *(VEC(int) **) arg; | |
8104 | VEC_free (int, iter); | |
8105 | } | |
8106 | ||
8107 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
8108 | filter list, or NULL if no filtering is required. */ | |
8109 | static VEC(int) * | |
8110 | catch_syscall_split_args (char *arg) | |
8111 | { | |
8112 | VEC(int) *result = NULL; | |
8113 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
8114 | ||
8115 | while (*arg != '\0') | |
8116 | { | |
8117 | int i, syscall_number; | |
8118 | char *endptr; | |
8119 | char cur_name[128]; | |
8120 | struct syscall s; | |
8121 | ||
8122 | /* Skip whitespace. */ | |
8123 | while (isspace (*arg)) | |
8124 | arg++; | |
8125 | ||
8126 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
8127 | cur_name[i] = arg[i]; | |
8128 | cur_name[i] = '\0'; | |
8129 | arg += i; | |
8130 | ||
8131 | /* Check if the user provided a syscall name or a number. */ | |
8132 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
8133 | if (*endptr == '\0') | |
bccd0dd2 | 8134 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
8135 | else |
8136 | { | |
8137 | /* We have a name. Let's check if it's valid and convert it | |
8138 | to a number. */ | |
8139 | get_syscall_by_name (cur_name, &s); | |
8140 | ||
8141 | if (s.number == UNKNOWN_SYSCALL) | |
8142 | /* Here we have to issue an error instead of a warning, because | |
8143 | GDB cannot do anything useful if there's no syscall number to | |
8144 | be caught. */ | |
8145 | error (_("Unknown syscall name '%s'."), cur_name); | |
8146 | } | |
8147 | ||
8148 | /* Ok, it's valid. */ | |
8149 | VEC_safe_push (int, result, s.number); | |
8150 | } | |
8151 | ||
8152 | discard_cleanups (cleanup); | |
8153 | return result; | |
8154 | } | |
8155 | ||
8156 | /* Implement the "catch syscall" command. */ | |
8157 | ||
8158 | static void | |
8159 | catch_syscall_command_1 (char *arg, int from_tty, struct cmd_list_element *command) | |
8160 | { | |
8161 | int tempflag; | |
8162 | VEC(int) *filter; | |
8163 | struct syscall s; | |
8164 | struct gdbarch *gdbarch = get_current_arch (); | |
8165 | ||
8166 | /* Checking if the feature if supported. */ | |
8167 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
8168 | error (_("The feature 'catch syscall' is not supported on \ | |
8169 | this architeture yet.")); | |
8170 | ||
8171 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
8172 | ||
8173 | ep_skip_leading_whitespace (&arg); | |
8174 | ||
8175 | /* We need to do this first "dummy" translation in order | |
8176 | to get the syscall XML file loaded or, most important, | |
8177 | to display a warning to the user if there's no XML file | |
8178 | for his/her architecture. */ | |
8179 | get_syscall_by_number (0, &s); | |
8180 | ||
8181 | /* The allowed syntax is: | |
8182 | catch syscall | |
8183 | catch syscall <name | number> [<name | number> ... <name | number>] | |
8184 | ||
8185 | Let's check if there's a syscall name. */ | |
8186 | ||
8187 | if (arg != NULL) | |
8188 | filter = catch_syscall_split_args (arg); | |
8189 | else | |
8190 | filter = NULL; | |
8191 | ||
8192 | create_syscall_event_catchpoint (tempflag, filter, | |
8193 | &catch_syscall_breakpoint_ops); | |
8194 | } | |
8195 | ||
f7f9143b JB |
8196 | /* Implement the "catch assert" command. */ |
8197 | ||
8198 | static void | |
44feb3ce | 8199 | catch_assert_command (char *arg, int from_tty, struct cmd_list_element *command) |
f7f9143b | 8200 | { |
a6d9a66e | 8201 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 8202 | int tempflag; |
f7f9143b JB |
8203 | struct symtab_and_line sal; |
8204 | char *addr_string = NULL; | |
8205 | struct breakpoint_ops *ops = NULL; | |
8206 | ||
44feb3ce TT |
8207 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
8208 | ||
8209 | if (!arg) | |
8210 | arg = ""; | |
f7f9143b | 8211 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
8212 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
8213 | ops, tempflag, from_tty); | |
f7f9143b JB |
8214 | } |
8215 | ||
c906108c | 8216 | static void |
fba45db2 | 8217 | catch_command (char *arg, int from_tty) |
c906108c | 8218 | { |
44feb3ce | 8219 | error (_("Catch requires an event name.")); |
c906108c SS |
8220 | } |
8221 | \f | |
8222 | ||
8223 | static void | |
fba45db2 | 8224 | tcatch_command (char *arg, int from_tty) |
c906108c | 8225 | { |
44feb3ce | 8226 | error (_("Catch requires an event name.")); |
c906108c SS |
8227 | } |
8228 | ||
80f8a6eb | 8229 | /* Delete breakpoints by address or line. */ |
c906108c SS |
8230 | |
8231 | static void | |
fba45db2 | 8232 | clear_command (char *arg, int from_tty) |
c906108c | 8233 | { |
d6e956e5 VP |
8234 | struct breakpoint *b; |
8235 | VEC(breakpoint_p) *found = 0; | |
8236 | int ix; | |
c906108c SS |
8237 | int default_match; |
8238 | struct symtabs_and_lines sals; | |
8239 | struct symtab_and_line sal; | |
c906108c SS |
8240 | int i; |
8241 | ||
8242 | if (arg) | |
8243 | { | |
8244 | sals = decode_line_spec (arg, 1); | |
8245 | default_match = 0; | |
8246 | } | |
8247 | else | |
8248 | { | |
c5aa993b | 8249 | sals.sals = (struct symtab_and_line *) |
c906108c | 8250 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 8251 | make_cleanup (xfree, sals.sals); |
fe39c653 | 8252 | init_sal (&sal); /* initialize to zeroes */ |
c906108c SS |
8253 | sal.line = default_breakpoint_line; |
8254 | sal.symtab = default_breakpoint_symtab; | |
8255 | sal.pc = default_breakpoint_address; | |
6c95b8df | 8256 | sal.pspace = default_breakpoint_pspace; |
c906108c | 8257 | if (sal.symtab == 0) |
8a3fe4f8 | 8258 | error (_("No source file specified.")); |
c906108c SS |
8259 | |
8260 | sals.sals[0] = sal; | |
8261 | sals.nelts = 1; | |
8262 | ||
8263 | default_match = 1; | |
8264 | } | |
8265 | ||
ed0616c6 VP |
8266 | /* We don't call resolve_sal_pc here. That's not |
8267 | as bad as it seems, because all existing breakpoints | |
8268 | typically have both file/line and pc set. So, if | |
8269 | clear is given file/line, we can match this to existing | |
8270 | breakpoint without obtaining pc at all. | |
8271 | ||
8272 | We only support clearing given the address explicitly | |
8273 | present in breakpoint table. Say, we've set breakpoint | |
8274 | at file:line. There were several PC values for that file:line, | |
8275 | due to optimization, all in one block. | |
8276 | We've picked one PC value. If "clear" is issued with another | |
8277 | PC corresponding to the same file:line, the breakpoint won't | |
8278 | be cleared. We probably can still clear the breakpoint, but | |
8279 | since the other PC value is never presented to user, user | |
8280 | can only find it by guessing, and it does not seem important | |
8281 | to support that. */ | |
8282 | ||
c906108c | 8283 | /* For each line spec given, delete bps which correspond |
80f8a6eb MS |
8284 | to it. Do it in two passes, solely to preserve the current |
8285 | behavior that from_tty is forced true if we delete more than | |
8286 | one breakpoint. */ | |
c906108c | 8287 | |
80f8a6eb | 8288 | found = NULL; |
c906108c SS |
8289 | for (i = 0; i < sals.nelts; i++) |
8290 | { | |
8291 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
8292 | If line given (pc == 0), clear all bpts on specified line. |
8293 | If defaulting, clear all bpts on default line | |
c906108c | 8294 | or at default pc. |
c5aa993b JM |
8295 | |
8296 | defaulting sal.pc != 0 tests to do | |
8297 | ||
8298 | 0 1 pc | |
8299 | 1 1 pc _and_ line | |
8300 | 0 0 line | |
8301 | 1 0 <can't happen> */ | |
c906108c SS |
8302 | |
8303 | sal = sals.sals[i]; | |
c906108c | 8304 | |
d6e956e5 VP |
8305 | /* Find all matching breakpoints and add them to |
8306 | 'found'. */ | |
8307 | ALL_BREAKPOINTS (b) | |
c5aa993b | 8308 | { |
0d381245 | 8309 | int match = 0; |
80f8a6eb MS |
8310 | /* Are we going to delete b? */ |
8311 | if (b->type != bp_none | |
8312 | && b->type != bp_watchpoint | |
8313 | && b->type != bp_hardware_watchpoint | |
8314 | && b->type != bp_read_watchpoint | |
0d381245 VP |
8315 | && b->type != bp_access_watchpoint) |
8316 | { | |
8317 | struct bp_location *loc = b->loc; | |
8318 | for (; loc; loc = loc->next) | |
8319 | { | |
6c95b8df PA |
8320 | int pc_match = sal.pc |
8321 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
8322 | && (loc->address == sal.pc) |
8323 | && (!section_is_overlay (loc->section) | |
8324 | || loc->section == sal.section); | |
8325 | int line_match = ((default_match || (0 == sal.pc)) | |
8326 | && b->source_file != NULL | |
8327 | && sal.symtab != NULL | |
6c95b8df | 8328 | && sal.pspace == loc->pspace |
0d381245 VP |
8329 | && strcmp (b->source_file, sal.symtab->filename) == 0 |
8330 | && b->line_number == sal.line); | |
8331 | if (pc_match || line_match) | |
8332 | { | |
8333 | match = 1; | |
8334 | break; | |
8335 | } | |
8336 | } | |
8337 | } | |
8338 | ||
8339 | if (match) | |
d6e956e5 | 8340 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 8341 | } |
80f8a6eb MS |
8342 | } |
8343 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 8344 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
8345 | { |
8346 | if (arg) | |
8a3fe4f8 | 8347 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 8348 | else |
8a3fe4f8 | 8349 | error (_("No breakpoint at this line.")); |
80f8a6eb | 8350 | } |
c906108c | 8351 | |
d6e956e5 | 8352 | if (VEC_length(breakpoint_p, found) > 1) |
80f8a6eb MS |
8353 | from_tty = 1; /* Always report if deleted more than one */ |
8354 | if (from_tty) | |
a3f17187 | 8355 | { |
d6e956e5 | 8356 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
8357 | printf_unfiltered (_("Deleted breakpoint ")); |
8358 | else | |
8359 | printf_unfiltered (_("Deleted breakpoints ")); | |
8360 | } | |
80f8a6eb | 8361 | breakpoints_changed (); |
d6e956e5 VP |
8362 | |
8363 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 8364 | { |
c5aa993b | 8365 | if (from_tty) |
d6e956e5 VP |
8366 | printf_unfiltered ("%d ", b->number); |
8367 | delete_breakpoint (b); | |
c906108c | 8368 | } |
80f8a6eb MS |
8369 | if (from_tty) |
8370 | putchar_unfiltered ('\n'); | |
c906108c SS |
8371 | } |
8372 | \f | |
8373 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
8374 | all breakpoints that are marked for deletion, whether hit or not. | |
8375 | This is called after any breakpoint is hit, or after errors. */ | |
8376 | ||
8377 | void | |
fba45db2 | 8378 | breakpoint_auto_delete (bpstat bs) |
c906108c SS |
8379 | { |
8380 | struct breakpoint *b, *temp; | |
8381 | ||
8382 | for (; bs; bs = bs->next) | |
20874c92 VP |
8383 | if (bs->breakpoint_at |
8384 | && bs->breakpoint_at->owner | |
8385 | && bs->breakpoint_at->owner->disposition == disp_del | |
c906108c | 8386 | && bs->stop) |
4f8d1dc6 | 8387 | delete_breakpoint (bs->breakpoint_at->owner); |
c906108c SS |
8388 | |
8389 | ALL_BREAKPOINTS_SAFE (b, temp) | |
c5aa993b | 8390 | { |
b5de0fa7 | 8391 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
8392 | delete_breakpoint (b); |
8393 | } | |
c906108c SS |
8394 | } |
8395 | ||
494cfb0f | 8396 | /* A comparison function for bp_location AP and BP being interfaced to qsort. |
876fa593 JK |
8397 | Sort elements primarily by their ADDRESS (no matter what does |
8398 | breakpoint_address_is_meaningful say for its OWNER), secondarily by ordering | |
8399 | first bp_permanent OWNERed elements and terciarily just ensuring the array | |
8400 | is sorted stable way despite qsort being an instable algorithm. */ | |
8401 | ||
8402 | static int | |
494cfb0f | 8403 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 8404 | { |
494cfb0f JK |
8405 | struct bp_location *a = *(void **) ap; |
8406 | struct bp_location *b = *(void **) bp; | |
876fa593 JK |
8407 | int a_perm = a->owner->enable_state == bp_permanent; |
8408 | int b_perm = b->owner->enable_state == bp_permanent; | |
8409 | ||
8410 | if (a->address != b->address) | |
8411 | return (a->address > b->address) - (a->address < b->address); | |
8412 | ||
8413 | /* Sort permanent breakpoints first. */ | |
8414 | if (a_perm != b_perm) | |
8415 | return (a_perm < b_perm) - (a_perm > b_perm); | |
8416 | ||
8417 | /* Make the user-visible order stable across GDB runs. Locations of the same | |
8418 | breakpoint can be sorted in arbitrary order. */ | |
8419 | ||
8420 | if (a->owner->number != b->owner->number) | |
8421 | return (a->owner->number > b->owner->number) | |
8422 | - (a->owner->number < b->owner->number); | |
8423 | ||
8424 | return (a > b) - (a < b); | |
8425 | } | |
8426 | ||
876fa593 JK |
8427 | /* Set bp_location_placed_address_before_address_max and |
8428 | bp_location_shadow_len_after_address_max according to the current content of | |
8429 | the bp_location array. */ | |
f7545552 TT |
8430 | |
8431 | static void | |
876fa593 | 8432 | bp_location_target_extensions_update (void) |
f7545552 | 8433 | { |
876fa593 JK |
8434 | struct bp_location *bl, **blp_tmp; |
8435 | ||
8436 | bp_location_placed_address_before_address_max = 0; | |
8437 | bp_location_shadow_len_after_address_max = 0; | |
8438 | ||
8439 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
8440 | { | |
8441 | CORE_ADDR start, end, addr; | |
8442 | ||
8443 | if (!bp_location_has_shadow (bl)) | |
8444 | continue; | |
8445 | ||
8446 | start = bl->target_info.placed_address; | |
8447 | end = start + bl->target_info.shadow_len; | |
8448 | ||
8449 | gdb_assert (bl->address >= start); | |
8450 | addr = bl->address - start; | |
8451 | if (addr > bp_location_placed_address_before_address_max) | |
8452 | bp_location_placed_address_before_address_max = addr; | |
8453 | ||
8454 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
8455 | ||
8456 | gdb_assert (bl->address < end); | |
8457 | addr = end - bl->address; | |
8458 | if (addr > bp_location_shadow_len_after_address_max) | |
8459 | bp_location_shadow_len_after_address_max = addr; | |
8460 | } | |
f7545552 TT |
8461 | } |
8462 | ||
4cd9bd08 | 8463 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
8464 | into the inferior, only remove already-inserted locations that no |
8465 | longer should be inserted. Functions that delete a breakpoint or | |
8466 | breakpoints should pass false, so that deleting a breakpoint | |
8467 | doesn't have the side effect of inserting the locations of other | |
8468 | breakpoints that are marked not-inserted, but should_be_inserted | |
8469 | returns true on them. | |
8470 | ||
8471 | This behaviour is useful is situations close to tear-down -- e.g., | |
8472 | after an exec, while the target still has execution, but breakpoint | |
8473 | shadows of the previous executable image should *NOT* be restored | |
8474 | to the new image; or before detaching, where the target still has | |
8475 | execution and wants to delete breakpoints from GDB's lists, and all | |
8476 | breakpoints had already been removed from the inferior. */ | |
8477 | ||
0d381245 | 8478 | static void |
b60e7edf | 8479 | update_global_location_list (int should_insert) |
0d381245 | 8480 | { |
74960c60 | 8481 | struct breakpoint *b; |
876fa593 | 8482 | struct bp_location **locp, *loc; |
f7545552 TT |
8483 | struct cleanup *cleanups; |
8484 | ||
2d134ed3 PA |
8485 | /* Used in the duplicates detection below. When iterating over all |
8486 | bp_locations, points to the first bp_location of a given address. | |
8487 | Breakpoints and watchpoints of different types are never | |
8488 | duplicates of each other. Keep one pointer for each type of | |
8489 | breakpoint/watchpoint, so we only need to loop over all locations | |
8490 | once. */ | |
8491 | struct bp_location *bp_loc_first; /* breakpoint */ | |
8492 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
8493 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
8494 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 JK |
8495 | |
8496 | /* Saved former bp_location array which we compare against the newly built | |
8497 | bp_location from the current state of ALL_BREAKPOINTS. */ | |
8498 | struct bp_location **old_location, **old_locp; | |
8499 | unsigned old_location_count; | |
8500 | ||
8501 | old_location = bp_location; | |
8502 | old_location_count = bp_location_count; | |
8503 | bp_location = NULL; | |
8504 | bp_location_count = 0; | |
8505 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 8506 | |
74960c60 | 8507 | ALL_BREAKPOINTS (b) |
876fa593 JK |
8508 | for (loc = b->loc; loc; loc = loc->next) |
8509 | bp_location_count++; | |
8510 | ||
8511 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
8512 | locp = bp_location; | |
8513 | ALL_BREAKPOINTS (b) | |
8514 | for (loc = b->loc; loc; loc = loc->next) | |
8515 | *locp++ = loc; | |
8516 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 8517 | bp_location_compare); |
876fa593 JK |
8518 | |
8519 | bp_location_target_extensions_update (); | |
74960c60 VP |
8520 | |
8521 | /* Identify bp_location instances that are no longer present in the new | |
8522 | list, and therefore should be freed. Note that it's not necessary that | |
8523 | those locations should be removed from inferior -- if there's another | |
8524 | location at the same address (previously marked as duplicate), | |
876fa593 JK |
8525 | we don't need to remove/insert the location. |
8526 | ||
8527 | LOCP is kept in sync with OLD_LOCP, each pointing to the current and | |
8528 | former bp_location array state respectively. */ | |
8529 | ||
8530 | locp = bp_location; | |
8531 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
8532 | old_locp++) | |
74960c60 | 8533 | { |
876fa593 | 8534 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 8535 | struct bp_location **loc2p; |
876fa593 JK |
8536 | |
8537 | /* Tells if 'old_loc' is found amoung the new locations. If not, we | |
74960c60 | 8538 | have to free it. */ |
c7d46a38 | 8539 | int found_object = 0; |
20874c92 VP |
8540 | /* Tells if the location should remain inserted in the target. */ |
8541 | int keep_in_target = 0; | |
8542 | int removed = 0; | |
876fa593 JK |
8543 | |
8544 | /* Skip LOCP entries which will definitely never be needed. Stop either | |
8545 | at or being the one matching OLD_LOC. */ | |
8546 | while (locp < bp_location + bp_location_count | |
c7d46a38 | 8547 | && (*locp)->address < old_loc->address) |
876fa593 | 8548 | locp++; |
c7d46a38 PA |
8549 | |
8550 | for (loc2p = locp; | |
8551 | (loc2p < bp_location + bp_location_count | |
8552 | && (*loc2p)->address == old_loc->address); | |
8553 | loc2p++) | |
8554 | { | |
8555 | if (*loc2p == old_loc) | |
8556 | { | |
8557 | found_object = 1; | |
8558 | break; | |
8559 | } | |
8560 | } | |
74960c60 VP |
8561 | |
8562 | /* If this location is no longer present, and inserted, look if there's | |
8563 | maybe a new location at the same address. If so, mark that one | |
8564 | inserted, and don't remove this one. This is needed so that we | |
8565 | don't have a time window where a breakpoint at certain location is not | |
8566 | inserted. */ | |
8567 | ||
876fa593 | 8568 | if (old_loc->inserted) |
0d381245 | 8569 | { |
74960c60 | 8570 | /* If the location is inserted now, we might have to remove it. */ |
74960c60 | 8571 | |
876fa593 | 8572 | if (found_object && should_be_inserted (old_loc)) |
74960c60 VP |
8573 | { |
8574 | /* The location is still present in the location list, and still | |
8575 | should be inserted. Don't do anything. */ | |
20874c92 | 8576 | keep_in_target = 1; |
74960c60 VP |
8577 | } |
8578 | else | |
8579 | { | |
8580 | /* The location is either no longer present, or got disabled. | |
8581 | See if there's another location at the same address, in which | |
8582 | case we don't need to remove this one from the target. */ | |
876fa593 JK |
8583 | |
8584 | if (breakpoint_address_is_meaningful (old_loc->owner)) | |
8585 | { | |
876fa593 | 8586 | for (loc2p = locp; |
c7d46a38 PA |
8587 | (loc2p < bp_location + bp_location_count |
8588 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
8589 | loc2p++) |
8590 | { | |
8591 | struct bp_location *loc2 = *loc2p; | |
8592 | ||
2d134ed3 | 8593 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
8594 | { |
8595 | /* For the sake of should_be_inserted. | |
8596 | Duplicates check below will fix up this later. */ | |
8597 | loc2->duplicate = 0; | |
85d721b8 PA |
8598 | |
8599 | /* Read watchpoint locations are switched to | |
8600 | access watchpoints, if the former are not | |
8601 | supported, but the latter are. */ | |
8602 | if (is_hardware_watchpoint (old_loc->owner)) | |
8603 | { | |
8604 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
8605 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
8606 | } | |
8607 | ||
c7d46a38 PA |
8608 | if (loc2 != old_loc && should_be_inserted (loc2)) |
8609 | { | |
8610 | loc2->inserted = 1; | |
8611 | loc2->target_info = old_loc->target_info; | |
8612 | keep_in_target = 1; | |
8613 | break; | |
8614 | } | |
876fa593 JK |
8615 | } |
8616 | } | |
8617 | } | |
74960c60 VP |
8618 | } |
8619 | ||
20874c92 VP |
8620 | if (!keep_in_target) |
8621 | { | |
876fa593 | 8622 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 VP |
8623 | { |
8624 | /* This is just about all we can do. We could keep this | |
8625 | location on the global list, and try to remove it next | |
8626 | time, but there's no particular reason why we will | |
8627 | succeed next time. | |
8628 | ||
876fa593 | 8629 | Note that at this point, old_loc->owner is still valid, |
20874c92 VP |
8630 | as delete_breakpoint frees the breakpoint only |
8631 | after calling us. */ | |
8632 | printf_filtered (_("warning: Error removing breakpoint %d\n"), | |
876fa593 | 8633 | old_loc->owner->number); |
20874c92 VP |
8634 | } |
8635 | removed = 1; | |
8636 | } | |
0d381245 | 8637 | } |
74960c60 VP |
8638 | |
8639 | if (!found_object) | |
1c5cfe86 | 8640 | { |
db82e815 PA |
8641 | if (removed && non_stop |
8642 | && breakpoint_address_is_meaningful (old_loc->owner) | |
8643 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 8644 | { |
db82e815 PA |
8645 | /* This location was removed from the target. In |
8646 | non-stop mode, a race condition is possible where | |
8647 | we've removed a breakpoint, but stop events for that | |
8648 | breakpoint are already queued and will arrive later. | |
8649 | We apply an heuristic to be able to distinguish such | |
8650 | SIGTRAPs from other random SIGTRAPs: we keep this | |
8651 | breakpoint location for a bit, and will retire it | |
8652 | after we see some number of events. The theory here | |
8653 | is that reporting of events should, "on the average", | |
8654 | be fair, so after a while we'll see events from all | |
8655 | threads that have anything of interest, and no longer | |
8656 | need to keep this breakpoint location around. We | |
8657 | don't hold locations forever so to reduce chances of | |
8658 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
8659 | SIGTRAP. | |
8660 | ||
8661 | The heuristic failing can be disastrous on | |
8662 | decr_pc_after_break targets. | |
8663 | ||
8664 | On decr_pc_after_break targets, like e.g., x86-linux, | |
8665 | if we fail to recognize a late breakpoint SIGTRAP, | |
8666 | because events_till_retirement has reached 0 too | |
8667 | soon, we'll fail to do the PC adjustment, and report | |
8668 | a random SIGTRAP to the user. When the user resumes | |
8669 | the inferior, it will most likely immediately crash | |
8670 | with SIGILL/SIGBUS/SEGSEGV, or worse, get silently | |
8671 | corrupted, because of being resumed e.g., in the | |
8672 | middle of a multi-byte instruction, or skipped a | |
8673 | one-byte instruction. This was actually seen happen | |
8674 | on native x86-linux, and should be less rare on | |
8675 | targets that do not support new thread events, like | |
8676 | remote, due to the heuristic depending on | |
8677 | thread_count. | |
8678 | ||
8679 | Mistaking a random SIGTRAP for a breakpoint trap | |
8680 | causes similar symptoms (PC adjustment applied when | |
8681 | it shouldn't), but then again, playing with SIGTRAPs | |
8682 | behind the debugger's back is asking for trouble. | |
8683 | ||
8684 | Since hardware watchpoint traps are always | |
8685 | distinguishable from other traps, so we don't need to | |
8686 | apply keep hardware watchpoint moribund locations | |
8687 | around. We simply always ignore hardware watchpoint | |
8688 | traps we can no longer explain. */ | |
8689 | ||
876fa593 JK |
8690 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
8691 | old_loc->owner = NULL; | |
20874c92 | 8692 | |
876fa593 | 8693 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
8694 | } |
8695 | else | |
876fa593 | 8696 | free_bp_location (old_loc); |
20874c92 | 8697 | } |
74960c60 | 8698 | } |
1c5cfe86 | 8699 | |
2d134ed3 PA |
8700 | /* Rescan breakpoints at the same address and section, marking the |
8701 | first one as "first" and any others as "duplicates". This is so | |
8702 | that the bpt instruction is only inserted once. If we have a | |
8703 | permanent breakpoint at the same place as BPT, make that one the | |
8704 | official one, and the rest as duplicates. Permanent breakpoints | |
8705 | are sorted first for the same address. | |
8706 | ||
8707 | Do the same for hardware watchpoints, but also considering the | |
8708 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 8709 | |
2d134ed3 PA |
8710 | bp_loc_first = NULL; |
8711 | wp_loc_first = NULL; | |
8712 | awp_loc_first = NULL; | |
8713 | rwp_loc_first = NULL; | |
876fa593 | 8714 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 8715 | { |
876fa593 | 8716 | struct breakpoint *b = loc->owner; |
2d134ed3 | 8717 | struct bp_location **loc_first_p; |
876fa593 JK |
8718 | |
8719 | if (b->enable_state == bp_disabled | |
8720 | || b->enable_state == bp_call_disabled | |
8721 | || b->enable_state == bp_startup_disabled | |
8722 | || !loc->enabled | |
8723 | || loc->shlib_disabled | |
15c3d785 PA |
8724 | || !breakpoint_address_is_meaningful (b) |
8725 | || tracepoint_type (b)) | |
876fa593 JK |
8726 | continue; |
8727 | ||
8728 | /* Permanent breakpoint should always be inserted. */ | |
8729 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
8730 | internal_error (__FILE__, __LINE__, | |
8731 | _("allegedly permanent breakpoint is not " | |
8732 | "actually inserted")); | |
8733 | ||
2d134ed3 PA |
8734 | if (b->type == bp_hardware_watchpoint) |
8735 | loc_first_p = &wp_loc_first; | |
8736 | else if (b->type == bp_read_watchpoint) | |
8737 | loc_first_p = &rwp_loc_first; | |
8738 | else if (b->type == bp_access_watchpoint) | |
8739 | loc_first_p = &awp_loc_first; | |
8740 | else | |
8741 | loc_first_p = &bp_loc_first; | |
8742 | ||
8743 | if (*loc_first_p == NULL | |
8744 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
8745 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 8746 | { |
2d134ed3 | 8747 | *loc_first_p = loc; |
876fa593 JK |
8748 | loc->duplicate = 0; |
8749 | continue; | |
8750 | } | |
8751 | ||
8752 | loc->duplicate = 1; | |
8753 | ||
2d134ed3 PA |
8754 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
8755 | && b->enable_state != bp_permanent) | |
876fa593 JK |
8756 | internal_error (__FILE__, __LINE__, |
8757 | _("another breakpoint was inserted on top of " | |
8758 | "a permanent breakpoint")); | |
0d381245 | 8759 | } |
74960c60 | 8760 | |
50c71eaf | 8761 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 8762 | && (have_live_inferiors () |
2567c7d9 | 8763 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 8764 | insert_breakpoint_locations (); |
f7545552 TT |
8765 | |
8766 | do_cleanups (cleanups); | |
74960c60 VP |
8767 | } |
8768 | ||
20874c92 VP |
8769 | void |
8770 | breakpoint_retire_moribund (void) | |
8771 | { | |
8772 | struct bp_location *loc; | |
8773 | int ix; | |
8774 | ||
8775 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
8776 | if (--(loc->events_till_retirement) == 0) | |
8777 | { | |
8778 | free_bp_location (loc); | |
8779 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); | |
8780 | --ix; | |
8781 | } | |
8782 | } | |
8783 | ||
74960c60 | 8784 | static void |
b60e7edf | 8785 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
8786 | { |
8787 | struct gdb_exception e; | |
8788 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
b60e7edf | 8789 | update_global_location_list (inserting); |
0d381245 VP |
8790 | } |
8791 | ||
a474d7c2 PA |
8792 | /* Clear BPT from a BPS. */ |
8793 | static void | |
8794 | bpstat_remove_breakpoint (bpstat bps, struct breakpoint *bpt) | |
8795 | { | |
8796 | bpstat bs; | |
8797 | for (bs = bps; bs; bs = bs->next) | |
8798 | if (bs->breakpoint_at && bs->breakpoint_at->owner == bpt) | |
8799 | { | |
8800 | bs->breakpoint_at = NULL; | |
8801 | bs->old_val = NULL; | |
8802 | /* bs->commands will be freed later. */ | |
8803 | } | |
8804 | } | |
8805 | ||
8806 | /* Callback for iterate_over_threads. */ | |
8807 | static int | |
8808 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) | |
8809 | { | |
8810 | struct breakpoint *bpt = data; | |
8811 | bpstat_remove_breakpoint (th->stop_bpstat, bpt); | |
8812 | return 0; | |
8813 | } | |
8814 | ||
53a5351d JM |
8815 | /* Delete a breakpoint and clean up all traces of it in the data |
8816 | structures. */ | |
c906108c SS |
8817 | |
8818 | void | |
fba45db2 | 8819 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 8820 | { |
52f0bd74 | 8821 | struct breakpoint *b; |
74960c60 | 8822 | struct bp_location *loc, *next; |
c906108c | 8823 | |
8a3fe4f8 | 8824 | gdb_assert (bpt != NULL); |
c906108c SS |
8825 | |
8826 | /* Has this bp already been deleted? This can happen because multiple | |
8827 | lists can hold pointers to bp's. bpstat lists are especial culprits. | |
8828 | ||
8829 | One example of this happening is a watchpoint's scope bp. When the | |
8830 | scope bp triggers, we notice that the watchpoint is out of scope, and | |
8831 | delete it. We also delete its scope bp. But the scope bp is marked | |
8832 | "auto-deleting", and is already on a bpstat. That bpstat is then | |
8833 | checked for auto-deleting bp's, which are deleted. | |
8834 | ||
8835 | A real solution to this problem might involve reference counts in bp's, | |
8836 | and/or giving them pointers back to their referencing bpstat's, and | |
8837 | teaching delete_breakpoint to only free a bp's storage when no more | |
1272ad14 | 8838 | references were extent. A cheaper bandaid was chosen. */ |
c906108c SS |
8839 | if (bpt->type == bp_none) |
8840 | return; | |
8841 | ||
e5a0a904 JK |
8842 | /* At least avoid this stale reference until the reference counting of |
8843 | breakpoints gets resolved. */ | |
8844 | if (bpt->related_breakpoint != NULL) | |
8845 | { | |
8846 | gdb_assert (bpt->related_breakpoint->related_breakpoint == bpt); | |
8847 | bpt->related_breakpoint->disposition = disp_del_at_next_stop; | |
8848 | bpt->related_breakpoint->related_breakpoint = NULL; | |
8849 | bpt->related_breakpoint = NULL; | |
8850 | } | |
8851 | ||
383f836e | 8852 | observer_notify_breakpoint_deleted (bpt->number); |
c906108c | 8853 | |
c906108c SS |
8854 | if (breakpoint_chain == bpt) |
8855 | breakpoint_chain = bpt->next; | |
8856 | ||
c906108c SS |
8857 | ALL_BREAKPOINTS (b) |
8858 | if (b->next == bpt) | |
c5aa993b JM |
8859 | { |
8860 | b->next = bpt->next; | |
8861 | break; | |
8862 | } | |
c906108c | 8863 | |
c906108c | 8864 | free_command_lines (&bpt->commands); |
c906108c | 8865 | if (bpt->cond_string != NULL) |
b8c9b27d | 8866 | xfree (bpt->cond_string); |
c906108c | 8867 | if (bpt->addr_string != NULL) |
b8c9b27d | 8868 | xfree (bpt->addr_string); |
c906108c | 8869 | if (bpt->exp != NULL) |
b8c9b27d | 8870 | xfree (bpt->exp); |
c906108c | 8871 | if (bpt->exp_string != NULL) |
b8c9b27d | 8872 | xfree (bpt->exp_string); |
c906108c SS |
8873 | if (bpt->val != NULL) |
8874 | value_free (bpt->val); | |
8875 | if (bpt->source_file != NULL) | |
b8c9b27d | 8876 | xfree (bpt->source_file); |
c906108c | 8877 | if (bpt->exec_pathname != NULL) |
b8c9b27d | 8878 | xfree (bpt->exec_pathname); |
a96d9b2e | 8879 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c SS |
8880 | |
8881 | /* Be sure no bpstat's are pointing at it after it's been freed. */ | |
8882 | /* FIXME, how can we find all bpstat's? | |
198757a8 VP |
8883 | We just check stop_bpstat for now. Note that we cannot just |
8884 | remove bpstats pointing at bpt from the stop_bpstat list | |
8885 | entirely, as breakpoint commands are associated with the bpstat; | |
8886 | if we remove it here, then the later call to | |
8887 | bpstat_do_actions (&stop_bpstat); | |
8888 | in event-top.c won't do anything, and temporary breakpoints | |
8889 | with commands won't work. */ | |
a474d7c2 | 8890 | |
a474d7c2 | 8891 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); |
74960c60 VP |
8892 | |
8893 | /* Now that breakpoint is removed from breakpoint | |
8894 | list, update the global location list. This | |
8895 | will remove locations that used to belong to | |
8896 | this breakpoint. Do this before freeing | |
8897 | the breakpoint itself, since remove_breakpoint | |
8898 | looks at location's owner. It might be better | |
8899 | design to have location completely self-contained, | |
8900 | but it's not the case now. */ | |
b60e7edf | 8901 | update_global_location_list (0); |
74960c60 VP |
8902 | |
8903 | ||
c906108c SS |
8904 | /* On the chance that someone will soon try again to delete this same |
8905 | bp, we mark it as deleted before freeing its storage. */ | |
8906 | bpt->type = bp_none; | |
8907 | ||
b8c9b27d | 8908 | xfree (bpt); |
c906108c SS |
8909 | } |
8910 | ||
4d6140d9 AC |
8911 | static void |
8912 | do_delete_breakpoint_cleanup (void *b) | |
8913 | { | |
8914 | delete_breakpoint (b); | |
8915 | } | |
8916 | ||
8917 | struct cleanup * | |
8918 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
8919 | { | |
8920 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
8921 | } | |
8922 | ||
c906108c | 8923 | void |
fba45db2 | 8924 | delete_command (char *arg, int from_tty) |
c906108c SS |
8925 | { |
8926 | struct breakpoint *b, *temp; | |
8927 | ||
ea9365bb TT |
8928 | dont_repeat (); |
8929 | ||
c906108c SS |
8930 | if (arg == 0) |
8931 | { | |
8932 | int breaks_to_delete = 0; | |
8933 | ||
8934 | /* Delete all breakpoints if no argument. | |
c5aa993b JM |
8935 | Do not delete internal or call-dummy breakpoints, these |
8936 | have to be deleted with an explicit breakpoint number argument. */ | |
8937 | ALL_BREAKPOINTS (b) | |
8938 | { | |
059fb39f PM |
8939 | if (b->type != bp_call_dummy |
8940 | && b->type != bp_shlib_event | |
4efc6507 | 8941 | && b->type != bp_jit_event |
059fb39f PM |
8942 | && b->type != bp_thread_event |
8943 | && b->type != bp_overlay_event | |
0fd8e87f | 8944 | && b->type != bp_longjmp_master |
059fb39f | 8945 | && b->number >= 0) |
973d738b DJ |
8946 | { |
8947 | breaks_to_delete = 1; | |
8948 | break; | |
8949 | } | |
c5aa993b | 8950 | } |
c906108c SS |
8951 | |
8952 | /* Ask user only if there are some breakpoints to delete. */ | |
8953 | if (!from_tty | |
e2e0b3e5 | 8954 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 8955 | { |
c5aa993b JM |
8956 | ALL_BREAKPOINTS_SAFE (b, temp) |
8957 | { | |
059fb39f PM |
8958 | if (b->type != bp_call_dummy |
8959 | && b->type != bp_shlib_event | |
8960 | && b->type != bp_thread_event | |
4efc6507 | 8961 | && b->type != bp_jit_event |
059fb39f | 8962 | && b->type != bp_overlay_event |
0fd8e87f | 8963 | && b->type != bp_longjmp_master |
059fb39f | 8964 | && b->number >= 0) |
c5aa993b JM |
8965 | delete_breakpoint (b); |
8966 | } | |
c906108c SS |
8967 | } |
8968 | } | |
8969 | else | |
8970 | map_breakpoint_numbers (arg, delete_breakpoint); | |
8971 | } | |
8972 | ||
0d381245 VP |
8973 | static int |
8974 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 8975 | { |
0d381245 VP |
8976 | for (; loc; loc = loc->next) |
8977 | if (!loc->shlib_disabled) | |
8978 | return 0; | |
8979 | return 1; | |
fe3f5fa8 VP |
8980 | } |
8981 | ||
776592bf DE |
8982 | /* Subroutine of update_breakpoint_locations to simplify it. |
8983 | Return non-zero if multiple fns in list LOC have the same name. | |
8984 | Null names are ignored. */ | |
8985 | ||
8986 | static int | |
8987 | ambiguous_names_p (struct bp_location *loc) | |
8988 | { | |
8989 | struct bp_location *l; | |
8990 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
8991 | (int (*) (const void *, const void *)) streq, | |
8992 | NULL, xcalloc, xfree); | |
8993 | ||
8994 | for (l = loc; l != NULL; l = l->next) | |
8995 | { | |
8996 | const char **slot; | |
8997 | const char *name = l->function_name; | |
8998 | ||
8999 | /* Allow for some names to be NULL, ignore them. */ | |
9000 | if (name == NULL) | |
9001 | continue; | |
9002 | ||
9003 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
9004 | INSERT); | |
9005 | /* NOTE: We can assume slot != NULL here because xcalloc never returns | |
9006 | NULL. */ | |
9007 | if (*slot != NULL) | |
9008 | { | |
9009 | htab_delete (htab); | |
9010 | return 1; | |
9011 | } | |
9012 | *slot = name; | |
9013 | } | |
9014 | ||
9015 | htab_delete (htab); | |
9016 | return 0; | |
9017 | } | |
9018 | ||
fe3f5fa8 | 9019 | static void |
0d381245 VP |
9020 | update_breakpoint_locations (struct breakpoint *b, |
9021 | struct symtabs_and_lines sals) | |
fe3f5fa8 VP |
9022 | { |
9023 | int i; | |
9024 | char *s; | |
0d381245 VP |
9025 | struct bp_location *existing_locations = b->loc; |
9026 | ||
9027 | /* If there's no new locations, and all existing locations | |
9028 | are pending, don't do anything. This optimizes | |
9029 | the common case where all locations are in the same | |
9030 | shared library, that was unloaded. We'd like to | |
9031 | retain the location, so that when the library | |
9032 | is loaded again, we don't loose the enabled/disabled | |
9033 | status of the individual locations. */ | |
9034 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) | |
fe3f5fa8 VP |
9035 | return; |
9036 | ||
fe3f5fa8 VP |
9037 | b->loc = NULL; |
9038 | ||
0d381245 | 9039 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 9040 | { |
0d381245 | 9041 | struct bp_location *new_loc = |
39d61571 | 9042 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 9043 | |
0d381245 VP |
9044 | /* Reparse conditions, they might contain references to the |
9045 | old symtab. */ | |
9046 | if (b->cond_string != NULL) | |
9047 | { | |
9048 | struct gdb_exception e; | |
fe3f5fa8 | 9049 | |
0d381245 VP |
9050 | s = b->cond_string; |
9051 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
9052 | { | |
9053 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
9054 | 0); | |
9055 | } | |
9056 | if (e.reason < 0) | |
9057 | { | |
9058 | warning (_("failed to reevaluate condition for breakpoint %d: %s"), | |
9059 | b->number, e.message); | |
9060 | new_loc->enabled = 0; | |
9061 | } | |
9062 | } | |
fe3f5fa8 | 9063 | |
0d381245 VP |
9064 | if (b->source_file != NULL) |
9065 | xfree (b->source_file); | |
9066 | if (sals.sals[i].symtab == NULL) | |
9067 | b->source_file = NULL; | |
9068 | else | |
1b36a34b | 9069 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 9070 | |
0d381245 VP |
9071 | if (b->line_number == 0) |
9072 | b->line_number = sals.sals[i].line; | |
9073 | } | |
fe3f5fa8 | 9074 | |
514f746b AR |
9075 | /* Update locations of permanent breakpoints. */ |
9076 | if (b->enable_state == bp_permanent) | |
9077 | make_breakpoint_permanent (b); | |
9078 | ||
0d381245 VP |
9079 | /* If possible, carry over 'disable' status from existing breakpoints. */ |
9080 | { | |
9081 | struct bp_location *e = existing_locations; | |
776592bf DE |
9082 | /* If there are multiple breakpoints with the same function name, |
9083 | e.g. for inline functions, comparing function names won't work. | |
9084 | Instead compare pc addresses; this is just a heuristic as things | |
9085 | may have moved, but in practice it gives the correct answer | |
9086 | often enough until a better solution is found. */ | |
9087 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
9088 | ||
0d381245 VP |
9089 | for (; e; e = e->next) |
9090 | { | |
9091 | if (!e->enabled && e->function_name) | |
9092 | { | |
9093 | struct bp_location *l = b->loc; | |
776592bf DE |
9094 | if (have_ambiguous_names) |
9095 | { | |
9096 | for (; l; l = l->next) | |
6c95b8df PA |
9097 | if (breakpoint_address_match (e->pspace->aspace, e->address, |
9098 | l->pspace->aspace, l->address)) | |
776592bf DE |
9099 | { |
9100 | l->enabled = 0; | |
9101 | break; | |
9102 | } | |
9103 | } | |
9104 | else | |
9105 | { | |
9106 | for (; l; l = l->next) | |
9107 | if (l->function_name | |
9108 | && strcmp (e->function_name, l->function_name) == 0) | |
9109 | { | |
9110 | l->enabled = 0; | |
9111 | break; | |
9112 | } | |
9113 | } | |
0d381245 VP |
9114 | } |
9115 | } | |
9116 | } | |
fe3f5fa8 | 9117 | |
b60e7edf | 9118 | update_global_location_list (1); |
fe3f5fa8 VP |
9119 | } |
9120 | ||
9121 | ||
c906108c SS |
9122 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
9123 | The value we return ends up being the return value from catch_errors. | |
9124 | Unused in this case. */ | |
9125 | ||
9126 | static int | |
4efb68b1 | 9127 | breakpoint_re_set_one (void *bint) |
c906108c | 9128 | { |
53a5351d JM |
9129 | /* get past catch_errs */ |
9130 | struct breakpoint *b = (struct breakpoint *) bint; | |
c906108c SS |
9131 | struct value *mark; |
9132 | int i; | |
fe3f5fa8 VP |
9133 | int not_found = 0; |
9134 | int *not_found_ptr = ¬_found; | |
6c95b8df PA |
9135 | struct symtabs_and_lines sals = {0}; |
9136 | struct symtabs_and_lines expanded = {0}; | |
c906108c | 9137 | char *s; |
b5de0fa7 | 9138 | enum enable_state save_enable; |
fe3f5fa8 | 9139 | struct gdb_exception e; |
6c95b8df | 9140 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
c906108c SS |
9141 | |
9142 | switch (b->type) | |
9143 | { | |
9144 | case bp_none: | |
8a3fe4f8 | 9145 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 9146 | b->number); |
c906108c SS |
9147 | return 0; |
9148 | case bp_breakpoint: | |
9149 | case bp_hardware_breakpoint: | |
1042e4c0 | 9150 | case bp_tracepoint: |
7a697b8d | 9151 | case bp_fast_tracepoint: |
8bea4e01 UW |
9152 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
9153 | if (b->enable_state == bp_startup_disabled) | |
9154 | return 0; | |
9155 | ||
c906108c SS |
9156 | if (b->addr_string == NULL) |
9157 | { | |
9158 | /* Anything without a string can't be re-set. */ | |
9159 | delete_breakpoint (b); | |
9160 | return 0; | |
9161 | } | |
c906108c SS |
9162 | |
9163 | set_language (b->language); | |
9164 | input_radix = b->input_radix; | |
9165 | s = b->addr_string; | |
6c95b8df PA |
9166 | |
9167 | save_current_space_and_thread (); | |
9168 | switch_to_program_space_and_thread (b->pspace); | |
9169 | ||
fe3f5fa8 | 9170 | TRY_CATCH (e, RETURN_MASK_ERROR) |
c906108c | 9171 | { |
fe3f5fa8 VP |
9172 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, (char ***) NULL, |
9173 | not_found_ptr); | |
9174 | } | |
9175 | if (e.reason < 0) | |
9176 | { | |
9177 | int not_found_and_ok = 0; | |
9178 | /* For pending breakpoints, it's expected that parsing | |
9179 | will fail until the right shared library is loaded. | |
9180 | User has already told to create pending breakpoints and | |
9181 | don't need extra messages. If breakpoint is in bp_shlib_disabled | |
9182 | state, then user already saw the message about that breakpoint | |
9183 | being disabled, and don't want to see more errors. */ | |
0d381245 VP |
9184 | if (not_found |
9185 | && (b->condition_not_parsed | |
9186 | || (b->loc && b->loc->shlib_disabled) | |
9187 | || b->enable_state == bp_disabled)) | |
fe3f5fa8 VP |
9188 | not_found_and_ok = 1; |
9189 | ||
9190 | if (!not_found_and_ok) | |
c906108c | 9191 | { |
fe3f5fa8 VP |
9192 | /* We surely don't want to warn about the same breakpoint |
9193 | 10 times. One solution, implemented here, is disable | |
9194 | the breakpoint on error. Another solution would be to | |
9195 | have separate 'warning emitted' flag. Since this | |
9196 | happens only when a binary has changed, I don't know | |
9197 | which approach is better. */ | |
9198 | b->enable_state = bp_disabled; | |
9199 | throw_exception (e); | |
c906108c | 9200 | } |
fe3f5fa8 | 9201 | } |
c906108c | 9202 | |
6c95b8df | 9203 | if (!not_found) |
fe3f5fa8 | 9204 | { |
6c95b8df PA |
9205 | gdb_assert (sals.nelts == 1); |
9206 | ||
9207 | resolve_sal_pc (&sals.sals[0]); | |
9208 | if (b->condition_not_parsed && s && s[0]) | |
9209 | { | |
9210 | char *cond_string = 0; | |
9211 | int thread = -1; | |
9212 | int task = 0; | |
9213 | ||
9214 | find_condition_and_thread (s, sals.sals[0].pc, | |
9215 | &cond_string, &thread, &task); | |
9216 | if (cond_string) | |
9217 | b->cond_string = cond_string; | |
9218 | b->thread = thread; | |
9219 | b->task = task; | |
9220 | b->condition_not_parsed = 0; | |
9221 | } | |
9222 | ||
9223 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
fe3f5fa8 | 9224 | } |
6c95b8df PA |
9225 | |
9226 | make_cleanup (xfree, sals.sals); | |
ed0616c6 | 9227 | update_breakpoint_locations (b, expanded); |
c906108c SS |
9228 | break; |
9229 | ||
9230 | case bp_watchpoint: | |
9231 | case bp_hardware_watchpoint: | |
9232 | case bp_read_watchpoint: | |
9233 | case bp_access_watchpoint: | |
0b3de036 VP |
9234 | /* Watchpoint can be either on expression using entirely global variables, |
9235 | or it can be on local variables. | |
9236 | ||
9237 | Watchpoints of the first kind are never auto-deleted, and even persist | |
9238 | across program restarts. Since they can use variables from shared | |
9239 | libraries, we need to reparse expression as libraries are loaded | |
9240 | and unloaded. | |
9241 | ||
9242 | Watchpoints on local variables can also change meaning as result | |
9243 | of solib event. For example, if a watchpoint uses both a local and | |
9244 | a global variables in expression, it's a local watchpoint, but | |
9245 | unloading of a shared library will make the expression invalid. | |
9246 | This is not a very common use case, but we still re-evaluate | |
9247 | expression, to avoid surprises to the user. | |
9248 | ||
9249 | Note that for local watchpoints, we re-evaluate it only if | |
9250 | watchpoints frame id is still valid. If it's not, it means | |
9251 | the watchpoint is out of scope and will be deleted soon. In fact, | |
9252 | I'm not sure we'll ever be called in this case. | |
9253 | ||
9254 | If a local watchpoint's frame id is still valid, then | |
9255 | b->exp_valid_block is likewise valid, and we can safely use it. | |
9256 | ||
9257 | Don't do anything about disabled watchpoints, since they will | |
9258 | be reevaluated again when enabled. */ | |
a5606eee | 9259 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 9260 | break; |
c5aa993b JM |
9261 | /* We needn't really do anything to reset these, since the mask |
9262 | that requests them is unaffected by e.g., new libraries being | |
9263 | loaded. */ | |
ce78b96d | 9264 | case bp_catchpoint: |
c906108c | 9265 | break; |
c5aa993b | 9266 | |
c906108c | 9267 | default: |
a3f17187 | 9268 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 9269 | /* fall through */ |
0fd8e87f UW |
9270 | /* Delete overlay event and longjmp master breakpoints; they will be |
9271 | reset later by breakpoint_re_set. */ | |
1900040c | 9272 | case bp_overlay_event: |
0fd8e87f | 9273 | case bp_longjmp_master: |
c906108c SS |
9274 | delete_breakpoint (b); |
9275 | break; | |
9276 | ||
c5aa993b JM |
9277 | /* This breakpoint is special, it's set up when the inferior |
9278 | starts and we really don't want to touch it. */ | |
c906108c SS |
9279 | case bp_shlib_event: |
9280 | ||
c4093a6a JM |
9281 | /* Like bp_shlib_event, this breakpoint type is special. |
9282 | Once it is set up, we do not want to touch it. */ | |
9283 | case bp_thread_event: | |
9284 | ||
c5aa993b JM |
9285 | /* Keep temporary breakpoints, which can be encountered when we step |
9286 | over a dlopen call and SOLIB_ADD is resetting the breakpoints. | |
9287 | Otherwise these should have been blown away via the cleanup chain | |
9288 | or by breakpoint_init_inferior when we rerun the executable. */ | |
c906108c SS |
9289 | case bp_until: |
9290 | case bp_finish: | |
9291 | case bp_watchpoint_scope: | |
9292 | case bp_call_dummy: | |
9293 | case bp_step_resume: | |
611c83ae PA |
9294 | case bp_longjmp: |
9295 | case bp_longjmp_resume: | |
4efc6507 | 9296 | case bp_jit_event: |
c906108c SS |
9297 | break; |
9298 | } | |
9299 | ||
6c95b8df | 9300 | do_cleanups (cleanups); |
c906108c SS |
9301 | return 0; |
9302 | } | |
9303 | ||
69de3c6a | 9304 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 9305 | void |
69de3c6a | 9306 | breakpoint_re_set (void) |
c906108c SS |
9307 | { |
9308 | struct breakpoint *b, *temp; | |
9309 | enum language save_language; | |
9310 | int save_input_radix; | |
6c95b8df | 9311 | struct cleanup *old_chain; |
c5aa993b | 9312 | |
c906108c SS |
9313 | save_language = current_language->la_language; |
9314 | save_input_radix = input_radix; | |
6c95b8df PA |
9315 | old_chain = save_current_program_space (); |
9316 | ||
c906108c | 9317 | ALL_BREAKPOINTS_SAFE (b, temp) |
c5aa993b | 9318 | { |
53a5351d | 9319 | /* Format possible error msg */ |
fe3f5fa8 | 9320 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
9321 | b->number); |
9322 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 9323 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 9324 | do_cleanups (cleanups); |
c5aa993b | 9325 | } |
c906108c SS |
9326 | set_language (save_language); |
9327 | input_radix = save_input_radix; | |
e62c965a | 9328 | |
0756c555 | 9329 | jit_breakpoint_re_set (); |
4efc6507 | 9330 | |
6c95b8df PA |
9331 | do_cleanups (old_chain); |
9332 | ||
69de3c6a | 9333 | create_overlay_event_breakpoint ("_ovly_debug_event"); |
0fd8e87f UW |
9334 | create_longjmp_master_breakpoint ("longjmp"); |
9335 | create_longjmp_master_breakpoint ("_longjmp"); | |
9336 | create_longjmp_master_breakpoint ("siglongjmp"); | |
9337 | create_longjmp_master_breakpoint ("_siglongjmp"); | |
c906108c SS |
9338 | } |
9339 | \f | |
c906108c SS |
9340 | /* Reset the thread number of this breakpoint: |
9341 | ||
9342 | - If the breakpoint is for all threads, leave it as-is. | |
39f77062 | 9343 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 9344 | void |
fba45db2 | 9345 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
9346 | { |
9347 | if (b->thread != -1) | |
9348 | { | |
39f77062 KB |
9349 | if (in_thread_list (inferior_ptid)) |
9350 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
9351 | |
9352 | /* We're being called after following a fork. The new fork is | |
9353 | selected as current, and unless this was a vfork will have a | |
9354 | different program space from the original thread. Reset that | |
9355 | as well. */ | |
9356 | b->loc->pspace = current_program_space; | |
c906108c SS |
9357 | } |
9358 | } | |
9359 | ||
03ac34d5 MS |
9360 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9361 | If from_tty is nonzero, it prints a message to that effect, | |
9362 | which ends with a period (no newline). */ | |
9363 | ||
c906108c | 9364 | void |
fba45db2 | 9365 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 9366 | { |
52f0bd74 | 9367 | struct breakpoint *b; |
c906108c SS |
9368 | |
9369 | if (count < 0) | |
9370 | count = 0; | |
9371 | ||
9372 | ALL_BREAKPOINTS (b) | |
9373 | if (b->number == bptnum) | |
c5aa993b JM |
9374 | { |
9375 | b->ignore_count = count; | |
221ea385 KS |
9376 | if (from_tty) |
9377 | { | |
9378 | if (count == 0) | |
a3f17187 | 9379 | printf_filtered (_("Will stop next time breakpoint %d is reached."), |
221ea385 KS |
9380 | bptnum); |
9381 | else if (count == 1) | |
a3f17187 | 9382 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
9383 | bptnum); |
9384 | else | |
a3f17187 | 9385 | printf_filtered (_("Will ignore next %d crossings of breakpoint %d."), |
221ea385 KS |
9386 | count, bptnum); |
9387 | } | |
c5aa993b | 9388 | breakpoints_changed (); |
383f836e | 9389 | observer_notify_breakpoint_modified (b->number); |
c5aa993b JM |
9390 | return; |
9391 | } | |
c906108c | 9392 | |
8a3fe4f8 | 9393 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
9394 | } |
9395 | ||
b2175913 MS |
9396 | void |
9397 | make_breakpoint_silent (struct breakpoint *b) | |
9398 | { | |
9399 | /* Silence the breakpoint. */ | |
9400 | b->silent = 1; | |
9401 | } | |
9402 | ||
c906108c SS |
9403 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
9404 | ||
9405 | static void | |
fba45db2 | 9406 | ignore_command (char *args, int from_tty) |
c906108c SS |
9407 | { |
9408 | char *p = args; | |
52f0bd74 | 9409 | int num; |
c906108c SS |
9410 | |
9411 | if (p == 0) | |
e2e0b3e5 | 9412 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 9413 | |
c906108c | 9414 | num = get_number (&p); |
5c44784c | 9415 | if (num == 0) |
8a3fe4f8 | 9416 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 9417 | if (*p == 0) |
8a3fe4f8 | 9418 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
9419 | |
9420 | set_ignore_count (num, | |
9421 | longest_to_int (value_as_long (parse_and_eval (p))), | |
9422 | from_tty); | |
221ea385 KS |
9423 | if (from_tty) |
9424 | printf_filtered ("\n"); | |
c906108c SS |
9425 | } |
9426 | \f | |
9427 | /* Call FUNCTION on each of the breakpoints | |
9428 | whose numbers are given in ARGS. */ | |
9429 | ||
9430 | static void | |
831662b3 | 9431 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *)) |
c906108c | 9432 | { |
52f0bd74 | 9433 | char *p = args; |
c906108c | 9434 | char *p1; |
52f0bd74 AC |
9435 | int num; |
9436 | struct breakpoint *b, *tmp; | |
11cf8741 | 9437 | int match; |
c906108c SS |
9438 | |
9439 | if (p == 0) | |
e2e0b3e5 | 9440 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c SS |
9441 | |
9442 | while (*p) | |
9443 | { | |
11cf8741 | 9444 | match = 0; |
c906108c | 9445 | p1 = p; |
c5aa993b | 9446 | |
5c44784c JM |
9447 | num = get_number_or_range (&p1); |
9448 | if (num == 0) | |
c5aa993b | 9449 | { |
8a3fe4f8 | 9450 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
9451 | } |
9452 | else | |
9453 | { | |
9454 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
9455 | if (b->number == num) | |
9456 | { | |
9457 | struct breakpoint *related_breakpoint = b->related_breakpoint; | |
11cf8741 | 9458 | match = 1; |
5c44784c JM |
9459 | function (b); |
9460 | if (related_breakpoint) | |
9461 | function (related_breakpoint); | |
11cf8741 | 9462 | break; |
5c44784c | 9463 | } |
11cf8741 | 9464 | if (match == 0) |
a3f17187 | 9465 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 9466 | } |
c906108c SS |
9467 | p = p1; |
9468 | } | |
9469 | } | |
9470 | ||
0d381245 VP |
9471 | static struct bp_location * |
9472 | find_location_by_number (char *number) | |
9473 | { | |
9474 | char *dot = strchr (number, '.'); | |
9475 | char *p1; | |
9476 | int bp_num; | |
9477 | int loc_num; | |
9478 | struct breakpoint *b; | |
9479 | struct bp_location *loc; | |
9480 | ||
9481 | *dot = '\0'; | |
9482 | ||
9483 | p1 = number; | |
9484 | bp_num = get_number_or_range (&p1); | |
9485 | if (bp_num == 0) | |
9486 | error (_("Bad breakpoint number '%s'"), number); | |
9487 | ||
9488 | ALL_BREAKPOINTS (b) | |
9489 | if (b->number == bp_num) | |
9490 | { | |
9491 | break; | |
9492 | } | |
9493 | ||
9494 | if (!b || b->number != bp_num) | |
9495 | error (_("Bad breakpoint number '%s'"), number); | |
9496 | ||
9497 | p1 = dot+1; | |
9498 | loc_num = get_number_or_range (&p1); | |
9499 | if (loc_num == 0) | |
9500 | error (_("Bad breakpoint location number '%s'"), number); | |
9501 | ||
9502 | --loc_num; | |
9503 | loc = b->loc; | |
9504 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
9505 | ; | |
9506 | if (!loc) | |
9507 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
9508 | ||
9509 | return loc; | |
9510 | } | |
9511 | ||
9512 | ||
1900040c MS |
9513 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
9514 | If from_tty is nonzero, it prints a message to that effect, | |
9515 | which ends with a period (no newline). */ | |
9516 | ||
c906108c | 9517 | void |
fba45db2 | 9518 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9519 | { |
9520 | /* Never disable a watchpoint scope breakpoint; we want to | |
9521 | hit them when we leave scope so we can delete both the | |
9522 | watchpoint and its scope breakpoint at that time. */ | |
9523 | if (bpt->type == bp_watchpoint_scope) | |
9524 | return; | |
9525 | ||
c2c6d25f | 9526 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 9527 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
9528 | return; |
9529 | ||
b5de0fa7 | 9530 | bpt->enable_state = bp_disabled; |
c906108c | 9531 | |
b60e7edf | 9532 | update_global_location_list (0); |
c906108c | 9533 | |
383f836e | 9534 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9535 | } |
9536 | ||
c906108c | 9537 | static void |
fba45db2 | 9538 | disable_command (char *args, int from_tty) |
c906108c | 9539 | { |
52f0bd74 | 9540 | struct breakpoint *bpt; |
c906108c SS |
9541 | if (args == 0) |
9542 | ALL_BREAKPOINTS (bpt) | |
9543 | switch (bpt->type) | |
c5aa993b JM |
9544 | { |
9545 | case bp_none: | |
8a3fe4f8 | 9546 | warning (_("attempted to disable apparently deleted breakpoint #%d?"), |
53a5351d | 9547 | bpt->number); |
c5aa993b JM |
9548 | continue; |
9549 | case bp_breakpoint: | |
1042e4c0 | 9550 | case bp_tracepoint: |
7a697b8d | 9551 | case bp_fast_tracepoint: |
ce78b96d | 9552 | case bp_catchpoint: |
c5aa993b JM |
9553 | case bp_hardware_breakpoint: |
9554 | case bp_watchpoint: | |
9555 | case bp_hardware_watchpoint: | |
9556 | case bp_read_watchpoint: | |
9557 | case bp_access_watchpoint: | |
9558 | disable_breakpoint (bpt); | |
9559 | default: | |
9560 | continue; | |
9561 | } | |
0d381245 VP |
9562 | else if (strchr (args, '.')) |
9563 | { | |
9564 | struct bp_location *loc = find_location_by_number (args); | |
9565 | if (loc) | |
9566 | loc->enabled = 0; | |
b60e7edf | 9567 | update_global_location_list (0); |
0d381245 | 9568 | } |
c906108c SS |
9569 | else |
9570 | map_breakpoint_numbers (args, disable_breakpoint); | |
9571 | } | |
9572 | ||
9573 | static void | |
fba45db2 | 9574 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 9575 | { |
c906108c SS |
9576 | int target_resources_ok, other_type_used; |
9577 | struct value *mark; | |
9578 | ||
9579 | if (bpt->type == bp_hardware_breakpoint) | |
9580 | { | |
9581 | int i; | |
c5aa993b | 9582 | i = hw_breakpoint_used_count (); |
53a5351d | 9583 | target_resources_ok = |
d92524f1 | 9584 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 9585 | i + 1, 0); |
c906108c | 9586 | if (target_resources_ok == 0) |
8a3fe4f8 | 9587 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 9588 | else if (target_resources_ok < 0) |
8a3fe4f8 | 9589 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
9590 | } |
9591 | ||
059fb39f PM |
9592 | if (bpt->type == bp_watchpoint |
9593 | || bpt->type == bp_hardware_watchpoint | |
9594 | || bpt->type == bp_read_watchpoint | |
9595 | || bpt->type == bp_access_watchpoint) | |
c906108c | 9596 | { |
dde02812 ES |
9597 | struct gdb_exception e; |
9598 | ||
9599 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 9600 | { |
dde02812 | 9601 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 9602 | } |
dde02812 | 9603 | if (e.reason < 0) |
c5aa993b | 9604 | { |
dde02812 ES |
9605 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
9606 | bpt->number); | |
9607 | return; | |
c5aa993b | 9608 | } |
c906108c | 9609 | } |
0101ce28 | 9610 | |
b4c291bb KH |
9611 | if (bpt->enable_state != bp_permanent) |
9612 | bpt->enable_state = bp_enabled; | |
9613 | bpt->disposition = disposition; | |
b60e7edf | 9614 | update_global_location_list (1); |
b4c291bb KH |
9615 | breakpoints_changed (); |
9616 | ||
383f836e | 9617 | observer_notify_breakpoint_modified (bpt->number); |
c906108c SS |
9618 | } |
9619 | ||
fe3f5fa8 | 9620 | |
c906108c | 9621 | void |
fba45db2 | 9622 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
9623 | { |
9624 | do_enable_breakpoint (bpt, bpt->disposition); | |
9625 | } | |
9626 | ||
9627 | /* The enable command enables the specified breakpoints (or all defined | |
9628 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 9629 | in stopping the inferior. */ |
c906108c | 9630 | |
c906108c | 9631 | static void |
fba45db2 | 9632 | enable_command (char *args, int from_tty) |
c906108c | 9633 | { |
52f0bd74 | 9634 | struct breakpoint *bpt; |
c906108c SS |
9635 | if (args == 0) |
9636 | ALL_BREAKPOINTS (bpt) | |
9637 | switch (bpt->type) | |
c5aa993b JM |
9638 | { |
9639 | case bp_none: | |
8a3fe4f8 | 9640 | warning (_("attempted to enable apparently deleted breakpoint #%d?"), |
53a5351d | 9641 | bpt->number); |
c5aa993b JM |
9642 | continue; |
9643 | case bp_breakpoint: | |
1042e4c0 | 9644 | case bp_tracepoint: |
7a697b8d | 9645 | case bp_fast_tracepoint: |
ce78b96d | 9646 | case bp_catchpoint: |
c5aa993b JM |
9647 | case bp_hardware_breakpoint: |
9648 | case bp_watchpoint: | |
9649 | case bp_hardware_watchpoint: | |
9650 | case bp_read_watchpoint: | |
9651 | case bp_access_watchpoint: | |
9652 | enable_breakpoint (bpt); | |
9653 | default: | |
9654 | continue; | |
9655 | } | |
0d381245 VP |
9656 | else if (strchr (args, '.')) |
9657 | { | |
9658 | struct bp_location *loc = find_location_by_number (args); | |
9659 | if (loc) | |
9660 | loc->enabled = 1; | |
b60e7edf | 9661 | update_global_location_list (1); |
0d381245 | 9662 | } |
c906108c SS |
9663 | else |
9664 | map_breakpoint_numbers (args, enable_breakpoint); | |
9665 | } | |
9666 | ||
9667 | static void | |
fba45db2 | 9668 | enable_once_breakpoint (struct breakpoint *bpt) |
c906108c | 9669 | { |
b5de0fa7 | 9670 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
9671 | } |
9672 | ||
c906108c | 9673 | static void |
fba45db2 | 9674 | enable_once_command (char *args, int from_tty) |
c906108c SS |
9675 | { |
9676 | map_breakpoint_numbers (args, enable_once_breakpoint); | |
9677 | } | |
9678 | ||
9679 | static void | |
fba45db2 | 9680 | enable_delete_breakpoint (struct breakpoint *bpt) |
c906108c | 9681 | { |
b5de0fa7 | 9682 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
9683 | } |
9684 | ||
c906108c | 9685 | static void |
fba45db2 | 9686 | enable_delete_command (char *args, int from_tty) |
c906108c SS |
9687 | { |
9688 | map_breakpoint_numbers (args, enable_delete_breakpoint); | |
9689 | } | |
9690 | \f | |
fa8d40ab JJ |
9691 | static void |
9692 | set_breakpoint_cmd (char *args, int from_tty) | |
9693 | { | |
9694 | } | |
9695 | ||
9696 | static void | |
9697 | show_breakpoint_cmd (char *args, int from_tty) | |
9698 | { | |
9699 | } | |
9700 | ||
1f3b5d1b PP |
9701 | /* Invalidate last known value of any hardware watchpoint if |
9702 | the memory which that value represents has been written to by | |
9703 | GDB itself. */ | |
9704 | ||
9705 | static void | |
9706 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
9707 | const bfd_byte *data) | |
9708 | { | |
9709 | struct breakpoint *bp; | |
9710 | ||
9711 | ALL_BREAKPOINTS (bp) | |
9712 | if (bp->enable_state == bp_enabled | |
9713 | && bp->type == bp_hardware_watchpoint | |
9714 | && bp->val_valid && bp->val) | |
9715 | { | |
9716 | struct bp_location *loc; | |
9717 | ||
9718 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
9719 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
9720 | && loc->address + loc->length > addr | |
9721 | && addr + len > loc->address) | |
9722 | { | |
9723 | value_free (bp->val); | |
9724 | bp->val = NULL; | |
9725 | bp->val_valid = 0; | |
9726 | } | |
9727 | } | |
9728 | } | |
9729 | ||
c906108c SS |
9730 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
9731 | ||
9732 | struct symtabs_and_lines | |
fba45db2 | 9733 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
9734 | { |
9735 | struct symtabs_and_lines sals; | |
9736 | if (string == 0) | |
8a3fe4f8 | 9737 | error (_("Empty line specification.")); |
c906108c SS |
9738 | if (default_breakpoint_valid) |
9739 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
9740 | default_breakpoint_symtab, |
9741 | default_breakpoint_line, | |
68219205 | 9742 | (char ***) NULL, NULL); |
c906108c SS |
9743 | else |
9744 | sals = decode_line_1 (&string, funfirstline, | |
68219205 | 9745 | (struct symtab *) NULL, 0, (char ***) NULL, NULL); |
c906108c | 9746 | if (*string) |
8a3fe4f8 | 9747 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
9748 | return sals; |
9749 | } | |
8181d85f DJ |
9750 | |
9751 | /* Create and insert a raw software breakpoint at PC. Return an | |
9752 | identifier, which should be used to remove the breakpoint later. | |
9753 | In general, places which call this should be using something on the | |
9754 | breakpoint chain instead; this function should be eliminated | |
9755 | someday. */ | |
9756 | ||
9757 | void * | |
6c95b8df PA |
9758 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
9759 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
9760 | { |
9761 | struct bp_target_info *bp_tgt; | |
9762 | ||
6c95b8df | 9763 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 9764 | |
6c95b8df | 9765 | bp_tgt->placed_address_space = aspace; |
8181d85f | 9766 | bp_tgt->placed_address = pc; |
6c95b8df | 9767 | |
a6d9a66e | 9768 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
9769 | { |
9770 | /* Could not insert the breakpoint. */ | |
9771 | xfree (bp_tgt); | |
9772 | return NULL; | |
9773 | } | |
9774 | ||
9775 | return bp_tgt; | |
9776 | } | |
9777 | ||
9778 | /* Remove a breakpoint BP inserted by deprecated_insert_raw_breakpoint. */ | |
9779 | ||
9780 | int | |
a6d9a66e | 9781 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
9782 | { |
9783 | struct bp_target_info *bp_tgt = bp; | |
9784 | int ret; | |
9785 | ||
a6d9a66e | 9786 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
9787 | xfree (bp_tgt); |
9788 | ||
9789 | return ret; | |
9790 | } | |
9791 | ||
9792 | /* One (or perhaps two) breakpoints used for software single stepping. */ | |
9793 | ||
9794 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 9795 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
9796 | |
9797 | /* Create and insert a breakpoint for software single step. */ | |
9798 | ||
9799 | void | |
6c95b8df PA |
9800 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
9801 | struct address_space *aspace, CORE_ADDR next_pc) | |
8181d85f DJ |
9802 | { |
9803 | void **bpt_p; | |
9804 | ||
9805 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
9806 | { |
9807 | bpt_p = &single_step_breakpoints[0]; | |
9808 | single_step_gdbarch[0] = gdbarch; | |
9809 | } | |
8181d85f DJ |
9810 | else |
9811 | { | |
9812 | gdb_assert (single_step_breakpoints[1] == NULL); | |
9813 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 9814 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
9815 | } |
9816 | ||
9817 | /* NOTE drow/2006-04-11: A future improvement to this function would be | |
9818 | to only create the breakpoints once, and actually put them on the | |
9819 | breakpoint chain. That would let us use set_raw_breakpoint. We could | |
9820 | adjust the addresses each time they were needed. Doing this requires | |
9821 | corresponding changes elsewhere where single step breakpoints are | |
9822 | handled, however. So, for now, we use this. */ | |
9823 | ||
6c95b8df | 9824 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 9825 | if (*bpt_p == NULL) |
5af949e3 UW |
9826 | error (_("Could not insert single-step breakpoint at %s"), |
9827 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
9828 | } |
9829 | ||
9830 | /* Remove and delete any breakpoints used for software single step. */ | |
9831 | ||
9832 | void | |
9833 | remove_single_step_breakpoints (void) | |
9834 | { | |
9835 | gdb_assert (single_step_breakpoints[0] != NULL); | |
9836 | ||
9837 | /* See insert_single_step_breakpoint for more about this deprecated | |
9838 | call. */ | |
a6d9a66e UW |
9839 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
9840 | single_step_breakpoints[0]); | |
9841 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
9842 | single_step_breakpoints[0] = NULL; |
9843 | ||
9844 | if (single_step_breakpoints[1] != NULL) | |
9845 | { | |
a6d9a66e UW |
9846 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
9847 | single_step_breakpoints[1]); | |
9848 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
9849 | single_step_breakpoints[1] = NULL; |
9850 | } | |
9851 | } | |
9852 | ||
1aafd4da UW |
9853 | /* Check whether a software single-step breakpoint is inserted at PC. */ |
9854 | ||
9855 | static int | |
6c95b8df | 9856 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
1aafd4da UW |
9857 | { |
9858 | int i; | |
9859 | ||
9860 | for (i = 0; i < 2; i++) | |
9861 | { | |
9862 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
9863 | if (bp_tgt |
9864 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
9865 | bp_tgt->placed_address, | |
9866 | aspace, pc)) | |
1aafd4da UW |
9867 | return 1; |
9868 | } | |
9869 | ||
9870 | return 0; | |
9871 | } | |
9872 | ||
a96d9b2e SDJ |
9873 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
9874 | non-zero otherwise. */ | |
9875 | static int | |
9876 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
9877 | { | |
9878 | if (syscall_catchpoint_p (bp) | |
9879 | && bp->enable_state != bp_disabled | |
9880 | && bp->enable_state != bp_call_disabled) | |
9881 | return 1; | |
9882 | else | |
9883 | return 0; | |
9884 | } | |
9885 | ||
9886 | int | |
9887 | catch_syscall_enabled (void) | |
9888 | { | |
9889 | struct inferior *inf = current_inferior (); | |
9890 | ||
9891 | return inf->total_syscalls_count != 0; | |
9892 | } | |
9893 | ||
9894 | int | |
9895 | catching_syscall_number (int syscall_number) | |
9896 | { | |
9897 | struct breakpoint *bp; | |
9898 | ||
9899 | ALL_BREAKPOINTS (bp) | |
9900 | if (is_syscall_catchpoint_enabled (bp)) | |
9901 | { | |
9902 | if (bp->syscalls_to_be_caught) | |
9903 | { | |
9904 | int i, iter; | |
9905 | for (i = 0; | |
9906 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
9907 | i++) | |
9908 | if (syscall_number == iter) | |
9909 | return 1; | |
9910 | } | |
9911 | else | |
9912 | return 1; | |
9913 | } | |
9914 | ||
9915 | return 0; | |
9916 | } | |
9917 | ||
9918 | /* Complete syscall names. Used by "catch syscall". */ | |
9919 | static char ** | |
9920 | catch_syscall_completer (struct cmd_list_element *cmd, | |
9921 | char *text, char *word) | |
9922 | { | |
9923 | const char **list = get_syscall_names (); | |
9924 | return (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
9925 | } | |
9926 | ||
1042e4c0 SS |
9927 | /* Tracepoint-specific operations. */ |
9928 | ||
9929 | /* Set tracepoint count to NUM. */ | |
9930 | static void | |
9931 | set_tracepoint_count (int num) | |
9932 | { | |
9933 | tracepoint_count = num; | |
4fa62494 | 9934 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
9935 | } |
9936 | ||
9937 | void | |
9938 | trace_command (char *arg, int from_tty) | |
9939 | { | |
fd9b8c24 PA |
9940 | if (break_command_really (get_current_arch (), |
9941 | arg, | |
9942 | NULL, 0, 1 /* parse arg */, | |
9943 | 0 /* tempflag */, 0 /* hardwareflag */, | |
9944 | 1 /* traceflag */, | |
9945 | 0 /* Ignore count */, | |
9946 | pending_break_support, | |
9947 | NULL, | |
9948 | from_tty, | |
9949 | 1 /* enabled */)) | |
9950 | set_tracepoint_count (breakpoint_count); | |
1042e4c0 SS |
9951 | } |
9952 | ||
7a697b8d SS |
9953 | void |
9954 | ftrace_command (char *arg, int from_tty) | |
9955 | { | |
fd9b8c24 PA |
9956 | if (break_command_really (get_current_arch (), |
9957 | arg, | |
9958 | NULL, 0, 1 /* parse arg */, | |
9959 | 0 /* tempflag */, 1 /* hardwareflag */, | |
9960 | 1 /* traceflag */, | |
9961 | 0 /* Ignore count */, | |
9962 | pending_break_support, | |
9963 | NULL, | |
9964 | from_tty, | |
9965 | 1 /* enabled */)) | |
9966 | set_tracepoint_count (breakpoint_count); | |
7a697b8d SS |
9967 | } |
9968 | ||
00bf0b85 SS |
9969 | /* Given information about a tracepoint as recorded on a target (which |
9970 | can be either a live system or a trace file), attempt to create an | |
9971 | equivalent GDB tracepoint. This is not a reliable process, since | |
9972 | the target does not necessarily have all the information used when | |
9973 | the tracepoint was originally defined. */ | |
9974 | ||
9975 | struct breakpoint * | |
9976 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 SS |
9977 | { |
9978 | char buf[100]; | |
9979 | struct breakpoint *tp; | |
fd9b8c24 | 9980 | |
00bf0b85 SS |
9981 | /* In the absence of a source location, fall back to raw address. */ |
9982 | sprintf (buf, "*%s", paddress (get_current_arch(), utp->addr)); | |
d5551862 | 9983 | |
fd9b8c24 PA |
9984 | if (!break_command_really (get_current_arch (), |
9985 | buf, | |
9986 | NULL, 0, 1 /* parse arg */, | |
9987 | 0 /* tempflag */, | |
9988 | (utp->type == bp_fast_tracepoint) /* hardwareflag */, | |
9989 | 1 /* traceflag */, | |
9990 | 0 /* Ignore count */, | |
9991 | pending_break_support, | |
9992 | NULL, | |
9993 | 0 /* from_tty */, | |
9994 | utp->enabled /* enabled */)) | |
9995 | return NULL; | |
9996 | ||
00bf0b85 SS |
9997 | set_tracepoint_count (breakpoint_count); |
9998 | ||
fd9b8c24 PA |
9999 | tp = get_tracepoint (tracepoint_count); |
10000 | gdb_assert (tp != NULL); | |
d5551862 | 10001 | |
00bf0b85 SS |
10002 | if (utp->pass > 0) |
10003 | { | |
10004 | sprintf (buf, "%d %d", utp->pass, tp->number); | |
10005 | ||
10006 | trace_pass_command (buf, 0); | |
10007 | } | |
10008 | ||
10009 | if (utp->cond) | |
10010 | { | |
10011 | printf_filtered ("Want to restore a condition\n"); | |
10012 | } | |
10013 | ||
10014 | if (utp->numactions > 0) | |
10015 | { | |
10016 | printf_filtered ("Want to restore action list\n"); | |
10017 | } | |
d5551862 | 10018 | |
00bf0b85 SS |
10019 | if (utp->num_step_actions > 0) |
10020 | { | |
10021 | printf_filtered ("Want to restore action list\n"); | |
10022 | } | |
10023 | ||
10024 | return tp; | |
10025 | } | |
10026 | ||
1042e4c0 SS |
10027 | /* Print information on tracepoint number TPNUM_EXP, or all if |
10028 | omitted. */ | |
10029 | ||
10030 | static void | |
10031 | tracepoints_info (char *tpnum_exp, int from_tty) | |
10032 | { | |
10033 | struct breakpoint *b; | |
10034 | int tps_to_list = 0; | |
10035 | ||
10036 | /* In the no-arguments case, say "No tracepoints" if none found. */ | |
10037 | if (tpnum_exp == 0) | |
10038 | { | |
10039 | ALL_TRACEPOINTS (b) | |
10040 | { | |
10041 | if (b->number >= 0) | |
10042 | { | |
10043 | tps_to_list = 1; | |
10044 | break; | |
10045 | } | |
10046 | } | |
10047 | if (!tps_to_list) | |
10048 | { | |
10049 | ui_out_message (uiout, 0, "No tracepoints.\n"); | |
10050 | return; | |
10051 | } | |
10052 | } | |
10053 | ||
10054 | /* Otherwise be the same as "info break". */ | |
10055 | breakpoints_info (tpnum_exp, from_tty); | |
10056 | } | |
10057 | ||
10058 | /* The 'enable trace' command enables tracepoints. | |
10059 | Not supported by all targets. */ | |
10060 | static void | |
10061 | enable_trace_command (char *args, int from_tty) | |
10062 | { | |
10063 | enable_command (args, from_tty); | |
10064 | } | |
10065 | ||
10066 | /* The 'disable trace' command disables tracepoints. | |
10067 | Not supported by all targets. */ | |
10068 | static void | |
10069 | disable_trace_command (char *args, int from_tty) | |
10070 | { | |
10071 | disable_command (args, from_tty); | |
10072 | } | |
10073 | ||
10074 | /* Remove a tracepoint (or all if no argument) */ | |
10075 | static void | |
10076 | delete_trace_command (char *arg, int from_tty) | |
10077 | { | |
10078 | struct breakpoint *b, *temp; | |
10079 | ||
10080 | dont_repeat (); | |
10081 | ||
10082 | if (arg == 0) | |
10083 | { | |
10084 | int breaks_to_delete = 0; | |
10085 | ||
10086 | /* Delete all breakpoints if no argument. | |
10087 | Do not delete internal or call-dummy breakpoints, these | |
10088 | have to be deleted with an explicit breakpoint number argument. */ | |
10089 | ALL_TRACEPOINTS (b) | |
10090 | { | |
10091 | if (b->number >= 0) | |
10092 | { | |
10093 | breaks_to_delete = 1; | |
10094 | break; | |
10095 | } | |
10096 | } | |
10097 | ||
10098 | /* Ask user only if there are some breakpoints to delete. */ | |
10099 | if (!from_tty | |
10100 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
10101 | { | |
10102 | ALL_BREAKPOINTS_SAFE (b, temp) | |
10103 | { | |
7a697b8d | 10104 | if (tracepoint_type (b) |
059fb39f | 10105 | && b->number >= 0) |
1042e4c0 SS |
10106 | delete_breakpoint (b); |
10107 | } | |
10108 | } | |
10109 | } | |
10110 | else | |
10111 | map_breakpoint_numbers (arg, delete_breakpoint); | |
10112 | } | |
10113 | ||
10114 | /* Set passcount for tracepoint. | |
10115 | ||
10116 | First command argument is passcount, second is tracepoint number. | |
10117 | If tracepoint number omitted, apply to most recently defined. | |
10118 | Also accepts special argument "all". */ | |
10119 | ||
10120 | static void | |
10121 | trace_pass_command (char *args, int from_tty) | |
10122 | { | |
10123 | struct breakpoint *t1 = (struct breakpoint *) -1, *t2; | |
10124 | unsigned int count; | |
10125 | int all = 0; | |
10126 | ||
10127 | if (args == 0 || *args == 0) | |
10128 | error (_("passcount command requires an argument (count + optional TP num)")); | |
10129 | ||
10130 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ | |
10131 | ||
10132 | while (*args && isspace ((int) *args)) | |
10133 | args++; | |
10134 | ||
10135 | if (*args && strncasecmp (args, "all", 3) == 0) | |
10136 | { | |
10137 | args += 3; /* Skip special argument "all". */ | |
10138 | all = 1; | |
10139 | if (*args) | |
10140 | error (_("Junk at end of arguments.")); | |
10141 | } | |
10142 | else | |
10143 | t1 = get_tracepoint_by_number (&args, 1, 1); | |
10144 | ||
10145 | do | |
10146 | { | |
10147 | if (t1) | |
10148 | { | |
10149 | ALL_TRACEPOINTS (t2) | |
10150 | if (t1 == (struct breakpoint *) -1 || t1 == t2) | |
10151 | { | |
10152 | t2->pass_count = count; | |
10153 | observer_notify_tracepoint_modified (t2->number); | |
10154 | if (from_tty) | |
10155 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
10156 | t2->number, count); | |
10157 | } | |
10158 | if (! all && *args) | |
10159 | t1 = get_tracepoint_by_number (&args, 1, 0); | |
10160 | } | |
10161 | } | |
10162 | while (*args); | |
10163 | } | |
10164 | ||
10165 | struct breakpoint * | |
10166 | get_tracepoint (int num) | |
10167 | { | |
10168 | struct breakpoint *t; | |
10169 | ||
10170 | ALL_TRACEPOINTS (t) | |
10171 | if (t->number == num) | |
10172 | return t; | |
10173 | ||
10174 | return NULL; | |
10175 | } | |
10176 | ||
d5551862 SS |
10177 | /* Find the tracepoint with the given target-side number (which may be |
10178 | different from the tracepoint number after disconnecting and | |
10179 | reconnecting). */ | |
10180 | ||
10181 | struct breakpoint * | |
10182 | get_tracepoint_by_number_on_target (int num) | |
10183 | { | |
10184 | struct breakpoint *t; | |
10185 | ||
10186 | ALL_TRACEPOINTS (t) | |
10187 | if (t->number_on_target == num) | |
10188 | return t; | |
10189 | ||
10190 | return NULL; | |
10191 | } | |
10192 | ||
1042e4c0 SS |
10193 | /* Utility: parse a tracepoint number and look it up in the list. |
10194 | If MULTI_P is true, there might be a range of tracepoints in ARG. | |
10195 | if OPTIONAL_P is true, then if the argument is missing, the most | |
10196 | recent tracepoint (tracepoint_count) is returned. */ | |
10197 | struct breakpoint * | |
10198 | get_tracepoint_by_number (char **arg, int multi_p, int optional_p) | |
10199 | { | |
10200 | extern int tracepoint_count; | |
10201 | struct breakpoint *t; | |
10202 | int tpnum; | |
10203 | char *instring = arg == NULL ? NULL : *arg; | |
10204 | ||
10205 | if (arg == NULL || *arg == NULL || ! **arg) | |
10206 | { | |
10207 | if (optional_p) | |
10208 | tpnum = tracepoint_count; | |
10209 | else | |
10210 | error_no_arg (_("tracepoint number")); | |
10211 | } | |
10212 | else | |
10213 | tpnum = multi_p ? get_number_or_range (arg) : get_number (arg); | |
10214 | ||
10215 | if (tpnum <= 0) | |
10216 | { | |
10217 | if (instring && *instring) | |
10218 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
10219 | instring); | |
10220 | else | |
10221 | printf_filtered (_("Tracepoint argument missing and no previous tracepoint\n")); | |
10222 | return NULL; | |
10223 | } | |
10224 | ||
10225 | ALL_TRACEPOINTS (t) | |
10226 | if (t->number == tpnum) | |
10227 | { | |
10228 | return t; | |
10229 | } | |
10230 | ||
10231 | /* FIXME: if we are in the middle of a range we don't want to give | |
10232 | a message. The current interface to get_number_or_range doesn't | |
10233 | allow us to discover this. */ | |
10234 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); | |
10235 | return NULL; | |
10236 | } | |
10237 | ||
10238 | /* save-tracepoints command */ | |
10239 | static void | |
10240 | tracepoint_save_command (char *args, int from_tty) | |
10241 | { | |
10242 | struct breakpoint *tp; | |
10243 | int any_tp = 0; | |
10244 | struct action_line *line; | |
10245 | FILE *fp; | |
10246 | char *i1 = " ", *i2 = " "; | |
10247 | char *indent, *actionline, *pathname; | |
10248 | char tmp[40]; | |
10249 | struct cleanup *cleanup; | |
10250 | ||
10251 | if (args == 0 || *args == 0) | |
10252 | error (_("Argument required (file name in which to save tracepoints)")); | |
10253 | ||
10254 | /* See if we have anything to save. */ | |
10255 | ALL_TRACEPOINTS (tp) | |
10256 | { | |
10257 | any_tp = 1; | |
10258 | break; | |
10259 | } | |
10260 | if (!any_tp) | |
10261 | { | |
10262 | warning (_("save-tracepoints: no tracepoints to save.")); | |
10263 | return; | |
10264 | } | |
10265 | ||
10266 | pathname = tilde_expand (args); | |
10267 | cleanup = make_cleanup (xfree, pathname); | |
059fb39f PM |
10268 | fp = fopen (pathname, "w"); |
10269 | if (!fp) | |
1042e4c0 SS |
10270 | error (_("Unable to open file '%s' for saving tracepoints (%s)"), |
10271 | args, safe_strerror (errno)); | |
10272 | make_cleanup_fclose (fp); | |
10273 | ||
10274 | ALL_TRACEPOINTS (tp) | |
10275 | { | |
10276 | if (tp->addr_string) | |
10277 | fprintf (fp, "trace %s\n", tp->addr_string); | |
10278 | else | |
10279 | { | |
10280 | sprintf_vma (tmp, tp->loc->address); | |
10281 | fprintf (fp, "trace *0x%s\n", tmp); | |
10282 | } | |
10283 | ||
10284 | if (tp->pass_count) | |
10285 | fprintf (fp, " passcount %d\n", tp->pass_count); | |
10286 | ||
10287 | if (tp->actions) | |
10288 | { | |
10289 | fprintf (fp, " actions\n"); | |
10290 | indent = i1; | |
10291 | for (line = tp->actions; line; line = line->next) | |
10292 | { | |
10293 | struct cmd_list_element *cmd; | |
10294 | ||
10295 | QUIT; /* allow user to bail out with ^C */ | |
10296 | actionline = line->action; | |
10297 | while (isspace ((int) *actionline)) | |
10298 | actionline++; | |
10299 | ||
10300 | fprintf (fp, "%s%s\n", indent, actionline); | |
10301 | if (*actionline != '#') /* skip for comment lines */ | |
10302 | { | |
10303 | cmd = lookup_cmd (&actionline, cmdlist, "", -1, 1); | |
10304 | if (cmd == 0) | |
10305 | error (_("Bad action list item: %s"), actionline); | |
10306 | if (cmd_cfunc_eq (cmd, while_stepping_pseudocommand)) | |
10307 | indent = i2; | |
10308 | else if (cmd_cfunc_eq (cmd, end_actions_pseudocommand)) | |
10309 | indent = i1; | |
10310 | } | |
10311 | } | |
10312 | } | |
10313 | } | |
10314 | do_cleanups (cleanup); | |
10315 | if (from_tty) | |
10316 | printf_filtered (_("Tracepoints saved to file '%s'.\n"), args); | |
10317 | return; | |
10318 | } | |
10319 | ||
10320 | /* Create a vector of all tracepoints. */ | |
10321 | ||
10322 | VEC(breakpoint_p) * | |
10323 | all_tracepoints () | |
10324 | { | |
10325 | VEC(breakpoint_p) *tp_vec = 0; | |
10326 | struct breakpoint *tp; | |
10327 | ||
10328 | ALL_TRACEPOINTS (tp) | |
10329 | { | |
10330 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
10331 | } | |
10332 | ||
10333 | return tp_vec; | |
10334 | } | |
10335 | ||
c906108c | 10336 | \f |
31e2b00f AS |
10337 | /* This help string is used for the break, hbreak, tbreak and thbreak commands. |
10338 | It is defined as a macro to prevent duplication. | |
10339 | COMMAND should be a string constant containing the name of the command. */ | |
10340 | #define BREAK_ARGS_HELP(command) \ | |
10341 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
10342 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
10343 | If a line number is specified, break at start of code for that line.\n\ | |
10344 | If a function is specified, break at start of code for that function.\n\ | |
10345 | If an address is specified, break at that exact address.\n\ | |
10346 | With no LOCATION, uses current execution address of selected stack frame.\n\ | |
10347 | This is useful for breaking on return to a stack frame.\n\ | |
10348 | \n\ | |
10349 | THREADNUM is the number from \"info threads\".\n\ | |
10350 | CONDITION is a boolean expression.\n\ | |
10351 | \n\ | |
10352 | Multiple breakpoints at one place are permitted, and useful if conditional.\n\ | |
10353 | \n\ | |
10354 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
10355 | ||
44feb3ce TT |
10356 | /* List of subcommands for "catch". */ |
10357 | static struct cmd_list_element *catch_cmdlist; | |
10358 | ||
10359 | /* List of subcommands for "tcatch". */ | |
10360 | static struct cmd_list_element *tcatch_cmdlist; | |
10361 | ||
10362 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
10363 | lists, and pass some additional user data to the command function. */ | |
10364 | static void | |
10365 | add_catch_command (char *name, char *docstring, | |
10366 | void (*sfunc) (char *args, int from_tty, | |
10367 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
10368 | char **(*completer) (struct cmd_list_element *cmd, |
10369 | char *text, char *word), | |
44feb3ce TT |
10370 | void *user_data_catch, |
10371 | void *user_data_tcatch) | |
10372 | { | |
10373 | struct cmd_list_element *command; | |
10374 | ||
10375 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10376 | &catch_cmdlist); | |
10377 | set_cmd_sfunc (command, sfunc); | |
10378 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 10379 | set_cmd_completer (command, completer); |
44feb3ce TT |
10380 | |
10381 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
10382 | &tcatch_cmdlist); | |
10383 | set_cmd_sfunc (command, sfunc); | |
10384 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 10385 | set_cmd_completer (command, completer); |
44feb3ce TT |
10386 | } |
10387 | ||
6c95b8df | 10388 | static void |
a79b8f6e | 10389 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 10390 | { |
6c95b8df PA |
10391 | inf->total_syscalls_count = 0; |
10392 | inf->any_syscall_count = 0; | |
10393 | VEC_free (int, inf->syscalls_counts); | |
10394 | } | |
10395 | ||
c906108c | 10396 | void |
fba45db2 | 10397 | _initialize_breakpoint (void) |
c906108c | 10398 | { |
fa8d40ab JJ |
10399 | static struct cmd_list_element *breakpoint_set_cmdlist; |
10400 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
c906108c SS |
10401 | struct cmd_list_element *c; |
10402 | ||
84acb35a | 10403 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 10404 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 10405 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 10406 | |
c906108c SS |
10407 | breakpoint_chain = 0; |
10408 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
10409 | before a breakpoint is set. */ | |
10410 | breakpoint_count = 0; | |
10411 | ||
1042e4c0 SS |
10412 | tracepoint_count = 0; |
10413 | ||
1bedd215 AC |
10414 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
10415 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
10416 | Usage is `ignore N COUNT'.")); | |
c906108c | 10417 | if (xdb_commands) |
c5aa993b | 10418 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 10419 | |
1bedd215 AC |
10420 | add_com ("commands", class_breakpoint, commands_command, _("\ |
10421 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
10422 | Give breakpoint number as argument after \"commands\".\n\ |
10423 | With no argument, the targeted breakpoint is the last one set.\n\ | |
10424 | The commands themselves follow starting on the next line.\n\ | |
10425 | Type a line containing \"end\" to indicate the end of them.\n\ | |
10426 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 10427 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 10428 | |
1bedd215 AC |
10429 | add_com ("condition", class_breakpoint, condition_command, _("\ |
10430 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 10431 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 10432 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 10433 | |
1bedd215 | 10434 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 10435 | Set a temporary breakpoint.\n\ |
c906108c SS |
10436 | Like \"break\" except the breakpoint is only temporary,\n\ |
10437 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
10438 | by using \"enable delete\" on the breakpoint number.\n\ |
10439 | \n" | |
10440 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 10441 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10442 | |
1bedd215 | 10443 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
31e2b00f | 10444 | Set a hardware assisted breakpoint.\n\ |
c906108c | 10445 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
10446 | some target hardware may not have this support.\n\ |
10447 | \n" | |
10448 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 10449 | set_cmd_completer (c, location_completer); |
c906108c | 10450 | |
1bedd215 | 10451 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 10452 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 10453 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
10454 | so it will be deleted when hit.\n\ |
10455 | \n" | |
10456 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 10457 | set_cmd_completer (c, location_completer); |
c906108c | 10458 | |
1bedd215 AC |
10459 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
10460 | Enable some breakpoints.\n\ | |
c906108c SS |
10461 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10462 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10463 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10464 | With a subcommand you can enable temporarily."), |
c906108c SS |
10465 | &enablelist, "enable ", 1, &cmdlist); |
10466 | if (xdb_commands) | |
1bedd215 AC |
10467 | add_com ("ab", class_breakpoint, enable_command, _("\ |
10468 | Enable some breakpoints.\n\ | |
c906108c SS |
10469 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10470 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
10471 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10472 | With a subcommand you can enable temporarily.")); |
c906108c SS |
10473 | |
10474 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
10475 | ||
1bedd215 AC |
10476 | add_abbrev_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
10477 | Enable some breakpoints.\n\ | |
c906108c SS |
10478 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
10479 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 10480 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 10481 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 10482 | |
1a966eab AC |
10483 | add_cmd ("once", no_class, enable_once_command, _("\ |
10484 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10485 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10486 | &enablebreaklist); |
10487 | ||
1a966eab AC |
10488 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10489 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10490 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10491 | &enablebreaklist); |
10492 | ||
1a966eab AC |
10493 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
10494 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
10495 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
10496 | &enablelist); |
10497 | ||
1a966eab AC |
10498 | add_cmd ("once", no_class, enable_once_command, _("\ |
10499 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
10500 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
10501 | &enablelist); |
10502 | ||
1bedd215 AC |
10503 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
10504 | Disable some breakpoints.\n\ | |
c906108c SS |
10505 | Arguments are breakpoint numbers with spaces in between.\n\ |
10506 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10507 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
10508 | &disablelist, "disable ", 1, &cmdlist); |
10509 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
10510 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
10511 | if (xdb_commands) | |
1bedd215 AC |
10512 | add_com ("sb", class_breakpoint, disable_command, _("\ |
10513 | Disable some breakpoints.\n\ | |
c906108c SS |
10514 | Arguments are breakpoint numbers with spaces in between.\n\ |
10515 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 10516 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 10517 | |
1a966eab AC |
10518 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
10519 | Disable some breakpoints.\n\ | |
c906108c SS |
10520 | Arguments are breakpoint numbers with spaces in between.\n\ |
10521 | To disable all breakpoints, give no argument.\n\ | |
10522 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 10523 | This command may be abbreviated \"disable\"."), |
c906108c SS |
10524 | &disablelist); |
10525 | ||
1bedd215 AC |
10526 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
10527 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10528 | Arguments are breakpoint numbers with spaces in between.\n\ |
10529 | To delete all breakpoints, give no argument.\n\ | |
10530 | \n\ | |
10531 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 10532 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
10533 | &deletelist, "delete ", 1, &cmdlist); |
10534 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 10535 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 10536 | if (xdb_commands) |
1bedd215 AC |
10537 | add_com ("db", class_breakpoint, delete_command, _("\ |
10538 | Delete some breakpoints.\n\ | |
c906108c | 10539 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 10540 | To delete all breakpoints, give no argument.\n")); |
c906108c | 10541 | |
1a966eab AC |
10542 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
10543 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
10544 | Arguments are breakpoint numbers with spaces in between.\n\ |
10545 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 10546 | This command may be abbreviated \"delete\"."), |
c906108c SS |
10547 | &deletelist); |
10548 | ||
1bedd215 AC |
10549 | add_com ("clear", class_breakpoint, clear_command, _("\ |
10550 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
10551 | Argument may be line number, function name, or \"*\" and an address.\n\ |
10552 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
10553 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
10554 | If an address is specified, breakpoints at that address are cleared.\n\ |
10555 | \n\ | |
10556 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
10557 | is executing in.\n\ |
10558 | \n\ | |
1bedd215 | 10559 | See also the \"delete\" command which clears breakpoints by number.")); |
c906108c | 10560 | |
1bedd215 | 10561 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
10562 | Set breakpoint at specified line or function.\n" |
10563 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 10564 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 10565 | |
c906108c SS |
10566 | add_com_alias ("b", "break", class_run, 1); |
10567 | add_com_alias ("br", "break", class_run, 1); | |
10568 | add_com_alias ("bre", "break", class_run, 1); | |
10569 | add_com_alias ("brea", "break", class_run, 1); | |
10570 | ||
7681d515 PM |
10571 | if (xdb_commands) |
10572 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
10573 | |
10574 | if (dbx_commands) | |
10575 | { | |
1bedd215 AC |
10576 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
10577 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
10578 | &stoplist, "stop ", 1, &cmdlist); |
10579 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 10580 | _("Break in function or address."), &stoplist); |
c5aa993b | 10581 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 10582 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
10583 | add_com ("status", class_info, breakpoints_info, _("\ |
10584 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10585 | The \"Type\" column indicates one of:\n\ |
10586 | \tbreakpoint - normal breakpoint\n\ | |
10587 | \twatchpoint - watchpoint\n\ | |
10588 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10589 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10590 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10591 | address and file/line number respectively.\n\ |
10592 | \n\ | |
10593 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10594 | are set to the address of the last breakpoint listed unless the command\n\ |
10595 | is prefixed with \"server \".\n\n\ | |
c906108c | 10596 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10597 | breakpoint set.")); |
c906108c SS |
10598 | } |
10599 | ||
1bedd215 AC |
10600 | add_info ("breakpoints", breakpoints_info, _("\ |
10601 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10602 | The \"Type\" column indicates one of:\n\ |
10603 | \tbreakpoint - normal breakpoint\n\ | |
10604 | \twatchpoint - watchpoint\n\ | |
10605 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10606 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10607 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10608 | address and file/line number respectively.\n\ |
10609 | \n\ | |
10610 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10611 | are set to the address of the last breakpoint listed unless the command\n\ |
10612 | is prefixed with \"server \".\n\n\ | |
c906108c | 10613 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10614 | breakpoint set.")); |
c906108c | 10615 | |
6b04bdb7 MS |
10616 | add_info_alias ("b", "breakpoints", 1); |
10617 | ||
c906108c | 10618 | if (xdb_commands) |
1bedd215 AC |
10619 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
10620 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10621 | The \"Type\" column indicates one of:\n\ |
10622 | \tbreakpoint - normal breakpoint\n\ | |
10623 | \twatchpoint - watchpoint\n\ | |
10624 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
10625 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
10626 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
10627 | address and file/line number respectively.\n\ |
10628 | \n\ | |
10629 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10630 | are set to the address of the last breakpoint listed unless the command\n\ |
10631 | is prefixed with \"server \".\n\n\ | |
c906108c | 10632 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 10633 | breakpoint set.")); |
c906108c | 10634 | |
1a966eab AC |
10635 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
10636 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
10637 | The \"Type\" column indicates one of:\n\ |
10638 | \tbreakpoint - normal breakpoint\n\ | |
10639 | \twatchpoint - watchpoint\n\ | |
10640 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
10641 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
10642 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
10643 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
10644 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
10645 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
10646 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
10647 | address and file/line number respectively.\n\ |
10648 | \n\ | |
10649 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
10650 | are set to the address of the last breakpoint listed unless the command\n\ |
10651 | is prefixed with \"server \".\n\n\ | |
c906108c | 10652 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 10653 | breakpoint set."), |
c906108c SS |
10654 | &maintenanceinfolist); |
10655 | ||
44feb3ce TT |
10656 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
10657 | Set catchpoints to catch events."), | |
10658 | &catch_cmdlist, "catch ", | |
10659 | 0/*allow-unknown*/, &cmdlist); | |
10660 | ||
10661 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
10662 | Set temporary catchpoints to catch events."), | |
10663 | &tcatch_cmdlist, "tcatch ", | |
10664 | 0/*allow-unknown*/, &cmdlist); | |
10665 | ||
10666 | /* Add catch and tcatch sub-commands. */ | |
10667 | add_catch_command ("catch", _("\ | |
10668 | Catch an exception, when caught.\n\ | |
10669 | With an argument, catch only exceptions with the given name."), | |
10670 | catch_catch_command, | |
a96d9b2e | 10671 | NULL, |
44feb3ce TT |
10672 | CATCH_PERMANENT, |
10673 | CATCH_TEMPORARY); | |
10674 | add_catch_command ("throw", _("\ | |
10675 | Catch an exception, when thrown.\n\ | |
10676 | With an argument, catch only exceptions with the given name."), | |
10677 | catch_throw_command, | |
a96d9b2e | 10678 | NULL, |
44feb3ce TT |
10679 | CATCH_PERMANENT, |
10680 | CATCH_TEMPORARY); | |
10681 | add_catch_command ("fork", _("Catch calls to fork."), | |
10682 | catch_fork_command_1, | |
a96d9b2e | 10683 | NULL, |
44feb3ce TT |
10684 | (void *) (uintptr_t) catch_fork_permanent, |
10685 | (void *) (uintptr_t) catch_fork_temporary); | |
10686 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
10687 | catch_fork_command_1, | |
a96d9b2e | 10688 | NULL, |
44feb3ce TT |
10689 | (void *) (uintptr_t) catch_vfork_permanent, |
10690 | (void *) (uintptr_t) catch_vfork_temporary); | |
10691 | add_catch_command ("exec", _("Catch calls to exec."), | |
10692 | catch_exec_command_1, | |
a96d9b2e SDJ |
10693 | NULL, |
10694 | CATCH_PERMANENT, | |
10695 | CATCH_TEMPORARY); | |
10696 | add_catch_command ("syscall", _("\ | |
10697 | Catch system calls by their names and/or numbers.\n\ | |
10698 | Arguments say which system calls to catch. If no arguments\n\ | |
10699 | are given, every system call will be caught.\n\ | |
10700 | Arguments, if given, should be one or more system call names\n\ | |
10701 | (if your system supports that), or system call numbers."), | |
10702 | catch_syscall_command_1, | |
10703 | catch_syscall_completer, | |
44feb3ce TT |
10704 | CATCH_PERMANENT, |
10705 | CATCH_TEMPORARY); | |
44feb3ce TT |
10706 | add_catch_command ("exception", _("\ |
10707 | Catch Ada exceptions, when raised.\n\ | |
10708 | With an argument, catch only exceptions with the given name."), | |
10709 | catch_ada_exception_command, | |
a96d9b2e | 10710 | NULL, |
44feb3ce TT |
10711 | CATCH_PERMANENT, |
10712 | CATCH_TEMPORARY); | |
10713 | add_catch_command ("assert", _("\ | |
10714 | Catch failed Ada assertions, when raised.\n\ | |
10715 | With an argument, catch only exceptions with the given name."), | |
10716 | catch_assert_command, | |
a96d9b2e | 10717 | NULL, |
44feb3ce TT |
10718 | CATCH_PERMANENT, |
10719 | CATCH_TEMPORARY); | |
c5aa993b | 10720 | |
1bedd215 AC |
10721 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
10722 | Set a watchpoint for an expression.\n\ | |
c906108c | 10723 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10724 | an expression changes.")); |
65d12d83 | 10725 | set_cmd_completer (c, expression_completer); |
c906108c | 10726 | |
1bedd215 AC |
10727 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
10728 | Set a read watchpoint for an expression.\n\ | |
c906108c | 10729 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10730 | an expression is read.")); |
65d12d83 | 10731 | set_cmd_completer (c, expression_completer); |
c906108c | 10732 | |
1bedd215 AC |
10733 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
10734 | Set a watchpoint for an expression.\n\ | |
c906108c | 10735 | A watchpoint stops execution of your program whenever the value of\n\ |
1bedd215 | 10736 | an expression is either read or written.")); |
65d12d83 | 10737 | set_cmd_completer (c, expression_completer); |
c906108c SS |
10738 | |
10739 | add_info ("watchpoints", breakpoints_info, | |
1bedd215 | 10740 | _("Synonym for ``info breakpoints''.")); |
c906108c SS |
10741 | |
10742 | ||
920d2a44 AC |
10743 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
10744 | respond to changes - contrary to the description. */ | |
85c07804 AC |
10745 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
10746 | &can_use_hw_watchpoints, _("\ | |
10747 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
10748 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
10749 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
10750 | such is available. (However, any hardware watchpoints that were\n\ | |
10751 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
10752 | hardware.)"), |
10753 | NULL, | |
920d2a44 | 10754 | show_can_use_hw_watchpoints, |
85c07804 | 10755 | &setlist, &showlist); |
c906108c SS |
10756 | |
10757 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 10758 | |
1042e4c0 SS |
10759 | /* Tracepoint manipulation commands. */ |
10760 | ||
10761 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
10762 | Set a tracepoint at specified line or function.\n\ | |
10763 | \n" | |
10764 | BREAK_ARGS_HELP ("trace") "\n\ | |
10765 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
10766 | set_cmd_completer (c, location_completer); | |
10767 | ||
10768 | add_com_alias ("tp", "trace", class_alias, 0); | |
10769 | add_com_alias ("tr", "trace", class_alias, 1); | |
10770 | add_com_alias ("tra", "trace", class_alias, 1); | |
10771 | add_com_alias ("trac", "trace", class_alias, 1); | |
10772 | ||
7a697b8d SS |
10773 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
10774 | Set a fast tracepoint at specified line or function.\n\ | |
10775 | \n" | |
10776 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
10777 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
10778 | set_cmd_completer (c, location_completer); | |
10779 | ||
1042e4c0 SS |
10780 | add_info ("tracepoints", tracepoints_info, _("\ |
10781 | Status of tracepoints, or tracepoint number NUMBER.\n\ | |
10782 | Convenience variable \"$tpnum\" contains the number of the\n\ | |
10783 | last tracepoint set.")); | |
10784 | ||
10785 | add_info_alias ("tp", "tracepoints", 1); | |
10786 | ||
10787 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
10788 | Delete specified tracepoints.\n\ | |
10789 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10790 | No argument means delete all tracepoints."), | |
10791 | &deletelist); | |
10792 | ||
10793 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
10794 | Disable specified tracepoints.\n\ | |
10795 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10796 | No argument means disable all tracepoints."), | |
10797 | &disablelist); | |
10798 | deprecate_cmd (c, "disable"); | |
10799 | ||
10800 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
10801 | Enable specified tracepoints.\n\ | |
10802 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
10803 | No argument means enable all tracepoints."), | |
10804 | &enablelist); | |
10805 | deprecate_cmd (c, "enable"); | |
10806 | ||
10807 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
10808 | Set the passcount for a tracepoint.\n\ | |
10809 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
10810 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
10811 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
10812 | ||
10813 | c = add_com ("save-tracepoints", class_trace, tracepoint_save_command, _("\ | |
10814 | Save current tracepoint definitions as a script.\n\ | |
10815 | Use the 'source' command in another debug session to restore them.")); | |
10816 | set_cmd_completer (c, filename_completer); | |
10817 | ||
1bedd215 | 10818 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10819 | Breakpoint specific settings\n\ |
10820 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10821 | pending breakpoint behavior"), |
fa8d40ab JJ |
10822 | &breakpoint_set_cmdlist, "set breakpoint ", |
10823 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 10824 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
10825 | Breakpoint specific settings\n\ |
10826 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 10827 | pending breakpoint behavior"), |
fa8d40ab JJ |
10828 | &breakpoint_show_cmdlist, "show breakpoint ", |
10829 | 0/*allow-unknown*/, &showlist); | |
10830 | ||
7915a72c AC |
10831 | add_setshow_auto_boolean_cmd ("pending", no_class, |
10832 | &pending_break_support, _("\ | |
10833 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
10834 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
10835 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
10836 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
10837 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 10838 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 10839 | NULL, |
920d2a44 | 10840 | show_pending_break_support, |
6e1d7d6c AC |
10841 | &breakpoint_set_cmdlist, |
10842 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
10843 | |
10844 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
10845 | |
10846 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
10847 | &automatic_hardware_breakpoints, _("\ | |
10848 | Set automatic usage of hardware breakpoints."), _("\ | |
10849 | Show automatic usage of hardware breakpoints."), _("\ | |
10850 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
10851 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
10852 | a warning will be emitted for such breakpoints."), | |
10853 | NULL, | |
10854 | show_automatic_hardware_breakpoints, | |
10855 | &breakpoint_set_cmdlist, | |
10856 | &breakpoint_show_cmdlist); | |
74960c60 | 10857 | |
33e5cbd6 PA |
10858 | add_setshow_enum_cmd ("always-inserted", class_support, |
10859 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
10860 | Set mode for inserting breakpoints."), _("\ |
10861 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
10862 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
10863 | resumed, and removed when execution stops. When this mode is on,\n\ | |
10864 | breakpoints are inserted immediately and removed only when the user\n\ | |
10865 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
10866 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
10867 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
10868 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
10869 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
10870 | NULL, |
10871 | &show_always_inserted_mode, | |
10872 | &breakpoint_set_cmdlist, | |
10873 | &breakpoint_show_cmdlist); | |
765dc015 VP |
10874 | |
10875 | automatic_hardware_breakpoints = 1; | |
f3b1572e PA |
10876 | |
10877 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 10878 | } |