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, |
7b6bb8da | 5 | 2008, 2009, 2010, 2011 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" | |
0ba1096a | 42 | #include "filenames.h" |
c906108c SS |
43 | #include "annotate.h" |
44 | #include "symfile.h" | |
45 | #include "objfiles.h" | |
0378c332 | 46 | #include "source.h" |
c5f0f3d0 | 47 | #include "linespec.h" |
c94fdfd0 | 48 | #include "completer.h" |
5b7f31a4 | 49 | #include "gdb.h" |
8b93c638 | 50 | #include "ui-out.h" |
e1507482 | 51 | #include "cli/cli-script.h" |
0225421b | 52 | #include "gdb_assert.h" |
fe898f56 | 53 | #include "block.h" |
a77053c2 | 54 | #include "solib.h" |
84acb35a JJ |
55 | #include "solist.h" |
56 | #include "observer.h" | |
60250e8b | 57 | #include "exceptions.h" |
765dc015 | 58 | #include "memattr.h" |
f7f9143b | 59 | #include "ada-lang.h" |
d1aa2f50 | 60 | #include "top.h" |
fa4727a6 | 61 | #include "wrapper.h" |
79a45b7d | 62 | #include "valprint.h" |
4efc6507 | 63 | #include "jit.h" |
a96d9b2e | 64 | #include "xml-syscall.h" |
65d79d4b | 65 | #include "parser-defs.h" |
e9cafbcc | 66 | #include "cli/cli-utils.h" |
c906108c | 67 | |
1042e4c0 SS |
68 | /* readline include files */ |
69 | #include "readline/readline.h" | |
70 | #include "readline/history.h" | |
71 | ||
72 | /* readline defines this. */ | |
73 | #undef savestring | |
74 | ||
034dad6f | 75 | #include "mi/mi-common.h" |
7371cf6d | 76 | #include "python/python.h" |
104c1213 | 77 | |
44feb3ce TT |
78 | /* Arguments to pass as context to some catch command handlers. */ |
79 | #define CATCH_PERMANENT ((void *) (uintptr_t) 0) | |
80 | #define CATCH_TEMPORARY ((void *) (uintptr_t) 1) | |
c906108c | 81 | |
4a64f543 | 82 | /* Prototypes for local functions. */ |
c906108c | 83 | |
a14ed312 | 84 | static void enable_delete_command (char *, int); |
c906108c | 85 | |
a14ed312 | 86 | static void enable_once_command (char *, int); |
c906108c | 87 | |
a14ed312 | 88 | static void disable_command (char *, int); |
c906108c | 89 | |
a14ed312 | 90 | static void enable_command (char *, int); |
c906108c | 91 | |
95a42b64 TT |
92 | static void map_breakpoint_numbers (char *, void (*) (struct breakpoint *, |
93 | void *), | |
94 | void *); | |
c906108c | 95 | |
a14ed312 | 96 | static void ignore_command (char *, int); |
c906108c | 97 | |
4efb68b1 | 98 | static int breakpoint_re_set_one (void *); |
c906108c | 99 | |
a14ed312 | 100 | static void clear_command (char *, int); |
c906108c | 101 | |
a14ed312 | 102 | static void catch_command (char *, int); |
c906108c | 103 | |
a9634178 | 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 | |
4a64f543 MS |
110 | /* This function is used in gdbtk sources and thus can not be made |
111 | static. */ | |
63c252f8 | 112 | struct breakpoint *set_raw_breakpoint (struct gdbarch *gdbarch, |
a6d9a66e UW |
113 | struct symtab_and_line, |
114 | enum bptype); | |
c906108c | 115 | |
76897487 KB |
116 | static void breakpoint_adjustment_warning (CORE_ADDR, CORE_ADDR, int, int); |
117 | ||
a6d9a66e UW |
118 | static CORE_ADDR adjust_breakpoint_address (struct gdbarch *gdbarch, |
119 | CORE_ADDR bpaddr, | |
88f7da05 | 120 | enum bptype bptype); |
76897487 | 121 | |
6c95b8df PA |
122 | static void describe_other_breakpoints (struct gdbarch *, |
123 | struct program_space *, CORE_ADDR, | |
5af949e3 | 124 | struct obj_section *, int); |
c906108c | 125 | |
6c95b8df PA |
126 | static int breakpoint_address_match (struct address_space *aspace1, |
127 | CORE_ADDR addr1, | |
128 | struct address_space *aspace2, | |
129 | CORE_ADDR addr2); | |
130 | ||
85d721b8 PA |
131 | static int watchpoint_locations_match (struct bp_location *loc1, |
132 | struct bp_location *loc2); | |
133 | ||
f1310107 TJB |
134 | static int breakpoint_location_address_match (struct bp_location *bl, |
135 | struct address_space *aspace, | |
136 | CORE_ADDR addr); | |
137 | ||
a14ed312 | 138 | static void breakpoints_info (char *, int); |
c906108c | 139 | |
d77f58be SS |
140 | static void watchpoints_info (char *, int); |
141 | ||
e5a67952 MS |
142 | static int breakpoint_1 (char *, int, |
143 | int (*) (const struct breakpoint *)); | |
c906108c | 144 | |
4efb68b1 | 145 | static int breakpoint_cond_eval (void *); |
c906108c | 146 | |
4efb68b1 | 147 | static void cleanup_executing_breakpoints (void *); |
c906108c | 148 | |
a14ed312 | 149 | static void commands_command (char *, int); |
c906108c | 150 | |
a14ed312 | 151 | static void condition_command (char *, int); |
c906108c | 152 | |
c5aa993b JM |
153 | typedef enum |
154 | { | |
155 | mark_inserted, | |
156 | mark_uninserted | |
157 | } | |
158 | insertion_state_t; | |
c906108c | 159 | |
0bde7532 | 160 | static int remove_breakpoint (struct bp_location *, insertion_state_t); |
6c95b8df | 161 | static int remove_breakpoint_1 (struct bp_location *, insertion_state_t); |
c906108c | 162 | |
a14ed312 | 163 | static enum print_stop_action print_it_typical (bpstat); |
e514a9d6 JM |
164 | |
165 | static enum print_stop_action print_bp_stop_message (bpstat bs); | |
c906108c | 166 | |
4efb68b1 | 167 | static int watchpoint_check (void *); |
c906108c | 168 | |
a14ed312 | 169 | static void maintenance_info_breakpoints (char *, int); |
c906108c | 170 | |
a14ed312 | 171 | static int hw_breakpoint_used_count (void); |
c906108c | 172 | |
a14ed312 | 173 | static int hw_watchpoint_used_count (enum bptype, int *); |
c906108c | 174 | |
a14ed312 | 175 | static void hbreak_command (char *, int); |
c906108c | 176 | |
a14ed312 | 177 | static void thbreak_command (char *, int); |
c906108c | 178 | |
a14ed312 | 179 | static void do_enable_breakpoint (struct breakpoint *, enum bpdisp); |
c906108c | 180 | |
a14ed312 | 181 | static void stop_command (char *arg, int from_tty); |
7a292a7a | 182 | |
a14ed312 | 183 | static void stopin_command (char *arg, int from_tty); |
7a292a7a | 184 | |
a14ed312 | 185 | static void stopat_command (char *arg, int from_tty); |
7a292a7a | 186 | |
a14ed312 | 187 | static char *ep_parse_optional_if_clause (char **arg); |
7a292a7a | 188 | |
d85310f7 MS |
189 | static void catch_exception_command_1 (enum exception_event_kind ex_event, |
190 | char *arg, int tempflag, int from_tty); | |
7a292a7a | 191 | |
a14ed312 | 192 | static void tcatch_command (char *arg, int from_tty); |
7a292a7a | 193 | |
d03285ec UW |
194 | static void detach_single_step_breakpoints (void); |
195 | ||
6c95b8df PA |
196 | static int single_step_breakpoint_inserted_here_p (struct address_space *, |
197 | CORE_ADDR pc); | |
1aafd4da | 198 | |
fe3f5fa8 | 199 | static void free_bp_location (struct bp_location *loc); |
f431efe5 PA |
200 | static void incref_bp_location (struct bp_location *loc); |
201 | static void decref_bp_location (struct bp_location **loc); | |
fe3f5fa8 | 202 | |
39d61571 | 203 | static struct bp_location *allocate_bp_location (struct breakpoint *bpt); |
a5606eee | 204 | |
b60e7edf | 205 | static void update_global_location_list (int); |
a5606eee | 206 | |
b60e7edf | 207 | static void update_global_location_list_nothrow (int); |
74960c60 | 208 | |
d77f58be | 209 | static int is_hardware_watchpoint (const struct breakpoint *bpt); |
74960c60 | 210 | |
d77f58be | 211 | static int is_watchpoint (const struct breakpoint *bpt); |
60e1c644 | 212 | |
74960c60 | 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 | ||
9c06b0b4 TJB |
227 | static int is_masked_watchpoint (const struct breakpoint *b); |
228 | ||
0fb4aa4b PA |
229 | /* Assuming we're creating a static tracepoint, does S look like a |
230 | static tracepoint marker spec ("-m MARKER_ID")? */ | |
231 | #define is_marker_spec(s) \ | |
f5a8e22b | 232 | (s != NULL && strncmp (s, "-m", 2) == 0 && ((s)[2] == ' ' || (s)[2] == '\t')) |
0fb4aa4b | 233 | |
5cea2a26 PA |
234 | /* A reference-counted struct command_line. This lets multiple |
235 | breakpoints share a single command list. */ | |
236 | struct counted_command_line | |
237 | { | |
238 | /* The reference count. */ | |
239 | int refc; | |
240 | ||
241 | /* The command list. */ | |
242 | struct command_line *commands; | |
243 | }; | |
244 | ||
245 | struct command_line * | |
246 | breakpoint_commands (struct breakpoint *b) | |
247 | { | |
248 | return b->commands ? b->commands->commands : NULL; | |
249 | } | |
3daf8fe5 | 250 | |
f3b1572e PA |
251 | /* Flag indicating that a command has proceeded the inferior past the |
252 | current breakpoint. */ | |
253 | ||
254 | static int breakpoint_proceeded; | |
255 | ||
956a9fb9 | 256 | const char * |
2cec12e5 AR |
257 | bpdisp_text (enum bpdisp disp) |
258 | { | |
4a64f543 MS |
259 | /* NOTE: the following values are a part of MI protocol and |
260 | represent values of 'disp' field returned when inferior stops at | |
261 | a breakpoint. */ | |
bc043ef3 | 262 | static const char * const bpdisps[] = {"del", "dstp", "dis", "keep"}; |
cc59ec59 | 263 | |
2cec12e5 AR |
264 | return bpdisps[(int) disp]; |
265 | } | |
c906108c | 266 | |
4a64f543 | 267 | /* Prototypes for exported functions. */ |
c906108c | 268 | /* If FALSE, gdb will not use hardware support for watchpoints, even |
4a64f543 | 269 | if such is available. */ |
c906108c SS |
270 | static int can_use_hw_watchpoints; |
271 | ||
920d2a44 AC |
272 | static void |
273 | show_can_use_hw_watchpoints (struct ui_file *file, int from_tty, | |
274 | struct cmd_list_element *c, | |
275 | const char *value) | |
276 | { | |
3e43a32a MS |
277 | fprintf_filtered (file, |
278 | _("Debugger's willingness to use " | |
279 | "watchpoint hardware is %s.\n"), | |
920d2a44 AC |
280 | value); |
281 | } | |
282 | ||
fa8d40ab JJ |
283 | /* If AUTO_BOOLEAN_FALSE, gdb will not attempt to create pending breakpoints. |
284 | If AUTO_BOOLEAN_TRUE, gdb will automatically create pending breakpoints | |
4a64f543 | 285 | for unrecognized breakpoint locations. |
fa8d40ab JJ |
286 | If AUTO_BOOLEAN_AUTO, gdb will query when breakpoints are unrecognized. */ |
287 | static enum auto_boolean pending_break_support; | |
920d2a44 AC |
288 | static void |
289 | show_pending_break_support (struct ui_file *file, int from_tty, | |
290 | struct cmd_list_element *c, | |
291 | const char *value) | |
292 | { | |
3e43a32a MS |
293 | fprintf_filtered (file, |
294 | _("Debugger's behavior regarding " | |
295 | "pending breakpoints is %s.\n"), | |
920d2a44 AC |
296 | value); |
297 | } | |
fa8d40ab | 298 | |
765dc015 | 299 | /* If 1, gdb will automatically use hardware breakpoints for breakpoints |
4a64f543 | 300 | set with "break" but falling in read-only memory. |
765dc015 VP |
301 | If 0, gdb will warn about such breakpoints, but won't automatically |
302 | use hardware breakpoints. */ | |
303 | static int automatic_hardware_breakpoints; | |
304 | static void | |
305 | show_automatic_hardware_breakpoints (struct ui_file *file, int from_tty, | |
306 | struct cmd_list_element *c, | |
307 | const char *value) | |
308 | { | |
3e43a32a MS |
309 | fprintf_filtered (file, |
310 | _("Automatic usage of hardware breakpoints is %s.\n"), | |
765dc015 VP |
311 | value); |
312 | } | |
313 | ||
33e5cbd6 PA |
314 | /* If on, gdb will keep breakpoints inserted even as inferior is |
315 | stopped, and immediately insert any new breakpoints. If off, gdb | |
316 | will insert breakpoints into inferior only when resuming it, and | |
317 | will remove breakpoints upon stop. If auto, GDB will behave as ON | |
318 | if in non-stop mode, and as OFF if all-stop mode.*/ | |
319 | ||
320 | static const char always_inserted_auto[] = "auto"; | |
321 | static const char always_inserted_on[] = "on"; | |
322 | static const char always_inserted_off[] = "off"; | |
323 | static const char *always_inserted_enums[] = { | |
324 | always_inserted_auto, | |
325 | always_inserted_off, | |
326 | always_inserted_on, | |
327 | NULL | |
328 | }; | |
329 | static const char *always_inserted_mode = always_inserted_auto; | |
330 | static void | |
74960c60 | 331 | show_always_inserted_mode (struct ui_file *file, int from_tty, |
33e5cbd6 | 332 | struct cmd_list_element *c, const char *value) |
74960c60 | 333 | { |
33e5cbd6 | 334 | if (always_inserted_mode == always_inserted_auto) |
3e43a32a MS |
335 | fprintf_filtered (file, |
336 | _("Always inserted breakpoint " | |
337 | "mode is %s (currently %s).\n"), | |
33e5cbd6 PA |
338 | value, |
339 | breakpoints_always_inserted_mode () ? "on" : "off"); | |
340 | else | |
3e43a32a MS |
341 | fprintf_filtered (file, _("Always inserted breakpoint mode is %s.\n"), |
342 | value); | |
74960c60 VP |
343 | } |
344 | ||
33e5cbd6 PA |
345 | int |
346 | breakpoints_always_inserted_mode (void) | |
347 | { | |
348 | return (always_inserted_mode == always_inserted_on | |
349 | || (always_inserted_mode == always_inserted_auto && non_stop)); | |
350 | } | |
765dc015 | 351 | |
a14ed312 | 352 | void _initialize_breakpoint (void); |
c906108c | 353 | |
c906108c SS |
354 | /* Are we executing breakpoint commands? */ |
355 | static int executing_breakpoint_commands; | |
356 | ||
c02f5703 MS |
357 | /* Are overlay event breakpoints enabled? */ |
358 | static int overlay_events_enabled; | |
359 | ||
e09342b5 TJB |
360 | /* See description in breakpoint.h. */ |
361 | int target_exact_watchpoints = 0; | |
362 | ||
c906108c | 363 | /* Walk the following statement or block through all breakpoints. |
4a64f543 MS |
364 | ALL_BREAKPOINTS_SAFE does so even if the statment deletes the |
365 | current breakpoint. */ | |
c906108c | 366 | |
5c44784c | 367 | #define ALL_BREAKPOINTS(B) for (B = breakpoint_chain; B; B = B->next) |
c906108c | 368 | |
5c44784c JM |
369 | #define ALL_BREAKPOINTS_SAFE(B,TMP) \ |
370 | for (B = breakpoint_chain; \ | |
371 | B ? (TMP=B->next, 1): 0; \ | |
372 | B = TMP) | |
c906108c | 373 | |
4a64f543 MS |
374 | /* Similar iterator for the low-level breakpoints. SAFE variant is |
375 | not provided so update_global_location_list must not be called | |
376 | while executing the block of ALL_BP_LOCATIONS. */ | |
7cc221ef | 377 | |
876fa593 JK |
378 | #define ALL_BP_LOCATIONS(B,BP_TMP) \ |
379 | for (BP_TMP = bp_location; \ | |
380 | BP_TMP < bp_location + bp_location_count && (B = *BP_TMP); \ | |
381 | BP_TMP++) | |
7cc221ef | 382 | |
1042e4c0 SS |
383 | /* Iterator for tracepoints only. */ |
384 | ||
385 | #define ALL_TRACEPOINTS(B) \ | |
386 | for (B = breakpoint_chain; B; B = B->next) \ | |
d77f58be | 387 | if (is_tracepoint (B)) |
1042e4c0 | 388 | |
7cc221ef | 389 | /* Chains of all breakpoints defined. */ |
c906108c SS |
390 | |
391 | struct breakpoint *breakpoint_chain; | |
392 | ||
876fa593 JK |
393 | /* Array is sorted by bp_location_compare - primarily by the ADDRESS. */ |
394 | ||
395 | static struct bp_location **bp_location; | |
396 | ||
397 | /* Number of elements of BP_LOCATION. */ | |
398 | ||
399 | static unsigned bp_location_count; | |
400 | ||
4a64f543 MS |
401 | /* Maximum alignment offset between bp_target_info.PLACED_ADDRESS and |
402 | ADDRESS for the current elements of BP_LOCATION which get a valid | |
403 | result from bp_location_has_shadow. You can use it for roughly | |
404 | limiting the subrange of BP_LOCATION to scan for shadow bytes for | |
405 | an address you need to read. */ | |
876fa593 JK |
406 | |
407 | static CORE_ADDR bp_location_placed_address_before_address_max; | |
408 | ||
4a64f543 MS |
409 | /* Maximum offset plus alignment between bp_target_info.PLACED_ADDRESS |
410 | + bp_target_info.SHADOW_LEN and ADDRESS for the current elements of | |
411 | BP_LOCATION which get a valid result from bp_location_has_shadow. | |
412 | You can use it for roughly limiting the subrange of BP_LOCATION to | |
413 | scan for shadow bytes for an address you need to read. */ | |
876fa593 JK |
414 | |
415 | static CORE_ADDR bp_location_shadow_len_after_address_max; | |
7cc221ef | 416 | |
4a64f543 MS |
417 | /* The locations that no longer correspond to any breakpoint, unlinked |
418 | from bp_location array, but for which a hit may still be reported | |
419 | by a target. */ | |
20874c92 VP |
420 | VEC(bp_location_p) *moribund_locations = NULL; |
421 | ||
c906108c SS |
422 | /* Number of last breakpoint made. */ |
423 | ||
95a42b64 TT |
424 | static int breakpoint_count; |
425 | ||
86b17b60 PA |
426 | /* The value of `breakpoint_count' before the last command that |
427 | created breakpoints. If the last (break-like) command created more | |
428 | than one breakpoint, then the difference between BREAKPOINT_COUNT | |
429 | and PREV_BREAKPOINT_COUNT is more than one. */ | |
430 | static int prev_breakpoint_count; | |
c906108c | 431 | |
1042e4c0 SS |
432 | /* Number of last tracepoint made. */ |
433 | ||
95a42b64 | 434 | static int tracepoint_count; |
1042e4c0 | 435 | |
6149aea9 PA |
436 | static struct cmd_list_element *breakpoint_set_cmdlist; |
437 | static struct cmd_list_element *breakpoint_show_cmdlist; | |
9291a0cd | 438 | struct cmd_list_element *save_cmdlist; |
6149aea9 | 439 | |
468d015d JJ |
440 | /* Return whether a breakpoint is an active enabled breakpoint. */ |
441 | static int | |
442 | breakpoint_enabled (struct breakpoint *b) | |
443 | { | |
0d381245 | 444 | return (b->enable_state == bp_enabled); |
468d015d JJ |
445 | } |
446 | ||
c906108c SS |
447 | /* Set breakpoint count to NUM. */ |
448 | ||
95a42b64 | 449 | static void |
fba45db2 | 450 | set_breakpoint_count (int num) |
c906108c | 451 | { |
86b17b60 | 452 | prev_breakpoint_count = breakpoint_count; |
c906108c | 453 | breakpoint_count = num; |
4fa62494 | 454 | set_internalvar_integer (lookup_internalvar ("bpnum"), num); |
c906108c SS |
455 | } |
456 | ||
86b17b60 PA |
457 | /* Used by `start_rbreak_breakpoints' below, to record the current |
458 | breakpoint count before "rbreak" creates any breakpoint. */ | |
459 | static int rbreak_start_breakpoint_count; | |
460 | ||
95a42b64 TT |
461 | /* Called at the start an "rbreak" command to record the first |
462 | breakpoint made. */ | |
86b17b60 | 463 | |
95a42b64 TT |
464 | void |
465 | start_rbreak_breakpoints (void) | |
466 | { | |
86b17b60 | 467 | rbreak_start_breakpoint_count = breakpoint_count; |
95a42b64 TT |
468 | } |
469 | ||
470 | /* Called at the end of an "rbreak" command to record the last | |
471 | breakpoint made. */ | |
86b17b60 | 472 | |
95a42b64 TT |
473 | void |
474 | end_rbreak_breakpoints (void) | |
475 | { | |
86b17b60 | 476 | prev_breakpoint_count = rbreak_start_breakpoint_count; |
95a42b64 TT |
477 | } |
478 | ||
4a64f543 | 479 | /* Used in run_command to zero the hit count when a new run starts. */ |
c906108c SS |
480 | |
481 | void | |
fba45db2 | 482 | clear_breakpoint_hit_counts (void) |
c906108c SS |
483 | { |
484 | struct breakpoint *b; | |
485 | ||
486 | ALL_BREAKPOINTS (b) | |
487 | b->hit_count = 0; | |
488 | } | |
489 | ||
9add0f1b TT |
490 | /* Allocate a new counted_command_line with reference count of 1. |
491 | The new structure owns COMMANDS. */ | |
492 | ||
493 | static struct counted_command_line * | |
494 | alloc_counted_command_line (struct command_line *commands) | |
495 | { | |
496 | struct counted_command_line *result | |
497 | = xmalloc (sizeof (struct counted_command_line)); | |
cc59ec59 | 498 | |
9add0f1b TT |
499 | result->refc = 1; |
500 | result->commands = commands; | |
501 | return result; | |
502 | } | |
503 | ||
504 | /* Increment reference count. This does nothing if CMD is NULL. */ | |
505 | ||
506 | static void | |
507 | incref_counted_command_line (struct counted_command_line *cmd) | |
508 | { | |
509 | if (cmd) | |
510 | ++cmd->refc; | |
511 | } | |
512 | ||
513 | /* Decrement reference count. If the reference count reaches 0, | |
514 | destroy the counted_command_line. Sets *CMDP to NULL. This does | |
515 | nothing if *CMDP is NULL. */ | |
516 | ||
517 | static void | |
518 | decref_counted_command_line (struct counted_command_line **cmdp) | |
519 | { | |
520 | if (*cmdp) | |
521 | { | |
522 | if (--(*cmdp)->refc == 0) | |
523 | { | |
524 | free_command_lines (&(*cmdp)->commands); | |
525 | xfree (*cmdp); | |
526 | } | |
527 | *cmdp = NULL; | |
528 | } | |
529 | } | |
530 | ||
531 | /* A cleanup function that calls decref_counted_command_line. */ | |
532 | ||
533 | static void | |
534 | do_cleanup_counted_command_line (void *arg) | |
535 | { | |
536 | decref_counted_command_line (arg); | |
537 | } | |
538 | ||
539 | /* Create a cleanup that calls decref_counted_command_line on the | |
540 | argument. */ | |
541 | ||
542 | static struct cleanup * | |
543 | make_cleanup_decref_counted_command_line (struct counted_command_line **cmdp) | |
544 | { | |
545 | return make_cleanup (do_cleanup_counted_command_line, cmdp); | |
546 | } | |
547 | ||
c906108c SS |
548 | /* Default address, symtab and line to put a breakpoint at |
549 | for "break" command with no arg. | |
4a64f543 | 550 | If default_breakpoint_valid is zero, the other three are |
c906108c SS |
551 | not valid, and "break" with no arg is an error. |
552 | ||
553 | This set by print_stack_frame, which calls set_default_breakpoint. */ | |
554 | ||
555 | int default_breakpoint_valid; | |
556 | CORE_ADDR default_breakpoint_address; | |
557 | struct symtab *default_breakpoint_symtab; | |
558 | int default_breakpoint_line; | |
6c95b8df PA |
559 | struct program_space *default_breakpoint_pspace; |
560 | ||
c906108c | 561 | \f |
48cb2d85 VP |
562 | /* Return the breakpoint with the specified number, or NULL |
563 | if the number does not refer to an existing breakpoint. */ | |
564 | ||
565 | struct breakpoint * | |
566 | get_breakpoint (int num) | |
567 | { | |
568 | struct breakpoint *b; | |
569 | ||
570 | ALL_BREAKPOINTS (b) | |
571 | if (b->number == num) | |
572 | return b; | |
573 | ||
574 | return NULL; | |
575 | } | |
5c44784c | 576 | |
c906108c | 577 | \f |
adc36818 PM |
578 | |
579 | void | |
580 | set_breakpoint_condition (struct breakpoint *b, char *exp, | |
581 | int from_tty) | |
582 | { | |
583 | struct bp_location *loc = b->loc; | |
584 | ||
585 | for (; loc; loc = loc->next) | |
586 | { | |
587 | xfree (loc->cond); | |
588 | loc->cond = NULL; | |
589 | } | |
590 | xfree (b->cond_string); | |
591 | b->cond_string = NULL; | |
592 | xfree (b->cond_exp); | |
593 | b->cond_exp = NULL; | |
594 | ||
595 | if (*exp == 0) | |
596 | { | |
597 | if (from_tty) | |
598 | printf_filtered (_("Breakpoint %d now unconditional.\n"), b->number); | |
599 | } | |
600 | else | |
601 | { | |
602 | char *arg = exp; | |
cc59ec59 | 603 | |
adc36818 PM |
604 | /* I don't know if it matters whether this is the string the user |
605 | typed in or the decompiled expression. */ | |
606 | b->cond_string = xstrdup (arg); | |
607 | b->condition_not_parsed = 0; | |
608 | ||
609 | if (is_watchpoint (b)) | |
610 | { | |
611 | innermost_block = NULL; | |
612 | arg = exp; | |
613 | b->cond_exp = parse_exp_1 (&arg, 0, 0); | |
614 | if (*arg) | |
615 | error (_("Junk at end of expression")); | |
616 | b->cond_exp_valid_block = innermost_block; | |
617 | } | |
618 | else | |
619 | { | |
620 | for (loc = b->loc; loc; loc = loc->next) | |
621 | { | |
622 | arg = exp; | |
623 | loc->cond = | |
624 | parse_exp_1 (&arg, block_for_pc (loc->address), 0); | |
625 | if (*arg) | |
626 | error (_("Junk at end of expression")); | |
627 | } | |
628 | } | |
629 | } | |
630 | breakpoints_changed (); | |
8d3788bd | 631 | observer_notify_breakpoint_modified (b); |
adc36818 PM |
632 | } |
633 | ||
c906108c SS |
634 | /* condition N EXP -- set break condition of breakpoint N to EXP. */ |
635 | ||
636 | static void | |
fba45db2 | 637 | condition_command (char *arg, int from_tty) |
c906108c | 638 | { |
52f0bd74 | 639 | struct breakpoint *b; |
c906108c | 640 | char *p; |
52f0bd74 | 641 | int bnum; |
c906108c SS |
642 | |
643 | if (arg == 0) | |
e2e0b3e5 | 644 | error_no_arg (_("breakpoint number")); |
c906108c SS |
645 | |
646 | p = arg; | |
647 | bnum = get_number (&p); | |
5c44784c | 648 | if (bnum == 0) |
8a3fe4f8 | 649 | error (_("Bad breakpoint argument: '%s'"), arg); |
c906108c SS |
650 | |
651 | ALL_BREAKPOINTS (b) | |
652 | if (b->number == bnum) | |
2f069f6f | 653 | { |
7371cf6d PM |
654 | /* Check if this breakpoint has a Python object assigned to |
655 | it, and if it has a definition of the "stop" | |
656 | method. This method and conditions entered into GDB from | |
657 | the CLI are mutually exclusive. */ | |
658 | if (b->py_bp_object | |
659 | && gdbpy_breakpoint_has_py_cond (b->py_bp_object)) | |
660 | error (_("Cannot set a condition where a Python 'stop' " | |
661 | "method has been defined in the breakpoint.")); | |
2566ad2d | 662 | set_breakpoint_condition (b, p, from_tty); |
2f069f6f JB |
663 | return; |
664 | } | |
c906108c | 665 | |
8a3fe4f8 | 666 | error (_("No breakpoint number %d."), bnum); |
c906108c SS |
667 | } |
668 | ||
a7bdde9e VP |
669 | /* Check that COMMAND do not contain commands that are suitable |
670 | only for tracepoints and not suitable for ordinary breakpoints. | |
4a64f543 MS |
671 | Throw if any such commands is found. */ |
672 | ||
a7bdde9e VP |
673 | static void |
674 | check_no_tracepoint_commands (struct command_line *commands) | |
675 | { | |
676 | struct command_line *c; | |
cc59ec59 | 677 | |
a7bdde9e VP |
678 | for (c = commands; c; c = c->next) |
679 | { | |
680 | int i; | |
681 | ||
682 | if (c->control_type == while_stepping_control) | |
3e43a32a MS |
683 | error (_("The 'while-stepping' command can " |
684 | "only be used for tracepoints")); | |
a7bdde9e VP |
685 | |
686 | for (i = 0; i < c->body_count; ++i) | |
687 | check_no_tracepoint_commands ((c->body_list)[i]); | |
688 | ||
689 | /* Not that command parsing removes leading whitespace and comment | |
4a64f543 | 690 | lines and also empty lines. So, we only need to check for |
a7bdde9e VP |
691 | command directly. */ |
692 | if (strstr (c->line, "collect ") == c->line) | |
693 | error (_("The 'collect' command can only be used for tracepoints")); | |
694 | ||
51661e93 VP |
695 | if (strstr (c->line, "teval ") == c->line) |
696 | error (_("The 'teval' command can only be used for tracepoints")); | |
a7bdde9e VP |
697 | } |
698 | } | |
699 | ||
d77f58be SS |
700 | /* Encapsulate tests for different types of tracepoints. */ |
701 | ||
a7bdde9e | 702 | int |
d77f58be | 703 | is_tracepoint (const struct breakpoint *b) |
a7bdde9e | 704 | { |
0fb4aa4b PA |
705 | return (b->type == bp_tracepoint |
706 | || b->type == bp_fast_tracepoint | |
707 | || b->type == bp_static_tracepoint); | |
a7bdde9e | 708 | } |
d77f58be | 709 | |
95a42b64 TT |
710 | /* A helper function that validsates that COMMANDS are valid for a |
711 | breakpoint. This function will throw an exception if a problem is | |
712 | found. */ | |
48cb2d85 | 713 | |
95a42b64 TT |
714 | static void |
715 | validate_commands_for_breakpoint (struct breakpoint *b, | |
716 | struct command_line *commands) | |
48cb2d85 | 717 | { |
d77f58be | 718 | if (is_tracepoint (b)) |
a7bdde9e | 719 | { |
4a64f543 MS |
720 | /* We need to verify that each top-level element of commands is |
721 | valid for tracepoints, that there's at most one | |
722 | while-stepping element, and that while-stepping's body has | |
723 | valid tracing commands excluding nested while-stepping. */ | |
a7bdde9e VP |
724 | struct command_line *c; |
725 | struct command_line *while_stepping = 0; | |
726 | for (c = commands; c; c = c->next) | |
727 | { | |
a7bdde9e VP |
728 | if (c->control_type == while_stepping_control) |
729 | { | |
730 | if (b->type == bp_fast_tracepoint) | |
3e43a32a MS |
731 | error (_("The 'while-stepping' command " |
732 | "cannot be used for fast tracepoint")); | |
0fb4aa4b | 733 | else if (b->type == bp_static_tracepoint) |
3e43a32a MS |
734 | error (_("The 'while-stepping' command " |
735 | "cannot be used for static tracepoint")); | |
a7bdde9e VP |
736 | |
737 | if (while_stepping) | |
3e43a32a MS |
738 | error (_("The 'while-stepping' command " |
739 | "can be used only once")); | |
a7bdde9e VP |
740 | else |
741 | while_stepping = c; | |
742 | } | |
743 | } | |
744 | if (while_stepping) | |
745 | { | |
746 | struct command_line *c2; | |
747 | ||
748 | gdb_assert (while_stepping->body_count == 1); | |
749 | c2 = while_stepping->body_list[0]; | |
750 | for (; c2; c2 = c2->next) | |
751 | { | |
a7bdde9e VP |
752 | if (c2->control_type == while_stepping_control) |
753 | error (_("The 'while-stepping' command cannot be nested")); | |
754 | } | |
755 | } | |
756 | } | |
757 | else | |
758 | { | |
759 | check_no_tracepoint_commands (commands); | |
760 | } | |
95a42b64 TT |
761 | } |
762 | ||
0fb4aa4b PA |
763 | /* Return a vector of all the static tracepoints set at ADDR. The |
764 | caller is responsible for releasing the vector. */ | |
765 | ||
766 | VEC(breakpoint_p) * | |
767 | static_tracepoints_here (CORE_ADDR addr) | |
768 | { | |
769 | struct breakpoint *b; | |
770 | VEC(breakpoint_p) *found = 0; | |
771 | struct bp_location *loc; | |
772 | ||
773 | ALL_BREAKPOINTS (b) | |
774 | if (b->type == bp_static_tracepoint) | |
775 | { | |
776 | for (loc = b->loc; loc; loc = loc->next) | |
777 | if (loc->address == addr) | |
778 | VEC_safe_push(breakpoint_p, found, b); | |
779 | } | |
780 | ||
781 | return found; | |
782 | } | |
783 | ||
95a42b64 | 784 | /* Set the command list of B to COMMANDS. If breakpoint is tracepoint, |
4a64f543 | 785 | validate that only allowed commands are included. */ |
95a42b64 TT |
786 | |
787 | void | |
4a64f543 MS |
788 | breakpoint_set_commands (struct breakpoint *b, |
789 | struct command_line *commands) | |
95a42b64 TT |
790 | { |
791 | validate_commands_for_breakpoint (b, commands); | |
a7bdde9e | 792 | |
9add0f1b TT |
793 | decref_counted_command_line (&b->commands); |
794 | b->commands = alloc_counted_command_line (commands); | |
48cb2d85 | 795 | breakpoints_changed (); |
8d3788bd | 796 | observer_notify_breakpoint_modified (b); |
48cb2d85 VP |
797 | } |
798 | ||
45a43567 TT |
799 | /* Set the internal `silent' flag on the breakpoint. Note that this |
800 | is not the same as the "silent" that may appear in the breakpoint's | |
801 | commands. */ | |
802 | ||
803 | void | |
804 | breakpoint_set_silent (struct breakpoint *b, int silent) | |
805 | { | |
806 | int old_silent = b->silent; | |
807 | ||
808 | b->silent = silent; | |
809 | if (old_silent != silent) | |
8d3788bd | 810 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
811 | } |
812 | ||
813 | /* Set the thread for this breakpoint. If THREAD is -1, make the | |
814 | breakpoint work for any thread. */ | |
815 | ||
816 | void | |
817 | breakpoint_set_thread (struct breakpoint *b, int thread) | |
818 | { | |
819 | int old_thread = b->thread; | |
820 | ||
821 | b->thread = thread; | |
822 | if (old_thread != thread) | |
8d3788bd | 823 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
824 | } |
825 | ||
826 | /* Set the task for this breakpoint. If TASK is 0, make the | |
827 | breakpoint work for any task. */ | |
828 | ||
829 | void | |
830 | breakpoint_set_task (struct breakpoint *b, int task) | |
831 | { | |
832 | int old_task = b->task; | |
833 | ||
834 | b->task = task; | |
835 | if (old_task != task) | |
8d3788bd | 836 | observer_notify_breakpoint_modified (b); |
45a43567 TT |
837 | } |
838 | ||
95a42b64 TT |
839 | void |
840 | check_tracepoint_command (char *line, void *closure) | |
a7bdde9e VP |
841 | { |
842 | struct breakpoint *b = closure; | |
cc59ec59 | 843 | |
a7bdde9e VP |
844 | validate_actionline (&line, b); |
845 | } | |
846 | ||
95a42b64 TT |
847 | /* A structure used to pass information through |
848 | map_breakpoint_numbers. */ | |
849 | ||
850 | struct commands_info | |
851 | { | |
852 | /* True if the command was typed at a tty. */ | |
853 | int from_tty; | |
86b17b60 PA |
854 | |
855 | /* The breakpoint range spec. */ | |
856 | char *arg; | |
857 | ||
95a42b64 TT |
858 | /* Non-NULL if the body of the commands are being read from this |
859 | already-parsed command. */ | |
860 | struct command_line *control; | |
86b17b60 | 861 | |
95a42b64 TT |
862 | /* The command lines read from the user, or NULL if they have not |
863 | yet been read. */ | |
864 | struct counted_command_line *cmd; | |
865 | }; | |
866 | ||
867 | /* A callback for map_breakpoint_numbers that sets the commands for | |
868 | commands_command. */ | |
869 | ||
c906108c | 870 | static void |
95a42b64 | 871 | do_map_commands_command (struct breakpoint *b, void *data) |
c906108c | 872 | { |
95a42b64 | 873 | struct commands_info *info = data; |
c906108c | 874 | |
95a42b64 TT |
875 | if (info->cmd == NULL) |
876 | { | |
877 | struct command_line *l; | |
5c44784c | 878 | |
95a42b64 TT |
879 | if (info->control != NULL) |
880 | l = copy_command_lines (info->control->body_list[0]); | |
881 | else | |
86b17b60 PA |
882 | { |
883 | struct cleanup *old_chain; | |
884 | char *str; | |
c5aa993b | 885 | |
3e43a32a MS |
886 | str = xstrprintf (_("Type commands for breakpoint(s) " |
887 | "%s, one per line."), | |
86b17b60 PA |
888 | info->arg); |
889 | ||
890 | old_chain = make_cleanup (xfree, str); | |
891 | ||
892 | l = read_command_lines (str, | |
893 | info->from_tty, 1, | |
d77f58be | 894 | (is_tracepoint (b) |
86b17b60 PA |
895 | ? check_tracepoint_command : 0), |
896 | b); | |
897 | ||
898 | do_cleanups (old_chain); | |
899 | } | |
a7bdde9e | 900 | |
95a42b64 TT |
901 | info->cmd = alloc_counted_command_line (l); |
902 | } | |
903 | ||
904 | /* If a breakpoint was on the list more than once, we don't need to | |
905 | do anything. */ | |
906 | if (b->commands != info->cmd) | |
907 | { | |
908 | validate_commands_for_breakpoint (b, info->cmd->commands); | |
909 | incref_counted_command_line (info->cmd); | |
910 | decref_counted_command_line (&b->commands); | |
911 | b->commands = info->cmd; | |
912 | breakpoints_changed (); | |
8d3788bd | 913 | observer_notify_breakpoint_modified (b); |
c5aa993b | 914 | } |
95a42b64 TT |
915 | } |
916 | ||
917 | static void | |
4a64f543 MS |
918 | commands_command_1 (char *arg, int from_tty, |
919 | struct command_line *control) | |
95a42b64 TT |
920 | { |
921 | struct cleanup *cleanups; | |
922 | struct commands_info info; | |
923 | ||
924 | info.from_tty = from_tty; | |
925 | info.control = control; | |
926 | info.cmd = NULL; | |
927 | /* If we read command lines from the user, then `info' will hold an | |
928 | extra reference to the commands that we must clean up. */ | |
929 | cleanups = make_cleanup_decref_counted_command_line (&info.cmd); | |
930 | ||
931 | if (arg == NULL || !*arg) | |
932 | { | |
86b17b60 | 933 | if (breakpoint_count - prev_breakpoint_count > 1) |
4a64f543 MS |
934 | arg = xstrprintf ("%d-%d", prev_breakpoint_count + 1, |
935 | breakpoint_count); | |
95a42b64 TT |
936 | else if (breakpoint_count > 0) |
937 | arg = xstrprintf ("%d", breakpoint_count); | |
86b17b60 PA |
938 | else |
939 | { | |
940 | /* So that we don't try to free the incoming non-NULL | |
941 | argument in the cleanup below. Mapping breakpoint | |
942 | numbers will fail in this case. */ | |
943 | arg = NULL; | |
944 | } | |
95a42b64 | 945 | } |
9766ced4 SS |
946 | else |
947 | /* The command loop has some static state, so we need to preserve | |
948 | our argument. */ | |
949 | arg = xstrdup (arg); | |
86b17b60 PA |
950 | |
951 | if (arg != NULL) | |
952 | make_cleanup (xfree, arg); | |
953 | ||
954 | info.arg = arg; | |
95a42b64 TT |
955 | |
956 | map_breakpoint_numbers (arg, do_map_commands_command, &info); | |
957 | ||
958 | if (info.cmd == NULL) | |
959 | error (_("No breakpoints specified.")); | |
960 | ||
961 | do_cleanups (cleanups); | |
962 | } | |
963 | ||
964 | static void | |
965 | commands_command (char *arg, int from_tty) | |
966 | { | |
967 | commands_command_1 (arg, from_tty, NULL); | |
c906108c | 968 | } |
40c03ae8 EZ |
969 | |
970 | /* Like commands_command, but instead of reading the commands from | |
971 | input stream, takes them from an already parsed command structure. | |
972 | ||
973 | This is used by cli-script.c to DTRT with breakpoint commands | |
974 | that are part of if and while bodies. */ | |
975 | enum command_control_type | |
976 | commands_from_control_command (char *arg, struct command_line *cmd) | |
977 | { | |
95a42b64 TT |
978 | commands_command_1 (arg, 0, cmd); |
979 | return simple_control; | |
40c03ae8 | 980 | } |
876fa593 JK |
981 | |
982 | /* Return non-zero if BL->TARGET_INFO contains valid information. */ | |
983 | ||
984 | static int | |
985 | bp_location_has_shadow (struct bp_location *bl) | |
986 | { | |
987 | if (bl->loc_type != bp_loc_software_breakpoint) | |
988 | return 0; | |
989 | if (!bl->inserted) | |
990 | return 0; | |
991 | if (bl->target_info.shadow_len == 0) | |
992 | /* bp isn't valid, or doesn't shadow memory. */ | |
993 | return 0; | |
994 | return 1; | |
995 | } | |
996 | ||
8defab1a | 997 | /* Update BUF, which is LEN bytes read from the target address MEMADDR, |
876fa593 JK |
998 | by replacing any memory breakpoints with their shadowed contents. |
999 | ||
1000 | The range of shadowed area by each bp_location is: | |
35df4500 TJB |
1001 | bl->address - bp_location_placed_address_before_address_max |
1002 | up to bl->address + bp_location_shadow_len_after_address_max | |
876fa593 JK |
1003 | The range we were requested to resolve shadows for is: |
1004 | memaddr ... memaddr + len | |
1005 | Thus the safe cutoff boundaries for performance optimization are | |
35df4500 TJB |
1006 | memaddr + len <= (bl->address |
1007 | - bp_location_placed_address_before_address_max) | |
876fa593 | 1008 | and: |
35df4500 | 1009 | bl->address + bp_location_shadow_len_after_address_max <= memaddr */ |
c906108c | 1010 | |
8defab1a DJ |
1011 | void |
1012 | breakpoint_restore_shadows (gdb_byte *buf, ULONGEST memaddr, LONGEST len) | |
c906108c | 1013 | { |
4a64f543 MS |
1014 | /* Left boundary, right boundary and median element of our binary |
1015 | search. */ | |
876fa593 JK |
1016 | unsigned bc_l, bc_r, bc; |
1017 | ||
4a64f543 MS |
1018 | /* Find BC_L which is a leftmost element which may affect BUF |
1019 | content. It is safe to report lower value but a failure to | |
1020 | report higher one. */ | |
876fa593 JK |
1021 | |
1022 | bc_l = 0; | |
1023 | bc_r = bp_location_count; | |
1024 | while (bc_l + 1 < bc_r) | |
1025 | { | |
35df4500 | 1026 | struct bp_location *bl; |
876fa593 JK |
1027 | |
1028 | bc = (bc_l + bc_r) / 2; | |
35df4500 | 1029 | bl = bp_location[bc]; |
876fa593 | 1030 | |
4a64f543 MS |
1031 | /* Check first BL->ADDRESS will not overflow due to the added |
1032 | constant. Then advance the left boundary only if we are sure | |
1033 | the BC element can in no way affect the BUF content (MEMADDR | |
1034 | to MEMADDR + LEN range). | |
876fa593 | 1035 | |
4a64f543 MS |
1036 | Use the BP_LOCATION_SHADOW_LEN_AFTER_ADDRESS_MAX safety |
1037 | offset so that we cannot miss a breakpoint with its shadow | |
1038 | range tail still reaching MEMADDR. */ | |
c5aa993b | 1039 | |
35df4500 TJB |
1040 | if ((bl->address + bp_location_shadow_len_after_address_max |
1041 | >= bl->address) | |
1042 | && (bl->address + bp_location_shadow_len_after_address_max | |
1043 | <= memaddr)) | |
876fa593 JK |
1044 | bc_l = bc; |
1045 | else | |
1046 | bc_r = bc; | |
1047 | } | |
1048 | ||
128070bb PA |
1049 | /* Due to the binary search above, we need to make sure we pick the |
1050 | first location that's at BC_L's address. E.g., if there are | |
1051 | multiple locations at the same address, BC_L may end up pointing | |
1052 | at a duplicate location, and miss the "master"/"inserted" | |
1053 | location. Say, given locations L1, L2 and L3 at addresses A and | |
1054 | B: | |
1055 | ||
1056 | L1@A, L2@A, L3@B, ... | |
1057 | ||
1058 | BC_L could end up pointing at location L2, while the "master" | |
1059 | location could be L1. Since the `loc->inserted' flag is only set | |
1060 | on "master" locations, we'd forget to restore the shadow of L1 | |
1061 | and L2. */ | |
1062 | while (bc_l > 0 | |
1063 | && bp_location[bc_l]->address == bp_location[bc_l - 1]->address) | |
1064 | bc_l--; | |
1065 | ||
876fa593 JK |
1066 | /* Now do full processing of the found relevant range of elements. */ |
1067 | ||
1068 | for (bc = bc_l; bc < bp_location_count; bc++) | |
c5aa993b | 1069 | { |
35df4500 | 1070 | struct bp_location *bl = bp_location[bc]; |
876fa593 JK |
1071 | CORE_ADDR bp_addr = 0; |
1072 | int bp_size = 0; | |
1073 | int bptoffset = 0; | |
1074 | ||
35df4500 TJB |
1075 | /* bp_location array has BL->OWNER always non-NULL. */ |
1076 | if (bl->owner->type == bp_none) | |
8a3fe4f8 | 1077 | warning (_("reading through apparently deleted breakpoint #%d?"), |
35df4500 | 1078 | bl->owner->number); |
ffce0d52 | 1079 | |
876fa593 JK |
1080 | /* Performance optimization: any futher element can no longer affect BUF |
1081 | content. */ | |
1082 | ||
35df4500 TJB |
1083 | if (bl->address >= bp_location_placed_address_before_address_max |
1084 | && memaddr + len <= (bl->address | |
1085 | - bp_location_placed_address_before_address_max)) | |
876fa593 JK |
1086 | break; |
1087 | ||
35df4500 | 1088 | if (!bp_location_has_shadow (bl)) |
c5aa993b | 1089 | continue; |
35df4500 | 1090 | if (!breakpoint_address_match (bl->target_info.placed_address_space, 0, |
6c95b8df PA |
1091 | current_program_space->aspace, 0)) |
1092 | continue; | |
1093 | ||
c5aa993b JM |
1094 | /* Addresses and length of the part of the breakpoint that |
1095 | we need to copy. */ | |
35df4500 TJB |
1096 | bp_addr = bl->target_info.placed_address; |
1097 | bp_size = bl->target_info.shadow_len; | |
8defab1a | 1098 | |
c5aa993b JM |
1099 | if (bp_addr + bp_size <= memaddr) |
1100 | /* The breakpoint is entirely before the chunk of memory we | |
1101 | are reading. */ | |
1102 | continue; | |
8defab1a | 1103 | |
c5aa993b JM |
1104 | if (bp_addr >= memaddr + len) |
1105 | /* The breakpoint is entirely after the chunk of memory we are | |
4a64f543 | 1106 | reading. */ |
c5aa993b | 1107 | continue; |
c5aa993b | 1108 | |
8defab1a DJ |
1109 | /* Offset within shadow_contents. */ |
1110 | if (bp_addr < memaddr) | |
1111 | { | |
1112 | /* Only copy the second part of the breakpoint. */ | |
1113 | bp_size -= memaddr - bp_addr; | |
1114 | bptoffset = memaddr - bp_addr; | |
1115 | bp_addr = memaddr; | |
1116 | } | |
c5aa993b | 1117 | |
8defab1a DJ |
1118 | if (bp_addr + bp_size > memaddr + len) |
1119 | { | |
1120 | /* Only copy the first part of the breakpoint. */ | |
1121 | bp_size -= (bp_addr + bp_size) - (memaddr + len); | |
1122 | } | |
c5aa993b | 1123 | |
8defab1a | 1124 | memcpy (buf + bp_addr - memaddr, |
35df4500 | 1125 | bl->target_info.shadow_contents + bptoffset, bp_size); |
c5aa993b | 1126 | } |
c906108c | 1127 | } |
c906108c | 1128 | \f |
c5aa993b | 1129 | |
60e1c644 PA |
1130 | /* Return true if BPT is of any hardware watchpoint kind. */ |
1131 | ||
a5606eee | 1132 | static int |
d77f58be | 1133 | is_hardware_watchpoint (const struct breakpoint *bpt) |
a5606eee VP |
1134 | { |
1135 | return (bpt->type == bp_hardware_watchpoint | |
1136 | || bpt->type == bp_read_watchpoint | |
1137 | || bpt->type == bp_access_watchpoint); | |
1138 | } | |
7270d8f2 | 1139 | |
60e1c644 PA |
1140 | /* Return true if BPT is of any watchpoint kind, hardware or |
1141 | software. */ | |
1142 | ||
1143 | static int | |
d77f58be | 1144 | is_watchpoint (const struct breakpoint *bpt) |
60e1c644 PA |
1145 | { |
1146 | return (is_hardware_watchpoint (bpt) | |
1147 | || bpt->type == bp_watchpoint); | |
1148 | } | |
1149 | ||
f6bc2008 PA |
1150 | /* Assuming that B is a watchpoint: returns true if the current thread |
1151 | and its running state are safe to evaluate or update watchpoint B. | |
1152 | Watchpoints on local expressions need to be evaluated in the | |
1153 | context of the thread that was current when the watchpoint was | |
1154 | created, and, that thread needs to be stopped to be able to select | |
1155 | the correct frame context. Watchpoints on global expressions can | |
1156 | be evaluated on any thread, and in any state. It is presently left | |
1157 | to the target allowing memory accesses when threads are | |
1158 | running. */ | |
1159 | ||
1160 | static int | |
1161 | watchpoint_in_thread_scope (struct breakpoint *b) | |
1162 | { | |
1163 | return (ptid_equal (b->watchpoint_thread, null_ptid) | |
1164 | || (ptid_equal (inferior_ptid, b->watchpoint_thread) | |
1165 | && !is_executing (inferior_ptid))); | |
1166 | } | |
1167 | ||
d0fb5eae JK |
1168 | /* Set watchpoint B to disp_del_at_next_stop, even including its possible |
1169 | associated bp_watchpoint_scope breakpoint. */ | |
1170 | ||
1171 | static void | |
1172 | watchpoint_del_at_next_stop (struct breakpoint *b) | |
1173 | { | |
1174 | gdb_assert (is_watchpoint (b)); | |
1175 | ||
1176 | if (b->related_breakpoint != b) | |
1177 | { | |
1178 | gdb_assert (b->related_breakpoint->type == bp_watchpoint_scope); | |
1179 | gdb_assert (b->related_breakpoint->related_breakpoint == b); | |
1180 | b->related_breakpoint->disposition = disp_del_at_next_stop; | |
1181 | b->related_breakpoint->related_breakpoint = b->related_breakpoint; | |
1182 | b->related_breakpoint = b; | |
1183 | } | |
1184 | b->disposition = disp_del_at_next_stop; | |
1185 | } | |
1186 | ||
567e1b4e JB |
1187 | /* Assuming that B is a watchpoint: |
1188 | - Reparse watchpoint expression, if REPARSE is non-zero | |
a5606eee | 1189 | - Evaluate expression and store the result in B->val |
567e1b4e JB |
1190 | - Evaluate the condition if there is one, and store the result |
1191 | in b->loc->cond. | |
a5606eee VP |
1192 | - Update the list of values that must be watched in B->loc. |
1193 | ||
4a64f543 MS |
1194 | If the watchpoint disposition is disp_del_at_next_stop, then do |
1195 | nothing. If this is local watchpoint that is out of scope, delete | |
1196 | it. | |
1197 | ||
1198 | Even with `set breakpoint always-inserted on' the watchpoints are | |
1199 | removed + inserted on each stop here. Normal breakpoints must | |
1200 | never be removed because they might be missed by a running thread | |
1201 | when debugging in non-stop mode. On the other hand, hardware | |
1202 | watchpoints (is_hardware_watchpoint; processed here) are specific | |
1203 | to each LWP since they are stored in each LWP's hardware debug | |
1204 | registers. Therefore, such LWP must be stopped first in order to | |
1205 | be able to modify its hardware watchpoints. | |
1206 | ||
1207 | Hardware watchpoints must be reset exactly once after being | |
1208 | presented to the user. It cannot be done sooner, because it would | |
1209 | reset the data used to present the watchpoint hit to the user. And | |
1210 | it must not be done later because it could display the same single | |
1211 | watchpoint hit during multiple GDB stops. Note that the latter is | |
1212 | relevant only to the hardware watchpoint types bp_read_watchpoint | |
1213 | and bp_access_watchpoint. False hit by bp_hardware_watchpoint is | |
1214 | not user-visible - its hit is suppressed if the memory content has | |
1215 | not changed. | |
1216 | ||
1217 | The following constraints influence the location where we can reset | |
1218 | hardware watchpoints: | |
1219 | ||
1220 | * target_stopped_by_watchpoint and target_stopped_data_address are | |
1221 | called several times when GDB stops. | |
1222 | ||
1223 | [linux] | |
1224 | * Multiple hardware watchpoints can be hit at the same time, | |
1225 | causing GDB to stop. GDB only presents one hardware watchpoint | |
1226 | hit at a time as the reason for stopping, and all the other hits | |
1227 | are presented later, one after the other, each time the user | |
1228 | requests the execution to be resumed. Execution is not resumed | |
1229 | for the threads still having pending hit event stored in | |
1230 | LWP_INFO->STATUS. While the watchpoint is already removed from | |
1231 | the inferior on the first stop the thread hit event is kept being | |
1232 | reported from its cached value by linux_nat_stopped_data_address | |
1233 | until the real thread resume happens after the watchpoint gets | |
1234 | presented and thus its LWP_INFO->STATUS gets reset. | |
1235 | ||
1236 | Therefore the hardware watchpoint hit can get safely reset on the | |
1237 | watchpoint removal from inferior. */ | |
a79d3c27 | 1238 | |
b40ce68a | 1239 | static void |
a5606eee | 1240 | update_watchpoint (struct breakpoint *b, int reparse) |
7270d8f2 | 1241 | { |
a5606eee | 1242 | int within_current_scope; |
a5606eee | 1243 | struct frame_id saved_frame_id; |
66076460 | 1244 | int frame_saved; |
a5606eee | 1245 | |
d0fb5eae JK |
1246 | gdb_assert (is_watchpoint (b)); |
1247 | ||
f6bc2008 PA |
1248 | /* If this is a local watchpoint, we only want to check if the |
1249 | watchpoint frame is in scope if the current thread is the thread | |
1250 | that was used to create the watchpoint. */ | |
1251 | if (!watchpoint_in_thread_scope (b)) | |
1252 | return; | |
1253 | ||
a5606eee VP |
1254 | if (b->disposition == disp_del_at_next_stop) |
1255 | return; | |
1256 | ||
66076460 | 1257 | frame_saved = 0; |
a5606eee VP |
1258 | |
1259 | /* Determine if the watchpoint is within scope. */ | |
1260 | if (b->exp_valid_block == NULL) | |
1261 | within_current_scope = 1; | |
1262 | else | |
1263 | { | |
b5db5dfc UW |
1264 | struct frame_info *fi = get_current_frame (); |
1265 | struct gdbarch *frame_arch = get_frame_arch (fi); | |
1266 | CORE_ADDR frame_pc = get_frame_pc (fi); | |
1267 | ||
1268 | /* If we're in a function epilogue, unwinding may not work | |
1269 | properly, so do not attempt to recreate locations at this | |
1270 | point. See similar comments in watchpoint_check. */ | |
1271 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) | |
1272 | return; | |
66076460 DJ |
1273 | |
1274 | /* Save the current frame's ID so we can restore it after | |
1275 | evaluating the watchpoint expression on its own frame. */ | |
1276 | /* FIXME drow/2003-09-09: It would be nice if evaluate_expression | |
1277 | took a frame parameter, so that we didn't have to change the | |
1278 | selected frame. */ | |
1279 | frame_saved = 1; | |
1280 | saved_frame_id = get_frame_id (get_selected_frame (NULL)); | |
1281 | ||
a5606eee VP |
1282 | fi = frame_find_by_id (b->watchpoint_frame); |
1283 | within_current_scope = (fi != NULL); | |
1284 | if (within_current_scope) | |
1285 | select_frame (fi); | |
1286 | } | |
1287 | ||
b5db5dfc UW |
1288 | /* We don't free locations. They are stored in the bp_location array |
1289 | and update_global_location_list will eventually delete them and | |
1290 | remove breakpoints if needed. */ | |
1291 | b->loc = NULL; | |
1292 | ||
a5606eee VP |
1293 | if (within_current_scope && reparse) |
1294 | { | |
1295 | char *s; | |
d63d0675 | 1296 | |
a5606eee VP |
1297 | if (b->exp) |
1298 | { | |
1299 | xfree (b->exp); | |
1300 | b->exp = NULL; | |
1301 | } | |
d63d0675 | 1302 | s = b->exp_string_reparse ? b->exp_string_reparse : b->exp_string; |
a5606eee VP |
1303 | b->exp = parse_exp_1 (&s, b->exp_valid_block, 0); |
1304 | /* If the meaning of expression itself changed, the old value is | |
1305 | no longer relevant. We don't want to report a watchpoint hit | |
1306 | to the user when the old value and the new value may actually | |
1307 | be completely different objects. */ | |
1308 | value_free (b->val); | |
fa4727a6 DJ |
1309 | b->val = NULL; |
1310 | b->val_valid = 0; | |
60e1c644 PA |
1311 | |
1312 | /* Note that unlike with breakpoints, the watchpoint's condition | |
1313 | expression is stored in the breakpoint object, not in the | |
1314 | locations (re)created below. */ | |
1315 | if (b->cond_string != NULL) | |
1316 | { | |
1317 | if (b->cond_exp != NULL) | |
1318 | { | |
1319 | xfree (b->cond_exp); | |
1320 | b->cond_exp = NULL; | |
1321 | } | |
1322 | ||
1323 | s = b->cond_string; | |
1324 | b->cond_exp = parse_exp_1 (&s, b->cond_exp_valid_block, 0); | |
1325 | } | |
a5606eee | 1326 | } |
a5606eee VP |
1327 | |
1328 | /* If we failed to parse the expression, for example because | |
1329 | it refers to a global variable in a not-yet-loaded shared library, | |
1330 | don't try to insert watchpoint. We don't automatically delete | |
1331 | such watchpoint, though, since failure to parse expression | |
1332 | is different from out-of-scope watchpoint. */ | |
2d134ed3 PA |
1333 | if ( !target_has_execution) |
1334 | { | |
1335 | /* Without execution, memory can't change. No use to try and | |
1336 | set watchpoint locations. The watchpoint will be reset when | |
1337 | the target gains execution, through breakpoint_re_set. */ | |
1338 | } | |
1339 | else if (within_current_scope && b->exp) | |
a5606eee | 1340 | { |
0cf6dd15 | 1341 | int pc = 0; |
fa4727a6 | 1342 | struct value *val_chain, *v, *result, *next; |
2d134ed3 | 1343 | struct program_space *frame_pspace; |
a5606eee | 1344 | |
0cf6dd15 | 1345 | fetch_subexp_value (b->exp, &pc, &v, &result, &val_chain); |
a5606eee | 1346 | |
a5606eee VP |
1347 | /* Avoid setting b->val if it's already set. The meaning of |
1348 | b->val is 'the last value' user saw, and we should update | |
1349 | it only if we reported that last value to user. As it | |
9c06b0b4 TJB |
1350 | happens, the code that reports it updates b->val directly. |
1351 | We don't keep track of the memory value for masked | |
1352 | watchpoints. */ | |
1353 | if (!b->val_valid && !is_masked_watchpoint (b)) | |
fa4727a6 DJ |
1354 | { |
1355 | b->val = v; | |
1356 | b->val_valid = 1; | |
1357 | } | |
a5606eee | 1358 | |
2d134ed3 PA |
1359 | frame_pspace = get_frame_program_space (get_selected_frame (NULL)); |
1360 | ||
a5606eee | 1361 | /* Look at each value on the value chain. */ |
9fa40276 | 1362 | for (v = val_chain; v; v = value_next (v)) |
a5606eee VP |
1363 | { |
1364 | /* If it's a memory location, and GDB actually needed | |
1365 | its contents to evaluate the expression, then we | |
fa4727a6 DJ |
1366 | must watch it. If the first value returned is |
1367 | still lazy, that means an error occurred reading it; | |
1368 | watch it anyway in case it becomes readable. */ | |
a5606eee | 1369 | if (VALUE_LVAL (v) == lval_memory |
fa4727a6 | 1370 | && (v == val_chain || ! value_lazy (v))) |
a5606eee VP |
1371 | { |
1372 | struct type *vtype = check_typedef (value_type (v)); | |
7270d8f2 | 1373 | |
a5606eee VP |
1374 | /* We only watch structs and arrays if user asked |
1375 | for it explicitly, never if they just happen to | |
1376 | appear in the middle of some value chain. */ | |
fa4727a6 | 1377 | if (v == result |
a5606eee VP |
1378 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT |
1379 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
1380 | { | |
1381 | CORE_ADDR addr; | |
1382 | int len, type; | |
1383 | struct bp_location *loc, **tmp; | |
1384 | ||
42ae5230 | 1385 | addr = value_address (v); |
a5606eee VP |
1386 | len = TYPE_LENGTH (value_type (v)); |
1387 | type = hw_write; | |
1388 | if (b->type == bp_read_watchpoint) | |
1389 | type = hw_read; | |
1390 | else if (b->type == bp_access_watchpoint) | |
1391 | type = hw_access; | |
1392 | ||
39d61571 | 1393 | loc = allocate_bp_location (b); |
a5606eee VP |
1394 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
1395 | ; | |
1396 | *tmp = loc; | |
a6d9a66e | 1397 | loc->gdbarch = get_type_arch (value_type (v)); |
6c95b8df PA |
1398 | |
1399 | loc->pspace = frame_pspace; | |
a5606eee VP |
1400 | loc->address = addr; |
1401 | loc->length = len; | |
1402 | loc->watchpoint_type = type; | |
1403 | } | |
1404 | } | |
9fa40276 TJB |
1405 | } |
1406 | ||
1407 | /* Change the type of breakpoint between hardware assisted or | |
1408 | an ordinary watchpoint depending on the hardware support | |
1409 | and free hardware slots. REPARSE is set when the inferior | |
1410 | is started. */ | |
a9634178 | 1411 | if (reparse) |
9fa40276 | 1412 | { |
e09342b5 | 1413 | int reg_cnt; |
9fa40276 TJB |
1414 | enum bp_loc_type loc_type; |
1415 | struct bp_location *bl; | |
a5606eee | 1416 | |
a9634178 | 1417 | reg_cnt = can_use_hardware_watchpoint (val_chain); |
e09342b5 TJB |
1418 | |
1419 | if (reg_cnt) | |
9fa40276 TJB |
1420 | { |
1421 | int i, target_resources_ok, other_type_used; | |
1422 | ||
a9634178 TJB |
1423 | /* Use an exact watchpoint when there's only one memory region to be |
1424 | watched, and only one debug register is needed to watch it. */ | |
1425 | b->exact = target_exact_watchpoints && reg_cnt == 1; | |
1426 | ||
9fa40276 | 1427 | /* We need to determine how many resources are already |
e09342b5 TJB |
1428 | used for all other hardware watchpoints plus this one |
1429 | to see if we still have enough resources to also fit | |
1430 | this watchpoint in as well. To guarantee the | |
1431 | hw_watchpoint_used_count call below counts this | |
1432 | watchpoint, make sure that it is marked as a hardware | |
1433 | watchpoint. */ | |
a9634178 TJB |
1434 | if (b->type == bp_watchpoint) |
1435 | b->type = bp_hardware_watchpoint; | |
9fa40276 | 1436 | |
a9634178 | 1437 | i = hw_watchpoint_used_count (b->type, &other_type_used); |
e09342b5 | 1438 | target_resources_ok = target_can_use_hardware_watchpoint |
a9634178 | 1439 | (b->type, i, other_type_used); |
e09342b5 | 1440 | if (target_resources_ok <= 0) |
a9634178 | 1441 | { |
9c06b0b4 TJB |
1442 | /* If there's no works_in_software_mode method, we |
1443 | assume that the watchpoint works in software mode. */ | |
1444 | int sw_mode = (!b->ops || !b->ops->works_in_software_mode | |
1445 | || b->ops->works_in_software_mode (b)); | |
1446 | ||
1447 | if (target_resources_ok == 0 && !sw_mode) | |
a9634178 TJB |
1448 | error (_("Target does not support this type of " |
1449 | "hardware watchpoint.")); | |
9c06b0b4 TJB |
1450 | else if (target_resources_ok < 0 && !sw_mode) |
1451 | error (_("There are not enough available hardware " | |
1452 | "resources for this watchpoint.")); | |
a9634178 TJB |
1453 | else |
1454 | b->type = bp_watchpoint; | |
1455 | } | |
9fa40276 | 1456 | } |
9c06b0b4 TJB |
1457 | else if (b->ops && b->ops->works_in_software_mode |
1458 | && !b->ops->works_in_software_mode (b)) | |
a9634178 TJB |
1459 | error (_("Expression cannot be implemented with " |
1460 | "read/access watchpoint.")); | |
9fa40276 TJB |
1461 | else |
1462 | b->type = bp_watchpoint; | |
1463 | ||
1464 | loc_type = (b->type == bp_watchpoint? bp_loc_other | |
1465 | : bp_loc_hardware_watchpoint); | |
1466 | for (bl = b->loc; bl; bl = bl->next) | |
1467 | bl->loc_type = loc_type; | |
1468 | } | |
1469 | ||
1470 | for (v = val_chain; v; v = next) | |
1471 | { | |
a5606eee VP |
1472 | next = value_next (v); |
1473 | if (v != b->val) | |
1474 | value_free (v); | |
1475 | } | |
1476 | ||
c7437ca6 PA |
1477 | /* If a software watchpoint is not watching any memory, then the |
1478 | above left it without any location set up. But, | |
1479 | bpstat_stop_status requires a location to be able to report | |
1480 | stops, so make sure there's at least a dummy one. */ | |
1481 | if (b->type == bp_watchpoint && b->loc == NULL) | |
1482 | { | |
1483 | b->loc = allocate_bp_location (b); | |
1484 | b->loc->pspace = frame_pspace; | |
1485 | b->loc->address = -1; | |
1486 | b->loc->length = -1; | |
1487 | b->loc->watchpoint_type = -1; | |
1488 | } | |
a5606eee VP |
1489 | } |
1490 | else if (!within_current_scope) | |
7270d8f2 | 1491 | { |
ac74f770 MS |
1492 | printf_filtered (_("\ |
1493 | Watchpoint %d deleted because the program has left the block\n\ | |
1494 | in which its expression is valid.\n"), | |
a5606eee | 1495 | b->number); |
d0fb5eae | 1496 | watchpoint_del_at_next_stop (b); |
7270d8f2 | 1497 | } |
a5606eee VP |
1498 | |
1499 | /* Restore the selected frame. */ | |
66076460 DJ |
1500 | if (frame_saved) |
1501 | select_frame (frame_find_by_id (saved_frame_id)); | |
7270d8f2 OF |
1502 | } |
1503 | ||
a5606eee | 1504 | |
74960c60 VP |
1505 | /* Returns 1 iff breakpoint location should be |
1506 | inserted in the inferior. */ | |
1507 | static int | |
35df4500 | 1508 | should_be_inserted (struct bp_location *bl) |
74960c60 | 1509 | { |
35df4500 | 1510 | if (bl->owner == NULL || !breakpoint_enabled (bl->owner)) |
74960c60 VP |
1511 | return 0; |
1512 | ||
35df4500 | 1513 | if (bl->owner->disposition == disp_del_at_next_stop) |
74960c60 VP |
1514 | return 0; |
1515 | ||
35df4500 | 1516 | if (!bl->enabled || bl->shlib_disabled || bl->duplicate) |
74960c60 VP |
1517 | return 0; |
1518 | ||
56710373 PA |
1519 | /* This is set for example, when we're attached to the parent of a |
1520 | vfork, and have detached from the child. The child is running | |
1521 | free, and we expect it to do an exec or exit, at which point the | |
1522 | OS makes the parent schedulable again (and the target reports | |
1523 | that the vfork is done). Until the child is done with the shared | |
1524 | memory region, do not insert breakpoints in the parent, otherwise | |
1525 | the child could still trip on the parent's breakpoints. Since | |
1526 | the parent is blocked anyway, it won't miss any breakpoint. */ | |
35df4500 | 1527 | if (bl->pspace->breakpoints_not_allowed) |
56710373 PA |
1528 | return 0; |
1529 | ||
1042e4c0 SS |
1530 | /* Tracepoints are inserted by the target at a time of its choosing, |
1531 | not by us. */ | |
35df4500 | 1532 | if (is_tracepoint (bl->owner)) |
1042e4c0 SS |
1533 | return 0; |
1534 | ||
74960c60 VP |
1535 | return 1; |
1536 | } | |
1537 | ||
35df4500 TJB |
1538 | /* Insert a low-level "breakpoint" of some type. BL is the breakpoint |
1539 | location. Any error messages are printed to TMP_ERROR_STREAM; and | |
1540 | DISABLED_BREAKS, and HW_BREAKPOINT_ERROR are used to report problems. | |
879bfdc2 | 1541 | |
4a64f543 MS |
1542 | NOTE drow/2003-09-09: This routine could be broken down to an |
1543 | object-style method for each breakpoint or catchpoint type. */ | |
26bb91f3 | 1544 | static int |
35df4500 | 1545 | insert_bp_location (struct bp_location *bl, |
26bb91f3 | 1546 | struct ui_file *tmp_error_stream, |
fa3a767f | 1547 | int *disabled_breaks, |
26bb91f3 | 1548 | int *hw_breakpoint_error) |
879bfdc2 DJ |
1549 | { |
1550 | int val = 0; | |
1551 | ||
35df4500 | 1552 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1553 | return 0; |
1554 | ||
8181d85f | 1555 | /* Initialize the target-specific information. */ |
35df4500 TJB |
1556 | memset (&bl->target_info, 0, sizeof (bl->target_info)); |
1557 | bl->target_info.placed_address = bl->address; | |
1558 | bl->target_info.placed_address_space = bl->pspace->aspace; | |
f1310107 | 1559 | bl->target_info.length = bl->length; |
8181d85f | 1560 | |
35df4500 TJB |
1561 | if (bl->loc_type == bp_loc_software_breakpoint |
1562 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
879bfdc2 | 1563 | { |
35df4500 | 1564 | if (bl->owner->type != bp_hardware_breakpoint) |
765dc015 VP |
1565 | { |
1566 | /* If the explicitly specified breakpoint type | |
1567 | is not hardware breakpoint, check the memory map to see | |
1568 | if the breakpoint address is in read only memory or not. | |
4a64f543 | 1569 | |
765dc015 VP |
1570 | Two important cases are: |
1571 | - location type is not hardware breakpoint, memory | |
1572 | is readonly. We change the type of the location to | |
1573 | hardware breakpoint. | |
4a64f543 MS |
1574 | - location type is hardware breakpoint, memory is |
1575 | read-write. This means we've previously made the | |
1576 | location hardware one, but then the memory map changed, | |
1577 | so we undo. | |
765dc015 | 1578 | |
4a64f543 MS |
1579 | When breakpoints are removed, remove_breakpoints will use |
1580 | location types we've just set here, the only possible | |
1581 | problem is that memory map has changed during running | |
1582 | program, but it's not going to work anyway with current | |
1583 | gdb. */ | |
765dc015 | 1584 | struct mem_region *mr |
35df4500 | 1585 | = lookup_mem_region (bl->target_info.placed_address); |
765dc015 VP |
1586 | |
1587 | if (mr) | |
1588 | { | |
1589 | if (automatic_hardware_breakpoints) | |
1590 | { | |
765dc015 VP |
1591 | enum bp_loc_type new_type; |
1592 | ||
1593 | if (mr->attrib.mode != MEM_RW) | |
1594 | new_type = bp_loc_hardware_breakpoint; | |
1595 | else | |
1596 | new_type = bp_loc_software_breakpoint; | |
1597 | ||
35df4500 | 1598 | if (new_type != bl->loc_type) |
765dc015 VP |
1599 | { |
1600 | static int said = 0; | |
cc59ec59 | 1601 | |
35df4500 | 1602 | bl->loc_type = new_type; |
765dc015 VP |
1603 | if (!said) |
1604 | { | |
3e43a32a MS |
1605 | fprintf_filtered (gdb_stdout, |
1606 | _("Note: automatically using " | |
1607 | "hardware breakpoints for " | |
1608 | "read-only addresses.\n")); | |
765dc015 VP |
1609 | said = 1; |
1610 | } | |
1611 | } | |
1612 | } | |
35df4500 | 1613 | else if (bl->loc_type == bp_loc_software_breakpoint |
765dc015 | 1614 | && mr->attrib.mode != MEM_RW) |
3e43a32a MS |
1615 | warning (_("cannot set software breakpoint " |
1616 | "at readonly address %s"), | |
35df4500 | 1617 | paddress (bl->gdbarch, bl->address)); |
765dc015 VP |
1618 | } |
1619 | } | |
1620 | ||
879bfdc2 DJ |
1621 | /* First check to see if we have to handle an overlay. */ |
1622 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
1623 | || bl->section == NULL |
1624 | || !(section_is_overlay (bl->section))) | |
879bfdc2 DJ |
1625 | { |
1626 | /* No overlay handling: just set the breakpoint. */ | |
1627 | ||
35df4500 TJB |
1628 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1629 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1630 | &bl->target_info); | |
879bfdc2 | 1631 | else |
35df4500 TJB |
1632 | val = target_insert_breakpoint (bl->gdbarch, |
1633 | &bl->target_info); | |
879bfdc2 DJ |
1634 | } |
1635 | else | |
1636 | { | |
4a64f543 | 1637 | /* This breakpoint is in an overlay section. |
879bfdc2 DJ |
1638 | Shall we set a breakpoint at the LMA? */ |
1639 | if (!overlay_events_enabled) | |
1640 | { | |
1641 | /* Yes -- overlay event support is not active, | |
1642 | so we must try to set a breakpoint at the LMA. | |
1643 | This will not work for a hardware breakpoint. */ | |
35df4500 | 1644 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
8a3fe4f8 | 1645 | warning (_("hardware breakpoint %d not supported in overlay!"), |
35df4500 | 1646 | bl->owner->number); |
879bfdc2 DJ |
1647 | else |
1648 | { | |
35df4500 TJB |
1649 | CORE_ADDR addr = overlay_unmapped_address (bl->address, |
1650 | bl->section); | |
879bfdc2 | 1651 | /* Set a software (trap) breakpoint at the LMA. */ |
35df4500 TJB |
1652 | bl->overlay_target_info = bl->target_info; |
1653 | bl->overlay_target_info.placed_address = addr; | |
1654 | val = target_insert_breakpoint (bl->gdbarch, | |
1655 | &bl->overlay_target_info); | |
879bfdc2 | 1656 | if (val != 0) |
99361f52 | 1657 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1658 | "Overlay breakpoint %d " |
1659 | "failed: in ROM?\n", | |
35df4500 | 1660 | bl->owner->number); |
879bfdc2 DJ |
1661 | } |
1662 | } | |
1663 | /* Shall we set a breakpoint at the VMA? */ | |
35df4500 | 1664 | if (section_is_mapped (bl->section)) |
879bfdc2 DJ |
1665 | { |
1666 | /* Yes. This overlay section is mapped into memory. */ | |
35df4500 TJB |
1667 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
1668 | val = target_insert_hw_breakpoint (bl->gdbarch, | |
1669 | &bl->target_info); | |
879bfdc2 | 1670 | else |
35df4500 TJB |
1671 | val = target_insert_breakpoint (bl->gdbarch, |
1672 | &bl->target_info); | |
879bfdc2 DJ |
1673 | } |
1674 | else | |
1675 | { | |
1676 | /* No. This breakpoint will not be inserted. | |
1677 | No error, but do not mark the bp as 'inserted'. */ | |
1678 | return 0; | |
1679 | } | |
1680 | } | |
1681 | ||
1682 | if (val) | |
1683 | { | |
1684 | /* Can't set the breakpoint. */ | |
35df4500 | 1685 | if (solib_name_from_address (bl->pspace, bl->address)) |
879bfdc2 | 1686 | { |
4a64f543 | 1687 | /* See also: disable_breakpoints_in_shlibs. */ |
879bfdc2 | 1688 | val = 0; |
35df4500 | 1689 | bl->shlib_disabled = 1; |
8d3788bd | 1690 | observer_notify_breakpoint_modified (bl->owner); |
879bfdc2 DJ |
1691 | if (!*disabled_breaks) |
1692 | { | |
1693 | fprintf_unfiltered (tmp_error_stream, | |
1694 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1695 | bl->owner->number); |
879bfdc2 | 1696 | fprintf_unfiltered (tmp_error_stream, |
3e43a32a MS |
1697 | "Temporarily disabling shared " |
1698 | "library breakpoints:\n"); | |
879bfdc2 DJ |
1699 | } |
1700 | *disabled_breaks = 1; | |
1701 | fprintf_unfiltered (tmp_error_stream, | |
35df4500 | 1702 | "breakpoint #%d\n", bl->owner->number); |
879bfdc2 DJ |
1703 | } |
1704 | else | |
879bfdc2 | 1705 | { |
35df4500 | 1706 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
879bfdc2 DJ |
1707 | { |
1708 | *hw_breakpoint_error = 1; | |
3e43a32a MS |
1709 | fprintf_unfiltered (tmp_error_stream, |
1710 | "Cannot insert hardware " | |
1711 | "breakpoint %d.\n", | |
35df4500 | 1712 | bl->owner->number); |
879bfdc2 DJ |
1713 | } |
1714 | else | |
1715 | { | |
1716 | fprintf_unfiltered (tmp_error_stream, | |
1717 | "Cannot insert breakpoint %d.\n", | |
35df4500 | 1718 | bl->owner->number); |
879bfdc2 DJ |
1719 | fprintf_filtered (tmp_error_stream, |
1720 | "Error accessing memory address "); | |
35df4500 | 1721 | fputs_filtered (paddress (bl->gdbarch, bl->address), |
5af949e3 | 1722 | tmp_error_stream); |
879bfdc2 DJ |
1723 | fprintf_filtered (tmp_error_stream, ": %s.\n", |
1724 | safe_strerror (val)); | |
1725 | } | |
1726 | ||
1727 | } | |
1728 | } | |
1729 | else | |
35df4500 | 1730 | bl->inserted = 1; |
879bfdc2 DJ |
1731 | |
1732 | return val; | |
1733 | } | |
1734 | ||
35df4500 | 1735 | else if (bl->loc_type == bp_loc_hardware_watchpoint |
879bfdc2 | 1736 | /* NOTE drow/2003-09-08: This state only exists for removing |
4a64f543 | 1737 | watchpoints. It's not clear that it's necessary... */ |
35df4500 | 1738 | && bl->owner->disposition != disp_del_at_next_stop) |
879bfdc2 | 1739 | { |
77b06cd7 TJB |
1740 | gdb_assert (bl->owner->ops != NULL |
1741 | && bl->owner->ops->insert_location != NULL); | |
1742 | ||
1743 | val = bl->owner->ops->insert_location (bl); | |
85d721b8 PA |
1744 | |
1745 | /* If trying to set a read-watchpoint, and it turns out it's not | |
1746 | supported, try emulating one with an access watchpoint. */ | |
35df4500 | 1747 | if (val == 1 && bl->watchpoint_type == hw_read) |
85d721b8 PA |
1748 | { |
1749 | struct bp_location *loc, **loc_temp; | |
1750 | ||
1751 | /* But don't try to insert it, if there's already another | |
1752 | hw_access location that would be considered a duplicate | |
1753 | of this one. */ | |
1754 | ALL_BP_LOCATIONS (loc, loc_temp) | |
35df4500 | 1755 | if (loc != bl |
85d721b8 | 1756 | && loc->watchpoint_type == hw_access |
35df4500 | 1757 | && watchpoint_locations_match (bl, loc)) |
85d721b8 | 1758 | { |
35df4500 TJB |
1759 | bl->duplicate = 1; |
1760 | bl->inserted = 1; | |
1761 | bl->target_info = loc->target_info; | |
1762 | bl->watchpoint_type = hw_access; | |
85d721b8 PA |
1763 | val = 0; |
1764 | break; | |
1765 | } | |
1766 | ||
1767 | if (val == 1) | |
1768 | { | |
77b06cd7 TJB |
1769 | bl->watchpoint_type = hw_access; |
1770 | val = bl->owner->ops->insert_location (bl); | |
1771 | ||
1772 | if (val) | |
1773 | /* Back to the original value. */ | |
1774 | bl->watchpoint_type = hw_read; | |
85d721b8 PA |
1775 | } |
1776 | } | |
1777 | ||
35df4500 | 1778 | bl->inserted = (val == 0); |
879bfdc2 DJ |
1779 | } |
1780 | ||
35df4500 | 1781 | else if (bl->owner->type == bp_catchpoint) |
879bfdc2 | 1782 | { |
77b06cd7 TJB |
1783 | gdb_assert (bl->owner->ops != NULL |
1784 | && bl->owner->ops->insert_location != NULL); | |
1785 | ||
1786 | val = bl->owner->ops->insert_location (bl); | |
1787 | if (val) | |
1788 | { | |
1789 | bl->owner->enable_state = bp_disabled; | |
1790 | ||
1791 | if (val == 1) | |
1792 | warning (_("\ | |
1793 | Error inserting catchpoint %d: Your system does not support this type\n\ | |
1794 | of catchpoint."), bl->owner->number); | |
1795 | else | |
1796 | warning (_("Error inserting catchpoint %d."), bl->owner->number); | |
1797 | } | |
1798 | ||
1799 | bl->inserted = (val == 0); | |
1640b821 DJ |
1800 | |
1801 | /* We've already printed an error message if there was a problem | |
1802 | inserting this catchpoint, and we've disabled the catchpoint, | |
1803 | so just return success. */ | |
1804 | return 0; | |
879bfdc2 DJ |
1805 | } |
1806 | ||
1807 | return 0; | |
1808 | } | |
1809 | ||
6c95b8df PA |
1810 | /* This function is called when program space PSPACE is about to be |
1811 | deleted. It takes care of updating breakpoints to not reference | |
1812 | PSPACE anymore. */ | |
1813 | ||
1814 | void | |
1815 | breakpoint_program_space_exit (struct program_space *pspace) | |
1816 | { | |
1817 | struct breakpoint *b, *b_temp; | |
876fa593 | 1818 | struct bp_location *loc, **loc_temp; |
6c95b8df PA |
1819 | |
1820 | /* Remove any breakpoint that was set through this program space. */ | |
1821 | ALL_BREAKPOINTS_SAFE (b, b_temp) | |
1822 | { | |
1823 | if (b->pspace == pspace) | |
1824 | delete_breakpoint (b); | |
1825 | } | |
1826 | ||
1827 | /* Breakpoints set through other program spaces could have locations | |
1828 | bound to PSPACE as well. Remove those. */ | |
876fa593 | 1829 | ALL_BP_LOCATIONS (loc, loc_temp) |
6c95b8df PA |
1830 | { |
1831 | struct bp_location *tmp; | |
1832 | ||
1833 | if (loc->pspace == pspace) | |
1834 | { | |
2bdf28a0 | 1835 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
6c95b8df PA |
1836 | if (loc->owner->loc == loc) |
1837 | loc->owner->loc = loc->next; | |
1838 | else | |
1839 | for (tmp = loc->owner->loc; tmp->next != NULL; tmp = tmp->next) | |
1840 | if (tmp->next == loc) | |
1841 | { | |
1842 | tmp->next = loc->next; | |
1843 | break; | |
1844 | } | |
1845 | } | |
1846 | } | |
1847 | ||
1848 | /* Now update the global location list to permanently delete the | |
1849 | removed locations above. */ | |
1850 | update_global_location_list (0); | |
1851 | } | |
1852 | ||
74960c60 VP |
1853 | /* Make sure all breakpoints are inserted in inferior. |
1854 | Throws exception on any error. | |
1855 | A breakpoint that is already inserted won't be inserted | |
1856 | again, so calling this function twice is safe. */ | |
1857 | void | |
1858 | insert_breakpoints (void) | |
1859 | { | |
1860 | struct breakpoint *bpt; | |
1861 | ||
1862 | ALL_BREAKPOINTS (bpt) | |
1863 | if (is_hardware_watchpoint (bpt)) | |
4a64f543 | 1864 | update_watchpoint (bpt, 0 /* don't reparse. */); |
74960c60 | 1865 | |
b60e7edf | 1866 | update_global_location_list (1); |
74960c60 | 1867 | |
c35b1492 PA |
1868 | /* update_global_location_list does not insert breakpoints when |
1869 | always_inserted_mode is not enabled. Explicitly insert them | |
1870 | now. */ | |
1871 | if (!breakpoints_always_inserted_mode ()) | |
74960c60 VP |
1872 | insert_breakpoint_locations (); |
1873 | } | |
1874 | ||
c906108c SS |
1875 | /* insert_breakpoints is used when starting or continuing the program. |
1876 | remove_breakpoints is used when the program stops. | |
1877 | Both return zero if successful, | |
1878 | or an `errno' value if could not write the inferior. */ | |
1879 | ||
74960c60 VP |
1880 | static void |
1881 | insert_breakpoint_locations (void) | |
c906108c | 1882 | { |
a5606eee | 1883 | struct breakpoint *bpt; |
35df4500 | 1884 | struct bp_location *bl, **blp_tmp; |
e236ba44 | 1885 | int error = 0; |
c906108c SS |
1886 | int val = 0; |
1887 | int disabled_breaks = 0; | |
81d0cc19 | 1888 | int hw_breakpoint_error = 0; |
c906108c | 1889 | |
81d0cc19 | 1890 | struct ui_file *tmp_error_stream = mem_fileopen (); |
f7545552 | 1891 | struct cleanup *cleanups = make_cleanup_ui_file_delete (tmp_error_stream); |
74960c60 | 1892 | |
81d0cc19 GS |
1893 | /* Explicitly mark the warning -- this will only be printed if |
1894 | there was an error. */ | |
1895 | fprintf_unfiltered (tmp_error_stream, "Warning:\n"); | |
6c95b8df PA |
1896 | |
1897 | save_current_space_and_thread (); | |
1898 | ||
35df4500 | 1899 | ALL_BP_LOCATIONS (bl, blp_tmp) |
879bfdc2 | 1900 | { |
35df4500 | 1901 | if (!should_be_inserted (bl) || bl->inserted) |
879bfdc2 DJ |
1902 | continue; |
1903 | ||
4a64f543 MS |
1904 | /* There is no point inserting thread-specific breakpoints if |
1905 | the thread no longer exists. ALL_BP_LOCATIONS bp_location | |
1906 | has BL->OWNER always non-NULL. */ | |
35df4500 TJB |
1907 | if (bl->owner->thread != -1 |
1908 | && !valid_thread_id (bl->owner->thread)) | |
f365de73 AS |
1909 | continue; |
1910 | ||
35df4500 | 1911 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df PA |
1912 | |
1913 | /* For targets that support global breakpoints, there's no need | |
1914 | to select an inferior to insert breakpoint to. In fact, even | |
1915 | if we aren't attached to any process yet, we should still | |
1916 | insert breakpoints. */ | |
1917 | if (!gdbarch_has_global_breakpoints (target_gdbarch) | |
1918 | && ptid_equal (inferior_ptid, null_ptid)) | |
1919 | continue; | |
1920 | ||
35df4500 | 1921 | val = insert_bp_location (bl, tmp_error_stream, &disabled_breaks, |
879bfdc2 DJ |
1922 | &hw_breakpoint_error); |
1923 | if (val) | |
e236ba44 | 1924 | error = val; |
879bfdc2 | 1925 | } |
c906108c | 1926 | |
4a64f543 MS |
1927 | /* If we failed to insert all locations of a watchpoint, remove |
1928 | them, as half-inserted watchpoint is of limited use. */ | |
a5606eee VP |
1929 | ALL_BREAKPOINTS (bpt) |
1930 | { | |
1931 | int some_failed = 0; | |
1932 | struct bp_location *loc; | |
1933 | ||
1934 | if (!is_hardware_watchpoint (bpt)) | |
1935 | continue; | |
1936 | ||
d6b74ac4 | 1937 | if (!breakpoint_enabled (bpt)) |
a5606eee | 1938 | continue; |
74960c60 VP |
1939 | |
1940 | if (bpt->disposition == disp_del_at_next_stop) | |
1941 | continue; | |
a5606eee VP |
1942 | |
1943 | for (loc = bpt->loc; loc; loc = loc->next) | |
56710373 | 1944 | if (!loc->inserted && should_be_inserted (loc)) |
a5606eee VP |
1945 | { |
1946 | some_failed = 1; | |
1947 | break; | |
1948 | } | |
1949 | if (some_failed) | |
1950 | { | |
1951 | for (loc = bpt->loc; loc; loc = loc->next) | |
1952 | if (loc->inserted) | |
1953 | remove_breakpoint (loc, mark_uninserted); | |
1954 | ||
1955 | hw_breakpoint_error = 1; | |
1956 | fprintf_unfiltered (tmp_error_stream, | |
1957 | "Could not insert hardware watchpoint %d.\n", | |
1958 | bpt->number); | |
1959 | error = -1; | |
1960 | } | |
1961 | } | |
1962 | ||
e236ba44 | 1963 | if (error) |
81d0cc19 GS |
1964 | { |
1965 | /* If a hardware breakpoint or watchpoint was inserted, add a | |
1966 | message about possibly exhausted resources. */ | |
879bfdc2 | 1967 | if (hw_breakpoint_error) |
81d0cc19 | 1968 | { |
c6510018 MS |
1969 | fprintf_unfiltered (tmp_error_stream, |
1970 | "Could not insert hardware breakpoints:\n\ | |
1971 | You may have requested too many hardware breakpoints/watchpoints.\n"); | |
81d0cc19 | 1972 | } |
81d0cc19 GS |
1973 | target_terminal_ours_for_output (); |
1974 | error_stream (tmp_error_stream); | |
1975 | } | |
f7545552 TT |
1976 | |
1977 | do_cleanups (cleanups); | |
c906108c SS |
1978 | } |
1979 | ||
c906108c | 1980 | int |
fba45db2 | 1981 | remove_breakpoints (void) |
c906108c | 1982 | { |
35df4500 | 1983 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 1984 | int val = 0; |
c906108c | 1985 | |
35df4500 | 1986 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 1987 | { |
35df4500 TJB |
1988 | if (bl->inserted) |
1989 | val |= remove_breakpoint (bl, mark_uninserted); | |
c5aa993b | 1990 | } |
3a1bae8e | 1991 | return val; |
c906108c SS |
1992 | } |
1993 | ||
6c95b8df PA |
1994 | /* Remove breakpoints of process PID. */ |
1995 | ||
1996 | int | |
1997 | remove_breakpoints_pid (int pid) | |
1998 | { | |
35df4500 | 1999 | struct bp_location *bl, **blp_tmp; |
6c95b8df PA |
2000 | int val; |
2001 | struct inferior *inf = find_inferior_pid (pid); | |
2002 | ||
35df4500 | 2003 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2004 | { |
35df4500 | 2005 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2006 | continue; |
2007 | ||
35df4500 | 2008 | if (bl->inserted) |
6c95b8df | 2009 | { |
35df4500 | 2010 | val = remove_breakpoint (bl, mark_uninserted); |
6c95b8df PA |
2011 | if (val != 0) |
2012 | return val; | |
2013 | } | |
2014 | } | |
2015 | return 0; | |
2016 | } | |
2017 | ||
692590c1 | 2018 | int |
80ce1ecb | 2019 | remove_hw_watchpoints (void) |
692590c1 | 2020 | { |
35df4500 | 2021 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2022 | int val = 0; |
692590c1 | 2023 | |
35df4500 | 2024 | ALL_BP_LOCATIONS (bl, blp_tmp) |
692590c1 | 2025 | { |
35df4500 TJB |
2026 | if (bl->inserted && bl->loc_type == bp_loc_hardware_watchpoint) |
2027 | val |= remove_breakpoint (bl, mark_uninserted); | |
692590c1 | 2028 | } |
3a1bae8e | 2029 | return val; |
692590c1 MS |
2030 | } |
2031 | ||
c906108c | 2032 | int |
fba45db2 | 2033 | reattach_breakpoints (int pid) |
c906108c | 2034 | { |
6c95b8df | 2035 | struct cleanup *old_chain; |
35df4500 | 2036 | struct bp_location *bl, **blp_tmp; |
c906108c | 2037 | int val; |
86b887df | 2038 | struct ui_file *tmp_error_stream; |
fa3a767f | 2039 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2040 | struct inferior *inf; |
2041 | struct thread_info *tp; | |
2042 | ||
2043 | tp = any_live_thread_of_process (pid); | |
2044 | if (tp == NULL) | |
2045 | return 1; | |
2046 | ||
2047 | inf = find_inferior_pid (pid); | |
2048 | old_chain = save_inferior_ptid (); | |
2049 | ||
2050 | inferior_ptid = tp->ptid; | |
a4954f26 | 2051 | |
86b887df | 2052 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2053 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2054 | |
35df4500 | 2055 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2056 | { |
35df4500 | 2057 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2058 | continue; |
2059 | ||
35df4500 | 2060 | if (bl->inserted) |
c5aa993b | 2061 | { |
35df4500 TJB |
2062 | bl->inserted = 0; |
2063 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); | |
c5aa993b JM |
2064 | if (val != 0) |
2065 | { | |
ce696e05 | 2066 | do_cleanups (old_chain); |
c5aa993b JM |
2067 | return val; |
2068 | } | |
2069 | } | |
2070 | } | |
ce696e05 | 2071 | do_cleanups (old_chain); |
c906108c SS |
2072 | return 0; |
2073 | } | |
2074 | ||
e58b0e63 PA |
2075 | static int internal_breakpoint_number = -1; |
2076 | ||
84f4c1fe PM |
2077 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2078 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2079 | from internal_breakpoint_number and that variable decremented. | |
2080 | Otherwis the breakpoint number will be populated from | |
2081 | breakpoint_count and that value incremented. Internal breakpoints | |
2082 | do not set the internal var bpnum. */ | |
2083 | static void | |
2084 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2085 | { | |
2086 | if (internal) | |
2087 | b->number = internal_breakpoint_number--; | |
2088 | else | |
2089 | { | |
2090 | set_breakpoint_count (breakpoint_count + 1); | |
2091 | b->number = breakpoint_count; | |
2092 | } | |
2093 | } | |
2094 | ||
e62c965a | 2095 | static struct breakpoint * |
a6d9a66e UW |
2096 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2097 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2098 | { |
e62c965a PP |
2099 | struct symtab_and_line sal; |
2100 | struct breakpoint *b; | |
2101 | ||
4a64f543 | 2102 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2103 | |
2104 | sal.pc = address; | |
2105 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2106 | sal.pspace = current_program_space; |
e62c965a | 2107 | |
a6d9a66e | 2108 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2109 | b->number = internal_breakpoint_number--; |
2110 | b->disposition = disp_donttouch; | |
2111 | ||
2112 | return b; | |
2113 | } | |
2114 | ||
17450429 PP |
2115 | static const char *const longjmp_names[] = |
2116 | { | |
2117 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2118 | }; | |
2119 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2120 | ||
2121 | /* Per-objfile data private to breakpoint.c. */ | |
2122 | struct breakpoint_objfile_data | |
2123 | { | |
2124 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2125 | struct minimal_symbol *overlay_msym; | |
2126 | ||
2127 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2128 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2129 | ||
2130 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2131 | struct minimal_symbol *terminate_msym; | |
2132 | ||
2133 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2134 | struct minimal_symbol *exception_msym; | |
2135 | }; | |
2136 | ||
2137 | static const struct objfile_data *breakpoint_objfile_key; | |
2138 | ||
2139 | /* Minimal symbol not found sentinel. */ | |
2140 | static struct minimal_symbol msym_not_found; | |
2141 | ||
2142 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2143 | ||
2144 | static int | |
2145 | msym_not_found_p (const struct minimal_symbol *msym) | |
2146 | { | |
2147 | return msym == &msym_not_found; | |
2148 | } | |
2149 | ||
2150 | /* Return per-objfile data needed by breakpoint.c. | |
2151 | Allocate the data if necessary. */ | |
2152 | ||
2153 | static struct breakpoint_objfile_data * | |
2154 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2155 | { | |
2156 | struct breakpoint_objfile_data *bp_objfile_data; | |
2157 | ||
2158 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2159 | if (bp_objfile_data == NULL) | |
2160 | { | |
2161 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2162 | sizeof (*bp_objfile_data)); | |
2163 | ||
2164 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2165 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2166 | } | |
2167 | return bp_objfile_data; | |
2168 | } | |
2169 | ||
e62c965a | 2170 | static void |
af02033e | 2171 | create_overlay_event_breakpoint (void) |
e62c965a | 2172 | { |
69de3c6a | 2173 | struct objfile *objfile; |
af02033e | 2174 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2175 | |
69de3c6a PP |
2176 | ALL_OBJFILES (objfile) |
2177 | { | |
2178 | struct breakpoint *b; | |
17450429 PP |
2179 | struct breakpoint_objfile_data *bp_objfile_data; |
2180 | CORE_ADDR addr; | |
69de3c6a | 2181 | |
17450429 PP |
2182 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2183 | ||
2184 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2185 | continue; | |
2186 | ||
2187 | if (bp_objfile_data->overlay_msym == NULL) | |
2188 | { | |
2189 | struct minimal_symbol *m; | |
2190 | ||
2191 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2192 | if (m == NULL) | |
2193 | { | |
2194 | /* Avoid future lookups in this objfile. */ | |
2195 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2196 | continue; | |
2197 | } | |
2198 | bp_objfile_data->overlay_msym = m; | |
2199 | } | |
e62c965a | 2200 | |
17450429 PP |
2201 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2202 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
69de3c6a PP |
2203 | bp_overlay_event); |
2204 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2205 | |
69de3c6a PP |
2206 | if (overlay_debugging == ovly_auto) |
2207 | { | |
2208 | b->enable_state = bp_enabled; | |
2209 | overlay_events_enabled = 1; | |
2210 | } | |
2211 | else | |
2212 | { | |
2213 | b->enable_state = bp_disabled; | |
2214 | overlay_events_enabled = 0; | |
2215 | } | |
e62c965a PP |
2216 | } |
2217 | update_global_location_list (1); | |
2218 | } | |
2219 | ||
0fd8e87f | 2220 | static void |
af02033e | 2221 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2222 | { |
6c95b8df | 2223 | struct program_space *pspace; |
6c95b8df PA |
2224 | struct cleanup *old_chain; |
2225 | ||
2226 | old_chain = save_current_program_space (); | |
0fd8e87f | 2227 | |
6c95b8df | 2228 | ALL_PSPACES (pspace) |
af02033e PP |
2229 | { |
2230 | struct objfile *objfile; | |
2231 | ||
2232 | set_current_program_space (pspace); | |
2233 | ||
2234 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2235 | { |
af02033e PP |
2236 | int i; |
2237 | struct gdbarch *gdbarch; | |
17450429 | 2238 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2239 | |
af02033e PP |
2240 | gdbarch = get_objfile_arch (objfile); |
2241 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2242 | continue; |
2243 | ||
17450429 PP |
2244 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2245 | ||
2246 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2247 | { |
2248 | struct breakpoint *b; | |
af02033e | 2249 | const char *func_name; |
17450429 | 2250 | CORE_ADDR addr; |
6c95b8df | 2251 | |
17450429 | 2252 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2253 | continue; |
0fd8e87f | 2254 | |
17450429 PP |
2255 | func_name = longjmp_names[i]; |
2256 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2257 | { | |
2258 | struct minimal_symbol *m; | |
2259 | ||
2260 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2261 | if (m == NULL) | |
2262 | { | |
2263 | /* Prevent future lookups in this objfile. */ | |
2264 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2265 | continue; | |
2266 | } | |
2267 | bp_objfile_data->longjmp_msym[i] = m; | |
2268 | } | |
2269 | ||
2270 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
2271 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master); | |
af02033e PP |
2272 | b->addr_string = xstrdup (func_name); |
2273 | b->enable_state = bp_disabled; | |
2274 | } | |
0fd8e87f | 2275 | } |
af02033e | 2276 | } |
0fd8e87f | 2277 | update_global_location_list (1); |
6c95b8df PA |
2278 | |
2279 | do_cleanups (old_chain); | |
0fd8e87f UW |
2280 | } |
2281 | ||
af02033e | 2282 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2283 | static void |
af02033e | 2284 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2285 | { |
2286 | struct program_space *pspace; | |
aa7d318d | 2287 | struct cleanup *old_chain; |
af02033e | 2288 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2289 | |
2290 | old_chain = save_current_program_space (); | |
2291 | ||
2292 | ALL_PSPACES (pspace) | |
17450429 PP |
2293 | { |
2294 | struct objfile *objfile; | |
2295 | CORE_ADDR addr; | |
2296 | ||
2297 | set_current_program_space (pspace); | |
2298 | ||
aa7d318d TT |
2299 | ALL_OBJFILES (objfile) |
2300 | { | |
2301 | struct breakpoint *b; | |
17450429 | 2302 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2303 | |
17450429 | 2304 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2305 | |
17450429 PP |
2306 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2307 | continue; | |
2308 | ||
2309 | if (bp_objfile_data->terminate_msym == NULL) | |
2310 | { | |
2311 | struct minimal_symbol *m; | |
2312 | ||
2313 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2314 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2315 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2316 | { | |
2317 | /* Prevent future lookups in this objfile. */ | |
2318 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2319 | continue; | |
2320 | } | |
2321 | bp_objfile_data->terminate_msym = m; | |
2322 | } | |
aa7d318d | 2323 | |
17450429 PP |
2324 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2325 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
aa7d318d TT |
2326 | bp_std_terminate_master); |
2327 | b->addr_string = xstrdup (func_name); | |
2328 | b->enable_state = bp_disabled; | |
2329 | } | |
17450429 PP |
2330 | } |
2331 | ||
aa7d318d TT |
2332 | update_global_location_list (1); |
2333 | ||
2334 | do_cleanups (old_chain); | |
2335 | } | |
2336 | ||
186c406b TT |
2337 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2338 | ||
2339 | void | |
2340 | create_exception_master_breakpoint (void) | |
2341 | { | |
2342 | struct objfile *objfile; | |
17450429 | 2343 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2344 | |
2345 | ALL_OBJFILES (objfile) | |
2346 | { | |
17450429 PP |
2347 | struct breakpoint *b; |
2348 | struct gdbarch *gdbarch; | |
2349 | struct breakpoint_objfile_data *bp_objfile_data; | |
2350 | CORE_ADDR addr; | |
2351 | ||
2352 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2353 | ||
2354 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2355 | continue; | |
2356 | ||
2357 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2358 | |
17450429 | 2359 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2360 | { |
17450429 | 2361 | struct minimal_symbol *debug_hook; |
186c406b | 2362 | |
17450429 PP |
2363 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2364 | if (debug_hook == NULL) | |
2365 | { | |
2366 | bp_objfile_data->exception_msym = &msym_not_found; | |
2367 | continue; | |
2368 | } | |
2369 | ||
2370 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2371 | } |
17450429 PP |
2372 | |
2373 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2374 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2375 | ¤t_target); | |
2376 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); | |
2377 | b->addr_string = xstrdup (func_name); | |
2378 | b->enable_state = bp_disabled; | |
186c406b TT |
2379 | } |
2380 | ||
2381 | update_global_location_list (1); | |
2382 | } | |
2383 | ||
c906108c | 2384 | void |
fba45db2 | 2385 | update_breakpoints_after_exec (void) |
c906108c | 2386 | { |
35df4500 | 2387 | struct breakpoint *b, *b_tmp; |
876fa593 | 2388 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2389 | |
25b22b0a PA |
2390 | /* We're about to delete breakpoints from GDB's lists. If the |
2391 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2392 | writing the breakpoints' "shadow contents" back into memory. The | |
2393 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2394 | do that. Instead, the target is responsible from marking | |
2395 | breakpoints out as soon as it detects an exec. We don't do that | |
2396 | here instead, because there may be other attempts to delete | |
2397 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2398 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2399 | if (bploc->pspace == current_program_space) |
2400 | gdb_assert (!bploc->inserted); | |
c906108c | 2401 | |
35df4500 | 2402 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2403 | { |
6c95b8df PA |
2404 | if (b->pspace != current_program_space) |
2405 | continue; | |
2406 | ||
4a64f543 | 2407 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2408 | if (b->type == bp_shlib_event) |
2409 | { | |
2410 | delete_breakpoint (b); | |
2411 | continue; | |
2412 | } | |
c906108c | 2413 | |
4a64f543 | 2414 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2415 | if (b->type == bp_jit_event) |
2416 | { | |
2417 | delete_breakpoint (b); | |
2418 | continue; | |
2419 | } | |
2420 | ||
1900040c | 2421 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2422 | as must overlay event and longjmp master breakpoints. */ |
2423 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2424 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2425 | || b->type == bp_exception_master) | |
c4093a6a JM |
2426 | { |
2427 | delete_breakpoint (b); | |
2428 | continue; | |
2429 | } | |
2430 | ||
4a64f543 | 2431 | /* Step-resume breakpoints are meaningless after an exec(). */ |
c5aa993b JM |
2432 | if (b->type == bp_step_resume) |
2433 | { | |
2434 | delete_breakpoint (b); | |
2435 | continue; | |
2436 | } | |
2437 | ||
611c83ae PA |
2438 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2439 | after an exec. */ | |
186c406b TT |
2440 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2441 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2442 | { |
2443 | delete_breakpoint (b); | |
2444 | continue; | |
2445 | } | |
2446 | ||
ce78b96d JB |
2447 | if (b->type == bp_catchpoint) |
2448 | { | |
2449 | /* For now, none of the bp_catchpoint breakpoints need to | |
2450 | do anything at this point. In the future, if some of | |
2451 | the catchpoints need to something, we will need to add | |
2452 | a new method, and call this method from here. */ | |
2453 | continue; | |
2454 | } | |
2455 | ||
c5aa993b JM |
2456 | /* bp_finish is a special case. The only way we ought to be able |
2457 | to see one of these when an exec() has happened, is if the user | |
2458 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2459 | carries them to the call-site of the current callee, by setting | |
2460 | a temporary bp there and resuming. But in this case, the finish | |
2461 | will carry them entirely through the vfork & exec. | |
2462 | ||
2463 | We don't want to allow a bp_finish to remain inserted now. But | |
2464 | we can't safely delete it, 'cause finish_command has a handle to | |
2465 | the bp on a bpstat, and will later want to delete it. There's a | |
2466 | chance (and I've seen it happen) that if we delete the bp_finish | |
2467 | here, that its storage will get reused by the time finish_command | |
2468 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2469 | We really must allow finish_command to delete a bp_finish. | |
2470 | ||
53a5351d JM |
2471 | In the absense of a general solution for the "how do we know |
2472 | it's safe to delete something others may have handles to?" | |
2473 | problem, what we'll do here is just uninsert the bp_finish, and | |
2474 | let finish_command delete it. | |
2475 | ||
2476 | (We know the bp_finish is "doomed" in the sense that it's | |
2477 | momentary, and will be deleted as soon as finish_command sees | |
2478 | the inferior stopped. So it doesn't matter that the bp's | |
2479 | address is probably bogus in the new a.out, unlike e.g., the | |
2480 | solib breakpoints.) */ | |
c5aa993b | 2481 | |
c5aa993b JM |
2482 | if (b->type == bp_finish) |
2483 | { | |
2484 | continue; | |
2485 | } | |
2486 | ||
2487 | /* Without a symbolic address, we have little hope of the | |
2488 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2489 | a.out. */ |
c5aa993b JM |
2490 | if (b->addr_string == NULL) |
2491 | { | |
2492 | delete_breakpoint (b); | |
2493 | continue; | |
2494 | } | |
c5aa993b | 2495 | } |
1900040c | 2496 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2497 | create_overlay_event_breakpoint (); |
2498 | create_longjmp_master_breakpoint (); | |
2499 | create_std_terminate_master_breakpoint (); | |
186c406b | 2500 | create_exception_master_breakpoint (); |
c906108c SS |
2501 | } |
2502 | ||
2503 | int | |
fba45db2 | 2504 | detach_breakpoints (int pid) |
c906108c | 2505 | { |
35df4500 | 2506 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2507 | int val = 0; |
ce696e05 | 2508 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2509 | struct inferior *inf = current_inferior (); |
c5aa993b | 2510 | |
39f77062 | 2511 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2512 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2513 | |
6c95b8df | 2514 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2515 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2516 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2517 | { |
35df4500 | 2518 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2519 | continue; |
2520 | ||
35df4500 TJB |
2521 | if (bl->inserted) |
2522 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2523 | } |
d03285ec UW |
2524 | |
2525 | /* Detach single-step breakpoints as well. */ | |
2526 | detach_single_step_breakpoints (); | |
2527 | ||
ce696e05 | 2528 | do_cleanups (old_chain); |
3a1bae8e | 2529 | return val; |
c906108c SS |
2530 | } |
2531 | ||
35df4500 | 2532 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2533 | Note that this is used to detach breakpoints from a child fork. |
2534 | When we get here, the child isn't in the inferior list, and neither | |
2535 | do we have objects to represent its address space --- we should | |
35df4500 | 2536 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2537 | |
c906108c | 2538 | static int |
35df4500 | 2539 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2540 | { |
2541 | int val; | |
c5aa993b | 2542 | |
35df4500 TJB |
2543 | /* BL is never in moribund_locations by our callers. */ |
2544 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2545 | |
35df4500 | 2546 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2547 | /* Permanent breakpoints cannot be inserted or removed. */ |
2548 | return 0; | |
2549 | ||
74960c60 VP |
2550 | /* The type of none suggests that owner is actually deleted. |
2551 | This should not ever happen. */ | |
35df4500 | 2552 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2553 | |
35df4500 TJB |
2554 | if (bl->loc_type == bp_loc_software_breakpoint |
2555 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2556 | { |
c02f5703 MS |
2557 | /* "Normal" instruction breakpoint: either the standard |
2558 | trap-instruction bp (bp_breakpoint), or a | |
2559 | bp_hardware_breakpoint. */ | |
2560 | ||
2561 | /* First check to see if we have to handle an overlay. */ | |
2562 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2563 | || bl->section == NULL |
2564 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2565 | { |
2566 | /* No overlay handling: just remove the breakpoint. */ | |
2567 | ||
35df4500 TJB |
2568 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2569 | val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
c02f5703 | 2570 | else |
35df4500 | 2571 | val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
c02f5703 | 2572 | } |
c906108c SS |
2573 | else |
2574 | { | |
4a64f543 | 2575 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2576 | Did we set a breakpoint at the LMA? */ |
2577 | if (!overlay_events_enabled) | |
2578 | { | |
2579 | /* Yes -- overlay event support is not active, so we | |
2580 | should have set a breakpoint at the LMA. Remove it. | |
2581 | */ | |
c02f5703 MS |
2582 | /* Ignore any failures: if the LMA is in ROM, we will |
2583 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2584 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2585 | target_remove_hw_breakpoint (bl->gdbarch, | |
2586 | &bl->overlay_target_info); | |
c02f5703 | 2587 | else |
35df4500 TJB |
2588 | target_remove_breakpoint (bl->gdbarch, |
2589 | &bl->overlay_target_info); | |
c02f5703 MS |
2590 | } |
2591 | /* Did we set a breakpoint at the VMA? | |
2592 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2593 | if (bl->inserted) |
c906108c | 2594 | { |
c02f5703 MS |
2595 | /* Yes -- remove it. Previously we did not bother to |
2596 | remove the breakpoint if the section had been | |
2597 | unmapped, but let's not rely on that being safe. We | |
2598 | don't know what the overlay manager might do. */ | |
35df4500 TJB |
2599 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2600 | val = target_remove_hw_breakpoint (bl->gdbarch, | |
2601 | &bl->target_info); | |
aa67235e UW |
2602 | |
2603 | /* However, we should remove *software* breakpoints only | |
2604 | if the section is still mapped, or else we overwrite | |
2605 | wrong code with the saved shadow contents. */ | |
35df4500 TJB |
2606 | else if (section_is_mapped (bl->section)) |
2607 | val = target_remove_breakpoint (bl->gdbarch, | |
2608 | &bl->target_info); | |
aa67235e UW |
2609 | else |
2610 | val = 0; | |
c906108c | 2611 | } |
c02f5703 MS |
2612 | else |
2613 | { | |
2614 | /* No -- not inserted, so no need to remove. No error. */ | |
2615 | val = 0; | |
2616 | } | |
c906108c | 2617 | } |
879d1e6b UW |
2618 | |
2619 | /* In some cases, we might not be able to remove a breakpoint | |
2620 | in a shared library that has already been removed, but we | |
2621 | have not yet processed the shlib unload event. */ | |
35df4500 | 2622 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2623 | val = 0; |
2624 | ||
c906108c SS |
2625 | if (val) |
2626 | return val; | |
35df4500 | 2627 | bl->inserted = (is == mark_inserted); |
c906108c | 2628 | } |
35df4500 | 2629 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2630 | { |
77b06cd7 TJB |
2631 | gdb_assert (bl->owner->ops != NULL |
2632 | && bl->owner->ops->remove_location != NULL); | |
2633 | ||
35df4500 | 2634 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2635 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2636 | |
c906108c | 2637 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2638 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2639 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2640 | bl->owner->number); |
c906108c | 2641 | } |
35df4500 TJB |
2642 | else if (bl->owner->type == bp_catchpoint |
2643 | && breakpoint_enabled (bl->owner) | |
2644 | && !bl->duplicate) | |
ce78b96d | 2645 | { |
77b06cd7 TJB |
2646 | gdb_assert (bl->owner->ops != NULL |
2647 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2648 | |
77b06cd7 | 2649 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2650 | if (val) |
2651 | return val; | |
77b06cd7 | 2652 | |
35df4500 | 2653 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2654 | } |
c906108c SS |
2655 | |
2656 | return 0; | |
2657 | } | |
2658 | ||
6c95b8df | 2659 | static int |
35df4500 | 2660 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2661 | { |
2662 | int ret; | |
2663 | struct cleanup *old_chain; | |
2664 | ||
35df4500 TJB |
2665 | /* BL is never in moribund_locations by our callers. */ |
2666 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2667 | |
35df4500 | 2668 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2669 | /* Permanent breakpoints cannot be inserted or removed. */ |
2670 | return 0; | |
2671 | ||
2672 | /* The type of none suggests that owner is actually deleted. | |
2673 | This should not ever happen. */ | |
35df4500 | 2674 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2675 | |
2676 | old_chain = save_current_space_and_thread (); | |
2677 | ||
35df4500 | 2678 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2679 | |
35df4500 | 2680 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2681 | |
2682 | do_cleanups (old_chain); | |
2683 | return ret; | |
2684 | } | |
2685 | ||
c906108c SS |
2686 | /* Clear the "inserted" flag in all breakpoints. */ |
2687 | ||
25b22b0a | 2688 | void |
fba45db2 | 2689 | mark_breakpoints_out (void) |
c906108c | 2690 | { |
35df4500 | 2691 | struct bp_location *bl, **blp_tmp; |
c906108c | 2692 | |
35df4500 TJB |
2693 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2694 | if (bl->pspace == current_program_space) | |
2695 | bl->inserted = 0; | |
c906108c SS |
2696 | } |
2697 | ||
53a5351d JM |
2698 | /* Clear the "inserted" flag in all breakpoints and delete any |
2699 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2700 | |
2701 | Plus other such housekeeping that has to be done for breakpoints | |
2702 | between runs. | |
2703 | ||
53a5351d JM |
2704 | Note: this function gets called at the end of a run (by |
2705 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2706 | init_wait_for_inferior). */ |
c906108c SS |
2707 | |
2708 | ||
2709 | ||
2710 | void | |
fba45db2 | 2711 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2712 | { |
35df4500 TJB |
2713 | struct breakpoint *b, *b_tmp; |
2714 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2715 | int ix; |
6c95b8df | 2716 | struct program_space *pspace = current_program_space; |
c906108c | 2717 | |
50c71eaf PA |
2718 | /* If breakpoint locations are shared across processes, then there's |
2719 | nothing to do. */ | |
2567c7d9 | 2720 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2721 | return; |
2722 | ||
35df4500 | 2723 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2724 | { |
35df4500 TJB |
2725 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2726 | if (bl->pspace == pspace | |
2727 | && bl->owner->enable_state != bp_permanent) | |
2728 | bl->inserted = 0; | |
6c95b8df | 2729 | } |
075f6582 | 2730 | |
35df4500 | 2731 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2732 | { |
6c95b8df PA |
2733 | if (b->loc && b->loc->pspace != pspace) |
2734 | continue; | |
2735 | ||
c5aa993b JM |
2736 | switch (b->type) |
2737 | { | |
2738 | case bp_call_dummy: | |
c906108c | 2739 | |
c5aa993b | 2740 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2741 | cause problems when the inferior is rerun, so we better get |
2742 | rid of it. */ | |
2743 | ||
2744 | case bp_watchpoint_scope: | |
2745 | ||
2746 | /* Also get rid of scope breakpoints. */ | |
2747 | ||
2748 | case bp_shlib_event: | |
2749 | ||
2750 | /* Also remove solib event breakpoints. Their addresses may | |
2751 | have changed since the last time we ran the program. | |
2752 | Actually we may now be debugging against different target; | |
2753 | and so the solib backend that installed this breakpoint may | |
2754 | not be used in by the target. E.g., | |
2755 | ||
2756 | (gdb) file prog-linux | |
2757 | (gdb) run # native linux target | |
2758 | ... | |
2759 | (gdb) kill | |
2760 | (gdb) file prog-win.exe | |
2761 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2762 | */ | |
c906108c | 2763 | |
c5aa993b JM |
2764 | delete_breakpoint (b); |
2765 | break; | |
c906108c | 2766 | |
c5aa993b JM |
2767 | case bp_watchpoint: |
2768 | case bp_hardware_watchpoint: | |
2769 | case bp_read_watchpoint: | |
2770 | case bp_access_watchpoint: | |
c906108c | 2771 | |
c5aa993b JM |
2772 | /* Likewise for watchpoints on local expressions. */ |
2773 | if (b->exp_valid_block != NULL) | |
2774 | delete_breakpoint (b); | |
967af18d | 2775 | else if (context == inf_starting) |
c860120c | 2776 | { |
4a64f543 MS |
2777 | /* Reset val field to force reread of starting value in |
2778 | insert_breakpoints. */ | |
c860120c PM |
2779 | if (b->val) |
2780 | value_free (b->val); | |
2781 | b->val = NULL; | |
fa4727a6 | 2782 | b->val_valid = 0; |
c860120c | 2783 | } |
c5aa993b JM |
2784 | break; |
2785 | default: | |
c5aa993b JM |
2786 | break; |
2787 | } | |
2788 | } | |
1c5cfe86 PA |
2789 | |
2790 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2791 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2792 | decref_bp_location (&bl); | |
1c5cfe86 | 2793 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2794 | } |
2795 | ||
6c95b8df PA |
2796 | /* These functions concern about actual breakpoints inserted in the |
2797 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2798 | we need to hop over the bkpt --- so we check for address space | |
2799 | match, not program space. */ | |
2800 | ||
c2c6d25f JM |
2801 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2802 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2803 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2804 | permanent breakpoint. | |
2805 | - When continuing from a location with an ordinary breakpoint, we | |
2806 | actually single step once before calling insert_breakpoints. | |
2807 | - When continuing from a localion with a permanent breakpoint, we | |
2808 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2809 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2810 | |
c2c6d25f | 2811 | enum breakpoint_here |
6c95b8df | 2812 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2813 | { |
35df4500 | 2814 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2815 | int any_breakpoint_here = 0; |
c906108c | 2816 | |
35df4500 | 2817 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2818 | { |
35df4500 TJB |
2819 | if (bl->loc_type != bp_loc_software_breakpoint |
2820 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2821 | continue; |
2822 | ||
f1310107 | 2823 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
2824 | if ((breakpoint_enabled (bl->owner) |
2825 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 2826 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2827 | { |
2828 | if (overlay_debugging | |
35df4500 TJB |
2829 | && section_is_overlay (bl->section) |
2830 | && !section_is_mapped (bl->section)) | |
075f6582 | 2831 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2832 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2833 | return permanent_breakpoint_here; |
2834 | else | |
2835 | any_breakpoint_here = 1; | |
2836 | } | |
2837 | } | |
c906108c | 2838 | |
c2c6d25f | 2839 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2840 | } |
2841 | ||
1c5cfe86 PA |
2842 | /* Return true if there's a moribund breakpoint at PC. */ |
2843 | ||
2844 | int | |
6c95b8df | 2845 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2846 | { |
2847 | struct bp_location *loc; | |
2848 | int ix; | |
2849 | ||
2850 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 2851 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
2852 | return 1; |
2853 | ||
2854 | return 0; | |
2855 | } | |
c2c6d25f | 2856 | |
c36b740a | 2857 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2858 | inserted using regular breakpoint_chain / bp_location array |
2859 | mechanism. This does not check for single-step breakpoints, which | |
2860 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2861 | |
2862 | int | |
4a64f543 MS |
2863 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2864 | CORE_ADDR pc) | |
c906108c | 2865 | { |
35df4500 | 2866 | struct bp_location *bl, **blp_tmp; |
c906108c | 2867 | |
35df4500 | 2868 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2869 | { |
35df4500 TJB |
2870 | if (bl->loc_type != bp_loc_software_breakpoint |
2871 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2872 | continue; |
2873 | ||
35df4500 | 2874 | if (bl->inserted |
f1310107 | 2875 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2876 | { |
2877 | if (overlay_debugging | |
35df4500 TJB |
2878 | && section_is_overlay (bl->section) |
2879 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2880 | continue; /* unmapped overlay -- can't be a match */ |
2881 | else | |
2882 | return 1; | |
2883 | } | |
c5aa993b | 2884 | } |
c36b740a VP |
2885 | return 0; |
2886 | } | |
2887 | ||
2888 | /* Returns non-zero iff there's either regular breakpoint | |
2889 | or a single step breakpoint inserted at PC. */ | |
2890 | ||
2891 | int | |
6c95b8df | 2892 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2893 | { |
6c95b8df | 2894 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2895 | return 1; |
c906108c | 2896 | |
6c95b8df | 2897 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2898 | return 1; |
2899 | ||
c906108c SS |
2900 | return 0; |
2901 | } | |
2902 | ||
4fa8626c DJ |
2903 | /* This function returns non-zero iff there is a software breakpoint |
2904 | inserted at PC. */ | |
2905 | ||
2906 | int | |
3e43a32a MS |
2907 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2908 | CORE_ADDR pc) | |
4fa8626c | 2909 | { |
35df4500 | 2910 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2911 | |
35df4500 | 2912 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2913 | { |
35df4500 | 2914 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2915 | continue; |
2916 | ||
35df4500 TJB |
2917 | if (bl->inserted |
2918 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2919 | aspace, pc)) |
4fa8626c DJ |
2920 | { |
2921 | if (overlay_debugging | |
35df4500 TJB |
2922 | && section_is_overlay (bl->section) |
2923 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2924 | continue; /* unmapped overlay -- can't be a match */ |
2925 | else | |
2926 | return 1; | |
2927 | } | |
2928 | } | |
2929 | ||
1aafd4da | 2930 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2931 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2932 | return 1; |
2933 | ||
4fa8626c DJ |
2934 | return 0; |
2935 | } | |
2936 | ||
9093389c PA |
2937 | int |
2938 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2939 | CORE_ADDR addr, ULONGEST len) | |
2940 | { | |
2941 | struct breakpoint *bpt; | |
2942 | ||
2943 | ALL_BREAKPOINTS (bpt) | |
2944 | { | |
2945 | struct bp_location *loc; | |
2946 | ||
2947 | if (bpt->type != bp_hardware_watchpoint | |
2948 | && bpt->type != bp_access_watchpoint) | |
2949 | continue; | |
2950 | ||
2951 | if (!breakpoint_enabled (bpt)) | |
2952 | continue; | |
2953 | ||
2954 | for (loc = bpt->loc; loc; loc = loc->next) | |
2955 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2956 | { | |
2957 | CORE_ADDR l, h; | |
2958 | ||
2959 | /* Check for intersection. */ | |
2960 | l = max (loc->address, addr); | |
2961 | h = min (loc->address + loc->length, addr + len); | |
2962 | if (l < h) | |
2963 | return 1; | |
2964 | } | |
2965 | } | |
2966 | return 0; | |
2967 | } | |
2968 | ||
075f6582 DJ |
2969 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2970 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2971 | |
2972 | int | |
6c95b8df PA |
2973 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2974 | ptid_t ptid) | |
c906108c | 2975 | { |
35df4500 | 2976 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 2977 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2978 | int thread = -1; |
4a306c9a | 2979 | int task = 0; |
a6f1cd96 | 2980 | |
35df4500 | 2981 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2982 | { |
35df4500 TJB |
2983 | if (bl->loc_type != bp_loc_software_breakpoint |
2984 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2985 | continue; |
2986 | ||
35df4500 TJB |
2987 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2988 | if (!breakpoint_enabled (bl->owner) | |
2989 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
2990 | continue; |
2991 | ||
f1310107 | 2992 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
2993 | continue; |
2994 | ||
35df4500 | 2995 | if (bl->owner->thread != -1) |
075f6582 | 2996 | { |
a6f1cd96 JB |
2997 | /* This is a thread-specific breakpoint. Check that ptid |
2998 | matches that thread. If thread hasn't been computed yet, | |
2999 | it is now time to do so. */ | |
3000 | if (thread == -1) | |
3001 | thread = pid_to_thread_id (ptid); | |
35df4500 | 3002 | if (bl->owner->thread != thread) |
a6f1cd96 | 3003 | continue; |
075f6582 | 3004 | } |
a6f1cd96 | 3005 | |
35df4500 | 3006 | if (bl->owner->task != 0) |
4a306c9a JB |
3007 | { |
3008 | /* This is a task-specific breakpoint. Check that ptid | |
3009 | matches that task. If task hasn't been computed yet, | |
3010 | it is now time to do so. */ | |
3011 | if (task == 0) | |
3012 | task = ada_get_task_number (ptid); | |
35df4500 | 3013 | if (bl->owner->task != task) |
4a306c9a JB |
3014 | continue; |
3015 | } | |
3016 | ||
a6f1cd96 | 3017 | if (overlay_debugging |
35df4500 TJB |
3018 | && section_is_overlay (bl->section) |
3019 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3020 | continue; /* unmapped overlay -- can't be a match */ |
3021 | ||
3022 | return 1; | |
c5aa993b | 3023 | } |
c906108c SS |
3024 | |
3025 | return 0; | |
3026 | } | |
c906108c | 3027 | \f |
c5aa993b | 3028 | |
c906108c SS |
3029 | /* bpstat stuff. External routines' interfaces are documented |
3030 | in breakpoint.h. */ | |
3031 | ||
3032 | int | |
fba45db2 | 3033 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3034 | { |
533be4dd | 3035 | return (ep->type == bp_catchpoint); |
c906108c SS |
3036 | } |
3037 | ||
f431efe5 PA |
3038 | /* Frees any storage that is part of a bpstat. Does not walk the |
3039 | 'next' chain. */ | |
3040 | ||
3041 | static void | |
198757a8 VP |
3042 | bpstat_free (bpstat bs) |
3043 | { | |
3044 | if (bs->old_val != NULL) | |
3045 | value_free (bs->old_val); | |
9add0f1b | 3046 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3047 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3048 | xfree (bs); |
3049 | } | |
3050 | ||
c906108c SS |
3051 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3052 | Also free any storage that is part of a bpstat. */ | |
3053 | ||
3054 | void | |
fba45db2 | 3055 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3056 | { |
3057 | bpstat p; | |
3058 | bpstat q; | |
3059 | ||
3060 | if (bsp == 0) | |
3061 | return; | |
3062 | p = *bsp; | |
3063 | while (p != NULL) | |
3064 | { | |
3065 | q = p->next; | |
198757a8 | 3066 | bpstat_free (p); |
c906108c SS |
3067 | p = q; |
3068 | } | |
3069 | *bsp = NULL; | |
3070 | } | |
3071 | ||
3072 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3073 | is part of the bpstat is copied as well. */ | |
3074 | ||
3075 | bpstat | |
fba45db2 | 3076 | bpstat_copy (bpstat bs) |
c906108c SS |
3077 | { |
3078 | bpstat p = NULL; | |
3079 | bpstat tmp; | |
3080 | bpstat retval = NULL; | |
3081 | ||
3082 | if (bs == NULL) | |
3083 | return bs; | |
3084 | ||
3085 | for (; bs != NULL; bs = bs->next) | |
3086 | { | |
3087 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3088 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3089 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3090 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3091 | if (bs->old_val != NULL) |
3c3185ac JK |
3092 | { |
3093 | tmp->old_val = value_copy (bs->old_val); | |
3094 | release_value (tmp->old_val); | |
3095 | } | |
31cc81e9 | 3096 | |
c906108c SS |
3097 | if (p == NULL) |
3098 | /* This is the first thing in the chain. */ | |
3099 | retval = tmp; | |
3100 | else | |
3101 | p->next = tmp; | |
3102 | p = tmp; | |
3103 | } | |
3104 | p->next = NULL; | |
3105 | return retval; | |
3106 | } | |
3107 | ||
4a64f543 | 3108 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3109 | |
3110 | bpstat | |
fba45db2 | 3111 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3112 | { |
c5aa993b JM |
3113 | if (bsp == NULL) |
3114 | return NULL; | |
c906108c | 3115 | |
c5aa993b JM |
3116 | for (; bsp != NULL; bsp = bsp->next) |
3117 | { | |
f431efe5 | 3118 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3119 | return bsp; |
3120 | } | |
c906108c SS |
3121 | return NULL; |
3122 | } | |
3123 | ||
4a64f543 MS |
3124 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3125 | stopped at. *BSP upon return is a bpstat which points to the | |
3126 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3127 | good for anything but further calls to bpstat_num). | |
3128 | ||
8671a17b PA |
3129 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3130 | Return -1 if stopped at a breakpoint that has been deleted since | |
3131 | we set it. | |
3132 | Return 1 otherwise. */ | |
c906108c SS |
3133 | |
3134 | int | |
8671a17b | 3135 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3136 | { |
3137 | struct breakpoint *b; | |
3138 | ||
3139 | if ((*bsp) == NULL) | |
3140 | return 0; /* No more breakpoint values */ | |
8671a17b | 3141 | |
4a64f543 MS |
3142 | /* We assume we'll never have several bpstats that correspond to a |
3143 | single breakpoint -- otherwise, this function might return the | |
3144 | same number more than once and this will look ugly. */ | |
f431efe5 | 3145 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3146 | *bsp = (*bsp)->next; |
3147 | if (b == NULL) | |
3148 | return -1; /* breakpoint that's been deleted since */ | |
3149 | ||
3150 | *num = b->number; /* We have its number */ | |
3151 | return 1; | |
c906108c SS |
3152 | } |
3153 | ||
3154 | /* Modify BS so that the actions will not be performed. */ | |
3155 | ||
3156 | void | |
fba45db2 | 3157 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3158 | { |
3159 | for (; bs != NULL; bs = bs->next) | |
3160 | { | |
9add0f1b | 3161 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3162 | bs->commands_left = NULL; |
c906108c SS |
3163 | if (bs->old_val != NULL) |
3164 | { | |
3165 | value_free (bs->old_val); | |
3166 | bs->old_val = NULL; | |
3167 | } | |
3168 | } | |
3169 | } | |
3170 | ||
f3b1572e PA |
3171 | /* Called when a command is about to proceed the inferior. */ |
3172 | ||
3173 | static void | |
3174 | breakpoint_about_to_proceed (void) | |
3175 | { | |
3176 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3177 | { | |
3178 | struct thread_info *tp = inferior_thread (); | |
3179 | ||
3180 | /* Allow inferior function calls in breakpoint commands to not | |
3181 | interrupt the command list. When the call finishes | |
3182 | successfully, the inferior will be standing at the same | |
3183 | breakpoint as if nothing happened. */ | |
16c381f0 | 3184 | if (tp->control.in_infcall) |
f3b1572e PA |
3185 | return; |
3186 | } | |
3187 | ||
3188 | breakpoint_proceeded = 1; | |
3189 | } | |
3190 | ||
4a64f543 MS |
3191 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3192 | command. */ | |
c906108c | 3193 | static void |
4efb68b1 | 3194 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3195 | { |
3196 | executing_breakpoint_commands = 0; | |
3197 | } | |
3198 | ||
4a64f543 MS |
3199 | /* Execute all the commands associated with all the breakpoints at |
3200 | this location. Any of these commands could cause the process to | |
3201 | proceed beyond this point, etc. We look out for such changes by | |
3202 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3203 | |
347bddb7 PA |
3204 | Returns true if a breakpoint command resumed the inferior. In that |
3205 | case, it is the caller's responsibility to recall it again with the | |
3206 | bpstat of the current thread. */ | |
3207 | ||
3208 | static int | |
3209 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3210 | { |
3211 | bpstat bs; | |
3212 | struct cleanup *old_chain; | |
347bddb7 | 3213 | int again = 0; |
c906108c SS |
3214 | |
3215 | /* Avoid endless recursion if a `source' command is contained | |
3216 | in bs->commands. */ | |
3217 | if (executing_breakpoint_commands) | |
347bddb7 | 3218 | return 0; |
c906108c SS |
3219 | |
3220 | executing_breakpoint_commands = 1; | |
3221 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3222 | ||
4a64f543 | 3223 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3224 | bs = *bsp; |
3225 | ||
3226 | breakpoint_proceeded = 0; | |
3227 | for (; bs != NULL; bs = bs->next) | |
3228 | { | |
9add0f1b | 3229 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3230 | struct command_line *cmd; |
3231 | struct cleanup *this_cmd_tree_chain; | |
3232 | ||
3233 | /* Take ownership of the BSP's command tree, if it has one. | |
3234 | ||
3235 | The command tree could legitimately contain commands like | |
3236 | 'step' and 'next', which call clear_proceed_status, which | |
3237 | frees stop_bpstat's command tree. To make sure this doesn't | |
3238 | free the tree we're executing out from under us, we need to | |
3239 | take ownership of the tree ourselves. Since a given bpstat's | |
3240 | commands are only executed once, we don't need to copy it; we | |
3241 | can clear the pointer in the bpstat, and make sure we free | |
3242 | the tree when we're done. */ | |
9add0f1b TT |
3243 | ccmd = bs->commands; |
3244 | bs->commands = NULL; | |
3245 | this_cmd_tree_chain | |
3246 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3247 | cmd = bs->commands_left; | |
3248 | bs->commands_left = NULL; | |
6c50ab1c | 3249 | |
c906108c SS |
3250 | while (cmd != NULL) |
3251 | { | |
3252 | execute_control_command (cmd); | |
3253 | ||
3254 | if (breakpoint_proceeded) | |
3255 | break; | |
3256 | else | |
3257 | cmd = cmd->next; | |
3258 | } | |
6c50ab1c JB |
3259 | |
3260 | /* We can free this command tree now. */ | |
3261 | do_cleanups (this_cmd_tree_chain); | |
3262 | ||
c906108c | 3263 | if (breakpoint_proceeded) |
32c1e744 VP |
3264 | { |
3265 | if (target_can_async_p ()) | |
347bddb7 PA |
3266 | /* If we are in async mode, then the target might be still |
3267 | running, not stopped at any breakpoint, so nothing for | |
3268 | us to do here -- just return to the event loop. */ | |
3269 | ; | |
32c1e744 VP |
3270 | else |
3271 | /* In sync mode, when execute_control_command returns | |
3272 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3273 | Breakpoint commands for that stop were not run, since |
3274 | execute_command does not run breakpoint commands -- | |
3275 | only command_line_handler does, but that one is not | |
3276 | involved in execution of breakpoint commands. So, we | |
3277 | can now execute breakpoint commands. It should be | |
3278 | noted that making execute_command do bpstat actions is | |
3279 | not an option -- in this case we'll have recursive | |
3280 | invocation of bpstat for each breakpoint with a | |
3281 | command, and can easily blow up GDB stack. Instead, we | |
3282 | return true, which will trigger the caller to recall us | |
3283 | with the new stop_bpstat. */ | |
3284 | again = 1; | |
3285 | break; | |
32c1e744 | 3286 | } |
c906108c | 3287 | } |
c2b8ed2c | 3288 | do_cleanups (old_chain); |
347bddb7 PA |
3289 | return again; |
3290 | } | |
3291 | ||
3292 | void | |
3293 | bpstat_do_actions (void) | |
3294 | { | |
3295 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3296 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3297 | && target_has_execution | |
3298 | && !is_exited (inferior_ptid) | |
3299 | && !is_executing (inferior_ptid)) | |
3300 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3301 | and only return when it is stopped at the next breakpoint, we | |
3302 | keep doing breakpoint actions until it returns false to | |
3303 | indicate the inferior was not resumed. */ | |
16c381f0 | 3304 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3305 | break; |
c906108c SS |
3306 | } |
3307 | ||
fa4727a6 DJ |
3308 | /* Print out the (old or new) value associated with a watchpoint. */ |
3309 | ||
3310 | static void | |
3311 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3312 | { | |
3313 | if (val == NULL) | |
3314 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3315 | else | |
79a45b7d TT |
3316 | { |
3317 | struct value_print_options opts; | |
3318 | get_user_print_options (&opts); | |
3319 | value_print (val, stream, &opts); | |
3320 | } | |
fa4727a6 DJ |
3321 | } |
3322 | ||
e514a9d6 | 3323 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3324 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3325 | by having it set different print_it values. |
3326 | ||
3327 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3328 | through the bpstat list of things causing this stop, calling the | |
4a64f543 | 3329 | print_bp_stop_message function on each one. The behavior of the |
e514a9d6 | 3330 | print_bp_stop_message function depends on the print_it field of |
4a64f543 | 3331 | bpstat. If such field so indicates, call this function here. |
e514a9d6 JM |
3332 | |
3333 | Return values from this routine (ultimately used by bpstat_print() | |
3334 | and normal_stop() to decide what to do): | |
3335 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3336 | don't print anything else. | |
3337 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3338 | that something to be followed by a location. | |
3339 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3340 | that something to be followed by a location. | |
3341 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3342 | analysis. */ | |
c906108c | 3343 | |
917317f4 | 3344 | static enum print_stop_action |
fba45db2 | 3345 | print_it_typical (bpstat bs) |
c906108c | 3346 | { |
f7545552 | 3347 | struct cleanup *old_chain; |
4f8d1dc6 | 3348 | struct breakpoint *b; |
89f9893c | 3349 | const struct bp_location *bl; |
8b93c638 | 3350 | struct ui_stream *stb; |
f7545552 TT |
3351 | int bp_temp = 0; |
3352 | enum print_stop_action result; | |
3353 | ||
f431efe5 PA |
3354 | gdb_assert (bs->bp_location_at != NULL); |
3355 | ||
3356 | bl = bs->bp_location_at; | |
3357 | b = bs->breakpoint_at; | |
c906108c | 3358 | |
f7545552 TT |
3359 | stb = ui_out_stream_new (uiout); |
3360 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3361 | ||
4f8d1dc6 | 3362 | switch (b->type) |
c906108c | 3363 | { |
e514a9d6 JM |
3364 | case bp_breakpoint: |
3365 | case bp_hardware_breakpoint: | |
f431efe5 | 3366 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3367 | if (bl->address != bl->requested_address) |
3368 | breakpoint_adjustment_warning (bl->requested_address, | |
3369 | bl->address, | |
4f8d1dc6 VP |
3370 | b->number, 1); |
3371 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3372 | if (bp_temp) |
3373 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3374 | else | |
3375 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3376 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3377 | { |
3378 | ui_out_field_string (uiout, "reason", | |
3379 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3380 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3381 | } | |
4f8d1dc6 | 3382 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3383 | ui_out_text (uiout, ", "); |
f7545552 | 3384 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3385 | break; |
3386 | ||
3387 | case bp_shlib_event: | |
917317f4 JM |
3388 | /* Did we stop because the user set the stop_on_solib_events |
3389 | variable? (If so, we report this as a generic, "Stopped due | |
3390 | to shlib event" message.) */ | |
a3f17187 | 3391 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3392 | result = PRINT_NOTHING; |
e514a9d6 JM |
3393 | break; |
3394 | ||
c4093a6a | 3395 | case bp_thread_event: |
4a64f543 | 3396 | /* Not sure how we will get here. |
c4093a6a | 3397 | GDB should not stop for these breakpoints. */ |
a3f17187 | 3398 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3399 | result = PRINT_NOTHING; |
c4093a6a JM |
3400 | break; |
3401 | ||
1900040c | 3402 | case bp_overlay_event: |
4a64f543 | 3403 | /* By analogy with the thread event, GDB should not stop for these. */ |
a3f17187 | 3404 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3405 | result = PRINT_NOTHING; |
1900040c MS |
3406 | break; |
3407 | ||
0fd8e87f UW |
3408 | case bp_longjmp_master: |
3409 | /* These should never be enabled. */ | |
3410 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3411 | result = PRINT_NOTHING; | |
3412 | break; | |
3413 | ||
aa7d318d TT |
3414 | case bp_std_terminate_master: |
3415 | /* These should never be enabled. */ | |
3e43a32a MS |
3416 | printf_filtered (_("std::terminate Master Breakpoint: " |
3417 | "gdb should not stop!\n")); | |
aa7d318d TT |
3418 | result = PRINT_NOTHING; |
3419 | break; | |
3420 | ||
186c406b TT |
3421 | case bp_exception_master: |
3422 | /* These should never be enabled. */ | |
3e43a32a MS |
3423 | printf_filtered (_("Exception Master Breakpoint: " |
3424 | "gdb should not stop!\n")); | |
186c406b TT |
3425 | result = PRINT_NOTHING; |
3426 | break; | |
3427 | ||
e514a9d6 JM |
3428 | case bp_watchpoint: |
3429 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3430 | annotate_watchpoint (b->number); |
3431 | if (ui_out_is_mi_like_p (uiout)) | |
3432 | ui_out_field_string | |
3433 | (uiout, "reason", | |
3434 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3435 | mention (b); | |
f7545552 | 3436 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3437 | ui_out_text (uiout, "\nOld value = "); |
3438 | watchpoint_value_print (bs->old_val, stb->stream); | |
3439 | ui_out_field_stream (uiout, "old", stb); | |
3440 | ui_out_text (uiout, "\nNew value = "); | |
3441 | watchpoint_value_print (b->val, stb->stream); | |
3442 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3443 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3444 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3445 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3446 | break; |
3447 | ||
3448 | case bp_read_watchpoint: | |
9dc5e2a9 | 3449 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3450 | ui_out_field_string |
3451 | (uiout, "reason", | |
3452 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3453 | mention (b); |
f7545552 | 3454 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3455 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3456 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3457 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3458 | ui_out_text (uiout, "\n"); |
f7545552 | 3459 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3460 | break; |
3461 | ||
3462 | case bp_access_watchpoint: | |
fa4727a6 | 3463 | if (bs->old_val != NULL) |
8b93c638 | 3464 | { |
4f8d1dc6 | 3465 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3466 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3467 | ui_out_field_string |
3468 | (uiout, "reason", | |
3469 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3470 | mention (b); |
f7545552 | 3471 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3472 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3473 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3474 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3475 | ui_out_text (uiout, "\nNew value = "); |
3476 | } | |
3477 | else | |
3478 | { | |
4f8d1dc6 | 3479 | mention (b); |
9dc5e2a9 | 3480 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3481 | ui_out_field_string |
3482 | (uiout, "reason", | |
3483 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3484 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3485 | ui_out_text (uiout, "\nValue = "); |
3486 | } | |
fa4727a6 | 3487 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3488 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3489 | ui_out_text (uiout, "\n"); |
f7545552 | 3490 | result = PRINT_UNKNOWN; |
e514a9d6 | 3491 | break; |
4ce44c66 | 3492 | |
e514a9d6 | 3493 | /* Fall through, we don't deal with these types of breakpoints |
4a64f543 | 3494 | here. */ |
e514a9d6 | 3495 | |
11cf8741 | 3496 | case bp_finish: |
9dc5e2a9 | 3497 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3498 | ui_out_field_string |
3499 | (uiout, "reason", | |
3500 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3501 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3502 | break; |
3503 | ||
e514a9d6 | 3504 | case bp_until: |
9dc5e2a9 | 3505 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3506 | ui_out_field_string |
3507 | (uiout, "reason", | |
3508 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3509 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3510 | break; |
3511 | ||
c2d11a7d | 3512 | case bp_none: |
e514a9d6 JM |
3513 | case bp_longjmp: |
3514 | case bp_longjmp_resume: | |
186c406b TT |
3515 | case bp_exception: |
3516 | case bp_exception_resume: | |
e514a9d6 | 3517 | case bp_step_resume: |
e514a9d6 JM |
3518 | case bp_watchpoint_scope: |
3519 | case bp_call_dummy: | |
aa7d318d | 3520 | case bp_std_terminate: |
1042e4c0 | 3521 | case bp_tracepoint: |
7a697b8d | 3522 | case bp_fast_tracepoint: |
4efc6507 | 3523 | case bp_jit_event: |
0e30163f JK |
3524 | case bp_gnu_ifunc_resolver: |
3525 | case bp_gnu_ifunc_resolver_return: | |
e514a9d6 | 3526 | default: |
f7545552 TT |
3527 | result = PRINT_UNKNOWN; |
3528 | break; | |
e514a9d6 | 3529 | } |
f7545552 TT |
3530 | |
3531 | do_cleanups (old_chain); | |
3532 | return result; | |
e514a9d6 JM |
3533 | } |
3534 | ||
3535 | /* Generic routine for printing messages indicating why we | |
4a64f543 | 3536 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3537 | 'print_it' in the bpstat structure. Under some circumstances we |
3538 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3539 | normal_stop(). */ |
e514a9d6 JM |
3540 | |
3541 | static enum print_stop_action | |
3542 | print_bp_stop_message (bpstat bs) | |
3543 | { | |
3544 | switch (bs->print_it) | |
3545 | { | |
3546 | case print_it_noop: | |
4a64f543 | 3547 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3548 | return PRINT_UNKNOWN; |
3549 | break; | |
3550 | ||
3551 | case print_it_done: | |
3552 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3553 | relevant messages. */ |
e514a9d6 JM |
3554 | return PRINT_SRC_AND_LOC; |
3555 | break; | |
3556 | ||
3557 | case print_it_normal: | |
4f8d1dc6 | 3558 | { |
f431efe5 PA |
3559 | struct breakpoint *b = bs->breakpoint_at; |
3560 | ||
1a6a67de TJB |
3561 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3562 | which has since been deleted. */ | |
3563 | if (b == NULL) | |
3564 | return PRINT_UNKNOWN; | |
3565 | ||
4f8d1dc6 VP |
3566 | /* Normal case. Call the breakpoint's print_it method, or |
3567 | print_it_typical. */ | |
1a6a67de | 3568 | if (b->ops != NULL && b->ops->print_it != NULL) |
4f8d1dc6 VP |
3569 | return b->ops->print_it (b); |
3570 | else | |
3571 | return print_it_typical (bs); | |
3572 | } | |
3573 | break; | |
3086aeae | 3574 | |
e514a9d6 | 3575 | default: |
8e65ff28 | 3576 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3577 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3578 | break; |
c906108c | 3579 | } |
c906108c SS |
3580 | } |
3581 | ||
e514a9d6 JM |
3582 | /* Print a message indicating what happened. This is called from |
3583 | normal_stop(). The input to this routine is the head of the bpstat | |
3584 | list - a list of the eventpoints that caused this stop. This | |
3585 | routine calls the generic print routine for printing a message | |
3586 | about reasons for stopping. This will print (for example) the | |
3587 | "Breakpoint n," part of the output. The return value of this | |
3588 | routine is one of: | |
c906108c | 3589 | |
4a64f543 | 3590 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3591 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3592 | code to print the location. An example is |
c5aa993b JM |
3593 | "Breakpoint 1, " which should be followed by |
3594 | the location. | |
917317f4 | 3595 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3596 | to also print the location part of the message. |
3597 | An example is the catch/throw messages, which | |
4a64f543 | 3598 | don't require a location appended to the end. |
917317f4 | 3599 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3600 | further info to be printed. */ |
c906108c | 3601 | |
917317f4 | 3602 | enum print_stop_action |
fba45db2 | 3603 | bpstat_print (bpstat bs) |
c906108c SS |
3604 | { |
3605 | int val; | |
c5aa993b | 3606 | |
c906108c | 3607 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3608 | (Currently all watchpoints go on the bpstat whether hit or not. |
3609 | That probably could (should) be changed, provided care is taken | |
c906108c | 3610 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3611 | for (; bs; bs = bs->next) |
3612 | { | |
3613 | val = print_bp_stop_message (bs); | |
3614 | if (val == PRINT_SRC_ONLY | |
3615 | || val == PRINT_SRC_AND_LOC | |
3616 | || val == PRINT_NOTHING) | |
3617 | return val; | |
3618 | } | |
c906108c | 3619 | |
e514a9d6 | 3620 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3621 | with and nothing was printed. */ |
917317f4 | 3622 | return PRINT_UNKNOWN; |
c906108c SS |
3623 | } |
3624 | ||
4a64f543 MS |
3625 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3626 | used inside a catch_errors to evaluate the breakpoint condition. | |
3627 | The argument is a "struct expression *" that has been cast to a | |
3628 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3629 | |
3630 | static int | |
4efb68b1 | 3631 | breakpoint_cond_eval (void *exp) |
c906108c | 3632 | { |
278cd55f | 3633 | struct value *mark = value_mark (); |
c5aa993b | 3634 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3635 | |
c906108c SS |
3636 | value_free_to_mark (mark); |
3637 | return i; | |
3638 | } | |
3639 | ||
5760d0ab | 3640 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3641 | |
3642 | static bpstat | |
5760d0ab | 3643 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3644 | { |
3645 | bpstat bs; | |
3646 | ||
3647 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3648 | bs->next = NULL; |
3649 | **bs_link_pointer = bs; | |
3650 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3651 | bs->breakpoint_at = bl->owner; |
3652 | bs->bp_location_at = bl; | |
3653 | incref_bp_location (bl); | |
c906108c SS |
3654 | /* If the condition is false, etc., don't do the commands. */ |
3655 | bs->commands = NULL; | |
9add0f1b | 3656 | bs->commands_left = NULL; |
c906108c SS |
3657 | bs->old_val = NULL; |
3658 | bs->print_it = print_it_normal; | |
3659 | return bs; | |
3660 | } | |
3661 | \f | |
d983da9c DJ |
3662 | /* The target has stopped with waitstatus WS. Check if any hardware |
3663 | watchpoints have triggered, according to the target. */ | |
3664 | ||
3665 | int | |
3666 | watchpoints_triggered (struct target_waitstatus *ws) | |
3667 | { | |
d92524f1 | 3668 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3669 | CORE_ADDR addr; |
3670 | struct breakpoint *b; | |
3671 | ||
3672 | if (!stopped_by_watchpoint) | |
3673 | { | |
3674 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3675 | as not triggered. */ | |
3676 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3677 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3678 | b->watchpoint_triggered = watch_triggered_no; |
3679 | ||
3680 | return 0; | |
3681 | } | |
3682 | ||
3683 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3684 | { | |
3685 | /* We were stopped by a watchpoint, but we don't know where. | |
3686 | Mark all watchpoints as unknown. */ | |
3687 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3688 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3689 | b->watchpoint_triggered = watch_triggered_unknown; |
3690 | ||
3691 | return stopped_by_watchpoint; | |
3692 | } | |
3693 | ||
3694 | /* The target could report the data address. Mark watchpoints | |
3695 | affected by this data address as triggered, and all others as not | |
3696 | triggered. */ | |
3697 | ||
3698 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3699 | if (is_hardware_watchpoint (b)) |
d983da9c | 3700 | { |
a5606eee | 3701 | struct bp_location *loc; |
d983da9c DJ |
3702 | |
3703 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee | 3704 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 TJB |
3705 | { |
3706 | if (is_masked_watchpoint (loc->owner)) | |
3707 | { | |
3708 | CORE_ADDR newaddr = addr & loc->owner->hw_wp_mask; | |
3709 | CORE_ADDR start = loc->address & loc->owner->hw_wp_mask; | |
3710 | ||
3711 | if (newaddr == start) | |
3712 | { | |
3713 | b->watchpoint_triggered = watch_triggered_yes; | |
3714 | break; | |
3715 | } | |
3716 | } | |
3717 | /* Exact match not required. Within range is sufficient. */ | |
3718 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3719 | addr, loc->address, | |
3720 | loc->length)) | |
3721 | { | |
3722 | b->watchpoint_triggered = watch_triggered_yes; | |
3723 | break; | |
3724 | } | |
3725 | } | |
d983da9c DJ |
3726 | } |
3727 | ||
3728 | return 1; | |
3729 | } | |
3730 | ||
c906108c SS |
3731 | /* Possible return values for watchpoint_check (this can't be an enum |
3732 | because of check_errors). */ | |
3733 | /* The watchpoint has been deleted. */ | |
3734 | #define WP_DELETED 1 | |
3735 | /* The value has changed. */ | |
3736 | #define WP_VALUE_CHANGED 2 | |
3737 | /* The value has not changed. */ | |
3738 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3739 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3740 | #define WP_IGNORE 4 | |
c906108c SS |
3741 | |
3742 | #define BP_TEMPFLAG 1 | |
3743 | #define BP_HARDWAREFLAG 2 | |
3744 | ||
4a64f543 MS |
3745 | /* Evaluate watchpoint condition expression and check if its value |
3746 | changed. | |
553e4c11 JB |
3747 | |
3748 | P should be a pointer to struct bpstat, but is defined as a void * | |
3749 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3750 | |
3751 | static int | |
4efb68b1 | 3752 | watchpoint_check (void *p) |
c906108c SS |
3753 | { |
3754 | bpstat bs = (bpstat) p; | |
3755 | struct breakpoint *b; | |
3756 | struct frame_info *fr; | |
3757 | int within_current_scope; | |
3758 | ||
f431efe5 | 3759 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3760 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3761 | b = bs->breakpoint_at; |
c906108c | 3762 | |
d0fb5eae JK |
3763 | gdb_assert (is_watchpoint (b)); |
3764 | ||
f6bc2008 PA |
3765 | /* If this is a local watchpoint, we only want to check if the |
3766 | watchpoint frame is in scope if the current thread is the thread | |
3767 | that was used to create the watchpoint. */ | |
3768 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3769 | return WP_IGNORE; |
f6bc2008 | 3770 | |
c906108c SS |
3771 | if (b->exp_valid_block == NULL) |
3772 | within_current_scope = 1; | |
3773 | else | |
3774 | { | |
edb3359d DJ |
3775 | struct frame_info *frame = get_current_frame (); |
3776 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3777 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3778 | ||
4a64f543 MS |
3779 | /* in_function_epilogue_p() returns a non-zero value if we're |
3780 | still in the function but the stack frame has already been | |
3781 | invalidated. Since we can't rely on the values of local | |
3782 | variables after the stack has been destroyed, we are treating | |
3783 | the watchpoint in that state as `not changed' without further | |
3784 | checking. Don't mark watchpoints as changed if the current | |
3785 | frame is in an epilogue - even if they are in some other | |
3786 | frame, our view of the stack is likely to be wrong and | |
3787 | frame_find_by_id could error out. */ | |
a0f49112 | 3788 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3789 | return WP_IGNORE; |
a0f49112 | 3790 | |
101dcfbe | 3791 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3792 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3793 | |
3794 | /* If we've gotten confused in the unwinder, we might have | |
3795 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3796 | if (within_current_scope) |
3797 | { | |
3798 | struct symbol *function; | |
3799 | ||
3800 | function = get_frame_function (fr); | |
3801 | if (function == NULL | |
3802 | || !contained_in (b->exp_valid_block, | |
3803 | SYMBOL_BLOCK_VALUE (function))) | |
3804 | within_current_scope = 0; | |
3805 | } | |
69fbadd5 | 3806 | |
edb3359d | 3807 | if (within_current_scope) |
c906108c SS |
3808 | /* If we end up stopping, the current frame will get selected |
3809 | in normal_stop. So this call to select_frame won't affect | |
3810 | the user. */ | |
0f7d239c | 3811 | select_frame (fr); |
c906108c | 3812 | } |
c5aa993b | 3813 | |
c906108c SS |
3814 | if (within_current_scope) |
3815 | { | |
4a64f543 MS |
3816 | /* We use value_{,free_to_}mark because it could be a *long* |
3817 | time before we return to the command level and call | |
3818 | free_all_values. We can't call free_all_values because we | |
3819 | might be in the middle of evaluating a function call. */ | |
c906108c | 3820 | |
0cf6dd15 | 3821 | int pc = 0; |
9c06b0b4 | 3822 | struct value *mark; |
fa4727a6 DJ |
3823 | struct value *new_val; |
3824 | ||
9c06b0b4 TJB |
3825 | if (is_masked_watchpoint (b)) |
3826 | /* Since we don't know the exact trigger address (from | |
3827 | stopped_data_address), just tell the user we've triggered | |
3828 | a mask watchpoint. */ | |
3829 | return WP_VALUE_CHANGED; | |
3830 | ||
3831 | mark = value_mark (); | |
0cf6dd15 | 3832 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3833 | |
4a64f543 MS |
3834 | /* We use value_equal_contents instead of value_equal because |
3835 | the latter coerces an array to a pointer, thus comparing just | |
3836 | the address of the array instead of its contents. This is | |
3837 | not what we want. */ | |
fa4727a6 | 3838 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3839 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3840 | { |
fa4727a6 DJ |
3841 | if (new_val != NULL) |
3842 | { | |
3843 | release_value (new_val); | |
3844 | value_free_to_mark (mark); | |
3845 | } | |
c906108c SS |
3846 | bs->old_val = b->val; |
3847 | b->val = new_val; | |
fa4727a6 | 3848 | b->val_valid = 1; |
c906108c SS |
3849 | return WP_VALUE_CHANGED; |
3850 | } | |
3851 | else | |
3852 | { | |
60e1c644 | 3853 | /* Nothing changed. */ |
c906108c | 3854 | value_free_to_mark (mark); |
c906108c SS |
3855 | return WP_VALUE_NOT_CHANGED; |
3856 | } | |
3857 | } | |
3858 | else | |
3859 | { | |
3860 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3861 | if we temporarily ignored the watchpoint, then when |
3862 | we reenter the block in which it is valid it contains | |
3863 | garbage (in the case of a function, it may have two | |
3864 | garbage values, one before and one after the prologue). | |
3865 | So we can't even detect the first assignment to it and | |
3866 | watch after that (since the garbage may or may not equal | |
3867 | the first value assigned). */ | |
4ce44c66 JM |
3868 | /* We print all the stop information in print_it_typical(), but |
3869 | in this case, by the time we call print_it_typical() this bp | |
4a64f543 MS |
3870 | will be deleted already. So we have no choice but print the |
3871 | information here. */ | |
9dc5e2a9 | 3872 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3873 | ui_out_field_string |
3874 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3875 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3876 | ui_out_field_int (uiout, "wpnum", b->number); |
3e43a32a MS |
3877 | ui_out_text (uiout, |
3878 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3879 | which its expression is valid.\n"); |
4ce44c66 | 3880 | |
d0fb5eae | 3881 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3882 | |
3883 | return WP_DELETED; | |
3884 | } | |
3885 | } | |
3886 | ||
18a18393 VP |
3887 | /* Return true if it looks like target has stopped due to hitting |
3888 | breakpoint location BL. This function does not check if we | |
3889 | should stop, only if BL explains the stop. */ | |
3890 | static int | |
6c95b8df PA |
3891 | bpstat_check_location (const struct bp_location *bl, |
3892 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3893 | { |
3894 | struct breakpoint *b = bl->owner; | |
3895 | ||
2bdf28a0 JK |
3896 | /* BL is from existing struct breakpoint. */ |
3897 | gdb_assert (b != NULL); | |
3898 | ||
f1310107 TJB |
3899 | if (b->ops && b->ops->breakpoint_hit) |
3900 | return b->ops->breakpoint_hit (bl, aspace, bp_addr); | |
3901 | ||
e8595ef6 SS |
3902 | /* By definition, the inferior does not report stops at |
3903 | tracepoints. */ | |
d77f58be | 3904 | if (is_tracepoint (b)) |
e8595ef6 SS |
3905 | return 0; |
3906 | ||
cc60f2e3 | 3907 | if (!is_watchpoint (b) |
18a18393 | 3908 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3909 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3910 | { |
6c95b8df PA |
3911 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3912 | aspace, bp_addr)) | |
18a18393 VP |
3913 | return 0; |
3914 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3915 | && section_is_overlay (bl->section) |
18a18393 VP |
3916 | && !section_is_mapped (bl->section)) |
3917 | return 0; | |
3918 | } | |
cc60f2e3 | 3919 | |
18a18393 VP |
3920 | /* Continuable hardware watchpoints are treated as non-existent if the |
3921 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3922 | some data address). Otherwise gdb won't stop on a break instruction | |
3923 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3924 | been defined. Also skip watchpoints which we know did not trigger | |
3925 | (did not match the data address). */ | |
cc60f2e3 PA |
3926 | |
3927 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3928 | && b->watchpoint_triggered == watch_triggered_no) |
3929 | return 0; | |
f1310107 | 3930 | |
18a18393 VP |
3931 | if (b->type == bp_hardware_breakpoint) |
3932 | { | |
3933 | if (bl->address != bp_addr) | |
3934 | return 0; | |
3935 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3936 | && section_is_overlay (bl->section) |
18a18393 VP |
3937 | && !section_is_mapped (bl->section)) |
3938 | return 0; | |
3939 | } | |
ce78b96d | 3940 | |
18a18393 VP |
3941 | return 1; |
3942 | } | |
3943 | ||
3944 | /* If BS refers to a watchpoint, determine if the watched values | |
3945 | has actually changed, and we should stop. If not, set BS->stop | |
3946 | to 0. */ | |
3947 | static void | |
3948 | bpstat_check_watchpoint (bpstat bs) | |
3949 | { | |
2bdf28a0 JK |
3950 | const struct bp_location *bl; |
3951 | struct breakpoint *b; | |
3952 | ||
3953 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3954 | bl = bs->bp_location_at; |
2bdf28a0 | 3955 | gdb_assert (bl != NULL); |
f431efe5 | 3956 | b = bs->breakpoint_at; |
2bdf28a0 | 3957 | gdb_assert (b != NULL); |
18a18393 | 3958 | |
cc60f2e3 | 3959 | if (is_watchpoint (b)) |
18a18393 | 3960 | { |
18a18393 VP |
3961 | int must_check_value = 0; |
3962 | ||
3963 | if (b->type == bp_watchpoint) | |
3964 | /* For a software watchpoint, we must always check the | |
3965 | watched value. */ | |
3966 | must_check_value = 1; | |
3967 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3968 | /* We have a hardware watchpoint (read, write, or access) | |
3969 | and the target earlier reported an address watched by | |
3970 | this watchpoint. */ | |
3971 | must_check_value = 1; | |
3972 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3973 | && b->type == bp_hardware_watchpoint) | |
3974 | /* We were stopped by a hardware watchpoint, but the target could | |
3975 | not report the data address. We must check the watchpoint's | |
3976 | value. Access and read watchpoints are out of luck; without | |
3977 | a data address, we can't figure it out. */ | |
3978 | must_check_value = 1; | |
3979 | ||
3980 | if (must_check_value) | |
3981 | { | |
3e43a32a MS |
3982 | char *message |
3983 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3984 | b->number); | |
18a18393 VP |
3985 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3986 | int e = catch_errors (watchpoint_check, bs, message, | |
3987 | RETURN_MASK_ALL); | |
3988 | do_cleanups (cleanups); | |
3989 | switch (e) | |
3990 | { | |
3991 | case WP_DELETED: | |
3992 | /* We've already printed what needs to be printed. */ | |
3993 | bs->print_it = print_it_done; | |
3994 | /* Stop. */ | |
3995 | break; | |
60e1c644 PA |
3996 | case WP_IGNORE: |
3997 | bs->print_it = print_it_noop; | |
3998 | bs->stop = 0; | |
3999 | break; | |
18a18393 VP |
4000 | case WP_VALUE_CHANGED: |
4001 | if (b->type == bp_read_watchpoint) | |
4002 | { | |
85d721b8 PA |
4003 | /* There are two cases to consider here: |
4004 | ||
4a64f543 | 4005 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
4006 | In that case, trust the target, and always report |
4007 | the watchpoint hit to the user. Even though | |
4008 | reads don't cause value changes, the value may | |
4009 | have changed since the last time it was read, and | |
4010 | since we're not trapping writes, we will not see | |
4011 | those, and as such we should ignore our notion of | |
4012 | old value. | |
4013 | ||
4a64f543 | 4014 | 2. We're watching the triggered memory for both |
85d721b8 PA |
4015 | reads and writes. There are two ways this may |
4016 | happen: | |
4017 | ||
4a64f543 | 4018 | 2.1. This is a target that can't break on data |
85d721b8 PA |
4019 | reads only, but can break on accesses (reads or |
4020 | writes), such as e.g., x86. We detect this case | |
4021 | at the time we try to insert read watchpoints. | |
4022 | ||
4a64f543 | 4023 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
4024 | watchpoints, but, the user set an access or write |
4025 | watchpoint watching the same memory as this read | |
4026 | watchpoint. | |
4027 | ||
4028 | If we're watching memory writes as well as reads, | |
4029 | ignore watchpoint hits when we find that the | |
4030 | value hasn't changed, as reads don't cause | |
4031 | changes. This still gives false positives when | |
4032 | the program writes the same value to memory as | |
4033 | what there was already in memory (we will confuse | |
4034 | it for a read), but it's much better than | |
4035 | nothing. */ | |
4036 | ||
4037 | int other_write_watchpoint = 0; | |
4038 | ||
4039 | if (bl->watchpoint_type == hw_read) | |
4040 | { | |
4041 | struct breakpoint *other_b; | |
4042 | ||
4043 | ALL_BREAKPOINTS (other_b) | |
4044 | if ((other_b->type == bp_hardware_watchpoint | |
4045 | || other_b->type == bp_access_watchpoint) | |
4046 | && (other_b->watchpoint_triggered | |
4047 | == watch_triggered_yes)) | |
4048 | { | |
4049 | other_write_watchpoint = 1; | |
4050 | break; | |
4051 | } | |
4052 | } | |
4053 | ||
4054 | if (other_write_watchpoint | |
4055 | || bl->watchpoint_type == hw_access) | |
4056 | { | |
4057 | /* We're watching the same memory for writes, | |
4058 | and the value changed since the last time we | |
4059 | updated it, so this trap must be for a write. | |
4060 | Ignore it. */ | |
4061 | bs->print_it = print_it_noop; | |
4062 | bs->stop = 0; | |
4063 | } | |
18a18393 VP |
4064 | } |
4065 | break; | |
4066 | case WP_VALUE_NOT_CHANGED: | |
4067 | if (b->type == bp_hardware_watchpoint | |
4068 | || b->type == bp_watchpoint) | |
4069 | { | |
4070 | /* Don't stop: write watchpoints shouldn't fire if | |
4071 | the value hasn't changed. */ | |
4072 | bs->print_it = print_it_noop; | |
4073 | bs->stop = 0; | |
4074 | } | |
4075 | /* Stop. */ | |
4076 | break; | |
4077 | default: | |
4078 | /* Can't happen. */ | |
4079 | case 0: | |
4080 | /* Error from catch_errors. */ | |
4081 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
d0fb5eae | 4082 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
4083 | /* We've already printed what needs to be printed. */ |
4084 | bs->print_it = print_it_done; | |
4085 | break; | |
4086 | } | |
4087 | } | |
4088 | else /* must_check_value == 0 */ | |
4089 | { | |
4090 | /* This is a case where some watchpoint(s) triggered, but | |
4091 | not at the address of this watchpoint, or else no | |
4092 | watchpoint triggered after all. So don't print | |
4093 | anything for this watchpoint. */ | |
4094 | bs->print_it = print_it_noop; | |
4095 | bs->stop = 0; | |
4096 | } | |
4097 | } | |
4098 | } | |
4099 | ||
4100 | ||
4101 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4102 | of breakpoint referred to by BS. If we should not stop for this | |
4103 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4104 | |
18a18393 VP |
4105 | static void |
4106 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4107 | { | |
4108 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4109 | const struct bp_location *bl; |
4110 | struct breakpoint *b; | |
4111 | ||
4112 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4113 | bl = bs->bp_location_at; |
2bdf28a0 | 4114 | gdb_assert (bl != NULL); |
f431efe5 | 4115 | b = bs->breakpoint_at; |
2bdf28a0 | 4116 | gdb_assert (b != NULL); |
18a18393 VP |
4117 | |
4118 | if (frame_id_p (b->frame_id) | |
edb3359d | 4119 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4120 | bs->stop = 0; |
4121 | else if (bs->stop) | |
4122 | { | |
4123 | int value_is_zero = 0; | |
60e1c644 PA |
4124 | struct expression *cond; |
4125 | ||
7371cf6d PM |
4126 | /* Evaluate Python breakpoints that have a "stop" |
4127 | method implemented. */ | |
4128 | if (b->py_bp_object) | |
4129 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4130 | ||
60e1c644 PA |
4131 | if (is_watchpoint (b)) |
4132 | cond = b->cond_exp; | |
4133 | else | |
4134 | cond = bl->cond; | |
4135 | ||
f431efe5 | 4136 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4137 | { |
60e1c644 PA |
4138 | int within_current_scope = 1; |
4139 | ||
c5bc3a77 DJ |
4140 | /* We use value_mark and value_free_to_mark because it could |
4141 | be a long time before we return to the command level and | |
4142 | call free_all_values. We can't call free_all_values | |
4143 | because we might be in the middle of evaluating a | |
4144 | function call. */ | |
4145 | struct value *mark = value_mark (); | |
4146 | ||
edb3359d DJ |
4147 | /* Need to select the frame, with all that implies so that |
4148 | the conditions will have the right context. Because we | |
4149 | use the frame, we will not see an inlined function's | |
4150 | variables when we arrive at a breakpoint at the start | |
4151 | of the inlined function; the current frame will be the | |
4152 | call site. */ | |
60e1c644 PA |
4153 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
4154 | select_frame (get_current_frame ()); | |
4155 | else | |
4156 | { | |
4157 | struct frame_info *frame; | |
4158 | ||
4159 | /* For local watchpoint expressions, which particular | |
4160 | instance of a local is being watched matters, so we | |
4161 | keep track of the frame to evaluate the expression | |
4162 | in. To evaluate the condition however, it doesn't | |
4163 | really matter which instantiation of the function | |
4164 | where the condition makes sense triggers the | |
4165 | watchpoint. This allows an expression like "watch | |
4166 | global if q > 10" set in `func', catch writes to | |
4167 | global on all threads that call `func', or catch | |
4168 | writes on all recursive calls of `func' by a single | |
4169 | thread. We simply always evaluate the condition in | |
4170 | the innermost frame that's executing where it makes | |
4171 | sense to evaluate the condition. It seems | |
4172 | intuitive. */ | |
4173 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4174 | if (frame != NULL) | |
4175 | select_frame (frame); | |
4176 | else | |
4177 | within_current_scope = 0; | |
4178 | } | |
4179 | if (within_current_scope) | |
4180 | value_is_zero | |
4181 | = catch_errors (breakpoint_cond_eval, cond, | |
4182 | "Error in testing breakpoint condition:\n", | |
4183 | RETURN_MASK_ALL); | |
4184 | else | |
4185 | { | |
4186 | warning (_("Watchpoint condition cannot be tested " | |
4187 | "in the current scope")); | |
4188 | /* If we failed to set the right context for this | |
4189 | watchpoint, unconditionally report it. */ | |
4190 | value_is_zero = 0; | |
4191 | } | |
4a64f543 | 4192 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4193 | value_free_to_mark (mark); |
18a18393 | 4194 | } |
60e1c644 PA |
4195 | |
4196 | if (cond && value_is_zero) | |
18a18393 VP |
4197 | { |
4198 | bs->stop = 0; | |
4199 | } | |
4200 | else if (b->thread != -1 && b->thread != thread_id) | |
4201 | { | |
4202 | bs->stop = 0; | |
4203 | } | |
4204 | else if (b->ignore_count > 0) | |
4205 | { | |
4206 | b->ignore_count--; | |
4207 | annotate_ignore_count_change (); | |
4208 | bs->stop = 0; | |
4a64f543 | 4209 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4210 | ++(b->hit_count); |
8d3788bd | 4211 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4212 | } |
4213 | } | |
4214 | } | |
4215 | ||
4216 | ||
9709f61c | 4217 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4218 | BP_ADDR in thread PTID. |
c906108c | 4219 | |
d983da9c | 4220 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4221 | don't understand this stop. Result is a chain of bpstat's such |
4222 | that: | |
c906108c | 4223 | |
c5aa993b | 4224 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4225 | |
c5aa993b | 4226 | if we understand why we stopped, the result is not null. |
c906108c | 4227 | |
c5aa993b JM |
4228 | Each element of the chain refers to a particular breakpoint or |
4229 | watchpoint at which we have stopped. (We may have stopped for | |
4230 | several reasons concurrently.) | |
c906108c | 4231 | |
c5aa993b JM |
4232 | Each element of the chain has valid next, breakpoint_at, |
4233 | commands, FIXME??? fields. */ | |
c906108c SS |
4234 | |
4235 | bpstat | |
6c95b8df PA |
4236 | bpstat_stop_status (struct address_space *aspace, |
4237 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4238 | { |
0d381245 | 4239 | struct breakpoint *b = NULL; |
afe38095 | 4240 | struct bp_location *bl; |
20874c92 | 4241 | struct bp_location *loc; |
5760d0ab JK |
4242 | /* First item of allocated bpstat's. */ |
4243 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4244 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4245 | bpstat bs; |
20874c92 | 4246 | int ix; |
429374b8 | 4247 | int need_remove_insert; |
f431efe5 | 4248 | int removed_any; |
c906108c | 4249 | |
f431efe5 PA |
4250 | /* First, build the bpstat chain with locations that explain a |
4251 | target stop, while being careful to not set the target running, | |
4252 | as that may invalidate locations (in particular watchpoint | |
4253 | locations are recreated). Resuming will happen here with | |
4254 | breakpoint conditions or watchpoint expressions that include | |
4255 | inferior function calls. */ | |
c5aa993b | 4256 | |
429374b8 JK |
4257 | ALL_BREAKPOINTS (b) |
4258 | { | |
4259 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4260 | continue; | |
a5606eee | 4261 | |
429374b8 JK |
4262 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4263 | { | |
4a64f543 MS |
4264 | /* For hardware watchpoints, we look only at the first |
4265 | location. The watchpoint_check function will work on the | |
4266 | entire expression, not the individual locations. For | |
4267 | read watchpoints, the watchpoints_triggered function has | |
4268 | checked all locations already. */ | |
429374b8 JK |
4269 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4270 | break; | |
18a18393 | 4271 | |
429374b8 JK |
4272 | if (bl->shlib_disabled) |
4273 | continue; | |
c5aa993b | 4274 | |
429374b8 JK |
4275 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4276 | continue; | |
c5aa993b | 4277 | |
4a64f543 MS |
4278 | /* Come here if it's a watchpoint, or if the break address |
4279 | matches. */ | |
c5aa993b | 4280 | |
4a64f543 MS |
4281 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4282 | explain stop. */ | |
c5aa993b | 4283 | |
f431efe5 PA |
4284 | /* Assume we stop. Should we find a watchpoint that is not |
4285 | actually triggered, or if the condition of the breakpoint | |
4286 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4287 | bs->stop = 1; |
4288 | bs->print = 1; | |
d983da9c | 4289 | |
f431efe5 PA |
4290 | /* If this is a scope breakpoint, mark the associated |
4291 | watchpoint as triggered so that we will handle the | |
4292 | out-of-scope event. We'll get to the watchpoint next | |
4293 | iteration. */ | |
d0fb5eae | 4294 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
f431efe5 PA |
4295 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; |
4296 | } | |
4297 | } | |
4298 | ||
4299 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4300 | { | |
f1310107 | 4301 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4302 | { |
5760d0ab | 4303 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4304 | /* For hits of moribund locations, we should just proceed. */ |
4305 | bs->stop = 0; | |
4306 | bs->print = 0; | |
4307 | bs->print_it = print_it_noop; | |
4308 | } | |
4309 | } | |
4310 | ||
f431efe5 PA |
4311 | /* Now go through the locations that caused the target to stop, and |
4312 | check whether we're interested in reporting this stop to higher | |
4313 | layers, or whether we should resume the target transparently. */ | |
4314 | ||
4315 | removed_any = 0; | |
4316 | ||
5760d0ab | 4317 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4318 | { |
4319 | if (!bs->stop) | |
4320 | continue; | |
4321 | ||
4322 | bpstat_check_watchpoint (bs); | |
4323 | if (!bs->stop) | |
4324 | continue; | |
4325 | ||
4326 | b = bs->breakpoint_at; | |
18a18393 | 4327 | |
429374b8 | 4328 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d | 4329 | || b->type == bp_longjmp_master |
186c406b TT |
4330 | || b->type == bp_std_terminate_master |
4331 | || b->type == bp_exception_master) | |
429374b8 JK |
4332 | /* We do not stop for these. */ |
4333 | bs->stop = 0; | |
4334 | else | |
4335 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4336 | |
429374b8 JK |
4337 | if (bs->stop) |
4338 | { | |
4339 | ++(b->hit_count); | |
8d3788bd | 4340 | observer_notify_breakpoint_modified (b); |
c906108c | 4341 | |
4a64f543 | 4342 | /* We will stop here. */ |
429374b8 JK |
4343 | if (b->disposition == disp_disable) |
4344 | { | |
4345 | if (b->enable_state != bp_permanent) | |
4346 | b->enable_state = bp_disabled; | |
f431efe5 | 4347 | removed_any = 1; |
429374b8 JK |
4348 | } |
4349 | if (b->silent) | |
4350 | bs->print = 0; | |
4351 | bs->commands = b->commands; | |
9add0f1b TT |
4352 | incref_counted_command_line (bs->commands); |
4353 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4354 | if (bs->commands_left | |
4355 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4356 | || (xdb_commands | |
4357 | && strcmp ("Q", | |
4358 | bs->commands_left->line) == 0))) | |
429374b8 | 4359 | { |
9add0f1b | 4360 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4361 | bs->print = 0; |
4362 | } | |
429374b8 JK |
4363 | } |
4364 | ||
4365 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4366 | if (bs->stop == 0 || bs->print == 0) | |
4367 | bs->print_it = print_it_noop; | |
429374b8 | 4368 | } |
876fa593 | 4369 | |
d983da9c DJ |
4370 | /* If we aren't stopping, the value of some hardware watchpoint may |
4371 | not have changed, but the intermediate memory locations we are | |
4372 | watching may have. Don't bother if we're stopping; this will get | |
4373 | done later. */ | |
d832cb68 | 4374 | need_remove_insert = 0; |
5760d0ab JK |
4375 | if (! bpstat_causes_stop (bs_head)) |
4376 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4377 | if (!bs->stop |
f431efe5 PA |
4378 | && bs->breakpoint_at |
4379 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4380 | { |
4a64f543 | 4381 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4382 | need_remove_insert = 1; |
d983da9c DJ |
4383 | } |
4384 | ||
d832cb68 | 4385 | if (need_remove_insert) |
2d134ed3 | 4386 | update_global_location_list (1); |
f431efe5 PA |
4387 | else if (removed_any) |
4388 | update_global_location_list (0); | |
d832cb68 | 4389 | |
5760d0ab | 4390 | return bs_head; |
c906108c | 4391 | } |
628fe4e4 JK |
4392 | |
4393 | static void | |
4394 | handle_jit_event (void) | |
4395 | { | |
4396 | struct frame_info *frame; | |
4397 | struct gdbarch *gdbarch; | |
4398 | ||
4399 | /* Switch terminal for any messages produced by | |
4400 | breakpoint_re_set. */ | |
4401 | target_terminal_ours_for_output (); | |
4402 | ||
4403 | frame = get_current_frame (); | |
4404 | gdbarch = get_frame_arch (frame); | |
4405 | ||
4406 | jit_event_handler (gdbarch); | |
4407 | ||
4408 | target_terminal_inferior (); | |
4409 | } | |
4410 | ||
4411 | /* Prepare WHAT final decision for infrun. */ | |
4412 | ||
4413 | /* Decide what infrun needs to do with this bpstat. */ | |
4414 | ||
c906108c | 4415 | struct bpstat_what |
0e30163f | 4416 | bpstat_what (bpstat bs_head) |
c906108c | 4417 | { |
c906108c | 4418 | struct bpstat_what retval; |
628fe4e4 JK |
4419 | /* We need to defer calling `solib_add', as adding new symbols |
4420 | resets breakpoints, which in turn deletes breakpoint locations, | |
4421 | and hence may clear unprocessed entries in the BS chain. */ | |
4422 | int shlib_event = 0; | |
4423 | int jit_event = 0; | |
0e30163f | 4424 | bpstat bs; |
c906108c | 4425 | |
628fe4e4 | 4426 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4427 | retval.call_dummy = STOP_NONE; |
186c406b | 4428 | retval.is_longjmp = 0; |
628fe4e4 | 4429 | |
0e30163f | 4430 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4431 | { |
628fe4e4 JK |
4432 | /* Extract this BS's action. After processing each BS, we check |
4433 | if its action overrides all we've seem so far. */ | |
4434 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4435 | enum bptype bptype; | |
4436 | ||
c906108c | 4437 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4438 | { |
4439 | /* I suspect this can happen if it was a momentary | |
4440 | breakpoint which has since been deleted. */ | |
4441 | bptype = bp_none; | |
4442 | } | |
f431efe5 | 4443 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4444 | bptype = bp_none; |
20874c92 | 4445 | else |
f431efe5 | 4446 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4447 | |
4448 | switch (bptype) | |
c906108c SS |
4449 | { |
4450 | case bp_none: | |
628fe4e4 | 4451 | break; |
c906108c SS |
4452 | case bp_breakpoint: |
4453 | case bp_hardware_breakpoint: | |
4454 | case bp_until: | |
4455 | case bp_finish: | |
4456 | if (bs->stop) | |
4457 | { | |
4458 | if (bs->print) | |
628fe4e4 | 4459 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4460 | else |
628fe4e4 | 4461 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4462 | } |
4463 | else | |
628fe4e4 | 4464 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4465 | break; |
4466 | case bp_watchpoint: | |
4467 | case bp_hardware_watchpoint: | |
4468 | case bp_read_watchpoint: | |
4469 | case bp_access_watchpoint: | |
4470 | if (bs->stop) | |
4471 | { | |
4472 | if (bs->print) | |
628fe4e4 | 4473 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4474 | else |
628fe4e4 | 4475 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4476 | } |
4477 | else | |
628fe4e4 JK |
4478 | { |
4479 | /* There was a watchpoint, but we're not stopping. | |
4480 | This requires no further action. */ | |
4481 | } | |
c906108c SS |
4482 | break; |
4483 | case bp_longjmp: | |
186c406b | 4484 | case bp_exception: |
628fe4e4 | 4485 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4486 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4487 | break; |
4488 | case bp_longjmp_resume: | |
186c406b | 4489 | case bp_exception_resume: |
628fe4e4 | 4490 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4491 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4492 | break; |
4493 | case bp_step_resume: | |
4494 | if (bs->stop) | |
628fe4e4 JK |
4495 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4496 | else | |
c906108c | 4497 | { |
628fe4e4 JK |
4498 | /* It is for the wrong frame. */ |
4499 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4500 | } |
c906108c | 4501 | break; |
c906108c | 4502 | case bp_watchpoint_scope: |
c4093a6a | 4503 | case bp_thread_event: |
1900040c | 4504 | case bp_overlay_event: |
0fd8e87f | 4505 | case bp_longjmp_master: |
aa7d318d | 4506 | case bp_std_terminate_master: |
186c406b | 4507 | case bp_exception_master: |
628fe4e4 | 4508 | this_action = BPSTAT_WHAT_SINGLE; |
c4093a6a | 4509 | break; |
ce78b96d | 4510 | case bp_catchpoint: |
c5aa993b JM |
4511 | if (bs->stop) |
4512 | { | |
4513 | if (bs->print) | |
628fe4e4 | 4514 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c5aa993b | 4515 | else |
628fe4e4 | 4516 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c5aa993b JM |
4517 | } |
4518 | else | |
628fe4e4 JK |
4519 | { |
4520 | /* There was a catchpoint, but we're not stopping. | |
4521 | This requires no further action. */ | |
4522 | } | |
4523 | break; | |
4524 | case bp_shlib_event: | |
4525 | shlib_event = 1; | |
4526 | ||
4527 | /* If requested, stop when the dynamic linker notifies GDB | |
4528 | of events. This allows the user to get control and place | |
4529 | breakpoints in initializer routines for dynamically | |
4530 | loaded objects (among other things). */ | |
4531 | if (stop_on_solib_events) | |
4532 | this_action = BPSTAT_WHAT_STOP_NOISY; | |
4533 | else | |
4534 | this_action = BPSTAT_WHAT_SINGLE; | |
4535 | break; | |
4536 | case bp_jit_event: | |
4537 | jit_event = 1; | |
4538 | this_action = BPSTAT_WHAT_SINGLE; | |
c5aa993b | 4539 | break; |
c906108c | 4540 | case bp_call_dummy: |
53a5351d JM |
4541 | /* Make sure the action is stop (silent or noisy), |
4542 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4543 | retval.call_dummy = STOP_STACK_DUMMY; |
628fe4e4 | 4544 | this_action = BPSTAT_WHAT_STOP_SILENT; |
aa7d318d TT |
4545 | break; |
4546 | case bp_std_terminate: | |
4547 | /* Make sure the action is stop (silent or noisy), | |
4548 | so infrun.c pops the dummy frame. */ | |
aa7d318d | 4549 | retval.call_dummy = STOP_STD_TERMINATE; |
628fe4e4 | 4550 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c | 4551 | break; |
1042e4c0 | 4552 | case bp_tracepoint: |
7a697b8d | 4553 | case bp_fast_tracepoint: |
0fb4aa4b | 4554 | case bp_static_tracepoint: |
1042e4c0 SS |
4555 | /* Tracepoint hits should not be reported back to GDB, and |
4556 | if one got through somehow, it should have been filtered | |
4557 | out already. */ | |
4558 | internal_error (__FILE__, __LINE__, | |
7a697b8d | 4559 | _("bpstat_what: tracepoint encountered")); |
0e30163f JK |
4560 | break; |
4561 | case bp_gnu_ifunc_resolver: | |
4562 | /* Step over it (and insert bp_gnu_ifunc_resolver_return). */ | |
4563 | this_action = BPSTAT_WHAT_SINGLE; | |
4564 | break; | |
4565 | case bp_gnu_ifunc_resolver_return: | |
4566 | /* The breakpoint will be removed, execution will restart from the | |
4567 | PC of the former breakpoint. */ | |
4568 | this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4569 | break; | |
628fe4e4 JK |
4570 | default: |
4571 | internal_error (__FILE__, __LINE__, | |
4572 | _("bpstat_what: unhandled bptype %d"), (int) bptype); | |
c906108c | 4573 | } |
628fe4e4 JK |
4574 | |
4575 | retval.main_action = max (retval.main_action, this_action); | |
c906108c | 4576 | } |
628fe4e4 | 4577 | |
0e30163f JK |
4578 | /* These operations may affect the bs->breakpoint_at state so they are |
4579 | delayed after MAIN_ACTION is decided above. */ | |
4580 | ||
628fe4e4 JK |
4581 | if (shlib_event) |
4582 | { | |
4583 | if (debug_infrun) | |
4584 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_shlib_event\n"); | |
4585 | ||
4586 | /* Check for any newly added shared libraries if we're supposed | |
4587 | to be adding them automatically. */ | |
4588 | ||
4589 | /* Switch terminal for any messages produced by | |
4590 | breakpoint_re_set. */ | |
4591 | target_terminal_ours_for_output (); | |
4592 | ||
4593 | #ifdef SOLIB_ADD | |
4594 | SOLIB_ADD (NULL, 0, ¤t_target, auto_solib_add); | |
4595 | #else | |
4596 | solib_add (NULL, 0, ¤t_target, auto_solib_add); | |
4597 | #endif | |
4598 | ||
4599 | target_terminal_inferior (); | |
4600 | } | |
4601 | ||
4602 | if (jit_event) | |
4603 | { | |
4604 | if (debug_infrun) | |
4605 | fprintf_unfiltered (gdb_stdlog, "bpstat_what: bp_jit_event\n"); | |
4606 | ||
4607 | handle_jit_event (); | |
4608 | } | |
4609 | ||
0e30163f JK |
4610 | for (bs = bs_head; bs != NULL; bs = bs->next) |
4611 | { | |
4612 | struct breakpoint *b = bs->breakpoint_at; | |
4613 | ||
4614 | if (b == NULL) | |
4615 | continue; | |
4616 | switch (b->type) | |
4617 | { | |
4618 | case bp_gnu_ifunc_resolver: | |
4619 | gnu_ifunc_resolver_stop (b); | |
4620 | break; | |
4621 | case bp_gnu_ifunc_resolver_return: | |
4622 | gnu_ifunc_resolver_return_stop (b); | |
4623 | break; | |
4624 | } | |
4625 | } | |
4626 | ||
c906108c SS |
4627 | return retval; |
4628 | } | |
4629 | ||
4630 | /* Nonzero if we should step constantly (e.g. watchpoints on machines | |
4631 | without hardware support). This isn't related to a specific bpstat, | |
4632 | just to things like whether watchpoints are set. */ | |
4633 | ||
c5aa993b | 4634 | int |
fba45db2 | 4635 | bpstat_should_step (void) |
c906108c SS |
4636 | { |
4637 | struct breakpoint *b; | |
cc59ec59 | 4638 | |
c906108c | 4639 | ALL_BREAKPOINTS (b) |
717a8278 | 4640 | if (breakpoint_enabled (b) && b->type == bp_watchpoint && b->loc != NULL) |
3172dc30 | 4641 | return 1; |
c906108c SS |
4642 | return 0; |
4643 | } | |
4644 | ||
67822962 PA |
4645 | int |
4646 | bpstat_causes_stop (bpstat bs) | |
4647 | { | |
4648 | for (; bs != NULL; bs = bs->next) | |
4649 | if (bs->stop) | |
4650 | return 1; | |
4651 | ||
4652 | return 0; | |
4653 | } | |
4654 | ||
c906108c | 4655 | \f |
c5aa993b | 4656 | |
170b53b2 UW |
4657 | /* Compute a string of spaces suitable to indent the next line |
4658 | so it starts at the position corresponding to the table column | |
4659 | named COL_NAME in the currently active table of UIOUT. */ | |
4660 | ||
4661 | static char * | |
4662 | wrap_indent_at_field (struct ui_out *uiout, const char *col_name) | |
4663 | { | |
4664 | static char wrap_indent[80]; | |
4665 | int i, total_width, width, align; | |
4666 | char *text; | |
4667 | ||
4668 | total_width = 0; | |
4669 | for (i = 1; ui_out_query_field (uiout, i, &width, &align, &text); i++) | |
4670 | { | |
4671 | if (strcmp (text, col_name) == 0) | |
4672 | { | |
4673 | gdb_assert (total_width < sizeof wrap_indent); | |
4674 | memset (wrap_indent, ' ', total_width); | |
4675 | wrap_indent[total_width] = 0; | |
4676 | ||
4677 | return wrap_indent; | |
4678 | } | |
4679 | ||
4680 | total_width += width + 1; | |
4681 | } | |
4682 | ||
4683 | return NULL; | |
4684 | } | |
4685 | ||
859825b8 JK |
4686 | /* Print the LOC location out of the list of B->LOC locations. */ |
4687 | ||
170b53b2 UW |
4688 | static void |
4689 | print_breakpoint_location (struct breakpoint *b, | |
4690 | struct bp_location *loc) | |
0d381245 | 4691 | { |
6c95b8df PA |
4692 | struct cleanup *old_chain = save_current_program_space (); |
4693 | ||
859825b8 JK |
4694 | if (loc != NULL && loc->shlib_disabled) |
4695 | loc = NULL; | |
4696 | ||
6c95b8df PA |
4697 | if (loc != NULL) |
4698 | set_current_program_space (loc->pspace); | |
4699 | ||
56435ebe TT |
4700 | if (b->display_canonical) |
4701 | ui_out_field_string (uiout, "what", b->addr_string); | |
4702 | else if (b->source_file && loc) | |
0d381245 VP |
4703 | { |
4704 | struct symbol *sym | |
4705 | = find_pc_sect_function (loc->address, loc->section); | |
4706 | if (sym) | |
4707 | { | |
4708 | ui_out_text (uiout, "in "); | |
4709 | ui_out_field_string (uiout, "func", | |
4710 | SYMBOL_PRINT_NAME (sym)); | |
170b53b2 UW |
4711 | ui_out_text (uiout, " "); |
4712 | ui_out_wrap_hint (uiout, wrap_indent_at_field (uiout, "what")); | |
4713 | ui_out_text (uiout, "at "); | |
0d381245 VP |
4714 | } |
4715 | ui_out_field_string (uiout, "file", b->source_file); | |
4716 | ui_out_text (uiout, ":"); | |
4717 | ||
4718 | if (ui_out_is_mi_like_p (uiout)) | |
4719 | { | |
4720 | struct symtab_and_line sal = find_pc_line (loc->address, 0); | |
4721 | char *fullname = symtab_to_fullname (sal.symtab); | |
4722 | ||
4723 | if (fullname) | |
4724 | ui_out_field_string (uiout, "fullname", fullname); | |
4725 | } | |
4726 | ||
4727 | ui_out_field_int (uiout, "line", b->line_number); | |
4728 | } | |
859825b8 | 4729 | else if (loc) |
0d381245 | 4730 | { |
170b53b2 UW |
4731 | struct ui_stream *stb = ui_out_stream_new (uiout); |
4732 | struct cleanup *stb_chain = make_cleanup_ui_out_stream_delete (stb); | |
4733 | ||
22e722e1 DJ |
4734 | print_address_symbolic (loc->gdbarch, loc->address, stb->stream, |
4735 | demangle, ""); | |
0d381245 | 4736 | ui_out_field_stream (uiout, "at", stb); |
170b53b2 UW |
4737 | |
4738 | do_cleanups (stb_chain); | |
0d381245 | 4739 | } |
859825b8 JK |
4740 | else |
4741 | ui_out_field_string (uiout, "pending", b->addr_string); | |
6c95b8df PA |
4742 | |
4743 | do_cleanups (old_chain); | |
0d381245 VP |
4744 | } |
4745 | ||
269b11a2 PA |
4746 | static const char * |
4747 | bptype_string (enum bptype type) | |
c906108c | 4748 | { |
c4093a6a JM |
4749 | struct ep_type_description |
4750 | { | |
4751 | enum bptype type; | |
4752 | char *description; | |
4753 | }; | |
4754 | static struct ep_type_description bptypes[] = | |
c906108c | 4755 | { |
c5aa993b JM |
4756 | {bp_none, "?deleted?"}, |
4757 | {bp_breakpoint, "breakpoint"}, | |
c906108c | 4758 | {bp_hardware_breakpoint, "hw breakpoint"}, |
c5aa993b JM |
4759 | {bp_until, "until"}, |
4760 | {bp_finish, "finish"}, | |
4761 | {bp_watchpoint, "watchpoint"}, | |
c906108c | 4762 | {bp_hardware_watchpoint, "hw watchpoint"}, |
c5aa993b JM |
4763 | {bp_read_watchpoint, "read watchpoint"}, |
4764 | {bp_access_watchpoint, "acc watchpoint"}, | |
4765 | {bp_longjmp, "longjmp"}, | |
4766 | {bp_longjmp_resume, "longjmp resume"}, | |
186c406b TT |
4767 | {bp_exception, "exception"}, |
4768 | {bp_exception_resume, "exception resume"}, | |
c5aa993b | 4769 | {bp_step_resume, "step resume"}, |
c5aa993b JM |
4770 | {bp_watchpoint_scope, "watchpoint scope"}, |
4771 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4772 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4773 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4774 | {bp_thread_event, "thread events"}, |
1900040c | 4775 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4776 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4777 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4778 | {bp_exception_master, "exception master"}, |
ce78b96d | 4779 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4780 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4781 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4782 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4783 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4784 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4785 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4786 | }; |
269b11a2 PA |
4787 | |
4788 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4789 | || ((int) type != bptypes[(int) type].type)) | |
4790 | internal_error (__FILE__, __LINE__, | |
4791 | _("bptypes table does not describe type #%d."), | |
4792 | (int) type); | |
4793 | ||
4794 | return bptypes[(int) type].description; | |
4795 | } | |
4796 | ||
4797 | /* Print B to gdb_stdout. */ | |
4798 | ||
4799 | static void | |
4800 | print_one_breakpoint_location (struct breakpoint *b, | |
4801 | struct bp_location *loc, | |
4802 | int loc_number, | |
4803 | struct bp_location **last_loc, | |
269b11a2 PA |
4804 | int allflag) |
4805 | { | |
4806 | struct command_line *l; | |
c2c6d25f | 4807 | static char bpenables[] = "nynny"; |
c906108c | 4808 | |
0d381245 VP |
4809 | int header_of_multiple = 0; |
4810 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4811 | struct value_print_options opts; |
4812 | ||
4813 | get_user_print_options (&opts); | |
0d381245 VP |
4814 | |
4815 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4816 | /* See comment in print_one_breakpoint concerning treatment of |
4817 | breakpoints with single disabled location. */ | |
0d381245 VP |
4818 | if (loc == NULL |
4819 | && (b->loc != NULL | |
4820 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4821 | header_of_multiple = 1; | |
4822 | if (loc == NULL) | |
4823 | loc = b->loc; | |
4824 | ||
c4093a6a JM |
4825 | annotate_record (); |
4826 | ||
4827 | /* 1 */ | |
4828 | annotate_field (0); | |
0d381245 VP |
4829 | if (part_of_multiple) |
4830 | { | |
4831 | char *formatted; | |
0c6773c1 | 4832 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4833 | ui_out_field_string (uiout, "number", formatted); |
4834 | xfree (formatted); | |
4835 | } | |
4836 | else | |
4837 | { | |
4838 | ui_out_field_int (uiout, "number", b->number); | |
4839 | } | |
c4093a6a JM |
4840 | |
4841 | /* 2 */ | |
4842 | annotate_field (1); | |
0d381245 VP |
4843 | if (part_of_multiple) |
4844 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4845 | else |
4846 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4847 | |
4848 | /* 3 */ | |
4849 | annotate_field (2); | |
0d381245 VP |
4850 | if (part_of_multiple) |
4851 | ui_out_field_skip (uiout, "disp"); | |
4852 | else | |
2cec12e5 | 4853 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4854 | |
c4093a6a JM |
4855 | |
4856 | /* 4 */ | |
4857 | annotate_field (3); | |
0d381245 | 4858 | if (part_of_multiple) |
54e52265 | 4859 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4860 | else |
4a64f543 MS |
4861 | ui_out_field_fmt (uiout, "enabled", "%c", |
4862 | bpenables[(int) b->enable_state]); | |
54e52265 | 4863 | ui_out_spaces (uiout, 2); |
0d381245 | 4864 | |
c4093a6a JM |
4865 | |
4866 | /* 5 and 6 */ | |
3086aeae | 4867 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4868 | { |
4a64f543 MS |
4869 | /* Although the print_one can possibly print all locations, |
4870 | calling it here is not likely to get any nice result. So, | |
4871 | make sure there's just one location. */ | |
0d381245 | 4872 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4873 | b->ops->print_one (b, last_loc); |
0d381245 | 4874 | } |
3086aeae DJ |
4875 | else |
4876 | switch (b->type) | |
4877 | { | |
4878 | case bp_none: | |
4879 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4880 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4881 | break; |
c906108c | 4882 | |
3086aeae DJ |
4883 | case bp_watchpoint: |
4884 | case bp_hardware_watchpoint: | |
4885 | case bp_read_watchpoint: | |
4886 | case bp_access_watchpoint: | |
4887 | /* Field 4, the address, is omitted (which makes the columns | |
4888 | not line up too nicely with the headers, but the effect | |
4889 | is relatively readable). */ | |
79a45b7d | 4890 | if (opts.addressprint) |
3086aeae DJ |
4891 | ui_out_field_skip (uiout, "addr"); |
4892 | annotate_field (5); | |
fa8a61dc | 4893 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4894 | break; |
4895 | ||
3086aeae DJ |
4896 | case bp_breakpoint: |
4897 | case bp_hardware_breakpoint: | |
4898 | case bp_until: | |
4899 | case bp_finish: | |
4900 | case bp_longjmp: | |
4901 | case bp_longjmp_resume: | |
186c406b TT |
4902 | case bp_exception: |
4903 | case bp_exception_resume: | |
3086aeae | 4904 | case bp_step_resume: |
3086aeae DJ |
4905 | case bp_watchpoint_scope: |
4906 | case bp_call_dummy: | |
aa7d318d | 4907 | case bp_std_terminate: |
3086aeae DJ |
4908 | case bp_shlib_event: |
4909 | case bp_thread_event: | |
4910 | case bp_overlay_event: | |
0fd8e87f | 4911 | case bp_longjmp_master: |
aa7d318d | 4912 | case bp_std_terminate_master: |
186c406b | 4913 | case bp_exception_master: |
1042e4c0 | 4914 | case bp_tracepoint: |
7a697b8d | 4915 | case bp_fast_tracepoint: |
0fb4aa4b | 4916 | case bp_static_tracepoint: |
4efc6507 | 4917 | case bp_jit_event: |
0e30163f JK |
4918 | case bp_gnu_ifunc_resolver: |
4919 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4920 | if (opts.addressprint) |
3086aeae DJ |
4921 | { |
4922 | annotate_field (4); | |
54e52265 | 4923 | if (header_of_multiple) |
0d381245 | 4924 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4925 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4926 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4927 | else |
5af949e3 UW |
4928 | ui_out_field_core_addr (uiout, "addr", |
4929 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4930 | } |
4931 | annotate_field (5); | |
0d381245 | 4932 | if (!header_of_multiple) |
170b53b2 | 4933 | print_breakpoint_location (b, loc); |
0d381245 | 4934 | if (b->loc) |
a6d9a66e | 4935 | *last_loc = b->loc; |
3086aeae DJ |
4936 | break; |
4937 | } | |
c906108c | 4938 | |
6c95b8df PA |
4939 | |
4940 | /* For backward compatibility, don't display inferiors unless there | |
4941 | are several. */ | |
4942 | if (loc != NULL | |
4943 | && !header_of_multiple | |
4944 | && (allflag | |
4945 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4946 | && (number_of_program_spaces () > 1 | |
4947 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4948 | /* LOC is for existing B, it cannot be in |
4949 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4950 | && loc->owner->type != bp_catchpoint))) |
4951 | { | |
4952 | struct inferior *inf; | |
4953 | int first = 1; | |
4954 | ||
4955 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4956 | { | |
4957 | if (inf->pspace == loc->pspace) | |
4958 | { | |
4959 | if (first) | |
4960 | { | |
4961 | first = 0; | |
4962 | ui_out_text (uiout, " inf "); | |
4963 | } | |
4964 | else | |
4965 | ui_out_text (uiout, ", "); | |
4966 | ui_out_text (uiout, plongest (inf->num)); | |
4967 | } | |
4968 | } | |
4969 | } | |
4970 | ||
4a306c9a | 4971 | if (!part_of_multiple) |
c4093a6a | 4972 | { |
4a306c9a JB |
4973 | if (b->thread != -1) |
4974 | { | |
4975 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4976 | "stop only in" line a little further down. */ |
4a306c9a JB |
4977 | ui_out_text (uiout, " thread "); |
4978 | ui_out_field_int (uiout, "thread", b->thread); | |
4979 | } | |
4980 | else if (b->task != 0) | |
4981 | { | |
4982 | ui_out_text (uiout, " task "); | |
4983 | ui_out_field_int (uiout, "task", b->task); | |
4984 | } | |
c4093a6a | 4985 | } |
f1310107 | 4986 | |
8b93c638 | 4987 | ui_out_text (uiout, "\n"); |
f1310107 TJB |
4988 | |
4989 | if (!part_of_multiple && b->ops && b->ops->print_one_detail) | |
4990 | b->ops->print_one_detail (b, uiout); | |
4991 | ||
0fb4aa4b PA |
4992 | if (!part_of_multiple && b->static_trace_marker_id) |
4993 | { | |
4994 | gdb_assert (b->type == bp_static_tracepoint); | |
4995 | ||
4996 | ui_out_text (uiout, "\tmarker id is "); | |
4997 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
4998 | b->static_trace_marker_id); | |
4999 | ui_out_text (uiout, "\n"); | |
5000 | } | |
5001 | ||
0d381245 | 5002 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
5003 | { |
5004 | annotate_field (6); | |
8b93c638 | 5005 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
5006 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
5007 | the frame ID. */ | |
5af949e3 UW |
5008 | ui_out_field_core_addr (uiout, "frame", |
5009 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 5010 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
5011 | } |
5012 | ||
0d381245 | 5013 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 5014 | { |
f7f9143b JB |
5015 | /* We do not print the condition for Ada exception catchpoints |
5016 | because the condition is an internal implementation detail | |
5017 | that we do not want to expose to the user. */ | |
c4093a6a | 5018 | annotate_field (7); |
d77f58be | 5019 | if (is_tracepoint (b)) |
1042e4c0 SS |
5020 | ui_out_text (uiout, "\ttrace only if "); |
5021 | else | |
5022 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
5023 | ui_out_field_string (uiout, "cond", b->cond_string); |
5024 | ui_out_text (uiout, "\n"); | |
5025 | } | |
5026 | ||
0d381245 | 5027 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 5028 | { |
4a64f543 | 5029 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5030 | ui_out_text (uiout, "\tstop only in thread "); |
5031 | ui_out_field_int (uiout, "thread", b->thread); | |
5032 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
5033 | } |
5034 | ||
63c715c6 | 5035 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 5036 | { |
4a64f543 | 5037 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5038 | if (ep_is_catchpoint (b)) |
5039 | ui_out_text (uiout, "\tcatchpoint"); | |
5040 | else | |
5041 | ui_out_text (uiout, "\tbreakpoint"); | |
5042 | ui_out_text (uiout, " already hit "); | |
5043 | ui_out_field_int (uiout, "times", b->hit_count); | |
5044 | if (b->hit_count == 1) | |
5045 | ui_out_text (uiout, " time\n"); | |
5046 | else | |
5047 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
5048 | } |
5049 | ||
4a64f543 MS |
5050 | /* Output the count also if it is zero, but only if this is mi. |
5051 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 5052 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 5053 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 5054 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 5055 | |
0d381245 | 5056 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
5057 | { |
5058 | annotate_field (8); | |
8b93c638 JM |
5059 | ui_out_text (uiout, "\tignore next "); |
5060 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
5061 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 5062 | } |
059fb39f | 5063 | |
9add0f1b | 5064 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 5065 | if (!part_of_multiple && l) |
c4093a6a | 5066 | { |
3b31d625 EZ |
5067 | struct cleanup *script_chain; |
5068 | ||
c4093a6a | 5069 | annotate_field (9); |
3b31d625 | 5070 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 5071 | print_command_lines (uiout, l, 4); |
3b31d625 | 5072 | do_cleanups (script_chain); |
c4093a6a | 5073 | } |
d24317b4 | 5074 | |
1042e4c0 SS |
5075 | if (!part_of_multiple && b->pass_count) |
5076 | { | |
5077 | annotate_field (10); | |
5078 | ui_out_text (uiout, "\tpass count "); | |
5079 | ui_out_field_int (uiout, "pass", b->pass_count); | |
5080 | ui_out_text (uiout, " \n"); | |
5081 | } | |
5082 | ||
d24317b4 VP |
5083 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5084 | { | |
5085 | if (b->addr_string) | |
5086 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
5087 | else if (b->exp_string) | |
5088 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
5089 | } | |
c4093a6a | 5090 | } |
c5aa993b | 5091 | |
0d381245 VP |
5092 | static void |
5093 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5094 | struct bp_location **last_loc, |
6c95b8df | 5095 | int allflag) |
0d381245 | 5096 | { |
8d3788bd VP |
5097 | struct cleanup *bkpt_chain; |
5098 | ||
5099 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
5100 | ||
12c5a436 | 5101 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 5102 | do_cleanups (bkpt_chain); |
0d381245 VP |
5103 | |
5104 | /* If this breakpoint has custom print function, | |
5105 | it's already printed. Otherwise, print individual | |
5106 | locations, if any. */ | |
5107 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5108 | { | |
4a64f543 MS |
5109 | /* If breakpoint has a single location that is disabled, we |
5110 | print it as if it had several locations, since otherwise it's | |
5111 | hard to represent "breakpoint enabled, location disabled" | |
5112 | situation. | |
5113 | ||
5114 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5115 | internally, that's not a property exposed to user. */ |
0d381245 | 5116 | if (b->loc |
a5606eee | 5117 | && !is_hardware_watchpoint (b) |
8d3788bd | 5118 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
5119 | { |
5120 | struct bp_location *loc; | |
5121 | int n = 1; | |
8d3788bd | 5122 | |
0d381245 | 5123 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
5124 | { |
5125 | struct cleanup *inner2 = | |
5126 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
5127 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
5128 | do_cleanups (inner2); | |
5129 | } | |
0d381245 VP |
5130 | } |
5131 | } | |
5132 | } | |
5133 | ||
a6d9a66e UW |
5134 | static int |
5135 | breakpoint_address_bits (struct breakpoint *b) | |
5136 | { | |
5137 | int print_address_bits = 0; | |
5138 | struct bp_location *loc; | |
5139 | ||
5140 | for (loc = b->loc; loc; loc = loc->next) | |
5141 | { | |
c7437ca6 PA |
5142 | int addr_bit; |
5143 | ||
5144 | /* Software watchpoints that aren't watching memory don't have | |
5145 | an address to print. */ | |
5146 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5147 | continue; | |
5148 | ||
5149 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5150 | if (addr_bit > print_address_bits) |
5151 | print_address_bits = addr_bit; | |
5152 | } | |
5153 | ||
5154 | return print_address_bits; | |
5155 | } | |
0d381245 | 5156 | |
c4093a6a JM |
5157 | struct captured_breakpoint_query_args |
5158 | { | |
5159 | int bnum; | |
5160 | }; | |
c5aa993b | 5161 | |
c4093a6a | 5162 | static int |
2b65245e | 5163 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5164 | { |
5165 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5166 | struct breakpoint *b; |
a6d9a66e | 5167 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5168 | |
c4093a6a JM |
5169 | ALL_BREAKPOINTS (b) |
5170 | { | |
5171 | if (args->bnum == b->number) | |
c5aa993b | 5172 | { |
12c5a436 | 5173 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5174 | return GDB_RC_OK; |
c5aa993b | 5175 | } |
c4093a6a JM |
5176 | } |
5177 | return GDB_RC_NONE; | |
5178 | } | |
c5aa993b | 5179 | |
c4093a6a | 5180 | enum gdb_rc |
4a64f543 MS |
5181 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5182 | char **error_message) | |
c4093a6a JM |
5183 | { |
5184 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5185 | |
c4093a6a JM |
5186 | args.bnum = bnum; |
5187 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5188 | an error. */ |
b0b13bb4 DJ |
5189 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5190 | error_message, RETURN_MASK_ALL) < 0) | |
5191 | return GDB_RC_FAIL; | |
5192 | else | |
5193 | return GDB_RC_OK; | |
c4093a6a | 5194 | } |
c5aa993b | 5195 | |
09d682a4 TT |
5196 | /* Return true if this breakpoint was set by the user, false if it is |
5197 | internal or momentary. */ | |
5198 | ||
5199 | int | |
5200 | user_breakpoint_p (struct breakpoint *b) | |
5201 | { | |
46c6471b | 5202 | return b->number > 0; |
09d682a4 TT |
5203 | } |
5204 | ||
7f3b0473 | 5205 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5206 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5207 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5208 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5209 | ones for which it returns non-zero. Return the total number of | |
5210 | breakpoints listed. */ | |
c906108c | 5211 | |
d77f58be | 5212 | static int |
e5a67952 | 5213 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5214 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5215 | { |
52f0bd74 | 5216 | struct breakpoint *b; |
a6d9a66e | 5217 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5218 | int nr_printable_breakpoints; |
3b31d625 | 5219 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5220 | struct value_print_options opts; |
a6d9a66e | 5221 | int print_address_bits = 0; |
269b11a2 PA |
5222 | int print_type_col_width = 14; |
5223 | ||
79a45b7d TT |
5224 | get_user_print_options (&opts); |
5225 | ||
4a64f543 MS |
5226 | /* Compute the number of rows in the table, as well as the size |
5227 | required for address fields. */ | |
7f3b0473 AC |
5228 | nr_printable_breakpoints = 0; |
5229 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5230 | { |
5231 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5232 | if (filter && !filter (b)) | |
5233 | continue; | |
5234 | ||
5235 | /* If we have an "args" string, it is a list of breakpoints to | |
5236 | accept. Skip the others. */ | |
5237 | if (args != NULL && *args != '\0') | |
5238 | { | |
5239 | if (allflag && parse_and_eval_long (args) != b->number) | |
5240 | continue; | |
5241 | if (!allflag && !number_is_in_list (args, b->number)) | |
5242 | continue; | |
5243 | } | |
269b11a2 | 5244 | |
e5a67952 MS |
5245 | if (allflag || user_breakpoint_p (b)) |
5246 | { | |
5247 | int addr_bit, type_len; | |
a6d9a66e | 5248 | |
e5a67952 MS |
5249 | addr_bit = breakpoint_address_bits (b); |
5250 | if (addr_bit > print_address_bits) | |
5251 | print_address_bits = addr_bit; | |
269b11a2 | 5252 | |
e5a67952 MS |
5253 | type_len = strlen (bptype_string (b->type)); |
5254 | if (type_len > print_type_col_width) | |
5255 | print_type_col_width = type_len; | |
5256 | ||
5257 | nr_printable_breakpoints++; | |
5258 | } | |
5259 | } | |
7f3b0473 | 5260 | |
79a45b7d | 5261 | if (opts.addressprint) |
3b31d625 | 5262 | bkpttbl_chain |
3e43a32a MS |
5263 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5264 | nr_printable_breakpoints, | |
3b31d625 | 5265 | "BreakpointTable"); |
8b93c638 | 5266 | else |
3b31d625 | 5267 | bkpttbl_chain |
3e43a32a MS |
5268 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5269 | nr_printable_breakpoints, | |
3b31d625 | 5270 | "BreakpointTable"); |
8b93c638 | 5271 | |
7f3b0473 | 5272 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5273 | annotate_breakpoints_headers (); |
5274 | if (nr_printable_breakpoints > 0) | |
5275 | annotate_field (0); | |
4a64f543 | 5276 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5277 | if (nr_printable_breakpoints > 0) |
5278 | annotate_field (1); | |
269b11a2 | 5279 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5280 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5281 | if (nr_printable_breakpoints > 0) |
5282 | annotate_field (2); | |
4a64f543 | 5283 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5284 | if (nr_printable_breakpoints > 0) |
5285 | annotate_field (3); | |
54e52265 | 5286 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5287 | if (opts.addressprint) |
e5a67952 MS |
5288 | { |
5289 | if (nr_printable_breakpoints > 0) | |
5290 | annotate_field (4); | |
5291 | if (print_address_bits <= 32) | |
5292 | ui_out_table_header (uiout, 10, ui_left, | |
5293 | "addr", "Address"); /* 5 */ | |
5294 | else | |
5295 | ui_out_table_header (uiout, 18, ui_left, | |
5296 | "addr", "Address"); /* 5 */ | |
5297 | } | |
d7faa9e7 AC |
5298 | if (nr_printable_breakpoints > 0) |
5299 | annotate_field (5); | |
5300 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5301 | ui_out_table_body (uiout); | |
5302 | if (nr_printable_breakpoints > 0) | |
5303 | annotate_breakpoints_table (); | |
7f3b0473 | 5304 | |
c4093a6a | 5305 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5306 | { |
5307 | QUIT; | |
5308 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5309 | if (filter && !filter (b)) | |
5310 | continue; | |
5311 | ||
5312 | /* If we have an "args" string, it is a list of breakpoints to | |
5313 | accept. Skip the others. */ | |
5314 | ||
5315 | if (args != NULL && *args != '\0') | |
5316 | { | |
5317 | if (allflag) /* maintenance info breakpoint */ | |
5318 | { | |
5319 | if (parse_and_eval_long (args) != b->number) | |
5320 | continue; | |
5321 | } | |
5322 | else /* all others */ | |
5323 | { | |
5324 | if (!number_is_in_list (args, b->number)) | |
5325 | continue; | |
5326 | } | |
5327 | } | |
5328 | /* We only print out user settable breakpoints unless the | |
5329 | allflag is set. */ | |
5330 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5331 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5332 | } |
5333 | ||
3b31d625 | 5334 | do_cleanups (bkpttbl_chain); |
698384cd | 5335 | |
7f3b0473 | 5336 | if (nr_printable_breakpoints == 0) |
c906108c | 5337 | { |
4a64f543 MS |
5338 | /* If there's a filter, let the caller decide how to report |
5339 | empty list. */ | |
d77f58be SS |
5340 | if (!filter) |
5341 | { | |
e5a67952 | 5342 | if (args == NULL || *args == '\0') |
d77f58be SS |
5343 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5344 | else | |
4a64f543 | 5345 | ui_out_message (uiout, 0, |
e5a67952 MS |
5346 | "No breakpoint or watchpoint matching '%s'.\n", |
5347 | args); | |
d77f58be | 5348 | } |
c906108c SS |
5349 | } |
5350 | else | |
c4093a6a | 5351 | { |
a6d9a66e UW |
5352 | if (last_loc && !server_command) |
5353 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5354 | } |
c906108c | 5355 | |
4a64f543 | 5356 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5357 | there have been breakpoints? */ |
c906108c | 5358 | annotate_breakpoints_table_end (); |
d77f58be SS |
5359 | |
5360 | return nr_printable_breakpoints; | |
c906108c SS |
5361 | } |
5362 | ||
ad443146 SS |
5363 | /* Display the value of default-collect in a way that is generally |
5364 | compatible with the breakpoint list. */ | |
5365 | ||
5366 | static void | |
5367 | default_collect_info (void) | |
5368 | { | |
5369 | /* If it has no value (which is frequently the case), say nothing; a | |
5370 | message like "No default-collect." gets in user's face when it's | |
5371 | not wanted. */ | |
5372 | if (!*default_collect) | |
5373 | return; | |
5374 | ||
5375 | /* The following phrase lines up nicely with per-tracepoint collect | |
5376 | actions. */ | |
5377 | ui_out_text (uiout, "default collect "); | |
5378 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5379 | ui_out_text (uiout, " \n"); | |
5380 | } | |
5381 | ||
c906108c | 5382 | static void |
e5a67952 | 5383 | breakpoints_info (char *args, int from_tty) |
c906108c | 5384 | { |
e5a67952 | 5385 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5386 | |
5387 | default_collect_info (); | |
d77f58be SS |
5388 | } |
5389 | ||
5390 | static void | |
e5a67952 | 5391 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5392 | { |
e5a67952 | 5393 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
d77f58be SS |
5394 | |
5395 | if (num_printed == 0) | |
5396 | { | |
e5a67952 | 5397 | if (args == NULL || *args == '\0') |
d77f58be SS |
5398 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5399 | else | |
e5a67952 | 5400 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5401 | } |
c906108c SS |
5402 | } |
5403 | ||
7a292a7a | 5404 | static void |
e5a67952 | 5405 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5406 | { |
e5a67952 | 5407 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5408 | |
5409 | default_collect_info (); | |
c906108c SS |
5410 | } |
5411 | ||
0d381245 | 5412 | static int |
714835d5 | 5413 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5414 | struct program_space *pspace, |
714835d5 | 5415 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5416 | { |
5417 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5418 | |
0d381245 VP |
5419 | for (; bl; bl = bl->next) |
5420 | { | |
6c95b8df PA |
5421 | if (bl->pspace == pspace |
5422 | && bl->address == pc | |
0d381245 VP |
5423 | && (!overlay_debugging || bl->section == section)) |
5424 | return 1; | |
5425 | } | |
5426 | return 0; | |
5427 | } | |
5428 | ||
6c95b8df PA |
5429 | /* Print a message describing any breakpoints set at PC. This |
5430 | concerns with logical breakpoints, so we match program spaces, not | |
5431 | address spaces. */ | |
c906108c SS |
5432 | |
5433 | static void | |
6c95b8df PA |
5434 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5435 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5436 | struct obj_section *section, int thread) |
c906108c | 5437 | { |
52f0bd74 AC |
5438 | int others = 0; |
5439 | struct breakpoint *b; | |
c906108c SS |
5440 | |
5441 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5442 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5443 | if (others > 0) |
5444 | { | |
a3f17187 AC |
5445 | if (others == 1) |
5446 | printf_filtered (_("Note: breakpoint ")); | |
5447 | else /* if (others == ???) */ | |
5448 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5449 | ALL_BREAKPOINTS (b) |
6c95b8df | 5450 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5451 | { |
5452 | others--; | |
5453 | printf_filtered ("%d", b->number); | |
5454 | if (b->thread == -1 && thread != -1) | |
5455 | printf_filtered (" (all threads)"); | |
5456 | else if (b->thread != -1) | |
5457 | printf_filtered (" (thread %d)", b->thread); | |
5458 | printf_filtered ("%s%s ", | |
059fb39f | 5459 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5460 | || b->enable_state == bp_call_disabled |
5461 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5462 | ? " (disabled)" |
5463 | : b->enable_state == bp_permanent | |
5464 | ? " (permanent)" | |
5465 | : ""), | |
5466 | (others > 1) ? "," | |
5467 | : ((others == 1) ? " and" : "")); | |
5468 | } | |
a3f17187 | 5469 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5470 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5471 | printf_filtered (".\n"); |
5472 | } | |
5473 | } | |
5474 | \f | |
5475 | /* Set the default place to put a breakpoint | |
5476 | for the `break' command with no arguments. */ | |
5477 | ||
5478 | void | |
6c95b8df PA |
5479 | set_default_breakpoint (int valid, struct program_space *pspace, |
5480 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5481 | int line) |
c906108c SS |
5482 | { |
5483 | default_breakpoint_valid = valid; | |
6c95b8df | 5484 | default_breakpoint_pspace = pspace; |
c906108c SS |
5485 | default_breakpoint_address = addr; |
5486 | default_breakpoint_symtab = symtab; | |
5487 | default_breakpoint_line = line; | |
5488 | } | |
5489 | ||
e4f237da KB |
5490 | /* Return true iff it is meaningful to use the address member of |
5491 | BPT. For some breakpoint types, the address member is irrelevant | |
5492 | and it makes no sense to attempt to compare it to other addresses | |
5493 | (or use it for any other purpose either). | |
5494 | ||
4a64f543 MS |
5495 | More specifically, each of the following breakpoint types will |
5496 | always have a zero valued address and we don't want to mark | |
5497 | breakpoints of any of these types to be a duplicate of an actual | |
5498 | breakpoint at address zero: | |
e4f237da KB |
5499 | |
5500 | bp_watchpoint | |
2d134ed3 PA |
5501 | bp_catchpoint |
5502 | ||
5503 | */ | |
e4f237da KB |
5504 | |
5505 | static int | |
5506 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5507 | { | |
5508 | enum bptype type = bpt->type; | |
5509 | ||
2d134ed3 PA |
5510 | return (type != bp_watchpoint && type != bp_catchpoint); |
5511 | } | |
5512 | ||
5513 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5514 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5515 | ||
5516 | static int | |
4a64f543 MS |
5517 | watchpoint_locations_match (struct bp_location *loc1, |
5518 | struct bp_location *loc2) | |
2d134ed3 | 5519 | { |
2bdf28a0 JK |
5520 | /* Both of them must not be in moribund_locations. */ |
5521 | gdb_assert (loc1->owner != NULL); | |
5522 | gdb_assert (loc2->owner != NULL); | |
5523 | ||
4a64f543 MS |
5524 | /* If the target can evaluate the condition expression in hardware, |
5525 | then we we need to insert both watchpoints even if they are at | |
5526 | the same place. Otherwise the watchpoint will only trigger when | |
5527 | the condition of whichever watchpoint was inserted evaluates to | |
5528 | true, not giving a chance for GDB to check the condition of the | |
5529 | other watchpoint. */ | |
0cf6dd15 | 5530 | if ((loc1->owner->cond_exp |
4a64f543 MS |
5531 | && target_can_accel_watchpoint_condition (loc1->address, |
5532 | loc1->length, | |
0cf6dd15 TJB |
5533 | loc1->watchpoint_type, |
5534 | loc1->owner->cond_exp)) | |
5535 | || (loc2->owner->cond_exp | |
4a64f543 MS |
5536 | && target_can_accel_watchpoint_condition (loc2->address, |
5537 | loc2->length, | |
0cf6dd15 TJB |
5538 | loc2->watchpoint_type, |
5539 | loc2->owner->cond_exp))) | |
5540 | return 0; | |
5541 | ||
85d721b8 PA |
5542 | /* Note that this checks the owner's type, not the location's. In |
5543 | case the target does not support read watchpoints, but does | |
5544 | support access watchpoints, we'll have bp_read_watchpoint | |
5545 | watchpoints with hw_access locations. Those should be considered | |
5546 | duplicates of hw_read locations. The hw_read locations will | |
5547 | become hw_access locations later. */ | |
2d134ed3 PA |
5548 | return (loc1->owner->type == loc2->owner->type |
5549 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5550 | && loc1->address == loc2->address | |
5551 | && loc1->length == loc2->length); | |
e4f237da KB |
5552 | } |
5553 | ||
6c95b8df PA |
5554 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5555 | same breakpoint location. In most targets, this can only be true | |
5556 | if ASPACE1 matches ASPACE2. On targets that have global | |
5557 | breakpoints, the address space doesn't really matter. */ | |
5558 | ||
5559 | static int | |
5560 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5561 | struct address_space *aspace2, CORE_ADDR addr2) | |
5562 | { | |
5563 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5564 | || aspace1 == aspace2) | |
5565 | && addr1 == addr2); | |
5566 | } | |
5567 | ||
f1310107 TJB |
5568 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5569 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5570 | matches ASPACE2. On targets that have global breakpoints, the address | |
5571 | space doesn't really matter. */ | |
5572 | ||
5573 | static int | |
5574 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5575 | int len1, struct address_space *aspace2, | |
5576 | CORE_ADDR addr2) | |
5577 | { | |
5578 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5579 | || aspace1 == aspace2) | |
5580 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5581 | } | |
5582 | ||
5583 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5584 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5585 | matches the breakpoint's address space. On targets that have global | |
5586 | breakpoints, the address space doesn't really matter. */ | |
5587 | ||
5588 | static int | |
5589 | breakpoint_location_address_match (struct bp_location *bl, | |
5590 | struct address_space *aspace, | |
5591 | CORE_ADDR addr) | |
5592 | { | |
5593 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5594 | aspace, addr) | |
5595 | || (bl->length | |
5596 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5597 | bl->address, bl->length, | |
5598 | aspace, addr))); | |
5599 | } | |
5600 | ||
2d134ed3 PA |
5601 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5602 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5603 | represent the same location. */ | |
5604 | ||
5605 | static int | |
4a64f543 MS |
5606 | breakpoint_locations_match (struct bp_location *loc1, |
5607 | struct bp_location *loc2) | |
2d134ed3 | 5608 | { |
2bdf28a0 JK |
5609 | int hw_point1, hw_point2; |
5610 | ||
5611 | /* Both of them must not be in moribund_locations. */ | |
5612 | gdb_assert (loc1->owner != NULL); | |
5613 | gdb_assert (loc2->owner != NULL); | |
5614 | ||
5615 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5616 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5617 | |
5618 | if (hw_point1 != hw_point2) | |
5619 | return 0; | |
5620 | else if (hw_point1) | |
5621 | return watchpoint_locations_match (loc1, loc2); | |
5622 | else | |
f1310107 TJB |
5623 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5624 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5625 | loc2->pspace->aspace, loc2->address) | |
5626 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5627 | } |
5628 | ||
76897487 KB |
5629 | static void |
5630 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5631 | int bnum, int have_bnum) | |
5632 | { | |
f63fbe86 MS |
5633 | /* The longest string possibly returned by hex_string_custom |
5634 | is 50 chars. These must be at least that big for safety. */ | |
5635 | char astr1[64]; | |
5636 | char astr2[64]; | |
76897487 | 5637 | |
bb599908 PH |
5638 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5639 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5640 | if (have_bnum) |
8a3fe4f8 | 5641 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5642 | bnum, astr1, astr2); |
5643 | else | |
8a3fe4f8 | 5644 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5645 | } |
5646 | ||
4a64f543 MS |
5647 | /* Adjust a breakpoint's address to account for architectural |
5648 | constraints on breakpoint placement. Return the adjusted address. | |
5649 | Note: Very few targets require this kind of adjustment. For most | |
5650 | targets, this function is simply the identity function. */ | |
76897487 KB |
5651 | |
5652 | static CORE_ADDR | |
a6d9a66e UW |
5653 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5654 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5655 | { |
a6d9a66e | 5656 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5657 | { |
5658 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5659 | return bpaddr; | |
5660 | } | |
88f7da05 KB |
5661 | else if (bptype == bp_watchpoint |
5662 | || bptype == bp_hardware_watchpoint | |
5663 | || bptype == bp_read_watchpoint | |
5664 | || bptype == bp_access_watchpoint | |
fe798b75 | 5665 | || bptype == bp_catchpoint) |
88f7da05 KB |
5666 | { |
5667 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5668 | have their addresses modified. */ | |
5669 | return bpaddr; | |
5670 | } | |
76897487 KB |
5671 | else |
5672 | { | |
5673 | CORE_ADDR adjusted_bpaddr; | |
5674 | ||
5675 | /* Some targets have architectural constraints on the placement | |
5676 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5677 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5678 | |
5679 | /* An adjusted breakpoint address can significantly alter | |
5680 | a user's expectations. Print a warning if an adjustment | |
5681 | is required. */ | |
5682 | if (adjusted_bpaddr != bpaddr) | |
5683 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5684 | ||
5685 | return adjusted_bpaddr; | |
5686 | } | |
5687 | } | |
5688 | ||
7cc221ef DJ |
5689 | /* Allocate a struct bp_location. */ |
5690 | ||
26bb91f3 | 5691 | static struct bp_location * |
39d61571 | 5692 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5693 | { |
afe38095 | 5694 | struct bp_location *loc; |
7cc221ef DJ |
5695 | |
5696 | loc = xmalloc (sizeof (struct bp_location)); | |
5697 | memset (loc, 0, sizeof (*loc)); | |
5698 | ||
e049a4b5 | 5699 | loc->owner = bpt; |
511a6cd4 | 5700 | loc->cond = NULL; |
0d381245 VP |
5701 | loc->shlib_disabled = 0; |
5702 | loc->enabled = 1; | |
e049a4b5 | 5703 | |
39d61571 | 5704 | switch (bpt->type) |
e049a4b5 DJ |
5705 | { |
5706 | case bp_breakpoint: | |
5707 | case bp_until: | |
5708 | case bp_finish: | |
5709 | case bp_longjmp: | |
5710 | case bp_longjmp_resume: | |
186c406b TT |
5711 | case bp_exception: |
5712 | case bp_exception_resume: | |
e049a4b5 | 5713 | case bp_step_resume: |
e049a4b5 DJ |
5714 | case bp_watchpoint_scope: |
5715 | case bp_call_dummy: | |
aa7d318d | 5716 | case bp_std_terminate: |
e049a4b5 DJ |
5717 | case bp_shlib_event: |
5718 | case bp_thread_event: | |
5719 | case bp_overlay_event: | |
4efc6507 | 5720 | case bp_jit_event: |
0fd8e87f | 5721 | case bp_longjmp_master: |
aa7d318d | 5722 | case bp_std_terminate_master: |
186c406b | 5723 | case bp_exception_master: |
0e30163f JK |
5724 | case bp_gnu_ifunc_resolver: |
5725 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5726 | loc->loc_type = bp_loc_software_breakpoint; |
5727 | break; | |
5728 | case bp_hardware_breakpoint: | |
5729 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5730 | break; | |
5731 | case bp_hardware_watchpoint: | |
5732 | case bp_read_watchpoint: | |
5733 | case bp_access_watchpoint: | |
5734 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5735 | break; | |
5736 | case bp_watchpoint: | |
ce78b96d | 5737 | case bp_catchpoint: |
15c3d785 PA |
5738 | case bp_tracepoint: |
5739 | case bp_fast_tracepoint: | |
0fb4aa4b | 5740 | case bp_static_tracepoint: |
e049a4b5 DJ |
5741 | loc->loc_type = bp_loc_other; |
5742 | break; | |
5743 | default: | |
e2e0b3e5 | 5744 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5745 | } |
5746 | ||
f431efe5 | 5747 | loc->refc = 1; |
7cc221ef DJ |
5748 | return loc; |
5749 | } | |
5750 | ||
f431efe5 PA |
5751 | static void |
5752 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5753 | { |
5754 | if (loc->cond) | |
5755 | xfree (loc->cond); | |
74960c60 VP |
5756 | |
5757 | if (loc->function_name) | |
5758 | xfree (loc->function_name); | |
f431efe5 | 5759 | |
fe3f5fa8 VP |
5760 | xfree (loc); |
5761 | } | |
5762 | ||
f431efe5 PA |
5763 | /* Increment reference count. */ |
5764 | ||
5765 | static void | |
5766 | incref_bp_location (struct bp_location *bl) | |
5767 | { | |
5768 | ++bl->refc; | |
5769 | } | |
5770 | ||
5771 | /* Decrement reference count. If the reference count reaches 0, | |
5772 | destroy the bp_location. Sets *BLP to NULL. */ | |
5773 | ||
5774 | static void | |
5775 | decref_bp_location (struct bp_location **blp) | |
5776 | { | |
0807b50c PA |
5777 | gdb_assert ((*blp)->refc > 0); |
5778 | ||
f431efe5 PA |
5779 | if (--(*blp)->refc == 0) |
5780 | free_bp_location (*blp); | |
5781 | *blp = NULL; | |
5782 | } | |
5783 | ||
4a64f543 MS |
5784 | /* Helper to set_raw_breakpoint below. Creates a breakpoint that has |
5785 | type BPTYPE and has no locations as yet. */ | |
5786 | /* This function is used in gdbtk sources and thus can not be made | |
5787 | static. */ | |
c906108c | 5788 | |
c40e75cd | 5789 | static struct breakpoint * |
a6d9a66e UW |
5790 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5791 | enum bptype bptype) | |
c906108c | 5792 | { |
52f0bd74 | 5793 | struct breakpoint *b, *b1; |
c906108c SS |
5794 | |
5795 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5796 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5797 | |
4d28f7a8 | 5798 | b->type = bptype; |
a6d9a66e | 5799 | b->gdbarch = gdbarch; |
c906108c SS |
5800 | b->language = current_language->la_language; |
5801 | b->input_radix = input_radix; | |
5802 | b->thread = -1; | |
b5de0fa7 | 5803 | b->enable_state = bp_enabled; |
c906108c SS |
5804 | b->next = 0; |
5805 | b->silent = 0; | |
5806 | b->ignore_count = 0; | |
5807 | b->commands = NULL; | |
818dd999 | 5808 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5809 | b->forked_inferior_pid = null_ptid; |
c906108c | 5810 | b->exec_pathname = NULL; |
a96d9b2e | 5811 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5812 | b->ops = NULL; |
0d381245 | 5813 | b->condition_not_parsed = 0; |
84f4c1fe | 5814 | b->py_bp_object = NULL; |
d0fb5eae | 5815 | b->related_breakpoint = b; |
c906108c | 5816 | |
4a64f543 MS |
5817 | /* Add this breakpoint to the end of the chain so that a list of |
5818 | breakpoints will come out in order of increasing numbers. */ | |
c906108c SS |
5819 | |
5820 | b1 = breakpoint_chain; | |
5821 | if (b1 == 0) | |
5822 | breakpoint_chain = b; | |
5823 | else | |
5824 | { | |
5825 | while (b1->next) | |
5826 | b1 = b1->next; | |
5827 | b1->next = b; | |
5828 | } | |
0d381245 VP |
5829 | return b; |
5830 | } | |
5831 | ||
0e30163f JK |
5832 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5833 | resolutions should be made as the user specified the location explicitly | |
5834 | enough. */ | |
5835 | ||
0d381245 | 5836 | static void |
0e30163f | 5837 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5838 | { |
2bdf28a0 JK |
5839 | gdb_assert (loc->owner != NULL); |
5840 | ||
0d381245 | 5841 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5842 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5843 | || is_tracepoint (loc->owner)) |
0d381245 | 5844 | { |
0e30163f JK |
5845 | int is_gnu_ifunc; |
5846 | ||
5847 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5848 | NULL, NULL, &is_gnu_ifunc); | |
5849 | ||
5850 | if (is_gnu_ifunc && !explicit_loc) | |
5851 | { | |
5852 | struct breakpoint *b = loc->owner; | |
5853 | ||
5854 | gdb_assert (loc->pspace == current_program_space); | |
5855 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5856 | &loc->requested_address)) | |
5857 | { | |
5858 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5859 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5860 | loc->requested_address, | |
5861 | b->type); | |
5862 | } | |
5863 | else if (b->type == bp_breakpoint && b->loc == loc | |
5864 | && loc->next == NULL && b->related_breakpoint == b) | |
5865 | { | |
5866 | /* Create only the whole new breakpoint of this type but do not | |
5867 | mess more complicated breakpoints with multiple locations. */ | |
5868 | b->type = bp_gnu_ifunc_resolver; | |
5869 | } | |
5870 | } | |
5871 | ||
0d381245 VP |
5872 | if (loc->function_name) |
5873 | loc->function_name = xstrdup (loc->function_name); | |
5874 | } | |
5875 | } | |
5876 | ||
a6d9a66e UW |
5877 | /* Attempt to determine architecture of location identified by SAL. */ |
5878 | static struct gdbarch * | |
5879 | get_sal_arch (struct symtab_and_line sal) | |
5880 | { | |
5881 | if (sal.section) | |
5882 | return get_objfile_arch (sal.section->objfile); | |
5883 | if (sal.symtab) | |
5884 | return get_objfile_arch (sal.symtab->objfile); | |
5885 | ||
5886 | return NULL; | |
5887 | } | |
5888 | ||
0d381245 VP |
5889 | /* set_raw_breakpoint is a low level routine for allocating and |
5890 | partially initializing a breakpoint of type BPTYPE. The newly | |
5891 | created breakpoint's address, section, source file name, and line | |
5892 | number are provided by SAL. The newly created and partially | |
5893 | initialized breakpoint is added to the breakpoint chain and | |
5894 | is also returned as the value of this function. | |
5895 | ||
5896 | It is expected that the caller will complete the initialization of | |
5897 | the newly created breakpoint struct as well as output any status | |
5898 | information regarding the creation of a new breakpoint. In | |
5899 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5900 | number! Care should be taken to not allow an error to occur | |
5901 | prior to completing the initialization of the breakpoint. If this | |
5902 | should happen, a bogus breakpoint will be left on the chain. */ | |
5903 | ||
63c252f8 | 5904 | struct breakpoint * |
a6d9a66e UW |
5905 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5906 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5907 | { |
4a64f543 MS |
5908 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, |
5909 | bptype); | |
0d381245 | 5910 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5911 | struct gdbarch *loc_gdbarch; |
5912 | ||
5913 | loc_gdbarch = get_sal_arch (sal); | |
5914 | if (!loc_gdbarch) | |
5915 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5916 | |
6c95b8df PA |
5917 | if (bptype != bp_catchpoint) |
5918 | gdb_assert (sal.pspace != NULL); | |
5919 | ||
0d381245 VP |
5920 | /* Adjust the breakpoint's address prior to allocating a location. |
5921 | Once we call allocate_bp_location(), that mostly uninitialized | |
5922 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5923 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5924 | not want its scan of the location chain to find a breakpoint and |
5925 | location that's only been partially initialized. */ | |
4a64f543 MS |
5926 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5927 | sal.pc, b->type); | |
0d381245 | 5928 | |
39d61571 | 5929 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5930 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5931 | b->loc->requested_address = sal.pc; |
5932 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5933 | b->loc->pspace = sal.pspace; |
5934 | ||
5935 | /* Store the program space that was used to set the breakpoint, for | |
5936 | breakpoint resetting. */ | |
5937 | b->pspace = sal.pspace; | |
0d381245 VP |
5938 | |
5939 | if (sal.symtab == NULL) | |
5940 | b->source_file = NULL; | |
5941 | else | |
1b36a34b | 5942 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5943 | b->loc->section = sal.section; |
5944 | b->line_number = sal.line; | |
5945 | ||
0e30163f JK |
5946 | set_breakpoint_location_function (b->loc, |
5947 | sal.explicit_pc || sal.explicit_line); | |
c906108c | 5948 | |
c906108c SS |
5949 | breakpoints_changed (); |
5950 | ||
5951 | return b; | |
5952 | } | |
5953 | ||
c2c6d25f JM |
5954 | |
5955 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5956 | instruction, hard-wired into the inferior's code. */ | |
5957 | void | |
5958 | make_breakpoint_permanent (struct breakpoint *b) | |
5959 | { | |
0d381245 | 5960 | struct bp_location *bl; |
cc59ec59 | 5961 | |
b5de0fa7 | 5962 | b->enable_state = bp_permanent; |
c2c6d25f | 5963 | |
4a64f543 MS |
5964 | /* By definition, permanent breakpoints are already present in the |
5965 | code. Mark all locations as inserted. For now, | |
5966 | make_breakpoint_permanent is called in just one place, so it's | |
5967 | hard to say if it's reasonable to have permanent breakpoint with | |
5968 | multiple locations or not, but it's easy to implmement. */ | |
0d381245 VP |
5969 | for (bl = b->loc; bl; bl = bl->next) |
5970 | bl->inserted = 1; | |
c2c6d25f JM |
5971 | } |
5972 | ||
53a5351d | 5973 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5974 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5975 | initiated the operation. */ | |
c906108c SS |
5976 | |
5977 | void | |
186c406b | 5978 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5979 | { |
35df4500 | 5980 | struct breakpoint *b, *b_tmp; |
186c406b | 5981 | int thread = tp->num; |
0fd8e87f UW |
5982 | |
5983 | /* To avoid having to rescan all objfile symbols at every step, | |
5984 | we maintain a list of continually-inserted but always disabled | |
5985 | longjmp "master" breakpoints. Here, we simply create momentary | |
5986 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5987 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5988 | if (b->pspace == current_program_space |
186c406b TT |
5989 | && (b->type == bp_longjmp_master |
5990 | || b->type == bp_exception_master)) | |
0fd8e87f UW |
5991 | { |
5992 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5993 | |
186c406b | 5994 | clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
0fd8e87f UW |
5995 | clone->thread = thread; |
5996 | } | |
186c406b TT |
5997 | |
5998 | tp->initiating_frame = frame; | |
c906108c SS |
5999 | } |
6000 | ||
611c83ae | 6001 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 6002 | void |
611c83ae | 6003 | delete_longjmp_breakpoint (int thread) |
c906108c | 6004 | { |
35df4500 | 6005 | struct breakpoint *b, *b_tmp; |
c906108c | 6006 | |
35df4500 | 6007 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 6008 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
6009 | { |
6010 | if (b->thread == thread) | |
6011 | delete_breakpoint (b); | |
6012 | } | |
c906108c SS |
6013 | } |
6014 | ||
1900040c MS |
6015 | void |
6016 | enable_overlay_breakpoints (void) | |
6017 | { | |
52f0bd74 | 6018 | struct breakpoint *b; |
1900040c MS |
6019 | |
6020 | ALL_BREAKPOINTS (b) | |
6021 | if (b->type == bp_overlay_event) | |
6022 | { | |
6023 | b->enable_state = bp_enabled; | |
b60e7edf | 6024 | update_global_location_list (1); |
c02f5703 | 6025 | overlay_events_enabled = 1; |
1900040c MS |
6026 | } |
6027 | } | |
6028 | ||
6029 | void | |
6030 | disable_overlay_breakpoints (void) | |
6031 | { | |
52f0bd74 | 6032 | struct breakpoint *b; |
1900040c MS |
6033 | |
6034 | ALL_BREAKPOINTS (b) | |
6035 | if (b->type == bp_overlay_event) | |
6036 | { | |
6037 | b->enable_state = bp_disabled; | |
b60e7edf | 6038 | update_global_location_list (0); |
c02f5703 | 6039 | overlay_events_enabled = 0; |
1900040c MS |
6040 | } |
6041 | } | |
6042 | ||
aa7d318d TT |
6043 | /* Set an active std::terminate breakpoint for each std::terminate |
6044 | master breakpoint. */ | |
6045 | void | |
6046 | set_std_terminate_breakpoint (void) | |
6047 | { | |
35df4500 | 6048 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6049 | |
35df4500 | 6050 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6051 | if (b->pspace == current_program_space |
6052 | && b->type == bp_std_terminate_master) | |
6053 | { | |
6054 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
6055 | clone->type = bp_std_terminate; | |
6056 | } | |
6057 | } | |
6058 | ||
6059 | /* Delete all the std::terminate breakpoints. */ | |
6060 | void | |
6061 | delete_std_terminate_breakpoint (void) | |
6062 | { | |
35df4500 | 6063 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6064 | |
35df4500 | 6065 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6066 | if (b->type == bp_std_terminate) |
6067 | delete_breakpoint (b); | |
6068 | } | |
6069 | ||
c4093a6a | 6070 | struct breakpoint * |
a6d9a66e | 6071 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
6072 | { |
6073 | struct breakpoint *b; | |
c4093a6a | 6074 | |
a6d9a66e | 6075 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 6076 | |
b5de0fa7 | 6077 | b->enable_state = bp_enabled; |
c4093a6a | 6078 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
6079 | b->addr_string |
6080 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 6081 | |
b60e7edf | 6082 | update_global_location_list_nothrow (1); |
74960c60 | 6083 | |
c4093a6a JM |
6084 | return b; |
6085 | } | |
6086 | ||
6087 | void | |
6088 | remove_thread_event_breakpoints (void) | |
6089 | { | |
35df4500 | 6090 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6091 | |
35df4500 | 6092 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6093 | if (b->type == bp_thread_event |
6094 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6095 | delete_breakpoint (b); |
6096 | } | |
6097 | ||
0101ce28 JJ |
6098 | struct lang_and_radix |
6099 | { | |
6100 | enum language lang; | |
6101 | int radix; | |
6102 | }; | |
6103 | ||
4efc6507 DE |
6104 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6105 | ||
6106 | struct breakpoint * | |
6107 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6108 | { | |
6109 | struct breakpoint *b; | |
6110 | ||
6111 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
6112 | update_global_location_list_nothrow (1); | |
6113 | return b; | |
6114 | } | |
0101ce28 | 6115 | |
03673fc7 PP |
6116 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6117 | ||
6118 | void | |
6119 | remove_jit_event_breakpoints (void) | |
6120 | { | |
6121 | struct breakpoint *b, *b_tmp; | |
6122 | ||
6123 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6124 | if (b->type == bp_jit_event | |
6125 | && b->loc->pspace == current_program_space) | |
6126 | delete_breakpoint (b); | |
6127 | } | |
6128 | ||
cae688ec JJ |
6129 | void |
6130 | remove_solib_event_breakpoints (void) | |
6131 | { | |
35df4500 | 6132 | struct breakpoint *b, *b_tmp; |
cae688ec | 6133 | |
35df4500 | 6134 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6135 | if (b->type == bp_shlib_event |
6136 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6137 | delete_breakpoint (b); |
6138 | } | |
6139 | ||
6140 | struct breakpoint * | |
a6d9a66e | 6141 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6142 | { |
6143 | struct breakpoint *b; | |
6144 | ||
a6d9a66e | 6145 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 6146 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6147 | return b; |
6148 | } | |
6149 | ||
6150 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6151 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6152 | ||
6153 | void | |
cb851954 | 6154 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6155 | { |
876fa593 | 6156 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6157 | |
876fa593 | 6158 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6159 | { |
2bdf28a0 | 6160 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6161 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6162 | |
4a64f543 MS |
6163 | /* We apply the check to all breakpoints, including disabled for |
6164 | those with loc->duplicate set. This is so that when breakpoint | |
6165 | becomes enabled, or the duplicate is removed, gdb will try to | |
6166 | insert all breakpoints. If we don't set shlib_disabled here, | |
6167 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6168 | if (((b->type == bp_breakpoint) |
508ccb1f | 6169 | || (b->type == bp_jit_event) |
1042e4c0 | 6170 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6171 | || (is_tracepoint (b))) |
6c95b8df | 6172 | && loc->pspace == current_program_space |
0d381245 | 6173 | && !loc->shlib_disabled |
a77053c2 | 6174 | #ifdef PC_SOLIB |
0d381245 | 6175 | && PC_SOLIB (loc->address) |
a77053c2 | 6176 | #else |
6c95b8df | 6177 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6178 | #endif |
6179 | ) | |
0d381245 VP |
6180 | { |
6181 | loc->shlib_disabled = 1; | |
6182 | } | |
cae688ec JJ |
6183 | } |
6184 | } | |
6185 | ||
7a9dd1b2 | 6186 | /* Disable any breakpoints that are in an unloaded shared library. |
4a64f543 MS |
6187 | Only apply to enabled breakpoints, disabled ones can just stay |
6188 | disabled. */ | |
84acb35a | 6189 | |
75149521 | 6190 | static void |
84acb35a JJ |
6191 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6192 | { | |
876fa593 | 6193 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6194 | int disabled_shlib_breaks = 0; |
6195 | ||
c86cf029 VP |
6196 | /* SunOS a.out shared libraries are always mapped, so do not |
6197 | disable breakpoints; they will only be reported as unloaded | |
6198 | through clear_solib when GDB discards its shared library | |
6199 | list. See clear_solib for more information. */ | |
6200 | if (exec_bfd != NULL | |
6201 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6202 | return; | |
6203 | ||
876fa593 | 6204 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6205 | { |
2bdf28a0 | 6206 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6207 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6208 | |
0d381245 VP |
6209 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6210 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6211 | && solib->pspace == loc->pspace |
e2dd7057 | 6212 | && !loc->shlib_disabled |
508ccb1f TT |
6213 | && (b->type == bp_breakpoint |
6214 | || b->type == bp_jit_event | |
6215 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6216 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6217 | { |
e2dd7057 PP |
6218 | loc->shlib_disabled = 1; |
6219 | /* At this point, we cannot rely on remove_breakpoint | |
6220 | succeeding so we must mark the breakpoint as not inserted | |
6221 | to prevent future errors occurring in remove_breakpoints. */ | |
6222 | loc->inserted = 0; | |
8d3788bd VP |
6223 | |
6224 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6225 | observer_notify_breakpoint_modified (b); | |
6226 | ||
e2dd7057 PP |
6227 | if (!disabled_shlib_breaks) |
6228 | { | |
6229 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6230 | warning (_("Temporarily disabling breakpoints " |
6231 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6232 | solib->so_name); |
84acb35a | 6233 | } |
e2dd7057 | 6234 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6235 | } |
6236 | } | |
84acb35a JJ |
6237 | } |
6238 | ||
ce78b96d JB |
6239 | /* FORK & VFORK catchpoints. */ |
6240 | ||
4a64f543 MS |
6241 | /* Implement the "insert" breakpoint_ops method for fork |
6242 | catchpoints. */ | |
ce78b96d | 6243 | |
77b06cd7 TJB |
6244 | static int |
6245 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6246 | { |
77b06cd7 | 6247 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6248 | } |
6249 | ||
4a64f543 MS |
6250 | /* Implement the "remove" breakpoint_ops method for fork |
6251 | catchpoints. */ | |
ce78b96d JB |
6252 | |
6253 | static int | |
77b06cd7 | 6254 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6255 | { |
6256 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6257 | } | |
6258 | ||
6259 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6260 | catchpoints. */ | |
6261 | ||
6262 | static int | |
f1310107 TJB |
6263 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
6264 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6265 | { |
f1310107 | 6266 | return inferior_has_forked (inferior_ptid, &bl->owner->forked_inferior_pid); |
ce78b96d JB |
6267 | } |
6268 | ||
4a64f543 MS |
6269 | /* Implement the "print_it" breakpoint_ops method for fork |
6270 | catchpoints. */ | |
ce78b96d JB |
6271 | |
6272 | static enum print_stop_action | |
6273 | print_it_catch_fork (struct breakpoint *b) | |
6274 | { | |
6275 | annotate_catchpoint (b->number); | |
6276 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
6277 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6278 | return PRINT_SRC_AND_LOC; | |
6279 | } | |
6280 | ||
4a64f543 MS |
6281 | /* Implement the "print_one" breakpoint_ops method for fork |
6282 | catchpoints. */ | |
ce78b96d JB |
6283 | |
6284 | static void | |
a6d9a66e | 6285 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6286 | { |
79a45b7d TT |
6287 | struct value_print_options opts; |
6288 | ||
6289 | get_user_print_options (&opts); | |
6290 | ||
4a64f543 MS |
6291 | /* Field 4, the address, is omitted (which makes the columns not |
6292 | line up too nicely with the headers, but the effect is relatively | |
6293 | readable). */ | |
79a45b7d | 6294 | if (opts.addressprint) |
ce78b96d JB |
6295 | ui_out_field_skip (uiout, "addr"); |
6296 | annotate_field (5); | |
6297 | ui_out_text (uiout, "fork"); | |
6298 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6299 | { | |
6300 | ui_out_text (uiout, ", process "); | |
6301 | ui_out_field_int (uiout, "what", | |
6302 | ptid_get_pid (b->forked_inferior_pid)); | |
6303 | ui_out_spaces (uiout, 1); | |
6304 | } | |
6305 | } | |
6306 | ||
6307 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6308 | catchpoints. */ | |
6309 | ||
6310 | static void | |
6311 | print_mention_catch_fork (struct breakpoint *b) | |
6312 | { | |
6313 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6314 | } | |
6315 | ||
6149aea9 PA |
6316 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6317 | catchpoints. */ | |
6318 | ||
6319 | static void | |
6320 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6321 | { | |
6322 | fprintf_unfiltered (fp, "catch fork"); | |
6323 | } | |
6324 | ||
ce78b96d JB |
6325 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6326 | ||
6327 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
6328 | { | |
6329 | insert_catch_fork, | |
6330 | remove_catch_fork, | |
6331 | breakpoint_hit_catch_fork, | |
e09342b5 | 6332 | NULL, /* resources_needed */ |
9c06b0b4 | 6333 | NULL, /* works_in_software_mode */ |
ce78b96d JB |
6334 | print_it_catch_fork, |
6335 | print_one_catch_fork, | |
f1310107 | 6336 | NULL, /* print_one_detail */ |
6149aea9 PA |
6337 | print_mention_catch_fork, |
6338 | print_recreate_catch_fork | |
ce78b96d JB |
6339 | }; |
6340 | ||
4a64f543 MS |
6341 | /* Implement the "insert" breakpoint_ops method for vfork |
6342 | catchpoints. */ | |
ce78b96d | 6343 | |
77b06cd7 TJB |
6344 | static int |
6345 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6346 | { |
77b06cd7 | 6347 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6348 | } |
6349 | ||
4a64f543 MS |
6350 | /* Implement the "remove" breakpoint_ops method for vfork |
6351 | catchpoints. */ | |
ce78b96d JB |
6352 | |
6353 | static int | |
77b06cd7 | 6354 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6355 | { |
6356 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6357 | } | |
6358 | ||
6359 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6360 | catchpoints. */ | |
6361 | ||
6362 | static int | |
f1310107 TJB |
6363 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
6364 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6365 | { |
f1310107 | 6366 | return inferior_has_vforked (inferior_ptid, &bl->owner->forked_inferior_pid); |
ce78b96d JB |
6367 | } |
6368 | ||
4a64f543 MS |
6369 | /* Implement the "print_it" breakpoint_ops method for vfork |
6370 | catchpoints. */ | |
ce78b96d JB |
6371 | |
6372 | static enum print_stop_action | |
6373 | print_it_catch_vfork (struct breakpoint *b) | |
6374 | { | |
6375 | annotate_catchpoint (b->number); | |
6376 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
6377 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6378 | return PRINT_SRC_AND_LOC; | |
6379 | } | |
6380 | ||
4a64f543 MS |
6381 | /* Implement the "print_one" breakpoint_ops method for vfork |
6382 | catchpoints. */ | |
ce78b96d JB |
6383 | |
6384 | static void | |
a6d9a66e | 6385 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6386 | { |
79a45b7d TT |
6387 | struct value_print_options opts; |
6388 | ||
6389 | get_user_print_options (&opts); | |
4a64f543 MS |
6390 | /* Field 4, the address, is omitted (which makes the columns not |
6391 | line up too nicely with the headers, but the effect is relatively | |
6392 | readable). */ | |
79a45b7d | 6393 | if (opts.addressprint) |
ce78b96d JB |
6394 | ui_out_field_skip (uiout, "addr"); |
6395 | annotate_field (5); | |
6396 | ui_out_text (uiout, "vfork"); | |
6397 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6398 | { | |
6399 | ui_out_text (uiout, ", process "); | |
6400 | ui_out_field_int (uiout, "what", | |
6401 | ptid_get_pid (b->forked_inferior_pid)); | |
6402 | ui_out_spaces (uiout, 1); | |
6403 | } | |
6404 | } | |
6405 | ||
6406 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6407 | catchpoints. */ | |
6408 | ||
6409 | static void | |
6410 | print_mention_catch_vfork (struct breakpoint *b) | |
6411 | { | |
6412 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6413 | } | |
6414 | ||
6149aea9 PA |
6415 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6416 | catchpoints. */ | |
6417 | ||
6418 | static void | |
6419 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6420 | { | |
6421 | fprintf_unfiltered (fp, "catch vfork"); | |
6422 | } | |
6423 | ||
ce78b96d JB |
6424 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6425 | ||
6426 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6427 | { | |
6428 | insert_catch_vfork, | |
6429 | remove_catch_vfork, | |
6430 | breakpoint_hit_catch_vfork, | |
e09342b5 | 6431 | NULL, /* resources_needed */ |
9c06b0b4 | 6432 | NULL, /* works_in_software_mode */ |
ce78b96d JB |
6433 | print_it_catch_vfork, |
6434 | print_one_catch_vfork, | |
f1310107 | 6435 | NULL, /* print_one_detail */ |
6149aea9 PA |
6436 | print_mention_catch_vfork, |
6437 | print_recreate_catch_vfork | |
ce78b96d JB |
6438 | }; |
6439 | ||
a96d9b2e SDJ |
6440 | /* Implement the "insert" breakpoint_ops method for syscall |
6441 | catchpoints. */ | |
6442 | ||
77b06cd7 TJB |
6443 | static int |
6444 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e SDJ |
6445 | { |
6446 | struct inferior *inf = current_inferior (); | |
6447 | ||
6448 | ++inf->total_syscalls_count; | |
77b06cd7 | 6449 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6450 | ++inf->any_syscall_count; |
6451 | else | |
6452 | { | |
6453 | int i, iter; | |
cc59ec59 | 6454 | |
a96d9b2e | 6455 | for (i = 0; |
77b06cd7 | 6456 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6457 | i++) |
6458 | { | |
6459 | int elem; | |
cc59ec59 | 6460 | |
a96d9b2e SDJ |
6461 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6462 | { | |
6463 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6464 | uintptr_t vec_addr_offset |
6465 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6466 | uintptr_t vec_addr; |
6467 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6468 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6469 | vec_addr_offset; | |
6470 | memset ((void *) vec_addr, 0, | |
6471 | (iter + 1 - old_size) * sizeof (int)); | |
6472 | } | |
6473 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6474 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6475 | } | |
6476 | } | |
6477 | ||
77b06cd7 TJB |
6478 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6479 | inf->total_syscalls_count != 0, | |
6480 | inf->any_syscall_count, | |
6481 | VEC_length (int, inf->syscalls_counts), | |
6482 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6483 | } |
6484 | ||
6485 | /* Implement the "remove" breakpoint_ops method for syscall | |
6486 | catchpoints. */ | |
6487 | ||
6488 | static int | |
77b06cd7 | 6489 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e SDJ |
6490 | { |
6491 | struct inferior *inf = current_inferior (); | |
6492 | ||
6493 | --inf->total_syscalls_count; | |
77b06cd7 | 6494 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6495 | --inf->any_syscall_count; |
6496 | else | |
6497 | { | |
6498 | int i, iter; | |
cc59ec59 | 6499 | |
a96d9b2e | 6500 | for (i = 0; |
77b06cd7 | 6501 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6502 | i++) |
6503 | { | |
6504 | int elem; | |
6505 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6506 | /* Shouldn't happen. */ | |
6507 | continue; | |
6508 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6509 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6510 | } | |
6511 | } | |
6512 | ||
6513 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6514 | inf->total_syscalls_count != 0, | |
6515 | inf->any_syscall_count, | |
6516 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6517 | VEC_address (int, |
6518 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6519 | } |
6520 | ||
6521 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6522 | catchpoints. */ | |
6523 | ||
6524 | static int | |
f1310107 TJB |
6525 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
6526 | struct address_space *aspace, CORE_ADDR bp_addr) | |
a96d9b2e | 6527 | { |
4a64f543 MS |
6528 | /* We must check if we are catching specific syscalls in this |
6529 | breakpoint. If we are, then we must guarantee that the called | |
6530 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6531 | int syscall_number = 0; |
f1310107 | 6532 | const struct breakpoint *b = bl->owner; |
a96d9b2e SDJ |
6533 | |
6534 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6535 | return 0; | |
6536 | ||
6537 | /* Now, checking if the syscall is the same. */ | |
6538 | if (b->syscalls_to_be_caught) | |
6539 | { | |
6540 | int i, iter; | |
cc59ec59 | 6541 | |
a96d9b2e SDJ |
6542 | for (i = 0; |
6543 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6544 | i++) | |
6545 | if (syscall_number == iter) | |
6546 | break; | |
6547 | /* Not the same. */ | |
6548 | if (!iter) | |
6549 | return 0; | |
6550 | } | |
6551 | ||
6552 | return 1; | |
6553 | } | |
6554 | ||
6555 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6556 | catchpoints. */ | |
6557 | ||
6558 | static enum print_stop_action | |
6559 | print_it_catch_syscall (struct breakpoint *b) | |
6560 | { | |
6561 | /* These are needed because we want to know in which state a | |
6562 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6563 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6564 | must print "called syscall" or "returned from syscall". */ | |
6565 | ptid_t ptid; | |
6566 | struct target_waitstatus last; | |
6567 | struct syscall s; | |
6568 | struct cleanup *old_chain; | |
6569 | char *syscall_id; | |
6570 | ||
6571 | get_last_target_status (&ptid, &last); | |
6572 | ||
6573 | get_syscall_by_number (last.value.syscall_number, &s); | |
6574 | ||
6575 | annotate_catchpoint (b->number); | |
6576 | ||
6577 | if (s.name == NULL) | |
6578 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6579 | else | |
6580 | syscall_id = xstrprintf ("'%s'", s.name); | |
6581 | ||
6582 | old_chain = make_cleanup (xfree, syscall_id); | |
6583 | ||
6584 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6585 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6586 | b->number, syscall_id); | |
6587 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6588 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6589 | b->number, syscall_id); | |
6590 | ||
6591 | do_cleanups (old_chain); | |
6592 | ||
6593 | return PRINT_SRC_AND_LOC; | |
6594 | } | |
6595 | ||
6596 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6597 | catchpoints. */ | |
6598 | ||
6599 | static void | |
6600 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6601 | struct bp_location **last_loc) |
a96d9b2e SDJ |
6602 | { |
6603 | struct value_print_options opts; | |
6604 | ||
6605 | get_user_print_options (&opts); | |
4a64f543 MS |
6606 | /* Field 4, the address, is omitted (which makes the columns not |
6607 | line up too nicely with the headers, but the effect is relatively | |
6608 | readable). */ | |
a96d9b2e SDJ |
6609 | if (opts.addressprint) |
6610 | ui_out_field_skip (uiout, "addr"); | |
6611 | annotate_field (5); | |
6612 | ||
6613 | if (b->syscalls_to_be_caught | |
6614 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6615 | ui_out_text (uiout, "syscalls \""); | |
6616 | else | |
6617 | ui_out_text (uiout, "syscall \""); | |
6618 | ||
6619 | if (b->syscalls_to_be_caught) | |
6620 | { | |
6621 | int i, iter; | |
6622 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6623 | |
a96d9b2e SDJ |
6624 | for (i = 0; |
6625 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6626 | i++) | |
6627 | { | |
6628 | char *x = text; | |
6629 | struct syscall s; | |
6630 | get_syscall_by_number (iter, &s); | |
6631 | ||
6632 | if (s.name != NULL) | |
6633 | text = xstrprintf ("%s%s, ", text, s.name); | |
6634 | else | |
6635 | text = xstrprintf ("%s%d, ", text, iter); | |
6636 | ||
6637 | /* We have to xfree the last 'text' (now stored at 'x') | |
6638 | because xstrprintf dinamically allocates new space for it | |
6639 | on every call. */ | |
6640 | xfree (x); | |
6641 | } | |
6642 | /* Remove the last comma. */ | |
6643 | text[strlen (text) - 2] = '\0'; | |
6644 | ui_out_field_string (uiout, "what", text); | |
6645 | } | |
6646 | else | |
6647 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6648 | ui_out_text (uiout, "\" "); | |
6649 | } | |
6650 | ||
6651 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6652 | catchpoints. */ | |
6653 | ||
6654 | static void | |
6655 | print_mention_catch_syscall (struct breakpoint *b) | |
6656 | { | |
6657 | if (b->syscalls_to_be_caught) | |
6658 | { | |
6659 | int i, iter; | |
6660 | ||
6661 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6662 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6663 | else | |
6664 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6665 | ||
6666 | for (i = 0; | |
6667 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6668 | i++) | |
6669 | { | |
6670 | struct syscall s; | |
6671 | get_syscall_by_number (iter, &s); | |
6672 | ||
6673 | if (s.name) | |
6674 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6675 | else | |
6676 | printf_filtered (" %d", s.number); | |
6677 | } | |
6678 | printf_filtered (")"); | |
6679 | } | |
6680 | else | |
6681 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6682 | b->number); | |
6683 | } | |
6684 | ||
6149aea9 PA |
6685 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6686 | catchpoints. */ | |
6687 | ||
6688 | static void | |
6689 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6690 | { | |
6691 | fprintf_unfiltered (fp, "catch syscall"); | |
6692 | ||
6693 | if (b->syscalls_to_be_caught) | |
6694 | { | |
6695 | int i, iter; | |
6696 | ||
6697 | for (i = 0; | |
6698 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6699 | i++) | |
6700 | { | |
6701 | struct syscall s; | |
6702 | ||
6703 | get_syscall_by_number (iter, &s); | |
6704 | if (s.name) | |
6705 | fprintf_unfiltered (fp, " %s", s.name); | |
6706 | else | |
6707 | fprintf_unfiltered (fp, " %d", s.number); | |
6708 | } | |
6709 | } | |
6710 | } | |
6711 | ||
a96d9b2e SDJ |
6712 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6713 | ||
6714 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6715 | { | |
6716 | insert_catch_syscall, | |
6717 | remove_catch_syscall, | |
6718 | breakpoint_hit_catch_syscall, | |
e09342b5 | 6719 | NULL, /* resources_needed */ |
9c06b0b4 | 6720 | NULL, /* works_in_software_mode */ |
a96d9b2e SDJ |
6721 | print_it_catch_syscall, |
6722 | print_one_catch_syscall, | |
f1310107 | 6723 | NULL, /* print_one_detail */ |
6149aea9 PA |
6724 | print_mention_catch_syscall, |
6725 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6726 | }; |
6727 | ||
6728 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6729 | ||
6730 | static int | |
6731 | syscall_catchpoint_p (struct breakpoint *b) | |
6732 | { | |
6733 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6734 | } | |
6735 | ||
6736 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6737 | but does NOT mention it nor update the global location list. | |
6738 | This is useful if you need to fill more fields in the | |
6739 | struct breakpoint before calling mention. | |
ce78b96d JB |
6740 | |
6741 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6742 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6743 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6744 | to the catchpoint. */ | |
6745 | ||
6746 | static struct breakpoint * | |
a96d9b2e SDJ |
6747 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6748 | char *cond_string, | |
6749 | struct breakpoint_ops *ops) | |
c906108c | 6750 | { |
c5aa993b JM |
6751 | struct symtab_and_line sal; |
6752 | struct breakpoint *b; | |
c5aa993b | 6753 | |
fe39c653 | 6754 | init_sal (&sal); |
6c95b8df | 6755 | sal.pspace = current_program_space; |
c5aa993b | 6756 | |
a6d9a66e | 6757 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6758 | set_breakpoint_count (breakpoint_count + 1); |
6759 | b->number = breakpoint_count; | |
ce78b96d | 6760 | |
1b36a34b | 6761 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6762 | b->thread = -1; |
c906108c | 6763 | b->addr_string = NULL; |
b5de0fa7 EZ |
6764 | b->enable_state = bp_enabled; |
6765 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6766 | b->ops = ops; |
c5aa993b | 6767 | |
a96d9b2e SDJ |
6768 | return b; |
6769 | } | |
6770 | ||
6771 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6772 | ||
6773 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6774 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6775 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6776 | to the catchpoint. */ | |
6777 | ||
6778 | static struct breakpoint * | |
6779 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6780 | char *cond_string, struct breakpoint_ops *ops) | |
6781 | { | |
6782 | struct breakpoint *b = | |
6783 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6784 | ||
c906108c | 6785 | mention (b); |
8d3788bd | 6786 | observer_notify_breakpoint_created (b); |
ce78b96d | 6787 | update_global_location_list (1); |
c906108c | 6788 | |
ce78b96d | 6789 | return b; |
c906108c | 6790 | } |
c5aa993b | 6791 | |
9b70b993 | 6792 | static void |
a6d9a66e UW |
6793 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6794 | int tempflag, char *cond_string, | |
ce78b96d | 6795 | struct breakpoint_ops *ops) |
c906108c | 6796 | { |
a6d9a66e UW |
6797 | struct breakpoint *b |
6798 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6799 | |
6800 | /* FIXME: We should put this information in a breakpoint private data | |
6801 | area. */ | |
6802 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6803 | } |
6804 | ||
fe798b75 JB |
6805 | /* Exec catchpoints. */ |
6806 | ||
77b06cd7 TJB |
6807 | static int |
6808 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6809 | { |
77b06cd7 | 6810 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6811 | } |
c906108c | 6812 | |
fe798b75 | 6813 | static int |
77b06cd7 | 6814 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6815 | { |
6816 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6817 | } | |
c906108c | 6818 | |
fe798b75 | 6819 | static int |
f1310107 TJB |
6820 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
6821 | struct address_space *aspace, CORE_ADDR bp_addr) | |
fe798b75 | 6822 | { |
f1310107 | 6823 | return inferior_has_execd (inferior_ptid, &bl->owner->exec_pathname); |
fe798b75 | 6824 | } |
c906108c | 6825 | |
fe798b75 JB |
6826 | static enum print_stop_action |
6827 | print_it_catch_exec (struct breakpoint *b) | |
6828 | { | |
6829 | annotate_catchpoint (b->number); | |
6830 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6831 | b->exec_pathname); | |
6832 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6833 | } |
6834 | ||
fe798b75 | 6835 | static void |
a6d9a66e | 6836 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6837 | { |
6838 | struct value_print_options opts; | |
6839 | ||
6840 | get_user_print_options (&opts); | |
6841 | ||
6842 | /* Field 4, the address, is omitted (which makes the columns | |
6843 | not line up too nicely with the headers, but the effect | |
6844 | is relatively readable). */ | |
6845 | if (opts.addressprint) | |
6846 | ui_out_field_skip (uiout, "addr"); | |
6847 | annotate_field (5); | |
6848 | ui_out_text (uiout, "exec"); | |
6849 | if (b->exec_pathname != NULL) | |
6850 | { | |
6851 | ui_out_text (uiout, ", program \""); | |
6852 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6853 | ui_out_text (uiout, "\" "); | |
6854 | } | |
6855 | } | |
6856 | ||
6857 | static void | |
6858 | print_mention_catch_exec (struct breakpoint *b) | |
6859 | { | |
6860 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6861 | } | |
6862 | ||
6149aea9 PA |
6863 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6864 | catchpoints. */ | |
6865 | ||
6866 | static void | |
6867 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6868 | { | |
6869 | fprintf_unfiltered (fp, "catch exec"); | |
6870 | } | |
6871 | ||
fe798b75 JB |
6872 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6873 | { | |
6874 | insert_catch_exec, | |
6875 | remove_catch_exec, | |
6876 | breakpoint_hit_catch_exec, | |
e09342b5 | 6877 | NULL, /* resources_needed */ |
9c06b0b4 | 6878 | NULL, /* works_in_software_mode */ |
fe798b75 JB |
6879 | print_it_catch_exec, |
6880 | print_one_catch_exec, | |
f1310107 | 6881 | NULL, /* print_one_detail */ |
6149aea9 PA |
6882 | print_mention_catch_exec, |
6883 | print_recreate_catch_exec | |
fe798b75 JB |
6884 | }; |
6885 | ||
a96d9b2e SDJ |
6886 | static void |
6887 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6888 | struct breakpoint_ops *ops) | |
6889 | { | |
6890 | struct gdbarch *gdbarch = get_current_arch (); | |
6891 | struct breakpoint *b = | |
6892 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6893 | ||
6894 | b->syscalls_to_be_caught = filter; | |
6895 | ||
6896 | /* Now, we have to mention the breakpoint and update the global | |
6897 | location list. */ | |
6898 | mention (b); | |
8d3788bd | 6899 | observer_notify_breakpoint_created (b); |
a96d9b2e SDJ |
6900 | update_global_location_list (1); |
6901 | } | |
6902 | ||
c906108c | 6903 | static int |
fba45db2 | 6904 | hw_breakpoint_used_count (void) |
c906108c | 6905 | { |
c906108c | 6906 | int i = 0; |
f1310107 TJB |
6907 | struct breakpoint *b; |
6908 | struct bp_location *bl; | |
c906108c SS |
6909 | |
6910 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6911 | { |
d6b74ac4 | 6912 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
6913 | for (bl = b->loc; bl; bl = bl->next) |
6914 | { | |
6915 | /* Special types of hardware breakpoints may use more than | |
6916 | one register. */ | |
6917 | if (b->ops && b->ops->resources_needed) | |
6918 | i += b->ops->resources_needed (bl); | |
6919 | else | |
6920 | i++; | |
6921 | } | |
c5aa993b | 6922 | } |
c906108c SS |
6923 | |
6924 | return i; | |
6925 | } | |
6926 | ||
6927 | static int | |
fba45db2 | 6928 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6929 | { |
c906108c | 6930 | int i = 0; |
e09342b5 TJB |
6931 | struct breakpoint *b; |
6932 | struct bp_location *bl; | |
c906108c SS |
6933 | |
6934 | *other_type_used = 0; | |
6935 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6936 | { |
6937 | if (!breakpoint_enabled (b)) | |
6938 | continue; | |
6939 | ||
c5aa993b | 6940 | if (b->type == type) |
e09342b5 TJB |
6941 | for (bl = b->loc; bl; bl = bl->next) |
6942 | { | |
6943 | /* Special types of hardware watchpoints may use more than | |
6944 | one register. */ | |
6945 | if (b->ops && b->ops->resources_needed) | |
6946 | i += b->ops->resources_needed (bl); | |
6947 | else | |
6948 | i++; | |
6949 | } | |
cc60f2e3 | 6950 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6951 | *other_type_used = 1; |
e09342b5 TJB |
6952 | } |
6953 | ||
c906108c SS |
6954 | return i; |
6955 | } | |
6956 | ||
c906108c | 6957 | void |
fba45db2 | 6958 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6959 | { |
c5aa993b | 6960 | struct breakpoint *b; |
c906108c SS |
6961 | |
6962 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6963 | { |
cc60f2e3 | 6964 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6965 | { |
b5de0fa7 | 6966 | b->enable_state = bp_call_disabled; |
b60e7edf | 6967 | update_global_location_list (0); |
c5aa993b JM |
6968 | } |
6969 | } | |
c906108c SS |
6970 | } |
6971 | ||
6972 | void | |
fba45db2 | 6973 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6974 | { |
c5aa993b | 6975 | struct breakpoint *b; |
c906108c SS |
6976 | |
6977 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6978 | { |
cc60f2e3 | 6979 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6980 | { |
b5de0fa7 | 6981 | b->enable_state = bp_enabled; |
b60e7edf | 6982 | update_global_location_list (1); |
c5aa993b JM |
6983 | } |
6984 | } | |
c906108c SS |
6985 | } |
6986 | ||
8bea4e01 UW |
6987 | void |
6988 | disable_breakpoints_before_startup (void) | |
6989 | { | |
6990 | struct breakpoint *b; | |
6991 | int found = 0; | |
6992 | ||
6993 | ALL_BREAKPOINTS (b) | |
6994 | { | |
6c95b8df PA |
6995 | if (b->pspace != current_program_space) |
6996 | continue; | |
6997 | ||
8bea4e01 UW |
6998 | if ((b->type == bp_breakpoint |
6999 | || b->type == bp_hardware_breakpoint) | |
7000 | && breakpoint_enabled (b)) | |
7001 | { | |
7002 | b->enable_state = bp_startup_disabled; | |
7003 | found = 1; | |
7004 | } | |
7005 | } | |
7006 | ||
7007 | if (found) | |
7008 | update_global_location_list (0); | |
7009 | ||
6c95b8df | 7010 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
7011 | } |
7012 | ||
7013 | void | |
7014 | enable_breakpoints_after_startup (void) | |
7015 | { | |
7016 | struct breakpoint *b; | |
7017 | int found = 0; | |
7018 | ||
6c95b8df | 7019 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
7020 | |
7021 | ALL_BREAKPOINTS (b) | |
7022 | { | |
6c95b8df PA |
7023 | if (b->pspace != current_program_space) |
7024 | continue; | |
7025 | ||
8bea4e01 UW |
7026 | if ((b->type == bp_breakpoint |
7027 | || b->type == bp_hardware_breakpoint) | |
7028 | && b->enable_state == bp_startup_disabled) | |
7029 | { | |
7030 | b->enable_state = bp_enabled; | |
7031 | found = 1; | |
7032 | } | |
7033 | } | |
7034 | ||
7035 | if (found) | |
7036 | breakpoint_re_set (); | |
7037 | } | |
7038 | ||
c906108c SS |
7039 | |
7040 | /* Set a breakpoint that will evaporate an end of command | |
7041 | at address specified by SAL. | |
7042 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
7043 | ||
7044 | struct breakpoint * | |
a6d9a66e UW |
7045 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
7046 | struct frame_id frame_id, enum bptype type) | |
c906108c | 7047 | { |
52f0bd74 | 7048 | struct breakpoint *b; |
edb3359d DJ |
7049 | |
7050 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
7051 | one. */ | |
7052 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
7053 | ||
a6d9a66e | 7054 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
7055 | b->enable_state = bp_enabled; |
7056 | b->disposition = disp_donttouch; | |
818dd999 | 7057 | b->frame_id = frame_id; |
c906108c | 7058 | |
4a64f543 MS |
7059 | /* If we're debugging a multi-threaded program, then we want |
7060 | momentary breakpoints to be active in only a single thread of | |
7061 | control. */ | |
39f77062 KB |
7062 | if (in_thread_list (inferior_ptid)) |
7063 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 7064 | |
b60e7edf | 7065 | update_global_location_list_nothrow (1); |
74960c60 | 7066 | |
c906108c SS |
7067 | return b; |
7068 | } | |
611c83ae | 7069 | |
e58b0e63 PA |
7070 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7071 | ORIG is NULL. */ | |
7072 | ||
7073 | struct breakpoint * | |
7074 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7075 | { | |
7076 | struct breakpoint *copy; | |
7077 | ||
7078 | /* If there's nothing to clone, then return nothing. */ | |
7079 | if (orig == NULL) | |
7080 | return NULL; | |
7081 | ||
a6d9a66e | 7082 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 | 7083 | copy->loc = allocate_bp_location (copy); |
0e30163f | 7084 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 7085 | |
a6d9a66e | 7086 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
7087 | copy->loc->requested_address = orig->loc->requested_address; |
7088 | copy->loc->address = orig->loc->address; | |
7089 | copy->loc->section = orig->loc->section; | |
6c95b8df | 7090 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
7091 | |
7092 | if (orig->source_file == NULL) | |
7093 | copy->source_file = NULL; | |
7094 | else | |
7095 | copy->source_file = xstrdup (orig->source_file); | |
7096 | ||
7097 | copy->line_number = orig->line_number; | |
7098 | copy->frame_id = orig->frame_id; | |
7099 | copy->thread = orig->thread; | |
6c95b8df | 7100 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7101 | |
7102 | copy->enable_state = bp_enabled; | |
7103 | copy->disposition = disp_donttouch; | |
7104 | copy->number = internal_breakpoint_number--; | |
7105 | ||
7106 | update_global_location_list_nothrow (0); | |
7107 | return copy; | |
7108 | } | |
7109 | ||
611c83ae | 7110 | struct breakpoint * |
a6d9a66e UW |
7111 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7112 | enum bptype type) | |
611c83ae PA |
7113 | { |
7114 | struct symtab_and_line sal; | |
7115 | ||
7116 | sal = find_pc_line (pc, 0); | |
7117 | sal.pc = pc; | |
7118 | sal.section = find_pc_overlay (pc); | |
7119 | sal.explicit_pc = 1; | |
7120 | ||
a6d9a66e | 7121 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7122 | } |
c906108c | 7123 | \f |
c5aa993b | 7124 | |
c906108c SS |
7125 | /* Tell the user we have just set a breakpoint B. */ |
7126 | ||
7127 | static void | |
fba45db2 | 7128 | mention (struct breakpoint *b) |
c906108c SS |
7129 | { |
7130 | int say_where = 0; | |
fa8a61dc | 7131 | struct cleanup *ui_out_chain; |
79a45b7d TT |
7132 | struct value_print_options opts; |
7133 | ||
7134 | get_user_print_options (&opts); | |
8b93c638 | 7135 | |
3086aeae DJ |
7136 | if (b->ops != NULL && b->ops->print_mention != NULL) |
7137 | b->ops->print_mention (b); | |
7138 | else | |
7139 | switch (b->type) | |
7140 | { | |
7141 | case bp_none: | |
3e43a32a MS |
7142 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), |
7143 | b->number); | |
3086aeae DJ |
7144 | break; |
7145 | case bp_watchpoint: | |
7146 | ui_out_text (uiout, "Watchpoint "); | |
7147 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
7148 | ui_out_field_int (uiout, "number", b->number); | |
7149 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7150 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7151 | do_cleanups (ui_out_chain); |
7152 | break; | |
7153 | case bp_hardware_watchpoint: | |
7154 | ui_out_text (uiout, "Hardware watchpoint "); | |
7155 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
7156 | ui_out_field_int (uiout, "number", b->number); | |
7157 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7158 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7159 | do_cleanups (ui_out_chain); |
7160 | break; | |
7161 | case bp_read_watchpoint: | |
7162 | ui_out_text (uiout, "Hardware read watchpoint "); | |
7163 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
7164 | ui_out_field_int (uiout, "number", b->number); | |
7165 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7166 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7167 | do_cleanups (ui_out_chain); |
7168 | break; | |
7169 | case bp_access_watchpoint: | |
7170 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
7171 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
7172 | ui_out_field_int (uiout, "number", b->number); | |
7173 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7174 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7175 | do_cleanups (ui_out_chain); |
7176 | break; | |
7177 | case bp_breakpoint: | |
0e30163f | 7178 | case bp_gnu_ifunc_resolver: |
3086aeae DJ |
7179 | if (ui_out_is_mi_like_p (uiout)) |
7180 | { | |
7181 | say_where = 0; | |
7182 | break; | |
7183 | } | |
2cec12e5 AR |
7184 | if (b->disposition == disp_del) |
7185 | printf_filtered (_("Temporary breakpoint")); | |
7186 | else | |
7187 | printf_filtered (_("Breakpoint")); | |
7188 | printf_filtered (_(" %d"), b->number); | |
0e30163f JK |
7189 | if (b->type == bp_gnu_ifunc_resolver) |
7190 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
3086aeae DJ |
7191 | say_where = 1; |
7192 | break; | |
7193 | case bp_hardware_breakpoint: | |
7194 | if (ui_out_is_mi_like_p (uiout)) | |
7195 | { | |
7196 | say_where = 0; | |
7197 | break; | |
7198 | } | |
a3f17187 | 7199 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
7200 | say_where = 1; |
7201 | break; | |
1042e4c0 SS |
7202 | case bp_tracepoint: |
7203 | if (ui_out_is_mi_like_p (uiout)) | |
7204 | { | |
7205 | say_where = 0; | |
7206 | break; | |
7207 | } | |
7208 | printf_filtered (_("Tracepoint")); | |
7209 | printf_filtered (_(" %d"), b->number); | |
7210 | say_where = 1; | |
7211 | break; | |
7a697b8d SS |
7212 | case bp_fast_tracepoint: |
7213 | if (ui_out_is_mi_like_p (uiout)) | |
7214 | { | |
7215 | say_where = 0; | |
7216 | break; | |
7217 | } | |
7218 | printf_filtered (_("Fast tracepoint")); | |
7219 | printf_filtered (_(" %d"), b->number); | |
7220 | say_where = 1; | |
7221 | break; | |
0fb4aa4b PA |
7222 | case bp_static_tracepoint: |
7223 | if (ui_out_is_mi_like_p (uiout)) | |
7224 | { | |
7225 | say_where = 0; | |
7226 | break; | |
7227 | } | |
7228 | printf_filtered (_("Static tracepoint")); | |
7229 | printf_filtered (_(" %d"), b->number); | |
7230 | say_where = 1; | |
7231 | break; | |
3086aeae DJ |
7232 | |
7233 | case bp_until: | |
7234 | case bp_finish: | |
7235 | case bp_longjmp: | |
7236 | case bp_longjmp_resume: | |
186c406b TT |
7237 | case bp_exception: |
7238 | case bp_exception_resume: | |
3086aeae | 7239 | case bp_step_resume: |
3086aeae | 7240 | case bp_call_dummy: |
aa7d318d | 7241 | case bp_std_terminate: |
3086aeae DJ |
7242 | case bp_watchpoint_scope: |
7243 | case bp_shlib_event: | |
7244 | case bp_thread_event: | |
7245 | case bp_overlay_event: | |
4efc6507 | 7246 | case bp_jit_event: |
0fd8e87f | 7247 | case bp_longjmp_master: |
aa7d318d | 7248 | case bp_std_terminate_master: |
186c406b | 7249 | case bp_exception_master: |
0e30163f | 7250 | case bp_gnu_ifunc_resolver_return: |
3086aeae DJ |
7251 | break; |
7252 | } | |
c906108c | 7253 | |
c906108c SS |
7254 | if (say_where) |
7255 | { | |
a3f17187 AC |
7256 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
7257 | single string. */ | |
0d381245 | 7258 | if (b->loc == NULL) |
c906108c | 7259 | { |
a3f17187 | 7260 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
7261 | } |
7262 | else | |
7263 | { | |
79a45b7d | 7264 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
7265 | { |
7266 | printf_filtered (" at "); | |
5af949e3 UW |
7267 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
7268 | gdb_stdout); | |
0101ce28 JJ |
7269 | } |
7270 | if (b->source_file) | |
7271 | printf_filtered (": file %s, line %d.", | |
7272 | b->source_file, b->line_number); | |
0d381245 VP |
7273 | |
7274 | if (b->loc->next) | |
7275 | { | |
7276 | struct bp_location *loc = b->loc; | |
7277 | int n = 0; | |
7278 | for (; loc; loc = loc->next) | |
7279 | ++n; | |
7280 | printf_filtered (" (%d locations)", n); | |
7281 | } | |
7282 | ||
c906108c | 7283 | } |
c906108c | 7284 | } |
9dc5e2a9 | 7285 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7286 | return; |
c906108c SS |
7287 | printf_filtered ("\n"); |
7288 | } | |
c906108c | 7289 | \f |
c5aa993b | 7290 | |
0d381245 | 7291 | static struct bp_location * |
39d61571 | 7292 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7293 | const struct symtab_and_line *sal) |
7294 | { | |
7295 | struct bp_location *loc, **tmp; | |
7296 | ||
39d61571 | 7297 | loc = allocate_bp_location (b); |
0d381245 VP |
7298 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7299 | ; | |
7300 | *tmp = loc; | |
a6d9a66e UW |
7301 | loc->gdbarch = get_sal_arch (*sal); |
7302 | if (!loc->gdbarch) | |
7303 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7304 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7305 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7306 | loc->requested_address, b->type); | |
6c95b8df PA |
7307 | loc->pspace = sal->pspace; |
7308 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7309 | loc->section = sal->section; |
7310 | ||
0e30163f JK |
7311 | set_breakpoint_location_function (loc, |
7312 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7313 | return loc; |
7314 | } | |
514f746b AR |
7315 | \f |
7316 | ||
7317 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7318 | return 0 otherwise. */ | |
7319 | ||
7320 | static int | |
7321 | bp_loc_is_permanent (struct bp_location *loc) | |
7322 | { | |
7323 | int len; | |
7324 | CORE_ADDR addr; | |
7325 | const gdb_byte *brk; | |
7326 | gdb_byte *target_mem; | |
939c61fa JK |
7327 | struct cleanup *cleanup; |
7328 | int retval = 0; | |
514f746b AR |
7329 | |
7330 | gdb_assert (loc != NULL); | |
7331 | ||
7332 | addr = loc->address; | |
a6d9a66e | 7333 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7334 | |
939c61fa JK |
7335 | /* Software breakpoints unsupported? */ |
7336 | if (brk == NULL) | |
7337 | return 0; | |
7338 | ||
514f746b AR |
7339 | target_mem = alloca (len); |
7340 | ||
939c61fa JK |
7341 | /* Enable the automatic memory restoration from breakpoints while |
7342 | we read the memory. Otherwise we could say about our temporary | |
7343 | breakpoints they are permanent. */ | |
6c95b8df PA |
7344 | cleanup = save_current_space_and_thread (); |
7345 | ||
7346 | switch_to_program_space_and_thread (loc->pspace); | |
7347 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7348 | |
514f746b AR |
7349 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7350 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7351 | retval = 1; |
514f746b | 7352 | |
939c61fa JK |
7353 | do_cleanups (cleanup); |
7354 | ||
7355 | return retval; | |
514f746b AR |
7356 | } |
7357 | ||
7358 | ||
c3f6f71d | 7359 | |
018d34a4 VP |
7360 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7361 | as textual description of the location, and COND_STRING | |
db107f19 | 7362 | as condition expression. */ |
018d34a4 VP |
7363 | |
7364 | static void | |
8cdf0e15 VP |
7365 | create_breakpoint_sal (struct gdbarch *gdbarch, |
7366 | struct symtabs_and_lines sals, char *addr_string, | |
7367 | char *cond_string, | |
7368 | enum bptype type, enum bpdisp disposition, | |
7369 | int thread, int task, int ignore_count, | |
84f4c1fe | 7370 | struct breakpoint_ops *ops, int from_tty, |
56435ebe | 7371 | int enabled, int internal, int display_canonical) |
018d34a4 | 7372 | { |
0d381245 VP |
7373 | struct breakpoint *b = NULL; |
7374 | int i; | |
018d34a4 VP |
7375 | |
7376 | if (type == bp_hardware_breakpoint) | |
7377 | { | |
7378 | int i = hw_breakpoint_used_count (); | |
7379 | int target_resources_ok = | |
d92524f1 | 7380 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7381 | i + 1, 0); |
7382 | if (target_resources_ok == 0) | |
7383 | error (_("No hardware breakpoint support in the target.")); | |
7384 | else if (target_resources_ok < 0) | |
7385 | error (_("Hardware breakpoints used exceeds limit.")); | |
7386 | } | |
7387 | ||
6c95b8df PA |
7388 | gdb_assert (sals.nelts > 0); |
7389 | ||
0d381245 VP |
7390 | for (i = 0; i < sals.nelts; ++i) |
7391 | { | |
7392 | struct symtab_and_line sal = sals.sals[i]; | |
7393 | struct bp_location *loc; | |
7394 | ||
7395 | if (from_tty) | |
5af949e3 UW |
7396 | { |
7397 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7398 | if (!loc_gdbarch) | |
7399 | loc_gdbarch = gdbarch; | |
7400 | ||
7401 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7402 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7403 | } |
0d381245 VP |
7404 | |
7405 | if (i == 0) | |
7406 | { | |
a6d9a66e | 7407 | b = set_raw_breakpoint (gdbarch, sal, type); |
84f4c1fe | 7408 | set_breakpoint_number (internal, b); |
0d381245 | 7409 | b->thread = thread; |
4a306c9a | 7410 | b->task = task; |
018d34a4 | 7411 | |
0d381245 VP |
7412 | b->cond_string = cond_string; |
7413 | b->ignore_count = ignore_count; | |
41447f92 | 7414 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7415 | b->disposition = disposition; |
6c95b8df PA |
7416 | b->pspace = sals.sals[0].pspace; |
7417 | ||
0fb4aa4b PA |
7418 | if (type == bp_static_tracepoint) |
7419 | { | |
7420 | struct static_tracepoint_marker marker; | |
7421 | ||
7422 | if (is_marker_spec (addr_string)) | |
7423 | { | |
7424 | /* We already know the marker exists, otherwise, we | |
7425 | wouldn't see a sal for it. */ | |
7426 | char *p = &addr_string[3]; | |
7427 | char *endp; | |
7428 | char *marker_str; | |
7429 | int i; | |
7430 | ||
e9cafbcc | 7431 | p = skip_spaces (p); |
0fb4aa4b | 7432 | |
e9cafbcc | 7433 | endp = skip_to_space (p); |
0fb4aa4b PA |
7434 | |
7435 | marker_str = savestring (p, endp - p); | |
7436 | b->static_trace_marker_id = marker_str; | |
7437 | ||
3e43a32a MS |
7438 | printf_filtered (_("Probed static tracepoint " |
7439 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7440 | b->static_trace_marker_id); |
7441 | } | |
7442 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7443 | { | |
7444 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
7445 | release_static_tracepoint_marker (&marker); | |
7446 | ||
3e43a32a MS |
7447 | printf_filtered (_("Probed static tracepoint " |
7448 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7449 | b->static_trace_marker_id); |
7450 | } | |
7451 | else | |
3e43a32a MS |
7452 | warning (_("Couldn't determine the static " |
7453 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7454 | } |
7455 | ||
6c95b8df | 7456 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7457 | && (b->type == bp_breakpoint |
7458 | || b->type == bp_hardware_breakpoint)) | |
7459 | b->enable_state = bp_startup_disabled; | |
7460 | ||
0d381245 VP |
7461 | loc = b->loc; |
7462 | } | |
7463 | else | |
018d34a4 | 7464 | { |
39d61571 | 7465 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7466 | } |
7467 | ||
514f746b AR |
7468 | if (bp_loc_is_permanent (loc)) |
7469 | make_breakpoint_permanent (b); | |
7470 | ||
0d381245 VP |
7471 | if (b->cond_string) |
7472 | { | |
7473 | char *arg = b->cond_string; | |
d32a6982 | 7474 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7475 | if (*arg) |
db107f19 | 7476 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7477 | } |
0d381245 | 7478 | } |
018d34a4 | 7479 | |
56435ebe | 7480 | b->display_canonical = display_canonical; |
018d34a4 VP |
7481 | if (addr_string) |
7482 | b->addr_string = addr_string; | |
7483 | else | |
7484 | /* addr_string has to be used or breakpoint_re_set will delete | |
7485 | me. */ | |
5af949e3 UW |
7486 | b->addr_string |
7487 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7488 | |
604133b5 | 7489 | b->ops = ops; |
8d3788bd VP |
7490 | /* Do not mention breakpoints with a negative number, but do |
7491 | notify observers. */ | |
7492 | if (!internal) | |
84f4c1fe | 7493 | mention (b); |
8d3788bd | 7494 | observer_notify_breakpoint_created (b); |
018d34a4 VP |
7495 | } |
7496 | ||
ed0616c6 VP |
7497 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7498 | elements to fill the void space. */ | |
2c0b251b PA |
7499 | static void |
7500 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7501 | { |
7502 | int i = index_to_remove+1; | |
7503 | int last_index = sal->nelts-1; | |
7504 | ||
7505 | for (;i <= last_index; ++i) | |
7506 | sal->sals[i-1] = sal->sals[i]; | |
7507 | ||
7508 | --(sal->nelts); | |
7509 | } | |
7510 | ||
6c95b8df PA |
7511 | /* If appropriate, obtains all sals that correspond to the same file |
7512 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7513 | will want to set a breakpoint at foo.c:line, and not really care | |
7514 | about program spaces. This is done only if SAL does not have | |
7515 | explicit PC and has line and file information. If we got just a | |
7516 | single expanded sal, return the original. | |
ed0616c6 | 7517 | |
6c95b8df PA |
7518 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7519 | which the name of enclosing function is different from SAL. This | |
7520 | makes sure that if we have breakpoint originally set in template | |
7521 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7522 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7523 | |
2c0b251b | 7524 | static struct symtabs_and_lines |
ed0616c6 VP |
7525 | expand_line_sal_maybe (struct symtab_and_line sal) |
7526 | { | |
7527 | struct symtabs_and_lines expanded; | |
7528 | CORE_ADDR original_pc = sal.pc; | |
7529 | char *original_function = NULL; | |
7530 | int found; | |
7531 | int i; | |
6c95b8df | 7532 | struct cleanup *old_chain; |
ed0616c6 VP |
7533 | |
7534 | /* If we have explicit pc, don't expand. | |
7535 | If we have no line number, we can't expand. */ | |
7536 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7537 | { | |
7538 | expanded.nelts = 1; | |
7539 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7540 | expanded.sals[0] = sal; | |
7541 | return expanded; | |
7542 | } | |
7543 | ||
7544 | sal.pc = 0; | |
6c95b8df PA |
7545 | |
7546 | old_chain = save_current_space_and_thread (); | |
7547 | ||
7548 | switch_to_program_space_and_thread (sal.pspace); | |
7549 | ||
ed0616c6 | 7550 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7551 | |
7552 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7553 | expanded = expand_line_sal (sal); |
6c95b8df | 7554 | |
ed0616c6 VP |
7555 | if (expanded.nelts == 1) |
7556 | { | |
3dba1c98 JB |
7557 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7558 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7559 | xfree (expanded.sals); |
7560 | expanded.nelts = 1; | |
7561 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7562 | sal.pc = original_pc; | |
7563 | expanded.sals[0] = sal; | |
3dba1c98 | 7564 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7565 | do_cleanups (old_chain); |
ed0616c6 VP |
7566 | return expanded; |
7567 | } | |
7568 | ||
7569 | if (!sal.explicit_line) | |
7570 | { | |
7571 | CORE_ADDR func_addr, func_end; | |
7572 | for (i = 0; i < expanded.nelts; ++i) | |
7573 | { | |
7574 | CORE_ADDR pc = expanded.sals[i].pc; | |
7575 | char *this_function; | |
6c95b8df PA |
7576 | |
7577 | /* We need to switch threads as well since we're about to | |
7578 | read memory. */ | |
7579 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7580 | ||
ed0616c6 VP |
7581 | if (find_pc_partial_function (pc, &this_function, |
7582 | &func_addr, &func_end)) | |
7583 | { | |
059fb39f PM |
7584 | if (this_function |
7585 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7586 | { |
7587 | remove_sal (&expanded, i); | |
7588 | --i; | |
7589 | } | |
ed0616c6 VP |
7590 | } |
7591 | } | |
7592 | } | |
059acae7 UW |
7593 | |
7594 | /* Skip the function prologue if necessary. */ | |
7595 | for (i = 0; i < expanded.nelts; ++i) | |
7596 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7597 | |
6c95b8df PA |
7598 | do_cleanups (old_chain); |
7599 | ||
ed0616c6 VP |
7600 | if (expanded.nelts <= 1) |
7601 | { | |
4a64f543 MS |
7602 | /* This is un ugly workaround. If we get zero expanded sals |
7603 | then something is really wrong. Fix that by returning the | |
7604 | original sal. */ | |
7605 | ||
ed0616c6 VP |
7606 | xfree (expanded.sals); |
7607 | expanded.nelts = 1; | |
7608 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7609 | sal.pc = original_pc; | |
7610 | expanded.sals[0] = sal; | |
7611 | return expanded; | |
7612 | } | |
7613 | ||
7614 | if (original_pc) | |
7615 | { | |
7616 | found = 0; | |
7617 | for (i = 0; i < expanded.nelts; ++i) | |
7618 | if (expanded.sals[i].pc == original_pc) | |
7619 | { | |
7620 | found = 1; | |
7621 | break; | |
7622 | } | |
7623 | gdb_assert (found); | |
7624 | } | |
7625 | ||
7626 | return expanded; | |
7627 | } | |
7628 | ||
018d34a4 VP |
7629 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7630 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7631 | value. COND_STRING, if not NULL, specified the condition to be | |
7632 | used for all breakpoints. Essentially the only case where | |
7633 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7634 | function. In that case, it's still not possible to specify | |
7635 | separate conditions for different overloaded functions, so | |
7636 | we take just a single condition string. | |
7637 | ||
c3f6f71d | 7638 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7639 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7640 | array contents). If the function fails (error() is called), the |
7641 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7642 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7643 | |
7644 | static void | |
8cdf0e15 | 7645 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7646 | struct symtabs_and_lines sals, |
7647 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7648 | char *cond_string, |
7649 | enum bptype type, enum bpdisp disposition, | |
7650 | int thread, int task, int ignore_count, | |
7651 | struct breakpoint_ops *ops, int from_tty, | |
84f4c1fe | 7652 | int enabled, int internal) |
c906108c | 7653 | { |
018d34a4 | 7654 | int i; |
cc59ec59 | 7655 | |
018d34a4 | 7656 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7657 | { |
ed0616c6 VP |
7658 | struct symtabs_and_lines expanded = |
7659 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7660 | |
7efd8fc2 | 7661 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7662 | cond_string, type, disposition, |
84f4c1fe | 7663 | thread, task, ignore_count, ops, |
56435ebe TT |
7664 | from_tty, enabled, internal, |
7665 | canonical->special_display); | |
c3f6f71d | 7666 | } |
c3f6f71d | 7667 | } |
c906108c | 7668 | |
9998af43 | 7669 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7670 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7671 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7672 | address strings. ADDRESS points to the end of the SAL. |
7673 | ||
7674 | The array and the line spec strings are allocated on the heap, it is | |
7675 | the caller's responsibility to free them. */ | |
c906108c | 7676 | |
b9362cc7 | 7677 | static void |
c3f6f71d JM |
7678 | parse_breakpoint_sals (char **address, |
7679 | struct symtabs_and_lines *sals, | |
58438ac1 | 7680 | struct linespec_result *canonical) |
c3f6f71d JM |
7681 | { |
7682 | char *addr_start = *address; | |
cc59ec59 | 7683 | |
c3f6f71d | 7684 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7685 | breakpoint. */ |
c3f6f71d JM |
7686 | if ((*address) == NULL |
7687 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7688 | { |
7689 | if (default_breakpoint_valid) | |
7690 | { | |
c3f6f71d | 7691 | struct symtab_and_line sal; |
cc59ec59 | 7692 | |
4a64f543 | 7693 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7694 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7695 | xmalloc (sizeof (struct symtab_and_line)); |
7696 | sal.pc = default_breakpoint_address; | |
7697 | sal.line = default_breakpoint_line; | |
7698 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7699 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7700 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7701 | |
4a64f543 MS |
7702 | /* "break" without arguments is equivalent to "break *PC" |
7703 | where PC is the default_breakpoint_address. So make sure | |
7704 | to set sal.explicit_pc to prevent GDB from trying to | |
7705 | expand the list of sals to include all other instances | |
7706 | with the same symtab and line. */ | |
00903456 JK |
7707 | sal.explicit_pc = 1; |
7708 | ||
c3f6f71d JM |
7709 | sals->sals[0] = sal; |
7710 | sals->nelts = 1; | |
c906108c SS |
7711 | } |
7712 | else | |
8a3fe4f8 | 7713 | error (_("No default breakpoint address now.")); |
c906108c SS |
7714 | } |
7715 | else | |
7716 | { | |
c906108c | 7717 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7718 | current_source_symtab (which is decode_line_1's default). |
7719 | This should produce the results we want almost all of the | |
7720 | time while leaving default_breakpoint_* alone. | |
7721 | ||
1aeae86e AF |
7722 | ObjC: However, don't match an Objective-C method name which |
7723 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7724 | |
c214a6fd | 7725 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7726 | |
c906108c | 7727 | if (default_breakpoint_valid |
0378c332 | 7728 | && (!cursal.symtab |
1aeae86e AF |
7729 | || ((strchr ("+-", (*address)[0]) != NULL) |
7730 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7731 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
58438ac1 | 7732 | default_breakpoint_line, canonical); |
c906108c | 7733 | else |
0101ce28 | 7734 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
58438ac1 | 7735 | canonical); |
c906108c | 7736 | } |
4a64f543 | 7737 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 | 7738 | if (sals->nelts > 0 && canonical->canonical == NULL) |
38a714bb | 7739 | canonical->canonical = xcalloc (sals->nelts, sizeof (char *)); |
c3f6f71d | 7740 | if (addr_start != (*address)) |
c906108c | 7741 | { |
c3f6f71d | 7742 | int i; |
cc59ec59 | 7743 | |
c3f6f71d | 7744 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7745 | { |
4a64f543 | 7746 | /* Add the string if not present. */ |
7efd8fc2 TT |
7747 | if (canonical->canonical[i] == NULL) |
7748 | canonical->canonical[i] = savestring (addr_start, | |
7749 | (*address) - addr_start); | |
c906108c SS |
7750 | } |
7751 | } | |
c3f6f71d | 7752 | } |
c906108c | 7753 | |
c906108c | 7754 | |
c3f6f71d | 7755 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7756 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7757 | |
b9362cc7 | 7758 | static void |
23e7acfb | 7759 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7760 | { |
7761 | int i; | |
cc59ec59 | 7762 | |
c3f6f71d | 7763 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7764 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7765 | } |
7766 | ||
7a697b8d SS |
7767 | /* Fast tracepoints may have restrictions on valid locations. For |
7768 | instance, a fast tracepoint using a jump instead of a trap will | |
7769 | likely have to overwrite more bytes than a trap would, and so can | |
7770 | only be placed where the instruction is longer than the jump, or a | |
7771 | multi-instruction sequence does not have a jump into the middle of | |
7772 | it, etc. */ | |
7773 | ||
7774 | static void | |
7775 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7776 | struct symtabs_and_lines *sals) | |
7777 | { | |
7778 | int i, rslt; | |
7779 | struct symtab_and_line *sal; | |
7780 | char *msg; | |
7781 | struct cleanup *old_chain; | |
7782 | ||
7783 | for (i = 0; i < sals->nelts; i++) | |
7784 | { | |
7785 | sal = &sals->sals[i]; | |
7786 | ||
7787 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7788 | NULL, &msg); | |
7789 | old_chain = make_cleanup (xfree, msg); | |
7790 | ||
7791 | if (!rslt) | |
7792 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7793 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7794 | ||
7795 | do_cleanups (old_chain); | |
7796 | } | |
7797 | } | |
7798 | ||
018d34a4 VP |
7799 | /* Given TOK, a string specification of condition and thread, as |
7800 | accepted by the 'break' command, extract the condition | |
7801 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7802 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7803 | If no condition is found, *COND_STRING is set to NULL. |
7804 | If no thread is found, *THREAD is set to -1. */ | |
7805 | static void | |
7806 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7807 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7808 | { |
7809 | *cond_string = NULL; | |
7810 | *thread = -1; | |
7811 | while (tok && *tok) | |
7812 | { | |
7813 | char *end_tok; | |
7814 | int toklen; | |
7815 | char *cond_start = NULL; | |
7816 | char *cond_end = NULL; | |
cc59ec59 | 7817 | |
e9cafbcc | 7818 | tok = skip_spaces (tok); |
018d34a4 | 7819 | |
e9cafbcc | 7820 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7821 | |
7822 | toklen = end_tok - tok; | |
7823 | ||
7824 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7825 | { | |
f7545552 TT |
7826 | struct expression *expr; |
7827 | ||
018d34a4 | 7828 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7829 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7830 | xfree (expr); | |
018d34a4 VP |
7831 | cond_end = tok; |
7832 | *cond_string = savestring (cond_start, | |
7833 | cond_end - cond_start); | |
7834 | } | |
7835 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7836 | { | |
7837 | char *tmptok; | |
7838 | ||
7839 | tok = end_tok + 1; | |
7840 | tmptok = tok; | |
7841 | *thread = strtol (tok, &tok, 0); | |
7842 | if (tok == tmptok) | |
7843 | error (_("Junk after thread keyword.")); | |
7844 | if (!valid_thread_id (*thread)) | |
7845 | error (_("Unknown thread %d."), *thread); | |
7846 | } | |
4a306c9a JB |
7847 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7848 | { | |
7849 | char *tmptok; | |
7850 | ||
7851 | tok = end_tok + 1; | |
7852 | tmptok = tok; | |
7853 | *task = strtol (tok, &tok, 0); | |
7854 | if (tok == tmptok) | |
7855 | error (_("Junk after task keyword.")); | |
7856 | if (!valid_task_id (*task)) | |
b6199126 | 7857 | error (_("Unknown task %d."), *task); |
4a306c9a | 7858 | } |
018d34a4 VP |
7859 | else |
7860 | error (_("Junk at end of arguments.")); | |
7861 | } | |
7862 | } | |
7863 | ||
0fb4aa4b PA |
7864 | /* Decode a static tracepoint marker spec. */ |
7865 | ||
7866 | static struct symtabs_and_lines | |
7867 | decode_static_tracepoint_spec (char **arg_p) | |
7868 | { | |
7869 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7870 | struct symtabs_and_lines sals; | |
7871 | struct symtab_and_line sal; | |
7872 | struct symbol *sym; | |
7873 | struct cleanup *old_chain; | |
7874 | char *p = &(*arg_p)[3]; | |
7875 | char *endp; | |
7876 | char *marker_str; | |
7877 | int i; | |
7878 | ||
e9cafbcc | 7879 | p = skip_spaces (p); |
0fb4aa4b | 7880 | |
e9cafbcc | 7881 | endp = skip_to_space (p); |
0fb4aa4b PA |
7882 | |
7883 | marker_str = savestring (p, endp - p); | |
7884 | old_chain = make_cleanup (xfree, marker_str); | |
7885 | ||
7886 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7887 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7888 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7889 | ||
7890 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7891 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7892 | ||
7893 | for (i = 0; i < sals.nelts; i++) | |
7894 | { | |
7895 | struct static_tracepoint_marker *marker; | |
7896 | ||
7897 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7898 | ||
7899 | init_sal (&sals.sals[i]); | |
7900 | ||
7901 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7902 | sals.sals[i].pc = marker->address; | |
7903 | ||
7904 | release_static_tracepoint_marker (marker); | |
7905 | } | |
7906 | ||
7907 | do_cleanups (old_chain); | |
7908 | ||
7909 | *arg_p = endp; | |
7910 | return sals; | |
7911 | } | |
7912 | ||
fd9b8c24 PA |
7913 | /* Set a breakpoint. This function is shared between CLI and MI |
7914 | functions for setting a breakpoint. This function has two major | |
7915 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7916 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7917 | breakpoint location, address and thread. Otherwise, ARG is just |
7918 | the location of breakpoint, with condition and thread specified by | |
7919 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7920 | the breakpoint number will be allocated from the internal | |
7921 | breakpoint count. Returns true if any breakpoint was created; | |
7922 | false otherwise. */ | |
0101ce28 | 7923 | |
8cdf0e15 VP |
7924 | int |
7925 | create_breakpoint (struct gdbarch *gdbarch, | |
7926 | char *arg, char *cond_string, int thread, | |
7927 | int parse_condition_and_thread, | |
0fb4aa4b | 7928 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7929 | int ignore_count, |
7930 | enum auto_boolean pending_break_support, | |
7931 | struct breakpoint_ops *ops, | |
84f4c1fe | 7932 | int from_tty, int enabled, int internal) |
c3f6f71d | 7933 | { |
b78a6381 | 7934 | volatile struct gdb_exception e; |
c3f6f71d | 7935 | struct symtabs_and_lines sals; |
0101ce28 | 7936 | struct symtab_and_line pending_sal; |
0101ce28 | 7937 | char *copy_arg; |
c3f6f71d | 7938 | char *addr_start = arg; |
7efd8fc2 | 7939 | struct linespec_result canonical; |
c3f6f71d | 7940 | struct cleanup *old_chain; |
80c99de1 | 7941 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 7942 | int i; |
0101ce28 | 7943 | int pending = 0; |
4a306c9a | 7944 | int task = 0; |
86b17b60 | 7945 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7946 | |
c3f6f71d JM |
7947 | sals.sals = NULL; |
7948 | sals.nelts = 0; | |
7efd8fc2 | 7949 | init_linespec_result (&canonical); |
c3f6f71d | 7950 | |
0fb4aa4b PA |
7951 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7952 | { | |
7953 | int i; | |
7954 | ||
7955 | sals = decode_static_tracepoint_spec (&arg); | |
7956 | ||
7957 | copy_arg = savestring (addr_start, arg - addr_start); | |
38a714bb | 7958 | canonical.canonical = xcalloc (sals.nelts, sizeof (char *)); |
0fb4aa4b | 7959 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7960 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7961 | goto done; |
7962 | } | |
7963 | ||
b78a6381 TT |
7964 | TRY_CATCH (e, RETURN_MASK_ALL) |
7965 | { | |
58438ac1 | 7966 | parse_breakpoint_sals (&arg, &sals, &canonical); |
b78a6381 | 7967 | } |
0101ce28 JJ |
7968 | |
7969 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7970 | switch (e.reason) |
0101ce28 | 7971 | { |
05ff989b | 7972 | case RETURN_QUIT: |
98deb0da | 7973 | throw_exception (e); |
05ff989b AC |
7974 | case RETURN_ERROR: |
7975 | switch (e.error) | |
0101ce28 | 7976 | { |
05ff989b | 7977 | case NOT_FOUND_ERROR: |
0101ce28 | 7978 | |
05ff989b AC |
7979 | /* If pending breakpoint support is turned off, throw |
7980 | error. */ | |
fa8d40ab JJ |
7981 | |
7982 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7983 | throw_exception (e); |
7984 | ||
7985 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7986 | |
05ff989b AC |
7987 | /* If pending breakpoint support is auto query and the user |
7988 | selects no, then simply return the error code. */ | |
059fb39f | 7989 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7990 | && !nquery (_("Make breakpoint pending on " |
7991 | "future shared library load? "))) | |
fd9b8c24 | 7992 | return 0; |
fa8d40ab | 7993 | |
05ff989b AC |
7994 | /* At this point, either the user was queried about setting |
7995 | a pending breakpoint and selected yes, or pending | |
7996 | breakpoint behavior is on and thus a pending breakpoint | |
7997 | is defaulted on behalf of the user. */ | |
0101ce28 | 7998 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 7999 | canonical.canonical = ©_arg; |
0101ce28 JJ |
8000 | sals.nelts = 1; |
8001 | sals.sals = &pending_sal; | |
8002 | pending_sal.pc = 0; | |
8003 | pending = 1; | |
05ff989b AC |
8004 | break; |
8005 | default: | |
98deb0da | 8006 | throw_exception (e); |
0101ce28 | 8007 | } |
2abae994 | 8008 | break; |
05ff989b AC |
8009 | default: |
8010 | if (!sals.nelts) | |
fd9b8c24 | 8011 | return 0; |
0101ce28 | 8012 | } |
c3f6f71d | 8013 | |
0fb4aa4b PA |
8014 | done: |
8015 | ||
4a64f543 | 8016 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
8017 | old_chain = make_cleanup (null_cleanup, 0); |
8018 | ||
0101ce28 JJ |
8019 | if (!pending) |
8020 | { | |
8021 | /* Make sure that all storage allocated to SALS gets freed. */ | |
8022 | make_cleanup (xfree, sals.sals); | |
8023 | ||
7efd8fc2 TT |
8024 | /* Cleanup the canonical array but not its contents. */ |
8025 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 8026 | } |
c3f6f71d | 8027 | |
c3f6f71d JM |
8028 | /* ----------------------------- SNIP ----------------------------- |
8029 | Anything added to the cleanup chain beyond this point is assumed | |
8030 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
8031 | then the memory is not reclaimed. */ |
8032 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 8033 | |
7efd8fc2 | 8034 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 8035 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
8036 | for (i = 0; i < sals.nelts; i++) |
8037 | { | |
7efd8fc2 TT |
8038 | if (canonical.canonical[i] != NULL) |
8039 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
8040 | } |
8041 | ||
8042 | /* Resolve all line numbers to PC's and verify that the addresses | |
8043 | are ok for the target. */ | |
0101ce28 | 8044 | if (!pending) |
23e7acfb | 8045 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 8046 | |
7a697b8d SS |
8047 | /* Fast tracepoints may have additional restrictions on location. */ |
8048 | if (type_wanted == bp_fast_tracepoint) | |
8049 | check_fast_tracepoint_sals (gdbarch, &sals); | |
8050 | ||
c3f6f71d JM |
8051 | /* Verify that condition can be parsed, before setting any |
8052 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 8053 | breakpoint. */ |
0101ce28 | 8054 | if (!pending) |
c3f6f71d | 8055 | { |
2f069f6f | 8056 | if (parse_condition_and_thread) |
72b2ff0e VP |
8057 | { |
8058 | /* Here we only parse 'arg' to separate condition | |
8059 | from thread number, so parsing in context of first | |
8060 | sal is OK. When setting the breakpoint we'll | |
8061 | re-parse it in context of each sal. */ | |
8062 | cond_string = NULL; | |
8063 | thread = -1; | |
4a306c9a JB |
8064 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
8065 | &thread, &task); | |
72b2ff0e VP |
8066 | if (cond_string) |
8067 | make_cleanup (xfree, cond_string); | |
8068 | } | |
2f069f6f | 8069 | else |
72b2ff0e VP |
8070 | { |
8071 | /* Create a private copy of condition string. */ | |
8072 | if (cond_string) | |
8073 | { | |
8074 | cond_string = xstrdup (cond_string); | |
8075 | make_cleanup (xfree, cond_string); | |
8076 | } | |
8077 | } | |
0fb4aa4b PA |
8078 | |
8079 | /* If the user is creating a static tracepoint by marker id | |
8080 | (strace -m MARKER_ID), then store the sals index, so that | |
8081 | breakpoint_re_set can try to match up which of the newly | |
8082 | found markers corresponds to this one, and, don't try to | |
8083 | expand multiple locations for each sal, given than SALS | |
8084 | already should contain all sals for MARKER_ID. */ | |
8085 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 8086 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
8087 | { |
8088 | int i; | |
8089 | ||
8090 | for (i = 0; i < sals.nelts; ++i) | |
8091 | { | |
8092 | struct symtabs_and_lines expanded; | |
8093 | struct breakpoint *tp; | |
8094 | struct cleanup *old_chain; | |
8095 | ||
8096 | expanded.nelts = 1; | |
8097 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
8098 | expanded.sals[0] = sals.sals[i]; | |
8099 | old_chain = make_cleanup (xfree, expanded.sals); | |
8100 | ||
7efd8fc2 | 8101 | create_breakpoint_sal (gdbarch, expanded, canonical.canonical[i], |
0fb4aa4b PA |
8102 | cond_string, type_wanted, |
8103 | tempflag ? disp_del : disp_donttouch, | |
8104 | thread, task, ignore_count, ops, | |
56435ebe TT |
8105 | from_tty, enabled, internal, |
8106 | canonical.special_display); | |
0fb4aa4b PA |
8107 | |
8108 | do_cleanups (old_chain); | |
8109 | ||
8110 | /* Get the tracepoint we just created. */ | |
84f4c1fe PM |
8111 | if (internal) |
8112 | tp = get_breakpoint (internal_breakpoint_number); | |
8113 | else | |
8114 | tp = get_breakpoint (breakpoint_count); | |
0fb4aa4b PA |
8115 | gdb_assert (tp != NULL); |
8116 | ||
8117 | /* Given that its possible to have multiple markers with | |
8118 | the same string id, if the user is creating a static | |
8119 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
8120 | store the sals index, so that breakpoint_re_set can | |
8121 | try to match up which of the newly found markers | |
8122 | corresponds to this one */ | |
8123 | tp->static_trace_marker_id_idx = i; | |
8124 | } | |
8125 | } | |
8126 | else | |
7efd8fc2 | 8127 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
8128 | type_wanted, |
8129 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 8130 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 8131 | enabled, internal); |
c906108c | 8132 | } |
0101ce28 JJ |
8133 | else |
8134 | { | |
0101ce28 JJ |
8135 | struct breakpoint *b; |
8136 | ||
0101ce28 JJ |
8137 | make_cleanup (xfree, copy_arg); |
8138 | ||
a6d9a66e | 8139 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
84f4c1fe | 8140 | set_breakpoint_number (internal, b); |
72b2ff0e | 8141 | b->thread = -1; |
7efd8fc2 | 8142 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 8143 | b->cond_string = NULL; |
0101ce28 | 8144 | b->ignore_count = ignore_count; |
0101ce28 | 8145 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8146 | b->condition_not_parsed = 1; |
604133b5 | 8147 | b->ops = ops; |
41447f92 | 8148 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 8149 | b->pspace = current_program_space; |
84f4c1fe | 8150 | b->py_bp_object = NULL; |
74960c60 | 8151 | |
6c95b8df | 8152 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8153 | && (b->type == bp_breakpoint |
8154 | || b->type == bp_hardware_breakpoint)) | |
8155 | b->enable_state = bp_startup_disabled; | |
8156 | ||
8d3788bd | 8157 | if (!internal) |
84f4c1fe PM |
8158 | /* Do not mention breakpoints with a negative number, |
8159 | but do notify observers. */ | |
8d3788bd VP |
8160 | mention (b); |
8161 | observer_notify_breakpoint_created (b); | |
0101ce28 JJ |
8162 | } |
8163 | ||
c3f6f71d | 8164 | if (sals.nelts > 1) |
95a42b64 | 8165 | { |
3e43a32a MS |
8166 | warning (_("Multiple breakpoints were set.\nUse the " |
8167 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8168 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8169 | } |
8170 | ||
80c99de1 PA |
8171 | /* That's it. Discard the cleanups for data inserted into the |
8172 | breakpoint. */ | |
8173 | discard_cleanups (bkpt_chain); | |
8174 | /* But cleanup everything else. */ | |
c3f6f71d | 8175 | do_cleanups (old_chain); |
217dc9e2 | 8176 | |
80c99de1 | 8177 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8178 | update_global_location_list (1); |
fd9b8c24 PA |
8179 | |
8180 | return 1; | |
c3f6f71d | 8181 | } |
c906108c | 8182 | |
72b2ff0e VP |
8183 | /* Set a breakpoint. |
8184 | ARG is a string describing breakpoint address, | |
8185 | condition, and thread. | |
8186 | FLAG specifies if a breakpoint is hardware on, | |
8187 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8188 | and BP_TEMPFLAG. */ | |
8189 | ||
98deb0da | 8190 | static void |
72b2ff0e | 8191 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8192 | { |
72b2ff0e | 8193 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8194 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8195 | ? bp_hardware_breakpoint | |
8196 | : bp_breakpoint); | |
c3f6f71d | 8197 | |
8cdf0e15 VP |
8198 | create_breakpoint (get_current_arch (), |
8199 | arg, | |
8200 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8201 | tempflag, type_wanted, |
8cdf0e15 VP |
8202 | 0 /* Ignore count */, |
8203 | pending_break_support, | |
8204 | NULL /* breakpoint_ops */, | |
8205 | from_tty, | |
84f4c1fe PM |
8206 | 1 /* enabled */, |
8207 | 0 /* internal */); | |
c906108c SS |
8208 | } |
8209 | ||
72b2ff0e | 8210 | |
c906108c SS |
8211 | /* Helper function for break_command_1 and disassemble_command. */ |
8212 | ||
8213 | void | |
fba45db2 | 8214 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8215 | { |
8216 | CORE_ADDR pc; | |
8217 | ||
8218 | if (sal->pc == 0 && sal->symtab != NULL) | |
8219 | { | |
8220 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8221 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8222 | sal->line, sal->symtab->filename); |
8223 | sal->pc = pc; | |
6a048695 | 8224 | |
4a64f543 MS |
8225 | /* If this SAL corresponds to a breakpoint inserted using a line |
8226 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8227 | if (sal->explicit_line) |
059acae7 | 8228 | skip_prologue_sal (sal); |
c906108c SS |
8229 | } |
8230 | ||
8231 | if (sal->section == 0 && sal->symtab != NULL) | |
8232 | { | |
8233 | struct blockvector *bv; | |
c5aa993b JM |
8234 | struct block *b; |
8235 | struct symbol *sym; | |
c906108c | 8236 | |
801e3a5b | 8237 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8238 | if (bv != NULL) |
8239 | { | |
7f0df278 | 8240 | sym = block_linkage_function (b); |
c906108c SS |
8241 | if (sym != NULL) |
8242 | { | |
8243 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8244 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8245 | } |
8246 | else | |
8247 | { | |
4a64f543 MS |
8248 | /* It really is worthwhile to have the section, so we'll |
8249 | just have to look harder. This case can be executed | |
8250 | if we have line numbers but no functions (as can | |
8251 | happen in assembly source). */ | |
c906108c | 8252 | |
c5aa993b | 8253 | struct minimal_symbol *msym; |
6c95b8df PA |
8254 | struct cleanup *old_chain = save_current_space_and_thread (); |
8255 | ||
8256 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8257 | |
8258 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8259 | if (msym) | |
714835d5 | 8260 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8261 | |
8262 | do_cleanups (old_chain); | |
c906108c SS |
8263 | } |
8264 | } | |
8265 | } | |
8266 | } | |
8267 | ||
8268 | void | |
fba45db2 | 8269 | break_command (char *arg, int from_tty) |
c906108c | 8270 | { |
db107f19 | 8271 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8272 | } |
8273 | ||
c906108c | 8274 | void |
fba45db2 | 8275 | tbreak_command (char *arg, int from_tty) |
c906108c | 8276 | { |
db107f19 | 8277 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8278 | } |
8279 | ||
c906108c | 8280 | static void |
fba45db2 | 8281 | hbreak_command (char *arg, int from_tty) |
c906108c | 8282 | { |
db107f19 | 8283 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8284 | } |
8285 | ||
8286 | static void | |
fba45db2 | 8287 | thbreak_command (char *arg, int from_tty) |
c906108c | 8288 | { |
db107f19 | 8289 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8290 | } |
8291 | ||
8292 | static void | |
fba45db2 | 8293 | stop_command (char *arg, int from_tty) |
c906108c | 8294 | { |
a3f17187 | 8295 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8296 | Usage: stop in <function | address>\n\ |
a3f17187 | 8297 | stop at <line>\n")); |
c906108c SS |
8298 | } |
8299 | ||
8300 | static void | |
fba45db2 | 8301 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8302 | { |
8303 | int badInput = 0; | |
8304 | ||
c5aa993b | 8305 | if (arg == (char *) NULL) |
c906108c SS |
8306 | badInput = 1; |
8307 | else if (*arg != '*') | |
8308 | { | |
8309 | char *argptr = arg; | |
8310 | int hasColon = 0; | |
8311 | ||
4a64f543 | 8312 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8313 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8314 | function/method name. */ |
c906108c | 8315 | while (*argptr && !hasColon) |
c5aa993b JM |
8316 | { |
8317 | hasColon = (*argptr == ':'); | |
8318 | argptr++; | |
8319 | } | |
c906108c SS |
8320 | |
8321 | if (hasColon) | |
c5aa993b | 8322 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8323 | else |
c5aa993b | 8324 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8325 | } |
8326 | ||
8327 | if (badInput) | |
a3f17187 | 8328 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8329 | else |
db107f19 | 8330 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8331 | } |
8332 | ||
8333 | static void | |
fba45db2 | 8334 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8335 | { |
8336 | int badInput = 0; | |
8337 | ||
c5aa993b | 8338 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8339 | badInput = 1; |
8340 | else | |
8341 | { | |
8342 | char *argptr = arg; | |
8343 | int hasColon = 0; | |
8344 | ||
4a64f543 MS |
8345 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8346 | it is probably a line number. */ | |
c906108c | 8347 | while (*argptr && !hasColon) |
c5aa993b JM |
8348 | { |
8349 | hasColon = (*argptr == ':'); | |
8350 | argptr++; | |
8351 | } | |
c906108c SS |
8352 | |
8353 | if (hasColon) | |
c5aa993b | 8354 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8355 | else |
c5aa993b | 8356 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8357 | } |
8358 | ||
8359 | if (badInput) | |
a3f17187 | 8360 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8361 | else |
db107f19 | 8362 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8363 | } |
8364 | ||
f1310107 TJB |
8365 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8366 | ranged breakpoints. */ | |
8367 | ||
8368 | static int | |
8369 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8370 | struct address_space *aspace, | |
8371 | CORE_ADDR bp_addr) | |
8372 | { | |
8373 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, | |
8374 | bl->length, aspace, bp_addr); | |
8375 | } | |
8376 | ||
8377 | /* Implement the "resources_needed" breakpoint_ops method for | |
8378 | ranged breakpoints. */ | |
8379 | ||
8380 | static int | |
8381 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8382 | { | |
8383 | return target_ranged_break_num_registers (); | |
8384 | } | |
8385 | ||
8386 | /* Implement the "print_it" breakpoint_ops method for | |
8387 | ranged breakpoints. */ | |
8388 | ||
8389 | static enum print_stop_action | |
8390 | print_it_ranged_breakpoint (struct breakpoint *b) | |
8391 | { | |
8392 | struct bp_location *bl = b->loc; | |
8393 | ||
8394 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8395 | ||
8396 | /* Ranged breakpoints have only one location. */ | |
8397 | gdb_assert (bl && bl->next == NULL); | |
8398 | ||
8399 | annotate_breakpoint (b->number); | |
8400 | if (b->disposition == disp_del) | |
8401 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8402 | else | |
8403 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8404 | if (ui_out_is_mi_like_p (uiout)) | |
8405 | { | |
8406 | ui_out_field_string (uiout, "reason", | |
8407 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8408 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8409 | } | |
8410 | ui_out_field_int (uiout, "bkptno", b->number); | |
8411 | ui_out_text (uiout, ", "); | |
8412 | ||
8413 | return PRINT_SRC_AND_LOC; | |
8414 | } | |
8415 | ||
8416 | /* Implement the "print_one" breakpoint_ops method for | |
8417 | ranged breakpoints. */ | |
8418 | ||
8419 | static void | |
8420 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8421 | struct bp_location **last_loc) | |
8422 | { | |
8423 | struct bp_location *bl = b->loc; | |
8424 | struct value_print_options opts; | |
8425 | ||
8426 | /* Ranged breakpoints have only one location. */ | |
8427 | gdb_assert (bl && bl->next == NULL); | |
8428 | ||
8429 | get_user_print_options (&opts); | |
8430 | ||
8431 | if (opts.addressprint) | |
8432 | /* We don't print the address range here, it will be printed later | |
8433 | by print_one_detail_ranged_breakpoint. */ | |
8434 | ui_out_field_skip (uiout, "addr"); | |
8435 | annotate_field (5); | |
8436 | print_breakpoint_location (b, bl); | |
8437 | *last_loc = bl; | |
8438 | } | |
8439 | ||
8440 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8441 | ranged breakpoints. */ | |
8442 | ||
8443 | static void | |
8444 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8445 | struct ui_out *uiout) | |
8446 | { | |
8447 | CORE_ADDR address_start, address_end; | |
8448 | struct bp_location *bl = b->loc; | |
8449 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8450 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8451 | ||
8452 | gdb_assert (bl); | |
8453 | ||
8454 | address_start = bl->address; | |
8455 | address_end = address_start + bl->length - 1; | |
8456 | ||
8457 | ui_out_text (uiout, "\taddress range: "); | |
8458 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8459 | print_core_address (bl->gdbarch, address_start), | |
8460 | print_core_address (bl->gdbarch, address_end)); | |
8461 | ui_out_field_stream (uiout, "addr", stb); | |
8462 | ui_out_text (uiout, "\n"); | |
8463 | ||
8464 | do_cleanups (cleanup); | |
8465 | } | |
8466 | ||
8467 | /* Implement the "print_mention" breakpoint_ops method for | |
8468 | ranged breakpoints. */ | |
8469 | ||
8470 | static void | |
8471 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8472 | { | |
8473 | struct bp_location *bl = b->loc; | |
8474 | ||
8475 | gdb_assert (bl); | |
8476 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8477 | ||
8478 | if (ui_out_is_mi_like_p (uiout)) | |
8479 | return; | |
8480 | ||
8481 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8482 | b->number, paddress (bl->gdbarch, bl->address), | |
8483 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8484 | } | |
8485 | ||
8486 | /* Implement the "print_recreate" breakpoint_ops method for | |
8487 | ranged breakpoints. */ | |
8488 | ||
8489 | static void | |
8490 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8491 | { | |
8492 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8493 | b->addr_string_range_end); | |
8494 | } | |
8495 | ||
8496 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8497 | ||
8498 | static struct breakpoint_ops ranged_breakpoint_ops = | |
8499 | { | |
8500 | NULL, /* insert */ | |
8501 | NULL, /* remove */ | |
8502 | breakpoint_hit_ranged_breakpoint, | |
8503 | resources_needed_ranged_breakpoint, | |
9c06b0b4 | 8504 | NULL, /* works_in_software_mode */ |
f1310107 TJB |
8505 | print_it_ranged_breakpoint, |
8506 | print_one_ranged_breakpoint, | |
8507 | print_one_detail_ranged_breakpoint, | |
8508 | print_mention_ranged_breakpoint, | |
8509 | print_recreate_ranged_breakpoint | |
8510 | }; | |
8511 | ||
8512 | /* Find the address where the end of the breakpoint range should be | |
8513 | placed, given the SAL of the end of the range. This is so that if | |
8514 | the user provides a line number, the end of the range is set to the | |
8515 | last instruction of the given line. */ | |
8516 | ||
8517 | static CORE_ADDR | |
8518 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8519 | { | |
8520 | CORE_ADDR end; | |
8521 | ||
8522 | /* If the user provided a PC value, use it. Otherwise, | |
8523 | find the address of the end of the given location. */ | |
8524 | if (sal.explicit_pc) | |
8525 | end = sal.pc; | |
8526 | else | |
8527 | { | |
8528 | int ret; | |
8529 | CORE_ADDR start; | |
8530 | ||
8531 | ret = find_line_pc_range (sal, &start, &end); | |
8532 | if (!ret) | |
8533 | error (_("Could not find location of the end of the range.")); | |
8534 | ||
8535 | /* find_line_pc_range returns the start of the next line. */ | |
8536 | end--; | |
8537 | } | |
8538 | ||
8539 | return end; | |
8540 | } | |
8541 | ||
8542 | /* Implement the "break-range" CLI command. */ | |
8543 | ||
8544 | static void | |
8545 | break_range_command (char *arg, int from_tty) | |
8546 | { | |
8547 | char *arg_start, *addr_string_start, *addr_string_end; | |
8548 | struct linespec_result canonical_start, canonical_end; | |
8549 | int bp_count, can_use_bp, length; | |
8550 | CORE_ADDR end; | |
8551 | struct breakpoint *b; | |
8552 | struct symtab_and_line sal_start, sal_end; | |
8553 | struct symtabs_and_lines sals_start, sals_end; | |
8554 | struct cleanup *cleanup_bkpt; | |
8555 | ||
8556 | /* We don't support software ranged breakpoints. */ | |
8557 | if (target_ranged_break_num_registers () < 0) | |
8558 | error (_("This target does not support hardware ranged breakpoints.")); | |
8559 | ||
8560 | bp_count = hw_breakpoint_used_count (); | |
8561 | bp_count += target_ranged_break_num_registers (); | |
8562 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8563 | bp_count, 0); | |
8564 | if (can_use_bp < 0) | |
8565 | error (_("Hardware breakpoints used exceeds limit.")); | |
8566 | ||
8567 | if (arg == NULL || arg[0] == '\0') | |
8568 | error(_("No address range specified.")); | |
8569 | ||
8570 | sals_start.sals = NULL; | |
8571 | sals_start.nelts = 0; | |
8572 | init_linespec_result (&canonical_start); | |
8573 | ||
8574 | while (*arg == ' ' || *arg == '\t') | |
8575 | arg++; | |
8576 | ||
58438ac1 | 8577 | parse_breakpoint_sals (&arg, &sals_start, &canonical_start); |
f1310107 TJB |
8578 | |
8579 | sal_start = sals_start.sals[0]; | |
8580 | addr_string_start = canonical_start.canonical[0]; | |
8581 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); | |
8582 | xfree (sals_start.sals); | |
8583 | xfree (canonical_start.canonical); | |
8584 | ||
8585 | if (arg[0] != ',') | |
8586 | error (_("Too few arguments.")); | |
8587 | else if (sals_start.nelts == 0) | |
8588 | error (_("Could not find location of the beginning of the range.")); | |
8589 | else if (sals_start.nelts != 1) | |
8590 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8591 | ||
8592 | resolve_sal_pc (&sal_start); | |
8593 | ||
8594 | arg++; /* Skip the comma. */ | |
8595 | while (*arg == ' ' || *arg == '\t') | |
8596 | arg++; | |
8597 | ||
8598 | /* Parse the end location. */ | |
8599 | ||
8600 | sals_end.sals = NULL; | |
8601 | sals_end.nelts = 0; | |
8602 | init_linespec_result (&canonical_end); | |
8603 | arg_start = arg; | |
8604 | ||
423f41a5 | 8605 | /* We call decode_line_1 directly here instead of using |
f1310107 TJB |
8606 | parse_breakpoint_sals because we need to specify the start location's |
8607 | symtab and line as the default symtab and line for the end of the | |
8608 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8609 | where +14 means 14 lines from the start location. */ | |
8610 | sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line, | |
58438ac1 | 8611 | &canonical_end); |
f1310107 TJB |
8612 | |
8613 | /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */ | |
8614 | if (canonical_end.canonical == NULL) | |
38a714bb | 8615 | canonical_end.canonical = xcalloc (1, sizeof (char *)); |
f1310107 TJB |
8616 | /* Add the string if not present. */ |
8617 | if (arg_start != arg && canonical_end.canonical[0] == NULL) | |
8618 | canonical_end.canonical[0] = savestring (arg_start, arg - arg_start); | |
8619 | ||
8620 | sal_end = sals_end.sals[0]; | |
8621 | addr_string_end = canonical_end.canonical[0]; | |
8622 | make_cleanup (xfree, addr_string_end); | |
8623 | xfree (sals_end.sals); | |
8624 | xfree (canonical_end.canonical); | |
8625 | ||
8626 | if (sals_end.nelts == 0) | |
8627 | error (_("Could not find location of the end of the range.")); | |
8628 | else if (sals_end.nelts != 1) | |
8629 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8630 | ||
8631 | resolve_sal_pc (&sal_end); | |
8632 | ||
8633 | end = find_breakpoint_range_end (sal_end); | |
8634 | if (sal_start.pc > end) | |
8635 | error (_("Invalid address range, end preceeds start.")); | |
8636 | ||
8637 | length = end - sal_start.pc + 1; | |
8638 | if (length < 0) | |
8639 | /* Length overflowed. */ | |
8640 | error (_("Address range too large.")); | |
8641 | else if (length == 1) | |
8642 | { | |
8643 | /* This range is simple enough to be handled by | |
8644 | the `hbreak' command. */ | |
8645 | hbreak_command (addr_string_start, 1); | |
8646 | ||
8647 | do_cleanups (cleanup_bkpt); | |
8648 | ||
8649 | return; | |
8650 | } | |
8651 | ||
8652 | /* Now set up the breakpoint. */ | |
8653 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
8654 | bp_hardware_breakpoint); | |
8655 | set_breakpoint_count (breakpoint_count + 1); | |
8656 | b->number = breakpoint_count; | |
8657 | b->disposition = disp_donttouch; | |
8658 | b->addr_string = addr_string_start; | |
8659 | b->addr_string_range_end = addr_string_end; | |
8660 | b->ops = &ranged_breakpoint_ops; | |
8661 | b->loc->length = length; | |
8662 | ||
8663 | discard_cleanups (cleanup_bkpt); | |
8664 | ||
8665 | mention (b); | |
8d3788bd | 8666 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8667 | update_global_location_list (1); |
8668 | } | |
8669 | ||
4a64f543 MS |
8670 | /* Return non-zero if EXP is verified as constant. Returned zero |
8671 | means EXP is variable. Also the constant detection may fail for | |
8672 | some constant expressions and in such case still falsely return | |
8673 | zero. */ | |
65d79d4b SDJ |
8674 | static int |
8675 | watchpoint_exp_is_const (const struct expression *exp) | |
8676 | { | |
8677 | int i = exp->nelts; | |
8678 | ||
8679 | while (i > 0) | |
8680 | { | |
8681 | int oplenp, argsp; | |
8682 | ||
8683 | /* We are only interested in the descriptor of each element. */ | |
8684 | operator_length (exp, i, &oplenp, &argsp); | |
8685 | i -= oplenp; | |
8686 | ||
8687 | switch (exp->elts[i].opcode) | |
8688 | { | |
8689 | case BINOP_ADD: | |
8690 | case BINOP_SUB: | |
8691 | case BINOP_MUL: | |
8692 | case BINOP_DIV: | |
8693 | case BINOP_REM: | |
8694 | case BINOP_MOD: | |
8695 | case BINOP_LSH: | |
8696 | case BINOP_RSH: | |
8697 | case BINOP_LOGICAL_AND: | |
8698 | case BINOP_LOGICAL_OR: | |
8699 | case BINOP_BITWISE_AND: | |
8700 | case BINOP_BITWISE_IOR: | |
8701 | case BINOP_BITWISE_XOR: | |
8702 | case BINOP_EQUAL: | |
8703 | case BINOP_NOTEQUAL: | |
8704 | case BINOP_LESS: | |
8705 | case BINOP_GTR: | |
8706 | case BINOP_LEQ: | |
8707 | case BINOP_GEQ: | |
8708 | case BINOP_REPEAT: | |
8709 | case BINOP_COMMA: | |
8710 | case BINOP_EXP: | |
8711 | case BINOP_MIN: | |
8712 | case BINOP_MAX: | |
8713 | case BINOP_INTDIV: | |
8714 | case BINOP_CONCAT: | |
8715 | case BINOP_IN: | |
8716 | case BINOP_RANGE: | |
8717 | case TERNOP_COND: | |
8718 | case TERNOP_SLICE: | |
8719 | case TERNOP_SLICE_COUNT: | |
8720 | ||
8721 | case OP_LONG: | |
8722 | case OP_DOUBLE: | |
8723 | case OP_DECFLOAT: | |
8724 | case OP_LAST: | |
8725 | case OP_COMPLEX: | |
8726 | case OP_STRING: | |
8727 | case OP_BITSTRING: | |
8728 | case OP_ARRAY: | |
8729 | case OP_TYPE: | |
8730 | case OP_NAME: | |
8731 | case OP_OBJC_NSSTRING: | |
8732 | ||
8733 | case UNOP_NEG: | |
8734 | case UNOP_LOGICAL_NOT: | |
8735 | case UNOP_COMPLEMENT: | |
8736 | case UNOP_ADDR: | |
8737 | case UNOP_HIGH: | |
4a64f543 MS |
8738 | /* Unary, binary and ternary operators: We have to check |
8739 | their operands. If they are constant, then so is the | |
8740 | result of that operation. For instance, if A and B are | |
8741 | determined to be constants, then so is "A + B". | |
8742 | ||
8743 | UNOP_IND is one exception to the rule above, because the | |
8744 | value of *ADDR is not necessarily a constant, even when | |
8745 | ADDR is. */ | |
65d79d4b SDJ |
8746 | break; |
8747 | ||
8748 | case OP_VAR_VALUE: | |
8749 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8750 | |
65d79d4b | 8751 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8752 | possible that a buggy compiler could mark a variable as |
8753 | constant even when it is not, and TYPE_CONST would return | |
8754 | true in this case, while SYMBOL_CLASS wouldn't. | |
8755 | ||
8756 | We also have to check for function symbols because they | |
8757 | are always constant. */ | |
65d79d4b SDJ |
8758 | { |
8759 | struct symbol *s = exp->elts[i + 2].symbol; | |
8760 | ||
8761 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8762 | && SYMBOL_CLASS (s) != LOC_CONST | |
8763 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8764 | return 0; | |
8765 | break; | |
8766 | } | |
8767 | ||
8768 | /* The default action is to return 0 because we are using | |
8769 | the optimistic approach here: If we don't know something, | |
8770 | then it is not a constant. */ | |
8771 | default: | |
8772 | return 0; | |
8773 | } | |
8774 | } | |
8775 | ||
8776 | return 1; | |
8777 | } | |
8778 | ||
77b06cd7 TJB |
8779 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8780 | ||
8781 | static int | |
8782 | insert_watchpoint (struct bp_location *bl) | |
8783 | { | |
e09342b5 TJB |
8784 | int length = bl->owner->exact? 1 : bl->length; |
8785 | ||
8786 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
8787 | bl->owner->cond_exp); | |
77b06cd7 TJB |
8788 | } |
8789 | ||
8790 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8791 | ||
8792 | static int | |
8793 | remove_watchpoint (struct bp_location *bl) | |
8794 | { | |
e09342b5 TJB |
8795 | int length = bl->owner->exact? 1 : bl->length; |
8796 | ||
8797 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
8798 | bl->owner->cond_exp); | |
8799 | } | |
8800 | ||
8801 | /* Implement the "resources_needed" breakpoint_ops method for | |
8802 | hardware watchpoints. */ | |
8803 | ||
8804 | static int | |
8805 | resources_needed_watchpoint (const struct bp_location *bl) | |
8806 | { | |
90e4670f | 8807 | int length = bl->owner->exact? 1 : bl->length; |
e09342b5 | 8808 | |
90e4670f | 8809 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
77b06cd7 TJB |
8810 | } |
8811 | ||
9c06b0b4 TJB |
8812 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
8813 | hardware watchpoints. */ | |
8814 | ||
8815 | int | |
8816 | works_in_software_mode_watchpoint (const struct breakpoint *b) | |
8817 | { | |
8818 | return b->type == bp_hardware_watchpoint; | |
8819 | } | |
8820 | ||
77b06cd7 TJB |
8821 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
8822 | ||
8823 | static struct breakpoint_ops watchpoint_breakpoint_ops = | |
8824 | { | |
8825 | insert_watchpoint, | |
8826 | remove_watchpoint, | |
8827 | NULL, /* breakpoint_hit */ | |
e09342b5 | 8828 | resources_needed_watchpoint, |
9c06b0b4 | 8829 | works_in_software_mode_watchpoint, |
77b06cd7 TJB |
8830 | NULL, /* print_it */ |
8831 | NULL, /* print_one */ | |
f1310107 | 8832 | NULL, /* print_one_detail */ |
77b06cd7 TJB |
8833 | NULL, /* print_mention */ |
8834 | NULL /* print_recreate */ | |
8835 | }; | |
8836 | ||
9c06b0b4 TJB |
8837 | /* Implement the "insert" breakpoint_ops method for |
8838 | masked hardware watchpoints. */ | |
8839 | ||
8840 | static int | |
8841 | insert_masked_watchpoint (struct bp_location *bl) | |
8842 | { | |
8843 | return target_insert_mask_watchpoint (bl->address, bl->owner->hw_wp_mask, | |
8844 | bl->watchpoint_type); | |
8845 | } | |
8846 | ||
8847 | /* Implement the "remove" breakpoint_ops method for | |
8848 | masked hardware watchpoints. */ | |
8849 | ||
8850 | static int | |
8851 | remove_masked_watchpoint (struct bp_location *bl) | |
8852 | { | |
8853 | return target_remove_mask_watchpoint (bl->address, bl->owner->hw_wp_mask, | |
8854 | bl->watchpoint_type); | |
8855 | } | |
8856 | ||
8857 | /* Implement the "resources_needed" breakpoint_ops method for | |
8858 | masked hardware watchpoints. */ | |
8859 | ||
8860 | static int | |
8861 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
8862 | { | |
8863 | return target_masked_watch_num_registers (bl->address, | |
8864 | bl->owner->hw_wp_mask); | |
8865 | } | |
8866 | ||
8867 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
8868 | masked hardware watchpoints. */ | |
8869 | ||
8870 | static int | |
8871 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
8872 | { | |
8873 | return 0; | |
8874 | } | |
8875 | ||
8876 | /* Implement the "print_it" breakpoint_ops method for | |
8877 | masked hardware watchpoints. */ | |
8878 | ||
8879 | static enum print_stop_action | |
8880 | print_it_masked_watchpoint (struct breakpoint *b) | |
8881 | { | |
8882 | /* Masked watchpoints have only one location. */ | |
8883 | gdb_assert (b->loc && b->loc->next == NULL); | |
8884 | ||
8885 | switch (b->type) | |
8886 | { | |
8887 | case bp_hardware_watchpoint: | |
8888 | annotate_watchpoint (b->number); | |
8889 | if (ui_out_is_mi_like_p (uiout)) | |
8890 | ui_out_field_string | |
8891 | (uiout, "reason", | |
8892 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
8893 | break; | |
8894 | ||
8895 | case bp_read_watchpoint: | |
8896 | if (ui_out_is_mi_like_p (uiout)) | |
8897 | ui_out_field_string | |
8898 | (uiout, "reason", | |
8899 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
8900 | break; | |
8901 | ||
8902 | case bp_access_watchpoint: | |
8903 | if (ui_out_is_mi_like_p (uiout)) | |
8904 | ui_out_field_string | |
8905 | (uiout, "reason", | |
8906 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8907 | break; | |
8908 | default: | |
8909 | internal_error (__FILE__, __LINE__, | |
8910 | _("Invalid hardware watchpoint type.")); | |
8911 | } | |
8912 | ||
8913 | mention (b); | |
8914 | ui_out_text (uiout, _("\n\ | |
8915 | Check the underlying instruction at PC for the memory\n\ | |
8916 | address and value which triggered this watchpoint.\n")); | |
8917 | ui_out_text (uiout, "\n"); | |
8918 | ||
8919 | /* More than one watchpoint may have been triggered. */ | |
8920 | return PRINT_UNKNOWN; | |
8921 | } | |
8922 | ||
8923 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8924 | masked hardware watchpoints. */ | |
8925 | ||
8926 | static void | |
8927 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
8928 | struct ui_out *uiout) | |
8929 | { | |
8930 | /* Masked watchpoints have only one location. */ | |
8931 | gdb_assert (b->loc && b->loc->next == NULL); | |
8932 | ||
8933 | ui_out_text (uiout, "\tmask "); | |
8934 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, b->hw_wp_mask); | |
8935 | ui_out_text (uiout, "\n"); | |
8936 | } | |
8937 | ||
8938 | /* Implement the "print_mention" breakpoint_ops method for | |
8939 | masked hardware watchpoints. */ | |
8940 | ||
8941 | static void | |
8942 | print_mention_masked_watchpoint (struct breakpoint *b) | |
8943 | { | |
8944 | struct cleanup *ui_out_chain; | |
8945 | ||
8946 | switch (b->type) | |
8947 | { | |
8948 | case bp_hardware_watchpoint: | |
8949 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
8950 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8951 | break; | |
8952 | case bp_read_watchpoint: | |
8953 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
8954 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8955 | break; | |
8956 | case bp_access_watchpoint: | |
8957 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
8958 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8959 | break; | |
8960 | default: | |
8961 | internal_error (__FILE__, __LINE__, | |
8962 | _("Invalid hardware watchpoint type.")); | |
8963 | } | |
8964 | ||
8965 | ui_out_field_int (uiout, "number", b->number); | |
8966 | ui_out_text (uiout, ": "); | |
8967 | ui_out_field_string (uiout, "exp", b->exp_string); | |
8968 | do_cleanups (ui_out_chain); | |
8969 | } | |
8970 | ||
8971 | /* Implement the "print_recreate" breakpoint_ops method for | |
8972 | masked hardware watchpoints. */ | |
8973 | ||
8974 | static void | |
8975 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8976 | { | |
8977 | char tmp[40]; | |
8978 | ||
8979 | switch (b->type) | |
8980 | { | |
8981 | case bp_hardware_watchpoint: | |
8982 | fprintf_unfiltered (fp, "watch"); | |
8983 | break; | |
8984 | case bp_read_watchpoint: | |
8985 | fprintf_unfiltered (fp, "rwatch"); | |
8986 | break; | |
8987 | case bp_access_watchpoint: | |
8988 | fprintf_unfiltered (fp, "awatch"); | |
8989 | break; | |
8990 | default: | |
8991 | internal_error (__FILE__, __LINE__, | |
8992 | _("Invalid hardware watchpoint type.")); | |
8993 | } | |
8994 | ||
8995 | sprintf_vma (tmp, b->hw_wp_mask); | |
8996 | fprintf_unfiltered (fp, " %s mask 0x%s", b->exp_string, tmp); | |
8997 | } | |
8998 | ||
8999 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9000 | ||
9001 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops = | |
9002 | { | |
9003 | insert_masked_watchpoint, | |
9004 | remove_masked_watchpoint, | |
9005 | NULL, /* breakpoint_hit */ | |
9006 | resources_needed_masked_watchpoint, | |
9007 | works_in_software_mode_masked_watchpoint, | |
9008 | print_it_masked_watchpoint, | |
9009 | NULL, /* print_one */ | |
9010 | print_one_detail_masked_watchpoint, | |
9011 | print_mention_masked_watchpoint, | |
9012 | print_recreate_masked_watchpoint | |
9013 | }; | |
9014 | ||
9015 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9016 | ||
9017 | static int | |
9018 | is_masked_watchpoint (const struct breakpoint *b) | |
9019 | { | |
9020 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9021 | } | |
9022 | ||
53a5351d JM |
9023 | /* accessflag: hw_write: watch write, |
9024 | hw_read: watch read, | |
9025 | hw_access: watch access (read or write) */ | |
c906108c | 9026 | static void |
84f4c1fe PM |
9027 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9028 | int just_location, int internal) | |
c906108c | 9029 | { |
a9634178 | 9030 | volatile struct gdb_exception e; |
d983da9c | 9031 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9032 | struct expression *exp; |
60e1c644 | 9033 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9034 | struct value *val, *mark, *result; |
c906108c | 9035 | struct frame_info *frame; |
c906108c SS |
9036 | char *exp_start = NULL; |
9037 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9038 | char *tok, *end_tok; |
9039 | int toklen = -1; | |
c906108c SS |
9040 | char *cond_start = NULL; |
9041 | char *cond_end = NULL; | |
c906108c | 9042 | enum bptype bp_type; |
37e4754d | 9043 | int thread = -1; |
0cf6dd15 | 9044 | int pc = 0; |
9c06b0b4 TJB |
9045 | /* Flag to indicate whether we are going to use masks for |
9046 | the hardware watchpoint. */ | |
9047 | int use_mask = 0; | |
9048 | CORE_ADDR mask = 0; | |
c906108c | 9049 | |
37e4754d LM |
9050 | /* Make sure that we actually have parameters to parse. */ |
9051 | if (arg != NULL && arg[0] != '\0') | |
9052 | { | |
9c06b0b4 | 9053 | char *value_start; |
37e4754d | 9054 | |
9c06b0b4 TJB |
9055 | /* Look for "parameter value" pairs at the end |
9056 | of the arguments string. */ | |
9057 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9058 | { | |
9059 | /* Skip whitespace at the end of the argument list. */ | |
9060 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9061 | tok--; | |
9062 | ||
9063 | /* Find the beginning of the last token. | |
9064 | This is the value of the parameter. */ | |
9065 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9066 | tok--; | |
9067 | value_start = tok + 1; | |
9068 | ||
9069 | /* Skip whitespace. */ | |
9070 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9071 | tok--; | |
9072 | ||
9073 | end_tok = tok; | |
9074 | ||
9075 | /* Find the beginning of the second to last token. | |
9076 | This is the parameter itself. */ | |
9077 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9078 | tok--; | |
9079 | tok++; | |
9080 | toklen = end_tok - tok + 1; | |
9081 | ||
9082 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9083 | { | |
9084 | /* At this point we've found a "thread" token, which means | |
9085 | the user is trying to set a watchpoint that triggers | |
9086 | only in a specific thread. */ | |
9087 | char *endp; | |
37e4754d | 9088 | |
9c06b0b4 TJB |
9089 | if (thread != -1) |
9090 | error(_("You can specify only one thread.")); | |
37e4754d | 9091 | |
9c06b0b4 TJB |
9092 | /* Extract the thread ID from the next token. */ |
9093 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9094 | |
9c06b0b4 TJB |
9095 | /* Check if the user provided a valid numeric value for the |
9096 | thread ID. */ | |
9097 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9098 | error (_("Invalid thread ID specification %s."), value_start); | |
9099 | ||
9100 | /* Check if the thread actually exists. */ | |
9101 | if (!valid_thread_id (thread)) | |
9102 | error (_("Unknown thread %d."), thread); | |
9103 | } | |
9104 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9105 | { | |
9106 | /* We've found a "mask" token, which means the user wants to | |
9107 | create a hardware watchpoint that is going to have the mask | |
9108 | facility. */ | |
9109 | struct value *mask_value, *mark; | |
37e4754d | 9110 | |
9c06b0b4 TJB |
9111 | if (use_mask) |
9112 | error(_("You can specify only one mask.")); | |
37e4754d | 9113 | |
9c06b0b4 | 9114 | use_mask = just_location = 1; |
37e4754d | 9115 | |
9c06b0b4 TJB |
9116 | mark = value_mark (); |
9117 | mask_value = parse_to_comma_and_eval (&value_start); | |
9118 | mask = value_as_address (mask_value); | |
9119 | value_free_to_mark (mark); | |
9120 | } | |
9121 | else | |
9122 | /* We didn't recognize what we found. We should stop here. */ | |
9123 | break; | |
37e4754d | 9124 | |
9c06b0b4 TJB |
9125 | /* Truncate the string and get rid of the "parameter value" pair before |
9126 | the arguments string is parsed by the parse_exp_1 function. */ | |
9127 | *tok = '\0'; | |
9128 | } | |
37e4754d LM |
9129 | } |
9130 | ||
9131 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9132 | innermost_block = NULL; |
9133 | exp_start = arg; | |
9134 | exp = parse_exp_1 (&arg, 0, 0); | |
9135 | exp_end = arg; | |
fa8a61dc TT |
9136 | /* Remove trailing whitespace from the expression before saving it. |
9137 | This makes the eventual display of the expression string a bit | |
9138 | prettier. */ | |
9139 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9140 | --exp_end; | |
9141 | ||
65d79d4b SDJ |
9142 | /* Checking if the expression is not constant. */ |
9143 | if (watchpoint_exp_is_const (exp)) | |
9144 | { | |
9145 | int len; | |
9146 | ||
9147 | len = exp_end - exp_start; | |
9148 | while (len > 0 && isspace (exp_start[len - 1])) | |
9149 | len--; | |
9150 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9151 | } | |
9152 | ||
c906108c SS |
9153 | exp_valid_block = innermost_block; |
9154 | mark = value_mark (); | |
a1442452 | 9155 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9156 | |
9157 | if (just_location) | |
9158 | { | |
9c06b0b4 TJB |
9159 | int ret; |
9160 | ||
06a64a0b | 9161 | exp_valid_block = NULL; |
a1442452 | 9162 | val = value_addr (result); |
06a64a0b TT |
9163 | release_value (val); |
9164 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9165 | |
9166 | if (use_mask) | |
9167 | { | |
9168 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9169 | mask); | |
9170 | if (ret == -1) | |
9171 | error (_("This target does not support masked watchpoints.")); | |
9172 | else if (ret == -2) | |
9173 | error (_("Invalid mask or memory region.")); | |
9174 | } | |
06a64a0b TT |
9175 | } |
9176 | else if (val != NULL) | |
fa4727a6 | 9177 | release_value (val); |
c906108c | 9178 | |
e9cafbcc TT |
9179 | tok = skip_spaces (arg); |
9180 | end_tok = skip_to_space (tok); | |
c906108c SS |
9181 | |
9182 | toklen = end_tok - tok; | |
9183 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9184 | { | |
2d134ed3 PA |
9185 | struct expression *cond; |
9186 | ||
60e1c644 | 9187 | innermost_block = NULL; |
c906108c SS |
9188 | tok = cond_start = end_tok + 1; |
9189 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9190 | |
9191 | /* The watchpoint expression may not be local, but the condition | |
9192 | may still be. E.g.: `watch global if local > 0'. */ | |
9193 | cond_exp_valid_block = innermost_block; | |
9194 | ||
2d134ed3 | 9195 | xfree (cond); |
c906108c SS |
9196 | cond_end = tok; |
9197 | } | |
9198 | if (*tok) | |
8a3fe4f8 | 9199 | error (_("Junk at end of command.")); |
c906108c | 9200 | |
53a5351d | 9201 | if (accessflag == hw_read) |
c5aa993b | 9202 | bp_type = bp_read_watchpoint; |
53a5351d | 9203 | else if (accessflag == hw_access) |
c5aa993b JM |
9204 | bp_type = bp_access_watchpoint; |
9205 | else | |
9206 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9207 | |
d983da9c | 9208 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9209 | |
9210 | /* If the expression is "local", then set up a "watchpoint scope" | |
9211 | breakpoint at the point where we've left the scope of the watchpoint | |
9212 | expression. Create the scope breakpoint before the watchpoint, so | |
9213 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9214 | if (exp_valid_block && frame) |
d983da9c | 9215 | { |
edb3359d DJ |
9216 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9217 | { | |
9218 | scope_breakpoint | |
a6d9a66e UW |
9219 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9220 | frame_unwind_caller_pc (frame), | |
edb3359d | 9221 | bp_watchpoint_scope); |
d983da9c | 9222 | |
edb3359d | 9223 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9224 | |
edb3359d DJ |
9225 | /* Automatically delete the breakpoint when it hits. */ |
9226 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9227 | |
edb3359d DJ |
9228 | /* Only break in the proper frame (help with recursion). */ |
9229 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9230 | |
edb3359d | 9231 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9232 | scope_breakpoint->loc->gdbarch |
9233 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9234 | scope_breakpoint->loc->requested_address |
9235 | = frame_unwind_caller_pc (frame); | |
9236 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9237 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9238 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9239 | scope_breakpoint->type); |
9240 | } | |
d983da9c DJ |
9241 | } |
9242 | ||
c906108c | 9243 | /* Now set up the breakpoint. */ |
2d134ed3 | 9244 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
37e4754d | 9245 | b->thread = thread; |
b5de0fa7 | 9246 | b->disposition = disp_donttouch; |
c906108c SS |
9247 | b->exp = exp; |
9248 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 9249 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
9250 | if (just_location) |
9251 | { | |
9252 | struct type *t = value_type (val); | |
9253 | CORE_ADDR addr = value_as_address (val); | |
9254 | char *name; | |
9255 | ||
9256 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9257 | name = type_to_string (t); | |
9258 | ||
d63d0675 JK |
9259 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
9260 | core_addr_to_string (addr)); | |
06a64a0b TT |
9261 | xfree (name); |
9262 | ||
4a4106ca | 9263 | b->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9264 | (int) (exp_end - exp_start), exp_start); |
9265 | ||
06a64a0b TT |
9266 | /* The above expression is in C. */ |
9267 | b->language = language_c; | |
9268 | } | |
9269 | else | |
9270 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
9c06b0b4 TJB |
9271 | |
9272 | if (use_mask) | |
9273 | { | |
9274 | b->hw_wp_mask = mask; | |
9275 | b->ops = &masked_watchpoint_breakpoint_ops; | |
9276 | } | |
9277 | else | |
9278 | { | |
9279 | b->val = val; | |
9280 | b->val_valid = 1; | |
9281 | b->ops = &watchpoint_breakpoint_ops; | |
9282 | } | |
77b06cd7 | 9283 | |
c906108c SS |
9284 | if (cond_start) |
9285 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9286 | else | |
9287 | b->cond_string = 0; | |
c5aa993b | 9288 | |
c906108c | 9289 | if (frame) |
f6bc2008 PA |
9290 | { |
9291 | b->watchpoint_frame = get_frame_id (frame); | |
9292 | b->watchpoint_thread = inferior_ptid; | |
9293 | } | |
c906108c | 9294 | else |
f6bc2008 PA |
9295 | { |
9296 | b->watchpoint_frame = null_frame_id; | |
9297 | b->watchpoint_thread = null_ptid; | |
9298 | } | |
c906108c | 9299 | |
d983da9c | 9300 | if (scope_breakpoint != NULL) |
c906108c | 9301 | { |
d983da9c DJ |
9302 | /* The scope breakpoint is related to the watchpoint. We will |
9303 | need to act on them together. */ | |
9304 | b->related_breakpoint = scope_breakpoint; | |
9305 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9306 | } |
d983da9c | 9307 | |
06a64a0b TT |
9308 | if (!just_location) |
9309 | value_free_to_mark (mark); | |
2d134ed3 | 9310 | |
a9634178 TJB |
9311 | TRY_CATCH (e, RETURN_MASK_ALL) |
9312 | { | |
9313 | /* Finally update the new watchpoint. This creates the locations | |
9314 | that should be inserted. */ | |
9315 | update_watchpoint (b, 1); | |
9316 | } | |
9317 | if (e.reason < 0) | |
9318 | { | |
9319 | delete_breakpoint (b); | |
9320 | throw_exception (e); | |
9321 | } | |
9322 | ||
9323 | set_breakpoint_number (internal, b); | |
8d3788bd VP |
9324 | |
9325 | /* Do not mention breakpoints with a negative number, but do | |
a9634178 | 9326 | notify observers. */ |
8d3788bd | 9327 | if (!internal) |
84f4c1fe | 9328 | mention (b); |
8d3788bd VP |
9329 | observer_notify_breakpoint_created (b); |
9330 | ||
b60e7edf | 9331 | update_global_location_list (1); |
c906108c SS |
9332 | } |
9333 | ||
e09342b5 | 9334 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9335 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9336 | |
c906108c | 9337 | static int |
a9634178 | 9338 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9339 | { |
9340 | int found_memory_cnt = 0; | |
2e70b7b9 | 9341 | struct value *head = v; |
c906108c SS |
9342 | |
9343 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9344 | if (!can_use_hw_watchpoints) |
c906108c | 9345 | return 0; |
c5aa993b | 9346 | |
5c44784c JM |
9347 | /* Make sure that the value of the expression depends only upon |
9348 | memory contents, and values computed from them within GDB. If we | |
9349 | find any register references or function calls, we can't use a | |
9350 | hardware watchpoint. | |
9351 | ||
9352 | The idea here is that evaluating an expression generates a series | |
9353 | of values, one holding the value of every subexpression. (The | |
9354 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9355 | a*b+c.) GDB's values hold almost enough information to establish | |
9356 | the criteria given above --- they identify memory lvalues, | |
9357 | register lvalues, computed values, etcetera. So we can evaluate | |
9358 | the expression, and then scan the chain of values that leaves | |
9359 | behind to decide whether we can detect any possible change to the | |
9360 | expression's final value using only hardware watchpoints. | |
9361 | ||
9362 | However, I don't think that the values returned by inferior | |
9363 | function calls are special in any way. So this function may not | |
9364 | notice that an expression involving an inferior function call | |
9365 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9366 | for (; v; v = value_next (v)) |
c906108c | 9367 | { |
5c44784c | 9368 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9369 | { |
8464be76 DJ |
9370 | if (v != head && value_lazy (v)) |
9371 | /* A lazy memory lvalue in the chain is one that GDB never | |
9372 | needed to fetch; we either just used its address (e.g., | |
9373 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9374 | in `a,b'). This doesn't apply to HEAD; if that is | |
9375 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9376 | ; |
53a5351d | 9377 | else |
5c44784c JM |
9378 | { |
9379 | /* Ahh, memory we actually used! Check if we can cover | |
9380 | it with hardware watchpoints. */ | |
df407dfe | 9381 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9382 | |
9383 | /* We only watch structs and arrays if user asked for it | |
9384 | explicitly, never if they just happen to appear in a | |
9385 | middle of some value chain. */ | |
9386 | if (v == head | |
9387 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9388 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9389 | { | |
42ae5230 | 9390 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9391 | int len; |
9392 | int num_regs; | |
9393 | ||
a9634178 | 9394 | len = (target_exact_watchpoints |
e09342b5 TJB |
9395 | && is_scalar_type_recursive (vtype))? |
9396 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9397 | |
e09342b5 TJB |
9398 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9399 | if (!num_regs) | |
2e70b7b9 MS |
9400 | return 0; |
9401 | else | |
e09342b5 | 9402 | found_memory_cnt += num_regs; |
2e70b7b9 | 9403 | } |
5c44784c | 9404 | } |
c5aa993b | 9405 | } |
5086187c AC |
9406 | else if (VALUE_LVAL (v) != not_lval |
9407 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9408 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9409 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9410 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9411 | } |
9412 | ||
9413 | /* The expression itself looks suitable for using a hardware | |
9414 | watchpoint, but give the target machine a chance to reject it. */ | |
9415 | return found_memory_cnt; | |
9416 | } | |
9417 | ||
8b93c638 | 9418 | void |
84f4c1fe | 9419 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9420 | { |
84f4c1fe | 9421 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9422 | } |
9423 | ||
9424 | /* A helper function that looks for an argument at the start of a | |
9425 | string. The argument must also either be at the end of the string, | |
9426 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9427 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9428 | ||
9429 | static int | |
9430 | check_for_argument (char **str, char *arg, int arg_len) | |
9431 | { | |
9432 | if (strncmp (*str, arg, arg_len) == 0 | |
9433 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9434 | { | |
9435 | *str += arg_len; | |
9436 | return 1; | |
9437 | } | |
9438 | return 0; | |
9439 | } | |
9440 | ||
9441 | /* A helper function that looks for the "-location" argument and then | |
9442 | calls watch_command_1. */ | |
9443 | ||
9444 | static void | |
9445 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9446 | { | |
9447 | int just_location = 0; | |
9448 | ||
9449 | if (arg | |
9450 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9451 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9452 | { | |
e9cafbcc | 9453 | arg = skip_spaces (arg); |
06a64a0b TT |
9454 | just_location = 1; |
9455 | } | |
9456 | ||
84f4c1fe | 9457 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9458 | } |
8926118c | 9459 | |
c5aa993b | 9460 | static void |
fba45db2 | 9461 | watch_command (char *arg, int from_tty) |
c906108c | 9462 | { |
06a64a0b | 9463 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9464 | } |
9465 | ||
8b93c638 | 9466 | void |
84f4c1fe | 9467 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9468 | { |
84f4c1fe | 9469 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9470 | } |
8926118c | 9471 | |
c5aa993b | 9472 | static void |
fba45db2 | 9473 | rwatch_command (char *arg, int from_tty) |
c906108c | 9474 | { |
06a64a0b | 9475 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9476 | } |
9477 | ||
8b93c638 | 9478 | void |
84f4c1fe | 9479 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9480 | { |
84f4c1fe | 9481 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9482 | } |
8926118c | 9483 | |
c5aa993b | 9484 | static void |
fba45db2 | 9485 | awatch_command (char *arg, int from_tty) |
c906108c | 9486 | { |
06a64a0b | 9487 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9488 | } |
c906108c | 9489 | \f |
c5aa993b | 9490 | |
43ff13b4 | 9491 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9492 | because it uses the mechanisms of breakpoints. */ |
9493 | ||
bfec99b2 PA |
9494 | struct until_break_command_continuation_args |
9495 | { | |
9496 | struct breakpoint *breakpoint; | |
9497 | struct breakpoint *breakpoint2; | |
186c406b | 9498 | int thread_num; |
bfec99b2 PA |
9499 | }; |
9500 | ||
43ff13b4 | 9501 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9502 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9503 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9504 | command. */ |
c2c6d25f | 9505 | static void |
604ead4a | 9506 | until_break_command_continuation (void *arg) |
43ff13b4 | 9507 | { |
bfec99b2 PA |
9508 | struct until_break_command_continuation_args *a = arg; |
9509 | ||
9510 | delete_breakpoint (a->breakpoint); | |
9511 | if (a->breakpoint2) | |
9512 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9513 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9514 | } |
9515 | ||
c906108c | 9516 | void |
ae66c1fc | 9517 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9518 | { |
9519 | struct symtabs_and_lines sals; | |
9520 | struct symtab_and_line sal; | |
206415a3 | 9521 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9522 | struct breakpoint *breakpoint; |
f107f563 | 9523 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9524 | struct cleanup *old_chain; |
186c406b TT |
9525 | int thread; |
9526 | struct thread_info *tp; | |
c906108c SS |
9527 | |
9528 | clear_proceed_status (); | |
9529 | ||
9530 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9531 | this function. */ |
c5aa993b | 9532 | |
c906108c SS |
9533 | if (default_breakpoint_valid) |
9534 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
58438ac1 | 9535 | default_breakpoint_line, NULL); |
c906108c | 9536 | else |
58438ac1 | 9537 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL); |
c5aa993b | 9538 | |
c906108c | 9539 | if (sals.nelts != 1) |
8a3fe4f8 | 9540 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9541 | |
c906108c | 9542 | sal = sals.sals[0]; |
4a64f543 | 9543 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9544 | |
c906108c | 9545 | if (*arg) |
8a3fe4f8 | 9546 | error (_("Junk at end of arguments.")); |
c5aa993b | 9547 | |
c906108c | 9548 | resolve_sal_pc (&sal); |
c5aa993b | 9549 | |
ae66c1fc EZ |
9550 | if (anywhere) |
9551 | /* If the user told us to continue until a specified location, | |
9552 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9553 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9554 | null_frame_id, bp_until); | |
ae66c1fc | 9555 | else |
4a64f543 MS |
9556 | /* Otherwise, specify the selected frame, because we want to stop |
9557 | only at the very same frame. */ | |
a6d9a66e UW |
9558 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9559 | get_stack_frame_id (frame), | |
ae66c1fc | 9560 | bp_until); |
c5aa993b | 9561 | |
f107f563 | 9562 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9563 | |
186c406b TT |
9564 | tp = inferior_thread (); |
9565 | thread = tp->num; | |
9566 | ||
ae66c1fc EZ |
9567 | /* Keep within the current frame, or in frames called by the current |
9568 | one. */ | |
edb3359d DJ |
9569 | |
9570 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9571 | { |
edb3359d DJ |
9572 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9573 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9574 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9575 | sal, | |
edb3359d | 9576 | frame_unwind_caller_id (frame), |
f107f563 VP |
9577 | bp_until); |
9578 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9579 | |
9580 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9581 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9582 | } |
c5aa993b | 9583 | |
c906108c | 9584 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9585 | |
4a64f543 MS |
9586 | /* If we are running asynchronously, and proceed call above has |
9587 | actually managed to start the target, arrange for breakpoints to | |
9588 | be deleted when the target stops. Otherwise, we're already | |
9589 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9590 | |
8ea051c5 | 9591 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9592 | { |
bfec99b2 PA |
9593 | struct until_break_command_continuation_args *args; |
9594 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9595 | |
bfec99b2 PA |
9596 | args->breakpoint = breakpoint; |
9597 | args->breakpoint2 = breakpoint2; | |
186c406b | 9598 | args->thread_num = thread; |
f107f563 VP |
9599 | |
9600 | discard_cleanups (old_chain); | |
95e54da7 PA |
9601 | add_continuation (inferior_thread (), |
9602 | until_break_command_continuation, args, | |
604ead4a | 9603 | xfree); |
f107f563 VP |
9604 | } |
9605 | else | |
c5aa993b | 9606 | do_cleanups (old_chain); |
c906108c | 9607 | } |
ae66c1fc | 9608 | |
c906108c SS |
9609 | /* This function attempts to parse an optional "if <cond>" clause |
9610 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9611 | |
c906108c SS |
9612 | Else, it returns a pointer to the condition string. (It does not |
9613 | attempt to evaluate the string against a particular block.) And, | |
9614 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9615 | if clause in the arg string. */ |
53a5351d | 9616 | |
c906108c | 9617 | static char * |
fba45db2 | 9618 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9619 | { |
c5aa993b JM |
9620 | char *cond_string; |
9621 | ||
9622 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9623 | return NULL; |
c5aa993b | 9624 | |
4a64f543 | 9625 | /* Skip the "if" keyword. */ |
c906108c | 9626 | (*arg) += 2; |
c5aa993b | 9627 | |
c906108c | 9628 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9629 | condition string. */ |
e9cafbcc | 9630 | *arg = skip_spaces (*arg); |
c906108c | 9631 | cond_string = *arg; |
c5aa993b | 9632 | |
4a64f543 MS |
9633 | /* Assume that the condition occupies the remainder of the arg |
9634 | string. */ | |
c906108c | 9635 | (*arg) += strlen (cond_string); |
c5aa993b | 9636 | |
c906108c SS |
9637 | return cond_string; |
9638 | } | |
c5aa993b | 9639 | |
c906108c SS |
9640 | /* Commands to deal with catching events, such as signals, exceptions, |
9641 | process start/exit, etc. */ | |
c5aa993b JM |
9642 | |
9643 | typedef enum | |
9644 | { | |
44feb3ce TT |
9645 | catch_fork_temporary, catch_vfork_temporary, |
9646 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9647 | } |
9648 | catch_fork_kind; | |
9649 | ||
c906108c | 9650 | static void |
cc59ec59 MS |
9651 | catch_fork_command_1 (char *arg, int from_tty, |
9652 | struct cmd_list_element *command) | |
c906108c | 9653 | { |
a6d9a66e | 9654 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9655 | char *cond_string = NULL; |
44feb3ce TT |
9656 | catch_fork_kind fork_kind; |
9657 | int tempflag; | |
9658 | ||
9659 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9660 | tempflag = (fork_kind == catch_fork_temporary | |
9661 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9662 | |
44feb3ce TT |
9663 | if (!arg) |
9664 | arg = ""; | |
e9cafbcc | 9665 | arg = skip_spaces (arg); |
c5aa993b | 9666 | |
c906108c | 9667 | /* The allowed syntax is: |
c5aa993b JM |
9668 | catch [v]fork |
9669 | catch [v]fork if <cond> | |
9670 | ||
4a64f543 | 9671 | First, check if there's an if clause. */ |
c906108c | 9672 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9673 | |
c906108c | 9674 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9675 | error (_("Junk at end of arguments.")); |
c5aa993b | 9676 | |
c906108c | 9677 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9678 | and enable reporting of such events. */ |
c5aa993b JM |
9679 | switch (fork_kind) |
9680 | { | |
44feb3ce TT |
9681 | case catch_fork_temporary: |
9682 | case catch_fork_permanent: | |
a6d9a66e | 9683 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9684 | &catch_fork_breakpoint_ops); |
c906108c | 9685 | break; |
44feb3ce TT |
9686 | case catch_vfork_temporary: |
9687 | case catch_vfork_permanent: | |
a6d9a66e | 9688 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9689 | &catch_vfork_breakpoint_ops); |
c906108c | 9690 | break; |
c5aa993b | 9691 | default: |
8a3fe4f8 | 9692 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9693 | break; |
c5aa993b | 9694 | } |
c906108c SS |
9695 | } |
9696 | ||
9697 | static void | |
cc59ec59 MS |
9698 | catch_exec_command_1 (char *arg, int from_tty, |
9699 | struct cmd_list_element *command) | |
c906108c | 9700 | { |
a6d9a66e | 9701 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9702 | int tempflag; |
c5aa993b | 9703 | char *cond_string = NULL; |
c906108c | 9704 | |
44feb3ce TT |
9705 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9706 | ||
9707 | if (!arg) | |
9708 | arg = ""; | |
e9cafbcc | 9709 | arg = skip_spaces (arg); |
c906108c SS |
9710 | |
9711 | /* The allowed syntax is: | |
c5aa993b JM |
9712 | catch exec |
9713 | catch exec if <cond> | |
c906108c | 9714 | |
4a64f543 | 9715 | First, check if there's an if clause. */ |
c906108c SS |
9716 | cond_string = ep_parse_optional_if_clause (&arg); |
9717 | ||
9718 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9719 | error (_("Junk at end of arguments.")); |
c906108c SS |
9720 | |
9721 | /* If this target supports it, create an exec catchpoint | |
4a64f543 | 9722 | and enable reporting of such events. */ |
a6d9a66e UW |
9723 | create_catchpoint (gdbarch, tempflag, cond_string, |
9724 | &catch_exec_breakpoint_ops); | |
c906108c | 9725 | } |
c5aa993b | 9726 | |
3086aeae | 9727 | static enum print_stop_action |
ba770c9c | 9728 | print_it_exception_catchpoint (struct breakpoint *b) |
3086aeae | 9729 | { |
ade92717 | 9730 | int bp_temp, bp_throw; |
3086aeae | 9731 | |
ade92717 | 9732 | annotate_catchpoint (b->number); |
3086aeae | 9733 | |
ade92717 AR |
9734 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9735 | if (b->loc->address != b->loc->requested_address) | |
9736 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9737 | b->loc->address, | |
9738 | b->number, 1); | |
df2b6d2d | 9739 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9740 | ui_out_text (uiout, |
9741 | bp_temp ? "Temporary catchpoint " | |
9742 | : "Catchpoint "); | |
9743 | if (!ui_out_is_mi_like_p (uiout)) | |
9744 | ui_out_field_int (uiout, "bkptno", b->number); | |
9745 | ui_out_text (uiout, | |
c0b37c48 AR |
9746 | bp_throw ? " (exception thrown), " |
9747 | : " (exception caught), "); | |
ade92717 AR |
9748 | if (ui_out_is_mi_like_p (uiout)) |
9749 | { | |
9750 | ui_out_field_string (uiout, "reason", | |
9751 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9752 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9753 | ui_out_field_int (uiout, "bkptno", b->number); | |
9754 | } | |
3086aeae DJ |
9755 | return PRINT_SRC_AND_LOC; |
9756 | } | |
9757 | ||
9758 | static void | |
cc59ec59 MS |
9759 | print_one_exception_catchpoint (struct breakpoint *b, |
9760 | struct bp_location **last_loc) | |
3086aeae | 9761 | { |
79a45b7d | 9762 | struct value_print_options opts; |
cc59ec59 | 9763 | |
79a45b7d TT |
9764 | get_user_print_options (&opts); |
9765 | if (opts.addressprint) | |
3086aeae DJ |
9766 | { |
9767 | annotate_field (4); | |
604133b5 AR |
9768 | if (b->loc == NULL || b->loc->shlib_disabled) |
9769 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9770 | else | |
5af949e3 UW |
9771 | ui_out_field_core_addr (uiout, "addr", |
9772 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9773 | } |
9774 | annotate_field (5); | |
604133b5 | 9775 | if (b->loc) |
a6d9a66e | 9776 | *last_loc = b->loc; |
3086aeae DJ |
9777 | if (strstr (b->addr_string, "throw") != NULL) |
9778 | ui_out_field_string (uiout, "what", "exception throw"); | |
9779 | else | |
9780 | ui_out_field_string (uiout, "what", "exception catch"); | |
9781 | } | |
9782 | ||
9783 | static void | |
9784 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9785 | { | |
ade92717 AR |
9786 | int bp_temp; |
9787 | int bp_throw; | |
9788 | ||
df2b6d2d | 9789 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9790 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9791 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9792 | : _("Catchpoint ")); | |
9793 | ui_out_field_int (uiout, "bkptno", b->number); | |
9794 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9795 | : _(" (catch)")); | |
3086aeae DJ |
9796 | } |
9797 | ||
6149aea9 PA |
9798 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9799 | catch catchpoints. */ | |
9800 | ||
9801 | static void | |
4a64f543 MS |
9802 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9803 | struct ui_file *fp) | |
6149aea9 PA |
9804 | { |
9805 | int bp_temp; | |
9806 | int bp_throw; | |
9807 | ||
9808 | bp_temp = b->disposition == disp_del; | |
9809 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9810 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9811 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
9812 | } | |
9813 | ||
3086aeae | 9814 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
9815 | NULL, /* insert */ |
9816 | NULL, /* remove */ | |
9817 | NULL, /* breakpoint_hit */ | |
e09342b5 | 9818 | NULL, /* resources_needed */ |
9c06b0b4 | 9819 | NULL, /* works_in_software_mode */ |
ba770c9c | 9820 | print_it_exception_catchpoint, |
3086aeae | 9821 | print_one_exception_catchpoint, |
f1310107 | 9822 | NULL, /* print_one_detail */ |
6149aea9 PA |
9823 | print_mention_exception_catchpoint, |
9824 | print_recreate_exception_catchpoint | |
3086aeae DJ |
9825 | }; |
9826 | ||
9827 | static int | |
9828 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9829 | enum exception_event_kind ex_event, int from_tty) | |
9830 | { | |
604133b5 AR |
9831 | char *trigger_func_name; |
9832 | ||
3086aeae | 9833 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9834 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9835 | else |
604133b5 | 9836 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9837 | |
8cdf0e15 VP |
9838 | create_breakpoint (get_current_arch (), |
9839 | trigger_func_name, cond_string, -1, | |
9840 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9841 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9842 | 0, |
9843 | AUTO_BOOLEAN_TRUE /* pending */, | |
9844 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9845 | 1 /* enabled */, |
9846 | 0 /* internal */); | |
3086aeae | 9847 | |
3086aeae DJ |
9848 | return 1; |
9849 | } | |
9850 | ||
4a64f543 | 9851 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9852 | |
9853 | static void | |
fba45db2 KB |
9854 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9855 | int tempflag, int from_tty) | |
c906108c | 9856 | { |
c5aa993b | 9857 | char *cond_string = NULL; |
c5aa993b | 9858 | |
44feb3ce TT |
9859 | if (!arg) |
9860 | arg = ""; | |
e9cafbcc | 9861 | arg = skip_spaces (arg); |
c5aa993b | 9862 | |
c906108c SS |
9863 | cond_string = ep_parse_optional_if_clause (&arg); |
9864 | ||
9865 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9866 | error (_("Junk at end of arguments.")); |
c906108c | 9867 | |
059fb39f PM |
9868 | if (ex_event != EX_EVENT_THROW |
9869 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9870 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9871 | |
3086aeae DJ |
9872 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9873 | return; | |
9874 | ||
8a3fe4f8 | 9875 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9876 | } |
9877 | ||
44feb3ce TT |
9878 | /* Implementation of "catch catch" command. */ |
9879 | ||
9880 | static void | |
9881 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9882 | { | |
9883 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9884 | |
44feb3ce TT |
9885 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9886 | } | |
9887 | ||
9888 | /* Implementation of "catch throw" command. */ | |
9889 | ||
9890 | static void | |
9891 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9892 | { | |
9893 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9894 | |
44feb3ce TT |
9895 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9896 | } | |
9897 | ||
f7f9143b JB |
9898 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
9899 | ||
9900 | static void | |
a6d9a66e UW |
9901 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
9902 | struct symtab_and_line sal, | |
f7f9143b JB |
9903 | char *addr_string, |
9904 | char *exp_string, | |
9905 | char *cond_string, | |
9906 | struct expression *cond, | |
9907 | struct breakpoint_ops *ops, | |
9908 | int tempflag, | |
9909 | int from_tty) | |
9910 | { | |
9911 | struct breakpoint *b; | |
9912 | ||
9913 | if (from_tty) | |
9914 | { | |
5af949e3 UW |
9915 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9916 | if (!loc_gdbarch) | |
9917 | loc_gdbarch = gdbarch; | |
9918 | ||
6c95b8df PA |
9919 | describe_other_breakpoints (loc_gdbarch, |
9920 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9921 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9922 | version for exception catchpoints, because two catchpoints | |
9923 | used for different exception names will use the same address. | |
9924 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9925 | unproductive. Besides, the warning phrasing is also a bit |
f7f9143b JB |
9926 | inapropriate, we should use the word catchpoint, and tell |
9927 | the user what type of catchpoint it is. The above is good | |
9928 | enough for now, though. */ | |
9929 | } | |
9930 | ||
a6d9a66e | 9931 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
9932 | set_breakpoint_count (breakpoint_count + 1); |
9933 | ||
9934 | b->enable_state = bp_enabled; | |
9935 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
9936 | b->number = breakpoint_count; | |
9937 | b->ignore_count = 0; | |
511a6cd4 | 9938 | b->loc->cond = cond; |
f7f9143b JB |
9939 | b->addr_string = addr_string; |
9940 | b->language = language_ada; | |
9941 | b->cond_string = cond_string; | |
9942 | b->exp_string = exp_string; | |
9943 | b->thread = -1; | |
9944 | b->ops = ops; | |
f7f9143b JB |
9945 | |
9946 | mention (b); | |
8d3788bd | 9947 | observer_notify_breakpoint_created (b); |
b60e7edf | 9948 | update_global_location_list (1); |
f7f9143b JB |
9949 | } |
9950 | ||
9951 | /* Implement the "catch exception" command. */ | |
9952 | ||
9953 | static void | |
44feb3ce TT |
9954 | catch_ada_exception_command (char *arg, int from_tty, |
9955 | struct cmd_list_element *command) | |
f7f9143b | 9956 | { |
a6d9a66e | 9957 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9958 | int tempflag; |
f7f9143b | 9959 | struct symtab_and_line sal; |
f7f9143b JB |
9960 | char *addr_string = NULL; |
9961 | char *exp_string = NULL; | |
9962 | char *cond_string = NULL; | |
9963 | struct expression *cond = NULL; | |
9964 | struct breakpoint_ops *ops = NULL; | |
9965 | ||
44feb3ce TT |
9966 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9967 | ||
9968 | if (!arg) | |
9969 | arg = ""; | |
f7f9143b JB |
9970 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
9971 | &cond_string, &cond, &ops); | |
a6d9a66e | 9972 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
9973 | cond_string, cond, ops, tempflag, |
9974 | from_tty); | |
9975 | } | |
9976 | ||
a96d9b2e SDJ |
9977 | /* Cleanup function for a syscall filter list. */ |
9978 | static void | |
9979 | clean_up_filters (void *arg) | |
9980 | { | |
9981 | VEC(int) *iter = *(VEC(int) **) arg; | |
9982 | VEC_free (int, iter); | |
9983 | } | |
9984 | ||
9985 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
9986 | filter list, or NULL if no filtering is required. */ | |
9987 | static VEC(int) * | |
9988 | catch_syscall_split_args (char *arg) | |
9989 | { | |
9990 | VEC(int) *result = NULL; | |
9991 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
9992 | ||
9993 | while (*arg != '\0') | |
9994 | { | |
9995 | int i, syscall_number; | |
9996 | char *endptr; | |
9997 | char cur_name[128]; | |
9998 | struct syscall s; | |
9999 | ||
10000 | /* Skip whitespace. */ | |
10001 | while (isspace (*arg)) | |
10002 | arg++; | |
10003 | ||
10004 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10005 | cur_name[i] = arg[i]; | |
10006 | cur_name[i] = '\0'; | |
10007 | arg += i; | |
10008 | ||
10009 | /* Check if the user provided a syscall name or a number. */ | |
10010 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10011 | if (*endptr == '\0') | |
bccd0dd2 | 10012 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10013 | else |
10014 | { | |
10015 | /* We have a name. Let's check if it's valid and convert it | |
10016 | to a number. */ | |
10017 | get_syscall_by_name (cur_name, &s); | |
10018 | ||
10019 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10020 | /* Here we have to issue an error instead of a warning, |
10021 | because GDB cannot do anything useful if there's no | |
10022 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10023 | error (_("Unknown syscall name '%s'."), cur_name); |
10024 | } | |
10025 | ||
10026 | /* Ok, it's valid. */ | |
10027 | VEC_safe_push (int, result, s.number); | |
10028 | } | |
10029 | ||
10030 | discard_cleanups (cleanup); | |
10031 | return result; | |
10032 | } | |
10033 | ||
10034 | /* Implement the "catch syscall" command. */ | |
10035 | ||
10036 | static void | |
cc59ec59 MS |
10037 | catch_syscall_command_1 (char *arg, int from_tty, |
10038 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10039 | { |
10040 | int tempflag; | |
10041 | VEC(int) *filter; | |
10042 | struct syscall s; | |
10043 | struct gdbarch *gdbarch = get_current_arch (); | |
10044 | ||
10045 | /* Checking if the feature if supported. */ | |
10046 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10047 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10048 | this architecture yet.")); |
a96d9b2e SDJ |
10049 | |
10050 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10051 | ||
e9cafbcc | 10052 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10053 | |
10054 | /* We need to do this first "dummy" translation in order | |
10055 | to get the syscall XML file loaded or, most important, | |
10056 | to display a warning to the user if there's no XML file | |
10057 | for his/her architecture. */ | |
10058 | get_syscall_by_number (0, &s); | |
10059 | ||
10060 | /* The allowed syntax is: | |
10061 | catch syscall | |
10062 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10063 | ||
10064 | Let's check if there's a syscall name. */ | |
10065 | ||
10066 | if (arg != NULL) | |
10067 | filter = catch_syscall_split_args (arg); | |
10068 | else | |
10069 | filter = NULL; | |
10070 | ||
10071 | create_syscall_event_catchpoint (tempflag, filter, | |
10072 | &catch_syscall_breakpoint_ops); | |
10073 | } | |
10074 | ||
f7f9143b JB |
10075 | /* Implement the "catch assert" command. */ |
10076 | ||
10077 | static void | |
3e43a32a MS |
10078 | catch_assert_command (char *arg, int from_tty, |
10079 | struct cmd_list_element *command) | |
f7f9143b | 10080 | { |
a6d9a66e | 10081 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 10082 | int tempflag; |
f7f9143b JB |
10083 | struct symtab_and_line sal; |
10084 | char *addr_string = NULL; | |
10085 | struct breakpoint_ops *ops = NULL; | |
10086 | ||
44feb3ce TT |
10087 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
10088 | ||
10089 | if (!arg) | |
10090 | arg = ""; | |
f7f9143b | 10091 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
10092 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
10093 | ops, tempflag, from_tty); | |
f7f9143b JB |
10094 | } |
10095 | ||
c906108c | 10096 | static void |
fba45db2 | 10097 | catch_command (char *arg, int from_tty) |
c906108c | 10098 | { |
44feb3ce | 10099 | error (_("Catch requires an event name.")); |
c906108c SS |
10100 | } |
10101 | \f | |
10102 | ||
10103 | static void | |
fba45db2 | 10104 | tcatch_command (char *arg, int from_tty) |
c906108c | 10105 | { |
44feb3ce | 10106 | error (_("Catch requires an event name.")); |
c906108c SS |
10107 | } |
10108 | ||
80f8a6eb | 10109 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10110 | |
10111 | static void | |
fba45db2 | 10112 | clear_command (char *arg, int from_tty) |
c906108c | 10113 | { |
d6e956e5 VP |
10114 | struct breakpoint *b; |
10115 | VEC(breakpoint_p) *found = 0; | |
10116 | int ix; | |
c906108c SS |
10117 | int default_match; |
10118 | struct symtabs_and_lines sals; | |
10119 | struct symtab_and_line sal; | |
c906108c SS |
10120 | int i; |
10121 | ||
10122 | if (arg) | |
10123 | { | |
10124 | sals = decode_line_spec (arg, 1); | |
10125 | default_match = 0; | |
10126 | } | |
10127 | else | |
10128 | { | |
c5aa993b | 10129 | sals.sals = (struct symtab_and_line *) |
c906108c | 10130 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10131 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10132 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
10133 | sal.line = default_breakpoint_line; |
10134 | sal.symtab = default_breakpoint_symtab; | |
10135 | sal.pc = default_breakpoint_address; | |
6c95b8df | 10136 | sal.pspace = default_breakpoint_pspace; |
c906108c | 10137 | if (sal.symtab == 0) |
8a3fe4f8 | 10138 | error (_("No source file specified.")); |
c906108c SS |
10139 | |
10140 | sals.sals[0] = sal; | |
10141 | sals.nelts = 1; | |
10142 | ||
10143 | default_match = 1; | |
10144 | } | |
10145 | ||
4a64f543 MS |
10146 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10147 | seems, because all existing breakpoints typically have both | |
10148 | file/line and pc set. So, if clear is given file/line, we can | |
10149 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10150 | |
10151 | We only support clearing given the address explicitly | |
10152 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10153 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10154 | due to optimization, all in one block. |
4a64f543 MS |
10155 | |
10156 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10157 | PC corresponding to the same file:line, the breakpoint won't |
10158 | be cleared. We probably can still clear the breakpoint, but | |
10159 | since the other PC value is never presented to user, user | |
10160 | can only find it by guessing, and it does not seem important | |
10161 | to support that. */ | |
10162 | ||
4a64f543 MS |
10163 | /* For each line spec given, delete bps which correspond to it. Do |
10164 | it in two passes, solely to preserve the current behavior that | |
10165 | from_tty is forced true if we delete more than one | |
10166 | breakpoint. */ | |
c906108c | 10167 | |
80f8a6eb | 10168 | found = NULL; |
c906108c SS |
10169 | for (i = 0; i < sals.nelts; i++) |
10170 | { | |
10171 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
10172 | If line given (pc == 0), clear all bpts on specified line. |
10173 | If defaulting, clear all bpts on default line | |
c906108c | 10174 | or at default pc. |
c5aa993b JM |
10175 | |
10176 | defaulting sal.pc != 0 tests to do | |
10177 | ||
10178 | 0 1 pc | |
10179 | 1 1 pc _and_ line | |
10180 | 0 0 line | |
10181 | 1 0 <can't happen> */ | |
c906108c SS |
10182 | |
10183 | sal = sals.sals[i]; | |
c906108c | 10184 | |
4a64f543 | 10185 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10186 | ALL_BREAKPOINTS (b) |
c5aa993b | 10187 | { |
0d381245 | 10188 | int match = 0; |
4a64f543 | 10189 | /* Are we going to delete b? */ |
cc60f2e3 | 10190 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10191 | { |
10192 | struct bp_location *loc = b->loc; | |
10193 | for (; loc; loc = loc->next) | |
10194 | { | |
6c95b8df PA |
10195 | int pc_match = sal.pc |
10196 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
10197 | && (loc->address == sal.pc) |
10198 | && (!section_is_overlay (loc->section) | |
10199 | || loc->section == sal.section); | |
10200 | int line_match = ((default_match || (0 == sal.pc)) | |
10201 | && b->source_file != NULL | |
10202 | && sal.symtab != NULL | |
6c95b8df | 10203 | && sal.pspace == loc->pspace |
0ba1096a KT |
10204 | && filename_cmp (b->source_file, |
10205 | sal.symtab->filename) == 0 | |
0d381245 VP |
10206 | && b->line_number == sal.line); |
10207 | if (pc_match || line_match) | |
10208 | { | |
10209 | match = 1; | |
10210 | break; | |
10211 | } | |
10212 | } | |
10213 | } | |
10214 | ||
10215 | if (match) | |
d6e956e5 | 10216 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10217 | } |
80f8a6eb MS |
10218 | } |
10219 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 10220 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10221 | { |
10222 | if (arg) | |
8a3fe4f8 | 10223 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10224 | else |
8a3fe4f8 | 10225 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10226 | } |
c906108c | 10227 | |
d6e956e5 | 10228 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10229 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10230 | if (from_tty) |
a3f17187 | 10231 | { |
d6e956e5 | 10232 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10233 | printf_unfiltered (_("Deleted breakpoint ")); |
10234 | else | |
10235 | printf_unfiltered (_("Deleted breakpoints ")); | |
10236 | } | |
80f8a6eb | 10237 | breakpoints_changed (); |
d6e956e5 VP |
10238 | |
10239 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10240 | { |
c5aa993b | 10241 | if (from_tty) |
d6e956e5 VP |
10242 | printf_unfiltered ("%d ", b->number); |
10243 | delete_breakpoint (b); | |
c906108c | 10244 | } |
80f8a6eb MS |
10245 | if (from_tty) |
10246 | putchar_unfiltered ('\n'); | |
c906108c SS |
10247 | } |
10248 | \f | |
10249 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10250 | all breakpoints that are marked for deletion, whether hit or not. | |
10251 | This is called after any breakpoint is hit, or after errors. */ | |
10252 | ||
10253 | void | |
fba45db2 | 10254 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10255 | { |
35df4500 | 10256 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10257 | |
10258 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10259 | if (bs->breakpoint_at |
10260 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10261 | && bs->stop) |
f431efe5 | 10262 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10263 | |
35df4500 | 10264 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10265 | { |
b5de0fa7 | 10266 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10267 | delete_breakpoint (b); |
10268 | } | |
c906108c SS |
10269 | } |
10270 | ||
4a64f543 MS |
10271 | /* A comparison function for bp_location AP and BP being interfaced to |
10272 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10273 | does breakpoint_address_is_meaningful say for its OWNER), | |
10274 | secondarily by ordering first bp_permanent OWNERed elements and | |
10275 | terciarily just ensuring the array is sorted stable way despite | |
10276 | qsort being an instable algorithm. */ | |
876fa593 JK |
10277 | |
10278 | static int | |
494cfb0f | 10279 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10280 | { |
494cfb0f JK |
10281 | struct bp_location *a = *(void **) ap; |
10282 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10283 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10284 | int a_perm = a->owner->enable_state == bp_permanent; |
10285 | int b_perm = b->owner->enable_state == bp_permanent; | |
10286 | ||
10287 | if (a->address != b->address) | |
10288 | return (a->address > b->address) - (a->address < b->address); | |
10289 | ||
10290 | /* Sort permanent breakpoints first. */ | |
10291 | if (a_perm != b_perm) | |
10292 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10293 | ||
4a64f543 MS |
10294 | /* Make the user-visible order stable across GDB runs. Locations of |
10295 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10296 | |
10297 | if (a->owner->number != b->owner->number) | |
10298 | return (a->owner->number > b->owner->number) | |
10299 | - (a->owner->number < b->owner->number); | |
10300 | ||
10301 | return (a > b) - (a < b); | |
10302 | } | |
10303 | ||
876fa593 | 10304 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10305 | bp_location_shadow_len_after_address_max according to the current |
10306 | content of the bp_location array. */ | |
f7545552 TT |
10307 | |
10308 | static void | |
876fa593 | 10309 | bp_location_target_extensions_update (void) |
f7545552 | 10310 | { |
876fa593 JK |
10311 | struct bp_location *bl, **blp_tmp; |
10312 | ||
10313 | bp_location_placed_address_before_address_max = 0; | |
10314 | bp_location_shadow_len_after_address_max = 0; | |
10315 | ||
10316 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10317 | { | |
10318 | CORE_ADDR start, end, addr; | |
10319 | ||
10320 | if (!bp_location_has_shadow (bl)) | |
10321 | continue; | |
10322 | ||
10323 | start = bl->target_info.placed_address; | |
10324 | end = start + bl->target_info.shadow_len; | |
10325 | ||
10326 | gdb_assert (bl->address >= start); | |
10327 | addr = bl->address - start; | |
10328 | if (addr > bp_location_placed_address_before_address_max) | |
10329 | bp_location_placed_address_before_address_max = addr; | |
10330 | ||
10331 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10332 | ||
10333 | gdb_assert (bl->address < end); | |
10334 | addr = end - bl->address; | |
10335 | if (addr > bp_location_shadow_len_after_address_max) | |
10336 | bp_location_shadow_len_after_address_max = addr; | |
10337 | } | |
f7545552 TT |
10338 | } |
10339 | ||
4cd9bd08 | 10340 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10341 | into the inferior, only remove already-inserted locations that no |
10342 | longer should be inserted. Functions that delete a breakpoint or | |
10343 | breakpoints should pass false, so that deleting a breakpoint | |
10344 | doesn't have the side effect of inserting the locations of other | |
10345 | breakpoints that are marked not-inserted, but should_be_inserted | |
10346 | returns true on them. | |
10347 | ||
10348 | This behaviour is useful is situations close to tear-down -- e.g., | |
10349 | after an exec, while the target still has execution, but breakpoint | |
10350 | shadows of the previous executable image should *NOT* be restored | |
10351 | to the new image; or before detaching, where the target still has | |
10352 | execution and wants to delete breakpoints from GDB's lists, and all | |
10353 | breakpoints had already been removed from the inferior. */ | |
10354 | ||
0d381245 | 10355 | static void |
b60e7edf | 10356 | update_global_location_list (int should_insert) |
0d381245 | 10357 | { |
74960c60 | 10358 | struct breakpoint *b; |
876fa593 | 10359 | struct bp_location **locp, *loc; |
f7545552 TT |
10360 | struct cleanup *cleanups; |
10361 | ||
2d134ed3 PA |
10362 | /* Used in the duplicates detection below. When iterating over all |
10363 | bp_locations, points to the first bp_location of a given address. | |
10364 | Breakpoints and watchpoints of different types are never | |
10365 | duplicates of each other. Keep one pointer for each type of | |
10366 | breakpoint/watchpoint, so we only need to loop over all locations | |
10367 | once. */ | |
10368 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10369 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10370 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10371 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10372 | |
4a64f543 MS |
10373 | /* Saved former bp_location array which we compare against the newly |
10374 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10375 | struct bp_location **old_location, **old_locp; |
10376 | unsigned old_location_count; | |
10377 | ||
10378 | old_location = bp_location; | |
10379 | old_location_count = bp_location_count; | |
10380 | bp_location = NULL; | |
10381 | bp_location_count = 0; | |
10382 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10383 | |
74960c60 | 10384 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10385 | for (loc = b->loc; loc; loc = loc->next) |
10386 | bp_location_count++; | |
10387 | ||
10388 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10389 | locp = bp_location; | |
10390 | ALL_BREAKPOINTS (b) | |
10391 | for (loc = b->loc; loc; loc = loc->next) | |
10392 | *locp++ = loc; | |
10393 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10394 | bp_location_compare); |
876fa593 JK |
10395 | |
10396 | bp_location_target_extensions_update (); | |
74960c60 | 10397 | |
4a64f543 MS |
10398 | /* Identify bp_location instances that are no longer present in the |
10399 | new list, and therefore should be freed. Note that it's not | |
10400 | necessary that those locations should be removed from inferior -- | |
10401 | if there's another location at the same address (previously | |
10402 | marked as duplicate), we don't need to remove/insert the | |
10403 | location. | |
876fa593 | 10404 | |
4a64f543 MS |
10405 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10406 | and former bp_location array state respectively. */ | |
876fa593 JK |
10407 | |
10408 | locp = bp_location; | |
10409 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10410 | old_locp++) | |
74960c60 | 10411 | { |
876fa593 | 10412 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10413 | struct bp_location **loc2p; |
876fa593 | 10414 | |
4a64f543 MS |
10415 | /* Tells if 'old_loc' is found amoung the new locations. If |
10416 | not, we have to free it. */ | |
c7d46a38 | 10417 | int found_object = 0; |
20874c92 VP |
10418 | /* Tells if the location should remain inserted in the target. */ |
10419 | int keep_in_target = 0; | |
10420 | int removed = 0; | |
876fa593 | 10421 | |
4a64f543 MS |
10422 | /* Skip LOCP entries which will definitely never be needed. |
10423 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10424 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10425 | && (*locp)->address < old_loc->address) |
876fa593 | 10426 | locp++; |
c7d46a38 PA |
10427 | |
10428 | for (loc2p = locp; | |
10429 | (loc2p < bp_location + bp_location_count | |
10430 | && (*loc2p)->address == old_loc->address); | |
10431 | loc2p++) | |
10432 | { | |
10433 | if (*loc2p == old_loc) | |
10434 | { | |
10435 | found_object = 1; | |
10436 | break; | |
10437 | } | |
10438 | } | |
74960c60 | 10439 | |
4a64f543 MS |
10440 | /* If this location is no longer present, and inserted, look if |
10441 | there's maybe a new location at the same address. If so, | |
10442 | mark that one inserted, and don't remove this one. This is | |
10443 | needed so that we don't have a time window where a breakpoint | |
10444 | at certain location is not inserted. */ | |
74960c60 | 10445 | |
876fa593 | 10446 | if (old_loc->inserted) |
0d381245 | 10447 | { |
4a64f543 MS |
10448 | /* If the location is inserted now, we might have to remove |
10449 | it. */ | |
74960c60 | 10450 | |
876fa593 | 10451 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10452 | { |
4a64f543 MS |
10453 | /* The location is still present in the location list, |
10454 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10455 | keep_in_target = 1; |
74960c60 VP |
10456 | } |
10457 | else | |
10458 | { | |
4a64f543 MS |
10459 | /* The location is either no longer present, or got |
10460 | disabled. See if there's another location at the | |
10461 | same address, in which case we don't need to remove | |
10462 | this one from the target. */ | |
876fa593 | 10463 | |
2bdf28a0 | 10464 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10465 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10466 | { | |
876fa593 | 10467 | for (loc2p = locp; |
c7d46a38 PA |
10468 | (loc2p < bp_location + bp_location_count |
10469 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10470 | loc2p++) |
10471 | { | |
10472 | struct bp_location *loc2 = *loc2p; | |
10473 | ||
2d134ed3 | 10474 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
10475 | { |
10476 | /* For the sake of should_be_inserted. | |
4a64f543 MS |
10477 | Duplicates check below will fix up this |
10478 | later. */ | |
c7d46a38 | 10479 | loc2->duplicate = 0; |
85d721b8 PA |
10480 | |
10481 | /* Read watchpoint locations are switched to | |
10482 | access watchpoints, if the former are not | |
10483 | supported, but the latter are. */ | |
10484 | if (is_hardware_watchpoint (old_loc->owner)) | |
10485 | { | |
10486 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10487 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10488 | } | |
10489 | ||
c7d46a38 PA |
10490 | if (loc2 != old_loc && should_be_inserted (loc2)) |
10491 | { | |
10492 | loc2->inserted = 1; | |
10493 | loc2->target_info = old_loc->target_info; | |
10494 | keep_in_target = 1; | |
10495 | break; | |
10496 | } | |
876fa593 JK |
10497 | } |
10498 | } | |
10499 | } | |
74960c60 VP |
10500 | } |
10501 | ||
20874c92 VP |
10502 | if (!keep_in_target) |
10503 | { | |
876fa593 | 10504 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10505 | { |
4a64f543 MS |
10506 | /* This is just about all we can do. We could keep |
10507 | this location on the global list, and try to | |
10508 | remove it next time, but there's no particular | |
10509 | reason why we will succeed next time. | |
20874c92 | 10510 | |
4a64f543 MS |
10511 | Note that at this point, old_loc->owner is still |
10512 | valid, as delete_breakpoint frees the breakpoint | |
10513 | only after calling us. */ | |
3e43a32a MS |
10514 | printf_filtered (_("warning: Error removing " |
10515 | "breakpoint %d\n"), | |
876fa593 | 10516 | old_loc->owner->number); |
20874c92 VP |
10517 | } |
10518 | removed = 1; | |
10519 | } | |
0d381245 | 10520 | } |
74960c60 VP |
10521 | |
10522 | if (!found_object) | |
1c5cfe86 | 10523 | { |
db82e815 PA |
10524 | if (removed && non_stop |
10525 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10526 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10527 | { |
db82e815 PA |
10528 | /* This location was removed from the target. In |
10529 | non-stop mode, a race condition is possible where | |
10530 | we've removed a breakpoint, but stop events for that | |
10531 | breakpoint are already queued and will arrive later. | |
10532 | We apply an heuristic to be able to distinguish such | |
10533 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10534 | breakpoint location for a bit, and will retire it | |
10535 | after we see some number of events. The theory here | |
10536 | is that reporting of events should, "on the average", | |
10537 | be fair, so after a while we'll see events from all | |
10538 | threads that have anything of interest, and no longer | |
10539 | need to keep this breakpoint location around. We | |
10540 | don't hold locations forever so to reduce chances of | |
10541 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10542 | SIGTRAP. | |
10543 | ||
10544 | The heuristic failing can be disastrous on | |
10545 | decr_pc_after_break targets. | |
10546 | ||
10547 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10548 | if we fail to recognize a late breakpoint SIGTRAP, | |
10549 | because events_till_retirement has reached 0 too | |
10550 | soon, we'll fail to do the PC adjustment, and report | |
10551 | a random SIGTRAP to the user. When the user resumes | |
10552 | the inferior, it will most likely immediately crash | |
2dec564e | 10553 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10554 | corrupted, because of being resumed e.g., in the |
10555 | middle of a multi-byte instruction, or skipped a | |
10556 | one-byte instruction. This was actually seen happen | |
10557 | on native x86-linux, and should be less rare on | |
10558 | targets that do not support new thread events, like | |
10559 | remote, due to the heuristic depending on | |
10560 | thread_count. | |
10561 | ||
10562 | Mistaking a random SIGTRAP for a breakpoint trap | |
10563 | causes similar symptoms (PC adjustment applied when | |
10564 | it shouldn't), but then again, playing with SIGTRAPs | |
10565 | behind the debugger's back is asking for trouble. | |
10566 | ||
10567 | Since hardware watchpoint traps are always | |
10568 | distinguishable from other traps, so we don't need to | |
10569 | apply keep hardware watchpoint moribund locations | |
10570 | around. We simply always ignore hardware watchpoint | |
10571 | traps we can no longer explain. */ | |
10572 | ||
876fa593 JK |
10573 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10574 | old_loc->owner = NULL; | |
20874c92 | 10575 | |
876fa593 | 10576 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10577 | } |
10578 | else | |
f431efe5 PA |
10579 | { |
10580 | old_loc->owner = NULL; | |
10581 | decref_bp_location (&old_loc); | |
10582 | } | |
20874c92 | 10583 | } |
74960c60 | 10584 | } |
1c5cfe86 | 10585 | |
2d134ed3 PA |
10586 | /* Rescan breakpoints at the same address and section, marking the |
10587 | first one as "first" and any others as "duplicates". This is so | |
10588 | that the bpt instruction is only inserted once. If we have a | |
10589 | permanent breakpoint at the same place as BPT, make that one the | |
10590 | official one, and the rest as duplicates. Permanent breakpoints | |
10591 | are sorted first for the same address. | |
10592 | ||
10593 | Do the same for hardware watchpoints, but also considering the | |
10594 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 10595 | |
2d134ed3 PA |
10596 | bp_loc_first = NULL; |
10597 | wp_loc_first = NULL; | |
10598 | awp_loc_first = NULL; | |
10599 | rwp_loc_first = NULL; | |
876fa593 | 10600 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 10601 | { |
4a64f543 MS |
10602 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
10603 | non-NULL. */ | |
876fa593 | 10604 | struct breakpoint *b = loc->owner; |
2d134ed3 | 10605 | struct bp_location **loc_first_p; |
876fa593 JK |
10606 | |
10607 | if (b->enable_state == bp_disabled | |
10608 | || b->enable_state == bp_call_disabled | |
10609 | || b->enable_state == bp_startup_disabled | |
10610 | || !loc->enabled | |
10611 | || loc->shlib_disabled | |
15c3d785 | 10612 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 10613 | || is_tracepoint (b)) |
876fa593 JK |
10614 | continue; |
10615 | ||
10616 | /* Permanent breakpoint should always be inserted. */ | |
10617 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10618 | internal_error (__FILE__, __LINE__, | |
10619 | _("allegedly permanent breakpoint is not " | |
10620 | "actually inserted")); | |
10621 | ||
2d134ed3 PA |
10622 | if (b->type == bp_hardware_watchpoint) |
10623 | loc_first_p = &wp_loc_first; | |
10624 | else if (b->type == bp_read_watchpoint) | |
10625 | loc_first_p = &rwp_loc_first; | |
10626 | else if (b->type == bp_access_watchpoint) | |
10627 | loc_first_p = &awp_loc_first; | |
10628 | else | |
10629 | loc_first_p = &bp_loc_first; | |
10630 | ||
10631 | if (*loc_first_p == NULL | |
10632 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10633 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 10634 | { |
2d134ed3 | 10635 | *loc_first_p = loc; |
876fa593 JK |
10636 | loc->duplicate = 0; |
10637 | continue; | |
10638 | } | |
10639 | ||
10640 | loc->duplicate = 1; | |
10641 | ||
2d134ed3 PA |
10642 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
10643 | && b->enable_state != bp_permanent) | |
876fa593 JK |
10644 | internal_error (__FILE__, __LINE__, |
10645 | _("another breakpoint was inserted on top of " | |
10646 | "a permanent breakpoint")); | |
0d381245 | 10647 | } |
74960c60 | 10648 | |
50c71eaf | 10649 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 10650 | && (have_live_inferiors () |
2567c7d9 | 10651 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 10652 | insert_breakpoint_locations (); |
f7545552 TT |
10653 | |
10654 | do_cleanups (cleanups); | |
74960c60 VP |
10655 | } |
10656 | ||
20874c92 VP |
10657 | void |
10658 | breakpoint_retire_moribund (void) | |
10659 | { | |
10660 | struct bp_location *loc; | |
10661 | int ix; | |
10662 | ||
10663 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10664 | if (--(loc->events_till_retirement) == 0) | |
10665 | { | |
f431efe5 | 10666 | decref_bp_location (&loc); |
20874c92 VP |
10667 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
10668 | --ix; | |
10669 | } | |
10670 | } | |
10671 | ||
74960c60 | 10672 | static void |
b60e7edf | 10673 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
10674 | { |
10675 | struct gdb_exception e; | |
cc59ec59 | 10676 | |
74960c60 | 10677 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 10678 | update_global_location_list (inserting); |
0d381245 VP |
10679 | } |
10680 | ||
f431efe5 PA |
10681 | /* Clear BKP from a BPS. */ |
10682 | ||
a474d7c2 | 10683 | static void |
f431efe5 | 10684 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
10685 | { |
10686 | bpstat bs; | |
cc59ec59 | 10687 | |
a474d7c2 | 10688 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 10689 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
10690 | { |
10691 | bs->breakpoint_at = NULL; | |
10692 | bs->old_val = NULL; | |
10693 | /* bs->commands will be freed later. */ | |
10694 | } | |
10695 | } | |
10696 | ||
10697 | /* Callback for iterate_over_threads. */ | |
10698 | static int | |
f431efe5 | 10699 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 10700 | { |
f431efe5 | 10701 | struct breakpoint *bpt = data; |
cc59ec59 | 10702 | |
16c381f0 | 10703 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
a474d7c2 PA |
10704 | return 0; |
10705 | } | |
10706 | ||
53a5351d | 10707 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 10708 | structures. */ |
c906108c SS |
10709 | |
10710 | void | |
fba45db2 | 10711 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 10712 | { |
52f0bd74 | 10713 | struct breakpoint *b; |
c906108c | 10714 | |
8a3fe4f8 | 10715 | gdb_assert (bpt != NULL); |
c906108c | 10716 | |
4a64f543 MS |
10717 | /* Has this bp already been deleted? This can happen because |
10718 | multiple lists can hold pointers to bp's. bpstat lists are | |
10719 | especial culprits. | |
10720 | ||
10721 | One example of this happening is a watchpoint's scope bp. When | |
10722 | the scope bp triggers, we notice that the watchpoint is out of | |
10723 | scope, and delete it. We also delete its scope bp. But the | |
10724 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
10725 | That bpstat is then checked for auto-deleting bp's, which are | |
10726 | deleted. | |
10727 | ||
10728 | A real solution to this problem might involve reference counts in | |
10729 | bp's, and/or giving them pointers back to their referencing | |
10730 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
10731 | storage when no more references were extent. A cheaper bandaid | |
10732 | was chosen. */ | |
c906108c SS |
10733 | if (bpt->type == bp_none) |
10734 | return; | |
10735 | ||
4a64f543 MS |
10736 | /* At least avoid this stale reference until the reference counting |
10737 | of breakpoints gets resolved. */ | |
d0fb5eae | 10738 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 10739 | { |
d0fb5eae JK |
10740 | struct breakpoint *related; |
10741 | ||
10742 | if (bpt->type == bp_watchpoint_scope) | |
10743 | watchpoint_del_at_next_stop (bpt->related_breakpoint); | |
10744 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) | |
10745 | watchpoint_del_at_next_stop (bpt); | |
10746 | ||
10747 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
10748 | for (related = bpt; related->related_breakpoint != bpt; | |
10749 | related = related->related_breakpoint); | |
10750 | related->related_breakpoint = bpt->related_breakpoint; | |
10751 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
10752 | } |
10753 | ||
a9634178 TJB |
10754 | /* watch_command_1 creates a watchpoint but only sets its number if |
10755 | update_watchpoint succeeds in creating its bp_locations. If there's | |
10756 | a problem in that process, we'll be asked to delete the half-created | |
10757 | watchpoint. In that case, don't announce the deletion. */ | |
10758 | if (bpt->number) | |
10759 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 10760 | |
c906108c SS |
10761 | if (breakpoint_chain == bpt) |
10762 | breakpoint_chain = bpt->next; | |
10763 | ||
c906108c SS |
10764 | ALL_BREAKPOINTS (b) |
10765 | if (b->next == bpt) | |
c5aa993b JM |
10766 | { |
10767 | b->next = bpt->next; | |
10768 | break; | |
10769 | } | |
c906108c | 10770 | |
9add0f1b | 10771 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
10772 | xfree (bpt->cond_string); |
10773 | xfree (bpt->cond_exp); | |
10774 | xfree (bpt->addr_string); | |
f1310107 | 10775 | xfree (bpt->addr_string_range_end); |
60e1c644 PA |
10776 | xfree (bpt->exp); |
10777 | xfree (bpt->exp_string); | |
d63d0675 | 10778 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
10779 | value_free (bpt->val); |
10780 | xfree (bpt->source_file); | |
10781 | xfree (bpt->exec_pathname); | |
a96d9b2e | 10782 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 10783 | |
f431efe5 PA |
10784 | |
10785 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
10786 | been freed. */ | |
10787 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
10788 | in all threeds for now. Note that we cannot just remove bpstats | |
10789 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
10790 | commands are associated with the bpstat; if we remove it here, | |
10791 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
10792 | event-top.c won't do anything, and temporary breakpoints with | |
10793 | commands won't work. */ | |
10794 | ||
10795 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
10796 | ||
4a64f543 MS |
10797 | /* Now that breakpoint is removed from breakpoint list, update the |
10798 | global location list. This will remove locations that used to | |
10799 | belong to this breakpoint. Do this before freeing the breakpoint | |
10800 | itself, since remove_breakpoint looks at location's owner. It | |
10801 | might be better design to have location completely | |
10802 | self-contained, but it's not the case now. */ | |
b60e7edf | 10803 | update_global_location_list (0); |
74960c60 VP |
10804 | |
10805 | ||
4a64f543 MS |
10806 | /* On the chance that someone will soon try again to delete this |
10807 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c SS |
10808 | bpt->type = bp_none; |
10809 | ||
b8c9b27d | 10810 | xfree (bpt); |
c906108c SS |
10811 | } |
10812 | ||
4d6140d9 AC |
10813 | static void |
10814 | do_delete_breakpoint_cleanup (void *b) | |
10815 | { | |
10816 | delete_breakpoint (b); | |
10817 | } | |
10818 | ||
10819 | struct cleanup * | |
10820 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
10821 | { | |
10822 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
10823 | } | |
10824 | ||
95a42b64 TT |
10825 | /* A callback for map_breakpoint_numbers that calls |
10826 | delete_breakpoint. */ | |
10827 | ||
10828 | static void | |
10829 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
10830 | { | |
10831 | delete_breakpoint (b); | |
10832 | } | |
10833 | ||
c906108c | 10834 | void |
fba45db2 | 10835 | delete_command (char *arg, int from_tty) |
c906108c | 10836 | { |
35df4500 | 10837 | struct breakpoint *b, *b_tmp; |
c906108c | 10838 | |
ea9365bb TT |
10839 | dont_repeat (); |
10840 | ||
c906108c SS |
10841 | if (arg == 0) |
10842 | { | |
10843 | int breaks_to_delete = 0; | |
10844 | ||
46c6471b PA |
10845 | /* Delete all breakpoints if no argument. Do not delete |
10846 | internal breakpoints, these have to be deleted with an | |
10847 | explicit breakpoint number argument. */ | |
c5aa993b | 10848 | ALL_BREAKPOINTS (b) |
46c6471b | 10849 | if (user_breakpoint_p (b)) |
973d738b DJ |
10850 | { |
10851 | breaks_to_delete = 1; | |
10852 | break; | |
10853 | } | |
c906108c SS |
10854 | |
10855 | /* Ask user only if there are some breakpoints to delete. */ | |
10856 | if (!from_tty | |
e2e0b3e5 | 10857 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 10858 | { |
35df4500 | 10859 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 10860 | if (user_breakpoint_p (b)) |
c5aa993b | 10861 | delete_breakpoint (b); |
c906108c SS |
10862 | } |
10863 | } | |
10864 | else | |
95a42b64 | 10865 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
c906108c SS |
10866 | } |
10867 | ||
0d381245 VP |
10868 | static int |
10869 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 10870 | { |
0d381245 VP |
10871 | for (; loc; loc = loc->next) |
10872 | if (!loc->shlib_disabled) | |
10873 | return 0; | |
10874 | return 1; | |
fe3f5fa8 VP |
10875 | } |
10876 | ||
776592bf DE |
10877 | /* Subroutine of update_breakpoint_locations to simplify it. |
10878 | Return non-zero if multiple fns in list LOC have the same name. | |
10879 | Null names are ignored. */ | |
10880 | ||
10881 | static int | |
10882 | ambiguous_names_p (struct bp_location *loc) | |
10883 | { | |
10884 | struct bp_location *l; | |
10885 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
10886 | (int (*) (const void *, |
10887 | const void *)) streq, | |
776592bf DE |
10888 | NULL, xcalloc, xfree); |
10889 | ||
10890 | for (l = loc; l != NULL; l = l->next) | |
10891 | { | |
10892 | const char **slot; | |
10893 | const char *name = l->function_name; | |
10894 | ||
10895 | /* Allow for some names to be NULL, ignore them. */ | |
10896 | if (name == NULL) | |
10897 | continue; | |
10898 | ||
10899 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
10900 | INSERT); | |
4a64f543 MS |
10901 | /* NOTE: We can assume slot != NULL here because xcalloc never |
10902 | returns NULL. */ | |
776592bf DE |
10903 | if (*slot != NULL) |
10904 | { | |
10905 | htab_delete (htab); | |
10906 | return 1; | |
10907 | } | |
10908 | *slot = name; | |
10909 | } | |
10910 | ||
10911 | htab_delete (htab); | |
10912 | return 0; | |
10913 | } | |
10914 | ||
0fb4aa4b PA |
10915 | /* When symbols change, it probably means the sources changed as well, |
10916 | and it might mean the static tracepoint markers are no longer at | |
10917 | the same address or line numbers they used to be at last we | |
10918 | checked. Losing your static tracepoints whenever you rebuild is | |
10919 | undesirable. This function tries to resync/rematch gdb static | |
10920 | tracepoints with the markers on the target, for static tracepoints | |
10921 | that have not been set by marker id. Static tracepoint that have | |
10922 | been set by marker id are reset by marker id in breakpoint_re_set. | |
10923 | The heuristic is: | |
10924 | ||
10925 | 1) For a tracepoint set at a specific address, look for a marker at | |
10926 | the old PC. If one is found there, assume to be the same marker. | |
10927 | If the name / string id of the marker found is different from the | |
10928 | previous known name, assume that means the user renamed the marker | |
10929 | in the sources, and output a warning. | |
10930 | ||
10931 | 2) For a tracepoint set at a given line number, look for a marker | |
10932 | at the new address of the old line number. If one is found there, | |
10933 | assume to be the same marker. If the name / string id of the | |
10934 | marker found is different from the previous known name, assume that | |
10935 | means the user renamed the marker in the sources, and output a | |
10936 | warning. | |
10937 | ||
10938 | 3) If a marker is no longer found at the same address or line, it | |
10939 | may mean the marker no longer exists. But it may also just mean | |
10940 | the code changed a bit. Maybe the user added a few lines of code | |
10941 | that made the marker move up or down (in line number terms). Ask | |
10942 | the target for info about the marker with the string id as we knew | |
10943 | it. If found, update line number and address in the matching | |
10944 | static tracepoint. This will get confused if there's more than one | |
10945 | marker with the same ID (possible in UST, although unadvised | |
10946 | precisely because it confuses tools). */ | |
10947 | ||
10948 | static struct symtab_and_line | |
10949 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
10950 | { | |
10951 | struct static_tracepoint_marker marker; | |
10952 | CORE_ADDR pc; | |
10953 | int i; | |
10954 | ||
10955 | pc = sal.pc; | |
10956 | if (sal.line) | |
10957 | find_line_pc (sal.symtab, sal.line, &pc); | |
10958 | ||
10959 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
10960 | { | |
10961 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
10962 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
10963 | b->number, | |
10964 | b->static_trace_marker_id, marker.str_id); | |
10965 | ||
10966 | xfree (b->static_trace_marker_id); | |
10967 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
10968 | release_static_tracepoint_marker (&marker); | |
10969 | ||
10970 | return sal; | |
10971 | } | |
10972 | ||
10973 | /* Old marker wasn't found on target at lineno. Try looking it up | |
10974 | by string ID. */ | |
10975 | if (!sal.explicit_pc | |
10976 | && sal.line != 0 | |
10977 | && sal.symtab != NULL | |
10978 | && b->static_trace_marker_id != NULL) | |
10979 | { | |
10980 | VEC(static_tracepoint_marker_p) *markers; | |
10981 | ||
10982 | markers | |
10983 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
10984 | ||
10985 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
10986 | { | |
10987 | struct symtab_and_line sal; | |
10988 | struct symbol *sym; | |
10989 | struct static_tracepoint_marker *marker; | |
10990 | ||
10991 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
10992 | ||
10993 | xfree (b->static_trace_marker_id); | |
10994 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
10995 | ||
10996 | warning (_("marker for static tracepoint %d (%s) not " | |
10997 | "found at previous line number"), | |
10998 | b->number, b->static_trace_marker_id); | |
10999 | ||
11000 | init_sal (&sal); | |
11001 | ||
11002 | sal.pc = marker->address; | |
11003 | ||
11004 | sal = find_pc_line (marker->address, 0); | |
11005 | sym = find_pc_sect_function (marker->address, NULL); | |
11006 | ui_out_text (uiout, "Now in "); | |
11007 | if (sym) | |
11008 | { | |
11009 | ui_out_field_string (uiout, "func", | |
11010 | SYMBOL_PRINT_NAME (sym)); | |
11011 | ui_out_text (uiout, " at "); | |
11012 | } | |
11013 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
11014 | ui_out_text (uiout, ":"); | |
11015 | ||
11016 | if (ui_out_is_mi_like_p (uiout)) | |
11017 | { | |
11018 | char *fullname = symtab_to_fullname (sal.symtab); | |
11019 | ||
11020 | if (fullname) | |
11021 | ui_out_field_string (uiout, "fullname", fullname); | |
11022 | } | |
11023 | ||
11024 | ui_out_field_int (uiout, "line", sal.line); | |
11025 | ui_out_text (uiout, "\n"); | |
11026 | ||
11027 | b->line_number = sal.line; | |
11028 | ||
11029 | xfree (b->source_file); | |
11030 | if (sym) | |
11031 | b->source_file = xstrdup (sal.symtab->filename); | |
11032 | else | |
11033 | b->source_file = NULL; | |
11034 | ||
11035 | xfree (b->addr_string); | |
11036 | b->addr_string = xstrprintf ("%s:%d", | |
11037 | sal.symtab->filename, b->line_number); | |
11038 | ||
11039 | /* Might be nice to check if function changed, and warn if | |
11040 | so. */ | |
11041 | ||
11042 | release_static_tracepoint_marker (marker); | |
11043 | } | |
11044 | } | |
11045 | return sal; | |
11046 | } | |
11047 | ||
8d3788bd VP |
11048 | /* Returns 1 iff locations A and B are sufficiently same that |
11049 | we don't need to report breakpoint as changed. */ | |
11050 | ||
11051 | static int | |
11052 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11053 | { | |
11054 | while (a && b) | |
11055 | { | |
11056 | if (a->address != b->address) | |
11057 | return 0; | |
11058 | ||
11059 | if (a->shlib_disabled != b->shlib_disabled) | |
11060 | return 0; | |
11061 | ||
11062 | if (a->enabled != b->enabled) | |
11063 | return 0; | |
11064 | ||
11065 | a = a->next; | |
11066 | b = b->next; | |
11067 | } | |
11068 | ||
11069 | if ((a == NULL) != (b == NULL)) | |
11070 | return 0; | |
11071 | ||
11072 | return 1; | |
11073 | } | |
11074 | ||
f1310107 TJB |
11075 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11076 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11077 | a ranged breakpoint. */ | |
11078 | ||
0e30163f | 11079 | void |
0d381245 | 11080 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11081 | struct symtabs_and_lines sals, |
11082 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11083 | { |
11084 | int i; | |
0d381245 VP |
11085 | struct bp_location *existing_locations = b->loc; |
11086 | ||
f1310107 TJB |
11087 | /* Ranged breakpoints have only one start location and one end location. */ |
11088 | gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1)); | |
11089 | ||
4a64f543 MS |
11090 | /* If there's no new locations, and all existing locations are |
11091 | pending, don't do anything. This optimizes the common case where | |
11092 | all locations are in the same shared library, that was unloaded. | |
11093 | We'd like to retain the location, so that when the library is | |
11094 | loaded again, we don't loose the enabled/disabled status of the | |
11095 | individual locations. */ | |
0d381245 | 11096 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11097 | return; |
11098 | ||
fe3f5fa8 VP |
11099 | b->loc = NULL; |
11100 | ||
0d381245 | 11101 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11102 | { |
0d381245 | 11103 | struct bp_location *new_loc = |
39d61571 | 11104 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 11105 | |
0d381245 VP |
11106 | /* Reparse conditions, they might contain references to the |
11107 | old symtab. */ | |
11108 | if (b->cond_string != NULL) | |
11109 | { | |
f1310107 | 11110 | char *s; |
0d381245 | 11111 | struct gdb_exception e; |
fe3f5fa8 | 11112 | |
0d381245 VP |
11113 | s = b->cond_string; |
11114 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11115 | { | |
11116 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11117 | 0); | |
11118 | } | |
11119 | if (e.reason < 0) | |
11120 | { | |
3e43a32a MS |
11121 | warning (_("failed to reevaluate condition " |
11122 | "for breakpoint %d: %s"), | |
0d381245 VP |
11123 | b->number, e.message); |
11124 | new_loc->enabled = 0; | |
11125 | } | |
11126 | } | |
fe3f5fa8 | 11127 | |
0d381245 VP |
11128 | if (b->source_file != NULL) |
11129 | xfree (b->source_file); | |
11130 | if (sals.sals[i].symtab == NULL) | |
11131 | b->source_file = NULL; | |
11132 | else | |
1b36a34b | 11133 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 11134 | |
0d381245 VP |
11135 | if (b->line_number == 0) |
11136 | b->line_number = sals.sals[i].line; | |
f1310107 TJB |
11137 | |
11138 | if (sals_end.nelts) | |
11139 | { | |
11140 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11141 | ||
11142 | new_loc->length = end - sals.sals[0].pc + 1; | |
11143 | } | |
0d381245 | 11144 | } |
fe3f5fa8 | 11145 | |
514f746b AR |
11146 | /* Update locations of permanent breakpoints. */ |
11147 | if (b->enable_state == bp_permanent) | |
11148 | make_breakpoint_permanent (b); | |
11149 | ||
4a64f543 MS |
11150 | /* If possible, carry over 'disable' status from existing |
11151 | breakpoints. */ | |
0d381245 VP |
11152 | { |
11153 | struct bp_location *e = existing_locations; | |
776592bf DE |
11154 | /* If there are multiple breakpoints with the same function name, |
11155 | e.g. for inline functions, comparing function names won't work. | |
11156 | Instead compare pc addresses; this is just a heuristic as things | |
11157 | may have moved, but in practice it gives the correct answer | |
11158 | often enough until a better solution is found. */ | |
11159 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
11160 | ||
0d381245 VP |
11161 | for (; e; e = e->next) |
11162 | { | |
11163 | if (!e->enabled && e->function_name) | |
11164 | { | |
11165 | struct bp_location *l = b->loc; | |
776592bf DE |
11166 | if (have_ambiguous_names) |
11167 | { | |
11168 | for (; l; l = l->next) | |
f1310107 | 11169 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
11170 | { |
11171 | l->enabled = 0; | |
11172 | break; | |
11173 | } | |
11174 | } | |
11175 | else | |
11176 | { | |
11177 | for (; l; l = l->next) | |
11178 | if (l->function_name | |
11179 | && strcmp (e->function_name, l->function_name) == 0) | |
11180 | { | |
11181 | l->enabled = 0; | |
11182 | break; | |
11183 | } | |
11184 | } | |
0d381245 VP |
11185 | } |
11186 | } | |
11187 | } | |
fe3f5fa8 | 11188 | |
8d3788bd VP |
11189 | if (!locations_are_equal (existing_locations, b->loc)) |
11190 | observer_notify_breakpoint_modified (b); | |
11191 | ||
b60e7edf | 11192 | update_global_location_list (1); |
fe3f5fa8 VP |
11193 | } |
11194 | ||
ef23e705 TJB |
11195 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
11196 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
11197 | ||
11198 | static struct symtabs_and_lines | |
11199 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
11200 | { | |
11201 | char *s; | |
58438ac1 | 11202 | int marker_spec; |
02d20e4a | 11203 | struct symtabs_and_lines sals = {0}; |
ef23e705 TJB |
11204 | struct gdb_exception e; |
11205 | ||
11206 | s = addr_string; | |
11207 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); | |
11208 | ||
11209 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11210 | { | |
11211 | if (marker_spec) | |
11212 | { | |
11213 | sals = decode_static_tracepoint_spec (&s); | |
11214 | if (sals.nelts > b->static_trace_marker_id_idx) | |
11215 | { | |
11216 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
11217 | sals.nelts = 1; | |
11218 | } | |
11219 | else | |
11220 | error (_("marker %s not found"), b->static_trace_marker_id); | |
11221 | } | |
11222 | else | |
58438ac1 | 11223 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL); |
ef23e705 TJB |
11224 | } |
11225 | if (e.reason < 0) | |
11226 | { | |
11227 | int not_found_and_ok = 0; | |
11228 | /* For pending breakpoints, it's expected that parsing will | |
11229 | fail until the right shared library is loaded. User has | |
11230 | already told to create pending breakpoints and don't need | |
11231 | extra messages. If breakpoint is in bp_shlib_disabled | |
11232 | state, then user already saw the message about that | |
11233 | breakpoint being disabled, and don't want to see more | |
11234 | errors. */ | |
58438ac1 | 11235 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
11236 | && (b->condition_not_parsed |
11237 | || (b->loc && b->loc->shlib_disabled) | |
11238 | || b->enable_state == bp_disabled)) | |
11239 | not_found_and_ok = 1; | |
11240 | ||
11241 | if (!not_found_and_ok) | |
11242 | { | |
11243 | /* We surely don't want to warn about the same breakpoint | |
11244 | 10 times. One solution, implemented here, is disable | |
11245 | the breakpoint on error. Another solution would be to | |
11246 | have separate 'warning emitted' flag. Since this | |
11247 | happens only when a binary has changed, I don't know | |
11248 | which approach is better. */ | |
11249 | b->enable_state = bp_disabled; | |
11250 | throw_exception (e); | |
11251 | } | |
11252 | } | |
11253 | ||
58438ac1 | 11254 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 TJB |
11255 | { |
11256 | gdb_assert (sals.nelts == 1); | |
11257 | ||
11258 | resolve_sal_pc (&sals.sals[0]); | |
11259 | if (b->condition_not_parsed && s && s[0]) | |
11260 | { | |
11261 | char *cond_string = 0; | |
11262 | int thread = -1; | |
11263 | int task = 0; | |
11264 | ||
11265 | find_condition_and_thread (s, sals.sals[0].pc, | |
11266 | &cond_string, &thread, &task); | |
11267 | if (cond_string) | |
11268 | b->cond_string = cond_string; | |
11269 | b->thread = thread; | |
11270 | b->task = task; | |
11271 | b->condition_not_parsed = 0; | |
11272 | } | |
11273 | ||
11274 | if (b->type == bp_static_tracepoint && !marker_spec) | |
11275 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
ef23e705 | 11276 | |
58438ac1 TT |
11277 | *found = 1; |
11278 | } | |
11279 | else | |
11280 | *found = 0; | |
ef23e705 TJB |
11281 | |
11282 | return sals; | |
11283 | } | |
11284 | ||
11285 | /* Reevaluate a hardware or software breakpoint and recreate its locations. | |
11286 | This is necessary after symbols are read (e.g., an executable or DSO | |
11287 | was loaded, or the inferior just started). */ | |
11288 | ||
11289 | static void | |
11290 | re_set_breakpoint (struct breakpoint *b) | |
11291 | { | |
11292 | int found; | |
f1310107 | 11293 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 11294 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 11295 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
11296 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
11297 | ||
11298 | input_radix = b->input_radix; | |
11299 | save_current_space_and_thread (); | |
11300 | switch_to_program_space_and_thread (b->pspace); | |
11301 | set_language (b->language); | |
11302 | ||
11303 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
11304 | if (found) | |
11305 | { | |
11306 | make_cleanup (xfree, sals.sals); | |
11307 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
11308 | } | |
11309 | ||
f1310107 TJB |
11310 | if (b->addr_string_range_end) |
11311 | { | |
11312 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
11313 | if (found) | |
11314 | { | |
11315 | make_cleanup (xfree, sals_end.sals); | |
11316 | expanded_end = expand_line_sal_maybe (sals_end.sals[0]); | |
11317 | } | |
11318 | } | |
11319 | ||
11320 | update_breakpoint_locations (b, expanded, expanded_end); | |
ef23e705 TJB |
11321 | do_cleanups (cleanups); |
11322 | } | |
11323 | ||
c906108c SS |
11324 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
11325 | The value we return ends up being the return value from catch_errors. | |
11326 | Unused in this case. */ | |
11327 | ||
11328 | static int | |
4efb68b1 | 11329 | breakpoint_re_set_one (void *bint) |
c906108c | 11330 | { |
4a64f543 | 11331 | /* Get past catch_errs. */ |
53a5351d | 11332 | struct breakpoint *b = (struct breakpoint *) bint; |
c906108c SS |
11333 | |
11334 | switch (b->type) | |
11335 | { | |
11336 | case bp_none: | |
8a3fe4f8 | 11337 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 11338 | b->number); |
c906108c SS |
11339 | return 0; |
11340 | case bp_breakpoint: | |
11341 | case bp_hardware_breakpoint: | |
1042e4c0 | 11342 | case bp_tracepoint: |
7a697b8d | 11343 | case bp_fast_tracepoint: |
0fb4aa4b | 11344 | case bp_static_tracepoint: |
0e30163f | 11345 | case bp_gnu_ifunc_resolver: |
8bea4e01 UW |
11346 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
11347 | if (b->enable_state == bp_startup_disabled) | |
11348 | return 0; | |
11349 | ||
c906108c SS |
11350 | if (b->addr_string == NULL) |
11351 | { | |
4a64f543 | 11352 | /* Anything without a string can't be re-set. */ |
c906108c SS |
11353 | delete_breakpoint (b); |
11354 | return 0; | |
11355 | } | |
c906108c | 11356 | |
ef23e705 | 11357 | re_set_breakpoint (b); |
c906108c SS |
11358 | break; |
11359 | ||
11360 | case bp_watchpoint: | |
11361 | case bp_hardware_watchpoint: | |
11362 | case bp_read_watchpoint: | |
11363 | case bp_access_watchpoint: | |
4a64f543 MS |
11364 | /* Watchpoint can be either on expression using entirely global |
11365 | variables, or it can be on local variables. | |
11366 | ||
11367 | Watchpoints of the first kind are never auto-deleted, and | |
11368 | even persist across program restarts. Since they can use | |
11369 | variables from shared libraries, we need to reparse | |
11370 | expression as libraries are loaded and unloaded. | |
11371 | ||
11372 | Watchpoints on local variables can also change meaning as | |
11373 | result of solib event. For example, if a watchpoint uses | |
11374 | both a local and a global variables in expression, it's a | |
11375 | local watchpoint, but unloading of a shared library will make | |
11376 | the expression invalid. This is not a very common use case, | |
11377 | but we still re-evaluate expression, to avoid surprises to | |
11378 | the user. | |
0b3de036 VP |
11379 | |
11380 | Note that for local watchpoints, we re-evaluate it only if | |
11381 | watchpoints frame id is still valid. If it's not, it means | |
4a64f543 MS |
11382 | the watchpoint is out of scope and will be deleted soon. In |
11383 | fact, I'm not sure we'll ever be called in this case. | |
0b3de036 VP |
11384 | |
11385 | If a local watchpoint's frame id is still valid, then | |
4a64f543 | 11386 | b->exp_valid_block is likewise valid, and we can safely use it. |
0b3de036 VP |
11387 | |
11388 | Don't do anything about disabled watchpoints, since they will | |
11389 | be reevaluated again when enabled. */ | |
a5606eee | 11390 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 11391 | break; |
c5aa993b JM |
11392 | /* We needn't really do anything to reset these, since the mask |
11393 | that requests them is unaffected by e.g., new libraries being | |
4a64f543 | 11394 | loaded. */ |
ce78b96d | 11395 | case bp_catchpoint: |
c906108c | 11396 | break; |
c5aa993b | 11397 | |
c906108c | 11398 | default: |
a3f17187 | 11399 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 11400 | /* fall through */ |
0fd8e87f UW |
11401 | /* Delete overlay event and longjmp master breakpoints; they will be |
11402 | reset later by breakpoint_re_set. */ | |
1900040c | 11403 | case bp_overlay_event: |
0fd8e87f | 11404 | case bp_longjmp_master: |
aa7d318d | 11405 | case bp_std_terminate_master: |
186c406b | 11406 | case bp_exception_master: |
c906108c SS |
11407 | delete_breakpoint (b); |
11408 | break; | |
11409 | ||
c5aa993b JM |
11410 | /* This breakpoint is special, it's set up when the inferior |
11411 | starts and we really don't want to touch it. */ | |
c906108c SS |
11412 | case bp_shlib_event: |
11413 | ||
c4093a6a JM |
11414 | /* Like bp_shlib_event, this breakpoint type is special. |
11415 | Once it is set up, we do not want to touch it. */ | |
11416 | case bp_thread_event: | |
11417 | ||
4a64f543 MS |
11418 | /* Keep temporary breakpoints, which can be encountered when we |
11419 | step over a dlopen call and SOLIB_ADD is resetting the | |
11420 | breakpoints. Otherwise these should have been blown away via | |
11421 | the cleanup chain or by breakpoint_init_inferior when we | |
11422 | rerun the executable. */ | |
c906108c SS |
11423 | case bp_until: |
11424 | case bp_finish: | |
11425 | case bp_watchpoint_scope: | |
11426 | case bp_call_dummy: | |
aa7d318d | 11427 | case bp_std_terminate: |
c906108c | 11428 | case bp_step_resume: |
611c83ae PA |
11429 | case bp_longjmp: |
11430 | case bp_longjmp_resume: | |
186c406b TT |
11431 | case bp_exception: |
11432 | case bp_exception_resume: | |
4efc6507 | 11433 | case bp_jit_event: |
0e30163f | 11434 | case bp_gnu_ifunc_resolver_return: |
c906108c SS |
11435 | break; |
11436 | } | |
11437 | ||
11438 | return 0; | |
11439 | } | |
11440 | ||
69de3c6a | 11441 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 11442 | void |
69de3c6a | 11443 | breakpoint_re_set (void) |
c906108c | 11444 | { |
35df4500 | 11445 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11446 | enum language save_language; |
11447 | int save_input_radix; | |
6c95b8df | 11448 | struct cleanup *old_chain; |
c5aa993b | 11449 | |
c906108c SS |
11450 | save_language = current_language->la_language; |
11451 | save_input_radix = input_radix; | |
6c95b8df PA |
11452 | old_chain = save_current_program_space (); |
11453 | ||
35df4500 | 11454 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11455 | { |
4a64f543 | 11456 | /* Format possible error msg. */ |
fe3f5fa8 | 11457 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
11458 | b->number); |
11459 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 11460 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 11461 | do_cleanups (cleanups); |
c5aa993b | 11462 | } |
c906108c SS |
11463 | set_language (save_language); |
11464 | input_radix = save_input_radix; | |
e62c965a | 11465 | |
0756c555 | 11466 | jit_breakpoint_re_set (); |
4efc6507 | 11467 | |
6c95b8df PA |
11468 | do_cleanups (old_chain); |
11469 | ||
af02033e PP |
11470 | create_overlay_event_breakpoint (); |
11471 | create_longjmp_master_breakpoint (); | |
11472 | create_std_terminate_master_breakpoint (); | |
186c406b | 11473 | create_exception_master_breakpoint (); |
c906108c SS |
11474 | } |
11475 | \f | |
c906108c SS |
11476 | /* Reset the thread number of this breakpoint: |
11477 | ||
11478 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 11479 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 11480 | void |
fba45db2 | 11481 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
11482 | { |
11483 | if (b->thread != -1) | |
11484 | { | |
39f77062 KB |
11485 | if (in_thread_list (inferior_ptid)) |
11486 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
11487 | |
11488 | /* We're being called after following a fork. The new fork is | |
11489 | selected as current, and unless this was a vfork will have a | |
11490 | different program space from the original thread. Reset that | |
11491 | as well. */ | |
11492 | b->loc->pspace = current_program_space; | |
c906108c SS |
11493 | } |
11494 | } | |
11495 | ||
03ac34d5 MS |
11496 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
11497 | If from_tty is nonzero, it prints a message to that effect, | |
11498 | which ends with a period (no newline). */ | |
11499 | ||
c906108c | 11500 | void |
fba45db2 | 11501 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 11502 | { |
52f0bd74 | 11503 | struct breakpoint *b; |
c906108c SS |
11504 | |
11505 | if (count < 0) | |
11506 | count = 0; | |
11507 | ||
11508 | ALL_BREAKPOINTS (b) | |
11509 | if (b->number == bptnum) | |
c5aa993b | 11510 | { |
d77f58be SS |
11511 | if (is_tracepoint (b)) |
11512 | { | |
11513 | if (from_tty && count != 0) | |
11514 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
11515 | bptnum); | |
11516 | return; | |
11517 | } | |
11518 | ||
c5aa993b | 11519 | b->ignore_count = count; |
221ea385 KS |
11520 | if (from_tty) |
11521 | { | |
11522 | if (count == 0) | |
3e43a32a MS |
11523 | printf_filtered (_("Will stop next time " |
11524 | "breakpoint %d is reached."), | |
221ea385 KS |
11525 | bptnum); |
11526 | else if (count == 1) | |
a3f17187 | 11527 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
11528 | bptnum); |
11529 | else | |
3e43a32a MS |
11530 | printf_filtered (_("Will ignore next %d " |
11531 | "crossings of breakpoint %d."), | |
221ea385 KS |
11532 | count, bptnum); |
11533 | } | |
c5aa993b | 11534 | breakpoints_changed (); |
8d3788bd | 11535 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
11536 | return; |
11537 | } | |
c906108c | 11538 | |
8a3fe4f8 | 11539 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
11540 | } |
11541 | ||
c906108c SS |
11542 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
11543 | ||
11544 | static void | |
fba45db2 | 11545 | ignore_command (char *args, int from_tty) |
c906108c SS |
11546 | { |
11547 | char *p = args; | |
52f0bd74 | 11548 | int num; |
c906108c SS |
11549 | |
11550 | if (p == 0) | |
e2e0b3e5 | 11551 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 11552 | |
c906108c | 11553 | num = get_number (&p); |
5c44784c | 11554 | if (num == 0) |
8a3fe4f8 | 11555 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 11556 | if (*p == 0) |
8a3fe4f8 | 11557 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
11558 | |
11559 | set_ignore_count (num, | |
11560 | longest_to_int (value_as_long (parse_and_eval (p))), | |
11561 | from_tty); | |
221ea385 KS |
11562 | if (from_tty) |
11563 | printf_filtered ("\n"); | |
c906108c SS |
11564 | } |
11565 | \f | |
11566 | /* Call FUNCTION on each of the breakpoints | |
11567 | whose numbers are given in ARGS. */ | |
11568 | ||
11569 | static void | |
95a42b64 TT |
11570 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
11571 | void *), | |
11572 | void *data) | |
c906108c | 11573 | { |
52f0bd74 AC |
11574 | int num; |
11575 | struct breakpoint *b, *tmp; | |
11cf8741 | 11576 | int match; |
197f0a60 | 11577 | struct get_number_or_range_state state; |
c906108c | 11578 | |
197f0a60 | 11579 | if (args == 0) |
e2e0b3e5 | 11580 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 11581 | |
197f0a60 TT |
11582 | init_number_or_range (&state, args); |
11583 | ||
11584 | while (!state.finished) | |
c906108c | 11585 | { |
197f0a60 TT |
11586 | char *p = state.string; |
11587 | ||
11cf8741 | 11588 | match = 0; |
c5aa993b | 11589 | |
197f0a60 | 11590 | num = get_number_or_range (&state); |
5c44784c | 11591 | if (num == 0) |
c5aa993b | 11592 | { |
8a3fe4f8 | 11593 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
11594 | } |
11595 | else | |
11596 | { | |
11597 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
11598 | if (b->number == num) | |
11599 | { | |
d0fb5eae JK |
11600 | struct breakpoint *related_breakpoint; |
11601 | ||
11cf8741 | 11602 | match = 1; |
d0fb5eae JK |
11603 | related_breakpoint = b; |
11604 | do | |
11605 | { | |
11606 | struct breakpoint *next_related_b; | |
11607 | ||
11608 | /* FUNCTION can be also delete_breakpoint. */ | |
11609 | next_related_b = related_breakpoint->related_breakpoint; | |
11610 | function (related_breakpoint, data); | |
11611 | ||
11612 | /* For delete_breakpoint of the last entry of the ring we | |
11613 | were traversing we would never get back to B. */ | |
11614 | if (next_related_b == related_breakpoint) | |
11615 | break; | |
11616 | related_breakpoint = next_related_b; | |
11617 | } | |
11618 | while (related_breakpoint != b); | |
11cf8741 | 11619 | break; |
5c44784c | 11620 | } |
11cf8741 | 11621 | if (match == 0) |
a3f17187 | 11622 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 11623 | } |
c906108c SS |
11624 | } |
11625 | } | |
11626 | ||
0d381245 VP |
11627 | static struct bp_location * |
11628 | find_location_by_number (char *number) | |
11629 | { | |
11630 | char *dot = strchr (number, '.'); | |
11631 | char *p1; | |
11632 | int bp_num; | |
11633 | int loc_num; | |
11634 | struct breakpoint *b; | |
11635 | struct bp_location *loc; | |
11636 | ||
11637 | *dot = '\0'; | |
11638 | ||
11639 | p1 = number; | |
197f0a60 | 11640 | bp_num = get_number (&p1); |
0d381245 VP |
11641 | if (bp_num == 0) |
11642 | error (_("Bad breakpoint number '%s'"), number); | |
11643 | ||
11644 | ALL_BREAKPOINTS (b) | |
11645 | if (b->number == bp_num) | |
11646 | { | |
11647 | break; | |
11648 | } | |
11649 | ||
11650 | if (!b || b->number != bp_num) | |
11651 | error (_("Bad breakpoint number '%s'"), number); | |
11652 | ||
11653 | p1 = dot+1; | |
197f0a60 | 11654 | loc_num = get_number (&p1); |
0d381245 VP |
11655 | if (loc_num == 0) |
11656 | error (_("Bad breakpoint location number '%s'"), number); | |
11657 | ||
11658 | --loc_num; | |
11659 | loc = b->loc; | |
11660 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
11661 | ; | |
11662 | if (!loc) | |
11663 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
11664 | ||
11665 | return loc; | |
11666 | } | |
11667 | ||
11668 | ||
1900040c MS |
11669 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
11670 | If from_tty is nonzero, it prints a message to that effect, | |
11671 | which ends with a period (no newline). */ | |
11672 | ||
c906108c | 11673 | void |
fba45db2 | 11674 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
11675 | { |
11676 | /* Never disable a watchpoint scope breakpoint; we want to | |
11677 | hit them when we leave scope so we can delete both the | |
11678 | watchpoint and its scope breakpoint at that time. */ | |
11679 | if (bpt->type == bp_watchpoint_scope) | |
11680 | return; | |
11681 | ||
c2c6d25f | 11682 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 11683 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
11684 | return; |
11685 | ||
b5de0fa7 | 11686 | bpt->enable_state = bp_disabled; |
c906108c | 11687 | |
d248b706 KY |
11688 | if (target_supports_enable_disable_tracepoint () |
11689 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
11690 | { | |
11691 | struct bp_location *location; | |
11692 | ||
11693 | for (location = bpt->loc; location; location = location->next) | |
11694 | target_disable_tracepoint (location); | |
11695 | } | |
11696 | ||
b60e7edf | 11697 | update_global_location_list (0); |
c906108c | 11698 | |
8d3788bd | 11699 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
11700 | } |
11701 | ||
95a42b64 TT |
11702 | /* A callback for map_breakpoint_numbers that calls |
11703 | disable_breakpoint. */ | |
11704 | ||
11705 | static void | |
11706 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
11707 | { | |
11708 | disable_breakpoint (b); | |
11709 | } | |
11710 | ||
c906108c | 11711 | static void |
fba45db2 | 11712 | disable_command (char *args, int from_tty) |
c906108c | 11713 | { |
c906108c | 11714 | if (args == 0) |
46c6471b PA |
11715 | { |
11716 | struct breakpoint *bpt; | |
11717 | ||
11718 | ALL_BREAKPOINTS (bpt) | |
11719 | if (user_breakpoint_p (bpt)) | |
11720 | disable_breakpoint (bpt); | |
11721 | } | |
0d381245 VP |
11722 | else if (strchr (args, '.')) |
11723 | { | |
11724 | struct bp_location *loc = find_location_by_number (args); | |
11725 | if (loc) | |
d248b706 KY |
11726 | { |
11727 | loc->enabled = 0; | |
11728 | if (target_supports_enable_disable_tracepoint () | |
11729 | && current_trace_status ()->running && loc->owner | |
11730 | && is_tracepoint (loc->owner)) | |
11731 | target_disable_tracepoint (loc); | |
11732 | } | |
b60e7edf | 11733 | update_global_location_list (0); |
0d381245 | 11734 | } |
c906108c | 11735 | else |
95a42b64 | 11736 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
11737 | } |
11738 | ||
11739 | static void | |
fba45db2 | 11740 | do_enable_breakpoint (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 11741 | { |
afe38095 | 11742 | int target_resources_ok; |
c906108c SS |
11743 | |
11744 | if (bpt->type == bp_hardware_breakpoint) | |
11745 | { | |
11746 | int i; | |
c5aa993b | 11747 | i = hw_breakpoint_used_count (); |
53a5351d | 11748 | target_resources_ok = |
d92524f1 | 11749 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 11750 | i + 1, 0); |
c906108c | 11751 | if (target_resources_ok == 0) |
8a3fe4f8 | 11752 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 11753 | else if (target_resources_ok < 0) |
8a3fe4f8 | 11754 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
11755 | } |
11756 | ||
cc60f2e3 | 11757 | if (is_watchpoint (bpt)) |
c906108c | 11758 | { |
d07205c2 JK |
11759 | /* Initialize it just to avoid a GCC false warning. */ |
11760 | enum enable_state orig_enable_state = 0; | |
dde02812 ES |
11761 | struct gdb_exception e; |
11762 | ||
11763 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 11764 | { |
1e718ff1 TJB |
11765 | orig_enable_state = bpt->enable_state; |
11766 | bpt->enable_state = bp_enabled; | |
dde02812 | 11767 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 11768 | } |
dde02812 | 11769 | if (e.reason < 0) |
c5aa993b | 11770 | { |
1e718ff1 | 11771 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
11772 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
11773 | bpt->number); | |
11774 | return; | |
c5aa993b | 11775 | } |
c906108c | 11776 | } |
0101ce28 | 11777 | |
b4c291bb KH |
11778 | if (bpt->enable_state != bp_permanent) |
11779 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
11780 | |
11781 | if (target_supports_enable_disable_tracepoint () | |
11782 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
11783 | { | |
11784 | struct bp_location *location; | |
11785 | ||
11786 | for (location = bpt->loc; location; location = location->next) | |
11787 | target_enable_tracepoint (location); | |
11788 | } | |
11789 | ||
b4c291bb | 11790 | bpt->disposition = disposition; |
b60e7edf | 11791 | update_global_location_list (1); |
b4c291bb KH |
11792 | breakpoints_changed (); |
11793 | ||
8d3788bd | 11794 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
11795 | } |
11796 | ||
fe3f5fa8 | 11797 | |
c906108c | 11798 | void |
fba45db2 | 11799 | enable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
11800 | { |
11801 | do_enable_breakpoint (bpt, bpt->disposition); | |
11802 | } | |
11803 | ||
95a42b64 TT |
11804 | /* A callback for map_breakpoint_numbers that calls |
11805 | enable_breakpoint. */ | |
11806 | ||
11807 | static void | |
11808 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
11809 | { | |
11810 | enable_breakpoint (b); | |
11811 | } | |
11812 | ||
c906108c SS |
11813 | /* The enable command enables the specified breakpoints (or all defined |
11814 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 11815 | in stopping the inferior. */ |
c906108c | 11816 | |
c906108c | 11817 | static void |
fba45db2 | 11818 | enable_command (char *args, int from_tty) |
c906108c | 11819 | { |
c906108c | 11820 | if (args == 0) |
46c6471b PA |
11821 | { |
11822 | struct breakpoint *bpt; | |
11823 | ||
11824 | ALL_BREAKPOINTS (bpt) | |
11825 | if (user_breakpoint_p (bpt)) | |
11826 | enable_breakpoint (bpt); | |
11827 | } | |
0d381245 VP |
11828 | else if (strchr (args, '.')) |
11829 | { | |
11830 | struct bp_location *loc = find_location_by_number (args); | |
11831 | if (loc) | |
d248b706 KY |
11832 | { |
11833 | loc->enabled = 1; | |
11834 | if (target_supports_enable_disable_tracepoint () | |
11835 | && current_trace_status ()->running && loc->owner | |
11836 | && is_tracepoint (loc->owner)) | |
11837 | target_enable_tracepoint (loc); | |
11838 | } | |
b60e7edf | 11839 | update_global_location_list (1); |
0d381245 | 11840 | } |
c906108c | 11841 | else |
95a42b64 | 11842 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
11843 | } |
11844 | ||
11845 | static void | |
95a42b64 | 11846 | enable_once_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11847 | { |
b5de0fa7 | 11848 | do_enable_breakpoint (bpt, disp_disable); |
c906108c SS |
11849 | } |
11850 | ||
c906108c | 11851 | static void |
fba45db2 | 11852 | enable_once_command (char *args, int from_tty) |
c906108c | 11853 | { |
95a42b64 | 11854 | map_breakpoint_numbers (args, enable_once_breakpoint, NULL); |
c906108c SS |
11855 | } |
11856 | ||
11857 | static void | |
95a42b64 | 11858 | enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11859 | { |
b5de0fa7 | 11860 | do_enable_breakpoint (bpt, disp_del); |
c906108c SS |
11861 | } |
11862 | ||
c906108c | 11863 | static void |
fba45db2 | 11864 | enable_delete_command (char *args, int from_tty) |
c906108c | 11865 | { |
95a42b64 | 11866 | map_breakpoint_numbers (args, enable_delete_breakpoint, NULL); |
c906108c SS |
11867 | } |
11868 | \f | |
fa8d40ab JJ |
11869 | static void |
11870 | set_breakpoint_cmd (char *args, int from_tty) | |
11871 | { | |
11872 | } | |
11873 | ||
11874 | static void | |
11875 | show_breakpoint_cmd (char *args, int from_tty) | |
11876 | { | |
11877 | } | |
11878 | ||
1f3b5d1b PP |
11879 | /* Invalidate last known value of any hardware watchpoint if |
11880 | the memory which that value represents has been written to by | |
11881 | GDB itself. */ | |
11882 | ||
11883 | static void | |
11884 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
11885 | const bfd_byte *data) | |
11886 | { | |
11887 | struct breakpoint *bp; | |
11888 | ||
11889 | ALL_BREAKPOINTS (bp) | |
11890 | if (bp->enable_state == bp_enabled | |
11891 | && bp->type == bp_hardware_watchpoint | |
11892 | && bp->val_valid && bp->val) | |
11893 | { | |
11894 | struct bp_location *loc; | |
11895 | ||
11896 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
11897 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
11898 | && loc->address + loc->length > addr | |
11899 | && addr + len > loc->address) | |
11900 | { | |
11901 | value_free (bp->val); | |
11902 | bp->val = NULL; | |
11903 | bp->val_valid = 0; | |
11904 | } | |
11905 | } | |
11906 | } | |
11907 | ||
c906108c SS |
11908 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
11909 | ||
11910 | struct symtabs_and_lines | |
fba45db2 | 11911 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
11912 | { |
11913 | struct symtabs_and_lines sals; | |
cc59ec59 | 11914 | |
c906108c | 11915 | if (string == 0) |
8a3fe4f8 | 11916 | error (_("Empty line specification.")); |
c906108c SS |
11917 | if (default_breakpoint_valid) |
11918 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
11919 | default_breakpoint_symtab, |
11920 | default_breakpoint_line, | |
58438ac1 | 11921 | NULL); |
c906108c SS |
11922 | else |
11923 | sals = decode_line_1 (&string, funfirstline, | |
58438ac1 | 11924 | (struct symtab *) NULL, 0, NULL); |
c906108c | 11925 | if (*string) |
8a3fe4f8 | 11926 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
11927 | return sals; |
11928 | } | |
8181d85f DJ |
11929 | |
11930 | /* Create and insert a raw software breakpoint at PC. Return an | |
11931 | identifier, which should be used to remove the breakpoint later. | |
11932 | In general, places which call this should be using something on the | |
11933 | breakpoint chain instead; this function should be eliminated | |
11934 | someday. */ | |
11935 | ||
11936 | void * | |
6c95b8df PA |
11937 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
11938 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
11939 | { |
11940 | struct bp_target_info *bp_tgt; | |
11941 | ||
6c95b8df | 11942 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 11943 | |
6c95b8df | 11944 | bp_tgt->placed_address_space = aspace; |
8181d85f | 11945 | bp_tgt->placed_address = pc; |
6c95b8df | 11946 | |
a6d9a66e | 11947 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
11948 | { |
11949 | /* Could not insert the breakpoint. */ | |
11950 | xfree (bp_tgt); | |
11951 | return NULL; | |
11952 | } | |
11953 | ||
11954 | return bp_tgt; | |
11955 | } | |
11956 | ||
4a64f543 MS |
11957 | /* Remove a breakpoint BP inserted by |
11958 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
11959 | |
11960 | int | |
a6d9a66e | 11961 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
11962 | { |
11963 | struct bp_target_info *bp_tgt = bp; | |
11964 | int ret; | |
11965 | ||
a6d9a66e | 11966 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
11967 | xfree (bp_tgt); |
11968 | ||
11969 | return ret; | |
11970 | } | |
11971 | ||
4a64f543 MS |
11972 | /* One (or perhaps two) breakpoints used for software single |
11973 | stepping. */ | |
8181d85f DJ |
11974 | |
11975 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 11976 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
11977 | |
11978 | /* Create and insert a breakpoint for software single step. */ | |
11979 | ||
11980 | void | |
6c95b8df | 11981 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
11982 | struct address_space *aspace, |
11983 | CORE_ADDR next_pc) | |
8181d85f DJ |
11984 | { |
11985 | void **bpt_p; | |
11986 | ||
11987 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
11988 | { |
11989 | bpt_p = &single_step_breakpoints[0]; | |
11990 | single_step_gdbarch[0] = gdbarch; | |
11991 | } | |
8181d85f DJ |
11992 | else |
11993 | { | |
11994 | gdb_assert (single_step_breakpoints[1] == NULL); | |
11995 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 11996 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
11997 | } |
11998 | ||
4a64f543 MS |
11999 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12000 | be to only create the breakpoints once, and actually put them on | |
12001 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12002 | We could adjust the addresses each time they were needed. Doing | |
12003 | this requires corresponding changes elsewhere where single step | |
12004 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12005 | |
6c95b8df | 12006 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12007 | if (*bpt_p == NULL) |
5af949e3 UW |
12008 | error (_("Could not insert single-step breakpoint at %s"), |
12009 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12010 | } |
12011 | ||
f02253f1 HZ |
12012 | /* Check if the breakpoints used for software single stepping |
12013 | were inserted or not. */ | |
12014 | ||
12015 | int | |
12016 | single_step_breakpoints_inserted (void) | |
12017 | { | |
12018 | return (single_step_breakpoints[0] != NULL | |
12019 | || single_step_breakpoints[1] != NULL); | |
12020 | } | |
12021 | ||
8181d85f DJ |
12022 | /* Remove and delete any breakpoints used for software single step. */ |
12023 | ||
12024 | void | |
12025 | remove_single_step_breakpoints (void) | |
12026 | { | |
12027 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12028 | ||
12029 | /* See insert_single_step_breakpoint for more about this deprecated | |
12030 | call. */ | |
a6d9a66e UW |
12031 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12032 | single_step_breakpoints[0]); | |
12033 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12034 | single_step_breakpoints[0] = NULL; |
12035 | ||
12036 | if (single_step_breakpoints[1] != NULL) | |
12037 | { | |
a6d9a66e UW |
12038 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12039 | single_step_breakpoints[1]); | |
12040 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12041 | single_step_breakpoints[1] = NULL; |
12042 | } | |
12043 | } | |
12044 | ||
d03285ec UW |
12045 | /* Delete software single step breakpoints without removing them from |
12046 | the inferior. This is intended to be used if the inferior's address | |
12047 | space where they were inserted is already gone, e.g. after exit or | |
12048 | exec. */ | |
12049 | ||
12050 | void | |
12051 | cancel_single_step_breakpoints (void) | |
12052 | { | |
12053 | int i; | |
12054 | ||
12055 | for (i = 0; i < 2; i++) | |
12056 | if (single_step_breakpoints[i]) | |
12057 | { | |
12058 | xfree (single_step_breakpoints[i]); | |
12059 | single_step_breakpoints[i] = NULL; | |
12060 | single_step_gdbarch[i] = NULL; | |
12061 | } | |
12062 | } | |
12063 | ||
12064 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12065 | removing them. */ | |
12066 | ||
12067 | static void | |
12068 | detach_single_step_breakpoints (void) | |
12069 | { | |
12070 | int i; | |
12071 | ||
12072 | for (i = 0; i < 2; i++) | |
12073 | if (single_step_breakpoints[i]) | |
12074 | target_remove_breakpoint (single_step_gdbarch[i], | |
12075 | single_step_breakpoints[i]); | |
12076 | } | |
12077 | ||
4a64f543 MS |
12078 | /* Check whether a software single-step breakpoint is inserted at |
12079 | PC. */ | |
1aafd4da UW |
12080 | |
12081 | static int | |
cc59ec59 MS |
12082 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12083 | CORE_ADDR pc) | |
1aafd4da UW |
12084 | { |
12085 | int i; | |
12086 | ||
12087 | for (i = 0; i < 2; i++) | |
12088 | { | |
12089 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12090 | if (bp_tgt |
12091 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12092 | bp_tgt->placed_address, | |
12093 | aspace, pc)) | |
1aafd4da UW |
12094 | return 1; |
12095 | } | |
12096 | ||
12097 | return 0; | |
12098 | } | |
12099 | ||
a96d9b2e SDJ |
12100 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12101 | non-zero otherwise. */ | |
12102 | static int | |
12103 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12104 | { | |
12105 | if (syscall_catchpoint_p (bp) | |
12106 | && bp->enable_state != bp_disabled | |
12107 | && bp->enable_state != bp_call_disabled) | |
12108 | return 1; | |
12109 | else | |
12110 | return 0; | |
12111 | } | |
12112 | ||
12113 | int | |
12114 | catch_syscall_enabled (void) | |
12115 | { | |
12116 | struct inferior *inf = current_inferior (); | |
12117 | ||
12118 | return inf->total_syscalls_count != 0; | |
12119 | } | |
12120 | ||
12121 | int | |
12122 | catching_syscall_number (int syscall_number) | |
12123 | { | |
12124 | struct breakpoint *bp; | |
12125 | ||
12126 | ALL_BREAKPOINTS (bp) | |
12127 | if (is_syscall_catchpoint_enabled (bp)) | |
12128 | { | |
12129 | if (bp->syscalls_to_be_caught) | |
12130 | { | |
12131 | int i, iter; | |
12132 | for (i = 0; | |
12133 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
12134 | i++) | |
12135 | if (syscall_number == iter) | |
12136 | return 1; | |
12137 | } | |
12138 | else | |
12139 | return 1; | |
12140 | } | |
12141 | ||
12142 | return 0; | |
12143 | } | |
12144 | ||
12145 | /* Complete syscall names. Used by "catch syscall". */ | |
12146 | static char ** | |
12147 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12148 | char *text, char *word) | |
12149 | { | |
12150 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12151 | char **retlist |
12152 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12153 | |
c38eea1a MS |
12154 | xfree (list); |
12155 | return retlist; | |
a96d9b2e SDJ |
12156 | } |
12157 | ||
1042e4c0 SS |
12158 | /* Tracepoint-specific operations. */ |
12159 | ||
12160 | /* Set tracepoint count to NUM. */ | |
12161 | static void | |
12162 | set_tracepoint_count (int num) | |
12163 | { | |
12164 | tracepoint_count = num; | |
4fa62494 | 12165 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
12166 | } |
12167 | ||
12168 | void | |
12169 | trace_command (char *arg, int from_tty) | |
12170 | { | |
8cdf0e15 VP |
12171 | if (create_breakpoint (get_current_arch (), |
12172 | arg, | |
12173 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12174 | 0 /* tempflag */, |
12175 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12176 | 0 /* Ignore count */, |
12177 | pending_break_support, | |
12178 | NULL, | |
12179 | from_tty, | |
84f4c1fe PM |
12180 | 1 /* enabled */, |
12181 | 0 /* internal */)) | |
fd9b8c24 | 12182 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
12183 | } |
12184 | ||
7a697b8d SS |
12185 | void |
12186 | ftrace_command (char *arg, int from_tty) | |
12187 | { | |
8cdf0e15 VP |
12188 | if (create_breakpoint (get_current_arch (), |
12189 | arg, | |
12190 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12191 | 0 /* tempflag */, |
12192 | bp_fast_tracepoint /* type_wanted */, | |
12193 | 0 /* Ignore count */, | |
12194 | pending_break_support, | |
12195 | NULL, | |
12196 | from_tty, | |
84f4c1fe PM |
12197 | 1 /* enabled */, |
12198 | 0 /* internal */)) | |
0fb4aa4b PA |
12199 | set_tracepoint_count (breakpoint_count); |
12200 | } | |
12201 | ||
12202 | /* strace command implementation. Creates a static tracepoint. */ | |
12203 | ||
12204 | void | |
12205 | strace_command (char *arg, int from_tty) | |
12206 | { | |
12207 | if (create_breakpoint (get_current_arch (), | |
12208 | arg, | |
12209 | NULL, 0, 1 /* parse arg */, | |
12210 | 0 /* tempflag */, | |
12211 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12212 | 0 /* Ignore count */, |
12213 | pending_break_support, | |
12214 | NULL, | |
12215 | from_tty, | |
84f4c1fe PM |
12216 | 1 /* enabled */, |
12217 | 0 /* internal */)) | |
fd9b8c24 | 12218 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
12219 | } |
12220 | ||
409873ef SS |
12221 | /* Set up a fake reader function that gets command lines from a linked |
12222 | list that was acquired during tracepoint uploading. */ | |
12223 | ||
12224 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 12225 | static int next_cmd; |
409873ef SS |
12226 | |
12227 | static char * | |
12228 | read_uploaded_action (void) | |
12229 | { | |
12230 | char *rslt; | |
12231 | ||
3149d8c1 | 12232 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 12233 | |
3149d8c1 | 12234 | next_cmd++; |
409873ef SS |
12235 | |
12236 | return rslt; | |
12237 | } | |
12238 | ||
00bf0b85 SS |
12239 | /* Given information about a tracepoint as recorded on a target (which |
12240 | can be either a live system or a trace file), attempt to create an | |
12241 | equivalent GDB tracepoint. This is not a reliable process, since | |
12242 | the target does not necessarily have all the information used when | |
12243 | the tracepoint was originally defined. */ | |
12244 | ||
12245 | struct breakpoint * | |
12246 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 12247 | { |
409873ef | 12248 | char *addr_str, small_buf[100]; |
d5551862 | 12249 | struct breakpoint *tp; |
fd9b8c24 | 12250 | |
409873ef SS |
12251 | if (utp->at_string) |
12252 | addr_str = utp->at_string; | |
12253 | else | |
12254 | { | |
12255 | /* In the absence of a source location, fall back to raw | |
12256 | address. Since there is no way to confirm that the address | |
12257 | means the same thing as when the trace was started, warn the | |
12258 | user. */ | |
3e43a32a MS |
12259 | warning (_("Uploaded tracepoint %d has no " |
12260 | "source location, using raw address"), | |
409873ef SS |
12261 | utp->number); |
12262 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
12263 | addr_str = small_buf; | |
12264 | } | |
12265 | ||
12266 | /* There's not much we can do with a sequence of bytecodes. */ | |
12267 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
12268 | warning (_("Uploaded tracepoint %d condition " |
12269 | "has no source form, ignoring it"), | |
409873ef | 12270 | utp->number); |
d5551862 | 12271 | |
8cdf0e15 | 12272 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
12273 | addr_str, |
12274 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 12275 | 0 /* tempflag */, |
0fb4aa4b | 12276 | utp->type /* type_wanted */, |
8cdf0e15 VP |
12277 | 0 /* Ignore count */, |
12278 | pending_break_support, | |
12279 | NULL, | |
12280 | 0 /* from_tty */, | |
84f4c1fe PM |
12281 | utp->enabled /* enabled */, |
12282 | 0 /* internal */)) | |
fd9b8c24 PA |
12283 | return NULL; |
12284 | ||
00bf0b85 SS |
12285 | set_tracepoint_count (breakpoint_count); |
12286 | ||
409873ef | 12287 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
12288 | tp = get_tracepoint (tracepoint_count); |
12289 | gdb_assert (tp != NULL); | |
d5551862 | 12290 | |
00bf0b85 SS |
12291 | if (utp->pass > 0) |
12292 | { | |
409873ef | 12293 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 12294 | |
409873ef | 12295 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
12296 | } |
12297 | ||
409873ef SS |
12298 | /* If we have uploaded versions of the original commands, set up a |
12299 | special-purpose "reader" function and call the usual command line | |
12300 | reader, then pass the result to the breakpoint command-setting | |
12301 | function. */ | |
3149d8c1 | 12302 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 12303 | { |
409873ef | 12304 | struct command_line *cmd_list; |
00bf0b85 | 12305 | |
409873ef | 12306 | this_utp = utp; |
3149d8c1 | 12307 | next_cmd = 0; |
d5551862 | 12308 | |
409873ef SS |
12309 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
12310 | ||
12311 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 12312 | } |
3149d8c1 SS |
12313 | else if (!VEC_empty (char_ptr, utp->actions) |
12314 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
12315 | warning (_("Uploaded tracepoint %d actions " |
12316 | "have no source form, ignoring them"), | |
409873ef | 12317 | utp->number); |
00bf0b85 SS |
12318 | |
12319 | return tp; | |
12320 | } | |
12321 | ||
1042e4c0 SS |
12322 | /* Print information on tracepoint number TPNUM_EXP, or all if |
12323 | omitted. */ | |
12324 | ||
12325 | static void | |
e5a67952 | 12326 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 12327 | { |
e5a67952 | 12328 | int num_printed; |
1042e4c0 | 12329 | |
e5a67952 | 12330 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
12331 | |
12332 | if (num_printed == 0) | |
1042e4c0 | 12333 | { |
e5a67952 | 12334 | if (args == NULL || *args == '\0') |
d77f58be SS |
12335 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
12336 | else | |
e5a67952 | 12337 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 12338 | } |
ad443146 SS |
12339 | |
12340 | default_collect_info (); | |
1042e4c0 SS |
12341 | } |
12342 | ||
4a64f543 | 12343 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
12344 | Not supported by all targets. */ |
12345 | static void | |
12346 | enable_trace_command (char *args, int from_tty) | |
12347 | { | |
12348 | enable_command (args, from_tty); | |
12349 | } | |
12350 | ||
4a64f543 | 12351 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
12352 | Not supported by all targets. */ |
12353 | static void | |
12354 | disable_trace_command (char *args, int from_tty) | |
12355 | { | |
12356 | disable_command (args, from_tty); | |
12357 | } | |
12358 | ||
4a64f543 | 12359 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
12360 | static void |
12361 | delete_trace_command (char *arg, int from_tty) | |
12362 | { | |
35df4500 | 12363 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
12364 | |
12365 | dont_repeat (); | |
12366 | ||
12367 | if (arg == 0) | |
12368 | { | |
12369 | int breaks_to_delete = 0; | |
12370 | ||
12371 | /* Delete all breakpoints if no argument. | |
12372 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
12373 | have to be deleted with an explicit breakpoint number |
12374 | argument. */ | |
1042e4c0 | 12375 | ALL_TRACEPOINTS (b) |
46c6471b | 12376 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
12377 | { |
12378 | breaks_to_delete = 1; | |
12379 | break; | |
12380 | } | |
1042e4c0 SS |
12381 | |
12382 | /* Ask user only if there are some breakpoints to delete. */ | |
12383 | if (!from_tty | |
12384 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
12385 | { | |
35df4500 | 12386 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12387 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 12388 | delete_breakpoint (b); |
1042e4c0 SS |
12389 | } |
12390 | } | |
12391 | else | |
95a42b64 | 12392 | map_breakpoint_numbers (arg, do_delete_breakpoint, NULL); |
1042e4c0 SS |
12393 | } |
12394 | ||
197f0a60 TT |
12395 | /* Helper function for trace_pass_command. */ |
12396 | ||
12397 | static void | |
12398 | trace_pass_set_count (struct breakpoint *bp, int count, int from_tty) | |
12399 | { | |
12400 | bp->pass_count = count; | |
12401 | observer_notify_tracepoint_modified (bp->number); | |
12402 | if (from_tty) | |
12403 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
12404 | bp->number, count); | |
12405 | } | |
12406 | ||
1042e4c0 SS |
12407 | /* Set passcount for tracepoint. |
12408 | ||
12409 | First command argument is passcount, second is tracepoint number. | |
12410 | If tracepoint number omitted, apply to most recently defined. | |
12411 | Also accepts special argument "all". */ | |
12412 | ||
12413 | static void | |
12414 | trace_pass_command (char *args, int from_tty) | |
12415 | { | |
197f0a60 | 12416 | struct breakpoint *t1; |
1042e4c0 | 12417 | unsigned int count; |
1042e4c0 SS |
12418 | |
12419 | if (args == 0 || *args == 0) | |
3e43a32a MS |
12420 | error (_("passcount command requires an " |
12421 | "argument (count + optional TP num)")); | |
1042e4c0 | 12422 | |
4a64f543 | 12423 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
12424 | |
12425 | while (*args && isspace ((int) *args)) | |
12426 | args++; | |
12427 | ||
12428 | if (*args && strncasecmp (args, "all", 3) == 0) | |
12429 | { | |
12430 | args += 3; /* Skip special argument "all". */ | |
1042e4c0 SS |
12431 | if (*args) |
12432 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 12433 | |
197f0a60 TT |
12434 | ALL_TRACEPOINTS (t1) |
12435 | { | |
12436 | trace_pass_set_count (t1, count, from_tty); | |
12437 | } | |
12438 | } | |
12439 | else if (*args == '\0') | |
1042e4c0 | 12440 | { |
197f0a60 | 12441 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 12442 | if (t1) |
197f0a60 TT |
12443 | trace_pass_set_count (t1, count, from_tty); |
12444 | } | |
12445 | else | |
12446 | { | |
12447 | struct get_number_or_range_state state; | |
12448 | ||
12449 | init_number_or_range (&state, args); | |
12450 | while (!state.finished) | |
1042e4c0 | 12451 | { |
197f0a60 TT |
12452 | t1 = get_tracepoint_by_number (&args, &state, 1); |
12453 | if (t1) | |
12454 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
12455 | } |
12456 | } | |
1042e4c0 SS |
12457 | } |
12458 | ||
12459 | struct breakpoint * | |
12460 | get_tracepoint (int num) | |
12461 | { | |
12462 | struct breakpoint *t; | |
12463 | ||
12464 | ALL_TRACEPOINTS (t) | |
12465 | if (t->number == num) | |
12466 | return t; | |
12467 | ||
12468 | return NULL; | |
12469 | } | |
12470 | ||
d5551862 SS |
12471 | /* Find the tracepoint with the given target-side number (which may be |
12472 | different from the tracepoint number after disconnecting and | |
12473 | reconnecting). */ | |
12474 | ||
12475 | struct breakpoint * | |
12476 | get_tracepoint_by_number_on_target (int num) | |
12477 | { | |
12478 | struct breakpoint *t; | |
12479 | ||
12480 | ALL_TRACEPOINTS (t) | |
12481 | if (t->number_on_target == num) | |
12482 | return t; | |
12483 | ||
12484 | return NULL; | |
12485 | } | |
12486 | ||
1042e4c0 | 12487 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
12488 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
12489 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 SS |
12490 | recent tracepoint (tracepoint_count) is returned. */ |
12491 | struct breakpoint * | |
197f0a60 TT |
12492 | get_tracepoint_by_number (char **arg, |
12493 | struct get_number_or_range_state *state, | |
12494 | int optional_p) | |
1042e4c0 SS |
12495 | { |
12496 | extern int tracepoint_count; | |
12497 | struct breakpoint *t; | |
12498 | int tpnum; | |
12499 | char *instring = arg == NULL ? NULL : *arg; | |
12500 | ||
197f0a60 TT |
12501 | if (state) |
12502 | { | |
12503 | gdb_assert (!state->finished); | |
12504 | tpnum = get_number_or_range (state); | |
12505 | } | |
12506 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
12507 | { |
12508 | if (optional_p) | |
12509 | tpnum = tracepoint_count; | |
12510 | else | |
12511 | error_no_arg (_("tracepoint number")); | |
12512 | } | |
12513 | else | |
197f0a60 | 12514 | tpnum = get_number (arg); |
1042e4c0 SS |
12515 | |
12516 | if (tpnum <= 0) | |
12517 | { | |
12518 | if (instring && *instring) | |
12519 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
12520 | instring); | |
12521 | else | |
3e43a32a MS |
12522 | printf_filtered (_("Tracepoint argument missing " |
12523 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
12524 | return NULL; |
12525 | } | |
12526 | ||
12527 | ALL_TRACEPOINTS (t) | |
12528 | if (t->number == tpnum) | |
12529 | { | |
12530 | return t; | |
12531 | } | |
12532 | ||
1042e4c0 SS |
12533 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
12534 | return NULL; | |
12535 | } | |
12536 | ||
6149aea9 PA |
12537 | /* Save information on user settable breakpoints (watchpoints, etc) to |
12538 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
12539 | on each breakpoint and only include the ones for which it returns | |
12540 | non-zero. */ | |
12541 | ||
1042e4c0 | 12542 | static void |
6149aea9 PA |
12543 | save_breakpoints (char *filename, int from_tty, |
12544 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
12545 | { |
12546 | struct breakpoint *tp; | |
6149aea9 | 12547 | int any = 0; |
a7bdde9e | 12548 | char *pathname; |
1042e4c0 | 12549 | struct cleanup *cleanup; |
a7bdde9e | 12550 | struct ui_file *fp; |
6149aea9 | 12551 | int extra_trace_bits = 0; |
1042e4c0 | 12552 | |
6149aea9 PA |
12553 | if (filename == 0 || *filename == 0) |
12554 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
12555 | |
12556 | /* See if we have anything to save. */ | |
6149aea9 | 12557 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 12558 | { |
6149aea9 | 12559 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 12560 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
12561 | continue; |
12562 | ||
12563 | /* If we have a filter, only save the breakpoints it accepts. */ | |
12564 | if (filter && !filter (tp)) | |
12565 | continue; | |
12566 | ||
12567 | any = 1; | |
12568 | ||
12569 | if (is_tracepoint (tp)) | |
12570 | { | |
12571 | extra_trace_bits = 1; | |
12572 | ||
12573 | /* We can stop searching. */ | |
12574 | break; | |
12575 | } | |
1042e4c0 | 12576 | } |
6149aea9 PA |
12577 | |
12578 | if (!any) | |
1042e4c0 | 12579 | { |
6149aea9 | 12580 | warning (_("Nothing to save.")); |
1042e4c0 SS |
12581 | return; |
12582 | } | |
12583 | ||
6149aea9 | 12584 | pathname = tilde_expand (filename); |
1042e4c0 | 12585 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 12586 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 12587 | if (!fp) |
6149aea9 PA |
12588 | error (_("Unable to open file '%s' for saving (%s)"), |
12589 | filename, safe_strerror (errno)); | |
a7bdde9e | 12590 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 12591 | |
6149aea9 PA |
12592 | if (extra_trace_bits) |
12593 | save_trace_state_variables (fp); | |
8bf6485c | 12594 | |
6149aea9 | 12595 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 12596 | { |
6149aea9 | 12597 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 12598 | if (!user_breakpoint_p (tp)) |
6149aea9 | 12599 | continue; |
8bf6485c | 12600 | |
6149aea9 PA |
12601 | /* If we have a filter, only save the breakpoints it accepts. */ |
12602 | if (filter && !filter (tp)) | |
12603 | continue; | |
12604 | ||
26063d49 | 12605 | if (tp->ops != NULL && tp->ops->print_recreate != NULL) |
6149aea9 | 12606 | (tp->ops->print_recreate) (tp, fp); |
1042e4c0 SS |
12607 | else |
12608 | { | |
6149aea9 PA |
12609 | if (tp->type == bp_fast_tracepoint) |
12610 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
12611 | if (tp->type == bp_static_tracepoint) |
12612 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
12613 | else if (tp->type == bp_tracepoint) |
12614 | fprintf_unfiltered (fp, "trace"); | |
12615 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12616 | fprintf_unfiltered (fp, "tbreak"); | |
12617 | else if (tp->type == bp_breakpoint) | |
12618 | fprintf_unfiltered (fp, "break"); | |
12619 | else if (tp->type == bp_hardware_breakpoint | |
12620 | && tp->disposition == disp_del) | |
12621 | fprintf_unfiltered (fp, "thbreak"); | |
12622 | else if (tp->type == bp_hardware_breakpoint) | |
12623 | fprintf_unfiltered (fp, "hbreak"); | |
12624 | else if (tp->type == bp_watchpoint) | |
12625 | fprintf_unfiltered (fp, "watch"); | |
12626 | else if (tp->type == bp_hardware_watchpoint) | |
12627 | fprintf_unfiltered (fp, "watch"); | |
12628 | else if (tp->type == bp_read_watchpoint) | |
12629 | fprintf_unfiltered (fp, "rwatch"); | |
12630 | else if (tp->type == bp_access_watchpoint) | |
12631 | fprintf_unfiltered (fp, "awatch"); | |
12632 | else | |
12633 | internal_error (__FILE__, __LINE__, | |
12634 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12635 | ||
12636 | if (tp->exp_string) | |
12637 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
12638 | else if (tp->addr_string) | |
12639 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
12640 | else | |
12641 | { | |
12642 | char tmp[40]; | |
12643 | ||
12644 | sprintf_vma (tmp, tp->loc->address); | |
12645 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
12646 | } | |
1042e4c0 SS |
12647 | } |
12648 | ||
6149aea9 PA |
12649 | if (tp->thread != -1) |
12650 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
12651 | ||
12652 | if (tp->task != 0) | |
12653 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
12654 | |
12655 | fprintf_unfiltered (fp, "\n"); | |
12656 | ||
6149aea9 PA |
12657 | /* Note, we can't rely on tp->number for anything, as we can't |
12658 | assume the recreated breakpoint numbers will match. Use $bpnum | |
12659 | instead. */ | |
12660 | ||
12661 | if (tp->cond_string) | |
12662 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
12663 | ||
12664 | if (tp->ignore_count) | |
12665 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
12666 | ||
1042e4c0 | 12667 | if (tp->pass_count) |
a7bdde9e | 12668 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 12669 | |
a7bdde9e | 12670 | if (tp->commands) |
1042e4c0 | 12671 | { |
a7bdde9e VP |
12672 | volatile struct gdb_exception ex; |
12673 | ||
6149aea9 | 12674 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
12675 | |
12676 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 12677 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 12678 | { |
9add0f1b | 12679 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
12680 | } |
12681 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 12682 | |
a7bdde9e VP |
12683 | if (ex.reason < 0) |
12684 | throw_exception (ex); | |
1042e4c0 | 12685 | |
a7bdde9e | 12686 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 12687 | } |
6149aea9 PA |
12688 | |
12689 | if (tp->enable_state == bp_disabled) | |
12690 | fprintf_unfiltered (fp, "disable\n"); | |
12691 | ||
12692 | /* If this is a multi-location breakpoint, check if the locations | |
12693 | should be individually disabled. Watchpoint locations are | |
12694 | special, and not user visible. */ | |
12695 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
12696 | { | |
12697 | struct bp_location *loc; | |
12698 | int n = 1; | |
12699 | ||
12700 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
12701 | if (!loc->enabled) | |
12702 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
12703 | } | |
1042e4c0 | 12704 | } |
8bf6485c | 12705 | |
6149aea9 | 12706 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
12707 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
12708 | ||
1042e4c0 SS |
12709 | do_cleanups (cleanup); |
12710 | if (from_tty) | |
6149aea9 PA |
12711 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
12712 | } | |
12713 | ||
12714 | /* The `save breakpoints' command. */ | |
12715 | ||
12716 | static void | |
12717 | save_breakpoints_command (char *args, int from_tty) | |
12718 | { | |
12719 | save_breakpoints (args, from_tty, NULL); | |
12720 | } | |
12721 | ||
12722 | /* The `save tracepoints' command. */ | |
12723 | ||
12724 | static void | |
12725 | save_tracepoints_command (char *args, int from_tty) | |
12726 | { | |
12727 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
12728 | } |
12729 | ||
12730 | /* Create a vector of all tracepoints. */ | |
12731 | ||
12732 | VEC(breakpoint_p) * | |
eeae04df | 12733 | all_tracepoints (void) |
1042e4c0 SS |
12734 | { |
12735 | VEC(breakpoint_p) *tp_vec = 0; | |
12736 | struct breakpoint *tp; | |
12737 | ||
12738 | ALL_TRACEPOINTS (tp) | |
12739 | { | |
12740 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
12741 | } | |
12742 | ||
12743 | return tp_vec; | |
12744 | } | |
12745 | ||
c906108c | 12746 | \f |
4a64f543 MS |
12747 | /* This help string is used for the break, hbreak, tbreak and thbreak |
12748 | commands. It is defined as a macro to prevent duplication. | |
12749 | COMMAND should be a string constant containing the name of the | |
12750 | command. */ | |
31e2b00f AS |
12751 | #define BREAK_ARGS_HELP(command) \ |
12752 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
12753 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
12754 | If a line number is specified, break at start of code for that line.\n\ | |
12755 | If a function is specified, break at start of code for that function.\n\ | |
12756 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
12757 | With no LOCATION, uses current execution address of the selected\n\ |
12758 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
12759 | \n\ |
12760 | THREADNUM is the number from \"info threads\".\n\ | |
12761 | CONDITION is a boolean expression.\n\ | |
12762 | \n\ | |
d41c0fc8 PA |
12763 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
12764 | conditions are different.\n\ | |
31e2b00f AS |
12765 | \n\ |
12766 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
12767 | ||
44feb3ce TT |
12768 | /* List of subcommands for "catch". */ |
12769 | static struct cmd_list_element *catch_cmdlist; | |
12770 | ||
12771 | /* List of subcommands for "tcatch". */ | |
12772 | static struct cmd_list_element *tcatch_cmdlist; | |
12773 | ||
12774 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
12775 | lists, and pass some additional user data to the command function. */ | |
12776 | static void | |
12777 | add_catch_command (char *name, char *docstring, | |
12778 | void (*sfunc) (char *args, int from_tty, | |
12779 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
12780 | char **(*completer) (struct cmd_list_element *cmd, |
12781 | char *text, char *word), | |
44feb3ce TT |
12782 | void *user_data_catch, |
12783 | void *user_data_tcatch) | |
12784 | { | |
12785 | struct cmd_list_element *command; | |
12786 | ||
12787 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12788 | &catch_cmdlist); | |
12789 | set_cmd_sfunc (command, sfunc); | |
12790 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 12791 | set_cmd_completer (command, completer); |
44feb3ce TT |
12792 | |
12793 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12794 | &tcatch_cmdlist); | |
12795 | set_cmd_sfunc (command, sfunc); | |
12796 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 12797 | set_cmd_completer (command, completer); |
44feb3ce TT |
12798 | } |
12799 | ||
6c95b8df | 12800 | static void |
a79b8f6e | 12801 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 12802 | { |
6c95b8df PA |
12803 | inf->total_syscalls_count = 0; |
12804 | inf->any_syscall_count = 0; | |
12805 | VEC_free (int, inf->syscalls_counts); | |
12806 | } | |
12807 | ||
6149aea9 PA |
12808 | static void |
12809 | save_command (char *arg, int from_tty) | |
12810 | { | |
3e43a32a MS |
12811 | printf_unfiltered (_("\"save\" must be followed by " |
12812 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
12813 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
12814 | } | |
12815 | ||
84f4c1fe PM |
12816 | struct breakpoint * |
12817 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
12818 | void *data) | |
12819 | { | |
35df4500 | 12820 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 12821 | |
35df4500 | 12822 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
12823 | { |
12824 | if ((*callback) (b, data)) | |
12825 | return b; | |
12826 | } | |
12827 | ||
12828 | return NULL; | |
12829 | } | |
12830 | ||
c906108c | 12831 | void |
fba45db2 | 12832 | _initialize_breakpoint (void) |
c906108c SS |
12833 | { |
12834 | struct cmd_list_element *c; | |
12835 | ||
84acb35a | 12836 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 12837 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 12838 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 12839 | |
17450429 PP |
12840 | breakpoint_objfile_key = register_objfile_data (); |
12841 | ||
c906108c SS |
12842 | breakpoint_chain = 0; |
12843 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
12844 | before a breakpoint is set. */ | |
12845 | breakpoint_count = 0; | |
12846 | ||
1042e4c0 SS |
12847 | tracepoint_count = 0; |
12848 | ||
1bedd215 AC |
12849 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
12850 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
12851 | Usage is `ignore N COUNT'.")); | |
c906108c | 12852 | if (xdb_commands) |
c5aa993b | 12853 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 12854 | |
1bedd215 AC |
12855 | add_com ("commands", class_breakpoint, commands_command, _("\ |
12856 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
12857 | Give breakpoint number as argument after \"commands\".\n\ |
12858 | With no argument, the targeted breakpoint is the last one set.\n\ | |
12859 | The commands themselves follow starting on the next line.\n\ | |
12860 | Type a line containing \"end\" to indicate the end of them.\n\ | |
12861 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 12862 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 12863 | |
1bedd215 AC |
12864 | add_com ("condition", class_breakpoint, condition_command, _("\ |
12865 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 12866 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 12867 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 12868 | |
1bedd215 | 12869 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 12870 | Set a temporary breakpoint.\n\ |
c906108c SS |
12871 | Like \"break\" except the breakpoint is only temporary,\n\ |
12872 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
12873 | by using \"enable delete\" on the breakpoint number.\n\ |
12874 | \n" | |
12875 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 12876 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12877 | |
1bedd215 | 12878 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 12879 | Set a hardware assisted breakpoint.\n\ |
c906108c | 12880 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
12881 | some target hardware may not have this support.\n\ |
12882 | \n" | |
12883 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 12884 | set_cmd_completer (c, location_completer); |
c906108c | 12885 | |
1bedd215 | 12886 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 12887 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 12888 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
12889 | so it will be deleted when hit.\n\ |
12890 | \n" | |
12891 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 12892 | set_cmd_completer (c, location_completer); |
c906108c | 12893 | |
1bedd215 AC |
12894 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
12895 | Enable some breakpoints.\n\ | |
c906108c SS |
12896 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12897 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12898 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12899 | With a subcommand you can enable temporarily."), |
c906108c SS |
12900 | &enablelist, "enable ", 1, &cmdlist); |
12901 | if (xdb_commands) | |
1bedd215 AC |
12902 | add_com ("ab", class_breakpoint, enable_command, _("\ |
12903 | Enable some breakpoints.\n\ | |
c906108c SS |
12904 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12905 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12906 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12907 | With a subcommand you can enable temporarily.")); |
c906108c SS |
12908 | |
12909 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
12910 | ||
84951ab5 | 12911 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 12912 | Enable some breakpoints.\n\ |
c906108c SS |
12913 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12914 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12915 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 12916 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 12917 | |
1a966eab AC |
12918 | add_cmd ("once", no_class, enable_once_command, _("\ |
12919 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12920 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12921 | &enablebreaklist); |
12922 | ||
1a966eab AC |
12923 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12924 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12925 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12926 | &enablebreaklist); |
12927 | ||
1a966eab AC |
12928 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12929 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12930 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12931 | &enablelist); |
12932 | ||
1a966eab AC |
12933 | add_cmd ("once", no_class, enable_once_command, _("\ |
12934 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12935 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12936 | &enablelist); |
12937 | ||
1bedd215 AC |
12938 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
12939 | Disable some breakpoints.\n\ | |
c906108c SS |
12940 | Arguments are breakpoint numbers with spaces in between.\n\ |
12941 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12942 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
12943 | &disablelist, "disable ", 1, &cmdlist); |
12944 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
12945 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
12946 | if (xdb_commands) | |
1bedd215 AC |
12947 | add_com ("sb", class_breakpoint, disable_command, _("\ |
12948 | Disable some breakpoints.\n\ | |
c906108c SS |
12949 | Arguments are breakpoint numbers with spaces in between.\n\ |
12950 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12951 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 12952 | |
1a966eab AC |
12953 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
12954 | Disable some breakpoints.\n\ | |
c906108c SS |
12955 | Arguments are breakpoint numbers with spaces in between.\n\ |
12956 | To disable all breakpoints, give no argument.\n\ | |
12957 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 12958 | This command may be abbreviated \"disable\"."), |
c906108c SS |
12959 | &disablelist); |
12960 | ||
1bedd215 AC |
12961 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
12962 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12963 | Arguments are breakpoint numbers with spaces in between.\n\ |
12964 | To delete all breakpoints, give no argument.\n\ | |
12965 | \n\ | |
12966 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 12967 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
12968 | &deletelist, "delete ", 1, &cmdlist); |
12969 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 12970 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 12971 | if (xdb_commands) |
1bedd215 AC |
12972 | add_com ("db", class_breakpoint, delete_command, _("\ |
12973 | Delete some breakpoints.\n\ | |
c906108c | 12974 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 12975 | To delete all breakpoints, give no argument.\n")); |
c906108c | 12976 | |
1a966eab AC |
12977 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
12978 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
12979 | Arguments are breakpoint numbers with spaces in between.\n\ |
12980 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 12981 | This command may be abbreviated \"delete\"."), |
c906108c SS |
12982 | &deletelist); |
12983 | ||
1bedd215 AC |
12984 | add_com ("clear", class_breakpoint, clear_command, _("\ |
12985 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
12986 | Argument may be line number, function name, or \"*\" and an address.\n\ |
12987 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
12988 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
12989 | If an address is specified, breakpoints at that address are cleared.\n\ |
12990 | \n\ | |
12991 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
12992 | is executing in.\n\ |
12993 | \n\ | |
1bedd215 | 12994 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 12995 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 12996 | |
1bedd215 | 12997 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
12998 | Set breakpoint at specified line or function.\n" |
12999 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 13000 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13001 | |
c906108c SS |
13002 | add_com_alias ("b", "break", class_run, 1); |
13003 | add_com_alias ("br", "break", class_run, 1); | |
13004 | add_com_alias ("bre", "break", class_run, 1); | |
13005 | add_com_alias ("brea", "break", class_run, 1); | |
13006 | ||
7681d515 PM |
13007 | if (xdb_commands) |
13008 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
13009 | |
13010 | if (dbx_commands) | |
13011 | { | |
1bedd215 AC |
13012 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
13013 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
13014 | &stoplist, "stop ", 1, &cmdlist); |
13015 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 13016 | _("Break in function or address."), &stoplist); |
c5aa993b | 13017 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 13018 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
13019 | add_com ("status", class_info, breakpoints_info, _("\ |
13020 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13021 | The \"Type\" column indicates one of:\n\ |
13022 | \tbreakpoint - normal breakpoint\n\ | |
13023 | \twatchpoint - watchpoint\n\ | |
13024 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13025 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13026 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13027 | address and file/line number respectively.\n\ |
13028 | \n\ | |
13029 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13030 | are set to the address of the last breakpoint listed unless the command\n\ |
13031 | is prefixed with \"server \".\n\n\ | |
c906108c | 13032 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13033 | breakpoint set.")); |
c906108c SS |
13034 | } |
13035 | ||
1bedd215 | 13036 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 13037 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
13038 | The \"Type\" column indicates one of:\n\ |
13039 | \tbreakpoint - normal breakpoint\n\ | |
13040 | \twatchpoint - watchpoint\n\ | |
13041 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13042 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13043 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13044 | address and file/line number respectively.\n\ |
13045 | \n\ | |
13046 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13047 | are set to the address of the last breakpoint listed unless the command\n\ |
13048 | is prefixed with \"server \".\n\n\ | |
c906108c | 13049 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13050 | breakpoint set.")); |
c906108c | 13051 | |
6b04bdb7 MS |
13052 | add_info_alias ("b", "breakpoints", 1); |
13053 | ||
c906108c | 13054 | if (xdb_commands) |
1bedd215 AC |
13055 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
13056 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13057 | The \"Type\" column indicates one of:\n\ |
13058 | \tbreakpoint - normal breakpoint\n\ | |
13059 | \twatchpoint - watchpoint\n\ | |
13060 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13061 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13062 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13063 | address and file/line number respectively.\n\ |
13064 | \n\ | |
13065 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13066 | are set to the address of the last breakpoint listed unless the command\n\ |
13067 | is prefixed with \"server \".\n\n\ | |
c906108c | 13068 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13069 | breakpoint set.")); |
c906108c | 13070 | |
1a966eab AC |
13071 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
13072 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13073 | The \"Type\" column indicates one of:\n\ |
13074 | \tbreakpoint - normal breakpoint\n\ | |
13075 | \twatchpoint - watchpoint\n\ | |
13076 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
13077 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
13078 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
13079 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
13080 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
13081 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
13082 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
13083 | address and file/line number respectively.\n\ |
13084 | \n\ | |
13085 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13086 | are set to the address of the last breakpoint listed unless the command\n\ |
13087 | is prefixed with \"server \".\n\n\ | |
c906108c | 13088 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 13089 | breakpoint set."), |
c906108c SS |
13090 | &maintenanceinfolist); |
13091 | ||
44feb3ce TT |
13092 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
13093 | Set catchpoints to catch events."), | |
13094 | &catch_cmdlist, "catch ", | |
13095 | 0/*allow-unknown*/, &cmdlist); | |
13096 | ||
13097 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
13098 | Set temporary catchpoints to catch events."), | |
13099 | &tcatch_cmdlist, "tcatch ", | |
13100 | 0/*allow-unknown*/, &cmdlist); | |
13101 | ||
13102 | /* Add catch and tcatch sub-commands. */ | |
13103 | add_catch_command ("catch", _("\ | |
13104 | Catch an exception, when caught.\n\ | |
13105 | With an argument, catch only exceptions with the given name."), | |
13106 | catch_catch_command, | |
a96d9b2e | 13107 | NULL, |
44feb3ce TT |
13108 | CATCH_PERMANENT, |
13109 | CATCH_TEMPORARY); | |
13110 | add_catch_command ("throw", _("\ | |
13111 | Catch an exception, when thrown.\n\ | |
13112 | With an argument, catch only exceptions with the given name."), | |
13113 | catch_throw_command, | |
a96d9b2e | 13114 | NULL, |
44feb3ce TT |
13115 | CATCH_PERMANENT, |
13116 | CATCH_TEMPORARY); | |
13117 | add_catch_command ("fork", _("Catch calls to fork."), | |
13118 | catch_fork_command_1, | |
a96d9b2e | 13119 | NULL, |
44feb3ce TT |
13120 | (void *) (uintptr_t) catch_fork_permanent, |
13121 | (void *) (uintptr_t) catch_fork_temporary); | |
13122 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
13123 | catch_fork_command_1, | |
a96d9b2e | 13124 | NULL, |
44feb3ce TT |
13125 | (void *) (uintptr_t) catch_vfork_permanent, |
13126 | (void *) (uintptr_t) catch_vfork_temporary); | |
13127 | add_catch_command ("exec", _("Catch calls to exec."), | |
13128 | catch_exec_command_1, | |
a96d9b2e SDJ |
13129 | NULL, |
13130 | CATCH_PERMANENT, | |
13131 | CATCH_TEMPORARY); | |
13132 | add_catch_command ("syscall", _("\ | |
13133 | Catch system calls by their names and/or numbers.\n\ | |
13134 | Arguments say which system calls to catch. If no arguments\n\ | |
13135 | are given, every system call will be caught.\n\ | |
13136 | Arguments, if given, should be one or more system call names\n\ | |
13137 | (if your system supports that), or system call numbers."), | |
13138 | catch_syscall_command_1, | |
13139 | catch_syscall_completer, | |
44feb3ce TT |
13140 | CATCH_PERMANENT, |
13141 | CATCH_TEMPORARY); | |
44feb3ce TT |
13142 | add_catch_command ("exception", _("\ |
13143 | Catch Ada exceptions, when raised.\n\ | |
13144 | With an argument, catch only exceptions with the given name."), | |
13145 | catch_ada_exception_command, | |
a96d9b2e | 13146 | NULL, |
44feb3ce TT |
13147 | CATCH_PERMANENT, |
13148 | CATCH_TEMPORARY); | |
13149 | add_catch_command ("assert", _("\ | |
13150 | Catch failed Ada assertions, when raised.\n\ | |
13151 | With an argument, catch only exceptions with the given name."), | |
13152 | catch_assert_command, | |
a96d9b2e | 13153 | NULL, |
44feb3ce TT |
13154 | CATCH_PERMANENT, |
13155 | CATCH_TEMPORARY); | |
c5aa993b | 13156 | |
1bedd215 AC |
13157 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
13158 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13159 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 13160 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13161 | an expression changes.\n\ |
13162 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13163 | the memory to which it refers.")); | |
65d12d83 | 13164 | set_cmd_completer (c, expression_completer); |
c906108c | 13165 | |
1bedd215 AC |
13166 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
13167 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 13168 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 13169 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13170 | an expression is read.\n\ |
13171 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13172 | the memory to which it refers.")); | |
65d12d83 | 13173 | set_cmd_completer (c, expression_completer); |
c906108c | 13174 | |
1bedd215 AC |
13175 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
13176 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13177 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 13178 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13179 | an expression is either read or written.\n\ |
13180 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13181 | the memory to which it refers.")); | |
65d12d83 | 13182 | set_cmd_completer (c, expression_completer); |
c906108c | 13183 | |
d77f58be | 13184 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 13185 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 13186 | |
920d2a44 AC |
13187 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
13188 | respond to changes - contrary to the description. */ | |
85c07804 AC |
13189 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
13190 | &can_use_hw_watchpoints, _("\ | |
13191 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
13192 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
13193 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
13194 | such is available. (However, any hardware watchpoints that were\n\ | |
13195 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
13196 | hardware.)"), |
13197 | NULL, | |
920d2a44 | 13198 | show_can_use_hw_watchpoints, |
85c07804 | 13199 | &setlist, &showlist); |
c906108c SS |
13200 | |
13201 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 13202 | |
1042e4c0 SS |
13203 | /* Tracepoint manipulation commands. */ |
13204 | ||
13205 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
13206 | Set a tracepoint at specified line or function.\n\ | |
13207 | \n" | |
13208 | BREAK_ARGS_HELP ("trace") "\n\ | |
13209 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13210 | set_cmd_completer (c, location_completer); | |
13211 | ||
13212 | add_com_alias ("tp", "trace", class_alias, 0); | |
13213 | add_com_alias ("tr", "trace", class_alias, 1); | |
13214 | add_com_alias ("tra", "trace", class_alias, 1); | |
13215 | add_com_alias ("trac", "trace", class_alias, 1); | |
13216 | ||
7a697b8d SS |
13217 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
13218 | Set a fast tracepoint at specified line or function.\n\ | |
13219 | \n" | |
13220 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
13221 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13222 | set_cmd_completer (c, location_completer); | |
13223 | ||
0fb4aa4b PA |
13224 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
13225 | Set a static tracepoint at specified line, function or marker.\n\ | |
13226 | \n\ | |
13227 | strace [LOCATION] [if CONDITION]\n\ | |
13228 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
13229 | or -m MARKER_ID.\n\ | |
13230 | If a line number is specified, probe the marker at start of code\n\ | |
13231 | for that line. If a function is specified, probe the marker at start\n\ | |
13232 | of code for that function. If an address is specified, probe the marker\n\ | |
13233 | at that exact address. If a marker id is specified, probe the marker\n\ | |
13234 | with that name. With no LOCATION, uses current execution address of\n\ | |
13235 | the selected stack frame.\n\ | |
13236 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
13237 | This collects arbitrary user data passed in the probe point call to the\n\ | |
13238 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
13239 | by printing the $_sdata variable like any other convenience variable.\n\ | |
13240 | \n\ | |
13241 | CONDITION is a boolean expression.\n\ | |
13242 | \n\ | |
d41c0fc8 PA |
13243 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
13244 | conditions are different.\n\ | |
0fb4aa4b PA |
13245 | \n\ |
13246 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
13247 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13248 | set_cmd_completer (c, location_completer); | |
13249 | ||
1042e4c0 | 13250 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 13251 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
13252 | Convenience variable \"$tpnum\" contains the number of the\n\ |
13253 | last tracepoint set.")); | |
13254 | ||
13255 | add_info_alias ("tp", "tracepoints", 1); | |
13256 | ||
13257 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
13258 | Delete specified tracepoints.\n\ | |
13259 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13260 | No argument means delete all tracepoints."), | |
13261 | &deletelist); | |
13262 | ||
13263 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
13264 | Disable specified tracepoints.\n\ | |
13265 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13266 | No argument means disable all tracepoints."), | |
13267 | &disablelist); | |
13268 | deprecate_cmd (c, "disable"); | |
13269 | ||
13270 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
13271 | Enable specified tracepoints.\n\ | |
13272 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13273 | No argument means enable all tracepoints."), | |
13274 | &enablelist); | |
13275 | deprecate_cmd (c, "enable"); | |
13276 | ||
13277 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
13278 | Set the passcount for a tracepoint.\n\ | |
13279 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
13280 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
13281 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
13282 | ||
6149aea9 PA |
13283 | add_prefix_cmd ("save", class_breakpoint, save_command, |
13284 | _("Save breakpoint definitions as a script."), | |
13285 | &save_cmdlist, "save ", | |
13286 | 0/*allow-unknown*/, &cmdlist); | |
13287 | ||
13288 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
13289 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 13290 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
13291 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
13292 | session to restore them."), | |
13293 | &save_cmdlist); | |
13294 | set_cmd_completer (c, filename_completer); | |
13295 | ||
13296 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 13297 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
13298 | Use the 'source' command in another debug session to restore them."), |
13299 | &save_cmdlist); | |
1042e4c0 SS |
13300 | set_cmd_completer (c, filename_completer); |
13301 | ||
6149aea9 PA |
13302 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
13303 | deprecate_cmd (c, "save tracepoints"); | |
13304 | ||
1bedd215 | 13305 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13306 | Breakpoint specific settings\n\ |
13307 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13308 | pending breakpoint behavior"), |
fa8d40ab JJ |
13309 | &breakpoint_set_cmdlist, "set breakpoint ", |
13310 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 13311 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13312 | Breakpoint specific settings\n\ |
13313 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13314 | pending breakpoint behavior"), |
fa8d40ab JJ |
13315 | &breakpoint_show_cmdlist, "show breakpoint ", |
13316 | 0/*allow-unknown*/, &showlist); | |
13317 | ||
7915a72c AC |
13318 | add_setshow_auto_boolean_cmd ("pending", no_class, |
13319 | &pending_break_support, _("\ | |
13320 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
13321 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
13322 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
13323 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
13324 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 13325 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 13326 | NULL, |
920d2a44 | 13327 | show_pending_break_support, |
6e1d7d6c AC |
13328 | &breakpoint_set_cmdlist, |
13329 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
13330 | |
13331 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
13332 | |
13333 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
13334 | &automatic_hardware_breakpoints, _("\ | |
13335 | Set automatic usage of hardware breakpoints."), _("\ | |
13336 | Show automatic usage of hardware breakpoints."), _("\ | |
13337 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
13338 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
13339 | a warning will be emitted for such breakpoints."), | |
13340 | NULL, | |
13341 | show_automatic_hardware_breakpoints, | |
13342 | &breakpoint_set_cmdlist, | |
13343 | &breakpoint_show_cmdlist); | |
74960c60 | 13344 | |
33e5cbd6 PA |
13345 | add_setshow_enum_cmd ("always-inserted", class_support, |
13346 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
13347 | Set mode for inserting breakpoints."), _("\ |
13348 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
13349 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
13350 | resumed, and removed when execution stops. When this mode is on,\n\ | |
13351 | breakpoints are inserted immediately and removed only when the user\n\ | |
13352 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
13353 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
13354 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
13355 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
13356 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
13357 | NULL, |
13358 | &show_always_inserted_mode, | |
13359 | &breakpoint_set_cmdlist, | |
13360 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
13361 | |
13362 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
13363 | Set a breakpoint for an address range.\n\ | |
13364 | break-range START-LOCATION, END-LOCATION\n\ | |
13365 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
13366 | LINENUM, for that line in the current file,\n\ | |
13367 | FILE:LINENUM, for that line in that file,\n\ | |
13368 | +OFFSET, for that number of lines after the current line\n\ | |
13369 | or the start of the range\n\ | |
13370 | FUNCTION, for the first line in that function,\n\ | |
13371 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
13372 | *ADDRESS, for the instruction at that address.\n\ | |
13373 | \n\ | |
13374 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
13375 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
13376 | range (including START-LOCATION and END-LOCATION).")); | |
13377 | ||
765dc015 | 13378 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
13379 | |
13380 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 13381 | } |