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 | |
51be5b68 | 179 | static void enable_breakpoint_disp (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 | ||
c906108c | 2018 | int |
fba45db2 | 2019 | reattach_breakpoints (int pid) |
c906108c | 2020 | { |
6c95b8df | 2021 | struct cleanup *old_chain; |
35df4500 | 2022 | struct bp_location *bl, **blp_tmp; |
c906108c | 2023 | int val; |
86b887df | 2024 | struct ui_file *tmp_error_stream; |
fa3a767f | 2025 | int dummy1 = 0, dummy2 = 0; |
6c95b8df PA |
2026 | struct inferior *inf; |
2027 | struct thread_info *tp; | |
2028 | ||
2029 | tp = any_live_thread_of_process (pid); | |
2030 | if (tp == NULL) | |
2031 | return 1; | |
2032 | ||
2033 | inf = find_inferior_pid (pid); | |
2034 | old_chain = save_inferior_ptid (); | |
2035 | ||
2036 | inferior_ptid = tp->ptid; | |
a4954f26 | 2037 | |
86b887df | 2038 | tmp_error_stream = mem_fileopen (); |
a4954f26 | 2039 | make_cleanup_ui_file_delete (tmp_error_stream); |
c906108c | 2040 | |
35df4500 | 2041 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2042 | { |
35df4500 | 2043 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2044 | continue; |
2045 | ||
35df4500 | 2046 | if (bl->inserted) |
c5aa993b | 2047 | { |
35df4500 TJB |
2048 | bl->inserted = 0; |
2049 | val = insert_bp_location (bl, tmp_error_stream, &dummy1, &dummy2); | |
c5aa993b JM |
2050 | if (val != 0) |
2051 | { | |
ce696e05 | 2052 | do_cleanups (old_chain); |
c5aa993b JM |
2053 | return val; |
2054 | } | |
2055 | } | |
2056 | } | |
ce696e05 | 2057 | do_cleanups (old_chain); |
c906108c SS |
2058 | return 0; |
2059 | } | |
2060 | ||
e58b0e63 PA |
2061 | static int internal_breakpoint_number = -1; |
2062 | ||
84f4c1fe PM |
2063 | /* Set the breakpoint number of B, depending on the value of INTERNAL. |
2064 | If INTERNAL is non-zero, the breakpoint number will be populated | |
2065 | from internal_breakpoint_number and that variable decremented. | |
2066 | Otherwis the breakpoint number will be populated from | |
2067 | breakpoint_count and that value incremented. Internal breakpoints | |
2068 | do not set the internal var bpnum. */ | |
2069 | static void | |
2070 | set_breakpoint_number (int internal, struct breakpoint *b) | |
2071 | { | |
2072 | if (internal) | |
2073 | b->number = internal_breakpoint_number--; | |
2074 | else | |
2075 | { | |
2076 | set_breakpoint_count (breakpoint_count + 1); | |
2077 | b->number = breakpoint_count; | |
2078 | } | |
2079 | } | |
2080 | ||
e62c965a | 2081 | static struct breakpoint * |
a6d9a66e UW |
2082 | create_internal_breakpoint (struct gdbarch *gdbarch, |
2083 | CORE_ADDR address, enum bptype type) | |
e62c965a | 2084 | { |
e62c965a PP |
2085 | struct symtab_and_line sal; |
2086 | struct breakpoint *b; | |
2087 | ||
4a64f543 | 2088 | init_sal (&sal); /* Initialize to zeroes. */ |
e62c965a PP |
2089 | |
2090 | sal.pc = address; | |
2091 | sal.section = find_pc_overlay (sal.pc); | |
6c95b8df | 2092 | sal.pspace = current_program_space; |
e62c965a | 2093 | |
a6d9a66e | 2094 | b = set_raw_breakpoint (gdbarch, sal, type); |
e62c965a PP |
2095 | b->number = internal_breakpoint_number--; |
2096 | b->disposition = disp_donttouch; | |
2097 | ||
2098 | return b; | |
2099 | } | |
2100 | ||
17450429 PP |
2101 | static const char *const longjmp_names[] = |
2102 | { | |
2103 | "longjmp", "_longjmp", "siglongjmp", "_siglongjmp" | |
2104 | }; | |
2105 | #define NUM_LONGJMP_NAMES ARRAY_SIZE(longjmp_names) | |
2106 | ||
2107 | /* Per-objfile data private to breakpoint.c. */ | |
2108 | struct breakpoint_objfile_data | |
2109 | { | |
2110 | /* Minimal symbol for "_ovly_debug_event" (if any). */ | |
2111 | struct minimal_symbol *overlay_msym; | |
2112 | ||
2113 | /* Minimal symbol(s) for "longjmp", "siglongjmp", etc. (if any). */ | |
2114 | struct minimal_symbol *longjmp_msym[NUM_LONGJMP_NAMES]; | |
2115 | ||
2116 | /* Minimal symbol for "std::terminate()" (if any). */ | |
2117 | struct minimal_symbol *terminate_msym; | |
2118 | ||
2119 | /* Minimal symbol for "_Unwind_DebugHook" (if any). */ | |
2120 | struct minimal_symbol *exception_msym; | |
2121 | }; | |
2122 | ||
2123 | static const struct objfile_data *breakpoint_objfile_key; | |
2124 | ||
2125 | /* Minimal symbol not found sentinel. */ | |
2126 | static struct minimal_symbol msym_not_found; | |
2127 | ||
2128 | /* Returns TRUE if MSYM point to the "not found" sentinel. */ | |
2129 | ||
2130 | static int | |
2131 | msym_not_found_p (const struct minimal_symbol *msym) | |
2132 | { | |
2133 | return msym == &msym_not_found; | |
2134 | } | |
2135 | ||
2136 | /* Return per-objfile data needed by breakpoint.c. | |
2137 | Allocate the data if necessary. */ | |
2138 | ||
2139 | static struct breakpoint_objfile_data * | |
2140 | get_breakpoint_objfile_data (struct objfile *objfile) | |
2141 | { | |
2142 | struct breakpoint_objfile_data *bp_objfile_data; | |
2143 | ||
2144 | bp_objfile_data = objfile_data (objfile, breakpoint_objfile_key); | |
2145 | if (bp_objfile_data == NULL) | |
2146 | { | |
2147 | bp_objfile_data = obstack_alloc (&objfile->objfile_obstack, | |
2148 | sizeof (*bp_objfile_data)); | |
2149 | ||
2150 | memset (bp_objfile_data, 0, sizeof (*bp_objfile_data)); | |
2151 | set_objfile_data (objfile, breakpoint_objfile_key, bp_objfile_data); | |
2152 | } | |
2153 | return bp_objfile_data; | |
2154 | } | |
2155 | ||
e62c965a | 2156 | static void |
af02033e | 2157 | create_overlay_event_breakpoint (void) |
e62c965a | 2158 | { |
69de3c6a | 2159 | struct objfile *objfile; |
af02033e | 2160 | const char *const func_name = "_ovly_debug_event"; |
e62c965a | 2161 | |
69de3c6a PP |
2162 | ALL_OBJFILES (objfile) |
2163 | { | |
2164 | struct breakpoint *b; | |
17450429 PP |
2165 | struct breakpoint_objfile_data *bp_objfile_data; |
2166 | CORE_ADDR addr; | |
69de3c6a | 2167 | |
17450429 PP |
2168 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2169 | ||
2170 | if (msym_not_found_p (bp_objfile_data->overlay_msym)) | |
2171 | continue; | |
2172 | ||
2173 | if (bp_objfile_data->overlay_msym == NULL) | |
2174 | { | |
2175 | struct minimal_symbol *m; | |
2176 | ||
2177 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2178 | if (m == NULL) | |
2179 | { | |
2180 | /* Avoid future lookups in this objfile. */ | |
2181 | bp_objfile_data->overlay_msym = &msym_not_found; | |
2182 | continue; | |
2183 | } | |
2184 | bp_objfile_data->overlay_msym = m; | |
2185 | } | |
e62c965a | 2186 | |
17450429 PP |
2187 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->overlay_msym); |
2188 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
69de3c6a PP |
2189 | bp_overlay_event); |
2190 | b->addr_string = xstrdup (func_name); | |
e62c965a | 2191 | |
69de3c6a PP |
2192 | if (overlay_debugging == ovly_auto) |
2193 | { | |
2194 | b->enable_state = bp_enabled; | |
2195 | overlay_events_enabled = 1; | |
2196 | } | |
2197 | else | |
2198 | { | |
2199 | b->enable_state = bp_disabled; | |
2200 | overlay_events_enabled = 0; | |
2201 | } | |
e62c965a PP |
2202 | } |
2203 | update_global_location_list (1); | |
2204 | } | |
2205 | ||
0fd8e87f | 2206 | static void |
af02033e | 2207 | create_longjmp_master_breakpoint (void) |
0fd8e87f | 2208 | { |
6c95b8df | 2209 | struct program_space *pspace; |
6c95b8df PA |
2210 | struct cleanup *old_chain; |
2211 | ||
2212 | old_chain = save_current_program_space (); | |
0fd8e87f | 2213 | |
6c95b8df | 2214 | ALL_PSPACES (pspace) |
af02033e PP |
2215 | { |
2216 | struct objfile *objfile; | |
2217 | ||
2218 | set_current_program_space (pspace); | |
2219 | ||
2220 | ALL_OBJFILES (objfile) | |
0fd8e87f | 2221 | { |
af02033e PP |
2222 | int i; |
2223 | struct gdbarch *gdbarch; | |
17450429 | 2224 | struct breakpoint_objfile_data *bp_objfile_data; |
0fd8e87f | 2225 | |
af02033e PP |
2226 | gdbarch = get_objfile_arch (objfile); |
2227 | if (!gdbarch_get_longjmp_target_p (gdbarch)) | |
0fd8e87f UW |
2228 | continue; |
2229 | ||
17450429 PP |
2230 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
2231 | ||
2232 | for (i = 0; i < NUM_LONGJMP_NAMES; i++) | |
af02033e PP |
2233 | { |
2234 | struct breakpoint *b; | |
af02033e | 2235 | const char *func_name; |
17450429 | 2236 | CORE_ADDR addr; |
6c95b8df | 2237 | |
17450429 | 2238 | if (msym_not_found_p (bp_objfile_data->longjmp_msym[i])) |
af02033e | 2239 | continue; |
0fd8e87f | 2240 | |
17450429 PP |
2241 | func_name = longjmp_names[i]; |
2242 | if (bp_objfile_data->longjmp_msym[i] == NULL) | |
2243 | { | |
2244 | struct minimal_symbol *m; | |
2245 | ||
2246 | m = lookup_minimal_symbol_text (func_name, objfile); | |
2247 | if (m == NULL) | |
2248 | { | |
2249 | /* Prevent future lookups in this objfile. */ | |
2250 | bp_objfile_data->longjmp_msym[i] = &msym_not_found; | |
2251 | continue; | |
2252 | } | |
2253 | bp_objfile_data->longjmp_msym[i] = m; | |
2254 | } | |
2255 | ||
2256 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->longjmp_msym[i]); | |
2257 | b = create_internal_breakpoint (gdbarch, addr, bp_longjmp_master); | |
af02033e PP |
2258 | b->addr_string = xstrdup (func_name); |
2259 | b->enable_state = bp_disabled; | |
2260 | } | |
0fd8e87f | 2261 | } |
af02033e | 2262 | } |
0fd8e87f | 2263 | update_global_location_list (1); |
6c95b8df PA |
2264 | |
2265 | do_cleanups (old_chain); | |
0fd8e87f UW |
2266 | } |
2267 | ||
af02033e | 2268 | /* Create a master std::terminate breakpoint. */ |
aa7d318d | 2269 | static void |
af02033e | 2270 | create_std_terminate_master_breakpoint (void) |
aa7d318d TT |
2271 | { |
2272 | struct program_space *pspace; | |
aa7d318d | 2273 | struct cleanup *old_chain; |
af02033e | 2274 | const char *const func_name = "std::terminate()"; |
aa7d318d TT |
2275 | |
2276 | old_chain = save_current_program_space (); | |
2277 | ||
2278 | ALL_PSPACES (pspace) | |
17450429 PP |
2279 | { |
2280 | struct objfile *objfile; | |
2281 | CORE_ADDR addr; | |
2282 | ||
2283 | set_current_program_space (pspace); | |
2284 | ||
aa7d318d TT |
2285 | ALL_OBJFILES (objfile) |
2286 | { | |
2287 | struct breakpoint *b; | |
17450429 | 2288 | struct breakpoint_objfile_data *bp_objfile_data; |
aa7d318d | 2289 | |
17450429 | 2290 | bp_objfile_data = get_breakpoint_objfile_data (objfile); |
aa7d318d | 2291 | |
17450429 PP |
2292 | if (msym_not_found_p (bp_objfile_data->terminate_msym)) |
2293 | continue; | |
2294 | ||
2295 | if (bp_objfile_data->terminate_msym == NULL) | |
2296 | { | |
2297 | struct minimal_symbol *m; | |
2298 | ||
2299 | m = lookup_minimal_symbol (func_name, NULL, objfile); | |
2300 | if (m == NULL || (MSYMBOL_TYPE (m) != mst_text | |
2301 | && MSYMBOL_TYPE (m) != mst_file_text)) | |
2302 | { | |
2303 | /* Prevent future lookups in this objfile. */ | |
2304 | bp_objfile_data->terminate_msym = &msym_not_found; | |
2305 | continue; | |
2306 | } | |
2307 | bp_objfile_data->terminate_msym = m; | |
2308 | } | |
aa7d318d | 2309 | |
17450429 PP |
2310 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->terminate_msym); |
2311 | b = create_internal_breakpoint (get_objfile_arch (objfile), addr, | |
aa7d318d TT |
2312 | bp_std_terminate_master); |
2313 | b->addr_string = xstrdup (func_name); | |
2314 | b->enable_state = bp_disabled; | |
2315 | } | |
17450429 PP |
2316 | } |
2317 | ||
aa7d318d TT |
2318 | update_global_location_list (1); |
2319 | ||
2320 | do_cleanups (old_chain); | |
2321 | } | |
2322 | ||
186c406b TT |
2323 | /* Install a master breakpoint on the unwinder's debug hook. */ |
2324 | ||
2325 | void | |
2326 | create_exception_master_breakpoint (void) | |
2327 | { | |
2328 | struct objfile *objfile; | |
17450429 | 2329 | const char *const func_name = "_Unwind_DebugHook"; |
186c406b TT |
2330 | |
2331 | ALL_OBJFILES (objfile) | |
2332 | { | |
17450429 PP |
2333 | struct breakpoint *b; |
2334 | struct gdbarch *gdbarch; | |
2335 | struct breakpoint_objfile_data *bp_objfile_data; | |
2336 | CORE_ADDR addr; | |
2337 | ||
2338 | bp_objfile_data = get_breakpoint_objfile_data (objfile); | |
2339 | ||
2340 | if (msym_not_found_p (bp_objfile_data->exception_msym)) | |
2341 | continue; | |
2342 | ||
2343 | gdbarch = get_objfile_arch (objfile); | |
186c406b | 2344 | |
17450429 | 2345 | if (bp_objfile_data->exception_msym == NULL) |
186c406b | 2346 | { |
17450429 | 2347 | struct minimal_symbol *debug_hook; |
186c406b | 2348 | |
17450429 PP |
2349 | debug_hook = lookup_minimal_symbol (func_name, NULL, objfile); |
2350 | if (debug_hook == NULL) | |
2351 | { | |
2352 | bp_objfile_data->exception_msym = &msym_not_found; | |
2353 | continue; | |
2354 | } | |
2355 | ||
2356 | bp_objfile_data->exception_msym = debug_hook; | |
186c406b | 2357 | } |
17450429 PP |
2358 | |
2359 | addr = SYMBOL_VALUE_ADDRESS (bp_objfile_data->exception_msym); | |
2360 | addr = gdbarch_convert_from_func_ptr_addr (gdbarch, addr, | |
2361 | ¤t_target); | |
2362 | b = create_internal_breakpoint (gdbarch, addr, bp_exception_master); | |
2363 | b->addr_string = xstrdup (func_name); | |
2364 | b->enable_state = bp_disabled; | |
186c406b TT |
2365 | } |
2366 | ||
2367 | update_global_location_list (1); | |
2368 | } | |
2369 | ||
c906108c | 2370 | void |
fba45db2 | 2371 | update_breakpoints_after_exec (void) |
c906108c | 2372 | { |
35df4500 | 2373 | struct breakpoint *b, *b_tmp; |
876fa593 | 2374 | struct bp_location *bploc, **bplocp_tmp; |
c906108c | 2375 | |
25b22b0a PA |
2376 | /* We're about to delete breakpoints from GDB's lists. If the |
2377 | INSERTED flag is true, GDB will try to lift the breakpoints by | |
2378 | writing the breakpoints' "shadow contents" back into memory. The | |
2379 | "shadow contents" are NOT valid after an exec, so GDB should not | |
2380 | do that. Instead, the target is responsible from marking | |
2381 | breakpoints out as soon as it detects an exec. We don't do that | |
2382 | here instead, because there may be other attempts to delete | |
2383 | breakpoints after detecting an exec and before reaching here. */ | |
876fa593 | 2384 | ALL_BP_LOCATIONS (bploc, bplocp_tmp) |
6c95b8df PA |
2385 | if (bploc->pspace == current_program_space) |
2386 | gdb_assert (!bploc->inserted); | |
c906108c | 2387 | |
35df4500 | 2388 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2389 | { |
6c95b8df PA |
2390 | if (b->pspace != current_program_space) |
2391 | continue; | |
2392 | ||
4a64f543 | 2393 | /* Solib breakpoints must be explicitly reset after an exec(). */ |
c5aa993b JM |
2394 | if (b->type == bp_shlib_event) |
2395 | { | |
2396 | delete_breakpoint (b); | |
2397 | continue; | |
2398 | } | |
c906108c | 2399 | |
4a64f543 | 2400 | /* JIT breakpoints must be explicitly reset after an exec(). */ |
4efc6507 DE |
2401 | if (b->type == bp_jit_event) |
2402 | { | |
2403 | delete_breakpoint (b); | |
2404 | continue; | |
2405 | } | |
2406 | ||
1900040c | 2407 | /* Thread event breakpoints must be set anew after an exec(), |
0fd8e87f UW |
2408 | as must overlay event and longjmp master breakpoints. */ |
2409 | if (b->type == bp_thread_event || b->type == bp_overlay_event | |
186c406b TT |
2410 | || b->type == bp_longjmp_master || b->type == bp_std_terminate_master |
2411 | || b->type == bp_exception_master) | |
c4093a6a JM |
2412 | { |
2413 | delete_breakpoint (b); | |
2414 | continue; | |
2415 | } | |
2416 | ||
4a64f543 | 2417 | /* Step-resume breakpoints are meaningless after an exec(). */ |
2c03e5be | 2418 | if (b->type == bp_step_resume || b->type == bp_hp_step_resume) |
c5aa993b JM |
2419 | { |
2420 | delete_breakpoint (b); | |
2421 | continue; | |
2422 | } | |
2423 | ||
611c83ae PA |
2424 | /* Longjmp and longjmp-resume breakpoints are also meaningless |
2425 | after an exec. */ | |
186c406b TT |
2426 | if (b->type == bp_longjmp || b->type == bp_longjmp_resume |
2427 | || b->type == bp_exception || b->type == bp_exception_resume) | |
611c83ae PA |
2428 | { |
2429 | delete_breakpoint (b); | |
2430 | continue; | |
2431 | } | |
2432 | ||
ce78b96d JB |
2433 | if (b->type == bp_catchpoint) |
2434 | { | |
2435 | /* For now, none of the bp_catchpoint breakpoints need to | |
2436 | do anything at this point. In the future, if some of | |
2437 | the catchpoints need to something, we will need to add | |
2438 | a new method, and call this method from here. */ | |
2439 | continue; | |
2440 | } | |
2441 | ||
c5aa993b JM |
2442 | /* bp_finish is a special case. The only way we ought to be able |
2443 | to see one of these when an exec() has happened, is if the user | |
2444 | caught a vfork, and then said "finish". Ordinarily a finish just | |
2445 | carries them to the call-site of the current callee, by setting | |
2446 | a temporary bp there and resuming. But in this case, the finish | |
2447 | will carry them entirely through the vfork & exec. | |
2448 | ||
2449 | We don't want to allow a bp_finish to remain inserted now. But | |
2450 | we can't safely delete it, 'cause finish_command has a handle to | |
2451 | the bp on a bpstat, and will later want to delete it. There's a | |
2452 | chance (and I've seen it happen) that if we delete the bp_finish | |
2453 | here, that its storage will get reused by the time finish_command | |
2454 | gets 'round to deleting the "use to be a bp_finish" breakpoint. | |
2455 | We really must allow finish_command to delete a bp_finish. | |
2456 | ||
53a5351d JM |
2457 | In the absense of a general solution for the "how do we know |
2458 | it's safe to delete something others may have handles to?" | |
2459 | problem, what we'll do here is just uninsert the bp_finish, and | |
2460 | let finish_command delete it. | |
2461 | ||
2462 | (We know the bp_finish is "doomed" in the sense that it's | |
2463 | momentary, and will be deleted as soon as finish_command sees | |
2464 | the inferior stopped. So it doesn't matter that the bp's | |
2465 | address is probably bogus in the new a.out, unlike e.g., the | |
2466 | solib breakpoints.) */ | |
c5aa993b | 2467 | |
c5aa993b JM |
2468 | if (b->type == bp_finish) |
2469 | { | |
2470 | continue; | |
2471 | } | |
2472 | ||
2473 | /* Without a symbolic address, we have little hope of the | |
2474 | pre-exec() address meaning the same thing in the post-exec() | |
4a64f543 | 2475 | a.out. */ |
c5aa993b JM |
2476 | if (b->addr_string == NULL) |
2477 | { | |
2478 | delete_breakpoint (b); | |
2479 | continue; | |
2480 | } | |
c5aa993b | 2481 | } |
1900040c | 2482 | /* FIXME what about longjmp breakpoints? Re-create them here? */ |
af02033e PP |
2483 | create_overlay_event_breakpoint (); |
2484 | create_longjmp_master_breakpoint (); | |
2485 | create_std_terminate_master_breakpoint (); | |
186c406b | 2486 | create_exception_master_breakpoint (); |
c906108c SS |
2487 | } |
2488 | ||
2489 | int | |
fba45db2 | 2490 | detach_breakpoints (int pid) |
c906108c | 2491 | { |
35df4500 | 2492 | struct bp_location *bl, **blp_tmp; |
3a1bae8e | 2493 | int val = 0; |
ce696e05 | 2494 | struct cleanup *old_chain = save_inferior_ptid (); |
6c95b8df | 2495 | struct inferior *inf = current_inferior (); |
c5aa993b | 2496 | |
39f77062 | 2497 | if (pid == PIDGET (inferior_ptid)) |
8a3fe4f8 | 2498 | error (_("Cannot detach breakpoints of inferior_ptid")); |
c5aa993b | 2499 | |
6c95b8df | 2500 | /* Set inferior_ptid; remove_breakpoint_1 uses this global. */ |
ce696e05 | 2501 | inferior_ptid = pid_to_ptid (pid); |
35df4500 | 2502 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2503 | { |
35df4500 | 2504 | if (bl->pspace != inf->pspace) |
6c95b8df PA |
2505 | continue; |
2506 | ||
35df4500 TJB |
2507 | if (bl->inserted) |
2508 | val |= remove_breakpoint_1 (bl, mark_inserted); | |
c5aa993b | 2509 | } |
d03285ec UW |
2510 | |
2511 | /* Detach single-step breakpoints as well. */ | |
2512 | detach_single_step_breakpoints (); | |
2513 | ||
ce696e05 | 2514 | do_cleanups (old_chain); |
3a1bae8e | 2515 | return val; |
c906108c SS |
2516 | } |
2517 | ||
35df4500 | 2518 | /* Remove the breakpoint location BL from the current address space. |
6c95b8df PA |
2519 | Note that this is used to detach breakpoints from a child fork. |
2520 | When we get here, the child isn't in the inferior list, and neither | |
2521 | do we have objects to represent its address space --- we should | |
35df4500 | 2522 | *not* look at bl->pspace->aspace here. */ |
6c95b8df | 2523 | |
c906108c | 2524 | static int |
35df4500 | 2525 | remove_breakpoint_1 (struct bp_location *bl, insertion_state_t is) |
c906108c SS |
2526 | { |
2527 | int val; | |
c5aa993b | 2528 | |
35df4500 TJB |
2529 | /* BL is never in moribund_locations by our callers. */ |
2530 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2531 | |
35df4500 | 2532 | if (bl->owner->enable_state == bp_permanent) |
c2c6d25f JM |
2533 | /* Permanent breakpoints cannot be inserted or removed. */ |
2534 | return 0; | |
2535 | ||
74960c60 VP |
2536 | /* The type of none suggests that owner is actually deleted. |
2537 | This should not ever happen. */ | |
35df4500 | 2538 | gdb_assert (bl->owner->type != bp_none); |
0bde7532 | 2539 | |
35df4500 TJB |
2540 | if (bl->loc_type == bp_loc_software_breakpoint |
2541 | || bl->loc_type == bp_loc_hardware_breakpoint) | |
c906108c | 2542 | { |
c02f5703 MS |
2543 | /* "Normal" instruction breakpoint: either the standard |
2544 | trap-instruction bp (bp_breakpoint), or a | |
2545 | bp_hardware_breakpoint. */ | |
2546 | ||
2547 | /* First check to see if we have to handle an overlay. */ | |
2548 | if (overlay_debugging == ovly_off | |
35df4500 TJB |
2549 | || bl->section == NULL |
2550 | || !(section_is_overlay (bl->section))) | |
c02f5703 MS |
2551 | { |
2552 | /* No overlay handling: just remove the breakpoint. */ | |
2553 | ||
35df4500 TJB |
2554 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2555 | val = target_remove_hw_breakpoint (bl->gdbarch, &bl->target_info); | |
c02f5703 | 2556 | else |
35df4500 | 2557 | val = target_remove_breakpoint (bl->gdbarch, &bl->target_info); |
c02f5703 | 2558 | } |
c906108c SS |
2559 | else |
2560 | { | |
4a64f543 | 2561 | /* This breakpoint is in an overlay section. |
c02f5703 MS |
2562 | Did we set a breakpoint at the LMA? */ |
2563 | if (!overlay_events_enabled) | |
2564 | { | |
2565 | /* Yes -- overlay event support is not active, so we | |
2566 | should have set a breakpoint at the LMA. Remove it. | |
2567 | */ | |
c02f5703 MS |
2568 | /* Ignore any failures: if the LMA is in ROM, we will |
2569 | have already warned when we failed to insert it. */ | |
35df4500 TJB |
2570 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2571 | target_remove_hw_breakpoint (bl->gdbarch, | |
2572 | &bl->overlay_target_info); | |
c02f5703 | 2573 | else |
35df4500 TJB |
2574 | target_remove_breakpoint (bl->gdbarch, |
2575 | &bl->overlay_target_info); | |
c02f5703 MS |
2576 | } |
2577 | /* Did we set a breakpoint at the VMA? | |
2578 | If so, we will have marked the breakpoint 'inserted'. */ | |
35df4500 | 2579 | if (bl->inserted) |
c906108c | 2580 | { |
c02f5703 MS |
2581 | /* Yes -- remove it. Previously we did not bother to |
2582 | remove the breakpoint if the section had been | |
2583 | unmapped, but let's not rely on that being safe. We | |
2584 | don't know what the overlay manager might do. */ | |
35df4500 TJB |
2585 | if (bl->loc_type == bp_loc_hardware_breakpoint) |
2586 | val = target_remove_hw_breakpoint (bl->gdbarch, | |
2587 | &bl->target_info); | |
aa67235e UW |
2588 | |
2589 | /* However, we should remove *software* breakpoints only | |
2590 | if the section is still mapped, or else we overwrite | |
2591 | wrong code with the saved shadow contents. */ | |
35df4500 TJB |
2592 | else if (section_is_mapped (bl->section)) |
2593 | val = target_remove_breakpoint (bl->gdbarch, | |
2594 | &bl->target_info); | |
aa67235e UW |
2595 | else |
2596 | val = 0; | |
c906108c | 2597 | } |
c02f5703 MS |
2598 | else |
2599 | { | |
2600 | /* No -- not inserted, so no need to remove. No error. */ | |
2601 | val = 0; | |
2602 | } | |
c906108c | 2603 | } |
879d1e6b UW |
2604 | |
2605 | /* In some cases, we might not be able to remove a breakpoint | |
2606 | in a shared library that has already been removed, but we | |
2607 | have not yet processed the shlib unload event. */ | |
35df4500 | 2608 | if (val && solib_name_from_address (bl->pspace, bl->address)) |
879d1e6b UW |
2609 | val = 0; |
2610 | ||
c906108c SS |
2611 | if (val) |
2612 | return val; | |
35df4500 | 2613 | bl->inserted = (is == mark_inserted); |
c906108c | 2614 | } |
35df4500 | 2615 | else if (bl->loc_type == bp_loc_hardware_watchpoint) |
c906108c | 2616 | { |
77b06cd7 TJB |
2617 | gdb_assert (bl->owner->ops != NULL |
2618 | && bl->owner->ops->remove_location != NULL); | |
2619 | ||
35df4500 | 2620 | bl->inserted = (is == mark_inserted); |
77b06cd7 | 2621 | bl->owner->ops->remove_location (bl); |
2e70b7b9 | 2622 | |
c906108c | 2623 | /* Failure to remove any of the hardware watchpoints comes here. */ |
35df4500 | 2624 | if ((is == mark_uninserted) && (bl->inserted)) |
8a3fe4f8 | 2625 | warning (_("Could not remove hardware watchpoint %d."), |
35df4500 | 2626 | bl->owner->number); |
c906108c | 2627 | } |
35df4500 TJB |
2628 | else if (bl->owner->type == bp_catchpoint |
2629 | && breakpoint_enabled (bl->owner) | |
2630 | && !bl->duplicate) | |
ce78b96d | 2631 | { |
77b06cd7 TJB |
2632 | gdb_assert (bl->owner->ops != NULL |
2633 | && bl->owner->ops->remove_location != NULL); | |
ce78b96d | 2634 | |
77b06cd7 | 2635 | val = bl->owner->ops->remove_location (bl); |
ce78b96d JB |
2636 | if (val) |
2637 | return val; | |
77b06cd7 | 2638 | |
35df4500 | 2639 | bl->inserted = (is == mark_inserted); |
ce78b96d | 2640 | } |
c906108c SS |
2641 | |
2642 | return 0; | |
2643 | } | |
2644 | ||
6c95b8df | 2645 | static int |
35df4500 | 2646 | remove_breakpoint (struct bp_location *bl, insertion_state_t is) |
6c95b8df PA |
2647 | { |
2648 | int ret; | |
2649 | struct cleanup *old_chain; | |
2650 | ||
35df4500 TJB |
2651 | /* BL is never in moribund_locations by our callers. */ |
2652 | gdb_assert (bl->owner != NULL); | |
2bdf28a0 | 2653 | |
35df4500 | 2654 | if (bl->owner->enable_state == bp_permanent) |
6c95b8df PA |
2655 | /* Permanent breakpoints cannot be inserted or removed. */ |
2656 | return 0; | |
2657 | ||
2658 | /* The type of none suggests that owner is actually deleted. | |
2659 | This should not ever happen. */ | |
35df4500 | 2660 | gdb_assert (bl->owner->type != bp_none); |
6c95b8df PA |
2661 | |
2662 | old_chain = save_current_space_and_thread (); | |
2663 | ||
35df4500 | 2664 | switch_to_program_space_and_thread (bl->pspace); |
6c95b8df | 2665 | |
35df4500 | 2666 | ret = remove_breakpoint_1 (bl, is); |
6c95b8df PA |
2667 | |
2668 | do_cleanups (old_chain); | |
2669 | return ret; | |
2670 | } | |
2671 | ||
c906108c SS |
2672 | /* Clear the "inserted" flag in all breakpoints. */ |
2673 | ||
25b22b0a | 2674 | void |
fba45db2 | 2675 | mark_breakpoints_out (void) |
c906108c | 2676 | { |
35df4500 | 2677 | struct bp_location *bl, **blp_tmp; |
c906108c | 2678 | |
35df4500 TJB |
2679 | ALL_BP_LOCATIONS (bl, blp_tmp) |
2680 | if (bl->pspace == current_program_space) | |
2681 | bl->inserted = 0; | |
c906108c SS |
2682 | } |
2683 | ||
53a5351d JM |
2684 | /* Clear the "inserted" flag in all breakpoints and delete any |
2685 | breakpoints which should go away between runs of the program. | |
c906108c SS |
2686 | |
2687 | Plus other such housekeeping that has to be done for breakpoints | |
2688 | between runs. | |
2689 | ||
53a5351d JM |
2690 | Note: this function gets called at the end of a run (by |
2691 | generic_mourn_inferior) and when a run begins (by | |
4a64f543 | 2692 | init_wait_for_inferior). */ |
c906108c SS |
2693 | |
2694 | ||
2695 | ||
2696 | void | |
fba45db2 | 2697 | breakpoint_init_inferior (enum inf_context context) |
c906108c | 2698 | { |
35df4500 TJB |
2699 | struct breakpoint *b, *b_tmp; |
2700 | struct bp_location *bl, **blp_tmp; | |
1c5cfe86 | 2701 | int ix; |
6c95b8df | 2702 | struct program_space *pspace = current_program_space; |
c906108c | 2703 | |
50c71eaf PA |
2704 | /* If breakpoint locations are shared across processes, then there's |
2705 | nothing to do. */ | |
2567c7d9 | 2706 | if (gdbarch_has_global_breakpoints (target_gdbarch)) |
50c71eaf PA |
2707 | return; |
2708 | ||
35df4500 | 2709 | ALL_BP_LOCATIONS (bl, blp_tmp) |
6c95b8df | 2710 | { |
35df4500 TJB |
2711 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
2712 | if (bl->pspace == pspace | |
2713 | && bl->owner->enable_state != bp_permanent) | |
2714 | bl->inserted = 0; | |
6c95b8df | 2715 | } |
075f6582 | 2716 | |
35df4500 | 2717 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 2718 | { |
6c95b8df PA |
2719 | if (b->loc && b->loc->pspace != pspace) |
2720 | continue; | |
2721 | ||
c5aa993b JM |
2722 | switch (b->type) |
2723 | { | |
2724 | case bp_call_dummy: | |
c906108c | 2725 | |
c5aa993b | 2726 | /* If the call dummy breakpoint is at the entry point it will |
ab92d69b PA |
2727 | cause problems when the inferior is rerun, so we better get |
2728 | rid of it. */ | |
2729 | ||
2730 | case bp_watchpoint_scope: | |
2731 | ||
2732 | /* Also get rid of scope breakpoints. */ | |
2733 | ||
2734 | case bp_shlib_event: | |
2735 | ||
2736 | /* Also remove solib event breakpoints. Their addresses may | |
2737 | have changed since the last time we ran the program. | |
2738 | Actually we may now be debugging against different target; | |
2739 | and so the solib backend that installed this breakpoint may | |
2740 | not be used in by the target. E.g., | |
2741 | ||
2742 | (gdb) file prog-linux | |
2743 | (gdb) run # native linux target | |
2744 | ... | |
2745 | (gdb) kill | |
2746 | (gdb) file prog-win.exe | |
2747 | (gdb) tar rem :9999 # remote Windows gdbserver. | |
2748 | */ | |
c906108c | 2749 | |
c5aa993b JM |
2750 | delete_breakpoint (b); |
2751 | break; | |
c906108c | 2752 | |
c5aa993b JM |
2753 | case bp_watchpoint: |
2754 | case bp_hardware_watchpoint: | |
2755 | case bp_read_watchpoint: | |
2756 | case bp_access_watchpoint: | |
c906108c | 2757 | |
c5aa993b JM |
2758 | /* Likewise for watchpoints on local expressions. */ |
2759 | if (b->exp_valid_block != NULL) | |
2760 | delete_breakpoint (b); | |
967af18d | 2761 | else if (context == inf_starting) |
c860120c | 2762 | { |
4a64f543 MS |
2763 | /* Reset val field to force reread of starting value in |
2764 | insert_breakpoints. */ | |
c860120c PM |
2765 | if (b->val) |
2766 | value_free (b->val); | |
2767 | b->val = NULL; | |
fa4727a6 | 2768 | b->val_valid = 0; |
c860120c | 2769 | } |
c5aa993b JM |
2770 | break; |
2771 | default: | |
c5aa993b JM |
2772 | break; |
2773 | } | |
2774 | } | |
1c5cfe86 PA |
2775 | |
2776 | /* Get rid of the moribund locations. */ | |
35df4500 TJB |
2777 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, bl); ++ix) |
2778 | decref_bp_location (&bl); | |
1c5cfe86 | 2779 | VEC_free (bp_location_p, moribund_locations); |
c906108c SS |
2780 | } |
2781 | ||
6c95b8df PA |
2782 | /* These functions concern about actual breakpoints inserted in the |
2783 | target --- to e.g. check if we need to do decr_pc adjustment or if | |
2784 | we need to hop over the bkpt --- so we check for address space | |
2785 | match, not program space. */ | |
2786 | ||
c2c6d25f JM |
2787 | /* breakpoint_here_p (PC) returns non-zero if an enabled breakpoint |
2788 | exists at PC. It returns ordinary_breakpoint_here if it's an | |
2789 | ordinary breakpoint, or permanent_breakpoint_here if it's a | |
2790 | permanent breakpoint. | |
2791 | - When continuing from a location with an ordinary breakpoint, we | |
2792 | actually single step once before calling insert_breakpoints. | |
2793 | - When continuing from a localion with a permanent breakpoint, we | |
2794 | need to use the `SKIP_PERMANENT_BREAKPOINT' macro, provided by | |
2795 | the target, to advance the PC past the breakpoint. */ | |
c906108c | 2796 | |
c2c6d25f | 2797 | enum breakpoint_here |
6c95b8df | 2798 | breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
c906108c | 2799 | { |
35df4500 | 2800 | struct bp_location *bl, **blp_tmp; |
c2c6d25f | 2801 | int any_breakpoint_here = 0; |
c906108c | 2802 | |
35df4500 | 2803 | ALL_BP_LOCATIONS (bl, blp_tmp) |
075f6582 | 2804 | { |
35df4500 TJB |
2805 | if (bl->loc_type != bp_loc_software_breakpoint |
2806 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2807 | continue; |
2808 | ||
f1310107 | 2809 | /* ALL_BP_LOCATIONS bp_location has BL->OWNER always non-NULL. */ |
35df4500 TJB |
2810 | if ((breakpoint_enabled (bl->owner) |
2811 | || bl->owner->enable_state == bp_permanent) | |
f1310107 | 2812 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2813 | { |
2814 | if (overlay_debugging | |
35df4500 TJB |
2815 | && section_is_overlay (bl->section) |
2816 | && !section_is_mapped (bl->section)) | |
075f6582 | 2817 | continue; /* unmapped overlay -- can't be a match */ |
35df4500 | 2818 | else if (bl->owner->enable_state == bp_permanent) |
075f6582 DJ |
2819 | return permanent_breakpoint_here; |
2820 | else | |
2821 | any_breakpoint_here = 1; | |
2822 | } | |
2823 | } | |
c906108c | 2824 | |
c2c6d25f | 2825 | return any_breakpoint_here ? ordinary_breakpoint_here : 0; |
c906108c SS |
2826 | } |
2827 | ||
1c5cfe86 PA |
2828 | /* Return true if there's a moribund breakpoint at PC. */ |
2829 | ||
2830 | int | |
6c95b8df | 2831 | moribund_breakpoint_here_p (struct address_space *aspace, CORE_ADDR pc) |
1c5cfe86 PA |
2832 | { |
2833 | struct bp_location *loc; | |
2834 | int ix; | |
2835 | ||
2836 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
f1310107 | 2837 | if (breakpoint_location_address_match (loc, aspace, pc)) |
1c5cfe86 PA |
2838 | return 1; |
2839 | ||
2840 | return 0; | |
2841 | } | |
c2c6d25f | 2842 | |
c36b740a | 2843 | /* Returns non-zero if there's a breakpoint inserted at PC, which is |
4a64f543 MS |
2844 | inserted using regular breakpoint_chain / bp_location array |
2845 | mechanism. This does not check for single-step breakpoints, which | |
2846 | are inserted and removed using direct target manipulation. */ | |
c906108c SS |
2847 | |
2848 | int | |
4a64f543 MS |
2849 | regular_breakpoint_inserted_here_p (struct address_space *aspace, |
2850 | CORE_ADDR pc) | |
c906108c | 2851 | { |
35df4500 | 2852 | struct bp_location *bl, **blp_tmp; |
c906108c | 2853 | |
35df4500 | 2854 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2855 | { |
35df4500 TJB |
2856 | if (bl->loc_type != bp_loc_software_breakpoint |
2857 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2858 | continue; |
2859 | ||
35df4500 | 2860 | if (bl->inserted |
f1310107 | 2861 | && breakpoint_location_address_match (bl, aspace, pc)) |
075f6582 DJ |
2862 | { |
2863 | if (overlay_debugging | |
35df4500 TJB |
2864 | && section_is_overlay (bl->section) |
2865 | && !section_is_mapped (bl->section)) | |
075f6582 DJ |
2866 | continue; /* unmapped overlay -- can't be a match */ |
2867 | else | |
2868 | return 1; | |
2869 | } | |
c5aa993b | 2870 | } |
c36b740a VP |
2871 | return 0; |
2872 | } | |
2873 | ||
2874 | /* Returns non-zero iff there's either regular breakpoint | |
2875 | or a single step breakpoint inserted at PC. */ | |
2876 | ||
2877 | int | |
6c95b8df | 2878 | breakpoint_inserted_here_p (struct address_space *aspace, CORE_ADDR pc) |
c36b740a | 2879 | { |
6c95b8df | 2880 | if (regular_breakpoint_inserted_here_p (aspace, pc)) |
c36b740a | 2881 | return 1; |
c906108c | 2882 | |
6c95b8df | 2883 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2884 | return 1; |
2885 | ||
c906108c SS |
2886 | return 0; |
2887 | } | |
2888 | ||
4fa8626c DJ |
2889 | /* This function returns non-zero iff there is a software breakpoint |
2890 | inserted at PC. */ | |
2891 | ||
2892 | int | |
3e43a32a MS |
2893 | software_breakpoint_inserted_here_p (struct address_space *aspace, |
2894 | CORE_ADDR pc) | |
4fa8626c | 2895 | { |
35df4500 | 2896 | struct bp_location *bl, **blp_tmp; |
4fa8626c | 2897 | |
35df4500 | 2898 | ALL_BP_LOCATIONS (bl, blp_tmp) |
4fa8626c | 2899 | { |
35df4500 | 2900 | if (bl->loc_type != bp_loc_software_breakpoint) |
4fa8626c DJ |
2901 | continue; |
2902 | ||
35df4500 TJB |
2903 | if (bl->inserted |
2904 | && breakpoint_address_match (bl->pspace->aspace, bl->address, | |
6c95b8df | 2905 | aspace, pc)) |
4fa8626c DJ |
2906 | { |
2907 | if (overlay_debugging | |
35df4500 TJB |
2908 | && section_is_overlay (bl->section) |
2909 | && !section_is_mapped (bl->section)) | |
4fa8626c DJ |
2910 | continue; /* unmapped overlay -- can't be a match */ |
2911 | else | |
2912 | return 1; | |
2913 | } | |
2914 | } | |
2915 | ||
1aafd4da | 2916 | /* Also check for software single-step breakpoints. */ |
6c95b8df | 2917 | if (single_step_breakpoint_inserted_here_p (aspace, pc)) |
1aafd4da UW |
2918 | return 1; |
2919 | ||
4fa8626c DJ |
2920 | return 0; |
2921 | } | |
2922 | ||
9093389c PA |
2923 | int |
2924 | hardware_watchpoint_inserted_in_range (struct address_space *aspace, | |
2925 | CORE_ADDR addr, ULONGEST len) | |
2926 | { | |
2927 | struct breakpoint *bpt; | |
2928 | ||
2929 | ALL_BREAKPOINTS (bpt) | |
2930 | { | |
2931 | struct bp_location *loc; | |
2932 | ||
2933 | if (bpt->type != bp_hardware_watchpoint | |
2934 | && bpt->type != bp_access_watchpoint) | |
2935 | continue; | |
2936 | ||
2937 | if (!breakpoint_enabled (bpt)) | |
2938 | continue; | |
2939 | ||
2940 | for (loc = bpt->loc; loc; loc = loc->next) | |
2941 | if (loc->pspace->aspace == aspace && loc->inserted) | |
2942 | { | |
2943 | CORE_ADDR l, h; | |
2944 | ||
2945 | /* Check for intersection. */ | |
2946 | l = max (loc->address, addr); | |
2947 | h = min (loc->address + loc->length, addr + len); | |
2948 | if (l < h) | |
2949 | return 1; | |
2950 | } | |
2951 | } | |
2952 | return 0; | |
2953 | } | |
2954 | ||
075f6582 DJ |
2955 | /* breakpoint_thread_match (PC, PTID) returns true if the breakpoint at |
2956 | PC is valid for process/thread PTID. */ | |
c906108c SS |
2957 | |
2958 | int | |
6c95b8df PA |
2959 | breakpoint_thread_match (struct address_space *aspace, CORE_ADDR pc, |
2960 | ptid_t ptid) | |
c906108c | 2961 | { |
35df4500 | 2962 | struct bp_location *bl, **blp_tmp; |
4a306c9a | 2963 | /* The thread and task IDs associated to PTID, computed lazily. */ |
a6f1cd96 | 2964 | int thread = -1; |
4a306c9a | 2965 | int task = 0; |
a6f1cd96 | 2966 | |
35df4500 | 2967 | ALL_BP_LOCATIONS (bl, blp_tmp) |
c5aa993b | 2968 | { |
35df4500 TJB |
2969 | if (bl->loc_type != bp_loc_software_breakpoint |
2970 | && bl->loc_type != bp_loc_hardware_breakpoint) | |
075f6582 DJ |
2971 | continue; |
2972 | ||
35df4500 TJB |
2973 | /* ALL_BP_LOCATIONS bp_location has bl->OWNER always non-NULL. */ |
2974 | if (!breakpoint_enabled (bl->owner) | |
2975 | && bl->owner->enable_state != bp_permanent) | |
a6f1cd96 JB |
2976 | continue; |
2977 | ||
f1310107 | 2978 | if (!breakpoint_location_address_match (bl, aspace, pc)) |
a6f1cd96 JB |
2979 | continue; |
2980 | ||
35df4500 | 2981 | if (bl->owner->thread != -1) |
075f6582 | 2982 | { |
a6f1cd96 JB |
2983 | /* This is a thread-specific breakpoint. Check that ptid |
2984 | matches that thread. If thread hasn't been computed yet, | |
2985 | it is now time to do so. */ | |
2986 | if (thread == -1) | |
2987 | thread = pid_to_thread_id (ptid); | |
35df4500 | 2988 | if (bl->owner->thread != thread) |
a6f1cd96 | 2989 | continue; |
075f6582 | 2990 | } |
a6f1cd96 | 2991 | |
35df4500 | 2992 | if (bl->owner->task != 0) |
4a306c9a JB |
2993 | { |
2994 | /* This is a task-specific breakpoint. Check that ptid | |
2995 | matches that task. If task hasn't been computed yet, | |
2996 | it is now time to do so. */ | |
2997 | if (task == 0) | |
2998 | task = ada_get_task_number (ptid); | |
35df4500 | 2999 | if (bl->owner->task != task) |
4a306c9a JB |
3000 | continue; |
3001 | } | |
3002 | ||
a6f1cd96 | 3003 | if (overlay_debugging |
35df4500 TJB |
3004 | && section_is_overlay (bl->section) |
3005 | && !section_is_mapped (bl->section)) | |
a6f1cd96 JB |
3006 | continue; /* unmapped overlay -- can't be a match */ |
3007 | ||
3008 | return 1; | |
c5aa993b | 3009 | } |
c906108c SS |
3010 | |
3011 | return 0; | |
3012 | } | |
c906108c | 3013 | \f |
c5aa993b | 3014 | |
c906108c SS |
3015 | /* bpstat stuff. External routines' interfaces are documented |
3016 | in breakpoint.h. */ | |
3017 | ||
3018 | int | |
fba45db2 | 3019 | ep_is_catchpoint (struct breakpoint *ep) |
c906108c | 3020 | { |
533be4dd | 3021 | return (ep->type == bp_catchpoint); |
c906108c SS |
3022 | } |
3023 | ||
f431efe5 PA |
3024 | /* Frees any storage that is part of a bpstat. Does not walk the |
3025 | 'next' chain. */ | |
3026 | ||
3027 | static void | |
198757a8 VP |
3028 | bpstat_free (bpstat bs) |
3029 | { | |
3030 | if (bs->old_val != NULL) | |
3031 | value_free (bs->old_val); | |
9add0f1b | 3032 | decref_counted_command_line (&bs->commands); |
f431efe5 | 3033 | decref_bp_location (&bs->bp_location_at); |
198757a8 VP |
3034 | xfree (bs); |
3035 | } | |
3036 | ||
c906108c SS |
3037 | /* Clear a bpstat so that it says we are not at any breakpoint. |
3038 | Also free any storage that is part of a bpstat. */ | |
3039 | ||
3040 | void | |
fba45db2 | 3041 | bpstat_clear (bpstat *bsp) |
c906108c SS |
3042 | { |
3043 | bpstat p; | |
3044 | bpstat q; | |
3045 | ||
3046 | if (bsp == 0) | |
3047 | return; | |
3048 | p = *bsp; | |
3049 | while (p != NULL) | |
3050 | { | |
3051 | q = p->next; | |
198757a8 | 3052 | bpstat_free (p); |
c906108c SS |
3053 | p = q; |
3054 | } | |
3055 | *bsp = NULL; | |
3056 | } | |
3057 | ||
3058 | /* Return a copy of a bpstat. Like "bs1 = bs2" but all storage that | |
3059 | is part of the bpstat is copied as well. */ | |
3060 | ||
3061 | bpstat | |
fba45db2 | 3062 | bpstat_copy (bpstat bs) |
c906108c SS |
3063 | { |
3064 | bpstat p = NULL; | |
3065 | bpstat tmp; | |
3066 | bpstat retval = NULL; | |
3067 | ||
3068 | if (bs == NULL) | |
3069 | return bs; | |
3070 | ||
3071 | for (; bs != NULL; bs = bs->next) | |
3072 | { | |
3073 | tmp = (bpstat) xmalloc (sizeof (*tmp)); | |
3074 | memcpy (tmp, bs, sizeof (*tmp)); | |
9add0f1b | 3075 | incref_counted_command_line (tmp->commands); |
f431efe5 | 3076 | incref_bp_location (tmp->bp_location_at); |
31cc81e9 | 3077 | if (bs->old_val != NULL) |
3c3185ac JK |
3078 | { |
3079 | tmp->old_val = value_copy (bs->old_val); | |
3080 | release_value (tmp->old_val); | |
3081 | } | |
31cc81e9 | 3082 | |
c906108c SS |
3083 | if (p == NULL) |
3084 | /* This is the first thing in the chain. */ | |
3085 | retval = tmp; | |
3086 | else | |
3087 | p->next = tmp; | |
3088 | p = tmp; | |
3089 | } | |
3090 | p->next = NULL; | |
3091 | return retval; | |
3092 | } | |
3093 | ||
4a64f543 | 3094 | /* Find the bpstat associated with this breakpoint. */ |
c906108c SS |
3095 | |
3096 | bpstat | |
fba45db2 | 3097 | bpstat_find_breakpoint (bpstat bsp, struct breakpoint *breakpoint) |
c906108c | 3098 | { |
c5aa993b JM |
3099 | if (bsp == NULL) |
3100 | return NULL; | |
c906108c | 3101 | |
c5aa993b JM |
3102 | for (; bsp != NULL; bsp = bsp->next) |
3103 | { | |
f431efe5 | 3104 | if (bsp->breakpoint_at == breakpoint) |
c5aa993b JM |
3105 | return bsp; |
3106 | } | |
c906108c SS |
3107 | return NULL; |
3108 | } | |
3109 | ||
4a64f543 MS |
3110 | /* Put in *NUM the breakpoint number of the first breakpoint we are |
3111 | stopped at. *BSP upon return is a bpstat which points to the | |
3112 | remaining breakpoints stopped at (but which is not guaranteed to be | |
3113 | good for anything but further calls to bpstat_num). | |
3114 | ||
8671a17b PA |
3115 | Return 0 if passed a bpstat which does not indicate any breakpoints. |
3116 | Return -1 if stopped at a breakpoint that has been deleted since | |
3117 | we set it. | |
3118 | Return 1 otherwise. */ | |
c906108c SS |
3119 | |
3120 | int | |
8671a17b | 3121 | bpstat_num (bpstat *bsp, int *num) |
c906108c SS |
3122 | { |
3123 | struct breakpoint *b; | |
3124 | ||
3125 | if ((*bsp) == NULL) | |
3126 | return 0; /* No more breakpoint values */ | |
8671a17b | 3127 | |
4a64f543 MS |
3128 | /* We assume we'll never have several bpstats that correspond to a |
3129 | single breakpoint -- otherwise, this function might return the | |
3130 | same number more than once and this will look ugly. */ | |
f431efe5 | 3131 | b = (*bsp)->breakpoint_at; |
8671a17b PA |
3132 | *bsp = (*bsp)->next; |
3133 | if (b == NULL) | |
3134 | return -1; /* breakpoint that's been deleted since */ | |
3135 | ||
3136 | *num = b->number; /* We have its number */ | |
3137 | return 1; | |
c906108c SS |
3138 | } |
3139 | ||
3140 | /* Modify BS so that the actions will not be performed. */ | |
3141 | ||
3142 | void | |
fba45db2 | 3143 | bpstat_clear_actions (bpstat bs) |
c906108c SS |
3144 | { |
3145 | for (; bs != NULL; bs = bs->next) | |
3146 | { | |
9add0f1b | 3147 | decref_counted_command_line (&bs->commands); |
dde2d684 | 3148 | bs->commands_left = NULL; |
c906108c SS |
3149 | if (bs->old_val != NULL) |
3150 | { | |
3151 | value_free (bs->old_val); | |
3152 | bs->old_val = NULL; | |
3153 | } | |
3154 | } | |
3155 | } | |
3156 | ||
f3b1572e PA |
3157 | /* Called when a command is about to proceed the inferior. */ |
3158 | ||
3159 | static void | |
3160 | breakpoint_about_to_proceed (void) | |
3161 | { | |
3162 | if (!ptid_equal (inferior_ptid, null_ptid)) | |
3163 | { | |
3164 | struct thread_info *tp = inferior_thread (); | |
3165 | ||
3166 | /* Allow inferior function calls in breakpoint commands to not | |
3167 | interrupt the command list. When the call finishes | |
3168 | successfully, the inferior will be standing at the same | |
3169 | breakpoint as if nothing happened. */ | |
16c381f0 | 3170 | if (tp->control.in_infcall) |
f3b1572e PA |
3171 | return; |
3172 | } | |
3173 | ||
3174 | breakpoint_proceeded = 1; | |
3175 | } | |
3176 | ||
4a64f543 MS |
3177 | /* Stub for cleaning up our state if we error-out of a breakpoint |
3178 | command. */ | |
c906108c | 3179 | static void |
4efb68b1 | 3180 | cleanup_executing_breakpoints (void *ignore) |
c906108c SS |
3181 | { |
3182 | executing_breakpoint_commands = 0; | |
3183 | } | |
3184 | ||
4a64f543 MS |
3185 | /* Execute all the commands associated with all the breakpoints at |
3186 | this location. Any of these commands could cause the process to | |
3187 | proceed beyond this point, etc. We look out for such changes by | |
3188 | checking the global "breakpoint_proceeded" after each command. | |
c906108c | 3189 | |
347bddb7 PA |
3190 | Returns true if a breakpoint command resumed the inferior. In that |
3191 | case, it is the caller's responsibility to recall it again with the | |
3192 | bpstat of the current thread. */ | |
3193 | ||
3194 | static int | |
3195 | bpstat_do_actions_1 (bpstat *bsp) | |
c906108c SS |
3196 | { |
3197 | bpstat bs; | |
3198 | struct cleanup *old_chain; | |
347bddb7 | 3199 | int again = 0; |
c906108c SS |
3200 | |
3201 | /* Avoid endless recursion if a `source' command is contained | |
3202 | in bs->commands. */ | |
3203 | if (executing_breakpoint_commands) | |
347bddb7 | 3204 | return 0; |
c906108c SS |
3205 | |
3206 | executing_breakpoint_commands = 1; | |
3207 | old_chain = make_cleanup (cleanup_executing_breakpoints, 0); | |
3208 | ||
cf6c5ffb TT |
3209 | prevent_dont_repeat (); |
3210 | ||
4a64f543 | 3211 | /* This pointer will iterate over the list of bpstat's. */ |
c906108c SS |
3212 | bs = *bsp; |
3213 | ||
3214 | breakpoint_proceeded = 0; | |
3215 | for (; bs != NULL; bs = bs->next) | |
3216 | { | |
9add0f1b | 3217 | struct counted_command_line *ccmd; |
6c50ab1c JB |
3218 | struct command_line *cmd; |
3219 | struct cleanup *this_cmd_tree_chain; | |
3220 | ||
3221 | /* Take ownership of the BSP's command tree, if it has one. | |
3222 | ||
3223 | The command tree could legitimately contain commands like | |
3224 | 'step' and 'next', which call clear_proceed_status, which | |
3225 | frees stop_bpstat's command tree. To make sure this doesn't | |
3226 | free the tree we're executing out from under us, we need to | |
3227 | take ownership of the tree ourselves. Since a given bpstat's | |
3228 | commands are only executed once, we don't need to copy it; we | |
3229 | can clear the pointer in the bpstat, and make sure we free | |
3230 | the tree when we're done. */ | |
9add0f1b TT |
3231 | ccmd = bs->commands; |
3232 | bs->commands = NULL; | |
3233 | this_cmd_tree_chain | |
3234 | = make_cleanup_decref_counted_command_line (&ccmd); | |
3235 | cmd = bs->commands_left; | |
3236 | bs->commands_left = NULL; | |
6c50ab1c | 3237 | |
c906108c SS |
3238 | while (cmd != NULL) |
3239 | { | |
3240 | execute_control_command (cmd); | |
3241 | ||
3242 | if (breakpoint_proceeded) | |
3243 | break; | |
3244 | else | |
3245 | cmd = cmd->next; | |
3246 | } | |
6c50ab1c JB |
3247 | |
3248 | /* We can free this command tree now. */ | |
3249 | do_cleanups (this_cmd_tree_chain); | |
3250 | ||
c906108c | 3251 | if (breakpoint_proceeded) |
32c1e744 VP |
3252 | { |
3253 | if (target_can_async_p ()) | |
347bddb7 PA |
3254 | /* If we are in async mode, then the target might be still |
3255 | running, not stopped at any breakpoint, so nothing for | |
3256 | us to do here -- just return to the event loop. */ | |
3257 | ; | |
32c1e744 VP |
3258 | else |
3259 | /* In sync mode, when execute_control_command returns | |
3260 | we're already standing on the next breakpoint. | |
347bddb7 PA |
3261 | Breakpoint commands for that stop were not run, since |
3262 | execute_command does not run breakpoint commands -- | |
3263 | only command_line_handler does, but that one is not | |
3264 | involved in execution of breakpoint commands. So, we | |
3265 | can now execute breakpoint commands. It should be | |
3266 | noted that making execute_command do bpstat actions is | |
3267 | not an option -- in this case we'll have recursive | |
3268 | invocation of bpstat for each breakpoint with a | |
3269 | command, and can easily blow up GDB stack. Instead, we | |
3270 | return true, which will trigger the caller to recall us | |
3271 | with the new stop_bpstat. */ | |
3272 | again = 1; | |
3273 | break; | |
32c1e744 | 3274 | } |
c906108c | 3275 | } |
c2b8ed2c | 3276 | do_cleanups (old_chain); |
347bddb7 PA |
3277 | return again; |
3278 | } | |
3279 | ||
3280 | void | |
3281 | bpstat_do_actions (void) | |
3282 | { | |
3283 | /* Do any commands attached to breakpoint we are stopped at. */ | |
3284 | while (!ptid_equal (inferior_ptid, null_ptid) | |
3285 | && target_has_execution | |
3286 | && !is_exited (inferior_ptid) | |
3287 | && !is_executing (inferior_ptid)) | |
3288 | /* Since in sync mode, bpstat_do_actions may resume the inferior, | |
3289 | and only return when it is stopped at the next breakpoint, we | |
3290 | keep doing breakpoint actions until it returns false to | |
3291 | indicate the inferior was not resumed. */ | |
16c381f0 | 3292 | if (!bpstat_do_actions_1 (&inferior_thread ()->control.stop_bpstat)) |
347bddb7 | 3293 | break; |
c906108c SS |
3294 | } |
3295 | ||
fa4727a6 DJ |
3296 | /* Print out the (old or new) value associated with a watchpoint. */ |
3297 | ||
3298 | static void | |
3299 | watchpoint_value_print (struct value *val, struct ui_file *stream) | |
3300 | { | |
3301 | if (val == NULL) | |
3302 | fprintf_unfiltered (stream, _("<unreadable>")); | |
3303 | else | |
79a45b7d TT |
3304 | { |
3305 | struct value_print_options opts; | |
3306 | get_user_print_options (&opts); | |
3307 | value_print (val, stream, &opts); | |
3308 | } | |
fa4727a6 DJ |
3309 | } |
3310 | ||
e514a9d6 | 3311 | /* This is the normal print function for a bpstat. In the future, |
c906108c | 3312 | much of this logic could (should?) be moved to bpstat_stop_status, |
e514a9d6 JM |
3313 | by having it set different print_it values. |
3314 | ||
3315 | Current scheme: When we stop, bpstat_print() is called. It loops | |
3316 | through the bpstat list of things causing this stop, calling the | |
4a64f543 | 3317 | print_bp_stop_message function on each one. The behavior of the |
e514a9d6 | 3318 | print_bp_stop_message function depends on the print_it field of |
4a64f543 | 3319 | bpstat. If such field so indicates, call this function here. |
e514a9d6 JM |
3320 | |
3321 | Return values from this routine (ultimately used by bpstat_print() | |
3322 | and normal_stop() to decide what to do): | |
3323 | PRINT_NOTHING: Means we already printed all we needed to print, | |
3324 | don't print anything else. | |
3325 | PRINT_SRC_ONLY: Means we printed something, and we do *not* desire | |
3326 | that something to be followed by a location. | |
3327 | PRINT_SCR_AND_LOC: Means we printed something, and we *do* desire | |
3328 | that something to be followed by a location. | |
3329 | PRINT_UNKNOWN: Means we printed nothing or we need to do some more | |
3330 | analysis. */ | |
c906108c | 3331 | |
917317f4 | 3332 | static enum print_stop_action |
fba45db2 | 3333 | print_it_typical (bpstat bs) |
c906108c | 3334 | { |
f7545552 | 3335 | struct cleanup *old_chain; |
4f8d1dc6 | 3336 | struct breakpoint *b; |
89f9893c | 3337 | const struct bp_location *bl; |
8b93c638 | 3338 | struct ui_stream *stb; |
f7545552 TT |
3339 | int bp_temp = 0; |
3340 | enum print_stop_action result; | |
3341 | ||
f431efe5 PA |
3342 | gdb_assert (bs->bp_location_at != NULL); |
3343 | ||
3344 | bl = bs->bp_location_at; | |
3345 | b = bs->breakpoint_at; | |
c906108c | 3346 | |
f7545552 TT |
3347 | stb = ui_out_stream_new (uiout); |
3348 | old_chain = make_cleanup_ui_out_stream_delete (stb); | |
3349 | ||
4f8d1dc6 | 3350 | switch (b->type) |
c906108c | 3351 | { |
e514a9d6 JM |
3352 | case bp_breakpoint: |
3353 | case bp_hardware_breakpoint: | |
f431efe5 | 3354 | bp_temp = b->disposition == disp_del; |
0d381245 VP |
3355 | if (bl->address != bl->requested_address) |
3356 | breakpoint_adjustment_warning (bl->requested_address, | |
3357 | bl->address, | |
4f8d1dc6 VP |
3358 | b->number, 1); |
3359 | annotate_breakpoint (b->number); | |
2cec12e5 AR |
3360 | if (bp_temp) |
3361 | ui_out_text (uiout, "\nTemporary breakpoint "); | |
3362 | else | |
3363 | ui_out_text (uiout, "\nBreakpoint "); | |
9dc5e2a9 | 3364 | if (ui_out_is_mi_like_p (uiout)) |
2cec12e5 AR |
3365 | { |
3366 | ui_out_field_string (uiout, "reason", | |
3367 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
3368 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
3369 | } | |
4f8d1dc6 | 3370 | ui_out_field_int (uiout, "bkptno", b->number); |
8b93c638 | 3371 | ui_out_text (uiout, ", "); |
f7545552 | 3372 | result = PRINT_SRC_AND_LOC; |
e514a9d6 JM |
3373 | break; |
3374 | ||
3375 | case bp_shlib_event: | |
917317f4 JM |
3376 | /* Did we stop because the user set the stop_on_solib_events |
3377 | variable? (If so, we report this as a generic, "Stopped due | |
3378 | to shlib event" message.) */ | |
a3f17187 | 3379 | printf_filtered (_("Stopped due to shared library event\n")); |
f7545552 | 3380 | result = PRINT_NOTHING; |
e514a9d6 JM |
3381 | break; |
3382 | ||
c4093a6a | 3383 | case bp_thread_event: |
4a64f543 | 3384 | /* Not sure how we will get here. |
c4093a6a | 3385 | GDB should not stop for these breakpoints. */ |
a3f17187 | 3386 | printf_filtered (_("Thread Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3387 | result = PRINT_NOTHING; |
c4093a6a JM |
3388 | break; |
3389 | ||
1900040c | 3390 | case bp_overlay_event: |
4a64f543 | 3391 | /* By analogy with the thread event, GDB should not stop for these. */ |
a3f17187 | 3392 | printf_filtered (_("Overlay Event Breakpoint: gdb should not stop!\n")); |
f7545552 | 3393 | result = PRINT_NOTHING; |
1900040c MS |
3394 | break; |
3395 | ||
0fd8e87f UW |
3396 | case bp_longjmp_master: |
3397 | /* These should never be enabled. */ | |
3398 | printf_filtered (_("Longjmp Master Breakpoint: gdb should not stop!\n")); | |
3399 | result = PRINT_NOTHING; | |
3400 | break; | |
3401 | ||
aa7d318d TT |
3402 | case bp_std_terminate_master: |
3403 | /* These should never be enabled. */ | |
3e43a32a MS |
3404 | printf_filtered (_("std::terminate Master Breakpoint: " |
3405 | "gdb should not stop!\n")); | |
aa7d318d TT |
3406 | result = PRINT_NOTHING; |
3407 | break; | |
3408 | ||
186c406b TT |
3409 | case bp_exception_master: |
3410 | /* These should never be enabled. */ | |
3e43a32a MS |
3411 | printf_filtered (_("Exception Master Breakpoint: " |
3412 | "gdb should not stop!\n")); | |
186c406b TT |
3413 | result = PRINT_NOTHING; |
3414 | break; | |
3415 | ||
e514a9d6 JM |
3416 | case bp_watchpoint: |
3417 | case bp_hardware_watchpoint: | |
fa4727a6 DJ |
3418 | annotate_watchpoint (b->number); |
3419 | if (ui_out_is_mi_like_p (uiout)) | |
3420 | ui_out_field_string | |
3421 | (uiout, "reason", | |
3422 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
3423 | mention (b); | |
f7545552 | 3424 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
fa4727a6 DJ |
3425 | ui_out_text (uiout, "\nOld value = "); |
3426 | watchpoint_value_print (bs->old_val, stb->stream); | |
3427 | ui_out_field_stream (uiout, "old", stb); | |
3428 | ui_out_text (uiout, "\nNew value = "); | |
3429 | watchpoint_value_print (b->val, stb->stream); | |
3430 | ui_out_field_stream (uiout, "new", stb); | |
fa4727a6 | 3431 | ui_out_text (uiout, "\n"); |
e514a9d6 | 3432 | /* More than one watchpoint may have been triggered. */ |
f7545552 | 3433 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3434 | break; |
3435 | ||
3436 | case bp_read_watchpoint: | |
9dc5e2a9 | 3437 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3438 | ui_out_field_string |
3439 | (uiout, "reason", | |
3440 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3441 | mention (b); |
f7545552 | 3442 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3443 | ui_out_text (uiout, "\nValue = "); |
fa4727a6 | 3444 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3445 | ui_out_field_stream (uiout, "value", stb); |
8b93c638 | 3446 | ui_out_text (uiout, "\n"); |
f7545552 | 3447 | result = PRINT_UNKNOWN; |
e514a9d6 JM |
3448 | break; |
3449 | ||
3450 | case bp_access_watchpoint: | |
fa4727a6 | 3451 | if (bs->old_val != NULL) |
8b93c638 | 3452 | { |
4f8d1dc6 | 3453 | annotate_watchpoint (b->number); |
9dc5e2a9 | 3454 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3455 | ui_out_field_string |
3456 | (uiout, "reason", | |
3457 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
4f8d1dc6 | 3458 | mention (b); |
f7545552 | 3459 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 | 3460 | ui_out_text (uiout, "\nOld value = "); |
fa4727a6 | 3461 | watchpoint_value_print (bs->old_val, stb->stream); |
8b93c638 | 3462 | ui_out_field_stream (uiout, "old", stb); |
8b93c638 JM |
3463 | ui_out_text (uiout, "\nNew value = "); |
3464 | } | |
3465 | else | |
3466 | { | |
4f8d1dc6 | 3467 | mention (b); |
9dc5e2a9 | 3468 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3469 | ui_out_field_string |
3470 | (uiout, "reason", | |
3471 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
f7545552 | 3472 | make_cleanup_ui_out_tuple_begin_end (uiout, "value"); |
8b93c638 JM |
3473 | ui_out_text (uiout, "\nValue = "); |
3474 | } | |
fa4727a6 | 3475 | watchpoint_value_print (b->val, stb->stream); |
8b93c638 | 3476 | ui_out_field_stream (uiout, "new", stb); |
8b93c638 | 3477 | ui_out_text (uiout, "\n"); |
f7545552 | 3478 | result = PRINT_UNKNOWN; |
e514a9d6 | 3479 | break; |
4ce44c66 | 3480 | |
e514a9d6 | 3481 | /* Fall through, we don't deal with these types of breakpoints |
4a64f543 | 3482 | here. */ |
e514a9d6 | 3483 | |
11cf8741 | 3484 | case bp_finish: |
9dc5e2a9 | 3485 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3486 | ui_out_field_string |
3487 | (uiout, "reason", | |
3488 | async_reason_lookup (EXEC_ASYNC_FUNCTION_FINISHED)); | |
f7545552 | 3489 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3490 | break; |
3491 | ||
e514a9d6 | 3492 | case bp_until: |
9dc5e2a9 | 3493 | if (ui_out_is_mi_like_p (uiout)) |
1fbc2a49 NR |
3494 | ui_out_field_string |
3495 | (uiout, "reason", | |
3496 | async_reason_lookup (EXEC_ASYNC_LOCATION_REACHED)); | |
f7545552 | 3497 | result = PRINT_UNKNOWN; |
8b93c638 JM |
3498 | break; |
3499 | ||
c2d11a7d | 3500 | case bp_none: |
e514a9d6 JM |
3501 | case bp_longjmp: |
3502 | case bp_longjmp_resume: | |
186c406b TT |
3503 | case bp_exception: |
3504 | case bp_exception_resume: | |
e514a9d6 | 3505 | case bp_step_resume: |
2c03e5be | 3506 | case bp_hp_step_resume: |
e514a9d6 JM |
3507 | case bp_watchpoint_scope: |
3508 | case bp_call_dummy: | |
aa7d318d | 3509 | case bp_std_terminate: |
1042e4c0 | 3510 | case bp_tracepoint: |
7a697b8d | 3511 | case bp_fast_tracepoint: |
4efc6507 | 3512 | case bp_jit_event: |
0e30163f JK |
3513 | case bp_gnu_ifunc_resolver: |
3514 | case bp_gnu_ifunc_resolver_return: | |
e514a9d6 | 3515 | default: |
f7545552 TT |
3516 | result = PRINT_UNKNOWN; |
3517 | break; | |
e514a9d6 | 3518 | } |
f7545552 TT |
3519 | |
3520 | do_cleanups (old_chain); | |
3521 | return result; | |
e514a9d6 JM |
3522 | } |
3523 | ||
3524 | /* Generic routine for printing messages indicating why we | |
4a64f543 | 3525 | stopped. The behavior of this function depends on the value |
e514a9d6 JM |
3526 | 'print_it' in the bpstat structure. Under some circumstances we |
3527 | may decide not to print anything here and delegate the task to | |
4a64f543 | 3528 | normal_stop(). */ |
e514a9d6 JM |
3529 | |
3530 | static enum print_stop_action | |
3531 | print_bp_stop_message (bpstat bs) | |
3532 | { | |
3533 | switch (bs->print_it) | |
3534 | { | |
3535 | case print_it_noop: | |
4a64f543 | 3536 | /* Nothing should be printed for this bpstat entry. */ |
e514a9d6 JM |
3537 | return PRINT_UNKNOWN; |
3538 | break; | |
3539 | ||
3540 | case print_it_done: | |
3541 | /* We still want to print the frame, but we already printed the | |
4a64f543 | 3542 | relevant messages. */ |
e514a9d6 JM |
3543 | return PRINT_SRC_AND_LOC; |
3544 | break; | |
3545 | ||
3546 | case print_it_normal: | |
4f8d1dc6 | 3547 | { |
f431efe5 PA |
3548 | struct breakpoint *b = bs->breakpoint_at; |
3549 | ||
1a6a67de TJB |
3550 | /* bs->breakpoint_at can be NULL if it was a momentary breakpoint |
3551 | which has since been deleted. */ | |
3552 | if (b == NULL) | |
3553 | return PRINT_UNKNOWN; | |
3554 | ||
4f8d1dc6 VP |
3555 | /* Normal case. Call the breakpoint's print_it method, or |
3556 | print_it_typical. */ | |
1a6a67de | 3557 | if (b->ops != NULL && b->ops->print_it != NULL) |
4f8d1dc6 VP |
3558 | return b->ops->print_it (b); |
3559 | else | |
3560 | return print_it_typical (bs); | |
3561 | } | |
3562 | break; | |
3086aeae | 3563 | |
e514a9d6 | 3564 | default: |
8e65ff28 | 3565 | internal_error (__FILE__, __LINE__, |
e2e0b3e5 | 3566 | _("print_bp_stop_message: unrecognized enum value")); |
e514a9d6 | 3567 | break; |
c906108c | 3568 | } |
c906108c SS |
3569 | } |
3570 | ||
e514a9d6 JM |
3571 | /* Print a message indicating what happened. This is called from |
3572 | normal_stop(). The input to this routine is the head of the bpstat | |
3573 | list - a list of the eventpoints that caused this stop. This | |
3574 | routine calls the generic print routine for printing a message | |
3575 | about reasons for stopping. This will print (for example) the | |
3576 | "Breakpoint n," part of the output. The return value of this | |
3577 | routine is one of: | |
c906108c | 3578 | |
4a64f543 | 3579 | PRINT_UNKNOWN: Means we printed nothing. |
917317f4 | 3580 | PRINT_SRC_AND_LOC: Means we printed something, and expect subsequent |
4a64f543 | 3581 | code to print the location. An example is |
c5aa993b JM |
3582 | "Breakpoint 1, " which should be followed by |
3583 | the location. | |
917317f4 | 3584 | PRINT_SRC_ONLY: Means we printed something, but there is no need |
c5aa993b JM |
3585 | to also print the location part of the message. |
3586 | An example is the catch/throw messages, which | |
4a64f543 | 3587 | don't require a location appended to the end. |
917317f4 | 3588 | PRINT_NOTHING: We have done some printing and we don't need any |
4a64f543 | 3589 | further info to be printed. */ |
c906108c | 3590 | |
917317f4 | 3591 | enum print_stop_action |
fba45db2 | 3592 | bpstat_print (bpstat bs) |
c906108c SS |
3593 | { |
3594 | int val; | |
c5aa993b | 3595 | |
c906108c | 3596 | /* Maybe another breakpoint in the chain caused us to stop. |
53a5351d JM |
3597 | (Currently all watchpoints go on the bpstat whether hit or not. |
3598 | That probably could (should) be changed, provided care is taken | |
c906108c | 3599 | with respect to bpstat_explains_signal). */ |
e514a9d6 JM |
3600 | for (; bs; bs = bs->next) |
3601 | { | |
3602 | val = print_bp_stop_message (bs); | |
3603 | if (val == PRINT_SRC_ONLY | |
3604 | || val == PRINT_SRC_AND_LOC | |
3605 | || val == PRINT_NOTHING) | |
3606 | return val; | |
3607 | } | |
c906108c | 3608 | |
e514a9d6 | 3609 | /* We reached the end of the chain, or we got a null BS to start |
4a64f543 | 3610 | with and nothing was printed. */ |
917317f4 | 3611 | return PRINT_UNKNOWN; |
c906108c SS |
3612 | } |
3613 | ||
4a64f543 MS |
3614 | /* Evaluate the expression EXP and return 1 if value is zero. This is |
3615 | used inside a catch_errors to evaluate the breakpoint condition. | |
3616 | The argument is a "struct expression *" that has been cast to a | |
3617 | "char *" to make it pass through catch_errors. */ | |
c906108c SS |
3618 | |
3619 | static int | |
4efb68b1 | 3620 | breakpoint_cond_eval (void *exp) |
c906108c | 3621 | { |
278cd55f | 3622 | struct value *mark = value_mark (); |
c5aa993b | 3623 | int i = !value_true (evaluate_expression ((struct expression *) exp)); |
cc59ec59 | 3624 | |
c906108c SS |
3625 | value_free_to_mark (mark); |
3626 | return i; | |
3627 | } | |
3628 | ||
5760d0ab | 3629 | /* Allocate a new bpstat. Link it to the FIFO list by BS_LINK_POINTER. */ |
c906108c SS |
3630 | |
3631 | static bpstat | |
5760d0ab | 3632 | bpstat_alloc (struct bp_location *bl, bpstat **bs_link_pointer) |
c906108c SS |
3633 | { |
3634 | bpstat bs; | |
3635 | ||
3636 | bs = (bpstat) xmalloc (sizeof (*bs)); | |
5760d0ab JK |
3637 | bs->next = NULL; |
3638 | **bs_link_pointer = bs; | |
3639 | *bs_link_pointer = &bs->next; | |
f431efe5 PA |
3640 | bs->breakpoint_at = bl->owner; |
3641 | bs->bp_location_at = bl; | |
3642 | incref_bp_location (bl); | |
c906108c SS |
3643 | /* If the condition is false, etc., don't do the commands. */ |
3644 | bs->commands = NULL; | |
9add0f1b | 3645 | bs->commands_left = NULL; |
c906108c SS |
3646 | bs->old_val = NULL; |
3647 | bs->print_it = print_it_normal; | |
3648 | return bs; | |
3649 | } | |
3650 | \f | |
d983da9c DJ |
3651 | /* The target has stopped with waitstatus WS. Check if any hardware |
3652 | watchpoints have triggered, according to the target. */ | |
3653 | ||
3654 | int | |
3655 | watchpoints_triggered (struct target_waitstatus *ws) | |
3656 | { | |
d92524f1 | 3657 | int stopped_by_watchpoint = target_stopped_by_watchpoint (); |
d983da9c DJ |
3658 | CORE_ADDR addr; |
3659 | struct breakpoint *b; | |
3660 | ||
3661 | if (!stopped_by_watchpoint) | |
3662 | { | |
3663 | /* We were not stopped by a watchpoint. Mark all watchpoints | |
3664 | as not triggered. */ | |
3665 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3666 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3667 | b->watchpoint_triggered = watch_triggered_no; |
3668 | ||
3669 | return 0; | |
3670 | } | |
3671 | ||
3672 | if (!target_stopped_data_address (¤t_target, &addr)) | |
3673 | { | |
3674 | /* We were stopped by a watchpoint, but we don't know where. | |
3675 | Mark all watchpoints as unknown. */ | |
3676 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3677 | if (is_hardware_watchpoint (b)) |
d983da9c DJ |
3678 | b->watchpoint_triggered = watch_triggered_unknown; |
3679 | ||
3680 | return stopped_by_watchpoint; | |
3681 | } | |
3682 | ||
3683 | /* The target could report the data address. Mark watchpoints | |
3684 | affected by this data address as triggered, and all others as not | |
3685 | triggered. */ | |
3686 | ||
3687 | ALL_BREAKPOINTS (b) | |
cc60f2e3 | 3688 | if (is_hardware_watchpoint (b)) |
d983da9c | 3689 | { |
a5606eee | 3690 | struct bp_location *loc; |
d983da9c DJ |
3691 | |
3692 | b->watchpoint_triggered = watch_triggered_no; | |
a5606eee | 3693 | for (loc = b->loc; loc; loc = loc->next) |
9c06b0b4 TJB |
3694 | { |
3695 | if (is_masked_watchpoint (loc->owner)) | |
3696 | { | |
3697 | CORE_ADDR newaddr = addr & loc->owner->hw_wp_mask; | |
3698 | CORE_ADDR start = loc->address & loc->owner->hw_wp_mask; | |
3699 | ||
3700 | if (newaddr == start) | |
3701 | { | |
3702 | b->watchpoint_triggered = watch_triggered_yes; | |
3703 | break; | |
3704 | } | |
3705 | } | |
3706 | /* Exact match not required. Within range is sufficient. */ | |
3707 | else if (target_watchpoint_addr_within_range (¤t_target, | |
3708 | addr, loc->address, | |
3709 | loc->length)) | |
3710 | { | |
3711 | b->watchpoint_triggered = watch_triggered_yes; | |
3712 | break; | |
3713 | } | |
3714 | } | |
d983da9c DJ |
3715 | } |
3716 | ||
3717 | return 1; | |
3718 | } | |
3719 | ||
c906108c SS |
3720 | /* Possible return values for watchpoint_check (this can't be an enum |
3721 | because of check_errors). */ | |
3722 | /* The watchpoint has been deleted. */ | |
3723 | #define WP_DELETED 1 | |
3724 | /* The value has changed. */ | |
3725 | #define WP_VALUE_CHANGED 2 | |
3726 | /* The value has not changed. */ | |
3727 | #define WP_VALUE_NOT_CHANGED 3 | |
60e1c644 PA |
3728 | /* Ignore this watchpoint, no matter if the value changed or not. */ |
3729 | #define WP_IGNORE 4 | |
c906108c SS |
3730 | |
3731 | #define BP_TEMPFLAG 1 | |
3732 | #define BP_HARDWAREFLAG 2 | |
3733 | ||
4a64f543 MS |
3734 | /* Evaluate watchpoint condition expression and check if its value |
3735 | changed. | |
553e4c11 JB |
3736 | |
3737 | P should be a pointer to struct bpstat, but is defined as a void * | |
3738 | in order for this function to be usable with catch_errors. */ | |
c906108c SS |
3739 | |
3740 | static int | |
4efb68b1 | 3741 | watchpoint_check (void *p) |
c906108c SS |
3742 | { |
3743 | bpstat bs = (bpstat) p; | |
3744 | struct breakpoint *b; | |
3745 | struct frame_info *fr; | |
3746 | int within_current_scope; | |
3747 | ||
f431efe5 | 3748 | /* BS is built from an existing struct breakpoint. */ |
2bdf28a0 | 3749 | gdb_assert (bs->breakpoint_at != NULL); |
f431efe5 | 3750 | b = bs->breakpoint_at; |
c906108c | 3751 | |
d0fb5eae JK |
3752 | gdb_assert (is_watchpoint (b)); |
3753 | ||
f6bc2008 PA |
3754 | /* If this is a local watchpoint, we only want to check if the |
3755 | watchpoint frame is in scope if the current thread is the thread | |
3756 | that was used to create the watchpoint. */ | |
3757 | if (!watchpoint_in_thread_scope (b)) | |
60e1c644 | 3758 | return WP_IGNORE; |
f6bc2008 | 3759 | |
c906108c SS |
3760 | if (b->exp_valid_block == NULL) |
3761 | within_current_scope = 1; | |
3762 | else | |
3763 | { | |
edb3359d DJ |
3764 | struct frame_info *frame = get_current_frame (); |
3765 | struct gdbarch *frame_arch = get_frame_arch (frame); | |
3766 | CORE_ADDR frame_pc = get_frame_pc (frame); | |
3767 | ||
4a64f543 MS |
3768 | /* in_function_epilogue_p() returns a non-zero value if we're |
3769 | still in the function but the stack frame has already been | |
3770 | invalidated. Since we can't rely on the values of local | |
3771 | variables after the stack has been destroyed, we are treating | |
3772 | the watchpoint in that state as `not changed' without further | |
3773 | checking. Don't mark watchpoints as changed if the current | |
3774 | frame is in an epilogue - even if they are in some other | |
3775 | frame, our view of the stack is likely to be wrong and | |
3776 | frame_find_by_id could error out. */ | |
a0f49112 | 3777 | if (gdbarch_in_function_epilogue_p (frame_arch, frame_pc)) |
60e1c644 | 3778 | return WP_IGNORE; |
a0f49112 | 3779 | |
101dcfbe | 3780 | fr = frame_find_by_id (b->watchpoint_frame); |
c906108c | 3781 | within_current_scope = (fr != NULL); |
69fbadd5 DJ |
3782 | |
3783 | /* If we've gotten confused in the unwinder, we might have | |
3784 | returned a frame that can't describe this variable. */ | |
edb3359d DJ |
3785 | if (within_current_scope) |
3786 | { | |
3787 | struct symbol *function; | |
3788 | ||
3789 | function = get_frame_function (fr); | |
3790 | if (function == NULL | |
3791 | || !contained_in (b->exp_valid_block, | |
3792 | SYMBOL_BLOCK_VALUE (function))) | |
3793 | within_current_scope = 0; | |
3794 | } | |
69fbadd5 | 3795 | |
edb3359d | 3796 | if (within_current_scope) |
c906108c SS |
3797 | /* If we end up stopping, the current frame will get selected |
3798 | in normal_stop. So this call to select_frame won't affect | |
3799 | the user. */ | |
0f7d239c | 3800 | select_frame (fr); |
c906108c | 3801 | } |
c5aa993b | 3802 | |
c906108c SS |
3803 | if (within_current_scope) |
3804 | { | |
4a64f543 MS |
3805 | /* We use value_{,free_to_}mark because it could be a *long* |
3806 | time before we return to the command level and call | |
3807 | free_all_values. We can't call free_all_values because we | |
3808 | might be in the middle of evaluating a function call. */ | |
c906108c | 3809 | |
0cf6dd15 | 3810 | int pc = 0; |
9c06b0b4 | 3811 | struct value *mark; |
fa4727a6 DJ |
3812 | struct value *new_val; |
3813 | ||
9c06b0b4 TJB |
3814 | if (is_masked_watchpoint (b)) |
3815 | /* Since we don't know the exact trigger address (from | |
3816 | stopped_data_address), just tell the user we've triggered | |
3817 | a mask watchpoint. */ | |
3818 | return WP_VALUE_CHANGED; | |
3819 | ||
3820 | mark = value_mark (); | |
0cf6dd15 | 3821 | fetch_subexp_value (b->exp, &pc, &new_val, NULL, NULL); |
218d2fc6 | 3822 | |
4a64f543 MS |
3823 | /* We use value_equal_contents instead of value_equal because |
3824 | the latter coerces an array to a pointer, thus comparing just | |
3825 | the address of the array instead of its contents. This is | |
3826 | not what we want. */ | |
fa4727a6 | 3827 | if ((b->val != NULL) != (new_val != NULL) |
218d2fc6 | 3828 | || (b->val != NULL && !value_equal_contents (b->val, new_val))) |
c906108c | 3829 | { |
fa4727a6 DJ |
3830 | if (new_val != NULL) |
3831 | { | |
3832 | release_value (new_val); | |
3833 | value_free_to_mark (mark); | |
3834 | } | |
c906108c SS |
3835 | bs->old_val = b->val; |
3836 | b->val = new_val; | |
fa4727a6 | 3837 | b->val_valid = 1; |
c906108c SS |
3838 | return WP_VALUE_CHANGED; |
3839 | } | |
3840 | else | |
3841 | { | |
60e1c644 | 3842 | /* Nothing changed. */ |
c906108c | 3843 | value_free_to_mark (mark); |
c906108c SS |
3844 | return WP_VALUE_NOT_CHANGED; |
3845 | } | |
3846 | } | |
3847 | else | |
3848 | { | |
3849 | /* This seems like the only logical thing to do because | |
c5aa993b JM |
3850 | if we temporarily ignored the watchpoint, then when |
3851 | we reenter the block in which it is valid it contains | |
3852 | garbage (in the case of a function, it may have two | |
3853 | garbage values, one before and one after the prologue). | |
3854 | So we can't even detect the first assignment to it and | |
3855 | watch after that (since the garbage may or may not equal | |
3856 | the first value assigned). */ | |
4ce44c66 JM |
3857 | /* We print all the stop information in print_it_typical(), but |
3858 | in this case, by the time we call print_it_typical() this bp | |
4a64f543 MS |
3859 | will be deleted already. So we have no choice but print the |
3860 | information here. */ | |
9dc5e2a9 | 3861 | if (ui_out_is_mi_like_p (uiout)) |
034dad6f BR |
3862 | ui_out_field_string |
3863 | (uiout, "reason", async_reason_lookup (EXEC_ASYNC_WATCHPOINT_SCOPE)); | |
8b93c638 | 3864 | ui_out_text (uiout, "\nWatchpoint "); |
4f8d1dc6 | 3865 | ui_out_field_int (uiout, "wpnum", b->number); |
3e43a32a MS |
3866 | ui_out_text (uiout, |
3867 | " deleted because the program has left the block in\n\ | |
8b93c638 | 3868 | which its expression is valid.\n"); |
4ce44c66 | 3869 | |
cdac0397 PA |
3870 | /* Make sure the watchpoint's commands aren't executed. */ |
3871 | decref_counted_command_line (&b->commands); | |
d0fb5eae | 3872 | watchpoint_del_at_next_stop (b); |
c906108c SS |
3873 | |
3874 | return WP_DELETED; | |
3875 | } | |
3876 | } | |
3877 | ||
18a18393 VP |
3878 | /* Return true if it looks like target has stopped due to hitting |
3879 | breakpoint location BL. This function does not check if we | |
3880 | should stop, only if BL explains the stop. */ | |
3881 | static int | |
6c95b8df PA |
3882 | bpstat_check_location (const struct bp_location *bl, |
3883 | struct address_space *aspace, CORE_ADDR bp_addr) | |
18a18393 VP |
3884 | { |
3885 | struct breakpoint *b = bl->owner; | |
3886 | ||
2bdf28a0 JK |
3887 | /* BL is from existing struct breakpoint. */ |
3888 | gdb_assert (b != NULL); | |
3889 | ||
f1310107 TJB |
3890 | if (b->ops && b->ops->breakpoint_hit) |
3891 | return b->ops->breakpoint_hit (bl, aspace, bp_addr); | |
3892 | ||
e8595ef6 SS |
3893 | /* By definition, the inferior does not report stops at |
3894 | tracepoints. */ | |
d77f58be | 3895 | if (is_tracepoint (b)) |
e8595ef6 SS |
3896 | return 0; |
3897 | ||
cc60f2e3 | 3898 | if (!is_watchpoint (b) |
18a18393 | 3899 | && b->type != bp_hardware_breakpoint |
fe798b75 | 3900 | && b->type != bp_catchpoint) /* a non-watchpoint bp */ |
18a18393 | 3901 | { |
6c95b8df PA |
3902 | if (!breakpoint_address_match (bl->pspace->aspace, bl->address, |
3903 | aspace, bp_addr)) | |
18a18393 VP |
3904 | return 0; |
3905 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3906 | && section_is_overlay (bl->section) |
18a18393 VP |
3907 | && !section_is_mapped (bl->section)) |
3908 | return 0; | |
3909 | } | |
cc60f2e3 | 3910 | |
18a18393 VP |
3911 | /* Continuable hardware watchpoints are treated as non-existent if the |
3912 | reason we stopped wasn't a hardware watchpoint (we didn't stop on | |
3913 | some data address). Otherwise gdb won't stop on a break instruction | |
3914 | in the code (not from a breakpoint) when a hardware watchpoint has | |
3915 | been defined. Also skip watchpoints which we know did not trigger | |
3916 | (did not match the data address). */ | |
cc60f2e3 PA |
3917 | |
3918 | if (is_hardware_watchpoint (b) | |
18a18393 VP |
3919 | && b->watchpoint_triggered == watch_triggered_no) |
3920 | return 0; | |
f1310107 | 3921 | |
18a18393 VP |
3922 | if (b->type == bp_hardware_breakpoint) |
3923 | { | |
3924 | if (bl->address != bp_addr) | |
3925 | return 0; | |
3926 | if (overlay_debugging /* unmapped overlay section */ | |
35df4500 | 3927 | && section_is_overlay (bl->section) |
18a18393 VP |
3928 | && !section_is_mapped (bl->section)) |
3929 | return 0; | |
3930 | } | |
ce78b96d | 3931 | |
18a18393 VP |
3932 | return 1; |
3933 | } | |
3934 | ||
3935 | /* If BS refers to a watchpoint, determine if the watched values | |
3936 | has actually changed, and we should stop. If not, set BS->stop | |
3937 | to 0. */ | |
3938 | static void | |
3939 | bpstat_check_watchpoint (bpstat bs) | |
3940 | { | |
2bdf28a0 JK |
3941 | const struct bp_location *bl; |
3942 | struct breakpoint *b; | |
3943 | ||
3944 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 3945 | bl = bs->bp_location_at; |
2bdf28a0 | 3946 | gdb_assert (bl != NULL); |
f431efe5 | 3947 | b = bs->breakpoint_at; |
2bdf28a0 | 3948 | gdb_assert (b != NULL); |
18a18393 | 3949 | |
cc60f2e3 | 3950 | if (is_watchpoint (b)) |
18a18393 | 3951 | { |
18a18393 VP |
3952 | int must_check_value = 0; |
3953 | ||
3954 | if (b->type == bp_watchpoint) | |
3955 | /* For a software watchpoint, we must always check the | |
3956 | watched value. */ | |
3957 | must_check_value = 1; | |
3958 | else if (b->watchpoint_triggered == watch_triggered_yes) | |
3959 | /* We have a hardware watchpoint (read, write, or access) | |
3960 | and the target earlier reported an address watched by | |
3961 | this watchpoint. */ | |
3962 | must_check_value = 1; | |
3963 | else if (b->watchpoint_triggered == watch_triggered_unknown | |
3964 | && b->type == bp_hardware_watchpoint) | |
3965 | /* We were stopped by a hardware watchpoint, but the target could | |
3966 | not report the data address. We must check the watchpoint's | |
3967 | value. Access and read watchpoints are out of luck; without | |
3968 | a data address, we can't figure it out. */ | |
3969 | must_check_value = 1; | |
3970 | ||
3971 | if (must_check_value) | |
3972 | { | |
3e43a32a MS |
3973 | char *message |
3974 | = xstrprintf ("Error evaluating expression for watchpoint %d\n", | |
3975 | b->number); | |
18a18393 VP |
3976 | struct cleanup *cleanups = make_cleanup (xfree, message); |
3977 | int e = catch_errors (watchpoint_check, bs, message, | |
3978 | RETURN_MASK_ALL); | |
3979 | do_cleanups (cleanups); | |
3980 | switch (e) | |
3981 | { | |
3982 | case WP_DELETED: | |
3983 | /* We've already printed what needs to be printed. */ | |
3984 | bs->print_it = print_it_done; | |
3985 | /* Stop. */ | |
3986 | break; | |
60e1c644 PA |
3987 | case WP_IGNORE: |
3988 | bs->print_it = print_it_noop; | |
3989 | bs->stop = 0; | |
3990 | break; | |
18a18393 VP |
3991 | case WP_VALUE_CHANGED: |
3992 | if (b->type == bp_read_watchpoint) | |
3993 | { | |
85d721b8 PA |
3994 | /* There are two cases to consider here: |
3995 | ||
4a64f543 | 3996 | 1. We're watching the triggered memory for reads. |
85d721b8 PA |
3997 | In that case, trust the target, and always report |
3998 | the watchpoint hit to the user. Even though | |
3999 | reads don't cause value changes, the value may | |
4000 | have changed since the last time it was read, and | |
4001 | since we're not trapping writes, we will not see | |
4002 | those, and as such we should ignore our notion of | |
4003 | old value. | |
4004 | ||
4a64f543 | 4005 | 2. We're watching the triggered memory for both |
85d721b8 PA |
4006 | reads and writes. There are two ways this may |
4007 | happen: | |
4008 | ||
4a64f543 | 4009 | 2.1. This is a target that can't break on data |
85d721b8 PA |
4010 | reads only, but can break on accesses (reads or |
4011 | writes), such as e.g., x86. We detect this case | |
4012 | at the time we try to insert read watchpoints. | |
4013 | ||
4a64f543 | 4014 | 2.2. Otherwise, the target supports read |
85d721b8 PA |
4015 | watchpoints, but, the user set an access or write |
4016 | watchpoint watching the same memory as this read | |
4017 | watchpoint. | |
4018 | ||
4019 | If we're watching memory writes as well as reads, | |
4020 | ignore watchpoint hits when we find that the | |
4021 | value hasn't changed, as reads don't cause | |
4022 | changes. This still gives false positives when | |
4023 | the program writes the same value to memory as | |
4024 | what there was already in memory (we will confuse | |
4025 | it for a read), but it's much better than | |
4026 | nothing. */ | |
4027 | ||
4028 | int other_write_watchpoint = 0; | |
4029 | ||
4030 | if (bl->watchpoint_type == hw_read) | |
4031 | { | |
4032 | struct breakpoint *other_b; | |
4033 | ||
4034 | ALL_BREAKPOINTS (other_b) | |
4035 | if ((other_b->type == bp_hardware_watchpoint | |
4036 | || other_b->type == bp_access_watchpoint) | |
4037 | && (other_b->watchpoint_triggered | |
4038 | == watch_triggered_yes)) | |
4039 | { | |
4040 | other_write_watchpoint = 1; | |
4041 | break; | |
4042 | } | |
4043 | } | |
4044 | ||
4045 | if (other_write_watchpoint | |
4046 | || bl->watchpoint_type == hw_access) | |
4047 | { | |
4048 | /* We're watching the same memory for writes, | |
4049 | and the value changed since the last time we | |
4050 | updated it, so this trap must be for a write. | |
4051 | Ignore it. */ | |
4052 | bs->print_it = print_it_noop; | |
4053 | bs->stop = 0; | |
4054 | } | |
18a18393 VP |
4055 | } |
4056 | break; | |
4057 | case WP_VALUE_NOT_CHANGED: | |
4058 | if (b->type == bp_hardware_watchpoint | |
4059 | || b->type == bp_watchpoint) | |
4060 | { | |
4061 | /* Don't stop: write watchpoints shouldn't fire if | |
4062 | the value hasn't changed. */ | |
4063 | bs->print_it = print_it_noop; | |
4064 | bs->stop = 0; | |
4065 | } | |
4066 | /* Stop. */ | |
4067 | break; | |
4068 | default: | |
4069 | /* Can't happen. */ | |
4070 | case 0: | |
4071 | /* Error from catch_errors. */ | |
4072 | printf_filtered (_("Watchpoint %d deleted.\n"), b->number); | |
d0fb5eae | 4073 | watchpoint_del_at_next_stop (b); |
18a18393 VP |
4074 | /* We've already printed what needs to be printed. */ |
4075 | bs->print_it = print_it_done; | |
4076 | break; | |
4077 | } | |
4078 | } | |
4079 | else /* must_check_value == 0 */ | |
4080 | { | |
4081 | /* This is a case where some watchpoint(s) triggered, but | |
4082 | not at the address of this watchpoint, or else no | |
4083 | watchpoint triggered after all. So don't print | |
4084 | anything for this watchpoint. */ | |
4085 | bs->print_it = print_it_noop; | |
4086 | bs->stop = 0; | |
4087 | } | |
4088 | } | |
4089 | } | |
4090 | ||
4091 | ||
4092 | /* Check conditions (condition proper, frame, thread and ignore count) | |
4093 | of breakpoint referred to by BS. If we should not stop for this | |
4094 | breakpoint, set BS->stop to 0. */ | |
f431efe5 | 4095 | |
18a18393 VP |
4096 | static void |
4097 | bpstat_check_breakpoint_conditions (bpstat bs, ptid_t ptid) | |
4098 | { | |
4099 | int thread_id = pid_to_thread_id (ptid); | |
2bdf28a0 JK |
4100 | const struct bp_location *bl; |
4101 | struct breakpoint *b; | |
4102 | ||
4103 | /* BS is built for existing struct breakpoint. */ | |
f431efe5 | 4104 | bl = bs->bp_location_at; |
2bdf28a0 | 4105 | gdb_assert (bl != NULL); |
f431efe5 | 4106 | b = bs->breakpoint_at; |
2bdf28a0 | 4107 | gdb_assert (b != NULL); |
18a18393 VP |
4108 | |
4109 | if (frame_id_p (b->frame_id) | |
edb3359d | 4110 | && !frame_id_eq (b->frame_id, get_stack_frame_id (get_current_frame ()))) |
18a18393 VP |
4111 | bs->stop = 0; |
4112 | else if (bs->stop) | |
4113 | { | |
4114 | int value_is_zero = 0; | |
60e1c644 PA |
4115 | struct expression *cond; |
4116 | ||
7371cf6d PM |
4117 | /* Evaluate Python breakpoints that have a "stop" |
4118 | method implemented. */ | |
4119 | if (b->py_bp_object) | |
4120 | bs->stop = gdbpy_should_stop (b->py_bp_object); | |
4121 | ||
60e1c644 PA |
4122 | if (is_watchpoint (b)) |
4123 | cond = b->cond_exp; | |
4124 | else | |
4125 | cond = bl->cond; | |
4126 | ||
f431efe5 | 4127 | if (cond && b->disposition != disp_del_at_next_stop) |
18a18393 | 4128 | { |
60e1c644 PA |
4129 | int within_current_scope = 1; |
4130 | ||
c5bc3a77 DJ |
4131 | /* We use value_mark and value_free_to_mark because it could |
4132 | be a long time before we return to the command level and | |
4133 | call free_all_values. We can't call free_all_values | |
4134 | because we might be in the middle of evaluating a | |
4135 | function call. */ | |
4136 | struct value *mark = value_mark (); | |
4137 | ||
edb3359d DJ |
4138 | /* Need to select the frame, with all that implies so that |
4139 | the conditions will have the right context. Because we | |
4140 | use the frame, we will not see an inlined function's | |
4141 | variables when we arrive at a breakpoint at the start | |
4142 | of the inlined function; the current frame will be the | |
4143 | call site. */ | |
60e1c644 PA |
4144 | if (!is_watchpoint (b) || b->cond_exp_valid_block == NULL) |
4145 | select_frame (get_current_frame ()); | |
4146 | else | |
4147 | { | |
4148 | struct frame_info *frame; | |
4149 | ||
4150 | /* For local watchpoint expressions, which particular | |
4151 | instance of a local is being watched matters, so we | |
4152 | keep track of the frame to evaluate the expression | |
4153 | in. To evaluate the condition however, it doesn't | |
4154 | really matter which instantiation of the function | |
4155 | where the condition makes sense triggers the | |
4156 | watchpoint. This allows an expression like "watch | |
4157 | global if q > 10" set in `func', catch writes to | |
4158 | global on all threads that call `func', or catch | |
4159 | writes on all recursive calls of `func' by a single | |
4160 | thread. We simply always evaluate the condition in | |
4161 | the innermost frame that's executing where it makes | |
4162 | sense to evaluate the condition. It seems | |
4163 | intuitive. */ | |
4164 | frame = block_innermost_frame (b->cond_exp_valid_block); | |
4165 | if (frame != NULL) | |
4166 | select_frame (frame); | |
4167 | else | |
4168 | within_current_scope = 0; | |
4169 | } | |
4170 | if (within_current_scope) | |
4171 | value_is_zero | |
4172 | = catch_errors (breakpoint_cond_eval, cond, | |
4173 | "Error in testing breakpoint condition:\n", | |
4174 | RETURN_MASK_ALL); | |
4175 | else | |
4176 | { | |
4177 | warning (_("Watchpoint condition cannot be tested " | |
4178 | "in the current scope")); | |
4179 | /* If we failed to set the right context for this | |
4180 | watchpoint, unconditionally report it. */ | |
4181 | value_is_zero = 0; | |
4182 | } | |
4a64f543 | 4183 | /* FIXME-someday, should give breakpoint #. */ |
c5bc3a77 | 4184 | value_free_to_mark (mark); |
18a18393 | 4185 | } |
60e1c644 PA |
4186 | |
4187 | if (cond && value_is_zero) | |
18a18393 VP |
4188 | { |
4189 | bs->stop = 0; | |
4190 | } | |
4191 | else if (b->thread != -1 && b->thread != thread_id) | |
4192 | { | |
4193 | bs->stop = 0; | |
4194 | } | |
4195 | else if (b->ignore_count > 0) | |
4196 | { | |
4197 | b->ignore_count--; | |
4198 | annotate_ignore_count_change (); | |
4199 | bs->stop = 0; | |
4a64f543 | 4200 | /* Increase the hit count even though we don't stop. */ |
18a18393 | 4201 | ++(b->hit_count); |
8d3788bd | 4202 | observer_notify_breakpoint_modified (b); |
18a18393 VP |
4203 | } |
4204 | } | |
4205 | } | |
4206 | ||
4207 | ||
9709f61c | 4208 | /* Get a bpstat associated with having just stopped at address |
d983da9c | 4209 | BP_ADDR in thread PTID. |
c906108c | 4210 | |
d983da9c | 4211 | Determine whether we stopped at a breakpoint, etc, or whether we |
4a64f543 MS |
4212 | don't understand this stop. Result is a chain of bpstat's such |
4213 | that: | |
c906108c | 4214 | |
c5aa993b | 4215 | if we don't understand the stop, the result is a null pointer. |
c906108c | 4216 | |
c5aa993b | 4217 | if we understand why we stopped, the result is not null. |
c906108c | 4218 | |
c5aa993b JM |
4219 | Each element of the chain refers to a particular breakpoint or |
4220 | watchpoint at which we have stopped. (We may have stopped for | |
4221 | several reasons concurrently.) | |
c906108c | 4222 | |
c5aa993b JM |
4223 | Each element of the chain has valid next, breakpoint_at, |
4224 | commands, FIXME??? fields. */ | |
c906108c SS |
4225 | |
4226 | bpstat | |
6c95b8df PA |
4227 | bpstat_stop_status (struct address_space *aspace, |
4228 | CORE_ADDR bp_addr, ptid_t ptid) | |
c906108c | 4229 | { |
0d381245 | 4230 | struct breakpoint *b = NULL; |
afe38095 | 4231 | struct bp_location *bl; |
20874c92 | 4232 | struct bp_location *loc; |
5760d0ab JK |
4233 | /* First item of allocated bpstat's. */ |
4234 | bpstat bs_head = NULL, *bs_link = &bs_head; | |
c906108c | 4235 | /* Pointer to the last thing in the chain currently. */ |
5760d0ab | 4236 | bpstat bs; |
20874c92 | 4237 | int ix; |
429374b8 | 4238 | int need_remove_insert; |
f431efe5 | 4239 | int removed_any; |
c906108c | 4240 | |
f431efe5 PA |
4241 | /* First, build the bpstat chain with locations that explain a |
4242 | target stop, while being careful to not set the target running, | |
4243 | as that may invalidate locations (in particular watchpoint | |
4244 | locations are recreated). Resuming will happen here with | |
4245 | breakpoint conditions or watchpoint expressions that include | |
4246 | inferior function calls. */ | |
c5aa993b | 4247 | |
429374b8 JK |
4248 | ALL_BREAKPOINTS (b) |
4249 | { | |
4250 | if (!breakpoint_enabled (b) && b->enable_state != bp_permanent) | |
4251 | continue; | |
a5606eee | 4252 | |
429374b8 JK |
4253 | for (bl = b->loc; bl != NULL; bl = bl->next) |
4254 | { | |
4a64f543 MS |
4255 | /* For hardware watchpoints, we look only at the first |
4256 | location. The watchpoint_check function will work on the | |
4257 | entire expression, not the individual locations. For | |
4258 | read watchpoints, the watchpoints_triggered function has | |
4259 | checked all locations already. */ | |
429374b8 JK |
4260 | if (b->type == bp_hardware_watchpoint && bl != b->loc) |
4261 | break; | |
18a18393 | 4262 | |
429374b8 JK |
4263 | if (bl->shlib_disabled) |
4264 | continue; | |
c5aa993b | 4265 | |
429374b8 JK |
4266 | if (!bpstat_check_location (bl, aspace, bp_addr)) |
4267 | continue; | |
c5aa993b | 4268 | |
4a64f543 MS |
4269 | /* Come here if it's a watchpoint, or if the break address |
4270 | matches. */ | |
c5aa993b | 4271 | |
4a64f543 MS |
4272 | bs = bpstat_alloc (bl, &bs_link); /* Alloc a bpstat to |
4273 | explain stop. */ | |
c5aa993b | 4274 | |
f431efe5 PA |
4275 | /* Assume we stop. Should we find a watchpoint that is not |
4276 | actually triggered, or if the condition of the breakpoint | |
4277 | evaluates as false, we'll reset 'stop' to 0. */ | |
429374b8 JK |
4278 | bs->stop = 1; |
4279 | bs->print = 1; | |
d983da9c | 4280 | |
f431efe5 PA |
4281 | /* If this is a scope breakpoint, mark the associated |
4282 | watchpoint as triggered so that we will handle the | |
4283 | out-of-scope event. We'll get to the watchpoint next | |
4284 | iteration. */ | |
d0fb5eae | 4285 | if (b->type == bp_watchpoint_scope && b->related_breakpoint != b) |
f431efe5 PA |
4286 | b->related_breakpoint->watchpoint_triggered = watch_triggered_yes; |
4287 | } | |
4288 | } | |
4289 | ||
4290 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
4291 | { | |
f1310107 | 4292 | if (breakpoint_location_address_match (loc, aspace, bp_addr)) |
f431efe5 | 4293 | { |
5760d0ab | 4294 | bs = bpstat_alloc (loc, &bs_link); |
f431efe5 PA |
4295 | /* For hits of moribund locations, we should just proceed. */ |
4296 | bs->stop = 0; | |
4297 | bs->print = 0; | |
4298 | bs->print_it = print_it_noop; | |
4299 | } | |
4300 | } | |
4301 | ||
f431efe5 PA |
4302 | /* Now go through the locations that caused the target to stop, and |
4303 | check whether we're interested in reporting this stop to higher | |
4304 | layers, or whether we should resume the target transparently. */ | |
4305 | ||
4306 | removed_any = 0; | |
4307 | ||
5760d0ab | 4308 | for (bs = bs_head; bs != NULL; bs = bs->next) |
f431efe5 PA |
4309 | { |
4310 | if (!bs->stop) | |
4311 | continue; | |
4312 | ||
4313 | bpstat_check_watchpoint (bs); | |
4314 | if (!bs->stop) | |
4315 | continue; | |
4316 | ||
4317 | b = bs->breakpoint_at; | |
18a18393 | 4318 | |
429374b8 | 4319 | if (b->type == bp_thread_event || b->type == bp_overlay_event |
aa7d318d | 4320 | || b->type == bp_longjmp_master |
186c406b TT |
4321 | || b->type == bp_std_terminate_master |
4322 | || b->type == bp_exception_master) | |
429374b8 JK |
4323 | /* We do not stop for these. */ |
4324 | bs->stop = 0; | |
4325 | else | |
4326 | bpstat_check_breakpoint_conditions (bs, ptid); | |
f431efe5 | 4327 | |
429374b8 JK |
4328 | if (bs->stop) |
4329 | { | |
4330 | ++(b->hit_count); | |
8d3788bd | 4331 | observer_notify_breakpoint_modified (b); |
c906108c | 4332 | |
4a64f543 | 4333 | /* We will stop here. */ |
429374b8 JK |
4334 | if (b->disposition == disp_disable) |
4335 | { | |
4336 | if (b->enable_state != bp_permanent) | |
4337 | b->enable_state = bp_disabled; | |
f431efe5 | 4338 | removed_any = 1; |
429374b8 JK |
4339 | } |
4340 | if (b->silent) | |
4341 | bs->print = 0; | |
4342 | bs->commands = b->commands; | |
9add0f1b TT |
4343 | incref_counted_command_line (bs->commands); |
4344 | bs->commands_left = bs->commands ? bs->commands->commands : NULL; | |
4345 | if (bs->commands_left | |
4346 | && (strcmp ("silent", bs->commands_left->line) == 0 | |
4347 | || (xdb_commands | |
4348 | && strcmp ("Q", | |
4349 | bs->commands_left->line) == 0))) | |
429374b8 | 4350 | { |
9add0f1b | 4351 | bs->commands_left = bs->commands_left->next; |
429374b8 JK |
4352 | bs->print = 0; |
4353 | } | |
429374b8 JK |
4354 | } |
4355 | ||
4356 | /* Print nothing for this entry if we dont stop or dont print. */ | |
4357 | if (bs->stop == 0 || bs->print == 0) | |
4358 | bs->print_it = print_it_noop; | |
429374b8 | 4359 | } |
876fa593 | 4360 | |
d983da9c DJ |
4361 | /* If we aren't stopping, the value of some hardware watchpoint may |
4362 | not have changed, but the intermediate memory locations we are | |
4363 | watching may have. Don't bother if we're stopping; this will get | |
4364 | done later. */ | |
d832cb68 | 4365 | need_remove_insert = 0; |
5760d0ab JK |
4366 | if (! bpstat_causes_stop (bs_head)) |
4367 | for (bs = bs_head; bs != NULL; bs = bs->next) | |
d983da9c | 4368 | if (!bs->stop |
f431efe5 PA |
4369 | && bs->breakpoint_at |
4370 | && is_hardware_watchpoint (bs->breakpoint_at)) | |
d983da9c | 4371 | { |
4a64f543 | 4372 | update_watchpoint (bs->breakpoint_at, 0 /* don't reparse. */); |
d832cb68 | 4373 | need_remove_insert = 1; |
d983da9c DJ |
4374 | } |
4375 | ||
d832cb68 | 4376 | if (need_remove_insert) |
2d134ed3 | 4377 | update_global_location_list (1); |
f431efe5 PA |
4378 | else if (removed_any) |
4379 | update_global_location_list (0); | |
d832cb68 | 4380 | |
5760d0ab | 4381 | return bs_head; |
c906108c | 4382 | } |
628fe4e4 JK |
4383 | |
4384 | static void | |
4385 | handle_jit_event (void) | |
4386 | { | |
4387 | struct frame_info *frame; | |
4388 | struct gdbarch *gdbarch; | |
4389 | ||
4390 | /* Switch terminal for any messages produced by | |
4391 | breakpoint_re_set. */ | |
4392 | target_terminal_ours_for_output (); | |
4393 | ||
4394 | frame = get_current_frame (); | |
4395 | gdbarch = get_frame_arch (frame); | |
4396 | ||
4397 | jit_event_handler (gdbarch); | |
4398 | ||
4399 | target_terminal_inferior (); | |
4400 | } | |
4401 | ||
4402 | /* Prepare WHAT final decision for infrun. */ | |
4403 | ||
4404 | /* Decide what infrun needs to do with this bpstat. */ | |
4405 | ||
c906108c | 4406 | struct bpstat_what |
0e30163f | 4407 | bpstat_what (bpstat bs_head) |
c906108c | 4408 | { |
c906108c | 4409 | struct bpstat_what retval; |
628fe4e4 JK |
4410 | /* We need to defer calling `solib_add', as adding new symbols |
4411 | resets breakpoints, which in turn deletes breakpoint locations, | |
4412 | and hence may clear unprocessed entries in the BS chain. */ | |
4413 | int shlib_event = 0; | |
4414 | int jit_event = 0; | |
0e30163f | 4415 | bpstat bs; |
c906108c | 4416 | |
628fe4e4 | 4417 | retval.main_action = BPSTAT_WHAT_KEEP_CHECKING; |
aa7d318d | 4418 | retval.call_dummy = STOP_NONE; |
186c406b | 4419 | retval.is_longjmp = 0; |
628fe4e4 | 4420 | |
0e30163f | 4421 | for (bs = bs_head; bs != NULL; bs = bs->next) |
c906108c | 4422 | { |
628fe4e4 JK |
4423 | /* Extract this BS's action. After processing each BS, we check |
4424 | if its action overrides all we've seem so far. */ | |
4425 | enum bpstat_what_main_action this_action = BPSTAT_WHAT_KEEP_CHECKING; | |
4426 | enum bptype bptype; | |
4427 | ||
c906108c | 4428 | if (bs->breakpoint_at == NULL) |
628fe4e4 JK |
4429 | { |
4430 | /* I suspect this can happen if it was a momentary | |
4431 | breakpoint which has since been deleted. */ | |
4432 | bptype = bp_none; | |
4433 | } | |
f431efe5 | 4434 | else if (bs->breakpoint_at == NULL) |
628fe4e4 | 4435 | bptype = bp_none; |
20874c92 | 4436 | else |
f431efe5 | 4437 | bptype = bs->breakpoint_at->type; |
628fe4e4 JK |
4438 | |
4439 | switch (bptype) | |
c906108c SS |
4440 | { |
4441 | case bp_none: | |
628fe4e4 | 4442 | break; |
c906108c SS |
4443 | case bp_breakpoint: |
4444 | case bp_hardware_breakpoint: | |
4445 | case bp_until: | |
4446 | case bp_finish: | |
4447 | if (bs->stop) | |
4448 | { | |
4449 | if (bs->print) | |
628fe4e4 | 4450 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4451 | else |
628fe4e4 | 4452 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4453 | } |
4454 | else | |
628fe4e4 | 4455 | this_action = BPSTAT_WHAT_SINGLE; |
c906108c SS |
4456 | break; |
4457 | case bp_watchpoint: | |
4458 | case bp_hardware_watchpoint: | |
4459 | case bp_read_watchpoint: | |
4460 | case bp_access_watchpoint: | |
4461 | if (bs->stop) | |
4462 | { | |
4463 | if (bs->print) | |
628fe4e4 | 4464 | this_action = BPSTAT_WHAT_STOP_NOISY; |
c906108c | 4465 | else |
628fe4e4 | 4466 | this_action = BPSTAT_WHAT_STOP_SILENT; |
c906108c SS |
4467 | } |
4468 | else | |
628fe4e4 JK |
4469 | { |
4470 | /* There was a watchpoint, but we're not stopping. | |
4471 | This requires no further action. */ | |
4472 | } | |
c906108c SS |
4473 | break; |
4474 | case bp_longjmp: | |
186c406b | 4475 | case bp_exception: |
628fe4e4 | 4476 | this_action = BPSTAT_WHAT_SET_LONGJMP_RESUME; |
186c406b | 4477 | retval.is_longjmp = bptype == bp_longjmp; |
c906108c SS |
4478 | break; |
4479 | case bp_longjmp_resume: | |
186c406b | 4480 | case bp_exception_resume: |
628fe4e4 | 4481 | this_action = BPSTAT_WHAT_CLEAR_LONGJMP_RESUME; |
186c406b | 4482 | retval.is_longjmp = bptype == bp_longjmp_resume; |
c906108c SS |
4483 | break; |
4484 | case bp_step_resume: | |
4485 | if (bs->stop) | |
628fe4e4 JK |
4486 | this_action = BPSTAT_WHAT_STEP_RESUME; |
4487 | else | |
c906108c | 4488 | { |
628fe4e4 JK |
4489 | /* It is for the wrong frame. */ |
4490 | this_action = BPSTAT_WHAT_SINGLE; | |
c906108c | 4491 | } |
c906108c | 4492 | break; |
2c03e5be PA |
4493 | case bp_hp_step_resume: |
4494 | if (bs->stop) | |
4495 | this_action = BPSTAT_WHAT_HP_STEP_RESUME; | |
4496 | else | |
4497 | { | |
4498 | /* It is for the wrong frame. */ | |
4499 | this_action = BPSTAT_WHAT_SINGLE; | |
4500 | } | |
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"}, |
2c03e5be | 4770 | {bp_hp_step_resume, "high-priority step resume"}, |
c5aa993b JM |
4771 | {bp_watchpoint_scope, "watchpoint scope"}, |
4772 | {bp_call_dummy, "call dummy"}, | |
aa7d318d | 4773 | {bp_std_terminate, "std::terminate"}, |
c5aa993b | 4774 | {bp_shlib_event, "shlib events"}, |
c4093a6a | 4775 | {bp_thread_event, "thread events"}, |
1900040c | 4776 | {bp_overlay_event, "overlay events"}, |
0fd8e87f | 4777 | {bp_longjmp_master, "longjmp master"}, |
aa7d318d | 4778 | {bp_std_terminate_master, "std::terminate master"}, |
186c406b | 4779 | {bp_exception_master, "exception master"}, |
ce78b96d | 4780 | {bp_catchpoint, "catchpoint"}, |
1042e4c0 | 4781 | {bp_tracepoint, "tracepoint"}, |
7a697b8d | 4782 | {bp_fast_tracepoint, "fast tracepoint"}, |
0fb4aa4b | 4783 | {bp_static_tracepoint, "static tracepoint"}, |
4efc6507 | 4784 | {bp_jit_event, "jit events"}, |
0e30163f JK |
4785 | {bp_gnu_ifunc_resolver, "STT_GNU_IFUNC resolver"}, |
4786 | {bp_gnu_ifunc_resolver_return, "STT_GNU_IFUNC resolver return"}, | |
c5aa993b | 4787 | }; |
269b11a2 PA |
4788 | |
4789 | if (((int) type >= (sizeof (bptypes) / sizeof (bptypes[0]))) | |
4790 | || ((int) type != bptypes[(int) type].type)) | |
4791 | internal_error (__FILE__, __LINE__, | |
4792 | _("bptypes table does not describe type #%d."), | |
4793 | (int) type); | |
4794 | ||
4795 | return bptypes[(int) type].description; | |
4796 | } | |
4797 | ||
4798 | /* Print B to gdb_stdout. */ | |
4799 | ||
4800 | static void | |
4801 | print_one_breakpoint_location (struct breakpoint *b, | |
4802 | struct bp_location *loc, | |
4803 | int loc_number, | |
4804 | struct bp_location **last_loc, | |
269b11a2 PA |
4805 | int allflag) |
4806 | { | |
4807 | struct command_line *l; | |
c2c6d25f | 4808 | static char bpenables[] = "nynny"; |
c906108c | 4809 | |
0d381245 VP |
4810 | int header_of_multiple = 0; |
4811 | int part_of_multiple = (loc != NULL); | |
79a45b7d TT |
4812 | struct value_print_options opts; |
4813 | ||
4814 | get_user_print_options (&opts); | |
0d381245 VP |
4815 | |
4816 | gdb_assert (!loc || loc_number != 0); | |
4a64f543 MS |
4817 | /* See comment in print_one_breakpoint concerning treatment of |
4818 | breakpoints with single disabled location. */ | |
0d381245 VP |
4819 | if (loc == NULL |
4820 | && (b->loc != NULL | |
4821 | && (b->loc->next != NULL || !b->loc->enabled))) | |
4822 | header_of_multiple = 1; | |
4823 | if (loc == NULL) | |
4824 | loc = b->loc; | |
4825 | ||
c4093a6a JM |
4826 | annotate_record (); |
4827 | ||
4828 | /* 1 */ | |
4829 | annotate_field (0); | |
0d381245 VP |
4830 | if (part_of_multiple) |
4831 | { | |
4832 | char *formatted; | |
0c6773c1 | 4833 | formatted = xstrprintf ("%d.%d", b->number, loc_number); |
0d381245 VP |
4834 | ui_out_field_string (uiout, "number", formatted); |
4835 | xfree (formatted); | |
4836 | } | |
4837 | else | |
4838 | { | |
4839 | ui_out_field_int (uiout, "number", b->number); | |
4840 | } | |
c4093a6a JM |
4841 | |
4842 | /* 2 */ | |
4843 | annotate_field (1); | |
0d381245 VP |
4844 | if (part_of_multiple) |
4845 | ui_out_field_skip (uiout, "type"); | |
269b11a2 PA |
4846 | else |
4847 | ui_out_field_string (uiout, "type", bptype_string (b->type)); | |
c4093a6a JM |
4848 | |
4849 | /* 3 */ | |
4850 | annotate_field (2); | |
0d381245 VP |
4851 | if (part_of_multiple) |
4852 | ui_out_field_skip (uiout, "disp"); | |
4853 | else | |
2cec12e5 | 4854 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); |
0d381245 | 4855 | |
c4093a6a JM |
4856 | |
4857 | /* 4 */ | |
4858 | annotate_field (3); | |
0d381245 | 4859 | if (part_of_multiple) |
54e52265 | 4860 | ui_out_field_string (uiout, "enabled", loc->enabled ? "y" : "n"); |
0d381245 | 4861 | else |
4a64f543 MS |
4862 | ui_out_field_fmt (uiout, "enabled", "%c", |
4863 | bpenables[(int) b->enable_state]); | |
54e52265 | 4864 | ui_out_spaces (uiout, 2); |
0d381245 | 4865 | |
c4093a6a JM |
4866 | |
4867 | /* 5 and 6 */ | |
3086aeae | 4868 | if (b->ops != NULL && b->ops->print_one != NULL) |
0d381245 | 4869 | { |
4a64f543 MS |
4870 | /* Although the print_one can possibly print all locations, |
4871 | calling it here is not likely to get any nice result. So, | |
4872 | make sure there's just one location. */ | |
0d381245 | 4873 | gdb_assert (b->loc == NULL || b->loc->next == NULL); |
a6d9a66e | 4874 | b->ops->print_one (b, last_loc); |
0d381245 | 4875 | } |
3086aeae DJ |
4876 | else |
4877 | switch (b->type) | |
4878 | { | |
4879 | case bp_none: | |
4880 | internal_error (__FILE__, __LINE__, | |
e2e0b3e5 | 4881 | _("print_one_breakpoint: bp_none encountered\n")); |
3086aeae | 4882 | break; |
c906108c | 4883 | |
3086aeae DJ |
4884 | case bp_watchpoint: |
4885 | case bp_hardware_watchpoint: | |
4886 | case bp_read_watchpoint: | |
4887 | case bp_access_watchpoint: | |
4888 | /* Field 4, the address, is omitted (which makes the columns | |
4889 | not line up too nicely with the headers, but the effect | |
4890 | is relatively readable). */ | |
79a45b7d | 4891 | if (opts.addressprint) |
3086aeae DJ |
4892 | ui_out_field_skip (uiout, "addr"); |
4893 | annotate_field (5); | |
fa8a61dc | 4894 | ui_out_field_string (uiout, "what", b->exp_string); |
3086aeae DJ |
4895 | break; |
4896 | ||
3086aeae DJ |
4897 | case bp_breakpoint: |
4898 | case bp_hardware_breakpoint: | |
4899 | case bp_until: | |
4900 | case bp_finish: | |
4901 | case bp_longjmp: | |
4902 | case bp_longjmp_resume: | |
186c406b TT |
4903 | case bp_exception: |
4904 | case bp_exception_resume: | |
3086aeae | 4905 | case bp_step_resume: |
2c03e5be | 4906 | case bp_hp_step_resume: |
3086aeae DJ |
4907 | case bp_watchpoint_scope: |
4908 | case bp_call_dummy: | |
aa7d318d | 4909 | case bp_std_terminate: |
3086aeae DJ |
4910 | case bp_shlib_event: |
4911 | case bp_thread_event: | |
4912 | case bp_overlay_event: | |
0fd8e87f | 4913 | case bp_longjmp_master: |
aa7d318d | 4914 | case bp_std_terminate_master: |
186c406b | 4915 | case bp_exception_master: |
1042e4c0 | 4916 | case bp_tracepoint: |
7a697b8d | 4917 | case bp_fast_tracepoint: |
0fb4aa4b | 4918 | case bp_static_tracepoint: |
4efc6507 | 4919 | case bp_jit_event: |
0e30163f JK |
4920 | case bp_gnu_ifunc_resolver: |
4921 | case bp_gnu_ifunc_resolver_return: | |
79a45b7d | 4922 | if (opts.addressprint) |
3086aeae DJ |
4923 | { |
4924 | annotate_field (4); | |
54e52265 | 4925 | if (header_of_multiple) |
0d381245 | 4926 | ui_out_field_string (uiout, "addr", "<MULTIPLE>"); |
e9bbd7c5 | 4927 | else if (b->loc == NULL || loc->shlib_disabled) |
54e52265 | 4928 | ui_out_field_string (uiout, "addr", "<PENDING>"); |
0101ce28 | 4929 | else |
5af949e3 UW |
4930 | ui_out_field_core_addr (uiout, "addr", |
4931 | loc->gdbarch, loc->address); | |
3086aeae DJ |
4932 | } |
4933 | annotate_field (5); | |
0d381245 | 4934 | if (!header_of_multiple) |
170b53b2 | 4935 | print_breakpoint_location (b, loc); |
0d381245 | 4936 | if (b->loc) |
a6d9a66e | 4937 | *last_loc = b->loc; |
3086aeae DJ |
4938 | break; |
4939 | } | |
c906108c | 4940 | |
6c95b8df PA |
4941 | |
4942 | /* For backward compatibility, don't display inferiors unless there | |
4943 | are several. */ | |
4944 | if (loc != NULL | |
4945 | && !header_of_multiple | |
4946 | && (allflag | |
4947 | || (!gdbarch_has_global_breakpoints (target_gdbarch) | |
4948 | && (number_of_program_spaces () > 1 | |
4949 | || number_of_inferiors () > 1) | |
4a64f543 MS |
4950 | /* LOC is for existing B, it cannot be in |
4951 | moribund_locations and thus having NULL OWNER. */ | |
6c95b8df PA |
4952 | && loc->owner->type != bp_catchpoint))) |
4953 | { | |
4954 | struct inferior *inf; | |
4955 | int first = 1; | |
4956 | ||
4957 | for (inf = inferior_list; inf != NULL; inf = inf->next) | |
4958 | { | |
4959 | if (inf->pspace == loc->pspace) | |
4960 | { | |
4961 | if (first) | |
4962 | { | |
4963 | first = 0; | |
4964 | ui_out_text (uiout, " inf "); | |
4965 | } | |
4966 | else | |
4967 | ui_out_text (uiout, ", "); | |
4968 | ui_out_text (uiout, plongest (inf->num)); | |
4969 | } | |
4970 | } | |
4971 | } | |
4972 | ||
4a306c9a | 4973 | if (!part_of_multiple) |
c4093a6a | 4974 | { |
4a306c9a JB |
4975 | if (b->thread != -1) |
4976 | { | |
4977 | /* FIXME: This seems to be redundant and lost here; see the | |
4a64f543 | 4978 | "stop only in" line a little further down. */ |
4a306c9a JB |
4979 | ui_out_text (uiout, " thread "); |
4980 | ui_out_field_int (uiout, "thread", b->thread); | |
4981 | } | |
4982 | else if (b->task != 0) | |
4983 | { | |
4984 | ui_out_text (uiout, " task "); | |
4985 | ui_out_field_int (uiout, "task", b->task); | |
4986 | } | |
c4093a6a | 4987 | } |
f1310107 | 4988 | |
8b93c638 | 4989 | ui_out_text (uiout, "\n"); |
f1310107 TJB |
4990 | |
4991 | if (!part_of_multiple && b->ops && b->ops->print_one_detail) | |
4992 | b->ops->print_one_detail (b, uiout); | |
4993 | ||
0fb4aa4b PA |
4994 | if (!part_of_multiple && b->static_trace_marker_id) |
4995 | { | |
4996 | gdb_assert (b->type == bp_static_tracepoint); | |
4997 | ||
4998 | ui_out_text (uiout, "\tmarker id is "); | |
4999 | ui_out_field_string (uiout, "static-tracepoint-marker-string-id", | |
5000 | b->static_trace_marker_id); | |
5001 | ui_out_text (uiout, "\n"); | |
5002 | } | |
5003 | ||
0d381245 | 5004 | if (part_of_multiple && frame_id_p (b->frame_id)) |
c4093a6a JM |
5005 | { |
5006 | annotate_field (6); | |
8b93c638 | 5007 | ui_out_text (uiout, "\tstop only in stack frame at "); |
818dd999 AC |
5008 | /* FIXME: cagney/2002-12-01: Shouldn't be poeking around inside |
5009 | the frame ID. */ | |
5af949e3 UW |
5010 | ui_out_field_core_addr (uiout, "frame", |
5011 | b->gdbarch, b->frame_id.stack_addr); | |
8b93c638 | 5012 | ui_out_text (uiout, "\n"); |
c4093a6a JM |
5013 | } |
5014 | ||
0d381245 | 5015 | if (!part_of_multiple && b->cond_string && !ada_exception_catchpoint_p (b)) |
c4093a6a | 5016 | { |
f7f9143b JB |
5017 | /* We do not print the condition for Ada exception catchpoints |
5018 | because the condition is an internal implementation detail | |
5019 | that we do not want to expose to the user. */ | |
c4093a6a | 5020 | annotate_field (7); |
d77f58be | 5021 | if (is_tracepoint (b)) |
1042e4c0 SS |
5022 | ui_out_text (uiout, "\ttrace only if "); |
5023 | else | |
5024 | ui_out_text (uiout, "\tstop only if "); | |
0101ce28 JJ |
5025 | ui_out_field_string (uiout, "cond", b->cond_string); |
5026 | ui_out_text (uiout, "\n"); | |
5027 | } | |
5028 | ||
0d381245 | 5029 | if (!part_of_multiple && b->thread != -1) |
c4093a6a | 5030 | { |
4a64f543 | 5031 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5032 | ui_out_text (uiout, "\tstop only in thread "); |
5033 | ui_out_field_int (uiout, "thread", b->thread); | |
5034 | ui_out_text (uiout, "\n"); | |
c4093a6a JM |
5035 | } |
5036 | ||
63c715c6 | 5037 | if (!part_of_multiple && b->hit_count) |
c4093a6a | 5038 | { |
4a64f543 | 5039 | /* FIXME should make an annotation for this. */ |
8b93c638 JM |
5040 | if (ep_is_catchpoint (b)) |
5041 | ui_out_text (uiout, "\tcatchpoint"); | |
5042 | else | |
5043 | ui_out_text (uiout, "\tbreakpoint"); | |
5044 | ui_out_text (uiout, " already hit "); | |
5045 | ui_out_field_int (uiout, "times", b->hit_count); | |
5046 | if (b->hit_count == 1) | |
5047 | ui_out_text (uiout, " time\n"); | |
5048 | else | |
5049 | ui_out_text (uiout, " times\n"); | |
c4093a6a JM |
5050 | } |
5051 | ||
4a64f543 MS |
5052 | /* Output the count also if it is zero, but only if this is mi. |
5053 | FIXME: Should have a better test for this. */ | |
9dc5e2a9 | 5054 | if (ui_out_is_mi_like_p (uiout)) |
63c715c6 | 5055 | if (!part_of_multiple && b->hit_count == 0) |
fb40c209 | 5056 | ui_out_field_int (uiout, "times", b->hit_count); |
8b93c638 | 5057 | |
0d381245 | 5058 | if (!part_of_multiple && b->ignore_count) |
c4093a6a JM |
5059 | { |
5060 | annotate_field (8); | |
8b93c638 JM |
5061 | ui_out_text (uiout, "\tignore next "); |
5062 | ui_out_field_int (uiout, "ignore", b->ignore_count); | |
5063 | ui_out_text (uiout, " hits\n"); | |
c4093a6a | 5064 | } |
059fb39f | 5065 | |
9add0f1b | 5066 | l = b->commands ? b->commands->commands : NULL; |
059fb39f | 5067 | if (!part_of_multiple && l) |
c4093a6a | 5068 | { |
3b31d625 EZ |
5069 | struct cleanup *script_chain; |
5070 | ||
c4093a6a | 5071 | annotate_field (9); |
3b31d625 | 5072 | script_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "script"); |
8b93c638 | 5073 | print_command_lines (uiout, l, 4); |
3b31d625 | 5074 | do_cleanups (script_chain); |
c4093a6a | 5075 | } |
d24317b4 | 5076 | |
1042e4c0 SS |
5077 | if (!part_of_multiple && b->pass_count) |
5078 | { | |
5079 | annotate_field (10); | |
5080 | ui_out_text (uiout, "\tpass count "); | |
5081 | ui_out_field_int (uiout, "pass", b->pass_count); | |
5082 | ui_out_text (uiout, " \n"); | |
5083 | } | |
5084 | ||
d24317b4 VP |
5085 | if (ui_out_is_mi_like_p (uiout) && !part_of_multiple) |
5086 | { | |
5087 | if (b->addr_string) | |
5088 | ui_out_field_string (uiout, "original-location", b->addr_string); | |
5089 | else if (b->exp_string) | |
5090 | ui_out_field_string (uiout, "original-location", b->exp_string); | |
5091 | } | |
c4093a6a | 5092 | } |
c5aa993b | 5093 | |
0d381245 VP |
5094 | static void |
5095 | print_one_breakpoint (struct breakpoint *b, | |
4a64f543 | 5096 | struct bp_location **last_loc, |
6c95b8df | 5097 | int allflag) |
0d381245 | 5098 | { |
8d3788bd VP |
5099 | struct cleanup *bkpt_chain; |
5100 | ||
5101 | bkpt_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "bkpt"); | |
5102 | ||
12c5a436 | 5103 | print_one_breakpoint_location (b, NULL, 0, last_loc, allflag); |
8d3788bd | 5104 | do_cleanups (bkpt_chain); |
0d381245 VP |
5105 | |
5106 | /* If this breakpoint has custom print function, | |
5107 | it's already printed. Otherwise, print individual | |
5108 | locations, if any. */ | |
5109 | if (b->ops == NULL || b->ops->print_one == NULL) | |
5110 | { | |
4a64f543 MS |
5111 | /* If breakpoint has a single location that is disabled, we |
5112 | print it as if it had several locations, since otherwise it's | |
5113 | hard to represent "breakpoint enabled, location disabled" | |
5114 | situation. | |
5115 | ||
5116 | Note that while hardware watchpoints have several locations | |
a3be7890 | 5117 | internally, that's not a property exposed to user. */ |
0d381245 | 5118 | if (b->loc |
a5606eee | 5119 | && !is_hardware_watchpoint (b) |
8d3788bd | 5120 | && (b->loc->next || !b->loc->enabled)) |
0d381245 VP |
5121 | { |
5122 | struct bp_location *loc; | |
5123 | int n = 1; | |
8d3788bd | 5124 | |
0d381245 | 5125 | for (loc = b->loc; loc; loc = loc->next, ++n) |
8d3788bd VP |
5126 | { |
5127 | struct cleanup *inner2 = | |
5128 | make_cleanup_ui_out_tuple_begin_end (uiout, NULL); | |
5129 | print_one_breakpoint_location (b, loc, n, last_loc, allflag); | |
5130 | do_cleanups (inner2); | |
5131 | } | |
0d381245 VP |
5132 | } |
5133 | } | |
5134 | } | |
5135 | ||
a6d9a66e UW |
5136 | static int |
5137 | breakpoint_address_bits (struct breakpoint *b) | |
5138 | { | |
5139 | int print_address_bits = 0; | |
5140 | struct bp_location *loc; | |
5141 | ||
5142 | for (loc = b->loc; loc; loc = loc->next) | |
5143 | { | |
c7437ca6 PA |
5144 | int addr_bit; |
5145 | ||
5146 | /* Software watchpoints that aren't watching memory don't have | |
5147 | an address to print. */ | |
5148 | if (b->type == bp_watchpoint && loc->watchpoint_type == -1) | |
5149 | continue; | |
5150 | ||
5151 | addr_bit = gdbarch_addr_bit (loc->gdbarch); | |
a6d9a66e UW |
5152 | if (addr_bit > print_address_bits) |
5153 | print_address_bits = addr_bit; | |
5154 | } | |
5155 | ||
5156 | return print_address_bits; | |
5157 | } | |
0d381245 | 5158 | |
c4093a6a JM |
5159 | struct captured_breakpoint_query_args |
5160 | { | |
5161 | int bnum; | |
5162 | }; | |
c5aa993b | 5163 | |
c4093a6a | 5164 | static int |
2b65245e | 5165 | do_captured_breakpoint_query (struct ui_out *uiout, void *data) |
c4093a6a JM |
5166 | { |
5167 | struct captured_breakpoint_query_args *args = data; | |
52f0bd74 | 5168 | struct breakpoint *b; |
a6d9a66e | 5169 | struct bp_location *dummy_loc = NULL; |
cc59ec59 | 5170 | |
c4093a6a JM |
5171 | ALL_BREAKPOINTS (b) |
5172 | { | |
5173 | if (args->bnum == b->number) | |
c5aa993b | 5174 | { |
12c5a436 | 5175 | print_one_breakpoint (b, &dummy_loc, 0); |
c4093a6a | 5176 | return GDB_RC_OK; |
c5aa993b | 5177 | } |
c4093a6a JM |
5178 | } |
5179 | return GDB_RC_NONE; | |
5180 | } | |
c5aa993b | 5181 | |
c4093a6a | 5182 | enum gdb_rc |
4a64f543 MS |
5183 | gdb_breakpoint_query (struct ui_out *uiout, int bnum, |
5184 | char **error_message) | |
c4093a6a JM |
5185 | { |
5186 | struct captured_breakpoint_query_args args; | |
cc59ec59 | 5187 | |
c4093a6a JM |
5188 | args.bnum = bnum; |
5189 | /* For the moment we don't trust print_one_breakpoint() to not throw | |
4a64f543 | 5190 | an error. */ |
b0b13bb4 DJ |
5191 | if (catch_exceptions_with_msg (uiout, do_captured_breakpoint_query, &args, |
5192 | error_message, RETURN_MASK_ALL) < 0) | |
5193 | return GDB_RC_FAIL; | |
5194 | else | |
5195 | return GDB_RC_OK; | |
c4093a6a | 5196 | } |
c5aa993b | 5197 | |
09d682a4 TT |
5198 | /* Return true if this breakpoint was set by the user, false if it is |
5199 | internal or momentary. */ | |
5200 | ||
5201 | int | |
5202 | user_breakpoint_p (struct breakpoint *b) | |
5203 | { | |
46c6471b | 5204 | return b->number > 0; |
09d682a4 TT |
5205 | } |
5206 | ||
7f3b0473 | 5207 | /* Print information on user settable breakpoint (watchpoint, etc) |
d77f58be SS |
5208 | number BNUM. If BNUM is -1 print all user-settable breakpoints. |
5209 | If ALLFLAG is non-zero, include non-user-settable breakpoints. If | |
5210 | FILTER is non-NULL, call it on each breakpoint and only include the | |
5211 | ones for which it returns non-zero. Return the total number of | |
5212 | breakpoints listed. */ | |
c906108c | 5213 | |
d77f58be | 5214 | static int |
e5a67952 | 5215 | breakpoint_1 (char *args, int allflag, |
4a64f543 | 5216 | int (*filter) (const struct breakpoint *)) |
c4093a6a | 5217 | { |
52f0bd74 | 5218 | struct breakpoint *b; |
a6d9a66e | 5219 | struct bp_location *last_loc = NULL; |
7f3b0473 | 5220 | int nr_printable_breakpoints; |
3b31d625 | 5221 | struct cleanup *bkpttbl_chain; |
79a45b7d | 5222 | struct value_print_options opts; |
a6d9a66e | 5223 | int print_address_bits = 0; |
269b11a2 PA |
5224 | int print_type_col_width = 14; |
5225 | ||
79a45b7d TT |
5226 | get_user_print_options (&opts); |
5227 | ||
4a64f543 MS |
5228 | /* Compute the number of rows in the table, as well as the size |
5229 | required for address fields. */ | |
7f3b0473 AC |
5230 | nr_printable_breakpoints = 0; |
5231 | ALL_BREAKPOINTS (b) | |
e5a67952 MS |
5232 | { |
5233 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5234 | if (filter && !filter (b)) | |
5235 | continue; | |
5236 | ||
5237 | /* If we have an "args" string, it is a list of breakpoints to | |
5238 | accept. Skip the others. */ | |
5239 | if (args != NULL && *args != '\0') | |
5240 | { | |
5241 | if (allflag && parse_and_eval_long (args) != b->number) | |
5242 | continue; | |
5243 | if (!allflag && !number_is_in_list (args, b->number)) | |
5244 | continue; | |
5245 | } | |
269b11a2 | 5246 | |
e5a67952 MS |
5247 | if (allflag || user_breakpoint_p (b)) |
5248 | { | |
5249 | int addr_bit, type_len; | |
a6d9a66e | 5250 | |
e5a67952 MS |
5251 | addr_bit = breakpoint_address_bits (b); |
5252 | if (addr_bit > print_address_bits) | |
5253 | print_address_bits = addr_bit; | |
269b11a2 | 5254 | |
e5a67952 MS |
5255 | type_len = strlen (bptype_string (b->type)); |
5256 | if (type_len > print_type_col_width) | |
5257 | print_type_col_width = type_len; | |
5258 | ||
5259 | nr_printable_breakpoints++; | |
5260 | } | |
5261 | } | |
7f3b0473 | 5262 | |
79a45b7d | 5263 | if (opts.addressprint) |
3b31d625 | 5264 | bkpttbl_chain |
3e43a32a MS |
5265 | = make_cleanup_ui_out_table_begin_end (uiout, 6, |
5266 | nr_printable_breakpoints, | |
3b31d625 | 5267 | "BreakpointTable"); |
8b93c638 | 5268 | else |
3b31d625 | 5269 | bkpttbl_chain |
3e43a32a MS |
5270 | = make_cleanup_ui_out_table_begin_end (uiout, 5, |
5271 | nr_printable_breakpoints, | |
3b31d625 | 5272 | "BreakpointTable"); |
8b93c638 | 5273 | |
7f3b0473 | 5274 | if (nr_printable_breakpoints > 0) |
d7faa9e7 AC |
5275 | annotate_breakpoints_headers (); |
5276 | if (nr_printable_breakpoints > 0) | |
5277 | annotate_field (0); | |
4a64f543 | 5278 | ui_out_table_header (uiout, 7, ui_left, "number", "Num"); /* 1 */ |
d7faa9e7 AC |
5279 | if (nr_printable_breakpoints > 0) |
5280 | annotate_field (1); | |
269b11a2 | 5281 | ui_out_table_header (uiout, print_type_col_width, ui_left, |
4a64f543 | 5282 | "type", "Type"); /* 2 */ |
d7faa9e7 AC |
5283 | if (nr_printable_breakpoints > 0) |
5284 | annotate_field (2); | |
4a64f543 | 5285 | ui_out_table_header (uiout, 4, ui_left, "disp", "Disp"); /* 3 */ |
d7faa9e7 AC |
5286 | if (nr_printable_breakpoints > 0) |
5287 | annotate_field (3); | |
54e52265 | 5288 | ui_out_table_header (uiout, 3, ui_left, "enabled", "Enb"); /* 4 */ |
79a45b7d | 5289 | if (opts.addressprint) |
e5a67952 MS |
5290 | { |
5291 | if (nr_printable_breakpoints > 0) | |
5292 | annotate_field (4); | |
5293 | if (print_address_bits <= 32) | |
5294 | ui_out_table_header (uiout, 10, ui_left, | |
5295 | "addr", "Address"); /* 5 */ | |
5296 | else | |
5297 | ui_out_table_header (uiout, 18, ui_left, | |
5298 | "addr", "Address"); /* 5 */ | |
5299 | } | |
d7faa9e7 AC |
5300 | if (nr_printable_breakpoints > 0) |
5301 | annotate_field (5); | |
5302 | ui_out_table_header (uiout, 40, ui_noalign, "what", "What"); /* 6 */ | |
5303 | ui_out_table_body (uiout); | |
5304 | if (nr_printable_breakpoints > 0) | |
5305 | annotate_breakpoints_table (); | |
7f3b0473 | 5306 | |
c4093a6a | 5307 | ALL_BREAKPOINTS (b) |
e5a67952 MS |
5308 | { |
5309 | QUIT; | |
5310 | /* If we have a filter, only list the breakpoints it accepts. */ | |
5311 | if (filter && !filter (b)) | |
5312 | continue; | |
5313 | ||
5314 | /* If we have an "args" string, it is a list of breakpoints to | |
5315 | accept. Skip the others. */ | |
5316 | ||
5317 | if (args != NULL && *args != '\0') | |
5318 | { | |
5319 | if (allflag) /* maintenance info breakpoint */ | |
5320 | { | |
5321 | if (parse_and_eval_long (args) != b->number) | |
5322 | continue; | |
5323 | } | |
5324 | else /* all others */ | |
5325 | { | |
5326 | if (!number_is_in_list (args, b->number)) | |
5327 | continue; | |
5328 | } | |
5329 | } | |
5330 | /* We only print out user settable breakpoints unless the | |
5331 | allflag is set. */ | |
5332 | if (allflag || user_breakpoint_p (b)) | |
12c5a436 | 5333 | print_one_breakpoint (b, &last_loc, allflag); |
e5a67952 MS |
5334 | } |
5335 | ||
3b31d625 | 5336 | do_cleanups (bkpttbl_chain); |
698384cd | 5337 | |
7f3b0473 | 5338 | if (nr_printable_breakpoints == 0) |
c906108c | 5339 | { |
4a64f543 MS |
5340 | /* If there's a filter, let the caller decide how to report |
5341 | empty list. */ | |
d77f58be SS |
5342 | if (!filter) |
5343 | { | |
e5a67952 | 5344 | if (args == NULL || *args == '\0') |
d77f58be SS |
5345 | ui_out_message (uiout, 0, "No breakpoints or watchpoints.\n"); |
5346 | else | |
4a64f543 | 5347 | ui_out_message (uiout, 0, |
e5a67952 MS |
5348 | "No breakpoint or watchpoint matching '%s'.\n", |
5349 | args); | |
d77f58be | 5350 | } |
c906108c SS |
5351 | } |
5352 | else | |
c4093a6a | 5353 | { |
a6d9a66e UW |
5354 | if (last_loc && !server_command) |
5355 | set_next_address (last_loc->gdbarch, last_loc->address); | |
c4093a6a | 5356 | } |
c906108c | 5357 | |
4a64f543 | 5358 | /* FIXME? Should this be moved up so that it is only called when |
c4093a6a | 5359 | there have been breakpoints? */ |
c906108c | 5360 | annotate_breakpoints_table_end (); |
d77f58be SS |
5361 | |
5362 | return nr_printable_breakpoints; | |
c906108c SS |
5363 | } |
5364 | ||
ad443146 SS |
5365 | /* Display the value of default-collect in a way that is generally |
5366 | compatible with the breakpoint list. */ | |
5367 | ||
5368 | static void | |
5369 | default_collect_info (void) | |
5370 | { | |
5371 | /* If it has no value (which is frequently the case), say nothing; a | |
5372 | message like "No default-collect." gets in user's face when it's | |
5373 | not wanted. */ | |
5374 | if (!*default_collect) | |
5375 | return; | |
5376 | ||
5377 | /* The following phrase lines up nicely with per-tracepoint collect | |
5378 | actions. */ | |
5379 | ui_out_text (uiout, "default collect "); | |
5380 | ui_out_field_string (uiout, "default-collect", default_collect); | |
5381 | ui_out_text (uiout, " \n"); | |
5382 | } | |
5383 | ||
c906108c | 5384 | static void |
e5a67952 | 5385 | breakpoints_info (char *args, int from_tty) |
c906108c | 5386 | { |
e5a67952 | 5387 | breakpoint_1 (args, 0, NULL); |
ad443146 SS |
5388 | |
5389 | default_collect_info (); | |
d77f58be SS |
5390 | } |
5391 | ||
5392 | static void | |
e5a67952 | 5393 | watchpoints_info (char *args, int from_tty) |
d77f58be | 5394 | { |
e5a67952 | 5395 | int num_printed = breakpoint_1 (args, 0, is_watchpoint); |
d77f58be SS |
5396 | |
5397 | if (num_printed == 0) | |
5398 | { | |
e5a67952 | 5399 | if (args == NULL || *args == '\0') |
d77f58be SS |
5400 | ui_out_message (uiout, 0, "No watchpoints.\n"); |
5401 | else | |
e5a67952 | 5402 | ui_out_message (uiout, 0, "No watchpoint matching '%s'.\n", args); |
d77f58be | 5403 | } |
c906108c SS |
5404 | } |
5405 | ||
7a292a7a | 5406 | static void |
e5a67952 | 5407 | maintenance_info_breakpoints (char *args, int from_tty) |
c906108c | 5408 | { |
e5a67952 | 5409 | breakpoint_1 (args, 1, NULL); |
ad443146 SS |
5410 | |
5411 | default_collect_info (); | |
c906108c SS |
5412 | } |
5413 | ||
0d381245 | 5414 | static int |
714835d5 | 5415 | breakpoint_has_pc (struct breakpoint *b, |
6c95b8df | 5416 | struct program_space *pspace, |
714835d5 | 5417 | CORE_ADDR pc, struct obj_section *section) |
0d381245 VP |
5418 | { |
5419 | struct bp_location *bl = b->loc; | |
cc59ec59 | 5420 | |
0d381245 VP |
5421 | for (; bl; bl = bl->next) |
5422 | { | |
6c95b8df PA |
5423 | if (bl->pspace == pspace |
5424 | && bl->address == pc | |
0d381245 VP |
5425 | && (!overlay_debugging || bl->section == section)) |
5426 | return 1; | |
5427 | } | |
5428 | return 0; | |
5429 | } | |
5430 | ||
6c95b8df PA |
5431 | /* Print a message describing any breakpoints set at PC. This |
5432 | concerns with logical breakpoints, so we match program spaces, not | |
5433 | address spaces. */ | |
c906108c SS |
5434 | |
5435 | static void | |
6c95b8df PA |
5436 | describe_other_breakpoints (struct gdbarch *gdbarch, |
5437 | struct program_space *pspace, CORE_ADDR pc, | |
5af949e3 | 5438 | struct obj_section *section, int thread) |
c906108c | 5439 | { |
52f0bd74 AC |
5440 | int others = 0; |
5441 | struct breakpoint *b; | |
c906108c SS |
5442 | |
5443 | ALL_BREAKPOINTS (b) | |
6c95b8df | 5444 | others += breakpoint_has_pc (b, pspace, pc, section); |
c906108c SS |
5445 | if (others > 0) |
5446 | { | |
a3f17187 AC |
5447 | if (others == 1) |
5448 | printf_filtered (_("Note: breakpoint ")); | |
5449 | else /* if (others == ???) */ | |
5450 | printf_filtered (_("Note: breakpoints ")); | |
c906108c | 5451 | ALL_BREAKPOINTS (b) |
6c95b8df | 5452 | if (breakpoint_has_pc (b, pspace, pc, section)) |
0d381245 VP |
5453 | { |
5454 | others--; | |
5455 | printf_filtered ("%d", b->number); | |
5456 | if (b->thread == -1 && thread != -1) | |
5457 | printf_filtered (" (all threads)"); | |
5458 | else if (b->thread != -1) | |
5459 | printf_filtered (" (thread %d)", b->thread); | |
5460 | printf_filtered ("%s%s ", | |
059fb39f | 5461 | ((b->enable_state == bp_disabled |
8bea4e01 UW |
5462 | || b->enable_state == bp_call_disabled |
5463 | || b->enable_state == bp_startup_disabled) | |
0d381245 VP |
5464 | ? " (disabled)" |
5465 | : b->enable_state == bp_permanent | |
5466 | ? " (permanent)" | |
5467 | : ""), | |
5468 | (others > 1) ? "," | |
5469 | : ((others == 1) ? " and" : "")); | |
5470 | } | |
a3f17187 | 5471 | printf_filtered (_("also set at pc ")); |
5af949e3 | 5472 | fputs_filtered (paddress (gdbarch, pc), gdb_stdout); |
c906108c SS |
5473 | printf_filtered (".\n"); |
5474 | } | |
5475 | } | |
5476 | \f | |
5477 | /* Set the default place to put a breakpoint | |
5478 | for the `break' command with no arguments. */ | |
5479 | ||
5480 | void | |
6c95b8df PA |
5481 | set_default_breakpoint (int valid, struct program_space *pspace, |
5482 | CORE_ADDR addr, struct symtab *symtab, | |
fba45db2 | 5483 | int line) |
c906108c SS |
5484 | { |
5485 | default_breakpoint_valid = valid; | |
6c95b8df | 5486 | default_breakpoint_pspace = pspace; |
c906108c SS |
5487 | default_breakpoint_address = addr; |
5488 | default_breakpoint_symtab = symtab; | |
5489 | default_breakpoint_line = line; | |
5490 | } | |
5491 | ||
e4f237da KB |
5492 | /* Return true iff it is meaningful to use the address member of |
5493 | BPT. For some breakpoint types, the address member is irrelevant | |
5494 | and it makes no sense to attempt to compare it to other addresses | |
5495 | (or use it for any other purpose either). | |
5496 | ||
4a64f543 MS |
5497 | More specifically, each of the following breakpoint types will |
5498 | always have a zero valued address and we don't want to mark | |
5499 | breakpoints of any of these types to be a duplicate of an actual | |
5500 | breakpoint at address zero: | |
e4f237da KB |
5501 | |
5502 | bp_watchpoint | |
2d134ed3 PA |
5503 | bp_catchpoint |
5504 | ||
5505 | */ | |
e4f237da KB |
5506 | |
5507 | static int | |
5508 | breakpoint_address_is_meaningful (struct breakpoint *bpt) | |
5509 | { | |
5510 | enum bptype type = bpt->type; | |
5511 | ||
2d134ed3 PA |
5512 | return (type != bp_watchpoint && type != bp_catchpoint); |
5513 | } | |
5514 | ||
5515 | /* Assuming LOC1 and LOC2's owners are hardware watchpoints, returns | |
5516 | true if LOC1 and LOC2 represent the same watchpoint location. */ | |
5517 | ||
5518 | static int | |
4a64f543 MS |
5519 | watchpoint_locations_match (struct bp_location *loc1, |
5520 | struct bp_location *loc2) | |
2d134ed3 | 5521 | { |
2bdf28a0 JK |
5522 | /* Both of them must not be in moribund_locations. */ |
5523 | gdb_assert (loc1->owner != NULL); | |
5524 | gdb_assert (loc2->owner != NULL); | |
5525 | ||
4a64f543 MS |
5526 | /* If the target can evaluate the condition expression in hardware, |
5527 | then we we need to insert both watchpoints even if they are at | |
5528 | the same place. Otherwise the watchpoint will only trigger when | |
5529 | the condition of whichever watchpoint was inserted evaluates to | |
5530 | true, not giving a chance for GDB to check the condition of the | |
5531 | other watchpoint. */ | |
0cf6dd15 | 5532 | if ((loc1->owner->cond_exp |
4a64f543 MS |
5533 | && target_can_accel_watchpoint_condition (loc1->address, |
5534 | loc1->length, | |
0cf6dd15 TJB |
5535 | loc1->watchpoint_type, |
5536 | loc1->owner->cond_exp)) | |
5537 | || (loc2->owner->cond_exp | |
4a64f543 MS |
5538 | && target_can_accel_watchpoint_condition (loc2->address, |
5539 | loc2->length, | |
0cf6dd15 TJB |
5540 | loc2->watchpoint_type, |
5541 | loc2->owner->cond_exp))) | |
5542 | return 0; | |
5543 | ||
85d721b8 PA |
5544 | /* Note that this checks the owner's type, not the location's. In |
5545 | case the target does not support read watchpoints, but does | |
5546 | support access watchpoints, we'll have bp_read_watchpoint | |
5547 | watchpoints with hw_access locations. Those should be considered | |
5548 | duplicates of hw_read locations. The hw_read locations will | |
5549 | become hw_access locations later. */ | |
2d134ed3 PA |
5550 | return (loc1->owner->type == loc2->owner->type |
5551 | && loc1->pspace->aspace == loc2->pspace->aspace | |
5552 | && loc1->address == loc2->address | |
5553 | && loc1->length == loc2->length); | |
e4f237da KB |
5554 | } |
5555 | ||
6c95b8df PA |
5556 | /* Returns true if {ASPACE1,ADDR1} and {ASPACE2,ADDR2} represent the |
5557 | same breakpoint location. In most targets, this can only be true | |
5558 | if ASPACE1 matches ASPACE2. On targets that have global | |
5559 | breakpoints, the address space doesn't really matter. */ | |
5560 | ||
5561 | static int | |
5562 | breakpoint_address_match (struct address_space *aspace1, CORE_ADDR addr1, | |
5563 | struct address_space *aspace2, CORE_ADDR addr2) | |
5564 | { | |
5565 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5566 | || aspace1 == aspace2) | |
5567 | && addr1 == addr2); | |
5568 | } | |
5569 | ||
f1310107 TJB |
5570 | /* Returns true if {ASPACE2,ADDR2} falls within the range determined by |
5571 | {ASPACE1,ADDR1,LEN1}. In most targets, this can only be true if ASPACE1 | |
5572 | matches ASPACE2. On targets that have global breakpoints, the address | |
5573 | space doesn't really matter. */ | |
5574 | ||
5575 | static int | |
5576 | breakpoint_address_match_range (struct address_space *aspace1, CORE_ADDR addr1, | |
5577 | int len1, struct address_space *aspace2, | |
5578 | CORE_ADDR addr2) | |
5579 | { | |
5580 | return ((gdbarch_has_global_breakpoints (target_gdbarch) | |
5581 | || aspace1 == aspace2) | |
5582 | && addr2 >= addr1 && addr2 < addr1 + len1); | |
5583 | } | |
5584 | ||
5585 | /* Returns true if {ASPACE,ADDR} matches the breakpoint BL. BL may be | |
5586 | a ranged breakpoint. In most targets, a match happens only if ASPACE | |
5587 | matches the breakpoint's address space. On targets that have global | |
5588 | breakpoints, the address space doesn't really matter. */ | |
5589 | ||
5590 | static int | |
5591 | breakpoint_location_address_match (struct bp_location *bl, | |
5592 | struct address_space *aspace, | |
5593 | CORE_ADDR addr) | |
5594 | { | |
5595 | return (breakpoint_address_match (bl->pspace->aspace, bl->address, | |
5596 | aspace, addr) | |
5597 | || (bl->length | |
5598 | && breakpoint_address_match_range (bl->pspace->aspace, | |
5599 | bl->address, bl->length, | |
5600 | aspace, addr))); | |
5601 | } | |
5602 | ||
2d134ed3 PA |
5603 | /* Assuming LOC1 and LOC2's types' have meaningful target addresses |
5604 | (breakpoint_address_is_meaningful), returns true if LOC1 and LOC2 | |
5605 | represent the same location. */ | |
5606 | ||
5607 | static int | |
4a64f543 MS |
5608 | breakpoint_locations_match (struct bp_location *loc1, |
5609 | struct bp_location *loc2) | |
2d134ed3 | 5610 | { |
2bdf28a0 JK |
5611 | int hw_point1, hw_point2; |
5612 | ||
5613 | /* Both of them must not be in moribund_locations. */ | |
5614 | gdb_assert (loc1->owner != NULL); | |
5615 | gdb_assert (loc2->owner != NULL); | |
5616 | ||
5617 | hw_point1 = is_hardware_watchpoint (loc1->owner); | |
5618 | hw_point2 = is_hardware_watchpoint (loc2->owner); | |
2d134ed3 PA |
5619 | |
5620 | if (hw_point1 != hw_point2) | |
5621 | return 0; | |
5622 | else if (hw_point1) | |
5623 | return watchpoint_locations_match (loc1, loc2); | |
5624 | else | |
f1310107 TJB |
5625 | /* We compare bp_location.length in order to cover ranged breakpoints. */ |
5626 | return (breakpoint_address_match (loc1->pspace->aspace, loc1->address, | |
5627 | loc2->pspace->aspace, loc2->address) | |
5628 | && loc1->length == loc2->length); | |
2d134ed3 PA |
5629 | } |
5630 | ||
76897487 KB |
5631 | static void |
5632 | breakpoint_adjustment_warning (CORE_ADDR from_addr, CORE_ADDR to_addr, | |
5633 | int bnum, int have_bnum) | |
5634 | { | |
f63fbe86 MS |
5635 | /* The longest string possibly returned by hex_string_custom |
5636 | is 50 chars. These must be at least that big for safety. */ | |
5637 | char astr1[64]; | |
5638 | char astr2[64]; | |
76897487 | 5639 | |
bb599908 PH |
5640 | strcpy (astr1, hex_string_custom ((unsigned long) from_addr, 8)); |
5641 | strcpy (astr2, hex_string_custom ((unsigned long) to_addr, 8)); | |
76897487 | 5642 | if (have_bnum) |
8a3fe4f8 | 5643 | warning (_("Breakpoint %d address previously adjusted from %s to %s."), |
76897487 KB |
5644 | bnum, astr1, astr2); |
5645 | else | |
8a3fe4f8 | 5646 | warning (_("Breakpoint address adjusted from %s to %s."), astr1, astr2); |
76897487 KB |
5647 | } |
5648 | ||
4a64f543 MS |
5649 | /* Adjust a breakpoint's address to account for architectural |
5650 | constraints on breakpoint placement. Return the adjusted address. | |
5651 | Note: Very few targets require this kind of adjustment. For most | |
5652 | targets, this function is simply the identity function. */ | |
76897487 KB |
5653 | |
5654 | static CORE_ADDR | |
a6d9a66e UW |
5655 | adjust_breakpoint_address (struct gdbarch *gdbarch, |
5656 | CORE_ADDR bpaddr, enum bptype bptype) | |
76897487 | 5657 | { |
a6d9a66e | 5658 | if (!gdbarch_adjust_breakpoint_address_p (gdbarch)) |
76897487 KB |
5659 | { |
5660 | /* Very few targets need any kind of breakpoint adjustment. */ | |
5661 | return bpaddr; | |
5662 | } | |
88f7da05 KB |
5663 | else if (bptype == bp_watchpoint |
5664 | || bptype == bp_hardware_watchpoint | |
5665 | || bptype == bp_read_watchpoint | |
5666 | || bptype == bp_access_watchpoint | |
fe798b75 | 5667 | || bptype == bp_catchpoint) |
88f7da05 KB |
5668 | { |
5669 | /* Watchpoints and the various bp_catch_* eventpoints should not | |
5670 | have their addresses modified. */ | |
5671 | return bpaddr; | |
5672 | } | |
76897487 KB |
5673 | else |
5674 | { | |
5675 | CORE_ADDR adjusted_bpaddr; | |
5676 | ||
5677 | /* Some targets have architectural constraints on the placement | |
5678 | of breakpoint instructions. Obtain the adjusted address. */ | |
a6d9a66e | 5679 | adjusted_bpaddr = gdbarch_adjust_breakpoint_address (gdbarch, bpaddr); |
76897487 KB |
5680 | |
5681 | /* An adjusted breakpoint address can significantly alter | |
5682 | a user's expectations. Print a warning if an adjustment | |
5683 | is required. */ | |
5684 | if (adjusted_bpaddr != bpaddr) | |
5685 | breakpoint_adjustment_warning (bpaddr, adjusted_bpaddr, 0, 0); | |
5686 | ||
5687 | return adjusted_bpaddr; | |
5688 | } | |
5689 | } | |
5690 | ||
7cc221ef DJ |
5691 | /* Allocate a struct bp_location. */ |
5692 | ||
26bb91f3 | 5693 | static struct bp_location * |
39d61571 | 5694 | allocate_bp_location (struct breakpoint *bpt) |
7cc221ef | 5695 | { |
afe38095 | 5696 | struct bp_location *loc; |
7cc221ef DJ |
5697 | |
5698 | loc = xmalloc (sizeof (struct bp_location)); | |
5699 | memset (loc, 0, sizeof (*loc)); | |
5700 | ||
e049a4b5 | 5701 | loc->owner = bpt; |
511a6cd4 | 5702 | loc->cond = NULL; |
0d381245 VP |
5703 | loc->shlib_disabled = 0; |
5704 | loc->enabled = 1; | |
e049a4b5 | 5705 | |
39d61571 | 5706 | switch (bpt->type) |
e049a4b5 DJ |
5707 | { |
5708 | case bp_breakpoint: | |
5709 | case bp_until: | |
5710 | case bp_finish: | |
5711 | case bp_longjmp: | |
5712 | case bp_longjmp_resume: | |
186c406b TT |
5713 | case bp_exception: |
5714 | case bp_exception_resume: | |
e049a4b5 | 5715 | case bp_step_resume: |
2c03e5be | 5716 | case bp_hp_step_resume: |
e049a4b5 DJ |
5717 | case bp_watchpoint_scope: |
5718 | case bp_call_dummy: | |
aa7d318d | 5719 | case bp_std_terminate: |
e049a4b5 DJ |
5720 | case bp_shlib_event: |
5721 | case bp_thread_event: | |
5722 | case bp_overlay_event: | |
4efc6507 | 5723 | case bp_jit_event: |
0fd8e87f | 5724 | case bp_longjmp_master: |
aa7d318d | 5725 | case bp_std_terminate_master: |
186c406b | 5726 | case bp_exception_master: |
0e30163f JK |
5727 | case bp_gnu_ifunc_resolver: |
5728 | case bp_gnu_ifunc_resolver_return: | |
e049a4b5 DJ |
5729 | loc->loc_type = bp_loc_software_breakpoint; |
5730 | break; | |
5731 | case bp_hardware_breakpoint: | |
5732 | loc->loc_type = bp_loc_hardware_breakpoint; | |
5733 | break; | |
5734 | case bp_hardware_watchpoint: | |
5735 | case bp_read_watchpoint: | |
5736 | case bp_access_watchpoint: | |
5737 | loc->loc_type = bp_loc_hardware_watchpoint; | |
5738 | break; | |
5739 | case bp_watchpoint: | |
ce78b96d | 5740 | case bp_catchpoint: |
15c3d785 PA |
5741 | case bp_tracepoint: |
5742 | case bp_fast_tracepoint: | |
0fb4aa4b | 5743 | case bp_static_tracepoint: |
e049a4b5 DJ |
5744 | loc->loc_type = bp_loc_other; |
5745 | break; | |
5746 | default: | |
e2e0b3e5 | 5747 | internal_error (__FILE__, __LINE__, _("unknown breakpoint type")); |
e049a4b5 DJ |
5748 | } |
5749 | ||
f431efe5 | 5750 | loc->refc = 1; |
7cc221ef DJ |
5751 | return loc; |
5752 | } | |
5753 | ||
f431efe5 PA |
5754 | static void |
5755 | free_bp_location (struct bp_location *loc) | |
fe3f5fa8 VP |
5756 | { |
5757 | if (loc->cond) | |
5758 | xfree (loc->cond); | |
74960c60 VP |
5759 | |
5760 | if (loc->function_name) | |
5761 | xfree (loc->function_name); | |
f431efe5 | 5762 | |
fe3f5fa8 VP |
5763 | xfree (loc); |
5764 | } | |
5765 | ||
f431efe5 PA |
5766 | /* Increment reference count. */ |
5767 | ||
5768 | static void | |
5769 | incref_bp_location (struct bp_location *bl) | |
5770 | { | |
5771 | ++bl->refc; | |
5772 | } | |
5773 | ||
5774 | /* Decrement reference count. If the reference count reaches 0, | |
5775 | destroy the bp_location. Sets *BLP to NULL. */ | |
5776 | ||
5777 | static void | |
5778 | decref_bp_location (struct bp_location **blp) | |
5779 | { | |
0807b50c PA |
5780 | gdb_assert ((*blp)->refc > 0); |
5781 | ||
f431efe5 PA |
5782 | if (--(*blp)->refc == 0) |
5783 | free_bp_location (*blp); | |
5784 | *blp = NULL; | |
5785 | } | |
5786 | ||
4a64f543 MS |
5787 | /* Helper to set_raw_breakpoint below. Creates a breakpoint that has |
5788 | type BPTYPE and has no locations as yet. */ | |
5789 | /* This function is used in gdbtk sources and thus can not be made | |
5790 | static. */ | |
c906108c | 5791 | |
c40e75cd | 5792 | static struct breakpoint * |
a6d9a66e UW |
5793 | set_raw_breakpoint_without_location (struct gdbarch *gdbarch, |
5794 | enum bptype bptype) | |
c906108c | 5795 | { |
52f0bd74 | 5796 | struct breakpoint *b, *b1; |
c906108c SS |
5797 | |
5798 | b = (struct breakpoint *) xmalloc (sizeof (struct breakpoint)); | |
5799 | memset (b, 0, sizeof (*b)); | |
2219d63c | 5800 | |
4d28f7a8 | 5801 | b->type = bptype; |
a6d9a66e | 5802 | b->gdbarch = gdbarch; |
c906108c SS |
5803 | b->language = current_language->la_language; |
5804 | b->input_radix = input_radix; | |
5805 | b->thread = -1; | |
b5de0fa7 | 5806 | b->enable_state = bp_enabled; |
c906108c SS |
5807 | b->next = 0; |
5808 | b->silent = 0; | |
5809 | b->ignore_count = 0; | |
5810 | b->commands = NULL; | |
818dd999 | 5811 | b->frame_id = null_frame_id; |
3a3e9ee3 | 5812 | b->forked_inferior_pid = null_ptid; |
c906108c | 5813 | b->exec_pathname = NULL; |
a96d9b2e | 5814 | b->syscalls_to_be_caught = NULL; |
3086aeae | 5815 | b->ops = NULL; |
0d381245 | 5816 | b->condition_not_parsed = 0; |
84f4c1fe | 5817 | b->py_bp_object = NULL; |
d0fb5eae | 5818 | b->related_breakpoint = b; |
c906108c | 5819 | |
4a64f543 MS |
5820 | /* Add this breakpoint to the end of the chain so that a list of |
5821 | breakpoints will come out in order of increasing numbers. */ | |
c906108c SS |
5822 | |
5823 | b1 = breakpoint_chain; | |
5824 | if (b1 == 0) | |
5825 | breakpoint_chain = b; | |
5826 | else | |
5827 | { | |
5828 | while (b1->next) | |
5829 | b1 = b1->next; | |
5830 | b1->next = b; | |
5831 | } | |
0d381245 VP |
5832 | return b; |
5833 | } | |
5834 | ||
0e30163f JK |
5835 | /* Initialize loc->function_name. EXPLICIT_LOC says no indirect function |
5836 | resolutions should be made as the user specified the location explicitly | |
5837 | enough. */ | |
5838 | ||
0d381245 | 5839 | static void |
0e30163f | 5840 | set_breakpoint_location_function (struct bp_location *loc, int explicit_loc) |
0d381245 | 5841 | { |
2bdf28a0 JK |
5842 | gdb_assert (loc->owner != NULL); |
5843 | ||
0d381245 | 5844 | if (loc->owner->type == bp_breakpoint |
1042e4c0 | 5845 | || loc->owner->type == bp_hardware_breakpoint |
d77f58be | 5846 | || is_tracepoint (loc->owner)) |
0d381245 | 5847 | { |
0e30163f JK |
5848 | int is_gnu_ifunc; |
5849 | ||
5850 | find_pc_partial_function_gnu_ifunc (loc->address, &loc->function_name, | |
5851 | NULL, NULL, &is_gnu_ifunc); | |
5852 | ||
5853 | if (is_gnu_ifunc && !explicit_loc) | |
5854 | { | |
5855 | struct breakpoint *b = loc->owner; | |
5856 | ||
5857 | gdb_assert (loc->pspace == current_program_space); | |
5858 | if (gnu_ifunc_resolve_name (loc->function_name, | |
5859 | &loc->requested_address)) | |
5860 | { | |
5861 | /* Recalculate ADDRESS based on new REQUESTED_ADDRESS. */ | |
5862 | loc->address = adjust_breakpoint_address (loc->gdbarch, | |
5863 | loc->requested_address, | |
5864 | b->type); | |
5865 | } | |
5866 | else if (b->type == bp_breakpoint && b->loc == loc | |
5867 | && loc->next == NULL && b->related_breakpoint == b) | |
5868 | { | |
5869 | /* Create only the whole new breakpoint of this type but do not | |
5870 | mess more complicated breakpoints with multiple locations. */ | |
5871 | b->type = bp_gnu_ifunc_resolver; | |
5872 | } | |
5873 | } | |
5874 | ||
0d381245 VP |
5875 | if (loc->function_name) |
5876 | loc->function_name = xstrdup (loc->function_name); | |
5877 | } | |
5878 | } | |
5879 | ||
a6d9a66e UW |
5880 | /* Attempt to determine architecture of location identified by SAL. */ |
5881 | static struct gdbarch * | |
5882 | get_sal_arch (struct symtab_and_line sal) | |
5883 | { | |
5884 | if (sal.section) | |
5885 | return get_objfile_arch (sal.section->objfile); | |
5886 | if (sal.symtab) | |
5887 | return get_objfile_arch (sal.symtab->objfile); | |
5888 | ||
5889 | return NULL; | |
5890 | } | |
5891 | ||
0d381245 VP |
5892 | /* set_raw_breakpoint is a low level routine for allocating and |
5893 | partially initializing a breakpoint of type BPTYPE. The newly | |
5894 | created breakpoint's address, section, source file name, and line | |
5895 | number are provided by SAL. The newly created and partially | |
5896 | initialized breakpoint is added to the breakpoint chain and | |
5897 | is also returned as the value of this function. | |
5898 | ||
5899 | It is expected that the caller will complete the initialization of | |
5900 | the newly created breakpoint struct as well as output any status | |
5901 | information regarding the creation of a new breakpoint. In | |
5902 | particular, set_raw_breakpoint does NOT set the breakpoint | |
5903 | number! Care should be taken to not allow an error to occur | |
5904 | prior to completing the initialization of the breakpoint. If this | |
5905 | should happen, a bogus breakpoint will be left on the chain. */ | |
5906 | ||
63c252f8 | 5907 | struct breakpoint * |
a6d9a66e UW |
5908 | set_raw_breakpoint (struct gdbarch *gdbarch, |
5909 | struct symtab_and_line sal, enum bptype bptype) | |
0d381245 | 5910 | { |
4a64f543 MS |
5911 | struct breakpoint *b = set_raw_breakpoint_without_location (gdbarch, |
5912 | bptype); | |
0d381245 | 5913 | CORE_ADDR adjusted_address; |
a6d9a66e UW |
5914 | struct gdbarch *loc_gdbarch; |
5915 | ||
5916 | loc_gdbarch = get_sal_arch (sal); | |
5917 | if (!loc_gdbarch) | |
5918 | loc_gdbarch = b->gdbarch; | |
0d381245 | 5919 | |
6c95b8df PA |
5920 | if (bptype != bp_catchpoint) |
5921 | gdb_assert (sal.pspace != NULL); | |
5922 | ||
0d381245 VP |
5923 | /* Adjust the breakpoint's address prior to allocating a location. |
5924 | Once we call allocate_bp_location(), that mostly uninitialized | |
5925 | location will be placed on the location chain. Adjustment of the | |
8defab1a | 5926 | breakpoint may cause target_read_memory() to be called and we do |
0d381245 VP |
5927 | not want its scan of the location chain to find a breakpoint and |
5928 | location that's only been partially initialized. */ | |
4a64f543 MS |
5929 | adjusted_address = adjust_breakpoint_address (loc_gdbarch, |
5930 | sal.pc, b->type); | |
0d381245 | 5931 | |
39d61571 | 5932 | b->loc = allocate_bp_location (b); |
a6d9a66e | 5933 | b->loc->gdbarch = loc_gdbarch; |
0d381245 VP |
5934 | b->loc->requested_address = sal.pc; |
5935 | b->loc->address = adjusted_address; | |
6c95b8df PA |
5936 | b->loc->pspace = sal.pspace; |
5937 | ||
5938 | /* Store the program space that was used to set the breakpoint, for | |
5939 | breakpoint resetting. */ | |
5940 | b->pspace = sal.pspace; | |
0d381245 VP |
5941 | |
5942 | if (sal.symtab == NULL) | |
5943 | b->source_file = NULL; | |
5944 | else | |
1b36a34b | 5945 | b->source_file = xstrdup (sal.symtab->filename); |
0d381245 VP |
5946 | b->loc->section = sal.section; |
5947 | b->line_number = sal.line; | |
5948 | ||
0e30163f JK |
5949 | set_breakpoint_location_function (b->loc, |
5950 | sal.explicit_pc || sal.explicit_line); | |
c906108c | 5951 | |
c906108c SS |
5952 | breakpoints_changed (); |
5953 | ||
5954 | return b; | |
5955 | } | |
5956 | ||
c2c6d25f JM |
5957 | |
5958 | /* Note that the breakpoint object B describes a permanent breakpoint | |
5959 | instruction, hard-wired into the inferior's code. */ | |
5960 | void | |
5961 | make_breakpoint_permanent (struct breakpoint *b) | |
5962 | { | |
0d381245 | 5963 | struct bp_location *bl; |
cc59ec59 | 5964 | |
b5de0fa7 | 5965 | b->enable_state = bp_permanent; |
c2c6d25f | 5966 | |
4a64f543 MS |
5967 | /* By definition, permanent breakpoints are already present in the |
5968 | code. Mark all locations as inserted. For now, | |
5969 | make_breakpoint_permanent is called in just one place, so it's | |
5970 | hard to say if it's reasonable to have permanent breakpoint with | |
5971 | multiple locations or not, but it's easy to implmement. */ | |
0d381245 VP |
5972 | for (bl = b->loc; bl; bl = bl->next) |
5973 | bl->inserted = 1; | |
c2c6d25f JM |
5974 | } |
5975 | ||
53a5351d | 5976 | /* Call this routine when stepping and nexting to enable a breakpoint |
186c406b TT |
5977 | if we do a longjmp() or 'throw' in TP. FRAME is the frame which |
5978 | initiated the operation. */ | |
c906108c SS |
5979 | |
5980 | void | |
186c406b | 5981 | set_longjmp_breakpoint (struct thread_info *tp, struct frame_id frame) |
c906108c | 5982 | { |
35df4500 | 5983 | struct breakpoint *b, *b_tmp; |
186c406b | 5984 | int thread = tp->num; |
0fd8e87f UW |
5985 | |
5986 | /* To avoid having to rescan all objfile symbols at every step, | |
5987 | we maintain a list of continually-inserted but always disabled | |
5988 | longjmp "master" breakpoints. Here, we simply create momentary | |
5989 | clones of those and enable them for the requested thread. */ | |
35df4500 | 5990 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df | 5991 | if (b->pspace == current_program_space |
186c406b TT |
5992 | && (b->type == bp_longjmp_master |
5993 | || b->type == bp_exception_master)) | |
0fd8e87f UW |
5994 | { |
5995 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
cc59ec59 | 5996 | |
186c406b | 5997 | clone->type = b->type == bp_longjmp_master ? bp_longjmp : bp_exception; |
0fd8e87f UW |
5998 | clone->thread = thread; |
5999 | } | |
186c406b TT |
6000 | |
6001 | tp->initiating_frame = frame; | |
c906108c SS |
6002 | } |
6003 | ||
611c83ae | 6004 | /* Delete all longjmp breakpoints from THREAD. */ |
c906108c | 6005 | void |
611c83ae | 6006 | delete_longjmp_breakpoint (int thread) |
c906108c | 6007 | { |
35df4500 | 6008 | struct breakpoint *b, *b_tmp; |
c906108c | 6009 | |
35df4500 | 6010 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
186c406b | 6011 | if (b->type == bp_longjmp || b->type == bp_exception) |
611c83ae PA |
6012 | { |
6013 | if (b->thread == thread) | |
6014 | delete_breakpoint (b); | |
6015 | } | |
c906108c SS |
6016 | } |
6017 | ||
1900040c MS |
6018 | void |
6019 | enable_overlay_breakpoints (void) | |
6020 | { | |
52f0bd74 | 6021 | struct breakpoint *b; |
1900040c MS |
6022 | |
6023 | ALL_BREAKPOINTS (b) | |
6024 | if (b->type == bp_overlay_event) | |
6025 | { | |
6026 | b->enable_state = bp_enabled; | |
b60e7edf | 6027 | update_global_location_list (1); |
c02f5703 | 6028 | overlay_events_enabled = 1; |
1900040c MS |
6029 | } |
6030 | } | |
6031 | ||
6032 | void | |
6033 | disable_overlay_breakpoints (void) | |
6034 | { | |
52f0bd74 | 6035 | struct breakpoint *b; |
1900040c MS |
6036 | |
6037 | ALL_BREAKPOINTS (b) | |
6038 | if (b->type == bp_overlay_event) | |
6039 | { | |
6040 | b->enable_state = bp_disabled; | |
b60e7edf | 6041 | update_global_location_list (0); |
c02f5703 | 6042 | overlay_events_enabled = 0; |
1900040c MS |
6043 | } |
6044 | } | |
6045 | ||
aa7d318d TT |
6046 | /* Set an active std::terminate breakpoint for each std::terminate |
6047 | master breakpoint. */ | |
6048 | void | |
6049 | set_std_terminate_breakpoint (void) | |
6050 | { | |
35df4500 | 6051 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6052 | |
35df4500 | 6053 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6054 | if (b->pspace == current_program_space |
6055 | && b->type == bp_std_terminate_master) | |
6056 | { | |
6057 | struct breakpoint *clone = clone_momentary_breakpoint (b); | |
6058 | clone->type = bp_std_terminate; | |
6059 | } | |
6060 | } | |
6061 | ||
6062 | /* Delete all the std::terminate breakpoints. */ | |
6063 | void | |
6064 | delete_std_terminate_breakpoint (void) | |
6065 | { | |
35df4500 | 6066 | struct breakpoint *b, *b_tmp; |
aa7d318d | 6067 | |
35df4500 | 6068 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
aa7d318d TT |
6069 | if (b->type == bp_std_terminate) |
6070 | delete_breakpoint (b); | |
6071 | } | |
6072 | ||
c4093a6a | 6073 | struct breakpoint * |
a6d9a66e | 6074 | create_thread_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
c4093a6a JM |
6075 | { |
6076 | struct breakpoint *b; | |
c4093a6a | 6077 | |
a6d9a66e | 6078 | b = create_internal_breakpoint (gdbarch, address, bp_thread_event); |
c4093a6a | 6079 | |
b5de0fa7 | 6080 | b->enable_state = bp_enabled; |
c4093a6a | 6081 | /* addr_string has to be used or breakpoint_re_set will delete me. */ |
5af949e3 UW |
6082 | b->addr_string |
6083 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
c4093a6a | 6084 | |
b60e7edf | 6085 | update_global_location_list_nothrow (1); |
74960c60 | 6086 | |
c4093a6a JM |
6087 | return b; |
6088 | } | |
6089 | ||
6090 | void | |
6091 | remove_thread_event_breakpoints (void) | |
6092 | { | |
35df4500 | 6093 | struct breakpoint *b, *b_tmp; |
c4093a6a | 6094 | |
35df4500 | 6095 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6096 | if (b->type == bp_thread_event |
6097 | && b->loc->pspace == current_program_space) | |
c4093a6a JM |
6098 | delete_breakpoint (b); |
6099 | } | |
6100 | ||
0101ce28 JJ |
6101 | struct lang_and_radix |
6102 | { | |
6103 | enum language lang; | |
6104 | int radix; | |
6105 | }; | |
6106 | ||
4efc6507 DE |
6107 | /* Create a breakpoint for JIT code registration and unregistration. */ |
6108 | ||
6109 | struct breakpoint * | |
6110 | create_jit_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) | |
6111 | { | |
6112 | struct breakpoint *b; | |
6113 | ||
6114 | b = create_internal_breakpoint (gdbarch, address, bp_jit_event); | |
6115 | update_global_location_list_nothrow (1); | |
6116 | return b; | |
6117 | } | |
0101ce28 | 6118 | |
03673fc7 PP |
6119 | /* Remove JIT code registration and unregistration breakpoint(s). */ |
6120 | ||
6121 | void | |
6122 | remove_jit_event_breakpoints (void) | |
6123 | { | |
6124 | struct breakpoint *b, *b_tmp; | |
6125 | ||
6126 | ALL_BREAKPOINTS_SAFE (b, b_tmp) | |
6127 | if (b->type == bp_jit_event | |
6128 | && b->loc->pspace == current_program_space) | |
6129 | delete_breakpoint (b); | |
6130 | } | |
6131 | ||
cae688ec JJ |
6132 | void |
6133 | remove_solib_event_breakpoints (void) | |
6134 | { | |
35df4500 | 6135 | struct breakpoint *b, *b_tmp; |
cae688ec | 6136 | |
35df4500 | 6137 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
6c95b8df PA |
6138 | if (b->type == bp_shlib_event |
6139 | && b->loc->pspace == current_program_space) | |
cae688ec JJ |
6140 | delete_breakpoint (b); |
6141 | } | |
6142 | ||
6143 | struct breakpoint * | |
a6d9a66e | 6144 | create_solib_event_breakpoint (struct gdbarch *gdbarch, CORE_ADDR address) |
cae688ec JJ |
6145 | { |
6146 | struct breakpoint *b; | |
6147 | ||
a6d9a66e | 6148 | b = create_internal_breakpoint (gdbarch, address, bp_shlib_event); |
b60e7edf | 6149 | update_global_location_list_nothrow (1); |
cae688ec JJ |
6150 | return b; |
6151 | } | |
6152 | ||
6153 | /* Disable any breakpoints that are on code in shared libraries. Only | |
6154 | apply to enabled breakpoints, disabled ones can just stay disabled. */ | |
6155 | ||
6156 | void | |
cb851954 | 6157 | disable_breakpoints_in_shlibs (void) |
cae688ec | 6158 | { |
876fa593 | 6159 | struct bp_location *loc, **locp_tmp; |
cae688ec | 6160 | |
876fa593 | 6161 | ALL_BP_LOCATIONS (loc, locp_tmp) |
cae688ec | 6162 | { |
2bdf28a0 | 6163 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6164 | struct breakpoint *b = loc->owner; |
2bdf28a0 | 6165 | |
4a64f543 MS |
6166 | /* We apply the check to all breakpoints, including disabled for |
6167 | those with loc->duplicate set. This is so that when breakpoint | |
6168 | becomes enabled, or the duplicate is removed, gdb will try to | |
6169 | insert all breakpoints. If we don't set shlib_disabled here, | |
6170 | we'll try to insert those breakpoints and fail. */ | |
1042e4c0 | 6171 | if (((b->type == bp_breakpoint) |
508ccb1f | 6172 | || (b->type == bp_jit_event) |
1042e4c0 | 6173 | || (b->type == bp_hardware_breakpoint) |
d77f58be | 6174 | || (is_tracepoint (b))) |
6c95b8df | 6175 | && loc->pspace == current_program_space |
0d381245 | 6176 | && !loc->shlib_disabled |
a77053c2 | 6177 | #ifdef PC_SOLIB |
0d381245 | 6178 | && PC_SOLIB (loc->address) |
a77053c2 | 6179 | #else |
6c95b8df | 6180 | && solib_name_from_address (loc->pspace, loc->address) |
a77053c2 MK |
6181 | #endif |
6182 | ) | |
0d381245 VP |
6183 | { |
6184 | loc->shlib_disabled = 1; | |
6185 | } | |
cae688ec JJ |
6186 | } |
6187 | } | |
6188 | ||
7a9dd1b2 | 6189 | /* Disable any breakpoints that are in an unloaded shared library. |
4a64f543 MS |
6190 | Only apply to enabled breakpoints, disabled ones can just stay |
6191 | disabled. */ | |
84acb35a | 6192 | |
75149521 | 6193 | static void |
84acb35a JJ |
6194 | disable_breakpoints_in_unloaded_shlib (struct so_list *solib) |
6195 | { | |
876fa593 | 6196 | struct bp_location *loc, **locp_tmp; |
84acb35a JJ |
6197 | int disabled_shlib_breaks = 0; |
6198 | ||
c86cf029 VP |
6199 | /* SunOS a.out shared libraries are always mapped, so do not |
6200 | disable breakpoints; they will only be reported as unloaded | |
6201 | through clear_solib when GDB discards its shared library | |
6202 | list. See clear_solib for more information. */ | |
6203 | if (exec_bfd != NULL | |
6204 | && bfd_get_flavour (exec_bfd) == bfd_target_aout_flavour) | |
6205 | return; | |
6206 | ||
876fa593 | 6207 | ALL_BP_LOCATIONS (loc, locp_tmp) |
84acb35a | 6208 | { |
2bdf28a0 | 6209 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always non-NULL. */ |
0d381245 | 6210 | struct breakpoint *b = loc->owner; |
cc59ec59 | 6211 | |
0d381245 VP |
6212 | if ((loc->loc_type == bp_loc_hardware_breakpoint |
6213 | || loc->loc_type == bp_loc_software_breakpoint) | |
6c95b8df | 6214 | && solib->pspace == loc->pspace |
e2dd7057 | 6215 | && !loc->shlib_disabled |
508ccb1f TT |
6216 | && (b->type == bp_breakpoint |
6217 | || b->type == bp_jit_event | |
6218 | || b->type == bp_hardware_breakpoint) | |
e2dd7057 | 6219 | && solib_contains_address_p (solib, loc->address)) |
84acb35a | 6220 | { |
e2dd7057 PP |
6221 | loc->shlib_disabled = 1; |
6222 | /* At this point, we cannot rely on remove_breakpoint | |
6223 | succeeding so we must mark the breakpoint as not inserted | |
6224 | to prevent future errors occurring in remove_breakpoints. */ | |
6225 | loc->inserted = 0; | |
8d3788bd VP |
6226 | |
6227 | /* This may cause duplicate notifications for the same breakpoint. */ | |
6228 | observer_notify_breakpoint_modified (b); | |
6229 | ||
e2dd7057 PP |
6230 | if (!disabled_shlib_breaks) |
6231 | { | |
6232 | target_terminal_ours_for_output (); | |
3e43a32a MS |
6233 | warning (_("Temporarily disabling breakpoints " |
6234 | "for unloaded shared library \"%s\""), | |
e2dd7057 | 6235 | solib->so_name); |
84acb35a | 6236 | } |
e2dd7057 | 6237 | disabled_shlib_breaks = 1; |
84acb35a JJ |
6238 | } |
6239 | } | |
84acb35a JJ |
6240 | } |
6241 | ||
ce78b96d JB |
6242 | /* FORK & VFORK catchpoints. */ |
6243 | ||
4a64f543 MS |
6244 | /* Implement the "insert" breakpoint_ops method for fork |
6245 | catchpoints. */ | |
ce78b96d | 6246 | |
77b06cd7 TJB |
6247 | static int |
6248 | insert_catch_fork (struct bp_location *bl) | |
ce78b96d | 6249 | { |
77b06cd7 | 6250 | return target_insert_fork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6251 | } |
6252 | ||
4a64f543 MS |
6253 | /* Implement the "remove" breakpoint_ops method for fork |
6254 | catchpoints. */ | |
ce78b96d JB |
6255 | |
6256 | static int | |
77b06cd7 | 6257 | remove_catch_fork (struct bp_location *bl) |
ce78b96d JB |
6258 | { |
6259 | return target_remove_fork_catchpoint (PIDGET (inferior_ptid)); | |
6260 | } | |
6261 | ||
6262 | /* Implement the "breakpoint_hit" breakpoint_ops method for fork | |
6263 | catchpoints. */ | |
6264 | ||
6265 | static int | |
f1310107 TJB |
6266 | breakpoint_hit_catch_fork (const struct bp_location *bl, |
6267 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6268 | { |
f1310107 | 6269 | return inferior_has_forked (inferior_ptid, &bl->owner->forked_inferior_pid); |
ce78b96d JB |
6270 | } |
6271 | ||
4a64f543 MS |
6272 | /* Implement the "print_it" breakpoint_ops method for fork |
6273 | catchpoints. */ | |
ce78b96d JB |
6274 | |
6275 | static enum print_stop_action | |
6276 | print_it_catch_fork (struct breakpoint *b) | |
6277 | { | |
6278 | annotate_catchpoint (b->number); | |
6279 | printf_filtered (_("\nCatchpoint %d (forked process %d), "), | |
6280 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6281 | return PRINT_SRC_AND_LOC; | |
6282 | } | |
6283 | ||
4a64f543 MS |
6284 | /* Implement the "print_one" breakpoint_ops method for fork |
6285 | catchpoints. */ | |
ce78b96d JB |
6286 | |
6287 | static void | |
a6d9a66e | 6288 | print_one_catch_fork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6289 | { |
79a45b7d TT |
6290 | struct value_print_options opts; |
6291 | ||
6292 | get_user_print_options (&opts); | |
6293 | ||
4a64f543 MS |
6294 | /* Field 4, the address, is omitted (which makes the columns not |
6295 | line up too nicely with the headers, but the effect is relatively | |
6296 | readable). */ | |
79a45b7d | 6297 | if (opts.addressprint) |
ce78b96d JB |
6298 | ui_out_field_skip (uiout, "addr"); |
6299 | annotate_field (5); | |
6300 | ui_out_text (uiout, "fork"); | |
6301 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6302 | { | |
6303 | ui_out_text (uiout, ", process "); | |
6304 | ui_out_field_int (uiout, "what", | |
6305 | ptid_get_pid (b->forked_inferior_pid)); | |
6306 | ui_out_spaces (uiout, 1); | |
6307 | } | |
6308 | } | |
6309 | ||
6310 | /* Implement the "print_mention" breakpoint_ops method for fork | |
6311 | catchpoints. */ | |
6312 | ||
6313 | static void | |
6314 | print_mention_catch_fork (struct breakpoint *b) | |
6315 | { | |
6316 | printf_filtered (_("Catchpoint %d (fork)"), b->number); | |
6317 | } | |
6318 | ||
6149aea9 PA |
6319 | /* Implement the "print_recreate" breakpoint_ops method for fork |
6320 | catchpoints. */ | |
6321 | ||
6322 | static void | |
6323 | print_recreate_catch_fork (struct breakpoint *b, struct ui_file *fp) | |
6324 | { | |
6325 | fprintf_unfiltered (fp, "catch fork"); | |
6326 | } | |
6327 | ||
ce78b96d JB |
6328 | /* The breakpoint_ops structure to be used in fork catchpoints. */ |
6329 | ||
6330 | static struct breakpoint_ops catch_fork_breakpoint_ops = | |
6331 | { | |
6332 | insert_catch_fork, | |
6333 | remove_catch_fork, | |
6334 | breakpoint_hit_catch_fork, | |
e09342b5 | 6335 | NULL, /* resources_needed */ |
9c06b0b4 | 6336 | NULL, /* works_in_software_mode */ |
ce78b96d JB |
6337 | print_it_catch_fork, |
6338 | print_one_catch_fork, | |
f1310107 | 6339 | NULL, /* print_one_detail */ |
6149aea9 PA |
6340 | print_mention_catch_fork, |
6341 | print_recreate_catch_fork | |
ce78b96d JB |
6342 | }; |
6343 | ||
4a64f543 MS |
6344 | /* Implement the "insert" breakpoint_ops method for vfork |
6345 | catchpoints. */ | |
ce78b96d | 6346 | |
77b06cd7 TJB |
6347 | static int |
6348 | insert_catch_vfork (struct bp_location *bl) | |
ce78b96d | 6349 | { |
77b06cd7 | 6350 | return target_insert_vfork_catchpoint (PIDGET (inferior_ptid)); |
ce78b96d JB |
6351 | } |
6352 | ||
4a64f543 MS |
6353 | /* Implement the "remove" breakpoint_ops method for vfork |
6354 | catchpoints. */ | |
ce78b96d JB |
6355 | |
6356 | static int | |
77b06cd7 | 6357 | remove_catch_vfork (struct bp_location *bl) |
ce78b96d JB |
6358 | { |
6359 | return target_remove_vfork_catchpoint (PIDGET (inferior_ptid)); | |
6360 | } | |
6361 | ||
6362 | /* Implement the "breakpoint_hit" breakpoint_ops method for vfork | |
6363 | catchpoints. */ | |
6364 | ||
6365 | static int | |
f1310107 TJB |
6366 | breakpoint_hit_catch_vfork (const struct bp_location *bl, |
6367 | struct address_space *aspace, CORE_ADDR bp_addr) | |
ce78b96d | 6368 | { |
f1310107 | 6369 | return inferior_has_vforked (inferior_ptid, &bl->owner->forked_inferior_pid); |
ce78b96d JB |
6370 | } |
6371 | ||
4a64f543 MS |
6372 | /* Implement the "print_it" breakpoint_ops method for vfork |
6373 | catchpoints. */ | |
ce78b96d JB |
6374 | |
6375 | static enum print_stop_action | |
6376 | print_it_catch_vfork (struct breakpoint *b) | |
6377 | { | |
6378 | annotate_catchpoint (b->number); | |
6379 | printf_filtered (_("\nCatchpoint %d (vforked process %d), "), | |
6380 | b->number, ptid_get_pid (b->forked_inferior_pid)); | |
6381 | return PRINT_SRC_AND_LOC; | |
6382 | } | |
6383 | ||
4a64f543 MS |
6384 | /* Implement the "print_one" breakpoint_ops method for vfork |
6385 | catchpoints. */ | |
ce78b96d JB |
6386 | |
6387 | static void | |
a6d9a66e | 6388 | print_one_catch_vfork (struct breakpoint *b, struct bp_location **last_loc) |
ce78b96d | 6389 | { |
79a45b7d TT |
6390 | struct value_print_options opts; |
6391 | ||
6392 | get_user_print_options (&opts); | |
4a64f543 MS |
6393 | /* Field 4, the address, is omitted (which makes the columns not |
6394 | line up too nicely with the headers, but the effect is relatively | |
6395 | readable). */ | |
79a45b7d | 6396 | if (opts.addressprint) |
ce78b96d JB |
6397 | ui_out_field_skip (uiout, "addr"); |
6398 | annotate_field (5); | |
6399 | ui_out_text (uiout, "vfork"); | |
6400 | if (!ptid_equal (b->forked_inferior_pid, null_ptid)) | |
6401 | { | |
6402 | ui_out_text (uiout, ", process "); | |
6403 | ui_out_field_int (uiout, "what", | |
6404 | ptid_get_pid (b->forked_inferior_pid)); | |
6405 | ui_out_spaces (uiout, 1); | |
6406 | } | |
6407 | } | |
6408 | ||
6409 | /* Implement the "print_mention" breakpoint_ops method for vfork | |
6410 | catchpoints. */ | |
6411 | ||
6412 | static void | |
6413 | print_mention_catch_vfork (struct breakpoint *b) | |
6414 | { | |
6415 | printf_filtered (_("Catchpoint %d (vfork)"), b->number); | |
6416 | } | |
6417 | ||
6149aea9 PA |
6418 | /* Implement the "print_recreate" breakpoint_ops method for vfork |
6419 | catchpoints. */ | |
6420 | ||
6421 | static void | |
6422 | print_recreate_catch_vfork (struct breakpoint *b, struct ui_file *fp) | |
6423 | { | |
6424 | fprintf_unfiltered (fp, "catch vfork"); | |
6425 | } | |
6426 | ||
ce78b96d JB |
6427 | /* The breakpoint_ops structure to be used in vfork catchpoints. */ |
6428 | ||
6429 | static struct breakpoint_ops catch_vfork_breakpoint_ops = | |
6430 | { | |
6431 | insert_catch_vfork, | |
6432 | remove_catch_vfork, | |
6433 | breakpoint_hit_catch_vfork, | |
e09342b5 | 6434 | NULL, /* resources_needed */ |
9c06b0b4 | 6435 | NULL, /* works_in_software_mode */ |
ce78b96d JB |
6436 | print_it_catch_vfork, |
6437 | print_one_catch_vfork, | |
f1310107 | 6438 | NULL, /* print_one_detail */ |
6149aea9 PA |
6439 | print_mention_catch_vfork, |
6440 | print_recreate_catch_vfork | |
ce78b96d JB |
6441 | }; |
6442 | ||
a96d9b2e SDJ |
6443 | /* Implement the "insert" breakpoint_ops method for syscall |
6444 | catchpoints. */ | |
6445 | ||
77b06cd7 TJB |
6446 | static int |
6447 | insert_catch_syscall (struct bp_location *bl) | |
a96d9b2e SDJ |
6448 | { |
6449 | struct inferior *inf = current_inferior (); | |
6450 | ||
6451 | ++inf->total_syscalls_count; | |
77b06cd7 | 6452 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6453 | ++inf->any_syscall_count; |
6454 | else | |
6455 | { | |
6456 | int i, iter; | |
cc59ec59 | 6457 | |
a96d9b2e | 6458 | for (i = 0; |
77b06cd7 | 6459 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6460 | i++) |
6461 | { | |
6462 | int elem; | |
cc59ec59 | 6463 | |
a96d9b2e SDJ |
6464 | if (iter >= VEC_length (int, inf->syscalls_counts)) |
6465 | { | |
6466 | int old_size = VEC_length (int, inf->syscalls_counts); | |
3e43a32a MS |
6467 | uintptr_t vec_addr_offset |
6468 | = old_size * ((uintptr_t) sizeof (int)); | |
a96d9b2e SDJ |
6469 | uintptr_t vec_addr; |
6470 | VEC_safe_grow (int, inf->syscalls_counts, iter + 1); | |
6471 | vec_addr = (uintptr_t) VEC_address (int, inf->syscalls_counts) + | |
6472 | vec_addr_offset; | |
6473 | memset ((void *) vec_addr, 0, | |
6474 | (iter + 1 - old_size) * sizeof (int)); | |
6475 | } | |
6476 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6477 | VEC_replace (int, inf->syscalls_counts, iter, ++elem); | |
6478 | } | |
6479 | } | |
6480 | ||
77b06cd7 TJB |
6481 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), |
6482 | inf->total_syscalls_count != 0, | |
6483 | inf->any_syscall_count, | |
6484 | VEC_length (int, inf->syscalls_counts), | |
6485 | VEC_address (int, inf->syscalls_counts)); | |
a96d9b2e SDJ |
6486 | } |
6487 | ||
6488 | /* Implement the "remove" breakpoint_ops method for syscall | |
6489 | catchpoints. */ | |
6490 | ||
6491 | static int | |
77b06cd7 | 6492 | remove_catch_syscall (struct bp_location *bl) |
a96d9b2e SDJ |
6493 | { |
6494 | struct inferior *inf = current_inferior (); | |
6495 | ||
6496 | --inf->total_syscalls_count; | |
77b06cd7 | 6497 | if (!bl->owner->syscalls_to_be_caught) |
a96d9b2e SDJ |
6498 | --inf->any_syscall_count; |
6499 | else | |
6500 | { | |
6501 | int i, iter; | |
cc59ec59 | 6502 | |
a96d9b2e | 6503 | for (i = 0; |
77b06cd7 | 6504 | VEC_iterate (int, bl->owner->syscalls_to_be_caught, i, iter); |
a96d9b2e SDJ |
6505 | i++) |
6506 | { | |
6507 | int elem; | |
6508 | if (iter >= VEC_length (int, inf->syscalls_counts)) | |
6509 | /* Shouldn't happen. */ | |
6510 | continue; | |
6511 | elem = VEC_index (int, inf->syscalls_counts, iter); | |
6512 | VEC_replace (int, inf->syscalls_counts, iter, --elem); | |
6513 | } | |
6514 | } | |
6515 | ||
6516 | return target_set_syscall_catchpoint (PIDGET (inferior_ptid), | |
6517 | inf->total_syscalls_count != 0, | |
6518 | inf->any_syscall_count, | |
6519 | VEC_length (int, inf->syscalls_counts), | |
3e43a32a MS |
6520 | VEC_address (int, |
6521 | inf->syscalls_counts)); | |
a96d9b2e SDJ |
6522 | } |
6523 | ||
6524 | /* Implement the "breakpoint_hit" breakpoint_ops method for syscall | |
6525 | catchpoints. */ | |
6526 | ||
6527 | static int | |
f1310107 TJB |
6528 | breakpoint_hit_catch_syscall (const struct bp_location *bl, |
6529 | struct address_space *aspace, CORE_ADDR bp_addr) | |
a96d9b2e | 6530 | { |
4a64f543 MS |
6531 | /* We must check if we are catching specific syscalls in this |
6532 | breakpoint. If we are, then we must guarantee that the called | |
6533 | syscall is the same syscall we are catching. */ | |
a96d9b2e | 6534 | int syscall_number = 0; |
f1310107 | 6535 | const struct breakpoint *b = bl->owner; |
a96d9b2e SDJ |
6536 | |
6537 | if (!inferior_has_called_syscall (inferior_ptid, &syscall_number)) | |
6538 | return 0; | |
6539 | ||
6540 | /* Now, checking if the syscall is the same. */ | |
6541 | if (b->syscalls_to_be_caught) | |
6542 | { | |
6543 | int i, iter; | |
cc59ec59 | 6544 | |
a96d9b2e SDJ |
6545 | for (i = 0; |
6546 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6547 | i++) | |
6548 | if (syscall_number == iter) | |
6549 | break; | |
6550 | /* Not the same. */ | |
6551 | if (!iter) | |
6552 | return 0; | |
6553 | } | |
6554 | ||
6555 | return 1; | |
6556 | } | |
6557 | ||
6558 | /* Implement the "print_it" breakpoint_ops method for syscall | |
6559 | catchpoints. */ | |
6560 | ||
6561 | static enum print_stop_action | |
6562 | print_it_catch_syscall (struct breakpoint *b) | |
6563 | { | |
6564 | /* These are needed because we want to know in which state a | |
6565 | syscall is. It can be in the TARGET_WAITKIND_SYSCALL_ENTRY | |
6566 | or TARGET_WAITKIND_SYSCALL_RETURN, and depending on it we | |
6567 | must print "called syscall" or "returned from syscall". */ | |
6568 | ptid_t ptid; | |
6569 | struct target_waitstatus last; | |
6570 | struct syscall s; | |
6571 | struct cleanup *old_chain; | |
6572 | char *syscall_id; | |
6573 | ||
6574 | get_last_target_status (&ptid, &last); | |
6575 | ||
6576 | get_syscall_by_number (last.value.syscall_number, &s); | |
6577 | ||
6578 | annotate_catchpoint (b->number); | |
6579 | ||
6580 | if (s.name == NULL) | |
6581 | syscall_id = xstrprintf ("%d", last.value.syscall_number); | |
6582 | else | |
6583 | syscall_id = xstrprintf ("'%s'", s.name); | |
6584 | ||
6585 | old_chain = make_cleanup (xfree, syscall_id); | |
6586 | ||
6587 | if (last.kind == TARGET_WAITKIND_SYSCALL_ENTRY) | |
6588 | printf_filtered (_("\nCatchpoint %d (call to syscall %s), "), | |
6589 | b->number, syscall_id); | |
6590 | else if (last.kind == TARGET_WAITKIND_SYSCALL_RETURN) | |
6591 | printf_filtered (_("\nCatchpoint %d (returned from syscall %s), "), | |
6592 | b->number, syscall_id); | |
6593 | ||
6594 | do_cleanups (old_chain); | |
6595 | ||
6596 | return PRINT_SRC_AND_LOC; | |
6597 | } | |
6598 | ||
6599 | /* Implement the "print_one" breakpoint_ops method for syscall | |
6600 | catchpoints. */ | |
6601 | ||
6602 | static void | |
6603 | print_one_catch_syscall (struct breakpoint *b, | |
f1310107 | 6604 | struct bp_location **last_loc) |
a96d9b2e SDJ |
6605 | { |
6606 | struct value_print_options opts; | |
6607 | ||
6608 | get_user_print_options (&opts); | |
4a64f543 MS |
6609 | /* Field 4, the address, is omitted (which makes the columns not |
6610 | line up too nicely with the headers, but the effect is relatively | |
6611 | readable). */ | |
a96d9b2e SDJ |
6612 | if (opts.addressprint) |
6613 | ui_out_field_skip (uiout, "addr"); | |
6614 | annotate_field (5); | |
6615 | ||
6616 | if (b->syscalls_to_be_caught | |
6617 | && VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6618 | ui_out_text (uiout, "syscalls \""); | |
6619 | else | |
6620 | ui_out_text (uiout, "syscall \""); | |
6621 | ||
6622 | if (b->syscalls_to_be_caught) | |
6623 | { | |
6624 | int i, iter; | |
6625 | char *text = xstrprintf ("%s", ""); | |
cc59ec59 | 6626 | |
a96d9b2e SDJ |
6627 | for (i = 0; |
6628 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6629 | i++) | |
6630 | { | |
6631 | char *x = text; | |
6632 | struct syscall s; | |
6633 | get_syscall_by_number (iter, &s); | |
6634 | ||
6635 | if (s.name != NULL) | |
6636 | text = xstrprintf ("%s%s, ", text, s.name); | |
6637 | else | |
6638 | text = xstrprintf ("%s%d, ", text, iter); | |
6639 | ||
6640 | /* We have to xfree the last 'text' (now stored at 'x') | |
6641 | because xstrprintf dinamically allocates new space for it | |
6642 | on every call. */ | |
6643 | xfree (x); | |
6644 | } | |
6645 | /* Remove the last comma. */ | |
6646 | text[strlen (text) - 2] = '\0'; | |
6647 | ui_out_field_string (uiout, "what", text); | |
6648 | } | |
6649 | else | |
6650 | ui_out_field_string (uiout, "what", "<any syscall>"); | |
6651 | ui_out_text (uiout, "\" "); | |
6652 | } | |
6653 | ||
6654 | /* Implement the "print_mention" breakpoint_ops method for syscall | |
6655 | catchpoints. */ | |
6656 | ||
6657 | static void | |
6658 | print_mention_catch_syscall (struct breakpoint *b) | |
6659 | { | |
6660 | if (b->syscalls_to_be_caught) | |
6661 | { | |
6662 | int i, iter; | |
6663 | ||
6664 | if (VEC_length (int, b->syscalls_to_be_caught) > 1) | |
6665 | printf_filtered (_("Catchpoint %d (syscalls"), b->number); | |
6666 | else | |
6667 | printf_filtered (_("Catchpoint %d (syscall"), b->number); | |
6668 | ||
6669 | for (i = 0; | |
6670 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6671 | i++) | |
6672 | { | |
6673 | struct syscall s; | |
6674 | get_syscall_by_number (iter, &s); | |
6675 | ||
6676 | if (s.name) | |
6677 | printf_filtered (" '%s' [%d]", s.name, s.number); | |
6678 | else | |
6679 | printf_filtered (" %d", s.number); | |
6680 | } | |
6681 | printf_filtered (")"); | |
6682 | } | |
6683 | else | |
6684 | printf_filtered (_("Catchpoint %d (any syscall)"), | |
6685 | b->number); | |
6686 | } | |
6687 | ||
6149aea9 PA |
6688 | /* Implement the "print_recreate" breakpoint_ops method for syscall |
6689 | catchpoints. */ | |
6690 | ||
6691 | static void | |
6692 | print_recreate_catch_syscall (struct breakpoint *b, struct ui_file *fp) | |
6693 | { | |
6694 | fprintf_unfiltered (fp, "catch syscall"); | |
6695 | ||
6696 | if (b->syscalls_to_be_caught) | |
6697 | { | |
6698 | int i, iter; | |
6699 | ||
6700 | for (i = 0; | |
6701 | VEC_iterate (int, b->syscalls_to_be_caught, i, iter); | |
6702 | i++) | |
6703 | { | |
6704 | struct syscall s; | |
6705 | ||
6706 | get_syscall_by_number (iter, &s); | |
6707 | if (s.name) | |
6708 | fprintf_unfiltered (fp, " %s", s.name); | |
6709 | else | |
6710 | fprintf_unfiltered (fp, " %d", s.number); | |
6711 | } | |
6712 | } | |
6713 | } | |
6714 | ||
a96d9b2e SDJ |
6715 | /* The breakpoint_ops structure to be used in syscall catchpoints. */ |
6716 | ||
6717 | static struct breakpoint_ops catch_syscall_breakpoint_ops = | |
6718 | { | |
6719 | insert_catch_syscall, | |
6720 | remove_catch_syscall, | |
6721 | breakpoint_hit_catch_syscall, | |
e09342b5 | 6722 | NULL, /* resources_needed */ |
9c06b0b4 | 6723 | NULL, /* works_in_software_mode */ |
a96d9b2e SDJ |
6724 | print_it_catch_syscall, |
6725 | print_one_catch_syscall, | |
f1310107 | 6726 | NULL, /* print_one_detail */ |
6149aea9 PA |
6727 | print_mention_catch_syscall, |
6728 | print_recreate_catch_syscall | |
a96d9b2e SDJ |
6729 | }; |
6730 | ||
6731 | /* Returns non-zero if 'b' is a syscall catchpoint. */ | |
6732 | ||
6733 | static int | |
6734 | syscall_catchpoint_p (struct breakpoint *b) | |
6735 | { | |
6736 | return (b->ops == &catch_syscall_breakpoint_ops); | |
6737 | } | |
6738 | ||
6739 | /* Create a new breakpoint of the bp_catchpoint kind and return it, | |
6740 | but does NOT mention it nor update the global location list. | |
6741 | This is useful if you need to fill more fields in the | |
6742 | struct breakpoint before calling mention. | |
ce78b96d JB |
6743 | |
6744 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6745 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6746 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6747 | to the catchpoint. */ | |
6748 | ||
6749 | static struct breakpoint * | |
a96d9b2e SDJ |
6750 | create_catchpoint_without_mention (struct gdbarch *gdbarch, int tempflag, |
6751 | char *cond_string, | |
6752 | struct breakpoint_ops *ops) | |
c906108c | 6753 | { |
c5aa993b JM |
6754 | struct symtab_and_line sal; |
6755 | struct breakpoint *b; | |
c5aa993b | 6756 | |
fe39c653 | 6757 | init_sal (&sal); |
6c95b8df | 6758 | sal.pspace = current_program_space; |
c5aa993b | 6759 | |
a6d9a66e | 6760 | b = set_raw_breakpoint (gdbarch, sal, bp_catchpoint); |
c906108c SS |
6761 | set_breakpoint_count (breakpoint_count + 1); |
6762 | b->number = breakpoint_count; | |
ce78b96d | 6763 | |
1b36a34b | 6764 | b->cond_string = (cond_string == NULL) ? NULL : xstrdup (cond_string); |
ce78b96d | 6765 | b->thread = -1; |
c906108c | 6766 | b->addr_string = NULL; |
b5de0fa7 EZ |
6767 | b->enable_state = bp_enabled; |
6768 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
ce78b96d | 6769 | b->ops = ops; |
c5aa993b | 6770 | |
a96d9b2e SDJ |
6771 | return b; |
6772 | } | |
6773 | ||
6774 | /* Create a new breakpoint of the bp_catchpoint kind and return it. | |
6775 | ||
6776 | If TEMPFLAG is non-zero, then make the breakpoint temporary. | |
6777 | If COND_STRING is not NULL, then store it in the breakpoint. | |
6778 | OPS, if not NULL, is the breakpoint_ops structure associated | |
6779 | to the catchpoint. */ | |
6780 | ||
6781 | static struct breakpoint * | |
6782 | create_catchpoint (struct gdbarch *gdbarch, int tempflag, | |
6783 | char *cond_string, struct breakpoint_ops *ops) | |
6784 | { | |
6785 | struct breakpoint *b = | |
6786 | create_catchpoint_without_mention (gdbarch, tempflag, cond_string, ops); | |
6787 | ||
c906108c | 6788 | mention (b); |
8d3788bd | 6789 | observer_notify_breakpoint_created (b); |
ce78b96d | 6790 | update_global_location_list (1); |
c906108c | 6791 | |
ce78b96d | 6792 | return b; |
c906108c | 6793 | } |
c5aa993b | 6794 | |
9b70b993 | 6795 | static void |
a6d9a66e UW |
6796 | create_fork_vfork_event_catchpoint (struct gdbarch *gdbarch, |
6797 | int tempflag, char *cond_string, | |
ce78b96d | 6798 | struct breakpoint_ops *ops) |
c906108c | 6799 | { |
a6d9a66e UW |
6800 | struct breakpoint *b |
6801 | = create_catchpoint (gdbarch, tempflag, cond_string, ops); | |
ce78b96d JB |
6802 | |
6803 | /* FIXME: We should put this information in a breakpoint private data | |
6804 | area. */ | |
6805 | b->forked_inferior_pid = null_ptid; | |
c906108c SS |
6806 | } |
6807 | ||
fe798b75 JB |
6808 | /* Exec catchpoints. */ |
6809 | ||
77b06cd7 TJB |
6810 | static int |
6811 | insert_catch_exec (struct bp_location *bl) | |
c906108c | 6812 | { |
77b06cd7 | 6813 | return target_insert_exec_catchpoint (PIDGET (inferior_ptid)); |
fe798b75 | 6814 | } |
c906108c | 6815 | |
fe798b75 | 6816 | static int |
77b06cd7 | 6817 | remove_catch_exec (struct bp_location *bl) |
fe798b75 JB |
6818 | { |
6819 | return target_remove_exec_catchpoint (PIDGET (inferior_ptid)); | |
6820 | } | |
c906108c | 6821 | |
fe798b75 | 6822 | static int |
f1310107 TJB |
6823 | breakpoint_hit_catch_exec (const struct bp_location *bl, |
6824 | struct address_space *aspace, CORE_ADDR bp_addr) | |
fe798b75 | 6825 | { |
f1310107 | 6826 | return inferior_has_execd (inferior_ptid, &bl->owner->exec_pathname); |
fe798b75 | 6827 | } |
c906108c | 6828 | |
fe798b75 JB |
6829 | static enum print_stop_action |
6830 | print_it_catch_exec (struct breakpoint *b) | |
6831 | { | |
6832 | annotate_catchpoint (b->number); | |
6833 | printf_filtered (_("\nCatchpoint %d (exec'd %s), "), b->number, | |
6834 | b->exec_pathname); | |
6835 | return PRINT_SRC_AND_LOC; | |
c906108c SS |
6836 | } |
6837 | ||
fe798b75 | 6838 | static void |
a6d9a66e | 6839 | print_one_catch_exec (struct breakpoint *b, struct bp_location **last_loc) |
fe798b75 JB |
6840 | { |
6841 | struct value_print_options opts; | |
6842 | ||
6843 | get_user_print_options (&opts); | |
6844 | ||
6845 | /* Field 4, the address, is omitted (which makes the columns | |
6846 | not line up too nicely with the headers, but the effect | |
6847 | is relatively readable). */ | |
6848 | if (opts.addressprint) | |
6849 | ui_out_field_skip (uiout, "addr"); | |
6850 | annotate_field (5); | |
6851 | ui_out_text (uiout, "exec"); | |
6852 | if (b->exec_pathname != NULL) | |
6853 | { | |
6854 | ui_out_text (uiout, ", program \""); | |
6855 | ui_out_field_string (uiout, "what", b->exec_pathname); | |
6856 | ui_out_text (uiout, "\" "); | |
6857 | } | |
6858 | } | |
6859 | ||
6860 | static void | |
6861 | print_mention_catch_exec (struct breakpoint *b) | |
6862 | { | |
6863 | printf_filtered (_("Catchpoint %d (exec)"), b->number); | |
6864 | } | |
6865 | ||
6149aea9 PA |
6866 | /* Implement the "print_recreate" breakpoint_ops method for exec |
6867 | catchpoints. */ | |
6868 | ||
6869 | static void | |
6870 | print_recreate_catch_exec (struct breakpoint *b, struct ui_file *fp) | |
6871 | { | |
6872 | fprintf_unfiltered (fp, "catch exec"); | |
6873 | } | |
6874 | ||
fe798b75 JB |
6875 | static struct breakpoint_ops catch_exec_breakpoint_ops = |
6876 | { | |
6877 | insert_catch_exec, | |
6878 | remove_catch_exec, | |
6879 | breakpoint_hit_catch_exec, | |
e09342b5 | 6880 | NULL, /* resources_needed */ |
9c06b0b4 | 6881 | NULL, /* works_in_software_mode */ |
fe798b75 JB |
6882 | print_it_catch_exec, |
6883 | print_one_catch_exec, | |
f1310107 | 6884 | NULL, /* print_one_detail */ |
6149aea9 PA |
6885 | print_mention_catch_exec, |
6886 | print_recreate_catch_exec | |
fe798b75 JB |
6887 | }; |
6888 | ||
a96d9b2e SDJ |
6889 | static void |
6890 | create_syscall_event_catchpoint (int tempflag, VEC(int) *filter, | |
6891 | struct breakpoint_ops *ops) | |
6892 | { | |
6893 | struct gdbarch *gdbarch = get_current_arch (); | |
6894 | struct breakpoint *b = | |
6895 | create_catchpoint_without_mention (gdbarch, tempflag, NULL, ops); | |
6896 | ||
6897 | b->syscalls_to_be_caught = filter; | |
6898 | ||
6899 | /* Now, we have to mention the breakpoint and update the global | |
6900 | location list. */ | |
6901 | mention (b); | |
8d3788bd | 6902 | observer_notify_breakpoint_created (b); |
a96d9b2e SDJ |
6903 | update_global_location_list (1); |
6904 | } | |
6905 | ||
c906108c | 6906 | static int |
fba45db2 | 6907 | hw_breakpoint_used_count (void) |
c906108c | 6908 | { |
c906108c | 6909 | int i = 0; |
f1310107 TJB |
6910 | struct breakpoint *b; |
6911 | struct bp_location *bl; | |
c906108c SS |
6912 | |
6913 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6914 | { |
d6b74ac4 | 6915 | if (b->type == bp_hardware_breakpoint && breakpoint_enabled (b)) |
f1310107 TJB |
6916 | for (bl = b->loc; bl; bl = bl->next) |
6917 | { | |
6918 | /* Special types of hardware breakpoints may use more than | |
6919 | one register. */ | |
6920 | if (b->ops && b->ops->resources_needed) | |
6921 | i += b->ops->resources_needed (bl); | |
6922 | else | |
6923 | i++; | |
6924 | } | |
c5aa993b | 6925 | } |
c906108c SS |
6926 | |
6927 | return i; | |
6928 | } | |
6929 | ||
6930 | static int | |
fba45db2 | 6931 | hw_watchpoint_used_count (enum bptype type, int *other_type_used) |
c906108c | 6932 | { |
c906108c | 6933 | int i = 0; |
e09342b5 TJB |
6934 | struct breakpoint *b; |
6935 | struct bp_location *bl; | |
c906108c SS |
6936 | |
6937 | *other_type_used = 0; | |
6938 | ALL_BREAKPOINTS (b) | |
e09342b5 TJB |
6939 | { |
6940 | if (!breakpoint_enabled (b)) | |
6941 | continue; | |
6942 | ||
c5aa993b | 6943 | if (b->type == type) |
e09342b5 TJB |
6944 | for (bl = b->loc; bl; bl = bl->next) |
6945 | { | |
6946 | /* Special types of hardware watchpoints may use more than | |
6947 | one register. */ | |
6948 | if (b->ops && b->ops->resources_needed) | |
6949 | i += b->ops->resources_needed (bl); | |
6950 | else | |
6951 | i++; | |
6952 | } | |
cc60f2e3 | 6953 | else if (is_hardware_watchpoint (b)) |
c5aa993b | 6954 | *other_type_used = 1; |
e09342b5 TJB |
6955 | } |
6956 | ||
c906108c SS |
6957 | return i; |
6958 | } | |
6959 | ||
c906108c | 6960 | void |
fba45db2 | 6961 | disable_watchpoints_before_interactive_call_start (void) |
c906108c | 6962 | { |
c5aa993b | 6963 | struct breakpoint *b; |
c906108c SS |
6964 | |
6965 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6966 | { |
cc60f2e3 | 6967 | if (is_watchpoint (b) && breakpoint_enabled (b)) |
c5aa993b | 6968 | { |
b5de0fa7 | 6969 | b->enable_state = bp_call_disabled; |
b60e7edf | 6970 | update_global_location_list (0); |
c5aa993b JM |
6971 | } |
6972 | } | |
c906108c SS |
6973 | } |
6974 | ||
6975 | void | |
fba45db2 | 6976 | enable_watchpoints_after_interactive_call_stop (void) |
c906108c | 6977 | { |
c5aa993b | 6978 | struct breakpoint *b; |
c906108c SS |
6979 | |
6980 | ALL_BREAKPOINTS (b) | |
c5aa993b | 6981 | { |
cc60f2e3 | 6982 | if (is_watchpoint (b) && b->enable_state == bp_call_disabled) |
c5aa993b | 6983 | { |
b5de0fa7 | 6984 | b->enable_state = bp_enabled; |
b60e7edf | 6985 | update_global_location_list (1); |
c5aa993b JM |
6986 | } |
6987 | } | |
c906108c SS |
6988 | } |
6989 | ||
8bea4e01 UW |
6990 | void |
6991 | disable_breakpoints_before_startup (void) | |
6992 | { | |
6993 | struct breakpoint *b; | |
6994 | int found = 0; | |
6995 | ||
6996 | ALL_BREAKPOINTS (b) | |
6997 | { | |
6c95b8df PA |
6998 | if (b->pspace != current_program_space) |
6999 | continue; | |
7000 | ||
8bea4e01 UW |
7001 | if ((b->type == bp_breakpoint |
7002 | || b->type == bp_hardware_breakpoint) | |
7003 | && breakpoint_enabled (b)) | |
7004 | { | |
7005 | b->enable_state = bp_startup_disabled; | |
7006 | found = 1; | |
7007 | } | |
7008 | } | |
7009 | ||
7010 | if (found) | |
7011 | update_global_location_list (0); | |
7012 | ||
6c95b8df | 7013 | current_program_space->executing_startup = 1; |
8bea4e01 UW |
7014 | } |
7015 | ||
7016 | void | |
7017 | enable_breakpoints_after_startup (void) | |
7018 | { | |
7019 | struct breakpoint *b; | |
7020 | int found = 0; | |
7021 | ||
6c95b8df | 7022 | current_program_space->executing_startup = 0; |
8bea4e01 UW |
7023 | |
7024 | ALL_BREAKPOINTS (b) | |
7025 | { | |
6c95b8df PA |
7026 | if (b->pspace != current_program_space) |
7027 | continue; | |
7028 | ||
8bea4e01 UW |
7029 | if ((b->type == bp_breakpoint |
7030 | || b->type == bp_hardware_breakpoint) | |
7031 | && b->enable_state == bp_startup_disabled) | |
7032 | { | |
7033 | b->enable_state = bp_enabled; | |
7034 | found = 1; | |
7035 | } | |
7036 | } | |
7037 | ||
7038 | if (found) | |
7039 | breakpoint_re_set (); | |
7040 | } | |
7041 | ||
c906108c SS |
7042 | |
7043 | /* Set a breakpoint that will evaporate an end of command | |
7044 | at address specified by SAL. | |
7045 | Restrict it to frame FRAME if FRAME is nonzero. */ | |
7046 | ||
7047 | struct breakpoint * | |
a6d9a66e UW |
7048 | set_momentary_breakpoint (struct gdbarch *gdbarch, struct symtab_and_line sal, |
7049 | struct frame_id frame_id, enum bptype type) | |
c906108c | 7050 | { |
52f0bd74 | 7051 | struct breakpoint *b; |
edb3359d DJ |
7052 | |
7053 | /* If FRAME_ID is valid, it should be a real frame, not an inlined | |
7054 | one. */ | |
7055 | gdb_assert (!frame_id_inlined_p (frame_id)); | |
7056 | ||
a6d9a66e | 7057 | b = set_raw_breakpoint (gdbarch, sal, type); |
b5de0fa7 EZ |
7058 | b->enable_state = bp_enabled; |
7059 | b->disposition = disp_donttouch; | |
818dd999 | 7060 | b->frame_id = frame_id; |
c906108c | 7061 | |
4a64f543 MS |
7062 | /* If we're debugging a multi-threaded program, then we want |
7063 | momentary breakpoints to be active in only a single thread of | |
7064 | control. */ | |
39f77062 KB |
7065 | if (in_thread_list (inferior_ptid)) |
7066 | b->thread = pid_to_thread_id (inferior_ptid); | |
c906108c | 7067 | |
b60e7edf | 7068 | update_global_location_list_nothrow (1); |
74960c60 | 7069 | |
c906108c SS |
7070 | return b; |
7071 | } | |
611c83ae | 7072 | |
e58b0e63 PA |
7073 | /* Make a deep copy of momentary breakpoint ORIG. Returns NULL if |
7074 | ORIG is NULL. */ | |
7075 | ||
7076 | struct breakpoint * | |
7077 | clone_momentary_breakpoint (struct breakpoint *orig) | |
7078 | { | |
7079 | struct breakpoint *copy; | |
7080 | ||
7081 | /* If there's nothing to clone, then return nothing. */ | |
7082 | if (orig == NULL) | |
7083 | return NULL; | |
7084 | ||
a6d9a66e | 7085 | copy = set_raw_breakpoint_without_location (orig->gdbarch, orig->type); |
e58b0e63 | 7086 | copy->loc = allocate_bp_location (copy); |
0e30163f | 7087 | set_breakpoint_location_function (copy->loc, 1); |
e58b0e63 | 7088 | |
a6d9a66e | 7089 | copy->loc->gdbarch = orig->loc->gdbarch; |
e58b0e63 PA |
7090 | copy->loc->requested_address = orig->loc->requested_address; |
7091 | copy->loc->address = orig->loc->address; | |
7092 | copy->loc->section = orig->loc->section; | |
6c95b8df | 7093 | copy->loc->pspace = orig->loc->pspace; |
e58b0e63 PA |
7094 | |
7095 | if (orig->source_file == NULL) | |
7096 | copy->source_file = NULL; | |
7097 | else | |
7098 | copy->source_file = xstrdup (orig->source_file); | |
7099 | ||
7100 | copy->line_number = orig->line_number; | |
7101 | copy->frame_id = orig->frame_id; | |
7102 | copy->thread = orig->thread; | |
6c95b8df | 7103 | copy->pspace = orig->pspace; |
e58b0e63 PA |
7104 | |
7105 | copy->enable_state = bp_enabled; | |
7106 | copy->disposition = disp_donttouch; | |
7107 | copy->number = internal_breakpoint_number--; | |
7108 | ||
7109 | update_global_location_list_nothrow (0); | |
7110 | return copy; | |
7111 | } | |
7112 | ||
611c83ae | 7113 | struct breakpoint * |
a6d9a66e UW |
7114 | set_momentary_breakpoint_at_pc (struct gdbarch *gdbarch, CORE_ADDR pc, |
7115 | enum bptype type) | |
611c83ae PA |
7116 | { |
7117 | struct symtab_and_line sal; | |
7118 | ||
7119 | sal = find_pc_line (pc, 0); | |
7120 | sal.pc = pc; | |
7121 | sal.section = find_pc_overlay (pc); | |
7122 | sal.explicit_pc = 1; | |
7123 | ||
a6d9a66e | 7124 | return set_momentary_breakpoint (gdbarch, sal, null_frame_id, type); |
611c83ae | 7125 | } |
c906108c | 7126 | \f |
c5aa993b | 7127 | |
c906108c SS |
7128 | /* Tell the user we have just set a breakpoint B. */ |
7129 | ||
7130 | static void | |
fba45db2 | 7131 | mention (struct breakpoint *b) |
c906108c SS |
7132 | { |
7133 | int say_where = 0; | |
fa8a61dc | 7134 | struct cleanup *ui_out_chain; |
79a45b7d TT |
7135 | struct value_print_options opts; |
7136 | ||
7137 | get_user_print_options (&opts); | |
8b93c638 | 7138 | |
3086aeae DJ |
7139 | if (b->ops != NULL && b->ops->print_mention != NULL) |
7140 | b->ops->print_mention (b); | |
7141 | else | |
7142 | switch (b->type) | |
7143 | { | |
7144 | case bp_none: | |
3e43a32a MS |
7145 | printf_filtered (_("(apparently deleted?) Eventpoint %d: "), |
7146 | b->number); | |
3086aeae DJ |
7147 | break; |
7148 | case bp_watchpoint: | |
7149 | ui_out_text (uiout, "Watchpoint "); | |
7150 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
7151 | ui_out_field_int (uiout, "number", b->number); | |
7152 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7153 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7154 | do_cleanups (ui_out_chain); |
7155 | break; | |
7156 | case bp_hardware_watchpoint: | |
7157 | ui_out_text (uiout, "Hardware watchpoint "); | |
7158 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
7159 | ui_out_field_int (uiout, "number", b->number); | |
7160 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7161 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7162 | do_cleanups (ui_out_chain); |
7163 | break; | |
7164 | case bp_read_watchpoint: | |
7165 | ui_out_text (uiout, "Hardware read watchpoint "); | |
7166 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
7167 | ui_out_field_int (uiout, "number", b->number); | |
7168 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7169 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7170 | do_cleanups (ui_out_chain); |
7171 | break; | |
7172 | case bp_access_watchpoint: | |
7173 | ui_out_text (uiout, "Hardware access (read/write) watchpoint "); | |
7174 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
7175 | ui_out_field_int (uiout, "number", b->number); | |
7176 | ui_out_text (uiout, ": "); | |
fa8a61dc | 7177 | ui_out_field_string (uiout, "exp", b->exp_string); |
3086aeae DJ |
7178 | do_cleanups (ui_out_chain); |
7179 | break; | |
7180 | case bp_breakpoint: | |
0e30163f | 7181 | case bp_gnu_ifunc_resolver: |
3086aeae DJ |
7182 | if (ui_out_is_mi_like_p (uiout)) |
7183 | { | |
7184 | say_where = 0; | |
7185 | break; | |
7186 | } | |
2cec12e5 AR |
7187 | if (b->disposition == disp_del) |
7188 | printf_filtered (_("Temporary breakpoint")); | |
7189 | else | |
7190 | printf_filtered (_("Breakpoint")); | |
7191 | printf_filtered (_(" %d"), b->number); | |
0e30163f JK |
7192 | if (b->type == bp_gnu_ifunc_resolver) |
7193 | printf_filtered (_(" at gnu-indirect-function resolver")); | |
3086aeae DJ |
7194 | say_where = 1; |
7195 | break; | |
7196 | case bp_hardware_breakpoint: | |
7197 | if (ui_out_is_mi_like_p (uiout)) | |
7198 | { | |
7199 | say_where = 0; | |
7200 | break; | |
7201 | } | |
a3f17187 | 7202 | printf_filtered (_("Hardware assisted breakpoint %d"), b->number); |
3086aeae DJ |
7203 | say_where = 1; |
7204 | break; | |
1042e4c0 SS |
7205 | case bp_tracepoint: |
7206 | if (ui_out_is_mi_like_p (uiout)) | |
7207 | { | |
7208 | say_where = 0; | |
7209 | break; | |
7210 | } | |
7211 | printf_filtered (_("Tracepoint")); | |
7212 | printf_filtered (_(" %d"), b->number); | |
7213 | say_where = 1; | |
7214 | break; | |
7a697b8d SS |
7215 | case bp_fast_tracepoint: |
7216 | if (ui_out_is_mi_like_p (uiout)) | |
7217 | { | |
7218 | say_where = 0; | |
7219 | break; | |
7220 | } | |
7221 | printf_filtered (_("Fast tracepoint")); | |
7222 | printf_filtered (_(" %d"), b->number); | |
7223 | say_where = 1; | |
7224 | break; | |
0fb4aa4b PA |
7225 | case bp_static_tracepoint: |
7226 | if (ui_out_is_mi_like_p (uiout)) | |
7227 | { | |
7228 | say_where = 0; | |
7229 | break; | |
7230 | } | |
7231 | printf_filtered (_("Static tracepoint")); | |
7232 | printf_filtered (_(" %d"), b->number); | |
7233 | say_where = 1; | |
7234 | break; | |
3086aeae DJ |
7235 | |
7236 | case bp_until: | |
7237 | case bp_finish: | |
7238 | case bp_longjmp: | |
7239 | case bp_longjmp_resume: | |
186c406b TT |
7240 | case bp_exception: |
7241 | case bp_exception_resume: | |
3086aeae | 7242 | case bp_step_resume: |
2c03e5be | 7243 | case bp_hp_step_resume: |
3086aeae | 7244 | case bp_call_dummy: |
aa7d318d | 7245 | case bp_std_terminate: |
3086aeae DJ |
7246 | case bp_watchpoint_scope: |
7247 | case bp_shlib_event: | |
7248 | case bp_thread_event: | |
7249 | case bp_overlay_event: | |
4efc6507 | 7250 | case bp_jit_event: |
0fd8e87f | 7251 | case bp_longjmp_master: |
aa7d318d | 7252 | case bp_std_terminate_master: |
186c406b | 7253 | case bp_exception_master: |
0e30163f | 7254 | case bp_gnu_ifunc_resolver_return: |
3086aeae DJ |
7255 | break; |
7256 | } | |
c906108c | 7257 | |
c906108c SS |
7258 | if (say_where) |
7259 | { | |
a3f17187 AC |
7260 | /* i18n: cagney/2005-02-11: Below needs to be merged into a |
7261 | single string. */ | |
0d381245 | 7262 | if (b->loc == NULL) |
c906108c | 7263 | { |
a3f17187 | 7264 | printf_filtered (_(" (%s) pending."), b->addr_string); |
0101ce28 JJ |
7265 | } |
7266 | else | |
7267 | { | |
79a45b7d | 7268 | if (opts.addressprint || b->source_file == NULL) |
0101ce28 JJ |
7269 | { |
7270 | printf_filtered (" at "); | |
5af949e3 UW |
7271 | fputs_filtered (paddress (b->loc->gdbarch, b->loc->address), |
7272 | gdb_stdout); | |
0101ce28 JJ |
7273 | } |
7274 | if (b->source_file) | |
7275 | printf_filtered (": file %s, line %d.", | |
7276 | b->source_file, b->line_number); | |
0d381245 VP |
7277 | |
7278 | if (b->loc->next) | |
7279 | { | |
7280 | struct bp_location *loc = b->loc; | |
7281 | int n = 0; | |
7282 | for (; loc; loc = loc->next) | |
7283 | ++n; | |
7284 | printf_filtered (" (%d locations)", n); | |
7285 | } | |
7286 | ||
c906108c | 7287 | } |
c906108c | 7288 | } |
9dc5e2a9 | 7289 | if (ui_out_is_mi_like_p (uiout)) |
fb40c209 | 7290 | return; |
c906108c SS |
7291 | printf_filtered ("\n"); |
7292 | } | |
c906108c | 7293 | \f |
c5aa993b | 7294 | |
0d381245 | 7295 | static struct bp_location * |
39d61571 | 7296 | add_location_to_breakpoint (struct breakpoint *b, |
0d381245 VP |
7297 | const struct symtab_and_line *sal) |
7298 | { | |
7299 | struct bp_location *loc, **tmp; | |
7300 | ||
39d61571 | 7301 | loc = allocate_bp_location (b); |
0d381245 VP |
7302 | for (tmp = &(b->loc); *tmp != NULL; tmp = &((*tmp)->next)) |
7303 | ; | |
7304 | *tmp = loc; | |
a6d9a66e UW |
7305 | loc->gdbarch = get_sal_arch (*sal); |
7306 | if (!loc->gdbarch) | |
7307 | loc->gdbarch = b->gdbarch; | |
0d381245 | 7308 | loc->requested_address = sal->pc; |
a6d9a66e UW |
7309 | loc->address = adjust_breakpoint_address (loc->gdbarch, |
7310 | loc->requested_address, b->type); | |
6c95b8df PA |
7311 | loc->pspace = sal->pspace; |
7312 | gdb_assert (loc->pspace != NULL); | |
0d381245 VP |
7313 | loc->section = sal->section; |
7314 | ||
0e30163f JK |
7315 | set_breakpoint_location_function (loc, |
7316 | sal->explicit_pc || sal->explicit_line); | |
0d381245 VP |
7317 | return loc; |
7318 | } | |
514f746b AR |
7319 | \f |
7320 | ||
7321 | /* Return 1 if LOC is pointing to a permanent breakpoint, | |
7322 | return 0 otherwise. */ | |
7323 | ||
7324 | static int | |
7325 | bp_loc_is_permanent (struct bp_location *loc) | |
7326 | { | |
7327 | int len; | |
7328 | CORE_ADDR addr; | |
7329 | const gdb_byte *brk; | |
7330 | gdb_byte *target_mem; | |
939c61fa JK |
7331 | struct cleanup *cleanup; |
7332 | int retval = 0; | |
514f746b AR |
7333 | |
7334 | gdb_assert (loc != NULL); | |
7335 | ||
7336 | addr = loc->address; | |
a6d9a66e | 7337 | brk = gdbarch_breakpoint_from_pc (loc->gdbarch, &addr, &len); |
514f746b | 7338 | |
939c61fa JK |
7339 | /* Software breakpoints unsupported? */ |
7340 | if (brk == NULL) | |
7341 | return 0; | |
7342 | ||
514f746b AR |
7343 | target_mem = alloca (len); |
7344 | ||
939c61fa JK |
7345 | /* Enable the automatic memory restoration from breakpoints while |
7346 | we read the memory. Otherwise we could say about our temporary | |
7347 | breakpoints they are permanent. */ | |
6c95b8df PA |
7348 | cleanup = save_current_space_and_thread (); |
7349 | ||
7350 | switch_to_program_space_and_thread (loc->pspace); | |
7351 | make_show_memory_breakpoints_cleanup (0); | |
939c61fa | 7352 | |
514f746b AR |
7353 | if (target_read_memory (loc->address, target_mem, len) == 0 |
7354 | && memcmp (target_mem, brk, len) == 0) | |
939c61fa | 7355 | retval = 1; |
514f746b | 7356 | |
939c61fa JK |
7357 | do_cleanups (cleanup); |
7358 | ||
7359 | return retval; | |
514f746b AR |
7360 | } |
7361 | ||
7362 | ||
c3f6f71d | 7363 | |
018d34a4 VP |
7364 | /* Create a breakpoint with SAL as location. Use ADDR_STRING |
7365 | as textual description of the location, and COND_STRING | |
db107f19 | 7366 | as condition expression. */ |
018d34a4 VP |
7367 | |
7368 | static void | |
8cdf0e15 VP |
7369 | create_breakpoint_sal (struct gdbarch *gdbarch, |
7370 | struct symtabs_and_lines sals, char *addr_string, | |
7371 | char *cond_string, | |
7372 | enum bptype type, enum bpdisp disposition, | |
7373 | int thread, int task, int ignore_count, | |
84f4c1fe | 7374 | struct breakpoint_ops *ops, int from_tty, |
56435ebe | 7375 | int enabled, int internal, int display_canonical) |
018d34a4 | 7376 | { |
0d381245 VP |
7377 | struct breakpoint *b = NULL; |
7378 | int i; | |
018d34a4 VP |
7379 | |
7380 | if (type == bp_hardware_breakpoint) | |
7381 | { | |
7382 | int i = hw_breakpoint_used_count (); | |
7383 | int target_resources_ok = | |
d92524f1 | 7384 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
018d34a4 VP |
7385 | i + 1, 0); |
7386 | if (target_resources_ok == 0) | |
7387 | error (_("No hardware breakpoint support in the target.")); | |
7388 | else if (target_resources_ok < 0) | |
7389 | error (_("Hardware breakpoints used exceeds limit.")); | |
7390 | } | |
7391 | ||
6c95b8df PA |
7392 | gdb_assert (sals.nelts > 0); |
7393 | ||
0d381245 VP |
7394 | for (i = 0; i < sals.nelts; ++i) |
7395 | { | |
7396 | struct symtab_and_line sal = sals.sals[i]; | |
7397 | struct bp_location *loc; | |
7398 | ||
7399 | if (from_tty) | |
5af949e3 UW |
7400 | { |
7401 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); | |
7402 | if (!loc_gdbarch) | |
7403 | loc_gdbarch = gdbarch; | |
7404 | ||
7405 | describe_other_breakpoints (loc_gdbarch, | |
6c95b8df | 7406 | sal.pspace, sal.pc, sal.section, thread); |
5af949e3 | 7407 | } |
0d381245 VP |
7408 | |
7409 | if (i == 0) | |
7410 | { | |
a6d9a66e | 7411 | b = set_raw_breakpoint (gdbarch, sal, type); |
84f4c1fe | 7412 | set_breakpoint_number (internal, b); |
0d381245 | 7413 | b->thread = thread; |
4a306c9a | 7414 | b->task = task; |
018d34a4 | 7415 | |
0d381245 VP |
7416 | b->cond_string = cond_string; |
7417 | b->ignore_count = ignore_count; | |
41447f92 | 7418 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
0d381245 | 7419 | b->disposition = disposition; |
6c95b8df PA |
7420 | b->pspace = sals.sals[0].pspace; |
7421 | ||
0fb4aa4b PA |
7422 | if (type == bp_static_tracepoint) |
7423 | { | |
7424 | struct static_tracepoint_marker marker; | |
7425 | ||
7426 | if (is_marker_spec (addr_string)) | |
7427 | { | |
7428 | /* We already know the marker exists, otherwise, we | |
7429 | wouldn't see a sal for it. */ | |
7430 | char *p = &addr_string[3]; | |
7431 | char *endp; | |
7432 | char *marker_str; | |
7433 | int i; | |
7434 | ||
e9cafbcc | 7435 | p = skip_spaces (p); |
0fb4aa4b | 7436 | |
e9cafbcc | 7437 | endp = skip_to_space (p); |
0fb4aa4b PA |
7438 | |
7439 | marker_str = savestring (p, endp - p); | |
7440 | b->static_trace_marker_id = marker_str; | |
7441 | ||
3e43a32a MS |
7442 | printf_filtered (_("Probed static tracepoint " |
7443 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7444 | b->static_trace_marker_id); |
7445 | } | |
7446 | else if (target_static_tracepoint_marker_at (sal.pc, &marker)) | |
7447 | { | |
7448 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
7449 | release_static_tracepoint_marker (&marker); | |
7450 | ||
3e43a32a MS |
7451 | printf_filtered (_("Probed static tracepoint " |
7452 | "marker \"%s\"\n"), | |
0fb4aa4b PA |
7453 | b->static_trace_marker_id); |
7454 | } | |
7455 | else | |
3e43a32a MS |
7456 | warning (_("Couldn't determine the static " |
7457 | "tracepoint marker to probe")); | |
0fb4aa4b PA |
7458 | } |
7459 | ||
6c95b8df | 7460 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
7461 | && (b->type == bp_breakpoint |
7462 | || b->type == bp_hardware_breakpoint)) | |
7463 | b->enable_state = bp_startup_disabled; | |
7464 | ||
0d381245 VP |
7465 | loc = b->loc; |
7466 | } | |
7467 | else | |
018d34a4 | 7468 | { |
39d61571 | 7469 | loc = add_location_to_breakpoint (b, &sal); |
0d381245 VP |
7470 | } |
7471 | ||
514f746b AR |
7472 | if (bp_loc_is_permanent (loc)) |
7473 | make_breakpoint_permanent (b); | |
7474 | ||
0d381245 VP |
7475 | if (b->cond_string) |
7476 | { | |
7477 | char *arg = b->cond_string; | |
d32a6982 | 7478 | loc->cond = parse_exp_1 (&arg, block_for_pc (loc->address), 0); |
0d381245 | 7479 | if (*arg) |
db107f19 | 7480 | error (_("Garbage %s follows condition"), arg); |
018d34a4 | 7481 | } |
0d381245 | 7482 | } |
018d34a4 | 7483 | |
56435ebe | 7484 | b->display_canonical = display_canonical; |
018d34a4 VP |
7485 | if (addr_string) |
7486 | b->addr_string = addr_string; | |
7487 | else | |
7488 | /* addr_string has to be used or breakpoint_re_set will delete | |
7489 | me. */ | |
5af949e3 UW |
7490 | b->addr_string |
7491 | = xstrprintf ("*%s", paddress (b->loc->gdbarch, b->loc->address)); | |
018d34a4 | 7492 | |
604133b5 | 7493 | b->ops = ops; |
8d3788bd VP |
7494 | /* Do not mention breakpoints with a negative number, but do |
7495 | notify observers. */ | |
7496 | if (!internal) | |
84f4c1fe | 7497 | mention (b); |
8d3788bd | 7498 | observer_notify_breakpoint_created (b); |
018d34a4 VP |
7499 | } |
7500 | ||
ed0616c6 VP |
7501 | /* Remove element at INDEX_TO_REMOVE from SAL, shifting other |
7502 | elements to fill the void space. */ | |
2c0b251b PA |
7503 | static void |
7504 | remove_sal (struct symtabs_and_lines *sal, int index_to_remove) | |
ed0616c6 VP |
7505 | { |
7506 | int i = index_to_remove+1; | |
7507 | int last_index = sal->nelts-1; | |
7508 | ||
7509 | for (;i <= last_index; ++i) | |
7510 | sal->sals[i-1] = sal->sals[i]; | |
7511 | ||
7512 | --(sal->nelts); | |
7513 | } | |
7514 | ||
6c95b8df PA |
7515 | /* If appropriate, obtains all sals that correspond to the same file |
7516 | and line as SAL, in all program spaces. Users debugging with IDEs, | |
7517 | will want to set a breakpoint at foo.c:line, and not really care | |
7518 | about program spaces. This is done only if SAL does not have | |
7519 | explicit PC and has line and file information. If we got just a | |
7520 | single expanded sal, return the original. | |
ed0616c6 | 7521 | |
6c95b8df PA |
7522 | Otherwise, if SAL.explicit_line is not set, filter out all sals for |
7523 | which the name of enclosing function is different from SAL. This | |
7524 | makes sure that if we have breakpoint originally set in template | |
7525 | instantiation, say foo<int>(), we won't expand SAL to locations at | |
7526 | the same line in all existing instantiations of 'foo'. */ | |
ed0616c6 | 7527 | |
2c0b251b | 7528 | static struct symtabs_and_lines |
ed0616c6 VP |
7529 | expand_line_sal_maybe (struct symtab_and_line sal) |
7530 | { | |
7531 | struct symtabs_and_lines expanded; | |
7532 | CORE_ADDR original_pc = sal.pc; | |
7533 | char *original_function = NULL; | |
7534 | int found; | |
7535 | int i; | |
6c95b8df | 7536 | struct cleanup *old_chain; |
ed0616c6 VP |
7537 | |
7538 | /* If we have explicit pc, don't expand. | |
7539 | If we have no line number, we can't expand. */ | |
7540 | if (sal.explicit_pc || sal.line == 0 || sal.symtab == NULL) | |
7541 | { | |
7542 | expanded.nelts = 1; | |
7543 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7544 | expanded.sals[0] = sal; | |
7545 | return expanded; | |
7546 | } | |
7547 | ||
7548 | sal.pc = 0; | |
6c95b8df PA |
7549 | |
7550 | old_chain = save_current_space_and_thread (); | |
7551 | ||
7552 | switch_to_program_space_and_thread (sal.pspace); | |
7553 | ||
ed0616c6 | 7554 | find_pc_partial_function (original_pc, &original_function, NULL, NULL); |
6c95b8df PA |
7555 | |
7556 | /* Note that expand_line_sal visits *all* program spaces. */ | |
ed0616c6 | 7557 | expanded = expand_line_sal (sal); |
6c95b8df | 7558 | |
ed0616c6 VP |
7559 | if (expanded.nelts == 1) |
7560 | { | |
3dba1c98 JB |
7561 | /* We had one sal, we got one sal. Return that sal, adjusting it |
7562 | past the function prologue if necessary. */ | |
ed0616c6 VP |
7563 | xfree (expanded.sals); |
7564 | expanded.nelts = 1; | |
7565 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7566 | sal.pc = original_pc; | |
7567 | expanded.sals[0] = sal; | |
3dba1c98 | 7568 | skip_prologue_sal (&expanded.sals[0]); |
6c95b8df | 7569 | do_cleanups (old_chain); |
ed0616c6 VP |
7570 | return expanded; |
7571 | } | |
7572 | ||
7573 | if (!sal.explicit_line) | |
7574 | { | |
7575 | CORE_ADDR func_addr, func_end; | |
7576 | for (i = 0; i < expanded.nelts; ++i) | |
7577 | { | |
7578 | CORE_ADDR pc = expanded.sals[i].pc; | |
7579 | char *this_function; | |
6c95b8df PA |
7580 | |
7581 | /* We need to switch threads as well since we're about to | |
7582 | read memory. */ | |
7583 | switch_to_program_space_and_thread (expanded.sals[i].pspace); | |
7584 | ||
ed0616c6 VP |
7585 | if (find_pc_partial_function (pc, &this_function, |
7586 | &func_addr, &func_end)) | |
7587 | { | |
059fb39f PM |
7588 | if (this_function |
7589 | && strcmp (this_function, original_function) != 0) | |
ed0616c6 VP |
7590 | { |
7591 | remove_sal (&expanded, i); | |
7592 | --i; | |
7593 | } | |
ed0616c6 VP |
7594 | } |
7595 | } | |
7596 | } | |
059acae7 UW |
7597 | |
7598 | /* Skip the function prologue if necessary. */ | |
7599 | for (i = 0; i < expanded.nelts; ++i) | |
7600 | skip_prologue_sal (&expanded.sals[i]); | |
ed0616c6 | 7601 | |
6c95b8df PA |
7602 | do_cleanups (old_chain); |
7603 | ||
ed0616c6 VP |
7604 | if (expanded.nelts <= 1) |
7605 | { | |
4a64f543 MS |
7606 | /* This is un ugly workaround. If we get zero expanded sals |
7607 | then something is really wrong. Fix that by returning the | |
7608 | original sal. */ | |
7609 | ||
ed0616c6 VP |
7610 | xfree (expanded.sals); |
7611 | expanded.nelts = 1; | |
7612 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
7613 | sal.pc = original_pc; | |
7614 | expanded.sals[0] = sal; | |
7615 | return expanded; | |
7616 | } | |
7617 | ||
7618 | if (original_pc) | |
7619 | { | |
7620 | found = 0; | |
7621 | for (i = 0; i < expanded.nelts; ++i) | |
7622 | if (expanded.sals[i].pc == original_pc) | |
7623 | { | |
7624 | found = 1; | |
7625 | break; | |
7626 | } | |
7627 | gdb_assert (found); | |
7628 | } | |
7629 | ||
7630 | return expanded; | |
7631 | } | |
7632 | ||
018d34a4 VP |
7633 | /* Add SALS.nelts breakpoints to the breakpoint table. For each |
7634 | SALS.sal[i] breakpoint, include the corresponding ADDR_STRING[i] | |
7635 | value. COND_STRING, if not NULL, specified the condition to be | |
7636 | used for all breakpoints. Essentially the only case where | |
7637 | SALS.nelts is not 1 is when we set a breakpoint on an overloaded | |
7638 | function. In that case, it's still not possible to specify | |
7639 | separate conditions for different overloaded functions, so | |
7640 | we take just a single condition string. | |
7641 | ||
c3f6f71d | 7642 | NOTE: If the function succeeds, the caller is expected to cleanup |
018d34a4 | 7643 | the arrays ADDR_STRING, COND_STRING, and SALS (but not the |
c3f6f71d JM |
7644 | array contents). If the function fails (error() is called), the |
7645 | caller is expected to cleanups both the ADDR_STRING, COND_STRING, | |
4a64f543 | 7646 | COND and SALS arrays and each of those arrays contents. */ |
c906108c SS |
7647 | |
7648 | static void | |
8cdf0e15 | 7649 | create_breakpoints_sal (struct gdbarch *gdbarch, |
7efd8fc2 TT |
7650 | struct symtabs_and_lines sals, |
7651 | struct linespec_result *canonical, | |
8cdf0e15 VP |
7652 | char *cond_string, |
7653 | enum bptype type, enum bpdisp disposition, | |
7654 | int thread, int task, int ignore_count, | |
7655 | struct breakpoint_ops *ops, int from_tty, | |
84f4c1fe | 7656 | int enabled, int internal) |
c906108c | 7657 | { |
018d34a4 | 7658 | int i; |
cc59ec59 | 7659 | |
018d34a4 | 7660 | for (i = 0; i < sals.nelts; ++i) |
c3f6f71d | 7661 | { |
ed0616c6 VP |
7662 | struct symtabs_and_lines expanded = |
7663 | expand_line_sal_maybe (sals.sals[i]); | |
0d381245 | 7664 | |
7efd8fc2 | 7665 | create_breakpoint_sal (gdbarch, expanded, canonical->canonical[i], |
8cdf0e15 | 7666 | cond_string, type, disposition, |
84f4c1fe | 7667 | thread, task, ignore_count, ops, |
56435ebe TT |
7668 | from_tty, enabled, internal, |
7669 | canonical->special_display); | |
c3f6f71d | 7670 | } |
c3f6f71d | 7671 | } |
c906108c | 7672 | |
9998af43 | 7673 | /* Parse ADDRESS which is assumed to be a SAL specification possibly |
c3f6f71d | 7674 | followed by conditionals. On return, SALS contains an array of SAL |
4a64f543 | 7675 | addresses found. ADDR_STRING contains a vector of (canonical) |
9998af43 TJB |
7676 | address strings. ADDRESS points to the end of the SAL. |
7677 | ||
7678 | The array and the line spec strings are allocated on the heap, it is | |
7679 | the caller's responsibility to free them. */ | |
c906108c | 7680 | |
b9362cc7 | 7681 | static void |
c3f6f71d JM |
7682 | parse_breakpoint_sals (char **address, |
7683 | struct symtabs_and_lines *sals, | |
58438ac1 | 7684 | struct linespec_result *canonical) |
c3f6f71d JM |
7685 | { |
7686 | char *addr_start = *address; | |
cc59ec59 | 7687 | |
c3f6f71d | 7688 | /* If no arg given, or if first arg is 'if ', use the default |
4a64f543 | 7689 | breakpoint. */ |
c3f6f71d JM |
7690 | if ((*address) == NULL |
7691 | || (strncmp ((*address), "if", 2) == 0 && isspace ((*address)[2]))) | |
c906108c SS |
7692 | { |
7693 | if (default_breakpoint_valid) | |
7694 | { | |
c3f6f71d | 7695 | struct symtab_and_line sal; |
cc59ec59 | 7696 | |
4a64f543 | 7697 | init_sal (&sal); /* Initialize to zeroes. */ |
c3f6f71d | 7698 | sals->sals = (struct symtab_and_line *) |
c906108c SS |
7699 | xmalloc (sizeof (struct symtab_and_line)); |
7700 | sal.pc = default_breakpoint_address; | |
7701 | sal.line = default_breakpoint_line; | |
7702 | sal.symtab = default_breakpoint_symtab; | |
6c95b8df | 7703 | sal.pspace = default_breakpoint_pspace; |
c5aa993b | 7704 | sal.section = find_pc_overlay (sal.pc); |
00903456 | 7705 | |
4a64f543 MS |
7706 | /* "break" without arguments is equivalent to "break *PC" |
7707 | where PC is the default_breakpoint_address. So make sure | |
7708 | to set sal.explicit_pc to prevent GDB from trying to | |
7709 | expand the list of sals to include all other instances | |
7710 | with the same symtab and line. */ | |
00903456 JK |
7711 | sal.explicit_pc = 1; |
7712 | ||
c3f6f71d JM |
7713 | sals->sals[0] = sal; |
7714 | sals->nelts = 1; | |
c906108c SS |
7715 | } |
7716 | else | |
8a3fe4f8 | 7717 | error (_("No default breakpoint address now.")); |
c906108c SS |
7718 | } |
7719 | else | |
7720 | { | |
c906108c | 7721 | /* Force almost all breakpoints to be in terms of the |
4a64f543 MS |
7722 | current_source_symtab (which is decode_line_1's default). |
7723 | This should produce the results we want almost all of the | |
7724 | time while leaving default_breakpoint_* alone. | |
7725 | ||
1aeae86e AF |
7726 | ObjC: However, don't match an Objective-C method name which |
7727 | may have a '+' or '-' succeeded by a '[' */ | |
0378c332 | 7728 | |
c214a6fd | 7729 | struct symtab_and_line cursal = get_current_source_symtab_and_line (); |
0378c332 | 7730 | |
c906108c | 7731 | if (default_breakpoint_valid |
0378c332 | 7732 | && (!cursal.symtab |
1aeae86e AF |
7733 | || ((strchr ("+-", (*address)[0]) != NULL) |
7734 | && ((*address)[1] != '[')))) | |
c3f6f71d | 7735 | *sals = decode_line_1 (address, 1, default_breakpoint_symtab, |
58438ac1 | 7736 | default_breakpoint_line, canonical); |
c906108c | 7737 | else |
0101ce28 | 7738 | *sals = decode_line_1 (address, 1, (struct symtab *) NULL, 0, |
58438ac1 | 7739 | canonical); |
c906108c | 7740 | } |
4a64f543 | 7741 | /* For any SAL that didn't have a canonical string, fill one in. */ |
7efd8fc2 | 7742 | if (sals->nelts > 0 && canonical->canonical == NULL) |
38a714bb | 7743 | canonical->canonical = xcalloc (sals->nelts, sizeof (char *)); |
c3f6f71d | 7744 | if (addr_start != (*address)) |
c906108c | 7745 | { |
c3f6f71d | 7746 | int i; |
cc59ec59 | 7747 | |
c3f6f71d | 7748 | for (i = 0; i < sals->nelts; i++) |
c906108c | 7749 | { |
4a64f543 | 7750 | /* Add the string if not present. */ |
7efd8fc2 TT |
7751 | if (canonical->canonical[i] == NULL) |
7752 | canonical->canonical[i] = savestring (addr_start, | |
7753 | (*address) - addr_start); | |
c906108c SS |
7754 | } |
7755 | } | |
c3f6f71d | 7756 | } |
c906108c | 7757 | |
c906108c | 7758 | |
c3f6f71d | 7759 | /* Convert each SAL into a real PC. Verify that the PC can be |
4a64f543 | 7760 | inserted as a breakpoint. If it can't throw an error. */ |
c906108c | 7761 | |
b9362cc7 | 7762 | static void |
23e7acfb | 7763 | breakpoint_sals_to_pc (struct symtabs_and_lines *sals) |
c3f6f71d JM |
7764 | { |
7765 | int i; | |
cc59ec59 | 7766 | |
c3f6f71d | 7767 | for (i = 0; i < sals->nelts; i++) |
ee53e872 | 7768 | resolve_sal_pc (&sals->sals[i]); |
c3f6f71d JM |
7769 | } |
7770 | ||
7a697b8d SS |
7771 | /* Fast tracepoints may have restrictions on valid locations. For |
7772 | instance, a fast tracepoint using a jump instead of a trap will | |
7773 | likely have to overwrite more bytes than a trap would, and so can | |
7774 | only be placed where the instruction is longer than the jump, or a | |
7775 | multi-instruction sequence does not have a jump into the middle of | |
7776 | it, etc. */ | |
7777 | ||
7778 | static void | |
7779 | check_fast_tracepoint_sals (struct gdbarch *gdbarch, | |
7780 | struct symtabs_and_lines *sals) | |
7781 | { | |
7782 | int i, rslt; | |
7783 | struct symtab_and_line *sal; | |
7784 | char *msg; | |
7785 | struct cleanup *old_chain; | |
7786 | ||
7787 | for (i = 0; i < sals->nelts; i++) | |
7788 | { | |
7789 | sal = &sals->sals[i]; | |
7790 | ||
7791 | rslt = gdbarch_fast_tracepoint_valid_at (gdbarch, sal->pc, | |
7792 | NULL, &msg); | |
7793 | old_chain = make_cleanup (xfree, msg); | |
7794 | ||
7795 | if (!rslt) | |
7796 | error (_("May not have a fast tracepoint at 0x%s%s"), | |
7797 | paddress (gdbarch, sal->pc), (msg ? msg : "")); | |
7798 | ||
7799 | do_cleanups (old_chain); | |
7800 | } | |
7801 | } | |
7802 | ||
018d34a4 VP |
7803 | /* Given TOK, a string specification of condition and thread, as |
7804 | accepted by the 'break' command, extract the condition | |
7805 | string and thread number and set *COND_STRING and *THREAD. | |
4a64f543 | 7806 | PC identifies the context at which the condition should be parsed. |
018d34a4 VP |
7807 | If no condition is found, *COND_STRING is set to NULL. |
7808 | If no thread is found, *THREAD is set to -1. */ | |
7809 | static void | |
7810 | find_condition_and_thread (char *tok, CORE_ADDR pc, | |
4a306c9a | 7811 | char **cond_string, int *thread, int *task) |
018d34a4 VP |
7812 | { |
7813 | *cond_string = NULL; | |
7814 | *thread = -1; | |
7815 | while (tok && *tok) | |
7816 | { | |
7817 | char *end_tok; | |
7818 | int toklen; | |
7819 | char *cond_start = NULL; | |
7820 | char *cond_end = NULL; | |
cc59ec59 | 7821 | |
e9cafbcc | 7822 | tok = skip_spaces (tok); |
018d34a4 | 7823 | |
e9cafbcc | 7824 | end_tok = skip_to_space (tok); |
018d34a4 VP |
7825 | |
7826 | toklen = end_tok - tok; | |
7827 | ||
7828 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
7829 | { | |
f7545552 TT |
7830 | struct expression *expr; |
7831 | ||
018d34a4 | 7832 | tok = cond_start = end_tok + 1; |
f7545552 TT |
7833 | expr = parse_exp_1 (&tok, block_for_pc (pc), 0); |
7834 | xfree (expr); | |
018d34a4 VP |
7835 | cond_end = tok; |
7836 | *cond_string = savestring (cond_start, | |
7837 | cond_end - cond_start); | |
7838 | } | |
7839 | else if (toklen >= 1 && strncmp (tok, "thread", toklen) == 0) | |
7840 | { | |
7841 | char *tmptok; | |
7842 | ||
7843 | tok = end_tok + 1; | |
7844 | tmptok = tok; | |
7845 | *thread = strtol (tok, &tok, 0); | |
7846 | if (tok == tmptok) | |
7847 | error (_("Junk after thread keyword.")); | |
7848 | if (!valid_thread_id (*thread)) | |
7849 | error (_("Unknown thread %d."), *thread); | |
7850 | } | |
4a306c9a JB |
7851 | else if (toklen >= 1 && strncmp (tok, "task", toklen) == 0) |
7852 | { | |
7853 | char *tmptok; | |
7854 | ||
7855 | tok = end_tok + 1; | |
7856 | tmptok = tok; | |
7857 | *task = strtol (tok, &tok, 0); | |
7858 | if (tok == tmptok) | |
7859 | error (_("Junk after task keyword.")); | |
7860 | if (!valid_task_id (*task)) | |
b6199126 | 7861 | error (_("Unknown task %d."), *task); |
4a306c9a | 7862 | } |
018d34a4 VP |
7863 | else |
7864 | error (_("Junk at end of arguments.")); | |
7865 | } | |
7866 | } | |
7867 | ||
0fb4aa4b PA |
7868 | /* Decode a static tracepoint marker spec. */ |
7869 | ||
7870 | static struct symtabs_and_lines | |
7871 | decode_static_tracepoint_spec (char **arg_p) | |
7872 | { | |
7873 | VEC(static_tracepoint_marker_p) *markers = NULL; | |
7874 | struct symtabs_and_lines sals; | |
7875 | struct symtab_and_line sal; | |
7876 | struct symbol *sym; | |
7877 | struct cleanup *old_chain; | |
7878 | char *p = &(*arg_p)[3]; | |
7879 | char *endp; | |
7880 | char *marker_str; | |
7881 | int i; | |
7882 | ||
e9cafbcc | 7883 | p = skip_spaces (p); |
0fb4aa4b | 7884 | |
e9cafbcc | 7885 | endp = skip_to_space (p); |
0fb4aa4b PA |
7886 | |
7887 | marker_str = savestring (p, endp - p); | |
7888 | old_chain = make_cleanup (xfree, marker_str); | |
7889 | ||
7890 | markers = target_static_tracepoint_markers_by_strid (marker_str); | |
7891 | if (VEC_empty(static_tracepoint_marker_p, markers)) | |
7892 | error (_("No known static tracepoint marker named %s"), marker_str); | |
7893 | ||
7894 | sals.nelts = VEC_length(static_tracepoint_marker_p, markers); | |
7895 | sals.sals = xmalloc (sizeof *sals.sals * sals.nelts); | |
7896 | ||
7897 | for (i = 0; i < sals.nelts; i++) | |
7898 | { | |
7899 | struct static_tracepoint_marker *marker; | |
7900 | ||
7901 | marker = VEC_index (static_tracepoint_marker_p, markers, i); | |
7902 | ||
7903 | init_sal (&sals.sals[i]); | |
7904 | ||
7905 | sals.sals[i] = find_pc_line (marker->address, 0); | |
7906 | sals.sals[i].pc = marker->address; | |
7907 | ||
7908 | release_static_tracepoint_marker (marker); | |
7909 | } | |
7910 | ||
7911 | do_cleanups (old_chain); | |
7912 | ||
7913 | *arg_p = endp; | |
7914 | return sals; | |
7915 | } | |
7916 | ||
fd9b8c24 PA |
7917 | /* Set a breakpoint. This function is shared between CLI and MI |
7918 | functions for setting a breakpoint. This function has two major | |
7919 | modes of operations, selected by the PARSE_CONDITION_AND_THREAD | |
7920 | parameter. If non-zero, the function will parse arg, extracting | |
4a64f543 MS |
7921 | breakpoint location, address and thread. Otherwise, ARG is just |
7922 | the location of breakpoint, with condition and thread specified by | |
7923 | the COND_STRING and THREAD parameters. If INTERNAL is non-zero, | |
7924 | the breakpoint number will be allocated from the internal | |
7925 | breakpoint count. Returns true if any breakpoint was created; | |
7926 | false otherwise. */ | |
0101ce28 | 7927 | |
8cdf0e15 VP |
7928 | int |
7929 | create_breakpoint (struct gdbarch *gdbarch, | |
7930 | char *arg, char *cond_string, int thread, | |
7931 | int parse_condition_and_thread, | |
0fb4aa4b | 7932 | int tempflag, enum bptype type_wanted, |
8cdf0e15 VP |
7933 | int ignore_count, |
7934 | enum auto_boolean pending_break_support, | |
7935 | struct breakpoint_ops *ops, | |
84f4c1fe | 7936 | int from_tty, int enabled, int internal) |
c3f6f71d | 7937 | { |
b78a6381 | 7938 | volatile struct gdb_exception e; |
c3f6f71d | 7939 | struct symtabs_and_lines sals; |
0101ce28 | 7940 | struct symtab_and_line pending_sal; |
0101ce28 | 7941 | char *copy_arg; |
c3f6f71d | 7942 | char *addr_start = arg; |
7efd8fc2 | 7943 | struct linespec_result canonical; |
c3f6f71d | 7944 | struct cleanup *old_chain; |
80c99de1 | 7945 | struct cleanup *bkpt_chain = NULL; |
05ff989b | 7946 | int i; |
0101ce28 | 7947 | int pending = 0; |
4a306c9a | 7948 | int task = 0; |
86b17b60 | 7949 | int prev_bkpt_count = breakpoint_count; |
c3f6f71d | 7950 | |
c3f6f71d JM |
7951 | sals.sals = NULL; |
7952 | sals.nelts = 0; | |
7efd8fc2 | 7953 | init_linespec_result (&canonical); |
c3f6f71d | 7954 | |
0fb4aa4b PA |
7955 | if (type_wanted == bp_static_tracepoint && is_marker_spec (arg)) |
7956 | { | |
7957 | int i; | |
7958 | ||
7959 | sals = decode_static_tracepoint_spec (&arg); | |
7960 | ||
7961 | copy_arg = savestring (addr_start, arg - addr_start); | |
38a714bb | 7962 | canonical.canonical = xcalloc (sals.nelts, sizeof (char *)); |
0fb4aa4b | 7963 | for (i = 0; i < sals.nelts; i++) |
7efd8fc2 | 7964 | canonical.canonical[i] = xstrdup (copy_arg); |
0fb4aa4b PA |
7965 | goto done; |
7966 | } | |
7967 | ||
b78a6381 TT |
7968 | TRY_CATCH (e, RETURN_MASK_ALL) |
7969 | { | |
58438ac1 | 7970 | parse_breakpoint_sals (&arg, &sals, &canonical); |
b78a6381 | 7971 | } |
0101ce28 JJ |
7972 | |
7973 | /* If caller is interested in rc value from parse, set value. */ | |
05ff989b | 7974 | switch (e.reason) |
0101ce28 | 7975 | { |
05ff989b | 7976 | case RETURN_QUIT: |
98deb0da | 7977 | throw_exception (e); |
05ff989b AC |
7978 | case RETURN_ERROR: |
7979 | switch (e.error) | |
0101ce28 | 7980 | { |
05ff989b | 7981 | case NOT_FOUND_ERROR: |
0101ce28 | 7982 | |
05ff989b AC |
7983 | /* If pending breakpoint support is turned off, throw |
7984 | error. */ | |
fa8d40ab JJ |
7985 | |
7986 | if (pending_break_support == AUTO_BOOLEAN_FALSE) | |
723a2275 VP |
7987 | throw_exception (e); |
7988 | ||
7989 | exception_print (gdb_stderr, e); | |
fa8d40ab | 7990 | |
05ff989b AC |
7991 | /* If pending breakpoint support is auto query and the user |
7992 | selects no, then simply return the error code. */ | |
059fb39f | 7993 | if (pending_break_support == AUTO_BOOLEAN_AUTO |
3e43a32a MS |
7994 | && !nquery (_("Make breakpoint pending on " |
7995 | "future shared library load? "))) | |
fd9b8c24 | 7996 | return 0; |
fa8d40ab | 7997 | |
05ff989b AC |
7998 | /* At this point, either the user was queried about setting |
7999 | a pending breakpoint and selected yes, or pending | |
8000 | breakpoint behavior is on and thus a pending breakpoint | |
8001 | is defaulted on behalf of the user. */ | |
0101ce28 | 8002 | copy_arg = xstrdup (addr_start); |
7efd8fc2 | 8003 | canonical.canonical = ©_arg; |
0101ce28 JJ |
8004 | sals.nelts = 1; |
8005 | sals.sals = &pending_sal; | |
8006 | pending_sal.pc = 0; | |
8007 | pending = 1; | |
05ff989b AC |
8008 | break; |
8009 | default: | |
98deb0da | 8010 | throw_exception (e); |
0101ce28 | 8011 | } |
2abae994 | 8012 | break; |
05ff989b AC |
8013 | default: |
8014 | if (!sals.nelts) | |
fd9b8c24 | 8015 | return 0; |
0101ce28 | 8016 | } |
c3f6f71d | 8017 | |
0fb4aa4b PA |
8018 | done: |
8019 | ||
4a64f543 | 8020 | /* Create a chain of things that always need to be cleaned up. */ |
c3f6f71d JM |
8021 | old_chain = make_cleanup (null_cleanup, 0); |
8022 | ||
0101ce28 JJ |
8023 | if (!pending) |
8024 | { | |
8025 | /* Make sure that all storage allocated to SALS gets freed. */ | |
8026 | make_cleanup (xfree, sals.sals); | |
8027 | ||
7efd8fc2 TT |
8028 | /* Cleanup the canonical array but not its contents. */ |
8029 | make_cleanup (xfree, canonical.canonical); | |
0101ce28 | 8030 | } |
c3f6f71d | 8031 | |
c3f6f71d JM |
8032 | /* ----------------------------- SNIP ----------------------------- |
8033 | Anything added to the cleanup chain beyond this point is assumed | |
8034 | to be part of a breakpoint. If the breakpoint create succeeds | |
80c99de1 PA |
8035 | then the memory is not reclaimed. */ |
8036 | bkpt_chain = make_cleanup (null_cleanup, 0); | |
c3f6f71d | 8037 | |
7efd8fc2 | 8038 | /* Mark the contents of the canonical for cleanup. These go on |
80c99de1 | 8039 | the bkpt_chain and only occur if the breakpoint create fails. */ |
c3f6f71d JM |
8040 | for (i = 0; i < sals.nelts; i++) |
8041 | { | |
7efd8fc2 TT |
8042 | if (canonical.canonical[i] != NULL) |
8043 | make_cleanup (xfree, canonical.canonical[i]); | |
c3f6f71d JM |
8044 | } |
8045 | ||
8046 | /* Resolve all line numbers to PC's and verify that the addresses | |
8047 | are ok for the target. */ | |
0101ce28 | 8048 | if (!pending) |
23e7acfb | 8049 | breakpoint_sals_to_pc (&sals); |
c3f6f71d | 8050 | |
7a697b8d SS |
8051 | /* Fast tracepoints may have additional restrictions on location. */ |
8052 | if (type_wanted == bp_fast_tracepoint) | |
8053 | check_fast_tracepoint_sals (gdbarch, &sals); | |
8054 | ||
c3f6f71d JM |
8055 | /* Verify that condition can be parsed, before setting any |
8056 | breakpoints. Allocate a separate condition expression for each | |
4a64f543 | 8057 | breakpoint. */ |
0101ce28 | 8058 | if (!pending) |
c3f6f71d | 8059 | { |
2f069f6f | 8060 | if (parse_condition_and_thread) |
72b2ff0e VP |
8061 | { |
8062 | /* Here we only parse 'arg' to separate condition | |
8063 | from thread number, so parsing in context of first | |
8064 | sal is OK. When setting the breakpoint we'll | |
8065 | re-parse it in context of each sal. */ | |
8066 | cond_string = NULL; | |
8067 | thread = -1; | |
4a306c9a JB |
8068 | find_condition_and_thread (arg, sals.sals[0].pc, &cond_string, |
8069 | &thread, &task); | |
72b2ff0e VP |
8070 | if (cond_string) |
8071 | make_cleanup (xfree, cond_string); | |
8072 | } | |
2f069f6f | 8073 | else |
72b2ff0e VP |
8074 | { |
8075 | /* Create a private copy of condition string. */ | |
8076 | if (cond_string) | |
8077 | { | |
8078 | cond_string = xstrdup (cond_string); | |
8079 | make_cleanup (xfree, cond_string); | |
8080 | } | |
8081 | } | |
0fb4aa4b PA |
8082 | |
8083 | /* If the user is creating a static tracepoint by marker id | |
8084 | (strace -m MARKER_ID), then store the sals index, so that | |
8085 | breakpoint_re_set can try to match up which of the newly | |
8086 | found markers corresponds to this one, and, don't try to | |
8087 | expand multiple locations for each sal, given than SALS | |
8088 | already should contain all sals for MARKER_ID. */ | |
8089 | if (type_wanted == bp_static_tracepoint | |
7efd8fc2 | 8090 | && is_marker_spec (canonical.canonical[0])) |
0fb4aa4b PA |
8091 | { |
8092 | int i; | |
8093 | ||
8094 | for (i = 0; i < sals.nelts; ++i) | |
8095 | { | |
8096 | struct symtabs_and_lines expanded; | |
8097 | struct breakpoint *tp; | |
8098 | struct cleanup *old_chain; | |
8099 | ||
8100 | expanded.nelts = 1; | |
8101 | expanded.sals = xmalloc (sizeof (struct symtab_and_line)); | |
8102 | expanded.sals[0] = sals.sals[i]; | |
8103 | old_chain = make_cleanup (xfree, expanded.sals); | |
8104 | ||
7efd8fc2 | 8105 | create_breakpoint_sal (gdbarch, expanded, canonical.canonical[i], |
0fb4aa4b PA |
8106 | cond_string, type_wanted, |
8107 | tempflag ? disp_del : disp_donttouch, | |
8108 | thread, task, ignore_count, ops, | |
56435ebe TT |
8109 | from_tty, enabled, internal, |
8110 | canonical.special_display); | |
0fb4aa4b PA |
8111 | |
8112 | do_cleanups (old_chain); | |
8113 | ||
8114 | /* Get the tracepoint we just created. */ | |
84f4c1fe PM |
8115 | if (internal) |
8116 | tp = get_breakpoint (internal_breakpoint_number); | |
8117 | else | |
8118 | tp = get_breakpoint (breakpoint_count); | |
0fb4aa4b PA |
8119 | gdb_assert (tp != NULL); |
8120 | ||
8121 | /* Given that its possible to have multiple markers with | |
8122 | the same string id, if the user is creating a static | |
8123 | tracepoint by marker id ("strace -m MARKER_ID"), then | |
8124 | store the sals index, so that breakpoint_re_set can | |
8125 | try to match up which of the newly found markers | |
8126 | corresponds to this one */ | |
8127 | tp->static_trace_marker_id_idx = i; | |
8128 | } | |
8129 | } | |
8130 | else | |
7efd8fc2 | 8131 | create_breakpoints_sal (gdbarch, sals, &canonical, cond_string, |
3e43a32a MS |
8132 | type_wanted, |
8133 | tempflag ? disp_del : disp_donttouch, | |
0fb4aa4b | 8134 | thread, task, ignore_count, ops, from_tty, |
84f4c1fe | 8135 | enabled, internal); |
c906108c | 8136 | } |
0101ce28 JJ |
8137 | else |
8138 | { | |
0101ce28 JJ |
8139 | struct breakpoint *b; |
8140 | ||
0101ce28 JJ |
8141 | make_cleanup (xfree, copy_arg); |
8142 | ||
a6d9a66e | 8143 | b = set_raw_breakpoint_without_location (gdbarch, type_wanted); |
84f4c1fe | 8144 | set_breakpoint_number (internal, b); |
72b2ff0e | 8145 | b->thread = -1; |
7efd8fc2 | 8146 | b->addr_string = canonical.canonical[0]; |
72b2ff0e | 8147 | b->cond_string = NULL; |
0101ce28 | 8148 | b->ignore_count = ignore_count; |
0101ce28 | 8149 | b->disposition = tempflag ? disp_del : disp_donttouch; |
0d381245 | 8150 | b->condition_not_parsed = 1; |
604133b5 | 8151 | b->ops = ops; |
41447f92 | 8152 | b->enable_state = enabled ? bp_enabled : bp_disabled; |
6c95b8df | 8153 | b->pspace = current_program_space; |
84f4c1fe | 8154 | b->py_bp_object = NULL; |
74960c60 | 8155 | |
6c95b8df | 8156 | if (enabled && b->pspace->executing_startup |
8bea4e01 UW |
8157 | && (b->type == bp_breakpoint |
8158 | || b->type == bp_hardware_breakpoint)) | |
8159 | b->enable_state = bp_startup_disabled; | |
8160 | ||
8d3788bd | 8161 | if (!internal) |
84f4c1fe PM |
8162 | /* Do not mention breakpoints with a negative number, |
8163 | but do notify observers. */ | |
8d3788bd VP |
8164 | mention (b); |
8165 | observer_notify_breakpoint_created (b); | |
0101ce28 JJ |
8166 | } |
8167 | ||
c3f6f71d | 8168 | if (sals.nelts > 1) |
95a42b64 | 8169 | { |
3e43a32a MS |
8170 | warning (_("Multiple breakpoints were set.\nUse the " |
8171 | "\"delete\" command to delete unwanted breakpoints.")); | |
86b17b60 | 8172 | prev_breakpoint_count = prev_bkpt_count; |
95a42b64 TT |
8173 | } |
8174 | ||
80c99de1 PA |
8175 | /* That's it. Discard the cleanups for data inserted into the |
8176 | breakpoint. */ | |
8177 | discard_cleanups (bkpt_chain); | |
8178 | /* But cleanup everything else. */ | |
c3f6f71d | 8179 | do_cleanups (old_chain); |
217dc9e2 | 8180 | |
80c99de1 | 8181 | /* error call may happen here - have BKPT_CHAIN already discarded. */ |
217dc9e2 | 8182 | update_global_location_list (1); |
fd9b8c24 PA |
8183 | |
8184 | return 1; | |
c3f6f71d | 8185 | } |
c906108c | 8186 | |
72b2ff0e VP |
8187 | /* Set a breakpoint. |
8188 | ARG is a string describing breakpoint address, | |
8189 | condition, and thread. | |
8190 | FLAG specifies if a breakpoint is hardware on, | |
8191 | and if breakpoint is temporary, using BP_HARDWARE_FLAG | |
8192 | and BP_TEMPFLAG. */ | |
8193 | ||
98deb0da | 8194 | static void |
72b2ff0e | 8195 | break_command_1 (char *arg, int flag, int from_tty) |
c3f6f71d | 8196 | { |
72b2ff0e | 8197 | int tempflag = flag & BP_TEMPFLAG; |
0fb4aa4b PA |
8198 | enum bptype type_wanted = (flag & BP_HARDWAREFLAG |
8199 | ? bp_hardware_breakpoint | |
8200 | : bp_breakpoint); | |
c3f6f71d | 8201 | |
8cdf0e15 VP |
8202 | create_breakpoint (get_current_arch (), |
8203 | arg, | |
8204 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b | 8205 | tempflag, type_wanted, |
8cdf0e15 VP |
8206 | 0 /* Ignore count */, |
8207 | pending_break_support, | |
8208 | NULL /* breakpoint_ops */, | |
8209 | from_tty, | |
84f4c1fe PM |
8210 | 1 /* enabled */, |
8211 | 0 /* internal */); | |
c906108c SS |
8212 | } |
8213 | ||
72b2ff0e | 8214 | |
c906108c SS |
8215 | /* Helper function for break_command_1 and disassemble_command. */ |
8216 | ||
8217 | void | |
fba45db2 | 8218 | resolve_sal_pc (struct symtab_and_line *sal) |
c906108c SS |
8219 | { |
8220 | CORE_ADDR pc; | |
8221 | ||
8222 | if (sal->pc == 0 && sal->symtab != NULL) | |
8223 | { | |
8224 | if (!find_line_pc (sal->symtab, sal->line, &pc)) | |
8a3fe4f8 | 8225 | error (_("No line %d in file \"%s\"."), |
c906108c SS |
8226 | sal->line, sal->symtab->filename); |
8227 | sal->pc = pc; | |
6a048695 | 8228 | |
4a64f543 MS |
8229 | /* If this SAL corresponds to a breakpoint inserted using a line |
8230 | number, then skip the function prologue if necessary. */ | |
6a048695 | 8231 | if (sal->explicit_line) |
059acae7 | 8232 | skip_prologue_sal (sal); |
c906108c SS |
8233 | } |
8234 | ||
8235 | if (sal->section == 0 && sal->symtab != NULL) | |
8236 | { | |
8237 | struct blockvector *bv; | |
c5aa993b JM |
8238 | struct block *b; |
8239 | struct symbol *sym; | |
c906108c | 8240 | |
801e3a5b | 8241 | bv = blockvector_for_pc_sect (sal->pc, 0, &b, sal->symtab); |
c906108c SS |
8242 | if (bv != NULL) |
8243 | { | |
7f0df278 | 8244 | sym = block_linkage_function (b); |
c906108c SS |
8245 | if (sym != NULL) |
8246 | { | |
8247 | fixup_symbol_section (sym, sal->symtab->objfile); | |
714835d5 | 8248 | sal->section = SYMBOL_OBJ_SECTION (sym); |
c906108c SS |
8249 | } |
8250 | else | |
8251 | { | |
4a64f543 MS |
8252 | /* It really is worthwhile to have the section, so we'll |
8253 | just have to look harder. This case can be executed | |
8254 | if we have line numbers but no functions (as can | |
8255 | happen in assembly source). */ | |
c906108c | 8256 | |
c5aa993b | 8257 | struct minimal_symbol *msym; |
6c95b8df PA |
8258 | struct cleanup *old_chain = save_current_space_and_thread (); |
8259 | ||
8260 | switch_to_program_space_and_thread (sal->pspace); | |
c906108c SS |
8261 | |
8262 | msym = lookup_minimal_symbol_by_pc (sal->pc); | |
8263 | if (msym) | |
714835d5 | 8264 | sal->section = SYMBOL_OBJ_SECTION (msym); |
6c95b8df PA |
8265 | |
8266 | do_cleanups (old_chain); | |
c906108c SS |
8267 | } |
8268 | } | |
8269 | } | |
8270 | } | |
8271 | ||
8272 | void | |
fba45db2 | 8273 | break_command (char *arg, int from_tty) |
c906108c | 8274 | { |
db107f19 | 8275 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8276 | } |
8277 | ||
c906108c | 8278 | void |
fba45db2 | 8279 | tbreak_command (char *arg, int from_tty) |
c906108c | 8280 | { |
db107f19 | 8281 | break_command_1 (arg, BP_TEMPFLAG, from_tty); |
c906108c SS |
8282 | } |
8283 | ||
c906108c | 8284 | static void |
fba45db2 | 8285 | hbreak_command (char *arg, int from_tty) |
c906108c | 8286 | { |
db107f19 | 8287 | break_command_1 (arg, BP_HARDWAREFLAG, from_tty); |
c906108c SS |
8288 | } |
8289 | ||
8290 | static void | |
fba45db2 | 8291 | thbreak_command (char *arg, int from_tty) |
c906108c | 8292 | { |
db107f19 | 8293 | break_command_1 (arg, (BP_TEMPFLAG | BP_HARDWAREFLAG), from_tty); |
c906108c SS |
8294 | } |
8295 | ||
8296 | static void | |
fba45db2 | 8297 | stop_command (char *arg, int from_tty) |
c906108c | 8298 | { |
a3f17187 | 8299 | printf_filtered (_("Specify the type of breakpoint to set.\n\ |
c906108c | 8300 | Usage: stop in <function | address>\n\ |
a3f17187 | 8301 | stop at <line>\n")); |
c906108c SS |
8302 | } |
8303 | ||
8304 | static void | |
fba45db2 | 8305 | stopin_command (char *arg, int from_tty) |
c906108c SS |
8306 | { |
8307 | int badInput = 0; | |
8308 | ||
c5aa993b | 8309 | if (arg == (char *) NULL) |
c906108c SS |
8310 | badInput = 1; |
8311 | else if (*arg != '*') | |
8312 | { | |
8313 | char *argptr = arg; | |
8314 | int hasColon = 0; | |
8315 | ||
4a64f543 | 8316 | /* Look for a ':'. If this is a line number specification, then |
53a5351d | 8317 | say it is bad, otherwise, it should be an address or |
4a64f543 | 8318 | function/method name. */ |
c906108c | 8319 | while (*argptr && !hasColon) |
c5aa993b JM |
8320 | { |
8321 | hasColon = (*argptr == ':'); | |
8322 | argptr++; | |
8323 | } | |
c906108c SS |
8324 | |
8325 | if (hasColon) | |
c5aa993b | 8326 | badInput = (*argptr != ':'); /* Not a class::method */ |
c906108c | 8327 | else |
c5aa993b | 8328 | badInput = isdigit (*arg); /* a simple line number */ |
c906108c SS |
8329 | } |
8330 | ||
8331 | if (badInput) | |
a3f17187 | 8332 | printf_filtered (_("Usage: stop in <function | address>\n")); |
c906108c | 8333 | else |
db107f19 | 8334 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8335 | } |
8336 | ||
8337 | static void | |
fba45db2 | 8338 | stopat_command (char *arg, int from_tty) |
c906108c SS |
8339 | { |
8340 | int badInput = 0; | |
8341 | ||
c5aa993b | 8342 | if (arg == (char *) NULL || *arg == '*') /* no line number */ |
c906108c SS |
8343 | badInput = 1; |
8344 | else | |
8345 | { | |
8346 | char *argptr = arg; | |
8347 | int hasColon = 0; | |
8348 | ||
4a64f543 MS |
8349 | /* Look for a ':'. If there is a '::' then get out, otherwise |
8350 | it is probably a line number. */ | |
c906108c | 8351 | while (*argptr && !hasColon) |
c5aa993b JM |
8352 | { |
8353 | hasColon = (*argptr == ':'); | |
8354 | argptr++; | |
8355 | } | |
c906108c SS |
8356 | |
8357 | if (hasColon) | |
c5aa993b | 8358 | badInput = (*argptr == ':'); /* we have class::method */ |
c906108c | 8359 | else |
c5aa993b | 8360 | badInput = !isdigit (*arg); /* not a line number */ |
c906108c SS |
8361 | } |
8362 | ||
8363 | if (badInput) | |
a3f17187 | 8364 | printf_filtered (_("Usage: stop at <line>\n")); |
c906108c | 8365 | else |
db107f19 | 8366 | break_command_1 (arg, 0, from_tty); |
c906108c SS |
8367 | } |
8368 | ||
f1310107 TJB |
8369 | /* Implement the "breakpoint_hit" breakpoint_ops method for |
8370 | ranged breakpoints. */ | |
8371 | ||
8372 | static int | |
8373 | breakpoint_hit_ranged_breakpoint (const struct bp_location *bl, | |
8374 | struct address_space *aspace, | |
8375 | CORE_ADDR bp_addr) | |
8376 | { | |
8377 | return breakpoint_address_match_range (bl->pspace->aspace, bl->address, | |
8378 | bl->length, aspace, bp_addr); | |
8379 | } | |
8380 | ||
8381 | /* Implement the "resources_needed" breakpoint_ops method for | |
8382 | ranged breakpoints. */ | |
8383 | ||
8384 | static int | |
8385 | resources_needed_ranged_breakpoint (const struct bp_location *bl) | |
8386 | { | |
8387 | return target_ranged_break_num_registers (); | |
8388 | } | |
8389 | ||
8390 | /* Implement the "print_it" breakpoint_ops method for | |
8391 | ranged breakpoints. */ | |
8392 | ||
8393 | static enum print_stop_action | |
8394 | print_it_ranged_breakpoint (struct breakpoint *b) | |
8395 | { | |
8396 | struct bp_location *bl = b->loc; | |
8397 | ||
8398 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8399 | ||
8400 | /* Ranged breakpoints have only one location. */ | |
8401 | gdb_assert (bl && bl->next == NULL); | |
8402 | ||
8403 | annotate_breakpoint (b->number); | |
8404 | if (b->disposition == disp_del) | |
8405 | ui_out_text (uiout, "\nTemporary ranged breakpoint "); | |
8406 | else | |
8407 | ui_out_text (uiout, "\nRanged breakpoint "); | |
8408 | if (ui_out_is_mi_like_p (uiout)) | |
8409 | { | |
8410 | ui_out_field_string (uiout, "reason", | |
8411 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
8412 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
8413 | } | |
8414 | ui_out_field_int (uiout, "bkptno", b->number); | |
8415 | ui_out_text (uiout, ", "); | |
8416 | ||
8417 | return PRINT_SRC_AND_LOC; | |
8418 | } | |
8419 | ||
8420 | /* Implement the "print_one" breakpoint_ops method for | |
8421 | ranged breakpoints. */ | |
8422 | ||
8423 | static void | |
8424 | print_one_ranged_breakpoint (struct breakpoint *b, | |
8425 | struct bp_location **last_loc) | |
8426 | { | |
8427 | struct bp_location *bl = b->loc; | |
8428 | struct value_print_options opts; | |
8429 | ||
8430 | /* Ranged breakpoints have only one location. */ | |
8431 | gdb_assert (bl && bl->next == NULL); | |
8432 | ||
8433 | get_user_print_options (&opts); | |
8434 | ||
8435 | if (opts.addressprint) | |
8436 | /* We don't print the address range here, it will be printed later | |
8437 | by print_one_detail_ranged_breakpoint. */ | |
8438 | ui_out_field_skip (uiout, "addr"); | |
8439 | annotate_field (5); | |
8440 | print_breakpoint_location (b, bl); | |
8441 | *last_loc = bl; | |
8442 | } | |
8443 | ||
8444 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8445 | ranged breakpoints. */ | |
8446 | ||
8447 | static void | |
8448 | print_one_detail_ranged_breakpoint (const struct breakpoint *b, | |
8449 | struct ui_out *uiout) | |
8450 | { | |
8451 | CORE_ADDR address_start, address_end; | |
8452 | struct bp_location *bl = b->loc; | |
8453 | struct ui_stream *stb = ui_out_stream_new (uiout); | |
8454 | struct cleanup *cleanup = make_cleanup_ui_out_stream_delete (stb); | |
8455 | ||
8456 | gdb_assert (bl); | |
8457 | ||
8458 | address_start = bl->address; | |
8459 | address_end = address_start + bl->length - 1; | |
8460 | ||
8461 | ui_out_text (uiout, "\taddress range: "); | |
8462 | fprintf_unfiltered (stb->stream, "[%s, %s]", | |
8463 | print_core_address (bl->gdbarch, address_start), | |
8464 | print_core_address (bl->gdbarch, address_end)); | |
8465 | ui_out_field_stream (uiout, "addr", stb); | |
8466 | ui_out_text (uiout, "\n"); | |
8467 | ||
8468 | do_cleanups (cleanup); | |
8469 | } | |
8470 | ||
8471 | /* Implement the "print_mention" breakpoint_ops method for | |
8472 | ranged breakpoints. */ | |
8473 | ||
8474 | static void | |
8475 | print_mention_ranged_breakpoint (struct breakpoint *b) | |
8476 | { | |
8477 | struct bp_location *bl = b->loc; | |
8478 | ||
8479 | gdb_assert (bl); | |
8480 | gdb_assert (b->type == bp_hardware_breakpoint); | |
8481 | ||
8482 | if (ui_out_is_mi_like_p (uiout)) | |
8483 | return; | |
8484 | ||
8485 | printf_filtered (_("Hardware assisted ranged breakpoint %d from %s to %s."), | |
8486 | b->number, paddress (bl->gdbarch, bl->address), | |
8487 | paddress (bl->gdbarch, bl->address + bl->length - 1)); | |
8488 | } | |
8489 | ||
8490 | /* Implement the "print_recreate" breakpoint_ops method for | |
8491 | ranged breakpoints. */ | |
8492 | ||
8493 | static void | |
8494 | print_recreate_ranged_breakpoint (struct breakpoint *b, struct ui_file *fp) | |
8495 | { | |
8496 | fprintf_unfiltered (fp, "break-range %s, %s", b->addr_string, | |
8497 | b->addr_string_range_end); | |
8498 | } | |
8499 | ||
8500 | /* The breakpoint_ops structure to be used in ranged breakpoints. */ | |
8501 | ||
8502 | static struct breakpoint_ops ranged_breakpoint_ops = | |
8503 | { | |
8504 | NULL, /* insert */ | |
8505 | NULL, /* remove */ | |
8506 | breakpoint_hit_ranged_breakpoint, | |
8507 | resources_needed_ranged_breakpoint, | |
9c06b0b4 | 8508 | NULL, /* works_in_software_mode */ |
f1310107 TJB |
8509 | print_it_ranged_breakpoint, |
8510 | print_one_ranged_breakpoint, | |
8511 | print_one_detail_ranged_breakpoint, | |
8512 | print_mention_ranged_breakpoint, | |
8513 | print_recreate_ranged_breakpoint | |
8514 | }; | |
8515 | ||
8516 | /* Find the address where the end of the breakpoint range should be | |
8517 | placed, given the SAL of the end of the range. This is so that if | |
8518 | the user provides a line number, the end of the range is set to the | |
8519 | last instruction of the given line. */ | |
8520 | ||
8521 | static CORE_ADDR | |
8522 | find_breakpoint_range_end (struct symtab_and_line sal) | |
8523 | { | |
8524 | CORE_ADDR end; | |
8525 | ||
8526 | /* If the user provided a PC value, use it. Otherwise, | |
8527 | find the address of the end of the given location. */ | |
8528 | if (sal.explicit_pc) | |
8529 | end = sal.pc; | |
8530 | else | |
8531 | { | |
8532 | int ret; | |
8533 | CORE_ADDR start; | |
8534 | ||
8535 | ret = find_line_pc_range (sal, &start, &end); | |
8536 | if (!ret) | |
8537 | error (_("Could not find location of the end of the range.")); | |
8538 | ||
8539 | /* find_line_pc_range returns the start of the next line. */ | |
8540 | end--; | |
8541 | } | |
8542 | ||
8543 | return end; | |
8544 | } | |
8545 | ||
8546 | /* Implement the "break-range" CLI command. */ | |
8547 | ||
8548 | static void | |
8549 | break_range_command (char *arg, int from_tty) | |
8550 | { | |
8551 | char *arg_start, *addr_string_start, *addr_string_end; | |
8552 | struct linespec_result canonical_start, canonical_end; | |
8553 | int bp_count, can_use_bp, length; | |
8554 | CORE_ADDR end; | |
8555 | struct breakpoint *b; | |
8556 | struct symtab_and_line sal_start, sal_end; | |
8557 | struct symtabs_and_lines sals_start, sals_end; | |
8558 | struct cleanup *cleanup_bkpt; | |
8559 | ||
8560 | /* We don't support software ranged breakpoints. */ | |
8561 | if (target_ranged_break_num_registers () < 0) | |
8562 | error (_("This target does not support hardware ranged breakpoints.")); | |
8563 | ||
8564 | bp_count = hw_breakpoint_used_count (); | |
8565 | bp_count += target_ranged_break_num_registers (); | |
8566 | can_use_bp = target_can_use_hardware_watchpoint (bp_hardware_breakpoint, | |
8567 | bp_count, 0); | |
8568 | if (can_use_bp < 0) | |
8569 | error (_("Hardware breakpoints used exceeds limit.")); | |
8570 | ||
8571 | if (arg == NULL || arg[0] == '\0') | |
8572 | error(_("No address range specified.")); | |
8573 | ||
8574 | sals_start.sals = NULL; | |
8575 | sals_start.nelts = 0; | |
8576 | init_linespec_result (&canonical_start); | |
8577 | ||
8578 | while (*arg == ' ' || *arg == '\t') | |
8579 | arg++; | |
8580 | ||
58438ac1 | 8581 | parse_breakpoint_sals (&arg, &sals_start, &canonical_start); |
f1310107 TJB |
8582 | |
8583 | sal_start = sals_start.sals[0]; | |
8584 | addr_string_start = canonical_start.canonical[0]; | |
8585 | cleanup_bkpt = make_cleanup (xfree, addr_string_start); | |
8586 | xfree (sals_start.sals); | |
8587 | xfree (canonical_start.canonical); | |
8588 | ||
8589 | if (arg[0] != ',') | |
8590 | error (_("Too few arguments.")); | |
8591 | else if (sals_start.nelts == 0) | |
8592 | error (_("Could not find location of the beginning of the range.")); | |
8593 | else if (sals_start.nelts != 1) | |
8594 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8595 | ||
8596 | resolve_sal_pc (&sal_start); | |
8597 | ||
8598 | arg++; /* Skip the comma. */ | |
8599 | while (*arg == ' ' || *arg == '\t') | |
8600 | arg++; | |
8601 | ||
8602 | /* Parse the end location. */ | |
8603 | ||
8604 | sals_end.sals = NULL; | |
8605 | sals_end.nelts = 0; | |
8606 | init_linespec_result (&canonical_end); | |
8607 | arg_start = arg; | |
8608 | ||
423f41a5 | 8609 | /* We call decode_line_1 directly here instead of using |
f1310107 TJB |
8610 | parse_breakpoint_sals because we need to specify the start location's |
8611 | symtab and line as the default symtab and line for the end of the | |
8612 | range. This makes it possible to have ranges like "foo.c:27, +14", | |
8613 | where +14 means 14 lines from the start location. */ | |
8614 | sals_end = decode_line_1 (&arg, 1, sal_start.symtab, sal_start.line, | |
58438ac1 | 8615 | &canonical_end); |
f1310107 TJB |
8616 | |
8617 | /* canonical_end can be NULL if it was of the form "*0xdeadbeef". */ | |
8618 | if (canonical_end.canonical == NULL) | |
38a714bb | 8619 | canonical_end.canonical = xcalloc (1, sizeof (char *)); |
f1310107 TJB |
8620 | /* Add the string if not present. */ |
8621 | if (arg_start != arg && canonical_end.canonical[0] == NULL) | |
8622 | canonical_end.canonical[0] = savestring (arg_start, arg - arg_start); | |
8623 | ||
8624 | sal_end = sals_end.sals[0]; | |
8625 | addr_string_end = canonical_end.canonical[0]; | |
8626 | make_cleanup (xfree, addr_string_end); | |
8627 | xfree (sals_end.sals); | |
8628 | xfree (canonical_end.canonical); | |
8629 | ||
8630 | if (sals_end.nelts == 0) | |
8631 | error (_("Could not find location of the end of the range.")); | |
8632 | else if (sals_end.nelts != 1) | |
8633 | error (_("Cannot create a ranged breakpoint with multiple locations.")); | |
8634 | ||
8635 | resolve_sal_pc (&sal_end); | |
8636 | ||
8637 | end = find_breakpoint_range_end (sal_end); | |
8638 | if (sal_start.pc > end) | |
8639 | error (_("Invalid address range, end preceeds start.")); | |
8640 | ||
8641 | length = end - sal_start.pc + 1; | |
8642 | if (length < 0) | |
8643 | /* Length overflowed. */ | |
8644 | error (_("Address range too large.")); | |
8645 | else if (length == 1) | |
8646 | { | |
8647 | /* This range is simple enough to be handled by | |
8648 | the `hbreak' command. */ | |
8649 | hbreak_command (addr_string_start, 1); | |
8650 | ||
8651 | do_cleanups (cleanup_bkpt); | |
8652 | ||
8653 | return; | |
8654 | } | |
8655 | ||
8656 | /* Now set up the breakpoint. */ | |
8657 | b = set_raw_breakpoint (get_current_arch (), sal_start, | |
8658 | bp_hardware_breakpoint); | |
8659 | set_breakpoint_count (breakpoint_count + 1); | |
8660 | b->number = breakpoint_count; | |
8661 | b->disposition = disp_donttouch; | |
8662 | b->addr_string = addr_string_start; | |
8663 | b->addr_string_range_end = addr_string_end; | |
8664 | b->ops = &ranged_breakpoint_ops; | |
8665 | b->loc->length = length; | |
8666 | ||
8667 | discard_cleanups (cleanup_bkpt); | |
8668 | ||
8669 | mention (b); | |
8d3788bd | 8670 | observer_notify_breakpoint_created (b); |
f1310107 TJB |
8671 | update_global_location_list (1); |
8672 | } | |
8673 | ||
4a64f543 MS |
8674 | /* Return non-zero if EXP is verified as constant. Returned zero |
8675 | means EXP is variable. Also the constant detection may fail for | |
8676 | some constant expressions and in such case still falsely return | |
8677 | zero. */ | |
65d79d4b SDJ |
8678 | static int |
8679 | watchpoint_exp_is_const (const struct expression *exp) | |
8680 | { | |
8681 | int i = exp->nelts; | |
8682 | ||
8683 | while (i > 0) | |
8684 | { | |
8685 | int oplenp, argsp; | |
8686 | ||
8687 | /* We are only interested in the descriptor of each element. */ | |
8688 | operator_length (exp, i, &oplenp, &argsp); | |
8689 | i -= oplenp; | |
8690 | ||
8691 | switch (exp->elts[i].opcode) | |
8692 | { | |
8693 | case BINOP_ADD: | |
8694 | case BINOP_SUB: | |
8695 | case BINOP_MUL: | |
8696 | case BINOP_DIV: | |
8697 | case BINOP_REM: | |
8698 | case BINOP_MOD: | |
8699 | case BINOP_LSH: | |
8700 | case BINOP_RSH: | |
8701 | case BINOP_LOGICAL_AND: | |
8702 | case BINOP_LOGICAL_OR: | |
8703 | case BINOP_BITWISE_AND: | |
8704 | case BINOP_BITWISE_IOR: | |
8705 | case BINOP_BITWISE_XOR: | |
8706 | case BINOP_EQUAL: | |
8707 | case BINOP_NOTEQUAL: | |
8708 | case BINOP_LESS: | |
8709 | case BINOP_GTR: | |
8710 | case BINOP_LEQ: | |
8711 | case BINOP_GEQ: | |
8712 | case BINOP_REPEAT: | |
8713 | case BINOP_COMMA: | |
8714 | case BINOP_EXP: | |
8715 | case BINOP_MIN: | |
8716 | case BINOP_MAX: | |
8717 | case BINOP_INTDIV: | |
8718 | case BINOP_CONCAT: | |
8719 | case BINOP_IN: | |
8720 | case BINOP_RANGE: | |
8721 | case TERNOP_COND: | |
8722 | case TERNOP_SLICE: | |
8723 | case TERNOP_SLICE_COUNT: | |
8724 | ||
8725 | case OP_LONG: | |
8726 | case OP_DOUBLE: | |
8727 | case OP_DECFLOAT: | |
8728 | case OP_LAST: | |
8729 | case OP_COMPLEX: | |
8730 | case OP_STRING: | |
8731 | case OP_BITSTRING: | |
8732 | case OP_ARRAY: | |
8733 | case OP_TYPE: | |
8734 | case OP_NAME: | |
8735 | case OP_OBJC_NSSTRING: | |
8736 | ||
8737 | case UNOP_NEG: | |
8738 | case UNOP_LOGICAL_NOT: | |
8739 | case UNOP_COMPLEMENT: | |
8740 | case UNOP_ADDR: | |
8741 | case UNOP_HIGH: | |
4a64f543 MS |
8742 | /* Unary, binary and ternary operators: We have to check |
8743 | their operands. If they are constant, then so is the | |
8744 | result of that operation. For instance, if A and B are | |
8745 | determined to be constants, then so is "A + B". | |
8746 | ||
8747 | UNOP_IND is one exception to the rule above, because the | |
8748 | value of *ADDR is not necessarily a constant, even when | |
8749 | ADDR is. */ | |
65d79d4b SDJ |
8750 | break; |
8751 | ||
8752 | case OP_VAR_VALUE: | |
8753 | /* Check whether the associated symbol is a constant. | |
4a64f543 | 8754 | |
65d79d4b | 8755 | We use SYMBOL_CLASS rather than TYPE_CONST because it's |
4a64f543 MS |
8756 | possible that a buggy compiler could mark a variable as |
8757 | constant even when it is not, and TYPE_CONST would return | |
8758 | true in this case, while SYMBOL_CLASS wouldn't. | |
8759 | ||
8760 | We also have to check for function symbols because they | |
8761 | are always constant. */ | |
65d79d4b SDJ |
8762 | { |
8763 | struct symbol *s = exp->elts[i + 2].symbol; | |
8764 | ||
8765 | if (SYMBOL_CLASS (s) != LOC_BLOCK | |
8766 | && SYMBOL_CLASS (s) != LOC_CONST | |
8767 | && SYMBOL_CLASS (s) != LOC_CONST_BYTES) | |
8768 | return 0; | |
8769 | break; | |
8770 | } | |
8771 | ||
8772 | /* The default action is to return 0 because we are using | |
8773 | the optimistic approach here: If we don't know something, | |
8774 | then it is not a constant. */ | |
8775 | default: | |
8776 | return 0; | |
8777 | } | |
8778 | } | |
8779 | ||
8780 | return 1; | |
8781 | } | |
8782 | ||
77b06cd7 TJB |
8783 | /* Implement the "insert" breakpoint_ops method for hardware watchpoints. */ |
8784 | ||
8785 | static int | |
8786 | insert_watchpoint (struct bp_location *bl) | |
8787 | { | |
e09342b5 TJB |
8788 | int length = bl->owner->exact? 1 : bl->length; |
8789 | ||
8790 | return target_insert_watchpoint (bl->address, length, bl->watchpoint_type, | |
8791 | bl->owner->cond_exp); | |
77b06cd7 TJB |
8792 | } |
8793 | ||
8794 | /* Implement the "remove" breakpoint_ops method for hardware watchpoints. */ | |
8795 | ||
8796 | static int | |
8797 | remove_watchpoint (struct bp_location *bl) | |
8798 | { | |
e09342b5 TJB |
8799 | int length = bl->owner->exact? 1 : bl->length; |
8800 | ||
8801 | return target_remove_watchpoint (bl->address, length, bl->watchpoint_type, | |
8802 | bl->owner->cond_exp); | |
8803 | } | |
8804 | ||
8805 | /* Implement the "resources_needed" breakpoint_ops method for | |
8806 | hardware watchpoints. */ | |
8807 | ||
8808 | static int | |
8809 | resources_needed_watchpoint (const struct bp_location *bl) | |
8810 | { | |
90e4670f | 8811 | int length = bl->owner->exact? 1 : bl->length; |
e09342b5 | 8812 | |
90e4670f | 8813 | return target_region_ok_for_hw_watchpoint (bl->address, length); |
77b06cd7 TJB |
8814 | } |
8815 | ||
9c06b0b4 TJB |
8816 | /* Implement the "works_in_software_mode" breakpoint_ops method for |
8817 | hardware watchpoints. */ | |
8818 | ||
8819 | int | |
8820 | works_in_software_mode_watchpoint (const struct breakpoint *b) | |
8821 | { | |
8822 | return b->type == bp_hardware_watchpoint; | |
8823 | } | |
8824 | ||
77b06cd7 TJB |
8825 | /* The breakpoint_ops structure to be used in hardware watchpoints. */ |
8826 | ||
8827 | static struct breakpoint_ops watchpoint_breakpoint_ops = | |
8828 | { | |
8829 | insert_watchpoint, | |
8830 | remove_watchpoint, | |
8831 | NULL, /* breakpoint_hit */ | |
e09342b5 | 8832 | resources_needed_watchpoint, |
9c06b0b4 | 8833 | works_in_software_mode_watchpoint, |
77b06cd7 TJB |
8834 | NULL, /* print_it */ |
8835 | NULL, /* print_one */ | |
f1310107 | 8836 | NULL, /* print_one_detail */ |
77b06cd7 TJB |
8837 | NULL, /* print_mention */ |
8838 | NULL /* print_recreate */ | |
8839 | }; | |
8840 | ||
9c06b0b4 TJB |
8841 | /* Implement the "insert" breakpoint_ops method for |
8842 | masked hardware watchpoints. */ | |
8843 | ||
8844 | static int | |
8845 | insert_masked_watchpoint (struct bp_location *bl) | |
8846 | { | |
8847 | return target_insert_mask_watchpoint (bl->address, bl->owner->hw_wp_mask, | |
8848 | bl->watchpoint_type); | |
8849 | } | |
8850 | ||
8851 | /* Implement the "remove" breakpoint_ops method for | |
8852 | masked hardware watchpoints. */ | |
8853 | ||
8854 | static int | |
8855 | remove_masked_watchpoint (struct bp_location *bl) | |
8856 | { | |
8857 | return target_remove_mask_watchpoint (bl->address, bl->owner->hw_wp_mask, | |
8858 | bl->watchpoint_type); | |
8859 | } | |
8860 | ||
8861 | /* Implement the "resources_needed" breakpoint_ops method for | |
8862 | masked hardware watchpoints. */ | |
8863 | ||
8864 | static int | |
8865 | resources_needed_masked_watchpoint (const struct bp_location *bl) | |
8866 | { | |
8867 | return target_masked_watch_num_registers (bl->address, | |
8868 | bl->owner->hw_wp_mask); | |
8869 | } | |
8870 | ||
8871 | /* Implement the "works_in_software_mode" breakpoint_ops method for | |
8872 | masked hardware watchpoints. */ | |
8873 | ||
8874 | static int | |
8875 | works_in_software_mode_masked_watchpoint (const struct breakpoint *b) | |
8876 | { | |
8877 | return 0; | |
8878 | } | |
8879 | ||
8880 | /* Implement the "print_it" breakpoint_ops method for | |
8881 | masked hardware watchpoints. */ | |
8882 | ||
8883 | static enum print_stop_action | |
8884 | print_it_masked_watchpoint (struct breakpoint *b) | |
8885 | { | |
8886 | /* Masked watchpoints have only one location. */ | |
8887 | gdb_assert (b->loc && b->loc->next == NULL); | |
8888 | ||
8889 | switch (b->type) | |
8890 | { | |
8891 | case bp_hardware_watchpoint: | |
8892 | annotate_watchpoint (b->number); | |
8893 | if (ui_out_is_mi_like_p (uiout)) | |
8894 | ui_out_field_string | |
8895 | (uiout, "reason", | |
8896 | async_reason_lookup (EXEC_ASYNC_WATCHPOINT_TRIGGER)); | |
8897 | break; | |
8898 | ||
8899 | case bp_read_watchpoint: | |
8900 | if (ui_out_is_mi_like_p (uiout)) | |
8901 | ui_out_field_string | |
8902 | (uiout, "reason", | |
8903 | async_reason_lookup (EXEC_ASYNC_READ_WATCHPOINT_TRIGGER)); | |
8904 | break; | |
8905 | ||
8906 | case bp_access_watchpoint: | |
8907 | if (ui_out_is_mi_like_p (uiout)) | |
8908 | ui_out_field_string | |
8909 | (uiout, "reason", | |
8910 | async_reason_lookup (EXEC_ASYNC_ACCESS_WATCHPOINT_TRIGGER)); | |
8911 | break; | |
8912 | default: | |
8913 | internal_error (__FILE__, __LINE__, | |
8914 | _("Invalid hardware watchpoint type.")); | |
8915 | } | |
8916 | ||
8917 | mention (b); | |
8918 | ui_out_text (uiout, _("\n\ | |
8919 | Check the underlying instruction at PC for the memory\n\ | |
8920 | address and value which triggered this watchpoint.\n")); | |
8921 | ui_out_text (uiout, "\n"); | |
8922 | ||
8923 | /* More than one watchpoint may have been triggered. */ | |
8924 | return PRINT_UNKNOWN; | |
8925 | } | |
8926 | ||
8927 | /* Implement the "print_one_detail" breakpoint_ops method for | |
8928 | masked hardware watchpoints. */ | |
8929 | ||
8930 | static void | |
8931 | print_one_detail_masked_watchpoint (const struct breakpoint *b, | |
8932 | struct ui_out *uiout) | |
8933 | { | |
8934 | /* Masked watchpoints have only one location. */ | |
8935 | gdb_assert (b->loc && b->loc->next == NULL); | |
8936 | ||
8937 | ui_out_text (uiout, "\tmask "); | |
8938 | ui_out_field_core_addr (uiout, "mask", b->loc->gdbarch, b->hw_wp_mask); | |
8939 | ui_out_text (uiout, "\n"); | |
8940 | } | |
8941 | ||
8942 | /* Implement the "print_mention" breakpoint_ops method for | |
8943 | masked hardware watchpoints. */ | |
8944 | ||
8945 | static void | |
8946 | print_mention_masked_watchpoint (struct breakpoint *b) | |
8947 | { | |
8948 | struct cleanup *ui_out_chain; | |
8949 | ||
8950 | switch (b->type) | |
8951 | { | |
8952 | case bp_hardware_watchpoint: | |
8953 | ui_out_text (uiout, "Masked hardware watchpoint "); | |
8954 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "wpt"); | |
8955 | break; | |
8956 | case bp_read_watchpoint: | |
8957 | ui_out_text (uiout, "Masked hardware read watchpoint "); | |
8958 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-rwpt"); | |
8959 | break; | |
8960 | case bp_access_watchpoint: | |
8961 | ui_out_text (uiout, "Masked hardware access (read/write) watchpoint "); | |
8962 | ui_out_chain = make_cleanup_ui_out_tuple_begin_end (uiout, "hw-awpt"); | |
8963 | break; | |
8964 | default: | |
8965 | internal_error (__FILE__, __LINE__, | |
8966 | _("Invalid hardware watchpoint type.")); | |
8967 | } | |
8968 | ||
8969 | ui_out_field_int (uiout, "number", b->number); | |
8970 | ui_out_text (uiout, ": "); | |
8971 | ui_out_field_string (uiout, "exp", b->exp_string); | |
8972 | do_cleanups (ui_out_chain); | |
8973 | } | |
8974 | ||
8975 | /* Implement the "print_recreate" breakpoint_ops method for | |
8976 | masked hardware watchpoints. */ | |
8977 | ||
8978 | static void | |
8979 | print_recreate_masked_watchpoint (struct breakpoint *b, struct ui_file *fp) | |
8980 | { | |
8981 | char tmp[40]; | |
8982 | ||
8983 | switch (b->type) | |
8984 | { | |
8985 | case bp_hardware_watchpoint: | |
8986 | fprintf_unfiltered (fp, "watch"); | |
8987 | break; | |
8988 | case bp_read_watchpoint: | |
8989 | fprintf_unfiltered (fp, "rwatch"); | |
8990 | break; | |
8991 | case bp_access_watchpoint: | |
8992 | fprintf_unfiltered (fp, "awatch"); | |
8993 | break; | |
8994 | default: | |
8995 | internal_error (__FILE__, __LINE__, | |
8996 | _("Invalid hardware watchpoint type.")); | |
8997 | } | |
8998 | ||
8999 | sprintf_vma (tmp, b->hw_wp_mask); | |
9000 | fprintf_unfiltered (fp, " %s mask 0x%s", b->exp_string, tmp); | |
9001 | } | |
9002 | ||
9003 | /* The breakpoint_ops structure to be used in masked hardware watchpoints. */ | |
9004 | ||
9005 | static struct breakpoint_ops masked_watchpoint_breakpoint_ops = | |
9006 | { | |
9007 | insert_masked_watchpoint, | |
9008 | remove_masked_watchpoint, | |
9009 | NULL, /* breakpoint_hit */ | |
9010 | resources_needed_masked_watchpoint, | |
9011 | works_in_software_mode_masked_watchpoint, | |
9012 | print_it_masked_watchpoint, | |
9013 | NULL, /* print_one */ | |
9014 | print_one_detail_masked_watchpoint, | |
9015 | print_mention_masked_watchpoint, | |
9016 | print_recreate_masked_watchpoint | |
9017 | }; | |
9018 | ||
9019 | /* Tell whether the given watchpoint is a masked hardware watchpoint. */ | |
9020 | ||
9021 | static int | |
9022 | is_masked_watchpoint (const struct breakpoint *b) | |
9023 | { | |
9024 | return b->ops == &masked_watchpoint_breakpoint_ops; | |
9025 | } | |
9026 | ||
53a5351d JM |
9027 | /* accessflag: hw_write: watch write, |
9028 | hw_read: watch read, | |
9029 | hw_access: watch access (read or write) */ | |
c906108c | 9030 | static void |
84f4c1fe PM |
9031 | watch_command_1 (char *arg, int accessflag, int from_tty, |
9032 | int just_location, int internal) | |
c906108c | 9033 | { |
a9634178 | 9034 | volatile struct gdb_exception e; |
d983da9c | 9035 | struct breakpoint *b, *scope_breakpoint = NULL; |
c906108c | 9036 | struct expression *exp; |
60e1c644 | 9037 | struct block *exp_valid_block = NULL, *cond_exp_valid_block = NULL; |
a1442452 | 9038 | struct value *val, *mark, *result; |
c906108c | 9039 | struct frame_info *frame; |
c906108c SS |
9040 | char *exp_start = NULL; |
9041 | char *exp_end = NULL; | |
9c06b0b4 TJB |
9042 | char *tok, *end_tok; |
9043 | int toklen = -1; | |
c906108c SS |
9044 | char *cond_start = NULL; |
9045 | char *cond_end = NULL; | |
c906108c | 9046 | enum bptype bp_type; |
37e4754d | 9047 | int thread = -1; |
0cf6dd15 | 9048 | int pc = 0; |
9c06b0b4 TJB |
9049 | /* Flag to indicate whether we are going to use masks for |
9050 | the hardware watchpoint. */ | |
9051 | int use_mask = 0; | |
9052 | CORE_ADDR mask = 0; | |
c906108c | 9053 | |
37e4754d LM |
9054 | /* Make sure that we actually have parameters to parse. */ |
9055 | if (arg != NULL && arg[0] != '\0') | |
9056 | { | |
9c06b0b4 | 9057 | char *value_start; |
37e4754d | 9058 | |
9c06b0b4 TJB |
9059 | /* Look for "parameter value" pairs at the end |
9060 | of the arguments string. */ | |
9061 | for (tok = arg + strlen (arg) - 1; tok > arg; tok--) | |
9062 | { | |
9063 | /* Skip whitespace at the end of the argument list. */ | |
9064 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9065 | tok--; | |
9066 | ||
9067 | /* Find the beginning of the last token. | |
9068 | This is the value of the parameter. */ | |
9069 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9070 | tok--; | |
9071 | value_start = tok + 1; | |
9072 | ||
9073 | /* Skip whitespace. */ | |
9074 | while (tok > arg && (*tok == ' ' || *tok == '\t')) | |
9075 | tok--; | |
9076 | ||
9077 | end_tok = tok; | |
9078 | ||
9079 | /* Find the beginning of the second to last token. | |
9080 | This is the parameter itself. */ | |
9081 | while (tok > arg && (*tok != ' ' && *tok != '\t')) | |
9082 | tok--; | |
9083 | tok++; | |
9084 | toklen = end_tok - tok + 1; | |
9085 | ||
9086 | if (toklen == 6 && !strncmp (tok, "thread", 6)) | |
9087 | { | |
9088 | /* At this point we've found a "thread" token, which means | |
9089 | the user is trying to set a watchpoint that triggers | |
9090 | only in a specific thread. */ | |
9091 | char *endp; | |
37e4754d | 9092 | |
9c06b0b4 TJB |
9093 | if (thread != -1) |
9094 | error(_("You can specify only one thread.")); | |
37e4754d | 9095 | |
9c06b0b4 TJB |
9096 | /* Extract the thread ID from the next token. */ |
9097 | thread = strtol (value_start, &endp, 0); | |
37e4754d | 9098 | |
9c06b0b4 TJB |
9099 | /* Check if the user provided a valid numeric value for the |
9100 | thread ID. */ | |
9101 | if (*endp != ' ' && *endp != '\t' && *endp != '\0') | |
9102 | error (_("Invalid thread ID specification %s."), value_start); | |
9103 | ||
9104 | /* Check if the thread actually exists. */ | |
9105 | if (!valid_thread_id (thread)) | |
9106 | error (_("Unknown thread %d."), thread); | |
9107 | } | |
9108 | else if (toklen == 4 && !strncmp (tok, "mask", 4)) | |
9109 | { | |
9110 | /* We've found a "mask" token, which means the user wants to | |
9111 | create a hardware watchpoint that is going to have the mask | |
9112 | facility. */ | |
9113 | struct value *mask_value, *mark; | |
37e4754d | 9114 | |
9c06b0b4 TJB |
9115 | if (use_mask) |
9116 | error(_("You can specify only one mask.")); | |
37e4754d | 9117 | |
9c06b0b4 | 9118 | use_mask = just_location = 1; |
37e4754d | 9119 | |
9c06b0b4 TJB |
9120 | mark = value_mark (); |
9121 | mask_value = parse_to_comma_and_eval (&value_start); | |
9122 | mask = value_as_address (mask_value); | |
9123 | value_free_to_mark (mark); | |
9124 | } | |
9125 | else | |
9126 | /* We didn't recognize what we found. We should stop here. */ | |
9127 | break; | |
37e4754d | 9128 | |
9c06b0b4 TJB |
9129 | /* Truncate the string and get rid of the "parameter value" pair before |
9130 | the arguments string is parsed by the parse_exp_1 function. */ | |
9131 | *tok = '\0'; | |
9132 | } | |
37e4754d LM |
9133 | } |
9134 | ||
9135 | /* Parse the rest of the arguments. */ | |
c906108c SS |
9136 | innermost_block = NULL; |
9137 | exp_start = arg; | |
9138 | exp = parse_exp_1 (&arg, 0, 0); | |
9139 | exp_end = arg; | |
fa8a61dc TT |
9140 | /* Remove trailing whitespace from the expression before saving it. |
9141 | This makes the eventual display of the expression string a bit | |
9142 | prettier. */ | |
9143 | while (exp_end > exp_start && (exp_end[-1] == ' ' || exp_end[-1] == '\t')) | |
9144 | --exp_end; | |
9145 | ||
65d79d4b SDJ |
9146 | /* Checking if the expression is not constant. */ |
9147 | if (watchpoint_exp_is_const (exp)) | |
9148 | { | |
9149 | int len; | |
9150 | ||
9151 | len = exp_end - exp_start; | |
9152 | while (len > 0 && isspace (exp_start[len - 1])) | |
9153 | len--; | |
9154 | error (_("Cannot watch constant value `%.*s'."), len, exp_start); | |
9155 | } | |
9156 | ||
c906108c SS |
9157 | exp_valid_block = innermost_block; |
9158 | mark = value_mark (); | |
a1442452 | 9159 | fetch_subexp_value (exp, &pc, &val, &result, NULL); |
06a64a0b TT |
9160 | |
9161 | if (just_location) | |
9162 | { | |
9c06b0b4 TJB |
9163 | int ret; |
9164 | ||
06a64a0b | 9165 | exp_valid_block = NULL; |
a1442452 | 9166 | val = value_addr (result); |
06a64a0b TT |
9167 | release_value (val); |
9168 | value_free_to_mark (mark); | |
9c06b0b4 TJB |
9169 | |
9170 | if (use_mask) | |
9171 | { | |
9172 | ret = target_masked_watch_num_registers (value_as_address (val), | |
9173 | mask); | |
9174 | if (ret == -1) | |
9175 | error (_("This target does not support masked watchpoints.")); | |
9176 | else if (ret == -2) | |
9177 | error (_("Invalid mask or memory region.")); | |
9178 | } | |
06a64a0b TT |
9179 | } |
9180 | else if (val != NULL) | |
fa4727a6 | 9181 | release_value (val); |
c906108c | 9182 | |
e9cafbcc TT |
9183 | tok = skip_spaces (arg); |
9184 | end_tok = skip_to_space (tok); | |
c906108c SS |
9185 | |
9186 | toklen = end_tok - tok; | |
9187 | if (toklen >= 1 && strncmp (tok, "if", toklen) == 0) | |
9188 | { | |
2d134ed3 PA |
9189 | struct expression *cond; |
9190 | ||
60e1c644 | 9191 | innermost_block = NULL; |
c906108c SS |
9192 | tok = cond_start = end_tok + 1; |
9193 | cond = parse_exp_1 (&tok, 0, 0); | |
60e1c644 PA |
9194 | |
9195 | /* The watchpoint expression may not be local, but the condition | |
9196 | may still be. E.g.: `watch global if local > 0'. */ | |
9197 | cond_exp_valid_block = innermost_block; | |
9198 | ||
2d134ed3 | 9199 | xfree (cond); |
c906108c SS |
9200 | cond_end = tok; |
9201 | } | |
9202 | if (*tok) | |
8a3fe4f8 | 9203 | error (_("Junk at end of command.")); |
c906108c | 9204 | |
53a5351d | 9205 | if (accessflag == hw_read) |
c5aa993b | 9206 | bp_type = bp_read_watchpoint; |
53a5351d | 9207 | else if (accessflag == hw_access) |
c5aa993b JM |
9208 | bp_type = bp_access_watchpoint; |
9209 | else | |
9210 | bp_type = bp_hardware_watchpoint; | |
c906108c | 9211 | |
d983da9c | 9212 | frame = block_innermost_frame (exp_valid_block); |
d983da9c DJ |
9213 | |
9214 | /* If the expression is "local", then set up a "watchpoint scope" | |
9215 | breakpoint at the point where we've left the scope of the watchpoint | |
9216 | expression. Create the scope breakpoint before the watchpoint, so | |
9217 | that we will encounter it first in bpstat_stop_status. */ | |
60e1c644 | 9218 | if (exp_valid_block && frame) |
d983da9c | 9219 | { |
edb3359d DJ |
9220 | if (frame_id_p (frame_unwind_caller_id (frame))) |
9221 | { | |
9222 | scope_breakpoint | |
a6d9a66e UW |
9223 | = create_internal_breakpoint (frame_unwind_caller_arch (frame), |
9224 | frame_unwind_caller_pc (frame), | |
edb3359d | 9225 | bp_watchpoint_scope); |
d983da9c | 9226 | |
edb3359d | 9227 | scope_breakpoint->enable_state = bp_enabled; |
d983da9c | 9228 | |
edb3359d DJ |
9229 | /* Automatically delete the breakpoint when it hits. */ |
9230 | scope_breakpoint->disposition = disp_del; | |
d983da9c | 9231 | |
edb3359d DJ |
9232 | /* Only break in the proper frame (help with recursion). */ |
9233 | scope_breakpoint->frame_id = frame_unwind_caller_id (frame); | |
d983da9c | 9234 | |
edb3359d | 9235 | /* Set the address at which we will stop. */ |
a6d9a66e UW |
9236 | scope_breakpoint->loc->gdbarch |
9237 | = frame_unwind_caller_arch (frame); | |
edb3359d DJ |
9238 | scope_breakpoint->loc->requested_address |
9239 | = frame_unwind_caller_pc (frame); | |
9240 | scope_breakpoint->loc->address | |
a6d9a66e UW |
9241 | = adjust_breakpoint_address (scope_breakpoint->loc->gdbarch, |
9242 | scope_breakpoint->loc->requested_address, | |
edb3359d DJ |
9243 | scope_breakpoint->type); |
9244 | } | |
d983da9c DJ |
9245 | } |
9246 | ||
c906108c | 9247 | /* Now set up the breakpoint. */ |
2d134ed3 | 9248 | b = set_raw_breakpoint_without_location (NULL, bp_type); |
37e4754d | 9249 | b->thread = thread; |
b5de0fa7 | 9250 | b->disposition = disp_donttouch; |
c906108c SS |
9251 | b->exp = exp; |
9252 | b->exp_valid_block = exp_valid_block; | |
60e1c644 | 9253 | b->cond_exp_valid_block = cond_exp_valid_block; |
06a64a0b TT |
9254 | if (just_location) |
9255 | { | |
9256 | struct type *t = value_type (val); | |
9257 | CORE_ADDR addr = value_as_address (val); | |
9258 | char *name; | |
9259 | ||
9260 | t = check_typedef (TYPE_TARGET_TYPE (check_typedef (t))); | |
9261 | name = type_to_string (t); | |
9262 | ||
d63d0675 JK |
9263 | b->exp_string_reparse = xstrprintf ("* (%s *) %s", name, |
9264 | core_addr_to_string (addr)); | |
06a64a0b TT |
9265 | xfree (name); |
9266 | ||
4a4106ca | 9267 | b->exp_string = xstrprintf ("-location %.*s", |
d63d0675 JK |
9268 | (int) (exp_end - exp_start), exp_start); |
9269 | ||
06a64a0b TT |
9270 | /* The above expression is in C. */ |
9271 | b->language = language_c; | |
9272 | } | |
9273 | else | |
9274 | b->exp_string = savestring (exp_start, exp_end - exp_start); | |
9c06b0b4 TJB |
9275 | |
9276 | if (use_mask) | |
9277 | { | |
9278 | b->hw_wp_mask = mask; | |
9279 | b->ops = &masked_watchpoint_breakpoint_ops; | |
9280 | } | |
9281 | else | |
9282 | { | |
9283 | b->val = val; | |
9284 | b->val_valid = 1; | |
9285 | b->ops = &watchpoint_breakpoint_ops; | |
9286 | } | |
77b06cd7 | 9287 | |
c906108c SS |
9288 | if (cond_start) |
9289 | b->cond_string = savestring (cond_start, cond_end - cond_start); | |
9290 | else | |
9291 | b->cond_string = 0; | |
c5aa993b | 9292 | |
c906108c | 9293 | if (frame) |
f6bc2008 PA |
9294 | { |
9295 | b->watchpoint_frame = get_frame_id (frame); | |
9296 | b->watchpoint_thread = inferior_ptid; | |
9297 | } | |
c906108c | 9298 | else |
f6bc2008 PA |
9299 | { |
9300 | b->watchpoint_frame = null_frame_id; | |
9301 | b->watchpoint_thread = null_ptid; | |
9302 | } | |
c906108c | 9303 | |
d983da9c | 9304 | if (scope_breakpoint != NULL) |
c906108c | 9305 | { |
d983da9c DJ |
9306 | /* The scope breakpoint is related to the watchpoint. We will |
9307 | need to act on them together. */ | |
9308 | b->related_breakpoint = scope_breakpoint; | |
9309 | scope_breakpoint->related_breakpoint = b; | |
c906108c | 9310 | } |
d983da9c | 9311 | |
06a64a0b TT |
9312 | if (!just_location) |
9313 | value_free_to_mark (mark); | |
2d134ed3 | 9314 | |
a9634178 TJB |
9315 | TRY_CATCH (e, RETURN_MASK_ALL) |
9316 | { | |
9317 | /* Finally update the new watchpoint. This creates the locations | |
9318 | that should be inserted. */ | |
9319 | update_watchpoint (b, 1); | |
9320 | } | |
9321 | if (e.reason < 0) | |
9322 | { | |
9323 | delete_breakpoint (b); | |
9324 | throw_exception (e); | |
9325 | } | |
9326 | ||
9327 | set_breakpoint_number (internal, b); | |
8d3788bd VP |
9328 | |
9329 | /* Do not mention breakpoints with a negative number, but do | |
a9634178 | 9330 | notify observers. */ |
8d3788bd | 9331 | if (!internal) |
84f4c1fe | 9332 | mention (b); |
8d3788bd VP |
9333 | observer_notify_breakpoint_created (b); |
9334 | ||
b60e7edf | 9335 | update_global_location_list (1); |
c906108c SS |
9336 | } |
9337 | ||
e09342b5 | 9338 | /* Return count of debug registers needed to watch the given expression. |
e09342b5 | 9339 | If the watchpoint cannot be handled in hardware return zero. */ |
c906108c | 9340 | |
c906108c | 9341 | static int |
a9634178 | 9342 | can_use_hardware_watchpoint (struct value *v) |
c906108c SS |
9343 | { |
9344 | int found_memory_cnt = 0; | |
2e70b7b9 | 9345 | struct value *head = v; |
c906108c SS |
9346 | |
9347 | /* Did the user specifically forbid us to use hardware watchpoints? */ | |
c5aa993b | 9348 | if (!can_use_hw_watchpoints) |
c906108c | 9349 | return 0; |
c5aa993b | 9350 | |
5c44784c JM |
9351 | /* Make sure that the value of the expression depends only upon |
9352 | memory contents, and values computed from them within GDB. If we | |
9353 | find any register references or function calls, we can't use a | |
9354 | hardware watchpoint. | |
9355 | ||
9356 | The idea here is that evaluating an expression generates a series | |
9357 | of values, one holding the value of every subexpression. (The | |
9358 | expression a*b+c has five subexpressions: a, b, a*b, c, and | |
9359 | a*b+c.) GDB's values hold almost enough information to establish | |
9360 | the criteria given above --- they identify memory lvalues, | |
9361 | register lvalues, computed values, etcetera. So we can evaluate | |
9362 | the expression, and then scan the chain of values that leaves | |
9363 | behind to decide whether we can detect any possible change to the | |
9364 | expression's final value using only hardware watchpoints. | |
9365 | ||
9366 | However, I don't think that the values returned by inferior | |
9367 | function calls are special in any way. So this function may not | |
9368 | notice that an expression involving an inferior function call | |
9369 | can't be watched with hardware watchpoints. FIXME. */ | |
17cf0ecd | 9370 | for (; v; v = value_next (v)) |
c906108c | 9371 | { |
5c44784c | 9372 | if (VALUE_LVAL (v) == lval_memory) |
c906108c | 9373 | { |
8464be76 DJ |
9374 | if (v != head && value_lazy (v)) |
9375 | /* A lazy memory lvalue in the chain is one that GDB never | |
9376 | needed to fetch; we either just used its address (e.g., | |
9377 | `a' in `a.b') or we never needed it at all (e.g., `a' | |
9378 | in `a,b'). This doesn't apply to HEAD; if that is | |
9379 | lazy then it was not readable, but watch it anyway. */ | |
5c44784c | 9380 | ; |
53a5351d | 9381 | else |
5c44784c JM |
9382 | { |
9383 | /* Ahh, memory we actually used! Check if we can cover | |
9384 | it with hardware watchpoints. */ | |
df407dfe | 9385 | struct type *vtype = check_typedef (value_type (v)); |
2e70b7b9 MS |
9386 | |
9387 | /* We only watch structs and arrays if user asked for it | |
9388 | explicitly, never if they just happen to appear in a | |
9389 | middle of some value chain. */ | |
9390 | if (v == head | |
9391 | || (TYPE_CODE (vtype) != TYPE_CODE_STRUCT | |
9392 | && TYPE_CODE (vtype) != TYPE_CODE_ARRAY)) | |
9393 | { | |
42ae5230 | 9394 | CORE_ADDR vaddr = value_address (v); |
e09342b5 TJB |
9395 | int len; |
9396 | int num_regs; | |
9397 | ||
a9634178 | 9398 | len = (target_exact_watchpoints |
e09342b5 TJB |
9399 | && is_scalar_type_recursive (vtype))? |
9400 | 1 : TYPE_LENGTH (value_type (v)); | |
2e70b7b9 | 9401 | |
e09342b5 TJB |
9402 | num_regs = target_region_ok_for_hw_watchpoint (vaddr, len); |
9403 | if (!num_regs) | |
2e70b7b9 MS |
9404 | return 0; |
9405 | else | |
e09342b5 | 9406 | found_memory_cnt += num_regs; |
2e70b7b9 | 9407 | } |
5c44784c | 9408 | } |
c5aa993b | 9409 | } |
5086187c AC |
9410 | else if (VALUE_LVAL (v) != not_lval |
9411 | && deprecated_value_modifiable (v) == 0) | |
38b6c3b3 | 9412 | return 0; /* These are values from the history (e.g., $1). */ |
5086187c | 9413 | else if (VALUE_LVAL (v) == lval_register) |
38b6c3b3 | 9414 | return 0; /* Cannot watch a register with a HW watchpoint. */ |
c906108c SS |
9415 | } |
9416 | ||
9417 | /* The expression itself looks suitable for using a hardware | |
9418 | watchpoint, but give the target machine a chance to reject it. */ | |
9419 | return found_memory_cnt; | |
9420 | } | |
9421 | ||
8b93c638 | 9422 | void |
84f4c1fe | 9423 | watch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9424 | { |
84f4c1fe | 9425 | watch_command_1 (arg, hw_write, from_tty, 0, internal); |
06a64a0b TT |
9426 | } |
9427 | ||
9428 | /* A helper function that looks for an argument at the start of a | |
9429 | string. The argument must also either be at the end of the string, | |
9430 | or be followed by whitespace. Returns 1 if it finds the argument, | |
9431 | 0 otherwise. If the argument is found, it updates *STR. */ | |
9432 | ||
9433 | static int | |
9434 | check_for_argument (char **str, char *arg, int arg_len) | |
9435 | { | |
9436 | if (strncmp (*str, arg, arg_len) == 0 | |
9437 | && ((*str)[arg_len] == '\0' || isspace ((*str)[arg_len]))) | |
9438 | { | |
9439 | *str += arg_len; | |
9440 | return 1; | |
9441 | } | |
9442 | return 0; | |
9443 | } | |
9444 | ||
9445 | /* A helper function that looks for the "-location" argument and then | |
9446 | calls watch_command_1. */ | |
9447 | ||
9448 | static void | |
9449 | watch_maybe_just_location (char *arg, int accessflag, int from_tty) | |
9450 | { | |
9451 | int just_location = 0; | |
9452 | ||
9453 | if (arg | |
9454 | && (check_for_argument (&arg, "-location", sizeof ("-location") - 1) | |
9455 | || check_for_argument (&arg, "-l", sizeof ("-l") - 1))) | |
9456 | { | |
e9cafbcc | 9457 | arg = skip_spaces (arg); |
06a64a0b TT |
9458 | just_location = 1; |
9459 | } | |
9460 | ||
84f4c1fe | 9461 | watch_command_1 (arg, accessflag, from_tty, just_location, 0); |
8b93c638 | 9462 | } |
8926118c | 9463 | |
c5aa993b | 9464 | static void |
fba45db2 | 9465 | watch_command (char *arg, int from_tty) |
c906108c | 9466 | { |
06a64a0b | 9467 | watch_maybe_just_location (arg, hw_write, from_tty); |
c906108c SS |
9468 | } |
9469 | ||
8b93c638 | 9470 | void |
84f4c1fe | 9471 | rwatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9472 | { |
84f4c1fe | 9473 | watch_command_1 (arg, hw_read, from_tty, 0, internal); |
8b93c638 | 9474 | } |
8926118c | 9475 | |
c5aa993b | 9476 | static void |
fba45db2 | 9477 | rwatch_command (char *arg, int from_tty) |
c906108c | 9478 | { |
06a64a0b | 9479 | watch_maybe_just_location (arg, hw_read, from_tty); |
c906108c SS |
9480 | } |
9481 | ||
8b93c638 | 9482 | void |
84f4c1fe | 9483 | awatch_command_wrapper (char *arg, int from_tty, int internal) |
8b93c638 | 9484 | { |
84f4c1fe | 9485 | watch_command_1 (arg, hw_access, from_tty, 0, internal); |
8b93c638 | 9486 | } |
8926118c | 9487 | |
c5aa993b | 9488 | static void |
fba45db2 | 9489 | awatch_command (char *arg, int from_tty) |
c906108c | 9490 | { |
06a64a0b | 9491 | watch_maybe_just_location (arg, hw_access, from_tty); |
c906108c | 9492 | } |
c906108c | 9493 | \f |
c5aa993b | 9494 | |
43ff13b4 | 9495 | /* Helper routines for the until_command routine in infcmd.c. Here |
c906108c SS |
9496 | because it uses the mechanisms of breakpoints. */ |
9497 | ||
bfec99b2 PA |
9498 | struct until_break_command_continuation_args |
9499 | { | |
9500 | struct breakpoint *breakpoint; | |
9501 | struct breakpoint *breakpoint2; | |
186c406b | 9502 | int thread_num; |
bfec99b2 PA |
9503 | }; |
9504 | ||
43ff13b4 | 9505 | /* This function is called by fetch_inferior_event via the |
4a64f543 | 9506 | cmd_continuation pointer, to complete the until command. It takes |
43ff13b4 | 9507 | care of cleaning up the temporary breakpoints set up by the until |
4a64f543 | 9508 | command. */ |
c2c6d25f | 9509 | static void |
604ead4a | 9510 | until_break_command_continuation (void *arg) |
43ff13b4 | 9511 | { |
bfec99b2 PA |
9512 | struct until_break_command_continuation_args *a = arg; |
9513 | ||
9514 | delete_breakpoint (a->breakpoint); | |
9515 | if (a->breakpoint2) | |
9516 | delete_breakpoint (a->breakpoint2); | |
186c406b | 9517 | delete_longjmp_breakpoint (a->thread_num); |
43ff13b4 JM |
9518 | } |
9519 | ||
c906108c | 9520 | void |
ae66c1fc | 9521 | until_break_command (char *arg, int from_tty, int anywhere) |
c906108c SS |
9522 | { |
9523 | struct symtabs_and_lines sals; | |
9524 | struct symtab_and_line sal; | |
206415a3 | 9525 | struct frame_info *frame = get_selected_frame (NULL); |
c906108c | 9526 | struct breakpoint *breakpoint; |
f107f563 | 9527 | struct breakpoint *breakpoint2 = NULL; |
c906108c | 9528 | struct cleanup *old_chain; |
186c406b TT |
9529 | int thread; |
9530 | struct thread_info *tp; | |
c906108c SS |
9531 | |
9532 | clear_proceed_status (); | |
9533 | ||
9534 | /* Set a breakpoint where the user wants it and at return from | |
4a64f543 | 9535 | this function. */ |
c5aa993b | 9536 | |
c906108c SS |
9537 | if (default_breakpoint_valid) |
9538 | sals = decode_line_1 (&arg, 1, default_breakpoint_symtab, | |
58438ac1 | 9539 | default_breakpoint_line, NULL); |
c906108c | 9540 | else |
58438ac1 | 9541 | sals = decode_line_1 (&arg, 1, (struct symtab *) NULL, 0, NULL); |
c5aa993b | 9542 | |
c906108c | 9543 | if (sals.nelts != 1) |
8a3fe4f8 | 9544 | error (_("Couldn't get information on specified line.")); |
c5aa993b | 9545 | |
c906108c | 9546 | sal = sals.sals[0]; |
4a64f543 | 9547 | xfree (sals.sals); /* malloc'd, so freed. */ |
c5aa993b | 9548 | |
c906108c | 9549 | if (*arg) |
8a3fe4f8 | 9550 | error (_("Junk at end of arguments.")); |
c5aa993b | 9551 | |
c906108c | 9552 | resolve_sal_pc (&sal); |
c5aa993b | 9553 | |
ae66c1fc EZ |
9554 | if (anywhere) |
9555 | /* If the user told us to continue until a specified location, | |
9556 | we don't specify a frame at which we need to stop. */ | |
a6d9a66e UW |
9557 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9558 | null_frame_id, bp_until); | |
ae66c1fc | 9559 | else |
4a64f543 MS |
9560 | /* Otherwise, specify the selected frame, because we want to stop |
9561 | only at the very same frame. */ | |
a6d9a66e UW |
9562 | breakpoint = set_momentary_breakpoint (get_frame_arch (frame), sal, |
9563 | get_stack_frame_id (frame), | |
ae66c1fc | 9564 | bp_until); |
c5aa993b | 9565 | |
f107f563 | 9566 | old_chain = make_cleanup_delete_breakpoint (breakpoint); |
c906108c | 9567 | |
186c406b TT |
9568 | tp = inferior_thread (); |
9569 | thread = tp->num; | |
9570 | ||
ae66c1fc EZ |
9571 | /* Keep within the current frame, or in frames called by the current |
9572 | one. */ | |
edb3359d DJ |
9573 | |
9574 | if (frame_id_p (frame_unwind_caller_id (frame))) | |
c906108c | 9575 | { |
edb3359d DJ |
9576 | sal = find_pc_line (frame_unwind_caller_pc (frame), 0); |
9577 | sal.pc = frame_unwind_caller_pc (frame); | |
a6d9a66e UW |
9578 | breakpoint2 = set_momentary_breakpoint (frame_unwind_caller_arch (frame), |
9579 | sal, | |
edb3359d | 9580 | frame_unwind_caller_id (frame), |
f107f563 VP |
9581 | bp_until); |
9582 | make_cleanup_delete_breakpoint (breakpoint2); | |
186c406b TT |
9583 | |
9584 | set_longjmp_breakpoint (tp, frame_unwind_caller_id (frame)); | |
9585 | make_cleanup (delete_longjmp_breakpoint_cleanup, &thread); | |
c906108c | 9586 | } |
c5aa993b | 9587 | |
c906108c | 9588 | proceed (-1, TARGET_SIGNAL_DEFAULT, 0); |
f107f563 | 9589 | |
4a64f543 MS |
9590 | /* If we are running asynchronously, and proceed call above has |
9591 | actually managed to start the target, arrange for breakpoints to | |
9592 | be deleted when the target stops. Otherwise, we're already | |
9593 | stopped and delete breakpoints via cleanup chain. */ | |
f107f563 | 9594 | |
8ea051c5 | 9595 | if (target_can_async_p () && is_running (inferior_ptid)) |
f107f563 | 9596 | { |
bfec99b2 PA |
9597 | struct until_break_command_continuation_args *args; |
9598 | args = xmalloc (sizeof (*args)); | |
f107f563 | 9599 | |
bfec99b2 PA |
9600 | args->breakpoint = breakpoint; |
9601 | args->breakpoint2 = breakpoint2; | |
186c406b | 9602 | args->thread_num = thread; |
f107f563 VP |
9603 | |
9604 | discard_cleanups (old_chain); | |
95e54da7 PA |
9605 | add_continuation (inferior_thread (), |
9606 | until_break_command_continuation, args, | |
604ead4a | 9607 | xfree); |
f107f563 VP |
9608 | } |
9609 | else | |
c5aa993b | 9610 | do_cleanups (old_chain); |
c906108c | 9611 | } |
ae66c1fc | 9612 | |
c906108c SS |
9613 | /* This function attempts to parse an optional "if <cond>" clause |
9614 | from the arg string. If one is not found, it returns NULL. | |
c5aa993b | 9615 | |
c906108c SS |
9616 | Else, it returns a pointer to the condition string. (It does not |
9617 | attempt to evaluate the string against a particular block.) And, | |
9618 | it updates arg to point to the first character following the parsed | |
4a64f543 | 9619 | if clause in the arg string. */ |
53a5351d | 9620 | |
c906108c | 9621 | static char * |
fba45db2 | 9622 | ep_parse_optional_if_clause (char **arg) |
c906108c | 9623 | { |
c5aa993b JM |
9624 | char *cond_string; |
9625 | ||
9626 | if (((*arg)[0] != 'i') || ((*arg)[1] != 'f') || !isspace ((*arg)[2])) | |
c906108c | 9627 | return NULL; |
c5aa993b | 9628 | |
4a64f543 | 9629 | /* Skip the "if" keyword. */ |
c906108c | 9630 | (*arg) += 2; |
c5aa993b | 9631 | |
c906108c | 9632 | /* Skip any extra leading whitespace, and record the start of the |
4a64f543 | 9633 | condition string. */ |
e9cafbcc | 9634 | *arg = skip_spaces (*arg); |
c906108c | 9635 | cond_string = *arg; |
c5aa993b | 9636 | |
4a64f543 MS |
9637 | /* Assume that the condition occupies the remainder of the arg |
9638 | string. */ | |
c906108c | 9639 | (*arg) += strlen (cond_string); |
c5aa993b | 9640 | |
c906108c SS |
9641 | return cond_string; |
9642 | } | |
c5aa993b | 9643 | |
c906108c SS |
9644 | /* Commands to deal with catching events, such as signals, exceptions, |
9645 | process start/exit, etc. */ | |
c5aa993b JM |
9646 | |
9647 | typedef enum | |
9648 | { | |
44feb3ce TT |
9649 | catch_fork_temporary, catch_vfork_temporary, |
9650 | catch_fork_permanent, catch_vfork_permanent | |
c5aa993b JM |
9651 | } |
9652 | catch_fork_kind; | |
9653 | ||
c906108c | 9654 | static void |
cc59ec59 MS |
9655 | catch_fork_command_1 (char *arg, int from_tty, |
9656 | struct cmd_list_element *command) | |
c906108c | 9657 | { |
a6d9a66e | 9658 | struct gdbarch *gdbarch = get_current_arch (); |
c5aa993b | 9659 | char *cond_string = NULL; |
44feb3ce TT |
9660 | catch_fork_kind fork_kind; |
9661 | int tempflag; | |
9662 | ||
9663 | fork_kind = (catch_fork_kind) (uintptr_t) get_cmd_context (command); | |
9664 | tempflag = (fork_kind == catch_fork_temporary | |
9665 | || fork_kind == catch_vfork_temporary); | |
c5aa993b | 9666 | |
44feb3ce TT |
9667 | if (!arg) |
9668 | arg = ""; | |
e9cafbcc | 9669 | arg = skip_spaces (arg); |
c5aa993b | 9670 | |
c906108c | 9671 | /* The allowed syntax is: |
c5aa993b JM |
9672 | catch [v]fork |
9673 | catch [v]fork if <cond> | |
9674 | ||
4a64f543 | 9675 | First, check if there's an if clause. */ |
c906108c | 9676 | cond_string = ep_parse_optional_if_clause (&arg); |
c5aa993b | 9677 | |
c906108c | 9678 | if ((*arg != '\0') && !isspace (*arg)) |
8a3fe4f8 | 9679 | error (_("Junk at end of arguments.")); |
c5aa993b | 9680 | |
c906108c | 9681 | /* If this target supports it, create a fork or vfork catchpoint |
4a64f543 | 9682 | and enable reporting of such events. */ |
c5aa993b JM |
9683 | switch (fork_kind) |
9684 | { | |
44feb3ce TT |
9685 | case catch_fork_temporary: |
9686 | case catch_fork_permanent: | |
a6d9a66e | 9687 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9688 | &catch_fork_breakpoint_ops); |
c906108c | 9689 | break; |
44feb3ce TT |
9690 | case catch_vfork_temporary: |
9691 | case catch_vfork_permanent: | |
a6d9a66e | 9692 | create_fork_vfork_event_catchpoint (gdbarch, tempflag, cond_string, |
ce78b96d | 9693 | &catch_vfork_breakpoint_ops); |
c906108c | 9694 | break; |
c5aa993b | 9695 | default: |
8a3fe4f8 | 9696 | error (_("unsupported or unknown fork kind; cannot catch it")); |
c906108c | 9697 | break; |
c5aa993b | 9698 | } |
c906108c SS |
9699 | } |
9700 | ||
9701 | static void | |
cc59ec59 MS |
9702 | catch_exec_command_1 (char *arg, int from_tty, |
9703 | struct cmd_list_element *command) | |
c906108c | 9704 | { |
a6d9a66e | 9705 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9706 | int tempflag; |
c5aa993b | 9707 | char *cond_string = NULL; |
c906108c | 9708 | |
44feb3ce TT |
9709 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9710 | ||
9711 | if (!arg) | |
9712 | arg = ""; | |
e9cafbcc | 9713 | arg = skip_spaces (arg); |
c906108c SS |
9714 | |
9715 | /* The allowed syntax is: | |
c5aa993b JM |
9716 | catch exec |
9717 | catch exec if <cond> | |
c906108c | 9718 | |
4a64f543 | 9719 | First, check if there's an if clause. */ |
c906108c SS |
9720 | cond_string = ep_parse_optional_if_clause (&arg); |
9721 | ||
9722 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9723 | error (_("Junk at end of arguments.")); |
c906108c SS |
9724 | |
9725 | /* If this target supports it, create an exec catchpoint | |
4a64f543 | 9726 | and enable reporting of such events. */ |
a6d9a66e UW |
9727 | create_catchpoint (gdbarch, tempflag, cond_string, |
9728 | &catch_exec_breakpoint_ops); | |
c906108c | 9729 | } |
c5aa993b | 9730 | |
3086aeae | 9731 | static enum print_stop_action |
ba770c9c | 9732 | print_it_exception_catchpoint (struct breakpoint *b) |
3086aeae | 9733 | { |
ade92717 | 9734 | int bp_temp, bp_throw; |
3086aeae | 9735 | |
ade92717 | 9736 | annotate_catchpoint (b->number); |
3086aeae | 9737 | |
ade92717 AR |
9738 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9739 | if (b->loc->address != b->loc->requested_address) | |
9740 | breakpoint_adjustment_warning (b->loc->requested_address, | |
9741 | b->loc->address, | |
9742 | b->number, 1); | |
df2b6d2d | 9743 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9744 | ui_out_text (uiout, |
9745 | bp_temp ? "Temporary catchpoint " | |
9746 | : "Catchpoint "); | |
9747 | if (!ui_out_is_mi_like_p (uiout)) | |
9748 | ui_out_field_int (uiout, "bkptno", b->number); | |
9749 | ui_out_text (uiout, | |
c0b37c48 AR |
9750 | bp_throw ? " (exception thrown), " |
9751 | : " (exception caught), "); | |
ade92717 AR |
9752 | if (ui_out_is_mi_like_p (uiout)) |
9753 | { | |
9754 | ui_out_field_string (uiout, "reason", | |
9755 | async_reason_lookup (EXEC_ASYNC_BREAKPOINT_HIT)); | |
9756 | ui_out_field_string (uiout, "disp", bpdisp_text (b->disposition)); | |
9757 | ui_out_field_int (uiout, "bkptno", b->number); | |
9758 | } | |
3086aeae DJ |
9759 | return PRINT_SRC_AND_LOC; |
9760 | } | |
9761 | ||
9762 | static void | |
cc59ec59 MS |
9763 | print_one_exception_catchpoint (struct breakpoint *b, |
9764 | struct bp_location **last_loc) | |
3086aeae | 9765 | { |
79a45b7d | 9766 | struct value_print_options opts; |
cc59ec59 | 9767 | |
79a45b7d TT |
9768 | get_user_print_options (&opts); |
9769 | if (opts.addressprint) | |
3086aeae DJ |
9770 | { |
9771 | annotate_field (4); | |
604133b5 AR |
9772 | if (b->loc == NULL || b->loc->shlib_disabled) |
9773 | ui_out_field_string (uiout, "addr", "<PENDING>"); | |
9774 | else | |
5af949e3 UW |
9775 | ui_out_field_core_addr (uiout, "addr", |
9776 | b->loc->gdbarch, b->loc->address); | |
3086aeae DJ |
9777 | } |
9778 | annotate_field (5); | |
604133b5 | 9779 | if (b->loc) |
a6d9a66e | 9780 | *last_loc = b->loc; |
3086aeae DJ |
9781 | if (strstr (b->addr_string, "throw") != NULL) |
9782 | ui_out_field_string (uiout, "what", "exception throw"); | |
9783 | else | |
9784 | ui_out_field_string (uiout, "what", "exception catch"); | |
9785 | } | |
9786 | ||
9787 | static void | |
9788 | print_mention_exception_catchpoint (struct breakpoint *b) | |
9789 | { | |
ade92717 AR |
9790 | int bp_temp; |
9791 | int bp_throw; | |
9792 | ||
df2b6d2d | 9793 | bp_temp = b->disposition == disp_del; |
ade92717 AR |
9794 | bp_throw = strstr (b->addr_string, "throw") != NULL; |
9795 | ui_out_text (uiout, bp_temp ? _("Temporary catchpoint ") | |
9796 | : _("Catchpoint ")); | |
9797 | ui_out_field_int (uiout, "bkptno", b->number); | |
9798 | ui_out_text (uiout, bp_throw ? _(" (throw)") | |
9799 | : _(" (catch)")); | |
3086aeae DJ |
9800 | } |
9801 | ||
6149aea9 PA |
9802 | /* Implement the "print_recreate" breakpoint_ops method for throw and |
9803 | catch catchpoints. */ | |
9804 | ||
9805 | static void | |
4a64f543 MS |
9806 | print_recreate_exception_catchpoint (struct breakpoint *b, |
9807 | struct ui_file *fp) | |
6149aea9 PA |
9808 | { |
9809 | int bp_temp; | |
9810 | int bp_throw; | |
9811 | ||
9812 | bp_temp = b->disposition == disp_del; | |
9813 | bp_throw = strstr (b->addr_string, "throw") != NULL; | |
9814 | fprintf_unfiltered (fp, bp_temp ? "tcatch " : "catch "); | |
9815 | fprintf_unfiltered (fp, bp_throw ? "throw" : "catch"); | |
9816 | } | |
9817 | ||
3086aeae | 9818 | static struct breakpoint_ops gnu_v3_exception_catchpoint_ops = { |
ce78b96d JB |
9819 | NULL, /* insert */ |
9820 | NULL, /* remove */ | |
9821 | NULL, /* breakpoint_hit */ | |
e09342b5 | 9822 | NULL, /* resources_needed */ |
9c06b0b4 | 9823 | NULL, /* works_in_software_mode */ |
ba770c9c | 9824 | print_it_exception_catchpoint, |
3086aeae | 9825 | print_one_exception_catchpoint, |
f1310107 | 9826 | NULL, /* print_one_detail */ |
6149aea9 PA |
9827 | print_mention_exception_catchpoint, |
9828 | print_recreate_exception_catchpoint | |
3086aeae DJ |
9829 | }; |
9830 | ||
9831 | static int | |
9832 | handle_gnu_v3_exceptions (int tempflag, char *cond_string, | |
9833 | enum exception_event_kind ex_event, int from_tty) | |
9834 | { | |
604133b5 AR |
9835 | char *trigger_func_name; |
9836 | ||
3086aeae | 9837 | if (ex_event == EX_EVENT_CATCH) |
604133b5 | 9838 | trigger_func_name = "__cxa_begin_catch"; |
3086aeae | 9839 | else |
604133b5 | 9840 | trigger_func_name = "__cxa_throw"; |
3086aeae | 9841 | |
8cdf0e15 VP |
9842 | create_breakpoint (get_current_arch (), |
9843 | trigger_func_name, cond_string, -1, | |
9844 | 0 /* condition and thread are valid. */, | |
0fb4aa4b | 9845 | tempflag, bp_breakpoint, |
8cdf0e15 VP |
9846 | 0, |
9847 | AUTO_BOOLEAN_TRUE /* pending */, | |
9848 | &gnu_v3_exception_catchpoint_ops, from_tty, | |
84f4c1fe PM |
9849 | 1 /* enabled */, |
9850 | 0 /* internal */); | |
3086aeae | 9851 | |
3086aeae DJ |
9852 | return 1; |
9853 | } | |
9854 | ||
4a64f543 | 9855 | /* Deal with "catch catch" and "catch throw" commands. */ |
c906108c SS |
9856 | |
9857 | static void | |
fba45db2 KB |
9858 | catch_exception_command_1 (enum exception_event_kind ex_event, char *arg, |
9859 | int tempflag, int from_tty) | |
c906108c | 9860 | { |
c5aa993b | 9861 | char *cond_string = NULL; |
c5aa993b | 9862 | |
44feb3ce TT |
9863 | if (!arg) |
9864 | arg = ""; | |
e9cafbcc | 9865 | arg = skip_spaces (arg); |
c5aa993b | 9866 | |
c906108c SS |
9867 | cond_string = ep_parse_optional_if_clause (&arg); |
9868 | ||
9869 | if ((*arg != '\0') && !isspace (*arg)) | |
8a3fe4f8 | 9870 | error (_("Junk at end of arguments.")); |
c906108c | 9871 | |
059fb39f PM |
9872 | if (ex_event != EX_EVENT_THROW |
9873 | && ex_event != EX_EVENT_CATCH) | |
8a3fe4f8 | 9874 | error (_("Unsupported or unknown exception event; cannot catch it")); |
c906108c | 9875 | |
3086aeae DJ |
9876 | if (handle_gnu_v3_exceptions (tempflag, cond_string, ex_event, from_tty)) |
9877 | return; | |
9878 | ||
8a3fe4f8 | 9879 | warning (_("Unsupported with this platform/compiler combination.")); |
c906108c SS |
9880 | } |
9881 | ||
44feb3ce TT |
9882 | /* Implementation of "catch catch" command. */ |
9883 | ||
9884 | static void | |
9885 | catch_catch_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9886 | { | |
9887 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9888 | |
44feb3ce TT |
9889 | catch_exception_command_1 (EX_EVENT_CATCH, arg, tempflag, from_tty); |
9890 | } | |
9891 | ||
9892 | /* Implementation of "catch throw" command. */ | |
9893 | ||
9894 | static void | |
9895 | catch_throw_command (char *arg, int from_tty, struct cmd_list_element *command) | |
9896 | { | |
9897 | int tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
cc59ec59 | 9898 | |
44feb3ce TT |
9899 | catch_exception_command_1 (EX_EVENT_THROW, arg, tempflag, from_tty); |
9900 | } | |
9901 | ||
f7f9143b JB |
9902 | /* Create a breakpoint struct for Ada exception catchpoints. */ |
9903 | ||
9904 | static void | |
a6d9a66e UW |
9905 | create_ada_exception_breakpoint (struct gdbarch *gdbarch, |
9906 | struct symtab_and_line sal, | |
f7f9143b JB |
9907 | char *addr_string, |
9908 | char *exp_string, | |
9909 | char *cond_string, | |
9910 | struct expression *cond, | |
9911 | struct breakpoint_ops *ops, | |
9912 | int tempflag, | |
9913 | int from_tty) | |
9914 | { | |
9915 | struct breakpoint *b; | |
9916 | ||
9917 | if (from_tty) | |
9918 | { | |
5af949e3 UW |
9919 | struct gdbarch *loc_gdbarch = get_sal_arch (sal); |
9920 | if (!loc_gdbarch) | |
9921 | loc_gdbarch = gdbarch; | |
9922 | ||
6c95b8df PA |
9923 | describe_other_breakpoints (loc_gdbarch, |
9924 | sal.pspace, sal.pc, sal.section, -1); | |
f7f9143b JB |
9925 | /* FIXME: brobecker/2006-12-28: Actually, re-implement a special |
9926 | version for exception catchpoints, because two catchpoints | |
9927 | used for different exception names will use the same address. | |
9928 | In this case, a "breakpoint ... also set at..." warning is | |
4a64f543 | 9929 | unproductive. Besides, the warning phrasing is also a bit |
f7f9143b JB |
9930 | inapropriate, we should use the word catchpoint, and tell |
9931 | the user what type of catchpoint it is. The above is good | |
9932 | enough for now, though. */ | |
9933 | } | |
9934 | ||
a6d9a66e | 9935 | b = set_raw_breakpoint (gdbarch, sal, bp_breakpoint); |
f7f9143b JB |
9936 | set_breakpoint_count (breakpoint_count + 1); |
9937 | ||
9938 | b->enable_state = bp_enabled; | |
9939 | b->disposition = tempflag ? disp_del : disp_donttouch; | |
9940 | b->number = breakpoint_count; | |
9941 | b->ignore_count = 0; | |
511a6cd4 | 9942 | b->loc->cond = cond; |
f7f9143b JB |
9943 | b->addr_string = addr_string; |
9944 | b->language = language_ada; | |
9945 | b->cond_string = cond_string; | |
9946 | b->exp_string = exp_string; | |
9947 | b->thread = -1; | |
9948 | b->ops = ops; | |
f7f9143b JB |
9949 | |
9950 | mention (b); | |
8d3788bd | 9951 | observer_notify_breakpoint_created (b); |
b60e7edf | 9952 | update_global_location_list (1); |
f7f9143b JB |
9953 | } |
9954 | ||
9955 | /* Implement the "catch exception" command. */ | |
9956 | ||
9957 | static void | |
44feb3ce TT |
9958 | catch_ada_exception_command (char *arg, int from_tty, |
9959 | struct cmd_list_element *command) | |
f7f9143b | 9960 | { |
a6d9a66e | 9961 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 9962 | int tempflag; |
f7f9143b | 9963 | struct symtab_and_line sal; |
f7f9143b JB |
9964 | char *addr_string = NULL; |
9965 | char *exp_string = NULL; | |
9966 | char *cond_string = NULL; | |
9967 | struct expression *cond = NULL; | |
9968 | struct breakpoint_ops *ops = NULL; | |
9969 | ||
44feb3ce TT |
9970 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
9971 | ||
9972 | if (!arg) | |
9973 | arg = ""; | |
f7f9143b JB |
9974 | sal = ada_decode_exception_location (arg, &addr_string, &exp_string, |
9975 | &cond_string, &cond, &ops); | |
a6d9a66e | 9976 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, exp_string, |
f7f9143b JB |
9977 | cond_string, cond, ops, tempflag, |
9978 | from_tty); | |
9979 | } | |
9980 | ||
a96d9b2e SDJ |
9981 | /* Cleanup function for a syscall filter list. */ |
9982 | static void | |
9983 | clean_up_filters (void *arg) | |
9984 | { | |
9985 | VEC(int) *iter = *(VEC(int) **) arg; | |
9986 | VEC_free (int, iter); | |
9987 | } | |
9988 | ||
9989 | /* Splits the argument using space as delimiter. Returns an xmalloc'd | |
9990 | filter list, or NULL if no filtering is required. */ | |
9991 | static VEC(int) * | |
9992 | catch_syscall_split_args (char *arg) | |
9993 | { | |
9994 | VEC(int) *result = NULL; | |
9995 | struct cleanup *cleanup = make_cleanup (clean_up_filters, &result); | |
9996 | ||
9997 | while (*arg != '\0') | |
9998 | { | |
9999 | int i, syscall_number; | |
10000 | char *endptr; | |
10001 | char cur_name[128]; | |
10002 | struct syscall s; | |
10003 | ||
10004 | /* Skip whitespace. */ | |
10005 | while (isspace (*arg)) | |
10006 | arg++; | |
10007 | ||
10008 | for (i = 0; i < 127 && arg[i] && !isspace (arg[i]); ++i) | |
10009 | cur_name[i] = arg[i]; | |
10010 | cur_name[i] = '\0'; | |
10011 | arg += i; | |
10012 | ||
10013 | /* Check if the user provided a syscall name or a number. */ | |
10014 | syscall_number = (int) strtol (cur_name, &endptr, 0); | |
10015 | if (*endptr == '\0') | |
bccd0dd2 | 10016 | get_syscall_by_number (syscall_number, &s); |
a96d9b2e SDJ |
10017 | else |
10018 | { | |
10019 | /* We have a name. Let's check if it's valid and convert it | |
10020 | to a number. */ | |
10021 | get_syscall_by_name (cur_name, &s); | |
10022 | ||
10023 | if (s.number == UNKNOWN_SYSCALL) | |
4a64f543 MS |
10024 | /* Here we have to issue an error instead of a warning, |
10025 | because GDB cannot do anything useful if there's no | |
10026 | syscall number to be caught. */ | |
a96d9b2e SDJ |
10027 | error (_("Unknown syscall name '%s'."), cur_name); |
10028 | } | |
10029 | ||
10030 | /* Ok, it's valid. */ | |
10031 | VEC_safe_push (int, result, s.number); | |
10032 | } | |
10033 | ||
10034 | discard_cleanups (cleanup); | |
10035 | return result; | |
10036 | } | |
10037 | ||
10038 | /* Implement the "catch syscall" command. */ | |
10039 | ||
10040 | static void | |
cc59ec59 MS |
10041 | catch_syscall_command_1 (char *arg, int from_tty, |
10042 | struct cmd_list_element *command) | |
a96d9b2e SDJ |
10043 | { |
10044 | int tempflag; | |
10045 | VEC(int) *filter; | |
10046 | struct syscall s; | |
10047 | struct gdbarch *gdbarch = get_current_arch (); | |
10048 | ||
10049 | /* Checking if the feature if supported. */ | |
10050 | if (gdbarch_get_syscall_number_p (gdbarch) == 0) | |
10051 | error (_("The feature 'catch syscall' is not supported on \ | |
ea666128 | 10052 | this architecture yet.")); |
a96d9b2e SDJ |
10053 | |
10054 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; | |
10055 | ||
e9cafbcc | 10056 | arg = skip_spaces (arg); |
a96d9b2e SDJ |
10057 | |
10058 | /* We need to do this first "dummy" translation in order | |
10059 | to get the syscall XML file loaded or, most important, | |
10060 | to display a warning to the user if there's no XML file | |
10061 | for his/her architecture. */ | |
10062 | get_syscall_by_number (0, &s); | |
10063 | ||
10064 | /* The allowed syntax is: | |
10065 | catch syscall | |
10066 | catch syscall <name | number> [<name | number> ... <name | number>] | |
10067 | ||
10068 | Let's check if there's a syscall name. */ | |
10069 | ||
10070 | if (arg != NULL) | |
10071 | filter = catch_syscall_split_args (arg); | |
10072 | else | |
10073 | filter = NULL; | |
10074 | ||
10075 | create_syscall_event_catchpoint (tempflag, filter, | |
10076 | &catch_syscall_breakpoint_ops); | |
10077 | } | |
10078 | ||
f7f9143b JB |
10079 | /* Implement the "catch assert" command. */ |
10080 | ||
10081 | static void | |
3e43a32a MS |
10082 | catch_assert_command (char *arg, int from_tty, |
10083 | struct cmd_list_element *command) | |
f7f9143b | 10084 | { |
a6d9a66e | 10085 | struct gdbarch *gdbarch = get_current_arch (); |
44feb3ce | 10086 | int tempflag; |
f7f9143b JB |
10087 | struct symtab_and_line sal; |
10088 | char *addr_string = NULL; | |
10089 | struct breakpoint_ops *ops = NULL; | |
10090 | ||
44feb3ce TT |
10091 | tempflag = get_cmd_context (command) == CATCH_TEMPORARY; |
10092 | ||
10093 | if (!arg) | |
10094 | arg = ""; | |
f7f9143b | 10095 | sal = ada_decode_assert_location (arg, &addr_string, &ops); |
a6d9a66e UW |
10096 | create_ada_exception_breakpoint (gdbarch, sal, addr_string, NULL, NULL, NULL, |
10097 | ops, tempflag, from_tty); | |
f7f9143b JB |
10098 | } |
10099 | ||
c906108c | 10100 | static void |
fba45db2 | 10101 | catch_command (char *arg, int from_tty) |
c906108c | 10102 | { |
44feb3ce | 10103 | error (_("Catch requires an event name.")); |
c906108c SS |
10104 | } |
10105 | \f | |
10106 | ||
10107 | static void | |
fba45db2 | 10108 | tcatch_command (char *arg, int from_tty) |
c906108c | 10109 | { |
44feb3ce | 10110 | error (_("Catch requires an event name.")); |
c906108c SS |
10111 | } |
10112 | ||
80f8a6eb | 10113 | /* Delete breakpoints by address or line. */ |
c906108c SS |
10114 | |
10115 | static void | |
fba45db2 | 10116 | clear_command (char *arg, int from_tty) |
c906108c | 10117 | { |
d6e956e5 VP |
10118 | struct breakpoint *b; |
10119 | VEC(breakpoint_p) *found = 0; | |
10120 | int ix; | |
c906108c SS |
10121 | int default_match; |
10122 | struct symtabs_and_lines sals; | |
10123 | struct symtab_and_line sal; | |
c906108c SS |
10124 | int i; |
10125 | ||
10126 | if (arg) | |
10127 | { | |
10128 | sals = decode_line_spec (arg, 1); | |
10129 | default_match = 0; | |
10130 | } | |
10131 | else | |
10132 | { | |
c5aa993b | 10133 | sals.sals = (struct symtab_and_line *) |
c906108c | 10134 | xmalloc (sizeof (struct symtab_and_line)); |
80f8a6eb | 10135 | make_cleanup (xfree, sals.sals); |
4a64f543 | 10136 | init_sal (&sal); /* Initialize to zeroes. */ |
c906108c SS |
10137 | sal.line = default_breakpoint_line; |
10138 | sal.symtab = default_breakpoint_symtab; | |
10139 | sal.pc = default_breakpoint_address; | |
6c95b8df | 10140 | sal.pspace = default_breakpoint_pspace; |
c906108c | 10141 | if (sal.symtab == 0) |
8a3fe4f8 | 10142 | error (_("No source file specified.")); |
c906108c SS |
10143 | |
10144 | sals.sals[0] = sal; | |
10145 | sals.nelts = 1; | |
10146 | ||
10147 | default_match = 1; | |
10148 | } | |
10149 | ||
4a64f543 MS |
10150 | /* We don't call resolve_sal_pc here. That's not as bad as it |
10151 | seems, because all existing breakpoints typically have both | |
10152 | file/line and pc set. So, if clear is given file/line, we can | |
10153 | match this to existing breakpoint without obtaining pc at all. | |
ed0616c6 VP |
10154 | |
10155 | We only support clearing given the address explicitly | |
10156 | present in breakpoint table. Say, we've set breakpoint | |
4a64f543 | 10157 | at file:line. There were several PC values for that file:line, |
ed0616c6 | 10158 | due to optimization, all in one block. |
4a64f543 MS |
10159 | |
10160 | We've picked one PC value. If "clear" is issued with another | |
ed0616c6 VP |
10161 | PC corresponding to the same file:line, the breakpoint won't |
10162 | be cleared. We probably can still clear the breakpoint, but | |
10163 | since the other PC value is never presented to user, user | |
10164 | can only find it by guessing, and it does not seem important | |
10165 | to support that. */ | |
10166 | ||
4a64f543 MS |
10167 | /* For each line spec given, delete bps which correspond to it. Do |
10168 | it in two passes, solely to preserve the current behavior that | |
10169 | from_tty is forced true if we delete more than one | |
10170 | breakpoint. */ | |
c906108c | 10171 | |
80f8a6eb | 10172 | found = NULL; |
c906108c SS |
10173 | for (i = 0; i < sals.nelts; i++) |
10174 | { | |
10175 | /* If exact pc given, clear bpts at that pc. | |
c5aa993b JM |
10176 | If line given (pc == 0), clear all bpts on specified line. |
10177 | If defaulting, clear all bpts on default line | |
c906108c | 10178 | or at default pc. |
c5aa993b JM |
10179 | |
10180 | defaulting sal.pc != 0 tests to do | |
10181 | ||
10182 | 0 1 pc | |
10183 | 1 1 pc _and_ line | |
10184 | 0 0 line | |
10185 | 1 0 <can't happen> */ | |
c906108c SS |
10186 | |
10187 | sal = sals.sals[i]; | |
c906108c | 10188 | |
4a64f543 | 10189 | /* Find all matching breakpoints and add them to 'found'. */ |
d6e956e5 | 10190 | ALL_BREAKPOINTS (b) |
c5aa993b | 10191 | { |
0d381245 | 10192 | int match = 0; |
4a64f543 | 10193 | /* Are we going to delete b? */ |
cc60f2e3 | 10194 | if (b->type != bp_none && !is_watchpoint (b)) |
0d381245 VP |
10195 | { |
10196 | struct bp_location *loc = b->loc; | |
10197 | for (; loc; loc = loc->next) | |
10198 | { | |
6c95b8df PA |
10199 | int pc_match = sal.pc |
10200 | && (loc->pspace == sal.pspace) | |
0d381245 VP |
10201 | && (loc->address == sal.pc) |
10202 | && (!section_is_overlay (loc->section) | |
10203 | || loc->section == sal.section); | |
10204 | int line_match = ((default_match || (0 == sal.pc)) | |
10205 | && b->source_file != NULL | |
10206 | && sal.symtab != NULL | |
6c95b8df | 10207 | && sal.pspace == loc->pspace |
0ba1096a KT |
10208 | && filename_cmp (b->source_file, |
10209 | sal.symtab->filename) == 0 | |
0d381245 VP |
10210 | && b->line_number == sal.line); |
10211 | if (pc_match || line_match) | |
10212 | { | |
10213 | match = 1; | |
10214 | break; | |
10215 | } | |
10216 | } | |
10217 | } | |
10218 | ||
10219 | if (match) | |
d6e956e5 | 10220 | VEC_safe_push(breakpoint_p, found, b); |
c906108c | 10221 | } |
80f8a6eb MS |
10222 | } |
10223 | /* Now go thru the 'found' chain and delete them. */ | |
d6e956e5 | 10224 | if (VEC_empty(breakpoint_p, found)) |
80f8a6eb MS |
10225 | { |
10226 | if (arg) | |
8a3fe4f8 | 10227 | error (_("No breakpoint at %s."), arg); |
80f8a6eb | 10228 | else |
8a3fe4f8 | 10229 | error (_("No breakpoint at this line.")); |
80f8a6eb | 10230 | } |
c906108c | 10231 | |
d6e956e5 | 10232 | if (VEC_length(breakpoint_p, found) > 1) |
4a64f543 | 10233 | from_tty = 1; /* Always report if deleted more than one. */ |
80f8a6eb | 10234 | if (from_tty) |
a3f17187 | 10235 | { |
d6e956e5 | 10236 | if (VEC_length(breakpoint_p, found) == 1) |
a3f17187 AC |
10237 | printf_unfiltered (_("Deleted breakpoint ")); |
10238 | else | |
10239 | printf_unfiltered (_("Deleted breakpoints ")); | |
10240 | } | |
80f8a6eb | 10241 | breakpoints_changed (); |
d6e956e5 VP |
10242 | |
10243 | for (ix = 0; VEC_iterate(breakpoint_p, found, ix, b); ix++) | |
80f8a6eb | 10244 | { |
c5aa993b | 10245 | if (from_tty) |
d6e956e5 VP |
10246 | printf_unfiltered ("%d ", b->number); |
10247 | delete_breakpoint (b); | |
c906108c | 10248 | } |
80f8a6eb MS |
10249 | if (from_tty) |
10250 | putchar_unfiltered ('\n'); | |
c906108c SS |
10251 | } |
10252 | \f | |
10253 | /* Delete breakpoint in BS if they are `delete' breakpoints and | |
10254 | all breakpoints that are marked for deletion, whether hit or not. | |
10255 | This is called after any breakpoint is hit, or after errors. */ | |
10256 | ||
10257 | void | |
fba45db2 | 10258 | breakpoint_auto_delete (bpstat bs) |
c906108c | 10259 | { |
35df4500 | 10260 | struct breakpoint *b, *b_tmp; |
c906108c SS |
10261 | |
10262 | for (; bs; bs = bs->next) | |
f431efe5 PA |
10263 | if (bs->breakpoint_at |
10264 | && bs->breakpoint_at->disposition == disp_del | |
c906108c | 10265 | && bs->stop) |
f431efe5 | 10266 | delete_breakpoint (bs->breakpoint_at); |
c906108c | 10267 | |
35df4500 | 10268 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 10269 | { |
b5de0fa7 | 10270 | if (b->disposition == disp_del_at_next_stop) |
c5aa993b JM |
10271 | delete_breakpoint (b); |
10272 | } | |
c906108c SS |
10273 | } |
10274 | ||
4a64f543 MS |
10275 | /* A comparison function for bp_location AP and BP being interfaced to |
10276 | qsort. Sort elements primarily by their ADDRESS (no matter what | |
10277 | does breakpoint_address_is_meaningful say for its OWNER), | |
10278 | secondarily by ordering first bp_permanent OWNERed elements and | |
10279 | terciarily just ensuring the array is sorted stable way despite | |
10280 | qsort being an instable algorithm. */ | |
876fa593 JK |
10281 | |
10282 | static int | |
494cfb0f | 10283 | bp_location_compare (const void *ap, const void *bp) |
876fa593 | 10284 | { |
494cfb0f JK |
10285 | struct bp_location *a = *(void **) ap; |
10286 | struct bp_location *b = *(void **) bp; | |
2bdf28a0 | 10287 | /* A and B come from existing breakpoints having non-NULL OWNER. */ |
876fa593 JK |
10288 | int a_perm = a->owner->enable_state == bp_permanent; |
10289 | int b_perm = b->owner->enable_state == bp_permanent; | |
10290 | ||
10291 | if (a->address != b->address) | |
10292 | return (a->address > b->address) - (a->address < b->address); | |
10293 | ||
10294 | /* Sort permanent breakpoints first. */ | |
10295 | if (a_perm != b_perm) | |
10296 | return (a_perm < b_perm) - (a_perm > b_perm); | |
10297 | ||
4a64f543 MS |
10298 | /* Make the user-visible order stable across GDB runs. Locations of |
10299 | the same breakpoint can be sorted in arbitrary order. */ | |
876fa593 JK |
10300 | |
10301 | if (a->owner->number != b->owner->number) | |
10302 | return (a->owner->number > b->owner->number) | |
10303 | - (a->owner->number < b->owner->number); | |
10304 | ||
10305 | return (a > b) - (a < b); | |
10306 | } | |
10307 | ||
876fa593 | 10308 | /* Set bp_location_placed_address_before_address_max and |
4a64f543 MS |
10309 | bp_location_shadow_len_after_address_max according to the current |
10310 | content of the bp_location array. */ | |
f7545552 TT |
10311 | |
10312 | static void | |
876fa593 | 10313 | bp_location_target_extensions_update (void) |
f7545552 | 10314 | { |
876fa593 JK |
10315 | struct bp_location *bl, **blp_tmp; |
10316 | ||
10317 | bp_location_placed_address_before_address_max = 0; | |
10318 | bp_location_shadow_len_after_address_max = 0; | |
10319 | ||
10320 | ALL_BP_LOCATIONS (bl, blp_tmp) | |
10321 | { | |
10322 | CORE_ADDR start, end, addr; | |
10323 | ||
10324 | if (!bp_location_has_shadow (bl)) | |
10325 | continue; | |
10326 | ||
10327 | start = bl->target_info.placed_address; | |
10328 | end = start + bl->target_info.shadow_len; | |
10329 | ||
10330 | gdb_assert (bl->address >= start); | |
10331 | addr = bl->address - start; | |
10332 | if (addr > bp_location_placed_address_before_address_max) | |
10333 | bp_location_placed_address_before_address_max = addr; | |
10334 | ||
10335 | /* Zero SHADOW_LEN would not pass bp_location_has_shadow. */ | |
10336 | ||
10337 | gdb_assert (bl->address < end); | |
10338 | addr = end - bl->address; | |
10339 | if (addr > bp_location_shadow_len_after_address_max) | |
10340 | bp_location_shadow_len_after_address_max = addr; | |
10341 | } | |
f7545552 TT |
10342 | } |
10343 | ||
4cd9bd08 | 10344 | /* If SHOULD_INSERT is false, do not insert any breakpoint locations |
b60e7edf PA |
10345 | into the inferior, only remove already-inserted locations that no |
10346 | longer should be inserted. Functions that delete a breakpoint or | |
10347 | breakpoints should pass false, so that deleting a breakpoint | |
10348 | doesn't have the side effect of inserting the locations of other | |
10349 | breakpoints that are marked not-inserted, but should_be_inserted | |
10350 | returns true on them. | |
10351 | ||
10352 | This behaviour is useful is situations close to tear-down -- e.g., | |
10353 | after an exec, while the target still has execution, but breakpoint | |
10354 | shadows of the previous executable image should *NOT* be restored | |
10355 | to the new image; or before detaching, where the target still has | |
10356 | execution and wants to delete breakpoints from GDB's lists, and all | |
10357 | breakpoints had already been removed from the inferior. */ | |
10358 | ||
0d381245 | 10359 | static void |
b60e7edf | 10360 | update_global_location_list (int should_insert) |
0d381245 | 10361 | { |
74960c60 | 10362 | struct breakpoint *b; |
876fa593 | 10363 | struct bp_location **locp, *loc; |
f7545552 TT |
10364 | struct cleanup *cleanups; |
10365 | ||
2d134ed3 PA |
10366 | /* Used in the duplicates detection below. When iterating over all |
10367 | bp_locations, points to the first bp_location of a given address. | |
10368 | Breakpoints and watchpoints of different types are never | |
10369 | duplicates of each other. Keep one pointer for each type of | |
10370 | breakpoint/watchpoint, so we only need to loop over all locations | |
10371 | once. */ | |
10372 | struct bp_location *bp_loc_first; /* breakpoint */ | |
10373 | struct bp_location *wp_loc_first; /* hardware watchpoint */ | |
10374 | struct bp_location *awp_loc_first; /* access watchpoint */ | |
10375 | struct bp_location *rwp_loc_first; /* read watchpoint */ | |
876fa593 | 10376 | |
4a64f543 MS |
10377 | /* Saved former bp_location array which we compare against the newly |
10378 | built bp_location from the current state of ALL_BREAKPOINTS. */ | |
876fa593 JK |
10379 | struct bp_location **old_location, **old_locp; |
10380 | unsigned old_location_count; | |
10381 | ||
10382 | old_location = bp_location; | |
10383 | old_location_count = bp_location_count; | |
10384 | bp_location = NULL; | |
10385 | bp_location_count = 0; | |
10386 | cleanups = make_cleanup (xfree, old_location); | |
0d381245 | 10387 | |
74960c60 | 10388 | ALL_BREAKPOINTS (b) |
876fa593 JK |
10389 | for (loc = b->loc; loc; loc = loc->next) |
10390 | bp_location_count++; | |
10391 | ||
10392 | bp_location = xmalloc (sizeof (*bp_location) * bp_location_count); | |
10393 | locp = bp_location; | |
10394 | ALL_BREAKPOINTS (b) | |
10395 | for (loc = b->loc; loc; loc = loc->next) | |
10396 | *locp++ = loc; | |
10397 | qsort (bp_location, bp_location_count, sizeof (*bp_location), | |
494cfb0f | 10398 | bp_location_compare); |
876fa593 JK |
10399 | |
10400 | bp_location_target_extensions_update (); | |
74960c60 | 10401 | |
4a64f543 MS |
10402 | /* Identify bp_location instances that are no longer present in the |
10403 | new list, and therefore should be freed. Note that it's not | |
10404 | necessary that those locations should be removed from inferior -- | |
10405 | if there's another location at the same address (previously | |
10406 | marked as duplicate), we don't need to remove/insert the | |
10407 | location. | |
876fa593 | 10408 | |
4a64f543 MS |
10409 | LOCP is kept in sync with OLD_LOCP, each pointing to the current |
10410 | and former bp_location array state respectively. */ | |
876fa593 JK |
10411 | |
10412 | locp = bp_location; | |
10413 | for (old_locp = old_location; old_locp < old_location + old_location_count; | |
10414 | old_locp++) | |
74960c60 | 10415 | { |
876fa593 | 10416 | struct bp_location *old_loc = *old_locp; |
c7d46a38 | 10417 | struct bp_location **loc2p; |
876fa593 | 10418 | |
4a64f543 MS |
10419 | /* Tells if 'old_loc' is found amoung the new locations. If |
10420 | not, we have to free it. */ | |
c7d46a38 | 10421 | int found_object = 0; |
20874c92 VP |
10422 | /* Tells if the location should remain inserted in the target. */ |
10423 | int keep_in_target = 0; | |
10424 | int removed = 0; | |
876fa593 | 10425 | |
4a64f543 MS |
10426 | /* Skip LOCP entries which will definitely never be needed. |
10427 | Stop either at or being the one matching OLD_LOC. */ | |
876fa593 | 10428 | while (locp < bp_location + bp_location_count |
c7d46a38 | 10429 | && (*locp)->address < old_loc->address) |
876fa593 | 10430 | locp++; |
c7d46a38 PA |
10431 | |
10432 | for (loc2p = locp; | |
10433 | (loc2p < bp_location + bp_location_count | |
10434 | && (*loc2p)->address == old_loc->address); | |
10435 | loc2p++) | |
10436 | { | |
10437 | if (*loc2p == old_loc) | |
10438 | { | |
10439 | found_object = 1; | |
10440 | break; | |
10441 | } | |
10442 | } | |
74960c60 | 10443 | |
4a64f543 MS |
10444 | /* If this location is no longer present, and inserted, look if |
10445 | there's maybe a new location at the same address. If so, | |
10446 | mark that one inserted, and don't remove this one. This is | |
10447 | needed so that we don't have a time window where a breakpoint | |
10448 | at certain location is not inserted. */ | |
74960c60 | 10449 | |
876fa593 | 10450 | if (old_loc->inserted) |
0d381245 | 10451 | { |
4a64f543 MS |
10452 | /* If the location is inserted now, we might have to remove |
10453 | it. */ | |
74960c60 | 10454 | |
876fa593 | 10455 | if (found_object && should_be_inserted (old_loc)) |
74960c60 | 10456 | { |
4a64f543 MS |
10457 | /* The location is still present in the location list, |
10458 | and still should be inserted. Don't do anything. */ | |
20874c92 | 10459 | keep_in_target = 1; |
74960c60 VP |
10460 | } |
10461 | else | |
10462 | { | |
4a64f543 MS |
10463 | /* The location is either no longer present, or got |
10464 | disabled. See if there's another location at the | |
10465 | same address, in which case we don't need to remove | |
10466 | this one from the target. */ | |
876fa593 | 10467 | |
2bdf28a0 | 10468 | /* OLD_LOC comes from existing struct breakpoint. */ |
876fa593 JK |
10469 | if (breakpoint_address_is_meaningful (old_loc->owner)) |
10470 | { | |
876fa593 | 10471 | for (loc2p = locp; |
c7d46a38 PA |
10472 | (loc2p < bp_location + bp_location_count |
10473 | && (*loc2p)->address == old_loc->address); | |
876fa593 JK |
10474 | loc2p++) |
10475 | { | |
10476 | struct bp_location *loc2 = *loc2p; | |
10477 | ||
2d134ed3 | 10478 | if (breakpoint_locations_match (loc2, old_loc)) |
c7d46a38 PA |
10479 | { |
10480 | /* For the sake of should_be_inserted. | |
4a64f543 MS |
10481 | Duplicates check below will fix up this |
10482 | later. */ | |
c7d46a38 | 10483 | loc2->duplicate = 0; |
85d721b8 PA |
10484 | |
10485 | /* Read watchpoint locations are switched to | |
10486 | access watchpoints, if the former are not | |
10487 | supported, but the latter are. */ | |
10488 | if (is_hardware_watchpoint (old_loc->owner)) | |
10489 | { | |
10490 | gdb_assert (is_hardware_watchpoint (loc2->owner)); | |
10491 | loc2->watchpoint_type = old_loc->watchpoint_type; | |
10492 | } | |
10493 | ||
c7d46a38 PA |
10494 | if (loc2 != old_loc && should_be_inserted (loc2)) |
10495 | { | |
10496 | loc2->inserted = 1; | |
10497 | loc2->target_info = old_loc->target_info; | |
10498 | keep_in_target = 1; | |
10499 | break; | |
10500 | } | |
876fa593 JK |
10501 | } |
10502 | } | |
10503 | } | |
74960c60 VP |
10504 | } |
10505 | ||
20874c92 VP |
10506 | if (!keep_in_target) |
10507 | { | |
876fa593 | 10508 | if (remove_breakpoint (old_loc, mark_uninserted)) |
20874c92 | 10509 | { |
4a64f543 MS |
10510 | /* This is just about all we can do. We could keep |
10511 | this location on the global list, and try to | |
10512 | remove it next time, but there's no particular | |
10513 | reason why we will succeed next time. | |
20874c92 | 10514 | |
4a64f543 MS |
10515 | Note that at this point, old_loc->owner is still |
10516 | valid, as delete_breakpoint frees the breakpoint | |
10517 | only after calling us. */ | |
3e43a32a MS |
10518 | printf_filtered (_("warning: Error removing " |
10519 | "breakpoint %d\n"), | |
876fa593 | 10520 | old_loc->owner->number); |
20874c92 VP |
10521 | } |
10522 | removed = 1; | |
10523 | } | |
0d381245 | 10524 | } |
74960c60 VP |
10525 | |
10526 | if (!found_object) | |
1c5cfe86 | 10527 | { |
db82e815 PA |
10528 | if (removed && non_stop |
10529 | && breakpoint_address_is_meaningful (old_loc->owner) | |
10530 | && !is_hardware_watchpoint (old_loc->owner)) | |
20874c92 | 10531 | { |
db82e815 PA |
10532 | /* This location was removed from the target. In |
10533 | non-stop mode, a race condition is possible where | |
10534 | we've removed a breakpoint, but stop events for that | |
10535 | breakpoint are already queued and will arrive later. | |
10536 | We apply an heuristic to be able to distinguish such | |
10537 | SIGTRAPs from other random SIGTRAPs: we keep this | |
10538 | breakpoint location for a bit, and will retire it | |
10539 | after we see some number of events. The theory here | |
10540 | is that reporting of events should, "on the average", | |
10541 | be fair, so after a while we'll see events from all | |
10542 | threads that have anything of interest, and no longer | |
10543 | need to keep this breakpoint location around. We | |
10544 | don't hold locations forever so to reduce chances of | |
10545 | mistaking a non-breakpoint SIGTRAP for a breakpoint | |
10546 | SIGTRAP. | |
10547 | ||
10548 | The heuristic failing can be disastrous on | |
10549 | decr_pc_after_break targets. | |
10550 | ||
10551 | On decr_pc_after_break targets, like e.g., x86-linux, | |
10552 | if we fail to recognize a late breakpoint SIGTRAP, | |
10553 | because events_till_retirement has reached 0 too | |
10554 | soon, we'll fail to do the PC adjustment, and report | |
10555 | a random SIGTRAP to the user. When the user resumes | |
10556 | the inferior, it will most likely immediately crash | |
2dec564e | 10557 | with SIGILL/SIGBUS/SIGSEGV, or worse, get silently |
db82e815 PA |
10558 | corrupted, because of being resumed e.g., in the |
10559 | middle of a multi-byte instruction, or skipped a | |
10560 | one-byte instruction. This was actually seen happen | |
10561 | on native x86-linux, and should be less rare on | |
10562 | targets that do not support new thread events, like | |
10563 | remote, due to the heuristic depending on | |
10564 | thread_count. | |
10565 | ||
10566 | Mistaking a random SIGTRAP for a breakpoint trap | |
10567 | causes similar symptoms (PC adjustment applied when | |
10568 | it shouldn't), but then again, playing with SIGTRAPs | |
10569 | behind the debugger's back is asking for trouble. | |
10570 | ||
10571 | Since hardware watchpoint traps are always | |
10572 | distinguishable from other traps, so we don't need to | |
10573 | apply keep hardware watchpoint moribund locations | |
10574 | around. We simply always ignore hardware watchpoint | |
10575 | traps we can no longer explain. */ | |
10576 | ||
876fa593 JK |
10577 | old_loc->events_till_retirement = 3 * (thread_count () + 1); |
10578 | old_loc->owner = NULL; | |
20874c92 | 10579 | |
876fa593 | 10580 | VEC_safe_push (bp_location_p, moribund_locations, old_loc); |
1c5cfe86 PA |
10581 | } |
10582 | else | |
f431efe5 PA |
10583 | { |
10584 | old_loc->owner = NULL; | |
10585 | decref_bp_location (&old_loc); | |
10586 | } | |
20874c92 | 10587 | } |
74960c60 | 10588 | } |
1c5cfe86 | 10589 | |
2d134ed3 PA |
10590 | /* Rescan breakpoints at the same address and section, marking the |
10591 | first one as "first" and any others as "duplicates". This is so | |
10592 | that the bpt instruction is only inserted once. If we have a | |
10593 | permanent breakpoint at the same place as BPT, make that one the | |
10594 | official one, and the rest as duplicates. Permanent breakpoints | |
10595 | are sorted first for the same address. | |
10596 | ||
10597 | Do the same for hardware watchpoints, but also considering the | |
10598 | watchpoint's type (regular/access/read) and length. */ | |
876fa593 | 10599 | |
2d134ed3 PA |
10600 | bp_loc_first = NULL; |
10601 | wp_loc_first = NULL; | |
10602 | awp_loc_first = NULL; | |
10603 | rwp_loc_first = NULL; | |
876fa593 | 10604 | ALL_BP_LOCATIONS (loc, locp) |
74960c60 | 10605 | { |
4a64f543 MS |
10606 | /* ALL_BP_LOCATIONS bp_location has LOC->OWNER always |
10607 | non-NULL. */ | |
876fa593 | 10608 | struct breakpoint *b = loc->owner; |
2d134ed3 | 10609 | struct bp_location **loc_first_p; |
876fa593 JK |
10610 | |
10611 | if (b->enable_state == bp_disabled | |
10612 | || b->enable_state == bp_call_disabled | |
10613 | || b->enable_state == bp_startup_disabled | |
10614 | || !loc->enabled | |
10615 | || loc->shlib_disabled | |
15c3d785 | 10616 | || !breakpoint_address_is_meaningful (b) |
d77f58be | 10617 | || is_tracepoint (b)) |
876fa593 JK |
10618 | continue; |
10619 | ||
10620 | /* Permanent breakpoint should always be inserted. */ | |
10621 | if (b->enable_state == bp_permanent && ! loc->inserted) | |
10622 | internal_error (__FILE__, __LINE__, | |
10623 | _("allegedly permanent breakpoint is not " | |
10624 | "actually inserted")); | |
10625 | ||
2d134ed3 PA |
10626 | if (b->type == bp_hardware_watchpoint) |
10627 | loc_first_p = &wp_loc_first; | |
10628 | else if (b->type == bp_read_watchpoint) | |
10629 | loc_first_p = &rwp_loc_first; | |
10630 | else if (b->type == bp_access_watchpoint) | |
10631 | loc_first_p = &awp_loc_first; | |
10632 | else | |
10633 | loc_first_p = &bp_loc_first; | |
10634 | ||
10635 | if (*loc_first_p == NULL | |
10636 | || (overlay_debugging && loc->section != (*loc_first_p)->section) | |
10637 | || !breakpoint_locations_match (loc, *loc_first_p)) | |
876fa593 | 10638 | { |
2d134ed3 | 10639 | *loc_first_p = loc; |
876fa593 JK |
10640 | loc->duplicate = 0; |
10641 | continue; | |
10642 | } | |
10643 | ||
10644 | loc->duplicate = 1; | |
10645 | ||
2d134ed3 PA |
10646 | if ((*loc_first_p)->owner->enable_state == bp_permanent && loc->inserted |
10647 | && b->enable_state != bp_permanent) | |
876fa593 JK |
10648 | internal_error (__FILE__, __LINE__, |
10649 | _("another breakpoint was inserted on top of " | |
10650 | "a permanent breakpoint")); | |
0d381245 | 10651 | } |
74960c60 | 10652 | |
50c71eaf | 10653 | if (breakpoints_always_inserted_mode () && should_insert |
c35b1492 | 10654 | && (have_live_inferiors () |
2567c7d9 | 10655 | || (gdbarch_has_global_breakpoints (target_gdbarch)))) |
74960c60 | 10656 | insert_breakpoint_locations (); |
f7545552 TT |
10657 | |
10658 | do_cleanups (cleanups); | |
74960c60 VP |
10659 | } |
10660 | ||
20874c92 VP |
10661 | void |
10662 | breakpoint_retire_moribund (void) | |
10663 | { | |
10664 | struct bp_location *loc; | |
10665 | int ix; | |
10666 | ||
10667 | for (ix = 0; VEC_iterate (bp_location_p, moribund_locations, ix, loc); ++ix) | |
10668 | if (--(loc->events_till_retirement) == 0) | |
10669 | { | |
f431efe5 | 10670 | decref_bp_location (&loc); |
20874c92 VP |
10671 | VEC_unordered_remove (bp_location_p, moribund_locations, ix); |
10672 | --ix; | |
10673 | } | |
10674 | } | |
10675 | ||
74960c60 | 10676 | static void |
b60e7edf | 10677 | update_global_location_list_nothrow (int inserting) |
74960c60 VP |
10678 | { |
10679 | struct gdb_exception e; | |
cc59ec59 | 10680 | |
74960c60 | 10681 | TRY_CATCH (e, RETURN_MASK_ERROR) |
b60e7edf | 10682 | update_global_location_list (inserting); |
0d381245 VP |
10683 | } |
10684 | ||
f431efe5 PA |
10685 | /* Clear BKP from a BPS. */ |
10686 | ||
a474d7c2 | 10687 | static void |
f431efe5 | 10688 | bpstat_remove_bp_location (bpstat bps, struct breakpoint *bpt) |
a474d7c2 PA |
10689 | { |
10690 | bpstat bs; | |
cc59ec59 | 10691 | |
a474d7c2 | 10692 | for (bs = bps; bs; bs = bs->next) |
f431efe5 | 10693 | if (bs->breakpoint_at == bpt) |
a474d7c2 PA |
10694 | { |
10695 | bs->breakpoint_at = NULL; | |
10696 | bs->old_val = NULL; | |
10697 | /* bs->commands will be freed later. */ | |
10698 | } | |
10699 | } | |
10700 | ||
10701 | /* Callback for iterate_over_threads. */ | |
10702 | static int | |
f431efe5 | 10703 | bpstat_remove_breakpoint_callback (struct thread_info *th, void *data) |
a474d7c2 | 10704 | { |
f431efe5 | 10705 | struct breakpoint *bpt = data; |
cc59ec59 | 10706 | |
16c381f0 | 10707 | bpstat_remove_bp_location (th->control.stop_bpstat, bpt); |
a474d7c2 PA |
10708 | return 0; |
10709 | } | |
10710 | ||
53a5351d | 10711 | /* Delete a breakpoint and clean up all traces of it in the data |
f431efe5 | 10712 | structures. */ |
c906108c SS |
10713 | |
10714 | void | |
fba45db2 | 10715 | delete_breakpoint (struct breakpoint *bpt) |
c906108c | 10716 | { |
52f0bd74 | 10717 | struct breakpoint *b; |
c906108c | 10718 | |
8a3fe4f8 | 10719 | gdb_assert (bpt != NULL); |
c906108c | 10720 | |
4a64f543 MS |
10721 | /* Has this bp already been deleted? This can happen because |
10722 | multiple lists can hold pointers to bp's. bpstat lists are | |
10723 | especial culprits. | |
10724 | ||
10725 | One example of this happening is a watchpoint's scope bp. When | |
10726 | the scope bp triggers, we notice that the watchpoint is out of | |
10727 | scope, and delete it. We also delete its scope bp. But the | |
10728 | scope bp is marked "auto-deleting", and is already on a bpstat. | |
10729 | That bpstat is then checked for auto-deleting bp's, which are | |
10730 | deleted. | |
10731 | ||
10732 | A real solution to this problem might involve reference counts in | |
10733 | bp's, and/or giving them pointers back to their referencing | |
10734 | bpstat's, and teaching delete_breakpoint to only free a bp's | |
10735 | storage when no more references were extent. A cheaper bandaid | |
10736 | was chosen. */ | |
c906108c SS |
10737 | if (bpt->type == bp_none) |
10738 | return; | |
10739 | ||
4a64f543 MS |
10740 | /* At least avoid this stale reference until the reference counting |
10741 | of breakpoints gets resolved. */ | |
d0fb5eae | 10742 | if (bpt->related_breakpoint != bpt) |
e5a0a904 | 10743 | { |
d0fb5eae JK |
10744 | struct breakpoint *related; |
10745 | ||
10746 | if (bpt->type == bp_watchpoint_scope) | |
10747 | watchpoint_del_at_next_stop (bpt->related_breakpoint); | |
10748 | else if (bpt->related_breakpoint->type == bp_watchpoint_scope) | |
10749 | watchpoint_del_at_next_stop (bpt); | |
10750 | ||
10751 | /* Unlink bpt from the bpt->related_breakpoint ring. */ | |
10752 | for (related = bpt; related->related_breakpoint != bpt; | |
10753 | related = related->related_breakpoint); | |
10754 | related->related_breakpoint = bpt->related_breakpoint; | |
10755 | bpt->related_breakpoint = bpt; | |
e5a0a904 JK |
10756 | } |
10757 | ||
a9634178 TJB |
10758 | /* watch_command_1 creates a watchpoint but only sets its number if |
10759 | update_watchpoint succeeds in creating its bp_locations. If there's | |
10760 | a problem in that process, we'll be asked to delete the half-created | |
10761 | watchpoint. In that case, don't announce the deletion. */ | |
10762 | if (bpt->number) | |
10763 | observer_notify_breakpoint_deleted (bpt); | |
c906108c | 10764 | |
c906108c SS |
10765 | if (breakpoint_chain == bpt) |
10766 | breakpoint_chain = bpt->next; | |
10767 | ||
c906108c SS |
10768 | ALL_BREAKPOINTS (b) |
10769 | if (b->next == bpt) | |
c5aa993b JM |
10770 | { |
10771 | b->next = bpt->next; | |
10772 | break; | |
10773 | } | |
c906108c | 10774 | |
9add0f1b | 10775 | decref_counted_command_line (&bpt->commands); |
60e1c644 PA |
10776 | xfree (bpt->cond_string); |
10777 | xfree (bpt->cond_exp); | |
10778 | xfree (bpt->addr_string); | |
f1310107 | 10779 | xfree (bpt->addr_string_range_end); |
60e1c644 PA |
10780 | xfree (bpt->exp); |
10781 | xfree (bpt->exp_string); | |
d63d0675 | 10782 | xfree (bpt->exp_string_reparse); |
60e1c644 PA |
10783 | value_free (bpt->val); |
10784 | xfree (bpt->source_file); | |
10785 | xfree (bpt->exec_pathname); | |
a96d9b2e | 10786 | clean_up_filters (&bpt->syscalls_to_be_caught); |
c906108c | 10787 | |
f431efe5 PA |
10788 | |
10789 | /* Be sure no bpstat's are pointing at the breakpoint after it's | |
10790 | been freed. */ | |
10791 | /* FIXME, how can we find all bpstat's? We just check stop_bpstat | |
10792 | in all threeds for now. Note that we cannot just remove bpstats | |
10793 | pointing at bpt from the stop_bpstat list entirely, as breakpoint | |
10794 | commands are associated with the bpstat; if we remove it here, | |
10795 | then the later call to bpstat_do_actions (&stop_bpstat); in | |
10796 | event-top.c won't do anything, and temporary breakpoints with | |
10797 | commands won't work. */ | |
10798 | ||
10799 | iterate_over_threads (bpstat_remove_breakpoint_callback, bpt); | |
10800 | ||
4a64f543 MS |
10801 | /* Now that breakpoint is removed from breakpoint list, update the |
10802 | global location list. This will remove locations that used to | |
10803 | belong to this breakpoint. Do this before freeing the breakpoint | |
10804 | itself, since remove_breakpoint looks at location's owner. It | |
10805 | might be better design to have location completely | |
10806 | self-contained, but it's not the case now. */ | |
b60e7edf | 10807 | update_global_location_list (0); |
74960c60 VP |
10808 | |
10809 | ||
4a64f543 MS |
10810 | /* On the chance that someone will soon try again to delete this |
10811 | same bp, we mark it as deleted before freeing its storage. */ | |
c906108c SS |
10812 | bpt->type = bp_none; |
10813 | ||
b8c9b27d | 10814 | xfree (bpt); |
c906108c SS |
10815 | } |
10816 | ||
4d6140d9 AC |
10817 | static void |
10818 | do_delete_breakpoint_cleanup (void *b) | |
10819 | { | |
10820 | delete_breakpoint (b); | |
10821 | } | |
10822 | ||
10823 | struct cleanup * | |
10824 | make_cleanup_delete_breakpoint (struct breakpoint *b) | |
10825 | { | |
10826 | return make_cleanup (do_delete_breakpoint_cleanup, b); | |
10827 | } | |
10828 | ||
51be5b68 PA |
10829 | /* Iterator function to call a user-provided callback function once |
10830 | for each of B and its related breakpoints. */ | |
10831 | ||
10832 | static void | |
10833 | iterate_over_related_breakpoints (struct breakpoint *b, | |
10834 | void (*function) (struct breakpoint *, | |
10835 | void *), | |
10836 | void *data) | |
10837 | { | |
10838 | struct breakpoint *related; | |
10839 | ||
10840 | related = b; | |
10841 | do | |
10842 | { | |
10843 | struct breakpoint *next; | |
10844 | ||
10845 | /* FUNCTION may delete RELATED. */ | |
10846 | next = related->related_breakpoint; | |
10847 | ||
10848 | if (next == related) | |
10849 | { | |
10850 | /* RELATED is the last ring entry. */ | |
10851 | function (related, data); | |
10852 | ||
10853 | /* FUNCTION may have deleted it, so we'd never reach back to | |
10854 | B. There's nothing left to do anyway, so just break | |
10855 | out. */ | |
10856 | break; | |
10857 | } | |
10858 | else | |
10859 | function (related, data); | |
10860 | ||
10861 | related = next; | |
10862 | } | |
10863 | while (related != b); | |
10864 | } | |
95a42b64 TT |
10865 | |
10866 | static void | |
10867 | do_delete_breakpoint (struct breakpoint *b, void *ignore) | |
10868 | { | |
10869 | delete_breakpoint (b); | |
10870 | } | |
10871 | ||
51be5b68 PA |
10872 | /* A callback for map_breakpoint_numbers that calls |
10873 | delete_breakpoint. */ | |
10874 | ||
10875 | static void | |
10876 | do_map_delete_breakpoint (struct breakpoint *b, void *ignore) | |
10877 | { | |
10878 | iterate_over_related_breakpoints (b, do_delete_breakpoint, NULL); | |
10879 | } | |
10880 | ||
c906108c | 10881 | void |
fba45db2 | 10882 | delete_command (char *arg, int from_tty) |
c906108c | 10883 | { |
35df4500 | 10884 | struct breakpoint *b, *b_tmp; |
c906108c | 10885 | |
ea9365bb TT |
10886 | dont_repeat (); |
10887 | ||
c906108c SS |
10888 | if (arg == 0) |
10889 | { | |
10890 | int breaks_to_delete = 0; | |
10891 | ||
46c6471b PA |
10892 | /* Delete all breakpoints if no argument. Do not delete |
10893 | internal breakpoints, these have to be deleted with an | |
10894 | explicit breakpoint number argument. */ | |
c5aa993b | 10895 | ALL_BREAKPOINTS (b) |
46c6471b | 10896 | if (user_breakpoint_p (b)) |
973d738b DJ |
10897 | { |
10898 | breaks_to_delete = 1; | |
10899 | break; | |
10900 | } | |
c906108c SS |
10901 | |
10902 | /* Ask user only if there are some breakpoints to delete. */ | |
10903 | if (!from_tty | |
e2e0b3e5 | 10904 | || (breaks_to_delete && query (_("Delete all breakpoints? ")))) |
c906108c | 10905 | { |
35df4500 | 10906 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 10907 | if (user_breakpoint_p (b)) |
c5aa993b | 10908 | delete_breakpoint (b); |
c906108c SS |
10909 | } |
10910 | } | |
10911 | else | |
51be5b68 | 10912 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
c906108c SS |
10913 | } |
10914 | ||
0d381245 VP |
10915 | static int |
10916 | all_locations_are_pending (struct bp_location *loc) | |
fe3f5fa8 | 10917 | { |
0d381245 VP |
10918 | for (; loc; loc = loc->next) |
10919 | if (!loc->shlib_disabled) | |
10920 | return 0; | |
10921 | return 1; | |
fe3f5fa8 VP |
10922 | } |
10923 | ||
776592bf DE |
10924 | /* Subroutine of update_breakpoint_locations to simplify it. |
10925 | Return non-zero if multiple fns in list LOC have the same name. | |
10926 | Null names are ignored. */ | |
10927 | ||
10928 | static int | |
10929 | ambiguous_names_p (struct bp_location *loc) | |
10930 | { | |
10931 | struct bp_location *l; | |
10932 | htab_t htab = htab_create_alloc (13, htab_hash_string, | |
cc59ec59 MS |
10933 | (int (*) (const void *, |
10934 | const void *)) streq, | |
776592bf DE |
10935 | NULL, xcalloc, xfree); |
10936 | ||
10937 | for (l = loc; l != NULL; l = l->next) | |
10938 | { | |
10939 | const char **slot; | |
10940 | const char *name = l->function_name; | |
10941 | ||
10942 | /* Allow for some names to be NULL, ignore them. */ | |
10943 | if (name == NULL) | |
10944 | continue; | |
10945 | ||
10946 | slot = (const char **) htab_find_slot (htab, (const void *) name, | |
10947 | INSERT); | |
4a64f543 MS |
10948 | /* NOTE: We can assume slot != NULL here because xcalloc never |
10949 | returns NULL. */ | |
776592bf DE |
10950 | if (*slot != NULL) |
10951 | { | |
10952 | htab_delete (htab); | |
10953 | return 1; | |
10954 | } | |
10955 | *slot = name; | |
10956 | } | |
10957 | ||
10958 | htab_delete (htab); | |
10959 | return 0; | |
10960 | } | |
10961 | ||
0fb4aa4b PA |
10962 | /* When symbols change, it probably means the sources changed as well, |
10963 | and it might mean the static tracepoint markers are no longer at | |
10964 | the same address or line numbers they used to be at last we | |
10965 | checked. Losing your static tracepoints whenever you rebuild is | |
10966 | undesirable. This function tries to resync/rematch gdb static | |
10967 | tracepoints with the markers on the target, for static tracepoints | |
10968 | that have not been set by marker id. Static tracepoint that have | |
10969 | been set by marker id are reset by marker id in breakpoint_re_set. | |
10970 | The heuristic is: | |
10971 | ||
10972 | 1) For a tracepoint set at a specific address, look for a marker at | |
10973 | the old PC. If one is found there, assume to be the same marker. | |
10974 | If the name / string id of the marker found is different from the | |
10975 | previous known name, assume that means the user renamed the marker | |
10976 | in the sources, and output a warning. | |
10977 | ||
10978 | 2) For a tracepoint set at a given line number, look for a marker | |
10979 | at the new address of the old line number. If one is found there, | |
10980 | assume to be the same marker. If the name / string id of the | |
10981 | marker found is different from the previous known name, assume that | |
10982 | means the user renamed the marker in the sources, and output a | |
10983 | warning. | |
10984 | ||
10985 | 3) If a marker is no longer found at the same address or line, it | |
10986 | may mean the marker no longer exists. But it may also just mean | |
10987 | the code changed a bit. Maybe the user added a few lines of code | |
10988 | that made the marker move up or down (in line number terms). Ask | |
10989 | the target for info about the marker with the string id as we knew | |
10990 | it. If found, update line number and address in the matching | |
10991 | static tracepoint. This will get confused if there's more than one | |
10992 | marker with the same ID (possible in UST, although unadvised | |
10993 | precisely because it confuses tools). */ | |
10994 | ||
10995 | static struct symtab_and_line | |
10996 | update_static_tracepoint (struct breakpoint *b, struct symtab_and_line sal) | |
10997 | { | |
10998 | struct static_tracepoint_marker marker; | |
10999 | CORE_ADDR pc; | |
11000 | int i; | |
11001 | ||
11002 | pc = sal.pc; | |
11003 | if (sal.line) | |
11004 | find_line_pc (sal.symtab, sal.line, &pc); | |
11005 | ||
11006 | if (target_static_tracepoint_marker_at (pc, &marker)) | |
11007 | { | |
11008 | if (strcmp (b->static_trace_marker_id, marker.str_id) != 0) | |
11009 | warning (_("static tracepoint %d changed probed marker from %s to %s"), | |
11010 | b->number, | |
11011 | b->static_trace_marker_id, marker.str_id); | |
11012 | ||
11013 | xfree (b->static_trace_marker_id); | |
11014 | b->static_trace_marker_id = xstrdup (marker.str_id); | |
11015 | release_static_tracepoint_marker (&marker); | |
11016 | ||
11017 | return sal; | |
11018 | } | |
11019 | ||
11020 | /* Old marker wasn't found on target at lineno. Try looking it up | |
11021 | by string ID. */ | |
11022 | if (!sal.explicit_pc | |
11023 | && sal.line != 0 | |
11024 | && sal.symtab != NULL | |
11025 | && b->static_trace_marker_id != NULL) | |
11026 | { | |
11027 | VEC(static_tracepoint_marker_p) *markers; | |
11028 | ||
11029 | markers | |
11030 | = target_static_tracepoint_markers_by_strid (b->static_trace_marker_id); | |
11031 | ||
11032 | if (!VEC_empty(static_tracepoint_marker_p, markers)) | |
11033 | { | |
11034 | struct symtab_and_line sal; | |
11035 | struct symbol *sym; | |
11036 | struct static_tracepoint_marker *marker; | |
11037 | ||
11038 | marker = VEC_index (static_tracepoint_marker_p, markers, 0); | |
11039 | ||
11040 | xfree (b->static_trace_marker_id); | |
11041 | b->static_trace_marker_id = xstrdup (marker->str_id); | |
11042 | ||
11043 | warning (_("marker for static tracepoint %d (%s) not " | |
11044 | "found at previous line number"), | |
11045 | b->number, b->static_trace_marker_id); | |
11046 | ||
11047 | init_sal (&sal); | |
11048 | ||
11049 | sal.pc = marker->address; | |
11050 | ||
11051 | sal = find_pc_line (marker->address, 0); | |
11052 | sym = find_pc_sect_function (marker->address, NULL); | |
11053 | ui_out_text (uiout, "Now in "); | |
11054 | if (sym) | |
11055 | { | |
11056 | ui_out_field_string (uiout, "func", | |
11057 | SYMBOL_PRINT_NAME (sym)); | |
11058 | ui_out_text (uiout, " at "); | |
11059 | } | |
11060 | ui_out_field_string (uiout, "file", sal.symtab->filename); | |
11061 | ui_out_text (uiout, ":"); | |
11062 | ||
11063 | if (ui_out_is_mi_like_p (uiout)) | |
11064 | { | |
11065 | char *fullname = symtab_to_fullname (sal.symtab); | |
11066 | ||
11067 | if (fullname) | |
11068 | ui_out_field_string (uiout, "fullname", fullname); | |
11069 | } | |
11070 | ||
11071 | ui_out_field_int (uiout, "line", sal.line); | |
11072 | ui_out_text (uiout, "\n"); | |
11073 | ||
11074 | b->line_number = sal.line; | |
11075 | ||
11076 | xfree (b->source_file); | |
11077 | if (sym) | |
11078 | b->source_file = xstrdup (sal.symtab->filename); | |
11079 | else | |
11080 | b->source_file = NULL; | |
11081 | ||
11082 | xfree (b->addr_string); | |
11083 | b->addr_string = xstrprintf ("%s:%d", | |
11084 | sal.symtab->filename, b->line_number); | |
11085 | ||
11086 | /* Might be nice to check if function changed, and warn if | |
11087 | so. */ | |
11088 | ||
11089 | release_static_tracepoint_marker (marker); | |
11090 | } | |
11091 | } | |
11092 | return sal; | |
11093 | } | |
11094 | ||
8d3788bd VP |
11095 | /* Returns 1 iff locations A and B are sufficiently same that |
11096 | we don't need to report breakpoint as changed. */ | |
11097 | ||
11098 | static int | |
11099 | locations_are_equal (struct bp_location *a, struct bp_location *b) | |
11100 | { | |
11101 | while (a && b) | |
11102 | { | |
11103 | if (a->address != b->address) | |
11104 | return 0; | |
11105 | ||
11106 | if (a->shlib_disabled != b->shlib_disabled) | |
11107 | return 0; | |
11108 | ||
11109 | if (a->enabled != b->enabled) | |
11110 | return 0; | |
11111 | ||
11112 | a = a->next; | |
11113 | b = b->next; | |
11114 | } | |
11115 | ||
11116 | if ((a == NULL) != (b == NULL)) | |
11117 | return 0; | |
11118 | ||
11119 | return 1; | |
11120 | } | |
11121 | ||
f1310107 TJB |
11122 | /* Create new breakpoint locations for B (a hardware or software breakpoint) |
11123 | based on SALS and SALS_END. If SALS_END.NELTS is not zero, then B is | |
11124 | a ranged breakpoint. */ | |
11125 | ||
0e30163f | 11126 | void |
0d381245 | 11127 | update_breakpoint_locations (struct breakpoint *b, |
f1310107 TJB |
11128 | struct symtabs_and_lines sals, |
11129 | struct symtabs_and_lines sals_end) | |
fe3f5fa8 VP |
11130 | { |
11131 | int i; | |
0d381245 VP |
11132 | struct bp_location *existing_locations = b->loc; |
11133 | ||
f1310107 TJB |
11134 | /* Ranged breakpoints have only one start location and one end location. */ |
11135 | gdb_assert (sals_end.nelts == 0 || (sals.nelts == 1 && sals_end.nelts == 1)); | |
11136 | ||
4a64f543 MS |
11137 | /* If there's no new locations, and all existing locations are |
11138 | pending, don't do anything. This optimizes the common case where | |
11139 | all locations are in the same shared library, that was unloaded. | |
11140 | We'd like to retain the location, so that when the library is | |
11141 | loaded again, we don't loose the enabled/disabled status of the | |
11142 | individual locations. */ | |
0d381245 | 11143 | if (all_locations_are_pending (existing_locations) && sals.nelts == 0) |
fe3f5fa8 VP |
11144 | return; |
11145 | ||
fe3f5fa8 VP |
11146 | b->loc = NULL; |
11147 | ||
0d381245 | 11148 | for (i = 0; i < sals.nelts; ++i) |
fe3f5fa8 | 11149 | { |
0d381245 | 11150 | struct bp_location *new_loc = |
39d61571 | 11151 | add_location_to_breakpoint (b, &(sals.sals[i])); |
fe3f5fa8 | 11152 | |
0d381245 VP |
11153 | /* Reparse conditions, they might contain references to the |
11154 | old symtab. */ | |
11155 | if (b->cond_string != NULL) | |
11156 | { | |
f1310107 | 11157 | char *s; |
0d381245 | 11158 | struct gdb_exception e; |
fe3f5fa8 | 11159 | |
0d381245 VP |
11160 | s = b->cond_string; |
11161 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11162 | { | |
11163 | new_loc->cond = parse_exp_1 (&s, block_for_pc (sals.sals[i].pc), | |
11164 | 0); | |
11165 | } | |
11166 | if (e.reason < 0) | |
11167 | { | |
3e43a32a MS |
11168 | warning (_("failed to reevaluate condition " |
11169 | "for breakpoint %d: %s"), | |
0d381245 VP |
11170 | b->number, e.message); |
11171 | new_loc->enabled = 0; | |
11172 | } | |
11173 | } | |
fe3f5fa8 | 11174 | |
0d381245 VP |
11175 | if (b->source_file != NULL) |
11176 | xfree (b->source_file); | |
11177 | if (sals.sals[i].symtab == NULL) | |
11178 | b->source_file = NULL; | |
11179 | else | |
1b36a34b | 11180 | b->source_file = xstrdup (sals.sals[i].symtab->filename); |
fe3f5fa8 | 11181 | |
0d381245 VP |
11182 | if (b->line_number == 0) |
11183 | b->line_number = sals.sals[i].line; | |
f1310107 TJB |
11184 | |
11185 | if (sals_end.nelts) | |
11186 | { | |
11187 | CORE_ADDR end = find_breakpoint_range_end (sals_end.sals[0]); | |
11188 | ||
11189 | new_loc->length = end - sals.sals[0].pc + 1; | |
11190 | } | |
0d381245 | 11191 | } |
fe3f5fa8 | 11192 | |
514f746b AR |
11193 | /* Update locations of permanent breakpoints. */ |
11194 | if (b->enable_state == bp_permanent) | |
11195 | make_breakpoint_permanent (b); | |
11196 | ||
4a64f543 MS |
11197 | /* If possible, carry over 'disable' status from existing |
11198 | breakpoints. */ | |
0d381245 VP |
11199 | { |
11200 | struct bp_location *e = existing_locations; | |
776592bf DE |
11201 | /* If there are multiple breakpoints with the same function name, |
11202 | e.g. for inline functions, comparing function names won't work. | |
11203 | Instead compare pc addresses; this is just a heuristic as things | |
11204 | may have moved, but in practice it gives the correct answer | |
11205 | often enough until a better solution is found. */ | |
11206 | int have_ambiguous_names = ambiguous_names_p (b->loc); | |
11207 | ||
0d381245 VP |
11208 | for (; e; e = e->next) |
11209 | { | |
11210 | if (!e->enabled && e->function_name) | |
11211 | { | |
11212 | struct bp_location *l = b->loc; | |
776592bf DE |
11213 | if (have_ambiguous_names) |
11214 | { | |
11215 | for (; l; l = l->next) | |
f1310107 | 11216 | if (breakpoint_locations_match (e, l)) |
776592bf DE |
11217 | { |
11218 | l->enabled = 0; | |
11219 | break; | |
11220 | } | |
11221 | } | |
11222 | else | |
11223 | { | |
11224 | for (; l; l = l->next) | |
11225 | if (l->function_name | |
11226 | && strcmp (e->function_name, l->function_name) == 0) | |
11227 | { | |
11228 | l->enabled = 0; | |
11229 | break; | |
11230 | } | |
11231 | } | |
0d381245 VP |
11232 | } |
11233 | } | |
11234 | } | |
fe3f5fa8 | 11235 | |
8d3788bd VP |
11236 | if (!locations_are_equal (existing_locations, b->loc)) |
11237 | observer_notify_breakpoint_modified (b); | |
11238 | ||
b60e7edf | 11239 | update_global_location_list (1); |
fe3f5fa8 VP |
11240 | } |
11241 | ||
ef23e705 TJB |
11242 | /* Find the SaL locations corresponding to the given ADDR_STRING. |
11243 | On return, FOUND will be 1 if any SaL was found, zero otherwise. */ | |
11244 | ||
11245 | static struct symtabs_and_lines | |
11246 | addr_string_to_sals (struct breakpoint *b, char *addr_string, int *found) | |
11247 | { | |
11248 | char *s; | |
58438ac1 | 11249 | int marker_spec; |
02d20e4a | 11250 | struct symtabs_and_lines sals = {0}; |
ef23e705 TJB |
11251 | struct gdb_exception e; |
11252 | ||
11253 | s = addr_string; | |
11254 | marker_spec = b->type == bp_static_tracepoint && is_marker_spec (s); | |
11255 | ||
11256 | TRY_CATCH (e, RETURN_MASK_ERROR) | |
11257 | { | |
11258 | if (marker_spec) | |
11259 | { | |
11260 | sals = decode_static_tracepoint_spec (&s); | |
11261 | if (sals.nelts > b->static_trace_marker_id_idx) | |
11262 | { | |
11263 | sals.sals[0] = sals.sals[b->static_trace_marker_id_idx]; | |
11264 | sals.nelts = 1; | |
11265 | } | |
11266 | else | |
11267 | error (_("marker %s not found"), b->static_trace_marker_id); | |
11268 | } | |
11269 | else | |
58438ac1 | 11270 | sals = decode_line_1 (&s, 1, (struct symtab *) NULL, 0, NULL); |
ef23e705 TJB |
11271 | } |
11272 | if (e.reason < 0) | |
11273 | { | |
11274 | int not_found_and_ok = 0; | |
11275 | /* For pending breakpoints, it's expected that parsing will | |
11276 | fail until the right shared library is loaded. User has | |
11277 | already told to create pending breakpoints and don't need | |
11278 | extra messages. If breakpoint is in bp_shlib_disabled | |
11279 | state, then user already saw the message about that | |
11280 | breakpoint being disabled, and don't want to see more | |
11281 | errors. */ | |
58438ac1 | 11282 | if (e.error == NOT_FOUND_ERROR |
ef23e705 TJB |
11283 | && (b->condition_not_parsed |
11284 | || (b->loc && b->loc->shlib_disabled) | |
11285 | || b->enable_state == bp_disabled)) | |
11286 | not_found_and_ok = 1; | |
11287 | ||
11288 | if (!not_found_and_ok) | |
11289 | { | |
11290 | /* We surely don't want to warn about the same breakpoint | |
11291 | 10 times. One solution, implemented here, is disable | |
11292 | the breakpoint on error. Another solution would be to | |
11293 | have separate 'warning emitted' flag. Since this | |
11294 | happens only when a binary has changed, I don't know | |
11295 | which approach is better. */ | |
11296 | b->enable_state = bp_disabled; | |
11297 | throw_exception (e); | |
11298 | } | |
11299 | } | |
11300 | ||
58438ac1 | 11301 | if (e.reason == 0 || e.error != NOT_FOUND_ERROR) |
ef23e705 TJB |
11302 | { |
11303 | gdb_assert (sals.nelts == 1); | |
11304 | ||
11305 | resolve_sal_pc (&sals.sals[0]); | |
11306 | if (b->condition_not_parsed && s && s[0]) | |
11307 | { | |
11308 | char *cond_string = 0; | |
11309 | int thread = -1; | |
11310 | int task = 0; | |
11311 | ||
11312 | find_condition_and_thread (s, sals.sals[0].pc, | |
11313 | &cond_string, &thread, &task); | |
11314 | if (cond_string) | |
11315 | b->cond_string = cond_string; | |
11316 | b->thread = thread; | |
11317 | b->task = task; | |
11318 | b->condition_not_parsed = 0; | |
11319 | } | |
11320 | ||
11321 | if (b->type == bp_static_tracepoint && !marker_spec) | |
11322 | sals.sals[0] = update_static_tracepoint (b, sals.sals[0]); | |
ef23e705 | 11323 | |
58438ac1 TT |
11324 | *found = 1; |
11325 | } | |
11326 | else | |
11327 | *found = 0; | |
ef23e705 TJB |
11328 | |
11329 | return sals; | |
11330 | } | |
11331 | ||
11332 | /* Reevaluate a hardware or software breakpoint and recreate its locations. | |
11333 | This is necessary after symbols are read (e.g., an executable or DSO | |
11334 | was loaded, or the inferior just started). */ | |
11335 | ||
11336 | static void | |
11337 | re_set_breakpoint (struct breakpoint *b) | |
11338 | { | |
11339 | int found; | |
f1310107 | 11340 | struct symtabs_and_lines sals, sals_end; |
ef23e705 | 11341 | struct symtabs_and_lines expanded = {0}; |
f1310107 | 11342 | struct symtabs_and_lines expanded_end = {0}; |
ef23e705 TJB |
11343 | struct cleanup *cleanups = make_cleanup (null_cleanup, NULL); |
11344 | ||
11345 | input_radix = b->input_radix; | |
11346 | save_current_space_and_thread (); | |
11347 | switch_to_program_space_and_thread (b->pspace); | |
11348 | set_language (b->language); | |
11349 | ||
11350 | sals = addr_string_to_sals (b, b->addr_string, &found); | |
11351 | if (found) | |
11352 | { | |
11353 | make_cleanup (xfree, sals.sals); | |
11354 | expanded = expand_line_sal_maybe (sals.sals[0]); | |
11355 | } | |
11356 | ||
f1310107 TJB |
11357 | if (b->addr_string_range_end) |
11358 | { | |
11359 | sals_end = addr_string_to_sals (b, b->addr_string_range_end, &found); | |
11360 | if (found) | |
11361 | { | |
11362 | make_cleanup (xfree, sals_end.sals); | |
11363 | expanded_end = expand_line_sal_maybe (sals_end.sals[0]); | |
11364 | } | |
11365 | } | |
11366 | ||
11367 | update_breakpoint_locations (b, expanded, expanded_end); | |
ef23e705 TJB |
11368 | do_cleanups (cleanups); |
11369 | } | |
11370 | ||
c906108c SS |
11371 | /* Reset a breakpoint given it's struct breakpoint * BINT. |
11372 | The value we return ends up being the return value from catch_errors. | |
11373 | Unused in this case. */ | |
11374 | ||
11375 | static int | |
4efb68b1 | 11376 | breakpoint_re_set_one (void *bint) |
c906108c | 11377 | { |
4a64f543 | 11378 | /* Get past catch_errs. */ |
53a5351d | 11379 | struct breakpoint *b = (struct breakpoint *) bint; |
c906108c SS |
11380 | |
11381 | switch (b->type) | |
11382 | { | |
11383 | case bp_none: | |
8a3fe4f8 | 11384 | warning (_("attempted to reset apparently deleted breakpoint #%d?"), |
53a5351d | 11385 | b->number); |
c906108c SS |
11386 | return 0; |
11387 | case bp_breakpoint: | |
11388 | case bp_hardware_breakpoint: | |
1042e4c0 | 11389 | case bp_tracepoint: |
7a697b8d | 11390 | case bp_fast_tracepoint: |
0fb4aa4b | 11391 | case bp_static_tracepoint: |
0e30163f | 11392 | case bp_gnu_ifunc_resolver: |
8bea4e01 UW |
11393 | /* Do not attempt to re-set breakpoints disabled during startup. */ |
11394 | if (b->enable_state == bp_startup_disabled) | |
11395 | return 0; | |
11396 | ||
c906108c SS |
11397 | if (b->addr_string == NULL) |
11398 | { | |
4a64f543 | 11399 | /* Anything without a string can't be re-set. */ |
c906108c SS |
11400 | delete_breakpoint (b); |
11401 | return 0; | |
11402 | } | |
c906108c | 11403 | |
ef23e705 | 11404 | re_set_breakpoint (b); |
c906108c SS |
11405 | break; |
11406 | ||
11407 | case bp_watchpoint: | |
11408 | case bp_hardware_watchpoint: | |
11409 | case bp_read_watchpoint: | |
11410 | case bp_access_watchpoint: | |
4a64f543 MS |
11411 | /* Watchpoint can be either on expression using entirely global |
11412 | variables, or it can be on local variables. | |
11413 | ||
11414 | Watchpoints of the first kind are never auto-deleted, and | |
11415 | even persist across program restarts. Since they can use | |
11416 | variables from shared libraries, we need to reparse | |
11417 | expression as libraries are loaded and unloaded. | |
11418 | ||
11419 | Watchpoints on local variables can also change meaning as | |
11420 | result of solib event. For example, if a watchpoint uses | |
11421 | both a local and a global variables in expression, it's a | |
11422 | local watchpoint, but unloading of a shared library will make | |
11423 | the expression invalid. This is not a very common use case, | |
11424 | but we still re-evaluate expression, to avoid surprises to | |
11425 | the user. | |
0b3de036 VP |
11426 | |
11427 | Note that for local watchpoints, we re-evaluate it only if | |
11428 | watchpoints frame id is still valid. If it's not, it means | |
4a64f543 MS |
11429 | the watchpoint is out of scope and will be deleted soon. In |
11430 | fact, I'm not sure we'll ever be called in this case. | |
0b3de036 VP |
11431 | |
11432 | If a local watchpoint's frame id is still valid, then | |
4a64f543 | 11433 | b->exp_valid_block is likewise valid, and we can safely use it. |
0b3de036 VP |
11434 | |
11435 | Don't do anything about disabled watchpoints, since they will | |
11436 | be reevaluated again when enabled. */ | |
a5606eee | 11437 | update_watchpoint (b, 1 /* reparse */); |
c906108c | 11438 | break; |
c5aa993b JM |
11439 | /* We needn't really do anything to reset these, since the mask |
11440 | that requests them is unaffected by e.g., new libraries being | |
4a64f543 | 11441 | loaded. */ |
ce78b96d | 11442 | case bp_catchpoint: |
c906108c | 11443 | break; |
c5aa993b | 11444 | |
c906108c | 11445 | default: |
a3f17187 | 11446 | printf_filtered (_("Deleting unknown breakpoint type %d\n"), b->type); |
c906108c | 11447 | /* fall through */ |
0fd8e87f UW |
11448 | /* Delete overlay event and longjmp master breakpoints; they will be |
11449 | reset later by breakpoint_re_set. */ | |
1900040c | 11450 | case bp_overlay_event: |
0fd8e87f | 11451 | case bp_longjmp_master: |
aa7d318d | 11452 | case bp_std_terminate_master: |
186c406b | 11453 | case bp_exception_master: |
c906108c SS |
11454 | delete_breakpoint (b); |
11455 | break; | |
11456 | ||
c5aa993b JM |
11457 | /* This breakpoint is special, it's set up when the inferior |
11458 | starts and we really don't want to touch it. */ | |
c906108c SS |
11459 | case bp_shlib_event: |
11460 | ||
c4093a6a JM |
11461 | /* Like bp_shlib_event, this breakpoint type is special. |
11462 | Once it is set up, we do not want to touch it. */ | |
11463 | case bp_thread_event: | |
11464 | ||
4a64f543 MS |
11465 | /* Keep temporary breakpoints, which can be encountered when we |
11466 | step over a dlopen call and SOLIB_ADD is resetting the | |
11467 | breakpoints. Otherwise these should have been blown away via | |
11468 | the cleanup chain or by breakpoint_init_inferior when we | |
11469 | rerun the executable. */ | |
c906108c SS |
11470 | case bp_until: |
11471 | case bp_finish: | |
11472 | case bp_watchpoint_scope: | |
11473 | case bp_call_dummy: | |
aa7d318d | 11474 | case bp_std_terminate: |
c906108c | 11475 | case bp_step_resume: |
2c03e5be | 11476 | case bp_hp_step_resume: |
611c83ae PA |
11477 | case bp_longjmp: |
11478 | case bp_longjmp_resume: | |
186c406b TT |
11479 | case bp_exception: |
11480 | case bp_exception_resume: | |
4efc6507 | 11481 | case bp_jit_event: |
0e30163f | 11482 | case bp_gnu_ifunc_resolver_return: |
c906108c SS |
11483 | break; |
11484 | } | |
11485 | ||
11486 | return 0; | |
11487 | } | |
11488 | ||
69de3c6a | 11489 | /* Re-set all breakpoints after symbols have been re-loaded. */ |
c906108c | 11490 | void |
69de3c6a | 11491 | breakpoint_re_set (void) |
c906108c | 11492 | { |
35df4500 | 11493 | struct breakpoint *b, *b_tmp; |
c906108c SS |
11494 | enum language save_language; |
11495 | int save_input_radix; | |
6c95b8df | 11496 | struct cleanup *old_chain; |
c5aa993b | 11497 | |
c906108c SS |
11498 | save_language = current_language->la_language; |
11499 | save_input_radix = input_radix; | |
6c95b8df PA |
11500 | old_chain = save_current_program_space (); |
11501 | ||
35df4500 | 11502 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
c5aa993b | 11503 | { |
4a64f543 | 11504 | /* Format possible error msg. */ |
fe3f5fa8 | 11505 | char *message = xstrprintf ("Error in re-setting breakpoint %d: ", |
9ebf4acf AC |
11506 | b->number); |
11507 | struct cleanup *cleanups = make_cleanup (xfree, message); | |
c5aa993b | 11508 | catch_errors (breakpoint_re_set_one, b, message, RETURN_MASK_ALL); |
9ebf4acf | 11509 | do_cleanups (cleanups); |
c5aa993b | 11510 | } |
c906108c SS |
11511 | set_language (save_language); |
11512 | input_radix = save_input_radix; | |
e62c965a | 11513 | |
0756c555 | 11514 | jit_breakpoint_re_set (); |
4efc6507 | 11515 | |
6c95b8df PA |
11516 | do_cleanups (old_chain); |
11517 | ||
af02033e PP |
11518 | create_overlay_event_breakpoint (); |
11519 | create_longjmp_master_breakpoint (); | |
11520 | create_std_terminate_master_breakpoint (); | |
186c406b | 11521 | create_exception_master_breakpoint (); |
c906108c SS |
11522 | } |
11523 | \f | |
c906108c SS |
11524 | /* Reset the thread number of this breakpoint: |
11525 | ||
11526 | - If the breakpoint is for all threads, leave it as-is. | |
4a64f543 | 11527 | - Else, reset it to the current thread for inferior_ptid. */ |
c906108c | 11528 | void |
fba45db2 | 11529 | breakpoint_re_set_thread (struct breakpoint *b) |
c906108c SS |
11530 | { |
11531 | if (b->thread != -1) | |
11532 | { | |
39f77062 KB |
11533 | if (in_thread_list (inferior_ptid)) |
11534 | b->thread = pid_to_thread_id (inferior_ptid); | |
6c95b8df PA |
11535 | |
11536 | /* We're being called after following a fork. The new fork is | |
11537 | selected as current, and unless this was a vfork will have a | |
11538 | different program space from the original thread. Reset that | |
11539 | as well. */ | |
11540 | b->loc->pspace = current_program_space; | |
c906108c SS |
11541 | } |
11542 | } | |
11543 | ||
03ac34d5 MS |
11544 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
11545 | If from_tty is nonzero, it prints a message to that effect, | |
11546 | which ends with a period (no newline). */ | |
11547 | ||
c906108c | 11548 | void |
fba45db2 | 11549 | set_ignore_count (int bptnum, int count, int from_tty) |
c906108c | 11550 | { |
52f0bd74 | 11551 | struct breakpoint *b; |
c906108c SS |
11552 | |
11553 | if (count < 0) | |
11554 | count = 0; | |
11555 | ||
11556 | ALL_BREAKPOINTS (b) | |
11557 | if (b->number == bptnum) | |
c5aa993b | 11558 | { |
d77f58be SS |
11559 | if (is_tracepoint (b)) |
11560 | { | |
11561 | if (from_tty && count != 0) | |
11562 | printf_filtered (_("Ignore count ignored for tracepoint %d."), | |
11563 | bptnum); | |
11564 | return; | |
11565 | } | |
11566 | ||
c5aa993b | 11567 | b->ignore_count = count; |
221ea385 KS |
11568 | if (from_tty) |
11569 | { | |
11570 | if (count == 0) | |
3e43a32a MS |
11571 | printf_filtered (_("Will stop next time " |
11572 | "breakpoint %d is reached."), | |
221ea385 KS |
11573 | bptnum); |
11574 | else if (count == 1) | |
a3f17187 | 11575 | printf_filtered (_("Will ignore next crossing of breakpoint %d."), |
221ea385 KS |
11576 | bptnum); |
11577 | else | |
3e43a32a MS |
11578 | printf_filtered (_("Will ignore next %d " |
11579 | "crossings of breakpoint %d."), | |
221ea385 KS |
11580 | count, bptnum); |
11581 | } | |
c5aa993b | 11582 | breakpoints_changed (); |
8d3788bd | 11583 | observer_notify_breakpoint_modified (b); |
c5aa993b JM |
11584 | return; |
11585 | } | |
c906108c | 11586 | |
8a3fe4f8 | 11587 | error (_("No breakpoint number %d."), bptnum); |
c906108c SS |
11588 | } |
11589 | ||
c906108c SS |
11590 | /* Command to set ignore-count of breakpoint N to COUNT. */ |
11591 | ||
11592 | static void | |
fba45db2 | 11593 | ignore_command (char *args, int from_tty) |
c906108c SS |
11594 | { |
11595 | char *p = args; | |
52f0bd74 | 11596 | int num; |
c906108c SS |
11597 | |
11598 | if (p == 0) | |
e2e0b3e5 | 11599 | error_no_arg (_("a breakpoint number")); |
c5aa993b | 11600 | |
c906108c | 11601 | num = get_number (&p); |
5c44784c | 11602 | if (num == 0) |
8a3fe4f8 | 11603 | error (_("bad breakpoint number: '%s'"), args); |
c906108c | 11604 | if (*p == 0) |
8a3fe4f8 | 11605 | error (_("Second argument (specified ignore-count) is missing.")); |
c906108c SS |
11606 | |
11607 | set_ignore_count (num, | |
11608 | longest_to_int (value_as_long (parse_and_eval (p))), | |
11609 | from_tty); | |
221ea385 KS |
11610 | if (from_tty) |
11611 | printf_filtered ("\n"); | |
c906108c SS |
11612 | } |
11613 | \f | |
11614 | /* Call FUNCTION on each of the breakpoints | |
11615 | whose numbers are given in ARGS. */ | |
11616 | ||
11617 | static void | |
95a42b64 TT |
11618 | map_breakpoint_numbers (char *args, void (*function) (struct breakpoint *, |
11619 | void *), | |
11620 | void *data) | |
c906108c | 11621 | { |
52f0bd74 AC |
11622 | int num; |
11623 | struct breakpoint *b, *tmp; | |
11cf8741 | 11624 | int match; |
197f0a60 | 11625 | struct get_number_or_range_state state; |
c906108c | 11626 | |
197f0a60 | 11627 | if (args == 0) |
e2e0b3e5 | 11628 | error_no_arg (_("one or more breakpoint numbers")); |
c906108c | 11629 | |
197f0a60 TT |
11630 | init_number_or_range (&state, args); |
11631 | ||
11632 | while (!state.finished) | |
c906108c | 11633 | { |
197f0a60 TT |
11634 | char *p = state.string; |
11635 | ||
11cf8741 | 11636 | match = 0; |
c5aa993b | 11637 | |
197f0a60 | 11638 | num = get_number_or_range (&state); |
5c44784c | 11639 | if (num == 0) |
c5aa993b | 11640 | { |
8a3fe4f8 | 11641 | warning (_("bad breakpoint number at or near '%s'"), p); |
5c44784c JM |
11642 | } |
11643 | else | |
11644 | { | |
11645 | ALL_BREAKPOINTS_SAFE (b, tmp) | |
11646 | if (b->number == num) | |
11647 | { | |
11cf8741 | 11648 | match = 1; |
cdac0397 | 11649 | function (b, data); |
11cf8741 | 11650 | break; |
5c44784c | 11651 | } |
11cf8741 | 11652 | if (match == 0) |
a3f17187 | 11653 | printf_unfiltered (_("No breakpoint number %d.\n"), num); |
c5aa993b | 11654 | } |
c906108c SS |
11655 | } |
11656 | } | |
11657 | ||
0d381245 VP |
11658 | static struct bp_location * |
11659 | find_location_by_number (char *number) | |
11660 | { | |
11661 | char *dot = strchr (number, '.'); | |
11662 | char *p1; | |
11663 | int bp_num; | |
11664 | int loc_num; | |
11665 | struct breakpoint *b; | |
11666 | struct bp_location *loc; | |
11667 | ||
11668 | *dot = '\0'; | |
11669 | ||
11670 | p1 = number; | |
197f0a60 | 11671 | bp_num = get_number (&p1); |
0d381245 VP |
11672 | if (bp_num == 0) |
11673 | error (_("Bad breakpoint number '%s'"), number); | |
11674 | ||
11675 | ALL_BREAKPOINTS (b) | |
11676 | if (b->number == bp_num) | |
11677 | { | |
11678 | break; | |
11679 | } | |
11680 | ||
11681 | if (!b || b->number != bp_num) | |
11682 | error (_("Bad breakpoint number '%s'"), number); | |
11683 | ||
11684 | p1 = dot+1; | |
197f0a60 | 11685 | loc_num = get_number (&p1); |
0d381245 VP |
11686 | if (loc_num == 0) |
11687 | error (_("Bad breakpoint location number '%s'"), number); | |
11688 | ||
11689 | --loc_num; | |
11690 | loc = b->loc; | |
11691 | for (;loc_num && loc; --loc_num, loc = loc->next) | |
11692 | ; | |
11693 | if (!loc) | |
11694 | error (_("Bad breakpoint location number '%s'"), dot+1); | |
11695 | ||
11696 | return loc; | |
11697 | } | |
11698 | ||
11699 | ||
1900040c MS |
11700 | /* Set ignore-count of breakpoint number BPTNUM to COUNT. |
11701 | If from_tty is nonzero, it prints a message to that effect, | |
11702 | which ends with a period (no newline). */ | |
11703 | ||
c906108c | 11704 | void |
fba45db2 | 11705 | disable_breakpoint (struct breakpoint *bpt) |
c906108c SS |
11706 | { |
11707 | /* Never disable a watchpoint scope breakpoint; we want to | |
11708 | hit them when we leave scope so we can delete both the | |
11709 | watchpoint and its scope breakpoint at that time. */ | |
11710 | if (bpt->type == bp_watchpoint_scope) | |
11711 | return; | |
11712 | ||
c2c6d25f | 11713 | /* You can't disable permanent breakpoints. */ |
b5de0fa7 | 11714 | if (bpt->enable_state == bp_permanent) |
c2c6d25f JM |
11715 | return; |
11716 | ||
b5de0fa7 | 11717 | bpt->enable_state = bp_disabled; |
c906108c | 11718 | |
d248b706 KY |
11719 | if (target_supports_enable_disable_tracepoint () |
11720 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
11721 | { | |
11722 | struct bp_location *location; | |
11723 | ||
11724 | for (location = bpt->loc; location; location = location->next) | |
11725 | target_disable_tracepoint (location); | |
11726 | } | |
11727 | ||
b60e7edf | 11728 | update_global_location_list (0); |
c906108c | 11729 | |
8d3788bd | 11730 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
11731 | } |
11732 | ||
51be5b68 PA |
11733 | /* A callback for iterate_over_related_breakpoints. */ |
11734 | ||
11735 | static void | |
11736 | do_disable_breakpoint (struct breakpoint *b, void *ignore) | |
11737 | { | |
11738 | disable_breakpoint (b); | |
11739 | } | |
11740 | ||
95a42b64 TT |
11741 | /* A callback for map_breakpoint_numbers that calls |
11742 | disable_breakpoint. */ | |
11743 | ||
11744 | static void | |
11745 | do_map_disable_breakpoint (struct breakpoint *b, void *ignore) | |
11746 | { | |
51be5b68 | 11747 | iterate_over_related_breakpoints (b, do_disable_breakpoint, NULL); |
95a42b64 TT |
11748 | } |
11749 | ||
c906108c | 11750 | static void |
fba45db2 | 11751 | disable_command (char *args, int from_tty) |
c906108c | 11752 | { |
c906108c | 11753 | if (args == 0) |
46c6471b PA |
11754 | { |
11755 | struct breakpoint *bpt; | |
11756 | ||
11757 | ALL_BREAKPOINTS (bpt) | |
11758 | if (user_breakpoint_p (bpt)) | |
11759 | disable_breakpoint (bpt); | |
11760 | } | |
0d381245 VP |
11761 | else if (strchr (args, '.')) |
11762 | { | |
11763 | struct bp_location *loc = find_location_by_number (args); | |
11764 | if (loc) | |
d248b706 KY |
11765 | { |
11766 | loc->enabled = 0; | |
11767 | if (target_supports_enable_disable_tracepoint () | |
11768 | && current_trace_status ()->running && loc->owner | |
11769 | && is_tracepoint (loc->owner)) | |
11770 | target_disable_tracepoint (loc); | |
11771 | } | |
b60e7edf | 11772 | update_global_location_list (0); |
0d381245 | 11773 | } |
c906108c | 11774 | else |
95a42b64 | 11775 | map_breakpoint_numbers (args, do_map_disable_breakpoint, NULL); |
c906108c SS |
11776 | } |
11777 | ||
11778 | static void | |
51be5b68 | 11779 | enable_breakpoint_disp (struct breakpoint *bpt, enum bpdisp disposition) |
c906108c | 11780 | { |
afe38095 | 11781 | int target_resources_ok; |
c906108c SS |
11782 | |
11783 | if (bpt->type == bp_hardware_breakpoint) | |
11784 | { | |
11785 | int i; | |
c5aa993b | 11786 | i = hw_breakpoint_used_count (); |
53a5351d | 11787 | target_resources_ok = |
d92524f1 | 11788 | target_can_use_hardware_watchpoint (bp_hardware_breakpoint, |
53a5351d | 11789 | i + 1, 0); |
c906108c | 11790 | if (target_resources_ok == 0) |
8a3fe4f8 | 11791 | error (_("No hardware breakpoint support in the target.")); |
c906108c | 11792 | else if (target_resources_ok < 0) |
8a3fe4f8 | 11793 | error (_("Hardware breakpoints used exceeds limit.")); |
c906108c SS |
11794 | } |
11795 | ||
cc60f2e3 | 11796 | if (is_watchpoint (bpt)) |
c906108c | 11797 | { |
d07205c2 JK |
11798 | /* Initialize it just to avoid a GCC false warning. */ |
11799 | enum enable_state orig_enable_state = 0; | |
dde02812 ES |
11800 | struct gdb_exception e; |
11801 | ||
11802 | TRY_CATCH (e, RETURN_MASK_ALL) | |
c906108c | 11803 | { |
1e718ff1 TJB |
11804 | orig_enable_state = bpt->enable_state; |
11805 | bpt->enable_state = bp_enabled; | |
dde02812 | 11806 | update_watchpoint (bpt, 1 /* reparse */); |
c906108c | 11807 | } |
dde02812 | 11808 | if (e.reason < 0) |
c5aa993b | 11809 | { |
1e718ff1 | 11810 | bpt->enable_state = orig_enable_state; |
dde02812 ES |
11811 | exception_fprintf (gdb_stderr, e, _("Cannot enable watchpoint %d: "), |
11812 | bpt->number); | |
11813 | return; | |
c5aa993b | 11814 | } |
c906108c | 11815 | } |
0101ce28 | 11816 | |
b4c291bb KH |
11817 | if (bpt->enable_state != bp_permanent) |
11818 | bpt->enable_state = bp_enabled; | |
d248b706 KY |
11819 | |
11820 | if (target_supports_enable_disable_tracepoint () | |
11821 | && current_trace_status ()->running && is_tracepoint (bpt)) | |
11822 | { | |
11823 | struct bp_location *location; | |
11824 | ||
11825 | for (location = bpt->loc; location; location = location->next) | |
11826 | target_enable_tracepoint (location); | |
11827 | } | |
11828 | ||
b4c291bb | 11829 | bpt->disposition = disposition; |
b60e7edf | 11830 | update_global_location_list (1); |
b4c291bb KH |
11831 | breakpoints_changed (); |
11832 | ||
8d3788bd | 11833 | observer_notify_breakpoint_modified (bpt); |
c906108c SS |
11834 | } |
11835 | ||
fe3f5fa8 | 11836 | |
c906108c | 11837 | void |
fba45db2 | 11838 | enable_breakpoint (struct breakpoint *bpt) |
c906108c | 11839 | { |
51be5b68 PA |
11840 | enable_breakpoint_disp (bpt, bpt->disposition); |
11841 | } | |
11842 | ||
11843 | static void | |
11844 | do_enable_breakpoint (struct breakpoint *bpt, void *arg) | |
11845 | { | |
11846 | enable_breakpoint (bpt); | |
c906108c SS |
11847 | } |
11848 | ||
95a42b64 TT |
11849 | /* A callback for map_breakpoint_numbers that calls |
11850 | enable_breakpoint. */ | |
11851 | ||
11852 | static void | |
11853 | do_map_enable_breakpoint (struct breakpoint *b, void *ignore) | |
11854 | { | |
51be5b68 | 11855 | iterate_over_related_breakpoints (b, do_enable_breakpoint, NULL); |
95a42b64 TT |
11856 | } |
11857 | ||
c906108c SS |
11858 | /* The enable command enables the specified breakpoints (or all defined |
11859 | breakpoints) so they once again become (or continue to be) effective | |
1272ad14 | 11860 | in stopping the inferior. */ |
c906108c | 11861 | |
c906108c | 11862 | static void |
fba45db2 | 11863 | enable_command (char *args, int from_tty) |
c906108c | 11864 | { |
c906108c | 11865 | if (args == 0) |
46c6471b PA |
11866 | { |
11867 | struct breakpoint *bpt; | |
11868 | ||
11869 | ALL_BREAKPOINTS (bpt) | |
11870 | if (user_breakpoint_p (bpt)) | |
11871 | enable_breakpoint (bpt); | |
11872 | } | |
0d381245 VP |
11873 | else if (strchr (args, '.')) |
11874 | { | |
11875 | struct bp_location *loc = find_location_by_number (args); | |
11876 | if (loc) | |
d248b706 KY |
11877 | { |
11878 | loc->enabled = 1; | |
11879 | if (target_supports_enable_disable_tracepoint () | |
11880 | && current_trace_status ()->running && loc->owner | |
11881 | && is_tracepoint (loc->owner)) | |
11882 | target_enable_tracepoint (loc); | |
11883 | } | |
b60e7edf | 11884 | update_global_location_list (1); |
0d381245 | 11885 | } |
c906108c | 11886 | else |
95a42b64 | 11887 | map_breakpoint_numbers (args, do_map_enable_breakpoint, NULL); |
c906108c SS |
11888 | } |
11889 | ||
11890 | static void | |
51be5b68 PA |
11891 | do_enable_breakpoint_disp (struct breakpoint *bpt, void *arg) |
11892 | { | |
11893 | enum bpdisp disp = *(enum bpdisp *) arg; | |
11894 | ||
11895 | enable_breakpoint_disp (bpt, disp); | |
11896 | } | |
11897 | ||
11898 | static void | |
11899 | do_map_enable_once_breakpoint (struct breakpoint *bpt, void *ignore) | |
c906108c | 11900 | { |
51be5b68 PA |
11901 | enum bpdisp disp = disp_disable; |
11902 | ||
11903 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
11904 | } |
11905 | ||
c906108c | 11906 | static void |
fba45db2 | 11907 | enable_once_command (char *args, int from_tty) |
c906108c | 11908 | { |
51be5b68 | 11909 | map_breakpoint_numbers (args, do_map_enable_once_breakpoint, NULL); |
c906108c SS |
11910 | } |
11911 | ||
11912 | static void | |
51be5b68 | 11913 | do_map_enable_delete_breakpoint (struct breakpoint *bpt, void *ignore) |
c906108c | 11914 | { |
51be5b68 PA |
11915 | enum bpdisp disp = disp_del; |
11916 | ||
11917 | iterate_over_related_breakpoints (bpt, do_enable_breakpoint_disp, &disp); | |
c906108c SS |
11918 | } |
11919 | ||
c906108c | 11920 | static void |
fba45db2 | 11921 | enable_delete_command (char *args, int from_tty) |
c906108c | 11922 | { |
51be5b68 | 11923 | map_breakpoint_numbers (args, do_map_enable_delete_breakpoint, NULL); |
c906108c SS |
11924 | } |
11925 | \f | |
fa8d40ab JJ |
11926 | static void |
11927 | set_breakpoint_cmd (char *args, int from_tty) | |
11928 | { | |
11929 | } | |
11930 | ||
11931 | static void | |
11932 | show_breakpoint_cmd (char *args, int from_tty) | |
11933 | { | |
11934 | } | |
11935 | ||
1f3b5d1b PP |
11936 | /* Invalidate last known value of any hardware watchpoint if |
11937 | the memory which that value represents has been written to by | |
11938 | GDB itself. */ | |
11939 | ||
11940 | static void | |
11941 | invalidate_bp_value_on_memory_change (CORE_ADDR addr, int len, | |
11942 | const bfd_byte *data) | |
11943 | { | |
11944 | struct breakpoint *bp; | |
11945 | ||
11946 | ALL_BREAKPOINTS (bp) | |
11947 | if (bp->enable_state == bp_enabled | |
11948 | && bp->type == bp_hardware_watchpoint | |
11949 | && bp->val_valid && bp->val) | |
11950 | { | |
11951 | struct bp_location *loc; | |
11952 | ||
11953 | for (loc = bp->loc; loc != NULL; loc = loc->next) | |
11954 | if (loc->loc_type == bp_loc_hardware_watchpoint | |
11955 | && loc->address + loc->length > addr | |
11956 | && addr + len > loc->address) | |
11957 | { | |
11958 | value_free (bp->val); | |
11959 | bp->val = NULL; | |
11960 | bp->val_valid = 0; | |
11961 | } | |
11962 | } | |
11963 | } | |
11964 | ||
c906108c SS |
11965 | /* Use default_breakpoint_'s, or nothing if they aren't valid. */ |
11966 | ||
11967 | struct symtabs_and_lines | |
fba45db2 | 11968 | decode_line_spec_1 (char *string, int funfirstline) |
c906108c SS |
11969 | { |
11970 | struct symtabs_and_lines sals; | |
cc59ec59 | 11971 | |
c906108c | 11972 | if (string == 0) |
8a3fe4f8 | 11973 | error (_("Empty line specification.")); |
c906108c SS |
11974 | if (default_breakpoint_valid) |
11975 | sals = decode_line_1 (&string, funfirstline, | |
53a5351d JM |
11976 | default_breakpoint_symtab, |
11977 | default_breakpoint_line, | |
58438ac1 | 11978 | NULL); |
c906108c SS |
11979 | else |
11980 | sals = decode_line_1 (&string, funfirstline, | |
58438ac1 | 11981 | (struct symtab *) NULL, 0, NULL); |
c906108c | 11982 | if (*string) |
8a3fe4f8 | 11983 | error (_("Junk at end of line specification: %s"), string); |
c906108c SS |
11984 | return sals; |
11985 | } | |
8181d85f DJ |
11986 | |
11987 | /* Create and insert a raw software breakpoint at PC. Return an | |
11988 | identifier, which should be used to remove the breakpoint later. | |
11989 | In general, places which call this should be using something on the | |
11990 | breakpoint chain instead; this function should be eliminated | |
11991 | someday. */ | |
11992 | ||
11993 | void * | |
6c95b8df PA |
11994 | deprecated_insert_raw_breakpoint (struct gdbarch *gdbarch, |
11995 | struct address_space *aspace, CORE_ADDR pc) | |
8181d85f DJ |
11996 | { |
11997 | struct bp_target_info *bp_tgt; | |
11998 | ||
6c95b8df | 11999 | bp_tgt = XZALLOC (struct bp_target_info); |
8181d85f | 12000 | |
6c95b8df | 12001 | bp_tgt->placed_address_space = aspace; |
8181d85f | 12002 | bp_tgt->placed_address = pc; |
6c95b8df | 12003 | |
a6d9a66e | 12004 | if (target_insert_breakpoint (gdbarch, bp_tgt) != 0) |
8181d85f DJ |
12005 | { |
12006 | /* Could not insert the breakpoint. */ | |
12007 | xfree (bp_tgt); | |
12008 | return NULL; | |
12009 | } | |
12010 | ||
12011 | return bp_tgt; | |
12012 | } | |
12013 | ||
4a64f543 MS |
12014 | /* Remove a breakpoint BP inserted by |
12015 | deprecated_insert_raw_breakpoint. */ | |
8181d85f DJ |
12016 | |
12017 | int | |
a6d9a66e | 12018 | deprecated_remove_raw_breakpoint (struct gdbarch *gdbarch, void *bp) |
8181d85f DJ |
12019 | { |
12020 | struct bp_target_info *bp_tgt = bp; | |
12021 | int ret; | |
12022 | ||
a6d9a66e | 12023 | ret = target_remove_breakpoint (gdbarch, bp_tgt); |
8181d85f DJ |
12024 | xfree (bp_tgt); |
12025 | ||
12026 | return ret; | |
12027 | } | |
12028 | ||
4a64f543 MS |
12029 | /* One (or perhaps two) breakpoints used for software single |
12030 | stepping. */ | |
8181d85f DJ |
12031 | |
12032 | static void *single_step_breakpoints[2]; | |
a6d9a66e | 12033 | static struct gdbarch *single_step_gdbarch[2]; |
8181d85f DJ |
12034 | |
12035 | /* Create and insert a breakpoint for software single step. */ | |
12036 | ||
12037 | void | |
6c95b8df | 12038 | insert_single_step_breakpoint (struct gdbarch *gdbarch, |
4a64f543 MS |
12039 | struct address_space *aspace, |
12040 | CORE_ADDR next_pc) | |
8181d85f DJ |
12041 | { |
12042 | void **bpt_p; | |
12043 | ||
12044 | if (single_step_breakpoints[0] == NULL) | |
a6d9a66e UW |
12045 | { |
12046 | bpt_p = &single_step_breakpoints[0]; | |
12047 | single_step_gdbarch[0] = gdbarch; | |
12048 | } | |
8181d85f DJ |
12049 | else |
12050 | { | |
12051 | gdb_assert (single_step_breakpoints[1] == NULL); | |
12052 | bpt_p = &single_step_breakpoints[1]; | |
a6d9a66e | 12053 | single_step_gdbarch[1] = gdbarch; |
8181d85f DJ |
12054 | } |
12055 | ||
4a64f543 MS |
12056 | /* NOTE drow/2006-04-11: A future improvement to this function would |
12057 | be to only create the breakpoints once, and actually put them on | |
12058 | the breakpoint chain. That would let us use set_raw_breakpoint. | |
12059 | We could adjust the addresses each time they were needed. Doing | |
12060 | this requires corresponding changes elsewhere where single step | |
12061 | breakpoints are handled, however. So, for now, we use this. */ | |
8181d85f | 12062 | |
6c95b8df | 12063 | *bpt_p = deprecated_insert_raw_breakpoint (gdbarch, aspace, next_pc); |
8181d85f | 12064 | if (*bpt_p == NULL) |
5af949e3 UW |
12065 | error (_("Could not insert single-step breakpoint at %s"), |
12066 | paddress (gdbarch, next_pc)); | |
8181d85f DJ |
12067 | } |
12068 | ||
f02253f1 HZ |
12069 | /* Check if the breakpoints used for software single stepping |
12070 | were inserted or not. */ | |
12071 | ||
12072 | int | |
12073 | single_step_breakpoints_inserted (void) | |
12074 | { | |
12075 | return (single_step_breakpoints[0] != NULL | |
12076 | || single_step_breakpoints[1] != NULL); | |
12077 | } | |
12078 | ||
8181d85f DJ |
12079 | /* Remove and delete any breakpoints used for software single step. */ |
12080 | ||
12081 | void | |
12082 | remove_single_step_breakpoints (void) | |
12083 | { | |
12084 | gdb_assert (single_step_breakpoints[0] != NULL); | |
12085 | ||
12086 | /* See insert_single_step_breakpoint for more about this deprecated | |
12087 | call. */ | |
a6d9a66e UW |
12088 | deprecated_remove_raw_breakpoint (single_step_gdbarch[0], |
12089 | single_step_breakpoints[0]); | |
12090 | single_step_gdbarch[0] = NULL; | |
8181d85f DJ |
12091 | single_step_breakpoints[0] = NULL; |
12092 | ||
12093 | if (single_step_breakpoints[1] != NULL) | |
12094 | { | |
a6d9a66e UW |
12095 | deprecated_remove_raw_breakpoint (single_step_gdbarch[1], |
12096 | single_step_breakpoints[1]); | |
12097 | single_step_gdbarch[1] = NULL; | |
8181d85f DJ |
12098 | single_step_breakpoints[1] = NULL; |
12099 | } | |
12100 | } | |
12101 | ||
d03285ec UW |
12102 | /* Delete software single step breakpoints without removing them from |
12103 | the inferior. This is intended to be used if the inferior's address | |
12104 | space where they were inserted is already gone, e.g. after exit or | |
12105 | exec. */ | |
12106 | ||
12107 | void | |
12108 | cancel_single_step_breakpoints (void) | |
12109 | { | |
12110 | int i; | |
12111 | ||
12112 | for (i = 0; i < 2; i++) | |
12113 | if (single_step_breakpoints[i]) | |
12114 | { | |
12115 | xfree (single_step_breakpoints[i]); | |
12116 | single_step_breakpoints[i] = NULL; | |
12117 | single_step_gdbarch[i] = NULL; | |
12118 | } | |
12119 | } | |
12120 | ||
12121 | /* Detach software single-step breakpoints from INFERIOR_PTID without | |
12122 | removing them. */ | |
12123 | ||
12124 | static void | |
12125 | detach_single_step_breakpoints (void) | |
12126 | { | |
12127 | int i; | |
12128 | ||
12129 | for (i = 0; i < 2; i++) | |
12130 | if (single_step_breakpoints[i]) | |
12131 | target_remove_breakpoint (single_step_gdbarch[i], | |
12132 | single_step_breakpoints[i]); | |
12133 | } | |
12134 | ||
4a64f543 MS |
12135 | /* Check whether a software single-step breakpoint is inserted at |
12136 | PC. */ | |
1aafd4da UW |
12137 | |
12138 | static int | |
cc59ec59 MS |
12139 | single_step_breakpoint_inserted_here_p (struct address_space *aspace, |
12140 | CORE_ADDR pc) | |
1aafd4da UW |
12141 | { |
12142 | int i; | |
12143 | ||
12144 | for (i = 0; i < 2; i++) | |
12145 | { | |
12146 | struct bp_target_info *bp_tgt = single_step_breakpoints[i]; | |
6c95b8df PA |
12147 | if (bp_tgt |
12148 | && breakpoint_address_match (bp_tgt->placed_address_space, | |
12149 | bp_tgt->placed_address, | |
12150 | aspace, pc)) | |
1aafd4da UW |
12151 | return 1; |
12152 | } | |
12153 | ||
12154 | return 0; | |
12155 | } | |
12156 | ||
a96d9b2e SDJ |
12157 | /* Returns 0 if 'bp' is NOT a syscall catchpoint, |
12158 | non-zero otherwise. */ | |
12159 | static int | |
12160 | is_syscall_catchpoint_enabled (struct breakpoint *bp) | |
12161 | { | |
12162 | if (syscall_catchpoint_p (bp) | |
12163 | && bp->enable_state != bp_disabled | |
12164 | && bp->enable_state != bp_call_disabled) | |
12165 | return 1; | |
12166 | else | |
12167 | return 0; | |
12168 | } | |
12169 | ||
12170 | int | |
12171 | catch_syscall_enabled (void) | |
12172 | { | |
12173 | struct inferior *inf = current_inferior (); | |
12174 | ||
12175 | return inf->total_syscalls_count != 0; | |
12176 | } | |
12177 | ||
12178 | int | |
12179 | catching_syscall_number (int syscall_number) | |
12180 | { | |
12181 | struct breakpoint *bp; | |
12182 | ||
12183 | ALL_BREAKPOINTS (bp) | |
12184 | if (is_syscall_catchpoint_enabled (bp)) | |
12185 | { | |
12186 | if (bp->syscalls_to_be_caught) | |
12187 | { | |
12188 | int i, iter; | |
12189 | for (i = 0; | |
12190 | VEC_iterate (int, bp->syscalls_to_be_caught, i, iter); | |
12191 | i++) | |
12192 | if (syscall_number == iter) | |
12193 | return 1; | |
12194 | } | |
12195 | else | |
12196 | return 1; | |
12197 | } | |
12198 | ||
12199 | return 0; | |
12200 | } | |
12201 | ||
12202 | /* Complete syscall names. Used by "catch syscall". */ | |
12203 | static char ** | |
12204 | catch_syscall_completer (struct cmd_list_element *cmd, | |
12205 | char *text, char *word) | |
12206 | { | |
12207 | const char **list = get_syscall_names (); | |
c38eea1a MS |
12208 | char **retlist |
12209 | = (list == NULL) ? NULL : complete_on_enum (list, text, word); | |
cc59ec59 | 12210 | |
c38eea1a MS |
12211 | xfree (list); |
12212 | return retlist; | |
a96d9b2e SDJ |
12213 | } |
12214 | ||
1042e4c0 SS |
12215 | /* Tracepoint-specific operations. */ |
12216 | ||
12217 | /* Set tracepoint count to NUM. */ | |
12218 | static void | |
12219 | set_tracepoint_count (int num) | |
12220 | { | |
12221 | tracepoint_count = num; | |
4fa62494 | 12222 | set_internalvar_integer (lookup_internalvar ("tpnum"), num); |
1042e4c0 SS |
12223 | } |
12224 | ||
12225 | void | |
12226 | trace_command (char *arg, int from_tty) | |
12227 | { | |
8cdf0e15 VP |
12228 | if (create_breakpoint (get_current_arch (), |
12229 | arg, | |
12230 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12231 | 0 /* tempflag */, |
12232 | bp_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12233 | 0 /* Ignore count */, |
12234 | pending_break_support, | |
12235 | NULL, | |
12236 | from_tty, | |
84f4c1fe PM |
12237 | 1 /* enabled */, |
12238 | 0 /* internal */)) | |
fd9b8c24 | 12239 | set_tracepoint_count (breakpoint_count); |
1042e4c0 SS |
12240 | } |
12241 | ||
7a697b8d SS |
12242 | void |
12243 | ftrace_command (char *arg, int from_tty) | |
12244 | { | |
8cdf0e15 VP |
12245 | if (create_breakpoint (get_current_arch (), |
12246 | arg, | |
12247 | NULL, 0, 1 /* parse arg */, | |
0fb4aa4b PA |
12248 | 0 /* tempflag */, |
12249 | bp_fast_tracepoint /* type_wanted */, | |
12250 | 0 /* Ignore count */, | |
12251 | pending_break_support, | |
12252 | NULL, | |
12253 | from_tty, | |
84f4c1fe PM |
12254 | 1 /* enabled */, |
12255 | 0 /* internal */)) | |
0fb4aa4b PA |
12256 | set_tracepoint_count (breakpoint_count); |
12257 | } | |
12258 | ||
12259 | /* strace command implementation. Creates a static tracepoint. */ | |
12260 | ||
12261 | void | |
12262 | strace_command (char *arg, int from_tty) | |
12263 | { | |
12264 | if (create_breakpoint (get_current_arch (), | |
12265 | arg, | |
12266 | NULL, 0, 1 /* parse arg */, | |
12267 | 0 /* tempflag */, | |
12268 | bp_static_tracepoint /* type_wanted */, | |
8cdf0e15 VP |
12269 | 0 /* Ignore count */, |
12270 | pending_break_support, | |
12271 | NULL, | |
12272 | from_tty, | |
84f4c1fe PM |
12273 | 1 /* enabled */, |
12274 | 0 /* internal */)) | |
fd9b8c24 | 12275 | set_tracepoint_count (breakpoint_count); |
7a697b8d SS |
12276 | } |
12277 | ||
409873ef SS |
12278 | /* Set up a fake reader function that gets command lines from a linked |
12279 | list that was acquired during tracepoint uploading. */ | |
12280 | ||
12281 | static struct uploaded_tp *this_utp; | |
3149d8c1 | 12282 | static int next_cmd; |
409873ef SS |
12283 | |
12284 | static char * | |
12285 | read_uploaded_action (void) | |
12286 | { | |
12287 | char *rslt; | |
12288 | ||
3149d8c1 | 12289 | VEC_iterate (char_ptr, this_utp->cmd_strings, next_cmd, rslt); |
409873ef | 12290 | |
3149d8c1 | 12291 | next_cmd++; |
409873ef SS |
12292 | |
12293 | return rslt; | |
12294 | } | |
12295 | ||
00bf0b85 SS |
12296 | /* Given information about a tracepoint as recorded on a target (which |
12297 | can be either a live system or a trace file), attempt to create an | |
12298 | equivalent GDB tracepoint. This is not a reliable process, since | |
12299 | the target does not necessarily have all the information used when | |
12300 | the tracepoint was originally defined. */ | |
12301 | ||
12302 | struct breakpoint * | |
12303 | create_tracepoint_from_upload (struct uploaded_tp *utp) | |
d5551862 | 12304 | { |
409873ef | 12305 | char *addr_str, small_buf[100]; |
d5551862 | 12306 | struct breakpoint *tp; |
fd9b8c24 | 12307 | |
409873ef SS |
12308 | if (utp->at_string) |
12309 | addr_str = utp->at_string; | |
12310 | else | |
12311 | { | |
12312 | /* In the absence of a source location, fall back to raw | |
12313 | address. Since there is no way to confirm that the address | |
12314 | means the same thing as when the trace was started, warn the | |
12315 | user. */ | |
3e43a32a MS |
12316 | warning (_("Uploaded tracepoint %d has no " |
12317 | "source location, using raw address"), | |
409873ef SS |
12318 | utp->number); |
12319 | sprintf (small_buf, "*%s", hex_string (utp->addr)); | |
12320 | addr_str = small_buf; | |
12321 | } | |
12322 | ||
12323 | /* There's not much we can do with a sequence of bytecodes. */ | |
12324 | if (utp->cond && !utp->cond_string) | |
3e43a32a MS |
12325 | warning (_("Uploaded tracepoint %d condition " |
12326 | "has no source form, ignoring it"), | |
409873ef | 12327 | utp->number); |
d5551862 | 12328 | |
8cdf0e15 | 12329 | if (!create_breakpoint (get_current_arch (), |
409873ef SS |
12330 | addr_str, |
12331 | utp->cond_string, -1, 0 /* parse cond/thread */, | |
8cdf0e15 | 12332 | 0 /* tempflag */, |
0fb4aa4b | 12333 | utp->type /* type_wanted */, |
8cdf0e15 VP |
12334 | 0 /* Ignore count */, |
12335 | pending_break_support, | |
12336 | NULL, | |
12337 | 0 /* from_tty */, | |
84f4c1fe PM |
12338 | utp->enabled /* enabled */, |
12339 | 0 /* internal */)) | |
fd9b8c24 PA |
12340 | return NULL; |
12341 | ||
00bf0b85 SS |
12342 | set_tracepoint_count (breakpoint_count); |
12343 | ||
409873ef | 12344 | /* Get the tracepoint we just created. */ |
fd9b8c24 PA |
12345 | tp = get_tracepoint (tracepoint_count); |
12346 | gdb_assert (tp != NULL); | |
d5551862 | 12347 | |
00bf0b85 SS |
12348 | if (utp->pass > 0) |
12349 | { | |
409873ef | 12350 | sprintf (small_buf, "%d %d", utp->pass, tp->number); |
00bf0b85 | 12351 | |
409873ef | 12352 | trace_pass_command (small_buf, 0); |
00bf0b85 SS |
12353 | } |
12354 | ||
409873ef SS |
12355 | /* If we have uploaded versions of the original commands, set up a |
12356 | special-purpose "reader" function and call the usual command line | |
12357 | reader, then pass the result to the breakpoint command-setting | |
12358 | function. */ | |
3149d8c1 | 12359 | if (!VEC_empty (char_ptr, utp->cmd_strings)) |
00bf0b85 | 12360 | { |
409873ef | 12361 | struct command_line *cmd_list; |
00bf0b85 | 12362 | |
409873ef | 12363 | this_utp = utp; |
3149d8c1 | 12364 | next_cmd = 0; |
d5551862 | 12365 | |
409873ef SS |
12366 | cmd_list = read_command_lines_1 (read_uploaded_action, 1, NULL, NULL); |
12367 | ||
12368 | breakpoint_set_commands (tp, cmd_list); | |
00bf0b85 | 12369 | } |
3149d8c1 SS |
12370 | else if (!VEC_empty (char_ptr, utp->actions) |
12371 | || !VEC_empty (char_ptr, utp->step_actions)) | |
3e43a32a MS |
12372 | warning (_("Uploaded tracepoint %d actions " |
12373 | "have no source form, ignoring them"), | |
409873ef | 12374 | utp->number); |
00bf0b85 SS |
12375 | |
12376 | return tp; | |
12377 | } | |
12378 | ||
1042e4c0 SS |
12379 | /* Print information on tracepoint number TPNUM_EXP, or all if |
12380 | omitted. */ | |
12381 | ||
12382 | static void | |
e5a67952 | 12383 | tracepoints_info (char *args, int from_tty) |
1042e4c0 | 12384 | { |
e5a67952 | 12385 | int num_printed; |
1042e4c0 | 12386 | |
e5a67952 | 12387 | num_printed = breakpoint_1 (args, 0, is_tracepoint); |
d77f58be SS |
12388 | |
12389 | if (num_printed == 0) | |
1042e4c0 | 12390 | { |
e5a67952 | 12391 | if (args == NULL || *args == '\0') |
d77f58be SS |
12392 | ui_out_message (uiout, 0, "No tracepoints.\n"); |
12393 | else | |
e5a67952 | 12394 | ui_out_message (uiout, 0, "No tracepoint matching '%s'.\n", args); |
1042e4c0 | 12395 | } |
ad443146 SS |
12396 | |
12397 | default_collect_info (); | |
1042e4c0 SS |
12398 | } |
12399 | ||
4a64f543 | 12400 | /* The 'enable trace' command enables tracepoints. |
1042e4c0 SS |
12401 | Not supported by all targets. */ |
12402 | static void | |
12403 | enable_trace_command (char *args, int from_tty) | |
12404 | { | |
12405 | enable_command (args, from_tty); | |
12406 | } | |
12407 | ||
4a64f543 | 12408 | /* The 'disable trace' command disables tracepoints. |
1042e4c0 SS |
12409 | Not supported by all targets. */ |
12410 | static void | |
12411 | disable_trace_command (char *args, int from_tty) | |
12412 | { | |
12413 | disable_command (args, from_tty); | |
12414 | } | |
12415 | ||
4a64f543 | 12416 | /* Remove a tracepoint (or all if no argument). */ |
1042e4c0 SS |
12417 | static void |
12418 | delete_trace_command (char *arg, int from_tty) | |
12419 | { | |
35df4500 | 12420 | struct breakpoint *b, *b_tmp; |
1042e4c0 SS |
12421 | |
12422 | dont_repeat (); | |
12423 | ||
12424 | if (arg == 0) | |
12425 | { | |
12426 | int breaks_to_delete = 0; | |
12427 | ||
12428 | /* Delete all breakpoints if no argument. | |
12429 | Do not delete internal or call-dummy breakpoints, these | |
4a64f543 MS |
12430 | have to be deleted with an explicit breakpoint number |
12431 | argument. */ | |
1042e4c0 | 12432 | ALL_TRACEPOINTS (b) |
46c6471b | 12433 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 SS |
12434 | { |
12435 | breaks_to_delete = 1; | |
12436 | break; | |
12437 | } | |
1042e4c0 SS |
12438 | |
12439 | /* Ask user only if there are some breakpoints to delete. */ | |
12440 | if (!from_tty | |
12441 | || (breaks_to_delete && query (_("Delete all tracepoints? ")))) | |
12442 | { | |
35df4500 | 12443 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
46c6471b | 12444 | if (is_tracepoint (b) && user_breakpoint_p (b)) |
1042e4c0 | 12445 | delete_breakpoint (b); |
1042e4c0 SS |
12446 | } |
12447 | } | |
12448 | else | |
51be5b68 | 12449 | map_breakpoint_numbers (arg, do_map_delete_breakpoint, NULL); |
1042e4c0 SS |
12450 | } |
12451 | ||
197f0a60 TT |
12452 | /* Helper function for trace_pass_command. */ |
12453 | ||
12454 | static void | |
12455 | trace_pass_set_count (struct breakpoint *bp, int count, int from_tty) | |
12456 | { | |
12457 | bp->pass_count = count; | |
12458 | observer_notify_tracepoint_modified (bp->number); | |
12459 | if (from_tty) | |
12460 | printf_filtered (_("Setting tracepoint %d's passcount to %d\n"), | |
12461 | bp->number, count); | |
12462 | } | |
12463 | ||
1042e4c0 SS |
12464 | /* Set passcount for tracepoint. |
12465 | ||
12466 | First command argument is passcount, second is tracepoint number. | |
12467 | If tracepoint number omitted, apply to most recently defined. | |
12468 | Also accepts special argument "all". */ | |
12469 | ||
12470 | static void | |
12471 | trace_pass_command (char *args, int from_tty) | |
12472 | { | |
197f0a60 | 12473 | struct breakpoint *t1; |
1042e4c0 | 12474 | unsigned int count; |
1042e4c0 SS |
12475 | |
12476 | if (args == 0 || *args == 0) | |
3e43a32a MS |
12477 | error (_("passcount command requires an " |
12478 | "argument (count + optional TP num)")); | |
1042e4c0 | 12479 | |
4a64f543 | 12480 | count = strtoul (args, &args, 10); /* Count comes first, then TP num. */ |
1042e4c0 SS |
12481 | |
12482 | while (*args && isspace ((int) *args)) | |
12483 | args++; | |
12484 | ||
12485 | if (*args && strncasecmp (args, "all", 3) == 0) | |
12486 | { | |
12487 | args += 3; /* Skip special argument "all". */ | |
1042e4c0 SS |
12488 | if (*args) |
12489 | error (_("Junk at end of arguments.")); | |
1042e4c0 | 12490 | |
197f0a60 TT |
12491 | ALL_TRACEPOINTS (t1) |
12492 | { | |
12493 | trace_pass_set_count (t1, count, from_tty); | |
12494 | } | |
12495 | } | |
12496 | else if (*args == '\0') | |
1042e4c0 | 12497 | { |
197f0a60 | 12498 | t1 = get_tracepoint_by_number (&args, NULL, 1); |
1042e4c0 | 12499 | if (t1) |
197f0a60 TT |
12500 | trace_pass_set_count (t1, count, from_tty); |
12501 | } | |
12502 | else | |
12503 | { | |
12504 | struct get_number_or_range_state state; | |
12505 | ||
12506 | init_number_or_range (&state, args); | |
12507 | while (!state.finished) | |
1042e4c0 | 12508 | { |
197f0a60 TT |
12509 | t1 = get_tracepoint_by_number (&args, &state, 1); |
12510 | if (t1) | |
12511 | trace_pass_set_count (t1, count, from_tty); | |
1042e4c0 SS |
12512 | } |
12513 | } | |
1042e4c0 SS |
12514 | } |
12515 | ||
12516 | struct breakpoint * | |
12517 | get_tracepoint (int num) | |
12518 | { | |
12519 | struct breakpoint *t; | |
12520 | ||
12521 | ALL_TRACEPOINTS (t) | |
12522 | if (t->number == num) | |
12523 | return t; | |
12524 | ||
12525 | return NULL; | |
12526 | } | |
12527 | ||
d5551862 SS |
12528 | /* Find the tracepoint with the given target-side number (which may be |
12529 | different from the tracepoint number after disconnecting and | |
12530 | reconnecting). */ | |
12531 | ||
12532 | struct breakpoint * | |
12533 | get_tracepoint_by_number_on_target (int num) | |
12534 | { | |
12535 | struct breakpoint *t; | |
12536 | ||
12537 | ALL_TRACEPOINTS (t) | |
12538 | if (t->number_on_target == num) | |
12539 | return t; | |
12540 | ||
12541 | return NULL; | |
12542 | } | |
12543 | ||
1042e4c0 | 12544 | /* Utility: parse a tracepoint number and look it up in the list. |
197f0a60 TT |
12545 | If STATE is not NULL, use, get_number_or_range_state and ignore ARG. |
12546 | If OPTIONAL_P is true, then if the argument is missing, the most | |
1042e4c0 SS |
12547 | recent tracepoint (tracepoint_count) is returned. */ |
12548 | struct breakpoint * | |
197f0a60 TT |
12549 | get_tracepoint_by_number (char **arg, |
12550 | struct get_number_or_range_state *state, | |
12551 | int optional_p) | |
1042e4c0 SS |
12552 | { |
12553 | extern int tracepoint_count; | |
12554 | struct breakpoint *t; | |
12555 | int tpnum; | |
12556 | char *instring = arg == NULL ? NULL : *arg; | |
12557 | ||
197f0a60 TT |
12558 | if (state) |
12559 | { | |
12560 | gdb_assert (!state->finished); | |
12561 | tpnum = get_number_or_range (state); | |
12562 | } | |
12563 | else if (arg == NULL || *arg == NULL || ! **arg) | |
1042e4c0 SS |
12564 | { |
12565 | if (optional_p) | |
12566 | tpnum = tracepoint_count; | |
12567 | else | |
12568 | error_no_arg (_("tracepoint number")); | |
12569 | } | |
12570 | else | |
197f0a60 | 12571 | tpnum = get_number (arg); |
1042e4c0 SS |
12572 | |
12573 | if (tpnum <= 0) | |
12574 | { | |
12575 | if (instring && *instring) | |
12576 | printf_filtered (_("bad tracepoint number at or near '%s'\n"), | |
12577 | instring); | |
12578 | else | |
3e43a32a MS |
12579 | printf_filtered (_("Tracepoint argument missing " |
12580 | "and no previous tracepoint\n")); | |
1042e4c0 SS |
12581 | return NULL; |
12582 | } | |
12583 | ||
12584 | ALL_TRACEPOINTS (t) | |
12585 | if (t->number == tpnum) | |
12586 | { | |
12587 | return t; | |
12588 | } | |
12589 | ||
1042e4c0 SS |
12590 | printf_unfiltered ("No tracepoint number %d.\n", tpnum); |
12591 | return NULL; | |
12592 | } | |
12593 | ||
6149aea9 PA |
12594 | /* Save information on user settable breakpoints (watchpoints, etc) to |
12595 | a new script file named FILENAME. If FILTER is non-NULL, call it | |
12596 | on each breakpoint and only include the ones for which it returns | |
12597 | non-zero. */ | |
12598 | ||
1042e4c0 | 12599 | static void |
6149aea9 PA |
12600 | save_breakpoints (char *filename, int from_tty, |
12601 | int (*filter) (const struct breakpoint *)) | |
1042e4c0 SS |
12602 | { |
12603 | struct breakpoint *tp; | |
6149aea9 | 12604 | int any = 0; |
a7bdde9e | 12605 | char *pathname; |
1042e4c0 | 12606 | struct cleanup *cleanup; |
a7bdde9e | 12607 | struct ui_file *fp; |
6149aea9 | 12608 | int extra_trace_bits = 0; |
1042e4c0 | 12609 | |
6149aea9 PA |
12610 | if (filename == 0 || *filename == 0) |
12611 | error (_("Argument required (file name in which to save)")); | |
1042e4c0 SS |
12612 | |
12613 | /* See if we have anything to save. */ | |
6149aea9 | 12614 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 12615 | { |
6149aea9 | 12616 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 12617 | if (!user_breakpoint_p (tp)) |
6149aea9 PA |
12618 | continue; |
12619 | ||
12620 | /* If we have a filter, only save the breakpoints it accepts. */ | |
12621 | if (filter && !filter (tp)) | |
12622 | continue; | |
12623 | ||
12624 | any = 1; | |
12625 | ||
12626 | if (is_tracepoint (tp)) | |
12627 | { | |
12628 | extra_trace_bits = 1; | |
12629 | ||
12630 | /* We can stop searching. */ | |
12631 | break; | |
12632 | } | |
1042e4c0 | 12633 | } |
6149aea9 PA |
12634 | |
12635 | if (!any) | |
1042e4c0 | 12636 | { |
6149aea9 | 12637 | warning (_("Nothing to save.")); |
1042e4c0 SS |
12638 | return; |
12639 | } | |
12640 | ||
6149aea9 | 12641 | pathname = tilde_expand (filename); |
1042e4c0 | 12642 | cleanup = make_cleanup (xfree, pathname); |
a7bdde9e | 12643 | fp = gdb_fopen (pathname, "w"); |
059fb39f | 12644 | if (!fp) |
6149aea9 PA |
12645 | error (_("Unable to open file '%s' for saving (%s)"), |
12646 | filename, safe_strerror (errno)); | |
a7bdde9e | 12647 | make_cleanup_ui_file_delete (fp); |
8bf6485c | 12648 | |
6149aea9 PA |
12649 | if (extra_trace_bits) |
12650 | save_trace_state_variables (fp); | |
8bf6485c | 12651 | |
6149aea9 | 12652 | ALL_BREAKPOINTS (tp) |
1042e4c0 | 12653 | { |
6149aea9 | 12654 | /* Skip internal and momentary breakpoints. */ |
09d682a4 | 12655 | if (!user_breakpoint_p (tp)) |
6149aea9 | 12656 | continue; |
8bf6485c | 12657 | |
6149aea9 PA |
12658 | /* If we have a filter, only save the breakpoints it accepts. */ |
12659 | if (filter && !filter (tp)) | |
12660 | continue; | |
12661 | ||
26063d49 | 12662 | if (tp->ops != NULL && tp->ops->print_recreate != NULL) |
6149aea9 | 12663 | (tp->ops->print_recreate) (tp, fp); |
1042e4c0 SS |
12664 | else |
12665 | { | |
6149aea9 PA |
12666 | if (tp->type == bp_fast_tracepoint) |
12667 | fprintf_unfiltered (fp, "ftrace"); | |
0fb4aa4b PA |
12668 | if (tp->type == bp_static_tracepoint) |
12669 | fprintf_unfiltered (fp, "strace"); | |
6149aea9 PA |
12670 | else if (tp->type == bp_tracepoint) |
12671 | fprintf_unfiltered (fp, "trace"); | |
12672 | else if (tp->type == bp_breakpoint && tp->disposition == disp_del) | |
12673 | fprintf_unfiltered (fp, "tbreak"); | |
12674 | else if (tp->type == bp_breakpoint) | |
12675 | fprintf_unfiltered (fp, "break"); | |
12676 | else if (tp->type == bp_hardware_breakpoint | |
12677 | && tp->disposition == disp_del) | |
12678 | fprintf_unfiltered (fp, "thbreak"); | |
12679 | else if (tp->type == bp_hardware_breakpoint) | |
12680 | fprintf_unfiltered (fp, "hbreak"); | |
12681 | else if (tp->type == bp_watchpoint) | |
12682 | fprintf_unfiltered (fp, "watch"); | |
12683 | else if (tp->type == bp_hardware_watchpoint) | |
12684 | fprintf_unfiltered (fp, "watch"); | |
12685 | else if (tp->type == bp_read_watchpoint) | |
12686 | fprintf_unfiltered (fp, "rwatch"); | |
12687 | else if (tp->type == bp_access_watchpoint) | |
12688 | fprintf_unfiltered (fp, "awatch"); | |
12689 | else | |
12690 | internal_error (__FILE__, __LINE__, | |
12691 | _("unhandled breakpoint type %d"), (int) tp->type); | |
12692 | ||
12693 | if (tp->exp_string) | |
12694 | fprintf_unfiltered (fp, " %s", tp->exp_string); | |
12695 | else if (tp->addr_string) | |
12696 | fprintf_unfiltered (fp, " %s", tp->addr_string); | |
12697 | else | |
12698 | { | |
12699 | char tmp[40]; | |
12700 | ||
12701 | sprintf_vma (tmp, tp->loc->address); | |
12702 | fprintf_unfiltered (fp, " *0x%s", tmp); | |
12703 | } | |
1042e4c0 SS |
12704 | } |
12705 | ||
6149aea9 PA |
12706 | if (tp->thread != -1) |
12707 | fprintf_unfiltered (fp, " thread %d", tp->thread); | |
12708 | ||
12709 | if (tp->task != 0) | |
12710 | fprintf_unfiltered (fp, " task %d", tp->task); | |
8bf6485c SS |
12711 | |
12712 | fprintf_unfiltered (fp, "\n"); | |
12713 | ||
6149aea9 PA |
12714 | /* Note, we can't rely on tp->number for anything, as we can't |
12715 | assume the recreated breakpoint numbers will match. Use $bpnum | |
12716 | instead. */ | |
12717 | ||
12718 | if (tp->cond_string) | |
12719 | fprintf_unfiltered (fp, " condition $bpnum %s\n", tp->cond_string); | |
12720 | ||
12721 | if (tp->ignore_count) | |
12722 | fprintf_unfiltered (fp, " ignore $bpnum %d\n", tp->ignore_count); | |
12723 | ||
1042e4c0 | 12724 | if (tp->pass_count) |
a7bdde9e | 12725 | fprintf_unfiltered (fp, " passcount %d\n", tp->pass_count); |
1042e4c0 | 12726 | |
a7bdde9e | 12727 | if (tp->commands) |
1042e4c0 | 12728 | { |
a7bdde9e VP |
12729 | volatile struct gdb_exception ex; |
12730 | ||
6149aea9 | 12731 | fprintf_unfiltered (fp, " commands\n"); |
a7bdde9e VP |
12732 | |
12733 | ui_out_redirect (uiout, fp); | |
14dba4b4 | 12734 | TRY_CATCH (ex, RETURN_MASK_ALL) |
1042e4c0 | 12735 | { |
9add0f1b | 12736 | print_command_lines (uiout, tp->commands->commands, 2); |
a7bdde9e VP |
12737 | } |
12738 | ui_out_redirect (uiout, NULL); | |
1042e4c0 | 12739 | |
a7bdde9e VP |
12740 | if (ex.reason < 0) |
12741 | throw_exception (ex); | |
1042e4c0 | 12742 | |
a7bdde9e | 12743 | fprintf_unfiltered (fp, " end\n"); |
1042e4c0 | 12744 | } |
6149aea9 PA |
12745 | |
12746 | if (tp->enable_state == bp_disabled) | |
12747 | fprintf_unfiltered (fp, "disable\n"); | |
12748 | ||
12749 | /* If this is a multi-location breakpoint, check if the locations | |
12750 | should be individually disabled. Watchpoint locations are | |
12751 | special, and not user visible. */ | |
12752 | if (!is_watchpoint (tp) && tp->loc && tp->loc->next) | |
12753 | { | |
12754 | struct bp_location *loc; | |
12755 | int n = 1; | |
12756 | ||
12757 | for (loc = tp->loc; loc != NULL; loc = loc->next, n++) | |
12758 | if (!loc->enabled) | |
12759 | fprintf_unfiltered (fp, "disable $bpnum.%d\n", n); | |
12760 | } | |
1042e4c0 | 12761 | } |
8bf6485c | 12762 | |
6149aea9 | 12763 | if (extra_trace_bits && *default_collect) |
8bf6485c SS |
12764 | fprintf_unfiltered (fp, "set default-collect %s\n", default_collect); |
12765 | ||
1042e4c0 SS |
12766 | do_cleanups (cleanup); |
12767 | if (from_tty) | |
6149aea9 PA |
12768 | printf_filtered (_("Saved to file '%s'.\n"), filename); |
12769 | } | |
12770 | ||
12771 | /* The `save breakpoints' command. */ | |
12772 | ||
12773 | static void | |
12774 | save_breakpoints_command (char *args, int from_tty) | |
12775 | { | |
12776 | save_breakpoints (args, from_tty, NULL); | |
12777 | } | |
12778 | ||
12779 | /* The `save tracepoints' command. */ | |
12780 | ||
12781 | static void | |
12782 | save_tracepoints_command (char *args, int from_tty) | |
12783 | { | |
12784 | save_breakpoints (args, from_tty, is_tracepoint); | |
1042e4c0 SS |
12785 | } |
12786 | ||
12787 | /* Create a vector of all tracepoints. */ | |
12788 | ||
12789 | VEC(breakpoint_p) * | |
eeae04df | 12790 | all_tracepoints (void) |
1042e4c0 SS |
12791 | { |
12792 | VEC(breakpoint_p) *tp_vec = 0; | |
12793 | struct breakpoint *tp; | |
12794 | ||
12795 | ALL_TRACEPOINTS (tp) | |
12796 | { | |
12797 | VEC_safe_push (breakpoint_p, tp_vec, tp); | |
12798 | } | |
12799 | ||
12800 | return tp_vec; | |
12801 | } | |
12802 | ||
c906108c | 12803 | \f |
4a64f543 MS |
12804 | /* This help string is used for the break, hbreak, tbreak and thbreak |
12805 | commands. It is defined as a macro to prevent duplication. | |
12806 | COMMAND should be a string constant containing the name of the | |
12807 | command. */ | |
31e2b00f AS |
12808 | #define BREAK_ARGS_HELP(command) \ |
12809 | command" [LOCATION] [thread THREADNUM] [if CONDITION]\n\ | |
12810 | LOCATION may be a line number, function name, or \"*\" and an address.\n\ | |
12811 | If a line number is specified, break at start of code for that line.\n\ | |
12812 | If a function is specified, break at start of code for that function.\n\ | |
12813 | If an address is specified, break at that exact address.\n\ | |
dc10affe PA |
12814 | With no LOCATION, uses current execution address of the selected\n\ |
12815 | stack frame. This is useful for breaking on return to a stack frame.\n\ | |
31e2b00f AS |
12816 | \n\ |
12817 | THREADNUM is the number from \"info threads\".\n\ | |
12818 | CONDITION is a boolean expression.\n\ | |
12819 | \n\ | |
d41c0fc8 PA |
12820 | Multiple breakpoints at one place are permitted, and useful if their\n\ |
12821 | conditions are different.\n\ | |
31e2b00f AS |
12822 | \n\ |
12823 | Do \"help breakpoints\" for info on other commands dealing with breakpoints." | |
12824 | ||
44feb3ce TT |
12825 | /* List of subcommands for "catch". */ |
12826 | static struct cmd_list_element *catch_cmdlist; | |
12827 | ||
12828 | /* List of subcommands for "tcatch". */ | |
12829 | static struct cmd_list_element *tcatch_cmdlist; | |
12830 | ||
12831 | /* Like add_cmd, but add the command to both the "catch" and "tcatch" | |
12832 | lists, and pass some additional user data to the command function. */ | |
12833 | static void | |
12834 | add_catch_command (char *name, char *docstring, | |
12835 | void (*sfunc) (char *args, int from_tty, | |
12836 | struct cmd_list_element *command), | |
a96d9b2e SDJ |
12837 | char **(*completer) (struct cmd_list_element *cmd, |
12838 | char *text, char *word), | |
44feb3ce TT |
12839 | void *user_data_catch, |
12840 | void *user_data_tcatch) | |
12841 | { | |
12842 | struct cmd_list_element *command; | |
12843 | ||
12844 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12845 | &catch_cmdlist); | |
12846 | set_cmd_sfunc (command, sfunc); | |
12847 | set_cmd_context (command, user_data_catch); | |
a96d9b2e | 12848 | set_cmd_completer (command, completer); |
44feb3ce TT |
12849 | |
12850 | command = add_cmd (name, class_breakpoint, NULL, docstring, | |
12851 | &tcatch_cmdlist); | |
12852 | set_cmd_sfunc (command, sfunc); | |
12853 | set_cmd_context (command, user_data_tcatch); | |
a96d9b2e | 12854 | set_cmd_completer (command, completer); |
44feb3ce TT |
12855 | } |
12856 | ||
6c95b8df | 12857 | static void |
a79b8f6e | 12858 | clear_syscall_counts (struct inferior *inf) |
6c95b8df | 12859 | { |
6c95b8df PA |
12860 | inf->total_syscalls_count = 0; |
12861 | inf->any_syscall_count = 0; | |
12862 | VEC_free (int, inf->syscalls_counts); | |
12863 | } | |
12864 | ||
6149aea9 PA |
12865 | static void |
12866 | save_command (char *arg, int from_tty) | |
12867 | { | |
3e43a32a MS |
12868 | printf_unfiltered (_("\"save\" must be followed by " |
12869 | "the name of a save subcommand.\n")); | |
6149aea9 PA |
12870 | help_list (save_cmdlist, "save ", -1, gdb_stdout); |
12871 | } | |
12872 | ||
84f4c1fe PM |
12873 | struct breakpoint * |
12874 | iterate_over_breakpoints (int (*callback) (struct breakpoint *, void *), | |
12875 | void *data) | |
12876 | { | |
35df4500 | 12877 | struct breakpoint *b, *b_tmp; |
84f4c1fe | 12878 | |
35df4500 | 12879 | ALL_BREAKPOINTS_SAFE (b, b_tmp) |
84f4c1fe PM |
12880 | { |
12881 | if ((*callback) (b, data)) | |
12882 | return b; | |
12883 | } | |
12884 | ||
12885 | return NULL; | |
12886 | } | |
12887 | ||
c906108c | 12888 | void |
fba45db2 | 12889 | _initialize_breakpoint (void) |
c906108c SS |
12890 | { |
12891 | struct cmd_list_element *c; | |
12892 | ||
84acb35a | 12893 | observer_attach_solib_unloaded (disable_breakpoints_in_unloaded_shlib); |
6c95b8df | 12894 | observer_attach_inferior_exit (clear_syscall_counts); |
1f3b5d1b | 12895 | observer_attach_memory_changed (invalidate_bp_value_on_memory_change); |
84acb35a | 12896 | |
17450429 PP |
12897 | breakpoint_objfile_key = register_objfile_data (); |
12898 | ||
c906108c SS |
12899 | breakpoint_chain = 0; |
12900 | /* Don't bother to call set_breakpoint_count. $bpnum isn't useful | |
12901 | before a breakpoint is set. */ | |
12902 | breakpoint_count = 0; | |
12903 | ||
1042e4c0 SS |
12904 | tracepoint_count = 0; |
12905 | ||
1bedd215 AC |
12906 | add_com ("ignore", class_breakpoint, ignore_command, _("\ |
12907 | Set ignore-count of breakpoint number N to COUNT.\n\ | |
12908 | Usage is `ignore N COUNT'.")); | |
c906108c | 12909 | if (xdb_commands) |
c5aa993b | 12910 | add_com_alias ("bc", "ignore", class_breakpoint, 1); |
c906108c | 12911 | |
1bedd215 AC |
12912 | add_com ("commands", class_breakpoint, commands_command, _("\ |
12913 | Set commands to be executed when a breakpoint is hit.\n\ | |
c906108c SS |
12914 | Give breakpoint number as argument after \"commands\".\n\ |
12915 | With no argument, the targeted breakpoint is the last one set.\n\ | |
12916 | The commands themselves follow starting on the next line.\n\ | |
12917 | Type a line containing \"end\" to indicate the end of them.\n\ | |
12918 | Give \"silent\" as the first line to make the breakpoint silent;\n\ | |
1bedd215 | 12919 | then no output is printed when it is hit, except what the commands print.")); |
c906108c | 12920 | |
1bedd215 AC |
12921 | add_com ("condition", class_breakpoint, condition_command, _("\ |
12922 | Specify breakpoint number N to break only if COND is true.\n\ | |
c906108c | 12923 | Usage is `condition N COND', where N is an integer and COND is an\n\ |
1bedd215 | 12924 | expression to be evaluated whenever breakpoint N is reached.")); |
c906108c | 12925 | |
1bedd215 | 12926 | c = add_com ("tbreak", class_breakpoint, tbreak_command, _("\ |
31e2b00f | 12927 | Set a temporary breakpoint.\n\ |
c906108c SS |
12928 | Like \"break\" except the breakpoint is only temporary,\n\ |
12929 | so it will be deleted when hit. Equivalent to \"break\" followed\n\ | |
31e2b00f AS |
12930 | by using \"enable delete\" on the breakpoint number.\n\ |
12931 | \n" | |
12932 | BREAK_ARGS_HELP ("tbreak"))); | |
5ba2abeb | 12933 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 12934 | |
1bedd215 | 12935 | c = add_com ("hbreak", class_breakpoint, hbreak_command, _("\ |
a3be7890 | 12936 | Set a hardware assisted breakpoint.\n\ |
c906108c | 12937 | Like \"break\" except the breakpoint requires hardware support,\n\ |
31e2b00f AS |
12938 | some target hardware may not have this support.\n\ |
12939 | \n" | |
12940 | BREAK_ARGS_HELP ("hbreak"))); | |
5ba2abeb | 12941 | set_cmd_completer (c, location_completer); |
c906108c | 12942 | |
1bedd215 | 12943 | c = add_com ("thbreak", class_breakpoint, thbreak_command, _("\ |
31e2b00f | 12944 | Set a temporary hardware assisted breakpoint.\n\ |
c906108c | 12945 | Like \"hbreak\" except the breakpoint is only temporary,\n\ |
31e2b00f AS |
12946 | so it will be deleted when hit.\n\ |
12947 | \n" | |
12948 | BREAK_ARGS_HELP ("thbreak"))); | |
5ba2abeb | 12949 | set_cmd_completer (c, location_completer); |
c906108c | 12950 | |
1bedd215 AC |
12951 | add_prefix_cmd ("enable", class_breakpoint, enable_command, _("\ |
12952 | Enable some breakpoints.\n\ | |
c906108c SS |
12953 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12954 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12955 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12956 | With a subcommand you can enable temporarily."), |
c906108c SS |
12957 | &enablelist, "enable ", 1, &cmdlist); |
12958 | if (xdb_commands) | |
1bedd215 AC |
12959 | add_com ("ab", class_breakpoint, enable_command, _("\ |
12960 | Enable some breakpoints.\n\ | |
c906108c SS |
12961 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12962 | With no subcommand, breakpoints are enabled until you command otherwise.\n\ | |
12963 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12964 | With a subcommand you can enable temporarily.")); |
c906108c SS |
12965 | |
12966 | add_com_alias ("en", "enable", class_breakpoint, 1); | |
12967 | ||
84951ab5 | 12968 | add_prefix_cmd ("breakpoints", class_breakpoint, enable_command, _("\ |
1bedd215 | 12969 | Enable some breakpoints.\n\ |
c906108c SS |
12970 | Give breakpoint numbers (separated by spaces) as arguments.\n\ |
12971 | This is used to cancel the effect of the \"disable\" command.\n\ | |
1bedd215 | 12972 | May be abbreviated to simply \"enable\".\n"), |
c5aa993b | 12973 | &enablebreaklist, "enable breakpoints ", 1, &enablelist); |
c906108c | 12974 | |
1a966eab AC |
12975 | add_cmd ("once", no_class, enable_once_command, _("\ |
12976 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12977 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12978 | &enablebreaklist); |
12979 | ||
1a966eab AC |
12980 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12981 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12982 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12983 | &enablebreaklist); |
12984 | ||
1a966eab AC |
12985 | add_cmd ("delete", no_class, enable_delete_command, _("\ |
12986 | Enable breakpoints and delete when hit. Give breakpoint numbers.\n\ | |
12987 | If a breakpoint is hit while enabled in this fashion, it is deleted."), | |
c906108c SS |
12988 | &enablelist); |
12989 | ||
1a966eab AC |
12990 | add_cmd ("once", no_class, enable_once_command, _("\ |
12991 | Enable breakpoints for one hit. Give breakpoint numbers.\n\ | |
12992 | If a breakpoint is hit while enabled in this fashion, it becomes disabled."), | |
c906108c SS |
12993 | &enablelist); |
12994 | ||
1bedd215 AC |
12995 | add_prefix_cmd ("disable", class_breakpoint, disable_command, _("\ |
12996 | Disable some breakpoints.\n\ | |
c906108c SS |
12997 | Arguments are breakpoint numbers with spaces in between.\n\ |
12998 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 12999 | A disabled breakpoint is not forgotten, but has no effect until reenabled."), |
c906108c SS |
13000 | &disablelist, "disable ", 1, &cmdlist); |
13001 | add_com_alias ("dis", "disable", class_breakpoint, 1); | |
13002 | add_com_alias ("disa", "disable", class_breakpoint, 1); | |
13003 | if (xdb_commands) | |
1bedd215 AC |
13004 | add_com ("sb", class_breakpoint, disable_command, _("\ |
13005 | Disable some breakpoints.\n\ | |
c906108c SS |
13006 | Arguments are breakpoint numbers with spaces in between.\n\ |
13007 | To disable all breakpoints, give no argument.\n\ | |
1bedd215 | 13008 | A disabled breakpoint is not forgotten, but has no effect until reenabled.")); |
c906108c | 13009 | |
1a966eab AC |
13010 | add_cmd ("breakpoints", class_alias, disable_command, _("\ |
13011 | Disable some breakpoints.\n\ | |
c906108c SS |
13012 | Arguments are breakpoint numbers with spaces in between.\n\ |
13013 | To disable all breakpoints, give no argument.\n\ | |
13014 | A disabled breakpoint is not forgotten, but has no effect until reenabled.\n\ | |
1a966eab | 13015 | This command may be abbreviated \"disable\"."), |
c906108c SS |
13016 | &disablelist); |
13017 | ||
1bedd215 AC |
13018 | add_prefix_cmd ("delete", class_breakpoint, delete_command, _("\ |
13019 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13020 | Arguments are breakpoint numbers with spaces in between.\n\ |
13021 | To delete all breakpoints, give no argument.\n\ | |
13022 | \n\ | |
13023 | Also a prefix command for deletion of other GDB objects.\n\ | |
1bedd215 | 13024 | The \"unset\" command is also an alias for \"delete\"."), |
c906108c SS |
13025 | &deletelist, "delete ", 1, &cmdlist); |
13026 | add_com_alias ("d", "delete", class_breakpoint, 1); | |
7f198e01 | 13027 | add_com_alias ("del", "delete", class_breakpoint, 1); |
c906108c | 13028 | if (xdb_commands) |
1bedd215 AC |
13029 | add_com ("db", class_breakpoint, delete_command, _("\ |
13030 | Delete some breakpoints.\n\ | |
c906108c | 13031 | Arguments are breakpoint numbers with spaces in between.\n\ |
1bedd215 | 13032 | To delete all breakpoints, give no argument.\n")); |
c906108c | 13033 | |
1a966eab AC |
13034 | add_cmd ("breakpoints", class_alias, delete_command, _("\ |
13035 | Delete some breakpoints or auto-display expressions.\n\ | |
c906108c SS |
13036 | Arguments are breakpoint numbers with spaces in between.\n\ |
13037 | To delete all breakpoints, give no argument.\n\ | |
1a966eab | 13038 | This command may be abbreviated \"delete\"."), |
c906108c SS |
13039 | &deletelist); |
13040 | ||
1bedd215 AC |
13041 | add_com ("clear", class_breakpoint, clear_command, _("\ |
13042 | Clear breakpoint at specified line or function.\n\ | |
c906108c SS |
13043 | Argument may be line number, function name, or \"*\" and an address.\n\ |
13044 | If line number is specified, all breakpoints in that line are cleared.\n\ | |
13045 | If function is specified, breakpoints at beginning of function are cleared.\n\ | |
1bedd215 AC |
13046 | If an address is specified, breakpoints at that address are cleared.\n\ |
13047 | \n\ | |
13048 | With no argument, clears all breakpoints in the line that the selected frame\n\ | |
c906108c SS |
13049 | is executing in.\n\ |
13050 | \n\ | |
1bedd215 | 13051 | See also the \"delete\" command which clears breakpoints by number.")); |
a6cc4789 | 13052 | add_com_alias ("cl", "clear", class_breakpoint, 1); |
c906108c | 13053 | |
1bedd215 | 13054 | c = add_com ("break", class_breakpoint, break_command, _("\ |
31e2b00f AS |
13055 | Set breakpoint at specified line or function.\n" |
13056 | BREAK_ARGS_HELP ("break"))); | |
5ba2abeb | 13057 | set_cmd_completer (c, location_completer); |
c94fdfd0 | 13058 | |
c906108c SS |
13059 | add_com_alias ("b", "break", class_run, 1); |
13060 | add_com_alias ("br", "break", class_run, 1); | |
13061 | add_com_alias ("bre", "break", class_run, 1); | |
13062 | add_com_alias ("brea", "break", class_run, 1); | |
13063 | ||
7681d515 PM |
13064 | if (xdb_commands) |
13065 | add_com_alias ("ba", "break", class_breakpoint, 1); | |
c906108c SS |
13066 | |
13067 | if (dbx_commands) | |
13068 | { | |
1bedd215 AC |
13069 | add_abbrev_prefix_cmd ("stop", class_breakpoint, stop_command, _("\ |
13070 | Break in function/address or break at a line in the current file."), | |
c5aa993b JM |
13071 | &stoplist, "stop ", 1, &cmdlist); |
13072 | add_cmd ("in", class_breakpoint, stopin_command, | |
1a966eab | 13073 | _("Break in function or address."), &stoplist); |
c5aa993b | 13074 | add_cmd ("at", class_breakpoint, stopat_command, |
1a966eab | 13075 | _("Break at a line in the current file."), &stoplist); |
1bedd215 AC |
13076 | add_com ("status", class_info, breakpoints_info, _("\ |
13077 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13078 | The \"Type\" column indicates one of:\n\ |
13079 | \tbreakpoint - normal breakpoint\n\ | |
13080 | \twatchpoint - watchpoint\n\ | |
13081 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13082 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13083 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13084 | address and file/line number respectively.\n\ |
13085 | \n\ | |
13086 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13087 | are set to the address of the last breakpoint listed unless the command\n\ |
13088 | is prefixed with \"server \".\n\n\ | |
c906108c | 13089 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13090 | breakpoint set.")); |
c906108c SS |
13091 | } |
13092 | ||
1bedd215 | 13093 | add_info ("breakpoints", breakpoints_info, _("\ |
e5a67952 | 13094 | Status of specified breakpoints (all user-settable breakpoints if no argument).\n\ |
c906108c SS |
13095 | The \"Type\" column indicates one of:\n\ |
13096 | \tbreakpoint - normal breakpoint\n\ | |
13097 | \twatchpoint - watchpoint\n\ | |
13098 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13099 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13100 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13101 | address and file/line number respectively.\n\ |
13102 | \n\ | |
13103 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13104 | are set to the address of the last breakpoint listed unless the command\n\ |
13105 | is prefixed with \"server \".\n\n\ | |
c906108c | 13106 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13107 | breakpoint set.")); |
c906108c | 13108 | |
6b04bdb7 MS |
13109 | add_info_alias ("b", "breakpoints", 1); |
13110 | ||
c906108c | 13111 | if (xdb_commands) |
1bedd215 AC |
13112 | add_com ("lb", class_breakpoint, breakpoints_info, _("\ |
13113 | Status of user-settable breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13114 | The \"Type\" column indicates one of:\n\ |
13115 | \tbreakpoint - normal breakpoint\n\ | |
13116 | \twatchpoint - watchpoint\n\ | |
13117 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
13118 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ | |
13119 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1bedd215 AC |
13120 | address and file/line number respectively.\n\ |
13121 | \n\ | |
13122 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13123 | are set to the address of the last breakpoint listed unless the command\n\ |
13124 | is prefixed with \"server \".\n\n\ | |
c906108c | 13125 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1bedd215 | 13126 | breakpoint set.")); |
c906108c | 13127 | |
1a966eab AC |
13128 | add_cmd ("breakpoints", class_maintenance, maintenance_info_breakpoints, _("\ |
13129 | Status of all breakpoints, or breakpoint number NUMBER.\n\ | |
c906108c SS |
13130 | The \"Type\" column indicates one of:\n\ |
13131 | \tbreakpoint - normal breakpoint\n\ | |
13132 | \twatchpoint - watchpoint\n\ | |
13133 | \tlongjmp - internal breakpoint used to step through longjmp()\n\ | |
13134 | \tlongjmp resume - internal breakpoint at the target of longjmp()\n\ | |
13135 | \tuntil - internal breakpoint used by the \"until\" command\n\ | |
1a966eab AC |
13136 | \tfinish - internal breakpoint used by the \"finish\" command\n\ |
13137 | The \"Disp\" column contains one of \"keep\", \"del\", or \"dis\" to indicate\n\ | |
c906108c SS |
13138 | the disposition of the breakpoint after it gets hit. \"dis\" means that the\n\ |
13139 | breakpoint will be disabled. The \"Address\" and \"What\" columns indicate the\n\ | |
1a966eab AC |
13140 | address and file/line number respectively.\n\ |
13141 | \n\ | |
13142 | Convenience variable \"$_\" and default examine address for \"x\"\n\ | |
d1aa2f50 NR |
13143 | are set to the address of the last breakpoint listed unless the command\n\ |
13144 | is prefixed with \"server \".\n\n\ | |
c906108c | 13145 | Convenience variable \"$bpnum\" contains the number of the last\n\ |
1a966eab | 13146 | breakpoint set."), |
c906108c SS |
13147 | &maintenanceinfolist); |
13148 | ||
44feb3ce TT |
13149 | add_prefix_cmd ("catch", class_breakpoint, catch_command, _("\ |
13150 | Set catchpoints to catch events."), | |
13151 | &catch_cmdlist, "catch ", | |
13152 | 0/*allow-unknown*/, &cmdlist); | |
13153 | ||
13154 | add_prefix_cmd ("tcatch", class_breakpoint, tcatch_command, _("\ | |
13155 | Set temporary catchpoints to catch events."), | |
13156 | &tcatch_cmdlist, "tcatch ", | |
13157 | 0/*allow-unknown*/, &cmdlist); | |
13158 | ||
13159 | /* Add catch and tcatch sub-commands. */ | |
13160 | add_catch_command ("catch", _("\ | |
13161 | Catch an exception, when caught.\n\ | |
13162 | With an argument, catch only exceptions with the given name."), | |
13163 | catch_catch_command, | |
a96d9b2e | 13164 | NULL, |
44feb3ce TT |
13165 | CATCH_PERMANENT, |
13166 | CATCH_TEMPORARY); | |
13167 | add_catch_command ("throw", _("\ | |
13168 | Catch an exception, when thrown.\n\ | |
13169 | With an argument, catch only exceptions with the given name."), | |
13170 | catch_throw_command, | |
a96d9b2e | 13171 | NULL, |
44feb3ce TT |
13172 | CATCH_PERMANENT, |
13173 | CATCH_TEMPORARY); | |
13174 | add_catch_command ("fork", _("Catch calls to fork."), | |
13175 | catch_fork_command_1, | |
a96d9b2e | 13176 | NULL, |
44feb3ce TT |
13177 | (void *) (uintptr_t) catch_fork_permanent, |
13178 | (void *) (uintptr_t) catch_fork_temporary); | |
13179 | add_catch_command ("vfork", _("Catch calls to vfork."), | |
13180 | catch_fork_command_1, | |
a96d9b2e | 13181 | NULL, |
44feb3ce TT |
13182 | (void *) (uintptr_t) catch_vfork_permanent, |
13183 | (void *) (uintptr_t) catch_vfork_temporary); | |
13184 | add_catch_command ("exec", _("Catch calls to exec."), | |
13185 | catch_exec_command_1, | |
a96d9b2e SDJ |
13186 | NULL, |
13187 | CATCH_PERMANENT, | |
13188 | CATCH_TEMPORARY); | |
13189 | add_catch_command ("syscall", _("\ | |
13190 | Catch system calls by their names and/or numbers.\n\ | |
13191 | Arguments say which system calls to catch. If no arguments\n\ | |
13192 | are given, every system call will be caught.\n\ | |
13193 | Arguments, if given, should be one or more system call names\n\ | |
13194 | (if your system supports that), or system call numbers."), | |
13195 | catch_syscall_command_1, | |
13196 | catch_syscall_completer, | |
44feb3ce TT |
13197 | CATCH_PERMANENT, |
13198 | CATCH_TEMPORARY); | |
44feb3ce TT |
13199 | add_catch_command ("exception", _("\ |
13200 | Catch Ada exceptions, when raised.\n\ | |
13201 | With an argument, catch only exceptions with the given name."), | |
13202 | catch_ada_exception_command, | |
a96d9b2e | 13203 | NULL, |
44feb3ce TT |
13204 | CATCH_PERMANENT, |
13205 | CATCH_TEMPORARY); | |
13206 | add_catch_command ("assert", _("\ | |
13207 | Catch failed Ada assertions, when raised.\n\ | |
13208 | With an argument, catch only exceptions with the given name."), | |
13209 | catch_assert_command, | |
a96d9b2e | 13210 | NULL, |
44feb3ce TT |
13211 | CATCH_PERMANENT, |
13212 | CATCH_TEMPORARY); | |
c5aa993b | 13213 | |
1bedd215 AC |
13214 | c = add_com ("watch", class_breakpoint, watch_command, _("\ |
13215 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13216 | Usage: watch [-l|-location] EXPRESSION\n\ |
c906108c | 13217 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13218 | an expression changes.\n\ |
13219 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13220 | the memory to which it refers.")); | |
65d12d83 | 13221 | set_cmd_completer (c, expression_completer); |
c906108c | 13222 | |
1bedd215 AC |
13223 | c = add_com ("rwatch", class_breakpoint, rwatch_command, _("\ |
13224 | Set a read watchpoint for an expression.\n\ | |
06a64a0b | 13225 | Usage: rwatch [-l|-location] EXPRESSION\n\ |
c906108c | 13226 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13227 | an expression is read.\n\ |
13228 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13229 | the memory to which it refers.")); | |
65d12d83 | 13230 | set_cmd_completer (c, expression_completer); |
c906108c | 13231 | |
1bedd215 AC |
13232 | c = add_com ("awatch", class_breakpoint, awatch_command, _("\ |
13233 | Set a watchpoint for an expression.\n\ | |
06a64a0b | 13234 | Usage: awatch [-l|-location] EXPRESSION\n\ |
c906108c | 13235 | A watchpoint stops execution of your program whenever the value of\n\ |
06a64a0b TT |
13236 | an expression is either read or written.\n\ |
13237 | If -l or -location is given, this evaluates EXPRESSION and watches\n\ | |
13238 | the memory to which it refers.")); | |
65d12d83 | 13239 | set_cmd_completer (c, expression_completer); |
c906108c | 13240 | |
d77f58be | 13241 | add_info ("watchpoints", watchpoints_info, _("\ |
e5a67952 | 13242 | Status of specified watchpoints (all watchpoints if no argument).")); |
c906108c | 13243 | |
920d2a44 AC |
13244 | /* XXX: cagney/2005-02-23: This should be a boolean, and should |
13245 | respond to changes - contrary to the description. */ | |
85c07804 AC |
13246 | add_setshow_zinteger_cmd ("can-use-hw-watchpoints", class_support, |
13247 | &can_use_hw_watchpoints, _("\ | |
13248 | Set debugger's willingness to use watchpoint hardware."), _("\ | |
13249 | Show debugger's willingness to use watchpoint hardware."), _("\ | |
c906108c SS |
13250 | If zero, gdb will not use hardware for new watchpoints, even if\n\ |
13251 | such is available. (However, any hardware watchpoints that were\n\ | |
13252 | created before setting this to nonzero, will continue to use watchpoint\n\ | |
85c07804 AC |
13253 | hardware.)"), |
13254 | NULL, | |
920d2a44 | 13255 | show_can_use_hw_watchpoints, |
85c07804 | 13256 | &setlist, &showlist); |
c906108c SS |
13257 | |
13258 | can_use_hw_watchpoints = 1; | |
fa8d40ab | 13259 | |
1042e4c0 SS |
13260 | /* Tracepoint manipulation commands. */ |
13261 | ||
13262 | c = add_com ("trace", class_breakpoint, trace_command, _("\ | |
13263 | Set a tracepoint at specified line or function.\n\ | |
13264 | \n" | |
13265 | BREAK_ARGS_HELP ("trace") "\n\ | |
13266 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13267 | set_cmd_completer (c, location_completer); | |
13268 | ||
13269 | add_com_alias ("tp", "trace", class_alias, 0); | |
13270 | add_com_alias ("tr", "trace", class_alias, 1); | |
13271 | add_com_alias ("tra", "trace", class_alias, 1); | |
13272 | add_com_alias ("trac", "trace", class_alias, 1); | |
13273 | ||
7a697b8d SS |
13274 | c = add_com ("ftrace", class_breakpoint, ftrace_command, _("\ |
13275 | Set a fast tracepoint at specified line or function.\n\ | |
13276 | \n" | |
13277 | BREAK_ARGS_HELP ("ftrace") "\n\ | |
13278 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13279 | set_cmd_completer (c, location_completer); | |
13280 | ||
0fb4aa4b PA |
13281 | c = add_com ("strace", class_breakpoint, strace_command, _("\ |
13282 | Set a static tracepoint at specified line, function or marker.\n\ | |
13283 | \n\ | |
13284 | strace [LOCATION] [if CONDITION]\n\ | |
13285 | LOCATION may be a line number, function name, \"*\" and an address,\n\ | |
13286 | or -m MARKER_ID.\n\ | |
13287 | If a line number is specified, probe the marker at start of code\n\ | |
13288 | for that line. If a function is specified, probe the marker at start\n\ | |
13289 | of code for that function. If an address is specified, probe the marker\n\ | |
13290 | at that exact address. If a marker id is specified, probe the marker\n\ | |
13291 | with that name. With no LOCATION, uses current execution address of\n\ | |
13292 | the selected stack frame.\n\ | |
13293 | Static tracepoints accept an extra collect action -- ``collect $_sdata''.\n\ | |
13294 | This collects arbitrary user data passed in the probe point call to the\n\ | |
13295 | tracing library. You can inspect it when analyzing the trace buffer,\n\ | |
13296 | by printing the $_sdata variable like any other convenience variable.\n\ | |
13297 | \n\ | |
13298 | CONDITION is a boolean expression.\n\ | |
13299 | \n\ | |
d41c0fc8 PA |
13300 | Multiple tracepoints at one place are permitted, and useful if their\n\ |
13301 | conditions are different.\n\ | |
0fb4aa4b PA |
13302 | \n\ |
13303 | Do \"help breakpoints\" for info on other commands dealing with breakpoints.\n\ | |
13304 | Do \"help tracepoints\" for info on other tracepoint commands.")); | |
13305 | set_cmd_completer (c, location_completer); | |
13306 | ||
1042e4c0 | 13307 | add_info ("tracepoints", tracepoints_info, _("\ |
e5a67952 | 13308 | Status of specified tracepoints (all tracepoints if no argument).\n\ |
1042e4c0 SS |
13309 | Convenience variable \"$tpnum\" contains the number of the\n\ |
13310 | last tracepoint set.")); | |
13311 | ||
13312 | add_info_alias ("tp", "tracepoints", 1); | |
13313 | ||
13314 | add_cmd ("tracepoints", class_trace, delete_trace_command, _("\ | |
13315 | Delete specified tracepoints.\n\ | |
13316 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13317 | No argument means delete all tracepoints."), | |
13318 | &deletelist); | |
13319 | ||
13320 | c = add_cmd ("tracepoints", class_trace, disable_trace_command, _("\ | |
13321 | Disable specified tracepoints.\n\ | |
13322 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13323 | No argument means disable all tracepoints."), | |
13324 | &disablelist); | |
13325 | deprecate_cmd (c, "disable"); | |
13326 | ||
13327 | c = add_cmd ("tracepoints", class_trace, enable_trace_command, _("\ | |
13328 | Enable specified tracepoints.\n\ | |
13329 | Arguments are tracepoint numbers, separated by spaces.\n\ | |
13330 | No argument means enable all tracepoints."), | |
13331 | &enablelist); | |
13332 | deprecate_cmd (c, "enable"); | |
13333 | ||
13334 | add_com ("passcount", class_trace, trace_pass_command, _("\ | |
13335 | Set the passcount for a tracepoint.\n\ | |
13336 | The trace will end when the tracepoint has been passed 'count' times.\n\ | |
13337 | Usage: passcount COUNT TPNUM, where TPNUM may also be \"all\";\n\ | |
13338 | if TPNUM is omitted, passcount refers to the last tracepoint defined.")); | |
13339 | ||
6149aea9 PA |
13340 | add_prefix_cmd ("save", class_breakpoint, save_command, |
13341 | _("Save breakpoint definitions as a script."), | |
13342 | &save_cmdlist, "save ", | |
13343 | 0/*allow-unknown*/, &cmdlist); | |
13344 | ||
13345 | c = add_cmd ("breakpoints", class_breakpoint, save_breakpoints_command, _("\ | |
13346 | Save current breakpoint definitions as a script.\n\ | |
cce7e648 | 13347 | This includes all types of breakpoints (breakpoints, watchpoints,\n\ |
6149aea9 PA |
13348 | catchpoints, tracepoints). Use the 'source' command in another debug\n\ |
13349 | session to restore them."), | |
13350 | &save_cmdlist); | |
13351 | set_cmd_completer (c, filename_completer); | |
13352 | ||
13353 | c = add_cmd ("tracepoints", class_trace, save_tracepoints_command, _("\ | |
1042e4c0 | 13354 | Save current tracepoint definitions as a script.\n\ |
6149aea9 PA |
13355 | Use the 'source' command in another debug session to restore them."), |
13356 | &save_cmdlist); | |
1042e4c0 SS |
13357 | set_cmd_completer (c, filename_completer); |
13358 | ||
6149aea9 PA |
13359 | c = add_com_alias ("save-tracepoints", "save tracepoints", class_trace, 0); |
13360 | deprecate_cmd (c, "save tracepoints"); | |
13361 | ||
1bedd215 | 13362 | add_prefix_cmd ("breakpoint", class_maintenance, set_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13363 | Breakpoint specific settings\n\ |
13364 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13365 | pending breakpoint behavior"), |
fa8d40ab JJ |
13366 | &breakpoint_set_cmdlist, "set breakpoint ", |
13367 | 0/*allow-unknown*/, &setlist); | |
1bedd215 | 13368 | add_prefix_cmd ("breakpoint", class_maintenance, show_breakpoint_cmd, _("\ |
fa8d40ab JJ |
13369 | Breakpoint specific settings\n\ |
13370 | Configure various breakpoint-specific variables such as\n\ | |
1bedd215 | 13371 | pending breakpoint behavior"), |
fa8d40ab JJ |
13372 | &breakpoint_show_cmdlist, "show breakpoint ", |
13373 | 0/*allow-unknown*/, &showlist); | |
13374 | ||
7915a72c AC |
13375 | add_setshow_auto_boolean_cmd ("pending", no_class, |
13376 | &pending_break_support, _("\ | |
13377 | Set debugger's behavior regarding pending breakpoints."), _("\ | |
13378 | Show debugger's behavior regarding pending breakpoints."), _("\ | |
6e1d7d6c AC |
13379 | If on, an unrecognized breakpoint location will cause gdb to create a\n\ |
13380 | pending breakpoint. If off, an unrecognized breakpoint location results in\n\ | |
13381 | an error. If auto, an unrecognized breakpoint location results in a\n\ | |
7915a72c | 13382 | user-query to see if a pending breakpoint should be created."), |
2c5b56ce | 13383 | NULL, |
920d2a44 | 13384 | show_pending_break_support, |
6e1d7d6c AC |
13385 | &breakpoint_set_cmdlist, |
13386 | &breakpoint_show_cmdlist); | |
fa8d40ab JJ |
13387 | |
13388 | pending_break_support = AUTO_BOOLEAN_AUTO; | |
765dc015 VP |
13389 | |
13390 | add_setshow_boolean_cmd ("auto-hw", no_class, | |
13391 | &automatic_hardware_breakpoints, _("\ | |
13392 | Set automatic usage of hardware breakpoints."), _("\ | |
13393 | Show automatic usage of hardware breakpoints."), _("\ | |
13394 | If set, the debugger will automatically use hardware breakpoints for\n\ | |
13395 | breakpoints set with \"break\" but falling in read-only memory. If not set,\n\ | |
13396 | a warning will be emitted for such breakpoints."), | |
13397 | NULL, | |
13398 | show_automatic_hardware_breakpoints, | |
13399 | &breakpoint_set_cmdlist, | |
13400 | &breakpoint_show_cmdlist); | |
74960c60 | 13401 | |
33e5cbd6 PA |
13402 | add_setshow_enum_cmd ("always-inserted", class_support, |
13403 | always_inserted_enums, &always_inserted_mode, _("\ | |
74960c60 VP |
13404 | Set mode for inserting breakpoints."), _("\ |
13405 | Show mode for inserting breakpoints."), _("\ | |
33e5cbd6 PA |
13406 | When this mode is off, breakpoints are inserted in inferior when it is\n\ |
13407 | resumed, and removed when execution stops. When this mode is on,\n\ | |
13408 | breakpoints are inserted immediately and removed only when the user\n\ | |
13409 | deletes the breakpoint. When this mode is auto (which is the default),\n\ | |
13410 | the behaviour depends on the non-stop setting (see help set non-stop).\n\ | |
13411 | In this case, if gdb is controlling the inferior in non-stop mode, gdb\n\ | |
13412 | behaves as if always-inserted mode is on; if gdb is controlling the\n\ | |
13413 | inferior in all-stop mode, gdb behaves as if always-inserted mode is off."), | |
74960c60 VP |
13414 | NULL, |
13415 | &show_always_inserted_mode, | |
13416 | &breakpoint_set_cmdlist, | |
13417 | &breakpoint_show_cmdlist); | |
f1310107 TJB |
13418 | |
13419 | add_com ("break-range", class_breakpoint, break_range_command, _("\ | |
13420 | Set a breakpoint for an address range.\n\ | |
13421 | break-range START-LOCATION, END-LOCATION\n\ | |
13422 | where START-LOCATION and END-LOCATION can be one of the following:\n\ | |
13423 | LINENUM, for that line in the current file,\n\ | |
13424 | FILE:LINENUM, for that line in that file,\n\ | |
13425 | +OFFSET, for that number of lines after the current line\n\ | |
13426 | or the start of the range\n\ | |
13427 | FUNCTION, for the first line in that function,\n\ | |
13428 | FILE:FUNCTION, to distinguish among like-named static functions.\n\ | |
13429 | *ADDRESS, for the instruction at that address.\n\ | |
13430 | \n\ | |
13431 | The breakpoint will stop execution of the inferior whenever it executes\n\ | |
13432 | an instruction at any address within the [START-LOCATION, END-LOCATION]\n\ | |
13433 | range (including START-LOCATION and END-LOCATION).")); | |
13434 | ||
765dc015 | 13435 | automatic_hardware_breakpoints = 1; |
f3b1572e PA |
13436 | |
13437 | observer_attach_about_to_proceed (breakpoint_about_to_proceed); | |
c906108c | 13438 | } |